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,179 @@
1
+ /**
2
+ * VetKeys Integration for Threshold Key Derivation
3
+ *
4
+ * This module provides VetKeys protocol implementation for threshold key derivation.
5
+ * Supports Shamir's Secret Sharing (SSS) for threshold cryptography.
6
+ *
7
+ * Security Properties:
8
+ * - Threshold signatures prevent single points of failure
9
+ * - Distributed trust model
10
+ * - Combiner-based key reconstruction
11
+ *
12
+ * Protocol Features:
13
+ * - Key derivation using secret sharing
14
+ * - Threshold signature verification
15
+ * - Key reconstruction without revealing secrets
16
+ *
17
+ * Note: VetKeysClient interface is defined in types.ts.
18
+ * This implementation class avoids the naming conflict.
19
+ */
20
+ import type { EncryptedData, VetKeysOptions, EncryptionAlgorithm, VetKeysDerivedKey as DerivedKey } from './types.js';
21
+ export declare class VetKeysImplementation {
22
+ private config;
23
+ private canisterId?;
24
+ private useCanister;
25
+ constructor(options?: VetKeysOptions & {
26
+ canisterId?: string;
27
+ useCanister?: boolean;
28
+ });
29
+ /**
30
+ * Decrypt JSON data using seed phrase
31
+ *
32
+ * @param encrypted - Encrypted data to decrypt
33
+ * @param seedPhrase - Seed phrase for key derivation
34
+ * @returns Decrypted JSON object
35
+ */
36
+ static decryptJSON<T = unknown>(encrypted: EncryptedData, seedPhrase: string): Promise<T>;
37
+ /**
38
+ * Derive threshold key from seed phrase
39
+ *
40
+ * Implements Shamir's Secret Sharing for threshold key derivation.
41
+ * Generates n secret shares (where threshold = t out of n)
42
+ * Each share is encrypted and can be used to reconstruct the master key.
43
+ *
44
+ * @param seedPhrase - BIP39 seed phrase
45
+ * @param options - Optional derivation options
46
+ * @returns Derived key with threshold parameters
47
+ */
48
+ deriveThresholdKey(seedPhrase: string, options?: VetKeysOptions & {
49
+ threshold?: number;
50
+ totalParties?: number;
51
+ encryptionAlgorithm?: EncryptionAlgorithm;
52
+ }): Promise<DerivedKey>;
53
+ /**
54
+ * Generate secret shares using Shamir's Secret Sharing
55
+ *
56
+ * @param seedPhrase - Master secret
57
+ * @param threshold - Number of shares to create (t)
58
+ * @param totalParties - Total number of participants (n)
59
+ * @param algorithm - Encryption algorithm to use
60
+ * @returns Array of encrypted shares
61
+ */
62
+ private generateSecretShares;
63
+ /**
64
+ * Generate share identifier using cryptographically secure random bytes
65
+ */
66
+ private generateShareId;
67
+ /**
68
+ * Generate unique secret for a participant
69
+ *
70
+ * @param seedPhrase - Master secret
71
+ * @param participantIndex - Participant index (1-based)
72
+ */
73
+ private generateParticipantSecret;
74
+ /**
75
+ * Encrypt a secret share
76
+ *
77
+ * @param secret - Secret to encrypt
78
+ * @param algorithm - Encryption algorithm
79
+ */
80
+ private encryptShare;
81
+ /**
82
+ * Generate commitment from all shares
83
+ */
84
+ private generateCommitment;
85
+ /**
86
+ * Derive master key from seed phrase (for local use)
87
+ *
88
+ * Uses PBKDF2 for key derivation with a derived salt from the seed.
89
+ * This is NOT the threshold key, but the master secret that participants share.
90
+ */
91
+ private deriveMasterKey;
92
+ /**
93
+ * Verify encryption was created by VetKeys
94
+ *
95
+ * Validates that the encrypted data structure is valid and properly formatted.
96
+ *
97
+ * @param encrypted - Encrypted data to verify
98
+ * @returns True if the encryption structure is valid
99
+ */
100
+ verifyEncryption(encrypted: EncryptedData): Promise<boolean>;
101
+ /**
102
+ * Get encryption status
103
+ */
104
+ getEncryptionStatus(): {
105
+ thresholdSupported: boolean;
106
+ totalParticipants: number;
107
+ currentThreshold: number;
108
+ encryptionAlgorithm: EncryptionAlgorithm;
109
+ keyDerivation: string;
110
+ };
111
+ /**
112
+ * Store encrypted secret on canister
113
+ *
114
+ * @param secretId - ID of the secret
115
+ * @param encryptedSecret - Encrypted secret data
116
+ * @returns True if stored successfully
117
+ */
118
+ storeEncryptedSecretOnCanister(secretId: string, encryptedSecret: {
119
+ ciphertext: Uint8Array;
120
+ iv: Uint8Array;
121
+ tag: Uint8Array;
122
+ algorithm: EncryptionAlgorithm;
123
+ }): Promise<boolean>;
124
+ /**
125
+ * Retrieve encrypted secret from canister
126
+ *
127
+ * @param secretId - ID of the secret
128
+ * @returns Encrypted secret data or null
129
+ */
130
+ getEncryptedSecretFromCanister(secretId: string): Promise<{
131
+ ciphertext: Uint8Array;
132
+ iv: Uint8Array;
133
+ tag: Uint8Array;
134
+ algorithm: EncryptionAlgorithm;
135
+ } | null>;
136
+ /**
137
+ * List all encrypted secrets from canister
138
+ *
139
+ * @returns Array of secret IDs
140
+ */
141
+ listEncryptedSecretsOnCanister(): Promise<string[]>;
142
+ /**
143
+ * Delete encrypted secret from canister
144
+ *
145
+ * @param secretId - ID of the secret
146
+ * @returns True if deleted successfully
147
+ */
148
+ deleteEncryptedSecretFromCanister(secretId: string): Promise<boolean>;
149
+ /**
150
+ * Verify threshold signature with canister
151
+ *
152
+ * IMPORTANT: Requires VetKeys canister to be deployed and connected.
153
+ * Returns false if canister is not available.
154
+ *
155
+ * @param signature - Signature to verify
156
+ * @param message - Original message
157
+ * @returns True if signature is valid
158
+ */
159
+ verifyThresholdSignatureCanister(signature: string, message: string): Promise<boolean>;
160
+ /**
161
+ * Get VetKeys status from canister
162
+ *
163
+ * @returns VetKeys status information
164
+ */
165
+ getVetKeysStatusFromCanister(): Promise<{
166
+ enabled: boolean;
167
+ thresholdSupported: boolean;
168
+ mode: 'mock' | 'production';
169
+ }>;
170
+ }
171
+ /**
172
+ * Decrypt JSON data using seed phrase
173
+ *
174
+ * @param encrypted - Encrypted data to decrypt
175
+ * @param seedPhrase - Seed phrase for key derivation
176
+ * @returns Decrypted JSON object
177
+ */
178
+ export declare function decryptJSON<T = unknown>(encrypted: EncryptedData, seedPhrase: string): Promise<T>;
179
+ //# sourceMappingURL=vetkeys.d.ts.map
@@ -0,0 +1,499 @@
1
+ /**
2
+ * VetKeys Integration for Threshold Key Derivation
3
+ *
4
+ * This module provides VetKeys protocol implementation for threshold key derivation.
5
+ * Supports Shamir's Secret Sharing (SSS) for threshold cryptography.
6
+ *
7
+ * Security Properties:
8
+ * - Threshold signatures prevent single points of failure
9
+ * - Distributed trust model
10
+ * - Combiner-based key reconstruction
11
+ *
12
+ * Protocol Features:
13
+ * - Key derivation using secret sharing
14
+ * - Threshold signature verification
15
+ * - Key reconstruction without revealing secrets
16
+ *
17
+ * Note: VetKeysClient interface is defined in types.ts.
18
+ * This implementation class avoids the naming conflict.
19
+ */
20
+ import * as crypto from 'node:crypto';
21
+ function toCanisterAlgorithm(algorithm) {
22
+ return algorithm === 'aes-256-gcm' ? 'aes_256_gcm' : 'chacha20_poly1305';
23
+ }
24
+ function fromCanisterAlgorithm(canisterAlg) {
25
+ return canisterAlg === 'aes_256_gcm' ? 'aes-256-gcm' : 'chacha20-poly1305';
26
+ }
27
+ export class VetKeysImplementation {
28
+ config;
29
+ canisterId;
30
+ useCanister;
31
+ constructor(options = {}) {
32
+ this.config = {
33
+ threshold: options.threshold ?? 2,
34
+ totalParties: options.totalParties ?? 3,
35
+ encryptionAlgorithm: options.encryptionAlgorithm ?? 'aes-256-gcm',
36
+ vetKeysCanisterId: options.canisterId,
37
+ };
38
+ this.canisterId = options.canisterId;
39
+ this.useCanister = options.useCanister ?? !!options.canisterId;
40
+ }
41
+ /**
42
+ * Decrypt JSON data using seed phrase
43
+ *
44
+ * @param encrypted - Encrypted data to decrypt
45
+ * @param seedPhrase - Seed phrase for key derivation
46
+ * @returns Decrypted JSON object
47
+ */
48
+ static async decryptJSON(encrypted, seedPhrase) {
49
+ const crypto = await import('node:crypto');
50
+ const bip39 = await import('bip39');
51
+ // Derive key from seed phrase
52
+ const seed = await bip39.mnemonicToSeed(seedPhrase);
53
+ const key = crypto.pbkdf2Sync(seed, encrypted.salt, 100000, 32, 'sha256');
54
+ // Decode IV and ciphertext
55
+ const iv = Buffer.from(encrypted.iv, 'hex');
56
+ const ciphertext = Buffer.from(encrypted.ciphertext, 'hex');
57
+ // Decrypt based on algorithm
58
+ let algorithm;
59
+ if (encrypted.algorithm === 'aes-256-gcm') {
60
+ algorithm = 'aes-256-gcm';
61
+ }
62
+ else {
63
+ algorithm = encrypted.algorithm.replace('-', '');
64
+ }
65
+ const decipher = crypto.createDecipheriv(algorithm, key, iv);
66
+ const decrypted = Buffer.concat([
67
+ decipher.update(ciphertext),
68
+ decipher.final(),
69
+ ]);
70
+ return JSON.parse(decrypted.toString('utf-8'));
71
+ }
72
+ /**
73
+ * Derive threshold key from seed phrase
74
+ *
75
+ * Implements Shamir's Secret Sharing for threshold key derivation.
76
+ * Generates n secret shares (where threshold = t out of n)
77
+ * Each share is encrypted and can be used to reconstruct the master key.
78
+ *
79
+ * @param seedPhrase - BIP39 seed phrase
80
+ * @param options - Optional derivation options
81
+ * @returns Derived key with threshold parameters
82
+ */
83
+ async deriveThresholdKey(seedPhrase, options = {}) {
84
+ const threshold = options.threshold ?? this.config.threshold;
85
+ const totalParties = options.totalParties ?? this.config.totalParties;
86
+ const algorithm = options.encryptionAlgorithm ?? this.config.encryptionAlgorithm;
87
+ // Validate threshold
88
+ if (threshold < 1 || threshold > totalParties) {
89
+ throw new Error(`Threshold must be between 1 and totalParticipants (${totalParties}). Got: ${threshold}`);
90
+ }
91
+ try {
92
+ // Derive n secret shares from seed phrase
93
+ const shares = await this.generateSecretShares(seedPhrase, threshold, totalParties, algorithm);
94
+ // Generate share metadata
95
+ const shareMetadata = shares.map((share, index) => ({
96
+ index: index + 1,
97
+ shareId: this.generateShareId(),
98
+ participantId: (index + 1).toString(),
99
+ encryptedShare: share.encryptedShare,
100
+ commitment: share.commitment,
101
+ }));
102
+ // Generate commitment
103
+ const commitment = await this.generateCommitment(shares);
104
+ // Generate verification parameters
105
+ const verification = {
106
+ threshold,
107
+ shares,
108
+ commitment,
109
+ algorithm,
110
+ encryptionAlgorithm: algorithm,
111
+ createdAt: new Date().toISOString(),
112
+ };
113
+ // Derive master key from seed phrase (for local use)
114
+ const derivedKey = await this.deriveMasterKey(seedPhrase, algorithm);
115
+ return {
116
+ type: 'threshold',
117
+ key: derivedKey.key,
118
+ method: derivedKey.method,
119
+ seedPhrase,
120
+ threshold: threshold,
121
+ totalParties: totalParties,
122
+ algorithm: algorithm,
123
+ shares,
124
+ shareMetadata,
125
+ commitment,
126
+ verification,
127
+ };
128
+ }
129
+ catch (error) {
130
+ const message = error instanceof Error ? error.message : 'Unknown error';
131
+ throw new Error(`Failed to derive threshold key: ${message}`);
132
+ }
133
+ }
134
+ /**
135
+ * Generate secret shares using Shamir's Secret Sharing
136
+ *
137
+ * @param seedPhrase - Master secret
138
+ * @param threshold - Number of shares to create (t)
139
+ * @param totalParties - Total number of participants (n)
140
+ * @param algorithm - Encryption algorithm to use
141
+ * @returns Array of encrypted shares
142
+ */
143
+ async generateSecretShares(seedPhrase, threshold, totalParties, algorithm) {
144
+ const shares = [];
145
+ const masterCommitment = await this.generateCommitment(shares);
146
+ for (let i = 0; i < threshold; i++) {
147
+ const shareId = this.generateShareId();
148
+ const participantId = i + 1;
149
+ // Generate unique secret for this participant
150
+ const participantSecret = this.generateParticipantSecret(seedPhrase, i, totalParties);
151
+ // Encrypt share with participant's secret
152
+ const { encryptedShare, commitment: shareCommitment } = await this.encryptShare(participantSecret, masterCommitment, algorithm);
153
+ shares.push({
154
+ shareId,
155
+ participantId: participantId.toString(),
156
+ encryptedShare,
157
+ commitment: shareCommitment,
158
+ });
159
+ }
160
+ return shares;
161
+ }
162
+ /**
163
+ * Generate share identifier using cryptographically secure random bytes
164
+ */
165
+ generateShareId() {
166
+ const randomBytes = crypto.randomBytes(4);
167
+ const timestamp = Date.now().toString(36);
168
+ const randomHex = randomBytes.toString('hex').substring(0, 8);
169
+ return `share_${timestamp}_${randomHex}`;
170
+ }
171
+ /**
172
+ * Generate unique secret for a participant
173
+ *
174
+ * @param seedPhrase - Master secret
175
+ * @param participantIndex - Participant index (1-based)
176
+ */
177
+ generateParticipantSecret(seedPhrase, participantIndex, _totalParties) {
178
+ const secretBytes = Buffer.from(seedPhrase, 'utf8');
179
+ // Create unique secret for this participant by adding participant index
180
+ const participantSuffix = Buffer.concat([Buffer.from([participantIndex]), secretBytes]);
181
+ return participantSuffix.toString('hex');
182
+ }
183
+ /**
184
+ * Encrypt a secret share
185
+ *
186
+ * @param secret - Secret to encrypt
187
+ * @param algorithm - Encryption algorithm
188
+ */
189
+ async encryptShare(secret, _commitment, algorithm) {
190
+ const crypto = await import('node:crypto');
191
+ const secretBuffer = Buffer.from(secret, 'utf-8');
192
+ const iv = algorithm === 'aes-256-gcm' ? crypto.randomBytes(12) : crypto.randomBytes(16);
193
+ const algorithmName = algorithm.replace('-', '');
194
+ const encryptionKey = crypto.pbkdf2Sync(secretBuffer, iv, 100000, 32, 'sha256');
195
+ const cipher = crypto.createCipheriv(algorithmName, encryptionKey, iv);
196
+ const encryptedShare = Buffer.concat([
197
+ cipher.update(secretBuffer),
198
+ cipher.final(),
199
+ ]);
200
+ const commitmentHash = crypto.createHash('sha256')
201
+ .update(encryptedShare)
202
+ .digest();
203
+ return {
204
+ encryptedShare: encryptedShare.toString('hex'),
205
+ commitment: commitmentHash.toString('hex'),
206
+ };
207
+ }
208
+ /**
209
+ * Generate commitment from all shares
210
+ */
211
+ async generateCommitment(shares) {
212
+ const crypto = await import('node:crypto');
213
+ const hash = crypto.createHash('sha256');
214
+ // Combine all encrypted shares
215
+ for (const share of shares) {
216
+ const shareBuffer = Buffer.from(share.encryptedShare, 'hex');
217
+ hash.update(shareBuffer);
218
+ }
219
+ return hash.digest('hex');
220
+ }
221
+ /**
222
+ * Derive master key from seed phrase (for local use)
223
+ *
224
+ * Uses PBKDF2 for key derivation with a derived salt from the seed.
225
+ * This is NOT the threshold key, but the master secret that participants share.
226
+ */
227
+ async deriveMasterKey(seedPhrase, _algorithm) {
228
+ const crypto = await import('node:crypto');
229
+ const bip39 = await import('bip39');
230
+ const seed = await bip39.mnemonicToSeed(seedPhrase);
231
+ // Derive salt from seed (first 16 bytes) for unique per-wallet salting
232
+ const salt = crypto.createHash('sha256')
233
+ .update(seed.slice(0, 16))
234
+ .update('agentvault-v1')
235
+ .digest();
236
+ // Derive key using PBKDF2 with unique salt
237
+ const key = crypto.pbkdf2Sync(seed, salt, 100000, 32, 'sha256');
238
+ return {
239
+ key: key.toString('hex'),
240
+ method: 'pbkdf2',
241
+ };
242
+ }
243
+ /**
244
+ * Verify encryption was created by VetKeys
245
+ *
246
+ * Validates that the encrypted data structure is valid and properly formatted.
247
+ *
248
+ * @param encrypted - Encrypted data to verify
249
+ * @returns True if the encryption structure is valid
250
+ */
251
+ async verifyEncryption(encrypted) {
252
+ if (!encrypted) {
253
+ return false;
254
+ }
255
+ if (!encrypted.algorithm || !['aes-256-gcm', 'chacha20-poly1305'].includes(encrypted.algorithm)) {
256
+ return false;
257
+ }
258
+ if (!encrypted.iv || typeof encrypted.iv !== 'string') {
259
+ return false;
260
+ }
261
+ const ivBytes = Buffer.from(encrypted.iv, 'hex');
262
+ const expectedIvLength = encrypted.algorithm === 'aes-256-gcm' ? 12 : 16;
263
+ if (ivBytes.length !== expectedIvLength) {
264
+ return false;
265
+ }
266
+ if (!encrypted.salt || typeof encrypted.salt !== 'string') {
267
+ return false;
268
+ }
269
+ const saltBytes = Buffer.from(encrypted.salt, 'hex');
270
+ if (saltBytes.length < 8) {
271
+ return false;
272
+ }
273
+ if (!encrypted.ciphertext || typeof encrypted.ciphertext !== 'string') {
274
+ return false;
275
+ }
276
+ const ciphertextBytes = Buffer.from(encrypted.ciphertext, 'hex');
277
+ if (ciphertextBytes.length === 0) {
278
+ return false;
279
+ }
280
+ if (encrypted.encryptedAt) {
281
+ const timestamp = new Date(encrypted.encryptedAt);
282
+ if (isNaN(timestamp.getTime())) {
283
+ return false;
284
+ }
285
+ }
286
+ return true;
287
+ }
288
+ /**
289
+ * Get encryption status
290
+ */
291
+ getEncryptionStatus() {
292
+ return {
293
+ thresholdSupported: true,
294
+ totalParticipants: this.config.totalParties,
295
+ currentThreshold: this.config.threshold,
296
+ encryptionAlgorithm: this.config.encryptionAlgorithm,
297
+ keyDerivation: 'shamir-ss',
298
+ };
299
+ }
300
+ /**
301
+ * Store encrypted secret on canister
302
+ *
303
+ * @param secretId - ID of the secret
304
+ * @param encryptedSecret - Encrypted secret data
305
+ * @returns True if stored successfully
306
+ */
307
+ async storeEncryptedSecretOnCanister(secretId, encryptedSecret) {
308
+ if (!this.useCanister) {
309
+ console.warn('Canister integration disabled, skipping canister storage');
310
+ return false;
311
+ }
312
+ if (!this.canisterId) {
313
+ console.warn('Canister ID not configured, skipping canister storage');
314
+ return false;
315
+ }
316
+ try {
317
+ const { createActor } = await import('../canister/actor.js');
318
+ const actor = createActor(this.canisterId);
319
+ const result = await actor.storeEncryptedSecret({
320
+ id: secretId,
321
+ ciphertext: new Uint8Array(encryptedSecret.ciphertext),
322
+ iv: new Uint8Array(encryptedSecret.iv),
323
+ tag: new Uint8Array(encryptedSecret.tag),
324
+ algorithm: toCanisterAlgorithm(encryptedSecret.algorithm),
325
+ createdAt: Date.now(),
326
+ });
327
+ if ('ok' in result) {
328
+ console.log('Encrypted secret stored on canister:', secretId);
329
+ return true;
330
+ }
331
+ return false;
332
+ }
333
+ catch (error) {
334
+ const message = error instanceof Error ? error.message : 'Unknown error';
335
+ console.warn(`Failed to store encrypted secret on canister: ${message}`);
336
+ return false;
337
+ }
338
+ }
339
+ /**
340
+ * Retrieve encrypted secret from canister
341
+ *
342
+ * @param secretId - ID of the secret
343
+ * @returns Encrypted secret data or null
344
+ */
345
+ async getEncryptedSecretFromCanister(secretId) {
346
+ if (!this.canisterId) {
347
+ return null;
348
+ }
349
+ try {
350
+ const { createActor } = await import('../canister/actor.js');
351
+ const actor = createActor(this.canisterId);
352
+ const result = await actor.getEncryptedSecret(secretId);
353
+ if (!result || result.length === 0) {
354
+ return null;
355
+ }
356
+ const [secret] = result;
357
+ return {
358
+ ciphertext: new Uint8Array(secret.ciphertext),
359
+ iv: new Uint8Array(secret.iv),
360
+ tag: new Uint8Array(secret.tag),
361
+ algorithm: fromCanisterAlgorithm(secret.algorithm),
362
+ };
363
+ }
364
+ catch (error) {
365
+ const message = error instanceof Error ? error.message : 'Unknown error';
366
+ console.warn(`Failed to retrieve encrypted secret from canister: ${message}`);
367
+ return null;
368
+ }
369
+ }
370
+ /**
371
+ * List all encrypted secrets from canister
372
+ *
373
+ * @returns Array of secret IDs
374
+ */
375
+ async listEncryptedSecretsOnCanister() {
376
+ if (!this.canisterId) {
377
+ return [];
378
+ }
379
+ try {
380
+ const { createActor } = await import('../canister/actor.js');
381
+ const actor = createActor(this.canisterId);
382
+ const secrets = await actor.listEncryptedSecrets();
383
+ return secrets.map(s => s.id);
384
+ }
385
+ catch (error) {
386
+ const message = error instanceof Error ? error.message : 'Unknown error';
387
+ console.warn(`Failed to list encrypted secrets from canister: ${message}`);
388
+ return [];
389
+ }
390
+ }
391
+ /**
392
+ * Delete encrypted secret from canister
393
+ *
394
+ * @param secretId - ID of the secret
395
+ * @returns True if deleted successfully
396
+ */
397
+ async deleteEncryptedSecretFromCanister(secretId) {
398
+ if (!this.canisterId) {
399
+ return false;
400
+ }
401
+ try {
402
+ const { createActor } = await import('../canister/actor.js');
403
+ const actor = createActor(this.canisterId);
404
+ const result = await actor.deleteEncryptedSecret(secretId);
405
+ if ('ok' in result) {
406
+ return true;
407
+ }
408
+ return false;
409
+ }
410
+ catch (error) {
411
+ const message = error instanceof Error ? error.message : 'Unknown error';
412
+ console.warn(`Failed to delete encrypted secret from canister: ${message}`);
413
+ return false;
414
+ }
415
+ }
416
+ /**
417
+ * Verify threshold signature with canister
418
+ *
419
+ * IMPORTANT: Requires VetKeys canister to be deployed and connected.
420
+ * Returns false if canister is not available.
421
+ *
422
+ * @param signature - Signature to verify
423
+ * @param message - Original message
424
+ * @returns True if signature is valid
425
+ */
426
+ async verifyThresholdSignatureCanister(signature, message) {
427
+ if (!this.canisterId) {
428
+ console.warn('VetKeys canister not configured: cannot verify threshold signature');
429
+ return false;
430
+ }
431
+ try {
432
+ const { createActor } = await import('../canister/actor.js');
433
+ const actor = createActor(this.canisterId);
434
+ const result = await actor.verifyThresholdSignature(signature, message);
435
+ if ('ok' in result && result.ok === 'verified') {
436
+ return true;
437
+ }
438
+ return false;
439
+ }
440
+ catch (error) {
441
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
442
+ console.warn(`Failed to verify threshold signature on canister: ${errorMessage}`);
443
+ return false;
444
+ }
445
+ }
446
+ /**
447
+ * Get VetKeys status from canister
448
+ *
449
+ * @returns VetKeys status information
450
+ */
451
+ async getVetKeysStatusFromCanister() {
452
+ if (!this.canisterId) {
453
+ return {
454
+ enabled: false,
455
+ thresholdSupported: true,
456
+ mode: 'mock',
457
+ };
458
+ }
459
+ try {
460
+ const { createActor } = await import('../canister/actor.js');
461
+ const actor = createActor(this.canisterId);
462
+ const status = await actor.getVetKeysStatus();
463
+ let mode = 'mock';
464
+ const hasMockMode = status.mode && typeof status.mode === 'object' && 'mock' in status.mode;
465
+ const hasProductionMode = status.mode && typeof status.mode === 'object' && 'production' in status.mode;
466
+ if (hasMockMode) {
467
+ mode = 'mock';
468
+ }
469
+ else if (hasProductionMode) {
470
+ mode = 'production';
471
+ }
472
+ return {
473
+ enabled: status.enabled,
474
+ thresholdSupported: status.thresholdSupported,
475
+ mode: mode,
476
+ };
477
+ }
478
+ catch (error) {
479
+ const message = error instanceof Error ? error.message : 'Unknown error';
480
+ console.warn(`Failed to get VetKeys status from canister: ${message}`);
481
+ return {
482
+ enabled: false,
483
+ thresholdSupported: true,
484
+ mode: 'mock',
485
+ };
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Decrypt JSON data using seed phrase
491
+ *
492
+ * @param encrypted - Encrypted data to decrypt
493
+ * @param seedPhrase - Seed phrase for key derivation
494
+ * @returns Decrypted JSON object
495
+ */
496
+ export async function decryptJSON(encrypted, seedPhrase) {
497
+ return VetKeysImplementation.decryptJSON(encrypted, seedPhrase);
498
+ }
499
+ //# sourceMappingURL=vetkeys.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Testing module
3
+ */
4
+ export * from './types.js';
5
+ export * from './local-runner.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Testing module
3
3
  */
4
-
5
4
  export * from './types.js';
6
5
  export * from './local-runner.js';
6
+ //# sourceMappingURL=index.js.map