@secondlayer/stacks 2.14.1 → 2.15.1
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 +37 -0
- package/dist/shared/{stacks-f66v961k.js → stacks-1k0kmpcw.js} +2 -2
- package/dist/shared/{stacks-6mhsf8hk.cjs → stacks-1xk4wby6.cjs} +10 -21
- package/dist/shared/{stacks-6mhsf8hk.cjs.map → stacks-1xk4wby6.cjs.map} +5 -6
- package/dist/shared/{stacks-tswh2xav.js → stacks-2x04a6ss.js} +12 -26
- package/dist/shared/{stacks-tswh2xav.js.map → stacks-2x04a6ss.js.map} +5 -6
- package/dist/shared/stacks-3kj51c6p.cjs +16 -0
- package/dist/shared/stacks-3kj51c6p.cjs.map +10 -0
- package/dist/shared/{stacks-jcgvn5v5.cjs → stacks-70xxh5h1.cjs} +15 -6
- package/dist/shared/{stacks-dmrvk1mz.js.map → stacks-70xxh5h1.cjs.map} +3 -3
- package/dist/shared/stacks-f0hfqaj5.js +22 -0
- package/dist/shared/stacks-f0hfqaj5.js.map +10 -0
- package/dist/shared/{stacks-3vyvtahh.js → stacks-ggxnnph5.cjs} +2 -46
- package/dist/shared/stacks-ggxnnph5.cjs.map +10 -0
- package/dist/shared/stacks-pdcz1w1d.js +33 -0
- package/dist/shared/stacks-pdcz1w1d.js.map +10 -0
- package/dist/shared/{stacks-fjrpnkt3.cjs → stacks-q45x3389.js} +20 -15
- package/dist/shared/stacks-q45x3389.js.map +10 -0
- package/dist/shared/{stacks-hxp7v905.js → stacks-refg7hca.js} +7 -5
- package/dist/shared/{stacks-hxp7v905.js.map → stacks-refg7hca.js.map} +2 -2
- package/dist/shared/{stacks-dmrvk1mz.js → stacks-y9w78e2b.js} +15 -6
- package/dist/shared/{stacks-jcgvn5v5.cjs.map → stacks-y9w78e2b.js.map} +3 -3
- package/dist/shared/stacks-yetejw9x.cjs +16 -0
- package/dist/shared/stacks-yetejw9x.cjs.map +10 -0
- package/dist/src/actions/index.js +12 -8
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bns/index.js +5 -4
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/connect/index.cjs +47 -6
- package/dist/src/connect/index.cjs.map +8 -4
- package/dist/src/connect/index.js +47 -6
- package/dist/src/connect/index.js.map +8 -4
- package/dist/src/index.js +11 -7
- package/dist/src/index.js.map +2 -2
- package/dist/src/pox/index.js +5 -4
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +513 -0
- package/dist/src/pox5/index.cjs.map +16 -0
- package/dist/src/pox5/index.d.cts +646 -0
- package/dist/src/pox5/index.d.ts +646 -0
- package/dist/src/pox5/index.js +540 -0
- package/dist/src/pox5/index.js.map +16 -0
- package/dist/src/sbtc/index.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +5 -4
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/btc/index.cjs +6 -5
- package/dist/src/tools/btc/index.cjs.map +3 -3
- package/dist/src/tools/btc/index.d.cts +2 -1
- package/dist/src/tools/btc/index.d.ts +2 -1
- package/dist/src/tools/btc/index.js +6 -5
- package/dist/src/tools/btc/index.js.map +3 -3
- package/dist/src/tools/index.cjs +323 -43
- package/dist/src/tools/index.cjs.map +10 -9
- package/dist/src/tools/index.js +323 -46
- package/dist/src/tools/index.js.map +10 -9
- package/dist/src/x402/index.js +2 -2
- package/package.json +7 -2
- package/dist/shared/stacks-3vyvtahh.js.map +0 -11
- package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
- /package/dist/shared/{stacks-f66v961k.js.map → stacks-1k0kmpcw.js.map} +0 -0
package/dist/src/tools/index.cjs
CHANGED
|
@@ -58,6 +58,37 @@ module.exports = __toCommonJS(exports_tools);
|
|
|
58
58
|
var import_ai = require("ai");
|
|
59
59
|
var import_zod = require("zod");
|
|
60
60
|
|
|
61
|
+
// src/errors/base.ts
|
|
62
|
+
class BaseError extends Error {
|
|
63
|
+
name = "StacksError";
|
|
64
|
+
shortMessage;
|
|
65
|
+
details;
|
|
66
|
+
constructor(shortMessage, options) {
|
|
67
|
+
const message = [
|
|
68
|
+
shortMessage,
|
|
69
|
+
options?.details ? `
|
|
70
|
+
${options.details}` : ""
|
|
71
|
+
].join("");
|
|
72
|
+
super(message, { cause: options?.cause });
|
|
73
|
+
this.shortMessage = shortMessage;
|
|
74
|
+
this.details = options?.details;
|
|
75
|
+
}
|
|
76
|
+
toJSON() {
|
|
77
|
+
return {
|
|
78
|
+
name: this.name,
|
|
79
|
+
message: this.message,
|
|
80
|
+
shortMessage: this.shortMessage,
|
|
81
|
+
details: this.details,
|
|
82
|
+
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/errors/response.ts
|
|
88
|
+
class MalformedResponseError extends BaseError {
|
|
89
|
+
name = "MalformedResponseError";
|
|
90
|
+
}
|
|
91
|
+
|
|
61
92
|
// src/utils/c32.ts
|
|
62
93
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
63
94
|
|
|
@@ -471,6 +502,9 @@ var AssetType = {
|
|
|
471
502
|
};
|
|
472
503
|
var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
|
|
473
504
|
var MEMO_MAX_LENGTH_BYTES = 34;
|
|
505
|
+
var COINBASE_BYTES_LENGTH = 32;
|
|
506
|
+
var VRF_PROOF_BYTES_LENGTH = 80;
|
|
507
|
+
var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
|
|
474
508
|
|
|
475
509
|
// src/transactions/wire/serialize.ts
|
|
476
510
|
function serializeAddress2(c32Address) {
|
|
@@ -656,6 +690,9 @@ function serializeTransaction(tx) {
|
|
|
656
690
|
}
|
|
657
691
|
|
|
658
692
|
// src/actions/public/estimateFee.ts
|
|
693
|
+
function isValidEstimation(e) {
|
|
694
|
+
return typeof e === "object" && e !== null && "fee_rate" in e && "fee" in e && (typeof e.fee_rate === "number" || typeof e.fee_rate === "string") && (typeof e.fee === "number" || typeof e.fee === "string");
|
|
695
|
+
}
|
|
659
696
|
async function estimateFee(client, params) {
|
|
660
697
|
const payloadHex = bytesToHex(serializePayload(params.transaction.payload));
|
|
661
698
|
const txHex = bytesToHex(serializeTransaction(params.transaction));
|
|
@@ -666,10 +703,16 @@ async function estimateFee(client, params) {
|
|
|
666
703
|
transaction_payload: `0x${payloadHex}`
|
|
667
704
|
}
|
|
668
705
|
});
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
706
|
+
const raw = data?.estimations ?? [];
|
|
707
|
+
return raw.map((e) => {
|
|
708
|
+
if (!isValidEstimation(e)) {
|
|
709
|
+
throw new MalformedResponseError("estimateFee: node response contains invalid fee estimation entry");
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
feeRate: Number(e.fee_rate),
|
|
713
|
+
fee: Number(e.fee)
|
|
714
|
+
};
|
|
715
|
+
});
|
|
673
716
|
}
|
|
674
717
|
|
|
675
718
|
// src/actions/public/getAccountHistory.ts
|
|
@@ -678,48 +721,19 @@ async function getAccountHistory(client, params) {
|
|
|
678
721
|
return client.request(`/extended/v2/addresses/${params.address}/transactions?limit=${limit}`, { method: "GET" });
|
|
679
722
|
}
|
|
680
723
|
|
|
681
|
-
// src/errors/base.ts
|
|
682
|
-
class BaseError extends Error {
|
|
683
|
-
name = "StacksError";
|
|
684
|
-
shortMessage;
|
|
685
|
-
details;
|
|
686
|
-
constructor(shortMessage, options) {
|
|
687
|
-
const message = [
|
|
688
|
-
shortMessage,
|
|
689
|
-
options?.details ? `
|
|
690
|
-
${options.details}` : ""
|
|
691
|
-
].join("");
|
|
692
|
-
super(message, { cause: options?.cause });
|
|
693
|
-
this.shortMessage = shortMessage;
|
|
694
|
-
this.details = options?.details;
|
|
695
|
-
}
|
|
696
|
-
toJSON() {
|
|
697
|
-
return {
|
|
698
|
-
name: this.name,
|
|
699
|
-
message: this.message,
|
|
700
|
-
shortMessage: this.shortMessage,
|
|
701
|
-
details: this.details,
|
|
702
|
-
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// src/errors/response.ts
|
|
708
|
-
class MalformedResponseError extends BaseError {
|
|
709
|
-
name = "MalformedResponseError";
|
|
710
|
-
}
|
|
711
|
-
|
|
712
724
|
// src/actions/public/getAccountInfo.ts
|
|
713
725
|
async function getAccountInfo(client, params) {
|
|
714
726
|
const data = await client.request(`/v2/accounts/${params.address}?proof=1`, {
|
|
715
727
|
method: "GET"
|
|
716
728
|
});
|
|
717
|
-
|
|
729
|
+
const balance = data?.balance;
|
|
730
|
+
const nonce = data?.nonce;
|
|
731
|
+
if (typeof balance !== "string" && typeof balance !== "number" || typeof nonce !== "string" && typeof nonce !== "number") {
|
|
718
732
|
throw new MalformedResponseError(`getAccountInfo: /v2/accounts/${params.address} response is missing "balance" or "nonce"`);
|
|
719
733
|
}
|
|
720
734
|
return {
|
|
721
|
-
balance: BigInt(
|
|
722
|
-
nonce: BigInt(
|
|
735
|
+
balance: BigInt(balance),
|
|
736
|
+
nonce: BigInt(nonce),
|
|
723
737
|
balanceProof: data.balance_proof ?? "",
|
|
724
738
|
nonceProof: data.nonce_proof ?? ""
|
|
725
739
|
};
|
|
@@ -730,10 +744,11 @@ async function getBalance(client, params) {
|
|
|
730
744
|
const data = await client.request(`/v2/accounts/${params.address}`, {
|
|
731
745
|
method: "GET"
|
|
732
746
|
});
|
|
733
|
-
|
|
747
|
+
const balance = data?.balance;
|
|
748
|
+
if (typeof balance !== "string" && typeof balance !== "number") {
|
|
734
749
|
throw new MalformedResponseError(`getBalance: /v2/accounts/${params.address} response is missing "balance"`);
|
|
735
750
|
}
|
|
736
|
-
return BigInt(
|
|
751
|
+
return BigInt(balance);
|
|
737
752
|
}
|
|
738
753
|
|
|
739
754
|
// src/actions/public/getBlock.ts
|
|
@@ -2543,6 +2558,258 @@ async function getPrimaryName(client, address) {
|
|
|
2543
2558
|
}
|
|
2544
2559
|
}
|
|
2545
2560
|
|
|
2561
|
+
// src/transactions/wire/deserialize.ts
|
|
2562
|
+
function readSpendingCondition(r) {
|
|
2563
|
+
const hashMode = r.readUInt8();
|
|
2564
|
+
const signer = bytesToHex(r.readBytes(20));
|
|
2565
|
+
const nonce = r.readBigUInt64BE();
|
|
2566
|
+
const fee = r.readBigUInt64BE();
|
|
2567
|
+
if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {
|
|
2568
|
+
const keyEncoding = r.readUInt8();
|
|
2569
|
+
const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));
|
|
2570
|
+
return {
|
|
2571
|
+
hashMode,
|
|
2572
|
+
signer,
|
|
2573
|
+
nonce,
|
|
2574
|
+
fee,
|
|
2575
|
+
keyEncoding,
|
|
2576
|
+
signature
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
const fieldCount = r.readUInt32BE();
|
|
2580
|
+
const fields = [];
|
|
2581
|
+
for (let i = 0;i < fieldCount; i++) {
|
|
2582
|
+
const fieldType = r.readUInt8();
|
|
2583
|
+
if (fieldType <= 1) {
|
|
2584
|
+
const keyLen = fieldType === 0 ? 33 : 65;
|
|
2585
|
+
fields.push({
|
|
2586
|
+
type: "publicKey",
|
|
2587
|
+
pubKeyEncoding: fieldType,
|
|
2588
|
+
data: bytesToHex(r.readBytes(keyLen))
|
|
2589
|
+
});
|
|
2590
|
+
} else {
|
|
2591
|
+
fields.push({
|
|
2592
|
+
type: "signature",
|
|
2593
|
+
pubKeyEncoding: fieldType === 2 ? 0 : 1,
|
|
2594
|
+
data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES))
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
const signaturesRequired = r.readUInt16BE();
|
|
2599
|
+
return {
|
|
2600
|
+
hashMode,
|
|
2601
|
+
signer,
|
|
2602
|
+
nonce,
|
|
2603
|
+
fee,
|
|
2604
|
+
fields,
|
|
2605
|
+
signaturesRequired
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
function readAuthorization(r) {
|
|
2609
|
+
const authType = r.readUInt8();
|
|
2610
|
+
const spendingCondition = readSpendingCondition(r);
|
|
2611
|
+
if (authType === AuthType.Standard) {
|
|
2612
|
+
return { authType: AuthType.Standard, spendingCondition };
|
|
2613
|
+
}
|
|
2614
|
+
const sponsorSpendingCondition = readSpendingCondition(r);
|
|
2615
|
+
return {
|
|
2616
|
+
authType: AuthType.Sponsored,
|
|
2617
|
+
spendingCondition,
|
|
2618
|
+
sponsorSpendingCondition
|
|
2619
|
+
};
|
|
2620
|
+
}
|
|
2621
|
+
function readAssetInfo(r) {
|
|
2622
|
+
return {
|
|
2623
|
+
address: readAddress(r),
|
|
2624
|
+
contractName: readLPString(r),
|
|
2625
|
+
assetName: readLPString(r)
|
|
2626
|
+
};
|
|
2627
|
+
}
|
|
2628
|
+
function readPostConditionPrincipal(r) {
|
|
2629
|
+
const type = r.readUInt8();
|
|
2630
|
+
switch (type) {
|
|
2631
|
+
case PostConditionPrincipalId.Origin:
|
|
2632
|
+
return { type: "origin" };
|
|
2633
|
+
case PostConditionPrincipalId.Standard:
|
|
2634
|
+
return { type: "standard", address: readAddress(r) };
|
|
2635
|
+
case PostConditionPrincipalId.Contract:
|
|
2636
|
+
return {
|
|
2637
|
+
type: "contract",
|
|
2638
|
+
address: readAddress(r),
|
|
2639
|
+
contractName: readLPString(r)
|
|
2640
|
+
};
|
|
2641
|
+
default:
|
|
2642
|
+
return { type: "origin" };
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
function readPostConditions(r) {
|
|
2646
|
+
const count = r.readUInt32BE();
|
|
2647
|
+
const pcs = [];
|
|
2648
|
+
for (let i = 0;i < count; i++) {
|
|
2649
|
+
const assetType = r.readUInt8();
|
|
2650
|
+
const principal = readPostConditionPrincipal(r);
|
|
2651
|
+
switch (assetType) {
|
|
2652
|
+
case AssetType.STX:
|
|
2653
|
+
pcs.push({
|
|
2654
|
+
type: "stx",
|
|
2655
|
+
principal,
|
|
2656
|
+
conditionCode: r.readUInt8(),
|
|
2657
|
+
amount: r.readBigUInt64BE()
|
|
2658
|
+
});
|
|
2659
|
+
break;
|
|
2660
|
+
case AssetType.Fungible:
|
|
2661
|
+
pcs.push({
|
|
2662
|
+
type: "ft",
|
|
2663
|
+
principal,
|
|
2664
|
+
asset: readAssetInfo(r),
|
|
2665
|
+
conditionCode: r.readUInt8(),
|
|
2666
|
+
amount: r.readBigUInt64BE()
|
|
2667
|
+
});
|
|
2668
|
+
break;
|
|
2669
|
+
case AssetType.NonFungible:
|
|
2670
|
+
pcs.push({
|
|
2671
|
+
type: "nft",
|
|
2672
|
+
principal,
|
|
2673
|
+
asset: readAssetInfo(r),
|
|
2674
|
+
assetId: readCV(r),
|
|
2675
|
+
conditionCode: r.readUInt8()
|
|
2676
|
+
});
|
|
2677
|
+
break;
|
|
2678
|
+
case AssetType.Staking:
|
|
2679
|
+
pcs.push({
|
|
2680
|
+
type: "staking",
|
|
2681
|
+
principal,
|
|
2682
|
+
conditionCode: r.readUInt8(),
|
|
2683
|
+
amount: r.readBigUInt64BE()
|
|
2684
|
+
});
|
|
2685
|
+
break;
|
|
2686
|
+
case AssetType.Pox:
|
|
2687
|
+
pcs.push({
|
|
2688
|
+
type: "pox",
|
|
2689
|
+
principal,
|
|
2690
|
+
conditionCode: r.readUInt8()
|
|
2691
|
+
});
|
|
2692
|
+
break;
|
|
2693
|
+
default:
|
|
2694
|
+
throw new Error(`Unknown post-condition asset type: 0x${assetType.toString(16).padStart(2, "0")} (post-condition ${i + 1}/${count})`);
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
return pcs;
|
|
2698
|
+
}
|
|
2699
|
+
function readPayload(r) {
|
|
2700
|
+
const payloadType = r.readUInt8();
|
|
2701
|
+
switch (payloadType) {
|
|
2702
|
+
case PayloadType.TokenTransfer: {
|
|
2703
|
+
const recipient = readCV(r);
|
|
2704
|
+
const amount = r.readBigUInt64BE();
|
|
2705
|
+
const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
|
|
2706
|
+
const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
|
|
2707
|
+
return {
|
|
2708
|
+
payloadType: PayloadType.TokenTransfer,
|
|
2709
|
+
recipient,
|
|
2710
|
+
amount,
|
|
2711
|
+
memo
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
case PayloadType.ContractCall: {
|
|
2715
|
+
const contractAddress = readAddress(r);
|
|
2716
|
+
const contractName = readLPString(r);
|
|
2717
|
+
const functionName = readLPString(r);
|
|
2718
|
+
const numArgs = r.readUInt32BE();
|
|
2719
|
+
const functionArgs = [];
|
|
2720
|
+
for (let i = 0;i < numArgs; i++)
|
|
2721
|
+
functionArgs.push(readCV(r));
|
|
2722
|
+
return {
|
|
2723
|
+
payloadType: PayloadType.ContractCall,
|
|
2724
|
+
contractAddress,
|
|
2725
|
+
contractName,
|
|
2726
|
+
functionName,
|
|
2727
|
+
functionArgs
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
case PayloadType.SmartContract: {
|
|
2731
|
+
const contractName = readLPString(r);
|
|
2732
|
+
const codeBody = readLPString(r, 4);
|
|
2733
|
+
return { payloadType: PayloadType.SmartContract, contractName, codeBody };
|
|
2734
|
+
}
|
|
2735
|
+
case PayloadType.VersionedSmartContract: {
|
|
2736
|
+
const clarityVersion = r.readUInt8();
|
|
2737
|
+
const contractName = readLPString(r);
|
|
2738
|
+
const codeBody = readLPString(r, 4);
|
|
2739
|
+
return {
|
|
2740
|
+
payloadType: PayloadType.VersionedSmartContract,
|
|
2741
|
+
clarityVersion,
|
|
2742
|
+
contractName,
|
|
2743
|
+
codeBody
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
case PayloadType.Coinbase: {
|
|
2747
|
+
const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
|
|
2748
|
+
return { payloadType: PayloadType.Coinbase, coinbaseBuffer };
|
|
2749
|
+
}
|
|
2750
|
+
case PayloadType.CoinbaseToAltRecipient: {
|
|
2751
|
+
const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
|
|
2752
|
+
const recipient = readCV(r);
|
|
2753
|
+
return {
|
|
2754
|
+
payloadType: PayloadType.CoinbaseToAltRecipient,
|
|
2755
|
+
coinbaseBuffer,
|
|
2756
|
+
recipient
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
case PayloadType.PoisonMicroblock: {
|
|
2760
|
+
const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
|
|
2761
|
+
const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));
|
|
2762
|
+
return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };
|
|
2763
|
+
}
|
|
2764
|
+
case PayloadType.TenureChange: {
|
|
2765
|
+
const tenureConsensusHash = bytesToHex(r.readBytes(20));
|
|
2766
|
+
const prevTenureConsensusHash = bytesToHex(r.readBytes(20));
|
|
2767
|
+
const burnViewConsensusHash = bytesToHex(r.readBytes(20));
|
|
2768
|
+
const previousTenureEnd = bytesToHex(r.readBytes(32));
|
|
2769
|
+
const previousTenureBlocks = r.readUInt32BE();
|
|
2770
|
+
const cause = r.readUInt8();
|
|
2771
|
+
const pubkeyHash = bytesToHex(r.readBytes(20));
|
|
2772
|
+
return {
|
|
2773
|
+
payloadType: PayloadType.TenureChange,
|
|
2774
|
+
tenureConsensusHash,
|
|
2775
|
+
prevTenureConsensusHash,
|
|
2776
|
+
burnViewConsensusHash,
|
|
2777
|
+
previousTenureEnd,
|
|
2778
|
+
previousTenureBlocks,
|
|
2779
|
+
cause,
|
|
2780
|
+
pubkeyHash
|
|
2781
|
+
};
|
|
2782
|
+
}
|
|
2783
|
+
case PayloadType.NakamotoCoinbase: {
|
|
2784
|
+
const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));
|
|
2785
|
+
const optionalCV = readCV(r);
|
|
2786
|
+
const recipient = optionalCV.type === "none" ? null : optionalCV.type === "some" ? optionalCV.value : optionalCV;
|
|
2787
|
+
const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));
|
|
2788
|
+
return {
|
|
2789
|
+
payloadType: PayloadType.NakamotoCoinbase,
|
|
2790
|
+
coinbaseBuffer,
|
|
2791
|
+
recipient,
|
|
2792
|
+
vrfProof
|
|
2793
|
+
};
|
|
2794
|
+
}
|
|
2795
|
+
default:
|
|
2796
|
+
throw new Error(`Unknown payload type: ${payloadType}`);
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
function deserializeTransaction(input) {
|
|
2800
|
+
const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
|
|
2801
|
+
const r = new BytesReader(bytes);
|
|
2802
|
+
return {
|
|
2803
|
+
version: r.readUInt8(),
|
|
2804
|
+
chainId: r.readUInt32BE(),
|
|
2805
|
+
auth: readAuthorization(r),
|
|
2806
|
+
anchorMode: r.readUInt8(),
|
|
2807
|
+
postConditionMode: r.readUInt8(),
|
|
2808
|
+
postConditions: readPostConditions(r),
|
|
2809
|
+
payload: readPayload(r)
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2546
2813
|
// src/chains/definitions.ts
|
|
2547
2814
|
var mainnet = {
|
|
2548
2815
|
id: 1,
|
|
@@ -2985,11 +3252,24 @@ async function contractRead(client, args) {
|
|
|
2985
3252
|
const result = await readContract(client, args);
|
|
2986
3253
|
return { result: JSON.stringify(result) };
|
|
2987
3254
|
}
|
|
3255
|
+
function assertValidHex(raw) {
|
|
3256
|
+
if (raw.length % 2 !== 0) {
|
|
3257
|
+
throw new Error("serializedTxHex: odd-length hex string");
|
|
3258
|
+
}
|
|
3259
|
+
if (!/^[0-9a-fA-F]+$/.test(raw)) {
|
|
3260
|
+
throw new Error("serializedTxHex: contains non-hex characters");
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
2988
3263
|
async function fee(client, serializedTxHex) {
|
|
2989
3264
|
const raw = serializedTxHex.startsWith("0x") ? serializedTxHex.slice(2) : serializedTxHex;
|
|
3265
|
+
assertValidHex(raw);
|
|
2990
3266
|
const txBytes = new Uint8Array(Buffer.from(raw, "hex"));
|
|
2991
|
-
|
|
2992
|
-
|
|
3267
|
+
let transaction;
|
|
3268
|
+
try {
|
|
3269
|
+
transaction = deserializeTransaction(txBytes);
|
|
3270
|
+
} catch (e) {
|
|
3271
|
+
throw new Error(`serializedTxHex: deserialization failed — ${e instanceof Error ? e.message : String(e)}`);
|
|
3272
|
+
}
|
|
2993
3273
|
const fees = await estimateFee(client, {
|
|
2994
3274
|
transaction
|
|
2995
3275
|
});
|
|
@@ -3174,5 +3454,5 @@ var getNftHoldings2 = import_ai.tool({
|
|
|
3174
3454
|
execute: ({ principal, limit }) => nftHoldings(getDefaultPublicClient(), principal, limit)
|
|
3175
3455
|
});
|
|
3176
3456
|
|
|
3177
|
-
//# debugId=
|
|
3457
|
+
//# debugId=8A41B6F924608F5B64756E2164756E21
|
|
3178
3458
|
//# sourceMappingURL=index.cjs.map
|