@sip-protocol/sdk 0.2.1 → 0.2.2

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/index.mjs CHANGED
@@ -3,18 +3,14 @@ import {
3
3
  BaseWalletAdapter,
4
4
  CHAIN_NUMERIC_IDS,
5
5
  ComplianceManager,
6
- CryptoError,
7
6
  DEFAULT_THRESHOLD,
8
7
  DEFAULT_TOTAL_ORACLES,
9
8
  DerivationPath,
10
- EncryptionNotImplementedError,
11
- ErrorCode,
12
9
  EthereumChainId,
13
10
  EthereumWalletAdapter,
14
11
  HardwareErrorCode,
15
12
  HardwareWalletError,
16
13
  IntentBuilder,
17
- IntentError,
18
14
  IntentStatus,
19
15
  LedgerWalletAdapter,
20
16
  MockEthereumAdapter,
@@ -26,8 +22,6 @@ import {
26
22
  MockWalletAdapter,
27
23
  NATIVE_TOKENS,
28
24
  NEARIntentsAdapter,
29
- NetworkError,
30
- NoirProofProvider,
31
25
  ORACLE_DOMAIN,
32
26
  OneClickClient,
33
27
  OneClickDepositMode,
@@ -37,13 +31,9 @@ import {
37
31
  PaymentBuilder,
38
32
  PaymentStatus,
39
33
  PrivacyLevel,
40
- ProofError,
41
- ProofGenerationError,
42
- ProofNotImplementedError,
43
34
  ProposalStatus,
44
35
  ReportStatus,
45
36
  SIP,
46
- SIPError,
47
37
  SIP_VERSION,
48
38
  STABLECOIN_ADDRESSES,
49
39
  STABLECOIN_DECIMALS,
@@ -51,7 +41,6 @@ import {
51
41
  SolanaWalletAdapter,
52
42
  Treasury,
53
43
  TrezorWalletAdapter,
54
- ValidationError,
55
44
  WalletError,
56
45
  WalletErrorCode,
57
46
  ZcashErrorCode,
@@ -127,7 +116,6 @@ import {
127
116
  getCurveForChain,
128
117
  getDefaultRpcEndpoint,
129
118
  getDerivationPath,
130
- getErrorMessage,
131
119
  getEthereumProvider,
132
120
  getGenerators,
133
121
  getIntentSummary,
@@ -142,7 +130,6 @@ import {
142
130
  getSupportedStablecoins,
143
131
  getTimeRemaining,
144
132
  hasEnoughOracles,
145
- hasErrorCode,
146
133
  hasRequiredProofs,
147
134
  hash,
148
135
  hexToBytes,
@@ -154,7 +141,6 @@ import {
154
141
  isPaymentExpired,
155
142
  isPrivate,
156
143
  isPrivateWalletAdapter,
157
- isSIPError,
158
144
  isStablecoin,
159
145
  isStablecoinOnChain,
160
146
  isValidAmount,
@@ -210,9 +196,24 @@ import {
210
196
  verifyOracleSignature,
211
197
  walletRegistry,
212
198
  withSecureBuffer,
213
- withSecureBufferSync,
199
+ withSecureBufferSync
200
+ } from "./chunk-DU7LQDD2.mjs";
201
+ import {
202
+ CryptoError,
203
+ EncryptionNotImplementedError,
204
+ ErrorCode,
205
+ IntentError,
206
+ NetworkError,
207
+ ProofError,
208
+ ProofGenerationError,
209
+ ProofNotImplementedError,
210
+ SIPError,
211
+ ValidationError,
212
+ getErrorMessage,
213
+ hasErrorCode,
214
+ isSIPError,
214
215
  wrapError
215
- } from "./chunk-4VJHI66K.mjs";
216
+ } from "./chunk-UHZKNGIT.mjs";
216
217
  export {
217
218
  ATTESTATION_VERSION,
218
219
  BaseWalletAdapter,
@@ -242,7 +243,6 @@ export {
242
243
  NATIVE_TOKENS,
243
244
  NEARIntentsAdapter,
244
245
  NetworkError,
245
- NoirProofProvider,
246
246
  ORACLE_DOMAIN,
247
247
  OneClickClient,
248
248
  OneClickDepositMode,
@@ -0,0 +1,467 @@
1
+ import { ZKProof, HexString, Commitment } from '@sip-protocol/types';
2
+
3
+ /**
4
+ * Proof Provider Interface
5
+ *
6
+ * Defines a pluggable interface for ZK proof generation and verification.
7
+ * This allows different backends (Noir, mock for testing) to be swapped.
8
+ *
9
+ * @see docs/specs/ZK-ARCHITECTURE.md for framework decision (Noir)
10
+ */
11
+
12
+ /**
13
+ * Supported proof framework types
14
+ */
15
+ type ProofFramework = 'noir' | 'mock';
16
+ /**
17
+ * Parameters for generating a Funding Proof
18
+ *
19
+ * Proves: balance >= minimumRequired without revealing balance
20
+ *
21
+ * @see docs/specs/FUNDING-PROOF.md
22
+ */
23
+ interface FundingProofParams {
24
+ /** User's actual balance (private) */
25
+ balance: bigint;
26
+ /** Minimum amount required for the intent (public) */
27
+ minimumRequired: bigint;
28
+ /** Blinding factor for the commitment (private) */
29
+ blindingFactor: Uint8Array;
30
+ /** Asset identifier (public) */
31
+ assetId: string;
32
+ /** User's address for ownership proof (private) */
33
+ userAddress: string;
34
+ /** Signature proving ownership of the address (private) */
35
+ ownershipSignature: Uint8Array;
36
+ }
37
+ /**
38
+ * Public key coordinates for secp256k1 (X and Y as byte arrays)
39
+ */
40
+ interface PublicKeyXY {
41
+ /** X coordinate as 32-byte array */
42
+ x: Uint8Array;
43
+ /** Y coordinate as 32-byte array */
44
+ y: Uint8Array;
45
+ }
46
+ /**
47
+ * Parameters for generating a Validity Proof
48
+ *
49
+ * Proves: intent is authorized by sender without revealing sender
50
+ *
51
+ * @see docs/specs/VALIDITY-PROOF.md
52
+ */
53
+ interface ValidityProofParams {
54
+ /** Hash of the intent (public) */
55
+ intentHash: HexString;
56
+ /** Sender's address (private) */
57
+ senderAddress: string;
58
+ /** Blinding factor for sender commitment (private) */
59
+ senderBlinding: Uint8Array;
60
+ /** Sender's secret key (private) - used to derive public key if senderPublicKey not provided */
61
+ senderSecret: Uint8Array;
62
+ /** Signature authorizing the intent (private) */
63
+ authorizationSignature: Uint8Array;
64
+ /** Nonce for nullifier generation (private) */
65
+ nonce: Uint8Array;
66
+ /** Intent timestamp (public) */
67
+ timestamp: number;
68
+ /** Intent expiry (public) */
69
+ expiry: number;
70
+ /** Optional: Sender's public key. If not provided, derived from senderSecret */
71
+ senderPublicKey?: PublicKeyXY;
72
+ }
73
+ /**
74
+ * Parameters for generating a Fulfillment Proof
75
+ *
76
+ * Proves: solver delivered output >= minimum to correct recipient
77
+ *
78
+ * @see docs/specs/FULFILLMENT-PROOF.md
79
+ */
80
+ interface FulfillmentProofParams {
81
+ /** Hash of the original intent (public) */
82
+ intentHash: HexString;
83
+ /** Actual output amount delivered (private) */
84
+ outputAmount: bigint;
85
+ /** Blinding factor for output commitment (private) */
86
+ outputBlinding: Uint8Array;
87
+ /** Minimum required output from intent (public) */
88
+ minOutputAmount: bigint;
89
+ /** Recipient's stealth address (public) */
90
+ recipientStealth: HexString;
91
+ /** Solver's identifier (public) */
92
+ solverId: string;
93
+ /** Solver's secret for authorization (private) */
94
+ solverSecret: Uint8Array;
95
+ /** Oracle attestation of delivery (private) */
96
+ oracleAttestation: OracleAttestation;
97
+ /** Time of fulfillment (public) */
98
+ fulfillmentTime: number;
99
+ /** Intent expiry (public) */
100
+ expiry: number;
101
+ }
102
+ /**
103
+ * Oracle attestation for cross-chain verification
104
+ */
105
+ interface OracleAttestation {
106
+ /** Recipient who received funds */
107
+ recipient: HexString;
108
+ /** Amount received */
109
+ amount: bigint;
110
+ /** Transaction hash on destination chain */
111
+ txHash: HexString;
112
+ /** Block number containing the transaction */
113
+ blockNumber: bigint;
114
+ /** Oracle signature (threshold signature for multi-oracle) */
115
+ signature: Uint8Array;
116
+ }
117
+ /**
118
+ * Result of proof generation
119
+ */
120
+ interface ProofResult {
121
+ /** The generated proof */
122
+ proof: ZKProof;
123
+ /** Public inputs used in the proof */
124
+ publicInputs: HexString[];
125
+ /** Commitment (if generated as part of proof) */
126
+ commitment?: Commitment;
127
+ }
128
+ /**
129
+ * Proof Provider Interface
130
+ *
131
+ * Implementations of this interface provide ZK proof generation and verification.
132
+ * The SDK uses this interface to remain agnostic to the underlying ZK framework.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * // Use mock provider for testing
137
+ * const mockProvider = new MockProofProvider()
138
+ *
139
+ * // Use Noir provider for production
140
+ * const noirProvider = new NoirProofProvider()
141
+ *
142
+ * // Configure SIP client with provider
143
+ * const sip = new SIP({
144
+ * network: 'testnet',
145
+ * proofProvider: noirProvider,
146
+ * })
147
+ * ```
148
+ */
149
+ interface ProofProvider {
150
+ /**
151
+ * The ZK framework this provider uses
152
+ */
153
+ readonly framework: ProofFramework;
154
+ /**
155
+ * Whether the provider is ready to generate proofs
156
+ * (e.g., circuits compiled, keys loaded)
157
+ */
158
+ readonly isReady: boolean;
159
+ /**
160
+ * Initialize the provider (compile circuits, load keys, etc.)
161
+ *
162
+ * @throws Error if initialization fails
163
+ */
164
+ initialize(): Promise<void>;
165
+ /**
166
+ * Generate a Funding Proof
167
+ *
168
+ * Proves that the user has sufficient balance without revealing the exact amount.
169
+ *
170
+ * @param params - Funding proof parameters
171
+ * @returns The generated proof with public inputs
172
+ * @throws ProofGenerationError if proof generation fails
173
+ *
174
+ * @see docs/specs/FUNDING-PROOF.md (~22,000 constraints)
175
+ */
176
+ generateFundingProof(params: FundingProofParams): Promise<ProofResult>;
177
+ /**
178
+ * Generate a Validity Proof
179
+ *
180
+ * Proves that the intent is authorized without revealing the sender.
181
+ *
182
+ * @param params - Validity proof parameters
183
+ * @returns The generated proof with public inputs
184
+ * @throws ProofGenerationError if proof generation fails
185
+ *
186
+ * @see docs/specs/VALIDITY-PROOF.md (~72,000 constraints)
187
+ */
188
+ generateValidityProof(params: ValidityProofParams): Promise<ProofResult>;
189
+ /**
190
+ * Generate a Fulfillment Proof
191
+ *
192
+ * Proves that the solver correctly delivered the output.
193
+ *
194
+ * @param params - Fulfillment proof parameters
195
+ * @returns The generated proof with public inputs
196
+ * @throws ProofGenerationError if proof generation fails
197
+ *
198
+ * @see docs/specs/FULFILLMENT-PROOF.md (~22,000 constraints)
199
+ */
200
+ generateFulfillmentProof(params: FulfillmentProofParams): Promise<ProofResult>;
201
+ /**
202
+ * Verify a proof
203
+ *
204
+ * @param proof - The proof to verify
205
+ * @returns true if the proof is valid, false otherwise
206
+ */
207
+ verifyProof(proof: ZKProof): Promise<boolean>;
208
+ }
209
+ /**
210
+ * Error thrown when proof generation fails
211
+ */
212
+ declare class ProofGenerationError extends Error {
213
+ readonly proofType: 'funding' | 'validity' | 'fulfillment';
214
+ readonly cause?: Error;
215
+ constructor(proofType: 'funding' | 'validity' | 'fulfillment', message: string, cause?: Error);
216
+ }
217
+
218
+ /**
219
+ * Noir Proof Provider
220
+ *
221
+ * Production-ready ZK proof provider using Noir (Aztec) circuits.
222
+ *
223
+ * This provider generates cryptographically sound proofs using:
224
+ * - Funding Proof: ~2,000 constraints (docs/specs/FUNDING-PROOF.md)
225
+ * - Validity Proof: ~72,000 constraints (docs/specs/VALIDITY-PROOF.md)
226
+ * - Fulfillment Proof: ~22,000 constraints (docs/specs/FULFILLMENT-PROOF.md)
227
+ *
228
+ * @see docs/specs/ZK-ARCHITECTURE.md for framework decision
229
+ */
230
+
231
+ /**
232
+ * Public key coordinates for secp256k1
233
+ */
234
+ interface PublicKeyCoordinates {
235
+ /** X coordinate as 32-byte array */
236
+ x: number[];
237
+ /** Y coordinate as 32-byte array */
238
+ y: number[];
239
+ }
240
+ /**
241
+ * Noir Proof Provider Configuration
242
+ */
243
+ interface NoirProviderConfig {
244
+ /**
245
+ * Path to compiled circuit artifacts
246
+ * If not provided, uses bundled artifacts
247
+ */
248
+ artifactsPath?: string;
249
+ /**
250
+ * Backend to use for proof generation
251
+ * @default 'barretenberg' (UltraHonk)
252
+ */
253
+ backend?: 'barretenberg';
254
+ /**
255
+ * Enable verbose logging for debugging
256
+ * @default false
257
+ */
258
+ verbose?: boolean;
259
+ /**
260
+ * Oracle public key for verifying attestations in fulfillment proofs
261
+ * Required for production use. If not provided, proofs will use placeholder keys.
262
+ */
263
+ oraclePublicKey?: PublicKeyCoordinates;
264
+ }
265
+ /**
266
+ * Noir Proof Provider
267
+ *
268
+ * Production ZK proof provider using Noir circuits.
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * const provider = new NoirProofProvider()
273
+ *
274
+ * await provider.initialize()
275
+ *
276
+ * const result = await provider.generateFundingProof({
277
+ * balance: 100n,
278
+ * minimumRequired: 50n,
279
+ * blindingFactor: new Uint8Array(32),
280
+ * assetId: '0xABCD',
281
+ * userAddress: '0x1234...',
282
+ * ownershipSignature: new Uint8Array(64),
283
+ * })
284
+ * ```
285
+ */
286
+ declare class NoirProofProvider implements ProofProvider {
287
+ readonly framework: ProofFramework;
288
+ private _isReady;
289
+ private config;
290
+ private fundingNoir;
291
+ private fundingBackend;
292
+ private validityNoir;
293
+ private validityBackend;
294
+ private fulfillmentNoir;
295
+ private fulfillmentBackend;
296
+ constructor(config?: NoirProviderConfig);
297
+ get isReady(): boolean;
298
+ /**
299
+ * Derive secp256k1 public key coordinates from a private key
300
+ *
301
+ * Utility method that can be used to generate public key coordinates
302
+ * for use in ValidityProofParams.senderPublicKey or NoirProviderConfig.oraclePublicKey
303
+ *
304
+ * @param privateKey - 32-byte private key
305
+ * @returns X and Y coordinates as 32-byte arrays
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * const privateKey = new Uint8Array(32).fill(1) // Your secret key
310
+ * const publicKey = NoirProofProvider.derivePublicKey(privateKey)
311
+ *
312
+ * // Use for oracle configuration
313
+ * const provider = new NoirProofProvider({
314
+ * oraclePublicKey: publicKey
315
+ * })
316
+ *
317
+ * // Or use for validity proof params
318
+ * const validityParams = {
319
+ * // ... other params
320
+ * senderPublicKey: {
321
+ * x: new Uint8Array(publicKey.x),
322
+ * y: new Uint8Array(publicKey.y)
323
+ * }
324
+ * }
325
+ * ```
326
+ */
327
+ static derivePublicKey(privateKey: Uint8Array): PublicKeyCoordinates;
328
+ /**
329
+ * Initialize the Noir provider
330
+ *
331
+ * Loads circuit artifacts and initializes the proving backend.
332
+ */
333
+ initialize(): Promise<void>;
334
+ /**
335
+ * Generate a Funding Proof using Noir circuits
336
+ *
337
+ * Proves: balance >= minimumRequired without revealing balance
338
+ *
339
+ * @see docs/specs/FUNDING-PROOF.md
340
+ */
341
+ generateFundingProof(params: FundingProofParams): Promise<ProofResult>;
342
+ /**
343
+ * Generate a Validity Proof using Noir circuits
344
+ *
345
+ * Proves: Intent is authorized by sender without revealing identity
346
+ *
347
+ * @see docs/specs/VALIDITY-PROOF.md
348
+ */
349
+ generateValidityProof(params: ValidityProofParams): Promise<ProofResult>;
350
+ /**
351
+ * Generate a Fulfillment Proof using Noir circuits
352
+ *
353
+ * Proves: Solver correctly executed the intent and delivered the required
354
+ * output to the recipient, without revealing execution path or liquidity sources.
355
+ *
356
+ * @see docs/specs/FULFILLMENT-PROOF.md
357
+ */
358
+ generateFulfillmentProof(params: FulfillmentProofParams): Promise<ProofResult>;
359
+ /**
360
+ * Verify a Noir proof
361
+ */
362
+ verifyProof(proof: ZKProof): Promise<boolean>;
363
+ /**
364
+ * Destroy the provider and free resources
365
+ */
366
+ destroy(): Promise<void>;
367
+ private ensureReady;
368
+ /**
369
+ * Compute the commitment hash that the circuit expects
370
+ *
371
+ * The circuit computes:
372
+ * 1. commitment = pedersen_commitment([balance, blinding])
373
+ * 2. commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id])
374
+ *
375
+ * We need to compute this outside to pass as a public input.
376
+ *
377
+ * **IMPORTANT**: This SDK uses SHA256 as a deterministic stand-in for Pedersen hash.
378
+ * Both the SDK and circuit MUST use the same hash function. The bundled circuit
379
+ * artifacts are configured to use SHA256 for compatibility. If you use custom
380
+ * circuits with actual Pedersen hashing, you must update this implementation.
381
+ *
382
+ * @see docs/specs/HASH-COMPATIBILITY.md for hash function requirements
383
+ */
384
+ private computeCommitmentHash;
385
+ /**
386
+ * Convert asset ID to field element
387
+ */
388
+ private assetIdToField;
389
+ /**
390
+ * Convert bytes to field element string
391
+ */
392
+ private bytesToField;
393
+ /**
394
+ * Convert bigint to bytes
395
+ */
396
+ private bigintToBytes;
397
+ /**
398
+ * Convert hex string to bytes
399
+ */
400
+ private hexToBytes;
401
+ /**
402
+ * Convert hex string to field element string
403
+ */
404
+ private hexToField;
405
+ /**
406
+ * Convert field string to 32-byte array
407
+ */
408
+ private fieldToBytes32;
409
+ /**
410
+ * Compute sender commitment for validity proof
411
+ *
412
+ * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
413
+ * are compiled to use SHA256 for compatibility with this SDK.
414
+ *
415
+ * @see computeCommitmentHash for hash function compatibility notes
416
+ */
417
+ private computeSenderCommitment;
418
+ /**
419
+ * Compute nullifier for validity proof
420
+ *
421
+ * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
422
+ * are compiled to use SHA256 for compatibility with this SDK.
423
+ *
424
+ * @see computeCommitmentHash for hash function compatibility notes
425
+ */
426
+ private computeNullifier;
427
+ /**
428
+ * Compute output commitment for fulfillment proof
429
+ *
430
+ * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
431
+ * are compiled to use SHA256 for compatibility with this SDK.
432
+ *
433
+ * @see computeCommitmentHash for hash function compatibility notes
434
+ */
435
+ private computeOutputCommitment;
436
+ /**
437
+ * Compute solver ID from solver secret
438
+ *
439
+ * Uses SHA256 for SDK-side computation. The bundled circuit artifacts
440
+ * are compiled to use SHA256 for compatibility with this SDK.
441
+ *
442
+ * @see computeCommitmentHash for hash function compatibility notes
443
+ */
444
+ private computeSolverId;
445
+ /**
446
+ * Compute oracle message hash for fulfillment proof
447
+ *
448
+ * Hash of attestation data that oracle signs
449
+ */
450
+ private computeOracleMessageHash;
451
+ /**
452
+ * Derive secp256k1 public key coordinates from a private key
453
+ *
454
+ * @param privateKey - 32-byte private key as Uint8Array
455
+ * @returns X and Y coordinates as 32-byte arrays
456
+ */
457
+ private getPublicKeyCoordinates;
458
+ /**
459
+ * Derive public key coordinates from a field string (private key)
460
+ *
461
+ * @param privateKeyField - Private key as hex field string
462
+ * @returns X and Y coordinates as 32-byte arrays
463
+ */
464
+ private getPublicKeyFromField;
465
+ }
466
+
467
+ export { type FundingProofParams as F, type NoirProviderConfig as N, type OracleAttestation as O, type ProofProvider as P, type ValidityProofParams as V, type ProofFramework as a, type ProofResult as b, type FulfillmentProofParams as c, ProofGenerationError as d, type PublicKeyCoordinates as e, NoirProofProvider as f };