@aptos-labs/confidential-assets-bindings 0.0.5 → 0.0.7
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 +22 -39
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,60 +10,43 @@ npm install @aptos-labs/confidential-assets-bindings
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
import init, {
|
|
15
|
-
DiscreteLogSolver,
|
|
16
|
-
range_proof,
|
|
17
|
-
batch_range_proof,
|
|
18
|
-
verify_proof,
|
|
19
|
-
batch_verify_proof,
|
|
20
|
-
initializeWasm,
|
|
21
|
-
} from "@aptos-labs/confidential-assets-bindings";
|
|
22
|
-
|
|
23
|
-
// Initialize WASM module before calling any functions
|
|
24
|
-
await init();
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Node.js consumers do not need to call `initializeWasm()`; the runtime is loaded automatically.
|
|
13
|
+
No initialization required — WASM is loaded automatically on first use, from local `node_modules` in Node.js or from the versioned unpkg CDN in browsers.
|
|
28
14
|
|
|
29
15
|
### Discrete Log
|
|
30
16
|
|
|
31
17
|
Solves discrete logarithms on the Ristretto255 curve for 16-bit and 32-bit secrets. Used to decrypt confidential asset balances.
|
|
32
18
|
|
|
33
19
|
```typescript
|
|
34
|
-
|
|
20
|
+
import { solveDiscreteLog } from "@aptos-labs/confidential-assets-bindings";
|
|
35
21
|
|
|
36
22
|
// y is a compressed Ristretto point (32 bytes): y = g^x
|
|
37
|
-
//
|
|
38
|
-
const x: bigint =
|
|
39
|
-
|
|
40
|
-
console.log(solver.algorithm()); // e.g. "NaiveTruncatedDoubledLookup (16-bit) + TBSGS-k32 (32-bit)"
|
|
41
|
-
console.log(solver.max_num_bits()); // [16, 32]
|
|
23
|
+
// maxNumBits must be 16 or 32
|
|
24
|
+
const x: bigint = await solveDiscreteLog(y, 32);
|
|
42
25
|
```
|
|
43
26
|
|
|
44
27
|
### Range Proofs
|
|
45
28
|
|
|
46
|
-
Zero-knowledge range proofs using Bulletproofs. Proves a value lies in `[0, 2^
|
|
29
|
+
Zero-knowledge range proofs using Bulletproofs. Proves a value lies in `[0, 2^numBits)` without revealing it.
|
|
47
30
|
|
|
48
31
|
```typescript
|
|
49
|
-
|
|
32
|
+
import {
|
|
33
|
+
rangeProof,
|
|
34
|
+
batchRangeProof,
|
|
35
|
+
verifyProof,
|
|
36
|
+
batchVerifyProof,
|
|
37
|
+
} from "@aptos-labs/confidential-assets-bindings";
|
|
38
|
+
|
|
50
39
|
// r is a 32-byte blinding scalar
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const batchResult = batch_range_proof(values, blindings, val_base, rand_base, num_bits);
|
|
62
|
-
const batchProof: Uint8Array = batchResult.proof();
|
|
63
|
-
const commitments: Uint8Array[] = batchResult.comms(); // one per value
|
|
64
|
-
|
|
65
|
-
// Verify a batch range proof
|
|
66
|
-
const batchValid: boolean = batch_verify_proof(batchProof, commitments, val_base, rand_base, num_bits);
|
|
40
|
+
// valBase and randBase are 32-byte compressed Ristretto points (Pedersen bases)
|
|
41
|
+
// numBits must be 8, 16, 32, or 64 (default: 32)
|
|
42
|
+
const { proof, commitment } = await rangeProof({ v, r, valBase, randBase, numBits });
|
|
43
|
+
|
|
44
|
+
const valid = await verifyProof({ proof, comm: commitment, valBase, randBase, numBits });
|
|
45
|
+
|
|
46
|
+
// Batch variants
|
|
47
|
+
const { proof: batchProof, commitments } = await batchRangeProof({ v: values, rs: blindings, valBase, randBase, numBits });
|
|
48
|
+
|
|
49
|
+
const batchValid = await batchVerifyProof({ proof: batchProof, comms: commitments, valBase, randBase, numBits });
|
|
67
50
|
```
|
|
68
51
|
|
|
69
52
|
## Cross-Version Compatibility
|
package/dist/index.cjs
CHANGED
|
@@ -522,7 +522,7 @@ async function __wbg_init(module_or_path) {
|
|
|
522
522
|
}
|
|
523
523
|
//#endregion
|
|
524
524
|
//#region src/index.ts
|
|
525
|
-
const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.
|
|
525
|
+
const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.7/dist/aptos_confidential_asset_wasm_bg.wasm`;
|
|
526
526
|
async function getNodeModulesWASM() {
|
|
527
527
|
try {
|
|
528
528
|
const fs = await import("fs");
|
package/dist/index.mjs
CHANGED
|
@@ -521,7 +521,7 @@ async function __wbg_init(module_or_path) {
|
|
|
521
521
|
}
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region src/index.ts
|
|
524
|
-
const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.
|
|
524
|
+
const CDN_WASM_URL = `https://unpkg.com/@aptos-labs/confidential-assets-bindings@0.0.7/dist/aptos_confidential_asset_wasm_bg.wasm`;
|
|
525
525
|
async function getNodeModulesWASM() {
|
|
526
526
|
try {
|
|
527
527
|
const fs = await import("fs");
|