@taquito/utils 23.0.3 → 24.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-utils.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,104 +1,3 @@
1
- /**
2
- * @deprecated use PrefixV2 instead, this enum will be removed in the next minor release
3
- * @description base58 prefix definition enum
4
- */
5
- export declare enum Prefix {
6
- TZ1 = "tz1",// ed25519_public_key_hash
7
- TZ2 = "tz2",// secp256k1_public_key_hash
8
- TZ3 = "tz3",// p256_public_key_hash
9
- TZ4 = "tz4",// bls12_381_public_key_hash
10
- KT = "KT",
11
- KT1 = "KT1",
12
- EDSK = "edsk",// ed25519_secret_key
13
- EDSK2 = "edsk2",// ed25519_seed
14
- SPSK = "spsk",// secp256k1_secret_key
15
- P2SK = "p2sk",// p256_secret_key
16
- BLSK = "BLsk",// bls12_381_secret_key
17
- EDPK = "edpk",// ed25519_public_key
18
- SPPK = "sppk",// secp256k1_public_key
19
- P2PK = "p2pk",// p256_public_key
20
- BLPK = "BLpk",// bls12_381_public_key
21
- EDESK = "edesk",// ed25519_encrypted_seed
22
- SPESK = "spesk",// secp256k1_encrypted_secret_key
23
- P2ESK = "p2esk",// p256_encrypted_secret_key
24
- BLESK = "BLesk",// bls12_381_encrypted_secret_key
25
- EDSIG = "edsig",// ed25519_signature
26
- SPSIG = "spsig",// secp256k1_signature
27
- P2SIG = "p2sig",// p256_signature
28
- BLSIG = "BLsig",// bls12_381_signature
29
- SIG = "sig",// generic_signature
30
- NET = "Net",// chain_id
31
- NCE = "nce",
32
- B = "B",// block_hash
33
- O = "o",// operation_hash
34
- LO = "Lo",// operation_list_hash
35
- LLO = "LLo",// operation_list_list_hash
36
- P = "P",// protocol_hash
37
- CO = "Co",// context_hash
38
- ID = "id",// cryptobox_public_key_hash
39
- EXPR = "expr",
40
- TZ = "TZ",
41
- VH = "vh",// block_payload_hash
42
- SASK = "sask",// sapling_spending_key
43
- ZET1 = "zet1",// sapling_address
44
- SR1 = "sr1",// smart_rollup_address
45
- SRC1 = "src1",// smart_rollup_commitment
46
- SH = "sh"
47
- }
48
- /**
49
- * @deprecated use prefixV2 instead this constant will be removed in the next minor release
50
- * @description base58 prefix to bytes mapping
51
- */
52
- export declare const prefix: {
53
- tz1: Uint8Array;
54
- tz2: Uint8Array;
55
- tz3: Uint8Array;
56
- tz4: Uint8Array;
57
- KT: Uint8Array;
58
- KT1: Uint8Array;
59
- edsk: Uint8Array;
60
- edsk2: Uint8Array;
61
- spsk: Uint8Array;
62
- p2sk: Uint8Array;
63
- BLsk: Uint8Array;
64
- edpk: Uint8Array;
65
- sppk: Uint8Array;
66
- p2pk: Uint8Array;
67
- BLpk: Uint8Array;
68
- edesk: Uint8Array;
69
- spesk: Uint8Array;
70
- p2esk: Uint8Array;
71
- BLesk: Uint8Array;
72
- edsig: Uint8Array;
73
- spsig: Uint8Array;
74
- p2sig: Uint8Array;
75
- BLsig: Uint8Array;
76
- sig: Uint8Array;
77
- Net: Uint8Array;
78
- nce: Uint8Array;
79
- B: Uint8Array;
80
- o: Uint8Array;
81
- Lo: Uint8Array;
82
- LLo: Uint8Array;
83
- P: Uint8Array;
84
- Co: Uint8Array;
85
- id: Uint8Array;
86
- expr: Uint8Array;
87
- TZ: Uint8Array;
88
- vh: Uint8Array;
89
- sask: Uint8Array;
90
- zet1: Uint8Array;
91
- sr1: Uint8Array;
92
- src1: Uint8Array;
93
- sh: Uint8Array;
94
- };
95
- /**
96
- * @deprecated use payloadLength instead this constant will be removed in the next minor release
97
- * @description base58 prefix to payload length mapping
98
- */
99
- export declare const prefixLength: {
100
- [key: string]: number;
101
- };
102
1
  /**
103
2
  * @description base58 name to prefix mapping
104
3
  */
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module @taquito/utils
4
+ */
5
+ import { Buffer } from 'buffer';
6
+ import { PrefixV2 } from './constants';
7
+ import BigNumber from 'bignumber.js';
8
+ /**
9
+ * @description list of prefixes that can be used to decode an address
10
+ */
11
+ export declare const addressPrefixes: PrefixV2[];
12
+ /**
13
+ * @description list of prefixes that can be used to decode a public key
14
+ */
15
+ export declare const publicKeyPrefixes: PrefixV2[];
16
+ /**
17
+ * @description list of prefixes that can be used to decode a public key hash
18
+ */
19
+ export declare const publicKeyHashPrefixes: PrefixV2[];
20
+ /**
21
+ * @description list of prefixes that can be used to decode a signature
22
+ */
23
+ export declare const signaturePrefixes: PrefixV2[];
24
+ /**
25
+ * @description Decodes Base58 string, looks for known prefix and strips it
26
+ * @param src Base58 string
27
+ * @returns Payload and prefix
28
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
29
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash]) // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
30
+ * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash], true) // returns Uint8Array
31
+ */
32
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed?: T): [Uint8Array, T[number]];
33
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: false): [Uint8Array, T[number]];
34
+ export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: true): Uint8Array;
35
+ /**
36
+ * @description Decode a Base58 public key and return its binary representation
37
+ * @param value Value to decode
38
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
39
+ * @returns string or Uint8Array of bytes
40
+ * @example b58DecodePublicKey('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return '0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'
41
+ */
42
+ export declare function b58DecodePublicKey(value: string, fmt?: 'hex'): string;
43
+ export declare function b58DecodePublicKey(value: string, fmt: 'array'): Uint8Array;
44
+ /**
45
+ * @description Decode a Base58 public key hash and return its binary representation
46
+ * @param value Value to decode
47
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
48
+ * @returns string or Uint8Array of bytes
49
+ * @example b58DecodePublicKeyHash('tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe') // return '0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1'
50
+ */
51
+ export declare function b58DecodePublicKeyHash(value: string, fmt?: 'hex'): string;
52
+ export declare function b58DecodePublicKeyHash(value: string, fmt: 'array'): Uint8Array;
53
+ /**
54
+ * @description Decode a Base58 string and assert tz4 type
55
+ * @param value a bls address(tz4) to decode
56
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
57
+ * @returns string or Uint8Array of bytes
58
+ * @example b58DecodeBlsAddress('tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8') // return 'af2dc3c40667abc0e89c0ef40171d22aed08d5eb'
59
+ */
60
+ export declare function b58DecodeBlsAddress(value: string, fmt?: 'hex'): string;
61
+ export declare function b58DecodeBlsAddress(value: string, fmt: 'array'): Uint8Array;
62
+ /**
63
+ * @description Decode a Base58 contract ID and return its binary representation
64
+ * @param value Value to decode
65
+ * @param fmt optional format of the decoded return value, 'hex' or 'array'
66
+ * @returns string or Uint8Array of bytes
67
+ * @example b58DecodeAddress('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // return '0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'
68
+ */
69
+ export declare function b58DecodeAddress(value: string, fmt?: 'hex'): string;
70
+ export declare function b58DecodeAddress(value: string, fmt: 'array'): Uint8Array;
71
+ /**
72
+ * @description Gets Tezos address (PKH) from Public Key
73
+ * @param publicKey Base58 Public Key
74
+ * @returns A string of the Tezos address (PKH) that was derived from the given Public Key
75
+ * @example getPkhfromPk('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
76
+ */
77
+ export declare function getPkhfromPk(publicKey: string): string;
78
+ /**
79
+ * @description Add the prefix to a hex string or Uint8Array and Base58 encode it
80
+ * @param value Value to Base58 encode
81
+ * @param pre prefix ID to append to the encoded string
82
+ * @example b58Encode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', PrefixV2.Ed25519PublicKeyHash) // returns 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
83
+ */
84
+ export declare function b58Encode(value: string | Uint8Array, pre: PrefixV2): string;
85
+ /**
86
+ * @description Parse binary public key and return Base58 representation
87
+ * @param value Binary key data
88
+ * @returns return prefixed public key
89
+ * @example encodeKey('02033aba7da4a2e7b5dd9f074555c118829aff16213ea1b65859686bd5fcfeaf3616') // return 'p2pk66xmhjiN7LpfrDGFwpxPtJxkLtPjQ6HUxJbKmRbxSR7RMpamDwi'
90
+ */
91
+ export declare function encodeKey(value: string | Uint8Array): string;
92
+ /**
93
+ * @description Parse binary public key hash and return Base58 representation
94
+ * @param value Key hash to parse
95
+ * @returns return prefixed public key hash
96
+ * @example encodeKeyHash('0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
97
+ */
98
+ export declare function encodeKeyHash(value: string | Uint8Array): string;
99
+ /**
100
+ * @description Parse binary Contract ID and return Base58 representation
101
+ * @param value Address to parse (tz1, tz2, tz3, KT1, or sr1).
102
+ * @example encodeAddress('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f') // return 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
103
+ */
104
+ export declare function encodeAddress(value: string | Uint8Array): string;
105
+ /**
106
+ * @description Base58 encode an address without predefined prefix
107
+ * @param value Address to base58 encode (tz4) hex dec
108
+ * @returns return address
109
+ * @example encodeBlsAddress('af2dc3c40667abc0e89c0ef40171d22aed08d5eb') // return 'tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8'
110
+ */
111
+ export declare function encodeBlsAddress(value: string): string;
112
+ /**
113
+ * @description convert a fragment of Michelson code in hex string to an 'expr' prefix + base58 encoded BLAKE2b hash string
114
+ * @param value a fragment of Michelson code in hex string
115
+ * @returns return 'expr' prefix + base58 encoded BLAKE2b hash
116
+ * @example encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea') // return 'exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN'
117
+ */
118
+ export declare function encodeExpr(value: string): string;
119
+ /**
120
+ * @description convert a signed operation in hex string to an 'op' prefix + base58 encoded BLAKE2b hash string
121
+ * @param value signed operation in hex string
122
+ * @returns return 'op' prefix + base58 encoded BLAKE2b hash
123
+ * @example encodeOpHash('0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d') // return 'opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t'
124
+ */
125
+ export declare function encodeOpHash(value: string): string;
126
+ /**
127
+ * @description Convert an hex string to a Uint8Array
128
+ * @param hex Hex string to convert
129
+ * @throws {@link ValueConversionError}
130
+ */
131
+ export declare function hex2buf(hex: string): Uint8Array;
132
+ /**
133
+ * @description Merge 2 buffers together
134
+ * @param b1 First buffer
135
+ * @param b2 Second buffer
136
+ */
137
+ export declare function mergebuf(b1: Uint8Array, b2: Uint8Array): Uint8Array;
138
+ /**
139
+ * @description Flatten a michelson json representation to an array
140
+ * @param s michelson json
141
+ */
142
+ export declare function mic2arr(s: any): any;
143
+ /**
144
+ * @description Convert a Uint8Array to an hex string
145
+ * @param buffer Uint8Array to convert
146
+ */
147
+ export declare function buf2hex(bytes: ArrayLike<number>): string;
148
+ /**
149
+ * @description Convert a string to a byte string representation
150
+ * @param str String to convert
151
+ */
152
+ export declare function stringToBytes(str: string): string;
153
+ /**
154
+ * @description Convert byte string representation to string
155
+ * @param hex byte string to convert
156
+ */
157
+ export declare function bytesToString(hex: string): string;
158
+ /**
159
+ * @description Convert hex string/UintArray/Buffer to bytes
160
+ * @param hex String value to convert to bytes
161
+ */
162
+ export declare function hex2Bytes(hex: string): Buffer;
163
+ /**
164
+ * @description Converts a number or Bignumber to hexadecimal string
165
+ * @param val The value that will be converted to a hexadecimal string value
166
+ */
167
+ export declare function toHexBuf(val: number | BigNumber, bitLength?: number): Buffer;
168
+ export declare function numToHexBuffer(val: number | BigNumber, bitLength?: number): Buffer;
169
+ /**
170
+ * @description Converts a number or BigNumber to a padded hexadecimal string
171
+ * @param val The value that will be converted into a padded hexadecimal string value
172
+ * @param bitLength The length of bits
173
+ *
174
+ */
175
+ export declare function num2PaddedHex(val: number | BigNumber, bitLength?: number): string;
176
+ /**
177
+ *
178
+ * @description Strips the first 2 characters of a hex string (0x)
179
+ *
180
+ * @param hex string to strip prefix from
181
+ */
182
+ export declare function stripHexPrefix(hex: string): string;
183
+ export declare function splitAddress(addr: string): [string, string | null];
184
+ export declare function compareArrays(a: ArrayLike<number>, b: ArrayLike<number>): number;
@@ -2,243 +2,10 @@
2
2
  * @packageDocumentation
3
3
  * @module @taquito/utils
4
4
  */
5
- import { Buffer } from 'buffer';
6
- import { PrefixV2 } from './constants';
7
- import BigNumber from 'bignumber.js';
5
+ export * from './encoding';
8
6
  export * from './validators';
9
7
  export { VERSION } from './version';
10
- export { prefix, Prefix, prefixLength } from './constants';
11
8
  export { PrefixV2, payloadLength } from './constants';
12
- export { validatePkAndExtractPrefix } from './verify-signature';
13
9
  export { verifySignature, BLS12_381_DST, POP_DST } from './verify-signature';
14
10
  export * from './errors';
15
11
  export { format } from './format';
16
- /**
17
- * @description list of prefixes that can be used to decode an address
18
- */
19
- export declare const addressPrefixes: PrefixV2[];
20
- /**
21
- * @description list of prefixes that can be used to decode a public key
22
- */
23
- export declare const publicKeyPrefixes: PrefixV2[];
24
- /**
25
- * @description list of prefixes that can be used to decode a public key hash
26
- */
27
- export declare const publicKeyHashPrefixes: PrefixV2[];
28
- /**
29
- * @description list of prefixes that can be used to decode a signature
30
- */
31
- export declare const signaturePrefixes: PrefixV2[];
32
- /**
33
- * @description Decodes Base58 string, looks for known prefix and strips it
34
- * @param src Base58 string
35
- * @returns Payload and prefix
36
- * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
37
- * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash]) // returns [Uint8Array, PrefixV2.Ed25519PublicKeyHash]
38
- * @example b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash], true) // returns Uint8Array
39
- */
40
- export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed?: T): [Uint8Array, T[number]];
41
- export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: false): [Uint8Array, T[number]];
42
- export declare function b58DecodeAndCheckPrefix<T extends readonly PrefixV2[]>(src: string, allowed: T, payloadOnly: true): Uint8Array;
43
- /**
44
- * @description Decode a Base58 public key and return its binary representation
45
- * @param value Value to decode
46
- * @param fmt optional format of the decoded return value, 'hex' or 'array'
47
- * @returns string or Uint8Array of bytes
48
- * @example b58DecodePublicKey('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return '0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'
49
- */
50
- export declare function b58DecodePublicKey(value: string, fmt?: 'hex'): string;
51
- export declare function b58DecodePublicKey(value: string, fmt: 'array'): Uint8Array;
52
- /**
53
- * @description Decode a Base58 public key hash and return its binary representation
54
- * @param value Value to decode
55
- * @param fmt optional format of the decoded return value, 'hex' or 'array'
56
- * @returns string or Uint8Array of bytes
57
- * @example b58DecodePublicKeyHash('tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe') // return '0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1'
58
- */
59
- export declare function b58DecodePublicKeyHash(value: string, fmt?: 'hex'): string;
60
- export declare function b58DecodePublicKeyHash(value: string, fmt: 'array'): Uint8Array;
61
- /**
62
- * @description Decode a Base58 string and assert tz4 type
63
- * @param value a bls address(tz4) to decode
64
- * @param fmt optional format of the decoded return value, 'hex' or 'array'
65
- * @returns string or Uint8Array of bytes
66
- * @example b58DecodeBlsAddress('tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8') // return 'af2dc3c40667abc0e89c0ef40171d22aed08d5eb'
67
- */
68
- export declare function b58DecodeBlsAddress(value: string, fmt?: 'hex'): string;
69
- export declare function b58DecodeBlsAddress(value: string, fmt: 'array'): Uint8Array;
70
- /**
71
- * @description Decode a Base58 contract ID and return its binary representation
72
- * @param value Value to decode
73
- * @param fmt optional format of the decoded return value, 'hex' or 'array'
74
- * @returns string or Uint8Array of bytes
75
- * @example b58DecodeAddress('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM') // return '0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'
76
- */
77
- export declare function b58DecodeAddress(value: string, fmt?: 'hex'): string;
78
- export declare function b58DecodeAddress(value: string, fmt: 'array'): Uint8Array;
79
- /**
80
- * @description Gets Tezos address (PKH) from Public Key
81
- * @param publicKey Base58 Public Key
82
- * @returns A string of the Tezos address (PKH) that was derived from the given Public Key
83
- * @example getPkhfromPk('edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
84
- */
85
- export declare function getPkhfromPk(publicKey: string): string;
86
- /**
87
- * @description Add the prefix to a hex string or Uint8Array and Base58 encode it
88
- * @param value Value to Base58 encode
89
- * @param pre prefix ID to append to the encoded string
90
- * @example b58Encode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', PrefixV2.Ed25519PublicKeyHash) // returns 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
91
- */
92
- export declare function b58Encode(value: string | Uint8Array, pre: PrefixV2): string;
93
- /**
94
- * @description Parse binary public key and return Base58 representation
95
- * @param value Binary key data
96
- * @returns return prefixed public key
97
- * @example encodeKey('02033aba7da4a2e7b5dd9f074555c118829aff16213ea1b65859686bd5fcfeaf3616') // return 'p2pk66xmhjiN7LpfrDGFwpxPtJxkLtPjQ6HUxJbKmRbxSR7RMpamDwi'
98
- */
99
- export declare function encodeKey(value: string | Uint8Array): string;
100
- /**
101
- * @description Parse binary public key hash and return Base58 representation
102
- * @param value Key hash to parse
103
- * @returns return prefixed public key hash
104
- * @example encodeKeyHash('0001907d6a7e9f084df840d6e67ffa8db5464f87d4d1') // return 'tz2MVED1t9Jery77Bwm1m5YhUx8Wp5KWWRQe'
105
- */
106
- export declare function encodeKeyHash(value: string | Uint8Array): string;
107
- /**
108
- * @description Parse binary Contract ID and return Base58 representation
109
- * @param value Address to parse (tz1, tz2, tz3, KT1, or sr1).
110
- * @example encodeAddress('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f') // return 'tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'
111
- */
112
- export declare function encodeAddress(value: string | Uint8Array): string;
113
- /**
114
- * @description Base58 encode an address without predefined prefix
115
- * @param value Address to base58 encode (tz4) hex dec
116
- * @returns return address
117
- * @example encodeBlsAddress('af2dc3c40667abc0e89c0ef40171d22aed08d5eb') // return 'tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8'
118
- */
119
- export declare function encodeBlsAddress(value: string): string;
120
- /**
121
- * @description convert a fragment of Michelson code in hex string to an 'expr' prefix + base58 encoded BLAKE2b hash string
122
- * @param value a fragment of Michelson code in hex string
123
- * @returns return 'expr' prefix + base58 encoded BLAKE2b hash
124
- * @example encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea') // return 'exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN'
125
- */
126
- export declare function encodeExpr(value: string): string;
127
- /**
128
- * @description convert a signed operation in hex string to an 'op' prefix + base58 encoded BLAKE2b hash string
129
- * @param value signed operation in hex string
130
- * @returns return 'op' prefix + base58 encoded BLAKE2b hash
131
- * @example encodeOpHash('0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d') // return 'opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t'
132
- */
133
- export declare function encodeOpHash(value: string): string;
134
- /**
135
- * @description Convert an hex string to a Uint8Array
136
- * @param hex Hex string to convert
137
- * @throws {@link ValueConversionError}
138
- */
139
- export declare function hex2buf(hex: string): Uint8Array;
140
- /**
141
- * @description Merge 2 buffers together
142
- * @param b1 First buffer
143
- * @param b2 Second buffer
144
- */
145
- export declare function mergebuf(b1: Uint8Array, b2: Uint8Array): Uint8Array;
146
- /**
147
- * @description Flatten a michelson json representation to an array
148
- * @param s michelson json
149
- */
150
- export declare function mic2arr(s: any): any;
151
- /**
152
- * @description Convert a Uint8Array to an hex string
153
- * @param buffer Uint8Array to convert
154
- */
155
- export declare function buf2hex(bytes: ArrayLike<number>): string;
156
- /**
157
- * @description Convert a string to a byte string representation
158
- * @param str String to convert
159
- */
160
- export declare function stringToBytes(str: string): string;
161
- /**
162
- * @description Convert byte string representation to string
163
- * @param hex byte string to convert
164
- */
165
- export declare function bytesToString(hex: string): string;
166
- /**
167
- * @description Convert hex string/UintArray/Buffer to bytes
168
- * @param hex String value to convert to bytes
169
- */
170
- export declare function hex2Bytes(hex: string): Buffer;
171
- /**
172
- * @description Converts a number or Bignumber to hexadecimal string
173
- * @param val The value that will be converted to a hexadecimal string value
174
- */
175
- export declare function toHexBuf(val: number | BigNumber, bitLength?: number): Buffer;
176
- export declare function numToHexBuffer(val: number | BigNumber, bitLength?: number): Buffer;
177
- /**
178
- * @description Converts a number or BigNumber to a padded hexadecimal string
179
- * @param val The value that will be converted into a padded hexadecimal string value
180
- * @param bitLength The length of bits
181
- *
182
- */
183
- export declare function num2PaddedHex(val: number | BigNumber, bitLength?: number): string;
184
- /**
185
- *
186
- * @description Strips the first 2 characters of a hex string (0x)
187
- *
188
- * @param hex string to strip prefix from
189
- */
190
- export declare function stripHexPrefix(hex: string): string;
191
- export declare function splitAddress(addr: string): [string, string | null];
192
- export declare function compareArrays(a: ArrayLike<number>, b: ArrayLike<number>): number;
193
- /**
194
- * @deprecated use b58DecodeAndCheckPrefix instead, this function will be removed in the next minor release
195
- * @description Base58 decode a string and remove the prefix from it
196
- * @param enc Value to base58 decode
197
- * @param prefixArg prefix to remove from the decoded string
198
- */
199
- export declare function b58cdecode(enc: string, prefixArg: Uint8Array): Uint8Array;
200
- /**
201
- * @deprecated use b58Encode instead, this function will be removed in the next minor release
202
- * @description Base58 encode a string or a Uint8Array and append a prefix to it
203
- * @param value Value to base58 encode
204
- * @param prefix prefix to append to the encoded string
205
- */
206
- export declare function b58cencode(value: string | Uint8Array, prefix: Uint8Array): string;
207
- /**
208
- * @deprecated use b58DecodePublicKey, b58DecodePublicKeyHash, b58DecodeBlsAddress, b58DecodeAddress instead, this function will be removed in the next minor release
209
- * @description Base58 decode a string with predefined prefix
210
- * @param payload Value to base58 decode
211
- */
212
- export declare function b58decode(payload: string): string;
213
- /**
214
- * @deprecated use b58DecodeBlsAddress instead, this function will be removed in the next minor release
215
- * @description b58 decode a string without predefined prefix
216
- * @param payload Value to base58 decode
217
- * @returns string of bytes
218
- */
219
- export declare function b58decodeL2Address(payload: string): string;
220
- /**
221
- * @deprecated use encodeAddress instead, this function will be removed in the next minor release
222
- * @description Base58 encode an address using predefined prefix
223
- * @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
224
- */
225
- export declare function encodePubKey(value: string): string;
226
- /**
227
- * @deprecated use encodeBlsAddress instead, this function will be removed in the next minor release
228
- * @description Base58 encode an address without predefined prefix
229
- * @param value Address to base58 encode (tz4) hex dec
230
- * @returns return address
231
- */
232
- export declare function encodeL2Address(value: string): string;
233
- /**
234
- * @deprecated use stringToBytes instead, this function will be removed in the next minor release
235
- * @description Convert a string to bytes
236
- * @param str String to convert
237
- */
238
- export declare function char2Bytes(str: string): string;
239
- /**
240
- * @deprecated use bytesToString instead, this function will be removed in the next minor release
241
- * @description Convert bytes to a string
242
- * @param hex Bytes to convert
243
- */
244
- export declare function bytes2Char(hex: string): string;
@@ -1,5 +1,5 @@
1
1
  import { PrefixV2 } from './constants';
2
- import { ValidationResult } from './taquito-utils';
2
+ import { ValidationResult } from '@taquito/core';
3
3
  export { ValidationResult } from '@taquito/core';
4
4
  /**
5
5
  * @description Used to check if a value has one of the allowed prefixes.
@@ -157,11 +157,6 @@ export declare function validateProtocol(value: string): ValidationResult;
157
157
  * ```
158
158
  */
159
159
  export declare function validateBlock(value: string): ValidationResult;
160
- /**
161
- * @deprecated this function will be removed in the next minor release
162
- * @description generates a readable error string from a validation result
163
- */
164
- export declare function invalidDetail(validation: ValidationResult): string;
165
160
  /**
166
161
  * @description Used to check if a spending key is valid.
167
162
  * @returns
@@ -1,4 +1,3 @@
1
- import { PrefixV2 } from './taquito-utils';
2
1
  export declare const BLS12_381_DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
3
2
  export declare const POP_DST = "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
4
3
  /**
@@ -21,10 +20,3 @@ export declare const POP_DST = "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
21
20
  *
22
21
  */
23
22
  export declare function verifySignature(message: string | Uint8Array, publicKey: string, signature: string, watermark?: Uint8Array, pop?: boolean): boolean;
24
- type PkPrefix = PrefixV2.Ed25519PublicKey | PrefixV2.Secp256k1PublicKey | PrefixV2.P256PublicKey | PrefixV2.BLS12_381PublicKey;
25
- /**
26
- * @deprecated use b58DecodeAndCheckPrefix instead, this function will be removed in the next minor release
27
- * @description validates a public key and extracts the prefix
28
- */
29
- export declare function validatePkAndExtractPrefix(publicKey: string): PkPrefix;
30
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/utils",
3
- "version": "23.0.3",
3
+ "version": "24.0.0-beta.0",
4
4
  "description": "converts michelson data and types into convenient JS/TS objects",
5
5
  "keywords": [
6
6
  "tezos",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "license": "Apache-2.0",
27
27
  "engines": {
28
- "node": ">=18"
28
+ "node": ">=20"
29
29
  },
30
30
  "scripts": {
31
31
  "lint": "eslint --ext .js,.ts .",
@@ -62,23 +62,22 @@
62
62
  ]
63
63
  },
64
64
  "dependencies": {
65
- "@noble/curves": "^1.9.6",
65
+ "@noble/curves": "^1.9.7",
66
66
  "@stablelib/blake2b": "^1.0.1",
67
67
  "@stablelib/ed25519": "^1.0.3",
68
- "@taquito/core": "^23.0.3",
68
+ "@taquito/core": "^24.0.0-beta.0",
69
69
  "@types/bs58check": "^2.1.2",
70
70
  "bignumber.js": "^9.1.2",
71
71
  "blakejs": "^1.2.1",
72
72
  "bs58check": "^3.0.1",
73
73
  "buffer": "^6.0.3",
74
- "elliptic": "^6.6.1",
75
74
  "typedarray-to-buffer": "^4.0.0"
76
75
  },
77
76
  "devDependencies": {
78
77
  "@types/bluebird": "^3.5.42",
79
- "@types/elliptic": "^6.4.18",
80
78
  "@types/jest": "^29.5.12",
81
- "@types/node": "^18",
79
+ "@types/node": "^20",
80
+ "@types/typedarray-to-buffer": "^4.0.4",
82
81
  "@typescript-eslint/eslint-plugin": "^6.21.0",
83
82
  "@typescript-eslint/parser": "^6.21.0",
84
83
  "colors": "^1.4.0",
@@ -95,6 +94,7 @@
95
94
  "rimraf": "^6.0.1",
96
95
  "rollup": "^4.22.4",
97
96
  "rollup-plugin-json": "^4.0.0",
97
+ "rollup-plugin-polyfill-node": "^0.13.0",
98
98
  "rollup-plugin-typescript2": "^0.36.0",
99
99
  "shelljs": "^0.8.5",
100
100
  "ts-jest": "^29.2.3",
@@ -102,5 +102,5 @@
102
102
  "ts-toolbelt": "^9.6.0",
103
103
  "typescript": "~5.5.4"
104
104
  },
105
- "gitHead": "2abf349e97af45f11210b3121078b9d96699d5da"
105
+ "gitHead": "f212ea3edaf1fac34d738b5d00a9892ab7a3b721"
106
106
  }