forked from HeliosLang/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelios.d.ts
6873 lines (6873 loc) · 187 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
/**
* @template Ta
* @template Tb
* @param {[Ta | null, Tb | null][]} pairs
* @returns {null | [Ta, Tb][]}
*/
export function reduceNullPairs<Ta, Tb>(pairs: [Ta, Tb][]): [Ta, Tb][];
/**
* Converts a hexadecimal representation of bytes into an actual list of uint8 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;
/**
* A tag function for a helios source.
* Is just a marker so IDE support can work on literal helios sources inside javascript/typescript files.
* @example
* hl`hello ${"world"}!` => "hello world!"
* @param {string[]} a
* @param {...any} b
* @returns {string}
*/
export function hl(a: string[], ...b: any[]): string;
/**
* Dynamically constructs a new List class, depending on the item type.
* @template {HeliosData} T
* @param {HeliosDataClass<T>} ItemClass
* @returns {HeliosDataClass<HList_>}
*/
export function HList<T extends HeliosData>(ItemClass: HeliosDataClass<T>): HeliosDataClass<{
/**
* @type {T[]}
*/
"__#1@#items": T[];
/**
* @package
* @type {string}
*/
readonly _listTypeName: string;
/**
* @type {T[]}
*/
readonly items: T[];
/**
* @package
* @returns {UplcData}
*/
_toUplcData(): UplcData;
/**
* @returns {string}
*/
toSchemaJson(): string;
/**
* @returns {number[]}
*/
toCbor(): number[];
}>;
/**
* @template {HeliosData} TKey
* @template {HeliosData} TValue
* @param {HeliosDataClass<TKey>} KeyClass
* @param {HeliosDataClass<TValue>} ValueClass
* @returns {HeliosDataClass<HMap_>}
*/
export function HMap<TKey extends HeliosData, TValue extends HeliosData>(KeyClass: HeliosDataClass<TKey>, ValueClass: HeliosDataClass<TValue>): HeliosDataClass<{
/**
* @type {[TKey, TValue][]}
*/
"__#2@#pairs": [TKey, TValue][];
/**
* @package
* @type {string}
*/
readonly _mapTypeName: string;
/**
* @type {[TKey, TValue][]}
*/
readonly pairs: [TKey, TValue][];
/**
* @package
* @returns {UplcData}
*/
_toUplcData(): UplcData;
/**
* @returns {string}
*/
toSchemaJson(): string;
/**
* @returns {number[]}
*/
toCbor(): number[];
}>;
/**
* @template {HeliosData} T
* @param {HeliosDataClass<T>} SomeClass
* @returns {HeliosDataClass<Option_>}
*/
export function Option<T extends HeliosData>(SomeClass: HeliosDataClass<T>): HeliosDataClass<{
/**
* @type {?T}
*/
"__#3@#value": T;
/**
* @package
* @type {string}
*/
readonly _optionTypeName: string;
/**
* @type {?T}
*/
readonly some: T;
/**
* @package
* @returns {UplcData}
*/
_toUplcData(): UplcData;
/**
* @returns {string}
*/
toSchemaJson(): string;
/**
* @returns {number[]}
*/
toCbor(): number[];
}>;
/**
* Returns index of a named builtin
* Throws an error if builtin doesn't exist
* @param {string} name
* @returns
*/
export function findUplcBuiltin(name: string): number;
/**
* Checks if a named builtin exists
* @param {string} name
* @param {boolean} strict - if true then throws an error if builtin doesn't exist
* @returns {boolean}
*/
export function isUplcBuiltin(name: string, strict?: boolean): boolean;
/**
* @param {number[]} bytes
* @returns {UplcProgram}
*/
export function deserializeUplcBytes(bytes: number[]): UplcProgram;
/**
* Parses a plutus core program. Returns a UplcProgram object
* @param {string} jsonString
* @returns {UplcProgram}
*/
export function deserializeUplc(jsonString: string): UplcProgram;
/**
* Tokenizes a string (wrapped in Source)
* Also used by VSCode plugin
* @param {Source} src
* @returns {Token[] | null}
*/
export function tokenize(src: Source): Token[] | null;
/**
* Used by VSCode plugin
* @param {(path: StringLiteral) => (string | null)} fn
*/
export function setImportPathTranslator(fn: (path: StringLiteral) => (string | null)): void;
/**
* Also used by VSCode plugin
* @param {Token[]} ts
* @param {number | null} expectedPurpose
* @returns {[number | null, Word | null, Statement[], number]}
*/
export function buildScript(ts: Token[], expectedPurpose?: number | null): [number | null, Word | null, Statement[], number];
/**
* Parses Helios quickly to extract the script purpose header.
* Returns null if header is missing or incorrectly formed (instead of throwing an error)
* @param {string} rawSrc
* @returns {?[string, string]} - [purpose, name]
*/
export function extractScriptPurposeAndName(rawSrc: string): [string, string] | null;
/**
* Applies syntax highlighting by returning a list of char categories.
* Not part of Tokeizer because it needs to be very fast and can't throw errors.
* Doesn't depend on any other functions so it can easily be ported to other languages.
* @param {string} src
* @returns {Uint8Array}
*/
export function highlight(src: string): Uint8Array;
/**
* Version of the Helios library.
*/
export const VERSION: "0.13.38";
/**
* Modifiable config vars
* @type {{
* DEBUG: boolean,
* STRICT_BABBAGE: boolean,
* IS_TESTNET: boolean,
* N_DUMMY_INPUTS: number,
* AUTO_SET_VALIDITY_RANGE: boolean,
* VALIDITY_RANGE_START_OFFSET: number | null,
* VALIDITY_RANGE_END_OFFSET: number | null
* }}
*/
export const config: {
DEBUG: boolean;
STRICT_BABBAGE: boolean;
IS_TESTNET: boolean;
N_DUMMY_INPUTS: number;
AUTO_SET_VALIDITY_RANGE: boolean;
VALIDITY_RANGE_START_OFFSET: number | null;
VALIDITY_RANGE_END_OFFSET: number | null;
};
/**
* 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 {null | number} fileIndex
*/
constructor(raw: string, fileIndex?: null | number);
/**
* @param {TransferUplcAst} other
* @returns {any}
*/
transfer(other: TransferUplcAst): any;
/**
* @package
* @type {string}
*/
get raw(): string;
/**
* @package
* @type {?number}
*/
get fileIndex(): number;
/**
* @type {Error[]}
*/
get errors(): Error[];
throwErrors(): void;
/**
* Get char from the underlying string.
* Should work fine utf-8 runes.
* @package
* @param {number} pos
* @returns {string}
*/
getChar(pos: number): string;
/**
* Returns word under pos
* @package
* @param {number} pos
* @returns {?string}
*/
getWord(pos: number): string | null;
/**
* @package
* @type {number}
*/
get length(): number;
/**
* Calculates the line number of the line where the given character is located (0-based).
* @package
* @param {number} pos
* @returns {number}
*/
posToLine(pos: number): number;
/**
* Calculates the column and line number where the given character is located (0-based).
* @package
* @param {number} pos
* @returns {[number, number]}
*/
posToLineAndCol(pos: number): [number, number];
/**
* Creates a more human-readable version of the source by prepending the line-numbers to each line.
* The line-numbers are at least two digits.
* @example
* (new Source("hello\nworld")).pretty() => "01 hello\n02 world"
* @package
* @returns {string}
*/
pretty(): string;
#private;
}
/**
* UserErrors are generated when the user of Helios makes a mistake (eg. a syntax error),
* or when the user of Helios throws an explicit error inside a script (eg. division by zero).
*/
export class UserError extends Error {
/**
* @param {string} type
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
* @param {string} info
*/
static new(type: string, src: Source, startPos: number, endPos: number, info?: string): UserError;
/**
* Constructs a SyntaxError
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
* @param {string} info
* @returns {UserError}
*/
static syntaxError(src: Source, startPos: number, endPos: number, info?: string): UserError;
/**
* Constructs a TypeError
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
* @param {string} info
* @returns {UserError}
*/
static typeError(src: Source, startPos: number, endPos: number, info?: string): UserError;
/**
* @param {Error} e
* @returns {boolean}
*/
static isTypeError(e: Error): boolean;
/**
* Constructs a ReferenceError (i.e. name undefined, or name unused)
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
* @param {string} info
* @returns {UserError}
*/
static referenceError(src: Source, startPos: number, endPos: number, info?: string): UserError;
/**
* @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;
/**
* @param {string} msg
* @param {Source} src
* @param {number} startPos
* @param {number} endPos
*/
constructor(msg: string, src: Source, startPos: number, endPos?: number);
/**
* @type {Source}
*/
get src(): Source;
/**
* @type {Object}
*/
get context(): any;
get data(): void;
/**
* @type {number}
*/
get startPos(): number;
/**
* Calculates column/line position in 'this.src'.
* @returns {[number, number, number, number]} - [startLine, startCol, endLine, endCol]
*/
getFilePos(): [number, number, number, number];
/**
* Dumps the error without throwing.
* If 'verbose == true' the Source is also pretty printed with line-numbers.
* @param {boolean} verbose
*/
dump(verbose?: boolean): void;
#private;
}
/**
* Token is the base class of all Expressions and Statements
*/
export class Token {
/**
* @param {Site} site
*/
constructor(site: Site);
get site(): Site;
/**
* @returns {string}
*/
toString(): string;
/**
* Returns 'true' if 'this' is a literal primitive, a literal struct constructor, or a literal function expression.
* @returns {boolean}
*/
isLiteral(): boolean;
/**
* Returns 'true' if 'this' is a Word token.
* @param {?(string | string[])} value
* @returns {boolean}
*/
isWord(value?: (string | string[]) | null): boolean;
/**
* @returns {boolean}
*/
isKeyword(): boolean;
/**
* Returns 'true' if 'this' is a Symbol token (eg. '+', '(' etc.)
* @param {?(string | string[])} value
* @returns {boolean}
*/
isSymbol(value?: (string | string[]) | null): boolean;
/**
* Returns 'true' if 'this' is a group (eg. '(...)').
* @param {?string} value
* @param {number | null} nFields
* @returns {boolean}
*/
isGroup(value: string | null, nFields?: number | null): boolean;
/**
* Returns a SyntaxError at the current Site.
* @param {string} msg
* @returns {UserError}
*/
syntaxError(msg: string): UserError;
/**
* Returns a TypeError at the current Site.
* @param {string} msg
* @returns {UserError}
*/
typeError(msg: string): UserError;
/**
* Returns a ReferenceError at the current Site.
* @param {string} msg
* @returns {UserError}
*/
referenceError(msg: string): UserError;
/**
* Throws a SyntaxError if 'this' isn't a Word.
* @param {?(string | string[])} value
* @returns {Word | null}
*/
assertWord(value?: (string | string[]) | null): Word | null;
/**
* Throws a SyntaxError if 'this' isn't a Symbol.
* @param {?(string | string[])} value
* @returns {SymbolToken | null}
*/
assertSymbol(value?: (string | string[]) | null): SymbolToken | null;
/**
* Throws a SyntaxError if 'this' isn't a Group.
* @param {?string} type
* @param {?number} nFields
* @returns {Group | null}
*/
assertGroup(type?: string | null, nFields?: number | null): Group | null;
#private;
}
/**
* A collection of cryptography primitives are included here in order to avoid external dependencies
* mulberry32: random number generator
* base32 encoding and decoding
* bech32 encoding, checking, and decoding
* sha2_256, sha2_512, sha3 and blake2b hashing
* ed25519 pubkey generation, signing, and signature verification (NOTE: the current implementation is simple but slow)
*/
export class Crypto {
/**
* Returns a simple random number generator
* @package
* @param {number} seed
* @returns {NumberGenerator} - a random number generator
*/
static mulberry32(seed: number): NumberGenerator;
/**
* Alias for rand generator of choice
* @package
* @param {number} seed
* @returns {NumberGenerator} - the random number generator function
*/
static rand(seed: number): NumberGenerator;
/**
* Rfc 4648 base32 alphabet
* @type {string}
*/
static get DEFAULT_BASE32_ALPHABET(): string;
/**
* Bech32 base32 alphabet
* @type {string}
*/
static get BECH32_BASE32_ALPHABET(): string;
/**
* Encode bytes in special 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"
* @package
* @param {number[]} bytes - uint8 numbers
* @param {string} alphabet - list of chars
* @return {string}
*/
static encodeBase32(bytes: number[], alphabet?: string): string;
/**
* Internal method
* @package
* @param {number[]} bytes
* @returns {number[]} - list of numbers between 0 and 32
*/
static encodeBase32Bytes(bytes: number[]): number[];
/**
* Decode 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"
* @package
* @param {string} encoded
* @param {string} alphabet
* @return {number[]}
*/
static decodeBase32(encoded: string, alphabet?: string): number[];
/**
* Expand human readable prefix of the bech32 encoding so it can be used in the checkSum
* Internal method.
* @package
* @param {string} hrp
* @returns {number[]}
*/
static expandBech32HumanReadablePart(hrp: string): number[];
/**
* Used as part of the bech32 checksum.
* Internal method.
* @package
* @param {number[]} bytes
* @returns {number}
*/
static calcBech32Polymod(bytes: number[]): number;
/**
* Generate the bech32 checksum
* Internal method
* @package
* @param {string} hrp
* @param {number[]} data - numbers between 0 and 32
* @returns {number[]} - 6 numbers between 0 and 32
*/
static calcBech32Checksum(hrp: string, data: number[]): number[];
/**
* Creates a bech32 checksummed string (used to represent Cardano addresses)
* @example
* Crypto.encodeBech32("foo", textToBytes("foobar")) => "foo1vehk7cnpwgry9h96"
* @example
* Crypto.encodeBech32("addr_test", hexToBytes("70a9508f015cfbcffc3d88ac4c1c934b5b82d2bb281d464672f6c49539")) => "addr_test1wz54prcptnaullpa3zkyc8ynfddc954m9qw5v3nj7mzf2wggs2uld"
* @package
* @param {string} hrp
* @param {number[]} data - uint8 0 - 256
* @returns {string}
*/
static encodeBech32(hrp: string, data: number[]): string;
/**
* Decomposes a bech32 checksummed string (i.e. 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"
* @package
* @param {string} addr
* @returns {[string, number[]]}
*/
static decodeBech32(addr: string): [string, number[]];
/**
* Verify 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
* @package
* @param {string} addr
* @returns {boolean}
*/
static verifyBech32(addr: string): boolean;
/**
* Calculates sha2-256 (32bytes) hash of a list of uint8 numbers.
* Result is also a list of uint8 number.
* @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]
* @package
* @param {number[]} bytes - list of uint8 numbers
* @returns {number[]} - list of uint8 numbers
*/
static 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"
* @package
* @param {number[]} bytes - list of uint8 numbers
* @returns {number[]} - list of uint8 numbers
*/
static sha2_512(bytes: number[]): number[];
/**
* Calculates sha3-256 (32bytes) hash of a list of uint8 numbers.
* Result is also a list of uint8 number.
* Sha3 only bit-wise operations, so 64-bit operations can easily be replicated using 2 32-bit operations instead
* @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"
* @package
* @param {number[]} bytes - list of uint8 numbers
* @returns {number[]} - list of uint8 numbers
*/
static sha3(bytes: number[]): number[];
/**
* Calculates blake2b hash of a list of uint8 numbers (variable digest size).
* Result is also a list of uint8 number.
* Blake2b is a 64bit algorithm, so we need to be careful when replicating 64-bit operations with 2 32-bit numbers (low-word overflow must spill into high-word, and shifts must go over low/high boundary)
* @example
* bytesToHex(Crypto.blake2b([0, 1])) => "01cf79da4945c370c68b265ef70641aaa65eaa8f5953e3900d97724c2c5aa095"
* @example
* bytesToHex(Crypto.blake2b(textToBytes("abc"), 64)) => "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923"
* @package
* @param {number[]} bytes
* @param {number} digestSize - at most 64
* @returns {number[]}
*/
static blake2b(bytes: number[], digestSize?: number): number[];
/**
* Crypto.Ed25519 exports the following functions:
* * Crypto.Ed25519.derivePublicKey(privateKey)
* * Crypto.Ed25519.sign(message, privateKey)
* * Crypto.Ed25519.verify(message, signature, publicKey)
*
* This is implementation is slow (~0.5s per verification), but should be good enough for simple client-side usage
*
* Ported from: https://ed25519.cr.yp.to/python/ed25519.py
* @package
*/
static get Ed25519(): {
/**
* @param {number[]} privateKey
* @returns {number[]}
*/
derivePublicKey: (privateKey: number[]) => number[];
/**
* @param {number[]} message
* @param {number[]} privateKey
* @returns {number[]}
*/
sign: (message: number[], privateKey: number[]) => number[];
/**
* @param {number[]} signature
* @param {number[]} message
* @param {number[]} publicKey
* @returns {boolean}
*/
verify: (signature: number[], message: number[], publicKey: number[]) => boolean;
};
}
/**
* @typedef {(i: number, bytes: number[]) => void} Decoder
*/
/**
* Base class of any Cbor serializable data class
* Also contains helper methods for (de)serializing data to/from Cbor
*/
export class CborData {
/**
* @param {number} m - major type
* @param {bigint} n - size parameter
* @returns {number[]} - uint8 bytes
*/
static encodeHead(m: number, n: bigint): number[];
/**
* @param {number[]} bytes - mutated to contain the rest
* @returns {[number, bigint]} - [majorType, n]
*/
static decodeHead(bytes: number[]): [number, bigint];
/**
* @param {number} m
* @returns {number[]}
*/
static encodeIndefHead(m: number): number[];
/**
* @param {number[]} bytes - cbor bytes
* @returns {number} - majorType
*/
static decodeIndefHead(bytes: number[]): number;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isNull(bytes: number[]): boolean;
/**
* @returns {number[]}
*/
static encodeNull(): number[];
/**
* Throws error if not null
* @param {number[]} bytes
*/
static decodeNull(bytes: number[]): void;
/**
* @param {boolean} b
* @returns {number[]}
*/
static encodeBool(b: boolean): number[];
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static decodeBool(bytes: number[]): boolean;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isDefBytes(bytes: number[]): boolean;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isIndefBytes(bytes: number[]): boolean;
/**
* @example
* bytesToHex(CborData.encodeBytes(hexToBytes("4d01000033222220051200120011"))) => "4e4d01000033222220051200120011"
* @param {number[]} bytes
* @param {boolean} splitInChunks
* @returns {number[]} - cbor bytes
*/
static encodeBytes(bytes: number[], splitInChunks?: boolean): number[];
/**
* Decodes both an indef array of bytes, and a bytearray of specified length
* @example
* bytesToHex(CborData.decodeBytes(hexToBytes("4e4d01000033222220051200120011"))) => "4d01000033222220051200120011"
* @param {number[]} bytes - cborbytes, mutated to form remaining
* @returns {number[]} - byteArray
*/
static decodeBytes(bytes: number[]): number[];
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isUtf8(bytes: number[]): boolean;
/**
* Encodes a Utf8 string into Cbor bytes.
* Strings can be split into lists with chunks of up to 64 bytes
* to play nice with Cardano tx metadata constraints.
* @param {string} str
* @param {boolean} split
* @returns {number[]}
*/
static encodeUtf8(str: string, split?: boolean): number[];
/**
* @param {number[]} bytes
* @returns {string}
*/
static decodeUtf8Internal(bytes: number[]): string;
/**
* @param {number[]} bytes
* @returns {string}
*/
static decodeUtf8(bytes: number[]): string;
/**
* @param {bigint} n
* @returns {number[]} - cbor bytes
*/
static encodeInteger(n: bigint): number[];
/**
* @param {number[]} bytes
* @returns {bigint}
*/
static decodeInteger(bytes: number[]): bigint;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isIndefList(bytes: number[]): boolean;
/**
* @returns {number[]}
*/
static encodeIndefListStart(): number[];
/**
* @param {CborData[] | number[][]} list
* @returns {number[]}
*/
static encodeListInternal(list: CborData[] | number[][]): number[];
/**
* @returns {number[]}
*/
static encodeIndefListEnd(): number[];
/**
* @param {CborData[] | number[][]} list
* @returns {number[]}
*/
static encodeList(list: CborData[] | number[][]): number[];
/**
* @param {CborData[] | number[][]} list
* @returns {number[]}
*/
static encodeIndefList(list: CborData[] | number[][]): number[];
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isDefList(bytes: number[]): boolean;
/**
* @param {bigint} n
* @returns {number[]}
*/
static encodeDefListStart(n: bigint): number[];
/**
* @param {CborData[] | number[][]} list
* @returns {number[]}
*/
static encodeDefList(list: CborData[] | number[][]): number[];
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isList(bytes: number[]): boolean;
/**
* @param {number[]} bytes
* @param {Decoder} itemDecoder
*/
static decodeList(bytes: number[], itemDecoder: Decoder): void;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isTuple(bytes: number[]): boolean;
/**
* @param {number[][]} tuple
* @returns {number[]}
*/
static encodeTuple(tuple: number[][]): number[];
/**
* @param {number[]} bytes
* @param {Decoder} tupleDecoder
* @returns {number} - returns the size of the tuple
*/
static decodeTuple(bytes: number[], tupleDecoder: Decoder): number;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isMap(bytes: number[]): boolean;
/**
* @param {[CborData | number[], CborData | number[]][]} pairList
* @returns {number[]}
*/
static encodeMapInternal(pairList: [CborData | number[], CborData | number[]][]): number[];
/**
* A decode map method doesn't exist because it specific for the requested type
* @param {[CborData | number[], CborData | number[]][]} pairList
* @returns {number[]}
*/
static encodeMap(pairList: [CborData | number[], CborData | number[]][]): number[];
/**
* @param {number[]} bytes
* @param {Decoder} pairDecoder
*/
static decodeMap(bytes: number[], pairDecoder: Decoder): void;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isObject(bytes: number[]): boolean;
/**
* @param {Map<number, CborData | number[]>} object
* @returns {number[]}
*/
static encodeObject(object: Map<number, CborData | number[]>): number[];
/**
* @param {number[]} bytes
* @param {Decoder} fieldDecoder
* @returns {Set<number>}
*/
static decodeObject(bytes: number[], fieldDecoder: Decoder): Set<number>;
/**
* Unrelated to constructor
* @param {bigint} tag
* @returns {number[]}
*/
static encodeTag(tag: bigint): number[];
/**
* @param {number[]} bytes
* @returns {bigint}
*/
static decodeTag(bytes: number[]): bigint;
/**
* @param {number[]} bytes
* @returns {boolean}
*/
static isConstr(bytes: number[]): boolean;
/**
* Encode a constructor tag of a ConstrData type
* @param {number} tag
* @returns {number[]}
*/
static encodeConstrTag(tag: number): number[];
/**
* @param {number} tag
* @param {CborData[] | number[][]} fields
* @returns {number[]}
*/
static encodeConstr(tag: number, fields: CborData[] | number[][]): number[];
/**
* @param {number[]} bytes
* @returns {number}
*/
static decodeConstrTag(bytes: number[]): number;
/**
* Returns the tag
* @param {number[]} bytes
* @param {Decoder} fieldDecoder
* @returns {number}
*/
static decodeConstr(bytes: number[], fieldDecoder: Decoder): number;
/**
* @returns {number[]}
*/
toCbor(): number[];
}
/**
* Base class for Plutus-core data classes (not the same as Plutus-core value classes!)
*/
export class UplcData extends CborData {
/**
* @param {string | number[]} bytes
* @returns {UplcData}
*/
static fromCbor(bytes: string | number[]): UplcData;
/**
* @param {TransferUplcAst} other