@auditable/privacy-pool-zk-sdk 0.0.2-rc.9 → 0.4.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/sdk.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import type { CoinData, GeneratedCoin, SDKOptions, SnarkInput, StateFile, WithdrawResult } from './types';
1
+ import { type DecodedDepositorSharedSecretPreimage, type DecodedEphemeralKey, type EncodedDepositorSharedSecretPreimage, type EncodedEphemeralKey } from './ephemeral-key';
2
+ import { type SharedSecret } from './shared-secret';
3
+ import type { DecodedRecipientSharedSecretPreimage } from './stealth-address';
4
+ import type { CoinData, GeneratedCoin, SDKOptions, StateFile, WithdrawMerkleWitness, WithdrawResult } from './types';
5
+ import { type DepositSlot, type TransactionPublicLegParams, type WithdrawalProofPublicParams, type WithdrawSlot } from './withdrawal-transaction-input';
2
6
  export declare class PrivacyPoolSDK {
3
7
  private wasm;
4
8
  private options;
@@ -18,13 +22,55 @@ export declare class PrivacyPoolSDK {
18
22
  */
19
23
  static init(options?: SDKOptions): Promise<PrivacyPoolSDK>;
20
24
  /**
21
- * Generate a new coin with random nullifier and secret.
25
+ * Uniform 32-byte scalar as lowercase hex (Web Crypto). Same in browser and Node 19+.
22
26
  */
23
- generateCoin(): GeneratedCoin;
27
+ static generateRandomScalarHex32(): string;
24
28
  /**
25
- * Generate withdrawal SNARK input from coin data and state.
29
+ * Text to sign with a Stellar wallet for stealth derivation (UTF-8). No WASM required.
26
30
  */
27
- generateWithdrawalInput(coin: CoinData, state: StateFile): SnarkInput;
31
+ static buildStealthAddressSignMessage(address: string, nonce?: string): string;
32
+ /**
33
+ * Generate a new coin with random nullifier, secret, and random shared-secret field elements (dev / self-contained tests).
34
+ * @param amount Stroops encoded as `bigint` or integer `number` (WASM `u64`).
35
+ * @param assetHiDecimal / assetLoDecimal Decimal Fr strings for Stellar asset contract id (two limbs).
36
+ */
37
+ generateCoin(amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string): GeneratedCoin;
38
+ /**
39
+ * Generate a coin with the same commitment shape as on-chain deposit: pass `ecdhSharedKey` output (hex x, y).
40
+ * @param amount Stroops (`bigint` | `number`).
41
+ */
42
+ generateCoinWithSharedSecret(shared: SharedSecret, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string): GeneratedCoin;
43
+ /**
44
+ * Coin for a depositor `ephemeralKeyScalar` (32-byte hex): `coin.secret = Poseidon255(1)(scalar)` as in `deposit.circom`.
45
+ * @param amount Stroops (`bigint` | `number`).
46
+ */
47
+ generateCoinFromDepositEphemeralScalarHex(scalarHex: string, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string): GeneratedCoin;
48
+ /**
49
+ * Aligned deposit coin: `secret = Poseidon₁(scalar)` and ECDH shared key from hex coords (e.g. `ecdhSharedKey(scalar, recipient_x, recipient_y)`).
50
+ * @param amount Stroops (`bigint` | `number`).
51
+ */
52
+ generateCoinForDepositWithSharedHex(scalarHex: string, sharedXHex: string, sharedYHex: string, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string): GeneratedCoin;
53
+ /**
54
+ * Merkle root, path, and coin fields for the first withdraw leg (Rust LeanIMT + Poseidon).
55
+ */
56
+ buildWithdrawMerkleWitness(coin: CoinData, state: StateFile): WithdrawMerkleWitness;
57
+ /**
58
+ * Full `Transaction(20,2,2)` withdrawal proof: one real withdraw + dummies, using coin/state and depositor ECDH point (hex).
59
+ *
60
+ * Optional **partial public withdraw**: spend the full coin commitment `coin.value` (V), send `publicWithdrawStroops` (W) to the
61
+ * Stellar receiver, and re-deposit the remainder (V−W) as a new private note to `changeRecipientStealthAddress` (same circuit balance).
62
+ */
63
+ proveWithdrawal(coin: CoinData, state: StateFile, params: {
64
+ withdrawAddressHi: string;
65
+ withdrawAddressLo: string;
66
+ privKeyScalar: string;
67
+ ephemeralXHex: string;
68
+ ephemeralYHex: string;
69
+ /** If set, public leg amount W (stroops). Must satisfy 0 < W < V. Remainder (V−W) stays in the pool as a new commitment. */
70
+ publicWithdrawStroops?: bigint;
71
+ /** Required when `publicWithdrawStroops` is set: stealth recipient for the change note (typically same as deposit). */
72
+ changeRecipientStealthAddress?: string;
73
+ }): Promise<WithdrawResult>;
28
74
  /**
29
75
  * Convert a snarkjs proof JSON to hex bytes for Soroban.
30
76
  */
@@ -34,14 +80,38 @@ export declare class PrivacyPoolSDK {
34
80
  */
35
81
  publicToHex(publicSignals: string[]): string;
36
82
  /**
37
- * Full withdrawal flow: generate input -> witness -> proof -> serialize.
38
- * Returns proof_hex and public_hex ready for Soroban contract call.
83
+ * BabyJubJub ephemeral point from a 32-byte scalar (hex). For custom {@link WithdrawObject} / tests.
39
84
  */
40
- prepareWithdrawal(coin: CoinData, state: StateFile): Promise<WithdrawResult>;
85
+ ecdhEphemeralPublicKeyFromScalarHex(scalarHex: string): {
86
+ x: string;
87
+ y: string;
88
+ };
89
+ /** Circuit `ECDH`: scalar (32-byte hex) × recipient BabyJub point → shared key hex coords. */
90
+ ecdhSharedKey(scalarHex: string, recipientPubXHex: string, recipientPubYHex: string): SharedSecret;
91
+ /**
92
+ * `Transaction(20,2,2)` proof from high-level legs: maps to witness input (incl. `"dummy"` ECDH via WASM), then Groth16 → Soroban hex.
93
+ *
94
+ * @param publicParams Public inputs: `stateRoot`, `withdrawAddressHi` / `withdrawAddressLo`, `privKeyScalar` (decimal field strings).
95
+ * @param publicLegs Public token legs (`publicWithdrawnAssets`, `publicDepositedAssets`, `publicDeposits`, `publicWithdrawals`).
96
+ * @param withdraws Exactly two withdraw slots (`WithdrawObject` or `"dummy"`).
97
+ * @param deposits Exactly two deposit slots (`DepositObject` or `"dummy"`).
98
+ */
99
+ proveTransaction(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdraws: [WithdrawSlot, WithdrawSlot], deposits: [DepositSlot, DepositSlot]): Promise<WithdrawResult>;
41
100
  /**
42
101
  * Calculate nullifier hash: Poseidon(nullifier)
43
102
  * @param nullifier Nullifier decimal string from coin data
44
103
  * @returns Hex string (0x...) of the hash bytes
45
104
  */
46
105
  calculateNullifierHash(nullifier: string): string;
106
+ /**
107
+ * Ed25519 signature from signing {@link buildStealthAddressSignMessage}: **128 hex chars** (optional `0x`)
108
+ * or **base64** (64 raw bytes after decode). `SHA-256(signature bytes)` → scalar → ECDH → `stpl1` Bech32.
109
+ */
110
+ generateStealthAddressFromStellarSignature(signature: string): Promise<string>;
111
+ encodeDecodedEphemeralKey(decoded: DecodedEphemeralKey): EncodedEphemeralKey;
112
+ decodeDecodedEphemeralKey(encoded: EncodedEphemeralKey): DecodedEphemeralKey;
113
+ encodeDepositorSharedSecretPreimage(decoded: DecodedDepositorSharedSecretPreimage): EncodedDepositorSharedSecretPreimage;
114
+ decodeDepositorSharedSecretPreimage(encoded: EncodedDepositorSharedSecretPreimage): DecodedDepositorSharedSecretPreimage;
115
+ sharedSecretFromDepositorPreimage(preimage: DecodedDepositorSharedSecretPreimage): SharedSecret;
116
+ sharedSecretFromRecipientPreimage(preimage: DecodedRecipientSharedSecretPreimage): SharedSecret;
47
117
  }
@@ -0,0 +1,24 @@
1
+ import type { DecodedDepositorSharedSecretPreimage, DecodedEphemeralKey } from './ephemeral-key';
2
+ import type { DecodedRecipientSharedSecretPreimage, Hex } from './stealth-address';
3
+ /** ECDH shared key coordinates (`ecdh_shared_key` / circuit `ECDH` output). */
4
+ export interface SharedSecret {
5
+ x: Hex;
6
+ y: Hex;
7
+ }
8
+ /** Withdrawer-side material: recipient private scalar ‖ depositor’s ephemeral point. */
9
+ export interface DecodedWithdrawerSharedSecret {
10
+ recipientScalar: Hex;
11
+ ephemeralKey: DecodedEphemeralKey;
12
+ }
13
+ export type EcdhSharedKeyFn = (privHex64: string, pubXHex64: string, pubYHex64: string) => {
14
+ x: string;
15
+ y: string;
16
+ };
17
+ /**
18
+ * Depositor: `randomNonceScalar * recipientStealthPoint` (same as circom `ECDH` with depositor scalar).
19
+ */
20
+ export declare function sharedSecretFromDepositorPreimage(ecdhShared: EcdhSharedKeyFn, preimage: DecodedDepositorSharedSecretPreimage): SharedSecret;
21
+ /**
22
+ * Recipient: `recipientScalar * ephemeralKey` (same shared point as depositor path when keys match).
23
+ */
24
+ export declare function sharedSecretFromRecipientPreimage(ecdhShared: EcdhSharedKeyFn, preimage: DecodedRecipientSharedSecretPreimage): SharedSecret;
@@ -0,0 +1,23 @@
1
+ import type { DecodedEphemeralKey } from './ephemeral-key';
2
+ /** Lowercase hex string (optional `0x` prefix when parsing). */
3
+ export type Hex = string;
4
+ export type StealthAddress = string;
5
+ export interface DecodedStealthAddress {
6
+ x: Hex;
7
+ y: Hex;
8
+ }
9
+ /** Withdrawer preimage: recipient scalar ‖ depositor-revealed ephemeral point. */
10
+ export interface DecodedRecipientSharedSecretPreimage {
11
+ ephemeralKey: DecodedEphemeralKey;
12
+ recipientScalar: Hex;
13
+ }
14
+ export declare const STEALTH_ADDRESS_HRP: "stpl1";
15
+ /**
16
+ * Encodes `x || y` as Bech32 (BIP-173) with human-readable part {@link STEALTH_ADDRESS_HRP} (`stpl1`).
17
+ * `x` and `y` must have the same byte length so decoding can split the payload in half.
18
+ */
19
+ export declare function encodeStealthAddress(decoded: DecodedStealthAddress): StealthAddress;
20
+ /**
21
+ * Decodes a `stpl1` Bech32 stealth address into `x` and `y` (each half of the payload, as lowercase hex).
22
+ */
23
+ export declare function decodeStealthAddress(address: StealthAddress): DecodedStealthAddress;
@@ -0,0 +1,7 @@
1
+ /** Default nonce when deriving the wallet sign-in message. */
2
+ export declare const DEFAULT_STEALTH_SIGN_NONCE = "main address";
3
+ /**
4
+ * Plaintext for Stellar wallet message signing (stealth address derivation).
5
+ * Sign the exact bytes of this string (UTF-8) with the stellar account key.
6
+ */
7
+ export declare function buildStealthAddressSignMessage(address: string, nonce?: string): string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Ed25519 signature as **128 hex chars** (optional `0x`) or **base64** (typically 88 chars for 64 bytes, whitespace ignored).
3
+ */
4
+ export declare function parseStellarEd25519SignatureRaw(input: string): Uint8Array;
5
+ /** SHA-256 via Web Crypto only (`crypto.subtle`) — works in browsers and Node 19+ (global `crypto`). */
6
+ export declare function sha256(data: Uint8Array): Promise<Uint8Array>;
7
+ /**
8
+ * Stellar Ed25519 signature (hex or base64) → SHA-256(signature bytes) → scalar → WASM ECDH (no UTF-8 seed hash).
9
+ */
10
+ export declare function stealthAddressFromStellarSignature(ecdhFromScalarHex: (scalarHex64: string) => {
11
+ x: string;
12
+ y: string;
13
+ }, encodeStealth: (decoded: {
14
+ x: string;
15
+ y: string;
16
+ }) => string, signature: string): Promise<string>;
17
+ /**
18
+ * SHA-256(signature) as 32-byte BE integer, truncated to **253 bits** (same effective scalar as
19
+ * `libs/cryptography` `scalar_mul_253` / circom `Num2Bits(253)`), decimal for `privKeyScalar`.
20
+ */
21
+ export declare function privKeyScalarDecimalFromStellarSignature(signature: string): Promise<string>;
package/dist/types.d.ts CHANGED
@@ -3,18 +3,36 @@ export interface CoinData {
3
3
  nullifier: string;
4
4
  secret: string;
5
5
  commitment: string;
6
+ /** Decimal Fr strings for Stellar asset contract id (`asset[0]`, `asset[1]` in `commitment.circom`). */
7
+ asset_hi: string;
8
+ asset_lo: string;
6
9
  }
7
10
  export interface GeneratedCoin {
8
11
  coin: CoinData;
9
12
  commitment_hex: string;
13
+ /** 64-char lowercase hex (no `0x`), Fr big-endian for audit `precommitement`. */
14
+ precommitement_hex: string;
10
15
  }
11
- export interface SnarkInput {
16
+ /** Pool Merkle tree depth (matches `coin::TREE_DEPTH` / `Transaction` circuit). */
17
+ export declare const POOL_MERKLE_TREE_DEPTH = 20;
18
+ /** Default coin value in stroops (1 XLM); matches Rust `coin::COIN_VALUE`. */
19
+ export declare const COIN_VALUE_STROOPS = 1000000000;
20
+ /**
21
+ * Merkle path + coin fields for the first withdraw leg (WASM `buildWithdrawMerkleWitness`).
22
+ * Serde: `withdrawnValue`, `stateRoot`, `stateIndex`, `stateSiblings`.
23
+ */
24
+ export interface WithdrawMerkleWitness {
25
+ /** Withdrawn amount in stroops as decimal Fr string; matches `coin.value`. */
12
26
  withdrawnValue: string;
27
+ /** Coin value as decimal field string. */
13
28
  value: string;
14
29
  nullifier: string;
15
30
  secret: string;
31
+ /** `[asset_hi, asset_lo]` decimal Fr strings (Stellar asset contract id). */
32
+ withdrawnAsset: [string, string];
16
33
  stateRoot: string;
17
34
  stateIndex: string;
35
+ /** Length is always {@link POOL_MERKLE_TREE_DEPTH}; each entry is a decimal field element. */
18
36
  stateSiblings: string[];
19
37
  }
20
38
  export interface StateFile {
@@ -0,0 +1,117 @@
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
+ /** Must match `Transaction(..., publicNInputs, publicNOutputs)` and contract `get_public_slot_config`. */
7
+ export declare const TRANSACTION_PUBLIC_N_INPUTS = 1;
8
+ export declare const TRANSACTION_PUBLIC_N_OUTPUTS = 1;
9
+ /** BN254 scalar field modulus (ark `Fr`, circom signals). */
10
+ export declare const BN254_SCALAR_MOD = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
11
+ /**
12
+ * BabyJub ECDH in `circuits/encryption.circom` uses `Num2Bits(253)`; scalars must be < 2^253
13
+ * (matches `libs/cryptography` `scalar_mul_253`).
14
+ */
15
+ export declare const BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE: bigint;
16
+ export interface WithdrawalProofPublicParams {
17
+ /** Decimal string, circom `stateRoot`. */
18
+ stateRoot: string;
19
+ /** Decimal string, circom `withdrawAddressHi` (Ed25519 key bytes [0..16] as big-endian u128). */
20
+ withdrawAddressHi: string;
21
+ /** Decimal string, circom `withdrawAddressLo` (Ed25519 key bytes [16..32] as big-endian u128). */
22
+ withdrawAddressLo: string;
23
+ /** Decimal string, circom `privKeyScalar`. */
24
+ privKeyScalar: string;
25
+ }
26
+ /** Public accounting legs (`publicWithdrawnAssets`, `publicDepositedAssets`, `publicDeposits`, `publicWithdrawals`). */
27
+ export interface TransactionPublicLegParams {
28
+ publicWithdrawnAssets: Array<[string, string]>;
29
+ publicDepositedAssets: Array<[string, string]>;
30
+ publicDeposits: string[];
31
+ publicWithdrawals: string[];
32
+ }
33
+ /** All-zero public legs (private-only pool moves). */
34
+ export declare function zeroPublicLegs(): TransactionPublicLegParams;
35
+ /** Real withdraw leg; coordinates are decimal field strings (same as `CoinData`). */
36
+ export interface WithdrawObject {
37
+ value: string;
38
+ nullifier: string;
39
+ secret: string;
40
+ /** Asset contract id as two decimal Fr strings (`asset[0]`, `asset[1]`). */
41
+ asset: [string, string];
42
+ /** Depositor ECDH point `[x, y]` as decimal strings. */
43
+ ephemeralKeys: [string, string];
44
+ stateSiblings: string[];
45
+ stateIndex: string;
46
+ }
47
+ export interface DepositObject {
48
+ value: string;
49
+ nullifier: string;
50
+ ephemeralKeyScalar: string;
51
+ /** Asset contract id as two decimal Fr strings. */
52
+ asset: [string, string];
53
+ /** Recipient public key `[x, y]` as decimal strings. */
54
+ recipientPublicKeys: [string, string];
55
+ }
56
+ export type WithdrawSlot = WithdrawObject | 'dummy';
57
+ export type DepositSlot = DepositObject | 'dummy';
58
+ /** Witness calculator input for `circuits/main.circom` `Transaction(20,2,2,publicNInputs,publicNOutputs)`. */
59
+ export interface TransactionWitnessInput {
60
+ stateRoot: string;
61
+ withdrawAddressHi: string;
62
+ withdrawAddressLo: string;
63
+ privKeyScalar: string;
64
+ withdrawnValues: [string, string];
65
+ withdrawnNullifiers: [string, string];
66
+ withdrawnSecrets: [string, string];
67
+ withdrawnAssets: [[string, string], [string, string]];
68
+ ephemeralKeys: [[string, string], [string, string]];
69
+ stateSiblings: [string[], string[]];
70
+ stateIndex: [string, string];
71
+ depositedValues: [string, string];
72
+ depositedNullifiers: [string, string];
73
+ depositedAssets: [[string, string], [string, string]];
74
+ depositedEphemeralKeyScalars: [string, string];
75
+ depositedRecipientPublicKeys: [[string, string], [string, string]];
76
+ publicWithdrawnAssets: Array<[string, string]>;
77
+ publicDepositedAssets: Array<[string, string]>;
78
+ publicDeposits: string[];
79
+ publicWithdrawals: string[];
80
+ }
81
+ export interface WasmEcdhPointFns {
82
+ ecdhEphemeralPublicKeyFromScalarHex(scalarHex: string): {
83
+ x: string;
84
+ y: string;
85
+ };
86
+ }
87
+ /** 32-byte field coordinate (hex, no 0x) → decimal string mod BN254 scalar field. */
88
+ export declare function coordHexToDecimal(hex: string): string;
89
+ /**
90
+ * 32-byte big-endian scalar hex → decimal for circom `ephemeralKeyScalar` / ECDH `priv`.
91
+ * Integer must be < 2^253 (not reduced mod r — values ≥ 2^253 are rejected).
92
+ */
93
+ export declare function scalarHexToFrDecimal(hex: string): string;
94
+ /**
95
+ * Stellar G-address Ed25519 payload (32 bytes as 64 hex, optional 0x) → two circom public decimals
96
+ * (`withdrawAddressHi` / `withdrawAddressLo`). No mod-r; each half fits in 128 bits.
97
+ */
98
+ export declare function ed25519PubkeyPayloadHexToWithdrawFrDecimals(hex: string): {
99
+ hi: string;
100
+ lo: string;
101
+ };
102
+ /**
103
+ * Stellar contract id (`C…`) → two circom field decimals for `asset[0]`, `asset[1]` (same 32-byte split as accounts).
104
+ */
105
+ export declare function stellarContractAddressToAssetFrDecimals(address: string): [string, string];
106
+ /** Uniform random `Fr` as decimal (32 random bytes, mod r). For Poseidon-only inputs (e.g. nullifiers). */
107
+ export declare function randomFrDecimal(): string;
108
+ /** Random scalar < 2^253 for BabyJub ECDH / `Num2Bits(253)` (uses {@link generateRandomScalarHex32}). */
109
+ export declare function randomFrDecimal253(): string;
110
+ export declare function buildTransactionWitnessInput(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdrawSlots: [WithdrawSlot, WithdrawSlot], depositSlots: [DepositSlot, DepositSlot], wasm: WasmEcdhPointFns): TransactionWitnessInput;
111
+ /** `stpl1…` stealth address → `[x, y]` as decimal field strings for `depositedRecipientPublicKeys`. */
112
+ export declare function recipientPublicKeysDecimalFromStealthAddress(stealthAddress: string): [string, string];
113
+ /** First withdraw leg: Merkle witness + depositor ECDH point coordinates (hex). */
114
+ export declare function withdrawObjectFromMerkleWitness(witness: WithdrawMerkleWitness, depositorEphemeralHex: {
115
+ x: string;
116
+ y: string;
117
+ }): WithdrawObject;
package/dist/witness.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { SnarkInput } from './types';
2
- export declare function generateWitness(input: SnarkInput, circuitWasm?: BufferSource): Promise<Uint8Array>;
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.2-rc.9",
3
+ "version": "0.4.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,20 @@
35
38
  "cli": "node dist/cli.js"
36
39
  },
37
40
  "dependencies": {
41
+ "@stellar/stellar-base": "^13.0.0",
42
+ "bech32": "^2.0.0",
38
43
  "snarkjs": "^0.7.0"
39
44
  },
40
45
  "devDependencies": {
41
- "rollup": "^4.0.0",
42
46
  "@rollup/plugin-alias": "^5.0.0",
43
- "@rollup/plugin-typescript": "^11.0.0",
44
- "@rollup/plugin-node-resolve": "^15.0.0",
45
47
  "@rollup/plugin-commonjs": "^25.0.0",
46
48
  "@rollup/plugin-json": "^6.0.0",
49
+ "@rollup/plugin-node-resolve": "^15.0.0",
50
+ "@rollup/plugin-typescript": "^11.0.0",
51
+ "@types/node": "^20.0.0",
52
+ "rollup": "^4.0.0",
47
53
  "rollup-plugin-copy": "^3.5.0",
48
- "typescript": "^5.0.0",
49
54
  "tslib": "^2.6.0",
50
- "@types/node": "^20.0.0"
55
+ "typescript": "^5.0.0"
51
56
  }
52
57
  }
@@ -1,62 +1,106 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
+
3
4
  /**
4
- * Convert snarkjs public signals JSON to hex bytes for Soroban contract.
5
+ * Merkle root, path, and coin field strings for the first withdraw leg (JSON → JSON).
5
6
  */
6
- export function publicToHex(public_json: string): string;
7
+ export function buildWithdrawMerkleWitness(coin_json: string, state_json: string): string;
8
+
7
9
  /**
8
10
  * Calculate nullifier hash from nullifier decimal string.
9
11
  * Returns hex string (0x...)
10
12
  */
11
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
+ * `asset_hi_decimal` / `asset_lo_decimal` are decimal Fr strings for the Stellar asset contract id (two limbs).
35
+ * Returns JSON: { coin: { value, nullifier, secret, commitment, asset_hi, asset_lo }, commitment_hex, precommitement_hex }
36
+ */
37
+ export function generateCoin(amount: bigint, asset_hi_decimal: string, asset_lo_decimal: string): any;
38
+
39
+ /**
40
+ * `Poseidon₁(scalar)` secret + fixed ECDH shared coords (hex), matching an aligned deposit witness.
41
+ */
42
+ export function generateCoinForDepositWithSharedHex(scalar_hex: string, shared_x_hex: string, shared_y_hex: string, amount: bigint, asset_hi_decimal: string, asset_lo_decimal: string): any;
43
+
12
44
  /**
13
- * Generate withdrawal SNARK input from coin and state JSON strings.
14
- * Returns JSON string of SnarkInput.
45
+ * `secret` in coin = `Poseidon255(1)(scalar)` per `deposit.circom`; scalar is 32-byte hex (64 chars, optional `0x`).
15
46
  */
16
- export function generateWithdrawalInput(coin_json: string, state_json: string): string;
47
+ export function generateCoinFromDepositEphemeralScalarHex(scalar_hex: string, amount: bigint, asset_hi_decimal: string, asset_lo_decimal: string): any;
48
+
17
49
  /**
18
- * Generate a new coin with random nullifier and secret.
19
- * Returns JSON: { coin: { value, nullifier, secret, commitment }, commitment_hex }
50
+ * 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.
20
51
  */
21
- export function generateCoin(): any;
52
+ export function generateCoinWithSharedSecretHex(shared_x_hex: string, shared_y_hex: string, amount: bigint, asset_hi_decimal: string, asset_lo_decimal: string): any;
53
+
22
54
  /**
23
55
  * Convert snarkjs proof JSON to hex bytes for Soroban contract.
24
56
  */
25
57
  export function proofToHex(proof_json: string): string;
26
58
 
59
+ /**
60
+ * Convert snarkjs public signals JSON to hex bytes for Soroban contract.
61
+ */
62
+ export function publicToHex(public_json: string): string;
63
+
27
64
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
28
65
 
29
66
  export interface InitOutput {
30
- readonly memory: WebAssembly.Memory;
31
- readonly calculateNullifierHash: (a: number, b: number, c: number) => void;
32
- readonly generateCoin: () => number;
33
- readonly generateWithdrawalInput: (a: number, b: number, c: number, d: number, e: number) => void;
34
- readonly proofToHex: (a: number, b: number, c: number) => void;
35
- readonly publicToHex: (a: number, b: number, c: number) => void;
36
- readonly __wbindgen_export_0: (a: number) => void;
37
- readonly __wbindgen_export_1: (a: number, b: number) => number;
38
- readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
39
- readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
40
- readonly __wbindgen_export_3: (a: number, b: number, c: number) => void;
67
+ readonly memory: WebAssembly.Memory;
68
+ readonly buildWithdrawMerkleWitness: (a: number, b: number, c: number, d: number, e: number) => void;
69
+ readonly calculateNullifierHash: (a: number, b: number, c: number) => void;
70
+ readonly ecdhEphemeralPublicKey: (a: number, b: number, c: number) => void;
71
+ readonly ecdhEphemeralPublicKeyFromScalarHex: (a: number, b: number, c: number) => void;
72
+ readonly ecdhSharedKey: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
73
+ readonly generateCoin: (a: number, b: bigint, c: number, d: number, e: number, f: number) => void;
74
+ readonly generateCoinForDepositWithSharedHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number, k: number, l: number) => void;
75
+ readonly generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number, h: number) => void;
76
+ readonly generateCoinWithSharedSecretHex: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number) => void;
77
+ readonly proofToHex: (a: number, b: number, c: number) => void;
78
+ readonly publicToHex: (a: number, b: number, c: number) => void;
79
+ readonly __wbindgen_export: (a: number, b: number) => number;
80
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
81
+ readonly __wbindgen_export3: (a: number) => void;
82
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
83
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
41
84
  }
42
85
 
43
86
  export type SyncInitInput = BufferSource | WebAssembly.Module;
87
+
44
88
  /**
45
- * Instantiates the given `module`, which can either be bytes or
46
- * a precompiled `WebAssembly.Module`.
47
- *
48
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
49
- *
50
- * @returns {InitOutput}
51
- */
89
+ * Instantiates the given `module`, which can either be bytes or
90
+ * a precompiled `WebAssembly.Module`.
91
+ *
92
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
93
+ *
94
+ * @returns {InitOutput}
95
+ */
52
96
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
53
97
 
54
98
  /**
55
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
56
- * for everything else, calls `WebAssembly.instantiate` directly.
57
- *
58
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
59
- *
60
- * @returns {Promise<InitOutput>}
61
- */
99
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
100
+ * for everything else, calls `WebAssembly.instantiate` directly.
101
+ *
102
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
103
+ *
104
+ * @returns {Promise<InitOutput>}
105
+ */
62
106
  export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;