@auditable/privacy-pool-zk-sdk 0.8.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.
- package/dist/ciphertext-blob.d.ts +17 -0
- package/dist/circuit-artifacts.d.ts +9 -0
- package/dist/cli.js +769 -591
- package/dist/cli.js.map +1 -1
- package/dist/domain-separators.d.ts +6 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.mjs +1122 -889
- package/dist/index.mjs.map +1 -1
- package/dist/kyt-flow.d.ts +2 -0
- package/dist/kyt-passage.d.ts +17 -3
- package/dist/output-note-encryption.d.ts +31 -2
- package/dist/prover.d.ts +3 -3
- package/dist/sdk.d.ts +22 -18
- package/dist/transaction-audit.d.ts +8 -12
- package/dist/types.d.ts +12 -4
- package/dist/withdrawal-transaction-input.d.ts +33 -42
- package/dist/witness.d.ts +2 -1
- package/dist/zk-artifact-url.d.ts +4 -0
- package/dist/zk-layout.d.ts +84 -0
- package/package.json +4 -9
- package/pkg/client_sdk_wasm.d.ts +6 -0
- package/pkg/client_sdk_wasm.js +39 -0
- package/pkg/client_sdk_wasm_bg.wasm +0 -0
- package/pkg/client_sdk_wasm_bg.wasm.d.ts +1 -0
- package/assets/main.wasm +0 -0
- package/assets/main_final.zkey +0 -0
- package/assets/witness_calculator.js +0 -383
package/dist/kyt-flow.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface RegisterPassageParams {
|
|
|
6
6
|
owner: string;
|
|
7
7
|
nonce?: bigint | number;
|
|
8
8
|
publicSignalsBytes: Buffer | string;
|
|
9
|
+
ciphertextBytes?: Buffer | string;
|
|
9
10
|
publicLegContext: PublicLegContextInput;
|
|
10
11
|
signature: string;
|
|
11
12
|
expiresAtLedger: number;
|
|
@@ -19,6 +20,7 @@ export interface SubmitKytTransactParams {
|
|
|
19
20
|
nonce: bigint | number;
|
|
20
21
|
proofBytes: Buffer;
|
|
21
22
|
publicSignalsBytes: Buffer;
|
|
23
|
+
ciphertextBytes?: Buffer;
|
|
22
24
|
/** Omit when the pool's own registered passage covers this call (no explicit signed authorization). */
|
|
23
25
|
kytAuthorization?: {
|
|
24
26
|
expirationLedger: number;
|
package/dist/kyt-passage.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const KYT_PASSAGE_AUTH_DOMAIN = "privacy-pool-kyt-passage-v1";
|
|
2
2
|
export declare const PUBLIC_LEG_CONTEXT_DOMAIN = "privacy-pool-public-leg-context-v1";
|
|
3
|
-
export declare const PASSAGE_ID_DOMAIN = "privacy-pool-passage-id-
|
|
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";
|
|
4
5
|
export declare const PASSAGE_ID_DOMAIN_V1 = "privacy-pool-passage-id-v1";
|
|
5
6
|
export declare const NOTE_AUDIT_LEN = 12;
|
|
6
7
|
export declare const TOTAL_PUBLIC_SIGNALS = 93;
|
|
@@ -34,7 +35,8 @@ export declare function zeroAddressSentinelBuffer(): Buffer;
|
|
|
34
35
|
export declare function addressToCanonicalXdr(address: string): Buffer;
|
|
35
36
|
export declare function hashPublicSignalBytes(publicSignalsBytes: Buffer | string, zkConfigNonce?: bigint): string;
|
|
36
37
|
export declare function hashPublicLegContext(layout: PublicLegLayout, input: PublicLegContextInput): string;
|
|
37
|
-
export declare function derivePassageId(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: 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;
|
|
38
40
|
export declare function derivePassageIdV1(owner: string, nonce: bigint | number, publicSignalHash: string, publicLegContextHash: string, onboardingHash: string): string;
|
|
39
41
|
export declare function buildKytPassageAuthorization(input: {
|
|
40
42
|
poolContract: string;
|
|
@@ -46,9 +48,18 @@ export declare function derivePassageFromTransactContext(input: {
|
|
|
46
48
|
owner: string;
|
|
47
49
|
nonce?: bigint | number;
|
|
48
50
|
publicSignalsBytes: Buffer | string;
|
|
51
|
+
ciphertextBytes?: Buffer | string;
|
|
49
52
|
publicLegContext: PublicLegContextInput;
|
|
50
53
|
layout?: PublicLegLayout;
|
|
51
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;
|
|
52
63
|
export declare function accountIdFromAddress(address: string): Buffer;
|
|
53
64
|
export interface InspectKytPassageRequest {
|
|
54
65
|
owner: string;
|
|
@@ -56,8 +67,11 @@ export interface InspectKytPassageRequest {
|
|
|
56
67
|
kytRegistry: string;
|
|
57
68
|
proofBytes: string;
|
|
58
69
|
publicSignalsBytes: string;
|
|
59
|
-
applicationIdsPlaintext: [
|
|
70
|
+
applicationIdsPlaintext: string[];
|
|
71
|
+
ciphertextBytes?: string;
|
|
72
|
+
outputNoteEphemeralScalars?: string[];
|
|
60
73
|
nonce?: string;
|
|
74
|
+
zkConfigNonce?: string;
|
|
61
75
|
}
|
|
62
76
|
export interface InspectKytPassageApproved {
|
|
63
77
|
status: 'approved';
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import
|
|
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
|
|
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;
|
|
@@ -28,6 +31,13 @@ export type OutputNoteEventInput = {
|
|
|
28
31
|
tag: string;
|
|
29
32
|
ownerMode?: bigint;
|
|
30
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;
|
|
31
41
|
export declare function secretFromDepositEphemeralScalarDecimal(ephemeralKeyScalarDecimal: string): Promise<string>;
|
|
32
42
|
export declare function encryptOutputNoteForDeposit(parameters: {
|
|
33
43
|
deposit: DepositObject;
|
|
@@ -41,3 +51,22 @@ export declare function buildOutputNoteEncryptionPublicInputs(parameters: {
|
|
|
41
51
|
outputNoteTags: [string, string];
|
|
42
52
|
}>;
|
|
43
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
|
-
|
|
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,24 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import { type
|
|
4
|
-
import type
|
|
5
|
-
import type {
|
|
6
|
-
import { type DepositSlot, type TransactionPublicLegParams, type WithdrawalProofPublicParams, type WithdrawSlot } from
|
|
7
|
-
import { type TransactionAuditParams } from
|
|
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";
|
|
8
9
|
export declare class PrivacyPoolSDK {
|
|
9
10
|
private wasm;
|
|
10
11
|
private options;
|
|
12
|
+
private zkConfigNonce;
|
|
13
|
+
private circuitConfig;
|
|
14
|
+
private layout;
|
|
15
|
+
private circuitArtifacts;
|
|
11
16
|
private constructor();
|
|
17
|
+
getZkConfigNonce(): bigint;
|
|
18
|
+
getLayout(): ZkLayoutParams;
|
|
12
19
|
/**
|
|
13
20
|
* Initialize the SDK by loading WASM modules.
|
|
14
21
|
*
|
|
15
|
-
* In Node.js,
|
|
16
|
-
*
|
|
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:
|
|
17
25
|
* ```ts
|
|
18
26
|
* const sdk = await PrivacyPoolSDK.init({
|
|
19
27
|
* wasmBinary: await fetch('/pkg/client_sdk_wasm_bg.wasm').then(r => r.arrayBuffer()),
|
|
20
|
-
*
|
|
21
|
-
* 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',
|
|
22
29
|
* });
|
|
23
30
|
* ```
|
|
24
31
|
*/
|
|
@@ -97,14 +104,11 @@ export declare class PrivacyPoolSDK {
|
|
|
97
104
|
/** Circuit `ECDH`: scalar (32-byte hex) × recipient BabyJub point → shared key hex coords. */
|
|
98
105
|
ecdhSharedKey(scalarHex: string, recipientPubXHex: string, recipientPubYHex: string): SharedSecret;
|
|
99
106
|
/**
|
|
100
|
-
* `Transaction(20,
|
|
101
|
-
*
|
|
102
|
-
* @param publicParams Public inputs: `stateRoot`, `withdrawAddressHi` / `withdrawAddressLo`, `privKeyScalar` (decimal field strings).
|
|
103
|
-
* @param publicLegs Public token legs (`publicWithdrawnAssets`, `publicDepositedAssets`, `publicDeposits`, `publicWithdrawals`).
|
|
104
|
-
* @param withdraws Exactly two withdraw slots (`WithdrawObject` or `"dummy"`).
|
|
105
|
-
* @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).
|
|
106
109
|
*/
|
|
107
|
-
proveTransaction(publicParams: WithdrawalProofPublicParams, publicLegs: TransactionPublicLegParams, withdraws: [
|
|
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>;
|
|
108
112
|
/**
|
|
109
113
|
* Calculate owner-bound nullifier hash: Poseidon(DOM_NULLIFIER, nullifier, privKeyScalar)
|
|
110
114
|
* @param nullifier Nullifier decimal string from coin data
|
|
@@ -1,25 +1,21 @@
|
|
|
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
|
-
|
|
10
|
-
|
|
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: [
|
|
19
|
-
outputApplicationIds: [
|
|
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: [
|
|
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
21
|
/**
|
|
@@ -27,4 +23,4 @@ export declare function withApplicationIdOnWithdraw(withdraw: WithdrawObject, ap
|
|
|
27
23
|
* then the built-in demo key. Used by CLI/`demo.sh` for per-app audit pubkeys.
|
|
28
24
|
*/
|
|
29
25
|
export declare function resolveAuditPublicKeyFromEnv(auditPublicKey?: AuditPublicKey): AuditPublicKey;
|
|
30
|
-
export declare function resolveTransactionAuditParams(applicationId: string, auditPublicKey?: AuditPublicKey): TransactionAuditParams;
|
|
26
|
+
export declare function resolveTransactionAuditParams(applicationId: string, auditPublicKey?: AuditPublicKey, nAuditSlots?: number): TransactionAuditParams;
|
package/dist/types.d.ts
CHANGED
|
@@ -45,12 +45,20 @@ export interface StateFile {
|
|
|
45
45
|
export interface WithdrawResult {
|
|
46
46
|
proof_hex: string;
|
|
47
47
|
public_hex: string;
|
|
48
|
+
ciphertext_hex: string;
|
|
49
|
+
output_note_ephemeral_scalars: string[];
|
|
48
50
|
}
|
|
49
51
|
export interface SDKOptions {
|
|
50
52
|
/** Pre-loaded Rust WASM binary (ArrayBuffer). Required in browser. */
|
|
51
53
|
wasmBinary?: BufferSource;
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
|
|
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;
|
|
56
64
|
}
|
|
@@ -43,7 +43,8 @@ export interface TransactionPublicLegParams {
|
|
|
43
43
|
publicWithdrawals: string[];
|
|
44
44
|
}
|
|
45
45
|
/** All-zero public legs (private-only pool moves). */
|
|
46
|
-
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;
|
|
47
48
|
/** Real withdraw leg; coordinates are decimal field strings (same as `CoinData`). */
|
|
48
49
|
export interface WithdrawObject {
|
|
49
50
|
value: string;
|
|
@@ -78,7 +79,7 @@ export interface DepositObject {
|
|
|
78
79
|
}
|
|
79
80
|
export type WithdrawSlot = WithdrawObject | 'dummy';
|
|
80
81
|
export type DepositSlot = DepositObject | 'dummy';
|
|
81
|
-
/** Witness calculator input for
|
|
82
|
+
/** Witness calculator input for a `Transaction(20, nIns, nOuts, …)` instantiation. */
|
|
82
83
|
export interface TransactionWitnessInput {
|
|
83
84
|
stateRoot: string;
|
|
84
85
|
withdrawAddressHi: string;
|
|
@@ -87,49 +88,32 @@ export interface TransactionWitnessInput {
|
|
|
87
88
|
escrowRecipientLo: string;
|
|
88
89
|
sweepOutputOwnerPubX: string;
|
|
89
90
|
sweepOutputOwnerPubY: string;
|
|
90
|
-
privKeyScalars: [
|
|
91
|
-
ownerPubs: [
|
|
92
|
-
paddingRandoms: [
|
|
93
|
-
withdrawnValues: [
|
|
94
|
-
withdrawnNullifiers: [
|
|
95
|
-
withdrawnSecrets: [
|
|
96
|
-
withdrawnAssets: [
|
|
97
|
-
withdrawnEscrowNonces: [
|
|
98
|
-
inputRecipientStellar: [
|
|
99
|
-
stateSiblings:
|
|
100
|
-
stateIndex: [
|
|
101
|
-
depositedValues: [
|
|
102
|
-
depositedNullifiers: [
|
|
103
|
-
depositedAssets: [
|
|
104
|
-
depositedEphemeralKeyScalars: [
|
|
105
|
-
depositedRecipientPublicKeys: [
|
|
106
|
-
depositedEscrowNonces: [
|
|
107
|
-
outputRecipientStellar: [
|
|
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]>;
|
|
108
109
|
publicWithdrawnAssets: Array<[string, string]>;
|
|
109
110
|
publicDepositedAssets: Array<[string, string]>;
|
|
110
111
|
publicDeposits: string[];
|
|
111
112
|
publicWithdrawals: string[];
|
|
112
|
-
inputApplicationIds: [
|
|
113
|
-
outputApplicationIds: [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
[
|
|
117
|
-
string,
|
|
118
|
-
string
|
|
119
|
-
],
|
|
120
|
-
[
|
|
121
|
-
string,
|
|
122
|
-
string
|
|
123
|
-
],
|
|
124
|
-
[
|
|
125
|
-
string,
|
|
126
|
-
string
|
|
127
|
-
],
|
|
128
|
-
[
|
|
129
|
-
string,
|
|
130
|
-
string
|
|
131
|
-
]
|
|
132
|
-
];
|
|
113
|
+
inputApplicationIds: string[];
|
|
114
|
+
outputApplicationIds: string[];
|
|
115
|
+
auditEphemeralScalar: string;
|
|
116
|
+
noteAuditPublicKey: [string, string];
|
|
133
117
|
}
|
|
134
118
|
export interface WasmEcdhPointFns {
|
|
135
119
|
ecdhEphemeralPublicKeyFromScalarHex(scalarHex: string): {
|
|
@@ -161,7 +145,14 @@ export declare function randomFrDecimal(): string;
|
|
|
161
145
|
/** Random scalar < 2^253 for BabyJub ECDH / `Num2Bits(253)` (uses {@link generateRandomScalarHex32}). */
|
|
162
146
|
export declare function randomFrDecimal253(): string;
|
|
163
147
|
export declare function resolveDepositsForWitness(depositSlots: [DepositSlot, DepositSlot], wasm: WasmEcdhPointFns): [DepositObject, DepositObject];
|
|
164
|
-
export declare function
|
|
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;
|
|
165
156
|
/** `stpl1…` stealth address → `[x, y]` as decimal field strings for `depositedRecipientPublicKeys`. */
|
|
166
157
|
export declare function recipientPublicKeysDecimalFromStealthAddress(stealthAddress: string): [string, string];
|
|
167
158
|
/** First withdraw leg: Merkle witness + owner public key (hex) and matching scalar. */
|
package/dist/witness.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { TransactionWitnessInput } from './withdrawal-transaction-input';
|
|
2
|
-
|
|
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;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Off-chain ZK layout table. Must stay byte-identical to `libs/zk::ZkLayoutParams`. */
|
|
2
|
+
export declare const LEGACY_ZK_NONCE = 0n;
|
|
3
|
+
export declare const COMMITMENT_V2_ZK_NONCE = 2n;
|
|
4
|
+
export declare const BINDING_ZK_NONCE = 3n;
|
|
5
|
+
export declare const SIX_BY_SIX_ZK_NONCE = 6n;
|
|
6
|
+
export declare const SIX_BY_SIX_BINDING_ZK_NONCE = 7n;
|
|
7
|
+
export declare const LEGACY_PUBLIC_INPUT_PREFIX_LEN = 5;
|
|
8
|
+
export declare const V2_PUBLIC_INPUT_PREFIX_LEN = 7;
|
|
9
|
+
export declare const NOTE_AUDIT_LEN = 12;
|
|
10
|
+
export declare const NOTE_OUTPUT_LEN = 6;
|
|
11
|
+
export type CircuitProfileName = '2x2' | '6x6';
|
|
12
|
+
export declare enum BundledZkCircuit {
|
|
13
|
+
TwoByTwo = "2x2",
|
|
14
|
+
SixBySix = "6x6"
|
|
15
|
+
}
|
|
16
|
+
export interface ZkCircuitLayoutFields {
|
|
17
|
+
nIns: number;
|
|
18
|
+
nOuts: number;
|
|
19
|
+
publicNInputs: number;
|
|
20
|
+
publicNOutputs: number;
|
|
21
|
+
}
|
|
22
|
+
export type BundledZkCircuitConfig = ZkCircuitLayoutFields & {
|
|
23
|
+
circuit: BundledZkCircuit;
|
|
24
|
+
};
|
|
25
|
+
export type DevZkCircuitConfig = ZkCircuitLayoutFields & {
|
|
26
|
+
circuitGraph: BufferSource;
|
|
27
|
+
r1cs: BufferSource;
|
|
28
|
+
provingKey: BufferSource;
|
|
29
|
+
zkey?: BufferSource;
|
|
30
|
+
};
|
|
31
|
+
export type ZkCircuitConfig = BundledZkCircuitConfig | DevZkCircuitConfig;
|
|
32
|
+
export declare function isDevZkCircuitConfig(config: ZkCircuitConfig): config is DevZkCircuitConfig;
|
|
33
|
+
export declare const DEFAULT_ZK_CONFIG_NONCE = 3n;
|
|
34
|
+
export declare const DEFAULT_ZK_CIRCUITS: Record<string, BundledZkCircuitConfig>;
|
|
35
|
+
export declare function layoutFromCircuitConfig(config: ZkCircuitConfig): ZkLayoutParams;
|
|
36
|
+
export declare function resolveZkCircuitConfig(zkCircuits: Record<string, ZkCircuitConfig> | undefined, zkConfigNonce: bigint | undefined): {
|
|
37
|
+
nonce: bigint;
|
|
38
|
+
config: ZkCircuitConfig;
|
|
39
|
+
};
|
|
40
|
+
export declare function bundledCircuitFileNames(circuit: BundledZkCircuit): {
|
|
41
|
+
graphFileName: string;
|
|
42
|
+
r1csFileName: string;
|
|
43
|
+
provingKeyFileName: string;
|
|
44
|
+
verificationKeyFileName: string;
|
|
45
|
+
zkeyFileName: string;
|
|
46
|
+
};
|
|
47
|
+
export interface ZkLayoutParams {
|
|
48
|
+
nIns: number;
|
|
49
|
+
nOuts: number;
|
|
50
|
+
publicNInputs: number;
|
|
51
|
+
publicNOutputs: number;
|
|
52
|
+
nAuditSlots: number;
|
|
53
|
+
noteAuditLen: number;
|
|
54
|
+
noteOutputLen: number;
|
|
55
|
+
publicInputPrefixLen: number;
|
|
56
|
+
auditOffset: number;
|
|
57
|
+
outputNoteOffset: number;
|
|
58
|
+
}
|
|
59
|
+
export interface CircuitProfile {
|
|
60
|
+
name: CircuitProfileName;
|
|
61
|
+
nonce: bigint;
|
|
62
|
+
layout: ZkLayoutParams;
|
|
63
|
+
wasmFileName: string;
|
|
64
|
+
zkeyFileName: string;
|
|
65
|
+
}
|
|
66
|
+
export declare function zkLayoutFromShape(nIns: number, nOuts: number, publicNInputs: number, publicNOutputs: number, nAuditSlots: number, noteAuditLen: number, noteOutputLen: number, publicInputPrefixLen?: number): ZkLayoutParams;
|
|
67
|
+
export declare function zkLayoutFromShapeBinding(nIns: number, nOuts: number, publicNInputs: number, publicNOutputs: number, nAuditSlots: number, noteAuditLen: number, noteOutputLen: number): ZkLayoutParams;
|
|
68
|
+
export declare function ciphertextsInPublicSignals(layout: ZkLayoutParams): boolean;
|
|
69
|
+
export declare function ciphertextFieldCount(layout: ZkLayoutParams): number;
|
|
70
|
+
export declare function auditEphemeralPublicKeyCount(layout: ZkLayoutParams): number;
|
|
71
|
+
export declare function indexAuditEphemeralPublicKeys(layout: ZkLayoutParams): number;
|
|
72
|
+
export declare function indexAuditTags(layout: ZkLayoutParams): number;
|
|
73
|
+
export declare function indexOutputNoteTags(layout: ZkLayoutParams): number;
|
|
74
|
+
export declare function publicOutputsLen(layout: ZkLayoutParams): number;
|
|
75
|
+
export declare function totalPublicSignals(layout: ZkLayoutParams): number;
|
|
76
|
+
export declare function stateRootIndex(layout: ZkLayoutParams): number;
|
|
77
|
+
export declare function legacyOwnerBoundLayout(): ZkLayoutParams;
|
|
78
|
+
export declare function standardLayout(): ZkLayoutParams;
|
|
79
|
+
export declare function sixBySixLayout(): ZkLayoutParams;
|
|
80
|
+
export declare function standardBindingLayout(): ZkLayoutParams;
|
|
81
|
+
export declare function sixBySixBindingLayout(): ZkLayoutParams;
|
|
82
|
+
export declare function layoutForKnownNonce(nonce: bigint): ZkLayoutParams;
|
|
83
|
+
export declare function circuitProfileFromName(name: string): CircuitProfile;
|
|
84
|
+
export declare function circuitProfileFromNonce(nonce: bigint): CircuitProfile;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auditable/privacy-pool-zk-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1-rc.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",
|
|
@@ -10,10 +10,7 @@
|
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
},
|
|
13
|
-
"./main.zkey": "./assets/main_final.zkey",
|
|
14
|
-
"./witness.wasm": "./assets/main.wasm",
|
|
15
13
|
"./sdk.wasm": "./pkg/client_sdk_wasm_bg.wasm",
|
|
16
|
-
"./assets/witness_calculator.js": "./assets/witness_calculator.js",
|
|
17
14
|
"./pkg/client_sdk_wasm.js": "./pkg/client_sdk_wasm.js"
|
|
18
15
|
},
|
|
19
16
|
"bin": {
|
|
@@ -28,15 +25,14 @@
|
|
|
28
25
|
},
|
|
29
26
|
"files": [
|
|
30
27
|
"dist/",
|
|
31
|
-
"pkg/"
|
|
32
|
-
"assets/"
|
|
28
|
+
"pkg/"
|
|
33
29
|
],
|
|
34
30
|
"scripts": {
|
|
35
31
|
"build:wasm": "cd crate && wasm-pack build --target web --out-dir ../pkg",
|
|
36
32
|
"build:ts": "rollup -c",
|
|
37
33
|
"build": "rollup -c",
|
|
38
34
|
"cli": "node dist/cli.js",
|
|
39
|
-
"test:kyt": "node test/kyt-flow-atomic.mjs && node test/kyt-public-leg-context.mjs && node test/kyt-passage-id-auth.mjs && node test/derived-escrow-key.mjs && node test/spend-scalar-domain.mjs && node test/eighteen-decimal-value.mjs && node test/no-onboarding-exports.mjs && node test/owner-bound-witness-check.mjs",
|
|
35
|
+
"test:kyt": "node test/kyt-flow-atomic.mjs && node test/kyt-public-leg-context.mjs && node test/kyt-passage-id-auth.mjs && node test/derived-escrow-key.mjs && node test/spend-scalar-domain.mjs && node test/eighteen-decimal-value.mjs && node test/zk-artifact-url.mjs && node test/no-onboarding-exports.mjs && node test/owner-bound-witness-check.mjs && node test/six-by-six-layout.mjs && node test/six-by-six-witness-proof.mjs",
|
|
40
36
|
"test:output-note": "node test/output-note-encryption.mjs"
|
|
41
37
|
},
|
|
42
38
|
"dependencies": {
|
|
@@ -44,8 +40,7 @@
|
|
|
44
40
|
"@stellar/stellar-sdk": "^16.0.1",
|
|
45
41
|
"bech32": "^2.0.0",
|
|
46
42
|
"circomlibjs": "^0.1.7",
|
|
47
|
-
"ffjavascript": "^0.3.0"
|
|
48
|
-
"snarkjs": "^0.7.0"
|
|
43
|
+
"ffjavascript": "^0.3.0"
|
|
49
44
|
},
|
|
50
45
|
"devDependencies": {
|
|
51
46
|
"@rollup/plugin-alias": "^5.0.0",
|
package/pkg/client_sdk_wasm.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ export function generateCoinWithOwnerPubHex(owner_x_hex: string, owner_y_hex: st
|
|
|
63
63
|
*/
|
|
64
64
|
export function proofToHex(proof_json: string): string;
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Graph witness + arkworks Groth16 prove. Returns `{ proof_hex, public_hex }`.
|
|
68
|
+
*/
|
|
69
|
+
export function proveGroth16(graph: Uint8Array, proving_key: Uint8Array, r1cs: Uint8Array, inputs_json: string): any;
|
|
70
|
+
|
|
66
71
|
/**
|
|
67
72
|
* Convert snarkjs public signals JSON to hex bytes for Soroban contract.
|
|
68
73
|
*/
|
|
@@ -83,6 +88,7 @@ export interface InitOutput {
|
|
|
83
88
|
readonly generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
|
|
84
89
|
readonly generateCoinWithOwnerPubHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
|
|
85
90
|
readonly proofToHex: (a: number, b: number, c: number) => void;
|
|
91
|
+
readonly proveGroth16: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
86
92
|
readonly publicToHex: (a: number, b: number, c: number) => void;
|
|
87
93
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
88
94
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
package/pkg/client_sdk_wasm.js
CHANGED
|
@@ -351,6 +351,38 @@ export function proofToHex(proof_json) {
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Graph witness + arkworks Groth16 prove. Returns `{ proof_hex, public_hex }`.
|
|
356
|
+
* @param {Uint8Array} graph
|
|
357
|
+
* @param {Uint8Array} proving_key
|
|
358
|
+
* @param {Uint8Array} r1cs
|
|
359
|
+
* @param {string} inputs_json
|
|
360
|
+
* @returns {any}
|
|
361
|
+
*/
|
|
362
|
+
export function proveGroth16(graph, proving_key, r1cs, inputs_json) {
|
|
363
|
+
try {
|
|
364
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
365
|
+
const ptr0 = passArray8ToWasm0(graph, wasm.__wbindgen_export);
|
|
366
|
+
const len0 = WASM_VECTOR_LEN;
|
|
367
|
+
const ptr1 = passArray8ToWasm0(proving_key, wasm.__wbindgen_export);
|
|
368
|
+
const len1 = WASM_VECTOR_LEN;
|
|
369
|
+
const ptr2 = passArray8ToWasm0(r1cs, wasm.__wbindgen_export);
|
|
370
|
+
const len2 = WASM_VECTOR_LEN;
|
|
371
|
+
const ptr3 = passStringToWasm0(inputs_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
372
|
+
const len3 = WASM_VECTOR_LEN;
|
|
373
|
+
wasm.proveGroth16(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
374
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
375
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
376
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
377
|
+
if (r2) {
|
|
378
|
+
throw takeObject(r1);
|
|
379
|
+
}
|
|
380
|
+
return takeObject(r0);
|
|
381
|
+
} finally {
|
|
382
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
354
386
|
/**
|
|
355
387
|
* Convert snarkjs public signals JSON to hex bytes for Soroban contract.
|
|
356
388
|
* @param {string} public_json
|
|
@@ -561,6 +593,13 @@ function isLikeNone(x) {
|
|
|
561
593
|
return x === undefined || x === null;
|
|
562
594
|
}
|
|
563
595
|
|
|
596
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
597
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
598
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
599
|
+
WASM_VECTOR_LEN = arg.length;
|
|
600
|
+
return ptr;
|
|
601
|
+
}
|
|
602
|
+
|
|
564
603
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
565
604
|
if (realloc === undefined) {
|
|
566
605
|
const buf = cachedTextEncoder.encode(arg);
|
|
Binary file
|
|
@@ -12,6 +12,7 @@ export const generateCoinForDepositWithOwnerPubHex: (a: number, b: number, c: nu
|
|
|
12
12
|
export const generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
|
|
13
13
|
export const generateCoinWithOwnerPubHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
|
|
14
14
|
export const proofToHex: (a: number, b: number, c: number) => void;
|
|
15
|
+
export const proveGroth16: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
15
16
|
export const publicToHex: (a: number, b: number, c: number) => void;
|
|
16
17
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
17
18
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
package/assets/main.wasm
DELETED
|
Binary file
|
package/assets/main_final.zkey
DELETED
|
Binary file
|