@secondlayer/stacks 0.2.0 → 0.2.2
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-2ar4prfz.cjs +328 -0
- package/dist/shared/stacks-2ar4prfz.cjs.map +11 -0
- package/dist/shared/{stacks-ph4a6322.js → stacks-6m1z4j07.js} +26 -24
- package/dist/shared/stacks-6m1z4j07.js.map +10 -0
- package/dist/shared/{stacks-0hqzpm29.js → stacks-96gaxfcf.js} +9 -13
- package/dist/shared/{stacks-0hqzpm29.js.map → stacks-96gaxfcf.js.map} +2 -2
- package/dist/shared/stacks-dr5en54r.cjs +119 -0
- package/dist/shared/stacks-dr5en54r.cjs.map +10 -0
- package/dist/shared/{stacks-v3zy6zds.cjs → stacks-etf219gs.cjs} +11 -7
- package/dist/shared/stacks-etf219gs.cjs.map +10 -0
- package/dist/shared/stacks-je937aas.js +121 -0
- package/dist/shared/stacks-je937aas.js.map +10 -0
- package/dist/shared/stacks-jrnmh4kc.js +282 -0
- package/dist/shared/stacks-jrnmh4kc.js.map +11 -0
- package/dist/shared/{stacks-8qhfd37f.js → stacks-k9p8m3wf.js} +15 -19
- package/dist/shared/{stacks-8qhfd37f.js.map → stacks-k9p8m3wf.js.map} +2 -2
- package/dist/shared/{stacks-j2cy7qtt.js → stacks-ky14tdf6.cjs} +109 -24
- package/dist/shared/stacks-ky14tdf6.cjs.map +13 -0
- package/dist/shared/stacks-mrk6tkkh.cjs +41 -0
- package/dist/shared/{stacks-2gdt3aqj.cjs.map → stacks-mrk6tkkh.cjs.map} +1 -1
- package/dist/shared/{stacks-d1fmkv3p.js → stacks-p93g814f.js} +3 -3
- package/dist/shared/{stacks-zhd20wgz.js → stacks-q79dx28x.js} +3 -3
- package/dist/shared/{stacks-r1t6g3c3.cjs → stacks-ra02bpny.cjs} +8 -3
- package/dist/shared/{stacks-r1t6g3c3.cjs.map → stacks-ra02bpny.cjs.map} +3 -3
- package/dist/shared/{stacks-b008c3w8.cjs → stacks-rg1g0fja.js} +134 -2
- package/dist/shared/stacks-rg1g0fja.js.map +13 -0
- package/dist/shared/{stacks-bycy6t9k.js → stacks-rwfgts3s.js} +2 -2
- package/dist/shared/{stacks-gjvbq6w7.js → stacks-s10yb9gz.js} +2 -2
- package/dist/shared/{stacks-nqytwfcc.js → stacks-s7z5q8be.js} +8 -3
- package/dist/shared/{stacks-nqytwfcc.js.map → stacks-s7z5q8be.js.map} +3 -3
- package/dist/shared/{stacks-hfem9dck.cjs → stacks-v6ja2eh7.cjs} +342 -91
- package/dist/shared/stacks-v6ja2eh7.cjs.map +15 -0
- package/dist/shared/{stacks-xtz0n62y.js → stacks-xp9n3r0t.js} +357 -112
- package/dist/shared/stacks-xp9n3r0t.js.map +15 -0
- package/dist/src/accounts/index.js +3 -4
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.d.cts +7 -0
- package/dist/src/actions/index.d.ts +7 -0
- package/dist/src/actions/index.js +11 -14
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bns/index.js +13 -16
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/chains/index.js +1 -2
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/clarity/index.cjs +1 -326
- package/dist/src/clarity/index.cjs.map +3 -5
- package/dist/src/clarity/index.js +19 -273
- package/dist/src/clarity/index.js.map +3 -5
- package/dist/src/connect/index.cjs +19 -9
- package/dist/src/connect/index.cjs.map +3 -3
- package/dist/src/connect/index.js.map +2 -2
- package/dist/src/connect/walletconnect/index.cjs +19 -9
- package/dist/src/connect/walletconnect/index.cjs.map +3 -3
- package/dist/src/connect/walletconnect/index.js.map +1 -1
- package/dist/src/index.cjs +1 -2
- package/dist/src/index.cjs.map +3 -3
- package/dist/src/index.d.cts +7 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +12 -19
- package/dist/src/index.js.map +3 -3
- package/dist/src/postconditions/index.cjs +1 -117
- package/dist/src/postconditions/index.cjs.map +3 -4
- package/dist/src/postconditions/index.js +5 -119
- package/dist/src/postconditions/index.js.map +3 -4
- package/dist/src/pox/index.js +12 -15
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +11 -14
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/subscriptions/index.js +1 -2
- package/dist/src/subscriptions/index.js.map +1 -1
- package/dist/src/transactions/index.d.cts +7 -0
- package/dist/src/transactions/index.d.ts +7 -0
- package/dist/src/transactions/index.js +18 -22
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.js +4 -5
- package/dist/src/utils/index.js.map +2 -2
- package/package.json +1 -1
- package/dist/shared/stacks-1aqm7c2h.cjs +0 -110
- package/dist/shared/stacks-1aqm7c2h.cjs.map +0 -11
- package/dist/shared/stacks-2gdt3aqj.cjs +0 -44
- package/dist/shared/stacks-8yykgdww.js +0 -125
- package/dist/shared/stacks-8yykgdww.js.map +0 -11
- package/dist/shared/stacks-b008c3w8.cjs.map +0 -11
- package/dist/shared/stacks-hfem9dck.cjs.map +0 -13
- package/dist/shared/stacks-j2cy7qtt.js.map +0 -11
- package/dist/shared/stacks-kgesjxq4.cjs +0 -247
- package/dist/shared/stacks-kgesjxq4.cjs.map +0 -11
- package/dist/shared/stacks-nbz193yk.js +0 -282
- package/dist/shared/stacks-nbz193yk.js.map +0 -11
- package/dist/shared/stacks-njvyj3ab.js +0 -23
- package/dist/shared/stacks-njvyj3ab.js.map +0 -9
- package/dist/shared/stacks-ph4a6322.js.map +0 -10
- package/dist/shared/stacks-v3zy6zds.cjs.map +0 -10
- package/dist/shared/stacks-xtz0n62y.js.map +0 -13
- /package/dist/shared/{stacks-d1fmkv3p.js.map → stacks-p93g814f.js.map} +0 -0
- /package/dist/shared/{stacks-zhd20wgz.js.map → stacks-q79dx28x.js.map} +0 -0
- /package/dist/shared/{stacks-bycy6t9k.js.map → stacks-rwfgts3s.js.map} +0 -0
- /package/dist/shared/{stacks-gjvbq6w7.js.map → stacks-s10yb9gz.js.map} +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/postconditions/index.ts
|
|
2
|
+
var exports_postconditions = {};
|
|
3
|
+
__export(exports_postconditions, {
|
|
4
|
+
Pc: () => Pc
|
|
5
|
+
});
|
|
6
|
+
module.exports = __toCommonJS(exports_postconditions);
|
|
7
|
+
|
|
8
|
+
// src/postconditions/builder.ts
|
|
9
|
+
class PartialPcWithPrincipal {
|
|
10
|
+
address;
|
|
11
|
+
constructor(address) {
|
|
12
|
+
this.address = address;
|
|
13
|
+
}
|
|
14
|
+
willSendEq(amount) {
|
|
15
|
+
return new PartialPcFtWithCode(this.address, amount, "eq");
|
|
16
|
+
}
|
|
17
|
+
willSendGte(amount) {
|
|
18
|
+
return new PartialPcFtWithCode(this.address, amount, "gte");
|
|
19
|
+
}
|
|
20
|
+
willSendGt(amount) {
|
|
21
|
+
return new PartialPcFtWithCode(this.address, amount, "gt");
|
|
22
|
+
}
|
|
23
|
+
willSendLte(amount) {
|
|
24
|
+
return new PartialPcFtWithCode(this.address, amount, "lte");
|
|
25
|
+
}
|
|
26
|
+
willSendLt(amount) {
|
|
27
|
+
return new PartialPcFtWithCode(this.address, amount, "lt");
|
|
28
|
+
}
|
|
29
|
+
willSendAsset() {
|
|
30
|
+
return new PartialPcNftWithCode(this.address, "sent");
|
|
31
|
+
}
|
|
32
|
+
willNotSendAsset() {
|
|
33
|
+
return new PartialPcNftWithCode(this.address, "not-sent");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class PartialPcFtWithCode {
|
|
38
|
+
address;
|
|
39
|
+
amount;
|
|
40
|
+
code;
|
|
41
|
+
constructor(address, amount, code) {
|
|
42
|
+
this.address = address;
|
|
43
|
+
this.amount = amount;
|
|
44
|
+
this.code = code;
|
|
45
|
+
}
|
|
46
|
+
ustx() {
|
|
47
|
+
return {
|
|
48
|
+
type: "stx-postcondition",
|
|
49
|
+
address: this.address,
|
|
50
|
+
condition: this.code,
|
|
51
|
+
amount: intToBigInt(this.amount).toString()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
ft(contractId, tokenName) {
|
|
55
|
+
const [address, name] = contractId.split(".");
|
|
56
|
+
if (!address || !validateStacksAddress(address) || !name) {
|
|
57
|
+
throw new Error(`Invalid contract id: ${contractId}`);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
type: "ft-postcondition",
|
|
61
|
+
address: this.address,
|
|
62
|
+
condition: this.code,
|
|
63
|
+
amount: intToBigInt(this.amount).toString(),
|
|
64
|
+
asset: `${contractId}::${tokenName}`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class PartialPcNftWithCode {
|
|
70
|
+
address;
|
|
71
|
+
code;
|
|
72
|
+
constructor(address, code) {
|
|
73
|
+
this.address = address;
|
|
74
|
+
this.code = code;
|
|
75
|
+
}
|
|
76
|
+
nft(assetOrContractId, tokenNameOrAssetId, assetId) {
|
|
77
|
+
let contractAddress;
|
|
78
|
+
let contractName;
|
|
79
|
+
let tokenName;
|
|
80
|
+
let id;
|
|
81
|
+
if (assetId !== undefined) {
|
|
82
|
+
[contractAddress, contractName] = parseContractId(assetOrContractId);
|
|
83
|
+
tokenName = tokenNameOrAssetId;
|
|
84
|
+
id = assetId;
|
|
85
|
+
} else {
|
|
86
|
+
const [principal, tName] = assetOrContractId.split("::");
|
|
87
|
+
if (!principal || !tName)
|
|
88
|
+
throw new Error(`Invalid asset name: ${assetOrContractId}`);
|
|
89
|
+
[contractAddress, contractName] = parseContractId(principal);
|
|
90
|
+
tokenName = tName;
|
|
91
|
+
id = tokenNameOrAssetId;
|
|
92
|
+
}
|
|
93
|
+
if (!validateStacksAddress(contractAddress)) {
|
|
94
|
+
throw new Error(`Invalid contract address: ${contractAddress}`);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
type: "nft-postcondition",
|
|
98
|
+
address: this.address,
|
|
99
|
+
condition: this.code,
|
|
100
|
+
asset: `${contractAddress}.${contractName}::${tokenName}`,
|
|
101
|
+
assetId: id
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
var Pc = {
|
|
106
|
+
principal(address) {
|
|
107
|
+
const [addr, name] = address.split(".");
|
|
108
|
+
if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
|
|
109
|
+
throw new Error(`Invalid principal: ${address}`);
|
|
110
|
+
}
|
|
111
|
+
return new PartialPcWithPrincipal(address);
|
|
112
|
+
},
|
|
113
|
+
origin() {
|
|
114
|
+
return new PartialPcWithPrincipal("origin");
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//# debugId=60B2774FE4E4DD2564756E2164756E21
|
|
119
|
+
//# sourceMappingURL=stacks-dr5en54r.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/postconditions/builder.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { intToBigInt, type IntegerType } from \"../utils/encoding.ts\";\nimport { validateStacksAddress, parseContractId } from \"../utils/address.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type {\n StxPostCondition,\n FtPostCondition,\n NftPostCondition,\n FungibleComparator,\n NonFungibleComparator,\n} from \"./types.ts\";\n\nclass PartialPcWithPrincipal {\n constructor(private address: string) {}\n\n willSendEq(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"eq\");\n }\n willSendGte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gte\");\n }\n willSendGt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gt\");\n }\n willSendLte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lte\");\n }\n willSendLt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lt\");\n }\n willSendAsset() {\n return new PartialPcNftWithCode(this.address, \"sent\");\n }\n willNotSendAsset() {\n return new PartialPcNftWithCode(this.address, \"not-sent\");\n }\n}\n\nclass PartialPcFtWithCode {\n constructor(\n private address: string,\n private amount: IntegerType,\n private code: FungibleComparator\n ) {}\n\n ustx(): StxPostCondition {\n return {\n type: \"stx-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n };\n }\n\n ft(contractId: string, tokenName: string): FtPostCondition {\n const [address, name] = contractId.split(\".\");\n if (!address || !validateStacksAddress(address) || !name) {\n throw new Error(`Invalid contract id: ${contractId}`);\n }\n return {\n type: \"ft-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n asset: `${contractId}::${tokenName}`,\n };\n }\n}\n\nclass PartialPcNftWithCode {\n constructor(\n private address: string,\n private code: NonFungibleComparator\n ) {}\n\n nft(assetOrContractId: string, tokenNameOrAssetId: string | ClarityValue, assetId?: ClarityValue): NftPostCondition {\n let contractAddress: string;\n let contractName: string;\n let tokenName: string;\n let id: ClarityValue;\n\n if (assetId !== undefined) {\n // 3 args: contractId, tokenName, assetId\n [contractAddress, contractName] = parseContractId(assetOrContractId);\n tokenName = tokenNameOrAssetId as string;\n id = assetId;\n } else {\n // 2 args: assetString (addr.contract::token), assetId\n const [principal, tName] = assetOrContractId.split(\"::\");\n if (!principal || !tName) throw new Error(`Invalid asset name: ${assetOrContractId}`);\n [contractAddress, contractName] = parseContractId(principal);\n tokenName = tName;\n id = tokenNameOrAssetId as ClarityValue;\n }\n\n if (!validateStacksAddress(contractAddress)) {\n throw new Error(`Invalid contract address: ${contractAddress}`);\n }\n\n return {\n type: \"nft-postcondition\",\n address: this.address,\n condition: this.code,\n asset: `${contractAddress}.${contractName}::${tokenName}`,\n assetId: id,\n };\n }\n}\n\nexport const Pc = {\n principal(address: string) {\n const [addr, name] = address.split(\".\");\n if (!addr || !validateStacksAddress(addr) || (typeof name === \"string\" && !name)) {\n throw new Error(`Invalid principal: ${address}`);\n }\n return new PartialPcWith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S,CAAC,SAAiB;AAAA,IACzB,OAAO,MAAM,QAAQ,QAAQ,MAAM,GAAG;AAAA,IACtC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,IAAI,KAAM,OAAO,SAAS,YAAY,CAAC,MAAO;AAAA,MAChF,MAAM,IAAI,MAAM,sBAAsB,SAAS;AAAA,IACjD;AAAA,IACA,OAAO,IAAI,uBAAuB,OAAO;AAAA;AAAA,EAE3C,MAAM,GAAG;AAAA,IACP,OAAO,IAAI,uBAAuB,QAAQ;AAAA;AAE9C;",
|
|
8
|
+
"debugId": "60B2774FE4E4DD2564756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -19,12 +19,17 @@ class Reader {
|
|
|
19
19
|
return val;
|
|
20
20
|
}
|
|
21
21
|
readBytes(length) {
|
|
22
|
+
if (this.offset + length > this.data.length) {
|
|
23
|
+
throw new Error(`Buffer underflow: need ${length} bytes at offset ${this.offset}, have ${this.data.length}`);
|
|
24
|
+
}
|
|
22
25
|
const slice = this.data.slice(this.offset, this.offset + length);
|
|
23
26
|
this.offset += length;
|
|
24
27
|
return slice;
|
|
25
28
|
}
|
|
26
29
|
readBigUInt64BE() {
|
|
27
|
-
|
|
30
|
+
const bytes = this.readBytes(8);
|
|
31
|
+
const hex = bytesToHex(bytes);
|
|
32
|
+
return hex.length > 0 ? BigInt(`0x${hex}`) : 0n;
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
function readAddress(r) {
|
|
@@ -160,15 +165,15 @@ function readPostConditionPrincipal(r) {
|
|
|
160
165
|
case PostConditionPrincipalId.Contract:
|
|
161
166
|
return { type: "contract", address: readAddress(r), contractName: readLPString(r) };
|
|
162
167
|
default:
|
|
163
|
-
|
|
168
|
+
return { type: "origin" };
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
function readPostConditions(r) {
|
|
167
172
|
const count = r.readUInt32BE();
|
|
168
173
|
const pcs = [];
|
|
169
174
|
for (let i = 0;i < count; i++) {
|
|
170
|
-
const principal = readPostConditionPrincipal(r);
|
|
171
175
|
const assetType = r.readUInt8();
|
|
176
|
+
const principal = readPostConditionPrincipal(r);
|
|
172
177
|
switch (assetType) {
|
|
173
178
|
case AssetType.STX:
|
|
174
179
|
pcs.push({ type: "stx", principal, conditionCode: r.readUInt8(), amount: r.readBigUInt64BE() });
|
|
@@ -189,9 +194,8 @@ function readPayload(r) {
|
|
|
189
194
|
case PayloadType.TokenTransfer: {
|
|
190
195
|
const recipient = readCV(r);
|
|
191
196
|
const amount = r.readBigUInt64BE();
|
|
192
|
-
const memoContentLen = r.readUInt8();
|
|
193
197
|
const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);
|
|
194
|
-
const memo = bytesToAscii(memoBytes
|
|
198
|
+
const memo = bytesToAscii(memoBytes).replace(/\0+$/, "");
|
|
195
199
|
return { payloadType: PayloadType.TokenTransfer, recipient, amount, memo };
|
|
196
200
|
}
|
|
197
201
|
case PayloadType.ContractCall: {
|
|
@@ -273,5 +277,5 @@ function deserializeTransaction(input) {
|
|
|
273
277
|
};
|
|
274
278
|
}
|
|
275
279
|
|
|
276
|
-
//# debugId=
|
|
277
|
-
//# sourceMappingURL=stacks-
|
|
280
|
+
//# debugId=876770F5E21209F964756E2164756E21
|
|
281
|
+
//# sourceMappingURL=stacks-etf219gs.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/transactions/wire/deserialize.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n bytesToHex,\n hexToBytes,\n bytesToAscii,\n bytesToUtf8,\n without0x,\n} from \"../../utils/encoding.ts\";\nimport { c32address } from \"../../utils/c32.ts\";\nimport {\n AuthType,\n PayloadType,\n AddressHashMode,\n PostConditionPrincipalId,\n AssetType,\n RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,\n MEMO_MAX_LENGTH_BYTES,\n COINBASE_BYTES_LENGTH,\n VRF_PROOF_BYTES_LENGTH,\n MICROBLOCK_HEADER_BYTES_LENGTH,\n type StacksTransaction,\n type Authorization,\n type SpendingCondition,\n type TransactionPayload,\n type PostConditionWire,\n type PostConditionPrincipalWire,\n type AssetInfoWire,\n type TransactionAuthField,\n type AnchorMode,\n type PostConditionModeWire,\n type ClarityVersion,\n type TenureChangeCause,\n} from \"../types.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport { clarityTypeFromByte } from \"../../clarity/types.ts\";\nimport {\n intCV,\n uintCV,\n trueCV,\n falseCV,\n bufferCV,\n noneCV,\n someCV,\n responseOkCV,\n responseErrorCV,\n standardPrincipalCV,\n contractPrincipalCV,\n listCV,\n tupleCV,\n stringAsciiCV,\n stringUtf8CV,\n} from \"../../clarity/values.ts\";\nimport { bytesToTwosBigInt } from \"../../utils/encoding.ts\";\n\nclass Reader {\n private data: Uint8Array;\n public offset = 0;\n\n constructor(data: Uint8Array) {\n this.data = data;\n }\n\n readUInt8(): number {\n return this.data[this.offset++]!;\n }\n\n readUInt16BE(): number {\n const val = ((this.data[this.offset]! << 8) | this.data[this.offset + 1]!) >>> 0;\n this.offset += 2;\n return val;\n }\n\n readUInt32BE(): number {\n const val =\n ((this.data[this.offset]! << 24) |\n (this.data[this.offset + 1]! << 16) |\n (this.data[this.offset + 2]! << 8) |\n this.data[this.offset + 3]!) >>>\n 0;\n this.offset += 4;\n return val;\n }\n\n readBytes(length: number): Uint8Array {\n if (this.offset + length > this.data.length) {\n throw new Error(`Buffer underflow: need ${length} bytes at offset ${this.offset}, have ${this.data.length}`);\n }\n const slice = this.data.slice(this.offset, this.offset + length);\n this.offset += length;\n return slice;\n }\n\n readBigUInt64BE(): bigint {\n const bytes = this.readBytes(8);\n const hex = bytesToHex(bytes);\n return hex.length > 0 ? BigInt(`0x${hex}`) : 0n;\n }\n}\n\nfunction readAddress(r: Reader): string {\n const version = r.readUInt8();\n const hash160 = bytesToHex(r.readBytes(20));\n return c32address(version, hash160);\n}\n\nfunction readLPString(r: Reader, prefixBytes = 1): string {\n let length = 0;\n for (let i = 0; i < prefixBytes; i++) {\n length = (length << 8) | r.readUInt8();\n }\n return bytesToUtf8(r.readBytes(length));\n}\n\nfunction readCV(r: Reader): ClarityValue {\n const typeByte = r.readUInt8();\n const type = clarityTypeFromByte(typeByte);\n\n switch (type) {\n case \"int\":\n return intCV(bytesToTwosBigInt(r.readBytes(16)));\n case \"uint\":\n return uintCV(r.readBytes(16));\n case \"true\":\n return trueCV();\n case \"false\":\n return falseCV();\n case \"buffer\": {\n const len = r.readUInt32BE();\n return bufferCV(r.readBytes(len));\n }\n case \"none\":\n return noneCV();\n case \"some\":\n return someCV(readCV(r));\n case \"ok\":\n return responseOkCV(readCV(r));\n case \"err\":\n return responseErrorCV(readCV(r));\n case \"address\":\n return standardPrincipalCV(readAddress(r));\n case \"contract\": {\n const addr = readAddress(r);\n const name = readLPString(r);\n return contractPrincipalCV(addr, name);\n }\n case \"list\": {\n const len = r.readUInt32BE();\n const items: ClarityValue[] = [];\n for (let i = 0; i < len; i++) items.push(readCV(r));\n return listCV(items);\n }\n case \"tuple\": {\n const len = r.readUInt32BE();\n const data: Record<string, ClarityValue> = {};\n for (let i = 0; i < len; i++) {\n const key = readLPString(r);\n data[key] = readCV(r);\n }\n return tupleCV(data);\n }\n case \"ascii\": {\n const len = r.readUInt32BE();\n return stringAsciiCV(bytesToAscii(r.readBytes(len)));\n }\n case \"utf8\": {\n const len = r.readUInt32BE();\n return stringUtf8CV(bytesToUtf8(r.readBytes(len)));\n }\n default:\n throw new Error(`Unknown clarity type: ${type}`);\n }\n}\n\nfunction readSpendingCondition(r: Reader): SpendingCondition {\n const hashMode = r.readUInt8();\n const signer = bytesToHex(r.readBytes(20));\n const nonce = r.readBigUInt64BE();\n const fee = r.readBigUInt64BE();\n\n if (hashMode === AddressHashMode.P2PKH || hashMode === AddressHashMode.P2WPKH) {\n const keyEncoding = r.readUInt8();\n const signature = bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES));\n return { hashMode, signer, nonce, fee, keyEncoding, signature } as SpendingCondition;\n }\n\n const fieldCount = r.readUInt32BE();\n const fields: TransactionAuthField[] = [];\n for (let i = 0; i < fieldCount; i++) {\n const fieldType = r.readUInt8();\n if (fieldType <= 0x01) {\n const keyLen = fieldType === 0x00 ? 33 : 65;\n fields.push({\n type: \"publicKey\",\n pubKeyEncoding: fieldType as 0x00 | 0x01,\n data: bytesToHex(r.readBytes(keyLen)),\n });\n } else {\n fields.push({\n type: \"signature\",\n pubKeyEncoding: (fieldType === 0x02 ? 0x00 : 0x01) as 0x00 | 0x01,\n data: bytesToHex(r.readBytes(RECOVERABLE_ECDSA_SIG_LENGTH_BYTES)),\n });\n }\n }\n const signaturesRequired = r.readUInt16BE();\n\n return { hashMode, signer, nonce, fee, fields, signaturesRequired } as SpendingCondition;\n}\n\nfunction readAuthorization(r: Reader): Authorization {\n const authType = r.readUInt8();\n const spendingCondition = readSpendingCondition(r);\n\n if (authType === AuthType.Standard) {\n return { authType: AuthType.Standard, spendingCondition };\n }\n\n const sponsorSpendingCondition = readSpendingCondition(r);\n return {\n authType: AuthType.Sponsored,\n spendingCondition,\n sponsorSpendingCondition,\n };\n}\n\nfunction readAssetInfo(r: Reader): AssetInfoWire {\n return {\n address: readAddress(r),\n contractName: readLPString(r),\n assetName: readLPString(r),\n };\n}\n\nfunction readPostConditionPrincipal(r: Reader): PostConditionPrincipalWire {\n const type = r.readUInt8();\n switch (type) {\n case PostConditionPrincipalId.Origin:\n return { type: \"origin\" };\n case PostConditionPrincipalId.Standard:\n return { type: \"standard\", address: readAddress(r) };\n case PostConditionPrincipalId.Contract:\n return { type: \"contract\", address: readAddress(r), contractName: readLPString(r) };\n default:\n // Some legacy transactions may have unexpected principal types.\n // Treat as origin to allow deserialization to continue.\n return { type: \"origin\" };\n }\n}\n\nfunction readPostConditions(r: Reader): PostConditionWire[] {\n const count = r.readUInt32BE();\n const pcs: PostConditionWire[] = [];\n for (let i = 0; i < count; i++) {\n // Wire order: asset_type, then principal (per SIP-005 and stacks.js)\n const assetType = r.readUInt8();\n const principal = readPostConditionPrincipal(r);\n switch (assetType) {\n case AssetType.STX:\n pcs.push({ type: \"stx\", principal, conditionCode: r.readUInt8(), amount: r.readBigUInt64BE() });\n break;\n case AssetType.Fungible:\n pcs.push({ type: \"ft\", principal, asset: readAssetInfo(r), conditionCode: r.readUInt8(), amount: r.readBigUInt64BE() });\n break;\n case AssetType.NonFungible:\n pcs.push({ type: \"nft\", principal, asset: readAssetInfo(r), assetId: readCV(r), conditionCode: r.readUInt8() });\n break;\n }\n }\n return pcs;\n}\n\nfunction readPayload(r: Reader): TransactionPayload {\n const payloadType = r.readUInt8();\n\n switch (payloadType) {\n case PayloadType.TokenTransfer: {\n const recipient = readCV(r);\n const amount = r.readBigUInt64BE();\n // Memo is a flat 34-byte field (no length prefix) per SIP-005\n const memoBytes = r.readBytes(MEMO_MAX_LENGTH_BYTES);\n const memo = bytesToAscii(memoBytes).replace(/\\0+$/, \"\");\n return { payloadType: PayloadType.TokenTransfer, recipient, amount, memo };\n }\n case PayloadType.ContractCall: {\n const contractAddress = readAddress(r);\n const contractName = readLPString(r);\n const functionName = readLPString(r);\n const numArgs = r.readUInt32BE();\n const functionArgs: ClarityValue[] = [];\n for (let i = 0; i < numArgs; i++) functionArgs.push(readCV(r));\n return { payloadType: PayloadType.ContractCall, contractAddress, contractName, functionName, functionArgs };\n }\n case PayloadType.SmartContract: {\n const contractName = readLPString(r);\n const codeBody = readLPString(r, 4);\n return { payloadType: PayloadType.SmartContract, contractName, codeBody };\n }\n case PayloadType.VersionedSmartContract: {\n const clarityVersion = r.readUInt8() as ClarityVersion;\n const contractName = readLPString(r);\n const codeBody = readLPString(r, 4);\n return { payloadType: PayloadType.VersionedSmartContract, clarityVersion, contractName, codeBody };\n }\n case PayloadType.Coinbase: {\n const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n return { payloadType: PayloadType.Coinbase, coinbaseBuffer };\n }\n case PayloadType.CoinbaseToAltRecipient: {\n const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n const recipient = readCV(r);\n return { payloadType: PayloadType.CoinbaseToAltRecipient, coinbaseBuffer, recipient };\n }\n case PayloadType.PoisonMicroblock: {\n const header1 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));\n const header2 = bytesToHex(r.readBytes(MICROBLOCK_HEADER_BYTES_LENGTH));\n return { payloadType: PayloadType.PoisonMicroblock, header1, header2 };\n }\n case PayloadType.TenureChange: {\n const tenureConsensusHash = bytesToHex(r.readBytes(20));\n const prevTenureConsensusHash = bytesToHex(r.readBytes(20));\n const burnViewConsensusHash = bytesToHex(r.readBytes(20));\n const previousTenureEnd = bytesToHex(r.readBytes(32));\n const previousTenureBlocks = r.readUInt32BE();\n const cause = r.readUInt8() as TenureChangeCause;\n const pubkeyHash = bytesToHex(r.readBytes(20));\n return {\n payloadType: PayloadType.TenureChange,\n tenureConsensusHash,\n prevTenureConsensusHash,\n burnViewConsensusHash,\n previousTenureEnd,\n previousTenureBlocks,\n cause,\n pubkeyHash,\n };\n }\n case PayloadType.NakamotoCoinbase: {\n const coinbaseBuffer = bytesToHex(r.readBytes(COINBASE_BYTES_LENGTH));\n const optionalCV = readCV(r);\n const recipient = optionalCV.type === \"none\" ? null : optionalCV.type === \"some\" ? optionalCV.value : optionalCV;\n const vrfProof = bytesToHex(r.readBytes(VRF_PROOF_BYTES_LENGTH));\n return { payloadType: PayloadType.NakamotoCoinbase, coinbaseBuffer, recipient, vrfProof };\n }\n default:\n throw new Error(`Unknown payload type: ${payloadType}`);\n }\n}\n\nexport function deserializeTransaction(input: string | Uint8Array): StacksTransaction {\n const bytes = typeof input === \"string\" ? hexToBytes(without0x(input)) : input;\n const r = new Reader(bytes);\n\n return {\n version: r.readUInt8(),\n chainId: r.readUInt32BE(),\n auth: readAuthorization(r),\n anchorMode: r.readUInt8() as Anch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OAAO,KAAK;AAAA,EAE1B,OAAO;AAAA,IACL,SAAS,EAAE,UAAU;AAAA,IACrB,SAAS,EAAE,aAAa;AAAA,IACxB,MAAM,kBAAkB,CAAC;AAAA,IACzB,YAAY,EAAE,UAAU;AAAA,IACxB,mBAAmB,EAAE,UAAU;AAAA,IAC/B,gBAAgB,mBAAmB,CAAC;AAAA,IACpC,SAAS,YAAY,CAAC;AAAA,EACxB;AAAA;",
|
|
8
|
+
"debugId": "876770F5E21209F964756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseContractId,
|
|
3
|
+
validateStacksAddress
|
|
4
|
+
} from "./stacks-s10yb9gz.js";
|
|
5
|
+
import {
|
|
6
|
+
intToBigInt
|
|
7
|
+
} from "./stacks-s7z5q8be.js";
|
|
8
|
+
|
|
9
|
+
// src/postconditions/builder.ts
|
|
10
|
+
class PartialPcWithPrincipal {
|
|
11
|
+
address;
|
|
12
|
+
constructor(address) {
|
|
13
|
+
this.address = address;
|
|
14
|
+
}
|
|
15
|
+
willSendEq(amount) {
|
|
16
|
+
return new PartialPcFtWithCode(this.address, amount, "eq");
|
|
17
|
+
}
|
|
18
|
+
willSendGte(amount) {
|
|
19
|
+
return new PartialPcFtWithCode(this.address, amount, "gte");
|
|
20
|
+
}
|
|
21
|
+
willSendGt(amount) {
|
|
22
|
+
return new PartialPcFtWithCode(this.address, amount, "gt");
|
|
23
|
+
}
|
|
24
|
+
willSendLte(amount) {
|
|
25
|
+
return new PartialPcFtWithCode(this.address, amount, "lte");
|
|
26
|
+
}
|
|
27
|
+
willSendLt(amount) {
|
|
28
|
+
return new PartialPcFtWithCode(this.address, amount, "lt");
|
|
29
|
+
}
|
|
30
|
+
willSendAsset() {
|
|
31
|
+
return new PartialPcNftWithCode(this.address, "sent");
|
|
32
|
+
}
|
|
33
|
+
willNotSendAsset() {
|
|
34
|
+
return new PartialPcNftWithCode(this.address, "not-sent");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class PartialPcFtWithCode {
|
|
39
|
+
address;
|
|
40
|
+
amount;
|
|
41
|
+
code;
|
|
42
|
+
constructor(address, amount, code) {
|
|
43
|
+
this.address = address;
|
|
44
|
+
this.amount = amount;
|
|
45
|
+
this.code = code;
|
|
46
|
+
}
|
|
47
|
+
ustx() {
|
|
48
|
+
return {
|
|
49
|
+
type: "stx-postcondition",
|
|
50
|
+
address: this.address,
|
|
51
|
+
condition: this.code,
|
|
52
|
+
amount: intToBigInt(this.amount).toString()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
ft(contractId, tokenName) {
|
|
56
|
+
const [address, name] = contractId.split(".");
|
|
57
|
+
if (!address || !validateStacksAddress(address) || !name) {
|
|
58
|
+
throw new Error(`Invalid contract id: ${contractId}`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
type: "ft-postcondition",
|
|
62
|
+
address: this.address,
|
|
63
|
+
condition: this.code,
|
|
64
|
+
amount: intToBigInt(this.amount).toString(),
|
|
65
|
+
asset: `${contractId}::${tokenName}`
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class PartialPcNftWithCode {
|
|
71
|
+
address;
|
|
72
|
+
code;
|
|
73
|
+
constructor(address, code) {
|
|
74
|
+
this.address = address;
|
|
75
|
+
this.code = code;
|
|
76
|
+
}
|
|
77
|
+
nft(assetOrContractId, tokenNameOrAssetId, assetId) {
|
|
78
|
+
let contractAddress;
|
|
79
|
+
let contractName;
|
|
80
|
+
let tokenName;
|
|
81
|
+
let id;
|
|
82
|
+
if (assetId !== undefined) {
|
|
83
|
+
[contractAddress, contractName] = parseContractId(assetOrContractId);
|
|
84
|
+
tokenName = tokenNameOrAssetId;
|
|
85
|
+
id = assetId;
|
|
86
|
+
} else {
|
|
87
|
+
const [principal, tName] = assetOrContractId.split("::");
|
|
88
|
+
if (!principal || !tName)
|
|
89
|
+
throw new Error(`Invalid asset name: ${assetOrContractId}`);
|
|
90
|
+
[contractAddress, contractName] = parseContractId(principal);
|
|
91
|
+
tokenName = tName;
|
|
92
|
+
id = tokenNameOrAssetId;
|
|
93
|
+
}
|
|
94
|
+
if (!validateStacksAddress(contractAddress)) {
|
|
95
|
+
throw new Error(`Invalid contract address: ${contractAddress}`);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
type: "nft-postcondition",
|
|
99
|
+
address: this.address,
|
|
100
|
+
condition: this.code,
|
|
101
|
+
asset: `${contractAddress}.${contractName}::${tokenName}`,
|
|
102
|
+
assetId: id
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
var Pc = {
|
|
107
|
+
principal(address) {
|
|
108
|
+
const [addr, name] = address.split(".");
|
|
109
|
+
if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
|
|
110
|
+
throw new Error(`Invalid principal: ${address}`);
|
|
111
|
+
}
|
|
112
|
+
return new PartialPcWithPrincipal(address);
|
|
113
|
+
},
|
|
114
|
+
origin() {
|
|
115
|
+
return new PartialPcWithPrincipal("origin");
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
export { Pc };
|
|
119
|
+
|
|
120
|
+
//# debugId=A955F701F76F44AE64756E2164756E21
|
|
121
|
+
//# sourceMappingURL=stacks-je937aas.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/postconditions/builder.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { intToBigInt, type IntegerType } from \"../utils/encoding.ts\";\nimport { validateStacksAddress, parseContractId } from \"../utils/address.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type {\n StxPostCondition,\n FtPostCondition,\n NftPostCondition,\n FungibleComparator,\n NonFungibleComparator,\n} from \"./types.ts\";\n\nclass PartialPcWithPrincipal {\n constructor(private address: string) {}\n\n willSendEq(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"eq\");\n }\n willSendGte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gte\");\n }\n willSendGt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"gt\");\n }\n willSendLte(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lte\");\n }\n willSendLt(amount: IntegerType) {\n return new PartialPcFtWithCode(this.address, amount, \"lt\");\n }\n willSendAsset() {\n return new PartialPcNftWithCode(this.address, \"sent\");\n }\n willNotSendAsset() {\n return new PartialPcNftWithCode(this.address, \"not-sent\");\n }\n}\n\nclass PartialPcFtWithCode {\n constructor(\n private address: string,\n private amount: IntegerType,\n private code: FungibleComparator\n ) {}\n\n ustx(): StxPostCondition {\n return {\n type: \"stx-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n };\n }\n\n ft(contractId: string, tokenName: string): FtPostCondition {\n const [address, name] = contractId.split(\".\");\n if (!address || !validateStacksAddress(address) || !name) {\n throw new Error(`Invalid contract id: ${contractId}`);\n }\n return {\n type: \"ft-postcondition\",\n address: this.address,\n condition: this.code,\n amount: intToBigInt(this.amount).toString(),\n asset: `${contractId}::${tokenName}`,\n };\n }\n}\n\nclass PartialPcNftWithCode {\n constructor(\n private address: string,\n private code: NonFungibleComparator\n ) {}\n\n nft(assetOrContractId: string, tokenNameOrAssetId: string | ClarityValue, assetId?: ClarityValue): NftPostCondition {\n let contractAddress: string;\n let contractName: string;\n let tokenName: string;\n let id: ClarityValue;\n\n if (assetId !== undefined) {\n // 3 args: contractId, tokenName, assetId\n [contractAddress, contractName] = parseContractId(assetOrContractId);\n tokenName = tokenNameOrAssetId as string;\n id = assetId;\n } else {\n // 2 args: assetString (addr.contract::token), assetId\n const [principal, tName] = assetOrContractId.split(\"::\");\n if (!principal || !tName) throw new Error(`Invalid asset name: ${assetOrContractId}`);\n [contractAddress, contractName] = parseContractId(principal);\n tokenName = tName;\n id = tokenNameOrAssetId as ClarityValue;\n }\n\n if (!validateStacksAddress(contractAddress)) {\n throw new Error(`Invalid contract address: ${contractAddress}`);\n }\n\n return {\n type: \"nft-postcondition\",\n address: this.address,\n condition: this.code,\n asset: `${contractAddress}.${contractName}::${tokenName}`,\n assetId: id,\n };\n }\n}\n\nexport const Pc = {\n principal(address: string) {\n const [addr, name] = address.split(\".\");\n if (!addr || !validateStacksAddress(addr) || (typeof name === \"string\" && !name)) {\n throw new Error(`Invalid principal: ${address}`);\n }\n return new PartialPcWithPrincipal(address);\n },\n origin() {\n return new PartialPcWithPrincipal(\"origin\");\n },\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;AAWA,MAAM,uBAAuB;AAAA,EACP;AAAA,EAApB,WAAW,CAAS,SAAiB;AAAA,IAAjB;AAAA;AAAA,EAEpB,UAAU,CAAC,QAAqB;AAAA,IAC9B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE3D,WAAW,CAAC,QAAqB;AAAA,IAC/B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,KAAK;AAAA;AAAA,EAE5D,UAAU,CAAC,QAAqB;AAAA,IAC9B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE3D,WAAW,CAAC,QAAqB;AAAA,IAC/B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,KAAK;AAAA;AAAA,EAE5D,UAAU,CAAC,QAAqB;AAAA,IAC9B,OAAO,IAAI,oBAAoB,KAAK,SAAS,QAAQ,IAAI;AAAA;AAAA,EAE3D,aAAa,GAAG;AAAA,IACd,OAAO,IAAI,qBAAqB,KAAK,SAAS,MAAM;AAAA;AAAA,EAEtD,gBAAgB,GAAG;AAAA,IACjB,OAAO,IAAI,qBAAqB,KAAK,SAAS,UAAU;AAAA;AAE5D;AAAA;AAEA,MAAM,oBAAoB;AAAA,EAEd;AA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AAAA,MAC3D,YAAY;AAAA,MACZ,KAAK;AAAA;AAAA,IAGP,IAAI,CAAC,sBAAsB,eAAe,GAAG;AAAA,MAC3C,MAAM,IAAI,MAAM,6BAA6B,iBAAiB;AAAA,IAChE;AAAA,IAEA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS,KAAK;AAAA,MACd,WAAW,KAAK;AAAA,MAChB,OAAO,GAAG,mBAAmB,iBAAiB;AAAA,MAC9C,SAAS;AAAA,IACX;AAAA;AAEJ;AAEO,IAAM,KAAK;AAAA,EAChB,SAAS,CAAC,SAAiB;AAAA,IACzB,OAAO,MAAM,QAAQ,QAAQ,MAAM,GAAG;AAAA,IACtC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,IAAI,KAAM,OAAO,SAAS,YAAY,CAAC,MAAO;AAAA,MAChF,MAAM,IAAI,MAAM,sBAAsB,SAAS;AAAA,IACjD;AAAA,IACA,OAAO,IAAI,uBAAuB,OAAO;AAAA;AAAA,EAE3C,MAAM,GAAG;AAAA,IACP,OAAO,IAAI,uBAAuB,QAAQ;AAAA;AAE9C;",
|
|
8
|
+
"debugId": "A955F701F76F44AE64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isAbiBuffer,
|
|
3
|
+
isAbiList,
|
|
4
|
+
isAbiOptional,
|
|
5
|
+
isAbiResponse,
|
|
6
|
+
isAbiStringAscii,
|
|
7
|
+
isAbiStringUtf8,
|
|
8
|
+
isAbiTuple,
|
|
9
|
+
isBool,
|
|
10
|
+
isInt128,
|
|
11
|
+
isPrincipal,
|
|
12
|
+
isString,
|
|
13
|
+
isUint128,
|
|
14
|
+
isUint8Array,
|
|
15
|
+
toCamelCase
|
|
16
|
+
} from "./stacks-p93g814f.js";
|
|
17
|
+
import {
|
|
18
|
+
asciiToBytes,
|
|
19
|
+
bytesToAscii,
|
|
20
|
+
hexToBytes,
|
|
21
|
+
utf8ToBytes
|
|
22
|
+
} from "./stacks-s7z5q8be.js";
|
|
23
|
+
// src/clarity/prettyPrint.ts
|
|
24
|
+
function prettyPrint(val, encoding = "hex") {
|
|
25
|
+
switch (val.type) {
|
|
26
|
+
case "true":
|
|
27
|
+
return "true";
|
|
28
|
+
case "false":
|
|
29
|
+
return "false";
|
|
30
|
+
case "int":
|
|
31
|
+
return val.value.toString();
|
|
32
|
+
case "uint":
|
|
33
|
+
return `u${val.value.toString()}`;
|
|
34
|
+
case "buffer":
|
|
35
|
+
if (encoding === "tryAscii") {
|
|
36
|
+
const str = bytesToAscii(hexToBytes(val.value));
|
|
37
|
+
if (/^[ -~]*$/.test(str))
|
|
38
|
+
return JSON.stringify(str);
|
|
39
|
+
}
|
|
40
|
+
return `0x${val.value}`;
|
|
41
|
+
case "none":
|
|
42
|
+
return "none";
|
|
43
|
+
case "some":
|
|
44
|
+
return `(some ${prettyPrint(val.value, encoding)})`;
|
|
45
|
+
case "ok":
|
|
46
|
+
return `(ok ${prettyPrint(val.value, encoding)})`;
|
|
47
|
+
case "err":
|
|
48
|
+
return `(err ${prettyPrint(val.value, encoding)})`;
|
|
49
|
+
case "address":
|
|
50
|
+
case "contract":
|
|
51
|
+
return val.value;
|
|
52
|
+
case "list":
|
|
53
|
+
return `(list ${val.value.map((v) => prettyPrint(v, encoding)).join(" ")})`;
|
|
54
|
+
case "tuple":
|
|
55
|
+
return `(tuple ${Object.keys(val.value).map((key) => `(${key} ${prettyPrint(val.value[key], encoding)})`).join(" ")})`;
|
|
56
|
+
case "ascii":
|
|
57
|
+
return `"${val.value}"`;
|
|
58
|
+
case "utf8":
|
|
59
|
+
return `u"${val.value}"`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function cvToJSON(val) {
|
|
63
|
+
switch (val.type) {
|
|
64
|
+
case "true":
|
|
65
|
+
return { type: "bool", value: true };
|
|
66
|
+
case "false":
|
|
67
|
+
return { type: "bool", value: false };
|
|
68
|
+
case "int":
|
|
69
|
+
return { type: "int", value: val.value.toString() };
|
|
70
|
+
case "uint":
|
|
71
|
+
return { type: "uint", value: val.value.toString() };
|
|
72
|
+
case "buffer":
|
|
73
|
+
return { type: `(buff ${Math.ceil(val.value.length / 2)})`, value: `0x${val.value}` };
|
|
74
|
+
case "none":
|
|
75
|
+
return { type: "(optional none)", value: null };
|
|
76
|
+
case "some":
|
|
77
|
+
return { type: `(optional)`, value: cvToJSON(val.value) };
|
|
78
|
+
case "ok":
|
|
79
|
+
return { type: "(response)", value: cvToJSON(val.value), success: true };
|
|
80
|
+
case "err":
|
|
81
|
+
return { type: "(response)", value: cvToJSON(val.value), success: false };
|
|
82
|
+
case "address":
|
|
83
|
+
case "contract":
|
|
84
|
+
return { type: "principal", value: val.value };
|
|
85
|
+
case "list":
|
|
86
|
+
return { type: "(list)", value: val.value.map(cvToJSON) };
|
|
87
|
+
case "tuple": {
|
|
88
|
+
const result = {};
|
|
89
|
+
for (const key of Object.keys(val.value)) {
|
|
90
|
+
result[key] = cvToJSON(val.value[key]);
|
|
91
|
+
}
|
|
92
|
+
return { type: "(tuple)", value: result };
|
|
93
|
+
}
|
|
94
|
+
case "ascii":
|
|
95
|
+
return { type: `(string-ascii ${asciiToBytes(val.value).length})`, value: val.value };
|
|
96
|
+
case "utf8":
|
|
97
|
+
return { type: `(string-utf8 ${utf8ToBytes(val.value).length})`, value: val.value };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function cvToValue(val) {
|
|
101
|
+
switch (val.type) {
|
|
102
|
+
case "true":
|
|
103
|
+
return true;
|
|
104
|
+
case "false":
|
|
105
|
+
return false;
|
|
106
|
+
case "int":
|
|
107
|
+
case "uint":
|
|
108
|
+
return val.value;
|
|
109
|
+
case "buffer":
|
|
110
|
+
return `0x${val.value}`;
|
|
111
|
+
case "none":
|
|
112
|
+
return null;
|
|
113
|
+
case "some":
|
|
114
|
+
return cvToValue(val.value);
|
|
115
|
+
case "ok":
|
|
116
|
+
case "err":
|
|
117
|
+
return cvToValue(val.value);
|
|
118
|
+
case "address":
|
|
119
|
+
case "contract":
|
|
120
|
+
return val.value;
|
|
121
|
+
case "list":
|
|
122
|
+
return val.value.map(cvToValue);
|
|
123
|
+
case "tuple": {
|
|
124
|
+
const result = {};
|
|
125
|
+
for (const key of Object.keys(val.value)) {
|
|
126
|
+
result[key] = cvToValue(val.value[key]);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
case "ascii":
|
|
131
|
+
case "utf8":
|
|
132
|
+
return val.value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// src/clarity/abi/converters.ts
|
|
136
|
+
class ClarityConversionError extends Error {
|
|
137
|
+
type;
|
|
138
|
+
value;
|
|
139
|
+
constructor(message, type, value) {
|
|
140
|
+
super(message);
|
|
141
|
+
this.type = type;
|
|
142
|
+
this.value = value;
|
|
143
|
+
this.name = "ClarityConversionError";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function jsToClarity(type, value) {
|
|
147
|
+
if (type === "none")
|
|
148
|
+
return null;
|
|
149
|
+
if (type === "uint128") {
|
|
150
|
+
if (!isUint128(value))
|
|
151
|
+
throw new ClarityConversionError("Invalid uint128 value", type, value);
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
if (type === "int128") {
|
|
155
|
+
if (!isInt128(value))
|
|
156
|
+
throw new ClarityConversionError("Invalid int128 value", type, value);
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
if (type === "bool") {
|
|
160
|
+
if (!isBool(value))
|
|
161
|
+
throw new ClarityConversionError("Invalid bool value", type, value);
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
if (type === "principal") {
|
|
165
|
+
if (!isPrincipal(value))
|
|
166
|
+
throw new ClarityConversionError("Invalid principal value", type, value);
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
if (type === "trait_reference") {
|
|
170
|
+
if (!isPrincipal(value))
|
|
171
|
+
throw new ClarityConversionError("Invalid trait_reference value", type, value);
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
if (isAbiStringAscii(type)) {
|
|
175
|
+
if (!isString(value))
|
|
176
|
+
throw new ClarityConversionError("Invalid string-ascii value", type, value);
|
|
177
|
+
const str = value;
|
|
178
|
+
for (let i = 0;i < str.length; i++) {
|
|
179
|
+
if (str.charCodeAt(i) > 127) {
|
|
180
|
+
throw new ClarityConversionError(`Non-ASCII character at position ${i}: '${str[i]}' (code ${str.charCodeAt(i)})`, type, value);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (str.length > type["string-ascii"].length) {
|
|
184
|
+
throw new ClarityConversionError(`String length ${str.length} exceeds max ${type["string-ascii"].length}`, type, value);
|
|
185
|
+
}
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
if (isAbiStringUtf8(type)) {
|
|
189
|
+
if (!isString(value))
|
|
190
|
+
throw new ClarityConversionError("Invalid string-utf8 value", type, value);
|
|
191
|
+
const str = value;
|
|
192
|
+
const byteLength = new TextEncoder().encode(str).length;
|
|
193
|
+
if (byteLength > type["string-utf8"].length) {
|
|
194
|
+
throw new ClarityConversionError(`String byte length ${byteLength} exceeds max ${type["string-utf8"].length}`, type, value);
|
|
195
|
+
}
|
|
196
|
+
return value;
|
|
197
|
+
}
|
|
198
|
+
if (isAbiBuffer(type)) {
|
|
199
|
+
if (!isUint8Array(value))
|
|
200
|
+
throw new ClarityConversionError("Invalid buffer value", type, value);
|
|
201
|
+
const buff = value;
|
|
202
|
+
if (buff.length > type.buff.length) {
|
|
203
|
+
throw new ClarityConversionError(`Buffer length ${buff.length} exceeds max ${type.buff.length}`, type, value);
|
|
204
|
+
}
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
if (isAbiList(type)) {
|
|
208
|
+
if (!Array.isArray(value))
|
|
209
|
+
throw new ClarityConversionError("Expected array for list type", type, value);
|
|
210
|
+
if (value.length > type.list.length) {
|
|
211
|
+
throw new ClarityConversionError(`List length ${value.length} exceeds max ${type.list.length}`, type, value);
|
|
212
|
+
}
|
|
213
|
+
return value.map((item) => jsToClarity(type.list.type, item));
|
|
214
|
+
}
|
|
215
|
+
if (isAbiTuple(type)) {
|
|
216
|
+
if (typeof value !== "object" || value === null)
|
|
217
|
+
throw new ClarityConversionError("Expected object for tuple type", type, value);
|
|
218
|
+
const result = {};
|
|
219
|
+
for (const field of type.tuple) {
|
|
220
|
+
const camelKey = toCamelCase(field.name);
|
|
221
|
+
const hasOriginal = field.name in value;
|
|
222
|
+
const hasCamel = camelKey in value;
|
|
223
|
+
if (!hasOriginal && !hasCamel) {
|
|
224
|
+
throw new ClarityConversionError(`Missing tuple field: ${field.name}`, type, value);
|
|
225
|
+
}
|
|
226
|
+
const fieldValue = hasOriginal ? value[field.name] : value[camelKey];
|
|
227
|
+
result[field.name] = jsToClarity(field.type, fieldValue);
|
|
228
|
+
}
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
if (isAbiOptional(type)) {
|
|
232
|
+
if (value === null || value === undefined)
|
|
233
|
+
return null;
|
|
234
|
+
return jsToClarity(type.optional, value);
|
|
235
|
+
}
|
|
236
|
+
if (isAbiResponse(type)) {
|
|
237
|
+
if (typeof value !== "object" || value === null)
|
|
238
|
+
throw new ClarityConversionError("Expected object for response type", type, value);
|
|
239
|
+
const hasOk = "ok" in value;
|
|
240
|
+
const hasErr = "err" in value;
|
|
241
|
+
if (hasOk && !hasErr) {
|
|
242
|
+
return {
|
|
243
|
+
ok: jsToClarity(type.response.ok, value.ok)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (hasErr && !hasOk) {
|
|
247
|
+
return {
|
|
248
|
+
err: jsToClarity(type.response.error, value.err)
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
throw new ClarityConversionError("Response must have exactly 'ok' or 'err' property", type, value);
|
|
252
|
+
}
|
|
253
|
+
throw new ClarityConversionError(`Unknown Clarity type`, type, value);
|
|
254
|
+
}
|
|
255
|
+
function prepareArgs(func, args) {
|
|
256
|
+
return func.args.map((arg) => {
|
|
257
|
+
if (!(arg.name in args)) {
|
|
258
|
+
throw new ClarityConversionError(`Missing argument: ${arg.name}`, arg.type, undefined);
|
|
259
|
+
}
|
|
260
|
+
return jsToClarity(arg.type, args[arg.name]);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function validateArgs(func, args) {
|
|
264
|
+
for (const arg of func.args) {
|
|
265
|
+
if (!(arg.name in args)) {
|
|
266
|
+
throw new ClarityConversionError(`Missing argument: ${arg.name}`, arg.type, undefined);
|
|
267
|
+
}
|
|
268
|
+
jsToClarity(arg.type, args[arg.name]);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function validateArgsArray(func, args) {
|
|
272
|
+
if (args.length !== func.args.length) {
|
|
273
|
+
throw new ClarityConversionError(`Expected ${func.args.length} arguments, got ${args.length}`, func.args[0]?.type ?? "bool", args);
|
|
274
|
+
}
|
|
275
|
+
func.args.forEach((arg, i) => {
|
|
276
|
+
jsToClarity(arg.type, args[i]);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
export { prettyPrint, cvToJSON, cvToValue, ClarityConversionError, jsToClarity, prepareArgs, validateArgs, validateArgsArray };
|
|
280
|
+
|
|
281
|
+
//# debugId=DAD8B8065D272C2164756E2164756E21
|
|
282
|
+
//# sourceMappingURL=stacks-jrnmh4kc.js.map
|