@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.
- package/dist/shared/stacks-esm-0pc6tmf0.js +50 -0
- package/dist/shared/{stacks-qex691bh.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
- package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-16d82wyc.js} +10 -10
- package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-16d82wyc.js.map} +2 -2
- package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-7a0ehykf.js} +43 -43
- package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
- package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-7v18h5dk.js} +4 -4
- package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-7v18h5dk.js.map} +2 -2
- package/dist/shared/{stacks-71k0vmct.js → stacks-esm-8f5catbf.js} +126 -126
- package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-8f5catbf.js.map} +2 -2
- package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-8jt6k8p3.js} +13 -13
- package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
- package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-a20wyky3.js} +92 -92
- package/dist/shared/{stacks-agk106zs.cjs.map → stacks-esm-a20wyky3.js.map} +2 -2
- package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-b54n1jdx.js} +102 -58
- package/dist/shared/stacks-esm-b54n1jdx.js.map +12 -0
- package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-cmtj5vky.js} +162 -162
- package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
- package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-e2qhfgke.js} +36 -36
- package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
- package/dist/shared/{stacks-v03zef3g.js → stacks-esm-ea4m4bk7.js} +117 -117
- package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
- package/dist/shared/{stacks-69nq48jp.js → stacks-esm-hkw1kvd4.js} +140 -140
- package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
- package/dist/shared/{stacks-qcae5852.js → stacks-esm-k108pemv.js} +4 -4
- package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-k108pemv.js.map} +2 -2
- package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
- package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
- package/dist/shared/{stacks-kg1npstf.js → stacks-esm-mt1thm7k.js} +9 -9
- package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
- package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-n1mekwnb.js} +9 -9
- package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-n1mekwnb.js.map} +2 -2
- package/dist/shared/{stacks-mftyrc60.js → stacks-esm-nt5hf8ht.js} +34 -34
- package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
- package/dist/shared/{stacks-51ybf135.js → stacks-esm-phgy8yqf.js} +210 -210
- package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
- package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-pxv6ny92.js} +116 -116
- package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
- package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-qfzxhdqz.js} +19 -19
- package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
- package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-snj9s2q8.js} +43 -43
- package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
- package/dist/shared/{stacks-yajyej2y.js → stacks-esm-ss9ap75h.js} +28 -28
- package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
- package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-t88hc019.js} +18 -18
- package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-t88hc019.js.map} +2 -2
- package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
- package/dist/shared/{stacks-enpj9krt.cjs.map → stacks-esm-tdrdye4y.js.map} +2 -2
- package/dist/src/accounts/index.cjs +565 -9
- package/dist/src/accounts/index.cjs.map +10 -4
- package/dist/src/accounts/index.d.cts +1 -1
- package/dist/src/accounts/index.d.ts +1 -1
- package/dist/src/accounts/index.js +26 -26
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +3860 -44
- package/dist/src/actions/index.cjs.map +65 -3
- package/dist/src/actions/index.d.cts +1 -1
- package/dist/src/actions/index.d.ts +1 -1
- package/dist/src/actions/index.js +102 -103
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +2506 -31
- package/dist/src/bitcoin/index.cjs.map +31 -3
- package/dist/src/bitcoin/index.d.cts +92 -92
- package/dist/src/bitcoin/index.d.ts +92 -92
- package/dist/src/bitcoin/index.js +88 -90
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.cjs +4435 -10
- package/dist/src/bns/index.cjs.map +50 -3
- package/dist/src/bns/index.d.cts +1 -1
- package/dist/src/bns/index.d.ts +1 -1
- package/dist/src/bns/index.js +39 -41
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/chains/index.cjs +141 -5
- package/dist/src/chains/index.cjs.map +5 -3
- package/dist/src/chains/index.d.cts +1 -1
- package/dist/src/chains/index.d.ts +1 -1
- package/dist/src/chains/index.js +12 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/clarity/index.cjs +2021 -1
- package/dist/src/clarity/index.cjs.map +24 -3
- package/dist/src/clarity/index.d.cts +1 -1
- package/dist/src/clarity/index.d.ts +1 -1
- package/dist/src/clarity/index.js +170 -171
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/connect/index.cjs +19 -19
- package/dist/src/connect/index.cjs.map +2 -2
- package/dist/src/connect/index.d.cts +1 -1
- package/dist/src/connect/index.d.ts +1 -1
- package/dist/src/connect/index.js +19 -19
- package/dist/src/connect/index.js.map +2 -2
- package/dist/src/connect/walletconnect/index.cjs +6 -46
- package/dist/src/connect/walletconnect/index.cjs.map +3 -4
- package/dist/src/connect/walletconnect/index.d.cts +1 -1
- package/dist/src/connect/walletconnect/index.d.ts +1 -1
- package/dist/src/connect/walletconnect/index.js +6 -46
- package/dist/src/connect/walletconnect/index.js.map +3 -4
- package/dist/src/filters/index.cjs +727 -1
- package/dist/src/filters/index.cjs.map +11 -3
- package/dist/src/filters/index.d.cts +76 -13
- package/dist/src/filters/index.d.ts +76 -13
- package/dist/src/filters/index.js +30 -26
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/index.cjs +4000 -126
- package/dist/src/index.cjs.map +69 -4
- package/dist/src/index.d.cts +658 -607
- package/dist/src/index.d.ts +658 -607
- package/dist/src/index.js +219 -219
- package/dist/src/index.js.map +2 -2
- package/dist/src/postconditions/index.cjs +1728 -1
- package/dist/src/postconditions/index.cjs.map +20 -3
- package/dist/src/postconditions/index.d.cts +1 -1
- package/dist/src/postconditions/index.d.ts +1 -1
- package/dist/src/postconditions/index.js +16 -17
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.cjs +3866 -11
- package/dist/src/pox/index.cjs.map +48 -3
- package/dist/src/pox/index.d.cts +1 -1
- package/dist/src/pox/index.d.ts +1 -1
- package/dist/src/pox/index.js +40 -41
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +4124 -95
- package/dist/src/pox5/index.cjs.map +55 -4
- package/dist/src/pox5/index.d.cts +9 -1
- package/dist/src/pox5/index.d.ts +9 -1
- package/dist/src/pox5/index.js +210 -209
- package/dist/src/pox5/index.js.map +3 -3
- package/dist/src/sbtc/index.cjs +3719 -16
- package/dist/src/sbtc/index.cjs.map +47 -3
- package/dist/src/sbtc/index.d.cts +1 -1
- package/dist/src/sbtc/index.d.ts +1 -1
- package/dist/src/sbtc/index.js +39 -40
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/simnet/index.cjs +16 -16
- package/dist/src/simnet/index.cjs.map +2 -2
- package/dist/src/simnet/index.d.cts +1 -1
- package/dist/src/simnet/index.d.ts +1 -1
- package/dist/src/simnet/index.js +16 -16
- package/dist/src/simnet/index.js.map +2 -2
- package/dist/src/stackingdao/index.cjs +3747 -3
- package/dist/src/stackingdao/index.cjs.map +45 -3
- package/dist/src/stackingdao/index.d.cts +1 -1
- package/dist/src/stackingdao/index.d.ts +1 -1
- package/dist/src/stackingdao/index.js +26 -27
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/subscriptions/index.cjs +160 -6
- package/dist/src/subscriptions/index.cjs.map +6 -3
- package/dist/src/subscriptions/index.d.cts +1 -1
- package/dist/src/subscriptions/index.d.ts +1 -1
- package/dist/src/subscriptions/index.js +14 -15
- package/dist/src/subscriptions/index.js.map +1 -1
- package/dist/src/transactions/index.cjs +2189 -49
- package/dist/src/transactions/index.cjs.map +23 -3
- package/dist/src/transactions/index.d.cts +1 -1
- package/dist/src/transactions/index.d.ts +1 -1
- package/dist/src/transactions/index.js +104 -105
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.cjs +503 -69
- package/dist/src/utils/index.cjs.map +9 -3
- package/dist/src/utils/index.d.cts +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +131 -131
- package/dist/src/utils/index.js.map +2 -2
- package/package.json +1 -1
- package/dist/shared/stacks-02actsrx.cjs +0 -17
- package/dist/shared/stacks-02actsrx.cjs.map +0 -10
- package/dist/shared/stacks-03vfm21t.cjs +0 -222
- package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
- package/dist/shared/stacks-24h5k94q.cjs +0 -74
- package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
- package/dist/shared/stacks-37kz5t9f.cjs +0 -764
- package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
- package/dist/shared/stacks-3mt2q2na.cjs +0 -65
- package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
- package/dist/shared/stacks-4d7c3x27.js +0 -84
- package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
- package/dist/shared/stacks-8vzxax5e.cjs +0 -45
- package/dist/shared/stacks-agk106zs.cjs +0 -267
- package/dist/shared/stacks-bdgh9n83.cjs +0 -212
- package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
- package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
- package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
- package/dist/shared/stacks-ee53k9j2.cjs +0 -651
- package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
- package/dist/shared/stacks-enpj9krt.cjs +0 -38
- package/dist/shared/stacks-f35mnrmg.cjs +0 -164
- package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
- package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
- package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
- package/dist/shared/stacks-gjz26k6b.js.map +0 -12
- package/dist/shared/stacks-gza2n1zs.cjs +0 -73
- package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
- package/dist/shared/stacks-kem68d80.cjs +0 -156
- package/dist/shared/stacks-kem68d80.cjs.map +0 -10
- package/dist/shared/stacks-n98w7g57.cjs +0 -234
- package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
- package/dist/shared/stacks-p337hp6m.cjs +0 -336
- package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
- package/dist/shared/stacks-q34k4vnc.cjs +0 -286
- package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
- package/dist/shared/stacks-qex691bh.js +0 -50
- package/dist/shared/stacks-rryme9bv.cjs +0 -569
- package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
- package/dist/shared/stacks-s5vej5z6.cjs +0 -410
- package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
- package/dist/shared/stacks-sdqkapct.cjs +0 -67
- package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
- package/dist/shared/stacks-v2rfr46a.js +0 -48
- package/dist/shared/stacks-v2rfr46a.js.map +0 -10
- package/dist/shared/stacks-vea7nde7.cjs +0 -731
- package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
- package/dist/shared/stacks-wk8yp13j.cjs +0 -33
- package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
- package/dist/shared/stacks-x0qqwrev.js.map +0 -12
- package/dist/shared/stacks-xjkn3en1.cjs +0 -42
- package/dist/shared/stacks-xnrywjf1.cjs +0 -131
- package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
- package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "./stacks-51ybf135.js";
|
|
2
|
+
bytesToHex2,
|
|
3
|
+
hexToBytes2,
|
|
4
|
+
concatBytes2,
|
|
5
|
+
intToBigInt2,
|
|
6
|
+
intToBytes2,
|
|
7
|
+
intToHex2,
|
|
8
|
+
c32address2,
|
|
9
|
+
hash1602,
|
|
10
|
+
txidFromBytes2,
|
|
11
|
+
hashP2PKH2
|
|
12
|
+
} from "./stacks-esm-7a0ehykf.js";
|
|
14
13
|
import {
|
|
15
|
-
|
|
16
|
-
} from "./stacks-
|
|
14
|
+
Cl2
|
|
15
|
+
} from "./stacks-esm-hkw1kvd4.js";
|
|
17
16
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
AuthType2,
|
|
18
|
+
PayloadType2,
|
|
19
|
+
ClarityVersion2,
|
|
20
|
+
AnchorMode2,
|
|
21
|
+
PostConditionModeWire2,
|
|
22
|
+
AddressHashMode2,
|
|
23
|
+
PubKeyEncoding2,
|
|
24
|
+
RECOVERABLE_ECDSA_SIG_LENGTH_BYTES2,
|
|
25
|
+
serializeTransaction2,
|
|
26
|
+
convertPostCondition,
|
|
27
|
+
fromHex2
|
|
28
|
+
} from "./stacks-esm-phgy8yqf.js";
|
|
29
29
|
|
|
30
30
|
// src/transactions/authorization.ts
|
|
31
31
|
import { hmac } from "@noble/hashes/hmac.js";
|
|
@@ -37,28 +37,28 @@ etc.hmacSha256Sync = (key, ...msgs) => {
|
|
|
37
37
|
h.update(msg);
|
|
38
38
|
return h.digest();
|
|
39
39
|
};
|
|
40
|
-
var EMPTY_SIG =
|
|
41
|
-
function
|
|
42
|
-
const pubKeyBytes =
|
|
43
|
-
const signer =
|
|
40
|
+
var EMPTY_SIG = bytesToHex2(new Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES2));
|
|
41
|
+
function createSingleSigSpendingCondition2(publicKey, nonce, fee) {
|
|
42
|
+
const pubKeyBytes = hexToBytes2(publicKey);
|
|
43
|
+
const signer = hashP2PKH2(pubKeyBytes);
|
|
44
44
|
const isCompressed = pubKeyBytes.length === 33;
|
|
45
45
|
return {
|
|
46
|
-
hashMode:
|
|
46
|
+
hashMode: AddressHashMode2.P2PKH,
|
|
47
47
|
signer,
|
|
48
48
|
nonce,
|
|
49
49
|
fee,
|
|
50
|
-
keyEncoding: isCompressed ?
|
|
50
|
+
keyEncoding: isCompressed ? PubKeyEncoding2.Compressed : PubKeyEncoding2.Uncompressed,
|
|
51
51
|
signature: EMPTY_SIG
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
return { authType:
|
|
54
|
+
function createStandardAuth2(spendingCondition) {
|
|
55
|
+
return { authType: AuthType2.Standard, spendingCondition };
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function createSponsoredAuth2(spendingCondition, sponsorSpendingCondition) {
|
|
58
58
|
return {
|
|
59
|
-
authType:
|
|
59
|
+
authType: AuthType2.Sponsored,
|
|
60
60
|
spendingCondition,
|
|
61
|
-
sponsorSpendingCondition: sponsorSpendingCondition ??
|
|
61
|
+
sponsorSpendingCondition: sponsorSpendingCondition ?? createSingleSigSpendingCondition2("0".repeat(66), 0n, 0n)
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
function clearCondition(condition) {
|
|
@@ -79,42 +79,42 @@ function clearCondition(condition) {
|
|
|
79
79
|
}
|
|
80
80
|
function sponsorSigningSentinel() {
|
|
81
81
|
return {
|
|
82
|
-
hashMode:
|
|
82
|
+
hashMode: AddressHashMode2.P2PKH,
|
|
83
83
|
signer: "00".repeat(20),
|
|
84
84
|
nonce: 0n,
|
|
85
85
|
fee: 0n,
|
|
86
|
-
keyEncoding:
|
|
86
|
+
keyEncoding: PubKeyEncoding2.Compressed,
|
|
87
87
|
signature: EMPTY_SIG
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
function intoInitialSighashAuth(auth) {
|
|
91
|
-
if (auth.authType ===
|
|
92
|
-
return
|
|
91
|
+
if (auth.authType === AuthType2.Standard) {
|
|
92
|
+
return createStandardAuth2(clearCondition(auth.spendingCondition));
|
|
93
93
|
}
|
|
94
|
-
return
|
|
94
|
+
return createSponsoredAuth2(clearCondition(auth.spendingCondition), sponsorSigningSentinel());
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
const data =
|
|
98
|
-
return
|
|
96
|
+
function sigHashPreSign2(curSigHash, authType, fee, nonce) {
|
|
97
|
+
const data = concatBytes2(hexToBytes2(curSigHash), new Uint8Array([authType]), intToBytes2(fee, 8), intToBytes2(nonce, 8));
|
|
98
|
+
return txidFromBytes2(data);
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
const data =
|
|
102
|
-
return
|
|
100
|
+
function sigHashPostSign2(curSigHash, pubKeyEncoding, signature) {
|
|
101
|
+
const data = concatBytes2(hexToBytes2(curSigHash), new Uint8Array([pubKeyEncoding]), hexToBytes2(signature));
|
|
102
|
+
return txidFromBytes2(data);
|
|
103
103
|
}
|
|
104
104
|
function signWithKey(privateKey, messageHash) {
|
|
105
|
-
const keyBytes =
|
|
105
|
+
const keyBytes = hexToBytes2(privateKey).slice(0, 32);
|
|
106
106
|
const sig = sign(messageHash, keyBytes, { lowS: true });
|
|
107
|
-
const recoveryIdHex =
|
|
107
|
+
const recoveryIdHex = intToHex2(sig.recovery, 1);
|
|
108
108
|
return recoveryIdHex + sig.toCompactHex();
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
const sigHashPre =
|
|
112
|
-
const keyBytes =
|
|
110
|
+
function nextSignature2(curSigHash, authType, fee, nonce, privateKey) {
|
|
111
|
+
const sigHashPre = sigHashPreSign2(curSigHash, authType, fee, nonce);
|
|
112
|
+
const keyBytes = hexToBytes2(privateKey).slice(0, 32);
|
|
113
113
|
const pubKey = nobleGetPublicKey(keyBytes, true);
|
|
114
114
|
const isCompressed = pubKey.length === 33;
|
|
115
|
-
const pubKeyEncoding = isCompressed ?
|
|
115
|
+
const pubKeyEncoding = isCompressed ? PubKeyEncoding2.Compressed : PubKeyEncoding2.Uncompressed;
|
|
116
116
|
const nextSig = signWithKey(privateKey, sigHashPre);
|
|
117
|
-
const nextSigHash =
|
|
117
|
+
const nextSigHash = sigHashPostSign2(sigHashPre, pubKeyEncoding, nextSig);
|
|
118
118
|
return { nextSig, nextSigHash };
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -124,33 +124,33 @@ import {
|
|
|
124
124
|
sign as nobleSign
|
|
125
125
|
} from "@noble/secp256k1";
|
|
126
126
|
var OP_CHECKMULTISIG = 174;
|
|
127
|
-
function
|
|
127
|
+
function isNonSequential2(hashMode) {
|
|
128
128
|
return (hashMode & 4) !== 0;
|
|
129
129
|
}
|
|
130
130
|
function makeRedeemScript(publicKeys, signaturesRequired) {
|
|
131
131
|
const parts = [];
|
|
132
132
|
parts.push(new Uint8Array([80 + signaturesRequired]));
|
|
133
133
|
for (const pk of publicKeys) {
|
|
134
|
-
const pkBytes =
|
|
134
|
+
const pkBytes = hexToBytes2(pk);
|
|
135
135
|
parts.push(new Uint8Array([pkBytes.length]));
|
|
136
136
|
parts.push(pkBytes);
|
|
137
137
|
}
|
|
138
138
|
parts.push(new Uint8Array([80 + publicKeys.length]));
|
|
139
139
|
parts.push(new Uint8Array([OP_CHECKMULTISIG]));
|
|
140
|
-
return
|
|
140
|
+
return concatBytes2(...parts);
|
|
141
141
|
}
|
|
142
|
-
function
|
|
142
|
+
function makeMultiSigAddress2(publicKeys, signaturesRequired, chain) {
|
|
143
143
|
if (signaturesRequired < 1 || signaturesRequired > publicKeys.length) {
|
|
144
144
|
throw new Error(`signaturesRequired must be between 1 and ${publicKeys.length}`);
|
|
145
145
|
}
|
|
146
146
|
const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
|
|
147
|
-
const signer =
|
|
147
|
+
const signer = hash1602(redeemScript);
|
|
148
148
|
const version = chain?.addressVersion?.multiSig ?? 20;
|
|
149
|
-
return
|
|
149
|
+
return c32address2(version, bytesToHex2(signer));
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function createMultiSigSpendingCondition2(publicKeys, signaturesRequired, nonce, fee, hashMode = AddressHashMode2.P2SH) {
|
|
152
152
|
const redeemScript = makeRedeemScript(publicKeys, signaturesRequired);
|
|
153
|
-
const signer =
|
|
153
|
+
const signer = bytesToHex2(hash1602(redeemScript));
|
|
154
154
|
return {
|
|
155
155
|
hashMode,
|
|
156
156
|
signer,
|
|
@@ -165,33 +165,33 @@ function initialSigHash(tx) {
|
|
|
165
165
|
...tx,
|
|
166
166
|
auth: intoInitialSighashAuth(tx.auth)
|
|
167
167
|
};
|
|
168
|
-
return
|
|
168
|
+
return txidFromBytes2(serializeTransaction2(cleared));
|
|
169
169
|
}
|
|
170
170
|
function nonSequentialPreSignHash(tx) {
|
|
171
171
|
const condition = tx.auth.spendingCondition;
|
|
172
172
|
const initHash = initialSigHash(tx);
|
|
173
|
-
return
|
|
173
|
+
return sigHashPreSign2(initHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function replayMultiSigSigHash2(tx) {
|
|
176
176
|
const condition = tx.auth.spendingCondition;
|
|
177
|
-
if (
|
|
177
|
+
if (isNonSequential2(condition.hashMode)) {
|
|
178
178
|
const preSign = nonSequentialPreSignHash(tx);
|
|
179
|
-
let
|
|
179
|
+
let curSigHash = preSign;
|
|
180
180
|
for (const field of condition.fields) {
|
|
181
|
-
|
|
181
|
+
curSigHash = sigHashPostSign2(curSigHash, field.pubKeyEncoding, field.data);
|
|
182
182
|
}
|
|
183
|
-
return
|
|
183
|
+
return curSigHash;
|
|
184
184
|
}
|
|
185
185
|
let curSigHash = initialSigHash(tx);
|
|
186
186
|
for (const field of condition.fields) {
|
|
187
|
-
const preSign =
|
|
188
|
-
curSigHash =
|
|
187
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
188
|
+
curSigHash = sigHashPostSign2(preSign, field.pubKeyEncoding, field.data);
|
|
189
189
|
}
|
|
190
190
|
return curSigHash;
|
|
191
191
|
}
|
|
192
|
-
function
|
|
193
|
-
const keyBytes =
|
|
194
|
-
const signerPubKey =
|
|
192
|
+
function signMultiSig2(tx, privateKey, publicKeys) {
|
|
193
|
+
const keyBytes = hexToBytes2(privateKey).slice(0, 32);
|
|
194
|
+
const signerPubKey = bytesToHex2(nobleGetPublicKey2(keyBytes, true));
|
|
195
195
|
const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);
|
|
196
196
|
if (signerIndex === -1) {
|
|
197
197
|
throw new Error("Private key does not correspond to any signer in the multi-sig");
|
|
@@ -199,7 +199,7 @@ function signMultiSig(tx, privateKey, publicKeys) {
|
|
|
199
199
|
const condition = {
|
|
200
200
|
...tx.auth.spendingCondition
|
|
201
201
|
};
|
|
202
|
-
if (
|
|
202
|
+
if (isNonSequential2(condition.hashMode)) {
|
|
203
203
|
return signNonSequential(tx, condition, privateKey);
|
|
204
204
|
}
|
|
205
205
|
return signSequential(tx, condition, privateKey, publicKeys, signerIndex);
|
|
@@ -207,13 +207,13 @@ function signMultiSig(tx, privateKey, publicKeys) {
|
|
|
207
207
|
function signNonSequential(tx, condition, privateKey) {
|
|
208
208
|
const fields = [...condition.fields];
|
|
209
209
|
const preSignHash = nonSequentialPreSignHash(tx);
|
|
210
|
-
const keyBytes =
|
|
210
|
+
const keyBytes = hexToBytes2(privateKey).slice(0, 32);
|
|
211
211
|
const sig = nobleSign(preSignHash, keyBytes, { lowS: true });
|
|
212
|
-
const recoveryIdHex =
|
|
212
|
+
const recoveryIdHex = intToHex2(sig.recovery, 1);
|
|
213
213
|
const nextSig = recoveryIdHex + sig.toCompactHex();
|
|
214
214
|
fields.push({
|
|
215
215
|
type: "signature",
|
|
216
|
-
pubKeyEncoding:
|
|
216
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
217
217
|
data: nextSig
|
|
218
218
|
});
|
|
219
219
|
const newCondition = { ...condition, fields };
|
|
@@ -233,23 +233,23 @@ function signSequential(tx, condition, privateKey, publicKeys, signerIndex) {
|
|
|
233
233
|
const fields = [...condition.fields];
|
|
234
234
|
let curSigHash = initialSigHash(tx);
|
|
235
235
|
for (const field of fields) {
|
|
236
|
-
const preSign =
|
|
237
|
-
curSigHash =
|
|
236
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
237
|
+
curSigHash = sigHashPostSign2(preSign, field.pubKeyEncoding, field.data);
|
|
238
238
|
}
|
|
239
239
|
for (let i = fields.length;i < signerIndex; i++) {
|
|
240
240
|
const pubKeyField = {
|
|
241
241
|
type: "publicKey",
|
|
242
|
-
pubKeyEncoding:
|
|
242
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
243
243
|
data: publicKeys[i]
|
|
244
244
|
};
|
|
245
245
|
fields.push(pubKeyField);
|
|
246
|
-
const preSign =
|
|
247
|
-
curSigHash =
|
|
246
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
247
|
+
curSigHash = sigHashPostSign2(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
|
|
248
248
|
}
|
|
249
|
-
const { nextSig, nextSigHash } =
|
|
249
|
+
const { nextSig, nextSigHash } = nextSignature2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce, privateKey);
|
|
250
250
|
fields.push({
|
|
251
251
|
type: "signature",
|
|
252
|
-
pubKeyEncoding:
|
|
252
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
253
253
|
data: nextSig
|
|
254
254
|
});
|
|
255
255
|
curSigHash = nextSigHash;
|
|
@@ -267,7 +267,7 @@ function signSequential(tx, condition, privateKey, publicKeys, signerIndex) {
|
|
|
267
267
|
}
|
|
268
268
|
};
|
|
269
269
|
}
|
|
270
|
-
async function
|
|
270
|
+
async function signMultiSigWithAccount2(tx, account, publicKeys) {
|
|
271
271
|
const signerPubKey = account.publicKey;
|
|
272
272
|
const signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);
|
|
273
273
|
if (signerIndex === -1) {
|
|
@@ -276,7 +276,7 @@ async function signMultiSigWithAccount(tx, account, publicKeys) {
|
|
|
276
276
|
const condition = {
|
|
277
277
|
...tx.auth.spendingCondition
|
|
278
278
|
};
|
|
279
|
-
if (
|
|
279
|
+
if (isNonSequential2(condition.hashMode)) {
|
|
280
280
|
return signNonSequentialWithAccount(tx, condition, account);
|
|
281
281
|
}
|
|
282
282
|
return signSequentialWithAccount(tx, condition, account, publicKeys, signerIndex);
|
|
@@ -284,11 +284,11 @@ async function signMultiSigWithAccount(tx, account, publicKeys) {
|
|
|
284
284
|
async function signNonSequentialWithAccount(tx, condition, account) {
|
|
285
285
|
const fields = [...condition.fields];
|
|
286
286
|
const preSignHash = nonSequentialPreSignHash(tx);
|
|
287
|
-
const sigBytes = await account.sign(
|
|
288
|
-
const nextSig =
|
|
287
|
+
const sigBytes = await account.sign(hexToBytes2(preSignHash));
|
|
288
|
+
const nextSig = bytesToHex2(sigBytes);
|
|
289
289
|
fields.push({
|
|
290
290
|
type: "signature",
|
|
291
|
-
pubKeyEncoding:
|
|
291
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
292
292
|
data: nextSig
|
|
293
293
|
});
|
|
294
294
|
const newCondition = { ...condition, fields };
|
|
@@ -301,26 +301,26 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
|
|
|
301
301
|
const fields = [...condition.fields];
|
|
302
302
|
let curSigHash = initialSigHash(tx);
|
|
303
303
|
for (const field of fields) {
|
|
304
|
-
const
|
|
305
|
-
curSigHash =
|
|
304
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
305
|
+
curSigHash = sigHashPostSign2(preSign, field.pubKeyEncoding, field.data);
|
|
306
306
|
}
|
|
307
307
|
for (let i = fields.length;i < signerIndex; i++) {
|
|
308
308
|
const pubKeyField = {
|
|
309
309
|
type: "publicKey",
|
|
310
|
-
pubKeyEncoding:
|
|
310
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
311
311
|
data: publicKeys[i]
|
|
312
312
|
};
|
|
313
313
|
fields.push(pubKeyField);
|
|
314
|
-
const
|
|
315
|
-
curSigHash =
|
|
314
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
315
|
+
curSigHash = sigHashPostSign2(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
|
|
316
316
|
}
|
|
317
|
-
const preSign =
|
|
318
|
-
const sigBytes = await account.sign(
|
|
319
|
-
const nextSig =
|
|
320
|
-
const nextSigHash =
|
|
317
|
+
const preSign = sigHashPreSign2(curSigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
318
|
+
const sigBytes = await account.sign(hexToBytes2(preSign));
|
|
319
|
+
const nextSig = bytesToHex2(sigBytes);
|
|
320
|
+
const nextSigHash = sigHashPostSign2(preSign, PubKeyEncoding2.Compressed, nextSig);
|
|
321
321
|
fields.push({
|
|
322
322
|
type: "signature",
|
|
323
|
-
pubKeyEncoding:
|
|
323
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
324
324
|
data: nextSig
|
|
325
325
|
});
|
|
326
326
|
curSigHash = nextSigHash;
|
|
@@ -338,12 +338,12 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
|
|
|
338
338
|
}
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function finalizeMultiSig2(tx, publicKeys) {
|
|
342
342
|
const condition = tx.auth.spendingCondition;
|
|
343
|
-
if (
|
|
343
|
+
if (isNonSequential2(condition.hashMode)) {
|
|
344
344
|
return tx;
|
|
345
345
|
}
|
|
346
|
-
const curSigHash =
|
|
346
|
+
const curSigHash = replayMultiSigSigHash2(tx);
|
|
347
347
|
const finalCondition = finalizeMultiSigCondition(condition, publicKeys, curSigHash);
|
|
348
348
|
return {
|
|
349
349
|
...tx,
|
|
@@ -359,18 +359,18 @@ function finalizeMultiSigCondition(condition, publicKeys, curSigHash) {
|
|
|
359
359
|
for (let i = fields.length;i < publicKeys.length; i++) {
|
|
360
360
|
const pubKeyField = {
|
|
361
361
|
type: "publicKey",
|
|
362
|
-
pubKeyEncoding:
|
|
362
|
+
pubKeyEncoding: PubKeyEncoding2.Compressed,
|
|
363
363
|
data: publicKeys[i]
|
|
364
364
|
};
|
|
365
365
|
fields.push(pubKeyField);
|
|
366
|
-
const preSign =
|
|
367
|
-
sigHash =
|
|
366
|
+
const preSign = sigHashPreSign2(sigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
367
|
+
sigHash = sigHashPostSign2(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
|
|
368
368
|
}
|
|
369
369
|
return { ...condition, fields };
|
|
370
370
|
}
|
|
371
|
-
function
|
|
371
|
+
function combineMultiSigSignatures2(baseTx, signedTxs) {
|
|
372
372
|
const condition = baseTx.auth.spendingCondition;
|
|
373
|
-
if (!
|
|
373
|
+
if (!isNonSequential2(condition.hashMode)) {
|
|
374
374
|
throw new Error("combineMultiSigSignatures only works with non-sequential hash modes (SIP-027)");
|
|
375
375
|
}
|
|
376
376
|
const seenSigs = new Set;
|
|
@@ -400,47 +400,47 @@ function combineMultiSigSignatures(baseTx, signedTxs) {
|
|
|
400
400
|
// src/transactions/build.ts
|
|
401
401
|
function resolvePcMode(mode) {
|
|
402
402
|
if (mode === "allow")
|
|
403
|
-
return
|
|
403
|
+
return PostConditionModeWire2.Allow;
|
|
404
404
|
if (mode === "originator")
|
|
405
|
-
return
|
|
406
|
-
return
|
|
405
|
+
return PostConditionModeWire2.Originator;
|
|
406
|
+
return PostConditionModeWire2.Deny;
|
|
407
407
|
}
|
|
408
408
|
function convertPostConditions(pcs) {
|
|
409
409
|
if (!pcs || pcs.length === 0)
|
|
410
410
|
return [];
|
|
411
|
-
return pcs.map((pc) => convertPostCondition(typeof pc === "string" ?
|
|
411
|
+
return pcs.map((pc) => convertPostCondition(typeof pc === "string" ? fromHex2(pc) : pc));
|
|
412
412
|
}
|
|
413
413
|
function resolveSpendingCondition(opts, nonce, fee) {
|
|
414
414
|
if (opts.publicKeys) {
|
|
415
|
-
return
|
|
415
|
+
return createMultiSigSpendingCondition2(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
|
|
416
416
|
}
|
|
417
|
-
return
|
|
417
|
+
return createSingleSigSpendingCondition2(opts.publicKey, nonce, fee);
|
|
418
418
|
}
|
|
419
419
|
function resolveAuth(spendingCondition, sponsored) {
|
|
420
|
-
return sponsored ?
|
|
420
|
+
return sponsored ? createSponsoredAuth2(spendingCondition) : createStandardAuth2(spendingCondition);
|
|
421
421
|
}
|
|
422
422
|
function resolveVersionAndChainId(chain) {
|
|
423
423
|
if (!chain)
|
|
424
424
|
return { version: 0, chainId: 1 };
|
|
425
425
|
return { version: chain.transactionVersion, chainId: chain.id };
|
|
426
426
|
}
|
|
427
|
-
function
|
|
427
|
+
function buildTokenTransfer2(options) {
|
|
428
428
|
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
429
|
-
const fee =
|
|
430
|
-
const nonce =
|
|
429
|
+
const fee = intToBigInt2(options.fee);
|
|
430
|
+
const nonce = intToBigInt2(options.nonce);
|
|
431
431
|
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
432
|
-
const recipient =
|
|
432
|
+
const recipient = Cl2.principal(options.recipient);
|
|
433
433
|
const tx = {
|
|
434
434
|
version,
|
|
435
435
|
chainId,
|
|
436
436
|
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
437
|
-
anchorMode:
|
|
437
|
+
anchorMode: AnchorMode2.Any,
|
|
438
438
|
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
439
439
|
postConditions: convertPostConditions(options.postConditions),
|
|
440
440
|
payload: {
|
|
441
|
-
payloadType:
|
|
441
|
+
payloadType: PayloadType2.TokenTransfer,
|
|
442
442
|
recipient,
|
|
443
|
-
amount:
|
|
443
|
+
amount: intToBigInt2(options.amount),
|
|
444
444
|
memo: options.memo ?? ""
|
|
445
445
|
}
|
|
446
446
|
};
|
|
@@ -449,20 +449,20 @@ function buildTokenTransfer(options) {
|
|
|
449
449
|
}
|
|
450
450
|
return tx;
|
|
451
451
|
}
|
|
452
|
-
function
|
|
452
|
+
function buildContractCall2(options) {
|
|
453
453
|
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
454
|
-
const fee =
|
|
455
|
-
const nonce =
|
|
454
|
+
const fee = intToBigInt2(options.fee);
|
|
455
|
+
const nonce = intToBigInt2(options.nonce);
|
|
456
456
|
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
457
457
|
const tx = {
|
|
458
458
|
version,
|
|
459
459
|
chainId,
|
|
460
460
|
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
461
|
-
anchorMode:
|
|
461
|
+
anchorMode: AnchorMode2.Any,
|
|
462
462
|
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
463
463
|
postConditions: convertPostConditions(options.postConditions),
|
|
464
464
|
payload: {
|
|
465
|
-
payloadType:
|
|
465
|
+
payloadType: PayloadType2.ContractCall,
|
|
466
466
|
contractAddress: options.contractAddress,
|
|
467
467
|
contractName: options.contractName,
|
|
468
468
|
functionName: options.functionName,
|
|
@@ -474,21 +474,21 @@ function buildContractCall(options) {
|
|
|
474
474
|
}
|
|
475
475
|
return tx;
|
|
476
476
|
}
|
|
477
|
-
function
|
|
477
|
+
function buildContractDeploy2(options) {
|
|
478
478
|
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
479
|
-
const fee =
|
|
480
|
-
const nonce =
|
|
479
|
+
const fee = intToBigInt2(options.fee);
|
|
480
|
+
const nonce = intToBigInt2(options.nonce);
|
|
481
481
|
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
482
|
-
const clarityVersion = options.clarityVersion ??
|
|
482
|
+
const clarityVersion = options.clarityVersion ?? ClarityVersion2.Clarity4;
|
|
483
483
|
const tx = {
|
|
484
484
|
version,
|
|
485
485
|
chainId,
|
|
486
486
|
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
487
|
-
anchorMode:
|
|
487
|
+
anchorMode: AnchorMode2.Any,
|
|
488
488
|
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
489
489
|
postConditions: convertPostConditions(options.postConditions),
|
|
490
490
|
payload: {
|
|
491
|
-
payloadType:
|
|
491
|
+
payloadType: PayloadType2.VersionedSmartContract,
|
|
492
492
|
clarityVersion,
|
|
493
493
|
contractName: options.contractName,
|
|
494
494
|
codeBody: options.codeBody
|
|
@@ -502,19 +502,19 @@ function buildContractDeploy(options) {
|
|
|
502
502
|
|
|
503
503
|
// src/transactions/signer.ts
|
|
504
504
|
function txid(tx) {
|
|
505
|
-
return
|
|
505
|
+
return txidFromBytes2(serializeTransaction2(tx));
|
|
506
506
|
}
|
|
507
|
-
function
|
|
507
|
+
function signBegin2(tx) {
|
|
508
508
|
const cleared = {
|
|
509
509
|
...tx,
|
|
510
510
|
auth: intoInitialSighashAuth(tx.auth)
|
|
511
511
|
};
|
|
512
512
|
return txid(cleared);
|
|
513
513
|
}
|
|
514
|
-
function
|
|
515
|
-
const sigHash =
|
|
514
|
+
function signTransaction2(tx, privateKey) {
|
|
515
|
+
const sigHash = signBegin2(tx);
|
|
516
516
|
const condition = tx.auth.spendingCondition;
|
|
517
|
-
const { nextSig } =
|
|
517
|
+
const { nextSig } = nextSignature2(sigHash, AuthType2.Standard, condition.fee, condition.nonce, privateKey);
|
|
518
518
|
return {
|
|
519
519
|
...tx,
|
|
520
520
|
auth: {
|
|
@@ -526,12 +526,12 @@ function signTransaction(tx, privateKey) {
|
|
|
526
526
|
}
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
|
-
async function
|
|
530
|
-
const sigHash =
|
|
529
|
+
async function signTransactionWithAccount2(tx, account) {
|
|
530
|
+
const sigHash = signBegin2(tx);
|
|
531
531
|
const condition = tx.auth.spendingCondition;
|
|
532
|
-
const sigHashPre =
|
|
533
|
-
const sigBytes = await account.sign(
|
|
534
|
-
const nextSig =
|
|
532
|
+
const sigHashPre = sigHashPreSign2(sigHash, AuthType2.Standard, condition.fee, condition.nonce);
|
|
533
|
+
const sigBytes = await account.sign(hexToBytes2(sigHashPre));
|
|
534
|
+
const nextSig = bytesToHex2(sigBytes);
|
|
535
535
|
return {
|
|
536
536
|
...tx,
|
|
537
537
|
auth: {
|
|
@@ -543,27 +543,27 @@ async function signTransactionWithAccount(tx, account) {
|
|
|
543
543
|
}
|
|
544
544
|
};
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function getTransactionId2(tx) {
|
|
547
547
|
return txid(tx);
|
|
548
548
|
}
|
|
549
|
-
function
|
|
549
|
+
function getOriginSigHash2(tx) {
|
|
550
550
|
const condition = tx.auth.spendingCondition;
|
|
551
551
|
if ("fields" in condition) {
|
|
552
|
-
return
|
|
552
|
+
return replayMultiSigSigHash2(tx);
|
|
553
553
|
}
|
|
554
|
-
const
|
|
554
|
+
const initialSigHash = signBegin2(tx);
|
|
555
555
|
const sc = condition;
|
|
556
|
-
const preSign =
|
|
557
|
-
return
|
|
556
|
+
const preSign = sigHashPreSign2(initialSigHash, AuthType2.Standard, sc.fee, sc.nonce);
|
|
557
|
+
return sigHashPostSign2(preSign, sc.keyEncoding, sc.signature);
|
|
558
558
|
}
|
|
559
|
-
function
|
|
560
|
-
if (tx.auth.authType !==
|
|
559
|
+
function signSponsor2(tx, privateKey) {
|
|
560
|
+
if (tx.auth.authType !== AuthType2.Sponsored) {
|
|
561
561
|
throw new Error("Transaction must be sponsored");
|
|
562
562
|
}
|
|
563
563
|
const auth = tx.auth;
|
|
564
564
|
const sponsorCondition = auth.sponsorSpendingCondition;
|
|
565
|
-
const originSigHash =
|
|
566
|
-
const { nextSig } =
|
|
565
|
+
const originSigHash = getOriginSigHash2(tx);
|
|
566
|
+
const { nextSig } = nextSignature2(originSigHash, AuthType2.Sponsored, sponsorCondition.fee, sponsorCondition.nonce, privateKey);
|
|
567
567
|
return {
|
|
568
568
|
...tx,
|
|
569
569
|
auth: {
|
|
@@ -575,16 +575,16 @@ function signSponsor(tx, privateKey) {
|
|
|
575
575
|
}
|
|
576
576
|
};
|
|
577
577
|
}
|
|
578
|
-
async function
|
|
579
|
-
if (tx.auth.authType !==
|
|
578
|
+
async function signSponsorWithAccount2(tx, account) {
|
|
579
|
+
if (tx.auth.authType !== AuthType2.Sponsored) {
|
|
580
580
|
throw new Error("Transaction must be sponsored");
|
|
581
581
|
}
|
|
582
582
|
const auth = tx.auth;
|
|
583
583
|
const sponsorCondition = auth.sponsorSpendingCondition;
|
|
584
|
-
const originSigHash =
|
|
585
|
-
const sigHashPre =
|
|
586
|
-
const sigBytes = await account.sign(
|
|
587
|
-
const nextSig =
|
|
584
|
+
const originSigHash = getOriginSigHash2(tx);
|
|
585
|
+
const sigHashPre = sigHashPreSign2(originSigHash, AuthType2.Sponsored, sponsorCondition.fee, sponsorCondition.nonce);
|
|
586
|
+
const sigBytes = await account.sign(hexToBytes2(sigHashPre));
|
|
587
|
+
const nextSig = bytesToHex2(sigBytes);
|
|
588
588
|
return {
|
|
589
589
|
...tx,
|
|
590
590
|
auth: {
|
|
@@ -597,7 +597,7 @@ async function signSponsorWithAccount(tx, account) {
|
|
|
597
597
|
};
|
|
598
598
|
}
|
|
599
599
|
|
|
600
|
-
export {
|
|
600
|
+
export { createSingleSigSpendingCondition2, createStandardAuth2, createSponsoredAuth2, sigHashPreSign2, sigHashPostSign2, nextSignature2, isNonSequential2, makeMultiSigAddress2, createMultiSigSpendingCondition2, replayMultiSigSigHash2, signMultiSig2, signMultiSigWithAccount2, finalizeMultiSig2, combineMultiSigSignatures2, buildTokenTransfer2, buildContractCall2, buildContractDeploy2, signBegin2, signTransaction2, signTransactionWithAccount2, getTransactionId2, getOriginSigHash2, signSponsor2, signSponsorWithAccount2 };
|
|
601
601
|
|
|
602
|
-
//# debugId=
|
|
603
|
-
//# sourceMappingURL=stacks-
|
|
602
|
+
//# debugId=603A3254758ACC9C64756E2164756E21
|
|
603
|
+
//# sourceMappingURL=stacks-esm-cmtj5vky.js.map
|