@aptos-labs/confidential-assets-bindings 0.0.3 → 0.0.5

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.
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
2
  //#region build/wasm/aptos_confidential_asset_wasm.js
2
3
  /**
3
4
  * Result of a batch range proof generation
@@ -513,22 +514,34 @@ async function __wbg_init(module_or_path) {
513
514
  if (wasm !== void 0) return wasm;
514
515
  if (module_or_path !== void 0) if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
515
516
  else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
516
- if (module_or_path === void 0) module_or_path = new URL("aptos_confidential_asset_wasm_bg.wasm", import.meta.url);
517
+ if (module_or_path === void 0) module_or_path = new URL("aptos_confidential_asset_wasm_bg.wasm", require("url").pathToFileURL(__filename).href);
517
518
  const imports = __wbg_get_imports();
518
519
  if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
519
520
  const { instance, module } = await __wbg_load(await module_or_path, imports);
520
521
  return __wbg_finalize_init(instance, module);
521
522
  }
522
523
  //#endregion
523
- //#region src/index.browser.ts
524
- const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.2/dist/aptos_confidential_asset_wasm_bg.wasm`;
524
+ //#region src/index.ts
525
+ const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.5/dist/aptos_confidential_asset_wasm_bg.wasm`;
526
+ async function getNodeModulesWASM() {
527
+ try {
528
+ const fs = await import("fs");
529
+ const possiblePaths = [(await import("path")).resolve(process.cwd(), "node_modules/@aptos-labs/confidential-assets-bindings/dist/aptos_confidential_asset_wasm_bg.wasm"), new URL("./aptos_confidential_asset_wasm_bg.wasm", require("url").pathToFileURL(__filename).href).pathname];
530
+ for (const wasmPath of possiblePaths) if (fs.existsSync(wasmPath)) return fs.readFileSync(wasmPath);
531
+ } catch {}
532
+ return CDN_WASM_URL;
533
+ }
534
+ async function getWasmSource() {
535
+ if (typeof process !== "undefined" && process.versions?.node) return getNodeModulesWASM();
536
+ return CDN_WASM_URL;
537
+ }
525
538
  let initPromise;
526
539
  let initialized = false;
527
540
  async function ensureWasmInitialized() {
528
541
  if (initialized) return;
529
542
  if (!initPromise) initPromise = (async () => {
530
543
  try {
531
- await __wbg_init({ module_or_path: CDN_WASM_URL });
544
+ await __wbg_init({ module_or_path: await getWasmSource() });
532
545
  initialized = true;
533
546
  } catch (error) {
534
547
  initPromise = void 0;
@@ -541,23 +554,27 @@ const rangeProof = async (inputs) => {
541
554
  await ensureWasmInitialized();
542
555
  const { v, r, valBase, randBase, numBits = 32 } = inputs;
543
556
  const proof = range_proof(v, r, valBase, randBase, numBits);
544
- const output = {
545
- proof: proof.proof(),
546
- commitment: proof.comm()
547
- };
548
- proof.free();
549
- return output;
557
+ try {
558
+ return {
559
+ proof: proof.proof(),
560
+ commitment: proof.comm()
561
+ };
562
+ } finally {
563
+ proof.free();
564
+ }
550
565
  };
551
566
  const batchRangeProof = async (inputs) => {
552
567
  await ensureWasmInitialized();
553
568
  const { v, rs, valBase, randBase, numBits = 32 } = inputs;
554
569
  const proof = batch_range_proof(new BigUint64Array(v), rs, valBase, randBase, numBits);
555
- const output = {
556
- proof: proof.proof(),
557
- commitments: proof.comms()
558
- };
559
- proof.free();
560
- return output;
570
+ try {
571
+ return {
572
+ proof: proof.proof(),
573
+ commitments: proof.comms()
574
+ };
575
+ } finally {
576
+ proof.free();
577
+ }
561
578
  };
562
579
  const verifyProof = async (inputs) => {
563
580
  await ensureWasmInitialized();
@@ -569,7 +586,7 @@ const batchVerifyProof = async (inputs) => {
569
586
  const { proof, comms, valBase, randBase, numBits } = inputs;
570
587
  return batch_verify_proof(proof, comms, valBase, randBase, numBits);
571
588
  };
572
- let _discreteLogSolver;
589
+ let _discreteLogSolver = null;
573
590
  const getDiscreteLogSolver = () => {
574
591
  if (_discreteLogSolver) return _discreteLogSolver;
575
592
  return _discreteLogSolver = new DiscreteLogSolver();
@@ -579,4 +596,9 @@ const solveDiscreteLog = async (y, maxNumBits) => {
579
596
  return getDiscreteLogSolver().solve(y, maxNumBits);
580
597
  };
581
598
  //#endregion
582
- export { batchRangeProof, batchVerifyProof, ensureWasmInitialized, rangeProof, solveDiscreteLog, verifyProof };
599
+ exports.batchRangeProof = batchRangeProof;
600
+ exports.batchVerifyProof = batchVerifyProof;
601
+ exports.ensureWasmInitialized = ensureWasmInitialized;
602
+ exports.rangeProof = rangeProof;
603
+ exports.solveDiscreteLog = solveDiscreteLog;
604
+ exports.verifyProof = verifyProof;
@@ -1,4 +1,4 @@
1
- //#region src/index.node.d.ts
1
+ //#region src/index.d.ts
2
2
  declare function ensureWasmInitialized(): Promise<void>;
3
3
  interface RangeProofInputs {
4
4
  v: bigint;
@@ -16,7 +16,7 @@ interface BatchRangeProofInputs {
16
16
  rs: Uint8Array[];
17
17
  valBase: Uint8Array;
18
18
  randBase: Uint8Array;
19
- numBits: number;
19
+ numBits?: number;
20
20
  }
21
21
  declare const batchRangeProof: (inputs: BatchRangeProofInputs) => Promise<{
22
22
  proof: Uint8Array<ArrayBufferLike>;
@@ -1,4 +1,4 @@
1
- //#region src/index.node.d.ts
1
+ //#region src/index.d.ts
2
2
  declare function ensureWasmInitialized(): Promise<void>;
3
3
  interface RangeProofInputs {
4
4
  v: bigint;
@@ -16,7 +16,7 @@ interface BatchRangeProofInputs {
16
16
  rs: Uint8Array[];
17
17
  valBase: Uint8Array;
18
18
  randBase: Uint8Array;
19
- numBits: number;
19
+ numBits?: number;
20
20
  }
21
21
  declare const batchRangeProof: (inputs: BatchRangeProofInputs) => Promise<{
22
22
  proof: Uint8Array<ArrayBufferLike>;
@@ -1,5 +1,3 @@
1
- import fs from "fs";
2
- import path from "path";
3
1
  //#region build/wasm/aptos_confidential_asset_wasm.js
4
2
  /**
5
3
  * Result of a batch range proof generation
@@ -522,15 +520,20 @@ async function __wbg_init(module_or_path) {
522
520
  return __wbg_finalize_init(instance, module);
523
521
  }
524
522
  //#endregion
525
- //#region src/index.node.ts
526
- const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.2/dist/aptos_confidential_asset_wasm_bg.wasm`;
527
- async function getWasmSource() {
523
+ //#region src/index.ts
524
+ const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.5/dist/aptos_confidential_asset_wasm_bg.wasm`;
525
+ async function getNodeModulesWASM() {
528
526
  try {
529
- const possiblePaths = [path.resolve(process.cwd(), "node_modules/@aptos-labs/confidential-asset-wasm-bindings/aptos_confidential_asset_wasm_bg.wasm"), path.resolve(__dirname, "../../node_modules/@aptos-labs/confidential-asset-wasm-bindings/aptos_confidential_asset_wasm_bg.wasm")];
527
+ const fs = await import("fs");
528
+ const possiblePaths = [(await import("path")).resolve(process.cwd(), "node_modules/@aptos-labs/confidential-assets-bindings/dist/aptos_confidential_asset_wasm_bg.wasm"), new URL("./aptos_confidential_asset_wasm_bg.wasm", import.meta.url).pathname];
530
529
  for (const wasmPath of possiblePaths) if (fs.existsSync(wasmPath)) return fs.readFileSync(wasmPath);
531
530
  } catch {}
532
531
  return CDN_WASM_URL;
533
532
  }
533
+ async function getWasmSource() {
534
+ if (typeof process !== "undefined" && process.versions?.node) return getNodeModulesWASM();
535
+ return CDN_WASM_URL;
536
+ }
534
537
  let initPromise;
535
538
  let initialized = false;
536
539
  async function ensureWasmInitialized() {
@@ -550,23 +553,27 @@ const rangeProof = async (inputs) => {
550
553
  await ensureWasmInitialized();
551
554
  const { v, r, valBase, randBase, numBits = 32 } = inputs;
552
555
  const proof = range_proof(v, r, valBase, randBase, numBits);
553
- const output = {
554
- proof: proof.proof(),
555
- commitment: proof.comm()
556
- };
557
- proof.free();
558
- return output;
556
+ try {
557
+ return {
558
+ proof: proof.proof(),
559
+ commitment: proof.comm()
560
+ };
561
+ } finally {
562
+ proof.free();
563
+ }
559
564
  };
560
565
  const batchRangeProof = async (inputs) => {
561
566
  await ensureWasmInitialized();
562
567
  const { v, rs, valBase, randBase, numBits = 32 } = inputs;
563
568
  const proof = batch_range_proof(new BigUint64Array(v), rs, valBase, randBase, numBits);
564
- const output = {
565
- proof: proof.proof(),
566
- commitments: proof.comms()
567
- };
568
- proof.free();
569
- return output;
569
+ try {
570
+ return {
571
+ proof: proof.proof(),
572
+ commitments: proof.comms()
573
+ };
574
+ } finally {
575
+ proof.free();
576
+ }
570
577
  };
571
578
  const verifyProof = async (inputs) => {
572
579
  await ensureWasmInitialized();
@@ -578,7 +585,7 @@ const batchVerifyProof = async (inputs) => {
578
585
  const { proof, comms, valBase, randBase, numBits } = inputs;
579
586
  return batch_verify_proof(proof, comms, valBase, randBase, numBits);
580
587
  };
581
- let _discreteLogSolver;
588
+ let _discreteLogSolver = null;
582
589
  const getDiscreteLogSolver = () => {
583
590
  if (_discreteLogSolver) return _discreteLogSolver;
584
591
  return _discreteLogSolver = new DiscreteLogSolver();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptos-labs/confidential-assets-bindings",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Bindings for Aptos confidential assets (discrete log + range proofs)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -17,25 +17,20 @@
17
17
  ],
18
18
  "files": ["dist"],
19
19
  "type": "module",
20
- "main": "./dist/index.node.cjs",
21
- "module": "./dist/index.node.mjs",
22
- "browser": "./dist/index.browser.js",
23
- "types": "./dist/index.node.d.mts",
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.mts",
24
23
  "exports": {
25
24
  ".": {
26
- "browser": {
27
- "types": "./dist/index.browser.d.ts",
28
- "import": "./dist/index.browser.js"
29
- },
30
25
  "import": {
31
- "types": "./dist/index.node.d.mts",
32
- "default": "./dist/index.node.mjs"
26
+ "types": "./dist/index.d.mts",
27
+ "default": "./dist/index.mjs"
33
28
  },
34
29
  "require": {
35
- "types": "./dist/index.node.d.cts",
36
- "default": "./dist/index.node.cjs"
30
+ "types": "./dist/index.d.cts",
31
+ "default": "./dist/index.cjs"
37
32
  },
38
- "default": "./dist/index.node.mjs"
33
+ "default": "./dist/index.mjs"
39
34
  }
40
35
  },
41
36
  "scripts": {
@@ -1,43 +0,0 @@
1
- //#region src/index.browser.d.ts
2
- declare function ensureWasmInitialized(): Promise<void>;
3
- interface RangeProofInputs {
4
- v: bigint;
5
- r: Uint8Array;
6
- valBase: Uint8Array;
7
- randBase: Uint8Array;
8
- numBits?: number;
9
- }
10
- declare const rangeProof: (inputs: RangeProofInputs) => Promise<{
11
- proof: Uint8Array<ArrayBufferLike>;
12
- commitment: Uint8Array<ArrayBufferLike>;
13
- }>;
14
- interface BatchRangeProofInputs {
15
- v: bigint[];
16
- rs: Uint8Array[];
17
- valBase: Uint8Array;
18
- randBase: Uint8Array;
19
- numBits: number;
20
- }
21
- declare const batchRangeProof: (inputs: BatchRangeProofInputs) => Promise<{
22
- proof: Uint8Array<ArrayBufferLike>;
23
- commitments: Uint8Array<ArrayBufferLike>[];
24
- }>;
25
- interface VerifyRangeProofInputs {
26
- proof: Uint8Array;
27
- comm: Uint8Array;
28
- valBase: Uint8Array;
29
- randBase: Uint8Array;
30
- numBits?: number;
31
- }
32
- declare const verifyProof: (inputs: VerifyRangeProofInputs) => Promise<boolean>;
33
- interface BatchVerifyRangeProofInputs {
34
- proof: Uint8Array;
35
- comms: Uint8Array[];
36
- valBase: Uint8Array;
37
- randBase: Uint8Array;
38
- numBits: number;
39
- }
40
- declare const batchVerifyProof: (inputs: BatchVerifyRangeProofInputs) => Promise<boolean>;
41
- declare const solveDiscreteLog: (y: Uint8Array, maxNumBits: number) => Promise<bigint>;
42
- //#endregion
43
- export { BatchRangeProofInputs, BatchVerifyRangeProofInputs, RangeProofInputs, VerifyRangeProofInputs, batchRangeProof, batchVerifyProof, ensureWasmInitialized, rangeProof, solveDiscreteLog, verifyProof };
@@ -1,621 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
- let fs = require("fs");
25
- fs = __toESM(fs);
26
- let path = require("path");
27
- path = __toESM(path);
28
- //#region build/wasm/aptos_confidential_asset_wasm.js
29
- /**
30
- * Result of a batch range proof generation
31
- */
32
- var BatchRangeProof = class BatchRangeProof {
33
- static __wrap(ptr) {
34
- ptr = ptr >>> 0;
35
- const obj = Object.create(BatchRangeProof.prototype);
36
- obj.__wbg_ptr = ptr;
37
- BatchRangeProofFinalization.register(obj, obj.__wbg_ptr, obj);
38
- return obj;
39
- }
40
- __destroy_into_raw() {
41
- const ptr = this.__wbg_ptr;
42
- this.__wbg_ptr = 0;
43
- BatchRangeProofFinalization.unregister(this);
44
- return ptr;
45
- }
46
- free() {
47
- const ptr = this.__destroy_into_raw();
48
- wasm.__wbg_batchrangeproof_free(ptr, 0);
49
- }
50
- /**
51
- * Returns the serialized commitments (each 32 bytes)
52
- * @returns {Uint8Array[]}
53
- */
54
- comms() {
55
- const ret = wasm.batchrangeproof_comms(this.__wbg_ptr);
56
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
57
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
58
- return v1;
59
- }
60
- /**
61
- * Returns the serialized proof bytes
62
- * @returns {Uint8Array}
63
- */
64
- proof() {
65
- const ret = wasm.batchrangeproof_proof(this.__wbg_ptr);
66
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
67
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
68
- return v1;
69
- }
70
- };
71
- if (Symbol.dispose) BatchRangeProof.prototype[Symbol.dispose] = BatchRangeProof.prototype.free;
72
- /**
73
- * Discrete log solver supporting 16-bit and 32-bit secrets.
74
- */
75
- var DiscreteLogSolver = class {
76
- __destroy_into_raw() {
77
- const ptr = this.__wbg_ptr;
78
- this.__wbg_ptr = 0;
79
- DiscreteLogSolverFinalization.unregister(this);
80
- return ptr;
81
- }
82
- free() {
83
- const ptr = this.__destroy_into_raw();
84
- wasm.__wbg_discretelogsolver_free(ptr, 0);
85
- }
86
- /**
87
- * Returns the algorithm name.
88
- * @returns {string}
89
- */
90
- algorithm() {
91
- let deferred1_0;
92
- let deferred1_1;
93
- try {
94
- const ret = wasm.discretelogsolver_algorithm(this.__wbg_ptr);
95
- deferred1_0 = ret[0];
96
- deferred1_1 = ret[1];
97
- return getStringFromWasm0(ret[0], ret[1]);
98
- } finally {
99
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
100
- }
101
- }
102
- /**
103
- * Returns the supported bit sizes as an array [16, 32].
104
- * @returns {Uint8Array}
105
- */
106
- max_num_bits() {
107
- const ret = wasm.discretelogsolver_max_num_bits(this.__wbg_ptr);
108
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
109
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
110
- return v1;
111
- }
112
- /**
113
- * Creates a new solver with precomputed tables.
114
- */
115
- constructor() {
116
- this.__wbg_ptr = wasm.discretelogsolver_new() >>> 0;
117
- DiscreteLogSolverFinalization.register(this, this.__wbg_ptr, this);
118
- return this;
119
- }
120
- /**
121
- * Solves the discrete log problem.
122
- *
123
- * Given a compressed Ristretto point y = g^x (32 bytes), finds x.
124
- *
125
- * # Arguments
126
- * * `y` - The compressed Ristretto point (32 bytes)
127
- * * `max_num_bits` - Maximum bits of the secret: 16 or 32
128
- *
129
- * # Returns
130
- * The discrete log x, or an error if not found or invalid input.
131
- * @param {Uint8Array} y
132
- * @param {number} max_num_bits
133
- * @returns {bigint}
134
- */
135
- solve(y, max_num_bits) {
136
- const ptr0 = passArray8ToWasm0(y, wasm.__wbindgen_malloc);
137
- const len0 = WASM_VECTOR_LEN;
138
- const ret = wasm.discretelogsolver_solve(this.__wbg_ptr, ptr0, len0, max_num_bits);
139
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
140
- return BigInt.asUintN(64, ret[0]);
141
- }
142
- };
143
- if (Symbol.dispose) DiscreteLogSolver.prototype[Symbol.dispose] = DiscreteLogSolver.prototype.free;
144
- /**
145
- * Result of a single range proof generation
146
- */
147
- var SingleRangeProof = class SingleRangeProof {
148
- static __wrap(ptr) {
149
- ptr = ptr >>> 0;
150
- const obj = Object.create(SingleRangeProof.prototype);
151
- obj.__wbg_ptr = ptr;
152
- SingleRangeProofFinalization.register(obj, obj.__wbg_ptr, obj);
153
- return obj;
154
- }
155
- __destroy_into_raw() {
156
- const ptr = this.__wbg_ptr;
157
- this.__wbg_ptr = 0;
158
- SingleRangeProofFinalization.unregister(this);
159
- return ptr;
160
- }
161
- free() {
162
- const ptr = this.__destroy_into_raw();
163
- wasm.__wbg_singlerangeproof_free(ptr, 0);
164
- }
165
- /**
166
- * Returns the serialized commitment (32 bytes)
167
- * @returns {Uint8Array}
168
- */
169
- comm() {
170
- const ret = wasm.singlerangeproof_comm(this.__wbg_ptr);
171
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
172
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
173
- return v1;
174
- }
175
- /**
176
- * Returns the serialized proof bytes
177
- * @returns {Uint8Array}
178
- */
179
- proof() {
180
- const ret = wasm.singlerangeproof_proof(this.__wbg_ptr);
181
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
182
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
183
- return v1;
184
- }
185
- };
186
- if (Symbol.dispose) SingleRangeProof.prototype[Symbol.dispose] = SingleRangeProof.prototype.free;
187
- /**
188
- * Generate a batch range proof for multiple values.
189
- *
190
- * # Arguments
191
- * * `v` - The secret values to prove are in range [0, 2^num_bits)
192
- * * `rs` - The blinding factors (each 32-byte scalar)
193
- * * `val_base` - Value base point for Pedersen commitment (32-byte compressed point)
194
- * * `rand_base` - Randomness base point for Pedersen commitment (32-byte compressed point)
195
- * * `num_bits` - Bit length for range proof (8, 16, 32, or 64)
196
- * @param {BigUint64Array} v
197
- * @param {Uint8Array[]} rs
198
- * @param {Uint8Array} val_base
199
- * @param {Uint8Array} rand_base
200
- * @param {number} num_bits
201
- * @returns {BatchRangeProof}
202
- */
203
- function batch_range_proof(v, rs, val_base, rand_base, num_bits) {
204
- const ptr0 = passArray64ToWasm0(v, wasm.__wbindgen_malloc);
205
- const len0 = WASM_VECTOR_LEN;
206
- const ptr1 = passArrayJsValueToWasm0(rs, wasm.__wbindgen_malloc);
207
- const len1 = WASM_VECTOR_LEN;
208
- const ptr2 = passArray8ToWasm0(val_base, wasm.__wbindgen_malloc);
209
- const len2 = WASM_VECTOR_LEN;
210
- const ptr3 = passArray8ToWasm0(rand_base, wasm.__wbindgen_malloc);
211
- const len3 = WASM_VECTOR_LEN;
212
- const ret = wasm.batch_range_proof(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, num_bits);
213
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
214
- return BatchRangeProof.__wrap(ret[0]);
215
- }
216
- /**
217
- * Verify a batch range proof.
218
- * @param {Uint8Array} proof
219
- * @param {Uint8Array[]} comms
220
- * @param {Uint8Array} val_base
221
- * @param {Uint8Array} rand_base
222
- * @param {number} num_bits
223
- * @returns {boolean}
224
- */
225
- function batch_verify_proof(proof, comms, val_base, rand_base, num_bits) {
226
- const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
227
- const len0 = WASM_VECTOR_LEN;
228
- const ptr1 = passArrayJsValueToWasm0(comms, wasm.__wbindgen_malloc);
229
- const len1 = WASM_VECTOR_LEN;
230
- const ptr2 = passArray8ToWasm0(val_base, wasm.__wbindgen_malloc);
231
- const len2 = WASM_VECTOR_LEN;
232
- const ptr3 = passArray8ToWasm0(rand_base, wasm.__wbindgen_malloc);
233
- const len3 = WASM_VECTOR_LEN;
234
- const ret = wasm.batch_verify_proof(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, num_bits);
235
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
236
- return ret[0] !== 0;
237
- }
238
- /**
239
- * Generate a single range proof.
240
- *
241
- * # Arguments
242
- * * `v` - The secret value to prove is in range [0, 2^num_bits)
243
- * * `r` - The blinding factor (32-byte scalar)
244
- * * `val_base` - Value base point for Pedersen commitment (32-byte compressed point)
245
- * * `rand_base` - Randomness base point for Pedersen commitment (32-byte compressed point)
246
- * * `num_bits` - Bit length for range proof (8, 16, 32, or 64)
247
- * @param {bigint} v
248
- * @param {Uint8Array} r
249
- * @param {Uint8Array} val_base
250
- * @param {Uint8Array} rand_base
251
- * @param {number} num_bits
252
- * @returns {SingleRangeProof}
253
- */
254
- function range_proof(v, r, val_base, rand_base, num_bits) {
255
- const ptr0 = passArray8ToWasm0(r, wasm.__wbindgen_malloc);
256
- const len0 = WASM_VECTOR_LEN;
257
- const ptr1 = passArray8ToWasm0(val_base, wasm.__wbindgen_malloc);
258
- const len1 = WASM_VECTOR_LEN;
259
- const ptr2 = passArray8ToWasm0(rand_base, wasm.__wbindgen_malloc);
260
- const len2 = WASM_VECTOR_LEN;
261
- const ret = wasm.range_proof(v, ptr0, len0, ptr1, len1, ptr2, len2, num_bits);
262
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
263
- return SingleRangeProof.__wrap(ret[0]);
264
- }
265
- /**
266
- * Verify a single range proof.
267
- * @param {Uint8Array} proof
268
- * @param {Uint8Array} comm
269
- * @param {Uint8Array} val_base
270
- * @param {Uint8Array} rand_base
271
- * @param {number} num_bits
272
- * @returns {boolean}
273
- */
274
- function verify_proof(proof, comm, val_base, rand_base, num_bits) {
275
- const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
276
- const len0 = WASM_VECTOR_LEN;
277
- const ptr1 = passArray8ToWasm0(comm, wasm.__wbindgen_malloc);
278
- const len1 = WASM_VECTOR_LEN;
279
- const ptr2 = passArray8ToWasm0(val_base, wasm.__wbindgen_malloc);
280
- const len2 = WASM_VECTOR_LEN;
281
- const ptr3 = passArray8ToWasm0(rand_base, wasm.__wbindgen_malloc);
282
- const len3 = WASM_VECTOR_LEN;
283
- const ret = wasm.verify_proof(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, num_bits);
284
- if (ret[2]) throw takeFromExternrefTable0(ret[1]);
285
- return ret[0] !== 0;
286
- }
287
- function __wbg_get_imports() {
288
- const import0 = {
289
- __proto__: null,
290
- __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
291
- return Error(getStringFromWasm0(arg0, arg1));
292
- },
293
- __wbg___wbindgen_is_function_49868bde5eb1e745: function(arg0) {
294
- return typeof arg0 === "function";
295
- },
296
- __wbg___wbindgen_is_object_40c5a80572e8f9d3: function(arg0) {
297
- const val = arg0;
298
- return typeof val === "object" && val !== null;
299
- },
300
- __wbg___wbindgen_is_string_b29b5c5a8065ba1a: function(arg0) {
301
- return typeof arg0 === "string";
302
- },
303
- __wbg___wbindgen_is_undefined_c0cca72b82b86f4d: function(arg0) {
304
- return arg0 === void 0;
305
- },
306
- __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
307
- throw new Error(getStringFromWasm0(arg0, arg1));
308
- },
309
- __wbg_call_d578befcc3145dee: function() {
310
- return handleError(function(arg0, arg1, arg2) {
311
- return arg0.call(arg1, arg2);
312
- }, arguments);
313
- },
314
- __wbg_crypto_38df2bab126b63dc: function(arg0) {
315
- return arg0.crypto;
316
- },
317
- __wbg_error_38bec0a78dd8ded8: function(arg0) {
318
- console.error(arg0);
319
- },
320
- __wbg_getRandomValues_c44a50d8cfdaebeb: function() {
321
- return handleError(function(arg0, arg1) {
322
- arg0.getRandomValues(arg1);
323
- }, arguments);
324
- },
325
- __wbg_length_0c32cb8543c8e4c8: function(arg0) {
326
- return arg0.length;
327
- },
328
- __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
329
- return arg0.msCrypto;
330
- },
331
- __wbg_new_from_slice_2580ff33d0d10520: function(arg0, arg1) {
332
- return new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
333
- },
334
- __wbg_new_with_length_9cedd08484b73942: function(arg0) {
335
- return new Uint8Array(arg0 >>> 0);
336
- },
337
- __wbg_node_84ea875411254db1: function(arg0) {
338
- return arg0.node;
339
- },
340
- __wbg_process_44c7a14e11e9f69e: function(arg0) {
341
- return arg0.process;
342
- },
343
- __wbg_prototypesetcall_3e05eb9545565046: function(arg0, arg1, arg2) {
344
- Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
345
- },
346
- __wbg_randomFillSync_6c25eac9869eb53c: function() {
347
- return handleError(function(arg0, arg1) {
348
- arg0.randomFillSync(arg1);
349
- }, arguments);
350
- },
351
- __wbg_require_b4edbdcf3e2a1ef0: function() {
352
- return handleError(function() {
353
- return module.require;
354
- }, arguments);
355
- },
356
- __wbg_static_accessor_GLOBAL_THIS_a1248013d790bf5f: function() {
357
- const ret = typeof globalThis === "undefined" ? null : globalThis;
358
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
359
- },
360
- __wbg_static_accessor_GLOBAL_f2e0f995a21329ff: function() {
361
- const ret = typeof global === "undefined" ? null : global;
362
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
363
- },
364
- __wbg_static_accessor_SELF_24f78b6d23f286ea: function() {
365
- const ret = typeof self === "undefined" ? null : self;
366
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
367
- },
368
- __wbg_static_accessor_WINDOW_59fd959c540fe405: function() {
369
- const ret = typeof window === "undefined" ? null : window;
370
- return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
371
- },
372
- __wbg_subarray_0f98d3fb634508ad: function(arg0, arg1, arg2) {
373
- return arg0.subarray(arg1 >>> 0, arg2 >>> 0);
374
- },
375
- __wbg_versions_276b2795b1c6a219: function(arg0) {
376
- return arg0.versions;
377
- },
378
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
379
- return getArrayU8FromWasm0(arg0, arg1);
380
- },
381
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
382
- return getStringFromWasm0(arg0, arg1);
383
- },
384
- __wbindgen_init_externref_table: function() {
385
- const table = wasm.__wbindgen_externrefs;
386
- const offset = table.grow(4);
387
- table.set(0, void 0);
388
- table.set(offset + 0, void 0);
389
- table.set(offset + 1, null);
390
- table.set(offset + 2, true);
391
- table.set(offset + 3, false);
392
- }
393
- };
394
- return {
395
- __proto__: null,
396
- "./aptos_confidential_asset_wasm_bg.js": import0
397
- };
398
- }
399
- const BatchRangeProofFinalization = typeof FinalizationRegistry === "undefined" ? {
400
- register: () => {},
401
- unregister: () => {}
402
- } : new FinalizationRegistry((ptr) => wasm.__wbg_batchrangeproof_free(ptr >>> 0, 1));
403
- const DiscreteLogSolverFinalization = typeof FinalizationRegistry === "undefined" ? {
404
- register: () => {},
405
- unregister: () => {}
406
- } : new FinalizationRegistry((ptr) => wasm.__wbg_discretelogsolver_free(ptr >>> 0, 1));
407
- const SingleRangeProofFinalization = typeof FinalizationRegistry === "undefined" ? {
408
- register: () => {},
409
- unregister: () => {}
410
- } : new FinalizationRegistry((ptr) => wasm.__wbg_singlerangeproof_free(ptr >>> 0, 1));
411
- function addToExternrefTable0(obj) {
412
- const idx = wasm.__externref_table_alloc();
413
- wasm.__wbindgen_externrefs.set(idx, obj);
414
- return idx;
415
- }
416
- function getArrayJsValueFromWasm0(ptr, len) {
417
- ptr = ptr >>> 0;
418
- const mem = getDataViewMemory0();
419
- const result = [];
420
- for (let i = ptr; i < ptr + 4 * len; i += 4) result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
421
- wasm.__externref_drop_slice(ptr, len);
422
- return result;
423
- }
424
- function getArrayU8FromWasm0(ptr, len) {
425
- ptr = ptr >>> 0;
426
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
427
- }
428
- let cachedBigUint64ArrayMemory0 = null;
429
- function getBigUint64ArrayMemory0() {
430
- if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
431
- return cachedBigUint64ArrayMemory0;
432
- }
433
- let cachedDataViewMemory0 = null;
434
- function getDataViewMemory0() {
435
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
436
- return cachedDataViewMemory0;
437
- }
438
- function getStringFromWasm0(ptr, len) {
439
- ptr = ptr >>> 0;
440
- return decodeText(ptr, len);
441
- }
442
- let cachedUint8ArrayMemory0 = null;
443
- function getUint8ArrayMemory0() {
444
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
445
- return cachedUint8ArrayMemory0;
446
- }
447
- function handleError(f, args) {
448
- try {
449
- return f.apply(this, args);
450
- } catch (e) {
451
- const idx = addToExternrefTable0(e);
452
- wasm.__wbindgen_exn_store(idx);
453
- }
454
- }
455
- function isLikeNone(x) {
456
- return x === void 0 || x === null;
457
- }
458
- function passArray64ToWasm0(arg, malloc) {
459
- const ptr = malloc(arg.length * 8, 8) >>> 0;
460
- getBigUint64ArrayMemory0().set(arg, ptr / 8);
461
- WASM_VECTOR_LEN = arg.length;
462
- return ptr;
463
- }
464
- function passArray8ToWasm0(arg, malloc) {
465
- const ptr = malloc(arg.length * 1, 1) >>> 0;
466
- getUint8ArrayMemory0().set(arg, ptr / 1);
467
- WASM_VECTOR_LEN = arg.length;
468
- return ptr;
469
- }
470
- function passArrayJsValueToWasm0(array, malloc) {
471
- const ptr = malloc(array.length * 4, 4) >>> 0;
472
- for (let i = 0; i < array.length; i++) {
473
- const add = addToExternrefTable0(array[i]);
474
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
475
- }
476
- WASM_VECTOR_LEN = array.length;
477
- return ptr;
478
- }
479
- function takeFromExternrefTable0(idx) {
480
- const value = wasm.__wbindgen_externrefs.get(idx);
481
- wasm.__externref_table_dealloc(idx);
482
- return value;
483
- }
484
- let cachedTextDecoder = new TextDecoder("utf-8", {
485
- ignoreBOM: true,
486
- fatal: true
487
- });
488
- cachedTextDecoder.decode();
489
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
490
- let numBytesDecoded = 0;
491
- function decodeText(ptr, len) {
492
- numBytesDecoded += len;
493
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
494
- cachedTextDecoder = new TextDecoder("utf-8", {
495
- ignoreBOM: true,
496
- fatal: true
497
- });
498
- cachedTextDecoder.decode();
499
- numBytesDecoded = len;
500
- }
501
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
502
- }
503
- let WASM_VECTOR_LEN = 0, wasm;
504
- function __wbg_finalize_init(instance, module) {
505
- wasm = instance.exports;
506
- cachedBigUint64ArrayMemory0 = null;
507
- cachedDataViewMemory0 = null;
508
- cachedUint8ArrayMemory0 = null;
509
- wasm.__wbindgen_start();
510
- return wasm;
511
- }
512
- async function __wbg_load(module, imports) {
513
- if (typeof Response === "function" && module instanceof Response) {
514
- if (typeof WebAssembly.instantiateStreaming === "function") try {
515
- return await WebAssembly.instantiateStreaming(module, imports);
516
- } catch (e) {
517
- if (module.ok && expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
518
- else throw e;
519
- }
520
- const bytes = await module.arrayBuffer();
521
- return await WebAssembly.instantiate(bytes, imports);
522
- } else {
523
- const instance = await WebAssembly.instantiate(module, imports);
524
- if (instance instanceof WebAssembly.Instance) return {
525
- instance,
526
- module
527
- };
528
- else return instance;
529
- }
530
- function expectedResponseType(type) {
531
- switch (type) {
532
- case "basic":
533
- case "cors":
534
- case "default": return true;
535
- }
536
- return false;
537
- }
538
- }
539
- async function __wbg_init(module_or_path) {
540
- if (wasm !== void 0) return wasm;
541
- if (module_or_path !== void 0) if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
542
- else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
543
- if (module_or_path === void 0) module_or_path = new URL("aptos_confidential_asset_wasm_bg.wasm", require("url").pathToFileURL(__filename).href);
544
- const imports = __wbg_get_imports();
545
- if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
546
- const { instance, module } = await __wbg_load(await module_or_path, imports);
547
- return __wbg_finalize_init(instance, module);
548
- }
549
- //#endregion
550
- //#region src/index.node.ts
551
- const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.2/dist/aptos_confidential_asset_wasm_bg.wasm`;
552
- async function getWasmSource() {
553
- try {
554
- const possiblePaths = [path.default.resolve(process.cwd(), "node_modules/@aptos-labs/confidential-asset-wasm-bindings/aptos_confidential_asset_wasm_bg.wasm"), path.default.resolve(__dirname, "../../node_modules/@aptos-labs/confidential-asset-wasm-bindings/aptos_confidential_asset_wasm_bg.wasm")];
555
- for (const wasmPath of possiblePaths) if (fs.default.existsSync(wasmPath)) return fs.default.readFileSync(wasmPath);
556
- } catch {}
557
- return CDN_WASM_URL;
558
- }
559
- let initPromise;
560
- let initialized = false;
561
- async function ensureWasmInitialized() {
562
- if (initialized) return;
563
- if (!initPromise) initPromise = (async () => {
564
- try {
565
- await __wbg_init({ module_or_path: await getWasmSource() });
566
- initialized = true;
567
- } catch (error) {
568
- initPromise = void 0;
569
- throw error;
570
- }
571
- })();
572
- await initPromise;
573
- }
574
- const rangeProof = async (inputs) => {
575
- await ensureWasmInitialized();
576
- const { v, r, valBase, randBase, numBits = 32 } = inputs;
577
- const proof = range_proof(v, r, valBase, randBase, numBits);
578
- const output = {
579
- proof: proof.proof(),
580
- commitment: proof.comm()
581
- };
582
- proof.free();
583
- return output;
584
- };
585
- const batchRangeProof = async (inputs) => {
586
- await ensureWasmInitialized();
587
- const { v, rs, valBase, randBase, numBits = 32 } = inputs;
588
- const proof = batch_range_proof(new BigUint64Array(v), rs, valBase, randBase, numBits);
589
- const output = {
590
- proof: proof.proof(),
591
- commitments: proof.comms()
592
- };
593
- proof.free();
594
- return output;
595
- };
596
- const verifyProof = async (inputs) => {
597
- await ensureWasmInitialized();
598
- const { proof, comm, valBase, randBase, numBits = 32 } = inputs;
599
- return verify_proof(proof, comm, valBase, randBase, numBits);
600
- };
601
- const batchVerifyProof = async (inputs) => {
602
- await ensureWasmInitialized();
603
- const { proof, comms, valBase, randBase, numBits } = inputs;
604
- return batch_verify_proof(proof, comms, valBase, randBase, numBits);
605
- };
606
- let _discreteLogSolver;
607
- const getDiscreteLogSolver = () => {
608
- if (_discreteLogSolver) return _discreteLogSolver;
609
- return _discreteLogSolver = new DiscreteLogSolver();
610
- };
611
- const solveDiscreteLog = async (y, maxNumBits) => {
612
- await ensureWasmInitialized();
613
- return getDiscreteLogSolver().solve(y, maxNumBits);
614
- };
615
- //#endregion
616
- exports.batchRangeProof = batchRangeProof;
617
- exports.batchVerifyProof = batchVerifyProof;
618
- exports.ensureWasmInitialized = ensureWasmInitialized;
619
- exports.rangeProof = rangeProof;
620
- exports.solveDiscreteLog = solveDiscreteLog;
621
- exports.verifyProof = verifyProof;