agentvault 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/dist/cli/commands/approve.js +5 -5
- package/dist/cli/commands/archive.js +5 -5
- package/dist/cli/commands/backup.js +5 -5
- package/dist/cli/commands/cloud-backup.js +12 -12
- package/dist/cli/commands/decrypt.js +2 -2
- package/dist/cli/commands/deploy.js +1 -1
- package/dist/cli/commands/exec.js +2 -2
- package/dist/cli/commands/fetch.js +4 -4
- package/dist/cli/commands/inference.js +5 -5
- package/dist/cli/commands/init.d.ts +1 -1
- package/dist/cli/commands/init.js +16 -16
- package/dist/cli/commands/list.js +4 -4
- package/dist/cli/commands/package.js +2 -2
- package/dist/cli/commands/profile.js +1 -1
- package/dist/cli/commands/rebuild.js +2 -2
- package/dist/cli/commands/show.js +1 -1
- package/dist/cli/commands/status.d.ts +1 -1
- package/dist/cli/commands/status.js +8 -8
- package/dist/cli/commands/trace.js +1 -1
- package/dist/cli/commands/wallet-export.js +1 -1
- package/dist/cli/commands/wallet-sign.js +1 -1
- package/dist/cli/commands/wallet.d.ts +1 -1
- package/dist/cli/commands/wallet.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +3 -3
- package/dist/src/archival/archive-manager.d.ts +85 -0
- package/dist/src/archival/archive-manager.js +294 -0
- package/dist/src/archival/arweave-client.d.ts +88 -0
- package/dist/src/archival/arweave-client.js +223 -0
- package/dist/src/archival/index.d.ts +8 -0
- package/{src/archival/index.ts → dist/src/archival/index.js} +1 -1
- package/dist/src/backup/backup.d.ts +67 -0
- package/dist/src/backup/backup.js +231 -0
- package/dist/src/backup/index.d.ts +7 -0
- package/{src/backup/index.ts → dist/src/backup/index.js} +1 -1
- package/dist/src/cloud-storage/cloud-sync.d.ts +49 -0
- package/dist/src/cloud-storage/cloud-sync.js +372 -0
- package/dist/src/cloud-storage/index.d.ts +11 -0
- package/{src/cloud-storage/index.ts → dist/src/cloud-storage/index.js} +1 -1
- package/dist/src/cloud-storage/provider-detector.d.ts +34 -0
- package/dist/src/cloud-storage/provider-detector.js +158 -0
- package/{src/cloud-storage/types.ts → dist/src/cloud-storage/types.d.ts} +40 -53
- package/dist/src/cloud-storage/types.js +10 -0
- package/dist/src/debugging/index.d.ts +6 -0
- package/{src/debugging/index.ts → dist/src/debugging/index.js} +1 -1
- package/dist/src/debugging/logs.d.ts +32 -0
- package/dist/src/debugging/logs.js +158 -0
- package/dist/src/debugging/types.d.ts +91 -0
- package/dist/src/debugging/types.js +5 -0
- package/dist/src/deployment/deployer.d.ts +52 -0
- package/dist/src/deployment/deployer.js +211 -0
- package/dist/src/deployment/icpClient.d.ts +144 -0
- package/dist/src/deployment/icpClient.js +545 -0
- package/dist/src/deployment/index.d.ts +11 -0
- package/dist/src/deployment/index.js +14 -0
- package/dist/src/deployment/promotion.d.ts +32 -0
- package/dist/src/deployment/promotion.js +114 -0
- package/dist/src/deployment/types.d.ts +101 -0
- package/dist/src/deployment/types.js +5 -0
- package/dist/src/icp/batch.d.ts +112 -0
- package/dist/src/icp/batch.js +273 -0
- package/dist/src/icp/cycles.d.ts +29 -0
- package/{src/icp/cycles.ts → dist/src/icp/cycles.js} +8 -22
- package/dist/src/icp/environment.d.ts +60 -0
- package/dist/src/icp/environment.js +183 -0
- package/dist/src/icp/icpcli.d.ts +204 -0
- package/dist/src/icp/icpcli.js +374 -0
- package/dist/src/icp/icwasm.d.ts +94 -0
- package/dist/src/icp/icwasm.js +197 -0
- package/dist/src/icp/identity.d.ts +50 -0
- package/{src/icp/identity.ts → dist/src/icp/identity.js} +15 -28
- package/dist/src/icp/index.d.ts +16 -0
- package/dist/src/icp/index.js +20 -0
- package/dist/src/icp/optimization.d.ts +16 -0
- package/dist/src/icp/optimization.js +225 -0
- package/dist/src/icp/tokens.d.ts +24 -0
- package/{src/icp/tokens.ts → dist/src/icp/tokens.js} +5 -12
- package/dist/src/icp/tool-detector.d.ts +31 -0
- package/dist/src/icp/tool-detector.js +104 -0
- package/dist/src/icp/types.d.ts +493 -0
- package/dist/src/icp/types.js +7 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +18 -0
- package/dist/src/inference/bittensor-client.d.ts +108 -0
- package/dist/src/inference/bittensor-client.js +224 -0
- package/dist/src/inference/index.d.ts +8 -0
- package/{src/inference/index.ts → dist/src/inference/index.js} +1 -1
- package/dist/src/inference/inference-manager.d.ts +76 -0
- package/dist/src/inference/inference-manager.js +228 -0
- package/dist/src/metrics/index.d.ts +7 -0
- package/{src/metrics/index.ts → dist/src/metrics/index.js} +1 -1
- package/dist/src/metrics/metrics.d.ts +39 -0
- package/dist/src/metrics/metrics.js +129 -0
- package/dist/src/monitoring/alerting.d.ts +51 -0
- package/dist/src/monitoring/alerting.js +169 -0
- package/dist/src/monitoring/health.d.ts +40 -0
- package/dist/src/monitoring/health.js +164 -0
- package/dist/src/monitoring/index.d.ts +10 -0
- package/dist/src/monitoring/index.js +12 -0
- package/dist/src/monitoring/info.d.ts +15 -0
- package/dist/src/monitoring/info.js +109 -0
- package/dist/src/monitoring/types.d.ts +93 -0
- package/dist/src/monitoring/types.js +7 -0
- package/dist/src/network/index.d.ts +5 -0
- package/{src/network/index.ts → dist/src/network/index.js} +1 -1
- package/dist/src/network/network-config.d.ts +31 -0
- package/dist/src/network/network-config.js +109 -0
- package/dist/src/packaging/compiler.d.ts +61 -0
- package/dist/src/packaging/compiler.js +562 -0
- package/dist/src/packaging/config-persistence.d.ts +46 -0
- package/dist/src/packaging/config-persistence.js +108 -0
- package/dist/src/packaging/config-schemas.d.ts +115 -0
- package/dist/src/packaging/config-schemas.js +43 -0
- package/dist/src/packaging/detector.d.ts +26 -0
- package/dist/src/packaging/detector.js +193 -0
- package/dist/src/packaging/index.d.ts +16 -0
- package/dist/src/packaging/index.js +22 -0
- package/dist/src/packaging/packager.d.ts +31 -0
- package/dist/src/packaging/packager.js +90 -0
- package/dist/src/packaging/parsers/clawdbot.d.ts +19 -0
- package/dist/src/packaging/parsers/clawdbot.js +231 -0
- package/dist/src/packaging/parsers/cline.d.ts +26 -0
- package/dist/src/packaging/parsers/cline.js +185 -0
- package/dist/src/packaging/parsers/generic.d.ts +27 -0
- package/dist/src/packaging/parsers/generic.js +228 -0
- package/dist/src/packaging/parsers/goose.d.ts +26 -0
- package/dist/src/packaging/parsers/goose.js +175 -0
- package/dist/src/packaging/parsers/index.d.ts +11 -0
- package/{src/packaging/parsers/index.ts → dist/src/packaging/parsers/index.js} +1 -1
- package/dist/src/packaging/serializer.d.ts +108 -0
- package/dist/src/packaging/serializer.js +153 -0
- package/dist/src/packaging/types.d.ts +131 -0
- package/dist/src/packaging/types.js +5 -0
- package/dist/src/packaging/wasmedge-compiler.d.ts +76 -0
- package/dist/src/packaging/wasmedge-compiler.js +349 -0
- package/dist/src/security/index.d.ts +11 -0
- package/{src/security/index.ts → dist/src/security/index.js} +1 -4
- package/dist/src/security/multisig.d.ts +102 -0
- package/dist/src/security/multisig.js +283 -0
- package/dist/src/security/types.d.ts +207 -0
- package/dist/src/security/types.js +217 -0
- package/dist/src/security/vetkeys.d.ts +179 -0
- package/dist/src/security/vetkeys.js +499 -0
- package/dist/src/testing/index.d.ts +6 -0
- package/{src/testing/index.ts → dist/src/testing/index.js} +1 -1
- package/dist/src/testing/local-runner.d.ts +23 -0
- package/dist/src/testing/local-runner.js +226 -0
- package/dist/src/testing/types.d.ts +98 -0
- package/dist/src/testing/types.js +5 -0
- package/dist/src/wallet/cbor-serializer.d.ts +82 -0
- package/dist/src/wallet/cbor-serializer.js +282 -0
- package/dist/src/wallet/chain-dispatcher.d.ts +112 -0
- package/dist/src/wallet/chain-dispatcher.js +241 -0
- package/dist/src/wallet/cross-chain-aggregator.d.ts +119 -0
- package/dist/src/wallet/cross-chain-aggregator.js +235 -0
- package/dist/src/wallet/index.d.ts +16 -0
- package/dist/src/wallet/index.js +22 -0
- package/dist/src/wallet/key-derivation.d.ts +117 -0
- package/dist/src/wallet/key-derivation.js +325 -0
- package/dist/src/wallet/providers/base-provider.d.ts +111 -0
- package/dist/src/wallet/providers/base-provider.js +58 -0
- package/dist/src/wallet/providers/cketh-provider.d.ts +104 -0
- package/dist/src/wallet/providers/cketh-provider.js +343 -0
- package/dist/src/wallet/providers/polkadot-provider.d.ts +115 -0
- package/dist/src/wallet/providers/polkadot-provider.js +407 -0
- package/dist/src/wallet/providers/solana-provider.d.ts +102 -0
- package/dist/src/wallet/providers/solana-provider.js +393 -0
- package/dist/src/wallet/transaction-queue.d.ts +133 -0
- package/dist/src/wallet/transaction-queue.js +195 -0
- package/dist/src/wallet/types.d.ts +167 -0
- package/dist/src/wallet/types.js +5 -0
- package/dist/src/wallet/vetkeys-adapter.d.ts +134 -0
- package/dist/src/wallet/vetkeys-adapter.js +313 -0
- package/dist/src/wallet/wallet-manager.d.ts +202 -0
- package/dist/src/wallet/wallet-manager.js +451 -0
- package/dist/src/wallet/wallet-storage.d.ts +131 -0
- package/dist/src/wallet/wallet-storage.js +274 -0
- package/macos-wallet-app/AgentVaultWallet/App/AgentVaultWalletApp.swift +54 -0
- package/macos-wallet-app/AgentVaultWallet/Models/AppState.swift +102 -0
- package/macos-wallet-app/AgentVaultWallet/Models/Chain.swift +121 -0
- package/macos-wallet-app/AgentVaultWallet/Models/Wallet.swift +98 -0
- package/macos-wallet-app/AgentVaultWallet/Resources/AgentVaultWallet.entitlements +27 -0
- package/macos-wallet-app/AgentVaultWallet/Resources/Info.plist +69 -0
- package/macos-wallet-app/AgentVaultWallet/Services/BackupService.swift +270 -0
- package/macos-wallet-app/AgentVaultWallet/Services/CLIBridge.swift +367 -0
- package/macos-wallet-app/AgentVaultWallet/Services/CryptoService.swift +157 -0
- package/macos-wallet-app/AgentVaultWallet/Services/FileService.swift +120 -0
- package/macos-wallet-app/AgentVaultWallet/Services/KeychainService.swift +219 -0
- package/macos-wallet-app/AgentVaultWallet/Utilities/Constants.swift +44 -0
- package/macos-wallet-app/AgentVaultWallet/Utilities/Extensions.swift +115 -0
- package/macos-wallet-app/AgentVaultWallet/ViewModels/BackupViewModel.swift +237 -0
- package/macos-wallet-app/AgentVaultWallet/ViewModels/CreateWalletViewModel.swift +137 -0
- package/macos-wallet-app/AgentVaultWallet/ViewModels/ImportWalletViewModel.swift +179 -0
- package/macos-wallet-app/AgentVaultWallet/ViewModels/WalletStore.swift +286 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Backup/BackupView.swift +235 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Backup/RestoreView.swift +316 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Create/CreateWalletFlow.swift +438 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Import/ImportWalletFlow.swift +399 -0
- package/macos-wallet-app/AgentVaultWallet/Views/MainView.swift +134 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Settings/SettingsView.swift +276 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Sidebar/SidebarView.swift +133 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Wallet/DashboardView.swift +233 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Wallet/WalletDetailView.swift +281 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Wallet/WalletListView.swift +280 -0
- package/macos-wallet-app/AgentVaultWallet/Views/Welcome/WelcomeView.swift +176 -0
- package/macos-wallet-app/Makefile +47 -0
- package/macos-wallet-app/project.yml +40 -0
- package/macos-wallet-app/setup.sh +73 -0
- package/package.json +10 -2
- package/backups/agentvault-backup-test-agent-2026-02-12T17-54-28-967Z.json +0 -28
- package/backups/agentvault-backup-test-agent-2026-02-12T17-54-29-032Z.backup +0 -1
- package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-373Z.json +0 -28
- package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-428Z.backup +0 -1
- package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-132Z.json +0 -28
- package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-247Z.backup +0 -1
- package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-216Z.json +0 -28
- package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-283Z.backup +0 -1
- package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-772Z.backup +0 -1
- package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-793Z.json +0 -28
- package/backups/test-backup.json +0 -28
- package/scripts/dev-dashboard.mjs +0 -84
- package/site/README.md +0 -63
- package/site/docusaurus.config.ts +0 -148
- package/site/package-lock.json +0 -18383
- package/site/package.json +0 -47
- package/site/sidebars.ts +0 -86
- package/site/static/.gitkeep +0 -0
- package/site/static/img/logo.svg +0 -28
- package/site/static/img/og-image.svg +0 -35
- package/src/archival/archive-manager.ts +0 -372
- package/src/archival/arweave-client.ts +0 -289
- package/src/backup/backup.ts +0 -315
- package/src/cloud-storage/cloud-sync.ts +0 -461
- package/src/cloud-storage/provider-detector.ts +0 -198
- package/src/debugging/logs.ts +0 -193
- package/src/debugging/types.ts +0 -100
- package/src/deployment/deployer.ts +0 -274
- package/src/deployment/icpClient.ts +0 -620
- package/src/deployment/index.ts +0 -46
- package/src/deployment/promotion.ts +0 -161
- package/src/deployment/types.ts +0 -111
- package/src/icp/batch.ts +0 -374
- package/src/icp/environment.ts +0 -215
- package/src/icp/icpcli.ts +0 -438
- package/src/icp/icwasm.ts +0 -222
- package/src/icp/index.ts +0 -94
- package/src/icp/optimization.ts +0 -242
- package/src/icp/tool-detector.ts +0 -110
- package/src/icp/types.ts +0 -574
- package/src/index.ts +0 -25
- package/src/inference/bittensor-client.ts +0 -304
- package/src/inference/inference-manager.ts +0 -327
- package/src/metrics/metrics.ts +0 -186
- package/src/monitoring/alerting.ts +0 -190
- package/src/monitoring/health.ts +0 -197
- package/src/monitoring/index.ts +0 -38
- package/src/monitoring/info.ts +0 -114
- package/src/monitoring/types.ts +0 -99
- package/src/network/network-config.ts +0 -129
- package/src/packaging/compiler.ts +0 -647
- package/src/packaging/config-persistence.ts +0 -135
- package/src/packaging/config-schemas.ts +0 -156
- package/src/packaging/detector.ts +0 -220
- package/src/packaging/index.ts +0 -90
- package/src/packaging/packager.ts +0 -118
- package/src/packaging/parsers/clawdbot.ts +0 -278
- package/src/packaging/parsers/cline.ts +0 -223
- package/src/packaging/parsers/generic.ts +0 -266
- package/src/packaging/parsers/goose.ts +0 -214
- package/src/packaging/serializer.ts +0 -260
- package/src/packaging/types.ts +0 -144
- package/src/packaging/wasmedge-compiler.ts +0 -406
- package/src/security/multisig.ts +0 -415
- package/src/security/types.ts +0 -416
- package/src/security/vetkeys.ts +0 -655
- package/src/testing/local-runner.ts +0 -264
- package/src/testing/types.ts +0 -104
- package/src/wallet/cbor-serializer.ts +0 -323
- package/src/wallet/chain-dispatcher.ts +0 -313
- package/src/wallet/cross-chain-aggregator.ts +0 -346
- package/src/wallet/index.ts +0 -76
- package/src/wallet/key-derivation.ts +0 -425
- package/src/wallet/providers/base-provider.ts +0 -154
- package/src/wallet/providers/cketh-provider.ts +0 -434
- package/src/wallet/providers/polkadot-provider.ts +0 -503
- package/src/wallet/providers/solana-provider.ts +0 -490
- package/src/wallet/transaction-queue.ts +0 -284
- package/src/wallet/types.ts +0 -178
- package/src/wallet/vetkeys-adapter.ts +0 -431
- package/src/wallet/wallet-manager.ts +0 -597
- package/src/wallet/wallet-storage.ts +0 -380
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Manager
|
|
3
|
+
*
|
|
4
|
+
* Main wallet management module.
|
|
5
|
+
* Handles wallet creation, storage, and retrieval with per-agent isolation.
|
|
6
|
+
* Phase 5A: Added canister sync functionality.
|
|
7
|
+
*/
|
|
8
|
+
import { randomBytes } from 'node:crypto';
|
|
9
|
+
import { saveWallet, loadWallet, deleteWallet, listWallets, walletExists, } from './wallet-storage.js';
|
|
10
|
+
import { deriveWalletKey, validateSeedPhrase, generateMnemonic, } from './key-derivation.js';
|
|
11
|
+
// Phase 5A: Canister imports (lazy load)
|
|
12
|
+
let _createActor = null;
|
|
13
|
+
let _canisterInitialized = false;
|
|
14
|
+
/**
|
|
15
|
+
* Lazy load canister actor
|
|
16
|
+
*/
|
|
17
|
+
async function loadCanister() {
|
|
18
|
+
if (_canisterInitialized)
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
const { createActor } = await import('../canister/actor.js');
|
|
22
|
+
_createActor = createActor;
|
|
23
|
+
_canisterInitialized = true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.warn('Canister integration not available:', error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get or create canister actor
|
|
31
|
+
*/
|
|
32
|
+
async function getCanisterActor(canisterId) {
|
|
33
|
+
await loadCanister();
|
|
34
|
+
if (!_createActor) {
|
|
35
|
+
throw new Error('Canister actor not initialized');
|
|
36
|
+
}
|
|
37
|
+
const { createAnonymousAgent } = await import('../canister/actor.js');
|
|
38
|
+
const agent = createAnonymousAgent();
|
|
39
|
+
return _createActor(canisterId, agent);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* In-memory wallet connections cache
|
|
43
|
+
*/
|
|
44
|
+
const walletConnections = new Map();
|
|
45
|
+
/**
|
|
46
|
+
* Generate unique wallet ID
|
|
47
|
+
*
|
|
48
|
+
* @returns Unique wallet ID
|
|
49
|
+
*/
|
|
50
|
+
function generateWalletId() {
|
|
51
|
+
const bytes = randomBytes(16);
|
|
52
|
+
return `wallet-${bytes.toString('hex')}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a new wallet
|
|
56
|
+
*
|
|
57
|
+
* @param options - Wallet creation options
|
|
58
|
+
* @param storageOptions - Storage options
|
|
59
|
+
* @returns Created wallet data
|
|
60
|
+
*/
|
|
61
|
+
export function createWallet(options, storageOptions = {}) {
|
|
62
|
+
// Derive wallet key
|
|
63
|
+
const derivedKey = deriveWalletKey(options.method, options.seedPhrase, options.privateKey, options.derivationPath, options.chain);
|
|
64
|
+
// Create wallet data object
|
|
65
|
+
const walletData = {
|
|
66
|
+
id: options.walletId || generateWalletId(),
|
|
67
|
+
agentId: options.agentId,
|
|
68
|
+
chain: options.chain,
|
|
69
|
+
address: derivedKey.address,
|
|
70
|
+
privateKey: options.method === 'private-key' ? derivedKey.privateKey : undefined,
|
|
71
|
+
mnemonic: (options.method === 'seed' || options.method === 'mnemonic')
|
|
72
|
+
? options.seedPhrase
|
|
73
|
+
: undefined,
|
|
74
|
+
seedDerivationPath: derivedKey.derivationPath,
|
|
75
|
+
createdAt: Date.now(),
|
|
76
|
+
updatedAt: Date.now(),
|
|
77
|
+
creationMethod: options.method,
|
|
78
|
+
chainMetadata: options.chainMetadata,
|
|
79
|
+
};
|
|
80
|
+
// Save wallet to storage
|
|
81
|
+
saveWallet(walletData, storageOptions);
|
|
82
|
+
return walletData;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Import wallet from private key
|
|
86
|
+
*
|
|
87
|
+
* @param agentId - Agent ID
|
|
88
|
+
* @param chain - Blockchain type
|
|
89
|
+
* @param privateKey - Private key (hex)
|
|
90
|
+
* @param storageOptions - Storage options
|
|
91
|
+
* @returns Imported wallet data
|
|
92
|
+
*/
|
|
93
|
+
export function importWalletFromPrivateKey(agentId, chain, privateKey, storageOptions = {}) {
|
|
94
|
+
return createWallet({
|
|
95
|
+
agentId,
|
|
96
|
+
chain: chain,
|
|
97
|
+
method: 'private-key',
|
|
98
|
+
privateKey,
|
|
99
|
+
}, storageOptions);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Import wallet from seed phrase
|
|
103
|
+
*
|
|
104
|
+
* @param agentId - Agent ID
|
|
105
|
+
* @param chain - Blockchain type
|
|
106
|
+
* @param seedPhrase - BIP39 seed phrase
|
|
107
|
+
* @param derivationPath - Optional custom derivation path
|
|
108
|
+
* @param storageOptions - Storage options
|
|
109
|
+
* @returns Imported wallet data
|
|
110
|
+
*/
|
|
111
|
+
export function importWalletFromSeed(agentId, chain, seedPhrase, derivationPath, storageOptions = {}) {
|
|
112
|
+
return createWallet({
|
|
113
|
+
agentId,
|
|
114
|
+
chain: chain,
|
|
115
|
+
method: 'seed',
|
|
116
|
+
seedPhrase,
|
|
117
|
+
derivationPath,
|
|
118
|
+
}, storageOptions);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Import wallet from mnemonic
|
|
122
|
+
*
|
|
123
|
+
* @param agentId - Agent ID
|
|
124
|
+
* @param chain - Blockchain type
|
|
125
|
+
* @param mnemonic - BIP39 mnemonic phrase
|
|
126
|
+
* @param derivationPath - Optional custom derivation path
|
|
127
|
+
* @param storageOptions - Storage options
|
|
128
|
+
* @returns Imported wallet data
|
|
129
|
+
*/
|
|
130
|
+
export function importWalletFromMnemonic(agentId, chain, mnemonic, derivationPath, storageOptions = {}) {
|
|
131
|
+
return createWallet({
|
|
132
|
+
agentId,
|
|
133
|
+
chain: chain,
|
|
134
|
+
method: 'mnemonic',
|
|
135
|
+
seedPhrase: mnemonic,
|
|
136
|
+
derivationPath,
|
|
137
|
+
}, storageOptions);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Generate new wallet
|
|
141
|
+
*
|
|
142
|
+
* @param agentId - Agent ID
|
|
143
|
+
* @param chain - Blockchain type
|
|
144
|
+
* @param storageOptions - Storage options
|
|
145
|
+
* @returns Generated wallet data
|
|
146
|
+
*/
|
|
147
|
+
export function generateWallet(agentId, chain, storageOptions = {}) {
|
|
148
|
+
const mnemonic = generateMnemonic(128);
|
|
149
|
+
return importWalletFromSeed(agentId, chain, mnemonic, undefined, storageOptions);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get wallet by ID
|
|
153
|
+
*
|
|
154
|
+
* @param agentId - Agent ID
|
|
155
|
+
* @param walletId - Wallet ID
|
|
156
|
+
* @param storageOptions - Storage options
|
|
157
|
+
* @returns Wallet data or null if not found
|
|
158
|
+
*/
|
|
159
|
+
export function getWallet(agentId, walletId, storageOptions = {}) {
|
|
160
|
+
return loadWallet(agentId, walletId, storageOptions);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* List all wallets for an agent
|
|
164
|
+
*
|
|
165
|
+
* @param agentId - Agent ID
|
|
166
|
+
* @param storageOptions - Storage options
|
|
167
|
+
* @returns Array of wallet IDs
|
|
168
|
+
*/
|
|
169
|
+
export function listAgentWallets(agentId, storageOptions = {}) {
|
|
170
|
+
return listWallets(agentId, storageOptions);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if wallet exists
|
|
174
|
+
*
|
|
175
|
+
* @param agentId - Agent ID
|
|
176
|
+
* @param walletId - Wallet ID
|
|
177
|
+
* @param storageOptions - Storage options
|
|
178
|
+
* @returns True if wallet exists
|
|
179
|
+
*/
|
|
180
|
+
export function hasWallet(agentId, walletId, storageOptions = {}) {
|
|
181
|
+
return walletExists(agentId, walletId, storageOptions);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Remove wallet
|
|
185
|
+
*
|
|
186
|
+
* @param agentId - Agent ID
|
|
187
|
+
* @param walletId - Wallet ID
|
|
188
|
+
* @param storageOptions - Storage options
|
|
189
|
+
*/
|
|
190
|
+
export function removeWallet(agentId, walletId, storageOptions = {}) {
|
|
191
|
+
deleteWallet(agentId, walletId, storageOptions);
|
|
192
|
+
// Remove from connections cache
|
|
193
|
+
walletConnections.delete(`${agentId}:${walletId}`);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Clear all wallets for an agent
|
|
197
|
+
*
|
|
198
|
+
* @param agentId - Agent ID
|
|
199
|
+
* @param storageOptions - Storage options
|
|
200
|
+
*/
|
|
201
|
+
export function clearAgentWallets(agentId, storageOptions = {}) {
|
|
202
|
+
const walletIds = listWallets(agentId, storageOptions);
|
|
203
|
+
for (const walletId of walletIds) {
|
|
204
|
+
deleteWallet(agentId, walletId, storageOptions);
|
|
205
|
+
walletConnections.delete(`${agentId}:${walletId}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Cache wallet connection
|
|
210
|
+
*
|
|
211
|
+
* @param agentId - Agent ID
|
|
212
|
+
* @param walletId - Wallet ID
|
|
213
|
+
* @param provider - Provider instance
|
|
214
|
+
*/
|
|
215
|
+
export function cacheWalletConnection(agentId, walletId, provider) {
|
|
216
|
+
walletConnections.set(`${agentId}:${walletId}`, provider);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get cached wallet connection
|
|
220
|
+
*
|
|
221
|
+
* @param agentId - Agent ID
|
|
222
|
+
* @param walletId - Wallet ID
|
|
223
|
+
* @returns Cached provider or undefined
|
|
224
|
+
*/
|
|
225
|
+
export function getCachedConnection(agentId, walletId) {
|
|
226
|
+
return walletConnections.get(`${agentId}:${walletId}`);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Clear wallet connection cache
|
|
230
|
+
*
|
|
231
|
+
* @param agentId - Agent ID
|
|
232
|
+
* @param walletId - Wallet ID
|
|
233
|
+
*/
|
|
234
|
+
export function clearCachedConnection(agentId, walletId) {
|
|
235
|
+
walletConnections.delete(`${agentId}:${walletId}`);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Validate seed phrase
|
|
239
|
+
*
|
|
240
|
+
* @param seedPhrase - Seed phrase to validate
|
|
241
|
+
* @returns True if valid
|
|
242
|
+
*/
|
|
243
|
+
export function validateSeedPhraseWrapper(seedPhrase) {
|
|
244
|
+
return validateSeedPhrase(seedPhrase);
|
|
245
|
+
}
|
|
246
|
+
// ==================== Phase 5A: Canister Sync Functions ====================
|
|
247
|
+
/**
|
|
248
|
+
* Sync wallet to canister (register wallet metadata)
|
|
249
|
+
*
|
|
250
|
+
* @param agentId - Agent ID
|
|
251
|
+
* @param walletId - Wallet ID
|
|
252
|
+
* @param canisterId - Canister ID to sync to
|
|
253
|
+
* @returns Sync result
|
|
254
|
+
*/
|
|
255
|
+
export async function syncWalletToCanister(agentId, walletId, canisterId) {
|
|
256
|
+
try {
|
|
257
|
+
await loadCanister();
|
|
258
|
+
if (!_createActor) {
|
|
259
|
+
return { success: false, error: 'Canister not available' };
|
|
260
|
+
}
|
|
261
|
+
const wallet = getWallet(agentId, walletId);
|
|
262
|
+
if (!wallet) {
|
|
263
|
+
return { success: false, error: 'Wallet not found' };
|
|
264
|
+
}
|
|
265
|
+
const actor = await getCanisterActor(canisterId);
|
|
266
|
+
const result = await actor.registerWallet({
|
|
267
|
+
id: walletId,
|
|
268
|
+
agentId,
|
|
269
|
+
chain: wallet.chain,
|
|
270
|
+
address: wallet.address,
|
|
271
|
+
registeredAt: BigInt(wallet.createdAt),
|
|
272
|
+
status: { active: null },
|
|
273
|
+
});
|
|
274
|
+
if ('ok' in result) {
|
|
275
|
+
return {
|
|
276
|
+
success: true,
|
|
277
|
+
registeredAt: wallet.createdAt,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return {
|
|
282
|
+
success: false,
|
|
283
|
+
error: result.err,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
return {
|
|
289
|
+
success: false,
|
|
290
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Sync all wallets for an agent to canister
|
|
296
|
+
*
|
|
297
|
+
* @param agentId - Agent ID
|
|
298
|
+
* @param canisterId - Canister ID to sync to
|
|
299
|
+
* @returns Sync results
|
|
300
|
+
*/
|
|
301
|
+
export async function syncAgentWallets(agentId, canisterId) {
|
|
302
|
+
const walletIds = listAgentWallets(agentId);
|
|
303
|
+
const synced = [];
|
|
304
|
+
const failed = [];
|
|
305
|
+
for (const walletId of walletIds) {
|
|
306
|
+
const result = await syncWalletToCanister(agentId, walletId, canisterId);
|
|
307
|
+
if (result.success) {
|
|
308
|
+
synced.push(walletId);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
failed.push({
|
|
312
|
+
walletId,
|
|
313
|
+
error: result.error || 'Unknown error',
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return { synced, failed };
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get wallet sync status
|
|
321
|
+
*
|
|
322
|
+
* @param agentId - Agent ID
|
|
323
|
+
* @param walletId - Wallet ID
|
|
324
|
+
* @param canisterId - Canister ID
|
|
325
|
+
* @returns Wallet sync status
|
|
326
|
+
*/
|
|
327
|
+
export async function getWalletSyncStatus(agentId, walletId, canisterId) {
|
|
328
|
+
try {
|
|
329
|
+
await loadCanister();
|
|
330
|
+
const localExists = hasWallet(agentId, walletId);
|
|
331
|
+
let inCanister = false;
|
|
332
|
+
let canisterStatus;
|
|
333
|
+
if (_createActor) {
|
|
334
|
+
const actor = await getCanisterActor(canisterId);
|
|
335
|
+
const result = await actor.getWallet(walletId);
|
|
336
|
+
if (result && result.length > 0) {
|
|
337
|
+
inCanister = true;
|
|
338
|
+
canisterStatus = result[0];
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const wallet = localExists ? getWallet(agentId, walletId) : null;
|
|
342
|
+
const synced = inCanister && localExists && wallet && canisterStatus;
|
|
343
|
+
return {
|
|
344
|
+
walletId,
|
|
345
|
+
inCanister,
|
|
346
|
+
canisterStatus,
|
|
347
|
+
localExists,
|
|
348
|
+
synced,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
catch (_error) {
|
|
352
|
+
return {
|
|
353
|
+
walletId,
|
|
354
|
+
inCanister: false,
|
|
355
|
+
localExists: hasWallet(agentId, walletId),
|
|
356
|
+
synced: false,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* List wallets from canister
|
|
362
|
+
*
|
|
363
|
+
* @param agentId - Agent ID
|
|
364
|
+
* @param canisterId - Canister ID
|
|
365
|
+
* @returns Array of canister wallet info
|
|
366
|
+
*/
|
|
367
|
+
export async function listCanisterWallets(agentId, canisterId) {
|
|
368
|
+
try {
|
|
369
|
+
await loadCanister();
|
|
370
|
+
if (!_createActor) {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
373
|
+
const actor = await getCanisterActor(canisterId);
|
|
374
|
+
return await actor.listWallets(agentId);
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
console.error('Failed to list canister wallets:', error);
|
|
378
|
+
return [];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Deregister wallet from canister
|
|
383
|
+
*
|
|
384
|
+
* @param walletId - Wallet ID
|
|
385
|
+
* @param canisterId - Canister ID
|
|
386
|
+
* @returns Deregistration result
|
|
387
|
+
*/
|
|
388
|
+
export async function deregisterWalletFromCanister(walletId, canisterId) {
|
|
389
|
+
try {
|
|
390
|
+
await loadCanister();
|
|
391
|
+
if (!_createActor) {
|
|
392
|
+
return { success: false, error: 'Canister not available' };
|
|
393
|
+
}
|
|
394
|
+
const actor = await getCanisterActor(canisterId);
|
|
395
|
+
const result = await actor.deregisterWallet(walletId);
|
|
396
|
+
if ('ok' in result) {
|
|
397
|
+
return { success: true };
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return {
|
|
401
|
+
success: false,
|
|
402
|
+
error: result.err,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
return {
|
|
408
|
+
success: false,
|
|
409
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Update wallet status in canister
|
|
415
|
+
*
|
|
416
|
+
* @param walletId - Wallet ID
|
|
417
|
+
* @param status - New status
|
|
418
|
+
* @param canisterId - Canister ID
|
|
419
|
+
* @returns Update result
|
|
420
|
+
*/
|
|
421
|
+
export async function updateCanisterWalletStatus(walletId, status, canisterId) {
|
|
422
|
+
try {
|
|
423
|
+
await loadCanister();
|
|
424
|
+
if (!_createActor) {
|
|
425
|
+
return { success: false, error: 'Canister not available' };
|
|
426
|
+
}
|
|
427
|
+
const actor = await getCanisterActor(canisterId);
|
|
428
|
+
const statusVariant = status === 'active'
|
|
429
|
+
? { active: null }
|
|
430
|
+
: status === 'inactive'
|
|
431
|
+
? { inactive: null }
|
|
432
|
+
: { revoked: null };
|
|
433
|
+
const result = await actor.updateWalletStatus(walletId, statusVariant);
|
|
434
|
+
if ('ok' in result) {
|
|
435
|
+
return { success: true };
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
return {
|
|
439
|
+
success: false,
|
|
440
|
+
error: result.err,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
return {
|
|
446
|
+
success: false,
|
|
447
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=wallet-manager.js.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Storage Module
|
|
3
|
+
*
|
|
4
|
+
* Manages encrypted wallet persistence in ~/.agentvault/wallets/
|
|
5
|
+
* Provides per-agent wallet isolation and encryption.
|
|
6
|
+
*/
|
|
7
|
+
import type { WalletData, WalletStorageOptions } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Get base directory for wallet storage
|
|
10
|
+
*
|
|
11
|
+
* @param options - Storage options
|
|
12
|
+
* @returns Wallet base directory
|
|
13
|
+
*/
|
|
14
|
+
export declare function getWalletBaseDir(options?: WalletStorageOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get agent-specific wallet directory
|
|
17
|
+
*
|
|
18
|
+
* @param agentId - Agent ID
|
|
19
|
+
* @param options - Storage options
|
|
20
|
+
* @returns Agent wallet directory
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAgentWalletDir(agentId: string, options?: WalletStorageOptions): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get wallet file path
|
|
25
|
+
*
|
|
26
|
+
* @param agentId - Agent ID
|
|
27
|
+
* @param walletId - Wallet ID
|
|
28
|
+
* @param options - Storage options
|
|
29
|
+
* @returns Wallet file path
|
|
30
|
+
*/
|
|
31
|
+
export declare function getWalletFilePath(agentId: string, walletId: string, options?: WalletStorageOptions): string;
|
|
32
|
+
/**
|
|
33
|
+
* Ensure wallet directories exist
|
|
34
|
+
*
|
|
35
|
+
* @param agentId - Agent ID
|
|
36
|
+
* @param options - Storage options
|
|
37
|
+
*/
|
|
38
|
+
export declare function ensureWalletDirectories(agentId: string, options?: WalletStorageOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Save wallet to encrypted storage
|
|
41
|
+
*
|
|
42
|
+
* @param wallet - Wallet data to save
|
|
43
|
+
* @param options - Storage options
|
|
44
|
+
*/
|
|
45
|
+
export declare function saveWallet(wallet: WalletData, options?: WalletStorageOptions): void;
|
|
46
|
+
/**
|
|
47
|
+
* Load wallet from storage
|
|
48
|
+
*
|
|
49
|
+
* @param agentId - Agent ID
|
|
50
|
+
* @param walletId - Wallet ID
|
|
51
|
+
* @param options - Storage options
|
|
52
|
+
* @returns Loaded wallet data or null if not found
|
|
53
|
+
*/
|
|
54
|
+
export declare function loadWallet(agentId: string, walletId: string, options?: WalletStorageOptions): WalletData | null;
|
|
55
|
+
/**
|
|
56
|
+
* Delete wallet from storage
|
|
57
|
+
*
|
|
58
|
+
* @param agentId - Agent ID
|
|
59
|
+
* @param walletId - Wallet ID
|
|
60
|
+
* @param options - Storage options
|
|
61
|
+
*/
|
|
62
|
+
export declare function deleteWallet(agentId: string, walletId: string, options?: WalletStorageOptions): void;
|
|
63
|
+
/**
|
|
64
|
+
* List all wallets for an agent
|
|
65
|
+
*
|
|
66
|
+
* @param agentId - Agent ID
|
|
67
|
+
* @param options - Storage options
|
|
68
|
+
* @returns Array of wallet IDs
|
|
69
|
+
*/
|
|
70
|
+
export declare function listWallets(agentId: string, options?: WalletStorageOptions): string[];
|
|
71
|
+
/**
|
|
72
|
+
* List all agents with wallets
|
|
73
|
+
*
|
|
74
|
+
* @param options - Storage options
|
|
75
|
+
* @returns Array of agent IDs
|
|
76
|
+
*/
|
|
77
|
+
export declare function listAgents(options?: WalletStorageOptions): string[];
|
|
78
|
+
/**
|
|
79
|
+
* Check if wallet exists
|
|
80
|
+
*
|
|
81
|
+
* @param agentId - Agent ID
|
|
82
|
+
* @param walletId - Wallet ID
|
|
83
|
+
* @param options - Storage options
|
|
84
|
+
* @returns True if wallet exists
|
|
85
|
+
*/
|
|
86
|
+
export declare function walletExists(agentId: string, walletId: string, options?: WalletStorageOptions): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get wallet file stats
|
|
89
|
+
*
|
|
90
|
+
* @param agentId - Agent ID
|
|
91
|
+
* @param walletId - Wallet ID
|
|
92
|
+
* @param options - Storage options
|
|
93
|
+
* @returns Wallet file stats or null if not found
|
|
94
|
+
*/
|
|
95
|
+
export declare function getWalletStats(agentId: string, walletId: string, options?: WalletStorageOptions): {
|
|
96
|
+
size: number;
|
|
97
|
+
modified: Date;
|
|
98
|
+
created: Date;
|
|
99
|
+
} | null;
|
|
100
|
+
/**
|
|
101
|
+
* Backup all wallets for an agent
|
|
102
|
+
*
|
|
103
|
+
* @param agentId - Agent ID
|
|
104
|
+
* @param backupPath - Path to save backup
|
|
105
|
+
* @param options - Storage options
|
|
106
|
+
*/
|
|
107
|
+
export declare function backupWallets(agentId: string, backupPath: string, options?: WalletStorageOptions): void;
|
|
108
|
+
/**
|
|
109
|
+
* Restore wallets from backup
|
|
110
|
+
*
|
|
111
|
+
* @param agentId - Agent ID
|
|
112
|
+
* @param backupPath - Path to backup directory
|
|
113
|
+
* @param options - Storage options
|
|
114
|
+
*/
|
|
115
|
+
export declare function restoreWallets(agentId: string, backupPath: string, options?: WalletStorageOptions): void;
|
|
116
|
+
/**
|
|
117
|
+
* Clear all wallets for an agent
|
|
118
|
+
*
|
|
119
|
+
* @param agentId - Agent ID
|
|
120
|
+
* @param options - Storage options
|
|
121
|
+
*/
|
|
122
|
+
export declare function clearWallets(agentId: string, options?: WalletStorageOptions): void;
|
|
123
|
+
/**
|
|
124
|
+
* Get total storage size for an agent
|
|
125
|
+
*
|
|
126
|
+
* @param agentId - Agent ID
|
|
127
|
+
* @param options - Storage options
|
|
128
|
+
* @returns Total size in bytes
|
|
129
|
+
*/
|
|
130
|
+
export declare function getWalletStorageSize(agentId: string, options?: WalletStorageOptions): number;
|
|
131
|
+
//# sourceMappingURL=wallet-storage.d.ts.map
|