@sip-protocol/sdk 0.2.0 → 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/browser.mjs CHANGED
@@ -1,21 +1,16 @@
1
1
  import {
2
2
  ATTESTATION_VERSION,
3
3
  BaseWalletAdapter,
4
- BrowserNoirProvider,
5
4
  CHAIN_NUMERIC_IDS,
6
5
  ComplianceManager,
7
- CryptoError,
8
6
  DEFAULT_THRESHOLD,
9
7
  DEFAULT_TOTAL_ORACLES,
10
8
  DerivationPath,
11
- EncryptionNotImplementedError,
12
- ErrorCode,
13
9
  EthereumChainId,
14
10
  EthereumWalletAdapter,
15
11
  HardwareErrorCode,
16
12
  HardwareWalletError,
17
13
  IntentBuilder,
18
- IntentError,
19
14
  IntentStatus,
20
15
  LedgerWalletAdapter,
21
16
  MockEthereumAdapter,
@@ -27,8 +22,6 @@ import {
27
22
  MockWalletAdapter,
28
23
  NATIVE_TOKENS,
29
24
  NEARIntentsAdapter,
30
- NetworkError,
31
- NoirProofProvider,
32
25
  ORACLE_DOMAIN,
33
26
  OneClickClient,
34
27
  OneClickDepositMode,
@@ -38,13 +31,9 @@ import {
38
31
  PaymentBuilder,
39
32
  PaymentStatus,
40
33
  PrivacyLevel,
41
- ProofError,
42
- ProofGenerationError,
43
- ProofNotImplementedError,
44
34
  ProposalStatus,
45
35
  ReportStatus,
46
36
  SIP,
47
- SIPError,
48
37
  SIP_VERSION,
49
38
  STABLECOIN_ADDRESSES,
50
39
  STABLECOIN_DECIMALS,
@@ -52,7 +41,6 @@ import {
52
41
  SolanaWalletAdapter,
53
42
  Treasury,
54
43
  TrezorWalletAdapter,
55
- ValidationError,
56
44
  WalletError,
57
45
  WalletErrorCode,
58
46
  ZcashErrorCode,
@@ -128,7 +116,6 @@ import {
128
116
  getCurveForChain,
129
117
  getDefaultRpcEndpoint,
130
118
  getDerivationPath,
131
- getErrorMessage,
132
119
  getEthereumProvider,
133
120
  getGenerators,
134
121
  getIntentSummary,
@@ -143,7 +130,6 @@ import {
143
130
  getSupportedStablecoins,
144
131
  getTimeRemaining,
145
132
  hasEnoughOracles,
146
- hasErrorCode,
147
133
  hasRequiredProofs,
148
134
  hash,
149
135
  hexToBytes,
@@ -155,7 +141,6 @@ import {
155
141
  isPaymentExpired,
156
142
  isPrivate,
157
143
  isPrivateWalletAdapter,
158
- isSIPError,
159
144
  isStablecoin,
160
145
  isStablecoinOnChain,
161
146
  isValidAmount,
@@ -211,9 +196,632 @@ import {
211
196
  verifyOracleSignature,
212
197
  walletRegistry,
213
198
  withSecureBuffer,
214
- withSecureBufferSync,
199
+ withSecureBufferSync
200
+ } from "./chunk-DU7LQDD2.mjs";
201
+ import {
202
+ fulfillment_proof_default,
203
+ funding_proof_default,
204
+ validity_proof_default
205
+ } from "./chunk-VITVG25F.mjs";
206
+ import {
207
+ CryptoError,
208
+ EncryptionNotImplementedError,
209
+ ErrorCode,
210
+ IntentError,
211
+ NetworkError,
212
+ ProofError,
213
+ ProofGenerationError,
214
+ ProofNotImplementedError,
215
+ SIPError,
216
+ ValidationError,
217
+ getErrorMessage,
218
+ hasErrorCode,
219
+ isSIPError,
215
220
  wrapError
216
- } from "./chunk-O4Y2ZUDL.mjs";
221
+ } from "./chunk-UHZKNGIT.mjs";
222
+
223
+ // src/proofs/browser.ts
224
+ import { Noir } from "@noir-lang/noir_js";
225
+ import { UltraHonkBackend } from "@aztec/bb.js";
226
+ import { secp256k1 } from "@noble/curves/secp256k1";
227
+ var BrowserNoirProvider = class _BrowserNoirProvider {
228
+ framework = "noir";
229
+ _isReady = false;
230
+ config;
231
+ // Circuit instances
232
+ fundingNoir = null;
233
+ fundingBackend = null;
234
+ validityNoir = null;
235
+ validityBackend = null;
236
+ fulfillmentNoir = null;
237
+ fulfillmentBackend = null;
238
+ // Worker instance (optional)
239
+ worker = null;
240
+ workerPending = /* @__PURE__ */ new Map();
241
+ constructor(config = {}) {
242
+ this.config = {
243
+ useWorker: config.useWorker ?? true,
244
+ verbose: config.verbose ?? false,
245
+ oraclePublicKey: config.oraclePublicKey ?? void 0,
246
+ timeout: config.timeout ?? 6e4
247
+ };
248
+ if (!isBrowser()) {
249
+ console.warn(
250
+ "[BrowserNoirProvider] Not running in browser environment. Consider using NoirProofProvider for Node.js."
251
+ );
252
+ }
253
+ }
254
+ get isReady() {
255
+ return this._isReady;
256
+ }
257
+ /**
258
+ * Get browser environment info
259
+ */
260
+ static getBrowserInfo() {
261
+ return getBrowserInfo();
262
+ }
263
+ /**
264
+ * Check if browser supports all required features
265
+ */
266
+ static checkBrowserSupport() {
267
+ const missing = [];
268
+ if (!isBrowser()) {
269
+ missing.push("browser environment");
270
+ }
271
+ if (typeof WebAssembly === "undefined") {
272
+ missing.push("WebAssembly");
273
+ }
274
+ if (!supportsSharedArrayBuffer()) {
275
+ missing.push("SharedArrayBuffer (requires COOP/COEP headers)");
276
+ }
277
+ return {
278
+ supported: missing.length === 0,
279
+ missing
280
+ };
281
+ }
282
+ /**
283
+ * Derive secp256k1 public key coordinates from a private key
284
+ */
285
+ static derivePublicKey(privateKey) {
286
+ const uncompressedPubKey = secp256k1.getPublicKey(privateKey, false);
287
+ const x = Array.from(uncompressedPubKey.slice(1, 33));
288
+ const y = Array.from(uncompressedPubKey.slice(33, 65));
289
+ return { x, y };
290
+ }
291
+ /**
292
+ * Initialize the browser provider
293
+ *
294
+ * Loads WASM and circuit artifacts. This should be called before any
295
+ * proof generation. Consider showing a loading indicator during init.
296
+ *
297
+ * @param onProgress - Optional progress callback
298
+ */
299
+ async initialize(onProgress) {
300
+ if (this._isReady) {
301
+ return;
302
+ }
303
+ const { supported, missing } = _BrowserNoirProvider.checkBrowserSupport();
304
+ if (!supported) {
305
+ throw new ProofError(
306
+ `Browser missing required features: ${missing.join(", ")}`,
307
+ "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
308
+ );
309
+ }
310
+ try {
311
+ onProgress?.({
312
+ stage: "initializing",
313
+ percent: 0,
314
+ message: "Loading WASM runtime..."
315
+ });
316
+ if (this.config.verbose) {
317
+ console.log("[BrowserNoirProvider] Initializing...");
318
+ console.log("[BrowserNoirProvider] Browser info:", getBrowserInfo());
319
+ }
320
+ const fundingCircuit = funding_proof_default;
321
+ const validityCircuit = validity_proof_default;
322
+ const fulfillmentCircuit = fulfillment_proof_default;
323
+ onProgress?.({
324
+ stage: "initializing",
325
+ percent: 20,
326
+ message: "Creating proof backends..."
327
+ });
328
+ this.fundingBackend = new UltraHonkBackend(fundingCircuit.bytecode);
329
+ this.validityBackend = new UltraHonkBackend(validityCircuit.bytecode);
330
+ this.fulfillmentBackend = new UltraHonkBackend(fulfillmentCircuit.bytecode);
331
+ onProgress?.({
332
+ stage: "initializing",
333
+ percent: 60,
334
+ message: "Initializing Noir circuits..."
335
+ });
336
+ this.fundingNoir = new Noir(fundingCircuit);
337
+ this.validityNoir = new Noir(validityCircuit);
338
+ this.fulfillmentNoir = new Noir(fulfillmentCircuit);
339
+ onProgress?.({
340
+ stage: "initializing",
341
+ percent: 90,
342
+ message: "Setting up worker..."
343
+ });
344
+ if (this.config.useWorker && supportsWebWorkers()) {
345
+ await this.initializeWorker();
346
+ }
347
+ this._isReady = true;
348
+ onProgress?.({
349
+ stage: "complete",
350
+ percent: 100,
351
+ message: "Ready for proof generation"
352
+ });
353
+ if (this.config.verbose) {
354
+ console.log("[BrowserNoirProvider] Initialization complete");
355
+ }
356
+ } catch (error) {
357
+ throw new ProofError(
358
+ `Failed to initialize BrowserNoirProvider: ${error instanceof Error ? error.message : String(error)}`,
359
+ "SIP_4003" /* PROOF_NOT_IMPLEMENTED */,
360
+ { context: { error } }
361
+ );
362
+ }
363
+ }
364
+ /**
365
+ * Initialize Web Worker for off-main-thread proof generation
366
+ */
367
+ async initializeWorker() {
368
+ if (this.config.verbose) {
369
+ console.log("[BrowserNoirProvider] Worker support: using async main-thread");
370
+ }
371
+ }
372
+ /**
373
+ * Generate a Funding Proof
374
+ *
375
+ * Proves: balance >= minimumRequired without revealing balance
376
+ *
377
+ * @param params - Funding proof parameters
378
+ * @param onProgress - Optional progress callback
379
+ */
380
+ async generateFundingProof(params, onProgress) {
381
+ this.ensureReady();
382
+ if (!this.fundingNoir || !this.fundingBackend) {
383
+ throw new ProofGenerationError("funding", "Funding circuit not initialized");
384
+ }
385
+ try {
386
+ onProgress?.({
387
+ stage: "witness",
388
+ percent: 10,
389
+ message: "Preparing witness inputs..."
390
+ });
391
+ const { commitmentHash, blindingField } = await this.computeCommitmentHash(
392
+ params.balance,
393
+ params.blindingFactor,
394
+ params.assetId
395
+ );
396
+ const witnessInputs = {
397
+ commitment_hash: commitmentHash,
398
+ minimum_required: params.minimumRequired.toString(),
399
+ asset_id: this.assetIdToField(params.assetId),
400
+ balance: params.balance.toString(),
401
+ blinding: blindingField
402
+ };
403
+ onProgress?.({
404
+ stage: "witness",
405
+ percent: 30,
406
+ message: "Generating witness..."
407
+ });
408
+ const { witness } = await this.fundingNoir.execute(witnessInputs);
409
+ onProgress?.({
410
+ stage: "proving",
411
+ percent: 50,
412
+ message: "Generating proof (this may take a moment)..."
413
+ });
414
+ const proofData = await this.fundingBackend.generateProof(witness);
415
+ onProgress?.({
416
+ stage: "complete",
417
+ percent: 100,
418
+ message: "Proof generated successfully"
419
+ });
420
+ const publicInputs = [
421
+ `0x${commitmentHash}`,
422
+ `0x${params.minimumRequired.toString(16).padStart(16, "0")}`,
423
+ `0x${this.assetIdToField(params.assetId)}`
424
+ ];
425
+ const proof = {
426
+ type: "funding",
427
+ proof: `0x${bytesToHex(proofData.proof)}`,
428
+ publicInputs
429
+ };
430
+ return { proof, publicInputs };
431
+ } catch (error) {
432
+ const message = error instanceof Error ? error.message : String(error);
433
+ throw new ProofGenerationError(
434
+ "funding",
435
+ `Failed to generate funding proof: ${message}`,
436
+ error instanceof Error ? error : void 0
437
+ );
438
+ }
439
+ }
440
+ /**
441
+ * Generate a Validity Proof
442
+ *
443
+ * Proves: Intent is authorized by sender without revealing identity
444
+ */
445
+ async generateValidityProof(params, onProgress) {
446
+ this.ensureReady();
447
+ if (!this.validityNoir || !this.validityBackend) {
448
+ throw new ProofGenerationError("validity", "Validity circuit not initialized");
449
+ }
450
+ try {
451
+ onProgress?.({
452
+ stage: "witness",
453
+ percent: 10,
454
+ message: "Preparing validity witness..."
455
+ });
456
+ const intentHashField = this.hexToField(params.intentHash);
457
+ const senderAddressField = this.hexToField(params.senderAddress);
458
+ const senderBlindingField = this.bytesToField(params.senderBlinding);
459
+ const senderSecretField = this.bytesToField(params.senderSecret);
460
+ const nonceField = this.bytesToField(params.nonce);
461
+ const { commitmentX, commitmentY } = await this.computeSenderCommitment(
462
+ senderAddressField,
463
+ senderBlindingField
464
+ );
465
+ const nullifier = await this.computeNullifier(senderSecretField, intentHashField, nonceField);
466
+ const signature = Array.from(params.authorizationSignature);
467
+ const messageHash = this.fieldToBytes32(intentHashField);
468
+ let pubKeyX;
469
+ let pubKeyY;
470
+ if (params.senderPublicKey) {
471
+ pubKeyX = Array.from(params.senderPublicKey.x);
472
+ pubKeyY = Array.from(params.senderPublicKey.y);
473
+ } else {
474
+ const coords = this.getPublicKeyCoordinates(params.senderSecret);
475
+ pubKeyX = coords.x;
476
+ pubKeyY = coords.y;
477
+ }
478
+ const witnessInputs = {
479
+ intent_hash: intentHashField,
480
+ sender_commitment_x: commitmentX,
481
+ sender_commitment_y: commitmentY,
482
+ nullifier,
483
+ timestamp: params.timestamp.toString(),
484
+ expiry: params.expiry.toString(),
485
+ sender_address: senderAddressField,
486
+ sender_blinding: senderBlindingField,
487
+ sender_secret: senderSecretField,
488
+ pub_key_x: pubKeyX,
489
+ pub_key_y: pubKeyY,
490
+ signature,
491
+ message_hash: messageHash,
492
+ nonce: nonceField
493
+ };
494
+ onProgress?.({
495
+ stage: "witness",
496
+ percent: 30,
497
+ message: "Generating witness..."
498
+ });
499
+ const { witness } = await this.validityNoir.execute(witnessInputs);
500
+ onProgress?.({
501
+ stage: "proving",
502
+ percent: 50,
503
+ message: "Generating validity proof..."
504
+ });
505
+ const proofData = await this.validityBackend.generateProof(witness);
506
+ onProgress?.({
507
+ stage: "complete",
508
+ percent: 100,
509
+ message: "Validity proof generated"
510
+ });
511
+ const publicInputs = [
512
+ `0x${intentHashField}`,
513
+ `0x${commitmentX}`,
514
+ `0x${commitmentY}`,
515
+ `0x${nullifier}`,
516
+ `0x${params.timestamp.toString(16).padStart(16, "0")}`,
517
+ `0x${params.expiry.toString(16).padStart(16, "0")}`
518
+ ];
519
+ const proof = {
520
+ type: "validity",
521
+ proof: `0x${bytesToHex(proofData.proof)}`,
522
+ publicInputs
523
+ };
524
+ return { proof, publicInputs };
525
+ } catch (error) {
526
+ const message = error instanceof Error ? error.message : String(error);
527
+ throw new ProofGenerationError(
528
+ "validity",
529
+ `Failed to generate validity proof: ${message}`,
530
+ error instanceof Error ? error : void 0
531
+ );
532
+ }
533
+ }
534
+ /**
535
+ * Generate a Fulfillment Proof
536
+ *
537
+ * Proves: Solver correctly executed the intent
538
+ */
539
+ async generateFulfillmentProof(params, onProgress) {
540
+ this.ensureReady();
541
+ if (!this.fulfillmentNoir || !this.fulfillmentBackend) {
542
+ throw new ProofGenerationError("fulfillment", "Fulfillment circuit not initialized");
543
+ }
544
+ try {
545
+ onProgress?.({
546
+ stage: "witness",
547
+ percent: 10,
548
+ message: "Preparing fulfillment witness..."
549
+ });
550
+ const intentHashField = this.hexToField(params.intentHash);
551
+ const recipientStealthField = this.hexToField(params.recipientStealth);
552
+ const { commitmentX, commitmentY } = await this.computeOutputCommitment(
553
+ params.outputAmount,
554
+ params.outputBlinding
555
+ );
556
+ const solverSecretField = this.bytesToField(params.solverSecret);
557
+ const solverId = await this.computeSolverId(solverSecretField);
558
+ const outputBlindingField = this.bytesToField(params.outputBlinding);
559
+ const attestation = params.oracleAttestation;
560
+ const attestationRecipientField = this.hexToField(attestation.recipient);
561
+ const attestationTxHashField = this.hexToField(attestation.txHash);
562
+ const oracleSignature = Array.from(attestation.signature);
563
+ const oracleMessageHash = await this.computeOracleMessageHash(
564
+ attestation.recipient,
565
+ attestation.amount,
566
+ attestation.txHash,
567
+ attestation.blockNumber
568
+ );
569
+ const oraclePubKeyX = this.config.oraclePublicKey?.x ?? new Array(32).fill(0);
570
+ const oraclePubKeyY = this.config.oraclePublicKey?.y ?? new Array(32).fill(0);
571
+ const witnessInputs = {
572
+ intent_hash: intentHashField,
573
+ output_commitment_x: commitmentX,
574
+ output_commitment_y: commitmentY,
575
+ recipient_stealth: recipientStealthField,
576
+ min_output_amount: params.minOutputAmount.toString(),
577
+ solver_id: solverId,
578
+ fulfillment_time: params.fulfillmentTime.toString(),
579
+ expiry: params.expiry.toString(),
580
+ output_amount: params.outputAmount.toString(),
581
+ output_blinding: outputBlindingField,
582
+ solver_secret: solverSecretField,
583
+ attestation_recipient: attestationRecipientField,
584
+ attestation_amount: attestation.amount.toString(),
585
+ attestation_tx_hash: attestationTxHashField,
586
+ attestation_block: attestation.blockNumber.toString(),
587
+ oracle_signature: oracleSignature,
588
+ oracle_message_hash: oracleMessageHash,
589
+ oracle_pub_key_x: oraclePubKeyX,
590
+ oracle_pub_key_y: oraclePubKeyY
591
+ };
592
+ onProgress?.({
593
+ stage: "witness",
594
+ percent: 30,
595
+ message: "Generating witness..."
596
+ });
597
+ const { witness } = await this.fulfillmentNoir.execute(witnessInputs);
598
+ onProgress?.({
599
+ stage: "proving",
600
+ percent: 50,
601
+ message: "Generating fulfillment proof..."
602
+ });
603
+ const proofData = await this.fulfillmentBackend.generateProof(witness);
604
+ onProgress?.({
605
+ stage: "complete",
606
+ percent: 100,
607
+ message: "Fulfillment proof generated"
608
+ });
609
+ const publicInputs = [
610
+ `0x${intentHashField}`,
611
+ `0x${commitmentX}`,
612
+ `0x${commitmentY}`,
613
+ `0x${recipientStealthField}`,
614
+ `0x${params.minOutputAmount.toString(16).padStart(16, "0")}`,
615
+ `0x${solverId}`,
616
+ `0x${params.fulfillmentTime.toString(16).padStart(16, "0")}`,
617
+ `0x${params.expiry.toString(16).padStart(16, "0")}`
618
+ ];
619
+ const proof = {
620
+ type: "fulfillment",
621
+ proof: `0x${bytesToHex(proofData.proof)}`,
622
+ publicInputs
623
+ };
624
+ return { proof, publicInputs };
625
+ } catch (error) {
626
+ const message = error instanceof Error ? error.message : String(error);
627
+ throw new ProofGenerationError(
628
+ "fulfillment",
629
+ `Failed to generate fulfillment proof: ${message}`,
630
+ error instanceof Error ? error : void 0
631
+ );
632
+ }
633
+ }
634
+ /**
635
+ * Verify a proof
636
+ */
637
+ async verifyProof(proof) {
638
+ this.ensureReady();
639
+ let backend = null;
640
+ switch (proof.type) {
641
+ case "funding":
642
+ backend = this.fundingBackend;
643
+ break;
644
+ case "validity":
645
+ backend = this.validityBackend;
646
+ break;
647
+ case "fulfillment":
648
+ backend = this.fulfillmentBackend;
649
+ break;
650
+ default:
651
+ throw new ProofError(`Unknown proof type: ${proof.type}`, "SIP_4003" /* PROOF_NOT_IMPLEMENTED */);
652
+ }
653
+ if (!backend) {
654
+ throw new ProofError(
655
+ `${proof.type} backend not initialized`,
656
+ "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
657
+ );
658
+ }
659
+ try {
660
+ const proofHex = proof.proof.startsWith("0x") ? proof.proof.slice(2) : proof.proof;
661
+ const proofBytes = hexToBytes(proofHex);
662
+ const isValid = await backend.verifyProof({
663
+ proof: proofBytes,
664
+ publicInputs: proof.publicInputs.map(
665
+ (input) => input.startsWith("0x") ? input.slice(2) : input
666
+ )
667
+ });
668
+ return isValid;
669
+ } catch (error) {
670
+ if (this.config.verbose) {
671
+ console.error("[BrowserNoirProvider] Verification error:", error);
672
+ }
673
+ return false;
674
+ }
675
+ }
676
+ /**
677
+ * Destroy the provider and free resources
678
+ */
679
+ async destroy() {
680
+ if (this.fundingBackend) {
681
+ await this.fundingBackend.destroy();
682
+ this.fundingBackend = null;
683
+ }
684
+ if (this.validityBackend) {
685
+ await this.validityBackend.destroy();
686
+ this.validityBackend = null;
687
+ }
688
+ if (this.fulfillmentBackend) {
689
+ await this.fulfillmentBackend.destroy();
690
+ this.fulfillmentBackend = null;
691
+ }
692
+ if (this.worker) {
693
+ this.worker.terminate();
694
+ this.worker = null;
695
+ }
696
+ this.fundingNoir = null;
697
+ this.validityNoir = null;
698
+ this.fulfillmentNoir = null;
699
+ this._isReady = false;
700
+ }
701
+ // ─── Private Utility Methods ────────────────────────────────────────────────
702
+ ensureReady() {
703
+ if (!this._isReady) {
704
+ throw new ProofError(
705
+ "BrowserNoirProvider not initialized. Call initialize() first.",
706
+ "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
707
+ );
708
+ }
709
+ }
710
+ async computeCommitmentHash(balance, blindingFactor, assetId) {
711
+ const blindingField = this.bytesToField(blindingFactor);
712
+ const { sha256 } = await import("@noble/hashes/sha256");
713
+ const { bytesToHex: nobleToHex } = await import("@noble/hashes/utils");
714
+ const preimage = new Uint8Array([
715
+ ...this.bigintToBytes(balance, 8),
716
+ ...blindingFactor.slice(0, 32),
717
+ ...hexToBytes(this.assetIdToField(assetId))
718
+ ]);
719
+ const hash2 = sha256(preimage);
720
+ const commitmentHash = nobleToHex(hash2);
721
+ return { commitmentHash, blindingField };
722
+ }
723
+ assetIdToField(assetId) {
724
+ if (assetId.startsWith("0x")) {
725
+ return assetId.slice(2).padStart(64, "0");
726
+ }
727
+ const encoder = new TextEncoder();
728
+ const bytes = encoder.encode(assetId);
729
+ let result = 0n;
730
+ for (let i = 0; i < bytes.length && i < 31; i++) {
731
+ result = result * 256n + BigInt(bytes[i]);
732
+ }
733
+ return result.toString(16).padStart(64, "0");
734
+ }
735
+ bytesToField(bytes) {
736
+ let result = 0n;
737
+ const len = Math.min(bytes.length, 31);
738
+ for (let i = 0; i < len; i++) {
739
+ result = result * 256n + BigInt(bytes[i]);
740
+ }
741
+ return result.toString();
742
+ }
743
+ bigintToBytes(value, length) {
744
+ const bytes = new Uint8Array(length);
745
+ let v = value;
746
+ for (let i = length - 1; i >= 0; i--) {
747
+ bytes[i] = Number(v & 0xffn);
748
+ v = v >> 8n;
749
+ }
750
+ return bytes;
751
+ }
752
+ hexToField(hex) {
753
+ const h = hex.startsWith("0x") ? hex.slice(2) : hex;
754
+ return h.padStart(64, "0");
755
+ }
756
+ fieldToBytes32(field) {
757
+ const hex = field.padStart(64, "0");
758
+ const bytes = [];
759
+ for (let i = 0; i < 32; i++) {
760
+ bytes.push(parseInt(hex.slice(i * 2, i * 2 + 2), 16));
761
+ }
762
+ return bytes;
763
+ }
764
+ async computeSenderCommitment(senderAddressField, senderBlindingField) {
765
+ const { sha256 } = await import("@noble/hashes/sha256");
766
+ const { bytesToHex: nobleToHex } = await import("@noble/hashes/utils");
767
+ const addressBytes = hexToBytes(senderAddressField);
768
+ const blindingBytes = hexToBytes(senderBlindingField.padStart(64, "0"));
769
+ const preimage = new Uint8Array([...addressBytes, ...blindingBytes]);
770
+ const hash2 = sha256(preimage);
771
+ const commitmentX = nobleToHex(hash2.slice(0, 16)).padStart(64, "0");
772
+ const commitmentY = nobleToHex(hash2.slice(16, 32)).padStart(64, "0");
773
+ return { commitmentX, commitmentY };
774
+ }
775
+ async computeNullifier(senderSecretField, intentHashField, nonceField) {
776
+ const { sha256 } = await import("@noble/hashes/sha256");
777
+ const { bytesToHex: nobleToHex } = await import("@noble/hashes/utils");
778
+ const secretBytes = hexToBytes(senderSecretField.padStart(64, "0"));
779
+ const intentBytes = hexToBytes(intentHashField);
780
+ const nonceBytes = hexToBytes(nonceField.padStart(64, "0"));
781
+ const preimage = new Uint8Array([...secretBytes, ...intentBytes, ...nonceBytes]);
782
+ const hash2 = sha256(preimage);
783
+ return nobleToHex(hash2);
784
+ }
785
+ async computeOutputCommitment(outputAmount, outputBlinding) {
786
+ const { sha256 } = await import("@noble/hashes/sha256");
787
+ const { bytesToHex: nobleToHex } = await import("@noble/hashes/utils");
788
+ const amountBytes = this.bigintToBytes(outputAmount, 8);
789
+ const blindingBytes = outputBlinding.slice(0, 32);
790
+ const preimage = new Uint8Array([...amountBytes, ...blindingBytes]);
791
+ const hash2 = sha256(preimage);
792
+ const commitmentX = nobleToHex(hash2.slice(0, 16)).padStart(64, "0");
793
+ const commitmentY = nobleToHex(hash2.slice(16, 32)).padStart(64, "0");
794
+ return { commitmentX, commitmentY };
795
+ }
796
+ async computeSolverId(solverSecretField) {
797
+ const { sha256 } = await import("@noble/hashes/sha256");
798
+ const { bytesToHex: nobleToHex } = await import("@noble/hashes/utils");
799
+ const secretBytes = hexToBytes(solverSecretField.padStart(64, "0"));
800
+ const hash2 = sha256(secretBytes);
801
+ return nobleToHex(hash2);
802
+ }
803
+ async computeOracleMessageHash(recipient, amount, txHash, blockNumber) {
804
+ const { sha256 } = await import("@noble/hashes/sha256");
805
+ const recipientBytes = hexToBytes(this.hexToField(recipient));
806
+ const amountBytes = this.bigintToBytes(amount, 8);
807
+ const txHashBytes = hexToBytes(this.hexToField(txHash));
808
+ const blockBytes = this.bigintToBytes(blockNumber, 8);
809
+ const preimage = new Uint8Array([
810
+ ...recipientBytes,
811
+ ...amountBytes,
812
+ ...txHashBytes,
813
+ ...blockBytes
814
+ ]);
815
+ const hash2 = sha256(preimage);
816
+ return Array.from(hash2);
817
+ }
818
+ getPublicKeyCoordinates(privateKey) {
819
+ const uncompressedPubKey = secp256k1.getPublicKey(privateKey, false);
820
+ const x = Array.from(uncompressedPubKey.slice(1, 33));
821
+ const y = Array.from(uncompressedPubKey.slice(33, 65));
822
+ return { x, y };
823
+ }
824
+ };
217
825
  export {
218
826
  ATTESTATION_VERSION,
219
827
  BaseWalletAdapter,
@@ -244,7 +852,6 @@ export {
244
852
  NATIVE_TOKENS,
245
853
  NEARIntentsAdapter,
246
854
  NetworkError,
247
- NoirProofProvider,
248
855
  ORACLE_DOMAIN,
249
856
  OneClickClient,
250
857
  OneClickDepositMode,