@secondlayer/stacks 2.14.1 → 2.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/shared/{stacks-f66v961k.js → stacks-1k0kmpcw.js} +2 -2
- package/dist/shared/{stacks-6mhsf8hk.cjs → stacks-1xk4wby6.cjs} +10 -21
- package/dist/shared/{stacks-6mhsf8hk.cjs.map → stacks-1xk4wby6.cjs.map} +5 -6
- package/dist/shared/{stacks-tswh2xav.js → stacks-2x04a6ss.js} +12 -26
- package/dist/shared/{stacks-tswh2xav.js.map → stacks-2x04a6ss.js.map} +5 -6
- package/dist/shared/stacks-3kj51c6p.cjs +16 -0
- package/dist/shared/stacks-3kj51c6p.cjs.map +10 -0
- package/dist/shared/{stacks-jcgvn5v5.cjs → stacks-70xxh5h1.cjs} +15 -6
- package/dist/shared/{stacks-dmrvk1mz.js.map → stacks-70xxh5h1.cjs.map} +3 -3
- package/dist/shared/stacks-f0hfqaj5.js +22 -0
- package/dist/shared/stacks-f0hfqaj5.js.map +10 -0
- package/dist/shared/{stacks-3vyvtahh.js → stacks-ggxnnph5.cjs} +2 -46
- package/dist/shared/stacks-ggxnnph5.cjs.map +10 -0
- package/dist/shared/stacks-pdcz1w1d.js +33 -0
- package/dist/shared/stacks-pdcz1w1d.js.map +10 -0
- package/dist/shared/{stacks-fjrpnkt3.cjs → stacks-q45x3389.js} +20 -15
- package/dist/shared/stacks-q45x3389.js.map +10 -0
- package/dist/shared/{stacks-hxp7v905.js → stacks-refg7hca.js} +7 -5
- package/dist/shared/{stacks-hxp7v905.js.map → stacks-refg7hca.js.map} +2 -2
- package/dist/shared/{stacks-dmrvk1mz.js → stacks-y9w78e2b.js} +15 -6
- package/dist/shared/{stacks-jcgvn5v5.cjs.map → stacks-y9w78e2b.js.map} +3 -3
- package/dist/shared/stacks-yetejw9x.cjs +16 -0
- package/dist/shared/stacks-yetejw9x.cjs.map +10 -0
- package/dist/src/actions/index.js +12 -8
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bns/index.js +5 -4
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/connect/index.cjs +47 -6
- package/dist/src/connect/index.cjs.map +8 -4
- package/dist/src/connect/index.js +47 -6
- package/dist/src/connect/index.js.map +8 -4
- package/dist/src/index.js +11 -7
- package/dist/src/index.js.map +2 -2
- package/dist/src/pox/index.js +5 -4
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +513 -0
- package/dist/src/pox5/index.cjs.map +16 -0
- package/dist/src/pox5/index.d.cts +646 -0
- package/dist/src/pox5/index.d.ts +646 -0
- package/dist/src/pox5/index.js +540 -0
- package/dist/src/pox5/index.js.map +16 -0
- package/dist/src/sbtc/index.js +5 -4
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/stackingdao/index.js +5 -4
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/tools/btc/index.cjs +6 -5
- package/dist/src/tools/btc/index.cjs.map +3 -3
- package/dist/src/tools/btc/index.d.cts +2 -1
- package/dist/src/tools/btc/index.d.ts +2 -1
- package/dist/src/tools/btc/index.js +6 -5
- package/dist/src/tools/btc/index.js.map +3 -3
- package/dist/src/tools/index.cjs +323 -43
- package/dist/src/tools/index.cjs.map +10 -9
- package/dist/src/tools/index.js +323 -46
- package/dist/src/tools/index.js.map +10 -9
- package/dist/src/x402/index.js +2 -2
- package/package.json +7 -2
- package/dist/shared/stacks-3vyvtahh.js.map +0 -11
- package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
- /package/dist/shared/{stacks-f66v961k.js.map → stacks-1k0kmpcw.js.map} +0 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
/** Account derived from a local private key (mnemonic or raw key). */
|
|
2
|
+
type LocalAccount = {
|
|
3
|
+
type: "local"
|
|
4
|
+
address: string
|
|
5
|
+
/** Compressed public key (hex) */
|
|
6
|
+
publicKey: string
|
|
7
|
+
/** Raw ECDSA sign over a hash */
|
|
8
|
+
sign(hash: Uint8Array): Uint8Array
|
|
9
|
+
/** Sign a structured message (SIP-018) */
|
|
10
|
+
signMessage(message: string | Uint8Array): string
|
|
11
|
+
};
|
|
12
|
+
/** Account with a user-provided signing function (sync or async). */
|
|
13
|
+
type CustomAccount = {
|
|
14
|
+
type: "custom"
|
|
15
|
+
address: string
|
|
16
|
+
publicKey: string
|
|
17
|
+
sign(hash: Uint8Array): Promise<Uint8Array> | Uint8Array
|
|
18
|
+
};
|
|
19
|
+
/** Browser wallet provider interface (e.g. Leather, Xverse). */
|
|
20
|
+
type StacksProvider = {
|
|
21
|
+
request(method: string, params?: any): Promise<any>
|
|
22
|
+
};
|
|
23
|
+
/** Account backed by a browser wallet {@link StacksProvider}. */
|
|
24
|
+
type ProviderAccount = {
|
|
25
|
+
type: "provider"
|
|
26
|
+
address: string
|
|
27
|
+
publicKey: string
|
|
28
|
+
provider: StacksProvider
|
|
29
|
+
};
|
|
30
|
+
type IntCV = {
|
|
31
|
+
readonly type: "int"
|
|
32
|
+
readonly value: bigint
|
|
33
|
+
};
|
|
34
|
+
type UIntCV = {
|
|
35
|
+
readonly type: "uint"
|
|
36
|
+
readonly value: bigint
|
|
37
|
+
};
|
|
38
|
+
type BooleanCV = TrueCV | FalseCV;
|
|
39
|
+
type TrueCV = {
|
|
40
|
+
readonly type: "true"
|
|
41
|
+
};
|
|
42
|
+
type FalseCV = {
|
|
43
|
+
readonly type: "false"
|
|
44
|
+
};
|
|
45
|
+
type BufferCV = {
|
|
46
|
+
readonly type: "buffer"
|
|
47
|
+
readonly value: string
|
|
48
|
+
};
|
|
49
|
+
type NoneCV = {
|
|
50
|
+
readonly type: "none"
|
|
51
|
+
};
|
|
52
|
+
type SomeCV = {
|
|
53
|
+
readonly type: "some"
|
|
54
|
+
readonly value: ClarityValue
|
|
55
|
+
};
|
|
56
|
+
type ResponseOkCV = {
|
|
57
|
+
readonly type: "ok"
|
|
58
|
+
readonly value: ClarityValue
|
|
59
|
+
};
|
|
60
|
+
type ResponseErrorCV = {
|
|
61
|
+
readonly type: "err"
|
|
62
|
+
readonly value: ClarityValue
|
|
63
|
+
};
|
|
64
|
+
type StandardPrincipalCV = {
|
|
65
|
+
readonly type: "address"
|
|
66
|
+
readonly value: string
|
|
67
|
+
};
|
|
68
|
+
type ContractPrincipalCV = {
|
|
69
|
+
readonly type: "contract"
|
|
70
|
+
readonly value: string
|
|
71
|
+
};
|
|
72
|
+
type ListCV = {
|
|
73
|
+
type: "list"
|
|
74
|
+
value: ClarityValue[]
|
|
75
|
+
};
|
|
76
|
+
type TupleData = {
|
|
77
|
+
[key: string]: ClarityValue
|
|
78
|
+
};
|
|
79
|
+
type TupleCV = {
|
|
80
|
+
type: "tuple"
|
|
81
|
+
value: TupleData
|
|
82
|
+
};
|
|
83
|
+
type StringAsciiCV = {
|
|
84
|
+
readonly type: "ascii"
|
|
85
|
+
readonly value: string
|
|
86
|
+
};
|
|
87
|
+
type StringUtf8CV = {
|
|
88
|
+
readonly type: "utf8"
|
|
89
|
+
readonly value: string
|
|
90
|
+
};
|
|
91
|
+
type ClarityValue = IntCV | UIntCV | BooleanCV | BufferCV | NoneCV | SomeCV | ResponseOkCV | ResponseErrorCV | StandardPrincipalCV | ContractPrincipalCV | ListCV | TupleCV | StringAsciiCV | StringUtf8CV;
|
|
92
|
+
/** Allocates mempool-safe sequential nonces across rapid broadcasts from one account. */
|
|
93
|
+
type NonceManager = {
|
|
94
|
+
consume(params: {
|
|
95
|
+
client: Client
|
|
96
|
+
address: string
|
|
97
|
+
}): Promise<bigint>
|
|
98
|
+
reset(params: {
|
|
99
|
+
client: Client
|
|
100
|
+
address: string
|
|
101
|
+
}): void | Promise<void>
|
|
102
|
+
/** Next nonce that {@link NonceManager.consume} would return without consuming it, or `undefined` if untracked. */
|
|
103
|
+
peek(params: {
|
|
104
|
+
client: Client
|
|
105
|
+
address: string
|
|
106
|
+
}): Promise<bigint | undefined>
|
|
107
|
+
};
|
|
108
|
+
/** Full chain descriptor used by clients and transports for network-aware operations. */
|
|
109
|
+
type StacksChain = {
|
|
110
|
+
/** Chain ID (e.g. 0x00000001 for mainnet) */
|
|
111
|
+
id: number
|
|
112
|
+
/** Human-readable name */
|
|
113
|
+
name: string
|
|
114
|
+
/** Network type */
|
|
115
|
+
network: "mainnet" | "testnet"
|
|
116
|
+
/** Transaction version byte for serialization */
|
|
117
|
+
transactionVersion: number
|
|
118
|
+
/** Peer network ID for P2P broadcasting */
|
|
119
|
+
peerNetworkId: number
|
|
120
|
+
/** Address version bytes */
|
|
121
|
+
addressVersion: {
|
|
122
|
+
singleSig: number
|
|
123
|
+
multiSig: number
|
|
124
|
+
}
|
|
125
|
+
/** Magic bytes for network identification */
|
|
126
|
+
magicBytes: string
|
|
127
|
+
/** Boot address (system contracts deployer) */
|
|
128
|
+
bootAddress: string
|
|
129
|
+
/** Native currency info */
|
|
130
|
+
nativeCurrency: {
|
|
131
|
+
name: string
|
|
132
|
+
symbol: string
|
|
133
|
+
decimals: number
|
|
134
|
+
}
|
|
135
|
+
/** Default RPC URLs */
|
|
136
|
+
rpcUrls: {
|
|
137
|
+
default: {
|
|
138
|
+
http: string[]
|
|
139
|
+
ws?: string[]
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** Block explorer URLs */
|
|
143
|
+
blockExplorers?: {
|
|
144
|
+
default: {
|
|
145
|
+
name: string
|
|
146
|
+
url: string
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
/** Function that sends an HTTP request to a Stacks node API path. */
|
|
151
|
+
type RequestFn = (path: string, options?: RequestOptions) => Promise<any>;
|
|
152
|
+
/** Options for a transport-level HTTP request. */
|
|
153
|
+
type RequestOptions = {
|
|
154
|
+
method?: "GET" | "POST" | "PUT" | "DELETE"
|
|
155
|
+
body?: unknown
|
|
156
|
+
headers?: Record<string, string>
|
|
157
|
+
};
|
|
158
|
+
/** Shared configuration for all transport types. */
|
|
159
|
+
type TransportConfig = {
|
|
160
|
+
url?: string
|
|
161
|
+
timeout?: number
|
|
162
|
+
retryCount?: number
|
|
163
|
+
retryDelay?: number
|
|
164
|
+
fetchOptions?: RequestInit
|
|
165
|
+
apiKey?: string
|
|
166
|
+
};
|
|
167
|
+
/** A resolved transport instance with a bound request function. */
|
|
168
|
+
type Transport = {
|
|
169
|
+
type: string
|
|
170
|
+
request: RequestFn
|
|
171
|
+
config: TransportConfig
|
|
172
|
+
destroy?: () => void
|
|
173
|
+
};
|
|
174
|
+
/** Union of all supported account types (local key, custom signer, or browser provider). */
|
|
175
|
+
type Account = LocalAccount | CustomAccount | ProviderAccount;
|
|
176
|
+
/**
|
|
177
|
+
* Core client instance that holds chain context, transport, and extensible actions.
|
|
178
|
+
* Created via {@link createClient}, {@link createPublicClient}, or {@link createWalletClient}.
|
|
179
|
+
*/
|
|
180
|
+
type Client<TExtended extends Record<string, unknown> = Record<string, unknown>> = {
|
|
181
|
+
chain?: StacksChain
|
|
182
|
+
account?: Account
|
|
183
|
+
transport: Transport
|
|
184
|
+
request: RequestFn
|
|
185
|
+
/** Optional nonce manager for mempool-safe sequential nonces across rapid broadcasts. */
|
|
186
|
+
nonceManager?: NonceManager
|
|
187
|
+
extend: <const TNew extends Record<string, unknown>>(fn: (client: Client<TExtended>) => TNew) => Client<TExtended & TNew> & TNew
|
|
188
|
+
} & TExtended;
|
|
189
|
+
/**
|
|
190
|
+
* Chain-reported PoX-5 activation facts, read from the node's `/v2/pox`
|
|
191
|
+
* `contract_versions[]`. Present the moment nodes run stacks-core >= 4.0.0 —
|
|
192
|
+
* no hardcoded heights, works on any network.
|
|
193
|
+
*/
|
|
194
|
+
type Pox5Activation = {
|
|
195
|
+
/** Fully-qualified `pox-5` contract id (boot address differs per network). */
|
|
196
|
+
contractId: string
|
|
197
|
+
/** Bitcoin block height at which Epoch 4.0 (and pox-5) activates. */
|
|
198
|
+
activationBurnchainBlockHeight: number
|
|
199
|
+
/** First reward cycle in which pox-5 governs PoX. */
|
|
200
|
+
firstRewardCycleId: number
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Read pox-5's activation entry from the node. Returns `undefined` when the
|
|
204
|
+
* node doesn't know about pox-5 yet (pre-4.0.0 node software).
|
|
205
|
+
*/
|
|
206
|
+
declare function getPox5Activation(client: Client): Promise<Pox5Activation | undefined>;
|
|
207
|
+
/**
|
|
208
|
+
* Whether pox-5 is live on the node's chain: the node software knows the
|
|
209
|
+
* contract AND the burnchain has reached its activation height. One request.
|
|
210
|
+
*/
|
|
211
|
+
declare function isPox5Active(client: Client): Promise<boolean>;
|
|
212
|
+
/** Throw a descriptive error unless pox-5 is active on the client's chain. */
|
|
213
|
+
declare function assertPox5Active(client: Client): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* PoX-5 (SIP-045 Bitcoin Staking) constants, pinned against the final
|
|
216
|
+
* contract shipped in stacks-core 4.0.0 (`stackslib/.../boot/pox-5.clar`).
|
|
217
|
+
*/
|
|
218
|
+
/** Boot contract name; deployer is the chain's boot address. */
|
|
219
|
+
declare const POX5_CONTRACT_NAME = "pox-5";
|
|
220
|
+
/**
|
|
221
|
+
* Epoch 4.0 hard-fork activation height on mainnet — Bitcoin block 960,230
|
|
222
|
+
* (expected ~2026-07-29 03:00 UTC, per the stacks-core 4.0.0 release).
|
|
223
|
+
* Prefer the runtime gate in `activation.ts` (`getPox5Activation`), which
|
|
224
|
+
* reads the node's `/v2/pox` and needs no hardcoded height.
|
|
225
|
+
*/
|
|
226
|
+
declare const POX5_ACTIVATION_BURN_HEIGHT_MAINNET = 960230;
|
|
227
|
+
/** Length of a paired-BTC bond, in reward cycles (`BOND_LENGTH_CYCLES`). */
|
|
228
|
+
declare const BOND_LENGTH_CYCLES = 12;
|
|
229
|
+
/** Gap between consecutive bond starts, in reward cycles (`BOND_GAP_CYCLES`). */
|
|
230
|
+
declare const BOND_GAP_CYCLES = 2;
|
|
231
|
+
/** Hard cap for STX-only stake duration, in cycles (`MAX_NUM_CYCLES`). */
|
|
232
|
+
declare const MAX_NUM_CYCLES = 96;
|
|
233
|
+
/** SIP-018 domain for signer-key grants (`POX_5_SIGNER_DOMAIN`). */
|
|
234
|
+
declare const POX5_SIGNER_DOMAIN: {
|
|
235
|
+
readonly name: "pox-5-signer"
|
|
236
|
+
readonly version: "1.0.0"
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* `serialize-c-script-num` rejects values at or above 2^39 — the ceiling of a
|
|
240
|
+
* 5-byte minimally-encoded ScriptNum (`ERR_INVALID_UNLOCK_HEIGHT`).
|
|
241
|
+
*/
|
|
242
|
+
declare const C_SCRIPT_NUM_MAX = 549755813888n;
|
|
243
|
+
/**
|
|
244
|
+
* Bitcoin treats CLTV values >= 500,000,000 as Unix timestamps (BIP-65); the
|
|
245
|
+
* contract rejects unlock heights at or above this so a lockup can never
|
|
246
|
+
* commit a height Bitcoin would reinterpret.
|
|
247
|
+
*/
|
|
248
|
+
declare const BITCOIN_LOCKTIME_THRESHOLD = 500000000n;
|
|
249
|
+
/**
|
|
250
|
+
* Pure cycle/height math, mirroring the pox-5 helper read-onlys byte-for-byte
|
|
251
|
+
* (`burn-height-to-reward-cycle`, `reward-cycle-to-burn-height`,
|
|
252
|
+
* `bond-period-to-reward-cycle`, `burn-height-to-distribution-index`).
|
|
253
|
+
*
|
|
254
|
+
* All functions anchor on chain-reported parameters — pass values from
|
|
255
|
+
* `/v2/pox` (`first_burnchain_block_height`, `reward_cycle_length`,
|
|
256
|
+
* `prepare_cycle_length`) and `getPox5Activation` (`firstRewardCycleId` =
|
|
257
|
+
* the contract's `first-bond-period-cycle`). Nothing is hardcoded, so the
|
|
258
|
+
* math is correct on mainnet, testnet, and devnet alike.
|
|
259
|
+
*/
|
|
260
|
+
type PoxCycleParams = {
|
|
261
|
+
/** `/v2/pox` `first_burnchain_block_height`. */
|
|
262
|
+
firstBurnchainBlockHeight: number
|
|
263
|
+
/** `/v2/pox` `reward_cycle_length` (mainnet 2100). */
|
|
264
|
+
rewardCycleLength: number
|
|
265
|
+
};
|
|
266
|
+
type BondCycleParams = PoxCycleParams & {
|
|
267
|
+
/** pox-5's first bond-period cycle (`getPox5Activation().firstRewardCycleId`). */
|
|
268
|
+
firstBondPeriodCycle: number
|
|
269
|
+
};
|
|
270
|
+
/** Reward cycle containing `burnHeight`. Mirrors `burn-height-to-reward-cycle`. */
|
|
271
|
+
declare function burnHeightToRewardCycle(burnHeight: number, params: PoxCycleParams): number;
|
|
272
|
+
/** Burn height at the start of `cycle`. Mirrors `reward-cycle-to-burn-height`. */
|
|
273
|
+
declare function rewardCycleToBurnHeight(cycle: number, params: PoxCycleParams): number;
|
|
274
|
+
/** Reward cycle at which bond period `bondIndex` starts. Mirrors `bond-period-to-reward-cycle`. */
|
|
275
|
+
declare function bondPeriodToRewardCycle(bondIndex: number, params: BondCycleParams): number;
|
|
276
|
+
/** Burn height at which bond period `bondIndex` starts. Mirrors `bond-period-to-burn-height`. */
|
|
277
|
+
declare function bondPeriodToBurnHeight(bondIndex: number, params: BondCycleParams): number;
|
|
278
|
+
/** First reward cycle in which bond `bondIndex`'s STX unlock (start + 12 cycles). */
|
|
279
|
+
declare function bondUnlockCycle(bondIndex: number, params: BondCycleParams): number;
|
|
280
|
+
/**
|
|
281
|
+
* Distribution-cycle index at `burnHeight` — distribution cycles are half a
|
|
282
|
+
* reward cycle long. Mirrors `burn-height-to-distribution-index`.
|
|
283
|
+
*/
|
|
284
|
+
declare function burnHeightToDistributionIndex(burnHeight: number, params: PoxCycleParams): number;
|
|
285
|
+
/**
|
|
286
|
+
* Whether `burnHeight` falls in a cycle's prepare phase (the final
|
|
287
|
+
* `prepareCycleLength` blocks). pox-5 rejects `unstake-sbtc` and
|
|
288
|
+
* `announce-l1-early-exit` during a prepare phase.
|
|
289
|
+
*/
|
|
290
|
+
declare function isInPreparePhase(burnHeight: number, params: PoxCycleParams & {
|
|
291
|
+
prepareCycleLength: number
|
|
292
|
+
}): boolean;
|
|
293
|
+
type BondPhase = "too-early" | "open" | "locked" | "unlocked";
|
|
294
|
+
/**
|
|
295
|
+
* Coarse lifecycle phase of bond `bondIndex` at `burnHeight`: `too-early`
|
|
296
|
+
* (before the bond's start is registerable), `open`/`locked` while active,
|
|
297
|
+
* `unlocked` after 12 cycles.
|
|
298
|
+
*/
|
|
299
|
+
declare function bondPhaseAtHeight(bondIndex: number, burnHeight: number, params: BondCycleParams): BondPhase;
|
|
300
|
+
type BitcoinNetwork = "mainnet" | "testnet" | "regtest";
|
|
301
|
+
/**
|
|
302
|
+
* Byte-for-byte TypeScript mirrors of pox-5's Bitcoin-script helpers
|
|
303
|
+
* (`serialize-c-script-num`, `push-c-script-num`, `push-script-bytes`,
|
|
304
|
+
* `construct-lockup-script`, `construct-lockup-output-script`), pinned
|
|
305
|
+
* against the final contract in stacks-core 4.0.0. The contract validates a
|
|
306
|
+
* staker's L1 lockup output against exactly these bytes, so any divergence
|
|
307
|
+
* means a rejected registration — the read-onlys on-chain double as a
|
|
308
|
+
* cross-check oracle for these functions.
|
|
309
|
+
*/
|
|
310
|
+
/**
|
|
311
|
+
* Minimal little-endian ScriptNum encoding of a non-negative integer
|
|
312
|
+
* (`0` → empty; a `0x00` sign byte is appended when the top byte's high bit
|
|
313
|
+
* is set). Mirrors `serialize-c-script-num`, including its 2^39 ceiling.
|
|
314
|
+
*/
|
|
315
|
+
declare function serializeCScriptNum(n: number | bigint): Uint8Array;
|
|
316
|
+
/**
|
|
317
|
+
* Push arbitrary bytes onto a Bitcoin script: direct length byte under 76,
|
|
318
|
+
* `OP_PUSHDATA1` under 256, `OP_PUSHDATA2` otherwise. Mirrors
|
|
319
|
+
* `push-script-bytes`.
|
|
320
|
+
*/
|
|
321
|
+
declare function pushScriptBytes(bytes: Uint8Array): Uint8Array;
|
|
322
|
+
/**
|
|
323
|
+
* Push a numeric script value: `OP_0` for zero, the single-byte ops
|
|
324
|
+
* `OP_1`..`OP_16` for 1–16, else a minimal ScriptNum push. Mirrors
|
|
325
|
+
* `push-c-script-num`.
|
|
326
|
+
*/
|
|
327
|
+
declare function pushCScriptNum(n: number | bigint): Uint8Array;
|
|
328
|
+
/** `to-consensus-buff?` of a principal — the staker identity the script commits to. */
|
|
329
|
+
declare function stakerConsensusBuff(stxAddress: string): Uint8Array;
|
|
330
|
+
/**
|
|
331
|
+
* The 32-byte witness item the early-exit branch must reveal:
|
|
332
|
+
* `sha256(to-consensus-buff? staker)`. The script stores `sha256` of THIS,
|
|
333
|
+
* so revealing it proves which staker the exit is for.
|
|
334
|
+
*/
|
|
335
|
+
declare function stakerPreimage(stxAddress: string): Uint8Array;
|
|
336
|
+
type BuildLockupScriptOptions = {
|
|
337
|
+
/** Staker principal (standard or contract address). */
|
|
338
|
+
stxAddress: string
|
|
339
|
+
/** Burn height at which the CLTV branch becomes spendable. */
|
|
340
|
+
unlockBurnHeight: number | bigint
|
|
341
|
+
/** Staker-signature subscript, run last in BOTH branches. */
|
|
342
|
+
stakerUnlockBytes: Uint8Array | string
|
|
343
|
+
/** Per-bond early-unlock subscript (from `protocol-bonds.early-unlock-bytes`). */
|
|
344
|
+
earlyUnlockBytes: Uint8Array | string
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* The L1 lockup witness script. Mirrors `construct-lockup-script`:
|
|
348
|
+
*
|
|
349
|
+
* ```
|
|
350
|
+
* OP_IF
|
|
351
|
+
* <unlockBurnHeight> OP_CHECKLOCKTIMEVERIFY
|
|
352
|
+
* OP_ELSE
|
|
353
|
+
* OP_SIZE <32> OP_EQUALVERIFY OP_SHA256
|
|
354
|
+
* <sha256(sha256(consensus-buff(staker)))> OP_EQUALVERIFY
|
|
355
|
+
* <earlyUnlockBytes>
|
|
356
|
+
* OP_ENDIF
|
|
357
|
+
* OP_VERIFY
|
|
358
|
+
* <stakerUnlockBytes>
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare function buildLockupScript(opts: BuildLockupScriptOptions): Uint8Array;
|
|
362
|
+
/**
|
|
363
|
+
* P2WSH `scriptPubKey` for a lockup script: `0x0020 || sha256(script)`.
|
|
364
|
+
* Mirrors `construct-lockup-output-script`.
|
|
365
|
+
*/
|
|
366
|
+
declare function buildLockupOutputScript(opts: BuildLockupScriptOptions): Uint8Array;
|
|
367
|
+
/** The bech32 P2WSH address a staker sends their L1 BTC lockup to. */
|
|
368
|
+
declare function buildLockupAddress(opts: BuildLockupScriptOptions, network?: BitcoinNetwork): string;
|
|
369
|
+
/**
|
|
370
|
+
* The default staker subscript: `<pubkey> OP_CHECKSIG` — spendable by one
|
|
371
|
+
* key. Any script tail is valid as far as the contract is concerned; this is
|
|
372
|
+
* the common case.
|
|
373
|
+
*/
|
|
374
|
+
declare function buildDefaultStakerUnlockBytes(publicKey: Uint8Array | string): Uint8Array;
|
|
375
|
+
/**
|
|
376
|
+
* PoX-5 signer-key grants: SIP-018 structured-data signatures authorizing a
|
|
377
|
+
* signer-manager contract to use a signer key. Mirrors
|
|
378
|
+
* `pox-5.get-signer-grant-message-hash` — domain `pox-5-signer/1.0.0`,
|
|
379
|
+
* message `{ topic: "grant-authorization", signer-manager, auth-id }`.
|
|
380
|
+
*/
|
|
381
|
+
type SignerGrantOptions = {
|
|
382
|
+
/** The signer-manager contract principal being authorized. */
|
|
383
|
+
signerManager: string
|
|
384
|
+
/** Replay-protection id, chosen by the signer. */
|
|
385
|
+
authId: bigint | number
|
|
386
|
+
/** Stacks chain id (`mainnet.id` / `testnet.id`). */
|
|
387
|
+
chainId: number
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* The 32-byte hash a signer signs to grant their key — byte-identical to the
|
|
391
|
+
* contract's `get-signer-grant-message-hash` read-only (which doubles as an
|
|
392
|
+
* on-chain cross-check).
|
|
393
|
+
*/
|
|
394
|
+
declare function computeSignerGrantHash(opts: SignerGrantOptions): Uint8Array;
|
|
395
|
+
/**
|
|
396
|
+
* Sign a signer-key grant. Returns the 65-byte recoverable signature in RSV
|
|
397
|
+
* order (recovery byte last), hex — the layout `grant-signer-key`'s
|
|
398
|
+
* `signer-sig (buff 65)` expects.
|
|
399
|
+
*/
|
|
400
|
+
declare function signSignerGrant(account: LocalAccount, opts: SignerGrantOptions): Promise<string>;
|
|
401
|
+
/**
|
|
402
|
+
* Verify a signer-key grant signature locally: recover the pubkey from the
|
|
403
|
+
* RSV signature over the grant hash and compare. Returns `false` for
|
|
404
|
+
* malformed input rather than throwing.
|
|
405
|
+
*/
|
|
406
|
+
declare function verifySignerGrant(opts: SignerGrantOptions & {
|
|
407
|
+
publicKey: Uint8Array | string
|
|
408
|
+
signature: Uint8Array | string
|
|
409
|
+
}): boolean;
|
|
410
|
+
type FungibleComparator = "eq" | "gt" | "gte" | "lt" | "lte";
|
|
411
|
+
type NonFungibleComparator = "sent" | "not-sent";
|
|
412
|
+
type StxPostCondition = {
|
|
413
|
+
type: "stx-postcondition"
|
|
414
|
+
address: string
|
|
415
|
+
condition: FungibleComparator
|
|
416
|
+
amount: string | bigint | number
|
|
417
|
+
};
|
|
418
|
+
type FtPostCondition = {
|
|
419
|
+
type: "ft-postcondition"
|
|
420
|
+
address: string
|
|
421
|
+
condition: FungibleComparator
|
|
422
|
+
asset: string
|
|
423
|
+
amount: string | bigint | number
|
|
424
|
+
};
|
|
425
|
+
type NftPostCondition = {
|
|
426
|
+
type: "nft-postcondition"
|
|
427
|
+
address: string
|
|
428
|
+
condition: NonFungibleComparator
|
|
429
|
+
asset: string
|
|
430
|
+
assetId: ClarityValue
|
|
431
|
+
};
|
|
432
|
+
type StakingPostCondition = {
|
|
433
|
+
type: "staking-postcondition"
|
|
434
|
+
address: string
|
|
435
|
+
condition: FungibleComparator
|
|
436
|
+
amount: string | bigint | number
|
|
437
|
+
};
|
|
438
|
+
type PoxComparator = "will-not-perform" | "may-perform" | "will-perform";
|
|
439
|
+
type PoxPostCondition = {
|
|
440
|
+
type: "pox-postcondition"
|
|
441
|
+
address: string
|
|
442
|
+
condition: PoxComparator
|
|
443
|
+
};
|
|
444
|
+
type PostCondition = StxPostCondition | FtPostCondition | NftPostCondition | StakingPostCondition | PoxPostCondition;
|
|
445
|
+
type IntegerType = number | string | bigint | Uint8Array;
|
|
446
|
+
/**
|
|
447
|
+
* Named fee tiers. `'low' | 'mid' | 'high'` map to the node's three fee
|
|
448
|
+
* estimations; `'min'` is the node's minimum relay fee — 1 uSTX per byte of
|
|
449
|
+
* the serialized transaction, computable offline.
|
|
450
|
+
*/
|
|
451
|
+
type FeeTier = "min" | "low" | "mid" | "high";
|
|
452
|
+
/** Fee input accepted by wallet actions: an explicit amount or a named tier. */
|
|
453
|
+
type FeeParam = IntegerType | FeeTier;
|
|
454
|
+
type CallContractParams = {
|
|
455
|
+
contract: string
|
|
456
|
+
functionName: string
|
|
457
|
+
functionArgs?: ClarityValue[]
|
|
458
|
+
fee?: FeeParam
|
|
459
|
+
nonce?: IntegerType
|
|
460
|
+
postConditionMode?: "allow" | "deny"
|
|
461
|
+
postConditions?: PostCondition[]
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* PoX-5 contract calls and reads, pinned against the final contract in
|
|
465
|
+
* stacks-core 4.0.0. Wallet actions route through `callContract`, so they
|
|
466
|
+
* inherit fee tiers, nonce management, and typed broadcast errors; pair the
|
|
467
|
+
* returned txid with `waitForTransactionReceipt` to await inclusion.
|
|
468
|
+
*
|
|
469
|
+
* Note: pox-5 uses `contract-caller`/`tx-sender` directly (there is no
|
|
470
|
+
* `allow-contract-caller` indirection like pox-4). Amount/lock safety is
|
|
471
|
+
* expressed with the new Epoch 4.0 `Staking`/`Pox` post-conditions — pass
|
|
472
|
+
* them via `postConditions` on any of these actions.
|
|
473
|
+
*/
|
|
474
|
+
/** Resolve the boot `pox-5` contract id for the client's chain. */
|
|
475
|
+
declare function pox5ContractId(client: Client): string;
|
|
476
|
+
type TxOptions = Pick<CallContractParams, "fee" | "nonce" | "postConditions" | "postConditionMode">;
|
|
477
|
+
/**
|
|
478
|
+
* One proven L1 timelock output — a Bitcoin SPV inclusion proof of the lockup
|
|
479
|
+
* tx plus which output is the lockup. `@secondlayer/stacks/bitcoin`'s
|
|
480
|
+
* `buildTxProof` produces the proof fields.
|
|
481
|
+
*/
|
|
482
|
+
type L1LockupOutput = {
|
|
483
|
+
/** Burn height of the Bitcoin block containing the lockup tx. */
|
|
484
|
+
height: IntegerType
|
|
485
|
+
/** Raw Bitcoin tx (witness-stripped), hex or bytes. */
|
|
486
|
+
tx: Uint8Array | string
|
|
487
|
+
outputIndex: IntegerType
|
|
488
|
+
/** 80-byte Bitcoin block header. */
|
|
489
|
+
header: Uint8Array | string
|
|
490
|
+
/** Merkle siblings, leaf→root (max 14). */
|
|
491
|
+
leafHashes: Array<Uint8Array | string>
|
|
492
|
+
txCount: IntegerType
|
|
493
|
+
txIndex: IntegerType
|
|
494
|
+
/** Output value in sats. */
|
|
495
|
+
amount: IntegerType
|
|
496
|
+
unlockBurnHeight: IntegerType
|
|
497
|
+
};
|
|
498
|
+
/** BTC side of a bond registration: proven L1 lockups, or an sBTC amount. */
|
|
499
|
+
type BtcLockup = {
|
|
500
|
+
l1Outputs: L1LockupOutput[]
|
|
501
|
+
stakerUnlockBytes: Uint8Array | string
|
|
502
|
+
} | {
|
|
503
|
+
sbtcSats: IntegerType
|
|
504
|
+
};
|
|
505
|
+
type SetupBondParams = TxOptions & {
|
|
506
|
+
bondIndex: IntegerType
|
|
507
|
+
/** Target yield rate, basis points. */
|
|
508
|
+
targetRate: IntegerType
|
|
509
|
+
/** µSTX per 100 sats (BTCUSD / STXUSD representation). */
|
|
510
|
+
stxValueRatio: IntegerType
|
|
511
|
+
/** Minimum locked STX relative to BTC, basis points. */
|
|
512
|
+
minUstxRatio: IntegerType
|
|
513
|
+
/** Early-unlock subscript for this bond's L1 lockup scripts (max 683B). */
|
|
514
|
+
earlyUnlockBytes: Uint8Array | string
|
|
515
|
+
allowlist: Array<{
|
|
516
|
+
staker: string
|
|
517
|
+
maxSats: IntegerType
|
|
518
|
+
}>
|
|
519
|
+
};
|
|
520
|
+
type RegisterForBondParams = TxOptions & {
|
|
521
|
+
bondIndex: IntegerType
|
|
522
|
+
/** Signer-manager contract principal. */
|
|
523
|
+
signerManager: string
|
|
524
|
+
amountUstx: IntegerType
|
|
525
|
+
btcLockup: BtcLockup
|
|
526
|
+
signerCalldata?: Uint8Array | string
|
|
527
|
+
};
|
|
528
|
+
type UpdateBondRegistrationParams = TxOptions & {
|
|
529
|
+
signerManager: string
|
|
530
|
+
oldSignerManager: string
|
|
531
|
+
signerCalldata?: Uint8Array | string
|
|
532
|
+
};
|
|
533
|
+
type StakeParams = TxOptions & {
|
|
534
|
+
signerManager: string
|
|
535
|
+
amountUstx: IntegerType
|
|
536
|
+
numCycles: IntegerType
|
|
537
|
+
startBurnHeight: IntegerType
|
|
538
|
+
signerCalldata?: Uint8Array | string
|
|
539
|
+
};
|
|
540
|
+
type StakeUpdateParams = TxOptions & {
|
|
541
|
+
signerManager: string
|
|
542
|
+
oldSignerManager: string
|
|
543
|
+
cyclesToExtend: IntegerType
|
|
544
|
+
amountIncrease: IntegerType
|
|
545
|
+
signerCalldata?: Uint8Array | string
|
|
546
|
+
};
|
|
547
|
+
type UnstakeParams = TxOptions & {
|
|
548
|
+
oldSignerManager: string
|
|
549
|
+
};
|
|
550
|
+
type UnstakeSbtcParams = TxOptions & {
|
|
551
|
+
signerManager: string
|
|
552
|
+
amountSats: IntegerType
|
|
553
|
+
};
|
|
554
|
+
type AnnounceL1EarlyExitParams = TxOptions & {
|
|
555
|
+
staker: string
|
|
556
|
+
oldSignerManager: string
|
|
557
|
+
};
|
|
558
|
+
type CalculateRewardsParams = TxOptions & {
|
|
559
|
+
bondPeriods: IntegerType[]
|
|
560
|
+
};
|
|
561
|
+
type ClaimRewardsParams = TxOptions & {
|
|
562
|
+
bondPeriods: IntegerType[]
|
|
563
|
+
rewardCycle: IntegerType
|
|
564
|
+
};
|
|
565
|
+
type ClaimStakerRewardsForSignerParams = TxOptions & {
|
|
566
|
+
staker: string
|
|
567
|
+
rewardCycle: IntegerType
|
|
568
|
+
bondIndex?: IntegerType
|
|
569
|
+
};
|
|
570
|
+
type GrantSignerKeyParams = TxOptions & {
|
|
571
|
+
/** 33-byte compressed signer key. */
|
|
572
|
+
signerKey: Uint8Array | string
|
|
573
|
+
signerManager: string
|
|
574
|
+
authId: IntegerType
|
|
575
|
+
/** 65-byte RSV signature from `signSignerGrant`. */
|
|
576
|
+
signerSig: Uint8Array | string
|
|
577
|
+
};
|
|
578
|
+
type RevokeSignerGrantParams = TxOptions & {
|
|
579
|
+
signerManager: string
|
|
580
|
+
signerKey: Uint8Array | string
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* A staker's whole PoX-5 position in ONE batched request: staker info, bond
|
|
584
|
+
* membership, custodied sBTC, and the current cycle — the state a dashboard
|
|
585
|
+
* or agent polls, without four round-trips.
|
|
586
|
+
*/
|
|
587
|
+
type StakerState = {
|
|
588
|
+
stakerInfo: ClarityValue
|
|
589
|
+
bondMembership: ClarityValue
|
|
590
|
+
custodiedSbtc: ClarityValue
|
|
591
|
+
currentCycle: ClarityValue
|
|
592
|
+
};
|
|
593
|
+
/** Actions provided by the pox5 extension. */
|
|
594
|
+
type Pox5Actions = {
|
|
595
|
+
pox5: {
|
|
596
|
+
isActive: () => Promise<boolean>
|
|
597
|
+
getActivation: () => Promise<Pox5Activation | undefined>
|
|
598
|
+
contractId: () => string
|
|
599
|
+
getStakerState: (staker: string) => Promise<StakerState>
|
|
600
|
+
getStakerInfo: (staker: string) => Promise<ClarityValue>
|
|
601
|
+
getBondMembership: (staker: string) => Promise<ClarityValue>
|
|
602
|
+
getProtocolBond: (bondIndex: IntegerType) => Promise<ClarityValue>
|
|
603
|
+
getBondAllowance: (bondIndex: IntegerType, staker: string) => Promise<ClarityValue>
|
|
604
|
+
getTotalSbtcStakedForBond: (bondIndex: IntegerType) => Promise<ClarityValue>
|
|
605
|
+
getStakerCustodiedSbtc: (staker: string) => Promise<ClarityValue>
|
|
606
|
+
hasAnnouncedL1EarlyExit: (bondIndex: IntegerType, staker: string) => Promise<ClarityValue>
|
|
607
|
+
getBondL1UnlockHeight: (bondIndex: IntegerType) => Promise<ClarityValue>
|
|
608
|
+
getSignerInfo: (signer: string) => Promise<ClarityValue>
|
|
609
|
+
verifySignerKeyGrant: (signerManager: string, signerKey: Uint8Array | string) => Promise<ClarityValue>
|
|
610
|
+
getCurrentRewardCycle: () => Promise<ClarityValue>
|
|
611
|
+
getFirstRewardCycle: () => Promise<ClarityValue>
|
|
612
|
+
setupBond: (params: SetupBondParams) => Promise<string>
|
|
613
|
+
registerForBond: (params: RegisterForBondParams) => Promise<string>
|
|
614
|
+
updateBondRegistration: (params: UpdateBondRegistrationParams) => Promise<string>
|
|
615
|
+
stake: (params: StakeParams) => Promise<string>
|
|
616
|
+
stakeUpdate: (params: StakeUpdateParams) => Promise<string>
|
|
617
|
+
unstake: (params: UnstakeParams) => Promise<string>
|
|
618
|
+
unstakeSbtc: (params: UnstakeSbtcParams) => Promise<string>
|
|
619
|
+
announceL1EarlyExit: (params: AnnounceL1EarlyExitParams) => Promise<string>
|
|
620
|
+
calculateRewards: (params: CalculateRewardsParams) => Promise<string>
|
|
621
|
+
claimRewards: (params: ClaimRewardsParams) => Promise<string>
|
|
622
|
+
claimStakerRewardsForSigner: (params: ClaimStakerRewardsForSignerParams) => Promise<string>
|
|
623
|
+
grantSignerKey: (params: GrantSignerKeyParams) => Promise<string>
|
|
624
|
+
revokeSignerGrant: (params: RevokeSignerGrantParams) => Promise<string>
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
/**
|
|
628
|
+
* PoX-5 extension for the Stacks client.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* const client = createWalletClient({ chain: mainnet, transport: http(), account })
|
|
632
|
+
* .extend(pox5());
|
|
633
|
+
*
|
|
634
|
+
* if (await client.pox5.isActive()) {
|
|
635
|
+
* const txid = await client.pox5.stake({
|
|
636
|
+
* signerManager: "SP….signer-mgr",
|
|
637
|
+
* amountUstx: 100_000_000_000n,
|
|
638
|
+
* numCycles: 12,
|
|
639
|
+
* startBurnHeight: 960_231,
|
|
640
|
+
* fee: "low",
|
|
641
|
+
* });
|
|
642
|
+
* await client.waitForTransactionReceipt({ txid });
|
|
643
|
+
* }
|
|
644
|
+
*/
|
|
645
|
+
declare function pox5(): (client: Client) => Pox5Actions;
|
|
646
|
+
export { verifySignerGrant, stakerPreimage, stakerConsensusBuff, signSignerGrant, serializeCScriptNum, rewardCycleToBurnHeight, pushScriptBytes, pushCScriptNum, pox5ContractId, pox5, isPox5Active, isInPreparePhase, getPox5Activation, computeSignerGrantHash, burnHeightToRewardCycle, burnHeightToDistributionIndex, buildLockupScript, buildLockupOutputScript, buildLockupAddress, buildDefaultStakerUnlockBytes, bondUnlockCycle, bondPhaseAtHeight, bondPeriodToRewardCycle, bondPeriodToBurnHeight, assertPox5Active, UpdateBondRegistrationParams, UnstakeSbtcParams, UnstakeParams, StakerState, StakeUpdateParams, StakeParams, SignerGrantOptions, SetupBondParams, RevokeSignerGrantParams, RegisterForBondParams, PoxCycleParams, Pox5Activation, Pox5Actions, POX5_SIGNER_DOMAIN, POX5_CONTRACT_NAME, POX5_ACTIVATION_BURN_HEIGHT_MAINNET, MAX_NUM_CYCLES, L1LockupOutput, GrantSignerKeyParams, ClaimStakerRewardsForSignerParams, ClaimRewardsParams, CalculateRewardsParams, C_SCRIPT_NUM_MAX, BuildLockupScriptOptions, BtcLockup, BondPhase, BondCycleParams, BOND_LENGTH_CYCLES, BOND_GAP_CYCLES, BITCOIN_LOCKTIME_THRESHOLD, AnnounceL1EarlyExitParams };
|