@secondlayer/stacks 0.2.0 → 0.2.2

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 (98) hide show
  1. package/dist/shared/stacks-2ar4prfz.cjs +328 -0
  2. package/dist/shared/stacks-2ar4prfz.cjs.map +11 -0
  3. package/dist/shared/{stacks-ph4a6322.js → stacks-6m1z4j07.js} +26 -24
  4. package/dist/shared/stacks-6m1z4j07.js.map +10 -0
  5. package/dist/shared/{stacks-0hqzpm29.js → stacks-96gaxfcf.js} +9 -13
  6. package/dist/shared/{stacks-0hqzpm29.js.map → stacks-96gaxfcf.js.map} +2 -2
  7. package/dist/shared/stacks-dr5en54r.cjs +119 -0
  8. package/dist/shared/stacks-dr5en54r.cjs.map +10 -0
  9. package/dist/shared/{stacks-v3zy6zds.cjs → stacks-etf219gs.cjs} +11 -7
  10. package/dist/shared/stacks-etf219gs.cjs.map +10 -0
  11. package/dist/shared/stacks-je937aas.js +121 -0
  12. package/dist/shared/stacks-je937aas.js.map +10 -0
  13. package/dist/shared/stacks-jrnmh4kc.js +282 -0
  14. package/dist/shared/stacks-jrnmh4kc.js.map +11 -0
  15. package/dist/shared/{stacks-8qhfd37f.js → stacks-k9p8m3wf.js} +15 -19
  16. package/dist/shared/{stacks-8qhfd37f.js.map → stacks-k9p8m3wf.js.map} +2 -2
  17. package/dist/shared/{stacks-j2cy7qtt.js → stacks-ky14tdf6.cjs} +109 -24
  18. package/dist/shared/stacks-ky14tdf6.cjs.map +13 -0
  19. package/dist/shared/stacks-mrk6tkkh.cjs +41 -0
  20. package/dist/shared/{stacks-2gdt3aqj.cjs.map → stacks-mrk6tkkh.cjs.map} +1 -1
  21. package/dist/shared/{stacks-d1fmkv3p.js → stacks-p93g814f.js} +3 -3
  22. package/dist/shared/{stacks-zhd20wgz.js → stacks-q79dx28x.js} +3 -3
  23. package/dist/shared/{stacks-r1t6g3c3.cjs → stacks-ra02bpny.cjs} +8 -3
  24. package/dist/shared/{stacks-r1t6g3c3.cjs.map → stacks-ra02bpny.cjs.map} +3 -3
  25. package/dist/shared/{stacks-b008c3w8.cjs → stacks-rg1g0fja.js} +134 -2
  26. package/dist/shared/stacks-rg1g0fja.js.map +13 -0
  27. package/dist/shared/{stacks-bycy6t9k.js → stacks-rwfgts3s.js} +2 -2
  28. package/dist/shared/{stacks-gjvbq6w7.js → stacks-s10yb9gz.js} +2 -2
  29. package/dist/shared/{stacks-nqytwfcc.js → stacks-s7z5q8be.js} +8 -3
  30. package/dist/shared/{stacks-nqytwfcc.js.map → stacks-s7z5q8be.js.map} +3 -3
  31. package/dist/shared/{stacks-hfem9dck.cjs → stacks-v6ja2eh7.cjs} +342 -91
  32. package/dist/shared/stacks-v6ja2eh7.cjs.map +15 -0
  33. package/dist/shared/{stacks-xtz0n62y.js → stacks-xp9n3r0t.js} +357 -112
  34. package/dist/shared/stacks-xp9n3r0t.js.map +15 -0
  35. package/dist/src/accounts/index.js +3 -4
  36. package/dist/src/accounts/index.js.map +2 -2
  37. package/dist/src/actions/index.d.cts +7 -0
  38. package/dist/src/actions/index.d.ts +7 -0
  39. package/dist/src/actions/index.js +11 -14
  40. package/dist/src/actions/index.js.map +1 -1
  41. package/dist/src/bns/index.js +13 -16
  42. package/dist/src/bns/index.js.map +2 -2
  43. package/dist/src/chains/index.js +1 -2
  44. package/dist/src/chains/index.js.map +1 -1
  45. package/dist/src/clarity/index.cjs +1 -326
  46. package/dist/src/clarity/index.cjs.map +3 -5
  47. package/dist/src/clarity/index.js +19 -273
  48. package/dist/src/clarity/index.js.map +3 -5
  49. package/dist/src/connect/index.cjs +19 -9
  50. package/dist/src/connect/index.cjs.map +3 -3
  51. package/dist/src/connect/index.js.map +2 -2
  52. package/dist/src/connect/walletconnect/index.cjs +19 -9
  53. package/dist/src/connect/walletconnect/index.cjs.map +3 -3
  54. package/dist/src/connect/walletconnect/index.js.map +1 -1
  55. package/dist/src/index.cjs +1 -2
  56. package/dist/src/index.cjs.map +3 -3
  57. package/dist/src/index.d.cts +7 -0
  58. package/dist/src/index.d.ts +7 -0
  59. package/dist/src/index.js +12 -19
  60. package/dist/src/index.js.map +3 -3
  61. package/dist/src/postconditions/index.cjs +1 -117
  62. package/dist/src/postconditions/index.cjs.map +3 -4
  63. package/dist/src/postconditions/index.js +5 -119
  64. package/dist/src/postconditions/index.js.map +3 -4
  65. package/dist/src/pox/index.js +12 -15
  66. package/dist/src/pox/index.js.map +2 -2
  67. package/dist/src/stackingdao/index.js +11 -14
  68. package/dist/src/stackingdao/index.js.map +2 -2
  69. package/dist/src/subscriptions/index.js +1 -2
  70. package/dist/src/subscriptions/index.js.map +1 -1
  71. package/dist/src/transactions/index.d.cts +7 -0
  72. package/dist/src/transactions/index.d.ts +7 -0
  73. package/dist/src/transactions/index.js +18 -22
  74. package/dist/src/transactions/index.js.map +1 -1
  75. package/dist/src/utils/index.js +4 -5
  76. package/dist/src/utils/index.js.map +2 -2
  77. package/package.json +1 -1
  78. package/dist/shared/stacks-1aqm7c2h.cjs +0 -110
  79. package/dist/shared/stacks-1aqm7c2h.cjs.map +0 -11
  80. package/dist/shared/stacks-2gdt3aqj.cjs +0 -44
  81. package/dist/shared/stacks-8yykgdww.js +0 -125
  82. package/dist/shared/stacks-8yykgdww.js.map +0 -11
  83. package/dist/shared/stacks-b008c3w8.cjs.map +0 -11
  84. package/dist/shared/stacks-hfem9dck.cjs.map +0 -13
  85. package/dist/shared/stacks-j2cy7qtt.js.map +0 -11
  86. package/dist/shared/stacks-kgesjxq4.cjs +0 -247
  87. package/dist/shared/stacks-kgesjxq4.cjs.map +0 -11
  88. package/dist/shared/stacks-nbz193yk.js +0 -282
  89. package/dist/shared/stacks-nbz193yk.js.map +0 -11
  90. package/dist/shared/stacks-njvyj3ab.js +0 -23
  91. package/dist/shared/stacks-njvyj3ab.js.map +0 -9
  92. package/dist/shared/stacks-ph4a6322.js.map +0 -10
  93. package/dist/shared/stacks-v3zy6zds.cjs.map +0 -10
  94. package/dist/shared/stacks-xtz0n62y.js.map +0 -13
  95. /package/dist/shared/{stacks-d1fmkv3p.js.map → stacks-p93g814f.js.map} +0 -0
  96. /package/dist/shared/{stacks-zhd20wgz.js.map → stacks-q79dx28x.js.map} +0 -0
  97. /package/dist/shared/{stacks-bycy6t9k.js.map → stacks-rwfgts3s.js.map} +0 -0
  98. /package/dist/shared/{stacks-gjvbq6w7.js.map → stacks-s10yb9gz.js.map} +0 -0
@@ -1,11 +1,15 @@
1
1
  import {
2
+ Cl,
2
3
  serializeCVBytes
3
- } from "./stacks-8yykgdww.js";
4
+ } from "./stacks-rg1g0fja.js";
4
5
  import {
5
6
  hash160,
6
7
  hashP2PKH,
7
8
  txidFromBytes
8
- } from "./stacks-bycy6t9k.js";
9
+ } from "./stacks-rwfgts3s.js";
10
+ import {
11
+ parseContractId
12
+ } from "./stacks-s10yb9gz.js";
9
13
  import {
10
14
  asciiToBytes,
11
15
  bytesToHex,
@@ -13,29 +17,14 @@ import {
13
17
  c32addressDecode,
14
18
  concatBytes,
15
19
  hexToBytes,
20
+ intToBigInt,
16
21
  intToBytes,
17
22
  intToHex,
18
23
  utf8ToBytes,
19
24
  writeUInt16BE,
20
25
  writeUInt32BE,
21
26
  writeUInt8
22
- } from "./stacks-nqytwfcc.js";
23
- import"./stacks-njvyj3ab.js";
24
-
25
- // src/transactions/multisig.ts
26
- import {
27
- getPublicKey as nobleGetPublicKey2,
28
- sign as nobleSign
29
- } from "@noble/secp256k1";
30
-
31
- // src/transactions/authorization.ts
32
- import {
33
- getPublicKey as nobleGetPublicKey,
34
- sign,
35
- etc
36
- } from "@noble/secp256k1";
37
- import { hmac } from "@noble/hashes/hmac.js";
38
- import { sha256 } from "@noble/hashes/sha2.js";
27
+ } from "./stacks-s7z5q8be.js";
39
28
 
40
29
  // src/transactions/types.ts
41
30
  var AuthType = {
@@ -56,7 +45,9 @@ var PayloadType = {
56
45
  var ClarityVersion = {
57
46
  Clarity1: 1,
58
47
  Clarity2: 2,
59
- Clarity3: 3
48
+ Clarity3: 3,
49
+ Clarity4: 4,
50
+ Clarity5: 5
60
51
  };
61
52
  var AnchorMode = {
62
53
  OnChainOnly: 1,
@@ -114,86 +105,14 @@ var VRF_PROOF_BYTES_LENGTH = 80;
114
105
  var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
115
106
  var TenureChangeCause = {
116
107
  BlockFound: 0,
117
- Extended: 1
108
+ Extended: 1,
109
+ ExtendedRuntime: 2,
110
+ ExtendedReadCount: 3,
111
+ ExtendedReadLength: 4,
112
+ ExtendedWriteCount: 5,
113
+ ExtendedWriteLength: 6
118
114
  };
119
115
 
120
- // src/transactions/authorization.ts
121
- etc.hmacSha256Sync = (key, ...msgs) => {
122
- const h = hmac.create(sha256, key);
123
- msgs.forEach((msg) => h.update(msg));
124
- return h.digest();
125
- };
126
- var EMPTY_SIG = bytesToHex(new Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
127
- function createSingleSigSpendingCondition(publicKey, nonce, fee) {
128
- const pubKeyBytes = hexToBytes(publicKey);
129
- const signer = hashP2PKH(pubKeyBytes);
130
- const isCompressed = pubKeyBytes.length === 33;
131
- return {
132
- hashMode: AddressHashMode.P2PKH,
133
- signer,
134
- nonce,
135
- fee,
136
- keyEncoding: isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed,
137
- signature: EMPTY_SIG
138
- };
139
- }
140
- function createStandardAuth(spendingCondition) {
141
- return { authType: AuthType.Standard, spendingCondition };
142
- }
143
- function createSponsoredAuth(spendingCondition, sponsorSpendingCondition) {
144
- return {
145
- authType: AuthType.Sponsored,
146
- spendingCondition,
147
- sponsorSpendingCondition: sponsorSpendingCondition ?? createSingleSigSpendingCondition("0".repeat(66), 0n, 0n)
148
- };
149
- }
150
- function clearCondition(condition) {
151
- if ("signature" in condition) {
152
- return {
153
- ...condition,
154
- nonce: 0n,
155
- fee: 0n,
156
- signature: EMPTY_SIG
157
- };
158
- }
159
- return {
160
- ...condition,
161
- nonce: 0n,
162
- fee: 0n,
163
- fields: []
164
- };
165
- }
166
- function intoInitialSighashAuth(auth) {
167
- if (auth.authType === AuthType.Standard) {
168
- return createStandardAuth(clearCondition(auth.spendingCondition));
169
- }
170
- return createSponsoredAuth(clearCondition(auth.spendingCondition), clearCondition(createSingleSigSpendingCondition("0".repeat(66), 0n, 0n)));
171
- }
172
- function sigHashPreSign(curSigHash, authType, fee, nonce) {
173
- const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([authType]), intToBytes(fee, 8), intToBytes(nonce, 8));
174
- return txidFromBytes(data);
175
- }
176
- function sigHashPostSign(curSigHash, pubKeyEncoding, signature) {
177
- const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([pubKeyEncoding]), hexToBytes(signature));
178
- return txidFromBytes(data);
179
- }
180
- function signWithKey(privateKey, messageHash) {
181
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
182
- const sig = sign(messageHash, keyBytes, { lowS: true });
183
- const recoveryIdHex = intToHex(sig.recovery, 1);
184
- return recoveryIdHex + sig.toCompactHex();
185
- }
186
- function nextSignature(curSigHash, authType, fee, nonce, privateKey) {
187
- const sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);
188
- const keyBytes = hexToBytes(privateKey).slice(0, 32);
189
- const pubKey = nobleGetPublicKey(keyBytes, true);
190
- const isCompressed = pubKey.length === 33;
191
- const pubKeyEncoding = isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed;
192
- const nextSig = signWithKey(privateKey, sigHashPre);
193
- const nextSigHash = sigHashPostSign(sigHashPre, pubKeyEncoding, nextSig);
194
- return { nextSig, nextSigHash };
195
- }
196
-
197
116
  // src/transactions/wire/serialize.ts
198
117
  function serializeAddress(c32Address) {
199
118
  const [version, hash1602] = c32addressDecode(c32Address);
@@ -211,7 +130,7 @@ function serializeMemo(memo) {
211
130
  const content = asciiToBytes(memo);
212
131
  const padded = new Uint8Array(MEMO_MAX_LENGTH_BYTES);
213
132
  padded.set(content.slice(0, MEMO_MAX_LENGTH_BYTES));
214
- return concatBytes(writeUInt8(content.length), padded);
133
+ return padded;
215
134
  }
216
135
  function serializeSpendingCondition(condition) {
217
136
  const parts = [
@@ -265,21 +184,24 @@ function serializeAssetInfo(asset) {
265
184
  return concatBytes(serializeAddress(asset.address), serializeLPString(asset.contractName), serializeLPString(asset.assetName));
266
185
  }
267
186
  function serializePostCondition(pc) {
268
- const parts = [serializePrincipal(pc.principal)];
187
+ const parts = [];
269
188
  switch (pc.type) {
270
189
  case "stx":
271
190
  parts.push(writeUInt8(AssetType.STX));
191
+ parts.push(serializePrincipal(pc.principal));
272
192
  parts.push(writeUInt8(pc.conditionCode));
273
193
  parts.push(intToBytes(pc.amount, 8));
274
194
  break;
275
195
  case "ft":
276
196
  parts.push(writeUInt8(AssetType.Fungible));
197
+ parts.push(serializePrincipal(pc.principal));
277
198
  parts.push(serializeAssetInfo(pc.asset));
278
199
  parts.push(writeUInt8(pc.conditionCode));
279
200
  parts.push(intToBytes(pc.amount, 8));
280
201
  break;
281
202
  case "nft":
282
203
  parts.push(writeUInt8(AssetType.NonFungible));
204
+ parts.push(serializePrincipal(pc.principal));
283
205
  parts.push(serializeAssetInfo(pc.asset));
284
206
  parts.push(serializeCVBytes(pc.assetId));
285
207
  parts.push(writeUInt8(pc.conditionCode));
@@ -367,7 +289,95 @@ function serializeTransactionHex(tx) {
367
289
  return bytesToHex(serializeTransaction(tx));
368
290
  }
369
291
 
292
+ // src/transactions/authorization.ts
293
+ import {
294
+ getPublicKey as nobleGetPublicKey,
295
+ sign,
296
+ etc
297
+ } from "@noble/secp256k1";
298
+ import { hmac } from "@noble/hashes/hmac.js";
299
+ import { sha256 } from "@noble/hashes/sha2.js";
300
+ etc.hmacSha256Sync = (key, ...msgs) => {
301
+ const h = hmac.create(sha256, key);
302
+ msgs.forEach((msg) => h.update(msg));
303
+ return h.digest();
304
+ };
305
+ var EMPTY_SIG = bytesToHex(new Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
306
+ function createSingleSigSpendingCondition(publicKey, nonce, fee) {
307
+ const pubKeyBytes = hexToBytes(publicKey);
308
+ const signer = hashP2PKH(pubKeyBytes);
309
+ const isCompressed = pubKeyBytes.length === 33;
310
+ return {
311
+ hashMode: AddressHashMode.P2PKH,
312
+ signer,
313
+ nonce,
314
+ fee,
315
+ keyEncoding: isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed,
316
+ signature: EMPTY_SIG
317
+ };
318
+ }
319
+ function createStandardAuth(spendingCondition) {
320
+ return { authType: AuthType.Standard, spendingCondition };
321
+ }
322
+ function createSponsoredAuth(spendingCondition, sponsorSpendingCondition) {
323
+ return {
324
+ authType: AuthType.Sponsored,
325
+ spendingCondition,
326
+ sponsorSpendingCondition: sponsorSpendingCondition ?? createSingleSigSpendingCondition("0".repeat(66), 0n, 0n)
327
+ };
328
+ }
329
+ function clearCondition(condition) {
330
+ if ("signature" in condition) {
331
+ return {
332
+ ...condition,
333
+ nonce: 0n,
334
+ fee: 0n,
335
+ signature: EMPTY_SIG
336
+ };
337
+ }
338
+ return {
339
+ ...condition,
340
+ nonce: 0n,
341
+ fee: 0n,
342
+ fields: []
343
+ };
344
+ }
345
+ function intoInitialSighashAuth(auth) {
346
+ if (auth.authType === AuthType.Standard) {
347
+ return createStandardAuth(clearCondition(auth.spendingCondition));
348
+ }
349
+ return createSponsoredAuth(clearCondition(auth.spendingCondition), clearCondition(createSingleSigSpendingCondition("0".repeat(66), 0n, 0n)));
350
+ }
351
+ function sigHashPreSign(curSigHash, authType, fee, nonce) {
352
+ const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([authType]), intToBytes(fee, 8), intToBytes(nonce, 8));
353
+ return txidFromBytes(data);
354
+ }
355
+ function sigHashPostSign(curSigHash, pubKeyEncoding, signature) {
356
+ const data = concatBytes(hexToBytes(curSigHash), new Uint8Array([pubKeyEncoding]), hexToBytes(signature));
357
+ return txidFromBytes(data);
358
+ }
359
+ function signWithKey(privateKey, messageHash) {
360
+ const keyBytes = hexToBytes(privateKey).slice(0, 32);
361
+ const sig = sign(messageHash, keyBytes, { lowS: true });
362
+ const recoveryIdHex = intToHex(sig.recovery, 1);
363
+ return recoveryIdHex + sig.toCompactHex();
364
+ }
365
+ function nextSignature(curSigHash, authType, fee, nonce, privateKey) {
366
+ const sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);
367
+ const keyBytes = hexToBytes(privateKey).slice(0, 32);
368
+ const pubKey = nobleGetPublicKey(keyBytes, true);
369
+ const isCompressed = pubKey.length === 33;
370
+ const pubKeyEncoding = isCompressed ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed;
371
+ const nextSig = signWithKey(privateKey, sigHashPre);
372
+ const nextSigHash = sigHashPostSign(sigHashPre, pubKeyEncoding, nextSig);
373
+ return { nextSig, nextSigHash };
374
+ }
375
+
370
376
  // src/transactions/multisig.ts
377
+ import {
378
+ getPublicKey as nobleGetPublicKey2,
379
+ sign as nobleSign
380
+ } from "@noble/secp256k1";
371
381
  var OP_CHECKMULTISIG = 174;
372
382
  function isNonSequential(hashMode) {
373
383
  return (hashMode & 4) !== 0;
@@ -637,18 +647,253 @@ function combineMultiSigSignatures(baseTx, signedTxs) {
637
647
  auth: { ...baseTx.auth, spendingCondition: newCondition }
638
648
  };
639
649
  }
640
- export {
641
- signMultiSigWithAccount,
642
- signMultiSig,
643
- replayMultiSigSigHash,
644
- makeMultiSigAddress,
645
- isNonSequential,
646
- finalizeMultiSig,
647
- createMultiSigSpendingCondition,
648
- combineMultiSigSignatures
650
+
651
+ // src/transactions/signer.ts
652
+ function txid(tx) {
653
+ return txidFromBytes(serializeTransaction(tx));
654
+ }
655
+ function signBegin(tx) {
656
+ const cleared = {
657
+ ...tx,
658
+ auth: intoInitialSighashAuth(tx.auth)
659
+ };
660
+ return txid(cleared);
661
+ }
662
+ function signTransaction(tx, privateKey) {
663
+ const sigHash = signBegin(tx);
664
+ const condition = tx.auth.spendingCondition;
665
+ const { nextSig } = nextSignature(sigHash, AuthType.Standard, condition.fee, condition.nonce, privateKey);
666
+ return {
667
+ ...tx,
668
+ auth: {
669
+ ...tx.auth,
670
+ spendingCondition: {
671
+ ...condition,
672
+ signature: nextSig
673
+ }
674
+ }
675
+ };
676
+ }
677
+ async function signTransactionWithAccount(tx, account) {
678
+ const sigHash = signBegin(tx);
679
+ const condition = tx.auth.spendingCondition;
680
+ const sigHashPre = sigHashPreSign(sigHash, AuthType.Standard, condition.fee, condition.nonce);
681
+ const sigBytes = await account.sign(hexToBytes(sigHashPre));
682
+ const nextSig = bytesToHex(sigBytes);
683
+ return {
684
+ ...tx,
685
+ auth: {
686
+ ...tx.auth,
687
+ spendingCondition: {
688
+ ...condition,
689
+ signature: nextSig
690
+ }
691
+ }
692
+ };
693
+ }
694
+ function getTransactionId(tx) {
695
+ return txid(tx);
696
+ }
697
+ function getOriginSigHash(tx) {
698
+ const condition = tx.auth.spendingCondition;
699
+ if ("fields" in condition) {
700
+ return replayMultiSigSigHash(tx);
701
+ }
702
+ const initialSigHash2 = signBegin(tx);
703
+ const sc = condition;
704
+ const preSign = sigHashPreSign(initialSigHash2, AuthType.Standard, sc.fee, sc.nonce);
705
+ return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);
706
+ }
707
+ function signSponsor(tx, privateKey) {
708
+ if (tx.auth.authType !== AuthType.Sponsored) {
709
+ throw new Error("Transaction must be sponsored");
710
+ }
711
+ const auth = tx.auth;
712
+ const sponsorCondition = auth.sponsorSpendingCondition;
713
+ const originSigHash = getOriginSigHash(tx);
714
+ const { nextSig } = nextSignature(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce, privateKey);
715
+ return {
716
+ ...tx,
717
+ auth: {
718
+ ...auth,
719
+ sponsorSpendingCondition: {
720
+ ...sponsorCondition,
721
+ signature: nextSig
722
+ }
723
+ }
724
+ };
725
+ }
726
+ async function signSponsorWithAccount(tx, account) {
727
+ if (tx.auth.authType !== AuthType.Sponsored) {
728
+ throw new Error("Transaction must be sponsored");
729
+ }
730
+ const auth = tx.auth;
731
+ const sponsorCondition = auth.sponsorSpendingCondition;
732
+ const originSigHash = getOriginSigHash(tx);
733
+ const sigHashPre = sigHashPreSign(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce);
734
+ const sigBytes = await account.sign(hexToBytes(sigHashPre));
735
+ const nextSig = bytesToHex(sigBytes);
736
+ return {
737
+ ...tx,
738
+ auth: {
739
+ ...auth,
740
+ sponsorSpendingCondition: {
741
+ ...sponsorCondition,
742
+ signature: nextSig
743
+ }
744
+ }
745
+ };
746
+ }
747
+
748
+ // src/transactions/build.ts
749
+ function resolvePcMode(mode) {
750
+ return mode === "allow" ? PostConditionModeWire.Allow : PostConditionModeWire.Deny;
751
+ }
752
+ function convertPostConditions(pcs) {
753
+ if (!pcs || pcs.length === 0)
754
+ return [];
755
+ return pcs.map(convertPostCondition);
756
+ }
757
+ function resolvePrincipal(address) {
758
+ if (address === "origin")
759
+ return { type: "origin" };
760
+ const [addr, name] = address.split(".");
761
+ if (name) {
762
+ return { type: "contract", address: addr, contractName: name };
763
+ }
764
+ return { type: "standard", address: addr };
765
+ }
766
+ var FUNGIBLE_CODE_MAP = {
767
+ eq: FungibleConditionCode.Equal,
768
+ gt: FungibleConditionCode.Greater,
769
+ gte: FungibleConditionCode.GreaterEqual,
770
+ lt: FungibleConditionCode.Less,
771
+ lte: FungibleConditionCode.LessEqual
649
772
  };
773
+ function convertPostCondition(pc) {
774
+ switch (pc.type) {
775
+ case "stx-postcondition":
776
+ return {
777
+ type: "stx",
778
+ principal: resolvePrincipal(pc.address),
779
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
780
+ amount: intToBigInt(pc.amount)
781
+ };
782
+ case "ft-postcondition": {
783
+ const [contractId, tokenName] = pc.asset.split("::");
784
+ const [addr, name] = parseContractId(contractId);
785
+ return {
786
+ type: "ft",
787
+ principal: resolvePrincipal(pc.address),
788
+ asset: { address: addr, contractName: name, assetName: tokenName },
789
+ conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
790
+ amount: intToBigInt(pc.amount)
791
+ };
792
+ }
793
+ case "nft-postcondition": {
794
+ const [contractId, tokenName] = pc.asset.split("::");
795
+ const [addr, name] = parseContractId(contractId);
796
+ return {
797
+ type: "nft",
798
+ principal: resolvePrincipal(pc.address),
799
+ asset: { address: addr, contractName: name, assetName: tokenName },
800
+ conditionCode: pc.condition === "sent" ? NonFungibleConditionCode.Sends : NonFungibleConditionCode.DoesNotSend,
801
+ assetId: pc.assetId
802
+ };
803
+ }
804
+ }
805
+ }
806
+ function resolveSpendingCondition(opts, nonce, fee) {
807
+ if (opts.publicKeys) {
808
+ return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
809
+ }
810
+ return createSingleSigSpendingCondition(opts.publicKey, nonce, fee);
811
+ }
812
+ function resolveAuth(spendingCondition, sponsored) {
813
+ return sponsored ? createSponsoredAuth(spendingCondition) : createStandardAuth(spendingCondition);
814
+ }
815
+ function resolveVersionAndChainId(chain) {
816
+ if (!chain)
817
+ return { version: 0, chainId: 1 };
818
+ return { version: chain.transactionVersion, chainId: chain.id };
819
+ }
820
+ function buildTokenTransfer(options) {
821
+ const { version, chainId } = resolveVersionAndChainId(options.chain);
822
+ const fee = intToBigInt(options.fee);
823
+ const nonce = intToBigInt(options.nonce);
824
+ const spendingCondition = resolveSpendingCondition(options, nonce, fee);
825
+ const recipient = Cl.principal(options.recipient);
826
+ const tx = {
827
+ version,
828
+ chainId,
829
+ auth: resolveAuth(spendingCondition, options.sponsored),
830
+ anchorMode: AnchorMode.Any,
831
+ postConditionMode: resolvePcMode(options.postConditionMode),
832
+ postConditions: convertPostConditions(options.postConditions),
833
+ payload: {
834
+ payloadType: PayloadType.TokenTransfer,
835
+ recipient,
836
+ amount: intToBigInt(options.amount),
837
+ memo: options.memo ?? ""
838
+ }
839
+ };
840
+ if (options.publicKeys) {
841
+ tx._multisig = { publicKeys: options.publicKeys };
842
+ }
843
+ return tx;
844
+ }
845
+ function buildContractCall(options) {
846
+ const { version, chainId } = resolveVersionAndChainId(options.chain);
847
+ const fee = intToBigInt(options.fee);
848
+ const nonce = intToBigInt(options.nonce);
849
+ const spendingCondition = resolveSpendingCondition(options, nonce, fee);
850
+ const tx = {
851
+ version,
852
+ chainId,
853
+ auth: resolveAuth(spendingCondition, options.sponsored),
854
+ anchorMode: AnchorMode.Any,
855
+ postConditionMode: resolvePcMode(options.postConditionMode),
856
+ postConditions: convertPostConditions(options.postConditions),
857
+ payload: {
858
+ payloadType: PayloadType.ContractCall,
859
+ contractAddress: options.contractAddress,
860
+ contractName: options.contractName,
861
+ functionName: options.functionName,
862
+ functionArgs: options.functionArgs
863
+ }
864
+ };
865
+ if (options.publicKeys) {
866
+ tx._multisig = { publicKeys: options.publicKeys };
867
+ }
868
+ return tx;
869
+ }
870
+ function buildContractDeploy(options) {
871
+ const { version, chainId } = resolveVersionAndChainId(options.chain);
872
+ const fee = intToBigInt(options.fee);
873
+ const nonce = intToBigInt(options.nonce);
874
+ const spendingCondition = resolveSpendingCondition(options, nonce, fee);
875
+ const useVersioned = options.clarityVersion !== undefined;
876
+ const tx = {
877
+ version,
878
+ chainId,
879
+ auth: resolveAuth(spendingCondition, options.sponsored),
880
+ anchorMode: AnchorMode.Any,
881
+ postConditionMode: resolvePcMode(options.postConditionMode),
882
+ postConditions: convertPostConditions(options.postConditions),
883
+ payload: {
884
+ payloadType: useVersioned ? PayloadType.VersionedSmartContract : PayloadType.SmartContract,
885
+ clarityVersion: options.clarityVersion,
886
+ contractName: options.contractName,
887
+ codeBody: options.codeBody
888
+ }
889
+ };
890
+ if (options.publicKeys) {
891
+ tx._multisig = { publicKeys: options.publicKeys };
892
+ }
893
+ return tx;
894
+ }
650
895
 
651
- export { AuthType, PayloadType, ClarityVersion, AnchorMode, PostConditionModeWire, AddressHashMode, PubKeyEncoding, FungibleConditionCode, NonFungibleConditionCode, PostConditionPrincipalId, AssetType, AuthFieldType, RECOVERABLE_ECDSA_SIG_LENGTH_BYTES, MEMO_MAX_LENGTH_BYTES, MAX_STRING_LENGTH_BYTES, COINBASE_BYTES_LENGTH, VRF_PROOF_BYTES_LENGTH, MICROBLOCK_HEADER_BYTES_LENGTH, TenureChangeCause, serializePayload, serializeTransaction, serializeTransactionHex, createSingleSigSpendingCondition, createStandardAuth, createSponsoredAuth, intoInitialSighashAuth, sigHashPreSign, sigHashPostSign, nextSignature, isNonSequential, makeMultiSigAddress, createMultiSigSpendingCondition, replayMultiSigSigHash, signMultiSig, signMultiSigWithAccount, finalizeMultiSig, combineMultiSigSignatures };
896
+ export { AuthType, PayloadType, ClarityVersion, AnchorMode, PostConditionModeWire, AddressHashMode, PubKeyEncoding, FungibleConditionCode, NonFungibleConditionCode, PostConditionPrincipalId, AssetType, AuthFieldType, RECOVERABLE_ECDSA_SIG_LENGTH_BYTES, MEMO_MAX_LENGTH_BYTES, MAX_STRING_LENGTH_BYTES, COINBASE_BYTES_LENGTH, VRF_PROOF_BYTES_LENGTH, MICROBLOCK_HEADER_BYTES_LENGTH, TenureChangeCause, serializePayload, serializeTransaction, serializeTransactionHex, createSingleSigSpendingCondition, createStandardAuth, createSponsoredAuth, sigHashPreSign, sigHashPostSign, nextSignature, isNonSequential, makeMultiSigAddress, createMultiSigSpendingCondition, replayMultiSigSigHash, signMultiSig, signMultiSigWithAccount, finalizeMultiSig, combineMultiSigSignatures, signBegin, signTransaction, signTransactionWithAccount, getTransactionId, getOriginSigHash, signSponsor, signSponsorWithAccount, buildTokenTransfer, buildContractCall, buildContractDeploy };
652
897
 
653
- //# debugId=8A5B8348EC23E0AD64756E2164756E21
654
- //# sourceMappingURL=stacks-xtz0n62y.js.map
898
+ //# debugId=9CEDB9079783463964756E2164756E21
899
+ //# sourceMappingURL=stacks-xp9n3r0t.js.map