@laceio/sdk 0.1.1-canary.2 → 0.1.1

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 (386) hide show
  1. package/dist/{TransactionBuilder-CCjOn7NA.cjs → TransactionBuilder-DrB3NVTi.cjs} +0 -42
  2. package/dist/{TransactionBuilder-CIzdw18M.js → TransactionBuilder-V6aLx4SV.js} +1 -1
  3. package/dist/{_polyfill-buffer-patch-CM8X7JiY.cjs → _polyfill-buffer-patch-BnPVerlG.cjs} +2 -21
  4. package/dist/account-guards.stable-B1DSSh9D.cjs +10 -0
  5. package/dist/account-guards.stable-JRQ5qx2V.js +5 -0
  6. package/dist/{activity-type-Ch6ljxBy.cjs → activity-type.stable-BJEfeLxL.cjs} +1 -2
  7. package/dist/{activity-type-GsJGWs-3.js → activity-type.stable-C76_hWd7.js} +1 -2
  8. package/dist/{address-book-address-validator-ByIZOdO-.js → address-book-address-validator-DIUolI-s.js} +2 -2
  9. package/dist/{address-book-address-validator-BjOWerRE.cjs → address-book-address-validator-DNwQGlOB.cjs} +2 -2
  10. package/dist/bitcoin.cjs +0 -45
  11. package/dist/bitcoin.d.ts +1 -29782
  12. package/dist/bitcoin.js +0 -20
  13. package/dist/{blockfrost-tx-submit-provider-CLNQ5ycR.cjs → blockfrost-tx-submit-provider-BAIzV5o3.cjs} +167 -3
  14. package/dist/{blockfrost-tx-submit-provider-CBWQ0wK9.js → blockfrost-tx-submit-provider-DPTrapz-.js} +157 -5
  15. package/dist/{secret-box-DrjLZuS1.cjs → bytes.vo-Ck5u40RA.cjs} +35 -1
  16. package/dist/{secret-box-DUR0ACYz.js → bytes.vo-TgiwogWF.js} +25 -3
  17. package/dist/{cardano-network-id.vo-wfLiAxpY.js → cardano-network-id.vo-CK1tNQDg.js} +1 -1
  18. package/dist/{cardano-network-id.vo-BEvFd_74.cjs → cardano-network-id.vo-DSxrFk9S.cjs} +1 -1
  19. package/dist/cardano.cjs +18 -22
  20. package/dist/cardano.d.ts +3982 -18409
  21. package/dist/cardano.js +11 -16
  22. package/dist/codecs-B7X9pAsK.cjs +1945 -0
  23. package/dist/codecs-CC1Xjntz.js +1882 -0
  24. package/dist/{const-oMF-TLow.cjs → const-BDEg2Trq.cjs} +4 -4
  25. package/dist/{const-iwzZEE_w.cjs → const-BY8B3_0_.cjs} +1 -1
  26. package/dist/{const-CBGn60yu.js → const-C84qHkjp.js} +4 -4
  27. package/dist/{const-CjmfjBP3.js → const-DXk2tFyv.js} +1 -1
  28. package/dist/{delegation-tx-builder-BR6bt1fE.js → delegation-tx-builder-CGVqlaFE.js} +5 -5
  29. package/dist/{delegation-tx-builder-DVwGfiV0.cjs → delegation-tx-builder-CRpLP6jH.cjs} +6 -6
  30. package/dist/{deregistration-tx-builder-BhJRGj1M.js → deregistration-tx-builder-B-CrUyX6.js} +5 -5
  31. package/dist/{deregistration-tx-builder-Cv_09HGf.cjs → deregistration-tx-builder-DZGwB4cz.cjs} +6 -6
  32. package/dist/{earn-rewards-tx-builder-RYzKsZ6-.js → earn-rewards-tx-builder-BDbTDZmD.js} +5 -5
  33. package/dist/{earn-rewards-tx-builder-52gJiJYa.cjs → earn-rewards-tx-builder-D5sUT5v8.cjs} +6 -6
  34. package/dist/{group-cardano-addresses-by-account-D06r7daZ.cjs → group-cardano-addresses-by-account-B533oVXR.cjs} +35 -19
  35. package/dist/{group-cardano-addresses-by-account-CxCqFDrX.js → group-cardano-addresses-by-account-RHKoEskR.js} +35 -19
  36. package/dist/{guarded-transaction-signer-BhnTBjf6.cjs → guarded-transaction-signer-Bxl6_XNd.cjs} +18 -17
  37. package/dist/{guarded-transaction-signer-BSEx83R-.js → guarded-transaction-signer-CpKLj8Kp.js} +15 -8
  38. package/dist/{in-memory-wallet-integration-CH4rcg92.cjs → in-memory-wallet-integration-CnLYeX4-.cjs} +108 -17
  39. package/dist/{in-memory-wallet-integration-BKu985Jz.js → in-memory-wallet-integration-Croiuopx.js} +104 -7
  40. package/dist/{in-memory-wallet-integration-B0blZBxM.js → in-memory-wallet-integration-D-qn65Kx.js} +2 -5
  41. package/dist/{in-memory-wallet-integration-CwPCDMIe.cjs → in-memory-wallet-integration-DVh9sRXa.cjs} +2 -3
  42. package/dist/index.cjs +47 -84
  43. package/dist/index.d.ts +13618 -40268
  44. package/dist/index.js +24 -52
  45. package/dist/{init-DUF4ar8P.cjs → init-B64zCLxG.cjs} +4 -4
  46. package/dist/{init-Y3mkB4XS.js → init-BAJJzBza.js} +2 -2
  47. package/dist/{init-BTzOjA8x.cjs → init-BJVU54pI.cjs} +1 -1
  48. package/dist/{init-D6BxBs7e.cjs → init-BKhH6mVR.cjs} +1 -1
  49. package/dist/{init-EP0CUWNK.cjs → init-BsCBAGWf.cjs} +2 -2
  50. package/dist/{init-Dy-05ktr.cjs → init-BtzMZ7Pk.cjs} +1 -1
  51. package/dist/init-Bv53hpLM.js +19 -0
  52. package/dist/{init-BopV9ed4.cjs → init-C-jErzp5.cjs} +2 -2
  53. package/dist/{init-CjT-WZcW.cjs → init-C4Bkib9u.cjs} +59 -49
  54. package/dist/{init-BEjCRHxU.cjs → init-C7IeJwQR.cjs} +61 -258
  55. package/dist/{init-C-G32J12.cjs → init-CB__aLD7.cjs} +2 -2
  56. package/dist/{init-CyAY4Lzl.js → init-CFYsq82V.js} +1 -1
  57. package/dist/{init-0zzs9aqU.js → init-CLHuAMB-.js} +4 -4
  58. package/dist/{init-DA7zmptx.js → init-CNLGJJRx.js} +1 -1
  59. package/dist/{init-B-YE57gg.js → init-CR6tpw1B.js} +33 -25
  60. package/dist/init-CRbjI7p1.js +3494 -0
  61. package/dist/{init-CSDpdu0Q.cjs → init-CSHwHnfg.cjs} +2 -2
  62. package/dist/{init-CNM5m7M2.js → init-Cg9XdAru.js} +4 -4
  63. package/dist/{init-B3-1ghyx.js → init-CigestoM.js} +2 -2
  64. package/dist/{init-Dv3zKj0r.cjs → init-D6DBUsD3.cjs} +4 -4
  65. package/dist/init-DAna1KCg.cjs +3495 -0
  66. package/dist/{init-D74mn8nH2.js → init-DDdhguVC.js} +2 -2
  67. package/dist/init-DGe47B22.cjs +364 -0
  68. package/dist/init-DMtyvYfC.cjs +21 -0
  69. package/dist/{init-BrdVzxei.cjs → init-DX4WyB0R.cjs} +3 -3
  70. package/dist/{init-C8URA2OX.js → init-DcYY6zMD.js} +1 -1
  71. package/dist/{init-DFMiP2ZH.cjs → init-DkIc5nqF.cjs} +1 -1
  72. package/dist/{init-vqxOQNZi.js → init-Dku4b2lG.js} +1 -1
  73. package/dist/{init-NdhG_VrF.cjs → init-DxUHsN53.cjs} +6 -6
  74. package/dist/{init-COMH3Hfo.js → init-FMGDET-9.js} +60 -259
  75. package/dist/{init-DrkOb-wd.cjs → init-LfyMo-sS.cjs} +2 -2
  76. package/dist/{init-NCjgwCZy.js → init-Rxohwpmu.js} +2 -2
  77. package/dist/init-TkPDD750.js +363 -0
  78. package/dist/{init-C2RgrfZe.js → init-TkPq_Ny_.js} +1 -1
  79. package/dist/{init-5KcGcBb5.cjs → init-U8c9yHYx.cjs} +1 -1
  80. package/dist/{init-CX0AMQUn.js → init-aJHl-7AO.js} +2 -2
  81. package/dist/{init-rmt7-fQE.cjs → init-anYu6XB7.cjs} +2 -2
  82. package/dist/{init-Fw89ZmrR.js → init-w9GEs73W.js} +2 -2
  83. package/dist/{init-Dnsv155v.js → init-y2Ra0vZP.js} +3 -3
  84. package/dist/{init-DFjT8YvT.js → init-zSzCjoor.js} +4 -4
  85. package/dist/{is-retriable-error-BUiVJDwH.js → is-retriable-error-BU0e3hVI.js} +1 -1
  86. package/dist/{is-retriable-error-Dpt860if.cjs → is-retriable-error-CeeuHqDa.cjs} +1 -1
  87. package/dist/{lace-context-BZciB9c7.js → lace-context-CZcNHr4M.js} +4 -4
  88. package/dist/{lace-context-DgR6vLli.cjs → lace-context-fJTDghdp.cjs} +4 -4
  89. package/dist/{libsodium-wrappers-BhbOA8dQ.js → libsodium-wrappers-UH0LaOUE.js} +1647 -3
  90. package/dist/modules-cardano-BDvuL4Xx.js +5248 -0
  91. package/dist/modules-cardano-D2G3De2P.cjs +5432 -0
  92. package/dist/{retry-config-Dmgt28wM.js → retry-config-BcUmMS--.js} +1 -1
  93. package/dist/{retry-config-BaCfVC1H.cjs → retry-config-DC5IMaH7.cjs} +1 -1
  94. package/dist/{seam-cardano-B_etH4F4.js → seam-cardano-CATqBEyK.js} +1 -1
  95. package/dist/{signer-factory-B7PMe3lQ.js → signer-factory-9URFliA5.js} +3 -6
  96. package/dist/{signer-factory-DduwpsQj.cjs → signer-factory-BWGUmnvm.cjs} +3 -4
  97. package/dist/{slice-CqVNnz-j.js → slice-B2PhoWAg.js} +125 -316
  98. package/dist/{slice-DyNs7oWp.js → slice-BNu73oBa.js} +2 -2
  99. package/dist/{slice-GwiiJRoq.js → slice-CB4SnzMm.js} +3 -3
  100. package/dist/slice-CGVHXHDt.cjs +125 -0
  101. package/dist/{slice-CU80pbiu.js → slice-CnyWevM9.js} +3 -3
  102. package/dist/{slice-CwyYrh1H.js → slice-CobanYgn.js} +2 -2
  103. package/dist/{slice-7G2xxYKJ.cjs → slice-CuHUaPZx.cjs} +3 -3
  104. package/dist/{slice-DayJvMRD.cjs → slice-D11m2EKl.cjs} +1 -1
  105. package/dist/{slice-Bg6HEr3K.cjs → slice-DGcNrbPR.cjs} +4 -4
  106. package/dist/{slice-B4CdYoPu.cjs → slice-DZmQJNV8.cjs} +2 -2
  107. package/dist/slice-DhvF7L6X.js +107 -0
  108. package/dist/{slice-C9TT5KhY.cjs → slice-Do2R2CYW.cjs} +6 -6
  109. package/dist/{slice-Bs2aMERu.cjs → slice-DtaO72qY.cjs} +3 -3
  110. package/dist/{slice-C34iOOUH.cjs → slice-HeHCv3bl.cjs} +7 -7
  111. package/dist/{slice-D-9aPKG-.js → slice-d0p6-xj5.js} +6 -6
  112. package/dist/{slice-CK07EBCo.js → slice-eIwcwKHI.js} +4 -4
  113. package/dist/{slice-DBpJ2QGf.js → slice-maaskdUn.js} +6 -6
  114. package/dist/{slice-6sP0Qs5V.cjs → slice-mxLQ_FeY.cjs} +127 -343
  115. package/dist/{slice-DnG-yvpI.cjs → slice-oqm_r1cS.cjs} +2 -2
  116. package/dist/{slice-Da426sf9.js → slice-zJ9XVYjZ.js} +1 -1
  117. package/dist/{sync-operation-utils-KT5Y9yFK.js → sync-operation-utils-BYXLO80m.js} +52 -1
  118. package/dist/{sync-operation-utils-C9kcmjKH.cjs → sync-operation-utils-SdPbwFoD.cjs} +87 -0
  119. package/dist/{token-id-mapper-qx7XfH0b.js → token-id-mapper-B2ivlLv3.js} +2 -2
  120. package/dist/{token-id-mapper-IApjwuJb.cjs → token-id-mapper-DsPAL6Nh.cjs} +2 -2
  121. package/dist/{util-D1e0skzp.js → util-BaLzwa32.js} +1 -1
  122. package/dist/{util-BeG7WXzM.cjs → util-CGzqQ8IV.cjs} +1 -1
  123. package/dist/{utils-DsElZgCI.cjs → utils-5JvjbqH3.cjs} +1 -7
  124. package/dist/{utils-BfBEUvWA.js → utils-o8aMjfln.js} +2 -2
  125. package/dist/{vote-delegation-tx-builder-CtdIgaIt.cjs → vote-delegation-tx-builder-BpEMSti4.cjs} +6 -6
  126. package/dist/{vote-delegation-tx-builder-CQjGvVNZ.js → vote-delegation-tx-builder-CmKv6GoG.js} +5 -5
  127. package/package.json +4 -96
  128. package/dist/_polyfill-buffer-patch-yNxN4d5E.js +0 -1467
  129. package/dist/_web-crypto-random-bytes-Bo-GTcRS.js +0 -197
  130. package/dist/acc-module-4iIUv6My.cjs +0 -27654
  131. package/dist/acc-module-Cmj8EsIb.js +0 -27624
  132. package/dist/account-BlYkEmcs.cjs +0 -11
  133. package/dist/account-DVX0F5_M.js +0 -6
  134. package/dist/account-call-D68oF6bh.js +0 -267
  135. package/dist/account-call-DIIa2rK_.cjs +0 -314
  136. package/dist/account-call-NgLhYein.cjs +0 -4
  137. package/dist/account-call-n-Nkp35e.js +0 -3
  138. package/dist/account-guards-BtjTGxDZ.cjs +0 -42
  139. package/dist/account-guards-D9Lu5T3W.js +0 -36
  140. package/dist/account-tokens-CtN2BaFy.js +0 -16
  141. package/dist/account-tokens-DXr8DlpW.cjs +0 -21
  142. package/dist/address-B9ntKL8K.js +0 -13761
  143. package/dist/address-BXp-mY8H.cjs +0 -11270
  144. package/dist/address-book-address-validator-DK0dnsRS.cjs +0 -41
  145. package/dist/address-book-address-validator-Di_ywo8M.js +0 -39
  146. package/dist/artefact-loader-54uK5RAa.js +0 -160
  147. package/dist/artefact-loader-DZPYrq-6.cjs +0 -183
  148. package/dist/auto-dismiss-failure-on-success-C-qoJuid.cjs +0 -37
  149. package/dist/auto-dismiss-failure-on-success-s8MGDEIu.js +0 -31
  150. package/dist/bip32-D6wd_QMn.cjs +0 -3851
  151. package/dist/bitcoin-data-provider-BYPSmuZS.js +0 -21
  152. package/dist/bitcoin-data-provider-w1oEDSU3.cjs +0 -26
  153. package/dist/bn-d3nSOIf7.cjs +0 -2553
  154. package/dist/browser-B1eMbDwh.js +0 -7468
  155. package/dist/bytes.vo-BB7_4JK6.js +0 -23
  156. package/dist/bytes.vo-BNRquqaO.cjs +0 -34
  157. package/dist/cardano-DfPwhwm-.js +0 -3
  158. package/dist/client-DXBLHk7K.cjs +0 -808
  159. package/dist/codecs-Cswkg7Tm.cjs +0 -4051
  160. package/dist/codecs-Dc1Krpbt.js +0 -3903
  161. package/dist/const-BfEnY8fg.js +0 -153
  162. package/dist/const-BhYOdznB.cjs +0 -42
  163. package/dist/const-CUnCl5U0.js +0 -13
  164. package/dist/const-DLrX5SD9.cjs +0 -31995
  165. package/dist/contract-C_CBwwiC.cjs +0 -189
  166. package/dist/contract-s_x-9-lz.js +0 -171
  167. package/dist/create-add-accounts-Brqk84vF.js +0 -102
  168. package/dist/create-add-accounts-DzXIh7Ot.cjs +0 -114
  169. package/dist/device-commitment-hex.vo-5wFtQvDS.js +0 -26
  170. package/dist/device-commitment-hex.vo-CT3RmAug.cjs +0 -31
  171. package/dist/device-readers-70i7tQqU.cjs +0 -8
  172. package/dist/device-readers-B7--ezKM.js +0 -4
  173. package/dist/device-readers-BWOmz9eD.js +0 -145
  174. package/dist/device-readers-CIgYZN7f.cjs +0 -168
  175. package/dist/dist-BMi5ZjEq.cjs +0 -43175
  176. package/dist/dist-BtIq4XFn.cjs +0 -535
  177. package/dist/dist-C3SHC_Ho.cjs +0 -1394
  178. package/dist/dist-CykEjYEX.cjs +0 -3814
  179. package/dist/dist-Dcsxh3be.cjs +0 -3452
  180. package/dist/dist-DqJfSlTd.cjs +0 -4413
  181. package/dist/dist-nTZ70qj7.cjs +0 -1306
  182. package/dist/enc-key-circuits-C8fGAMEF.cjs +0 -24
  183. package/dist/enc-key-circuits-DA2Xs3vZ.js +0 -13
  184. package/dist/english-Byb9M0E_.cjs +0 -2057
  185. package/dist/envelopes-BkH1Qdxk.js +0 -1620
  186. package/dist/envelopes-ETZEJS_O.cjs +0 -1721
  187. package/dist/errors-BZ8hnhCM.cjs +0 -584
  188. package/dist/errors-DIJTAsLa.js +0 -392
  189. package/dist/esm-HBSUQw3w.js +0 -384
  190. package/dist/esm-LZuaZjMf.cjs +0 -389
  191. package/dist/experimental.cjs +0 -7073
  192. package/dist/experimental.d.ts +0 -84347
  193. package/dist/experimental.js +0 -6915
  194. package/dist/gated-call-Boy6rXdC.js +0 -3
  195. package/dist/gated-call-DJWY299W.cjs +0 -736
  196. package/dist/gated-call-DjoRPqn1.js +0 -695
  197. package/dist/gated-call-SomdJ5nj.cjs +0 -4
  198. package/dist/grant-circuits-_1x--moV.cjs +0 -49
  199. package/dist/grant-circuits-swuzEdUl.js +0 -26
  200. package/dist/grant-rules-7Zqi_3BN.cjs +0 -7114
  201. package/dist/grant-rules-_xJHAT2M.js +0 -6833
  202. package/dist/grant-status-B2y49iIu.js +0 -2688
  203. package/dist/grant-status-DOr3t_u8.cjs +0 -2820
  204. package/dist/grants--b0LQQzZ.cjs +0 -266
  205. package/dist/grants-BIs6qm3b.js +0 -213
  206. package/dist/grants-CSgfYlOO.js +0 -5
  207. package/dist/grants-D61131nK.cjs +0 -17
  208. package/dist/hex-D9ITYbwt.cjs +0 -263
  209. package/dist/hex-mkXcV3pN.js +0 -191
  210. package/dist/http-client-B3N-TMxu.cjs +0 -167
  211. package/dist/http-client-TRlhDZGh.js +0 -155
  212. package/dist/identity-BMLuufva.cjs +0 -263
  213. package/dist/identity-DII6f-h7.js +0 -233
  214. package/dist/in-memory-wallet-integration-B2xzxORj.cjs +0 -20741
  215. package/dist/in-memory-wallet-integration-CUKesGG1.js +0 -130
  216. package/dist/in-memory-wallet-integration-CoPx69lQ.cjs +0 -240
  217. package/dist/in-memory-wallet-integration-TM9bBphA.js +0 -20738
  218. package/dist/init-B5X_sGj9.cjs +0 -6
  219. package/dist/init-BJn-8_hf.js +0 -141
  220. package/dist/init-Bp6yJk31.js +0 -1142
  221. package/dist/init-Bu4iXcTH.cjs +0 -34
  222. package/dist/init-C00gw1zi.js +0 -422
  223. package/dist/init-CIjZaQvL.js +0 -3584
  224. package/dist/init-CR7BfztQ.cjs +0 -18
  225. package/dist/init-Cp8EJGbm.js +0 -5
  226. package/dist/init-CpIadSUb.js +0 -33
  227. package/dist/init-D5UiYI12.cjs +0 -106
  228. package/dist/init-DAikR9qU.js +0 -1177
  229. package/dist/init-DGjXwWs2.cjs +0 -143
  230. package/dist/init-DHrCbpkW.cjs +0 -121
  231. package/dist/init-DU5yYX5u.js +0 -2374
  232. package/dist/init-DWvkFDkc.cjs +0 -1176
  233. package/dist/init-DY1unoGb.cjs +0 -1141
  234. package/dist/init-DlqJuHhl.js +0 -119
  235. package/dist/init-DuYENxci.js +0 -17
  236. package/dist/init-E7c40ddW.cjs +0 -3585
  237. package/dist/init-GsT2AEa4.cjs +0 -424
  238. package/dist/init-KQnIdm39.js +0 -104
  239. package/dist/init-ZjNDDC-T.cjs +0 -2375
  240. package/dist/jubjub-authoriser-BxE3oN2y.js +0 -86
  241. package/dist/jubjub-authoriser-C6SDEP9I.cjs +0 -87
  242. package/dist/key-source-5oUBFiC7.cjs +0 -583
  243. package/dist/key-source-B08HukZg.js +0 -2550
  244. package/dist/keyDerivation-D3k9XyHg.js +0 -4077
  245. package/dist/keyDerivation-u0nBA93T.cjs +0 -274
  246. package/dist/lib--iqvW4O_.js +0 -2354
  247. package/dist/lib-Yk6Upl5D.cjs +0 -2359
  248. package/dist/midnight-account-id.vo-0x9X-r3l.cjs +0 -10
  249. package/dist/midnight-account-id.vo-DjCAGcqc.js +0 -5
  250. package/dist/midnight-engine-DpemplKO.js +0 -5
  251. package/dist/midnight-engine-xU1wotne.cjs +0 -6
  252. package/dist/midnight-wallet-DIsAlSn6.js +0 -18
  253. package/dist/midnight-wallet-XTZc2li7.cjs +0 -24
  254. package/dist/midnight.cjs +0 -1406
  255. package/dist/midnight.d.ts +0 -28586
  256. package/dist/midnight.js +0 -1350
  257. package/dist/modules-cardano-CtWLntet.cjs +0 -1108
  258. package/dist/modules-cardano-D2dkeKHY.js +0 -995
  259. package/dist/node-relay-Cv0cNknM.js +0 -48
  260. package/dist/node-relay-DblH5fKv.cjs +0 -49
  261. package/dist/outputs-Bd2yZVjx.js +0 -720
  262. package/dist/outputs-CJoQBIA2.cjs +0 -990
  263. package/dist/pbkdf2-CIW-oWrm.cjs +0 -1337
  264. package/dist/pending-operation-B0_P78Jo.cjs +0 -26
  265. package/dist/pending-operation-BIS6mpjB.js +0 -21
  266. package/dist/providers-BLgJ0uQs.cjs +0 -366
  267. package/dist/providers-CwnT4vEE.js +0 -343
  268. package/dist/redacted-BmE2aXqr.js +0 -81
  269. package/dist/redacted-CRZJLS3w.cjs +0 -86
  270. package/dist/safe-buffer-B_vMqJWU.js +0 -43
  271. package/dist/safe-buffer-DYOwEfHB.cjs +0 -48
  272. package/dist/sdk-DIcjlgLF.js +0 -1241
  273. package/dist/sdk-Dgal10kG.cjs +0 -1439
  274. package/dist/sdk-init-BKkqFtWZ.cjs +0 -3791
  275. package/dist/sdk-init-DNd-oQXp.js +0 -1044
  276. package/dist/send-proof-progress-DTK3ZuYB.js +0 -22
  277. package/dist/send-proof-progress-dDoqIohG.cjs +0 -33
  278. package/dist/side-effects-BnqYz7Nl.js +0 -768
  279. package/dist/side-effects-CngaeXi0.cjs +0 -804
  280. package/dist/sign-bitcoin-transaction-with-seed-D4z62-jV.js +0 -147
  281. package/dist/sign-bitcoin-transaction-with-seed-DsLYXnCY.cjs +0 -158
  282. package/dist/signer-3fk8lZtE.cjs +0 -7
  283. package/dist/signer-CsL28DrK.cjs +0 -121
  284. package/dist/signer-DGluibtn.js +0 -92
  285. package/dist/signer-RqB5pu3K.js +0 -2
  286. package/dist/signer-factory-BA7WFJVZ.js +0 -282
  287. package/dist/signer-factory-CORIG4Yl.cjs +0 -130
  288. package/dist/signer-factory-Cd2TwD50.js +0 -129
  289. package/dist/signer-factory-Cwd6o-lG.cjs +0 -281
  290. package/dist/slice-BOyAAaj0.cjs +0 -378
  291. package/dist/slice-BnTJeMOb.js +0 -354
  292. package/dist/slice-C4uXUT7S.js +0 -9013
  293. package/dist/slice-CxKWDuBP.js +0 -87
  294. package/dist/slice-DQv_RhsI.cjs +0 -9031
  295. package/dist/slice-HjLXJyQG2.cjs +0 -105
  296. package/dist/src-BDzYIksE.cjs +0 -20637
  297. package/dist/src-BFoefPv_.js +0 -20755
  298. package/dist/store-B1Lq3cEf.cjs +0 -66
  299. package/dist/store-DuBG8qh5.js +0 -37
  300. package/dist/submit-BBYjnZu8.cjs +0 -87
  301. package/dist/submit-D_yxYM_T.js +0 -70
  302. package/dist/submit-bitcoin-tx-BkZIeF4b.js +0 -983
  303. package/dist/submit-bitcoin-tx-DZNQgihl.cjs +0 -1049
  304. package/dist/token-id-mapper-Bnds3xKH.cjs +0 -18
  305. package/dist/token-id-mapper-CnKHQ8DV.js +0 -16
  306. package/dist/tokens-Cevp7rdU.cjs +0 -62
  307. package/dist/tokens-Diw4MLRM.js +0 -44
  308. package/dist/types-B8uiJn-X.js +0 -12
  309. package/dist/types-CJT6XF2c.js +0 -10
  310. package/dist/types-CLRUYpfe.cjs +0 -23
  311. package/dist/types-DWbVZpnF.cjs +0 -15
  312. package/dist/types-T0cjaR75.js +0 -33
  313. package/dist/types-Zj78LtYu.cjs +0 -50
  314. package/dist/unwrap-provider-result-BZSiwabU.js +0 -32
  315. package/dist/unwrap-provider-result-ZqfBsTkk.cjs +0 -39
  316. package/dist/utils-BfMdr_1w.cjs +0 -112
  317. package/dist/utils-CvAW5Yw7.js +0 -65
  318. package/dist/v8Signatures-CO_Uloy7.cjs +0 -71
  319. package/dist/watch-Cz1J42um.cjs +0 -52205
  320. package/dist/watch-Z53L4yoK.js +0 -13054
  321. /package/dist/{account-id.vo-DwqFjK5u.cjs → account-id.vo-LvCBVn5r.cjs} +0 -0
  322. /package/dist/{account-id.vo-OPz2v-JZ.js → account-id.vo-MYSI7YFm.js} +0 -0
  323. /package/dist/{actions-iLXdgL5Y.js → actions-9QSQR-GB.js} +0 -0
  324. /package/dist/{actions-B2BJ4RTy.cjs → actions-DdGbj7c7.cjs} +0 -0
  325. /package/dist/{apply-vkey-witnesses-ZnFS0jnJ.cjs → apply-vkey-witnesses-CLzVSWxl.cjs} +0 -0
  326. /package/dist/{apply-vkey-witnesses-BKx3lcs0.js → apply-vkey-witnesses-ClZbpk5w.js} +0 -0
  327. /package/dist/{asyncoption-CruEYOBI.js → asyncoption-Cw07zPH7.js} +0 -0
  328. /package/dist/{asyncoption-i0VbqVTq.cjs → asyncoption-DYoGuQfP.cjs} +0 -0
  329. /package/dist/{bignum.vo-CEXOIew0.js → bignum.vo-B0rK_PQ1.js} +0 -0
  330. /package/dist/{bignum.vo-hx2kuqlA.cjs → bignum.vo-DsG3kNiZ.cjs} +0 -0
  331. /package/dist/{bip32ed25519-B7Yat217.cjs → bip32ed25519-1ApqeAZk.cjs} +0 -0
  332. /package/dist/{bip32ed25519-FQ8qvdcq.js → bip32ed25519-DetAdGwD.js} +0 -0
  333. /package/dist/{blake2b-DEeVUdKR.cjs → blake2b-B9tftbvG.cjs} +0 -0
  334. /package/dist/{blake2b-BiQTw3GC.js → blake2b-DOEVc57D.js} +0 -0
  335. /package/dist/{blockchain-network-id.vo-BAKEwGjG.cjs → blockchain-network-id.vo-BXpZhvvQ.cjs} +0 -0
  336. /package/dist/{blockchain-network-id.vo-CiVykuqG.js → blockchain-network-id.vo-DNRkuT5B.js} +0 -0
  337. /package/dist/{blockingWithLatestFrom-Cd8c8EPG.js → blockingWithLatestFrom-C5wp_uA-.js} +0 -0
  338. /package/dist/{blockingWithLatestFrom-D8kBPBMX.cjs → blockingWithLatestFrom-DY8OPg0w.cjs} +0 -0
  339. /package/dist/{cardano-network-id-to-network-type-C0ufJOyE.cjs → cardano-network-id-to-network-type-BDTF-HmK.cjs} +0 -0
  340. /package/dist/{cardano-network-id-to-network-type-BWwzeEtM.js → cardano-network-id-to-network-type-CrZfUcyP.js} +0 -0
  341. /package/dist/{cardano-tx-id.vo-D3ASTIMd.cjs → cardano-tx-id.vo-BPhV-AmZ.cjs} +0 -0
  342. /package/dist/{cardano-tx-id.vo-BXLo1b7Q.js → cardano-tx-id.vo-DF9NzZXk.js} +0 -0
  343. /package/dist/{composite-signer-factory-m5cVs9h_.cjs → composite-signer-factory-BpF1mIYA.cjs} +0 -0
  344. /package/dist/{composite-signer-factory-CR8YHA1y.js → composite-signer-factory-_46QsNBz.js} +0 -0
  345. /package/dist/{error-DIZOY2Lw.js → error-BCp9NkPi.js} +0 -0
  346. /package/dist/{error-Cb3EnD0u.cjs → error-CNIquqT5.cjs} +0 -0
  347. /package/dist/{esm-browser-MG97cre9.js → esm-browser-C93Q-EOI.js} +0 -0
  348. /package/dist/{esm-browser-bweqfBlL.cjs → esm-browser-DTc9IK3D.cjs} +0 -0
  349. /package/dist/{feature-flag-key.vo-RlfHL3hq.cjs → feature-flag-key.vo-BPz-ZAp6.cjs} +0 -0
  350. /package/dist/{feature-flag-key.vo-DN_-4-sG.js → feature-flag-key.vo-ofrB6ZVQ.js} +0 -0
  351. /package/dist/{first-state-of-status-unPynOuM.js → first-state-of-status-DQnMT3ya.js} +0 -0
  352. /package/dist/{first-state-of-status-CbT7hPa4.cjs → first-state-of-status-OROkXcRv.cjs} +0 -0
  353. /package/dist/{init-zUoRG_EC2.cjs → init-C5CEZ1m0.cjs} +0 -0
  354. /package/dist/{init-DHaMxHM1.js → init-CKipPE_c.js} +0 -0
  355. /package/dist/{init-Atisw4x2.cjs → init-DFQQ9dTW.cjs} +0 -0
  356. /package/dist/{init-829HRYcz.js → init-Es3wHW7D.js} +0 -0
  357. /package/dist/{init-BgNobbNq.cjs → init-IAk_CkGa.cjs} +0 -0
  358. /package/dist/{init-atCFur0v.js → init-cqN3uX2j.js} +0 -0
  359. /package/dist/{is-redux-persist-state-BCFnSm36.cjs → is-redux-persist-state-CTn3WZVh.cjs} +0 -0
  360. /package/dist/{is-redux-persist-state-yBfq0h_E.js → is-redux-persist-state-Cxcd0_bM.js} +0 -0
  361. /package/dist/{key-value-store--W3SrMaw.js → key-value-store-8cMzeNyG.js} +0 -0
  362. /package/dist/{key-value-store-C2Xt5Emp.cjs → key-value-store-DUAepXQf.cjs} +0 -0
  363. /package/dist/{repo-slice-RxFm0zDZ.js → repo-slice-DwyMhCR1.js} +0 -0
  364. /package/dist/{repo-slice-7X4AYYVm.cjs → repo-slice-WxetRhMY.cjs} +0 -0
  365. /package/dist/{reselect-CGoLzEPv.js → reselect-C06X06oX.js} +0 -0
  366. /package/dist/{reselect-Bd94u0K-.cjs → reselect-CRDqmQY9.cjs} +0 -0
  367. /package/dist/{serializable-BHdKIgk3.js → serializable-B8GahgE1.js} +0 -0
  368. /package/dist/{serializable-BxHkoPdk.cjs → serializable-CRdnFaLZ.cjs} +0 -0
  369. /package/dist/{slice-obCSLm1x.js → slice-B87b52iM.js} +0 -0
  370. /package/dist/{slice-Bk0Sv05J.js → slice-Be7hj4Iy.js} +0 -0
  371. /package/dist/{slice-BiRsDKOK.cjs → slice-D11FHQuQ.cjs} +0 -0
  372. /package/dist/{slice-Dqw1ecum.cjs → slice-FioKeHtA.cjs} +0 -0
  373. /package/dist/{src-Cqp0B2M_.cjs → src-BTPIvlDI.cjs} +0 -0
  374. /package/dist/{src-BlxEp6Mm.js → src-vq1wS9sZ.js} +0 -0
  375. /package/dist/{time.vo-D3wWRw9L.cjs → time.vo-CQ8pSXz2.cjs} +0 -0
  376. /package/dist/{time.vo-tNheinXm.js → time.vo-DkYYGYp6.js} +0 -0
  377. /package/dist/{toEmpty-8Zax1MPd.js → toEmpty-CgAl3097.js} +0 -0
  378. /package/dist/{toEmpty-CYAbupM4.cjs → toEmpty-DAMmNB5r.cjs} +0 -0
  379. /package/dist/{token-id.vo-DXv5uS9n.cjs → token-id.vo-BxG9TG0O.cjs} +0 -0
  380. /package/dist/{token-id.vo-Bvwhr3ZE.js → token-id.vo-ClsroxHO.js} +0 -0
  381. /package/dist/{util-CzeB3hfa.cjs → util-CmdAhheh.cjs} +0 -0
  382. /package/dist/{util-C8a4fA9p.js → util-DxzlYNS5.js} +0 -0
  383. /package/dist/{util-selector-BWPH68_l.cjs → util-selector-BcAncU4L.cjs} +0 -0
  384. /package/dist/{util-selector-BSTsxgne.js → util-selector-CcK-GAdE.js} +0 -0
  385. /package/dist/{while-active-B0lWy_6l.js → while-active-BpppWuCs.js} +0 -0
  386. /package/dist/{while-active-Dsowp0Fi.cjs → while-active-Dhc2LwOm.cjs} +0 -0
@@ -1,1620 +0,0 @@
1
- import { n as HexBytes, t as ByteArray } from "./bytes.vo-BB7_4JK6.js";
2
- import { A as equalBytes$1, C as aInRange, D as bytesToNumberLE, E as bytesToNumberBE, F as sha512, G as GrantScopeSalt, I as abytes$1, K as GrantId, L as hexToBytes, M as numberToBytesLE, N as randomBytes, O as concatBytes, P as validateObject, S as pow2, T as asciiToBytes, W as GrantSlot, _ as FpSqrtEven, b as mapHashToField, c as _DST_scalar, d as PrimeEdwardsPoint, f as edwards, g as FpInvertBatch, h as validatePointCons, j as numberToBytesBE, k as copyBytes, l as createHasher, m as pippenger, o as jubjub, p as createKeygen, q as sha256, s as createFROST, t as RECIPIENT_KINDS, u as expand_message_xmd, v as getMinHashLength, w as abytes, x as mod, y as isNegativeLE } from "./grant-rules-_xJHAT2M.js";
3
- //#region ../../packages/module/passport-account/node_modules/@noble/curves/abstract/montgomery.js
4
- /**
5
- * Montgomery curve methods. It's not really whole montgomery curve,
6
- * just bunch of very specific methods for X25519 / X448 from
7
- * [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748)
8
- * @module
9
- */
10
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
- const _0n$1 = BigInt(0);
12
- const _1n$1 = BigInt(1);
13
- const _2n$1 = BigInt(2);
14
- function validateOpts(curve) {
15
- validateObject(curve, {
16
- P: "bigint",
17
- type: "string",
18
- adjustScalarBytes: "function",
19
- powPminus2: "function"
20
- }, { randomBytes: "function" });
21
- return Object.freeze({ ...curve });
22
- }
23
- /**
24
- * @param curveDef - Montgomery curve definition.
25
- * @returns ECDH helper namespace.
26
- * @throws If the curve definition or derived shared point is invalid. {@link Error}
27
- * @example
28
- * Perform one X25519 key exchange through the generic Montgomery helper.
29
- *
30
- * ```ts
31
- * import { x25519 } from '@noble/curves/ed25519.js';
32
- * const alice = x25519.keygen();
33
- * const shared = x25519.getSharedSecret(alice.secretKey, alice.publicKey);
34
- * ```
35
- */
36
- function montgomery(curveDef) {
37
- const { P, type, adjustScalarBytes, powPminus2, randomBytes: rand } = validateOpts(curveDef);
38
- const is25519 = type === "x25519";
39
- if (!is25519 && type !== "x448") throw new Error("invalid type");
40
- const randomBytes_ = rand === void 0 ? randomBytes : rand;
41
- const montgomeryBits = is25519 ? 255 : 448;
42
- const fieldLen = is25519 ? 32 : 56;
43
- const Gu = is25519 ? BigInt(9) : BigInt(5);
44
- const a24 = is25519 ? BigInt(121665) : BigInt(39081);
45
- const minScalar = is25519 ? _2n$1 ** BigInt(254) : _2n$1 ** BigInt(447);
46
- const maxScalar = minScalar + (is25519 ? BigInt(8) * _2n$1 ** BigInt(251) - _1n$1 : BigInt(4) * _2n$1 ** BigInt(445) - _1n$1) + _1n$1;
47
- const modP = (n) => mod(n, P);
48
- const GuBytes = encodeU(Gu);
49
- function encodeU(u) {
50
- return numberToBytesLE(modP(u), fieldLen);
51
- }
52
- function decodeU(u) {
53
- const _u = copyBytes(abytes(u, fieldLen, "uCoordinate"));
54
- if (is25519) _u[31] &= 127;
55
- return modP(bytesToNumberLE(_u));
56
- }
57
- function decodeScalar(scalar) {
58
- return bytesToNumberLE(adjustScalarBytes(copyBytes(abytes(scalar, fieldLen, "scalar"))));
59
- }
60
- function scalarMult(scalar, u) {
61
- const pu = montgomeryLadder(decodeU(u), decodeScalar(scalar));
62
- if (pu === _0n$1) throw new Error("invalid private or public key received");
63
- return encodeU(pu);
64
- }
65
- function scalarMultBase(scalar) {
66
- return scalarMult(scalar, GuBytes);
67
- }
68
- const getPublicKey = scalarMultBase;
69
- const getSharedSecret = scalarMult;
70
- function cswap(swap, x_2, x_3) {
71
- const dummy = modP(swap * (x_2 - x_3));
72
- x_2 = modP(x_2 - dummy);
73
- x_3 = modP(x_3 + dummy);
74
- return {
75
- x_2,
76
- x_3
77
- };
78
- }
79
- /**
80
- * Montgomery x-only multiplication ladder for the selected X25519/X448 curve.
81
- * @param pointU - decoded Montgomery u coordinate for the selected curve
82
- * @param scalar - decoded clamped scalar by which the point is multiplied
83
- * @returns resulting Montgomery u coordinate for the selected curve
84
- */
85
- function montgomeryLadder(u, scalar) {
86
- aInRange("u", u, _0n$1, P);
87
- aInRange("scalar", scalar, minScalar, maxScalar);
88
- const k = scalar;
89
- const x_1 = u;
90
- let x_2 = _1n$1;
91
- let z_2 = _0n$1;
92
- let x_3 = u;
93
- let z_3 = _1n$1;
94
- let swap = _0n$1;
95
- for (let t = BigInt(montgomeryBits - 1); t >= _0n$1; t--) {
96
- const k_t = k >> t & _1n$1;
97
- swap ^= k_t;
98
- ({x_2, x_3} = cswap(swap, x_2, x_3));
99
- ({x_2: z_2, x_3: z_3} = cswap(swap, z_2, z_3));
100
- swap = k_t;
101
- const A = x_2 + z_2;
102
- const AA = modP(A * A);
103
- const B = x_2 - z_2;
104
- const BB = modP(B * B);
105
- const E = AA - BB;
106
- const C = x_3 + z_3;
107
- const DA = modP((x_3 - z_3) * A);
108
- const CB = modP(C * B);
109
- const dacb = DA + CB;
110
- const da_cb = DA - CB;
111
- x_3 = modP(dacb * dacb);
112
- z_3 = modP(x_1 * modP(da_cb * da_cb));
113
- x_2 = modP(AA * BB);
114
- z_2 = modP(E * (AA + modP(a24 * E)));
115
- }
116
- ({x_2, x_3} = cswap(swap, x_2, x_3));
117
- ({x_2: z_2, x_3: z_3} = cswap(swap, z_2, z_3));
118
- const z2 = powPminus2(z_2);
119
- return modP(x_2 * z2);
120
- }
121
- const lengths = {
122
- secretKey: fieldLen,
123
- publicKey: fieldLen,
124
- seed: fieldLen
125
- };
126
- const randomSecretKey = (seed) => {
127
- seed = seed === void 0 ? randomBytes_(fieldLen) : seed;
128
- abytes(seed, lengths.seed, "seed");
129
- return seed;
130
- };
131
- const utils = { randomSecretKey };
132
- Object.freeze(lengths);
133
- Object.freeze(utils);
134
- return Object.freeze({
135
- keygen: createKeygen(randomSecretKey, getPublicKey),
136
- getSharedSecret,
137
- getPublicKey,
138
- scalarMult,
139
- scalarMultBase,
140
- utils,
141
- GuBytes: GuBytes.slice(),
142
- lengths
143
- });
144
- }
145
- //#endregion
146
- //#region ../../packages/module/passport-account/node_modules/@noble/curves/abstract/oprf.js
147
- /**
148
- * RFC 9497: Oblivious Pseudorandom Functions (OPRFs) Using Prime-Order Groups.
149
- * https://www.rfc-editor.org/rfc/rfc9497
150
- *
151
-
152
- OPRF allows to interactively create an `Output = PRF(Input, serverSecretKey)`:
153
-
154
- - Server cannot calculate Output by itself: it doesn't know Input
155
- - Client cannot calculate Output by itself: it doesn't know server secretKey
156
- - An attacker interception the communication can't restore Input/Output/serverSecretKey and can't
157
- link Input to some value.
158
-
159
- ## Issues
160
-
161
- - Low-entropy inputs (e.g. password '123') enable brute-forced dictionary attacks by the server
162
- (solveable by domain separation in POPRF)
163
- - High-level protocol needs to be constructed on top, because OPRF is low-level
164
-
165
- ## Use cases
166
-
167
- 1. **Password-Authenticated Key Exchange (PAKE):** Enables secure password login (e.g., OPAQUE)
168
- without revealing the password to the server.
169
- 2. **Private Set Intersection (PSI):** Allows two parties to compute the intersection of their
170
- private sets without revealing non-intersecting elements.
171
- 3. **Anonymous Credential Systems:** Supports issuance of anonymous, unlinkable credentials
172
- (e.g., Privacy Pass) using blind OPRF evaluation.
173
- 4. **Private Information Retrieval (PIR):** Helps users query databases without revealing which
174
- item they accessed.
175
- 5. **Encrypted Search / Secure Indexing:** Enables keyword search over encrypted data while keeping
176
- queries private.
177
- 6. **Spam Prevention and Rate-Limiting:** Issues anonymous tokens to prevent abuse
178
- (e.g., CAPTCHA bypass) without compromising user privacy.
179
-
180
- ## Modes
181
-
182
- - OPRF: simple mode, client doesn't need to know server public key
183
- - VOPRF: verifiable mode. It lets the client verify that the server used the
184
- secret key corresponding to a known public key
185
- - POPRF: partially oblivious mode, VOPRF + domain separation
186
-
187
- There is also non-interactive mode (Evaluate), which creates Output
188
- non-interactively with knowledge of the secret key.
189
-
190
- Flow:
191
- - (once) Server generates secret and public keys, distributes public keys to clients
192
- - deterministically: `deriveKeyPair` or just random: `generateKeyPair`
193
- - Client blinds input: `blind(secretInput)`
194
- - Server evaluates blinded input: `blindEvaluate` generated by client, sends result to client
195
- - Client creates output using result of evaluation via 'finalize'
196
-
197
- * @module
198
- */
199
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
200
- const _DST_scalarBytes = /* @__PURE__ */ asciiToBytes(_DST_scalar);
201
- /**
202
- * @param opts - OPRF ciphersuite options. See {@link OPRFOpts}.
203
- * @returns OPRF helper namespace.
204
- * @example
205
- * Instantiate an OPRF suite from curve-specific hashing hooks.
206
- *
207
- * ```ts
208
- * import { createOPRF } from '@noble/curves/abstract/oprf.js';
209
- * import { p256, p256_hasher } from '@noble/curves/nist.js';
210
- * import { sha256 } from '@noble/hashes/sha2.js';
211
- * const oprf = createOPRF({
212
- * name: 'P256-SHA256',
213
- * Point: p256.Point,
214
- * hash: sha256,
215
- * hashToGroup: p256_hasher.hashToCurve,
216
- * hashToScalar: p256_hasher.hashToScalar,
217
- * });
218
- * const keys = oprf.oprf.generateKeyPair();
219
- * ```
220
- */
221
- function createOPRF(opts) {
222
- validateObject(opts, {
223
- name: "string",
224
- hash: "function",
225
- hashToScalar: "function",
226
- hashToGroup: "function"
227
- });
228
- validatePointCons(opts.Point);
229
- const { name, Point, hash } = opts;
230
- const { Fn } = Point;
231
- const hashToGroup = (msg, ctx) => opts.hashToGroup(msg, { DST: concatBytes(asciiToBytes("HashToGroup-"), ctx) });
232
- const hashToScalarPrefixed = (msg, ctx) => opts.hashToScalar(msg, { DST: concatBytes(_DST_scalarBytes, ctx) });
233
- const randomScalar = (rng = randomBytes) => {
234
- const t = mapHashToField(rng(getMinHashLength(Fn.ORDER)), Fn.ORDER, Fn.isLE);
235
- return Fn.isLE ? bytesToNumberLE(t) : bytesToNumberBE(t);
236
- };
237
- const msm = (points, scalars) => pippenger(Point, points, scalars);
238
- const getCtx = (mode) => concatBytes(asciiToBytes("OPRFV1-"), new Uint8Array([mode]), asciiToBytes("-" + name));
239
- const ctxOPRF = getCtx(0);
240
- const ctxVOPRF = getCtx(1);
241
- const ctxPOPRF = getCtx(2);
242
- function encode(...args) {
243
- const res = [];
244
- for (const a of args) if (typeof a === "number") res.push(numberToBytesBE(a, 2));
245
- else if (typeof a === "string") res.push(asciiToBytes(a));
246
- else {
247
- abytes(a);
248
- res.push(numberToBytesBE(a.length, 2), a);
249
- }
250
- return concatBytes(...res);
251
- }
252
- const inputBytes = (title, bytes) => {
253
- abytes(bytes, void 0, title);
254
- if (bytes.length > 65535) throw new Error(`"${title}" expected Uint8Array of length <= 65535, got length=${bytes.length}`);
255
- return bytes;
256
- };
257
- const hashInput = (...bytes) => hash(encode(...bytes, "Finalize"));
258
- function getTranscripts(B, C, D, ctx) {
259
- const seed = hash(encode(B.toBytes(), concatBytes(asciiToBytes("Seed-"), ctx)));
260
- const res = [];
261
- for (let i = 0; i < C.length; i++) {
262
- const Ci = C[i].toBytes();
263
- const Di = D[i].toBytes();
264
- const di = hashToScalarPrefixed(encode(seed, i, Ci, Di, "Composite"), ctx);
265
- res.push(di);
266
- }
267
- return res;
268
- }
269
- function computeComposites(B, C, D, ctx) {
270
- const T = getTranscripts(B, C, D, ctx);
271
- return {
272
- M: msm(C, T),
273
- Z: msm(D, T)
274
- };
275
- }
276
- function computeCompositesFast(k, B, C, D, ctx) {
277
- const M = msm(C, getTranscripts(B, C, D, ctx));
278
- return {
279
- M,
280
- Z: M.multiply(k)
281
- };
282
- }
283
- function challengeTranscript(B, M, Z, t2, t3, ctx) {
284
- const [Bm, a0, a1, a2, a3] = [
285
- B,
286
- M,
287
- Z,
288
- t2,
289
- t3
290
- ].map((i) => i.toBytes());
291
- return hashToScalarPrefixed(encode(Bm, a0, a1, a2, a3, "Challenge"), ctx);
292
- }
293
- function generateProof(ctx, k, B, C, D, rng) {
294
- const { M, Z } = computeCompositesFast(k, B, C, D, ctx);
295
- const r = randomScalar(rng);
296
- const c = challengeTranscript(B, M, Z, Point.BASE.multiply(r), M.multiply(r), ctx);
297
- return concatBytes(...[c, Fn.sub(r, Fn.mul(c, k))].map((i) => Fn.toBytes(i)));
298
- }
299
- function verifyProof(ctx, B, C, D, proof) {
300
- abytes(proof, 2 * Fn.BYTES);
301
- const { M, Z } = computeComposites(B, C, D, ctx);
302
- const [c, s] = [proof.subarray(0, Fn.BYTES), proof.subarray(Fn.BYTES)].map((f) => Fn.fromBytes(f));
303
- const expectedC = challengeTranscript(B, M, Z, Point.BASE.multiply(s).add(B.multiply(c)), M.multiply(s).add(Z.multiply(c)), ctx);
304
- if (!Fn.eql(c, expectedC)) throw new Error("proof verification failed");
305
- }
306
- function generateKeyPair() {
307
- const skS = randomScalar();
308
- const pkS = Point.BASE.multiply(skS);
309
- return {
310
- secretKey: Fn.toBytes(skS),
311
- publicKey: pkS.toBytes()
312
- };
313
- }
314
- function deriveKeyPair(ctx, seed, info) {
315
- abytes(seed, 32, "seed");
316
- info = inputBytes("keyInfo", info);
317
- const dst = concatBytes(asciiToBytes("DeriveKeyPair"), ctx);
318
- const msg = concatBytes(seed, encode(info), Uint8Array.of(0));
319
- for (let counter = 0; counter <= 255; counter++) {
320
- msg[msg.length - 1] = counter;
321
- const skS = opts.hashToScalar(msg, { DST: dst });
322
- if (Fn.is0(skS)) continue;
323
- return {
324
- secretKey: Fn.toBytes(skS),
325
- publicKey: Point.BASE.multiply(skS).toBytes()
326
- };
327
- }
328
- throw new Error("Cannot derive key");
329
- }
330
- const wirePoint = (label, bytes) => {
331
- const point = Point.fromBytes(bytes);
332
- if (point.equals(Point.ZERO)) throw new Error(label + " point at infinity");
333
- return point;
334
- };
335
- function blind(ctx, input, rng = randomBytes) {
336
- input = inputBytes("input", input);
337
- const blind = randomScalar(rng);
338
- const inputPoint = hashToGroup(input, ctx);
339
- if (inputPoint.equals(Point.ZERO)) throw new Error("Input point at infinity");
340
- const blinded = inputPoint.multiply(blind);
341
- return {
342
- blind: Fn.toBytes(blind),
343
- blinded: blinded.toBytes()
344
- };
345
- }
346
- function evaluate(ctx, secretKey, input) {
347
- input = inputBytes("input", input);
348
- const skS = Fn.fromBytes(secretKey);
349
- const inputPoint = hashToGroup(input, ctx);
350
- if (inputPoint.equals(Point.ZERO)) throw new Error("Input point at infinity");
351
- const unblinded = inputPoint.multiply(skS).toBytes();
352
- return hashInput(input, unblinded);
353
- }
354
- const oprf = Object.freeze({
355
- generateKeyPair,
356
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxOPRF, seed, keyInfo),
357
- blind: (input, rng = randomBytes) => blind(ctxOPRF, input, rng),
358
- blindEvaluate(secretKey, blindedPoint) {
359
- const skS = Fn.fromBytes(secretKey);
360
- return wirePoint("blinded", blindedPoint).multiply(skS).toBytes();
361
- },
362
- finalize(input, blindBytes, evaluatedBytes) {
363
- input = inputBytes("input", input);
364
- const blind = Fn.fromBytes(blindBytes);
365
- const unblinded = wirePoint("evaluated", evaluatedBytes).multiply(Fn.inv(blind)).toBytes();
366
- return hashInput(input, unblinded);
367
- },
368
- evaluate: (secretKey, input) => evaluate(ctxOPRF, secretKey, input)
369
- });
370
- const voprf = Object.freeze({
371
- generateKeyPair,
372
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxVOPRF, seed, keyInfo),
373
- blind: (input, rng = randomBytes) => blind(ctxVOPRF, input, rng),
374
- blindEvaluateBatch(secretKey, publicKey, blinded, rng = randomBytes) {
375
- if (!Array.isArray(blinded)) throw new Error("expected array");
376
- const skS = Fn.fromBytes(secretKey);
377
- const pkS = wirePoint("public key", publicKey);
378
- const blindedPoints = blinded.map((i) => wirePoint("blinded", i));
379
- const evaluated = blindedPoints.map((i) => i.multiply(skS));
380
- const proof = generateProof(ctxVOPRF, skS, pkS, blindedPoints, evaluated, rng);
381
- return {
382
- evaluated: evaluated.map((i) => i.toBytes()),
383
- proof
384
- };
385
- },
386
- blindEvaluate(secretKey, publicKey, blinded, rng = randomBytes) {
387
- const res = this.blindEvaluateBatch(secretKey, publicKey, [blinded], rng);
388
- return {
389
- evaluated: res.evaluated[0],
390
- proof: res.proof
391
- };
392
- },
393
- finalizeBatch(items, publicKey, proof) {
394
- if (!Array.isArray(items)) throw new Error("expected array");
395
- verifyProof(ctxVOPRF, wirePoint("public key", publicKey), items.map((i) => wirePoint("blinded", i.blinded)), items.map((i) => wirePoint("evaluated", i.evaluated)), proof);
396
- return items.map((i) => oprf.finalize(i.input, i.blind, i.evaluated));
397
- },
398
- finalize(input, blind, evaluated, blinded, publicKey, proof) {
399
- return this.finalizeBatch([{
400
- input,
401
- blind,
402
- evaluated,
403
- blinded
404
- }], publicKey, proof)[0];
405
- },
406
- evaluate: (secretKey, input) => evaluate(ctxVOPRF, secretKey, input)
407
- });
408
- const poprf = (info) => {
409
- info = inputBytes("info", info);
410
- const m = hashToScalarPrefixed(encode("Info", info), ctxPOPRF);
411
- const T = Point.BASE.multiply(m);
412
- return Object.freeze({
413
- generateKeyPair,
414
- deriveKeyPair: (seed, keyInfo) => deriveKeyPair(ctxPOPRF, seed, keyInfo),
415
- blind(input, publicKey, rng = randomBytes) {
416
- input = inputBytes("input", input);
417
- const pkS = wirePoint("public key", publicKey);
418
- const tweakedKey = T.add(pkS);
419
- if (tweakedKey.equals(Point.ZERO)) throw new Error("tweakedKey point at infinity");
420
- const blind = randomScalar(rng);
421
- const inputPoint = hashToGroup(input, ctxPOPRF);
422
- if (inputPoint.equals(Point.ZERO)) throw new Error("Input point at infinity");
423
- const blindedPoint = inputPoint.multiply(blind);
424
- return {
425
- blind: Fn.toBytes(blind),
426
- blinded: blindedPoint.toBytes(),
427
- tweakedKey: tweakedKey.toBytes()
428
- };
429
- },
430
- blindEvaluateBatch(secretKey, blinded, rng = randomBytes) {
431
- if (!Array.isArray(blinded)) throw new Error("expected array");
432
- const skS = Fn.fromBytes(secretKey);
433
- const t = Fn.add(skS, m);
434
- const invT = Fn.inv(t);
435
- const blindedPoints = blinded.map((i) => wirePoint("blinded", i));
436
- const evalPoints = blindedPoints.map((i) => i.multiply(invT));
437
- const proof = generateProof(ctxPOPRF, t, Point.BASE.multiply(t), evalPoints, blindedPoints, rng);
438
- return {
439
- evaluated: evalPoints.map((i) => i.toBytes()),
440
- proof
441
- };
442
- },
443
- blindEvaluate(secretKey, blinded, rng = randomBytes) {
444
- const res = this.blindEvaluateBatch(secretKey, [blinded], rng);
445
- return {
446
- evaluated: res.evaluated[0],
447
- proof: res.proof
448
- };
449
- },
450
- finalizeBatch(items, proof, tweakedKey) {
451
- if (!Array.isArray(items)) throw new Error("expected array");
452
- const inputs = items.map((i) => inputBytes("input", i.input));
453
- const evalPoints = items.map((i) => wirePoint("evaluated", i.evaluated));
454
- verifyProof(ctxPOPRF, wirePoint("tweakedKey", tweakedKey), evalPoints, items.map((i) => wirePoint("blinded", i.blinded)), proof);
455
- return items.map((i, j) => {
456
- const blind = Fn.fromBytes(i.blind);
457
- const point = evalPoints[j].multiply(Fn.inv(blind)).toBytes();
458
- return hashInput(inputs[j], info, point);
459
- });
460
- },
461
- finalize(input, blind, evaluated, blinded, proof, tweakedKey) {
462
- return this.finalizeBatch([{
463
- input,
464
- blind,
465
- evaluated,
466
- blinded
467
- }], proof, tweakedKey)[0];
468
- },
469
- evaluate(secretKey, input) {
470
- input = inputBytes("input", input);
471
- const skS = Fn.fromBytes(secretKey);
472
- const inputPoint = hashToGroup(input, ctxPOPRF);
473
- if (inputPoint.equals(Point.ZERO)) throw new Error("Input point at infinity");
474
- const t = Fn.add(skS, m);
475
- const invT = Fn.inv(t);
476
- const unblinded = inputPoint.multiply(invT).toBytes();
477
- return hashInput(input, info, unblinded);
478
- }
479
- });
480
- };
481
- const res = {
482
- name,
483
- oprf,
484
- voprf,
485
- poprf,
486
- __tests: Object.freeze({ Fn })
487
- };
488
- return Object.freeze(res);
489
- }
490
- //#endregion
491
- //#region ../../packages/module/passport-account/node_modules/@noble/curves/ed25519.js
492
- /**
493
- * ed25519 Twisted Edwards curve with following addons:
494
- * - X25519 ECDH
495
- * - Ristretto cofactor elimination
496
- * - Elligator hash-to-group / point indistinguishability
497
- * @module
498
- */
499
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
500
- const _0n = /* @__PURE__ */ BigInt(0), _1n = /* @__PURE__ */ BigInt(1), _2n = /* @__PURE__ */ BigInt(2), _3n = /* @__PURE__ */ BigInt(3);
501
- const _5n = /* @__PURE__ */ BigInt(5), _8n = /* @__PURE__ */ BigInt(8);
502
- const ed25519_CURVE_p = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
503
- const ed25519_CURVE = {
504
- p: ed25519_CURVE_p,
505
- n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
506
- h: _8n,
507
- a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
508
- d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
509
- Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
510
- Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
511
- };
512
- function ed25519_pow_2_252_3(x) {
513
- const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
514
- const P = ed25519_CURVE_p;
515
- const b2 = x * x % P * x % P;
516
- const b5 = pow2(pow2(b2, _2n, P) * b2 % P, _1n, P) * x % P;
517
- const b10 = pow2(b5, _5n, P) * b5 % P;
518
- const b20 = pow2(b10, _10n, P) * b10 % P;
519
- const b40 = pow2(b20, _20n, P) * b20 % P;
520
- const b80 = pow2(b40, _40n, P) * b40 % P;
521
- return {
522
- pow_p_5_8: pow2(pow2(pow2(pow2(b80, _80n, P) * b80 % P, _80n, P) * b80 % P, _10n, P) * b10 % P, _2n, P) * x % P,
523
- b2
524
- };
525
- }
526
- function adjustScalarBytes(bytes) {
527
- bytes[0] &= 248;
528
- bytes[31] &= 127;
529
- bytes[31] |= 64;
530
- return bytes;
531
- }
532
- const ED25519_SQRT_M1 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
533
- function uvRatio(u, v) {
534
- const P = ed25519_CURVE_p;
535
- const v3 = mod(v * v * v, P);
536
- const pow = ed25519_pow_2_252_3(u * mod(v3 * v3 * v, P)).pow_p_5_8;
537
- let x = mod(u * v3 * pow, P);
538
- const vx2 = mod(v * x * x, P);
539
- const root1 = x;
540
- const root2 = mod(x * ED25519_SQRT_M1, P);
541
- const useRoot1 = vx2 === u;
542
- const useRoot2 = vx2 === mod(-u, P);
543
- const noRoot = vx2 === mod(-u * ED25519_SQRT_M1, P);
544
- if (useRoot1) x = root1;
545
- if (useRoot2 || noRoot) x = root2;
546
- if (isNegativeLE(x, P)) x = mod(-x, P);
547
- return {
548
- isValid: useRoot1 || useRoot2,
549
- value: x
550
- };
551
- }
552
- const ed25519_Point = /* @__PURE__ */ edwards(ed25519_CURVE, { uvRatio });
553
- const Fp = ed25519_Point.Fp;
554
- const Fn = ed25519_Point.Fn;
555
- createFROST({
556
- name: "FROST-ED25519-SHA512-v1",
557
- Point: ed25519_Point,
558
- validatePoint: (p) => {
559
- p.assertValidity();
560
- if (!p.isTorsionFree()) throw new Error("bad point: not torsion-free");
561
- },
562
- hash: sha512,
563
- H2: ""
564
- });
565
- /**
566
- * ECDH using curve25519 aka x25519.
567
- * `getSharedSecret()` rejects low-order peer inputs by default, and seeded
568
- * `keygen(seed)` reuses the provided 32-byte seed buffer instead of copying it.
569
- * @example
570
- * Derive one shared secret between two X25519 peers.
571
- *
572
- * ```js
573
- * import { x25519 } from '@noble/curves/ed25519.js';
574
- * const alice = x25519.keygen();
575
- * const bob = x25519.keygen();
576
- * const shared = x25519.getSharedSecret(alice.secretKey, bob.publicKey);
577
- * ```
578
- */
579
- const x25519 = /* @__PURE__ */ (() => {
580
- const P = ed25519_CURVE_p;
581
- return montgomery({
582
- P,
583
- type: "x25519",
584
- powPminus2: (x) => {
585
- const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
586
- return mod(pow2(pow_p_5_8, _3n, P) * b2, P);
587
- },
588
- adjustScalarBytes
589
- });
590
- })();
591
- const ELL2_C1 = (ed25519_CURVE_p + _3n) / _8n;
592
- const ELL2_C2 = Fp.pow(_2n, ELL2_C1);
593
- const ELL2_C3 = Fp.sqrt(Fp.neg(Fp.ONE));
594
- /**
595
- * RFC 9380 method `map_to_curve_elligator2_curve25519`. Experimental name: may be renamed later.
596
- * @private
597
- */
598
- function _map_to_curve_elligator2_curve25519(u) {
599
- const ELL2_C4 = (ed25519_CURVE_p - _5n) / _8n;
600
- const ELL2_J = BigInt(486662);
601
- let tv1 = Fp.sqr(u);
602
- tv1 = Fp.mul(tv1, _2n);
603
- let xd = Fp.add(tv1, Fp.ONE);
604
- let x1n = Fp.neg(ELL2_J);
605
- let tv2 = Fp.sqr(xd);
606
- let gxd = Fp.mul(tv2, xd);
607
- let gx1 = Fp.mul(tv1, ELL2_J);
608
- gx1 = Fp.mul(gx1, x1n);
609
- gx1 = Fp.add(gx1, tv2);
610
- gx1 = Fp.mul(gx1, x1n);
611
- let tv3 = Fp.sqr(gxd);
612
- tv2 = Fp.sqr(tv3);
613
- tv3 = Fp.mul(tv3, gxd);
614
- tv3 = Fp.mul(tv3, gx1);
615
- tv2 = Fp.mul(tv2, tv3);
616
- let y11 = Fp.pow(tv2, ELL2_C4);
617
- y11 = Fp.mul(y11, tv3);
618
- let y12 = Fp.mul(y11, ELL2_C3);
619
- tv2 = Fp.sqr(y11);
620
- tv2 = Fp.mul(tv2, gxd);
621
- let e1 = Fp.eql(tv2, gx1);
622
- let y1 = Fp.cmov(y12, y11, e1);
623
- let x2n = Fp.mul(x1n, tv1);
624
- let y21 = Fp.mul(y11, u);
625
- y21 = Fp.mul(y21, ELL2_C2);
626
- let y22 = Fp.mul(y21, ELL2_C3);
627
- let gx2 = Fp.mul(gx1, tv1);
628
- tv2 = Fp.sqr(y21);
629
- tv2 = Fp.mul(tv2, gxd);
630
- let e2 = Fp.eql(tv2, gx2);
631
- let y2 = Fp.cmov(y22, y21, e2);
632
- tv2 = Fp.sqr(y1);
633
- tv2 = Fp.mul(tv2, gxd);
634
- let e3 = Fp.eql(tv2, gx1);
635
- let xn = Fp.cmov(x2n, x1n, e3);
636
- let y = Fp.cmov(y2, y1, e3);
637
- let e4 = Fp.isOdd(y);
638
- y = Fp.cmov(y, Fp.neg(y), e3 !== e4);
639
- return {
640
- xMn: xn,
641
- xMd: xd,
642
- yMn: y,
643
- yMd: _1n
644
- };
645
- }
646
- const ELL2_C1_EDWARDS = FpSqrtEven(Fp, Fp.neg(BigInt(486664)));
647
- function map_to_curve_elligator2_edwards25519(u) {
648
- const { xMn, xMd, yMn, yMd } = _map_to_curve_elligator2_curve25519(u);
649
- let xn = Fp.mul(xMn, yMd);
650
- xn = Fp.mul(xn, ELL2_C1_EDWARDS);
651
- let xd = Fp.mul(xMd, yMn);
652
- let yn = Fp.sub(xMn, xMd);
653
- let yd = Fp.add(xMn, xMd);
654
- let tv1 = Fp.mul(xd, yd);
655
- let e = Fp.eql(tv1, Fp.ZERO);
656
- xn = Fp.cmov(xn, Fp.ZERO, e);
657
- xd = Fp.cmov(xd, Fp.ONE, e);
658
- yn = Fp.cmov(yn, Fp.ONE, e);
659
- yd = Fp.cmov(yd, Fp.ONE, e);
660
- const [xd_inv, yd_inv] = FpInvertBatch(Fp, [xd, yd], true);
661
- return {
662
- x: Fp.mul(xn, xd_inv),
663
- y: Fp.mul(yn, yd_inv)
664
- };
665
- }
666
- createHasher(ed25519_Point, (scalars) => map_to_curve_elligator2_edwards25519(scalars[0]), {
667
- DST: "edwards25519_XMD:SHA-512_ELL2_RO_",
668
- encodeDST: "edwards25519_XMD:SHA-512_ELL2_NU_",
669
- p: ed25519_CURVE_p,
670
- m: 1,
671
- k: 128,
672
- expand: "xmd",
673
- hash: sha512
674
- });
675
- const SQRT_M1 = ED25519_SQRT_M1;
676
- const SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");
677
- const INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
678
- const ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
679
- const D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
680
- const invertSqrt = (number) => uvRatio(_1n, number);
681
- const MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
682
- const bytes255ToNumberLE = (bytes) => Fp.create(bytesToNumberLE(bytes) & MAX_255B);
683
- /**
684
- * Computes Elligator map for Ristretto255.
685
- * Primary formula source is RFC 9496 §4.3.4 MAP; RFC 9380 Appendix B builds
686
- * `hash_to_ristretto255` on top of this helper.
687
- * Returns an internal Edwards representative, not a public `_RistrettoPoint`.
688
- */
689
- function calcElligatorRistrettoMap(r0) {
690
- const { d } = ed25519_CURVE;
691
- const P = ed25519_CURVE_p;
692
- const mod = (n) => Fp.create(n);
693
- const r = mod(SQRT_M1 * r0 * r0);
694
- const Ns = mod((r + _1n) * ONE_MINUS_D_SQ);
695
- let c = BigInt(-1);
696
- const D = mod((c - d * r) * mod(r + d));
697
- let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D);
698
- let s_ = mod(s * r0);
699
- if (!isNegativeLE(s_, P)) s_ = mod(-s_);
700
- if (!Ns_D_is_sq) s = s_;
701
- if (!Ns_D_is_sq) c = r;
702
- const Nt = mod(c * (r - _1n) * D_MINUS_ONE_SQ - D);
703
- const s2 = s * s;
704
- const W0 = mod((s + s) * D);
705
- const W1 = mod(Nt * SQRT_AD_MINUS_ONE);
706
- const W2 = mod(_1n - s2);
707
- const W3 = mod(_1n + s2);
708
- return new ed25519_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
709
- }
710
- /**
711
- * Wrapper over Edwards Point for ristretto255.
712
- *
713
- * Each ed25519/EdwardsPoint has 8 different equivalent points. This can be
714
- * a source of bugs for protocols like ring signatures. Ristretto was created to solve this.
715
- * Ristretto point operates in X:Y:Z:T extended coordinates like EdwardsPoint,
716
- * but it should work in its own namespace: do not combine those two.
717
- * See [RFC9496](https://www.rfc-editor.org/rfc/rfc9496).
718
- */
719
- var _RistrettoPoint = class _RistrettoPoint extends PrimeEdwardsPoint {
720
- static BASE = new _RistrettoPoint(ed25519_Point.BASE);
721
- static ZERO = new _RistrettoPoint(ed25519_Point.ZERO);
722
- static Fp = Fp;
723
- static Fn = Fn;
724
- constructor(ep) {
725
- super(ep);
726
- }
727
- /**
728
- * Create one Ristretto255 point from affine Edwards coordinates.
729
- * This wraps the internal Edwards representative directly and is not a
730
- * canonical ristretto255 decoding path.
731
- * Use `toBytes()` / `fromBytes()` if canonical ristretto255 bytes matter.
732
- */
733
- static fromAffine(ap) {
734
- return new _RistrettoPoint(ed25519_Point.fromAffine(ap));
735
- }
736
- assertSame(other) {
737
- if (!(other instanceof _RistrettoPoint)) throw new Error("RistrettoPoint expected");
738
- }
739
- init(ep) {
740
- return new _RistrettoPoint(ep);
741
- }
742
- static fromBytes(bytes) {
743
- abytes$1(bytes, 32);
744
- const { a, d } = ed25519_CURVE;
745
- const P = ed25519_CURVE_p;
746
- const mod = (n) => Fp.create(n);
747
- const s = bytes255ToNumberLE(bytes);
748
- if (!equalBytes$1(Fp.toBytes(s), bytes) || isNegativeLE(s, P)) throw new Error("invalid ristretto255 encoding 1");
749
- const s2 = mod(s * s);
750
- const u1 = mod(_1n + a * s2);
751
- const u2 = mod(_1n - a * s2);
752
- const u1_2 = mod(u1 * u1);
753
- const u2_2 = mod(u2 * u2);
754
- const v = mod(a * d * u1_2 - u2_2);
755
- const { isValid, value: I } = invertSqrt(mod(v * u2_2));
756
- const Dx = mod(I * u2);
757
- const Dy = mod(I * Dx * v);
758
- let x = mod((s + s) * Dx);
759
- if (isNegativeLE(x, P)) x = mod(-x);
760
- const y = mod(u1 * Dy);
761
- const t = mod(x * y);
762
- if (!isValid || isNegativeLE(t, P) || y === _0n) throw new Error("invalid ristretto255 encoding 2");
763
- return new _RistrettoPoint(new ed25519_Point(x, y, _1n, t));
764
- }
765
- /**
766
- * Converts ristretto-encoded string to ristretto point.
767
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
768
- * @param hex - Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
769
- */
770
- static fromHex(hex) {
771
- return _RistrettoPoint.fromBytes(hexToBytes(hex));
772
- }
773
- /**
774
- * Encodes ristretto point to Uint8Array.
775
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
776
- */
777
- toBytes() {
778
- let { X, Y, Z, T } = this.ep;
779
- const P = ed25519_CURVE_p;
780
- const mod = (n) => Fp.create(n);
781
- const u1 = mod(mod(Z + Y) * mod(Z - Y));
782
- const u2 = mod(X * Y);
783
- const { value: invsqrt } = invertSqrt(mod(u1 * mod(u2 * u2)));
784
- const D1 = mod(invsqrt * u1);
785
- const D2 = mod(invsqrt * u2);
786
- const zInv = mod(D1 * D2 * T);
787
- let D;
788
- if (isNegativeLE(T * zInv, P)) {
789
- let _x = mod(Y * SQRT_M1);
790
- let _y = mod(X * SQRT_M1);
791
- X = _x;
792
- Y = _y;
793
- D = mod(D1 * INVSQRT_A_MINUS_D);
794
- } else D = D2;
795
- if (isNegativeLE(X * zInv, P)) Y = mod(-Y);
796
- let s = mod((Z - Y) * D);
797
- if (isNegativeLE(s, P)) s = mod(-s);
798
- return Fp.toBytes(s);
799
- }
800
- /**
801
- * Compares two Ristretto points.
802
- * Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
803
- */
804
- equals(other) {
805
- this.assertSame(other);
806
- const { X: X1, Y: Y1 } = this.ep;
807
- const { X: X2, Y: Y2 } = other.ep;
808
- const mod = (n) => Fp.create(n);
809
- const one = mod(X1 * Y2) === mod(Y1 * X2);
810
- const two = mod(Y1 * Y2) === mod(X1 * X2);
811
- return one || two;
812
- }
813
- is0() {
814
- return this.equals(_RistrettoPoint.ZERO);
815
- }
816
- };
817
- Object.freeze(_RistrettoPoint.BASE);
818
- Object.freeze(_RistrettoPoint.ZERO);
819
- Object.freeze(_RistrettoPoint.prototype);
820
- Object.freeze(_RistrettoPoint);
821
- /**
822
- * Hashing to ristretto255 points / field. RFC 9380 methods.
823
- * `hashToCurve()` is RFC 9380 Appendix B, `deriveToCurve()` is the RFC 9496
824
- * §4.3.4 element-derivation building block, and `hashToScalar()` is a
825
- * library-specific helper for OPRF-style use.
826
- * @example
827
- * Hash one message onto ristretto255.
828
- *
829
- * ```ts
830
- * const point = ristretto255_hasher.hashToCurve(new TextEncoder().encode('hello noble'));
831
- * ```
832
- */
833
- const ristretto255_hasher = Object.freeze({
834
- Point: _RistrettoPoint,
835
- hashToCurve(msg, options) {
836
- const xmd = expand_message_xmd(msg, options?.DST === void 0 ? "ristretto255_XMD:SHA-512_R255MAP_RO_" : options.DST, 64, sha512);
837
- return ristretto255_hasher.deriveToCurve(xmd);
838
- },
839
- hashToScalar(msg, options = { DST: _DST_scalar }) {
840
- const xmd = expand_message_xmd(msg, options.DST, 64, sha512);
841
- return Fn.create(bytesToNumberLE(xmd));
842
- },
843
- deriveToCurve(bytes) {
844
- abytes$1(bytes, 64);
845
- const R1 = calcElligatorRistrettoMap(bytes255ToNumberLE(bytes.subarray(0, 32)));
846
- const R2 = calcElligatorRistrettoMap(bytes255ToNumberLE(bytes.subarray(32, 64)));
847
- return new _RistrettoPoint(R1.add(R2));
848
- }
849
- });
850
- createOPRF({
851
- name: "ristretto255-SHA512",
852
- Point: _RistrettoPoint,
853
- hash: sha512,
854
- hashToGroup: ristretto255_hasher.hashToCurve,
855
- hashToScalar: ristretto255_hasher.hashToScalar
856
- });
857
- createFROST({
858
- name: "FROST-RISTRETTO255-SHA512-v1",
859
- Point: _RistrettoPoint,
860
- validatePoint: (p) => {
861
- p.assertValidity();
862
- },
863
- hash: sha512
864
- });
865
- /**
866
- * The most inbox entries one open-inbox request carries, held by the
867
- * client that batches and the signer that answers alike: a busy inbox is
868
- * opened over several requests, so no single request holds the signer
869
- * decrypting without bound.
870
- */
871
- const MAX_INBOX_ENTRIES_PER_REQUEST = 4096;
872
- const ENTRY_VERSION = 1;
873
- const ENTRY_SUITE = 1;
874
- const EPHEMERAL_KEY_OFFSET$1 = 2;
875
- const NONCE_OFFSET$1 = 34;
876
- const TAG_OFFSET$1 = 46;
877
- const CIPHERTEXT_OFFSET$1 = 62;
878
- const NONCE_LENGTH$2 = 12;
879
- const TAG_LENGTH$2 = 16;
880
- const KEY_LENGTH$2 = 32;
881
- const COIN_NONCE_LENGTH = 32;
882
- const COLOR_LENGTH = 32;
883
- const VALUE_LENGTH = 16;
884
- const PLAINTEXT_LENGTH = COIN_NONCE_LENGTH + COLOR_LENGTH + VALUE_LENGTH;
885
- const AEAD_TAG_BITS$2 = TAG_LENGTH$2 * 8;
886
- const VALUE_MAX = (1n << BigInt(VALUE_LENGTH * 8)) - 1n;
887
- const BYTE_BITS$1 = 8n;
888
- const BYTE_MASK$1 = 255n;
889
- const WRAPPING_KEY_INFO = new TextEncoder().encode("midnight:custody:inbox:v1");
890
- /**
891
- * The AES-256-GCM key that wraps one entry: HKDF-SHA256 over the X25519
892
- * shared secret with an empty salt and the fixed inbox label, imported
893
- * non-extractable so the key bytes never exist outside the shared secret,
894
- * which is zeroed once the key is derived.
895
- */
896
- const wrappingKey = async (shared) => {
897
- try {
898
- const material = await crypto.subtle.importKey("raw", shared, "HKDF", false, ["deriveKey"]);
899
- return await crypto.subtle.deriveKey({
900
- name: "HKDF",
901
- hash: "SHA-256",
902
- salt: new Uint8Array(0),
903
- info: WRAPPING_KEY_INFO
904
- }, material, {
905
- name: "AES-GCM",
906
- length: KEY_LENGTH$2 * 8
907
- }, false, ["encrypt", "decrypt"]);
908
- } finally {
909
- shared.fill(0);
910
- }
911
- };
912
- const encodeValue = (value) => {
913
- const bytes = new Uint8Array(VALUE_LENGTH);
914
- let remaining = value;
915
- for (let index = VALUE_LENGTH - 1; index >= 0; index -= 1) {
916
- bytes[index] = Number(remaining & BYTE_MASK$1);
917
- remaining >>= BYTE_BITS$1;
918
- }
919
- return bytes;
920
- };
921
- const decodeValue = (bytes) => bytes.reduce((value, byte) => value << BYTE_BITS$1 | BigInt(byte), 0n);
922
- const encodeCoin = ({ nonce, color, value }) => {
923
- if (nonce.length !== COIN_NONCE_LENGTH || color.length !== COLOR_LENGTH) throw new Error(`An inbox coin description needs a ${COIN_NONCE_LENGTH}-byte nonce and a ${COLOR_LENGTH}-byte colour.`);
924
- if (value < 0n || value > VALUE_MAX) throw new Error(`An inbox coin value must fit an unsigned 128-bit integer, got ${value}.`);
925
- const plaintext = new Uint8Array(PLAINTEXT_LENGTH);
926
- plaintext.set(nonce, 0);
927
- plaintext.set(color, COIN_NONCE_LENGTH);
928
- plaintext.set(encodeValue(value), COIN_NONCE_LENGTH + COLOR_LENGTH);
929
- return plaintext;
930
- };
931
- const decodeCoin = (plaintext) => ({
932
- nonce: plaintext.slice(0, COIN_NONCE_LENGTH),
933
- color: plaintext.slice(COIN_NONCE_LENGTH, COIN_NONCE_LENGTH + COLOR_LENGTH),
934
- value: decodeValue(plaintext.slice(COIN_NONCE_LENGTH + COLOR_LENGTH))
935
- });
936
- /**
937
- * Seals a coin description towards an account as an InboxEntry v1: the
938
- * plaintext is the coin nonce, colour and big-endian 128-bit value, wrapped
939
- * under a key agreed between a fresh ephemeral X25519 key and the
940
- * account's `enc_key`, with the version and suite bytes as associated
941
- * data; the trailing padding stays zero. The ephemeral secret is zeroed
942
- * before this returns.
943
- */
944
- const sealInboxEntry = async (encPublicKey, coin) => {
945
- const plaintext = encodeCoin(coin);
946
- const ephemeral = x25519.keygen();
947
- const entry = new Uint8Array(192);
948
- entry[0] = ENTRY_VERSION;
949
- entry[1] = ENTRY_SUITE;
950
- try {
951
- const key = await wrappingKey(x25519.getSharedSecret(ephemeral.secretKey, encPublicKey));
952
- const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH$2));
953
- const sealed = new Uint8Array(await crypto.subtle.encrypt({
954
- name: "AES-GCM",
955
- iv: nonce,
956
- additionalData: entry.slice(0, EPHEMERAL_KEY_OFFSET$1),
957
- tagLength: AEAD_TAG_BITS$2
958
- }, key, plaintext));
959
- entry.set(ephemeral.publicKey, EPHEMERAL_KEY_OFFSET$1);
960
- entry.set(nonce, NONCE_OFFSET$1);
961
- entry.set(sealed.subarray(PLAINTEXT_LENGTH), TAG_OFFSET$1);
962
- entry.set(sealed.subarray(0, PLAINTEXT_LENGTH), CIPHERTEXT_OFFSET$1);
963
- return entry;
964
- } finally {
965
- ephemeral.secretKey.fill(0);
966
- plaintext.fill(0);
967
- }
968
- };
969
- /**
970
- * Opens an InboxEntry v1 with the account encryption secret. Resolves the
971
- * coin the entry describes, or null for an entry the inbox walk must skip
972
- * rather than fail on: one of another length, version or suite, one
973
- * sealed towards another key, or one whose authentication fails. The
974
- * contract accepts any bytes from anyone, so a null is noise, not an
975
- * error.
976
- */
977
- const openInboxEntry = async (encSecret, entry) => {
978
- if (entry.length !== 192 || entry[0] !== ENTRY_VERSION || entry[1] !== ENTRY_SUITE) return null;
979
- try {
980
- const key = await wrappingKey(x25519.getSharedSecret(encSecret, entry.slice(EPHEMERAL_KEY_OFFSET$1, NONCE_OFFSET$1)));
981
- const sealed = new Uint8Array(PLAINTEXT_LENGTH + TAG_LENGTH$2);
982
- sealed.set(entry.slice(CIPHERTEXT_OFFSET$1, CIPHERTEXT_OFFSET$1 + PLAINTEXT_LENGTH), 0);
983
- sealed.set(entry.slice(TAG_OFFSET$1, CIPHERTEXT_OFFSET$1), PLAINTEXT_LENGTH);
984
- const plaintext = new Uint8Array(await crypto.subtle.decrypt({
985
- name: "AES-GCM",
986
- iv: entry.slice(NONCE_OFFSET$1, TAG_OFFSET$1),
987
- additionalData: entry.slice(0, EPHEMERAL_KEY_OFFSET$1),
988
- tagLength: AEAD_TAG_BITS$2
989
- }, key, sealed));
990
- try {
991
- return decodeCoin(plaintext);
992
- } finally {
993
- plaintext.fill(0);
994
- }
995
- } catch {
996
- return null;
997
- }
998
- };
999
- const SEAL_VERSION = 1;
1000
- const SEAL_SUITE = 1;
1001
- const EPHEMERAL_KEY_OFFSET = 2;
1002
- const NONCE_OFFSET = 34;
1003
- const TAG_OFFSET = 46;
1004
- const CIPHERTEXT_OFFSET = 62;
1005
- const NONCE_LENGTH$1 = 12;
1006
- const TAG_LENGTH$1 = 16;
1007
- const KEY_LENGTH$1 = 32;
1008
- const SECRET_LENGTH = 32;
1009
- const AEAD_TAG_BITS$1 = TAG_LENGTH$1 * 8;
1010
- const VIEW_KEY_INFO = new TextEncoder().encode("midnight:account:grant:view:v1");
1011
- const concat$1 = (...parts) => {
1012
- const joined = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
1013
- let offset = 0;
1014
- for (const part of parts) {
1015
- joined.set(part, offset);
1016
- offset += part.length;
1017
- }
1018
- return joined;
1019
- };
1020
- /**
1021
- * The AES-256-GCM key that wraps one seal: HKDF-SHA256 over the X25519
1022
- * shared secret with an empty salt and the view label followed by the
1023
- * grant id, imported non-extractable; the shared secret is zeroed once
1024
- * the key is derived.
1025
- */
1026
- const sealingKey = async (shared, grantId) => {
1027
- try {
1028
- const material = await crypto.subtle.importKey("raw", shared, "HKDF", false, ["deriveKey"]);
1029
- return await crypto.subtle.deriveKey({
1030
- name: "HKDF",
1031
- hash: "SHA-256",
1032
- salt: new Uint8Array(0),
1033
- info: concat$1(VIEW_KEY_INFO, grantId)
1034
- }, material, {
1035
- name: "AES-GCM",
1036
- length: KEY_LENGTH$1 * 8
1037
- }, false, ["encrypt"]);
1038
- } finally {
1039
- shared.fill(0);
1040
- }
1041
- };
1042
- /**
1043
- * Seals an account encryption secret towards a grantee's read key as a
1044
- * GrantViewSeal v1: the secret is wrapped under a key agreed between a
1045
- * fresh ephemeral X25519 key and the read key and derived with the grant
1046
- * id in its label, with the version, suite, ephemeral key, grant id and
1047
- * account as associated data, so the container opens only for that read
1048
- * key, under that grant and for that account. A read key of small order
1049
- * yields an all-zero shared secret, which the key agreement refuses. The
1050
- * ephemeral secret is zeroed before this returns; the account secret is
1051
- * the caller's to zero.
1052
- */
1053
- const sealGrantView = async (encSecret, { grantId, account, readPublicKey }) => {
1054
- if (encSecret.length !== SECRET_LENGTH) throw new Error(`A grant view seals a ${SECRET_LENGTH}-byte secret, got ${encSecret.length} bytes.`);
1055
- const grantIdBytes = ByteArray.fromHex(HexBytes(grantId));
1056
- const accountBytes = ByteArray.fromHex(HexBytes(account));
1057
- const readKey = ByteArray.fromHex(HexBytes(readPublicKey));
1058
- const ephemeral = x25519.keygen();
1059
- const seal = new Uint8Array(94);
1060
- seal[0] = SEAL_VERSION;
1061
- seal[1] = SEAL_SUITE;
1062
- seal.set(ephemeral.publicKey, EPHEMERAL_KEY_OFFSET);
1063
- try {
1064
- const key = await sealingKey(x25519.getSharedSecret(ephemeral.secretKey, readKey), grantIdBytes);
1065
- const nonce = crypto.getRandomValues(new Uint8Array(NONCE_LENGTH$1));
1066
- const sealed = new Uint8Array(await crypto.subtle.encrypt({
1067
- name: "AES-GCM",
1068
- iv: nonce,
1069
- additionalData: concat$1(seal.slice(0, NONCE_OFFSET), grantIdBytes, accountBytes),
1070
- tagLength: AEAD_TAG_BITS$1
1071
- }, key, encSecret));
1072
- seal.set(nonce, NONCE_OFFSET);
1073
- seal.set(sealed.subarray(SECRET_LENGTH), TAG_OFFSET);
1074
- seal.set(sealed.subarray(0, SECRET_LENGTH), CIPHERTEXT_OFFSET);
1075
- return seal;
1076
- } finally {
1077
- ephemeral.secretKey.fill(0);
1078
- }
1079
- };
1080
- //#endregion
1081
- //#region ../../packages/module/passport-account/src/acc/envelopes.ts
1082
- /**
1083
- * The Lace record kinds an Account Custody Contract inbox carries beside
1084
- * the coin entries senders write: device envelopes, which deliver the
1085
- * account secret and the roster key to one device's reader key; device
1086
- * registrations, which name an enrolled device's reader and device keys
1087
- * under the roster key; and grant records, which keep the bookkeeping of
1088
- * a grant this device issued under a key only it derives. Each is one
1089
- * 192-byte entry led by a type byte no custody standard reader knows, so
1090
- * every other reader skips it as noise, and each opens to null rather
1091
- * than an error when it is malformed, tampered with or addressed to
1092
- * someone else, since anyone may append any bytes to the inbox.
1093
- */
1094
- /** Type byte of a device envelope. */
1095
- const DEVICE_ENVELOPE_TYPE = 209;
1096
- /** Type byte of a device registration. */
1097
- const DEVICE_REGISTRATION_TYPE = 210;
1098
- /** Type byte of a grant record. */
1099
- const GRANT_RECORD_TYPE = 211;
1100
- const SUITE = 2;
1101
- const KEY_LENGTH = 32;
1102
- const NONCE_LENGTH = 12;
1103
- const TAG_LENGTH = 16;
1104
- const RECIPIENT_TAG_LENGTH = 32;
1105
- const AEAD_TAG_BITS = TAG_LENGTH * 8;
1106
- const MAX_COIN_VALUE_LENGTH = 16;
1107
- const BYTE_BITS = 8n;
1108
- const BYTE_MASK = 255n;
1109
- const RECIPIENT_TAG_OFFSET = 2;
1110
- const RECIPIENT_TAG_END = RECIPIENT_TAG_OFFSET + RECIPIENT_TAG_LENGTH;
1111
- const ENVELOPE_EPHEMERAL_OFFSET = RECIPIENT_TAG_END;
1112
- const ENVELOPE_NONCE_OFFSET = ENVELOPE_EPHEMERAL_OFFSET + KEY_LENGTH;
1113
- const ENVELOPE_PLAINTEXT_LENGTH = KEY_LENGTH * 2;
1114
- const REGISTRATION_NONCE_OFFSET = 2;
1115
- const REGISTRATION_PLAINTEXT_LENGTH = KEY_LENGTH * 2;
1116
- const RECORD_NONCE_OFFSET = RECIPIENT_TAG_END;
1117
- const RECORD_PLAINTEXT_LENGTH = 192 - (RECORD_NONCE_OFFSET + NONCE_LENGTH + TAG_LENGTH);
1118
- const encoder = new TextEncoder();
1119
- const ENVELOPE_TAG_DOMAIN = encoder.encode("lace:passport:envelope-tag:v2");
1120
- const ENVELOPE_KEY_INFO = encoder.encode("lace:passport:device-envelope:v1");
1121
- const REGISTRATION_KEY_INFO = encoder.encode("lace:passport:device-registration:v1");
1122
- const RECORD_KEY_INFO = encoder.encode("lace:passport:grant-record:v1");
1123
- const RECORD_TAG_KEY_INFO = encoder.encode("lace:passport:grant-record-tag:v1");
1124
- /**
1125
- * The kinds of grant record part, by the byte that leads its plaintext.
1126
- * The jubjub grant, object and view values come first, so the records
1127
- * written before secp256k1 grantees read back unchanged.
1128
- */
1129
- const RECORD_PART_KINDS = [
1130
- {
1131
- part: "grant",
1132
- granteeScheme: "jubjub-schnorr"
1133
- },
1134
- { part: "object" },
1135
- { part: "view" },
1136
- {
1137
- part: "grant",
1138
- granteeScheme: "secp256k1-ecdsa",
1139
- keyPrefix: 2
1140
- },
1141
- {
1142
- part: "grant",
1143
- granteeScheme: "secp256k1-ecdsa",
1144
- keyPrefix: 3
1145
- }
1146
- ];
1147
- /**
1148
- * A Jubjub device public key in the compressed 32-byte form a device
1149
- * registration carries, as lowercase hex: the y coordinate little-endian
1150
- * with the parity of x in its top bit.
1151
- */
1152
- const encodeDevicePublicKey = (point) => HexBytes.fromByteArray(jubjub.Point.fromAffine(point).toBytes());
1153
- /**
1154
- * The affine Jubjub point a compressed device public key names, or
1155
- * undefined for hex that is no point on the curve.
1156
- */
1157
- const decodeDevicePublicKey = (hex) => {
1158
- try {
1159
- return jubjub.Point.fromBytes(ByteArray.fromHex(HexBytes(hex))).toAffine();
1160
- } catch {
1161
- return;
1162
- }
1163
- };
1164
- const concat = (...parts) => {
1165
- const joined = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
1166
- let offset = 0;
1167
- for (const part of parts) {
1168
- joined.set(part, offset);
1169
- offset += part.length;
1170
- }
1171
- return joined;
1172
- };
1173
- const isZero = (bytes) => bytes.every((byte) => byte === 0);
1174
- const equalBytes = (left, right) => left.length === right.length && left.every((byte, index) => byte === right[index]);
1175
- /** Whether an entry is a 192-byte record of the given type and suite. */
1176
- const isRecordOf = (entry, type) => entry.length === 192 && entry[0] === type && entry[1] === SUITE;
1177
- /**
1178
- * Whether an inbox entry is one of the Lace record kinds, which a coin
1179
- * walk passes over rather than counts as noise.
1180
- */
1181
- const isLaceRecord = (entry) => isRecordOf(entry, DEVICE_ENVELOPE_TYPE) || isRecordOf(entry, DEVICE_REGISTRATION_TYPE) || isRecordOf(entry, GRANT_RECORD_TYPE);
1182
- /** Whether an inbox entry is a device registration. */
1183
- const isDeviceRegistration = (entry) => isRecordOf(entry, DEVICE_REGISTRATION_TYPE);
1184
- /**
1185
- * The HMAC-SHA256 key HKDF-SHA256 derives from `material` under `info`
1186
- * with an empty salt, imported non-extractable, so the key bytes never
1187
- * exist outside it.
1188
- */
1189
- const hmacKey = async (material, info) => {
1190
- const key = await crypto.subtle.importKey("raw", material, "HKDF", false, ["deriveKey"]);
1191
- return crypto.subtle.deriveKey({
1192
- name: "HKDF",
1193
- hash: "SHA-256",
1194
- salt: new Uint8Array(0),
1195
- info
1196
- }, key, {
1197
- name: "HMAC",
1198
- hash: "SHA-256",
1199
- length: KEY_LENGTH * 8
1200
- }, false, ["sign"]);
1201
- };
1202
- /**
1203
- * The AES-256-GCM key HKDF-SHA256 derives from `material` under `info`,
1204
- * imported non-extractable, so the key bytes never exist outside it.
1205
- */
1206
- const aeadKey = async (material, info) => {
1207
- const key = await crypto.subtle.importKey("raw", material, "HKDF", false, ["deriveKey"]);
1208
- return crypto.subtle.deriveKey({
1209
- name: "HKDF",
1210
- hash: "SHA-256",
1211
- salt: new Uint8Array(0),
1212
- info
1213
- }, key, {
1214
- name: "AES-GCM",
1215
- length: KEY_LENGTH * 8
1216
- }, false, ["encrypt", "decrypt"]);
1217
- };
1218
- /** A fresh AEAD nonce. */
1219
- const freshNonce = () => crypto.getRandomValues(new Uint8Array(NONCE_LENGTH));
1220
- /**
1221
- * The associated data of an entry: every byte before its AEAD tag, less
1222
- * the recipient tag when it carries one, since that tag is computed over
1223
- * the sealed entry and binds it in turn.
1224
- */
1225
- const associatedData = ({ entry, nonceOffset, isTagged }) => {
1226
- const tagOffset = nonceOffset + NONCE_LENGTH;
1227
- return isTagged ? concat(entry.subarray(0, RECIPIENT_TAG_OFFSET), entry.subarray(RECIPIENT_TAG_END, tagOffset)) : entry.slice(0, tagOffset);
1228
- };
1229
- /**
1230
- * Encrypts `plaintext` into `entry` behind its header: the AEAD tag
1231
- * after the nonce the entry already holds at `nonceOffset`, and the
1232
- * ciphertext after that, with the header as associated data, see
1233
- * {@link associatedData}, so the header must be complete before this
1234
- * runs, its recipient tag aside.
1235
- */
1236
- const sealInto = async ({ key, entry, nonceOffset, isTagged, plaintext }) => {
1237
- const nonce = entry.slice(nonceOffset, nonceOffset + NONCE_LENGTH);
1238
- const tagOffset = nonceOffset + NONCE_LENGTH;
1239
- const sealed = new Uint8Array(await crypto.subtle.encrypt({
1240
- name: "AES-GCM",
1241
- iv: nonce,
1242
- additionalData: associatedData({
1243
- entry,
1244
- nonceOffset,
1245
- isTagged
1246
- }),
1247
- tagLength: AEAD_TAG_BITS
1248
- }, key, plaintext));
1249
- entry.set(sealed.subarray(plaintext.length), tagOffset);
1250
- entry.set(sealed.subarray(0, plaintext.length), tagOffset + TAG_LENGTH);
1251
- };
1252
- /**
1253
- * Decrypts the ciphertext behind an entry's header, or null when the
1254
- * authentication fails or the padding after the ciphertext is not zero.
1255
- */
1256
- const openFrom = async ({ key, entry, nonceOffset, isTagged, plaintextLength }) => {
1257
- const tagOffset = nonceOffset + NONCE_LENGTH;
1258
- const ciphertextOffset = tagOffset + TAG_LENGTH;
1259
- if (!isZero(entry.subarray(ciphertextOffset + plaintextLength))) return null;
1260
- try {
1261
- return new Uint8Array(await crypto.subtle.decrypt({
1262
- name: "AES-GCM",
1263
- iv: entry.slice(nonceOffset, tagOffset),
1264
- additionalData: associatedData({
1265
- entry,
1266
- nonceOffset,
1267
- isTagged
1268
- }),
1269
- tagLength: AEAD_TAG_BITS
1270
- }, key, concat(entry.subarray(ciphertextOffset, ciphertextOffset + plaintextLength), entry.subarray(tagOffset, ciphertextOffset))));
1271
- } catch {
1272
- return null;
1273
- }
1274
- };
1275
- /**
1276
- * The recipient tag of a device envelope: SHA-256 over the tag domain,
1277
- * the type and suite bytes, the reader public key and every byte after
1278
- * the tag, the ephemeral key, the nonce, the AEAD tag, the ciphertext
1279
- * and the padding. A reader finds its envelopes by recomputing it, so
1280
- * an entry that copies a genuine envelope's tag with any other byte
1281
- * changed is not taken for one, and writing an entry that is takes the
1282
- * reader public key. Two envelopes to the same reader share nothing on
1283
- * chain, since each carries its own ephemeral key.
1284
- */
1285
- const envelopeTag = (readerPublicKey, entry) => sha256(concat(ENVELOPE_TAG_DOMAIN, entry.subarray(0, RECIPIENT_TAG_OFFSET), readerPublicKey, entry.subarray(RECIPIENT_TAG_END)));
1286
- /** Whether an entry is a device envelope addressed to this reader public key. */
1287
- const isAddressedTo = (entry, readerPublicKey) => isRecordOf(entry, DEVICE_ENVELOPE_TYPE) && equalBytes(entry.subarray(RECIPIENT_TAG_OFFSET, RECIPIENT_TAG_END), envelopeTag(readerPublicKey, entry));
1288
- /**
1289
- * Every envelope in an inbox addressed to this device, newest first: the
1290
- * ones a keyring carries. Anyone who knows a reader key can append
1291
- * envelopes tagged for it, so none is left out, and the live one is
1292
- * found however many land after it, at the cost of opening each.
1293
- */
1294
- const deviceEnvelopes = (entries, readerPublicKey) => entries.filter((entry) => isAddressedTo(entry, readerPublicKey)).reverse();
1295
- /**
1296
- * The AES-256-GCM key of one envelope: HKDF-SHA256 over the X25519 shared
1297
- * secret, zeroed once the key is derived.
1298
- */
1299
- const envelopeKey = async (shared) => {
1300
- try {
1301
- return await aeadKey(shared, ENVELOPE_KEY_INFO);
1302
- } finally {
1303
- shared.fill(0);
1304
- }
1305
- };
1306
- /**
1307
- * Seals the account secret and the roster key to one device's reader key
1308
- * as a device envelope: [0] type, [1] suite, [2..34) recipient tag,
1309
- * [34..66) ephemeral X25519 public key, [66..78) nonce, [78..94) AEAD
1310
- * tag, [94..158) the secret then the roster key, encrypted, and zero
1311
- * padding to 192 bytes. The key is agreed between a fresh ephemeral key
1312
- * and the reader key, everything before the AEAD tag but the recipient
1313
- * tag is associated data, and the recipient tag, computed last, covers
1314
- * the whole sealed envelope. The envelope carries no round or
1315
- * `enc_key`: a reader trusts the secret only once it derives the
1316
- * `enc_key` the ledger holds. The ephemeral secret is zeroed before this
1317
- * returns.
1318
- */
1319
- const sealDeviceEnvelope = async (readerPublicKey, { secret, rosterKey }) => {
1320
- const ephemeral = x25519.keygen();
1321
- const plaintext = concat(secret, rosterKey);
1322
- const entry = new Uint8Array(192);
1323
- entry[0] = DEVICE_ENVELOPE_TYPE;
1324
- entry[1] = SUITE;
1325
- entry.set(ephemeral.publicKey, ENVELOPE_EPHEMERAL_OFFSET);
1326
- entry.set(freshNonce(), ENVELOPE_NONCE_OFFSET);
1327
- try {
1328
- await sealInto({
1329
- key: await envelopeKey(x25519.getSharedSecret(ephemeral.secretKey, readerPublicKey)),
1330
- entry,
1331
- nonceOffset: ENVELOPE_NONCE_OFFSET,
1332
- isTagged: true,
1333
- plaintext
1334
- });
1335
- entry.set(envelopeTag(readerPublicKey, entry), RECIPIENT_TAG_OFFSET);
1336
- return entry;
1337
- } finally {
1338
- ephemeral.secretKey.fill(0);
1339
- plaintext.fill(0);
1340
- }
1341
- };
1342
- /**
1343
- * Opens a device envelope with this device's reader secret. Resolves the
1344
- * account secret and roster key it delivers, which the caller zeroes once
1345
- * used, or null for an entry that is not an envelope, is addressed to
1346
- * another reader or fails to authenticate.
1347
- */
1348
- const openDeviceEnvelope = async (readerSecret, entry) => {
1349
- if (!isAddressedTo(entry, x25519.getPublicKey(readerSecret))) return null;
1350
- let key;
1351
- try {
1352
- key = await envelopeKey(x25519.getSharedSecret(readerSecret, entry.slice(ENVELOPE_EPHEMERAL_OFFSET, ENVELOPE_NONCE_OFFSET)));
1353
- } catch {
1354
- return null;
1355
- }
1356
- const plaintext = await openFrom({
1357
- key,
1358
- entry,
1359
- nonceOffset: ENVELOPE_NONCE_OFFSET,
1360
- isTagged: true,
1361
- plaintextLength: ENVELOPE_PLAINTEXT_LENGTH
1362
- });
1363
- if (!plaintext) return null;
1364
- try {
1365
- return {
1366
- secret: plaintext.slice(0, KEY_LENGTH),
1367
- rosterKey: plaintext.slice(KEY_LENGTH)
1368
- };
1369
- } finally {
1370
- plaintext.fill(0);
1371
- }
1372
- };
1373
- /**
1374
- * Seals one enrolled device's reader and device keys under the roster key
1375
- * as a device registration: [0] type, [1] suite, [2..14) nonce, [14..30)
1376
- * AEAD tag, [30..94) the reader key then the device key, encrypted, and
1377
- * zero padding to 192 bytes. Only a holder of the roster key, an enrolled
1378
- * device, can write one that opens, and nothing on chain tells whose it
1379
- * is.
1380
- */
1381
- const sealDeviceRegistration = async (rosterKey, { readerPublicKey, devicePublicKey }) => {
1382
- const entry = new Uint8Array(192);
1383
- entry[0] = DEVICE_REGISTRATION_TYPE;
1384
- entry[1] = SUITE;
1385
- entry.set(freshNonce(), REGISTRATION_NONCE_OFFSET);
1386
- await sealInto({
1387
- key: await aeadKey(rosterKey, REGISTRATION_KEY_INFO),
1388
- entry,
1389
- nonceOffset: REGISTRATION_NONCE_OFFSET,
1390
- isTagged: false,
1391
- plaintext: concat(ByteArray.fromHex(HexBytes(readerPublicKey)), ByteArray.fromHex(HexBytes(devicePublicKey)))
1392
- });
1393
- return entry;
1394
- };
1395
- /**
1396
- * Opens a device registration with the roster key: the device it names,
1397
- * or null for an entry that is not a registration or was written under
1398
- * another roster key.
1399
- */
1400
- const openDeviceRegistration = async (rosterKey, entry) => {
1401
- if (!isRecordOf(entry, DEVICE_REGISTRATION_TYPE)) return null;
1402
- const plaintext = await openFrom({
1403
- key: await aeadKey(rosterKey, REGISTRATION_KEY_INFO),
1404
- entry,
1405
- nonceOffset: REGISTRATION_NONCE_OFFSET,
1406
- isTagged: false,
1407
- plaintextLength: REGISTRATION_PLAINTEXT_LENGTH
1408
- });
1409
- return plaintext && {
1410
- readerPublicKey: HexBytes.fromByteArray(plaintext.slice(0, KEY_LENGTH)),
1411
- devicePublicKey: HexBytes.fromByteArray(plaintext.slice(KEY_LENGTH))
1412
- };
1413
- };
1414
- /**
1415
- * The keys of this device's grant records on one account, both derived
1416
- * from its reader secret with the account address in the label: the
1417
- * AES-256-GCM key and the key its recipient tags are computed under, so
1418
- * only this device writes a record that opens or recognises one as its
1419
- * own, and a record copied from another account is neither.
1420
- */
1421
- const recordKeys = async (readerSecret, account) => {
1422
- const accountBytes = ByteArray.fromHex(HexBytes(account));
1423
- return {
1424
- key: await aeadKey(readerSecret, concat(RECORD_KEY_INFO, accountBytes)),
1425
- tagKey: await hmacKey(readerSecret, concat(RECORD_TAG_KEY_INFO, accountBytes))
1426
- };
1427
- };
1428
- /**
1429
- * The recipient tag of a grant record: HMAC-SHA256 under the tag key
1430
- * over the type and suite bytes and every byte after the tag, the
1431
- * nonce, the AEAD tag and the ciphertext, so a copied tag with any other
1432
- * byte changed is not taken for this device's.
1433
- */
1434
- const recordTag = async (tagKey, entry) => new Uint8Array(await crypto.subtle.sign("HMAC", tagKey, concat(entry.subarray(0, RECIPIENT_TAG_OFFSET), entry.subarray(RECIPIENT_TAG_END))));
1435
- const encodeAmount = (value) => {
1436
- const bytes = new Uint8Array(MAX_COIN_VALUE_LENGTH);
1437
- let remaining = BigInt(value);
1438
- for (let index = MAX_COIN_VALUE_LENGTH - 1; index >= 0; index -= 1) {
1439
- bytes[index] = Number(remaining & BYTE_MASK);
1440
- remaining >>= BYTE_BITS;
1441
- }
1442
- return bytes;
1443
- };
1444
- const decodeAmount = (bytes) => bytes.reduce((value, byte) => value << BYTE_BITS | BigInt(byte), 0n).toString();
1445
- const hexBytes = (hex) => ByteArray.fromHex(HexBytes(hex));
1446
- const encodeRecipient = (recipient) => concat(Uint8Array.of(Number(RECIPIENT_KINDS[recipient.kind])), recipient.kind === "any" ? new Uint8Array(KEY_LENGTH) : hexBytes(recipient.value));
1447
- const RECIPIENT_BY_KIND = new Map(Object.entries(RECIPIENT_KINDS).map(([kind, value]) => [Number(value), kind]));
1448
- const decodeRecipient = (bytes) => {
1449
- const kind = RECIPIENT_BY_KIND.get(bytes[0]);
1450
- const value = bytes.subarray(1);
1451
- if (kind === void 0) return null;
1452
- if (kind === "any") return isZero(value) ? { kind } : null;
1453
- return {
1454
- kind,
1455
- value: HexBytes.fromByteArray(value)
1456
- };
1457
- };
1458
- /** The part byte of an object or a view part, which take one value each. */
1459
- const partByteOf = (part) => RECORD_PART_KINDS.findIndex((kind) => kind.part === part);
1460
- /**
1461
- * The grantee field of a grant part and the part byte that names how it
1462
- * reads back, see {@link RecordPartKind}.
1463
- *
1464
- * @throws Error when the key is not in a form the record holds: a 32-byte
1465
- * jubjub key, or a 33-byte compressed secp256k1 key prefixed 02 or 03.
1466
- */
1467
- const encodeGrantee = (part) => {
1468
- const key = hexBytes(part.granteePublicKey);
1469
- const keyPrefix = part.granteeScheme === "secp256k1-ecdsa" ? key[0] : void 0;
1470
- const field = keyPrefix === void 0 ? key : key.subarray(1);
1471
- const partByte = RECORD_PART_KINDS.findIndex((kind) => kind.part === "grant" && kind.granteeScheme === part.granteeScheme && kind.keyPrefix === keyPrefix);
1472
- if (partByte < 0 || field.length !== KEY_LENGTH) throw new Error(`Grant record cannot carry this '${part.granteeScheme}' grantee key`);
1473
- return {
1474
- partByte,
1475
- field
1476
- };
1477
- };
1478
- /**
1479
- * The plaintext of one grant record part, 130 bytes: the part byte and
1480
- * the grant id, then for a grant the slot, the scope salt, the grantee
1481
- * field and the read key (zero for none); for an object the colour, the
1482
- * recipient kind and value, and the coin bound as a big-endian 128-bit
1483
- * integer; for a view the leading bytes of `enc_key` and the 94-byte
1484
- * seal; zero padding after. The part byte of a grant also names the form
1485
- * of its grantee key, see {@link RecordPartKind}, and a grant part whose
1486
- * grantee the format cannot hold is refused before anything is written.
1487
- */
1488
- const encodeRecordPart = (part) => {
1489
- const plaintext = new Uint8Array(RECORD_PLAINTEXT_LENGTH);
1490
- plaintext.set(hexBytes(part.grantId), 1);
1491
- const body = 1 + KEY_LENGTH;
1492
- switch (part.part) {
1493
- case "grant": {
1494
- const { partByte, field } = encodeGrantee(part);
1495
- plaintext[0] = partByte;
1496
- plaintext[body] = part.slot;
1497
- plaintext.set(hexBytes(part.scopeSalt), body + 1);
1498
- plaintext.set(field, body + 1 + KEY_LENGTH);
1499
- if (part.readPublicKey !== void 0) plaintext.set(hexBytes(part.readPublicKey), body + 1 + KEY_LENGTH * 2);
1500
- return plaintext;
1501
- }
1502
- case "object":
1503
- plaintext[0] = partByteOf(part.part);
1504
- plaintext.set(hexBytes(part.object.color), body);
1505
- plaintext.set(encodeRecipient(part.object.recipient), body + KEY_LENGTH);
1506
- plaintext.set(encodeAmount(part.object.maxCoinValue), body + KEY_LENGTH * 2 + 1);
1507
- return plaintext;
1508
- case "view":
1509
- plaintext[0] = partByteOf(part.part);
1510
- plaintext.set(hexBytes(part.encKeyPrefix), body);
1511
- plaintext.set(hexBytes(part.seal), body + 3);
1512
- return plaintext;
1513
- }
1514
- };
1515
- const decodeObject = (body) => {
1516
- const recipient = decodeRecipient(body.subarray(KEY_LENGTH, KEY_LENGTH * 2 + 1));
1517
- const amountOffset = KEY_LENGTH * 2 + 1;
1518
- if (!recipient || !isZero(body.subarray(amountOffset + MAX_COIN_VALUE_LENGTH))) return null;
1519
- return {
1520
- color: HexBytes.fromByteArray(body.subarray(0, KEY_LENGTH)),
1521
- recipient,
1522
- maxCoinValue: decodeAmount(body.subarray(amountOffset, amountOffset + MAX_COIN_VALUE_LENGTH))
1523
- };
1524
- };
1525
- /** Reads a grant record part back, or null for a plaintext no writer produces. */
1526
- const decodeRecordPart = (plaintext) => {
1527
- const kind = RECORD_PART_KINDS.at(plaintext[0]);
1528
- if (!kind) return null;
1529
- const grantId = GrantId(HexBytes.fromByteArray(plaintext.slice(1, 33)));
1530
- const body = plaintext.subarray(1 + KEY_LENGTH);
1531
- switch (kind.part) {
1532
- case "grant": {
1533
- const field = body.subarray(1 + KEY_LENGTH, 1 + KEY_LENGTH * 2);
1534
- const readKey = body.subarray(1 + KEY_LENGTH * 2);
1535
- return {
1536
- part: kind.part,
1537
- grantId,
1538
- slot: GrantSlot(body[0]),
1539
- scopeSalt: GrantScopeSalt(HexBytes.fromByteArray(body.subarray(1, 1 + KEY_LENGTH))),
1540
- granteeScheme: kind.granteeScheme,
1541
- granteePublicKey: HexBytes.fromByteArray(kind.keyPrefix === void 0 ? field : concat(Uint8Array.of(kind.keyPrefix), field)),
1542
- ...isZero(readKey) ? {} : { readPublicKey: HexBytes.fromByteArray(readKey) }
1543
- };
1544
- }
1545
- case "object": {
1546
- const object = decodeObject(body);
1547
- return object && {
1548
- part: kind.part,
1549
- grantId,
1550
- object
1551
- };
1552
- }
1553
- case "view": return {
1554
- part: kind.part,
1555
- grantId,
1556
- encKeyPrefix: HexBytes.fromByteArray(body.subarray(0, 3)),
1557
- seal: HexBytes.fromByteArray(body.subarray(3, 97))
1558
- };
1559
- }
1560
- };
1561
- /**
1562
- * Seals one part of a grant's bookkeeping for this device alone as a
1563
- * grant record: [0] type, [1] suite, [2..34) recipient tag, [34..46)
1564
- * nonce, [46..62) AEAD tag, [62..192) the 130-byte part, encrypted, with
1565
- * everything before the AEAD tag but the recipient tag as associated
1566
- * data. The key and the tag key are derived from this device's reader
1567
- * secret and the account, so only this device writes a record that opens
1568
- * and recognises its own on that account, and the tag, computed last
1569
- * over the whole sealed record and its fresh nonce, links no two
1570
- * records.
1571
- */
1572
- const sealGrantRecord = async (readerSecret, account, part) => {
1573
- const { key, tagKey } = await recordKeys(readerSecret, account);
1574
- const plaintext = encodeRecordPart(part);
1575
- const entry = new Uint8Array(192);
1576
- entry[0] = GRANT_RECORD_TYPE;
1577
- entry[1] = SUITE;
1578
- entry.set(freshNonce(), RECORD_NONCE_OFFSET);
1579
- try {
1580
- await sealInto({
1581
- key,
1582
- entry,
1583
- nonceOffset: RECORD_NONCE_OFFSET,
1584
- isTagged: true,
1585
- plaintext
1586
- });
1587
- entry.set(await recordTag(tagKey, entry), RECIPIENT_TAG_OFFSET);
1588
- return entry;
1589
- } finally {
1590
- plaintext.fill(0);
1591
- }
1592
- };
1593
- /**
1594
- * Opens a grant record of one account with this device's reader secret:
1595
- * the part it holds, or null for an entry that is not a grant record,
1596
- * carries another device's or another account's tag, fails to
1597
- * authenticate or decodes to no part.
1598
- */
1599
- const openGrantRecord = async (readerSecret, account, entry) => {
1600
- if (!isRecordOf(entry, GRANT_RECORD_TYPE)) return null;
1601
- const { key, tagKey } = await recordKeys(readerSecret, account);
1602
- if (!equalBytes(await recordTag(tagKey, entry), entry.subarray(RECIPIENT_TAG_OFFSET, RECIPIENT_TAG_END))) return null;
1603
- const plaintext = await openFrom({
1604
- key,
1605
- entry,
1606
- nonceOffset: RECORD_NONCE_OFFSET,
1607
- isTagged: true,
1608
- plaintextLength: RECORD_PLAINTEXT_LENGTH
1609
- });
1610
- if (!plaintext) return null;
1611
- try {
1612
- return decodeRecordPart(plaintext);
1613
- } catch {
1614
- return null;
1615
- } finally {
1616
- plaintext.fill(0);
1617
- }
1618
- };
1619
- //#endregion
1620
- export { x25519 as _, isDeviceRegistration as a, openDeviceRegistration as c, sealDeviceRegistration as d, sealGrantRecord as f, sealInboxEntry as g, openInboxEntry as h, isAddressedTo as i, openGrantRecord as l, MAX_INBOX_ENTRIES_PER_REQUEST as m, deviceEnvelopes as n, isLaceRecord as o, sealGrantView as p, encodeDevicePublicKey as r, openDeviceEnvelope as s, decodeDevicePublicKey as t, sealDeviceEnvelope as u };