@secondlayer/stacks 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-0rdxcta7.js} +2 -2
- package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-0rdxcta7.js.map} +1 -1
- package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-1jae0a3r.js} +2 -2
- package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-1jae0a3r.js.map} +1 -1
- package/dist/shared/{stacks-4d7c3x27.js → stacks-esm-2mc7ebrm.js} +3 -3
- package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-2mc7ebrm.js.map} +1 -1
- package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-3g33bqsm.js} +4 -4
- package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-3g33bqsm.js.map} +1 -1
- package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-3pv5avgr.js} +59 -15
- package/dist/shared/stacks-esm-3pv5avgr.js.map +12 -0
- package/dist/shared/{stacks-qex691bh.js → stacks-esm-743jfh10.js} +6 -6
- package/dist/shared/{stacks-qex691bh.js.map → stacks-esm-743jfh10.js.map} +1 -1
- package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-7fpqgtyx.js} +3 -3
- package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-7fpqgtyx.js.map} +1 -1
- package/dist/shared/{stacks-71k0vmct.js → stacks-esm-9rnx0zxr.js} +5 -5
- package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-9rnx0zxr.js.map} +1 -1
- package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-aw2mj3sj.js} +7 -7
- package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-aw2mj3sj.js.map} +1 -1
- package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-cvhazvhd.js} +2 -2
- package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-cvhazvhd.js.map} +1 -1
- package/dist/shared/{stacks-69nq48jp.js → stacks-esm-fcfdn2zx.js} +5 -5
- package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-fcfdn2zx.js.map} +1 -1
- package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-hr7fpxtj.js} +4 -4
- package/dist/shared/{stacks-x0qqwrev.js.map → stacks-esm-hr7fpxtj.js.map} +1 -1
- package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-kds4n82p.js} +11 -11
- package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-kds4n82p.js.map} +1 -1
- package/dist/shared/{stacks-kg1npstf.js → stacks-esm-n53kvwmt.js} +2 -2
- package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-n53kvwmt.js.map} +1 -1
- package/dist/shared/{stacks-v2rfr46a.js → stacks-esm-pxhfqfff.js} +4 -4
- package/dist/shared/{stacks-v2rfr46a.js.map → stacks-esm-pxhfqfff.js.map} +1 -1
- package/dist/shared/{stacks-yajyej2y.js → stacks-esm-q19a17fd.js} +3 -3
- package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-q19a17fd.js.map} +1 -1
- package/dist/shared/{stacks-v03zef3g.js → stacks-esm-qk0p9fr6.js} +9 -9
- package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-qk0p9fr6.js.map} +1 -1
- package/dist/shared/{stacks-qcae5852.js → stacks-esm-qkj67g80.js} +2 -2
- package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-qkj67g80.js.map} +1 -1
- package/dist/shared/{stacks-mftyrc60.js → stacks-esm-r6dejrgr.js} +4 -4
- package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-r6dejrgr.js.map} +1 -1
- package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-r9q4wnyw.js} +5 -5
- package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-r9q4wnyw.js.map} +1 -1
- package/dist/shared/{stacks-51ybf135.js → stacks-esm-skmcf5n2.js} +5 -5
- package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-skmcf5n2.js.map} +1 -1
- package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-v45990hx.js} +2 -2
- package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-v45990hx.js.map} +1 -1
- package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-wv67m4g6.js} +3 -3
- package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-wv67m4g6.js.map} +1 -1
- package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-x1r01353.js} +5 -5
- package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-x1r01353.js.map} +1 -1
- package/dist/src/accounts/index.cjs +558 -4
- package/dist/src/accounts/index.cjs.map +10 -4
- package/dist/src/accounts/index.js +3 -3
- package/dist/src/actions/index.cjs +3815 -1
- package/dist/src/actions/index.cjs.map +65 -3
- package/dist/src/actions/index.js +14 -14
- package/dist/src/bitcoin/index.cjs +2477 -1
- package/dist/src/bitcoin/index.cjs.map +31 -3
- package/dist/src/bitcoin/index.js +11 -11
- package/dist/src/bns/index.cjs +4439 -17
- package/dist/src/bns/index.cjs.map +50 -3
- package/dist/src/bns/index.js +14 -14
- package/dist/src/chains/index.cjs +135 -1
- package/dist/src/chains/index.cjs.map +5 -3
- package/dist/src/chains/index.js +1 -1
- package/dist/src/clarity/index.cjs +2019 -1
- package/dist/src/clarity/index.cjs.map +24 -3
- package/dist/src/clarity/index.js +8 -8
- package/dist/src/filters/index.cjs +725 -1
- package/dist/src/filters/index.cjs.map +11 -3
- package/dist/src/filters/index.d.cts +76 -13
- package/dist/src/filters/index.d.ts +76 -13
- package/dist/src/filters/index.js +8 -4
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/index.cjs +3935 -62
- package/dist/src/index.cjs.map +69 -4
- package/dist/src/index.d.cts +62 -11
- package/dist/src/index.d.ts +62 -11
- package/dist/src/index.js +16 -16
- package/dist/src/postconditions/index.cjs +1726 -1
- package/dist/src/postconditions/index.cjs.map +20 -3
- package/dist/src/postconditions/index.js +6 -6
- package/dist/src/pox/index.cjs +3855 -1
- package/dist/src/pox/index.cjs.map +48 -3
- package/dist/src/pox/index.js +13 -13
- package/dist/src/pox5/index.cjs +4054 -29
- package/dist/src/pox5/index.cjs.map +54 -3
- package/dist/src/pox5/index.js +15 -15
- package/dist/src/sbtc/index.cjs +3705 -4
- package/dist/src/sbtc/index.cjs.map +47 -3
- package/dist/src/sbtc/index.js +12 -12
- package/dist/src/stackingdao/index.cjs +3751 -8
- package/dist/src/stackingdao/index.cjs.map +45 -3
- package/dist/src/stackingdao/index.js +12 -12
- package/dist/src/subscriptions/index.cjs +153 -1
- package/dist/src/subscriptions/index.cjs.map +6 -3
- package/dist/src/subscriptions/index.js +2 -2
- package/dist/src/transactions/index.cjs +2139 -1
- package/dist/src/transactions/index.cjs.map +23 -3
- package/dist/src/transactions/index.js +6 -6
- package/dist/src/utils/index.cjs +435 -3
- package/dist/src/utils/index.cjs.map +9 -3
- package/dist/src/utils/index.js +3 -3
- package/package.json +1 -1
- package/dist/shared/stacks-02actsrx.cjs +0 -17
- package/dist/shared/stacks-02actsrx.cjs.map +0 -10
- package/dist/shared/stacks-03vfm21t.cjs +0 -222
- package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
- package/dist/shared/stacks-24h5k94q.cjs +0 -74
- package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
- package/dist/shared/stacks-37kz5t9f.cjs +0 -764
- package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
- package/dist/shared/stacks-3mt2q2na.cjs +0 -65
- package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
- package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
- package/dist/shared/stacks-8vzxax5e.cjs +0 -45
- package/dist/shared/stacks-agk106zs.cjs +0 -267
- package/dist/shared/stacks-agk106zs.cjs.map +0 -12
- package/dist/shared/stacks-bdgh9n83.cjs +0 -212
- package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
- package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
- package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
- package/dist/shared/stacks-ee53k9j2.cjs +0 -651
- package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
- package/dist/shared/stacks-enpj9krt.cjs +0 -38
- package/dist/shared/stacks-enpj9krt.cjs.map +0 -10
- package/dist/shared/stacks-f35mnrmg.cjs +0 -164
- package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
- package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
- package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
- package/dist/shared/stacks-gjz26k6b.js.map +0 -12
- package/dist/shared/stacks-gza2n1zs.cjs +0 -73
- package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
- package/dist/shared/stacks-kem68d80.cjs +0 -156
- package/dist/shared/stacks-kem68d80.cjs.map +0 -10
- package/dist/shared/stacks-n98w7g57.cjs +0 -234
- package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
- package/dist/shared/stacks-p337hp6m.cjs +0 -336
- package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
- package/dist/shared/stacks-q34k4vnc.cjs +0 -286
- package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
- package/dist/shared/stacks-rryme9bv.cjs +0 -569
- package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
- package/dist/shared/stacks-s5vej5z6.cjs +0 -410
- package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
- package/dist/shared/stacks-sdqkapct.cjs +0 -67
- package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
- package/dist/shared/stacks-vea7nde7.cjs +0 -731
- package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
- package/dist/shared/stacks-wk8yp13j.cjs +0 -33
- package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
- package/dist/shared/stacks-xjkn3en1.cjs +0 -42
- package/dist/shared/stacks-xnrywjf1.cjs +0 -131
- package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
- package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/transactions/types.ts", "../src/transactions/wire/serialize.ts", "../src/transactions/wire/deserialize.ts", "../src/postconditions/convert.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"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\tClarity6: 6, // SIP-044, Epoch 4.0\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\tOriginator: 0x03, // SIP-040, Epoch 3.4\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\tMaybeSent: 0x12, // SIP-040, Epoch 3.4\n} as const;\n\n// PoX condition codes (wire format, SIP-045)\nexport const PoxConditionCode = {\n\tWillNotPerform: 0x30,\n\tMayPerform: 0x31,\n\tWillPerform: 0x32,\n} as const;\nexport type PoxConditionCode =\n\t(typeof PoxConditionCode)[keyof typeof PoxConditionCode];\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\tStaking: 0x03, // SIP-045\n\tPox: 0x04, // SIP-045\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\t/** Multi-sig signer metadata — not part of the wire format, preserved\n\t * through serialize/deserialize round-trip for auto-detection. */\n\t_multisig?: { publicKeys: string[] };\n};\n\n// Wire post condition types\nexport type PostConditionWire =\n\t| StxPostConditionWire\n\t| FtPostConditionWire\n\t| NftPostConditionWire\n\t| StakingPostConditionWire\n\t| PoxPostConditionWire;\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\n// SIP-045: gates stake/register-for-bond/stake-update; same shape as STX\nexport type StakingPostConditionWire = {\n\ttype: \"staking\";\n\tprincipal: PostConditionPrincipalWire;\n\tconditionCode: number;\n\tamount: bigint;\n};\n\n// SIP-045: gates non-locking PoX state changes (unstake, announce-l1-early-exit, …); no amount\nexport type PoxPostConditionWire = {\n\ttype: \"pox\";\n\tprincipal: PostConditionPrincipalWire;\n\tconditionCode: PoxConditionCode;\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",
|
|
6
|
-
"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}\n\tconst typeId = field.pubKeyEncoding === 0x00 ? 0x02 : 0x03;\n\treturn concatBytes(writeUInt8(typeId), hexToBytes(field.data));\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\nexport function serializePostConditionWire(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\tcase \"staking\":\n\t\t\t// SIP-045: same body as STX (fungible condition code + amount)\n\t\t\tparts.push(writeUInt8(AssetType.Staking));\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 \"pox\":\n\t\t\t// SIP-045: PoX condition code only, no amount\n\t\t\tparts.push(writeUInt8(AssetType.Pox));\n\t\t\tparts.push(serializePrincipal(pc.principal));\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) parts.push(serializePostConditionWire(pc));\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\n// Memoization cache: transactions are immutable in practice (fields are set\n// once during build/signing), so the serialized bytes for a given transaction\n// object never change. The signing flow serializes the same object several\n// times (txid, sighash, sponsor sighash); caching avoids that redundant work.\n// Any in-place mutation MUST call clearTxCache — see setUnsignedFee.\nconst _txCache = new WeakMap<StacksTransaction, Uint8Array>();\n\n/** Invalidate the memoized serialization of a mutated transaction */\nexport function clearTxCache(tx: StacksTransaction): void {\n\t_txCache.delete(tx);\n}\n\nexport function serializeTransaction(tx: StacksTransaction): Uint8Array {\n\tconst cached = _txCache.get(tx);\n\tif (cached) return cached;\n\tconst bytes = 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\t_txCache.set(tx, bytes);\n\treturn bytes;\n}\n\nexport function serializeTransactionHex(tx: StacksTransaction): string {\n\treturn bytesToHex(serializeTransaction(tx));\n}\n\n/** Serialize a transaction, returning the wire bytes plus the out-of-band\n * `_multisig` metadata so callers can preserve it across a round-trip\n * (the wire format itself does not carry it). */\nexport function serializeTransactionWithMeta(tx: StacksTransaction): {\n\tbytes: Uint8Array;\n\t_multisig?: { publicKeys: string[] };\n} {\n\treturn { bytes: serializeTransaction(tx), _multisig: tx._multisig };\n}\n",
|
|
7
|
-
"import {\n\treadAddress,\n\treadCV,\n\treadLPString,\n} from \"../../clarity/deserialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { BytesReader } from \"../../utils/bytes-reader.ts\";\nimport {\n\tbytesToAscii,\n\tbytesToHex,\n\thexToBytes,\n\twithout0x,\n} from \"../../utils/encoding.ts\";\nimport {\n\tAddressHashMode,\n\ttype AnchorMode,\n\ttype AssetInfoWire,\n\tAssetType,\n\tAuthType,\n\ttype Authorization,\n\tCOINBASE_BYTES_LENGTH,\n\ttype ClarityVersion,\n\tMEMO_MAX_LENGTH_BYTES,\n\tMICROBLOCK_HEADER_BYTES_LENGTH,\n\tPayloadType,\n\ttype PostConditionModeWire,\n\tPostConditionPrincipalId,\n\ttype PostConditionPrincipalWire,\n\ttype PostConditionWire,\n\ttype PoxConditionCode,\n\tRECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n\ttype SpendingCondition,\n\ttype StacksTransaction,\n\ttype TenureChangeCause,\n\ttype TransactionAuthField,\n\ttype TransactionPayload,\n\tVRF_PROOF_BYTES_LENGTH,\n} from \"../types.ts\";\n\nfunction readSpendingCondition(r: BytesReader): SpendingCondition {\n\tconst hashMode = r.readUInt8();\n\tconst signer = bytesToHex(r.readBytes(20));\n\tconst nonce = r.readBigUInt64BE();\n\tconst fee = r.readBigUInt64BE();\n\n\tif (\n\t\thashMode === AddressHashMode.P2PKH ||\n\t\thashMode === AddressHashMode.P2WPKH\n\t) {\n\t\tconst keyEncoding = r.readUInt8();\n\t\tconst signature = bytesToHex(\n\t\t\tr.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES),\n\t\t);\n\t\treturn {\n\t\t\thashMode,\n\t\t\tsigner,\n\t\t\tnonce,\n\t\t\tfee,\n\t\t\tkeyEncoding,\n\t\t\tsignature,\n\t\t} as SpendingCondition;\n\t}\n\n\tconst fieldCount = r.readUInt32BE();\n\tconst fields: TransactionAuthField[] = [];\n\tfor (let i = 0; i < fieldCount; i++) {\n\t\tconst fieldType = r.readUInt8();\n\t\tif (fieldType <= 0x01) {\n\t\t\tconst keyLen = fieldType === 0x00 ? 33 : 65;\n\t\t\tfields.push({\n\t\t\t\ttype: \"publicKey\",\n\t\t\t\tpubKeyEncoding: fieldType as 0x00 | 0x01,\n\t\t\t\tdata: bytesToHex(r.readBytes(keyLen)),\n\t\t\t});\n\t\t} else {\n\t\t\tfields.push({\n\t\t\t\ttype: \"signature\",\n\t\t\t\tpubKeyEncoding: (fieldType === 0x02 ? 0x00 : 0x01) as 0x00 | 0x01,\n\t\t\t\tdata: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES)),\n\t\t\t});\n\t\t}\n\t}\n\tconst signaturesRequired = r.readUInt16BE();\n\n\treturn {\n\t\thashMode,\n\t\tsigner,\n\t\tnonce,\n\t\tfee,\n\t\tfields,\n\t\tsignaturesRequired,\n\t} as SpendingCondition;\n}\n\nfunction readAuthorization(r: BytesReader): Authorization {\n\tconst authType = r.readUInt8();\n\tconst spendingCondition = readSpendingCondition(r);\n\n\tif (authType === AuthType.Standard) {\n\t\treturn { authType: AuthType.Standard, spendingCondition };\n\t}\n\n\tconst sponsorSpendingCondition = readSpendingCondition(r);\n\treturn {\n\t\tauthType: AuthType.Sponsored,\n\t\tspendingCondition,\n\t\tsponsorSpendingCondition,\n\t};\n}\n\nfunction readAssetInfo(r: BytesReader): AssetInfoWire {\n\treturn {\n\t\taddress: readAddress(r),\n\t\tcontractName: readLPString(r),\n\t\tassetName: readLPString(r),\n\t};\n}\n\nfunction readPostConditionPrincipal(\n\tr: BytesReader,\n): PostConditionPrincipalWire {\n\tconst type = r.readUInt8();\n\tswitch (type) {\n\t\tcase PostConditionPrincipalId.Origin:\n\t\t\treturn { type: \"origin\" };\n\t\tcase PostConditionPrincipalId.Standard:\n\t\t\treturn { type: \"standard\", address: readAddress(r) };\n\t\tcase PostConditionPrincipalId.Contract:\n\t\t\treturn {\n\t\t\t\ttype: \"contract\",\n\t\t\t\taddress: readAddress(r),\n\t\t\t\tcontractName: readLPString(r),\n\t\t\t};\n\t\tdefault:\n\t\t\t// Some legacy transactions may have unexpected principal types.\n\t\t\t// Treat as origin to allow deserialization to continue.\n\t\t\treturn { type: \"origin\" };\n\t}\n}\n\nfunction readPostCondition(r: BytesReader): PostConditionWire {\n\t// Wire order: asset_type, then principal (per SIP-005 and stacks.js)\n\tconst assetType = r.readUInt8();\n\tconst principal = readPostConditionPrincipal(r);\n\tswitch (assetType) {\n\t\tcase AssetType.STX:\n\t\t\treturn {\n\t\t\t\ttype: \"stx\",\n\t\t\t\tprincipal,\n\t\t\t\tconditionCode: r.readUInt8(),\n\t\t\t\tamount: r.readBigUInt64BE(),\n\t\t\t};\n\t\tcase AssetType.Fungible:\n\t\t\treturn {\n\t\t\t\ttype: \"ft\",\n\t\t\t\tprincipal,\n\t\t\t\tasset: readAssetInfo(r),\n\t\t\t\tconditionCode: r.readUInt8(),\n\t\t\t\tamount: r.readBigUInt64BE(),\n\t\t\t};\n\t\tcase AssetType.NonFungible:\n\t\t\treturn {\n\t\t\t\ttype: \"nft\",\n\t\t\t\tprincipal,\n\t\t\t\tasset: readAssetInfo(r),\n\t\t\t\tassetId: readCV(r),\n\t\t\t\tconditionCode: r.readUInt8(),\n\t\t\t};\n\t\tcase AssetType.Staking:\n\t\t\treturn {\n\t\t\t\ttype: \"staking\",\n\t\t\t\tprincipal,\n\t\t\t\tconditionCode: r.readUInt8(),\n\t\t\t\tamount: r.readBigUInt64BE(),\n\t\t\t};\n\t\tcase AssetType.Pox:\n\t\t\treturn {\n\t\t\t\ttype: \"pox\",\n\t\t\t\tprincipal,\n\t\t\t\tconditionCode: r.readUInt8() as PoxConditionCode,\n\t\t\t};\n\t\tdefault:\n\t\t\tthrow new Error(\n\t\t\t\t`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, \"0\")}`,\n\t\t\t);\n\t}\n}\n\nfunction readPostConditions(r: BytesReader): PostConditionWire[] {\n\tconst count = r.readUInt32BE();\n\tconst pcs: PostConditionWire[] = [];\n\tfor (let i = 0; i < count; i++) {\n\t\ttry {\n\t\t\tpcs.push(readPostCondition(r));\n\t\t} catch (e) {\n\t\t\tif (\n\t\t\t\te instanceof Error &&\n\t\t\t\te.message.startsWith(\"Unknown post-condition asset type:\")\n\t\t\t) {\n\t\t\t\tthrow new Error(`${e.message} (post-condition ${i + 1}/${count})`);\n\t\t\t}\n\t\t\tthrow e;\n\t\t}\n\t}\n\treturn pcs;\n}\n\nfunction readPayload(r: BytesReader): TransactionPayload {\n\tconst payloadType = r.readUInt8();\n\n\tswitch (payloadType) {\n\t\tcase PayloadType.TokenTransfer: {\n\t\t\tconst recipient = readCV(r);\n\t\t\tconst amount = r.readBigUInt64BE();\n\t\t\t// Memo is a flat 34-byte field (no length prefix) per SIP-005\n\t\t\tconst memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);\n\t\t\tconst memo = bytesToAscii(memoBytes).replace(/\\0+$/, \"\");\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.TokenTransfer,\n\t\t\t\trecipient,\n\t\t\t\tamount,\n\t\t\t\tmemo,\n\t\t\t};\n\t\t}\n\t\tcase PayloadType.ContractCall: {\n\t\t\tconst contractAddress = readAddress(r);\n\t\t\tconst contractName = readLPString(r);\n\t\t\tconst functionName = readLPString(r);\n\t\t\tconst numArgs = r.readUInt32BE();\n\t\t\tconst functionArgs: ClarityValue[] = [];\n\t\t\tfor (let i = 0; i < numArgs; i++) functionArgs.push(readCV(r));\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.ContractCall,\n\t\t\t\tcontractAddress,\n\t\t\t\tcontractName,\n\t\t\t\tfunctionName,\n\t\t\t\tfunctionArgs,\n\t\t\t};\n\t\t}\n\t\tcase PayloadType.SmartContract: {\n\t\t\tconst contractName = readLPString(r);\n\t\t\tconst codeBody = readLPString(r, 4);\n\t\t\treturn { payloadType: PayloadType.SmartContract, contractName, codeBody };\n\t\t}\n\t\tcase PayloadType.VersionedSmartContract: {\n\t\t\tconst clarityVersion = r.readUInt8() as ClarityVersion;\n\t\t\tconst contractName = readLPString(r);\n\t\t\tconst codeBody = readLPString(r, 4);\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.VersionedSmartContract,\n\t\t\t\tclarityVersion,\n\t\t\t\tcontractName,\n\t\t\t\tcodeBody,\n\t\t\t};\n\t\t}\n\t\tcase PayloadType.Coinbase: {\n\t\t\tconst coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n\t\t\treturn { payloadType: PayloadType.Coinbase, coinbaseBuffer };\n\t\t}\n\t\tcase PayloadType.CoinbaseToAltRecipient: {\n\t\t\tconst coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n\t\t\tconst recipient = readCV(r);\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.CoinbaseToAltRecipient,\n\t\t\t\tcoinbaseBuffer,\n\t\t\t\trecipient,\n\t\t\t};\n\t\t}\n\t\tcase PayloadType.PoisonMicroblock: {\n\t\t\tconst header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));\n\t\t\tconst header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));\n\t\t\treturn { payloadType: PayloadType.PoisonMicroblock, header1, header2 };\n\t\t}\n\t\tcase PayloadType.TenureChange: {\n\t\t\tconst tenureConsensusHash = bytesToHex(r.readBytes(20));\n\t\t\tconst prevTenureConsensusHash = bytesToHex(r.readBytes(20));\n\t\t\tconst burnViewConsensusHash = bytesToHex(r.readBytes(20));\n\t\t\tconst previousTenureEnd = bytesToHex(r.readBytes(32));\n\t\t\tconst previousTenureBlocks = r.readUInt32BE();\n\t\t\tconst cause = r.readUInt8() as TenureChangeCause;\n\t\t\tconst pubkeyHash = bytesToHex(r.readBytes(20));\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.TenureChange,\n\t\t\t\ttenureConsensusHash,\n\t\t\t\tprevTenureConsensusHash,\n\t\t\t\tburnViewConsensusHash,\n\t\t\t\tpreviousTenureEnd,\n\t\t\t\tpreviousTenureBlocks,\n\t\t\t\tcause,\n\t\t\t\tpubkeyHash,\n\t\t\t};\n\t\t}\n\t\tcase PayloadType.NakamotoCoinbase: {\n\t\t\tconst coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n\t\t\tconst optionalCV = readCV(r);\n\t\t\tconst recipient =\n\t\t\t\toptionalCV.type === \"none\"\n\t\t\t\t\t? null\n\t\t\t\t\t: optionalCV.type === \"some\"\n\t\t\t\t\t\t? optionalCV.value\n\t\t\t\t\t\t: optionalCV;\n\t\t\tconst vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));\n\t\t\treturn {\n\t\t\t\tpayloadType: PayloadType.NakamotoCoinbase,\n\t\t\t\tcoinbaseBuffer,\n\t\t\t\trecipient,\n\t\t\t\tvrfProof,\n\t\t\t};\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown payload type: ${payloadType}`);\n\t}\n}\n\nexport function deserializePostConditionWire(\n\tinput: string | Uint8Array,\n): PostConditionWire {\n\tconst bytes =\n\t\ttypeof input === \"string\" ? hexToBytes(without0x(input)) : input;\n\treturn readPostCondition(new BytesReader(bytes));\n}\n\nexport function deserializeTransaction(\n\tinput: string | Uint8Array,\n\tmeta?: { _multisig?: { publicKeys: string[] } },\n): StacksTransaction {\n\tconst bytes =\n\t\ttypeof input === \"string\" ? hexToBytes(without0x(input)) : input;\n\tconst r = new BytesReader(bytes);\n\n\tconst tx: StacksTransaction = {\n\t\tversion: r.readUInt8(),\n\t\tchainId: r.readUInt32BE(),\n\t\tauth: readAuthorization(r),\n\t\tanchorMode: r.readUInt8() as AnchorMode,\n\t\tpostConditionMode: r.readUInt8() as PostConditionModeWire,\n\t\tpostConditions: readPostConditions(r),\n\t\tpayload: readPayload(r),\n\t};\n\tif (meta?._multisig) {\n\t\ttx._multisig = meta._multisig;\n\t}\n\treturn tx;\n}\n",
|
|
8
|
-
"import {\n\tFungibleConditionCode,\n\tNonFungibleConditionCode,\n\ttype PostConditionPrincipalWire,\n\ttype PostConditionWire,\n\tPoxConditionCode,\n} from \"../transactions/types.ts\";\nimport { deserializePostConditionWire } from \"../transactions/wire/deserialize.ts\";\nimport { serializePostConditionWire } from \"../transactions/wire/serialize.ts\";\nimport { parseContractId } from \"../utils/address.ts\";\nimport {\n\ttype IntegerType,\n\tbytesToHex,\n\tintToBigInt,\n} from \"../utils/encoding.ts\";\nimport type {\n\tFungibleComparator,\n\tNonFungibleComparator,\n\tPostCondition,\n\tPoxComparator,\n} from \"./types.ts\";\n\nconst MAX_U64 = 18446744073709551615n; // 2^64 - 1\n\n/** Parse a PC amount; throw if outside the u64 the wire can carry. */\nexport function parsePostConditionAmount(amount: IntegerType): bigint {\n\tconst value = intToBigInt(amount);\n\tif (value < 0n || value > MAX_U64) {\n\t\tthrow new RangeError(\n\t\t\t`Post-condition amount must be between 0 and ${MAX_U64} (u64 max), received: ${value}`,\n\t\t);\n\t}\n\treturn value;\n}\n\nexport const FUNGIBLE_CODE_MAP: Record<FungibleComparator, number> = {\n\teq: FungibleConditionCode.Equal,\n\tgt: FungibleConditionCode.Greater,\n\tgte: FungibleConditionCode.GreaterEqual,\n\tlt: FungibleConditionCode.Less,\n\tlte: FungibleConditionCode.LessEqual,\n};\n\nconst FUNGIBLE_CODE_REVERSE: Record<number, FungibleComparator> = {\n\t[FungibleConditionCode.Equal]: \"eq\",\n\t[FungibleConditionCode.Greater]: \"gt\",\n\t[FungibleConditionCode.GreaterEqual]: \"gte\",\n\t[FungibleConditionCode.Less]: \"lt\",\n\t[FungibleConditionCode.LessEqual]: \"lte\",\n};\n\nexport const NFT_CODE_MAP: Record<NonFungibleComparator, number> = {\n\tsent: NonFungibleConditionCode.Sends,\n\t\"not-sent\": NonFungibleConditionCode.DoesNotSend,\n\t\"maybe-sent\": NonFungibleConditionCode.MaybeSent,\n};\n\nconst NFT_CODE_REVERSE: Record<number, NonFungibleComparator> = {\n\t[NonFungibleConditionCode.Sends]: \"sent\",\n\t[NonFungibleConditionCode.DoesNotSend]: \"not-sent\",\n\t[NonFungibleConditionCode.MaybeSent]: \"maybe-sent\",\n};\n\nexport const POX_CODE_MAP: Record<PoxComparator, PoxConditionCode> = {\n\t\"will-not-perform\": PoxConditionCode.WillNotPerform,\n\t\"may-perform\": PoxConditionCode.MayPerform,\n\t\"will-perform\": PoxConditionCode.WillPerform,\n};\n\nconst POX_CODE_REVERSE: Record<number, PoxComparator> = {\n\t[PoxConditionCode.WillNotPerform]: \"will-not-perform\",\n\t[PoxConditionCode.MayPerform]: \"may-perform\",\n\t[PoxConditionCode.WillPerform]: \"will-perform\",\n};\n\nexport function resolvePrincipal(address: string): PostConditionPrincipalWire {\n\tif (address === \"origin\") return { type: \"origin\" };\n\tconst [addr, name] = address.split(\".\");\n\tif (name) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: split yields address when name is present\n\t\treturn { type: \"contract\", address: addr!, contractName: name };\n\t}\n\t// biome-ignore lint/style/noNonNullAssertion: address is the whole string\n\treturn { type: \"standard\", address: addr! };\n}\n\nfunction principalToString(principal: PostConditionPrincipalWire): string {\n\tif (principal.type === \"origin\") return \"origin\";\n\tif (principal.type === \"contract\") {\n\t\treturn `${principal.address}.${principal.contractName}`;\n\t}\n\treturn principal.address;\n}\n\nfunction assetToString(asset: {\n\taddress: string;\n\tcontractName: string;\n\tassetName: string;\n}): string {\n\treturn `${asset.address}.${asset.contractName}::${asset.assetName}`;\n}\n\nfunction parseAsset(asset: string): {\n\taddress: string;\n\tcontractName: string;\n\tassetName: string;\n} {\n\tconst [contractId, tokenName] = asset.split(\"::\");\n\t// biome-ignore lint/style/noNonNullAssertion: callers validate `::` form\n\tconst [addr, name] = parseContractId(contractId!);\n\t// biome-ignore lint/style/noNonNullAssertion: split of `addr.contract::token`\n\treturn { address: addr, contractName: name, assetName: tokenName! };\n}\n\nexport function 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: parsePostConditionAmount(pc.amount),\n\t\t\t};\n\t\tcase \"ft-postcondition\":\n\t\t\treturn {\n\t\t\t\ttype: \"ft\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tasset: parseAsset(pc.asset),\n\t\t\t\tconditionCode: FUNGIBLE_CODE_MAP[pc.condition],\n\t\t\t\tamount: parsePostConditionAmount(pc.amount),\n\t\t\t};\n\t\tcase \"nft-postcondition\":\n\t\t\treturn {\n\t\t\t\ttype: \"nft\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tasset: parseAsset(pc.asset),\n\t\t\t\tconditionCode: NFT_CODE_MAP[pc.condition],\n\t\t\t\tassetId: pc.assetId,\n\t\t\t};\n\t\tcase \"staking-postcondition\":\n\t\t\treturn {\n\t\t\t\ttype: \"staking\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tconditionCode: FUNGIBLE_CODE_MAP[pc.condition],\n\t\t\t\tamount: parsePostConditionAmount(pc.amount),\n\t\t\t};\n\t\tcase \"pox-postcondition\":\n\t\t\treturn {\n\t\t\t\ttype: \"pox\",\n\t\t\t\tprincipal: resolvePrincipal(pc.address),\n\t\t\t\tconditionCode: POX_CODE_MAP[pc.condition],\n\t\t\t};\n\t}\n}\n\nexport function wireToPostCondition(wire: PostConditionWire): PostCondition {\n\tswitch (wire.type) {\n\t\tcase \"stx\":\n\t\t\treturn {\n\t\t\t\ttype: \"stx-postcondition\",\n\t\t\t\taddress: principalToString(wire.principal),\n\t\t\t\tcondition: fungibleName(wire.conditionCode),\n\t\t\t\tamount: wire.amount.toString(),\n\t\t\t};\n\t\tcase \"ft\":\n\t\t\treturn {\n\t\t\t\ttype: \"ft-postcondition\",\n\t\t\t\taddress: principalToString(wire.principal),\n\t\t\t\tcondition: fungibleName(wire.conditionCode),\n\t\t\t\tamount: wire.amount.toString(),\n\t\t\t\tasset: assetToString(wire.asset),\n\t\t\t};\n\t\tcase \"nft\":\n\t\t\treturn {\n\t\t\t\ttype: \"nft-postcondition\",\n\t\t\t\taddress: principalToString(wire.principal),\n\t\t\t\tcondition: nftName(wire.conditionCode),\n\t\t\t\tasset: assetToString(wire.asset),\n\t\t\t\tassetId: wire.assetId,\n\t\t\t};\n\t\tcase \"staking\":\n\t\t\treturn {\n\t\t\t\ttype: \"staking-postcondition\",\n\t\t\t\taddress: principalToString(wire.principal),\n\t\t\t\tcondition: fungibleName(wire.conditionCode),\n\t\t\t\tamount: wire.amount.toString(),\n\t\t\t};\n\t\tcase \"pox\":\n\t\t\treturn {\n\t\t\t\ttype: \"pox-postcondition\",\n\t\t\t\taddress: principalToString(wire.principal),\n\t\t\t\tcondition: poxName(wire.conditionCode),\n\t\t\t};\n\t}\n}\n\nfunction fungibleName(code: number): FungibleComparator {\n\tconst name = FUNGIBLE_CODE_REVERSE[code];\n\tif (!name) throw new Error(`Unknown fungible post-condition code: ${code}`);\n\treturn name;\n}\n\nfunction nftName(code: number): NonFungibleComparator {\n\tconst name = NFT_CODE_REVERSE[code];\n\tif (!name) throw new Error(`Unknown nft post-condition code: ${code}`);\n\treturn name;\n}\n\nfunction poxName(code: number): PoxComparator {\n\tconst name = POX_CODE_REVERSE[code];\n\tif (!name) throw new Error(`Unknown pox post-condition code: ${code}`);\n\treturn name;\n}\n\n/** Decode a serialized post-condition (stacks.js `Pc.fromHex`). */\nexport function fromHex(hex: string): PostCondition {\n\treturn wireToPostCondition(deserializePostConditionWire(hex));\n}\n\n/** Encode a post-condition to hex (stacks.js `postConditionToHex`). */\nexport function postConditionToHex(pc: PostCondition): string {\n\treturn bytesToHex(serializePostConditionWire(convertPostCondition(pc)));\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"mappings": ";AAGO,IAAM,WAAW;AAAA,EACvB,UAAU;AAAA,EACV,WAAW;AACZ;AAIO,IAAM,cAAc;AAAA,EAC1B,eAAe;AAAA,EACf,eAAe;AAAA,EACf,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,UAAU;AAAA,EACV,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,cAAc;AAAA,EACd,kBAAkB;AACnB;AAIO,IAAM,iBAAiB;AAAA,EAC7B,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AAAA,EACV,UAAU;AACX;AAKO,IAAM,aAAa;AAAA,EACzB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,KAAK;AACN;AAIO,IAAM,wBAAwB;AAAA,EACpC,OAAO;AAAA,EACP,M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M,oCAAoC,MAAM;AAAA,EACrE,OAAO;AAAA;AAGR,SAAS,OAAO,CAAC,MAA6B;AAAA,EAC7C,MAAM,OAAO,iBAAiB;AAAA,EAC9B,IAAI,CAAC;AAAA,IAAM,MAAM,IAAI,MAAM,oCAAoC,MAAM;AAAA,EACrE,OAAO;AAAA;AAID,SAAS,OAAO,CAAC,KAA4B;AAAA,EACnD,OAAO,oBAAoB,6BAA6B,GAAG,CAAC;AAAA;AAItD,SAAS,kBAAkB,CAAC,IAA2B;AAAA,EAC7D,OAAO,WAAW,2BAA2B,qBAAqB,EAAE,CAAC,CAAC;AAAA;",
|
|
11
|
-
"debugId": "39ACDEFB0CF1F8AA64756E2164756E21",
|
|
12
|
-
"names": []
|
|
13
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// src/errors/response.ts
|
|
2
|
-
class MalformedResponseError extends BaseError {
|
|
3
|
-
name = "MalformedResponseError";
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
class ReadContractError extends BaseError {
|
|
7
|
-
name = "ReadContractError";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// src/actions/public/readContract.ts
|
|
11
|
-
async function readContract(client, params) {
|
|
12
|
-
const [address, name] = parseContractId(params.contract);
|
|
13
|
-
const sender = params.sender ?? address;
|
|
14
|
-
const serializedArgs = (params.args ?? []).map((arg) => with0x(bytesToHex(serializeCVBytes(arg))));
|
|
15
|
-
const path = `/v2/contracts/call-read/${encodeURIComponent(address)}/${encodeURIComponent(name)}/${encodeURIComponent(params.functionName)}`;
|
|
16
|
-
const data = await client.request(params.tip ? `${path}?tip=${encodeURIComponent(params.tip)}` : path, {
|
|
17
|
-
method: "POST",
|
|
18
|
-
body: {
|
|
19
|
-
sender,
|
|
20
|
-
arguments: serializedArgs
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
if (data.okay) {
|
|
24
|
-
if (typeof data.result !== "string") {
|
|
25
|
-
throw new MalformedResponseError(`readContract: /v2/contracts/call-read response is missing "result"`);
|
|
26
|
-
}
|
|
27
|
-
return deserializeCVBytes(data.result);
|
|
28
|
-
}
|
|
29
|
-
throw new ReadContractError(data.cause ?? "Read-only call failed");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//# debugId=96EB689995163C0E64756E2164756E21
|
|
33
|
-
//# sourceMappingURL=stacks-wk8yp13j.cjs.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/errors/response.ts", "../src/actions/public/readContract.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n\n/** Thrown when `/v2/contracts/call-read` answers `okay: false`. */\nexport class ReadContractError extends BaseError {\n\toverride name = \"ReadContractError\";\n}\n",
|
|
6
|
-
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport {\n\tMalformedResponseError,\n\tReadContractError,\n} from \"../../errors/response.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type ReadContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\targs?: ClarityValue[];\n\tsender?: string;\n\t/**\n\t * Nakamoto StacksBlockId to evaluate against. Without it the node answers\n\t * at its own moving tip, which makes a read non-deterministic — the same\n\t * reindex of the same block can return a different value.\n\t */\n\ttip?: string;\n};\n\nexport async function readContract<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: ReadContractParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst sender = params.sender ?? address;\n\n\tconst serializedArgs = (params.args ?? []).map((arg) =>\n\t\twith0x(bytesToHex(serializeCVBytes(arg))),\n\t);\n\n\tconst path = `/v2/contracts/call-read/${encodeURIComponent(address)}/${encodeURIComponent(name)}/${encodeURIComponent(params.functionName)}`;\n\tconst data = await client.request(\n\t\tparams.tip ? `${path}?tip=${encodeURIComponent(params.tip)}` : path,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: {\n\t\t\t\tsender,\n\t\t\t\targuments: serializedArgs,\n\t\t\t},\n\t\t},\n\t);\n\n\tif (data.okay) {\n\t\tif (typeof data.result !== \"string\") {\n\t\t\tthrow new MalformedResponseError(\n\t\t\t\t`readContract: /v2/contracts/call-read response is missing \"result\"`,\n\t\t\t);\n\t\t}\n\t\treturn deserializeCVBytes<T>(data.result);\n\t}\n\tthrow new ReadContractError(data.cause ?? \"Read-only call failed\");\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";AAGO,MAAM,+BAA+B,UAAU;AAAA,EAC5C,OAAO;AACjB;AAAA;AAGO,MAAM,0BAA0B,UAAU;AAAA,EACvC,OAAO;AACjB;;;ACcA,eAAsB,YAAmD,CACxE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,SAAS,OAAO,UAAU;AAAA,EAEhC,MAAM,kBAAkB,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,QAC/C,OAAO,WAAW,iBAAiB,GAAG,CAAC,CAAC,CACzC;AAAA,EAEA,MAAM,OAAO,2BAA2B,mBAAmB,OAAO,KAAK,mBAAmB,IAAI,KAAK,mBAAmB,OAAO,YAAY;AAAA,EACzI,MAAM,OAAO,MAAM,OAAO,QACzB,OAAO,MAAM,GAAG,YAAY,mBAAmB,OAAO,GAAG,MAAM,MAC/D;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,MACL;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,EACD,CACD;AAAA,EAEA,IAAI,KAAK,MAAM;AAAA,IACd,IAAI,OAAO,KAAK,WAAW,UAAU;AAAA,MACpC,MAAM,IAAI,uBACT,oEACD;AAAA,IACD;AAAA,IACA,OAAO,mBAAsB,KAAK,MAAM;AAAA,EACzC;AAAA,EACA,MAAM,IAAI,kBAAkB,KAAK,SAAS,uBAAuB;AAAA;",
|
|
9
|
-
"debugId": "96EB689995163C0E64756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// src/errors/base.ts
|
|
2
|
-
function codeFromName(name) {
|
|
3
|
-
return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toUpperCase();
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
class BaseError extends Error {
|
|
7
|
-
name = "StacksError";
|
|
8
|
-
#code;
|
|
9
|
-
shortMessage;
|
|
10
|
-
details;
|
|
11
|
-
constructor(shortMessage, options) {
|
|
12
|
-
const message = [
|
|
13
|
-
shortMessage,
|
|
14
|
-
options?.details ? `
|
|
15
|
-
${options.details}` : ""
|
|
16
|
-
].join("");
|
|
17
|
-
super(message, { cause: options?.cause });
|
|
18
|
-
if (options?.code !== undefined)
|
|
19
|
-
this.#code = options.code;
|
|
20
|
-
this.shortMessage = shortMessage;
|
|
21
|
-
this.details = options?.details;
|
|
22
|
-
}
|
|
23
|
-
get code() {
|
|
24
|
-
return this.#code ?? codeFromName(this.name);
|
|
25
|
-
}
|
|
26
|
-
set code(value) {
|
|
27
|
-
this.#code = value;
|
|
28
|
-
}
|
|
29
|
-
toJSON() {
|
|
30
|
-
return {
|
|
31
|
-
name: this.name,
|
|
32
|
-
code: this.code,
|
|
33
|
-
message: this.message,
|
|
34
|
-
shortMessage: this.shortMessage,
|
|
35
|
-
details: this.details,
|
|
36
|
-
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//# debugId=74E75E1C13F951A764756E2164756E21
|
|
42
|
-
//# sourceMappingURL=stacks-xjkn3en1.cjs.map
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// src/pox/constants.ts
|
|
2
|
-
var POX_CONTRACTS = {
|
|
3
|
-
mainnet: {
|
|
4
|
-
address: "SP000000000000000000002Q6VF78",
|
|
5
|
-
name: "pox-4"
|
|
6
|
-
},
|
|
7
|
-
testnet: {
|
|
8
|
-
address: "ST000000000000000000002AMW42H",
|
|
9
|
-
name: "pox-4"
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
var MIN_LOCK_PERIOD = 1;
|
|
13
|
-
var MAX_LOCK_PERIOD = 12;
|
|
14
|
-
var POX_ADDRESS_VERSION = {
|
|
15
|
-
p2pkh: 0,
|
|
16
|
-
p2sh: 1,
|
|
17
|
-
p2sh_p2wpkh: 2,
|
|
18
|
-
p2sh_p2wsh: 3,
|
|
19
|
-
p2wpkh: 4,
|
|
20
|
-
p2wsh: 5,
|
|
21
|
-
p2tr: 6
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// src/pox5/btcAddress.ts
|
|
25
|
-
var import_base = require("@scure/base");
|
|
26
|
-
function expectedHashLen(version) {
|
|
27
|
-
if (!Number.isInteger(version) || version < 0 || version > 6) {
|
|
28
|
-
throw new Error(`Unknown PoX address version: 0x${version.toString(16)}`);
|
|
29
|
-
}
|
|
30
|
-
return version <= 4 ? 20 : 32;
|
|
31
|
-
}
|
|
32
|
-
function canonicalizeBtcAddress(repr) {
|
|
33
|
-
const expected = expectedHashLen(repr.version);
|
|
34
|
-
const { hashbytes } = repr;
|
|
35
|
-
if (hashbytes.length === expected)
|
|
36
|
-
return { version: repr.version, hashbytes };
|
|
37
|
-
if (expected === 20 && hashbytes.length === 32 && hashbytes.slice(20).every((b) => b === 0)) {
|
|
38
|
-
return { version: repr.version, hashbytes: hashbytes.slice(0, 20) };
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Invalid hashbytes length for PoX version 0x${repr.version.toString(16)}: ${hashbytes.length}`);
|
|
41
|
-
}
|
|
42
|
-
function parseBtcAddress(address) {
|
|
43
|
-
if (address.startsWith("bc1") || address.startsWith("tb1") || address.startsWith("bcrt1")) {
|
|
44
|
-
return parseSegwitAddress(address);
|
|
45
|
-
}
|
|
46
|
-
return parseLegacyAddress(address);
|
|
47
|
-
}
|
|
48
|
-
function parseSegwitAddress(address) {
|
|
49
|
-
let decoded;
|
|
50
|
-
try {
|
|
51
|
-
decoded = import_base.bech32.decode(address);
|
|
52
|
-
} catch {
|
|
53
|
-
decoded = import_base.bech32m.decode(address);
|
|
54
|
-
}
|
|
55
|
-
const witnessVersion = decoded.words[0];
|
|
56
|
-
if (witnessVersion === undefined) {
|
|
57
|
-
throw new Error("Invalid segwit address: missing witness version");
|
|
58
|
-
}
|
|
59
|
-
const data = import_base.bech32.fromWords(decoded.words.slice(1));
|
|
60
|
-
const hashbytes = new Uint8Array(data);
|
|
61
|
-
let version;
|
|
62
|
-
if (witnessVersion === 0) {
|
|
63
|
-
if (hashbytes.length === 20) {
|
|
64
|
-
version = POX_ADDRESS_VERSION.p2wpkh;
|
|
65
|
-
} else if (hashbytes.length === 32) {
|
|
66
|
-
version = POX_ADDRESS_VERSION.p2wsh;
|
|
67
|
-
} else {
|
|
68
|
-
throw new Error(`Invalid witness v0 program length: ${hashbytes.length}`);
|
|
69
|
-
}
|
|
70
|
-
} else if (witnessVersion === 1) {
|
|
71
|
-
if (hashbytes.length !== 32) {
|
|
72
|
-
throw new Error(`Invalid witness v1 program length: ${hashbytes.length}`);
|
|
73
|
-
}
|
|
74
|
-
version = POX_ADDRESS_VERSION.p2tr;
|
|
75
|
-
} else {
|
|
76
|
-
throw new Error(`Unsupported witness version: ${witnessVersion}`);
|
|
77
|
-
}
|
|
78
|
-
return { version, hashbytes };
|
|
79
|
-
}
|
|
80
|
-
function parseLegacyAddress(address) {
|
|
81
|
-
const decoded = import_base.base58.decode(address);
|
|
82
|
-
if (decoded.length !== 25) {
|
|
83
|
-
throw new Error(`Invalid legacy address length: ${decoded.length}`);
|
|
84
|
-
}
|
|
85
|
-
const versionByte = decoded[0];
|
|
86
|
-
if (versionByte === undefined) {
|
|
87
|
-
throw new Error("Invalid legacy address: missing version byte");
|
|
88
|
-
}
|
|
89
|
-
const payload = decoded.slice(0, 21);
|
|
90
|
-
const checksum = decoded.slice(21);
|
|
91
|
-
const expected = doubleSha256(payload).slice(0, 4);
|
|
92
|
-
if (checksum.length !== 4 || expected.some((b, i) => b !== checksum[i])) {
|
|
93
|
-
throw new Error("Invalid legacy address checksum");
|
|
94
|
-
}
|
|
95
|
-
const hashbytes = decoded.slice(1, 21);
|
|
96
|
-
let version;
|
|
97
|
-
if (versionByte === 0 || versionByte === 111) {
|
|
98
|
-
version = POX_ADDRESS_VERSION.p2pkh;
|
|
99
|
-
} else if (versionByte === 5 || versionByte === 196) {
|
|
100
|
-
version = POX_ADDRESS_VERSION.p2sh;
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error(`Unknown legacy address version byte: 0x${versionByte.toString(16)}`);
|
|
103
|
-
}
|
|
104
|
-
return { version, hashbytes };
|
|
105
|
-
}
|
|
106
|
-
function stringifyBtcAddress(repr, network) {
|
|
107
|
-
const { version, hashbytes } = canonicalizeBtcAddress(repr);
|
|
108
|
-
const params = BITCOIN_NETWORK_PARAMS[network];
|
|
109
|
-
switch (version) {
|
|
110
|
-
case POX_ADDRESS_VERSION.p2pkh:
|
|
111
|
-
return base58CheckEncode(params.p2pkh, hashbytes);
|
|
112
|
-
case POX_ADDRESS_VERSION.p2sh:
|
|
113
|
-
case POX_ADDRESS_VERSION.p2sh_p2wpkh:
|
|
114
|
-
case POX_ADDRESS_VERSION.p2sh_p2wsh:
|
|
115
|
-
return base58CheckEncode(params.p2sh, hashbytes);
|
|
116
|
-
case POX_ADDRESS_VERSION.p2wpkh:
|
|
117
|
-
case POX_ADDRESS_VERSION.p2wsh:
|
|
118
|
-
return import_base.bech32.encode(params.hrp, [0, ...import_base.bech32.toWords(hashbytes)]);
|
|
119
|
-
case POX_ADDRESS_VERSION.p2tr:
|
|
120
|
-
return import_base.bech32m.encode(params.hrp, [1, ...import_base.bech32m.toWords(hashbytes)]);
|
|
121
|
-
default:
|
|
122
|
-
throw new Error(`Unknown PoX address version: 0x${version.toString(16)}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
var BtcAddress = {
|
|
126
|
-
parse: parseBtcAddress,
|
|
127
|
-
stringify: stringifyBtcAddress
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
//# debugId=F00DD70BC680A86264756E2164756E21
|
|
131
|
-
//# sourceMappingURL=stacks-xnrywjf1.cjs.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/pox/constants.ts", "../src/pox5/btcAddress.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"export const POX_CONTRACTS = {\n\tmainnet: {\n\t\taddress: \"SP000000000000000000002Q6VF78\",\n\t\tname: \"pox-4\",\n\t},\n\ttestnet: {\n\t\taddress: \"ST000000000000000000002AMW42H\",\n\t\tname: \"pox-4\",\n\t},\n} as const;\n\nexport const MIN_LOCK_PERIOD = 1;\nexport const MAX_LOCK_PERIOD = 12;\n\n/** PoX address version bytes (maps to Bitcoin address types) */\nexport const POX_ADDRESS_VERSION = {\n\t/** P2PKH - legacy addresses starting with \"1\" */\n\tp2pkh: 0x00,\n\t/** P2SH - script hash addresses starting with \"3\" */\n\tp2sh: 0x01,\n\t/** P2SH-P2WPKH - nested segwit */\n\tp2sh_p2wpkh: 0x02,\n\t/** P2SH-P2WSH - nested segwit script */\n\tp2sh_p2wsh: 0x03,\n\t/** P2WPKH - native segwit \"bc1q\" (20-byte hash) */\n\tp2wpkh: 0x04,\n\t/** P2WSH - native segwit \"bc1q\" (32-byte hash) */\n\tp2wsh: 0x05,\n\t/** P2TR - taproot \"bc1p\" (32-byte key) */\n\tp2tr: 0x06,\n} as const;\n",
|
|
6
|
-
"import { base58, bech32, bech32m } from \"@scure/base\";\nimport {\n\tBITCOIN_NETWORK_PARAMS,\n\tbase58CheckEncode,\n} from \"../bitcoin/address.ts\";\nimport type { BitcoinNetwork } from \"../bitcoin/constants.ts\";\nimport { doubleSha256 } from \"../bitcoin/serialize.ts\";\nimport { POX_ADDRESS_VERSION } from \"../pox/constants.ts\";\n\n/**\n * SIP-005 PoX `pox-addr` tuple, decoded from a Bitcoin address. `version` is\n * the PoX byte (`POX_ADDRESS_VERSION`), not a Bitcoin network version\n * (`p2sh` is 0x01 here, 0x05 on mainnet Bitcoin). `hashbytes` is the 20- or\n * 32-byte payload — unpadded, matching `check-pox-addr-hashbytes`.\n */\nexport type BtcAddressRepr = {\n\tversion: number;\n\thashbytes: Uint8Array;\n};\n\nfunction expectedHashLen(version: number): number {\n\tif (!Number.isInteger(version) || version < 0x00 || version > 0x06) {\n\t\tthrow new Error(`Unknown PoX address version: 0x${version.toString(16)}`);\n\t}\n\treturn version <= 0x04 ? 20 : 32;\n}\n\n/** Strip frozen-pox 32-byte padding; reject a length that doesn't match the version. */\nexport function canonicalizeBtcAddress(repr: BtcAddressRepr): BtcAddressRepr {\n\tconst expected = expectedHashLen(repr.version);\n\tconst { hashbytes } = repr;\n\tif (hashbytes.length === expected)\n\t\treturn { version: repr.version, hashbytes };\n\tif (\n\t\texpected === 20 &&\n\t\thashbytes.length === 32 &&\n\t\thashbytes.slice(20).every((b) => b === 0)\n\t) {\n\t\treturn { version: repr.version, hashbytes: hashbytes.slice(0, 20) };\n\t}\n\tthrow new Error(\n\t\t`Invalid hashbytes length for PoX version 0x${repr.version.toString(16)}: ${hashbytes.length}`,\n\t);\n}\n\n/**\n * Parse a Bitcoin address string into a PoX address tuple.\n * Supports P2PKH, P2SH, P2WPKH, P2WSH, P2TR (mainnet, testnet, regtest).\n */\nexport function parseBtcAddress(address: string): BtcAddressRepr {\n\tif (\n\t\taddress.startsWith(\"bc1\") ||\n\t\taddress.startsWith(\"tb1\") ||\n\t\taddress.startsWith(\"bcrt1\")\n\t) {\n\t\treturn parseSegwitAddress(address);\n\t}\n\treturn parseLegacyAddress(address);\n}\n\nfunction parseSegwitAddress(address: string): BtcAddressRepr {\n\tlet decoded: { prefix: string; words: number[] };\n\ttry {\n\t\tdecoded = bech32.decode(address as `${string}1${string}`);\n\t} catch {\n\t\tdecoded = bech32m.decode(address as `${string}1${string}`);\n\t}\n\n\tconst witnessVersion = decoded.words[0];\n\tif (witnessVersion === undefined) {\n\t\tthrow new Error(\"Invalid segwit address: missing witness version\");\n\t}\n\tconst data = bech32.fromWords(decoded.words.slice(1));\n\tconst hashbytes = new Uint8Array(data);\n\n\tlet version: number;\n\tif (witnessVersion === 0) {\n\t\tif (hashbytes.length === 20) {\n\t\t\tversion = POX_ADDRESS_VERSION.p2wpkh;\n\t\t} else if (hashbytes.length === 32) {\n\t\t\tversion = POX_ADDRESS_VERSION.p2wsh;\n\t\t} else {\n\t\t\tthrow new Error(`Invalid witness v0 program length: ${hashbytes.length}`);\n\t\t}\n\t} else if (witnessVersion === 1) {\n\t\tif (hashbytes.length !== 32) {\n\t\t\tthrow new Error(`Invalid witness v1 program length: ${hashbytes.length}`);\n\t\t}\n\t\tversion = POX_ADDRESS_VERSION.p2tr;\n\t} else {\n\t\tthrow new Error(`Unsupported witness version: ${witnessVersion}`);\n\t}\n\n\treturn { version, hashbytes };\n}\n\nfunction parseLegacyAddress(address: string): BtcAddressRepr {\n\tconst decoded = base58.decode(address);\n\n\tif (decoded.length !== 25) {\n\t\tthrow new Error(`Invalid legacy address length: ${decoded.length}`);\n\t}\n\n\tconst versionByte = decoded[0];\n\tif (versionByte === undefined) {\n\t\tthrow new Error(\"Invalid legacy address: missing version byte\");\n\t}\n\tconst payload = decoded.slice(0, 21);\n\tconst checksum = decoded.slice(21);\n\tconst expected = doubleSha256(payload).slice(0, 4);\n\tif (checksum.length !== 4 || expected.some((b, i) => b !== checksum[i])) {\n\t\tthrow new Error(\"Invalid legacy address checksum\");\n\t}\n\tconst hashbytes = decoded.slice(1, 21);\n\n\tlet version: number;\n\tif (versionByte === 0x00 || versionByte === 0x6f) {\n\t\tversion = POX_ADDRESS_VERSION.p2pkh;\n\t} else if (versionByte === 0x05 || versionByte === 0xc4) {\n\t\tversion = POX_ADDRESS_VERSION.p2sh;\n\t} else {\n\t\tthrow new Error(\n\t\t\t`Unknown legacy address version byte: 0x${versionByte.toString(16)}`,\n\t\t);\n\t}\n\n\treturn { version, hashbytes };\n}\n\nexport function stringifyBtcAddress(\n\trepr: BtcAddressRepr,\n\tnetwork: BitcoinNetwork,\n): string {\n\tconst { version, hashbytes } = canonicalizeBtcAddress(repr);\n\tconst params = BITCOIN_NETWORK_PARAMS[network];\n\tswitch (version) {\n\t\tcase POX_ADDRESS_VERSION.p2pkh:\n\t\t\treturn base58CheckEncode(params.p2pkh, hashbytes);\n\t\tcase POX_ADDRESS_VERSION.p2sh:\n\t\tcase POX_ADDRESS_VERSION.p2sh_p2wpkh:\n\t\tcase POX_ADDRESS_VERSION.p2sh_p2wsh:\n\t\t\treturn base58CheckEncode(params.p2sh, hashbytes);\n\t\tcase POX_ADDRESS_VERSION.p2wpkh:\n\t\tcase POX_ADDRESS_VERSION.p2wsh:\n\t\t\treturn bech32.encode(params.hrp, [0, ...bech32.toWords(hashbytes)]);\n\t\tcase POX_ADDRESS_VERSION.p2tr:\n\t\t\treturn bech32m.encode(params.hrp, [1, ...bech32m.toWords(hashbytes)]);\n\t\tdefault:\n\t\t\tthrow new Error(`Unknown PoX address version: 0x${version.toString(16)}`);\n\t}\n}\n\nexport const BtcAddress: {\n\tparse: typeof parseBtcAddress;\n\tstringify: typeof stringifyBtcAddress;\n} = {\n\tparse: parseBtcAddress,\n\tstringify: stringifyBtcAddress,\n};\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";AAAO,IAAM,gBAAgB;AAAA,EAC5B,SAAS;AAAA,IACR,SAAS;AAAA,IACT,MAAM;AAAA,EACP;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A;AAAA;AAIpE,IAAM,aAGT;AAAA,EACH,OAAO;AAAA,EACP,WAAW;AACZ;",
|
|
9
|
-
"debugId": "F00DD70BC680A86264756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/units.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"/**\n * Format a bigint value with decimal places.\n * @example formatUnits(1000000n, 6) → \"1.0\"\n * @example formatUnits(1500000n, 6) → \"1.5\"\n */\nexport function formatUnits(\n\tvalue: bigint | number | string,\n\tdecimals: number,\n): string {\n\tlet v = BigInt(value);\n\n\tconst negative = v < 0n;\n\tif (negative) v = -v;\n\n\tconst divisor = 10n ** BigInt(decimals);\n\tconst integer = (v / divisor).toString();\n\tlet fraction = (v % divisor).toString().padStart(decimals, \"0\");\n\n\t// Trim trailing zeros, but keep at least one decimal\n\tfraction = fraction.replace(/0+$/, \"\") || \"0\";\n\n\tconst result = `${integer}.${fraction}`;\n\treturn negative ? `-${result}` : result;\n}\n\n/**\n * Parse a decimal string into a bigint with the given number of decimals.\n * @example parseUnits(\"1.5\", 6) → 1500000n\n * @example parseUnits(\"1\", 6) → 1000000n\n */\nconst DECIMAL_STRING = /^-?\\d+(\\.\\d+)?$/;\n\nexport function parseUnits(value: string | number, decimals: number): bigint {\n\tif (typeof value === \"number\" && !Number.isFinite(value)) {\n\t\tthrow new RangeError(`Cannot parse ${value} as a decimal amount`);\n\t}\n\t// Numbers small or large enough to print in exponent form (1e-7, 1e21)\n\t// go through toFixed so the digits survive. A number the fixed form\n\t// cannot hold exactly (too many decimals, or too small for one unit) is\n\t// refused rather than rounded, so amounts never shrink silently.\n\tlet str = typeof value === \"number\" ? value.toFixed(decimals) : value.trim();\n\tif (!DECIMAL_STRING.test(str)) {\n\t\tthrow new RangeError(\n\t\t\t`Cannot parse \"${value}\" as a decimal amount: expected digits with an optional fraction, like \"1.5\"`,\n\t\t);\n\t}\n\tif (typeof value === \"number\" && Number(str) !== value) {\n\t\tthrow new RangeError(\n\t\t\t`Cannot parse ${value} with ${decimals} decimals: pass the amount as a string to keep every digit`,\n\t\t);\n\t}\n\n\tconst negative = str.startsWith(\"-\");\n\tif (negative) str = str.slice(1);\n\n\tconst [integer = \"\", fraction = \"\"] = str.split(\".\");\n\n\tif (fraction.length > decimals) {\n\t\tthrow new Error(\n\t\t\t`Too many decimal places: \"${value}\" has ${fraction.length} decimals, max is ${decimals}`,\n\t\t);\n\t}\n\n\tconst padded = fraction.padEnd(decimals, \"0\");\n\tconst result = BigInt(integer + padded);\n\treturn negative ? -result : result;\n}\n\n/**\n * Format microSTX to STX string (6 decimals).\n * @example formatStx(1000000n) → \"1.0\"\n */\nexport function formatStx(microStx: bigint | number | string): string {\n\treturn formatUnits(microStx, 6);\n}\n\n/**\n * Parse STX string to microSTX bigint (6 decimals).\n * @example parseStx(\"1.5\") → 1500000n\n */\nexport function parseStx(stx: string | number): bigint {\n\treturn parseUnits(stx, 6);\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";AAKO,SAAS,WAAW,CAC1B,OACA,UACS;AAAA,EACT,IAAI,IAAI,OAAO,KAAK;AAAA,EAEpB,MAAM,WAAW,IAAI;AAAA,EACrB,IAAI;AAAA,IAAU,IAAI,CAAC;AAAA,EAEnB,MAAM,UAAU,OAAO,OAAO,QAAQ;AAAA,EACtC,MAAM,WAAW,IAAI,SAAS,SAAS;AAAA,EACvC,IAAI,YAAY,IAAI,SAAS,SAAS,EAAE,SAAS,UAAU,GAAG;AAAA,EAG9D,WAAW,SAAS,QAAQ,OAAO,EAAE,KAAK;AAAA,EAE1C,MAAM,SAAS,GAAG,WAAW;AAAA,EAC7B,OAAO,WAAW,IAAI,WAAW;AAAA;AAQlC,IAAM,iBAAiB;AAEhB,SAAS,UAAU,CAAC,OAAwB,UAA0B;AAAA,EAC5E,IAAI,OAAO,UAAU,YAAY,CA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