repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Automaton Wallet Management |
| #3 | * |
| #4 | * Creates and manages an EVM wallet for the automaton's identity and payments. |
| #5 | * The private key is the automaton's sovereign identity. |
| #6 | * Adapted from runtime-mcp/src/wallet.ts |
| #7 | */ |
| #8 | import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; |
| #9 | import fs from "fs"; |
| #10 | import path from "path"; |
| #11 | const AUTOMATON_DIR = path.join(process.env.HOME || "/root", ".automaton"); |
| #12 | const WALLET_FILE = path.join(AUTOMATON_DIR, "wallet.json"); |
| #13 | export function getAutomatonDir() { |
| #14 | return AUTOMATON_DIR; |
| #15 | } |
| #16 | export function getWalletPath() { |
| #17 | return WALLET_FILE; |
| #18 | } |
| #19 | /** |
| #20 | * Get or create the automaton's wallet. |
| #21 | * The private key IS the automaton's identity -- protect it. |
| #22 | */ |
| #23 | export async function getWallet() { |
| #24 | if (!fs.existsSync(AUTOMATON_DIR)) { |
| #25 | fs.mkdirSync(AUTOMATON_DIR, { recursive: true, mode: 0o700 }); |
| #26 | } |
| #27 | if (fs.existsSync(WALLET_FILE)) { |
| #28 | const walletData = JSON.parse(fs.readFileSync(WALLET_FILE, "utf-8")); |
| #29 | const account = privateKeyToAccount(walletData.privateKey); |
| #30 | return { account, isNew: false }; |
| #31 | } |
| #32 | else { |
| #33 | const privateKey = generatePrivateKey(); |
| #34 | const account = privateKeyToAccount(privateKey); |
| #35 | const walletData = { |
| #36 | privateKey, |
| #37 | createdAt: new Date().toISOString(), |
| #38 | }; |
| #39 | fs.writeFileSync(WALLET_FILE, JSON.stringify(walletData, null, 2), { |
| #40 | mode: 0o600, |
| #41 | }); |
| #42 | return { account, isNew: true }; |
| #43 | } |
| #44 | } |
| #45 | /** |
| #46 | * Get the wallet address without loading the full account. |
| #47 | */ |
| #48 | export function getWalletAddress() { |
| #49 | if (!fs.existsSync(WALLET_FILE)) { |
| #50 | return null; |
| #51 | } |
| #52 | const walletData = JSON.parse(fs.readFileSync(WALLET_FILE, "utf-8")); |
| #53 | const account = privateKeyToAccount(walletData.privateKey); |
| #54 | return account.address; |
| #55 | } |
| #56 | /** |
| #57 | * Load the full wallet account (needed for signing). |
| #58 | */ |
| #59 | export function loadWalletAccount() { |
| #60 | if (!fs.existsSync(WALLET_FILE)) { |
| #61 | return null; |
| #62 | } |
| #63 | const walletData = JSON.parse(fs.readFileSync(WALLET_FILE, "utf-8")); |
| #64 | return privateKeyToAccount(walletData.privateKey); |
| #65 | } |
| #66 | export function walletExists() { |
| #67 | return fs.existsSync(WALLET_FILE); |
| #68 | } |
| #69 | //# sourceMappingURL=wallet.js.map |