@secondlayer/stacks 2.10.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/shared/{stacks-4t2vmp4y.js → stacks-01pbr7gf.js} +17 -16
- package/dist/shared/stacks-01pbr7gf.js.map +11 -0
- package/dist/shared/{stacks-wyxj879g.cjs → stacks-18jv9aen.js} +83 -4
- package/dist/shared/stacks-18jv9aen.js.map +13 -0
- package/dist/shared/{stacks-0zysn74p.js → stacks-2mm20wqf.js} +3 -3
- package/dist/shared/{stacks-hxm7r5ay.cjs → stacks-44y18a8e.cjs} +3 -10
- package/dist/shared/stacks-44y18a8e.cjs.map +10 -0
- package/dist/shared/{stacks-2dhf79w5.js → stacks-59xy6t1p.js} +33 -31
- package/dist/shared/{stacks-2dhf79w5.js.map → stacks-59xy6t1p.js.map} +6 -6
- package/dist/shared/{stacks-99ghanwx.js → stacks-6n2m9hyk.js} +56 -6
- package/dist/shared/stacks-6n2m9hyk.js.map +10 -0
- package/dist/shared/{stacks-g7ffp8aj.js → stacks-6xt8py97.cjs} +59 -30
- package/dist/shared/stacks-6xt8py97.cjs.map +13 -0
- package/dist/shared/stacks-azp00pve.js +70 -0
- package/dist/shared/stacks-azp00pve.js.map +11 -0
- package/dist/shared/{stacks-vk8fwz0t.cjs → stacks-b9904rc2.cjs} +3 -2
- package/dist/shared/{stacks-vk8fwz0t.cjs.map → stacks-b9904rc2.cjs.map} +2 -2
- package/dist/shared/stacks-esn3wcw5.cjs +416 -0
- package/dist/shared/stacks-esn3wcw5.cjs.map +18 -0
- package/dist/shared/{stacks-3y058qda.cjs → stacks-fhzwsn5d.cjs} +16 -2
- package/dist/shared/{stacks-3y058qda.cjs.map → stacks-fhzwsn5d.cjs.map} +5 -4
- package/dist/shared/{stacks-e60vrr34.js → stacks-g11v9a35.js} +4 -4
- package/dist/shared/{stacks-0ek3cyt8.js → stacks-g67f4w1d.js} +7 -14
- package/dist/shared/stacks-g67f4w1d.js.map +10 -0
- package/dist/shared/{stacks-6xmk24yw.js → stacks-gfm3r397.cjs} +20 -7
- package/dist/shared/stacks-gfm3r397.cjs.map +11 -0
- package/dist/shared/{stacks-43cxvnr7.js → stacks-jbmcwky5.js} +3 -3
- package/dist/shared/stacks-kjg7fw4y.js +434 -0
- package/dist/shared/stacks-kjg7fw4y.js.map +18 -0
- package/dist/shared/{stacks-q1mjkt15.js → stacks-msmgyerb.js} +4 -4
- package/dist/shared/{stacks-2h8d2y27.js → stacks-qs5fzts5.js} +17 -3
- package/dist/shared/{stacks-2h8d2y27.js.map → stacks-qs5fzts5.js.map} +5 -4
- package/dist/shared/{stacks-xw0j252s.cjs → stacks-shn9zw99.cjs} +43 -3
- package/dist/shared/stacks-shn9zw99.cjs.map +10 -0
- package/dist/shared/{stacks-vf0ekgwb.js → stacks-ssndnbbd.js} +8 -10
- package/dist/shared/{stacks-vf0ekgwb.js.map → stacks-ssndnbbd.js.map} +2 -2
- package/dist/shared/{stacks-maamjqma.cjs → stacks-tbv5p6pn.cjs} +7 -9
- package/dist/shared/stacks-tbv5p6pn.cjs.map +11 -0
- package/dist/shared/{stacks-a36n7sjz.js → stacks-x94a1d6s.js} +3 -3
- package/dist/shared/{stacks-k5an9zcw.cjs → stacks-y5epf0sb.cjs} +19 -22
- package/dist/shared/{stacks-k5an9zcw.cjs.map → stacks-y5epf0sb.cjs.map} +6 -6
- package/dist/src/accounts/index.js +3 -5
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +8 -1
- package/dist/src/actions/index.cjs.map +1 -1
- package/dist/src/actions/index.d.cts +198 -13
- package/dist/src/actions/index.d.ts +198 -13
- package/dist/src/actions/index.js +29 -17
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.js +8 -11
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.js +12 -14
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/clarity/index.d.cts +50 -1
- package/dist/src/clarity/index.d.ts +50 -1
- package/dist/src/clarity/index.js +8 -7
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/index.cjs +10 -1
- package/dist/src/index.cjs.map +3 -3
- package/dist/src/index.d.cts +167 -9
- package/dist/src/index.d.ts +167 -9
- package/dist/src/index.js +30 -17
- package/dist/src/index.js.map +3 -3
- package/dist/src/postconditions/index.js +3 -3
- package/dist/src/pox/index.js +11 -13
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/sbtc/index.js +10 -12
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +11 -13
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/index.cjs +348 -63
- package/dist/src/tools/index.cjs.map +18 -15
- package/dist/src/tools/index.js +348 -63
- package/dist/src/tools/index.js.map +18 -15
- package/dist/src/transactions/index.js +6 -7
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.cjs +2 -1
- package/dist/src/utils/index.cjs.map +2 -2
- package/dist/src/utils/index.d.cts +5 -1
- package/dist/src/utils/index.d.ts +5 -1
- package/dist/src/utils/index.js +12 -14
- package/dist/src/utils/index.js.map +2 -2
- package/dist/src/x402/index.cjs +5 -2
- package/dist/src/x402/index.cjs.map +3 -3
- package/dist/src/x402/index.d.cts +36 -0
- package/dist/src/x402/index.d.ts +36 -0
- package/dist/src/x402/index.js +13 -11
- package/dist/src/x402/index.js.map +3 -3
- package/package.json +1 -1
- package/dist/shared/stacks-0ek3cyt8.js.map +0 -10
- package/dist/shared/stacks-4t2vmp4y.js.map +0 -11
- package/dist/shared/stacks-6xmk24yw.js.map +0 -10
- package/dist/shared/stacks-99ghanwx.js.map +0 -10
- package/dist/shared/stacks-9g0jhab3.cjs +0 -40
- package/dist/shared/stacks-9g0jhab3.cjs.map +0 -10
- package/dist/shared/stacks-9t68zmpn.js +0 -210
- package/dist/shared/stacks-9t68zmpn.js.map +0 -15
- package/dist/shared/stacks-fcaefc5b.cjs +0 -16
- package/dist/shared/stacks-fcaefc5b.cjs.map +0 -10
- package/dist/shared/stacks-g7ffp8aj.js.map +0 -13
- package/dist/shared/stacks-hxm7r5ay.cjs.map +0 -10
- package/dist/shared/stacks-maamjqma.cjs.map +0 -11
- package/dist/shared/stacks-v9jqcpd4.js +0 -18
- package/dist/shared/stacks-v9jqcpd4.js.map +0 -10
- package/dist/shared/stacks-wyxj879g.cjs.map +0 -13
- package/dist/shared/stacks-xmsms921.cjs +0 -196
- package/dist/shared/stacks-xmsms921.cjs.map +0 -15
- package/dist/shared/stacks-xw0j252s.cjs.map +0 -10
- package/dist/shared/stacks-xxn5ma6g.js +0 -22
- package/dist/shared/stacks-xxn5ma6g.js.map +0 -10
- package/dist/shared/stacks-ya3x01yd.cjs +0 -16
- package/dist/shared/stacks-ya3x01yd.cjs.map +0 -10
- /package/dist/shared/{stacks-0zysn74p.js.map → stacks-2mm20wqf.js.map} +0 -0
- /package/dist/shared/{stacks-e60vrr34.js.map → stacks-g11v9a35.js.map} +0 -0
- /package/dist/shared/{stacks-43cxvnr7.js.map → stacks-jbmcwky5.js.map} +0 -0
- /package/dist/shared/{stacks-q1mjkt15.js.map → stacks-msmgyerb.js.map} +0 -0
- /package/dist/shared/{stacks-a36n7sjz.js.map → stacks-x94a1d6s.js.map} +0 -0
package/README.md
CHANGED
|
@@ -58,6 +58,30 @@ multi-broadcast gap, which is why it lives here rather than being deferred to
|
|
|
58
58
|
| `@secondlayer/stacks/pox` | PoX stacking — solo and delegated |
|
|
59
59
|
| `@secondlayer/stacks/stackingdao` | StackingDAO liquid staking (STX/stSTX) |
|
|
60
60
|
|
|
61
|
+
## Fee tiers
|
|
62
|
+
|
|
63
|
+
Every send action takes `fee` as an exact amount **or a named tier** — `'min' | 'low' | 'mid' | 'high'`. Tiers map to the node's three estimations; `'min'` is the minimum relay fee (1 uSTX per serialized byte), computed offline with no round-trip. Omitting `fee` estimates mid, and if the node can't produce an estimate (`NoEstimateAvailable`), the SDK falls back to `'min'` instead of failing.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
await client.transferStx({ to, amount: 1000n, fee: "low" });
|
|
67
|
+
await client.callContract({ contract, functionName: "mint", fee: "min" });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Wait for confirmation
|
|
71
|
+
|
|
72
|
+
`waitForTransactionReceipt` polls until a transaction is mined (optionally N confirmations deep) and returns a normalized receipt with the decoded Clarity result. It rejects with typed errors when the tx aborts (`TransactionAbortedError`, receipt attached), drops from the mempool (`TransactionDroppedError`), or times out — and it re-reads block placement every cycle, so reorgs don't strand the wait.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const { txid } = await client.callContract({ contract, functionName: "mint" });
|
|
76
|
+
const receipt = await client.waitForTransactionReceipt({ txid, confirmations: 2 });
|
|
77
|
+
receipt.result; // decoded ClarityValue
|
|
78
|
+
|
|
79
|
+
// or in one step:
|
|
80
|
+
const { receipt } = await sendTransaction(client, { transaction, wait: 2 });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Status reads are pluggable, like nonce sources: the default reads `/extended/v1/tx` on your transport host; `indexTxSource()` reads Secondlayer's index, which returns the chain tip in the same response — N-confirmation waits cost one request per poll. Rejection reasons are typed too: `BroadcastError.reason` is a literal union of all 26 stacks-node rejection strings (with `reasonData` and `txid` attached).
|
|
84
|
+
|
|
61
85
|
## Nonce management
|
|
62
86
|
|
|
63
87
|
Stacks' `/v2/accounts` returns only the confirmed nonce — it ignores the mempool. Broadcasting several transactions from one account before the first confirms makes them reuse the same nonce, so every one after the first is rejected (`ConflictingNonceInMempool`). The usual workaround is tracking nonces by hand.
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assertNoFeeTierForProvider,
|
|
2
3
|
broadcastWithNonceReset,
|
|
3
|
-
|
|
4
|
+
isFeeTier,
|
|
4
5
|
isProviderAccount,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
resolveFee,
|
|
7
|
+
resolveNonce,
|
|
8
|
+
setUnsignedFee
|
|
9
|
+
} from "./stacks-kjg7fw4y.js";
|
|
7
10
|
import {
|
|
8
11
|
buildContractCall,
|
|
9
12
|
signTransactionWithAccount
|
|
10
|
-
} from "./stacks-
|
|
13
|
+
} from "./stacks-ssndnbbd.js";
|
|
11
14
|
import {
|
|
12
15
|
deserializeCVBytes,
|
|
13
16
|
serializeCVBytes
|
|
14
|
-
} from "./stacks-
|
|
17
|
+
} from "./stacks-2mm20wqf.js";
|
|
15
18
|
import {
|
|
16
19
|
parseContractId
|
|
17
|
-
} from "./stacks-
|
|
20
|
+
} from "./stacks-azp00pve.js";
|
|
18
21
|
import {
|
|
19
22
|
bytesToHex,
|
|
20
23
|
with0x
|
|
21
|
-
} from "./stacks-
|
|
24
|
+
} from "./stacks-qs5fzts5.js";
|
|
22
25
|
|
|
23
26
|
// src/actions/public/getMapEntry.ts
|
|
24
27
|
async function getMapEntry(client, params) {
|
|
@@ -38,6 +41,7 @@ async function callContract(client, params) {
|
|
|
38
41
|
throw new Error("Account required");
|
|
39
42
|
const [contractAddress, contractName] = parseContractId(params.contract);
|
|
40
43
|
if (isProviderAccount(account)) {
|
|
44
|
+
assertNoFeeTierForProvider(params.fee);
|
|
41
45
|
const result = await account.provider.request("stx_callContract", {
|
|
42
46
|
contract: params.contract,
|
|
43
47
|
functionName: params.functionName,
|
|
@@ -46,24 +50,21 @@ async function callContract(client, params) {
|
|
|
46
50
|
return result.txid;
|
|
47
51
|
}
|
|
48
52
|
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
53
|
+
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
49
54
|
const unsigned = buildContractCall({
|
|
50
55
|
contractAddress,
|
|
51
56
|
contractName,
|
|
52
57
|
functionName: params.functionName,
|
|
53
58
|
functionArgs: params.functionArgs ?? [],
|
|
54
|
-
fee: params.fee
|
|
59
|
+
fee: needsFeeResolution ? 0n : params.fee,
|
|
55
60
|
nonce,
|
|
56
61
|
publicKey: account.publicKey,
|
|
57
62
|
chain: client.chain,
|
|
58
63
|
postConditionMode: params.postConditionMode,
|
|
59
64
|
postConditions: params.postConditions
|
|
60
65
|
});
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
const mid = estimates[1] ?? estimates[0];
|
|
64
|
-
if (mid) {
|
|
65
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
66
|
-
}
|
|
66
|
+
if (needsFeeResolution) {
|
|
67
|
+
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
67
68
|
}
|
|
68
69
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
69
70
|
return broadcastWithNonceReset(client, {
|
|
@@ -74,5 +75,5 @@ async function callContract(client, params) {
|
|
|
74
75
|
|
|
75
76
|
export { getMapEntry, callContract };
|
|
76
77
|
|
|
77
|
-
//# debugId=
|
|
78
|
-
//# sourceMappingURL=stacks-
|
|
78
|
+
//# debugId=4BCB4DDE739B706C64756E2164756E21
|
|
79
|
+
//# sourceMappingURL=stacks-01pbr7gf.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
|
|
6
|
+
"import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractCall } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
|
|
7
|
+
],
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,eAAsB,WAAkD,CACvE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,gBAAgB,OAAO,WAAW,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,EAErE,MAAM,OAAO,MAAM,OAAO,QACzB,iBAAiB,WAAW,QAAQ,OAAO,WAC3C;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CACD;AAAA,EAEA,OAAO,mBAAsB,KAAK,IAAI;AAAA;;;ACAvC,eAAsB,YAAY,CACjC,QACA,QACkB;AAAA,EAClB,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAIhD,OAAO,iBAAiB,gBAAgB,gBAAgB,OAAO,QAAQ;AAAA,EAGvE,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,2BAA2B,OAAO,GAAG;AAAA,IACrC,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,oBAAoB;AAAA,MACjE,UAAU,OAAO;AAAA,MACjB,cAAc,OAAO;AAAA,MACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACvC,CAAC;AAAA,IACD,OAAO,OAAO;AAAA,EACf;AAAA,EAGA,MAAM,QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,qBAAqB,OAAO,QAAQ,aAAa,UAAU,OAAO,GAAG;AAAA,EAE3E,MAAM,WAAW,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,cAAc,OAAO;AAAA,IACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACtC,KAAK,qBAAqB,KAAM,OAAO;AAAA,IACvC;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,oBAAoB;AAAA,IACvB,eAAe,UAAU,MAAM,WAAW,QAAQ,UAAU,OAAO,GAAG,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
|
|
9
|
+
"debugId": "4BCB4DDE739B706C64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cl,
|
|
3
|
+
boolCV,
|
|
4
|
+
bufferCV,
|
|
5
|
+
intCV,
|
|
6
|
+
listCV,
|
|
7
|
+
noneCV,
|
|
8
|
+
responseErrorCV,
|
|
9
|
+
responseOkCV,
|
|
10
|
+
someCV,
|
|
11
|
+
stringAsciiCV,
|
|
12
|
+
stringUtf8CV,
|
|
13
|
+
tupleCV,
|
|
14
|
+
uintCV
|
|
15
|
+
} from "./stacks-2mm20wqf.js";
|
|
16
|
+
import {
|
|
17
|
+
MAX_I128,
|
|
18
|
+
MAX_U128,
|
|
19
|
+
MIN_I128,
|
|
20
|
+
validateStacksAddress
|
|
21
|
+
} from "./stacks-azp00pve.js";
|
|
22
|
+
|
|
1
23
|
// src/clarity/abi/types.ts
|
|
2
24
|
var CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\-]{0,127}$/;
|
|
3
25
|
|
|
@@ -105,7 +127,64 @@ function toCamelCase(str) {
|
|
|
105
127
|
}
|
|
106
128
|
|
|
107
129
|
// src/clarity/bridge.ts
|
|
130
|
+
var CV_TYPE_TAGS = new Set([
|
|
131
|
+
"int",
|
|
132
|
+
"uint",
|
|
133
|
+
"true",
|
|
134
|
+
"false",
|
|
135
|
+
"address",
|
|
136
|
+
"contract",
|
|
137
|
+
"ascii",
|
|
138
|
+
"utf8",
|
|
139
|
+
"buffer",
|
|
140
|
+
"list",
|
|
141
|
+
"tuple",
|
|
142
|
+
"none",
|
|
143
|
+
"some",
|
|
144
|
+
"ok",
|
|
145
|
+
"err"
|
|
146
|
+
]);
|
|
147
|
+
function isClarityValue(value) {
|
|
148
|
+
if (typeof value !== "object" || value === null)
|
|
149
|
+
return false;
|
|
150
|
+
const type = value.type;
|
|
151
|
+
if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
|
|
152
|
+
return false;
|
|
153
|
+
if (type === "true" || type === "false" || type === "none")
|
|
154
|
+
return true;
|
|
155
|
+
return "value" in value;
|
|
156
|
+
}
|
|
157
|
+
var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
|
|
158
|
+
function coerceBuffer(value) {
|
|
159
|
+
if (value instanceof Uint8Array)
|
|
160
|
+
return bufferCV(value);
|
|
161
|
+
if (typeof value === "object" && value !== null && "type" in value) {
|
|
162
|
+
const tagged = value;
|
|
163
|
+
if (tagged.type === "buffer" && isClarityValue(value))
|
|
164
|
+
return value;
|
|
165
|
+
if (typeof tagged.value === "string") {
|
|
166
|
+
if (tagged.type === "ascii")
|
|
167
|
+
return Cl.bufferFromAscii(tagged.value);
|
|
168
|
+
if (tagged.type === "utf8")
|
|
169
|
+
return Cl.bufferFromUtf8(tagged.value);
|
|
170
|
+
if (tagged.type === "hex")
|
|
171
|
+
return Cl.bufferFromHex(tagged.value);
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
|
|
174
|
+
}
|
|
175
|
+
if (typeof value === "string") {
|
|
176
|
+
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
177
|
+
if (HEX_PAIRS_REGEX.test(hex))
|
|
178
|
+
return Cl.bufferFromHex(hex);
|
|
179
|
+
return Cl.bufferFromUtf8(value);
|
|
180
|
+
}
|
|
181
|
+
throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
|
|
182
|
+
}
|
|
108
183
|
function jsToClarityValue(abiType, value) {
|
|
184
|
+
if (isAbiBuffer(abiType))
|
|
185
|
+
return coerceBuffer(value);
|
|
186
|
+
if (isClarityValue(value))
|
|
187
|
+
return value;
|
|
109
188
|
if (abiType === "uint128")
|
|
110
189
|
return uintCV(value);
|
|
111
190
|
if (abiType === "int128")
|
|
@@ -118,8 +197,6 @@ function jsToClarityValue(abiType, value) {
|
|
|
118
197
|
return stringAsciiCV(value);
|
|
119
198
|
if (isAbiStringUtf8(abiType))
|
|
120
199
|
return stringUtf8CV(value);
|
|
121
|
-
if (isAbiBuffer(abiType))
|
|
122
|
-
return bufferCV(value);
|
|
123
200
|
if (isAbiList(abiType)) {
|
|
124
201
|
const arr = value;
|
|
125
202
|
return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
|
|
@@ -228,5 +305,7 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
228
305
|
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
229
306
|
}
|
|
230
307
|
|
|
231
|
-
|
|
232
|
-
|
|
308
|
+
export { CONTRACT_NAME_REGEX, isUint128, isInt128, isBool, isPrincipal, isStandardPrincipal, isContractPrincipal, isTraitReference, isString, isUint8Array, isArray, isOptional, isOkResponse, isErrResponse, isResponse, isAbiList, isAbiTuple, isAbiOptional, isAbiResponse, isAbiBuffer, isAbiStringAscii, isAbiStringUtf8, isAbiTraitReference, toCamelCase, isClarityValue, jsToClarityValue, clarityValueToJS, clarityValueToJSUntyped };
|
|
309
|
+
|
|
310
|
+
//# debugId=61393ECAC463249664756E2164756E21
|
|
311
|
+
//# sourceMappingURL=stacks-18jv9aen.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/clarity/abi/types.ts", "../src/clarity/abi/guards.ts", "../src/clarity/abi/utils.ts", "../src/clarity/bridge.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { MAX_I128, MAX_U128, MIN_I128 } from \"../../utils/constants.ts\";\n\nexport { MAX_U128, MAX_I128, MIN_I128 };\n\nexport const CONTRACT_NAME_REGEX: RegExp = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;\n\n// Primitive types\n\nexport type AbiUInt128 = \"uint128\";\nexport type AbiInt128 = \"int128\";\nexport type AbiBool = \"bool\";\nexport type AbiPrincipal = \"principal\";\nexport type AbiTraitReference = \"trait_reference\";\nexport type AbiNone = \"none\";\n\nexport type AbiStringAscii<L extends number = number> = {\n\t\"string-ascii\": { length: L };\n};\n\nexport type AbiStringUtf8<L extends number = number> = {\n\t\"string-utf8\": { length: L };\n};\n\nexport type AbiBuffer<L extends number = number> = {\n\tbuff: { length: L };\n};\n\nexport type AbiPrimitiveType =\n\t| AbiUInt128\n\t| AbiInt128\n\t| AbiBool\n\t| AbiPrincipal\n\t| AbiTraitReference\n\t| AbiNone\n\t| AbiStringAscii\n\t| AbiStringUtf8\n\t| AbiBuffer;\n\n// Composite types (interfaces for recursion)\n\nexport interface AbiListType {\n\tlist: { type: AbiType; length: number };\n}\n\nexport interface AbiTupleType {\n\ttuple: ReadonlyArray<{ name: string; type: AbiType }>;\n}\n\nexport interface AbiOptionalType {\n\toptional: AbiType;\n}\n\nexport interface AbiResponseType {\n\tresponse: { ok: AbiType; error: AbiType };\n}\n\n/** Discriminated union of all Clarity value types (primitives, buffers, lists, tuples, optionals, responses). */\nexport type AbiType =\n\t| AbiPrimitiveType\n\t| AbiListType\n\t| AbiTupleType\n\t| AbiOptionalType\n\t| AbiResponseType;\n\n// Generic versions for better type inference\n\nexport type AbiList<T extends AbiType = AbiType, L extends number = number> = {\n\tlist: { type: T; length: L };\n};\n\nexport type AbiTuple<T extends ReadonlyArray<{ name: string; type: AbiType }>> =\n\t{\n\t\ttuple: T;\n\t};\n\nexport type AbiOptional<T extends AbiType = AbiType> = {\n\toptional: T;\n};\n\nexport type AbiResponse<\n\tO extends AbiType = AbiType,\n\tE extends AbiType = AbiType,\n> = {\n\tresponse: { ok: O; error: E };\n};\n",
|
|
6
|
+
"import { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { CONTRACT_NAME_REGEX, MAX_I128, MAX_U128, MIN_I128 } from \"./types.ts\";\nimport type {\n\tAbiBuffer,\n\tAbiListType,\n\tAbiOptionalType,\n\tAbiResponseType,\n\tAbiStringAscii,\n\tAbiStringUtf8,\n\tAbiTraitReference,\n\tAbiTupleType,\n\tAbiType,\n} from \"./types.ts\";\n\n// Value guards\n\nexport function isUint128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= 0n && value <= MAX_U128;\n}\n\nexport function isInt128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= MIN_I128 && value <= MAX_I128;\n}\n\nexport function isBool(value: unknown): value is boolean {\n\treturn typeof value === \"boolean\";\n}\n\nexport function isPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\tconst contractName = parts[1];\n\tif (!validateStacksAddress(address)) return false;\n\tif (contractName !== undefined) {\n\t\treturn CONTRACT_NAME_REGEX.test(contractName);\n\t}\n\treturn true;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (value.includes(\".\")) return false;\n\treturn validateStacksAddress(value);\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (!value.includes(\".\")) return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst contractName = parts[1]!;\n\tif (!validateStacksAddress(address)) return false;\n\treturn CONTRACT_NAME_REGEX.test(contractName);\n}\n\nexport function isTraitReference(value: unknown): value is string {\n\treturn isContractPrincipal(value);\n}\n\nexport function isString(value: unknown): value is string {\n\treturn typeof value === \"string\";\n}\n\nexport function isUint8Array(value: unknown): value is Uint8Array {\n\treturn value instanceof Uint8Array;\n}\n\nexport function isArray<T>(\n\tvalue: unknown,\n\titemGuard: (item: unknown) => item is T,\n): value is T[] {\n\treturn Array.isArray(value) && value.every(itemGuard);\n}\n\nexport function isOptional<T>(\n\tvalue: unknown,\n\tguard: (val: unknown) => val is T,\n): value is T | null {\n\treturn value === null || guard(value);\n}\n\nexport function isOkResponse<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: T } | { err: any },\n): response is ResponseOk<T> {\n\treturn \"ok\" in response && !(\"err\" in response);\n}\n\nexport function isErrResponse<E>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: any } | { err: E },\n): response is ResponseErr<E> {\n\treturn \"err\" in response && !(\"ok\" in response);\n}\n\nexport function isResponse<T, E>(\n\tvalue: unknown,\n\tokGuard: (val: unknown) => val is T,\n\terrGuard: (val: unknown) => val is E,\n): value is ResponseOk<T> | ResponseErr<E> {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst obj = value as Record<string, unknown>;\n\tif (\"ok\" in value && !(\"err\" in value)) return okGuard(obj.ok);\n\tif (\"err\" in value && !(\"ok\" in value)) return errGuard(obj.err);\n\treturn false;\n}\n\n// ABI type definition guards\n\nexport function isAbiList(type: AbiType): type is AbiListType {\n\treturn typeof type === \"object\" && type !== null && \"list\" in type;\n}\n\nexport function isAbiTuple(type: AbiType): type is AbiTupleType {\n\treturn typeof type === \"object\" && type !== null && \"tuple\" in type;\n}\n\nexport function isAbiOptional(type: AbiType): type is AbiOptionalType {\n\treturn typeof type === \"object\" && type !== null && \"optional\" in type;\n}\n\nexport function isAbiResponse(type: AbiType): type is AbiResponseType {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nexport function isAbiBuffer(type: AbiType): type is AbiBuffer {\n\treturn typeof type === \"object\" && type !== null && \"buff\" in type;\n}\n\nexport function isAbiStringAscii(type: AbiType): type is AbiStringAscii {\n\treturn typeof type === \"object\" && type !== null && \"string-ascii\" in type;\n}\n\nexport function isAbiStringUtf8(type: AbiType): type is AbiStringUtf8 {\n\treturn typeof type === \"object\" && type !== null && \"string-utf8\" in type;\n}\n\nexport function isAbiTraitReference(type: AbiType): type is AbiTraitReference {\n\treturn type === \"trait_reference\";\n}\n",
|
|
7
|
+
"type CamelCaseInner<S extends string> =\n\tS extends `${infer P1}-${infer P2}${infer P3}`\n\t\t? `${P1}${Capitalize<CamelCaseInner<`${P2}${P3}`>>}`\n\t\t: S;\n\nexport type ToCamelCase<S extends string> =\n\tCamelCaseInner<S> extends `${number}${string}`\n\t\t? `_${CamelCaseInner<S>}`\n\t\t: CamelCaseInner<S>;\n\nexport function toCamelCase(str: string): string {\n\treturn str\n\t\t.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())\n\t\t.replace(/-([A-Z])/g, (_, letter) => letter)\n\t\t.replace(/-(\\d)/g, (_, digit) => digit)\n\t\t.replace(/-/g, \"\")\n\t\t.replace(/^\\d/, \"_$&\");\n}\n",
|
|
8
|
+
"import {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n} from \"./abi/guards.ts\";\nimport type { AbiToTS } from \"./abi/mappings.ts\";\nimport type { AbiType } from \"./abi/types.ts\";\nimport { toCamelCase } from \"./abi/utils.ts\";\nimport type { ClarityValue } from \"./types.ts\";\nimport {\n\tboolCV,\n\tbufferCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\nimport { Cl } from \"./values.ts\";\n\n/** CV type tags — mirrors the discriminants of `ClarityValue`. */\nconst CV_TYPE_TAGS = new Set([\n\t\"int\",\n\t\"uint\",\n\t\"true\",\n\t\"false\",\n\t\"address\",\n\t\"contract\",\n\t\"ascii\",\n\t\"utf8\",\n\t\"buffer\",\n\t\"list\",\n\t\"tuple\",\n\t\"none\",\n\t\"some\",\n\t\"ok\",\n\t\"err\",\n]);\n\n/**\n * Duck-type check: is `value` already a built ClarityValue? Tag-only CVs\n * (`true`/`false`/`none`) have no payload; every other tag carries `value`.\n */\nexport function isClarityValue(value: unknown): value is ClarityValue {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst type = (value as { type?: unknown }).type;\n\tif (typeof type !== \"string\" || !CV_TYPE_TAGS.has(type)) return false;\n\tif (type === \"true\" || type === \"false\" || type === \"none\") return true;\n\treturn \"value\" in value;\n}\n\nconst HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;\n\n/**\n * Coerce a flexible buffer input to a BufferCV. Accepts `Uint8Array`, a\n * pre-built `BufferCV`, a tagged `{ type: 'ascii' | 'utf8' | 'hex', value }`\n * object, or a bare string (even-length hex — optionally 0x-prefixed — is\n * decoded as hex; anything else is UTF-8 encoded).\n */\nfunction coerceBuffer(value: unknown): ClarityValue {\n\tif (value instanceof Uint8Array) return bufferCV(value);\n\tif (typeof value === \"object\" && value !== null && \"type\" in value) {\n\t\tconst tagged = value as { type: string; value?: unknown };\n\t\tif (tagged.type === \"buffer\" && isClarityValue(value)) return value;\n\t\tif (typeof tagged.value === \"string\") {\n\t\t\tif (tagged.type === \"ascii\") return Cl.bufferFromAscii(tagged.value);\n\t\t\tif (tagged.type === \"utf8\") return Cl.bufferFromUtf8(tagged.value);\n\t\t\tif (tagged.type === \"hex\") return Cl.bufferFromHex(tagged.value);\n\t\t}\n\t\tthrow new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst hex = value.startsWith(\"0x\") ? value.slice(2) : value;\n\t\tif (HEX_PAIRS_REGEX.test(hex)) return Cl.bufferFromHex(hex);\n\t\treturn Cl.bufferFromUtf8(value);\n\t}\n\tthrow new Error(\n\t\t\"buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV\",\n\t);\n}\n\n/**\n * Convert a JS value to a ClarityValue using ABI type information.\n *\n * Pre-built ClarityValues pass through unchanged (escape hatch for callers\n * that already hold a CV). Buffer args additionally accept hex strings and\n * tagged `{ type, value }` objects — matching the generated-client input\n * contract.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\n\t// Buffers first: the tagged `{ type: 'ascii', value }` input form is\n\t// shape-identical to StringAsciiCV, so buffer coercion wins for buff args.\n\tif (isAbiBuffer(abiType)) return coerceBuffer(value);\n\n\tif (isClarityValue(value)) return value;\n\n\tif (abiType === \"uint128\") return uintCV(value as bigint | number);\n\tif (abiType === \"int128\") return intCV(value as bigint | number);\n\tif (abiType === \"bool\") return boolCV(value as boolean);\n\tif (abiType === \"principal\" || abiType === \"trait_reference\")\n\t\treturn Cl.principal(value as string);\n\n\tif (isAbiStringAscii(abiType)) return stringAsciiCV(value as string);\n\tif (isAbiStringUtf8(abiType)) return stringUtf8CV(value as string);\n\n\tif (isAbiList(abiType)) {\n\t\tconst arr = value as unknown[];\n\t\treturn listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst data: Record<string, ClarityValue> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in obj;\n\t\t\tconst hasCamel = camelKey in obj;\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? obj[field.name]\n\t\t\t\t: hasCamel\n\t\t\t\t\t? obj[camelKey]\n\t\t\t\t\t: undefined;\n\t\t\tif (fieldValue === undefined && !isAbiOptional(field.type)) {\n\t\t\t\tthrow new Error(`Missing tuple field: ${field.name}`);\n\t\t\t}\n\t\t\tdata[field.name] = jsToClarityValue(field.type, fieldValue);\n\t\t}\n\t\treturn tupleCV(data);\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (value === null || value === undefined) return noneCV();\n\t\treturn someCV(jsToClarityValue(abiType.optional, value));\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tif (\"ok\" in obj && !(\"err\" in obj))\n\t\t\treturn responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));\n\t\tif (\"err\" in obj && !(\"ok\" in obj))\n\t\t\treturn responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));\n\t\tthrow new Error(\"Response must have exactly 'ok' or 'err' property\");\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n\n/**\n * Convert a ClarityValue back to a typed JS value using ABI type information.\n */\nexport function clarityValueToJS<T extends AbiType>(\n\tabiType: T,\n\tcv: ClarityValue,\n): AbiToTS<T> {\n\treturn clarityValueToJSInner(abiType, cv) as AbiToTS<T>;\n}\n\n/** Non-generic version for internal use — avoids deep type instantiation. */\nexport function clarityValueToJSUntyped(\n\tabiType: AbiType,\n\tcv: ClarityValue,\n): unknown {\n\treturn clarityValueToJSInner(abiType, cv);\n}\n\nfunction clarityValueToJSInner(abiType: AbiType, cv: ClarityValue): unknown {\n\tif (abiType === \"uint128\" || abiType === \"int128\") {\n\t\tif (cv.type !== \"int\" && cv.type !== \"uint\")\n\t\t\tthrow new Error(`Expected int/uint CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (abiType === \"bool\") {\n\t\tif (cv.type === \"true\") return true;\n\t\tif (cv.type === \"false\") return false;\n\t\tthrow new Error(`Expected bool CV, got ${cv.type}`);\n\t}\n\n\tif (abiType === \"principal\" || abiType === \"trait_reference\") {\n\t\tif (cv.type !== \"address\" && cv.type !== \"contract\")\n\t\t\tthrow new Error(`Expected principal CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {\n\t\tif (cv.type !== \"ascii\" && cv.type !== \"utf8\")\n\t\t\tthrow new Error(`Expected string CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiBuffer(abiType)) {\n\t\tif (cv.type !== \"buffer\")\n\t\t\tthrow new Error(`Expected buffer CV, got ${cv.type}`);\n\t\t// BufferCV stores hex string; convert back to Uint8Array\n\t\tconst hex = cv.value;\n\t\tconst bytes = new Uint8Array(hex.length / 2);\n\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\tbytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tif (isAbiList(abiType)) {\n\t\tif (cv.type !== \"list\") throw new Error(`Expected list CV, got ${cv.type}`);\n\t\treturn cv.value.map((item) =>\n\t\t\tclarityValueToJSInner(abiType.list.type, item),\n\t\t);\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tif (cv.type !== \"tuple\")\n\t\t\tthrow new Error(`Expected tuple CV, got ${cv.type}`);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst fieldCV = cv.value[field.name];\n\t\t\tif (!fieldCV) throw new Error(`Missing tuple field in CV: ${field.name}`);\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tresult[camelKey] = clarityValueToJSInner(field.type, fieldCV);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (cv.type === \"none\") return null;\n\t\tif (cv.type === \"some\")\n\t\t\treturn clarityValueToJSInner(abiType.optional, cv.value);\n\t\tthrow new Error(`Expected optional CV, got ${cv.type}`);\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tif (cv.type === \"ok\")\n\t\t\treturn { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };\n\t\tif (cv.type === \"err\")\n\t\t\treturn { err: clarityValueToJSInner(abiType.response.error, cv.value) };\n\t\tthrow new Error(`Expected response CV, got ${cv.type}`);\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,sBAA8B;;;ACapC,SAAS,SAAS,CAAC,OAAiC;AAAA,EAC1D,OAAO,OAAO,UAAU,YAAY,SAAS,MAAM,SAAS;AAAA;AAGtD,SAAS,QAAQ,CAAC,OAAiC;AAAA,EACzD,OAAO,OAAO,UAAU,YAAY,SAAS,YAAY,SAAS;AAAA;AAG5D,SAAS,MAAM,CAAC,OAAkC;AAAA,EACxD,OAAO,OAAO,UAAU;AAAA;AAGlB,SAAS,WAAW,CAAC,OAAiC;AAAA,EAC5D,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,MAAM,QAAQ,MAAM,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|
4
4
|
import {
|
|
5
5
|
asciiToBytes,
|
|
6
6
|
bigIntToBytes,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
utf8ToBytes,
|
|
19
19
|
without0x,
|
|
20
20
|
writeUInt32BE
|
|
21
|
-
} from "./stacks-
|
|
21
|
+
} from "./stacks-qs5fzts5.js";
|
|
22
22
|
|
|
23
23
|
// src/clarity/types.ts
|
|
24
24
|
var ClarityWireType = {
|
|
@@ -356,4 +356,4 @@ var Cl = {
|
|
|
356
356
|
export { ClarityWireType, clarityTypeFromByte, serializeCVBytes, serializeCV, BytesReader, intCV, uintCV, trueCV, falseCV, boolCV, bufferCV, standardPrincipalCV, contractPrincipalCV, noneCV, someCV, responseOkCV, responseErrorCV, listCV, tupleCV, stringAsciiCV, stringUtf8CV, Cl, readAddress, readLPString, readCV, deserializeCVBytes, deserializeCV };
|
|
357
357
|
|
|
358
358
|
//# debugId=75F450EFADB0433F64756E2164756E21
|
|
359
|
-
//# sourceMappingURL=stacks-
|
|
359
|
+
//# sourceMappingURL=stacks-2mm20wqf.js.map
|
|
@@ -11,14 +11,7 @@ async function sponsorTransaction(client, params) {
|
|
|
11
11
|
throw new Error("Provider accounts cannot sponsor transactions");
|
|
12
12
|
}
|
|
13
13
|
const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
|
|
14
|
-
|
|
15
|
-
if (params.fee != null) {
|
|
16
|
-
fee = intToBigInt(params.fee);
|
|
17
|
-
} else {
|
|
18
|
-
const estimates = await estimateFee(client, { transaction });
|
|
19
|
-
const mid = estimates[1] ?? estimates[0];
|
|
20
|
-
fee = mid ? BigInt(mid.fee) : 0n;
|
|
21
|
-
}
|
|
14
|
+
const fee = await resolveFee(client, transaction, params.fee);
|
|
22
15
|
const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
|
|
23
16
|
const auth = transaction.auth;
|
|
24
17
|
const sponsored = {
|
|
@@ -31,5 +24,5 @@ async function sponsorTransaction(client, params) {
|
|
|
31
24
|
return signSponsorWithAccount(sponsored, account);
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
//# debugId=
|
|
35
|
-
//# sourceMappingURL=stacks-
|
|
27
|
+
//# debugId=2C7F1B8FDFB94A5364756E2164756E21
|
|
28
|
+
//# sourceMappingURL=stacks-44y18a8e.cjs.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/actions/wallet/sponsorTransaction.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAoBA,eAAsB,kBAAkB,CACvC,QACA,QAC6B;AAAA,EAC7B,QAAQ,gBAAgB;AAAA,EAExB,IAAI,YAAY,KAAK,aAAa,SAAS,WAAW;AAAA,IACrD,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAEA,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAChD,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAGA,MAAM,QACL,OAAO,SAAS,OACb,YAAY,OAAO,KAAK,IACxB,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAI9C,MAAM,MAAM,MAAM,WAAW,QAAQ,aAAa,OAAO,GAAG;AAAA,EAG5D,MAAM,mBAAmB,iCACxB,QAAQ,WACR,OACA,GACD;AAAA,EAGA,MAAM,OAAO,YAAY;AAAA,EACzB,MAAM,YAA+B;AAAA,OACjC;AAAA,IACH,MAAM;AAAA,SACF;AAAA,MACH,0BAA0B;AAAA,IAC3B;AAAA,EACD;AAAA,EAGA,OAAO,uBAAuB,WAAW,OAAO;AAAA;",
|
|
8
|
+
"debugId": "2C7F1B8FDFB94A5364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readContract
|
|
3
|
-
} from "./stacks-
|
|
3
|
+
} from "./stacks-msmgyerb.js";
|
|
4
4
|
import {
|
|
5
|
+
assertNoFeeTierForProvider,
|
|
5
6
|
broadcastWithNonceReset,
|
|
6
7
|
estimateFee,
|
|
8
|
+
extendedApiSource,
|
|
9
|
+
isFeeTier,
|
|
7
10
|
isProviderAccount,
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
resolveFee,
|
|
12
|
+
resolveNonce,
|
|
13
|
+
setUnsignedFee
|
|
14
|
+
} from "./stacks-kjg7fw4y.js";
|
|
10
15
|
import {
|
|
11
16
|
BaseError
|
|
12
17
|
} from "./stacks-709tra19.js";
|
|
13
18
|
import {
|
|
14
19
|
deserializeTransaction
|
|
15
|
-
} from "./stacks-
|
|
20
|
+
} from "./stacks-g11v9a35.js";
|
|
16
21
|
import {
|
|
17
22
|
AddressHashMode,
|
|
18
23
|
PayloadType,
|
|
@@ -21,23 +26,23 @@ import {
|
|
|
21
26
|
serializeTransactionHex,
|
|
22
27
|
signMultiSigWithAccount,
|
|
23
28
|
signTransactionWithAccount
|
|
24
|
-
} from "./stacks-
|
|
29
|
+
} from "./stacks-ssndnbbd.js";
|
|
25
30
|
import {
|
|
26
31
|
Cl,
|
|
27
32
|
deserializeCVBytes,
|
|
28
33
|
serializeCVBytes
|
|
29
|
-
} from "./stacks-
|
|
34
|
+
} from "./stacks-2mm20wqf.js";
|
|
30
35
|
import {
|
|
31
36
|
isClarityName,
|
|
32
37
|
parseContractId,
|
|
33
38
|
validateStacksAddress
|
|
34
|
-
} from "./stacks-
|
|
39
|
+
} from "./stacks-azp00pve.js";
|
|
35
40
|
import {
|
|
36
41
|
bytesToHex,
|
|
37
42
|
c32address,
|
|
38
43
|
concatBytes,
|
|
39
44
|
with0x
|
|
40
|
-
} from "./stacks-
|
|
45
|
+
} from "./stacks-qs5fzts5.js";
|
|
41
46
|
|
|
42
47
|
// src/actions/public/getAccountInfo.ts
|
|
43
48
|
async function getAccountInfo(client, params) {
|
|
@@ -75,12 +80,6 @@ async function getBlock(client, params) {
|
|
|
75
80
|
return client.request("/extended/v2/blocks?limit=1", { method: "GET" });
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
// src/actions/public/getBlockHeight.ts
|
|
79
|
-
async function getBlockHeight(client) {
|
|
80
|
-
const data = await client.request("/v2/info", { method: "GET" });
|
|
81
|
-
return data.stacks_tip_height;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
83
|
// src/actions/public/getContractAbi.ts
|
|
85
84
|
async function getContractAbi(client, params) {
|
|
86
85
|
const [address, name] = parseContractId(params.contract);
|
|
@@ -89,6 +88,13 @@ async function getContractAbi(client, params) {
|
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
// src/actions/public/getTransaction.ts
|
|
92
|
+
async function getTransaction(client, params) {
|
|
93
|
+
const source = params.source ?? extendedApiSource();
|
|
94
|
+
const { receipt } = await source.get({ client, txid: params.txid });
|
|
95
|
+
return receipt;
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
// src/actions/public/multicall.ts
|
|
93
99
|
async function multicall(client, params) {
|
|
94
100
|
const { calls, allowFailure = true } = params;
|
|
@@ -183,6 +189,7 @@ async function deployContract(client, params) {
|
|
|
183
189
|
if (!isClarityName(params.contractName))
|
|
184
190
|
throw new Error(`Invalid contract name: ${params.contractName}`);
|
|
185
191
|
if (isProviderAccount(account)) {
|
|
192
|
+
assertNoFeeTierForProvider(params.fee);
|
|
186
193
|
const result = await account.provider.request("stx_deployContract", {
|
|
187
194
|
contractName: params.contractName,
|
|
188
195
|
codeBody: params.codeBody,
|
|
@@ -191,23 +198,20 @@ async function deployContract(client, params) {
|
|
|
191
198
|
return result.txid;
|
|
192
199
|
}
|
|
193
200
|
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
201
|
+
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
194
202
|
const unsigned = buildContractDeploy({
|
|
195
203
|
contractName: params.contractName,
|
|
196
204
|
codeBody: params.codeBody,
|
|
197
205
|
clarityVersion: params.clarityVersion,
|
|
198
|
-
fee: params.fee
|
|
206
|
+
fee: needsFeeResolution ? 0n : params.fee,
|
|
199
207
|
nonce,
|
|
200
208
|
publicKey: account.publicKey,
|
|
201
209
|
chain: client.chain,
|
|
202
210
|
postConditionMode: params.postConditionMode,
|
|
203
211
|
postConditions: params.postConditions
|
|
204
212
|
});
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
const mid = estimates[1] ?? estimates[0];
|
|
208
|
-
if (mid) {
|
|
209
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
210
|
-
}
|
|
213
|
+
if (needsFeeResolution) {
|
|
214
|
+
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
211
215
|
}
|
|
212
216
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
213
217
|
return broadcastWithNonceReset(client, {
|
|
@@ -279,6 +283,7 @@ async function transferStx(client, params) {
|
|
|
279
283
|
if (!validateStacksAddress(params.to))
|
|
280
284
|
throw new Error(`Invalid recipient address: ${params.to}`);
|
|
281
285
|
if (isProviderAccount(account)) {
|
|
286
|
+
assertNoFeeTierForProvider(params.fee);
|
|
282
287
|
const result = await account.provider.request("stx_transferStx", {
|
|
283
288
|
recipient: params.to,
|
|
284
289
|
amount: String(params.amount),
|
|
@@ -287,23 +292,20 @@ async function transferStx(client, params) {
|
|
|
287
292
|
return result.txid;
|
|
288
293
|
}
|
|
289
294
|
const nonce = params.nonce ?? await resolveNonce(client, account.address);
|
|
295
|
+
const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
|
|
290
296
|
const unsigned = buildTokenTransfer({
|
|
291
297
|
recipient: params.to,
|
|
292
298
|
amount: params.amount,
|
|
293
299
|
memo: params.memo,
|
|
294
|
-
fee: params.fee
|
|
300
|
+
fee: needsFeeResolution ? 0n : params.fee,
|
|
295
301
|
nonce,
|
|
296
302
|
publicKey: account.publicKey,
|
|
297
303
|
chain: client.chain,
|
|
298
304
|
postConditionMode: params.postConditionMode,
|
|
299
305
|
postConditions: params.postConditions
|
|
300
306
|
});
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
const mid = estimates[1] ?? estimates[0];
|
|
304
|
-
if (mid) {
|
|
305
|
-
unsigned.auth.spendingCondition.fee = BigInt(mid.fee);
|
|
306
|
-
}
|
|
307
|
+
if (needsFeeResolution) {
|
|
308
|
+
setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
|
|
307
309
|
}
|
|
308
310
|
const signed = await signTransactionWithAccount(unsigned, account);
|
|
309
311
|
return broadcastWithNonceReset(client, {
|
|
@@ -312,7 +314,7 @@ async function transferStx(client, params) {
|
|
|
312
314
|
});
|
|
313
315
|
}
|
|
314
316
|
|
|
315
|
-
export { getAccountInfo, getBalance, getBlock,
|
|
317
|
+
export { getAccountInfo, getBalance, getBlock, getContractAbi, getTransaction, multicall, SimulationError, simulateCall, simulateTransaction, deployContract, signMessage, signTransactionAction, transferStx };
|
|
316
318
|
|
|
317
|
-
//# debugId=
|
|
318
|
-
//# sourceMappingURL=stacks-
|
|
319
|
+
//# debugId=CD5517B72817ABFE64756E2164756E21
|
|
320
|
+
//# sourceMappingURL=stacks-59xy6t1p.js.map
|