@secondlayer/stacks 4.3.2 → 5.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.
Files changed (165) hide show
  1. package/README.md +27 -11
  2. package/dist/shared/{stacks-bfan7ex7.js → stacks-4d7c3x27.js} +5 -5
  3. package/dist/shared/{stacks-bfan7ex7.js.map → stacks-4d7c3x27.js.map} +3 -3
  4. package/dist/shared/{stacks-709tra19.js → stacks-4hs8r4q2.js} +16 -2
  5. package/dist/shared/stacks-4hs8r4q2.js.map +10 -0
  6. package/dist/shared/{stacks-w23294am.js → stacks-51ybf135.js} +3 -3
  7. package/dist/shared/{stacks-0jk7vd8r.cjs → stacks-69nq48jp.js} +120 -17
  8. package/dist/shared/stacks-69nq48jp.js.map +15 -0
  9. package/dist/shared/{stacks-8pfdscq6.js → stacks-6gavarmy.js} +37 -9
  10. package/dist/shared/stacks-6gavarmy.js.map +12 -0
  11. package/dist/shared/{stacks-gxq2pbky.js → stacks-71k0vmct.js} +65 -8
  12. package/dist/shared/stacks-71k0vmct.js.map +13 -0
  13. package/dist/shared/{stacks-7wkf2rph.js → stacks-7bqkf3b0.js} +86 -71
  14. package/dist/shared/{stacks-7wkf2rph.js.map → stacks-7bqkf3b0.js.map} +9 -10
  15. package/dist/shared/{stacks-zcpvzbr0.js → stacks-8brgfvqx.js} +3 -3
  16. package/dist/shared/{stacks-4vzmhw3q.cjs → stacks-8vzxax5e.cjs} +13 -3
  17. package/dist/shared/stacks-8vzxax5e.cjs.map +10 -0
  18. package/dist/shared/{stacks-hnqt5rz4.js → stacks-9c1yam8b.js} +3 -3
  19. package/dist/shared/{stacks-bnbdqznq.cjs → stacks-bdgh9n83.cjs} +11 -10
  20. package/dist/shared/{stacks-bnbdqznq.cjs.map → stacks-bdgh9n83.cjs.map} +3 -3
  21. package/dist/shared/{stacks-fb75yew8.js → stacks-db3kwavg.cjs} +346 -138
  22. package/dist/shared/stacks-db3kwavg.cjs.map +23 -0
  23. package/dist/shared/{stacks-jpt52csy.js → stacks-e3nwm1dz.js} +14 -17
  24. package/dist/shared/stacks-e3nwm1dz.js.map +10 -0
  25. package/dist/shared/{stacks-ta1gar0b.cjs → stacks-ee53k9j2.cjs} +62 -6
  26. package/dist/shared/stacks-ee53k9j2.cjs.map +13 -0
  27. package/dist/shared/{stacks-27fmgajb.js → stacks-ga026yxz.js} +9 -9
  28. package/dist/shared/{stacks-27fmgajb.js.map → stacks-ga026yxz.js.map} +3 -3
  29. package/dist/shared/{stacks-nyaw1z2a.cjs → stacks-ggdz96r1.cjs} +4 -4
  30. package/dist/shared/{stacks-nyaw1z2a.cjs.map → stacks-ggdz96r1.cjs.map} +3 -3
  31. package/dist/shared/{stacks-08y0y0t7.js → stacks-gjz26k6b.js} +2 -2
  32. package/dist/shared/{stacks-x5386y2y.cjs → stacks-gza2n1zs.cjs} +5 -5
  33. package/dist/shared/{stacks-x5386y2y.cjs.map → stacks-gza2n1zs.cjs.map} +3 -3
  34. package/dist/shared/{stacks-ztzygy90.js → stacks-mftyrc60.js} +2 -2
  35. package/dist/shared/stacks-n4d8j8q3.js +801 -0
  36. package/dist/shared/stacks-n4d8j8q3.js.map +23 -0
  37. package/dist/shared/{stacks-ycbq8pf7.cjs → stacks-p337hp6m.cjs} +74 -59
  38. package/dist/shared/{stacks-ycbq8pf7.cjs.map → stacks-p337hp6m.cjs.map} +9 -10
  39. package/dist/shared/{stacks-ttdk2g2f.js → stacks-s5vej5z6.cjs} +92 -41
  40. package/dist/shared/stacks-s5vej5z6.cjs.map +15 -0
  41. package/dist/shared/stacks-sdqkapct.cjs +67 -0
  42. package/dist/shared/stacks-sdqkapct.cjs.map +12 -0
  43. package/dist/shared/{stacks-1arrcd11.js → stacks-v2rfr46a.js} +2 -2
  44. package/dist/shared/{stacks-9mqveyjv.cjs → stacks-w9t61fra.cjs} +7 -10
  45. package/dist/shared/stacks-w9t61fra.cjs.map +10 -0
  46. package/dist/shared/{stacks-tjjnkt3r.js → stacks-wxfd6r4b.js} +2 -2
  47. package/dist/shared/{stacks-4z72akdf.js → stacks-x0qqwrev.js} +3 -3
  48. package/dist/shared/{stacks-gck1sq7h.cjs → stacks-xjkn3en1.cjs} +16 -2
  49. package/dist/shared/stacks-xjkn3en1.cjs.map +10 -0
  50. package/dist/shared/stacks-xnrywjf1.cjs +131 -0
  51. package/dist/shared/stacks-xnrywjf1.cjs.map +11 -0
  52. package/dist/shared/stacks-yajyej2y.js +139 -0
  53. package/dist/shared/stacks-yajyej2y.js.map +11 -0
  54. package/dist/shared/{stacks-913a2rx7.js → stacks-yvb7rvwk.js} +13 -3
  55. package/dist/shared/stacks-yvb7rvwk.js.map +10 -0
  56. package/dist/shared/{stacks-0cdm20eh.js → stacks-z90xdr1x.js} +7 -11
  57. package/dist/shared/{stacks-0cdm20eh.js.map → stacks-z90xdr1x.js.map} +3 -3
  58. package/dist/src/accounts/index.js +2 -3
  59. package/dist/src/accounts/index.js.map +2 -2
  60. package/dist/src/actions/index.cjs +2 -1
  61. package/dist/src/actions/index.cjs.map +1 -1
  62. package/dist/src/actions/index.d.cts +108 -20
  63. package/dist/src/actions/index.d.ts +108 -20
  64. package/dist/src/actions/index.js +17 -15
  65. package/dist/src/actions/index.js.map +1 -1
  66. package/dist/src/bitcoin/index.d.cts +27 -0
  67. package/dist/src/bitcoin/index.d.ts +27 -0
  68. package/dist/src/bitcoin/index.js +10 -11
  69. package/dist/src/bitcoin/index.js.map +2 -2
  70. package/dist/src/bns/index.d.cts +27 -0
  71. package/dist/src/bns/index.d.ts +27 -0
  72. package/dist/src/bns/index.js +13 -13
  73. package/dist/src/bns/index.js.map +1 -1
  74. package/dist/src/clarity/index.js +7 -6
  75. package/dist/src/clarity/index.js.map +1 -1
  76. package/dist/src/connect/index.cjs +44 -30
  77. package/dist/src/connect/index.cjs.map +7 -7
  78. package/dist/src/connect/index.d.cts +16 -1
  79. package/dist/src/connect/index.d.ts +16 -1
  80. package/dist/src/connect/index.js +44 -30
  81. package/dist/src/connect/index.js.map +7 -7
  82. package/dist/src/connect/walletconnect/index.cjs +49 -413
  83. package/dist/src/connect/walletconnect/index.cjs.map +4 -4
  84. package/dist/src/connect/walletconnect/index.js +47 -411
  85. package/dist/src/connect/walletconnect/index.js.map +4 -4
  86. package/dist/src/filters/index.js +2 -2
  87. package/dist/src/index.cjs +49 -124
  88. package/dist/src/index.cjs.map +6 -8
  89. package/dist/src/index.d.cts +163 -54
  90. package/dist/src/index.d.ts +163 -54
  91. package/dist/src/index.js +79 -147
  92. package/dist/src/index.js.map +6 -8
  93. package/dist/src/postconditions/index.js +6 -5
  94. package/dist/src/postconditions/index.js.map +1 -1
  95. package/dist/src/pox/index.cjs +7 -83
  96. package/dist/src/pox/index.cjs.map +3 -3
  97. package/dist/src/pox/index.d.cts +32 -1
  98. package/dist/src/pox/index.d.ts +32 -1
  99. package/dist/src/pox/index.js +22 -102
  100. package/dist/src/pox/index.js.map +3 -3
  101. package/dist/src/pox5/index.cjs +4 -112
  102. package/dist/src/pox5/index.cjs.map +3 -4
  103. package/dist/src/pox5/index.d.cts +27 -0
  104. package/dist/src/pox5/index.d.ts +27 -0
  105. package/dist/src/pox5/index.js +20 -131
  106. package/dist/src/pox5/index.js.map +3 -4
  107. package/dist/src/sbtc/index.cjs +2 -27
  108. package/dist/src/sbtc/index.cjs.map +3 -3
  109. package/dist/src/sbtc/index.d.cts +30 -2
  110. package/dist/src/sbtc/index.d.ts +30 -2
  111. package/dist/src/sbtc/index.js +15 -45
  112. package/dist/src/sbtc/index.js.map +3 -3
  113. package/dist/src/stackingdao/index.d.cts +27 -0
  114. package/dist/src/stackingdao/index.d.ts +27 -0
  115. package/dist/src/stackingdao/index.js +11 -11
  116. package/dist/src/stackingdao/index.js.map +1 -1
  117. package/dist/src/subscriptions/index.d.cts +27 -0
  118. package/dist/src/subscriptions/index.d.ts +27 -0
  119. package/dist/src/subscriptions/index.js +2 -2
  120. package/dist/src/tools/btc/index.cjs.map +2 -2
  121. package/dist/src/tools/btc/index.js.map +2 -2
  122. package/dist/src/tools/index.cjs +629 -392
  123. package/dist/src/tools/index.cjs.map +30 -28
  124. package/dist/src/tools/index.d.cts +44 -0
  125. package/dist/src/tools/index.d.ts +44 -0
  126. package/dist/src/tools/index.js +628 -391
  127. package/dist/src/tools/index.js.map +30 -28
  128. package/dist/src/transactions/index.js +6 -5
  129. package/dist/src/transactions/index.js.map +1 -1
  130. package/dist/src/utils/index.d.cts +2 -5
  131. package/dist/src/utils/index.d.ts +2 -5
  132. package/dist/src/utils/index.js +2 -2
  133. package/package.json +18 -7
  134. package/dist/shared/stacks-0eatsx6d.cjs +0 -25
  135. package/dist/shared/stacks-0eatsx6d.cjs.map +0 -10
  136. package/dist/shared/stacks-0jk7vd8r.cjs.map +0 -14
  137. package/dist/shared/stacks-4vzmhw3q.cjs.map +0 -10
  138. package/dist/shared/stacks-5nmz5ad9.js +0 -409
  139. package/dist/shared/stacks-5nmz5ad9.js.map +0 -10
  140. package/dist/shared/stacks-709tra19.js.map +0 -10
  141. package/dist/shared/stacks-8pfdscq6.js.map +0 -12
  142. package/dist/shared/stacks-913a2rx7.js.map +0 -10
  143. package/dist/shared/stacks-9mqveyjv.cjs.map +0 -10
  144. package/dist/shared/stacks-e4xn4m7j.js +0 -27
  145. package/dist/shared/stacks-e4xn4m7j.js.map +0 -10
  146. package/dist/shared/stacks-fb75yew8.js.map +0 -21
  147. package/dist/shared/stacks-gck1sq7h.cjs.map +0 -10
  148. package/dist/shared/stacks-gxq2pbky.js.map +0 -13
  149. package/dist/shared/stacks-jpt52csy.js.map +0 -10
  150. package/dist/shared/stacks-mnnhpex3.cjs +0 -407
  151. package/dist/shared/stacks-mnnhpex3.cjs.map +0 -10
  152. package/dist/shared/stacks-ta1gar0b.cjs.map +0 -13
  153. package/dist/shared/stacks-tdsp5gsb.cjs +0 -527
  154. package/dist/shared/stacks-tdsp5gsb.cjs.map +0 -21
  155. package/dist/shared/stacks-ttdk2g2f.js.map +0 -14
  156. package/dist/shared/stacks-wdp5yr8n.cjs +0 -39
  157. package/dist/shared/stacks-wdp5yr8n.cjs.map +0 -12
  158. /package/dist/shared/{stacks-w23294am.js.map → stacks-51ybf135.js.map} +0 -0
  159. /package/dist/shared/{stacks-zcpvzbr0.js.map → stacks-8brgfvqx.js.map} +0 -0
  160. /package/dist/shared/{stacks-hnqt5rz4.js.map → stacks-9c1yam8b.js.map} +0 -0
  161. /package/dist/shared/{stacks-08y0y0t7.js.map → stacks-gjz26k6b.js.map} +0 -0
  162. /package/dist/shared/{stacks-ztzygy90.js.map → stacks-mftyrc60.js.map} +0 -0
  163. /package/dist/shared/{stacks-1arrcd11.js.map → stacks-v2rfr46a.js.map} +0 -0
  164. /package/dist/shared/{stacks-tjjnkt3r.js.map → stacks-wxfd6r4b.js.map} +0 -0
  165. /package/dist/shared/{stacks-4z72akdf.js.map → stacks-x0qqwrev.js.map} +0 -0
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  MalformedResponseError,
3
3
  readContract
4
- } from "./stacks-27fmgajb.js";
4
+ } from "./stacks-ga026yxz.js";
5
5
  import {
6
6
  deserializeCVBytes
7
- } from "./stacks-ttdk2g2f.js";
7
+ } from "./stacks-69nq48jp.js";
8
8
  import {
9
9
  parseContractId
10
- } from "./stacks-bfan7ex7.js";
10
+ } from "./stacks-4d7c3x27.js";
11
11
 
12
12
  // src/actions/public/getBalance.ts
13
13
  async function getBalance(client, params) {
14
- const data = await client.request(`/v2/accounts/${params.address}`, {
14
+ const data = await client.request(`/v2/accounts/${encodeURIComponent(params.address)}`, {
15
15
  method: "GET"
16
16
  });
17
17
  const balance = data?.balance;
@@ -33,20 +33,48 @@ async function getDataVar(client, params) {
33
33
  }
34
34
 
35
35
  // src/actions/public/multicall.ts
36
+ async function mapWithConcurrency(items, limit, fn) {
37
+ const results = new Array(items.length);
38
+ let cursor = 0;
39
+ const worker = async () => {
40
+ while (cursor < items.length) {
41
+ const index = cursor++;
42
+ try {
43
+ results[index] = {
44
+ status: "fulfilled",
45
+ value: await fn(items[index])
46
+ };
47
+ } catch (reason) {
48
+ results[index] = { status: "rejected", reason };
49
+ }
50
+ }
51
+ };
52
+ const workers = Math.max(1, Math.min(limit, items.length));
53
+ await Promise.all(Array.from({ length: workers }, worker));
54
+ return results;
55
+ }
36
56
  async function multicall(client, params) {
37
- const { calls, allowFailure = true } = params;
57
+ const { calls, allowFailure = true, concurrency = 8 } = params;
58
+ if (!Number.isInteger(concurrency) || concurrency < 1) {
59
+ throw new RangeError(`multicall concurrency must be a positive integer, got ${concurrency}`);
60
+ }
61
+ const settled = await mapWithConcurrency(calls, concurrency, (call) => readContract(client, call));
38
62
  if (allowFailure) {
39
- const settled = await Promise.allSettled(calls.map((call) => readContract(client, call)));
40
63
  return settled.map((r) => r.status === "fulfilled" ? { status: "success", result: r.value } : {
41
64
  status: "failure",
42
65
  error: r.reason instanceof Error ? r.reason : new Error(String(r.reason))
43
66
  });
44
67
  }
45
- const results = await Promise.all(calls.map((call) => readContract(client, call)));
68
+ const results = [];
69
+ for (const r of settled) {
70
+ if (r.status === "rejected")
71
+ throw r.reason;
72
+ results.push(r.value);
73
+ }
46
74
  return results;
47
75
  }
48
76
 
49
77
  export { getBalance, getDataVar, multicall };
50
78
 
51
- //# debugId=FB2239917577E3D764756E2164756E21
52
- //# sourceMappingURL=stacks-8pfdscq6.js.map
79
+ //# debugId=55F75D35D3BBC27164756E2164756E21
80
+ //# sourceMappingURL=stacks-6gavarmy.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/actions/public/getBalance.ts", "../src/actions/public/getDataVar.ts", "../src/actions/public/multicall.ts"],
4
+ "sourcesContent": [
5
+ "import type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.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(\n\t\t`/v2/accounts/${encodeURIComponent(params.address)}`,\n\t\t{\n\t\t\tmethod: \"GET\",\n\t\t},\n\t);\n\tconst balance = (data as { balance?: unknown })?.balance;\n\tif (typeof balance !== \"string\" && typeof balance !== \"number\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getBalance: /v2/accounts/${params.address} response is missing \"balance\"`,\n\t\t);\n\t}\n\treturn BigInt(balance);\n}\n",
6
+ "import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetDataVarParams = {\n\tcontract: string; // \"address.name\"\n\tvarName: string;\n};\n\nexport async function getDataVar<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetDataVarParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst path = `/v2/data_var/${address}/${name}/${params.varName}?proof=0`;\n\n\tconst data = await client.request(path, { method: \"GET\" });\n\n\tif (typeof data?.data !== \"string\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getDataVar: /v2/data_var/${address}/${name}/${params.varName} response is missing \"data\"`,\n\t\t);\n\t}\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
7
+ "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\t/**\n\t * Reads in flight at once. Default 8. Each call is its own\n\t * `/v2/contracts/call-read` request (Stacks nodes have no batch RPC), so\n\t * an uncapped fan-out turns one multicall into a burst that trips rate\n\t * limits and then retries in lockstep.\n\t */\n\tconcurrency?: number;\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\n/** Run `fn` over `items` with at most `limit` in flight, preserving order. */\nasync function mapWithConcurrency<T, R>(\n\titems: readonly T[],\n\tlimit: number,\n\tfn: (item: T) => Promise<R>,\n): Promise<PromiseSettledResult<R>[]> {\n\tconst results: PromiseSettledResult<R>[] = new Array(items.length);\n\tlet cursor = 0;\n\tconst worker = async () => {\n\t\twhile (cursor < items.length) {\n\t\t\tconst index = cursor++;\n\t\t\ttry {\n\t\t\t\tresults[index] = {\n\t\t\t\t\tstatus: \"fulfilled\",\n\t\t\t\t\tvalue: await fn(items[index] as T),\n\t\t\t\t};\n\t\t\t} catch (reason) {\n\t\t\t\tresults[index] = { status: \"rejected\", reason };\n\t\t\t}\n\t\t}\n\t};\n\tconst workers = Math.max(1, Math.min(limit, items.length));\n\tawait Promise.all(Array.from({ length: workers }, worker));\n\treturn results;\n}\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, concurrency = 8 } = params;\n\tif (!Number.isInteger(concurrency) || concurrency < 1) {\n\t\tthrow new RangeError(\n\t\t\t`multicall concurrency must be a positive integer, got ${concurrency}`,\n\t\t);\n\t}\n\n\tconst settled = await mapWithConcurrency(calls, concurrency, (call) =>\n\t\treadContract(client, call),\n\t);\n\n\tif (allowFailure) {\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: ClarityValue[] = [];\n\tfor (const r of settled) {\n\t\tif (r.status === \"rejected\") throw r.reason;\n\t\tresults.push(r.value);\n\t}\n\treturn results as MulticallResult<TAllowFailure>;\n}\n"
8
+ ],
9
+ "mappings": ";;;;;;;;;;;;AAOA,eAAsB,UAAU,CAC/B,QACA,QACkB;AAAA,EAClB,MAAM,OAAO,MAAM,OAAO,QACzB,gBAAgB,mBAAmB,OAAO,OAAO,KACjD;AAAA,IACC,QAAQ;AAAA,EACT,CACD;AAAA,EACA,MAAM,UAAW,MAAgC;AAAA,EACjD,IAAI,OAAO,YAAY,YAAY,OAAO,YAAY,UAAU;AAAA,IAC/D,MAAM,IAAI,uBACT,4BAA4B,OAAO,uCACpC;AAAA,EACD;AAAA,EACA,OAAO,OAAO,OAAO;AAAA;;;ACZtB,eAAsB,UAAiD,CACtE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,OAAO,gBAAgB,WAAW,QAAQ,OAAO;AAAA,EAEvD,MAAM,OAAO,MAAM,OAAO,QAAQ,MAAM,EAAE,QAAQ,MAAM,CAAC;AAAA,EAEzD,IAAI,OAAO,MAAM,SAAS,UAAU;AAAA,IACnC,MAAM,IAAI,uBACT,4BAA4B,WAAW,QAAQ,OAAO,oCACvD;AAAA,EACD;AAAA,EACA,OAAO,mBAAsB,KAAK,IAAI;AAAA;;;ACSvC,eAAe,kBAAwB,CACtC,OACA,OACA,IACqC;AAAA,EACrC,MAAM,UAAqC,IAAI,MAAM,MAAM,MAAM;AAAA,EACjE,IAAI,SAAS;AAAA,EACb,MAAM,SAAS,YAAY;AAAA,IAC1B,OAAO,SAAS,MAAM,QAAQ;AAAA,MAC7B,MAAM,QAAQ;AAAA,MACd,IAAI;AAAA,QACH,QAAQ,SAAS;AAAA,UAChB,QAAQ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+ } from "./stacks-x0qqwrev.js";
22
22
  import {
23
23
  asciiToBytes,
24
24
  bytesToAscii,
25
25
  hexToBytes,
26
- utf8ToBytes
26
+ utf8ToBytes,
27
+ without0x
27
28
  } from "./stacks-qs5fzts5.js";
28
29
  // src/clarity/prettyPrint.ts
29
30
  function prettyPrint(val, encoding = "hex") {
@@ -74,11 +75,13 @@ function cvToJSON(val) {
74
75
  return { type: "int", value: val.value.toString() };
75
76
  case "uint":
76
77
  return { type: "uint", value: val.value.toString() };
77
- case "buffer":
78
+ case "buffer": {
79
+ const hex = without0x(val.value);
78
80
  return {
79
- type: `(buff ${Math.ceil(val.value.length / 2)})`,
80
- value: `0x${val.value}`
81
+ type: `(buff ${Math.ceil(hex.length / 2)})`,
82
+ value: `0x${hex}`
81
83
  };
84
+ }
82
85
  case "none":
83
86
  return { type: "(optional none)", value: null };
84
87
  case "some":
@@ -495,6 +498,25 @@ function normalizeVariable(variable) {
495
498
  access: variable.access
496
499
  };
497
500
  }
501
+ function normalizeFungibleToken(token) {
502
+ return { name: token.name };
503
+ }
504
+ function normalizeNonFungibleToken(token) {
505
+ return { name: token.name, type: normalizeType(token.type) };
506
+ }
507
+ function normalizeTraitDefinition(trait) {
508
+ const rawFunctions = Array.isArray(trait.functions) ? trait.functions : [];
509
+ const functions = [];
510
+ for (const func of rawFunctions) {
511
+ if (typeof func !== "object" || func === null)
512
+ continue;
513
+ const normalized = normalizeFunction(func);
514
+ if (normalized.access === "private")
515
+ continue;
516
+ functions.push(normalized);
517
+ }
518
+ return { name: trait.name, functions };
519
+ }
498
520
  function normalizeAbi(abi) {
499
521
  if (typeof abi !== "object" || abi === null) {
500
522
  return { functions: [] };
@@ -503,6 +525,10 @@ function normalizeAbi(abi) {
503
525
  const functions = [];
504
526
  const maps = [];
505
527
  const variables = [];
528
+ const fungibleTokens = [];
529
+ const nonFungibleTokens = [];
530
+ const implementedTraits = [];
531
+ const definedTraits = [];
506
532
  if (Array.isArray(abiObj.functions)) {
507
533
  for (const func of abiObj.functions) {
508
534
  if (typeof func === "object" && func !== null) {
@@ -524,13 +550,44 @@ function normalizeAbi(abi) {
524
550
  }
525
551
  }
526
552
  }
553
+ if (Array.isArray(abiObj.fungible_tokens)) {
554
+ for (const token of abiObj.fungible_tokens) {
555
+ if (typeof token === "object" && token !== null) {
556
+ fungibleTokens.push(normalizeFungibleToken(token));
557
+ }
558
+ }
559
+ }
560
+ if (Array.isArray(abiObj.non_fungible_tokens)) {
561
+ for (const token of abiObj.non_fungible_tokens) {
562
+ if (typeof token === "object" && token !== null) {
563
+ nonFungibleTokens.push(normalizeNonFungibleToken(token));
564
+ }
565
+ }
566
+ }
567
+ if (Array.isArray(abiObj.implemented_traits)) {
568
+ for (const trait of abiObj.implemented_traits) {
569
+ if (typeof trait === "string")
570
+ implementedTraits.push(trait);
571
+ }
572
+ }
573
+ if (Array.isArray(abiObj.defined_traits)) {
574
+ for (const trait of abiObj.defined_traits) {
575
+ if (typeof trait === "object" && trait !== null) {
576
+ definedTraits.push(normalizeTraitDefinition(trait));
577
+ }
578
+ }
579
+ }
527
580
  return {
528
581
  functions,
529
582
  maps: maps.length > 0 ? maps : undefined,
530
- variables: variables.length > 0 ? variables : undefined
583
+ variables: variables.length > 0 ? variables : undefined,
584
+ fungible_tokens: fungibleTokens.length > 0 ? fungibleTokens : undefined,
585
+ non_fungible_tokens: nonFungibleTokens.length > 0 ? nonFungibleTokens : undefined,
586
+ implemented_traits: implementedTraits.length > 0 ? implementedTraits : undefined,
587
+ defined_traits: definedTraits.length > 0 ? definedTraits : undefined
531
588
  };
532
589
  }
533
590
  export { prettyPrint, cvToJSON, cvToValue, cvToBigInt, cvToString, cvToBuffer, cvToBoolean, cvToPrincipal, ClarityConversionError, jsToClarity, prepareArgs, validateArgs, validateArgsArray, TRAIT_STANDARDS, classifyContract, parseDeclaredStandards, normalizeAccess, normalizeType, normalizeAbi };
534
591
 
535
- //# debugId=8CD9EEAAF9EBFC9164756E2164756E21
536
- //# sourceMappingURL=stacks-gxq2pbky.js.map
592
+ //# debugId=4968AF95FABE160264756E2164756E21
593
+ //# sourceMappingURL=stacks-71k0vmct.js.map
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/clarity/prettyPrint.ts", "../src/clarity/abi/converters.ts", "../src/clarity/abi/classify.ts", "../src/clarity/abi/normalize.ts"],
4
+ "sourcesContent": [
5
+ "import {\n\tasciiToBytes,\n\tbytesToAscii,\n\thexToBytes,\n\tutf8ToBytes,\n\twithout0x,\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// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\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\n// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\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\tconst hex = without0x(val.value);\n\t\t\treturn {\n\t\t\t\ttype: `(buff ${Math.ceil(hex.length / 2)})`,\n\t\t\t\tvalue: `0x${hex}`,\n\t\t\t};\n\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\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\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\n// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\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\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\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\n/** Narrow to bigint; throws unless `val` is an int or uint. */\nexport function cvToBigInt(val: ClarityValue): bigint {\n\tif (val.type !== \"int\" && val.type !== \"uint\") {\n\t\tthrow new Error(`cvToBigInt: expected int or uint, got ${val.type}`);\n\t}\n\treturn val.value;\n}\n\n/** Narrow to string; throws unless `val` is an ascii or utf8 string. */\nexport function cvToString(val: ClarityValue): string {\n\tif (val.type !== \"ascii\" && val.type !== \"utf8\") {\n\t\tthrow new Error(`cvToString: expected ascii or utf8, got ${val.type}`);\n\t}\n\treturn val.value;\n}\n\n/** Narrow to hex string (no 0x prefix); throws unless `val` is a buffer. */\nexport function cvToBuffer(val: ClarityValue): string {\n\tif (val.type !== \"buffer\") {\n\t\tthrow new Error(`cvToBuffer: expected buffer, got ${val.type}`);\n\t}\n\treturn val.value;\n}\n\n/** Narrow to boolean; throws unless `val` is a bool. */\nexport function cvToBoolean(val: ClarityValue): boolean {\n\tif (val.type !== \"true\" && val.type !== \"false\") {\n\t\tthrow new Error(`cvToBoolean: expected bool, got ${val.type}`);\n\t}\n\treturn val.type === \"true\";\n}\n\n/** Narrow to principal string; throws unless `val` is a standard or contract principal. */\nexport function cvToPrincipal(val: ClarityValue): string {\n\tif (val.type !== \"address\" && val.type !== \"contract\") {\n\t\tthrow new Error(\n\t\t\t`cvToPrincipal: expected principal or contract, got ${val.type}`,\n\t\t);\n\t}\n\treturn val.value;\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
+ "import type { AbiContract, AbiFunction } from \"./contract.ts\";\nimport { SIP009_ABI, SIP010_ABI, SIP013_ABI } from \"./standards.ts\";\n\n/**\n * Static conformance classification — \"does this contract's ABI look like a\n * SIP-009/010/013 token?\". Powers trait-based discovery for the (many) contracts\n * that conform to a standard without declaring its trait. Lean match: every\n * REQUIRED standard function must be present with the same access + arg arity\n * (optional functions like get-token-uri are ignored). Loose on exact arg/return\n * types to catch real-world variants; consumers wanting certainty use the\n * `declared` traits parsed from source instead.\n */\n\n/** The canonical SIP trait standards this package can classify/scaffold against.\n * Single source of truth — the `SipStandard` type, CLI `--trait` validation, and\n * the MCP traits resource all derive from this so the vocabulary can't drift. */\nexport const TRAIT_STANDARDS = [\"sip-009\", \"sip-010\", \"sip-013\"] as const;\n\nexport type SipStandard = (typeof TRAIT_STANDARDS)[number];\n\ninterface StandardSpec {\n\tid: SipStandard;\n\tabi: AbiContract;\n\t/** Functions in the reference ABI that real tokens may omit. */\n\toptional: ReadonlySet<string>;\n}\n\nconst STANDARDS: ReadonlyArray<StandardSpec> = [\n\t{ id: \"sip-010\", abi: SIP010_ABI, optional: new Set([\"get-token-uri\"]) },\n\t{ id: \"sip-009\", abi: SIP009_ABI, optional: new Set([\"get-token-uri\"]) },\n\t{\n\t\tid: \"sip-013\",\n\t\tabi: SIP013_ABI,\n\t\toptional: new Set([\n\t\t\t\"transfer-memo\",\n\t\t\t\"transfer-many\",\n\t\t\t\"transfer-many-memo\",\n\t\t\t\"get-token-uri\",\n\t\t\t\"get-overall-balance\",\n\t\t\t\"get-overall-supply\",\n\t\t]),\n\t},\n];\n\nfunction indexByName(abi: AbiContract): Map<string, AbiFunction> {\n\tconst m = new Map<string, AbiFunction>();\n\tfor (const f of abi.functions) m.set(f.name, f);\n\treturn m;\n}\n\nfunction conformsTo(candidate: AbiContract, spec: StandardSpec): boolean {\n\tconst fns = indexByName(candidate);\n\tfor (const required of spec.abi.functions) {\n\t\tif (spec.optional.has(required.name)) continue;\n\t\tconst got = fns.get(required.name);\n\t\tif (!got) return false;\n\t\tif (got.access !== required.access) return false;\n\t\tif (got.args.length !== required.args.length) return false;\n\t}\n\treturn true;\n}\n\n/** Return the SIP standards a contract's ABI statically conforms to. */\nexport function classifyContract(abi: AbiContract): SipStandard[] {\n\tif (!abi || !Array.isArray(abi.functions)) return [];\n\treturn STANDARDS.filter((s) => conformsTo(abi, s)).map((s) => s.id);\n}\n\n/**\n * Parse the standards a contract *declares* via `(impl-trait …)` in its Clarity\n * source. Matched heuristically on the trait-reference name (robust across\n * mainnet/testnet principals + community variants) rather than an exact principal\n * allowlist. The ABI/RPC doesn't carry trait info, so source is the only declared\n * signal. `declared` is the high-confidence signal; `classifyContract` is the\n * catch-all for conforming-but-undeclared contracts.\n */\nexport function parseDeclaredStandards(claritySource: string): SipStandard[] {\n\tconst out = new Set<SipStandard>();\n\tconst matches = claritySource.matchAll(/\\(impl-trait\\s+[^)]+\\)/gi);\n\tfor (const m of matches) {\n\t\tconst ref = m[0].toLowerCase();\n\t\tif (ref.includes(\"sip-010\") || ref.includes(\".ft-trait\"))\n\t\t\tout.add(\"sip-010\");\n\t\tif (ref.includes(\"sip-009\") || ref.includes(\"nft-trait\"))\n\t\t\tout.add(\"sip-009\");\n\t\tif (ref.includes(\"sip-013\") || ref.includes(\"semi-fungible\"))\n\t\t\tout.add(\"sip-013\");\n\t}\n\treturn [...out];\n}\n",
8
+ "/**\n * Normalize a Clarity ABI from any source into the canonical `AbiContract`\n * shape this package's type extractors expect.\n *\n * Sources differ in small, load-bearing ways: the Hiro API and Clarinet SDK\n * emit `buffer`/`read_only` and wrap function outputs as `{ type: … }`, while\n * the canonical shape uses `buff`/`read-only` and a bare `AbiType`. Passing a\n * raw ABI straight through produces a value that LOOKS right and silently\n * fails the `AbiContract` constraint, so `event.input` / `.read.x()` typing\n * quietly degrades. Run it through here first.\n *\n * Lives in `@secondlayer/stacks/clarity` (not the CLI) so a raw ABI can be\n * normalized anywhere — scaffolds, MCP, a user's own script — without the CLI\n * installed.\n */\n\nimport type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiFungibleToken,\n\tAbiMap,\n\tAbiNonFungibleToken,\n\tAbiTraitDefinition,\n\tAbiTraitFunction,\n\tAbiVariable,\n} from \"./contract.ts\";\nimport type { AbiType } from \"./types.ts\";\n\n/**\n * Normalize function access type from various formats to internal format\n */\nexport function normalizeAccess(\n\taccess: string,\n): \"public\" | \"read-only\" | \"private\" {\n\tif (access === \"read_only\") return \"read-only\";\n\treturn access as \"public\" | \"read-only\" | \"private\";\n}\n\n/**\n * Normalize a Clarity type from API format to internal format\n * Handles buffer vs buff, and recursively normalizes nested types\n */\nexport function normalizeType(type: unknown): AbiType {\n\tif (typeof type === \"string\") {\n\t\t// Handle string primitive types\n\t\tswitch (type) {\n\t\t\tcase \"uint128\":\n\t\t\tcase \"int128\":\n\t\t\tcase \"bool\":\n\t\t\tcase \"principal\":\n\t\t\tcase \"trait_reference\":\n\t\t\t\treturn type;\n\t\t\tdefault:\n\t\t\t\t// Unknown string type, return as-is\n\t\t\t\treturn type as AbiType;\n\t\t}\n\t}\n\n\tif (typeof type !== \"object\" || type === null) {\n\t\tthrow new Error(`Invalid ABI type: expected object, got ${typeof type}`);\n\t}\n\n\tconst typeObj = type as Record<string, unknown>;\n\n\t// Handle buffer vs buff (API uses buffer, we use buff)\n\tif (\"buffer\" in typeObj) {\n\t\tconst buffer = typeObj.buffer as { length?: number };\n\t\treturn {\n\t\t\tbuff: {\n\t\t\t\tlength: buffer?.length ?? 32,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Already in internal format\n\tif (\"buff\" in typeObj) {\n\t\tconst buff = typeObj.buff as { length?: number };\n\t\treturn {\n\t\t\tbuff: {\n\t\t\t\tlength: buff?.length ?? 32,\n\t\t\t},\n\t\t};\n\t}\n\n\t// String types\n\tif (\"string-ascii\" in typeObj) {\n\t\tconst strAscii = typeObj[\"string-ascii\"] as { length?: number };\n\t\treturn {\n\t\t\t\"string-ascii\": {\n\t\t\t\tlength: strAscii?.length ?? 256,\n\t\t\t},\n\t\t};\n\t}\n\n\tif (\"string-utf8\" in typeObj) {\n\t\tconst strUtf8 = typeObj[\"string-utf8\"] as { length?: number };\n\t\treturn {\n\t\t\t\"string-utf8\": {\n\t\t\t\tlength: strUtf8?.length ?? 256,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Response type - recursively normalize ok and error types\n\tif (\"response\" in typeObj) {\n\t\tconst response = typeObj.response as { ok?: unknown; error?: unknown };\n\t\treturn {\n\t\t\tresponse: {\n\t\t\t\tok: normalizeType(response?.ok ?? \"bool\"),\n\t\t\t\terror: normalizeType(response?.error ?? \"uint128\"),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Optional type - recursively normalize inner type\n\tif (\"optional\" in typeObj) {\n\t\treturn {\n\t\t\toptional: normalizeType(typeObj.optional),\n\t\t};\n\t}\n\n\t// List type - recursively normalize element type\n\tif (\"list\" in typeObj) {\n\t\tconst list = typeObj.list as { type?: unknown; length?: number };\n\t\treturn {\n\t\t\tlist: {\n\t\t\t\ttype: normalizeType(list?.type ?? \"uint128\"),\n\t\t\t\tlength: list?.length ?? 100,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Tuple type - recursively normalize field types\n\tif (\"tuple\" in typeObj) {\n\t\tconst tuple = typeObj.tuple as Array<{ name: string; type: unknown }>;\n\t\treturn {\n\t\t\ttuple: tuple.map((field) => ({\n\t\t\t\tname: field.name,\n\t\t\t\ttype: normalizeType(field.type),\n\t\t\t})),\n\t\t};\n\t}\n\n\t// Unknown type - fail explicitly\n\tthrow new Error(`Unknown ABI type structure: ${JSON.stringify(type)}`);\n}\n\n/**\n * Normalize a function definition from API format to internal format\n */\nexport function normalizeFunction(func: Record<string, unknown>): AbiFunction {\n\tconst access = normalizeAccess(func.access as string);\n\tconst args = (func.args as Array<{ name: string; type: unknown }>) ?? [];\n\tconst outputs = func.outputs as { type?: unknown } | unknown;\n\n\treturn {\n\t\tname: func.name as string,\n\t\taccess,\n\t\targs: args.map((arg) => ({\n\t\t\tname: arg.name,\n\t\t\ttype: normalizeType(arg.type),\n\t\t})),\n\t\toutputs: normalizeType(\n\t\t\ttypeof outputs === \"object\" && outputs !== null && \"type\" in outputs\n\t\t\t\t? (outputs as { type: unknown }).type\n\t\t\t\t: outputs,\n\t\t),\n\t};\n}\n\n/**\n * Normalize a map definition from API format to internal format\n */\nexport function normalizeMap(map: Record<string, unknown>): AbiMap {\n\treturn {\n\t\tname: map.name as string,\n\t\tkey: normalizeType(map.key),\n\t\tvalue: normalizeType(map.value),\n\t};\n}\n\n/**\n * Normalize a variable definition from API format to internal format\n */\nexport function normalizeVariable(\n\tvariable: Record<string, unknown>,\n): AbiVariable {\n\treturn {\n\t\tname: variable.name as string,\n\t\ttype: normalizeType(variable.type),\n\t\taccess: variable.access as \"constant\" | \"variable\",\n\t};\n}\n\n/**\n * Normalize a fungible-token definition. Only the name is carried on the wire.\n */\nexport function normalizeFungibleToken(\n\ttoken: Record<string, unknown>,\n): AbiFungibleToken {\n\treturn { name: token.name as string };\n}\n\n/**\n * Normalize a non-fungible-token definition, including its identifier type.\n */\nexport function normalizeNonFungibleToken(\n\ttoken: Record<string, unknown>,\n): AbiNonFungibleToken {\n\treturn { name: token.name as string, type: normalizeType(token.type) };\n}\n\n/**\n * Normalize a `define-trait` definition. A trait cannot declare private\n * functions, so any that show up are dropped rather than cast through.\n */\nexport function normalizeTraitDefinition(\n\ttrait: Record<string, unknown>,\n): AbiTraitDefinition {\n\tconst rawFunctions = Array.isArray(trait.functions) ? trait.functions : [];\n\tconst functions: AbiTraitFunction[] = [];\n\n\tfor (const func of rawFunctions) {\n\t\tif (typeof func !== \"object\" || func === null) continue;\n\t\tconst normalized = normalizeFunction(func as Record<string, unknown>);\n\t\tif (normalized.access === \"private\") continue;\n\t\tfunctions.push(normalized as AbiTraitFunction);\n\t}\n\n\treturn { name: trait.name as string, functions };\n}\n\n/**\n * Normalize an entire ABI from various sources to consistent internal format\n *\n * This handles ABIs from:\n * - Hiro API responses\n * - Clarinet SDK\n * - Upstream @secondlayer/stacks types\n */\nexport function normalizeAbi(abi: unknown): AbiContract {\n\tif (typeof abi !== \"object\" || abi === null) {\n\t\treturn { functions: [] };\n\t}\n\n\tconst abiObj = abi as Record<string, unknown>;\n\n\tconst functions: AbiFunction[] = [];\n\tconst maps: AbiMap[] = [];\n\tconst variables: AbiVariable[] = [];\n\tconst fungibleTokens: AbiFungibleToken[] = [];\n\tconst nonFungibleTokens: AbiNonFungibleToken[] = [];\n\tconst implementedTraits: string[] = [];\n\tconst definedTraits: AbiTraitDefinition[] = [];\n\n\t// Normalize functions\n\tif (Array.isArray(abiObj.functions)) {\n\t\tfor (const func of abiObj.functions) {\n\t\t\tif (typeof func === \"object\" && func !== null) {\n\t\t\t\tfunctions.push(normalizeFunction(func as Record<string, unknown>));\n\t\t\t}\n\t\t}\n\t}\n\n\t// Normalize maps\n\tif (Array.isArray(abiObj.maps)) {\n\t\tfor (const map of abiObj.maps) {\n\t\t\tif (typeof map === \"object\" && map !== null) {\n\t\t\t\tmaps.push(normalizeMap(map as Record<string, unknown>));\n\t\t\t}\n\t\t}\n\t}\n\n\t// Normalize variables\n\tif (Array.isArray(abiObj.variables)) {\n\t\tfor (const variable of abiObj.variables) {\n\t\t\tif (typeof variable === \"object\" && variable !== null) {\n\t\t\t\tvariables.push(normalizeVariable(variable as Record<string, unknown>));\n\t\t\t}\n\t\t}\n\t}\n\n\t// Token and trait definitions are declarations, not shapes to convert — but\n\t// dropping them makes a normalized ABI lossy, and callers do read them (an\n\t// `ft_transfer` filter needs `contract::asset`, not just the contract).\n\tif (Array.isArray(abiObj.fungible_tokens)) {\n\t\tfor (const token of abiObj.fungible_tokens) {\n\t\t\tif (typeof token === \"object\" && token !== null) {\n\t\t\t\tfungibleTokens.push(\n\t\t\t\t\tnormalizeFungibleToken(token as Record<string, unknown>),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (Array.isArray(abiObj.non_fungible_tokens)) {\n\t\tfor (const token of abiObj.non_fungible_tokens) {\n\t\t\tif (typeof token === \"object\" && token !== null) {\n\t\t\t\tnonFungibleTokens.push(\n\t\t\t\t\tnormalizeNonFungibleToken(token as Record<string, unknown>),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Neither the Clarinet SDK's `IContractInterface` nor the Hiro interface\n\t// response carries traits today; these two branches keep an ABI that does\n\t// have them (a hand-written config, a source-read ABI) round-tripping.\n\tif (Array.isArray(abiObj.implemented_traits)) {\n\t\tfor (const trait of abiObj.implemented_traits) {\n\t\t\tif (typeof trait === \"string\") implementedTraits.push(trait);\n\t\t}\n\t}\n\n\tif (Array.isArray(abiObj.defined_traits)) {\n\t\tfor (const trait of abiObj.defined_traits) {\n\t\t\tif (typeof trait === \"object\" && trait !== null) {\n\t\t\t\tdefinedTraits.push(\n\t\t\t\t\tnormalizeTraitDefinition(trait as Record<string, unknown>),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tfunctions,\n\t\tmaps: maps.length > 0 ? maps : undefined,\n\t\tvariables: variables.length > 0 ? variables : undefined,\n\t\tfungible_tokens: fungibleTokens.length > 0 ? fungibleTokens : undefined,\n\t\tnon_fungible_tokens:\n\t\t\tnonFungibleTokens.length > 0 ? nonFungibleTokens : undefined,\n\t\timplemented_traits:\n\t\t\timplementedTraits.length > 0 ? implementedTraits : undefined,\n\t\tdefined_traits: definedTraits.length > 0 ? definedTraits : undefined,\n\t};\n}\n"
9
+ ],
10
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASO,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,SACtB;AAAA,MACJ,OAAO,IAAI,IAAI,MAAM,SAAS;AAAA,SAC1B;AAAA,MACJ,IAAI,aAAa,YAAY;AAAA,QAC5B,MAAM,MAAM,aAAa,WAAW,IAAI,KAAK,CAAC;AAAA,QAC9C,IAAI,WAAW,KAAK,GAAG;AAAA,UAAG,OAAO,KAAK,UAAU,GAAG;AAAA,MACpD;AAAA,MACA,OAAO,KAAK,IAAI;AAAA,SACZ;AAAA,MACJ,OAAO;AAAA,SACH;AAAA,MACJ,OAAO,SAAS,YAAY,IAAI,OAAO,QAAQ;AAAA,SAC3C;AAAA,MACJ,OAAO,OAAO,YAAY,IAAI,OAAO,QAAQ;AAAA,SACzC;AAAA,MACJ,OAAO,QAAQ,YAAY,IAAI,OAAO,QAAQ;AAAA,SAC1C;AAAA,SACA;AAAA,MACJ,OAAO,IAAI;AAAA,SACP;AAAA,MACJ,OAAO,SAAS,IAAI,MAAM,IAAI,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,EAAE,KAAK,GAAG;AAAA,SACnE;AAAA,MACJ,OAAO,UAAU,OAAO,KAAK,IAAI,KAAK,EAEpC,IAAI,CAAC,QAAQ,IAAI,OAAO,YAAY,IAAI,MAAM,MAAO,QAAQ,IAAI,EACjE,KAAK,GAAG;AAAA,SACN;AAAA,MACJ,OAAO,IAAI,IAAI;AAAA,SACX;AAAA,MACJ,OAAO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AkB,SAAS,IAAI,oBAAoB;AAAA,IACpD,oBACC,kBAAkB,SAAS,IAAI,oBAAoB;AAAA,IACpD,gBAAgB,cAAc,SAAS,IAAI,gBAAgB;AAAA,EAC5D;AAAA;",
11
+ "debugId": "4968AF95FABE160264756E2164756E21",
12
+ "names": []
13
+ }
@@ -3,22 +3,19 @@ import {
3
3
  assertNoFeeTierForProvider,
4
4
  broadcastWithNonceReset,
5
5
  estimateFee,
6
- extendedApiSource,
7
6
  isFeeTier,
8
7
  isProviderAccount,
8
+ releaseNonce,
9
9
  resolveFee,
10
10
  resolveNonce,
11
11
  setUnsignedFee
12
- } from "./stacks-fb75yew8.js";
12
+ } from "./stacks-n4d8j8q3.js";
13
13
  import {
14
14
  MalformedResponseError
15
- } from "./stacks-27fmgajb.js";
16
- import {
17
- BaseError
18
- } from "./stacks-709tra19.js";
15
+ } from "./stacks-ga026yxz.js";
19
16
  import {
20
17
  structuredDataHash
21
- } from "./stacks-1arrcd11.js";
18
+ } from "./stacks-v2rfr46a.js";
22
19
  import {
23
20
  buildContractDeploy,
24
21
  buildTokenTransfer,
@@ -26,24 +23,27 @@ import {
26
23
  signMultiSigWithAccount,
27
24
  signSponsorWithAccount,
28
25
  signTransactionWithAccount
29
- } from "./stacks-hnqt5rz4.js";
26
+ } from "./stacks-9c1yam8b.js";
30
27
  import {
31
28
  AddressHashMode,
32
29
  AuthType,
33
30
  PayloadType,
34
31
  deserializeTransaction,
35
32
  serializeTransactionHex
36
- } from "./stacks-w23294am.js";
33
+ } from "./stacks-51ybf135.js";
37
34
  import {
38
35
  Cl,
39
36
  deserializeCVBytes,
40
37
  serializeCVBytes
41
- } from "./stacks-ttdk2g2f.js";
38
+ } from "./stacks-69nq48jp.js";
39
+ import {
40
+ BaseError
41
+ } from "./stacks-4hs8r4q2.js";
42
42
  import {
43
43
  isClarityName,
44
44
  parseContractId,
45
45
  validateStacksAddress
46
- } from "./stacks-bfan7ex7.js";
46
+ } from "./stacks-4d7c3x27.js";
47
47
  import {
48
48
  bytesToHex,
49
49
  c32address,
@@ -54,14 +54,12 @@ import {
54
54
  // src/actions/public/getAccountHistory.ts
55
55
  async function getAccountHistory(client, params) {
56
56
  const limit = Math.min(params.limit ?? 20, 50);
57
- return client.request(`/extended/v2/addresses/${params.address}/transactions?limit=${limit}`, { method: "GET" });
57
+ return client.request(`/extended/v2/addresses/${encodeURIComponent(params.address)}/transactions?limit=${limit}`, { method: "GET" });
58
58
  }
59
59
 
60
60
  // src/actions/public/getAccountInfo.ts
61
61
  async function getAccountInfo(client, params) {
62
- const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
63
- method: "GET"
64
- });
62
+ const data = await client.request(`/v2/accounts/${encodeURIComponent(params.address)}?proof=1`, { method: "GET" });
65
63
  const balance = data?.balance;
66
64
  const nonce = data?.nonce;
67
65
  if (typeof balance !== "string" && typeof balance !== "number" || typeof nonce !== "string" && typeof nonce !== "number") {
@@ -78,16 +76,16 @@ async function getAccountInfo(client, params) {
78
76
  // src/actions/public/getBlock.ts
79
77
  async function getBlock(client, params) {
80
78
  if (params?.hash) {
81
- return client.request(`/extended/v2/blocks/${params.hash}`, {
82
- method: "GET"
83
- });
79
+ return client.request(`/extended/v2/blocks/${encodeURIComponent(params.hash)}`, { method: "GET" });
84
80
  }
85
81
  if (params?.height !== undefined) {
86
- return client.request(`/extended/v2/blocks/${params.height}`, {
87
- method: "GET"
88
- });
82
+ return client.request(`/extended/v2/blocks/${encodeURIComponent(String(params.height))}`, { method: "GET" });
89
83
  }
90
- return client.request("/extended/v2/blocks?limit=1", { method: "GET" });
84
+ const data = await client.request("/extended/v2/blocks?limit=1", {
85
+ method: "GET"
86
+ });
87
+ const results = data?.results;
88
+ return Array.isArray(results) ? results[0] ?? null : data;
91
89
  }
92
90
 
93
91
  // src/actions/public/getContractAbi.ts
@@ -136,13 +134,6 @@ async function getRawBlock(client, params) {
136
134
  }
137
135
  }
138
136
 
139
- // src/actions/public/getTransaction.ts
140
- async function getTransaction(client, params) {
141
- const source = params.source ?? extendedApiSource();
142
- const { receipt } = await source.get({ client, txid: params.txid });
143
- return receipt;
144
- }
145
-
146
137
  // src/errors/simulation.ts
147
138
  class SimulationError extends BaseError {
148
139
  name = "SimulationError";
@@ -231,27 +222,35 @@ async function deployContract(client, params) {
231
222
  });
232
223
  return result.txid;
233
224
  }
225
+ const managed = params.nonce === undefined && client.nonceManager !== undefined;
234
226
  const nonce = params.nonce ?? await resolveNonce(client, account.address);
235
- const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
236
- const unsigned = buildContractDeploy({
237
- contractName: params.contractName,
238
- codeBody: params.codeBody,
239
- clarityVersion: params.clarityVersion,
240
- fee: needsFeeResolution ? 0n : params.fee,
241
- nonce,
242
- publicKey: account.publicKey,
243
- chain: client.chain,
244
- postConditionMode: params.postConditionMode,
245
- postConditions: params.postConditions
246
- });
247
- if (needsFeeResolution) {
248
- setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
227
+ try {
228
+ const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
229
+ const unsigned = buildContractDeploy({
230
+ contractName: params.contractName,
231
+ codeBody: params.codeBody,
232
+ clarityVersion: params.clarityVersion,
233
+ fee: needsFeeResolution ? 0n : params.fee,
234
+ nonce,
235
+ publicKey: account.publicKey,
236
+ chain: client.chain,
237
+ postConditionMode: params.postConditionMode,
238
+ postConditions: params.postConditions
239
+ });
240
+ if (needsFeeResolution) {
241
+ const { fee } = await resolveFee(client, unsigned, params.fee);
242
+ setUnsignedFee(unsigned, fee);
243
+ }
244
+ const signed = await signTransactionWithAccount(unsigned, account);
245
+ return await broadcastWithNonceReset(client, {
246
+ transaction: signed,
247
+ address: account.address
248
+ });
249
+ } catch (error) {
250
+ if (managed)
251
+ await releaseNonce(client, account.address, nonce);
252
+ throw error;
249
253
  }
250
- const signed = await signTransactionWithAccount(unsigned, account);
251
- return broadcastWithNonceReset(client, {
252
- transaction: signed,
253
- address: account.address
254
- });
255
254
  }
256
255
 
257
256
  // src/actions/wallet/signMessage.ts
@@ -317,8 +316,16 @@ async function sponsorTransaction(client, params) {
317
316
  if (isProviderAccount(account)) {
318
317
  throw new Error("Provider accounts cannot sponsor transactions");
319
318
  }
319
+ const managed = params.nonce == null && client.nonceManager !== undefined;
320
320
  const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
321
- const fee = await resolveFee(client, transaction, params.fee);
321
+ let fee;
322
+ try {
323
+ ({ fee } = await resolveFee(client, transaction, params.fee));
324
+ } catch (error) {
325
+ if (managed)
326
+ await releaseNonce(client, account.address, nonce);
327
+ throw error;
328
+ }
322
329
  const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
323
330
  const auth = transaction.auth;
324
331
  const sponsored = {
@@ -347,30 +354,38 @@ async function transferStx(client, params) {
347
354
  });
348
355
  return result.txid;
349
356
  }
357
+ const managed = params.nonce === undefined && client.nonceManager !== undefined;
350
358
  const nonce = params.nonce ?? await resolveNonce(client, account.address);
351
- const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
352
- const unsigned = buildTokenTransfer({
353
- recipient: params.to,
354
- amount: params.amount,
355
- memo: params.memo,
356
- fee: needsFeeResolution ? 0n : params.fee,
357
- nonce,
358
- publicKey: account.publicKey,
359
- chain: client.chain,
360
- postConditionMode: params.postConditionMode,
361
- postConditions: params.postConditions
362
- });
363
- if (needsFeeResolution) {
364
- setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
359
+ try {
360
+ const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
361
+ const unsigned = buildTokenTransfer({
362
+ recipient: params.to,
363
+ amount: params.amount,
364
+ memo: params.memo,
365
+ fee: needsFeeResolution ? 0n : params.fee,
366
+ nonce,
367
+ publicKey: account.publicKey,
368
+ chain: client.chain,
369
+ postConditionMode: params.postConditionMode,
370
+ postConditions: params.postConditions
371
+ });
372
+ if (needsFeeResolution) {
373
+ const { fee } = await resolveFee(client, unsigned, params.fee);
374
+ setUnsignedFee(unsigned, fee);
375
+ }
376
+ const signed = await signTransactionWithAccount(unsigned, account);
377
+ return await broadcastWithNonceReset(client, {
378
+ transaction: signed,
379
+ address: account.address
380
+ });
381
+ } catch (error) {
382
+ if (managed)
383
+ await releaseNonce(client, account.address, nonce);
384
+ throw error;
365
385
  }
366
- const signed = await signTransactionWithAccount(unsigned, account);
367
- return broadcastWithNonceReset(client, {
368
- transaction: signed,
369
- address: account.address
370
- });
371
386
  }
372
387
 
373
- export { getAccountHistory, getAccountInfo, getBlock, getContractAbi, getContractSource, getMempoolStats, getNftHoldings, getRawBlock, getTransaction, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, sponsorTransaction, transferStx };
388
+ export { getAccountHistory, getAccountInfo, getBlock, getContractAbi, getContractSource, getMempoolStats, getNftHoldings, getRawBlock, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, sponsorTransaction, transferStx };
374
389
 
375
- //# debugId=0B1CF001297B4A1064756E2164756E21
376
- //# sourceMappingURL=stacks-7wkf2rph.js.map
390
+ //# debugId=BE89AC7F1F124EB864756E2164756E21
391
+ //# sourceMappingURL=stacks-7bqkf3b0.js.map