-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
529 lines (458 loc) · 15.9 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
import * as bindings from './loader';
export * from './loader';
export const StacksNativeEncodingBindings = bindings;
export default StacksNativeEncodingBindings;
export type TxPostCondition = PostConditionStx | PostConditionFungible | PostConditionNonfungible;
export interface DecodedPostConditionsResult {
post_condition_mode: PostConditionModeID;
post_conditions: TxPostCondition[]
}
export interface DecodedTxResult {
/** Hex encoded string of the serialized transaction */
tx_id: string;
version: TransactionVersion;
chain_id: number;
auth: TxAuthStandard | TxAuthSponsored;
anchor_mode: AnchorModeID;
post_condition_mode: PostConditionModeID;
post_conditions: TxPostCondition[];
/** Hex string */
post_conditions_buffer: string;
payload:
| TxPayloadTokenTransfer
| TxPayloadSmartContract
| TxPayloadContractCall
| TxPayloadPoisonMicroblock
| TxPayloadCoinbase
| TxPayloadCoinbaseToAltRecipient
| TxPayloadVersionedSmartContract
| TxPayloadTenureChange
| TxPayloadNakamotoCoinbase;
}
export enum PostConditionAssetInfoID {
STX = 0,
FungibleAsset = 1,
NonfungibleAsset = 2,
}
export interface PostConditionStx {
asset_info_id: PostConditionAssetInfoID.STX;
principal: PostConditionPrincipal;
condition_code: PostConditionFungibleConditionCodeID;
condition_name: PostConditionFungibleConditionCodeName;
amount: string;
}
export interface PostConditionFungible {
asset_info_id: PostConditionAssetInfoID.FungibleAsset;
principal: PostConditionPrincipal;
asset: PostConditionAssetInfo;
condition_code: PostConditionFungibleConditionCodeID;
condition_name: PostConditionFungibleConditionCodeName;
amount: string;
}
export interface PostConditionNonfungible {
asset_info_id: PostConditionAssetInfoID.NonfungibleAsset;
principal: PostConditionPrincipal;
asset: PostConditionAssetInfo;
asset_value: ClarityValueAbstract;
condition_code: PostConditionNonfungibleConditionCodeID;
condition_name: PostConditionNonFungibleConditionName;
}
export interface PostConditionAssetInfo {
contract_address: string;
contract_name: string;
asset_name: string;
}
export enum PostConditionNonfungibleConditionCodeID {
Sent = 0x10,
NotSent = 0x11,
}
export enum PostConditionNonFungibleConditionName {
Sent = "sent",
NotSent = "not_sent",
}
export enum PostConditionFungibleConditionCodeID {
SentEq = 0x01,
SentGt = 0x02,
SentGe = 0x03,
SentLt = 0x04,
SentLe = 0x05,
}
export enum PostConditionFungibleConditionCodeName {
SentEq = "sent_equal_to",
SentGt = "sent_greater_than",
SentGe = "sent_greater_than_or_equal_to",
SentLt = "sent_less_than",
SentLe = "sent_less_than_or_equal_to",
}
export enum PostConditionPrincipalTypeID {
/** A STX post-condition, which pertains to the origin account's STX. */
Origin = 0x01,
/** A Fungible token post-condition, which pertains to one of the origin account's fungible tokens. */
Standard = 0x02,
/** A Non-fungible token post-condition, which pertains to one of the origin account's non-fungible tokens. */
Contract = 0x03,
}
export type PostConditionPrincipal = PostConditionPrincipalOrigin | PostConditionPrincipalStandard | PostConditionPrincipalContract;
export interface PostConditionPrincipalOrigin {
type_id: PostConditionPrincipalTypeID.Origin
}
export interface PostConditionPrincipalStandard {
type_id: PostConditionPrincipalTypeID.Standard;
address_version: number;
/** Hex string */
address_hash_bytes: string;
address: string;
}
export interface PostConditionPrincipalContract {
type_id: PostConditionPrincipalTypeID.Contract;
address_version: number;
/** Hex string */
address_hash_bytes: string;
address: string;
contract_name: string;
}
export interface TxPayloadTokenTransfer {
type_id: TxPayloadTypeID.TokenTransfer;
recipient: PrincipalStandardData | PrincipalContractData;
amount: string;
/** Hex encoded string of the 34-bytes */
memo_hex: string;
}
export enum PrincipalTypeID {
Standard = 5,
Contract = 6,
}
export interface PrincipalStandardData {
type_id: PrincipalTypeID.Standard;
address_version: number;
/** Hex string */
address_hash_bytes: string;
address: string;
}
export interface PrincipalContractData {
type_id: PrincipalTypeID.Contract;
contract_name: string;
address_version: number;
/** Hex string */
address_hash_bytes: string;
address: string;
}
export interface TxPayloadSmartContract {
type_id: TxPayloadTypeID.SmartContract;
contract_name: string;
code_body: string;
}
export interface TxPayloadContractCall {
type_id: TxPayloadTypeID.ContractCall;
address_version: number;
/** Hex string */
address_hash_bytes: string;
address: string;
contract_name: string;
function_name: string;
function_args: ClarityValueAbstract[];
/** Hex string */
function_args_buffer: string;
}
export interface TxPayloadPoisonMicroblock {
type_id: TxPayloadTypeID.PoisonMicroblock;
microblock_header_1: TxMicroblockHeader;
microblock_header_2: TxMicroblockHeader;
}
export interface TxPayloadCoinbase {
type_id: TxPayloadTypeID.Coinbase;
/** Hex string */
payload_buffer: string;
}
export interface TxPayloadCoinbaseToAltRecipient {
type_id: TxPayloadTypeID.CoinbaseToAltRecipient;
/** Hex string */
payload_buffer: string;
recipient: PrincipalStandardData | PrincipalContractData;
}
export interface TxPayloadNakamotoCoinbase {
type_id: TxPayloadTypeID.NakamotoCoinbase;
/** Hex string */
payload_buffer: string;
/** Optional, null if not specified */
recipient: PrincipalStandardData | PrincipalContractData | null;
/** Hex string */
vrf_proof: string;
}
export interface TxPayloadVersionedSmartContract {
type_id: TxPayloadTypeID.VersionedSmartContract;
clarity_version: ClarityVersion;
contract_name: string;
code_body: string;
}
export interface TxPayloadTenureChange {
type_id: TxPayloadTypeID.TenureChange;
/** Consensus hash of this tenure. Corresponds to the sortition in which the miner of this
* block was chosen. It may be the case that this miner's tenure gets _extended_ across
* subsequent sortitions; if this happens, then this `consensus_hash` value _remains the same_
* as the sortition in which the winning block-commit was mined. */
tenure_consensus_hash: string;
/** Consensus hash of the previous tenure. Corresponds to the sortition of the previous winning block-commit. */
prev_tenure_consensus_hash: string;
/** Current consensus hash on the underlying burnchain. Corresponds to the last-seen sortition. */
burn_view_consensus_hash: string;
/** The StacksBlockId of the last block from the previous tenure */
previous_tenure_end: string;
/** The number of blocks produced since the last sortition-linked tenure */
previous_tenure_blocks: number;
/** Cause of change in mining tenure. Depending on cause, tenure can be ended or extended. */
cause: TenureChangeCause;
/** (Hex string) The ECDSA public key hash of the current tenure */
pubkey_hash: string;
}
export enum TenureChangeCause {
/** A valid winning block-commit */
BlockFound = 0,
/** The next burnchain block is taking too long, so extend the runtime budget */
Extended = 1,
}
export enum TxPayloadTypeID {
TokenTransfer = 0,
SmartContract = 1,
ContractCall = 2,
PoisonMicroblock = 3,
Coinbase = 4,
CoinbaseToAltRecipient = 5,
VersionedSmartContract = 6,
TenureChange = 7,
NakamotoCoinbase = 8,
}
export enum PostConditionAuthFlag {
Standard = 0x04,
Sponsored = 0x05,
}
export interface TxAuthStandard {
type_id: PostConditionAuthFlag.Standard;
origin_condition: DecodedTxSpendingConditionSingleSig | DecodedTxSpendingConditionMultiSig;
}
export interface TxAuthSponsored {
type_id: PostConditionAuthFlag.Sponsored;
origin_condition: DecodedTxSpendingConditionSingleSig | DecodedTxSpendingConditionMultiSig;
sponsor_condition: DecodedTxSpendingConditionSingleSig | DecodedTxSpendingConditionMultiSig;
}
export enum TxSpendingConditionSingleSigHashMode {
/** hash160(public-key), same as bitcoin's p2pkh */
P2PKH = 0x00,
/** hash160(segwit-program-00(p2pkh)), same as bitcoin's p2sh-p2wpkh */
P2WPKH = 0x02,
}
export enum TxSpendingConditionMultiSigHashMode {
/** hash160(multisig-redeem-script), same as bitcoin's multisig p2sh */
P2SH = 0x01,
/** hash160(multisig-redeem-script), same as bitcoin's multisig p2sh (non-sequential signing) */
P2SHNonSequential = 0x05,
/** hash160(segwit-program-00(public-keys)), same as bitcoin's p2sh-p2wsh */
P2WSH = 0x03,
/** hash160(segwit-program-00(public-keys)), same as bitcoin's p2sh-p2wsh (non-sequential signing) */
P2WSHNonSequential = 0x07,
}
export enum ClarityVersion {
Clarity1 = 1,
Clarity2 = 2,
Clarity3 = 3,
}
export interface DecodedTxSpendingConditionSingleSig {
hash_mode: TxSpendingConditionSingleSigHashMode;
signer: DecodedStacksAddress;
nonce: string;
tx_fee: string;
/** A 1-byte public key encoding field to indicate whether or not the public key should be compressed before hashing. */
key_encoding: TxPublicKeyEncoding;
signature: string;
}
export interface DecodedTxSpendingConditionMultiSig {
hash_mode: TxSpendingConditionMultiSigHashMode;
signer: DecodedStacksAddress;
nonce: string;
tx_fee: string;
fields: (TxAuthFieldPublicKey | TxAuthFieldSignature)[];
signatures_required: number,
}
export enum TxAuthFieldTypeID {
/** The next 33 bytes are a compressed secp256k1 public key. If the field ID is 0x00, the key will be loaded as a compressed secp256k1 public key. */
PublicKeyCompressed = 0x00,
/** The next 33 bytes are a compressed secp256k1 public key. If it is 0x01, then the key will be loaded as an uncompressed secp256k1 public key. */
PublicKeyUncompressed = 0x01,
/** The next 65 bytes are a recoverable secp256k1 ECDSA signature. If the field ID is 0x02, then the recovered public key will be loaded as a compressed public key. */
SignatureCompressed = 0x02,
/** The next 65 bytes are a recoverable secp256k1 ECDSA signature. If it is 0x03, then the recovered public key will be loaded as an uncompressed public key. */
SignatureUncompressed = 0x03,
}
export interface TxAuthFieldPublicKey {
type_id: TxAuthFieldTypeID.PublicKeyCompressed | TxAuthFieldTypeID.PublicKeyUncompressed;
/** Hex encoded public key bytes. */
public_key: string;
}
export interface TxAuthFieldSignature {
type_id: TxAuthFieldTypeID.SignatureCompressed | TxAuthFieldTypeID.SignatureUncompressed;
/** Hex encoded signatures bytes. */
signature: string;
}
export interface TxMicroblockHeader {
/** Hex string */
buffer: string;
version: number;
sequence: number;
/** Hex string */
prev_block: string;
/** Hex string */
tx_merkle_root: string;
/** Hex string */
signature: string;
}
export enum TxPublicKeyEncoding {
Compressed = 0x00,
Uncompressed = 0x01,
}
export interface DecodedStacksAddress {
address_version: number;
/** Hex-encoded string of the hash160 signer address. */
address_hash_bytes: string;
address: string;
}
export enum TransactionVersion {
Mainnet = 0x00,
Testnet = 0x80,
}
export enum AnchorModeID {
/** The transaction MUST be included in an anchored block. */
OnChainOnly = 1,
/** The transaction MUST be included in a microblock. */
OffChainOnly = 2,
/** The leader can choose where to include the transaction. */
Any = 3,
}
export enum PostConditionModeID {
/** This transaction may affect other assets not listed in the post-conditions. */
Allow = 0x01,
/** This transaction may NOT affect other assets besides those listed in the post-conditions. */
Deny = 0x02,
}
export interface ClarityValueCommon {
/** Clarity repr value */
repr: string;
/** Hex encoded string of the serialized Clarity value */
hex: string;
}
export interface ClarityValueAbstract extends ClarityValueCommon {
type_id: number;
}
export enum ClarityTypeID {
Int = 0,
UInt = 1,
Buffer = 2,
BoolTrue = 3,
BoolFalse = 4,
PrincipalStandard = 5,
PrincipalContract = 6,
ResponseOk = 7,
ResponseError = 8,
OptionalNone = 9,
OptionalSome = 10,
List = 11,
Tuple = 12,
StringAscii = 13,
StringUtf8 = 14,
}
export interface ClarityValueInt extends ClarityValueCommon {
type_id: ClarityTypeID.Int;
/** String-quoted signed integer */
value: string;
}
export interface ClarityValueUInt extends ClarityValueCommon {
type_id: ClarityTypeID.UInt;
/** String-quoted unsigned integer */
value: string;
}
export interface ClarityValueBoolTrue extends ClarityValueCommon {
type_id: ClarityTypeID.BoolTrue;
value: true;
}
export interface ClarityValueBoolFalse extends ClarityValueCommon {
type_id: ClarityTypeID.BoolFalse;
value: false;
}
export interface ClarityValueBuffer extends ClarityValueCommon {
type_id: ClarityTypeID.Buffer;
/** Hex string */
buffer: string;
}
export interface ClarityValueList<T extends ClarityValue = ClarityValue> extends ClarityValueCommon {
type_id: ClarityTypeID.List;
list: T[];
}
export interface ClarityValueStringAscii extends ClarityValueCommon {
type_id: ClarityTypeID.StringAscii;
data: string;
}
export interface ClarityValueStringUtf8 extends ClarityValueCommon {
type_id: ClarityTypeID.StringUtf8;
data: string;
}
export interface ClarityValuePrincipalStandard extends ClarityValueCommon {
type_id: ClarityTypeID.PrincipalStandard;
address: string;
address_version: number;
/** Hex string */
address_hash_bytes: string;
}
export interface ClarityValuePrincipalContract extends ClarityValueCommon {
type_id: ClarityTypeID.PrincipalContract;
address: string;
address_version: number;
/** Hex string */
address_hash_bytes: string;
contract_name: string;
}
export type ClarityTupleData<T extends ClarityValue = ClarityValue> = { [key: string]: T };
export interface ClarityValueTuple<T extends ClarityTupleData = ClarityTupleData> extends ClarityValueCommon {
type_id: ClarityTypeID.Tuple;
data: T;
}
export interface ClarityValueOptionalSome<T extends ClarityValue = ClarityValue> extends ClarityValueCommon {
type_id: ClarityTypeID.OptionalSome;
value: T;
}
export interface ClarityValueOptionalNone extends ClarityValueCommon {
type_id: ClarityTypeID.OptionalNone;
}
export interface ClarityValueResponseOk<T extends ClarityValue = ClarityValue> extends ClarityValueCommon {
type_id: ClarityTypeID.ResponseOk;
value: T;
}
export interface ClarityValueResponseError<T extends ClarityValue = ClarityValue> extends ClarityValueCommon {
type_id: ClarityTypeID.ResponseError;
value: T;
}
export type ClarityValue =
| ClarityValueInt
| ClarityValueUInt
| ClarityValueBoolTrue
| ClarityValueBoolFalse
| ClarityValueBuffer
| ClarityValueList
| ClarityValueStringAscii
| ClarityValueStringUtf8
| ClarityValuePrincipalStandard
| ClarityValuePrincipalContract
| ClarityValueTuple
| ClarityValueOptionalSome
| ClarityValueOptionalNone
| ClarityValueResponseOk
| ClarityValueResponseError;
export type ClarityValueOptional<T extends ClarityValue = ClarityValue> = ClarityValueOptionalSome<T> | ClarityValueOptionalNone;
export type ClarityValueBool = ClarityValueBoolTrue | ClarityValueBoolFalse;
export type ClarityValueResponse<TOk extends ClarityValue = ClarityValue, TError extends ClarityValue = ClarityValue> = ClarityValueResponseOk<TOk> | ClarityValueResponseError<TError>;
/**
* Type for commonly used `(optional bool)`
*/
export type ClarityValueOptionalBool = ClarityValueOptional<ClarityValueBool>;
/**
* Type for commonly used `(optional uint)`
*/
export type ClarityValueOptionalUInt = ClarityValueOptional<ClarityValueUInt>;