@unlink-xyz/core 0.1.3 → 0.1.4

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 (369) hide show
  1. package/README.md +9 -0
  2. package/dist/account/{zkAccount.d.ts → account.d.ts} +36 -5
  3. package/dist/account/account.d.ts.map +1 -0
  4. package/dist/account/accounts.d.ts +42 -0
  5. package/dist/account/accounts.d.ts.map +1 -0
  6. package/dist/account/seed.d.ts +45 -0
  7. package/dist/account/seed.d.ts.map +1 -0
  8. package/dist/account/serialization.d.ts +6 -0
  9. package/dist/account/serialization.d.ts.map +1 -0
  10. package/dist/browser/index.js +56221 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/browser/wallet/index.js +55942 -0
  13. package/dist/browser/wallet/index.js.map +1 -0
  14. package/dist/clients/broadcaster.d.ts +8 -2
  15. package/dist/clients/broadcaster.d.ts.map +1 -1
  16. package/dist/clients/http.d.ts +6 -0
  17. package/dist/clients/http.d.ts.map +1 -1
  18. package/dist/clients/indexer.d.ts +16 -0
  19. package/dist/clients/indexer.d.ts.map +1 -1
  20. package/dist/config.d.ts +30 -9
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/constants.d.ts +6 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/core.d.ts.map +1 -1
  25. package/dist/crypto/adapters/index.d.ts +17 -0
  26. package/dist/crypto/adapters/index.d.ts.map +1 -0
  27. package/dist/crypto/adapters/polyfills.d.ts +5 -0
  28. package/dist/crypto/adapters/polyfills.d.ts.map +1 -0
  29. package/dist/crypto/encrypt.d.ts +33 -0
  30. package/dist/crypto/encrypt.d.ts.map +1 -0
  31. package/dist/crypto/secure-memory.d.ts +25 -0
  32. package/dist/crypto/secure-memory.d.ts.map +1 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/history/index.d.ts +3 -0
  36. package/dist/history/index.d.ts.map +1 -0
  37. package/dist/history/service.d.ts +46 -0
  38. package/dist/history/service.d.ts.map +1 -0
  39. package/dist/history/types.d.ts +21 -0
  40. package/dist/history/types.d.ts.map +1 -0
  41. package/dist/index.d.ts +16 -7
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +6721 -19
  44. package/dist/index.js.map +1 -0
  45. package/dist/keys/address.d.ts +13 -0
  46. package/dist/keys/address.d.ts.map +1 -0
  47. package/dist/keys/derive.d.ts +37 -0
  48. package/dist/keys/derive.d.ts.map +1 -0
  49. package/dist/keys/hex.d.ts +14 -0
  50. package/dist/keys/hex.d.ts.map +1 -0
  51. package/dist/keys/index.d.ts +5 -0
  52. package/dist/keys/index.d.ts.map +1 -0
  53. package/dist/keys/mnemonic.d.ts +6 -0
  54. package/dist/keys/mnemonic.d.ts.map +1 -0
  55. package/dist/keys.d.ts +5 -1
  56. package/dist/keys.d.ts.map +1 -1
  57. package/dist/prover/config.d.ts +53 -22
  58. package/dist/prover/config.d.ts.map +1 -1
  59. package/dist/prover/integrity.d.ts +20 -0
  60. package/dist/prover/integrity.d.ts.map +1 -0
  61. package/dist/prover/prover.d.ts +16 -20
  62. package/dist/prover/prover.d.ts.map +1 -1
  63. package/dist/prover/registry.d.ts +3 -30
  64. package/dist/prover/registry.d.ts.map +1 -1
  65. package/dist/state/merkle/hydrator.d.ts +21 -19
  66. package/dist/state/merkle/hydrator.d.ts.map +1 -1
  67. package/dist/state/merkle/index.d.ts +2 -2
  68. package/dist/state/merkle/index.d.ts.map +1 -1
  69. package/dist/state/merkle/merkle-tree.d.ts +8 -0
  70. package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
  71. package/dist/state/store/ciphertext-store.d.ts +11 -0
  72. package/dist/state/store/ciphertext-store.d.ts.map +1 -1
  73. package/dist/state/store/history-store.d.ts +24 -0
  74. package/dist/state/store/history-store.d.ts.map +1 -0
  75. package/dist/state/store/index.d.ts +3 -2
  76. package/dist/state/store/index.d.ts.map +1 -1
  77. package/dist/state/store/job-store.d.ts +7 -7
  78. package/dist/state/store/job-store.d.ts.map +1 -1
  79. package/dist/state/store/jobs.d.ts +70 -25
  80. package/dist/state/store/jobs.d.ts.map +1 -1
  81. package/dist/state/store/leaf-store.d.ts +4 -0
  82. package/dist/state/store/leaf-store.d.ts.map +1 -1
  83. package/dist/state/store/note-store.d.ts +7 -7
  84. package/dist/state/store/note-store.d.ts.map +1 -1
  85. package/dist/state/store/nullifier-store.d.ts +9 -0
  86. package/dist/state/store/nullifier-store.d.ts.map +1 -1
  87. package/dist/state/store/records.d.ts +39 -2
  88. package/dist/state/store/records.d.ts.map +1 -1
  89. package/dist/state/store/root-store.d.ts.map +1 -1
  90. package/dist/state/store/store.d.ts +79 -27
  91. package/dist/state/store/store.d.ts.map +1 -1
  92. package/dist/storage/indexeddb.d.ts.map +1 -1
  93. package/dist/storage/memory.d.ts.map +1 -1
  94. package/dist/transactions/adapter.d.ts +31 -0
  95. package/dist/transactions/adapter.d.ts.map +1 -0
  96. package/dist/transactions/deposit.d.ts +12 -15
  97. package/dist/transactions/deposit.d.ts.map +1 -1
  98. package/dist/transactions/index.d.ts +9 -4
  99. package/dist/transactions/index.d.ts.map +1 -1
  100. package/dist/transactions/note-selection.d.ts +17 -0
  101. package/dist/transactions/note-selection.d.ts.map +1 -0
  102. package/dist/transactions/note-sync.d.ts +5 -33
  103. package/dist/transactions/note-sync.d.ts.map +1 -1
  104. package/dist/transactions/reconcile.d.ts +9 -11
  105. package/dist/transactions/reconcile.d.ts.map +1 -1
  106. package/dist/transactions/transact.d.ts +30 -22
  107. package/dist/transactions/transact.d.ts.map +1 -1
  108. package/dist/transactions/transaction-planner.d.ts +34 -0
  109. package/dist/transactions/transaction-planner.d.ts.map +1 -0
  110. package/dist/transactions/transfer-planner.d.ts +37 -0
  111. package/dist/transactions/transfer-planner.d.ts.map +1 -0
  112. package/dist/transactions/types/deposit.d.ts +67 -0
  113. package/dist/transactions/types/deposit.d.ts.map +1 -0
  114. package/dist/transactions/types/domain.d.ts +70 -0
  115. package/dist/transactions/types/domain.d.ts.map +1 -0
  116. package/dist/transactions/types/index.d.ts +18 -0
  117. package/dist/transactions/types/index.d.ts.map +1 -0
  118. package/dist/transactions/types/options.d.ts +54 -0
  119. package/dist/transactions/types/options.d.ts.map +1 -0
  120. package/dist/transactions/types/planning.d.ts +82 -0
  121. package/dist/transactions/types/planning.d.ts.map +1 -0
  122. package/dist/transactions/types/state-stores.d.ts +151 -0
  123. package/dist/transactions/types/state-stores.d.ts.map +1 -0
  124. package/dist/transactions/types/transact.d.ts +83 -0
  125. package/dist/transactions/types/transact.d.ts.map +1 -0
  126. package/dist/transactions/withdrawal-planner.d.ts +58 -0
  127. package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
  128. package/dist/tsconfig.tsbuildinfo +1 -1
  129. package/dist/tsup.browser.config.d.ts +7 -0
  130. package/dist/tsup.browser.config.d.ts.map +1 -0
  131. package/dist/tsup.config.d.ts +8 -0
  132. package/dist/tsup.config.d.ts.map +1 -0
  133. package/dist/types.d.ts +1 -0
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/utils/amounts.d.ts +26 -0
  136. package/dist/utils/amounts.d.ts.map +1 -0
  137. package/dist/utils/async.d.ts +9 -0
  138. package/dist/utils/async.d.ts.map +1 -1
  139. package/dist/utils/async.js +38 -11
  140. package/dist/utils/async.js.map +1 -0
  141. package/dist/utils/bigint.d.ts +0 -2
  142. package/dist/utils/bigint.d.ts.map +1 -1
  143. package/dist/utils/format.d.ts +25 -0
  144. package/dist/utils/format.d.ts.map +1 -0
  145. package/dist/utils/notes.d.ts +15 -0
  146. package/dist/utils/notes.d.ts.map +1 -0
  147. package/dist/utils/polling.d.ts +5 -0
  148. package/dist/utils/polling.d.ts.map +1 -1
  149. package/dist/utils/random.d.ts +18 -0
  150. package/dist/utils/random.d.ts.map +1 -0
  151. package/dist/utils/signature.d.ts +6 -0
  152. package/dist/utils/signature.d.ts.map +1 -1
  153. package/dist/utils/validators.d.ts +21 -10
  154. package/dist/utils/validators.d.ts.map +1 -1
  155. package/dist/vitest.config.d.ts +3 -0
  156. package/dist/vitest.config.d.ts.map +1 -0
  157. package/dist/wallet/adapter.d.ts +21 -0
  158. package/dist/wallet/adapter.d.ts.map +1 -0
  159. package/dist/wallet/burner/service.d.ts +32 -0
  160. package/dist/wallet/burner/service.d.ts.map +1 -0
  161. package/dist/wallet/burner/types.d.ts +47 -0
  162. package/dist/wallet/burner/types.d.ts.map +1 -0
  163. package/dist/wallet/index.d.ts +20 -0
  164. package/dist/wallet/index.d.ts.map +1 -0
  165. package/dist/wallet/index.js +6462 -0
  166. package/dist/wallet/index.js.map +1 -0
  167. package/dist/wallet/sdk.d.ts +48 -0
  168. package/dist/wallet/sdk.d.ts.map +1 -0
  169. package/dist/wallet/types.d.ts +457 -0
  170. package/dist/wallet/types.d.ts.map +1 -0
  171. package/dist/wallet/unlink-wallet.d.ts +187 -0
  172. package/dist/wallet/unlink-wallet.d.ts.map +1 -0
  173. package/package.json +38 -15
  174. package/.eslintrc.json +0 -4
  175. package/account/zkAccount.test.ts +0 -316
  176. package/account/zkAccount.ts +0 -222
  177. package/circuits.json +0 -26
  178. package/clients/broadcaster.ts +0 -67
  179. package/clients/http.ts +0 -94
  180. package/clients/indexer.ts +0 -150
  181. package/config.ts +0 -39
  182. package/core.ts +0 -17
  183. package/dist/account/railgun-imports-prototype.d.ts +0 -12
  184. package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
  185. package/dist/account/railgun-imports-prototype.js +0 -30
  186. package/dist/account/zkAccount.d.ts.map +0 -1
  187. package/dist/account/zkAccount.js +0 -128
  188. package/dist/circuits.json +0 -26
  189. package/dist/clients/broadcaster.js +0 -23
  190. package/dist/clients/http.js +0 -57
  191. package/dist/clients/indexer.js +0 -67
  192. package/dist/config.js +0 -29
  193. package/dist/core.js +0 -12
  194. package/dist/errors.js +0 -18
  195. package/dist/key-derivation/babyjubjub.d.ts +0 -9
  196. package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
  197. package/dist/key-derivation/babyjubjub.js +0 -9
  198. package/dist/key-derivation/bech32.d.ts +0 -22
  199. package/dist/key-derivation/bech32.d.ts.map +0 -1
  200. package/dist/key-derivation/bech32.js +0 -86
  201. package/dist/key-derivation/bip32.d.ts +0 -17
  202. package/dist/key-derivation/bip32.d.ts.map +0 -1
  203. package/dist/key-derivation/bip32.js +0 -41
  204. package/dist/key-derivation/bip39.d.ts +0 -22
  205. package/dist/key-derivation/bip39.d.ts.map +0 -1
  206. package/dist/key-derivation/bip39.js +0 -56
  207. package/dist/key-derivation/bytes.d.ts +0 -19
  208. package/dist/key-derivation/bytes.d.ts.map +0 -1
  209. package/dist/key-derivation/bytes.js +0 -92
  210. package/dist/key-derivation/hash.d.ts +0 -3
  211. package/dist/key-derivation/hash.d.ts.map +0 -1
  212. package/dist/key-derivation/hash.js +0 -10
  213. package/dist/key-derivation/index.d.ts +0 -8
  214. package/dist/key-derivation/index.d.ts.map +0 -1
  215. package/dist/key-derivation/index.js +0 -7
  216. package/dist/key-derivation/wallet-node.d.ts +0 -45
  217. package/dist/key-derivation/wallet-node.d.ts.map +0 -1
  218. package/dist/key-derivation/wallet-node.js +0 -109
  219. package/dist/keys.js +0 -41
  220. package/dist/prover/config.js +0 -80
  221. package/dist/prover/index.js +0 -1
  222. package/dist/prover/prover.js +0 -274
  223. package/dist/prover/registry.js +0 -57
  224. package/dist/schema.js +0 -14
  225. package/dist/state/ciphertext-store.d.ts +0 -12
  226. package/dist/state/ciphertext-store.d.ts.map +0 -1
  227. package/dist/state/ciphertext-store.js +0 -25
  228. package/dist/state/hydrator.d.ts +0 -16
  229. package/dist/state/hydrator.d.ts.map +0 -1
  230. package/dist/state/hydrator.js +0 -18
  231. package/dist/state/index.js +0 -2
  232. package/dist/state/job-store.d.ts +0 -12
  233. package/dist/state/job-store.d.ts.map +0 -1
  234. package/dist/state/job-store.js +0 -118
  235. package/dist/state/jobs.d.ts +0 -50
  236. package/dist/state/jobs.d.ts.map +0 -1
  237. package/dist/state/jobs.js +0 -1
  238. package/dist/state/leaf-store.d.ts +0 -17
  239. package/dist/state/leaf-store.d.ts.map +0 -1
  240. package/dist/state/leaf-store.js +0 -35
  241. package/dist/state/merkle/hydrator.js +0 -36
  242. package/dist/state/merkle/index.js +0 -2
  243. package/dist/state/merkle/merkle-tree.js +0 -104
  244. package/dist/state/merkle-tree.d.ts +0 -34
  245. package/dist/state/merkle-tree.d.ts.map +0 -1
  246. package/dist/state/merkle-tree.js +0 -104
  247. package/dist/state/note-store.d.ts +0 -37
  248. package/dist/state/note-store.d.ts.map +0 -1
  249. package/dist/state/note-store.js +0 -133
  250. package/dist/state/nullifier-store.d.ts +0 -13
  251. package/dist/state/nullifier-store.d.ts.map +0 -1
  252. package/dist/state/nullifier-store.js +0 -21
  253. package/dist/state/records.d.ts +0 -57
  254. package/dist/state/records.d.ts.map +0 -1
  255. package/dist/state/records.js +0 -1
  256. package/dist/state/root-store.d.ts +0 -13
  257. package/dist/state/root-store.d.ts.map +0 -1
  258. package/dist/state/root-store.js +0 -30
  259. package/dist/state/store/ciphertext-store.js +0 -25
  260. package/dist/state/store/index.js +0 -8
  261. package/dist/state/store/job-store.js +0 -118
  262. package/dist/state/store/jobs.js +0 -1
  263. package/dist/state/store/leaf-store.js +0 -35
  264. package/dist/state/store/note-store.js +0 -142
  265. package/dist/state/store/nullifier-store.js +0 -30
  266. package/dist/state/store/records.js +0 -1
  267. package/dist/state/store/root-store.js +0 -30
  268. package/dist/state/store/store.js +0 -22
  269. package/dist/state/store.d.ts +0 -26
  270. package/dist/state/store.d.ts.map +0 -1
  271. package/dist/state/store.js +0 -19
  272. package/dist/state.d.ts +0 -83
  273. package/dist/state.d.ts.map +0 -1
  274. package/dist/state.js +0 -171
  275. package/dist/storage/index.js +0 -2
  276. package/dist/storage/indexeddb.js +0 -205
  277. package/dist/storage/memory.js +0 -87
  278. package/dist/transactions/deposit.js +0 -169
  279. package/dist/transactions/index.js +0 -4
  280. package/dist/transactions/note-sync.js +0 -320
  281. package/dist/transactions/reconcile.js +0 -39
  282. package/dist/transactions/shield.d.ts +0 -5
  283. package/dist/transactions/shield.d.ts.map +0 -1
  284. package/dist/transactions/shield.js +0 -93
  285. package/dist/transactions/transact.js +0 -561
  286. package/dist/transactions/types.d.ts +0 -114
  287. package/dist/transactions/types.d.ts.map +0 -1
  288. package/dist/transactions/types.js +0 -1
  289. package/dist/transactions/utils.d.ts +0 -10
  290. package/dist/transactions/utils.d.ts.map +0 -1
  291. package/dist/transactions/utils.js +0 -17
  292. package/dist/types.js +0 -1
  293. package/dist/utils/bigint.js +0 -29
  294. package/dist/utils/crypto.d.ts +0 -12
  295. package/dist/utils/crypto.d.ts.map +0 -1
  296. package/dist/utils/crypto.js +0 -39
  297. package/dist/utils/json-codec.js +0 -25
  298. package/dist/utils/polling.js +0 -6
  299. package/dist/utils/signature.js +0 -12
  300. package/dist/utils/time.d.ts +0 -2
  301. package/dist/utils/time.d.ts.map +0 -1
  302. package/dist/utils/time.js +0 -3
  303. package/dist/utils/validators.js +0 -70
  304. package/dist/utils/witness.d.ts +0 -11
  305. package/dist/utils/witness.d.ts.map +0 -1
  306. package/dist/utils/witness.js +0 -19
  307. package/errors.ts +0 -20
  308. package/index.ts +0 -21
  309. package/key-derivation/babyjubjub.ts +0 -11
  310. package/key-derivation/bech32.test.ts +0 -90
  311. package/key-derivation/bech32.ts +0 -124
  312. package/key-derivation/bip32.ts +0 -56
  313. package/key-derivation/bip39.ts +0 -76
  314. package/key-derivation/bytes.ts +0 -118
  315. package/key-derivation/hash.ts +0 -13
  316. package/key-derivation/index.ts +0 -7
  317. package/key-derivation/wallet-node.ts +0 -155
  318. package/keys.ts +0 -47
  319. package/prover/config.ts +0 -104
  320. package/prover/index.ts +0 -1
  321. package/prover/prover.integration.test.ts +0 -162
  322. package/prover/prover.test.ts +0 -309
  323. package/prover/prover.ts +0 -405
  324. package/prover/registry.test.ts +0 -90
  325. package/prover/registry.ts +0 -82
  326. package/schema.ts +0 -17
  327. package/setup-artifacts.sh +0 -57
  328. package/state/index.ts +0 -2
  329. package/state/merkle/hydrator.ts +0 -69
  330. package/state/merkle/index.ts +0 -12
  331. package/state/merkle/merkle-tree.test.ts +0 -50
  332. package/state/merkle/merkle-tree.ts +0 -163
  333. package/state/store/ciphertext-store.ts +0 -28
  334. package/state/store/index.ts +0 -24
  335. package/state/store/job-store.ts +0 -162
  336. package/state/store/jobs.ts +0 -64
  337. package/state/store/leaf-store.ts +0 -39
  338. package/state/store/note-store.ts +0 -177
  339. package/state/store/nullifier-store.ts +0 -39
  340. package/state/store/records.ts +0 -61
  341. package/state/store/root-store.ts +0 -34
  342. package/state/store/store.ts +0 -25
  343. package/state.test.ts +0 -235
  344. package/storage/index.ts +0 -3
  345. package/storage/indexeddb.test.ts +0 -99
  346. package/storage/indexeddb.ts +0 -235
  347. package/storage/memory.test.ts +0 -59
  348. package/storage/memory.ts +0 -93
  349. package/transactions/deposit.test.ts +0 -160
  350. package/transactions/deposit.ts +0 -227
  351. package/transactions/index.ts +0 -20
  352. package/transactions/note-sync.test.ts +0 -155
  353. package/transactions/note-sync.ts +0 -452
  354. package/transactions/reconcile.ts +0 -73
  355. package/transactions/transact.test.ts +0 -451
  356. package/transactions/transact.ts +0 -811
  357. package/transactions/types.ts +0 -141
  358. package/tsconfig.json +0 -15
  359. package/types/global.d.ts +0 -15
  360. package/types.ts +0 -24
  361. package/utils/async.ts +0 -15
  362. package/utils/bigint.ts +0 -34
  363. package/utils/crypto.test.ts +0 -69
  364. package/utils/crypto.ts +0 -58
  365. package/utils/json-codec.ts +0 -38
  366. package/utils/polling.ts +0 -6
  367. package/utils/signature.ts +0 -16
  368. package/utils/validators.test.ts +0 -64
  369. package/utils/validators.ts +0 -86
@@ -1,128 +0,0 @@
1
- import { Mnemonic } from "../key-derivation/bip39.js";
2
- import { ByteUtils } from "../key-derivation/bytes.js";
3
- import { deriveNodesFromSeed, WalletNode, } from "../key-derivation/wallet-node.js";
4
- export const MASTER_SEED_LENGTH = 64;
5
- export const MASTER_SEED_KEY = "cfg:wallet:master_seed/v1";
6
- export const MASTER_MNEMONIC_KEY = "cfg:wallet:master_mnemonic/v1";
7
- const MNEMONIC_ENTROPY_BYTES = 32;
8
- const textEncoder = new TextEncoder();
9
- const textDecoder = new TextDecoder();
10
- export async function deriveZkAccount(masterSeed, accountIndex = 0) {
11
- const seed = normalizeMasterSeed(masterSeed);
12
- if (!Number.isInteger(accountIndex) || accountIndex < 0) {
13
- throw new Error("accountIndex must be a non-negative integer");
14
- }
15
- const { spending, viewing } = deriveNodesFromSeed(seed, accountIndex);
16
- const spendingKeyPair = spending.getSpendingKeyPair();
17
- const viewingKeyPair = await viewing.getViewingKeyPair();
18
- const nullifyingKey = WalletNode.getNullifyingKey(viewingKeyPair.privateKey);
19
- const masterPublicKey = WalletNode.getMasterPublicKey(spendingKeyPair.pubkey, nullifyingKey);
20
- return {
21
- spendingKeyPair,
22
- viewingKeyPair,
23
- nullifyingKey,
24
- masterPublicKey,
25
- };
26
- }
27
- export async function deriveZkAccountFromMnemonic(mnemonic, accountIndex = 0, password = "") {
28
- const normalized = normalizeMnemonic(mnemonic);
29
- const seed = mnemonicToSeed(normalized, password);
30
- return deriveZkAccount(seed, accountIndex);
31
- }
32
- const identityMasterSeedCrypto = {
33
- encrypt(seed) {
34
- return clone(seed);
35
- },
36
- decrypt(payload) {
37
- return clone(payload);
38
- },
39
- };
40
- export async function generateMasterSeed({ storage, rng, crypto = identityMasterSeedCrypto, overwrite = false, mnemonicPassphrase, }) {
41
- if (!overwrite) {
42
- const existingSeed = await loadMasterSeed(storage, crypto);
43
- if (existingSeed)
44
- return existingSeed;
45
- const existingMnemonic = await loadMasterMnemonic(storage, crypto);
46
- if (existingMnemonic) {
47
- const seedFromMnemonic = mnemonicToSeed(existingMnemonic, mnemonicPassphrase);
48
- await storeMasterSeed(storage, seedFromMnemonic, crypto);
49
- return seedFromMnemonic;
50
- }
51
- }
52
- const entropy = rng(MNEMONIC_ENTROPY_BYTES);
53
- if (entropy.length !== MNEMONIC_ENTROPY_BYTES) {
54
- throw new Error(`mnemonic entropy must be ${MNEMONIC_ENTROPY_BYTES} bytes`);
55
- }
56
- const mnemonic = Mnemonic.fromEntropy(ByteUtils.bytesToHex(entropy));
57
- await storeMasterMnemonic(storage, mnemonic, crypto);
58
- const seed = mnemonicToSeed(mnemonic, mnemonicPassphrase);
59
- await storeMasterSeed(storage, seed, crypto);
60
- return seed;
61
- }
62
- export async function loadMasterSeed(storage, crypto = identityMasterSeedCrypto) {
63
- const stored = await storage.get(MASTER_SEED_KEY);
64
- if (!stored)
65
- return null;
66
- const plaintext = await crypto.decrypt(stored);
67
- return normalizeMasterSeed(plaintext);
68
- }
69
- export async function storeMasterSeed(storage, seed, crypto = identityMasterSeedCrypto) {
70
- const normalized = normalizeMasterSeed(seed);
71
- const encrypted = await crypto.encrypt(normalized);
72
- if (!(encrypted instanceof Uint8Array)) {
73
- throw new Error("master seed encryptor must return Uint8Array");
74
- }
75
- await storage.put(MASTER_SEED_KEY, clone(encrypted));
76
- }
77
- export async function loadMasterMnemonic(storage, crypto = identityMasterSeedCrypto) {
78
- const stored = await storage.get(MASTER_MNEMONIC_KEY);
79
- if (!stored)
80
- return null;
81
- const plaintext = await crypto.decrypt(stored);
82
- const mnemonic = textDecoder.decode(plaintext);
83
- return normalizeMnemonic(mnemonic);
84
- }
85
- export async function importMasterMnemonic({ storage, mnemonic, crypto = identityMasterSeedCrypto, overwrite = false, password = "", }) {
86
- if (!overwrite) {
87
- const existing = await loadMasterMnemonic(storage, crypto);
88
- if (existing) {
89
- throw new Error("master mnemonic already exists; set overwrite to true to replace it");
90
- }
91
- }
92
- const normalized = normalizeMnemonic(mnemonic);
93
- const seed = mnemonicToSeed(normalized, password);
94
- await storeMasterMnemonic(storage, normalized, crypto);
95
- await storeMasterSeed(storage, seed, crypto);
96
- return seed;
97
- }
98
- export async function storeMasterMnemonic(storage, mnemonic, crypto = identityMasterSeedCrypto) {
99
- const normalized = normalizeMnemonic(mnemonic);
100
- const encrypted = await crypto.encrypt(textEncoder.encode(normalized));
101
- if (!(encrypted instanceof Uint8Array)) {
102
- throw new Error("master mnemonic encryptor must return Uint8Array");
103
- }
104
- await storage.put(MASTER_MNEMONIC_KEY, clone(encrypted));
105
- }
106
- function clone(bytes) {
107
- return new Uint8Array(bytes);
108
- }
109
- function normalizeMasterSeed(seed) {
110
- if (!(seed instanceof Uint8Array)) {
111
- throw new Error("master seed must be a Uint8Array");
112
- }
113
- if (seed.length !== MASTER_SEED_LENGTH) {
114
- throw new Error(`master seed must be ${MASTER_SEED_LENGTH} bytes`);
115
- }
116
- return clone(seed);
117
- }
118
- function normalizeMnemonic(mnemonic) {
119
- const formatted = mnemonic.trim().replace(/\s+/g, " ");
120
- if (!Mnemonic.validate(formatted)) {
121
- throw new Error("invalid BIP-39 mnemonic phrase");
122
- }
123
- return formatted;
124
- }
125
- function mnemonicToSeed(mnemonic, password = "") {
126
- const seedHex = Mnemonic.toSeed(mnemonic, password);
127
- return ByteUtils.hexStringToBytes(seedHex);
128
- }
@@ -1,26 +0,0 @@
1
- {
2
- "joinsplit_3x3_16": {
3
- "file": "joinsplit",
4
- "template": "JoinSplit",
5
- "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
6
- "params": [3, 3, 16]
7
- },
8
- "joinsplit_2x3_16": {
9
- "file": "joinsplit",
10
- "template": "JoinSplit",
11
- "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
12
- "params": [2, 3, 16]
13
- },
14
- "joinsplit_1x2_16": {
15
- "file": "joinsplit",
16
- "template": "JoinSplit",
17
- "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
18
- "params": [1, 2, 16]
19
- },
20
- "joinsplit_1x1_16": {
21
- "file": "joinsplit",
22
- "template": "JoinSplit",
23
- "pubs": ["merkleRoot", "boundParamsHash", "nullifiers", "commitmentsOut"],
24
- "params": [1, 1, 16]
25
- }
26
- }
@@ -1,23 +0,0 @@
1
- import { createJsonHttpClient } from "./http.js";
2
- export function createBroadcasterClient(baseUrl, deps) {
3
- const http = createJsonHttpClient(baseUrl, deps);
4
- return {
5
- async submitRelay(params) {
6
- return http.request({
7
- method: "POST",
8
- path: "/relays",
9
- json: {
10
- client_tx_id: params.clientTxId,
11
- chain_id: params.chainId,
12
- ...params.payload,
13
- },
14
- });
15
- },
16
- async getRelayStatus(relayId) {
17
- return http.request({
18
- method: "GET",
19
- path: `/relays/${relayId}`,
20
- });
21
- },
22
- };
23
- }
@@ -1,57 +0,0 @@
1
- import ky, { HTTPError, TimeoutError } from "ky";
2
- export class HttpError extends Error {
3
- status;
4
- body;
5
- constructor(message, status, body) {
6
- super(message);
7
- this.status = status;
8
- this.body = body;
9
- }
10
- }
11
- async function readErrorBodySafe(res) {
12
- try {
13
- return await res.clone().json();
14
- }
15
- catch {
16
- const text = await res.text();
17
- return text || null;
18
- }
19
- }
20
- export function createJsonHttpClient(baseUrl, deps) {
21
- if (!baseUrl)
22
- throw new Error("baseUrl is required");
23
- if (!deps?.fetch)
24
- throw new Error("deps.fetch is required");
25
- // Ensure `fetch` is invoked with a global `this` to avoid "Illegal invocation"
26
- // errors in some browser environments when the function is extracted. // TODO: can we fix this in another way?
27
- const fetchImpl = (...args) => deps.fetch.apply(globalThis, args);
28
- const api = ky.create({
29
- prefixUrl: baseUrl.replace(/\/+$/, ""),
30
- fetch: fetchImpl,
31
- });
32
- return {
33
- async request(opts) {
34
- try {
35
- const res = api(opts.path.replace(/^\//, ""), {
36
- method: opts.method,
37
- searchParams: opts.query,
38
- json: opts.json,
39
- body: opts.body,
40
- headers: opts.headers,
41
- signal: opts.signal,
42
- });
43
- return await res.json();
44
- }
45
- catch (err) {
46
- if (err instanceof HTTPError) {
47
- const body = await readErrorBodySafe(err.response);
48
- throw new HttpError(`HTTP ${err.response.status} ${err.response.statusText}`.trim(), err.response.status, body);
49
- }
50
- if (err instanceof TimeoutError) {
51
- throw new HttpError("HTTP timeout", 408, null);
52
- }
53
- throw new HttpError(err instanceof Error ? err.message : "Network error", 0, null);
54
- }
55
- },
56
- };
57
- }
@@ -1,67 +0,0 @@
1
- import { createJsonHttpClient } from "./http.js";
2
- import { isNotFoundError } from "../utils/async.js";
3
- export function createIndexerClient(baseUrl, deps) {
4
- const http = createJsonHttpClient(baseUrl, deps);
5
- // Converts the snake_case record from the REST API into the camelCase shape
6
- // the rest of the SDK consumes.
7
- const normalizeRecord = (record) => ({
8
- index: record.leaf_index,
9
- commitment: record.commitment,
10
- ciphertext: [...record.ciphertext],
11
- root: record.root,
12
- txHash: record.tx_hash,
13
- insertedAt: record.inserted_at,
14
- });
15
- const normalizeNullifierRecord = (record) => ({
16
- nullifier: record.nullifier,
17
- txHash: record.tx_hash,
18
- spentAt: record.spent_at,
19
- chainId: record.chain_id,
20
- });
21
- return {
22
- async fetchCommitmentBatch(params) {
23
- const raw = await http.request({
24
- method: "GET",
25
- path: `/chains/${params.chainId}/commitments`,
26
- query: {
27
- start: params.start,
28
- limit: params.limit,
29
- },
30
- });
31
- return {
32
- chainId: raw.chain_id,
33
- commitments: raw.commitments.map(normalizeRecord),
34
- latestRoot: raw.latest_root,
35
- };
36
- },
37
- async getCommitment(params) {
38
- const raw = await http.request({
39
- method: "GET",
40
- path: `/chains/${params.chainId}/commitments/${params.commitment}`,
41
- });
42
- return normalizeRecord(raw);
43
- },
44
- async getNullifier(params) {
45
- try {
46
- const raw = await http.request({
47
- method: "GET",
48
- path: `/chains/${params.chainId}/nullifiers/${params.nullifier}`,
49
- });
50
- return normalizeNullifierRecord(raw);
51
- }
52
- catch (err) {
53
- if (isNotFoundError(err)) {
54
- return null; // Nullifier not spent on-chain
55
- }
56
- throw err;
57
- }
58
- },
59
- async getNullifierCount(chainId) {
60
- const raw = await http.request({
61
- method: "GET",
62
- path: `/chains/${chainId}/nullifiers/count`,
63
- });
64
- return raw.count;
65
- },
66
- };
67
- }
package/dist/config.js DELETED
@@ -1,29 +0,0 @@
1
- const DEFAULT_RPC_URL = "http://localhost:3000";
2
- function readEnv(key) {
3
- if (typeof process !== "undefined" && process?.env) {
4
- return process.env[key];
5
- }
6
- // Support environments where process isn't defined but a shim sets globalThis.process
7
- const globalProcess = globalThis.process;
8
- return globalProcess?.env?.[key];
9
- }
10
- function readServiceUrl(envKey, fallback) {
11
- const raw = readEnv(envKey);
12
- if (!raw)
13
- return fallback;
14
- const trimmed = raw.trim();
15
- if (!trimmed) {
16
- throw new Error(`${envKey} must not be empty when set`);
17
- }
18
- return trimmed.replace(/\/+$/, "");
19
- }
20
- export const serviceConfig = {
21
- /**
22
- * Base URL for the Broadcaster HTTP API (default: http://localhost:8081).
23
- */
24
- broadcasterBaseUrl: readServiceUrl("UNLINK_RPC_URL", DEFAULT_RPC_URL) + "/broadcaster",
25
- /**
26
- * Base URL for the Indexer HTTP API (default: http://localhost:8082).
27
- */
28
- indexerBaseUrl: readServiceUrl("UNLINK_RPC_URL", DEFAULT_RPC_URL) + "/indexer",
29
- };
package/dist/core.js DELETED
@@ -1,12 +0,0 @@
1
- import { migrate } from "./schema.js";
2
- export async function initCore(deps) {
3
- if (!deps?.storage)
4
- throw new Error("storage dep required");
5
- if (!deps?.rng)
6
- throw new Error("rng dep required");
7
- await migrate(deps.storage);
8
- return {
9
- storage: deps.storage,
10
- rng: deps.rng,
11
- };
12
- }
package/dist/errors.js DELETED
@@ -1,18 +0,0 @@
1
- export class CoreError extends Error {
2
- constructor(message) {
3
- super(message);
4
- this.name = "CoreError";
5
- }
6
- }
7
- export class KeyValidationError extends CoreError {
8
- constructor(message) {
9
- super(message);
10
- this.name = "KeyValidationError";
11
- }
12
- }
13
- export class SchemaMismatchError extends CoreError {
14
- constructor(current, expected) {
15
- super(`schema mismatch (current ${current}, expected ${expected})`);
16
- this.name = "SchemaMismatchError";
17
- }
18
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Lightweight wrapper exposing the BabyJubJub point packing helpers we rely on for
3
- * derivation and address encoding. Re-exported for consumers that need raw curve ops.
4
- */
5
- export declare class Babyjubjub {
6
- static packPoint: (point: [bigint, bigint]) => Uint8Array;
7
- static unpackPoint: (bytes: Uint8Array) => [bigint, bigint];
8
- }
9
- //# sourceMappingURL=babyjubjub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"babyjubjub.d.ts","sourceRoot":"","sources":["../../key-derivation/babyjubjub.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,UAAU;IACrB,MAAM,CAAC,SAAS,0CAAqB;IAErC,MAAM,CAAC,WAAW,0CAAuB;CAC1C"}
@@ -1,9 +0,0 @@
1
- import { babyjub } from "@railgun-community/circomlibjs";
2
- /**
3
- * Lightweight wrapper exposing the BabyJubJub point packing helpers we rely on for
4
- * derivation and address encoding. Re-exported for consumers that need raw curve ops.
5
- */
6
- export class Babyjubjub {
7
- static packPoint = babyjub.packPoint;
8
- static unpackPoint = babyjub.unpackPoint;
9
- }
@@ -1,22 +0,0 @@
1
- export type Chain = {
2
- type: number;
3
- id: number;
4
- };
5
- export type AddressData = {
6
- masterPublicKey: bigint;
7
- viewingPublicKey: Uint8Array;
8
- chain?: Chain;
9
- version?: number;
10
- };
11
- export declare const ADDRESS_VERSION = 1;
12
- export declare const ADDRESS_LENGTH_LIMIT = 127;
13
- export declare const ALL_CHAINS_NETWORK_ID = "ffffffffffffffff";
14
- /**
15
- * Encode address metadata into a Bech32m string with the 0zk prefix.
16
- */
17
- export declare const encodeAddress: (addressData: AddressData) => string;
18
- /**
19
- * Decode and validate a Bech32m address, returning the structured payload.
20
- */
21
- export declare const decodeAddress: (address: string) => AddressData;
22
- //# sourceMappingURL=bech32.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bech32.d.ts","sourceRoot":"","sources":["../../key-derivation/bech32.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,UAAU,CAAC;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AA0CxD;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,aAAa,WAAW,KAAG,MAmBxD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,WAoC/C,CAAC"}
@@ -1,86 +0,0 @@
1
- import { bech32m } from "@scure/base";
2
- import { ByteLength, ByteUtils } from "./bytes.js";
3
- export const ADDRESS_VERSION = 1;
4
- export const ADDRESS_LENGTH_LIMIT = 127;
5
- export const ALL_CHAINS_NETWORK_ID = "ffffffffffffffff";
6
- const PREFIX = "0zk";
7
- const XOR_SALT = new TextEncoder().encode("unlink");
8
- /**
9
- * XOR the network identifier with a static salt to keep addresses compact and avoid
10
- * exposing raw chain IDs directly (mirrors the reference implementation).
11
- */
12
- const xorNetworkID = (networkID) => {
13
- const bytes = ByteUtils.hexStringToBytes(networkID);
14
- const result = new Uint8Array(bytes.length);
15
- const saltLength = XOR_SALT.length;
16
- for (let i = 0; i < bytes.length; i += 1) {
17
- const byte = bytes[i] ?? 0;
18
- let saltByte = 0;
19
- if (saltLength > 0) {
20
- const saltIndex = i % saltLength;
21
- saltByte = XOR_SALT[saltIndex] ?? 0;
22
- }
23
- result[i] = byte ^ saltByte;
24
- }
25
- return ByteUtils.bytesToHex(result);
26
- };
27
- const chainToNetworkID = (chain) => {
28
- if (!chain)
29
- return ALL_CHAINS_NETWORK_ID;
30
- const { type, id } = chain;
31
- const typeHex = (type & 0xff).toString(16).padStart(2, "0");
32
- const idHex = BigInt(id).toString(16).padStart(14, "0");
33
- return `${typeHex}${idHex}`;
34
- };
35
- const networkIDToChain = (networkID) => {
36
- if (networkID === ALL_CHAINS_NETWORK_ID) {
37
- return undefined;
38
- }
39
- const type = parseInt(networkID.slice(0, 2), 16);
40
- const id = parseInt(networkID.slice(2), 16);
41
- return { type, id };
42
- };
43
- /**
44
- * Encode address metadata into a Bech32m string with the 0zk prefix.
45
- */
46
- export const encodeAddress = (addressData) => {
47
- const versionHex = (addressData.version ?? ADDRESS_VERSION)
48
- .toString(16)
49
- .padStart(2, "0");
50
- const masterPublicKey = ByteUtils.nToHex(addressData.masterPublicKey, ByteLength.UINT_256, false);
51
- const viewingPublicKey = ByteUtils.formatToByteLength(addressData.viewingPublicKey, ByteLength.UINT_256);
52
- const networkID = xorNetworkID(chainToNetworkID(addressData.chain));
53
- const payloadHex = `${versionHex}${masterPublicKey}${networkID}${viewingPublicKey}`;
54
- const payload = ByteUtils.hexStringToBytes(payloadHex);
55
- return bech32m.encode(PREFIX, bech32m.toWords(payload), ADDRESS_LENGTH_LIMIT);
56
- };
57
- /**
58
- * Decode and validate a Bech32m address, returning the structured payload.
59
- */
60
- export const decodeAddress = (address) => {
61
- if (!address) {
62
- throw new Error("No address to decode");
63
- }
64
- const decoded = bech32m.decode(address, ADDRESS_LENGTH_LIMIT);
65
- if (decoded.prefix !== PREFIX) {
66
- throw new Error("Invalid address prefix");
67
- }
68
- const payloadHex = ByteUtils.hexlify(bech32m.fromWords(decoded.words));
69
- if (payloadHex.length !== 2 + 64 + 16 + 64) {
70
- throw new Error("Incorrect address payload length");
71
- }
72
- const version = parseInt(payloadHex.slice(0, 2), 16);
73
- if (version !== ADDRESS_VERSION) {
74
- throw new Error("Incorrect address version");
75
- }
76
- const masterPublicKey = ByteUtils.hexToBigInt(payloadHex.slice(2, 66));
77
- const networkID = xorNetworkID(payloadHex.slice(66, 82));
78
- const viewingPublicKey = ByteUtils.hexStringToBytes(payloadHex.slice(82, 146));
79
- const chain = networkIDToChain(networkID);
80
- return {
81
- version,
82
- masterPublicKey,
83
- viewingPublicKey,
84
- chain,
85
- };
86
- };
@@ -1,17 +0,0 @@
1
- export type KeyNode = {
2
- chainKey: string;
3
- chainCode: string;
4
- };
5
- /**
6
- * Parse a derivation path into hardened segment indexes.
7
- */
8
- export declare const getPathSegments: (path: string) => number[];
9
- /**
10
- * Perform hardened child derivation using the BabyJubJub curve seed.
11
- */
12
- export declare const childKeyDerivationHardened: (node: KeyNode, index: number, offset?: number) => KeyNode;
13
- /**
14
- * Create the root BIP-32 node from a BIP-39 seed.
15
- */
16
- export declare const getMasterKeyFromSeed: (seed: string) => KeyNode;
17
- //# sourceMappingURL=bip32.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bip32.d.ts","sourceRoot":"","sources":["../../key-derivation/bip32.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AASF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAAM,EASpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,OAAO,EACb,OAAO,MAAM,EACb,SAAQ,MAAmB,KAC1B,OAOF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,OAKnD,CAAC"}
@@ -1,41 +0,0 @@
1
- import { ByteUtils, fromUTF8String } from "./bytes.js";
2
- import { sha512HMAC } from "./hash.js";
3
- const CURVE_SEED = fromUTF8String("babyjubjub seed");
4
- // Validates derivation paths of the form m/... with hardened segments.
5
- const PATH_REGEX = /^m(\/[0-9]+')+$/;
6
- const isValidPath = (path) => {
7
- return PATH_REGEX.test(path);
8
- };
9
- /**
10
- * Parse a derivation path into hardened segment indexes.
11
- */
12
- export const getPathSegments = (path) => {
13
- if (!isValidPath(path)) {
14
- throw new Error("Invalid derivation path");
15
- }
16
- return path
17
- .split("/")
18
- .slice(1)
19
- .map((segment) => segment.replace("'", ""))
20
- .map((segment) => parseInt(segment, 10));
21
- };
22
- /**
23
- * Perform hardened child derivation using the BabyJubJub curve seed.
24
- */
25
- export const childKeyDerivationHardened = (node, index, offset = 0x80000000) => {
26
- const indexFormatted = ByteUtils.padToLength(index + offset, 4);
27
- const preImage = `00${node.chainKey}${indexFormatted}`;
28
- const I = sha512HMAC(node.chainCode, preImage);
29
- const chainKey = I.slice(0, 64);
30
- const chainCode = I.slice(64);
31
- return { chainKey, chainCode };
32
- };
33
- /**
34
- * Create the root BIP-32 node from a BIP-39 seed.
35
- */
36
- export const getMasterKeyFromSeed = (seed) => {
37
- const I = sha512HMAC(CURVE_SEED, seed);
38
- const chainKey = I.slice(0, 64);
39
- const chainCode = I.slice(64);
40
- return { chainKey, chainCode };
41
- };
@@ -1,22 +0,0 @@
1
- export declare class Mnemonic {
2
- /**
3
- * Generate a BIP-39 mnemonic using the English wordlist.
4
- */
5
- static generate(strength?: 128 | 192 | 256): string;
6
- /**
7
- * Validate a mnemonic against the English wordlist checksum.
8
- */
9
- static validate(mnemonic: string): boolean;
10
- /**
11
- * Convert a mnemonic to a hex-encoded BIP-39 seed. Optional password supported.
12
- */
13
- static toSeed(mnemonic: string, password?: string): string;
14
- static toEntropy(mnemonic: string): string;
15
- static fromEntropy(entropyHex: string): string;
16
- /**
17
- * Convenience helper: derive a 0x private key for non-0zk flows.
18
- */
19
- static to0xPrivateKey(mnemonic: string, derivationIndex?: number): string;
20
- static to0xAddress(mnemonic: string, derivationIndex?: number): string;
21
- }
22
- //# sourceMappingURL=bip39.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bip39.d.ts","sourceRoot":"","sources":["../../key-derivation/bip39.ts"],"names":[],"mappings":"AAqBA,qBAAa,QAAQ;IACnB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,GAAE,GAAG,GAAG,GAAG,GAAG,GAAS,GAAG,MAAM;IAIxD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI1C;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAW,GAAG,MAAM;IAK9D,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAK1C,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAK9C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM;IAWzE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM;CAOvE"}
@@ -1,56 +0,0 @@
1
- import { entropyToMnemonic, generateMnemonic, mnemonicToEntropy, mnemonicToSeedSync, validateMnemonic, } from "@scure/bip39";
2
- import { wordlist } from "@scure/bip39/wordlists/english.js";
3
- import { HDKey } from "ethereum-cryptography/hdkey";
4
- import { Mnemonic as EthersMnemonic, HDNodeWallet } from "ethers";
5
- import { ByteUtils } from "./bytes.js";
6
- /**
7
- * Standard ETH derivation path helper for convenience utilities below.
8
- * Not used for 0zk accounts but kept for backwards compatibility.
9
- */
10
- const derivationPath = (index = 0) => {
11
- return `m/44'/60'/0'/0/${index}`;
12
- };
13
- export class Mnemonic {
14
- /**
15
- * Generate a BIP-39 mnemonic using the English wordlist.
16
- */
17
- static generate(strength = 128) {
18
- return generateMnemonic(wordlist, strength);
19
- }
20
- /**
21
- * Validate a mnemonic against the English wordlist checksum.
22
- */
23
- static validate(mnemonic) {
24
- return validateMnemonic(mnemonic, wordlist);
25
- }
26
- /**
27
- * Convert a mnemonic to a hex-encoded BIP-39 seed. Optional password supported.
28
- */
29
- static toSeed(mnemonic, password = "") {
30
- const seed = mnemonicToSeedSync(mnemonic, password);
31
- return ByteUtils.bytesToHex(seed);
32
- }
33
- static toEntropy(mnemonic) {
34
- const entropy = mnemonicToEntropy(mnemonic, wordlist);
35
- return ByteUtils.bytesToHex(entropy);
36
- }
37
- static fromEntropy(entropyHex) {
38
- const entropy = ByteUtils.hexStringToBytes(entropyHex);
39
- return entropyToMnemonic(entropy, wordlist);
40
- }
41
- /**
42
- * Convenience helper: derive a 0x private key for non-0zk flows.
43
- */
44
- static to0xPrivateKey(mnemonic, derivationIndex) {
45
- const seed = mnemonicToSeedSync(mnemonic);
46
- const node = HDKey.fromMasterSeed(Buffer.from(seed)).derive(derivationPath(derivationIndex));
47
- if (!node.privateKey) {
48
- throw new Error("Failed to derive private key");
49
- }
50
- return ByteUtils.bytesToHex(node.privateKey);
51
- }
52
- static to0xAddress(mnemonic, derivationIndex) {
53
- const wallet = HDNodeWallet.fromMnemonic(EthersMnemonic.fromPhrase(mnemonic), derivationPath(derivationIndex));
54
- return wallet.address;
55
- }
56
- }