@aibtc/mcp-server 1.36.0 → 1.37.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.
Files changed (50) hide show
  1. package/dist/services/defi.service.d.ts.map +1 -1
  2. package/dist/services/defi.service.js +4 -17
  3. package/dist/services/defi.service.js.map +1 -1
  4. package/dist/services/wallet-manager.d.ts.map +1 -1
  5. package/dist/services/wallet-manager.js +7 -0
  6. package/dist/services/wallet-manager.js.map +1 -1
  7. package/dist/tools/contract.tools.d.ts.map +1 -1
  8. package/dist/tools/contract.tools.js +3 -2
  9. package/dist/tools/contract.tools.js.map +1 -1
  10. package/dist/tools/index.d.ts.map +1 -1
  11. package/dist/tools/index.js +15 -0
  12. package/dist/tools/index.js.map +1 -1
  13. package/dist/tools/jingswap.tools.d.ts +3 -0
  14. package/dist/tools/jingswap.tools.d.ts.map +1 -0
  15. package/dist/tools/jingswap.tools.js +471 -0
  16. package/dist/tools/jingswap.tools.js.map +1 -0
  17. package/dist/tools/nostr.tools.d.ts +3 -0
  18. package/dist/tools/nostr.tools.d.ts.map +1 -0
  19. package/dist/tools/nostr.tools.js +409 -0
  20. package/dist/tools/nostr.tools.js.map +1 -0
  21. package/dist/tools/ordinals-p2p.tools.d.ts +21 -0
  22. package/dist/tools/ordinals-p2p.tools.d.ts.map +1 -0
  23. package/dist/tools/ordinals-p2p.tools.js +621 -0
  24. package/dist/tools/ordinals-p2p.tools.js.map +1 -0
  25. package/dist/tools/relay-diagnostic.tools.d.ts.map +1 -1
  26. package/dist/tools/relay-diagnostic.tools.js +27 -4
  27. package/dist/tools/relay-diagnostic.tools.js.map +1 -1
  28. package/dist/tools/skill-mappings.d.ts.map +1 -1
  29. package/dist/tools/skill-mappings.js +13 -1
  30. package/dist/tools/skill-mappings.js.map +1 -1
  31. package/dist/tools/stacks-market.tools.d.ts +22 -0
  32. package/dist/tools/stacks-market.tools.d.ts.map +1 -0
  33. package/dist/tools/stacks-market.tools.js +630 -0
  34. package/dist/tools/stacks-market.tools.js.map +1 -0
  35. package/dist/tools/taproot-multisig.tools.d.ts +17 -0
  36. package/dist/tools/taproot-multisig.tools.d.ts.map +1 -0
  37. package/dist/tools/taproot-multisig.tools.js +236 -0
  38. package/dist/tools/taproot-multisig.tools.js.map +1 -0
  39. package/dist/tools/transfer.tools.js +1 -1
  40. package/dist/tools/transfer.tools.js.map +1 -1
  41. package/dist/transactions/builder.d.ts +35 -1
  42. package/dist/transactions/builder.d.ts.map +1 -1
  43. package/dist/transactions/builder.js +153 -4
  44. package/dist/transactions/builder.js.map +1 -1
  45. package/dist/utils/fee.d.ts +15 -0
  46. package/dist/utils/fee.d.ts.map +1 -1
  47. package/dist/utils/fee.js +36 -4
  48. package/dist/utils/fee.js.map +1 -1
  49. package/package.json +4 -1
  50. package/skill/SKILL.md +1 -1
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Taproot Multisig Tools
3
+ *
4
+ * MCP tools for Taproot M-of-N multisig coordination between agents.
5
+ *
6
+ * - taproot_get_pubkey: Derive the x-only Taproot public key from the active wallet
7
+ * (BIP-86 path m/86'/0'/0'/0/0). Requires wallet unlock.
8
+ *
9
+ * - taproot_verify_cosig: Verify a Schnorr signature against a BIP-341 sighash.
10
+ * Read-only — no wallet needed.
11
+ *
12
+ * - taproot_multisig_guide: Return a step-by-step guide for M-of-N Taproot multisig
13
+ * coordination using OP_CHECKSIGADD (BIP-341/342). Read-only.
14
+ */
15
+ import { schnorr } from "@noble/curves/secp256k1.js";
16
+ import { z } from "zod";
17
+ import { getWalletManager } from "../services/wallet-manager.js";
18
+ import { createErrorResponse, createJsonResponse } from "../utils/index.js";
19
+ export function registerTaprootMultisigTools(server) {
20
+ // ---------------------------------------------------------------------------
21
+ // taproot_get_pubkey
22
+ // ---------------------------------------------------------------------------
23
+ server.registerTool("taproot_get_pubkey", {
24
+ description: "Derive the x-only Taproot public key (32 bytes hex) from the active wallet using the " +
25
+ "BIP-86 derivation path m/86'/0'/0'/0/0. " +
26
+ "Share this pubkey with co-signers to construct a Taproot multisig script tree. " +
27
+ "Requires the wallet to be unlocked (use wallet_unlock first).",
28
+ inputSchema: {},
29
+ }, async () => {
30
+ try {
31
+ const walletManager = getWalletManager();
32
+ const account = walletManager.getActiveAccount();
33
+ if (!account?.taprootPublicKey) {
34
+ throw new Error("Taproot key not available. Unlock your wallet first with wallet_unlock.");
35
+ }
36
+ if (account.taprootPublicKey.length !== 32) {
37
+ throw new Error(`Unexpected taproot public key length: ${account.taprootPublicKey.length} bytes (expected 32).`);
38
+ }
39
+ const pubkeyHex = Buffer.from(account.taprootPublicKey).toString("hex");
40
+ return createJsonResponse({
41
+ success: true,
42
+ pubkey: pubkeyHex,
43
+ encoding: "x-only (BIP-340, 32 bytes hex)",
44
+ derivationPath: "m/86'/0'/0'/0/0",
45
+ note: "Share this pubkey with co-signers. Use taproot_multisig_guide for coordination steps.",
46
+ });
47
+ }
48
+ catch (error) {
49
+ return createErrorResponse(error);
50
+ }
51
+ });
52
+ // ---------------------------------------------------------------------------
53
+ // taproot_verify_cosig
54
+ // ---------------------------------------------------------------------------
55
+ server.registerTool("taproot_verify_cosig", {
56
+ description: "Verify a Schnorr co-signature against a BIP-341 sighash. " +
57
+ "Use this to confirm that a co-signer's signature is valid before combining and broadcasting. " +
58
+ "Read-only — no wallet unlock required.",
59
+ inputSchema: {
60
+ sighash: z
61
+ .string()
62
+ .length(64)
63
+ .regex(/^[0-9a-fA-F]+$/, "must be valid hex")
64
+ .describe("BIP-341 sighash as 32-byte hex string (64 hex chars). " +
65
+ "This is the transaction commitment that was signed."),
66
+ signature: z
67
+ .string()
68
+ .length(128)
69
+ .regex(/^[0-9a-fA-F]+$/, "must be valid hex")
70
+ .describe("Schnorr signature as 64-byte hex string (128 hex chars, BIP-340 format)."),
71
+ pubkey: z
72
+ .string()
73
+ .length(64)
74
+ .regex(/^[0-9a-fA-F]+$/, "must be valid hex")
75
+ .describe("Signer's x-only public key as 32-byte hex string (64 hex chars). " +
76
+ "Obtain via taproot_get_pubkey from each co-signer."),
77
+ },
78
+ }, async ({ sighash, signature, pubkey }) => {
79
+ try {
80
+ const sighashBytes = Buffer.from(sighash, "hex");
81
+ const signatureBytes = Buffer.from(signature, "hex");
82
+ const pubkeyBytes = Buffer.from(pubkey, "hex");
83
+ if (sighashBytes.length !== 32) {
84
+ throw new Error(`sighash must be exactly 32 bytes (64 hex chars), got ${sighashBytes.length} bytes.`);
85
+ }
86
+ if (signatureBytes.length !== 64) {
87
+ throw new Error(`signature must be exactly 64 bytes (128 hex chars), got ${signatureBytes.length} bytes.`);
88
+ }
89
+ if (pubkeyBytes.length !== 32) {
90
+ throw new Error(`pubkey must be exactly 32 bytes (64 hex chars), got ${pubkeyBytes.length} bytes.`);
91
+ }
92
+ const valid = schnorr.verify(signatureBytes, sighashBytes, pubkeyBytes);
93
+ return createJsonResponse({
94
+ valid,
95
+ sighash,
96
+ signature,
97
+ pubkey,
98
+ message: valid
99
+ ? "Signature is valid. This co-signer's Schnorr signature is authentic."
100
+ : "Signature is INVALID. Do not proceed with this co-signer's input.",
101
+ });
102
+ }
103
+ catch (error) {
104
+ return createErrorResponse(error);
105
+ }
106
+ });
107
+ // ---------------------------------------------------------------------------
108
+ // taproot_multisig_guide
109
+ // ---------------------------------------------------------------------------
110
+ server.registerTool("taproot_multisig_guide", {
111
+ description: "Return a step-by-step guide for M-of-N Taproot multisig coordination between agents " +
112
+ "using OP_CHECKSIGADD (BIP-341/342). Read-only — no wallet needed.",
113
+ inputSchema: {
114
+ m: z
115
+ .number()
116
+ .int()
117
+ .min(1)
118
+ .max(20)
119
+ .optional()
120
+ .default(2)
121
+ .describe("Number of required signatures (default: 2)."),
122
+ n: z
123
+ .number()
124
+ .int()
125
+ .min(1)
126
+ .max(20)
127
+ .optional()
128
+ .default(3)
129
+ .describe("Total number of co-signers (default: 3)."),
130
+ },
131
+ }, async ({ m, n }) => {
132
+ if (m > n) {
133
+ return createErrorResponse(new Error(`Invalid parameters: m (${m}) cannot exceed n (${n}).`));
134
+ }
135
+ const guide = {
136
+ title: `${m}-of-${n} Taproot Multisig Coordination Guide`,
137
+ overview: `Taproot M-of-N multisig uses OP_CHECKSIGADD (BIP-342) inside a Taproot script leaf (BIP-341). ` +
138
+ `Each co-signer holds an independent BIP-86 keypair and signs the same BIP-341 sighash ` +
139
+ `with a Schnorr signature. No interaction is required during signing — co-signers collect ` +
140
+ `each other's signatures and combine them off-chain before broadcast.`,
141
+ steps: [
142
+ {
143
+ step: 1,
144
+ title: "Exchange x-only public keys",
145
+ details: [
146
+ `Each of the ${n} co-signers calls taproot_get_pubkey to obtain their x-only BIP-86 pubkey (32 bytes).`,
147
+ "Share pubkeys out-of-band (e.g. via the AIBTC inbox or a shared coordination channel).",
148
+ "Agree on a canonical ordering of the pubkeys (e.g. lexicographic ascending). This order must be consistent across all participants.",
149
+ ],
150
+ bip: "BIP-86 (key derivation), BIP-340 (x-only pubkey encoding)",
151
+ },
152
+ {
153
+ step: 2,
154
+ title: "Construct the Taproot script leaf with OP_CHECKSIGADD",
155
+ details: [
156
+ `Assemble the ${m}-of-${n} script using the agreed pubkey order:`,
157
+ ` <pubkey_1> OP_CHECKSIG <pubkey_2> OP_CHECKSIGADD ... <pubkey_${n}> OP_CHECKSIGADD OP_${m} OP_NUMEQUAL`,
158
+ "Compute the TapLeaf hash: SHA256(0xC0 || compact_size(script_len) || script).",
159
+ "Build the Taproot output key: internalKey = KeyAgg(pubkeys) tweaked by TapTweak.",
160
+ "The final P2TR address is: OP_1 <32-byte_output_key>.",
161
+ "All co-signers must independently verify they compute the same P2TR address before funding.",
162
+ ],
163
+ bip: "BIP-341 (Taproot output construction), BIP-342 (Tapscript OP_CHECKSIGADD)",
164
+ },
165
+ {
166
+ step: 3,
167
+ title: "Create the PSBT",
168
+ details: [
169
+ "One co-signer (the initiator) constructs the unsigned PSBT encoding the spending transaction.",
170
+ "The PSBT input must include: witnessUtxo (the P2TR output being spent), tapLeafScript (the multisig leaf), and tapBip32Derivation for each signer.",
171
+ "Compute the BIP-341 sighash (SIGHASH_DEFAULT = 0x00) over the PSBT using the script-path spending rules.",
172
+ "Distribute the PSBT and the sighash hex to all co-signers.",
173
+ ],
174
+ bip: "BIP-174 (PSBT), BIP-341 §Common signature message",
175
+ },
176
+ {
177
+ step: 4,
178
+ title: "Sign independently with Schnorr",
179
+ details: [
180
+ "Each co-signer receives the PSBT and signs the BIP-341 sighash with their BIP-86 Taproot private key.",
181
+ "Use psbt_sign (or use raw sighash signing when available) to produce a 64-byte BIP-340 Schnorr signature.",
182
+ `Only ${m} of the ${n} co-signers need to sign — but all ${n} must verify.`,
183
+ "Each signer returns their (pubkey, signature) pair to the combiner.",
184
+ ],
185
+ bip: "BIP-340 (Schnorr signatures), BIP-342 (script-path spending)",
186
+ },
187
+ {
188
+ step: 5,
189
+ title: "Verify co-signatures with taproot_verify_cosig",
190
+ details: [
191
+ "The combiner calls taproot_verify_cosig for each received (sighash, signature, pubkey) tuple.",
192
+ `Collect at least ${m} valid signatures before proceeding.`,
193
+ "Reject any signature that returns valid: false.",
194
+ "This step ensures no invalid or malformed signatures enter the final PSBT.",
195
+ ],
196
+ tool: "taproot_verify_cosig",
197
+ },
198
+ {
199
+ step: 6,
200
+ title: "Combine signatures and broadcast",
201
+ details: [
202
+ `Insert the ${m} valid Schnorr signatures into the PSBT as tapScriptSig entries (one per signer).`,
203
+ "The witness stack for OP_CHECKSIGADD script-path spending is: [sig_1, sig_2, ..., sig_m, script, control_block].",
204
+ "Absent signers (in an M < N setup) provide an empty stack item (0x00) as placeholder.",
205
+ "Finalize the PSBT (psbt_broadcast or psbt_sign with finalizeSignedInputs: true).",
206
+ "Broadcast the finalized transaction to the Bitcoin network.",
207
+ ],
208
+ bip: "BIP-341 §Script path spending, BIP-342 §Validation",
209
+ tool: "psbt_broadcast",
210
+ },
211
+ ],
212
+ securityNotes: [
213
+ "Never share your private key. Only share x-only public keys and signatures.",
214
+ "Always verify the P2TR address before funding — an incorrect script tree cannot be spent.",
215
+ "Verify co-signatures with taproot_verify_cosig before broadcasting.",
216
+ "Use a fresh nonce for each signing session to avoid nonce reuse attacks (handled automatically by @noble/curves).",
217
+ "For high-value multisig, use an air-gapped signer and verify the sighash independently.",
218
+ ],
219
+ tools: {
220
+ get_pubkey: "taproot_get_pubkey",
221
+ verify_cosig: "taproot_verify_cosig",
222
+ sign_psbt: "psbt_sign",
223
+ broadcast: "psbt_broadcast",
224
+ decode_psbt: "psbt_decode",
225
+ },
226
+ references: [
227
+ "BIP-340: https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki",
228
+ "BIP-341: https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki",
229
+ "BIP-342: https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki",
230
+ "BIP-86: https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki",
231
+ ],
232
+ };
233
+ return createJsonResponse(guide);
234
+ });
235
+ }
236
+ //# sourceMappingURL=taproot-multisig.tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"taproot-multisig.tools.js","sourceRoot":"","sources":["../../src/tools/taproot-multisig.tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5E,MAAM,UAAU,4BAA4B,CAAC,MAAiB;IAC5D,8EAA8E;IAC9E,qBAAqB;IACrB,8EAA8E;IAC9E,MAAM,CAAC,YAAY,CACjB,oBAAoB,EACpB;QACE,WAAW,EACT,uFAAuF;YACvF,0CAA0C;YAC1C,iFAAiF;YACjF,+DAA+D;QACjE,WAAW,EAAE,EAAE;KAChB,EACD,KAAK,IAAI,EAAE;QACT,IAAI,CAAC;YACH,MA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UAAU,EAAE,oBAAoB;gBAChC,YAAY,EAAE,sBAAsB;gBACpC,SAAS,EAAE,WAAW;gBACtB,SAAS,EAAE,gBAAgB;gBAC3B,WAAW,EAAE,aAAa;aAC3B;YACD,UAAU,EAAE;gBACV,yEAAyE;gBACzE,yEAAyE;gBACzE,yEAAyE;gBACzE,yEAAyE;aAC1E;SACF,CAAC;QAEF,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -21,7 +21,7 @@ Example: To send 2 STX, use amount "2000000" (micro-STX).
21
21
  fee: z
22
22
  .string()
23
23
  .optional()
24
- .describe("Optional fee: 'low' | 'medium' | 'high' preset or micro-STX amount. If omitted, auto-estimated. Ignored when sponsored=true."),
24
+ .describe("Optional fee: 'low' | 'medium' | 'high' preset or micro-STX amount. Clamped to 3,000 uSTX max for STX transfers. If omitted, medium-priority fee is auto-resolved. Ignored when sponsored=true."),
25
25
  sponsored: sponsoredSchema,
26
26
  },
27
27
  }, async ({ recipient, amount, memo, fee, sponsored }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"transfer.tools.js","sourceRoot":"","sources":["../../src/tools/transfer.tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAuB,MAAM,4BAA4B,CAAC;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,UAAU,qBAAqB,CAAC,MAAiB;IACrD,eAAe;IACf,MAAM,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AAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAEnE,OAAO,kBAAkB,CAAC;gBACxB,OAAO,EAAE,IAAI;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC;aACpD,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -1,6 +1,40 @@
1
1
  import { ClarityValue, PostConditionMode, PostCondition } from "@stacks/transactions";
2
2
  import { type Network } from "../config/networks.js";
3
3
  import type { WalletAddresses } from "../utils/storage.js";
4
+ /**
5
+ * Maximum number of addresses tracked simultaneously in pendingNonces and
6
+ * pendingNonceTimestamps. When this limit is reached the oldest entry (by
7
+ * insertion order) is evicted before a new one is added. This prevents
8
+ * unbounded memory growth in long-running server processes (issue #336).
9
+ */
10
+ export declare const MAX_NONCE_ENTRIES = 100;
11
+ /**
12
+ * Exported references to the internal nonce Maps for unit testing only.
13
+ * Do not use these outside of test files.
14
+ */
15
+ export declare const _testingNonceMaps: {
16
+ pendingNonces: Map<string, bigint>;
17
+ pendingNonceTimestamps: Map<string, number>;
18
+ STALE_NONCE_MS: number;
19
+ };
20
+ /**
21
+ * Reset the pending nonce for an address (called on wallet unlock/lock/switch
22
+ * so the counter re-syncs with the chain on the next transaction).
23
+ */
24
+ export declare function resetPendingNonce(address: string): void;
25
+ /**
26
+ * Force-resync the local pending nonce for an address.
27
+ * Identical to resetPendingNonce but exported under a name that makes the
28
+ * intent clear for the recover_sponsor_nonce tool's resync-local-nonce action.
29
+ */
30
+ export declare function forceResyncNonce(address: string): void;
31
+ /**
32
+ * Record that a transaction with `nonce` was successfully broadcast for
33
+ * `address`, so the next call advances past it.
34
+ *
35
+ * Exported for unit testing. Not part of the public API.
36
+ */
37
+ export declare function advancePendingNonce(address: string, nonce: bigint): void;
4
38
  export interface Account extends WalletAddresses {
5
39
  privateKey: string;
6
40
  /**
@@ -57,7 +91,7 @@ export interface ContractDeployOptions {
57
91
  }
58
92
  /**
59
93
  * Transfer STX tokens to a recipient
60
- * @param fee Optional fee in micro-STX. If omitted, fee is auto-estimated.
94
+ * @param fee Optional fee in micro-STX. If omitted, a medium-priority clamped fee is resolved.
61
95
  */
62
96
  export declare function transferStx(account: Account, recipient: string, amount: bigint, memo?: string, fee?: bigint): Promise<TransferResult>;
63
97
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/transactions/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAmC,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,WAAW,OAAQ,SAAQ,eAAe;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B;;OAEG;IACH,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B;;OAEG;IACH,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAC9B;;;;OAIG;IACH,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B;;;;OAIG;IACH,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YA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;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAmB7C;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAmB3B;AAED,cAAc,sBAAsB,CAAC"}
@@ -1,19 +1,157 @@
1
1
  import { makeSTXTokenTransfer, makeContractCall, makeContractDeploy, broadcastTransaction, PostConditionMode, } from "@stacks/transactions";
2
2
  import { hexToBytes } from "@stacks/common";
3
3
  import { getStacksNetwork, getApiBaseUrl } from "../config/networks.js";
4
+ import { getHiroApi } from "../services/hiro-api.js";
5
+ import { resolveDefaultFee } from "../utils/fee.js";
6
+ // ---------------------------------------------------------------------------
7
+ // Pending nonce tracking (fixes back-to-back tx nonce collision, issue #326)
8
+ // ---------------------------------------------------------------------------
9
+ /**
10
+ * How long a locally-tracked pending nonce is considered fresh.
11
+ * If no new transaction has been broadcast within this window the counter is
12
+ * stale (the tx likely confirmed or was dropped) and we fall back to the
13
+ * network value on the next call.
14
+ */
15
+ const STALE_NONCE_MS = 10 * 60 * 1000; // 10 minutes
16
+ /**
17
+ * Maximum number of addresses tracked simultaneously in pendingNonces and
18
+ * pendingNonceTimestamps. When this limit is reached the oldest entry (by
19
+ * insertion order) is evicted before a new one is added. This prevents
20
+ * unbounded memory growth in long-running server processes (issue #336).
21
+ */
22
+ export const MAX_NONCE_ENTRIES = 100;
23
+ /**
24
+ * Evict the oldest entry from a Map when it has reached MAX_NONCE_ENTRIES.
25
+ * JS Maps iterate in insertion order, so map.keys().next() yields the oldest
26
+ * key — no additional bookkeeping is needed.
27
+ */
28
+ function evictOldestIfFull(map) {
29
+ if (map.size >= MAX_NONCE_ENTRIES) {
30
+ const oldestKey = map.keys().next().value;
31
+ if (oldestKey !== undefined) {
32
+ map.delete(oldestKey);
33
+ }
34
+ }
35
+ }
36
+ /**
37
+ * In-memory map of STX address -> next expected nonce for non-sponsored txs.
38
+ * Updated after each successful broadcast so sequential calls don't re-use
39
+ * the same network nonce before the first tx lands in the mempool.
40
+ * Bounded to MAX_NONCE_ENTRIES entries; oldest evicted on overflow (issue #336).
41
+ */
42
+ const pendingNonces = new Map();
43
+ /**
44
+ * Tracks when each address last advanced its local nonce counter.
45
+ * Used to detect stale entries: if no transaction was sent within STALE_NONCE_MS
46
+ * the counter is expired and the network value is authoritative again.
47
+ * Bounded to MAX_NONCE_ENTRIES entries; oldest evicted on overflow (issue #336).
48
+ */
49
+ const pendingNonceTimestamps = new Map();
50
+ /**
51
+ * Exported references to the internal nonce Maps for unit testing only.
52
+ * Do not use these outside of test files.
53
+ */
54
+ export const _testingNonceMaps = {
55
+ pendingNonces,
56
+ pendingNonceTimestamps,
57
+ STALE_NONCE_MS,
58
+ };
59
+ /**
60
+ * Reset the pending nonce for an address (called on wallet unlock/lock/switch
61
+ * so the counter re-syncs with the chain on the next transaction).
62
+ */
63
+ export function resetPendingNonce(address) {
64
+ pendingNonces.delete(address);
65
+ pendingNonceTimestamps.delete(address);
66
+ }
67
+ /**
68
+ * Force-resync the local pending nonce for an address.
69
+ * Identical to resetPendingNonce but exported under a name that makes the
70
+ * intent clear for the recover_sponsor_nonce tool's resync-local-nonce action.
71
+ */
72
+ export function forceResyncNonce(address) {
73
+ resetPendingNonce(address);
74
+ }
75
+ /**
76
+ * Fetch the next nonce to use for `address`.
77
+ *
78
+ * Algorithm:
79
+ * 1. Fetch `possible_next_nonce` and `detected_missing_nonces` from Hiro.
80
+ * 2. If the local counter exists but is older than STALE_NONCE_MS, discard it
81
+ * so a stale counter never permanently blocks a recovered wallet.
82
+ * 3. Return max(possible_next_nonce, local_pending) so rapid sequential calls
83
+ * get strictly increasing nonces even before the mempool reflects the first tx.
84
+ * 4. Warn if the network reports missing nonces — gaps below the pending counter
85
+ * can cause the queue to stall until the gaps are filled.
86
+ */
87
+ async function getNextNonce(address, network) {
88
+ // Stale-timeout: discard local counter if it hasn't been refreshed recently.
89
+ const lastAdvanced = pendingNonceTimestamps.get(address);
90
+ const isStale = lastAdvanced !== undefined && Date.now() - lastAdvanced > STALE_NONCE_MS;
91
+ if (isStale) {
92
+ pendingNonces.delete(address);
93
+ pendingNonceTimestamps.delete(address);
94
+ }
95
+ const pending = pendingNonces.get(address) ?? 0n;
96
+ try {
97
+ const hiroApi = getHiroApi(network);
98
+ const nonceInfo = await hiroApi.getNonceInfo(address);
99
+ const networkNext = BigInt(nonceInfo.possible_next_nonce);
100
+ // Warn about detected nonce gaps that could stall the queue.
101
+ if (nonceInfo.detected_missing_nonces && nonceInfo.detected_missing_nonces.length > 0) {
102
+ console.warn(`[nonce] detected_missing_nonces for ${address}: [${nonceInfo.detected_missing_nonces.join(", ")}]. ` +
103
+ `These gaps may stall pending transactions. Use recover_sponsor_nonce with action=fill-gaps to resolve.`);
104
+ }
105
+ return networkNext > pending ? networkNext : pending;
106
+ }
107
+ catch (err) {
108
+ // Fallback: if we have a fresh local counter, use it to keep the queue moving
109
+ // even when Hiro is temporarily unreachable (e.g., between rapid sequential calls).
110
+ if (pending > 0n) {
111
+ console.warn(`[nonce] API call failed, using local pending counter (${pending}) for ${address}:`, err);
112
+ return pending;
113
+ }
114
+ throw err;
115
+ }
116
+ }
117
+ /**
118
+ * Record that a transaction with `nonce` was successfully broadcast for
119
+ * `address`, so the next call advances past it.
120
+ *
121
+ * Exported for unit testing. Not part of the public API.
122
+ */
123
+ export function advancePendingNonce(address, nonce) {
124
+ const next = nonce + 1n;
125
+ const current = pendingNonces.get(address) ?? 0n;
126
+ if (next > current) {
127
+ // Evict oldest entry before inserting a new address to keep maps bounded.
128
+ // Only evict when this is a new address — updates to existing keys don't
129
+ // change Map size so no eviction is needed.
130
+ if (!pendingNonces.has(address)) {
131
+ evictOldestIfFull(pendingNonces);
132
+ evictOldestIfFull(pendingNonceTimestamps);
133
+ }
134
+ pendingNonces.set(address, next);
135
+ pendingNonceTimestamps.set(address, Date.now());
136
+ }
137
+ }
4
138
  /**
5
139
  * Transfer STX tokens to a recipient
6
- * @param fee Optional fee in micro-STX. If omitted, fee is auto-estimated.
140
+ * @param fee Optional fee in micro-STX. If omitted, a medium-priority clamped fee is resolved.
7
141
  */
8
142
  export async function transferStx(account, recipient, amount, memo, fee) {
9
143
  const networkName = getStacksNetwork(account.network);
144
+ const nonce = await getNextNonce(account.address, account.network);
145
+ // Always resolve a clamped fee — prevents @stacks/transactions from over-estimating.
146
+ const resolvedFee = fee ?? await resolveDefaultFee(account.network, "token_transfer");
10
147
  const transaction = await makeSTXTokenTransfer({
11
148
  recipient,
12
149
  amount,
13
150
  senderKey: account.privateKey,
14
151
  network: networkName,
15
152
  memo: memo || "",
16
- ...(fee !== undefined && { fee }),
153
+ nonce,
154
+ fee: resolvedFee,
17
155
  });
18
156
  const broadcastResponse = await broadcastTransaction({
19
157
  transaction,
@@ -22,6 +160,7 @@ export async function transferStx(account, recipient, amount, memo, fee) {
22
160
  if ("error" in broadcastResponse) {
23
161
  throw new Error(`Broadcast failed: ${broadcastResponse.error} - ${broadcastResponse.reason}`);
24
162
  }
163
+ advancePendingNonce(account.address, nonce);
25
164
  return {
26
165
  txid: broadcastResponse.txid,
27
166
  rawTx: transaction.serialize(),
@@ -32,6 +171,9 @@ export async function transferStx(account, recipient, amount, memo, fee) {
32
171
  */
33
172
  export async function callContract(account, options) {
34
173
  const networkName = getStacksNetwork(account.network);
174
+ const nonce = await getNextNonce(account.address, account.network);
175
+ // Always resolve a clamped fee — prevents @stacks/transactions from over-estimating.
176
+ const resolvedFee = options.fee ?? await resolveDefaultFee(account.network, "contract_call");
35
177
  const transaction = await makeContractCall({
36
178
  contractAddress: options.contractAddress,
37
179
  contractName: options.contractName,
@@ -39,9 +181,10 @@ export async function callContract(account, options) {
39
181
  functionArgs: options.functionArgs,
40
182
  senderKey: account.privateKey,
41
183
  network: networkName,
184
+ nonce,
42
185
  postConditionMode: options.postConditionMode || PostConditionMode.Deny,
43
186
  postConditions: options.postConditions || [],
44
- ...(options.fee !== undefined && { fee: options.fee }),
187
+ fee: resolvedFee,
45
188
  });
46
189
  const broadcastResponse = await broadcastTransaction({
47
190
  transaction,
@@ -50,6 +193,7 @@ export async function callContract(account, options) {
50
193
  if ("error" in broadcastResponse) {
51
194
  throw new Error(`Broadcast failed: ${broadcastResponse.error} - ${broadcastResponse.reason}`);
52
195
  }
196
+ advancePendingNonce(account.address, nonce);
53
197
  return {
54
198
  txid: broadcastResponse.txid,
55
199
  rawTx: transaction.serialize(),
@@ -60,12 +204,16 @@ export async function callContract(account, options) {
60
204
  */
61
205
  export async function deployContract(account, options) {
62
206
  const networkName = getStacksNetwork(account.network);
207
+ const nonce = await getNextNonce(account.address, account.network);
208
+ // Always resolve a clamped fee — prevents @stacks/transactions from over-estimating.
209
+ const resolvedFee = options.fee ?? await resolveDefaultFee(account.network, "smart_contract");
63
210
  const transaction = await makeContractDeploy({
64
211
  contractName: options.contractName,
65
212
  codeBody: options.codeBody,
66
213
  senderKey: account.privateKey,
67
214
  network: networkName,
68
- ...(options.fee !== undefined && { fee: options.fee }),
215
+ nonce,
216
+ fee: resolvedFee,
69
217
  });
70
218
  const broadcastResponse = await broadcastTransaction({
71
219
  transaction,
@@ -74,6 +222,7 @@ export async function deployContract(account, options) {
74
222
  if ("error" in broadcastResponse) {
75
223
  throw new Error(`Broadcast failed: ${broadcastResponse.error} - ${broadcastResponse.reason}`);
76
224
  }
225
+ advancePendingNonce(account.address, nonce);
77
226
  return {
78
227
  txid: broadcastResponse.txid,
79
228
  rawTx: transaction.serialize(),
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/transactions/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,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AAC;IACnC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;AAC1C,CAAC;AAED,cAAc,sBAAsB,CAAC"}
@@ -38,4 +38,19 @@ export declare function isFeePreset(value: string): value is FeePreset;
38
38
  * await resolveFee(undefined, "mainnet") // -> undefined
39
39
  */
40
40
  export declare function resolveFee(fee: string | undefined, network: Network, txType?: "all" | "token_transfer" | "contract_call" | "smart_contract"): Promise<bigint | undefined>;
41
+ /**
42
+ * Resolve a default medium-priority fee for a given transaction type.
43
+ *
44
+ * Used by builder functions when the caller does not supply an explicit fee,
45
+ * so that ALL write paths receive a clamped fee rather than relying on the
46
+ * unclamped @stacks/transactions auto-estimation which can over-shoot.
47
+ *
48
+ * Falls back gracefully: if the Hiro mempool API is unreachable, returns the
49
+ * floor × 2 (medium multiplier) for the tx type.
50
+ *
51
+ * @param network - The Stacks network to fetch fee estimates from
52
+ * @param txType - The transaction type for ceiling/floor selection
53
+ * @returns Fee in micro-STX as bigint
54
+ */
55
+ export declare function resolveDefaultFee(network: Network, txType?: "token_transfer" | "contract_call" | "smart_contract"): Promise<bigint>;
41
56
  //# sourceMappingURL=fee.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fee.d.ts","sourceRoot":"","sources":["../../src/utils/fee.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAarD;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAElD;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,SAAS,CAE7D;AAwBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,KAAK,G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