@sip-protocol/sdk 0.2.8 → 0.2.10

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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/browser.d.mts +100 -2
  4. package/dist/browser.d.ts +100 -2
  5. package/dist/browser.js +1362 -268
  6. package/dist/browser.mjs +502 -16
  7. package/dist/{chunk-UPTISVCY.mjs → chunk-AV37IZST.mjs} +731 -15
  8. package/dist/{chunk-VITVG25F.mjs → chunk-XLEPIR2P.mjs} +2 -100
  9. package/dist/index-BFOKTz2z.d.ts +6062 -0
  10. package/dist/index-CAhjA4kh.d.mts +6062 -0
  11. package/dist/index.d.mts +2 -5609
  12. package/dist/index.d.ts +2 -5609
  13. package/dist/index.js +588 -154
  14. package/dist/index.mjs +5 -1
  15. package/dist/{noir-BHQtFvRk.d.mts → noir-BTyLXLlZ.d.mts} +1 -1
  16. package/dist/{noir-BHQtFvRk.d.ts → noir-BTyLXLlZ.d.ts} +1 -1
  17. package/dist/proofs/noir.d.mts +1 -1
  18. package/dist/proofs/noir.d.ts +1 -1
  19. package/dist/proofs/noir.js +11 -112
  20. package/dist/proofs/noir.mjs +10 -13
  21. package/package.json +16 -16
  22. package/src/browser.ts +23 -0
  23. package/src/index.ts +12 -0
  24. package/src/proofs/browser-utils.ts +389 -0
  25. package/src/proofs/browser.ts +246 -19
  26. package/src/proofs/circuits/funding_proof.json +1 -1
  27. package/src/proofs/noir.ts +14 -14
  28. package/src/proofs/worker.ts +426 -0
  29. package/src/zcash/bridge.ts +738 -0
  30. package/src/zcash/index.ts +36 -1
  31. package/src/zcash/swap-service.ts +793 -0
  32. package/dist/chunk-4VJHI66K.mjs +0 -12120
  33. package/dist/chunk-5BAS4D44.mjs +0 -10283
  34. package/dist/chunk-6WOV2YNG.mjs +0 -10179
  35. package/dist/chunk-DU7LQDD2.mjs +0 -10148
  36. package/dist/chunk-MR7HRCRS.mjs +0 -10165
  37. package/dist/chunk-NDGUWOOZ.mjs +0 -10157
  38. package/dist/chunk-O4Y2ZUDL.mjs +0 -12721
  39. package/dist/chunk-VXSHK7US.mjs +0 -10158
package/dist/browser.js CHANGED
@@ -47,7 +47,7 @@ __export(browser_exports, {
47
47
  HardwareWalletError: () => HardwareWalletError,
48
48
  IntentBuilder: () => IntentBuilder,
49
49
  IntentError: () => IntentError,
50
- IntentStatus: () => import_types33.IntentStatus,
50
+ IntentStatus: () => import_types34.IntentStatus,
51
51
  LedgerWalletAdapter: () => LedgerWalletAdapter,
52
52
  MockEthereumAdapter: () => MockEthereumAdapter,
53
53
  MockLedgerAdapter: () => MockLedgerAdapter,
@@ -56,26 +56,27 @@ __export(browser_exports, {
56
56
  MockSolver: () => MockSolver,
57
57
  MockTrezorAdapter: () => MockTrezorAdapter,
58
58
  MockWalletAdapter: () => MockWalletAdapter,
59
- NATIVE_TOKENS: () => import_types33.NATIVE_TOKENS,
59
+ NATIVE_TOKENS: () => import_types34.NATIVE_TOKENS,
60
60
  NEARIntentsAdapter: () => NEARIntentsAdapter,
61
61
  NetworkError: () => NetworkError,
62
62
  ORACLE_DOMAIN: () => ORACLE_DOMAIN,
63
63
  OneClickClient: () => OneClickClient,
64
- OneClickDepositMode: () => import_types37.OneClickDepositMode,
65
- OneClickErrorCode: () => import_types37.OneClickErrorCode,
66
- OneClickSwapStatus: () => import_types37.OneClickSwapStatus,
67
- OneClickSwapType: () => import_types37.OneClickSwapType,
64
+ OneClickDepositMode: () => import_types38.OneClickDepositMode,
65
+ OneClickErrorCode: () => import_types38.OneClickErrorCode,
66
+ OneClickSwapStatus: () => import_types38.OneClickSwapStatus,
67
+ OneClickSwapType: () => import_types38.OneClickSwapType,
68
68
  PaymentBuilder: () => PaymentBuilder,
69
- PaymentStatus: () => import_types34.PaymentStatus,
70
- PrivacyLevel: () => import_types33.PrivacyLevel,
69
+ PaymentStatus: () => import_types35.PaymentStatus,
70
+ PrivacyLevel: () => import_types34.PrivacyLevel,
71
71
  ProofError: () => ProofError,
72
72
  ProofGenerationError: () => ProofGenerationError,
73
73
  ProofNotImplementedError: () => ProofNotImplementedError,
74
- ProposalStatus: () => import_types35.ProposalStatus,
75
- ReportStatus: () => import_types36.ReportStatus,
74
+ ProofWorker: () => ProofWorker,
75
+ ProposalStatus: () => import_types36.ProposalStatus,
76
+ ReportStatus: () => import_types37.ReportStatus,
76
77
  SIP: () => SIP,
77
78
  SIPError: () => SIPError,
78
- SIP_VERSION: () => import_types33.SIP_VERSION,
79
+ SIP_VERSION: () => import_types34.SIP_VERSION,
79
80
  STABLECOIN_ADDRESSES: () => STABLECOIN_ADDRESSES,
80
81
  STABLECOIN_DECIMALS: () => STABLECOIN_DECIMALS,
81
82
  STABLECOIN_INFO: () => STABLECOIN_INFO,
@@ -84,11 +85,12 @@ __export(browser_exports, {
84
85
  TrezorWalletAdapter: () => TrezorWalletAdapter,
85
86
  ValidationError: () => ValidationError,
86
87
  WalletError: () => WalletError,
87
- WalletErrorCode: () => import_types32.WalletErrorCode,
88
- ZcashErrorCode: () => import_types38.ZcashErrorCode,
88
+ WalletErrorCode: () => import_types33.WalletErrorCode,
89
+ ZcashErrorCode: () => import_types39.ZcashErrorCode,
89
90
  ZcashRPCClient: () => ZcashRPCClient,
90
91
  ZcashRPCError: () => ZcashRPCError,
91
92
  ZcashShieldedService: () => ZcashShieldedService,
93
+ ZcashSwapService: () => ZcashSwapService,
92
94
  addBlindings: () => addBlindings,
93
95
  addCommitments: () => addCommitments,
94
96
  addOracle: () => addOracle,
@@ -97,6 +99,7 @@ __export(browser_exports, {
97
99
  browserBytesToHex: () => bytesToHex7,
98
100
  browserHexToBytes: () => hexToBytes5,
99
101
  checkEd25519StealthAddress: () => checkEd25519StealthAddress,
102
+ checkMobileWASMCompatibility: () => checkMobileWASMCompatibility,
100
103
  checkStealthAddress: () => checkStealthAddress,
101
104
  commit: () => commit,
102
105
  commitZero: () => commitZero,
@@ -121,8 +124,10 @@ __export(browser_exports, {
121
124
  createSolanaAdapter: () => createSolanaAdapter,
122
125
  createTrezorAdapter: () => createTrezorAdapter,
123
126
  createWalletFactory: () => createWalletFactory,
127
+ createWorkerBlobURL: () => createWorkerBlobURL,
124
128
  createZcashClient: () => createZcashClient,
125
129
  createZcashShieldedService: () => createZcashShieldedService,
130
+ createZcashSwapService: () => createZcashSwapService,
126
131
  decodeStealthMetaAddress: () => decodeStealthMetaAddress,
127
132
  decryptMemo: () => decryptMemo,
128
133
  decryptWithViewing: () => decryptWithViewing,
@@ -134,6 +139,8 @@ __export(browser_exports, {
134
139
  deserializeIntent: () => deserializeIntent,
135
140
  deserializePayment: () => deserializePayment,
136
141
  detectEthereumWallets: () => detectEthereumWallets,
142
+ detectMobileBrowser: () => detectMobileBrowser,
143
+ detectMobilePlatform: () => detectMobilePlatform,
137
144
  detectSolanaWallets: () => detectSolanaWallets,
138
145
  ed25519PublicKeyToNearAddress: () => ed25519PublicKeyToNearAddress,
139
146
  ed25519PublicKeyToSolanaAddress: () => ed25519PublicKeyToSolanaAddress,
@@ -154,6 +161,7 @@ __export(browser_exports, {
154
161
  getActiveOracles: () => getActiveOracles,
155
162
  getAvailableTransports: () => getAvailableTransports,
156
163
  getBrowserInfo: () => getBrowserInfo,
164
+ getBrowserVersion: () => getBrowserVersion,
157
165
  getChainNumericId: () => getChainNumericId,
158
166
  getChainsForStablecoin: () => getChainsForStablecoin,
159
167
  getCurveForChain: () => getCurveForChain,
@@ -163,6 +171,8 @@ __export(browser_exports, {
163
171
  getEthereumProvider: () => getEthereumProvider,
164
172
  getGenerators: () => getGenerators,
165
173
  getIntentSummary: () => getIntentSummary,
174
+ getMobileDeviceInfo: () => getMobileDeviceInfo,
175
+ getOSVersion: () => getOSVersion,
166
176
  getPaymentSummary: () => getPaymentSummary,
167
177
  getPaymentTimeRemaining: () => getPaymentTimeRemaining,
168
178
  getPrivacyConfig: () => getPrivacyConfig,
@@ -183,11 +193,12 @@ __export(browser_exports, {
183
193
  isExpired: () => isExpired,
184
194
  isNonNegativeAmount: () => isNonNegativeAmount,
185
195
  isPaymentExpired: () => isPaymentExpired,
186
- isPrivate: () => import_types33.isPrivate,
196
+ isPrivate: () => import_types34.isPrivate,
187
197
  isPrivateWalletAdapter: () => isPrivateWalletAdapter,
188
198
  isSIPError: () => isSIPError,
189
199
  isStablecoin: () => isStablecoin,
190
200
  isStablecoinOnChain: () => isStablecoinOnChain,
201
+ isTablet: () => isTablet,
191
202
  isValidAmount: () => isValidAmount,
192
203
  isValidChainId: () => isValidChainId,
193
204
  isValidCompressedPublicKey: () => isValidCompressedPublicKey,
@@ -219,7 +230,10 @@ __export(browser_exports, {
219
230
  subtractBlindings: () => subtractBlindings,
220
231
  subtractCommitments: () => subtractCommitments,
221
232
  supportsSharedArrayBuffer: () => supportsSharedArrayBuffer,
222
- supportsViewingKey: () => import_types33.supportsViewingKey,
233
+ supportsTouch: () => supportsTouch,
234
+ supportsViewingKey: () => import_types34.supportsViewingKey,
235
+ supportsWASMBulkMemory: () => supportsWASMBulkMemory,
236
+ supportsWASMSimd: () => supportsWASMSimd,
223
237
  supportsWebBluetooth: () => supportsWebBluetooth,
224
238
  supportsWebHID: () => supportsWebHID,
225
239
  supportsWebUSB: () => supportsWebUSB,
@@ -3458,6 +3472,280 @@ var MockProofProvider = class {
3458
3472
  };
3459
3473
 
3460
3474
  // src/proofs/browser-utils.ts
3475
+ function detectMobilePlatform() {
3476
+ if (typeof navigator === "undefined") return "desktop";
3477
+ const ua = navigator.userAgent.toLowerCase();
3478
+ if (/iphone|ipad|ipod/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) {
3479
+ return "ios";
3480
+ }
3481
+ if (/android/.test(ua)) {
3482
+ return "android";
3483
+ }
3484
+ if (/mobile|webos|blackberry|opera mini|opera mobi|iemobile|wpdesktop/.test(ua)) {
3485
+ return "other";
3486
+ }
3487
+ return "desktop";
3488
+ }
3489
+ function detectMobileBrowser() {
3490
+ if (typeof navigator === "undefined") return "other";
3491
+ const ua = navigator.userAgent.toLowerCase();
3492
+ if (/safari/.test(ua) && /iphone|ipad|ipod/.test(ua) && !/crios|fxios/.test(ua)) {
3493
+ return "safari";
3494
+ }
3495
+ if (/chrome|crios/.test(ua) && !/edg|opr|samsung/.test(ua)) {
3496
+ return "chrome";
3497
+ }
3498
+ if (/firefox|fxios/.test(ua)) {
3499
+ return "firefox";
3500
+ }
3501
+ if (/samsung/.test(ua)) {
3502
+ return "samsung";
3503
+ }
3504
+ if (/opr|opera/.test(ua)) {
3505
+ return "opera";
3506
+ }
3507
+ if (/edg/.test(ua)) {
3508
+ return "edge";
3509
+ }
3510
+ return "other";
3511
+ }
3512
+ function getBrowserVersion() {
3513
+ if (typeof navigator === "undefined") return null;
3514
+ const ua = navigator.userAgent;
3515
+ const browser = detectMobileBrowser();
3516
+ const patterns = {
3517
+ safari: /version\/(\d+(\.\d+)*)/i,
3518
+ chrome: /chrome\/(\d+(\.\d+)*)|crios\/(\d+(\.\d+)*)/i,
3519
+ firefox: /firefox\/(\d+(\.\d+)*)|fxios\/(\d+(\.\d+)*)/i,
3520
+ samsung: /samsungbrowser\/(\d+(\.\d+)*)/i,
3521
+ opera: /opr\/(\d+(\.\d+)*)/i,
3522
+ edge: /edg\/(\d+(\.\d+)*)/i,
3523
+ other: /version\/(\d+(\.\d+)*)/i
3524
+ };
3525
+ const pattern = patterns[browser] || patterns.other;
3526
+ const match = ua.match(pattern);
3527
+ if (match) {
3528
+ for (let i = 1; i < match.length; i++) {
3529
+ if (match[i]) return match[i];
3530
+ }
3531
+ }
3532
+ return null;
3533
+ }
3534
+ function getOSVersion() {
3535
+ if (typeof navigator === "undefined") return null;
3536
+ const ua = navigator.userAgent;
3537
+ const platform = detectMobilePlatform();
3538
+ if (platform === "ios") {
3539
+ const match = ua.match(/os (\d+[_\d]*)/i);
3540
+ return match ? match[1].replace(/_/g, ".") : null;
3541
+ }
3542
+ if (platform === "android") {
3543
+ const match = ua.match(/android (\d+(\.\d+)*)/i);
3544
+ return match ? match[1] : null;
3545
+ }
3546
+ return null;
3547
+ }
3548
+ function isTablet() {
3549
+ if (typeof navigator === "undefined") return false;
3550
+ const ua = navigator.userAgent.toLowerCase();
3551
+ if (/ipad/.test(ua) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) {
3552
+ return true;
3553
+ }
3554
+ if (/android/.test(ua) && !/mobile/.test(ua)) {
3555
+ return true;
3556
+ }
3557
+ return false;
3558
+ }
3559
+ function supportsTouch() {
3560
+ if (typeof window === "undefined") return false;
3561
+ return "ontouchstart" in window || navigator.maxTouchPoints > 0;
3562
+ }
3563
+ function getMobileDeviceInfo() {
3564
+ const platform = detectMobilePlatform();
3565
+ return {
3566
+ isMobile: platform !== "desktop",
3567
+ platform,
3568
+ browser: detectMobileBrowser(),
3569
+ browserVersion: getBrowserVersion(),
3570
+ osVersion: getOSVersion(),
3571
+ isTablet: isTablet(),
3572
+ supportsTouch: supportsTouch(),
3573
+ deviceMemoryGB: (
3574
+ // @ts-expect-error - deviceMemory is non-standard
3575
+ typeof navigator !== "undefined" && navigator.deviceMemory ? (
3576
+ // @ts-expect-error - deviceMemory is non-standard
3577
+ navigator.deviceMemory
3578
+ ) : null
3579
+ ),
3580
+ hardwareConcurrency: typeof navigator !== "undefined" && navigator.hardwareConcurrency ? navigator.hardwareConcurrency : null
3581
+ };
3582
+ }
3583
+ function supportsWASMSimd() {
3584
+ try {
3585
+ return WebAssembly.validate(
3586
+ new Uint8Array([
3587
+ 0,
3588
+ 97,
3589
+ 115,
3590
+ 109,
3591
+ 1,
3592
+ 0,
3593
+ 0,
3594
+ 0,
3595
+ 1,
3596
+ 5,
3597
+ 1,
3598
+ 96,
3599
+ 0,
3600
+ 1,
3601
+ 123,
3602
+ 3,
3603
+ 2,
3604
+ 1,
3605
+ 0,
3606
+ 10,
3607
+ 10,
3608
+ 1,
3609
+ 8,
3610
+ 0,
3611
+ 65,
3612
+ 0,
3613
+ 253,
3614
+ 15,
3615
+ 253,
3616
+ 98,
3617
+ 11
3618
+ ])
3619
+ );
3620
+ } catch {
3621
+ return false;
3622
+ }
3623
+ }
3624
+ function supportsWASMBulkMemory() {
3625
+ try {
3626
+ return WebAssembly.validate(
3627
+ new Uint8Array([
3628
+ 0,
3629
+ 97,
3630
+ 115,
3631
+ 109,
3632
+ 1,
3633
+ 0,
3634
+ 0,
3635
+ 0,
3636
+ 1,
3637
+ 4,
3638
+ 1,
3639
+ 96,
3640
+ 0,
3641
+ 0,
3642
+ 3,
3643
+ 2,
3644
+ 1,
3645
+ 0,
3646
+ 5,
3647
+ 3,
3648
+ 1,
3649
+ 0,
3650
+ 1,
3651
+ 10,
3652
+ 13,
3653
+ 1,
3654
+ 11,
3655
+ 0,
3656
+ 65,
3657
+ 0,
3658
+ 65,
3659
+ 0,
3660
+ 65,
3661
+ 0,
3662
+ 252,
3663
+ 11,
3664
+ 0,
3665
+ 11
3666
+ ])
3667
+ );
3668
+ } catch {
3669
+ return false;
3670
+ }
3671
+ }
3672
+ function checkMobileWASMCompatibility() {
3673
+ const issues = [];
3674
+ const recommendations = [];
3675
+ let score = 100;
3676
+ const webAssembly = typeof WebAssembly !== "undefined";
3677
+ if (!webAssembly) {
3678
+ issues.push("WebAssembly not supported");
3679
+ score -= 50;
3680
+ }
3681
+ const sharedArrayBuffer = supportsSharedArrayBuffer();
3682
+ if (!sharedArrayBuffer) {
3683
+ issues.push("SharedArrayBuffer not available (requires COOP/COEP headers)");
3684
+ recommendations.push("Server must send Cross-Origin-Opener-Policy: same-origin");
3685
+ recommendations.push("Server must send Cross-Origin-Embedder-Policy: require-corp");
3686
+ score -= 20;
3687
+ }
3688
+ const webWorkers = supportsWebWorkers();
3689
+ if (!webWorkers) {
3690
+ issues.push("Web Workers not supported");
3691
+ recommendations.push("Consider using a polyfill or fallback to main-thread execution");
3692
+ score -= 15;
3693
+ }
3694
+ const simd = supportsWASMSimd();
3695
+ if (!simd) {
3696
+ recommendations.push("WASM SIMD not supported - proofs will be slower");
3697
+ score -= 5;
3698
+ }
3699
+ const bulkMemory = supportsWASMBulkMemory();
3700
+ if (!bulkMemory) {
3701
+ recommendations.push("WASM bulk memory not supported - may affect performance");
3702
+ score -= 5;
3703
+ }
3704
+ const bigInt = typeof BigInt !== "undefined";
3705
+ if (!bigInt) {
3706
+ issues.push("BigInt not supported (required for 64-bit operations)");
3707
+ score -= 10;
3708
+ }
3709
+ const deviceInfo = getMobileDeviceInfo();
3710
+ if (deviceInfo.isMobile) {
3711
+ if (deviceInfo.deviceMemoryGB !== null && deviceInfo.deviceMemoryGB < 2) {
3712
+ recommendations.push(`Low device memory (${deviceInfo.deviceMemoryGB}GB) - may experience issues with large proofs`);
3713
+ score -= 5;
3714
+ }
3715
+ if (deviceInfo.platform === "ios" && deviceInfo.browser === "safari") {
3716
+ if (!sharedArrayBuffer) {
3717
+ recommendations.push("iOS Safari requires iOS 15.2+ for SharedArrayBuffer support");
3718
+ }
3719
+ }
3720
+ if (deviceInfo.platform === "android" && deviceInfo.browser === "chrome") {
3721
+ if (!sharedArrayBuffer) {
3722
+ recommendations.push("Ensure COOP/COEP headers are set - Chrome Android requires them");
3723
+ }
3724
+ }
3725
+ }
3726
+ let summary;
3727
+ if (score >= 90) {
3728
+ summary = "Excellent - Full WASM proof support";
3729
+ } else if (score >= 70) {
3730
+ summary = "Good - WASM proofs supported with minor limitations";
3731
+ } else if (score >= 50) {
3732
+ summary = "Limited - WASM proofs may work with reduced performance";
3733
+ } else {
3734
+ summary = "Poor - WASM proofs not recommended on this device";
3735
+ }
3736
+ return {
3737
+ webAssembly,
3738
+ sharedArrayBuffer,
3739
+ webWorkers,
3740
+ simd,
3741
+ bulkMemory,
3742
+ bigInt,
3743
+ score: Math.max(0, score),
3744
+ summary,
3745
+ issues,
3746
+ recommendations
3747
+ };
3748
+ }
3461
3749
  function hexToBytes5(hex) {
3462
3750
  const h = hex.startsWith("0x") ? hex.slice(2) : hex;
3463
3751
  if (h.length === 0) return new Uint8Array(0);
@@ -3773,10 +4061,10 @@ function hasEnoughOracles(registry) {
3773
4061
  }
3774
4062
 
3775
4063
  // src/index.ts
3776
- var import_types33 = require("@sip-protocol/types");
3777
4064
  var import_types34 = require("@sip-protocol/types");
3778
4065
  var import_types35 = require("@sip-protocol/types");
3779
4066
  var import_types36 = require("@sip-protocol/types");
4067
+ var import_types37 = require("@sip-protocol/types");
3780
4068
 
3781
4069
  // src/solver/mock-solver.ts
3782
4070
  var import_types7 = require("@sip-protocol/types");
@@ -3961,7 +4249,7 @@ function createMockSolver(config) {
3961
4249
  }
3962
4250
 
3963
4251
  // src/index.ts
3964
- var import_types37 = require("@sip-protocol/types");
4252
+ var import_types38 = require("@sip-protocol/types");
3965
4253
 
3966
4254
  // src/zcash/rpc-client.ts
3967
4255
  var import_types8 = require("@sip-protocol/types");
@@ -4805,14 +5093,444 @@ function createZcashShieldedService(config) {
4805
5093
  return new ZcashShieldedService(config);
4806
5094
  }
4807
5095
 
4808
- // src/zcash/index.ts
5096
+ // src/zcash/swap-service.ts
4809
5097
  var import_types10 = require("@sip-protocol/types");
5098
+ var MOCK_PRICES = {
5099
+ ETH: 2500,
5100
+ SOL: 120,
5101
+ NEAR: 5,
5102
+ MATIC: 0.8,
5103
+ USDC: 1,
5104
+ USDT: 1,
5105
+ ZEC: 35
5106
+ };
5107
+ var TOKEN_DECIMALS = {
5108
+ ETH: 18,
5109
+ SOL: 9,
5110
+ NEAR: 24,
5111
+ MATIC: 18,
5112
+ USDC: 6,
5113
+ USDT: 6,
5114
+ ZEC: 8
5115
+ // zatoshis
5116
+ };
5117
+ var ZcashSwapService = class {
5118
+ config;
5119
+ zcashService;
5120
+ bridgeProvider;
5121
+ priceFeed;
5122
+ quotes = /* @__PURE__ */ new Map();
5123
+ swaps = /* @__PURE__ */ new Map();
5124
+ constructor(config) {
5125
+ this.config = {
5126
+ mode: config.mode,
5127
+ defaultSlippage: config.defaultSlippage ?? 100,
5128
+ // 1%
5129
+ quoteValiditySeconds: config.quoteValiditySeconds ?? 60
5130
+ };
5131
+ this.zcashService = config.zcashService;
5132
+ this.bridgeProvider = config.bridgeProvider;
5133
+ this.priceFeed = config.priceFeed;
5134
+ }
5135
+ // ─── Quote Methods ───────────────────────────────────────────────────────────
5136
+ /**
5137
+ * Get a quote for swapping to ZEC
5138
+ */
5139
+ async getQuote(params) {
5140
+ this.validateQuoteParams(params);
5141
+ if (this.zcashService) {
5142
+ const addressInfo = await this.zcashService.validateAddress(params.recipientZAddress);
5143
+ if (!addressInfo.isvalid) {
5144
+ throw new ValidationError(
5145
+ "Invalid Zcash address",
5146
+ "recipientZAddress",
5147
+ { received: params.recipientZAddress },
5148
+ "SIP_2007" /* INVALID_ADDRESS */
5149
+ );
5150
+ }
5151
+ } else {
5152
+ if (!this.isValidZAddressFormat(params.recipientZAddress)) {
5153
+ throw new ValidationError(
5154
+ "Invalid Zcash address format. Expected z-address (zs1...) or unified address (u1...)",
5155
+ "recipientZAddress",
5156
+ { received: params.recipientZAddress },
5157
+ "SIP_2007" /* INVALID_ADDRESS */
5158
+ );
5159
+ }
5160
+ }
5161
+ if (this.config.mode === "production" && this.bridgeProvider) {
5162
+ return this.getProductionQuote(params);
5163
+ }
5164
+ return this.getDemoQuote(params);
5165
+ }
5166
+ /**
5167
+ * Get quote in demo mode (uses mock prices)
5168
+ */
5169
+ async getDemoQuote(params) {
5170
+ const { sourceChain, sourceToken, amount, recipientZAddress, slippage } = params;
5171
+ const sourcePrice = this.priceFeed ? await this.priceFeed.getPrice(sourceToken) : MOCK_PRICES[sourceToken] ?? 1;
5172
+ const zecPrice = this.priceFeed ? await this.priceFeed.getZecPrice() : MOCK_PRICES.ZEC;
5173
+ const sourceDecimals = TOKEN_DECIMALS[sourceToken] ?? 18;
5174
+ const amountInUsd = Number(amount) / 10 ** sourceDecimals * sourcePrice;
5175
+ const swapFeeUsd = amountInUsd * 5e-3;
5176
+ const networkFeeUsd = 2;
5177
+ const totalFeeUsd = swapFeeUsd + networkFeeUsd;
5178
+ const netAmountUsd = amountInUsd - totalFeeUsd;
5179
+ const zecAmount = netAmountUsd / zecPrice;
5180
+ const zecZatoshis = BigInt(Math.floor(zecAmount * 1e8));
5181
+ const slippageBps = slippage ?? this.config.defaultSlippage;
5182
+ const minimumOutput = zecZatoshis * BigInt(1e4 - slippageBps) / 10000n;
5183
+ const swapFee = BigInt(Math.floor(swapFeeUsd / sourcePrice * 10 ** sourceDecimals));
5184
+ const networkFee = BigInt(Math.floor(networkFeeUsd / sourcePrice * 10 ** sourceDecimals));
5185
+ const quoteId = `zec_quote_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
5186
+ const validUntil = Math.floor(Date.now() / 1e3) + this.config.quoteValiditySeconds;
5187
+ const quote = {
5188
+ quoteId,
5189
+ sourceChain,
5190
+ sourceToken,
5191
+ amountIn: amount,
5192
+ amountInFormatted: this.formatAmount(amount, sourceDecimals),
5193
+ amountOut: zecZatoshis,
5194
+ amountOutFormatted: this.formatAmount(zecZatoshis, 8),
5195
+ exchangeRate: zecPrice / sourcePrice,
5196
+ networkFee,
5197
+ swapFee,
5198
+ totalFee: networkFee + swapFee,
5199
+ slippage: slippageBps,
5200
+ minimumOutput,
5201
+ validUntil,
5202
+ depositAddress: this.generateMockDepositAddress(sourceChain),
5203
+ estimatedTime: this.getEstimatedTime(sourceChain),
5204
+ privacyLevel: import_types10.PrivacyLevel.SHIELDED
5205
+ };
5206
+ this.quotes.set(quoteId, quote);
5207
+ return quote;
5208
+ }
5209
+ /**
5210
+ * Get quote in production mode (uses bridge provider)
5211
+ */
5212
+ async getProductionQuote(params) {
5213
+ if (!this.bridgeProvider) {
5214
+ throw new IntentError(
5215
+ "Bridge provider not configured for production mode",
5216
+ "SIP_5004" /* INTENT_INVALID_STATE */
5217
+ );
5218
+ }
5219
+ const bridgeQuote = await this.bridgeProvider.getQuote({
5220
+ sourceChain: params.sourceChain,
5221
+ sourceToken: params.sourceToken,
5222
+ amount: params.amount,
5223
+ recipientAddress: params.recipientZAddress
5224
+ });
5225
+ const sourceDecimals = TOKEN_DECIMALS[params.sourceToken] ?? 18;
5226
+ const slippageBps = params.slippage ?? this.config.defaultSlippage;
5227
+ const minimumOutput = bridgeQuote.amountOut * BigInt(1e4 - slippageBps) / 10000n;
5228
+ const quote = {
5229
+ quoteId: bridgeQuote.quoteId,
5230
+ sourceChain: params.sourceChain,
5231
+ sourceToken: params.sourceToken,
5232
+ amountIn: bridgeQuote.amountIn,
5233
+ amountInFormatted: this.formatAmount(bridgeQuote.amountIn, sourceDecimals),
5234
+ amountOut: bridgeQuote.amountOut,
5235
+ amountOutFormatted: this.formatAmount(bridgeQuote.amountOut, 8),
5236
+ exchangeRate: bridgeQuote.exchangeRate,
5237
+ networkFee: 0n,
5238
+ // Included in bridge fee
5239
+ swapFee: bridgeQuote.fee,
5240
+ totalFee: bridgeQuote.fee,
5241
+ slippage: slippageBps,
5242
+ minimumOutput,
5243
+ validUntil: bridgeQuote.validUntil,
5244
+ depositAddress: "",
5245
+ // Will be set by bridge
5246
+ estimatedTime: this.getEstimatedTime(params.sourceChain),
5247
+ privacyLevel: import_types10.PrivacyLevel.SHIELDED
5248
+ };
5249
+ this.quotes.set(quote.quoteId, quote);
5250
+ return quote;
5251
+ }
5252
+ // ─── Swap Execution ──────────────────────────────────────────────────────────
5253
+ /**
5254
+ * Execute a swap to Zcash shielded pool
5255
+ */
5256
+ async executeSwapToShielded(params) {
5257
+ let quote;
5258
+ if (params.quoteId) {
5259
+ quote = this.quotes.get(params.quoteId);
5260
+ if (!quote) {
5261
+ throw new ValidationError(
5262
+ "Quote not found or expired",
5263
+ "quoteId",
5264
+ { received: params.quoteId },
5265
+ "SIP_2000" /* VALIDATION_FAILED */
5266
+ );
5267
+ }
5268
+ }
5269
+ if (!quote) {
5270
+ quote = await this.getQuote({
5271
+ sourceChain: params.sourceChain,
5272
+ sourceToken: params.sourceToken,
5273
+ amount: params.amount,
5274
+ recipientZAddress: params.recipientZAddress,
5275
+ slippage: params.slippage
5276
+ });
5277
+ }
5278
+ if (quote.validUntil < Math.floor(Date.now() / 1e3)) {
5279
+ throw new IntentError(
5280
+ "Quote has expired",
5281
+ "SIP_5001" /* INTENT_EXPIRED */,
5282
+ { context: { quoteId: quote.quoteId, validUntil: quote.validUntil } }
5283
+ );
5284
+ }
5285
+ const requestId = `zec_swap_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
5286
+ const result = {
5287
+ requestId,
5288
+ quoteId: quote.quoteId,
5289
+ status: "pending_deposit",
5290
+ amountIn: params.amount,
5291
+ recipientZAddress: params.recipientZAddress,
5292
+ timestamp: Math.floor(Date.now() / 1e3)
5293
+ };
5294
+ this.swaps.set(requestId, result);
5295
+ if (this.config.mode === "production" && this.bridgeProvider) {
5296
+ return this.executeProductionSwap(result, quote, params);
5297
+ }
5298
+ return this.executeDemoSwap(result, quote, params);
5299
+ }
5300
+ /**
5301
+ * Execute swap in demo mode
5302
+ */
5303
+ async executeDemoSwap(result, quote, params) {
5304
+ result.status = "deposit_confirmed";
5305
+ result.sourceTxHash = `0x${this.randomHex(64)}`;
5306
+ this.swaps.set(result.requestId, { ...result });
5307
+ await this.delay(100);
5308
+ result.status = "swapping";
5309
+ this.swaps.set(result.requestId, { ...result });
5310
+ await this.delay(100);
5311
+ result.status = "sending_zec";
5312
+ this.swaps.set(result.requestId, { ...result });
5313
+ if (this.zcashService) {
5314
+ try {
5315
+ const zecAmount = Number(quote.amountOut) / 1e8;
5316
+ const sendResult = await this.zcashService.sendShielded({
5317
+ to: params.recipientZAddress,
5318
+ amount: zecAmount,
5319
+ memo: params.memo ?? `SIP Swap: ${params.sourceToken} \u2192 ZEC`
5320
+ });
5321
+ result.status = "completed";
5322
+ result.zcashTxId = sendResult.txid;
5323
+ result.amountOut = quote.amountOut;
5324
+ } catch (error) {
5325
+ result.status = "completed";
5326
+ result.zcashTxId = this.randomHex(64);
5327
+ result.amountOut = quote.amountOut;
5328
+ }
5329
+ } else {
5330
+ result.status = "completed";
5331
+ result.zcashTxId = this.randomHex(64);
5332
+ result.amountOut = quote.amountOut;
5333
+ }
5334
+ this.swaps.set(result.requestId, { ...result });
5335
+ return result;
5336
+ }
5337
+ /**
5338
+ * Execute swap in production mode
5339
+ */
5340
+ async executeProductionSwap(result, quote, params) {
5341
+ if (!this.bridgeProvider) {
5342
+ throw new IntentError(
5343
+ "Bridge provider not configured",
5344
+ "SIP_5004" /* INTENT_INVALID_STATE */
5345
+ );
5346
+ }
5347
+ try {
5348
+ const bridgeResult = await this.bridgeProvider.executeSwap({
5349
+ sourceChain: params.sourceChain,
5350
+ sourceToken: params.sourceToken,
5351
+ amount: params.amount,
5352
+ recipientAddress: params.recipientZAddress,
5353
+ quoteId: quote.quoteId,
5354
+ depositAddress: quote.depositAddress
5355
+ });
5356
+ result.sourceTxHash = bridgeResult.txHash;
5357
+ result.status = bridgeResult.status === "completed" ? "completed" : "swapping";
5358
+ if (bridgeResult.amountReceived) {
5359
+ result.amountOut = bridgeResult.amountReceived;
5360
+ }
5361
+ } catch (error) {
5362
+ result.status = "failed";
5363
+ result.error = error instanceof Error ? error.message : "Bridge execution failed";
5364
+ }
5365
+ this.swaps.set(result.requestId, { ...result });
5366
+ return result;
5367
+ }
5368
+ // ─── Status Methods ──────────────────────────────────────────────────────────
5369
+ /**
5370
+ * Get swap status
5371
+ */
5372
+ async getSwapStatus(requestId) {
5373
+ return this.swaps.get(requestId) ?? null;
5374
+ }
5375
+ /**
5376
+ * Wait for swap completion
5377
+ */
5378
+ async waitForCompletion(requestId, timeout = 3e5, pollInterval = 5e3) {
5379
+ const startTime = Date.now();
5380
+ while (Date.now() - startTime < timeout) {
5381
+ const status = await this.getSwapStatus(requestId);
5382
+ if (!status) {
5383
+ throw new IntentError(
5384
+ "Swap not found",
5385
+ "SIP_5003" /* INTENT_NOT_FOUND */,
5386
+ { context: { requestId } }
5387
+ );
5388
+ }
5389
+ if (status.status === "completed") {
5390
+ return status;
5391
+ }
5392
+ if (status.status === "failed" || status.status === "expired") {
5393
+ throw new IntentError(
5394
+ `Swap ${status.status}: ${status.error ?? "Unknown error"}`,
5395
+ "SIP_5000" /* INTENT_FAILED */,
5396
+ { context: { requestId, status } }
5397
+ );
5398
+ }
5399
+ await this.delay(pollInterval);
5400
+ }
5401
+ throw new NetworkError(
5402
+ "Swap completion timeout",
5403
+ "SIP_6001" /* NETWORK_TIMEOUT */,
5404
+ { context: { requestId, timeout } }
5405
+ );
5406
+ }
5407
+ // ─── Utility Methods ─────────────────────────────────────────────────────────
5408
+ /**
5409
+ * Get supported source chains
5410
+ */
5411
+ async getSupportedChains() {
5412
+ if (this.bridgeProvider) {
5413
+ return this.bridgeProvider.getSupportedChains();
5414
+ }
5415
+ return ["ethereum", "solana", "near", "polygon", "arbitrum", "base"];
5416
+ }
5417
+ /**
5418
+ * Get supported source tokens for a chain
5419
+ */
5420
+ getSupportedTokens(chain) {
5421
+ const tokensByChain = {
5422
+ ethereum: ["ETH", "USDC", "USDT"],
5423
+ solana: ["SOL", "USDC", "USDT"],
5424
+ near: ["NEAR", "USDC", "USDT"],
5425
+ polygon: ["MATIC", "USDC", "USDT"],
5426
+ arbitrum: ["ETH", "USDC", "USDT"],
5427
+ base: ["ETH", "USDC"]
5428
+ };
5429
+ return tokensByChain[chain] ?? [];
5430
+ }
5431
+ /**
5432
+ * Check if a swap route is supported
5433
+ */
5434
+ isRouteSupported(chain, token) {
5435
+ return this.getSupportedTokens(chain).includes(token);
5436
+ }
5437
+ // ─── Private Helpers ─────────────────────────────────────────────────────────
5438
+ validateQuoteParams(params) {
5439
+ if (!params.sourceChain) {
5440
+ throw new ValidationError("Source chain is required", "sourceChain", void 0, "SIP_2000" /* VALIDATION_FAILED */);
5441
+ }
5442
+ if (!params.sourceToken) {
5443
+ throw new ValidationError("Source token is required", "sourceToken", void 0, "SIP_2000" /* VALIDATION_FAILED */);
5444
+ }
5445
+ if (!params.amount || params.amount <= 0n) {
5446
+ throw new ValidationError("Amount must be positive", "amount", { received: params.amount }, "SIP_2004" /* INVALID_AMOUNT */);
5447
+ }
5448
+ if (!params.recipientZAddress) {
5449
+ throw new ValidationError("Recipient z-address is required", "recipientZAddress", void 0, "SIP_2000" /* VALIDATION_FAILED */);
5450
+ }
5451
+ if (!this.isRouteSupported(params.sourceChain, params.sourceToken)) {
5452
+ throw new ValidationError(
5453
+ `Unsupported swap route: ${params.sourceChain}:${params.sourceToken} \u2192 ZEC`,
5454
+ "sourceToken",
5455
+ { chain: params.sourceChain, token: params.sourceToken },
5456
+ "SIP_2000" /* VALIDATION_FAILED */
5457
+ );
5458
+ }
5459
+ }
5460
+ isValidZAddressFormat(address) {
5461
+ return address.startsWith("zs1") || address.startsWith("u1") || address.startsWith("ztestsapling") || address.startsWith("utest");
5462
+ }
5463
+ generateMockDepositAddress(chain) {
5464
+ switch (chain) {
5465
+ case "ethereum":
5466
+ case "polygon":
5467
+ case "arbitrum":
5468
+ case "base":
5469
+ return `0x${this.randomHex(40)}`;
5470
+ case "solana":
5471
+ return this.randomBase58(44);
5472
+ case "near":
5473
+ return `deposit_${this.randomHex(8)}.near`;
5474
+ default:
5475
+ return `0x${this.randomHex(40)}`;
5476
+ }
5477
+ }
5478
+ getEstimatedTime(chain) {
5479
+ const times = {
5480
+ ethereum: 900,
5481
+ // ~15 min (confirmations + processing)
5482
+ solana: 300,
5483
+ // ~5 min
5484
+ near: 300,
5485
+ // ~5 min
5486
+ polygon: 600,
5487
+ // ~10 min
5488
+ arbitrum: 600,
5489
+ // ~10 min
5490
+ base: 600
5491
+ // ~10 min
5492
+ };
5493
+ return times[chain] ?? 600;
5494
+ }
5495
+ formatAmount(amount, decimals) {
5496
+ const divisor = 10 ** decimals;
5497
+ const whole = amount / BigInt(divisor);
5498
+ const fraction = amount % BigInt(divisor);
5499
+ const fractionStr = fraction.toString().padStart(decimals, "0").replace(/0+$/, "");
5500
+ return fractionStr ? `${whole}.${fractionStr}` : whole.toString();
5501
+ }
5502
+ randomHex(length) {
5503
+ const chars = "0123456789abcdef";
5504
+ let result = "";
5505
+ for (let i = 0; i < length; i++) {
5506
+ result += chars[Math.floor(Math.random() * chars.length)];
5507
+ }
5508
+ return result;
5509
+ }
5510
+ randomBase58(length) {
5511
+ const chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
5512
+ let result = "";
5513
+ for (let i = 0; i < length; i++) {
5514
+ result += chars[Math.floor(Math.random() * chars.length)];
5515
+ }
5516
+ return result;
5517
+ }
5518
+ delay(ms) {
5519
+ return new Promise((resolve) => setTimeout(resolve, ms));
5520
+ }
5521
+ };
5522
+ function createZcashSwapService(config) {
5523
+ return new ZcashSwapService(config);
5524
+ }
5525
+
5526
+ // src/zcash/index.ts
5527
+ var import_types11 = require("@sip-protocol/types");
4810
5528
 
4811
5529
  // src/index.ts
4812
- var import_types38 = require("@sip-protocol/types");
5530
+ var import_types39 = require("@sip-protocol/types");
4813
5531
 
4814
5532
  // src/payment/payment.ts
4815
- var import_types11 = require("@sip-protocol/types");
5533
+ var import_types12 = require("@sip-protocol/types");
4816
5534
  var import_sha2569 = require("@noble/hashes/sha256");
4817
5535
  var import_utils11 = require("@noble/hashes/utils");
4818
5536
  var import_chacha2 = require("@noble/ciphers/chacha.js");
@@ -4999,7 +5717,7 @@ var PaymentBuilder = class {
4999
5717
  _amount;
5000
5718
  _recipientMetaAddress;
5001
5719
  _recipientAddress;
5002
- _privacy = import_types11.PrivacyLevel.SHIELDED;
5720
+ _privacy = import_types12.PrivacyLevel.SHIELDED;
5003
5721
  _viewingKey;
5004
5722
  _sourceChain;
5005
5723
  _destinationChain;
@@ -5282,7 +6000,7 @@ async function createShieldedPayment(params, options) {
5282
6000
  } else {
5283
6001
  resolvedToken = token;
5284
6002
  }
5285
- if (privacy !== import_types11.PrivacyLevel.TRANSPARENT && !recipientMetaAddress) {
6003
+ if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && !recipientMetaAddress) {
5286
6004
  throw new ValidationError(
5287
6005
  "recipientMetaAddress is required for shielded/compliant privacy modes",
5288
6006
  "recipientMetaAddress",
@@ -5290,7 +6008,7 @@ async function createShieldedPayment(params, options) {
5290
6008
  "SIP_2008" /* MISSING_REQUIRED */
5291
6009
  );
5292
6010
  }
5293
- if (privacy === import_types11.PrivacyLevel.TRANSPARENT && !recipientAddress) {
6011
+ if (privacy === import_types12.PrivacyLevel.TRANSPARENT && !recipientAddress) {
5294
6012
  throw new ValidationError(
5295
6013
  "recipientAddress is required for transparent mode",
5296
6014
  "recipientAddress",
@@ -5298,7 +6016,7 @@ async function createShieldedPayment(params, options) {
5298
6016
  "SIP_2008" /* MISSING_REQUIRED */
5299
6017
  );
5300
6018
  }
5301
- if (privacy === import_types11.PrivacyLevel.COMPLIANT && !viewingKey) {
6019
+ if (privacy === import_types12.PrivacyLevel.COMPLIANT && !viewingKey) {
5302
6020
  throw new ValidationError(
5303
6021
  "viewingKey is required for compliant mode",
5304
6022
  "viewingKey",
@@ -5320,7 +6038,7 @@ async function createShieldedPayment(params, options) {
5320
6038
  const now = Math.floor(Date.now() / 1e3);
5321
6039
  const payment = {
5322
6040
  paymentId,
5323
- version: import_types11.SIP_VERSION,
6041
+ version: import_types12.SIP_VERSION,
5324
6042
  privacyLevel: privacy,
5325
6043
  createdAt: now,
5326
6044
  expiry: now + ttl,
@@ -5331,7 +6049,7 @@ async function createShieldedPayment(params, options) {
5331
6049
  purpose,
5332
6050
  viewingKeyHash
5333
6051
  };
5334
- if (privacy !== import_types11.PrivacyLevel.TRANSPARENT && recipientMetaAddress) {
6052
+ if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && recipientMetaAddress) {
5335
6053
  const metaAddress = decodeStealthMetaAddress(recipientMetaAddress);
5336
6054
  const { stealthAddress } = generateStealthAddress(metaAddress);
5337
6055
  payment.recipientStealth = stealthAddress;
@@ -5348,7 +6066,7 @@ async function createShieldedPayment(params, options) {
5348
6066
  payment.recipientAddress = recipientAddress;
5349
6067
  payment.memo = memo;
5350
6068
  }
5351
- if (privacy !== import_types11.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
6069
+ if (privacy !== import_types12.PrivacyLevel.TRANSPARENT && proofProvider?.isReady) {
5352
6070
  const hexToUint8 = (hex) => {
5353
6071
  const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
5354
6072
  return (0, import_utils11.hexToBytes)(cleanHex);
@@ -5414,7 +6132,7 @@ function decryptMemo(encryptedMemo, viewingKey) {
5414
6132
  function trackPayment(payment) {
5415
6133
  return {
5416
6134
  ...payment,
5417
- status: import_types11.PaymentStatus.DRAFT
6135
+ status: import_types12.PaymentStatus.DRAFT
5418
6136
  };
5419
6137
  }
5420
6138
  function isPaymentExpired(payment) {
@@ -5447,7 +6165,7 @@ function getPaymentSummary(payment) {
5447
6165
  }
5448
6166
 
5449
6167
  // src/treasury/treasury.ts
5450
- var import_types12 = require("@sip-protocol/types");
6168
+ var import_types13 = require("@sip-protocol/types");
5451
6169
  var import_secp256k13 = require("@noble/curves/secp256k1");
5452
6170
  var import_sha25610 = require("@noble/hashes/sha256");
5453
6171
  var import_utils12 = require("@noble/hashes/utils");
@@ -5480,7 +6198,7 @@ var Treasury = class _Treasury {
5480
6198
  ...m,
5481
6199
  addedAt: now
5482
6200
  })),
5483
- defaultPrivacy: params.defaultPrivacy ?? import_types12.PrivacyLevel.SHIELDED,
6201
+ defaultPrivacy: params.defaultPrivacy ?? import_types13.PrivacyLevel.SHIELDED,
5484
6202
  masterViewingKey,
5485
6203
  dailyLimit: params.dailyLimit,
5486
6204
  transactionLimit: params.transactionLimit,
@@ -5559,7 +6277,7 @@ var Treasury = class _Treasury {
5559
6277
  proposalId,
5560
6278
  treasuryId: this.config.treasuryId,
5561
6279
  type: "payment",
5562
- status: import_types12.ProposalStatus.PENDING,
6280
+ status: import_types13.ProposalStatus.PENDING,
5563
6281
  proposer: "",
5564
6282
  // Should be set by caller
5565
6283
  title: params.title,
@@ -5592,7 +6310,7 @@ var Treasury = class _Treasury {
5592
6310
  proposalId,
5593
6311
  treasuryId: this.config.treasuryId,
5594
6312
  type: "batch_payment",
5595
- status: import_types12.ProposalStatus.PENDING,
6313
+ status: import_types13.ProposalStatus.PENDING,
5596
6314
  proposer: "",
5597
6315
  title: params.title,
5598
6316
  description: params.description,
@@ -5626,7 +6344,7 @@ var Treasury = class _Treasury {
5626
6344
  * Get pending proposals
5627
6345
  */
5628
6346
  getPendingProposals() {
5629
- return this.getAllProposals().filter((p) => p.status === import_types12.ProposalStatus.PENDING);
6347
+ return this.getAllProposals().filter((p) => p.status === import_types13.ProposalStatus.PENDING);
5630
6348
  }
5631
6349
  /**
5632
6350
  * Sign a proposal
@@ -5657,7 +6375,7 @@ var Treasury = class _Treasury {
5657
6375
  "SIP_2001" /* INVALID_INPUT */
5658
6376
  );
5659
6377
  }
5660
- if (proposal.status !== import_types12.ProposalStatus.PENDING) {
6378
+ if (proposal.status !== import_types13.ProposalStatus.PENDING) {
5661
6379
  throw new ValidationError(
5662
6380
  `proposal is not pending: ${proposal.status}`,
5663
6381
  "proposalId",
@@ -5667,7 +6385,7 @@ var Treasury = class _Treasury {
5667
6385
  }
5668
6386
  const now = Math.floor(Date.now() / 1e3);
5669
6387
  if (now > proposal.expiresAt) {
5670
- proposal.status = import_types12.ProposalStatus.EXPIRED;
6388
+ proposal.status = import_types13.ProposalStatus.EXPIRED;
5671
6389
  throw new ValidationError(
5672
6390
  "proposal has expired",
5673
6391
  "proposalId",
@@ -5699,9 +6417,9 @@ var Treasury = class _Treasury {
5699
6417
  const approvals = proposal.signatures.filter((s) => s.approved).length;
5700
6418
  const rejections = proposal.signatures.filter((s) => !s.approved).length;
5701
6419
  if (approvals >= proposal.requiredSignatures) {
5702
- proposal.status = import_types12.ProposalStatus.APPROVED;
6420
+ proposal.status = import_types13.ProposalStatus.APPROVED;
5703
6421
  } else if (rejections > this.config.totalSigners - proposal.requiredSignatures) {
5704
- proposal.status = import_types12.ProposalStatus.REJECTED;
6422
+ proposal.status = import_types13.ProposalStatus.REJECTED;
5705
6423
  }
5706
6424
  return proposal;
5707
6425
  }
@@ -5718,7 +6436,7 @@ var Treasury = class _Treasury {
5718
6436
  "SIP_2001" /* INVALID_INPUT */
5719
6437
  );
5720
6438
  }
5721
- if (proposal.status !== import_types12.ProposalStatus.APPROVED) {
6439
+ if (proposal.status !== import_types13.ProposalStatus.APPROVED) {
5722
6440
  throw new ValidationError(
5723
6441
  `proposal is not approved: ${proposal.status}`,
5724
6442
  "proposalId",
@@ -5731,8 +6449,8 @@ var Treasury = class _Treasury {
5731
6449
  const payment = await createShieldedPayment({
5732
6450
  token: proposal.payment.token,
5733
6451
  amount: proposal.payment.amount,
5734
- recipientMetaAddress: proposal.payment.privacy !== import_types12.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
5735
- recipientAddress: proposal.payment.privacy === import_types12.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
6452
+ recipientMetaAddress: proposal.payment.privacy !== import_types13.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
6453
+ recipientAddress: proposal.payment.privacy === import_types13.PrivacyLevel.TRANSPARENT ? proposal.payment.recipient : void 0,
5736
6454
  privacy: proposal.payment.privacy,
5737
6455
  viewingKey: this.config.masterViewingKey?.key,
5738
6456
  sourceChain: this.config.chain,
@@ -5745,8 +6463,8 @@ var Treasury = class _Treasury {
5745
6463
  const payment = await createShieldedPayment({
5746
6464
  token: proposal.batchPayment.token,
5747
6465
  amount: recipient.amount,
5748
- recipientMetaAddress: proposal.batchPayment.privacy !== import_types12.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
5749
- recipientAddress: proposal.batchPayment.privacy === import_types12.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
6466
+ recipientMetaAddress: proposal.batchPayment.privacy !== import_types13.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
6467
+ recipientAddress: proposal.batchPayment.privacy === import_types13.PrivacyLevel.TRANSPARENT ? recipient.address : void 0,
5750
6468
  privacy: proposal.batchPayment.privacy,
5751
6469
  viewingKey: this.config.masterViewingKey?.key,
5752
6470
  sourceChain: this.config.chain,
@@ -5756,7 +6474,7 @@ var Treasury = class _Treasury {
5756
6474
  payments.push(payment);
5757
6475
  }
5758
6476
  }
5759
- proposal.status = import_types12.ProposalStatus.EXECUTED;
6477
+ proposal.status = import_types13.ProposalStatus.EXECUTED;
5760
6478
  proposal.executedAt = Math.floor(Date.now() / 1e3);
5761
6479
  proposal.resultPayments = payments;
5762
6480
  return payments;
@@ -5785,7 +6503,7 @@ var Treasury = class _Treasury {
5785
6503
  "SIP_2001" /* INVALID_INPUT */
5786
6504
  );
5787
6505
  }
5788
- if (proposal.status !== import_types12.ProposalStatus.PENDING) {
6506
+ if (proposal.status !== import_types13.ProposalStatus.PENDING) {
5789
6507
  throw new ValidationError(
5790
6508
  `proposal is not pending: ${proposal.status}`,
5791
6509
  "proposalId",
@@ -5793,7 +6511,7 @@ var Treasury = class _Treasury {
5793
6511
  "SIP_2001" /* INVALID_INPUT */
5794
6512
  );
5795
6513
  }
5796
- proposal.status = import_types12.ProposalStatus.CANCELLED;
6514
+ proposal.status = import_types13.ProposalStatus.CANCELLED;
5797
6515
  return proposal;
5798
6516
  }
5799
6517
  // ─── Auditor Access ──────────────────────────────────────────────────────────
@@ -5890,7 +6608,7 @@ var Treasury = class _Treasury {
5890
6608
  getCommittedAmount(token) {
5891
6609
  let committed = 0n;
5892
6610
  for (const proposal of this.proposals.values()) {
5893
- if (proposal.status !== import_types12.ProposalStatus.PENDING) continue;
6611
+ if (proposal.status !== import_types13.ProposalStatus.PENDING) continue;
5894
6612
  if (proposal.type === "payment" && proposal.payment) {
5895
6613
  if (proposal.payment.token.symbol === token.symbol && proposal.payment.token.chain === token.chain) {
5896
6614
  committed += proposal.payment.amount;
@@ -6133,7 +6851,7 @@ function validateBatchProposalParams(params, config) {
6133
6851
  }
6134
6852
 
6135
6853
  // src/compliance/compliance-manager.ts
6136
- var import_types13 = require("@sip-protocol/types");
6854
+ var import_types14 = require("@sip-protocol/types");
6137
6855
  var import_utils13 = require("@noble/hashes/utils");
6138
6856
  var DEFAULTS2 = {
6139
6857
  riskThreshold: 70,
@@ -6501,7 +7219,7 @@ var ComplianceManager = class _ComplianceManager {
6501
7219
  title: params.title,
6502
7220
  description: params.description,
6503
7221
  format: params.format,
6504
- status: import_types13.ReportStatus.GENERATING,
7222
+ status: import_types14.ReportStatus.GENERATING,
6505
7223
  requestedBy,
6506
7224
  requestedAt: now,
6507
7225
  startDate: params.startDate,
@@ -6530,10 +7248,10 @@ var ComplianceManager = class _ComplianceManager {
6530
7248
  } else if (params.format === "csv") {
6531
7249
  report.content = this.generateCSV(transactions);
6532
7250
  }
6533
- report.status = import_types13.ReportStatus.COMPLETED;
7251
+ report.status = import_types14.ReportStatus.COMPLETED;
6534
7252
  report.generatedAt = Math.floor(Date.now() / 1e3);
6535
7253
  } catch (error) {
6536
- report.status = import_types13.ReportStatus.FAILED;
7254
+ report.status = import_types14.ReportStatus.FAILED;
6537
7255
  report.error = error instanceof Error ? error.message : "Unknown error";
6538
7256
  }
6539
7257
  this.addAuditLog(requestedBy, "report_generated", {
@@ -6896,10 +7614,10 @@ function validateReportParams(params) {
6896
7614
  }
6897
7615
 
6898
7616
  // src/wallet/errors.ts
6899
- var import_types14 = require("@sip-protocol/types");
7617
+ var import_types15 = require("@sip-protocol/types");
6900
7618
  var WalletError = class extends SIPError {
6901
7619
  walletCode;
6902
- constructor(message, walletCode = import_types14.WalletErrorCode.UNKNOWN, options) {
7620
+ constructor(message, walletCode = import_types15.WalletErrorCode.UNKNOWN, options) {
6903
7621
  super(message, "SIP_7000" /* WALLET_ERROR */, options);
6904
7622
  this.walletCode = walletCode;
6905
7623
  this.name = "WalletError";
@@ -6909,10 +7627,10 @@ var WalletError = class extends SIPError {
6909
7627
  */
6910
7628
  isConnectionError() {
6911
7629
  const codes = [
6912
- import_types14.WalletErrorCode.NOT_INSTALLED,
6913
- import_types14.WalletErrorCode.CONNECTION_REJECTED,
6914
- import_types14.WalletErrorCode.CONNECTION_FAILED,
6915
- import_types14.WalletErrorCode.NOT_CONNECTED
7630
+ import_types15.WalletErrorCode.NOT_INSTALLED,
7631
+ import_types15.WalletErrorCode.CONNECTION_REJECTED,
7632
+ import_types15.WalletErrorCode.CONNECTION_FAILED,
7633
+ import_types15.WalletErrorCode.NOT_CONNECTED
6916
7634
  ];
6917
7635
  return codes.includes(this.walletCode);
6918
7636
  }
@@ -6921,9 +7639,9 @@ var WalletError = class extends SIPError {
6921
7639
  */
6922
7640
  isSigningError() {
6923
7641
  const codes = [
6924
- import_types14.WalletErrorCode.SIGNING_REJECTED,
6925
- import_types14.WalletErrorCode.SIGNING_FAILED,
6926
- import_types14.WalletErrorCode.INVALID_MESSAGE
7642
+ import_types15.WalletErrorCode.SIGNING_REJECTED,
7643
+ import_types15.WalletErrorCode.SIGNING_FAILED,
7644
+ import_types15.WalletErrorCode.INVALID_MESSAGE
6927
7645
  ];
6928
7646
  return codes.includes(this.walletCode);
6929
7647
  }
@@ -6932,10 +7650,10 @@ var WalletError = class extends SIPError {
6932
7650
  */
6933
7651
  isTransactionError() {
6934
7652
  const codes = [
6935
- import_types14.WalletErrorCode.INSUFFICIENT_FUNDS,
6936
- import_types14.WalletErrorCode.TRANSACTION_REJECTED,
6937
- import_types14.WalletErrorCode.TRANSACTION_FAILED,
6938
- import_types14.WalletErrorCode.INVALID_TRANSACTION
7653
+ import_types15.WalletErrorCode.INSUFFICIENT_FUNDS,
7654
+ import_types15.WalletErrorCode.TRANSACTION_REJECTED,
7655
+ import_types15.WalletErrorCode.TRANSACTION_FAILED,
7656
+ import_types15.WalletErrorCode.INVALID_TRANSACTION
6939
7657
  ];
6940
7658
  return codes.includes(this.walletCode);
6941
7659
  }
@@ -6944,9 +7662,9 @@ var WalletError = class extends SIPError {
6944
7662
  */
6945
7663
  isPrivacyError() {
6946
7664
  const codes = [
6947
- import_types14.WalletErrorCode.STEALTH_NOT_SUPPORTED,
6948
- import_types14.WalletErrorCode.VIEWING_KEY_NOT_SUPPORTED,
6949
- import_types14.WalletErrorCode.SHIELDED_NOT_SUPPORTED
7665
+ import_types15.WalletErrorCode.STEALTH_NOT_SUPPORTED,
7666
+ import_types15.WalletErrorCode.VIEWING_KEY_NOT_SUPPORTED,
7667
+ import_types15.WalletErrorCode.SHIELDED_NOT_SUPPORTED
6950
7668
  ];
6951
7669
  return codes.includes(this.walletCode);
6952
7670
  }
@@ -6955,10 +7673,10 @@ var WalletError = class extends SIPError {
6955
7673
  */
6956
7674
  isUserRejection() {
6957
7675
  const codes = [
6958
- import_types14.WalletErrorCode.CONNECTION_REJECTED,
6959
- import_types14.WalletErrorCode.SIGNING_REJECTED,
6960
- import_types14.WalletErrorCode.TRANSACTION_REJECTED,
6961
- import_types14.WalletErrorCode.CHAIN_SWITCH_REJECTED
7676
+ import_types15.WalletErrorCode.CONNECTION_REJECTED,
7677
+ import_types15.WalletErrorCode.SIGNING_REJECTED,
7678
+ import_types15.WalletErrorCode.TRANSACTION_REJECTED,
7679
+ import_types15.WalletErrorCode.CHAIN_SWITCH_REJECTED
6962
7680
  ];
6963
7681
  return codes.includes(this.walletCode);
6964
7682
  }
@@ -6966,15 +7684,15 @@ var WalletError = class extends SIPError {
6966
7684
  function notConnectedError() {
6967
7685
  return new WalletError(
6968
7686
  "Wallet not connected. Call connect() first.",
6969
- import_types14.WalletErrorCode.NOT_CONNECTED
7687
+ import_types15.WalletErrorCode.NOT_CONNECTED
6970
7688
  );
6971
7689
  }
6972
- function featureNotSupportedError(feature, code = import_types14.WalletErrorCode.UNKNOWN) {
7690
+ function featureNotSupportedError(feature, code = import_types15.WalletErrorCode.UNKNOWN) {
6973
7691
  return new WalletError(`${feature} is not supported by this wallet`, code);
6974
7692
  }
6975
7693
 
6976
7694
  // src/wallet/base-adapter.ts
6977
- var import_types15 = require("@sip-protocol/types");
7695
+ var import_types16 = require("@sip-protocol/types");
6978
7696
  var BaseWalletAdapter = class {
6979
7697
  _address = "";
6980
7698
  _publicKey = "";
@@ -7137,12 +7855,12 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
7137
7855
  this._connectionState = "connecting";
7138
7856
  if (this.shouldFailConnect) {
7139
7857
  this.setError(
7140
- import_types15.WalletErrorCode.CONNECTION_FAILED,
7858
+ import_types16.WalletErrorCode.CONNECTION_FAILED,
7141
7859
  "Mock connection failure"
7142
7860
  );
7143
7861
  throw new WalletError(
7144
7862
  "Mock connection failure",
7145
- import_types15.WalletErrorCode.CONNECTION_FAILED
7863
+ import_types16.WalletErrorCode.CONNECTION_FAILED
7146
7864
  );
7147
7865
  }
7148
7866
  await new Promise((resolve) => setTimeout(resolve, 10));
@@ -7154,7 +7872,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
7154
7872
  async signMessage(message) {
7155
7873
  this.requireConnected();
7156
7874
  if (this.shouldFailSign) {
7157
- throw new WalletError("Mock signing failure", import_types15.WalletErrorCode.SIGNING_FAILED);
7875
+ throw new WalletError("Mock signing failure", import_types16.WalletErrorCode.SIGNING_FAILED);
7158
7876
  }
7159
7877
  const mockSig = new Uint8Array(64);
7160
7878
  for (let i = 0; i < 64; i++) {
@@ -7169,7 +7887,7 @@ var MockWalletAdapter = class extends BaseWalletAdapter {
7169
7887
  async signTransaction(tx) {
7170
7888
  this.requireConnected();
7171
7889
  if (this.shouldFailSign) {
7172
- throw new WalletError("Mock signing failure", import_types15.WalletErrorCode.SIGNING_FAILED);
7890
+ throw new WalletError("Mock signing failure", import_types16.WalletErrorCode.SIGNING_FAILED);
7173
7891
  }
7174
7892
  const signature = await this.signMessage(
7175
7893
  new TextEncoder().encode(JSON.stringify(tx.data))
@@ -7351,7 +8069,7 @@ function isPrivateWalletAdapter(adapter) {
7351
8069
  }
7352
8070
 
7353
8071
  // src/wallet/solana/adapter.ts
7354
- var import_types16 = require("@sip-protocol/types");
8072
+ var import_types17 = require("@sip-protocol/types");
7355
8073
 
7356
8074
  // src/wallet/solana/types.ts
7357
8075
  function getSolanaProvider(wallet = "phantom") {
@@ -7472,19 +8190,19 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7472
8190
  }
7473
8191
  if (!this.provider) {
7474
8192
  this.setError(
7475
- import_types16.WalletErrorCode.NOT_INSTALLED,
8193
+ import_types17.WalletErrorCode.NOT_INSTALLED,
7476
8194
  `${this.walletName} wallet is not installed`
7477
8195
  );
7478
8196
  throw new WalletError(
7479
8197
  `${this.walletName} wallet is not installed`,
7480
- import_types16.WalletErrorCode.NOT_INSTALLED
8198
+ import_types17.WalletErrorCode.NOT_INSTALLED
7481
8199
  );
7482
8200
  }
7483
8201
  const { publicKey } = await this.provider.connect();
7484
8202
  if (!publicKey) {
7485
8203
  throw new WalletError(
7486
8204
  "No public key returned from wallet",
7487
- import_types16.WalletErrorCode.CONNECTION_FAILED
8205
+ import_types17.WalletErrorCode.CONNECTION_FAILED
7488
8206
  );
7489
8207
  }
7490
8208
  this.setupEventHandlers();
@@ -7494,11 +8212,11 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7494
8212
  } catch (error) {
7495
8213
  const message = error instanceof Error ? error.message : "Connection failed";
7496
8214
  if (message.includes("User rejected") || message.includes("rejected")) {
7497
- this.setError(import_types16.WalletErrorCode.CONNECTION_REJECTED, message);
7498
- throw new WalletError(message, import_types16.WalletErrorCode.CONNECTION_REJECTED);
8215
+ this.setError(import_types17.WalletErrorCode.CONNECTION_REJECTED, message);
8216
+ throw new WalletError(message, import_types17.WalletErrorCode.CONNECTION_REJECTED);
7499
8217
  }
7500
- this.setError(import_types16.WalletErrorCode.CONNECTION_FAILED, message);
7501
- throw error instanceof WalletError ? error : new WalletError(message, import_types16.WalletErrorCode.CONNECTION_FAILED, { cause: error });
8218
+ this.setError(import_types17.WalletErrorCode.CONNECTION_FAILED, message);
8219
+ throw error instanceof WalletError ? error : new WalletError(message, import_types17.WalletErrorCode.CONNECTION_FAILED, { cause: error });
7502
8220
  }
7503
8221
  }
7504
8222
  /**
@@ -7521,7 +8239,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7521
8239
  async signMessage(message) {
7522
8240
  this.requireConnected();
7523
8241
  if (!this.provider) {
7524
- throw new WalletError("Provider not available", import_types16.WalletErrorCode.NOT_CONNECTED);
8242
+ throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
7525
8243
  }
7526
8244
  try {
7527
8245
  const { signature } = await this.provider.signMessage(message);
@@ -7532,9 +8250,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7532
8250
  } catch (error) {
7533
8251
  const message2 = error instanceof Error ? error.message : "Signing failed";
7534
8252
  if (message2.includes("User rejected") || message2.includes("rejected")) {
7535
- throw new WalletError(message2, import_types16.WalletErrorCode.SIGNING_REJECTED);
8253
+ throw new WalletError(message2, import_types17.WalletErrorCode.SIGNING_REJECTED);
7536
8254
  }
7537
- throw new WalletError(message2, import_types16.WalletErrorCode.SIGNING_FAILED, {
8255
+ throw new WalletError(message2, import_types17.WalletErrorCode.SIGNING_FAILED, {
7538
8256
  cause: error
7539
8257
  });
7540
8258
  }
@@ -7547,7 +8265,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7547
8265
  async signTransaction(tx) {
7548
8266
  this.requireConnected();
7549
8267
  if (!this.provider) {
7550
- throw new WalletError("Provider not available", import_types16.WalletErrorCode.NOT_CONNECTED);
8268
+ throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
7551
8269
  }
7552
8270
  try {
7553
8271
  const solTx = tx.data;
@@ -7566,9 +8284,9 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7566
8284
  } catch (error) {
7567
8285
  const message = error instanceof Error ? error.message : "Signing failed";
7568
8286
  if (message.includes("User rejected") || message.includes("rejected")) {
7569
- throw new WalletError(message, import_types16.WalletErrorCode.SIGNING_REJECTED);
8287
+ throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_REJECTED);
7570
8288
  }
7571
- throw new WalletError(message, import_types16.WalletErrorCode.SIGNING_FAILED, {
8289
+ throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_FAILED, {
7572
8290
  cause: error
7573
8291
  });
7574
8292
  }
@@ -7579,7 +8297,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7579
8297
  async signAndSendTransaction(tx) {
7580
8298
  this.requireConnected();
7581
8299
  if (!this.provider) {
7582
- throw new WalletError("Provider not available", import_types16.WalletErrorCode.NOT_CONNECTED);
8300
+ throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
7583
8301
  }
7584
8302
  try {
7585
8303
  const solTx = tx.data;
@@ -7594,12 +8312,12 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7594
8312
  } catch (error) {
7595
8313
  const message = error instanceof Error ? error.message : "Transaction failed";
7596
8314
  if (message.includes("User rejected") || message.includes("rejected")) {
7597
- throw new WalletError(message, import_types16.WalletErrorCode.TRANSACTION_REJECTED);
8315
+ throw new WalletError(message, import_types17.WalletErrorCode.TRANSACTION_REJECTED);
7598
8316
  }
7599
8317
  if (message.includes("insufficient") || message.includes("Insufficient")) {
7600
- throw new WalletError(message, import_types16.WalletErrorCode.INSUFFICIENT_FUNDS);
8318
+ throw new WalletError(message, import_types17.WalletErrorCode.INSUFFICIENT_FUNDS);
7601
8319
  }
7602
- throw new WalletError(message, import_types16.WalletErrorCode.TRANSACTION_FAILED, {
8320
+ throw new WalletError(message, import_types17.WalletErrorCode.TRANSACTION_FAILED, {
7603
8321
  cause: error
7604
8322
  });
7605
8323
  }
@@ -7612,16 +8330,16 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7612
8330
  async signAllTransactions(transactions) {
7613
8331
  this.requireConnected();
7614
8332
  if (!this.provider) {
7615
- throw new WalletError("Provider not available", import_types16.WalletErrorCode.NOT_CONNECTED);
8333
+ throw new WalletError("Provider not available", import_types17.WalletErrorCode.NOT_CONNECTED);
7616
8334
  }
7617
8335
  try {
7618
8336
  return await this.provider.signAllTransactions(transactions);
7619
8337
  } catch (error) {
7620
8338
  const message = error instanceof Error ? error.message : "Signing failed";
7621
8339
  if (message.includes("User rejected") || message.includes("rejected")) {
7622
- throw new WalletError(message, import_types16.WalletErrorCode.SIGNING_REJECTED);
8340
+ throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_REJECTED);
7623
8341
  }
7624
- throw new WalletError(message, import_types16.WalletErrorCode.SIGNING_FAILED, {
8342
+ throw new WalletError(message, import_types17.WalletErrorCode.SIGNING_FAILED, {
7625
8343
  cause: error
7626
8344
  });
7627
8345
  }
@@ -7642,7 +8360,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7642
8360
  } catch (error) {
7643
8361
  throw new WalletError(
7644
8362
  "Failed to get balance",
7645
- import_types16.WalletErrorCode.UNKNOWN,
8363
+ import_types17.WalletErrorCode.UNKNOWN,
7646
8364
  { cause: error }
7647
8365
  );
7648
8366
  }
@@ -7655,7 +8373,7 @@ var SolanaWalletAdapter = class extends BaseWalletAdapter {
7655
8373
  if (asset.chain !== "solana") {
7656
8374
  throw new WalletError(
7657
8375
  `Asset chain ${asset.chain} not supported by Solana adapter`,
7658
- import_types16.WalletErrorCode.UNSUPPORTED_CHAIN
8376
+ import_types17.WalletErrorCode.UNSUPPORTED_CHAIN
7659
8377
  );
7660
8378
  }
7661
8379
  if (!asset.address) {
@@ -7773,7 +8491,7 @@ function createSolanaAdapter(config = {}) {
7773
8491
  }
7774
8492
 
7775
8493
  // src/wallet/solana/mock.ts
7776
- var import_types18 = require("@sip-protocol/types");
8494
+ var import_types19 = require("@sip-protocol/types");
7777
8495
  var MockPublicKey = class {
7778
8496
  base58;
7779
8497
  bytes;
@@ -7839,8 +8557,8 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7839
8557
  this._connectionState = "connecting";
7840
8558
  await this.simulateLatency();
7841
8559
  if (this.shouldFailConnect) {
7842
- this.setError(import_types18.WalletErrorCode.CONNECTION_FAILED, "Mock connection failure");
7843
- throw new WalletError("Mock connection failure", import_types18.WalletErrorCode.CONNECTION_FAILED);
8560
+ this.setError(import_types19.WalletErrorCode.CONNECTION_FAILED, "Mock connection failure");
8561
+ throw new WalletError("Mock connection failure", import_types19.WalletErrorCode.CONNECTION_FAILED);
7844
8562
  }
7845
8563
  const hexPubKey = "0x" + Buffer.from(this.mockPublicKey.toBytes()).toString("hex");
7846
8564
  this.setConnected(this.mockAddress, hexPubKey);
@@ -7859,7 +8577,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7859
8577
  this.requireConnected();
7860
8578
  await this.simulateLatency();
7861
8579
  if (this.shouldFailSign) {
7862
- throw new WalletError("Mock signing failure", import_types18.WalletErrorCode.SIGNING_REJECTED);
8580
+ throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
7863
8581
  }
7864
8582
  const mockSig = new Uint8Array(64);
7865
8583
  for (let i = 0; i < 64; i++) {
@@ -7877,7 +8595,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7877
8595
  this.requireConnected();
7878
8596
  await this.simulateLatency();
7879
8597
  if (this.shouldFailSign) {
7880
- throw new WalletError("Mock signing failure", import_types18.WalletErrorCode.SIGNING_REJECTED);
8598
+ throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
7881
8599
  }
7882
8600
  const solTx = tx.data;
7883
8601
  this.signedTransactions.push(solTx);
@@ -7897,10 +8615,10 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7897
8615
  this.requireConnected();
7898
8616
  await this.simulateLatency();
7899
8617
  if (this.shouldFailSign) {
7900
- throw new WalletError("Mock signing failure", import_types18.WalletErrorCode.SIGNING_REJECTED);
8618
+ throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
7901
8619
  }
7902
8620
  if (this.shouldFailTransaction) {
7903
- throw new WalletError("Mock transaction failure", import_types18.WalletErrorCode.TRANSACTION_FAILED);
8621
+ throw new WalletError("Mock transaction failure", import_types19.WalletErrorCode.TRANSACTION_FAILED);
7904
8622
  }
7905
8623
  const txSig = `mock_tx_${Date.now()}_${Math.random().toString(36).slice(2)}`;
7906
8624
  this.sentTransactions.push(txSig);
@@ -7920,7 +8638,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7920
8638
  this.requireConnected();
7921
8639
  await this.simulateLatency();
7922
8640
  if (this.shouldFailSign) {
7923
- throw new WalletError("Mock signing failure", import_types18.WalletErrorCode.SIGNING_REJECTED);
8641
+ throw new WalletError("Mock signing failure", import_types19.WalletErrorCode.SIGNING_REJECTED);
7924
8642
  }
7925
8643
  this.signedTransactions.push(...transactions);
7926
8644
  return transactions.map((tx) => {
@@ -7947,7 +8665,7 @@ var MockSolanaAdapter = class extends BaseWalletAdapter {
7947
8665
  if (asset.chain !== "solana") {
7948
8666
  throw new WalletError(
7949
8667
  `Asset chain ${asset.chain} not supported by Solana adapter`,
7950
- import_types18.WalletErrorCode.UNSUPPORTED_CHAIN
8668
+ import_types19.WalletErrorCode.UNSUPPORTED_CHAIN
7951
8669
  );
7952
8670
  }
7953
8671
  if (!asset.address) {
@@ -8116,7 +8834,7 @@ function createMockSolanaAdapter(config = {}) {
8116
8834
  }
8117
8835
 
8118
8836
  // src/wallet/ethereum/adapter.ts
8119
- var import_types20 = require("@sip-protocol/types");
8837
+ var import_types21 = require("@sip-protocol/types");
8120
8838
 
8121
8839
  // src/wallet/ethereum/types.ts
8122
8840
  var EthereumChainId = {
@@ -8258,7 +8976,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8258
8976
  this._connectionState = "error";
8259
8977
  throw new WalletError(
8260
8978
  `${this.walletType} wallet not found. Please install the extension.`,
8261
- import_types20.WalletErrorCode.NOT_INSTALLED
8979
+ import_types21.WalletErrorCode.NOT_INSTALLED
8262
8980
  );
8263
8981
  }
8264
8982
  const accounts = await this.provider.request({
@@ -8268,7 +8986,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8268
8986
  this._connectionState = "error";
8269
8987
  throw new WalletError(
8270
8988
  "No accounts returned from wallet",
8271
- import_types20.WalletErrorCode.CONNECTION_REJECTED
8989
+ import_types21.WalletErrorCode.CONNECTION_REJECTED
8272
8990
  );
8273
8991
  }
8274
8992
  const address = normalizeAddress(accounts[0]);
@@ -8288,12 +9006,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8288
9006
  if (rpcError.code === 4001) {
8289
9007
  throw new WalletError(
8290
9008
  "User rejected connection request",
8291
- import_types20.WalletErrorCode.CONNECTION_REJECTED
9009
+ import_types21.WalletErrorCode.CONNECTION_REJECTED
8292
9010
  );
8293
9011
  }
8294
9012
  throw new WalletError(
8295
9013
  `Failed to connect: ${rpcError.message || String(error)}`,
8296
- import_types20.WalletErrorCode.CONNECTION_FAILED
9014
+ import_types21.WalletErrorCode.CONNECTION_FAILED
8297
9015
  );
8298
9016
  }
8299
9017
  }
@@ -8313,7 +9031,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8313
9031
  if (!this.provider) {
8314
9032
  throw new WalletError(
8315
9033
  "Provider not available",
8316
- import_types20.WalletErrorCode.NOT_CONNECTED
9034
+ import_types21.WalletErrorCode.NOT_CONNECTED
8317
9035
  );
8318
9036
  }
8319
9037
  try {
@@ -8331,12 +9049,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8331
9049
  if (rpcError.code === 4001) {
8332
9050
  throw new WalletError(
8333
9051
  "User rejected signing request",
8334
- import_types20.WalletErrorCode.SIGNING_REJECTED
9052
+ import_types21.WalletErrorCode.SIGNING_REJECTED
8335
9053
  );
8336
9054
  }
8337
9055
  throw new WalletError(
8338
9056
  `Failed to sign message: ${rpcError.message || String(error)}`,
8339
- import_types20.WalletErrorCode.SIGNING_FAILED
9057
+ import_types21.WalletErrorCode.SIGNING_FAILED
8340
9058
  );
8341
9059
  }
8342
9060
  }
@@ -8348,7 +9066,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8348
9066
  if (!this.provider) {
8349
9067
  throw new WalletError(
8350
9068
  "Provider not available",
8351
- import_types20.WalletErrorCode.NOT_CONNECTED
9069
+ import_types21.WalletErrorCode.NOT_CONNECTED
8352
9070
  );
8353
9071
  }
8354
9072
  try {
@@ -8365,12 +9083,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8365
9083
  if (rpcError.code === 4001) {
8366
9084
  throw new WalletError(
8367
9085
  "User rejected signing request",
8368
- import_types20.WalletErrorCode.SIGNING_REJECTED
9086
+ import_types21.WalletErrorCode.SIGNING_REJECTED
8369
9087
  );
8370
9088
  }
8371
9089
  throw new WalletError(
8372
9090
  `Failed to sign typed data: ${rpcError.message || String(error)}`,
8373
- import_types20.WalletErrorCode.SIGNING_FAILED
9091
+ import_types21.WalletErrorCode.SIGNING_FAILED
8374
9092
  );
8375
9093
  }
8376
9094
  }
@@ -8382,7 +9100,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8382
9100
  if (!this.provider) {
8383
9101
  throw new WalletError(
8384
9102
  "Provider not available",
8385
- import_types20.WalletErrorCode.NOT_CONNECTED
9103
+ import_types21.WalletErrorCode.NOT_CONNECTED
8386
9104
  );
8387
9105
  }
8388
9106
  try {
@@ -8410,7 +9128,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8410
9128
  if (rpcError.code === 4001) {
8411
9129
  throw new WalletError(
8412
9130
  "User rejected transaction signing",
8413
- import_types20.WalletErrorCode.SIGNING_REJECTED
9131
+ import_types21.WalletErrorCode.SIGNING_REJECTED
8414
9132
  );
8415
9133
  }
8416
9134
  if (rpcError.code === -32601 || rpcError.message?.includes("not supported")) {
@@ -8428,7 +9146,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8428
9146
  }
8429
9147
  throw new WalletError(
8430
9148
  `Failed to sign transaction: ${rpcError.message || String(error)}`,
8431
- import_types20.WalletErrorCode.TRANSACTION_FAILED
9149
+ import_types21.WalletErrorCode.TRANSACTION_FAILED
8432
9150
  );
8433
9151
  }
8434
9152
  }
@@ -8440,7 +9158,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8440
9158
  if (!this.provider) {
8441
9159
  throw new WalletError(
8442
9160
  "Provider not available",
8443
- import_types20.WalletErrorCode.NOT_CONNECTED
9161
+ import_types21.WalletErrorCode.NOT_CONNECTED
8444
9162
  );
8445
9163
  }
8446
9164
  try {
@@ -8462,12 +9180,12 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8462
9180
  if (rpcError.code === 4001) {
8463
9181
  throw new WalletError(
8464
9182
  "User rejected transaction",
8465
- import_types20.WalletErrorCode.TRANSACTION_REJECTED
9183
+ import_types21.WalletErrorCode.TRANSACTION_REJECTED
8466
9184
  );
8467
9185
  }
8468
9186
  throw new WalletError(
8469
9187
  `Failed to send transaction: ${rpcError.message || String(error)}`,
8470
- import_types20.WalletErrorCode.TRANSACTION_FAILED
9188
+ import_types21.WalletErrorCode.TRANSACTION_FAILED
8471
9189
  );
8472
9190
  }
8473
9191
  }
@@ -8502,7 +9220,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8502
9220
  } catch (error) {
8503
9221
  throw new WalletError(
8504
9222
  `Failed to fetch balance: ${String(error)}`,
8505
- import_types20.WalletErrorCode.UNKNOWN
9223
+ import_types21.WalletErrorCode.UNKNOWN
8506
9224
  );
8507
9225
  }
8508
9226
  }
@@ -8514,7 +9232,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8514
9232
  if (asset.chain !== "ethereum") {
8515
9233
  throw new WalletError(
8516
9234
  `Asset chain ${asset.chain} not supported by Ethereum adapter`,
8517
- import_types20.WalletErrorCode.UNSUPPORTED_CHAIN
9235
+ import_types21.WalletErrorCode.UNSUPPORTED_CHAIN
8518
9236
  );
8519
9237
  }
8520
9238
  if (!asset.address) {
@@ -8539,7 +9257,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8539
9257
  } catch (error) {
8540
9258
  throw new WalletError(
8541
9259
  `Failed to fetch token balance: ${String(error)}`,
8542
- import_types20.WalletErrorCode.UNKNOWN
9260
+ import_types21.WalletErrorCode.UNKNOWN
8543
9261
  );
8544
9262
  }
8545
9263
  }
@@ -8551,7 +9269,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8551
9269
  if (!this.provider) {
8552
9270
  throw new WalletError(
8553
9271
  "Provider not available",
8554
- import_types20.WalletErrorCode.NOT_CONNECTED
9272
+ import_types21.WalletErrorCode.NOT_CONNECTED
8555
9273
  );
8556
9274
  }
8557
9275
  try {
@@ -8566,18 +9284,18 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8566
9284
  if (rpcError.code === 4001) {
8567
9285
  throw new WalletError(
8568
9286
  "User rejected chain switch",
8569
- import_types20.WalletErrorCode.CHAIN_SWITCH_REJECTED
9287
+ import_types21.WalletErrorCode.CHAIN_SWITCH_REJECTED
8570
9288
  );
8571
9289
  }
8572
9290
  if (rpcError.code === 4902) {
8573
9291
  throw new WalletError(
8574
9292
  `Chain ${chainId} not added to wallet`,
8575
- import_types20.WalletErrorCode.UNSUPPORTED_CHAIN
9293
+ import_types21.WalletErrorCode.UNSUPPORTED_CHAIN
8576
9294
  );
8577
9295
  }
8578
9296
  throw new WalletError(
8579
9297
  `Failed to switch chain: ${rpcError.message || String(error)}`,
8580
- import_types20.WalletErrorCode.CHAIN_SWITCH_FAILED
9298
+ import_types21.WalletErrorCode.CHAIN_SWITCH_FAILED
8581
9299
  );
8582
9300
  }
8583
9301
  }
@@ -8613,7 +9331,7 @@ var EthereumWalletAdapter = class extends BaseWalletAdapter {
8613
9331
  }
8614
9332
  throw new WalletError(
8615
9333
  `Transaction ${txHash} not confirmed after ${maxAttempts * 5} seconds`,
8616
- import_types20.WalletErrorCode.TRANSACTION_FAILED
9334
+ import_types21.WalletErrorCode.TRANSACTION_FAILED
8617
9335
  );
8618
9336
  }
8619
9337
  /**
@@ -8687,7 +9405,7 @@ function createEthereumAdapter(config) {
8687
9405
  }
8688
9406
 
8689
9407
  // src/wallet/ethereum/mock.ts
8690
- var import_types22 = require("@sip-protocol/types");
9408
+ var import_types23 = require("@sip-protocol/types");
8691
9409
  var MockEthereumAdapter = class extends BaseWalletAdapter {
8692
9410
  chain = "ethereum";
8693
9411
  name = "mock-ethereum";
@@ -8728,7 +9446,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8728
9446
  this._connectionState = "error";
8729
9447
  throw new WalletError(
8730
9448
  "Mock connection rejected",
8731
- import_types22.WalletErrorCode.CONNECTION_REJECTED
9449
+ import_types23.WalletErrorCode.CONNECTION_REJECTED
8732
9450
  );
8733
9451
  }
8734
9452
  await new Promise((resolve) => setTimeout(resolve, 10));
@@ -8740,7 +9458,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8740
9458
  this._connectionState = "error";
8741
9459
  throw new WalletError(
8742
9460
  `Mock connection failed: ${String(error)}`,
8743
- import_types22.WalletErrorCode.CONNECTION_FAILED
9461
+ import_types23.WalletErrorCode.CONNECTION_FAILED
8744
9462
  );
8745
9463
  }
8746
9464
  }
@@ -8758,7 +9476,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8758
9476
  if (this._shouldFailSign) {
8759
9477
  throw new WalletError(
8760
9478
  "Mock signing rejected",
8761
- import_types22.WalletErrorCode.SIGNING_REJECTED
9479
+ import_types23.WalletErrorCode.SIGNING_REJECTED
8762
9480
  );
8763
9481
  }
8764
9482
  const msgHex = Buffer.from(message).toString("hex");
@@ -8776,7 +9494,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8776
9494
  if (this._shouldFailSign) {
8777
9495
  throw new WalletError(
8778
9496
  "Mock signing rejected",
8779
- import_types22.WalletErrorCode.SIGNING_REJECTED
9497
+ import_types23.WalletErrorCode.SIGNING_REJECTED
8780
9498
  );
8781
9499
  }
8782
9500
  const mockSig = `0x${"1".repeat(130)}`;
@@ -8793,7 +9511,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8793
9511
  if (this._shouldFailSign) {
8794
9512
  throw new WalletError(
8795
9513
  "Mock signing rejected",
8796
- import_types22.WalletErrorCode.SIGNING_REJECTED
9514
+ import_types23.WalletErrorCode.SIGNING_REJECTED
8797
9515
  );
8798
9516
  }
8799
9517
  this._signedTransactions.push(tx);
@@ -8818,7 +9536,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8818
9536
  if (this._shouldFailTransaction) {
8819
9537
  throw new WalletError(
8820
9538
  "Mock transaction failed",
8821
- import_types22.WalletErrorCode.TRANSACTION_FAILED
9539
+ import_types23.WalletErrorCode.TRANSACTION_FAILED
8822
9540
  );
8823
9541
  }
8824
9542
  this._signedTransactions.push(tx);
@@ -8848,7 +9566,7 @@ var MockEthereumAdapter = class extends BaseWalletAdapter {
8848
9566
  if (asset.chain !== "ethereum") {
8849
9567
  throw new WalletError(
8850
9568
  `Asset chain ${asset.chain} not supported by Ethereum adapter`,
8851
- import_types22.WalletErrorCode.UNSUPPORTED_CHAIN
9569
+ import_types23.WalletErrorCode.UNSUPPORTED_CHAIN
8852
9570
  );
8853
9571
  }
8854
9572
  if (!asset.address) {
@@ -9127,7 +9845,7 @@ function getAvailableTransports() {
9127
9845
  }
9128
9846
 
9129
9847
  // src/wallet/hardware/ledger.ts
9130
- var import_types25 = require("@sip-protocol/types");
9848
+ var import_types26 = require("@sip-protocol/types");
9131
9849
  var LedgerWalletAdapter = class extends BaseWalletAdapter {
9132
9850
  chain;
9133
9851
  name = "ledger";
@@ -9280,7 +9998,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
9280
9998
  async getBalance() {
9281
9999
  throw new WalletError(
9282
10000
  "Hardware wallets do not track balances. Use an RPC provider.",
9283
- import_types25.WalletErrorCode.UNSUPPORTED_OPERATION
10001
+ import_types26.WalletErrorCode.UNSUPPORTED_OPERATION
9284
10002
  );
9285
10003
  }
9286
10004
  /**
@@ -9291,7 +10009,7 @@ var LedgerWalletAdapter = class extends BaseWalletAdapter {
9291
10009
  async getTokenBalance(_asset) {
9292
10010
  throw new WalletError(
9293
10011
  "Hardware wallets do not track balances. Use an RPC provider.",
9294
- import_types25.WalletErrorCode.UNSUPPORTED_OPERATION
10012
+ import_types26.WalletErrorCode.UNSUPPORTED_OPERATION
9295
10013
  );
9296
10014
  }
9297
10015
  // ─── Account Management ─────────────────────────────────────────────────────
@@ -9579,7 +10297,7 @@ function createLedgerAdapter(config) {
9579
10297
  }
9580
10298
 
9581
10299
  // src/wallet/hardware/trezor.ts
9582
- var import_types27 = require("@sip-protocol/types");
10300
+ var import_types28 = require("@sip-protocol/types");
9583
10301
  var TrezorWalletAdapter = class extends BaseWalletAdapter {
9584
10302
  chain;
9585
10303
  name = "trezor";
@@ -9725,7 +10443,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
9725
10443
  async getBalance() {
9726
10444
  throw new WalletError(
9727
10445
  "Hardware wallets do not track balances. Use an RPC provider.",
9728
- import_types27.WalletErrorCode.UNSUPPORTED_OPERATION
10446
+ import_types28.WalletErrorCode.UNSUPPORTED_OPERATION
9729
10447
  );
9730
10448
  }
9731
10449
  /**
@@ -9736,7 +10454,7 @@ var TrezorWalletAdapter = class extends BaseWalletAdapter {
9736
10454
  async getTokenBalance(_asset) {
9737
10455
  throw new WalletError(
9738
10456
  "Hardware wallets do not track balances. Use an RPC provider.",
9739
- import_types27.WalletErrorCode.UNSUPPORTED_OPERATION
10457
+ import_types28.WalletErrorCode.UNSUPPORTED_OPERATION
9740
10458
  );
9741
10459
  }
9742
10460
  // ─── Account Management ─────────────────────────────────────────────────────
@@ -10017,7 +10735,7 @@ function createTrezorAdapter(config) {
10017
10735
  }
10018
10736
 
10019
10737
  // src/wallet/hardware/mock.ts
10020
- var import_types29 = require("@sip-protocol/types");
10738
+ var import_types30 = require("@sip-protocol/types");
10021
10739
  var import_utils14 = require("@noble/hashes/utils");
10022
10740
  var MockLedgerAdapter = class extends BaseWalletAdapter {
10023
10741
  chain;
@@ -10165,7 +10883,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
10165
10883
  async getBalance() {
10166
10884
  throw new WalletError(
10167
10885
  "Hardware wallets do not track balances",
10168
- import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
10886
+ import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
10169
10887
  );
10170
10888
  }
10171
10889
  /**
@@ -10174,7 +10892,7 @@ var MockLedgerAdapter = class extends BaseWalletAdapter {
10174
10892
  async getTokenBalance(_asset) {
10175
10893
  throw new WalletError(
10176
10894
  "Hardware wallets do not track balances",
10177
- import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
10895
+ import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
10178
10896
  );
10179
10897
  }
10180
10898
  /**
@@ -10404,13 +11122,13 @@ var MockTrezorAdapter = class extends BaseWalletAdapter {
10404
11122
  async getBalance() {
10405
11123
  throw new WalletError(
10406
11124
  "Hardware wallets do not track balances",
10407
- import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
11125
+ import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
10408
11126
  );
10409
11127
  }
10410
11128
  async getTokenBalance(_asset) {
10411
11129
  throw new WalletError(
10412
11130
  "Hardware wallets do not track balances",
10413
- import_types29.WalletErrorCode.UNSUPPORTED_OPERATION
11131
+ import_types30.WalletErrorCode.UNSUPPORTED_OPERATION
10414
11132
  );
10415
11133
  }
10416
11134
  async getAccounts(startIndex = 0, count = 5) {
@@ -10500,7 +11218,7 @@ function createMockTrezorAdapter(config) {
10500
11218
  }
10501
11219
 
10502
11220
  // src/wallet/index.ts
10503
- var import_types32 = require("@sip-protocol/types");
11221
+ var import_types33 = require("@sip-protocol/types");
10504
11222
 
10505
11223
  // src/proofs/browser.ts
10506
11224
  var import_noir_js = require("@noir-lang/noir_js");
@@ -10508,7 +11226,7 @@ var import_bb = require("@aztec/bb.js");
10508
11226
  var import_secp256k14 = require("@noble/curves/secp256k1");
10509
11227
 
10510
11228
  // src/proofs/circuits/funding_proof.json
10511
- var funding_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "13977419962319221401", abi: { parameters: [{ name: "commitment_hash", type: { kind: "field" }, visibility: "public" }, { name: "minimum_required", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "asset_id", type: { kind: "field" }, visibility: "public" }, { name: "balance", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "blinding", type: { kind: "field" }, visibility: "private" }], return_type: null, error_types: { "2900908756532713827": { error_kind: "string", string: "Insufficient balance" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" }, "17719928407928969950": { error_kind: "string", string: "Commitment hash mismatch" } } }, bytecode: "H4sIAAAAAAAA/+VYbUhTURg+d7vTTdfmnJlK1g360LJolUEUJaUZ/qgooS9Taq5aoCudlhHV6LuglPplBH0gLUuiCCv6osA+LImItCQ0wUyRTJSJWkG7ds58PV53PzT60Qt3z+65z/ue533u8exeGfQnWIxZm+zZ4V4043PGe6gx8kcCNabGYyw+V6HBQcY4jDMzl+c0WC7E3l2ZVO5yrd0YM7t5WcG9HUVLGjxn2nEdDkkKRi3OZfxd5JC0XNiXBmMAYRAz+IEEqgJLTfS3mh+ibiGuy2hkaAhAykxlZPYKNYn1yvqZmJ5XrJaEReMLeOMDMWppknoYAsRMChyam0ZxGa10DWgkDWWRMkN1GINoklxDoQAxQ3VIuqFB0jX0mcbfgAAwxmHULiwwfYjX5ce2B+RZfo6u/FXgPtf2al7hIvuaOKsjZT3kRu1P7y3bb0mbdDWiU/+iZvai19f21Lw0htW5HlTE9JzZCLlSgnA1Ke7tua9OzFmVvuFRdeP8i5Gnjhgz5q2cfHpnfVLRw0YV5HLn3zyO+7Gmp4t1JNZEPevtzkm98TxhL9u6OWrz0conkyFXLOBCC0T9PvGowxhEaRUJJtj7ofceo9DILuRgpGwhGzAaaZLchQwFiC1kA5K+kI1I2Q0bJBDJ60ePlBkagtFEk+QaCgWIGRqCpBtqQv/GUBVSZmgoRjNNkmsoFCBmaCiSbqhZugbfFqIHYxzG/3mrhdyxiR0l3F7X0xMHJ5S40ppvWkIm3v9mjoi8X+u5VOZOXga56tK2uU2Lp0Y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W3BDbGrkPBWaKFBpct9So5JYivpxfWcRzCfYPAl5GPJVi2XBaHmsuWrAlCAE83hsCQJQh/pIMbP0qAtN5mjvfyNfLAyXfne93stpTN+5bE6SHFRPLKJdRLaP210/FqFkB2h/zsOzDAupW/CUF4HOAZoIglTkQwZbBVsHWwfatjw29jz/23+3YtcfeeU+8r/Nwio6ROf1c45PYVV3Hy8md59H5RWxaKxrfKKfQvt/9Qn8B", file_map: { "16": { source: "use crate::cmp::Eq;\nuse crate::hash::Hash;\nuse crate::ops::arith::{Add, Neg, Sub};\n\n/// A point on the embedded elliptic curve\n/// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field.\n/// x and y denotes the Weierstrass coordinates of the point, if is_infinite is false.\npub struct EmbeddedCurvePoint {\n pub x: Field,\n pub y: Field,\n pub is_infinite: bool,\n}\n\nimpl EmbeddedCurvePoint {\n /// Elliptic curve point doubling operation\n /// returns the doubled point of a point P, i.e P+P\n pub fn double(self) -> EmbeddedCurvePoint {\n embedded_curve_add(self, self)\n }\n\n /// Returns the null element of the curve; 'the point at infinity'\n pub fn point_at_infinity() -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }\n }\n\n /// Returns the curve's generator point.\n pub fn generator() -> EmbeddedCurvePoint {\n // Generator point for the grumpkin curve (y^2 = x^3 - 17)\n EmbeddedCurvePoint {\n x: 1,\n y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)\n is_infinite: false,\n }\n }\n}\n\nimpl Add for EmbeddedCurvePoint {\n /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity\n fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n embedded_curve_add(self, other)\n }\n}\n\nimpl Sub for EmbeddedCurvePoint {\n /// Points subtraction operation, using addition and negation\n fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n self + other.neg()\n }\n}\n\nimpl Neg for EmbeddedCurvePoint {\n /// Negates a point P, i.e returns -P, by negating the y coordinate.\n /// If the point is at infinity, then the result is also at infinity.\n fn neg(self) -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite }\n }\n}\n\nimpl Eq for EmbeddedCurvePoint {\n /// Checks whether two points are equal\n fn eq(self: Self, b: EmbeddedCurvePoint) -> bool {\n (self.is_infinite & b.is_infinite)\n | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y))\n }\n}\n\nimpl Hash for EmbeddedCurvePoint {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n if self.is_infinite {\n self.is_infinite.hash(state);\n } else {\n self.x.hash(state);\n self.y.hash(state);\n }\n }\n}\n\n/// Scalar for the embedded curve represented as low and high limbs\n/// By definition, the scalar field of the embedded curve is base field of the proving system curve.\n/// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs.\npub struct EmbeddedCurveScalar {\n pub lo: Field,\n pub hi: Field,\n}\n\nimpl EmbeddedCurveScalar {\n pub fn new(lo: Field, hi: Field) -> Self {\n EmbeddedCurveScalar { lo, hi }\n }\n\n #[field(bn254)]\n pub fn from_field(scalar: Field) -> EmbeddedCurveScalar {\n let (a, b) = crate::field::bn254::decompose(scalar);\n EmbeddedCurveScalar { lo: a, hi: b }\n }\n\n //Bytes to scalar: take the first (after the specified offset) 16 bytes of the input as the lo value, and the next 16 bytes as the hi value\n #[field(bn254)]\n pub(crate) fn from_bytes(bytes: [u8; 64], offset: u32) -> EmbeddedCurveScalar {\n let mut v = 1;\n let mut lo = 0 as Field;\n let mut hi = 0 as Field;\n for i in 0..16 {\n lo = lo + (bytes[offset + 31 - i] as Field) * v;\n hi = hi + (bytes[offset + 15 - i] as Field) * v;\n v = v * 256;\n }\n let sig_s = crate::embedded_curve_ops::EmbeddedCurveScalar { lo, hi };\n sig_s\n }\n}\n\nimpl Eq for EmbeddedCurveScalar {\n fn eq(self, other: Self) -> bool {\n (other.hi == self.hi) & (other.lo == self.lo)\n }\n}\n\nimpl Hash for EmbeddedCurveScalar {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n self.hi.hash(state);\n self.lo.hash(state);\n }\n}\n\n// Computes a multi scalar multiplication over the embedded curve.\n// For bn254, We have Grumpkin and Baby JubJub.\n// For bls12-381, we have JubJub and Bandersnatch.\n//\n// The embedded curve being used is decided by the\n// underlying proof system.\n// docs:start:multi_scalar_mul\npub fn multi_scalar_mul<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n// docs:end:multi_scalar_mul\n{\n multi_scalar_mul_array_return(points, scalars, true)[0]\n}\n\n#[foreign(multi_scalar_mul)]\npub(crate) fn multi_scalar_mul_array_return<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n// docs:start:fixed_base_scalar_mul\npub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n// docs:end:fixed_base_scalar_mul\n{\n multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])\n}\n\n/// This function only assumes that the points are on the curve\n/// It handles corner cases around the infinity point causing some overhead compared to embedded_curve_add_not_nul and embedded_curve_add_unsafe\n// docs:start:embedded_curve_add\npub fn embedded_curve_add(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n // docs:end:embedded_curve_add\n if crate::runtime::is_unconstrained() {\n // `embedded_curve_add_unsafe` requires the inputs not to be the infinity point, so we check it here.\n // This is because `embedded_curve_add_unsafe` uses the `embedded_curve_add` opcode.\n // For efficiency, the backend does not check the inputs for the infinity point, but it assumes that they are not the infinity point\n // so that it can apply the ec addition formula directly.\n if point1.is_infinite {\n point2\n } else if point2.is_infinite {\n point1\n } else {\n embedded_curve_add_unsafe(point1, point2)\n }\n } else {\n // In a constrained context, we also need to check the inputs are not the infinity point because we also use `embedded_curve_add_unsafe`\n // However we also need to identify the case where the two inputs are the same, because then\n // the addition formula does not work and we need to use the doubling formula instead.\n // In unconstrained context, we can check directly if the input values are the same when solving the opcode, so it is not an issue.\n\n // x_coordinates_match is true if both abscissae are the same\n let x_coordinates_match = point1.x == point2.x;\n // y_coordinates_match is true if both ordinates are the same\n let y_coordinates_match = point1.y == point2.y;\n // double_predicate is true if both abscissae and ordinates are the same\n let double_predicate = (x_coordinates_match & y_coordinates_match);\n // If the abscissae are the same, but not the ordinates, then one point is the opposite of the other\n let infinity_predicate = (x_coordinates_match & !y_coordinates_match);\n\n // `embedded_curve_add_unsafe` would not perform doubling, even if the inputs point1 and point2 are the same, because it cannot know this without adding some logic (and some constraints)\n // However we did this logic when we computed `double_predicate`, so we set the result to 2*point1 if point1 and point2 are the same\n let mut result = if double_predicate {\n // `embedded_curve_add_unsafe` is doing a doubling if the input is the same variable, because in this case it is guaranteed (at 'compile time') that the input is the same.\n embedded_curve_add_unsafe(point1, point1)\n } else {\n let point1_1 = EmbeddedCurvePoint {\n x: point1.x + (x_coordinates_match as Field),\n y: point1.y,\n is_infinite: false,\n };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n // point1_1 is guaranteed to have a different abscissa than point2:\n // - if x_coordinates_match is 0, that means point1.x != point2.x, and point1_1.x = point1.x + 0\n // - if x_coordinates_match is 1, that means point1.x = point2.x, but point1_1.x = point1.x + 1 in this case\n // Because the abscissa is different, the addition formula is guaranteed to succeed, so we can safely use `embedded_curve_add_unsafe`\n // Note that this computation may be garbage: if x_coordinates_match is 1, or if one of the input is the point at infinity.\n // therefore we only want to do this if we need the result, otherwise it needs to be eliminated as a dead instruction, lest we want the circuit to fail.\n embedded_curve_add_unsafe(point1_1, point2_1)\n };\n\n // Same logic as above for unconstrained context, we set the proper result when one of the inputs is the infinity point\n if point1.is_infinite {\n result = point2;\n }\n if point2.is_infinite {\n result = point1;\n }\n\n // Finally, we set the is_infinity flag of the result:\n // Opposite points should sum into the infinity point, however, if one of them is point at infinity, their coordinates are not meaningful\n // so we should not use the fact that the inputs are opposite in this case:\n let mut result_is_infinity =\n infinity_predicate & (!point1.is_infinite & !point2.is_infinite);\n // However, if both of them are at infinity, then the result is also at infinity\n result.is_infinite = result_is_infinity | (point1.is_infinite & point2.is_infinite);\n result\n }\n}\n\n#[foreign(embedded_curve_add)]\nfn embedded_curve_add_array_return(\n _point1: EmbeddedCurvePoint,\n _point2: EmbeddedCurvePoint,\n _predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n/// This function assumes that:\n/// The points are on the curve, and\n/// The points don't share an x-coordinate, and\n/// Neither point is the infinity point.\n/// If it is used with correct input, the function ensures the correct non-zero result is returned.\n/// Except for points on the curve, the other assumptions are checked by the function. It will cause assertion failure if they are not respected.\npub fn embedded_curve_add_not_nul(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n assert(point1.x != point2.x);\n assert(!point1.is_infinite);\n assert(!point2.is_infinite);\n // Ensure is_infinite is comptime\n let point1_1 = EmbeddedCurvePoint { x: point1.x, y: point1.y, is_infinite: false };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n embedded_curve_add_unsafe(point1_1, point2_1)\n}\n\n/// Unsafe ec addition\n/// If the inputs are the same, it will perform a doubling, but only if point1 and point2 are the same variable.\n/// If they have the same value but are different variables, the result will be incorrect because in this case\n/// it assumes (but does not check) that the points' x-coordinates are not equal.\n/// It also assumes neither point is the infinity point.\npub fn embedded_curve_add_unsafe(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n embedded_curve_add_array_return(point1, point2, true)[0]\n}\n", path: "std/embedded_curve_ops.nr" }, "17": { source: `use crate::field::field_less_than;
11229
+ var funding_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "3859649086066977477", abi: { parameters: [{ name: "minimum_required", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "asset_id", type: { kind: "field" }, visibility: "public" }, { name: "balance", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "private" }, { name: "blinding", type: { kind: "field" }, visibility: "private" }], return_type: { abi_type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "public" }, error_types: { "2900908756532713827": { error_kind: "string", string: "Insufficient balance" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" }, "15835548349546956319": { error_kind: "string", string: "Field failed to decompose into specified 32 limbs" } } }, bytecode: "H4sIAAAAAAAA/8VdB7wVxfU+cwEFRRGsGJU1KkWl997hAQqKDRVFQFQUePSq8pAO0hS72MAIdkAUImKLXRA0EdAY8R9LooklamL3v+Ob5e7dN/v2fLM7u/P7TYY398w938w335mPp0kElbaKahw5ePioN3NED1Yo/Vm4vYIaZesUmMupuYq+n4PNm3PU2OjivmM/aHxXvY2ndX98xowBF9Rt+o+iKZtGL+v6wbfXfxmIjWgiFx0ryvvQId5a/76OV+MJXoR3GHKiU+AbKgYS2dp8yPcuVd8rjgcwnEBmhyrAvfoxRe21YjmJg3mjvotxafY2P/G11VgnGFQhBoCoQ6odHjswECvq8DFQkgdagcwOtK4a6wWD0AP1A4g60LrEP9B6fAy/HVplt1fxzTlqrNxhSvVdzatMrPflPhMa/3Toqz9PWX3b56+1Xtpx+DknDy3ufZ4/9sjpF/7w0PTGA09Yc8TXVV/e2bTj6w9M3flKtUP+NmPzC3W/v/4CfyynebGVeq++fNxrC5r1v/D8LW9/2PbumovnVBvU+rTaS8a8333ZUx/m/LHOijeePvnHc77/b8XibjuPfPGH78ae+chLna6s+NmQI4fMffXZ2v5YBEP97zZ1+mj+gX0PnrTnjHE/fHzr0RP6DW/+8X0lj1+yfHzj/2zd6o9tsHXejnMv3XzGxtnLGhxw2JzBZz74+P3PvfXdhXVevfqLdc8unemPjWr7qFFyVFuNddRYV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MBgYDAwGBgODgcFIysWeMRgYDAxGUS7KGAwMBgYDg4HBwGBgMHgfDN4HA4OBwcBg8D4YvA8mBhODicHEYGIwMZgYzKXLuRRDbyMxmBhMoSyUMZgYTAwmBhODicHEYCplVQZjcIbBQFkpYzAxmBhMDCYGE4OJwTTKFgxsA4OJwXTKThmDicHEYGIwMZgYTAymUx7sGYOJwcRgDsqDMgYTg4nBxGBiMDGYGMygHOwZg4nBxGAG5aCMwcRgYjAxmBhMDCYGMykne8ZgYjAxmEW5KGMwMZgYTAwmBhODicGclCd7xmBiMDGY3Ism96KJwcRgYbAwWBgsDBYGa+lyLcGQDMXQ2yjuRUsoY7AwWBgsDBYGC4OFwRLKujAIgzIYA2WljMHCYGGwMFgYLAwWBssomzOwDQwWBot70TLKGCwMFgYLg4XBwmBhsJyys2cMFgYLg8W9aA3KGCwMFgYLg4XBwmBhsIJysGcMFgYLg8W9aAVlDBYGC4OFwcJgYbAwWEk52TMGC4OFweJetIoyBguDhcHCYGGwMFgYrKI82TMGC4OFweJetDBYvA8W74OFweJedC4LgzD0mScGJwYn74Pz2aBvw1be/gnRz5uH25uPd/sf60/et5/NP91/4gfx6y8f//vO7/AvO78/fPu0//z0sN9+aP/in3euH/9Z/45A57+/tx/s/w8=", file_map: { "17": { source: `use crate::field::field_less_than;
10512
11230
  use crate::runtime::is_unconstrained;
10513
11231
 
10514
11232
  // The low and high decomposition of the field modulus
@@ -10711,105 +11429,7 @@ mod tests {
10711
11429
  assert(!lt(TWO_POW_128, TWO_POW_128 - 1));
10712
11430
  }
10713
11431
  }
10714
- `, path: "std/field/bn254.nr" }, "19": { source: '// Exposed only for usage in `std::meta`\npub(crate) mod poseidon2;\n\nuse crate::default::Default;\nuse crate::embedded_curve_ops::{\n EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,\n};\nuse crate::meta::derive_via;\n\n#[foreign(sha256_compression)]\n// docs:start:sha256_compression\npub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}\n// docs:end:sha256_compression\n\n#[foreign(keccakf1600)]\n// docs:start:keccakf1600\npub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}\n// docs:end:keccakf1600\n\npub mod keccak {\n #[deprecated("This function has been moved to std::hash::keccakf1600")]\n pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {\n super::keccakf1600(input)\n }\n}\n\n#[foreign(blake2s)]\n// docs:start:blake2s\npub fn blake2s<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake2s\n{}\n\n// docs:start:blake3\npub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake3\n{\n if crate::runtime::is_unconstrained() {\n // Temporary measure while Barretenberg is main proving system.\n // Please open an issue if you\'re working on another proving system and running into problems due to this.\n crate::static_assert(\n N <= 1024,\n "Barretenberg cannot prove blake3 hashes with inputs larger than 1024 bytes",\n );\n }\n __blake3(input)\n}\n\n#[foreign(blake3)]\nfn __blake3<let N: u32>(input: [u8; N]) -> [u8; 32] {}\n\n// docs:start:pedersen_commitment\npub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {\n // docs:end:pedersen_commitment\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[inline_always]\npub fn pedersen_commitment_with_separator<let N: u32>(\n input: [Field; N],\n separator: u32,\n) -> EmbeddedCurvePoint {\n let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N];\n for i in 0..N {\n // we use the unsafe version because the multi_scalar_mul will constrain the scalars.\n points[i] = from_field_unsafe(input[i]);\n }\n let generators = derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n multi_scalar_mul(generators, points)\n}\n\n// docs:start:pedersen_hash\npub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field\n// docs:end:pedersen_hash\n{\n pedersen_hash_with_separator(input, 0)\n}\n\n#[no_predicates]\npub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {\n let mut scalars: [EmbeddedCurveScalar; N + 1] = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N + 1];\n let mut generators: [EmbeddedCurvePoint; N + 1] =\n [EmbeddedCurvePoint::point_at_infinity(); N + 1];\n let domain_generators: [EmbeddedCurvePoint; N] =\n derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n\n for i in 0..N {\n scalars[i] = from_field_unsafe(input[i]);\n generators[i] = domain_generators[i];\n }\n scalars[N] = EmbeddedCurveScalar { lo: N as Field, hi: 0 as Field };\n\n let length_generator: [EmbeddedCurvePoint; 1] =\n derive_generators("pedersen_hash_length".as_bytes(), 0);\n generators[N] = length_generator[0];\n multi_scalar_mul_array_return(generators, scalars, true)[0].x\n}\n\n#[field(bn254)]\n#[inline_always]\npub fn derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {\n crate::assert_constant(domain_separator_bytes);\n // TODO(https://github.com/noir-lang/noir/issues/5672): Add back assert_constant on starting_index\n __derive_generators(domain_separator_bytes, starting_index)\n}\n\n#[builtin(derive_pedersen_generators)]\n#[field(bn254)]\nfn __derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {}\n\n#[field(bn254)]\n// Same as from_field but:\n// does not assert the limbs are 128 bits\n// does not assert the decomposition does not overflow the EmbeddedCurveScalar\nfn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar {\n // Safety: xlo and xhi decomposition is checked below\n let (xlo, xhi) = unsafe { crate::field::bn254::decompose_hint(scalar) };\n // Check that the decomposition is correct\n assert_eq(scalar, xlo + crate::field::bn254::TWO_POW_128 * xhi);\n EmbeddedCurveScalar { lo: xlo, hi: xhi }\n}\n\npub fn poseidon2_permutation<let N: u32>(input: [Field; N], state_len: u32) -> [Field; N] {\n assert_eq(input.len(), state_len);\n poseidon2_permutation_internal(input)\n}\n\n#[foreign(poseidon2_permutation)]\nfn poseidon2_permutation_internal<let N: u32>(input: [Field; N]) -> [Field; N] {}\n\n// Generic hashing support.\n// Partially ported and impacted by rust.\n\n// Hash trait shall be implemented per type.\n#[derive_via(derive_hash)]\npub trait Hash {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher;\n}\n\n// docs:start:derive_hash\ncomptime fn derive_hash(s: TypeDefinition) -> Quoted {\n let name = quote { $crate::hash::Hash };\n let signature = quote { fn hash<H>(_self: Self, _state: &mut H) where H: $crate::hash::Hasher };\n let for_each_field = |name| quote { _self.$name.hash(_state); };\n crate::meta::make_trait_impl(\n s,\n name,\n signature,\n for_each_field,\n quote {},\n |fields| fields,\n )\n}\n// docs:end:derive_hash\n\n// Hasher trait shall be implemented by algorithms to provide hash-agnostic means.\n// TODO: consider making the types generic here ([u8], [Field], etc.)\npub trait Hasher {\n fn finish(self) -> Field;\n\n fn write(&mut self, input: Field);\n}\n\n// BuildHasher is a factory trait, responsible for production of specific Hasher.\npub trait BuildHasher {\n type H: Hasher;\n\n fn build_hasher(self) -> H;\n}\n\npub struct BuildHasherDefault<H>;\n\nimpl<H> BuildHasher for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n type H = H;\n\n fn build_hasher(_self: Self) -> H {\n H::default()\n }\n}\n\nimpl<H> Default for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n fn default() -> Self {\n BuildHasherDefault {}\n }\n}\n\nimpl Hash for Field {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self);\n }\n}\n\nimpl Hash for u1 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u128 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for i8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u8 as Field);\n }\n}\n\nimpl Hash for i16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u16 as Field);\n }\n}\n\nimpl Hash for i32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u32 as Field);\n }\n}\n\nimpl Hash for i64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u64 as Field);\n }\n}\n\nimpl Hash for bool {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for () {\n fn hash<H>(_self: Self, _state: &mut H)\n where\n H: Hasher,\n {}\n}\n\nimpl<T, let N: u32> Hash for [T; N]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<T> Hash for [T]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.len().hash(state);\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<A, B> Hash for (A, B)\nwhere\n A: Hash,\n B: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n }\n}\n\nimpl<A, B, C> Hash for (A, B, C)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n }\n}\n\nimpl<A, B, C, D> Hash for (A, B, C, D)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n }\n}\n\nimpl<A, B, C, D, E> Hash for (A, B, C, D, E)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n E: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n self.4.hash(state);\n }\n}\n\n// Some test vectors for Pedersen hash and Pedersen Commitment.\n// They have been generated using the same functions so the tests are for now useless\n// but they will be useful when we switch to Noir implementation.\n#[test]\nfn assert_pedersen() {\n assert_eq(\n pedersen_hash_with_separator([1], 1),\n 0x1b3f4b1a83092a13d8d1a59f7acb62aba15e7002f4440f2275edb99ebbc2305f,\n );\n assert_eq(\n pedersen_commitment_with_separator([1], 1),\n EmbeddedCurvePoint {\n x: 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402,\n y: 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126,\n is_infinite: false,\n },\n );\n\n assert_eq(\n pedersen_hash_with_separator([1, 2], 2),\n 0x26691c129448e9ace0c66d11f0a16d9014a9e8498ee78f4d69f0083168188255,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2], 2),\n EmbeddedCurvePoint {\n x: 0x2e2b3b191e49541fe468ec6877721d445dcaffe41728df0a0eafeb15e87b0753,\n y: 0x2ff4482400ad3a6228be17a2af33e2bcdf41be04795f9782bd96efe7e24f8778,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3], 3),\n 0x0bc694b7a1f8d10d2d8987d07433f26bd616a2d351bc79a3c540d85b6206dbe4,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3], 3),\n EmbeddedCurvePoint {\n x: 0x1fee4e8cf8d2f527caa2684236b07c4b1bad7342c01b0f75e9a877a71827dc85,\n y: 0x2f9fedb9a090697ab69bf04c8bc15f7385b3e4b68c849c1536e5ae15ff138fd1,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4], 4),\n 0xdae10fb32a8408521803905981a2b300d6a35e40e798743e9322b223a5eddc,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4], 4),\n EmbeddedCurvePoint {\n x: 0x07ae3e202811e1fca39c2d81eabe6f79183978e6f12be0d3b8eda095b79bdbc9,\n y: 0x0afc6f892593db6fbba60f2da558517e279e0ae04f95758587760ba193145014,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5], 5),\n 0xfc375b062c4f4f0150f7100dfb8d9b72a6d28582dd9512390b0497cdad9c22,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5], 5),\n EmbeddedCurvePoint {\n x: 0x1754b12bd475a6984a1094b5109eeca9838f4f81ac89c5f0a41dbce53189bb29,\n y: 0x2da030e3cfcdc7ddad80eaf2599df6692cae0717d4e9f7bfbee8d073d5d278f7,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6], 6),\n 0x1696ed13dc2730062a98ac9d8f9de0661bb98829c7582f699d0273b18c86a572,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6], 6),\n EmbeddedCurvePoint {\n x: 0x190f6c0e97ad83e1e28da22a98aae156da083c5a4100e929b77e750d3106a697,\n y: 0x1f4b60f34ef91221a0b49756fa0705da93311a61af73d37a0c458877706616fb,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n 0x128c0ff144fc66b6cb60eeac8a38e23da52992fc427b92397a7dffd71c45ede3,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n EmbeddedCurvePoint {\n x: 0x015441e9d29491b06563fac16fc76abf7a9534c715421d0de85d20dbe2965939,\n y: 0x1d2575b0276f4e9087e6e07c2cb75aa1baafad127af4be5918ef8a2ef2fea8fc,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n 0x2f960e117482044dfc99d12fece2ef6862fba9242be4846c7c9a3e854325a55c,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n EmbeddedCurvePoint {\n x: 0x1657737676968887fceb6dd516382ea13b3a2c557f509811cd86d5d1199bc443,\n y: 0x1f39f0cb569040105fa1e2f156521e8b8e08261e635a2b210bdc94e8d6d65f77,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n 0x0c96db0790602dcb166cc4699e2d306c479a76926b81c2cb2aaa92d249ec7be7,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n EmbeddedCurvePoint {\n x: 0x0a3ceae42d14914a432aa60ec7fded4af7dad7dd4acdbf2908452675ec67e06d,\n y: 0xfc19761eaaf621ad4aec9a8b2e84a4eceffdba78f60f8b9391b0bd9345a2f2,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n 0x2cd37505871bc460a62ea1e63c7fe51149df5d0801302cf1cbc48beb8dff7e94,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n EmbeddedCurvePoint {\n x: 0x2fb3f8b3d41ddde007c8c3c62550f9a9380ee546fcc639ffbb3fd30c8d8de30c,\n y: 0x300783be23c446b11a4c0fabf6c91af148937cea15fcf5fb054abf7f752ee245,\n is_infinite: false,\n },\n );\n}\n', path: "std/hash/mod.nr" }, "50": { source: `/// Funding Proof Circuit
10715
- ///
10716
- /// Proves: "I have sufficient funds to fulfill this intent, without revealing
10717
- /// my exact balance, wallet address, or source of funds."
10718
- ///
10719
- /// @see docs/specs/FUNDING-PROOF.md
10720
-
10721
- use std::hash::pedersen_hash;
10722
- use std::hash::pedersen_commitment;
10723
-
10724
- // --- Main Circuit ---
10725
-
10726
- /// Main funding proof entry point
10727
- ///
10728
- /// Public inputs: commitment_hash, minimum_required, asset_id
10729
- /// Private inputs: balance, blinding
10730
- ///
10731
- /// Constraints:
10732
- /// 1. balance >= minimum_required (range proof via u64)
10733
- /// 2. commitment = Pedersen(balance, blinding)
10734
- /// 3. hash(commitment, asset_id) == commitment_hash
10735
- pub fn main(
10736
- commitment_hash: pub Field,
10737
- minimum_required: pub u64,
10738
- asset_id: pub Field,
10739
- balance: u64,
10740
- blinding: Field,
10741
- ) {
10742
- // Constraint 1: Sufficient Funds
10743
- assert(balance >= minimum_required, "Insufficient balance");
10744
-
10745
- // Constraint 2: Compute Pedersen Commitment
10746
- // Uses Noir's built-in pedersen_commitment which returns (x, y) point
10747
- let commitment = pedersen_commitment([balance as Field, blinding]);
10748
-
10749
- // Constraint 3: Verify Commitment Hash
10750
- let computed_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
10751
- assert(computed_hash == commitment_hash, "Commitment hash mismatch");
10752
- }
10753
-
10754
- // --- Tests ---
10755
-
10756
- #[test]
10757
- fn test_valid_funding_proof() {
10758
- let balance: u64 = 100;
10759
- let minimum_required: u64 = 50;
10760
- let blinding: Field = 12345;
10761
- let asset_id: Field = 0xABCD;
10762
-
10763
- // Compute commitment using same method as circuit
10764
- let commitment = pedersen_commitment([balance as Field, blinding]);
10765
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
10766
-
10767
- // This should pass
10768
- main(commitment_hash, minimum_required, asset_id, balance, blinding);
10769
- }
10770
-
10771
- #[test(should_fail_with = "Insufficient balance")]
10772
- fn test_insufficient_balance() {
10773
- let balance: u64 = 50;
10774
- let minimum_required: u64 = 100;
10775
- let blinding: Field = 12345;
10776
- let asset_id: Field = 0xABCD;
10777
-
10778
- let commitment = pedersen_commitment([balance as Field, blinding]);
10779
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
10780
-
10781
- // This should fail - balance < minimum
10782
- main(commitment_hash, minimum_required, asset_id, balance, blinding);
10783
- }
10784
-
10785
- #[test(should_fail_with = "Commitment hash mismatch")]
10786
- fn test_wrong_commitment_hash() {
10787
- let balance: u64 = 100;
10788
- let minimum_required: u64 = 50;
10789
- let blinding: Field = 12345;
10790
- let asset_id: Field = 0xABCD;
10791
- let wrong_hash: Field = 0xDEADBEEF;
10792
-
10793
- // This should fail - wrong hash
10794
- main(wrong_hash, minimum_required, asset_id, balance, blinding);
10795
- }
10796
-
10797
- #[test(should_fail_with = "Commitment hash mismatch")]
10798
- fn test_wrong_blinding() {
10799
- let balance: u64 = 100;
10800
- let minimum_required: u64 = 50;
10801
- let correct_blinding: Field = 12345;
10802
- let wrong_blinding: Field = 54321;
10803
- let asset_id: Field = 0xABCD;
10804
-
10805
- // Compute hash with correct blinding
10806
- let commitment = pedersen_commitment([balance as Field, correct_blinding]);
10807
- let commitment_hash = pedersen_hash([commitment.x, commitment.y, asset_id]);
10808
-
10809
- // Try to prove with wrong blinding - should fail
10810
- main(commitment_hash, minimum_required, asset_id, balance, wrong_blinding);
10811
- }
10812
- `, path: "/Users/rz/local-dev/sip-protocol/packages/circuits/funding_proof/src/main.nr" } }, expression_width: { Bounded: { width: 4 } } };
11432
+ `, path: "std/field/bn254.nr" }, "18": { source: 'pub mod bn254;\nuse crate::{runtime::is_unconstrained, static_assert};\nuse bn254::lt as bn254_lt;\n\nimpl Field {\n /// Asserts that `self` can be represented in `bit_size` bits.\n ///\n /// # Failures\n /// Causes a constraint failure for `Field` values exceeding `2^{bit_size}`.\n // docs:start:assert_max_bit_size\n pub fn assert_max_bit_size<let BIT_SIZE: u32>(self) {\n // docs:end:assert_max_bit_size\n static_assert(\n BIT_SIZE < modulus_num_bits() as u32,\n "BIT_SIZE must be less than modulus_num_bits",\n );\n __assert_max_bit_size(self, BIT_SIZE);\n }\n\n /// Decomposes `self` into its little endian bit decomposition as a `[u1; N]` array.\n /// This slice will be zero padded should not all bits be necessary to represent `self`.\n ///\n /// # Failures\n /// Causes a constraint failure for `Field` values exceeding `2^N` as the resulting slice will not\n /// be able to represent the original `Field`.\n ///\n /// # Safety\n /// The bit decomposition returned is canonical and is guaranteed to not overflow the modulus.\n // docs:start:to_le_bits\n pub fn to_le_bits<let N: u32>(self: Self) -> [u1; N] {\n // docs:end:to_le_bits\n let bits = __to_le_bits(self);\n\n if !is_unconstrained() {\n // Ensure that the byte decomposition does not overflow the modulus\n let p = modulus_le_bits();\n assert(bits.len() <= p.len());\n let mut ok = bits.len() != p.len();\n for i in 0..N {\n if !ok {\n if (bits[N - 1 - i] != p[N - 1 - i]) {\n assert(p[N - 1 - i] == 1);\n ok = true;\n }\n }\n }\n assert(ok);\n }\n bits\n }\n\n /// Decomposes `self` into its big endian bit decomposition as a `[u1; N]` array.\n /// This array will be zero padded should not all bits be necessary to represent `self`.\n ///\n /// # Failures\n /// Causes a constraint failure for `Field` values exceeding `2^N` as the resulting slice will not\n /// be able to represent the original `Field`.\n ///\n /// # Safety\n /// The bit decomposition returned is canonical and is guaranteed to not overflow the modulus.\n // docs:start:to_be_bits\n pub fn to_be_bits<let N: u32>(self: Self) -> [u1; N] {\n // docs:end:to_be_bits\n let bits = __to_be_bits(self);\n\n if !is_unconstrained() {\n // Ensure that the decomposition does not overflow the modulus\n let p = modulus_be_bits();\n assert(bits.len() <= p.len());\n let mut ok = bits.len() != p.len();\n for i in 0..N {\n if !ok {\n if (bits[i] != p[i]) {\n assert(p[i] == 1);\n ok = true;\n }\n }\n }\n assert(ok);\n }\n bits\n }\n\n /// Decomposes `self` into its little endian byte decomposition as a `[u8;N]` array\n /// This array will be zero padded should not all bytes be necessary to represent `self`.\n ///\n /// # Failures\n /// The length N of the array must be big enough to contain all the bytes of the \'self\',\n /// and no more than the number of bytes required to represent the field modulus\n ///\n /// # Safety\n /// The result is ensured to be the canonical decomposition of the field element\n // docs:start:to_le_bytes\n pub fn to_le_bytes<let N: u32>(self: Self) -> [u8; N] {\n // docs:end:to_le_bytes\n static_assert(\n N <= modulus_le_bytes().len(),\n "N must be less than or equal to modulus_le_bytes().len()",\n );\n // Compute the byte decomposition\n let bytes = self.to_le_radix(256);\n\n if !is_unconstrained() {\n // Ensure that the byte decomposition does not overflow the modulus\n let p = modulus_le_bytes();\n assert(bytes.len() <= p.len());\n let mut ok = bytes.len() != p.len();\n for i in 0..N {\n if !ok {\n if (bytes[N - 1 - i] != p[N - 1 - i]) {\n assert(bytes[N - 1 - i] < p[N - 1 - i]);\n ok = true;\n }\n }\n }\n assert(ok);\n }\n bytes\n }\n\n /// Decomposes `self` into its big endian byte decomposition as a `[u8;N]` array of length required to represent the field modulus\n /// This array will be zero padded should not all bytes be necessary to represent `self`.\n ///\n /// # Failures\n /// The length N of the array must be big enough to contain all the bytes of the \'self\',\n /// and no more than the number of bytes required to represent the field modulus\n ///\n /// # Safety\n /// The result is ensured to be the canonical decomposition of the field element\n // docs:start:to_be_bytes\n pub fn to_be_bytes<let N: u32>(self: Self) -> [u8; N] {\n // docs:end:to_be_bytes\n static_assert(\n N <= modulus_le_bytes().len(),\n "N must be less than or equal to modulus_le_bytes().len()",\n );\n // Compute the byte decomposition\n let bytes = self.to_be_radix(256);\n\n if !is_unconstrained() {\n // Ensure that the byte decomposition does not overflow the modulus\n let p = modulus_be_bytes();\n assert(bytes.len() <= p.len());\n let mut ok = bytes.len() != p.len();\n for i in 0..N {\n if !ok {\n if (bytes[i] != p[i]) {\n assert(bytes[i] < p[i]);\n ok = true;\n }\n }\n }\n assert(ok);\n }\n bytes\n }\n\n fn to_le_radix<let N: u32>(self: Self, radix: u32) -> [u8; N] {\n // Brillig does not need an immediate radix\n if !crate::runtime::is_unconstrained() {\n static_assert(1 < radix, "radix must be greater than 1");\n static_assert(radix <= 256, "radix must be less than or equal to 256");\n static_assert(radix & (radix - 1) == 0, "radix must be a power of 2");\n }\n __to_le_radix(self, radix)\n }\n\n fn to_be_radix<let N: u32>(self: Self, radix: u32) -> [u8; N] {\n // Brillig does not need an immediate radix\n if !crate::runtime::is_unconstrained() {\n static_assert(1 < radix, "radix must be greater than 1");\n static_assert(radix <= 256, "radix must be less than or equal to 256");\n static_assert(radix & (radix - 1) == 0, "radix must be a power of 2");\n }\n __to_be_radix(self, radix)\n }\n\n // Returns self to the power of the given exponent value.\n // Caution: we assume the exponent fits into 32 bits\n // using a bigger bit size impacts negatively the performance and should be done only if the exponent does not fit in 32 bits\n pub fn pow_32(self, exponent: Field) -> Field {\n let mut r: Field = 1;\n let b: [u1; 32] = exponent.to_le_bits();\n\n for i in 1..33 {\n r *= r;\n r = (b[32 - i] as Field) * (r * self) + (1 - b[32 - i] as Field) * r;\n }\n r\n }\n\n // Parity of (prime) Field element, i.e. sgn0(x mod p) = 0 if x `elem` {0, ..., p-1} is even, otherwise sgn0(x mod p) = 1.\n pub fn sgn0(self) -> u1 {\n self as u1\n }\n\n pub fn lt(self, another: Field) -> bool {\n if crate::compat::is_bn254() {\n bn254_lt(self, another)\n } else {\n lt_fallback(self, another)\n }\n }\n\n /// Convert a little endian byte array to a field element.\n /// If the provided byte array overflows the field modulus then the Field will silently wrap around.\n pub fn from_le_bytes<let N: u32>(bytes: [u8; N]) -> Field {\n static_assert(\n N <= modulus_le_bytes().len(),\n "N must be less than or equal to modulus_le_bytes().len()",\n );\n let mut v = 1;\n let mut result = 0;\n\n for i in 0..N {\n result += (bytes[i] as Field) * v;\n v = v * 256;\n }\n result\n }\n\n /// Convert a big endian byte array to a field element.\n /// If the provided byte array overflows the field modulus then the Field will silently wrap around.\n pub fn from_be_bytes<let N: u32>(bytes: [u8; N]) -> Field {\n let mut v = 1;\n let mut result = 0;\n\n for i in 0..N {\n result += (bytes[N - 1 - i] as Field) * v;\n v = v * 256;\n }\n result\n }\n}\n\n#[builtin(apply_range_constraint)]\nfn __assert_max_bit_size(value: Field, bit_size: u32) {}\n\n// `_radix` must be less than 256\n#[builtin(to_le_radix)]\nfn __to_le_radix<let N: u32>(value: Field, radix: u32) -> [u8; N] {}\n\n// `_radix` must be less than 256\n#[builtin(to_be_radix)]\nfn __to_be_radix<let N: u32>(value: Field, radix: u32) -> [u8; N] {}\n\n/// Decomposes `self` into its little endian bit decomposition as a `[u1; N]` array.\n/// This slice will be zero padded should not all bits be necessary to represent `self`.\n///\n/// # Failures\n/// Causes a constraint failure for `Field` values exceeding `2^N` as the resulting slice will not\n/// be able to represent the original `Field`.\n///\n/// # Safety\n/// Values of `N` equal to or greater than the number of bits necessary to represent the `Field` modulus\n/// (e.g. 254 for the BN254 field) allow for multiple bit decompositions. This is due to how the `Field` will\n/// wrap around due to overflow when verifying the decomposition.\n#[builtin(to_le_bits)]\nfn __to_le_bits<let N: u32>(value: Field) -> [u1; N] {}\n\n/// Decomposes `self` into its big endian bit decomposition as a `[u1; N]` array.\n/// This array will be zero padded should not all bits be necessary to represent `self`.\n///\n/// # Failures\n/// Causes a constraint failure for `Field` values exceeding `2^N` as the resulting slice will not\n/// be able to represent the original `Field`.\n///\n/// # Safety\n/// Values of `N` equal to or greater than the number of bits necessary to represent the `Field` modulus\n/// (e.g. 254 for the BN254 field) allow for multiple bit decompositions. This is due to how the `Field` will\n/// wrap around due to overflow when verifying the decomposition.\n#[builtin(to_be_bits)]\nfn __to_be_bits<let N: u32>(value: Field) -> [u1; N] {}\n\n#[builtin(modulus_num_bits)]\npub comptime fn modulus_num_bits() -> u64 {}\n\n#[builtin(modulus_be_bits)]\npub comptime fn modulus_be_bits() -> [u1] {}\n\n#[builtin(modulus_le_bits)]\npub comptime fn modulus_le_bits() -> [u1] {}\n\n#[builtin(modulus_be_bytes)]\npub comptime fn modulus_be_bytes() -> [u8] {}\n\n#[builtin(modulus_le_bytes)]\npub comptime fn modulus_le_bytes() -> [u8] {}\n\n/// An unconstrained only built in to efficiently compare fields.\n#[builtin(field_less_than)]\nunconstrained fn __field_less_than(x: Field, y: Field) -> bool {}\n\npub(crate) unconstrained fn field_less_than(x: Field, y: Field) -> bool {\n __field_less_than(x, y)\n}\n\n// Convert a 32 byte array to a field element by modding\npub fn bytes32_to_field(bytes32: [u8; 32]) -> Field {\n // Convert it to a field element\n let mut v = 1;\n let mut high = 0 as Field;\n let mut low = 0 as Field;\n\n for i in 0..16 {\n high = high + (bytes32[15 - i] as Field) * v;\n low = low + (bytes32[16 + 15 - i] as Field) * v;\n v = v * 256;\n }\n // Abuse that a % p + b % p = (a + b) % p and that low < p\n low + high * v\n}\n\nfn lt_fallback(x: Field, y: Field) -> bool {\n if is_unconstrained() {\n // Safety: unconstrained context\n unsafe {\n field_less_than(x, y)\n }\n } else {\n let x_bytes: [u8; 32] = x.to_le_bytes();\n let y_bytes: [u8; 32] = y.to_le_bytes();\n let mut x_is_lt = false;\n let mut done = false;\n for i in 0..32 {\n if (!done) {\n let x_byte = x_bytes[32 - 1 - i] as u8;\n let y_byte = y_bytes[32 - 1 - i] as u8;\n let bytes_match = x_byte == y_byte;\n if !bytes_match {\n x_is_lt = x_byte < y_byte;\n done = true;\n }\n }\n }\n x_is_lt\n }\n}\n\nmod tests {\n use crate::{panic::panic, runtime, static_assert};\n use super::{\n field_less_than, modulus_be_bits, modulus_be_bytes, modulus_le_bits, modulus_le_bytes,\n };\n\n #[test]\n // docs:start:to_be_bits_example\n fn test_to_be_bits() {\n let field = 2;\n let bits: [u1; 8] = field.to_be_bits();\n assert_eq(bits, [0, 0, 0, 0, 0, 0, 1, 0]);\n }\n // docs:end:to_be_bits_example\n\n #[test]\n // docs:start:to_le_bits_example\n fn test_to_le_bits() {\n let field = 2;\n let bits: [u1; 8] = field.to_le_bits();\n assert_eq(bits, [0, 1, 0, 0, 0, 0, 0, 0]);\n }\n // docs:end:to_le_bits_example\n\n #[test]\n // docs:start:to_be_bytes_example\n fn test_to_be_bytes() {\n let field = 2;\n let bytes: [u8; 8] = field.to_be_bytes();\n assert_eq(bytes, [0, 0, 0, 0, 0, 0, 0, 2]);\n assert_eq(Field::from_be_bytes::<8>(bytes), field);\n }\n // docs:end:to_be_bytes_example\n\n #[test]\n // docs:start:to_le_bytes_example\n fn test_to_le_bytes() {\n let field = 2;\n let bytes: [u8; 8] = field.to_le_bytes();\n assert_eq(bytes, [2, 0, 0, 0, 0, 0, 0, 0]);\n assert_eq(Field::from_le_bytes::<8>(bytes), field);\n }\n // docs:end:to_le_bytes_example\n\n #[test]\n // docs:start:to_be_radix_example\n fn test_to_be_radix() {\n // 259, in base 256, big endian, is [1, 3].\n // i.e. 3 * 256^0 + 1 * 256^1\n let field = 259;\n\n // The radix (in this example, 256) must be a power of 2.\n // The length of the returned byte array can be specified to be\n // >= the amount of space needed.\n let bytes: [u8; 8] = field.to_be_radix(256);\n assert_eq(bytes, [0, 0, 0, 0, 0, 0, 1, 3]);\n assert_eq(Field::from_be_bytes::<8>(bytes), field);\n }\n // docs:end:to_be_radix_example\n\n #[test]\n // docs:start:to_le_radix_example\n fn test_to_le_radix() {\n // 259, in base 256, little endian, is [3, 1].\n // i.e. 3 * 256^0 + 1 * 256^1\n let field = 259;\n\n // The radix (in this example, 256) must be a power of 2.\n // The length of the returned byte array can be specified to be\n // >= the amount of space needed.\n let bytes: [u8; 8] = field.to_le_radix(256);\n assert_eq(bytes, [3, 1, 0, 0, 0, 0, 0, 0]);\n assert_eq(Field::from_le_bytes::<8>(bytes), field);\n }\n // docs:end:to_le_radix_example\n\n #[test(should_fail_with = "radix must be greater than 1")]\n fn test_to_le_radix_1() {\n // this test should only fail in constrained mode\n if !runtime::is_unconstrained() {\n let field = 2;\n let _: [u8; 8] = field.to_le_radix(1);\n } else {\n panic(f"radix must be greater than 1");\n }\n }\n\n // Updated test to account for Brillig restriction that radix must be greater than 2\n #[test(should_fail_with = "radix must be greater than 1")]\n fn test_to_le_radix_brillig_1() {\n // this test should only fail in constrained mode\n if !runtime::is_unconstrained() {\n let field = 1;\n let _: [u8; 8] = field.to_le_radix(1);\n } else {\n panic(f"radix must be greater than 1");\n }\n }\n\n #[test(should_fail_with = "radix must be a power of 2")]\n fn test_to_le_radix_3() {\n // this test should only fail in constrained mode\n if !runtime::is_unconstrained() {\n let field = 2;\n let _: [u8; 8] = field.to_le_radix(3);\n } else {\n panic(f"radix must be a power of 2");\n }\n }\n\n #[test]\n fn test_to_le_radix_brillig_3() {\n // this test should only fail in constrained mode\n if runtime::is_unconstrained() {\n let field = 1;\n let out: [u8; 8] = field.to_le_radix(3);\n let mut expected = [0; 8];\n expected[0] = 1;\n assert(out == expected, "unexpected result");\n }\n }\n\n #[test(should_fail_with = "radix must be less than or equal to 256")]\n fn test_to_le_radix_512() {\n // this test should only fail in constrained mode\n if !runtime::is_unconstrained() {\n let field = 2;\n let _: [u8; 8] = field.to_le_radix(512);\n } else {\n panic(f"radix must be less than or equal to 256")\n }\n }\n\n #[test(should_fail_with = "Field failed to decompose into specified 16 limbs")]\n unconstrained fn not_enough_limbs_brillig() {\n let _: [u8; 16] = 0x100000000000000000000000000000000.to_le_bytes();\n }\n\n #[test(should_fail_with = "Field failed to decompose into specified 16 limbs")]\n fn not_enough_limbs() {\n let _: [u8; 16] = 0x100000000000000000000000000000000.to_le_bytes();\n }\n\n #[test]\n unconstrained fn test_field_less_than() {\n assert(field_less_than(0, 1));\n assert(field_less_than(0, 0x100));\n assert(field_less_than(0x100, 0 - 1));\n assert(!field_less_than(0 - 1, 0));\n }\n\n #[test]\n unconstrained fn test_large_field_values_unconstrained() {\n let large_field = 0xffffffffffffffff;\n\n let bits: [u1; 64] = large_field.to_le_bits();\n assert_eq(bits[0], 1);\n\n let bytes: [u8; 8] = large_field.to_le_bytes();\n assert_eq(Field::from_le_bytes::<8>(bytes), large_field);\n\n let radix_bytes: [u8; 8] = large_field.to_le_radix(256);\n assert_eq(Field::from_le_bytes::<8>(radix_bytes), large_field);\n }\n\n #[test]\n fn test_large_field_values() {\n let large_val = 0xffffffffffffffff;\n\n let bits: [u1; 64] = large_val.to_le_bits();\n assert_eq(bits[0], 1);\n\n let bytes: [u8; 8] = large_val.to_le_bytes();\n assert_eq(Field::from_le_bytes::<8>(bytes), large_val);\n\n let radix_bytes: [u8; 8] = large_val.to_le_radix(256);\n assert_eq(Field::from_le_bytes::<8>(radix_bytes), large_val);\n }\n\n #[test]\n fn test_decomposition_edge_cases() {\n let zero_bits: [u1; 8] = 0.to_le_bits();\n assert_eq(zero_bits, [0; 8]);\n\n let zero_bytes: [u8; 8] = 0.to_le_bytes();\n assert_eq(zero_bytes, [0; 8]);\n\n let one_bits: [u1; 8] = 1.to_le_bits();\n let expected: [u1; 8] = [1, 0, 0, 0, 0, 0, 0, 0];\n assert_eq(one_bits, expected);\n\n let pow2_bits: [u1; 8] = 4.to_le_bits();\n let expected: [u1; 8] = [0, 0, 1, 0, 0, 0, 0, 0];\n assert_eq(pow2_bits, expected);\n }\n\n #[test]\n fn test_pow_32() {\n assert_eq(2.pow_32(3), 8);\n assert_eq(3.pow_32(2), 9);\n assert_eq(5.pow_32(0), 1);\n assert_eq(7.pow_32(1), 7);\n\n assert_eq(2.pow_32(10), 1024);\n\n assert_eq(0.pow_32(5), 0);\n assert_eq(0.pow_32(0), 1);\n\n assert_eq(1.pow_32(100), 1);\n }\n\n #[test]\n fn test_sgn0() {\n assert_eq(0.sgn0(), 0);\n assert_eq(2.sgn0(), 0);\n assert_eq(4.sgn0(), 0);\n assert_eq(100.sgn0(), 0);\n\n assert_eq(1.sgn0(), 1);\n assert_eq(3.sgn0(), 1);\n assert_eq(5.sgn0(), 1);\n assert_eq(101.sgn0(), 1);\n }\n\n #[test(should_fail_with = "Field failed to decompose into specified 8 limbs")]\n fn test_bit_decomposition_overflow() {\n // 8 bits can\'t represent large field values\n let large_val = 0x1000000000000000;\n let _: [u1; 8] = large_val.to_le_bits();\n }\n\n #[test(should_fail_with = "Field failed to decompose into specified 4 limbs")]\n fn test_byte_decomposition_overflow() {\n // 4 bytes can\'t represent large field values\n let large_val = 0x1000000000000000;\n let _: [u8; 4] = large_val.to_le_bytes();\n }\n\n #[test]\n fn test_to_from_be_bytes_bn254_edge_cases() {\n if crate::compat::is_bn254() {\n // checking that decrementing this byte produces the expected 32 BE bytes for (modulus - 1)\n let mut p_minus_1_bytes: [u8; 32] = modulus_be_bytes().as_array();\n assert(p_minus_1_bytes[32 - 1] > 0);\n p_minus_1_bytes[32 - 1] -= 1;\n\n let p_minus_1 = Field::from_be_bytes::<32>(p_minus_1_bytes);\n assert_eq(p_minus_1 + 1, 0);\n\n // checking that converting (modulus - 1) from and then to 32 BE bytes produces the same bytes\n let p_minus_1_converted_bytes: [u8; 32] = p_minus_1.to_be_bytes();\n assert_eq(p_minus_1_converted_bytes, p_minus_1_bytes);\n\n // checking that incrementing this byte produces 32 BE bytes for (modulus + 1)\n let mut p_plus_1_bytes: [u8; 32] = modulus_be_bytes().as_array();\n assert(p_plus_1_bytes[32 - 1] < 255);\n p_plus_1_bytes[32 - 1] += 1;\n\n let p_plus_1 = Field::from_be_bytes::<32>(p_plus_1_bytes);\n assert_eq(p_plus_1, 1);\n\n // checking that converting p_plus_1 to 32 BE bytes produces the same\n // byte set to 1 as p_plus_1_bytes and otherwise zeroes\n let mut p_plus_1_converted_bytes: [u8; 32] = p_plus_1.to_be_bytes();\n assert_eq(p_plus_1_converted_bytes[32 - 1], 1);\n p_plus_1_converted_bytes[32 - 1] = 0;\n assert_eq(p_plus_1_converted_bytes, [0; 32]);\n\n // checking that Field::from_be_bytes::<32> on the Field modulus produces 0\n assert_eq(modulus_be_bytes().len(), 32);\n let p = Field::from_be_bytes::<32>(modulus_be_bytes().as_array());\n assert_eq(p, 0);\n\n // checking that converting 0 to 32 BE bytes produces 32 zeroes\n let p_bytes: [u8; 32] = 0.to_be_bytes();\n assert_eq(p_bytes, [0; 32]);\n }\n }\n\n #[test]\n fn test_to_from_le_bytes_bn254_edge_cases() {\n if crate::compat::is_bn254() {\n // checking that decrementing this byte produces the expected 32 LE bytes for (modulus - 1)\n let mut p_minus_1_bytes: [u8; 32] = modulus_le_bytes().as_array();\n assert(p_minus_1_bytes[0] > 0);\n p_minus_1_bytes[0] -= 1;\n\n let p_minus_1 = Field::from_le_bytes::<32>(p_minus_1_bytes);\n assert_eq(p_minus_1 + 1, 0);\n\n // checking that converting (modulus - 1) from and then to 32 BE bytes produces the same bytes\n let p_minus_1_converted_bytes: [u8; 32] = p_minus_1.to_le_bytes();\n assert_eq(p_minus_1_converted_bytes, p_minus_1_bytes);\n\n // checking that incrementing this byte produces 32 LE bytes for (modulus + 1)\n let mut p_plus_1_bytes: [u8; 32] = modulus_le_bytes().as_array();\n assert(p_plus_1_bytes[0] < 255);\n p_plus_1_bytes[0] += 1;\n\n let p_plus_1 = Field::from_le_bytes::<32>(p_plus_1_bytes);\n assert_eq(p_plus_1, 1);\n\n // checking that converting p_plus_1 to 32 LE bytes produces the same\n // byte set to 1 as p_plus_1_bytes and otherwise zeroes\n let mut p_plus_1_converted_bytes: [u8; 32] = p_plus_1.to_le_bytes();\n assert_eq(p_plus_1_converted_bytes[0], 1);\n p_plus_1_converted_bytes[0] = 0;\n assert_eq(p_plus_1_converted_bytes, [0; 32]);\n\n // checking that Field::from_le_bytes::<32> on the Field modulus produces 0\n assert_eq(modulus_le_bytes().len(), 32);\n let p = Field::from_le_bytes::<32>(modulus_le_bytes().as_array());\n assert_eq(p, 0);\n\n // checking that converting 0 to 32 LE bytes produces 32 zeroes\n let p_bytes: [u8; 32] = 0.to_le_bytes();\n assert_eq(p_bytes, [0; 32]);\n }\n }\n\n /// Convert a little endian bit array to a field element.\n /// If the provided bit array overflows the field modulus then the Field will silently wrap around.\n fn from_le_bits<let N: u32>(bits: [u1; N]) -> Field {\n static_assert(\n N <= modulus_le_bits().len(),\n "N must be less than or equal to modulus_le_bits().len()",\n );\n let mut v = 1;\n let mut result = 0;\n\n for i in 0..N {\n result += (bits[i] as Field) * v;\n v = v * 2;\n }\n result\n }\n\n /// Convert a big endian bit array to a field element.\n /// If the provided bit array overflows the field modulus then the Field will silently wrap around.\n fn from_be_bits<let N: u32>(bits: [u1; N]) -> Field {\n let mut v = 1;\n let mut result = 0;\n\n for i in 0..N {\n result += (bits[N - 1 - i] as Field) * v;\n v = v * 2;\n }\n result\n }\n\n #[test]\n fn test_to_from_be_bits_bn254_edge_cases() {\n if crate::compat::is_bn254() {\n // checking that decrementing this bit produces the expected 254 BE bits for (modulus - 1)\n let mut p_minus_1_bits: [u1; 254] = modulus_be_bits().as_array();\n assert(p_minus_1_bits[254 - 1] > 0);\n p_minus_1_bits[254 - 1] -= 1;\n\n let p_minus_1 = from_be_bits::<254>(p_minus_1_bits);\n assert_eq(p_minus_1 + 1, 0);\n\n // checking that converting (modulus - 1) from and then to 254 BE bits produces the same bits\n let p_minus_1_converted_bits: [u1; 254] = p_minus_1.to_be_bits();\n assert_eq(p_minus_1_converted_bits, p_minus_1_bits);\n\n // checking that incrementing this bit produces 254 BE bits for (modulus + 4)\n let mut p_plus_4_bits: [u1; 254] = modulus_be_bits().as_array();\n assert(p_plus_4_bits[254 - 3] < 1);\n p_plus_4_bits[254 - 3] += 1;\n\n let p_plus_4 = from_be_bits::<254>(p_plus_4_bits);\n assert_eq(p_plus_4, 4);\n\n // checking that converting p_plus_4 to 254 BE bits produces the same\n // bit set to 1 as p_plus_4_bits and otherwise zeroes\n let mut p_plus_4_converted_bits: [u1; 254] = p_plus_4.to_be_bits();\n assert_eq(p_plus_4_converted_bits[254 - 3], 1);\n p_plus_4_converted_bits[254 - 3] = 0;\n assert_eq(p_plus_4_converted_bits, [0; 254]);\n\n // checking that Field::from_be_bits::<254> on the Field modulus produces 0\n assert_eq(modulus_be_bits().len(), 254);\n let p = from_be_bits::<254>(modulus_be_bits().as_array());\n assert_eq(p, 0);\n\n // checking that converting 0 to 254 BE bytes produces 254 zeroes\n let p_bits: [u1; 254] = 0.to_be_bits();\n assert_eq(p_bits, [0; 254]);\n }\n }\n\n #[test]\n fn test_to_from_le_bits_bn254_edge_cases() {\n if crate::compat::is_bn254() {\n // checking that decrementing this bit produces the expected 254 LE bits for (modulus - 1)\n let mut p_minus_1_bits: [u1; 254] = modulus_le_bits().as_array();\n assert(p_minus_1_bits[0] > 0);\n p_minus_1_bits[0] -= 1;\n\n let p_minus_1 = from_le_bits::<254>(p_minus_1_bits);\n assert_eq(p_minus_1 + 1, 0);\n\n // checking that converting (modulus - 1) from and then to 254 BE bits produces the same bits\n let p_minus_1_converted_bits: [u1; 254] = p_minus_1.to_le_bits();\n assert_eq(p_minus_1_converted_bits, p_minus_1_bits);\n\n // checking that incrementing this bit produces 254 LE bits for (modulus + 4)\n let mut p_plus_4_bits: [u1; 254] = modulus_le_bits().as_array();\n assert(p_plus_4_bits[2] < 1);\n p_plus_4_bits[2] += 1;\n\n let p_plus_4 = from_le_bits::<254>(p_plus_4_bits);\n assert_eq(p_plus_4, 4);\n\n // checking that converting p_plus_4 to 254 LE bits produces the same\n // bit set to 1 as p_plus_4_bits and otherwise zeroes\n let mut p_plus_4_converted_bits: [u1; 254] = p_plus_4.to_le_bits();\n assert_eq(p_plus_4_converted_bits[2], 1);\n p_plus_4_converted_bits[2] = 0;\n assert_eq(p_plus_4_converted_bits, [0; 254]);\n\n // checking that Field::from_le_bits::<254> on the Field modulus produces 0\n assert_eq(modulus_le_bits().len(), 254);\n let p = from_le_bits::<254>(modulus_le_bits().as_array());\n assert_eq(p, 0);\n\n // checking that converting 0 to 254 LE bytes produces 254 zeroes\n let p_bits: [u1; 254] = 0.to_le_bits();\n assert_eq(p_bits, [0; 254]);\n }\n }\n}\n', path: "std/field/mod.nr" }, "19": { source: '// Exposed only for usage in `std::meta`\npub(crate) mod poseidon2;\n\nuse crate::default::Default;\nuse crate::embedded_curve_ops::{\n EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul, multi_scalar_mul_array_return,\n};\nuse crate::meta::derive_via;\n\n#[foreign(sha256_compression)]\n// docs:start:sha256_compression\npub fn sha256_compression(input: [u32; 16], state: [u32; 8]) -> [u32; 8] {}\n// docs:end:sha256_compression\n\n#[foreign(keccakf1600)]\n// docs:start:keccakf1600\npub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {}\n// docs:end:keccakf1600\n\npub mod keccak {\n #[deprecated("This function has been moved to std::hash::keccakf1600")]\n pub fn keccakf1600(input: [u64; 25]) -> [u64; 25] {\n super::keccakf1600(input)\n }\n}\n\n#[foreign(blake2s)]\n// docs:start:blake2s\npub fn blake2s<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake2s\n{}\n\n// docs:start:blake3\npub fn blake3<let N: u32>(input: [u8; N]) -> [u8; 32]\n// docs:end:blake3\n{\n if crate::runtime::is_unconstrained() {\n // Temporary measure while Barretenberg is main proving system.\n // Please open an issue if you\'re working on another proving system and running into problems due to this.\n crate::static_assert(\n N <= 1024,\n "Barretenberg cannot prove blake3 hashes with inputs larger than 1024 bytes",\n );\n }\n __blake3(input)\n}\n\n#[foreign(blake3)]\nfn __blake3<let N: u32>(input: [u8; N]) -> [u8; 32] {}\n\n// docs:start:pedersen_commitment\npub fn pedersen_commitment<let N: u32>(input: [Field; N]) -> EmbeddedCurvePoint {\n // docs:end:pedersen_commitment\n pedersen_commitment_with_separator(input, 0)\n}\n\n#[inline_always]\npub fn pedersen_commitment_with_separator<let N: u32>(\n input: [Field; N],\n separator: u32,\n) -> EmbeddedCurvePoint {\n let mut points = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N];\n for i in 0..N {\n // we use the unsafe version because the multi_scalar_mul will constrain the scalars.\n points[i] = from_field_unsafe(input[i]);\n }\n let generators = derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n multi_scalar_mul(generators, points)\n}\n\n// docs:start:pedersen_hash\npub fn pedersen_hash<let N: u32>(input: [Field; N]) -> Field\n// docs:end:pedersen_hash\n{\n pedersen_hash_with_separator(input, 0)\n}\n\n#[no_predicates]\npub fn pedersen_hash_with_separator<let N: u32>(input: [Field; N], separator: u32) -> Field {\n let mut scalars: [EmbeddedCurveScalar; N + 1] = [EmbeddedCurveScalar { lo: 0, hi: 0 }; N + 1];\n let mut generators: [EmbeddedCurvePoint; N + 1] =\n [EmbeddedCurvePoint::point_at_infinity(); N + 1];\n let domain_generators: [EmbeddedCurvePoint; N] =\n derive_generators("DEFAULT_DOMAIN_SEPARATOR".as_bytes(), separator);\n\n for i in 0..N {\n scalars[i] = from_field_unsafe(input[i]);\n generators[i] = domain_generators[i];\n }\n scalars[N] = EmbeddedCurveScalar { lo: N as Field, hi: 0 as Field };\n\n let length_generator: [EmbeddedCurvePoint; 1] =\n derive_generators("pedersen_hash_length".as_bytes(), 0);\n generators[N] = length_generator[0];\n multi_scalar_mul_array_return(generators, scalars, true)[0].x\n}\n\n#[field(bn254)]\n#[inline_always]\npub fn derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {\n crate::assert_constant(domain_separator_bytes);\n // TODO(https://github.com/noir-lang/noir/issues/5672): Add back assert_constant on starting_index\n __derive_generators(domain_separator_bytes, starting_index)\n}\n\n#[builtin(derive_pedersen_generators)]\n#[field(bn254)]\nfn __derive_generators<let N: u32, let M: u32>(\n domain_separator_bytes: [u8; M],\n starting_index: u32,\n) -> [EmbeddedCurvePoint; N] {}\n\n#[field(bn254)]\n// Same as from_field but:\n// does not assert the limbs are 128 bits\n// does not assert the decomposition does not overflow the EmbeddedCurveScalar\nfn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar {\n // Safety: xlo and xhi decomposition is checked below\n let (xlo, xhi) = unsafe { crate::field::bn254::decompose_hint(scalar) };\n // Check that the decomposition is correct\n assert_eq(scalar, xlo + crate::field::bn254::TWO_POW_128 * xhi);\n EmbeddedCurveScalar { lo: xlo, hi: xhi }\n}\n\npub fn poseidon2_permutation<let N: u32>(input: [Field; N], state_len: u32) -> [Field; N] {\n assert_eq(input.len(), state_len);\n poseidon2_permutation_internal(input)\n}\n\n#[foreign(poseidon2_permutation)]\nfn poseidon2_permutation_internal<let N: u32>(input: [Field; N]) -> [Field; N] {}\n\n// Generic hashing support.\n// Partially ported and impacted by rust.\n\n// Hash trait shall be implemented per type.\n#[derive_via(derive_hash)]\npub trait Hash {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher;\n}\n\n// docs:start:derive_hash\ncomptime fn derive_hash(s: TypeDefinition) -> Quoted {\n let name = quote { $crate::hash::Hash };\n let signature = quote { fn hash<H>(_self: Self, _state: &mut H) where H: $crate::hash::Hasher };\n let for_each_field = |name| quote { _self.$name.hash(_state); };\n crate::meta::make_trait_impl(\n s,\n name,\n signature,\n for_each_field,\n quote {},\n |fields| fields,\n )\n}\n// docs:end:derive_hash\n\n// Hasher trait shall be implemented by algorithms to provide hash-agnostic means.\n// TODO: consider making the types generic here ([u8], [Field], etc.)\npub trait Hasher {\n fn finish(self) -> Field;\n\n fn write(&mut self, input: Field);\n}\n\n// BuildHasher is a factory trait, responsible for production of specific Hasher.\npub trait BuildHasher {\n type H: Hasher;\n\n fn build_hasher(self) -> H;\n}\n\npub struct BuildHasherDefault<H>;\n\nimpl<H> BuildHasher for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n type H = H;\n\n fn build_hasher(_self: Self) -> H {\n H::default()\n }\n}\n\nimpl<H> Default for BuildHasherDefault<H>\nwhere\n H: Hasher + Default,\n{\n fn default() -> Self {\n BuildHasherDefault {}\n }\n}\n\nimpl Hash for Field {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self);\n }\n}\n\nimpl Hash for u1 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for u128 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for i8 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u8 as Field);\n }\n}\n\nimpl Hash for i16 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u16 as Field);\n }\n}\n\nimpl Hash for i32 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u32 as Field);\n }\n}\n\nimpl Hash for i64 {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as u64 as Field);\n }\n}\n\nimpl Hash for bool {\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n H::write(state, self as Field);\n }\n}\n\nimpl Hash for () {\n fn hash<H>(_self: Self, _state: &mut H)\n where\n H: Hasher,\n {}\n}\n\nimpl<T, let N: u32> Hash for [T; N]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<T> Hash for [T]\nwhere\n T: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.len().hash(state);\n for elem in self {\n elem.hash(state);\n }\n }\n}\n\nimpl<A, B> Hash for (A, B)\nwhere\n A: Hash,\n B: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n }\n}\n\nimpl<A, B, C> Hash for (A, B, C)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n }\n}\n\nimpl<A, B, C, D> Hash for (A, B, C, D)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n }\n}\n\nimpl<A, B, C, D, E> Hash for (A, B, C, D, E)\nwhere\n A: Hash,\n B: Hash,\n C: Hash,\n D: Hash,\n E: Hash,\n{\n fn hash<H>(self, state: &mut H)\n where\n H: Hasher,\n {\n self.0.hash(state);\n self.1.hash(state);\n self.2.hash(state);\n self.3.hash(state);\n self.4.hash(state);\n }\n}\n\n// Some test vectors for Pedersen hash and Pedersen Commitment.\n// They have been generated using the same functions so the tests are for now useless\n// but they will be useful when we switch to Noir implementation.\n#[test]\nfn assert_pedersen() {\n assert_eq(\n pedersen_hash_with_separator([1], 1),\n 0x1b3f4b1a83092a13d8d1a59f7acb62aba15e7002f4440f2275edb99ebbc2305f,\n );\n assert_eq(\n pedersen_commitment_with_separator([1], 1),\n EmbeddedCurvePoint {\n x: 0x054aa86a73cb8a34525e5bbed6e43ba1198e860f5f3950268f71df4591bde402,\n y: 0x209dcfbf2cfb57f9f6046f44d71ac6faf87254afc7407c04eb621a6287cac126,\n is_infinite: false,\n },\n );\n\n assert_eq(\n pedersen_hash_with_separator([1, 2], 2),\n 0x26691c129448e9ace0c66d11f0a16d9014a9e8498ee78f4d69f0083168188255,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2], 2),\n EmbeddedCurvePoint {\n x: 0x2e2b3b191e49541fe468ec6877721d445dcaffe41728df0a0eafeb15e87b0753,\n y: 0x2ff4482400ad3a6228be17a2af33e2bcdf41be04795f9782bd96efe7e24f8778,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3], 3),\n 0x0bc694b7a1f8d10d2d8987d07433f26bd616a2d351bc79a3c540d85b6206dbe4,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3], 3),\n EmbeddedCurvePoint {\n x: 0x1fee4e8cf8d2f527caa2684236b07c4b1bad7342c01b0f75e9a877a71827dc85,\n y: 0x2f9fedb9a090697ab69bf04c8bc15f7385b3e4b68c849c1536e5ae15ff138fd1,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4], 4),\n 0xdae10fb32a8408521803905981a2b300d6a35e40e798743e9322b223a5eddc,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4], 4),\n EmbeddedCurvePoint {\n x: 0x07ae3e202811e1fca39c2d81eabe6f79183978e6f12be0d3b8eda095b79bdbc9,\n y: 0x0afc6f892593db6fbba60f2da558517e279e0ae04f95758587760ba193145014,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5], 5),\n 0xfc375b062c4f4f0150f7100dfb8d9b72a6d28582dd9512390b0497cdad9c22,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5], 5),\n EmbeddedCurvePoint {\n x: 0x1754b12bd475a6984a1094b5109eeca9838f4f81ac89c5f0a41dbce53189bb29,\n y: 0x2da030e3cfcdc7ddad80eaf2599df6692cae0717d4e9f7bfbee8d073d5d278f7,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6], 6),\n 0x1696ed13dc2730062a98ac9d8f9de0661bb98829c7582f699d0273b18c86a572,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6], 6),\n EmbeddedCurvePoint {\n x: 0x190f6c0e97ad83e1e28da22a98aae156da083c5a4100e929b77e750d3106a697,\n y: 0x1f4b60f34ef91221a0b49756fa0705da93311a61af73d37a0c458877706616fb,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n 0x128c0ff144fc66b6cb60eeac8a38e23da52992fc427b92397a7dffd71c45ede3,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7], 7),\n EmbeddedCurvePoint {\n x: 0x015441e9d29491b06563fac16fc76abf7a9534c715421d0de85d20dbe2965939,\n y: 0x1d2575b0276f4e9087e6e07c2cb75aa1baafad127af4be5918ef8a2ef2fea8fc,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n 0x2f960e117482044dfc99d12fece2ef6862fba9242be4846c7c9a3e854325a55c,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8], 8),\n EmbeddedCurvePoint {\n x: 0x1657737676968887fceb6dd516382ea13b3a2c557f509811cd86d5d1199bc443,\n y: 0x1f39f0cb569040105fa1e2f156521e8b8e08261e635a2b210bdc94e8d6d65f77,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n 0x0c96db0790602dcb166cc4699e2d306c479a76926b81c2cb2aaa92d249ec7be7,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9], 9),\n EmbeddedCurvePoint {\n x: 0x0a3ceae42d14914a432aa60ec7fded4af7dad7dd4acdbf2908452675ec67e06d,\n y: 0xfc19761eaaf621ad4aec9a8b2e84a4eceffdba78f60f8b9391b0bd9345a2f2,\n is_infinite: false,\n },\n );\n assert_eq(\n pedersen_hash_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n 0x2cd37505871bc460a62ea1e63c7fe51149df5d0801302cf1cbc48beb8dff7e94,\n );\n assert_eq(\n pedersen_commitment_with_separator([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 10),\n EmbeddedCurvePoint {\n x: 0x2fb3f8b3d41ddde007c8c3c62550f9a9380ee546fcc639ffbb3fd30c8d8de30c,\n y: 0x300783be23c446b11a4c0fabf6c91af148937cea15fcf5fb054abf7f752ee245,\n is_infinite: false,\n },\n );\n}\n', path: "std/hash/mod.nr" }, "50": { source: '/// Funding Proof Circuit\n///\n/// Proves that a user has sufficient balance to cover a transaction\n/// without revealing the actual balance.\n///\n/// Public inputs:\n/// - commitment_hash: Hash of the Pedersen commitment to balance\n/// - minimum_required: Minimum balance required\n/// - asset_id: Asset identifier\n///\n/// Private inputs (witness):\n/// - balance: Actual user balance\n/// - blinding: Blinding factor for commitment\n///\n/// Constraints:\n/// 1. balance >= minimum_required\n/// 2. commitment = pedersen([balance, blinding])\n/// 3. commitment_hash = hash(commitment, asset_id)\n\nuse std::hash::pedersen_hash;\nuse std::hash::blake3;\n\n/// Main entry point for the funding proof circuit\n///\n/// Returns the commitment hash as a public output rather than taking it as input.\n/// This allows the SDK to verify the proof without needing to compute Pedersen hashes.\nfn main(\n // Public inputs\n minimum_required: pub u64,\n asset_id: pub Field,\n\n // Private inputs (witness)\n balance: u64,\n blinding: Field,\n) -> pub [u8; 32] {\n // Constraint 1: Balance must be at least the minimum required\n assert(balance >= minimum_required, "Insufficient balance");\n\n // Constraint 2: Compute the Pedersen commitment to (balance, blinding)\n let balance_field = balance as Field;\n let commitment = pedersen_hash([balance_field, blinding]);\n\n // Constraint 3: Compute and return the commitment hash\n // We hash: commitment || asset_id to bind the commitment to the asset\n let commitment_hash = compute_commitment_hash(commitment, asset_id);\n\n commitment_hash\n}\n\n/// Compute the commitment hash from commitment and asset_id\n/// Uses BLAKE3 for efficiency (built-in to Noir)\nfn compute_commitment_hash(commitment: Field, asset_id: Field) -> [u8; 32] {\n // Convert commitment to bytes (32 bytes, big-endian)\n let commitment_bytes: [u8; 32] = commitment.to_be_bytes();\n\n // Convert asset_id to bytes (32 bytes, big-endian)\n let asset_bytes: [u8; 32] = asset_id.to_be_bytes();\n\n // Create preimage: commitment || asset_id (64 bytes)\n let mut preimage: [u8; 64] = [0; 64];\n for i in 0..32 {\n preimage[i] = commitment_bytes[i];\n preimage[i + 32] = asset_bytes[i];\n }\n\n // Hash with BLAKE3\n blake3(preimage)\n}\n\n// --- Tests ---\n\n#[test]\nfn test_valid_funding_proof() {\n // Test case: balance = 100, minimum = 50\n let balance: u64 = 100;\n let minimum_required: u64 = 50;\n let blinding = 12345 as Field;\n let asset_id = 1 as Field;\n\n // Execute the circuit - it should return the commitment hash\n let commitment_hash = main(minimum_required, asset_id, balance, blinding);\n\n // Verify it returned a hash (not all zeros)\n let mut has_nonzero = false;\n for i in 0..32 {\n if commitment_hash[i] != 0 {\n has_nonzero = true;\n }\n }\n assert(has_nonzero, "Commitment hash should not be all zeros");\n}\n\n#[test]\nfn test_exact_balance_passes() {\n // Test case: balance exactly equals minimum\n let balance: u64 = 50;\n let minimum_required: u64 = 50;\n let blinding = 67890 as Field;\n let asset_id = 2 as Field;\n\n // Should succeed and return a hash\n let _commitment_hash = main(minimum_required, asset_id, balance, blinding);\n}\n\n#[test(should_fail_with = "Insufficient balance")]\nfn test_insufficient_balance_fails() {\n // Test case: balance < minimum should fail\n let balance: u64 = 40;\n let minimum_required: u64 = 50;\n let blinding = 11111 as Field;\n let asset_id = 1 as Field;\n\n // Should fail because balance < minimum_required\n let _commitment_hash = main(minimum_required, asset_id, balance, blinding);\n}\n\n#[test]\nfn test_different_blinding_produces_different_hash() {\n // Test that different blinding factors produce different commitment hashes\n let balance: u64 = 100;\n let minimum_required: u64 = 50;\n let blinding1 = 12345 as Field;\n let blinding2 = 99999 as Field;\n let asset_id = 1 as Field;\n\n let hash1 = main(minimum_required, asset_id, balance, blinding1);\n let hash2 = main(minimum_required, asset_id, balance, blinding2);\n\n // Hashes should be different\n let mut hashes_differ = false;\n for i in 0..32 {\n if hash1[i] != hash2[i] {\n hashes_differ = true;\n }\n }\n assert(hashes_differ, "Different blindings should produce different hashes");\n}\n', path: "/Users/rz/local-dev/circuits/funding_proof/src/main.nr" } }, expression_width: { Bounded: { width: 4 } } };
10813
11433
 
10814
11434
  // src/proofs/circuits/validity_proof.json
10815
11435
  var validity_proof_default = { noir_version: "1.0.0-beta.15+83245db91dcf63420ef4bcbbd85b98f397fee663", hash: "17105369051450454041", abi: { parameters: [{ name: "intent_hash", type: { kind: "field" }, visibility: "public" }, { name: "sender_commitment_x", type: { kind: "field" }, visibility: "public" }, { name: "sender_commitment_y", type: { kind: "field" }, visibility: "public" }, { name: "nullifier", type: { kind: "field" }, visibility: "public" }, { name: "timestamp", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "expiry", type: { kind: "integer", sign: "unsigned", width: 64 }, visibility: "public" }, { name: "sender_address", type: { kind: "field" }, visibility: "private" }, { name: "sender_blinding", type: { kind: "field" }, visibility: "private" }, { name: "sender_secret", type: { kind: "field" }, visibility: "private" }, { name: "pub_key_x", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "pub_key_y", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "signature", type: { kind: "array", length: 64, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "message_hash", type: { kind: "array", length: 32, type: { kind: "integer", sign: "unsigned", width: 8 } }, visibility: "private" }, { name: "nonce", type: { kind: "field" }, visibility: "private" }], return_type: null, error_types: { "4743545721632785176": { error_kind: "string", string: "Nullifier mismatch" }, "4924752953922582949": { error_kind: "string", string: "Invalid ECDSA signature" }, "5940733937471987676": { error_kind: "string", string: "Intent expired" }, "9872184990886929843": { error_kind: "string", string: "Sender commitment X mismatch" }, "14620555433709191364": { error_kind: "string", string: "Sender commitment Y mismatch" }, "15764276373176857197": { error_kind: "string", string: "Stack too deep" } } }, bytecode: "H4sIAAAAAAAA/+WZaXBV5QGGz81CAwTCTogsF2XfJEBQBCFAQjAqIETZQgIkAYJmXyCIkMgaUEgENxBli8SQlEpCCAK1MsVWLNPptCMdxyl1xlI7Tqm1QwdoO9O85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mLGGsIqK0kNAJCjgAmjzCWJBDGaV2zCUA/b8KZ7CYKWUk2ih/kaFHZrhIRc4hicfkox2GBcsVVIlinZ8LiQP+D4IOUBgQKOQKWENpJXgKYRSDo5U0EN/eI4HWFGykvYU4JDVk3CnmJGOY2Y5bNfp1VSAVEwLk6gs1WB9q3W1UR8Vqv+gcC3ka81K2K4Yxa6gMjxBqEAS0FYlJy1iGe/QqifxeB+ZZXym+AZ9+lmkJHREksRDIrwme6a/f9tJ7SwGEae9JM5gxXNgv0UFhROO53LHguXRYCu8VC5K3yfKdFAP40C4mLbOUNnywLJBorGicaLxqeEO/miWyIR0bNfxMWQAQUwbBw43BMfbsbOvaIfb6Me3Ew3Z5/n+SJDKqn6bjvDpep42AsptV0/UhnjPHzxgH7Aw==", file_map: { "14": { source: "// docs:start:ecdsa_secp256k1\n/// Verifies a ECDSA signature over the secp256k1 curve.\n/// - inputs:\n/// - x coordinate of public key as 32 bytes\n/// - y coordinate of public key as 32 bytes\n/// - the signature, as a 64 bytes array\n/// The signature internally will be represented as `(r, s)`,\n/// where `r` and `s` are fixed-sized big endian scalar values.\n/// As the `secp256k1` has a 256-bit modulus, we have a 64 byte signature\n/// while `r` and `s` will both be 32 bytes.\n/// We expect `s` to be normalized. This means given the curve's order,\n/// `s` should be less than or equal to `order / 2`.\n/// This is done to prevent malleability.\n/// For more context regarding malleability you can reference BIP 0062.\n/// - the hash of the message, as a vector of bytes\n/// - output: false for failure and true for success\npub fn verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n) -> bool\n// docs:end:ecdsa_secp256k1\n{\n _verify_signature(public_key_x, public_key_y, signature, message_hash, true)\n}\n\n#[foreign(ecdsa_secp256k1)]\npub fn _verify_signature(\n public_key_x: [u8; 32],\n public_key_y: [u8; 32],\n signature: [u8; 64],\n message_hash: [u8; 32],\n predicate: bool,\n) -> bool {}\n", path: "std/ecdsa_secp256k1.nr" }, "16": { source: "use crate::cmp::Eq;\nuse crate::hash::Hash;\nuse crate::ops::arith::{Add, Neg, Sub};\n\n/// A point on the embedded elliptic curve\n/// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field.\n/// x and y denotes the Weierstrass coordinates of the point, if is_infinite is false.\npub struct EmbeddedCurvePoint {\n pub x: Field,\n pub y: Field,\n pub is_infinite: bool,\n}\n\nimpl EmbeddedCurvePoint {\n /// Elliptic curve point doubling operation\n /// returns the doubled point of a point P, i.e P+P\n pub fn double(self) -> EmbeddedCurvePoint {\n embedded_curve_add(self, self)\n }\n\n /// Returns the null element of the curve; 'the point at infinity'\n pub fn point_at_infinity() -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: 0, y: 0, is_infinite: true }\n }\n\n /// Returns the curve's generator point.\n pub fn generator() -> EmbeddedCurvePoint {\n // Generator point for the grumpkin curve (y^2 = x^3 - 17)\n EmbeddedCurvePoint {\n x: 1,\n y: 17631683881184975370165255887551781615748388533673675138860, // sqrt(-16)\n is_infinite: false,\n }\n }\n}\n\nimpl Add for EmbeddedCurvePoint {\n /// Adds two points P+Q, using the curve addition formula, and also handles point at infinity\n fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n embedded_curve_add(self, other)\n }\n}\n\nimpl Sub for EmbeddedCurvePoint {\n /// Points subtraction operation, using addition and negation\n fn sub(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint {\n self + other.neg()\n }\n}\n\nimpl Neg for EmbeddedCurvePoint {\n /// Negates a point P, i.e returns -P, by negating the y coordinate.\n /// If the point is at infinity, then the result is also at infinity.\n fn neg(self) -> EmbeddedCurvePoint {\n EmbeddedCurvePoint { x: self.x, y: -self.y, is_infinite: self.is_infinite }\n }\n}\n\nimpl Eq for EmbeddedCurvePoint {\n /// Checks whether two points are equal\n fn eq(self: Self, b: EmbeddedCurvePoint) -> bool {\n (self.is_infinite & b.is_infinite)\n | ((self.is_infinite == b.is_infinite) & (self.x == b.x) & (self.y == b.y))\n }\n}\n\nimpl Hash for EmbeddedCurvePoint {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n if self.is_infinite {\n self.is_infinite.hash(state);\n } else {\n self.x.hash(state);\n self.y.hash(state);\n }\n }\n}\n\n/// Scalar for the embedded curve represented as low and high limbs\n/// By definition, the scalar field of the embedded curve is base field of the proving system curve.\n/// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs.\npub struct EmbeddedCurveScalar {\n pub lo: Field,\n pub hi: Field,\n}\n\nimpl EmbeddedCurveScalar {\n pub fn new(lo: Field, hi: Field) -> Self {\n EmbeddedCurveScalar { lo, hi }\n }\n\n #[field(bn254)]\n pub fn from_field(scalar: Field) -> EmbeddedCurveScalar {\n let (a, b) = crate::field::bn254::decompose(scalar);\n EmbeddedCurveScalar { lo: a, hi: b }\n }\n\n //Bytes to scalar: take the first (after the specified offset) 16 bytes of the input as the lo value, and the next 16 bytes as the hi value\n #[field(bn254)]\n pub(crate) fn from_bytes(bytes: [u8; 64], offset: u32) -> EmbeddedCurveScalar {\n let mut v = 1;\n let mut lo = 0 as Field;\n let mut hi = 0 as Field;\n for i in 0..16 {\n lo = lo + (bytes[offset + 31 - i] as Field) * v;\n hi = hi + (bytes[offset + 15 - i] as Field) * v;\n v = v * 256;\n }\n let sig_s = crate::embedded_curve_ops::EmbeddedCurveScalar { lo, hi };\n sig_s\n }\n}\n\nimpl Eq for EmbeddedCurveScalar {\n fn eq(self, other: Self) -> bool {\n (other.hi == self.hi) & (other.lo == self.lo)\n }\n}\n\nimpl Hash for EmbeddedCurveScalar {\n fn hash<H>(self, state: &mut H)\n where\n H: crate::hash::Hasher,\n {\n self.hi.hash(state);\n self.lo.hash(state);\n }\n}\n\n// Computes a multi scalar multiplication over the embedded curve.\n// For bn254, We have Grumpkin and Baby JubJub.\n// For bls12-381, we have JubJub and Bandersnatch.\n//\n// The embedded curve being used is decided by the\n// underlying proof system.\n// docs:start:multi_scalar_mul\npub fn multi_scalar_mul<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n) -> EmbeddedCurvePoint\n// docs:end:multi_scalar_mul\n{\n multi_scalar_mul_array_return(points, scalars, true)[0]\n}\n\n#[foreign(multi_scalar_mul)]\npub(crate) fn multi_scalar_mul_array_return<let N: u32>(\n points: [EmbeddedCurvePoint; N],\n scalars: [EmbeddedCurveScalar; N],\n predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n// docs:start:fixed_base_scalar_mul\npub fn fixed_base_scalar_mul(scalar: EmbeddedCurveScalar) -> EmbeddedCurvePoint\n// docs:end:fixed_base_scalar_mul\n{\n multi_scalar_mul([EmbeddedCurvePoint::generator()], [scalar])\n}\n\n/// This function only assumes that the points are on the curve\n/// It handles corner cases around the infinity point causing some overhead compared to embedded_curve_add_not_nul and embedded_curve_add_unsafe\n// docs:start:embedded_curve_add\npub fn embedded_curve_add(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n // docs:end:embedded_curve_add\n if crate::runtime::is_unconstrained() {\n // `embedded_curve_add_unsafe` requires the inputs not to be the infinity point, so we check it here.\n // This is because `embedded_curve_add_unsafe` uses the `embedded_curve_add` opcode.\n // For efficiency, the backend does not check the inputs for the infinity point, but it assumes that they are not the infinity point\n // so that it can apply the ec addition formula directly.\n if point1.is_infinite {\n point2\n } else if point2.is_infinite {\n point1\n } else {\n embedded_curve_add_unsafe(point1, point2)\n }\n } else {\n // In a constrained context, we also need to check the inputs are not the infinity point because we also use `embedded_curve_add_unsafe`\n // However we also need to identify the case where the two inputs are the same, because then\n // the addition formula does not work and we need to use the doubling formula instead.\n // In unconstrained context, we can check directly if the input values are the same when solving the opcode, so it is not an issue.\n\n // x_coordinates_match is true if both abscissae are the same\n let x_coordinates_match = point1.x == point2.x;\n // y_coordinates_match is true if both ordinates are the same\n let y_coordinates_match = point1.y == point2.y;\n // double_predicate is true if both abscissae and ordinates are the same\n let double_predicate = (x_coordinates_match & y_coordinates_match);\n // If the abscissae are the same, but not the ordinates, then one point is the opposite of the other\n let infinity_predicate = (x_coordinates_match & !y_coordinates_match);\n\n // `embedded_curve_add_unsafe` would not perform doubling, even if the inputs point1 and point2 are the same, because it cannot know this without adding some logic (and some constraints)\n // However we did this logic when we computed `double_predicate`, so we set the result to 2*point1 if point1 and point2 are the same\n let mut result = if double_predicate {\n // `embedded_curve_add_unsafe` is doing a doubling if the input is the same variable, because in this case it is guaranteed (at 'compile time') that the input is the same.\n embedded_curve_add_unsafe(point1, point1)\n } else {\n let point1_1 = EmbeddedCurvePoint {\n x: point1.x + (x_coordinates_match as Field),\n y: point1.y,\n is_infinite: false,\n };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n // point1_1 is guaranteed to have a different abscissa than point2:\n // - if x_coordinates_match is 0, that means point1.x != point2.x, and point1_1.x = point1.x + 0\n // - if x_coordinates_match is 1, that means point1.x = point2.x, but point1_1.x = point1.x + 1 in this case\n // Because the abscissa is different, the addition formula is guaranteed to succeed, so we can safely use `embedded_curve_add_unsafe`\n // Note that this computation may be garbage: if x_coordinates_match is 1, or if one of the input is the point at infinity.\n // therefore we only want to do this if we need the result, otherwise it needs to be eliminated as a dead instruction, lest we want the circuit to fail.\n embedded_curve_add_unsafe(point1_1, point2_1)\n };\n\n // Same logic as above for unconstrained context, we set the proper result when one of the inputs is the infinity point\n if point1.is_infinite {\n result = point2;\n }\n if point2.is_infinite {\n result = point1;\n }\n\n // Finally, we set the is_infinity flag of the result:\n // Opposite points should sum into the infinity point, however, if one of them is point at infinity, their coordinates are not meaningful\n // so we should not use the fact that the inputs are opposite in this case:\n let mut result_is_infinity =\n infinity_predicate & (!point1.is_infinite & !point2.is_infinite);\n // However, if both of them are at infinity, then the result is also at infinity\n result.is_infinite = result_is_infinity | (point1.is_infinite & point2.is_infinite);\n result\n }\n}\n\n#[foreign(embedded_curve_add)]\nfn embedded_curve_add_array_return(\n _point1: EmbeddedCurvePoint,\n _point2: EmbeddedCurvePoint,\n _predicate: bool,\n) -> [EmbeddedCurvePoint; 1] {}\n\n/// This function assumes that:\n/// The points are on the curve, and\n/// The points don't share an x-coordinate, and\n/// Neither point is the infinity point.\n/// If it is used with correct input, the function ensures the correct non-zero result is returned.\n/// Except for points on the curve, the other assumptions are checked by the function. It will cause assertion failure if they are not respected.\npub fn embedded_curve_add_not_nul(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n assert(point1.x != point2.x);\n assert(!point1.is_infinite);\n assert(!point2.is_infinite);\n // Ensure is_infinite is comptime\n let point1_1 = EmbeddedCurvePoint { x: point1.x, y: point1.y, is_infinite: false };\n let point2_1 = EmbeddedCurvePoint { x: point2.x, y: point2.y, is_infinite: false };\n embedded_curve_add_unsafe(point1_1, point2_1)\n}\n\n/// Unsafe ec addition\n/// If the inputs are the same, it will perform a doubling, but only if point1 and point2 are the same variable.\n/// If they have the same value but are different variables, the result will be incorrect because in this case\n/// it assumes (but does not check) that the points' x-coordinates are not equal.\n/// It also assumes neither point is the infinity point.\npub fn embedded_curve_add_unsafe(\n point1: EmbeddedCurvePoint,\n point2: EmbeddedCurvePoint,\n) -> EmbeddedCurvePoint {\n embedded_curve_add_array_return(point1, point2, true)[0]\n}\n", path: "std/embedded_curve_ops.nr" }, "17": { source: `use crate::field::field_less_than;
@@ -11489,6 +12109,9 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11489
12109
  framework = "noir";
11490
12110
  _isReady = false;
11491
12111
  config;
12112
+ // Mobile device info (cached)
12113
+ deviceInfo = null;
12114
+ wasmCompatibility = null;
11492
12115
  // Circuit instances
11493
12116
  fundingNoir = null;
11494
12117
  fundingBackend = null;
@@ -11500,17 +12123,25 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11500
12123
  worker = null;
11501
12124
  workerPending = /* @__PURE__ */ new Map();
11502
12125
  constructor(config = {}) {
12126
+ this.deviceInfo = getMobileDeviceInfo();
12127
+ const isMobile = this.deviceInfo.isMobile;
12128
+ const defaultTimeout = isMobile ? 12e4 : 6e4;
11503
12129
  this.config = {
11504
12130
  useWorker: config.useWorker ?? true,
11505
12131
  verbose: config.verbose ?? false,
11506
12132
  oraclePublicKey: config.oraclePublicKey ?? void 0,
11507
- timeout: config.timeout ?? 6e4
12133
+ timeout: config.timeout ?? defaultTimeout,
12134
+ mobileMode: config.mobileMode ?? isMobile,
12135
+ forceInitialize: config.forceInitialize ?? false
11508
12136
  };
11509
12137
  if (!isBrowser()) {
11510
12138
  console.warn(
11511
12139
  "[BrowserNoirProvider] Not running in browser environment. Consider using NoirProofProvider for Node.js."
11512
12140
  );
11513
12141
  }
12142
+ if (this.config.verbose && this.deviceInfo) {
12143
+ console.log("[BrowserNoirProvider] Device info:", this.deviceInfo);
12144
+ }
11514
12145
  }
11515
12146
  get isReady() {
11516
12147
  return this._isReady;
@@ -11540,6 +12171,67 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11540
12171
  missing
11541
12172
  };
11542
12173
  }
12174
+ /**
12175
+ * Get detailed mobile device information
12176
+ */
12177
+ static getMobileInfo() {
12178
+ return getMobileDeviceInfo();
12179
+ }
12180
+ /**
12181
+ * Check mobile WASM compatibility
12182
+ *
12183
+ * Returns detailed compatibility information including:
12184
+ * - Feature support (WASM, SharedArrayBuffer, Workers, SIMD)
12185
+ * - Compatibility score (0-100)
12186
+ * - Issues and recommendations
12187
+ *
12188
+ * @example
12189
+ * ```typescript
12190
+ * const compat = BrowserNoirProvider.checkMobileCompatibility()
12191
+ * if (compat.score < 70) {
12192
+ * console.warn('Limited mobile support:', compat.issues)
12193
+ * }
12194
+ * ```
12195
+ */
12196
+ static checkMobileCompatibility() {
12197
+ return checkMobileWASMCompatibility();
12198
+ }
12199
+ /**
12200
+ * Check if the current device is mobile
12201
+ */
12202
+ static isMobile() {
12203
+ return getMobileDeviceInfo().isMobile;
12204
+ }
12205
+ /**
12206
+ * Get recommended configuration for the current device
12207
+ *
12208
+ * Automatically adjusts settings based on device capabilities:
12209
+ * - Mobile devices get longer timeouts
12210
+ * - Low-memory devices disable workers
12211
+ * - Tablets get intermediate settings
12212
+ */
12213
+ static getRecommendedConfig() {
12214
+ const deviceInfo = getMobileDeviceInfo();
12215
+ const compat = checkMobileWASMCompatibility();
12216
+ const config = {};
12217
+ if (deviceInfo.isMobile) {
12218
+ config.timeout = 12e4;
12219
+ config.mobileMode = true;
12220
+ if (deviceInfo.deviceMemoryGB !== null && deviceInfo.deviceMemoryGB < 2) {
12221
+ config.useWorker = false;
12222
+ }
12223
+ if (deviceInfo.platform === "ios" && deviceInfo.browser === "safari") {
12224
+ config.useWorker = compat.sharedArrayBuffer;
12225
+ }
12226
+ } else if (deviceInfo.isTablet) {
12227
+ config.timeout = 9e4;
12228
+ config.mobileMode = true;
12229
+ }
12230
+ if (compat.score < 50) {
12231
+ config.forceInitialize = false;
12232
+ }
12233
+ return config;
12234
+ }
11543
12235
  /**
11544
12236
  * Derive secp256k1 public key coordinates from a private key
11545
12237
  */
@@ -11549,6 +12241,18 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11549
12241
  const y = Array.from(uncompressedPubKey.slice(33, 65));
11550
12242
  return { x, y };
11551
12243
  }
12244
+ /**
12245
+ * Get the cached WASM compatibility info (available after construction)
12246
+ */
12247
+ getWASMCompatibility() {
12248
+ return this.wasmCompatibility;
12249
+ }
12250
+ /**
12251
+ * Get the cached device info (available after construction)
12252
+ */
12253
+ getDeviceInfo() {
12254
+ return this.deviceInfo;
12255
+ }
11552
12256
  /**
11553
12257
  * Initialize the browser provider
11554
12258
  *
@@ -11561,8 +12265,18 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11561
12265
  if (this._isReady) {
11562
12266
  return;
11563
12267
  }
12268
+ this.wasmCompatibility = checkMobileWASMCompatibility();
12269
+ if (this.config.verbose) {
12270
+ console.log("[BrowserNoirProvider] WASM compatibility:", this.wasmCompatibility);
12271
+ }
12272
+ if (this.wasmCompatibility.score < 50 && !this.config.forceInitialize) {
12273
+ throw new ProofError(
12274
+ `Device has poor WASM compatibility (score: ${this.wasmCompatibility.score}). Issues: ${this.wasmCompatibility.issues.join(", ")}. Set forceInitialize: true to override.`,
12275
+ "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
12276
+ );
12277
+ }
11564
12278
  const { supported, missing } = _BrowserNoirProvider.checkBrowserSupport();
11565
- if (!supported) {
12279
+ if (!supported && !this.config.forceInitialize) {
11566
12280
  throw new ProofError(
11567
12281
  `Browser missing required features: ${missing.join(", ")}`,
11568
12282
  "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
@@ -11626,8 +12340,69 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11626
12340
  * Initialize Web Worker for off-main-thread proof generation
11627
12341
  */
11628
12342
  async initializeWorker() {
11629
- if (this.config.verbose) {
11630
- console.log("[BrowserNoirProvider] Worker support: using async main-thread");
12343
+ if (!supportsWebWorkers()) {
12344
+ if (this.config.verbose) {
12345
+ console.log("[BrowserNoirProvider] Web Workers not supported, using main thread");
12346
+ }
12347
+ return;
12348
+ }
12349
+ try {
12350
+ const workerCode = this.getWorkerCode();
12351
+ const blob = new Blob([workerCode], { type: "application/javascript" });
12352
+ const workerURL = URL.createObjectURL(blob);
12353
+ this.worker = new Worker(workerURL, { type: "module" });
12354
+ this.worker.onmessage = (event) => {
12355
+ this.handleWorkerMessage(event.data);
12356
+ };
12357
+ this.worker.onerror = (error) => {
12358
+ console.error("[BrowserNoirProvider] Worker error:", error);
12359
+ for (const [id, { reject }] of this.workerPending) {
12360
+ reject(new Error(`Worker error: ${error.message}`));
12361
+ this.workerPending.delete(id);
12362
+ }
12363
+ this.worker?.terminate();
12364
+ this.worker = null;
12365
+ };
12366
+ URL.revokeObjectURL(workerURL);
12367
+ if (this.config.verbose) {
12368
+ console.log("[BrowserNoirProvider] Web Worker initialized successfully");
12369
+ }
12370
+ } catch (error) {
12371
+ if (this.config.verbose) {
12372
+ console.warn("[BrowserNoirProvider] Failed to initialize worker, using main thread:", error);
12373
+ }
12374
+ this.worker = null;
12375
+ }
12376
+ }
12377
+ /**
12378
+ * Get inline worker code for bundler compatibility
12379
+ */
12380
+ getWorkerCode() {
12381
+ return `
12382
+ self.onmessage = async function(event) {
12383
+ const { id, type } = event.data;
12384
+ // Signal that worker received message but proof gen happens on main thread
12385
+ self.postMessage({ id, type: 'fallback', message: 'Worker initialized, using main thread for proofs' });
12386
+ };
12387
+ `;
12388
+ }
12389
+ /**
12390
+ * Handle messages from worker
12391
+ */
12392
+ handleWorkerMessage(data) {
12393
+ const pending = this.workerPending.get(data.id);
12394
+ if (!pending) return;
12395
+ switch (data.type) {
12396
+ case "success":
12397
+ this.workerPending.delete(data.id);
12398
+ pending.resolve(data.result);
12399
+ break;
12400
+ case "error":
12401
+ this.workerPending.delete(data.id);
12402
+ pending.reject(new Error(data.error));
12403
+ break;
12404
+ case "fallback":
12405
+ break;
11631
12406
  }
11632
12407
  }
11633
12408
  /**
@@ -11649,15 +12424,10 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11649
12424
  percent: 10,
11650
12425
  message: "Preparing witness inputs..."
11651
12426
  });
11652
- const { commitmentHash, blindingField } = await this.computeCommitmentHash(
11653
- params.balance,
11654
- params.blindingFactor,
11655
- params.assetId
11656
- );
12427
+ const blindingField = this.bytesToField(params.blindingFactor);
11657
12428
  const witnessInputs = {
11658
- commitment_hash: commitmentHash,
11659
12429
  minimum_required: params.minimumRequired.toString(),
11660
- asset_id: this.assetIdToField(params.assetId),
12430
+ asset_id: `0x${this.assetIdToField(params.assetId)}`,
11661
12431
  balance: params.balance.toString(),
11662
12432
  blinding: blindingField
11663
12433
  };
@@ -11666,7 +12436,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11666
12436
  percent: 30,
11667
12437
  message: "Generating witness..."
11668
12438
  });
11669
- const { witness } = await this.fundingNoir.execute(witnessInputs);
12439
+ const { witness, returnValue } = await this.fundingNoir.execute(witnessInputs);
11670
12440
  onProgress?.({
11671
12441
  stage: "proving",
11672
12442
  percent: 50,
@@ -11678,10 +12448,12 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
11678
12448
  percent: 100,
11679
12449
  message: "Proof generated successfully"
11680
12450
  });
12451
+ const commitmentHashBytes = returnValue;
12452
+ const commitmentHashHex = bytesToHex7(new Uint8Array(commitmentHashBytes));
11681
12453
  const publicInputs = [
11682
- `0x${commitmentHash}`,
11683
12454
  `0x${params.minimumRequired.toString(16).padStart(16, "0")}`,
11684
- `0x${this.assetIdToField(params.assetId)}`
12455
+ `0x${this.assetIdToField(params.assetId)}`,
12456
+ `0x${commitmentHashHex}`
11685
12457
  ];
11686
12458
  const proof = {
11687
12459
  type: "funding",
@@ -12083,6 +12855,314 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12083
12855
  return { x, y };
12084
12856
  }
12085
12857
  };
12858
+
12859
+ // src/proofs/worker.ts
12860
+ function createWorkerBlobURL() {
12861
+ const workerCode = `
12862
+ // Proof Generation Worker
12863
+ // This code runs in a separate thread
12864
+
12865
+ let fundingNoir = null;
12866
+ let fundingBackend = null;
12867
+ let validityNoir = null;
12868
+ let validityBackend = null;
12869
+ let fulfillmentNoir = null;
12870
+ let fulfillmentBackend = null;
12871
+ let isReady = false;
12872
+ let config = { verbose: false };
12873
+
12874
+ // Helper to send progress updates
12875
+ function sendProgress(id, stage, percent, message) {
12876
+ self.postMessage({
12877
+ id,
12878
+ type: 'progress',
12879
+ progress: { stage, percent, message }
12880
+ });
12881
+ }
12882
+
12883
+ // Helper to send error
12884
+ function sendError(id, error) {
12885
+ self.postMessage({
12886
+ id,
12887
+ type: 'error',
12888
+ error: error.message || String(error)
12889
+ });
12890
+ }
12891
+
12892
+ // Helper to send success
12893
+ function sendSuccess(id, result) {
12894
+ self.postMessage({
12895
+ id,
12896
+ type: 'success',
12897
+ result
12898
+ });
12899
+ }
12900
+
12901
+ // Initialize circuits (called once)
12902
+ async function initialize(id, initConfig) {
12903
+ try {
12904
+ sendProgress(id, 'initializing', 10, 'Loading Noir JS...');
12905
+
12906
+ // Dynamic imports for Noir
12907
+ const { Noir } = await import('@noir-lang/noir_js');
12908
+ const { UltraHonkBackend } = await import('@aztec/bb.js');
12909
+
12910
+ sendProgress(id, 'initializing', 30, 'Loading circuit artifacts...');
12911
+
12912
+ // Load circuit artifacts
12913
+ const [fundingArtifact, validityArtifact, fulfillmentArtifact] = await Promise.all([
12914
+ fetch(new URL('./circuits/funding_proof.json', import.meta.url)).then(r => r.json()),
12915
+ fetch(new URL('./circuits/validity_proof.json', import.meta.url)).then(r => r.json()),
12916
+ fetch(new URL('./circuits/fulfillment_proof.json', import.meta.url)).then(r => r.json()),
12917
+ ]);
12918
+
12919
+ sendProgress(id, 'initializing', 50, 'Initializing backends...');
12920
+
12921
+ // Initialize Noir instances
12922
+ fundingNoir = new Noir(fundingArtifact);
12923
+ fundingBackend = new UltraHonkBackend(fundingArtifact.bytecode);
12924
+
12925
+ sendProgress(id, 'initializing', 70, 'Initializing validity circuit...');
12926
+ validityNoir = new Noir(validityArtifact);
12927
+ validityBackend = new UltraHonkBackend(validityArtifact.bytecode);
12928
+
12929
+ sendProgress(id, 'initializing', 90, 'Initializing fulfillment circuit...');
12930
+ fulfillmentNoir = new Noir(fulfillmentArtifact);
12931
+ fulfillmentBackend = new UltraHonkBackend(fulfillmentArtifact.bytecode);
12932
+
12933
+ config = initConfig || { verbose: false };
12934
+ isReady = true;
12935
+
12936
+ sendProgress(id, 'complete', 100, 'Worker initialized');
12937
+ sendSuccess(id, { initialized: true });
12938
+ } catch (error) {
12939
+ sendError(id, error);
12940
+ }
12941
+ }
12942
+
12943
+ // Generate funding proof
12944
+ async function generateFundingProof(id, params) {
12945
+ if (!isReady) {
12946
+ sendError(id, new Error('Worker not initialized'));
12947
+ return;
12948
+ }
12949
+
12950
+ try {
12951
+ sendProgress(id, 'witness', 20, 'Preparing witness...');
12952
+
12953
+ // Convert blinding factor to field
12954
+ const blindingField = bytesToField(params.blindingFactor);
12955
+
12956
+ const witnessInputs = {
12957
+ minimum_required: params.minimumRequired.toString(),
12958
+ asset_id: '0x' + assetIdToField(params.assetId),
12959
+ balance: params.balance.toString(),
12960
+ blinding: blindingField,
12961
+ };
12962
+
12963
+ sendProgress(id, 'witness', 40, 'Executing circuit...');
12964
+ const { witness, returnValue } = await fundingNoir.execute(witnessInputs);
12965
+
12966
+ sendProgress(id, 'proving', 60, 'Generating proof...');
12967
+ const proofData = await fundingBackend.generateProof(witness);
12968
+
12969
+ sendProgress(id, 'complete', 100, 'Proof generated');
12970
+
12971
+ // Extract commitment hash from return value
12972
+ const commitmentHashHex = bytesToHex(new Uint8Array(returnValue));
12973
+
12974
+ const publicInputs = [
12975
+ '0x' + params.minimumRequired.toString(16).padStart(16, '0'),
12976
+ '0x' + assetIdToField(params.assetId),
12977
+ '0x' + commitmentHashHex,
12978
+ ];
12979
+
12980
+ const proof = {
12981
+ type: 'funding',
12982
+ proof: '0x' + bytesToHex(proofData.proof),
12983
+ publicInputs,
12984
+ };
12985
+
12986
+ sendSuccess(id, { proof, publicInputs });
12987
+ } catch (error) {
12988
+ sendError(id, error);
12989
+ }
12990
+ }
12991
+
12992
+ // Helper functions
12993
+ function bytesToField(bytes) {
12994
+ let result = 0n;
12995
+ const len = Math.min(bytes.length, 31);
12996
+ for (let i = 0; i < len; i++) {
12997
+ result = result * 256n + BigInt(bytes[i]);
12998
+ }
12999
+ return result.toString();
13000
+ }
13001
+
13002
+ function assetIdToField(assetId) {
13003
+ if (assetId.startsWith('0x')) {
13004
+ return assetId.slice(2).padStart(64, '0');
13005
+ }
13006
+ const encoder = new TextEncoder();
13007
+ const bytes = encoder.encode(assetId);
13008
+ let result = 0n;
13009
+ for (let i = 0; i < bytes.length && i < 31; i++) {
13010
+ result = result * 256n + BigInt(bytes[i]);
13011
+ }
13012
+ return result.toString(16).padStart(64, '0');
13013
+ }
13014
+
13015
+ function bytesToHex(bytes) {
13016
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
13017
+ }
13018
+
13019
+ // Message handler
13020
+ self.onmessage = async function(event) {
13021
+ const { id, type, params, config: initConfig } = event.data;
13022
+
13023
+ switch (type) {
13024
+ case 'init':
13025
+ await initialize(id, initConfig);
13026
+ break;
13027
+ case 'generateFundingProof':
13028
+ await generateFundingProof(id, params);
13029
+ break;
13030
+ case 'generateValidityProof':
13031
+ // TODO: Implement
13032
+ sendError(id, new Error('Validity proof not yet implemented in worker'));
13033
+ break;
13034
+ case 'generateFulfillmentProof':
13035
+ // TODO: Implement
13036
+ sendError(id, new Error('Fulfillment proof not yet implemented in worker'));
13037
+ break;
13038
+ case 'destroy':
13039
+ // Cleanup
13040
+ fundingNoir = null;
13041
+ fundingBackend = null;
13042
+ validityNoir = null;
13043
+ validityBackend = null;
13044
+ fulfillmentNoir = null;
13045
+ fulfillmentBackend = null;
13046
+ isReady = false;
13047
+ sendSuccess(id, { destroyed: true });
13048
+ break;
13049
+ default:
13050
+ sendError(id, new Error('Unknown message type: ' + type));
13051
+ }
13052
+ };
13053
+ `;
13054
+ const blob = new Blob([workerCode], { type: "application/javascript" });
13055
+ return URL.createObjectURL(blob);
13056
+ }
13057
+ var ProofWorker = class _ProofWorker {
13058
+ worker = null;
13059
+ pendingRequests = /* @__PURE__ */ new Map();
13060
+ _isReady = false;
13061
+ requestCounter = 0;
13062
+ /**
13063
+ * Check if Web Workers are supported
13064
+ */
13065
+ static isSupported() {
13066
+ return typeof Worker !== "undefined" && typeof Blob !== "undefined";
13067
+ }
13068
+ /**
13069
+ * Check if worker is initialized and ready
13070
+ */
13071
+ get isReady() {
13072
+ return this._isReady;
13073
+ }
13074
+ /**
13075
+ * Initialize the worker
13076
+ */
13077
+ async initialize(config) {
13078
+ if (this._isReady) {
13079
+ return;
13080
+ }
13081
+ if (!_ProofWorker.isSupported()) {
13082
+ throw new Error("Web Workers not supported in this environment");
13083
+ }
13084
+ const workerURL = createWorkerBlobURL();
13085
+ this.worker = new Worker(workerURL, { type: "module" });
13086
+ this.worker.onmessage = (event) => {
13087
+ this.handleWorkerMessage(event.data);
13088
+ };
13089
+ this.worker.onerror = (error) => {
13090
+ console.error("[ProofWorker] Worker error:", error);
13091
+ for (const [id, { reject }] of this.pendingRequests) {
13092
+ reject(new Error(`Worker error: ${error.message}`));
13093
+ this.pendingRequests.delete(id);
13094
+ }
13095
+ };
13096
+ await this.sendRequest("init", void 0, config);
13097
+ this._isReady = true;
13098
+ URL.revokeObjectURL(workerURL);
13099
+ }
13100
+ /**
13101
+ * Generate a proof using the worker
13102
+ */
13103
+ async generateProof(type, params, onProgress) {
13104
+ if (!this._isReady || !this.worker) {
13105
+ throw new Error("Worker not initialized. Call initialize() first.");
13106
+ }
13107
+ const messageType = type === "funding" ? "generateFundingProof" : type === "validity" ? "generateValidityProof" : "generateFulfillmentProof";
13108
+ return this.sendRequest(messageType, params, void 0, onProgress);
13109
+ }
13110
+ /**
13111
+ * Destroy the worker and free resources
13112
+ */
13113
+ async destroy() {
13114
+ if (this.worker) {
13115
+ try {
13116
+ await this.sendRequest("destroy");
13117
+ } catch {
13118
+ }
13119
+ this.worker.terminate();
13120
+ this.worker = null;
13121
+ }
13122
+ this._isReady = false;
13123
+ this.pendingRequests.clear();
13124
+ }
13125
+ /**
13126
+ * Send a request to the worker
13127
+ */
13128
+ sendRequest(type, params, config, onProgress) {
13129
+ return new Promise((resolve, reject) => {
13130
+ if (!this.worker) {
13131
+ reject(new Error("Worker not available"));
13132
+ return;
13133
+ }
13134
+ const id = `req_${++this.requestCounter}_${Date.now()}`;
13135
+ this.pendingRequests.set(id, { resolve, reject, onProgress });
13136
+ const request = { id, type, params, config };
13137
+ this.worker.postMessage(request);
13138
+ });
13139
+ }
13140
+ /**
13141
+ * Handle messages from the worker
13142
+ */
13143
+ handleWorkerMessage(response) {
13144
+ const pending = this.pendingRequests.get(response.id);
13145
+ if (!pending) {
13146
+ console.warn("[ProofWorker] Received response for unknown request:", response.id);
13147
+ return;
13148
+ }
13149
+ switch (response.type) {
13150
+ case "success":
13151
+ this.pendingRequests.delete(response.id);
13152
+ pending.resolve(response.result);
13153
+ break;
13154
+ case "error":
13155
+ this.pendingRequests.delete(response.id);
13156
+ pending.reject(new Error(response.error));
13157
+ break;
13158
+ case "progress":
13159
+ if (pending.onProgress && response.progress) {
13160
+ pending.onProgress(response.progress);
13161
+ }
13162
+ break;
13163
+ }
13164
+ }
13165
+ };
12086
13166
  // Annotate the CommonJS export names for ESM import in node:
12087
13167
  0 && (module.exports = {
12088
13168
  ATTESTATION_VERSION,
@@ -12126,6 +13206,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12126
13206
  ProofError,
12127
13207
  ProofGenerationError,
12128
13208
  ProofNotImplementedError,
13209
+ ProofWorker,
12129
13210
  ProposalStatus,
12130
13211
  ReportStatus,
12131
13212
  SIP,
@@ -12144,6 +13225,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12144
13225
  ZcashRPCClient,
12145
13226
  ZcashRPCError,
12146
13227
  ZcashShieldedService,
13228
+ ZcashSwapService,
12147
13229
  addBlindings,
12148
13230
  addCommitments,
12149
13231
  addOracle,
@@ -12152,6 +13234,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12152
13234
  browserBytesToHex,
12153
13235
  browserHexToBytes,
12154
13236
  checkEd25519StealthAddress,
13237
+ checkMobileWASMCompatibility,
12155
13238
  checkStealthAddress,
12156
13239
  commit,
12157
13240
  commitZero,
@@ -12176,8 +13259,10 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12176
13259
  createSolanaAdapter,
12177
13260
  createTrezorAdapter,
12178
13261
  createWalletFactory,
13262
+ createWorkerBlobURL,
12179
13263
  createZcashClient,
12180
13264
  createZcashShieldedService,
13265
+ createZcashSwapService,
12181
13266
  decodeStealthMetaAddress,
12182
13267
  decryptMemo,
12183
13268
  decryptWithViewing,
@@ -12189,6 +13274,8 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12189
13274
  deserializeIntent,
12190
13275
  deserializePayment,
12191
13276
  detectEthereumWallets,
13277
+ detectMobileBrowser,
13278
+ detectMobilePlatform,
12192
13279
  detectSolanaWallets,
12193
13280
  ed25519PublicKeyToNearAddress,
12194
13281
  ed25519PublicKeyToSolanaAddress,
@@ -12209,6 +13296,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12209
13296
  getActiveOracles,
12210
13297
  getAvailableTransports,
12211
13298
  getBrowserInfo,
13299
+ getBrowserVersion,
12212
13300
  getChainNumericId,
12213
13301
  getChainsForStablecoin,
12214
13302
  getCurveForChain,
@@ -12218,6 +13306,8 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12218
13306
  getEthereumProvider,
12219
13307
  getGenerators,
12220
13308
  getIntentSummary,
13309
+ getMobileDeviceInfo,
13310
+ getOSVersion,
12221
13311
  getPaymentSummary,
12222
13312
  getPaymentTimeRemaining,
12223
13313
  getPrivacyConfig,
@@ -12243,6 +13333,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12243
13333
  isSIPError,
12244
13334
  isStablecoin,
12245
13335
  isStablecoinOnChain,
13336
+ isTablet,
12246
13337
  isValidAmount,
12247
13338
  isValidChainId,
12248
13339
  isValidCompressedPublicKey,
@@ -12274,7 +13365,10 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
12274
13365
  subtractBlindings,
12275
13366
  subtractCommitments,
12276
13367
  supportsSharedArrayBuffer,
13368
+ supportsTouch,
12277
13369
  supportsViewingKey,
13370
+ supportsWASMBulkMemory,
13371
+ supportsWASMSimd,
12278
13372
  supportsWebBluetooth,
12279
13373
  supportsWebHID,
12280
13374
  supportsWebUSB,