@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,629 @@
|
|
|
1
|
+
import {
|
|
2
|
+
providerToAccount
|
|
3
|
+
} from "../shared/stacks-qcae5852.js";
|
|
4
|
+
import {
|
|
5
|
+
defineChain,
|
|
6
|
+
devnet,
|
|
7
|
+
mainnet,
|
|
8
|
+
mocknet,
|
|
9
|
+
testnet
|
|
10
|
+
} from "../shared/stacks-qt8ehebn.js";
|
|
11
|
+
import {
|
|
12
|
+
deployContract,
|
|
13
|
+
getAccountInfo,
|
|
14
|
+
getBalance,
|
|
15
|
+
getBlock,
|
|
16
|
+
getBlockHeight,
|
|
17
|
+
getContractAbi,
|
|
18
|
+
multicall,
|
|
19
|
+
signMessage,
|
|
20
|
+
signTransactionAction,
|
|
21
|
+
simulateCall,
|
|
22
|
+
simulateTransaction,
|
|
23
|
+
sponsorTransaction,
|
|
24
|
+
transferStx
|
|
25
|
+
} from "../shared/stacks-n2g56wgg.js";
|
|
26
|
+
import {
|
|
27
|
+
callContract,
|
|
28
|
+
estimateFee,
|
|
29
|
+
getMapEntry,
|
|
30
|
+
getNonce,
|
|
31
|
+
readContract,
|
|
32
|
+
sendTransaction
|
|
33
|
+
} from "../shared/stacks-zm0b3tgy.js";
|
|
34
|
+
import {
|
|
35
|
+
WebSocketError,
|
|
36
|
+
watchAddress,
|
|
37
|
+
watchAddressBalance,
|
|
38
|
+
watchBlocks,
|
|
39
|
+
watchMempool,
|
|
40
|
+
watchNftEvent,
|
|
41
|
+
watchTransaction
|
|
42
|
+
} from "../shared/stacks-y3dh7hv1.js";
|
|
43
|
+
import"../shared/stacks-709tra19.js";
|
|
44
|
+
import"../shared/stacks-dxhntr76.js";
|
|
45
|
+
import {
|
|
46
|
+
buildContractCall,
|
|
47
|
+
buildContractDeploy,
|
|
48
|
+
buildTokenTransfer
|
|
49
|
+
} from "../shared/stacks-f7wdrzs3.js";
|
|
50
|
+
import {
|
|
51
|
+
finalizeMultiSig
|
|
52
|
+
} from "../shared/stacks-yfgsm6ap.js";
|
|
53
|
+
import"../shared/stacks-j2cy7qtt.js";
|
|
54
|
+
import"../shared/stacks-8yykgdww.js";
|
|
55
|
+
import {
|
|
56
|
+
formatStx,
|
|
57
|
+
parseStx
|
|
58
|
+
} from "../shared/stacks-k2p5tv6x.js";
|
|
59
|
+
import {
|
|
60
|
+
AddressVersion,
|
|
61
|
+
MICROSTX_PER_STX,
|
|
62
|
+
TESTNET_ZERO_ADDRESS,
|
|
63
|
+
ZERO_ADDRESS
|
|
64
|
+
} from "../shared/stacks-v9jqcpd4.js";
|
|
65
|
+
import"../shared/stacks-bycy6t9k.js";
|
|
66
|
+
import {
|
|
67
|
+
getContractAddress,
|
|
68
|
+
isAddressEqual,
|
|
69
|
+
isValidAddress,
|
|
70
|
+
parseContractId
|
|
71
|
+
} from "../shared/stacks-gjvbq6w7.js";
|
|
72
|
+
import"../shared/stacks-nqytwfcc.js";
|
|
73
|
+
import {
|
|
74
|
+
__require
|
|
75
|
+
} from "../shared/stacks-8m9byk2j.js";
|
|
76
|
+
|
|
77
|
+
// src/clients/createClient.ts
|
|
78
|
+
var BASE_KEYS = new Set(["chain", "account", "transport", "request", "extend"]);
|
|
79
|
+
function createClient(config) {
|
|
80
|
+
const transport = config.transport({ chain: config.chain });
|
|
81
|
+
const client = {
|
|
82
|
+
chain: config.chain,
|
|
83
|
+
account: config.account,
|
|
84
|
+
transport,
|
|
85
|
+
request: transport.request,
|
|
86
|
+
extend(fn) {
|
|
87
|
+
const extensions = fn(client);
|
|
88
|
+
const extended = { ...client };
|
|
89
|
+
for (const [key, value] of Object.entries(extensions)) {
|
|
90
|
+
if (BASE_KEYS.has(key))
|
|
91
|
+
continue;
|
|
92
|
+
extended[key] = value;
|
|
93
|
+
}
|
|
94
|
+
extended.extend = (nextFn) => {
|
|
95
|
+
const nextExtensions = nextFn(extended);
|
|
96
|
+
const next = { ...extended };
|
|
97
|
+
for (const [key, value] of Object.entries(nextExtensions)) {
|
|
98
|
+
if (BASE_KEYS.has(key))
|
|
99
|
+
continue;
|
|
100
|
+
next[key] = value;
|
|
101
|
+
}
|
|
102
|
+
next.extend = extended.extend;
|
|
103
|
+
return next;
|
|
104
|
+
};
|
|
105
|
+
return extended;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return client;
|
|
109
|
+
}
|
|
110
|
+
// src/clients/decorators/public.ts
|
|
111
|
+
function publicActions(client) {
|
|
112
|
+
return {
|
|
113
|
+
getNonce: (params) => getNonce(client, params),
|
|
114
|
+
getBalance: (params) => getBalance(client, params),
|
|
115
|
+
getAccountInfo: (params) => getAccountInfo(client, params),
|
|
116
|
+
getBlock: (params) => getBlock(client, params),
|
|
117
|
+
getBlockHeight: () => getBlockHeight(client),
|
|
118
|
+
readContract: (params) => readContract(client, params),
|
|
119
|
+
getContractAbi: (params) => getContractAbi(client, params),
|
|
120
|
+
getMapEntry: (params) => getMapEntry(client, params),
|
|
121
|
+
estimateFee: (params) => estimateFee(client, params),
|
|
122
|
+
multicall: (params) => multicall(client, params),
|
|
123
|
+
simulateCall: (params) => simulateCall(client, params),
|
|
124
|
+
simulateTransaction: (params) => simulateTransaction(client, params),
|
|
125
|
+
watchBlocks: (params) => watchBlocks(client, params),
|
|
126
|
+
watchMempool: (params) => watchMempool(client, params),
|
|
127
|
+
watchTransaction: (params) => watchTransaction(client, params),
|
|
128
|
+
watchAddress: (params) => watchAddress(client, params),
|
|
129
|
+
watchAddressBalance: (params) => watchAddressBalance(client, params),
|
|
130
|
+
watchNftEvent: (params) => watchNftEvent(client, params)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/clients/createPublicClient.ts
|
|
135
|
+
function createPublicClient(config) {
|
|
136
|
+
return createClient(config).extend(publicActions);
|
|
137
|
+
}
|
|
138
|
+
// src/clients/decorators/wallet.ts
|
|
139
|
+
function walletActions(client) {
|
|
140
|
+
return {
|
|
141
|
+
sendTransaction: (params) => sendTransaction(client, params),
|
|
142
|
+
signTransaction: (params) => signTransactionAction(client, params),
|
|
143
|
+
transferStx: (params) => transferStx(client, params),
|
|
144
|
+
callContract: (params) => callContract(client, params),
|
|
145
|
+
deployContract: (params) => deployContract(client, params),
|
|
146
|
+
signMessage: (params) => signMessage(client, params),
|
|
147
|
+
sponsorTransaction: (params) => sponsorTransaction(client, params)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/clients/createWalletClient.ts
|
|
152
|
+
function createWalletClient(config) {
|
|
153
|
+
return createClient(config).extend(walletActions);
|
|
154
|
+
}
|
|
155
|
+
// src/clients/decorators/multisig.ts
|
|
156
|
+
function multisigActions(client) {
|
|
157
|
+
const msConfig = client._multisigConfig;
|
|
158
|
+
if (!msConfig)
|
|
159
|
+
throw new Error("multisigActions requires a multi-sig client");
|
|
160
|
+
const { signers, requiredSignatures, hashMode } = msConfig;
|
|
161
|
+
async function resolveNonce(nonce) {
|
|
162
|
+
if (nonce !== undefined)
|
|
163
|
+
return nonce;
|
|
164
|
+
const { makeMultiSigAddress } = await import("../shared/stacks-f3tk2k5s.js");
|
|
165
|
+
const address = makeMultiSigAddress(signers, requiredSignatures, client.chain);
|
|
166
|
+
return getNonce(client, { address });
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
async transferStx(params) {
|
|
170
|
+
const nonce = await resolveNonce(params.nonce);
|
|
171
|
+
const unsigned = buildTokenTransfer({
|
|
172
|
+
recipient: params.to,
|
|
173
|
+
amount: params.amount,
|
|
174
|
+
memo: params.memo,
|
|
175
|
+
fee: params.fee ?? 0n,
|
|
176
|
+
nonce,
|
|
177
|
+
publicKeys: signers,
|
|
178
|
+
signaturesRequired: requiredSignatures,
|
|
179
|
+
hashMode,
|
|
180
|
+
chain: client.chain,
|
|
181
|
+
postConditionMode: params.postConditionMode,
|
|
182
|
+
postConditions: params.postConditions
|
|
183
|
+
});
|
|
184
|
+
if (params.fee === undefined) {
|
|
185
|
+
const estimates = await estimateFee(client, { transaction: unsigned });
|
|
186
|
+
const mid = estimates[1] ?? estimates[0];
|
|
187
|
+
if (mid) {
|
|
188
|
+
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return unsigned;
|
|
192
|
+
},
|
|
193
|
+
async callContract(params) {
|
|
194
|
+
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
195
|
+
const nonce = await resolveNonce(params.nonce);
|
|
196
|
+
const unsigned = buildContractCall({
|
|
197
|
+
contractAddress,
|
|
198
|
+
contractName,
|
|
199
|
+
functionName: params.functionName,
|
|
200
|
+
functionArgs: params.functionArgs ?? [],
|
|
201
|
+
fee: params.fee ?? 0n,
|
|
202
|
+
nonce,
|
|
203
|
+
publicKeys: signers,
|
|
204
|
+
signaturesRequired: requiredSignatures,
|
|
205
|
+
hashMode,
|
|
206
|
+
chain: client.chain,
|
|
207
|
+
postConditionMode: params.postConditionMode,
|
|
208
|
+
postConditions: params.postConditions
|
|
209
|
+
});
|
|
210
|
+
if (params.fee === undefined) {
|
|
211
|
+
const estimates = await estimateFee(client, { transaction: unsigned });
|
|
212
|
+
const mid = estimates[1] ?? estimates[0];
|
|
213
|
+
if (mid) {
|
|
214
|
+
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return unsigned;
|
|
218
|
+
},
|
|
219
|
+
async deployContract(params) {
|
|
220
|
+
const nonce = await resolveNonce(params.nonce);
|
|
221
|
+
const unsigned = buildContractDeploy({
|
|
222
|
+
contractName: params.contractName,
|
|
223
|
+
codeBody: params.codeBody,
|
|
224
|
+
clarityVersion: params.clarityVersion,
|
|
225
|
+
fee: params.fee ?? 0n,
|
|
226
|
+
nonce,
|
|
227
|
+
publicKeys: signers,
|
|
228
|
+
signaturesRequired: requiredSignatures,
|
|
229
|
+
hashMode,
|
|
230
|
+
chain: client.chain,
|
|
231
|
+
postConditionMode: params.postConditionMode,
|
|
232
|
+
postConditions: params.postConditions
|
|
233
|
+
});
|
|
234
|
+
if (params.fee === undefined) {
|
|
235
|
+
const estimates = await estimateFee(client, { transaction: unsigned });
|
|
236
|
+
const mid = estimates[1] ?? estimates[0];
|
|
237
|
+
if (mid) {
|
|
238
|
+
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return unsigned;
|
|
242
|
+
},
|
|
243
|
+
async sendTransaction(params) {
|
|
244
|
+
const finalized = finalizeMultiSig(params.transaction, signers);
|
|
245
|
+
return sendTransaction(client, {
|
|
246
|
+
transaction: finalized,
|
|
247
|
+
attachment: params.attachment
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/clients/createMultiSigClient.ts
|
|
254
|
+
function createMultiSigClient(config) {
|
|
255
|
+
const client = createClient(config);
|
|
256
|
+
client._multisigConfig = {
|
|
257
|
+
signers: config.signers,
|
|
258
|
+
requiredSignatures: config.requiredSignatures,
|
|
259
|
+
hashMode: config.hashMode
|
|
260
|
+
};
|
|
261
|
+
return client.extend(multisigActions);
|
|
262
|
+
}
|
|
263
|
+
// src/transports/createTransport.ts
|
|
264
|
+
function createTransport(type, config) {
|
|
265
|
+
return {
|
|
266
|
+
type,
|
|
267
|
+
request: config.request,
|
|
268
|
+
config
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
async function fetchWithRetry(url, options, retryCount, retryDelay, timeout) {
|
|
272
|
+
let lastError;
|
|
273
|
+
for (let attempt = 0;attempt <= retryCount; attempt++) {
|
|
274
|
+
try {
|
|
275
|
+
const controller = new AbortController;
|
|
276
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
277
|
+
const response = await fetch(url, {
|
|
278
|
+
...options,
|
|
279
|
+
signal: controller.signal
|
|
280
|
+
});
|
|
281
|
+
clearTimeout(timeoutId);
|
|
282
|
+
if (response.ok || response.status < 500) {
|
|
283
|
+
return response;
|
|
284
|
+
}
|
|
285
|
+
lastError = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
288
|
+
}
|
|
289
|
+
if (attempt < retryCount) {
|
|
290
|
+
await new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
throw lastError ?? new Error("Request failed");
|
|
294
|
+
}
|
|
295
|
+
function buildRequestFn(baseUrl, config) {
|
|
296
|
+
const {
|
|
297
|
+
timeout = 30000,
|
|
298
|
+
retryCount = 3,
|
|
299
|
+
retryDelay = 150,
|
|
300
|
+
fetchOptions = {},
|
|
301
|
+
apiKey
|
|
302
|
+
} = config;
|
|
303
|
+
return async (path, options) => {
|
|
304
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
305
|
+
const headers = {
|
|
306
|
+
"Content-Type": "application/json",
|
|
307
|
+
...fetchOptions.headers,
|
|
308
|
+
...options?.headers
|
|
309
|
+
};
|
|
310
|
+
if (apiKey) {
|
|
311
|
+
headers["x-api-key"] = apiKey;
|
|
312
|
+
}
|
|
313
|
+
const init = {
|
|
314
|
+
...fetchOptions,
|
|
315
|
+
method: options?.method ?? "GET",
|
|
316
|
+
headers
|
|
317
|
+
};
|
|
318
|
+
if (options?.body !== undefined) {
|
|
319
|
+
init.body = JSON.stringify(options.body);
|
|
320
|
+
}
|
|
321
|
+
const response = await fetchWithRetry(url, init, retryCount, retryDelay, timeout);
|
|
322
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
323
|
+
if (contentType.includes("application/json")) {
|
|
324
|
+
return response.json();
|
|
325
|
+
}
|
|
326
|
+
return response.text();
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/transports/http.ts
|
|
331
|
+
function http(url, config) {
|
|
332
|
+
return (params) => {
|
|
333
|
+
const resolvedUrl = url ?? params?.chain?.rpcUrls.default.http[0] ?? "http://localhost:3999";
|
|
334
|
+
const mergedConfig = {
|
|
335
|
+
...config,
|
|
336
|
+
url: resolvedUrl
|
|
337
|
+
};
|
|
338
|
+
return createTransport("http", {
|
|
339
|
+
...mergedConfig,
|
|
340
|
+
request: buildRequestFn(resolvedUrl, mergedConfig)
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// src/transports/custom.ts
|
|
345
|
+
function custom(params) {
|
|
346
|
+
return () => createTransport("custom", { request: params.request });
|
|
347
|
+
}
|
|
348
|
+
// src/transports/fallback.ts
|
|
349
|
+
function fallback(transports) {
|
|
350
|
+
return (params) => {
|
|
351
|
+
const resolved = transports.map((t) => t(params));
|
|
352
|
+
return createTransport("fallback", {
|
|
353
|
+
request: async (path, options) => {
|
|
354
|
+
let lastError;
|
|
355
|
+
for (const transport of resolved) {
|
|
356
|
+
try {
|
|
357
|
+
return await transport.request(path, options);
|
|
358
|
+
} catch (error) {
|
|
359
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
throw lastError ?? new Error("All transports failed");
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
// src/transports/webSocket.ts
|
|
368
|
+
function subKey(params) {
|
|
369
|
+
const parts = [params.event];
|
|
370
|
+
if (params.tx_id)
|
|
371
|
+
parts.push(`tx_id:${params.tx_id}`);
|
|
372
|
+
if (params.address)
|
|
373
|
+
parts.push(`address:${params.address}`);
|
|
374
|
+
if (params.asset_identifier)
|
|
375
|
+
parts.push(`asset:${params.asset_identifier}`);
|
|
376
|
+
if (params.value)
|
|
377
|
+
parts.push(`value:${params.value}`);
|
|
378
|
+
return parts.join("|");
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
class WebSocketChannel {
|
|
382
|
+
ws = null;
|
|
383
|
+
url;
|
|
384
|
+
nextId = 1;
|
|
385
|
+
pending = new Map;
|
|
386
|
+
subs = new Map;
|
|
387
|
+
destroyed = false;
|
|
388
|
+
reconnecting = false;
|
|
389
|
+
reconnectAttempt = 0;
|
|
390
|
+
reconnectTimer = null;
|
|
391
|
+
reconnect;
|
|
392
|
+
reconnectMaxAttempts;
|
|
393
|
+
reconnectBaseDelay;
|
|
394
|
+
constructor(url, config) {
|
|
395
|
+
this.url = url;
|
|
396
|
+
this.reconnect = config?.reconnect ?? true;
|
|
397
|
+
this.reconnectMaxAttempts = config?.reconnectMaxAttempts ?? 10;
|
|
398
|
+
this.reconnectBaseDelay = config?.reconnectBaseDelay ?? 1000;
|
|
399
|
+
}
|
|
400
|
+
connect() {
|
|
401
|
+
if (this.ws?.readyState === WebSocket.OPEN)
|
|
402
|
+
return Promise.resolve();
|
|
403
|
+
if (this.ws?.readyState === WebSocket.CONNECTING) {
|
|
404
|
+
return new Promise((resolve, reject) => {
|
|
405
|
+
const onOpen = () => {
|
|
406
|
+
this.ws?.removeEventListener("error", onError);
|
|
407
|
+
resolve();
|
|
408
|
+
};
|
|
409
|
+
const onError = (e) => {
|
|
410
|
+
this.ws?.removeEventListener("open", onOpen);
|
|
411
|
+
reject(new WebSocketError("WebSocket connection failed", {
|
|
412
|
+
details: String(e)
|
|
413
|
+
}));
|
|
414
|
+
};
|
|
415
|
+
this.ws.addEventListener("open", onOpen, { once: true });
|
|
416
|
+
this.ws.addEventListener("error", onError, { once: true });
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return new Promise((resolve, reject) => {
|
|
420
|
+
this.ws = new WebSocket(this.url);
|
|
421
|
+
this.ws.addEventListener("open", () => {
|
|
422
|
+
this.reconnectAttempt = 0;
|
|
423
|
+
this.reconnecting = false;
|
|
424
|
+
resolve();
|
|
425
|
+
}, { once: true });
|
|
426
|
+
this.ws.addEventListener("error", (e) => {
|
|
427
|
+
reject(new WebSocketError("WebSocket connection failed", {
|
|
428
|
+
details: String(e)
|
|
429
|
+
}));
|
|
430
|
+
}, { once: true });
|
|
431
|
+
this.ws.addEventListener("message", (event) => {
|
|
432
|
+
this.handleMessage(event.data);
|
|
433
|
+
});
|
|
434
|
+
this.ws.addEventListener("close", () => {
|
|
435
|
+
if (!this.destroyed)
|
|
436
|
+
this.handleDisconnect();
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
handleMessage(raw) {
|
|
441
|
+
const data = typeof raw === "string" ? raw : new TextDecoder().decode(raw);
|
|
442
|
+
let msg;
|
|
443
|
+
try {
|
|
444
|
+
msg = JSON.parse(data);
|
|
445
|
+
} catch {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if ("id" in msg && msg.id != null) {
|
|
449
|
+
const rpc = msg;
|
|
450
|
+
const p = this.pending.get(rpc.id);
|
|
451
|
+
if (!p)
|
|
452
|
+
return;
|
|
453
|
+
this.pending.delete(rpc.id);
|
|
454
|
+
if (rpc.error) {
|
|
455
|
+
p.reject(new WebSocketError(rpc.error.message, {
|
|
456
|
+
details: `JSON-RPC error ${rpc.error.code}`
|
|
457
|
+
}));
|
|
458
|
+
} else {
|
|
459
|
+
p.resolve(rpc.result);
|
|
460
|
+
}
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const notif = msg;
|
|
464
|
+
if (!notif.method)
|
|
465
|
+
return;
|
|
466
|
+
for (const [, entry] of this.subs) {
|
|
467
|
+
if (entry.params.event === notif.method) {
|
|
468
|
+
for (const cb of entry.callbacks) {
|
|
469
|
+
try {
|
|
470
|
+
cb(notif.params);
|
|
471
|
+
} catch {}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
handleDisconnect() {
|
|
477
|
+
this.ws = null;
|
|
478
|
+
for (const [, p] of this.pending) {
|
|
479
|
+
p.reject(new WebSocketError("WebSocket disconnected"));
|
|
480
|
+
}
|
|
481
|
+
this.pending.clear();
|
|
482
|
+
if (this.reconnect && this.subs.size > 0 && this.reconnectAttempt < this.reconnectMaxAttempts) {
|
|
483
|
+
this.scheduleReconnect();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
scheduleReconnect() {
|
|
487
|
+
if (this.destroyed || this.reconnecting)
|
|
488
|
+
return;
|
|
489
|
+
this.reconnecting = true;
|
|
490
|
+
const delay = this.reconnectBaseDelay * 2 ** this.reconnectAttempt;
|
|
491
|
+
this.reconnectAttempt++;
|
|
492
|
+
this.reconnectTimer = setTimeout(async () => {
|
|
493
|
+
this.reconnecting = false;
|
|
494
|
+
try {
|
|
495
|
+
await this.connect();
|
|
496
|
+
await this.resubscribeAll();
|
|
497
|
+
} catch {
|
|
498
|
+
if (!this.destroyed && this.subs.size > 0) {
|
|
499
|
+
this.handleDisconnect();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}, delay);
|
|
503
|
+
}
|
|
504
|
+
async resubscribeAll() {
|
|
505
|
+
for (const [, entry] of this.subs) {
|
|
506
|
+
await this.sendRpc("subscribe", entry.params);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
sendRpc(method, params) {
|
|
510
|
+
return new Promise((resolve, reject) => {
|
|
511
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
512
|
+
return reject(new WebSocketError("WebSocket not connected"));
|
|
513
|
+
}
|
|
514
|
+
const id = this.nextId++;
|
|
515
|
+
const msg = {
|
|
516
|
+
jsonrpc: "2.0",
|
|
517
|
+
id,
|
|
518
|
+
method,
|
|
519
|
+
params
|
|
520
|
+
};
|
|
521
|
+
this.pending.set(id, { resolve, reject });
|
|
522
|
+
this.ws.send(JSON.stringify(msg));
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
async subscribe(params, callback) {
|
|
526
|
+
if (this.destroyed) {
|
|
527
|
+
throw new WebSocketError("WebSocket channel has been destroyed");
|
|
528
|
+
}
|
|
529
|
+
await this.connect();
|
|
530
|
+
const key = subKey(params);
|
|
531
|
+
let entry = this.subs.get(key);
|
|
532
|
+
if (entry) {
|
|
533
|
+
entry.callbacks.add(callback);
|
|
534
|
+
} else {
|
|
535
|
+
entry = { params, callbacks: new Set([callback]) };
|
|
536
|
+
this.subs.set(key, entry);
|
|
537
|
+
await this.sendRpc("subscribe", params);
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
unsubscribe: () => {
|
|
541
|
+
const e = this.subs.get(key);
|
|
542
|
+
if (!e)
|
|
543
|
+
return;
|
|
544
|
+
e.callbacks.delete(callback);
|
|
545
|
+
if (e.callbacks.size === 0) {
|
|
546
|
+
this.subs.delete(key);
|
|
547
|
+
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
548
|
+
this.sendRpc("unsubscribe", params).catch(() => {});
|
|
549
|
+
}
|
|
550
|
+
if (this.subs.size === 0)
|
|
551
|
+
this.closeQuietly();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
closeQuietly() {
|
|
557
|
+
if (this.ws) {
|
|
558
|
+
this.ws.close();
|
|
559
|
+
this.ws = null;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
destroy() {
|
|
563
|
+
this.destroyed = true;
|
|
564
|
+
if (this.reconnectTimer)
|
|
565
|
+
clearTimeout(this.reconnectTimer);
|
|
566
|
+
for (const [, p] of this.pending) {
|
|
567
|
+
p.reject(new WebSocketError("WebSocket channel destroyed"));
|
|
568
|
+
}
|
|
569
|
+
this.pending.clear();
|
|
570
|
+
this.subs.clear();
|
|
571
|
+
if (this.ws) {
|
|
572
|
+
this.ws.close();
|
|
573
|
+
this.ws = null;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function deriveWsUrl(httpUrl) {
|
|
578
|
+
return httpUrl.replace(/^http/, "ws").replace(/\/$/, "") + "/extended/v1/ws";
|
|
579
|
+
}
|
|
580
|
+
function webSocket(url, config) {
|
|
581
|
+
return (params) => {
|
|
582
|
+
const httpUrl = config?.url ?? params?.chain?.rpcUrls.default.http[0] ?? "http://localhost:3999";
|
|
583
|
+
const wsUrl = url ?? params?.chain?.rpcUrls.default.ws?.[0] ?? deriveWsUrl(httpUrl);
|
|
584
|
+
const resolvedHttpConfig = {
|
|
585
|
+
...config,
|
|
586
|
+
url: httpUrl
|
|
587
|
+
};
|
|
588
|
+
const channel = new WebSocketChannel(wsUrl, config);
|
|
589
|
+
const transport = {
|
|
590
|
+
type: "webSocket",
|
|
591
|
+
request: buildRequestFn(httpUrl, resolvedHttpConfig),
|
|
592
|
+
config: resolvedHttpConfig,
|
|
593
|
+
subscribe: (subParams, callback) => channel.subscribe(subParams, callback),
|
|
594
|
+
destroy: () => channel.destroy()
|
|
595
|
+
};
|
|
596
|
+
return transport;
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
export {
|
|
600
|
+
webSocket,
|
|
601
|
+
walletActions,
|
|
602
|
+
testnet,
|
|
603
|
+
publicActions,
|
|
604
|
+
providerToAccount,
|
|
605
|
+
parseStx,
|
|
606
|
+
multisigActions,
|
|
607
|
+
mocknet,
|
|
608
|
+
mainnet,
|
|
609
|
+
isValidAddress,
|
|
610
|
+
isAddressEqual,
|
|
611
|
+
http,
|
|
612
|
+
getContractAddress,
|
|
613
|
+
formatStx,
|
|
614
|
+
fallback,
|
|
615
|
+
devnet,
|
|
616
|
+
defineChain,
|
|
617
|
+
custom,
|
|
618
|
+
createWalletClient,
|
|
619
|
+
createPublicClient,
|
|
620
|
+
createMultiSigClient,
|
|
621
|
+
createClient,
|
|
622
|
+
ZERO_ADDRESS,
|
|
623
|
+
TESTNET_ZERO_ADDRESS,
|
|
624
|
+
MICROSTX_PER_STX,
|
|
625
|
+
AddressVersion
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
//# debugId=BE2F1CEE4CB45C8564756E2164756E21
|
|
629
|
+
//# sourceMappingURL=index.js.map
|