@secondlayer/stacks 0.2.1 → 0.3.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/dist/shared/stacks-02actsrx.cjs.map +2 -2
- package/dist/shared/{stacks-vyb9rx8q.js → stacks-09wa7ewe.js} +125 -115
- package/dist/shared/stacks-09wa7ewe.js.map +15 -0
- package/dist/shared/{stacks-ky14tdf6.cjs → stacks-0nfexv24.cjs} +20 -8
- package/dist/shared/stacks-0nfexv24.cjs.map +14 -0
- package/dist/shared/{stacks-an5k8n4t.cjs → stacks-14pgpkrr.cjs} +82 -73
- package/dist/shared/stacks-14pgpkrr.cjs.map +23 -0
- package/dist/shared/{stacks-vbke9mqw.cjs → stacks-17sdtaxg.cjs} +120 -106
- package/dist/shared/stacks-17sdtaxg.cjs.map +15 -0
- package/dist/shared/{stacks-wrb1es85.js → stacks-1s5w4ncf.js} +46 -34
- package/dist/shared/stacks-1s5w4ncf.js.map +17 -0
- package/dist/shared/stacks-24h5k94q.cjs.map +3 -3
- package/dist/shared/{stacks-evnzth1q.cjs → stacks-4vzmhw3q.cjs} +3 -3
- package/dist/shared/stacks-4vzmhw3q.cjs.map +10 -0
- package/dist/shared/{stacks-vd9jcp0b.js → stacks-4x2bcc2k.js} +89 -80
- package/dist/shared/stacks-4x2bcc2k.js.map +23 -0
- package/dist/shared/stacks-5tprhns9.cjs.map +3 -3
- package/dist/shared/stacks-709tra19.js.map +2 -2
- package/dist/shared/{stacks-qcx67vqa.js → stacks-70p84bgg.js} +3 -3
- package/dist/shared/stacks-70p84bgg.js.map +10 -0
- package/dist/shared/{stacks-k2p5tv6x.js → stacks-913a2rx7.js} +3 -3
- package/dist/shared/stacks-913a2rx7.js.map +10 -0
- package/dist/shared/{stacks-qyt8m5v0.js → stacks-96d6m1zy.js} +16 -7
- package/dist/shared/stacks-96d6m1zy.js.map +11 -0
- package/dist/shared/stacks-9g0jhab3.cjs.map +2 -2
- package/dist/shared/stacks-dr5en54r.cjs.map +2 -2
- package/dist/shared/stacks-fcaefc5b.cjs.map +2 -2
- package/dist/shared/stacks-gck1sq7h.cjs.map +2 -2
- package/dist/shared/{stacks-yfveb68e.js → stacks-je937aas.js} +3 -3
- package/dist/shared/stacks-je937aas.js.map +10 -0
- package/dist/shared/{stacks-k58k970n.js → stacks-kg1npstf.js} +5 -3
- package/dist/shared/stacks-kg1npstf.js.map +10 -0
- package/dist/shared/{stacks-qvg7c24g.cjs → stacks-n98w7g57.cjs} +5 -3
- package/dist/shared/stacks-n98w7g57.cjs.map +10 -0
- package/dist/shared/{stacks-9mdk86wp.js → stacks-nqae5amn.cjs} +77 -159
- package/dist/shared/stacks-nqae5amn.cjs.map +10 -0
- package/dist/shared/stacks-qcae5852.js.map +2 -2
- package/dist/shared/stacks-qt8ehebn.js.map +3 -3
- package/dist/shared/{stacks-r1t6g3c3.cjs → stacks-ra02bpny.cjs} +8 -3
- package/dist/shared/stacks-ra02bpny.cjs.map +11 -0
- package/dist/shared/{stacks-bycy6t9k.js → stacks-rwfgts3s.js} +2 -2
- package/dist/shared/{stacks-bycy6t9k.js.map → stacks-rwfgts3s.js.map} +2 -2
- package/dist/shared/{stacks-gjvbq6w7.js → stacks-s10yb9gz.js} +2 -2
- package/dist/shared/stacks-s10yb9gz.js.map +10 -0
- package/dist/shared/{stacks-v3zy6zds.cjs → stacks-s30kkvm8.js} +104 -117
- package/dist/shared/stacks-s30kkvm8.js.map +10 -0
- package/dist/shared/{stacks-nqytwfcc.js → stacks-s7z5q8be.js} +8 -3
- package/dist/shared/stacks-s7z5q8be.js.map +11 -0
- package/dist/shared/stacks-v9jqcpd4.js.map +2 -2
- package/dist/shared/stacks-vdfag81a.cjs.map +2 -2
- package/dist/shared/{stacks-fedzr2ka.js → stacks-wjem3xw9.js} +23 -11
- package/dist/shared/stacks-wjem3xw9.js.map +14 -0
- package/dist/shared/{stacks-k08tgzyp.cjs → stacks-wyxj879g.cjs} +3 -3
- package/dist/shared/stacks-wyxj879g.cjs.map +13 -0
- package/dist/shared/stacks-y3dh7hv1.js.map +3 -3
- package/dist/shared/{stacks-2ar4prfz.cjs → stacks-y5262j0z.cjs} +14 -5
- package/dist/shared/stacks-y5262j0z.cjs.map +11 -0
- package/dist/shared/stacks-ya3x01yd.cjs.map +2 -2
- package/dist/shared/{stacks-9avax1yf.js → stacks-zf7rbpzp.js} +5 -5
- package/dist/shared/stacks-zf7rbpzp.js.map +13 -0
- package/dist/shared/{stacks-61rvzkz1.cjs → stacks-znrb59ce.cjs} +41 -29
- package/dist/shared/stacks-znrb59ce.cjs.map +17 -0
- package/dist/src/accounts/index.cjs +2 -2
- package/dist/src/accounts/index.cjs.map +5 -5
- package/dist/src/accounts/index.js +4 -8
- package/dist/src/accounts/index.js.map +5 -5
- package/dist/src/actions/index.d.cts +36 -29
- package/dist/src/actions/index.d.ts +36 -29
- package/dist/src/actions/index.js +10 -10
- package/dist/src/bns/index.cjs +55 -43
- package/dist/src/bns/index.cjs.map +9 -9
- package/dist/src/bns/index.d.cts +29 -29
- package/dist/src/bns/index.d.ts +29 -29
- package/dist/src/bns/index.js +66 -54
- package/dist/src/bns/index.js.map +9 -9
- package/dist/src/clarity/index.js +6 -6
- package/dist/src/connect/index.cjs +114 -112
- package/dist/src/connect/index.cjs.map +13 -13
- package/dist/src/connect/index.js +114 -112
- package/dist/src/connect/index.js.map +13 -13
- package/dist/src/connect/walletconnect/index.cjs +3 -3
- package/dist/src/connect/walletconnect/index.cjs.map +10 -10
- package/dist/src/connect/walletconnect/index.js +3 -3
- package/dist/src/connect/walletconnect/index.js.map +10 -10
- package/dist/src/index.cjs +108 -2
- package/dist/src/index.cjs.map +19 -15
- package/dist/src/index.d.cts +298 -112
- package/dist/src/index.d.ts +298 -112
- package/dist/src/index.js +125 -12
- package/dist/src/index.js.map +19 -15
- package/dist/src/postconditions/index.js +3 -3
- package/dist/src/pox/index.cjs.map +6 -6
- package/dist/src/pox/index.d.cts +29 -29
- package/dist/src/pox/index.d.ts +29 -29
- package/dist/src/pox/index.js +9 -9
- package/dist/src/pox/index.js.map +6 -6
- package/dist/src/stackingdao/index.cjs +31 -6
- package/dist/src/stackingdao/index.cjs.map +6 -6
- package/dist/src/stackingdao/index.d.cts +29 -29
- package/dist/src/stackingdao/index.d.ts +29 -29
- package/dist/src/stackingdao/index.js +41 -16
- package/dist/src/stackingdao/index.js.map +6 -6
- package/dist/src/subscriptions/index.d.cts +29 -29
- package/dist/src/subscriptions/index.d.ts +29 -29
- package/dist/src/tools/btc/index.cjs +130 -0
- package/dist/src/tools/btc/index.cjs.map +10 -0
- package/dist/src/tools/btc/index.d.cts +8 -0
- package/dist/src/tools/btc/index.d.ts +8 -0
- package/dist/src/tools/btc/index.js +89 -0
- package/dist/src/tools/btc/index.js.map +10 -0
- package/dist/src/tools/index.cjs +2470 -0
- package/dist/src/tools/index.cjs.map +61 -0
- package/dist/src/tools/index.d.cts +144 -0
- package/dist/src/tools/index.d.ts +144 -0
- package/dist/src/tools/index.js +2435 -0
- package/dist/src/tools/index.js.map +61 -0
- package/dist/src/transactions/index.d.cts +7 -0
- package/dist/src/transactions/index.d.ts +7 -0
- package/dist/src/transactions/index.js +6 -6
- package/dist/src/triggers/index.cjs +66 -0
- package/dist/src/triggers/index.cjs.map +10 -0
- package/dist/src/triggers/index.d.cts +116 -0
- package/dist/src/triggers/index.d.ts +116 -0
- package/dist/src/triggers/index.js +25 -0
- package/dist/src/triggers/index.js.map +10 -0
- package/dist/src/tx/index.cjs +65 -0
- package/dist/src/tx/index.cjs.map +10 -0
- package/dist/src/tx/index.d.cts +42 -0
- package/dist/src/tx/index.d.ts +42 -0
- package/dist/src/tx/index.js +22 -0
- package/dist/src/tx/index.js.map +10 -0
- package/dist/src/ui/index.cjs +431 -0
- package/dist/src/ui/index.cjs.map +27 -0
- package/dist/src/ui/index.d.cts +107 -0
- package/dist/src/ui/index.d.ts +107 -0
- package/dist/src/ui/index.js +391 -0
- package/dist/src/ui/index.js.map +27 -0
- package/dist/src/ui/schemas.cjs +134 -0
- package/dist/src/ui/schemas.cjs.map +18 -0
- package/dist/src/ui/schemas.d.cts +83 -0
- package/dist/src/ui/schemas.d.ts +83 -0
- package/dist/src/ui/schemas.js +91 -0
- package/dist/src/ui/schemas.js.map +18 -0
- package/dist/src/utils/index.cjs +3 -3
- package/dist/src/utils/index.cjs.map +4 -4
- package/dist/src/utils/index.js +7 -7
- package/dist/src/utils/index.js.map +4 -4
- package/package.json +157 -105
- package/dist/shared/stacks-2ar4prfz.cjs.map +0 -11
- package/dist/shared/stacks-61rvzkz1.cjs.map +0 -17
- package/dist/shared/stacks-9avax1yf.js.map +0 -13
- package/dist/shared/stacks-9mdk86wp.js.map +0 -10
- package/dist/shared/stacks-an5k8n4t.cjs.map +0 -23
- package/dist/shared/stacks-evnzth1q.cjs.map +0 -10
- package/dist/shared/stacks-fedzr2ka.js.map +0 -13
- package/dist/shared/stacks-gjvbq6w7.js.map +0 -10
- package/dist/shared/stacks-k08tgzyp.cjs.map +0 -13
- package/dist/shared/stacks-k2p5tv6x.js.map +0 -10
- package/dist/shared/stacks-k58k970n.js.map +0 -10
- package/dist/shared/stacks-ky14tdf6.cjs.map +0 -13
- package/dist/shared/stacks-nqytwfcc.js.map +0 -11
- package/dist/shared/stacks-qcx67vqa.js.map +0 -10
- package/dist/shared/stacks-qvg7c24g.cjs.map +0 -10
- package/dist/shared/stacks-qyt8m5v0.js.map +0 -11
- package/dist/shared/stacks-r1t6g3c3.cjs.map +0 -11
- package/dist/shared/stacks-v3zy6zds.cjs.map +0 -10
- package/dist/shared/stacks-vbke9mqw.cjs.map +0 -15
- package/dist/shared/stacks-vd9jcp0b.js.map +0 -23
- package/dist/shared/stacks-vyb9rx8q.js.map +0 -15
- package/dist/shared/stacks-wrb1es85.js.map +0 -17
- package/dist/shared/stacks-yfveb68e.js.map +0 -10
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/tools/index.ts", "../../../src/utils/c32.ts", "../../../src/utils/encoding.ts", "../../../src/clarity/types.ts", "../../../src/clarity/serialize.ts", "../../../src/transactions/types.ts", "../../../src/transactions/wire/serialize.ts", "../../../src/actions/public/estimateFee.ts", "../../../src/actions/public/getAccountInfo.ts", "../../../src/actions/public/getBalance.ts", "../../../src/actions/public/getBlock.ts", "../../../src/actions/public/getBlockHeight.ts", "../../../src/utils/bytes-reader.ts", "../../../src/utils/address.ts", "../../../src/clarity/values.ts", "../../../src/clarity/deserialize.ts", "../../../src/actions/public/readContract.ts", "../../../src/clarity/abi/utils.ts", "../../../src/utils/constants.ts", "../../../src/clarity/abi/guards.ts", "../../../src/clarity/bridge.ts", "../../../src/actions/public/getMapEntry.ts", "../../../src/transactions/authorization.ts", "../../../src/utils/hash.ts", "../../../src/transactions/multisig.ts", "../../../src/transactions/build.ts", "../../../src/transactions/signer.ts", "../../../src/actions/public/getNonce.ts", "../../../src/errors/base.ts", "../../../src/errors/transaction.ts", "../../../src/actions/wallet/sendTransaction.ts", "../../../src/actions/wallet/utils.ts", "../../../src/actions/wallet/callContract.ts", "../../../src/actions/getContract.ts", "../../../src/bns/abi.ts", "../../../src/bns/constants.ts", "../../../src/bns/utils.ts", "../../../src/bns/actions.ts", "../../../src/chains/definitions.ts", "../../../src/clients/createClient.ts", "../../../src/actions/public/getContractAbi.ts", "../../../src/actions/public/multicall.ts", "../../../src/errors/simulation.ts", "../../../src/actions/public/simulateCall.ts", "../../../src/actions/public/simulateTransaction.ts", "../../../src/errors/websocket.ts", "../../../src/subscriptions/actions.ts", "../../../src/clients/decorators/public.ts", "../../../src/clients/createPublicClient.ts", "../../../src/transports/createTransport.ts", "../../../src/transports/http.ts", "../../../src/tools/client.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * AI SDK-compatible read tools for the Stacks chain.\n *\n * Each tool is a `tool()` from `ai@^6` with a Zod input schema + async\n * execute that calls the underlying `@secondlayer/stacks` public action.\n *\n * Two usage modes:\n *\n * 1. **Bare exports** — use the default public client (reads `STACKS_RPC_URL`\n * + `STACKS_CHAIN` env vars). Zero-config, fine for most workflows:\n *\n * ```ts\n * import { getStxBalance, bnsReverse } from \"@secondlayer/stacks/tools\"\n * await step.generateText(\"enrich\", {\n * model: anthropic(\"claude-sonnet-4-6\"),\n * tools: { getStxBalance, bnsReverse },\n * prompt: \"…\",\n * })\n * ```\n *\n * 2. **Factory** — bind a custom client (testnet, custom RPC, etc.):\n *\n * ```ts\n * import { createPublicClient, http, testnet } from \"@secondlayer/stacks\"\n * import { createStacksTools } from \"@secondlayer/stacks/tools\"\n * const stacks = createStacksTools(\n * createPublicClient({ chain: testnet, transport: http() }),\n * )\n * ```\n */\n\nimport { type Tool, tool } from \"ai\";\nimport { z } from \"zod\";\n\n// biome-ignore lint/suspicious/noExplicitAny: Tool's input-schema generic is\n// too precise for isolated-declarations output — AI SDK validates at runtime.\ntype LooseTool = Tool<any, any>;\nimport { estimateFee as _estimateFee } from \"../actions/public/estimateFee.ts\";\nimport { getAccountInfo as _getAccountInfo } from \"../actions/public/getAccountInfo.ts\";\nimport { getBalance as _getBalance } from \"../actions/public/getBalance.ts\";\nimport { getBlock as _getBlock } from \"../actions/public/getBlock.ts\";\nimport { getBlockHeight as _getBlockHeight } from \"../actions/public/getBlockHeight.ts\";\nimport { readContract as _readContract } from \"../actions/public/readContract.ts\";\nimport {\n\tgetPrimaryName as _getPrimaryName,\n\tresolveName as _resolveName,\n} from \"../bns/actions.ts\";\nimport { type StacksReadClient, getDefaultPublicClient } from \"./client.ts\";\n\nconst PRINCIPAL = z\n\t.string()\n\t.describe(\"Stacks principal (SP…/SM… mainnet, ST… testnet)\");\n\n// --- Action wrappers bound to a client ---\n\nasync function stxBalance(client: StacksReadClient, principal: string) {\n\tconst balance = await _getBalance(client, { address: principal });\n\treturn { microStx: balance.toString() };\n}\n\nasync function accountInfo(client: StacksReadClient, principal: string) {\n\tconst info = await _getAccountInfo(client, { address: principal });\n\treturn {\n\t\tbalance: info.balance.toString(),\n\t\tnonce: info.nonce.toString(),\n\t};\n}\n\nasync function block(\n\tclient: StacksReadClient,\n\targs: { height?: number; hash?: string },\n) {\n\treturn _getBlock(client, args);\n}\n\nasync function blockHeight(client: StacksReadClient) {\n\treturn { height: await _getBlockHeight(client) };\n}\n\nasync function contractRead(\n\tclient: StacksReadClient,\n\targs: { contract: string; functionName: string; sender?: string },\n) {\n\tconst result = await _readContract(client, args);\n\treturn { result: JSON.stringify(result) };\n}\n\nasync function fee(client: StacksReadClient, serializedTxHex: string) {\n\tconst raw = serializedTxHex.startsWith(\"0x\")\n\t\t? serializedTxHex.slice(2)\n\t\t: serializedTxHex;\n\tconst txBytes = new Uint8Array(Buffer.from(raw, \"hex\"));\n\tconst { deserializeTransaction } = await import(\"@stacks/transactions\");\n\tconst transaction = deserializeTransaction(txBytes);\n\tconst fees = await _estimateFee(client, {\n\t\ttransaction: transaction as never,\n\t});\n\treturn {\n\t\tlow: fees[0]?.fee ?? 0,\n\t\tmedium: fees[1]?.fee ?? 0,\n\t\thigh: fees[2]?.fee ?? 0,\n\t};\n}\n\nasync function bnsResolveImpl(client: StacksReadClient, name: string) {\n\treturn { owner: await _resolveName(client, name) };\n}\n\nasync function bnsReverseImpl(client: StacksReadClient, principal: string) {\n\treturn { name: await _getPrimaryName(client, principal) };\n}\n\n// --- Hiro API-backed tools (extended endpoints beyond /v2) ---\n\nfunction hiroBase(client: StacksReadClient): string {\n\tconst url =\n\t\tclient.chain?.rpcUrls.default.http[0] ??\n\t\tprocess.env.STACKS_RPC_URL ??\n\t\t\"https://api.hiro.so\";\n\treturn url.replace(/\\/$/, \"\");\n}\n\nasync function hiroGet<T>(client: StacksReadClient, path: string): Promise<T> {\n\tconst res = await fetch(`${hiroBase(client)}${path}`, {\n\t\theaders: { Accept: \"application/json\" },\n\t});\n\tif (!res.ok) {\n\t\tthrow new Error(`Hiro API ${path} → ${res.status} ${res.statusText}`);\n\t}\n\treturn res.json() as Promise<T>;\n}\n\nasync function transactionByTxId(client: StacksReadClient, txId: string) {\n\tconst normalized = txId.startsWith(\"0x\") ? txId : `0x${txId}`;\n\treturn hiroGet<unknown>(client, `/extended/v1/tx/${normalized}`);\n}\n\nasync function accountHistory(\n\tclient: StacksReadClient,\n\tprincipal: string,\n\tlimit: number,\n) {\n\treturn hiroGet<{ results: unknown[]; total: number }>(\n\t\tclient,\n\t\t`/extended/v2/addresses/${principal}/transactions?limit=${Math.min(limit, 50)}`,\n\t);\n}\n\nasync function mempoolStats(client: StacksReadClient) {\n\treturn hiroGet<unknown>(client, \"/extended/v1/tx/mempool/stats\");\n}\n\nasync function nftHoldings(\n\tclient: StacksReadClient,\n\tprincipal: string,\n\tlimit: number,\n) {\n\treturn hiroGet<{ results: unknown[]; total: number }>(\n\t\tclient,\n\t\t`/extended/v1/tokens/nft/holdings?principal=${encodeURIComponent(principal)}&limit=${Math.min(limit, 50)}`,\n\t);\n}\n\n// --- Factory: bind tools to an explicit client ---\n\nexport interface StacksTools {\n\tgetStxBalance: LooseTool;\n\tgetAccountInfo: LooseTool;\n\tgetBlock: LooseTool;\n\tgetBlockHeight: LooseTool;\n\treadContract: LooseTool;\n\testimateFee: LooseTool;\n\tbnsResolve: LooseTool;\n\tbnsReverse: LooseTool;\n\tgetTransaction: LooseTool;\n\tgetAccountHistory: LooseTool;\n\tgetMempoolStats: LooseTool;\n\tgetNftHoldings: LooseTool;\n}\n\nexport function createStacksTools(client: StacksReadClient): StacksTools {\n\treturn {\n\t\tgetStxBalance: tool({\n\t\t\tdescription: \"Get the STX balance (in micro-STX) for a Stacks principal.\",\n\t\t\tinputSchema: z.object({ principal: PRINCIPAL }),\n\t\t\texecute: ({ principal }) => stxBalance(client, principal),\n\t\t}),\n\t\tgetAccountInfo: tool({\n\t\t\tdescription:\n\t\t\t\t\"Get account info (balance, locked, nonce) for a Stacks principal.\",\n\t\t\tinputSchema: z.object({ principal: PRINCIPAL }),\n\t\t\texecute: ({ principal }) => accountInfo(client, principal),\n\t\t}),\n\t\tgetBlock: tool({\n\t\t\tdescription:\n\t\t\t\t\"Fetch a Stacks block by height or hash. Omit both for the latest block.\",\n\t\t\tinputSchema: z.object({\n\t\t\t\theight: z.number().int().nonnegative().optional(),\n\t\t\t\thash: z.string().optional(),\n\t\t\t}),\n\t\t\texecute: (args) => block(client, args),\n\t\t}),\n\t\tgetBlockHeight: tool({\n\t\t\tdescription: \"Get the current Stacks chain tip height.\",\n\t\t\tinputSchema: z.object({}),\n\t\t\texecute: () => blockHeight(client),\n\t\t}),\n\t\treadContract: tool({\n\t\t\tdescription:\n\t\t\t\t\"Call a read-only Clarity function. Returns the decoded value as JSON.\",\n\t\t\tinputSchema: z.object({\n\t\t\t\tcontract: z\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\"Fully-qualified contract id: '{address}.{name}'\"),\n\t\t\t\tfunctionName: z.string(),\n\t\t\t\tsender: PRINCIPAL.optional(),\n\t\t\t}),\n\t\t\texecute: (args) => contractRead(client, args),\n\t\t}),\n\t\testimateFee: tool({\n\t\t\tdescription:\n\t\t\t\t\"Estimate fee range (low / medium / high) for a serialized Stacks transaction.\",\n\t\t\tinputSchema: z.object({\n\t\t\t\tserializedTxHex: z\n\t\t\t\t\t.string()\n\t\t\t\t\t.describe(\"Hex-encoded serialized transaction\"),\n\t\t\t}),\n\t\t\texecute: ({ serializedTxHex }) => fee(client, serializedTxHex),\n\t\t}),\n\t\tbnsResolve: tool({\n\t\t\tdescription:\n\t\t\t\t\"Resolve a BNS name (e.g. 'satoshi.btc') to its owning Stacks principal.\",\n\t\t\tinputSchema: z.object({\n\t\t\t\tname: z.string().describe(\"BNS name in 'name.namespace' form\"),\n\t\t\t}),\n\t\t\texecute: ({ name }) => bnsResolveImpl(client, name),\n\t\t}),\n\t\tbnsReverse: tool({\n\t\t\tdescription:\n\t\t\t\t\"Reverse-lookup the primary BNS name for a Stacks principal, if set.\",\n\t\t\tinputSchema: z.object({ principal: PRINCIPAL }),\n\t\t\texecute: ({ principal }) => bnsReverseImpl(client, principal),\n\t\t}),\n\t\tgetTransaction: tool({\n\t\t\tdescription:\n\t\t\t\t\"Fetch a confirmed Stacks transaction by txId (Hiro extended API).\",\n\t\t\tinputSchema: z.object({\n\t\t\t\ttxId: z.string().describe(\"Transaction id, with or without 0x prefix\"),\n\t\t\t}),\n\t\t\texecute: ({ txId }) => transactionByTxId(client, txId),\n\t\t}),\n\t\tgetAccountHistory: tool({\n\t\t\tdescription:\n\t\t\t\t\"Paginated transaction history for a Stacks principal (Hiro extended API).\",\n\t\t\tinputSchema: z.object({\n\t\t\t\tprincipal: PRINCIPAL,\n\t\t\t\tlimit: z.number().int().min(1).max(50).default(20),\n\t\t\t}),\n\t\t\texecute: ({ principal, limit }) =>\n\t\t\t\taccountHistory(client, principal, limit),\n\t\t}),\n\t\tgetMempoolStats: tool({\n\t\t\tdescription:\n\t\t\t\t\"Current mempool statistics: pending count, fee distribution, age buckets (Hiro extended API).\",\n\t\t\tinputSchema: z.object({}),\n\t\t\texecute: () => mempoolStats(client),\n\t\t}),\n\t\tgetNftHoldings: tool({\n\t\t\tdescription:\n\t\t\t\t\"NFT holdings for a Stacks principal across all collections (Hiro extended API).\",\n\t\t\tinputSchema: z.object({\n\t\t\t\tprincipal: PRINCIPAL,\n\t\t\t\tlimit: z.number().int().min(1).max(50).default(20),\n\t\t\t}),\n\t\t\texecute: ({ principal, limit }) => nftHoldings(client, principal, limit),\n\t\t}),\n\t};\n}\n\n\n// --- Bare exports using the default (env-configured) client ---\n\nexport const getStxBalance: LooseTool = tool({\n\tdescription:\n\t\t\"Get the STX balance (in micro-STX) for a Stacks principal. Uses default client.\",\n\tinputSchema: z.object({ principal: PRINCIPAL }),\n\texecute: ({ principal }) => stxBalance(getDefaultPublicClient(), principal),\n});\n\nexport const getAccountInfo: LooseTool = tool({\n\tdescription:\n\t\t\"Get account info (balance, locked, nonce) for a Stacks principal.\",\n\tinputSchema: z.object({ principal: PRINCIPAL }),\n\texecute: ({ principal }) => accountInfo(getDefaultPublicClient(), principal),\n});\n\nexport const getBlock: LooseTool = tool({\n\tdescription:\n\t\t\"Fetch a Stacks block by height or hash. Omit both for the latest block.\",\n\tinputSchema: z.object({\n\t\theight: z.number().int().nonnegative().optional(),\n\t\thash: z.string().optional(),\n\t}),\n\texecute: (args) => block(getDefaultPublicClient(), args),\n});\n\nexport const getBlockHeight: LooseTool = tool({\n\tdescription: \"Get the current Stacks chain tip height.\",\n\tinputSchema: z.object({}),\n\texecute: () => blockHeight(getDefaultPublicClient()),\n});\n\nexport const readContract: LooseTool = tool({\n\tdescription:\n\t\t\"Call a read-only Clarity function. Returns the decoded value as JSON.\",\n\tinputSchema: z.object({\n\t\tcontract: z.string(),\n\t\tfunctionName: z.string(),\n\t\tsender: PRINCIPAL.optional(),\n\t}),\n\texecute: (args) => contractRead(getDefaultPublicClient(), args),\n});\n\nexport const estimateFee: LooseTool = tool({\n\tdescription:\n\t\t\"Estimate fee range (low / medium / high) for a serialized Stacks transaction.\",\n\tinputSchema: z.object({ serializedTxHex: z.string() }),\n\texecute: ({ serializedTxHex }) =>\n\t\tfee(getDefaultPublicClient(), serializedTxHex),\n});\n\nexport const bnsResolve: LooseTool = tool({\n\tdescription:\n\t\t\"Resolve a BNS name (e.g. 'satoshi.btc') to its owning Stacks principal.\",\n\tinputSchema: z.object({ name: z.string() }),\n\texecute: ({ name }) => bnsResolveImpl(getDefaultPublicClient(), name),\n});\n\nexport const bnsReverse: LooseTool = tool({\n\tdescription:\n\t\t\"Reverse-lookup the primary BNS name for a Stacks principal, if set.\",\n\tinputSchema: z.object({ principal: PRINCIPAL }),\n\texecute: ({ principal }) =>\n\t\tbnsReverseImpl(getDefaultPublicClient(), principal),\n});\n\nexport const getTransaction: LooseTool = tool({\n\tdescription:\n\t\t\"Fetch a confirmed Stacks transaction by txId (Hiro extended API).\",\n\tinputSchema: z.object({ txId: z.string() }),\n\texecute: ({ txId }) => transactionByTxId(getDefaultPublicClient(), txId),\n});\n\nexport const getAccountHistory: LooseTool = tool({\n\tdescription:\n\t\t\"Paginated transaction history for a Stacks principal (Hiro extended API).\",\n\tinputSchema: z.object({\n\t\tprincipal: PRINCIPAL,\n\t\tlimit: z.number().int().min(1).max(50).default(20),\n\t}),\n\texecute: ({ principal, limit }) =>\n\t\taccountHistory(getDefaultPublicClient(), principal, limit),\n});\n\nexport const getMempoolStats: LooseTool = tool({\n\tdescription:\n\t\t\"Current mempool statistics: pending count, fee distribution, age buckets (Hiro extended API).\",\n\tinputSchema: z.object({}),\n\texecute: () => mempoolStats(getDefaultPublicClient()),\n});\n\nexport const getNftHoldings: LooseTool = tool({\n\tdescription:\n\t\t\"NFT holdings for a Stacks principal across all collections (Hiro extended API).\",\n\tinputSchema: z.object({\n\t\tprincipal: PRINCIPAL,\n\t\tlimit: z.number().int().min(1).max(50).default(20),\n\t}),\n\texecute: ({ principal, limit }) =>\n\t\tnftHoldings(getDefaultPublicClient(), principal, limit),\n});\n",
|
|
6
|
+
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex, hexToBytes } from \"./encoding.ts\";\n\nconst C32 = \"0123456789ABCDEFGHJKMNPQRSTVWXYZ\";\nconst HEX = \"0123456789abcdef\";\n\nfunction c32normalize(input: string): string {\n\treturn input.toUpperCase().replace(/O/g, \"0\").replace(/L|I/g, \"1\");\n}\n\nfunction c32encode(inputHex: string): string {\n\tif (inputHex.length % 2 !== 0) inputHex = `0${inputHex}`;\n\tinputHex = inputHex.toLowerCase();\n\n\tconst res: string[] = [];\n\tlet carry = 0;\n\tfor (let i = inputHex.length - 1; i >= 0; i--) {\n\t\tif (carry < 4) {\n\t\t\tconst currentCode = HEX.indexOf(inputHex[i]!) >> carry;\n\t\t\tconst nextCode = i !== 0 ? HEX.indexOf(inputHex[i - 1]!) : 0;\n\t\t\tconst nextBits = 1 + carry;\n\t\t\tconst nextLowBits = (nextCode % (1 << nextBits)) << (5 - nextBits);\n\t\t\tres.unshift(C32[currentCode + nextLowBits]!);\n\t\t\tcarry = nextBits;\n\t\t} else {\n\t\t\tcarry = 0;\n\t\t}\n\t}\n\n\t// Strip leading c32 zeros\n\tlet leadingZeros = 0;\n\twhile (leadingZeros < res.length && res[leadingZeros] === \"0\") leadingZeros++;\n\tconst stripped = res.slice(leadingZeros);\n\n\t// Preserve leading zero bytes from hex\n\tconst bytes = hexToBytes(inputHex);\n\tlet zeroBytesCount = 0;\n\twhile (zeroBytesCount < bytes.length && bytes[zeroBytesCount] === 0)\n\t\tzeroBytesCount++;\n\tconst prefix = Array(zeroBytesCount).fill(C32[0]) as string[];\n\n\treturn [...prefix, ...stripped].join(\"\");\n}\n\nfunction c32decode(c32input: string): string {\n\tc32input = c32normalize(c32input);\n\tif (!c32input.match(`^[${C32}]*$`))\n\t\tthrow new Error(\"Not a c32-encoded string\");\n\n\tconst zeroPrefix = c32input.match(`^${C32[0]}*`);\n\tconst numLeadingZeroBytes = zeroPrefix ? zeroPrefix[0]!.length : 0;\n\n\tconst res: string[] = [];\n\tlet carry = 0;\n\tlet carryBits = 0;\n\tfor (let i = c32input.length - 1; i >= 0; i--) {\n\t\tif (carryBits === 4) {\n\t\t\tres.unshift(HEX[carry]!);\n\t\t\tcarryBits = 0;\n\t\t\tcarry = 0;\n\t\t}\n\t\tconst currentValue = (C32.indexOf(c32input[i]!) << carryBits) + carry;\n\t\tres.unshift(HEX[currentValue % 16]!);\n\t\tcarryBits += 1;\n\t\tcarry = currentValue >> 4;\n\t\tif (carry > 1 << carryBits) throw new Error(\"Panic error in c32 decoding\");\n\t}\n\tres.unshift(HEX[carry]!);\n\n\tif (res.length % 2 === 1) res.unshift(\"0\");\n\n\t// Strip leading hex zeros\n\tlet hexLeadingZeros = 0;\n\twhile (hexLeadingZeros < res.length && res[hexLeadingZeros] === \"0\")\n\t\thexLeadingZeros++;\n\tlet hexStr = res.slice(hexLeadingZeros - (hexLeadingZeros % 2)).join(\"\");\n\n\tfor (let i = 0; i < numLeadingZeroBytes; i++) hexStr = `00${hexStr}`;\n\n\treturn hexStr;\n}\n\nfunction c32checksum(dataHex: string): string {\n\treturn bytesToHex(sha256(sha256(hexToBytes(dataHex))).slice(0, 4));\n}\n\nfunction c32checkEncode(version: number, data: string): string {\n\tif (version < 0 || version >= 32)\n\t\tthrow new Error(\"Invalid version (must be between 0 and 31)\");\n\tif (!data.match(/^[0-9a-fA-F]*$/))\n\t\tthrow new Error(\"Invalid data (not a hex string)\");\n\n\tdata = data.toLowerCase();\n\tif (data.length % 2 !== 0) data = `0${data}`;\n\n\tlet versionHex = version.toString(16);\n\tif (versionHex.length === 1) versionHex = `0${versionHex}`;\n\n\tconst checksumHex = c32checksum(`${versionHex}${data}`);\n\treturn `${C32[version]}${c32encode(`${data}${checksumHex}`)}`;\n}\n\nfunction c32checkDecode(c32data: string): [number, string] {\n\tc32data = c32normalize(c32data);\n\tconst dataHex = c32decode(c32data.slice(1));\n\tconst version = C32.indexOf(c32data[0]!);\n\tconst checksum = dataHex.slice(-8);\n\n\tlet versionHex = version.toString(16);\n\tif (versionHex.length === 1) versionHex = `0${versionHex}`;\n\n\tif (\n\t\tc32checksum(`${versionHex}${dataHex.substring(0, dataHex.length - 8)}`) !==\n\t\tchecksum\n\t) {\n\t\tthrow new Error(\"Invalid c32check string: checksum mismatch\");\n\t}\n\n\treturn [version, dataHex.substring(0, dataHex.length - 8)];\n}\n\nexport function c32address(version: number, hash160hex: string): string {\n\tif (!hash160hex.match(/^[0-9a-fA-F]{40}$/)) {\n\t\tthrow new Error(\"Invalid argument: not a hash160 hex string\");\n\t}\n\treturn `S${c32checkEncode(version, hash160hex)}`;\n}\n\nexport function c32addressDecode(c32addr: string): [number, string] {\n\tif (c32addr.length <= 5)\n\t\tthrow new Error(\"Invalid c32 address: invalid length\");\n\tif (c32addr[0] !== \"S\")\n\t\tthrow new Error('Invalid c32 address: must start with \"S\"');\n\treturn c32checkDecode(c32addr.slice(1));\n}\n",
|
|
7
|
+
"const hexes = Array.from({ length: 256 }, (_, i) =>\n\ti.toString(16).padStart(2, \"0\"),\n);\n\nexport function bytesToHex(bytes: Uint8Array): string {\n\tlet hex = \"\";\n\tfor (const b of bytes) {\n\t\thex += hexes[b];\n\t}\n\treturn hex;\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n\thex = without0x(hex);\n\tif (hex.length % 2) hex = `0${hex}`;\n\n\tconst array = new Uint8Array(hex.length / 2);\n\tfor (let i = 0; i < array.length; i++) {\n\t\tconst j = i * 2;\n\t\tconst byte = Number.parseInt(hex.slice(j, j + 2), 16);\n\t\tif (Number.isNaN(byte) || byte < 0)\n\t\t\tthrow new Error(\"Invalid byte sequence\");\n\t\tarray[i] = byte;\n\t}\n\treturn array;\n}\n\nexport function with0x(value: string): string {\n\treturn /^0x/i.test(value) ? value : `0x${value}`;\n}\n\nexport function without0x(value: string): string {\n\treturn /^0x/i.test(value) ? value.slice(2) : value;\n}\n\nexport function utf8ToBytes(str: string): Uint8Array {\n\treturn new TextEncoder().encode(str);\n}\n\nexport function bytesToUtf8(bytes: Uint8Array): string {\n\treturn new TextDecoder().decode(bytes);\n}\n\nexport function asciiToBytes(str: string): Uint8Array {\n\tconst bytes = new Uint8Array(str.length);\n\tfor (let i = 0; i < str.length; i++) {\n\t\tbytes[i] = str.charCodeAt(i) & 0xff;\n\t}\n\treturn bytes;\n}\n\nexport function bytesToAscii(bytes: Uint8Array): string {\n\treturn String.fromCharCode(...bytes);\n}\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n\tif (arrays.length === 1) return arrays[0]!;\n\tconst length = arrays.reduce((a, arr) => a + arr.length, 0);\n\tconst result = new Uint8Array(length);\n\tlet pad = 0;\n\tfor (const arr of arrays) {\n\t\tresult.set(arr, pad);\n\t\tpad += arr.length;\n\t}\n\treturn result;\n}\n\nexport type IntegerType = number | string | bigint | Uint8Array;\n\nexport function intToBigInt(value: IntegerType): bigint {\n\tif (typeof value === \"bigint\") return value;\n\tif (typeof value === \"string\") return BigInt(value);\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isInteger(value))\n\t\t\tthrow new RangeError(\"Values of type 'number' must be an integer.\");\n\t\tif (value > Number.MAX_SAFE_INTEGER)\n\t\t\tthrow new RangeError(\n\t\t\t\t`Values of type 'number' must be <= ${Number.MAX_SAFE_INTEGER}. Use BigInt instead.`,\n\t\t\t);\n\t\treturn BigInt(value);\n\t}\n\tif (value instanceof Uint8Array) return BigInt(`0x${bytesToHex(value)}`);\n\tthrow new TypeError(\"Must be a number, bigint, string, or Uint8Array.\");\n}\n\nexport function intToBytes(value: IntegerType, byteLength: number): Uint8Array {\n\treturn bigIntToBytes(intToBigInt(value), byteLength);\n}\n\nexport function bigIntToBytes(value: bigint, length = 16): Uint8Array {\n\tconst hex = value.toString(16).padStart(length * 2, \"0\");\n\treturn hexToBytes(hex);\n}\n\nexport function intToHex(integer: IntegerType, byteLength = 8): string {\n\tconst value = typeof integer === \"bigint\" ? integer : intToBigInt(integer);\n\treturn value.toString(16).padStart(byteLength * 2, \"0\");\n}\n\nexport function toTwos(value: bigint, width: bigint): bigint {\n\tconst limit = BigInt(1) << (width - BigInt(1));\n\tif (value < -limit || value > limit - BigInt(1)) {\n\t\tthrow new Error(`Unable to represent integer in width: ${width}`);\n\t}\n\tif (value >= BigInt(0)) return value;\n\treturn value + (BigInt(1) << width);\n}\n\nexport function fromTwos(value: bigint, width: bigint): bigint {\n\tif (value & (BigInt(1) << (width - BigInt(1)))) {\n\t\treturn value - (BigInt(1) << width);\n\t}\n\treturn value;\n}\n\nexport function bytesToTwosBigInt(bytes: Uint8Array): bigint {\n\tif (bytes.length === 0) return 0n;\n\tconst hex = bytesToHex(bytes);\n\tif (hex.length === 0) return 0n;\n\treturn fromTwos(BigInt(`0x${hex}`), BigInt(bytes.byteLength * 8));\n}\n\nexport function writeUInt32BE(value: number): Uint8Array {\n\tconst buf = new Uint8Array(4);\n\tbuf[0] = (value >>> 24) & 0xff;\n\tbuf[1] = (value >>> 16) & 0xff;\n\tbuf[2] = (value >>> 8) & 0xff;\n\tbuf[3] = value & 0xff;\n\treturn buf;\n}\n\nexport function readUInt32BE(bytes: Uint8Array, offset = 0): number {\n\treturn (\n\t\t((bytes[offset]! << 24) |\n\t\t\t(bytes[offset + 1]! << 16) |\n\t\t\t(bytes[offset + 2]! << 8) |\n\t\t\tbytes[offset + 3]!) >>>\n\t\t0\n\t);\n}\n\nexport function writeUInt16BE(value: number): Uint8Array {\n\tconst buf = new Uint8Array(2);\n\tbuf[0] = (value >>> 8) & 0xff;\n\tbuf[1] = value & 0xff;\n\treturn buf;\n}\n\nexport function readUInt16BE(bytes: Uint8Array, offset = 0): number {\n\treturn ((bytes[offset]! << 8) | bytes[offset + 1]!) >>> 0;\n}\n\nexport function writeUInt8(value: number): Uint8Array {\n\treturn new Uint8Array([value & 0xff]);\n}\n",
|
|
8
|
+
"export type ClarityType =\n\t| \"int\"\n\t| \"uint\"\n\t| \"buffer\"\n\t| \"true\"\n\t| \"false\"\n\t| \"address\"\n\t| \"contract\"\n\t| \"ok\"\n\t| \"err\"\n\t| \"none\"\n\t| \"some\"\n\t| \"list\"\n\t| \"tuple\"\n\t| \"ascii\"\n\t| \"utf8\";\n\n/** Wire type IDs matching the Stacks binary format (SIP-005) */\nexport const ClarityWireType = {\n\tint: 0x00,\n\tuint: 0x01,\n\tbuffer: 0x02,\n\ttrue: 0x03,\n\tfalse: 0x04,\n\taddress: 0x05,\n\tcontract: 0x06,\n\tok: 0x07,\n\terr: 0x08,\n\tnone: 0x09,\n\tsome: 0x0a,\n\tlist: 0x0b,\n\ttuple: 0x0c,\n\tascii: 0x0d,\n\tutf8: 0x0e,\n} as const satisfies Record<ClarityType, number>;\n\n/** Reverse lookup: wire byte → ClarityType string */\nconst wireTypeToClarity = Object.fromEntries(\n\tObject.entries(ClarityWireType).map(([k, v]) => [v, k]),\n) as Record<number, ClarityType>;\n\nexport function clarityTypeFromByte(byte: number): ClarityType {\n\tconst type = wireTypeToClarity[byte];\n\tif (!type) throw new Error(`Unknown clarity wire type: ${byte}`);\n\treturn type;\n}\n\n// CV types\n\nexport type IntCV = { readonly type: \"int\"; readonly value: bigint };\nexport type UIntCV = { readonly type: \"uint\"; readonly value: bigint };\nexport type BooleanCV = TrueCV | FalseCV;\nexport type TrueCV = { readonly type: \"true\" };\nexport type FalseCV = { readonly type: \"false\" };\nexport type BufferCV = { readonly type: \"buffer\"; readonly value: string }; // hex\nexport type NoneCV = { readonly type: \"none\" };\nexport type SomeCV = {\n\treadonly type: \"some\";\n\treadonly value: ClarityValue;\n};\nexport type OptionalCV = NoneCV | SomeCV;\nexport type ResponseOkCV = {\n\treadonly type: \"ok\";\n\treadonly value: ClarityValue;\n};\nexport type ResponseErrorCV = {\n\treadonly type: \"err\";\n\treadonly value: ClarityValue;\n};\nexport type ResponseCV = ResponseOkCV | ResponseErrorCV;\nexport type StandardPrincipalCV = {\n\treadonly type: \"address\";\n\treadonly value: string;\n};\nexport type ContractPrincipalCV = {\n\treadonly type: \"contract\";\n\treadonly value: string; // \"address.name\"\n};\nexport type PrincipalCV = StandardPrincipalCV | ContractPrincipalCV;\nexport type ListCV = {\n\ttype: \"list\";\n\tvalue: ClarityValue[];\n};\nexport type TupleData = {\n\t[key: string]: ClarityValue;\n};\nexport type TupleCV = {\n\ttype: \"tuple\";\n\tvalue: TupleData;\n};\nexport type StringAsciiCV = {\n\treadonly type: \"ascii\";\n\treadonly value: string;\n};\nexport type StringUtf8CV = {\n\treadonly type: \"utf8\";\n\treadonly value: string;\n};\n\nexport type ClarityValue =\n\t| IntCV\n\t| UIntCV\n\t| BooleanCV\n\t| BufferCV\n\t| NoneCV\n\t| SomeCV\n\t| ResponseOkCV\n\t| ResponseErrorCV\n\t| StandardPrincipalCV\n\t| ContractPrincipalCV\n\t| ListCV\n\t| TupleCV\n\t| StringAsciiCV\n\t| StringUtf8CV;\n",
|
|
9
|
+
"import { c32addressDecode } from \"../utils/c32.ts\";\nimport {\n\tasciiToBytes,\n\tbigIntToBytes,\n\tbytesToHex,\n\tconcatBytes,\n\thexToBytes,\n\tintToHex,\n\ttoTwos,\n\tutf8ToBytes,\n\twriteUInt32BE,\n} from \"../utils/encoding.ts\";\nimport {\n\ttype ClarityType,\n\ttype ClarityValue,\n\tClarityWireType,\n} from \"./types.ts\";\n\nconst CLARITY_INT_SIZE = 128n;\nconst CLARITY_INT_BYTE_SIZE = 16;\n\nfunction typeIdByte(type: ClarityType): number {\n\treturn ClarityWireType[type];\n}\n\nfunction withTypeId(type: ClarityType, bytes: Uint8Array): Uint8Array {\n\treturn concatBytes(new Uint8Array([typeIdByte(type)]), bytes);\n}\n\nfunction serializeAddress(c32Address: string): Uint8Array {\n\tconst [version, hash160] = c32addressDecode(c32Address);\n\treturn concatBytes(new Uint8Array([version]), hexToBytes(hash160));\n}\n\nfunction serializeLPString(str: string, prefixBytes = 1): Uint8Array {\n\tconst content = utf8ToBytes(str);\n\tconst lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));\n\treturn concatBytes(lengthPrefix, content);\n}\n\nexport function serializeCVBytes(value: ClarityValue): Uint8Array {\n\tswitch (value.type) {\n\t\tcase \"true\":\n\t\tcase \"false\":\n\t\t\treturn new Uint8Array([typeIdByte(value.type)]);\n\n\t\tcase \"int\": {\n\t\t\tconst bytes = bigIntToBytes(\n\t\t\t\ttoTwos(BigInt(value.value), CLARITY_INT_SIZE),\n\t\t\t\tCLARITY_INT_BYTE_SIZE,\n\t\t\t);\n\t\t\treturn withTypeId(value.type, bytes);\n\t\t}\n\n\t\tcase \"uint\": {\n\t\t\tconst bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);\n\t\t\treturn withTypeId(value.type, bytes);\n\t\t}\n\n\t\tcase \"buffer\": {\n\t\t\tconst bufBytes = hexToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(bufBytes.length), bufBytes),\n\t\t\t);\n\t\t}\n\n\t\tcase \"none\":\n\t\t\treturn new Uint8Array([typeIdByte(value.type)]);\n\n\t\tcase \"some\":\n\t\t\treturn withTypeId(value.type, serializeCVBytes(value.value));\n\n\t\tcase \"ok\":\n\t\tcase \"err\":\n\t\t\treturn withTypeId(value.type, serializeCVBytes(value.value));\n\n\t\tcase \"address\":\n\t\t\treturn withTypeId(value.type, serializeAddress(value.value));\n\n\t\tcase \"contract\": {\n\t\t\tconst [addr, name] = value.value.split(\".\");\n\t\t\tif (!addr || !name)\n\t\t\t\tthrow new Error(`Invalid contract principal: ${value.value}`);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(serializeAddress(addr), serializeLPString(name)),\n\t\t\t);\n\t\t}\n\n\t\tcase \"list\": {\n\t\t\tconst parts: Uint8Array[] = [writeUInt32BE(value.value.length)];\n\t\t\tfor (const item of value.value) {\n\t\t\t\tparts.push(serializeCVBytes(item));\n\t\t\t}\n\t\t\treturn withTypeId(value.type, concatBytes(...parts));\n\t\t}\n\n\t\tcase \"tuple\": {\n\t\t\tconst keys = Object.keys(value.value).sort((a, b) => a.localeCompare(b));\n\t\t\tconst parts: Uint8Array[] = [writeUInt32BE(keys.length)];\n\t\t\tfor (const key of keys) {\n\t\t\t\tparts.push(serializeLPString(key));\n\t\t\t\tparts.push(serializeCVBytes(value.value[key]!));\n\t\t\t}\n\t\t\treturn withTypeId(value.type, concatBytes(...parts));\n\t\t}\n\n\t\tcase \"ascii\": {\n\t\t\tconst strBytes = asciiToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(strBytes.length), strBytes),\n\t\t\t);\n\t\t}\n\n\t\tcase \"utf8\": {\n\t\t\tconst strBytes = utf8ToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(strBytes.length), strBytes),\n\t\t\t);\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot serialize unknown clarity type`);\n\t}\n}\n\nexport function serializeCV(value: ClarityValue): string {\n\treturn bytesToHex(serializeCVBytes(value));\n}\n",
|
|
10
|
+
"import type { ClarityValue } from \"../clarity/types.ts\";\n\n// Auth types\nexport const AuthType = {\n\tStandard: 0x04,\n\tSponsored: 0x05,\n} as const;\nexport type AuthType = (typeof AuthType)[keyof typeof AuthType];\n\n// Payload types\nexport const PayloadType = {\n\tTokenTransfer: 0x00,\n\tSmartContract: 0x01,\n\tContractCall: 0x02,\n\tPoisonMicroblock: 0x03,\n\tCoinbase: 0x04,\n\tCoinbaseToAltRecipient: 0x05,\n\tVersionedSmartContract: 0x06,\n\tTenureChange: 0x07,\n\tNakamotoCoinbase: 0x08,\n} as const;\nexport type PayloadType = (typeof PayloadType)[keyof typeof PayloadType];\n\n// Clarity version\nexport const ClarityVersion = {\n\tClarity1: 1,\n\tClarity2: 2,\n\tClarity3: 3,\n\tClarity4: 4,\n\tClarity5: 5,\n} as const;\nexport type ClarityVersion =\n\t(typeof ClarityVersion)[keyof typeof ClarityVersion];\n\n// Anchor mode (deprecated post-Nakamoto, but needed for wire format)\nexport const AnchorMode = {\n\tOnChainOnly: 0x01,\n\tOffChainOnly: 0x02,\n\tAny: 0x03,\n} as const;\nexport type AnchorMode = (typeof AnchorMode)[keyof typeof AnchorMode];\n\n// Post condition mode\nexport const PostConditionModeWire = {\n\tAllow: 0x01,\n\tDeny: 0x02,\n} as const;\nexport type PostConditionModeWire =\n\t(typeof PostConditionModeWire)[keyof typeof PostConditionModeWire];\n\n// Address hash modes\nexport const AddressHashMode = {\n\tP2PKH: 0x00,\n\tP2SH: 0x01,\n\tP2WPKH: 0x02,\n\tP2WSH: 0x03,\n\tP2SH_NonSequential: 0x05, // SIP-027\n\tP2WSH_P2SH_NonSequential: 0x07, // SIP-027\n} as const;\nexport type AddressHashMode =\n\t(typeof AddressHashMode)[keyof typeof AddressHashMode];\n\n// Pub key encoding\nexport const PubKeyEncoding = {\n\tCompressed: 0x00,\n\tUncompressed: 0x01,\n} as const;\nexport type PubKeyEncoding =\n\t(typeof PubKeyEncoding)[keyof typeof PubKeyEncoding];\n\n// Fungible condition codes (wire format)\nexport const FungibleConditionCode = {\n\tEqual: 0x01,\n\tGreater: 0x02,\n\tGreaterEqual: 0x03,\n\tLess: 0x04,\n\tLessEqual: 0x05,\n} as const;\n\n// Non-fungible condition codes (wire format)\nexport const NonFungibleConditionCode = {\n\tSends: 0x10,\n\tDoesNotSend: 0x11,\n} as const;\n\n// Post condition principal types\nexport const PostConditionPrincipalId = {\n\tOrigin: 0x01,\n\tStandard: 0x02,\n\tContract: 0x03,\n} as const;\n\n// Post condition asset types\nexport const AssetType = {\n\tSTX: 0x00,\n\tFungible: 0x01,\n\tNonFungible: 0x02,\n} as const;\n\n// Auth field types\nexport const AuthFieldType = {\n\tPublicKeyCompressed: 0x00,\n\tPublicKeyUncompressed: 0x01,\n\tSignatureCompressed: 0x02,\n\tSignatureUncompressed: 0x03,\n} as const;\n\nexport const RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;\nexport const MEMO_MAX_LENGTH_BYTES = 34;\nexport const MAX_STRING_LENGTH_BYTES = 128;\nexport const COINBASE_BYTES_LENGTH = 32;\nexport const VRF_PROOF_BYTES_LENGTH = 80;\nexport const MICROBLOCK_HEADER_BYTES_LENGTH = 132; // 1 + 2 + 32 + 32 + 65\n\n// Tenure change cause\nexport const TenureChangeCause = {\n\tBlockFound: 0x00,\n\tExtended: 0x01,\n\tExtendedRuntime: 0x02,\n\tExtendedReadCount: 0x03,\n\tExtendedReadLength: 0x04,\n\tExtendedWriteCount: 0x05,\n\tExtendedWriteLength: 0x06,\n} as const;\nexport type TenureChangeCause =\n\t(typeof TenureChangeCause)[keyof typeof TenureChangeCause];\n\n// Token transfer payload\nexport type TokenTransferPayload = {\n\tpayloadType: typeof PayloadType.TokenTransfer;\n\trecipient: ClarityValue; // PrincipalCV\n\tamount: bigint;\n\tmemo: string;\n};\n\n// Contract call payload\nexport type ContractCallPayload = {\n\tpayloadType: typeof PayloadType.ContractCall;\n\tcontractAddress: string;\n\tcontractName: string;\n\tfunctionName: string;\n\tfunctionArgs: ClarityValue[];\n};\n\n// Smart contract deploy payload\nexport type SmartContractPayload = {\n\tpayloadType:\n\t\t| typeof PayloadType.SmartContract\n\t\t| typeof PayloadType.VersionedSmartContract;\n\tclarityVersion?: ClarityVersion;\n\tcontractName: string;\n\tcodeBody: string;\n};\n\n// Coinbase payload (appears in every pre-Nakamoto block)\nexport type CoinbasePayload = {\n\tpayloadType: typeof PayloadType.Coinbase;\n\tcoinbaseBuffer: string; // 32 bytes hex\n};\n\n// Coinbase to alt recipient payload\nexport type CoinbaseToAltRecipientPayload = {\n\tpayloadType: typeof PayloadType.CoinbaseToAltRecipient;\n\tcoinbaseBuffer: string; // 32 bytes hex\n\trecipient: ClarityValue; // PrincipalCV\n};\n\n// Poison microblock payload\nexport type PoisonMicroblockPayload = {\n\tpayloadType: typeof PayloadType.PoisonMicroblock;\n\theader1: string; // 132 bytes hex (raw microblock header)\n\theader2: string; // 132 bytes hex (raw microblock header)\n};\n\n// Tenure change payload (Nakamoto)\nexport type TenureChangePayload = {\n\tpayloadType: typeof PayloadType.TenureChange;\n\ttenureConsensusHash: string; // 20 bytes hex\n\tprevTenureConsensusHash: string; // 20 bytes hex\n\tburnViewConsensusHash: string; // 20 bytes hex\n\tpreviousTenureEnd: string; // 32 bytes hex\n\tpreviousTenureBlocks: number; // u32\n\tcause: TenureChangeCause;\n\tpubkeyHash: string; // 20 bytes hex\n};\n\n// Nakamoto coinbase payload\nexport type NakamotoCoinbasePayload = {\n\tpayloadType: typeof PayloadType.NakamotoCoinbase;\n\tcoinbaseBuffer: string; // 32 bytes hex\n\trecipient: ClarityValue | null; // Optional PrincipalCV\n\tvrfProof: string; // 80 bytes hex\n};\n\nexport type TransactionPayload =\n\t| TokenTransferPayload\n\t| ContractCallPayload\n\t| SmartContractPayload\n\t| CoinbasePayload\n\t| CoinbaseToAltRecipientPayload\n\t| PoisonMicroblockPayload\n\t| TenureChangePayload\n\t| NakamotoCoinbasePayload;\n\n// Spending condition\nexport type SingleSigSpendingCondition = {\n\thashMode: typeof AddressHashMode.P2PKH | typeof AddressHashMode.P2WPKH;\n\tsigner: string; // hash160 hex\n\tnonce: bigint;\n\tfee: bigint;\n\tkeyEncoding: PubKeyEncoding;\n\tsignature: string; // 65-byte recoverable sig hex\n};\n\nexport type TransactionAuthField = {\n\tpubKeyEncoding: PubKeyEncoding;\n\ttype: \"publicKey\" | \"signature\";\n\tdata: string; // hex\n};\n\nexport type MultiSigHashMode =\n\t| typeof AddressHashMode.P2SH\n\t| typeof AddressHashMode.P2WSH\n\t| typeof AddressHashMode.P2SH_NonSequential\n\t| typeof AddressHashMode.P2WSH_P2SH_NonSequential;\n\nexport type MultiSigSpendingCondition = {\n\thashMode: MultiSigHashMode;\n\tsigner: string;\n\tnonce: bigint;\n\tfee: bigint;\n\tfields: TransactionAuthField[];\n\tsignaturesRequired: number;\n};\n\nexport type SpendingCondition =\n\t| SingleSigSpendingCondition\n\t| MultiSigSpendingCondition;\n\nexport type StandardAuthorization = {\n\tauthType: typeof AuthType.Standard;\n\tspendingCondition: SpendingCondition;\n};\n\nexport type SponsoredAuthorization = {\n\tauthType: typeof AuthType.Sponsored;\n\tspendingCondition: SpendingCondition;\n\tsponsorSpendingCondition: SpendingCondition;\n};\n\nexport type Authorization = StandardAuthorization | SponsoredAuthorization;\n\n// Full transaction\nexport type StacksTransaction = {\n\tversion: number;\n\tchainId: number;\n\tauth: Authorization;\n\tanchorMode: AnchorMode;\n\tpostConditionMode: PostConditionModeWire;\n\tpostConditions: PostConditionWire[];\n\tpayload: TransactionPayload;\n};\n\n// Wire post condition types\nexport type PostConditionWire =\n\t| StxPostConditionWire\n\t| FtPostConditionWire\n\t| NftPostConditionWire;\n\nexport type StxPostConditionWire = {\n\ttype: \"stx\";\n\tprincipal: PostConditionPrincipalWire;\n\tconditionCode: number;\n\tamount: bigint;\n};\n\nexport type FtPostConditionWire = {\n\ttype: \"ft\";\n\tprincipal: PostConditionPrincipalWire;\n\tasset: AssetInfoWire;\n\tconditionCode: number;\n\tamount: bigint;\n};\n\nexport type NftPostConditionWire = {\n\ttype: \"nft\";\n\tprincipal: PostConditionPrincipalWire;\n\tasset: AssetInfoWire;\n\tconditionCode: number;\n\tassetId: ClarityValue;\n};\n\nexport type PostConditionPrincipalWire =\n\t| { type: \"origin\" }\n\t| { type: \"standard\"; address: string }\n\t| { type: \"contract\"; address: string; contractName: string };\n\nexport type AssetInfoWire = {\n\taddress: string;\n\tcontractName: string;\n\tassetName: string;\n};\n",
|
|
11
|
+
"import { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport { c32addressDecode } from \"../../utils/c32.ts\";\nimport {\n\tasciiToBytes,\n\tbytesToHex,\n\tconcatBytes,\n\thexToBytes,\n\tintToBytes,\n\tintToHex,\n\tutf8ToBytes,\n\twriteUInt8,\n\twriteUInt16BE,\n\twriteUInt32BE,\n} from \"../../utils/encoding.ts\";\nimport {\n\ttype AssetInfoWire,\n\tAssetType,\n\tAuthType,\n\ttype Authorization,\n\ttype CoinbasePayload,\n\ttype CoinbaseToAltRecipientPayload,\n\tMEMO_MAX_LENGTH_BYTES,\n\ttype MultiSigSpendingCondition,\n\ttype NakamotoCoinbasePayload,\n\tPayloadType,\n\ttype PoisonMicroblockPayload,\n\tPostConditionPrincipalId,\n\ttype PostConditionPrincipalWire,\n\ttype PostConditionWire,\n\ttype SingleSigSpendingCondition,\n\ttype SpendingCondition,\n\ttype StacksTransaction,\n\ttype TenureChangePayload as TenureChangePayloadType,\n\ttype TransactionAuthField,\n\ttype TransactionPayload,\n} from \"../types.ts\";\n\n// Address serialization: version (1 byte) + hash160 (20 bytes)\nfunction serializeAddress(c32Address: string): Uint8Array {\n\tconst [version, hash160] = c32addressDecode(c32Address);\n\treturn concatBytes(new Uint8Array([version]), hexToBytes(hash160));\n}\n\n// LP string: length prefix (n bytes) + content bytes\nfunction serializeLPString(str: string, prefixBytes = 1): Uint8Array {\n\tconst content = utf8ToBytes(str);\n\tconst prefix = hexToBytes(intToHex(content.byteLength, prefixBytes));\n\treturn concatBytes(prefix, content);\n}\n\n// LP string for code body (4-byte prefix)\nfunction serializeLPStringLong(str: string): Uint8Array {\n\treturn serializeLPString(str, 4);\n}\n\n// Memo: flat 34-byte field (no length prefix) per SIP-005\nfunction serializeMemo(memo: string): Uint8Array {\n\tconst content = asciiToBytes(memo);\n\tconst padded = new Uint8Array(MEMO_MAX_LENGTH_BYTES);\n\tpadded.set(content.slice(0, MEMO_MAX_LENGTH_BYTES));\n\treturn padded;\n}\n\nfunction serializeSpendingCondition(condition: SpendingCondition): Uint8Array {\n\tconst parts: Uint8Array[] = [\n\t\twriteUInt8(condition.hashMode),\n\t\thexToBytes(condition.signer), // 20 bytes\n\t\tintToBytes(condition.nonce, 8),\n\t\tintToBytes(condition.fee, 8),\n\t];\n\n\tif (\"signature\" in condition) {\n\t\t// Single sig\n\t\tconst sc = condition as SingleSigSpendingCondition;\n\t\tparts.push(writeUInt8(sc.keyEncoding));\n\t\tparts.push(hexToBytes(sc.signature)); // 65 bytes\n\t} else {\n\t\t// Multi sig\n\t\tconst mc = condition as MultiSigSpendingCondition;\n\t\t// Fields as LP list\n\t\tparts.push(writeUInt32BE(mc.fields.length));\n\t\tfor (const field of mc.fields) {\n\t\t\tparts.push(serializeAuthField(field));\n\t\t}\n\t\tparts.push(writeUInt16BE(mc.signaturesRequired));\n\t}\n\n\treturn concatBytes(...parts);\n}\n\nfunction serializeAuthField(field: TransactionAuthField): Uint8Array {\n\tif (field.type === \"publicKey\") {\n\t\tconst typeId = field.pubKeyEncoding === 0x00 ? 0x00 : 0x01;\n\t\treturn concatBytes(writeUInt8(typeId), hexToBytes(field.data));\n\t} else {\n\t\tconst typeId = field.pubKeyEncoding === 0x00 ? 0x02 : 0x03;\n\t\treturn concatBytes(writeUInt8(typeId), hexToBytes(field.data));\n\t}\n}\n\nfunction serializeAuthorization(auth: Authorization): Uint8Array {\n\tconst parts: Uint8Array[] = [writeUInt8(auth.authType)];\n\tparts.push(serializeSpendingCondition(auth.spendingCondition));\n\tif (auth.authType === AuthType.Sponsored) {\n\t\tparts.push(serializeSpendingCondition(auth.sponsorSpendingCondition));\n\t}\n\treturn concatBytes(...parts);\n}\n\nfunction serializePrincipal(principal: PostConditionPrincipalWire): Uint8Array {\n\tswitch (principal.type) {\n\t\tcase \"origin\":\n\t\t\treturn writeUInt8(PostConditionPrincipalId.Origin);\n\t\tcase \"standard\":\n\t\t\treturn concatBytes(\n\t\t\t\twriteUInt8(PostConditionPrincipalId.Standard),\n\t\t\t\tserializeAddress(principal.address),\n\t\t\t);\n\t\tcase \"contract\":\n\t\t\treturn concatBytes(\n\t\t\t\twriteUInt8(PostConditionPrincipalId.Contract),\n\t\t\t\tserializeAddress(principal.address),\n\t\t\t\tserializeLPString(principal.contractName),\n\t\t\t);\n\t}\n}\n\nfunction serializeAssetInfo(asset: AssetInfoWire): Uint8Array {\n\treturn concatBytes(\n\t\tserializeAddress(asset.address),\n\t\tserializeLPString(asset.contractName),\n\t\tserializeLPString(asset.assetName),\n\t);\n}\n\nfunction serializePostCondition(pc: PostConditionWire): Uint8Array {\n\t// Wire order: asset_type first, then principal (per SIP-005)\n\tconst parts: Uint8Array[] = [];\n\n\tswitch (pc.type) {\n\t\tcase \"stx\":\n\t\t\tparts.push(writeUInt8(AssetType.STX));\n\t\t\tparts.push(serializePrincipal(pc.principal));\n\t\t\tparts.push(writeUInt8(pc.conditionCode));\n\t\t\tparts.push(intToBytes(pc.amount, 8));\n\t\t\tbreak;\n\t\tcase \"ft\":\n\t\t\tparts.push(writeUInt8(AssetType.Fungible));\n\t\t\tparts.push(serializePrincipal(pc.principal));\n\t\t\tparts.push(serializeAssetInfo(pc.asset));\n\t\t\tparts.push(writeUInt8(pc.conditionCode));\n\t\t\tparts.push(intToBytes(pc.amount, 8));\n\t\t\tbreak;\n\t\tcase \"nft\":\n\t\t\tparts.push(writeUInt8(AssetType.NonFungible));\n\t\t\tparts.push(serializePrincipal(pc.principal));\n\t\t\tparts.push(serializeAssetInfo(pc.asset));\n\t\t\tparts.push(serializeCVBytes(pc.assetId));\n\t\t\tparts.push(writeUInt8(pc.conditionCode));\n\t\t\tbreak;\n\t}\n\n\treturn concatBytes(...parts);\n}\n\nfunction serializePostConditions(pcs: PostConditionWire[]): Uint8Array {\n\tconst parts: Uint8Array[] = [writeUInt32BE(pcs.length)];\n\tfor (const pc of pcs) {\n\t\tparts.push(serializePostCondition(pc));\n\t}\n\treturn concatBytes(...parts);\n}\n\nexport function serializePayload(payload: TransactionPayload): Uint8Array {\n\tconst parts: Uint8Array[] = [writeUInt8(payload.payloadType)];\n\n\tswitch (payload.payloadType) {\n\t\tcase PayloadType.TokenTransfer:\n\t\t\tparts.push(serializeCVBytes(payload.recipient));\n\t\t\tparts.push(intToBytes(payload.amount, 8));\n\t\t\tparts.push(serializeMemo(payload.memo));\n\t\t\tbreak;\n\n\t\tcase PayloadType.ContractCall:\n\t\t\tparts.push(serializeAddress(payload.contractAddress));\n\t\t\tparts.push(serializeLPString(payload.contractName));\n\t\t\tparts.push(serializeLPString(payload.functionName));\n\t\t\tparts.push(writeUInt32BE(payload.functionArgs.length));\n\t\t\tfor (const arg of payload.functionArgs) {\n\t\t\t\tparts.push(serializeCVBytes(arg));\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase PayloadType.SmartContract:\n\t\t\tparts.push(serializeLPString(payload.contractName));\n\t\t\tparts.push(serializeLPStringLong(payload.codeBody));\n\t\t\tbreak;\n\n\t\tcase PayloadType.VersionedSmartContract:\n\t\t\tparts.push(writeUInt8(payload.clarityVersion ?? 2));\n\t\t\tparts.push(serializeLPString(payload.contractName));\n\t\t\tparts.push(serializeLPStringLong(payload.codeBody));\n\t\t\tbreak;\n\n\t\tcase PayloadType.Coinbase:\n\t\t\tparts.push(hexToBytes((payload as CoinbasePayload).coinbaseBuffer));\n\t\t\tbreak;\n\n\t\tcase PayloadType.CoinbaseToAltRecipient: {\n\t\t\tconst cbAlt = payload as CoinbaseToAltRecipientPayload;\n\t\t\tparts.push(hexToBytes(cbAlt.coinbaseBuffer));\n\t\t\tparts.push(serializeCVBytes(cbAlt.recipient));\n\t\t\tbreak;\n\t\t}\n\n\t\tcase PayloadType.PoisonMicroblock: {\n\t\t\tconst pm = payload as PoisonMicroblockPayload;\n\t\t\tparts.push(hexToBytes(pm.header1));\n\t\t\tparts.push(hexToBytes(pm.header2));\n\t\t\tbreak;\n\t\t}\n\n\t\tcase PayloadType.TenureChange: {\n\t\t\tconst tc = payload as TenureChangePayloadType;\n\t\t\tparts.push(hexToBytes(tc.tenureConsensusHash));\n\t\t\tparts.push(hexToBytes(tc.prevTenureConsensusHash));\n\t\t\tparts.push(hexToBytes(tc.burnViewConsensusHash));\n\t\t\tparts.push(hexToBytes(tc.previousTenureEnd));\n\t\t\tparts.push(writeUInt32BE(tc.previousTenureBlocks));\n\t\t\tparts.push(writeUInt8(tc.cause));\n\t\t\tparts.push(hexToBytes(tc.pubkeyHash));\n\t\t\tbreak;\n\t\t}\n\n\t\tcase PayloadType.NakamotoCoinbase: {\n\t\t\tconst nc = payload as NakamotoCoinbasePayload;\n\t\t\tparts.push(hexToBytes(nc.coinbaseBuffer));\n\t\t\tif (nc.recipient) {\n\t\t\t\tparts.push(serializeCVBytes({ type: \"some\", value: nc.recipient }));\n\t\t\t} else {\n\t\t\t\tparts.push(serializeCVBytes({ type: \"none\" }));\n\t\t\t}\n\t\t\tparts.push(hexToBytes(nc.vrfProof));\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn concatBytes(...parts);\n}\n\nexport function serializeTransaction(tx: StacksTransaction): Uint8Array {\n\treturn concatBytes(\n\t\twriteUInt8(tx.version),\n\t\twriteUInt32BE(tx.chainId),\n\t\tserializeAuthorization(tx.auth),\n\t\twriteUInt8(tx.anchorMode),\n\t\twriteUInt8(tx.postConditionMode),\n\t\tserializePostConditions(tx.postConditions),\n\t\tserializePayload(tx.payload),\n\t);\n}\n\nexport function serializeTransactionHex(tx: StacksTransaction): string {\n\treturn bytesToHex(serializeTransaction(tx));\n}\n",
|
|
12
|
+
"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\treturn (data.estimations ?? []).map((e: any) => ({\n\t\tfeeRate: e.fee_rate,\n\t\tfee: e.fee,\n\t}));\n}\n",
|
|
13
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetAccountInfoParams = {\n\taddress: string;\n};\n\nexport type AccountInfo = {\n\tbalance: bigint;\n\tnonce: bigint;\n\tbalanceProof: string;\n\tnonceProof: string;\n};\n\nexport async function getAccountInfo(\n\tclient: Client,\n\tparams: GetAccountInfoParams,\n): Promise<AccountInfo> {\n\tconst data = await client.request(`/v2/accounts/${params.address}?proof=1`, {\n\t\tmethod: \"GET\",\n\t});\n\treturn {\n\t\tbalance: BigInt(data.balance),\n\t\tnonce: BigInt(data.nonce),\n\t\tbalanceProof: data.balance_proof ?? \"\",\n\t\tnonceProof: data.nonce_proof ?? \"\",\n\t};\n}\n",
|
|
14
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBalanceParams = {\n\taddress: string;\n};\n\nexport async function getBalance(\n\tclient: Client,\n\tparams: GetBalanceParams,\n): Promise<bigint> {\n\tconst data = await client.request(`/v2/accounts/${params.address}`, {\n\t\tmethod: \"GET\",\n\t});\n\treturn BigInt(data.balance);\n}\n",
|
|
15
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBlockParams = {\n\theight?: number;\n\thash?: string;\n};\n\nexport async function getBlock(\n\tclient: Client,\n\tparams?: GetBlockParams,\n): Promise<any> {\n\tif (params?.hash) {\n\t\treturn client.request(`/extended/v2/blocks/${params.hash}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\tif (params?.height !== undefined) {\n\t\treturn client.request(`/extended/v2/blocks/${params.height}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\t// Latest block\n\treturn client.request(\"/extended/v2/blocks?limit=1\", { method: \"GET\" });\n}\n",
|
|
16
|
+
"import type { Client } from \"../../clients/types.ts\";\n\nexport async function getBlockHeight(client: Client): Promise<number> {\n\tconst data = await client.request(\"/v2/info\", { method: \"GET\" });\n\treturn data.stacks_tip_height;\n}\n",
|
|
17
|
+
"import { bytesToHex } from \"./encoding.ts\";\n\nexport class BytesReader {\n\tprivate data: Uint8Array;\n\tpublic offset = 0;\n\n\tconstructor(data: Uint8Array) {\n\t\tthis.data = data;\n\t}\n\n\treadUInt8(): number {\n\t\treturn this.data[this.offset++]!;\n\t}\n\n\treadUInt16BE(): number {\n\t\tconst val =\n\t\t\t((this.data[this.offset]! << 8) | this.data[this.offset + 1]!) >>> 0;\n\t\tthis.offset += 2;\n\t\treturn val;\n\t}\n\n\treadUInt32BE(): number {\n\t\tconst val =\n\t\t\t((this.data[this.offset]! << 24) |\n\t\t\t\t(this.data[this.offset + 1]! << 16) |\n\t\t\t\t(this.data[this.offset + 2]! << 8) |\n\t\t\t\tthis.data[this.offset + 3]!) >>>\n\t\t\t0;\n\t\tthis.offset += 4;\n\t\treturn val;\n\t}\n\n\treadBytes(length: number): Uint8Array {\n\t\tif (this.offset + length > this.data.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Buffer underflow: need ${length} bytes at offset ${this.offset}, have ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t\tconst slice = this.data.slice(this.offset, this.offset + length);\n\t\tthis.offset += length;\n\t\treturn slice;\n\t}\n\n\treadBigUInt64BE(): bigint {\n\t\tconst hex = bytesToHex(this.readBytes(8));\n\t\treturn hex.length > 0 ? BigInt(`0x${hex}`) : 0n;\n\t}\n}\n",
|
|
18
|
+
"import { c32address, c32addressDecode } from \"./c32.ts\";\n\nexport { c32address, c32addressDecode };\n\nexport function validateStacksAddress(address: string): boolean {\n\ttry {\n\t\tc32addressDecode(address);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Alias for validateStacksAddress — matches future.md naming. */\nexport const isValidAddress: (address: string) => boolean =\n\tvalidateStacksAddress;\n\nexport function parseContractId(contractId: string): [string, string] {\n\tconst [address, name] = contractId.split(\".\");\n\tif (!address || !name)\n\t\tthrow new Error(`Invalid contract identifier: ${contractId}`);\n\treturn [address, name];\n}\n\nexport function isClarityName(name: string): boolean {\n\tconst regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;\n\treturn regex.test(name) && name.length < 128;\n}\n\n/**\n * Compare two Stacks addresses for equality (case-insensitive, version-aware).\n * Throws if either address is invalid.\n */\nexport function isAddressEqual(a: string, b: string): boolean {\n\tconst [versionA, hashA] = c32addressDecode(a);\n\tconst [versionB, hashB] = c32addressDecode(b);\n\treturn versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();\n}\n\n/** Extract the version byte from a Stacks address (22, 20, 26, or 21). */\nexport function addressToVersion(address: string): number {\n\treturn c32addressDecode(address)[0];\n}\n\n/**\n * Build a contract address from deployer + contract name.\n * Validates both parts; returns `deployer.contractName`.\n */\nexport function getContractAddress(\n\tdeployer: string,\n\tcontractName: string,\n): string {\n\tif (!validateStacksAddress(deployer)) {\n\t\tthrow new Error(`Invalid deployer address: ${deployer}`);\n\t}\n\tif (!isClarityName(contractName)) {\n\t\tthrow new Error(`Invalid contract name: ${contractName}`);\n\t}\n\treturn `${deployer}.${contractName}`;\n}\n",
|
|
19
|
+
"import { isClarityName } from \"../utils/address.ts\";\nimport { c32address, c32addressDecode } from \"../utils/c32.ts\";\nimport {\n\ttype IntegerType,\n\tasciiToBytes,\n\tbytesToHex,\n\tbytesToTwosBigInt,\n\thexToBytes,\n\tintToBigInt,\n\tutf8ToBytes,\n} from \"../utils/encoding.ts\";\nimport { deserializeCVBytes } from \"./deserialize.ts\";\nimport { serializeCVBytes } from \"./serialize.ts\";\nimport type {\n\tBooleanCV,\n\tBufferCV,\n\tClarityValue,\n\tContractPrincipalCV,\n\tFalseCV,\n\tIntCV,\n\tListCV,\n\tNoneCV,\n\tResponseErrorCV,\n\tResponseOkCV,\n\tSomeCV,\n\tStandardPrincipalCV,\n\tStringAsciiCV,\n\tStringUtf8CV,\n\tTrueCV,\n\tTupleCV,\n\tTupleData,\n\tUIntCV,\n} from \"./types.ts\";\n\nconst MAX_U128 = BigInt(\"0xffffffffffffffffffffffffffffffff\");\nconst MIN_I128 = BigInt(\"-170141183460469231731687303715884105728\");\nconst MAX_I128 = BigInt(\"0x7fffffffffffffffffffffffffffffff\");\n\n// Primitives\n\nexport function intCV(value: IntegerType): IntCV {\n\tif (typeof value === \"string\" && value.toLowerCase().startsWith(\"0x\")) {\n\t\tvalue = bytesToTwosBigInt(hexToBytes(value));\n\t}\n\tif (value instanceof Uint8Array) value = bytesToTwosBigInt(value);\n\tconst n = intToBigInt(value);\n\tif (n > MAX_I128) throw new RangeError(`Int exceeds max i128: ${MAX_I128}`);\n\tif (n < MIN_I128) throw new RangeError(`Int below min i128: ${MIN_I128}`);\n\treturn { type: \"int\", value: n };\n}\n\nexport function uintCV(value: IntegerType): UIntCV {\n\tconst n = intToBigInt(value);\n\tif (n < 0n)\n\t\tthrow new RangeError(\"Cannot construct unsigned int from negative value\");\n\tif (n > MAX_U128) throw new RangeError(`UInt exceeds max u128: ${MAX_U128}`);\n\treturn { type: \"uint\", value: n };\n}\n\nexport const trueCV = (): TrueCV => ({ type: \"true\" });\nexport const falseCV = (): FalseCV => ({ type: \"false\" });\nexport const boolCV = (v: boolean): BooleanCV => (v ? trueCV() : falseCV());\n\nexport function bufferCV(buffer: Uint8Array): BufferCV {\n\tif (buffer.byteLength > 1_048_576) {\n\t\tthrow new Error(\"Buffer exceeds max size of 1MB\");\n\t}\n\treturn { type: \"buffer\", value: bytesToHex(buffer) };\n}\n\nexport function standardPrincipalCV(address: string): StandardPrincipalCV {\n\t// Validate by decoding\n\tconst [version, hash160] = c32addressDecode(address);\n\tconst normalized = c32address(version, hash160);\n\treturn { type: \"address\", value: normalized };\n}\n\nexport function contractPrincipalCV(\n\taddress: string,\n\tcontractName: string,\n): ContractPrincipalCV {\n\tconst [version, hash160] = c32addressDecode(address);\n\tconst normalized = c32address(version, hash160);\n\tif (utf8ToBytes(contractName).byteLength >= 128) {\n\t\tthrow new Error(\"Contract name must be less than 128 bytes\");\n\t}\n\treturn { type: \"contract\", value: `${normalized}.${contractName}` };\n}\n\nexport function noneCV(): NoneCV {\n\treturn { type: \"none\" };\n}\n\nexport function someCV(value: ClarityValue): SomeCV {\n\treturn { type: \"some\", value };\n}\n\nexport function responseOkCV(value: ClarityValue): ResponseOkCV {\n\treturn { type: \"ok\", value };\n}\n\nexport function responseErrorCV(value: ClarityValue): ResponseErrorCV {\n\treturn { type: \"err\", value };\n}\n\nexport function listCV(values: ClarityValue[]): ListCV {\n\treturn { type: \"list\", value: values };\n}\n\nexport function tupleCV(data: TupleData): TupleCV {\n\tfor (const key in data) {\n\t\tif (!isClarityName(key)) {\n\t\t\tthrow new Error(`\"${key}\" is not a valid Clarity name`);\n\t\t}\n\t}\n\treturn { type: \"tuple\", value: data };\n}\n\nexport function stringAsciiCV(value: string): StringAsciiCV {\n\treturn { type: \"ascii\", value };\n}\n\nexport function stringUtf8CV(value: string): StringUtf8CV {\n\treturn { type: \"utf8\", value };\n}\n\n// Cl namespace — clean API\n\nexport const Cl: {\n\treadonly int: (value: IntegerType) => IntCV;\n\treadonly uint: (value: IntegerType) => UIntCV;\n\treadonly bool: (v: boolean) => BooleanCV;\n\tprincipal(address: string): StandardPrincipalCV | ContractPrincipalCV;\n\taddress(address: string): StandardPrincipalCV | ContractPrincipalCV;\n\treadonly contractPrincipal: (\n\t\taddress: string,\n\t\tcontractName: string,\n\t) => ContractPrincipalCV;\n\treadonly standardPrincipal: (address: string) => StandardPrincipalCV;\n\treadonly buffer: (buffer: Uint8Array) => BufferCV;\n\treadonly bufferFromHex: (hex: string) => BufferCV;\n\treadonly bufferFromAscii: (ascii: string) => BufferCV;\n\treadonly bufferFromUtf8: (utf8: string) => BufferCV;\n\treadonly none: () => NoneCV;\n\treadonly some: (value: ClarityValue) => SomeCV;\n\treadonly ok: (value: ClarityValue) => ResponseOkCV;\n\treadonly error: (value: ClarityValue) => ResponseErrorCV;\n\treadonly list: (values: ClarityValue[]) => ListCV;\n\treadonly tuple: (data: TupleData) => TupleCV;\n\treadonly stringAscii: (value: string) => StringAsciiCV;\n\treadonly stringUtf8: (value: string) => StringUtf8CV;\n\tserialize(value: ClarityValue): string;\n\treadonly deserialize: (bytes: Uint8Array) => ClarityValue;\n} = {\n\tint: intCV,\n\tuint: uintCV,\n\tbool: boolCV,\n\tprincipal(address: string): StandardPrincipalCV | ContractPrincipalCV {\n\t\tconst [addr, name] = address.split(\".\");\n\t\tif (!addr) throw new Error(\"Invalid principal address\");\n\t\treturn name ? contractPrincipalCV(addr, name) : standardPrincipalCV(addr);\n\t},\n\taddress(address: string): StandardPrincipalCV | ContractPrincipalCV {\n\t\treturn Cl.principal(address);\n\t},\n\tcontractPrincipal: contractPrincipalCV,\n\tstandardPrincipal: standardPrincipalCV,\n\tbuffer: bufferCV,\n\tbufferFromHex: (hex: string): BufferCV => bufferCV(hexToBytes(hex)),\n\tbufferFromAscii: (ascii: string): BufferCV => bufferCV(asciiToBytes(ascii)),\n\tbufferFromUtf8: (utf8: string): BufferCV => bufferCV(utf8ToBytes(utf8)),\n\tnone: noneCV,\n\tsome: someCV,\n\tok: responseOkCV,\n\terror: responseErrorCV,\n\tlist: listCV,\n\ttuple: tupleCV,\n\tstringAscii: stringAsciiCV,\n\tstringUtf8: stringUtf8CV,\n\tserialize(value: ClarityValue): string {\n\t\treturn bytesToHex(serializeCVBytes(value));\n\t},\n\tdeserialize: deserializeCVBytes,\n} as const;\n",
|
|
20
|
+
"import { BytesReader } from \"../utils/bytes-reader.ts\";\nimport { c32address } from \"../utils/c32.ts\";\nimport {\n\tbytesToAscii,\n\tbytesToHex,\n\tbytesToTwosBigInt,\n\tbytesToUtf8,\n\thexToBytes,\n\twithout0x,\n} from \"../utils/encoding.ts\";\nimport { type ClarityValue, clarityTypeFromByte } from \"./types.ts\";\nimport {\n\tbufferCV,\n\tcontractPrincipalCV,\n\tfalseCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstandardPrincipalCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttrueCV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\n\nexport function readAddress(reader: BytesReader): string {\n\tconst version = reader.readUInt8();\n\tconst hash160 = bytesToHex(reader.readBytes(20));\n\treturn c32address(version, hash160);\n}\n\nexport function readLPString(reader: BytesReader, prefixBytes = 1): string {\n\tlet length = 0;\n\tfor (let i = 0; i < prefixBytes; i++) {\n\t\tlength = (length << 8) | reader.readUInt8();\n\t}\n\treturn bytesToUtf8(reader.readBytes(length));\n}\n\nexport function readCV(reader: BytesReader): ClarityValue {\n\tconst typeByte = reader.readUInt8();\n\tconst type = clarityTypeFromByte(typeByte);\n\n\tswitch (type) {\n\t\tcase \"int\":\n\t\t\treturn intCV(bytesToTwosBigInt(reader.readBytes(16)));\n\n\t\tcase \"uint\":\n\t\t\treturn uintCV(reader.readBytes(16));\n\n\t\tcase \"true\":\n\t\t\treturn trueCV();\n\n\t\tcase \"false\":\n\t\t\treturn falseCV();\n\n\t\tcase \"buffer\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn bufferCV(reader.readBytes(len));\n\t\t}\n\n\t\tcase \"none\":\n\t\t\treturn noneCV();\n\n\t\tcase \"some\":\n\t\t\treturn someCV(readCV(reader));\n\n\t\tcase \"ok\":\n\t\t\treturn responseOkCV(readCV(reader));\n\n\t\tcase \"err\":\n\t\t\treturn responseErrorCV(readCV(reader));\n\n\t\tcase \"address\":\n\t\t\treturn standardPrincipalCV(readAddress(reader));\n\n\t\tcase \"contract\": {\n\t\t\tconst addr = readAddress(reader);\n\t\t\tconst name = readLPString(reader);\n\t\t\treturn contractPrincipalCV(addr, name);\n\t\t}\n\n\t\tcase \"list\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\tconst items: ClarityValue[] = [];\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\titems.push(readCV(reader));\n\t\t\t}\n\t\t\treturn listCV(items);\n\t\t}\n\n\t\tcase \"tuple\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\tconst data: Record<string, ClarityValue> = {};\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\tconst key = readLPString(reader);\n\t\t\t\tdata[key] = readCV(reader);\n\t\t\t}\n\t\t\treturn tupleCV(data);\n\t\t}\n\n\t\tcase \"ascii\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn stringAsciiCV(bytesToAscii(reader.readBytes(len)));\n\t\t}\n\n\t\tcase \"utf8\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn stringUtf8CV(bytesToUtf8(reader.readBytes(len)));\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot deserialize unknown clarity type: ${type}`);\n\t}\n}\n\nexport function deserializeCVBytes<T extends ClarityValue = ClarityValue>(\n\tinput: Uint8Array | string,\n): T {\n\tconst bytes =\n\t\ttypeof input === \"string\" ? hexToBytes(without0x(input)) : input;\n\treturn readCV(new BytesReader(bytes)) as T;\n}\n\nexport function deserializeCV<T extends ClarityValue = ClarityValue>(\n\tinput: Uint8Array | string,\n): T {\n\treturn deserializeCVBytes(input);\n}\n",
|
|
21
|
+
"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",
|
|
22
|
+
"type CamelCaseInner<S extends string> =\n\tS extends `${infer P1}-${infer P2}${infer P3}`\n\t\t? `${P1}${Capitalize<CamelCaseInner<`${P2}${P3}`>>}`\n\t\t: S;\n\nexport type ToCamelCase<S extends string> =\n\tCamelCaseInner<S> extends `${number}${string}`\n\t\t? `_${CamelCaseInner<S>}`\n\t\t: CamelCaseInner<S>;\n\nexport function toCamelCase(str: string): string {\n\treturn str\n\t\t.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())\n\t\t.replace(/-([A-Z])/g, (_, letter) => letter)\n\t\t.replace(/-(\\d)/g, (_, digit) => digit)\n\t\t.replace(/-/g, \"\")\n\t\t.replace(/^\\d/, \"_$&\");\n}\n",
|
|
23
|
+
"// 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",
|
|
24
|
+
"import { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { CONTRACT_NAME_REGEX, MAX_I128, MAX_U128, MIN_I128 } from \"./types.ts\";\nimport type {\n\tAbiBuffer,\n\tAbiListType,\n\tAbiOptionalType,\n\tAbiResponseType,\n\tAbiStringAscii,\n\tAbiStringUtf8,\n\tAbiTraitReference,\n\tAbiTupleType,\n\tAbiType,\n} from \"./types.ts\";\n\n// Value guards\n\nexport function isUint128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= 0n && value <= MAX_U128;\n}\n\nexport function isInt128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= MIN_I128 && value <= MAX_I128;\n}\n\nexport function isBool(value: unknown): value is boolean {\n\treturn typeof value === \"boolean\";\n}\n\nexport function isPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parts = value.split(\".\");\n\tconst address = parts[0]!;\n\tconst contractName = parts[1];\n\tif (!validateStacksAddress(address)) return false;\n\tif (contractName !== undefined) {\n\t\treturn CONTRACT_NAME_REGEX.test(contractName);\n\t}\n\treturn true;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (value.includes(\".\")) return false;\n\treturn validateStacksAddress(value);\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (!value.includes(\".\")) return false;\n\tconst parts = value.split(\".\");\n\tconst address = parts[0]!;\n\tconst contractName = parts[1]!;\n\tif (!validateStacksAddress(address)) return false;\n\treturn CONTRACT_NAME_REGEX.test(contractName);\n}\n\nexport function isTraitReference(value: unknown): value is string {\n\treturn isContractPrincipal(value);\n}\n\nexport function isString(value: unknown): value is string {\n\treturn typeof value === \"string\";\n}\n\nexport function isUint8Array(value: unknown): value is Uint8Array {\n\treturn value instanceof Uint8Array;\n}\n\nexport function isArray<T>(\n\tvalue: unknown,\n\titemGuard: (item: unknown) => item is T,\n): value is T[] {\n\treturn Array.isArray(value) && value.every(itemGuard);\n}\n\nexport function isOptional<T>(\n\tvalue: unknown,\n\tguard: (val: unknown) => val is T,\n): value is T | null {\n\treturn value === null || guard(value);\n}\n\nexport function isOkResponse<T>(\n\tresponse: { ok: T } | { err: any },\n): response is ResponseOk<T> {\n\treturn \"ok\" in response && !(\"err\" in response);\n}\n\nexport function isErrResponse<E>(\n\tresponse: { ok: any } | { err: E },\n): response is ResponseErr<E> {\n\treturn \"err\" in response && !(\"ok\" in response);\n}\n\nexport function isResponse<T, E>(\n\tvalue: unknown,\n\tokGuard: (val: unknown) => val is T,\n\terrGuard: (val: unknown) => val is E,\n): value is ResponseOk<T> | ResponseErr<E> {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst obj = value as Record<string, unknown>;\n\tif (\"ok\" in value && !(\"err\" in value)) return okGuard(obj.ok);\n\tif (\"err\" in value && !(\"ok\" in value)) return errGuard(obj.err);\n\treturn false;\n}\n\n// ABI type definition guards\n\nexport function isAbiList(type: AbiType): type is AbiListType {\n\treturn typeof type === \"object\" && type !== null && \"list\" in type;\n}\n\nexport function isAbiTuple(type: AbiType): type is AbiTupleType {\n\treturn typeof type === \"object\" && type !== null && \"tuple\" in type;\n}\n\nexport function isAbiOptional(type: AbiType): type is AbiOptionalType {\n\treturn typeof type === \"object\" && type !== null && \"optional\" in type;\n}\n\nexport function isAbiResponse(type: AbiType): type is AbiResponseType {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nexport function isAbiBuffer(type: AbiType): type is AbiBuffer {\n\treturn typeof type === \"object\" && type !== null && \"buff\" in type;\n}\n\nexport function isAbiStringAscii(type: AbiType): type is AbiStringAscii {\n\treturn typeof type === \"object\" && type !== null && \"string-ascii\" in type;\n}\n\nexport function isAbiStringUtf8(type: AbiType): type is AbiStringUtf8 {\n\treturn typeof type === \"object\" && type !== null && \"string-utf8\" in type;\n}\n\nexport function isAbiTraitReference(type: AbiType): type is AbiTraitReference {\n\treturn type === \"trait_reference\";\n}\n",
|
|
25
|
+
"import {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n} from \"./abi/guards.ts\";\nimport type { AbiToTS } from \"./abi/mappings.ts\";\nimport type { AbiType } from \"./abi/types.ts\";\nimport { toCamelCase } from \"./abi/utils.ts\";\nimport type { ClarityValue } from \"./types.ts\";\nimport {\n\tboolCV,\n\tbufferCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\nimport { Cl } from \"./values.ts\";\n\n/**\n * Convert a JS value to a ClarityValue using ABI type information.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\n\tif (abiType === \"uint128\") return uintCV(value as bigint | number);\n\tif (abiType === \"int128\") return intCV(value as bigint | number);\n\tif (abiType === \"bool\") return boolCV(value as boolean);\n\tif (abiType === \"principal\" || abiType === \"trait_reference\")\n\t\treturn Cl.principal(value as string);\n\n\tif (isAbiStringAscii(abiType)) return stringAsciiCV(value as string);\n\tif (isAbiStringUtf8(abiType)) return stringUtf8CV(value as string);\n\tif (isAbiBuffer(abiType)) return bufferCV(value as Uint8Array);\n\n\tif (isAbiList(abiType)) {\n\t\tconst arr = value as unknown[];\n\t\treturn listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst data: Record<string, ClarityValue> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in obj;\n\t\t\tconst hasCamel = camelKey in obj;\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? obj[field.name]\n\t\t\t\t: hasCamel\n\t\t\t\t\t? obj[camelKey]\n\t\t\t\t\t: undefined;\n\t\t\tif (fieldValue === undefined && !isAbiOptional(field.type)) {\n\t\t\t\tthrow new Error(`Missing tuple field: ${field.name}`);\n\t\t\t}\n\t\t\tdata[field.name] = jsToClarityValue(field.type, fieldValue);\n\t\t}\n\t\treturn tupleCV(data);\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (value === null || value === undefined) return noneCV();\n\t\treturn someCV(jsToClarityValue(abiType.optional, value));\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tif (\"ok\" in obj && !(\"err\" in obj))\n\t\t\treturn responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));\n\t\tif (\"err\" in obj && !(\"ok\" in obj))\n\t\t\treturn responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));\n\t\tthrow new Error(\"Response must have exactly 'ok' or 'err' property\");\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n\n/**\n * Convert a ClarityValue back to a typed JS value using ABI type information.\n */\nexport function clarityValueToJS<T extends AbiType>(\n\tabiType: T,\n\tcv: ClarityValue,\n): AbiToTS<T> {\n\treturn clarityValueToJSInner(abiType, cv) as AbiToTS<T>;\n}\n\n/** Non-generic version for internal use — avoids deep type instantiation. */\nexport function clarityValueToJSUntyped(\n\tabiType: AbiType,\n\tcv: ClarityValue,\n): unknown {\n\treturn clarityValueToJSInner(abiType, cv);\n}\n\nfunction clarityValueToJSInner(abiType: AbiType, cv: ClarityValue): unknown {\n\tif (abiType === \"uint128\" || abiType === \"int128\") {\n\t\tif (cv.type !== \"int\" && cv.type !== \"uint\")\n\t\t\tthrow new Error(`Expected int/uint CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (abiType === \"bool\") {\n\t\tif (cv.type === \"true\") return true;\n\t\tif (cv.type === \"false\") return false;\n\t\tthrow new Error(`Expected bool CV, got ${cv.type}`);\n\t}\n\n\tif (abiType === \"principal\" || abiType === \"trait_reference\") {\n\t\tif (cv.type !== \"address\" && cv.type !== \"contract\")\n\t\t\tthrow new Error(`Expected principal CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {\n\t\tif (cv.type !== \"ascii\" && cv.type !== \"utf8\")\n\t\t\tthrow new Error(`Expected string CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiBuffer(abiType)) {\n\t\tif (cv.type !== \"buffer\")\n\t\t\tthrow new Error(`Expected buffer CV, got ${cv.type}`);\n\t\t// BufferCV stores hex string; convert back to Uint8Array\n\t\tconst hex = cv.value;\n\t\tconst bytes = new Uint8Array(hex.length / 2);\n\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\tbytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tif (isAbiList(abiType)) {\n\t\tif (cv.type !== \"list\") throw new Error(`Expected list CV, got ${cv.type}`);\n\t\treturn cv.value.map((item) =>\n\t\t\tclarityValueToJSInner(abiType.list.type, item),\n\t\t);\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tif (cv.type !== \"tuple\")\n\t\t\tthrow new Error(`Expected tuple CV, got ${cv.type}`);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst fieldCV = cv.value[field.name];\n\t\t\tif (!fieldCV) throw new Error(`Missing tuple field in CV: ${field.name}`);\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tresult[camelKey] = clarityValueToJSInner(field.type, fieldCV);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (cv.type === \"none\") return null;\n\t\tif (cv.type === \"some\")\n\t\t\treturn clarityValueToJSInner(abiType.optional, cv.value);\n\t\tthrow new Error(`Expected optional CV, got ${cv.type}`);\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tif (cv.type === \"ok\")\n\t\t\treturn { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };\n\t\tif (cv.type === \"err\")\n\t\t\treturn { err: clarityValueToJSInner(abiType.response.error, cv.value) };\n\t\tthrow new Error(`Expected response CV, got ${cv.type}`);\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n",
|
|
26
|
+
"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",
|
|
27
|
+
"import { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { etc, getPublicKey as nobleGetPublicKey, sign } from \"@noble/secp256k1\";\nimport {\n\tbytesToHex,\n\tconcatBytes,\n\thexToBytes,\n\tintToBytes,\n\tintToHex,\n} from \"../utils/encoding.ts\";\nimport { hashP2PKH, txidFromBytes } from \"../utils/hash.ts\";\nimport {\n\tAddressHashMode,\n\tAuthType,\n\ttype Authorization,\n\tPubKeyEncoding,\n\tRECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n\ttype SingleSigSpendingCondition,\n\ttype SpendingCondition,\n\ttype SponsoredAuthorization,\n\ttype StandardAuthorization,\n} from \"./types.ts\";\n\n// Ensure sync signing is available\netc.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {\n\tconst h = hmac.create(sha256, key);\n\tmsgs.forEach((msg) => h.update(msg));\n\treturn h.digest();\n};\n\nconst EMPTY_SIG = bytesToHex(\n\tnew Uint8Array(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES),\n);\n\nexport function createSingleSigSpendingCondition(\n\tpublicKey: string,\n\tnonce: bigint,\n\tfee: bigint,\n): SingleSigSpendingCondition {\n\tconst pubKeyBytes = hexToBytes(publicKey);\n\tconst signer = hashP2PKH(pubKeyBytes);\n\tconst isCompressed = pubKeyBytes.length === 33;\n\n\treturn {\n\t\thashMode: AddressHashMode.P2PKH,\n\t\tsigner,\n\t\tnonce,\n\t\tfee,\n\t\tkeyEncoding: isCompressed\n\t\t\t? PubKeyEncoding.Compressed\n\t\t\t: PubKeyEncoding.Uncompressed,\n\t\tsignature: EMPTY_SIG,\n\t};\n}\n\nexport function createStandardAuth(\n\tspendingCondition: SpendingCondition,\n): StandardAuthorization {\n\treturn { authType: AuthType.Standard, spendingCondition };\n}\n\nexport function createSponsoredAuth(\n\tspendingCondition: SpendingCondition,\n\tsponsorSpendingCondition?: SpendingCondition,\n): SponsoredAuthorization {\n\treturn {\n\t\tauthType: AuthType.Sponsored,\n\t\tspendingCondition,\n\t\tsponsorSpendingCondition:\n\t\t\tsponsorSpendingCondition ??\n\t\t\tcreateSingleSigSpendingCondition(\"0\".repeat(66), 0n, 0n),\n\t};\n}\n\nfunction clearCondition(condition: SpendingCondition): SpendingCondition {\n\tif (\"signature\" in condition) {\n\t\treturn {\n\t\t\t...condition,\n\t\t\tnonce: 0n,\n\t\t\tfee: 0n,\n\t\t\tsignature: EMPTY_SIG,\n\t\t};\n\t}\n\treturn {\n\t\t...condition,\n\t\tnonce: 0n,\n\t\tfee: 0n,\n\t\tfields: [],\n\t};\n}\n\nexport function intoInitialSighashAuth(auth: Authorization): Authorization {\n\tif (auth.authType === AuthType.Standard) {\n\t\treturn createStandardAuth(clearCondition(auth.spendingCondition));\n\t}\n\treturn createSponsoredAuth(\n\t\tclearCondition(auth.spendingCondition),\n\t\tclearCondition(createSingleSigSpendingCondition(\"0\".repeat(66), 0n, 0n)),\n\t);\n}\n\n/** Compute pre-sign sighash = sha512/256(prevSigHash + authType + fee + nonce) */\nexport function sigHashPreSign(\n\tcurSigHash: string,\n\tauthType: number,\n\tfee: bigint,\n\tnonce: bigint,\n): string {\n\tconst data = concatBytes(\n\t\thexToBytes(curSigHash),\n\t\tnew Uint8Array([authType]),\n\t\tintToBytes(fee, 8),\n\t\tintToBytes(nonce, 8),\n\t);\n\treturn txidFromBytes(data);\n}\n\n/** Compute post-sign sighash = sha512/256(preSigHash + pubKeyEncoding + signature) */\nexport function sigHashPostSign(\n\tcurSigHash: string,\n\tpubKeyEncoding: number,\n\tsignature: string,\n): string {\n\tconst data = concatBytes(\n\t\thexToBytes(curSigHash),\n\t\tnew Uint8Array([pubKeyEncoding]),\n\t\thexToBytes(signature),\n\t);\n\treturn txidFromBytes(data);\n}\n\n/** Sign with private key and return VRS signature (recoveryId + r + s) */\nfunction signWithKey(privateKey: string, messageHash: string): string {\n\tconst keyBytes = hexToBytes(privateKey).slice(0, 32);\n\tconst sig = sign(messageHash, keyBytes, { lowS: true });\n\tconst recoveryIdHex = intToHex(sig.recovery, 1);\n\treturn recoveryIdHex + sig.toCompactHex();\n}\n\nexport function nextSignature(\n\tcurSigHash: string,\n\tauthType: number,\n\tfee: bigint,\n\tnonce: bigint,\n\tprivateKey: string,\n): { nextSig: string; nextSigHash: string } {\n\tconst sigHashPre = sigHashPreSign(curSigHash, authType, fee, nonce);\n\n\tconst keyBytes = hexToBytes(privateKey).slice(0, 32);\n\tconst pubKey = nobleGetPublicKey(keyBytes, true);\n\tconst isCompressed = pubKey.length === 33;\n\tconst pubKeyEncoding = isCompressed\n\t\t? PubKeyEncoding.Compressed\n\t\t: PubKeyEncoding.Uncompressed;\n\n\tconst nextSig = signWithKey(privateKey, sigHashPre);\n\tconst nextSigHash = sigHashPostSign(sigHashPre, pubKeyEncoding, nextSig);\n\n\treturn { nextSig, nextSigHash };\n}\n",
|
|
28
|
+
"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",
|
|
29
|
+
"import {\n\tgetPublicKey as nobleGetPublicKey,\n\tsign as nobleSign,\n} from \"@noble/secp256k1\";\nimport type { CustomAccount, LocalAccount } from \"../accounts/types.ts\";\nimport type { StacksChain } from \"../chains/types.ts\";\nimport { c32address } from \"../utils/c32.ts\";\nimport {\n\tbytesToHex,\n\tconcatBytes,\n\thexToBytes,\n\tintToHex,\n} from \"../utils/encoding.ts\";\nimport { hash160 } from \"../utils/hash.ts\";\nimport { txidFromBytes } from \"../utils/hash.ts\";\nimport {\n\tintoInitialSighashAuth,\n\tnextSignature,\n\tsigHashPostSign,\n\tsigHashPreSign,\n} from \"./authorization.ts\";\nimport {\n\tAddressHashMode,\n\tAuthType,\n\ttype MultiSigHashMode,\n\ttype MultiSigSpendingCondition,\n\tPubKeyEncoding,\n\ttype StacksTransaction,\n\ttype TransactionAuthField,\n} from \"./types.ts\";\nimport { serializeTransaction } from \"./wire/serialize.ts\";\n\n// OP codes for redeem script\nconst OP_CHECKMULTISIG = 0xae;\n\n/** Check if hash mode is non-sequential (SIP-027) */\nexport function isNonSequential(hashMode: number): boolean {\n\treturn (hashMode & 0x04) !== 0;\n}\n\n/** Build a Bitcoin-style redeem script for m-of-n multi-sig */\nfunction makeRedeemScript(\n\tpublicKeys: string[],\n\tsignaturesRequired: number,\n): Uint8Array {\n\tconst parts: Uint8Array[] = [];\n\tparts.push(new Uint8Array([0x50 + signaturesRequired])); // OP_n\n\tfor (const pk of publicKeys) {\n\t\tconst pkBytes = hexToBytes(pk);\n\t\tparts.push(new Uint8Array([pkBytes.length])); // length prefix (0x21 for compressed)\n\t\tparts.push(pkBytes);\n\t}\n\tparts.push(new Uint8Array([0x50 + publicKeys.length])); // OP_m\n\tparts.push(new Uint8Array([OP_CHECKMULTISIG]));\n\treturn concatBytes(...parts);\n}\n\n/** Derive a multi-sig address from public keys */\nexport function makeMultiSigAddress(\n\tpublicKeys: string[],\n\tsignaturesRequired: number,\n\tchain?: StacksChain,\n): string {\n\tif (signaturesRequired < 1 || signaturesRequired > publicKeys.length) {\n\t\tthrow new Error(\n\t\t\t`signaturesRequired must be between 1 and ${publicKeys.length}`,\n\t\t);\n\t}\n\tconst redeemScript = makeRedeemScript(publicKeys, signaturesRequired);\n\tconst signer = hash160(redeemScript);\n\tconst version = chain?.addressVersion?.multiSig ?? 20; // mainnet default\n\treturn c32address(version, bytesToHex(signer));\n}\n\n/** Create an empty multi-sig spending condition */\nexport function createMultiSigSpendingCondition(\n\tpublicKeys: string[],\n\tsignaturesRequired: number,\n\tnonce: bigint,\n\tfee: bigint,\n\thashMode: MultiSigHashMode = AddressHashMode.P2SH,\n): MultiSigSpendingCondition {\n\tconst redeemScript = makeRedeemScript(publicKeys, signaturesRequired);\n\tconst signer = bytesToHex(hash160(redeemScript));\n\n\treturn {\n\t\thashMode,\n\t\tsigner,\n\t\tnonce,\n\t\tfee,\n\t\tfields: [],\n\t\tsignaturesRequired,\n\t};\n}\n\n/** Compute the initial sighash for a transaction (same as signBegin) */\nfunction initialSigHash(tx: StacksTransaction): string {\n\tconst cleared: StacksTransaction = {\n\t\t...tx,\n\t\tauth: intoInitialSighashAuth(tx.auth),\n\t};\n\treturn txidFromBytes(serializeTransaction(cleared));\n}\n\n/** Compute the presign-sighash used by all non-sequential signers */\nfunction nonSequentialPreSignHash(tx: StacksTransaction): string {\n\tconst condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n\tconst initHash = initialSigHash(tx);\n\treturn sigHashPreSign(\n\t\tinitHash,\n\t\tAuthType.Standard,\n\t\tcondition.fee,\n\t\tcondition.nonce,\n\t);\n}\n\n/** Replay sighash through existing auth fields of a multi-sig tx */\nexport function replayMultiSigSigHash(tx: StacksTransaction): string {\n\tconst condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n\n\t// Non-sequential: all signers sign the same presign-sighash, no field chaining\n\tif (isNonSequential(condition.hashMode)) {\n\t\tconst preSign = nonSequentialPreSignHash(tx);\n\t\t// Chain through all fields to get the final sighash\n\t\tlet curSigHash = preSign;\n\t\tfor (const field of condition.fields) {\n\t\t\tcurSigHash = sigHashPostSign(\n\t\t\t\tcurSigHash,\n\t\t\t\tfield.pubKeyEncoding,\n\t\t\t\tfield.data,\n\t\t\t);\n\t\t}\n\t\treturn curSigHash;\n\t}\n\n\t// Sequential: chain through all fields\n\tlet curSigHash = initialSigHash(tx);\n\tfor (const field of condition.fields) {\n\t\tconst preSign = sigHashPreSign(\n\t\t\tcurSigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tcurSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n\t}\n\treturn curSigHash;\n}\n\n/** Sign one position of a multi-sig transaction with a private key */\nexport function signMultiSig(\n\ttx: StacksTransaction,\n\tprivateKey: string,\n\tpublicKeys: string[],\n): StacksTransaction {\n\tconst keyBytes = hexToBytes(privateKey).slice(0, 32);\n\tconst signerPubKey = bytesToHex(nobleGetPublicKey(keyBytes, true));\n\n\tconst signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);\n\tif (signerIndex === -1) {\n\t\tthrow new Error(\n\t\t\t\"Private key does not correspond to any signer in the multi-sig\",\n\t\t);\n\t}\n\n\tconst condition = {\n\t\t...(tx.auth.spendingCondition as MultiSigSpendingCondition),\n\t};\n\n\t// Non-sequential: all signers sign the same presign-sighash independently\n\tif (isNonSequential(condition.hashMode)) {\n\t\treturn signNonSequential(tx, condition, privateKey);\n\t}\n\n\t// Sequential: existing P2SH behavior\n\treturn signSequential(tx, condition, privateKey, publicKeys, signerIndex);\n}\n\n/** Non-sequential signing: compute presign-sighash from initial tx, sign, append */\nfunction signNonSequential(\n\ttx: StacksTransaction,\n\tcondition: MultiSigSpendingCondition,\n\tprivateKey: string,\n): StacksTransaction {\n\tconst fields = [...condition.fields];\n\tconst preSignHash = nonSequentialPreSignHash(tx);\n\n\t// Sign the presign-sighash directly\n\tconst keyBytes = hexToBytes(privateKey).slice(0, 32);\n\tconst sig = nobleSign(preSignHash, keyBytes, { lowS: true });\n\tconst recoveryIdHex = intToHex(sig.recovery, 1);\n\tconst nextSig = recoveryIdHex + sig.toCompactHex();\n\n\tfields.push({\n\t\ttype: \"signature\",\n\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\tdata: nextSig,\n\t});\n\n\tconst newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\tconst sigCount = fields.filter((f) => f.type === \"signature\").length;\n\n\t// Auto-finalize: non-sequential needs no pubkey gap-filling\n\tif (sigCount >= condition.signaturesRequired) {\n\t\treturn {\n\t\t\t...tx,\n\t\t\tauth: { ...tx.auth, spendingCondition: newCondition },\n\t\t};\n\t}\n\n\treturn {\n\t\t...tx,\n\t\tauth: { ...tx.auth, spendingCondition: newCondition },\n\t};\n}\n\n/** Sequential signing: existing P2SH behavior */\nfunction signSequential(\n\ttx: StacksTransaction,\n\tcondition: MultiSigSpendingCondition,\n\tprivateKey: string,\n\tpublicKeys: string[],\n\tsignerIndex: number,\n): StacksTransaction {\n\tconst fields = [...condition.fields];\n\n\t// Replay sighash through existing fields\n\tlet curSigHash = initialSigHash(tx);\n\tfor (const field of fields) {\n\t\tconst preSign = sigHashPreSign(\n\t\t\tcurSigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tcurSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n\t}\n\n\t// Fill intervening positions with pubkey fields\n\tfor (let i = fields.length; i < signerIndex; i++) {\n\t\tconst pubKeyField: TransactionAuthField = {\n\t\t\ttype: \"publicKey\",\n\t\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\t\tdata: publicKeys[i]!,\n\t\t};\n\t\tfields.push(pubKeyField);\n\t\tconst preSign = sigHashPreSign(\n\t\t\tcurSigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tcurSigHash = sigHashPostSign(\n\t\t\tpreSign,\n\t\t\tpubKeyField.pubKeyEncoding,\n\t\t\tpubKeyField.data,\n\t\t);\n\t}\n\n\t// Sign at signerIndex\n\tconst { nextSig, nextSigHash } = nextSignature(\n\t\tcurSigHash,\n\t\tAuthType.Standard,\n\t\tcondition.fee,\n\t\tcondition.nonce,\n\t\tprivateKey,\n\t);\n\n\tfields.push({\n\t\ttype: \"signature\",\n\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\tdata: nextSig,\n\t});\n\tcurSigHash = nextSigHash;\n\n\tconst newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n\t// Count signatures so far\n\tconst sigCount = fields.filter((f) => f.type === \"signature\").length;\n\tlet finalCondition = newCondition;\n\n\t// Auto-finalize if enough signatures collected\n\tif (sigCount >= condition.signaturesRequired) {\n\t\tfinalCondition = finalizeMultiSigCondition(\n\t\t\tnewCondition,\n\t\t\tpublicKeys,\n\t\t\tcurSigHash,\n\t\t);\n\t}\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...tx.auth,\n\t\t\tspendingCondition: finalCondition,\n\t\t},\n\t};\n}\n\n/** Sign one position of a multi-sig transaction with an account */\nexport async function signMultiSigWithAccount(\n\ttx: StacksTransaction,\n\taccount: LocalAccount | CustomAccount,\n\tpublicKeys: string[],\n): Promise<StacksTransaction> {\n\tconst signerPubKey = account.publicKey;\n\n\tconst signerIndex = publicKeys.findIndex((pk) => pk === signerPubKey);\n\tif (signerIndex === -1) {\n\t\tthrow new Error(\n\t\t\t\"Account does not correspond to any signer in the multi-sig\",\n\t\t);\n\t}\n\n\tconst condition = {\n\t\t...(tx.auth.spendingCondition as MultiSigSpendingCondition),\n\t};\n\n\t// Non-sequential: all signers sign the same presign-sighash independently\n\tif (isNonSequential(condition.hashMode)) {\n\t\treturn signNonSequentialWithAccount(tx, condition, account);\n\t}\n\n\t// Sequential: existing behavior\n\treturn signSequentialWithAccount(\n\t\ttx,\n\t\tcondition,\n\t\taccount,\n\t\tpublicKeys,\n\t\tsignerIndex,\n\t);\n}\n\n/** Non-sequential signing with account */\nasync function signNonSequentialWithAccount(\n\ttx: StacksTransaction,\n\tcondition: MultiSigSpendingCondition,\n\taccount: LocalAccount | CustomAccount,\n): Promise<StacksTransaction> {\n\tconst fields = [...condition.fields];\n\tconst preSignHash = nonSequentialPreSignHash(tx);\n\n\tconst sigBytes = await account.sign(hexToBytes(preSignHash));\n\tconst nextSig = bytesToHex(sigBytes);\n\n\tfields.push({\n\t\ttype: \"signature\",\n\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\tdata: nextSig,\n\t});\n\n\tconst newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n\treturn {\n\t\t...tx,\n\t\tauth: { ...tx.auth, spendingCondition: newCondition },\n\t};\n}\n\n/** Sequential signing with account */\nasync function signSequentialWithAccount(\n\ttx: StacksTransaction,\n\tcondition: MultiSigSpendingCondition,\n\taccount: LocalAccount | CustomAccount,\n\tpublicKeys: string[],\n\tsignerIndex: number,\n): Promise<StacksTransaction> {\n\tconst fields = [...condition.fields];\n\n\t// Replay sighash through existing fields\n\tlet curSigHash = initialSigHash(tx);\n\tfor (const field of fields) {\n\t\tconst preSign = sigHashPreSign(\n\t\t\tcurSigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tcurSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);\n\t}\n\n\t// Fill intervening positions with pubkey fields\n\tfor (let i = fields.length; i < signerIndex; i++) {\n\t\tconst pubKeyField: TransactionAuthField = {\n\t\t\ttype: \"publicKey\",\n\t\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\t\tdata: publicKeys[i]!,\n\t\t};\n\t\tfields.push(pubKeyField);\n\t\tconst preSign = sigHashPreSign(\n\t\t\tcurSigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tcurSigHash = sigHashPostSign(\n\t\t\tpreSign,\n\t\t\tpubKeyField.pubKeyEncoding,\n\t\t\tpubKeyField.data,\n\t\t);\n\t}\n\n\t// Sign at signerIndex\n\tconst preSign = sigHashPreSign(\n\t\tcurSigHash,\n\t\tAuthType.Standard,\n\t\tcondition.fee,\n\t\tcondition.nonce,\n\t);\n\tconst sigBytes = await account.sign(hexToBytes(preSign));\n\tconst nextSig = bytesToHex(sigBytes);\n\tconst nextSigHash = sigHashPostSign(\n\t\tpreSign,\n\t\tPubKeyEncoding.Compressed,\n\t\tnextSig,\n\t);\n\n\tfields.push({\n\t\ttype: \"signature\",\n\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\tdata: nextSig,\n\t});\n\tcurSigHash = nextSigHash;\n\n\tconst newCondition: MultiSigSpendingCondition = { ...condition, fields };\n\n\t// Count signatures so far\n\tconst sigCount = fields.filter((f) => f.type === \"signature\").length;\n\tlet finalCondition = newCondition;\n\n\t// Auto-finalize if enough signatures collected\n\tif (sigCount >= condition.signaturesRequired) {\n\t\tfinalCondition = finalizeMultiSigCondition(\n\t\t\tnewCondition,\n\t\t\tpublicKeys,\n\t\t\tcurSigHash,\n\t\t);\n\t}\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...tx.auth,\n\t\t\tspendingCondition: finalCondition,\n\t\t},\n\t};\n}\n\n/** Fill remaining slots with pubkey fields after all signatures are collected */\nexport function finalizeMultiSig(\n\ttx: StacksTransaction,\n\tpublicKeys: string[],\n): StacksTransaction {\n\tconst condition = tx.auth.spendingCondition as MultiSigSpendingCondition;\n\n\t// Non-sequential: no pubkey gap-filling needed\n\tif (isNonSequential(condition.hashMode)) {\n\t\treturn tx;\n\t}\n\n\tconst curSigHash = replayMultiSigSigHash(tx);\n\tconst finalCondition = finalizeMultiSigCondition(\n\t\tcondition,\n\t\tpublicKeys,\n\t\tcurSigHash,\n\t);\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...tx.auth,\n\t\t\tspendingCondition: finalCondition,\n\t\t},\n\t};\n}\n\n/** Internal: finalize remaining pubkey slots (sequential only) */\nfunction finalizeMultiSigCondition(\n\tcondition: MultiSigSpendingCondition,\n\tpublicKeys: string[],\n\tcurSigHash: string,\n): MultiSigSpendingCondition {\n\tconst fields = [...condition.fields];\n\tlet sigHash = curSigHash;\n\n\t// Fill remaining positions\n\tfor (let i = fields.length; i < publicKeys.length; i++) {\n\t\tconst pubKeyField: TransactionAuthField = {\n\t\t\ttype: \"publicKey\",\n\t\t\tpubKeyEncoding: PubKeyEncoding.Compressed,\n\t\t\tdata: publicKeys[i]!,\n\t\t};\n\t\tfields.push(pubKeyField);\n\t\tconst preSign = sigHashPreSign(\n\t\t\tsigHash,\n\t\t\tAuthType.Standard,\n\t\t\tcondition.fee,\n\t\t\tcondition.nonce,\n\t\t);\n\t\tsigHash = sigHashPostSign(\n\t\t\tpreSign,\n\t\t\tpubKeyField.pubKeyEncoding,\n\t\t\tpubKeyField.data,\n\t\t);\n\t}\n\n\treturn { ...condition, fields };\n}\n\n/** Combine independently-signed non-sequential multi-sig transactions */\nexport function combineMultiSigSignatures(\n\tbaseTx: StacksTransaction,\n\tsignedTxs: StacksTransaction[],\n): StacksTransaction {\n\tconst condition = baseTx.auth.spendingCondition as MultiSigSpendingCondition;\n\n\tif (!isNonSequential(condition.hashMode)) {\n\t\tthrow new Error(\n\t\t\t\"combineMultiSigSignatures only works with non-sequential hash modes (SIP-027)\",\n\t\t);\n\t}\n\n\t// Collect all signature fields from each signed tx\n\tconst seenSigs = new Set<string>();\n\tconst signatures: TransactionAuthField[] = [];\n\n\tfor (const stx of signedTxs) {\n\t\tconst stxCondition = stx.auth\n\t\t\t.spendingCondition as MultiSigSpendingCondition;\n\t\tfor (const field of stxCondition.fields) {\n\t\t\tif (field.type === \"signature\" && !seenSigs.has(field.data)) {\n\t\t\t\tseenSigs.add(field.data);\n\t\t\t\tsignatures.push(field);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (signatures.length === 0) {\n\t\tthrow new Error(\"No signatures found in the provided transactions\");\n\t}\n\n\tconst newCondition: MultiSigSpendingCondition = {\n\t\t...condition,\n\t\tfields: signatures,\n\t};\n\n\treturn {\n\t\t...baseTx,\n\t\tauth: { ...baseTx.auth, spendingCondition: newCondition },\n\t};\n}\n",
|
|
30
|
+
"import type { StacksChain } from \"../chains/types.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport { parseContractId } from \"../utils/address.ts\";\nimport { type IntegerType, intToBigInt } from \"../utils/encoding.ts\";\nimport {\n\tcreateSingleSigSpendingCondition,\n\tcreateSponsoredAuth,\n\tcreateStandardAuth,\n} from \"./authorization.ts\";\nimport { createMultiSigSpendingCondition } from \"./multisig.ts\";\nimport type { MultiSigHashMode, SpendingCondition } from \"./types.ts\";\nimport {\n\tAnchorMode,\n\ttype ClarityVersion,\n\tFungibleConditionCode,\n\tNonFungibleConditionCode,\n\tPayloadType,\n\tPostConditionModeWire,\n\ttype PostConditionPrincipalWire,\n\ttype PostConditionWire,\n\ttype StacksTransaction,\n} from \"./types.ts\";\n\ntype MultiSigOptions = {\n\tpublicKeys?: string[];\n\tsignaturesRequired?: number;\n\thashMode?: MultiSigHashMode;\n};\n\nexport type BuildTokenTransferOptions = MultiSigOptions & {\n\trecipient: string;\n\tamount: IntegerType;\n\tmemo?: string;\n\tfee: IntegerType;\n\tnonce: IntegerType;\n\tpublicKey?: string;\n\tchain?: StacksChain;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n\tsponsored?: boolean;\n};\n\nexport type BuildContractCallOptions = MultiSigOptions & {\n\tcontractAddress: string;\n\tcontractName: string;\n\tfunctionName: string;\n\tfunctionArgs: ClarityValue[];\n\tfee: IntegerType;\n\tnonce: IntegerType;\n\tpublicKey?: string;\n\tchain?: StacksChain;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n\tsponsored?: boolean;\n};\n\nexport type BuildContractDeployOptions = MultiSigOptions & {\n\tcontractName: string;\n\tcodeBody: string;\n\tclarityVersion?: ClarityVersion;\n\tfee: IntegerType;\n\tnonce: IntegerType;\n\tpublicKey?: string;\n\tchain?: StacksChain;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n\tsponsored?: boolean;\n};\n\nfunction resolvePcMode(mode?: \"allow\" | \"deny\"): PostConditionModeWire {\n\treturn mode === \"allow\"\n\t\t? PostConditionModeWire.Allow\n\t\t: PostConditionModeWire.Deny;\n}\n\nfunction convertPostConditions(pcs?: PostCondition[]): PostConditionWire[] {\n\tif (!pcs || pcs.length === 0) return [];\n\treturn pcs.map(convertPostCondition);\n}\n\nfunction resolvePrincipal(address: string): PostConditionPrincipalWire {\n\tif (address === \"origin\") return { type: \"origin\" };\n\tconst [addr, name] = address.split(\".\");\n\tif (name) {\n\t\treturn { type: \"contract\", address: addr!, contractName: name };\n\t}\n\treturn { type: \"standard\", address: addr! };\n}\n\nconst FUNGIBLE_CODE_MAP: Record<string, number> = {\n\teq: FungibleConditionCode.Equal,\n\tgt: FungibleConditionCode.Greater,\n\tgte: FungibleConditionCode.GreaterEqual,\n\tlt: FungibleConditionCode.Less,\n\tlte: FungibleConditionCode.LessEqual,\n};\n\nfunction convertPostCondition(pc: PostCondition): PostConditionWire {\n\tswitch (pc.type) {\n\t\tcase \"stx-postcondition\":\n\t\t\treturn {\n\t\t\t\ttype: \"stx\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tconditionCode: FUNGIBLE_CODE_MAP[pc.condition]!,\n\t\t\t\tamount: intToBigInt(pc.amount),\n\t\t\t};\n\t\tcase \"ft-postcondition\": {\n\t\t\tconst [contractId, tokenName] = pc.asset.split(\"::\");\n\t\t\tconst [addr, name] = parseContractId(contractId!);\n\t\t\treturn {\n\t\t\t\ttype: \"ft\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tasset: { address: addr, contractName: name, assetName: tokenName! },\n\t\t\t\tconditionCode: FUNGIBLE_CODE_MAP[pc.condition]!,\n\t\t\t\tamount: intToBigInt(pc.amount),\n\t\t\t};\n\t\t}\n\t\tcase \"nft-postcondition\": {\n\t\t\tconst [contractId, tokenName] = pc.asset.split(\"::\");\n\t\t\tconst [addr, name] = parseContractId(contractId!);\n\t\t\treturn {\n\t\t\t\ttype: \"nft\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tasset: { address: addr, contractName: name, assetName: tokenName! },\n\t\t\t\tconditionCode:\n\t\t\t\t\tpc.condition === \"sent\"\n\t\t\t\t\t\t? NonFungibleConditionCode.Sends\n\t\t\t\t\t\t: NonFungibleConditionCode.DoesNotSend,\n\t\t\t\tassetId: pc.assetId,\n\t\t\t};\n\t\t}\n\t}\n}\n\nimport type { Authorization } from \"./types.ts\";\n\nfunction resolveSpendingCondition(\n\topts: MultiSigOptions & { publicKey?: string },\n\tnonce: bigint,\n\tfee: bigint,\n): SpendingCondition {\n\tif (opts.publicKeys) {\n\t\treturn createMultiSigSpendingCondition(\n\t\t\topts.publicKeys,\n\t\t\topts.signaturesRequired!,\n\t\t\tnonce,\n\t\t\tfee,\n\t\t\topts.hashMode,\n\t\t);\n\t}\n\treturn createSingleSigSpendingCondition(opts.publicKey!, nonce, fee);\n}\n\nfunction resolveAuth(\n\tspendingCondition: any,\n\tsponsored?: boolean,\n): Authorization {\n\treturn sponsored\n\t\t? createSponsoredAuth(spendingCondition)\n\t\t: createStandardAuth(spendingCondition);\n}\n\nfunction resolveVersionAndChainId(chain?: StacksChain): {\n\tversion: number;\n\tchainId: number;\n} {\n\tif (!chain) return { version: 0x00, chainId: 0x00000001 }; // mainnet defaults\n\treturn { version: chain.transactionVersion, chainId: chain.id };\n}\n\nexport function buildTokenTransfer(\n\toptions: BuildTokenTransferOptions,\n): StacksTransaction {\n\tconst { version, chainId } = resolveVersionAndChainId(options.chain);\n\tconst fee = intToBigInt(options.fee);\n\tconst nonce = intToBigInt(options.nonce);\n\n\tconst spendingCondition = resolveSpendingCondition(options, nonce, fee);\n\tconst recipient = Cl.principal(options.recipient);\n\n\tconst tx: StacksTransaction = {\n\t\tversion,\n\t\tchainId,\n\t\tauth: resolveAuth(spendingCondition, options.sponsored),\n\t\tanchorMode: AnchorMode.Any,\n\t\tpostConditionMode: resolvePcMode(options.postConditionMode),\n\t\tpostConditions: convertPostConditions(options.postConditions),\n\t\tpayload: {\n\t\t\tpayloadType: PayloadType.TokenTransfer,\n\t\t\trecipient,\n\t\t\tamount: intToBigInt(options.amount),\n\t\t\tmemo: options.memo ?? \"\",\n\t\t},\n\t};\n\n\tif (options.publicKeys) {\n\t\t(tx as any)._multisig = { publicKeys: options.publicKeys };\n\t}\n\treturn tx;\n}\n\nexport function buildContractCall(\n\toptions: BuildContractCallOptions,\n): StacksTransaction {\n\tconst { version, chainId } = resolveVersionAndChainId(options.chain);\n\tconst fee = intToBigInt(options.fee);\n\tconst nonce = intToBigInt(options.nonce);\n\n\tconst spendingCondition = resolveSpendingCondition(options, nonce, fee);\n\n\tconst tx: StacksTransaction = {\n\t\tversion,\n\t\tchainId,\n\t\tauth: resolveAuth(spendingCondition, options.sponsored),\n\t\tanchorMode: AnchorMode.Any,\n\t\tpostConditionMode: resolvePcMode(options.postConditionMode),\n\t\tpostConditions: convertPostConditions(options.postConditions),\n\t\tpayload: {\n\t\t\tpayloadType: PayloadType.ContractCall,\n\t\t\tcontractAddress: options.contractAddress,\n\t\t\tcontractName: options.contractName,\n\t\t\tfunctionName: options.functionName,\n\t\t\tfunctionArgs: options.functionArgs,\n\t\t},\n\t};\n\n\tif (options.publicKeys) {\n\t\t(tx as any)._multisig = { publicKeys: options.publicKeys };\n\t}\n\treturn tx;\n}\n\nexport function buildContractDeploy(\n\toptions: BuildContractDeployOptions,\n): StacksTransaction {\n\tconst { version, chainId } = resolveVersionAndChainId(options.chain);\n\tconst fee = intToBigInt(options.fee);\n\tconst nonce = intToBigInt(options.nonce);\n\n\tconst spendingCondition = resolveSpendingCondition(options, nonce, fee);\n\tconst useVersioned = options.clarityVersion !== undefined;\n\n\tconst tx: StacksTransaction = {\n\t\tversion,\n\t\tchainId,\n\t\tauth: resolveAuth(spendingCondition, options.sponsored),\n\t\tanchorMode: AnchorMode.Any,\n\t\tpostConditionMode: resolvePcMode(options.postConditionMode),\n\t\tpostConditions: convertPostConditions(options.postConditions),\n\t\tpayload: {\n\t\t\tpayloadType: useVersioned\n\t\t\t\t? PayloadType.VersionedSmartContract\n\t\t\t\t: PayloadType.SmartContract,\n\t\t\tclarityVersion: options.clarityVersion,\n\t\t\tcontractName: options.contractName,\n\t\t\tcodeBody: options.codeBody,\n\t\t},\n\t};\n\n\tif (options.publicKeys) {\n\t\t(tx as any)._multisig = { publicKeys: options.publicKeys };\n\t}\n\treturn tx;\n}\n",
|
|
31
|
+
"import type { CustomAccount, LocalAccount } from \"../accounts/types.ts\";\nimport { bytesToHex, hexToBytes } from \"../utils/encoding.ts\";\nimport { txidFromBytes } from \"../utils/hash.ts\";\nimport {\n\tintoInitialSighashAuth,\n\tnextSignature,\n\tsigHashPostSign,\n\tsigHashPreSign,\n} from \"./authorization.ts\";\nimport { replayMultiSigSigHash } from \"./multisig.ts\";\nimport {\n\tAuthType,\n\ttype SingleSigSpendingCondition,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"./types.ts\";\nimport { serializeTransaction } from \"./wire/serialize.ts\";\n\nfunction txid(tx: StacksTransaction): string {\n\treturn txidFromBytes(serializeTransaction(tx));\n}\n\n/** Compute the initial sighash for a transaction */\nexport function signBegin(tx: StacksTransaction): string {\n\tconst cleared: StacksTransaction = {\n\t\t...tx,\n\t\tauth: intoInitialSighashAuth(tx.auth),\n\t};\n\treturn txid(cleared);\n}\n\n/** Sign a single-sig transaction with a private key, returning the signed transaction */\nexport function signTransaction(\n\ttx: StacksTransaction,\n\tprivateKey: string,\n): StacksTransaction {\n\tconst sigHash = signBegin(tx);\n\tconst condition = tx.auth.spendingCondition as SingleSigSpendingCondition;\n\n\t// Origin always signs with AuthType.Standard (even for sponsored txs)\n\tconst { nextSig } = nextSignature(\n\t\tsigHash,\n\t\tAuthType.Standard,\n\t\tcondition.fee,\n\t\tcondition.nonce,\n\t\tprivateKey,\n\t);\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...tx.auth,\n\t\t\tspendingCondition: {\n\t\t\t\t...condition,\n\t\t\t\tsignature: nextSig,\n\t\t\t},\n\t\t},\n\t};\n}\n\n/** Sign a single-sig transaction using an account (LocalAccount or CustomAccount) */\nexport async function signTransactionWithAccount(\n\ttx: StacksTransaction,\n\taccount: LocalAccount | CustomAccount,\n): Promise<StacksTransaction> {\n\tconst sigHash = signBegin(tx);\n\tconst condition = tx.auth.spendingCondition as SingleSigSpendingCondition;\n\n\t// Origin always signs with AuthType.Standard (even for sponsored txs)\n\tconst sigHashPre = sigHashPreSign(\n\t\tsigHash,\n\t\tAuthType.Standard,\n\t\tcondition.fee,\n\t\tcondition.nonce,\n\t);\n\n\t// account.sign returns 65-byte VRS (recovery + r + s)\n\tconst sigBytes = await account.sign(hexToBytes(sigHashPre));\n\tconst nextSig = bytesToHex(sigBytes);\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...tx.auth,\n\t\t\tspendingCondition: {\n\t\t\t\t...condition,\n\t\t\t\tsignature: nextSig,\n\t\t\t},\n\t\t},\n\t};\n}\n\n/** Get the txid of a transaction */\nexport function getTransactionId(tx: StacksTransaction): string {\n\treturn txid(tx);\n}\n\n/** Reconstruct the sighash after origin signing (needed for sponsor signing) */\nexport function getOriginSigHash(tx: StacksTransaction): string {\n\tconst condition = tx.auth.spendingCondition;\n\n\t// Multi-sig: replay through all fields\n\tif (\"fields\" in condition) {\n\t\treturn replayMultiSigSigHash(tx);\n\t}\n\n\t// Single-sig\n\tconst initialSigHash = signBegin(tx);\n\tconst sc = condition as SingleSigSpendingCondition;\n\tconst preSign = sigHashPreSign(\n\t\tinitialSigHash,\n\t\tAuthType.Standard,\n\t\tsc.fee,\n\t\tsc.nonce,\n\t);\n\treturn sigHashPostSign(preSign, sc.keyEncoding, sc.signature);\n}\n\n/** Sign a sponsored transaction as the sponsor with a private key */\nexport function signSponsor(\n\ttx: StacksTransaction,\n\tprivateKey: string,\n): StacksTransaction {\n\tif (tx.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must be sponsored\");\n\t}\n\tconst auth = tx.auth as SponsoredAuthorization;\n\tconst sponsorCondition =\n\t\tauth.sponsorSpendingCondition as SingleSigSpendingCondition;\n\tconst originSigHash = getOriginSigHash(tx);\n\n\tconst { nextSig } = nextSignature(\n\t\toriginSigHash,\n\t\tAuthType.Sponsored,\n\t\tsponsorCondition.fee,\n\t\tsponsorCondition.nonce,\n\t\tprivateKey,\n\t);\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: {\n\t\t\t\t...sponsorCondition,\n\t\t\t\tsignature: nextSig,\n\t\t\t},\n\t\t},\n\t};\n}\n\n/** Sign a sponsored transaction as the sponsor using an account */\nexport async function signSponsorWithAccount(\n\ttx: StacksTransaction,\n\taccount: LocalAccount | CustomAccount,\n): Promise<StacksTransaction> {\n\tif (tx.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must be sponsored\");\n\t}\n\tconst auth = tx.auth as SponsoredAuthorization;\n\tconst sponsorCondition =\n\t\tauth.sponsorSpendingCondition as SingleSigSpendingCondition;\n\tconst originSigHash = getOriginSigHash(tx);\n\n\tconst sigHashPre = sigHashPreSign(\n\t\toriginSigHash,\n\t\tAuthType.Sponsored,\n\t\tsponsorCondition.fee,\n\t\tsponsorCondition.nonce,\n\t);\n\n\tconst sigBytes = await account.sign(hexToBytes(sigHashPre));\n\tconst nextSig = bytesToHex(sigBytes);\n\n\treturn {\n\t\t...tx,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: {\n\t\t\t\t...sponsorCondition,\n\t\t\t\tsignature: nextSig,\n\t\t\t},\n\t\t},\n\t};\n}\n",
|
|
32
|
+
"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\treturn BigInt(data.nonce);\n}\n",
|
|
33
|
+
"export class BaseError extends Error {\n\toverride name = \"StacksError\";\n\tshortMessage: string;\n\tdetails?: string;\n\n\tconstructor(\n\t\tshortMessage: string,\n\t\toptions?: { cause?: Error; details?: string },\n\t) {\n\t\tconst message = [\n\t\t\tshortMessage,\n\t\t\toptions?.details ? `\\n${options.details}` : \"\",\n\t\t].join(\"\");\n\n\t\tsuper(message, { cause: options?.cause });\n\t\tthis.shortMessage = shortMessage;\n\t\tthis.details = options?.details;\n\t}\n\n\ttoJSON(): {\n\t\tname: string;\n\t\tmessage: string;\n\t\tshortMessage: string;\n\t\tdetails: string | undefined;\n\t\tcause: string | undefined;\n\t} {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.message,\n\t\t\tshortMessage: this.shortMessage,\n\t\t\tdetails: this.details,\n\t\t\tcause: this.cause instanceof Error ? this.cause.message : undefined,\n\t\t};\n\t}\n}\n",
|
|
34
|
+
"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",
|
|
35
|
+
"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",
|
|
36
|
+
"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",
|
|
37
|
+
"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 { getNonce } from \"../public/getNonce.ts\";\nimport { sendTransaction } from \"./sendTransaction.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// 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 [contractAddress, contractName] = parseContractId(params.contract);\n\n\tconst nonce =\n\t\tparams.nonce ?? (await getNonce(client, { address: 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(unsigned.auth.spendingCondition as any).fee = BigInt(mid.fee);\n\t\t}\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\tconst result = await sendTransaction(client, { transaction: signed });\n\treturn result.txid;\n}\n",
|
|
38
|
+
"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 */\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(\n\t\tmessage: string,\n\t\tpublic readonly errorValue: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n",
|
|
39
|
+
"import type { AbiContract } from \"../clarity/abi/contract.ts\";\n\nexport const BNS_ABI = {\n\tfunctions: [\n\t\t// Name resolution (read-only)\n\t\t{\n\t\t\tname: \"get-owner-name\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: { optional: \"principal\" },\n\t\t\t\t\terror: \"uint128\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"get-id-from-bns\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t],\n\t\t\toutputs: { optional: \"uint128\" },\n\t\t},\n\t\t{\n\t\t\tname: \"get-bns-from-id\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [{ name: \"id\", type: \"uint128\" }],\n\t\t\toutputs: {\n\t\t\t\toptional: {\n\t\t\t\t\ttuple: [\n\t\t\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"get-owner\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [{ name: \"id\", type: \"uint128\" }],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: { optional: \"principal\" },\n\t\t\t\t\terror: \"none\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"get-primary\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [{ name: \"owner\", type: \"principal\" }],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: {\n\t\t\t\t\t\toptional: {\n\t\t\t\t\t\t\ttuple: [\n\t\t\t\t\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\terror: \"none\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"can-resolve-name\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: {\n\t\t\t\t\t\ttuple: [\n\t\t\t\t\t\t\t{ name: \"renewal\", type: \"uint128\" },\n\t\t\t\t\t\t\t{ name: \"owner\", type: \"principal\" },\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\terror: \"uint128\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"get-renewal-height\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [{ name: \"id\", type: \"uint128\" }],\n\t\t\toutputs: { response: { ok: \"uint128\", error: \"uint128\" } },\n\t\t},\n\t\t{\n\t\t\tname: \"get-name-price\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t],\n\t\t\toutputs: {\n\t\t\t\tresponse: {\n\t\t\t\t\tok: { response: { ok: \"uint128\", error: \"uint128\" } },\n\t\t\t\t\terror: \"uint128\",\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: \"get-bns-info\",\n\t\t\taccess: \"read-only\",\n\t\t\targs: [\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t],\n\t\t\toutputs: {\n\t\t\t\toptional: {\n\t\t\t\t\ttuple: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: \"hashed-salted-fqn-preorder\",\n\t\t\t\t\t\t\ttype: { optional: { buff: { length: 20 } } },\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ name: \"imported-at\", type: { optional: \"uint128\" } },\n\t\t\t\t\t\t{ name: \"owner\", type: \"principal\" },\n\t\t\t\t\t\t{ name: \"preordered-by\", type: { optional: \"principal\" } },\n\t\t\t\t\t\t{ name: \"registered-at\", type: { optional: \"uint128\" } },\n\t\t\t\t\t\t{ name: \"renewal-height\", type: \"uint128\" },\n\t\t\t\t\t\t{ name: \"stx-burn\", type: \"uint128\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\n\t\t// Name registration (public)\n\t\t{\n\t\t\tname: \"name-preorder\",\n\t\t\taccess: \"public\",\n\t\t\targs: [\n\t\t\t\t{ name: \"hashed-salted-fqn\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"stx-to-burn\", type: \"uint128\" },\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"uint128\", error: \"uint128\" } },\n\t\t},\n\t\t{\n\t\t\tname: \"name-register\",\n\t\t\taccess: \"public\",\n\t\t\targs: [\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t{ name: \"salt\", type: { buff: { length: 20 } } },\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"uint128\", error: \"uint128\" } },\n\t\t},\n\t\t{\n\t\t\tname: \"name-claim-fast\",\n\t\t\taccess: \"public\",\n\t\t\targs: [\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"send-to\", type: \"principal\" },\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"uint128\", error: \"uint128\" } },\n\t\t},\n\t\t{\n\t\t\tname: \"name-renewal\",\n\t\t\taccess: \"public\",\n\t\t\targs: [\n\t\t\t\t{ name: \"namespace\", type: { buff: { length: 20 } } },\n\t\t\t\t{ name: \"name\", type: { buff: { length: 48 } } },\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"bool\", error: \"uint128\" } },\n\t\t},\n\n\t\t// Name management (public)\n\t\t{\n\t\t\tname: \"transfer\",\n\t\t\taccess: \"public\",\n\t\t\targs: [\n\t\t\t\t{ name: \"id\", type: \"uint128\" },\n\t\t\t\t{ name: \"owner\", type: \"principal\" },\n\t\t\t\t{ name: \"recipient\", type: \"principal\" },\n\t\t\t],\n\t\t\toutputs: { response: { ok: \"bool\", error: \"uint128\" } },\n\t\t},\n\t\t{\n\t\t\tname: \"set-primary-name\",\n\t\t\taccess: \"public\",\n\t\t\targs: [{ name: \"primary-name-id\", type: \"uint128\" }],\n\t\t\toutputs: { response: { ok: \"bool\", error: \"uint128\" } },\n\t\t},\n\t],\n\tnon_fungible_tokens: [{ name: \"BNS-V2\", type: \"uint128\" }],\n} as const satisfies AbiContract;\n",
|
|
40
|
+
"export const BNS_CONTRACTS = {\n\tmainnet: {\n\t\taddress: \"SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF\",\n\t\tname: \"BNS-V2\",\n\t},\n\ttestnet: {\n\t\taddress: \"ST2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D9SZJQ0M\",\n\t\tname: \"BNS-V2\",\n\t},\n} as const;\n\nexport const ZONEFILE_RESOLVER_CONTRACTS = {\n\tmainnet: {\n\t\taddress: \"SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF\",\n\t\tname: \"zonefile-resolver\",\n\t},\n\ttestnet: {\n\t\taddress: \"ST2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D9SZJQ0M\",\n\t\tname: \"zonefile-resolver\",\n\t},\n} as const;\n\n// BNS v2 uses .btc namespace primarily\nexport const DEFAULT_NAMESPACE = \"btc\";\n",
|
|
41
|
+
"import { hash160 } from \"../utils/hash.ts\";\nimport { DEFAULT_NAMESPACE } from \"./constants.ts\";\nimport type { FullyQualifiedName } from \"./types.ts\";\n\n/**\n * Parse a fully qualified name string into components.\n * Supports:\n * - \"name.namespace\" → { name: \"name\", namespace: \"namespace\" }\n * - \"name\" → { name: \"name\", namespace: \"btc\" } (default)\n */\nexport function parseFQN(fqn: string): FullyQualifiedName {\n\tconst parts = fqn.split(\".\");\n\n\tif (parts.length === 1) {\n\t\treturn {\n\t\t\tname: parts[0]!,\n\t\t\tnamespace: DEFAULT_NAMESPACE,\n\t\t};\n\t}\n\n\tif (parts.length === 2) {\n\t\treturn {\n\t\t\tname: parts[0]!,\n\t\t\tnamespace: parts[1]!,\n\t\t};\n\t}\n\n\tthrow new Error(\n\t\t`Invalid fully qualified name: ${fqn}. Expected format: \"name.namespace\" or \"name\"`,\n\t);\n}\n\n/**\n * Format name components into FQN string.\n */\nexport function formatFQN(name: string, namespace: string): string {\n\treturn `${name}.${namespace}`;\n}\n\n/**\n * Validate name format.\n * Names must be:\n * - 1-48 characters\n * - Lowercase alphanumeric, hyphens, underscores\n * - Cannot start or end with hyphen/underscore\n */\nexport function validateName(name: string): boolean {\n\tif (name.length < 1 || name.length > 48) return false;\n\n\tconst regex = /^[a-z0-9]([a-z0-9_-]*[a-z0-9])?$/;\n\treturn regex.test(name);\n}\n\n/**\n * Validate namespace format.\n * Namespaces must be:\n * - 1-20 characters\n * - Lowercase alphanumeric\n */\nexport function validateNamespace(namespace: string): boolean {\n\tif (namespace.length < 1 || namespace.length > 20) return false;\n\n\tconst regex = /^[a-z0-9]+$/;\n\treturn regex.test(namespace);\n}\n\n/**\n * Validate a fully qualified name.\n */\nexport function validateFQN(fqn: string): boolean {\n\ttry {\n\t\tconst { name, namespace } = parseFQN(fqn);\n\t\treturn validateName(name) && validateNamespace(namespace);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Generate a random 20-byte salt for name preorders.\n * @returns Random Uint8Array of length 20\n */\nexport function generateSalt(): Uint8Array {\n\tconst salt = new Uint8Array(20);\n\tcrypto.getRandomValues(salt);\n\treturn salt;\n}\n\n/**\n * Calculate hash160 for name preorder commitment.\n * Hash format: hash160(name + namespace + salt)\n *\n * @param name - BNS name (without namespace)\n * @param namespace - BNS namespace (e.g., \"btc\")\n * @param salt - 20-byte random salt\n * @returns 20-byte hash160 commitment\n */\nexport function hashPreorder(\n\tname: string,\n\tnamespace: string,\n\tsalt: Uint8Array,\n): Uint8Array {\n\tconst nameBytes = new TextEncoder().encode(name);\n\tconst namespaceBytes = new TextEncoder().encode(namespace);\n\n\t// Concatenate: name + namespace + salt\n\tconst combined = new Uint8Array(\n\t\tnameBytes.length + namespaceBytes.length + salt.length,\n\t);\n\tcombined.set(nameBytes, 0);\n\tcombined.set(namespaceBytes, nameBytes.length);\n\tcombined.set(salt, nameBytes.length + namespaceBytes.length);\n\n\treturn hash160(combined);\n}\n",
|
|
42
|
+
"import { getContract } from \"../actions/getContract.ts\";\nimport { ContractResponseError } from \"../actions/getContract.ts\";\nimport { Cl } from \"../clarity/index.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { Pc } from \"../postconditions/index.ts\";\nimport { BNS_ABI } from \"./abi.ts\";\nimport { BNS_CONTRACTS, ZONEFILE_RESOLVER_CONTRACTS } from \"./constants.ts\";\nimport type {\n\tClaimFastParams,\n\tPreorderParams,\n\tRegisterParams,\n\tSetPrimaryParams,\n\tTransferParams,\n\tUpdateZonefileParams,\n} from \"./types.ts\";\nimport {\n\tformatFQN,\n\tgenerateSalt,\n\thashPreorder,\n\tparseFQN,\n\tvalidateFQN,\n} from \"./utils.ts\";\nimport { ZONEFILE_RESOLVER_ABI } from \"./zonefile-abi.ts\";\n\nfunction getBnsContract(client: Client) {\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\tconst network = client.chain.network;\n\tconst contract =\n\t\tnetwork === \"mainnet\" ? BNS_CONTRACTS.mainnet : BNS_CONTRACTS.testnet;\n\n\treturn getContract({\n\t\tclient,\n\t\taddress: contract.address,\n\t\tname: contract.name,\n\t\tabi: BNS_ABI,\n\t});\n}\n\nfunction getZonefileContract(client: Client) {\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\tconst network = client.chain.network;\n\tconst contract =\n\t\tnetwork === \"mainnet\"\n\t\t\t? ZONEFILE_RESOLVER_CONTRACTS.mainnet\n\t\t\t: ZONEFILE_RESOLVER_CONTRACTS.testnet;\n\n\treturn getContract({\n\t\tclient,\n\t\taddress: contract.address,\n\t\tname: contract.name,\n\t\tabi: ZONEFILE_RESOLVER_ABI,\n\t});\n}\n\nfunction stringToBytes(str: string): Uint8Array {\n\treturn new TextEncoder().encode(str);\n}\n\n/**\n * Resolve a BNS name to its owner address.\n * @example\n * const owner = await resolveName(client, \"alice.btc\");\n */\nexport async function resolveName(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<string | null> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst bns = getBnsContract(client);\n\n\ttry {\n\t\treturn (await bns.read.getOwnerName({\n\t\t\tname: stringToBytes(name),\n\t\t\tnamespace: stringToBytes(namespace),\n\t\t})) as string | null;\n\t} catch (e) {\n\t\tif (e instanceof ContractResponseError) return null;\n\t\tthrow e;\n\t}\n}\n\n/**\n * Get the primary name for an address.\n * @example\n * const primary = await getPrimaryName(client, \"SP2J6...\");\n */\nexport async function getPrimaryName(\n\tclient: Client,\n\taddress: string,\n): Promise<string | null> {\n\tconst bns = getBnsContract(client);\n\n\ttry {\n\t\tconst result = (await bns.read.getPrimary({\n\t\t\towner: address,\n\t\t})) as { name: Uint8Array; namespace: Uint8Array } | null;\n\n\t\tif (result === null) return null;\n\n\t\tconst name = new TextDecoder().decode(result.name);\n\t\tconst namespace = new TextDecoder().decode(result.namespace);\n\n\t\treturn formatFQN(name, namespace);\n\t} catch (e) {\n\t\tif (e instanceof ContractResponseError) return null;\n\t\tthrow e;\n\t}\n}\n\n/**\n * Check if a name is available for registration.\n * @example\n * const available = await canRegister(client, \"bob.btc\");\n */\nexport async function canRegister(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<boolean> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst bns = getBnsContract(client);\n\n\t// No can-register-name function — use can-resolve-name instead.\n\t// If it resolves, the name is taken. If it errors, it's available.\n\ttry {\n\t\tawait bns.read.canResolveName({\n\t\t\tnamespace: stringToBytes(namespace),\n\t\t\tname: stringToBytes(name),\n\t\t});\n\t\treturn false; // resolved = taken\n\t} catch {\n\t\treturn true; // error = available\n\t}\n}\n\n/**\n * Get the price to register a name in microSTX.\n * @example\n * const price = await getNamePrice(client, \"bob.btc\");\n */\nexport async function getNamePrice(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<bigint> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst bns = getBnsContract(client);\n\n\t// get-name-price returns a nested response: (ok (ok uint))\n\tconst result = (await bns.read.getNamePrice({\n\t\tnamespace: stringToBytes(namespace),\n\t\tname: stringToBytes(name),\n\t})) as { ok: bigint } | { err: bigint };\n\n\tif (\"ok\" in result) return result.ok;\n\tthrow new Error(`Failed to get name price for ${nameOrFQN}`);\n}\n\n/**\n * Get the NFT token ID for a name.\n * @example\n * const id = await getNameId(client, \"alice.btc\");\n */\nexport async function getNameId(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<bigint | null> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst bns = getBnsContract(client);\n\n\ttry {\n\t\treturn (await bns.read.getIdFromBns({\n\t\t\tname: stringToBytes(name),\n\t\t\tnamespace: stringToBytes(namespace),\n\t\t})) as bigint | null;\n\t} catch (e) {\n\t\tif (e instanceof ContractResponseError) return null;\n\t\tthrow e;\n\t}\n}\n\n/**\n * Preorder a name (step 1 of secure registration).\n * Commits to a name with a salted hash, preventing front-running.\n * Must wait 1 Bitcoin block (~10 min) before calling register().\n *\n * @example\n * const { txid, salt } = await preorder(client, {\n * name: \"bob.btc\",\n * });\n * // Save salt! You'll need it for register()\n * // Wait ~10 minutes (1 Bitcoin block)\n * await register(client, { name: \"bob.btc\", salt });\n */\nexport async function preorder(\n\tclient: Client,\n\tparams: PreorderParams,\n): Promise<{ txid: string; salt: Uint8Array }> {\n\tconst {\n\t\tname: nameInput,\n\t\tnamespace: namespaceInput,\n\t\tsalt: providedSalt,\n\t} = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(fqn);\n\n\t// Check availability\n\tconst available = await canRegister(client, fqn);\n\tif (!available) {\n\t\tthrow new Error(`Name ${fqn} is not available for registration`);\n\t}\n\n\t// Get price\n\tconst price = await getNamePrice(client, fqn);\n\n\t// Generate or use provided salt\n\tconst salt = providedSalt ?? generateSalt();\n\n\t// Calculate hash commitment\n\tconst hashedSaltedFqn = hashPreorder(name, namespace, salt);\n\n\tconst bns = getBnsContract(client);\n\n\tconst txid = await bns.call.namePreorder(\n\t\t{\n\t\t\thashedSaltedFqn,\n\t\t\tstxToBurn: price,\n\t\t},\n\t\t{\n\t\t\tpostConditions: [\n\t\t\t\tPc.principal(client.account!.address).willSendLte(price).ustx(),\n\t\t\t],\n\t\t},\n\t);\n\n\treturn { txid, salt };\n}\n\n/**\n * Register a name (step 2 of secure registration).\n * Reveals the name after preorder. Must wait 1 Bitcoin block after preorder.\n *\n * @example\n * const { txid } = await register(client, {\n * name: \"bob.btc\",\n * salt, // from preorder()\n * });\n */\nexport async function register(\n\tclient: Client,\n\tparams: RegisterParams,\n): Promise<string> {\n\tconst { name: nameInput, namespace: namespaceInput, salt } = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(fqn);\n\n\tconst bns = getBnsContract(client);\n\n\treturn bns.call.nameRegister({\n\t\tname: stringToBytes(name),\n\t\tnamespace: stringToBytes(namespace),\n\t\tsalt,\n\t});\n}\n\n/**\n * Claim a name instantly (fast but snipeable).\n * Burns STX to register the name immediately.\n * @example\n * const txid = await claimFast(client, {\n * name: \"bob.btc\",\n * recipient: account.address,\n * });\n */\nexport async function claimFast(\n\tclient: Client,\n\tparams: ClaimFastParams,\n): Promise<string> {\n\tconst { name: nameInput, namespace: namespaceInput, recipient } = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(fqn);\n\n\t// Check availability\n\tconst available = await canRegister(client, fqn);\n\tif (!available) {\n\t\tthrow new Error(`Name ${fqn} is not available for registration`);\n\t}\n\n\t// Get price\n\tconst price = await getNamePrice(client, fqn);\n\n\tconst bns = getBnsContract(client);\n\n\treturn bns.call.nameClaimFast(\n\t\t{\n\t\t\tname: stringToBytes(name),\n\t\t\tnamespace: stringToBytes(namespace),\n\t\t\tsendTo: recipient,\n\t\t},\n\t\t{\n\t\t\tpostConditions: [Pc.principal(recipient).willSendLte(price).ustx()],\n\t\t},\n\t);\n}\n\n/**\n * Transfer a name to a new owner.\n * @example\n * const txid = await transfer(client, {\n * name: \"alice.btc\",\n * recipient: \"SP3FBR...\",\n * });\n */\nexport async function transfer(\n\tclient: Client,\n\tparams: TransferParams,\n): Promise<string> {\n\tconst { name: nameInput, namespace: namespaceInput, recipient } = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst id = await getNameId(client, fqn);\n\tif (id === null) {\n\t\tthrow new Error(`Name ${fqn} does not exist`);\n\t}\n\n\tconst currentOwner = await resolveName(client, fqn);\n\tif (!currentOwner) {\n\t\tthrow new Error(`Cannot determine owner of ${fqn}`);\n\t}\n\n\tconst bns = getBnsContract(client);\n\tif (!client.chain) {\n\t\tthrow new Error(\"Client must have a chain configured\");\n\t}\n\tconst network = client.chain.network;\n\tconst contract =\n\t\tnetwork === \"mainnet\" ? BNS_CONTRACTS.mainnet : BNS_CONTRACTS.testnet;\n\n\treturn bns.call.transfer(\n\t\t{\n\t\t\tid,\n\t\t\towner: currentOwner,\n\t\t\trecipient,\n\t\t},\n\t\t{\n\t\t\tpostConditions: [\n\t\t\t\tPc.principal(currentOwner)\n\t\t\t\t\t.willSendAsset()\n\t\t\t\t\t.nft(`${contract.address}.${contract.name}::BNS-V2`, Cl.uint(id)),\n\t\t\t],\n\t\t},\n\t);\n}\n\n/**\n * Set a name as your primary name.\n * @example\n * const txid = await setPrimary(client, {\n * name: \"alice.btc\",\n * });\n */\nexport async function setPrimary(\n\tclient: Client,\n\tparams: SetPrimaryParams,\n): Promise<string> {\n\tconst { name: nameInput, namespace: namespaceInput } = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst id = await getNameId(client, fqn);\n\tif (id === null) {\n\t\tthrow new Error(`Name ${fqn} does not exist`);\n\t}\n\n\tconst bns = getBnsContract(client);\n\n\treturn bns.call.setPrimaryName({ primaryNameId: id });\n}\n\n/**\n * Get the zonefile for a name.\n * Zonefiles contain DNS-like records (up to 8192 bytes).\n *\n * @example\n * const zonefile = await getZonefile(client, \"alice.btc\");\n * if (zonefile) {\n * console.log(new TextDecoder().decode(zonefile));\n * }\n */\nexport async function getZonefile(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<Uint8Array | null> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst zonefile = getZonefileContract(client);\n\n\ttry {\n\t\tconst result = (await zonefile.read.resolveName({\n\t\t\tname: stringToBytes(name),\n\t\t\tnamespace: stringToBytes(namespace),\n\t\t})) as Uint8Array | null;\n\n\t\treturn result;\n\t} catch {\n\t\t// Contract returns (err 101) when no zonefile is set\n\t\treturn null;\n\t}\n}\n\n/**\n * Update or clear the zonefile for a name.\n * Only the name owner can update the zonefile.\n *\n * @example\n * // Update zonefile\n * await updateZonefile(client, {\n * name: \"alice.btc\",\n * zonefile: \"$ORIGIN alice.btc\\n$TTL 3600\\n...\",\n * });\n *\n * // Clear zonefile\n * await updateZonefile(client, {\n * name: \"alice.btc\",\n * zonefile: null,\n * });\n */\nexport async function updateZonefile(\n\tclient: Client,\n\tparams: UpdateZonefileParams,\n): Promise<string> {\n\tconst { name: nameInput, namespace: namespaceInput, zonefile } = params;\n\tconst fqn = namespaceInput ? `${nameInput}.${namespaceInput}` : nameInput;\n\n\tif (!validateFQN(fqn)) {\n\t\tthrow new Error(`Invalid name format: ${fqn}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(fqn);\n\n\t// Verify ownership\n\tconst currentOwner = await resolveName(client, fqn);\n\tif (!currentOwner) {\n\t\tthrow new Error(`Name ${fqn} does not exist`);\n\t}\n\n\tconst zonefileContract = getZonefileContract(client);\n\n\t// Convert zonefile to Uint8Array or null\n\tlet zonefileBytes: Uint8Array | null = null;\n\tif (zonefile !== null) {\n\t\tzonefileBytes =\n\t\t\ttypeof zonefile === \"string\"\n\t\t\t\t? new TextEncoder().encode(zonefile)\n\t\t\t\t: zonefile;\n\n\t\tif (zonefileBytes.length > 8192) {\n\t\t\tthrow new Error(\n\t\t\t\t`Zonefile too large: ${zonefileBytes.length} bytes (max 8192)`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn zonefileContract.call.updateZonefile({\n\t\tname: stringToBytes(name),\n\t\tnamespace: stringToBytes(namespace),\n\t\tnewZonefile: zonefileBytes,\n\t});\n}\n\n/**\n * Revoke (clear) the zonefile for a name.\n * Alias for updateZonefile with zonefile: null.\n *\n * @example\n * await revokeZonefile(client, \"alice.btc\");\n */\nexport async function revokeZonefile(\n\tclient: Client,\n\tnameOrFQN: string,\n): Promise<string> {\n\tif (!validateFQN(nameOrFQN)) {\n\t\tthrow new Error(`Invalid name format: ${nameOrFQN}`);\n\t}\n\n\tconst { name, namespace } = parseFQN(nameOrFQN);\n\tconst zonefileContract = getZonefileContract(client);\n\n\treturn zonefileContract.call.revokeName({\n\t\tname: stringToBytes(name),\n\t\tnamespace: stringToBytes(namespace),\n\t});\n}\n",
|
|
43
|
+
"import type { StacksChain } from \"./types.ts\";\n\n/** Stacks mainnet chain definition (Hiro API). */\nexport const mainnet: StacksChain = {\n\tid: 0x00000001,\n\tname: \"Stacks Mainnet\",\n\tnetwork: \"mainnet\",\n\ttransactionVersion: 0x00,\n\tpeerNetworkId: 0x17000000,\n\taddressVersion: { singleSig: 22, multiSig: 20 },\n\tmagicBytes: \"X2\",\n\tbootAddress: \"SP000000000000000000002Q6VF78\",\n\tnativeCurrency: { name: \"Stacks\", symbol: \"STX\", decimals: 6 },\n\trpcUrls: {\n\t\tdefault: {\n\t\t\thttp: [\"https://api.mainnet.hiro.so\"],\n\t\t\tws: [\"wss://api.mainnet.hiro.so/extended/v1/ws\"],\n\t\t},\n\t},\n\tblockExplorers: {\n\t\tdefault: { name: \"Hiro Explorer\", url: \"https://explorer.hiro.so\" },\n\t},\n};\n\n/** Stacks testnet chain definition (Hiro API). */\nexport const testnet: StacksChain = {\n\tid: 0x80000000,\n\tname: \"Stacks Testnet\",\n\tnetwork: \"testnet\",\n\ttransactionVersion: 0x80,\n\tpeerNetworkId: 0xff000000,\n\taddressVersion: { singleSig: 26, multiSig: 21 },\n\tmagicBytes: \"T2\",\n\tbootAddress: \"ST000000000000000000002AMW42H\",\n\tnativeCurrency: { name: \"Stacks\", symbol: \"STX\", decimals: 6 },\n\trpcUrls: {\n\t\tdefault: {\n\t\t\thttp: [\"https://api.testnet.hiro.so\"],\n\t\t\tws: [\"wss://api.testnet.hiro.so/extended/v1/ws\"],\n\t\t},\n\t},\n\tblockExplorers: {\n\t\tdefault: {\n\t\t\tname: \"Hiro Explorer\",\n\t\t\turl: \"https://explorer.hiro.so/?chain=testnet\",\n\t\t},\n\t},\n};\n\n/** Local development chain definition (localhost:3999). */\nexport const devnet: StacksChain = {\n\tid: 0x80000000,\n\tname: \"Stacks Devnet\",\n\tnetwork: \"testnet\",\n\ttransactionVersion: 0x80,\n\tpeerNetworkId: 0xff000000,\n\taddressVersion: { singleSig: 26, multiSig: 21 },\n\tmagicBytes: \"id\",\n\tbootAddress: \"ST000000000000000000002AMW42H\",\n\tnativeCurrency: { name: \"Stacks\", symbol: \"STX\", decimals: 6 },\n\trpcUrls: {\n\t\tdefault: {\n\t\t\thttp: [\"http://localhost:3999\"],\n\t\t\tws: [\"ws://localhost:3999/extended/v1/ws\"],\n\t\t},\n\t},\n};\n\n/** Alias for devnet used in mock/test environments. */\nexport const mocknet: StacksChain = {\n\t...devnet,\n\tname: \"Stacks Mocknet\",\n\taddressVersion: { ...devnet.addressVersion },\n};\n",
|
|
44
|
+
"import type { Client, ClientConfig } from \"./types.ts\";\n\nconst BASE_KEYS = new Set([\n\t\"chain\",\n\t\"account\",\n\t\"transport\",\n\t\"request\",\n\t\"extend\",\n]);\n\nfunction bindExtend(base: Client): Client[\"extend\"] {\n\treturn ((fn: any) => {\n\t\tconst extensions = fn(base);\n\t\tconst next = { ...base };\n\t\tfor (const [key, value] of Object.entries(extensions)) {\n\t\t\tif (BASE_KEYS.has(key)) continue;\n\t\t\t(next as any)[key] = value;\n\t\t}\n\t\tnext.extend = bindExtend(next);\n\t\treturn next as any;\n\t}) as Client[\"extend\"];\n}\n\n/**\n * Create a base client with transport and optional chain/account.\n * Use `.extend()` to compose action decorators (public, wallet, multisig).\n */\nexport function createClient<\n\tTExtended extends Record<string, unknown> = Record<string, unknown>,\n>(config: ClientConfig): Client<TExtended> {\n\tconst transport = config.transport({ chain: config.chain });\n\n\tconst client: Client = {\n\t\tchain: config.chain,\n\t\taccount: config.account,\n\t\ttransport,\n\t\trequest: transport.request,\n\t\textend: null as any,\n\t};\n\n\tclient.extend = bindExtend(client);\n\n\treturn client as Client<TExtended>;\n}\n",
|
|
45
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetContractAbiParams = {\n\tcontract: string; // \"address.name\"\n};\n\nexport async function getContractAbi(\n\tclient: Client,\n\tparams: GetContractAbiParams,\n): Promise<any> {\n\tconst [address, name] = parseContractId(params.contract);\n\treturn client.request(`/v2/contracts/interface/${address}/${name}`, {\n\t\tmethod: \"GET\",\n\t});\n}\n",
|
|
46
|
+
"import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { readContract } from \"./readContract.ts\";\n\nexport type MulticallCall = {\n\tcontract: string;\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n};\n\nexport type MulticallParams<TAllowFailure extends boolean = true> = {\n\tcalls: readonly MulticallCall[];\n\tallowFailure?: TAllowFailure;\n};\n\nexport type MulticallSuccessResult = {\n\tstatus: \"success\";\n\tresult: ClarityValue;\n};\nexport type MulticallFailureResult = { status: \"failure\"; error: Error };\n\nexport type MulticallResult<T extends boolean> = T extends true\n\t? (MulticallSuccessResult | MulticallFailureResult)[]\n\t: ClarityValue[];\n\nexport async function multicall<TAllowFailure extends boolean = true>(\n\tclient: Client,\n\tparams: MulticallParams<TAllowFailure>,\n): Promise<MulticallResult<TAllowFailure>> {\n\tconst { calls, allowFailure = true } = params;\n\n\tif (allowFailure) {\n\t\tconst settled = await Promise.allSettled(\n\t\t\tcalls.map((call) => readContract(client, call)),\n\t\t);\n\t\treturn settled.map((r) =>\n\t\t\tr.status === \"fulfilled\"\n\t\t\t\t? { status: \"success\" as const, result: r.value }\n\t\t\t\t: {\n\t\t\t\t\t\tstatus: \"failure\" as const,\n\t\t\t\t\t\terror:\n\t\t\t\t\t\t\tr.reason instanceof Error\n\t\t\t\t\t\t\t\t? r.reason\n\t\t\t\t\t\t\t\t: new Error(String(r.reason)),\n\t\t\t\t\t},\n\t\t) as MulticallResult<TAllowFailure>;\n\t}\n\n\tconst results = await Promise.all(\n\t\tcalls.map((call) => readContract(client, call)),\n\t);\n\treturn results as MulticallResult<TAllowFailure>;\n}\n",
|
|
47
|
+
"import { BaseError } from \"./base.ts\";\n\nexport class SimulationError extends BaseError {\n\toverride name = \"SimulationError\";\n\twritesDetected: boolean;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { writesDetected: boolean; details?: string },\n\t) {\n\t\tsuper(message, { details: options.details });\n\t\tthis.writesDetected = options.writesDetected;\n\t}\n}\n",
|
|
48
|
+
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { SimulationError } from \"../../errors/simulation.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type SimulateCallParams = {\n\tcontract: string;\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateCallSuccess = { success: true; result: ClarityValue };\nexport type SimulateCallFailure = { success: false; error: SimulationError };\nexport type SimulateCallResult = SimulateCallSuccess | SimulateCallFailure;\n\nexport async function simulateCall(\n\tclient: Client,\n\tparams: SimulateCallParams,\n): Promise<SimulateCallResult> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst sender = params.sender ?? address;\n\n\tconst serializedArgs = (params.args ?? []).map((arg) =>\n\t\twith0x(bytesToHex(serializeCVBytes(arg))),\n\t);\n\n\tlet path = `/v2/contracts/call-read/${address}/${name}/${params.functionName}`;\n\tif (params.tip) {\n\t\tpath += `?tip=${params.tip}`;\n\t}\n\n\tconst data = await client.request(path, {\n\t\tmethod: \"POST\",\n\t\tbody: {\n\t\t\tsender,\n\t\t\targuments: serializedArgs,\n\t\t},\n\t});\n\n\tif (data.okay) {\n\t\treturn { success: true, result: deserializeCVBytes(data.result) };\n\t}\n\n\tconst cause: string = data.cause ?? \"Simulation failed\";\n\tconst writesDetected =\n\t\tcause.includes(\"NotReadOnly\") || cause.includes(\"CostBalanceExceeded\");\n\n\treturn {\n\t\tsuccess: false,\n\t\terror: new SimulationError(\n\t\t\twritesDetected\n\t\t\t\t? \"Function mutates state and cannot be simulated\"\n\t\t\t\t: \"Simulation failed\",\n\t\t\t{ writesDetected, details: cause },\n\t\t),\n\t};\n}\n",
|
|
49
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { AddressHashMode, PayloadType } from \"../../transactions/types.ts\";\nimport { c32address } from \"../../utils/address.ts\";\nimport { type FeeEstimation, estimateFee } from \"./estimateFee.ts\";\nimport { type SimulateCallResult, simulateCall } from \"./simulateCall.ts\";\n\nexport type SimulateTransactionParams = {\n\ttransaction: StacksTransaction;\n\tsender?: string;\n\ttip?: string;\n};\n\nexport type SimulateContractCallResult = {\n\ttype: \"contract-call\";\n\texecution: SimulateCallResult;\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransferResult = {\n\ttype: \"token-transfer\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateDeployResult = {\n\ttype: \"contract-deploy\";\n\tfees: FeeEstimation[];\n};\n\nexport type SimulateTransactionResult =\n\t| SimulateContractCallResult\n\t| SimulateTransferResult\n\t| SimulateDeployResult;\n\nfunction isMultiSig(hashMode: number): boolean {\n\treturn (\n\t\thashMode === AddressHashMode.P2SH ||\n\t\thashMode === AddressHashMode.P2WSH ||\n\t\thashMode === AddressHashMode.P2SH_NonSequential ||\n\t\thashMode === AddressHashMode.P2WSH_P2SH_NonSequential\n\t);\n}\n\nfunction extractSender(tx: StacksTransaction, client: Client): string {\n\tconst { hashMode, signer } = tx.auth.spendingCondition;\n\tconst chain = client.chain;\n\tconst version = isMultiSig(hashMode)\n\t\t? (chain?.addressVersion.multiSig ?? 20)\n\t\t: (chain?.addressVersion.singleSig ?? 22);\n\treturn c32address(version, signer);\n}\n\nexport async function simulateTransaction(\n\tclient: Client,\n\tparams: SimulateTransactionParams,\n): Promise<SimulateTransactionResult> {\n\tconst { transaction, tip } = params;\n\tconst { payload } = transaction;\n\n\tif (payload.payloadType === PayloadType.ContractCall) {\n\t\tconst sender = params.sender ?? extractSender(transaction, client);\n\t\tconst contract = `${payload.contractAddress}.${payload.contractName}`;\n\n\t\tconst [execution, fees] = await Promise.all([\n\t\t\tsimulateCall(client, {\n\t\t\t\tcontract,\n\t\t\t\tfunctionName: payload.functionName,\n\t\t\t\targs: payload.functionArgs,\n\t\t\t\tsender,\n\t\t\t\ttip,\n\t\t\t}),\n\t\t\testimateFee(client, { transaction }),\n\t\t]);\n\n\t\treturn { type: \"contract-call\", execution, fees };\n\t}\n\n\tconst fees = await estimateFee(client, { transaction });\n\n\tif (\n\t\tpayload.payloadType === PayloadType.SmartContract ||\n\t\tpayload.payloadType === PayloadType.VersionedSmartContract\n\t) {\n\t\treturn { type: \"contract-deploy\", fees };\n\t}\n\n\treturn { type: \"token-transfer\", fees };\n}\n",
|
|
50
|
+
"import { BaseError } from \"./base.ts\";\n\nexport class WebSocketError extends BaseError {\n\toverride name = \"WebSocketError\";\n\n\tconstructor(message: string, options?: { cause?: Error; details?: string }) {\n\t\tsuper(message, options);\n\t}\n}\n",
|
|
51
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { WebSocketError } from \"../errors/websocket.ts\";\nimport type { WebSocketTransport } from \"../transports/webSocket.ts\";\nimport type {\n\tAddressBalanceNotification,\n\tAddressTxNotification,\n\tBlockNotification,\n\tMempoolNotification,\n\tNftEventNotification,\n\tSubscription,\n\tTxUpdateNotification,\n} from \"./types.ts\";\n\nfunction getWsTransport(client: Client): WebSocketTransport {\n\tif (client.transport.type !== \"webSocket\") {\n\t\tthrow new WebSocketError(\n\t\t\t\"Watch actions require a webSocket transport. Use `webSocket()` when creating your client.\",\n\t\t);\n\t}\n\treturn client.transport as WebSocketTransport;\n}\n\nexport type WatchBlocksParams = {\n\tonBlock: (block: BlockNotification) => void;\n};\n\nexport async function watchBlocks(\n\tclient: Client,\n\tparams: WatchBlocksParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"block\" }, params.onBlock);\n}\n\nexport type WatchMempoolParams = {\n\tonTransaction: (tx: MempoolNotification) => void;\n};\n\nexport async function watchMempool(\n\tclient: Client,\n\tparams: WatchMempoolParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"mempool\" }, params.onTransaction);\n}\n\nexport type WatchTransactionParams = {\n\ttxId: string;\n\tonUpdate: (update: TxUpdateNotification) => void;\n};\n\nexport async function watchTransaction(\n\tclient: Client,\n\tparams: WatchTransactionParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"tx_update\", tx_id: params.txId },\n\t\tparams.onUpdate,\n\t);\n}\n\nexport type WatchAddressParams = {\n\taddress: string;\n\tonTransaction: (tx: AddressTxNotification) => void;\n};\n\nexport async function watchAddress(\n\tclient: Client,\n\tparams: WatchAddressParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_tx_update\", address: params.address },\n\t\tparams.onTransaction,\n\t);\n}\n\nexport type WatchAddressBalanceParams = {\n\taddress: string;\n\tonBalance: (balance: AddressBalanceNotification) => void;\n};\n\nexport async function watchAddressBalance(\n\tclient: Client,\n\tparams: WatchAddressBalanceParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_balance_update\", address: params.address },\n\t\tparams.onBalance,\n\t);\n}\n\nexport type WatchNftEventParams = {\n\tonEvent: (event: NftEventNotification) => void;\n\tassetIdentifier?: string;\n\tvalue?: string;\n};\n\nexport async function watchNftEvent(\n\tclient: Client,\n\tparams: WatchNftEventParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\n\tlet event: \"nft_event\" | \"nft_asset_event\" | \"nft_collection_event\";\n\tif (params.assetIdentifier && params.value) {\n\t\tevent = \"nft_event\";\n\t} else if (params.assetIdentifier) {\n\t\tevent = \"nft_collection_event\";\n\t} else {\n\t\tevent = \"nft_event\";\n\t}\n\n\treturn transport.subscribe(\n\t\t{\n\t\t\tevent,\n\t\t\tasset_identifier: params.assetIdentifier,\n\t\t\tvalue: params.value,\n\t\t},\n\t\tparams.onEvent,\n\t);\n}\n",
|
|
52
|
+
"import {\n\ttype EstimateFeeParams,\n\ttype FeeEstimation,\n\testimateFee,\n} from \"../../actions/public/estimateFee.ts\";\nimport {\n\ttype AccountInfo,\n\ttype GetAccountInfoParams,\n\tgetAccountInfo,\n} from \"../../actions/public/getAccountInfo.ts\";\nimport {\n\ttype GetBalanceParams,\n\tgetBalance,\n} from \"../../actions/public/getBalance.ts\";\nimport {\n\ttype GetBlockParams,\n\tgetBlock,\n} from \"../../actions/public/getBlock.ts\";\nimport { getBlockHeight } from \"../../actions/public/getBlockHeight.ts\";\nimport {\n\ttype GetContractAbiParams,\n\tgetContractAbi,\n} from \"../../actions/public/getContractAbi.ts\";\nimport {\n\ttype GetMapEntryParams,\n\tgetMapEntry,\n} from \"../../actions/public/getMapEntry.ts\";\nimport {\n\ttype GetNonceParams,\n\tgetNonce,\n} from \"../../actions/public/getNonce.ts\";\nimport {\n\ttype MulticallParams,\n\ttype MulticallResult,\n\tmulticall,\n} from \"../../actions/public/multicall.ts\";\nimport {\n\ttype ReadContractParams,\n\treadContract,\n} from \"../../actions/public/readContract.ts\";\nimport {\n\ttype SimulateCallParams,\n\ttype SimulateCallResult,\n\tsimulateCall,\n} from \"../../actions/public/simulateCall.ts\";\nimport {\n\ttype SimulateTransactionParams,\n\ttype SimulateTransactionResult,\n\tsimulateTransaction,\n} from \"../../actions/public/simulateTransaction.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport {\n\ttype WatchAddressBalanceParams,\n\ttype WatchAddressParams,\n\ttype WatchBlocksParams,\n\ttype WatchMempoolParams,\n\ttype WatchNftEventParams,\n\ttype WatchTransactionParams,\n\twatchAddress,\n\twatchAddressBalance,\n\twatchBlocks,\n\twatchMempool,\n\twatchNftEvent,\n\twatchTransaction,\n} from \"../../subscriptions/actions.ts\";\nimport type { Subscription } from \"../../subscriptions/types.ts\";\nimport type { Client } from \"../types.ts\";\n\n/** Read-only actions: balance queries, contract reads, block data, and event subscriptions. */\nexport type PublicActions = {\n\tgetNonce: (params: GetNonceParams) => Promise<bigint>;\n\tgetBalance: (params: GetBalanceParams) => Promise<bigint>;\n\tgetAccountInfo: (params: GetAccountInfoParams) => Promise<AccountInfo>;\n\tgetBlock: (params: GetBlockParams) => Promise<any>;\n\tgetBlockHeight: () => Promise<number>;\n\treadContract: (params: ReadContractParams) => Promise<ClarityValue>;\n\tgetContractAbi: (params: GetContractAbiParams) => Promise<any>;\n\tgetMapEntry: (params: GetMapEntryParams) => Promise<ClarityValue>;\n\testimateFee: (params: EstimateFeeParams) => Promise<FeeEstimation[]>;\n\tmulticall: <T extends boolean = true>(\n\t\tparams: MulticallParams<T>,\n\t) => Promise<MulticallResult<T>>;\n\tsimulateCall: (params: SimulateCallParams) => Promise<SimulateCallResult>;\n\tsimulateTransaction: (\n\t\tparams: SimulateTransactionParams,\n\t) => Promise<SimulateTransactionResult>;\n\twatchBlocks: (params: WatchBlocksParams) => Promise<Subscription>;\n\twatchMempool: (params: WatchMempoolParams) => Promise<Subscription>;\n\twatchTransaction: (params: WatchTransactionParams) => Promise<Subscription>;\n\twatchAddress: (params: WatchAddressParams) => Promise<Subscription>;\n\twatchAddressBalance: (\n\t\tparams: WatchAddressBalanceParams,\n\t) => Promise<Subscription>;\n\twatchNftEvent: (params: WatchNftEventParams) => Promise<Subscription>;\n};\n\n/** Decorator that binds {@link PublicActions} to a client instance. */\nexport function publicActions(client: Client): PublicActions {\n\treturn {\n\t\tgetNonce: (params) => getNonce(client, params),\n\t\tgetBalance: (params) => getBalance(client, params),\n\t\tgetAccountInfo: (params) => getAccountInfo(client, params),\n\t\tgetBlock: (params) => getBlock(client, params),\n\t\tgetBlockHeight: () => getBlockHeight(client),\n\t\treadContract: (params) => readContract(client, params),\n\t\tgetContractAbi: (params) => getContractAbi(client, params),\n\t\tgetMapEntry: (params) => getMapEntry(client, params),\n\t\testimateFee: (params) => estimateFee(client, params),\n\t\tmulticall: (params) => multicall(client, params),\n\t\tsimulateCall: (params) => simulateCall(client, params),\n\t\tsimulateTransaction: (params) => simulateTransaction(client, params),\n\t\twatchBlocks: (params) => watchBlocks(client, params),\n\t\twatchMempool: (params) => watchMempool(client, params),\n\t\twatchTransaction: (params) => watchTransaction(client, params),\n\t\twatchAddress: (params) => watchAddress(client, params),\n\t\twatchAddressBalance: (params) => watchAddressBalance(client, params),\n\t\twatchNftEvent: (params) => watchNftEvent(client, params),\n\t};\n}\n",
|
|
53
|
+
"import { createClient } from \"./createClient.ts\";\nimport { type PublicActions, publicActions } from \"./decorators/public.ts\";\nimport type { Client, ClientConfig } from \"./types.ts\";\n\n/** Configuration for {@link createPublicClient} (no account needed). */\nexport type PublicClientConfig = Omit<ClientConfig, \"account\">;\n\n/**\n * Create a read-only client pre-extended with {@link PublicActions}.\n * Use for queries, contract reads, and event subscriptions.\n */\nexport function createPublicClient(\n\tconfig: PublicClientConfig,\n): Client<PublicActions> & PublicActions {\n\treturn createClient(config).extend(publicActions);\n}\n",
|
|
54
|
+
"import type {\n\tRequestFn,\n\tRequestOptions,\n\tTransport,\n\tTransportConfig,\n} from \"./types.ts\";\n\nexport function createTransport(\n\ttype: string,\n\tconfig: TransportConfig & { request: RequestFn },\n): Transport {\n\treturn {\n\t\ttype,\n\t\trequest: config.request,\n\t\tconfig,\n\t};\n}\n\nexport async function fetchWithRetry(\n\turl: string,\n\toptions: RequestInit,\n\tretryCount: number,\n\tretryDelay: number,\n\ttimeout: number,\n): Promise<Response> {\n\tlet lastError: Error | undefined;\n\n\tfor (let attempt = 0; attempt <= retryCount; attempt++) {\n\t\ttry {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst timeoutId = setTimeout(() => controller.abort(), timeout);\n\n\t\t\tconst response = await fetch(url, {\n\t\t\t\t...options,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\n\t\t\tclearTimeout(timeoutId);\n\n\t\t\tif (response.ok || response.status < 500) {\n\t\t\t\treturn response;\n\t\t\t}\n\n\t\t\tlastError = new Error(`HTTP ${response.status}: ${response.statusText}`);\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error));\n\t\t}\n\n\t\tif (attempt < retryCount) {\n\t\t\tawait new Promise((r) => setTimeout(r, retryDelay * (attempt + 1)));\n\t\t}\n\t}\n\n\tthrow lastError ?? new Error(\"Request failed\");\n}\n\nexport function buildRequestFn(\n\tbaseUrl: string,\n\tconfig: TransportConfig,\n): RequestFn {\n\tconst {\n\t\ttimeout = 30_000,\n\t\tretryCount = 3,\n\t\tretryDelay = 150,\n\t\tfetchOptions = {},\n\t\tapiKey,\n\t} = config;\n\n\treturn async (path: string, options?: RequestOptions) => {\n\t\tconst url = `${baseUrl.replace(/\\/$/, \"\")}${path}`;\n\t\tconst headers: Record<string, string> = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t...(fetchOptions.headers as Record<string, string>),\n\t\t\t...options?.headers,\n\t\t};\n\n\t\tif (apiKey) {\n\t\t\theaders[\"x-api-key\"] = apiKey;\n\t\t}\n\n\t\tconst init: RequestInit = {\n\t\t\t...fetchOptions,\n\t\t\tmethod: options?.method ?? \"GET\",\n\t\t\theaders,\n\t\t};\n\n\t\tif (options?.body !== undefined) {\n\t\t\tinit.body = JSON.stringify(options.body);\n\t\t}\n\n\t\tconst response = await fetchWithRetry(\n\t\t\turl,\n\t\t\tinit,\n\t\t\tretryCount,\n\t\t\tretryDelay,\n\t\t\ttimeout,\n\t\t);\n\n\t\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\t\tif (contentType.includes(\"application/json\")) {\n\t\t\treturn response.json();\n\t\t}\n\t\treturn response.text();\n\t};\n}\n",
|
|
55
|
+
"import { buildRequestFn, createTransport } from \"./createTransport.ts\";\nimport type { TransportConfig, TransportFactory } from \"./types.ts\";\n\n/**\n * Create an HTTP transport for Stacks node RPC calls.\n * Falls back to the chain's default RPC URL, then `localhost:3999`.\n */\nexport function http(url?: string, config?: TransportConfig): TransportFactory {\n\treturn (params) => {\n\t\tconst resolvedUrl =\n\t\t\turl ?? params?.chain?.rpcUrls.default.http[0] ?? \"http://localhost:3999\";\n\n\t\tconst mergedConfig: TransportConfig = {\n\t\t\t...config,\n\t\t\turl: resolvedUrl,\n\t\t};\n\n\t\treturn createTransport(\"http\", {\n\t\t\t...mergedConfig,\n\t\t\trequest: buildRequestFn(resolvedUrl, mergedConfig),\n\t\t});\n\t};\n}\n",
|
|
56
|
+
"import { mainnet, testnet } from \"../chains/definitions.ts\";\nimport { createPublicClient } from \"../clients/createPublicClient.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { http } from \"../transports/http.ts\";\n\n/**\n * Any Stacks client that can perform read-only RPC requests. We only need\n * the base `Client.request` contract; public actions are invoked as\n * free functions in `tools/index.ts`, so we keep this loose.\n */\nexport type StacksReadClient = Client<Record<string, unknown>>;\n\n/**\n * Lazy-initialized shared client used by the bare tool exports. Resolves\n * chain + transport from environment:\n * - `STACKS_RPC_URL` → override for the RPC endpoint\n * - `STACKS_CHAIN=testnet` → select testnet (defaults to mainnet)\n */\nlet _defaultClient: StacksReadClient | null = null;\n\nexport function getDefaultPublicClient(): StacksReadClient {\n\tif (_defaultClient) return _defaultClient;\n\tconst chain = process.env.STACKS_CHAIN === \"testnet\" ? testnet : mainnet;\n\t_defaultClient = createPublicClient({\n\t\tchain,\n\t\ttransport: http(process.env.STACKS_RPC_URL),\n\t});\n\treturn _defaultClient;\n}\n"
|
|
57
|
+
],
|
|
58
|
+
"mappings": ";;;;AA+BA;AACA;;;AChCA;;;ACAA,IAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,IAAI,GAAG,CAAC,GAAG,MAC7C,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAC/B;AAEO,SAAS,UAAU,CAAC,OAA2B;AAAA,EACrD,IAAI,MAAM;AAAA,EACV,WAAW,KAAK,OAAO;AAAA,IACtB,OAAO,MAAM;AAAA,EACd;AAAA,EACA,OAAO;AAAA;AAGD,SAAS,UAAU,CAAC,KAAyB;AAAA,EACnD,MAAM,UAAU,GAAG;AAAA,EACnB,IAAI,IAAI,SAAS;AAAA,IAAG,MAAM,IAAI;AAAA,EAE9B,MAAM,QAAQ,IAAI,WAAW,IAAI,SAAS,CAAC;AAAA,EAC3C,SAAS,IAAI,EAAG,IAAI,MAAM,QAAQ,KAAK;AAAA,IACtC,MAAM,IAAI,IAAI;AAAA,IACd,MAAM,OAAO,OAAO,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE;AAAA,IACpD,IAAI,OAAO,MAAM,IAAI,KAAK,OAAO;AAAA,MAChC,MAAM,IAAI,MAAM,uBAAuB;AAAA,IACxC,MAAM,KAAK;AAAA,EACZ;AAAA,EACA,OAAO;AAAA;AAGD,SAAS,MAAM,CAAC,OAAuB;AAAA,EAC7C,OAAO,OAAO,KAAK,KAAK,IAAI,Q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