@secondlayer/stacks 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/shared/stacks-02actsrx.cjs +17 -0
- package/dist/shared/stacks-02actsrx.cjs.map +10 -0
- package/dist/shared/stacks-1aqm7c2h.cjs +110 -0
- package/dist/shared/stacks-1aqm7c2h.cjs.map +11 -0
- package/dist/shared/stacks-24h5k94q.cjs +74 -0
- package/dist/shared/stacks-24h5k94q.cjs.map +11 -0
- package/dist/shared/stacks-2ar4prfz.cjs +328 -0
- package/dist/shared/stacks-2ar4prfz.cjs.map +11 -0
- package/dist/shared/stacks-4py5pm0r.cjs +237 -0
- package/dist/shared/stacks-4py5pm0r.cjs.map +10 -0
- package/dist/shared/stacks-5tprhns9.cjs +54 -0
- package/dist/shared/stacks-5tprhns9.cjs.map +11 -0
- package/dist/shared/stacks-61rvzkz1.cjs +132 -0
- package/dist/shared/stacks-61rvzkz1.cjs.map +17 -0
- package/dist/shared/stacks-709tra19.js +30 -0
- package/dist/shared/stacks-709tra19.js.map +10 -0
- package/dist/shared/stacks-74k8cxgb.cjs +567 -0
- package/dist/shared/stacks-74k8cxgb.cjs.map +13 -0
- package/dist/shared/stacks-8m9byk2j.js +7 -0
- package/dist/shared/stacks-8m9byk2j.js.map +9 -0
- package/dist/shared/stacks-8yykgdww.js +125 -0
- package/dist/shared/stacks-8yykgdww.js.map +11 -0
- package/dist/shared/stacks-9g0jhab3.cjs +40 -0
- package/dist/shared/stacks-9g0jhab3.cjs.map +10 -0
- package/dist/shared/stacks-an5k8n4t.cjs +291 -0
- package/dist/shared/stacks-an5k8n4t.cjs.map +23 -0
- package/dist/shared/stacks-b008c3w8.cjs +214 -0
- package/dist/shared/stacks-b008c3w8.cjs.map +11 -0
- package/dist/shared/stacks-bnvfmt7y.cjs +31 -0
- package/dist/shared/stacks-bnvfmt7y.cjs.map +9 -0
- package/dist/shared/stacks-bycy6t9k.js +22 -0
- package/dist/shared/stacks-bycy6t9k.js.map +10 -0
- package/dist/shared/stacks-d1fmkv3p.js +258 -0
- package/dist/shared/stacks-d1fmkv3p.js.map +13 -0
- package/dist/shared/stacks-dr5en54r.cjs +119 -0
- package/dist/shared/stacks-dr5en54r.cjs.map +10 -0
- package/dist/shared/stacks-dxhntr76.js +278 -0
- package/dist/shared/stacks-dxhntr76.js.map +10 -0
- package/dist/shared/stacks-evnzth1q.cjs +35 -0
- package/dist/shared/stacks-evnzth1q.cjs.map +10 -0
- package/dist/shared/stacks-f3tk2k5s.js +27 -0
- package/dist/shared/stacks-f3tk2k5s.js.map +9 -0
- package/dist/shared/stacks-f7wdrzs3.js +285 -0
- package/dist/shared/stacks-f7wdrzs3.js.map +11 -0
- package/dist/shared/stacks-fcaefc5b.cjs +16 -0
- package/dist/shared/stacks-fcaefc5b.cjs.map +10 -0
- package/dist/shared/stacks-g9mcjcqg.cjs +3 -0
- package/dist/shared/stacks-g9mcjcqg.cjs.map +9 -0
- package/dist/shared/stacks-gck1sq7h.cjs +28 -0
- package/dist/shared/stacks-gck1sq7h.cjs.map +10 -0
- package/dist/shared/stacks-gjvbq6w7.js +46 -0
- package/dist/shared/stacks-gjvbq6w7.js.map +10 -0
- package/dist/shared/stacks-j2cy7qtt.js +237 -0
- package/dist/shared/stacks-j2cy7qtt.js.map +11 -0
- package/dist/shared/stacks-k08tgzyp.cjs +232 -0
- package/dist/shared/stacks-k08tgzyp.cjs.map +13 -0
- package/dist/shared/stacks-k2p5tv6x.js +37 -0
- package/dist/shared/stacks-k2p5tv6x.js.map +10 -0
- package/dist/shared/stacks-k58k970n.js +234 -0
- package/dist/shared/stacks-k58k970n.js.map +10 -0
- package/dist/shared/stacks-n2g56wgg.js +338 -0
- package/dist/shared/stacks-n2g56wgg.js.map +23 -0
- package/dist/shared/stacks-nqytwfcc.js +243 -0
- package/dist/shared/stacks-nqytwfcc.js.map +11 -0
- package/dist/shared/stacks-qcae5852.js +19 -0
- package/dist/shared/stacks-qcae5852.js.map +10 -0
- package/dist/shared/stacks-qt8ehebn.js +76 -0
- package/dist/shared/stacks-qt8ehebn.js.map +11 -0
- package/dist/shared/stacks-qvg7c24g.cjs +232 -0
- package/dist/shared/stacks-qvg7c24g.cjs.map +10 -0
- package/dist/shared/stacks-r1t6g3c3.cjs +241 -0
- package/dist/shared/stacks-r1t6g3c3.cjs.map +11 -0
- package/dist/shared/stacks-tjxmrssa.js +282 -0
- package/dist/shared/stacks-tjxmrssa.js.map +11 -0
- package/dist/shared/stacks-v9jqcpd4.js +18 -0
- package/dist/shared/stacks-v9jqcpd4.js.map +10 -0
- package/dist/shared/stacks-vdfag81a.cjs +121 -0
- package/dist/shared/stacks-vdfag81a.cjs.map +10 -0
- package/dist/shared/stacks-vdfs3e5v.js +134 -0
- package/dist/shared/stacks-vdfs3e5v.js.map +10 -0
- package/dist/shared/stacks-y3dh7hv1.js +60 -0
- package/dist/shared/stacks-y3dh7hv1.js.map +11 -0
- package/dist/shared/stacks-ya3x01yd.cjs +16 -0
- package/dist/shared/stacks-ya3x01yd.cjs.map +10 -0
- package/dist/shared/stacks-yfgsm6ap.js +599 -0
- package/dist/shared/stacks-yfgsm6ap.js.map +13 -0
- package/dist/shared/stacks-yfveb68e.js +121 -0
- package/dist/shared/stacks-yfveb68e.js.map +10 -0
- package/dist/shared/stacks-zm0b3tgy.js +160 -0
- package/dist/shared/stacks-zm0b3tgy.js.map +17 -0
- package/dist/shared/stacks-zyv9qqme.cjs +249 -0
- package/dist/shared/stacks-zyv9qqme.cjs.map +11 -0
- package/dist/src/accounts/index.cjs +90 -0
- package/dist/src/accounts/index.cjs.map +12 -0
- package/dist/src/accounts/index.d.cts +47 -0
- package/dist/src/accounts/index.d.ts +47 -0
- package/dist/src/accounts/index.js +104 -0
- package/dist/src/accounts/index.js.map +12 -0
- package/dist/src/actions/index.cjs +36 -0
- package/dist/src/actions/index.cjs.map +9 -0
- package/dist/src/actions/index.d.cts +886 -0
- package/dist/src/actions/index.d.ts +886 -0
- package/dist/src/actions/index.js +81 -0
- package/dist/src/actions/index.js.map +9 -0
- package/dist/src/bns/index.cjs +590 -0
- package/dist/src/bns/index.cjs.map +15 -0
- package/dist/src/bns/index.d.cts +241 -0
- package/dist/src/bns/index.d.ts +241 -0
- package/dist/src/bns/index.js +611 -0
- package/dist/src/bns/index.js.map +15 -0
- package/dist/src/chains/index.cjs +13 -0
- package/dist/src/chains/index.cjs.map +9 -0
- package/dist/src/chains/index.d.cts +53 -0
- package/dist/src/chains/index.d.ts +53 -0
- package/dist/src/chains/index.js +18 -0
- package/dist/src/chains/index.js.map +9 -0
- package/dist/src/clarity/index.cjs +3 -0
- package/dist/src/clarity/index.cjs.map +9 -0
- package/dist/src/clarity/index.d.cts +821 -0
- package/dist/src/clarity/index.d.ts +821 -0
- package/dist/src/clarity/index.js +145 -0
- package/dist/src/clarity/index.js.map +9 -0
- package/dist/src/connect/index.cjs +480 -0
- package/dist/src/connect/index.cjs.map +19 -0
- package/dist/src/connect/index.d.cts +110 -0
- package/dist/src/connect/index.d.ts +110 -0
- package/dist/src/connect/index.js +448 -0
- package/dist/src/connect/index.js.map +19 -0
- package/dist/src/connect/walletconnect/index.cjs +1322 -0
- package/dist/src/connect/walletconnect/index.cjs.map +18 -0
- package/dist/src/connect/walletconnect/index.d.cts +132 -0
- package/dist/src/connect/walletconnect/index.d.ts +132 -0
- package/dist/src/connect/walletconnect/index.js +1290 -0
- package/dist/src/connect/walletconnect/index.js.map +18 -0
- package/dist/src/index.cjs +557 -0
- package/dist/src/index.cjs.map +21 -0
- package/dist/src/index.d.cts +847 -0
- package/dist/src/index.d.ts +847 -0
- package/dist/src/index.js +629 -0
- package/dist/src/index.js.map +21 -0
- package/dist/src/postconditions/index.cjs +3 -0
- package/dist/src/postconditions/index.cjs.map +9 -0
- package/dist/src/postconditions/index.d.cts +91 -0
- package/dist/src/postconditions/index.d.ts +91 -0
- package/dist/src/postconditions/index.js +12 -0
- package/dist/src/postconditions/index.js.map +9 -0
- package/dist/src/pox/index.cjs +860 -0
- package/dist/src/pox/index.cjs.map +15 -0
- package/dist/src/pox/index.d.cts +244 -0
- package/dist/src/pox/index.d.ts +244 -0
- package/dist/src/pox/index.js +877 -0
- package/dist/src/pox/index.js.map +15 -0
- package/dist/src/stackingdao/index.cjs +300 -0
- package/dist/src/stackingdao/index.cjs.map +13 -0
- package/dist/src/stackingdao/index.d.cts +179 -0
- package/dist/src/stackingdao/index.d.ts +179 -0
- package/dist/src/stackingdao/index.js +318 -0
- package/dist/src/stackingdao/index.js.map +13 -0
- package/dist/src/subscriptions/index.cjs +14 -0
- package/dist/src/subscriptions/index.cjs.map +9 -0
- package/dist/src/subscriptions/index.d.cts +250 -0
- package/dist/src/subscriptions/index.d.ts +250 -0
- package/dist/src/subscriptions/index.js +21 -0
- package/dist/src/subscriptions/index.js.map +9 -0
- package/dist/src/transactions/index.cjs +50 -0
- package/dist/src/transactions/index.cjs.map +9 -0
- package/dist/src/transactions/index.d.cts +412 -0
- package/dist/src/transactions/index.d.ts +412 -0
- package/dist/src/transactions/index.js +101 -0
- package/dist/src/transactions/index.js.map +9 -0
- package/dist/src/utils/index.cjs +168 -0
- package/dist/src/utils/index.cjs.map +11 -0
- package/dist/src/utils/index.d.cts +140 -0
- package/dist/src/utils/index.d.ts +140 -0
- package/dist/src/utils/index.js +222 -0
- package/dist/src/utils/index.js.map +11 -0
- package/package.json +105 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AnchorMode,
|
|
3
|
+
AuthType,
|
|
4
|
+
FungibleConditionCode,
|
|
5
|
+
NonFungibleConditionCode,
|
|
6
|
+
PayloadType,
|
|
7
|
+
PostConditionModeWire,
|
|
8
|
+
PubKeyEncoding,
|
|
9
|
+
createMultiSigSpendingCondition,
|
|
10
|
+
createSingleSigSpendingCondition,
|
|
11
|
+
createSponsoredAuth,
|
|
12
|
+
createStandardAuth,
|
|
13
|
+
intoInitialSighashAuth,
|
|
14
|
+
nextSignature,
|
|
15
|
+
replayMultiSigSigHash,
|
|
16
|
+
serializeTransaction,
|
|
17
|
+
sigHashPostSign,
|
|
18
|
+
sigHashPreSign
|
|
19
|
+
} from "./stacks-yfgsm6ap.js";
|
|
20
|
+
import {
|
|
21
|
+
Cl
|
|
22
|
+
} from "./stacks-j2cy7qtt.js";
|
|
23
|
+
import {
|
|
24
|
+
txidFromBytes
|
|
25
|
+
} from "./stacks-bycy6t9k.js";
|
|
26
|
+
import {
|
|
27
|
+
parseContractId
|
|
28
|
+
} from "./stacks-gjvbq6w7.js";
|
|
29
|
+
import {
|
|
30
|
+
bytesToHex,
|
|
31
|
+
hexToBytes,
|
|
32
|
+
intToBigInt
|
|
33
|
+
} from "./stacks-nqytwfcc.js";
|
|
34
|
+
|
|
35
|
+
// src/transactions/signer.ts
|
|
36
|
+
function txid(tx) {
|
|
37
|
+
return txidFromBytes(serializeTransaction(tx));
|
|
38
|
+
}
|
|
39
|
+
function signBegin(tx) {
|
|
40
|
+
const cleared = {
|
|
41
|
+
...tx,
|
|
42
|
+
auth: intoInitialSighashAuth(tx.auth)
|
|
43
|
+
};
|
|
44
|
+
return txid(cleared);
|
|
45
|
+
}
|
|
46
|
+
function signTransaction(tx, privateKey) {
|
|
47
|
+
const sigHash = signBegin(tx);
|
|
48
|
+
const condition = tx.auth.spendingCondition;
|
|
49
|
+
const { nextSig, nextSigHash } = nextSignature(sigHash, AuthType.Standard, condition.fee, condition.nonce, privateKey);
|
|
50
|
+
return {
|
|
51
|
+
...tx,
|
|
52
|
+
auth: {
|
|
53
|
+
...tx.auth,
|
|
54
|
+
spendingCondition: {
|
|
55
|
+
...condition,
|
|
56
|
+
signature: nextSig
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function signTransactionWithAccount(tx, account) {
|
|
62
|
+
const sigHash = signBegin(tx);
|
|
63
|
+
const condition = tx.auth.spendingCondition;
|
|
64
|
+
const sigHashPre = sigHashPreSign(sigHash, AuthType.Standard, condition.fee, condition.nonce);
|
|
65
|
+
const sigBytes = await account.sign(hexToBytes(sigHashPre));
|
|
66
|
+
const nextSig = bytesToHex(sigBytes);
|
|
67
|
+
const pubKeyBytes = hexToBytes(account.publicKey);
|
|
68
|
+
const pubKeyEncoding = pubKeyBytes.length === 33 ? PubKeyEncoding.Compressed : PubKeyEncoding.Uncompressed;
|
|
69
|
+
return {
|
|
70
|
+
...tx,
|
|
71
|
+
auth: {
|
|
72
|
+
...tx.auth,
|
|
73
|
+
spendingCondition: {
|
|
74
|
+
...condition,
|
|
75
|
+
signature: nextSig
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function getTransactionId(tx) {
|
|
81
|
+
return txid(tx);
|
|
82
|
+
}
|
|
83
|
+
function getOriginSigHash(tx) {
|
|
84
|
+
const condition = tx.auth.spendingCondition;
|
|
85
|
+
if ("fields" in condition) {
|
|
86
|
+
return replayMultiSigSigHash(tx);
|
|
87
|
+
}
|
|
88
|
+
const initialSigHash = signBegin(tx);
|
|
89
|
+
const sc = condition;
|
|
90
|
+
const preSign = sigHashPreSign(initialSigHash, AuthType.Standard, sc.fee, sc.nonce);
|
|
91
|
+
return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);
|
|
92
|
+
}
|
|
93
|
+
function signSponsor(tx, privateKey) {
|
|
94
|
+
if (tx.auth.authType !== AuthType.Sponsored) {
|
|
95
|
+
throw new Error("Transaction must be sponsored");
|
|
96
|
+
}
|
|
97
|
+
const auth = tx.auth;
|
|
98
|
+
const sponsorCondition = auth.sponsorSpendingCondition;
|
|
99
|
+
const originSigHash = getOriginSigHash(tx);
|
|
100
|
+
const { nextSig } = nextSignature(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce, privateKey);
|
|
101
|
+
return {
|
|
102
|
+
...tx,
|
|
103
|
+
auth: {
|
|
104
|
+
...auth,
|
|
105
|
+
sponsorSpendingCondition: {
|
|
106
|
+
...sponsorCondition,
|
|
107
|
+
signature: nextSig
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function signSponsorWithAccount(tx, account) {
|
|
113
|
+
if (tx.auth.authType !== AuthType.Sponsored) {
|
|
114
|
+
throw new Error("Transaction must be sponsored");
|
|
115
|
+
}
|
|
116
|
+
const auth = tx.auth;
|
|
117
|
+
const sponsorCondition = auth.sponsorSpendingCondition;
|
|
118
|
+
const originSigHash = getOriginSigHash(tx);
|
|
119
|
+
const sigHashPre = sigHashPreSign(originSigHash, AuthType.Sponsored, sponsorCondition.fee, sponsorCondition.nonce);
|
|
120
|
+
const sigBytes = await account.sign(hexToBytes(sigHashPre));
|
|
121
|
+
const nextSig = bytesToHex(sigBytes);
|
|
122
|
+
return {
|
|
123
|
+
...tx,
|
|
124
|
+
auth: {
|
|
125
|
+
...auth,
|
|
126
|
+
sponsorSpendingCondition: {
|
|
127
|
+
...sponsorCondition,
|
|
128
|
+
signature: nextSig
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/transactions/build.ts
|
|
135
|
+
function resolvePcMode(mode) {
|
|
136
|
+
return mode === "allow" ? PostConditionModeWire.Allow : PostConditionModeWire.Deny;
|
|
137
|
+
}
|
|
138
|
+
function convertPostConditions(pcs) {
|
|
139
|
+
if (!pcs || pcs.length === 0)
|
|
140
|
+
return [];
|
|
141
|
+
return pcs.map(convertPostCondition);
|
|
142
|
+
}
|
|
143
|
+
function resolvePrincipal(address) {
|
|
144
|
+
if (address === "origin")
|
|
145
|
+
return { type: "origin" };
|
|
146
|
+
const [addr, name] = address.split(".");
|
|
147
|
+
if (name) {
|
|
148
|
+
return { type: "contract", address: addr, contractName: name };
|
|
149
|
+
}
|
|
150
|
+
return { type: "standard", address: addr };
|
|
151
|
+
}
|
|
152
|
+
var FUNGIBLE_CODE_MAP = {
|
|
153
|
+
eq: FungibleConditionCode.Equal,
|
|
154
|
+
gt: FungibleConditionCode.Greater,
|
|
155
|
+
gte: FungibleConditionCode.GreaterEqual,
|
|
156
|
+
lt: FungibleConditionCode.Less,
|
|
157
|
+
lte: FungibleConditionCode.LessEqual
|
|
158
|
+
};
|
|
159
|
+
function convertPostCondition(pc) {
|
|
160
|
+
switch (pc.type) {
|
|
161
|
+
case "stx-postcondition":
|
|
162
|
+
return {
|
|
163
|
+
type: "stx",
|
|
164
|
+
principal: resolvePrincipal(pc.address),
|
|
165
|
+
conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
|
|
166
|
+
amount: intToBigInt(pc.amount)
|
|
167
|
+
};
|
|
168
|
+
case "ft-postcondition": {
|
|
169
|
+
const [contractId, tokenName] = pc.asset.split("::");
|
|
170
|
+
const [addr, name] = parseContractId(contractId);
|
|
171
|
+
return {
|
|
172
|
+
type: "ft",
|
|
173
|
+
principal: resolvePrincipal(pc.address),
|
|
174
|
+
asset: { address: addr, contractName: name, assetName: tokenName },
|
|
175
|
+
conditionCode: FUNGIBLE_CODE_MAP[pc.condition],
|
|
176
|
+
amount: intToBigInt(pc.amount)
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
case "nft-postcondition": {
|
|
180
|
+
const [contractId, tokenName] = pc.asset.split("::");
|
|
181
|
+
const [addr, name] = parseContractId(contractId);
|
|
182
|
+
return {
|
|
183
|
+
type: "nft",
|
|
184
|
+
principal: resolvePrincipal(pc.address),
|
|
185
|
+
asset: { address: addr, contractName: name, assetName: tokenName },
|
|
186
|
+
conditionCode: pc.condition === "sent" ? NonFungibleConditionCode.Sends : NonFungibleConditionCode.DoesNotSend,
|
|
187
|
+
assetId: pc.assetId
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function resolveSpendingCondition(opts, nonce, fee) {
|
|
193
|
+
if (opts.publicKeys) {
|
|
194
|
+
return createMultiSigSpendingCondition(opts.publicKeys, opts.signaturesRequired, nonce, fee, opts.hashMode);
|
|
195
|
+
}
|
|
196
|
+
return createSingleSigSpendingCondition(opts.publicKey, nonce, fee);
|
|
197
|
+
}
|
|
198
|
+
function resolveAuth(spendingCondition, sponsored) {
|
|
199
|
+
return sponsored ? createSponsoredAuth(spendingCondition) : createStandardAuth(spendingCondition);
|
|
200
|
+
}
|
|
201
|
+
function resolveVersionAndChainId(chain) {
|
|
202
|
+
if (!chain)
|
|
203
|
+
return { version: 0, chainId: 1 };
|
|
204
|
+
return { version: chain.transactionVersion, chainId: chain.id };
|
|
205
|
+
}
|
|
206
|
+
function buildTokenTransfer(options) {
|
|
207
|
+
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
208
|
+
const fee = intToBigInt(options.fee);
|
|
209
|
+
const nonce = intToBigInt(options.nonce);
|
|
210
|
+
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
211
|
+
const recipient = Cl.principal(options.recipient);
|
|
212
|
+
const tx = {
|
|
213
|
+
version,
|
|
214
|
+
chainId,
|
|
215
|
+
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
216
|
+
anchorMode: AnchorMode.Any,
|
|
217
|
+
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
218
|
+
postConditions: convertPostConditions(options.postConditions),
|
|
219
|
+
payload: {
|
|
220
|
+
payloadType: PayloadType.TokenTransfer,
|
|
221
|
+
recipient,
|
|
222
|
+
amount: intToBigInt(options.amount),
|
|
223
|
+
memo: options.memo ?? ""
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (options.publicKeys) {
|
|
227
|
+
tx._multisig = { publicKeys: options.publicKeys };
|
|
228
|
+
}
|
|
229
|
+
return tx;
|
|
230
|
+
}
|
|
231
|
+
function buildContractCall(options) {
|
|
232
|
+
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
233
|
+
const fee = intToBigInt(options.fee);
|
|
234
|
+
const nonce = intToBigInt(options.nonce);
|
|
235
|
+
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
236
|
+
const tx = {
|
|
237
|
+
version,
|
|
238
|
+
chainId,
|
|
239
|
+
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
240
|
+
anchorMode: AnchorMode.Any,
|
|
241
|
+
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
242
|
+
postConditions: convertPostConditions(options.postConditions),
|
|
243
|
+
payload: {
|
|
244
|
+
payloadType: PayloadType.ContractCall,
|
|
245
|
+
contractAddress: options.contractAddress,
|
|
246
|
+
contractName: options.contractName,
|
|
247
|
+
functionName: options.functionName,
|
|
248
|
+
functionArgs: options.functionArgs
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
if (options.publicKeys) {
|
|
252
|
+
tx._multisig = { publicKeys: options.publicKeys };
|
|
253
|
+
}
|
|
254
|
+
return tx;
|
|
255
|
+
}
|
|
256
|
+
function buildContractDeploy(options) {
|
|
257
|
+
const { version, chainId } = resolveVersionAndChainId(options.chain);
|
|
258
|
+
const fee = intToBigInt(options.fee);
|
|
259
|
+
const nonce = intToBigInt(options.nonce);
|
|
260
|
+
const spendingCondition = resolveSpendingCondition(options, nonce, fee);
|
|
261
|
+
const useVersioned = options.clarityVersion !== undefined;
|
|
262
|
+
const tx = {
|
|
263
|
+
version,
|
|
264
|
+
chainId,
|
|
265
|
+
auth: resolveAuth(spendingCondition, options.sponsored),
|
|
266
|
+
anchorMode: AnchorMode.Any,
|
|
267
|
+
postConditionMode: resolvePcMode(options.postConditionMode),
|
|
268
|
+
postConditions: convertPostConditions(options.postConditions),
|
|
269
|
+
payload: {
|
|
270
|
+
payloadType: useVersioned ? PayloadType.VersionedSmartContract : PayloadType.SmartContract,
|
|
271
|
+
clarityVersion: options.clarityVersion,
|
|
272
|
+
contractName: options.contractName,
|
|
273
|
+
codeBody: options.codeBody
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
if (options.publicKeys) {
|
|
277
|
+
tx._multisig = { publicKeys: options.publicKeys };
|
|
278
|
+
}
|
|
279
|
+
return tx;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export { signBegin, signTransaction, signTransactionWithAccount, getTransactionId, getOriginSigHash, signSponsor, signSponsorWithAccount, buildTokenTransfer, buildContractCall, buildContractDeploy };
|
|
283
|
+
|
|
284
|
+
//# debugId=4382774F865376AE64756E2164756E21
|
|
285
|
+
//# sourceMappingURL=stacks-f7wdrzs3.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/transactions/signer.ts", "../src/transactions/build.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { bytesToHex, hexToBytes } from \"../utils/encoding.ts\";\nimport { txidFromBytes } from \"../utils/hash.ts\";\nimport {\n intoInitialSighashAuth,\n nextSignature,\n sigHashPreSign,\n sigHashPostSign,\n createSingleSigSpendingCondition,\n} from \"./authorization.ts\";\nimport { replayMultiSigSigHash } from \"./multisig.ts\";\nimport { serializeTransaction } from \"./wire/serialize.ts\";\nimport {\n AuthType,\n PubKeyEncoding,\n RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n type StacksTransaction,\n type SingleSigSpendingCondition,\n type MultiSigSpendingCondition,\n type SponsoredAuthorization,\n} from \"./types.ts\";\nimport type { LocalAccount, CustomAccount } from \"../accounts/types.ts\";\n\nfunction txid(tx: StacksTransaction): string {\n return txidFromBytes(serializeTransaction(tx));\n}\n\n/** Compute the initial sighash for a transaction */\nexport function signBegin(tx: StacksTransaction): string {\n const cleared: StacksTransaction = {\n ...tx,\n auth: intoInitialSighashAuth(tx.auth),\n };\n return txid(cleared);\n}\n\n/** Sign a single-sig transaction with a private key, returning the signed transaction */\nexport function signTransaction(\n tx: StacksTransaction,\n privateKey: string\n): StacksTransaction {\n const sigHash = signBegin(tx);\n const condition = tx.auth.spendingCondition as SingleSigSpendingCondition;\n\n // Origin always signs with AuthType.Standard (even for sponsored txs)\n const { nextSig, nextSigHash } = nextSignature(\n sigHash,\n AuthType.Standard,\n condition.fee,\n condition.nonce,\n privateKey\n );\n\n return {\n ...tx,\n auth: {\n ...tx.auth,\n spendingCondition: {\n ...condition,\n signature: nextSig,\n },\n },\n };\n}\n\n/** Sign a single-sig transaction using an account (LocalAccount or CustomAccount) */\nexport async function signTransactionWithAccount(\n tx: StacksTransaction,\n account: LocalAccount | CustomAccount\n): Promise<StacksTransaction> {\n const sigHash = signBegin(tx);\n const condition = tx.auth.spendingCondition as SingleSigSpendingCondition;\n\n // Origin always signs with AuthType.Standard (even for sponsored txs)\n const sigHashPre = sigHashPreSign(\n sigHash,\n AuthType.Standard,\n condition.fee,\n condition.nonce\n );\n\n // account.sign returns 65-byte VRS (recovery + r + s)\n const sigBytes = await account.sign(hexToBytes(sigHashPre));\n const nextSig = bytesToHex(sigBytes);\n\n const pubKeyBytes = hexToBytes(account.publicKey);\n const pubKeyEncoding =\n pubKeyBytes.length === 33\n ? PubKeyEncoding.Compressed\n : PubKeyEncoding.Uncompressed;\n\n return {\n ...tx,\n auth: {\n ...tx.auth,\n spendingCondition: {\n ...condition,\n signature: nextSig,\n },\n },\n };\n}\n\n/** Get the txid of a transaction */\nexport function getTransactionId(tx: StacksTransaction): string {\n return txid(tx);\n}\n\n/** Reconstruct the sighash after origin signing (needed for sponsor signing) */\nexport function getOriginSigHash(tx: StacksTransaction): string {\n const condition = tx.auth.spendingCondition;\n\n // Multi-sig: replay through all fields\n if (\"fields\" in condition) {\n return replayMultiSigSigHash(tx);\n }\n\n // Single-sig\n const initialSigHash = signBegin(tx);\n const sc = condition as SingleSigSpendingCondition;\n const preSign = sigHashPreSign(initialSigHash, AuthType.Standard, sc.fee, sc.nonce);\n return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);\n}\n\n/** Sign a sponsored transaction as the sponsor with a private key */\nexport function signSponsor(tx: StacksTransaction, privateKey: string): StacksTransaction {\n if (tx.auth.authType !== AuthType.Sponsored) {\n throw new Error(\"Transaction must be sponsored\");\n }\n const auth = tx.auth as SponsoredAuthorization;\n const sponsorCondition = auth.sponsorSpendingCondition as SingleSigSpendingCondition;\n const originSigHash = getOriginSigHash(tx);\n\n const { nextSig } = nextSignature(\n originSigHash,\n AuthType.Sponsored,\n sponsorCondition.fee,\n sponsorCondition.nonce,\n privateKey\n );\n\n return {\n ...tx,\n auth: {\n ...auth,\n sponsorSpendingCondition: {\n ...sponsorCondition,\n signature: nextSig,\n },\n },\n };\n}\n\n/** Sign a sponsored transaction as the sponsor using an account */\nexport async function signSponsorWithAccount(\n tx: StacksTransaction,\n account: LocalAccount | CustomAccount\n): Promise<StacksTransaction> {\n if (tx.auth.authType !== AuthType.Sponsored) {\n throw new Error(\"Transaction must be sponsored\");\n }\n const auth = tx.auth as SponsoredAuthorization;\n const sponsorCondition = auth.sponsorSpendingCondition as SingleSigSpendingCondition;\n const originSigHash = getOriginSigHash(tx);\n\n const sigHashPre = sigHashPreSign(\n originSigHash,\n AuthType.Sponsored,\n sponsorCondition.fee,\n sponsorCondition.nonce\n );\n\n const sigBytes = await account.sign(hexToBytes(sigHashPre));\n const nextSig = bytesToHex(sigBytes);\n\n return {\n ...tx,\n auth: {\n ...auth,\n sponsorSpendingCondition: {\n ...sponsorCondition,\n signature: nextSig,\n },\n },\n };\n}\n",
|
|
6
|
+
"import type { StacksChain } from \"../chains/types.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport type { MultiSigHashMode, SpendingCondition } from \"./types.ts\";\nimport {\n createSingleSigSpendingCondition,\n createStandardAuth,\n createSponsoredAuth,\n} from \"./authorization.ts\";\nimport { createMultiSigSpendingCondition } from \"./multisig.ts\";\nimport {\n PayloadType,\n AnchorMode,\n PostConditionModeWire,\n FungibleConditionCode,\n NonFungibleConditionCode,\n PostConditionPrincipalId,\n type StacksTransaction,\n type PostConditionWire,\n type PostConditionPrincipalWire,\n type ClarityVersion,\n} from \"./types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { intToBigInt, type IntegerType } from \"../utils/encoding.ts\";\nimport { validateStacksAddress, parseContractId } from \"../utils/address.ts\";\n\ntype MultiSigOptions = {\n publicKeys?: string[];\n signaturesRequired?: number;\n hashMode?: MultiSigHashMode;\n};\n\nexport type BuildTokenTransferOptions = MultiSigOptions & {\n recipient: string;\n amount: IntegerType;\n memo?: string;\n fee: IntegerType;\n nonce: IntegerType;\n publicKey?: string;\n chain?: StacksChain;\n postConditionMode?: \"allow\" | \"deny\";\n postConditions?: PostCondition[];\n sponsored?: boolean;\n};\n\nexport type BuildContractCallOptions = MultiSigOptions & {\n contractAddress: string;\n contractName: string;\n functionName: string;\n functionArgs: ClarityValue[];\n fee: IntegerType;\n nonce: IntegerType;\n publicKey?: string;\n chain?: StacksChain;\n postConditionMode?: \"allow\" | \"deny\";\n postConditions?: PostCondition[];\n sponsored?: boolean;\n};\n\nexport type BuildContractDeployOptions = MultiSigOptions & {\n contractName: string;\n codeBody: string;\n clarityVersion?: ClarityVersion;\n fee: IntegerType;\n nonce: IntegerType;\n publicKey?: string;\n chain?: StacksChain;\n postConditionMode?: \"allow\" | \"deny\";\n postConditions?: PostCondition[];\n sponsored?: boolean;\n};\n\nfunction resolvePcMode(mode?: \"allow\" | \"deny\"): PostConditionModeWire {\n return mode === \"allow\" ? PostConditionModeWire.Allow : PostConditionModeWire.Deny;\n}\n\nfunction convertPostConditions(pcs?: PostCondition[]): PostConditionWire[] {\n if (!pcs || pcs.length === 0) return [];\n return pcs.map(convertPostCondition);\n}\n\nfunction resolvePrincipal(address: string): PostConditionPrincipalWire {\n if (address === \"origin\") return { type: \"origin\" };\n const [addr, name] = address.split(\".\");\n if (name) {\n return { type: \"contract\", address: addr!, contractName: name };\n }\n return { type: \"standard\", address: addr! };\n}\n\nconst FUNGIBLE_CODE_MAP: Record<string, number> = {\n eq: FungibleConditionCode.Equal,\n gt: FungibleConditionCode.Greater,\n gte: FungibleConditionCode.GreaterEqual,\n lt: FungibleConditionCode.Less,\n lte: FungibleConditionCode.LessEqual,\n};\n\nfunction convertPostCondition(pc: PostCondition): PostConditionWire {\n switch (pc.type) {\n case \"stx-postcondition\":\n return {\n type: \"stx\",\n principal: resolvePrincipal(pc.address),\n conditionCode: FUNGIBLE_CODE_MAP[pc.condition]!,\n amount: intToBigInt(pc.amount),\n };\n case \"ft-postcondition\": {\n const [contractId, tokenName] = pc.asset.split(\"::\");\n const [addr, name] = parseContractId(contractId!);\n return {\n type: \"ft\",\n principal: resolvePrincipal(pc.address),\n asset: { address: addr, contractName: name, assetName: tokenName! },\n conditionCode: FUNGIBLE_CODE_MAP[pc.condition]!,\n amount: intToBigInt(pc.amount),\n };\n }\n case \"nft-postcondition\": {\n const [contractId, tokenName] = pc.asset.split(\"::\");\n const [addr, name] = parseContractId(contractId!);\n return {\n type: \"nft\",\n principal: resolvePrincipal(pc.address),\n asset: { address: addr, contractName: name, assetName: tokenName! },\n conditionCode: pc.condition === \"sent\" ? NonFungibleConditionCode.Sends : NonFungibleConditionCode.DoesNotSend,\n assetId: pc.assetId,\n };\n }\n }\n}\n\nimport type { Authorization } from \"./types.ts\";\n\nfunction resolveSpendingCondition(\n opts: MultiSigOptions & { publicKey?: string },\n nonce: bigint,\n fee: bigint\n): SpendingCondition {\n if (opts.publicKeys) {\n return createMultiSigSpendingCondition(\n opts.publicKeys,\n opts.signaturesRequired!,\n nonce,\n fee,\n opts.hashMode\n );\n }\n return createSingleSigSpendingCondition(opts.publicKey!, nonce, fee);\n}\n\nfunction resolveAuth(spendingCondition: any, sponsored?: boolean): Authorization {\n return sponsored\n ? createSponsoredAuth(spendingCondition)\n : createStandardAuth(spendingCondition);\n}\n\nfunction resolveVersionAndChainId(chain?: StacksChain): { version: number; chainId: number } {\n if (!chain) return { version: 0x00, chainId: 0x00000001 }; // mainnet defaults\n return { version: chain.transactionVersion, chainId: chain.id };\n}\n\nexport function buildTokenTransfer(options: BuildTokenTransferOptions): StacksTransaction {\n const { version, chainId } = resolveVersionAndChainId(options.chain);\n const fee = intToBigInt(options.fee);\n const nonce = intToBigInt(options.nonce);\n\n const spendingCondition = resolveSpendingCondition(options, nonce, fee);\n const recipient = Cl.principal(options.recipient);\n\n const tx: StacksTransaction = {\n version,\n chainId,\n auth: resolveAuth(spendingCondition, options.sponsored),\n anchorMode: AnchorMode.Any,\n postConditionMode: resolvePcMode(options.postConditionMode),\n postConditions: convertPostConditions(options.postConditions),\n payload: {\n payloadType: PayloadType.TokenTransfer,\n recipient,\n amount: intToBigInt(options.amount),\n memo: options.memo ?? \"\",\n },\n };\n\n if (options.publicKeys) {\n (tx as any)._multisig = { publicKeys: options.publicKeys };\n }\n return tx;\n}\n\nexport function buildContractCall(options: BuildContractCallOptions): StacksTransaction {\n const { version, chainId } = resolveVersionAndChainId(options.chain);\n const fee = intToBigInt(options.fee);\n const nonce = intToBigInt(options.nonce);\n\n const spendingCondition = resolveSpendingCondition(options, nonce, fee);\n\n const tx: StacksTransaction = {\n version,\n chainId,\n auth: resolveAuth(spendingCondition, options.sponsored),\n anchorMode: AnchorMode.Any,\n postConditionMode: resolvePcMode(options.postConditionMode),\n postConditions: convertPostConditions(options.postConditions),\n payload: {\n payloadType: PayloadType.ContractCall,\n contractAddress: options.contractAddress,\n contractName: options.contractName,\n functionName: options.functionName,\n functionArgs: options.functionArgs,\n },\n };\n\n if (options.publicKeys) {\n (tx as any)._multisig = { publicKeys: options.publicKeys };\n }\n return tx;\n}\n\nexport function buildContractDeploy(options: BuildContractDeployOptions): StacksTransaction {\n const { version, chainId } = resolveVersionAndChainId(options.chain);\n const fee = intToBigInt(options.fee);\n const nonce = intToBigInt(options.nonce);\n\n const spendingCondition = resolveSpendingCondition(options, nonce, fee);\n const useVersioned = options.clarityVersion !== undefined;\n\n const tx: StacksTransaction = {\n version,\n chainId,\n auth: resolveAuth(spendingCondition, options.sponsored),\n anchorMode: AnchorMode.Any,\n postConditionMode: resolvePcMode(options.postConditionMode),\n postConditions: convertPostConditions(options.postConditions),\n payload: {\n payloadType: useVersioned ? PayloadType.VersionedSmartContract : PayloadType.SmartContract,\n clarityVersion: options.clarityVersion,\n contractName: options.contractName,\n codeBody: options.codeBody,\n },\n };\n\n if (options.publicKeys) {\n (tx as any)._multisig = { publicKeys: options.publicKeys };\n }\n return tx;\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAS,IAAI,CAAC,IAA+B;AAAA,EAC3C,OAAO,cAAc,qBAAqB,EAAE,CAAC;AAAA;AAIxC,SAAS,SAAS,CAAC,IAA+B;AAAA,EACvD,MAAM,UAA6B;AAAA,OAC9B;AAAA,IACH,MAAM,uBAAuB,GAAG,IAAI;AAAA,EACtC;AAAA,EACA,OAAO,KAAK,OAAO;AAAA;AAId,SAAS,eAAe,CAC7B,IACA,YACmB;AAAA,EACnB,MAAM,UAAU,UAAU,EAAE;AAAA,EAC5B,MAAM,YAAY,GAAG,KAAK;AAAA,EAG1B,QAAQ,SAAS,gBAAgB,cAC/B,SACA,SAAS,UACT,UAAU,KACV,UAAU,OACV,UACF;AAAA,EAEA,OAAO;AAAA,OACF;AAAA,IACH,MAAM;AAAA,SACD,GAAG;AAAA,MACN,mBAAmB;AAAA,WACd;AAAA,QACH,WAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAAA;AAIF,eAAsB,0BAA0B,CAC9C,IACA,SAC4B;AAAA,EAC5B,MAAM,UAAU,UAAU,EAAE;AAAA,EAC5B,MAAM,YAAY,GAAG,KAAK;AAAA,EAG1B,MAAM,aAAa,eACjB,SACA,SAAS,UACT,UAAU,KACV,UAAU,KACZ;AAAA,EAGA,MAAM,WAAW,MAAM,QAAQ,KAAK,WAAW,UAAU,CAAC;AAAA,EAC1D,MAAM,UAAU,WAAW,QAAQ;AAAA,EAEnC,MAAM,cAAc,WAAW,QAAQ,SAAS;AAAA,EAChD,MAAM,iBACJ,YAAY,WAAW,KACnB,eAAe,aACf,eAAe;AAAA,EAErB,OAAO;AAAA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AAY;AAAA,MACzB,iBAAiB,QAAQ;AAAA,MACzB,cAAc,QAAQ;AAAA,MACtB,cAAc,QAAQ;AAAA,MACtB,cAAc,QAAQ;AAAA,IACxB;AAAA,EACF;AAAA,EAEA,IAAI,QAAQ,YAAY;AAAA,IACrB,GAAW,YAAY,EAAE,YAAY,QAAQ,WAAW;AAAA,EAC3D;AAAA,EACA,OAAO;AAAA;AAGF,SAAS,mBAAmB,CAAC,SAAwD;AAAA,EAC1F,QAAQ,SAAS,YAAY,yBAAyB,QAAQ,KAAK;AAAA,EACnE,MAAM,MAAM,YAAY,QAAQ,GAAG;AAAA,EACnC,MAAM,QAAQ,YAAY,QAAQ,KAAK;AAAA,EAEvC,MAAM,oBAAoB,yBAAyB,SAAS,OAAO,GAAG;AAAA,EACtE,MAAM,eAAe,QAAQ,mBAAmB;AAAA,EAEhD,MAAM,KAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,MAAM,YAAY,mBAAmB,QAAQ,SAAS;AAAA,IACtD,YAAY,WAAW;AAAA,IACvB,mBAAmB,cAAc,QAAQ,iBAAiB;AAAA,IAC1D,gBAAgB,sBAAsB,QAAQ,cAAc;AAAA,IAC5D,SAAS;AAAA,MACP,aAAa,eAAe,YAAY,yBAAyB,YAAY;AAAA,MAC7E,gBAAgB,QAAQ;AAAA,MACxB,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,IAAI,QAAQ,YAAY;AAAA,IACrB,GAAW,YAAY,EAAE,YAAY,QAAQ,WAAW;AAAA,EAC3D;AAAA,EACA,OAAO;AAAA;",
|
|
9
|
+
"debugId": "4382774F865376AE64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/utils/hash.ts
|
|
2
|
+
var import_legacy = require("@noble/hashes/legacy.js");
|
|
3
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
4
|
+
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
5
|
+
function hash160(input) {
|
|
6
|
+
return import_legacy.ripemd160(import_sha2.sha256(input));
|
|
7
|
+
}
|
|
8
|
+
function txidFromBytes(data) {
|
|
9
|
+
return bytesToHex(import_sha22.sha512_256(data));
|
|
10
|
+
}
|
|
11
|
+
function hashP2PKH(input) {
|
|
12
|
+
return bytesToHex(hash160(input));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# debugId=34217CD0B57FD93C64756E2164756E21
|
|
16
|
+
//# sourceMappingURL=stacks-fcaefc5b.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/utils/hash.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { ripemd160 } from \"@noble/hashes/legacy.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { sha512_256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex } from \"./encoding.ts\";\n\nexport { sha256, sha512_256, ripemd160 };\n\n/** RIPEMD160(SHA256(input)) — standard Bitcoin/Stacks address hash */\nexport function hash160(input: Uint8Array): Uint8Array {\n return ripemd160(sha256(input));\n}\n\n/** Hash used for transaction IDs */\nexport function txidFromBytes(data: Uint8Array): string {\n return bytesToHex(sha512_256(data));\n}\n\n/** hash160 as hex — used for P2PKH address derivation */\nexport function hashP2PKH(input: Uint8Array): string {\n return bytesToHex(hash160(input));\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAA0B,IAA1B;AACuB,IAAvB;AAC2B,IAA3B;AAMO,SAAS,OAAO,CAAC,OAA+B;AAAA,EACrD,OAAO,wBAAU,mBAAO,KAAK,CAAC;AAAA;AAIzB,SAAS,aAAa,CAAC,MAA0B;AAAA,EACtD,OAAO,WAAW,wBAAW,IAAI,CAAC;AAAA;AAI7B,SAAS,SAAS,CAAC,OAA2B;AAAA,EACnD,OAAO,WAAW,QAAQ,KAAK,CAAC;AAAA;",
|
|
8
|
+
"debugId": "34217CD0B57FD93C64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/errors/base.ts
|
|
2
|
+
class BaseError extends Error {
|
|
3
|
+
name = "StacksError";
|
|
4
|
+
shortMessage;
|
|
5
|
+
details;
|
|
6
|
+
constructor(shortMessage, options) {
|
|
7
|
+
const message = [
|
|
8
|
+
shortMessage,
|
|
9
|
+
options?.details ? `
|
|
10
|
+
${options.details}` : ""
|
|
11
|
+
].join("");
|
|
12
|
+
super(message, { cause: options?.cause });
|
|
13
|
+
this.shortMessage = shortMessage;
|
|
14
|
+
this.details = options?.details;
|
|
15
|
+
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return {
|
|
18
|
+
name: this.name,
|
|
19
|
+
message: this.message,
|
|
20
|
+
shortMessage: this.shortMessage,
|
|
21
|
+
details: this.details,
|
|
22
|
+
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# debugId=DEA222C2A831257D64756E2164756E21
|
|
28
|
+
//# sourceMappingURL=stacks-gck1sq7h.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/errors/base.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export class BaseError extends Error {\n override name = \"StacksError\";\n shortMessage: string;\n details?: string;\n\n constructor(shortMessage: string, options?: { cause?: Error; details?: string }) {\n const message = [\n shortMessage,\n options?.details ? `\\n${options.details}` : \"\",\n ].join(\"\");\n\n super(message, { cause: options?.cause });\n this.shortMessage = shortMessage;\n this.details = options?.details;\n }\n\n toJSON() {\n return {\n name: this.name,\n message: this.message,\n shortMessage: this.shortMessage,\n details: this.details,\n cause: this.cause instanceof Error ? this.cause.message : undefined,\n };\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAAO,MAAM,kBAAkB,MAAM;AAAA,EAC1B,OAAO;AAAA,EAChB;AAAA,EACA;AAAA,EAEA,WAAW,CAAC,cAAsB,SAA+C;AAAA,IAC/E,MAAM,UAAU;AAAA,MACd;AAAA,MACA,SAAS,UAAU;AAAA,EAAK,QAAQ,YAAY;AAAA,IAC9C,EAAE,KAAK,EAAE;AAAA,IAET,MAAM,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,IACxC,KAAK,eAAe;AAAA,IACpB,KAAK,UAAU,SAAS;AAAA;AAAA,EAG1B,MAAM,GAAG;AAAA,IACP,OAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,MACd,OAAO,KAAK,iBAAiB,QAAQ,KAAK,MAAM,UAAU;AAAA,IAC5D;AAAA;AAEJ;",
|
|
8
|
+
"debugId": "DEA222C2A831257D64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
c32addressDecode
|
|
3
|
+
} from "./stacks-nqytwfcc.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/address.ts
|
|
6
|
+
function validateStacksAddress(address) {
|
|
7
|
+
try {
|
|
8
|
+
c32addressDecode(address);
|
|
9
|
+
return true;
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
var isValidAddress = validateStacksAddress;
|
|
15
|
+
function parseContractId(contractId) {
|
|
16
|
+
const [address, name] = contractId.split(".");
|
|
17
|
+
if (!address || !name)
|
|
18
|
+
throw new Error(`Invalid contract identifier: ${contractId}`);
|
|
19
|
+
return [address, name];
|
|
20
|
+
}
|
|
21
|
+
function isClarityName(name) {
|
|
22
|
+
const regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;
|
|
23
|
+
return regex.test(name) && name.length < 128;
|
|
24
|
+
}
|
|
25
|
+
function isAddressEqual(a, b) {
|
|
26
|
+
const [versionA, hashA] = c32addressDecode(a);
|
|
27
|
+
const [versionB, hashB] = c32addressDecode(b);
|
|
28
|
+
return versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
function addressToVersion(address) {
|
|
31
|
+
return c32addressDecode(address)[0];
|
|
32
|
+
}
|
|
33
|
+
function getContractAddress(deployer, contractName) {
|
|
34
|
+
if (!validateStacksAddress(deployer)) {
|
|
35
|
+
throw new Error(`Invalid deployer address: ${deployer}`);
|
|
36
|
+
}
|
|
37
|
+
if (!isClarityName(contractName)) {
|
|
38
|
+
throw new Error(`Invalid contract name: ${contractName}`);
|
|
39
|
+
}
|
|
40
|
+
return `${deployer}.${contractName}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { validateStacksAddress, isValidAddress, parseContractId, isClarityName, isAddressEqual, addressToVersion, getContractAddress };
|
|
44
|
+
|
|
45
|
+
//# debugId=899D2CA267B89FE364756E2164756E21
|
|
46
|
+
//# sourceMappingURL=stacks-gjvbq6w7.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/utils/address.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { c32address, c32addressDecode } from \"./c32.ts\";\n\nexport { c32address, c32addressDecode };\n\nexport function validateStacksAddress(address: string): boolean {\n try {\n c32addressDecode(address);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Alias for validateStacksAddress — matches future.md naming. */\nexport const isValidAddress = validateStacksAddress;\n\nexport function parseContractId(contractId: string): [string, string] {\n const [address, name] = contractId.split(\".\");\n if (!address || !name)\n throw new Error(`Invalid contract identifier: ${contractId}`);\n return [address, name];\n}\n\nexport function isClarityName(name: string): boolean {\n const regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;\n return regex.test(name) && name.length < 128;\n}\n\n/**\n * Compare two Stacks addresses for equality (case-insensitive, version-aware).\n * Throws if either address is invalid.\n */\nexport function isAddressEqual(a: string, b: string): boolean {\n const [versionA, hashA] = c32addressDecode(a);\n const [versionB, hashB] = c32addressDecode(b);\n return versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();\n}\n\n/** Extract the version byte from a Stacks address (22, 20, 26, or 21). */\nexport function addressToVersion(address: string): number {\n return c32addressDecode(address)[0];\n}\n\n/**\n * Build a contract address from deployer + contract name.\n * Validates both parts; returns `deployer.contractName`.\n */\nexport function getContractAddress(deployer: string, contractName: string): string {\n if (!validateStacksAddress(deployer)) {\n throw new Error(`Invalid deployer address: ${deployer}`);\n }\n if (!isClarityName(contractName)) {\n throw new Error(`Invalid contract name: ${contractName}`);\n }\n return `${deployer}.${contractName}`;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;AAIO,SAAS,qBAAqB,CAAC,SAA0B;AAAA,EAC9D,IAAI;AAAA,IACF,iBAAiB,OAAO;AAAA,IACxB,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA;AAAA;AAKJ,IAAM,iBAAiB;AAEvB,SAAS,eAAe,CAAC,YAAsC;AAAA,EACpE,OAAO,SAAS,QAAQ,WAAW,MAAM,GAAG;AAAA,EAC5C,IAAI,CAAC,WAAW,CAAC;AAAA,IACf,MAAM,IAAI,MAAM,gCAAgC,YAAY;AAAA,EAC9D,OAAO,CAAC,SAAS,IAAI;AAAA;AAGhB,SAAS,aAAa,CAAC,MAAuB;AAAA,EACnD,MAAM,QAAQ;AAAA,EACd,OAAO,MAAM,KAAK,IAAI,KAAK,KAAK,SAAS;AAAA;AAOpC,SAAS,cAAc,CAAC,GAAW,GAAoB;AAAA,EAC5D,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,aAAa,YAAY,MAAM,YAAY,MAAM,MAAM,YAAY;AAAA;AAIrE,SAAS,gBAAgB,CAAC,SAAyB;AAAA,EACxD,OAAO,iBAAiB,OAAO,EAAE;AAAA;AAO5B,SAAS,kBAAkB,CAAC,UAAkB,cAA8B;AAAA,EACjF,IAAI,CAAC,sBAAsB,QAAQ,GAAG;AAAA,IACpC,MAAM,IAAI,MAAM,6BAA6B,UAAU;AAAA,EACzD;AAAA,EACA,IAAI,CAAC,cAAc,YAAY,GAAG;AAAA,IAChC,MAAM,IAAI,MAAM,0BAA0B,cAAc;AAAA,EAC1D;AAAA,EACA,OAAO,GAAG,YAAY;AAAA;",
|
|
8
|
+
"debugId": "899D2CA267B89FE364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|