@secondlayer/stacks 6.0.0 → 6.1.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 (217) hide show
  1. package/dist/shared/stacks-esm-0pc6tmf0.js +50 -0
  2. package/dist/shared/{stacks-qex691bh.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
  3. package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-16d82wyc.js} +10 -10
  4. package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-16d82wyc.js.map} +2 -2
  5. package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-7a0ehykf.js} +43 -43
  6. package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
  7. package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-7v18h5dk.js} +4 -4
  8. package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-7v18h5dk.js.map} +2 -2
  9. package/dist/shared/{stacks-71k0vmct.js → stacks-esm-8f5catbf.js} +126 -126
  10. package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-8f5catbf.js.map} +2 -2
  11. package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-8jt6k8p3.js} +13 -13
  12. package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
  13. package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-a20wyky3.js} +92 -92
  14. package/dist/shared/{stacks-agk106zs.cjs.map → stacks-esm-a20wyky3.js.map} +2 -2
  15. package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-b54n1jdx.js} +102 -58
  16. package/dist/shared/stacks-esm-b54n1jdx.js.map +12 -0
  17. package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-cmtj5vky.js} +162 -162
  18. package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
  19. package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-e2qhfgke.js} +36 -36
  20. package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
  21. package/dist/shared/{stacks-v03zef3g.js → stacks-esm-ea4m4bk7.js} +117 -117
  22. package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
  23. package/dist/shared/{stacks-69nq48jp.js → stacks-esm-hkw1kvd4.js} +140 -140
  24. package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
  25. package/dist/shared/{stacks-qcae5852.js → stacks-esm-k108pemv.js} +4 -4
  26. package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-k108pemv.js.map} +2 -2
  27. package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
  28. package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
  29. package/dist/shared/{stacks-kg1npstf.js → stacks-esm-mt1thm7k.js} +9 -9
  30. package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
  31. package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-n1mekwnb.js} +9 -9
  32. package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-n1mekwnb.js.map} +2 -2
  33. package/dist/shared/{stacks-mftyrc60.js → stacks-esm-nt5hf8ht.js} +34 -34
  34. package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
  35. package/dist/shared/{stacks-51ybf135.js → stacks-esm-phgy8yqf.js} +210 -210
  36. package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
  37. package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-pxv6ny92.js} +116 -116
  38. package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
  39. package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-qfzxhdqz.js} +19 -19
  40. package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
  41. package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-snj9s2q8.js} +43 -43
  42. package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
  43. package/dist/shared/{stacks-yajyej2y.js → stacks-esm-ss9ap75h.js} +28 -28
  44. package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
  45. package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-t88hc019.js} +18 -18
  46. package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-t88hc019.js.map} +2 -2
  47. package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
  48. package/dist/shared/{stacks-enpj9krt.cjs.map → stacks-esm-tdrdye4y.js.map} +2 -2
  49. package/dist/src/accounts/index.cjs +565 -9
  50. package/dist/src/accounts/index.cjs.map +10 -4
  51. package/dist/src/accounts/index.d.cts +1 -1
  52. package/dist/src/accounts/index.d.ts +1 -1
  53. package/dist/src/accounts/index.js +26 -26
  54. package/dist/src/accounts/index.js.map +2 -2
  55. package/dist/src/actions/index.cjs +3860 -44
  56. package/dist/src/actions/index.cjs.map +65 -3
  57. package/dist/src/actions/index.d.cts +1 -1
  58. package/dist/src/actions/index.d.ts +1 -1
  59. package/dist/src/actions/index.js +102 -103
  60. package/dist/src/actions/index.js.map +1 -1
  61. package/dist/src/bitcoin/index.cjs +2506 -31
  62. package/dist/src/bitcoin/index.cjs.map +31 -3
  63. package/dist/src/bitcoin/index.d.cts +92 -92
  64. package/dist/src/bitcoin/index.d.ts +92 -92
  65. package/dist/src/bitcoin/index.js +88 -90
  66. package/dist/src/bitcoin/index.js.map +2 -2
  67. package/dist/src/bns/index.cjs +4435 -10
  68. package/dist/src/bns/index.cjs.map +50 -3
  69. package/dist/src/bns/index.d.cts +1 -1
  70. package/dist/src/bns/index.d.ts +1 -1
  71. package/dist/src/bns/index.js +39 -41
  72. package/dist/src/bns/index.js.map +2 -2
  73. package/dist/src/chains/index.cjs +141 -5
  74. package/dist/src/chains/index.cjs.map +5 -3
  75. package/dist/src/chains/index.d.cts +1 -1
  76. package/dist/src/chains/index.d.ts +1 -1
  77. package/dist/src/chains/index.js +12 -12
  78. package/dist/src/chains/index.js.map +1 -1
  79. package/dist/src/clarity/index.cjs +2021 -1
  80. package/dist/src/clarity/index.cjs.map +24 -3
  81. package/dist/src/clarity/index.d.cts +1 -1
  82. package/dist/src/clarity/index.d.ts +1 -1
  83. package/dist/src/clarity/index.js +170 -171
  84. package/dist/src/clarity/index.js.map +1 -1
  85. package/dist/src/connect/index.cjs +19 -19
  86. package/dist/src/connect/index.cjs.map +2 -2
  87. package/dist/src/connect/index.d.cts +1 -1
  88. package/dist/src/connect/index.d.ts +1 -1
  89. package/dist/src/connect/index.js +19 -19
  90. package/dist/src/connect/index.js.map +2 -2
  91. package/dist/src/connect/walletconnect/index.cjs +6 -46
  92. package/dist/src/connect/walletconnect/index.cjs.map +3 -4
  93. package/dist/src/connect/walletconnect/index.d.cts +1 -1
  94. package/dist/src/connect/walletconnect/index.d.ts +1 -1
  95. package/dist/src/connect/walletconnect/index.js +6 -46
  96. package/dist/src/connect/walletconnect/index.js.map +3 -4
  97. package/dist/src/filters/index.cjs +727 -1
  98. package/dist/src/filters/index.cjs.map +11 -3
  99. package/dist/src/filters/index.d.cts +76 -13
  100. package/dist/src/filters/index.d.ts +76 -13
  101. package/dist/src/filters/index.js +30 -26
  102. package/dist/src/filters/index.js.map +1 -1
  103. package/dist/src/index.cjs +4000 -126
  104. package/dist/src/index.cjs.map +69 -4
  105. package/dist/src/index.d.cts +658 -607
  106. package/dist/src/index.d.ts +658 -607
  107. package/dist/src/index.js +219 -219
  108. package/dist/src/index.js.map +2 -2
  109. package/dist/src/postconditions/index.cjs +1728 -1
  110. package/dist/src/postconditions/index.cjs.map +20 -3
  111. package/dist/src/postconditions/index.d.cts +1 -1
  112. package/dist/src/postconditions/index.d.ts +1 -1
  113. package/dist/src/postconditions/index.js +16 -17
  114. package/dist/src/postconditions/index.js.map +1 -1
  115. package/dist/src/pox/index.cjs +3866 -11
  116. package/dist/src/pox/index.cjs.map +48 -3
  117. package/dist/src/pox/index.d.cts +1 -1
  118. package/dist/src/pox/index.d.ts +1 -1
  119. package/dist/src/pox/index.js +40 -41
  120. package/dist/src/pox/index.js.map +2 -2
  121. package/dist/src/pox5/index.cjs +4124 -95
  122. package/dist/src/pox5/index.cjs.map +55 -4
  123. package/dist/src/pox5/index.d.cts +9 -1
  124. package/dist/src/pox5/index.d.ts +9 -1
  125. package/dist/src/pox5/index.js +210 -209
  126. package/dist/src/pox5/index.js.map +3 -3
  127. package/dist/src/sbtc/index.cjs +3719 -16
  128. package/dist/src/sbtc/index.cjs.map +47 -3
  129. package/dist/src/sbtc/index.d.cts +1 -1
  130. package/dist/src/sbtc/index.d.ts +1 -1
  131. package/dist/src/sbtc/index.js +39 -40
  132. package/dist/src/sbtc/index.js.map +2 -2
  133. package/dist/src/simnet/index.cjs +16 -16
  134. package/dist/src/simnet/index.cjs.map +2 -2
  135. package/dist/src/simnet/index.d.cts +1 -1
  136. package/dist/src/simnet/index.d.ts +1 -1
  137. package/dist/src/simnet/index.js +16 -16
  138. package/dist/src/simnet/index.js.map +2 -2
  139. package/dist/src/stackingdao/index.cjs +3747 -3
  140. package/dist/src/stackingdao/index.cjs.map +45 -3
  141. package/dist/src/stackingdao/index.d.cts +1 -1
  142. package/dist/src/stackingdao/index.d.ts +1 -1
  143. package/dist/src/stackingdao/index.js +26 -27
  144. package/dist/src/stackingdao/index.js.map +2 -2
  145. package/dist/src/subscriptions/index.cjs +160 -6
  146. package/dist/src/subscriptions/index.cjs.map +6 -3
  147. package/dist/src/subscriptions/index.d.cts +1 -1
  148. package/dist/src/subscriptions/index.d.ts +1 -1
  149. package/dist/src/subscriptions/index.js +14 -15
  150. package/dist/src/subscriptions/index.js.map +1 -1
  151. package/dist/src/transactions/index.cjs +2189 -49
  152. package/dist/src/transactions/index.cjs.map +23 -3
  153. package/dist/src/transactions/index.d.cts +1 -1
  154. package/dist/src/transactions/index.d.ts +1 -1
  155. package/dist/src/transactions/index.js +104 -105
  156. package/dist/src/transactions/index.js.map +1 -1
  157. package/dist/src/utils/index.cjs +503 -69
  158. package/dist/src/utils/index.cjs.map +9 -3
  159. package/dist/src/utils/index.d.cts +1 -1
  160. package/dist/src/utils/index.d.ts +1 -1
  161. package/dist/src/utils/index.js +131 -131
  162. package/dist/src/utils/index.js.map +2 -2
  163. package/package.json +1 -1
  164. package/dist/shared/stacks-02actsrx.cjs +0 -17
  165. package/dist/shared/stacks-02actsrx.cjs.map +0 -10
  166. package/dist/shared/stacks-03vfm21t.cjs +0 -222
  167. package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
  168. package/dist/shared/stacks-24h5k94q.cjs +0 -74
  169. package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
  170. package/dist/shared/stacks-37kz5t9f.cjs +0 -764
  171. package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
  172. package/dist/shared/stacks-3mt2q2na.cjs +0 -65
  173. package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
  174. package/dist/shared/stacks-4d7c3x27.js +0 -84
  175. package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
  176. package/dist/shared/stacks-8vzxax5e.cjs +0 -45
  177. package/dist/shared/stacks-agk106zs.cjs +0 -267
  178. package/dist/shared/stacks-bdgh9n83.cjs +0 -212
  179. package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
  180. package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
  181. package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
  182. package/dist/shared/stacks-ee53k9j2.cjs +0 -651
  183. package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
  184. package/dist/shared/stacks-enpj9krt.cjs +0 -38
  185. package/dist/shared/stacks-f35mnrmg.cjs +0 -164
  186. package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
  187. package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
  188. package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
  189. package/dist/shared/stacks-gjz26k6b.js.map +0 -12
  190. package/dist/shared/stacks-gza2n1zs.cjs +0 -73
  191. package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
  192. package/dist/shared/stacks-kem68d80.cjs +0 -156
  193. package/dist/shared/stacks-kem68d80.cjs.map +0 -10
  194. package/dist/shared/stacks-n98w7g57.cjs +0 -234
  195. package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
  196. package/dist/shared/stacks-p337hp6m.cjs +0 -336
  197. package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
  198. package/dist/shared/stacks-q34k4vnc.cjs +0 -286
  199. package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
  200. package/dist/shared/stacks-qex691bh.js +0 -50
  201. package/dist/shared/stacks-rryme9bv.cjs +0 -569
  202. package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
  203. package/dist/shared/stacks-s5vej5z6.cjs +0 -410
  204. package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
  205. package/dist/shared/stacks-sdqkapct.cjs +0 -67
  206. package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
  207. package/dist/shared/stacks-v2rfr46a.js +0 -48
  208. package/dist/shared/stacks-v2rfr46a.js.map +0 -10
  209. package/dist/shared/stacks-vea7nde7.cjs +0 -731
  210. package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
  211. package/dist/shared/stacks-wk8yp13j.cjs +0 -33
  212. package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
  213. package/dist/shared/stacks-x0qqwrev.js.map +0 -12
  214. package/dist/shared/stacks-xjkn3en1.cjs +0 -42
  215. package/dist/shared/stacks-xnrywjf1.cjs +0 -131
  216. package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
  217. package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
@@ -1,569 +0,0 @@
1
- // src/transactions/authorization.ts
2
- var import_hmac = require("@noble/hashes/hmac.js");
3
- var import_sha2 = require("@noble/hashes/sha2.js");
4
- var import_secp256k1 = require("@noble/secp256k1");
5
- import_secp256k1.etc.hmacSha256Sync = (key, ...msgs) => {
6
- const h = import_hmac.hmac.create(import_sha2.sha256, key);
7
- for (const msg of msgs)
8
- h.update(msg);
9
- return h.digest();
10
- };
11
- var EMPTY_SIG = bytesToHex(new Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
12
- function createSingleSigSpendingCondition(publicKey, nonce, fee) {
13
- const pubKeyBytes = hexToBytes(publicKey);
14
- const signer = hashP2PKH(pubKeyBytes);
15
- const isCompressed = pubKeyBytes.length === 33;
16
- return {
17
- hashMode: AddressHashMode.P2PKH,
18
- signer,
19
- nonce,
20
- fee,
21
- keyEncoding: isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed,
22
- signature: EMPTY_SIG
23
- };
24
- }
25
- function createStandardAuth(spendingCondition) {
26
- return { authType: AuthType.Standard, spendingCondition };
27
- }
28
- function createSponsoredAuth(spendingCondition, sponsorSpendingCondition) {
29
- return {
30
- authType: AuthType.Sponsored,
31
- spendingCondition,
32
- sponsorSpendingCondition: sponsorSpendingCondition ?? createSingleSigSpendingCondition("0".repeat(66), 0n, 0n)
33
- };
34
- }
35
- function clearCondition(condition) {
36
- if ("signature" in condition) {
37
- return {
38
- ...condition,
39
- nonce: 0n,
40
- fee: 0n,
41
- signature: EMPTY_SIG
42
- };
43
- }
44
- return {
45
- ...condition,
46
- nonce: 0n,
47
- fee: 0n,
48
- fields: []
49
- };
50
- }
51
- function sponsorSigningSentinel() {
52
- return {
53
- hashMode: AddressHashMode.P2PKH,
54
- signer: "00".repeat(20),
55
- nonce: 0n,
56
- fee: 0n,
57
- keyEncoding: PubKeyEncoding.Compressed,
58
- signature: EMPTY_SIG
59
- };
60
- }
61
- function intoInitialSighashAuth(auth) {
62
- if (auth.authType === AuthType.Standard) {
63
- return createStandardAuth(clearCondition(auth.spendingCondition));
64
- }
65
- return createSponsoredAuth(clearCondition(auth.spendingCondition), sponsorSigningSentinel());
66
- }
67
- function sigHashPreSign(curSigHash, authType, fee, nonce) {
68
- const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([authType]), intToBytes(fee, 8), intToBytes(nonce, 8));
69
- return txidFromBytes(data);
70
- }
71
- function sigHashPostSign(curSigHash, pubKeyEncoding, signature) {
72
- const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([pubKeyEncoding]), hexToBytes(signature));
73
- return txidFromBytes(data);
74
- }
75
- function signWithKey(privateKey, messageHash) {
76
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
77
- const sig = import_secp256k1.sign(messageHash, keyBytes, { lowS: true });
78
- const recoveryIdHex = intToHex(sig.recovery, 1);
79
- return recoveryIdHex + sig.toCompactHex();
80
- }
81
- function nextSignature(curSigHash, authType, fee, nonce, privateKey) {
82
- const sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);
83
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
84
- const pubKey = import_secp256k1.getPublicKey(keyBytes, true);
85
- const isCompressed = pubKey.length === 33;
86
- const pubKeyEncoding = isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed;
87
- const nextSig = signWithKey(privateKey, sigHashPre);
88
- const nextSigHash = sigHashPostSign(sigHashPre, pubKeyEncoding, nextSig);
89
- return { nextSig, nextSigHash };
90
- }
91
-
92
- // src/transactions/multisig.ts
93
- var import_secp256k12 = require("@noble/secp256k1");
94
- var OP_CHECKMULTISIG = 174;
95
- function isNonSequential(hashMode) {
96
- return (hashMode & 4) !== 0;
97
- }
98
- function makeRedeemScript(publicKeys, signaturesRequired) {
99
- const parts = [];
100
- parts.push(new Uint8Array([80 + signaturesRequired]));
101
- for (const pk of publicKeys) {
102
- const pkBytes = hexToBytes(pk);
103
- parts.push(new Uint8Array([pkBytes.length]));
104
- parts.push(pkBytes);
105
- }
106
- parts.push(new Uint8Array([80 + publicKeys.length]));
107
- parts.push(new Uint8Array([OP_CHECKMULTISIG]));
108
- return concatBytes(...parts);
109
- }
110
- function makeMultiSigAddress(publicKeys, signaturesRequired, chain) {
111
- if (signaturesRequired < 1 || signaturesRequired > publicKeys.length) {
112
- throw new Error(`signaturesRequired must be between 1 and ${publicKeys.length}`);
113
- }
114
- const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
115
- const signer = hash160(redeemScript);
116
- const version = chain?.addressVersion?.multiSig ?? 20;
117
- return c32address(version, bytesToHex(signer));
118
- }
119
- function createMultiSigSpendingCondition(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode.P2SH) {
120
- const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
121
- const signer = bytesToHex(hash160(redeemScript));
122
- return {
123
- hashMode,
124
- signer,
125
- nonce,
126
- fee,
127
- fields: [],
128
- signaturesRequired
129
- };
130
- }
131
- function initialSigHash(tx) {
132
- const cleared = {
133
- ...tx,
134
- auth: intoInitialSighashAuth(tx.auth)
135
- };
136
- return txidFromBytes(serializeTransaction(cleared));
137
- }
138
- function nonSequentialPreSignHash(tx) {
139
- const condition = tx.auth.spendingCondition;
140
- const initHash = initialSigHash(tx);
141
- return sigHashPreSign(initHash, AuthType.Standard, condition.fee, condition.nonce);
142
- }
143
- function replayMultiSigSigHash(tx) {
144
- const condition = tx.auth.spendingCondition;
145
- if (isNonSequential(condition.hashMode)) {
146
- const preSign = nonSequentialPreSignHash(tx);
147
- let curSigHash2 = preSign;
148
- for (const field of condition.fields) {
149
- curSigHash2 = sigHashPostSign(curSigHash2, field.pubKeyEncoding, field.data);
150
- }
151
- return curSigHash2;
152
- }
153
- let curSigHash = initialSigHash(tx);
154
- for (const field of condition.fields) {
155
- const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
156
- curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);
157
- }
158
- return curSigHash;
159
- }
160
- function signMultiSig(tx, privateKey, publicKeys) {
161
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
162
- const signerPubKey = bytesToHex(import_secp256k12.getPublicKey(keyBytes, true));
163
- const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);
164
- if (signerIndex === -1) {
165
- throw new Error("Private key does not correspond to any signer in the multi-sig");
166
- }
167
- const condition = {
168
- ...tx.auth.spendingCondition
169
- };
170
- if (isNonSequential(condition.hashMode)) {
171
- return signNonSequential(tx, condition, privateKey);
172
- }
173
- return signSequential(tx, condition, privateKey, publicKeys, signerIndex);
174
- }
175
- function signNonSequential(tx, condition, privateKey) {
176
- const fields = [...condition.fields];
177
- const preSignHash = nonSequentialPreSignHash(tx);
178
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
179
- const sig = import_secp256k12.sign(preSignHash, keyBytes, { lowS: true });
180
- const recoveryIdHex = intToHex(sig.recovery, 1);
181
- const nextSig = recoveryIdHex + sig.toCompactHex();
182
- fields.push({
183
- type: "signature",
184
- pubKeyEncoding: PubKeyEncoding.Compressed,
185
- data: nextSig
186
- });
187
- const newCondition = { ...condition, fields };
188
- const sigCount = fields.filter((f) => f.type === "signature").length;
189
- if (sigCount >= condition.signaturesRequired) {
190
- return {
191
- ...tx,
192
- auth: { ...tx.auth, spendingCondition: newCondition }
193
- };
194
- }
195
- return {
196
- ...tx,
197
- auth: { ...tx.auth, spendingCondition: newCondition }
198
- };
199
- }
200
- function signSequential(tx, condition, privateKey, publicKeys, signerIndex) {
201
- const fields = [...condition.fields];
202
- let curSigHash = initialSigHash(tx);
203
- for (const field of fields) {
204
- const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
205
- curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);
206
- }
207
- for (let i = fields.length;i < signerIndex; i++) {
208
- const pubKeyField = {
209
- type: "publicKey",
210
- pubKeyEncoding: PubKeyEncoding.Compressed,
211
- data: publicKeys[i]
212
- };
213
- fields.push(pubKeyField);
214
- const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
215
- curSigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
216
- }
217
- const { nextSig, nextSigHash } = nextSignature(curSigHash, AuthType.Standard, condition.fee, condition.nonce, privateKey);
218
- fields.push({
219
- type: "signature",
220
- pubKeyEncoding: PubKeyEncoding.Compressed,
221
- data: nextSig
222
- });
223
- curSigHash = nextSigHash;
224
- const newCondition = { ...condition, fields };
225
- const sigCount = fields.filter((f) => f.type === "signature").length;
226
- let finalCondition = newCondition;
227
- if (sigCount >= condition.signaturesRequired) {
228
- finalCondition = finalizeMultiSigCondition(newCondition, publicKeys, curSigHash);
229
- }
230
- return {
231
- ...tx,
232
- auth: {
233
- ...tx.auth,
234
- spendingCondition: finalCondition
235
- }
236
- };
237
- }
238
- async function signMultiSigWithAccount(tx, account, publicKeys) {
239
- const signerPubKey = account.publicKey;
240
- const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);
241
- if (signerIndex === -1) {
242
- throw new Error("Account does not correspond to any signer in the multi-sig");
243
- }
244
- const condition = {
245
- ...tx.auth.spendingCondition
246
- };
247
- if (isNonSequential(condition.hashMode)) {
248
- return signNonSequentialWithAccount(tx, condition, account);
249
- }
250
- return signSequentialWithAccount(tx, condition, account, publicKeys, signerIndex);
251
- }
252
- async function signNonSequentialWithAccount(tx, condition, account) {
253
- const fields = [...condition.fields];
254
- const preSignHash = nonSequentialPreSignHash(tx);
255
- const sigBytes = await account.sign(hexToBytes(preSignHash));
256
- const nextSig = bytesToHex(sigBytes);
257
- fields.push({
258
- type: "signature",
259
- pubKeyEncoding: PubKeyEncoding.Compressed,
260
- data: nextSig
261
- });
262
- const newCondition = { ...condition, fields };
263
- return {
264
- ...tx,
265
- auth: { ...tx.auth, spendingCondition: newCondition }
266
- };
267
- }
268
- async function signSequentialWithAccount(tx, condition, account, publicKeys, signerIndex) {
269
- const fields = [...condition.fields];
270
- let curSigHash = initialSigHash(tx);
271
- for (const field of fields) {
272
- const preSign2 = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
273
- curSigHash = sigHashPostSign(preSign2, field.pubKeyEncoding, field.data);
274
- }
275
- for (let i = fields.length;i < signerIndex; i++) {
276
- const pubKeyField = {
277
- type: "publicKey",
278
- pubKeyEncoding: PubKeyEncoding.Compressed,
279
- data: publicKeys[i]
280
- };
281
- fields.push(pubKeyField);
282
- const preSign2 = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
283
- curSigHash = sigHashPostSign(preSign2, pubKeyField.pubKeyEncoding, pubKeyField.data);
284
- }
285
- const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
286
- const sigBytes = await account.sign(hexToBytes(preSign));
287
- const nextSig = bytesToHex(sigBytes);
288
- const nextSigHash = sigHashPostSign(preSign, PubKeyEncoding.Compressed, nextSig);
289
- fields.push({
290
- type: "signature",
291
- pubKeyEncoding: PubKeyEncoding.Compressed,
292
- data: nextSig
293
- });
294
- curSigHash = nextSigHash;
295
- const newCondition = { ...condition, fields };
296
- const sigCount = fields.filter((f) => f.type === "signature").length;
297
- let finalCondition = newCondition;
298
- if (sigCount >= condition.signaturesRequired) {
299
- finalCondition = finalizeMultiSigCondition(newCondition, publicKeys, curSigHash);
300
- }
301
- return {
302
- ...tx,
303
- auth: {
304
- ...tx.auth,
305
- spendingCondition: finalCondition
306
- }
307
- };
308
- }
309
- function finalizeMultiSig(tx, publicKeys) {
310
- const condition = tx.auth.spendingCondition;
311
- if (isNonSequential(condition.hashMode)) {
312
- return tx;
313
- }
314
- const curSigHash = replayMultiSigSigHash(tx);
315
- const finalCondition = finalizeMultiSigCondition(condition, publicKeys, curSigHash);
316
- return {
317
- ...tx,
318
- auth: {
319
- ...tx.auth,
320
- spendingCondition: finalCondition
321
- }
322
- };
323
- }
324
- function finalizeMultiSigCondition(condition, publicKeys, curSigHash) {
325
- const fields = [...condition.fields];
326
- let sigHash = curSigHash;
327
- for (let i = fields.length;i < publicKeys.length; i++) {
328
- const pubKeyField = {
329
- type: "publicKey",
330
- pubKeyEncoding: PubKeyEncoding.Compressed,
331
- data: publicKeys[i]
332
- };
333
- fields.push(pubKeyField);
334
- const preSign = sigHashPreSign(sigHash, AuthType.Standard, condition.fee, condition.nonce);
335
- sigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
336
- }
337
- return { ...condition, fields };
338
- }
339
- function combineMultiSigSignatures(baseTx, signedTxs) {
340
- const condition = baseTx.auth.spendingCondition;
341
- if (!isNonSequential(condition.hashMode)) {
342
- throw new Error("combineMultiSigSignatures only works with non-sequential hash modes (SIP-027)");
343
- }
344
- const seenSigs = new Set;
345
- const signatures = [];
346
- for (const stx of signedTxs) {
347
- const stxCondition = stx.auth.spendingCondition;
348
- for (const field of stxCondition.fields) {
349
- if (field.type === "signature" && !seenSigs.has(field.data)) {
350
- seenSigs.add(field.data);
351
- signatures.push(field);
352
- }
353
- }
354
- }
355
- if (signatures.length === 0) {
356
- throw new Error("No signatures found in the provided transactions");
357
- }
358
- const newCondition = {
359
- ...condition,
360
- fields: signatures
361
- };
362
- return {
363
- ...baseTx,
364
- auth: { ...baseTx.auth, spendingCondition: newCondition }
365
- };
366
- }
367
-
368
- // src/transactions/build.ts
369
- function resolvePcMode(mode) {
370
- if (mode === "allow")
371
- return PostConditionModeWire.Allow;
372
- if (mode === "originator")
373
- return PostConditionModeWire.Originator;
374
- return PostConditionModeWire.Deny;
375
- }
376
- function convertPostConditions(pcs) {
377
- if (!pcs || pcs.length === 0)
378
- return [];
379
- return pcs.map((pc) => convertPostCondition(typeof pc === "string" ? fromHex(pc) : pc));
380
- }
381
- function resolveSpendingCondition(opts, nonce, fee) {
382
- if (opts.publicKeys) {
383
- return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
384
- }
385
- return createSingleSigSpendingCondition(opts.publicKey, nonce, fee);
386
- }
387
- function resolveAuth(spendingCondition, sponsored) {
388
- return sponsored ? createSponsoredAuth(spendingCondition) : createStandardAuth(spendingCondition);
389
- }
390
- function resolveVersionAndChainId(chain) {
391
- if (!chain)
392
- return { version: 0, chainId: 1 };
393
- return { version: chain.transactionVersion, chainId: chain.id };
394
- }
395
- function buildTokenTransfer(options) {
396
- const { version, chainId } = resolveVersionAndChainId(options.chain);
397
- const fee = intToBigInt(options.fee);
398
- const nonce = intToBigInt(options.nonce);
399
- const spendingCondition = resolveSpendingCondition(options, nonce, fee);
400
- const recipient = Cl.principal(options.recipient);
401
- const tx = {
402
- version,
403
- chainId,
404
- auth: resolveAuth(spendingCondition, options.sponsored),
405
- anchorMode: AnchorMode.Any,
406
- postConditionMode: resolvePcMode(options.postConditionMode),
407
- postConditions: convertPostConditions(options.postConditions),
408
- payload: {
409
- payloadType: PayloadType.TokenTransfer,
410
- recipient,
411
- amount: intToBigInt(options.amount),
412
- memo: options.memo ?? ""
413
- }
414
- };
415
- if (options.publicKeys) {
416
- tx._multisig = { publicKeys: options.publicKeys };
417
- }
418
- return tx;
419
- }
420
- function buildContractCall(options) {
421
- const { version, chainId } = resolveVersionAndChainId(options.chain);
422
- const fee = intToBigInt(options.fee);
423
- const nonce = intToBigInt(options.nonce);
424
- const spendingCondition = resolveSpendingCondition(options, nonce, fee);
425
- const tx = {
426
- version,
427
- chainId,
428
- auth: resolveAuth(spendingCondition, options.sponsored),
429
- anchorMode: AnchorMode.Any,
430
- postConditionMode: resolvePcMode(options.postConditionMode),
431
- postConditions: convertPostConditions(options.postConditions),
432
- payload: {
433
- payloadType: PayloadType.ContractCall,
434
- contractAddress: options.contractAddress,
435
- contractName: options.contractName,
436
- functionName: options.functionName,
437
- functionArgs: options.functionArgs
438
- }
439
- };
440
- if (options.publicKeys) {
441
- tx._multisig = { publicKeys: options.publicKeys };
442
- }
443
- return tx;
444
- }
445
- function buildContractDeploy(options) {
446
- const { version, chainId } = resolveVersionAndChainId(options.chain);
447
- const fee = intToBigInt(options.fee);
448
- const nonce = intToBigInt(options.nonce);
449
- const spendingCondition = resolveSpendingCondition(options, nonce, fee);
450
- const clarityVersion = options.clarityVersion ?? ClarityVersion.Clarity4;
451
- const tx = {
452
- version,
453
- chainId,
454
- auth: resolveAuth(spendingCondition, options.sponsored),
455
- anchorMode: AnchorMode.Any,
456
- postConditionMode: resolvePcMode(options.postConditionMode),
457
- postConditions: convertPostConditions(options.postConditions),
458
- payload: {
459
- payloadType: PayloadType.VersionedSmartContract,
460
- clarityVersion,
461
- contractName: options.contractName,
462
- codeBody: options.codeBody
463
- }
464
- };
465
- if (options.publicKeys) {
466
- tx._multisig = { publicKeys: options.publicKeys };
467
- }
468
- return tx;
469
- }
470
-
471
- // src/transactions/signer.ts
472
- function txid(tx) {
473
- return txidFromBytes(serializeTransaction(tx));
474
- }
475
- function signBegin(tx) {
476
- const cleared = {
477
- ...tx,
478
- auth: intoInitialSighashAuth(tx.auth)
479
- };
480
- return txid(cleared);
481
- }
482
- function signTransaction(tx, privateKey) {
483
- const sigHash = signBegin(tx);
484
- const condition = tx.auth.spendingCondition;
485
- const { nextSig } = nextSignature(sigHash, AuthType.Standard, condition.fee, condition.nonce, privateKey);
486
- return {
487
- ...tx,
488
- auth: {
489
- ...tx.auth,
490
- spendingCondition: {
491
- ...condition,
492
- signature: nextSig
493
- }
494
- }
495
- };
496
- }
497
- async function signTransactionWithAccount(tx, account) {
498
- const sigHash = signBegin(tx);
499
- const condition = tx.auth.spendingCondition;
500
- const sigHashPre = sigHashPreSign(sigHash, AuthType.Standard, condition.fee, condition.nonce);
501
- const sigBytes = await account.sign(hexToBytes(sigHashPre));
502
- const nextSig = bytesToHex(sigBytes);
503
- return {
504
- ...tx,
505
- auth: {
506
- ...tx.auth,
507
- spendingCondition: {
508
- ...condition,
509
- signature: nextSig
510
- }
511
- }
512
- };
513
- }
514
- function getTransactionId(tx) {
515
- return txid(tx);
516
- }
517
- function getOriginSigHash(tx) {
518
- const condition = tx.auth.spendingCondition;
519
- if ("fields" in condition) {
520
- return replayMultiSigSigHash(tx);
521
- }
522
- const initialSigHash2 = signBegin(tx);
523
- const sc = condition;
524
- const preSign = sigHashPreSign(initialSigHash2, AuthType.Standard, sc.fee, sc.nonce);
525
- return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);
526
- }
527
- function signSponsor(tx, privateKey) {
528
- if (tx.auth.authType !== AuthType.Sponsored) {
529
- throw new Error("Transaction must be sponsored");
530
- }
531
- const auth = tx.auth;
532
- const sponsorCondition = auth.sponsorSpendingCondition;
533
- const originSigHash = getOriginSigHash(tx);
534
- const { nextSig } = nextSignature(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce, privateKey);
535
- return {
536
- ...tx,
537
- auth: {
538
- ...auth,
539
- sponsorSpendingCondition: {
540
- ...sponsorCondition,
541
- signature: nextSig
542
- }
543
- }
544
- };
545
- }
546
- async function signSponsorWithAccount(tx, account) {
547
- if (tx.auth.authType !== AuthType.Sponsored) {
548
- throw new Error("Transaction must be sponsored");
549
- }
550
- const auth = tx.auth;
551
- const sponsorCondition = auth.sponsorSpendingCondition;
552
- const originSigHash = getOriginSigHash(tx);
553
- const sigHashPre = sigHashPreSign(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce);
554
- const sigBytes = await account.sign(hexToBytes(sigHashPre));
555
- const nextSig = bytesToHex(sigBytes);
556
- return {
557
- ...tx,
558
- auth: {
559
- ...auth,
560
- sponsorSpendingCondition: {
561
- ...sponsorCondition,
562
- signature: nextSig
563
- }
564
- }
565
- };
566
- }
567
-
568
- //# debugId=4803818E842AF84364756E2164756E21
569
- //# sourceMappingURL=stacks-rryme9bv.cjs.map