@secondlayer/stacks 3.3.1 → 4.1.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 (130) hide show
  1. package/README.md +4 -0
  2. package/dist/shared/stacks-1arrcd11.js +48 -0
  3. package/dist/shared/stacks-1arrcd11.js.map +10 -0
  4. package/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
  5. package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
  6. package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
  7. package/dist/shared/stacks-9mqveyjv.cjs.map +2 -2
  8. package/dist/shared/{stacks-8e5atbps.cjs → stacks-9qcr921s.cjs} +49 -5
  9. package/dist/shared/stacks-9qcr921s.cjs.map +10 -0
  10. package/dist/shared/{stacks-r1m1r72q.js → stacks-bw8qvqd1.js} +49 -23
  11. package/dist/shared/stacks-bw8qvqd1.js.map +27 -0
  12. package/dist/shared/stacks-enpj9krt.cjs +38 -0
  13. package/dist/shared/stacks-enpj9krt.cjs.map +10 -0
  14. package/dist/shared/{stacks-s361pmzs.cjs → stacks-fb75yew8.js} +86 -2
  15. package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-fb75yew8.js.map} +6 -4
  16. package/dist/shared/{stacks-rw2xbtdv.js → stacks-gxq2pbky.js} +2 -2
  17. package/dist/shared/{stacks-rw2xbtdv.js.map → stacks-gxq2pbky.js.map} +1 -1
  18. package/dist/shared/{stacks-jx146qf1.js → stacks-hnqt5rz4.js} +27 -377
  19. package/dist/shared/stacks-hnqt5rz4.js.map +13 -0
  20. package/dist/shared/{stacks-v1hzk599.js → stacks-jpt52csy.js} +8 -10
  21. package/dist/shared/stacks-jpt52csy.js.map +10 -0
  22. package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
  23. package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
  24. package/dist/shared/{stacks-bm49tsh0.js → stacks-rpqtgpyj.js} +42 -9
  25. package/dist/shared/stacks-rpqtgpyj.js.map +10 -0
  26. package/dist/shared/{stacks-g2qnr5qn.cjs → stacks-rryme9bv.cjs} +11 -364
  27. package/dist/shared/stacks-rryme9bv.cjs.map +13 -0
  28. package/dist/shared/{stacks-byyex2zk.cjs → stacks-ta1gar0b.cjs} +7 -2
  29. package/dist/shared/{stacks-byyex2zk.cjs.map → stacks-ta1gar0b.cjs.map} +2 -2
  30. package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
  31. package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
  32. package/dist/shared/stacks-vea7nde7.cjs +731 -0
  33. package/dist/shared/stacks-vea7nde7.cjs.map +13 -0
  34. package/dist/shared/stacks-w23294am.js +760 -0
  35. package/dist/shared/stacks-w23294am.js.map +13 -0
  36. package/dist/shared/{stacks-fvnxj77s.cjs → stacks-y4f7fm03.cjs} +33 -13
  37. package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-y4f7fm03.cjs.map} +7 -6
  38. package/dist/src/accounts/index.d.cts +1 -1
  39. package/dist/src/accounts/index.d.ts +1 -1
  40. package/dist/src/actions/index.d.cts +15 -11
  41. package/dist/src/actions/index.d.ts +15 -11
  42. package/dist/src/actions/index.js +21 -25
  43. package/dist/src/actions/index.js.map +1 -1
  44. package/dist/src/bitcoin/index.d.cts +29 -29
  45. package/dist/src/bitcoin/index.d.ts +29 -29
  46. package/dist/src/bitcoin/index.js +5 -6
  47. package/dist/src/bitcoin/index.js.map +2 -2
  48. package/dist/src/bns/index.d.cts +1 -1
  49. package/dist/src/bns/index.d.ts +1 -1
  50. package/dist/src/bns/index.js +9 -10
  51. package/dist/src/bns/index.js.map +2 -2
  52. package/dist/src/clarity/index.d.cts +37 -1
  53. package/dist/src/clarity/index.d.ts +37 -1
  54. package/dist/src/clarity/index.js +14 -2
  55. package/dist/src/clarity/index.js.map +1 -1
  56. package/dist/src/index.cjs.map +2 -2
  57. package/dist/src/index.d.cts +18 -14
  58. package/dist/src/index.d.ts +18 -14
  59. package/dist/src/index.js +22 -27
  60. package/dist/src/index.js.map +3 -3
  61. package/dist/src/postconditions/index.d.cts +66 -3
  62. package/dist/src/postconditions/index.d.ts +66 -3
  63. package/dist/src/postconditions/index.js +13 -3
  64. package/dist/src/postconditions/index.js.map +1 -1
  65. package/dist/src/pox/index.d.cts +1 -1
  66. package/dist/src/pox/index.d.ts +1 -1
  67. package/dist/src/pox/index.js +7 -9
  68. package/dist/src/pox/index.js.map +2 -2
  69. package/dist/src/pox5/index.cjs +213 -14
  70. package/dist/src/pox5/index.cjs.map +8 -7
  71. package/dist/src/pox5/index.d.cts +88 -5
  72. package/dist/src/pox5/index.d.ts +88 -5
  73. package/dist/src/pox5/index.js +222 -21
  74. package/dist/src/pox5/index.js.map +8 -7
  75. package/dist/src/sbtc/index.d.cts +1 -1
  76. package/dist/src/sbtc/index.d.ts +1 -1
  77. package/dist/src/sbtc/index.js +6 -7
  78. package/dist/src/sbtc/index.js.map +2 -2
  79. package/dist/src/stackingdao/index.d.cts +1 -1
  80. package/dist/src/stackingdao/index.d.ts +1 -1
  81. package/dist/src/stackingdao/index.js +7 -9
  82. package/dist/src/stackingdao/index.js.map +2 -2
  83. package/dist/src/subscriptions/index.d.cts +1 -1
  84. package/dist/src/subscriptions/index.d.ts +1 -1
  85. package/dist/src/tools/index.cjs +494 -367
  86. package/dist/src/tools/index.cjs.map +11 -9
  87. package/dist/src/tools/index.d.cts +1 -1
  88. package/dist/src/tools/index.d.ts +1 -1
  89. package/dist/src/tools/index.js +494 -367
  90. package/dist/src/tools/index.js.map +11 -9
  91. package/dist/src/transactions/index.cjs +3 -1
  92. package/dist/src/transactions/index.cjs.map +1 -1
  93. package/dist/src/transactions/index.d.cts +16 -9
  94. package/dist/src/transactions/index.d.ts +16 -9
  95. package/dist/src/transactions/index.js +31 -27
  96. package/dist/src/transactions/index.js.map +1 -1
  97. package/package.json +2 -7
  98. package/dist/shared/stacks-1mpmzzyp.js +0 -85
  99. package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
  100. package/dist/shared/stacks-44y18a8e.cjs +0 -28
  101. package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
  102. package/dist/shared/stacks-8e5atbps.cjs.map +0 -10
  103. package/dist/shared/stacks-8khy9v27.cjs +0 -7
  104. package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
  105. package/dist/shared/stacks-bm49tsh0.js.map +0 -10
  106. package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
  107. package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
  108. package/dist/shared/stacks-fh48neva.js +0 -13
  109. package/dist/shared/stacks-fh48neva.js.map +0 -10
  110. package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
  111. package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
  112. package/dist/shared/stacks-g2qnr5qn.cjs.map +0 -15
  113. package/dist/shared/stacks-gkf9tsws.js +0 -285
  114. package/dist/shared/stacks-gkf9tsws.js.map +0 -10
  115. package/dist/shared/stacks-jx146qf1.js.map +0 -15
  116. package/dist/shared/stacks-qjgh6pqr.cjs +0 -258
  117. package/dist/shared/stacks-qjgh6pqr.cjs.map +0 -10
  118. package/dist/shared/stacks-r1m1r72q.js.map +0 -26
  119. package/dist/shared/stacks-v1hzk599.js.map +0 -10
  120. package/dist/shared/stacks-w8tt1fmt.js +0 -44
  121. package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
  122. package/dist/shared/stacks-z53fwfcm.js +0 -3
  123. package/dist/shared/stacks-z53fwfcm.js.map +0 -9
  124. package/dist/src/x402/index.cjs +0 -65
  125. package/dist/src/x402/index.cjs.map +0 -11
  126. package/dist/src/x402/index.d.cts +0 -501
  127. package/dist/src/x402/index.d.ts +0 -501
  128. package/dist/src/x402/index.js +0 -90
  129. package/dist/src/x402/index.js.map +0 -11
  130. /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
@@ -402,7 +402,8 @@ var AnchorMode = {
402
402
  };
403
403
  var PostConditionModeWire = {
404
404
  Allow: 1,
405
- Deny: 2
405
+ Deny: 2,
406
+ Originator: 3
406
407
  };
407
408
  var AddressHashMode = {
408
409
  P2PKH: 0,
@@ -425,7 +426,8 @@ var FungibleConditionCode = {
425
426
  };
426
427
  var NonFungibleConditionCode = {
427
428
  Sends: 16,
428
- DoesNotSend: 17
429
+ DoesNotSend: 17,
430
+ MaybeSent: 18
429
431
  };
430
432
  var PoxConditionCode = {
431
433
  WillNotPerform: 48,
@@ -519,7 +521,7 @@ function serializePrincipal(principal) {
519
521
  function serializeAssetInfo(asset) {
520
522
  return concatBytes(serializeAddress2(asset.address), serializeLPString2(asset.contractName), serializeLPString2(asset.assetName));
521
523
  }
522
- function serializePostCondition(pc) {
524
+ function serializePostConditionWire(pc) {
523
525
  const parts = [];
524
526
  switch (pc.type) {
525
527
  case "stx":
@@ -558,9 +560,8 @@ function serializePostCondition(pc) {
558
560
  }
559
561
  function serializePostConditions(pcs) {
560
562
  const parts = [writeUInt32BE(pcs.length)];
561
- for (const pc of pcs) {
562
- parts.push(serializePostCondition(pc));
563
- }
563
+ for (const pc of pcs)
564
+ parts.push(serializePostConditionWire(pc));
564
565
  return concatBytes(...parts);
565
566
  }
566
567
  function serializePayload(payload) {
@@ -1301,6 +1302,441 @@ function clarityValueToJSInner(abiType, cv) {
1301
1302
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1302
1303
  }
1303
1304
 
1305
+ // src/transactions/wire/deserialize.ts
1306
+ function readSpendingCondition(r) {
1307
+ const hashMode = r.readUInt8();
1308
+ const signer = bytesToHex(r.readBytes(20));
1309
+ const nonce = r.readBigUInt64BE();
1310
+ const fee = r.readBigUInt64BE();
1311
+ if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {
1312
+ const keyEncoding = r.readUInt8();
1313
+ const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
1314
+ return {
1315
+ hashMode,
1316
+ signer,
1317
+ nonce,
1318
+ fee,
1319
+ keyEncoding,
1320
+ signature
1321
+ };
1322
+ }
1323
+ const fieldCount = r.readUInt32BE();
1324
+ const fields = [];
1325
+ for (let i = 0;i < fieldCount; i++) {
1326
+ const fieldType = r.readUInt8();
1327
+ if (fieldType <= 1) {
1328
+ const keyLen = fieldType === 0 ? 33 : 65;
1329
+ fields.push({
1330
+ type: "publicKey",
1331
+ pubKeyEncoding: fieldType,
1332
+ data: bytesToHex(r.readBytes(keyLen))
1333
+ });
1334
+ } else {
1335
+ fields.push({
1336
+ type: "signature",
1337
+ pubKeyEncoding: fieldType === 2 ? 0 : 1,
1338
+ data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES))
1339
+ });
1340
+ }
1341
+ }
1342
+ const signaturesRequired = r.readUInt16BE();
1343
+ return {
1344
+ hashMode,
1345
+ signer,
1346
+ nonce,
1347
+ fee,
1348
+ fields,
1349
+ signaturesRequired
1350
+ };
1351
+ }
1352
+ function readAuthorization(r) {
1353
+ const authType = r.readUInt8();
1354
+ const spendingCondition = readSpendingCondition(r);
1355
+ if (authType === AuthType.Standard) {
1356
+ return { authType: AuthType.Standard, spendingCondition };
1357
+ }
1358
+ const sponsorSpendingCondition = readSpendingCondition(r);
1359
+ return {
1360
+ authType: AuthType.Sponsored,
1361
+ spendingCondition,
1362
+ sponsorSpendingCondition
1363
+ };
1364
+ }
1365
+ function readAssetInfo(r) {
1366
+ return {
1367
+ address: readAddress(r),
1368
+ contractName: readLPString(r),
1369
+ assetName: readLPString(r)
1370
+ };
1371
+ }
1372
+ function readPostConditionPrincipal(r) {
1373
+ const type = r.readUInt8();
1374
+ switch (type) {
1375
+ case PostConditionPrincipalId.Origin:
1376
+ return { type: "origin" };
1377
+ case PostConditionPrincipalId.Standard:
1378
+ return { type: "standard", address: readAddress(r) };
1379
+ case PostConditionPrincipalId.Contract:
1380
+ return {
1381
+ type: "contract",
1382
+ address: readAddress(r),
1383
+ contractName: readLPString(r)
1384
+ };
1385
+ default:
1386
+ return { type: "origin" };
1387
+ }
1388
+ }
1389
+ function readPostCondition(r) {
1390
+ const assetType = r.readUInt8();
1391
+ const principal = readPostConditionPrincipal(r);
1392
+ switch (assetType) {
1393
+ case AssetType.STX:
1394
+ return {
1395
+ type: "stx",
1396
+ principal,
1397
+ conditionCode: r.readUInt8(),
1398
+ amount: r.readBigUInt64BE()
1399
+ };
1400
+ case AssetType.Fungible:
1401
+ return {
1402
+ type: "ft",
1403
+ principal,
1404
+ asset: readAssetInfo(r),
1405
+ conditionCode: r.readUInt8(),
1406
+ amount: r.readBigUInt64BE()
1407
+ };
1408
+ case AssetType.NonFungible:
1409
+ return {
1410
+ type: "nft",
1411
+ principal,
1412
+ asset: readAssetInfo(r),
1413
+ assetId: readCV(r),
1414
+ conditionCode: r.readUInt8()
1415
+ };
1416
+ case AssetType.Staking:
1417
+ return {
1418
+ type: "staking",
1419
+ principal,
1420
+ conditionCode: r.readUInt8(),
1421
+ amount: r.readBigUInt64BE()
1422
+ };
1423
+ case AssetType.Pox:
1424
+ return {
1425
+ type: "pox",
1426
+ principal,
1427
+ conditionCode: r.readUInt8()
1428
+ };
1429
+ default:
1430
+ throw new Error(`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, "0")}`);
1431
+ }
1432
+ }
1433
+ function readPostConditions(r) {
1434
+ const count = r.readUInt32BE();
1435
+ const pcs = [];
1436
+ for (let i = 0;i < count; i++) {
1437
+ try {
1438
+ pcs.push(readPostCondition(r));
1439
+ } catch (e) {
1440
+ if (e instanceof Error && e.message.startsWith("Unknown post-condition asset type:")) {
1441
+ throw new Error(`${e.message} (post-condition ${i + 1}/${count})`);
1442
+ }
1443
+ throw e;
1444
+ }
1445
+ }
1446
+ return pcs;
1447
+ }
1448
+ function readPayload(r) {
1449
+ const payloadType = r.readUInt8();
1450
+ switch (payloadType) {
1451
+ case PayloadType.TokenTransfer: {
1452
+ const recipient = readCV(r);
1453
+ const amount = r.readBigUInt64BE();
1454
+ const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
1455
+ const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
1456
+ return {
1457
+ payloadType: PayloadType.TokenTransfer,
1458
+ recipient,
1459
+ amount,
1460
+ memo
1461
+ };
1462
+ }
1463
+ case PayloadType.ContractCall: {
1464
+ const contractAddress = readAddress(r);
1465
+ const contractName = readLPString(r);
1466
+ const functionName = readLPString(r);
1467
+ const numArgs = r.readUInt32BE();
1468
+ const functionArgs = [];
1469
+ for (let i = 0;i < numArgs; i++)
1470
+ functionArgs.push(readCV(r));
1471
+ return {
1472
+ payloadType: PayloadType.ContractCall,
1473
+ contractAddress,
1474
+ contractName,
1475
+ functionName,
1476
+ functionArgs
1477
+ };
1478
+ }
1479
+ case PayloadType.SmartContract: {
1480
+ const contractName = readLPString(r);
1481
+ const codeBody = readLPString(r, 4);
1482
+ return { payloadType: PayloadType.SmartContract, contractName, codeBody };
1483
+ }
1484
+ case PayloadType.VersionedSmartContract: {
1485
+ const clarityVersion = r.readUInt8();
1486
+ const contractName = readLPString(r);
1487
+ const codeBody = readLPString(r, 4);
1488
+ return {
1489
+ payloadType: PayloadType.VersionedSmartContract,
1490
+ clarityVersion,
1491
+ contractName,
1492
+ codeBody
1493
+ };
1494
+ }
1495
+ case PayloadType.Coinbase: {
1496
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1497
+ return { payloadType: PayloadType.Coinbase, coinbaseBuffer };
1498
+ }
1499
+ case PayloadType.CoinbaseToAltRecipient: {
1500
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1501
+ const recipient = readCV(r);
1502
+ return {
1503
+ payloadType: PayloadType.CoinbaseToAltRecipient,
1504
+ coinbaseBuffer,
1505
+ recipient
1506
+ };
1507
+ }
1508
+ case PayloadType.PoisonMicroblock: {
1509
+ const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
1510
+ const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
1511
+ return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };
1512
+ }
1513
+ case PayloadType.TenureChange: {
1514
+ const tenureConsensusHash = bytesToHex(r.readBytes(20));
1515
+ const prevTenureConsensusHash = bytesToHex(r.readBytes(20));
1516
+ const burnViewConsensusHash = bytesToHex(r.readBytes(20));
1517
+ const previousTenureEnd = bytesToHex(r.readBytes(32));
1518
+ const previousTenureBlocks = r.readUInt32BE();
1519
+ const cause = r.readUInt8();
1520
+ const pubkeyHash = bytesToHex(r.readBytes(20));
1521
+ return {
1522
+ payloadType: PayloadType.TenureChange,
1523
+ tenureConsensusHash,
1524
+ prevTenureConsensusHash,
1525
+ burnViewConsensusHash,
1526
+ previousTenureEnd,
1527
+ previousTenureBlocks,
1528
+ cause,
1529
+ pubkeyHash
1530
+ };
1531
+ }
1532
+ case PayloadType.NakamotoCoinbase: {
1533
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1534
+ const optionalCV = readCV(r);
1535
+ const recipient = optionalCV.type === "none" ? null : optionalCV.type === "some" ? optionalCV.value : optionalCV;
1536
+ const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));
1537
+ return {
1538
+ payloadType: PayloadType.NakamotoCoinbase,
1539
+ coinbaseBuffer,
1540
+ recipient,
1541
+ vrfProof
1542
+ };
1543
+ }
1544
+ default:
1545
+ throw new Error(`Unknown payload type: ${payloadType}`);
1546
+ }
1547
+ }
1548
+ function deserializePostConditionWire(input) {
1549
+ const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
1550
+ return readPostCondition(new BytesReader(bytes));
1551
+ }
1552
+ function deserializeTransaction(input, meta) {
1553
+ const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
1554
+ const r = new BytesReader(bytes);
1555
+ const tx = {
1556
+ version: r.readUInt8(),
1557
+ chainId: r.readUInt32BE(),
1558
+ auth: readAuthorization(r),
1559
+ anchorMode: r.readUInt8(),
1560
+ postConditionMode: r.readUInt8(),
1561
+ postConditions: readPostConditions(r),
1562
+ payload: readPayload(r)
1563
+ };
1564
+ if (meta?._multisig) {
1565
+ tx._multisig = meta._multisig;
1566
+ }
1567
+ return tx;
1568
+ }
1569
+
1570
+ // src/postconditions/convert.ts
1571
+ var MAX_U64 = 18446744073709551615n;
1572
+ function parsePostConditionAmount(amount) {
1573
+ const value = intToBigInt(amount);
1574
+ if (value < 0n || value > MAX_U64) {
1575
+ throw new RangeError(`Post-condition amount must be between 0 and ${MAX_U64} (u64 max), received: ${value}`);
1576
+ }
1577
+ return value;
1578
+ }
1579
+ var FUNGIBLE_CODE_MAP = {
1580
+ eq: FungibleConditionCode.Equal,
1581
+ gt: FungibleConditionCode.Greater,
1582
+ gte: FungibleConditionCode.GreaterEqual,
1583
+ lt: FungibleConditionCode.Less,
1584
+ lte: FungibleConditionCode.LessEqual
1585
+ };
1586
+ var FUNGIBLE_CODE_REVERSE = {
1587
+ [FungibleConditionCode.Equal]: "eq",
1588
+ [FungibleConditionCode.Greater]: "gt",
1589
+ [FungibleConditionCode.GreaterEqual]: "gte",
1590
+ [FungibleConditionCode.Less]: "lt",
1591
+ [FungibleConditionCode.LessEqual]: "lte"
1592
+ };
1593
+ var NFT_CODE_MAP = {
1594
+ sent: NonFungibleConditionCode.Sends,
1595
+ "not-sent": NonFungibleConditionCode.DoesNotSend,
1596
+ "maybe-sent": NonFungibleConditionCode.MaybeSent
1597
+ };
1598
+ var NFT_CODE_REVERSE = {
1599
+ [NonFungibleConditionCode.Sends]: "sent",
1600
+ [NonFungibleConditionCode.DoesNotSend]: "not-sent",
1601
+ [NonFungibleConditionCode.MaybeSent]: "maybe-sent"
1602
+ };
1603
+ var POX_CODE_MAP = {
1604
+ "will-not-perform": PoxConditionCode.WillNotPerform,
1605
+ "may-perform": PoxConditionCode.MayPerform,
1606
+ "will-perform": PoxConditionCode.WillPerform
1607
+ };
1608
+ var POX_CODE_REVERSE = {
1609
+ [PoxConditionCode.WillNotPerform]: "will-not-perform",
1610
+ [PoxConditionCode.MayPerform]: "may-perform",
1611
+ [PoxConditionCode.WillPerform]: "will-perform"
1612
+ };
1613
+ function resolvePrincipal(address) {
1614
+ if (address === "origin")
1615
+ return { type: "origin" };
1616
+ const [addr, name] = address.split(".");
1617
+ if (name) {
1618
+ return { type: "contract", address: addr, contractName: name };
1619
+ }
1620
+ return { type: "standard", address: addr };
1621
+ }
1622
+ function principalToString(principal) {
1623
+ if (principal.type === "origin")
1624
+ return "origin";
1625
+ if (principal.type === "contract") {
1626
+ return `${principal.address}.${principal.contractName}`;
1627
+ }
1628
+ return principal.address;
1629
+ }
1630
+ function assetToString(asset) {
1631
+ return `${asset.address}.${asset.contractName}::${asset.assetName}`;
1632
+ }
1633
+ function parseAsset(asset) {
1634
+ const [contractId, tokenName] = asset.split("::");
1635
+ const [addr, name] = parseContractId(contractId);
1636
+ return { address: addr, contractName: name, assetName: tokenName };
1637
+ }
1638
+ function convertPostCondition(pc) {
1639
+ switch (pc.type) {
1640
+ case "stx-postcondition":
1641
+ return {
1642
+ type: "stx",
1643
+ principal: resolvePrincipal(pc.address),
1644
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1645
+ amount: parsePostConditionAmount(pc.amount)
1646
+ };
1647
+ case "ft-postcondition":
1648
+ return {
1649
+ type: "ft",
1650
+ principal: resolvePrincipal(pc.address),
1651
+ asset: parseAsset(pc.asset),
1652
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1653
+ amount: parsePostConditionAmount(pc.amount)
1654
+ };
1655
+ case "nft-postcondition":
1656
+ return {
1657
+ type: "nft",
1658
+ principal: resolvePrincipal(pc.address),
1659
+ asset: parseAsset(pc.asset),
1660
+ conditionCode: NFT_CODE_MAP[pc.condition],
1661
+ assetId: pc.assetId
1662
+ };
1663
+ case "staking-postcondition":
1664
+ return {
1665
+ type: "staking",
1666
+ principal: resolvePrincipal(pc.address),
1667
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1668
+ amount: parsePostConditionAmount(pc.amount)
1669
+ };
1670
+ case "pox-postcondition":
1671
+ return {
1672
+ type: "pox",
1673
+ principal: resolvePrincipal(pc.address),
1674
+ conditionCode: POX_CODE_MAP[pc.condition]
1675
+ };
1676
+ }
1677
+ }
1678
+ function wireToPostCondition(wire) {
1679
+ switch (wire.type) {
1680
+ case "stx":
1681
+ return {
1682
+ type: "stx-postcondition",
1683
+ address: principalToString(wire.principal),
1684
+ condition: fungibleName(wire.conditionCode),
1685
+ amount: wire.amount.toString()
1686
+ };
1687
+ case "ft":
1688
+ return {
1689
+ type: "ft-postcondition",
1690
+ address: principalToString(wire.principal),
1691
+ condition: fungibleName(wire.conditionCode),
1692
+ amount: wire.amount.toString(),
1693
+ asset: assetToString(wire.asset)
1694
+ };
1695
+ case "nft":
1696
+ return {
1697
+ type: "nft-postcondition",
1698
+ address: principalToString(wire.principal),
1699
+ condition: nftName(wire.conditionCode),
1700
+ asset: assetToString(wire.asset),
1701
+ assetId: wire.assetId
1702
+ };
1703
+ case "staking":
1704
+ return {
1705
+ type: "staking-postcondition",
1706
+ address: principalToString(wire.principal),
1707
+ condition: fungibleName(wire.conditionCode),
1708
+ amount: wire.amount.toString()
1709
+ };
1710
+ case "pox":
1711
+ return {
1712
+ type: "pox-postcondition",
1713
+ address: principalToString(wire.principal),
1714
+ condition: poxName(wire.conditionCode)
1715
+ };
1716
+ }
1717
+ }
1718
+ function fungibleName(code) {
1719
+ const name = FUNGIBLE_CODE_REVERSE[code];
1720
+ if (!name)
1721
+ throw new Error(`Unknown fungible post-condition code: ${code}`);
1722
+ return name;
1723
+ }
1724
+ function nftName(code) {
1725
+ const name = NFT_CODE_REVERSE[code];
1726
+ if (!name)
1727
+ throw new Error(`Unknown nft post-condition code: ${code}`);
1728
+ return name;
1729
+ }
1730
+ function poxName(code) {
1731
+ const name = POX_CODE_REVERSE[code];
1732
+ if (!name)
1733
+ throw new Error(`Unknown pox post-condition code: ${code}`);
1734
+ return name;
1735
+ }
1736
+ function fromHex(hex) {
1737
+ return wireToPostCondition(deserializePostConditionWire(hex));
1738
+ }
1739
+
1304
1740
  // src/transactions/authorization.ts
1305
1741
  import { hmac } from "@noble/hashes/hmac.js";
1306
1742
  import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
@@ -1373,112 +1809,49 @@ function sigHashPreSign(curSigHash, authType, fee, nonce) {
1373
1809
  }
1374
1810
 
1375
1811
  // src/transactions/multisig.ts
1376
- import {
1377
- getPublicKey as nobleGetPublicKey2,
1378
- sign as nobleSign
1379
- } from "@noble/secp256k1";
1380
- var OP_CHECKMULTISIG = 174;
1381
- function makeRedeemScript(publicKeys, signaturesRequired) {
1382
- const parts = [];
1383
- parts.push(new Uint8Array([80 + signaturesRequired]));
1384
- for (const pk of publicKeys) {
1385
- const pkBytes = hexToBytes(pk);
1386
- parts.push(new Uint8Array([pkBytes.length]));
1387
- parts.push(pkBytes);
1388
- }
1389
- parts.push(new Uint8Array([80 + publicKeys.length]));
1390
- parts.push(new Uint8Array([OP_CHECKMULTISIG]));
1391
- return concatBytes(...parts);
1392
- }
1393
- function createMultiSigSpendingCondition(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode.P2SH) {
1394
- const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
1395
- const signer = bytesToHex(hash160(redeemScript));
1396
- return {
1397
- hashMode,
1398
- signer,
1399
- nonce,
1400
- fee,
1401
- fields: [],
1402
- signaturesRequired
1403
- };
1404
- }
1405
-
1406
- // src/transactions/build.ts
1407
- function resolvePcMode(mode) {
1408
- return mode === "allow" ? PostConditionModeWire.Allow : PostConditionModeWire.Deny;
1409
- }
1410
- function convertPostConditions(pcs) {
1411
- if (!pcs || pcs.length === 0)
1412
- return [];
1413
- return pcs.map(convertPostCondition);
1414
- }
1415
- function resolvePrincipal(address) {
1416
- if (address === "origin")
1417
- return { type: "origin" };
1418
- const [addr, name] = address.split(".");
1419
- if (name) {
1420
- return { type: "contract", address: addr, contractName: name };
1421
- }
1422
- return { type: "standard", address: addr };
1423
- }
1424
- var FUNGIBLE_CODE_MAP = {
1425
- eq: FungibleConditionCode.Equal,
1426
- gt: FungibleConditionCode.Greater,
1427
- gte: FungibleConditionCode.GreaterEqual,
1428
- lt: FungibleConditionCode.Less,
1429
- lte: FungibleConditionCode.LessEqual
1430
- };
1431
- function convertPostCondition(pc) {
1432
- switch (pc.type) {
1433
- case "stx-postcondition":
1434
- return {
1435
- type: "stx",
1436
- principal: resolvePrincipal(pc.address),
1437
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1438
- amount: intToBigInt(pc.amount)
1439
- };
1440
- case "ft-postcondition": {
1441
- const [contractId, tokenName] = pc.asset.split("::");
1442
- const [addr, name] = parseContractId(contractId);
1443
- return {
1444
- type: "ft",
1445
- principal: resolvePrincipal(pc.address),
1446
- asset: { address: addr, contractName: name, assetName: tokenName },
1447
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1448
- amount: intToBigInt(pc.amount)
1449
- };
1450
- }
1451
- case "nft-postcondition": {
1452
- const [contractId, tokenName] = pc.asset.split("::");
1453
- const [addr, name] = parseContractId(contractId);
1454
- return {
1455
- type: "nft",
1456
- principal: resolvePrincipal(pc.address),
1457
- asset: { address: addr, contractName: name, assetName: tokenName },
1458
- conditionCode: pc.condition === "sent" ? NonFungibleConditionCode.Sends : NonFungibleConditionCode.DoesNotSend,
1459
- assetId: pc.assetId
1460
- };
1461
- }
1462
- case "staking-postcondition":
1463
- return {
1464
- type: "staking",
1465
- principal: resolvePrincipal(pc.address),
1466
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1467
- amount: intToBigInt(pc.amount)
1468
- };
1469
- case "pox-postcondition":
1470
- return {
1471
- type: "pox",
1472
- principal: resolvePrincipal(pc.address),
1473
- conditionCode: POX_CODE_MAP[pc.condition]
1474
- };
1812
+ import {
1813
+ getPublicKey as nobleGetPublicKey2,
1814
+ sign as nobleSign
1815
+ } from "@noble/secp256k1";
1816
+ var OP_CHECKMULTISIG = 174;
1817
+ function makeRedeemScript(publicKeys, signaturesRequired) {
1818
+ const parts = [];
1819
+ parts.push(new Uint8Array([80 + signaturesRequired]));
1820
+ for (const pk of publicKeys) {
1821
+ const pkBytes = hexToBytes(pk);
1822
+ parts.push(new Uint8Array([pkBytes.length]));
1823
+ parts.push(pkBytes);
1475
1824
  }
1825
+ parts.push(new Uint8Array([80 + publicKeys.length]));
1826
+ parts.push(new Uint8Array([OP_CHECKMULTISIG]));
1827
+ return concatBytes(...parts);
1828
+ }
1829
+ function createMultiSigSpendingCondition(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode.P2SH) {
1830
+ const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
1831
+ const signer = bytesToHex(hash160(redeemScript));
1832
+ return {
1833
+ hashMode,
1834
+ signer,
1835
+ nonce,
1836
+ fee,
1837
+ fields: [],
1838
+ signaturesRequired
1839
+ };
1840
+ }
1841
+
1842
+ // src/transactions/build.ts
1843
+ function resolvePcMode(mode) {
1844
+ if (mode === "allow")
1845
+ return PostConditionModeWire.Allow;
1846
+ if (mode === "originator")
1847
+ return PostConditionModeWire.Originator;
1848
+ return PostConditionModeWire.Deny;
1849
+ }
1850
+ function convertPostConditions(pcs) {
1851
+ if (!pcs || pcs.length === 0)
1852
+ return [];
1853
+ return pcs.map((pc) => convertPostCondition(typeof pc === "string" ? fromHex(pc) : pc));
1476
1854
  }
1477
- var POX_CODE_MAP = {
1478
- "will-not-perform": PoxConditionCode.WillNotPerform,
1479
- "may-perform": PoxConditionCode.MayPerform,
1480
- "will-perform": PoxConditionCode.WillPerform
1481
- };
1482
1855
  function resolveSpendingCondition(opts, nonce, fee) {
1483
1856
  if (opts.publicKeys) {
1484
1857
  return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
@@ -1979,6 +2352,16 @@ class ContractResponseError extends Error {
1979
2352
  this.errorValue = errorValue;
1980
2353
  }
1981
2354
  }
2355
+ // src/clarity/structuredData.ts
2356
+ import { sha256 as sha2564 } from "@noble/hashes/sha2.js";
2357
+ var SIP018_PREFIX = new Uint8Array([
2358
+ 83,
2359
+ 73,
2360
+ 80,
2361
+ 48,
2362
+ 49,
2363
+ 56
2364
+ ]);
1982
2365
  // src/clarity/abi/standards.ts
1983
2366
  var SIP010_ABI = {
1984
2367
  functions: [
@@ -2515,262 +2898,6 @@ async function getPrimaryName(client, address) {
2515
2898
  }
2516
2899
  }
2517
2900
 
2518
- // src/transactions/wire/deserialize.ts
2519
- function readSpendingCondition(r) {
2520
- const hashMode = r.readUInt8();
2521
- const signer = bytesToHex(r.readBytes(20));
2522
- const nonce = r.readBigUInt64BE();
2523
- const fee = r.readBigUInt64BE();
2524
- if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {
2525
- const keyEncoding = r.readUInt8();
2526
- const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
2527
- return {
2528
- hashMode,
2529
- signer,
2530
- nonce,
2531
- fee,
2532
- keyEncoding,
2533
- signature
2534
- };
2535
- }
2536
- const fieldCount = r.readUInt32BE();
2537
- const fields = [];
2538
- for (let i = 0;i < fieldCount; i++) {
2539
- const fieldType = r.readUInt8();
2540
- if (fieldType <= 1) {
2541
- const keyLen = fieldType === 0 ? 33 : 65;
2542
- fields.push({
2543
- type: "publicKey",
2544
- pubKeyEncoding: fieldType,
2545
- data: bytesToHex(r.readBytes(keyLen))
2546
- });
2547
- } else {
2548
- fields.push({
2549
- type: "signature",
2550
- pubKeyEncoding: fieldType === 2 ? 0 : 1,
2551
- data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES))
2552
- });
2553
- }
2554
- }
2555
- const signaturesRequired = r.readUInt16BE();
2556
- return {
2557
- hashMode,
2558
- signer,
2559
- nonce,
2560
- fee,
2561
- fields,
2562
- signaturesRequired
2563
- };
2564
- }
2565
- function readAuthorization(r) {
2566
- const authType = r.readUInt8();
2567
- const spendingCondition = readSpendingCondition(r);
2568
- if (authType === AuthType.Standard) {
2569
- return { authType: AuthType.Standard, spendingCondition };
2570
- }
2571
- const sponsorSpendingCondition = readSpendingCondition(r);
2572
- return {
2573
- authType: AuthType.Sponsored,
2574
- spendingCondition,
2575
- sponsorSpendingCondition
2576
- };
2577
- }
2578
- function readAssetInfo(r) {
2579
- return {
2580
- address: readAddress(r),
2581
- contractName: readLPString(r),
2582
- assetName: readLPString(r)
2583
- };
2584
- }
2585
- function readPostConditionPrincipal(r) {
2586
- const type = r.readUInt8();
2587
- switch (type) {
2588
- case PostConditionPrincipalId.Origin:
2589
- return { type: "origin" };
2590
- case PostConditionPrincipalId.Standard:
2591
- return { type: "standard", address: readAddress(r) };
2592
- case PostConditionPrincipalId.Contract:
2593
- return {
2594
- type: "contract",
2595
- address: readAddress(r),
2596
- contractName: readLPString(r)
2597
- };
2598
- default:
2599
- return { type: "origin" };
2600
- }
2601
- }
2602
- function readPostConditions(r) {
2603
- const count = r.readUInt32BE();
2604
- const pcs = [];
2605
- for (let i = 0;i < count; i++) {
2606
- const assetType = r.readUInt8();
2607
- const principal = readPostConditionPrincipal(r);
2608
- switch (assetType) {
2609
- case AssetType.STX:
2610
- pcs.push({
2611
- type: "stx",
2612
- principal,
2613
- conditionCode: r.readUInt8(),
2614
- amount: r.readBigUInt64BE()
2615
- });
2616
- break;
2617
- case AssetType.Fungible:
2618
- pcs.push({
2619
- type: "ft",
2620
- principal,
2621
- asset: readAssetInfo(r),
2622
- conditionCode: r.readUInt8(),
2623
- amount: r.readBigUInt64BE()
2624
- });
2625
- break;
2626
- case AssetType.NonFungible:
2627
- pcs.push({
2628
- type: "nft",
2629
- principal,
2630
- asset: readAssetInfo(r),
2631
- assetId: readCV(r),
2632
- conditionCode: r.readUInt8()
2633
- });
2634
- break;
2635
- case AssetType.Staking:
2636
- pcs.push({
2637
- type: "staking",
2638
- principal,
2639
- conditionCode: r.readUInt8(),
2640
- amount: r.readBigUInt64BE()
2641
- });
2642
- break;
2643
- case AssetType.Pox:
2644
- pcs.push({
2645
- type: "pox",
2646
- principal,
2647
- conditionCode: r.readUInt8()
2648
- });
2649
- break;
2650
- default:
2651
- throw new Error(`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, "0")} (post-condition ${i + 1}/${count})`);
2652
- }
2653
- }
2654
- return pcs;
2655
- }
2656
- function readPayload(r) {
2657
- const payloadType = r.readUInt8();
2658
- switch (payloadType) {
2659
- case PayloadType.TokenTransfer: {
2660
- const recipient = readCV(r);
2661
- const amount = r.readBigUInt64BE();
2662
- const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
2663
- const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
2664
- return {
2665
- payloadType: PayloadType.TokenTransfer,
2666
- recipient,
2667
- amount,
2668
- memo
2669
- };
2670
- }
2671
- case PayloadType.ContractCall: {
2672
- const contractAddress = readAddress(r);
2673
- const contractName = readLPString(r);
2674
- const functionName = readLPString(r);
2675
- const numArgs = r.readUInt32BE();
2676
- const functionArgs = [];
2677
- for (let i = 0;i < numArgs; i++)
2678
- functionArgs.push(readCV(r));
2679
- return {
2680
- payloadType: PayloadType.ContractCall,
2681
- contractAddress,
2682
- contractName,
2683
- functionName,
2684
- functionArgs
2685
- };
2686
- }
2687
- case PayloadType.SmartContract: {
2688
- const contractName = readLPString(r);
2689
- const codeBody = readLPString(r, 4);
2690
- return { payloadType: PayloadType.SmartContract, contractName, codeBody };
2691
- }
2692
- case PayloadType.VersionedSmartContract: {
2693
- const clarityVersion = r.readUInt8();
2694
- const contractName = readLPString(r);
2695
- const codeBody = readLPString(r, 4);
2696
- return {
2697
- payloadType: PayloadType.VersionedSmartContract,
2698
- clarityVersion,
2699
- contractName,
2700
- codeBody
2701
- };
2702
- }
2703
- case PayloadType.Coinbase: {
2704
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2705
- return { payloadType: PayloadType.Coinbase, coinbaseBuffer };
2706
- }
2707
- case PayloadType.CoinbaseToAltRecipient: {
2708
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2709
- const recipient = readCV(r);
2710
- return {
2711
- payloadType: PayloadType.CoinbaseToAltRecipient,
2712
- coinbaseBuffer,
2713
- recipient
2714
- };
2715
- }
2716
- case PayloadType.PoisonMicroblock: {
2717
- const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
2718
- const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
2719
- return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };
2720
- }
2721
- case PayloadType.TenureChange: {
2722
- const tenureConsensusHash = bytesToHex(r.readBytes(20));
2723
- const prevTenureConsensusHash = bytesToHex(r.readBytes(20));
2724
- const burnViewConsensusHash = bytesToHex(r.readBytes(20));
2725
- const previousTenureEnd = bytesToHex(r.readBytes(32));
2726
- const previousTenureBlocks = r.readUInt32BE();
2727
- const cause = r.readUInt8();
2728
- const pubkeyHash = bytesToHex(r.readBytes(20));
2729
- return {
2730
- payloadType: PayloadType.TenureChange,
2731
- tenureConsensusHash,
2732
- prevTenureConsensusHash,
2733
- burnViewConsensusHash,
2734
- previousTenureEnd,
2735
- previousTenureBlocks,
2736
- cause,
2737
- pubkeyHash
2738
- };
2739
- }
2740
- case PayloadType.NakamotoCoinbase: {
2741
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2742
- const optionalCV = readCV(r);
2743
- const recipient = optionalCV.type === "none" ? null : optionalCV.type === "some" ? optionalCV.value : optionalCV;
2744
- const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));
2745
- return {
2746
- payloadType: PayloadType.NakamotoCoinbase,
2747
- coinbaseBuffer,
2748
- recipient,
2749
- vrfProof
2750
- };
2751
- }
2752
- default:
2753
- throw new Error(`Unknown payload type: ${payloadType}`);
2754
- }
2755
- }
2756
- function deserializeTransaction(input, meta) {
2757
- const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
2758
- const r = new BytesReader(bytes);
2759
- const tx = {
2760
- version: r.readUInt8(),
2761
- chainId: r.readUInt32BE(),
2762
- auth: readAuthorization(r),
2763
- anchorMode: r.readUInt8(),
2764
- postConditionMode: r.readUInt8(),
2765
- postConditions: readPostConditions(r),
2766
- payload: readPayload(r)
2767
- };
2768
- if (meta?._multisig) {
2769
- tx._multisig = meta._multisig;
2770
- }
2771
- return tx;
2772
- }
2773
-
2774
2901
  // src/chains/definitions.ts
2775
2902
  var mainnet = {
2776
2903
  id: 1,
@@ -3442,5 +3569,5 @@ export {
3442
3569
  bnsResolve
3443
3570
  };
3444
3571
 
3445
- //# debugId=16EF5FF1D953A99864756E2164756E21
3572
+ //# debugId=2F350AD9DF4B435964756E2164756E21
3446
3573
  //# sourceMappingURL=index.js.map