@sip-protocol/sdk 0.6.0 → 0.6.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/README.md +58 -0
- package/dist/browser.d.mts +4 -4
- package/dist/browser.d.ts +4 -4
- package/dist/browser.js +2752 -448
- package/dist/browser.mjs +31 -1
- package/dist/chunk-7QZPORY5.mjs +15604 -0
- package/dist/chunk-C2NPCUAJ.mjs +17010 -0
- package/dist/chunk-FCVLFUIC.mjs +16699 -0
- package/dist/chunk-G5UHXECN.mjs +16340 -0
- package/dist/chunk-GEDEIZHJ.mjs +16798 -0
- package/dist/chunk-GOOEOAMV.mjs +17026 -0
- package/dist/chunk-MTNYSNR7.mjs +16269 -0
- package/dist/chunk-O5PIB2EA.mjs +16698 -0
- package/dist/chunk-PCFM7FQO.mjs +17010 -0
- package/dist/chunk-QK464ARC.mjs +16946 -0
- package/dist/chunk-VNBMNGC3.mjs +16698 -0
- package/dist/chunk-W5TUELDQ.mjs +16947 -0
- package/dist/index-CD_zShu-.d.ts +10870 -0
- package/dist/index-CQBYdLYy.d.mts +10976 -0
- package/dist/index-Cg9TYEPv.d.mts +11321 -0
- package/dist/index-CqZJOO8C.d.mts +11323 -0
- package/dist/index-CywN9Bnp.d.ts +11321 -0
- package/dist/index-DHy5ZjCD.d.ts +10976 -0
- package/dist/index-DfsVsmxu.d.ts +11323 -0
- package/dist/index-ObjwyVDX.d.mts +10870 -0
- package/dist/index-m0xbSfmT.d.mts +11318 -0
- package/dist/index-rWLEgvhN.d.ts +11318 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2737 -427
- package/dist/index.mjs +31 -1
- package/dist/noir-DKfEzWy9.d.mts +482 -0
- package/dist/noir-DKfEzWy9.d.ts +482 -0
- package/dist/proofs/noir.d.mts +1 -1
- package/dist/proofs/noir.d.ts +1 -1
- package/dist/proofs/noir.js +12 -3
- package/dist/proofs/noir.mjs +12 -3
- package/package.json +16 -14
- package/src/adapters/near-intents.ts +13 -3
- package/src/auction/index.ts +20 -0
- package/src/auction/sealed-bid.ts +1037 -0
- package/src/compliance/derivation.ts +13 -3
- package/src/compliance/reports.ts +5 -4
- package/src/cosmos/ibc-stealth.ts +2 -2
- package/src/cosmos/stealth.ts +2 -2
- package/src/governance/index.ts +19 -0
- package/src/governance/private-vote.ts +1116 -0
- package/src/index.ts +50 -2
- package/src/intent.ts +145 -8
- package/src/nft/index.ts +27 -0
- package/src/nft/private-nft.ts +811 -0
- package/src/proofs/browser-utils.ts +1 -7
- package/src/proofs/noir.ts +34 -7
- package/src/settlement/backends/direct-chain.ts +14 -3
- package/src/stealth.ts +31 -13
- package/src/types/browser.d.ts +67 -0
- package/src/validation.ts +4 -2
- package/src/wallet/bitcoin/adapter.ts +159 -15
- package/src/wallet/bitcoin/types.ts +340 -15
- package/src/wallet/cosmos/mock.ts +16 -12
- package/src/wallet/hardware/ledger.ts +82 -12
- package/src/wallet/hardware/types.ts +2 -0
- package/LICENSE +0 -21
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,8 @@ import {
|
|
|
39
39
|
PaymentBuilder,
|
|
40
40
|
PaymentStatus,
|
|
41
41
|
PrivacyLevel,
|
|
42
|
+
PrivateNFT,
|
|
43
|
+
PrivateVoting,
|
|
42
44
|
ProposalStatus,
|
|
43
45
|
ReportStatus,
|
|
44
46
|
SIP,
|
|
@@ -46,10 +48,12 @@ import {
|
|
|
46
48
|
STABLECOIN_ADDRESSES,
|
|
47
49
|
STABLECOIN_DECIMALS,
|
|
48
50
|
STABLECOIN_INFO,
|
|
51
|
+
SealedBidAuction,
|
|
49
52
|
SettlementRegistry,
|
|
50
53
|
SettlementRegistryError,
|
|
51
54
|
SmartRouter,
|
|
52
55
|
SolanaWalletAdapter,
|
|
56
|
+
SuiStealthService,
|
|
53
57
|
SwapStatus,
|
|
54
58
|
ThresholdViewingKey,
|
|
55
59
|
Treasury,
|
|
@@ -72,6 +76,7 @@ import {
|
|
|
72
76
|
checkAptosStealthAddress,
|
|
73
77
|
checkEd25519StealthAddress,
|
|
74
78
|
checkStealthAddress,
|
|
79
|
+
checkSuiStealthAddress,
|
|
75
80
|
commit,
|
|
76
81
|
commitZero,
|
|
77
82
|
computeAttestationHash,
|
|
@@ -91,8 +96,11 @@ import {
|
|
|
91
96
|
createNEARIntentsAdapter,
|
|
92
97
|
createNEARIntentsBackend,
|
|
93
98
|
createOracleRegistry,
|
|
99
|
+
createPrivateOwnership,
|
|
100
|
+
createPrivateVoting,
|
|
94
101
|
createProductionSIP,
|
|
95
102
|
createSIP,
|
|
103
|
+
createSealedBidAuction,
|
|
96
104
|
createShieldedIntent,
|
|
97
105
|
createShieldedPayment,
|
|
98
106
|
createSmartRouter,
|
|
@@ -112,6 +120,7 @@ import {
|
|
|
112
120
|
deriveEd25519StealthPrivateKey,
|
|
113
121
|
deriveOracleId,
|
|
114
122
|
deriveStealthPrivateKey,
|
|
123
|
+
deriveSuiStealthPrivateKey,
|
|
115
124
|
deriveViewingKey,
|
|
116
125
|
deserializeAttestationMessage,
|
|
117
126
|
deserializeIntent,
|
|
@@ -121,6 +130,7 @@ import {
|
|
|
121
130
|
ed25519PublicKeyToAptosAddress,
|
|
122
131
|
ed25519PublicKeyToNearAddress,
|
|
123
132
|
ed25519PublicKeyToSolanaAddress,
|
|
133
|
+
ed25519PublicKeyToSuiAddress,
|
|
124
134
|
encodeStealthMetaAddress,
|
|
125
135
|
encryptForViewing,
|
|
126
136
|
featureNotSupportedError,
|
|
@@ -138,6 +148,7 @@ import {
|
|
|
138
148
|
generateRandomBytes,
|
|
139
149
|
generateStealthAddress,
|
|
140
150
|
generateStealthMetaAddress,
|
|
151
|
+
generateSuiStealthAddress,
|
|
141
152
|
generateViewingKey,
|
|
142
153
|
getActiveOracles,
|
|
143
154
|
getAvailableTransports,
|
|
@@ -191,10 +202,13 @@ import {
|
|
|
191
202
|
isValidSlippage,
|
|
192
203
|
isValidSolanaAddress,
|
|
193
204
|
isValidStealthMetaAddress,
|
|
205
|
+
isValidSuiAddress,
|
|
194
206
|
isValidTaprootAddress,
|
|
195
207
|
nearAddressToEd25519PublicKey,
|
|
196
208
|
normalizeAddress,
|
|
209
|
+
normalizeSuiAddress,
|
|
197
210
|
notConnectedError,
|
|
211
|
+
proveOwnership,
|
|
198
212
|
publicKeyToEthAddress,
|
|
199
213
|
registerWallet,
|
|
200
214
|
removeOracle,
|
|
@@ -235,10 +249,11 @@ import {
|
|
|
235
249
|
verifyCommitment,
|
|
236
250
|
verifyOpening,
|
|
237
251
|
verifyOracleSignature,
|
|
252
|
+
verifyOwnership,
|
|
238
253
|
walletRegistry,
|
|
239
254
|
withSecureBuffer,
|
|
240
255
|
withSecureBufferSync
|
|
241
|
-
} from "./chunk-
|
|
256
|
+
} from "./chunk-GOOEOAMV.mjs";
|
|
242
257
|
import {
|
|
243
258
|
CryptoError,
|
|
244
259
|
EncryptionNotImplementedError,
|
|
@@ -302,6 +317,8 @@ export {
|
|
|
302
317
|
PaymentBuilder,
|
|
303
318
|
PaymentStatus,
|
|
304
319
|
PrivacyLevel,
|
|
320
|
+
PrivateNFT,
|
|
321
|
+
PrivateVoting,
|
|
305
322
|
ProofError,
|
|
306
323
|
ProofGenerationError,
|
|
307
324
|
ProofNotImplementedError,
|
|
@@ -313,10 +330,12 @@ export {
|
|
|
313
330
|
STABLECOIN_ADDRESSES,
|
|
314
331
|
STABLECOIN_DECIMALS,
|
|
315
332
|
STABLECOIN_INFO,
|
|
333
|
+
SealedBidAuction,
|
|
316
334
|
SettlementRegistry,
|
|
317
335
|
SettlementRegistryError,
|
|
318
336
|
SmartRouter,
|
|
319
337
|
SolanaWalletAdapter,
|
|
338
|
+
SuiStealthService,
|
|
320
339
|
SwapStatus,
|
|
321
340
|
ThresholdViewingKey,
|
|
322
341
|
Treasury,
|
|
@@ -341,6 +360,7 @@ export {
|
|
|
341
360
|
checkAptosStealthAddress,
|
|
342
361
|
checkEd25519StealthAddress,
|
|
343
362
|
checkStealthAddress,
|
|
363
|
+
checkSuiStealthAddress,
|
|
344
364
|
commit,
|
|
345
365
|
commitZero,
|
|
346
366
|
computeAttestationHash,
|
|
@@ -360,8 +380,11 @@ export {
|
|
|
360
380
|
createNEARIntentsAdapter,
|
|
361
381
|
createNEARIntentsBackend,
|
|
362
382
|
createOracleRegistry,
|
|
383
|
+
createPrivateOwnership,
|
|
384
|
+
createPrivateVoting,
|
|
363
385
|
createProductionSIP,
|
|
364
386
|
createSIP,
|
|
387
|
+
createSealedBidAuction,
|
|
365
388
|
createShieldedIntent,
|
|
366
389
|
createShieldedPayment,
|
|
367
390
|
createSmartRouter,
|
|
@@ -381,6 +404,7 @@ export {
|
|
|
381
404
|
deriveEd25519StealthPrivateKey,
|
|
382
405
|
deriveOracleId,
|
|
383
406
|
deriveStealthPrivateKey,
|
|
407
|
+
deriveSuiStealthPrivateKey,
|
|
384
408
|
deriveViewingKey,
|
|
385
409
|
deserializeAttestationMessage,
|
|
386
410
|
deserializeIntent,
|
|
@@ -390,6 +414,7 @@ export {
|
|
|
390
414
|
ed25519PublicKeyToAptosAddress,
|
|
391
415
|
ed25519PublicKeyToNearAddress,
|
|
392
416
|
ed25519PublicKeyToSolanaAddress,
|
|
417
|
+
ed25519PublicKeyToSuiAddress,
|
|
393
418
|
encodeStealthMetaAddress,
|
|
394
419
|
encryptForViewing,
|
|
395
420
|
featureNotSupportedError,
|
|
@@ -407,6 +432,7 @@ export {
|
|
|
407
432
|
generateRandomBytes,
|
|
408
433
|
generateStealthAddress,
|
|
409
434
|
generateStealthMetaAddress,
|
|
435
|
+
generateSuiStealthAddress,
|
|
410
436
|
generateViewingKey,
|
|
411
437
|
getActiveOracles,
|
|
412
438
|
getAvailableTransports,
|
|
@@ -462,10 +488,13 @@ export {
|
|
|
462
488
|
isValidSlippage,
|
|
463
489
|
isValidSolanaAddress,
|
|
464
490
|
isValidStealthMetaAddress,
|
|
491
|
+
isValidSuiAddress,
|
|
465
492
|
isValidTaprootAddress,
|
|
466
493
|
nearAddressToEd25519PublicKey,
|
|
467
494
|
normalizeAddress,
|
|
495
|
+
normalizeSuiAddress,
|
|
468
496
|
notConnectedError,
|
|
497
|
+
proveOwnership,
|
|
469
498
|
publicKeyToEthAddress,
|
|
470
499
|
registerWallet,
|
|
471
500
|
removeOracle,
|
|
@@ -506,6 +535,7 @@ export {
|
|
|
506
535
|
verifyCommitment,
|
|
507
536
|
verifyOpening,
|
|
508
537
|
verifyOracleSignature,
|
|
538
|
+
verifyOwnership,
|
|
509
539
|
walletRegistry,
|
|
510
540
|
withSecureBuffer,
|
|
511
541
|
withSecureBufferSync,
|
|
@@ -0,0 +1,482 @@
|
|
|
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 and strictMode is true,
|
|
262
|
+
* fulfillment proof generation will throw an error.
|
|
263
|
+
*/
|
|
264
|
+
oraclePublicKey?: PublicKeyCoordinates;
|
|
265
|
+
/**
|
|
266
|
+
* Enable strict mode for production use
|
|
267
|
+
*
|
|
268
|
+
* When true:
|
|
269
|
+
* - Fulfillment proofs require configured oraclePublicKey
|
|
270
|
+
* - Missing configuration throws errors instead of warnings
|
|
271
|
+
*
|
|
272
|
+
* When false (default):
|
|
273
|
+
* - Placeholder keys are used when oraclePublicKey not configured
|
|
274
|
+
* - Warnings are logged for missing configuration
|
|
275
|
+
*
|
|
276
|
+
* @default false
|
|
277
|
+
*/
|
|
278
|
+
strictMode?: boolean;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Noir Proof Provider
|
|
282
|
+
*
|
|
283
|
+
* Production ZK proof provider using Noir circuits.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const provider = new NoirProofProvider()
|
|
288
|
+
*
|
|
289
|
+
* await provider.initialize()
|
|
290
|
+
*
|
|
291
|
+
* const result = await provider.generateFundingProof({
|
|
292
|
+
* balance: 100n,
|
|
293
|
+
* minimumRequired: 50n,
|
|
294
|
+
* blindingFactor: new Uint8Array(32),
|
|
295
|
+
* assetId: '0xABCD',
|
|
296
|
+
* userAddress: '0x1234...',
|
|
297
|
+
* ownershipSignature: new Uint8Array(64),
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare class NoirProofProvider implements ProofProvider {
|
|
302
|
+
readonly framework: ProofFramework;
|
|
303
|
+
private _isReady;
|
|
304
|
+
private config;
|
|
305
|
+
private fundingNoir;
|
|
306
|
+
private fundingBackend;
|
|
307
|
+
private validityNoir;
|
|
308
|
+
private validityBackend;
|
|
309
|
+
private fulfillmentNoir;
|
|
310
|
+
private fulfillmentBackend;
|
|
311
|
+
constructor(config?: NoirProviderConfig);
|
|
312
|
+
get isReady(): boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Derive secp256k1 public key coordinates from a private key
|
|
315
|
+
*
|
|
316
|
+
* Utility method that can be used to generate public key coordinates
|
|
317
|
+
* for use in ValidityProofParams.senderPublicKey or NoirProviderConfig.oraclePublicKey
|
|
318
|
+
*
|
|
319
|
+
* @param privateKey - 32-byte private key
|
|
320
|
+
* @returns X and Y coordinates as 32-byte arrays
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const privateKey = new Uint8Array(32).fill(1) // Your secret key
|
|
325
|
+
* const publicKey = NoirProofProvider.derivePublicKey(privateKey)
|
|
326
|
+
*
|
|
327
|
+
* // Use for oracle configuration
|
|
328
|
+
* const provider = new NoirProofProvider({
|
|
329
|
+
* oraclePublicKey: publicKey
|
|
330
|
+
* })
|
|
331
|
+
*
|
|
332
|
+
* // Or use for validity proof params
|
|
333
|
+
* const validityParams = {
|
|
334
|
+
* // ... other params
|
|
335
|
+
* senderPublicKey: {
|
|
336
|
+
* x: new Uint8Array(publicKey.x),
|
|
337
|
+
* y: new Uint8Array(publicKey.y)
|
|
338
|
+
* }
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
static derivePublicKey(privateKey: Uint8Array): PublicKeyCoordinates;
|
|
343
|
+
/**
|
|
344
|
+
* Initialize the Noir provider
|
|
345
|
+
*
|
|
346
|
+
* Loads circuit artifacts and initializes the proving backend.
|
|
347
|
+
*/
|
|
348
|
+
initialize(): Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Generate a Funding Proof using Noir circuits
|
|
351
|
+
*
|
|
352
|
+
* Proves: balance >= minimumRequired without revealing balance
|
|
353
|
+
*
|
|
354
|
+
* @see docs/specs/FUNDING-PROOF.md
|
|
355
|
+
*/
|
|
356
|
+
generateFundingProof(params: FundingProofParams): Promise<ProofResult>;
|
|
357
|
+
/**
|
|
358
|
+
* Generate a Validity Proof using Noir circuits
|
|
359
|
+
*
|
|
360
|
+
* Proves: Intent is authorized by sender without revealing identity
|
|
361
|
+
*
|
|
362
|
+
* @see docs/specs/VALIDITY-PROOF.md
|
|
363
|
+
*/
|
|
364
|
+
generateValidityProof(params: ValidityProofParams): Promise<ProofResult>;
|
|
365
|
+
/**
|
|
366
|
+
* Generate a Fulfillment Proof using Noir circuits
|
|
367
|
+
*
|
|
368
|
+
* Proves: Solver correctly executed the intent and delivered the required
|
|
369
|
+
* output to the recipient, without revealing execution path or liquidity sources.
|
|
370
|
+
*
|
|
371
|
+
* @see docs/specs/FULFILLMENT-PROOF.md
|
|
372
|
+
*/
|
|
373
|
+
generateFulfillmentProof(params: FulfillmentProofParams): Promise<ProofResult>;
|
|
374
|
+
/**
|
|
375
|
+
* Verify a Noir proof
|
|
376
|
+
*/
|
|
377
|
+
verifyProof(proof: ZKProof): Promise<boolean>;
|
|
378
|
+
/**
|
|
379
|
+
* Destroy the provider and free resources
|
|
380
|
+
*/
|
|
381
|
+
destroy(): Promise<void>;
|
|
382
|
+
private ensureReady;
|
|
383
|
+
/**
|
|
384
|
+
* Compute the commitment hash that the circuit expects
|
|
385
|
+
*
|
|
386
|
+
* The circuit computes:
|
|
387
|
+
* 1. commitment = pedersen_commitment([balance, blinding])
|
|
388
|
+
* 2. commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id])
|
|
389
|
+
*
|
|
390
|
+
* We need to compute this outside to pass as a public input.
|
|
391
|
+
*
|
|
392
|
+
* **IMPORTANT**: This SDK uses SHA256 as a deterministic stand-in for Pedersen hash.
|
|
393
|
+
* Both the SDK and circuit MUST use the same hash function. The bundled circuit
|
|
394
|
+
* artifacts are configured to use SHA256 for compatibility. If you use custom
|
|
395
|
+
* circuits with actual Pedersen hashing, you must update this implementation.
|
|
396
|
+
*
|
|
397
|
+
* @see docs/specs/HASH-COMPATIBILITY.md for hash function requirements
|
|
398
|
+
*/
|
|
399
|
+
private computeCommitmentHash;
|
|
400
|
+
/**
|
|
401
|
+
* Convert asset ID to field element
|
|
402
|
+
*/
|
|
403
|
+
private assetIdToField;
|
|
404
|
+
/**
|
|
405
|
+
* Convert bytes to field element string
|
|
406
|
+
*/
|
|
407
|
+
private bytesToField;
|
|
408
|
+
/**
|
|
409
|
+
* Convert bigint to bytes
|
|
410
|
+
*/
|
|
411
|
+
private bigintToBytes;
|
|
412
|
+
/**
|
|
413
|
+
* Convert hex string to bytes
|
|
414
|
+
*/
|
|
415
|
+
private hexToBytes;
|
|
416
|
+
/**
|
|
417
|
+
* Convert hex string to field element string
|
|
418
|
+
*/
|
|
419
|
+
private hexToField;
|
|
420
|
+
/**
|
|
421
|
+
* Convert field string to 32-byte array
|
|
422
|
+
*/
|
|
423
|
+
private fieldToBytes32;
|
|
424
|
+
/**
|
|
425
|
+
* Compute sender commitment for validity proof
|
|
426
|
+
*
|
|
427
|
+
* Uses SHA256 for SDK-side computation. The bundled circuit artifacts
|
|
428
|
+
* are compiled to use SHA256 for compatibility with this SDK.
|
|
429
|
+
*
|
|
430
|
+
* @see computeCommitmentHash for hash function compatibility notes
|
|
431
|
+
*/
|
|
432
|
+
private computeSenderCommitment;
|
|
433
|
+
/**
|
|
434
|
+
* Compute nullifier for validity proof
|
|
435
|
+
*
|
|
436
|
+
* Uses SHA256 for SDK-side computation. The bundled circuit artifacts
|
|
437
|
+
* are compiled to use SHA256 for compatibility with this SDK.
|
|
438
|
+
*
|
|
439
|
+
* @see computeCommitmentHash for hash function compatibility notes
|
|
440
|
+
*/
|
|
441
|
+
private computeNullifier;
|
|
442
|
+
/**
|
|
443
|
+
* Compute output commitment for fulfillment proof
|
|
444
|
+
*
|
|
445
|
+
* Uses SHA256 for SDK-side computation. The bundled circuit artifacts
|
|
446
|
+
* are compiled to use SHA256 for compatibility with this SDK.
|
|
447
|
+
*
|
|
448
|
+
* @see computeCommitmentHash for hash function compatibility notes
|
|
449
|
+
*/
|
|
450
|
+
private computeOutputCommitment;
|
|
451
|
+
/**
|
|
452
|
+
* Compute solver ID from solver secret
|
|
453
|
+
*
|
|
454
|
+
* Uses SHA256 for SDK-side computation. The bundled circuit artifacts
|
|
455
|
+
* are compiled to use SHA256 for compatibility with this SDK.
|
|
456
|
+
*
|
|
457
|
+
* @see computeCommitmentHash for hash function compatibility notes
|
|
458
|
+
*/
|
|
459
|
+
private computeSolverId;
|
|
460
|
+
/**
|
|
461
|
+
* Compute oracle message hash for fulfillment proof
|
|
462
|
+
*
|
|
463
|
+
* Hash of attestation data that oracle signs
|
|
464
|
+
*/
|
|
465
|
+
private computeOracleMessageHash;
|
|
466
|
+
/**
|
|
467
|
+
* Derive secp256k1 public key coordinates from a private key
|
|
468
|
+
*
|
|
469
|
+
* @param privateKey - 32-byte private key as Uint8Array
|
|
470
|
+
* @returns X and Y coordinates as 32-byte arrays
|
|
471
|
+
*/
|
|
472
|
+
private getPublicKeyCoordinates;
|
|
473
|
+
/**
|
|
474
|
+
* Derive public key coordinates from a field string (private key)
|
|
475
|
+
*
|
|
476
|
+
* @param privateKeyField - Private key as hex field string
|
|
477
|
+
* @returns X and Y coordinates as 32-byte arrays
|
|
478
|
+
*/
|
|
479
|
+
private getPublicKeyFromField;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export { type FundingProofParams as F, type NoirProviderConfig as N, type OracleAttestation as O, type ProofResult as P, type ValidityProofParams as V, type FulfillmentProofParams as a, ProofGenerationError as b, type ProofProvider as c, type ProofFramework as d, type PublicKeyCoordinates as e, NoirProofProvider as f };
|