@sip-protocol/sdk 0.2.10 → 0.3.1

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 (49) hide show
  1. package/dist/browser.d.mts +1 -1
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +1643 -266
  4. package/dist/browser.mjs +259 -5
  5. package/dist/chunk-4IFOPYJF.mjs +11950 -0
  6. package/dist/chunk-4VJHI66K.mjs +12120 -0
  7. package/dist/chunk-5BAS4D44.mjs +10283 -0
  8. package/dist/chunk-6WOV2YNG.mjs +10179 -0
  9. package/dist/chunk-7IMRM7LN.mjs +12149 -0
  10. package/dist/chunk-DU7LQDD2.mjs +10148 -0
  11. package/dist/{chunk-AV37IZST.mjs → chunk-JNNXNTSS.mjs} +14 -0
  12. package/dist/chunk-KXN6IWL5.mjs +10736 -0
  13. package/dist/chunk-MR7HRCRS.mjs +10165 -0
  14. package/dist/chunk-NDGUWOOZ.mjs +10157 -0
  15. package/dist/chunk-O4Y2ZUDL.mjs +12721 -0
  16. package/dist/chunk-UPTISVCY.mjs +10304 -0
  17. package/dist/chunk-VITVG25F.mjs +982 -0
  18. package/dist/chunk-VXSHK7US.mjs +10158 -0
  19. package/dist/chunk-W3YXIQ7L.mjs +11950 -0
  20. package/dist/chunk-YZCK337Y.mjs +12155 -0
  21. package/dist/index-Ba7njCU3.d.ts +6925 -0
  22. package/dist/index-Co26-vbG.d.mts +6925 -0
  23. package/dist/index-DAgedMrt.d.ts +6927 -0
  24. package/dist/index-DW7AQwcU.d.mts +6927 -0
  25. package/dist/{index-CAhjA4kh.d.mts → index-DqZoHYKI.d.mts} +362 -6
  26. package/dist/index-dTtK_DTl.d.ts +6762 -0
  27. package/dist/index-jnkYu-Z4.d.mts +6762 -0
  28. package/dist/{index-BFOKTz2z.d.ts → index-vB1N1mHd.d.ts} +362 -6
  29. package/dist/index.d.mts +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +1340 -199
  32. package/dist/index.mjs +19 -1
  33. package/dist/noir-BHQtFvRk.d.mts +467 -0
  34. package/dist/noir-BHQtFvRk.d.ts +467 -0
  35. package/package.json +14 -14
  36. package/src/index.ts +32 -0
  37. package/src/proofs/worker.ts +240 -4
  38. package/src/settlement/README.md +439 -0
  39. package/src/settlement/backends/direct-chain.ts +569 -0
  40. package/src/settlement/backends/index.ts +22 -0
  41. package/src/settlement/backends/near-intents.ts +480 -0
  42. package/src/settlement/backends/zcash-native.ts +516 -0
  43. package/src/settlement/index.ts +47 -0
  44. package/src/settlement/interface.ts +397 -0
  45. package/src/settlement/registry.ts +269 -0
  46. package/src/settlement/router.ts +383 -0
  47. package/src/zcash/bridge.ts +20 -2
  48. package/src/zcash/swap-service.ts +20 -2
  49. package/LICENSE +0 -21
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,
@@ -72,15 +78,18 @@ import {
72
78
  createMockSolver,
73
79
  createMockTrezorAdapter,
74
80
  createNEARIntentsAdapter,
81
+ createNEARIntentsBackend,
75
82
  createOracleRegistry,
76
83
  createProductionSIP,
77
84
  createSIP,
78
85
  createShieldedIntent,
79
86
  createShieldedPayment,
87
+ createSmartRouter,
80
88
  createSolanaAdapter,
81
89
  createTrezorAdapter,
82
90
  createWalletFactory,
83
91
  createZcashClient,
92
+ createZcashNativeBackend,
84
93
  createZcashShieldedService,
85
94
  createZcashSwapService,
86
95
  decodeStealthMetaAddress,
@@ -209,7 +218,7 @@ import {
209
218
  walletRegistry,
210
219
  withSecureBuffer,
211
220
  withSecureBufferSync
212
- } from "./chunk-AV37IZST.mjs";
221
+ } from "./chunk-YZCK337Y.mjs";
213
222
  import {
214
223
  fulfillment_proof_default,
215
224
  funding_proof_default,
@@ -1120,6 +1129,211 @@ function createWorkerBlobURL() {
1120
1129
  }
1121
1130
  }
1122
1131
 
1132
+ // Generate validity proof
1133
+ async function generateValidityProof(id, params) {
1134
+ if (!isReady) {
1135
+ sendError(id, new Error('Worker not initialized'));
1136
+ return;
1137
+ }
1138
+
1139
+ try {
1140
+ sendProgress(id, 'witness', 20, 'Preparing validity witness...');
1141
+
1142
+ // Import noble crypto for hashing
1143
+ const { sha256 } = await import('@noble/hashes/sha256');
1144
+
1145
+ // Convert inputs to field elements
1146
+ const intentHashField = hexToField(params.intentHash);
1147
+ const senderAddressField = hexToField(params.senderAddress);
1148
+ const senderBlindingField = bytesToField(params.senderBlinding);
1149
+ const senderSecretField = bytesToField(params.senderSecret);
1150
+ const nonceField = bytesToField(params.nonce);
1151
+
1152
+ // Compute sender commitment
1153
+ const addressBytes = hexToBytes(senderAddressField);
1154
+ const blindingBytes = hexToBytes(senderBlindingField.padStart(64, '0'));
1155
+ const commitmentPreimage = new Uint8Array([...addressBytes, ...blindingBytes]);
1156
+ const commitmentHash = sha256(commitmentPreimage);
1157
+ const commitmentX = bytesToHex(commitmentHash.slice(0, 16)).padStart(64, '0');
1158
+ const commitmentY = bytesToHex(commitmentHash.slice(16, 32)).padStart(64, '0');
1159
+
1160
+ // Compute nullifier
1161
+ const secretBytes = hexToBytes(senderSecretField.padStart(64, '0'));
1162
+ const intentBytes = hexToBytes(intentHashField);
1163
+ const nonceBytes = hexToBytes(nonceField.padStart(64, '0'));
1164
+ const nullifierPreimage = new Uint8Array([...secretBytes, ...intentBytes, ...nonceBytes]);
1165
+ const nullifierHash = sha256(nullifierPreimage);
1166
+ const nullifier = bytesToHex(nullifierHash);
1167
+
1168
+ const signature = Array.from(params.authorizationSignature);
1169
+ const messageHash = fieldToBytes32(intentHashField);
1170
+
1171
+ // Get public key coordinates
1172
+ let pubKeyX, pubKeyY;
1173
+ if (params.senderPublicKey) {
1174
+ pubKeyX = Array.from(params.senderPublicKey.x);
1175
+ pubKeyY = Array.from(params.senderPublicKey.y);
1176
+ } else {
1177
+ // Derive from secret
1178
+ const { secp256k1 } = await import('@noble/curves/secp256k1');
1179
+ const uncompressedPubKey = secp256k1.getPublicKey(params.senderSecret, false);
1180
+ pubKeyX = Array.from(uncompressedPubKey.slice(1, 33));
1181
+ pubKeyY = Array.from(uncompressedPubKey.slice(33, 65));
1182
+ }
1183
+
1184
+ const witnessInputs = {
1185
+ intent_hash: intentHashField,
1186
+ sender_commitment_x: commitmentX,
1187
+ sender_commitment_y: commitmentY,
1188
+ nullifier: nullifier,
1189
+ timestamp: params.timestamp.toString(),
1190
+ expiry: params.expiry.toString(),
1191
+ sender_address: senderAddressField,
1192
+ sender_blinding: senderBlindingField,
1193
+ sender_secret: senderSecretField,
1194
+ pub_key_x: pubKeyX,
1195
+ pub_key_y: pubKeyY,
1196
+ signature: signature,
1197
+ message_hash: messageHash,
1198
+ nonce: nonceField,
1199
+ };
1200
+
1201
+ sendProgress(id, 'witness', 40, 'Executing validity circuit...');
1202
+ const { witness } = await validityNoir.execute(witnessInputs);
1203
+
1204
+ sendProgress(id, 'proving', 60, 'Generating validity proof...');
1205
+ const proofData = await validityBackend.generateProof(witness);
1206
+
1207
+ sendProgress(id, 'complete', 100, 'Validity proof generated');
1208
+
1209
+ const publicInputs = [
1210
+ '0x' + intentHashField,
1211
+ '0x' + commitmentX,
1212
+ '0x' + commitmentY,
1213
+ '0x' + nullifier,
1214
+ '0x' + params.timestamp.toString(16).padStart(16, '0'),
1215
+ '0x' + params.expiry.toString(16).padStart(16, '0'),
1216
+ ];
1217
+
1218
+ const proof = {
1219
+ type: 'validity',
1220
+ proof: '0x' + bytesToHex(proofData.proof),
1221
+ publicInputs,
1222
+ };
1223
+
1224
+ sendSuccess(id, { proof, publicInputs });
1225
+ } catch (error) {
1226
+ sendError(id, error);
1227
+ }
1228
+ }
1229
+
1230
+ // Generate fulfillment proof
1231
+ async function generateFulfillmentProof(id, params) {
1232
+ if (!isReady) {
1233
+ sendError(id, new Error('Worker not initialized'));
1234
+ return;
1235
+ }
1236
+
1237
+ try {
1238
+ sendProgress(id, 'witness', 20, 'Preparing fulfillment witness...');
1239
+
1240
+ // Import noble crypto for hashing
1241
+ const { sha256 } = await import('@noble/hashes/sha256');
1242
+
1243
+ const intentHashField = hexToField(params.intentHash);
1244
+ const recipientStealthField = hexToField(params.recipientStealth);
1245
+
1246
+ // Compute output commitment
1247
+ const amountBytes = bigintToBytes(params.outputAmount, 8);
1248
+ const blindingBytes = params.outputBlinding.slice(0, 32);
1249
+ const outputPreimage = new Uint8Array([...amountBytes, ...blindingBytes]);
1250
+ const outputHash = sha256(outputPreimage);
1251
+ const commitmentX = bytesToHex(outputHash.slice(0, 16)).padStart(64, '0');
1252
+ const commitmentY = bytesToHex(outputHash.slice(16, 32)).padStart(64, '0');
1253
+
1254
+ const solverSecretField = bytesToField(params.solverSecret);
1255
+
1256
+ // Compute solver ID
1257
+ const solverSecretBytes = hexToBytes(solverSecretField.padStart(64, '0'));
1258
+ const solverIdHash = sha256(solverSecretBytes);
1259
+ const solverId = bytesToHex(solverIdHash);
1260
+
1261
+ const outputBlindingField = bytesToField(params.outputBlinding);
1262
+
1263
+ const attestation = params.oracleAttestation;
1264
+ const attestationRecipientField = hexToField(attestation.recipient);
1265
+ const attestationTxHashField = hexToField(attestation.txHash);
1266
+ const oracleSignature = Array.from(attestation.signature);
1267
+
1268
+ // Compute oracle message hash
1269
+ const recipientBytes = hexToBytes(attestationRecipientField);
1270
+ const attestationAmountBytes = bigintToBytes(attestation.amount, 8);
1271
+ const txHashBytes = hexToBytes(attestationTxHashField);
1272
+ const blockBytes = bigintToBytes(attestation.blockNumber, 8);
1273
+ const oraclePreimage = new Uint8Array([
1274
+ ...recipientBytes,
1275
+ ...attestationAmountBytes,
1276
+ ...txHashBytes,
1277
+ ...blockBytes,
1278
+ ]);
1279
+ const oracleMessageHash = Array.from(sha256(oraclePreimage));
1280
+
1281
+ const oraclePubKeyX = config.oraclePublicKey?.x ?? new Array(32).fill(0);
1282
+ const oraclePubKeyY = config.oraclePublicKey?.y ?? new Array(32).fill(0);
1283
+
1284
+ const witnessInputs = {
1285
+ intent_hash: intentHashField,
1286
+ output_commitment_x: commitmentX,
1287
+ output_commitment_y: commitmentY,
1288
+ recipient_stealth: recipientStealthField,
1289
+ min_output_amount: params.minOutputAmount.toString(),
1290
+ solver_id: solverId,
1291
+ fulfillment_time: params.fulfillmentTime.toString(),
1292
+ expiry: params.expiry.toString(),
1293
+ output_amount: params.outputAmount.toString(),
1294
+ output_blinding: outputBlindingField,
1295
+ solver_secret: solverSecretField,
1296
+ attestation_recipient: attestationRecipientField,
1297
+ attestation_amount: attestation.amount.toString(),
1298
+ attestation_tx_hash: attestationTxHashField,
1299
+ attestation_block: attestation.blockNumber.toString(),
1300
+ oracle_signature: oracleSignature,
1301
+ oracle_message_hash: oracleMessageHash,
1302
+ oracle_pub_key_x: oraclePubKeyX,
1303
+ oracle_pub_key_y: oraclePubKeyY,
1304
+ };
1305
+
1306
+ sendProgress(id, 'witness', 40, 'Executing fulfillment circuit...');
1307
+ const { witness } = await fulfillmentNoir.execute(witnessInputs);
1308
+
1309
+ sendProgress(id, 'proving', 60, 'Generating fulfillment proof...');
1310
+ const proofData = await fulfillmentBackend.generateProof(witness);
1311
+
1312
+ sendProgress(id, 'complete', 100, 'Fulfillment proof generated');
1313
+
1314
+ const publicInputs = [
1315
+ '0x' + intentHashField,
1316
+ '0x' + commitmentX,
1317
+ '0x' + commitmentY,
1318
+ '0x' + recipientStealthField,
1319
+ '0x' + params.minOutputAmount.toString(16).padStart(16, '0'),
1320
+ '0x' + solverId,
1321
+ '0x' + params.fulfillmentTime.toString(16).padStart(16, '0'),
1322
+ '0x' + params.expiry.toString(16).padStart(16, '0'),
1323
+ ];
1324
+
1325
+ const proof = {
1326
+ type: 'fulfillment',
1327
+ proof: '0x' + bytesToHex(proofData.proof),
1328
+ publicInputs,
1329
+ };
1330
+
1331
+ sendSuccess(id, { proof, publicInputs });
1332
+ } catch (error) {
1333
+ sendError(id, error);
1334
+ }
1335
+ }
1336
+
1123
1337
  // Helper functions
1124
1338
  function bytesToField(bytes) {
1125
1339
  let result = 0n;
@@ -1147,6 +1361,39 @@ function createWorkerBlobURL() {
1147
1361
  return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
1148
1362
  }
1149
1363
 
1364
+ function hexToBytes(hex) {
1365
+ const h = hex.startsWith('0x') ? hex.slice(2) : hex;
1366
+ const bytes = new Uint8Array(h.length / 2);
1367
+ for (let i = 0; i < h.length; i += 2) {
1368
+ bytes[i / 2] = parseInt(h.slice(i, i + 2), 16);
1369
+ }
1370
+ return bytes;
1371
+ }
1372
+
1373
+ function hexToField(hex) {
1374
+ const h = hex.startsWith('0x') ? hex.slice(2) : hex;
1375
+ return h.padStart(64, '0');
1376
+ }
1377
+
1378
+ function fieldToBytes32(field) {
1379
+ const hex = field.padStart(64, '0');
1380
+ const bytes = [];
1381
+ for (let i = 0; i < 32; i++) {
1382
+ bytes.push(parseInt(hex.slice(i * 2, i * 2 + 2), 16));
1383
+ }
1384
+ return bytes;
1385
+ }
1386
+
1387
+ function bigintToBytes(value, length) {
1388
+ const bytes = new Uint8Array(length);
1389
+ let v = value;
1390
+ for (let i = length - 1; i >= 0; i--) {
1391
+ bytes[i] = Number(v & 0xffn);
1392
+ v = v >> 8n;
1393
+ }
1394
+ return bytes;
1395
+ }
1396
+
1150
1397
  // Message handler
1151
1398
  self.onmessage = async function(event) {
1152
1399
  const { id, type, params, config: initConfig } = event.data;
@@ -1159,12 +1406,10 @@ function createWorkerBlobURL() {
1159
1406
  await generateFundingProof(id, params);
1160
1407
  break;
1161
1408
  case 'generateValidityProof':
1162
- // TODO: Implement
1163
- sendError(id, new Error('Validity proof not yet implemented in worker'));
1409
+ await generateValidityProof(id, params);
1164
1410
  break;
1165
1411
  case 'generateFulfillmentProof':
1166
- // TODO: Implement
1167
- sendError(id, new Error('Fulfillment proof not yet implemented in worker'));
1412
+ await generateFulfillmentProof(id, params);
1168
1413
  break;
1169
1414
  case 'destroy':
1170
1415
  // Cleanup
@@ -1323,6 +1568,7 @@ export {
1323
1568
  MockWalletAdapter,
1324
1569
  NATIVE_TOKENS,
1325
1570
  NEARIntentsAdapter,
1571
+ NEARIntentsBackend,
1326
1572
  NetworkError,
1327
1573
  ORACLE_DOMAIN,
1328
1574
  OneClickClient,
@@ -1345,13 +1591,18 @@ export {
1345
1591
  STABLECOIN_ADDRESSES,
1346
1592
  STABLECOIN_DECIMALS,
1347
1593
  STABLECOIN_INFO,
1594
+ SettlementRegistry,
1595
+ SettlementRegistryError,
1596
+ SmartRouter,
1348
1597
  SolanaWalletAdapter,
1598
+ SwapStatus,
1349
1599
  Treasury,
1350
1600
  TrezorWalletAdapter,
1351
1601
  ValidationError,
1352
1602
  WalletError,
1353
1603
  WalletErrorCode,
1354
1604
  ZcashErrorCode,
1605
+ ZcashNativeBackend,
1355
1606
  ZcashRPCClient,
1356
1607
  ZcashRPCError,
1357
1608
  ZcashShieldedService,
@@ -1381,16 +1632,19 @@ export {
1381
1632
  createMockSolver,
1382
1633
  createMockTrezorAdapter,
1383
1634
  createNEARIntentsAdapter,
1635
+ createNEARIntentsBackend,
1384
1636
  createOracleRegistry,
1385
1637
  createProductionSIP,
1386
1638
  createSIP,
1387
1639
  createShieldedIntent,
1388
1640
  createShieldedPayment,
1641
+ createSmartRouter,
1389
1642
  createSolanaAdapter,
1390
1643
  createTrezorAdapter,
1391
1644
  createWalletFactory,
1392
1645
  createWorkerBlobURL,
1393
1646
  createZcashClient,
1647
+ createZcashNativeBackend,
1394
1648
  createZcashShieldedService,
1395
1649
  createZcashSwapService,
1396
1650
  decodeStealthMetaAddress,