zerc20-client-sdk 0.1.0
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/dist/assets/abi/ERC1967Proxy.json +76 -0
- package/dist/assets/abi/Hub.json +1443 -0
- package/dist/assets/abi/Minter.json +666 -0
- package/dist/assets/abi/Verifier.json +1935 -0
- package/dist/assets/abi/zERC20.json +919 -0
- package/dist/assets/wasm/node/README.md +6 -0
- package/dist/assets/wasm/node/package.json +11 -0
- package/dist/assets/wasm/node/zkerc20_wasm.d.ts +48 -0
- package/dist/assets/wasm/node/zkerc20_wasm.js +1209 -0
- package/dist/assets/wasm/node/zkerc20_wasm_bg.wasm +0 -0
- package/dist/assets/wasm/node/zkerc20_wasm_bg.wasm.d.ts +36 -0
- package/dist/assets/wasm/web/README.md +6 -0
- package/dist/assets/wasm/web/package.json +15 -0
- package/dist/assets/wasm/web/zkerc20_wasm.d.ts +108 -0
- package/dist/assets/wasm/web/zkerc20_wasm.js +1209 -0
- package/dist/assets/wasm/web/zkerc20_wasm_bg.wasm +0 -0
- package/dist/assets/wasm/web/zkerc20_wasm_bg.wasm.d.ts +36 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/decider/prover.d.ts +17 -0
- package/dist/decider/prover.d.ts.map +1 -0
- package/dist/decider/prover.js +108 -0
- package/dist/decider/prover.js.map +1 -0
- package/dist/ic/__tests__/authorization.test.d.ts +2 -0
- package/dist/ic/__tests__/authorization.test.d.ts.map +1 -0
- package/dist/ic/__tests__/authorization.test.js +31 -0
- package/dist/ic/__tests__/authorization.test.js.map +1 -0
- package/dist/ic/__tests__/encryption.test.d.ts +2 -0
- package/dist/ic/__tests__/encryption.test.d.ts.map +1 -0
- package/dist/ic/__tests__/encryption.test.js +28 -0
- package/dist/ic/__tests__/encryption.test.js.map +1 -0
- package/dist/ic/__tests__/storage_localnet.test.d.ts +2 -0
- package/dist/ic/__tests__/storage_localnet.test.d.ts.map +1 -0
- package/dist/ic/__tests__/storage_localnet.test.js +131 -0
- package/dist/ic/__tests__/storage_localnet.test.js.map +1 -0
- package/dist/ic/authorization.d.ts +10 -0
- package/dist/ic/authorization.d.ts.map +1 -0
- package/dist/ic/authorization.js +54 -0
- package/dist/ic/authorization.js.map +1 -0
- package/dist/ic/client.d.ts +66 -0
- package/dist/ic/client.d.ts.map +1 -0
- package/dist/ic/client.js +192 -0
- package/dist/ic/client.js.map +1 -0
- package/dist/ic/config.d.ts +6 -0
- package/dist/ic/config.d.ts.map +1 -0
- package/dist/ic/config.js +15 -0
- package/dist/ic/config.js.map +1 -0
- package/dist/ic/connections.d.ts +28 -0
- package/dist/ic/connections.d.ts.map +1 -0
- package/dist/ic/connections.js +74 -0
- package/dist/ic/connections.js.map +1 -0
- package/dist/ic/encryption.d.ts +15 -0
- package/dist/ic/encryption.d.ts.map +1 -0
- package/dist/ic/encryption.js +115 -0
- package/dist/ic/encryption.js.map +1 -0
- package/dist/ic/errors.d.ts +7 -0
- package/dist/ic/errors.d.ts.map +1 -0
- package/dist/ic/errors.js +13 -0
- package/dist/ic/errors.js.map +1 -0
- package/dist/ic/index.d.ts +9 -0
- package/dist/ic/index.d.ts.map +1 -0
- package/dist/ic/index.js +9 -0
- package/dist/ic/index.js.map +1 -0
- package/dist/ic/invoice.d.ts +4 -0
- package/dist/ic/invoice.d.ts.map +1 -0
- package/dist/ic/invoice.js +25 -0
- package/dist/ic/invoice.js.map +1 -0
- package/dist/ic/recipient.d.ts +8 -0
- package/dist/ic/recipient.d.ts.map +1 -0
- package/dist/ic/recipient.js +21 -0
- package/dist/ic/recipient.js.map +1 -0
- package/dist/ic/types.d.ts +64 -0
- package/dist/ic/types.d.ts.map +1 -0
- package/dist/ic/types.js +2 -0
- package/dist/ic/types.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/onchain/contracts.d.ts +14512 -0
- package/dist/onchain/contracts.d.ts.map +1 -0
- package/dist/onchain/contracts.js +39 -0
- package/dist/onchain/contracts.js.map +1 -0
- package/dist/operations/invoice.d.ts +17 -0
- package/dist/operations/invoice.d.ts.map +1 -0
- package/dist/operations/invoice.js +115 -0
- package/dist/operations/invoice.js.map +1 -0
- package/dist/operations/minter.d.ts +18 -0
- package/dist/operations/minter.d.ts.map +1 -0
- package/dist/operations/minter.js +77 -0
- package/dist/operations/minter.js.map +1 -0
- package/dist/operations/privateSend.d.ts +17 -0
- package/dist/operations/privateSend.d.ts.map +1 -0
- package/dist/operations/privateSend.js +48 -0
- package/dist/operations/privateSend.js.map +1 -0
- package/dist/operations/receive.d.ts +45 -0
- package/dist/operations/receive.d.ts.map +1 -0
- package/dist/operations/receive.js +107 -0
- package/dist/operations/receive.js.map +1 -0
- package/dist/operations/scanner.d.ts +21 -0
- package/dist/operations/scanner.d.ts.map +1 -0
- package/dist/operations/scanner.js +68 -0
- package/dist/operations/scanner.js.map +1 -0
- package/dist/operations/teleport.d.ts +3 -0
- package/dist/operations/teleport.d.ts.map +1 -0
- package/dist/operations/teleport.js +11 -0
- package/dist/operations/teleport.js.map +1 -0
- package/dist/operations/teleportProof.d.ts +30 -0
- package/dist/operations/teleportProof.d.ts.map +1 -0
- package/dist/operations/teleportProof.js +44 -0
- package/dist/operations/teleportProof.js.map +1 -0
- package/dist/registry/tokens.d.ts +39 -0
- package/dist/registry/tokens.d.ts.map +1 -0
- package/dist/registry/tokens.js +207 -0
- package/dist/registry/tokens.js.map +1 -0
- package/dist/sdk.d.ts +45 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +99 -0
- package/dist/sdk.js.map +1 -0
- package/dist/sdk.test.d.ts +2 -0
- package/dist/sdk.test.d.ts.map +1 -0
- package/dist/sdk.test.js +43 -0
- package/dist/sdk.test.js.map +1 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/__tests__/merkle.test.d.ts +2 -0
- package/dist/utils/__tests__/merkle.test.d.ts.map +1 -0
- package/dist/utils/__tests__/merkle.test.js +65 -0
- package/dist/utils/__tests__/merkle.test.js.map +1 -0
- package/dist/utils/hex.d.ts +13 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +94 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +7 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/merkle.d.ts +15 -0
- package/dist/utils/merkle.d.ts.map +1 -0
- package/dist/utils/merkle.js +90 -0
- package/dist/utils/merkle.js.map +1 -0
- package/dist/wasm/__tests__/validation.test.d.ts +2 -0
- package/dist/wasm/__tests__/validation.test.d.ts.map +1 -0
- package/dist/wasm/__tests__/validation.test.js +37 -0
- package/dist/wasm/__tests__/validation.test.js.map +1 -0
- package/dist/wasm/artifacts.d.ts +31 -0
- package/dist/wasm/artifacts.d.ts.map +1 -0
- package/dist/wasm/artifacts.js +70 -0
- package/dist/wasm/artifacts.js.map +1 -0
- package/dist/wasm/index.d.ts +69 -0
- package/dist/wasm/index.d.ts.map +1 -0
- package/dist/wasm/index.js +504 -0
- package/dist/wasm/index.js.map +1 -0
- package/dist/zkp/__tests__/proofUtils.test.d.ts +2 -0
- package/dist/zkp/__tests__/proofUtils.test.d.ts.map +1 -0
- package/dist/zkp/__tests__/proofUtils.test.js +19 -0
- package/dist/zkp/__tests__/proofUtils.test.js.map +1 -0
- package/dist/zkp/__tests__/runNovaProver.test.d.ts +2 -0
- package/dist/zkp/__tests__/runNovaProver.test.d.ts.map +1 -0
- package/dist/zkp/__tests__/runNovaProver.test.js +112 -0
- package/dist/zkp/__tests__/runNovaProver.test.js.map +1 -0
- package/dist/zkp/index.d.ts +3 -0
- package/dist/zkp/index.d.ts.map +1 -0
- package/dist/zkp/index.js +3 -0
- package/dist/zkp/index.js.map +1 -0
- package/dist/zkp/proofService.d.ts +12 -0
- package/dist/zkp/proofService.d.ts.map +1 -0
- package/dist/zkp/proofService.js +140 -0
- package/dist/zkp/proofService.js.map +1 -0
- package/dist/zkp/proofUtils.d.ts +7 -0
- package/dist/zkp/proofUtils.d.ts.map +1 -0
- package/dist/zkp/proofUtils.js +61 -0
- package/dist/zkp/proofUtils.js.map +1 -0
- package/dist/zkp/worker.d.ts +2 -0
- package/dist/zkp/worker.d.ts.map +1 -0
- package/dist/zkp/worker.js +49 -0
- package/dist/zkp/worker.js.map +1 -0
- package/dist/zkp/workerClient.d.ts +5 -0
- package/dist/zkp/workerClient.d.ts.map +1 -0
- package/dist/zkp/workerClient.js +80 -0
- package/dist/zkp/workerClient.js.map +1 -0
- package/dist/zkp/workerTypes.d.ts +37 -0
- package/dist/zkp/workerTypes.d.ts.map +1 -0
- package/dist/zkp/workerTypes.js +2 -0
- package/dist/zkp/workerTypes.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../../src/wasm/artifacts.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,QAAQ,EAAE,UAAU,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,2BAA2B,CAAC;IACpC,KAAK,EAAE,0BAA0B,CAAC;CACnC;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,KAAK,uBAAuB,GACxB,CAAC,MAAM,OAAO,CAAC,qBAAqB,CAAC,CAAC,GACtC,CAAC,MAAM,qBAAqB,CAAC,CAAC;AAalC,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAGtF;AAED,wBAAgB,2BAA2B,IAAI,IAAI,CAElD;AAED,wBAAgB,0BAA0B,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAE9D;AAED,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,qBAAqB,GAAG,IAAI,CAI7E;AAED,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,2BAA2B,GAAG,IAAI,CAEzF;AAED,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,0BAA0B,GAAG,IAAI,CAEvF;AAmBD,wBAAsB,qBAAqB,CACzC,QAAQ,GAAE,4BAAiC,GAC1C,OAAO,CAAC,qBAAqB,CAAC,CAShC;AAED,wBAAsB,2BAA2B,CAC/C,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,2BAA2B,CAAC,CAOtC;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,GAAE,4BAAiC,GACzC,OAAO,CAAC,0BAA0B,CAAC,CAOrC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
let artifactLoader;
|
|
2
|
+
let teleportArtifactsPromise;
|
|
3
|
+
let singleArtifactsPromise;
|
|
4
|
+
let batchArtifactsPromise;
|
|
5
|
+
function resetCaches() {
|
|
6
|
+
teleportArtifactsPromise = undefined;
|
|
7
|
+
singleArtifactsPromise = undefined;
|
|
8
|
+
batchArtifactsPromise = undefined;
|
|
9
|
+
}
|
|
10
|
+
export function configureTeleportArtifactsLoader(loader) {
|
|
11
|
+
artifactLoader = loader;
|
|
12
|
+
resetCaches();
|
|
13
|
+
}
|
|
14
|
+
export function clearTeleportArtifactsCache() {
|
|
15
|
+
resetCaches();
|
|
16
|
+
}
|
|
17
|
+
export function clearTeleportArtifactCache(_url) {
|
|
18
|
+
clearTeleportArtifactsCache();
|
|
19
|
+
}
|
|
20
|
+
export function primeTeleportArtifacts(artifacts) {
|
|
21
|
+
teleportArtifactsPromise = Promise.resolve(artifacts);
|
|
22
|
+
singleArtifactsPromise = Promise.resolve(artifacts.single);
|
|
23
|
+
batchArtifactsPromise = Promise.resolve(artifacts.batch);
|
|
24
|
+
}
|
|
25
|
+
export function primeSingleTeleportArtifacts(artifacts) {
|
|
26
|
+
singleArtifactsPromise = Promise.resolve(artifacts);
|
|
27
|
+
}
|
|
28
|
+
export function primeBatchTeleportArtifacts(artifacts) {
|
|
29
|
+
batchArtifactsPromise = Promise.resolve(artifacts);
|
|
30
|
+
}
|
|
31
|
+
function requireLoader() {
|
|
32
|
+
if (!artifactLoader) {
|
|
33
|
+
throw new Error("Teleport artifact loader is not configured. Call configureTeleportArtifactsLoader() first.");
|
|
34
|
+
}
|
|
35
|
+
return artifactLoader;
|
|
36
|
+
}
|
|
37
|
+
async function resolveTeleportArtifacts() {
|
|
38
|
+
if (!teleportArtifactsPromise) {
|
|
39
|
+
const loader = requireLoader();
|
|
40
|
+
teleportArtifactsPromise = Promise.resolve().then(() => loader());
|
|
41
|
+
}
|
|
42
|
+
return teleportArtifactsPromise;
|
|
43
|
+
}
|
|
44
|
+
export async function loadTeleportArtifacts(_options = {}) {
|
|
45
|
+
const artifacts = await resolveTeleportArtifacts();
|
|
46
|
+
if (!singleArtifactsPromise) {
|
|
47
|
+
singleArtifactsPromise = Promise.resolve(artifacts.single);
|
|
48
|
+
}
|
|
49
|
+
if (!batchArtifactsPromise) {
|
|
50
|
+
batchArtifactsPromise = Promise.resolve(artifacts.batch);
|
|
51
|
+
}
|
|
52
|
+
return artifacts;
|
|
53
|
+
}
|
|
54
|
+
export async function loadSingleTeleportArtifacts(options = {}) {
|
|
55
|
+
if (singleArtifactsPromise) {
|
|
56
|
+
return singleArtifactsPromise;
|
|
57
|
+
}
|
|
58
|
+
const promise = loadTeleportArtifacts(options).then((artifacts) => artifacts.single);
|
|
59
|
+
singleArtifactsPromise = promise;
|
|
60
|
+
return promise;
|
|
61
|
+
}
|
|
62
|
+
export async function loadBatchTeleportArtifacts(options = {}) {
|
|
63
|
+
if (batchArtifactsPromise) {
|
|
64
|
+
return batchArtifactsPromise;
|
|
65
|
+
}
|
|
66
|
+
const promise = loadTeleportArtifacts(options).then((artifacts) => artifacts.batch);
|
|
67
|
+
batchArtifactsPromise = promise;
|
|
68
|
+
return promise;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=artifacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts.js","sourceRoot":"","sources":["../../src/wasm/artifacts.ts"],"names":[],"mappings":"AA2BA,IAAI,cAAmD,CAAC;AACxD,IAAI,wBAAoE,CAAC;AACzE,IAAI,sBAAwE,CAAC;AAC7E,IAAI,qBAAsE,CAAC;AAE3E,SAAS,WAAW;IAClB,wBAAwB,GAAG,SAAS,CAAC;IACrC,sBAAsB,GAAG,SAAS,CAAC;IACnC,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,MAA+B;IAC9E,cAAc,GAAG,MAAM,CAAC;IACxB,WAAW,EAAE,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,WAAW,EAAE,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,IAAa;IACtD,2BAA2B,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,SAAgC;IACrE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtD,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3D,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,SAAsC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S,CAAC,MAAM,CAAC,CAAC;IACrF,sBAAsB,GAAG,OAAO,CAAC;IACjC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,UAAwC,EAAE;IAE1C,IAAI,qBAAqB,EAAE,CAAC;QAC1B,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IACD,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACpF,qBAAqB,GAAG,OAAO,CAAC;IAChC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SingleWithdrawWasm, WithdrawNovaWasm } from '../assets/wasm/web/zkerc20_wasm.js';
|
|
2
|
+
import { AggregationTreeState, BurnArtifacts, ChainEvents, FetchAggregationTreeStateParams, FetchLocalTeleportProofsParams, FetchTransferEventsParams, GenerateGlobalTeleportProofsParams, GlobalTeleportProofWithEvent, LocalTeleportProof, SecretAndTweak, SeparateEventsByEligibilityParams, SeparatedChainEvents } from '../types.js';
|
|
3
|
+
export interface WasmLocatorGlobal {
|
|
4
|
+
location?: {
|
|
5
|
+
origin?: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface WasmRuntimeOptions {
|
|
9
|
+
/** Direct URL to the wasm bundle. */
|
|
10
|
+
url?: string;
|
|
11
|
+
/** Base URL used to resolve the wasm file; relative paths rely on window.location.origin. */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Override filename when using a custom base. */
|
|
14
|
+
wasmFilename?: string;
|
|
15
|
+
/** Custom global object used when resolving relative base URLs (defaults to globalThis). */
|
|
16
|
+
globalObject?: WasmLocatorGlobal;
|
|
17
|
+
}
|
|
18
|
+
export declare class WasmRuntime {
|
|
19
|
+
private locator;
|
|
20
|
+
private overrideUrl?;
|
|
21
|
+
private initPromise?;
|
|
22
|
+
private wasmBindings?;
|
|
23
|
+
constructor(options?: WasmRuntimeOptions);
|
|
24
|
+
configure(options: WasmRuntimeOptions): void;
|
|
25
|
+
setOverrideUrl(url?: string): void;
|
|
26
|
+
ready(): Promise<void>;
|
|
27
|
+
getSeedMessage(): Promise<string>;
|
|
28
|
+
derivePaymentAdvice(seedHex: string, paymentAdviceIdHex: string, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
29
|
+
deriveInvoiceSingle(seedHex: string, invoiceIdHex: string, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
30
|
+
deriveInvoiceBatch(seedHex: string, invoiceIdHex: string, subId: number, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
31
|
+
buildFullBurnAddress(recipientChainId: bigint | number, recipientAddress: string, secretHex: string, tweakHex: string): Promise<BurnArtifacts>;
|
|
32
|
+
decodeFullBurnAddress(payloadHex: string): Promise<BurnArtifacts>;
|
|
33
|
+
generalRecipientFr(chainId: bigint | number, recipientAddress: string, tweakHex: string): Promise<string>;
|
|
34
|
+
aggregationRoot(snapshot: readonly string[]): Promise<string>;
|
|
35
|
+
aggregationMerkleProof(snapshot: readonly string[], index: number): Promise<string[]>;
|
|
36
|
+
fetchAggregationTreeState(params: FetchAggregationTreeStateParams): Promise<AggregationTreeState>;
|
|
37
|
+
fetchTransferEvents(params: FetchTransferEventsParams): Promise<ChainEvents[]>;
|
|
38
|
+
separateEventsByEligibility(params: SeparateEventsByEligibilityParams): Promise<SeparatedChainEvents[]>;
|
|
39
|
+
fetchLocalTeleportMerkleProofs(params: FetchLocalTeleportProofsParams): Promise<LocalTeleportProof[]>;
|
|
40
|
+
generateGlobalTeleportMerkleProofs(params: GenerateGlobalTeleportProofsParams): Promise<GlobalTeleportProofWithEvent[]>;
|
|
41
|
+
createSingleWithdrawProgram(localPk: Uint8Array, localVk: Uint8Array, globalPk: Uint8Array, globalVk: Uint8Array): Promise<SingleWithdrawWasm>;
|
|
42
|
+
createWithdrawNovaProgram(localPp: Uint8Array, localVp: Uint8Array, globalPp: Uint8Array, globalVp: Uint8Array): Promise<WithdrawNovaWasm>;
|
|
43
|
+
private ensureReady;
|
|
44
|
+
private readyBindings;
|
|
45
|
+
private getBindings;
|
|
46
|
+
private initialize;
|
|
47
|
+
private resolveCandidateUrls;
|
|
48
|
+
private resolveConfiguredUrl;
|
|
49
|
+
}
|
|
50
|
+
export declare function getDefaultWasmRuntime(): WasmRuntime;
|
|
51
|
+
export declare function configureWasmLocator(options?: WasmRuntimeOptions): void;
|
|
52
|
+
export declare function getSeedMessage(): Promise<string>;
|
|
53
|
+
export declare function derivePaymentAdvice(seedHex: string, paymentAdviceIdHex: string, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
54
|
+
export declare function deriveInvoiceSingle(seedHex: string, invoiceIdHex: string, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
55
|
+
export declare function deriveInvoiceBatch(seedHex: string, invoiceIdHex: string, subId: number, recipientChainId: bigint | number, recipientAddress: string): Promise<SecretAndTweak>;
|
|
56
|
+
export declare function buildFullBurnAddress(recipientChainId: bigint | number, recipientAddress: string, secretHex: string, tweakHex: string): Promise<BurnArtifacts>;
|
|
57
|
+
export declare function decodeFullBurnAddress(payloadHex: string): Promise<BurnArtifacts>;
|
|
58
|
+
export declare function generalRecipientFr(chainId: bigint | number, recipientAddress: string, tweakHex: string): Promise<string>;
|
|
59
|
+
export declare function aggregationRoot(snapshot: readonly string[]): Promise<string>;
|
|
60
|
+
export declare function aggregationMerkleProof(snapshot: readonly string[], index: number): Promise<string[]>;
|
|
61
|
+
export declare function fetchAggregationTreeState(params: FetchAggregationTreeStateParams): Promise<AggregationTreeState>;
|
|
62
|
+
export declare function fetchTransferEvents(params: FetchTransferEventsParams): Promise<ChainEvents[]>;
|
|
63
|
+
export declare function separateEventsByEligibility(params: SeparateEventsByEligibilityParams): Promise<SeparatedChainEvents[]>;
|
|
64
|
+
export declare function fetchLocalTeleportMerkleProofs(params: FetchLocalTeleportProofsParams): Promise<LocalTeleportProof[]>;
|
|
65
|
+
export declare function generateGlobalTeleportMerkleProofs(params: GenerateGlobalTeleportProofsParams): Promise<GlobalTeleportProofWithEvent[]>;
|
|
66
|
+
export declare function createSingleWithdrawWasm(localPk: Uint8Array, localVk: Uint8Array, globalPk: Uint8Array, globalVk: Uint8Array): Promise<SingleWithdrawWasm>;
|
|
67
|
+
export declare function createWithdrawNovaWasm(localPp: Uint8Array, localVp: Uint8Array, globalPp: Uint8Array, globalVp: Uint8Array): Promise<WithdrawNovaWasm>;
|
|
68
|
+
export type { SingleWithdrawWasm, WithdrawNovaWasm };
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAE/F,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,WAAW,EAGX,+BAA+B,EAC/B,8BAA8B,EAC9B,yBAAyB,EACzB,kCAAkC,EAClC,4BAA4B,EAG5B,kBAAkB,EAClB,cAAc,EACd,iCAAiC,EACjC,oBAAoB,EAErB,MAAM,aAAa,CAAC;AA+DrB,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4FAA4F;IAC5F,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED,qBAAa,WAAW;IACtB,O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AAO,CAAC,WAAW,EAAE,CAAC,CAEnG;AAED,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAEjC;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAE/B;AAED,wBAAsB,kCAAkC,CACtD,MAAM,EAAE,kCAAkC,GACzC,OAAO,CAAC,4BAA4B,EAAE,CAAC,CAEzC;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAE7B;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAE3B;AAoUD,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { normalizeHex, toBigInt } from '../utils/hex.js';
|
|
2
|
+
import { NUM_BATCH_INVOICES } from '../constants.js';
|
|
3
|
+
const DEFAULT_WASM_FILENAME = 'assets/wasm/web/zkerc20_wasm_bg.wasm';
|
|
4
|
+
const BUNDLED_WASM_URL = new URL('../assets/wasm/web/zkerc20_wasm_bg.wasm', import.meta.url).toString();
|
|
5
|
+
let bindingsCache;
|
|
6
|
+
let bindingsPromise;
|
|
7
|
+
function isNodeRuntime() {
|
|
8
|
+
return typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
|
9
|
+
}
|
|
10
|
+
async function getOrLoadBindings() {
|
|
11
|
+
if (bindingsCache) {
|
|
12
|
+
return bindingsCache;
|
|
13
|
+
}
|
|
14
|
+
if (!bindingsPromise) {
|
|
15
|
+
bindingsPromise = resolveBindings();
|
|
16
|
+
}
|
|
17
|
+
bindingsCache = await bindingsPromise;
|
|
18
|
+
return bindingsCache;
|
|
19
|
+
}
|
|
20
|
+
async function resolveBindings() {
|
|
21
|
+
if (isNodeRuntime()) {
|
|
22
|
+
return loadNodeBindings();
|
|
23
|
+
}
|
|
24
|
+
return import('../assets/wasm/web/zkerc20_wasm.js');
|
|
25
|
+
}
|
|
26
|
+
async function loadNodeBindings() {
|
|
27
|
+
const { createRequire } = await loadNodeModule();
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
return require('../assets/wasm/node/zkerc20_wasm.js');
|
|
30
|
+
}
|
|
31
|
+
async function loadNodeModule() {
|
|
32
|
+
const specifiers = ['node:module', 'module'];
|
|
33
|
+
let lastError;
|
|
34
|
+
for (const specifier of specifiers) {
|
|
35
|
+
try {
|
|
36
|
+
const mod = (await import(specifier));
|
|
37
|
+
return mod;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
lastError = error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
throw lastError ?? new Error('failed to load node:module for wasm bindings');
|
|
44
|
+
}
|
|
45
|
+
function requiresExplicitInit(bindings) {
|
|
46
|
+
return typeof bindings.default === 'function';
|
|
47
|
+
}
|
|
48
|
+
export class WasmRuntime {
|
|
49
|
+
locator;
|
|
50
|
+
overrideUrl;
|
|
51
|
+
initPromise;
|
|
52
|
+
wasmBindings;
|
|
53
|
+
constructor(options = {}) {
|
|
54
|
+
this.locator = { ...options };
|
|
55
|
+
this.overrideUrl = normalizeOverride(options.url);
|
|
56
|
+
}
|
|
57
|
+
configure(options) {
|
|
58
|
+
this.locator = { ...options };
|
|
59
|
+
this.overrideUrl = normalizeOverride(options.url);
|
|
60
|
+
this.initPromise = undefined;
|
|
61
|
+
}
|
|
62
|
+
setOverrideUrl(url) {
|
|
63
|
+
this.overrideUrl = normalizeOverride(url);
|
|
64
|
+
this.initPromise = undefined;
|
|
65
|
+
}
|
|
66
|
+
async ready() {
|
|
67
|
+
await this.ensureReady();
|
|
68
|
+
}
|
|
69
|
+
async getSeedMessage() {
|
|
70
|
+
const wasm = await this.readyBindings();
|
|
71
|
+
return wasm.seed_message();
|
|
72
|
+
}
|
|
73
|
+
async derivePaymentAdvice(seedHex, paymentAdviceIdHex, recipientChainId, recipientAddress) {
|
|
74
|
+
const wasm = await this.readyBindings();
|
|
75
|
+
return asSecretAndTweak(wasm.derive_payment_advice(normalizeHex(seedHex), normalizeHex(paymentAdviceIdHex), toBigInt(recipientChainId), normalizeHex(recipientAddress)));
|
|
76
|
+
}
|
|
77
|
+
async deriveInvoiceSingle(seedHex, invoiceIdHex, recipientChainId, recipientAddress) {
|
|
78
|
+
const wasm = await this.readyBindings();
|
|
79
|
+
return asSecretAndTweak(wasm.derive_invoice_single(normalizeHex(seedHex), normalizeHex(invoiceIdHex), toBigInt(recipientChainId), normalizeHex(recipientAddress)));
|
|
80
|
+
}
|
|
81
|
+
async deriveInvoiceBatch(seedHex, invoiceIdHex, subId, recipientChainId, recipientAddress) {
|
|
82
|
+
assertValidInvoiceSubId(subId);
|
|
83
|
+
const wasm = await this.readyBindings();
|
|
84
|
+
return asSecretAndTweak(wasm.derive_invoice_batch(normalizeHex(seedHex), normalizeHex(invoiceIdHex), subId, toBigInt(recipientChainId), normalizeHex(recipientAddress)));
|
|
85
|
+
}
|
|
86
|
+
async buildFullBurnAddress(recipientChainId, recipientAddress, secretHex, tweakHex) {
|
|
87
|
+
const wasm = await this.readyBindings();
|
|
88
|
+
const result = wasm.build_full_burn_address(toBigInt(recipientChainId), normalizeHex(recipientAddress), normalizeHex(secretHex), normalizeHex(tweakHex));
|
|
89
|
+
return asBurnArtifacts(result);
|
|
90
|
+
}
|
|
91
|
+
async decodeFullBurnAddress(payloadHex) {
|
|
92
|
+
const wasm = await this.readyBindings();
|
|
93
|
+
return asBurnArtifacts(wasm.decode_full_burn_address(normalizeHex(payloadHex)));
|
|
94
|
+
}
|
|
95
|
+
async generalRecipientFr(chainId, recipientAddress, tweakHex) {
|
|
96
|
+
const wasm = await this.readyBindings();
|
|
97
|
+
return normalizeHex(wasm.general_recipient_fr(toBigInt(chainId), normalizeHex(recipientAddress), normalizeHex(tweakHex)));
|
|
98
|
+
}
|
|
99
|
+
async aggregationRoot(snapshot) {
|
|
100
|
+
const wasm = await this.readyBindings();
|
|
101
|
+
return normalizeHex(wasm.aggregation_root(snapshot.slice()));
|
|
102
|
+
}
|
|
103
|
+
async aggregationMerkleProof(snapshot, index) {
|
|
104
|
+
const wasm = await this.readyBindings();
|
|
105
|
+
const siblings = wasm.aggregation_merkle_proof(snapshot.slice(), index);
|
|
106
|
+
return siblings.map((value) => normalizeHex(value));
|
|
107
|
+
}
|
|
108
|
+
async fetchAggregationTreeState(params) {
|
|
109
|
+
const payload = {
|
|
110
|
+
hub: serializeHubEntry(params.hub),
|
|
111
|
+
token: serializeTokenEntry(params.token),
|
|
112
|
+
};
|
|
113
|
+
if (params.eventBlockSpan !== undefined) {
|
|
114
|
+
payload.eventBlockSpan = toSafeNumber(params.eventBlockSpan, 'eventBlockSpan');
|
|
115
|
+
}
|
|
116
|
+
const wasm = await this.readyBindings();
|
|
117
|
+
const rawState = await wasm.fetch_aggregation_tree_state(payload);
|
|
118
|
+
return deserializeAggregationTreeState(rawState);
|
|
119
|
+
}
|
|
120
|
+
async fetchTransferEvents(params) {
|
|
121
|
+
const payload = {
|
|
122
|
+
indexerUrl: params.indexerUrl,
|
|
123
|
+
indexerFetchLimit: params.indexerFetchLimit,
|
|
124
|
+
tokens: params.tokens.map(serializeTokenEntry),
|
|
125
|
+
burnAddresses: params.burnAddresses.map((address) => normalizeHex(address)),
|
|
126
|
+
};
|
|
127
|
+
const wasm = await this.readyBindings();
|
|
128
|
+
const rawEvents = await wasm.fetch_transfer_events(payload);
|
|
129
|
+
return rawEvents.map((entry) => deserializeChainEvents(entry));
|
|
130
|
+
}
|
|
131
|
+
async separateEventsByEligibility(params) {
|
|
132
|
+
const payload = {
|
|
133
|
+
aggregationState: serializeAggregationTreeState(params.aggregationState),
|
|
134
|
+
events: params.events.map(serializeChainEvents),
|
|
135
|
+
};
|
|
136
|
+
const wasm = await this.readyBindings();
|
|
137
|
+
const rawSeparated = wasm.separate_events_by_eligibility(payload);
|
|
138
|
+
return rawSeparated.map((entry) => deserializeSeparatedChainEvents(entry));
|
|
139
|
+
}
|
|
140
|
+
async fetchLocalTeleportMerkleProofs(params) {
|
|
141
|
+
const payload = {
|
|
142
|
+
indexerUrl: params.indexerUrl,
|
|
143
|
+
token: serializeTokenEntry(params.token),
|
|
144
|
+
treeIndex: toBigInt(params.treeIndex),
|
|
145
|
+
events: params.events.map(serializeIndexedEvent),
|
|
146
|
+
};
|
|
147
|
+
const wasm = await this.readyBindings();
|
|
148
|
+
const rawProofs = await wasm.fetch_local_teleport_merkle_proofs(payload);
|
|
149
|
+
return rawProofs.map((proof) => deserializeLocalTeleportProof(proof));
|
|
150
|
+
}
|
|
151
|
+
async generateGlobalTeleportMerkleProofs(params) {
|
|
152
|
+
const payload = {
|
|
153
|
+
aggregationState: serializeAggregationTreeState(params.aggregationState),
|
|
154
|
+
proofs: params.chains.map(serializeChainLocalTeleportProofs),
|
|
155
|
+
};
|
|
156
|
+
const wasm = await this.readyBindings();
|
|
157
|
+
const rawProofs = wasm.generate_global_teleport_merkle_proofs(payload);
|
|
158
|
+
return rawProofs.map((proof) => deserializeGlobalTeleportProof(proof));
|
|
159
|
+
}
|
|
160
|
+
async createSingleWithdrawProgram(localPk, localVk, globalPk, globalVk) {
|
|
161
|
+
const wasm = await this.readyBindings();
|
|
162
|
+
return new wasm.SingleWithdrawWasm(localPk, localVk, globalPk, globalVk);
|
|
163
|
+
}
|
|
164
|
+
async createWithdrawNovaProgram(localPp, localVp, globalPp, globalVp) {
|
|
165
|
+
const wasm = await this.readyBindings();
|
|
166
|
+
return new wasm.WithdrawNovaWasm(localPp, localVp, globalPp, globalVp);
|
|
167
|
+
}
|
|
168
|
+
async ensureReady() {
|
|
169
|
+
if (!this.initPromise) {
|
|
170
|
+
this.initPromise = this.initialize();
|
|
171
|
+
}
|
|
172
|
+
await this.initPromise;
|
|
173
|
+
}
|
|
174
|
+
async readyBindings() {
|
|
175
|
+
await this.ensureReady();
|
|
176
|
+
return this.getBindings();
|
|
177
|
+
}
|
|
178
|
+
getBindings() {
|
|
179
|
+
if (!this.wasmBindings) {
|
|
180
|
+
throw new Error('zkERC20 wasm bindings are not initialized');
|
|
181
|
+
}
|
|
182
|
+
return this.wasmBindings;
|
|
183
|
+
}
|
|
184
|
+
async initialize() {
|
|
185
|
+
const bindings = await getOrLoadBindings();
|
|
186
|
+
if (!requiresExplicitInit(bindings)) {
|
|
187
|
+
this.wasmBindings = bindings;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const candidates = this.resolveCandidateUrls();
|
|
191
|
+
let lastError;
|
|
192
|
+
for (let idx = 0; idx < candidates.length; idx++) {
|
|
193
|
+
const candidate = candidates[idx];
|
|
194
|
+
try {
|
|
195
|
+
await bindings.default({ module_or_path: candidate });
|
|
196
|
+
this.wasmBindings = bindings;
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
lastError = error;
|
|
201
|
+
if (idx < candidates.length - 1) {
|
|
202
|
+
logWasmFallbackWarning(candidate, error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
throw new Error(`failed to initialize zkERC20 wasm: ${formatError(lastError)}`);
|
|
207
|
+
}
|
|
208
|
+
resolveCandidateUrls() {
|
|
209
|
+
const urls = [];
|
|
210
|
+
if (this.overrideUrl) {
|
|
211
|
+
urls.push(this.overrideUrl);
|
|
212
|
+
}
|
|
213
|
+
const configured = this.resolveConfiguredUrl();
|
|
214
|
+
if (configured && configured !== this.overrideUrl) {
|
|
215
|
+
urls.push(configured);
|
|
216
|
+
}
|
|
217
|
+
if (!urls.includes(BUNDLED_WASM_URL)) {
|
|
218
|
+
urls.push(BUNDLED_WASM_URL);
|
|
219
|
+
}
|
|
220
|
+
return urls;
|
|
221
|
+
}
|
|
222
|
+
resolveConfiguredUrl() {
|
|
223
|
+
const baseUrl = this.locator.baseUrl;
|
|
224
|
+
if (!baseUrl) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const wasmFilename = this.locator.wasmFilename ?? DEFAULT_WASM_FILENAME;
|
|
228
|
+
if (/^https?:\/\//i.test(baseUrl)) {
|
|
229
|
+
return new URL(wasmFilename, ensureTrailingSlash(baseUrl)).toString();
|
|
230
|
+
}
|
|
231
|
+
const globalRef = this.locator.globalObject ?? (typeof globalThis !== 'undefined' ? globalThis : undefined);
|
|
232
|
+
const origin = globalRef?.location?.origin;
|
|
233
|
+
if (!origin) {
|
|
234
|
+
throw new Error('WasmRuntime requires a global location.origin when baseUrl is relative');
|
|
235
|
+
}
|
|
236
|
+
const prefix = baseUrl.startsWith('/') ? `${origin}${baseUrl}` : `${origin}/${baseUrl}`;
|
|
237
|
+
return new URL(wasmFilename, ensureTrailingSlash(prefix)).toString();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const defaultRuntime = new WasmRuntime();
|
|
241
|
+
function runtime() {
|
|
242
|
+
return defaultRuntime;
|
|
243
|
+
}
|
|
244
|
+
export function getDefaultWasmRuntime() {
|
|
245
|
+
return runtime();
|
|
246
|
+
}
|
|
247
|
+
export function configureWasmLocator(options = {}) {
|
|
248
|
+
runtime().configure(options);
|
|
249
|
+
}
|
|
250
|
+
export async function getSeedMessage() {
|
|
251
|
+
return runtime().getSeedMessage();
|
|
252
|
+
}
|
|
253
|
+
export async function derivePaymentAdvice(seedHex, paymentAdviceIdHex, recipientChainId, recipientAddress) {
|
|
254
|
+
return runtime().derivePaymentAdvice(seedHex, paymentAdviceIdHex, recipientChainId, recipientAddress);
|
|
255
|
+
}
|
|
256
|
+
export async function deriveInvoiceSingle(seedHex, invoiceIdHex, recipientChainId, recipientAddress) {
|
|
257
|
+
return runtime().deriveInvoiceSingle(seedHex, invoiceIdHex, recipientChainId, recipientAddress);
|
|
258
|
+
}
|
|
259
|
+
export async function deriveInvoiceBatch(seedHex, invoiceIdHex, subId, recipientChainId, recipientAddress) {
|
|
260
|
+
return runtime().deriveInvoiceBatch(seedHex, invoiceIdHex, subId, recipientChainId, recipientAddress);
|
|
261
|
+
}
|
|
262
|
+
export async function buildFullBurnAddress(recipientChainId, recipientAddress, secretHex, tweakHex) {
|
|
263
|
+
return runtime().buildFullBurnAddress(recipientChainId, recipientAddress, secretHex, tweakHex);
|
|
264
|
+
}
|
|
265
|
+
export async function decodeFullBurnAddress(payloadHex) {
|
|
266
|
+
return runtime().decodeFullBurnAddress(payloadHex);
|
|
267
|
+
}
|
|
268
|
+
export async function generalRecipientFr(chainId, recipientAddress, tweakHex) {
|
|
269
|
+
return runtime().generalRecipientFr(chainId, recipientAddress, tweakHex);
|
|
270
|
+
}
|
|
271
|
+
export async function aggregationRoot(snapshot) {
|
|
272
|
+
return runtime().aggregationRoot(snapshot);
|
|
273
|
+
}
|
|
274
|
+
export async function aggregationMerkleProof(snapshot, index) {
|
|
275
|
+
return runtime().aggregationMerkleProof(snapshot, index);
|
|
276
|
+
}
|
|
277
|
+
export async function fetchAggregationTreeState(params) {
|
|
278
|
+
return runtime().fetchAggregationTreeState(params);
|
|
279
|
+
}
|
|
280
|
+
export async function fetchTransferEvents(params) {
|
|
281
|
+
return runtime().fetchTransferEvents(params);
|
|
282
|
+
}
|
|
283
|
+
export async function separateEventsByEligibility(params) {
|
|
284
|
+
return runtime().separateEventsByEligibility(params);
|
|
285
|
+
}
|
|
286
|
+
export async function fetchLocalTeleportMerkleProofs(params) {
|
|
287
|
+
return runtime().fetchLocalTeleportMerkleProofs(params);
|
|
288
|
+
}
|
|
289
|
+
export async function generateGlobalTeleportMerkleProofs(params) {
|
|
290
|
+
return runtime().generateGlobalTeleportMerkleProofs(params);
|
|
291
|
+
}
|
|
292
|
+
export async function createSingleWithdrawWasm(localPk, localVk, globalPk, globalVk) {
|
|
293
|
+
return runtime().createSingleWithdrawProgram(localPk, localVk, globalPk, globalVk);
|
|
294
|
+
}
|
|
295
|
+
export async function createWithdrawNovaWasm(localPp, localVp, globalPp, globalVp) {
|
|
296
|
+
return runtime().createWithdrawNovaProgram(localPp, localVp, globalPp, globalVp);
|
|
297
|
+
}
|
|
298
|
+
function normalizeOverride(url) {
|
|
299
|
+
if (!url) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
const trimmed = url.trim();
|
|
303
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
304
|
+
}
|
|
305
|
+
function ensureTrailingSlash(value) {
|
|
306
|
+
return value.endsWith('/') ? value : `${value}/`;
|
|
307
|
+
}
|
|
308
|
+
function logWasmFallbackWarning(url, error) {
|
|
309
|
+
if (typeof console === 'undefined' || typeof console.warn !== 'function') {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
console.warn(`zkERC20 wasm failed to load from '${url}'. Falling back to the next candidate.`, error);
|
|
313
|
+
}
|
|
314
|
+
function formatError(error) {
|
|
315
|
+
if (!error) {
|
|
316
|
+
return 'unknown error';
|
|
317
|
+
}
|
|
318
|
+
if (error instanceof Error) {
|
|
319
|
+
return error.message;
|
|
320
|
+
}
|
|
321
|
+
return String(error);
|
|
322
|
+
}
|
|
323
|
+
function asSecretAndTweak(value) {
|
|
324
|
+
const candidate = value;
|
|
325
|
+
if (!candidate || typeof candidate.secret !== 'string' || typeof candidate.tweak !== 'string') {
|
|
326
|
+
throw new Error('unexpected secret/tweak payload from wasm');
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
secret: normalizeHex(candidate.secret),
|
|
330
|
+
tweak: normalizeHex(candidate.tweak),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function asBurnArtifacts(value) {
|
|
334
|
+
const raw = value;
|
|
335
|
+
if (!raw || typeof raw.burnAddress !== 'string' || typeof raw.secret !== 'string') {
|
|
336
|
+
throw new Error('unexpected burn artifacts payload from wasm');
|
|
337
|
+
}
|
|
338
|
+
const recipient = raw.generalRecipient;
|
|
339
|
+
if (!recipient || typeof recipient.address !== 'string') {
|
|
340
|
+
throw new Error('missing general recipient payload from wasm');
|
|
341
|
+
}
|
|
342
|
+
const tweakSource = raw.tweak ?? recipient.tweak;
|
|
343
|
+
if (typeof tweakSource !== 'string') {
|
|
344
|
+
throw new Error('missing burn tweak payload from wasm');
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
burnAddress: normalizeHex(raw.burnAddress),
|
|
348
|
+
fullBurnAddress: normalizeHex(raw.fullBurnAddress),
|
|
349
|
+
secret: normalizeHex(raw.secret),
|
|
350
|
+
tweak: normalizeHex(tweakSource),
|
|
351
|
+
generalRecipient: {
|
|
352
|
+
chainId: toBigInt(recipient.chainId ?? 0),
|
|
353
|
+
address: normalizeHex(recipient.address),
|
|
354
|
+
tweak: normalizeHex(recipient.tweak),
|
|
355
|
+
fr: normalizeHex(recipient.fr),
|
|
356
|
+
u256: normalizeHex(recipient.u256),
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function copyRpcUrls(urls, label) {
|
|
361
|
+
if (!Array.isArray(urls) || urls.length === 0) {
|
|
362
|
+
throw new Error(`${label} must provide at least one RPC URL`);
|
|
363
|
+
}
|
|
364
|
+
return urls.map((url, idx) => {
|
|
365
|
+
if (typeof url !== 'string' || url.trim().length === 0) {
|
|
366
|
+
throw new Error(`${label} RPC URL at index ${idx} must be a non-empty string`);
|
|
367
|
+
}
|
|
368
|
+
return url.trim();
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function serializeHubEntry(entry) {
|
|
372
|
+
return {
|
|
373
|
+
hub_address: normalizeHex(entry.hubAddress),
|
|
374
|
+
chain_id: entry.chainId,
|
|
375
|
+
rpc_urls: copyRpcUrls(entry.rpcUrls, 'hub.rpcUrls'),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function serializeTokenEntry(entry) {
|
|
379
|
+
return {
|
|
380
|
+
label: entry.label,
|
|
381
|
+
token_address: normalizeHex(entry.tokenAddress),
|
|
382
|
+
verifier_address: normalizeHex(entry.verifierAddress),
|
|
383
|
+
minter_address: entry.minterAddress ? normalizeHex(entry.minterAddress) : undefined,
|
|
384
|
+
chain_id: entry.chainId,
|
|
385
|
+
deployed_block_number: entry.deployedBlockNumber,
|
|
386
|
+
rpc_urls: copyRpcUrls(entry.rpcUrls, `${entry.label}.rpcUrls`),
|
|
387
|
+
legacy_tx: entry.legacyTx ?? false,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function serializeAggregationTreeState(state) {
|
|
391
|
+
return {
|
|
392
|
+
latestAggSeq: state.latestAggSeq,
|
|
393
|
+
aggregationRoot: normalizeHex(state.aggregationRoot),
|
|
394
|
+
snapshot: state.snapshot.map((value) => normalizeHex(value)),
|
|
395
|
+
transferTreeIndices: state.transferTreeIndices.map((value) => value),
|
|
396
|
+
chainIds: state.chainIds.map((value) => value),
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function deserializeAggregationTreeState(raw) {
|
|
400
|
+
return {
|
|
401
|
+
latestAggSeq: toBigInt(raw.latestAggSeq),
|
|
402
|
+
aggregationRoot: normalizeHex(raw.aggregationRoot),
|
|
403
|
+
snapshot: raw.snapshot.map((value) => normalizeHex(value)),
|
|
404
|
+
transferTreeIndices: raw.transferTreeIndices.map((value) => toBigInt(value)),
|
|
405
|
+
chainIds: raw.chainIds.map((value) => toBigInt(value)),
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function serializeIndexedEvent(event) {
|
|
409
|
+
return {
|
|
410
|
+
event_index: event.eventIndex,
|
|
411
|
+
from: normalizeHex(event.from),
|
|
412
|
+
to: normalizeHex(event.to),
|
|
413
|
+
value: normalizeHex(event.value),
|
|
414
|
+
eth_block_number: event.ethBlockNumber,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function deserializeIndexedEvent(raw) {
|
|
418
|
+
return {
|
|
419
|
+
eventIndex: toBigInt(raw.event_index),
|
|
420
|
+
from: normalizeHex(raw.from),
|
|
421
|
+
to: normalizeHex(raw.to),
|
|
422
|
+
value: toBigInt(raw.value),
|
|
423
|
+
ethBlockNumber: toBigInt(raw.eth_block_number),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function serializeChainEvents(entry) {
|
|
427
|
+
return {
|
|
428
|
+
chainId: entry.chainId,
|
|
429
|
+
events: entry.events.map(serializeIndexedEvent),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function deserializeChainEvents(raw) {
|
|
433
|
+
return {
|
|
434
|
+
chainId: toBigInt(raw.chainId),
|
|
435
|
+
events: raw.events.map(deserializeIndexedEvent),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function deserializeEventsWithEligibility(raw) {
|
|
439
|
+
return {
|
|
440
|
+
eligible: raw.eligible.map(deserializeIndexedEvent),
|
|
441
|
+
ineligible: raw.ineligible.map(deserializeIndexedEvent),
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function deserializeSeparatedChainEvents(raw) {
|
|
445
|
+
return {
|
|
446
|
+
chainId: toBigInt(raw.chainId),
|
|
447
|
+
events: deserializeEventsWithEligibility(raw.events),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function serializeLocalTeleportProof(proof) {
|
|
451
|
+
return {
|
|
452
|
+
treeIndex: proof.treeIndex,
|
|
453
|
+
event: serializeIndexedEvent(proof.event),
|
|
454
|
+
siblings: proof.siblings.map((value) => normalizeHex(value)),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function deserializeLocalTeleportProof(raw) {
|
|
458
|
+
return {
|
|
459
|
+
treeIndex: toBigInt(raw.treeIndex),
|
|
460
|
+
event: deserializeIndexedEvent(raw.event),
|
|
461
|
+
siblings: raw.siblings.map((value) => normalizeHex(value)),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function serializeChainLocalTeleportProofs(entry) {
|
|
465
|
+
return {
|
|
466
|
+
chainId: entry.chainId,
|
|
467
|
+
proofs: entry.proofs.map(serializeLocalTeleportProof),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function deserializeGlobalTeleportProof(raw) {
|
|
471
|
+
return {
|
|
472
|
+
event: deserializeIndexedEvent(raw.event),
|
|
473
|
+
siblings: raw.siblings.map((value) => normalizeHex(value)),
|
|
474
|
+
leafIndex: toBigInt(raw.leafIndex),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function assertValidInvoiceSubId(subId) {
|
|
478
|
+
if (!Number.isFinite(subId) || !Number.isInteger(subId)) {
|
|
479
|
+
throw new Error('subId must be a finite integer');
|
|
480
|
+
}
|
|
481
|
+
if (subId < 0 || subId >= NUM_BATCH_INVOICES) {
|
|
482
|
+
throw new Error(`subId must be between 0 and ${NUM_BATCH_INVOICES - 1}`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function toSafeNumber(value, label) {
|
|
486
|
+
if (typeof value === 'number') {
|
|
487
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
488
|
+
throw new Error(`${label} must be a finite integer`);
|
|
489
|
+
}
|
|
490
|
+
if (value < 0) {
|
|
491
|
+
throw new Error(`${label} must be non-negative`);
|
|
492
|
+
}
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
495
|
+
if (value < 0n) {
|
|
496
|
+
throw new Error(`${label} must be non-negative`);
|
|
497
|
+
}
|
|
498
|
+
const asNumber = Number(value);
|
|
499
|
+
if (!Number.isFinite(asNumber) || BigInt(asNumber) !== value) {
|
|
500
|
+
throw new Error(`${label} exceeds JavaScript safe integer range`);
|
|
501
|
+
}
|
|
502
|
+
return asNumber;
|
|
503
|
+
}
|
|
504
|
+
//# sourceMappingURL=index.js.map
|