@secondlayer/stacks 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/shared/{stacks-sfpr4b0y.js → stacks-53bjdb6p.js} +2 -2
- package/dist/shared/{stacks-9z833ww5.js → stacks-5nmz5ad9.js} +3 -3
- package/dist/shared/{stacks-9z833ww5.js.map → stacks-5nmz5ad9.js.map} +1 -1
- package/dist/shared/{stacks-s9148m6h.js → stacks-8mj5jw77.js} +6 -4
- package/dist/shared/{stacks-s9148m6h.js.map → stacks-8mj5jw77.js.map} +2 -2
- package/dist/shared/stacks-cdvn8qbh.cjs +20 -0
- package/dist/shared/stacks-cdvn8qbh.cjs.map +10 -0
- package/dist/shared/{stacks-y9txtw3p.cjs → stacks-maamjqma.cjs} +2 -20
- package/dist/shared/{stacks-y9txtw3p.cjs.map → stacks-maamjqma.cjs.map} +3 -4
- package/dist/shared/stacks-q1mjkt15.js +34 -0
- package/dist/shared/stacks-q1mjkt15.js.map +10 -0
- package/dist/shared/{stacks-a63xq06y.js → stacks-z1j5d6fd.js} +3 -21
- package/dist/shared/{stacks-a63xq06y.js.map → stacks-z1j5d6fd.js.map} +3 -4
- package/dist/src/actions/index.js +7 -5
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +679 -0
- package/dist/src/bitcoin/index.cjs.map +19 -0
- package/dist/src/bitcoin/index.d.cts +743 -0
- package/dist/src/bitcoin/index.d.ts +743 -0
- package/dist/src/bitcoin/index.js +704 -0
- package/dist/src/bitcoin/index.js.map +19 -0
- package/dist/src/bns/index.js +4 -3
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/index.js +6 -4
- package/dist/src/index.js.map +2 -2
- package/dist/src/pox/index.js +5 -4
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/sbtc/index.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +4 -3
- package/dist/src/stackingdao/index.js.map +2 -2
- package/package.json +8 -4
- /package/dist/shared/{stacks-sfpr4b0y.js.map → stacks-53bjdb6p.js.map} +0 -0
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ const balance = await client.getBalance({
|
|
|
36
36
|
| `@secondlayer/stacks/transactions` | Build, sign, serialize transactions, multi-sig |
|
|
37
37
|
| `@secondlayer/stacks/postconditions` | `Pc` fluent builder for post-conditions |
|
|
38
38
|
| `@secondlayer/stacks/utils` | Encoding, hashing, addresses, unit formatting |
|
|
39
|
+
| `@secondlayer/stacks/bitcoin` | Trust-minimized Bitcoin SPV — proof construction, Clarity codecs, verifier (SIP-044) |
|
|
39
40
|
|
|
40
41
|
### Frozen modules
|
|
41
42
|
|
|
@@ -122,6 +123,93 @@ const reconciler = startNonceReconciler(nonceManager, {
|
|
|
122
123
|
|
|
123
124
|
Everything here is opt-in. With no `source`/`store`, the manager depends only on your node.
|
|
124
125
|
|
|
126
|
+
## Bitcoin SPV (SIP-044)
|
|
127
|
+
|
|
128
|
+
**Prove a Bitcoin payment happened — inside a Stacks contract, with no oracle.**
|
|
129
|
+
|
|
130
|
+
SIP-044 ("Clarity 6", activating with Stacks Epoch 4.0) lets a contract natively
|
|
131
|
+
verify that a Bitcoin transaction was mined — *SPV* (Simplified Payment
|
|
132
|
+
Verification), the proof technique Bitcoin light clients use. A contract can check
|
|
133
|
+
"BTC tx T paid Z sats to address Y in a confirmed block" without trusting an
|
|
134
|
+
indexer or oracle.
|
|
135
|
+
|
|
136
|
+
The catch: the built-ins (`get-bitcoin-tx-output?`, `verify-merkle-proof`) run
|
|
137
|
+
only *inside* a contract and demand precisely-shaped proof data — the right merkle
|
|
138
|
+
proof, internal byte order, witness stripped. This module does that off-chain prep
|
|
139
|
+
so you never run a node by hand or reverse a hash, and ships a reference contract
|
|
140
|
+
(`spv-adapter`, in `contracts/`) wired to the built-ins.
|
|
141
|
+
|
|
142
|
+
**What it unlocks** (it trust-minimizes *verification*, not *custody*):
|
|
143
|
+
|
|
144
|
+
- **BTC-settled escrow / OTC** — release sBTC, an NFT, or a loan only when a real BTC payment is proven on-chain.
|
|
145
|
+
- **BTC-L1 collateral** — prove a borrower's Bitcoin UTXO exists on L1 instead of trusting a price/existence oracle (Zest / Granite-style lending).
|
|
146
|
+
- **Atomic BTC ↔ sBTC / Runes swaps** — native SPV is uncapped, so multi-output Runes/BTC txs that blew past the old `clarity-bitcoin` limits now verify.
|
|
147
|
+
- **Trust-minimized sBTC** — deposits *proven* on-chain rather than only *asserted* by the signer set (aligns with SIP-028).
|
|
148
|
+
|
|
149
|
+
It's also the Bitcoin half of the [Secondlayer](https://secondlayer.tools) indexer:
|
|
150
|
+
our index already surfaces the `bitcoin_txid` on every sBTC deposit/withdrawal —
|
|
151
|
+
this module turns that correlation into an on-chain-verifiable proof.
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { createPublicClient, http } from "@secondlayer/stacks";
|
|
155
|
+
import { mainnet } from "@secondlayer/stacks/chains";
|
|
156
|
+
import {
|
|
157
|
+
buildTxProof,
|
|
158
|
+
bitcoinRpcSource,
|
|
159
|
+
esploraSource,
|
|
160
|
+
fallbackProofSource,
|
|
161
|
+
verifyBitcoinPayment,
|
|
162
|
+
} from "@secondlayer/stacks/bitcoin";
|
|
163
|
+
|
|
164
|
+
const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
165
|
+
|
|
166
|
+
// Trustless by default: the integrator's own node first, hosted fallback second.
|
|
167
|
+
const source = fallbackProofSource([
|
|
168
|
+
bitcoinRpcSource({ url: "http://127.0.0.1:8332", auth: { username: "u", password: "p" } }),
|
|
169
|
+
esploraSource({ url: "https://blockstream.info/api" }),
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
// "release only when a real BTC payment to <addr> for <amount> is proven on-chain"
|
|
173
|
+
const result = await verifyBitcoinPayment(client, {
|
|
174
|
+
txid: "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16",
|
|
175
|
+
source,
|
|
176
|
+
vout: 0,
|
|
177
|
+
contract: "SP….spv-adapter", // the reference adapter (or your own verifier contract)
|
|
178
|
+
expect: { address: "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", amount: 5_000_000_000n },
|
|
179
|
+
});
|
|
180
|
+
// → { verified, mined, output, proof }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Lower-level pieces are exported too: `parseBitcoinTx` / `buildMerkleProof` /
|
|
184
|
+
`merkleRoot` (proof construction), `encodeMerkleProofArgs` / `decodeTxOutput` /
|
|
185
|
+
`parseOutputScript` (Clarity codecs), and `bitcoinVerifier` / `isClarity6Active`
|
|
186
|
+
(the contract binding + activation gate).
|
|
187
|
+
|
|
188
|
+
The off-chain surface (proof construction, codecs, sources) works today against
|
|
189
|
+
live Bitcoin data. The on-chain verification calls the SIP-044 native built-ins,
|
|
190
|
+
which exist once Clarity 6 / Epoch 4.0 is active.
|
|
191
|
+
|
|
192
|
+
### Run the on-chain side locally — no node
|
|
193
|
+
|
|
194
|
+
Clarinet ≥ 3.21 boots simnet at Epoch 4.0, so the `spv-adapter` reference
|
|
195
|
+
contract (`contracts/spv-adapter.clar`) both type-checks and *executes* the
|
|
196
|
+
built-ins today:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
cd contracts && clarinet console # in-memory simnet @ Epoch 4.0
|
|
200
|
+
# then: (contract-call? .spv-adapter get-tx-output 0x<rawtx> u0)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
The SDK↔contract round-trip is covered in CI — it asserts the bytes this module
|
|
204
|
+
encodes are exactly what the built-ins accept:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
bun test packages/stacks/src/bitcoin/__tests__/onchain.simnet.test.ts # 7 pass
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
See `contracts/README.md` for the full local recipe.
|
|
211
|
+
**SPV trust-minimizes *verification*, not *custody*.**
|
|
212
|
+
|
|
125
213
|
## WalletConnect v2
|
|
126
214
|
|
|
127
215
|
Native WC v2 implementation — X25519 ECDH, AES-256-GCM envelope encryption, Ed25519 JWT relay auth. Zero cost if you don't import it, tree-shakes completely.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readContract
|
|
3
|
-
} from "./stacks-
|
|
3
|
+
} from "./stacks-q1mjkt15.js";
|
|
4
4
|
import {
|
|
5
5
|
broadcastWithNonceReset,
|
|
6
6
|
estimateFee,
|
|
@@ -315,4 +315,4 @@ async function transferStx(client, params) {
|
|
|
315
315
|
export { getAccountInfo, getBalance, getBlock, getBlockHeight, getContractAbi, multicall, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, transferStx };
|
|
316
316
|
|
|
317
317
|
//# debugId=315A19FD4484DD8064756E2164756E21
|
|
318
|
-
//# sourceMappingURL=stacks-
|
|
318
|
+
//# sourceMappingURL=stacks-53bjdb6p.js.map
|
|
@@ -403,7 +403,7 @@ var hex = hasHexBuiltin ? hexBuiltin : chain(radix2(4), alphabet("0123456789abcd
|
|
|
403
403
|
return s.toLowerCase();
|
|
404
404
|
}));
|
|
405
405
|
|
|
406
|
-
export { bech32, bech32m };
|
|
406
|
+
export { base58, bech32, bech32m };
|
|
407
407
|
|
|
408
|
-
//# debugId=
|
|
409
|
-
//# sourceMappingURL=stacks-
|
|
408
|
+
//# debugId=CBC131E37BFBAEEF64756E2164756E21
|
|
409
|
+
//# sourceMappingURL=stacks-5nmz5ad9.js.map
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */\nfunction isBytes(a) {\n return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');\n}\n/** Asserts something is Uint8Array. */\nfunction abytes(b) {\n if (!isBytes(b))\n throw new Error('Uint8Array expected');\n}\nfunction isArrayOf(isString, arr) {\n if (!Array.isArray(arr))\n return false;\n if (arr.length === 0)\n return true;\n if (isString) {\n return arr.every((item) => typeof item === 'string');\n }\n else {\n return arr.every((item) => Number.isSafeInteger(item));\n }\n}\nfunction afn(input) {\n if (typeof input !== 'function')\n throw new Error('function expected');\n return true;\n}\nfunction astr(label, input) {\n if (typeof input !== 'string')\n throw new Error(`${label}: string expected`);\n return true;\n}\nfunction anumber(n) {\n if (!Number.isSafeInteger(n))\n throw new Error(`invalid integer: ${n}`);\n}\nfunction aArr(input) {\n if (!Array.isArray(input))\n throw new Error('array expected');\n}\nfunction astrArr(label, input) {\n if (!isArrayOf(true, input))\n throw new Error(`${label}: array of strings expected`);\n}\nfunction anumArr(label, input) {\n if (!isArrayOf(false, input))\n throw new Error(`${label}: array of numbers expected`);\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction chain(...args) {\n const id = (a) => a;\n // Wrap call in closure so JIT can inline calls\n const wrap = (a, b) => (c) => a(b(c));\n // Construct chain of args[-1].encode(args[-2].encode([...]))\n const encode = args.map((x) => x.encode).reduceRight(wrap, id);\n // Construct chain of args[0].decode(args[1].decode(...))\n const decode = args.map((x) => x.decode).reduce(wrap, id);\n return { encode, decode };\n}\n/**\n * Encodes integer radix representation to array of strings using alphabet and back.\n * Could also be array of strings.\n * @__NO_SIDE_EFFECTS__\n */\nfunction alphabet(letters) {\n // mapping 1 to \"b\"\n const lettersA = typeof letters === 'string' ? letters.split('') : letters;\n const len = lettersA.length;\n astrArr('alphabet', lettersA);\n // mapping \"b\" to 1\n const indexes = new Map(lettersA.map((l, i) => [l, i]));\n return {\n encode: (digits) => {\n aArr(digits);\n return digits.map((i) => {\n if (!Number.isSafeInteger(i) || i < 0 || i >= len)\n throw new Error(`alphabet.encode: digit index outside alphabet \"${i}\". Allowed: ${letters}`);\n return lettersA[i];\n });\n },\n decode: (input) => {\n aArr(input);\n return input.map((letter) => {\n astr('alphabet.decode', letter);\n const i = indexes.get(letter);\n if (i === undefined)\n throw new Error(`Unknown letter: \"${letter}\". Allowed: ${letters}`);\n return i;\n });\n },\n };\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction join(separator = '') {\n astr('join', separator);\n return {\n encode: (from) => {\n astrArr('join.decode', from);\n return from.join(separator);\n },\n decode: (to) => {\n astr('join.decode', to);\n return to.split(separator);\n },\n };\n}\n/**\n * Pad strings array so it has integer number of bits\n * @__NO_SIDE_EFFECTS__\n */\nfunction padding(bits, chr = '=') {\n anumber(bits);\n astr('padding', chr);\n return {\n encode(data) {\n astrArr('padding.encode', data);\n while ((data.length * bits) % 8)\n data.push(chr);\n return data;\n },\n decode(input) {\n astrArr('padding.decode', input);\n let end = input.length;\n if ((end * bits) % 8)\n throw new Error('padding: invalid, string should have whole number of bytes');\n for (; end > 0 && input[end - 1] === chr; end--) {\n const last = end - 1;\n const byte = last * bits;\n if (byte % 8 === 0)\n throw new Error('padding: invalid, string has too much padding');\n }\n return input.slice(0, end);\n },\n };\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction normalize(fn) {\n afn(fn);\n return { encode: (from) => from, decode: (to) => fn(to) };\n}\n/**\n * Slow: O(n^2) time complexity\n */\nfunction convertRadix(data, from, to) {\n // base 1 is impossible\n if (from < 2)\n throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);\n if (to < 2)\n throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);\n aArr(data);\n if (!data.length)\n return [];\n let pos = 0;\n const res = [];\n const digits = Array.from(data, (d) => {\n anumber(d);\n if (d < 0 || d >= from)\n throw new Error(`invalid integer: ${d}`);\n return d;\n });\n const dlen = digits.length;\n while (true) {\n let carry = 0;\n let done = true;\n for (let i = pos; i < dlen; i++) {\n const digit = digits[i];\n const fromCarry = from * carry;\n const digitBase = fromCarry + digit;\n if (!Number.isSafeInteger(digitBase) ||\n fromCarry / from !== carry ||\n digitBase - digit !== fromCarry) {\n throw new Error('convertRadix: carry overflow');\n }\n const div = digitBase / to;\n carry = digitBase % to;\n const rounded = Math.floor(div);\n digits[i] = rounded;\n if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)\n throw new Error('convertRadix: carry overflow');\n if (!done)\n continue;\n else if (!rounded)\n pos = i;\n else\n done = false;\n }\n res.push(carry);\n if (done)\n break;\n }\n for (let i = 0; i < data.length - 1 && data[i] === 0; i++)\n res.push(0);\n return res.reverse();\n}\nconst gcd = (a, b) => (b === 0 ? a : gcd(b, a % b));\nconst radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));\nconst powers = /* @__PURE__ */ (() => {\n let res = [];\n for (let i = 0; i < 40; i++)\n res.push(2 ** i);\n return res;\n})();\n/**\n * Implemented with numbers, because BigInt is 5x slower\n */\nfunction convertRadix2(data, from, to, padding) {\n aArr(data);\n if (from <= 0 || from > 32)\n throw new Error(`convertRadix2: wrong from=${from}`);\n if (to <= 0 || to > 32)\n throw new Error(`convertRadix2: wrong to=${to}`);\n if (radix2carry(from, to) > 32) {\n throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`);\n }\n let carry = 0;\n let pos = 0; // bitwise position in current element\n const max = powers[from];\n const mask = powers[to] - 1;\n const res = [];\n for (const n of data) {\n anumber(n);\n if (n >= max)\n throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);\n carry = (carry << from) | n;\n if (pos + from > 32)\n throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);\n pos += from;\n for (; pos >= to; pos -= to)\n res.push(((carry >> (pos - to)) & mask) >>> 0);\n const pow = powers[pos];\n if (pow === undefined)\n throw new Error('invalid carry');\n carry &= pow - 1; // clean carry, otherwise it will cause overflow\n }\n carry = (carry << (to - pos)) & mask;\n if (!padding && pos >= from)\n throw new Error('Excess padding');\n if (!padding && carry > 0)\n throw new Error(`Non-zero padding: ${carry}`);\n if (padding && pos > 0)\n res.push(carry >>> 0);\n return res;\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix(num) {\n anumber(num);\n const _256 = 2 ** 8;\n return {\n encode: (bytes) => {\n if (!isBytes(bytes))\n throw new Error('radix.encode input should be Uint8Array');\n return convertRadix(Array.from(bytes), _256, num);\n },\n decode: (digits) => {\n anumArr('radix.decode', digits);\n return Uint8Array.from(convertRadix(digits, num, _256));\n },\n };\n}\n/**\n * If both bases are power of same number (like `2**8 <-> 2**64`),\n * there is a linear algorithm. For now we have implementation for power-of-two bases only.\n * @__NO_SIDE_EFFECTS__\n */\nfunction radix2(bits, revPadding = false) {\n anumber(bits);\n if (bits <= 0 || bits > 32)\n throw new Error('radix2: bits should be in (0..32]');\n if (radix2carry(8, bits) > 32 || radix2carry(bits, 8) > 32)\n throw new Error('radix2: carry overflow');\n return {\n encode: (bytes) => {\n if (!isBytes(bytes))\n throw new Error('radix2.encode input should be Uint8Array');\n return convertRadix2(Array.from(bytes), 8, bits, !revPadding);\n },\n decode: (digits) => {\n anumArr('radix2.decode', digits);\n return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));\n },\n };\n}\nfunction unsafeWrapper(fn) {\n afn(fn);\n return function (...args) {\n try {\n return fn.apply(null, args);\n }\n catch (e) { }\n };\n}\nfunction checksum(len, fn) {\n anumber(len);\n afn(fn);\n return {\n encode(data) {\n if (!isBytes(data))\n throw new Error('checksum.encode: input should be Uint8Array');\n const sum = fn(data).slice(0, len);\n const res = new Uint8Array(data.length + len);\n res.set(data);\n res.set(sum, data.length);\n return res;\n },\n decode(data) {\n if (!isBytes(data))\n throw new Error('checksum.decode: input should be Uint8Array');\n const payload = data.slice(0, -len);\n const oldChecksum = data.slice(-len);\n const newChecksum = fn(payload).slice(0, len);\n for (let i = 0; i < len; i++)\n if (newChecksum[i] !== oldChecksum[i])\n throw new Error('Invalid checksum');\n return payload;\n },\n };\n}\n// prettier-ignore\nexport const utils = {\n alphabet, chain, checksum, convertRadix, convertRadix2, radix, radix2, join, padding,\n};\n// RFC 4648 aka RFC 3548\n// ---------------------\n/**\n * base16 encoding from RFC 4648.\n * @example\n * ```js\n * base16.encode(Uint8Array.from([0x12, 0xab]));\n * // => '12AB'\n * ```\n */\nexport const base16 = chain(radix2(4), alphabet('0123456789ABCDEF'), join(''));\n/**\n * base32 encoding from RFC 4648. Has padding.\n * Use `base32nopad` for unpadded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'CKVQ===='\n * base32.decode('CKVQ====');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32 = chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), padding(5), join(''));\n/**\n * base32 encoding from RFC 4648. No padding.\n * Use `base32` for padded version.\n * Also check out `base32hex`, `base32hexnopad`, `base32crockford`.\n * @example\n * ```js\n * base32nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'CKVQ'\n * base32nopad.decode('CKVQ');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32nopad = chain(radix2(5), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'), join(''));\n/**\n * base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.\n * Use `base32hexnopad` for unpadded version.\n * @example\n * ```js\n * base32hex.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ALG===='\n * base32hex.decode('2ALG====');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hex = chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), padding(5), join(''));\n/**\n * base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.\n * Use `base32hex` for padded version.\n * @example\n * ```js\n * base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ALG'\n * base32hexnopad.decode('2ALG');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32hexnopad = chain(radix2(5), alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'), join(''));\n/**\n * base32 encoding from RFC 4648. Doug Crockford's version.\n * https://www.crockford.com/base32.html\n * @example\n * ```js\n * base32crockford.encode(Uint8Array.from([0x12, 0xab]));\n * // => '2ANG'\n * base32crockford.decode('2ANG');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base32crockford = chain(radix2(5), alphabet('0123456789ABCDEFGHJKMNPQRSTVWXYZ'), join(''), normalize((s) => s.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1')));\n// Built-in base64 conversion https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64\n// prettier-ignore\nconst hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === 'function' &&\n typeof Uint8Array.fromBase64 === 'function')();\nconst decodeBase64Builtin = (s, isUrl) => {\n astr('base64', s);\n const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;\n const alphabet = isUrl ? 'base64url' : 'base64';\n if (s.length > 0 && !re.test(s))\n throw new Error('invalid base64');\n return Uint8Array.fromBase64(s, { alphabet, lastChunkHandling: 'strict' });\n};\n/**\n * base64 from RFC 4648. Padded.\n * Use `base64nopad` for unpadded version.\n * Also check out `base64url`, `base64urlnopad`.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs='\n * base64.decode('Eqs=');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64 = hasBase64Builtin ? {\n encode(b) { abytes(b); return b.toBase64(); },\n decode(s) { return decodeBase64Builtin(s, false); },\n} : chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'), padding(6), join(''));\n/**\n * base64 from RFC 4648. No padding.\n * Use `base64` for padded version.\n * @example\n * ```js\n * base64nopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs'\n * base64nopad.decode('Eqs');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64nopad = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'), join(''));\n/**\n * base64 from RFC 4648, using URL-safe alphabet. Padded.\n * Use `base64urlnopad` for unpadded version.\n * Falls back to built-in function, when available.\n * @example\n * ```js\n * base64url.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs='\n * base64url.decode('Eqs=');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\n// prettier-ignore\nexport const base64url = hasBase64Builtin ? {\n encode(b) { abytes(b); return b.toBase64({ alphabet: 'base64url' }); },\n decode(s) { return decodeBase64Builtin(s, true); },\n} : chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'), padding(6), join(''));\n/**\n * base64 from RFC 4648, using URL-safe alphabet. No padding.\n * Use `base64url` for padded version.\n * @example\n * ```js\n * base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));\n * // => 'Eqs'\n * base64urlnopad.decode('Eqs');\n * // => Uint8Array.from([0x12, 0xab])\n * ```\n */\nexport const base64urlnopad = chain(radix2(6), alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'), join(''));\n// base58 code\n// -----------\nconst genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => chain(radix(58), alphabet(abc), join(''));\n/**\n * base58: base64 without ambigous characters +, /, 0, O, I, l.\n * Quadratic (O(n^2)) - so, can't be used on large inputs.\n * @example\n * ```js\n * base58.decode('01abcdef');\n * // => '3UhJW'\n * ```\n */\nexport const base58 = genBase58('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz');\n/**\n * base58: flickr version. Check out `base58`.\n */\nexport const base58flickr = genBase58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ');\n/**\n * base58: XRP version. Check out `base58`.\n */\nexport const base58xrp = genBase58('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz');\n// Data len (index) -> encoded block len\nconst XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11];\n/**\n * base58: XMR version. Check out `base58`.\n * Done in 8-byte blocks (which equals 11 chars in decoding). Last (non-full) block padded with '1' to size in XMR_BLOCK_LEN.\n * Block encoding significantly reduces quadratic complexity of base58.\n */\nexport const base58xmr = {\n encode(data) {\n let res = '';\n for (let i = 0; i < data.length; i += 8) {\n const block = data.subarray(i, i + 8);\n res += base58.encode(block).padStart(XMR_BLOCK_LEN[block.length], '1');\n }\n return res;\n },\n decode(str) {\n let res = [];\n for (let i = 0; i < str.length; i += 11) {\n const slice = str.slice(i, i + 11);\n const blockLen = XMR_BLOCK_LEN.indexOf(slice.length);\n const block = base58.decode(slice);\n for (let j = 0; j < block.length - blockLen; j++) {\n if (block[j] !== 0)\n throw new Error('base58xmr: wrong padding');\n }\n res = res.concat(Array.from(block.slice(block.length - blockLen)));\n }\n return Uint8Array.from(res);\n },\n};\n/**\n * Method, which creates base58check encoder.\n * Requires function, calculating sha256.\n */\nexport const createBase58check = (sha256) => chain(checksum(4, (data) => sha256(sha256(data))), base58);\n/**\n * Use `createBase58check` instead.\n * @deprecated\n */\nexport const base58check = createBase58check;\nconst BECH_ALPHABET = chain(alphabet('qpzry9x8gf2tvdw0s3jn54khce6mua7l'), join(''));\nconst POLYMOD_GENERATORS = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];\nfunction bech32Polymod(pre) {\n const b = pre >> 25;\n let chk = (pre & 0x1ffffff) << 5;\n for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {\n if (((b >> i) & 1) === 1)\n chk ^= POLYMOD_GENERATORS[i];\n }\n return chk;\n}\nfunction bechChecksum(prefix, words, encodingConst = 1) {\n const len = prefix.length;\n let chk = 1;\n for (let i = 0; i < len; i++) {\n const c = prefix.charCodeAt(i);\n if (c < 33 || c > 126)\n throw new Error(`Invalid prefix (${prefix})`);\n chk = bech32Polymod(chk) ^ (c >> 5);\n }\n chk = bech32Polymod(chk);\n for (let i = 0; i < len; i++)\n chk = bech32Polymod(chk) ^ (prefix.charCodeAt(i) & 0x1f);\n for (let v of words)\n chk = bech32Polymod(chk) ^ v;\n for (let i = 0; i < 6; i++)\n chk = bech32Polymod(chk);\n chk ^= encodingConst;\n return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));\n}\n/**\n * @__NO_SIDE_EFFECTS__\n */\nfunction genBech32(encoding) {\n const ENCODING_CONST = encoding === 'bech32' ? 1 : 0x2bc830a3;\n const _words = radix2(5);\n const fromWords = _words.decode;\n const toWords = _words.encode;\n const fromWordsUnsafe = unsafeWrapper(fromWords);\n function encode(prefix, words, limit = 90) {\n astr('bech32.encode prefix', prefix);\n if (isBytes(words))\n words = Array.from(words);\n anumArr('bech32.encode', words);\n const plen = prefix.length;\n if (plen === 0)\n throw new TypeError(`Invalid prefix length ${plen}`);\n const actualLength = plen + 7 + words.length;\n if (limit !== false && actualLength > limit)\n throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);\n const lowered = prefix.toLowerCase();\n const sum = bechChecksum(lowered, words, ENCODING_CONST);\n return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;\n }\n function decode(str, limit = 90) {\n astr('bech32.decode input', str);\n const slen = str.length;\n if (slen < 8 || (limit !== false && slen > limit))\n throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);\n // don't allow mixed case\n const lowered = str.toLowerCase();\n if (str !== lowered && str !== str.toUpperCase())\n throw new Error(`String must be lowercase or uppercase`);\n const sepIndex = lowered.lastIndexOf('1');\n if (sepIndex === 0 || sepIndex === -1)\n throw new Error(`Letter \"1\" must be present between prefix and data only`);\n const prefix = lowered.slice(0, sepIndex);\n const data = lowered.slice(sepIndex + 1);\n if (data.length < 6)\n throw new Error('Data must be at least 6 characters long');\n const words = BECH_ALPHABET.decode(data).slice(0, -6);\n const sum = bechChecksum(prefix, words, ENCODING_CONST);\n if (!data.endsWith(sum))\n throw new Error(`Invalid checksum in ${str}: expected \"${sum}\"`);\n return { prefix, words };\n }\n const decodeUnsafe = unsafeWrapper(decode);\n function decodeToBytes(str) {\n const { prefix, words } = decode(str, false);\n return { prefix, words, bytes: fromWords(words) };\n }\n function encodeFromBytes(prefix, bytes) {\n return encode(prefix, toWords(bytes));\n }\n return {\n encode,\n decode,\n encodeFromBytes,\n decodeToBytes,\n decodeUnsafe,\n fromWords,\n fromWordsUnsafe,\n toWords,\n };\n}\n/**\n * bech32 from BIP 173. Operates on words.\n * For high-level, check out scure-btc-signer:\n * https://github.com/paulmillr/scure-btc-signer.\n */\nexport const bech32 = genBech32('bech32');\n/**\n * bech32m from BIP 350. Operates on words.\n * It was to mitigate `bech32` weaknesses.\n * For high-level, check out scure-btc-signer:\n * https://github.com/paulmillr/scure-btc-signer.\n */\nexport const bech32m = genBech32('bech32m');\n/**\n * UTF-8-to-byte decoder. Uses built-in TextDecoder / TextEncoder.\n * @example\n * ```js\n * const b = utf8.decode(\"hey\"); // => new Uint8Array([ 104, 101, 121 ])\n * const str = utf8.encode(b); // \"hey\"\n * ```\n */\nexport const utf8 = {\n encode: (data) => new TextDecoder().decode(data),\n decode: (str) => new TextEncoder().encode(str),\n};\n// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex\n// prettier-ignore\nconst hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === 'function' &&\n typeof Uint8Array.fromHex === 'function')();\n// prettier-ignore\nconst hexBuiltin = {\n encode(data) { abytes(data); return data.toHex(); },\n decode(s) { astr('hex', s); return Uint8Array.fromHex(s); },\n};\n/**\n * hex string decoder. Uses built-in function, when available.\n * @example\n * ```js\n * const b = hex.decode(\"0102ff\"); // => new Uint8Array([ 1, 2, 255 ])\n * const str = hex.encode(b); // \"0102ff\"\n * ```\n */\nexport const hex = hasHexBuiltin\n ? hexBuiltin\n : chain(radix2(4), alphabet('0123456789abcdef'), join(''), normalize((s) => {\n if (typeof s !== 'string' || s.length % 2 !== 0)\n throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);\n return s.toLowerCase();\n }));\n// prettier-ignore\nconst CODERS = {\n utf8, hex, base16, base32, base64, base64url, base58, base58xmr\n};\nconst coderTypeError = 'Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr';\n/** @deprecated */\nexport const bytesToString = (type, bytes) => {\n if (typeof type !== 'string' || !CODERS.hasOwnProperty(type))\n throw new TypeError(coderTypeError);\n if (!isBytes(bytes))\n throw new TypeError('bytesToString() expects Uint8Array');\n return CODERS[type].encode(bytes);\n};\n/** @deprecated */\nexport const str = bytesToString; // as in python, but for bytes only\n/** @deprecated */\nexport const stringToBytes = (type, str) => {\n if (!CODERS.hasOwnProperty(type))\n throw new TypeError(coderTypeError);\n if (typeof str !== 'string')\n throw new TypeError('stringToBytes() expects string');\n return CODERS[type].decode(str);\n};\n/** @deprecated */\nexport const bytes = stringToBytes;\n//# sourceMappingURL=index.js.map"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AACA;AAAA,SAAS,OAAO,CAAC,GAAG;AAAA,EAChB,OAAO,aAAa,cAAe,YAAY,OAAO,CAAC,KAAK,EAAE,YAAY,SAAS;AAAA;AAGvF,SAAS,MAAM,CAAC,GAAG;AAAA,EACf,IAAI,CAAC,QAAQ,CAAC;AAAA,IACV,MAAM,IAAI,MAAM,qBAAqB;AAAA;AAE7C,SAAS,SAAS,CAAC,UAAU,KAAK;AAAA,EAC9B,IAAI,CAAC,MAAM,QAAQ,GAAG;AAAA,IAClB,OAAO;AAAA,EACX,IAAI,IAAI,WAAW;AAAA,IACf,OAAO;AAAA,EACX,IAAI,UAAU;AAAA,IACV,OAAO,IAAI,MAAM,CAAC,SAAS,OAAO,SAAS,QAAQ;AAAA,EACvD,EACK;AAAA,IACD,OAAO,IAAI,MAAM,CAA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,OAAO,OAAO,UAAU,KAAK,EAAE;AAAA;AAAA,EAEpD,SAAS,eAAe,CAAC,QAAQ,OAAO;AAAA,IACpC,OAAO,OAAO,QAAQ,QAAQ,KAAK,CAAC;AAAA;AAAA,EAExC,OAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AAAA;AAOG,IAAM,SAAS,UAAU,QAAQ;AAOjC,IAAM,UAAU,UAAU,SAAS;AAe1C,IAAM,iCAAiC,MAAM,OAAO,WAAW,KAAK,CAAC,CAAC,EAAE,UAAU,cAC9E,OAAO,WAAW,YAAY,YAAY;AAE9C,IAAM,aAAa;AAAA,EACf,MAAM,CAAC,MAAM;AAAA,IAAE,OAAO,IAAI;AAAA,IAAG,OAAO,KAAK,MAAM;AAAA;AAAA,EAC/C,MAAM,CAAC,GAAG;AAAA,IAAE,KAAK,OAAO,CAAC;AAAA,IAAG,OAAO,WAAW,QAAQ,CAAC;AAAA;AAC3D;AASO,IAAM,MAAM,gBACb,aACA,MAAM,OAAO,CAAC,GAAG,SAAS,kBAAkB,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,MAAM;AAAA,EACxE,IAAI,OAAO,MAAM,YAAY,EAAE,SAAS,MAAM;AAAA,IAC1C,MAAM,IAAI,UAAU,oCAAoC,OAAO,iBAAiB,EAAE,QAAQ;AAAA,EAC9F,OAAO,EAAE,YAAY;AAAA,CACxB,CAAC;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "CBC131E37BFBAEEF64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callContract,
|
|
3
|
-
getMapEntry
|
|
3
|
+
getMapEntry
|
|
4
|
+
} from "./stacks-z1j5d6fd.js";
|
|
5
|
+
import {
|
|
4
6
|
readContract
|
|
5
|
-
} from "./stacks-
|
|
7
|
+
} from "./stacks-q1mjkt15.js";
|
|
6
8
|
import {
|
|
7
9
|
clarityValueToJSUntyped,
|
|
8
10
|
jsToClarityValue,
|
|
@@ -130,5 +132,5 @@ class ContractResponseError extends Error {
|
|
|
130
132
|
|
|
131
133
|
export { getContract, ContractResponseError };
|
|
132
134
|
|
|
133
|
-
//# debugId=
|
|
134
|
-
//# sourceMappingURL=stacks-
|
|
135
|
+
//# debugId=1BB63E229D38EA0D64756E2164756E21
|
|
136
|
+
//# sourceMappingURL=stacks-8mj5jw77.js.map
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
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// --- 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(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,20 @@
|
|
|
1
|
+
// src/actions/public/readContract.ts
|
|
2
|
+
async function readContract(client, params) {
|
|
3
|
+
const [address, name] = parseContractId(params.contract);
|
|
4
|
+
const sender = params.sender ?? address;
|
|
5
|
+
const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
|
|
6
|
+
const data = await client.request(`/v2/contracts/call-read/${address}/${name}/${params.functionName}`, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
body: {
|
|
9
|
+
sender,
|
|
10
|
+
arguments: serializedArgs
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
if (data.okay) {
|
|
14
|
+
return deserializeCVBytes(data.result);
|
|
15
|
+
}
|
|
16
|
+
throw new Error(data.cause ?? "Read-only call failed");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# debugId=9736239B45D9470164756E2164756E21
|
|
20
|
+
//# sourceMappingURL=stacks-cdvn8qbh.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/public/readContract.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"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};\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 data = await client.request(\n\t\t`/v2/contracts/call-read/${address}/${name}/${params.functionName}`,\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
|
+
"mappings": ";AAcA,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/C,OAAO,WAAW,iBAAiB,GAAG,CAAC,CAAC,CACzC;AAAA,EAEA,MAAM,OAAO,MAAM,OAAO,QACzB,2BAA2B,WAAW,QAAQ,OAAO,gBACrD;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,MACL;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,EACD,CACD;AAAA,EAEA,IAAI,KAAK,MAAM;AAAA,IACd,OAAO,mBAAsB,KAAK,MAAM;AAAA,EACzC;AAAA,EACA,MAAM,IAAI,MAAM,KAAK,SAAS,uBAAuB;AAAA;",
|
|
8
|
+
"debugId": "9736239B45D9470164756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -9,24 +9,6 @@ async function getMapEntry(client, params) {
|
|
|
9
9
|
return deserializeCVBytes(data.data);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
// src/actions/public/readContract.ts
|
|
13
|
-
async function readContract(client, params) {
|
|
14
|
-
const [address, name] = parseContractId(params.contract);
|
|
15
|
-
const sender = params.sender ?? address;
|
|
16
|
-
const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
|
|
17
|
-
const data = await client.request(`/v2/contracts/call-read/${address}/${name}/${params.functionName}`, {
|
|
18
|
-
method: "POST",
|
|
19
|
-
body: {
|
|
20
|
-
sender,
|
|
21
|
-
arguments: serializedArgs
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
if (data.okay) {
|
|
25
|
-
return deserializeCVBytes(data.result);
|
|
26
|
-
}
|
|
27
|
-
throw new Error(data.cause ?? "Read-only call failed");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
12
|
// src/actions/wallet/callContract.ts
|
|
31
13
|
async function callContract(client, params) {
|
|
32
14
|
const account = client.account;
|
|
@@ -68,5 +50,5 @@ async function callContract(client, params) {
|
|
|
68
50
|
});
|
|
69
51
|
}
|
|
70
52
|
|
|
71
|
-
//# debugId=
|
|
72
|
-
//# sourceMappingURL=stacks-
|
|
53
|
+
//# debugId=9801AB4119DA901264756E2164756E21
|
|
54
|
+
//# sourceMappingURL=stacks-maamjqma.cjs.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/
|
|
3
|
+
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"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 GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
|
|
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};\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 data = await client.request(\n\t\t`/v2/contracts/call-read/${address}/${name}/${params.functionName}`,\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",
|
|
7
6
|
"import 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 { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\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 unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: params.fee ?? 0n,\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 (params.fee === undefined) {\n\t\tconst estimates = await estimateFee(client, { transaction: unsigned });\n\t\tconst mid = estimates[1] ?? estimates[0];\n\t\tif (mid) {\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\t\t(unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n\t\t}\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n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QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,WAAW,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,cAAc,OAAO;AAAA,IACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACtC,KAAK,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,OAAO,QAAQ,WAAW;AAAA,IAC7B,MAAM,YAAY,MAAM,YAAY,QAAQ,EAAE,aAAa,SAAS,CAAC;AAAA,IACrE,MAAM,MAAM,UAAU,MAAM,UAAU;AAAA,IACtC,IAAI,KAAK;AAAA,MAEP,SAAS,KAAK,kBAA0B,MAAM,OAAO,IAAI,GAAG;AAAA,IAC9D;AAAA,EACD;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
9
|
+
"debugId": "9801AB4119DA901264756E2164756E21",
|
|
11
10
|
"names": []
|
|
12
11
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deserializeCVBytes,
|
|
3
|
+
serializeCVBytes
|
|
4
|
+
} from "./stacks-0zysn74p.js";
|
|
5
|
+
import {
|
|
6
|
+
parseContractId
|
|
7
|
+
} from "./stacks-6xmk24yw.js";
|
|
8
|
+
import {
|
|
9
|
+
bytesToHex,
|
|
10
|
+
with0x
|
|
11
|
+
} from "./stacks-2h8d2y27.js";
|
|
12
|
+
|
|
13
|
+
// src/actions/public/readContract.ts
|
|
14
|
+
async function readContract(client, params) {
|
|
15
|
+
const [address, name] = parseContractId(params.contract);
|
|
16
|
+
const sender = params.sender ?? address;
|
|
17
|
+
const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
|
|
18
|
+
const data = await client.request(`/v2/contracts/call-read/${address}/${name}/${params.functionName}`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: {
|
|
21
|
+
sender,
|
|
22
|
+
arguments: serializedArgs
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (data.okay) {
|
|
26
|
+
return deserializeCVBytes(data.result);
|
|
27
|
+
}
|
|
28
|
+
throw new Error(data.cause ?? "Read-only call failed");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { readContract };
|
|
32
|
+
|
|
33
|
+
//# debugId=46B15CD66C8EE3CB64756E2164756E21
|
|
34
|
+
//# sourceMappingURL=stacks-q1mjkt15.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/public/readContract.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"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};\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 data = await client.request(\n\t\t`/v2/contracts/call-read/${address}/${name}/${params.functionName}`,\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
|
+
"mappings": ";;;;;;;;;;;;;AAcA,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/C,OAAO,WAAW,iBAAiB,GAAG,CAAC,CAAC,CACzC;AAAA,EAEA,MAAM,OAAO,MAAM,OAAO,QACzB,2BAA2B,WAAW,QAAQ,OAAO,gBACrD;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,MACL;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,EACD,CACD;AAAA,EAEA,IAAI,KAAK,MAAM;AAAA,IACd,OAAO,mBAAsB,KAAK,MAAM;AAAA,EACzC;AAAA,EACA,MAAM,IAAI,MAAM,KAAK,SAAS,uBAAuB;AAAA;",
|
|
8
|
+
"debugId": "46B15CD66C8EE3CB64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -31,24 +31,6 @@ async function getMapEntry(client, params) {
|
|
|
31
31
|
return deserializeCVBytes(data.data);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// src/actions/public/readContract.ts
|
|
35
|
-
async function readContract(client, params) {
|
|
36
|
-
const [address, name] = parseContractId(params.contract);
|
|
37
|
-
const sender = params.sender ?? address;
|
|
38
|
-
const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
|
|
39
|
-
const data = await client.request(`/v2/contracts/call-read/${address}/${name}/${params.functionName}`, {
|
|
40
|
-
method: "POST",
|
|
41
|
-
body: {
|
|
42
|
-
sender,
|
|
43
|
-
arguments: serializedArgs
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
if (data.okay) {
|
|
47
|
-
return deserializeCVBytes(data.result);
|
|
48
|
-
}
|
|
49
|
-
throw new Error(data.cause ?? "Read-only call failed");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
34
|
// src/actions/wallet/callContract.ts
|
|
53
35
|
async function callContract(client, params) {
|
|
54
36
|
const account = client.account;
|
|
@@ -90,7 +72,7 @@ async function callContract(client, params) {
|
|
|
90
72
|
});
|
|
91
73
|
}
|
|
92
74
|
|
|
93
|
-
export { getMapEntry,
|
|
75
|
+
export { getMapEntry, callContract };
|
|
94
76
|
|
|
95
|
-
//# debugId=
|
|
96
|
-
//# sourceMappingURL=stacks-
|
|
77
|
+
//# debugId=38BA122B145AC1B064756E2164756E21
|
|
78
|
+
//# sourceMappingURL=stacks-z1j5d6fd.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/
|
|
3
|
+
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"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 GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
|
|
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};\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 data = await client.request(\n\t\t`/v2/contracts/call-read/${address}/${name}/${params.functionName}`,\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",
|
|
7
6
|
"import 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 { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { estimateFee } from \"../public/estimateFee.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\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 unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: params.fee ?? 0n,\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 (params.fee === undefined) {\n\t\tconst estimates = await estimateFee(client, { transaction: unsigned });\n\t\tconst mid = estimates[1] ?? estimates[0];\n\t\tif (mid) {\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\t\t(unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n\t\t}\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,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AO,OAAO;AAAA,EACf;AAAA,EAGA,MAAM,QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,WAAW,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,cAAc,OAAO;AAAA,IACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACtC,KAAK,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,OAAO,QAAQ,WAAW;AAAA,IAC7B,MAAM,YAAY,MAAM,YAAY,QAAQ,EAAE,aAAa,SAAS,CAAC;AAAA,IACrE,MAAM,MAAM,UAAU,MAAM,UAAU;AAAA,IACtC,IAAI,KAAK;AAAA,MAEP,SAAS,KAAK,kBAA0B,MAAM,OAAO,IAAI,GAAG;AAAA,IAC9D;AAAA,EACD;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
9
|
+
"debugId": "38BA122B145AC1B064756E2164756E21",
|
|
11
10
|
"names": []
|
|
12
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ContractResponseError,
|
|
3
3
|
getContract
|
|
4
|
-
} from "../../shared/stacks-
|
|
4
|
+
} from "../../shared/stacks-8mj5jw77.js";
|
|
5
5
|
import {
|
|
6
6
|
deployContract,
|
|
7
7
|
getAccountInfo,
|
|
@@ -15,12 +15,14 @@ import {
|
|
|
15
15
|
simulateCall,
|
|
16
16
|
simulateTransaction,
|
|
17
17
|
transferStx
|
|
18
|
-
} from "../../shared/stacks-
|
|
18
|
+
} from "../../shared/stacks-53bjdb6p.js";
|
|
19
19
|
import {
|
|
20
20
|
callContract,
|
|
21
|
-
getMapEntry
|
|
21
|
+
getMapEntry
|
|
22
|
+
} from "../../shared/stacks-z1j5d6fd.js";
|
|
23
|
+
import {
|
|
22
24
|
readContract
|
|
23
|
-
} from "../../shared/stacks-
|
|
25
|
+
} from "../../shared/stacks-q1mjkt15.js";
|
|
24
26
|
import {
|
|
25
27
|
watchAddress,
|
|
26
28
|
watchAddressBalance,
|
|
@@ -79,5 +81,5 @@ export {
|
|
|
79
81
|
ContractResponseError
|
|
80
82
|
};
|
|
81
83
|
|
|
82
|
-
//# debugId=
|
|
84
|
+
//# debugId=7902642CF933E85764756E2164756E21
|
|
83
85
|
//# sourceMappingURL=index.js.map
|