@auditable/privacy-pool-zk-sdk 0.7.0 → 0.9.1-rc.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.
@@ -1,14 +1,13 @@
1
1
  import { Keypair } from '@stellar/stellar-sdk';
2
2
  import { buildKytPassageAuthorization, derivePassageFromTransactContext, hashPublicSignalBytes, type InspectKytPassageRequest, type PublicLegContextInput } from './kyt-passage.js';
3
- import { type OnboardingPayloadInput } from './kyt-onboarding.js';
4
3
  export interface RegisterPassageParams {
5
4
  kytRegistryId: string;
6
5
  poolContract: string;
7
6
  owner: string;
8
7
  nonce?: bigint | number;
9
8
  publicSignalsBytes: Buffer | string;
9
+ ciphertextBytes?: Buffer | string;
10
10
  publicLegContext: PublicLegContextInput;
11
- onboarding?: OnboardingPayloadInput | null;
12
11
  signature: string;
13
12
  expiresAtLedger: number;
14
13
  source: Keypair;
@@ -21,7 +20,7 @@ export interface SubmitKytTransactParams {
21
20
  nonce: bigint | number;
22
21
  proofBytes: Buffer;
23
22
  publicSignalsBytes: Buffer;
24
- onboarding?: OnboardingPayloadInput | null;
23
+ ciphertextBytes?: Buffer;
25
24
  /** Omit when the pool's own registered passage covers this call (no explicit signed authorization). */
26
25
  kytAuthorization?: {
27
26
  expirationLedger: number;
@@ -1,10 +1,11 @@
1
- import { type OnboardingPayloadInput } from './kyt-onboarding.js';
2
1
  export declare const KYT_PASSAGE_AUTH_DOMAIN = "privacy-pool-kyt-passage-v1";
3
2
  export declare const PUBLIC_LEG_CONTEXT_DOMAIN = "privacy-pool-public-leg-context-v1";
4
- export declare const PASSAGE_ID_DOMAIN = "privacy-pool-passage-id-v1";
5
- export declare const ONBOARDING_ZERO_DOMAIN = "privacy-pool-onboarding-zero-v1";
6
- export declare const NOTE_AUDIT_LEN = 9;
7
- export declare const TOTAL_PUBLIC_SIGNALS = 79;
3
+ export declare const PASSAGE_ID_DOMAIN = "privacy-pool-passage-id-v3";
4
+ export declare const PASSAGE_ID_DOMAIN_V2 = "privacy-pool-passage-id-v2";
5
+ export declare const PASSAGE_ID_DOMAIN_V1 = "privacy-pool-passage-id-v1";
6
+ export declare const NOTE_AUDIT_LEN = 12;
7
+ export declare const TOTAL_PUBLIC_SIGNALS = 93;
8
+ export declare const NOTE_AUDIT_PLAINTEXT_LEN = 12;
8
9
  export interface PublicLegLayout {
9
10
  publicNInputs: number;
10
11
  publicNOutputs: number;
@@ -20,7 +21,6 @@ export interface PublicLegContextInput {
20
21
  export interface KytPassageDerivation {
21
22
  publicSignalHash: string;
22
23
  publicLegContextHash: string;
23
- onboardingHash: string;
24
24
  passageId: string;
25
25
  }
26
26
  export interface KytPassageAuthorization {
@@ -33,10 +33,11 @@ export interface KytPassageAuthorization {
33
33
  /** Canonical zero-address sentinel for absent public-leg slots: `u32_be(0)` with no XDR bytes. */
34
34
  export declare function zeroAddressSentinelBuffer(): Buffer;
35
35
  export declare function addressToCanonicalXdr(address: string): Buffer;
36
- export declare function hashPublicSignalBytes(publicSignalsBytes: Buffer | string): string;
36
+ export declare function hashPublicSignalBytes(publicSignalsBytes: Buffer | string, zkConfigNonce?: bigint): string;
37
37
  export declare function hashPublicLegContext(layout: PublicLegLayout, input: PublicLegContextInput): string;
38
- export declare function hashOnboarding(onboarding: OnboardingPayloadInput | null | undefined): string;
39
- export declare function derivePassageId(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: string, onboardingHash: string): string;
38
+ export declare function derivePassageId(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: string, ciphertextHash: string): string;
39
+ export declare function derivePassageIdV2(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: string): string;
40
+ export declare function derivePassageIdV1(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: string, onboardingHash: string): string;
40
41
  export declare function buildKytPassageAuthorization(input: {
41
42
  poolContract: string;
42
43
  kytRegistry: string;
@@ -47,10 +48,18 @@ export declare function derivePassageFromTransactContext(input: {
47
48
  owner: string;
48
49
  nonce?: bigint | number;
49
50
  publicSignalsBytes: Buffer | string;
51
+ ciphertextBytes?: Buffer | string;
50
52
  publicLegContext: PublicLegContextInput;
51
53
  layout?: PublicLegLayout;
52
- onboarding?: OnboardingPayloadInput | null;
53
54
  }): KytPassageDerivation;
55
+ export declare function hashCiphertextBytes(ciphertextBytes: Buffer | string): string;
56
+ export declare function zeroBindingTagsInPublicSignals(publicSignalsBytes: Buffer | string, zkConfigNonce?: bigint): Buffer;
57
+ export declare function spliceBindingTagsIntoPublicSignals(parameters: {
58
+ publicSignalsBytes: Buffer | string;
59
+ zkConfigNonce: bigint;
60
+ auditTags: readonly string[];
61
+ outputNoteTags: readonly string[];
62
+ }): Buffer;
54
63
  export declare function accountIdFromAddress(address: string): Buffer;
55
64
  export interface InspectKytPassageRequest {
56
65
  owner: string;
@@ -58,9 +67,11 @@ export interface InspectKytPassageRequest {
58
67
  kytRegistry: string;
59
68
  proofBytes: string;
60
69
  publicSignalsBytes: string;
61
- applicationIdsPlaintext: [string, string, string, string];
62
- onboarding?: OnboardingPayloadInput | null;
70
+ applicationIdsPlaintext: string[];
71
+ ciphertextBytes?: string;
72
+ outputNoteEphemeralScalars?: string[];
63
73
  nonce?: string;
74
+ zkConfigNonce?: string;
64
75
  }
65
76
  export interface InspectKytPassageApproved {
66
77
  status: 'approved';
@@ -1,9 +1,12 @@
1
- import type { DepositObject } from './withdrawal-transaction-input.js';
1
+ import { buildPoseidon } from 'circomlibjs';
2
+ import type { DepositObject, TransactionWitnessInput } from './withdrawal-transaction-input.js';
2
3
  import type { EcdhSharedKeyFn } from './shared-secret.js';
4
+ import type { ZkLayoutParams } from './zk-layout.js';
3
5
  export declare const NOTE_OUTPUT_LEN = 6;
4
- export declare const OUTPUT_NOTE_TAG_DOMAIN = 3n;
6
+ export declare const NOTE_AUDIT_LEN = 12;
5
7
  export declare const STREAM_DOMAIN = 1n;
6
8
  export declare const FR_SIZE = 32;
9
+ type Poseidon = Awaited<ReturnType<typeof buildPoseidon>>;
7
10
  export type OutputNotePlaintext = {
8
11
  value: string;
9
12
  assetHi: string;
@@ -26,7 +29,15 @@ export type OutputNoteEventInput = {
26
29
  createdEphemeralKey: readonly [string, string];
27
30
  ciphertext: readonly string[];
28
31
  tag: string;
32
+ ownerMode?: bigint;
29
33
  };
34
+ export declare function poseidonMacTag(parameters: {
35
+ poseidon: Poseidon;
36
+ domain: bigint;
37
+ key: bigint;
38
+ nonce: bigint;
39
+ message: readonly bigint[];
40
+ }): bigint;
30
41
  export declare function secretFromDepositEphemeralScalarDecimal(ephemeralKeyScalarDecimal: string): Promise<string>;
31
42
  export declare function encryptOutputNoteForDeposit(parameters: {
32
43
  deposit: DepositObject;
@@ -40,3 +51,22 @@ export declare function buildOutputNoteEncryptionPublicInputs(parameters: {
40
51
  outputNoteTags: [string, string];
41
52
  }>;
42
53
  export declare function decryptOutputNoteEvent(input: OutputNoteEventInput): Promise<DecryptedOutputNote>;
54
+ export declare function encryptNoteAuditSlot(parameters: {
55
+ auditPublicKey: readonly [string, string];
56
+ auditEphemeralScalar: string;
57
+ plaintext: readonly string[];
58
+ ecdhShared: EcdhSharedKeyFn;
59
+ }): Promise<{
60
+ ciphertext: string[];
61
+ tag: string;
62
+ }>;
63
+ export declare function encryptTransactionCiphertextBlob(parameters: {
64
+ witness: TransactionWitnessInput;
65
+ layout: ZkLayoutParams;
66
+ ecdhShared: EcdhSharedKeyFn;
67
+ }): Promise<{
68
+ ciphertextHex: string;
69
+ auditCiphertexts: string[][];
70
+ outputNoteCiphertexts: string[][];
71
+ }>;
72
+ export {};
package/dist/prover.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export interface ProofResult {
1
+ /** @deprecated Groth16 proving is in the main SDK WASM (`proveGroth16`). */
2
+ export declare function generateProof(_wtns: Uint8Array, _zkey?: BufferSource, _zkeyFileName?: string): Promise<{
2
3
  proof: object;
3
4
  publicSignals: string[];
4
- }
5
- export declare function generateProof(wtns: Uint8Array, zkey?: BufferSource): Promise<ProofResult>;
5
+ }>;
package/dist/sdk.d.ts CHANGED
@@ -1,23 +1,31 @@
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';
6
- import { type TransactionAuditParams } from './transaction-audit';
1
+ import type { CoinData, GeneratedCoin, SDKOptions, StateFile, WithdrawMerkleWitness, WithdrawResult } from "./types";
2
+ import { type DecodedDepositorSharedSecretPreimage, type DecodedEphemeralKey, type EncodedDepositorSharedSecretPreimage, type EncodedEphemeralKey } from "./ephemeral-key";
3
+ import { type SharedSecret } from "./shared-secret";
4
+ import { type SpendScalarDomain } from "./stealth-sign-message";
5
+ import type { DecodedRecipientSharedSecretPreimage } from "./stealth-address";
6
+ import { type DepositSlot, type TransactionPublicLegParams, type WithdrawalProofPublicParams, type WithdrawSlot } from "./withdrawal-transaction-input";
7
+ import { type TransactionAuditParams } from "./transaction-audit";
8
+ import { type ZkLayoutParams } from "./zk-layout";
7
9
  export declare class PrivacyPoolSDK {
8
10
  private wasm;
9
11
  private options;
12
+ private zkConfigNonce;
13
+ private circuitConfig;
14
+ private layout;
15
+ private circuitArtifacts;
10
16
  private constructor();
17
+ getZkConfigNonce(): bigint;
18
+ getLayout(): ZkLayoutParams;
11
19
  /**
12
20
  * Initialize the SDK by loading WASM modules.
13
21
  *
14
- * In Node.js, assets are loaded from the filesystem automatically.
15
- * In browser, pass pre-loaded buffers via options:
22
+ * In Node.js, proving artifacts load from `zkArtifactBaseUrl` or
23
+ * `ZK_ARTIFACT_BASE_URL`, defaulting to this package's GitHub release.
24
+ * In browser, pass pre-loaded WASM via options:
16
25
  * ```ts
17
26
  * const sdk = await PrivacyPoolSDK.init({
18
27
  * wasmBinary: await fetch('/pkg/client_sdk_wasm_bg.wasm').then(r => r.arrayBuffer()),
19
- * circuitWasm: await fetch('/assets/main.wasm').then(r => r.arrayBuffer()),
20
- * zkey: await fetch('/assets/main_final.zkey').then(r => r.arrayBuffer()),
28
+ * zkArtifactBaseUrl: 'https://github.com/Polynom-Labs/stellar-privacy-layer-contracts/releases/download/v0.8.0',
21
29
  * });
22
30
  * ```
23
31
  */
@@ -27,30 +35,34 @@ export declare class PrivacyPoolSDK {
27
35
  */
28
36
  static generateRandomScalarHex32(): string;
29
37
  /**
30
- * Text to sign with a Stellar wallet for stealth derivation (UTF-8). No WASM required.
38
+ * Text to sign with a Stellar wallet for spend-key derivation (UTF-8). No WASM required.
39
+ * The message binds network, pool, registry, and schema version (H6).
31
40
  */
32
- static buildStealthAddressSignMessage(address: string, nonce?: string): string;
41
+ static buildStealthAddressSignMessage(address: string, domain: SpendScalarDomain, nonce?: string): string;
33
42
  /**
34
- * Generate a new coin with random nullifier, secret, and random shared-secret field elements (dev / self-contained tests).
35
- * @param amount Stroops encoded as `bigint` or integer `number` (WASM `u64`).
43
+ * Generate a new coin with random nullifier, secret, and random owner-pub field elements (dev / self-contained tests).
44
+ * @param amount Decimal field element as `bigint` or decimal `string` (never JS `number`).
36
45
  * @param assetHiDecimal / assetLoDecimal Decimal Fr strings for Stellar asset contract id (two limbs).
37
46
  */
38
- generateCoin(amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
47
+ generateCoin(amount: bigint | string, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
39
48
  /**
40
- * Generate a coin with the same commitment shape as on-chain deposit: pass `ecdhSharedKey` output (hex x, y).
41
- * @param amount Stroops (`bigint` | `number`).
49
+ * Generate a coin with the same commitment shape as on-chain deposit: pass owner public key (hex x, y).
50
+ * @param amount Decimal field element (`bigint` | `string`).
42
51
  */
43
- generateCoinWithSharedSecret(shared: SharedSecret, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
52
+ generateCoinWithOwnerPub(ownerPub: {
53
+ x: string;
54
+ y: string;
55
+ }, amount: bigint | string, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
44
56
  /**
45
57
  * Coin for a depositor `ephemeralKeyScalar` (32-byte hex): `coin.secret = Poseidon255(1)(scalar)` as in `deposit.circom`.
46
- * @param amount Stroops (`bigint` | `number`).
58
+ * @param amount Decimal field element (`bigint` | `string`).
47
59
  */
48
- generateCoinFromDepositEphemeralScalarHex(scalarHex: string, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
60
+ generateCoinFromDepositEphemeralScalarHex(scalarHex: string, amount: bigint | string, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
49
61
  /**
50
- * Aligned deposit coin: `secret = Poseidon₁(scalar)` and ECDH shared key from hex coords (e.g. `ecdhSharedKey(scalar, recipient_x, recipient_y)`).
51
- * @param amount Stroops (`bigint` | `number`).
62
+ * Aligned deposit coin: `secret = Poseidon₁(scalar)` and owner pub from recipient hex coords.
63
+ * @param amount Decimal field element (`bigint` | `string`).
52
64
  */
53
- generateCoinForDepositWithSharedHex(scalarHex: string, sharedXHex: string, sharedYHex: string, amount: bigint | number, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
65
+ generateCoinForDepositWithOwnerPubHex(scalarHex: string, ownerXHex: string, ownerYHex: string, amount: bigint | string, assetHiDecimal: string, assetLoDecimal: string, applicationIdDecimal?: string): GeneratedCoin;
54
66
  /**
55
67
  * Merkle root, path, and coin fields for the first withdraw leg (Rust LeanIMT + Poseidon).
56
68
  */
@@ -92,25 +104,23 @@ export declare class PrivacyPoolSDK {
92
104
  /** Circuit `ECDH`: scalar (32-byte hex) × recipient BabyJub point → shared key hex coords. */
93
105
  ecdhSharedKey(scalarHex: string, recipientPubXHex: string, recipientPubYHex: string): SharedSecret;
94
106
  /**
95
- * `Transaction(20,2,2)` proof from high-level legs: maps to witness input (incl. `"dummy"` ECDH via WASM), then Groth16 → Soroban hex.
96
- *
97
- * @param publicParams Public inputs: `stateRoot`, `withdrawAddressHi` / `withdrawAddressLo`, `privKeyScalar` (decimal field strings).
98
- * @param publicLegs Public token legs (`publicWithdrawnAssets`, `publicDepositedAssets`, `publicDeposits`, `publicWithdrawals`).
99
- * @param withdraws Exactly two withdraw slots (`WithdrawObject` or `"dummy"`).
100
- * @param deposits Exactly two deposit slots (`DepositObject` or `"dummy"`).
107
+ * `Transaction(20,nIns,nOuts)` proof from high-level legs: maps to witness input (incl. `"dummy"` ECDH via WASM), then Groth16 → Soroban hex.
108
+ * Slots are padded to the selected ZK config layout (bundled 2×2 or 6×6).
101
109
  */
102
- proveTransaction(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdraws: [WithdrawSlot, WithdrawSlot], deposits: [DepositSlot, DepositSlot], audit: TransactionAuditParams): Promise<WithdrawResult>;
110
+ proveTransaction(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdraws: WithdrawSlot[], deposits: DepositSlot[], audit: TransactionAuditParams): Promise<WithdrawResult>;
111
+ proveTransactionSlots(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdraws: WithdrawSlot[], deposits: DepositSlot[], audit: TransactionAuditParams): Promise<WithdrawResult>;
103
112
  /**
104
- * Calculate nullifier hash: Poseidon(nullifier)
113
+ * Calculate owner-bound nullifier hash: Poseidon(DOM_NULLIFIER, nullifier, privKeyScalar)
105
114
  * @param nullifier Nullifier decimal string from coin data
115
+ * @param privKeyScalar Spend scalar decimal string
106
116
  * @returns Hex string (0x...) of the hash bytes
107
117
  */
108
- calculateNullifierHash(nullifier: string): string;
118
+ calculateNullifierHash(nullifier: string, privKeyScalar: string): string;
109
119
  /**
110
120
  * Ed25519 signature from signing {@link buildStealthAddressSignMessage}: **128 hex chars** (optional `0x`)
111
- * or **base64** (64 raw bytes after decode). `SHA-256(signature bytes)` → scalar → ECDH → `stpl1` Bech32.
121
+ * or **base64** (64 raw bytes after decode). Domain-separated SHA-256 → scalar → ECDH → `stpl1` Bech32.
112
122
  */
113
- generateStealthAddressFromStellarSignature(signature: string): Promise<string>;
123
+ generateStealthAddressFromStellarSignature(signature: string, domain: SpendScalarDomain): Promise<string>;
114
124
  encodeDecodedEphemeralKey(decoded: DecodedEphemeralKey): EncodedEphemeralKey;
115
125
  decodeDecodedEphemeralKey(encoded: EncodedEphemeralKey): DecodedEphemeralKey;
116
126
  encodeDepositorSharedSecretPreimage(decoded: DecodedDepositorSharedSecretPreimage): EncodedDepositorSharedSecretPreimage;
@@ -1,7 +1,20 @@
1
1
  /** Default nonce when deriving the wallet sign-in message. */
2
2
  export declare const DEFAULT_STEALTH_SIGN_NONCE = "main address";
3
+ /** Domain tag mixed into the spend-scalar digest (H6). */
4
+ export declare const SPEND_SCALAR_DOMAIN_TAG = "privacy-pool-spend-scalar-v1";
5
+ /** Schema version bound into the spend-scalar message and digest. */
6
+ export declare const OWNER_BOUND_NOTE_SCHEMA_VERSION = 1;
7
+ export type SpendScalarDomain = {
8
+ networkPassphrase: string;
9
+ poolContract: string;
10
+ registryContract: string;
11
+ schemaVersion?: number;
12
+ };
13
+ export declare function resolveSpendScalarSchemaVersion(domain: SpendScalarDomain): number;
3
14
  /**
4
- * Plaintext for Stellar wallet message signing (stealth address derivation).
15
+ * Plaintext for Stellar wallet message signing (spend-key derivation).
5
16
  * Sign the exact bytes of this string (UTF-8) with the stellar account key.
17
+ *
18
+ * The derived scalar is the owner-bound spend key for notes in this environment.
6
19
  */
7
- export declare function buildStealthAddressSignMessage(address: string, nonce?: string): string;
20
+ export declare function buildStealthAddressSignMessage(address: string, domain: SpendScalarDomain, nonce?: string): string;
@@ -1,3 +1,4 @@
1
+ import { type SpendScalarDomain } from './stealth-sign-message';
1
2
  /**
2
3
  * Ed25519 signature as **128 hex chars** (optional `0x`) or **base64** (typically 88 chars for 64 bytes, whitespace ignored).
3
4
  */
@@ -5,7 +6,14 @@ export declare function parseStellarEd25519SignatureRaw(input: string): Uint8Arr
5
6
  /** SHA-256 via Web Crypto only (`crypto.subtle`) — works in browsers and Node 19+ (global `crypto`). */
6
7
  export declare function sha256(data: Uint8Array): Promise<Uint8Array>;
7
8
  /**
8
- * Stellar Ed25519 signature (hex or base64) → SHA-256(signature bytes) → scalar → WASM ECDH (no UTF-8 seed hash).
9
+ * Domain-separated spend-scalar digest: SHA-256(
10
+ * SPEND_SCALAR_DOMAIN_TAG || network || pool || registry || schemaVersion || signature
11
+ * ).
12
+ */
13
+ export declare function spendScalarDigestFromStellarSignature(signature: string, domain: SpendScalarDomain): Promise<Uint8Array>;
14
+ export declare function spendScalarHexFromStellarSignature(signature: string, domain: SpendScalarDomain): Promise<string>;
15
+ /**
16
+ * Stellar Ed25519 signature (hex or base64) → domain-separated SHA-256 → scalar → WASM ECDH.
9
17
  */
10
18
  export declare function stealthAddressFromStellarSignature(ecdhFromScalarHex: (scalarHex64: string) => {
11
19
  x: string;
@@ -13,9 +21,9 @@ export declare function stealthAddressFromStellarSignature(ecdhFromScalarHex: (s
13
21
  }, encodeStealth: (decoded: {
14
22
  x: string;
15
23
  y: string;
16
- }) => string, signature: string): Promise<string>;
24
+ }) => string, signature: string, domain: SpendScalarDomain): Promise<string>;
17
25
  /**
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`.
26
+ * Domain-separated SHA-256(signature, network, pool, registry, schema) reduced into
27
+ * `(0, BabyJub subgroup order)` so `privKeyScalar` matches `BabyPbk` and circom `LessThan(l)`.
20
28
  */
21
- export declare function privKeyScalarDecimalFromStellarSignature(signature: string): Promise<string>;
29
+ export declare function privKeyScalarDecimalFromStellarSignature(signature: string, domain: SpendScalarDomain): Promise<string>;
@@ -1,25 +1,26 @@
1
1
  import { type DepositObject, type DepositSlot, type WithdrawObject, type WithdrawSlot } from './withdrawal-transaction-input';
2
2
  export declare const TRANSACTION_N_AUDIT_SLOTS = 4;
3
+ export declare const SIX_BY_SIX_N_AUDIT_SLOTS = 12;
3
4
  export declare const DEFAULT_APPLICATION_ID = "101";
4
5
  /** BabyJub audit public key (decimal Fr) used in BDD / local demo when env is unset. */
5
6
  export declare const DEMO_AUDIT_PUBLIC_KEY: AuditPublicKey;
6
7
  export type AuditPublicKey = [string, string];
7
8
  export interface TransactionAuditParams {
8
9
  applicationId: string;
9
- noteAuditPublicKeys: [
10
- AuditPublicKey,
11
- AuditPublicKey,
12
- AuditPublicKey,
13
- AuditPublicKey
14
- ];
15
- auditEphemeralScalars: [string, string, string, string];
10
+ noteAuditPublicKey: AuditPublicKey;
11
+ auditEphemeralScalar: string;
16
12
  }
17
13
  export interface TransactionSlotApplicationIds {
18
- inputApplicationIds: [string, string];
19
- outputApplicationIds: [string, string];
14
+ inputApplicationIds: string[];
15
+ outputApplicationIds: string[];
20
16
  }
21
- export declare function buildUniformAuditParams(applicationId: string | undefined, auditPublicKey: AuditPublicKey): TransactionAuditParams;
22
- export declare function resolveSlotApplicationIds(audit: TransactionAuditParams, withdrawSlots: [WithdrawSlot, WithdrawSlot], depositSlots: [DepositSlot, DepositSlot]): TransactionSlotApplicationIds;
17
+ export declare function buildUniformAuditParams(applicationId: string | undefined, auditPublicKey: AuditPublicKey, _nAuditSlots?: number): TransactionAuditParams;
18
+ export declare function resolveSlotApplicationIds(audit: TransactionAuditParams, withdrawSlots: WithdrawSlot[], depositSlots: DepositSlot[]): TransactionSlotApplicationIds;
23
19
  export declare function withApplicationIdOnDeposit(deposit: DepositObject, applicationId: string): DepositObject;
24
20
  export declare function withApplicationIdOnWithdraw(withdraw: WithdrawObject, applicationId: string): WithdrawObject;
25
- export declare function resolveTransactionAuditParams(applicationId: string, auditPublicKey?: AuditPublicKey): TransactionAuditParams;
21
+ /**
22
+ * Prefer an explicit key, then `NOTE_AUDIT_PUBLIC_KEY_X`/`_Y` env (decimal Fr),
23
+ * then the built-in demo key. Used by CLI/`demo.sh` for per-app audit pubkeys.
24
+ */
25
+ export declare function resolveAuditPublicKeyFromEnv(auditPublicKey?: AuditPublicKey): AuditPublicKey;
26
+ export declare function resolveTransactionAuditParams(applicationId: string, auditPublicKey?: AuditPublicKey, nAuditSlots?: number): TransactionAuditParams;
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ export interface GeneratedCoin {
14
14
  commitment_hex: string;
15
15
  /** 64-char lowercase hex (no `0x`), Fr big-endian for audit `precommitement`. */
16
16
  precommitement_hex: string;
17
+ /** JS alias of {@link GeneratedCoin.precommitement_hex}. */
18
+ precommitementHex: string;
17
19
  }
18
20
  /** Pool Merkle tree depth (matches `coin::TREE_DEPTH` / `Transaction` circuit). */
19
21
  export declare const POOL_MERKLE_TREE_DEPTH = 20;
@@ -43,12 +45,20 @@ export interface StateFile {
43
45
  export interface WithdrawResult {
44
46
  proof_hex: string;
45
47
  public_hex: string;
48
+ ciphertext_hex: string;
49
+ output_note_ephemeral_scalars: string[];
46
50
  }
47
51
  export interface SDKOptions {
48
52
  /** Pre-loaded Rust WASM binary (ArrayBuffer). Required in browser. */
49
53
  wasmBinary?: BufferSource;
50
- /** Pre-loaded circuit WASM binary for witness generation. Required in browser. */
51
- circuitWasm?: BufferSource;
52
- /** Pre-loaded zkey binary for proof generation. Required in browser. */
53
- zkey?: BufferSource;
54
+ /** Nonce-keyed circuit map. Defaults to {@link DEFAULT_ZK_CIRCUITS}. */
55
+ zkCircuits?: Record<string, import('./zk-layout').ZkCircuitConfig>;
56
+ /** Selected pool `ZkConfig` nonce. Defaults to {@link DEFAULT_ZK_CONFIG_NONCE}. */
57
+ zkConfigNonce?: bigint;
58
+ /**
59
+ * Directory or URL prefix for graph/r1cs/proving-key files.
60
+ * Defaults to the GitHub release for this SDK version. Node also reads
61
+ * `ZK_ARTIFACT_BASE_URL`.
62
+ */
63
+ zkArtifactBaseUrl?: string;
54
64
  }
@@ -1,11 +1,11 @@
1
1
  import type { TransactionAuditParams } from './transaction-audit';
2
2
  import type { WithdrawMerkleWitness } from './types';
3
- /** Matches `Transaction(20, 2, 2, publicNInputs, publicNOutputs, 4, 9)` in `circuits/main.circom`. */
3
+ /** Matches `Transaction(20, 2, 2, publicNInputs, publicNOutputs, 4, 12, 6)` in `circuits/main.circom`. */
4
4
  export declare const TRANSACTION_TREE_DEPTH = 20;
5
5
  export declare const TRANSACTION_N_INS = 2;
6
6
  export declare const TRANSACTION_N_OUTS = 2;
7
7
  export declare const TRANSACTION_N_AUDIT_SLOTS = 4;
8
- export declare const NOTE_AUDIT_LEN = 9;
8
+ export declare const NOTE_AUDIT_LEN = 12;
9
9
  export declare const NOTE_OUTPUT_LEN = 6;
10
10
  /** Must match `Transaction(..., publicNInputs, publicNOutputs)` and contract `get_public_slot_config`. */
11
11
  export declare const TRANSACTION_PUBLIC_N_INPUTS = 1;
@@ -24,7 +24,15 @@ export interface WithdrawalProofPublicParams {
24
24
  withdrawAddressHi: string;
25
25
  /** Decimal string, circom `withdrawAddressLo` (Ed25519 key bytes [16..32] as big-endian u128). */
26
26
  withdrawAddressLo: string;
27
- /** Decimal string, circom `privKeyScalar`. */
27
+ /** Decimal string, circom `escrowRecipientHi`. */
28
+ escrowRecipientHi?: string;
29
+ /** Decimal string, circom `escrowRecipientLo`. */
30
+ escrowRecipientLo?: string;
31
+ /** Decimal string, circom `sweepOutputOwnerPubX`. Zero off-sweep. */
32
+ sweepOutputOwnerPubX?: string;
33
+ /** Decimal string, circom `sweepOutputOwnerPubY`. Zero off-sweep. */
34
+ sweepOutputOwnerPubY?: string;
35
+ /** Decimal string, default owner scalar copied onto dummy withdraw slots. */
28
36
  privKeyScalar: string;
29
37
  }
30
38
  /** Public accounting legs (`publicWithdrawnAssets`, `publicDepositedAssets`, `publicDeposits`, `publicWithdrawals`). */
@@ -35,7 +43,8 @@ export interface TransactionPublicLegParams {
35
43
  publicWithdrawals: string[];
36
44
  }
37
45
  /** All-zero public legs (private-only pool moves). */
38
- export declare function zeroPublicLegs(): TransactionPublicLegParams;
46
+ export declare function zeroPublicLegs(publicNInputs?: number, publicNOutputs?: number): TransactionPublicLegParams;
47
+ export declare function padPublicLegs(legs: TransactionPublicLegParams, publicNInputs: number, publicNOutputs: number): TransactionPublicLegParams;
39
48
  /** Real withdraw leg; coordinates are decimal field strings (same as `CoinData`). */
40
49
  export interface WithdrawObject {
41
50
  value: string;
@@ -45,8 +54,13 @@ export interface WithdrawObject {
45
54
  asset: [string, string];
46
55
  /** BN254 Fr decimal; `0` for dummy slots. */
47
56
  applicationId: string;
48
- /** Depositor ECDH point `[x, y]` as decimal strings. */
49
- ephemeralKeys: [string, string];
57
+ /** Owner BabyJubJub public key `[x, y]` as decimal strings. */
58
+ ownerPub: [string, string];
59
+ /** Per-input owner scalar. */
60
+ privKeyScalar: string;
61
+ paddingRandom: string;
62
+ escrowNonce: string;
63
+ recipientStellar: [string, string];
50
64
  stateSiblings: string[];
51
65
  stateIndex: string;
52
66
  }
@@ -60,52 +74,46 @@ export interface DepositObject {
60
74
  applicationId: string;
61
75
  /** Recipient public key `[x, y]` as decimal strings. */
62
76
  recipientPublicKeys: [string, string];
77
+ escrowNonce?: string;
78
+ recipientStellar?: [string, string];
63
79
  }
64
80
  export type WithdrawSlot = WithdrawObject | 'dummy';
65
81
  export type DepositSlot = DepositObject | 'dummy';
66
- /** Witness calculator input for `circuits/main.circom` `Transaction(20,2,2,publicNInputs,publicNOutputs)`. */
82
+ /** Witness calculator input for a `Transaction(20, nIns, nOuts, …)` instantiation. */
67
83
  export interface TransactionWitnessInput {
68
84
  stateRoot: string;
69
85
  withdrawAddressHi: string;
70
86
  withdrawAddressLo: string;
71
- privKeyScalar: string;
72
- withdrawnValues: [string, string];
73
- withdrawnNullifiers: [string, string];
74
- withdrawnSecrets: [string, string];
75
- withdrawnAssets: [[string, string], [string, string]];
76
- ephemeralKeys: [[string, string], [string, string]];
77
- stateSiblings: [string[], string[]];
78
- stateIndex: [string, string];
79
- depositedValues: [string, string];
80
- depositedNullifiers: [string, string];
81
- depositedAssets: [[string, string], [string, string]];
82
- depositedEphemeralKeyScalars: [string, string];
83
- depositedRecipientPublicKeys: [[string, string], [string, string]];
87
+ escrowRecipientHi: string;
88
+ escrowRecipientLo: string;
89
+ sweepOutputOwnerPubX: string;
90
+ sweepOutputOwnerPubY: string;
91
+ privKeyScalars: string[];
92
+ ownerPubs: Array<[string, string]>;
93
+ paddingRandoms: string[];
94
+ withdrawnValues: string[];
95
+ withdrawnNullifiers: string[];
96
+ withdrawnSecrets: string[];
97
+ withdrawnAssets: Array<[string, string]>;
98
+ withdrawnEscrowNonces: string[];
99
+ inputRecipientStellar: Array<[string, string]>;
100
+ stateSiblings: string[][];
101
+ stateIndex: string[];
102
+ depositedValues: string[];
103
+ depositedNullifiers: string[];
104
+ depositedAssets: Array<[string, string]>;
105
+ depositedEphemeralKeyScalars: string[];
106
+ depositedRecipientPublicKeys: Array<[string, string]>;
107
+ depositedEscrowNonces: string[];
108
+ outputRecipientStellar: Array<[string, string]>;
84
109
  publicWithdrawnAssets: Array<[string, string]>;
85
110
  publicDepositedAssets: Array<[string, string]>;
86
111
  publicDeposits: string[];
87
112
  publicWithdrawals: string[];
88
- inputApplicationIds: [string, string];
89
- outputApplicationIds: [string, string];
90
- auditEphemeralScalars: [string, string, string, string];
91
- noteAuditPublicKeys: [
92
- [
93
- string,
94
- string
95
- ],
96
- [
97
- string,
98
- string
99
- ],
100
- [
101
- string,
102
- string
103
- ],
104
- [
105
- string,
106
- string
107
- ]
108
- ];
113
+ inputApplicationIds: string[];
114
+ outputApplicationIds: string[];
115
+ auditEphemeralScalar: string;
116
+ noteAuditPublicKey: [string, string];
109
117
  }
110
118
  export interface WasmEcdhPointFns {
111
119
  ecdhEphemeralPublicKeyFromScalarHex(scalarHex: string): {
@@ -137,11 +145,18 @@ export declare function randomFrDecimal(): string;
137
145
  /** Random scalar < 2^253 for BabyJub ECDH / `Num2Bits(253)` (uses {@link generateRandomScalarHex32}). */
138
146
  export declare function randomFrDecimal253(): string;
139
147
  export declare function resolveDepositsForWitness(depositSlots: [DepositSlot, DepositSlot], wasm: WasmEcdhPointFns): [DepositObject, DepositObject];
140
- export declare function buildTransactionWitnessInput(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdrawSlots: [WithdrawSlot, WithdrawSlot], depositSlots: [DepositSlot, DepositSlot], audit: TransactionAuditParams, wasm: WasmEcdhPointFns): TransactionWitnessInput;
148
+ export declare function padWithdrawSlots(slots: WithdrawSlot[], nIns: number): WithdrawSlot[];
149
+ export declare function padDepositSlots(slots: DepositSlot[], nOuts: number): DepositSlot[];
150
+ export declare function buildTransactionWitnessInput(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdrawSlots: WithdrawSlot[], depositSlots: DepositSlot[], audit: TransactionAuditParams, wasm: WasmEcdhPointFns, dims?: {
151
+ nIns?: number;
152
+ nOuts?: number;
153
+ publicNInputs?: number;
154
+ publicNOutputs?: number;
155
+ }): TransactionWitnessInput;
141
156
  /** `stpl1…` stealth address → `[x, y]` as decimal field strings for `depositedRecipientPublicKeys`. */
142
157
  export declare function recipientPublicKeysDecimalFromStealthAddress(stealthAddress: string): [string, string];
143
- /** First withdraw leg: Merkle witness + depositor ECDH point coordinates (hex). */
144
- export declare function withdrawObjectFromMerkleWitness(witness: WithdrawMerkleWitness, depositorEphemeralHex: {
158
+ /** First withdraw leg: Merkle witness + owner public key (hex) and matching scalar. */
159
+ export declare function withdrawObjectFromMerkleWitness(witness: WithdrawMerkleWitness, ownerPubHex: {
145
160
  x: string;
146
161
  y: string;
147
- }, applicationId: string): WithdrawObject;
162
+ }, applicationId: string, privKeyScalar: string): WithdrawObject;
package/dist/witness.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { TransactionWitnessInput } from './withdrawal-transaction-input';
2
- export declare function generateWitness(input: TransactionWitnessInput, circuitWasm?: BufferSource): Promise<Uint8Array>;
2
+ /** @deprecated Witness generation is in the main SDK WASM (`proveGroth16`). */
3
+ export declare function generateWitness(_input: TransactionWitnessInput, _circuitWasm?: BufferSource, _wasmFileName?: string): Promise<Uint8Array>;
@@ -0,0 +1,4 @@
1
+ export declare const ZK_ARTIFACT_GITHUB_REPO = "Polynom-Labs/stellar-privacy-layer-contracts";
2
+ export declare const ZK_SDK_PACKAGE_VERSION = "__ZK_SDK_PACKAGE_VERSION__";
3
+ export declare function defaultZkArtifactBaseUrl(version?: string): string;
4
+ export declare function trimArtifactBaseUrl(value: string): string;