@secondlayer/stacks 4.0.0 → 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 (100) 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-9mqveyjv.cjs.map +2 -2
  5. package/dist/shared/{stacks-dr5en54r.cjs → stacks-9qcr921s.cjs} +42 -5
  6. package/dist/shared/stacks-9qcr921s.cjs.map +10 -0
  7. package/dist/shared/{stacks-thkhfwz8.js → stacks-bw8qvqd1.js} +18 -22
  8. package/dist/shared/{stacks-thkhfwz8.js.map → stacks-bw8qvqd1.js.map} +5 -5
  9. package/dist/shared/stacks-enpj9krt.cjs +38 -0
  10. package/dist/shared/stacks-enpj9krt.cjs.map +10 -0
  11. package/dist/shared/{stacks-90jcxs98.js → stacks-fb75yew8.js} +8 -6
  12. package/dist/shared/{stacks-90jcxs98.js.map → stacks-fb75yew8.js.map} +3 -3
  13. package/dist/shared/{stacks-rw2xbtdv.js → stacks-gxq2pbky.js} +2 -2
  14. package/dist/shared/{stacks-rw2xbtdv.js.map → stacks-gxq2pbky.js.map} +1 -1
  15. package/dist/shared/{stacks-jx146qf1.js → stacks-hnqt5rz4.js} +27 -377
  16. package/dist/shared/stacks-hnqt5rz4.js.map +13 -0
  17. package/dist/shared/{stacks-z3vztaz1.js → stacks-jpt52csy.js} +3 -3
  18. package/dist/shared/stacks-jpt52csy.js.map +10 -0
  19. package/dist/shared/{stacks-fse1f76h.js → stacks-rpqtgpyj.js} +42 -8
  20. package/dist/shared/stacks-rpqtgpyj.js.map +10 -0
  21. package/dist/shared/{stacks-g2qnr5qn.cjs → stacks-rryme9bv.cjs} +11 -364
  22. package/dist/shared/stacks-rryme9bv.cjs.map +13 -0
  23. package/dist/shared/{stacks-byyex2zk.cjs → stacks-ta1gar0b.cjs} +7 -2
  24. package/dist/shared/{stacks-byyex2zk.cjs.map → stacks-ta1gar0b.cjs.map} +2 -2
  25. package/dist/shared/stacks-tdsp5gsb.cjs.map +2 -2
  26. package/dist/shared/stacks-vea7nde7.cjs +731 -0
  27. package/dist/shared/stacks-vea7nde7.cjs.map +13 -0
  28. package/dist/shared/stacks-w23294am.js +760 -0
  29. package/dist/shared/stacks-w23294am.js.map +13 -0
  30. package/dist/shared/{stacks-zwgsbbb2.cjs → stacks-y4f7fm03.cjs} +7 -13
  31. package/dist/shared/{stacks-zwgsbbb2.cjs.map → stacks-y4f7fm03.cjs.map} +5 -5
  32. package/dist/src/accounts/index.d.cts +1 -1
  33. package/dist/src/accounts/index.d.ts +1 -1
  34. package/dist/src/actions/index.d.cts +15 -11
  35. package/dist/src/actions/index.d.ts +15 -11
  36. package/dist/src/actions/index.js +7 -6
  37. package/dist/src/actions/index.js.map +1 -1
  38. package/dist/src/bitcoin/index.d.cts +29 -29
  39. package/dist/src/bitcoin/index.d.ts +29 -29
  40. package/dist/src/bitcoin/index.js +3 -2
  41. package/dist/src/bitcoin/index.js.map +2 -2
  42. package/dist/src/bns/index.d.cts +1 -1
  43. package/dist/src/bns/index.d.ts +1 -1
  44. package/dist/src/bns/index.js +8 -6
  45. package/dist/src/bns/index.js.map +2 -2
  46. package/dist/src/clarity/index.d.cts +37 -1
  47. package/dist/src/clarity/index.d.ts +37 -1
  48. package/dist/src/clarity/index.js +14 -2
  49. package/dist/src/clarity/index.js.map +1 -1
  50. package/dist/src/index.cjs.map +2 -2
  51. package/dist/src/index.d.cts +18 -14
  52. package/dist/src/index.d.ts +18 -14
  53. package/dist/src/index.js +6 -5
  54. package/dist/src/index.js.map +3 -3
  55. package/dist/src/postconditions/index.d.cts +66 -3
  56. package/dist/src/postconditions/index.d.ts +66 -3
  57. package/dist/src/postconditions/index.js +13 -2
  58. package/dist/src/postconditions/index.js.map +1 -1
  59. package/dist/src/pox/index.d.cts +1 -1
  60. package/dist/src/pox/index.d.ts +1 -1
  61. package/dist/src/pox/index.js +6 -5
  62. package/dist/src/pox/index.js.map +2 -2
  63. package/dist/src/pox5/index.cjs +213 -14
  64. package/dist/src/pox5/index.cjs.map +8 -7
  65. package/dist/src/pox5/index.d.cts +88 -5
  66. package/dist/src/pox5/index.d.ts +88 -5
  67. package/dist/src/pox5/index.js +220 -17
  68. package/dist/src/pox5/index.js.map +8 -7
  69. package/dist/src/sbtc/index.d.cts +1 -1
  70. package/dist/src/sbtc/index.d.ts +1 -1
  71. package/dist/src/sbtc/index.js +5 -4
  72. package/dist/src/sbtc/index.js.map +2 -2
  73. package/dist/src/stackingdao/index.d.cts +1 -1
  74. package/dist/src/stackingdao/index.d.ts +1 -1
  75. package/dist/src/stackingdao/index.js +6 -5
  76. package/dist/src/stackingdao/index.js.map +2 -2
  77. package/dist/src/subscriptions/index.d.cts +1 -1
  78. package/dist/src/subscriptions/index.d.ts +1 -1
  79. package/dist/src/tools/index.cjs +494 -367
  80. package/dist/src/tools/index.cjs.map +11 -9
  81. package/dist/src/tools/index.d.cts +1 -1
  82. package/dist/src/tools/index.d.ts +1 -1
  83. package/dist/src/tools/index.js +494 -367
  84. package/dist/src/tools/index.js.map +11 -9
  85. package/dist/src/transactions/index.cjs +3 -1
  86. package/dist/src/transactions/index.cjs.map +1 -1
  87. package/dist/src/transactions/index.d.cts +16 -9
  88. package/dist/src/transactions/index.d.ts +16 -9
  89. package/dist/src/transactions/index.js +31 -27
  90. package/dist/src/transactions/index.js.map +1 -1
  91. package/package.json +2 -2
  92. package/dist/shared/stacks-dr5en54r.cjs.map +0 -10
  93. package/dist/shared/stacks-fse1f76h.js.map +0 -10
  94. package/dist/shared/stacks-g2qnr5qn.cjs.map +0 -15
  95. package/dist/shared/stacks-gkf9tsws.js +0 -285
  96. package/dist/shared/stacks-gkf9tsws.js.map +0 -10
  97. package/dist/shared/stacks-jx146qf1.js.map +0 -15
  98. package/dist/shared/stacks-qjgh6pqr.cjs +0 -258
  99. package/dist/shared/stacks-qjgh6pqr.cjs.map +0 -10
  100. package/dist/shared/stacks-z3vztaz1.js.map +0 -10
@@ -458,7 +458,8 @@ var AnchorMode = {
458
458
  };
459
459
  var PostConditionModeWire = {
460
460
  Allow: 1,
461
- Deny: 2
461
+ Deny: 2,
462
+ Originator: 3
462
463
  };
463
464
  var AddressHashMode = {
464
465
  P2PKH: 0,
@@ -481,7 +482,8 @@ var FungibleConditionCode = {
481
482
  };
482
483
  var NonFungibleConditionCode = {
483
484
  Sends: 16,
484
- DoesNotSend: 17
485
+ DoesNotSend: 17,
486
+ MaybeSent: 18
485
487
  };
486
488
  var PoxConditionCode = {
487
489
  WillNotPerform: 48,
@@ -575,7 +577,7 @@ function serializePrincipal(principal) {
575
577
  function serializeAssetInfo(asset) {
576
578
  return concatBytes(serializeAddress2(asset.address), serializeLPString2(asset.contractName), serializeLPString2(asset.assetName));
577
579
  }
578
- function serializePostCondition(pc) {
580
+ function serializePostConditionWire(pc) {
579
581
  const parts = [];
580
582
  switch (pc.type) {
581
583
  case "stx":
@@ -614,9 +616,8 @@ function serializePostCondition(pc) {
614
616
  }
615
617
  function serializePostConditions(pcs) {
616
618
  const parts = [writeUInt32BE(pcs.length)];
617
- for (const pc of pcs) {
618
- parts.push(serializePostCondition(pc));
619
- }
619
+ for (const pc of pcs)
620
+ parts.push(serializePostConditionWire(pc));
620
621
  return concatBytes(...parts);
621
622
  }
622
623
  function serializePayload(payload) {
@@ -1357,6 +1358,441 @@ function clarityValueToJSInner(abiType, cv) {
1357
1358
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
1358
1359
  }
1359
1360
 
1361
+ // src/transactions/wire/deserialize.ts
1362
+ function readSpendingCondition(r) {
1363
+ const hashMode = r.readUInt8();
1364
+ const signer = bytesToHex(r.readBytes(20));
1365
+ const nonce = r.readBigUInt64BE();
1366
+ const fee = r.readBigUInt64BE();
1367
+ if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {
1368
+ const keyEncoding = r.readUInt8();
1369
+ const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
1370
+ return {
1371
+ hashMode,
1372
+ signer,
1373
+ nonce,
1374
+ fee,
1375
+ keyEncoding,
1376
+ signature
1377
+ };
1378
+ }
1379
+ const fieldCount = r.readUInt32BE();
1380
+ const fields = [];
1381
+ for (let i = 0;i < fieldCount; i++) {
1382
+ const fieldType = r.readUInt8();
1383
+ if (fieldType <= 1) {
1384
+ const keyLen = fieldType === 0 ? 33 : 65;
1385
+ fields.push({
1386
+ type: "publicKey",
1387
+ pubKeyEncoding: fieldType,
1388
+ data: bytesToHex(r.readBytes(keyLen))
1389
+ });
1390
+ } else {
1391
+ fields.push({
1392
+ type: "signature",
1393
+ pubKeyEncoding: fieldType === 2 ? 0 : 1,
1394
+ data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES))
1395
+ });
1396
+ }
1397
+ }
1398
+ const signaturesRequired = r.readUInt16BE();
1399
+ return {
1400
+ hashMode,
1401
+ signer,
1402
+ nonce,
1403
+ fee,
1404
+ fields,
1405
+ signaturesRequired
1406
+ };
1407
+ }
1408
+ function readAuthorization(r) {
1409
+ const authType = r.readUInt8();
1410
+ const spendingCondition = readSpendingCondition(r);
1411
+ if (authType === AuthType.Standard) {
1412
+ return { authType: AuthType.Standard, spendingCondition };
1413
+ }
1414
+ const sponsorSpendingCondition = readSpendingCondition(r);
1415
+ return {
1416
+ authType: AuthType.Sponsored,
1417
+ spendingCondition,
1418
+ sponsorSpendingCondition
1419
+ };
1420
+ }
1421
+ function readAssetInfo(r) {
1422
+ return {
1423
+ address: readAddress(r),
1424
+ contractName: readLPString(r),
1425
+ assetName: readLPString(r)
1426
+ };
1427
+ }
1428
+ function readPostConditionPrincipal(r) {
1429
+ const type = r.readUInt8();
1430
+ switch (type) {
1431
+ case PostConditionPrincipalId.Origin:
1432
+ return { type: "origin" };
1433
+ case PostConditionPrincipalId.Standard:
1434
+ return { type: "standard", address: readAddress(r) };
1435
+ case PostConditionPrincipalId.Contract:
1436
+ return {
1437
+ type: "contract",
1438
+ address: readAddress(r),
1439
+ contractName: readLPString(r)
1440
+ };
1441
+ default:
1442
+ return { type: "origin" };
1443
+ }
1444
+ }
1445
+ function readPostCondition(r) {
1446
+ const assetType = r.readUInt8();
1447
+ const principal = readPostConditionPrincipal(r);
1448
+ switch (assetType) {
1449
+ case AssetType.STX:
1450
+ return {
1451
+ type: "stx",
1452
+ principal,
1453
+ conditionCode: r.readUInt8(),
1454
+ amount: r.readBigUInt64BE()
1455
+ };
1456
+ case AssetType.Fungible:
1457
+ return {
1458
+ type: "ft",
1459
+ principal,
1460
+ asset: readAssetInfo(r),
1461
+ conditionCode: r.readUInt8(),
1462
+ amount: r.readBigUInt64BE()
1463
+ };
1464
+ case AssetType.NonFungible:
1465
+ return {
1466
+ type: "nft",
1467
+ principal,
1468
+ asset: readAssetInfo(r),
1469
+ assetId: readCV(r),
1470
+ conditionCode: r.readUInt8()
1471
+ };
1472
+ case AssetType.Staking:
1473
+ return {
1474
+ type: "staking",
1475
+ principal,
1476
+ conditionCode: r.readUInt8(),
1477
+ amount: r.readBigUInt64BE()
1478
+ };
1479
+ case AssetType.Pox:
1480
+ return {
1481
+ type: "pox",
1482
+ principal,
1483
+ conditionCode: r.readUInt8()
1484
+ };
1485
+ default:
1486
+ throw new Error(`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, "0")}`);
1487
+ }
1488
+ }
1489
+ function readPostConditions(r) {
1490
+ const count = r.readUInt32BE();
1491
+ const pcs = [];
1492
+ for (let i = 0;i < count; i++) {
1493
+ try {
1494
+ pcs.push(readPostCondition(r));
1495
+ } catch (e) {
1496
+ if (e instanceof Error && e.message.startsWith("Unknown post-condition asset type:")) {
1497
+ throw new Error(`${e.message} (post-condition ${i + 1}/${count})`);
1498
+ }
1499
+ throw e;
1500
+ }
1501
+ }
1502
+ return pcs;
1503
+ }
1504
+ function readPayload(r) {
1505
+ const payloadType = r.readUInt8();
1506
+ switch (payloadType) {
1507
+ case PayloadType.TokenTransfer: {
1508
+ const recipient = readCV(r);
1509
+ const amount = r.readBigUInt64BE();
1510
+ const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
1511
+ const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
1512
+ return {
1513
+ payloadType: PayloadType.TokenTransfer,
1514
+ recipient,
1515
+ amount,
1516
+ memo
1517
+ };
1518
+ }
1519
+ case PayloadType.ContractCall: {
1520
+ const contractAddress = readAddress(r);
1521
+ const contractName = readLPString(r);
1522
+ const functionName = readLPString(r);
1523
+ const numArgs = r.readUInt32BE();
1524
+ const functionArgs = [];
1525
+ for (let i = 0;i < numArgs; i++)
1526
+ functionArgs.push(readCV(r));
1527
+ return {
1528
+ payloadType: PayloadType.ContractCall,
1529
+ contractAddress,
1530
+ contractName,
1531
+ functionName,
1532
+ functionArgs
1533
+ };
1534
+ }
1535
+ case PayloadType.SmartContract: {
1536
+ const contractName = readLPString(r);
1537
+ const codeBody = readLPString(r, 4);
1538
+ return { payloadType: PayloadType.SmartContract, contractName, codeBody };
1539
+ }
1540
+ case PayloadType.VersionedSmartContract: {
1541
+ const clarityVersion = r.readUInt8();
1542
+ const contractName = readLPString(r);
1543
+ const codeBody = readLPString(r, 4);
1544
+ return {
1545
+ payloadType: PayloadType.VersionedSmartContract,
1546
+ clarityVersion,
1547
+ contractName,
1548
+ codeBody
1549
+ };
1550
+ }
1551
+ case PayloadType.Coinbase: {
1552
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1553
+ return { payloadType: PayloadType.Coinbase, coinbaseBuffer };
1554
+ }
1555
+ case PayloadType.CoinbaseToAltRecipient: {
1556
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1557
+ const recipient = readCV(r);
1558
+ return {
1559
+ payloadType: PayloadType.CoinbaseToAltRecipient,
1560
+ coinbaseBuffer,
1561
+ recipient
1562
+ };
1563
+ }
1564
+ case PayloadType.PoisonMicroblock: {
1565
+ const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
1566
+ const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
1567
+ return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };
1568
+ }
1569
+ case PayloadType.TenureChange: {
1570
+ const tenureConsensusHash = bytesToHex(r.readBytes(20));
1571
+ const prevTenureConsensusHash = bytesToHex(r.readBytes(20));
1572
+ const burnViewConsensusHash = bytesToHex(r.readBytes(20));
1573
+ const previousTenureEnd = bytesToHex(r.readBytes(32));
1574
+ const previousTenureBlocks = r.readUInt32BE();
1575
+ const cause = r.readUInt8();
1576
+ const pubkeyHash = bytesToHex(r.readBytes(20));
1577
+ return {
1578
+ payloadType: PayloadType.TenureChange,
1579
+ tenureConsensusHash,
1580
+ prevTenureConsensusHash,
1581
+ burnViewConsensusHash,
1582
+ previousTenureEnd,
1583
+ previousTenureBlocks,
1584
+ cause,
1585
+ pubkeyHash
1586
+ };
1587
+ }
1588
+ case PayloadType.NakamotoCoinbase: {
1589
+ const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
1590
+ const optionalCV = readCV(r);
1591
+ const recipient = optionalCV.type === "none" ? null : optionalCV.type === "some" ? optionalCV.value : optionalCV;
1592
+ const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));
1593
+ return {
1594
+ payloadType: PayloadType.NakamotoCoinbase,
1595
+ coinbaseBuffer,
1596
+ recipient,
1597
+ vrfProof
1598
+ };
1599
+ }
1600
+ default:
1601
+ throw new Error(`Unknown payload type: ${payloadType}`);
1602
+ }
1603
+ }
1604
+ function deserializePostConditionWire(input) {
1605
+ const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
1606
+ return readPostCondition(new BytesReader(bytes));
1607
+ }
1608
+ function deserializeTransaction(input, meta) {
1609
+ const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
1610
+ const r = new BytesReader(bytes);
1611
+ const tx = {
1612
+ version: r.readUInt8(),
1613
+ chainId: r.readUInt32BE(),
1614
+ auth: readAuthorization(r),
1615
+ anchorMode: r.readUInt8(),
1616
+ postConditionMode: r.readUInt8(),
1617
+ postConditions: readPostConditions(r),
1618
+ payload: readPayload(r)
1619
+ };
1620
+ if (meta?._multisig) {
1621
+ tx._multisig = meta._multisig;
1622
+ }
1623
+ return tx;
1624
+ }
1625
+
1626
+ // src/postconditions/convert.ts
1627
+ var MAX_U64 = 18446744073709551615n;
1628
+ function parsePostConditionAmount(amount) {
1629
+ const value = intToBigInt(amount);
1630
+ if (value < 0n || value > MAX_U64) {
1631
+ throw new RangeError(`Post-condition amount must be between 0 and ${MAX_U64} (u64 max), received: ${value}`);
1632
+ }
1633
+ return value;
1634
+ }
1635
+ var FUNGIBLE_CODE_MAP = {
1636
+ eq: FungibleConditionCode.Equal,
1637
+ gt: FungibleConditionCode.Greater,
1638
+ gte: FungibleConditionCode.GreaterEqual,
1639
+ lt: FungibleConditionCode.Less,
1640
+ lte: FungibleConditionCode.LessEqual
1641
+ };
1642
+ var FUNGIBLE_CODE_REVERSE = {
1643
+ [FungibleConditionCode.Equal]: "eq",
1644
+ [FungibleConditionCode.Greater]: "gt",
1645
+ [FungibleConditionCode.GreaterEqual]: "gte",
1646
+ [FungibleConditionCode.Less]: "lt",
1647
+ [FungibleConditionCode.LessEqual]: "lte"
1648
+ };
1649
+ var NFT_CODE_MAP = {
1650
+ sent: NonFungibleConditionCode.Sends,
1651
+ "not-sent": NonFungibleConditionCode.DoesNotSend,
1652
+ "maybe-sent": NonFungibleConditionCode.MaybeSent
1653
+ };
1654
+ var NFT_CODE_REVERSE = {
1655
+ [NonFungibleConditionCode.Sends]: "sent",
1656
+ [NonFungibleConditionCode.DoesNotSend]: "not-sent",
1657
+ [NonFungibleConditionCode.MaybeSent]: "maybe-sent"
1658
+ };
1659
+ var POX_CODE_MAP = {
1660
+ "will-not-perform": PoxConditionCode.WillNotPerform,
1661
+ "may-perform": PoxConditionCode.MayPerform,
1662
+ "will-perform": PoxConditionCode.WillPerform
1663
+ };
1664
+ var POX_CODE_REVERSE = {
1665
+ [PoxConditionCode.WillNotPerform]: "will-not-perform",
1666
+ [PoxConditionCode.MayPerform]: "may-perform",
1667
+ [PoxConditionCode.WillPerform]: "will-perform"
1668
+ };
1669
+ function resolvePrincipal(address) {
1670
+ if (address === "origin")
1671
+ return { type: "origin" };
1672
+ const [addr, name] = address.split(".");
1673
+ if (name) {
1674
+ return { type: "contract", address: addr, contractName: name };
1675
+ }
1676
+ return { type: "standard", address: addr };
1677
+ }
1678
+ function principalToString(principal) {
1679
+ if (principal.type === "origin")
1680
+ return "origin";
1681
+ if (principal.type === "contract") {
1682
+ return `${principal.address}.${principal.contractName}`;
1683
+ }
1684
+ return principal.address;
1685
+ }
1686
+ function assetToString(asset) {
1687
+ return `${asset.address}.${asset.contractName}::${asset.assetName}`;
1688
+ }
1689
+ function parseAsset(asset) {
1690
+ const [contractId, tokenName] = asset.split("::");
1691
+ const [addr, name] = parseContractId(contractId);
1692
+ return { address: addr, contractName: name, assetName: tokenName };
1693
+ }
1694
+ function convertPostCondition(pc) {
1695
+ switch (pc.type) {
1696
+ case "stx-postcondition":
1697
+ return {
1698
+ type: "stx",
1699
+ principal: resolvePrincipal(pc.address),
1700
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1701
+ amount: parsePostConditionAmount(pc.amount)
1702
+ };
1703
+ case "ft-postcondition":
1704
+ return {
1705
+ type: "ft",
1706
+ principal: resolvePrincipal(pc.address),
1707
+ asset: parseAsset(pc.asset),
1708
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1709
+ amount: parsePostConditionAmount(pc.amount)
1710
+ };
1711
+ case "nft-postcondition":
1712
+ return {
1713
+ type: "nft",
1714
+ principal: resolvePrincipal(pc.address),
1715
+ asset: parseAsset(pc.asset),
1716
+ conditionCode: NFT_CODE_MAP[pc.condition],
1717
+ assetId: pc.assetId
1718
+ };
1719
+ case "staking-postcondition":
1720
+ return {
1721
+ type: "staking",
1722
+ principal: resolvePrincipal(pc.address),
1723
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1724
+ amount: parsePostConditionAmount(pc.amount)
1725
+ };
1726
+ case "pox-postcondition":
1727
+ return {
1728
+ type: "pox",
1729
+ principal: resolvePrincipal(pc.address),
1730
+ conditionCode: POX_CODE_MAP[pc.condition]
1731
+ };
1732
+ }
1733
+ }
1734
+ function wireToPostCondition(wire) {
1735
+ switch (wire.type) {
1736
+ case "stx":
1737
+ return {
1738
+ type: "stx-postcondition",
1739
+ address: principalToString(wire.principal),
1740
+ condition: fungibleName(wire.conditionCode),
1741
+ amount: wire.amount.toString()
1742
+ };
1743
+ case "ft":
1744
+ return {
1745
+ type: "ft-postcondition",
1746
+ address: principalToString(wire.principal),
1747
+ condition: fungibleName(wire.conditionCode),
1748
+ amount: wire.amount.toString(),
1749
+ asset: assetToString(wire.asset)
1750
+ };
1751
+ case "nft":
1752
+ return {
1753
+ type: "nft-postcondition",
1754
+ address: principalToString(wire.principal),
1755
+ condition: nftName(wire.conditionCode),
1756
+ asset: assetToString(wire.asset),
1757
+ assetId: wire.assetId
1758
+ };
1759
+ case "staking":
1760
+ return {
1761
+ type: "staking-postcondition",
1762
+ address: principalToString(wire.principal),
1763
+ condition: fungibleName(wire.conditionCode),
1764
+ amount: wire.amount.toString()
1765
+ };
1766
+ case "pox":
1767
+ return {
1768
+ type: "pox-postcondition",
1769
+ address: principalToString(wire.principal),
1770
+ condition: poxName(wire.conditionCode)
1771
+ };
1772
+ }
1773
+ }
1774
+ function fungibleName(code) {
1775
+ const name = FUNGIBLE_CODE_REVERSE[code];
1776
+ if (!name)
1777
+ throw new Error(`Unknown fungible post-condition code: ${code}`);
1778
+ return name;
1779
+ }
1780
+ function nftName(code) {
1781
+ const name = NFT_CODE_REVERSE[code];
1782
+ if (!name)
1783
+ throw new Error(`Unknown nft post-condition code: ${code}`);
1784
+ return name;
1785
+ }
1786
+ function poxName(code) {
1787
+ const name = POX_CODE_REVERSE[code];
1788
+ if (!name)
1789
+ throw new Error(`Unknown pox post-condition code: ${code}`);
1790
+ return name;
1791
+ }
1792
+ function fromHex(hex) {
1793
+ return wireToPostCondition(deserializePostConditionWire(hex));
1794
+ }
1795
+
1360
1796
  // src/transactions/authorization.ts
1361
1797
  var import_hmac = require("@noble/hashes/hmac.js");
1362
1798
  var import_sha24 = require("@noble/hashes/sha2.js");
@@ -1426,112 +1862,49 @@ function intoInitialSighashAuth(auth) {
1426
1862
  function sigHashPreSign(curSigHash, authType, fee, nonce) {
1427
1863
  const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([authType]), intToBytes(fee, 8), intToBytes(nonce, 8));
1428
1864
  return txidFromBytes(data);
1429
- }
1430
-
1431
- // src/transactions/multisig.ts
1432
- var import_secp256k12 = require("@noble/secp256k1");
1433
- var OP_CHECKMULTISIG = 174;
1434
- function makeRedeemScript(publicKeys, signaturesRequired) {
1435
- const parts = [];
1436
- parts.push(new Uint8Array([80 + signaturesRequired]));
1437
- for (const pk of publicKeys) {
1438
- const pkBytes = hexToBytes(pk);
1439
- parts.push(new Uint8Array([pkBytes.length]));
1440
- parts.push(pkBytes);
1441
- }
1442
- parts.push(new Uint8Array([80 + publicKeys.length]));
1443
- parts.push(new Uint8Array([OP_CHECKMULTISIG]));
1444
- return concatBytes(...parts);
1445
- }
1446
- function createMultiSigSpendingCondition(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode.P2SH) {
1447
- const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
1448
- const signer = bytesToHex(hash160(redeemScript));
1449
- return {
1450
- hashMode,
1451
- signer,
1452
- nonce,
1453
- fee,
1454
- fields: [],
1455
- signaturesRequired
1456
- };
1457
- }
1458
-
1459
- // src/transactions/build.ts
1460
- function resolvePcMode(mode) {
1461
- return mode === "allow" ? PostConditionModeWire.Allow : PostConditionModeWire.Deny;
1462
- }
1463
- function convertPostConditions(pcs) {
1464
- if (!pcs || pcs.length === 0)
1465
- return [];
1466
- return pcs.map(convertPostCondition);
1467
- }
1468
- function resolvePrincipal(address) {
1469
- if (address === "origin")
1470
- return { type: "origin" };
1471
- const [addr, name] = address.split(".");
1472
- if (name) {
1473
- return { type: "contract", address: addr, contractName: name };
1474
- }
1475
- return { type: "standard", address: addr };
1476
- }
1477
- var FUNGIBLE_CODE_MAP = {
1478
- eq: FungibleConditionCode.Equal,
1479
- gt: FungibleConditionCode.Greater,
1480
- gte: FungibleConditionCode.GreaterEqual,
1481
- lt: FungibleConditionCode.Less,
1482
- lte: FungibleConditionCode.LessEqual
1483
- };
1484
- function convertPostCondition(pc) {
1485
- switch (pc.type) {
1486
- case "stx-postcondition":
1487
- return {
1488
- type: "stx",
1489
- principal: resolvePrincipal(pc.address),
1490
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1491
- amount: intToBigInt(pc.amount)
1492
- };
1493
- case "ft-postcondition": {
1494
- const [contractId, tokenName] = pc.asset.split("::");
1495
- const [addr, name] = parseContractId(contractId);
1496
- return {
1497
- type: "ft",
1498
- principal: resolvePrincipal(pc.address),
1499
- asset: { address: addr, contractName: name, assetName: tokenName },
1500
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1501
- amount: intToBigInt(pc.amount)
1502
- };
1503
- }
1504
- case "nft-postcondition": {
1505
- const [contractId, tokenName] = pc.asset.split("::");
1506
- const [addr, name] = parseContractId(contractId);
1507
- return {
1508
- type: "nft",
1509
- principal: resolvePrincipal(pc.address),
1510
- asset: { address: addr, contractName: name, assetName: tokenName },
1511
- conditionCode: pc.condition === "sent" ? NonFungibleConditionCode.Sends : NonFungibleConditionCode.DoesNotSend,
1512
- assetId: pc.assetId
1513
- };
1514
- }
1515
- case "staking-postcondition":
1516
- return {
1517
- type: "staking",
1518
- principal: resolvePrincipal(pc.address),
1519
- conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
1520
- amount: intToBigInt(pc.amount)
1521
- };
1522
- case "pox-postcondition":
1523
- return {
1524
- type: "pox",
1525
- principal: resolvePrincipal(pc.address),
1526
- conditionCode: POX_CODE_MAP[pc.condition]
1527
- };
1865
+ }
1866
+
1867
+ // src/transactions/multisig.ts
1868
+ var import_secp256k12 = require("@noble/secp256k1");
1869
+ var OP_CHECKMULTISIG = 174;
1870
+ function makeRedeemScript(publicKeys, signaturesRequired) {
1871
+ const parts = [];
1872
+ parts.push(new Uint8Array([80 + signaturesRequired]));
1873
+ for (const pk of publicKeys) {
1874
+ const pkBytes = hexToBytes(pk);
1875
+ parts.push(new Uint8Array([pkBytes.length]));
1876
+ parts.push(pkBytes);
1528
1877
  }
1878
+ parts.push(new Uint8Array([80 + publicKeys.length]));
1879
+ parts.push(new Uint8Array([OP_CHECKMULTISIG]));
1880
+ return concatBytes(...parts);
1881
+ }
1882
+ function createMultiSigSpendingCondition(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode.P2SH) {
1883
+ const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
1884
+ const signer = bytesToHex(hash160(redeemScript));
1885
+ return {
1886
+ hashMode,
1887
+ signer,
1888
+ nonce,
1889
+ fee,
1890
+ fields: [],
1891
+ signaturesRequired
1892
+ };
1893
+ }
1894
+
1895
+ // src/transactions/build.ts
1896
+ function resolvePcMode(mode) {
1897
+ if (mode === "allow")
1898
+ return PostConditionModeWire.Allow;
1899
+ if (mode === "originator")
1900
+ return PostConditionModeWire.Originator;
1901
+ return PostConditionModeWire.Deny;
1902
+ }
1903
+ function convertPostConditions(pcs) {
1904
+ if (!pcs || pcs.length === 0)
1905
+ return [];
1906
+ return pcs.map((pc) => convertPostCondition(typeof pc === "string" ? fromHex(pc) : pc));
1529
1907
  }
1530
- var POX_CODE_MAP = {
1531
- "will-not-perform": PoxConditionCode.WillNotPerform,
1532
- "may-perform": PoxConditionCode.MayPerform,
1533
- "will-perform": PoxConditionCode.WillPerform
1534
- };
1535
1908
  function resolveSpendingCondition(opts, nonce, fee) {
1536
1909
  if (opts.publicKeys) {
1537
1910
  return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
@@ -2032,6 +2405,16 @@ class ContractResponseError extends Error {
2032
2405
  this.errorValue = errorValue;
2033
2406
  }
2034
2407
  }
2408
+ // src/clarity/structuredData.ts
2409
+ var import_sha25 = require("@noble/hashes/sha2.js");
2410
+ var SIP018_PREFIX = new Uint8Array([
2411
+ 83,
2412
+ 73,
2413
+ 80,
2414
+ 48,
2415
+ 49,
2416
+ 56
2417
+ ]);
2035
2418
  // src/clarity/abi/standards.ts
2036
2419
  var SIP010_ABI = {
2037
2420
  functions: [
@@ -2568,262 +2951,6 @@ async function getPrimaryName(client, address) {
2568
2951
  }
2569
2952
  }
2570
2953
 
2571
- // src/transactions/wire/deserialize.ts
2572
- function readSpendingCondition(r) {
2573
- const hashMode = r.readUInt8();
2574
- const signer = bytesToHex(r.readBytes(20));
2575
- const nonce = r.readBigUInt64BE();
2576
- const fee = r.readBigUInt64BE();
2577
- if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {
2578
- const keyEncoding = r.readUInt8();
2579
- const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
2580
- return {
2581
- hashMode,
2582
- signer,
2583
- nonce,
2584
- fee,
2585
- keyEncoding,
2586
- signature
2587
- };
2588
- }
2589
- const fieldCount = r.readUInt32BE();
2590
- const fields = [];
2591
- for (let i = 0;i < fieldCount; i++) {
2592
- const fieldType = r.readUInt8();
2593
- if (fieldType <= 1) {
2594
- const keyLen = fieldType === 0 ? 33 : 65;
2595
- fields.push({
2596
- type: "publicKey",
2597
- pubKeyEncoding: fieldType,
2598
- data: bytesToHex(r.readBytes(keyLen))
2599
- });
2600
- } else {
2601
- fields.push({
2602
- type: "signature",
2603
- pubKeyEncoding: fieldType === 2 ? 0 : 1,
2604
- data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES))
2605
- });
2606
- }
2607
- }
2608
- const signaturesRequired = r.readUInt16BE();
2609
- return {
2610
- hashMode,
2611
- signer,
2612
- nonce,
2613
- fee,
2614
- fields,
2615
- signaturesRequired
2616
- };
2617
- }
2618
- function readAuthorization(r) {
2619
- const authType = r.readUInt8();
2620
- const spendingCondition = readSpendingCondition(r);
2621
- if (authType === AuthType.Standard) {
2622
- return { authType: AuthType.Standard, spendingCondition };
2623
- }
2624
- const sponsorSpendingCondition = readSpendingCondition(r);
2625
- return {
2626
- authType: AuthType.Sponsored,
2627
- spendingCondition,
2628
- sponsorSpendingCondition
2629
- };
2630
- }
2631
- function readAssetInfo(r) {
2632
- return {
2633
- address: readAddress(r),
2634
- contractName: readLPString(r),
2635
- assetName: readLPString(r)
2636
- };
2637
- }
2638
- function readPostConditionPrincipal(r) {
2639
- const type = r.readUInt8();
2640
- switch (type) {
2641
- case PostConditionPrincipalId.Origin:
2642
- return { type: "origin" };
2643
- case PostConditionPrincipalId.Standard:
2644
- return { type: "standard", address: readAddress(r) };
2645
- case PostConditionPrincipalId.Contract:
2646
- return {
2647
- type: "contract",
2648
- address: readAddress(r),
2649
- contractName: readLPString(r)
2650
- };
2651
- default:
2652
- return { type: "origin" };
2653
- }
2654
- }
2655
- function readPostConditions(r) {
2656
- const count = r.readUInt32BE();
2657
- const pcs = [];
2658
- for (let i = 0;i < count; i++) {
2659
- const assetType = r.readUInt8();
2660
- const principal = readPostConditionPrincipal(r);
2661
- switch (assetType) {
2662
- case AssetType.STX:
2663
- pcs.push({
2664
- type: "stx",
2665
- principal,
2666
- conditionCode: r.readUInt8(),
2667
- amount: r.readBigUInt64BE()
2668
- });
2669
- break;
2670
- case AssetType.Fungible:
2671
- pcs.push({
2672
- type: "ft",
2673
- principal,
2674
- asset: readAssetInfo(r),
2675
- conditionCode: r.readUInt8(),
2676
- amount: r.readBigUInt64BE()
2677
- });
2678
- break;
2679
- case AssetType.NonFungible:
2680
- pcs.push({
2681
- type: "nft",
2682
- principal,
2683
- asset: readAssetInfo(r),
2684
- assetId: readCV(r),
2685
- conditionCode: r.readUInt8()
2686
- });
2687
- break;
2688
- case AssetType.Staking:
2689
- pcs.push({
2690
- type: "staking",
2691
- principal,
2692
- conditionCode: r.readUInt8(),
2693
- amount: r.readBigUInt64BE()
2694
- });
2695
- break;
2696
- case AssetType.Pox:
2697
- pcs.push({
2698
- type: "pox",
2699
- principal,
2700
- conditionCode: r.readUInt8()
2701
- });
2702
- break;
2703
- default:
2704
- throw new Error(`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, "0")} (post-condition ${i + 1}/${count})`);
2705
- }
2706
- }
2707
- return pcs;
2708
- }
2709
- function readPayload(r) {
2710
- const payloadType = r.readUInt8();
2711
- switch (payloadType) {
2712
- case PayloadType.TokenTransfer: {
2713
- const recipient = readCV(r);
2714
- const amount = r.readBigUInt64BE();
2715
- const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
2716
- const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
2717
- return {
2718
- payloadType: PayloadType.TokenTransfer,
2719
- recipient,
2720
- amount,
2721
- memo
2722
- };
2723
- }
2724
- case PayloadType.ContractCall: {
2725
- const contractAddress = readAddress(r);
2726
- const contractName = readLPString(r);
2727
- const functionName = readLPString(r);
2728
- const numArgs = r.readUInt32BE();
2729
- const functionArgs = [];
2730
- for (let i = 0;i < numArgs; i++)
2731
- functionArgs.push(readCV(r));
2732
- return {
2733
- payloadType: PayloadType.ContractCall,
2734
- contractAddress,
2735
- contractName,
2736
- functionName,
2737
- functionArgs
2738
- };
2739
- }
2740
- case PayloadType.SmartContract: {
2741
- const contractName = readLPString(r);
2742
- const codeBody = readLPString(r, 4);
2743
- return { payloadType: PayloadType.SmartContract, contractName, codeBody };
2744
- }
2745
- case PayloadType.VersionedSmartContract: {
2746
- const clarityVersion = r.readUInt8();
2747
- const contractName = readLPString(r);
2748
- const codeBody = readLPString(r, 4);
2749
- return {
2750
- payloadType: PayloadType.VersionedSmartContract,
2751
- clarityVersion,
2752
- contractName,
2753
- codeBody
2754
- };
2755
- }
2756
- case PayloadType.Coinbase: {
2757
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2758
- return { payloadType: PayloadType.Coinbase, coinbaseBuffer };
2759
- }
2760
- case PayloadType.CoinbaseToAltRecipient: {
2761
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2762
- const recipient = readCV(r);
2763
- return {
2764
- payloadType: PayloadType.CoinbaseToAltRecipient,
2765
- coinbaseBuffer,
2766
- recipient
2767
- };
2768
- }
2769
- case PayloadType.PoisonMicroblock: {
2770
- const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
2771
- const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
2772
- return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };
2773
- }
2774
- case PayloadType.TenureChange: {
2775
- const tenureConsensusHash = bytesToHex(r.readBytes(20));
2776
- const prevTenureConsensusHash = bytesToHex(r.readBytes(20));
2777
- const burnViewConsensusHash = bytesToHex(r.readBytes(20));
2778
- const previousTenureEnd = bytesToHex(r.readBytes(32));
2779
- const previousTenureBlocks = r.readUInt32BE();
2780
- const cause = r.readUInt8();
2781
- const pubkeyHash = bytesToHex(r.readBytes(20));
2782
- return {
2783
- payloadType: PayloadType.TenureChange,
2784
- tenureConsensusHash,
2785
- prevTenureConsensusHash,
2786
- burnViewConsensusHash,
2787
- previousTenureEnd,
2788
- previousTenureBlocks,
2789
- cause,
2790
- pubkeyHash
2791
- };
2792
- }
2793
- case PayloadType.NakamotoCoinbase: {
2794
- const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
2795
- const optionalCV = readCV(r);
2796
- const recipient = optionalCV.type === "none" ? null : optionalCV.type === "some" ? optionalCV.value : optionalCV;
2797
- const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));
2798
- return {
2799
- payloadType: PayloadType.NakamotoCoinbase,
2800
- coinbaseBuffer,
2801
- recipient,
2802
- vrfProof
2803
- };
2804
- }
2805
- default:
2806
- throw new Error(`Unknown payload type: ${payloadType}`);
2807
- }
2808
- }
2809
- function deserializeTransaction(input, meta) {
2810
- const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
2811
- const r = new BytesReader(bytes);
2812
- const tx = {
2813
- version: r.readUInt8(),
2814
- chainId: r.readUInt32BE(),
2815
- auth: readAuthorization(r),
2816
- anchorMode: r.readUInt8(),
2817
- postConditionMode: r.readUInt8(),
2818
- postConditions: readPostConditions(r),
2819
- payload: readPayload(r)
2820
- };
2821
- if (meta?._multisig) {
2822
- tx._multisig = meta._multisig;
2823
- }
2824
- return tx;
2825
- }
2826
-
2827
2954
  // src/chains/definitions.ts
2828
2955
  var mainnet = {
2829
2956
  id: 1,
@@ -3480,5 +3607,5 @@ var getNftHoldings2 = import_ai.tool({
3480
3607
  execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
3481
3608
  });
3482
3609
 
3483
- //# debugId=851896D4659A05D164756E2164756E21
3610
+ //# debugId=D01B0C427BFBC1C064756E2164756E21
3484
3611
  //# sourceMappingURL=index.cjs.map