zerc20-client-sdk 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +261 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -1
- package/dist/decider/__tests__/prover.test.d.ts +2 -0
- package/dist/decider/__tests__/prover.test.d.ts.map +1 -0
- package/dist/decider/__tests__/prover.test.js +246 -0
- package/dist/decider/__tests__/prover.test.js.map +1 -0
- package/dist/decider/prover.d.ts +36 -4
- package/dist/decider/prover.d.ts.map +1 -1
- package/dist/decider/prover.js +48 -38
- package/dist/decider/prover.js.map +1 -1
- package/dist/ic/__tests__/candid.test.d.ts +2 -0
- package/dist/ic/__tests__/candid.test.d.ts.map +1 -0
- package/dist/ic/__tests__/candid.test.js +44 -0
- package/dist/ic/__tests__/candid.test.js.map +1 -0
- package/dist/ic/__tests__/client.test.d.ts +2 -0
- package/dist/ic/__tests__/client.test.d.ts.map +1 -0
- package/dist/ic/__tests__/client.test.js +522 -0
- package/dist/ic/__tests__/client.test.js.map +1 -0
- package/dist/ic/__tests__/config.test.d.ts +2 -0
- package/dist/ic/__tests__/config.test.d.ts.map +1 -0
- package/dist/ic/__tests__/config.test.js +72 -0
- package/dist/ic/__tests__/config.test.js.map +1 -0
- package/dist/ic/__tests__/connections.test.d.ts +2 -0
- package/dist/ic/__tests__/connections.test.d.ts.map +1 -0
- package/dist/ic/__tests__/connections.test.js +385 -0
- package/dist/ic/__tests__/connections.test.js.map +1 -0
- package/dist/ic/__tests__/invoice.test.d.ts +2 -0
- package/dist/ic/__tests__/invoice.test.d.ts.map +1 -0
- package/dist/ic/__tests__/invoice.test.js +95 -0
- package/dist/ic/__tests__/invoice.test.js.map +1 -0
- package/dist/ic/authorization.d.ts +28 -0
- package/dist/ic/authorization.d.ts.map +1 -1
- package/dist/ic/authorization.js +24 -0
- package/dist/ic/authorization.js.map +1 -1
- package/dist/ic/candid.d.ts +72 -0
- package/dist/ic/candid.d.ts.map +1 -0
- package/dist/ic/candid.js +35 -0
- package/dist/ic/candid.js.map +1 -0
- package/dist/ic/client.d.ts +57 -59
- package/dist/ic/client.d.ts.map +1 -1
- package/dist/ic/client.js +59 -81
- package/dist/ic/client.js.map +1 -1
- package/dist/ic/config.d.ts +27 -0
- package/dist/ic/config.d.ts.map +1 -1
- package/dist/ic/config.js +27 -0
- package/dist/ic/config.js.map +1 -1
- package/dist/ic/connections.d.ts +99 -4
- package/dist/ic/connections.d.ts.map +1 -1
- package/dist/ic/connections.js +222 -30
- package/dist/ic/connections.js.map +1 -1
- package/dist/ic/encryption.d.ts +33 -0
- package/dist/ic/encryption.d.ts.map +1 -1
- package/dist/ic/encryption.js +21 -0
- package/dist/ic/encryption.js.map +1 -1
- package/dist/ic/errors.d.ts +15 -0
- package/dist/ic/errors.d.ts.map +1 -1
- package/dist/ic/errors.js +15 -0
- package/dist/ic/errors.js.map +1 -1
- package/dist/ic/idl.d.ts +26 -0
- package/dist/ic/idl.d.ts.map +1 -0
- package/dist/ic/idl.js +84 -0
- package/dist/ic/idl.js.map +1 -0
- package/dist/ic/index.d.ts +1 -1
- package/dist/ic/index.d.ts.map +1 -1
- package/dist/ic/index.js +1 -1
- package/dist/ic/index.js.map +1 -1
- package/dist/ic/invoice.d.ts.map +1 -1
- package/dist/ic/invoice.js.map +1 -1
- package/dist/ic/types.d.ts +42 -0
- package/dist/ic/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/onchain/__tests__/contracts.test.d.ts +2 -0
- package/dist/onchain/__tests__/contracts.test.d.ts.map +1 -0
- package/dist/onchain/__tests__/contracts.test.js +42 -0
- package/dist/onchain/__tests__/contracts.test.js.map +1 -0
- package/dist/onchain/contracts.d.ts +22 -0
- package/dist/onchain/contracts.d.ts.map +1 -1
- package/dist/onchain/contracts.js +22 -0
- package/dist/onchain/contracts.js.map +1 -1
- package/dist/operations/__tests__/invoice.test.d.ts +2 -0
- package/dist/operations/__tests__/invoice.test.d.ts.map +1 -0
- package/dist/operations/__tests__/invoice.test.js +261 -0
- package/dist/operations/__tests__/invoice.test.js.map +1 -0
- package/dist/operations/__tests__/privateSend.test.d.ts +2 -0
- package/dist/operations/__tests__/privateSend.test.d.ts.map +1 -0
- package/dist/operations/__tests__/privateSend.test.js +135 -0
- package/dist/operations/__tests__/privateSend.test.js.map +1 -0
- package/dist/operations/__tests__/reexports.test.d.ts +2 -0
- package/dist/operations/__tests__/reexports.test.d.ts.map +1 -0
- package/dist/operations/__tests__/reexports.test.js +22 -0
- package/dist/operations/__tests__/reexports.test.js.map +1 -0
- package/dist/operations/__tests__/scanner.test.d.ts +2 -0
- package/dist/operations/__tests__/scanner.test.d.ts.map +1 -0
- package/dist/operations/__tests__/scanner.test.js +201 -0
- package/dist/operations/__tests__/scanner.test.js.map +1 -0
- package/dist/operations/__tests__/teleport.test.d.ts +2 -0
- package/dist/operations/__tests__/teleport.test.d.ts.map +1 -0
- package/dist/operations/__tests__/teleport.test.js +35 -0
- package/dist/operations/__tests__/teleport.test.js.map +1 -0
- package/dist/operations/__tests__/teleportProof.test.d.ts +2 -0
- package/dist/operations/__tests__/teleportProof.test.d.ts.map +1 -0
- package/dist/operations/__tests__/teleportProof.test.js +126 -0
- package/dist/operations/__tests__/teleportProof.test.js.map +1 -0
- package/dist/operations/invoice.d.ts +44 -0
- package/dist/operations/invoice.d.ts.map +1 -1
- package/dist/operations/invoice.js +30 -0
- package/dist/operations/invoice.js.map +1 -1
- package/dist/operations/liquidityManager/__tests__/balance.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/balance.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/balance.test.js +104 -0
- package/dist/operations/liquidityManager/__tests__/balance.test.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.js +198 -0
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/helpers.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/helpers.test.js +126 -0
- package/dist/operations/liquidityManager/__tests__/helpers.test.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/unwrap.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/unwrap.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/unwrap.test.js +224 -0
- package/dist/operations/liquidityManager/__tests__/unwrap.test.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/wrap.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/wrap.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/wrap.test.js +144 -0
- package/dist/operations/liquidityManager/__tests__/wrap.test.js.map +1 -0
- package/dist/operations/liquidityManager/balance.d.ts +19 -0
- package/dist/operations/liquidityManager/balance.d.ts.map +1 -0
- package/dist/operations/liquidityManager/balance.js +62 -0
- package/dist/operations/liquidityManager/balance.js.map +1 -0
- package/dist/operations/liquidityManager/crossUnwrap.d.ts +73 -0
- package/dist/operations/liquidityManager/crossUnwrap.d.ts.map +1 -0
- package/dist/operations/liquidityManager/crossUnwrap.js +189 -0
- package/dist/operations/liquidityManager/crossUnwrap.js.map +1 -0
- package/dist/operations/liquidityManager/helpers.d.ts +15521 -0
- package/dist/operations/liquidityManager/helpers.d.ts.map +1 -0
- package/dist/operations/liquidityManager/helpers.js +81 -0
- package/dist/operations/liquidityManager/helpers.js.map +1 -0
- package/dist/operations/liquidityManager/index.d.ts +12 -0
- package/dist/operations/liquidityManager/index.d.ts.map +1 -0
- package/dist/operations/liquidityManager/index.js +9 -0
- package/dist/operations/liquidityManager/index.js.map +1 -0
- package/dist/operations/liquidityManager/types.d.ts +90 -0
- package/dist/operations/liquidityManager/types.d.ts.map +1 -0
- package/dist/operations/liquidityManager/types.js +5 -0
- package/dist/operations/liquidityManager/types.js.map +1 -0
- package/dist/operations/liquidityManager/unwrap.d.ts +54 -0
- package/dist/operations/liquidityManager/unwrap.d.ts.map +1 -0
- package/dist/operations/liquidityManager/unwrap.js +80 -0
- package/dist/operations/liquidityManager/unwrap.js.map +1 -0
- package/dist/operations/liquidityManager/wrap.d.ts +38 -0
- package/dist/operations/liquidityManager/wrap.d.ts.map +1 -0
- package/dist/operations/liquidityManager/wrap.js +53 -0
- package/dist/operations/liquidityManager/wrap.js.map +1 -0
- package/dist/operations/liquidityManager.d.ts +3 -104
- package/dist/operations/liquidityManager.d.ts.map +1 -1
- package/dist/operations/liquidityManager.js +3 -343
- package/dist/operations/liquidityManager.js.map +1 -1
- package/dist/operations/privateSend.d.ts +26 -0
- package/dist/operations/privateSend.d.ts.map +1 -1
- package/dist/operations/privateSend.js +11 -0
- package/dist/operations/privateSend.js.map +1 -1
- package/dist/operations/receive/__tests__/announcementStatus.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/announcementStatus.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/announcementStatus.test.js +223 -0
- package/dist/operations/receive/__tests__/announcementStatus.test.js.map +1 -0
- package/dist/operations/receive/__tests__/cache.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/cache.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/cache.test.js +339 -0
- package/dist/operations/receive/__tests__/cache.test.js.map +1 -0
- package/dist/operations/receive/__tests__/helpers.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/helpers.test.js +80 -0
- package/dist/operations/receive/__tests__/helpers.test.js.map +1 -0
- package/dist/operations/receive/__tests__/redeemContext.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/redeemContext.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/redeemContext.test.js +230 -0
- package/dist/operations/receive/__tests__/redeemContext.test.js.map +1 -0
- package/dist/operations/receive/announcementStatus.d.ts +12 -0
- package/dist/operations/receive/announcementStatus.d.ts.map +1 -0
- package/dist/operations/receive/announcementStatus.js +56 -0
- package/dist/operations/receive/announcementStatus.js.map +1 -0
- package/dist/operations/receive/cache.d.ts +69 -0
- package/dist/operations/receive/cache.d.ts.map +1 -0
- package/dist/operations/receive/cache.js +105 -0
- package/dist/operations/receive/cache.js.map +1 -0
- package/dist/operations/receive/helpers.d.ts +16 -0
- package/dist/operations/receive/helpers.d.ts.map +1 -0
- package/dist/operations/receive/helpers.js +33 -0
- package/dist/operations/receive/helpers.js.map +1 -0
- package/dist/operations/receive/index.d.ts +9 -0
- package/dist/operations/receive/index.d.ts.map +1 -0
- package/dist/operations/receive/index.js +9 -0
- package/dist/operations/receive/index.js.map +1 -0
- package/dist/operations/receive/redeemContext.d.ts +16 -0
- package/dist/operations/receive/redeemContext.d.ts.map +1 -0
- package/dist/operations/receive/redeemContext.js +107 -0
- package/dist/operations/receive/redeemContext.js.map +1 -0
- package/dist/operations/receive/types.d.ts +141 -0
- package/dist/operations/receive/types.d.ts.map +1 -0
- package/dist/operations/receive/types.js +5 -0
- package/dist/operations/receive/types.js.map +1 -0
- package/dist/operations/receive.d.ts +5 -66
- package/dist/operations/receive.d.ts.map +1 -1
- package/dist/operations/receive.js +5 -173
- package/dist/operations/receive.js.map +1 -1
- package/dist/operations/scanner.d.ts +37 -0
- package/dist/operations/scanner.d.ts.map +1 -1
- package/dist/operations/scanner.js +21 -0
- package/dist/operations/scanner.js.map +1 -1
- package/dist/operations/teleport.d.ts +5 -0
- package/dist/operations/teleport.d.ts.map +1 -1
- package/dist/operations/teleport.js +5 -0
- package/dist/operations/teleport.js.map +1 -1
- package/dist/operations/teleportProof.d.ts +34 -0
- package/dist/operations/teleportProof.d.ts.map +1 -1
- package/dist/operations/teleportProof.js +16 -0
- package/dist/operations/teleportProof.js.map +1 -1
- package/dist/registry/__tests__/helpers.test.d.ts +2 -0
- package/dist/registry/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/registry/__tests__/helpers.test.js +98 -0
- package/dist/registry/__tests__/helpers.test.js.map +1 -0
- package/dist/registry/__tests__/loader.test.d.ts +2 -0
- package/dist/registry/__tests__/loader.test.d.ts.map +1 -0
- package/dist/registry/__tests__/loader.test.js +300 -0
- package/dist/registry/__tests__/loader.test.js.map +1 -0
- package/dist/registry/__tests__/normalize.test.d.ts +2 -0
- package/dist/registry/__tests__/normalize.test.d.ts.map +1 -0
- package/dist/registry/__tests__/normalize.test.js +180 -0
- package/dist/registry/__tests__/normalize.test.js.map +1 -0
- package/dist/registry/__tests__/parsing.test.d.ts +2 -0
- package/dist/registry/__tests__/parsing.test.d.ts.map +1 -0
- package/dist/registry/__tests__/parsing.test.js +188 -0
- package/dist/registry/__tests__/parsing.test.js.map +1 -0
- package/dist/registry/helpers.d.ts +14 -0
- package/dist/registry/helpers.d.ts.map +1 -0
- package/dist/registry/helpers.js +29 -0
- package/dist/registry/helpers.js.map +1 -0
- package/dist/registry/index.d.ts +13 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +15 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/loader.d.ts +57 -0
- package/dist/registry/loader.d.ts.map +1 -0
- package/dist/registry/loader.js +188 -0
- package/dist/registry/loader.js.map +1 -0
- package/dist/registry/normalize.d.ts +29 -0
- package/dist/registry/normalize.d.ts.map +1 -0
- package/dist/registry/normalize.js +81 -0
- package/dist/registry/normalize.js.map +1 -0
- package/dist/registry/parsing.d.ts +55 -0
- package/dist/registry/parsing.d.ts.map +1 -0
- package/dist/registry/parsing.js +139 -0
- package/dist/registry/parsing.js.map +1 -0
- package/dist/registry/tokens.d.ts +6 -42
- package/dist/registry/tokens.d.ts.map +1 -1
- package/dist/registry/tokens.js +6 -231
- package/dist/registry/tokens.js.map +1 -1
- package/dist/registry/types.d.ts +81 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +2 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/sdk.d.ts +57 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +21 -0
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.publicApi.test.d.ts +2 -0
- package/dist/sdk.publicApi.test.d.ts.map +1 -0
- package/dist/sdk.publicApi.test.js +78 -0
- package/dist/sdk.publicApi.test.js.map +1 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/__tests__/branded.test.d.ts +2 -0
- package/dist/utils/__tests__/branded.test.d.ts.map +1 -0
- package/dist/utils/__tests__/branded.test.js +293 -0
- package/dist/utils/__tests__/branded.test.js.map +1 -0
- package/dist/utils/__tests__/fees.test.d.ts +2 -0
- package/dist/utils/__tests__/fees.test.d.ts.map +1 -0
- package/dist/utils/__tests__/fees.test.js +84 -0
- package/dist/utils/__tests__/fees.test.js.map +1 -0
- package/dist/utils/__tests__/hex.test.d.ts +2 -0
- package/dist/utils/__tests__/hex.test.d.ts.map +1 -0
- package/dist/utils/__tests__/hex.test.js +252 -0
- package/dist/utils/__tests__/hex.test.js.map +1 -0
- package/dist/utils/__tests__/http.test.d.ts +2 -0
- package/dist/utils/__tests__/http.test.d.ts.map +1 -0
- package/dist/utils/__tests__/http.test.js +295 -0
- package/dist/utils/__tests__/http.test.js.map +1 -0
- package/dist/utils/branded.d.ts +154 -0
- package/dist/utils/branded.d.ts.map +1 -0
- package/dist/utils/branded.js +177 -0
- package/dist/utils/branded.js.map +1 -0
- package/dist/utils/fees.d.ts +6 -0
- package/dist/utils/fees.d.ts.map +1 -1
- package/dist/utils/fees.js +4 -0
- package/dist/utils/fees.js.map +1 -1
- package/dist/utils/hex.d.ts +37 -0
- package/dist/utils/hex.d.ts.map +1 -1
- package/dist/utils/hex.js +30 -0
- package/dist/utils/hex.js.map +1 -1
- package/dist/utils/http.d.ts +100 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/http.js +158 -0
- package/dist/utils/http.js.map +1 -1
- package/dist/utils/merkle.d.ts +26 -0
- package/dist/utils/merkle.d.ts.map +1 -1
- package/dist/utils/merkle.js +26 -0
- package/dist/utils/merkle.js.map +1 -1
- package/dist/wasm/__tests__/artifacts.test.d.ts +2 -0
- package/dist/wasm/__tests__/artifacts.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/artifacts.test.js +437 -0
- package/dist/wasm/__tests__/artifacts.test.js.map +1 -0
- package/dist/wasm/__tests__/functions.test.d.ts +2 -0
- package/dist/wasm/__tests__/functions.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/functions.test.js +34 -0
- package/dist/wasm/__tests__/functions.test.js.map +1 -0
- package/dist/wasm/__tests__/helpers.test.d.ts +2 -0
- package/dist/wasm/__tests__/helpers.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/helpers.test.js +128 -0
- package/dist/wasm/__tests__/helpers.test.js.map +1 -0
- package/dist/wasm/__tests__/loader.test.d.ts +2 -0
- package/dist/wasm/__tests__/loader.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/loader.test.js +201 -0
- package/dist/wasm/__tests__/loader.test.js.map +1 -0
- package/dist/wasm/__tests__/runtime.test.d.ts +2 -0
- package/dist/wasm/__tests__/runtime.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/runtime.test.js +335 -0
- package/dist/wasm/__tests__/runtime.test.js.map +1 -0
- package/dist/wasm/__tests__/serialization.test.d.ts +2 -0
- package/dist/wasm/__tests__/serialization.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/serialization.test.js +226 -0
- package/dist/wasm/__tests__/serialization.test.js.map +1 -0
- package/dist/wasm/__tests__/validation.test.js +15 -15
- package/dist/wasm/__tests__/validation.test.js.map +1 -1
- package/dist/wasm/artifacts.d.ts +121 -3
- package/dist/wasm/artifacts.d.ts.map +1 -1
- package/dist/wasm/artifacts.js +175 -50
- package/dist/wasm/artifacts.js.map +1 -1
- package/dist/wasm/functions.d.ts +77 -0
- package/dist/wasm/functions.d.ts.map +1 -0
- package/dist/wasm/functions.js +120 -0
- package/dist/wasm/functions.js.map +1 -0
- package/dist/wasm/helpers.d.ts +32 -0
- package/dist/wasm/helpers.d.ts.map +1 -0
- package/dist/wasm/helpers.js +79 -0
- package/dist/wasm/helpers.js.map +1 -0
- package/dist/wasm/index.d.ts +13 -68
- package/dist/wasm/index.d.ts.map +1 -1
- package/dist/wasm/index.js +14 -514
- package/dist/wasm/index.js.map +1 -1
- package/dist/wasm/loader.d.ts +76 -0
- package/dist/wasm/loader.d.ts.map +1 -0
- package/dist/wasm/loader.js +145 -0
- package/dist/wasm/loader.js.map +1 -0
- package/dist/wasm/runtime.d.ts +65 -0
- package/dist/wasm/runtime.d.ts.map +1 -0
- package/dist/wasm/runtime.js +227 -0
- package/dist/wasm/runtime.js.map +1 -0
- package/dist/wasm/serialization.d.ts +113 -0
- package/dist/wasm/serialization.d.ts.map +1 -0
- package/dist/wasm/serialization.js +188 -0
- package/dist/wasm/serialization.js.map +1 -0
- package/dist/wasm/types.d.ts +30 -0
- package/dist/wasm/types.d.ts.map +1 -0
- package/dist/wasm/types.js +2 -0
- package/dist/wasm/types.js.map +1 -0
- package/dist/zkp/__tests__/proofService.test.d.ts +2 -0
- package/dist/zkp/__tests__/proofService.test.d.ts.map +1 -0
- package/dist/zkp/__tests__/proofService.test.js +283 -0
- package/dist/zkp/__tests__/proofService.test.js.map +1 -0
- package/dist/zkp/__tests__/proofUtils.test.js +86 -0
- package/dist/zkp/__tests__/proofUtils.test.js.map +1 -1
- package/dist/zkp/__tests__/runNovaProver.test.js +13 -1
- package/dist/zkp/__tests__/runNovaProver.test.js.map +1 -1
- package/dist/zkp/__tests__/workerClient.test.d.ts +2 -0
- package/dist/zkp/__tests__/workerClient.test.d.ts.map +1 -0
- package/dist/zkp/__tests__/workerClient.test.js +415 -0
- package/dist/zkp/__tests__/workerClient.test.js.map +1 -0
- package/dist/zkp/index.d.ts +1 -1
- package/dist/zkp/index.d.ts.map +1 -1
- package/dist/zkp/index.js +1 -1
- package/dist/zkp/index.js.map +1 -1
- package/dist/zkp/proofService.d.ts +27 -0
- package/dist/zkp/proofService.d.ts.map +1 -1
- package/dist/zkp/proofService.js +29 -21
- package/dist/zkp/proofService.js.map +1 -1
- package/dist/zkp/proofUtils.d.ts +36 -0
- package/dist/zkp/proofUtils.d.ts.map +1 -1
- package/dist/zkp/proofUtils.js +50 -0
- package/dist/zkp/proofUtils.js.map +1 -1
- package/dist/zkp/workerClient.d.ts +65 -0
- package/dist/zkp/workerClient.d.ts.map +1 -1
- package/dist/zkp/workerClient.js +135 -61
- package/dist/zkp/workerClient.js.map +1 -1
- package/dist/zkp/workerTypes.d.ts +27 -0
- package/dist/zkp/workerTypes.d.ts.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization and deserialization utilities for WASM interop.
|
|
3
|
+
* Handles conversion between SDK types (camelCase) and WASM boundary types.
|
|
4
|
+
* Note: WASM types use mixed naming conventions (snake_case for some fields, camelCase for others).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Most helpers in this file validate that required fields exist and that hex strings are well-formed.
|
|
8
|
+
* These validations intentionally throw early to avoid passing malformed values into WASM.
|
|
9
|
+
*/
|
|
10
|
+
import { AggregationTreeState, BurnArtifacts, ChainEvents, ChainLocalTeleportProofs, EventsWithEligibility, GlobalTeleportProofWithEvent, HubEntryConfig, IndexedEvent, LocalTeleportProof, SecretAndTweak, SeparatedChainEvents, TokenEntryConfig } from "../types.js";
|
|
11
|
+
export type NumericValue = number | string | bigint;
|
|
12
|
+
export interface RawSecretAndTweak {
|
|
13
|
+
secret: string;
|
|
14
|
+
tweak: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RawGeneralRecipient {
|
|
17
|
+
chainId: number | string | bigint;
|
|
18
|
+
address: string;
|
|
19
|
+
tweak: string;
|
|
20
|
+
fr: string;
|
|
21
|
+
u256: string;
|
|
22
|
+
}
|
|
23
|
+
export interface RawBurnArtifacts {
|
|
24
|
+
burnAddress: string;
|
|
25
|
+
fullBurnAddress: string;
|
|
26
|
+
secret: string;
|
|
27
|
+
tweak?: string;
|
|
28
|
+
generalRecipient: RawGeneralRecipient;
|
|
29
|
+
}
|
|
30
|
+
export interface RawHubEntry {
|
|
31
|
+
hub_address: string;
|
|
32
|
+
chain_id: NumericValue;
|
|
33
|
+
rpc_urls: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface RawTokenEntry {
|
|
36
|
+
label: string;
|
|
37
|
+
token_address: string;
|
|
38
|
+
verifier_address: string;
|
|
39
|
+
minter_address?: string;
|
|
40
|
+
chain_id: NumericValue;
|
|
41
|
+
deployed_block_number: NumericValue;
|
|
42
|
+
rpc_urls: string[];
|
|
43
|
+
legacy_tx: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface RawAggregationTreeState {
|
|
46
|
+
latestAggSeq: NumericValue;
|
|
47
|
+
aggregationRoot: string;
|
|
48
|
+
snapshot: string[];
|
|
49
|
+
transferTreeIndices: NumericValue[];
|
|
50
|
+
chainIds: NumericValue[];
|
|
51
|
+
}
|
|
52
|
+
export interface RawIndexedEvent {
|
|
53
|
+
event_index: NumericValue;
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
value: string;
|
|
57
|
+
eth_block_number: NumericValue;
|
|
58
|
+
}
|
|
59
|
+
export interface RawChainEvents {
|
|
60
|
+
chainId: NumericValue;
|
|
61
|
+
events: RawIndexedEvent[];
|
|
62
|
+
}
|
|
63
|
+
export interface RawEventsWithEligibility {
|
|
64
|
+
eligible: RawIndexedEvent[];
|
|
65
|
+
ineligible: RawIndexedEvent[];
|
|
66
|
+
}
|
|
67
|
+
export interface RawSeparatedChainEvents {
|
|
68
|
+
chainId: NumericValue;
|
|
69
|
+
events: RawEventsWithEligibility;
|
|
70
|
+
}
|
|
71
|
+
export interface RawLocalTeleportProof {
|
|
72
|
+
treeIndex: NumericValue;
|
|
73
|
+
event: RawIndexedEvent;
|
|
74
|
+
siblings: string[];
|
|
75
|
+
}
|
|
76
|
+
export interface RawChainLocalTeleportProofs {
|
|
77
|
+
chainId: NumericValue;
|
|
78
|
+
proofs: RawLocalTeleportProof[];
|
|
79
|
+
}
|
|
80
|
+
export interface RawGlobalTeleportProof {
|
|
81
|
+
event: RawIndexedEvent;
|
|
82
|
+
siblings: string[];
|
|
83
|
+
leafIndex: NumericValue;
|
|
84
|
+
}
|
|
85
|
+
export declare function asSecretAndTweak(value: unknown): SecretAndTweak;
|
|
86
|
+
/**
|
|
87
|
+
* Convert an unknown WASM payload into {@link BurnArtifacts}.
|
|
88
|
+
* @throws If the payload shape is missing required fields.
|
|
89
|
+
*/
|
|
90
|
+
export declare function asBurnArtifacts(value: unknown): BurnArtifacts;
|
|
91
|
+
export declare function copyRpcUrls(urls: readonly string[], label: string): string[];
|
|
92
|
+
export declare function serializeHubEntry(entry: HubEntryConfig): RawHubEntry;
|
|
93
|
+
/**
|
|
94
|
+
* Serialize a token entry for WASM/indexer boundary calls.
|
|
95
|
+
* @remarks `legacyTx` defaults to `false` when omitted.
|
|
96
|
+
*/
|
|
97
|
+
export declare function serializeTokenEntry(entry: TokenEntryConfig): RawTokenEntry;
|
|
98
|
+
export declare function serializeAggregationTreeState(state: AggregationTreeState): RawAggregationTreeState;
|
|
99
|
+
/**
|
|
100
|
+
* Serialize an indexed event for WASM/indexer boundary calls.
|
|
101
|
+
*/
|
|
102
|
+
export declare function serializeIndexedEvent(event: IndexedEvent): RawIndexedEvent;
|
|
103
|
+
export declare function serializeChainEvents(entry: ChainEvents): RawChainEvents;
|
|
104
|
+
export declare function serializeLocalTeleportProof(proof: LocalTeleportProof): RawLocalTeleportProof;
|
|
105
|
+
export declare function serializeChainLocalTeleportProofs(entry: ChainLocalTeleportProofs): RawChainLocalTeleportProofs;
|
|
106
|
+
export declare function deserializeAggregationTreeState(raw: RawAggregationTreeState): AggregationTreeState;
|
|
107
|
+
export declare function deserializeIndexedEvent(raw: RawIndexedEvent): IndexedEvent;
|
|
108
|
+
export declare function deserializeChainEvents(raw: RawChainEvents): ChainEvents;
|
|
109
|
+
export declare function deserializeEventsWithEligibility(raw: RawEventsWithEligibility): EventsWithEligibility;
|
|
110
|
+
export declare function deserializeSeparatedChainEvents(raw: RawSeparatedChainEvents): SeparatedChainEvents;
|
|
111
|
+
export declare function deserializeLocalTeleportProof(raw: RawLocalTeleportProof): LocalTeleportProof;
|
|
112
|
+
export declare function deserializeGlobalTeleportProof(raw: RawGlobalTeleportProof): GlobalTeleportProofWithEvent;
|
|
113
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../src/wasm/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,4BAA4B,EAC5B,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAOrB,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,C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AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,cAAc,GAAG,WAAW,CAKvE;AAED,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,wBAAwB,GAC5B,qBAAqB,CAKvB;AAED,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,uBAAuB,GAC3B,oBAAoB,CAKtB;AAED,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,qBAAqB,GAAG,kBAAkB,CAM5F;AAED,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,sBAAsB,GAC1B,4BAA4B,CAM9B"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization and deserialization utilities for WASM interop.
|
|
3
|
+
* Handles conversion between SDK types (camelCase) and WASM boundary types.
|
|
4
|
+
* Note: WASM types use mixed naming conventions (snake_case for some fields, camelCase for others).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Most helpers in this file validate that required fields exist and that hex strings are well-formed.
|
|
8
|
+
* These validations intentionally throw early to avoid passing malformed values into WASM.
|
|
9
|
+
*/
|
|
10
|
+
import { normalizeHex, toBigInt } from "../utils/hex.js";
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Conversion Helpers
|
|
13
|
+
// ============================================================================
|
|
14
|
+
export function asSecretAndTweak(value) {
|
|
15
|
+
const candidate = value;
|
|
16
|
+
if (!candidate || typeof candidate.secret !== "string" || typeof candidate.tweak !== "string") {
|
|
17
|
+
throw new Error("unexpected secret/tweak payload from wasm");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
secret: normalizeHex(candidate.secret),
|
|
21
|
+
tweak: normalizeHex(candidate.tweak),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Convert an unknown WASM payload into {@link BurnArtifacts}.
|
|
26
|
+
* @throws If the payload shape is missing required fields.
|
|
27
|
+
*/
|
|
28
|
+
export function asBurnArtifacts(value) {
|
|
29
|
+
const raw = value;
|
|
30
|
+
if (!raw || typeof raw.burnAddress !== "string" || typeof raw.secret !== "string") {
|
|
31
|
+
throw new Error("unexpected burn artifacts payload from wasm");
|
|
32
|
+
}
|
|
33
|
+
const recipient = raw.generalRecipient;
|
|
34
|
+
if (!recipient || typeof recipient.address !== "string") {
|
|
35
|
+
throw new Error("missing general recipient payload from wasm");
|
|
36
|
+
}
|
|
37
|
+
const tweakSource = raw.tweak ?? recipient.tweak;
|
|
38
|
+
if (typeof tweakSource !== "string") {
|
|
39
|
+
throw new Error("missing burn tweak payload from wasm");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
burnAddress: normalizeHex(raw.burnAddress),
|
|
43
|
+
fullBurnAddress: normalizeHex(raw.fullBurnAddress),
|
|
44
|
+
secret: normalizeHex(raw.secret),
|
|
45
|
+
tweak: normalizeHex(tweakSource),
|
|
46
|
+
generalRecipient: {
|
|
47
|
+
chainId: toBigInt(recipient.chainId ?? 0),
|
|
48
|
+
address: normalizeHex(recipient.address),
|
|
49
|
+
tweak: normalizeHex(recipient.tweak),
|
|
50
|
+
fr: normalizeHex(recipient.fr),
|
|
51
|
+
u256: normalizeHex(recipient.u256),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// RPC URL Validation
|
|
57
|
+
// ============================================================================
|
|
58
|
+
export function copyRpcUrls(urls, label) {
|
|
59
|
+
if (!Array.isArray(urls) || urls.length === 0) {
|
|
60
|
+
throw new Error(`${label} must provide at least one RPC URL`);
|
|
61
|
+
}
|
|
62
|
+
return urls.map((url, idx) => {
|
|
63
|
+
if (typeof url !== "string" || url.trim().length === 0) {
|
|
64
|
+
throw new Error(`${label} RPC URL at index ${idx} must be a non-empty string`);
|
|
65
|
+
}
|
|
66
|
+
return url.trim();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Serialization (SDK → WASM)
|
|
71
|
+
// ============================================================================
|
|
72
|
+
export function serializeHubEntry(entry) {
|
|
73
|
+
return {
|
|
74
|
+
hub_address: normalizeHex(entry.hubAddress),
|
|
75
|
+
chain_id: entry.chainId,
|
|
76
|
+
rpc_urls: copyRpcUrls(entry.rpcUrls, "hub.rpcUrls"),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Serialize a token entry for WASM/indexer boundary calls.
|
|
81
|
+
* @remarks `legacyTx` defaults to `false` when omitted.
|
|
82
|
+
*/
|
|
83
|
+
export function serializeTokenEntry(entry) {
|
|
84
|
+
return {
|
|
85
|
+
label: entry.label,
|
|
86
|
+
token_address: normalizeHex(entry.tokenAddress),
|
|
87
|
+
verifier_address: normalizeHex(entry.verifierAddress),
|
|
88
|
+
minter_address: entry.minterAddress ? normalizeHex(entry.minterAddress) : undefined,
|
|
89
|
+
chain_id: entry.chainId,
|
|
90
|
+
deployed_block_number: entry.deployedBlockNumber,
|
|
91
|
+
rpc_urls: copyRpcUrls(entry.rpcUrls, `${entry.label}.rpcUrls`),
|
|
92
|
+
legacy_tx: entry.legacyTx ?? false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export function serializeAggregationTreeState(state) {
|
|
96
|
+
return {
|
|
97
|
+
latestAggSeq: state.latestAggSeq,
|
|
98
|
+
aggregationRoot: normalizeHex(state.aggregationRoot),
|
|
99
|
+
snapshot: state.snapshot.map((value) => normalizeHex(value)),
|
|
100
|
+
transferTreeIndices: state.transferTreeIndices.map((value) => value),
|
|
101
|
+
chainIds: state.chainIds.map((value) => value),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Serialize an indexed event for WASM/indexer boundary calls.
|
|
106
|
+
*/
|
|
107
|
+
export function serializeIndexedEvent(event) {
|
|
108
|
+
return {
|
|
109
|
+
event_index: event.eventIndex,
|
|
110
|
+
from: normalizeHex(event.from),
|
|
111
|
+
to: normalizeHex(event.to),
|
|
112
|
+
value: normalizeHex(event.value),
|
|
113
|
+
eth_block_number: event.ethBlockNumber,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export function serializeChainEvents(entry) {
|
|
117
|
+
return {
|
|
118
|
+
chainId: entry.chainId,
|
|
119
|
+
events: entry.events.map(serializeIndexedEvent),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function serializeLocalTeleportProof(proof) {
|
|
123
|
+
return {
|
|
124
|
+
treeIndex: proof.treeIndex,
|
|
125
|
+
event: serializeIndexedEvent(proof.event),
|
|
126
|
+
siblings: proof.siblings.map((value) => normalizeHex(value)),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export function serializeChainLocalTeleportProofs(entry) {
|
|
130
|
+
return {
|
|
131
|
+
chainId: entry.chainId,
|
|
132
|
+
proofs: entry.proofs.map(serializeLocalTeleportProof),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Deserialization (WASM → SDK)
|
|
137
|
+
// ============================================================================
|
|
138
|
+
export function deserializeAggregationTreeState(raw) {
|
|
139
|
+
return {
|
|
140
|
+
latestAggSeq: toBigInt(raw.latestAggSeq),
|
|
141
|
+
aggregationRoot: normalizeHex(raw.aggregationRoot),
|
|
142
|
+
snapshot: raw.snapshot.map((value) => normalizeHex(value)),
|
|
143
|
+
transferTreeIndices: raw.transferTreeIndices.map((value) => toBigInt(value)),
|
|
144
|
+
chainIds: raw.chainIds.map((value) => toBigInt(value)),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export function deserializeIndexedEvent(raw) {
|
|
148
|
+
return {
|
|
149
|
+
eventIndex: toBigInt(raw.event_index),
|
|
150
|
+
from: normalizeHex(raw.from),
|
|
151
|
+
to: normalizeHex(raw.to),
|
|
152
|
+
value: toBigInt(raw.value),
|
|
153
|
+
ethBlockNumber: toBigInt(raw.eth_block_number),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export function deserializeChainEvents(raw) {
|
|
157
|
+
return {
|
|
158
|
+
chainId: toBigInt(raw.chainId),
|
|
159
|
+
events: raw.events.map(deserializeIndexedEvent),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export function deserializeEventsWithEligibility(raw) {
|
|
163
|
+
return {
|
|
164
|
+
eligible: raw.eligible.map(deserializeIndexedEvent),
|
|
165
|
+
ineligible: raw.ineligible.map(deserializeIndexedEvent),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export function deserializeSeparatedChainEvents(raw) {
|
|
169
|
+
return {
|
|
170
|
+
chainId: toBigInt(raw.chainId),
|
|
171
|
+
events: deserializeEventsWithEligibility(raw.events),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export function deserializeLocalTeleportProof(raw) {
|
|
175
|
+
return {
|
|
176
|
+
treeIndex: toBigInt(raw.treeIndex),
|
|
177
|
+
event: deserializeIndexedEvent(raw.event),
|
|
178
|
+
siblings: raw.siblings.map((value) => normalizeHex(value)),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export function deserializeGlobalTeleportProof(raw) {
|
|
182
|
+
return {
|
|
183
|
+
event: deserializeIndexedEvent(raw.event),
|
|
184
|
+
siblings: raw.siblings.map((value) => normalizeHex(value)),
|
|
185
|
+
leafIndex: toBigInt(raw.leafIndex),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../src/wasm/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA8FzD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,MAAM,SAAS,GAAG,KAA0B,CAAC;IAC7C,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,CAAC,M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AAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;KAC3D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,GAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC;QACzC,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1D,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global object interface for resolving WASM URLs.
|
|
3
|
+
*/
|
|
4
|
+
export interface WasmLocatorGlobal {
|
|
5
|
+
location?: {
|
|
6
|
+
origin?: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for WasmRuntime.
|
|
11
|
+
* @remarks
|
|
12
|
+
* URL resolution order is:
|
|
13
|
+
* 1) `url` (explicit override)
|
|
14
|
+
* 2) `baseUrl` + `wasmFilename` (defaults to `assets/wasm/web/zerc20_wasm_bg.wasm`)
|
|
15
|
+
* 3) bundled fallback URL (package-relative)
|
|
16
|
+
*
|
|
17
|
+
* If `baseUrl` is relative (not `http(s)://`), the runtime needs `location.origin` from the configured
|
|
18
|
+
* `globalObject` (defaults to `globalThis`) to construct an absolute URL.
|
|
19
|
+
*/
|
|
20
|
+
export interface WasmRuntimeOptions {
|
|
21
|
+
/** Direct URL to the wasm bundle (takes precedence over other resolution). */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** Base URL used to resolve the wasm file. */
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
/** Override filename when using a custom base. */
|
|
26
|
+
wasmFilename?: string;
|
|
27
|
+
/** Custom global object used when resolving relative base URLs (defaults to globalThis). */
|
|
28
|
+
globalObject?: WasmLocatorGlobal;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/wasm/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/wasm/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proofService.test.d.ts","sourceRoot":"","sources":["../../../src/zkp/__tests__/proofService.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { ProofService } from "../proofService.js";
|
|
3
|
+
// Suppress console output during tests
|
|
4
|
+
const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
5
|
+
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
6
|
+
// Mock dependencies
|
|
7
|
+
vi.mock("../workerClient.js", () => ({
|
|
8
|
+
canUseZkpWorker: vi.fn(),
|
|
9
|
+
disableZkpWorker: vi.fn(),
|
|
10
|
+
runZkpWorkerJob: vi.fn(),
|
|
11
|
+
}));
|
|
12
|
+
vi.mock("../../wasm/artifacts.js", () => ({
|
|
13
|
+
loadSingleTeleportArtifacts: vi.fn(),
|
|
14
|
+
loadBatchTeleportArtifacts: vi.fn(),
|
|
15
|
+
}));
|
|
16
|
+
vi.mock("../../utils/merkle.js", () => ({
|
|
17
|
+
verifyGlobalTeleportProofs: vi.fn(),
|
|
18
|
+
}));
|
|
19
|
+
import { canUseZkpWorker, disableZkpWorker, runZkpWorkerJob } from "../workerClient.js";
|
|
20
|
+
import { loadSingleTeleportArtifacts, loadBatchTeleportArtifacts } from "../../wasm/artifacts.js";
|
|
21
|
+
import { verifyGlobalTeleportProofs } from "../../utils/merkle.js";
|
|
22
|
+
const mockCanUseZkpWorker = vi.mocked(canUseZkpWorker);
|
|
23
|
+
const mockDisableZkpWorker = vi.mocked(disableZkpWorker);
|
|
24
|
+
const mockRunZkpWorkerJob = vi.mocked(runZkpWorkerJob);
|
|
25
|
+
const mockLoadSingleTeleportArtifacts = vi.mocked(loadSingleTeleportArtifacts);
|
|
26
|
+
const mockLoadBatchTeleportArtifacts = vi.mocked(loadBatchTeleportArtifacts);
|
|
27
|
+
const mockVerifyGlobalTeleportProofs = vi.mocked(verifyGlobalTeleportProofs);
|
|
28
|
+
describe("ProofService", () => {
|
|
29
|
+
const mockSingleWithdrawProgram = {
|
|
30
|
+
prove: vi.fn(),
|
|
31
|
+
};
|
|
32
|
+
const mockNovaProgram = {
|
|
33
|
+
prove: vi.fn(),
|
|
34
|
+
};
|
|
35
|
+
const mockWasmRuntime = {
|
|
36
|
+
createSingleWithdrawProgram: vi.fn().mockResolvedValue(mockSingleWithdrawProgram),
|
|
37
|
+
createWithdrawNovaProgram: vi.fn().mockResolvedValue(mockNovaProgram),
|
|
38
|
+
};
|
|
39
|
+
const singleTeleportParams = {
|
|
40
|
+
aggregationState: {
|
|
41
|
+
latestAggSeq: 1n,
|
|
42
|
+
aggregationRoot: "0x" + "00".repeat(32),
|
|
43
|
+
snapshot: [],
|
|
44
|
+
transferTreeIndices: [],
|
|
45
|
+
chainIds: [],
|
|
46
|
+
},
|
|
47
|
+
recipientFr: "0x" + "01".repeat(32),
|
|
48
|
+
secretHex: "0x" + "02".repeat(32),
|
|
49
|
+
event: {
|
|
50
|
+
from: "0x" + "03".repeat(20),
|
|
51
|
+
to: "0x" + "05".repeat(20),
|
|
52
|
+
value: 1000n,
|
|
53
|
+
eventIndex: 0n,
|
|
54
|
+
ethBlockNumber: 12345n,
|
|
55
|
+
},
|
|
56
|
+
proof: {
|
|
57
|
+
leafIndex: 5n,
|
|
58
|
+
siblings: ["0x" + "04".repeat(32)],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const novaProverParams = {
|
|
62
|
+
aggregationState: {
|
|
63
|
+
latestAggSeq: 1n,
|
|
64
|
+
aggregationRoot: "0x" + "00".repeat(32),
|
|
65
|
+
snapshot: [],
|
|
66
|
+
transferTreeIndices: [],
|
|
67
|
+
chainIds: [],
|
|
68
|
+
},
|
|
69
|
+
recipientFr: "0x" + "01".repeat(32),
|
|
70
|
+
secretHex: "0x" + "02".repeat(32),
|
|
71
|
+
events: [
|
|
72
|
+
{
|
|
73
|
+
from: "0x" + "03".repeat(20),
|
|
74
|
+
to: "0x" + "05".repeat(20),
|
|
75
|
+
value: 1000n,
|
|
76
|
+
eventIndex: 0n,
|
|
77
|
+
ethBlockNumber: 12345n,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
proofs: [
|
|
81
|
+
{
|
|
82
|
+
leafIndex: 5n,
|
|
83
|
+
siblings: ["0x" + "04".repeat(32)],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
const mockSingleArtifacts = {
|
|
88
|
+
localPk: new Uint8Array([1, 2, 3]),
|
|
89
|
+
localVk: new Uint8Array([4, 5, 6]),
|
|
90
|
+
globalPk: new Uint8Array([7, 8, 9]),
|
|
91
|
+
globalVk: new Uint8Array([10, 11, 12]),
|
|
92
|
+
};
|
|
93
|
+
const mockBatchArtifacts = {
|
|
94
|
+
localPp: new Uint8Array([1, 2, 3]),
|
|
95
|
+
localVp: new Uint8Array([4, 5, 6]),
|
|
96
|
+
globalPp: new Uint8Array([7, 8, 9]),
|
|
97
|
+
globalVp: new Uint8Array([10, 11, 12]),
|
|
98
|
+
};
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
vi.clearAllMocks();
|
|
101
|
+
mockLoadSingleTeleportArtifacts.mockResolvedValue(mockSingleArtifacts);
|
|
102
|
+
mockLoadBatchTeleportArtifacts.mockResolvedValue(mockBatchArtifacts);
|
|
103
|
+
});
|
|
104
|
+
afterEach(() => {
|
|
105
|
+
consoleWarnSpy.mockClear();
|
|
106
|
+
consoleErrorSpy.mockClear();
|
|
107
|
+
});
|
|
108
|
+
afterAll(() => {
|
|
109
|
+
consoleWarnSpy.mockRestore();
|
|
110
|
+
consoleErrorSpy.mockRestore();
|
|
111
|
+
});
|
|
112
|
+
describe("createSingleTeleportProof", () => {
|
|
113
|
+
test("uses worker when available", async () => {
|
|
114
|
+
mockCanUseZkpWorker.mockReturnValue(true);
|
|
115
|
+
const expectedResult = {
|
|
116
|
+
proofCalldata: "0xproof",
|
|
117
|
+
publicInputs: ["0xinput1"],
|
|
118
|
+
treeDepth: 20,
|
|
119
|
+
};
|
|
120
|
+
mockRunZkpWorkerJob.mockResolvedValue(expectedResult);
|
|
121
|
+
const service = new ProofService(mockWasmRuntime);
|
|
122
|
+
const result = await service.createSingleTeleportProof(singleTeleportParams);
|
|
123
|
+
expect(result).toEqual(expectedResult);
|
|
124
|
+
expect(mockRunZkpWorkerJob).toHaveBeenCalledWith("singleTeleport", {
|
|
125
|
+
params: singleTeleportParams,
|
|
126
|
+
artifacts: mockSingleArtifacts,
|
|
127
|
+
});
|
|
128
|
+
expect(mockWasmRuntime.createSingleWithdrawProgram).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
test("falls back to main thread when worker fails", async () => {
|
|
131
|
+
mockCanUseZkpWorker.mockReturnValue(true);
|
|
132
|
+
mockRunZkpWorkerJob.mockRejectedValue(new Error("Worker error"));
|
|
133
|
+
mockSingleWithdrawProgram.prove.mockResolvedValue({
|
|
134
|
+
proofCalldata: "0xaabbccdd",
|
|
135
|
+
publicInputs: ["0x1122"],
|
|
136
|
+
treeDepth: 20,
|
|
137
|
+
});
|
|
138
|
+
const service = new ProofService(mockWasmRuntime);
|
|
139
|
+
const result = await service.createSingleTeleportProof(singleTeleportParams);
|
|
140
|
+
expect(result.proofCalldata).toBe("0xaabbccdd");
|
|
141
|
+
expect(mockDisableZkpWorker).toHaveBeenCalled();
|
|
142
|
+
expect(mockWasmRuntime.createSingleWithdrawProgram).toHaveBeenCalled();
|
|
143
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("Worker single proof failed"), expect.any(Error));
|
|
144
|
+
});
|
|
145
|
+
test("uses main thread directly when worker not available", async () => {
|
|
146
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
147
|
+
mockSingleWithdrawProgram.prove.mockResolvedValue({
|
|
148
|
+
proofCalldata: "0xaabbccdd",
|
|
149
|
+
publicInputs: ["0x1122"],
|
|
150
|
+
treeDepth: 20,
|
|
151
|
+
});
|
|
152
|
+
const service = new ProofService(mockWasmRuntime);
|
|
153
|
+
const result = await service.createSingleTeleportProof(singleTeleportParams);
|
|
154
|
+
expect(result.proofCalldata).toBe("0xaabbccdd");
|
|
155
|
+
expect(mockRunZkpWorkerJob).not.toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
test("throws formatted error on proof failure", async () => {
|
|
158
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
159
|
+
mockSingleWithdrawProgram.prove.mockRejectedValue(new Error("Proof generation failed"));
|
|
160
|
+
const service = new ProofService(mockWasmRuntime);
|
|
161
|
+
await expect(service.createSingleTeleportProof(singleTeleportParams)).rejects.toThrow("single teleport proof failed: Proof generation failed");
|
|
162
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("createSingleTeleportProof failed"), expect.any(Object), expect.any(Error));
|
|
163
|
+
});
|
|
164
|
+
test("handles non-Error exceptions", async () => {
|
|
165
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
166
|
+
mockSingleWithdrawProgram.prove.mockRejectedValue("string error");
|
|
167
|
+
const service = new ProofService(mockWasmRuntime);
|
|
168
|
+
await expect(service.createSingleTeleportProof(singleTeleportParams)).rejects.toThrow("single teleport proof failed: string error");
|
|
169
|
+
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe("runNovaProver", () => {
|
|
173
|
+
test("uses worker when available", async () => {
|
|
174
|
+
mockCanUseZkpWorker.mockReturnValue(true);
|
|
175
|
+
const expectedResult = {
|
|
176
|
+
ivcProof: new Uint8Array([1, 2, 3]),
|
|
177
|
+
finalState: ["0xstate1"],
|
|
178
|
+
steps: 2,
|
|
179
|
+
};
|
|
180
|
+
mockRunZkpWorkerJob.mockResolvedValue(expectedResult);
|
|
181
|
+
const service = new ProofService(mockWasmRuntime);
|
|
182
|
+
const result = await service.runNovaProver(novaProverParams);
|
|
183
|
+
expect(result).toEqual(expectedResult);
|
|
184
|
+
expect(mockRunZkpWorkerJob).toHaveBeenCalledWith("nova", {
|
|
185
|
+
params: novaProverParams,
|
|
186
|
+
artifacts: mockBatchArtifacts,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
test("falls back to main thread when worker fails", async () => {
|
|
190
|
+
mockCanUseZkpWorker.mockReturnValue(true);
|
|
191
|
+
mockRunZkpWorkerJob.mockRejectedValue(new Error("Worker error"));
|
|
192
|
+
mockNovaProgram.prove.mockResolvedValue({
|
|
193
|
+
ivcProof: "0x010203",
|
|
194
|
+
finalState: ["0xstate1"],
|
|
195
|
+
steps: 2,
|
|
196
|
+
});
|
|
197
|
+
const service = new ProofService(mockWasmRuntime);
|
|
198
|
+
const result = await service.runNovaProver(novaProverParams);
|
|
199
|
+
expect(result.steps).toBe(2);
|
|
200
|
+
expect(mockDisableZkpWorker).toHaveBeenCalled();
|
|
201
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("Worker nova prover failed"), expect.any(Error));
|
|
202
|
+
});
|
|
203
|
+
test("throws when events and proofs length mismatch", async () => {
|
|
204
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
205
|
+
const invalidParams = {
|
|
206
|
+
...novaProverParams,
|
|
207
|
+
events: [novaProverParams.events[0], novaProverParams.events[0]],
|
|
208
|
+
proofs: [novaProverParams.proofs[0]],
|
|
209
|
+
};
|
|
210
|
+
const service = new ProofService(mockWasmRuntime);
|
|
211
|
+
await expect(service.runNovaProver(invalidParams)).rejects.toThrow("events length must match proofs length for batch teleport");
|
|
212
|
+
});
|
|
213
|
+
test("verifies proofs before computing", async () => {
|
|
214
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
215
|
+
mockNovaProgram.prove.mockResolvedValue({
|
|
216
|
+
ivcProof: "0x010203",
|
|
217
|
+
finalState: ["0xstate1"],
|
|
218
|
+
steps: 1,
|
|
219
|
+
});
|
|
220
|
+
const service = new ProofService(mockWasmRuntime);
|
|
221
|
+
await service.runNovaProver(novaProverParams);
|
|
222
|
+
expect(mockVerifyGlobalTeleportProofs).toHaveBeenCalledWith({
|
|
223
|
+
aggregationRoot: novaProverParams.aggregationState.aggregationRoot,
|
|
224
|
+
events: novaProverParams.events,
|
|
225
|
+
proofs: novaProverParams.proofs,
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
test("sorts proofs by leaf index before computing", async () => {
|
|
229
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
230
|
+
const multiEventParams = {
|
|
231
|
+
...novaProverParams,
|
|
232
|
+
events: [
|
|
233
|
+
{ ...novaProverParams.events[0], value: 2000n },
|
|
234
|
+
{ ...novaProverParams.events[0], value: 1000n },
|
|
235
|
+
],
|
|
236
|
+
proofs: [
|
|
237
|
+
{ leafIndex: 10n, siblings: [] },
|
|
238
|
+
{ leafIndex: 5n, siblings: [] },
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
mockNovaProgram.prove.mockResolvedValue({
|
|
242
|
+
ivcProof: "0x010203",
|
|
243
|
+
finalState: ["0xstate1"],
|
|
244
|
+
steps: 2,
|
|
245
|
+
});
|
|
246
|
+
const service = new ProofService(mockWasmRuntime);
|
|
247
|
+
await service.runNovaProver(multiEventParams);
|
|
248
|
+
// Verify proofs are sorted by leafIndex ascending (5n before 10n)
|
|
249
|
+
const verifyCall = mockVerifyGlobalTeleportProofs.mock.calls[0][0];
|
|
250
|
+
expect(verifyCall.proofs).toHaveLength(2);
|
|
251
|
+
expect(verifyCall.proofs[0].leafIndex).toBe(5n);
|
|
252
|
+
expect(verifyCall.proofs[1].leafIndex).toBe(10n);
|
|
253
|
+
// Verify events are reordered to match (value 1000n paired with leafIndex 5n)
|
|
254
|
+
expect(verifyCall.events[0].value).toBe(1000n);
|
|
255
|
+
expect(verifyCall.events[1].value).toBe(2000n);
|
|
256
|
+
});
|
|
257
|
+
test("throws formatted error on proof failure", async () => {
|
|
258
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
259
|
+
mockNovaProgram.prove.mockRejectedValue(new Error("Nova proof failed"));
|
|
260
|
+
const service = new ProofService(mockWasmRuntime);
|
|
261
|
+
await expect(service.runNovaProver(novaProverParams)).rejects.toThrow("batch teleport proof failed: Nova proof failed");
|
|
262
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining("runNovaProver failed"), expect.any(Object), expect.any(Object), expect.any(Error));
|
|
263
|
+
});
|
|
264
|
+
test("handles empty events array (dummy steps only)", async () => {
|
|
265
|
+
mockCanUseZkpWorker.mockReturnValue(false);
|
|
266
|
+
const emptyParams = {
|
|
267
|
+
...novaProverParams,
|
|
268
|
+
events: [],
|
|
269
|
+
proofs: [],
|
|
270
|
+
};
|
|
271
|
+
mockNovaProgram.prove.mockResolvedValue({
|
|
272
|
+
ivcProof: "0x010203",
|
|
273
|
+
finalState: ["0xstate1"],
|
|
274
|
+
steps: 1,
|
|
275
|
+
});
|
|
276
|
+
const service = new ProofService(mockWasmRuntime);
|
|
277
|
+
const result = await service.runNovaProver(emptyParams);
|
|
278
|
+
expect(result.steps).toBe(1);
|
|
279
|
+
expect(mockNovaProgram.prove).toHaveBeenCalled();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
//# sourceMappingURL=proofService.test.js.map
|