@secondlayer/stacks 2.10.0 → 2.12.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 (118) hide show
  1. package/README.md +24 -0
  2. package/dist/shared/{stacks-4t2vmp4y.js → stacks-01pbr7gf.js} +17 -16
  3. package/dist/shared/stacks-01pbr7gf.js.map +11 -0
  4. package/dist/shared/{stacks-wyxj879g.cjs → stacks-18jv9aen.js} +83 -4
  5. package/dist/shared/stacks-18jv9aen.js.map +13 -0
  6. package/dist/shared/{stacks-0zysn74p.js → stacks-2mm20wqf.js} +3 -3
  7. package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
  8. package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
  9. package/dist/shared/{stacks-2dhf79w5.js → stacks-59xy6t1p.js} +33 -31
  10. package/dist/shared/{stacks-2dhf79w5.js.map → stacks-59xy6t1p.js.map} +6 -6
  11. package/dist/shared/{stacks-99ghanwx.js → stacks-6n2m9hyk.js} +56 -6
  12. package/dist/shared/stacks-6n2m9hyk.js.map +10 -0
  13. package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
  14. package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
  15. package/dist/shared/stacks-azp00pve.js +70 -0
  16. package/dist/shared/stacks-azp00pve.js.map +11 -0
  17. package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
  18. package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
  19. package/dist/shared/stacks-esn3wcw5.cjs +416 -0
  20. package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
  21. package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
  22. package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
  23. package/dist/shared/{stacks-e60vrr34.js → stacks-g11v9a35.js} +4 -4
  24. package/dist/shared/{stacks-0ek3cyt8.js → stacks-g67f4w1d.js} +7 -14
  25. package/dist/shared/stacks-g67f4w1d.js.map +10 -0
  26. package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
  27. package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
  28. package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
  29. package/dist/shared/stacks-kjg7fw4y.js +434 -0
  30. package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
  31. package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
  32. package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
  33. package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
  34. package/dist/shared/{stacks-xw0j252s.cjs → stacks-shn9zw99.cjs} +43 -3
  35. package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
  36. package/dist/shared/{stacks-vf0ekgwb.js → stacks-ssndnbbd.js} +8 -10
  37. package/dist/shared/{stacks-vf0ekgwb.js.map → stacks-ssndnbbd.js.map} +2 -2
  38. package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
  39. package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
  40. package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
  41. package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
  42. package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
  43. package/dist/src/accounts/index.js +3 -5
  44. package/dist/src/accounts/index.js.map +2 -2
  45. package/dist/src/actions/index.cjs +8 -1
  46. package/dist/src/actions/index.cjs.map +1 -1
  47. package/dist/src/actions/index.d.cts +198 -13
  48. package/dist/src/actions/index.d.ts +198 -13
  49. package/dist/src/actions/index.js +29 -17
  50. package/dist/src/actions/index.js.map +1 -1
  51. package/dist/src/bitcoin/index.js +8 -11
  52. package/dist/src/bitcoin/index.js.map +2 -2
  53. package/dist/src/bns/index.js +12 -14
  54. package/dist/src/bns/index.js.map +2 -2
  55. package/dist/src/clarity/index.d.cts +50 -1
  56. package/dist/src/clarity/index.d.ts +50 -1
  57. package/dist/src/clarity/index.js +8 -7
  58. package/dist/src/clarity/index.js.map +1 -1
  59. package/dist/src/index.cjs +10 -1
  60. package/dist/src/index.cjs.map +3 -3
  61. package/dist/src/index.d.cts +167 -9
  62. package/dist/src/index.d.ts +167 -9
  63. package/dist/src/index.js +30 -17
  64. package/dist/src/index.js.map +3 -3
  65. package/dist/src/postconditions/index.js +3 -3
  66. package/dist/src/pox/index.js +11 -13
  67. package/dist/src/pox/index.js.map +2 -2
  68. package/dist/src/sbtc/index.js +10 -12
  69. package/dist/src/sbtc/index.js.map +2 -2
  70. package/dist/src/stackingdao/index.js +11 -13
  71. package/dist/src/stackingdao/index.js.map +2 -2
  72. package/dist/src/tools/index.cjs +348 -63
  73. package/dist/src/tools/index.cjs.map +18 -15
  74. package/dist/src/tools/index.js +348 -63
  75. package/dist/src/tools/index.js.map +18 -15
  76. package/dist/src/transactions/index.js +6 -7
  77. package/dist/src/transactions/index.js.map +1 -1
  78. package/dist/src/utils/index.cjs +2 -1
  79. package/dist/src/utils/index.cjs.map +2 -2
  80. package/dist/src/utils/index.d.cts +5 -1
  81. package/dist/src/utils/index.d.ts +5 -1
  82. package/dist/src/utils/index.js +12 -14
  83. package/dist/src/utils/index.js.map +2 -2
  84. package/dist/src/x402/index.cjs +5 -2
  85. package/dist/src/x402/index.cjs.map +3 -3
  86. package/dist/src/x402/index.d.cts +36 -0
  87. package/dist/src/x402/index.d.ts +36 -0
  88. package/dist/src/x402/index.js +13 -11
  89. package/dist/src/x402/index.js.map +3 -3
  90. package/package.json +1 -1
  91. package/dist/shared/stacks-0ek3cyt8.js.map +0 -10
  92. package/dist/shared/stacks-4t2vmp4y.js.map +0 -11
  93. package/dist/shared/stacks-6xmk24yw.js.map +0 -10
  94. package/dist/shared/stacks-99ghanwx.js.map +0 -10
  95. package/dist/shared/stacks-9g0jhab3.cjs +0 -40
  96. package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
  97. package/dist/shared/stacks-9t68zmpn.js +0 -210
  98. package/dist/shared/stacks-9t68zmpn.js.map +0 -15
  99. package/dist/shared/stacks-fcaefc5b.cjs +0 -16
  100. package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
  101. package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
  102. package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
  103. package/dist/shared/stacks-maamjqma.cjs.map +0 -11
  104. package/dist/shared/stacks-v9jqcpd4.js +0 -18
  105. package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
  106. package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
  107. package/dist/shared/stacks-xmsms921.cjs +0 -196
  108. package/dist/shared/stacks-xmsms921.cjs.map +0 -15
  109. package/dist/shared/stacks-xw0j252s.cjs.map +0 -10
  110. package/dist/shared/stacks-xxn5ma6g.js +0 -22
  111. package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
  112. package/dist/shared/stacks-ya3x01yd.cjs +0 -16
  113. package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
  114. /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
  115. /package/dist/shared/{stacks-e60vrr34.js.map → stacks-g11v9a35.js.map} +0 -0
  116. /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
  117. /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
  118. /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
@@ -1,196 +0,0 @@
1
- // src/actions/public/estimateFee.ts
2
- async function estimateFee(client, params) {
3
- const payloadHex = bytesToHex(serializePayload(params.transaction.payload));
4
- const txHex = bytesToHex(serializeTransaction(params.transaction));
5
- const data = await client.request("/v2/fees/transaction", {
6
- method: "POST",
7
- body: {
8
- estimated_len: Math.ceil(txHex.length / 2),
9
- transaction_payload: `0x${payloadHex}`
10
- }
11
- });
12
- return (data.estimations ?? []).map((e) => ({
13
- feeRate: e.fee_rate,
14
- fee: e.fee
15
- }));
16
- }
17
-
18
- // src/actions/public/getNonce.ts
19
- async function getNonce(client, params) {
20
- const data = await client.request(`/v2/accounts/${params.address}`, {
21
- method: "GET"
22
- });
23
- const nonce = data?.nonce;
24
- if (typeof nonce !== "number" && typeof nonce !== "string") {
25
- throw new Error(`getNonce: unexpected /v2/accounts response for ${params.address} (missing numeric nonce)`);
26
- }
27
- return BigInt(nonce);
28
- }
29
-
30
- // src/errors/transaction.ts
31
- class TransactionError extends BaseError {
32
- name = "TransactionError";
33
- }
34
-
35
- class BroadcastError extends BaseError {
36
- name = "BroadcastError";
37
- txid;
38
- reason;
39
- constructor(message, options) {
40
- super(message, options);
41
- this.txid = options?.txid;
42
- this.reason = options?.reason;
43
- }
44
- }
45
-
46
- class SerializationError extends BaseError {
47
- name = "SerializationError";
48
- }
49
-
50
- class SigningError extends BaseError {
51
- name = "SigningError";
52
- }
53
-
54
- // src/actions/wallet/sendTransaction.ts
55
- async function sendTransaction(client, params) {
56
- const hex = bytesToHex(serializeTransaction(params.transaction));
57
- const body = { tx: hex };
58
- if (params.attachment) {
59
- body.attachment = typeof params.attachment === "string" ? params.attachment : bytesToHex(params.attachment);
60
- }
61
- const data = await client.request("/v2/transactions", {
62
- method: "POST",
63
- body
64
- });
65
- if (data.error) {
66
- throw new BroadcastError(data.reason ?? data.error, {
67
- reason: data.reason
68
- });
69
- }
70
- const txid = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
71
- return { txid };
72
- }
73
-
74
- // src/actions/wallet/nonceManager.ts
75
- function jsonRpcSource() {
76
- return {
77
- get: ({ client, address }) => getNonce(client, { address })
78
- };
79
- }
80
- function memoryStore() {
81
- const next = new Map;
82
- const locks = new Map;
83
- function withLock(key, fn) {
84
- const prev = locks.get(key) ?? Promise.resolve();
85
- const run = prev.then(fn, fn);
86
- locks.set(key, run.catch(() => {}));
87
- return run;
88
- }
89
- return {
90
- reserve(key, getFloor) {
91
- return withLock(key, async () => {
92
- let current = next.get(key);
93
- if (current === undefined)
94
- current = await getFloor();
95
- next.set(key, current + 1n);
96
- return current;
97
- });
98
- },
99
- reset(key) {
100
- next.delete(key);
101
- },
102
- peek(key) {
103
- return next.get(key);
104
- }
105
- };
106
- }
107
- function nonceKey(client, address) {
108
- return `${client.chain?.id ?? "stacks"}:${address}`;
109
- }
110
- function createNonceManager(params = {}) {
111
- const source = params.source ?? jsonRpcSource();
112
- const store = params.store ?? memoryStore();
113
- return {
114
- consume({ client, address }) {
115
- return store.reserve(nonceKey(client, address), () => source.get({ client, address }));
116
- },
117
- reset({ client, address }) {
118
- return store.reset(nonceKey(client, address));
119
- },
120
- async peek({ client, address }) {
121
- return store.peek?.(nonceKey(client, address));
122
- }
123
- };
124
- }
125
- async function resolveNonce(client, address) {
126
- if (client.nonceManager)
127
- return client.nonceManager.consume({ client, address });
128
- return getNonce(client, { address });
129
- }
130
- async function reconcileNonce(manager, params) {
131
- const { client, address, source } = params;
132
- const downward = params.downward ?? true;
133
- const authoritative = await source.get({ client, address });
134
- const tracked = await manager.peek({ client, address });
135
- if (tracked === undefined || authoritative === tracked) {
136
- return { reset: false, authoritative, tracked };
137
- }
138
- if (authoritative < tracked && !downward) {
139
- return { reset: false, authoritative, tracked };
140
- }
141
- await manager.reset({ client, address });
142
- return { reset: true, authoritative, tracked };
143
- }
144
- function startNonceReconciler(manager, params) {
145
- const { client, addresses, source } = params;
146
- const intervalMs = params.intervalMs ?? 60000;
147
- const tick = async () => {
148
- for (const address of addresses) {
149
- try {
150
- const result = await reconcileNonce(manager, {
151
- client,
152
- address,
153
- source,
154
- downward: params.downward
155
- });
156
- params.onReconcile?.(address, result);
157
- } catch (error) {
158
- try {
159
- params.onError?.(address, error);
160
- } catch {}
161
- }
162
- }
163
- };
164
- const timer = setInterval(tick, intervalMs);
165
- timer.unref?.();
166
- return {
167
- stop: () => clearInterval(timer)
168
- };
169
- }
170
- function isNonceConflictError(error) {
171
- if (!(error instanceof BroadcastError))
172
- return false;
173
- const haystack = `${error.reason ?? ""} ${error.message}`.toLowerCase();
174
- return haystack.includes("nonce");
175
- }
176
- async function broadcastWithNonceReset(client, params) {
177
- try {
178
- const result = await sendTransaction(client, {
179
- transaction: params.transaction
180
- });
181
- return result.txid;
182
- } catch (error) {
183
- if (client.nonceManager && isNonceConflictError(error)) {
184
- await client.nonceManager.reset({ client, address: params.address });
185
- }
186
- throw error;
187
- }
188
- }
189
-
190
- // src/actions/wallet/utils.ts
191
- function isProviderAccount(account) {
192
- return account.type === "provider";
193
- }
194
-
195
- //# debugId=8EDE13AECCE4AEBA64756E2164756E21
196
- //# sourceMappingURL=stacks-xmsms921.cjs.map
@@ -1,15 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/actions/public/estimateFee.ts", "../src/actions/public/getNonce.ts", "../src/errors/transaction.ts", "../src/actions/wallet/sendTransaction.ts", "../src/actions/wallet/nonceManager.ts", "../src/actions/wallet/utils.ts"],
4
- "sourcesContent": [
5
- "import type { Client } from \"../../clients/types.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport {\n\tserializePayload,\n\tserializeTransaction,\n} from \"../../transactions/wire/serialize.ts\";\nimport { bytesToHex } from \"../../utils/encoding.ts\";\n\nexport type EstimateFeeParams = {\n\ttransaction: StacksTransaction;\n};\n\nexport type FeeEstimation = {\n\tfeeRate: number;\n\tfee: number;\n};\n\nexport async function estimateFee(\n\tclient: Client,\n\tparams: EstimateFeeParams,\n): Promise<FeeEstimation[]> {\n\tconst payloadHex = bytesToHex(serializePayload(params.transaction.payload));\n\tconst txHex = bytesToHex(serializeTransaction(params.transaction));\n\n\tconst data = await client.request(\"/v2/fees/transaction\", {\n\t\tmethod: \"POST\",\n\t\tbody: {\n\t\t\testimated_len: Math.ceil(txHex.length / 2),\n\t\t\ttransaction_payload: `0x${payloadHex}`,\n\t\t},\n\t});\n\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\treturn (data.estimations ?? []).map((e: any) => ({\n\t\tfeeRate: e.fee_rate,\n\t\tfee: e.fee,\n\t}));\n}\n",
6
- "import type { Client } from \"../../clients/types.ts\";\n\nexport type GetNonceParams = {\n\taddress: string;\n};\n\nexport type GetNonceResult = {\n\tnonce: bigint;\n\tpossibleNextNonce: bigint;\n};\n\nexport async function getNonce(\n\tclient: Client,\n\tparams: GetNonceParams,\n): Promise<bigint> {\n\tconst data = await client.request(`/v2/accounts/${params.address}`, {\n\t\tmethod: \"GET\",\n\t});\n\tconst nonce = (data as { nonce?: unknown })?.nonce;\n\tif (typeof nonce !== \"number\" && typeof nonce !== \"string\") {\n\t\tthrow new Error(\n\t\t\t`getNonce: unexpected /v2/accounts response for ${params.address} (missing numeric nonce)`,\n\t\t);\n\t}\n\treturn BigInt(nonce);\n}\n",
7
- "import { BaseError } from \"./base.ts\";\n\nexport class TransactionError extends BaseError {\n\toverride name = \"TransactionError\";\n}\n\nexport class BroadcastError extends BaseError {\n\toverride name = \"BroadcastError\";\n\ttxid?: string;\n\treason?: string;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions?: { cause?: Error; txid?: string; reason?: string },\n\t) {\n\t\tsuper(message, options);\n\t\tthis.txid = options?.txid;\n\t\tthis.reason = options?.reason;\n\t}\n}\n\nexport class SerializationError extends BaseError {\n\toverride name = \"SerializationError\";\n}\n\nexport class SigningError extends BaseError {\n\toverride name = \"SigningError\";\n}\n",
8
- "import type { Client } from \"../../clients/types.ts\";\nimport { BroadcastError } from \"../../errors/transaction.ts\";\nimport { getTransactionId } from \"../../transactions/signer.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { serializeTransaction } from \"../../transactions/wire/serialize.ts\";\nimport { bytesToHex } from \"../../utils/encoding.ts\";\n\nexport type SendTransactionParams = {\n\ttransaction: StacksTransaction;\n\tattachment?: Uint8Array | string;\n};\n\nexport type SendTransactionResult = {\n\ttxid: string;\n};\n\n/** Broadcast a signed transaction to the network */\nexport async function sendTransaction(\n\tclient: Client,\n\tparams: SendTransactionParams,\n): Promise<SendTransactionResult> {\n\tconst hex = bytesToHex(serializeTransaction(params.transaction));\n\n\tconst body: Record<string, string> = { tx: hex };\n\tif (params.attachment) {\n\t\tbody.attachment =\n\t\t\ttypeof params.attachment === \"string\"\n\t\t\t\t? params.attachment\n\t\t\t\t: bytesToHex(params.attachment);\n\t}\n\n\tconst data = await client.request(\"/v2/transactions\", {\n\t\tmethod: \"POST\",\n\t\tbody,\n\t});\n\n\tif (data.error) {\n\t\tthrow new BroadcastError(data.reason ?? data.error, {\n\t\t\treason: data.reason,\n\t\t});\n\t}\n\n\tconst txid =\n\t\ttypeof data === \"string\"\n\t\t\t? data.replace(/\"/g, \"\")\n\t\t\t: (data.txid ?? getTransactionId(params.transaction));\n\n\treturn { txid };\n}\n",
9
- "import type { Client } from \"../../clients/types.ts\";\nimport { BroadcastError } from \"../../errors/transaction.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { getNonce } from \"../public/getNonce.ts\";\nimport { sendTransaction } from \"./sendTransaction.ts\";\n\n/**\n * Provides the confirmed on-chain nonce floor for an address.\n *\n * The default {@link jsonRpcSource} reads the configured node's `/v2/accounts`\n * endpoint — node-agnostic, no Hiro dependency. Other sources (mempool-aware,\n * first-party Index) can be swapped in without touching the manager.\n */\nexport type NonceManagerSource = {\n\tget(params: { client: Client; address: string }): Promise<bigint>;\n};\n\n/**\n * Holds per-address allocation state and hands out the next nonce.\n *\n * `reserve` MUST be atomic per `key`: two concurrent reservations for the same\n * key must never return the same value. The in-memory {@link memoryStore}\n * serializes with a per-key promise chain; a persisted store (Redis `INCR`,\n * Postgres `SELECT ... FOR UPDATE`) becomes the cross-process lock for the\n * multi-builder / smart-wallet-as-a-service case.\n */\nexport type NonceStore = {\n\t/**\n\t * Reserve the next nonce for `key`. `getFloor` reads the confirmed on-chain\n\t * nonce; it is only invoked when the store has no tracked value (cold start\n\t * or after {@link NonceStore.reset}).\n\t */\n\treserve(key: string, getFloor: () => Promise<bigint>): Promise<bigint>;\n\t/** Forget tracked state for `key` so the next reserve re-syncs from the floor. */\n\treset(key: string): void | Promise<void>;\n\t/**\n\t * Return the next nonce that {@link NonceStore.reserve} would hand out for\n\t * `key` WITHOUT consuming it, or `undefined` if `key` is untracked. Used by\n\t * {@link reconcileNonce} to detect drift. Optional — stores that omit it\n\t * simply opt out of reconciliation.\n\t */\n\tpeek?(key: string): Promise<bigint | undefined> | bigint | undefined;\n};\n\n/** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */\nexport type NonceManager = {\n\tconsume(params: { client: Client; address: string }): Promise<bigint>;\n\treset(params: { client: Client; address: string }): void | Promise<void>;\n\t/** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */\n\tpeek(params: {\n\t\tclient: Client;\n\t\taddress: string;\n\t}): Promise<bigint | undefined>;\n};\n\nexport type CreateNonceManagerParams = {\n\tsource?: NonceManagerSource;\n\tstore?: NonceStore;\n};\n\n/** Confirmed-nonce source backed by the configured node's `/v2/accounts` RPC (no Hiro dependency). */\nexport function jsonRpcSource(): NonceManagerSource {\n\treturn {\n\t\tget: ({ client, address }) => getNonce(client, { address }),\n\t};\n}\n\n/**\n * In-memory, single-process store. Tracks the next nonce per key and serializes\n * concurrent reservations with a per-key promise chain.\n *\n * Correct only within one process — swap in a persisted store for multi-process\n * deployments that share a signing key.\n */\nexport function memoryStore(): NonceStore {\n\tconst next = new Map<string, bigint>();\n\tconst locks = new Map<string, Promise<unknown>>();\n\n\tfunction withLock<T>(key: string, fn: () => Promise<T>): Promise<T> {\n\t\tconst prev = locks.get(key) ?? Promise.resolve();\n\t\t// Chain onto the prior reservation regardless of how it settled, so a\n\t\t// rejected reserve never wedges the key.\n\t\tconst run = prev.then(fn, fn);\n\t\tlocks.set(\n\t\t\tkey,\n\t\t\trun.catch(() => {}),\n\t\t);\n\t\treturn run;\n\t}\n\n\treturn {\n\t\treserve(key, getFloor) {\n\t\t\treturn withLock(key, async () => {\n\t\t\t\tlet current = next.get(key);\n\t\t\t\tif (current === undefined) current = await getFloor();\n\t\t\t\tnext.set(key, current + 1n);\n\t\t\t\treturn current;\n\t\t\t});\n\t\t},\n\t\treset(key) {\n\t\t\tnext.delete(key);\n\t\t},\n\t\tpeek(key) {\n\t\t\treturn next.get(key);\n\t\t},\n\t};\n}\n\nfunction nonceKey(client: Client, address: string): string {\n\treturn `${client.chain?.id ?? \"stacks\"}:${address}`;\n}\n\n/**\n * Create a nonce manager that floors on a confirmed-nonce {@link NonceManagerSource}\n * and increments a {@link NonceStore} on every {@link NonceManager.consume}.\n *\n * Defaults to {@link jsonRpcSource} + {@link memoryStore} — node-agnostic,\n * single-process, zero external dependencies.\n */\nexport function createNonceManager(\n\tparams: CreateNonceManagerParams = {},\n): NonceManager {\n\tconst source = params.source ?? jsonRpcSource();\n\tconst store = params.store ?? memoryStore();\n\n\treturn {\n\t\tconsume({ client, address }) {\n\t\t\treturn store.reserve(nonceKey(client, address), () =>\n\t\t\t\tsource.get({ client, address }),\n\t\t\t);\n\t\t},\n\t\treset({ client, address }) {\n\t\t\treturn store.reset(nonceKey(client, address));\n\t\t},\n\t\tasync peek({ client, address }) {\n\t\t\treturn store.peek?.(nonceKey(client, address));\n\t\t},\n\t};\n}\n\n/** Resolve the next nonce via the client's nonce manager, falling back to a confirmed read. */\nexport async function resolveNonce(\n\tclient: Client,\n\taddress: string,\n): Promise<bigint> {\n\tif (client.nonceManager)\n\t\treturn client.nonceManager.consume({ client, address });\n\treturn getNonce(client, { address });\n}\n\nexport type ReconcileNonceParams = {\n\tclient: Client;\n\taddress: string;\n\t/** Authoritative (ideally mempool-aware) source to reconcile against. */\n\tsource: NonceManagerSource;\n\t/**\n\t * Allow resetting DOWNWARD when the source's next nonce is below what the\n\t * store tracks — i.e. a previously-allocated tx is no longer pending or\n\t * confirmed (dropped/GC'd), so its nonce should be reused. Default `true`.\n\t *\n\t * Downward resets rely on `source` being current: with a go-forward mempool\n\t * source that lags broadcast, run reconciliation on an interval comfortably\n\t * longer than mempool propagation so a still-missing tx is genuinely dropped.\n\t * Set `false` for upward-only reconciliation (always safe).\n\t */\n\tdownward?: boolean;\n};\n\nexport type ReconcileNonceResult = {\n\t/** Whether the manager was reset (drift detected). */\n\treset: boolean;\n\t/** Authoritative next nonce from `source`. */\n\tauthoritative: bigint;\n\t/** Next nonce the store tracked, or `undefined` if untracked. */\n\ttracked: bigint | undefined;\n};\n\n/**\n * Reconcile a tracked nonce against an authoritative source, healing silent\n * drift that produces no broadcast error (a dropped/GC'd mempool tx leaving the\n * counter overshot, or the chain advancing past the local view).\n *\n * When the source's next nonce differs from the tracked value, the manager is\n * {@link NonceManager.reset}; the next `consume` re-seeds from `source`. A no-op\n * if the store is untracked or does not implement `peek`.\n */\nexport async function reconcileNonce(\n\tmanager: NonceManager,\n\tparams: ReconcileNonceParams,\n): Promise<ReconcileNonceResult> {\n\tconst { client, address, source } = params;\n\tconst downward = params.downward ?? true;\n\n\tconst authoritative = await source.get({ client, address });\n\tconst tracked = await manager.peek({ client, address });\n\n\tif (tracked === undefined || authoritative === tracked) {\n\t\treturn { reset: false, authoritative, tracked };\n\t}\n\tif (authoritative < tracked && !downward) {\n\t\treturn { reset: false, authoritative, tracked };\n\t}\n\n\tawait manager.reset({ client, address });\n\treturn { reset: true, authoritative, tracked };\n}\n\nexport type StartNonceReconcilerParams = {\n\tclient: Client;\n\taddresses: string[];\n\tsource: NonceManagerSource;\n\t/** Reconcile interval in ms. Default 60_000. Keep well above mempool propagation. */\n\tintervalMs?: number;\n\tdownward?: boolean;\n\t/** Per-address callback after each reconcile (observability). */\n\tonReconcile?: (address: string, result: ReconcileNonceResult) => void;\n\t/** Per-address error callback; reconciliation continues on the next tick. */\n\tonError?: (address: string, error: unknown) => void;\n};\n\n/**\n * Run {@link reconcileNonce} on a timer for a set of addresses.\n *\n * SINGLE-WRITER: run this in exactly ONE process. With a shared persisted store,\n * a reconciler resetting the counter while other workers allocate is racy — keep\n * reconciliation on one designated process and let the others only allocate.\n *\n * Returns a handle; call `stop()` to clear the timer.\n */\nexport function startNonceReconciler(\n\tmanager: NonceManager,\n\tparams: StartNonceReconcilerParams,\n): { stop: () => void } {\n\tconst { client, addresses, source } = params;\n\tconst intervalMs = params.intervalMs ?? 60_000;\n\n\tconst tick = async () => {\n\t\tfor (const address of addresses) {\n\t\t\ttry {\n\t\t\t\tconst result = await reconcileNonce(manager, {\n\t\t\t\t\tclient,\n\t\t\t\t\taddress,\n\t\t\t\t\tsource,\n\t\t\t\t\tdownward: params.downward,\n\t\t\t\t});\n\t\t\t\tparams.onReconcile?.(address, result);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tparams.onError?.(address, error);\n\t\t\t\t} catch {\n\t\t\t\t\t// A throwing onError callback must not abort the reconcile loop\n\t\t\t\t\t// or surface as an unhandled rejection on the interval timer.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\tconst timer = setInterval(tick, intervalMs);\n\t// Don't keep the event loop alive solely for reconciliation (Node/Bun).\n\t(timer as { unref?: () => void }).unref?.();\n\n\treturn {\n\t\tstop: () => clearInterval(timer),\n\t};\n}\n\n/** True when a broadcast was rejected for a nonce conflict (`ConflictingNonceInMempool`, `BadNonce`). */\nexport function isNonceConflictError(error: unknown): boolean {\n\tif (!(error instanceof BroadcastError)) return false;\n\tconst haystack = `${error.reason ?? \"\"} ${error.message}`.toLowerCase();\n\treturn haystack.includes(\"nonce\");\n}\n\n/**\n * Broadcast a signed transaction; on a nonce-conflict rejection, reset the\n * manager so the next build re-syncs to the confirmed floor.\n */\nexport async function broadcastWithNonceReset(\n\tclient: Client,\n\tparams: { transaction: StacksTransaction; address: string },\n): Promise<string> {\n\ttry {\n\t\tconst result = await sendTransaction(client, {\n\t\t\ttransaction: params.transaction,\n\t\t});\n\t\treturn result.txid;\n\t} catch (error) {\n\t\tif (client.nonceManager && isNonceConflictError(error)) {\n\t\t\tawait client.nonceManager.reset({ client, address: params.address });\n\t\t}\n\t\tthrow error;\n\t}\n}\n",
10
- "import type { ProviderAccount } from \"../../accounts/types.ts\";\nimport type { Account } from \"../../clients/types.ts\";\n\nexport function isProviderAccount(\n\taccount: Account,\n): account is ProviderAccount {\n\treturn account.type === \"provider\";\n}\n"
11
- ],
12
- "mappings": ";AAiBA,eAAsB,WAAW,CAChC,QACA,QAC2B;AAAA,EAC3B,MAAM,aAAa,WAAW,iBAAiB,OAAO,YAAY,OAAO,CAAC;AAAA,EAC1E,MAAM,QAAQ,WAAW,qBAAqB,OAAO,WAAW,CAAC;AAAA,EAEjE,MAAM,OAAO,MAAM,OAAO,QAAQ,wBAAwB;AAAA,IACzD,QAAQ;AAAA,IACR,MAAM;AAAA,MACL,eAAe,KAAK,KAAK,MAAM,SAAS,CAAC;AAAA,MACzC,qBAAqB,KAAK;AAAA,IAC3B;AAAA,EACD,CAAC;AAAA,EAGD,QAAQ,KAAK,eAAe,CAAC,GAAG,IAAI,CAAC,OAAY;AAAA,IAChD,SAAS,EAAE;AAAA,IACX,KAAK,EAAE;AAAA,EACR,EAAE;AAAA;;;ACzBH,eAAsB,QAAQ,CAC7B,QACA,QACkB;AAAA,EAClB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,WAAW;AAAA,IACnE,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,MAAM,QAAS,MAA8B;AAAA,EAC7C,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAU;AAAA,IAC3D,MAAM,IAAI,MACT,kDAAkD,OAAO,iCAC1D;AAAA,EACD;AAAA,EACA,OAAO,OAAO,KAAK;AAAA;;;ACtBb,MAAM,yBAAyB,UAAU;AAAA,EACtC,OAAO;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AM,QAAQ,YAAY,MAAM,UAAU;AAAA,EAEzC,MAAiC,QAAQ;AAAA,EAE1C,OAAO;AAAA,IACN,MAAM,MAAM,cAAc,KAAK;AAAA,EAChC;AAAA;AAIM,SAAS,oBAAoB,CAAC,OAAyB;AAAA,EAC7D,IAAI,EAAE,iBAAiB;AAAA,IAAiB,OAAO;AAAA,EAC/C,MAAM,WAAW,GAAG,MAAM,UAAU,MAAM,MAAM,UAAU,YAAY;AAAA,EACtE,OAAO,SAAS,SAAS,OAAO;AAAA;AAOjC,eAAsB,uBAAuB,CAC5C,QACA,QACkB;AAAA,EAClB,IAAI;AAAA,IACH,MAAM,SAAS,MAAM,gBAAgB,QAAQ;AAAA,MAC5C,aAAa,OAAO;AAAA,IACrB,CAAC;AAAA,IACD,OAAO,OAAO;AAAA,IACb,OAAO,OAAO;AAAA,IACf,IAAI,OAAO,gBAAgB,qBAAqB,KAAK,GAAG;AAAA,MACvD,MAAM,OAAO,aAAa,MAAM,EAAE,QAAQ,SAAS,OAAO,QAAQ,CAAC;AAAA,IACpE;AAAA,IACA,MAAM;AAAA;AAAA;;;AC/RD,SAAS,iBAAiB,CAChC,SAC6B;AAAA,EAC7B,OAAO,QAAQ,SAAS;AAAA;",
13
- "debugId": "8EDE13AECCE4AEBA64756E2164756E21",
14
- "names": []
15
- }
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/actions/getContract.ts"],
4
- "sourcesContent": [
5
- "import type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiMap,\n\tAbiType,\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 type { IntegerType } from \"../utils/encoding.ts\";\nimport { getMapEntry } from \"./public/getMapEntry.ts\";\nimport { readContract } from \"./public/readContract.ts\";\nimport { callContract } from \"./wallet/callContract.ts\";\n\n// --- Type helpers for unwrapping response types ---\n\n/** Unwrap `(response ok err)` → just the `ok` branch type */\n// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\ntype UnwrapResponse<T> = T extends { ok: infer O } | { err: any } ? O : 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\ntype ReadMethods<C extends AbiContract> = {\n\t[N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t) => Promise<ReadMethodReturn<C, N>>;\n};\n\ntype CallMethods<C extends AbiContract> = {\n\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t\toptions?: ContractCallOptions,\n\t) => Promise<string>;\n};\n\ntype MapMethods<C extends AbiContract> = {\n\t[N in ExtractMapNames<C> as ToCamelCase<N>]: (\n\t\tkey: ExtractMapKey<C, N>,\n\t) => Promise<ExtractMapValue<C, N> | null>;\n};\n\nexport type ContractCallOptions = {\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\nexport type ContractInstance<C extends AbiContract> = {\n\tread: ReadMethods<C>;\n\tcall: CallMethods<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 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, 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\nfunction 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\nfunction 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
- ],
7
- "mappings": ";AA8EO,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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AiB,CACzB,IACA,MACiB;AAAA,EACjB,OAAO,GAAG,KAAK,IAAI,CAAC,QAAQ;AAAA,IAC3B,MAAM,WAAW,YAAY,IAAI,IAAI;AAAA,IACrC,MAAM,cAAc,IAAI,QAAQ;AAAA,IAChC,MAAM,WAAW,YAAY;AAAA,IAC7B,MAAM,QAAQ,cACX,KAAK,IAAI,QACT,WACC,KAAK,YACL;AAAA,IACJ,IAAI,UAAU;AAAA,MAAW,MAAM,IAAI,MAAM,qBAAqB,IAAI,MAAM;AAAA,IACxE,OAAO,iBAAiB,IAAI,MAAiB,KAAK;AAAA,GAClD;AAAA;AAGF,SAAS,gBAAgB,CAAC,MAAwB;AAAA,EACjD,OAAO,OAAO,SAAS,YAAY,SAAS,QAAQ,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
- "debugId": "AF3DD8A27468392A64756E2164756E21",
9
- "names": []
10
- }
@@ -1,22 +0,0 @@
1
- import {
2
- bytesToHex
3
- } from "./stacks-2h8d2y27.js";
4
-
5
- // src/utils/hash.ts
6
- import { ripemd160 } from "@noble/hashes/legacy.js";
7
- import { sha256 } from "@noble/hashes/sha2.js";
8
- import { sha512_256 } from "@noble/hashes/sha2.js";
9
- function hash160(input) {
10
- return ripemd160(sha256(input));
11
- }
12
- function txidFromBytes(data) {
13
- return bytesToHex(sha512_256(data));
14
- }
15
- function hashP2PKH(input) {
16
- return bytesToHex(hash160(input));
17
- }
18
-
19
- export { ripemd160, sha256, sha512_256, hash160, txidFromBytes, hashP2PKH };
20
-
21
- //# debugId=E53549EA02A4B7DB64756E2164756E21
22
- //# sourceMappingURL=stacks-xxn5ma6g.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/hash.ts"],
4
- "sourcesContent": [
5
- "import { ripemd160 } from \"@noble/hashes/legacy.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { sha512_256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex } from \"./encoding.ts\";\n\nexport { sha256, sha512_256, ripemd160 };\n\n/** RIPEMD160(SHA256(input)) — standard Bitcoin/Stacks address hash */\nexport function hash160(input: Uint8Array): Uint8Array {\n\treturn ripemd160(sha256(input));\n}\n\n/** Hash used for transaction IDs */\nexport function txidFromBytes(data: Uint8Array): string {\n\treturn bytesToHex(sha512_256(data));\n}\n\n/** hash160 as hex — used for P2PKH address derivation */\nexport function hashP2PKH(input: Uint8Array): string {\n\treturn bytesToHex(hash160(input));\n}\n"
6
- ],
7
- "mappings": ";;;;;AAAA;AACA;AACA;AAMO,SAAS,OAAO,CAAC,OAA+B;AAAA,EACtD,OAAO,UAAU,OAAO,KAAK,CAAC;AAAA;AAIxB,SAAS,aAAa,CAAC,MAA0B;AAAA,EACvD,OAAO,WAAW,WAAW,IAAI,CAAC;AAAA;AAI5B,SAAS,SAAS,CAAC,OAA2B;AAAA,EACpD,OAAO,WAAW,QAAQ,KAAK,CAAC;AAAA;",
8
- "debugId": "E53549EA02A4B7DB64756E2164756E21",
9
- "names": []
10
- }
@@ -1,16 +0,0 @@
1
- // src/utils/constants.ts
2
- var MAX_U128 = (1n << 128n) - 1n;
3
- var MAX_I128 = (1n << 127n) - 1n;
4
- var MIN_I128 = -(1n << 127n);
5
- var AddressVersion = {
6
- MainnetSingleSig: 22,
7
- MainnetMultiSig: 20,
8
- TestnetSingleSig: 26,
9
- TestnetMultiSig: 21
10
- };
11
- var ZERO_ADDRESS = "SP000000000000000000002Q6VF78";
12
- var TESTNET_ZERO_ADDRESS = "ST000000000000000000002AMW42H";
13
- var MICROSTX_PER_STX = 1000000n;
14
-
15
- //# debugId=B42A43BFB28E5FFC64756E2164756E21
16
- //# sourceMappingURL=stacks-ya3x01yd.cjs.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils/constants.ts"],
4
- "sourcesContent": [
5
- "// Clarity integer bounds\nexport const MAX_U128: bigint = (1n << 128n) - 1n;\nexport const MAX_I128: bigint = (1n << 127n) - 1n;\nexport const MIN_I128: bigint = -(1n << 127n);\n\n/** C32-encoded address version bytes for single-sig and multi-sig on each network. */\nexport const AddressVersion = {\n\tMainnetSingleSig: 22,\n\tMainnetMultiSig: 20,\n\tTestnetSingleSig: 26,\n\tTestnetMultiSig: 21,\n} as const;\nexport type AddressVersion =\n\t(typeof AddressVersion)[keyof typeof AddressVersion];\n\n/** Mainnet burn address (all-zero hash160). */\nexport const ZERO_ADDRESS = \"SP000000000000000000002Q6VF78\";\n/** Testnet burn address (all-zero hash160). */\nexport const TESTNET_ZERO_ADDRESS = \"ST000000000000000000002AMW42H\";\n\n/** Number of microSTX per 1 STX (10^6). */\nexport const MICROSTX_PER_STX = 1_000_000n;\n"
6
- ],
7
- "mappings": ";AACO,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,WAAmB,EAAE,MAAM;AAGjC,IAAM,iBAAiB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,iBAAiB;AAClB;AAKO,IAAM,eAAe;AAErB,IAAM,uBAAuB;AAG7B,IAAM,mBAAmB;",
8
- "debugId": "B42A43BFB28E5FFC64756E2164756E21",
9
- "names": []
10
- }