@sip-protocol/sdk 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/browser.d.mts +100 -2
  2. package/dist/browser.d.ts +100 -2
  3. package/dist/browser.js +2116 -321
  4. package/dist/browser.mjs +516 -16
  5. package/dist/chunk-4IFOPYJF.mjs +11950 -0
  6. package/dist/chunk-7IMRM7LN.mjs +12149 -0
  7. package/dist/chunk-JNNXNTSS.mjs +11034 -0
  8. package/dist/chunk-W3YXIQ7L.mjs +11950 -0
  9. package/dist/chunk-XLEPIR2P.mjs +884 -0
  10. package/dist/index-Ba7njCU3.d.ts +6925 -0
  11. package/dist/index-Co26-vbG.d.mts +6925 -0
  12. package/dist/index-DqZoHYKI.d.mts +6418 -0
  13. package/dist/index-dTtK_DTl.d.ts +6762 -0
  14. package/dist/index-jnkYu-Z4.d.mts +6762 -0
  15. package/dist/index-vB1N1mHd.d.ts +6418 -0
  16. package/dist/index.d.mts +2 -5897
  17. package/dist/index.d.ts +2 -5897
  18. package/dist/index.js +1334 -199
  19. package/dist/index.mjs +19 -1
  20. package/dist/noir-BTyLXLlZ.d.mts +467 -0
  21. package/dist/noir-BTyLXLlZ.d.ts +467 -0
  22. package/dist/proofs/noir.d.mts +1 -1
  23. package/dist/proofs/noir.d.ts +1 -1
  24. package/dist/proofs/noir.js +11 -112
  25. package/dist/proofs/noir.mjs +10 -13
  26. package/package.json +3 -3
  27. package/src/browser.ts +23 -0
  28. package/src/index.ts +32 -0
  29. package/src/proofs/browser-utils.ts +389 -0
  30. package/src/proofs/browser.ts +246 -19
  31. package/src/proofs/circuits/funding_proof.json +1 -1
  32. package/src/proofs/noir.ts +14 -14
  33. package/src/proofs/worker.ts +426 -0
  34. package/src/settlement/README.md +439 -0
  35. package/src/settlement/backends/direct-chain.ts +569 -0
  36. package/src/settlement/backends/index.ts +22 -0
  37. package/src/settlement/backends/near-intents.ts +480 -0
  38. package/src/settlement/backends/zcash-native.ts +516 -0
  39. package/src/settlement/index.ts +47 -0
  40. package/src/settlement/interface.ts +397 -0
  41. package/src/settlement/registry.ts +269 -0
  42. package/src/settlement/router.ts +383 -0
package/dist/browser.mjs CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  MockWalletAdapter,
23
23
  NATIVE_TOKENS,
24
24
  NEARIntentsAdapter,
25
+ NEARIntentsBackend,
25
26
  ORACLE_DOMAIN,
26
27
  OneClickClient,
27
28
  OneClickDepositMode,
@@ -38,12 +39,17 @@ import {
38
39
  STABLECOIN_ADDRESSES,
39
40
  STABLECOIN_DECIMALS,
40
41
  STABLECOIN_INFO,
42
+ SettlementRegistry,
43
+ SettlementRegistryError,
44
+ SmartRouter,
41
45
  SolanaWalletAdapter,
46
+ SwapStatus,
42
47
  Treasury,
43
48
  TrezorWalletAdapter,
44
49
  WalletError,
45
50
  WalletErrorCode,
46
51
  ZcashErrorCode,
52
+ ZcashNativeBackend,
47
53
  ZcashRPCClient,
48
54
  ZcashRPCError,
49
55
  ZcashShieldedService,
@@ -55,6 +61,7 @@ import {
55
61
  base58ToHex,
56
62
  bytesToHex,
57
63
  checkEd25519StealthAddress,
64
+ checkMobileWASMCompatibility,
58
65
  checkStealthAddress,
59
66
  commit,
60
67
  commitZero,
@@ -71,15 +78,18 @@ import {
71
78
  createMockSolver,
72
79
  createMockTrezorAdapter,
73
80
  createNEARIntentsAdapter,
81
+ createNEARIntentsBackend,
74
82
  createOracleRegistry,
75
83
  createProductionSIP,
76
84
  createSIP,
77
85
  createShieldedIntent,
78
86
  createShieldedPayment,
87
+ createSmartRouter,
79
88
  createSolanaAdapter,
80
89
  createTrezorAdapter,
81
90
  createWalletFactory,
82
91
  createZcashClient,
92
+ createZcashNativeBackend,
83
93
  createZcashShieldedService,
84
94
  createZcashSwapService,
85
95
  decodeStealthMetaAddress,
@@ -93,6 +103,8 @@ import {
93
103
  deserializeIntent,
94
104
  deserializePayment,
95
105
  detectEthereumWallets,
106
+ detectMobileBrowser,
107
+ detectMobilePlatform,
96
108
  detectSolanaWallets,
97
109
  ed25519PublicKeyToNearAddress,
98
110
  ed25519PublicKeyToSolanaAddress,
@@ -113,6 +125,7 @@ import {
113
125
  getActiveOracles,
114
126
  getAvailableTransports,
115
127
  getBrowserInfo,
128
+ getBrowserVersion,
116
129
  getChainNumericId,
117
130
  getChainsForStablecoin,
118
131
  getCurveForChain,
@@ -121,6 +134,8 @@ import {
121
134
  getEthereumProvider,
122
135
  getGenerators,
123
136
  getIntentSummary,
137
+ getMobileDeviceInfo,
138
+ getOSVersion,
124
139
  getPaymentSummary,
125
140
  getPaymentTimeRemaining,
126
141
  getPrivacyConfig,
@@ -145,6 +160,7 @@ import {
145
160
  isPrivateWalletAdapter,
146
161
  isStablecoin,
147
162
  isStablecoinOnChain,
163
+ isTablet,
148
164
  isValidAmount,
149
165
  isValidChainId,
150
166
  isValidCompressedPublicKey,
@@ -176,7 +192,10 @@ import {
176
192
  subtractBlindings,
177
193
  subtractCommitments,
178
194
  supportsSharedArrayBuffer,
195
+ supportsTouch,
179
196
  supportsViewingKey,
197
+ supportsWASMBulkMemory,
198
+ supportsWASMSimd,
180
199
  supportsWebBluetooth,
181
200
  supportsWebHID,
182
201
  supportsWebUSB,
@@ -199,12 +218,12 @@ import {
199
218
  walletRegistry,
200
219
  withSecureBuffer,
201
220
  withSecureBufferSync
202
- } from "./chunk-KXN6IWL5.mjs";
221
+ } from "./chunk-7IMRM7LN.mjs";
203
222
  import {
204
223
  fulfillment_proof_default,
205
224
  funding_proof_default,
206
225
  validity_proof_default
207
- } from "./chunk-VITVG25F.mjs";
226
+ } from "./chunk-XLEPIR2P.mjs";
208
227
  import {
209
228
  CryptoError,
210
229
  EncryptionNotImplementedError,
@@ -230,6 +249,9 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
230
249
  framework = "noir";
231
250
  _isReady = false;
232
251
  config;
252
+ // Mobile device info (cached)
253
+ deviceInfo = null;
254
+ wasmCompatibility = null;
233
255
  // Circuit instances
234
256
  fundingNoir = null;
235
257
  fundingBackend = null;
@@ -241,17 +263,25 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
241
263
  worker = null;
242
264
  workerPending = /* @__PURE__ */ new Map();
243
265
  constructor(config = {}) {
266
+ this.deviceInfo = getMobileDeviceInfo();
267
+ const isMobile = this.deviceInfo.isMobile;
268
+ const defaultTimeout = isMobile ? 12e4 : 6e4;
244
269
  this.config = {
245
270
  useWorker: config.useWorker ?? true,
246
271
  verbose: config.verbose ?? false,
247
272
  oraclePublicKey: config.oraclePublicKey ?? void 0,
248
- timeout: config.timeout ?? 6e4
273
+ timeout: config.timeout ?? defaultTimeout,
274
+ mobileMode: config.mobileMode ?? isMobile,
275
+ forceInitialize: config.forceInitialize ?? false
249
276
  };
250
277
  if (!isBrowser()) {
251
278
  console.warn(
252
279
  "[BrowserNoirProvider] Not running in browser environment. Consider using NoirProofProvider for Node.js."
253
280
  );
254
281
  }
282
+ if (this.config.verbose && this.deviceInfo) {
283
+ console.log("[BrowserNoirProvider] Device info:", this.deviceInfo);
284
+ }
255
285
  }
256
286
  get isReady() {
257
287
  return this._isReady;
@@ -281,6 +311,67 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
281
311
  missing
282
312
  };
283
313
  }
314
+ /**
315
+ * Get detailed mobile device information
316
+ */
317
+ static getMobileInfo() {
318
+ return getMobileDeviceInfo();
319
+ }
320
+ /**
321
+ * Check mobile WASM compatibility
322
+ *
323
+ * Returns detailed compatibility information including:
324
+ * - Feature support (WASM, SharedArrayBuffer, Workers, SIMD)
325
+ * - Compatibility score (0-100)
326
+ * - Issues and recommendations
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const compat = BrowserNoirProvider.checkMobileCompatibility()
331
+ * if (compat.score < 70) {
332
+ * console.warn('Limited mobile support:', compat.issues)
333
+ * }
334
+ * ```
335
+ */
336
+ static checkMobileCompatibility() {
337
+ return checkMobileWASMCompatibility();
338
+ }
339
+ /**
340
+ * Check if the current device is mobile
341
+ */
342
+ static isMobile() {
343
+ return getMobileDeviceInfo().isMobile;
344
+ }
345
+ /**
346
+ * Get recommended configuration for the current device
347
+ *
348
+ * Automatically adjusts settings based on device capabilities:
349
+ * - Mobile devices get longer timeouts
350
+ * - Low-memory devices disable workers
351
+ * - Tablets get intermediate settings
352
+ */
353
+ static getRecommendedConfig() {
354
+ const deviceInfo = getMobileDeviceInfo();
355
+ const compat = checkMobileWASMCompatibility();
356
+ const config = {};
357
+ if (deviceInfo.isMobile) {
358
+ config.timeout = 12e4;
359
+ config.mobileMode = true;
360
+ if (deviceInfo.deviceMemoryGB !== null && deviceInfo.deviceMemoryGB < 2) {
361
+ config.useWorker = false;
362
+ }
363
+ if (deviceInfo.platform === "ios" && deviceInfo.browser === "safari") {
364
+ config.useWorker = compat.sharedArrayBuffer;
365
+ }
366
+ } else if (deviceInfo.isTablet) {
367
+ config.timeout = 9e4;
368
+ config.mobileMode = true;
369
+ }
370
+ if (compat.score < 50) {
371
+ config.forceInitialize = false;
372
+ }
373
+ return config;
374
+ }
284
375
  /**
285
376
  * Derive secp256k1 public key coordinates from a private key
286
377
  */
@@ -290,6 +381,18 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
290
381
  const y = Array.from(uncompressedPubKey.slice(33, 65));
291
382
  return { x, y };
292
383
  }
384
+ /**
385
+ * Get the cached WASM compatibility info (available after construction)
386
+ */
387
+ getWASMCompatibility() {
388
+ return this.wasmCompatibility;
389
+ }
390
+ /**
391
+ * Get the cached device info (available after construction)
392
+ */
393
+ getDeviceInfo() {
394
+ return this.deviceInfo;
395
+ }
293
396
  /**
294
397
  * Initialize the browser provider
295
398
  *
@@ -302,8 +405,18 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
302
405
  if (this._isReady) {
303
406
  return;
304
407
  }
408
+ this.wasmCompatibility = checkMobileWASMCompatibility();
409
+ if (this.config.verbose) {
410
+ console.log("[BrowserNoirProvider] WASM compatibility:", this.wasmCompatibility);
411
+ }
412
+ if (this.wasmCompatibility.score < 50 && !this.config.forceInitialize) {
413
+ throw new ProofError(
414
+ `Device has poor WASM compatibility (score: ${this.wasmCompatibility.score}). Issues: ${this.wasmCompatibility.issues.join(", ")}. Set forceInitialize: true to override.`,
415
+ "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
416
+ );
417
+ }
305
418
  const { supported, missing } = _BrowserNoirProvider.checkBrowserSupport();
306
- if (!supported) {
419
+ if (!supported && !this.config.forceInitialize) {
307
420
  throw new ProofError(
308
421
  `Browser missing required features: ${missing.join(", ")}`,
309
422
  "SIP_4004" /* PROOF_PROVIDER_NOT_READY */
@@ -367,8 +480,69 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
367
480
  * Initialize Web Worker for off-main-thread proof generation
368
481
  */
369
482
  async initializeWorker() {
370
- if (this.config.verbose) {
371
- console.log("[BrowserNoirProvider] Worker support: using async main-thread");
483
+ if (!supportsWebWorkers()) {
484
+ if (this.config.verbose) {
485
+ console.log("[BrowserNoirProvider] Web Workers not supported, using main thread");
486
+ }
487
+ return;
488
+ }
489
+ try {
490
+ const workerCode = this.getWorkerCode();
491
+ const blob = new Blob([workerCode], { type: "application/javascript" });
492
+ const workerURL = URL.createObjectURL(blob);
493
+ this.worker = new Worker(workerURL, { type: "module" });
494
+ this.worker.onmessage = (event) => {
495
+ this.handleWorkerMessage(event.data);
496
+ };
497
+ this.worker.onerror = (error) => {
498
+ console.error("[BrowserNoirProvider] Worker error:", error);
499
+ for (const [id, { reject }] of this.workerPending) {
500
+ reject(new Error(`Worker error: ${error.message}`));
501
+ this.workerPending.delete(id);
502
+ }
503
+ this.worker?.terminate();
504
+ this.worker = null;
505
+ };
506
+ URL.revokeObjectURL(workerURL);
507
+ if (this.config.verbose) {
508
+ console.log("[BrowserNoirProvider] Web Worker initialized successfully");
509
+ }
510
+ } catch (error) {
511
+ if (this.config.verbose) {
512
+ console.warn("[BrowserNoirProvider] Failed to initialize worker, using main thread:", error);
513
+ }
514
+ this.worker = null;
515
+ }
516
+ }
517
+ /**
518
+ * Get inline worker code for bundler compatibility
519
+ */
520
+ getWorkerCode() {
521
+ return `
522
+ self.onmessage = async function(event) {
523
+ const { id, type } = event.data;
524
+ // Signal that worker received message but proof gen happens on main thread
525
+ self.postMessage({ id, type: 'fallback', message: 'Worker initialized, using main thread for proofs' });
526
+ };
527
+ `;
528
+ }
529
+ /**
530
+ * Handle messages from worker
531
+ */
532
+ handleWorkerMessage(data) {
533
+ const pending = this.workerPending.get(data.id);
534
+ if (!pending) return;
535
+ switch (data.type) {
536
+ case "success":
537
+ this.workerPending.delete(data.id);
538
+ pending.resolve(data.result);
539
+ break;
540
+ case "error":
541
+ this.workerPending.delete(data.id);
542
+ pending.reject(new Error(data.error));
543
+ break;
544
+ case "fallback":
545
+ break;
372
546
  }
373
547
  }
374
548
  /**
@@ -390,15 +564,10 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
390
564
  percent: 10,
391
565
  message: "Preparing witness inputs..."
392
566
  });
393
- const { commitmentHash, blindingField } = await this.computeCommitmentHash(
394
- params.balance,
395
- params.blindingFactor,
396
- params.assetId
397
- );
567
+ const blindingField = this.bytesToField(params.blindingFactor);
398
568
  const witnessInputs = {
399
- commitment_hash: commitmentHash,
400
569
  minimum_required: params.minimumRequired.toString(),
401
- asset_id: this.assetIdToField(params.assetId),
570
+ asset_id: `0x${this.assetIdToField(params.assetId)}`,
402
571
  balance: params.balance.toString(),
403
572
  blinding: blindingField
404
573
  };
@@ -407,7 +576,7 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
407
576
  percent: 30,
408
577
  message: "Generating witness..."
409
578
  });
410
- const { witness } = await this.fundingNoir.execute(witnessInputs);
579
+ const { witness, returnValue } = await this.fundingNoir.execute(witnessInputs);
411
580
  onProgress?.({
412
581
  stage: "proving",
413
582
  percent: 50,
@@ -419,10 +588,12 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
419
588
  percent: 100,
420
589
  message: "Proof generated successfully"
421
590
  });
591
+ const commitmentHashBytes = returnValue;
592
+ const commitmentHashHex = bytesToHex(new Uint8Array(commitmentHashBytes));
422
593
  const publicInputs = [
423
- `0x${commitmentHash}`,
424
594
  `0x${params.minimumRequired.toString(16).padStart(16, "0")}`,
425
- `0x${this.assetIdToField(params.assetId)}`
595
+ `0x${this.assetIdToField(params.assetId)}`,
596
+ `0x${commitmentHashHex}`
426
597
  ];
427
598
  const proof = {
428
599
  type: "funding",
@@ -824,6 +995,314 @@ var BrowserNoirProvider = class _BrowserNoirProvider {
824
995
  return { x, y };
825
996
  }
826
997
  };
998
+
999
+ // src/proofs/worker.ts
1000
+ function createWorkerBlobURL() {
1001
+ const workerCode = `
1002
+ // Proof Generation Worker
1003
+ // This code runs in a separate thread
1004
+
1005
+ let fundingNoir = null;
1006
+ let fundingBackend = null;
1007
+ let validityNoir = null;
1008
+ let validityBackend = null;
1009
+ let fulfillmentNoir = null;
1010
+ let fulfillmentBackend = null;
1011
+ let isReady = false;
1012
+ let config = { verbose: false };
1013
+
1014
+ // Helper to send progress updates
1015
+ function sendProgress(id, stage, percent, message) {
1016
+ self.postMessage({
1017
+ id,
1018
+ type: 'progress',
1019
+ progress: { stage, percent, message }
1020
+ });
1021
+ }
1022
+
1023
+ // Helper to send error
1024
+ function sendError(id, error) {
1025
+ self.postMessage({
1026
+ id,
1027
+ type: 'error',
1028
+ error: error.message || String(error)
1029
+ });
1030
+ }
1031
+
1032
+ // Helper to send success
1033
+ function sendSuccess(id, result) {
1034
+ self.postMessage({
1035
+ id,
1036
+ type: 'success',
1037
+ result
1038
+ });
1039
+ }
1040
+
1041
+ // Initialize circuits (called once)
1042
+ async function initialize(id, initConfig) {
1043
+ try {
1044
+ sendProgress(id, 'initializing', 10, 'Loading Noir JS...');
1045
+
1046
+ // Dynamic imports for Noir
1047
+ const { Noir } = await import('@noir-lang/noir_js');
1048
+ const { UltraHonkBackend } = await import('@aztec/bb.js');
1049
+
1050
+ sendProgress(id, 'initializing', 30, 'Loading circuit artifacts...');
1051
+
1052
+ // Load circuit artifacts
1053
+ const [fundingArtifact, validityArtifact, fulfillmentArtifact] = await Promise.all([
1054
+ fetch(new URL('./circuits/funding_proof.json', import.meta.url)).then(r => r.json()),
1055
+ fetch(new URL('./circuits/validity_proof.json', import.meta.url)).then(r => r.json()),
1056
+ fetch(new URL('./circuits/fulfillment_proof.json', import.meta.url)).then(r => r.json()),
1057
+ ]);
1058
+
1059
+ sendProgress(id, 'initializing', 50, 'Initializing backends...');
1060
+
1061
+ // Initialize Noir instances
1062
+ fundingNoir = new Noir(fundingArtifact);
1063
+ fundingBackend = new UltraHonkBackend(fundingArtifact.bytecode);
1064
+
1065
+ sendProgress(id, 'initializing', 70, 'Initializing validity circuit...');
1066
+ validityNoir = new Noir(validityArtifact);
1067
+ validityBackend = new UltraHonkBackend(validityArtifact.bytecode);
1068
+
1069
+ sendProgress(id, 'initializing', 90, 'Initializing fulfillment circuit...');
1070
+ fulfillmentNoir = new Noir(fulfillmentArtifact);
1071
+ fulfillmentBackend = new UltraHonkBackend(fulfillmentArtifact.bytecode);
1072
+
1073
+ config = initConfig || { verbose: false };
1074
+ isReady = true;
1075
+
1076
+ sendProgress(id, 'complete', 100, 'Worker initialized');
1077
+ sendSuccess(id, { initialized: true });
1078
+ } catch (error) {
1079
+ sendError(id, error);
1080
+ }
1081
+ }
1082
+
1083
+ // Generate funding proof
1084
+ async function generateFundingProof(id, params) {
1085
+ if (!isReady) {
1086
+ sendError(id, new Error('Worker not initialized'));
1087
+ return;
1088
+ }
1089
+
1090
+ try {
1091
+ sendProgress(id, 'witness', 20, 'Preparing witness...');
1092
+
1093
+ // Convert blinding factor to field
1094
+ const blindingField = bytesToField(params.blindingFactor);
1095
+
1096
+ const witnessInputs = {
1097
+ minimum_required: params.minimumRequired.toString(),
1098
+ asset_id: '0x' + assetIdToField(params.assetId),
1099
+ balance: params.balance.toString(),
1100
+ blinding: blindingField,
1101
+ };
1102
+
1103
+ sendProgress(id, 'witness', 40, 'Executing circuit...');
1104
+ const { witness, returnValue } = await fundingNoir.execute(witnessInputs);
1105
+
1106
+ sendProgress(id, 'proving', 60, 'Generating proof...');
1107
+ const proofData = await fundingBackend.generateProof(witness);
1108
+
1109
+ sendProgress(id, 'complete', 100, 'Proof generated');
1110
+
1111
+ // Extract commitment hash from return value
1112
+ const commitmentHashHex = bytesToHex(new Uint8Array(returnValue));
1113
+
1114
+ const publicInputs = [
1115
+ '0x' + params.minimumRequired.toString(16).padStart(16, '0'),
1116
+ '0x' + assetIdToField(params.assetId),
1117
+ '0x' + commitmentHashHex,
1118
+ ];
1119
+
1120
+ const proof = {
1121
+ type: 'funding',
1122
+ proof: '0x' + bytesToHex(proofData.proof),
1123
+ publicInputs,
1124
+ };
1125
+
1126
+ sendSuccess(id, { proof, publicInputs });
1127
+ } catch (error) {
1128
+ sendError(id, error);
1129
+ }
1130
+ }
1131
+
1132
+ // Helper functions
1133
+ function bytesToField(bytes) {
1134
+ let result = 0n;
1135
+ const len = Math.min(bytes.length, 31);
1136
+ for (let i = 0; i < len; i++) {
1137
+ result = result * 256n + BigInt(bytes[i]);
1138
+ }
1139
+ return result.toString();
1140
+ }
1141
+
1142
+ function assetIdToField(assetId) {
1143
+ if (assetId.startsWith('0x')) {
1144
+ return assetId.slice(2).padStart(64, '0');
1145
+ }
1146
+ const encoder = new TextEncoder();
1147
+ const bytes = encoder.encode(assetId);
1148
+ let result = 0n;
1149
+ for (let i = 0; i < bytes.length && i < 31; i++) {
1150
+ result = result * 256n + BigInt(bytes[i]);
1151
+ }
1152
+ return result.toString(16).padStart(64, '0');
1153
+ }
1154
+
1155
+ function bytesToHex(bytes) {
1156
+ return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
1157
+ }
1158
+
1159
+ // Message handler
1160
+ self.onmessage = async function(event) {
1161
+ const { id, type, params, config: initConfig } = event.data;
1162
+
1163
+ switch (type) {
1164
+ case 'init':
1165
+ await initialize(id, initConfig);
1166
+ break;
1167
+ case 'generateFundingProof':
1168
+ await generateFundingProof(id, params);
1169
+ break;
1170
+ case 'generateValidityProof':
1171
+ // TODO: Implement
1172
+ sendError(id, new Error('Validity proof not yet implemented in worker'));
1173
+ break;
1174
+ case 'generateFulfillmentProof':
1175
+ // TODO: Implement
1176
+ sendError(id, new Error('Fulfillment proof not yet implemented in worker'));
1177
+ break;
1178
+ case 'destroy':
1179
+ // Cleanup
1180
+ fundingNoir = null;
1181
+ fundingBackend = null;
1182
+ validityNoir = null;
1183
+ validityBackend = null;
1184
+ fulfillmentNoir = null;
1185
+ fulfillmentBackend = null;
1186
+ isReady = false;
1187
+ sendSuccess(id, { destroyed: true });
1188
+ break;
1189
+ default:
1190
+ sendError(id, new Error('Unknown message type: ' + type));
1191
+ }
1192
+ };
1193
+ `;
1194
+ const blob = new Blob([workerCode], { type: "application/javascript" });
1195
+ return URL.createObjectURL(blob);
1196
+ }
1197
+ var ProofWorker = class _ProofWorker {
1198
+ worker = null;
1199
+ pendingRequests = /* @__PURE__ */ new Map();
1200
+ _isReady = false;
1201
+ requestCounter = 0;
1202
+ /**
1203
+ * Check if Web Workers are supported
1204
+ */
1205
+ static isSupported() {
1206
+ return typeof Worker !== "undefined" && typeof Blob !== "undefined";
1207
+ }
1208
+ /**
1209
+ * Check if worker is initialized and ready
1210
+ */
1211
+ get isReady() {
1212
+ return this._isReady;
1213
+ }
1214
+ /**
1215
+ * Initialize the worker
1216
+ */
1217
+ async initialize(config) {
1218
+ if (this._isReady) {
1219
+ return;
1220
+ }
1221
+ if (!_ProofWorker.isSupported()) {
1222
+ throw new Error("Web Workers not supported in this environment");
1223
+ }
1224
+ const workerURL = createWorkerBlobURL();
1225
+ this.worker = new Worker(workerURL, { type: "module" });
1226
+ this.worker.onmessage = (event) => {
1227
+ this.handleWorkerMessage(event.data);
1228
+ };
1229
+ this.worker.onerror = (error) => {
1230
+ console.error("[ProofWorker] Worker error:", error);
1231
+ for (const [id, { reject }] of this.pendingRequests) {
1232
+ reject(new Error(`Worker error: ${error.message}`));
1233
+ this.pendingRequests.delete(id);
1234
+ }
1235
+ };
1236
+ await this.sendRequest("init", void 0, config);
1237
+ this._isReady = true;
1238
+ URL.revokeObjectURL(workerURL);
1239
+ }
1240
+ /**
1241
+ * Generate a proof using the worker
1242
+ */
1243
+ async generateProof(type, params, onProgress) {
1244
+ if (!this._isReady || !this.worker) {
1245
+ throw new Error("Worker not initialized. Call initialize() first.");
1246
+ }
1247
+ const messageType = type === "funding" ? "generateFundingProof" : type === "validity" ? "generateValidityProof" : "generateFulfillmentProof";
1248
+ return this.sendRequest(messageType, params, void 0, onProgress);
1249
+ }
1250
+ /**
1251
+ * Destroy the worker and free resources
1252
+ */
1253
+ async destroy() {
1254
+ if (this.worker) {
1255
+ try {
1256
+ await this.sendRequest("destroy");
1257
+ } catch {
1258
+ }
1259
+ this.worker.terminate();
1260
+ this.worker = null;
1261
+ }
1262
+ this._isReady = false;
1263
+ this.pendingRequests.clear();
1264
+ }
1265
+ /**
1266
+ * Send a request to the worker
1267
+ */
1268
+ sendRequest(type, params, config, onProgress) {
1269
+ return new Promise((resolve, reject) => {
1270
+ if (!this.worker) {
1271
+ reject(new Error("Worker not available"));
1272
+ return;
1273
+ }
1274
+ const id = `req_${++this.requestCounter}_${Date.now()}`;
1275
+ this.pendingRequests.set(id, { resolve, reject, onProgress });
1276
+ const request = { id, type, params, config };
1277
+ this.worker.postMessage(request);
1278
+ });
1279
+ }
1280
+ /**
1281
+ * Handle messages from the worker
1282
+ */
1283
+ handleWorkerMessage(response) {
1284
+ const pending = this.pendingRequests.get(response.id);
1285
+ if (!pending) {
1286
+ console.warn("[ProofWorker] Received response for unknown request:", response.id);
1287
+ return;
1288
+ }
1289
+ switch (response.type) {
1290
+ case "success":
1291
+ this.pendingRequests.delete(response.id);
1292
+ pending.resolve(response.result);
1293
+ break;
1294
+ case "error":
1295
+ this.pendingRequests.delete(response.id);
1296
+ pending.reject(new Error(response.error));
1297
+ break;
1298
+ case "progress":
1299
+ if (pending.onProgress && response.progress) {
1300
+ pending.onProgress(response.progress);
1301
+ }
1302
+ break;
1303
+ }
1304
+ }
1305
+ };
827
1306
  export {
828
1307
  ATTESTATION_VERSION,
829
1308
  BaseWalletAdapter,
@@ -853,6 +1332,7 @@ export {
853
1332
  MockWalletAdapter,
854
1333
  NATIVE_TOKENS,
855
1334
  NEARIntentsAdapter,
1335
+ NEARIntentsBackend,
856
1336
  NetworkError,
857
1337
  ORACLE_DOMAIN,
858
1338
  OneClickClient,
@@ -866,6 +1346,7 @@ export {
866
1346
  ProofError,
867
1347
  ProofGenerationError,
868
1348
  ProofNotImplementedError,
1349
+ ProofWorker,
869
1350
  ProposalStatus,
870
1351
  ReportStatus,
871
1352
  SIP,
@@ -874,13 +1355,18 @@ export {
874
1355
  STABLECOIN_ADDRESSES,
875
1356
  STABLECOIN_DECIMALS,
876
1357
  STABLECOIN_INFO,
1358
+ SettlementRegistry,
1359
+ SettlementRegistryError,
1360
+ SmartRouter,
877
1361
  SolanaWalletAdapter,
1362
+ SwapStatus,
878
1363
  Treasury,
879
1364
  TrezorWalletAdapter,
880
1365
  ValidationError,
881
1366
  WalletError,
882
1367
  WalletErrorCode,
883
1368
  ZcashErrorCode,
1369
+ ZcashNativeBackend,
884
1370
  ZcashRPCClient,
885
1371
  ZcashRPCError,
886
1372
  ZcashShieldedService,
@@ -893,6 +1379,7 @@ export {
893
1379
  bytesToHex as browserBytesToHex,
894
1380
  hexToBytes as browserHexToBytes,
895
1381
  checkEd25519StealthAddress,
1382
+ checkMobileWASMCompatibility,
896
1383
  checkStealthAddress,
897
1384
  commit,
898
1385
  commitZero,
@@ -909,15 +1396,19 @@ export {
909
1396
  createMockSolver,
910
1397
  createMockTrezorAdapter,
911
1398
  createNEARIntentsAdapter,
1399
+ createNEARIntentsBackend,
912
1400
  createOracleRegistry,
913
1401
  createProductionSIP,
914
1402
  createSIP,
915
1403
  createShieldedIntent,
916
1404
  createShieldedPayment,
1405
+ createSmartRouter,
917
1406
  createSolanaAdapter,
918
1407
  createTrezorAdapter,
919
1408
  createWalletFactory,
1409
+ createWorkerBlobURL,
920
1410
  createZcashClient,
1411
+ createZcashNativeBackend,
921
1412
  createZcashShieldedService,
922
1413
  createZcashSwapService,
923
1414
  decodeStealthMetaAddress,
@@ -931,6 +1422,8 @@ export {
931
1422
  deserializeIntent,
932
1423
  deserializePayment,
933
1424
  detectEthereumWallets,
1425
+ detectMobileBrowser,
1426
+ detectMobilePlatform,
934
1427
  detectSolanaWallets,
935
1428
  ed25519PublicKeyToNearAddress,
936
1429
  ed25519PublicKeyToSolanaAddress,
@@ -951,6 +1444,7 @@ export {
951
1444
  getActiveOracles,
952
1445
  getAvailableTransports,
953
1446
  getBrowserInfo,
1447
+ getBrowserVersion,
954
1448
  getChainNumericId,
955
1449
  getChainsForStablecoin,
956
1450
  getCurveForChain,
@@ -960,6 +1454,8 @@ export {
960
1454
  getEthereumProvider,
961
1455
  getGenerators,
962
1456
  getIntentSummary,
1457
+ getMobileDeviceInfo,
1458
+ getOSVersion,
963
1459
  getPaymentSummary,
964
1460
  getPaymentTimeRemaining,
965
1461
  getPrivacyConfig,
@@ -985,6 +1481,7 @@ export {
985
1481
  isSIPError,
986
1482
  isStablecoin,
987
1483
  isStablecoinOnChain,
1484
+ isTablet,
988
1485
  isValidAmount,
989
1486
  isValidChainId,
990
1487
  isValidCompressedPublicKey,
@@ -1016,7 +1513,10 @@ export {
1016
1513
  subtractBlindings,
1017
1514
  subtractCommitments,
1018
1515
  supportsSharedArrayBuffer,
1516
+ supportsTouch,
1019
1517
  supportsViewingKey,
1518
+ supportsWASMBulkMemory,
1519
+ supportsWASMSimd,
1020
1520
  supportsWebBluetooth,
1021
1521
  supportsWebHID,
1022
1522
  supportsWebUSB,