@secondlayer/stacks 0.0.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 (178) hide show
  1. package/README.md +92 -0
  2. package/dist/shared/stacks-02actsrx.cjs +17 -0
  3. package/dist/shared/stacks-02actsrx.cjs.map +10 -0
  4. package/dist/shared/stacks-1aqm7c2h.cjs +110 -0
  5. package/dist/shared/stacks-1aqm7c2h.cjs.map +11 -0
  6. package/dist/shared/stacks-24h5k94q.cjs +74 -0
  7. package/dist/shared/stacks-24h5k94q.cjs.map +11 -0
  8. package/dist/shared/stacks-2ar4prfz.cjs +328 -0
  9. package/dist/shared/stacks-2ar4prfz.cjs.map +11 -0
  10. package/dist/shared/stacks-4py5pm0r.cjs +237 -0
  11. package/dist/shared/stacks-4py5pm0r.cjs.map +10 -0
  12. package/dist/shared/stacks-5tprhns9.cjs +54 -0
  13. package/dist/shared/stacks-5tprhns9.cjs.map +11 -0
  14. package/dist/shared/stacks-61rvzkz1.cjs +132 -0
  15. package/dist/shared/stacks-61rvzkz1.cjs.map +17 -0
  16. package/dist/shared/stacks-709tra19.js +30 -0
  17. package/dist/shared/stacks-709tra19.js.map +10 -0
  18. package/dist/shared/stacks-74k8cxgb.cjs +567 -0
  19. package/dist/shared/stacks-74k8cxgb.cjs.map +13 -0
  20. package/dist/shared/stacks-8m9byk2j.js +7 -0
  21. package/dist/shared/stacks-8m9byk2j.js.map +9 -0
  22. package/dist/shared/stacks-8yykgdww.js +125 -0
  23. package/dist/shared/stacks-8yykgdww.js.map +11 -0
  24. package/dist/shared/stacks-9g0jhab3.cjs +40 -0
  25. package/dist/shared/stacks-9g0jhab3.cjs.map +10 -0
  26. package/dist/shared/stacks-an5k8n4t.cjs +291 -0
  27. package/dist/shared/stacks-an5k8n4t.cjs.map +23 -0
  28. package/dist/shared/stacks-b008c3w8.cjs +214 -0
  29. package/dist/shared/stacks-b008c3w8.cjs.map +11 -0
  30. package/dist/shared/stacks-bnvfmt7y.cjs +31 -0
  31. package/dist/shared/stacks-bnvfmt7y.cjs.map +9 -0
  32. package/dist/shared/stacks-bycy6t9k.js +22 -0
  33. package/dist/shared/stacks-bycy6t9k.js.map +10 -0
  34. package/dist/shared/stacks-d1fmkv3p.js +258 -0
  35. package/dist/shared/stacks-d1fmkv3p.js.map +13 -0
  36. package/dist/shared/stacks-dr5en54r.cjs +119 -0
  37. package/dist/shared/stacks-dr5en54r.cjs.map +10 -0
  38. package/dist/shared/stacks-dxhntr76.js +278 -0
  39. package/dist/shared/stacks-dxhntr76.js.map +10 -0
  40. package/dist/shared/stacks-evnzth1q.cjs +35 -0
  41. package/dist/shared/stacks-evnzth1q.cjs.map +10 -0
  42. package/dist/shared/stacks-f3tk2k5s.js +27 -0
  43. package/dist/shared/stacks-f3tk2k5s.js.map +9 -0
  44. package/dist/shared/stacks-f7wdrzs3.js +285 -0
  45. package/dist/shared/stacks-f7wdrzs3.js.map +11 -0
  46. package/dist/shared/stacks-fcaefc5b.cjs +16 -0
  47. package/dist/shared/stacks-fcaefc5b.cjs.map +10 -0
  48. package/dist/shared/stacks-g9mcjcqg.cjs +3 -0
  49. package/dist/shared/stacks-g9mcjcqg.cjs.map +9 -0
  50. package/dist/shared/stacks-gck1sq7h.cjs +28 -0
  51. package/dist/shared/stacks-gck1sq7h.cjs.map +10 -0
  52. package/dist/shared/stacks-gjvbq6w7.js +46 -0
  53. package/dist/shared/stacks-gjvbq6w7.js.map +10 -0
  54. package/dist/shared/stacks-j2cy7qtt.js +237 -0
  55. package/dist/shared/stacks-j2cy7qtt.js.map +11 -0
  56. package/dist/shared/stacks-k08tgzyp.cjs +232 -0
  57. package/dist/shared/stacks-k08tgzyp.cjs.map +13 -0
  58. package/dist/shared/stacks-k2p5tv6x.js +37 -0
  59. package/dist/shared/stacks-k2p5tv6x.js.map +10 -0
  60. package/dist/shared/stacks-k58k970n.js +234 -0
  61. package/dist/shared/stacks-k58k970n.js.map +10 -0
  62. package/dist/shared/stacks-n2g56wgg.js +338 -0
  63. package/dist/shared/stacks-n2g56wgg.js.map +23 -0
  64. package/dist/shared/stacks-nqytwfcc.js +243 -0
  65. package/dist/shared/stacks-nqytwfcc.js.map +11 -0
  66. package/dist/shared/stacks-qcae5852.js +19 -0
  67. package/dist/shared/stacks-qcae5852.js.map +10 -0
  68. package/dist/shared/stacks-qt8ehebn.js +76 -0
  69. package/dist/shared/stacks-qt8ehebn.js.map +11 -0
  70. package/dist/shared/stacks-qvg7c24g.cjs +232 -0
  71. package/dist/shared/stacks-qvg7c24g.cjs.map +10 -0
  72. package/dist/shared/stacks-r1t6g3c3.cjs +241 -0
  73. package/dist/shared/stacks-r1t6g3c3.cjs.map +11 -0
  74. package/dist/shared/stacks-tjxmrssa.js +282 -0
  75. package/dist/shared/stacks-tjxmrssa.js.map +11 -0
  76. package/dist/shared/stacks-v9jqcpd4.js +18 -0
  77. package/dist/shared/stacks-v9jqcpd4.js.map +10 -0
  78. package/dist/shared/stacks-vdfag81a.cjs +121 -0
  79. package/dist/shared/stacks-vdfag81a.cjs.map +10 -0
  80. package/dist/shared/stacks-vdfs3e5v.js +134 -0
  81. package/dist/shared/stacks-vdfs3e5v.js.map +10 -0
  82. package/dist/shared/stacks-y3dh7hv1.js +60 -0
  83. package/dist/shared/stacks-y3dh7hv1.js.map +11 -0
  84. package/dist/shared/stacks-ya3x01yd.cjs +16 -0
  85. package/dist/shared/stacks-ya3x01yd.cjs.map +10 -0
  86. package/dist/shared/stacks-yfgsm6ap.js +599 -0
  87. package/dist/shared/stacks-yfgsm6ap.js.map +13 -0
  88. package/dist/shared/stacks-yfveb68e.js +121 -0
  89. package/dist/shared/stacks-yfveb68e.js.map +10 -0
  90. package/dist/shared/stacks-zm0b3tgy.js +160 -0
  91. package/dist/shared/stacks-zm0b3tgy.js.map +17 -0
  92. package/dist/shared/stacks-zyv9qqme.cjs +249 -0
  93. package/dist/shared/stacks-zyv9qqme.cjs.map +11 -0
  94. package/dist/src/accounts/index.cjs +90 -0
  95. package/dist/src/accounts/index.cjs.map +12 -0
  96. package/dist/src/accounts/index.d.cts +47 -0
  97. package/dist/src/accounts/index.d.ts +47 -0
  98. package/dist/src/accounts/index.js +104 -0
  99. package/dist/src/accounts/index.js.map +12 -0
  100. package/dist/src/actions/index.cjs +36 -0
  101. package/dist/src/actions/index.cjs.map +9 -0
  102. package/dist/src/actions/index.d.cts +886 -0
  103. package/dist/src/actions/index.d.ts +886 -0
  104. package/dist/src/actions/index.js +81 -0
  105. package/dist/src/actions/index.js.map +9 -0
  106. package/dist/src/bns/index.cjs +590 -0
  107. package/dist/src/bns/index.cjs.map +15 -0
  108. package/dist/src/bns/index.d.cts +241 -0
  109. package/dist/src/bns/index.d.ts +241 -0
  110. package/dist/src/bns/index.js +611 -0
  111. package/dist/src/bns/index.js.map +15 -0
  112. package/dist/src/chains/index.cjs +13 -0
  113. package/dist/src/chains/index.cjs.map +9 -0
  114. package/dist/src/chains/index.d.cts +53 -0
  115. package/dist/src/chains/index.d.ts +53 -0
  116. package/dist/src/chains/index.js +18 -0
  117. package/dist/src/chains/index.js.map +9 -0
  118. package/dist/src/clarity/index.cjs +3 -0
  119. package/dist/src/clarity/index.cjs.map +9 -0
  120. package/dist/src/clarity/index.d.cts +821 -0
  121. package/dist/src/clarity/index.d.ts +821 -0
  122. package/dist/src/clarity/index.js +145 -0
  123. package/dist/src/clarity/index.js.map +9 -0
  124. package/dist/src/connect/index.cjs +480 -0
  125. package/dist/src/connect/index.cjs.map +19 -0
  126. package/dist/src/connect/index.d.cts +110 -0
  127. package/dist/src/connect/index.d.ts +110 -0
  128. package/dist/src/connect/index.js +448 -0
  129. package/dist/src/connect/index.js.map +19 -0
  130. package/dist/src/connect/walletconnect/index.cjs +1322 -0
  131. package/dist/src/connect/walletconnect/index.cjs.map +18 -0
  132. package/dist/src/connect/walletconnect/index.d.cts +132 -0
  133. package/dist/src/connect/walletconnect/index.d.ts +132 -0
  134. package/dist/src/connect/walletconnect/index.js +1290 -0
  135. package/dist/src/connect/walletconnect/index.js.map +18 -0
  136. package/dist/src/index.cjs +557 -0
  137. package/dist/src/index.cjs.map +21 -0
  138. package/dist/src/index.d.cts +847 -0
  139. package/dist/src/index.d.ts +847 -0
  140. package/dist/src/index.js +629 -0
  141. package/dist/src/index.js.map +21 -0
  142. package/dist/src/postconditions/index.cjs +3 -0
  143. package/dist/src/postconditions/index.cjs.map +9 -0
  144. package/dist/src/postconditions/index.d.cts +91 -0
  145. package/dist/src/postconditions/index.d.ts +91 -0
  146. package/dist/src/postconditions/index.js +12 -0
  147. package/dist/src/postconditions/index.js.map +9 -0
  148. package/dist/src/pox/index.cjs +860 -0
  149. package/dist/src/pox/index.cjs.map +15 -0
  150. package/dist/src/pox/index.d.cts +244 -0
  151. package/dist/src/pox/index.d.ts +244 -0
  152. package/dist/src/pox/index.js +877 -0
  153. package/dist/src/pox/index.js.map +15 -0
  154. package/dist/src/stackingdao/index.cjs +300 -0
  155. package/dist/src/stackingdao/index.cjs.map +13 -0
  156. package/dist/src/stackingdao/index.d.cts +179 -0
  157. package/dist/src/stackingdao/index.d.ts +179 -0
  158. package/dist/src/stackingdao/index.js +318 -0
  159. package/dist/src/stackingdao/index.js.map +13 -0
  160. package/dist/src/subscriptions/index.cjs +14 -0
  161. package/dist/src/subscriptions/index.cjs.map +9 -0
  162. package/dist/src/subscriptions/index.d.cts +250 -0
  163. package/dist/src/subscriptions/index.d.ts +250 -0
  164. package/dist/src/subscriptions/index.js +21 -0
  165. package/dist/src/subscriptions/index.js.map +9 -0
  166. package/dist/src/transactions/index.cjs +50 -0
  167. package/dist/src/transactions/index.cjs.map +9 -0
  168. package/dist/src/transactions/index.d.cts +412 -0
  169. package/dist/src/transactions/index.d.ts +412 -0
  170. package/dist/src/transactions/index.js +101 -0
  171. package/dist/src/transactions/index.js.map +9 -0
  172. package/dist/src/utils/index.cjs +168 -0
  173. package/dist/src/utils/index.cjs.map +11 -0
  174. package/dist/src/utils/index.d.cts +140 -0
  175. package/dist/src/utils/index.d.ts +140 -0
  176. package/dist/src/utils/index.js +222 -0
  177. package/dist/src/utils/index.js.map +11 -0
  178. package/package.json +105 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/transactions/multisig.ts", "../src/transactions/authorization.ts", "../src/transactions/types.ts", "../src/transactions/wire/serialize.ts"],
4
+ "sourcesContent": [
5
+ "import {\n getPublicKey as nobleGetPublicKey,\n sign as nobleSign,\n} from \"@noble/secp256k1\";\nimport { c32address } from \"../utils/c32.ts\";\nimport { bytesToHex, hexToBytes, intToHex, concatBytes } from \"../utils/encoding.ts\";\nimport { hash160 } from \"../utils/hash.ts\";\nimport {\n sigHashPreSign,\n sigHashPostSign,\n intoInitialSighashAuth,\n nextSignature,\n} from \"./authorization.ts\";\nimport { txidFromBytes } from \"../utils/hash.ts\";\nimport { serializeTransaction } from \"./wire/serialize.ts\";\nimport {\n AuthType,\n AddressHashMode,\n PubKeyEncoding,\n type MultiSigSpendingCondition,\n type MultiSigHashMode,\n type TransactionAuthField,\n type StacksTransaction,\n} from \"./types.ts\";\nimport type { StacksChain } from \"../chains/types.ts\";\nimport type { LocalAccount, CustomAccount } from \"../accounts/types.ts\";\n\n// OP codes for redeem script\nconst OP_CHECKMULTISIG = 0xae;\n\n/** Check if hash mode is non-sequential (SIP-027) */\nexport function isNonSequential(hashMode: number): boolean {\n return (hashMode & 0x04) !== 0;\n}\n\n/** Build a Bitcoin-style redeem script for m-of-n multi-sig */\nfunction makeRedeemScript(publicKeys: string[], signaturesRequired: number): Uint8Array {\n const parts: Uint8Array[] = [];\n parts.push(new Uint8Array([0x50 + signaturesRequired])); // OP_n\n for (const pk of publicKeys) {\n const pkBytes = hexToBytes(pk);\n parts.push(new Uint8Array([pkBytes.length])); // length prefix (0x21 for compressed)\n parts.push(pkBytes);\n }\n parts.push(new Uint8Array([0x50 + publicKeys.length])); // OP_m\n parts.push(new Uint8Array([OP_CHECKMULTISIG]));\n return concatBytes(...parts);\n}\n\n/** Derive a multi-sig address from public keys */\nexport function makeMultiSigAddress(\n publicKeys: string[],\n signaturesRequired: number,\n chain?: StacksChain\n): string {\n if (signaturesRequired < 1 || signaturesRequired > publicKeys.length) {\n throw new Error(`signaturesRequired must be between 1 and ${publicKeys.length}`);\n }\n const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);\n const signer = hash160(redeemScript);\n const version = chain?.addressVersion?.multiSig ?? 20; // mainnet default\n return c32address(version, bytesToHex(signer));\n}\n\n/** Create an empty multi-sig spending condition */\nexport function createMultiSigSpendingCondition(\n publicKeys: string[],\n signaturesRequired: number,\n nonce: bigint,\n fee: bigint,\n hashMode: MultiSigHashMode = AddressHashMode.P2SH\n): MultiSigSpendingCondition {\n const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);\n const signer = bytesToHex(hash160(redeemScript));\n\n return {\n hashMode,\n signer,\n nonce,\n fee,\n fields: [],\n signaturesRequired,\n };\n}\n\n/** Compute the initial sighash for a transaction (same as signBegin) */\nfunction initialSigHash(tx: StacksTransaction): string {\n const cleared: StacksTransaction = {\n ...tx,\n auth: intoInitialSighashAuth(tx.auth),\n };\n return txidFromBytes(serializeTransaction(cleared));\n}\n\n/** Compute the presign-sighash used by all non-sequential signers */\nfunction nonSequentialPreSignHash(tx: StacksTransaction): string {\n const condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n const initHash = initialSigHash(tx);\n return sigHashPreSign(initHash, AuthType.Standard, condition.fee, condition.nonce);\n}\n\n/** Replay sighash through existing auth fields of a multi-sig tx */\nexport function replayMultiSigSigHash(tx: StacksTransaction): string {\n const condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n\n // Non-sequential: all signers sign the same presign-sighash, no field chaining\n if (isNonSequential(condition.hashMode)) {\n const preSign = nonSequentialPreSignHash(tx);\n // Chain through all fields to get the final sighash\n let curSigHash = preSign;\n for (const field of condition.fields) {\n curSigHash = sigHashPostSign(curSigHash, field.pubKeyEncoding, field.data);\n }\n return curSigHash;\n }\n\n // Sequential: chain through all fields\n let curSigHash = initialSigHash(tx);\n for (const field of condition.fields) {\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n }\n return curSigHash;\n}\n\n/** Sign one position of a multi-sig transaction with a private key */\nexport function signMultiSig(\n tx: StacksTransaction,\n privateKey: string,\n publicKeys: string[]\n): StacksTransaction {\n const keyBytes = hexToBytes(privateKey).slice(0, 32);\n const signerPubKey = bytesToHex(nobleGetPublicKey(keyBytes, true));\n\n const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);\n if (signerIndex === -1) {\n throw new Error(\"Private key does not correspond to any signer in the multi-sig\");\n }\n\n const condition = { ...(tx.auth.spendingCondition as MultiSigSpendingCondition) };\n\n // Non-sequential: all signers sign the same presign-sighash independently\n if (isNonSequential(condition.hashMode)) {\n return signNonSequential(tx, condition, privateKey);\n }\n\n // Sequential: existing P2SH behavior\n return signSequential(tx, condition, privateKey, publicKeys, signerIndex);\n}\n\n/** Non-sequential signing: compute presign-sighash from initial tx, sign, append */\nfunction signNonSequential(\n tx: StacksTransaction,\n condition: MultiSigSpendingCondition,\n privateKey: string\n): StacksTransaction {\n const fields = [...condition.fields];\n const preSignHash = nonSequentialPreSignHash(tx);\n\n // Sign the presign-sighash directly\n const keyBytes = hexToBytes(privateKey).slice(0, 32);\n const sig = nobleSign(preSignHash, keyBytes, { lowS: true });\n const recoveryIdHex = intToHex(sig.recovery, 1);\n const nextSig = recoveryIdHex + sig.toCompactHex();\n\n fields.push({\n type: \"signature\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: nextSig,\n });\n\n const newCondition: MultiSigSpendingCondition = { ...condition, fields };\n const sigCount = fields.filter((f) => f.type === \"signature\").length;\n\n // Auto-finalize: non-sequential needs no pubkey gap-filling\n if (sigCount >= condition.signaturesRequired) {\n return {\n ...tx,\n auth: { ...tx.auth, spendingCondition: newCondition },\n };\n }\n\n return {\n ...tx,\n auth: { ...tx.auth, spendingCondition: newCondition },\n };\n}\n\n/** Sequential signing: existing P2SH behavior */\nfunction signSequential(\n tx: StacksTransaction,\n condition: MultiSigSpendingCondition,\n privateKey: string,\n publicKeys: string[],\n signerIndex: number\n): StacksTransaction {\n const fields = [...condition.fields];\n\n // Replay sighash through existing fields\n let curSigHash = initialSigHash(tx);\n for (const field of fields) {\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n }\n\n // Fill intervening positions with pubkey fields\n for (let i = fields.length; i < signerIndex; i++) {\n const pubKeyField: TransactionAuthField = {\n type: \"publicKey\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: publicKeys[i]!,\n };\n fields.push(pubKeyField);\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n curSigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);\n }\n\n // Sign at signerIndex\n const { nextSig, nextSigHash } = nextSignature(\n curSigHash,\n AuthType.Standard,\n condition.fee,\n condition.nonce,\n privateKey\n );\n\n fields.push({\n type: \"signature\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: nextSig,\n });\n curSigHash = nextSigHash;\n\n const newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n // Count signatures so far\n const sigCount = fields.filter((f) => f.type === \"signature\").length;\n let finalCondition = newCondition;\n\n // Auto-finalize if enough signatures collected\n if (sigCount >= condition.signaturesRequired) {\n finalCondition = finalizeMultiSigCondition(newCondition, publicKeys, curSigHash);\n }\n\n return {\n ...tx,\n auth: {\n ...tx.auth,\n spendingCondition: finalCondition,\n },\n };\n}\n\n/** Sign one position of a multi-sig transaction with an account */\nexport async function signMultiSigWithAccount(\n tx: StacksTransaction,\n account: LocalAccount | CustomAccount,\n publicKeys: string[]\n): Promise<StacksTransaction> {\n const signerPubKey = account.publicKey;\n\n const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);\n if (signerIndex === -1) {\n throw new Error(\"Account does not correspond to any signer in the multi-sig\");\n }\n\n const condition = { ...(tx.auth.spendingCondition as MultiSigSpendingCondition) };\n\n // Non-sequential: all signers sign the same presign-sighash independently\n if (isNonSequential(condition.hashMode)) {\n return signNonSequentialWithAccount(tx, condition, account);\n }\n\n // Sequential: existing behavior\n return signSequentialWithAccount(tx, condition, account, publicKeys, signerIndex);\n}\n\n/** Non-sequential signing with account */\nasync function signNonSequentialWithAccount(\n tx: StacksTransaction,\n condition: MultiSigSpendingCondition,\n account: LocalAccount | CustomAccount\n): Promise<StacksTransaction> {\n const fields = [...condition.fields];\n const preSignHash = nonSequentialPreSignHash(tx);\n\n const sigBytes = await account.sign(hexToBytes(preSignHash));\n const nextSig = bytesToHex(sigBytes);\n\n fields.push({\n type: \"signature\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: nextSig,\n });\n\n const newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n return {\n ...tx,\n auth: { ...tx.auth, spendingCondition: newCondition },\n };\n}\n\n/** Sequential signing with account */\nasync function signSequentialWithAccount(\n tx: StacksTransaction,\n condition: MultiSigSpendingCondition,\n account: LocalAccount | CustomAccount,\n publicKeys: string[],\n signerIndex: number\n): Promise<StacksTransaction> {\n const fields = [...condition.fields];\n\n // Replay sighash through existing fields\n let curSigHash = initialSigHash(tx);\n for (const field of fields) {\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n }\n\n // Fill intervening positions with pubkey fields\n for (let i = fields.length; i < signerIndex; i++) {\n const pubKeyField: TransactionAuthField = {\n type: \"publicKey\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: publicKeys[i]!,\n };\n fields.push(pubKeyField);\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n curSigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);\n }\n\n // Sign at signerIndex\n const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);\n const sigBytes = await account.sign(hexToBytes(preSign));\n const nextSig = bytesToHex(sigBytes);\n const nextSigHash = sigHashPostSign(preSign, PubKeyEncoding.Compressed, nextSig);\n\n fields.push({\n type: \"signature\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: nextSig,\n });\n curSigHash = nextSigHash;\n\n const newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n // Count signatures so far\n const sigCount = fields.filter((f) => f.type === \"signature\").length;\n let finalCondition = newCondition;\n\n // Auto-finalize if enough signatures collected\n if (sigCount >= condition.signaturesRequired) {\n finalCondition = finalizeMultiSigCondition(newCondition, publicKeys, curSigHash);\n }\n\n return {\n ...tx,\n auth: {\n ...tx.auth,\n spendingCondition: finalCondition,\n },\n };\n}\n\n/** Fill remaining slots with pubkey fields after all signatures are collected */\nexport function finalizeMultiSig(\n tx: StacksTransaction,\n publicKeys: string[]\n): StacksTransaction {\n const condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n\n // Non-sequential: no pubkey gap-filling needed\n if (isNonSequential(condition.hashMode)) {\n return tx;\n }\n\n const curSigHash = replayMultiSigSigHash(tx);\n const finalCondition = finalizeMultiSigCondition(condition, publicKeys, curSigHash);\n\n return {\n ...tx,\n auth: {\n ...tx.auth,\n spendingCondition: finalCondition,\n },\n };\n}\n\n/** Internal: finalize remaining pubkey slots (sequential only) */\nfunction finalizeMultiSigCondition(\n condition: MultiSigSpendingCondition,\n publicKeys: string[],\n curSigHash: string\n): MultiSigSpendingCondition {\n const fields = [...condition.fields];\n let sigHash = curSigHash;\n\n // Fill remaining positions\n for (let i = fields.length; i < publicKeys.length; i++) {\n const pubKeyField: TransactionAuthField = {\n type: \"publicKey\",\n pubKeyEncoding: PubKeyEncoding.Compressed,\n data: publicKeys[i]!,\n };\n fields.push(pubKeyField);\n const preSign = sigHashPreSign(sigHash, AuthType.Standard, condition.fee, condition.nonce);\n sigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);\n }\n\n return { ...condition, fields };\n}\n\n/** Combine independently-signed non-sequential multi-sig transactions */\nexport function combineMultiSigSignatures(\n baseTx: StacksTransaction,\n signedTxs: StacksTransaction[]\n): StacksTransaction {\n const condition = baseTx.auth.spendingCondition as MultiSigSpendingCondition;\n\n if (!isNonSequential(condition.hashMode)) {\n throw new Error(\"combineMultiSigSignatures only works with non-sequential hash modes (SIP-027)\");\n }\n\n // Collect all signature fields from each signed tx\n const seenSigs = new Set<string>();\n const signatures: TransactionAuthField[] = [];\n\n for (const stx of signedTxs) {\n const stxCondition = stx.auth.spendingCondition as MultiSigSpendingCondition;\n for (const field of stxCondition.fields) {\n if (field.type === \"signature\" && !seenSigs.has(field.data)) {\n seenSigs.add(field.data);\n signatures.push(field);\n }\n }\n }\n\n if (signatures.length === 0) {\n throw new Error(\"No signatures found in the provided transactions\");\n }\n\n const newCondition: MultiSigSpendingCondition = {\n ...condition,\n fields: signatures,\n };\n\n return {\n ...baseTx,\n auth: { ...baseTx.auth, spendingCondition: newCondition },\n };\n}\n",
6
+ "import {\n getPublicKey as nobleGetPublicKey,\n sign,\n etc,\n} from \"@noble/secp256k1\";\nimport { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport {\n bytesToHex,\n hexToBytes,\n intToBytes,\n intToHex,\n concatBytes,\n} from \"../utils/encoding.ts\";\nimport { hashP2PKH, txidFromBytes } from \"../utils/hash.ts\";\nimport {\n AuthType,\n AddressHashMode,\n PubKeyEncoding,\n RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n type SingleSigSpendingCondition,\n type SpendingCondition,\n type Authorization,\n type StandardAuthorization,\n type SponsoredAuthorization,\n} from \"./types.ts\";\n\n// Ensure sync signing is available\netc.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {\n const h = hmac.create(sha256, key);\n msgs.forEach((msg) => h.update(msg));\n return h.digest();\n};\n\nconst EMPTY_SIG = bytesToHex(new Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));\n\nexport function createSingleSigSpendingCondition(\n publicKey: string,\n nonce: bigint,\n fee: bigint\n): SingleSigSpendingCondition {\n const pubKeyBytes = hexToBytes(publicKey);\n const signer = hashP2PKH(pubKeyBytes);\n const isCompressed = pubKeyBytes.length === 33;\n\n return {\n hashMode: AddressHashMode.P2PKH,\n signer,\n nonce,\n fee,\n keyEncoding: isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed,\n signature: EMPTY_SIG,\n };\n}\n\nexport function createStandardAuth(\n spendingCondition: SpendingCondition\n): StandardAuthorization {\n return { authType: AuthType.Standard, spendingCondition };\n}\n\nexport function createSponsoredAuth(\n spendingCondition: SpendingCondition,\n sponsorSpendingCondition?: SpendingCondition\n): SponsoredAuthorization {\n return {\n authType: AuthType.Sponsored,\n spendingCondition,\n sponsorSpendingCondition: sponsorSpendingCondition ?? createSingleSigSpendingCondition(\n \"0\".repeat(66),\n 0n,\n 0n\n ),\n };\n}\n\nfunction clearCondition(condition: SpendingCondition): SpendingCondition {\n if (\"signature\" in condition) {\n return {\n ...condition,\n nonce: 0n,\n fee: 0n,\n signature: EMPTY_SIG,\n };\n }\n return {\n ...condition,\n nonce: 0n,\n fee: 0n,\n fields: [],\n };\n}\n\nexport function intoInitialSighashAuth(auth: Authorization): Authorization {\n if (auth.authType === AuthType.Standard) {\n return createStandardAuth(clearCondition(auth.spendingCondition));\n }\n return createSponsoredAuth(\n clearCondition(auth.spendingCondition),\n clearCondition(createSingleSigSpendingCondition(\"0\".repeat(66), 0n, 0n))\n );\n}\n\n/** Compute pre-sign sighash = sha512/256(prevSigHash + authType + fee + nonce) */\nexport function sigHashPreSign(\n curSigHash: string,\n authType: number,\n fee: bigint,\n nonce: bigint\n): string {\n const data = concatBytes(\n hexToBytes(curSigHash),\n new Uint8Array([authType]),\n intToBytes(fee, 8),\n intToBytes(nonce, 8)\n );\n return txidFromBytes(data);\n}\n\n/** Compute post-sign sighash = sha512/256(preSigHash + pubKeyEncoding + signature) */\nexport function sigHashPostSign(\n curSigHash: string,\n pubKeyEncoding: number,\n signature: string\n): string {\n const data = concatBytes(\n hexToBytes(curSigHash),\n new Uint8Array([pubKeyEncoding]),\n hexToBytes(signature)\n );\n return txidFromBytes(data);\n}\n\n/** Sign with private key and return VRS signature (recoveryId + r + s) */\nfunction signWithKey(privateKey: string, messageHash: string): string {\n const keyBytes = hexToBytes(privateKey).slice(0, 32);\n const sig = sign(messageHash, keyBytes, { lowS: true });\n const recoveryIdHex = intToHex(sig.recovery, 1);\n return recoveryIdHex + sig.toCompactHex();\n}\n\nexport function nextSignature(\n curSigHash: string,\n authType: number,\n fee: bigint,\n nonce: bigint,\n privateKey: string\n): { nextSig: string; nextSigHash: string } {\n const sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);\n\n const keyBytes = hexToBytes(privateKey).slice(0, 32);\n const pubKey = nobleGetPublicKey(keyBytes, true);\n const isCompressed = pubKey.length === 33;\n const pubKeyEncoding = isCompressed\n ? PubKeyEncoding.Compressed\n : PubKeyEncoding.Uncompressed;\n\n const nextSig = signWithKey(privateKey, sigHashPre);\n const nextSigHash = sigHashPostSign(sigHashPre, pubKeyEncoding, nextSig);\n\n return { nextSig, nextSigHash };\n}\n",
7
+ "import type { ClarityValue } from \"../clarity/types.ts\";\n\n// Auth types\nexport const AuthType = {\n Standard: 0x04,\n Sponsored: 0x05,\n} as const;\nexport type AuthType = (typeof AuthType)[keyof typeof AuthType];\n\n// Payload types\nexport const PayloadType = {\n TokenTransfer: 0x00,\n SmartContract: 0x01,\n ContractCall: 0x02,\n PoisonMicroblock: 0x03,\n Coinbase: 0x04,\n CoinbaseToAltRecipient: 0x05,\n VersionedSmartContract: 0x06,\n TenureChange: 0x07,\n NakamotoCoinbase: 0x08,\n} as const;\nexport type PayloadType = (typeof PayloadType)[keyof typeof PayloadType];\n\n// Clarity version\nexport const ClarityVersion = {\n Clarity1: 1,\n Clarity2: 2,\n Clarity3: 3,\n} as const;\nexport type ClarityVersion = (typeof ClarityVersion)[keyof typeof ClarityVersion];\n\n// Anchor mode (deprecated post-Nakamoto, but needed for wire format)\nexport const AnchorMode = {\n OnChainOnly: 0x01,\n OffChainOnly: 0x02,\n Any: 0x03,\n} as const;\nexport type AnchorMode = (typeof AnchorMode)[keyof typeof AnchorMode];\n\n// Post condition mode\nexport const PostConditionModeWire = {\n Allow: 0x01,\n Deny: 0x02,\n} as const;\nexport type PostConditionModeWire =\n (typeof PostConditionModeWire)[keyof typeof PostConditionModeWire];\n\n// Address hash modes\nexport const AddressHashMode = {\n P2PKH: 0x00,\n P2SH: 0x01,\n P2WPKH: 0x02,\n P2WSH: 0x03,\n P2SH_NonSequential: 0x05, // SIP-027\n P2WSH_P2SH_NonSequential: 0x07, // SIP-027\n} as const;\nexport type AddressHashMode = (typeof AddressHashMode)[keyof typeof AddressHashMode];\n\n// Pub key encoding\nexport const PubKeyEncoding = {\n Compressed: 0x00,\n Uncompressed: 0x01,\n} as const;\nexport type PubKeyEncoding = (typeof PubKeyEncoding)[keyof typeof PubKeyEncoding];\n\n// Fungible condition codes (wire format)\nexport const FungibleConditionCode = {\n Equal: 0x01,\n Greater: 0x02,\n GreaterEqual: 0x03,\n Less: 0x04,\n LessEqual: 0x05,\n} as const;\n\n// Non-fungible condition codes (wire format)\nexport const NonFungibleConditionCode = {\n Sends: 0x10,\n DoesNotSend: 0x11,\n} as const;\n\n// Post condition principal types\nexport const PostConditionPrincipalId = {\n Origin: 0x01,\n Standard: 0x02,\n Contract: 0x03,\n} as const;\n\n// Post condition asset types\nexport const AssetType = {\n STX: 0x00,\n Fungible: 0x01,\n NonFungible: 0x02,\n} as const;\n\n// Auth field types\nexport const AuthFieldType = {\n PublicKeyCompressed: 0x00,\n PublicKeyUncompressed: 0x01,\n SignatureCompressed: 0x02,\n SignatureUncompressed: 0x03,\n} as const;\n\nexport const RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;\nexport const MEMO_MAX_LENGTH_BYTES = 34;\nexport const MAX_STRING_LENGTH_BYTES = 128;\n\n// Token transfer payload\nexport type TokenTransferPayload = {\n payloadType: typeof PayloadType.TokenTransfer;\n recipient: ClarityValue; // PrincipalCV\n amount: bigint;\n memo: string;\n};\n\n// Contract call payload\nexport type ContractCallPayload = {\n payloadType: typeof PayloadType.ContractCall;\n contractAddress: string;\n contractName: string;\n functionName: string;\n functionArgs: ClarityValue[];\n};\n\n// Smart contract deploy payload\nexport type SmartContractPayload = {\n payloadType: typeof PayloadType.SmartContract | typeof PayloadType.VersionedSmartContract;\n clarityVersion?: ClarityVersion;\n contractName: string;\n codeBody: string;\n};\n\nexport type TransactionPayload =\n | TokenTransferPayload\n | ContractCallPayload\n | SmartContractPayload;\n\n// Spending condition\nexport type SingleSigSpendingCondition = {\n hashMode: typeof AddressHashMode.P2PKH | typeof AddressHashMode.P2WPKH;\n signer: string; // hash160 hex\n nonce: bigint;\n fee: bigint;\n keyEncoding: PubKeyEncoding;\n signature: string; // 65-byte recoverable sig hex\n};\n\nexport type TransactionAuthField = {\n pubKeyEncoding: PubKeyEncoding;\n type: \"publicKey\" | \"signature\";\n data: string; // hex\n};\n\nexport type MultiSigHashMode =\n | typeof AddressHashMode.P2SH\n | typeof AddressHashMode.P2WSH\n | typeof AddressHashMode.P2SH_NonSequential\n | typeof AddressHashMode.P2WSH_P2SH_NonSequential;\n\nexport type MultiSigSpendingCondition = {\n hashMode: MultiSigHashMode;\n signer: string;\n nonce: bigint;\n fee: bigint;\n fields: TransactionAuthField[];\n signaturesRequired: number;\n};\n\nexport type SpendingCondition = SingleSigSpendingCondition | MultiSigSpendingCondition;\n\nexport type StandardAuthorization = {\n authType: typeof AuthType.Standard;\n spendingCondition: SpendingCondition;\n};\n\nexport type SponsoredAuthorization = {\n authType: typeof AuthType.Sponsored;\n spendingCondition: SpendingCondition;\n sponsorSpendingCondition: SpendingCondition;\n};\n\nexport type Authorization = StandardAuthorization | SponsoredAuthorization;\n\n// Full transaction\nexport type StacksTransaction = {\n version: number;\n chainId: number;\n auth: Authorization;\n anchorMode: AnchorMode;\n postConditionMode: PostConditionModeWire;\n postConditions: PostConditionWire[];\n payload: TransactionPayload;\n};\n\n// Wire post condition types\nexport type PostConditionWire = StxPostConditionWire | FtPostConditionWire | NftPostConditionWire;\n\nexport type StxPostConditionWire = {\n type: \"stx\";\n principal: PostConditionPrincipalWire;\n conditionCode: number;\n amount: bigint;\n};\n\nexport type FtPostConditionWire = {\n type: \"ft\";\n principal: PostConditionPrincipalWire;\n asset: AssetInfoWire;\n conditionCode: number;\n amount: bigint;\n};\n\nexport type NftPostConditionWire = {\n type: \"nft\";\n principal: PostConditionPrincipalWire;\n asset: AssetInfoWire;\n conditionCode: number;\n assetId: ClarityValue;\n};\n\nexport type PostConditionPrincipalWire =\n | { type: \"origin\" }\n | { type: \"standard\"; address: string }\n | { type: \"contract\"; address: string; contractName: string };\n\nexport type AssetInfoWire = {\n address: string;\n contractName: string;\n assetName: string;\n};\n",
8
+ "import {\n bytesToHex,\n hexToBytes,\n concatBytes,\n intToBytes,\n intToHex,\n utf8ToBytes,\n asciiToBytes,\n writeUInt32BE,\n writeUInt16BE,\n writeUInt8,\n} from \"../../utils/encoding.ts\";\nimport { c32addressDecode } from \"../../utils/c32.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport {\n AuthType,\n PayloadType,\n PostConditionPrincipalId,\n AssetType,\n RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n MEMO_MAX_LENGTH_BYTES,\n type StacksTransaction,\n type Authorization,\n type SpendingCondition,\n type SingleSigSpendingCondition,\n type MultiSigSpendingCondition,\n type TransactionPayload,\n type PostConditionWire,\n type PostConditionPrincipalWire,\n type AssetInfoWire,\n type TransactionAuthField,\n type AuthFieldType,\n} from \"../types.ts\";\n\n// Address serialization: version (1 byte) + hash160 (20 bytes)\nfunction serializeAddress(c32Address: string): Uint8Array {\n const [version, hash160] = c32addressDecode(c32Address);\n return concatBytes(new Uint8Array([version]), hexToBytes(hash160));\n}\n\n// LP string: length prefix (n bytes) + content bytes\nfunction serializeLPString(str: string, prefixBytes = 1): Uint8Array {\n const content = utf8ToBytes(str);\n const prefix = hexToBytes(intToHex(content.byteLength, prefixBytes));\n return concatBytes(prefix, content);\n}\n\n// LP string for code body (4-byte prefix)\nfunction serializeLPStringLong(str: string): Uint8Array {\n return serializeLPString(str, 4);\n}\n\n// Memo: padded to MEMO_MAX_LENGTH_BYTES\nfunction serializeMemo(memo: string): Uint8Array {\n const content = asciiToBytes(memo);\n const padded = new Uint8Array(MEMO_MAX_LENGTH_BYTES);\n padded.set(content.slice(0, MEMO_MAX_LENGTH_BYTES));\n return concatBytes(writeUInt8(content.length), padded);\n}\n\nfunction serializeSpendingCondition(condition: SpendingCondition): Uint8Array {\n const parts: Uint8Array[] = [\n writeUInt8(condition.hashMode),\n hexToBytes(condition.signer), // 20 bytes\n intToBytes(condition.nonce, 8),\n intToBytes(condition.fee, 8),\n ];\n\n if (\"signature\" in condition) {\n // Single sig\n const sc = condition as SingleSigSpendingCondition;\n parts.push(writeUInt8(sc.keyEncoding));\n parts.push(hexToBytes(sc.signature)); // 65 bytes\n } else {\n // Multi sig\n const mc = condition as MultiSigSpendingCondition;\n // Fields as LP list\n parts.push(writeUInt32BE(mc.fields.length));\n for (const field of mc.fields) {\n parts.push(serializeAuthField(field));\n }\n parts.push(writeUInt16BE(mc.signaturesRequired));\n }\n\n return concatBytes(...parts);\n}\n\nfunction serializeAuthField(field: TransactionAuthField): Uint8Array {\n if (field.type === \"publicKey\") {\n const typeId = field.pubKeyEncoding === 0x00 ? 0x00 : 0x01;\n return concatBytes(writeUInt8(typeId), hexToBytes(field.data));\n } else {\n const typeId = field.pubKeyEncoding === 0x00 ? 0x02 : 0x03;\n return concatBytes(writeUInt8(typeId), hexToBytes(field.data));\n }\n}\n\nfunction serializeAuthorization(auth: Authorization): Uint8Array {\n const parts: Uint8Array[] = [writeUInt8(auth.authType)];\n parts.push(serializeSpendingCondition(auth.spendingCondition));\n if (auth.authType === AuthType.Sponsored) {\n parts.push(serializeSpendingCondition(auth.sponsorSpendingCondition));\n }\n return concatBytes(...parts);\n}\n\nfunction serializePrincipal(principal: PostConditionPrincipalWire): Uint8Array {\n switch (principal.type) {\n case \"origin\":\n return writeUInt8(PostConditionPrincipalId.Origin);\n case \"standard\":\n return concatBytes(\n writeUInt8(PostConditionPrincipalId.Standard),\n serializeAddress(principal.address)\n );\n case \"contract\":\n return concatBytes(\n writeUInt8(PostConditionPrincipalId.Contract),\n serializeAddress(principal.address),\n serializeLPString(principal.contractName)\n );\n }\n}\n\nfunction serializeAssetInfo(asset: AssetInfoWire): Uint8Array {\n return concatBytes(\n serializeAddress(asset.address),\n serializeLPString(asset.contractName),\n serializeLPString(asset.assetName)\n );\n}\n\nfunction serializePostCondition(pc: PostConditionWire): Uint8Array {\n const parts: Uint8Array[] = [serializePrincipal(pc.principal)];\n\n switch (pc.type) {\n case \"stx\":\n parts.push(writeUInt8(AssetType.STX));\n parts.push(writeUInt8(pc.conditionCode));\n parts.push(intToBytes(pc.amount, 8));\n break;\n case \"ft\":\n parts.push(writeUInt8(AssetType.Fungible));\n parts.push(serializeAssetInfo(pc.asset));\n parts.push(writeUInt8(pc.conditionCode));\n parts.push(intToBytes(pc.amount, 8));\n break;\n case \"nft\":\n parts.push(writeUInt8(AssetType.NonFungible));\n parts.push(serializeAssetInfo(pc.asset));\n parts.push(serializeCVBytes(pc.assetId));\n parts.push(writeUInt8(pc.conditionCode));\n break;\n }\n\n return concatBytes(...parts);\n}\n\nfunction serializePostConditions(pcs: PostConditionWire[]): Uint8Array {\n const parts: Uint8Array[] = [writeUInt32BE(pcs.length)];\n for (const pc of pcs) {\n parts.push(serializePostCondition(pc));\n }\n return concatBytes(...parts);\n}\n\nexport function serializePayload(payload: TransactionPayload): Uint8Array {\n const parts: Uint8Array[] = [writeUInt8(payload.payloadType)];\n\n switch (payload.payloadType) {\n case PayloadType.TokenTransfer:\n parts.push(serializeCVBytes(payload.recipient));\n parts.push(intToBytes(payload.amount, 8));\n parts.push(serializeMemo(payload.memo));\n break;\n\n case PayloadType.ContractCall:\n parts.push(serializeAddress(payload.contractAddress));\n parts.push(serializeLPString(payload.contractName));\n parts.push(serializeLPString(payload.functionName));\n parts.push(writeUInt32BE(payload.functionArgs.length));\n for (const arg of payload.functionArgs) {\n parts.push(serializeCVBytes(arg));\n }\n break;\n\n case PayloadType.SmartContract:\n parts.push(serializeLPString(payload.contractName));\n parts.push(serializeLPStringLong(payload.codeBody));\n break;\n\n case PayloadType.VersionedSmartContract:\n parts.push(writeUInt8(payload.clarityVersion ?? 2));\n parts.push(serializeLPString(payload.contractName));\n parts.push(serializeLPStringLong(payload.codeBody));\n break;\n }\n\n return concatBytes(...parts);\n}\n\nexport function serializeTransaction(tx: StacksTransaction): Uint8Array {\n return concatBytes(\n writeUInt8(tx.version),\n writeUInt32BE(tx.chainId),\n serializeAuthorization(tx.auth),\n writeUInt8(tx.anchorMode),\n writeUInt8(tx.postConditionMode),\n serializePostConditions(tx.postConditions),\n serializePayload(tx.payload)\n );\n}\n\nexport function serializeTransactionHex(tx: StacksTransaction): string {\n return bytesToHex(serializeTransaction(tx));\n}\n"
9
+ ],
10
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,kBACE;AAAA,UACA;AAAA;;;ACFF;AAAA,kBACE;AAAA;AAAA;AAAA;AAIF;AACA;;;ACHO,IAAM,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,WAAW;AACb;AAIO,IAAM,cAAc;AAAA,EACzB,eAAe;AAAA,EACf,eAAe;AAAA,EACf,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,cAAc;AAAA,EACd,kBAAkB;AACpB;AAIO,IAAM,iBAAiB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G;AAAA,IACxC,MAAM,IAAI,MAAM,+EAA+E;AAAA,EACjG;AAAA,EAGA,MAAM,WAAW,IAAI;AAAA,EACrB,MAAM,aAAqC,CAAC;AAAA,EAE5C,WAAW,OAAO,WAAW;AAAA,IAC3B,MAAM,eAAe,IAAI,KAAK;AAAA,IAC9B,WAAW,SAAS,aAAa,QAAQ;AAAA,MACvC,IAAI,MAAM,SAAS,eAAe,CAAC,SAAS,IAAI,MAAM,IAAI,GAAG;AAAA,QAC3D,SAAS,IAAI,MAAM,IAAI;AAAA,QACvB,WAAW,KAAK,KAAK;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IAAI,WAAW,WAAW,GAAG;AAAA,IAC3B,MAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAAA,EAEA,MAAM,eAA0C;AAAA,OAC3C;AAAA,IACH,QAAQ;AAAA,EACV;AAAA,EAEA,OAAO;AAAA,OACF;AAAA,IACH,MAAM,KAAK,OAAO,MAAM,mBAAmB,aAAa;AAAA,EAC1D;AAAA;",
11
+ "debugId": "99F694C3EE6B35BA64756E2164756E21",
12
+ "names": []
13
+ }
@@ -0,0 +1,121 @@
1
+ import {
2
+ parseContractId,
3
+ validateStacksAddress
4
+ } from "./stacks-gjvbq6w7.js";
5
+ import {
6
+ intToBigInt
7
+ } from "./stacks-nqytwfcc.js";
8
+
9
+ // src/postconditions/builder.ts
10
+ class PartialPcWithPrincipal {
11
+ address;
12
+ constructor(address) {
13
+ this.address = address;
14
+ }
15
+ willSendEq(amount) {
16
+ return new PartialPcFtWithCode(this.address, amount, "eq");
17
+ }
18
+ willSendGte(amount) {
19
+ return new PartialPcFtWithCode(this.address, amount, "gte");
20
+ }
21
+ willSendGt(amount) {
22
+ return new PartialPcFtWithCode(this.address, amount, "gt");
23
+ }
24
+ willSendLte(amount) {
25
+ return new PartialPcFtWithCode(this.address, amount, "lte");
26
+ }
27
+ willSendLt(amount) {
28
+ return new PartialPcFtWithCode(this.address, amount, "lt");
29
+ }
30
+ willSendAsset() {
31
+ return new PartialPcNftWithCode(this.address, "sent");
32
+ }
33
+ willNotSendAsset() {
34
+ return new PartialPcNftWithCode(this.address, "not-sent");
35
+ }
36
+ }
37
+
38
+ class PartialPcFtWithCode {
39
+ address;
40
+ amount;
41
+ code;
42
+ constructor(address, amount, code) {
43
+ this.address = address;
44
+ this.amount = amount;
45
+ this.code = code;
46
+ }
47
+ ustx() {
48
+ return {
49
+ type: "stx-postcondition",
50
+ address: this.address,
51
+ condition: this.code,
52
+ amount: intToBigInt(this.amount).toString()
53
+ };
54
+ }
55
+ ft(contractId, tokenName) {
56
+ const [address, name] = contractId.split(".");
57
+ if (!address || !validateStacksAddress(address) || !name) {
58
+ throw new Error(`Invalid contract id: ${contractId}`);
59
+ }
60
+ return {
61
+ type: "ft-postcondition",
62
+ address: this.address,
63
+ condition: this.code,
64
+ amount: intToBigInt(this.amount).toString(),
65
+ asset: `${contractId}::${tokenName}`
66
+ };
67
+ }
68
+ }
69
+
70
+ class PartialPcNftWithCode {
71
+ address;
72
+ code;
73
+ constructor(address, code) {
74
+ this.address = address;
75
+ this.code = code;
76
+ }
77
+ nft(assetOrContractId, tokenNameOrAssetId, assetId) {
78
+ let contractAddress;
79
+ let contractName;
80
+ let tokenName;
81
+ let id;
82
+ if (assetId !== undefined) {
83
+ [contractAddress, contractName] = parseContractId(assetOrContractId);
84
+ tokenName = tokenNameOrAssetId;
85
+ id = assetId;
86
+ } else {
87
+ const [principal, tName] = assetOrContractId.split("::");
88
+ if (!principal || !tName)
89
+ throw new Error(`Invalid asset name: ${assetOrContractId}`);
90
+ [contractAddress, contractName] = parseContractId(principal);
91
+ tokenName = tName;
92
+ id = tokenNameOrAssetId;
93
+ }
94
+ if (!validateStacksAddress(contractAddress)) {
95
+ throw new Error(`Invalid contract address: ${contractAddress}`);
96
+ }
97
+ return {
98
+ type: "nft-postcondition",
99
+ address: this.address,
100
+ condition: this.code,
101
+ asset: `${contractAddress}.${contractName}::${tokenName}`,
102
+ assetId: id
103
+ };
104
+ }
105
+ }
106
+ var Pc = {
107
+ principal(address) {
108
+ const [addr, name] = address.split(".");
109
+ if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
110
+ throw new Error(`Invalid principal: ${address}`);
111
+ }
112
+ return new PartialPcWithPrincipal(address);
113
+ },
114
+ origin() {
115
+ return new PartialPcWithPrincipal("origin");
116
+ }
117
+ };
118
+ export { Pc };
119
+
120
+ //# debugId=A955F701F76F44AE64756E2164756E21
121
+ //# sourceMappingURL=stacks-yfveb68e.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/postconditions/builder.ts"],
4
+ "sourcesContent": [
5
+ "import { intToBigInt, type IntegerType } from \"../utils/encoding.ts\";\nimport { validateStacksAddress, parseContractId } from \"../utils/address.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type {\n StxPostCondition,\n FtPostCondition,\n NftPostCondition,\n FungibleComparator,\n NonFungibleComparator,\n} from \"./types.ts\";\n\nclass PartialPcWithPrincipal {\n constructor(private address: string) {}\n\n willSendEq(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"eq\");\n }\n willSendGte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gte\");\n }\n willSendGt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gt\");\n }\n willSendLte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lte\");\n }\n willSendLt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lt\");\n }\n willSendAsset() {\n return new PartialPcNftWithCode(this.address, \"sent\");\n }\n willNotSendAsset() {\n return new PartialPcNftWithCode(this.address, \"not-sent\");\n }\n}\n\nclass PartialPcFtWithCode {\n constructor(\n private address: string,\n private amount: IntegerType,\n private code: FungibleComparator\n ) {}\n\n ustx(): StxPostCondition {\n return {\n type: \"stx-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n };\n }\n\n ft(contractId: string, tokenName: string): FtPostCondition {\n const [address, name] = contractId.split(\".\");\n if (!address || !validateStacksAddress(address) || !name) {\n throw new Error(`Invalid contract id: ${contractId}`);\n }\n return {\n type: \"ft-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n asset: `${contractId}::${tokenName}`,\n };\n }\n}\n\nclass PartialPcNftWithCode {\n constructor(\n private address: string,\n private code: NonFungibleComparator\n ) {}\n\n nft(assetOrContractId: string, tokenNameOrAssetId: string | ClarityValue, assetId?: ClarityValue): NftPostCondition {\n let contractAddress: string;\n let contractName: string;\n let tokenName: string;\n let id: ClarityValue;\n\n if (assetId !== undefined) {\n // 3 args: contractId, tokenName, assetId\n [contractAddress, contractName] = parseContractId(assetOrContractId);\n tokenName = tokenNameOrAssetId as string;\n id = assetId;\n } else {\n // 2 args: assetString (addr.contract::token), assetId\n const [principal, tName] = assetOrContractId.split(\"::\");\n if (!principal || !tName) throw new Error(`Invalid asset name: ${assetOrContractId}`);\n [contractAddress, contractName] = parseContractId(principal);\n tokenName = tName;\n id = tokenNameOrAssetId as ClarityValue;\n }\n\n if (!validateStacksAddress(contractAddress)) {\n throw new Error(`Invalid contract address: ${contractAddress}`);\n }\n\n return {\n type: \"nft-postcondition\",\n address: this.address,\n condition: this.code,\n asset: `${contractAddress}.${contractName}::${tokenName}`,\n assetId: id,\n };\n }\n}\n\nexport const Pc = {\n principal(address: string) {\n const [addr, name] = address.split(\".\");\n if (!addr || !validateStacksAddress(addr) || (typeof name === \"string\" && !name)) {\n throw new Error(`Invalid principal: ${address}`);\n }\n return new PartialPcWithPrincipal(address);\n },\n origin() {\n return new PartialPcWithPrincipal(\"origin\");\n },\n};\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;AAWA,MAAM,uBAAuB;AAAA,EACP;AAAA,EAApB,WAAW,CAAS,SAAiB;AAAA,IAAjB;AAAA;AAAA,EAEpB,UAAU,CAAC,QAAqB;AAAA,IA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,IAAI,uBAAuB,OAAO;AAAA;AAAA,EAE3C,MAAM,GAAG;AAAA,IACP,OAAO,IAAI,uBAAuB,QAAQ;AAAA;AAE9C;",
8
+ "debugId": "A955F701F76F44AE64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,160 @@
1
+ import {
2
+ BaseError
3
+ } from "./stacks-709tra19.js";
4
+ import {
5
+ buildContractCall,
6
+ getTransactionId,
7
+ signTransactionWithAccount
8
+ } from "./stacks-f7wdrzs3.js";
9
+ import {
10
+ serializePayload,
11
+ serializeTransaction
12
+ } from "./stacks-yfgsm6ap.js";
13
+ import {
14
+ deserializeCVBytes
15
+ } from "./stacks-j2cy7qtt.js";
16
+ import {
17
+ serializeCVBytes
18
+ } from "./stacks-8yykgdww.js";
19
+ import {
20
+ parseContractId
21
+ } from "./stacks-gjvbq6w7.js";
22
+ import {
23
+ bytesToHex,
24
+ with0x
25
+ } from "./stacks-nqytwfcc.js";
26
+
27
+ // src/actions/public/getNonce.ts
28
+ async function getNonce(client, params) {
29
+ const data = await client.request(`/v2/accounts/${params.address}`, {
30
+ method: "GET"
31
+ });
32
+ return BigInt(data.nonce);
33
+ }
34
+
35
+ // src/actions/public/readContract.ts
36
+ async function readContract(client, params) {
37
+ const [address, name] = parseContractId(params.contract);
38
+ const sender = params.sender ?? address;
39
+ const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
40
+ const data = await client.request(`/v2/contracts/call-read/${address}/${name}/${params.functionName}`, {
41
+ method: "POST",
42
+ body: {
43
+ sender,
44
+ arguments: serializedArgs
45
+ }
46
+ });
47
+ if (data.okay) {
48
+ return deserializeCVBytes(data.result);
49
+ }
50
+ throw new Error(data.cause ?? "Read-only call failed");
51
+ }
52
+
53
+ // src/actions/public/getMapEntry.ts
54
+ async function getMapEntry(client, params) {
55
+ const [address, name] = parseContractId(params.contract);
56
+ const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
57
+ const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
58
+ method: "POST",
59
+ body: serializedKey
60
+ });
61
+ return deserializeCVBytes(data.data);
62
+ }
63
+
64
+ // src/actions/public/estimateFee.ts
65
+ async function estimateFee(client, params) {
66
+ const payloadHex = bytesToHex(serializePayload(params.transaction.payload));
67
+ const txHex = bytesToHex(serializeTransaction(params.transaction));
68
+ const data = await client.request("/v2/fees/transaction", {
69
+ method: "POST",
70
+ body: {
71
+ estimated_len: Math.ceil(txHex.length / 2),
72
+ transaction_payload: "0x" + payloadHex
73
+ }
74
+ });
75
+ return (data.estimations ?? []).map((e) => ({
76
+ feeRate: e.fee_rate,
77
+ fee: e.fee
78
+ }));
79
+ }
80
+
81
+ // src/errors/transaction.ts
82
+ class BroadcastError extends BaseError {
83
+ name = "BroadcastError";
84
+ txid;
85
+ reason;
86
+ constructor(message, options) {
87
+ super(message, options);
88
+ this.txid = options?.txid;
89
+ this.reason = options?.reason;
90
+ }
91
+ }
92
+
93
+ // src/actions/wallet/sendTransaction.ts
94
+ async function sendTransaction(client, params) {
95
+ const hex = bytesToHex(serializeTransaction(params.transaction));
96
+ const body = { tx: hex };
97
+ if (params.attachment) {
98
+ body.attachment = typeof params.attachment === "string" ? params.attachment : bytesToHex(params.attachment);
99
+ }
100
+ const data = await client.request("/v2/transactions", {
101
+ method: "POST",
102
+ body
103
+ });
104
+ if (data.error) {
105
+ throw new BroadcastError(data.reason ?? data.error, {
106
+ reason: data.reason
107
+ });
108
+ }
109
+ const txid = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
110
+ return { txid };
111
+ }
112
+
113
+ // src/actions/wallet/utils.ts
114
+ function isProviderAccount(account) {
115
+ return account.type === "provider";
116
+ }
117
+
118
+ // src/actions/wallet/callContract.ts
119
+ async function callContract(client, params) {
120
+ const account = client.account;
121
+ if (!account)
122
+ throw new Error("Account required");
123
+ if (isProviderAccount(account)) {
124
+ const result2 = await account.provider.request("stx_callContract", {
125
+ contract: params.contract,
126
+ functionName: params.functionName,
127
+ functionArgs: params.functionArgs ?? []
128
+ });
129
+ return result2.txid;
130
+ }
131
+ const [contractAddress, contractName] = parseContractId(params.contract);
132
+ const nonce = params.nonce ?? await getNonce(client, { address: account.address });
133
+ const unsigned = buildContractCall({
134
+ contractAddress,
135
+ contractName,
136
+ functionName: params.functionName,
137
+ functionArgs: params.functionArgs ?? [],
138
+ fee: params.fee ?? 0n,
139
+ nonce,
140
+ publicKey: account.publicKey,
141
+ chain: client.chain,
142
+ postConditionMode: params.postConditionMode,
143
+ postConditions: params.postConditions
144
+ });
145
+ if (params.fee === undefined) {
146
+ const estimates = await estimateFee(client, { transaction: unsigned });
147
+ const mid = estimates[1] ?? estimates[0];
148
+ if (mid) {
149
+ unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
150
+ }
151
+ }
152
+ const signed = await signTransactionWithAccount(unsigned, account);
153
+ const result = await sendTransaction(client, { transaction: signed });
154
+ return result.txid;
155
+ }
156
+
157
+ export { getNonce, readContract, getMapEntry, estimateFee, sendTransaction, isProviderAccount, callContract };
158
+
159
+ //# debugId=B88C94A76BEBD99764756E2164756E21
160
+ //# sourceMappingURL=stacks-zm0b3tgy.js.map
@@ -0,0 +1,17 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/actions/public/getNonce.ts", "../src/actions/public/readContract.ts", "../src/actions/public/getMapEntry.ts", "../src/actions/public/estimateFee.ts", "../src/errors/transaction.ts", "../src/actions/wallet/sendTransaction.ts", "../src/actions/wallet/utils.ts", "../src/actions/wallet/callContract.ts"],
4
+ "sourcesContent": [
5
+ "import type { Client } from \"../../clients/types.ts\";\n\nexport type GetNonceParams = {\n address: string;\n};\n\nexport type GetNonceResult = {\n nonce: bigint;\n possibleNextNonce: bigint;\n};\n\nexport async function getNonce(\n client: Client,\n params: GetNonceParams\n): Promise<bigint> {\n const data = await client.request(`/v2/accounts/${params.address}`, {\n method: \"GET\",\n });\n return BigInt(data.nonce);\n}\n",
6
+ "import type { Client } from \"../../clients/types.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type ReadContractParams = {\n contract: string; // \"address.name\"\n functionName: string;\n args?: ClarityValue[];\n sender?: string;\n};\n\nexport async function readContract<T extends ClarityValue = ClarityValue>(\n client: Client,\n params: ReadContractParams\n): Promise<T> {\n const [address, name] = parseContractId(params.contract);\n const sender = params.sender ?? address;\n\n const serializedArgs = (params.args ?? []).map((arg) =>\n with0x(bytesToHex(serializeCVBytes(arg)))\n );\n\n const data = await client.request(\n `/v2/contracts/call-read/${address}/${name}/${params.functionName}`,\n {\n method: \"POST\",\n body: {\n sender,\n arguments: serializedArgs,\n },\n }\n );\n\n if (data.okay) {\n return deserializeCVBytes<T>(data.result);\n }\n throw new Error(data.cause ?? \"Read-only call failed\");\n}\n",
7
+ "import type { Client } from \"../../clients/types.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetMapEntryParams = {\n contract: string; // \"address.name\"\n mapName: string;\n key: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n client: Client,\n params: GetMapEntryParams\n): Promise<T> {\n const [address, name] = parseContractId(params.contract);\n const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n const data = await client.request(\n `/v2/map_entry/${address}/${name}/${params.mapName}`,\n {\n method: \"POST\",\n body: serializedKey,\n }\n );\n\n return deserializeCVBytes<T>(data.data);\n}\n",
8
+ "import type { Client } from \"../../clients/types.ts\";\nimport { bytesToHex } from \"../../utils/encoding.ts\";\nimport { serializePayload, serializeTransaction } from \"../../transactions/wire/serialize.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\n\nexport type EstimateFeeParams = {\n transaction: StacksTransaction;\n};\n\nexport type FeeEstimation = {\n feeRate: number;\n fee: number;\n};\n\nexport async function estimateFee(\n client: Client,\n params: EstimateFeeParams\n): Promise<FeeEstimation[]> {\n const payloadHex = bytesToHex(serializePayload(params.transaction.payload));\n const txHex = bytesToHex(serializeTransaction(params.transaction));\n\n const data = await client.request(\"/v2/fees/transaction\", {\n method: \"POST\",\n body: {\n estimated_len: Math.ceil(txHex.length / 2),\n transaction_payload: \"0x\" + payloadHex,\n },\n });\n\n return (data.estimations ?? []).map((e: any) => ({\n feeRate: e.fee_rate,\n fee: e.fee,\n }));\n}\n",
9
+ "import { BaseError } from \"./base.ts\";\n\nexport class TransactionError extends BaseError {\n override name = \"TransactionError\";\n}\n\nexport class BroadcastError extends BaseError {\n override name = \"BroadcastError\";\n txid?: string;\n reason?: string;\n\n constructor(\n message: string,\n options?: { cause?: Error; txid?: string; reason?: string }\n ) {\n super(message, options);\n this.txid = options?.txid;\n this.reason = options?.reason;\n }\n}\n\nexport class SerializationError extends BaseError {\n override name = \"SerializationError\";\n}\n\nexport class SigningError extends BaseError {\n override name = \"SigningError\";\n}\n",
10
+ "import type { Client, WalletClient } from \"../../clients/types.ts\";\nimport { bytesToHex } from \"../../utils/encoding.ts\";\nimport { serializeTransaction } from \"../../transactions/wire/serialize.ts\";\nimport { getTransactionId } from \"../../transactions/signer.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { BroadcastError } from \"../../errors/transaction.ts\";\n\nexport type SendTransactionParams = {\n transaction: StacksTransaction;\n attachment?: Uint8Array | string;\n};\n\nexport type SendTransactionResult = {\n txid: string;\n};\n\n/** Broadcast a signed transaction to the network */\nexport async function sendTransaction(\n client: Client,\n params: SendTransactionParams\n): Promise<SendTransactionResult> {\n const hex = bytesToHex(serializeTransaction(params.transaction));\n\n const body: Record<string, string> = { tx: hex };\n if (params.attachment) {\n body.attachment =\n typeof params.attachment === \"string\"\n ? params.attachment\n : bytesToHex(params.attachment);\n }\n\n const data = await client.request(\"/v2/transactions\", {\n method: \"POST\",\n body,\n });\n\n if (data.error) {\n throw new BroadcastError(data.reason ?? data.error, {\n reason: data.reason,\n });\n }\n\n const txid =\n typeof data === \"string\"\n ? data.replace(/\"/g, \"\")\n : data.txid ?? getTransactionId(params.transaction);\n\n return { txid };\n}\n",
11
+ "import type { Account } from \"../../clients/types.ts\";\nimport type { ProviderAccount } from \"../../accounts/types.ts\";\n\nexport function isProviderAccount(account: Account): account is ProviderAccount {\n return account.type === \"provider\";\n}\n",
12
+ "import type { Client } from \"../../clients/types.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { buildContractCall } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { sendTransaction } from \"./sendTransaction.ts\";\nimport { getNonce } from \"../public/getNonce.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type CallContractParams = {\n contract: string; // \"address.name\"\n functionName: string;\n functionArgs?: ClarityValue[];\n fee?: IntegerType;\n nonce?: IntegerType;\n postConditionMode?: \"allow\" | \"deny\";\n postConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n client: Client,\n params: CallContractParams\n): Promise<string> {\n const account = client.account;\n if (!account) throw new Error(\"Account required\");\n\n // Provider: delegate to wallet\n if (isProviderAccount(account)) {\n const result = await account.provider.request(\"stx_callContract\", {\n contract: params.contract,\n functionName: params.functionName,\n functionArgs: params.functionArgs ?? [],\n });\n return result.txid;\n }\n\n // Local/Custom: build → sign → broadcast\n const [contractAddress, contractName] = parseContractId(params.contract);\n\n const nonce =\n params.nonce ?? await getNonce(client, { address: account.address });\n\n const unsigned = buildContractCall({\n contractAddress,\n contractName,\n functionName: params.functionName,\n functionArgs: params.functionArgs ?? [],\n fee: params.fee ?? 0n,\n nonce,\n publicKey: account.publicKey,\n chain: client.chain,\n postConditionMode: params.postConditionMode,\n postConditions: params.postConditions,\n });\n\n if (params.fee === undefined) {\n const estimates = await estimateFee(client, { transaction: unsigned });\n const mid = estimates[1] ?? estimates[0];\n if (mid) {\n (unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n }\n }\n\n const signed = await signTransactionWithAccount(unsigned, account);\n const result = await sendTransaction(client, { transaction: signed });\n return result.txid;\n}\n"
13
+ ],
14
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,eAAsB,QAAQ,CAC5B,QACA,QACiB;AAAA,EACjB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,WAAW;AAAA,IAClE,QAAQ;AAAA,EACV,CAAC;AAAA,EACD,OAAO,OAAO,KAAK,KAAK;AAAA;;;ACJ1B,eAAsB,YAAmD,CACvE,QACA,QACY;AAAA,EACZ,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,SAAS,OAAO,UAAU;AAAA,EAEhC,MAAM,kBAAkB,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,QAC9C,OAAO,WAAW,iBAAiB,GAAG,CAAC,CAAC,CAC1C;AAAA,EAEA,MAAM,OAAO,MAAM,OAAO,QACxB,2BAA2B,WAAW,QAAQ,OAAO,gBACrD;AAAA,IACE,QAAQ;AAAA,IACR,MAAM;AAAA,MACJ;AAAA,MACA,WAAW;AAAA,IACb;AAAA,EACF,CACF;AAAA,EAEA,IAAI,KAAK,MAAM;AAAA,IACb,OAAO,mBAAsB,KAAK,MAAM;AAAA,EAC1C;AAAA,EACA,MAAM,IAAI,MAAM,KAAK,SAAS,uBAAuB;AAAA;;;AC1BvD,eAAs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