@secondlayer/stacks 2.5.1 → 2.6.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-1wra341e.cjs +146 -0
- package/dist/shared/stacks-1wra341e.cjs.map +15 -0
- package/dist/shared/{stacks-jevhg39n.cjs → stacks-7nf5h3qe.cjs} +16 -12
- package/dist/shared/{stacks-jevhg39n.cjs.map → stacks-7nf5h3qe.cjs.map} +4 -4
- package/dist/shared/{stacks-yq5a5cda.js → stacks-a9cn5ehj.js} +12 -10
- package/dist/shared/{stacks-yq5a5cda.js.map → stacks-a9cn5ehj.js.map} +3 -3
- package/dist/shared/{stacks-7wfdkhj6.cjs → stacks-e7pmsrbs.cjs} +9 -7
- package/dist/shared/{stacks-7wfdkhj6.cjs.map → stacks-e7pmsrbs.cjs.map} +3 -3
- package/dist/shared/{stacks-4z1jhw6y.js → stacks-ffsv2t3t.js} +6 -6
- package/dist/shared/{stacks-4z1jhw6y.js.map → stacks-ffsv2t3t.js.map} +3 -3
- package/dist/shared/{stacks-y8e3gx6w.js → stacks-gxhznn3h.js} +73 -3
- package/dist/shared/stacks-gxhznn3h.js.map +15 -0
- package/dist/shared/{stacks-hyz7zgdk.js → stacks-hr5rg2et.js} +2 -2
- package/dist/shared/{stacks-7wqprfrm.cjs → stacks-hxm7r5ay.cjs} +3 -3
- package/dist/shared/{stacks-7wqprfrm.cjs.map → stacks-hxm7r5ay.cjs.map} +3 -3
- package/dist/shared/{stacks-5th5dffx.js → stacks-yb8xesdm.js} +20 -16
- package/dist/shared/{stacks-5th5dffx.js.map → stacks-yb8xesdm.js.map} +4 -4
- package/dist/src/actions/index.d.cts +133 -120
- package/dist/src/actions/index.d.ts +133 -120
- package/dist/src/actions/index.js +5 -5
- package/dist/src/bns/index.d.cts +13 -0
- package/dist/src/bns/index.d.ts +13 -0
- package/dist/src/bns/index.js +3 -3
- package/dist/src/index.cjs +79 -5
- package/dist/src/index.cjs.map +6 -5
- package/dist/src/index.d.cts +228 -101
- package/dist/src/index.d.ts +228 -101
- package/dist/src/index.js +89 -9
- package/dist/src/index.js.map +6 -5
- package/dist/src/pox/index.d.cts +13 -0
- package/dist/src/pox/index.d.ts +13 -0
- package/dist/src/pox/index.js +3 -3
- package/dist/src/sbtc/index.d.cts +13 -0
- package/dist/src/sbtc/index.d.ts +13 -0
- package/dist/src/sbtc/index.js +3 -3
- package/dist/src/stackingdao/index.d.cts +13 -0
- package/dist/src/stackingdao/index.d.ts +13 -0
- package/dist/src/stackingdao/index.js +3 -3
- package/dist/src/subscriptions/index.d.cts +13 -0
- package/dist/src/subscriptions/index.d.ts +13 -0
- package/dist/src/tools/btc/index.cjs.map +2 -2
- package/dist/src/tools/btc/index.js.map +2 -2
- package/dist/src/tools/index.cjs +44 -14
- package/dist/src/tools/index.cjs.map +8 -7
- package/dist/src/tools/index.d.cts +13 -0
- package/dist/src/tools/index.d.ts +13 -0
- package/dist/src/tools/index.js +44 -14
- package/dist/src/tools/index.js.map +8 -7
- package/dist/src/x402/index.d.cts +13 -0
- package/dist/src/x402/index.d.ts +13 -0
- package/dist/src/x402/index.js +2 -2
- package/package.json +1 -1
- package/dist/shared/stacks-qk8pdyjy.cjs +0 -76
- package/dist/shared/stacks-qk8pdyjy.cjs.map +0 -14
- package/dist/shared/stacks-y8e3gx6w.js.map +0 -14
- /package/dist/shared/{stacks-hyz7zgdk.js.map → stacks-hr5rg2et.js.map} +0 -0
|
@@ -28,6 +28,17 @@ type ProviderAccount = {
|
|
|
28
28
|
publicKey: string
|
|
29
29
|
provider: StacksProvider
|
|
30
30
|
};
|
|
31
|
+
/** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
|
|
32
|
+
type NonceManager = {
|
|
33
|
+
consume(params: {
|
|
34
|
+
client: Client
|
|
35
|
+
address: string
|
|
36
|
+
}): Promise<bigint>
|
|
37
|
+
reset(params: {
|
|
38
|
+
client: Client
|
|
39
|
+
address: string
|
|
40
|
+
}): void | Promise<void>
|
|
41
|
+
};
|
|
31
42
|
/** Full chain descriptor used by clients and transports for network-aware operations. */
|
|
32
43
|
type StacksChain = {
|
|
33
44
|
/** Chain ID (e.g. 0x00000001 for mainnet) */
|
|
@@ -105,6 +116,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
|
|
|
105
116
|
account?: Account
|
|
106
117
|
transport: Transport
|
|
107
118
|
request: RequestFn
|
|
119
|
+
/** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
|
|
120
|
+
nonceManager?: NonceManager
|
|
108
121
|
extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
|
|
109
122
|
} & TExtended;
|
|
110
123
|
/**
|
|
@@ -28,6 +28,17 @@ type ProviderAccount = {
|
|
|
28
28
|
publicKey: string
|
|
29
29
|
provider: StacksProvider
|
|
30
30
|
};
|
|
31
|
+
/** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
|
|
32
|
+
type NonceManager = {
|
|
33
|
+
consume(params: {
|
|
34
|
+
client: Client
|
|
35
|
+
address: string
|
|
36
|
+
}): Promise<bigint>
|
|
37
|
+
reset(params: {
|
|
38
|
+
client: Client
|
|
39
|
+
address: string
|
|
40
|
+
}): void | Promise<void>
|
|
41
|
+
};
|
|
31
42
|
/** Full chain descriptor used by clients and transports for network-aware operations. */
|
|
32
43
|
type StacksChain = {
|
|
33
44
|
/** Chain ID (e.g. 0x00000001 for mainnet) */
|
|
@@ -105,6 +116,8 @@ type Client<TExtended extends Record<string, unknown> = Record<string, unknown>>
|
|
|
105
116
|
account?: Account
|
|
106
117
|
transport: Transport
|
|
107
118
|
request: RequestFn
|
|
119
|
+
/** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
|
|
120
|
+
nonceManager?: NonceManager
|
|
108
121
|
extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
|
|
109
122
|
} & TExtended;
|
|
110
123
|
/**
|
package/dist/src/tools/index.js
CHANGED
|
@@ -1308,14 +1308,6 @@ function getTransactionId(tx) {
|
|
|
1308
1308
|
return txid(tx);
|
|
1309
1309
|
}
|
|
1310
1310
|
|
|
1311
|
-
// src/actions/public/getNonce.ts
|
|
1312
|
-
async function getNonce(client, params) {
|
|
1313
|
-
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
1314
|
-
method: "GET"
|
|
1315
|
-
});
|
|
1316
|
-
return BigInt(data.nonce);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
1311
|
// src/errors/base.ts
|
|
1320
1312
|
class BaseError extends Error {
|
|
1321
1313
|
name = "StacksError";
|
|
@@ -1354,6 +1346,14 @@ class BroadcastError extends BaseError {
|
|
|
1354
1346
|
}
|
|
1355
1347
|
}
|
|
1356
1348
|
|
|
1349
|
+
// src/actions/public/getNonce.ts
|
|
1350
|
+
async function getNonce(client, params) {
|
|
1351
|
+
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
1352
|
+
method: "GET"
|
|
1353
|
+
});
|
|
1354
|
+
return BigInt(data.nonce);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
1357
|
// src/actions/wallet/sendTransaction.ts
|
|
1358
1358
|
async function sendTransaction(client, params) {
|
|
1359
1359
|
const hex = bytesToHex(serializeTransaction(params.transaction));
|
|
@@ -1374,6 +1374,32 @@ async function sendTransaction(client, params) {
|
|
|
1374
1374
|
return { txid: txid2 };
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
1377
|
+
// src/actions/wallet/nonceManager.ts
|
|
1378
|
+
async function resolveNonce(client, address) {
|
|
1379
|
+
if (client.nonceManager)
|
|
1380
|
+
return client.nonceManager.consume({ client, address });
|
|
1381
|
+
return getNonce(client, { address });
|
|
1382
|
+
}
|
|
1383
|
+
function isNonceConflictError(error) {
|
|
1384
|
+
if (!(error instanceof BroadcastError))
|
|
1385
|
+
return false;
|
|
1386
|
+
const haystack = `${error.reason ?? ""} ${error.message}`.toLowerCase();
|
|
1387
|
+
return haystack.includes("nonce");
|
|
1388
|
+
}
|
|
1389
|
+
async function broadcastWithNonceReset(client, params) {
|
|
1390
|
+
try {
|
|
1391
|
+
const result = await sendTransaction(client, {
|
|
1392
|
+
transaction: params.transaction
|
|
1393
|
+
});
|
|
1394
|
+
return result.txid;
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
if (client.nonceManager && isNonceConflictError(error)) {
|
|
1397
|
+
await client.nonceManager.reset({ client, address: params.address });
|
|
1398
|
+
}
|
|
1399
|
+
throw error;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1377
1403
|
// src/actions/wallet/utils.ts
|
|
1378
1404
|
function isProviderAccount(account) {
|
|
1379
1405
|
return account.type === "provider";
|
|
@@ -1385,15 +1411,15 @@ async function callContract(client, params) {
|
|
|
1385
1411
|
if (!account)
|
|
1386
1412
|
throw new Error("Account required");
|
|
1387
1413
|
if (isProviderAccount(account)) {
|
|
1388
|
-
const
|
|
1414
|
+
const result = await account.provider.request("stx_callContract", {
|
|
1389
1415
|
contract: params.contract,
|
|
1390
1416
|
functionName: params.functionName,
|
|
1391
1417
|
functionArgs: params.functionArgs ?? []
|
|
1392
1418
|
});
|
|
1393
|
-
return
|
|
1419
|
+
return result.txid;
|
|
1394
1420
|
}
|
|
1395
1421
|
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
1396
|
-
const nonce = params.nonce ?? await
|
|
1422
|
+
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
1397
1423
|
const unsigned = buildContractCall({
|
|
1398
1424
|
contractAddress,
|
|
1399
1425
|
contractName,
|
|
@@ -1414,8 +1440,10 @@ async function callContract(client, params) {
|
|
|
1414
1440
|
}
|
|
1415
1441
|
}
|
|
1416
1442
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
1417
|
-
|
|
1418
|
-
|
|
1443
|
+
return broadcastWithNonceReset(client, {
|
|
1444
|
+
transaction: signed,
|
|
1445
|
+
address: account.address
|
|
1446
|
+
});
|
|
1419
1447
|
}
|
|
1420
1448
|
|
|
1421
1449
|
// src/actions/getContract.ts
|
|
@@ -2149,6 +2177,7 @@ var BASE_KEYS = new Set([
|
|
|
2149
2177
|
"account",
|
|
2150
2178
|
"transport",
|
|
2151
2179
|
"request",
|
|
2180
|
+
"nonceManager",
|
|
2152
2181
|
"extend"
|
|
2153
2182
|
]);
|
|
2154
2183
|
function bindExtend(base) {
|
|
@@ -2171,6 +2200,7 @@ function createClient(config) {
|
|
|
2171
2200
|
account: config.account,
|
|
2172
2201
|
transport,
|
|
2173
2202
|
request: transport.request,
|
|
2203
|
+
nonceManager: config.nonceManager,
|
|
2174
2204
|
extend: null
|
|
2175
2205
|
};
|
|
2176
2206
|
client.extend = bindExtend(client);
|
|
@@ -2685,5 +2715,5 @@ export {
|
|
|
2685
2715
|
bnsResolve
|
|
2686
2716
|
};
|
|
2687
2717
|
|
|
2688
|
-
//# debugId=
|
|
2718
|
+
//# debugId=F35406DC34C9BAB964756E2164756E21
|
|
2689
2719
|
//# sourceMappingURL=index.js.map
|