@secondlayer/stacks 3.3.1 → 4.1.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 (130) hide show
  1. package/README.md +4 -0
  2. package/dist/shared/stacks-1arrcd11.js +48 -0
  3. package/dist/shared/stacks-1arrcd11.js.map +10 -0
  4. package/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
  5. package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
  6. package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
  7. package/dist/shared/stacks-9mqveyjv.cjs.map +2 -2
  8. package/dist/shared/{stacks-8e5atbps.cjs → stacks-9qcr921s.cjs} +49 -5
  9. package/dist/shared/stacks-9qcr921s.cjs.map +10 -0
  10. package/dist/shared/{stacks-r1m1r72q.js → stacks-bw8qvqd1.js} +49 -23
  11. package/dist/shared/stacks-bw8qvqd1.js.map +27 -0
  12. package/dist/shared/stacks-enpj9krt.cjs +38 -0
  13. package/dist/shared/stacks-enpj9krt.cjs.map +10 -0
  14. package/dist/shared/{stacks-s361pmzs.cjs → stacks-fb75yew8.js} +86 -2
  15. package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-fb75yew8.js.map} +6 -4
  16. package/dist/shared/{stacks-rw2xbtdv.js → stacks-gxq2pbky.js} +2 -2
  17. package/dist/shared/{stacks-rw2xbtdv.js.map → stacks-gxq2pbky.js.map} +1 -1
  18. package/dist/shared/{stacks-jx146qf1.js → stacks-hnqt5rz4.js} +27 -377
  19. package/dist/shared/stacks-hnqt5rz4.js.map +13 -0
  20. package/dist/shared/{stacks-v1hzk599.js → stacks-jpt52csy.js} +8 -10
  21. package/dist/shared/stacks-jpt52csy.js.map +10 -0
  22. package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
  23. package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
  24. package/dist/shared/{stacks-bm49tsh0.js → stacks-rpqtgpyj.js} +42 -9
  25. package/dist/shared/stacks-rpqtgpyj.js.map +10 -0
  26. package/dist/shared/{stacks-g2qnr5qn.cjs → stacks-rryme9bv.cjs} +11 -364
  27. package/dist/shared/stacks-rryme9bv.cjs.map +13 -0
  28. package/dist/shared/{stacks-byyex2zk.cjs → stacks-ta1gar0b.cjs} +7 -2
  29. package/dist/shared/{stacks-byyex2zk.cjs.map → stacks-ta1gar0b.cjs.map} +2 -2
  30. package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
  31. package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
  32. package/dist/shared/stacks-vea7nde7.cjs +731 -0
  33. package/dist/shared/stacks-vea7nde7.cjs.map +13 -0
  34. package/dist/shared/stacks-w23294am.js +760 -0
  35. package/dist/shared/stacks-w23294am.js.map +13 -0
  36. package/dist/shared/{stacks-fvnxj77s.cjs → stacks-y4f7fm03.cjs} +33 -13
  37. package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-y4f7fm03.cjs.map} +7 -6
  38. package/dist/src/accounts/index.d.cts +1 -1
  39. package/dist/src/accounts/index.d.ts +1 -1
  40. package/dist/src/actions/index.d.cts +15 -11
  41. package/dist/src/actions/index.d.ts +15 -11
  42. package/dist/src/actions/index.js +21 -25
  43. package/dist/src/actions/index.js.map +1 -1
  44. package/dist/src/bitcoin/index.d.cts +29 -29
  45. package/dist/src/bitcoin/index.d.ts +29 -29
  46. package/dist/src/bitcoin/index.js +5 -6
  47. package/dist/src/bitcoin/index.js.map +2 -2
  48. package/dist/src/bns/index.d.cts +1 -1
  49. package/dist/src/bns/index.d.ts +1 -1
  50. package/dist/src/bns/index.js +9 -10
  51. package/dist/src/bns/index.js.map +2 -2
  52. package/dist/src/clarity/index.d.cts +37 -1
  53. package/dist/src/clarity/index.d.ts +37 -1
  54. package/dist/src/clarity/index.js +14 -2
  55. package/dist/src/clarity/index.js.map +1 -1
  56. package/dist/src/index.cjs.map +2 -2
  57. package/dist/src/index.d.cts +18 -14
  58. package/dist/src/index.d.ts +18 -14
  59. package/dist/src/index.js +22 -27
  60. package/dist/src/index.js.map +3 -3
  61. package/dist/src/postconditions/index.d.cts +66 -3
  62. package/dist/src/postconditions/index.d.ts +66 -3
  63. package/dist/src/postconditions/index.js +13 -3
  64. package/dist/src/postconditions/index.js.map +1 -1
  65. package/dist/src/pox/index.d.cts +1 -1
  66. package/dist/src/pox/index.d.ts +1 -1
  67. package/dist/src/pox/index.js +7 -9
  68. package/dist/src/pox/index.js.map +2 -2
  69. package/dist/src/pox5/index.cjs +213 -14
  70. package/dist/src/pox5/index.cjs.map +8 -7
  71. package/dist/src/pox5/index.d.cts +88 -5
  72. package/dist/src/pox5/index.d.ts +88 -5
  73. package/dist/src/pox5/index.js +222 -21
  74. package/dist/src/pox5/index.js.map +8 -7
  75. package/dist/src/sbtc/index.d.cts +1 -1
  76. package/dist/src/sbtc/index.d.ts +1 -1
  77. package/dist/src/sbtc/index.js +6 -7
  78. package/dist/src/sbtc/index.js.map +2 -2
  79. package/dist/src/stackingdao/index.d.cts +1 -1
  80. package/dist/src/stackingdao/index.d.ts +1 -1
  81. package/dist/src/stackingdao/index.js +7 -9
  82. package/dist/src/stackingdao/index.js.map +2 -2
  83. package/dist/src/subscriptions/index.d.cts +1 -1
  84. package/dist/src/subscriptions/index.d.ts +1 -1
  85. package/dist/src/tools/index.cjs +494 -367
  86. package/dist/src/tools/index.cjs.map +11 -9
  87. package/dist/src/tools/index.d.cts +1 -1
  88. package/dist/src/tools/index.d.ts +1 -1
  89. package/dist/src/tools/index.js +494 -367
  90. package/dist/src/tools/index.js.map +11 -9
  91. package/dist/src/transactions/index.cjs +3 -1
  92. package/dist/src/transactions/index.cjs.map +1 -1
  93. package/dist/src/transactions/index.d.cts +16 -9
  94. package/dist/src/transactions/index.d.ts +16 -9
  95. package/dist/src/transactions/index.js +31 -27
  96. package/dist/src/transactions/index.js.map +1 -1
  97. package/package.json +2 -7
  98. package/dist/shared/stacks-1mpmzzyp.js +0 -85
  99. package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
  100. package/dist/shared/stacks-44y18a8e.cjs +0 -28
  101. package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
  102. package/dist/shared/stacks-8e5atbps.cjs.map +0 -10
  103. package/dist/shared/stacks-8khy9v27.cjs +0 -7
  104. package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
  105. package/dist/shared/stacks-bm49tsh0.js.map +0 -10
  106. package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
  107. package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
  108. package/dist/shared/stacks-fh48neva.js +0 -13
  109. package/dist/shared/stacks-fh48neva.js.map +0 -10
  110. package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
  111. package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
  112. package/dist/shared/stacks-g2qnr5qn.cjs.map +0 -15
  113. package/dist/shared/stacks-gkf9tsws.js +0 -285
  114. package/dist/shared/stacks-gkf9tsws.js.map +0 -10
  115. package/dist/shared/stacks-jx146qf1.js.map +0 -15
  116. package/dist/shared/stacks-qjgh6pqr.cjs +0 -258
  117. package/dist/shared/stacks-qjgh6pqr.cjs.map +0 -10
  118. package/dist/shared/stacks-r1m1r72q.js.map +0 -26
  119. package/dist/shared/stacks-v1hzk599.js.map +0 -10
  120. package/dist/shared/stacks-w8tt1fmt.js +0 -44
  121. package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
  122. package/dist/shared/stacks-z53fwfcm.js +0 -3
  123. package/dist/shared/stacks-z53fwfcm.js.map +0 -9
  124. package/dist/src/x402/index.cjs +0 -65
  125. package/dist/src/x402/index.cjs.map +0 -11
  126. package/dist/src/x402/index.d.cts +0 -501
  127. package/dist/src/x402/index.d.ts +0 -501
  128. package/dist/src/x402/index.js +0 -90
  129. package/dist/src/x402/index.js.map +0 -11
  130. /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
package/README.md CHANGED
@@ -130,6 +130,7 @@ Activation gating is chain-reported, not hardcoded: `client.pox5.isActive()` / `
130
130
  ```ts
131
131
  import { createWalletClient, http } from "@secondlayer/stacks";
132
132
  import { mainnet } from "@secondlayer/stacks/chains";
133
+ import { Pc } from "@secondlayer/stacks/postconditions";
133
134
  import { pox5 } from "@secondlayer/stacks/pox5";
134
135
 
135
136
  const client = createWalletClient({ chain: mainnet, transport: http(), account })
@@ -142,6 +143,9 @@ if (await client.pox5.isActive()) {
142
143
  numCycles: 12,
143
144
  startBurnHeight: 960_231,
144
145
  fee: "low",
146
+ postConditions: [
147
+ Pc.principal(account.address).willSendEq(100_000_000_000n).ustxToLock(),
148
+ ],
145
149
  });
146
150
  await client.waitForTransactionReceipt({ txid });
147
151
  }
@@ -0,0 +1,48 @@
1
+ import {
2
+ serializeCVBytes
3
+ } from "./stacks-ttdk2g2f.js";
4
+ import {
5
+ bytesToHex,
6
+ concatBytes
7
+ } from "./stacks-qs5fzts5.js";
8
+
9
+ // src/clarity/structuredData.ts
10
+ import { sha256 } from "@noble/hashes/sha2.js";
11
+ var SIP018_PREFIX = new Uint8Array([
12
+ 83,
13
+ 73,
14
+ 80,
15
+ 48,
16
+ 49,
17
+ 56
18
+ ]);
19
+ function hashStructuredData(structuredData) {
20
+ return sha256(serializeCVBytes(structuredData));
21
+ }
22
+ function isDomain(value) {
23
+ if (value.type !== "tuple")
24
+ return false;
25
+ const { name, version, "chain-id": chainId } = value.value;
26
+ return name?.type === "ascii" && version?.type === "ascii" && chainId?.type === "uint";
27
+ }
28
+ function encodeStructuredData(opts) {
29
+ if (!isDomain(opts.domain)) {
30
+ throw new Error("domain must be a tuple { name: ascii, version: ascii, chain-id: uint }");
31
+ }
32
+ return concatBytes(SIP018_PREFIX, hashStructuredData(opts.domain), hashStructuredData(opts.message));
33
+ }
34
+ function structuredDataHash(opts) {
35
+ return sha256(encodeStructuredData(opts));
36
+ }
37
+ async function signStructuredData(account, opts) {
38
+ const vrs = await account.sign(structuredDataHash(opts));
39
+ if (vrs.length !== 65) {
40
+ throw new Error(`Expected 65-byte recoverable signature, got ${vrs.length}`);
41
+ }
42
+ return bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));
43
+ }
44
+
45
+ export { SIP018_PREFIX, hashStructuredData, encodeStructuredData, structuredDataHash, signStructuredData };
46
+
47
+ //# debugId=196BB7249717D5DE64756E2164756E21
48
+ //# sourceMappingURL=stacks-1arrcd11.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/clarity/structuredData.ts"],
4
+ "sourcesContent": [
5
+ "import { sha256 } from \"@noble/hashes/sha2.js\";\nimport type { LocalAccount } from \"../accounts/types.ts\";\nimport { bytesToHex, concatBytes } from \"../utils/encoding.ts\";\nimport { serializeCVBytes } from \"./serialize.ts\";\nimport type { ClarityValue, TupleCV } from \"./types.ts\";\n\n/** asciiToBytes(\"SIP018\") */\nexport const SIP018_PREFIX = new Uint8Array([\n\t0x53, 0x49, 0x50, 0x30, 0x31, 0x38,\n]);\n\n/** sha256(serialize(cv)) — inner hash used by SIP-018. */\nexport function hashStructuredData(structuredData: ClarityValue): Uint8Array {\n\treturn sha256(serializeCVBytes(structuredData));\n}\n\nfunction isDomain(value: ClarityValue): value is TupleCV {\n\tif (value.type !== \"tuple\") return false;\n\tconst { name, version, \"chain-id\": chainId } = value.value;\n\treturn (\n\t\tname?.type === \"ascii\" &&\n\t\tversion?.type === \"ascii\" &&\n\t\tchainId?.type === \"uint\"\n\t);\n}\n\n/**\n * SIP-018 encoding: `\"SIP018\" || sha256(serialize(domain)) || sha256(serialize(message))`.\n * The signature is over `sha256` of this buffer.\n */\nexport function encodeStructuredData(opts: {\n\tmessage: ClarityValue;\n\tdomain: ClarityValue;\n}): Uint8Array {\n\tif (!isDomain(opts.domain)) {\n\t\tthrow new Error(\n\t\t\t\"domain must be a tuple { name: ascii, version: ascii, chain-id: uint }\",\n\t\t);\n\t}\n\treturn concatBytes(\n\t\tSIP018_PREFIX,\n\t\thashStructuredData(opts.domain),\n\t\thashStructuredData(opts.message),\n\t);\n}\n\n/** SIP-018 message hash: sha256(encodeStructuredData(...)). */\nexport function structuredDataHash(opts: {\n\tmessage: ClarityValue;\n\tdomain: ClarityValue;\n}): Uint8Array {\n\treturn sha256(encodeStructuredData(opts));\n}\n\n/**\n * Sign a SIP-018 structured message. Returns a 65-byte recoverable signature\n * in RSV order (recovery byte last) — the layout contracts expect.\n */\nexport async function signStructuredData(\n\taccount: LocalAccount,\n\topts: { message: ClarityValue; domain: ClarityValue },\n): Promise<string> {\n\tconst vrs = await account.sign(structuredDataHash(opts));\n\tif (vrs.length !== 65) {\n\t\tthrow new Error(\n\t\t\t`Expected 65-byte recoverable signature, got ${vrs.length}`,\n\t\t);\n\t}\n\treturn bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));\n}\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;AAAA;AAOO,IAAM,gBAAgB,IAAI,WAAW;AAAA,EAC3C;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAC/B,CAAC;AAGM,SAAS,kBAAkB,CAAC,gBAA0C;AAAA,EAC5E,OAAO,OAAO,iBAAiB,cAAc,CAAC;AAAA;AAG/C,SAAS,QAAQ,CAAC,OAAuC;AAAA,EACxD,IAAI,MAAM,SAAS;AAAA,IAAS,OAAO;AAAA,EACnC,QAAQ,MAAM,SAAS,YAAY,YAAY,MAAM;AAAA,EACrD,OACC,MAAM,SAAS,WACf,SAAS,SAAS,WAClB,SAAS,SAAS;AAAA;AAQb,SAAS,oBAAoB,CAAC,MAGtB;AAAA,EACd,IAAI,CAAC,SAAS,KAAK,MAAM,GAAG;AAAA,IAC3B,MAAM,IAAI,MACT,wEACD;AAAA,EACD;AAAA,EACA,OAAO,YACN,eACA,mBAAmB,KAAK,MAAM,GAC9B,mBAAmB,KAAK,OAAO,CAChC;AAAA;AAIM,SAAS,kBAAkB,CAAC,MAGpB;AAAA,EACd,OAAO,OAAO,qBAAqB,IAAI,CAAC;AAAA;AAOzC,eAAsB,kBAAkB,CACvC,SACA,MACkB;AAAA,EAClB,MAAM,MAAM,MAAM,QAAQ,KAAK,mBAAmB,IAAI,CAAC;AAAA,EACvD,IAAI,IAAI,WAAW,IAAI;AAAA,IACtB,MAAM,IAAI,MACT,+CAA+C,IAAI,QACpD;AAAA,EACD;AAAA,EACA,OAAO,WAAW,YAAY,IAAI,MAAM,CAAC,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;AAAA;",
8
+ "debugId": "196BB7249717D5DE64756E2164756E21",
9
+ "names": []
10
+ }
@@ -1,3 +1,6 @@
1
+ import {
2
+ BaseError
3
+ } from "./stacks-709tra19.js";
1
4
  import {
2
5
  deserializeCVBytes,
3
6
  serializeCVBytes
@@ -10,6 +13,11 @@ import {
10
13
  with0x
11
14
  } from "./stacks-qs5fzts5.js";
12
15
 
16
+ // src/errors/response.ts
17
+ class MalformedResponseError extends BaseError {
18
+ name = "MalformedResponseError";
19
+ }
20
+
13
21
  // src/actions/public/readContract.ts
14
22
  async function readContract(client, params) {
15
23
  const [address, name] = parseContractId(params.contract);
@@ -29,7 +37,7 @@ async function readContract(client, params) {
29
37
  throw new Error(data.cause ?? "Read-only call failed");
30
38
  }
31
39
 
32
- export { readContract };
40
+ export { MalformedResponseError, readContract };
33
41
 
34
- //# debugId=0C52945E9698380964756E2164756E21
35
- //# sourceMappingURL=stacks-6bgh2c9h.js.map
42
+ //# debugId=9666294BE2DE5A1364756E2164756E21
43
+ //# sourceMappingURL=stacks-27fmgajb.js.map
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/actions/public/readContract.ts"],
3
+ "sources": ["../src/errors/response.ts", "../src/actions/public/readContract.ts"],
4
4
  "sourcesContent": [
5
+ "import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n",
5
6
  "import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type ReadContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n\t/**\n\t * Nakamoto StacksBlockId to evaluate against. Without it the node answers\n\t * at its own moving tip, which makes a read non-deterministic — the same\n\t * reindex of the same block can return a different value.\n\t */\n\ttip?: string;\n};\n\nexport async function readContract<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: ReadContractParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst sender = params.sender ?? address;\n\n\tconst serializedArgs = (params.args ?? []).map((arg) =>\n\t\twith0x(bytesToHex(serializeCVBytes(arg))),\n\t);\n\n\tconst path = `/v2/contracts/call-read/${address}/${name}/${params.functionName}`;\n\tconst data = await client.request(\n\t\tparams.tip ? `${path}?tip=${params.tip}` : path,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tsender,\n\t\t\t\targuments: serializedArgs,\n\t\t\t},\n\t\t},\n\t);\n\n\tif (data.okay) {\n\t\treturn deserializeCVBytes<T>(data.result);\n\t}\n\tthrow new Error(data.cause ?? \"Read-only call failed\");\n}\n"
6
7
  ],
7
- "mappings": ";AAoBA,eAAsB,YAAmD,CACxE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,SAAS,OAAO,UAAU;AAAA,EAEhC,MAAM,kBAAkB,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,QAC/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
  readContract
3
- } from "./stacks-6bgh2c9h.js";
3
+ } from "./stacks-27fmgajb.js";
4
4
 
5
5
  // src/actions/public/multicall.ts
6
6
  async function multicall(client, params) {
@@ -19,4 +19,4 @@ async function multicall(client, params) {
19
19
  export { multicall };
20
20
 
21
21
  //# debugId=7B700090E4A219F464756E2164756E21
22
- //# sourceMappingURL=stacks-jknrzd6v.js.map
22
+ //# sourceMappingURL=stacks-2evvn48s.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/actions/getContract.ts"],
4
4
  "sourcesContent": [
5
- "import type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiMap,\n\tAbiType,\n\tAbiTypesOf,\n\tContractTypes,\n\tExtractFunctionArgs,\n\tExtractFunctionOutput,\n\tExtractMapKey,\n\tExtractMapNames,\n\tExtractMapValue,\n\tExtractPublicFunctions,\n\tExtractReadOnlyFunctions,\n} from \"../clarity/abi/index.ts\";\nimport { type ToCamelCase, toCamelCase } from \"../clarity/abi/utils.ts\";\nimport {\n\tclarityValueToJSUntyped,\n\tjsToClarityValue,\n} from \"../clarity/bridge.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport { buildContractCall } from \"../transactions/build.ts\";\nimport type { StacksTransaction } from \"../transactions/types.ts\";\nimport { publicKeyToAddress } from \"../utils/address.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { estimateFee } from \"./public/estimateFee.ts\";\nimport { getMapEntry } from \"./public/getMapEntry.ts\";\nimport { readContract } from \"./public/readContract.ts\";\nimport { callContract } from \"./wallet/callContract.ts\";\nimport { resolveNonce } from \"./wallet/nonceManager.ts\";\nimport { setUnsignedFee } from \"./wallet/utils.ts\";\n\n// --- Type helpers for unwrapping response types ---\n\n/**\n * Unwrap `(response ok err)` → just the `ok` branch type. Distributes over the\n * `{ ok } | { err }` union: the `err` branch maps to `never` (it throws\n * `ContractResponseError` at runtime, so it never reaches the caller).\n */\nexport type UnwrapResponse<T> = T extends { ok: infer O }\n\t? O\n\t: T extends { err: unknown }\n\t\t? never\n\t\t: T;\n\ntype ReadMethodReturn<\n\tC extends AbiContract,\n\tN extends ExtractReadOnlyFunctions<C>,\n> = UnwrapResponse<ExtractFunctionOutput<C, N>>;\n\n// --- Public type for the contract instance ---\n\n/**\n * When the ABI carries a codegen brand (`TypedAbi`), method types resolve to\n * the generated named aliases — cleaner hovers and error messages. Un-branded\n * ABIs fall back to structural inference over the as-const literal.\n */\ntype TypedReadMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"read-only\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t) => Promise<UnwrapResponse<T[\"functions\"][K][\"ret\"]>>;\n};\n\ntype TypedCallMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"public\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t\toptions?: ContractCallOptions,\n\t) => Promise<string>;\n};\n\ntype TypedMapMethods<T extends ContractTypes> = {\n\t[K in keyof NonNullable<T[\"maps\"]>]: (\n\t\tkey: NonNullable<T[\"maps\"]>[K][\"key\"],\n\t) => Promise<NonNullable<T[\"maps\"]>[K][\"value\"] | null>;\n};\n\ntype ReadMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t) => Promise<ReadMethodReturn<C, N>>;\n\t\t}\n\t: TypedReadMethods<AbiTypesOf<C>>;\n\ntype CallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => Promise<string>;\n\t\t}\n\t: TypedCallMethods<AbiTypesOf<C>>;\n\ntype MapMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractMapNames<C> as ToCamelCase<N>]: (\n\t\t\t\tkey: ExtractMapKey<C, N>,\n\t\t\t) => Promise<ExtractMapValue<C, N> | null>;\n\t\t}\n\t: TypedMapMethods<AbiTypesOf<C>>;\n\nexport type ContractCallOptions = {\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/**\n * Options for `buildCall.*` — building an unsigned transaction for\n * wallet-signs-later flows. `publicKey` defaults to the client account's\n * public key; `fee`/`nonce` are resolved from the network when omitted.\n */\nexport type ContractBuildCallOptions = ContractCallOptions & {\n\tpublicKey?: string;\n\tsponsored?: boolean;\n};\n\ntype TypedBuildCallMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"public\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t\toptions?: ContractBuildCallOptions,\n\t) => Promise<StacksTransaction>;\n};\n\ntype BuildCallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t\toptions?: ContractBuildCallOptions,\n\t\t\t) => Promise<StacksTransaction>;\n\t\t}\n\t: TypedBuildCallMethods<AbiTypesOf<C>>;\n\nexport type ContractInstance<C extends AbiContract> = {\n\tread: ReadMethods<C>;\n\tcall: CallMethods<C>;\n\t/** Build unsigned transactions (wallet-signs-later) — never broadcasts. */\n\tbuildCall: BuildCallMethods<C>;\n\tmaps: MapMethods<C>;\n};\n\nexport type GetContractParams<C extends AbiContract> = {\n\tclient: Client;\n\taddress: string;\n\tname: string;\n\tabi: C;\n};\n\nexport function getContract<const TAbi extends AbiContract>(\n\tparams: GetContractParams<TAbi>,\n): ContractInstance<TAbi> {\n\tconst { client, address, name: contractName, abi } = params;\n\tconst contractId = `${address}.${contractName}`;\n\n\t// Index functions/maps by name for fast lookup\n\tconst fnByName = new Map<string, AbiFunction>();\n\tfor (const fn of abi.functions) {\n\t\tfnByName.set(fn.name, fn as AbiFunction);\n\t}\n\n\tconst mapByName = new Map<string, AbiMap>();\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tmapByName.set(m.name, m as AbiMap);\n\t\t}\n\t}\n\n\t// Build kebab→camel reverse map for function/map names\n\tconst camelToKebab = new Map<string, string>();\n\tfor (const fn of abi.functions) {\n\t\tcamelToKebab.set(toCamelCase(fn.name), fn.name);\n\t}\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tcamelToKebab.set(toCamelCase(m.name), m.name);\n\t\t}\n\t}\n\n\tconst read = new Proxy({} as ReadMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"read-only\") return undefined;\n\n\t\t\treturn async (args: Record<string, unknown>) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst result = await readContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\targs: clarityArgs,\n\t\t\t\t});\n\n\t\t\t\tconst jsValue = clarityValueToJSUntyped(fn.outputs as AbiType, result);\n\n\t\t\t\t// Auto-unwrap: if output is response type, unwrap ok / throw on err\n\t\t\t\tif (isResponseOutput(fn.outputs as AbiType)) {\n\t\t\t\t\tconst resp = jsValue as { ok?: unknown; err?: unknown };\n\t\t\t\t\tif (\"ok\" in resp) return resp.ok;\n\t\t\t\t\tthrow new ContractResponseError(\n\t\t\t\t\t\t`${contractId}::${fn.name} returned (err ${formatErrValue(resp.err)})`,\n\t\t\t\t\t\tresp.err,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn jsValue;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst call = new Proxy({} as CallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\treturn callContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs: clarityArgs,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t});\n\n\tconst buildCall = new Proxy({} as BuildCallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractBuildCallOptions,\n\t\t\t) => {\n\t\t\t\tconst publicKey = options?.publicKey ?? client.account?.publicKey;\n\t\t\t\tif (!publicKey) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"buildCall requires a publicKey (pass options.publicKey or configure a client account)\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst functionArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst network = client.chain?.network ?? \"mainnet\";\n\t\t\t\tconst nonce =\n\t\t\t\t\toptions?.nonce ??\n\t\t\t\t\t(await resolveNonce(client, publicKeyToAddress(publicKey, network)));\n\n\t\t\t\tconst unsigned = buildContractCall({\n\t\t\t\t\tcontractAddress: address,\n\t\t\t\t\tcontractName,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs,\n\t\t\t\t\tfee: options?.fee ?? 0n,\n\t\t\t\t\tnonce,\n\t\t\t\t\tpublicKey,\n\t\t\t\t\tchain: client.chain,\n\t\t\t\t\tpostConditionMode: options?.postConditionMode,\n\t\t\t\t\tpostConditions: options?.postConditions,\n\t\t\t\t\tsponsored: options?.sponsored,\n\t\t\t\t});\n\n\t\t\t\tif (options?.fee === undefined) {\n\t\t\t\t\tconst estimates = await estimateFee(client, {\n\t\t\t\t\t\ttransaction: unsigned,\n\t\t\t\t\t});\n\t\t\t\t\tconst mid = estimates[1] ?? estimates[0];\n\t\t\t\t\tif (mid) {\n\t\t\t\t\t\tsetUnsignedFee(unsigned, BigInt(mid.fee));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn unsigned;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst maps = new Proxy({} as MapMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst mapName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst map = mapByName.get(mapName);\n\t\t\tif (!map) return undefined;\n\n\t\t\treturn async (key: unknown) => {\n\t\t\t\tconst clarityKey = jsToClarityValue(map.key as AbiType, key);\n\t\t\t\tconst result = await getMapEntry(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tmapName: map.name,\n\t\t\t\t\tkey: clarityKey,\n\t\t\t\t});\n\n\t\t\t\t// Map entries come back as (optional ...). If none, return null.\n\t\t\t\tif (result.type === \"none\") return null;\n\t\t\t\tif (result.type === \"some\") {\n\t\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result.value);\n\t\t\t\t}\n\t\t\t\t// Direct value (shouldn't normally happen, but handle gracefully)\n\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result);\n\t\t\t};\n\t\t},\n\t});\n\n\treturn { read, call, buildCall, maps };\n}\n\n/**\n * Resolve a network-keyed contract config for the client's chain. The contracts\n * map is keyed by network (\"mainnet\" | \"testnet\"), so selection is a direct\n * index — no per-call ternary. Throws if the client has no chain configured.\n */\nexport function resolveNetworkContract<\n\tT extends Record<\"mainnet\" | \"testnet\", { address: string }>,\n>(client: Client, contracts: T): T[\"mainnet\"] | T[\"testnet\"] {\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\treturn contracts[client.chain.network];\n}\n\n// --- Helpers ---\n\n/**\n * Encode an ABI function's named args into positional ClarityValues. Exported\n * so a caller that needs the raw ClarityValue result (to cache or re-serialize\n * it) can reuse the same encoding this module's read methods use, instead of\n * maintaining a second one that drifts.\n */\nexport function buildFunctionArgs(\n\tfn: AbiFunction,\n\targs: Record<string, unknown>,\n): ClarityValue[] {\n\treturn fn.args.map((arg) => {\n\t\tconst camelKey = toCamelCase(arg.name);\n\t\tconst hasOriginal = arg.name in args;\n\t\tconst hasCamel = camelKey in args;\n\t\tconst value = hasOriginal\n\t\t\t? args[arg.name]\n\t\t\t: hasCamel\n\t\t\t\t? args[camelKey]\n\t\t\t\t: undefined;\n\t\tif (value === undefined) throw new Error(`Missing argument: ${arg.name}`);\n\t\treturn jsToClarityValue(arg.type as AbiType, value);\n\t});\n}\n\n/** True when an ABI output is a `(response ok err)` and needs unwrapping. */\nexport function isResponseOutput(type: AbiType): boolean {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nfunction formatErrValue(value: unknown): string {\n\tif (typeof value === \"bigint\") return value.toString();\n\tif (typeof value === \"string\") return `\"${value}\"`;\n\treturn String(value);\n}\n\nexport class ContractResponseError extends Error {\n\toverride name = \"ContractResponseError\";\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly errorValue: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n"
5
+ "import type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiMap,\n\tAbiType,\n\tAbiTypesOf,\n\tContractTypes,\n\tExtractFunctionArgs,\n\tExtractFunctionOutput,\n\tExtractMapKey,\n\tExtractMapNames,\n\tExtractMapValue,\n\tExtractPublicFunctions,\n\tExtractReadOnlyFunctions,\n} from \"../clarity/abi/index.ts\";\nimport { type ToCamelCase, toCamelCase } from \"../clarity/abi/utils.ts\";\nimport {\n\tclarityValueToJSUntyped,\n\tjsToClarityValue,\n} from \"../clarity/bridge.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type {\n\tPostConditionInput,\n\tPostConditionMode,\n} from \"../postconditions/types.ts\";\nimport { buildContractCall } from \"../transactions/build.ts\";\nimport type { StacksTransaction } from \"../transactions/types.ts\";\nimport { publicKeyToAddress } from \"../utils/address.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { estimateFee } from \"./public/estimateFee.ts\";\nimport { getMapEntry } from \"./public/getMapEntry.ts\";\nimport { readContract } from \"./public/readContract.ts\";\nimport { callContract } from \"./wallet/callContract.ts\";\nimport { resolveNonce } from \"./wallet/nonceManager.ts\";\nimport { setUnsignedFee } from \"./wallet/utils.ts\";\n\n// --- Type helpers for unwrapping response types ---\n\n/**\n * Unwrap `(response ok err)` → just the `ok` branch type. Distributes over the\n * `{ ok } | { err }` union: the `err` branch maps to `never` (it throws\n * `ContractResponseError` at runtime, so it never reaches the caller).\n */\nexport type UnwrapResponse<T> = T extends { ok: infer O }\n\t? O\n\t: T extends { err: unknown }\n\t\t? never\n\t\t: T;\n\ntype ReadMethodReturn<\n\tC extends AbiContract,\n\tN extends ExtractReadOnlyFunctions<C>,\n> = UnwrapResponse<ExtractFunctionOutput<C, N>>;\n\n// --- Public type for the contract instance ---\n\n/**\n * When the ABI carries a codegen brand (`TypedAbi`), method types resolve to\n * the generated named aliases — cleaner hovers and error messages. Un-branded\n * ABIs fall back to structural inference over the as-const literal.\n */\ntype TypedReadMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"read-only\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t) => Promise<UnwrapResponse<T[\"functions\"][K][\"ret\"]>>;\n};\n\ntype TypedCallMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"public\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t\toptions?: ContractCallOptions,\n\t) => Promise<string>;\n};\n\ntype TypedMapMethods<T extends ContractTypes> = {\n\t[K in keyof NonNullable<T[\"maps\"]>]: (\n\t\tkey: NonNullable<T[\"maps\"]>[K][\"key\"],\n\t) => Promise<NonNullable<T[\"maps\"]>[K][\"value\"] | null>;\n};\n\ntype ReadMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t) => Promise<ReadMethodReturn<C, N>>;\n\t\t}\n\t: TypedReadMethods<AbiTypesOf<C>>;\n\ntype CallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => Promise<string>;\n\t\t}\n\t: TypedCallMethods<AbiTypesOf<C>>;\n\ntype MapMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractMapNames<C> as ToCamelCase<N>]: (\n\t\t\t\tkey: ExtractMapKey<C, N>,\n\t\t\t) => Promise<ExtractMapValue<C, N> | null>;\n\t\t}\n\t: TypedMapMethods<AbiTypesOf<C>>;\n\nexport type ContractCallOptions = {\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: PostConditionMode;\n\tpostConditions?: PostConditionInput[];\n};\n\n/**\n * Options for `buildCall.*` — building an unsigned transaction for\n * wallet-signs-later flows. `publicKey` defaults to the client account's\n * public key; `fee`/`nonce` are resolved from the network when omitted.\n */\nexport type ContractBuildCallOptions = ContractCallOptions & {\n\tpublicKey?: string;\n\tsponsored?: boolean;\n};\n\ntype TypedBuildCallMethods<T extends ContractTypes> = {\n\t[K in keyof T[\"functions\"] as T[\"functions\"][K][\"access\"] extends \"public\"\n\t\t? K\n\t\t: never]: (\n\t\targs: T[\"functions\"][K][\"args\"],\n\t\toptions?: ContractBuildCallOptions,\n\t) => Promise<StacksTransaction>;\n};\n\ntype BuildCallMethods<C extends AbiContract> = [AbiTypesOf<C>] extends [never]\n\t? {\n\t\t\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\t\t\targs: ExtractFunctionArgs<C, N>,\n\t\t\t\toptions?: ContractBuildCallOptions,\n\t\t\t) => Promise<StacksTransaction>;\n\t\t}\n\t: TypedBuildCallMethods<AbiTypesOf<C>>;\n\nexport type ContractInstance<C extends AbiContract> = {\n\tread: ReadMethods<C>;\n\tcall: CallMethods<C>;\n\t/** Build unsigned transactions (wallet-signs-later) — never broadcasts. */\n\tbuildCall: BuildCallMethods<C>;\n\tmaps: MapMethods<C>;\n};\n\nexport type GetContractParams<C extends AbiContract> = {\n\tclient: Client;\n\taddress: string;\n\tname: string;\n\tabi: C;\n};\n\nexport function getContract<const TAbi extends AbiContract>(\n\tparams: GetContractParams<TAbi>,\n): ContractInstance<TAbi> {\n\tconst { client, address, name: contractName, abi } = params;\n\tconst contractId = `${address}.${contractName}`;\n\n\t// Index functions/maps by name for fast lookup\n\tconst fnByName = new Map<string, AbiFunction>();\n\tfor (const fn of abi.functions) {\n\t\tfnByName.set(fn.name, fn as AbiFunction);\n\t}\n\n\tconst mapByName = new Map<string, AbiMap>();\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tmapByName.set(m.name, m as AbiMap);\n\t\t}\n\t}\n\n\t// Build kebab→camel reverse map for function/map names\n\tconst camelToKebab = new Map<string, string>();\n\tfor (const fn of abi.functions) {\n\t\tcamelToKebab.set(toCamelCase(fn.name), fn.name);\n\t}\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tcamelToKebab.set(toCamelCase(m.name), m.name);\n\t\t}\n\t}\n\n\tconst read = new Proxy({} as ReadMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"read-only\") return undefined;\n\n\t\t\treturn async (args: Record<string, unknown>) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst result = await readContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\targs: clarityArgs,\n\t\t\t\t});\n\n\t\t\t\tconst jsValue = clarityValueToJSUntyped(fn.outputs as AbiType, result);\n\n\t\t\t\t// Auto-unwrap: if output is response type, unwrap ok / throw on err\n\t\t\t\tif (isResponseOutput(fn.outputs as AbiType)) {\n\t\t\t\t\tconst resp = jsValue as { ok?: unknown; err?: unknown };\n\t\t\t\t\tif (\"ok\" in resp) return resp.ok;\n\t\t\t\t\tthrow new ContractResponseError(\n\t\t\t\t\t\t`${contractId}::${fn.name} returned (err ${formatErrValue(resp.err)})`,\n\t\t\t\t\t\tresp.err,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn jsValue;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst call = new Proxy({} as CallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\treturn callContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs: clarityArgs,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t});\n\n\tconst buildCall = new Proxy({} as BuildCallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractBuildCallOptions,\n\t\t\t) => {\n\t\t\t\tconst publicKey = options?.publicKey ?? client.account?.publicKey;\n\t\t\t\tif (!publicKey) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\"buildCall requires a publicKey (pass options.publicKey or configure a client account)\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst functionArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst network = client.chain?.network ?? \"mainnet\";\n\t\t\t\tconst nonce =\n\t\t\t\t\toptions?.nonce ??\n\t\t\t\t\t(await resolveNonce(client, publicKeyToAddress(publicKey, network)));\n\n\t\t\t\tconst unsigned = buildContractCall({\n\t\t\t\t\tcontractAddress: address,\n\t\t\t\t\tcontractName,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs,\n\t\t\t\t\tfee: options?.fee ?? 0n,\n\t\t\t\t\tnonce,\n\t\t\t\t\tpublicKey,\n\t\t\t\t\tchain: client.chain,\n\t\t\t\t\tpostConditionMode: options?.postConditionMode,\n\t\t\t\t\tpostConditions: options?.postConditions,\n\t\t\t\t\tsponsored: options?.sponsored,\n\t\t\t\t});\n\n\t\t\t\tif (options?.fee === undefined) {\n\t\t\t\t\tconst estimates = await estimateFee(client, {\n\t\t\t\t\t\ttransaction: unsigned,\n\t\t\t\t\t});\n\t\t\t\t\tconst mid = estimates[1] ?? estimates[0];\n\t\t\t\t\tif (mid) {\n\t\t\t\t\t\tsetUnsignedFee(unsigned, BigInt(mid.fee));\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn unsigned;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst maps = new Proxy({} as MapMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst mapName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst map = mapByName.get(mapName);\n\t\t\tif (!map) return undefined;\n\n\t\t\treturn async (key: unknown) => {\n\t\t\t\tconst clarityKey = jsToClarityValue(map.key as AbiType, key);\n\t\t\t\tconst result = await getMapEntry(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tmapName: map.name,\n\t\t\t\t\tkey: clarityKey,\n\t\t\t\t});\n\n\t\t\t\t// Map entries come back as (optional ...). If none, return null.\n\t\t\t\tif (result.type === \"none\") return null;\n\t\t\t\tif (result.type === \"some\") {\n\t\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result.value);\n\t\t\t\t}\n\t\t\t\t// Direct value (shouldn't normally happen, but handle gracefully)\n\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result);\n\t\t\t};\n\t\t},\n\t});\n\n\treturn { read, call, buildCall, maps };\n}\n\n/**\n * Resolve a network-keyed contract config for the client's chain. The contracts\n * map is keyed by network (\"mainnet\" | \"testnet\"), so selection is a direct\n * index — no per-call ternary. Throws if the client has no chain configured.\n */\nexport function resolveNetworkContract<\n\tT extends Record<\"mainnet\" | \"testnet\", { address: string }>,\n>(client: Client, contracts: T): T[\"mainnet\"] | T[\"testnet\"] {\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\treturn contracts[client.chain.network];\n}\n\n// --- Helpers ---\n\n/**\n * Encode an ABI function's named args into positional ClarityValues. Exported\n * so a caller that needs the raw ClarityValue result (to cache or re-serialize\n * it) can reuse the same encoding this module's read methods use, instead of\n * maintaining a second one that drifts.\n */\nexport function buildFunctionArgs(\n\tfn: AbiFunction,\n\targs: Record<string, unknown>,\n): ClarityValue[] {\n\treturn fn.args.map((arg) => {\n\t\tconst camelKey = toCamelCase(arg.name);\n\t\tconst hasOriginal = arg.name in args;\n\t\tconst hasCamel = camelKey in args;\n\t\tconst value = hasOriginal\n\t\t\t? args[arg.name]\n\t\t\t: hasCamel\n\t\t\t\t? args[camelKey]\n\t\t\t\t: undefined;\n\t\tif (value === undefined) throw new Error(`Missing argument: ${arg.name}`);\n\t\treturn jsToClarityValue(arg.type as AbiType, value);\n\t});\n}\n\n/** True when an ABI output is a `(response ok err)` and needs unwrapping. */\nexport function isResponseOutput(type: AbiType): boolean {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nfunction formatErrValue(value: unknown): string {\n\tif (typeof value === \"bigint\") return value.toString();\n\tif (typeof value === \"string\") return `\"${value}\"`;\n\treturn String(value);\n}\n\nexport class ContractResponseError extends Error {\n\toverride name = \"ContractResponseError\";\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly errorValue: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n"
6
6
  ],
7
- "mappings": ";AA6JO,SAAS,WAA2C,CAC1D,QACyB;AAAA,EACzB,QAAQ,QAAQ,SAAS,MAAM,cAAc,QAAQ;AAAA,EACrD,MAAM,aAAa,GAAG,WAAW;AAAA,EAGjC,MAAM,WAAW,IAAI;AAAA,EACrB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,SAAS,IAAI,GAAG,MAAM,EAAiB;AAAA,EACxC;AAAA,EAEA,MAAM,YAAY,IAAI;AAAA,EACtB,IAAI,IAAI,MAAM;AAAA,IACb,WAAW,KAAK,IAAI,MAAM;AAAA,MACzB,UAAU,IAAI,EAAE,MAAM,CAAW;AAAA,IAClC;AAAA,EACD;AAAA,EAGA,MAAM,eAAe,IAAI;AAAA,EACzB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,aAAa,IAAI,YAAY,GAAG,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AAQ,cAAc;AAAA;AAGnE,SAAS,cAAc,CAAC,OAAwB;AAAA,EAC/C,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO,MAAM,SAAS;AAAA,EACrD,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO,IAAI;AAAA,EAC1C,OAAO,OAAO,KAAK;AAAA;AAAA;AAGb,MAAM,8BAA8B,MAAM;AAAA,EAI/B;AAAA,EAHR,OAAO;AAAA,EAChB,WAAW,CACV,SACgB,YACf;AAAA,IACD,MAAM,OAAO;AAAA,IAFG;AAAA;AAIlB;",
8
8
  "debugId": "B18B041ED553CE7B64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,3 +1,14 @@
1
+ // src/postconditions/index.ts
2
+ var exports_postconditions = {};
3
+ __export(exports_postconditions, {
4
+ wireToPostCondition: () => wireToPostCondition,
5
+ postConditionToHex: () => postConditionToHex,
6
+ parsePostConditionAmount: () => parsePostConditionAmount,
7
+ fromHex: () => fromHex,
8
+ Pc: () => Pc
9
+ });
10
+ module.exports = __toCommonJS(exports_postconditions);
11
+
1
12
  // src/postconditions/builder.ts
2
13
  class PartialPcWithPrincipal {
3
14
  address;
@@ -25,6 +36,30 @@ class PartialPcWithPrincipal {
25
36
  willNotSendAsset() {
26
37
  return new PartialPcNftWithCode(this.address, "not-sent");
27
38
  }
39
+ willMaybeSendAsset() {
40
+ return new PartialPcNftWithCode(this.address, "maybe-sent");
41
+ }
42
+ willPerformPox() {
43
+ return {
44
+ type: "pox-postcondition",
45
+ address: this.address,
46
+ condition: "will-perform"
47
+ };
48
+ }
49
+ willNotPerformPox() {
50
+ return {
51
+ type: "pox-postcondition",
52
+ address: this.address,
53
+ condition: "will-not-perform"
54
+ };
55
+ }
56
+ mayPerformPox() {
57
+ return {
58
+ type: "pox-postcondition",
59
+ address: this.address,
60
+ condition: "may-perform"
61
+ };
62
+ }
28
63
  }
29
64
 
30
65
  class PartialPcFtWithCode {
@@ -41,7 +76,15 @@ class PartialPcFtWithCode {
41
76
  type: "stx-postcondition",
42
77
  address: this.address,
43
78
  condition: this.code,
44
- amount: intToBigInt(this.amount).toString()
79
+ amount: parsePostConditionAmount(this.amount).toString()
80
+ };
81
+ }
82
+ ustxToLock() {
83
+ return {
84
+ type: "staking-postcondition",
85
+ address: this.address,
86
+ condition: this.code,
87
+ amount: parsePostConditionAmount(this.amount).toString()
45
88
  };
46
89
  }
47
90
  ft(contractId, tokenName) {
@@ -53,7 +96,7 @@ class PartialPcFtWithCode {
53
96
  type: "ft-postcondition",
54
97
  address: this.address,
55
98
  condition: this.code,
56
- amount: intToBigInt(this.amount).toString(),
99
+ amount: parsePostConditionAmount(this.amount).toString(),
57
100
  asset: `${contractId}::${tokenName}`
58
101
  };
59
102
  }
@@ -105,8 +148,9 @@ var Pc = {
105
148
  },
106
149
  origin() {
107
150
  return new PartialPcWithPrincipal("origin");
108
- }
151
+ },
152
+ fromHex
109
153
  };
110
154
 
111
- //# debugId=AD0585B08DA6241D64756E2164756E21
112
- //# sourceMappingURL=stacks-8e5atbps.cjs.map
155
+ //# debugId=0EFCEE34D174071164756E2164756E21
156
+ //# sourceMappingURL=stacks-9qcr921s.cjs.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/postconditions/builder.ts"],
4
+ "sourcesContent": [
5
+ "import type { ClarityValue } from \"../clarity/types.ts\";\nimport { parseContractId, validateStacksAddress } from \"../utils/address.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { fromHex, parsePostConditionAmount } from \"./convert.ts\";\nimport type {\n\tFtPostCondition,\n\tFungibleComparator,\n\tNftPostCondition,\n\tNonFungibleComparator,\n\tPoxPostCondition,\n\tStakingPostCondition,\n\tStxPostCondition,\n} from \"./types.ts\";\n\nclass PartialPcWithPrincipal {\n\tconstructor(private address: string) {}\n\n\twillSendEq(amount: IntegerType) {\n\t\treturn new PartialPcFtWithCode(this.address, amount, \"eq\");\n\t}\n\twillSendGte(amount: IntegerType) {\n\t\treturn new PartialPcFtWithCode(this.address, amount, \"gte\");\n\t}\n\twillSendGt(amount: IntegerType) {\n\t\treturn new PartialPcFtWithCode(this.address, amount, \"gt\");\n\t}\n\twillSendLte(amount: IntegerType) {\n\t\treturn new PartialPcFtWithCode(this.address, amount, \"lte\");\n\t}\n\twillSendLt(amount: IntegerType) {\n\t\treturn new PartialPcFtWithCode(this.address, amount, \"lt\");\n\t}\n\twillSendAsset() {\n\t\treturn new PartialPcNftWithCode(this.address, \"sent\");\n\t}\n\twillNotSendAsset() {\n\t\treturn new PartialPcNftWithCode(this.address, \"not-sent\");\n\t}\n\twillMaybeSendAsset() {\n\t\treturn new PartialPcNftWithCode(this.address, \"maybe-sent\");\n\t}\n\twillPerformPox(): PoxPostCondition {\n\t\treturn {\n\t\t\ttype: \"pox-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: \"will-perform\",\n\t\t};\n\t}\n\twillNotPerformPox(): PoxPostCondition {\n\t\treturn {\n\t\t\ttype: \"pox-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: \"will-not-perform\",\n\t\t};\n\t}\n\tmayPerformPox(): PoxPostCondition {\n\t\treturn {\n\t\t\ttype: \"pox-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: \"may-perform\",\n\t\t};\n\t}\n}\n\nclass PartialPcFtWithCode {\n\tconstructor(\n\t\tprivate address: string,\n\t\tprivate amount: IntegerType,\n\t\tprivate code: FungibleComparator,\n\t) {}\n\n\tustx(): StxPostCondition {\n\t\treturn {\n\t\t\ttype: \"stx-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: this.code,\n\t\t\tamount: parsePostConditionAmount(this.amount).toString(),\n\t\t};\n\t}\n\n\tustxToLock(): StakingPostCondition {\n\t\treturn {\n\t\t\ttype: \"staking-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: this.code,\n\t\t\tamount: parsePostConditionAmount(this.amount).toString(),\n\t\t};\n\t}\n\n\tft(contractId: string, tokenName: string): FtPostCondition {\n\t\tconst [address, name] = contractId.split(\".\");\n\t\tif (!address || !validateStacksAddress(address) || !name) {\n\t\t\tthrow new Error(`Invalid contract id: ${contractId}`);\n\t\t}\n\t\treturn {\n\t\t\ttype: \"ft-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: this.code,\n\t\t\tamount: parsePostConditionAmount(this.amount).toString(),\n\t\t\tasset: `${contractId}::${tokenName}`,\n\t\t};\n\t}\n}\n\nclass PartialPcNftWithCode {\n\tconstructor(\n\t\tprivate address: string,\n\t\tprivate code: NonFungibleComparator,\n\t) {}\n\n\tnft(\n\t\tassetOrContractId: string,\n\t\ttokenNameOrAssetId: string | ClarityValue,\n\t\tassetId?: ClarityValue,\n\t): NftPostCondition {\n\t\tlet contractAddress: string;\n\t\tlet contractName: string;\n\t\tlet tokenName: string;\n\t\tlet id: ClarityValue;\n\n\t\tif (assetId !== undefined) {\n\t\t\t// 3 args: contractId, tokenName, assetId\n\t\t\t[contractAddress, contractName] = parseContractId(assetOrContractId);\n\t\t\ttokenName = tokenNameOrAssetId as string;\n\t\t\tid = assetId;\n\t\t} else {\n\t\t\t// 2 args: assetString (addr.contract::token), assetId\n\t\t\tconst [principal, tName] = assetOrContractId.split(\"::\");\n\t\t\tif (!principal || !tName)\n\t\t\t\tthrow new Error(`Invalid asset name: ${assetOrContractId}`);\n\t\t\t[contractAddress, contractName] = parseContractId(principal);\n\t\t\ttokenName = tName;\n\t\t\tid = tokenNameOrAssetId as ClarityValue;\n\t\t}\n\n\t\tif (!validateStacksAddress(contractAddress)) {\n\t\t\tthrow new Error(`Invalid contract address: ${contractAddress}`);\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"nft-postcondition\",\n\t\t\taddress: this.address,\n\t\t\tcondition: this.code,\n\t\t\tasset: `${contractAddress}.${contractName}::${tokenName}`,\n\t\t\tassetId: id,\n\t\t};\n\t}\n}\n\nexport const Pc = {\n\tprincipal(address: string) {\n\t\tconst [addr, name] = address.split(\".\");\n\t\tif (\n\t\t\t!addr ||\n\t\t\t!validateStacksAddress(addr) ||\n\t\t\t(typeof name === \"string\" && !name)\n\t\t) {\n\t\t\tthrow new Error(`Invalid principal: ${address}`);\n\t\t}\n\t\treturn new PartialPcWithPrincipal(address);\n\t},\n\torigin() {\n\t\treturn new PartialPcWithPrincipal(\"origin\");\n\t},\n\tfromHex,\n};\n"
6
+ ],
7
+ "mappings": ";;;;;;;;;;;;AAcA,MAAM,uBAAuB;AAAA,EACR;AAAA,EAApB,WAAW,CAAS,SAAiB;AAAA,IAAjB;AAAA;AAAA,EAEpB,UAAU,CAAC,QAAqB;AAAA,IAC/B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE1D,WAAW,CAAC,QAAqB;AAAA,IAChC,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,KAAK;AAAA;AAAA,EAE3D,UAAU,CAAC,QAAqB;AAAA,IAC/B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE1D,WAAW,CAAC,QAAqB;AAAA,IAChC,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,KAAK;AAAA;AAAA,EAE3D,UAAU,CAAC,QAAqB;AAAA,IAC/B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE1D,aAAa,GAAG;AAAA,IACf,OAAO,IAAI,qBAAqB,KAAK,SAAS,MAAM;AAAA;AAAA,EAErD,gBAAgB,GAAG;AAAA,IAClB,OAAO,IAAI,qBAAqB,KAAK,SAAS,UAAU;AAAA;AAAA,EAEzD,kBAAkB,GAAG;AAAA,IACpB,OAAO,IAAI,qBAAqB,KAAK,SAAS,YAAY;AAAA;AAAA,EAE3D,cAAc,GAAqB;AAAA,IAClC,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,KAAK;AAAA,MACd,WAAW;AAAA,IACZ;AAAA;AAAA,EAED,iBAAiB,GAAqB;AAAA,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Fee
12
- } from "./stacks-9d2d0qjc.js";
12
+ } from "./stacks-fb75yew8.js";
13
13
  import {
14
14
  MalformedResponseError
15
- } from "./stacks-fh48neva.js";
15
+ } from "./stacks-27fmgajb.js";
16
16
  import {
17
17
  BaseError
18
18
  } from "./stacks-709tra19.js";
19
19
  import {
20
- deserializeTransaction
21
- } from "./stacks-gkf9tsws.js";
20
+ structuredDataHash
21
+ } from "./stacks-1arrcd11.js";
22
22
  import {
23
- AddressHashMode,
24
- PayloadType,
25
23
  buildContractDeploy,
26
24
  buildTokenTransfer,
27
- serializeTransactionHex,
25
+ createSingleSigSpendingCondition,
28
26
  signMultiSigWithAccount,
27
+ signSponsorWithAccount,
29
28
  signTransactionWithAccount
30
- } from "./stacks-jx146qf1.js";
29
+ } from "./stacks-hnqt5rz4.js";
30
+ import {
31
+ AddressHashMode,
32
+ AuthType,
33
+ PayloadType,
34
+ deserializeTransaction,
35
+ serializeTransactionHex
36
+ } from "./stacks-w23294am.js";
31
37
  import {
32
38
  Cl,
33
39
  deserializeCVBytes,
@@ -41,7 +47,7 @@ import {
41
47
  import {
42
48
  bytesToHex,
43
49
  c32address,
44
- concatBytes,
50
+ intToBigInt,
45
51
  with0x
46
52
  } from "./stacks-qs5fzts5.js";
47
53
 
@@ -262,7 +268,6 @@ async function deployContract(client, params) {
262
268
 
263
269
  // src/actions/wallet/signMessage.ts
264
270
  import { sha256 } from "@noble/hashes/sha2.js";
265
- var SIP018_PREFIX = new Uint8Array([83, 73, 80, 48, 49, 56]);
266
271
  async function signMessage(client, params) {
267
272
  const account = client.account;
268
273
  if (!account)
@@ -276,19 +281,14 @@ async function signMessage(client, params) {
276
281
  return result.signature;
277
282
  }
278
283
  const cv = typeof params.message === "string" ? Cl.stringAscii(params.message) : params.message;
279
- const serializedMsg = serializeCVBytes(cv);
280
- let hash;
281
- if (params.domain) {
282
- const domainCV = Cl.tuple({
284
+ const hash = params.domain ? structuredDataHash({
285
+ message: cv,
286
+ domain: Cl.tuple({
283
287
  name: Cl.stringAscii(params.domain.name),
284
288
  version: Cl.stringAscii(params.domain.version),
285
289
  "chain-id": Cl.uint(params.domain.chainId)
286
- });
287
- const serializedDomain = serializeCVBytes(domainCV);
288
- hash = sha256(concatBytes(SIP018_PREFIX, serializedDomain, serializedMsg));
289
- } else {
290
- hash = sha256(serializedMsg);
291
- }
290
+ })
291
+ }) : sha256(serializeCVBytes(cv));
292
292
  const sigBytes = await account.sign(hash);
293
293
  return bytesToHex(sigBytes);
294
294
  }
@@ -317,6 +317,32 @@ async function signTransactionAction(client, params) {
317
317
  return signTransactionWithAccount(params.transaction, account);
318
318
  }
319
319
 
320
+ // src/actions/wallet/sponsorTransaction.ts
321
+ async function sponsorTransaction(client, params) {
322
+ const { transaction } = params;
323
+ if (transaction.auth.authType !== AuthType.Sponsored) {
324
+ throw new Error("Transaction must have sponsored authorization");
325
+ }
326
+ const account = client.account;
327
+ if (!account)
328
+ throw new Error("Account required");
329
+ if (isProviderAccount(account)) {
330
+ throw new Error("Provider accounts cannot sponsor transactions");
331
+ }
332
+ const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
333
+ const fee = await resolveFee(client, transaction, params.fee);
334
+ const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
335
+ const auth = transaction.auth;
336
+ const sponsored = {
337
+ ...transaction,
338
+ auth: {
339
+ ...auth,
340
+ sponsorSpendingCondition: sponsorCondition
341
+ }
342
+ };
343
+ return signSponsorWithAccount(sponsored, account);
344
+ }
345
+
320
346
  // src/actions/wallet/transferStx.ts
321
347
  async function transferStx(client, params) {
322
348
  const account = client.account;
@@ -356,7 +382,7 @@ async function transferStx(client, params) {
356
382
  });
357
383
  }
358
384
 
359
- export { getAccountHistory, getAccountInfo, getBalance, getBlock, getContractAbi, getContractSource, getMempoolStats, getNftHoldings, getRawBlock, getTransaction, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, transferStx };
385
+ export { getAccountHistory, getAccountInfo, getBalance, getBlock, getContractAbi, getContractSource, getMempoolStats, getNftHoldings, getRawBlock, getTransaction, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, sponsorTransaction, transferStx };
360
386
 
361
- //# debugId=6BA11CC77A75CCA264756E2164756E21
362
- //# sourceMappingURL=stacks-r1m1r72q.js.map
387
+ //# debugId=49BE090154B6DAE264756E2164756E21
388
+ //# sourceMappingURL=stacks-bw8qvqd1.js.map
@@ -0,0 +1,27 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/actions/public/getAccountHistory.ts", "../src/actions/public/getAccountInfo.ts", "../src/actions/public/getBalance.ts", "../src/actions/public/getBlock.ts", "../src/actions/public/getContractAbi.ts", "../src/actions/public/getContractSource.ts", "../src/actions/public/getMempoolStats.ts", "../src/actions/public/getNftHoldings.ts", "../src/actions/public/getRawBlock.ts", "../src/actions/public/getTransaction.ts", "../src/errors/simulation.ts", "../src/actions/public/simulateCall.ts", "../src/actions/public/simulateTransaction.ts", "../src/actions/wallet/deployContract.ts", "../src/actions/wallet/signMessage.ts", "../src/actions/wallet/signTransaction.ts", "../src/actions/wallet/sponsorTransaction.ts", "../src/actions/wallet/transferStx.ts"],
4
+ "sourcesContent": [
5
+ "import type { Client } from \"../../clients/types.ts\";\n\nexport type GetAccountHistoryParams = {\n\taddress: string;\n\t/** Capped at 50. Default 20. */\n\tlimit?: number;\n};\n\nexport type AccountHistoryResponse = {\n\tresults: unknown[];\n\ttotal: number;\n};\n\n/** Paginated transaction history for a principal (Hiro extended API). */\nexport async function getAccountHistory(\n\tclient: Client,\n\tparams: GetAccountHistoryParams,\n): Promise<AccountHistoryResponse> {\n\tconst limit = Math.min(params.limit ?? 20, 50);\n\treturn client.request(\n\t\t`/extended/v2/addresses/${params.address}/transactions?limit=${limit}`,\n\t\t{ method: \"GET\" },\n\t);\n}\n",
6
+ "import type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.ts\";\n\nexport type GetAccountInfoParams = {\n\taddress: string;\n};\n\nexport type AccountInfo = {\n\tbalance: bigint;\n\tnonce: bigint;\n\tbalanceProof: string;\n\tnonceProof: string;\n};\n\nexport async function getAccountInfo(\n\tclient: Client,\n\tparams: GetAccountInfoParams,\n): Promise<AccountInfo> {\n\tconst data = await client.request(`/v2/accounts/${params.address}?proof=1`, {\n\t\tmethod: \"GET\",\n\t});\n\tconst balance = (data as { balance?: unknown })?.balance;\n\tconst nonce = (data as { nonce?: unknown })?.nonce;\n\tif (\n\t\t(typeof balance !== \"string\" && typeof balance !== \"number\") ||\n\t\t(typeof nonce !== \"string\" && typeof nonce !== \"number\")\n\t) {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getAccountInfo: /v2/accounts/${params.address} response is missing \"balance\" or \"nonce\"`,\n\t\t);\n\t}\n\treturn {\n\t\tbalance: BigInt(balance),\n\t\tnonce: BigInt(nonce),\n\t\tbalanceProof: data.balance_proof ?? \"\",\n\t\tnonceProof: data.nonce_proof ?? \"\",\n\t};\n}\n",
7
+ "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(`/v2/accounts/${params.address}`, {\n\t\tmethod: \"GET\",\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",
8
+ "import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBlockParams = {\n\theight?: number;\n\thash?: string;\n};\n\nexport async function getBlock(\n\tclient: Client,\n\tparams?: GetBlockParams,\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n): Promise<any> {\n\tif (params?.hash) {\n\t\treturn client.request(`/extended/v2/blocks/${params.hash}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\tif (params?.height !== undefined) {\n\t\treturn client.request(`/extended/v2/blocks/${params.height}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\t// Latest block\n\treturn client.request(\"/extended/v2/blocks?limit=1\", { method: \"GET\" });\n}\n",
9
+ "import type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetContractAbiParams = {\n\tcontract: string; // \"address.name\"\n};\n\nexport async function getContractAbi(\n\tclient: Client,\n\tparams: GetContractAbiParams,\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n): Promise<any> {\n\tconst [address, name] = parseContractId(params.contract);\n\treturn client.request(`/v2/contracts/interface/${address}/${name}`, {\n\t\tmethod: \"GET\",\n\t});\n}\n",
10
+ "import type { Client } from \"../../clients/types.ts\";\nimport { HttpRequestError } from \"../../errors/http.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetContractSourceParams = {\n\tcontract: string; // \"address.name\"\n};\n\nexport type ContractSourceResponse = {\n\tsource: string;\n\tpublish_height: number;\n\tmarf_proof?: string;\n};\n\n/**\n * Fetch a deployed contract's Clarity source. Node-RPC only (`/v2/contracts/source`)\n * — not available through Hiro's extended API or a tenant proxy, so `client`\n * must be configured against a direct node transport. Returns `null` when the\n * node has no source for the contract.\n */\nexport async function getContractSource(\n\tclient: Client,\n\tparams: GetContractSourceParams,\n): Promise<ContractSourceResponse | null> {\n\tconst [address, name] = parseContractId(params.contract);\n\ttry {\n\t\tconst data = (await client.request(\n\t\t\t`/v2/contracts/source/${address}/${name}`,\n\t\t\t{ method: \"GET\" },\n\t\t)) as Partial<ContractSourceResponse> | undefined;\n\t\treturn data?.source ? (data as ContractSourceResponse) : null;\n\t} catch (error) {\n\t\tif (error instanceof HttpRequestError && error.status === 404) return null;\n\t\tthrow error;\n\t}\n}\n",
11
+ "import type { Client } from \"../../clients/types.ts\";\n\n/**\n * Current mempool statistics: pending count, fee distribution, age buckets\n * (Hiro extended API).\n */\nexport async function getMempoolStats(\n\tclient: Client,\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n): Promise<any> {\n\treturn client.request(\"/extended/v1/tx/mempool/stats\", { method: \"GET\" });\n}\n",
12
+ "import type { Client } from \"../../clients/types.ts\";\n\nexport type GetNftHoldingsParams = {\n\taddress: string;\n\t/** Capped at 50. Default 20. */\n\tlimit?: number;\n};\n\nexport type NftHoldingsResponse = {\n\tresults: unknown[];\n\ttotal: number;\n};\n\n/** NFT holdings for a principal across all collections (Hiro extended API). */\nexport async function getNftHoldings(\n\tclient: Client,\n\tparams: GetNftHoldingsParams,\n): Promise<NftHoldingsResponse> {\n\tconst limit = Math.min(params.limit ?? 20, 50);\n\treturn client.request(\n\t\t`/extended/v1/tokens/nft/holdings?principal=${encodeURIComponent(params.address)}&limit=${limit}`,\n\t\t{ method: \"GET\" },\n\t);\n}\n",
13
+ "import type { Client } from \"../../clients/types.ts\";\nimport { HttpRequestError } from \"../../errors/http.ts\";\n\nexport type GetRawBlockParams = {\n\theight: number;\n};\n\n/**\n * Raw node RPC block shape (`/v2/blocks/{height}`) — distinct from\n * {@link getBlock}'s Hiro extended-API shape. Carries consensus/identity\n * fields (`index_block_hash`, `miner_txid`, ...) that the indexed API doesn't\n * expose, for trust-minimized use cases (e.g. block-header proofs) that can't\n * rely on a third-party indexer.\n */\nexport type RawBlockResponse = {\n\thash: string;\n\theight: number;\n\tparent_block_hash: string;\n\tburn_block_height: number;\n\tburn_block_hash: string;\n\tburn_block_time: number;\n\tindex_block_hash: string;\n\tparent_index_block_hash: string;\n\tminer_txid: string;\n\ttxs: string[];\n};\n\n/**\n * Fetch a block by height directly from a stacks-node (not Hiro's extended\n * API — see {@link getBlock} for that). Returns `null` when the node has no\n * block at that height.\n */\nexport async function getRawBlock(\n\tclient: Client,\n\tparams: GetRawBlockParams,\n): Promise<RawBlockResponse | null> {\n\ttry {\n\t\tconst data = (await client.request(`/v2/blocks/${params.height}`, {\n\t\t\tmethod: \"GET\",\n\t\t})) as Partial<RawBlockResponse> | undefined;\n\t\treturn data?.hash ? (data as RawBlockResponse) : null;\n\t} catch (error) {\n\t\tif (error instanceof HttpRequestError && error.status === 404) return null;\n\t\tthrow error;\n\t}\n}\n",
14
+ "import type { Client } from \"../../clients/types.ts\";\nimport {\n\ttype TransactionReceipt,\n\ttype TransactionStatusSource,\n\textendedApiSource,\n} from \"./txSources.ts\";\n\nexport type GetTransactionParams = {\n\ttxid: string;\n\t/** Where to read status from. Defaults to {@link extendedApiSource}. */\n\tsource?: TransactionStatusSource;\n};\n\n/**\n * Fetch a transaction's receipt (status, block info, decoded result).\n * Returns `null` when the source has no record of the transaction.\n */\nexport async function getTransaction(\n\tclient: Client,\n\tparams: GetTransactionParams,\n): Promise<TransactionReceipt | null> {\n\tconst source = params.source ?? extendedApiSource();\n\tconst { receipt } = await source.get({ client, txid: params.txid });\n\treturn receipt;\n}\n",
15
+ "import { BaseError } from \"./base.ts\";\n\nexport class SimulationError extends BaseError {\n\toverride name = \"SimulationError\";\n\twritesDetected: boolean;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { writesDetected: boolean; details?: string },\n\t) {\n\t\tsuper(message, { details: options.details });\n\t\tthis.writesDetected = options.writesDetected;\n\t}\n}\n",
16
+ "import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { SimulationError } from \"../../errors/simulation.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type SimulateCallParams = {\n\tcontract: string;\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateCallSuccess = { success: true; result: ClarityValue };\nexport type SimulateCallFailure = { success: false; error: SimulationError };\nexport type SimulateCallResult = SimulateCallSuccess | SimulateCallFailure;\n\nexport async function simulateCall(\n\tclient: Client,\n\tparams: SimulateCallParams,\n): Promise<SimulateCallResult> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst sender = params.sender ?? address;\n\n\tconst serializedArgs = (params.args ?? []).map((arg) =>\n\t\twith0x(bytesToHex(serializeCVBytes(arg))),\n\t);\n\n\tlet path = `/v2/contracts/call-read/${address}/${name}/${params.functionName}`;\n\tif (params.tip) {\n\t\tpath += `?tip=${params.tip}`;\n\t}\n\n\tconst data = await client.request(path, {\n\t\tmethod: \"POST\",\n\t\tbody: {\n\t\t\tsender,\n\t\t\targuments: serializedArgs,\n\t\t},\n\t});\n\n\tif (data.okay) {\n\t\treturn { success: true, result: deserializeCVBytes(data.result) };\n\t}\n\n\tconst cause: string = data.cause ?? \"Simulation failed\";\n\tconst writesDetected =\n\t\tcause.includes(\"NotReadOnly\") || cause.includes(\"CostBalanceExceeded\");\n\n\treturn {\n\t\tsuccess: false,\n\t\terror: new SimulationError(\n\t\t\twritesDetected\n\t\t\t\t? \"Function mutates state and cannot be simulated\"\n\t\t\t\t: \"Simulation failed\",\n\t\t\t{ writesDetected, details: cause },\n\t\t),\n\t};\n}\n",
17
+ "import type { Client } from \"../../clients/types.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { AddressHashMode, PayloadType } from \"../../transactions/types.ts\";\nimport { c32address } from \"../../utils/address.ts\";\nimport { type FeeEstimation, estimateFee } from \"./estimateFee.ts\";\nimport { type SimulateCallResult, simulateCall } from \"./simulateCall.ts\";\n\nexport type SimulateTransactionParams = {\n\ttransaction: StacksTransaction;\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateContractCallResult = {\n\ttype: \"contract-call\";\n\texecution: SimulateCallResult;\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransferResult = {\n\ttype: \"token-transfer\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateDeployResult = {\n\ttype: \"contract-deploy\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransactionResult =\n\t| SimulateContractCallResult\n\t| SimulateTransferResult\n\t| SimulateDeployResult;\n\nfunction isMultiSig(hashMode: number): boolean {\n\treturn (\n\t\thashMode === AddressHashMode.P2SH ||\n\t\thashMode === AddressHashMode.P2WSH ||\n\t\thashMode === AddressHashMode.P2SH_NonSequential ||\n\t\thashMode === AddressHashMode.P2WSH_P2SH_NonSequential\n\t);\n}\n\nfunction extractSender(tx: StacksTransaction, client: Client): string {\n\tconst { hashMode, signer } = tx.auth.spendingCondition;\n\tconst chain = client.chain;\n\tconst version = isMultiSig(hashMode)\n\t\t? (chain?.addressVersion.multiSig ?? 20)\n\t\t: (chain?.addressVersion.singleSig ?? 22);\n\treturn c32address(version, signer);\n}\n\nexport async function simulateTransaction(\n\tclient: Client,\n\tparams: SimulateTransactionParams,\n): Promise<SimulateTransactionResult> {\n\tconst { transaction, tip } = params;\n\tconst { payload } = transaction;\n\n\tif (payload.payloadType === PayloadType.ContractCall) {\n\t\tconst sender = params.sender ?? extractSender(transaction, client);\n\t\tconst contract = `${payload.contractAddress}.${payload.contractName}`;\n\n\t\tconst [execution, fees] = await Promise.all([\n\t\t\tsimulateCall(client, {\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: payload.functionName,\n\t\t\t\targs: payload.functionArgs,\n\t\t\t\tsender,\n\t\t\t\ttip,\n\t\t\t}),\n\t\t\testimateFee(client, { transaction }),\n\t\t]);\n\n\t\treturn { type: \"contract-call\", execution, fees };\n\t}\n\n\tconst fees = await estimateFee(client, { transaction });\n\n\tif (\n\t\tpayload.payloadType === PayloadType.SmartContract ||\n\t\tpayload.payloadType === PayloadType.VersionedSmartContract\n\t) {\n\t\treturn { type: \"contract-deploy\", fees };\n\t}\n\n\treturn { type: \"token-transfer\", fees };\n}\n",
18
+ "import type { Client } from \"../../clients/types.ts\";\nimport type {\n\tPostConditionInput,\n\tPostConditionMode,\n} from \"../../postconditions/types.ts\";\nimport { buildContractDeploy } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { ClarityVersion } from \"../../transactions/types.ts\";\nimport { isClarityName } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type DeployContractParams = {\n\tcontractName: string;\n\tcodeBody: string;\n\tclarityVersion?: ClarityVersion;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: PostConditionMode;\n\tpostConditions?: PostConditionInput[];\n};\n\n/** Build, sign, and broadcast a contract deploy */\nexport async function deployContract(\n\tclient: Client,\n\tparams: DeployContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\tif (!isClarityName(params.contractName))\n\t\tthrow new Error(`Invalid contract name: ${params.contractName}`);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_deployContract\", {\n\t\t\tcontractName: params.contractName,\n\t\t\tcodeBody: params.codeBody,\n\t\t\tclarityVersion: params.clarityVersion,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractDeploy({\n\t\tcontractName: params.contractName,\n\t\tcodeBody: params.codeBody,\n\t\tclarityVersion: params.clarityVersion,\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n",
19
+ "import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport { structuredDataHash } from \"../../clarity/structuredData.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { Cl } from \"../../clarity/values.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { bytesToHex } from \"../../utils/encoding.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignMessageParams = {\n\tmessage: string | ClarityValue;\n\tdomain?: {\n\t\tname: string;\n\t\tversion: string;\n\t\tchainId: number;\n\t};\n};\n\n/** Sign a message. With `domain`, hashes per SIP-018; without, hashes the serialized CV. */\nexport async function signMessage(\n\tclient: Client,\n\tparams: SignMessageParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst method = params.domain\n\t\t\t? \"stx_signStructuredMessage\"\n\t\t\t: \"stx_signMessage\";\n\t\tconst result = await account.provider.request(method, {\n\t\t\tmessage: params.message,\n\t\t\tdomain: params.domain,\n\t\t});\n\t\treturn result.signature;\n\t}\n\n\tconst cv =\n\t\ttypeof params.message === \"string\"\n\t\t\t? Cl.stringAscii(params.message)\n\t\t\t: params.message;\n\n\tconst hash = params.domain\n\t\t? structuredDataHash({\n\t\t\t\tmessage: cv,\n\t\t\t\tdomain: Cl.tuple({\n\t\t\t\t\tname: Cl.stringAscii(params.domain.name),\n\t\t\t\t\tversion: Cl.stringAscii(params.domain.version),\n\t\t\t\t\t\"chain-id\": Cl.uint(params.domain.chainId),\n\t\t\t\t}),\n\t\t\t})\n\t\t: sha256(serializeCVBytes(cv));\n\n\tconst sigBytes = await account.sign(hash);\n\treturn bytesToHex(sigBytes);\n}\n",
20
+ "import type { Client } from \"../../clients/types.ts\";\nimport { signMultiSigWithAccount } from \"../../transactions/multisig.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { deserializeTransaction } from \"../../transactions/wire/deserialize.ts\";\nimport { serializeTransactionHex } from \"../../transactions/wire/serialize.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignTransactionParams = {\n\ttransaction: StacksTransaction;\n\t/** Public keys for multi-sig signing (auto-detected from _multisig metadata if omitted) */\n\tsigners?: string[];\n};\n\n/** Sign a transaction using the client's account */\nexport async function signTransactionAction(\n\tclient: Client,\n\tparams: SignTransactionParams,\n): Promise<StacksTransaction> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: send hex to wallet, get signed hex back\n\tif (isProviderAccount(account)) {\n\t\tconst hex = serializeTransactionHex(params.transaction);\n\t\tconst result = await account.provider.request(\"stx_signTransaction\", {\n\t\t\ttransaction: hex,\n\t\t});\n\t\treturn deserializeTransaction(result.transaction, {\n\t\t\t_multisig: params.transaction._multisig,\n\t\t});\n\t}\n\n\t// Multi-sig: auto-detect from fields or _multisig metadata\n\tconst condition = params.transaction.auth.spendingCondition;\n\tif (\"fields\" in condition) {\n\t\tconst publicKeys =\n\t\t\tparams.signers ?? params.transaction._multisig?.publicKeys;\n\t\tif (!publicKeys)\n\t\t\tthrow new Error(\"Multi-sig signing requires signers (publicKeys)\");\n\t\treturn signMultiSigWithAccount(params.transaction, account, publicKeys);\n\t}\n\n\t// Local/Custom: sign with account\n\treturn signTransactionWithAccount(params.transaction, account);\n}\n",
21
+ "import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n",
22
+ "import type { Client } from \"../../clients/types.ts\";\nimport type {\n\tPostConditionInput,\n\tPostConditionMode,\n} from \"../../postconditions/types.ts\";\nimport { buildTokenTransfer } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type TransferStxParams = {\n\tto: string;\n\tamount: IntegerType;\n\tmemo?: string;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: PostConditionMode;\n\tpostConditions?: PostConditionInput[];\n};\n\n/** Build, sign, and broadcast an STX transfer */\nexport async function transferStx(\n\tclient: Client,\n\tparams: TransferStxParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\tif (!validateStacksAddress(params.to))\n\t\tthrow new Error(`Invalid recipient address: ${params.to}`);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_transferStx\", {\n\t\t\trecipient: params.to,\n\t\t\tamount: String(params.amount),\n\t\t\tmemo: params.memo,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildTokenTransfer({\n\t\trecipient: params.to,\n\t\tamount: params.amount,\n\t\tmemo: params.memo,\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
23
+ ],
24
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,eAAsB,iBAAiB,CACtC,QACA,QACkC;AAAA,EAClC,MAAM,QAAQ,KAAK,IAAI,OAAO,SAAS,IAAI,EAAE;AAAA,EAC7C,OAAO,OAAO,QACb,0BAA0B,OAAO,8BAA8B,SAC/D,EAAE,QAAQ,MAAM,CACjB;AAAA;;;ACRD,eAAsB,cAAc,CACnC,QACA,QACuB;AAAA,EACvB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,mBAAmB;AAAA,IAC3E,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,MAAM,UAAW,MAAgC;AAAA,EACjD,MAAM,QAAS,MAA8B;AAAA,EAC7C,IACE,OAAO,YAAY,YAAY,OAAO,YAAY,YAClD,OAAO,UAAU,YAAY,OAAO,UAAU,UAC9C;AAAA,IACD,MAAM,IAAI,uBACT,gCAAgC,OAAO,kDACxC;AAAA,EACD;AAAA,EACA,OAAO;AAAA,IACN,SAAS,OAAO,OAAO;AAAA,IACvB,OAAO,OAAO,KAAK;AAAA,IACnB,cAAc,KAAK,iBAAiB;AAAA,IACpC,YAAY,KAAK,eAAe;AAAA,EACjC;AAAA;;;AC7BD,eAAsB,UAAU,CAC/B,QACA,QACkB;AAAA,EAClB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,WAAW;AAAA,IACnE,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,MAAM,UAAW,MAAgC;AAAA,EACjD,IAAI,OAAO,YAAY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,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
25
+ "debugId": "49BE090154B6DAE264756E2164756E21",
26
+ "names": []
27
+ }
@@ -0,0 +1,38 @@
1
+ // src/clarity/structuredData.ts
2
+ var import_sha2 = require("@noble/hashes/sha2.js");
3
+ var SIP018_PREFIX = new Uint8Array([
4
+ 83,
5
+ 73,
6
+ 80,
7
+ 48,
8
+ 49,
9
+ 56
10
+ ]);
11
+ function hashStructuredData(structuredData) {
12
+ return import_sha2.sha256(serializeCVBytes(structuredData));
13
+ }
14
+ function isDomain(value) {
15
+ if (value.type !== "tuple")
16
+ return false;
17
+ const { name, version, "chain-id": chainId } = value.value;
18
+ return name?.type === "ascii" && version?.type === "ascii" && chainId?.type === "uint";
19
+ }
20
+ function encodeStructuredData(opts) {
21
+ if (!isDomain(opts.domain)) {
22
+ throw new Error("domain must be a tuple { name: ascii, version: ascii, chain-id: uint }");
23
+ }
24
+ return concatBytes(SIP018_PREFIX, hashStructuredData(opts.domain), hashStructuredData(opts.message));
25
+ }
26
+ function structuredDataHash(opts) {
27
+ return import_sha2.sha256(encodeStructuredData(opts));
28
+ }
29
+ async function signStructuredData(account, opts) {
30
+ const vrs = await account.sign(structuredDataHash(opts));
31
+ if (vrs.length !== 65) {
32
+ throw new Error(`Expected 65-byte recoverable signature, got ${vrs.length}`);
33
+ }
34
+ return bytesToHex(concatBytes(vrs.slice(1), vrs.slice(0, 1)));
35
+ }
36
+
37
+ //# debugId=85A2539C2F081F0364756E2164756E21
38
+ //# sourceMappingURL=stacks-enpj9krt.cjs.map