agentvault 1.0.0 → 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.
Files changed (293) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/README.md +1 -1
  3. package/dist/cli/commands/approve.js +5 -5
  4. package/dist/cli/commands/archive.js +5 -5
  5. package/dist/cli/commands/backup.js +5 -5
  6. package/dist/cli/commands/cloud-backup.js +12 -12
  7. package/dist/cli/commands/decrypt.js +2 -2
  8. package/dist/cli/commands/deploy.js +1 -1
  9. package/dist/cli/commands/exec.js +2 -2
  10. package/dist/cli/commands/fetch.js +4 -4
  11. package/dist/cli/commands/inference.js +5 -5
  12. package/dist/cli/commands/init.d.ts +1 -1
  13. package/dist/cli/commands/init.js +16 -16
  14. package/dist/cli/commands/list.js +4 -4
  15. package/dist/cli/commands/package.js +2 -2
  16. package/dist/cli/commands/profile.js +1 -1
  17. package/dist/cli/commands/rebuild.js +2 -2
  18. package/dist/cli/commands/show.js +1 -1
  19. package/dist/cli/commands/status.d.ts +1 -1
  20. package/dist/cli/commands/status.js +8 -8
  21. package/dist/cli/commands/trace.js +1 -1
  22. package/dist/cli/commands/wallet-export.js +1 -1
  23. package/dist/cli/commands/wallet-sign.js +1 -1
  24. package/dist/cli/commands/wallet.d.ts +1 -1
  25. package/dist/cli/commands/wallet.js +1 -1
  26. package/dist/cli/index.d.ts +2 -2
  27. package/dist/cli/index.js +3 -3
  28. package/dist/src/archival/archive-manager.d.ts +85 -0
  29. package/dist/src/archival/archive-manager.js +294 -0
  30. package/dist/src/archival/arweave-client.d.ts +88 -0
  31. package/dist/src/archival/arweave-client.js +223 -0
  32. package/dist/src/archival/index.d.ts +8 -0
  33. package/{src/archival/index.ts → dist/src/archival/index.js} +1 -1
  34. package/dist/src/backup/backup.d.ts +67 -0
  35. package/dist/src/backup/backup.js +231 -0
  36. package/dist/src/backup/index.d.ts +7 -0
  37. package/{src/backup/index.ts → dist/src/backup/index.js} +1 -1
  38. package/dist/src/cloud-storage/cloud-sync.d.ts +49 -0
  39. package/dist/src/cloud-storage/cloud-sync.js +372 -0
  40. package/dist/src/cloud-storage/index.d.ts +11 -0
  41. package/{src/cloud-storage/index.ts → dist/src/cloud-storage/index.js} +1 -1
  42. package/dist/src/cloud-storage/provider-detector.d.ts +34 -0
  43. package/dist/src/cloud-storage/provider-detector.js +158 -0
  44. package/{src/cloud-storage/types.ts → dist/src/cloud-storage/types.d.ts} +40 -53
  45. package/dist/src/cloud-storage/types.js +10 -0
  46. package/dist/src/debugging/index.d.ts +6 -0
  47. package/{src/debugging/index.ts → dist/src/debugging/index.js} +1 -1
  48. package/dist/src/debugging/logs.d.ts +32 -0
  49. package/dist/src/debugging/logs.js +158 -0
  50. package/dist/src/debugging/types.d.ts +91 -0
  51. package/dist/src/debugging/types.js +5 -0
  52. package/dist/src/deployment/deployer.d.ts +52 -0
  53. package/dist/src/deployment/deployer.js +211 -0
  54. package/dist/src/deployment/icpClient.d.ts +144 -0
  55. package/dist/src/deployment/icpClient.js +545 -0
  56. package/dist/src/deployment/index.d.ts +11 -0
  57. package/dist/src/deployment/index.js +14 -0
  58. package/dist/src/deployment/promotion.d.ts +32 -0
  59. package/dist/src/deployment/promotion.js +114 -0
  60. package/dist/src/deployment/types.d.ts +101 -0
  61. package/dist/src/deployment/types.js +5 -0
  62. package/dist/src/icp/batch.d.ts +112 -0
  63. package/dist/src/icp/batch.js +273 -0
  64. package/dist/src/icp/cycles.d.ts +29 -0
  65. package/{src/icp/cycles.ts → dist/src/icp/cycles.js} +8 -22
  66. package/dist/src/icp/environment.d.ts +60 -0
  67. package/dist/src/icp/environment.js +183 -0
  68. package/dist/src/icp/icpcli.d.ts +204 -0
  69. package/dist/src/icp/icpcli.js +374 -0
  70. package/dist/src/icp/icwasm.d.ts +94 -0
  71. package/dist/src/icp/icwasm.js +197 -0
  72. package/dist/src/icp/identity.d.ts +50 -0
  73. package/{src/icp/identity.ts → dist/src/icp/identity.js} +15 -28
  74. package/dist/src/icp/index.d.ts +16 -0
  75. package/dist/src/icp/index.js +20 -0
  76. package/dist/src/icp/optimization.d.ts +16 -0
  77. package/dist/src/icp/optimization.js +225 -0
  78. package/dist/src/icp/tokens.d.ts +24 -0
  79. package/{src/icp/tokens.ts → dist/src/icp/tokens.js} +5 -12
  80. package/dist/src/icp/tool-detector.d.ts +31 -0
  81. package/dist/src/icp/tool-detector.js +104 -0
  82. package/dist/src/icp/types.d.ts +493 -0
  83. package/dist/src/icp/types.js +7 -0
  84. package/dist/src/index.d.ts +12 -0
  85. package/dist/src/index.js +18 -0
  86. package/dist/src/inference/bittensor-client.d.ts +108 -0
  87. package/dist/src/inference/bittensor-client.js +224 -0
  88. package/dist/src/inference/index.d.ts +8 -0
  89. package/{src/inference/index.ts → dist/src/inference/index.js} +1 -1
  90. package/dist/src/inference/inference-manager.d.ts +76 -0
  91. package/dist/src/inference/inference-manager.js +228 -0
  92. package/dist/src/metrics/index.d.ts +7 -0
  93. package/{src/metrics/index.ts → dist/src/metrics/index.js} +1 -1
  94. package/dist/src/metrics/metrics.d.ts +39 -0
  95. package/dist/src/metrics/metrics.js +129 -0
  96. package/dist/src/monitoring/alerting.d.ts +51 -0
  97. package/dist/src/monitoring/alerting.js +169 -0
  98. package/dist/src/monitoring/health.d.ts +40 -0
  99. package/dist/src/monitoring/health.js +164 -0
  100. package/dist/src/monitoring/index.d.ts +10 -0
  101. package/dist/src/monitoring/index.js +12 -0
  102. package/dist/src/monitoring/info.d.ts +15 -0
  103. package/dist/src/monitoring/info.js +109 -0
  104. package/dist/src/monitoring/types.d.ts +93 -0
  105. package/dist/src/monitoring/types.js +7 -0
  106. package/dist/src/network/index.d.ts +5 -0
  107. package/{src/network/index.ts → dist/src/network/index.js} +1 -1
  108. package/dist/src/network/network-config.d.ts +31 -0
  109. package/dist/src/network/network-config.js +109 -0
  110. package/dist/src/packaging/compiler.d.ts +61 -0
  111. package/dist/src/packaging/compiler.js +562 -0
  112. package/dist/src/packaging/config-persistence.d.ts +46 -0
  113. package/dist/src/packaging/config-persistence.js +108 -0
  114. package/dist/src/packaging/config-schemas.d.ts +115 -0
  115. package/dist/src/packaging/config-schemas.js +43 -0
  116. package/dist/src/packaging/detector.d.ts +26 -0
  117. package/dist/src/packaging/detector.js +193 -0
  118. package/dist/src/packaging/index.d.ts +16 -0
  119. package/dist/src/packaging/index.js +22 -0
  120. package/dist/src/packaging/packager.d.ts +31 -0
  121. package/dist/src/packaging/packager.js +90 -0
  122. package/dist/src/packaging/parsers/clawdbot.d.ts +19 -0
  123. package/dist/src/packaging/parsers/clawdbot.js +231 -0
  124. package/dist/src/packaging/parsers/cline.d.ts +26 -0
  125. package/dist/src/packaging/parsers/cline.js +185 -0
  126. package/dist/src/packaging/parsers/generic.d.ts +27 -0
  127. package/dist/src/packaging/parsers/generic.js +228 -0
  128. package/dist/src/packaging/parsers/goose.d.ts +26 -0
  129. package/dist/src/packaging/parsers/goose.js +175 -0
  130. package/dist/src/packaging/parsers/index.d.ts +11 -0
  131. package/{src/packaging/parsers/index.ts → dist/src/packaging/parsers/index.js} +1 -1
  132. package/dist/src/packaging/serializer.d.ts +108 -0
  133. package/dist/src/packaging/serializer.js +153 -0
  134. package/dist/src/packaging/types.d.ts +131 -0
  135. package/dist/src/packaging/types.js +5 -0
  136. package/dist/src/packaging/wasmedge-compiler.d.ts +76 -0
  137. package/dist/src/packaging/wasmedge-compiler.js +349 -0
  138. package/dist/src/security/index.d.ts +11 -0
  139. package/{src/security/index.ts → dist/src/security/index.js} +1 -4
  140. package/dist/src/security/multisig.d.ts +102 -0
  141. package/dist/src/security/multisig.js +283 -0
  142. package/dist/src/security/types.d.ts +207 -0
  143. package/dist/src/security/types.js +217 -0
  144. package/dist/src/security/vetkeys.d.ts +179 -0
  145. package/dist/src/security/vetkeys.js +499 -0
  146. package/dist/src/testing/index.d.ts +6 -0
  147. package/{src/testing/index.ts → dist/src/testing/index.js} +1 -1
  148. package/dist/src/testing/local-runner.d.ts +23 -0
  149. package/dist/src/testing/local-runner.js +226 -0
  150. package/dist/src/testing/types.d.ts +98 -0
  151. package/dist/src/testing/types.js +5 -0
  152. package/dist/src/wallet/cbor-serializer.d.ts +82 -0
  153. package/dist/src/wallet/cbor-serializer.js +282 -0
  154. package/dist/src/wallet/chain-dispatcher.d.ts +112 -0
  155. package/dist/src/wallet/chain-dispatcher.js +241 -0
  156. package/dist/src/wallet/cross-chain-aggregator.d.ts +119 -0
  157. package/dist/src/wallet/cross-chain-aggregator.js +235 -0
  158. package/dist/src/wallet/index.d.ts +16 -0
  159. package/dist/src/wallet/index.js +22 -0
  160. package/dist/src/wallet/key-derivation.d.ts +117 -0
  161. package/dist/src/wallet/key-derivation.js +325 -0
  162. package/dist/src/wallet/providers/base-provider.d.ts +111 -0
  163. package/dist/src/wallet/providers/base-provider.js +58 -0
  164. package/dist/src/wallet/providers/cketh-provider.d.ts +104 -0
  165. package/dist/src/wallet/providers/cketh-provider.js +343 -0
  166. package/dist/src/wallet/providers/polkadot-provider.d.ts +115 -0
  167. package/dist/src/wallet/providers/polkadot-provider.js +407 -0
  168. package/dist/src/wallet/providers/solana-provider.d.ts +102 -0
  169. package/dist/src/wallet/providers/solana-provider.js +393 -0
  170. package/dist/src/wallet/transaction-queue.d.ts +133 -0
  171. package/dist/src/wallet/transaction-queue.js +195 -0
  172. package/dist/src/wallet/types.d.ts +167 -0
  173. package/dist/src/wallet/types.js +5 -0
  174. package/dist/src/wallet/vetkeys-adapter.d.ts +134 -0
  175. package/dist/src/wallet/vetkeys-adapter.js +313 -0
  176. package/dist/src/wallet/wallet-manager.d.ts +202 -0
  177. package/dist/src/wallet/wallet-manager.js +451 -0
  178. package/dist/src/wallet/wallet-storage.d.ts +131 -0
  179. package/dist/src/wallet/wallet-storage.js +274 -0
  180. package/macos-wallet-app/AgentVaultWallet/App/AgentVaultWalletApp.swift +54 -0
  181. package/macos-wallet-app/AgentVaultWallet/Models/AppState.swift +102 -0
  182. package/macos-wallet-app/AgentVaultWallet/Models/Chain.swift +121 -0
  183. package/macos-wallet-app/AgentVaultWallet/Models/Wallet.swift +98 -0
  184. package/macos-wallet-app/AgentVaultWallet/Resources/AgentVaultWallet.entitlements +27 -0
  185. package/macos-wallet-app/AgentVaultWallet/Resources/Info.plist +69 -0
  186. package/macos-wallet-app/AgentVaultWallet/Services/BackupService.swift +270 -0
  187. package/macos-wallet-app/AgentVaultWallet/Services/CLIBridge.swift +367 -0
  188. package/macos-wallet-app/AgentVaultWallet/Services/CryptoService.swift +157 -0
  189. package/macos-wallet-app/AgentVaultWallet/Services/FileService.swift +120 -0
  190. package/macos-wallet-app/AgentVaultWallet/Services/KeychainService.swift +219 -0
  191. package/macos-wallet-app/AgentVaultWallet/Utilities/Constants.swift +44 -0
  192. package/macos-wallet-app/AgentVaultWallet/Utilities/Extensions.swift +115 -0
  193. package/macos-wallet-app/AgentVaultWallet/ViewModels/BackupViewModel.swift +237 -0
  194. package/macos-wallet-app/AgentVaultWallet/ViewModels/CreateWalletViewModel.swift +137 -0
  195. package/macos-wallet-app/AgentVaultWallet/ViewModels/ImportWalletViewModel.swift +179 -0
  196. package/macos-wallet-app/AgentVaultWallet/ViewModels/WalletStore.swift +286 -0
  197. package/macos-wallet-app/AgentVaultWallet/Views/Backup/BackupView.swift +235 -0
  198. package/macos-wallet-app/AgentVaultWallet/Views/Backup/RestoreView.swift +316 -0
  199. package/macos-wallet-app/AgentVaultWallet/Views/Create/CreateWalletFlow.swift +438 -0
  200. package/macos-wallet-app/AgentVaultWallet/Views/Import/ImportWalletFlow.swift +399 -0
  201. package/macos-wallet-app/AgentVaultWallet/Views/MainView.swift +134 -0
  202. package/macos-wallet-app/AgentVaultWallet/Views/Settings/SettingsView.swift +276 -0
  203. package/macos-wallet-app/AgentVaultWallet/Views/Sidebar/SidebarView.swift +133 -0
  204. package/macos-wallet-app/AgentVaultWallet/Views/Wallet/DashboardView.swift +233 -0
  205. package/macos-wallet-app/AgentVaultWallet/Views/Wallet/WalletDetailView.swift +281 -0
  206. package/macos-wallet-app/AgentVaultWallet/Views/Wallet/WalletListView.swift +280 -0
  207. package/macos-wallet-app/AgentVaultWallet/Views/Welcome/WelcomeView.swift +176 -0
  208. package/macos-wallet-app/Makefile +47 -0
  209. package/macos-wallet-app/project.yml +40 -0
  210. package/macos-wallet-app/setup.sh +73 -0
  211. package/package.json +10 -2
  212. package/backups/agentvault-backup-test-agent-2026-02-12T17-54-28-967Z.json +0 -28
  213. package/backups/agentvault-backup-test-agent-2026-02-12T17-54-29-032Z.backup +0 -1
  214. package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-373Z.json +0 -28
  215. package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-428Z.backup +0 -1
  216. package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-132Z.json +0 -28
  217. package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-247Z.backup +0 -1
  218. package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-216Z.json +0 -28
  219. package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-283Z.backup +0 -1
  220. package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-772Z.backup +0 -1
  221. package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-793Z.json +0 -28
  222. package/backups/test-backup.json +0 -28
  223. package/scripts/dev-dashboard.mjs +0 -84
  224. package/site/README.md +0 -63
  225. package/site/docusaurus.config.ts +0 -148
  226. package/site/package-lock.json +0 -18383
  227. package/site/package.json +0 -47
  228. package/site/sidebars.ts +0 -86
  229. package/site/static/.gitkeep +0 -0
  230. package/site/static/img/logo.svg +0 -28
  231. package/site/static/img/og-image.svg +0 -35
  232. package/src/archival/archive-manager.ts +0 -372
  233. package/src/archival/arweave-client.ts +0 -289
  234. package/src/backup/backup.ts +0 -315
  235. package/src/cloud-storage/cloud-sync.ts +0 -461
  236. package/src/cloud-storage/provider-detector.ts +0 -198
  237. package/src/debugging/logs.ts +0 -193
  238. package/src/debugging/types.ts +0 -100
  239. package/src/deployment/deployer.ts +0 -274
  240. package/src/deployment/icpClient.ts +0 -620
  241. package/src/deployment/index.ts +0 -46
  242. package/src/deployment/promotion.ts +0 -161
  243. package/src/deployment/types.ts +0 -111
  244. package/src/icp/batch.ts +0 -374
  245. package/src/icp/environment.ts +0 -215
  246. package/src/icp/icpcli.ts +0 -438
  247. package/src/icp/icwasm.ts +0 -222
  248. package/src/icp/index.ts +0 -94
  249. package/src/icp/optimization.ts +0 -242
  250. package/src/icp/tool-detector.ts +0 -110
  251. package/src/icp/types.ts +0 -574
  252. package/src/index.ts +0 -25
  253. package/src/inference/bittensor-client.ts +0 -304
  254. package/src/inference/inference-manager.ts +0 -327
  255. package/src/metrics/metrics.ts +0 -186
  256. package/src/monitoring/alerting.ts +0 -190
  257. package/src/monitoring/health.ts +0 -197
  258. package/src/monitoring/index.ts +0 -38
  259. package/src/monitoring/info.ts +0 -114
  260. package/src/monitoring/types.ts +0 -99
  261. package/src/network/network-config.ts +0 -129
  262. package/src/packaging/compiler.ts +0 -647
  263. package/src/packaging/config-persistence.ts +0 -135
  264. package/src/packaging/config-schemas.ts +0 -156
  265. package/src/packaging/detector.ts +0 -220
  266. package/src/packaging/index.ts +0 -90
  267. package/src/packaging/packager.ts +0 -118
  268. package/src/packaging/parsers/clawdbot.ts +0 -278
  269. package/src/packaging/parsers/cline.ts +0 -223
  270. package/src/packaging/parsers/generic.ts +0 -266
  271. package/src/packaging/parsers/goose.ts +0 -214
  272. package/src/packaging/serializer.ts +0 -260
  273. package/src/packaging/types.ts +0 -144
  274. package/src/packaging/wasmedge-compiler.ts +0 -406
  275. package/src/security/multisig.ts +0 -415
  276. package/src/security/types.ts +0 -416
  277. package/src/security/vetkeys.ts +0 -655
  278. package/src/testing/local-runner.ts +0 -264
  279. package/src/testing/types.ts +0 -104
  280. package/src/wallet/cbor-serializer.ts +0 -323
  281. package/src/wallet/chain-dispatcher.ts +0 -313
  282. package/src/wallet/cross-chain-aggregator.ts +0 -346
  283. package/src/wallet/index.ts +0 -76
  284. package/src/wallet/key-derivation.ts +0 -425
  285. package/src/wallet/providers/base-provider.ts +0 -154
  286. package/src/wallet/providers/cketh-provider.ts +0 -434
  287. package/src/wallet/providers/polkadot-provider.ts +0 -503
  288. package/src/wallet/providers/solana-provider.ts +0 -490
  289. package/src/wallet/transaction-queue.ts +0 -284
  290. package/src/wallet/types.ts +0 -178
  291. package/src/wallet/vetkeys-adapter.ts +0 -431
  292. package/src/wallet/wallet-manager.ts +0 -597
  293. package/src/wallet/wallet-storage.ts +0 -380
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Key Derivation Module
3
+ *
4
+ * Implements BIP39 seed phrase derivation for wallet keys.
5
+ * Supports multiple derivation paths for different blockchains.
6
+ */
7
+ import * as bip39 from 'bip39';
8
+ import * as crypto from 'node:crypto';
9
+ import { encodeAddress } from '@polkadot/util-crypto';
10
+ import { Keypair } from '@solana/web3.js';
11
+ import { HDNodeWallet, SigningKey, computeAddress } from 'ethers';
12
+ /**
13
+ * Default derivation paths for different chains
14
+ */
15
+ const DEFAULT_DERIVATION_PATHS = {
16
+ // Ethereum / ckETH (BIP44)
17
+ eth: "m/44'/60'/0'/0/0",
18
+ // Polkadot (Substrate)
19
+ polkadot: "//hard//stash",
20
+ // Solana (BIP44)
21
+ solana: "m/44'/501'/0'/0'/0'",
22
+ // Bitcoin
23
+ btc: "m/44'/0'/0'/0/0",
24
+ };
25
+ /**
26
+ * Parse derivation path string
27
+ *
28
+ * @param path - Derivation path string (e.g., "m/44'/60'/0'/0/0")
29
+ * @returns Parsed path components
30
+ */
31
+ export function parseDerivationPath(path) {
32
+ const parts = path.split('/');
33
+ if (parts[0] !== 'm') {
34
+ throw new Error('Invalid derivation path: must start with "m"');
35
+ }
36
+ const components = {
37
+ purpose: 0,
38
+ coinType: 0,
39
+ account: 0,
40
+ change: 0,
41
+ index: 0,
42
+ };
43
+ for (let i = 1; i < parts.length; i++) {
44
+ const part = parts[i]?.replace(/'/g, '') || '0';
45
+ const num = parseInt(part, 10);
46
+ switch (i) {
47
+ case 1:
48
+ components.purpose = num;
49
+ break;
50
+ case 2:
51
+ components.coinType = num;
52
+ break;
53
+ case 3:
54
+ components.account = num;
55
+ break;
56
+ case 4:
57
+ components.change = num;
58
+ break;
59
+ case 5:
60
+ components.index = num;
61
+ break;
62
+ }
63
+ }
64
+ return components;
65
+ }
66
+ /**
67
+ * Build derivation path from components
68
+ *
69
+ * @param components - Path components
70
+ * @returns Derivation path string
71
+ */
72
+ export function buildDerivationPath(components) {
73
+ const parts = ['m'];
74
+ parts.push(`${components.purpose}'`);
75
+ parts.push(`${components.coinType}'`);
76
+ parts.push(`${components.account}'`);
77
+ parts.push(`${components.change}`);
78
+ parts.push(`${components.index}`);
79
+ return parts.join('/');
80
+ }
81
+ /**
82
+ * Validate seed phrase (BIP39)
83
+ *
84
+ * @param seedPhrase - Seed phrase to validate
85
+ * @returns True if valid BIP39 phrase
86
+ */
87
+ export function validateSeedPhrase(seedPhrase) {
88
+ return bip39.validateMnemonic(seedPhrase);
89
+ }
90
+ /**
91
+ * Generate seed from seed phrase
92
+ *
93
+ * @param seedPhrase - BIP39 seed phrase
94
+ * @param passphrase - Optional passphrase (default empty)
95
+ * @returns Seed bytes
96
+ */
97
+ export function generateSeedFromMnemonic(seedPhrase, passphrase = '') {
98
+ return bip39.mnemonicToSeedSync(seedPhrase, passphrase);
99
+ }
100
+ /**
101
+ * Generate mnemonic from entropy
102
+ *
103
+ * @param strength - Entropy strength in bits (128, 160, 192, 224, 256)
104
+ * @param rng - Optional RNG function
105
+ * @returns BIP39 mnemonic phrase
106
+ */
107
+ export function generateMnemonic(strength = 128, rng) {
108
+ return bip39.generateMnemonic(strength, rng);
109
+ }
110
+ /**
111
+ * Derive key from seed using HMAC-SHA512
112
+ *
113
+ * @param seed - Seed bytes
114
+ * @param derivationPath - Derivation path
115
+ * @returns Derived key (32 bytes private, 32 bytes chain code)
116
+ */
117
+ function deriveKeyFromSeed(seed, derivationPath) {
118
+ const parts = parseDerivationPath(derivationPath);
119
+ let key = seed.slice(0, 32);
120
+ let chainCode = seed.slice(32, 64);
121
+ for (const part of [parts.purpose, parts.coinType, parts.account, parts.change, parts.index]) {
122
+ const isHardened = part >= 0x80000000;
123
+ const data = Buffer.concat([
124
+ key,
125
+ Buffer.from([0x00]),
126
+ Buffer.alloc(4),
127
+ ]);
128
+ data.writeUint32BE(isHardened ? part : part + 0x80000000, 4);
129
+ const hmac = crypto.createHmac('sha512', chainCode);
130
+ hmac.update(data);
131
+ const result = hmac.digest();
132
+ key = result.slice(0, 32);
133
+ chainCode = result.slice(32, 64);
134
+ }
135
+ return { privateKey: key, chainCode };
136
+ }
137
+ /**
138
+ * Derive Ethereum-compatible key
139
+ *
140
+ * @param seed - Seed bytes
141
+ * @param derivationPath - Derivation path (default: "m/44'/60'/0'/0/0")
142
+ * @returns Derived key with ETH address
143
+ */
144
+ export function deriveEthKey(seed, derivationPath = DEFAULT_DERIVATION_PATHS.eth) {
145
+ const root = HDNodeWallet.fromSeed(seed);
146
+ const node = root.derivePath(derivationPath);
147
+ const privateKeyHex = stripHexPrefix(node.privateKey);
148
+ const publicKeyHex = stripHexPrefix(SigningKey.computePublicKey(node.privateKey, false));
149
+ const address = node.address;
150
+ return {
151
+ privateKey: privateKeyHex,
152
+ publicKey: publicKeyHex,
153
+ address,
154
+ derivationPath,
155
+ };
156
+ }
157
+ /**
158
+ * Derive Polkadot-compatible key
159
+ *
160
+ * Uses SR25519 for key derivation and SS58 for address encoding.
161
+ *
162
+ * @param seed - Seed bytes
163
+ * @param derivationPath - Derivation path (default: "//hard//stash")
164
+ * @returns Derived key with Polkadot address
165
+ */
166
+ export function derivePolkadotKey(seed, derivationPath = DEFAULT_DERIVATION_PATHS.polkadot) {
167
+ const privateKey = seed.slice(0, 32);
168
+ const publicKey = derivePublicKey(privateKey);
169
+ const address = derivePolkadotAddress(Buffer.from(publicKey));
170
+ return {
171
+ privateKey: privateKey.toString('hex'),
172
+ publicKey: publicKey.toString('hex'),
173
+ address,
174
+ derivationPath,
175
+ };
176
+ }
177
+ /**
178
+ * Derive Solana-compatible key
179
+ *
180
+ * @param seed - Seed bytes
181
+ * @param derivationPath - Derivation path (default: "m/44'/501'/0'/0'/0'")
182
+ * @returns Derived key with Solana address
183
+ */
184
+ export function deriveSolanaKey(seed, derivationPath = DEFAULT_DERIVATION_PATHS.solana) {
185
+ // Use BIP44 derivation for Solana
186
+ const derived = deriveKeyFromSeed(seed, derivationPath);
187
+ if (!derived || !derived.privateKey) {
188
+ throw new Error('Failed to derive Solana key');
189
+ }
190
+ // Solana uses Ed25519, takes first 32 bytes as seed material
191
+ const privateKeyBytes = derived.privateKey.subarray(0, 32);
192
+ // Use Solana's Keypair for proper Ed25519 key generation
193
+ const keypair = Keypair.fromSeed(privateKeyBytes);
194
+ return {
195
+ privateKey: Buffer.from(keypair.secretKey).toString('hex'),
196
+ publicKey: Buffer.from(keypair.publicKey.toBytes()).toString('hex'),
197
+ address: keypair.publicKey.toBase58(),
198
+ derivationPath,
199
+ };
200
+ }
201
+ /**
202
+ * Derive public key from private key (simplified)
203
+ *
204
+ * @param privateKey - Private key bytes
205
+ * @returns Public key bytes
206
+ */
207
+ function derivePublicKey(privateKey) {
208
+ // Default to secp256k1 for generic key derivation paths.
209
+ // Chain-specific derivation functions should prefer their own primitives.
210
+ const privateKeyHex = `0x${privateKey.toString('hex')}`;
211
+ const publicKeyHex = SigningKey.computePublicKey(privateKeyHex, false);
212
+ return Buffer.from(stripHexPrefix(publicKeyHex), 'hex');
213
+ }
214
+ /**
215
+ * Derive Polkadot address from public key
216
+ *
217
+ * Uses proper SS58 encoding with Polkadot prefix (0).
218
+ *
219
+ * @param publicKey - Public key bytes (32 bytes for SR25519/ED25519)
220
+ * @returns Polkadot address (SS58 format)
221
+ */
222
+ function derivePolkadotAddress(publicKey) {
223
+ if (publicKey.length !== 32) {
224
+ throw new Error(`Invalid public key length: expected 32 bytes, got ${publicKey.length}`);
225
+ }
226
+ try {
227
+ const address = encodeAddress(publicKey, 0);
228
+ return address;
229
+ }
230
+ catch (error) {
231
+ const message = error instanceof Error ? error.message : 'Unknown error';
232
+ throw new Error(`Failed to derive Polkadot address: ${message}`);
233
+ }
234
+ }
235
+ /**
236
+ * Get default derivation path for chain
237
+ *
238
+ * @param chain - Blockchain type
239
+ * @returns Default derivation path
240
+ */
241
+ export function getDefaultDerivationPath(chain) {
242
+ switch (chain.toLowerCase()) {
243
+ case 'cketh':
244
+ case 'ethereum':
245
+ case 'eth':
246
+ return DEFAULT_DERIVATION_PATHS.eth;
247
+ case 'polkadot':
248
+ case 'dot':
249
+ return DEFAULT_DERIVATION_PATHS.polkadot;
250
+ case 'solana':
251
+ case 'sol':
252
+ return DEFAULT_DERIVATION_PATHS.solana;
253
+ default:
254
+ return DEFAULT_DERIVATION_PATHS.eth;
255
+ }
256
+ }
257
+ /**
258
+ * Derive wallet key based on creation method
259
+ *
260
+ * @param method - Wallet creation method
261
+ * @param seedPhrase - Seed phrase (for 'seed' and 'mnemonic' methods)
262
+ * @param privateKey - Private key (for 'private-key' method)
263
+ * @param derivationPath - Custom derivation path
264
+ * @param chain - Blockchain type
265
+ * @returns Derived key information
266
+ */
267
+ export function deriveWalletKey(method, seedPhrase, privateKey, derivationPath, chain = 'cketh') {
268
+ const effectiveDerivationPath = derivationPath || getDefaultDerivationPath(chain);
269
+ if (method === 'private-key' && privateKey) {
270
+ const normalizedPrivateKey = normalizePrivateKey(privateKey);
271
+ const privateKeyBuffer = Buffer.from(stripHexPrefix(normalizedPrivateKey), 'hex');
272
+ let address;
273
+ let publicKeyHex;
274
+ if (chain === 'cketh' || chain === 'ethereum') {
275
+ publicKeyHex = stripHexPrefix(SigningKey.computePublicKey(normalizedPrivateKey, false));
276
+ address = computeAddress(normalizedPrivateKey);
277
+ }
278
+ else if (chain === 'polkadot') {
279
+ const publicKey = derivePublicKey(privateKeyBuffer);
280
+ publicKeyHex = publicKey.toString('hex');
281
+ address = derivePolkadotAddress(publicKey);
282
+ }
283
+ else {
284
+ // Solana accepts either 32-byte seed or 64-byte secret key material.
285
+ const keypair = privateKeyBuffer.length >= 64
286
+ ? Keypair.fromSecretKey(privateKeyBuffer.subarray(0, 64))
287
+ : Keypair.fromSeed(privateKeyBuffer.subarray(0, 32));
288
+ publicKeyHex = Buffer.from(keypair.publicKey.toBytes()).toString('hex');
289
+ address = keypair.publicKey.toBase58();
290
+ }
291
+ return {
292
+ privateKey: stripHexPrefix(normalizedPrivateKey),
293
+ publicKey: publicKeyHex,
294
+ address,
295
+ derivationPath: effectiveDerivationPath,
296
+ };
297
+ }
298
+ if ((method === 'seed' || method === 'mnemonic') && seedPhrase) {
299
+ // Derive from seed phrase
300
+ if (!validateSeedPhrase(seedPhrase)) {
301
+ throw new Error('Invalid seed phrase');
302
+ }
303
+ const seed = generateSeedFromMnemonic(seedPhrase);
304
+ if (chain === 'cketh' || chain === 'ethereum') {
305
+ return deriveEthKey(seed, effectiveDerivationPath);
306
+ }
307
+ else if (chain === 'polkadot') {
308
+ return derivePolkadotKey(seed, effectiveDerivationPath);
309
+ }
310
+ else if (chain === 'solana') {
311
+ return deriveSolanaKey(seed, effectiveDerivationPath);
312
+ }
313
+ else {
314
+ return deriveEthKey(seed, effectiveDerivationPath);
315
+ }
316
+ }
317
+ throw new Error(`Invalid wallet creation method: ${method}`);
318
+ }
319
+ function stripHexPrefix(value) {
320
+ return value.startsWith('0x') ? value.slice(2) : value;
321
+ }
322
+ function normalizePrivateKey(value) {
323
+ return value.startsWith('0x') ? value : `0x${value}`;
324
+ }
325
+ //# sourceMappingURL=key-derivation.js.map
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Base Wallet Provider
3
+ *
4
+ * Abstract base class for all blockchain wallet providers.
5
+ * Defines common interface for wallet operations.
6
+ */
7
+ import type { ChainType, Balance, Transaction, TransactionRequest, SignedTransaction, ProviderConfig } from '../types.js';
8
+ /**
9
+ * Abstract base class for wallet providers
10
+ */
11
+ export declare abstract class BaseWalletProvider {
12
+ protected config: ProviderConfig;
13
+ protected connected: boolean;
14
+ constructor(config: ProviderConfig);
15
+ /**
16
+ * Connect to blockchain network
17
+ */
18
+ abstract connect(): Promise<void>;
19
+ /**
20
+ * Disconnect from blockchain network
21
+ */
22
+ abstract disconnect(): Promise<void>;
23
+ /**
24
+ * Get wallet balance
25
+ *
26
+ * @param address - Wallet address
27
+ * @returns Wallet balance
28
+ */
29
+ abstract getBalance(address: string): Promise<Balance>;
30
+ /**
31
+ * Send transaction
32
+ *
33
+ * @param from - From address
34
+ * @param request - Transaction request
35
+ * @returns Transaction result
36
+ */
37
+ abstract sendTransaction(from: string, request: TransactionRequest): Promise<Transaction>;
38
+ /**
39
+ * Sign transaction
40
+ *
41
+ * @param tx - Transaction object
42
+ * @param privateKey - Private key for signing
43
+ * @returns Signed transaction
44
+ */
45
+ abstract signTransaction(tx: any, privateKey: string): Promise<SignedTransaction>;
46
+ /**
47
+ * Get transaction history
48
+ *
49
+ * @param address - Wallet address
50
+ * @returns Transaction history
51
+ */
52
+ abstract getTransactionHistory(address: string): Promise<Transaction[]>;
53
+ /**
54
+ * Validate address format
55
+ *
56
+ * @param address - Address to validate
57
+ * @returns True if address is valid
58
+ */
59
+ abstract validateAddress(address: string): boolean;
60
+ /**
61
+ * Check connection status
62
+ *
63
+ * @returns True if connected
64
+ */
65
+ isConnected(): boolean;
66
+ /**
67
+ * Get chain type
68
+ *
69
+ * @returns Chain type
70
+ */
71
+ getChain(): ChainType;
72
+ /**
73
+ * Get provider configuration
74
+ *
75
+ * @returns Provider configuration
76
+ */
77
+ getConfig(): ProviderConfig;
78
+ /**
79
+ * Get RPC URL
80
+ *
81
+ * @returns RPC endpoint URL
82
+ */
83
+ getRpcUrl(): string;
84
+ /**
85
+ * Check if connected to testnet
86
+ *
87
+ * @returns True if using testnet
88
+ */
89
+ isTestnet(): boolean;
90
+ /**
91
+ * Estimate transaction fee
92
+ *
93
+ * @param request - Transaction request
94
+ * @returns Estimated fee (as string)
95
+ */
96
+ abstract estimateFee(request: TransactionRequest): Promise<string>;
97
+ /**
98
+ * Get current block number
99
+ *
100
+ * @returns Block number
101
+ */
102
+ abstract getBlockNumber(): Promise<number>;
103
+ /**
104
+ * Get transaction by hash
105
+ *
106
+ * @param txHash - Transaction hash
107
+ * @returns Transaction details
108
+ */
109
+ abstract getTransaction(txHash: string): Promise<Transaction | null>;
110
+ }
111
+ //# sourceMappingURL=base-provider.d.ts.map
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Base Wallet Provider
3
+ *
4
+ * Abstract base class for all blockchain wallet providers.
5
+ * Defines common interface for wallet operations.
6
+ */
7
+ /**
8
+ * Abstract base class for wallet providers
9
+ */
10
+ export class BaseWalletProvider {
11
+ config;
12
+ connected;
13
+ constructor(config) {
14
+ this.config = config;
15
+ this.connected = false;
16
+ }
17
+ /**
18
+ * Check connection status
19
+ *
20
+ * @returns True if connected
21
+ */
22
+ isConnected() {
23
+ return this.connected;
24
+ }
25
+ /**
26
+ * Get chain type
27
+ *
28
+ * @returns Chain type
29
+ */
30
+ getChain() {
31
+ return this.config.chain;
32
+ }
33
+ /**
34
+ * Get provider configuration
35
+ *
36
+ * @returns Provider configuration
37
+ */
38
+ getConfig() {
39
+ return this.config;
40
+ }
41
+ /**
42
+ * Get RPC URL
43
+ *
44
+ * @returns RPC endpoint URL
45
+ */
46
+ getRpcUrl() {
47
+ return this.config.rpcUrl || '';
48
+ }
49
+ /**
50
+ * Check if connected to testnet
51
+ *
52
+ * @returns True if using testnet
53
+ */
54
+ isTestnet() {
55
+ return this.config.isTestnet ?? false;
56
+ }
57
+ }
58
+ //# sourceMappingURL=base-provider.js.map
@@ -0,0 +1,104 @@
1
+ /**
2
+ * ckETH Wallet Provider
3
+ *
4
+ * Provider for Ethereum-compatible wallets on ICP ckETH.
5
+ * Supports balance queries, transactions, and signing.
6
+ */
7
+ import type { Balance, Transaction, TransactionRequest, SignedTransaction, ProviderConfig } from '../types.js';
8
+ import { BaseWalletProvider } from './base-provider.js';
9
+ /**
10
+ * ckETH provider configuration
11
+ */
12
+ interface CkEthConfig extends ProviderConfig {
13
+ /** Ethereum JSON-RPC endpoint */
14
+ rpcUrl: string;
15
+ /** Chain ID (1 = Mainnet, 5 = Goerli, 11155111 = Sepolia) */
16
+ chainId?: number;
17
+ /** Etherscan API key (optional, for transaction history) */
18
+ etherscanApiKey?: string;
19
+ }
20
+ /**
21
+ * ckETH wallet provider
22
+ */
23
+ export declare class CkEthProvider extends BaseWalletProvider {
24
+ private provider;
25
+ private chainId;
26
+ private etherscanApiKey;
27
+ constructor(config: CkEthConfig);
28
+ /**
29
+ * Resolve the RPC URL to use for connections
30
+ *
31
+ * Priority:
32
+ * 1. Explicitly configured URL
33
+ * 2. Environment variable (ETHEREUM_RPC_URL or SEPOLIA_RPC_URL)
34
+ * 3. Infura with API key from environment
35
+ * 4. Public RPC endpoints (fallback, rate-limited)
36
+ *
37
+ * @returns RPC URL
38
+ */
39
+ private resolveRpcUrl;
40
+ /**
41
+ * Connect to Ethereum network via RPC
42
+ */
43
+ connect(): Promise<void>;
44
+ /**
45
+ * Disconnect from network
46
+ */
47
+ disconnect(): Promise<void>;
48
+ /**
49
+ * Get wallet balance
50
+ */
51
+ getBalance(address: string): Promise<Balance>;
52
+ /**
53
+ * Send transaction
54
+ */
55
+ sendTransaction(from: string, request: TransactionRequest): Promise<Transaction>;
56
+ /**
57
+ * Sign transaction
58
+ */
59
+ signTransaction(tx: any, privateKey: string): Promise<SignedTransaction>;
60
+ /**
61
+ * Get transaction history
62
+ *
63
+ * Uses Etherscan API to fetch transaction history.
64
+ * Requires ETHERSCAN_API_KEY environment variable or etherscanApiKey in config.
65
+ *
66
+ * @param address - Wallet address to get history for
67
+ * @returns Array of transactions
68
+ */
69
+ getTransactionHistory(address: string): Promise<Transaction[]>;
70
+ /**
71
+ * Validate Ethereum address
72
+ */
73
+ validateAddress(address: string): boolean;
74
+ /**
75
+ * Estimate transaction fee
76
+ */
77
+ estimateFee(request: TransactionRequest): Promise<string>;
78
+ /**
79
+ * Get current block number
80
+ */
81
+ getBlockNumber(): Promise<number>;
82
+ /**
83
+ * Get transaction by hash
84
+ */
85
+ getTransaction(txHash: string): Promise<Transaction | null>;
86
+ /**
87
+ * Create transaction from request
88
+ */
89
+ private populateTransaction;
90
+ /**
91
+ * Get default RPC URL for chain
92
+ *
93
+ * @param isTestnet - Whether to get testnet URL
94
+ * @returns RPC URL from environment or public endpoint
95
+ * @throws Error if no RPC URL is configured
96
+ */
97
+ static getDefaultRpcUrl(isTestnet?: boolean): string;
98
+ /**
99
+ * Get chain ID
100
+ */
101
+ getChainId(): number;
102
+ }
103
+ export {};
104
+ //# sourceMappingURL=cketh-provider.d.ts.map