@auditable/privacy-pool-zk-sdk 0.0.2-rc.8 → 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/assets/main.wasm +0 -0
- package/assets/main_final.zkey +0 -0
- package/assets/witness_calculator.js +2 -0
- package/dist/cli.js +1500 -417
- package/dist/cli.js.map +1 -1
- package/dist/ephemeral-key.d.ts +28 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +1238 -374
- package/dist/index.mjs.map +1 -1
- package/dist/sdk.d.ts +69 -8
- package/dist/shared-secret.d.ts +24 -0
- package/dist/stealth-address.d.ts +23 -0
- package/dist/stealth-sign-message.d.ts +7 -0
- package/dist/stealth-signature.d.ts +21 -0
- package/dist/types.d.ts +12 -1
- package/dist/withdrawal-transaction-input.d.ts +91 -0
- package/dist/witness.d.ts +2 -2
- package/package.json +10 -6
- package/pkg/client_sdk_wasm.d.ts +105 -0
- package/pkg/client_sdk_wasm.js +708 -0
- package/pkg/client_sdk_wasm_bg.wasm +0 -0
- package/pkg/client_sdk_wasm_bg.wasm.d.ts +19 -0
package/dist/types.d.ts
CHANGED
|
@@ -8,13 +8,24 @@ export interface GeneratedCoin {
|
|
|
8
8
|
coin: CoinData;
|
|
9
9
|
commitment_hex: string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/** Pool Merkle tree depth (matches `coin::TREE_DEPTH` / `Transaction` circuit). */
|
|
12
|
+
export declare const POOL_MERKLE_TREE_DEPTH = 20;
|
|
13
|
+
/** Default coin value in stroops (1 XLM); matches Rust `coin::COIN_VALUE`. */
|
|
14
|
+
export declare const COIN_VALUE_STROOPS = 1000000000;
|
|
15
|
+
/**
|
|
16
|
+
* Merkle path + coin fields for the first withdraw leg (WASM `buildWithdrawMerkleWitness`).
|
|
17
|
+
* Serde: `withdrawnValue`, `stateRoot`, `stateIndex`, `stateSiblings`.
|
|
18
|
+
*/
|
|
19
|
+
export interface WithdrawMerkleWitness {
|
|
20
|
+
/** Withdrawn amount in stroops as decimal Fr string; matches `coin.value`. */
|
|
12
21
|
withdrawnValue: string;
|
|
22
|
+
/** Coin value as decimal field string. */
|
|
13
23
|
value: string;
|
|
14
24
|
nullifier: string;
|
|
15
25
|
secret: string;
|
|
16
26
|
stateRoot: string;
|
|
17
27
|
stateIndex: string;
|
|
28
|
+
/** Length is always {@link POOL_MERKLE_TREE_DEPTH}; each entry is a decimal field element. */
|
|
18
29
|
stateSiblings: string[];
|
|
19
30
|
}
|
|
20
31
|
export interface StateFile {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { WithdrawMerkleWitness } from './types';
|
|
2
|
+
/** Matches `Transaction(20, 2, 2)` in `circuits/main.circom`. */
|
|
3
|
+
export declare const TRANSACTION_TREE_DEPTH = 20;
|
|
4
|
+
export declare const TRANSACTION_N_INS = 2;
|
|
5
|
+
export declare const TRANSACTION_N_OUTS = 2;
|
|
6
|
+
/** BN254 scalar field modulus (ark `Fr`, circom signals). */
|
|
7
|
+
export declare const BN254_SCALAR_MOD = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
8
|
+
/**
|
|
9
|
+
* BabyJub ECDH in `circuits/encryption.circom` uses `Num2Bits(253)`; scalars must be < 2^253
|
|
10
|
+
* (matches `libs/cryptography` `scalar_mul_253`).
|
|
11
|
+
*/
|
|
12
|
+
export declare const BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE: bigint;
|
|
13
|
+
export interface WithdrawalProofPublicParams {
|
|
14
|
+
/** Decimal string, circom `stateRoot`. */
|
|
15
|
+
stateRoot: string;
|
|
16
|
+
/** Decimal string, circom `withdrawAddressHi` (Ed25519 key bytes [0..16] as big-endian u128). */
|
|
17
|
+
withdrawAddressHi: string;
|
|
18
|
+
/** Decimal string, circom `withdrawAddressLo` (Ed25519 key bytes [16..32] as big-endian u128). */
|
|
19
|
+
withdrawAddressLo: string;
|
|
20
|
+
/** Decimal string, circom `privKeyScalar`. */
|
|
21
|
+
privKeyScalar: string;
|
|
22
|
+
}
|
|
23
|
+
/** Real withdraw leg; coordinates are decimal field strings (same as `CoinData`). */
|
|
24
|
+
export interface WithdrawObject {
|
|
25
|
+
value: string;
|
|
26
|
+
nullifier: string;
|
|
27
|
+
secret: string;
|
|
28
|
+
/** Depositor ECDH point `[x, y]` as decimal strings. */
|
|
29
|
+
ephemeralKeys: [string, string];
|
|
30
|
+
stateSiblings: string[];
|
|
31
|
+
stateIndex: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DepositObject {
|
|
34
|
+
value: string;
|
|
35
|
+
nullifier: string;
|
|
36
|
+
ephemeralKeyScalar: string;
|
|
37
|
+
/** Recipient public key `[x, y]` as decimal strings. */
|
|
38
|
+
recipientPublicKeys: [string, string];
|
|
39
|
+
}
|
|
40
|
+
export type WithdrawSlot = WithdrawObject | 'dummy';
|
|
41
|
+
export type DepositSlot = DepositObject | 'dummy';
|
|
42
|
+
/** Witness calculator input for `circuits/main.circom` `Transaction(20,2,2)`. */
|
|
43
|
+
export interface TransactionWitnessInput {
|
|
44
|
+
stateRoot: string;
|
|
45
|
+
withdrawAddressHi: string;
|
|
46
|
+
withdrawAddressLo: string;
|
|
47
|
+
privKeyScalar: string;
|
|
48
|
+
withdrawnValues: [string, string];
|
|
49
|
+
withdrawnNullifiers: [string, string];
|
|
50
|
+
withdrawnSecrets: [string, string];
|
|
51
|
+
ephemeralKeys: [[string, string], [string, string]];
|
|
52
|
+
stateSiblings: [string[], string[]];
|
|
53
|
+
stateIndex: [string, string];
|
|
54
|
+
depositedValues: [string, string];
|
|
55
|
+
depositedNullifiers: [string, string];
|
|
56
|
+
depositedEphemeralKeyScalars: [string, string];
|
|
57
|
+
depositedRecipientPublicKeys: [[string, string], [string, string]];
|
|
58
|
+
}
|
|
59
|
+
export interface WasmEcdhPointFns {
|
|
60
|
+
ecdhEphemeralPublicKeyFromScalarHex(scalarHex: string): {
|
|
61
|
+
x: string;
|
|
62
|
+
y: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** 32-byte field coordinate (hex, no 0x) → decimal string mod BN254 scalar field. */
|
|
66
|
+
export declare function coordHexToDecimal(hex: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* 32-byte big-endian scalar hex → decimal for circom `ephemeralKeyScalar` / ECDH `priv`.
|
|
69
|
+
* Integer must be < 2^253 (not reduced mod r — values ≥ 2^253 are rejected).
|
|
70
|
+
*/
|
|
71
|
+
export declare function scalarHexToFrDecimal(hex: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Stellar G-address Ed25519 payload (32 bytes as 64 hex, optional 0x) → two circom public decimals
|
|
74
|
+
* (`withdrawAddressHi` / `withdrawAddressLo`). No mod-r; each half fits in 128 bits.
|
|
75
|
+
*/
|
|
76
|
+
export declare function ed25519PubkeyPayloadHexToWithdrawFrDecimals(hex: string): {
|
|
77
|
+
hi: string;
|
|
78
|
+
lo: string;
|
|
79
|
+
};
|
|
80
|
+
/** Uniform random `Fr` as decimal (32 random bytes, mod r). For Poseidon-only inputs (e.g. nullifiers). */
|
|
81
|
+
export declare function randomFrDecimal(): string;
|
|
82
|
+
/** Random scalar < 2^253 for BabyJub ECDH / `Num2Bits(253)` (uses {@link generateRandomScalarHex32}). */
|
|
83
|
+
export declare function randomFrDecimal253(): string;
|
|
84
|
+
export declare function buildTransactionWitnessInput(publicParams: WithdrawalProofPublicParams, withdrawSlots: [WithdrawSlot, WithdrawSlot], depositSlots: [DepositSlot, DepositSlot], wasm: WasmEcdhPointFns): TransactionWitnessInput;
|
|
85
|
+
/** `stpl1…` stealth address → `[x, y]` as decimal field strings for `depositedRecipientPublicKeys`. */
|
|
86
|
+
export declare function recipientPublicKeysDecimalFromStealthAddress(stealthAddress: string): [string, string];
|
|
87
|
+
/** First withdraw leg: Merkle witness + depositor ECDH point coordinates (hex). */
|
|
88
|
+
export declare function withdrawObjectFromMerkleWitness(witness: WithdrawMerkleWitness, depositorEphemeralHex: {
|
|
89
|
+
x: string;
|
|
90
|
+
y: string;
|
|
91
|
+
}): WithdrawObject;
|
package/dist/witness.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function generateWitness(input:
|
|
1
|
+
import type { TransactionWitnessInput } from './withdrawal-transaction-input';
|
|
2
|
+
export declare function generateWitness(input: TransactionWitnessInput, circuitWasm?: BufferSource): Promise<Uint8Array>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auditable/privacy-pool-zk-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Client SDK for Soroban Privacy Pools - coin generation, withdrawal proofs, and proof serialization",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"bin": {
|
|
20
20
|
"client-sdk-cli": "./dist/cli.js"
|
|
21
21
|
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=19.0.0"
|
|
24
|
+
},
|
|
22
25
|
"repository": {
|
|
23
26
|
"type": "git",
|
|
24
27
|
"url": "https://github.com/Polynom-Labs/stellar-privacy-layer-contracts"
|
|
@@ -35,18 +38,19 @@
|
|
|
35
38
|
"cli": "node dist/cli.js"
|
|
36
39
|
},
|
|
37
40
|
"dependencies": {
|
|
41
|
+
"bech32": "^2.0.0",
|
|
38
42
|
"snarkjs": "^0.7.0"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
|
-
"rollup": "^4.0.0",
|
|
42
45
|
"@rollup/plugin-alias": "^5.0.0",
|
|
43
|
-
"@rollup/plugin-typescript": "^11.0.0",
|
|
44
|
-
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
45
46
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
46
47
|
"@rollup/plugin-json": "^6.0.0",
|
|
48
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
49
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
50
|
+
"@types/node": "^20.0.0",
|
|
51
|
+
"rollup": "^4.0.0",
|
|
47
52
|
"rollup-plugin-copy": "^3.5.0",
|
|
48
|
-
"typescript": "^5.0.0",
|
|
49
53
|
"tslib": "^2.6.0",
|
|
50
|
-
"
|
|
54
|
+
"typescript": "^5.0.0"
|
|
51
55
|
}
|
|
52
56
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Merkle root, path, and coin field strings for the first withdraw leg (JSON → JSON).
|
|
6
|
+
*/
|
|
7
|
+
export function buildWithdrawMerkleWitness(coin_json: string, state_json: string): string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculate nullifier hash from nullifier decimal string.
|
|
11
|
+
* Returns hex string (0x...)
|
|
12
|
+
*/
|
|
13
|
+
export function calculateNullifierHash(nullifier_decimal: string): string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* UTF-8 seed → `SHA256` → scalar → BabyJubJub `BASE8 * r` (circom `ECDHEphemeralKey`).
|
|
17
|
+
* `x` and `y` are lowercase hex (no `0x`). Bech32 / stealth string: TypeScript `encodeStealthAddress`.
|
|
18
|
+
*/
|
|
19
|
+
export function ecdhEphemeralPublicKey(seed: string): any;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 32-byte scalar as 64 hex chars (optional `0x`) → `ecdh_ephemeral_public_key` (no UTF-8 seed hash).
|
|
23
|
+
*/
|
|
24
|
+
export function ecdhEphemeralPublicKeyFromScalarHex(scalar_hex: string): any;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Circuit `ECDH`: `priv * (pub_x, pub_y)` → shared key (`key[0], key[1]` hex).
|
|
28
|
+
*/
|
|
29
|
+
export function ecdhSharedKey(priv_hex: string, pub_x_hex: string, pub_y_hex: string): any;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generate a new coin with random nullifier, secret, and shared-secret field elements.
|
|
33
|
+
* `amount` is stroops (u64); JS passes `bigint`.
|
|
34
|
+
* Returns JSON: { coin: { value, nullifier, secret, commitment }, commitment_hex }
|
|
35
|
+
*/
|
|
36
|
+
export function generateCoin(amount: bigint): any;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `Poseidon₁(scalar)` secret + fixed ECDH shared coords (hex), matching an aligned deposit witness.
|
|
40
|
+
*/
|
|
41
|
+
export function generateCoinForDepositWithSharedHex(scalar_hex: string, shared_x_hex: string, shared_y_hex: string, amount: bigint): any;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `secret` in coin = `Poseidon255(1)(scalar)` per `deposit.circom`; scalar is 32-byte hex (64 chars, optional `0x`).
|
|
45
|
+
*/
|
|
46
|
+
export function generateCoinFromDepositEphemeralScalarHex(scalar_hex: string, amount: bigint): any;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Same as `generateCoin`, but commitment uses the given ECDH shared key (64-char hex coords from `ecdhSharedKey`); shared coords are not stored in `coin` JSON.
|
|
50
|
+
*/
|
|
51
|
+
export function generateCoinWithSharedSecretHex(shared_x_hex: string, shared_y_hex: string, amount: bigint): any;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Convert snarkjs proof JSON to hex bytes for Soroban contract.
|
|
55
|
+
*/
|
|
56
|
+
export function proofToHex(proof_json: string): string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Convert snarkjs public signals JSON to hex bytes for Soroban contract.
|
|
60
|
+
*/
|
|
61
|
+
export function publicToHex(public_json: string): string;
|
|
62
|
+
|
|
63
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
64
|
+
|
|
65
|
+
export interface InitOutput {
|
|
66
|
+
readonly memory: WebAssembly.Memory;
|
|
67
|
+
readonly buildWithdrawMerkleWitness: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
68
|
+
readonly calculateNullifierHash: (a: number, b: number, c: number) => void;
|
|
69
|
+
readonly ecdhEphemeralPublicKey: (a: number, b: number, c: number) => void;
|
|
70
|
+
readonly ecdhEphemeralPublicKeyFromScalarHex: (a: number, b: number, c: number) => void;
|
|
71
|
+
readonly ecdhSharedKey: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
72
|
+
readonly generateCoin: (a: bigint) => number;
|
|
73
|
+
readonly generateCoinForDepositWithSharedHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint) => void;
|
|
74
|
+
readonly generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: bigint) => void;
|
|
75
|
+
readonly generateCoinWithSharedSecretHex: (a: number, b: number, c: number, d: number, e: number, f: bigint) => void;
|
|
76
|
+
readonly proofToHex: (a: number, b: number, c: number) => void;
|
|
77
|
+
readonly publicToHex: (a: number, b: number, c: number) => void;
|
|
78
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
79
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
80
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
81
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
82
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
89
|
+
* a precompiled `WebAssembly.Module`.
|
|
90
|
+
*
|
|
91
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
92
|
+
*
|
|
93
|
+
* @returns {InitOutput}
|
|
94
|
+
*/
|
|
95
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
99
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
100
|
+
*
|
|
101
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
102
|
+
*
|
|
103
|
+
* @returns {Promise<InitOutput>}
|
|
104
|
+
*/
|
|
105
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|