forked from HeliosLang/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helios.d.ts
4947 lines (4945 loc) · 148 KB
/
helios.d.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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Needed by transfer() methods
* @typedef {{
* transferByteArrayData: (bytes: number[]) => any,
* transferConstrData: (index: number, fields: any[]) => any,
* transferIntData: (value: bigint) => any,
* transferListData: (items: any[]) => any,
* transferMapData: (pairs: [any, any][]) => any,
* transferSite: (src: any, startPos: number, endPos: number, codeMapSite: null | any) => any,
* transferSource: (raw: string, name: string) => any,
* transferUplcBool: (site: any, value: boolean) => any,
* transferUplcBuiltin: (site: any, name: string | number) => any,
* transferUplcByteArray: (site: any, bytes: number[]) => any,
* transferUplcCall: (site: any, a: any, b: any) => any,
* transferUplcConst: (value: any) => any,
* transferUplcDataValue: (site: any, data: any) => any,
* transferUplcDelay: (site: any, expr: any) => any,
* transferUplcError: (site: any, msg: string) => any,
* transferUplcForce: (site: any, expr: any) => any,
* transferUplcInt: (site: any, value: bigint, signed: boolean) => any,
* transferUplcLambda: (site: any, rhs: any, name: null | string) => any,
* transferUplcList: (site: any, itemType: any, items: any[]) => any,
* transferUplcPair: (site: any, first: any, second: any) => any,
* transferUplcString: (site: any, value: string) => any,
* transferUplcType: (typeBits: string) => any,
* transferUplcUnit: (site: any) => any,
* transferUplcVariable: (site: any, index: any) => any
* }} TransferUplcAst
*/
/**
* Converts a hexadecimal string into a list of bytes.
* @example
* hexToBytes("00ff34") == [0, 255, 52]
* @param {string} hex
* @returns {number[]}
*/
export function hexToBytes(hex: string): number[];
/**
* Converts a list of uint8 bytes into its hexadecimal string representation.
* @example
* bytesToHex([0, 255, 52]) == "00ff34"
* @param {number[]} bytes
* @returns {string}
*/
export function bytesToHex(bytes: number[]): string;
/**
* Encodes a string into a list of uint8 bytes using UTF-8 encoding.
* @example
* textToBytes("hello world") == [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
* @param {string} str
* @returns {number[]}
*/
export function textToBytes(str: string): number[];
/**
* Decodes a list of uint8 bytes into a string using UTF-8 encoding.
* @example
* bytesToText([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) == "hello world"
* @param {number[]} bytes
* @returns {string}
*/
export function bytesToText(bytes: number[]): string;
/**
* Template string tag function that doesn't do anything and just returns the template string as a string.
* Can be used as a marker of Helios sources so that syntax highlighting can work inside JS/TS files.
* @example
* hl`hello ${"world"}!` == "hello world!"
* @param {string[]} a
* @param {...any} b
* @returns {string}
*/
export function hl(a: string[], ...b: any[]): string;
/**
* Deserializes a flat encoded `UplcProgram`.
* @param {number[]} bytes
* @param {ProgramProperties} properties
* @returns {UplcProgram}
*/
export function deserializeUplcBytes(bytes: number[], properties?: ProgramProperties): UplcProgram;
/**
* Parses a plutus core program. Returns a `UplcProgram` instance.
* @param {string | {cborHex: string}} json a raw JSON string or a parsed JSON object
* @returns {UplcProgram}
*/
export function deserializeUplc(json: string | {
cborHex: string;
}): UplcProgram;
/**
* @template {HeliosData} T
*/
/**
* Quickly extract the script purpose header of a script source, by parsing only the minimally necessary characters.
* @param {string} rawSrc
* @returns {null | [ScriptPurpose, string]} Returns `null` if the script header is missing or syntactically incorrect. The first string returned is the script purpose, the second value returned is the script name.
*/
export function extractScriptPurposeAndName(rawSrc: string): null | [ScriptPurpose, string];
/**
* Returns Uint8Array with the same length as the number of chars in the script.
* Each resulting byte respresents a different syntax category.
* This approach should be faster than a RegExp based a approach.
* @param {string} src
* @returns {Uint8Array}
*/
export function highlight(src: string): Uint8Array;
/**
* Current version of the Helios library.
*/
export const VERSION: "0.16.0";
/**
* Mutable global config properties.
* @namespace
*/
export namespace config {
/**
* Modify the config properties
* @param {{
* DEBUG?: boolean
* STRICT_BABBAGE?: boolean
* IS_TESTNET?: boolean
* N_DUMMY_INPUTS?: number
* AUTO_SET_VALIDITY_RANGE?: boolean
* VALIDITY_RANGE_START_OFFSET?: number
* VALIDITY_RANGE_END_OFFSET?: number
* IGNORE_UNEVALUATED_CONSTANTS?: boolean
* CHECK_CASTS?: boolean
* MAX_ASSETS_PER_CHANGE_OUTPUT?: number
* }} props
*/
function set(props: {
DEBUG?: boolean | undefined;
STRICT_BABBAGE?: boolean | undefined;
IS_TESTNET?: boolean | undefined;
N_DUMMY_INPUTS?: number | undefined;
AUTO_SET_VALIDITY_RANGE?: boolean | undefined;
VALIDITY_RANGE_START_OFFSET?: number | undefined;
VALIDITY_RANGE_END_OFFSET?: number | undefined;
IGNORE_UNEVALUATED_CONSTANTS?: boolean | undefined;
CHECK_CASTS?: boolean | undefined;
MAX_ASSETS_PER_CHANGE_OUTPUT?: number | undefined;
}): void;
/**
* Global debug flag. Currently unused.
*
* Default: `false`.
* @type {boolean}
*/
const DEBUG: boolean;
/**
* If true, `TxOutput` is serialized using strictly the Babagge cddl format (slightly more verbose).
*
* Default: `false`.
* @type {boolean}
*/
const STRICT_BABBAGE: boolean;
/**
* If true, `Address` instances are assumed to be for a Testnet when constructing from hashes or raw bytes, otherwise for mainnet.
*
* Defaults: `true`.
* @type {boolean}
*/
const IS_TESTNET: boolean;
/**
* Calculating the execution budget during tx building requires knowing all the inputs beforehand,
* which is very difficult because balancing is done after the budget is calculated.
* Instead we use at least 1 dummy input, which should act as a representative balancing input.
* For increased robustness we use 2 dummy inputs, one with Txid 0 and other with TxId ffff...,
* because eg. there are cases where the TxId is being printed,
* and a Txid of ffff... would overestimate the fee for that.
* This value must be '1' or '2'.
*
* Default: 2.
* @deprecated
* @type {number}
*/
const N_DUMMY_INPUTS: number;
/**
* The validity time range can be set automatically if a call to tx.time_range in a Helios script is detected.
* If `false` the validity range is still set automatically if not set manually but a warning is printed.
*
* Default: `false`.
* @type {boolean}
*/
const AUTO_SET_VALIDITY_RANGE: boolean;
/**
* Lower offset wrt. the current system time when setting the validity range automatically.
*
* Defaut: 90 seconds.
* @type {number} seconds
*/
const VALIDITY_RANGE_START_OFFSET: number;
/**
* Upper offset wrt. the current system time when setting the validity range automatically.
*
* Default: 300 seconds.
* @type {number} seconds
*/
const VALIDITY_RANGE_END_OFFSET: number;
/**
* Ignore constants that can't be evaluated during compile-time.
*
* Default: `false`.
* @type {boolean}
*/
const IGNORE_UNEVALUATED_CONSTANTS: boolean;
/**
* Check that `from_data` casts make sense during runtime. This ony impacts unsimplified UplcPrograms.
*
* Default: `false`.
* @type {boolean}
*/
const CHECK_CASTS: boolean;
/**
* Maximum number of assets per change output. Used to break up very large asset outputs into multiple outputs.
*
* Default: `undefined` (no limit).
*/
const MAX_ASSETS_PER_CHANGE_OUTPUT: undefined;
}
/**
* Function that generates a random number between 0 and 1
* @typedef {() => number} NumberGenerator
*/
/**
* A Source instance wraps a string so we can use it cheaply as a reference inside a Site.
* Also used by VSCode plugin
*/
export class Source {
/**
* @param {string} raw
* @param {string} name
*/
constructor(raw: string, name: string);
/**
* @param {TransferUplcAst} other
* @returns {any}
*/
transfer(other: TransferUplcAst): any;
/**
* @type {Error[]}
*/
get errors(): Error[];
throwErrors(): void;
#private;
}
/**
* Each Token/Expression/Statement has a Site, which encapsulates a position in a Source
*/
export class Site {
static dummy(): Site;
/**
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
* @param {Site | null} codeMapSite
*/
constructor(src: Source, startPos: number, endPos?: number, codeMapSite?: Site | null);
/**
*
* @param {TransferUplcAst} other
*/
transfer(other: TransferUplcAst): any;
get src(): Source;
get startPos(): number;
get endPos(): number;
get endSite(): Site | null;
/**
* @param {Site} other
* @returns {Site}
*/
merge(other: Site): Site;
/**
* @param {?Site} site
*/
setEndSite(site: Site | null): void;
/**
* @type {?Site}
*/
get codeMapSite(): Site | null;
/**
* @param {Site} site
*/
setCodeMapSite(site: Site): void;
/**
* Returns a SyntaxError
* @param {string} info
* @returns {UserError}
*/
syntaxError(info?: string): UserError;
/**
* Returns a TypeError
* @param {string} info
* @returns {UserError}
*/
typeError(info?: string): UserError;
/**
* Returns a ReferenceError
* @param {string} info
* @returns {UserError}
*/
referenceError(info?: string): UserError;
/**
* Calculates the column,line position in 'this.#src'
* @returns {[number, number, number, number]} - [startLine, startCol, endLine, endCol]
*/
getFilePos(): [number, number, number, number];
/**
* @returns {string}
*/
toString(): string;
#private;
}
/**
* UserErrors are generated when the user of Helios makes a mistake (eg. a syntax error).
*/
export class UserError extends Error {
/**
* @param {Error} e
* @returns {boolean}
*/
static isTypeError(e: Error): boolean;
/**
* @param {Error} e
* @returns {boolean}
*/
static isReferenceError(e: Error): boolean;
/**
* Catches any UserErrors thrown inside 'fn()`.
* Dumps the error
* @template T
* @param {() => T} fn
* @param {boolean} verbose
* @returns {T | undefined}
*/
static catch<T>(fn: () => T, verbose?: boolean): T | undefined;
/**
* Filled with CBOR hex representations of Datum, Redeemer and ScriptContext by validation scripts throwing errors during `tx.finalize()`; and Redeemer and ScriptContext by minting scripts throwing errors.
* @type {Object}
*/
get context(): any;
#private;
}
/**
* Used for errors thrown during Uplc evaluation
*/
export class RuntimeError extends Error {
get context(): any;
#private;
}
/**
* The Helios `Crypto` namespace contains a collection of cryptography primitives.
*
* These functions have been implemented as part of the Helios library in order to avoid external dependencies
* (there still isn't a standardized Javascript [Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto) that provides all the needed functionality).
* @namespace
*/
export namespace Crypto {
/**
* A simple pseudo-random number generator for use in tests that requires some randomness but need to be deterministic
* (i.e. each test run gives the same result).
* @param {number} seed
* @returns {NumberGenerator} The returned function returns a new random number between 0 and 1 upon each call.
*/
function mulberry32(seed: number): NumberGenerator;
/**
* Alias for `mulberry32`.
* @param {number} seed
* @returns {NumberGenerator} The returned function returns a new random number between 0 and 1 upon each call.
*/
function rand(seed: number): NumberGenerator;
/**
* Encodes bytes in using Base32.
* @example
* Crypto.encodeBase32(textToBytes("f")) == "my"
* @example
* Crypto.encodeBase32(textToBytes("fo")) == "mzxq"
* @example
* Crypto.encodeBase32(textToBytes("foo")) == "mzxw6"
* @example
* Crypto.encodeBase32(textToBytes("foob")) == "mzxw6yq"
* @example
* Crypto.encodeBase32(textToBytes("fooba")) == "mzxw6ytb"
* @example
* Crypto.encodeBase32(textToBytes("foobar")) == "mzxw6ytboi"
* @param {number[]} bytes list of uint8 numbers
* @param {string} alphabet list of chars, defaults to "abcdefghijklmnopqrstuvwxyz234567"
* @return {string}
*/
function encodeBase32(bytes: number[], alphabet?: string): string;
/**
* Decodes a Base32 string into bytes.
* @example
* bytesToText(Crypto.decodeBase32("my")) == "f"
* @example
* bytesToText(Crypto.decodeBase32("mzxq")) == "fo"
* @example
* bytesToText(Crypto.decodeBase32("mzxw6")) == "foo"
* @example
* bytesToText(Crypto.decodeBase32("mzxw6yq")) == "foob"
* @example
* bytesToText(Crypto.decodeBase32("mzxw6ytb")) == "fooba"
* @example
* bytesToText(Crypto.decodeBase32("mzxw6ytboi")) == "foobar"
* @param {string} encoded
* @param {string} alphabet list of chars, defaults to "abcdefghijklmnopqrstuvwxyz234567"
* @return {number[]}
*/
function decodeBase32(encoded: string, alphabet?: string): number[];
/**
* Creates a Bech32 checksummed string (eg. used to represent Cardano addresses).
* @example
* Crypto.encodeBech32("foo", textToBytes("foobar")) == "foo1vehk7cnpwgry9h96"
* @example
* Crypto.encodeBech32("addr_test", hexToBytes("70a9508f015cfbcffc3d88ac4c1c934b5b82d2bb281d464672f6c49539")) == "addr_test1wz54prcptnaullpa3zkyc8ynfddc954m9qw5v3nj7mzf2wggs2uld"
* @param {string} hrp human-readable part (eg. "addr")
* @param {number[]} data a list of uint8 bytes
* @returns {string}
*/
function encodeBech32(hrp: string, data: number[]): string;
/**
* Decomposes a Bech32 checksummed string (eg. a Cardano address), and returns the human readable part and the original bytes
* Throws an error if checksum is invalid.
* @example
* bytesToHex(Crypto.decodeBech32("addr_test1wz54prcptnaullpa3zkyc8ynfddc954m9qw5v3nj7mzf2wggs2uld")[1]) == "70a9508f015cfbcffc3d88ac4c1c934b5b82d2bb281d464672f6c49539"
* @param {string} addr
* @returns {[string, number[]]} First part is the human-readable part, second part is a list containing the underlying bytes.
*/
function decodeBech32(addr: string): [string, number[]];
/**
* Verifies a Bech32 checksum.
* @example
* Crypto.verifyBech32("foo1vehk7cnpwgry9h96") == true
* @example
* Crypto.verifyBech32("foo1vehk7cnpwgry9h97") == false
* @example
* Crypto.verifyBech32("a12uel5l") == true
* @example
* Crypto.verifyBech32("mm1crxm3i") == false
* @example
* Crypto.verifyBech32("A1G7SGD8") == false
* @example
* Crypto.verifyBech32("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw") == true
* @example
* Crypto.verifyBech32("?1ezyfcl") == true
* @example
* Crypto.verifyBech32("addr_test1wz54prcptnaullpa3zkyc8ynfddc954m9qw5v3nj7mzf2wggs2uld") == true
* @param {string} encoded
* @returns {boolean}
*/
function verifyBech32(encoded: string): boolean;
/**
* Calculates sha2-256 (32bytes) hash of a list of bytes.
* Result is also a list of bytes.
* @example
* bytesToHex(Crypto.sha2_256([0x61, 0x62, 0x63])) == "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
* @example
* Crypto.sha2_256(textToBytes("Hello, World!")) == [223, 253, 96, 33, 187, 43, 213, 176, 175, 103, 98, 144, 128, 158, 195, 165, 49, 145, 221, 129, 199, 247, 10, 75, 40, 104, 138, 54, 33, 130, 152, 111]
* @param {number[]} bytes List of uint8 numbers
* @returns {number[]} List of uint8 numbers.
*/
function sha2_256(bytes: number[]): number[];
/**
* Calculates sha2-512 (64bytes) hash of a list of uint8 numbers.
* Result is also a list of uint8 number.
* @example
* bytesToHex(Crypto.sha2_512([0x61, 0x62, 0x63])) == "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
* @example
* bytesToHex(Crypto.sha2_512([])) == "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
* @example
* bytesToHex(Crypto.sha2_512(textToBytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))) == "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445"
* @example
* bytesToHex(Crypto.sha2_512(textToBytes("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstuu"))) == "23565d109ac0e2aa9fb162385178895058b28489a6bc31cb55491ed83956851ab1d4bbd46440586f5c9c4b69c9c280118cbc55c71495d258cc27cc6bb25ee720"
* @param {number[]} bytes List of uint8 numbers
* @returns {number[]} List of uint8 numbers.
*/
function sha2_512(bytes: number[]): number[];
/**
* Calculates sha3-256 (32bytes) hash of a list of uint8 numbers.
* Result is also a list of uint8 number.
* @example
* bytesToHex(Crypto.sha3(textToBytes("abc"))) == "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"
* @example
* bytesToHex(Crypto.sha3((new Array(136)).fill(1))) == "b36dc2167c4d9dda1a58b87046c8d76a6359afe3612c4de8a38857e09117b2db"
* @example
* bytesToHex(Crypto.sha3((new Array(135)).fill(2))) == "5bdf5d815d29a9d7161c66520efc17c2edd7898f2b99a029e8d2e4ff153407f4"
* @example
* bytesToHex(Crypto.sha3((new Array(134)).fill(3))) == "8e6575663dfb75a88f94a32c5b363c410278b65020734560d968aadd6896a621"
* @example
* bytesToHex(Crypto.sha3((new Array(137)).fill(4))) == "f10b39c3e455006aa42120b9751faa0f35c821211c9d086beb28bf3c4134c6c6"
* @param {number[]} bytes List of uint8 numbers
* @returns {number[]} List of uint8 numbers.
*/
function sha3(bytes: number[]): number[];
/**
* Calculates blake2b hash of a list of uint8 numbers (variable digest size).
* Result is also a list of uint8 numbers.
* @example
* bytesToHex(Crypto.blake2b([0, 1])) == "01cf79da4945c370c68b265ef70641aaa65eaa8f5953e3900d97724c2c5aa095"
* @example
* bytesToHex(Crypto.blake2b(textToBytes("abc"), 64)) == "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"
* @param {number[]} bytes
* @param {number} digestSize Defaults to 32. Can't be greater than 64.
* @returns {number[]} List of uint8 numbers.
*/
function blake2b(bytes: number[], digestSize?: number): number[];
/**
* Hmac using sha2-256.
* @example
* bytesToHex(Crypto.hmacSha2_256(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
* @param {number[]} key
* @param {number[]} message
* @returns {number[]}
*/
function hmacSha2_256(key: number[], message: number[]): number[];
/**
* Hmac using sha2-512.
* @example
* bytesToHex(Crypto.hmacSha2_512(textToBytes("key"), textToBytes("The quick brown fox jumps over the lazy dog"))) == "b42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a"
* @param {number[]} key
* @param {number[]} message
* @returns {number[]}
*/
function hmacSha2_512(key: number[], message: number[]): number[];
/**
* Password-Based Key Derivation Function 2.
* @example
* bytesToHex(Crypto.pbkdf2(Crypto.hmacSha2_256, textToBytes("password"), textToBytes("salt"), 1, 20)) == "120fb6cffcf8b32c43e7225256c4f837a86548c9"
* @example
* bytesToHex(Crypto.pbkdf2(Crypto.hmacSha2_512, textToBytes("password"), textToBytes("salt"), 2, 20)) == "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e"
* @param {(key: number[], msg: number[]) => number[]} prf
* @param {number[]} password
* @param {number[]} salt
* @param {number} iters
* @param {number} dkLength
* @returns {number[]}
*/
function pbkdf2(prf: (key: number[], msg: number[]) => number[], password: number[], salt: number[], iters: number, dkLength: number): number[];
}
/**
* The elliptic curve signature algorithm used by Cardano wallets.
*
* Ported from: [https://ed25519.cr.yp.to/python/ed25519.py](https://ed25519.cr.yp.to/python/ed25519.py).
*
* ExtendedPoint implementation taken from: [https://github.com/paulmillr/noble-ed25519](https://github.com/paulmillr/noble-ed25519).
* @namespace
*/
export namespace Ed25519 {
/**
* Similar to `Ed25519.derivePublicKey`, but doesn't hash the input key.
* @param {number[]} extendedKey
* @returns {number[]} 32 byte public key.
*/
function deriveBip32PublicKey(extendedKey: number[]): number[];
/**
* Derive a public key from a private key.
* The private key can be any number of bytes (it's hashed internally).
* The returned public key is 32 bytes long.
* @param {number[]} privateKey
* @returns {number[]} 32 byte public key.
*/
function derivePublicKey(privateKey: number[]): number[];
/**
* Like `Ed25519.sign`, but doesn't hash the input key.
* @param {number[]} message
* @param {number[]} extendedKey
* @returns {number[]} 64 byte signature.
*/
function signBip32(message: number[], extendedKey: number[]): number[];
/**
* Creates a 64 byte signature.
* @param {number[]} message
* @param {number[]} privateKey
* @returns {number[]} 64 byte signature.
*/
function sign(message: number[], privateKey: number[]): number[];
/**
* Returns `true` if the signature is correct.
* @param {number[]} signature
* @param {number[]} message
* @param {number[]} publicKey
* @returns {boolean}
*/
function verify(signature: number[], message: number[], publicKey: number[]): boolean;
}
/**
* Standard English Bip39 dictionary consisting of 2048 words allowing wallet root keys to be formed by a phrase of 12, 15, 18, 21 or 24 of these words.
*/
export const BIP39_DICT_EN: string[];
/**
* @typedef {(i: number, bytes: number[]) => void} Decoder
*/
/**
* Base class of any Cbor serializable data class
* Also
*/
export class CborData {
/**
* @returns {number[]}
*/
toCbor(): number[];
/**
* @returns {string}
*/
toCborHex(): string;
}
/**
* Helper methods for (de)serializing data to/from Cbor.
*
* **Note**: Each decoding method mutates the input `bytes` by shifting it to the following CBOR element.
* @namespace
*/
export namespace Cbor {
function encodeHead(m: number, n: bigint): number[];
function decodeHead(bytes: number[]): [number, bigint];
function encodeIndefHead(m: number): number[];
function decodeIndefHead(bytes: number[]): number;
function isNull(bytes: number[]): boolean;
function encodeNull(): number[];
function decodeNull(bytes: number[]): void;
function encodeBool(b: boolean): number[];
function decodeBool(bytes: number[]): boolean;
function isBytes(bytes: number[]): boolean;
function isDefBytes(bytes: number[]): boolean;
function isIndefBytes(bytes: number[]): boolean;
function encodeBytes(bytes: number[], splitIntoChunks?: boolean): number[];
function decodeBytes(bytes: number[]): number[];
function isUtf8(bytes: number[]): boolean;
function encodeUtf8(str: string, split?: boolean): number[];
function decodeUtf8Internal(bytes: number[]): string;
function decodeUtf8(bytes: number[]): string;
function encodeInteger(n: bigint): number[];
function decodeInteger(bytes: number[]): bigint;
function isIndefList(bytes: number[]): boolean;
function encodeIndefListStart(): number[];
function encodeListInternal(list: CborData[] | number[][]): number[];
function encodeIndefListEnd(): number[];
function encodeList(list: CborData[] | number[][]): number[];
function encodeIndefList(list: CborData[] | number[][]): number[];
function isDefList(bytes: number[]): boolean;
function encodeDefListStart(n: bigint): number[];
function encodeDefList(list: CborData[] | number[][]): number[];
function isList(bytes: number[]): boolean;
function decodeList(bytes: number[], itemDecoder: Decoder): void;
function isTuple(bytes: number[]): boolean;
function encodeTuple(tuple: number[][]): number[];
function decodeTuple(bytes: number[], tupleDecoder: Decoder): number;
function isMap(bytes: number[]): boolean;
function encodeMapInternal(pairList: [number[] | CborData, number[] | CborData][]): number[];
function encodeMap(pairList: [number[] | CborData, number[] | CborData][]): number[];
function decodeMap(bytes: number[], pairDecoder: Decoder): void;
function isObject(bytes: number[]): boolean;
function encodeObject(object: Map<number, number[] | CborData>): number[];
function decodeObject(bytes: number[], fieldDecoder: Decoder): Set<number>;
function encodeTag(tag: bigint): number[];
function decodeTag(bytes: number[]): bigint;
function isConstr(bytes: number[]): boolean;
function encodeConstrTag(tag: number): number[];
function encodeConstr(tag: number, fields: CborData[] | number[][]): number[];
function decodeConstrTag(bytes: number[]): number;
function decodeConstr(bytes: number[], fieldDecoder: Decoder): number;
}
/**
* Base class for Plutus-core data classes (not the same as Plutus-core value classes!)
*/
export class UplcData extends CborData {
/**
* @param {number[] | string} bytes
* @returns {UplcData}
*/
static fromCbor(bytes: number[] | string): UplcData;
/**
* @param {TransferUplcAst} other
* @returns {any}
*/
transfer(other: TransferUplcAst): any;
/**
* Estimate of memory usage during validation
* @type {number}
*/
get memSize(): number;
/**
* Compares the schema jsons
* @param {UplcData} other
* @returns {boolean}
*/
isSame(other: UplcData): boolean;
/**
* @returns {string}
*/
toSchemaJson(): string;
}
/**
* Represents an unbounded integer (bigint).
*/
export class IntData extends UplcData {
/**
* @param {number[]} bytes
* @returns {IntData}
*/
static fromCbor(bytes: number[]): IntData;
/**
* @param {bigint} value
*/
constructor(value: bigint);
/**
* @type {bigint}
*/
get value(): bigint;
#private;
}
/**
* Plutus-core bytearray data class.
* Wraps a regular list of uint8 numbers (so not Uint8Array)
*/
export class ByteArrayData extends UplcData {
/**
* Applies utf-8 encoding
* @param {string} s
* @returns {ByteArrayData}
*/
static fromString(s: string): ByteArrayData;
/**
* Calculates the mem size of a byte array without the DATA_NODE overhead.
* @param {number[]} bytes
* @returns {number}
*/
static memSizeInternal(bytes: number[]): number;
/**
* @param {number[]} bytes
* @returns {ByteArrayData}
*/
static fromCbor(bytes: number[]): ByteArrayData;
/**
* @param {number[]} bytes
*/
constructor(bytes: number[]);
/**
* @returns {string}
*/
toHex(): string;
/**
* @type {string}
*/
get hex(): string;
#private;
}
/**
* Represents a list of other `UplcData` instances.
*/
export class ListData extends UplcData {
/**
* @param {number[]} bytes
* @returns {ListData}
*/
static fromCbor(bytes: number[]): ListData;
/**
* @param {UplcData[]} items
*/
constructor(items: UplcData[]);
#private;
}
/**
* Represents a list of pairs of other `UplcData` instances.
*/
export class MapData extends UplcData {
/**
* @param {number[]} bytes
* @returns {MapData}
*/
static fromCbor(bytes: number[]): MapData;
/**
* @param {[UplcData, UplcData][]} pairs
*/
constructor(pairs: [UplcData, UplcData][]);
#private;
}
/**
* Represents a tag index and a list of `UplcData` fields.
*/
export class ConstrData extends UplcData {
/**
* @param {number[]} bytes
* @returns {ConstrData}
*/
static fromCbor(bytes: number[]): ConstrData;
/**
* @param {number} index
* @param {UplcData[]} fields
*/
constructor(index: number, fields: UplcData[]);
#private;
}
/**
* Base-type of all data-types that exist both on- and off-chain, and map directly to Helios instances.
* @deprecated
*/
export class HeliosData extends CborData {
/**
* @returns {string}
*/
toSchemaJson(): string;
}
/**
* @deprecated
* @typedef {number | bigint} HIntProps
*/
/**
* Helios Int type
* @deprecated
*/
export class HInt extends HeliosData {
/**
* @param {HInt | HIntProps} props
* @returns {HInt}
*/
static fromProps(props: HInt | HIntProps): HInt;
/**
* @param {UplcData} data
* @returns {HInt}
*/
static fromUplcData(data: UplcData): HInt;
/**
* @param {string | number[]} bytes
* @returns {HInt}
*/
static fromUplcCbor(bytes: string | number[]): HInt;
/**
* @param {number[]} bytes
* @returns {HInt}
*/
static fromCbor(bytes: number[]): HInt;
/**
* @param {HIntProps} rawValue
*/
constructor(rawValue: HIntProps);
/**
* @type {bigint}
*/
get value(): bigint;
/**
* @returns {string}
*/
dump(): string;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
eq(other: HInt | HIntProps): boolean;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
neq(other: HInt | HIntProps): boolean;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
ge(other: HInt | HIntProps): boolean;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
gt(other: HInt | HIntProps): boolean;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
le(other: HInt | HIntProps): boolean;
/**
* @param {HInt | HIntProps} other
* @returns {boolean}
*/
lt(other: HInt | HIntProps): boolean;
/**
* @param {HInt| HIntProps} other
* @returns {HInt}
*/
add(other: HInt | HIntProps): HInt;
/**
* @param {HInt | HIntProps} other
* @returns {HInt}
*/
sub(other: HInt | HIntProps): HInt;
/**
* @param {HInt| HIntProps} other
* @returns {HInt}
*/
mul(other: HInt | HIntProps): HInt;
#private;
}
/**
* @deprecated
* @typedef {number[] | string} ByteArrayProps
*/
/**
* Helios ByteArray type
* @deprecated
*/
export class ByteArray extends HeliosData {
/**
* @param {ByteArray | ByteArrayProps} props
* @returns {ByteArray}
*/
static fromProps(props: ByteArray | ByteArrayProps): ByteArray;
/**
* @param {UplcData} data
* @returns {ByteArray}
*/
static fromUplcData(data: UplcData): ByteArray;
/**
* @param {string | number[]} bytes
* @returns {ByteArray}
*/
static fromUplcCbor(bytes: string | number[]): ByteArray;
/**
* @param {number[]} bytes
* @returns {ByteArray}
*/
static fromCbor(bytes: number[]): ByteArray;
/**
* @param {ByteArrayProps} props
*/
constructor(props: ByteArrayProps);
/**
* @type {number[]}
*/
get bytes(): number[];
/**
* Hexadecimal representation.
* @type {string}
*/
get hex(): string;
/**
* @param {ByteArray | ByteArrayProps} other
* @returns {boolean}
*/
eq(other: ByteArray | ByteArrayProps): boolean;
#private;
}
/**
* @typedef {number[] | string} HashProps
*/
/**
* Base class of all hash-types
*/
export class Hash extends HeliosData {
/**
* @param {Hash | HashProps} props
* @returns {Hash}
*/
static fromProps(props: Hash | HashProps): Hash;
/**
* Used internally for metadataHash and scriptDataHash
* @param {number[]} bytes
* @returns {Hash}
*/
static fromCbor(bytes: number[]): Hash;
/**
* Might be needed for internal use
* @param {string} str
* @returns {Hash}
*/
static fromHex(str: string): Hash;
/**
* @param {Hash} a
* @param {Hash} b
* @returns {number}
*/
static compare(a: Hash, b: Hash): number;
/**
* @param {HashProps} props
*/
constructor(props: HashProps);
/**
* @readonly
* @type {number[]}
*/
readonly bytes: number[];
/**
* Hexadecimal representation.
* @returns {string}
*/
get hex(): string;
/**
* @param {Hash} other
* @returns {boolean}
*/
eq(other: Hash): boolean;
}
/**
* @typedef {HashProps} DatumHashProps
*/
/**
* Represents a blake2b-256 hash of datum data.
*/
export class DatumHash extends Hash {
/**
* @param {UplcData} data
* @returns {DatumHash}
*/
static fromUplcData(data: UplcData): DatumHash;