@secondlayer/stacks 0.2.1 → 0.3.0
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-02actsrx.cjs.map +2 -2
- package/dist/shared/{stacks-vyb9rx8q.js → stacks-09wa7ewe.js} +125 -115
- package/dist/shared/stacks-09wa7ewe.js.map +15 -0
- package/dist/shared/{stacks-ky14tdf6.cjs → stacks-0nfexv24.cjs} +20 -8
- package/dist/shared/stacks-0nfexv24.cjs.map +14 -0
- package/dist/shared/{stacks-an5k8n4t.cjs → stacks-14pgpkrr.cjs} +82 -73
- package/dist/shared/stacks-14pgpkrr.cjs.map +23 -0
- package/dist/shared/{stacks-vbke9mqw.cjs → stacks-17sdtaxg.cjs} +120 -106
- package/dist/shared/stacks-17sdtaxg.cjs.map +15 -0
- package/dist/shared/{stacks-wrb1es85.js → stacks-1s5w4ncf.js} +46 -34
- package/dist/shared/stacks-1s5w4ncf.js.map +17 -0
- package/dist/shared/stacks-24h5k94q.cjs.map +3 -3
- package/dist/shared/{stacks-evnzth1q.cjs → stacks-4vzmhw3q.cjs} +3 -3
- package/dist/shared/stacks-4vzmhw3q.cjs.map +10 -0
- package/dist/shared/{stacks-vd9jcp0b.js → stacks-4x2bcc2k.js} +89 -80
- package/dist/shared/stacks-4x2bcc2k.js.map +23 -0
- package/dist/shared/stacks-5tprhns9.cjs.map +3 -3
- package/dist/shared/stacks-709tra19.js.map +2 -2
- package/dist/shared/{stacks-qcx67vqa.js → stacks-70p84bgg.js} +3 -3
- package/dist/shared/stacks-70p84bgg.js.map +10 -0
- package/dist/shared/{stacks-k2p5tv6x.js → stacks-913a2rx7.js} +3 -3
- package/dist/shared/stacks-913a2rx7.js.map +10 -0
- package/dist/shared/{stacks-qyt8m5v0.js → stacks-96d6m1zy.js} +16 -7
- package/dist/shared/stacks-96d6m1zy.js.map +11 -0
- package/dist/shared/stacks-9g0jhab3.cjs.map +2 -2
- package/dist/shared/stacks-dr5en54r.cjs.map +2 -2
- package/dist/shared/stacks-fcaefc5b.cjs.map +2 -2
- package/dist/shared/stacks-gck1sq7h.cjs.map +2 -2
- package/dist/shared/{stacks-yfveb68e.js → stacks-je937aas.js} +3 -3
- package/dist/shared/stacks-je937aas.js.map +10 -0
- package/dist/shared/{stacks-k58k970n.js → stacks-kg1npstf.js} +5 -3
- package/dist/shared/stacks-kg1npstf.js.map +10 -0
- package/dist/shared/{stacks-qvg7c24g.cjs → stacks-n98w7g57.cjs} +5 -3
- package/dist/shared/stacks-n98w7g57.cjs.map +10 -0
- package/dist/shared/{stacks-9mdk86wp.js → stacks-nqae5amn.cjs} +77 -159
- package/dist/shared/stacks-nqae5amn.cjs.map +10 -0
- package/dist/shared/stacks-qcae5852.js.map +2 -2
- package/dist/shared/stacks-qt8ehebn.js.map +3 -3
- package/dist/shared/{stacks-r1t6g3c3.cjs → stacks-ra02bpny.cjs} +8 -3
- package/dist/shared/stacks-ra02bpny.cjs.map +11 -0
- package/dist/shared/{stacks-bycy6t9k.js → stacks-rwfgts3s.js} +2 -2
- package/dist/shared/{stacks-bycy6t9k.js.map → stacks-rwfgts3s.js.map} +2 -2
- package/dist/shared/{stacks-gjvbq6w7.js → stacks-s10yb9gz.js} +2 -2
- package/dist/shared/stacks-s10yb9gz.js.map +10 -0
- package/dist/shared/{stacks-v3zy6zds.cjs → stacks-s30kkvm8.js} +104 -117
- package/dist/shared/stacks-s30kkvm8.js.map +10 -0
- package/dist/shared/{stacks-nqytwfcc.js → stacks-s7z5q8be.js} +8 -3
- package/dist/shared/stacks-s7z5q8be.js.map +11 -0
- package/dist/shared/stacks-v9jqcpd4.js.map +2 -2
- package/dist/shared/stacks-vdfag81a.cjs.map +2 -2
- package/dist/shared/{stacks-fedzr2ka.js → stacks-wjem3xw9.js} +23 -11
- package/dist/shared/stacks-wjem3xw9.js.map +14 -0
- package/dist/shared/{stacks-k08tgzyp.cjs → stacks-wyxj879g.cjs} +3 -3
- package/dist/shared/stacks-wyxj879g.cjs.map +13 -0
- package/dist/shared/stacks-y3dh7hv1.js.map +3 -3
- package/dist/shared/{stacks-2ar4prfz.cjs → stacks-y5262j0z.cjs} +14 -5
- package/dist/shared/stacks-y5262j0z.cjs.map +11 -0
- package/dist/shared/stacks-ya3x01yd.cjs.map +2 -2
- package/dist/shared/{stacks-9avax1yf.js → stacks-zf7rbpzp.js} +5 -5
- package/dist/shared/stacks-zf7rbpzp.js.map +13 -0
- package/dist/shared/{stacks-61rvzkz1.cjs → stacks-znrb59ce.cjs} +41 -29
- package/dist/shared/stacks-znrb59ce.cjs.map +17 -0
- package/dist/src/accounts/index.cjs +2 -2
- package/dist/src/accounts/index.cjs.map +5 -5
- package/dist/src/accounts/index.js +4 -8
- package/dist/src/accounts/index.js.map +5 -5
- package/dist/src/actions/index.d.cts +36 -29
- package/dist/src/actions/index.d.ts +36 -29
- package/dist/src/actions/index.js +10 -10
- package/dist/src/bns/index.cjs +55 -43
- package/dist/src/bns/index.cjs.map +9 -9
- package/dist/src/bns/index.d.cts +29 -29
- package/dist/src/bns/index.d.ts +29 -29
- package/dist/src/bns/index.js +66 -54
- package/dist/src/bns/index.js.map +9 -9
- package/dist/src/clarity/index.js +6 -6
- package/dist/src/connect/index.cjs +114 -112
- package/dist/src/connect/index.cjs.map +13 -13
- package/dist/src/connect/index.js +114 -112
- package/dist/src/connect/index.js.map +13 -13
- package/dist/src/connect/walletconnect/index.cjs +3 -3
- package/dist/src/connect/walletconnect/index.cjs.map +10 -10
- package/dist/src/connect/walletconnect/index.js +3 -3
- package/dist/src/connect/walletconnect/index.js.map +10 -10
- package/dist/src/index.cjs +108 -2
- package/dist/src/index.cjs.map +19 -15
- package/dist/src/index.d.cts +298 -112
- package/dist/src/index.d.ts +298 -112
- package/dist/src/index.js +125 -12
- package/dist/src/index.js.map +19 -15
- package/dist/src/postconditions/index.js +3 -3
- package/dist/src/pox/index.cjs.map +6 -6
- package/dist/src/pox/index.d.cts +29 -29
- package/dist/src/pox/index.d.ts +29 -29
- package/dist/src/pox/index.js +9 -9
- package/dist/src/pox/index.js.map +6 -6
- package/dist/src/stackingdao/index.cjs +31 -6
- package/dist/src/stackingdao/index.cjs.map +6 -6
- package/dist/src/stackingdao/index.d.cts +29 -29
- package/dist/src/stackingdao/index.d.ts +29 -29
- package/dist/src/stackingdao/index.js +41 -16
- package/dist/src/stackingdao/index.js.map +6 -6
- package/dist/src/subscriptions/index.d.cts +29 -29
- package/dist/src/subscriptions/index.d.ts +29 -29
- package/dist/src/tools/btc/index.cjs +130 -0
- package/dist/src/tools/btc/index.cjs.map +10 -0
- package/dist/src/tools/btc/index.d.cts +8 -0
- package/dist/src/tools/btc/index.d.ts +8 -0
- package/dist/src/tools/btc/index.js +89 -0
- package/dist/src/tools/btc/index.js.map +10 -0
- package/dist/src/tools/index.cjs +2470 -0
- package/dist/src/tools/index.cjs.map +61 -0
- package/dist/src/tools/index.d.cts +144 -0
- package/dist/src/tools/index.d.ts +144 -0
- package/dist/src/tools/index.js +2435 -0
- package/dist/src/tools/index.js.map +61 -0
- package/dist/src/transactions/index.d.cts +7 -0
- package/dist/src/transactions/index.d.ts +7 -0
- package/dist/src/transactions/index.js +6 -6
- package/dist/src/triggers/index.cjs +66 -0
- package/dist/src/triggers/index.cjs.map +10 -0
- package/dist/src/triggers/index.d.cts +116 -0
- package/dist/src/triggers/index.d.ts +116 -0
- package/dist/src/triggers/index.js +25 -0
- package/dist/src/triggers/index.js.map +10 -0
- package/dist/src/tx/index.cjs +65 -0
- package/dist/src/tx/index.cjs.map +10 -0
- package/dist/src/tx/index.d.cts +42 -0
- package/dist/src/tx/index.d.ts +42 -0
- package/dist/src/tx/index.js +22 -0
- package/dist/src/tx/index.js.map +10 -0
- package/dist/src/ui/index.cjs +431 -0
- package/dist/src/ui/index.cjs.map +27 -0
- package/dist/src/ui/index.d.cts +107 -0
- package/dist/src/ui/index.d.ts +107 -0
- package/dist/src/ui/index.js +391 -0
- package/dist/src/ui/index.js.map +27 -0
- package/dist/src/ui/schemas.cjs +134 -0
- package/dist/src/ui/schemas.cjs.map +18 -0
- package/dist/src/ui/schemas.d.cts +83 -0
- package/dist/src/ui/schemas.d.ts +83 -0
- package/dist/src/ui/schemas.js +91 -0
- package/dist/src/ui/schemas.js.map +18 -0
- package/dist/src/utils/index.cjs +3 -3
- package/dist/src/utils/index.cjs.map +4 -4
- package/dist/src/utils/index.js +7 -7
- package/dist/src/utils/index.js.map +4 -4
- package/package.json +157 -105
- package/dist/shared/stacks-2ar4prfz.cjs.map +0 -11
- package/dist/shared/stacks-61rvzkz1.cjs.map +0 -17
- package/dist/shared/stacks-9avax1yf.js.map +0 -13
- package/dist/shared/stacks-9mdk86wp.js.map +0 -10
- package/dist/shared/stacks-an5k8n4t.cjs.map +0 -23
- package/dist/shared/stacks-evnzth1q.cjs.map +0 -10
- package/dist/shared/stacks-fedzr2ka.js.map +0 -13
- package/dist/shared/stacks-gjvbq6w7.js.map +0 -10
- package/dist/shared/stacks-k08tgzyp.cjs.map +0 -13
- package/dist/shared/stacks-k2p5tv6x.js.map +0 -10
- package/dist/shared/stacks-k58k970n.js.map +0 -10
- package/dist/shared/stacks-ky14tdf6.cjs.map +0 -13
- package/dist/shared/stacks-nqytwfcc.js.map +0 -11
- package/dist/shared/stacks-qcx67vqa.js.map +0 -10
- package/dist/shared/stacks-qvg7c24g.cjs.map +0 -10
- package/dist/shared/stacks-qyt8m5v0.js.map +0 -11
- package/dist/shared/stacks-r1t6g3c3.cjs.map +0 -11
- package/dist/shared/stacks-v3zy6zds.cjs.map +0 -10
- package/dist/shared/stacks-vbke9mqw.cjs.map +0 -15
- package/dist/shared/stacks-vd9jcp0b.js.map +0 -23
- package/dist/shared/stacks-vyb9rx8q.js.map +0 -15
- package/dist/shared/stacks-wrb1es85.js.map +0 -17
- package/dist/shared/stacks-yfveb68e.js.map +0 -10
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
isProviderAccount,
|
|
5
5
|
readContract,
|
|
6
6
|
sendTransaction
|
|
7
|
-
} from "./stacks-
|
|
7
|
+
} from "./stacks-1s5w4ncf.js";
|
|
8
8
|
import {
|
|
9
9
|
BaseError
|
|
10
10
|
} from "./stacks-709tra19.js";
|
|
11
11
|
import {
|
|
12
12
|
deserializeTransaction
|
|
13
|
-
} from "./stacks-
|
|
13
|
+
} from "./stacks-s30kkvm8.js";
|
|
14
14
|
import {
|
|
15
15
|
AddressHashMode,
|
|
16
16
|
AuthType,
|
|
@@ -22,34 +22,28 @@ import {
|
|
|
22
22
|
signMultiSigWithAccount,
|
|
23
23
|
signSponsorWithAccount,
|
|
24
24
|
signTransactionWithAccount
|
|
25
|
-
} from "./stacks-
|
|
25
|
+
} from "./stacks-09wa7ewe.js";
|
|
26
26
|
import {
|
|
27
27
|
Cl,
|
|
28
28
|
deserializeCVBytes,
|
|
29
29
|
serializeCVBytes
|
|
30
|
-
} from "./stacks-
|
|
30
|
+
} from "./stacks-wjem3xw9.js";
|
|
31
31
|
import {
|
|
32
32
|
parseContractId
|
|
33
|
-
} from "./stacks-
|
|
33
|
+
} from "./stacks-s10yb9gz.js";
|
|
34
34
|
import {
|
|
35
35
|
bytesToHex,
|
|
36
36
|
c32address,
|
|
37
37
|
concatBytes,
|
|
38
38
|
intToBigInt,
|
|
39
39
|
with0x
|
|
40
|
-
} from "./stacks-
|
|
41
|
-
|
|
42
|
-
// src/actions/public/getBalance.ts
|
|
43
|
-
async function getBalance(client, params) {
|
|
44
|
-
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
45
|
-
method: "GET"
|
|
46
|
-
});
|
|
47
|
-
return BigInt(data.balance);
|
|
48
|
-
}
|
|
40
|
+
} from "./stacks-s7z5q8be.js";
|
|
49
41
|
|
|
50
42
|
// src/actions/public/getAccountInfo.ts
|
|
51
43
|
async function getAccountInfo(client, params) {
|
|
52
|
-
const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
|
|
44
|
+
const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
|
|
45
|
+
method: "GET"
|
|
46
|
+
});
|
|
53
47
|
return {
|
|
54
48
|
balance: BigInt(data.balance),
|
|
55
49
|
nonce: BigInt(data.nonce),
|
|
@@ -58,13 +52,25 @@ async function getAccountInfo(client, params) {
|
|
|
58
52
|
};
|
|
59
53
|
}
|
|
60
54
|
|
|
55
|
+
// src/actions/public/getBalance.ts
|
|
56
|
+
async function getBalance(client, params) {
|
|
57
|
+
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
58
|
+
method: "GET"
|
|
59
|
+
});
|
|
60
|
+
return BigInt(data.balance);
|
|
61
|
+
}
|
|
62
|
+
|
|
61
63
|
// src/actions/public/getBlock.ts
|
|
62
64
|
async function getBlock(client, params) {
|
|
63
65
|
if (params?.hash) {
|
|
64
|
-
return client.request(`/extended/v2/blocks/${params.hash}`, {
|
|
66
|
+
return client.request(`/extended/v2/blocks/${params.hash}`, {
|
|
67
|
+
method: "GET"
|
|
68
|
+
});
|
|
65
69
|
}
|
|
66
70
|
if (params?.height !== undefined) {
|
|
67
|
-
return client.request(`/extended/v2/blocks/${params.height}`, {
|
|
71
|
+
return client.request(`/extended/v2/blocks/${params.height}`, {
|
|
72
|
+
method: "GET"
|
|
73
|
+
});
|
|
68
74
|
}
|
|
69
75
|
return client.request("/extended/v2/blocks?limit=1", { method: "GET" });
|
|
70
76
|
}
|
|
@@ -88,7 +94,10 @@ async function multicall(client, params) {
|
|
|
88
94
|
const { calls, allowFailure = true } = params;
|
|
89
95
|
if (allowFailure) {
|
|
90
96
|
const settled = await Promise.allSettled(calls.map((call) => readContract(client, call)));
|
|
91
|
-
return settled.map((r) => r.status === "fulfilled" ? { status: "success", result: r.value } : {
|
|
97
|
+
return settled.map((r) => r.status === "fulfilled" ? { status: "success", result: r.value } : {
|
|
98
|
+
status: "failure",
|
|
99
|
+
error: r.reason instanceof Error ? r.reason : new Error(String(r.reason))
|
|
100
|
+
});
|
|
92
101
|
}
|
|
93
102
|
const results = await Promise.all(calls.map((call) => readContract(client, call)));
|
|
94
103
|
return results;
|
|
@@ -166,65 +175,6 @@ async function simulateTransaction(client, params) {
|
|
|
166
175
|
return { type: "token-transfer", fees };
|
|
167
176
|
}
|
|
168
177
|
|
|
169
|
-
// src/actions/wallet/signTransaction.ts
|
|
170
|
-
async function signTransactionAction(client, params) {
|
|
171
|
-
const account = client.account;
|
|
172
|
-
if (!account)
|
|
173
|
-
throw new Error("Account required");
|
|
174
|
-
if (isProviderAccount(account)) {
|
|
175
|
-
const hex = serializeTransactionHex(params.transaction);
|
|
176
|
-
const result = await account.provider.request("stx_signTransaction", {
|
|
177
|
-
transaction: hex
|
|
178
|
-
});
|
|
179
|
-
return deserializeTransaction(result.transaction);
|
|
180
|
-
}
|
|
181
|
-
const condition = params.transaction.auth.spendingCondition;
|
|
182
|
-
if ("fields" in condition) {
|
|
183
|
-
const publicKeys = params.signers ?? params.transaction._multisig?.publicKeys;
|
|
184
|
-
if (!publicKeys)
|
|
185
|
-
throw new Error("Multi-sig signing requires signers (publicKeys)");
|
|
186
|
-
return signMultiSigWithAccount(params.transaction, account, publicKeys);
|
|
187
|
-
}
|
|
188
|
-
return signTransactionWithAccount(params.transaction, account);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/actions/wallet/transferStx.ts
|
|
192
|
-
async function transferStx(client, params) {
|
|
193
|
-
const account = client.account;
|
|
194
|
-
if (!account)
|
|
195
|
-
throw new Error("Account required");
|
|
196
|
-
if (isProviderAccount(account)) {
|
|
197
|
-
const result2 = await account.provider.request("stx_transferStx", {
|
|
198
|
-
recipient: params.to,
|
|
199
|
-
amount: String(params.amount),
|
|
200
|
-
memo: params.memo
|
|
201
|
-
});
|
|
202
|
-
return result2.txid;
|
|
203
|
-
}
|
|
204
|
-
const nonce = params.nonce ?? await getNonce(client, { address: account.address });
|
|
205
|
-
const unsigned = buildTokenTransfer({
|
|
206
|
-
recipient: params.to,
|
|
207
|
-
amount: params.amount,
|
|
208
|
-
memo: params.memo,
|
|
209
|
-
fee: params.fee ?? 0n,
|
|
210
|
-
nonce,
|
|
211
|
-
publicKey: account.publicKey,
|
|
212
|
-
chain: client.chain,
|
|
213
|
-
postConditionMode: params.postConditionMode,
|
|
214
|
-
postConditions: params.postConditions
|
|
215
|
-
});
|
|
216
|
-
if (params.fee === undefined) {
|
|
217
|
-
const estimates = await estimateFee(client, { transaction: unsigned });
|
|
218
|
-
const mid = estimates[1] ?? estimates[0];
|
|
219
|
-
if (mid) {
|
|
220
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
const signed = await signTransactionWithAccount(unsigned, account);
|
|
224
|
-
const result = await sendTransaction(client, { transaction: signed });
|
|
225
|
-
return result.txid;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
178
|
// src/actions/wallet/deployContract.ts
|
|
229
179
|
async function deployContract(client, params) {
|
|
230
180
|
const account = client.account;
|
|
@@ -295,6 +245,28 @@ async function signMessage(client, params) {
|
|
|
295
245
|
return bytesToHex(sigBytes);
|
|
296
246
|
}
|
|
297
247
|
|
|
248
|
+
// src/actions/wallet/signTransaction.ts
|
|
249
|
+
async function signTransactionAction(client, params) {
|
|
250
|
+
const account = client.account;
|
|
251
|
+
if (!account)
|
|
252
|
+
throw new Error("Account required");
|
|
253
|
+
if (isProviderAccount(account)) {
|
|
254
|
+
const hex = serializeTransactionHex(params.transaction);
|
|
255
|
+
const result = await account.provider.request("stx_signTransaction", {
|
|
256
|
+
transaction: hex
|
|
257
|
+
});
|
|
258
|
+
return deserializeTransaction(result.transaction);
|
|
259
|
+
}
|
|
260
|
+
const condition = params.transaction.auth.spendingCondition;
|
|
261
|
+
if ("fields" in condition) {
|
|
262
|
+
const publicKeys = params.signers ?? params.transaction._multisig?.publicKeys;
|
|
263
|
+
if (!publicKeys)
|
|
264
|
+
throw new Error("Multi-sig signing requires signers (publicKeys)");
|
|
265
|
+
return signMultiSigWithAccount(params.transaction, account, publicKeys);
|
|
266
|
+
}
|
|
267
|
+
return signTransactionWithAccount(params.transaction, account);
|
|
268
|
+
}
|
|
269
|
+
|
|
298
270
|
// src/actions/wallet/sponsorTransaction.ts
|
|
299
271
|
async function sponsorTransaction(client, params) {
|
|
300
272
|
const { transaction } = params;
|
|
@@ -328,7 +300,44 @@ async function sponsorTransaction(client, params) {
|
|
|
328
300
|
return signSponsorWithAccount(sponsored, account);
|
|
329
301
|
}
|
|
330
302
|
|
|
331
|
-
|
|
303
|
+
// src/actions/wallet/transferStx.ts
|
|
304
|
+
async function transferStx(client, params) {
|
|
305
|
+
const account = client.account;
|
|
306
|
+
if (!account)
|
|
307
|
+
throw new Error("Account required");
|
|
308
|
+
if (isProviderAccount(account)) {
|
|
309
|
+
const result2 = await account.provider.request("stx_transferStx", {
|
|
310
|
+
recipient: params.to,
|
|
311
|
+
amount: String(params.amount),
|
|
312
|
+
memo: params.memo
|
|
313
|
+
});
|
|
314
|
+
return result2.txid;
|
|
315
|
+
}
|
|
316
|
+
const nonce = params.nonce ?? await getNonce(client, { address: account.address });
|
|
317
|
+
const unsigned = buildTokenTransfer({
|
|
318
|
+
recipient: params.to,
|
|
319
|
+
amount: params.amount,
|
|
320
|
+
memo: params.memo,
|
|
321
|
+
fee: params.fee ?? 0n,
|
|
322
|
+
nonce,
|
|
323
|
+
publicKey: account.publicKey,
|
|
324
|
+
chain: client.chain,
|
|
325
|
+
postConditionMode: params.postConditionMode,
|
|
326
|
+
postConditions: params.postConditions
|
|
327
|
+
});
|
|
328
|
+
if (params.fee === undefined) {
|
|
329
|
+
const estimates = await estimateFee(client, { transaction: unsigned });
|
|
330
|
+
const mid = estimates[1] ?? estimates[0];
|
|
331
|
+
if (mid) {
|
|
332
|
+
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const signed = await signTransactionWithAccount(unsigned, account);
|
|
336
|
+
const result = await sendTransaction(client, { transaction: signed });
|
|
337
|
+
return result.txid;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export { getAccountInfo, getBalance, getBlock, getBlockHeight, getContractAbi, multicall, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, sponsorTransaction, transferStx };
|
|
332
341
|
|
|
333
|
-
//# debugId=
|
|
334
|
-
//# sourceMappingURL=stacks-
|
|
342
|
+
//# debugId=2EBBCEC91C51892B64756E2164756E21
|
|
343
|
+
//# sourceMappingURL=stacks-4x2bcc2k.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/public/getAccountInfo.ts", "../src/actions/public/getBalance.ts", "../src/actions/public/getBlock.ts", "../src/actions/public/getBlockHeight.ts", "../src/actions/public/getContractAbi.ts", "../src/actions/public/multicall.ts", "../src/errors/simulation.ts", "../src/actions/public/simulateCall.ts", "../src/actions/public/simulateTransaction.ts", "../src/actions/wallet/deployContract.ts", "../src/actions/wallet/signMessage.ts", "../src/actions/wallet/signTransaction.ts", "../src/actions/wallet/sponsorTransaction.ts", "../src/actions/wallet/transferStx.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetAccountInfoParams = {\n\taddress: string;\n};\n\nexport type AccountInfo = {\n\tbalance: bigint;\n\tnonce: bigint;\n\tbalanceProof: string;\n\tnonceProof: string;\n};\n\nexport async function getAccountInfo(\n\tclient: Client,\n\tparams: GetAccountInfoParams,\n): Promise<AccountInfo> {\n\tconst data = await client.request(`/v2/accounts/${params.address}?proof=1`, {\n\t\tmethod: \"GET\",\n\t});\n\treturn {\n\t\tbalance: BigInt(data.balance),\n\t\tnonce: BigInt(data.nonce),\n\t\tbalanceProof: data.balance_proof ?? \"\",\n\t\tnonceProof: data.nonce_proof ?? \"\",\n\t};\n}\n",
|
|
6
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBalanceParams = {\n\taddress: string;\n};\n\nexport async function getBalance(\n\tclient: Client,\n\tparams: GetBalanceParams,\n): Promise<bigint> {\n\tconst data = await client.request(`/v2/accounts/${params.address}`, {\n\t\tmethod: \"GET\",\n\t});\n\treturn BigInt(data.balance);\n}\n",
|
|
7
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBlockParams = {\n\theight?: number;\n\thash?: string;\n};\n\nexport async function getBlock(\n\tclient: Client,\n\tparams?: GetBlockParams,\n): Promise<any> {\n\tif (params?.hash) {\n\t\treturn client.request(`/extended/v2/blocks/${params.hash}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\tif (params?.height !== undefined) {\n\t\treturn client.request(`/extended/v2/blocks/${params.height}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\t// Latest block\n\treturn client.request(\"/extended/v2/blocks?limit=1\", { method: \"GET\" });\n}\n",
|
|
8
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport async function getBlockHeight(client: Client): Promise<number> {\n\tconst data = await client.request(\"/v2/info\", { method: \"GET\" });\n\treturn data.stacks_tip_height;\n}\n",
|
|
9
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetContractAbiParams = {\n\tcontract: string; // \"address.name\"\n};\n\nexport async function getContractAbi(\n\tclient: Client,\n\tparams: GetContractAbiParams,\n): Promise<any> {\n\tconst [address, name] = parseContractId(params.contract);\n\treturn client.request(`/v2/contracts/interface/${address}/${name}`, {\n\t\tmethod: \"GET\",\n\t});\n}\n",
|
|
10
|
+
"import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { readContract } from \"./readContract.ts\";\n\nexport type MulticallCall = {\n\tcontract: string;\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n};\n\nexport type MulticallParams<TAllowFailure extends boolean = true> = {\n\tcalls: readonly MulticallCall[];\n\tallowFailure?: TAllowFailure;\n};\n\nexport type MulticallSuccessResult = {\n\tstatus: \"success\";\n\tresult: ClarityValue;\n};\nexport type MulticallFailureResult = { status: \"failure\"; error: Error };\n\nexport type MulticallResult<T extends boolean> = T extends true\n\t? (MulticallSuccessResult | MulticallFailureResult)[]\n\t: ClarityValue[];\n\nexport async function multicall<TAllowFailure extends boolean = true>(\n\tclient: Client,\n\tparams: MulticallParams<TAllowFailure>,\n): Promise<MulticallResult<TAllowFailure>> {\n\tconst { calls, allowFailure = true } = params;\n\n\tif (allowFailure) {\n\t\tconst settled = await Promise.allSettled(\n\t\t\tcalls.map((call) => readContract(client, call)),\n\t\t);\n\t\treturn settled.map((r) =>\n\t\t\tr.status === \"fulfilled\"\n\t\t\t\t? { status: \"success\" as const, result: r.value }\n\t\t\t\t: {\n\t\t\t\t\t\tstatus: \"failure\" as const,\n\t\t\t\t\t\terror:\n\t\t\t\t\t\t\tr.reason instanceof Error\n\t\t\t\t\t\t\t\t? r.reason\n\t\t\t\t\t\t\t\t: new Error(String(r.reason)),\n\t\t\t\t\t},\n\t\t) as MulticallResult<TAllowFailure>;\n\t}\n\n\tconst results = await Promise.all(\n\t\tcalls.map((call) => readContract(client, call)),\n\t);\n\treturn results as MulticallResult<TAllowFailure>;\n}\n",
|
|
11
|
+
"import { BaseError } from \"./base.ts\";\n\nexport class SimulationError extends BaseError {\n\toverride name = \"SimulationError\";\n\twritesDetected: boolean;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { writesDetected: boolean; details?: string },\n\t) {\n\t\tsuper(message, { details: options.details });\n\t\tthis.writesDetected = options.writesDetected;\n\t}\n}\n",
|
|
12
|
+
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { SimulationError } from \"../../errors/simulation.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type SimulateCallParams = {\n\tcontract: string;\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateCallSuccess = { success: true; result: ClarityValue };\nexport type SimulateCallFailure = { success: false; error: SimulationError };\nexport type SimulateCallResult = SimulateCallSuccess | SimulateCallFailure;\n\nexport async function simulateCall(\n\tclient: Client,\n\tparams: SimulateCallParams,\n): Promise<SimulateCallResult> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst sender = params.sender ?? address;\n\n\tconst serializedArgs = (params.args ?? []).map((arg) =>\n\t\twith0x(bytesToHex(serializeCVBytes(arg))),\n\t);\n\n\tlet path = `/v2/contracts/call-read/${address}/${name}/${params.functionName}`;\n\tif (params.tip) {\n\t\tpath += `?tip=${params.tip}`;\n\t}\n\n\tconst data = await client.request(path, {\n\t\tmethod: \"POST\",\n\t\tbody: {\n\t\t\tsender,\n\t\t\targuments: serializedArgs,\n\t\t},\n\t});\n\n\tif (data.okay) {\n\t\treturn { success: true, result: deserializeCVBytes(data.result) };\n\t}\n\n\tconst cause: string = data.cause ?? \"Simulation failed\";\n\tconst writesDetected =\n\t\tcause.includes(\"NotReadOnly\") || cause.includes(\"CostBalanceExceeded\");\n\n\treturn {\n\t\tsuccess: false,\n\t\terror: new SimulationError(\n\t\t\twritesDetected\n\t\t\t\t? \"Function mutates state and cannot be simulated\"\n\t\t\t\t: \"Simulation failed\",\n\t\t\t{ writesDetected, details: cause },\n\t\t),\n\t};\n}\n",
|
|
13
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { AddressHashMode, PayloadType } from \"../../transactions/types.ts\";\nimport { c32address } from \"../../utils/address.ts\";\nimport { type FeeEstimation, estimateFee } from \"./estimateFee.ts\";\nimport { type SimulateCallResult, simulateCall } from \"./simulateCall.ts\";\n\nexport type SimulateTransactionParams = {\n\ttransaction: StacksTransaction;\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateContractCallResult = {\n\ttype: \"contract-call\";\n\texecution: SimulateCallResult;\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransferResult = {\n\ttype: \"token-transfer\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateDeployResult = {\n\ttype: \"contract-deploy\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransactionResult =\n\t| SimulateContractCallResult\n\t| SimulateTransferResult\n\t| SimulateDeployResult;\n\nfunction isMultiSig(hashMode: number): boolean {\n\treturn (\n\t\thashMode === AddressHashMode.P2SH ||\n\t\thashMode === AddressHashMode.P2WSH ||\n\t\thashMode === AddressHashMode.P2SH_NonSequential ||\n\t\thashMode === AddressHashMode.P2WSH_P2SH_NonSequential\n\t);\n}\n\nfunction extractSender(tx: StacksTransaction, client: Client): string {\n\tconst { hashMode, signer } = tx.auth.spendingCondition;\n\tconst chain = client.chain;\n\tconst version = isMultiSig(hashMode)\n\t\t? (chain?.addressVersion.multiSig ?? 20)\n\t\t: (chain?.addressVersion.singleSig ?? 22);\n\treturn c32address(version, signer);\n}\n\nexport async function simulateTransaction(\n\tclient: Client,\n\tparams: SimulateTransactionParams,\n): Promise<SimulateTransactionResult> {\n\tconst { transaction, tip } = params;\n\tconst { payload } = transaction;\n\n\tif (payload.payloadType === PayloadType.ContractCall) {\n\t\tconst sender = params.sender ?? extractSender(transaction, client);\n\t\tconst contract = `${payload.contractAddress}.${payload.contractName}`;\n\n\t\tconst [execution, fees] = await Promise.all([\n\t\t\tsimulateCall(client, {\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: payload.functionName,\n\t\t\t\targs: payload.functionArgs,\n\t\t\t\tsender,\n\t\t\t\ttip,\n\t\t\t}),\n\t\t\testimateFee(client, { transaction }),\n\t\t]);\n\n\t\treturn { type: \"contract-call\", execution, fees };\n\t}\n\n\tconst fees = await estimateFee(client, { transaction });\n\n\tif (\n\t\tpayload.payloadType === PayloadType.SmartContract ||\n\t\tpayload.payloadType === PayloadType.VersionedSmartContract\n\t) {\n\t\treturn { type: \"contract-deploy\", fees };\n\t}\n\n\treturn { type: \"token-transfer\", fees };\n}\n",
|
|
14
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractDeploy } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { ClarityVersion } from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { getNonce } from \"../public/getNonce.ts\";\nimport { sendTransaction } from \"./sendTransaction.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type DeployContractParams = {\n\tcontractName: string;\n\tcodeBody: string;\n\tclarityVersion?: ClarityVersion;\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract deploy */\nexport async function deployContract(\n\tclient: Client,\n\tparams: DeployContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst result = await account.provider.request(\"stx_deployContract\", {\n\t\t\tcontractName: params.contractName,\n\t\t\tcodeBody: params.codeBody,\n\t\t\tclarityVersion: params.clarityVersion,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce =\n\t\tparams.nonce ?? (await getNonce(client, { address: account.address }));\n\n\tconst unsigned = buildContractDeploy({\n\t\tcontractName: params.contractName,\n\t\tcodeBody: params.codeBody,\n\t\tclarityVersion: params.clarityVersion,\n\t\tfee: params.fee ?? 0n,\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (params.fee === undefined) {\n\t\tconst estimates = await estimateFee(client, { transaction: unsigned });\n\t\tconst mid = estimates[1] ?? estimates[0];\n\t\tif (mid) {\n\t\t\t(unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n\t\t}\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\tconst result = await sendTransaction(client, { transaction: signed });\n\treturn result.txid;\n}\n",
|
|
15
|
+
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { Cl } from \"../../clarity/values.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { bytesToHex, concatBytes } from \"../../utils/encoding.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignMessageParams = {\n\tmessage: string | ClarityValue;\n\tdomain?: {\n\t\tname: string;\n\t\tversion: string;\n\t\tchainId: number;\n\t};\n};\n\nconst SIP018_PREFIX = new Uint8Array([0x53, 0x49, 0x50, 0x30, 0x31, 0x38]); // \"SIP018\"\n\n/** Sign a structured message per SIP-018 */\nexport async function signMessage(\n\tclient: Client,\n\tparams: SignMessageParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst method = params.domain\n\t\t\t? \"stx_signStructuredMessage\"\n\t\t\t: \"stx_signMessage\";\n\t\tconst result = await account.provider.request(method, {\n\t\t\tmessage: params.message,\n\t\t\tdomain: params.domain,\n\t\t});\n\t\treturn result.signature;\n\t}\n\n\t// Local/Custom: sign locally\n\tconst cv =\n\t\ttypeof params.message === \"string\"\n\t\t\t? Cl.stringAscii(params.message)\n\t\t\t: params.message;\n\n\tconst serializedMsg = serializeCVBytes(cv);\n\n\tlet hash: Uint8Array;\n\n\tif (params.domain) {\n\t\tconst domainCV = Cl.tuple({\n\t\t\tname: Cl.stringAscii(params.domain.name),\n\t\t\tversion: Cl.stringAscii(params.domain.version),\n\t\t\t\"chain-id\": Cl.uint(params.domain.chainId),\n\t\t});\n\t\tconst serializedDomain = serializeCVBytes(domainCV);\n\t\thash = sha256(concatBytes(SIP018_PREFIX, serializedDomain, serializedMsg));\n\t} else {\n\t\thash = sha256(serializedMsg);\n\t}\n\n\tconst sigBytes = await account.sign(hash);\n\treturn bytesToHex(sigBytes);\n}\n",
|
|
16
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport { signMultiSigWithAccount } from \"../../transactions/multisig.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { deserializeTransaction } from \"../../transactions/wire/deserialize.ts\";\nimport { serializeTransactionHex } from \"../../transactions/wire/serialize.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignTransactionParams = {\n\ttransaction: StacksTransaction;\n\t/** Public keys for multi-sig signing (auto-detected from _multisig metadata if omitted) */\n\tsigners?: string[];\n};\n\n/** Sign a transaction using the client's account */\nexport async function signTransactionAction(\n\tclient: Client,\n\tparams: SignTransactionParams,\n): Promise<StacksTransaction> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: send hex to wallet, get signed hex back\n\tif (isProviderAccount(account)) {\n\t\tconst hex = serializeTransactionHex(params.transaction);\n\t\tconst result = await account.provider.request(\"stx_signTransaction\", {\n\t\t\ttransaction: hex,\n\t\t});\n\t\treturn deserializeTransaction(result.transaction);\n\t}\n\n\t// Multi-sig: auto-detect from fields or _multisig metadata\n\tconst condition = params.transaction.auth.spendingCondition;\n\tif (\"fields\" in condition) {\n\t\tconst publicKeys =\n\t\t\tparams.signers ?? (params.transaction as any)._multisig?.publicKeys;\n\t\tif (!publicKeys)\n\t\t\tthrow new Error(\"Multi-sig signing requires signers (publicKeys)\");\n\t\treturn signMultiSigWithAccount(params.transaction, account, publicKeys);\n\t}\n\n\t// Local/Custom: sign with account\n\treturn signTransactionWithAccount(params.transaction, account);\n}\n",
|
|
17
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { getNonce } from \"../public/getNonce.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await getNonce(client, { address: account.address });\n\n\t// Resolve sponsor fee\n\tlet fee: bigint;\n\tif (params.fee != null) {\n\t\tfee = intToBigInt(params.fee);\n\t} else {\n\t\tconst estimates = await estimateFee(client, { transaction });\n\t\tconst mid = estimates[1] ?? estimates[0];\n\t\tfee = mid ? BigInt(mid.fee) : 0n;\n\t}\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n",
|
|
18
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildTokenTransfer } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { getNonce } from \"../public/getNonce.ts\";\nimport { sendTransaction } from \"./sendTransaction.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type TransferStxParams = {\n\tto: string;\n\tamount: IntegerType;\n\tmemo?: string;\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast an STX transfer */\nexport async function transferStx(\n\tclient: Client,\n\tparams: TransferStxParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst result = await account.provider.request(\"stx_transferStx\", {\n\t\t\trecipient: params.to,\n\t\t\tamount: String(params.amount),\n\t\t\tmemo: params.memo,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce =\n\t\tparams.nonce ?? (await getNonce(client, { address: account.address }));\n\n\tconst unsigned = buildTokenTransfer({\n\t\trecipient: params.to,\n\t\tamount: params.amount,\n\t\tmemo: params.memo,\n\t\tfee: params.fee ?? 0n,\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (params.fee === undefined) {\n\t\tconst estimates = await estimateFee(client, { transaction: unsigned });\n\t\tconst mid = estimates[1] ?? estimates[0];\n\t\tif (mid) {\n\t\t\t(unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n\t\t}\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\tconst result = await sendTransaction(client, { transaction: signed });\n\treturn result.txid;\n}\n"
|
|
19
|
+
],
|
|
20
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,eAAsB,cAAc,CACnC,QACA,QACuB;AAAA,EACvB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,mBAAmB;AAAA,IAC3E,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,OAAO;AAAA,IACN,SAAS,OAAO,KAAK,OAAO;AAAA,IAC5B,OAAO,OAAO,KAAK,KAAK;AAAA,IACxB,cAAc,KAAK,iBAAiB;AAAA,IACpC,YAAY,KAAK,eAAe;AAAA,EACjC;AAAA;;;ACnBD,eAAsB,UAAU,CAC/B,QACA,QACkB;AAAA,EAClB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,WAAW;AAAA,IACnE,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,OAAO,OAAO,KAAK,OAAO;AAAA;;;ACN3B,eAAsB,QAAQ,CAC7B,QACA,QACe;AAAA,EACf,IAAI,QAAQ,MAAM;AAAA,IACjB,OAAO,OAAO,QAAQ,uBAAuB,OAAO,QAAQ;AAAA,MAC3D,QAAQ;AAAA,IACT,CAAC;AAAA,EACF;AAAA,EACA,IAAI,QAAQ,WAAW,WAAW;AAAA,IACjC,OAAO,OAAO,QAAQ,uBAAuB,OAAO,UAAU;AAAA,MAC7D,QAAQ;AAAA,IACT,CAAC;AAAA,EACF;AAAA,EAEA,OAAO,OAAO,QAAQ,+BAA+B,EAAE,QAAQ,MAAM,CAAC;AAAA;;;ACpBvE,eAAsB,cAAc,CAAC,QAAiC;AAAA,EACrE,MAAM,OAAO,MAAM,OAAO,QAAQ,YAAY,EAAE,QA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AA,IAClB,QAAQ,OAAO;AAAA,IACf,MAAM,OAAO;AAAA,IACb,KAAK,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,OAAO,QAAQ,WAAW;AAAA,IAC7B,MAAM,YAAY,MAAM,YAAY,QAAQ,EAAE,aAAa,SAAS,CAAC;AAAA,IACrE,MAAM,MAAM,UAAU,MAAM,UAAU;AAAA,IACtC,IAAI,KAAK;AAAA,MACP,SAAS,KAAK,kBAA0B,MAAM,OAAO,IAAI,GAAG;AAAA,IAC9D;AAAA,EACD;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,MAAM,SAAS,MAAM,gBAAgB,QAAQ,EAAE,aAAa,OAAO,CAAC;AAAA,EACpE,OAAO,OAAO;AAAA;",
|
|
21
|
+
"debugId": "2EBBCEC91C51892B64756E2164756E21",
|
|
22
|
+
"names": []
|
|
23
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors/websocket.ts", "../src/subscriptions/actions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { BaseError } from \"./base.ts\";\n\nexport class WebSocketError extends BaseError {\n
|
|
6
|
-
"import type { Client } from \"../clients/types.ts\";\nimport type { WebSocketTransport } from \"../transports/webSocket.ts\";\nimport type {\n
|
|
5
|
+
"import { BaseError } from \"./base.ts\";\n\nexport class WebSocketError extends BaseError {\n\toverride name = \"WebSocketError\";\n\n\tconstructor(message: string, options?: { cause?: Error; details?: string }) {\n\t\tsuper(message, options);\n\t}\n}\n",
|
|
6
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { WebSocketError } from \"../errors/websocket.ts\";\nimport type { WebSocketTransport } from \"../transports/webSocket.ts\";\nimport type {\n\tAddressBalanceNotification,\n\tAddressTxNotification,\n\tBlockNotification,\n\tMempoolNotification,\n\tNftEventNotification,\n\tSubscription,\n\tTxUpdateNotification,\n} from \"./types.ts\";\n\nfunction getWsTransport(client: Client): WebSocketTransport {\n\tif (client.transport.type !== \"webSocket\") {\n\t\tthrow new WebSocketError(\n\t\t\t\"Watch actions require a webSocket transport. Use `webSocket()` when creating your client.\",\n\t\t);\n\t}\n\treturn client.transport as WebSocketTransport;\n}\n\nexport type WatchBlocksParams = {\n\tonBlock: (block: BlockNotification) => void;\n};\n\nexport async function watchBlocks(\n\tclient: Client,\n\tparams: WatchBlocksParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"block\" }, params.onBlock);\n}\n\nexport type WatchMempoolParams = {\n\tonTransaction: (tx: MempoolNotification) => void;\n};\n\nexport async function watchMempool(\n\tclient: Client,\n\tparams: WatchMempoolParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"mempool\" }, params.onTransaction);\n}\n\nexport type WatchTransactionParams = {\n\ttxId: string;\n\tonUpdate: (update: TxUpdateNotification) => void;\n};\n\nexport async function watchTransaction(\n\tclient: Client,\n\tparams: WatchTransactionParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"tx_update\", tx_id: params.txId },\n\t\tparams.onUpdate,\n\t);\n}\n\nexport type WatchAddressParams = {\n\taddress: string;\n\tonTransaction: (tx: AddressTxNotification) => void;\n};\n\nexport async function watchAddress(\n\tclient: Client,\n\tparams: WatchAddressParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_tx_update\", address: params.address },\n\t\tparams.onTransaction,\n\t);\n}\n\nexport type WatchAddressBalanceParams = {\n\taddress: string;\n\tonBalance: (balance: AddressBalanceNotification) => void;\n};\n\nexport async function watchAddressBalance(\n\tclient: Client,\n\tparams: WatchAddressBalanceParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_balance_update\", address: params.address },\n\t\tparams.onBalance,\n\t);\n}\n\nexport type WatchNftEventParams = {\n\tonEvent: (event: NftEventNotification) => void;\n\tassetIdentifier?: string;\n\tvalue?: string;\n};\n\nexport async function watchNftEvent(\n\tclient: Client,\n\tparams: WatchNftEventParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\n\tlet event: \"nft_event\" | \"nft_asset_event\" | \"nft_collection_event\";\n\tif (params.assetIdentifier && params.value) {\n\t\tevent = \"nft_event\";\n\t} else if (params.assetIdentifier) {\n\t\tevent = \"nft_collection_event\";\n\t} else {\n\t\tevent = \"nft_event\";\n\t}\n\n\treturn transport.subscribe(\n\t\t{\n\t\t\tevent,\n\t\t\tasset_identifier: params.assetIdentifier,\n\t\t\tvalue: params.value,\n\t\t},\n\t\tparams.onEvent,\n\t);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";AAEO,MAAM,uBAAuB,UAAU;AAAA,
|
|
8
|
+
"mappings": ";AAEO,MAAM,uBAAuB,UAAU;AAAA,EACpC,OAAO;AAAA,EAEhB,WAAW,CAAC,SAAiB,SAA+C;AAAA,IAC3E,MAAM,SAAS,OAAO;AAAA;AAExB;;;ACKA,SAAS,cAAc,CAAC,QAAoC;AAAA,EAC3D,IAAI,OAAO,UAAU,SAAS,aAAa;AAAA,IAC1C,MAAM,IAAI,eACT,2FACD;AAAA,EACD;AAAA,EACA,OAAO,OAAO;AAAA;AAOf,eAAsB,WAAW,CAChC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EACvC,OAAO,UAAU,UAAU,EAAE,OAAO,QAAQ,GAAG,OAAO,OAAO;AAAA;AAO9D,eAAsB,YAAY,CACjC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EACvC,OAAO,UAAU,UAAU,EAAE,OAAO,UAAU,GAAG,OAAO,aAAa;AAAA;AAQtE,eAAsB,gBAAgB,CACrC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EACvC,OAAO,UAAU,UAChB,EAAE,OAAO,aAAa,OAAO,OAAO,KAAK,GACzC,OAAO,QACR;AAAA;AAQD,eAAsB,YAAY,CACjC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EACvC,OAAO,UAAU,UAChB,EAAE,OAAO,qBAAqB,SAAS,OAAO,QAAQ,GACtD,OAAO,aACR;AAAA;AAQD,eAAsB,mBAAmB,CACxC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EACvC,OAAO,UAAU,UAChB,EAAE,OAAO,0BAA0B,SAAS,OAAO,QAAQ,GAC3D,OAAO,SACR;AAAA;AASD,eAAsB,aAAa,CAClC,QACA,QACwB;AAAA,EACxB,MAAM,YAAY,eAAe,MAAM;AAAA,EAEvC,IAAI;AAAA,EACJ,IAAI,OAAO,mBAAmB,OAAO,OAAO;AAAA,IAC3C,QAAQ;AAAA,EACT,EAAO,SAAI,OAAO,iBAAiB;AAAA,IAClC,QAAQ;AAAA,EACT,EAAO;AAAA,IACN,QAAQ;AAAA;AAAA,EAGT,OAAO,UAAU,UAChB;AAAA,IACC;AAAA,IACA,kBAAkB,OAAO;AAAA,IACzB,OAAO,OAAO;AAAA,EACf,GACA,OAAO,OACR;AAAA;",
|
|
9
9
|
"debugId": "525245790E39F0C764756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors/base.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"export class BaseError extends Error {\n
|
|
5
|
+
"export class BaseError extends Error {\n\toverride name = \"StacksError\";\n\tshortMessage: string;\n\tdetails?: string;\n\n\tconstructor(\n\t\tshortMessage: string,\n\t\toptions?: { cause?: Error; details?: string },\n\t) {\n\t\tconst message = [\n\t\t\tshortMessage,\n\t\t\toptions?.details ? `\\n${options.details}` : \"\",\n\t\t].join(\"\");\n\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.shortMessage = shortMessage;\n\t\tthis.details = options?.details;\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tmessage: string;\n\t\tshortMessage: string;\n\t\tdetails: string | undefined;\n\t\tcause: string | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tshortMessage: this.shortMessage,\n\t\t\tdetails: this.details,\n\t\t\tcause: this.cause instanceof Error ? this.cause.message : undefined,\n\t\t};\n\t}\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAO,MAAM,kBAAkB,MAAM;AAAA,
|
|
7
|
+
"mappings": ";AAAO,MAAM,kBAAkB,MAAM;AAAA,EAC3B,OAAO;AAAA,EAChB;AAAA,EACA;AAAA,EAEA,WAAW,CACV,cACA,SACC;AAAA,IACD,MAAM,UAAU;AAAA,MACf;AAAA,MACA,SAAS,UAAU;AAAA,EAAK,QAAQ,YAAY;AAAA,IAC7C,EAAE,KAAK,EAAE;AAAA,IAET,MAAM,SAAS,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,IACxC,KAAK,eAAe;AAAA,IACpB,KAAK,UAAU,SAAS;AAAA;AAAA,EAGzB,MAAM,GAMJ;AAAA,IACD,OAAO;AAAA,MACN,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,MACd,OAAO,KAAK,iBAAiB,QAAQ,KAAK,MAAM,UAAU;AAAA,IAC3D;AAAA;AAEF;",
|
|
8
8
|
"debugId": "1A3CE4B478FC032D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
callContract,
|
|
3
3
|
getMapEntry,
|
|
4
4
|
readContract
|
|
5
|
-
} from "./stacks-
|
|
5
|
+
} from "./stacks-1s5w4ncf.js";
|
|
6
6
|
import {
|
|
7
7
|
clarityValueToJSUntyped,
|
|
8
8
|
jsToClarityValue,
|
|
9
9
|
toCamelCase
|
|
10
|
-
} from "./stacks-
|
|
10
|
+
} from "./stacks-zf7rbpzp.js";
|
|
11
11
|
|
|
12
12
|
// src/actions/getContract.ts
|
|
13
13
|
function getContract(params) {
|
|
@@ -131,4 +131,4 @@ class ContractResponseError extends Error {
|
|
|
131
131
|
export { getContract, ContractResponseError };
|
|
132
132
|
|
|
133
133
|
//# debugId=C71C39F2B8094B6864756E2164756E21
|
|
134
|
-
//# sourceMappingURL=stacks-
|
|
134
|
+
//# sourceMappingURL=stacks-70p84bgg.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/getContract.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiMap,\n\tAbiType,\n\tExtractFunctionArgs,\n\tExtractFunctionOutput,\n\tExtractMapKey,\n\tExtractMapNames,\n\tExtractMapValue,\n\tExtractPublicFunctions,\n\tExtractReadOnlyFunctions,\n} from \"../clarity/abi/index.ts\";\nimport { type ToCamelCase, toCamelCase } from \"../clarity/abi/utils.ts\";\nimport {\n\tclarityValueToJSUntyped,\n\tjsToClarityValue,\n} from \"../clarity/bridge.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { getMapEntry } from \"./public/getMapEntry.ts\";\nimport { readContract } from \"./public/readContract.ts\";\nimport { callContract } from \"./wallet/callContract.ts\";\n\n// --- Type helpers for unwrapping response types ---\n\n/** Unwrap `(response ok err)` → just the `ok` branch type */\ntype UnwrapResponse<T> = T extends { ok: infer O } | { err: any } ? O : T;\n\ntype ReadMethodReturn<\n\tC extends AbiContract,\n\tN extends ExtractReadOnlyFunctions<C>,\n> = UnwrapResponse<ExtractFunctionOutput<C, N>>;\n\n// --- Public type for the contract instance ---\n\ntype ReadMethods<C extends AbiContract> = {\n\t[N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t) => Promise<ReadMethodReturn<C, N>>;\n};\n\ntype CallMethods<C extends AbiContract> = {\n\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t\toptions?: ContractCallOptions,\n\t) => Promise<string>;\n};\n\ntype MapMethods<C extends AbiContract> = {\n\t[N in ExtractMapNames<C> as ToCamelCase<N>]: (\n\t\tkey: ExtractMapKey<C, N>,\n\t) => Promise<ExtractMapValue<C, N> | null>;\n};\n\nexport type ContractCallOptions = {\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\nexport type ContractInstance<C extends AbiContract> = {\n\tread: ReadMethods<C>;\n\tcall: CallMethods<C>;\n\tmaps: MapMethods<C>;\n};\n\nexport type GetContractParams<C extends AbiContract> = {\n\tclient: Client;\n\taddress: string;\n\tname: string;\n\tabi: C;\n};\n\nexport function getContract<const TAbi extends AbiContract>(\n\tparams: GetContractParams<TAbi>,\n): ContractInstance<TAbi> {\n\tconst { client, address, name: contractName, abi } = params;\n\tconst contractId = `${address}.${contractName}`;\n\n\t// Index functions/maps by name for fast lookup\n\tconst fnByName = new Map<string, AbiFunction>();\n\tfor (const fn of abi.functions) {\n\t\tfnByName.set(fn.name, fn as AbiFunction);\n\t}\n\n\tconst mapByName = new Map<string, AbiMap>();\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tmapByName.set(m.name, m as AbiMap);\n\t\t}\n\t}\n\n\t// Build kebab→camel reverse map for function/map names\n\tconst camelToKebab = new Map<string, string>();\n\tfor (const fn of abi.functions) {\n\t\tcamelToKebab.set(toCamelCase(fn.name), fn.name);\n\t}\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tcamelToKebab.set(toCamelCase(m.name), m.name);\n\t\t}\n\t}\n\n\tconst read = new Proxy({} as ReadMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"read-only\") return undefined;\n\n\t\t\treturn async (args: Record<string, unknown>) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst result = await readContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\targs: clarityArgs,\n\t\t\t\t});\n\n\t\t\t\tconst jsValue = clarityValueToJSUntyped(fn.outputs as AbiType, result);\n\n\t\t\t\t// Auto-unwrap: if output is response type, unwrap ok / throw on err\n\t\t\t\tif (isResponseOutput(fn.outputs as AbiType)) {\n\t\t\t\t\tconst resp = jsValue as { ok?: unknown; err?: unknown };\n\t\t\t\t\tif (\"ok\" in resp) return resp.ok;\n\t\t\t\t\tthrow new ContractResponseError(\n\t\t\t\t\t\t`${contractId}::${fn.name} returned (err ${formatErrValue(resp.err)})`,\n\t\t\t\t\t\tresp.err,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn jsValue;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst call = new Proxy({} as CallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\treturn callContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs: clarityArgs,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t});\n\n\tconst maps = new Proxy({} as MapMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst mapName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst map = mapByName.get(mapName);\n\t\t\tif (!map) return undefined;\n\n\t\t\treturn async (key: unknown) => {\n\t\t\t\tconst clarityKey = jsToClarityValue(map.key as AbiType, key);\n\t\t\t\tconst result = await getMapEntry(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tmapName: map.name,\n\t\t\t\t\tkey: clarityKey,\n\t\t\t\t});\n\n\t\t\t\t// Map entries come back as (optional ...). If none, return null.\n\t\t\t\tif (result.type === \"none\") return null;\n\t\t\t\tif (result.type === \"some\") {\n\t\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result.value);\n\t\t\t\t}\n\t\t\t\t// Direct value (shouldn't normally happen, but handle gracefully)\n\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result);\n\t\t\t};\n\t\t},\n\t});\n\n\treturn { read, call, maps };\n}\n\n// --- Helpers ---\n\nfunction buildFunctionArgs(\n\tfn: AbiFunction,\n\targs: Record<string, unknown>,\n): ClarityValue[] {\n\treturn fn.args.map((arg) => {\n\t\tconst camelKey = toCamelCase(arg.name);\n\t\tconst hasOriginal = arg.name in args;\n\t\tconst hasCamel = camelKey in args;\n\t\tconst value = hasOriginal\n\t\t\t? args[arg.name]\n\t\t\t: hasCamel\n\t\t\t\t? args[camelKey]\n\t\t\t\t: undefined;\n\t\tif (value === undefined) throw new Error(`Missing argument: ${arg.name}`);\n\t\treturn jsToClarityValue(arg.type as AbiType, value);\n\t});\n}\n\nfunction isResponseOutput(type: AbiType): boolean {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nfunction formatErrValue(value: unknown): string {\n\tif (typeof value === \"bigint\") return value.toString();\n\tif (typeof value === \"string\") return `\"${value}\"`;\n\treturn String(value);\n}\n\nexport class ContractResponseError extends Error {\n\toverride name = \"ContractResponseError\";\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly errorValue: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;AA6EO,SAAS,WAA2C,CAC1D,QACyB;AAAA,EACzB,QAAQ,QAAQ,SAAS,MAAM,cAAc,QAAQ;AAAA,EACrD,MAAM,aAAa,GAAG,WAAW;AAAA,EAGjC,MAAM,WAAW,IAAI;AAAA,EACrB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,SAAS,IAAI,GAAG,MAAM,EAAiB;AAAA,EACxC;AAAA,EAEA,MAAM,YAAY,IAAI;AAAA,EACtB,IAAI,IAAI,MAAM;AAAA,IACb,WAAW,KAAK,IAAI,MAAM;AAAA,MACzB,UAAU,IAAI,EAAE,MAAM,CAAW;AAAA,IAClC;AAAA,EACD;AAAA,EAGA,MAAM,eAAe,IAAI;AAAA,EACzB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,aAAa,IAAI,YAAY,GAAG,IAAI,GAAG,GAAG,IAAI;AAAA,EAC/C;AAAA,EACA,IAAI,IAAI,MAAM;AAAA,IACb,WAAW,KAAK,IAAI,MAAM;AAAA,MACzB,aAAa,IAAI,YAAY,EAAE,IAAI,GAAG,EAAE,IAAI;AAAA,IAC7C;AAAA,EACD;AAAA,EAEA,MAAM,OAAO,IAAI,MAAM,CAAC,GAAwB;AAAA,IAC/C,GAAG,CAAC,SAAS,MAAc;AAAA,MAC1B,MAAM,SAAS,aAAa,IAAI,IAAI,KAAK;AAAA,MACzC,MAAM,KAAK,SAAS,IAAI,MAAM;AAAA,MAC9B,IAAI,CAAC,MAAM,GAAG,WAAW;AAAA,QAAa;AAAA,MAEtC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O;AAAA,IAFG;AAAA;AAIlB;",
|
|
8
|
+
"debugId": "C71C39F2B8094B6864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -5,7 +5,7 @@ function formatUnits(value, decimals) {
|
|
|
5
5
|
if (negative)
|
|
6
6
|
v = -v;
|
|
7
7
|
const divisor = 10n ** BigInt(decimals);
|
|
8
|
-
|
|
8
|
+
const integer = (v / divisor).toString();
|
|
9
9
|
let fraction = (v % divisor).toString().padStart(decimals, "0");
|
|
10
10
|
fraction = fraction.replace(/0+$/, "") || "0";
|
|
11
11
|
const result = `${integer}.${fraction}`;
|
|
@@ -33,5 +33,5 @@ function parseStx(stx) {
|
|
|
33
33
|
|
|
34
34
|
export { formatUnits, parseUnits, formatStx, parseStx };
|
|
35
35
|
|
|
36
|
-
//# debugId=
|
|
37
|
-
//# sourceMappingURL=stacks-
|
|
36
|
+
//# debugId=3FFE694126DA3F0464756E2164756E21
|
|
37
|
+
//# sourceMappingURL=stacks-913a2rx7.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/utils/units.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Format a bigint value with decimal places.\n * @example formatUnits(1000000n, 6) → \"1.0\"\n * @example formatUnits(1500000n, 6) → \"1.5\"\n */\nexport function formatUnits(\n\tvalue: bigint | number | string,\n\tdecimals: number,\n): string {\n\tlet v = BigInt(value);\n\n\tconst negative = v < 0n;\n\tif (negative) v = -v;\n\n\tconst divisor = 10n ** BigInt(decimals);\n\tconst integer = (v / divisor).toString();\n\tlet fraction = (v % divisor).toString().padStart(decimals, \"0\");\n\n\t// Trim trailing zeros, but keep at least one decimal\n\tfraction = fraction.replace(/0+$/, \"\") || \"0\";\n\n\tconst result = `${integer}.${fraction}`;\n\treturn negative ? `-${result}` : result;\n}\n\n/**\n * Parse a decimal string into a bigint with the given number of decimals.\n * @example parseUnits(\"1.5\", 6) → 1500000n\n * @example parseUnits(\"1\", 6) → 1000000n\n */\nexport function parseUnits(value: string | number, decimals: number): bigint {\n\tlet str = typeof value === \"number\" ? value.toString() : value;\n\n\tconst negative = str.startsWith(\"-\");\n\tif (negative) str = str.slice(1);\n\n\tconst [integer = \"\", fraction = \"\"] = str.split(\".\");\n\n\tif (fraction.length > decimals) {\n\t\tthrow new Error(\n\t\t\t`Too many decimal places: \"${value}\" has ${fraction.length} decimals, max is ${decimals}`,\n\t\t);\n\t}\n\n\tconst padded = fraction.padEnd(decimals, \"0\");\n\tconst result = BigInt(integer + padded);\n\treturn negative ? -result : result;\n}\n\n/**\n * Format microSTX to STX string (6 decimals).\n * @example formatStx(1000000n) → \"1.0\"\n */\nexport function formatStx(microStx: bigint | number | string): string {\n\treturn formatUnits(microStx, 6);\n}\n\n/**\n * Parse STX string to microSTX bigint (6 decimals).\n * @example parseStx(\"1.5\") → 1500000n\n */\nexport function parseStx(stx: string | number): bigint {\n\treturn parseUnits(stx, 6);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAKO,SAAS,WAAW,CAC1B,OACA,UACS;AAAA,EACT,IAAI,IAAI,OAAO,KAAK;AAAA,EAEpB,MAAM,WAAW,IAAI;AAAA,EACrB,IAAI;AAAA,IAAU,IAAI,CAAC;AAAA,EAEnB,MAAM,UAAU,OAAO,OAAO,QAAQ;AAAA,EACtC,MAAM,WAAW,IAAI,SAAS,SAAS;AAAA,EACvC,IAAI,YAAY,IAAI,SAAS,SAAS,EAAE,SAAS,UAAU,GAAG;AAAA,EAG9D,WAAW,SAAS,QAAQ,OAAO,EAAE,KAAK;AAAA,EAE1C,MAAM,SAAS,GAAG,WAAW;AAAA,EAC7B,OAAO,WAAW,IAAI,WAAW;AAAA;AAQ3B,SAAS,UAAU,CAAC,OAAwB,UAA0B;AAAA,EAC5E,IAAI,MAAM,OAAO,UAAU,WAAW,MAAM,SAAS,IAAI;AAAA,EAEzD,MAAM,WAAW,IAAI,WAAW,GAAG;AAAA,EACnC,IAAI;AAAA,IAAU,MAAM,IAAI,MAAM,CAAC;AAAA,EAE/B,OAAO,UAAU,IAAI,WAAW,MAAM,IAAI,MAAM,GAAG;AAAA,EAEnD,IAAI,SAAS,SAAS,UAAU;AAAA,IAC/B,MAAM,IAAI,MACT,6BAA6B,cAAc,SAAS,2BAA2B,UAChF;AAAA,EACD;AAAA,EAEA,MAAM,SAAS,SAAS,OAAO,UAAU,GAAG;AAAA,EAC5C,MAAM,SAAS,OAAO,UAAU,MAAM;AAAA,EACtC,OAAO,WAAW,CAAC,SAAS;AAAA;AAOtB,SAAS,SAAS,CAAC,UAA4C;AAAA,EACrE,OAAO,YAAY,UAAU,CAAC;AAAA;AAOxB,SAAS,QAAQ,CAAC,KAA8B;AAAA,EACtD,OAAO,WAAW,KAAK,CAAC;AAAA;",
|
|
8
|
+
"debugId": "3FFE694126DA3F0464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -13,13 +13,13 @@ import {
|
|
|
13
13
|
isUint128,
|
|
14
14
|
isUint8Array,
|
|
15
15
|
toCamelCase
|
|
16
|
-
} from "./stacks-
|
|
16
|
+
} from "./stacks-zf7rbpzp.js";
|
|
17
17
|
import {
|
|
18
18
|
asciiToBytes,
|
|
19
19
|
bytesToAscii,
|
|
20
20
|
hexToBytes,
|
|
21
21
|
utf8ToBytes
|
|
22
|
-
} from "./stacks-
|
|
22
|
+
} from "./stacks-s7z5q8be.js";
|
|
23
23
|
// src/clarity/prettyPrint.ts
|
|
24
24
|
function prettyPrint(val, encoding = "hex") {
|
|
25
25
|
switch (val.type) {
|
|
@@ -70,7 +70,10 @@ function cvToJSON(val) {
|
|
|
70
70
|
case "uint":
|
|
71
71
|
return { type: "uint", value: val.value.toString() };
|
|
72
72
|
case "buffer":
|
|
73
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
type: `(buff ${Math.ceil(val.value.length / 2)})`,
|
|
75
|
+
value: `0x${val.value}`
|
|
76
|
+
};
|
|
74
77
|
case "none":
|
|
75
78
|
return { type: "(optional none)", value: null };
|
|
76
79
|
case "some":
|
|
@@ -92,9 +95,15 @@ function cvToJSON(val) {
|
|
|
92
95
|
return { type: "(tuple)", value: result };
|
|
93
96
|
}
|
|
94
97
|
case "ascii":
|
|
95
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
type: `(string-ascii ${asciiToBytes(val.value).length})`,
|
|
100
|
+
value: val.value
|
|
101
|
+
};
|
|
96
102
|
case "utf8":
|
|
97
|
-
return {
|
|
103
|
+
return {
|
|
104
|
+
type: `(string-utf8 ${utf8ToBytes(val.value).length})`,
|
|
105
|
+
value: val.value
|
|
106
|
+
};
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
function cvToValue(val) {
|
|
@@ -278,5 +287,5 @@ function validateArgsArray(func, args) {
|
|
|
278
287
|
}
|
|
279
288
|
export { prettyPrint, cvToJSON, cvToValue, ClarityConversionError, jsToClarity, prepareArgs, validateArgs, validateArgsArray };
|
|
280
289
|
|
|
281
|
-
//# debugId=
|
|
282
|
-
//# sourceMappingURL=stacks-
|
|
290
|
+
//# debugId=F40AEFE2CC29591364756E2164756E21
|
|
291
|
+
//# sourceMappingURL=stacks-96d6m1zy.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/clarity/prettyPrint.ts", "../src/clarity/abi/converters.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n\tasciiToBytes,\n\tbytesToAscii,\n\thexToBytes,\n\tutf8ToBytes,\n} from \"../utils/encoding.ts\";\nimport type { ClarityValue } from \"./types.ts\";\n\nexport function prettyPrint(\n\tval: ClarityValue,\n\tencoding: \"tryAscii\" | \"hex\" = \"hex\",\n): string | undefined {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn \"true\";\n\t\tcase \"false\":\n\t\t\treturn \"false\";\n\t\tcase \"int\":\n\t\t\treturn val.value.toString();\n\t\tcase \"uint\":\n\t\t\treturn `u${val.value.toString()}`;\n\t\tcase \"buffer\":\n\t\t\tif (encoding === \"tryAscii\") {\n\t\t\t\tconst str = bytesToAscii(hexToBytes(val.value));\n\t\t\t\tif (/^[ -~]*$/.test(str)) return JSON.stringify(str);\n\t\t\t}\n\t\t\treturn `0x${val.value}`;\n\t\tcase \"none\":\n\t\t\treturn \"none\";\n\t\tcase \"some\":\n\t\t\treturn `(some ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"ok\":\n\t\t\treturn `(ok ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"err\":\n\t\t\treturn `(err ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn val.value;\n\t\tcase \"list\":\n\t\t\treturn `(list ${val.value.map((v) => prettyPrint(v, encoding)).join(\" \")})`;\n\t\tcase \"tuple\":\n\t\t\treturn `(tuple ${Object.keys(val.value)\n\t\t\t\t.map((key) => `(${key} ${prettyPrint(val.value[key]!, encoding)})`)\n\t\t\t\t.join(\" \")})`;\n\t\tcase \"ascii\":\n\t\t\treturn `\"${val.value}\"`;\n\t\tcase \"utf8\":\n\t\t\treturn `u\"${val.value}\"`;\n\t}\n}\n\nexport function cvToJSON(val: ClarityValue): any {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn { type: \"bool\", value: true };\n\t\tcase \"false\":\n\t\t\treturn { type: \"bool\", value: false };\n\t\tcase \"int\":\n\t\t\treturn { type: \"int\", value: val.value.toString() };\n\t\tcase \"uint\":\n\t\t\treturn { type: \"uint\", value: val.value.toString() };\n\t\tcase \"buffer\":\n\t\t\treturn {\n\t\t\t\ttype: `(buff ${Math.ceil(val.value.length / 2)})`,\n\t\t\t\tvalue: `0x${val.value}`,\n\t\t\t};\n\t\tcase \"none\":\n\t\t\treturn { type: \"(optional none)\", value: null };\n\t\tcase \"some\":\n\t\t\treturn { type: `(optional)`, value: cvToJSON(val.value) };\n\t\tcase \"ok\":\n\t\t\treturn { type: \"(response)\", value: cvToJSON(val.value), success: true };\n\t\tcase \"err\":\n\t\t\treturn { type: \"(response)\", value: cvToJSON(val.value), success: false };\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn { type: \"principal\", value: val.value };\n\t\tcase \"list\":\n\t\t\treturn { type: \"(list)\", value: val.value.map(cvToJSON) };\n\t\tcase \"tuple\": {\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\tresult[key] = cvToJSON(val.value[key]!);\n\t\t\t}\n\t\t\treturn { type: \"(tuple)\", value: result };\n\t\t}\n\t\tcase \"ascii\":\n\t\t\treturn {\n\t\t\t\ttype: `(string-ascii ${asciiToBytes(val.value).length})`,\n\t\t\t\tvalue: val.value,\n\t\t\t};\n\t\tcase \"utf8\":\n\t\t\treturn {\n\t\t\t\ttype: `(string-utf8 ${utf8ToBytes(val.value).length})`,\n\t\t\t\tvalue: val.value,\n\t\t\t};\n\t}\n}\n\nexport function cvToValue(val: ClarityValue): any {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn true;\n\t\tcase \"false\":\n\t\t\treturn false;\n\t\tcase \"int\":\n\t\tcase \"uint\":\n\t\t\treturn val.value;\n\t\tcase \"buffer\":\n\t\t\treturn `0x${val.value}`;\n\t\tcase \"none\":\n\t\t\treturn null;\n\t\tcase \"some\":\n\t\t\treturn cvToValue(val.value);\n\t\tcase \"ok\":\n\t\tcase \"err\":\n\t\t\treturn cvToValue(val.value);\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn val.value;\n\t\tcase \"list\":\n\t\t\treturn val.value.map(cvToValue);\n\t\tcase \"tuple\": {\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\tresult[key] = cvToValue(val.value[key]!);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\tcase \"ascii\":\n\t\tcase \"utf8\":\n\t\t\treturn val.value;\n\t}\n}\n",
|
|
6
|
+
"import type { AbiFunction } from \"./contract.ts\";\nimport {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n\tisBool,\n\tisInt128,\n\tisPrincipal,\n\tisString,\n\tisUint8Array,\n\tisUint128,\n} from \"./guards.ts\";\nimport type { AbiType } from \"./types.ts\";\nimport { toCamelCase } from \"./utils.ts\";\n\nexport class ClarityConversionError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: AbiType,\n\t\tpublic readonly value: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ClarityConversionError\";\n\t}\n}\n\nexport function jsToClarity(type: AbiType, value: unknown): unknown {\n\tif (type === \"none\") return null;\n\n\tif (type === \"uint128\") {\n\t\tif (!isUint128(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid uint128 value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"int128\") {\n\t\tif (!isInt128(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid int128 value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"bool\") {\n\t\tif (!isBool(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid bool value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"principal\") {\n\t\tif (!isPrincipal(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid principal value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"trait_reference\") {\n\t\tif (!isPrincipal(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid trait_reference value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\treturn value;\n\t}\n\n\tif (isAbiStringAscii(type)) {\n\t\tif (!isString(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid string-ascii value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst str = value as string;\n\t\tfor (let i = 0; i < str.length; i++) {\n\t\t\tif (str.charCodeAt(i) > 127) {\n\t\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\t`Non-ASCII character at position ${i}: '${str[i]}' (code ${str.charCodeAt(i)})`,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (str.length > type[\"string-ascii\"].length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`String length ${str.length} exceeds max ${type[\"string-ascii\"].length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiStringUtf8(type)) {\n\t\tif (!isString(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid string-utf8 value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst str = value as string;\n\t\tconst byteLength = new TextEncoder().encode(str).length;\n\t\tif (byteLength > type[\"string-utf8\"].length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`String byte length ${byteLength} exceeds max ${type[\"string-utf8\"].length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiBuffer(type)) {\n\t\tif (!isUint8Array(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid buffer value\", type, value);\n\t\tconst buff = value as Uint8Array;\n\t\tif (buff.length > type.buff.length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Buffer length ${buff.length} exceeds max ${type.buff.length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiList(type)) {\n\t\tif (!Array.isArray(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected array for list type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tif (value.length > type.list.length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`List length ${value.length} exceeds max ${type.list.length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value.map((item) => jsToClarity(type.list.type, item));\n\t}\n\n\tif (isAbiTuple(type)) {\n\t\tif (typeof value !== \"object\" || value === null)\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected object for tuple type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of type.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in (value as object);\n\t\t\tconst hasCamel = camelKey in (value as object);\n\t\t\tif (!hasOriginal && !hasCamel) {\n\t\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\t`Missing tuple field: ${field.name}`,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? (value as Record<string, unknown>)[field.name]\n\t\t\t\t: (value as Record<string, unknown>)[camelKey];\n\t\t\tresult[field.name] = jsToClarity(field.type, fieldValue);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(type)) {\n\t\tif (value === null || value === undefined) return null;\n\t\treturn jsToClarity(type.optional, value);\n\t}\n\n\tif (isAbiResponse(type)) {\n\t\tif (typeof value !== \"object\" || value === null)\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected object for response type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst hasOk = \"ok\" in value;\n\t\tconst hasErr = \"err\" in value;\n\t\tif (hasOk && !hasErr) {\n\t\t\treturn {\n\t\t\t\tok: jsToClarity(type.response.ok, (value as { ok: unknown }).ok),\n\t\t\t};\n\t\t}\n\t\tif (hasErr && !hasOk) {\n\t\t\treturn {\n\t\t\t\terr: jsToClarity(type.response.error, (value as { err: unknown }).err),\n\t\t\t};\n\t\t}\n\t\tthrow new ClarityConversionError(\n\t\t\t\"Response must have exactly 'ok' or 'err' property\",\n\t\t\ttype,\n\t\t\tvalue,\n\t\t);\n\t}\n\n\tthrow new ClarityConversionError(`Unknown Clarity type`, type, value);\n}\n\nexport function prepareArgs<F extends AbiFunction>(\n\tfunc: F,\n\targs: Record<string, unknown>,\n): unknown[] {\n\treturn func.args.map((arg) => {\n\t\tif (!(arg.name in args)) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Missing argument: ${arg.name}`,\n\t\t\t\targ.type,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\t\treturn jsToClarity(arg.type, args[arg.name]);\n\t});\n}\n\nexport function validateArgs<F extends AbiFunction>(\n\tfunc: F,\n\targs: Record<string, unknown>,\n): void {\n\tfor (const arg of func.args) {\n\t\tif (!(arg.name in args)) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Missing argument: ${arg.name}`,\n\t\t\t\targ.type,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\t\tjsToClarity(arg.type, args[arg.name]);\n\t}\n}\n\nexport function validateArgsArray<F extends AbiFunction>(\n\tfunc: F,\n\targs: unknown[],\n): void {\n\tif (args.length !== func.args.length) {\n\t\tthrow new ClarityConversionError(\n\t\t\t`Expected ${func.args.length} arguments, got ${args.length}`,\n\t\t\tfunc.args[0]?.type ?? \"bool\",\n\t\t\targs,\n\t\t);\n\t}\n\tfunc.args.forEach((arg, i) => {\n\t\tjsToClarity(arg.type, args[i]);\n\t});\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAQO,SAAS,WAAW,CAC1B,KACA,WAA+B,OACV;AAAA,EACrB,QAAQ,IAAI;AAAA,SACN;AAAA,MACJ,OAAO;AAAA,SACH;AAAA,MACJ,OAAO;AAAA,SACH;AAAA,MACJ,OAAO,IAAI,MAAM,SAAS;AAAA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MACO;AAAA,EACP,IAAI,KAAK,WAAW,KAAK,KAAK,QAAQ;AAAA,IACrC,MAAM,IAAI,uBACT,YAAY,KAAK,KAAK,yBAAyB,KAAK,UACpD,KAAK,KAAK,IAAI,QAAQ,QACtB,IACD;AAAA,EACD;AAAA,EACA,KAAK,KAAK,QAAQ,CAAC,KAAK,MAAM;AAAA,IAC7B,YAAY,IAAI,MAAM,KAAK,EAAE;AAAA,GAC7B;AAAA;",
|
|
9
|
+
"debugId": "F40AEFE2CC29591364756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/address.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { c32address, c32addressDecode } from \"./c32.ts\";\n\nexport { c32address, c32addressDecode };\n\nexport function validateStacksAddress(address: string): boolean {\n
|
|
5
|
+
"import { c32address, c32addressDecode } from \"./c32.ts\";\n\nexport { c32address, c32addressDecode };\n\nexport function validateStacksAddress(address: string): boolean {\n\ttry {\n\t\tc32addressDecode(address);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Alias for validateStacksAddress — matches future.md naming. */\nexport const isValidAddress: (address: string) => boolean =\n\tvalidateStacksAddress;\n\nexport function parseContractId(contractId: string): [string, string] {\n\tconst [address, name] = contractId.split(\".\");\n\tif (!address || !name)\n\t\tthrow new Error(`Invalid contract identifier: ${contractId}`);\n\treturn [address, name];\n}\n\nexport function isClarityName(name: string): boolean {\n\tconst regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;\n\treturn 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\tconst [versionA, hashA] = c32addressDecode(a);\n\tconst [versionB, hashB] = c32addressDecode(b);\n\treturn 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\treturn 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(\n\tdeployer: string,\n\tcontractName: string,\n): string {\n\tif (!validateStacksAddress(deployer)) {\n\t\tthrow new Error(`Invalid deployer address: ${deployer}`);\n\t}\n\tif (!isClarityName(contractName)) {\n\t\tthrow new Error(`Invalid contract name: ${contractName}`);\n\t}\n\treturn `${deployer}.${contractName}`;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAIO,SAAS,qBAAqB,CAAC,SAA0B;AAAA,
|
|
7
|
+
"mappings": ";AAIO,SAAS,qBAAqB,CAAC,SAA0B;AAAA,EAC/D,IAAI;AAAA,IACH,iBAAiB,OAAO;AAAA,IACxB,OAAO;AAAA,IACN,MAAM;AAAA,IACP,OAAO;AAAA;AAAA;AAKF,IAAM,iBACZ;AAEM,SAAS,eAAe,CAAC,YAAsC;AAAA,EACrE,OAAO,SAAS,QAAQ,WAAW,MAAM,GAAG;AAAA,EAC5C,IAAI,CAAC,WAAW,CAAC;AAAA,IAChB,MAAM,IAAI,MAAM,gCAAgC,YAAY;AAAA,EAC7D,OAAO,CAAC,SAAS,IAAI;AAAA;AAGf,SAAS,aAAa,CAAC,MAAuB;AAAA,EACpD,MAAM,QAAQ;AAAA,EACd,OAAO,MAAM,KAAK,IAAI,KAAK,KAAK,SAAS;AAAA;AAOnC,SAAS,cAAc,CAAC,GAAW,GAAoB;AAAA,EAC7D,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,aAAa,YAAY,MAAM,YAAY,MAAM,MAAM,YAAY;AAAA;AAIpE,SAAS,gBAAgB,CAAC,SAAyB;AAAA,EACzD,OAAO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