@taquito/utils 23.0.0-beta.0 → 23.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-utils.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"taquito-utils.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @deprecated use PrefixV2 instead, this enum will be removed in the next minor release
3
+ * @description base58 prefix definition enum
4
+ */
1
5
  export declare enum Prefix {
2
6
  TZ1 = "tz1",// ed25519_public_key_hash
3
7
  TZ2 = "tz2",// secp256k1_public_key_hash
@@ -41,6 +45,10 @@ export declare enum Prefix {
41
45
  SRC1 = "src1",// smart_rollup_commitment
42
46
  SH = "sh"
43
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
+ */
44
52
  export declare const prefix: {
45
53
  tz1: Uint8Array;
46
54
  tz2: Uint8Array;
@@ -84,6 +92,88 @@ export declare const prefix: {
84
92
  src1: Uint8Array;
85
93
  sh: Uint8Array;
86
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
+ */
87
99
  export declare const prefixLength: {
88
100
  [key: string]: number;
89
101
  };
102
+ /**
103
+ * @description base58 name to prefix mapping
104
+ */
105
+ export declare enum PrefixV2 {
106
+ BlockHash = "B",
107
+ OperationHash = "o",
108
+ OperationListHash = "Lo",
109
+ OperationListListHash = "LLo",
110
+ ProtocolHash = "P",
111
+ ContextHash = "Co",
112
+ BlockMetadataHash = "bm",
113
+ OperationMetadataHash = "r",
114
+ OperationMetadataListHash = "Lr",
115
+ OperationMetadataListListHash = "LLr",
116
+ Ed25519PublicKeyHash = "tz1",
117
+ Secp256k1PublicKeyHash = "tz2",
118
+ P256PublicKeyHash = "tz3",
119
+ ContractHash = "KT1",
120
+ BlindedPublicKeyHash = "btz1",
121
+ BLS12_381PublicKeyHash = "tz4",
122
+ TXRollupAddress = "txr1",
123
+ ZkRollupHash = "epx1",
124
+ ScRollupHash = "scr1",
125
+ SmartRollupHash = "sr1",
126
+ CryptoboxPublicKeyHash = "id",
127
+ Ed25519Seed = "edsk",
128
+ Ed25519PublicKey = "edpk",
129
+ Secp256k1SecretKey = "spsk",
130
+ P256SecretKey = "p2sk",
131
+ BLS12_381SecretKey = "BLsk",
132
+ ValueHash = "vh",
133
+ CycleNonce = "nce",
134
+ ScriptExpr = "expr",
135
+ InboxHash = "txi",
136
+ MessageHash = "txm",
137
+ CommitmentHash = "txc",
138
+ MessageResultHash = "txmr",
139
+ MessageResultListHash = "txM",
140
+ WithdrawListHash = "txw",
141
+ ScRollupStateHash = "scs1",
142
+ ScRollupCommitmentHash = "scc1",
143
+ SmartRollupStateHash = "srs1",
144
+ SmartRollupCommitmentHash = "src1",
145
+ Ed25519EncryptedSeed = "edesk",
146
+ Secp256k1EncryptedSecretKey = "spesk",
147
+ P256EncryptedSecretKey = "p2esk",
148
+ BLS12_381EncryptedSecretKey = "BLesk",
149
+ Secp256k1EncryptedScalar = "seesk",
150
+ Secp256k1PublicKey = "sppk",
151
+ P256PublicKey = "p2pk",
152
+ Secp256k1Scalar = "SSp",
153
+ Secp256k1Element = "GSp",
154
+ Ed25519SecretKey = "_edsk",
155
+ Ed25519Signature = "edsig",
156
+ Secp256k1Signature = "spsig1",
157
+ P256Signature = "p2sig",
158
+ GenericSignature = "sig",
159
+ ChainID = "Net",
160
+ SaplingSpendingKey = "sask",
161
+ EncryptedSaplingSpendingKey = "_sask",
162
+ SaplingAddress = "zet1",
163
+ GenericAggregateSignature = "asig",
164
+ BLS12_381Signature = "BLsig",
165
+ BLS12_381PublicKey = "BLpk",
166
+ SlotHeader = "sh"
167
+ }
168
+ /**
169
+ * @description base58 prefix to bytes mapping
170
+ */
171
+ export declare const prefixV2: {
172
+ [key in PrefixV2]: Uint8Array;
173
+ };
174
+ /**
175
+ * @description base58 prefix to payload length mapping
176
+ */
177
+ export declare const payloadLength: {
178
+ [key in PrefixV2]: number;
179
+ };
@@ -1,4 +1,4 @@
1
- import { ParameterValidationError, UnsupportedActionError } from '@taquito/core';
1
+ import { ParameterValidationError, UnsupportedActionError, ValidationResult } from '@taquito/core';
2
2
  export { InvalidAddressError, InvalidBlockHashError, InvalidHexStringError, InvalidMessageError, InvalidKeyError, InvalidPublicKeyError, InvalidSignatureError, InvalidContractAddressError, InvalidChainIdError, InvalidKeyHashError, InvalidOperationHashError, InvalidOperationKindError, DeprecationError, ProhibitedActionError, } from '@taquito/core';
3
3
  /**
4
4
  * @category Error
@@ -6,9 +6,8 @@ export { InvalidAddressError, InvalidBlockHashError, InvalidHexStringError, Inva
6
6
  */
7
7
  export declare class InvalidProtocolHashError extends ParameterValidationError {
8
8
  readonly protocolHash: string;
9
- readonly errorDetails?: string | undefined;
10
9
  name: string;
11
- constructor(protocolHash: string, errorDetails?: string | undefined);
10
+ constructor(protocolHash: string, errorDetails?: string | ValidationResult);
12
11
  }
13
12
  /**
14
13
  * @category Error
@@ -3,179 +3,178 @@
3
3
  * @module @taquito/utils
4
4
  */
5
5
  import { Buffer } from 'buffer';
6
+ import { PrefixV2 } from './constants';
6
7
  import BigNumber from 'bignumber.js';
7
8
  export * from './validators';
8
9
  export { VERSION } from './version';
9
10
  export { prefix, Prefix, prefixLength } from './constants';
10
- export { verifySignature, validatePkAndExtractPrefix } from './verify-signature';
11
+ export { PrefixV2, payloadLength } from './constants';
12
+ export { validatePkAndExtractPrefix } from './verify-signature';
13
+ export { verifySignature, BLS12_381_DST, POP_DST } from './verify-signature';
11
14
  export * from './errors';
12
15
  export { format } from './format';
13
16
  /**
14
- *
15
- * @description Hash a string using the BLAKE2b algorithm, base58 encode the hash obtained and appends the prefix 'expr' to it
16
- *
17
- * @param value Value in hex
17
+ * @description list of prefixes that can be used to decode an address
18
18
  */
19
- export declare function encodeExpr(value: string): string;
19
+ export declare const addressPrefixes: PrefixV2[];
20
20
  /**
21
- *
22
- * @description Return the operation hash of a signed operation
23
- * @param value Value in hex of a signed operation
21
+ * @description list of prefixes that can be used to decode a public key
24
22
  */
25
- export declare function encodeOpHash(value: string): string;
23
+ export declare const publicKeyPrefixes: PrefixV2[];
26
24
  /**
27
- *
28
- * @description Base58 encode a string or a Uint8Array and append a prefix to it
29
- *
30
- * @param value Value to base58 encode
31
- * @param prefix prefix to append to the encoded string
25
+ * @description list of prefixes that can be used to decode a public key hash
32
26
  */
33
- export declare function b58cencode(value: string | Uint8Array, prefix: Uint8Array): string;
27
+ export declare const publicKeyHashPrefixes: PrefixV2[];
34
28
  /**
35
- *
36
- * @description Base58 decode a string and remove the prefix from it
37
- *
38
- * @param value Value to base58 decode
39
- * @param prefix prefix to remove from the decoded string
29
+ * @description list of prefixes that can be used to decode a signature
40
30
  */
41
- export declare const b58cdecode: (enc: string, prefixArg: Uint8Array) => Uint8Array;
31
+ export declare const signaturePrefixes: PrefixV2[];
42
32
  /**
43
- *
44
- * @description Base58 decode a string with predefined prefix
45
- *
46
- * @param value Value to base58 decode
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
47
39
  */
48
- export declare function b58decode(payload: string): string;
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;
49
43
  /**
50
- *
51
- * @description b58 decode a string without predefined prefix
52
- * @param value
53
- * @returns string of bytes
54
- * @deprecated use b58decode instead
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'
55
49
  */
56
- export declare function b58decodeL2Address(payload: string): string;
50
+ export declare function b58DecodePublicKey(value: string, fmt?: 'hex'): string;
51
+ export declare function b58DecodePublicKey(value: string, fmt: 'array'): Uint8Array;
57
52
  /**
58
- *
59
- * @description Base58 encode an address using predefined prefix
60
- *
61
- * @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
62
- * @deprecated use encodeAddress instead, same functionality with a more descriptive name
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'
63
58
  */
64
- export declare function encodePubKey(value: string): string;
59
+ export declare function b58DecodePublicKeyHash(value: string, fmt?: 'hex'): string;
60
+ export declare function b58DecodePublicKeyHash(value: string, fmt: 'array'): Uint8Array;
65
61
  /**
66
- *
67
- * @description Base58 encode an address using predefined prefix (tz1, tz2, tz3, or KT1 without annotation)
68
- *
69
- * @param value Address to base58 encode (tz1, tz2, tz3 or KT1). Supports value with or without '0x' prefix
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'
70
67
  */
71
- export declare function encodeAddress(value: string): string;
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;
72
113
  /**
73
- *
74
114
  * @description Base58 encode an address without predefined prefix
75
115
  * @param value Address to base58 encode (tz4) hex dec
76
116
  * @returns return address
77
- * @deprecated use encodeAddress instead
117
+ * @example encodeBlsAddress('af2dc3c40667abc0e89c0ef40171d22aed08d5eb') // return 'tz4QyWfEiv56CVDATV3DT3CDVhPaMKif2Ce8'
78
118
  */
79
- export declare function encodeL2Address(value: string): string;
119
+ export declare function encodeBlsAddress(value: string): string;
80
120
  /**
81
- *
82
- * @description Base58 encode a key according to its prefix
83
- *
84
- * @param value Key to base58 encode
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'
85
125
  */
86
- export declare function encodeKey(value: string): string | undefined;
126
+ export declare function encodeExpr(value: string): string;
87
127
  /**
88
- *
89
- * @description Base58 encode a key hash according to its prefix
90
- *
91
- * @param value Key hash to base58 encode
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'
92
132
  */
93
- export declare function encodeKeyHash(value: string): string | undefined;
133
+ export declare function encodeOpHash(value: string): string;
94
134
  /**
95
- *
96
135
  * @description Convert an hex string to a Uint8Array
97
- *
98
136
  * @param hex Hex string to convert
99
137
  * @throws {@link ValueConversionError}
100
138
  */
101
- export declare const hex2buf: (hex: string) => Uint8Array;
139
+ export declare function hex2buf(hex: string): Uint8Array;
102
140
  /**
103
- *
104
141
  * @description Merge 2 buffers together
105
- *
106
142
  * @param b1 First buffer
107
143
  * @param b2 Second buffer
108
144
  */
109
- export declare const mergebuf: (b1: Uint8Array, b2: Uint8Array) => Uint8Array;
145
+ export declare function mergebuf(b1: Uint8Array, b2: Uint8Array): Uint8Array;
110
146
  /**
111
- *
112
147
  * @description Flatten a michelson json representation to an array
113
- *
114
148
  * @param s michelson json
115
149
  */
116
- export declare const mic2arr: (s: any) => any;
150
+ export declare function mic2arr(s: any): any;
117
151
  /**
118
- *
119
152
  * @description Convert a Uint8Array to an hex string
120
- *
121
153
  * @param buffer Uint8Array to convert
122
154
  */
123
- export declare const buf2hex: (buffer: Uint8Array) => string;
155
+ export declare function buf2hex(bytes: ArrayLike<number>): string;
124
156
  /**
125
- *
126
- * @description Gets Tezos address (PKH) from Public Key
127
- *
128
- * @param publicKey Public Key
129
- * @returns A string of the Tezos address (PKH) that was derived from the given Public Key
130
- */
131
- export declare const getPkhfromPk: (publicKey: string) => string;
132
- /**
133
- *
134
- * @description Convert a string to bytes
135
- *
136
- * @param str String to convert
137
- * @deprecated use stringToBytes instead, same functionality with a more descriptive name
138
- */
139
- export declare function char2Bytes(str: string): string;
140
- /**
141
- *
142
157
  * @description Convert a string to a byte string representation
143
- *
144
158
  * @param str String to convert
145
159
  */
146
160
  export declare function stringToBytes(str: string): string;
147
161
  /**
148
- *
149
- * @description Convert bytes to a string
150
- *
151
- * @param str Bytes to convert
152
- * @deprecated use hexStringToBytes instead, same functionality with a more descriptive name
153
- */
154
- export declare function bytes2Char(hex: string): string;
155
- /**
156
- *
157
162
  * @description Convert byte string representation to string
158
- *
159
- * @param str byte string to convert
163
+ * @param hex byte string to convert
160
164
  */
161
165
  export declare function bytesToString(hex: string): string;
162
166
  /**
163
- *
164
167
  * @description Convert hex string/UintArray/Buffer to bytes
165
- *
166
168
  * @param hex String value to convert to bytes
167
169
  */
168
170
  export declare function hex2Bytes(hex: string): Buffer;
169
171
  /**
170
- *
171
172
  * @description Converts a number or Bignumber to hexadecimal string
172
- *
173
173
  * @param val The value that will be converted to a hexadecimal string value
174
174
  */
175
175
  export declare function toHexBuf(val: number | BigNumber, bitLength?: number): Buffer;
176
176
  export declare function numToHexBuffer(val: number | BigNumber, bitLength?: number): Buffer;
177
177
  /**
178
- *
179
178
  * @description Converts a number or BigNumber to a padded hexadecimal string
180
179
  * @param val The value that will be converted into a padded hexadecimal string value
181
180
  * @param bitLength The length of bits
@@ -189,3 +188,57 @@ export declare function num2PaddedHex(val: number | BigNumber, bitLength?: numbe
189
188
  * @param hex string to strip prefix from
190
189
  */
191
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 b58DecodeAndCheckPrefix 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,16 +1,23 @@
1
- import { Prefix } from './constants';
2
- export declare enum ValidationResult {
3
- NO_PREFIX_MATCHED = 0,
4
- INVALID_CHECKSUM = 1,
5
- INVALID_LENGTH = 2,
6
- VALID = 3
7
- }
8
- export declare function isValidPrefix(value: unknown): value is Prefix;
1
+ import { PrefixV2 } from './constants';
2
+ import { ValidationResult } from './taquito-utils';
3
+ export { ValidationResult } from '@taquito/core';
4
+ /**
5
+ * @description Used to check if a value has one of the allowed prefixes.
6
+ * @returns true if the value has one of the allowed prefixes, false otherwise
7
+ * @example
8
+ * ```
9
+ * import { isValidPrefixedValue } from '@taquito/utils';
10
+ * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
11
+ * const isValid = isValidPrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
12
+ * console.log(isValid) // true
13
+ * ```
14
+ */
15
+ export declare function isValidPrefixedValue(value: string, prefixes?: PrefixV2[]): boolean;
9
16
  /**
10
17
  * @description Used to check if an address or a contract address is valid.
11
18
  *
12
19
  * @returns
13
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
20
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
14
21
  *
15
22
  * @example
16
23
  * ```
@@ -26,7 +33,7 @@ export declare function validateAddress(value: string): ValidationResult;
26
33
  * @description Used to check if a chain id is valid.
27
34
  *
28
35
  * @returns
29
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
36
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
30
37
  *
31
38
  * @example
32
39
  * ```
@@ -42,7 +49,7 @@ export declare function validateChain(value: string): ValidationResult;
42
49
  * @description Used to check if a contract address is valid.
43
50
  *
44
51
  * @returns
45
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
52
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
46
53
  *
47
54
  * @example
48
55
  * ```
@@ -58,7 +65,7 @@ export declare function validateContractAddress(value: string): ValidationResult
58
65
  * @description Used to check if a key hash is valid.
59
66
  *
60
67
  * @returns
61
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
68
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
62
69
  *
63
70
  * @example
64
71
  * ```
@@ -74,7 +81,7 @@ export declare function validateKeyHash(value: string): ValidationResult;
74
81
  * @description Used to check if a signature is valid.
75
82
  *
76
83
  * @returns
77
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
84
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
78
85
  *
79
86
  * @example
80
87
  * ```
@@ -90,7 +97,7 @@ export declare function validateSignature(value: string): ValidationResult;
90
97
  * @description Used to check if a public key is valid.
91
98
  *
92
99
  * @returns
93
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
100
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
94
101
  *
95
102
  * @example
96
103
  * ```
@@ -106,7 +113,7 @@ export declare function validatePublicKey(value: string): ValidationResult;
106
113
  * @description Used to check if an operation hash is valid.
107
114
  *
108
115
  * @returns
109
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
116
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
110
117
  *
111
118
  * @example
112
119
  * ```
@@ -122,7 +129,7 @@ export declare function validateOperation(value: string): ValidationResult;
122
129
  * @description Used to check if a protocol hash is valid.
123
130
  *
124
131
  * @returns
125
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
132
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
126
133
  *
127
134
  * @example
128
135
  * ```
@@ -138,7 +145,7 @@ export declare function validateProtocol(value: string): ValidationResult;
138
145
  * @description Used to check if a block hash is valid.
139
146
  *
140
147
  * @returns
141
- * 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
148
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
142
149
  *
143
150
  * @example
144
151
  * ```
@@ -150,11 +157,16 @@ export declare function validateProtocol(value: string): ValidationResult;
150
157
  * ```
151
158
  */
152
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;
153
165
  /**
154
166
  * @description Used to check if a spending key is valid.
155
- * @returns 0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).
167
+ * @returns
168
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
156
169
  *
157
170
  */
158
- export declare function validateSpendingKey(value: any): ValidationResult;
159
- export declare function invalidDetail(validation: ValidationResult): string;
171
+ export declare function validateSpendingKey(value: string): ValidationResult;
160
172
  export declare function validateSmartRollupAddress(value: string): ValidationResult;
@@ -1,12 +1,13 @@
1
- import { Prefix } from './taquito-utils';
2
- type PkPrefix = Prefix.EDPK | Prefix.SPPK | Prefix.P2PK | Prefix.BLPK;
1
+ import { PrefixV2 } from './taquito-utils';
2
+ export declare const BLS12_381_DST = "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
3
+ export declare const POP_DST = "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
3
4
  /**
4
5
  * @description Verify signature of a payload
5
- *
6
- * @param messageBytes The forged message including the magic byte (11 for block,
7
- * 12 for preattestation, 13 for attestation, 3 for generic, 5 for the PACK format of michelson)
6
+ * @param message The forged message including the magic byte (11 for block, 12 for preattestation, 13 for attestation, 3 for generic, 5 for the PACK format of michelson) in string or Uint8Array
8
7
  * @param publicKey The public key to verify the signature against
9
8
  * @param signature The signature to verify
9
+ * @param watermark Optional if not included in the message
10
+ * @param pop Optional if verifying proof of possession signature
10
11
  * @returns A boolean indicating if the signature matches
11
12
  * @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
12
13
  * @example
@@ -19,6 +20,11 @@ type PkPrefix = Prefix.EDPK | Prefix.SPPK | Prefix.P2PK | Prefix.BLPK;
19
20
  * ```
20
21
  *
21
22
  */
22
- export declare function verifySignature(messageBytes: string, publicKey: string, signature: string, watermark?: Uint8Array): boolean;
23
+ 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
+ */
23
29
  export declare function validatePkAndExtractPrefix(publicKey: string): PkPrefix;
24
30
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/utils",
3
- "version": "23.0.0-beta.0",
3
+ "version": "23.0.0-beta.1",
4
4
  "description": "converts michelson data and types into convenient JS/TS objects",
5
5
  "keywords": [
6
6
  "tezos",
@@ -62,9 +62,10 @@
62
62
  ]
63
63
  },
64
64
  "dependencies": {
65
+ "@noble/curves": "^1.9.6",
65
66
  "@stablelib/blake2b": "^1.0.1",
66
67
  "@stablelib/ed25519": "^1.0.3",
67
- "@taquito/core": "^23.0.0-beta.0",
68
+ "@taquito/core": "^23.0.0-beta.1",
68
69
  "@types/bs58check": "^2.1.2",
69
70
  "bignumber.js": "^9.1.2",
70
71
  "blakejs": "^1.2.1",
@@ -101,5 +102,5 @@
101
102
  "ts-toolbelt": "^9.6.0",
102
103
  "typescript": "~5.5.4"
103
104
  },
104
- "gitHead": "37cc766d60407d7909fbd2d841d9dd946243d04a"
105
+ "gitHead": "1469d6f0d55134a4b853598a2eec48e6f71b3da3"
105
106
  }