@secondlayer/stacks 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/shared/{stacks-v150hffx.js → stacks-01pbr7gf.js} +13 -12
- package/dist/shared/stacks-01pbr7gf.js.map +11 -0
- package/dist/shared/stacks-0cdm20eh.js +225 -0
- package/dist/shared/stacks-0cdm20eh.js.map +11 -0
- package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
- package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
- package/dist/shared/{stacks-7nvbv61d.js → stacks-59xy6t1p.js} +27 -25
- package/dist/shared/{stacks-7nvbv61d.js.map → stacks-59xy6t1p.js.map} +6 -6
- package/dist/shared/{stacks-63xbc6cj.js → stacks-6n2m9hyk.js} +3 -3
- package/dist/shared/stacks-bnbdqznq.cjs +211 -0
- package/dist/shared/stacks-bnbdqznq.cjs.map +11 -0
- package/dist/shared/stacks-esn3wcw5.cjs +416 -0
- package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
- package/dist/shared/{stacks-3kmj5yre.js → stacks-g67f4w1d.js} +5 -12
- package/dist/shared/stacks-g67f4w1d.js.map +10 -0
- package/dist/shared/stacks-kjg7fw4y.js +434 -0
- package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
- package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
- package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
- package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
- package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
- package/dist/src/accounts/index.cjs +28 -1
- package/dist/src/accounts/index.cjs.map +4 -3
- package/dist/src/accounts/index.d.cts +23 -1
- package/dist/src/accounts/index.d.ts +23 -1
- package/dist/src/accounts/index.js +33 -1
- package/dist/src/accounts/index.js.map +4 -3
- package/dist/src/actions/index.cjs +8 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +140 -6
- package/dist/src/actions/index.d.ts +140 -6
- package/dist/src/actions/index.js +22 -8
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +4 -175
- package/dist/src/bitcoin/index.cjs.map +4 -6
- package/dist/src/bitcoin/index.d.cts +18 -2
- package/dist/src/bitcoin/index.d.ts +18 -2
- package/dist/src/bitcoin/index.js +18 -181
- package/dist/src/bitcoin/index.js.map +4 -6
- package/dist/src/bns/index.js +3 -3
- package/dist/src/index.cjs +10 -1
- package/dist/src/index.cjs.map +3 -3
- package/dist/src/index.d.cts +167 -9
- package/dist/src/index.d.ts +167 -9
- package/dist/src/index.js +23 -7
- package/dist/src/index.js.map +3 -3
- package/dist/src/pox/index.js +3 -3
- package/dist/src/sbtc/index.cjs +49 -7
- package/dist/src/sbtc/index.cjs.map +6 -6
- package/dist/src/sbtc/index.d.cts +8 -2
- package/dist/src/sbtc/index.d.ts +8 -2
- package/dist/src/sbtc/index.js +56 -10
- package/dist/src/sbtc/index.js.map +6 -6
- package/dist/src/stackingdao/index.js +3 -3
- package/dist/src/tools/index.cjs +194 -13
- package/dist/src/tools/index.cjs.map +12 -9
- package/dist/src/tools/index.js +194 -13
- package/dist/src/tools/index.js.map +12 -9
- package/dist/src/x402/index.cjs +5 -2
- package/dist/src/x402/index.cjs.map +3 -3
- package/dist/src/x402/index.d.cts +36 -0
- package/dist/src/x402/index.d.ts +36 -0
- package/dist/src/x402/index.js +7 -4
- package/dist/src/x402/index.js.map +3 -3
- package/package.json +2 -4
- package/dist/shared/stacks-3kmj5yre.js.map +0 -10
- package/dist/shared/stacks-502j0efj.js +0 -210
- package/dist/shared/stacks-502j0efj.js.map +0 -15
- package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
- package/dist/shared/stacks-maamjqma.cjs.map +0 -11
- package/dist/shared/stacks-v150hffx.js.map +0 -11
- package/dist/shared/stacks-xmsms921.cjs +0 -196
- package/dist/shared/stacks-xmsms921.cjs.map +0 -15
- /package/dist/shared/{stacks-63xbc6cj.js.map → stacks-6n2m9hyk.js.map} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/actions/public/getAccountInfo.ts", "../src/actions/public/getBalance.ts", "../src/actions/public/getBlock.ts", "../src/actions/public/
|
|
3
|
+
"sources": ["../src/actions/public/getAccountInfo.ts", "../src/actions/public/getBalance.ts", "../src/actions/public/getBlock.ts", "../src/actions/public/getContractAbi.ts", "../src/actions/public/getTransaction.ts", "../src/actions/public/multicall.ts", "../src/errors/simulation.ts", "../src/actions/public/simulateCall.ts", "../src/actions/public/simulateTransaction.ts", "../src/actions/wallet/deployContract.ts", "../src/actions/wallet/signMessage.ts", "../src/actions/wallet/signTransaction.ts", "../src/actions/wallet/transferStx.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"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",
|
|
6
6
|
"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",
|
|
7
7
|
"import type { Client } from \"../../clients/types.ts\";\n\nexport type GetBlockParams = {\n\theight?: number;\n\thash?: string;\n};\n\nexport async function getBlock(\n\tclient: Client,\n\tparams?: GetBlockParams,\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n): Promise<any> {\n\tif (params?.hash) {\n\t\treturn client.request(`/extended/v2/blocks/${params.hash}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\tif (params?.height !== undefined) {\n\t\treturn client.request(`/extended/v2/blocks/${params.height}`, {\n\t\t\tmethod: \"GET\",\n\t\t});\n\t}\n\t// Latest block\n\treturn client.request(\"/extended/v2/blocks?limit=1\", { method: \"GET\" });\n}\n",
|
|
8
|
-
"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",
|
|
9
8
|
"import type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\n\nexport type GetContractAbiParams = {\n\tcontract: string; // \"address.name\"\n};\n\nexport async function getContractAbi(\n\tclient: Client,\n\tparams: GetContractAbiParams,\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n): Promise<any> {\n\tconst [address, name] = parseContractId(params.contract);\n\treturn client.request(`/v2/contracts/interface/${address}/${name}`, {\n\t\tmethod: \"GET\",\n\t});\n}\n",
|
|
9
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport {\n\ttype TransactionReceipt,\n\ttype TransactionStatusSource,\n\textendedApiSource,\n} from \"./txSources.ts\";\n\nexport type GetTransactionParams = {\n\ttxid: string;\n\t/** Where to read status from. Defaults to {@link extendedApiSource}. */\n\tsource?: TransactionStatusSource;\n};\n\n/**\n * Fetch a transaction's receipt (status, block info, decoded result).\n * Returns `null` when the source has no record of the transaction.\n */\nexport async function getTransaction(\n\tclient: Client,\n\tparams: GetTransactionParams,\n): Promise<TransactionReceipt | null> {\n\tconst source = params.source ?? extendedApiSource();\n\tconst { receipt } = await source.get({ client, txid: params.txid });\n\treturn receipt;\n}\n",
|
|
10
10
|
"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",
|
|
11
11
|
"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",
|
|
12
12
|
"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",
|
|
13
13
|
"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",
|
|
14
|
-
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractDeploy } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { ClarityVersion } from \"../../transactions/types.ts\";\nimport { isClarityName } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport {
|
|
14
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractDeploy } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { ClarityVersion } from \"../../transactions/types.ts\";\nimport { isClarityName } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type DeployContractParams = {\n\tcontractName: string;\n\tcodeBody: string;\n\tclarityVersion?: ClarityVersion;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract deploy */\nexport async function deployContract(\n\tclient: Client,\n\tparams: DeployContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\tif (!isClarityName(params.contractName))\n\t\tthrow new Error(`Invalid contract name: ${params.contractName}`);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_deployContract\", {\n\t\t\tcontractName: params.contractName,\n\t\t\tcodeBody: params.codeBody,\n\t\t\tclarityVersion: params.clarityVersion,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractDeploy({\n\t\tcontractName: params.contractName,\n\t\tcodeBody: params.codeBody,\n\t\tclarityVersion: params.clarityVersion,\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n",
|
|
15
15
|
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { Cl } from \"../../clarity/values.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { bytesToHex, concatBytes } from \"../../utils/encoding.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignMessageParams = {\n\tmessage: string | ClarityValue;\n\tdomain?: {\n\t\tname: string;\n\t\tversion: string;\n\t\tchainId: number;\n\t};\n};\n\nconst SIP018_PREFIX = new Uint8Array([0x53, 0x49, 0x50, 0x30, 0x31, 0x38]); // \"SIP018\"\n\n/** Sign a structured message per SIP-018 */\nexport async function signMessage(\n\tclient: Client,\n\tparams: SignMessageParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tconst method = params.domain\n\t\t\t? \"stx_signStructuredMessage\"\n\t\t\t: \"stx_signMessage\";\n\t\tconst result = await account.provider.request(method, {\n\t\t\tmessage: params.message,\n\t\t\tdomain: params.domain,\n\t\t});\n\t\treturn result.signature;\n\t}\n\n\t// Local/Custom: sign locally\n\tconst cv =\n\t\ttypeof params.message === \"string\"\n\t\t\t? Cl.stringAscii(params.message)\n\t\t\t: params.message;\n\n\tconst serializedMsg = serializeCVBytes(cv);\n\n\tlet hash: Uint8Array;\n\n\tif (params.domain) {\n\t\tconst domainCV = Cl.tuple({\n\t\t\tname: Cl.stringAscii(params.domain.name),\n\t\t\tversion: Cl.stringAscii(params.domain.version),\n\t\t\t\"chain-id\": Cl.uint(params.domain.chainId),\n\t\t});\n\t\tconst serializedDomain = serializeCVBytes(domainCV);\n\t\thash = sha256(concatBytes(SIP018_PREFIX, serializedDomain, serializedMsg));\n\t} else {\n\t\thash = sha256(serializedMsg);\n\t}\n\n\tconst sigBytes = await account.sign(hash);\n\treturn bytesToHex(sigBytes);\n}\n",
|
|
16
16
|
"import type { Client } from \"../../clients/types.ts\";\nimport { signMultiSigWithAccount } from \"../../transactions/multisig.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport type { StacksTransaction } from \"../../transactions/types.ts\";\nimport { deserializeTransaction } from \"../../transactions/wire/deserialize.ts\";\nimport { serializeTransactionHex } from \"../../transactions/wire/serialize.ts\";\nimport { isProviderAccount } from \"./utils.ts\";\n\nexport type SignTransactionParams = {\n\ttransaction: StacksTransaction;\n\t/** Public keys for multi-sig signing (auto-detected from _multisig metadata if omitted) */\n\tsigners?: string[];\n};\n\n/** Sign a transaction using the client's account */\nexport async function signTransactionAction(\n\tclient: Client,\n\tparams: SignTransactionParams,\n): Promise<StacksTransaction> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Provider: send hex to wallet, get signed hex back\n\tif (isProviderAccount(account)) {\n\t\tconst hex = serializeTransactionHex(params.transaction);\n\t\tconst result = await account.provider.request(\"stx_signTransaction\", {\n\t\t\ttransaction: hex,\n\t\t});\n\t\treturn deserializeTransaction(result.transaction);\n\t}\n\n\t// Multi-sig: auto-detect from fields or _multisig metadata\n\tconst condition = params.transaction.auth.spendingCondition;\n\tif (\"fields\" in condition) {\n\t\tconst publicKeys =\n\t\t\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\t\t\tparams.signers ?? (params.transaction as any)._multisig?.publicKeys;\n\t\tif (!publicKeys)\n\t\t\tthrow new Error(\"Multi-sig signing requires signers (publicKeys)\");\n\t\treturn signMultiSigWithAccount(params.transaction, account, publicKeys);\n\t}\n\n\t// Local/Custom: sign with account\n\treturn signTransactionWithAccount(params.transaction, account);\n}\n",
|
|
17
|
-
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildTokenTransfer } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport {
|
|
17
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildTokenTransfer } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type TransferStxParams = {\n\tto: string;\n\tamount: IntegerType;\n\tmemo?: string;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast an STX transfer */\nexport async function transferStx(\n\tclient: Client,\n\tparams: TransferStxParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\tif (!validateStacksAddress(params.to))\n\t\tthrow new Error(`Invalid recipient address: ${params.to}`);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_transferStx\", {\n\t\t\trecipient: params.to,\n\t\t\tamount: String(params.amount),\n\t\t\tmemo: params.memo,\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildTokenTransfer({\n\t\trecipient: params.to,\n\t\tamount: params.amount,\n\t\tmemo: params.memo,\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
|
|
18
18
|
],
|
|
19
|
-
"mappings": "
|
|
20
|
-
"debugId": "
|
|
19
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,eAAsB,cAAc,CACnC,QACA,QACuB;AAAA,EACvB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,mBAAmB;AAAA,IAC3E,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,OAAO;AAAA,IACN,SAAS,OAAO,KAAK,OAAO;AAAA,IAC5B,OAAO,OAAO,KAAK,KAAK;AAAA,IACxB,cAAc,KAAK,iBAAiB;AAAA,IACpC,YAAY,KAAK,eAAe;AAAA,EACjC;AAAA;;;ACnBD,eAAsB,UAAU,CAC/B,QACA,QACkB;AAAA,EAClB,MAAM,OAAO,MAAM,OAAO,QAAQ,gBAAgB,OAAO,WAAW;AAAA,IACnE,QAAQ;AAAA,EACT,CAAC;AAAA,EACD,OAAO,OAAO,KAAK,OAAO;AAAA;;;ACN3B,eAAsB,QAAQ,CAC7B,QACA,QAEe;AAAA,EACf,IAAI,QAAQ,MAAM;AAAA,IACjB,OAAO,OAAO,QAAQ,uBAAuB,OAAO,QAAQ;AAAA,MAC3D,QAAQ;AAAA,IACT,CAAC;AAAA,EACF;AAAA,EACA,IAAI,QAAQ,WAAW,WAAW;AAAA,IACjC,OAAO,OAAO,QAAQ,uBAAuB,OAAO,UAAU;AAAA,MAC7D,QAAQ;AAAA,IACT,CAAC;AAAA,EACF;AAAA,EAEA,OAAO,OAAO,QAAQ,+BAA+B,EAAE,QAAQ,MAAM,CAAC;AAAA;;;AChBvE,eAAsB,cAAc,CACnC,QACA,QAEe;AAAA,EACf,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,OAAO,OAAO,QAAQ,2BAA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M,8BAA8B,OAAO,IAAI;AAAA,EAG1D,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,2BAA2B,OAAO,GAAG;AAAA,IACrC,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,mBAAmB;AAAA,MAChE,WAAW,OAAO;AAAA,MAClB,QAAQ,OAAO,OAAO,MAAM;AAAA,MAC5B,MAAM,OAAO;AAAA,IACd,CAAC;AAAA,IACD,OAAO,OAAO;AAAA,EACf;AAAA,EAGA,MAAM,QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,qBAAqB,OAAO,QAAQ,aAAa,UAAU,OAAO,GAAG;AAAA,EAE3E,MAAM,WAAW,mBAAmB;AAAA,IACnC,WAAW,OAAO;AAAA,IAClB,QAAQ,OAAO;AAAA,IACf,MAAM,OAAO;AAAA,IACb,KAAK,qBAAqB,KAAM,OAAO;AAAA,IACvC;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,oBAAoB;AAAA,IACvB,eAAe,UAAU,MAAM,WAAW,QAAQ,UAAU,OAAO,GAAG,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
20
|
+
"debugId": "CD5517B72817ABFE64756E2164756E21",
|
|
21
21
|
"names": []
|
|
22
22
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callContract,
|
|
3
3
|
getMapEntry
|
|
4
|
-
} from "./stacks-
|
|
4
|
+
} from "./stacks-01pbr7gf.js";
|
|
5
5
|
import {
|
|
6
6
|
readContract
|
|
7
7
|
} from "./stacks-msmgyerb.js";
|
|
8
8
|
import {
|
|
9
9
|
estimateFee,
|
|
10
10
|
resolveNonce
|
|
11
|
-
} from "./stacks-
|
|
11
|
+
} from "./stacks-kjg7fw4y.js";
|
|
12
12
|
import {
|
|
13
13
|
clarityValueToJSUntyped,
|
|
14
14
|
jsToClarityValue,
|
|
@@ -189,4 +189,4 @@ class ContractResponseError extends Error {
|
|
|
189
189
|
export { getContract, resolveNetworkContract, ContractResponseError };
|
|
190
190
|
|
|
191
191
|
//# debugId=BBB428C76B76C91764756E2164756E21
|
|
192
|
-
//# sourceMappingURL=stacks-
|
|
192
|
+
//# sourceMappingURL=stacks-6n2m9hyk.js.map
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// src/bitcoin/serialize.ts
|
|
2
|
+
function doubleSha256(bytes) {
|
|
3
|
+
return import_sha2.sha256(import_sha2.sha256(bytes));
|
|
4
|
+
}
|
|
5
|
+
function reverseBytes(bytes) {
|
|
6
|
+
const out = new Uint8Array(bytes.length);
|
|
7
|
+
for (let i = 0;i < bytes.length; i++) {
|
|
8
|
+
out[i] = bytes[bytes.length - 1 - i];
|
|
9
|
+
}
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class BtcReader {
|
|
14
|
+
data;
|
|
15
|
+
view;
|
|
16
|
+
offset = 0;
|
|
17
|
+
constructor(data) {
|
|
18
|
+
this.data = data;
|
|
19
|
+
this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
20
|
+
}
|
|
21
|
+
get length() {
|
|
22
|
+
return this.data.length;
|
|
23
|
+
}
|
|
24
|
+
readUInt8() {
|
|
25
|
+
const v = this.view.getUint8(this.offset);
|
|
26
|
+
this.offset += 1;
|
|
27
|
+
return v;
|
|
28
|
+
}
|
|
29
|
+
peekUInt8() {
|
|
30
|
+
return this.view.getUint8(this.offset);
|
|
31
|
+
}
|
|
32
|
+
readUInt32LE() {
|
|
33
|
+
const v = this.view.getUint32(this.offset, true);
|
|
34
|
+
this.offset += 4;
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
readUInt64LE() {
|
|
38
|
+
const v = this.view.getBigUint64(this.offset, true);
|
|
39
|
+
this.offset += 8;
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
readBytes(n) {
|
|
43
|
+
if (this.offset + n > this.data.length) {
|
|
44
|
+
throw new Error(`Bitcoin tx underflow: need ${n} bytes at offset ${this.offset}, have ${this.data.length}`);
|
|
45
|
+
}
|
|
46
|
+
const slice = this.data.slice(this.offset, this.offset + n);
|
|
47
|
+
this.offset += n;
|
|
48
|
+
return slice;
|
|
49
|
+
}
|
|
50
|
+
readVarInt() {
|
|
51
|
+
const first = this.readUInt8();
|
|
52
|
+
if (first < 253)
|
|
53
|
+
return first;
|
|
54
|
+
if (first === 253) {
|
|
55
|
+
const v = this.view.getUint16(this.offset, true);
|
|
56
|
+
this.offset += 2;
|
|
57
|
+
return v;
|
|
58
|
+
}
|
|
59
|
+
if (first === 254) {
|
|
60
|
+
return this.readUInt32LE();
|
|
61
|
+
}
|
|
62
|
+
const big = this.readUInt64LE();
|
|
63
|
+
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
64
|
+
throw new Error("Bitcoin varint exceeds safe integer range");
|
|
65
|
+
}
|
|
66
|
+
return Number(big);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function scanTx(rawTx) {
|
|
70
|
+
const r = new BtcReader(rawTx);
|
|
71
|
+
const version = r.readUInt32LE();
|
|
72
|
+
let hasWitness = false;
|
|
73
|
+
if (r.peekUInt8() === 0) {
|
|
74
|
+
r.readUInt8();
|
|
75
|
+
const flag = r.readUInt8();
|
|
76
|
+
if (flag !== 1) {
|
|
77
|
+
throw new Error(`Unexpected SegWit flag 0x${flag.toString(16)}`);
|
|
78
|
+
}
|
|
79
|
+
hasWitness = true;
|
|
80
|
+
}
|
|
81
|
+
const bodyStart = r.offset;
|
|
82
|
+
const inputCount = r.readVarInt();
|
|
83
|
+
const inputs = [];
|
|
84
|
+
for (let i = 0;i < inputCount; i++) {
|
|
85
|
+
const prevTxid = r.readBytes(32);
|
|
86
|
+
const vout = r.readUInt32LE();
|
|
87
|
+
const scriptSig = r.readBytes(r.readVarInt());
|
|
88
|
+
const sequence = r.readUInt32LE();
|
|
89
|
+
inputs.push({ prevTxid, vout, scriptSig, sequence });
|
|
90
|
+
}
|
|
91
|
+
const outputCount = r.readVarInt();
|
|
92
|
+
const outputs = [];
|
|
93
|
+
for (let i = 0;i < outputCount; i++) {
|
|
94
|
+
const value = r.readUInt64LE();
|
|
95
|
+
const scriptPubKey = r.readBytes(r.readVarInt());
|
|
96
|
+
outputs.push({ value, scriptPubKey });
|
|
97
|
+
}
|
|
98
|
+
const bodyEnd = r.offset;
|
|
99
|
+
if (hasWitness) {
|
|
100
|
+
for (let i = 0;i < inputCount; i++) {
|
|
101
|
+
const itemCount = r.readVarInt();
|
|
102
|
+
for (let j = 0;j < itemCount; j++) {
|
|
103
|
+
r.readBytes(r.readVarInt());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const locktime = r.readUInt32LE();
|
|
108
|
+
const legacy = concatBytes(rawTx.slice(0, 4), rawTx.slice(bodyStart, bodyEnd), rawTx.slice(r.offset - 4, r.offset));
|
|
109
|
+
return { version, hasWitness, inputs, outputs, locktime, legacy };
|
|
110
|
+
}
|
|
111
|
+
function parseBitcoinTx(rawTx) {
|
|
112
|
+
const s = scanTx(rawTx);
|
|
113
|
+
return {
|
|
114
|
+
version: s.version,
|
|
115
|
+
hasWitness: s.hasWitness,
|
|
116
|
+
inputs: s.inputs,
|
|
117
|
+
outputs: s.outputs,
|
|
118
|
+
locktime: s.locktime,
|
|
119
|
+
txidInternal: doubleSha256(s.legacy)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function stripWitness(rawTx) {
|
|
123
|
+
return scanTx(rawTx).legacy;
|
|
124
|
+
}
|
|
125
|
+
function bitcoinTxid(rawTx, { display = false } = {}) {
|
|
126
|
+
const txid = doubleSha256(scanTx(rawTx).legacy);
|
|
127
|
+
return display ? reverseBytes(txid) : txid;
|
|
128
|
+
}
|
|
129
|
+
function parseBlockHeader(header) {
|
|
130
|
+
if (header.length !== 80) {
|
|
131
|
+
throw new Error(`Bitcoin block header must be 80 bytes, got ${header.length}`);
|
|
132
|
+
}
|
|
133
|
+
const r = new BtcReader(header);
|
|
134
|
+
const version = r.readUInt32LE();
|
|
135
|
+
const prevBlock = r.readBytes(32);
|
|
136
|
+
const merkleRoot = r.readBytes(32);
|
|
137
|
+
const timestamp = r.readUInt32LE();
|
|
138
|
+
const bits = r.readUInt32LE();
|
|
139
|
+
const nonce = r.readUInt32LE();
|
|
140
|
+
return { version, prevBlock, merkleRoot, timestamp, bits, nonce };
|
|
141
|
+
}
|
|
142
|
+
function blockHash(header, { display = false } = {}) {
|
|
143
|
+
const hash = doubleSha256(header);
|
|
144
|
+
return display ? reverseBytes(hash) : hash;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/bitcoin/address.ts
|
|
148
|
+
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
149
|
+
var BITCOIN_NETWORK_PARAMS = {
|
|
150
|
+
mainnet: { p2pkh: 0, p2sh: 5, hrp: "bc" },
|
|
151
|
+
testnet: { p2pkh: 111, p2sh: 196, hrp: "tb" },
|
|
152
|
+
regtest: { p2pkh: 111, p2sh: 196, hrp: "bcrt" }
|
|
153
|
+
};
|
|
154
|
+
var NETWORK_PARAMS = BITCOIN_NETWORK_PARAMS;
|
|
155
|
+
function base58Check(version, payload) {
|
|
156
|
+
const data = concatBytes(Uint8Array.of(version), payload);
|
|
157
|
+
const checksum = doubleSha256(data).slice(0, 4);
|
|
158
|
+
return base58.encode(concatBytes(data, checksum));
|
|
159
|
+
}
|
|
160
|
+
function formatBitcoinAddress(parsed, network = "mainnet") {
|
|
161
|
+
const params = NETWORK_PARAMS[network];
|
|
162
|
+
const hash = parsed.hash;
|
|
163
|
+
if (!hash)
|
|
164
|
+
return;
|
|
165
|
+
switch (parsed.type) {
|
|
166
|
+
case "p2pkh":
|
|
167
|
+
return base58Check(params.p2pkh, hash);
|
|
168
|
+
case "p2sh":
|
|
169
|
+
return base58Check(params.p2sh, hash);
|
|
170
|
+
case "p2wpkh":
|
|
171
|
+
case "p2wsh":
|
|
172
|
+
return bech32.encode(params.hrp, [0, ...bech32.toWords(hash)]);
|
|
173
|
+
case "p2tr":
|
|
174
|
+
return bech32m.encode(params.hrp, [1, ...bech32m.toWords(hash)]);
|
|
175
|
+
default:
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function toPubkeyBytes(publicKey) {
|
|
180
|
+
return typeof publicKey === "string" ? hexToBytes(publicKey) : publicKey;
|
|
181
|
+
}
|
|
182
|
+
function taprootTweakPubkey(xonly) {
|
|
183
|
+
if (xonly.length !== 32)
|
|
184
|
+
throw new Error(`Expected 32-byte x-only pubkey, got ${xonly.length}`);
|
|
185
|
+
const tweak = import_secp256k1.schnorr.utils.taggedHash("TapTweak", xonly);
|
|
186
|
+
const t = BigInt(`0x${Array.from(tweak, (b) => b.toString(16).padStart(2, "0")).join("")}`);
|
|
187
|
+
if (t >= import_secp256k1.secp256k1.Point.Fn.ORDER)
|
|
188
|
+
throw new Error("Invalid tap tweak (exceeds curve order)");
|
|
189
|
+
const internal = import_secp256k1.secp256k1.Point.fromBytes(concatBytes(Uint8Array.of(2), xonly));
|
|
190
|
+
const output = internal.add(import_secp256k1.secp256k1.Point.BASE.multiply(t));
|
|
191
|
+
return output.toBytes(true).slice(1);
|
|
192
|
+
}
|
|
193
|
+
function publicKeyToP2wpkhAddress(publicKey, network = "mainnet") {
|
|
194
|
+
const pubkey = toPubkeyBytes(publicKey);
|
|
195
|
+
if (pubkey.length !== 33)
|
|
196
|
+
throw new Error(`Expected 33-byte compressed pubkey, got ${pubkey.length}`);
|
|
197
|
+
const params = NETWORK_PARAMS[network];
|
|
198
|
+
return bech32.encode(params.hrp, [0, ...bech32.toWords(hash160(pubkey))]);
|
|
199
|
+
}
|
|
200
|
+
function publicKeyToP2trAddress(publicKey, network = "mainnet") {
|
|
201
|
+
const pubkey = toPubkeyBytes(publicKey);
|
|
202
|
+
const xonly = pubkey.length === 33 ? pubkey.slice(1) : pubkey.length === 32 ? pubkey : undefined;
|
|
203
|
+
if (!xonly)
|
|
204
|
+
throw new Error(`Expected 33-byte compressed or 32-byte x-only pubkey, got ${pubkey.length}`);
|
|
205
|
+
const params = NETWORK_PARAMS[network];
|
|
206
|
+
const outputKey = taprootTweakPubkey(xonly);
|
|
207
|
+
return bech32m.encode(params.hrp, [1, ...bech32m.toWords(outputKey)]);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//# debugId=ED78FA66DEC3D66764756E2164756E21
|
|
211
|
+
//# sourceMappingURL=stacks-bnbdqznq.cjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/bitcoin/serialize.ts", "../src/bitcoin/address.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { concatBytes } from \"../utils/encoding.ts\";\nimport { sha256 } from \"../utils/hash.ts\";\n\n/**\n * Bitcoin double-SHA256: `sha256(sha256(bytes))`. This is the hash Bitcoin uses\n * for txids, block headers, and merkle nodes — NOT the same as the Stacks\n * `txidFromBytes` (which uses sha512_256), so it lives here, not in `utils/hash`.\n */\nexport function doubleSha256(bytes: Uint8Array): Uint8Array {\n\treturn sha256(sha256(bytes));\n}\n\n/**\n * Reverse a byte array. Bitcoin hashes are computed and stored in *internal*\n * (little-endian) order but *displayed* big-endian, so the two differ by a\n * reversal. The SIP-044 built-ins consume internal order; only reverse for\n * display / when matching an explorer value.\n */\nexport function reverseBytes(bytes: Uint8Array): Uint8Array {\n\tconst out = new Uint8Array(bytes.length);\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tout[i] = bytes[bytes.length - 1 - i] as number;\n\t}\n\treturn out;\n}\n\n/**\n * A little-endian, varint-aware byte reader for Bitcoin serialization. The\n * shared `utils/BytesReader` is big-endian only; Bitcoin tx fields are\n * little-endian with compact-size (varint) length prefixes.\n */\nexport class BtcReader {\n\tprivate readonly data: Uint8Array;\n\tprivate readonly view: DataView;\n\tpublic offset = 0;\n\n\tconstructor(data: Uint8Array) {\n\t\tthis.data = data;\n\t\tthis.view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n\t}\n\n\tget length(): number {\n\t\treturn this.data.length;\n\t}\n\n\treadUInt8(): number {\n\t\tconst v = this.view.getUint8(this.offset);\n\t\tthis.offset += 1;\n\t\treturn v;\n\t}\n\n\t/** Read the next byte without advancing. */\n\tpeekUInt8(): number {\n\t\treturn this.view.getUint8(this.offset);\n\t}\n\n\treadUInt32LE(): number {\n\t\tconst v = this.view.getUint32(this.offset, true);\n\t\tthis.offset += 4;\n\t\treturn v;\n\t}\n\n\treadUInt64LE(): bigint {\n\t\tconst v = this.view.getBigUint64(this.offset, true);\n\t\tthis.offset += 8;\n\t\treturn v;\n\t}\n\n\treadBytes(n: number): Uint8Array {\n\t\tif (this.offset + n > this.data.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Bitcoin tx underflow: need ${n} 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 + n);\n\t\tthis.offset += n;\n\t\treturn slice;\n\t}\n\n\t/** Read a Bitcoin compact-size unsigned integer (varint). */\n\treadVarInt(): number {\n\t\tconst first = this.readUInt8();\n\t\tif (first < 0xfd) return first;\n\t\tif (first === 0xfd) {\n\t\t\tconst v = this.view.getUint16(this.offset, true);\n\t\t\tthis.offset += 2;\n\t\t\treturn v;\n\t\t}\n\t\tif (first === 0xfe) {\n\t\t\treturn this.readUInt32LE();\n\t\t}\n\t\tconst big = this.readUInt64LE();\n\t\tif (big > BigInt(Number.MAX_SAFE_INTEGER)) {\n\t\t\tthrow new Error(\"Bitcoin varint exceeds safe integer range\");\n\t\t}\n\t\treturn Number(big);\n\t}\n}\n\nexport interface BitcoinTxInput {\n\t/** Previous output txid, in serialized (internal) byte order. */\n\tprevTxid: Uint8Array;\n\tvout: number;\n\tscriptSig: Uint8Array;\n\tsequence: number;\n}\n\nexport interface BitcoinTxOutput {\n\t/** Output value in satoshis. */\n\tvalue: bigint;\n\tscriptPubKey: Uint8Array;\n}\n\nexport interface ParsedBitcoinTx {\n\tversion: number;\n\thasWitness: boolean;\n\tinputs: BitcoinTxInput[];\n\toutputs: BitcoinTxOutput[];\n\tlocktime: number;\n\t/**\n\t * The legacy txid as the raw double-SHA256 in *internal* byte order — ready\n\t * to pass as the leaf to `verify-merkle-proof`. Witness data is excluded\n\t * (the txid is computed over the legacy serialization), so this is stable for\n\t * both legacy and SegWit txs. Use `reverseBytes` for the displayed form.\n\t */\n\ttxidInternal: Uint8Array;\n}\n\ninterface ScanResult {\n\tversion: number;\n\thasWitness: boolean;\n\tinputs: BitcoinTxInput[];\n\toutputs: BitcoinTxOutput[];\n\tlocktime: number;\n\t/** The legacy (witness-stripped) serialization — what the txid is hashed over. */\n\tlegacy: Uint8Array;\n}\n\n/**\n * Single-pass scan of a raw Bitcoin tx. Captures the inputs/outputs slice and\n * reassembles the legacy serialization so both `parseBitcoinTx` and\n * `stripWitness` share one parser (and one set of foot-guns).\n */\nfunction scanTx(rawTx: Uint8Array): ScanResult {\n\tconst r = new BtcReader(rawTx);\n\tconst version = r.readUInt32LE();\n\n\t// SegWit marker (0x00) + flag (0x01) sit immediately after the version. A\n\t// legacy tx can never have a zero input count, so 0x00 here is unambiguous.\n\tlet hasWitness = false;\n\tif (r.peekUInt8() === 0x00) {\n\t\tr.readUInt8(); // marker\n\t\tconst flag = r.readUInt8();\n\t\tif (flag !== 0x01) {\n\t\t\tthrow new Error(`Unexpected SegWit flag 0x${flag.toString(16)}`);\n\t\t}\n\t\thasWitness = true;\n\t}\n\n\tconst bodyStart = r.offset;\n\tconst inputCount = r.readVarInt();\n\tconst inputs: BitcoinTxInput[] = [];\n\tfor (let i = 0; i < inputCount; i++) {\n\t\tconst prevTxid = r.readBytes(32);\n\t\tconst vout = r.readUInt32LE();\n\t\tconst scriptSig = r.readBytes(r.readVarInt());\n\t\tconst sequence = r.readUInt32LE();\n\t\tinputs.push({ prevTxid, vout, scriptSig, sequence });\n\t}\n\n\tconst outputCount = r.readVarInt();\n\tconst outputs: BitcoinTxOutput[] = [];\n\tfor (let i = 0; i < outputCount; i++) {\n\t\tconst value = r.readUInt64LE();\n\t\tconst scriptPubKey = r.readBytes(r.readVarInt());\n\t\toutputs.push({ value, scriptPubKey });\n\t}\n\tconst bodyEnd = r.offset;\n\n\tif (hasWitness) {\n\t\tfor (let i = 0; i < inputCount; i++) {\n\t\t\tconst itemCount = r.readVarInt();\n\t\t\tfor (let j = 0; j < itemCount; j++) {\n\t\t\t\tr.readBytes(r.readVarInt());\n\t\t\t}\n\t\t}\n\t}\n\n\tconst locktime = r.readUInt32LE();\n\n\tconst legacy = concatBytes(\n\t\trawTx.slice(0, 4),\n\t\trawTx.slice(bodyStart, bodyEnd),\n\t\trawTx.slice(r.offset - 4, r.offset),\n\t);\n\n\treturn { version, hasWitness, inputs, outputs, locktime, legacy };\n}\n\n/** Parse a serialized Bitcoin tx (legacy or SegWit) into its fields + txid. */\nexport function parseBitcoinTx(rawTx: Uint8Array): ParsedBitcoinTx {\n\tconst s = scanTx(rawTx);\n\treturn {\n\t\tversion: s.version,\n\t\thasWitness: s.hasWitness,\n\t\tinputs: s.inputs,\n\t\toutputs: s.outputs,\n\t\tlocktime: s.locktime,\n\t\ttxidInternal: doubleSha256(s.legacy),\n\t};\n}\n\n/**\n * Return the legacy (witness-stripped) serialization of a tx. For a legacy tx\n * this is the input unchanged; for a SegWit tx the marker, flag, and witness\n * stack are removed. This is the byte string the txid is hashed over.\n */\nexport function stripWitness(rawTx: Uint8Array): Uint8Array {\n\treturn scanTx(rawTx).legacy;\n}\n\n/**\n * Compute a tx's id from its raw serialization. Internal byte order by default\n * (the merkle leaf / built-in input); pass `{ display: true }` for the\n * explorer-style big-endian form.\n */\nexport function bitcoinTxid(\n\trawTx: Uint8Array,\n\t{ display = false }: { display?: boolean } = {},\n): Uint8Array {\n\tconst txid = doubleSha256(scanTx(rawTx).legacy);\n\treturn display ? reverseBytes(txid) : txid;\n}\n\nexport interface BlockHeader {\n\tversion: number;\n\t/** Previous block hash, internal byte order. */\n\tprevBlock: Uint8Array;\n\t/** Merkle root, internal byte order — pairs with `verify-merkle-proof`. */\n\tmerkleRoot: Uint8Array;\n\ttimestamp: number;\n\tbits: number;\n\tnonce: number;\n}\n\n/** Parse an 80-byte Bitcoin block header into its fields (hashes internal order). */\nexport function parseBlockHeader(header: Uint8Array): BlockHeader {\n\tif (header.length !== 80) {\n\t\tthrow new Error(\n\t\t\t`Bitcoin block header must be 80 bytes, got ${header.length}`,\n\t\t);\n\t}\n\tconst r = new BtcReader(header);\n\tconst version = r.readUInt32LE();\n\tconst prevBlock = r.readBytes(32);\n\tconst merkleRoot = r.readBytes(32);\n\tconst timestamp = r.readUInt32LE();\n\tconst bits = r.readUInt32LE();\n\tconst nonce = r.readUInt32LE();\n\treturn { version, prevBlock, merkleRoot, timestamp, bits, nonce };\n}\n\n/**\n * Hash an 80-byte block header (double-SHA256). Internal byte order by default;\n * `{ display: true }` for the explorer-style block hash.\n */\nexport function blockHash(\n\theader: Uint8Array,\n\t{ display = false }: { display?: boolean } = {},\n): Uint8Array {\n\tconst hash = doubleSha256(header);\n\treturn display ? reverseBytes(hash) : hash;\n}\n",
|
|
6
|
+
"import { schnorr, secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { base58, bech32, bech32m } from \"@scure/base\";\nimport { concatBytes, hexToBytes } from \"../utils/encoding.ts\";\nimport { hash160 } from \"../utils/hash.ts\";\nimport type { ParsedOutputScript } from \"./codec.ts\";\nimport type { BitcoinNetwork } from \"./constants.ts\";\nimport { doubleSha256 } from \"./serialize.ts\";\n\n/** Address-encoding parameters (base58 version bytes + bech32 hrp) per network. */\nexport const BITCOIN_NETWORK_PARAMS = {\n\tmainnet: { p2pkh: 0x00, p2sh: 0x05, hrp: \"bc\" },\n\ttestnet: { p2pkh: 0x6f, p2sh: 0xc4, hrp: \"tb\" },\n\tregtest: { p2pkh: 0x6f, p2sh: 0xc4, hrp: \"bcrt\" },\n} as const;\n\nconst NETWORK_PARAMS = BITCOIN_NETWORK_PARAMS;\n\n/** Base58Check-encode a versioned 20-byte payload (legacy P2PKH / P2SH). */\nfunction base58Check(version: number, payload: Uint8Array): string {\n\tconst data = concatBytes(Uint8Array.of(version), payload);\n\tconst checksum = doubleSha256(data).slice(0, 4);\n\treturn base58.encode(concatBytes(data, checksum));\n}\n\n/**\n * Render a parsed output script as a Bitcoin address for the given network.\n * Returns `undefined` for scripts without a standard address (OP_RETURN, P2PK,\n * unknown). Address encoding is network-dependent, which is why this is separate\n * from the pure `parseOutputScript` decoder.\n */\nexport function formatBitcoinAddress(\n\tparsed: ParsedOutputScript,\n\tnetwork: BitcoinNetwork = \"mainnet\",\n): string | undefined {\n\tconst params = NETWORK_PARAMS[network];\n\tconst hash = parsed.hash;\n\tif (!hash) return undefined;\n\tswitch (parsed.type) {\n\t\tcase \"p2pkh\":\n\t\t\treturn base58Check(params.p2pkh, hash);\n\t\tcase \"p2sh\":\n\t\t\treturn base58Check(params.p2sh, hash);\n\t\tcase \"p2wpkh\":\n\t\tcase \"p2wsh\":\n\t\t\treturn bech32.encode(params.hrp, [0, ...bech32.toWords(hash)]);\n\t\tcase \"p2tr\":\n\t\t\treturn bech32m.encode(params.hrp, [1, ...bech32m.toWords(hash)]);\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nfunction toPubkeyBytes(publicKey: Uint8Array | string): Uint8Array {\n\treturn typeof publicKey === \"string\" ? hexToBytes(publicKey) : publicKey;\n}\n\n/**\n * BIP341 key-path tweak: lift the x-only internal key to a point, add\n * `tapTweakHash(P)·G` (no script tree), and return the x-only output key.\n */\nexport function taprootTweakPubkey(xonly: Uint8Array): Uint8Array {\n\tif (xonly.length !== 32)\n\t\tthrow new Error(`Expected 32-byte x-only pubkey, got ${xonly.length}`);\n\tconst tweak = schnorr.utils.taggedHash(\"TapTweak\", xonly);\n\tconst t = BigInt(\n\t\t`0x${Array.from(tweak, (b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`,\n\t);\n\tif (t >= secp256k1.Point.Fn.ORDER)\n\t\tthrow new Error(\"Invalid tap tweak (exceeds curve order)\");\n\tconst internal = secp256k1.Point.fromBytes(\n\t\tconcatBytes(Uint8Array.of(0x02), xonly),\n\t);\n\tconst output = internal.add(secp256k1.Point.BASE.multiply(t));\n\treturn output.toBytes(true).slice(1);\n}\n\n/**\n * Derive the native-segwit (P2WPKH, bech32 v0) address for a compressed\n * public key.\n */\nexport function publicKeyToP2wpkhAddress(\n\tpublicKey: Uint8Array | string,\n\tnetwork: BitcoinNetwork = \"mainnet\",\n): string {\n\tconst pubkey = toPubkeyBytes(publicKey);\n\tif (pubkey.length !== 33)\n\t\tthrow new Error(`Expected 33-byte compressed pubkey, got ${pubkey.length}`);\n\tconst params = NETWORK_PARAMS[network];\n\treturn bech32.encode(params.hrp, [0, ...bech32.toWords(hash160(pubkey))]);\n}\n\n/**\n * Derive the taproot (P2TR, bech32m v1) address for a public key — BIP341\n * key-path spend, no script tree. Accepts a 33-byte compressed key (the\n * parity byte is dropped) or a 32-byte x-only key.\n */\nexport function publicKeyToP2trAddress(\n\tpublicKey: Uint8Array | string,\n\tnetwork: BitcoinNetwork = \"mainnet\",\n): string {\n\tconst pubkey = toPubkeyBytes(publicKey);\n\tconst xonly =\n\t\tpubkey.length === 33\n\t\t\t? pubkey.slice(1)\n\t\t\t: pubkey.length === 32\n\t\t\t\t? pubkey\n\t\t\t\t: undefined;\n\tif (!xonly)\n\t\tthrow new Error(\n\t\t\t`Expected 33-byte compressed or 32-byte x-only pubkey, got ${pubkey.length}`,\n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