@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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Taquito Utils package
2
2
  *TypeDoc style documentation is available on-line [here](https://taquito.io/typedoc/modules/_taquito_utils.html)*
3
3
 
4
- `@taquito/utils` is an npm package that provides developers with utility functionality for Taquito.
4
+ `@taquito/utils` is an npm package that provides developers with utility functionality for Taquito.
5
5
 
6
6
  ## Install
7
7
 
@@ -21,7 +21,10 @@ The `ValidationResult` returned by these functions is an enum that can take the
21
21
  0 = NO_PREFIX_MATCHED,
22
22
  1 = INVALID_CHECKSUM,
23
23
  2 = INVALID_LENGTH,
24
- 3 = VALID
24
+ 3 = VALID,
25
+ 4 = PREFIX_NOT_ALLOWED,
26
+ 5 = INVALID_ENCODING,
27
+ 6 = OTHER,
25
28
  ```
26
29
 
27
30
  **Address validation (tz1, tz2, tz3, KT1)**
@@ -186,7 +189,7 @@ console.log(encodeKeyHash('01106d79a502c4135b10e61e92f4c5a72ca740fb87'));
186
189
  **Base58 encode a public key according to its prefix**
187
190
 
188
191
  ```ts
189
- import { encodeKey } from '@taquito/utils';
192
+ import { encodeKey } from '@taquito/utils';
190
193
 
191
194
  console.log(encodeKey('0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'));
192
195
  // output: edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh
@@ -194,7 +197,7 @@ console.log(encodeKey('0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea8
194
197
 
195
198
  **Base58 encode an address using a predefined prefix**
196
199
  ```ts
197
- import { encodeAddress } from '@taquito/utils';
200
+ import { encodeAddress } from '@taquito/utils';
198
201
 
199
202
  console.log(encodeAddress('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'));
200
203
  // output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM
@@ -206,7 +209,7 @@ console.log(encodeAddress('01f9b689a478253793bd92357c5e08e5ebcd8db47600'));
206
209
  **Base58 decode a string with a predefined prefix**
207
210
 
208
211
  ```ts
209
- import { b58decode } from '@taquito/utils';
212
+ import { b58decode } from '@taquito/utils';
210
213
 
211
214
  console.log(b58decode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'));
212
215
  // output: 0000e96b9f8b19af9c7ffa0c0480e1977b295850961f
@@ -215,18 +218,18 @@ console.log(b58decode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'));
215
218
  **Base58 decode a string and remove the prefix from it**
216
219
 
217
220
  ```ts
218
- import { b58cdecode, prefix, Prefix } from '@taquito/utils';
221
+ import { b58cdecode, PrefixV2 } from '@taquito/utils';
219
222
 
220
- console.log(b58cdecode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', prefix[Prefix.TZ1]));
223
+ console.log(b58cdecode('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', PrefixV2.Ed25519PublicKeyHash));
221
224
  // output: <Buffer e9 6b 9f 8b 19 af 9c 7f fa 0c 04 80 e1 97 7b 29 58 50 96 1f>
222
225
  ```
223
226
 
224
227
  **Base58 encode a string or a Uint8Array and append a prefix to it**
225
228
 
226
229
  ```ts
227
- import { b58cencode } from '@taquito/utils';
230
+ import { b58Encode } from '@taquito/utils';
228
231
 
229
- console.log(b58cdecode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', prefix[Prefix.TZ1]));
232
+ console.log(b58Encode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', PrefixV2.Ed25519PublicKeyHash));
230
233
  // output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM
231
234
  ```
232
235
 
@@ -245,7 +248,7 @@ console.log(encodeOpHash(opBytesSigned));
245
248
  Hash a string using the BLAKE2b algorithm, base58 encode the hash obtained and append the prefix 'expr' to it.
246
249
 
247
250
  ```ts
248
- import { encodeExpr } from '@taquito/utils';
251
+ import { encodeExpr } from '@taquito/utils';
249
252
 
250
253
  console.log(encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea'));
251
254
 
@@ -255,7 +258,7 @@ console.log(encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea
255
258
  **Obtain the public key hash given a public key**
256
259
 
257
260
  ```ts
258
- import { getPkhfromPk } from '@taquito/utils';
261
+ import { getPkhfromPk } from '@taquito/utils';
259
262
 
260
263
  const publicKey = 'sppk7czKu6So3zDWjhBPBv9wgCrBAfbEFoKYzEaKUsjhNr5Ug6E4Sn1';
261
264
  console.log(getPkhfromPk(publicKey));
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prefixLength = exports.prefix = exports.Prefix = void 0;
4
2
  // ref https://gitlab.com/tezos/tezos/-/blob/master/src/lib_crypto/base58.ml
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.payloadLength = exports.prefixV2 = exports.PrefixV2 = exports.prefixLength = exports.prefix = exports.Prefix = void 0;
5
+ /**
6
+ * @deprecated use PrefixV2 instead, this enum will be removed in the next minor release
7
+ * @description base58 prefix definition enum
8
+ */
5
9
  var Prefix;
6
10
  (function (Prefix) {
7
11
  Prefix["TZ1"] = "tz1";
@@ -46,6 +50,10 @@ var Prefix;
46
50
  Prefix["SRC1"] = "src1";
47
51
  Prefix["SH"] = "sh";
48
52
  })(Prefix || (exports.Prefix = Prefix = {}));
53
+ /**
54
+ * @deprecated use prefixV2 instead this constant will be removed in the next minor release
55
+ * @description base58 prefix to bytes mapping
56
+ */
49
57
  exports.prefix = {
50
58
  [Prefix.TZ1]: new Uint8Array([6, 161, 159]),
51
59
  [Prefix.TZ2]: new Uint8Array([6, 161, 161]),
@@ -90,6 +98,10 @@ exports.prefix = {
90
98
  [Prefix.SRC1]: new Uint8Array([17, 165, 134, 138]),
91
99
  [Prefix.SH]: new Uint8Array([2, 116, 180]),
92
100
  };
101
+ /**
102
+ * @deprecated use payloadLength instead this constant will be removed in the next minor release
103
+ * @description base58 prefix to payload length mapping
104
+ */
93
105
  exports.prefixLength = {
94
106
  [Prefix.TZ1]: 20,
95
107
  [Prefix.TZ2]: 20,
@@ -117,3 +129,202 @@ exports.prefixLength = {
117
129
  [Prefix.SRC1]: 32,
118
130
  [Prefix.SH]: 48,
119
131
  };
132
+ /**
133
+ * @description base58 name to prefix mapping
134
+ */
135
+ var PrefixV2;
136
+ (function (PrefixV2) {
137
+ PrefixV2["BlockHash"] = "B";
138
+ PrefixV2["OperationHash"] = "o";
139
+ PrefixV2["OperationListHash"] = "Lo";
140
+ PrefixV2["OperationListListHash"] = "LLo";
141
+ PrefixV2["ProtocolHash"] = "P";
142
+ PrefixV2["ContextHash"] = "Co";
143
+ PrefixV2["BlockMetadataHash"] = "bm";
144
+ PrefixV2["OperationMetadataHash"] = "r";
145
+ PrefixV2["OperationMetadataListHash"] = "Lr";
146
+ PrefixV2["OperationMetadataListListHash"] = "LLr";
147
+ PrefixV2["Ed25519PublicKeyHash"] = "tz1";
148
+ PrefixV2["Secp256k1PublicKeyHash"] = "tz2";
149
+ PrefixV2["P256PublicKeyHash"] = "tz3";
150
+ PrefixV2["ContractHash"] = "KT1";
151
+ PrefixV2["BlindedPublicKeyHash"] = "btz1";
152
+ PrefixV2["BLS12_381PublicKeyHash"] = "tz4";
153
+ PrefixV2["TXRollupAddress"] = "txr1";
154
+ PrefixV2["ZkRollupHash"] = "epx1";
155
+ PrefixV2["ScRollupHash"] = "scr1";
156
+ PrefixV2["SmartRollupHash"] = "sr1";
157
+ PrefixV2["CryptoboxPublicKeyHash"] = "id";
158
+ PrefixV2["Ed25519Seed"] = "edsk";
159
+ PrefixV2["Ed25519PublicKey"] = "edpk";
160
+ PrefixV2["Secp256k1SecretKey"] = "spsk";
161
+ PrefixV2["P256SecretKey"] = "p2sk";
162
+ PrefixV2["BLS12_381SecretKey"] = "BLsk";
163
+ PrefixV2["ValueHash"] = "vh";
164
+ PrefixV2["CycleNonce"] = "nce";
165
+ PrefixV2["ScriptExpr"] = "expr";
166
+ PrefixV2["InboxHash"] = "txi";
167
+ PrefixV2["MessageHash"] = "txm";
168
+ PrefixV2["CommitmentHash"] = "txc";
169
+ PrefixV2["MessageResultHash"] = "txmr";
170
+ PrefixV2["MessageResultListHash"] = "txM";
171
+ PrefixV2["WithdrawListHash"] = "txw";
172
+ PrefixV2["ScRollupStateHash"] = "scs1";
173
+ PrefixV2["ScRollupCommitmentHash"] = "scc1";
174
+ PrefixV2["SmartRollupStateHash"] = "srs1";
175
+ PrefixV2["SmartRollupCommitmentHash"] = "src1";
176
+ PrefixV2["Ed25519EncryptedSeed"] = "edesk";
177
+ PrefixV2["Secp256k1EncryptedSecretKey"] = "spesk";
178
+ PrefixV2["P256EncryptedSecretKey"] = "p2esk";
179
+ PrefixV2["BLS12_381EncryptedSecretKey"] = "BLesk";
180
+ PrefixV2["Secp256k1EncryptedScalar"] = "seesk";
181
+ PrefixV2["Secp256k1PublicKey"] = "sppk";
182
+ PrefixV2["P256PublicKey"] = "p2pk";
183
+ PrefixV2["Secp256k1Scalar"] = "SSp";
184
+ PrefixV2["Secp256k1Element"] = "GSp";
185
+ PrefixV2["Ed25519SecretKey"] = "_edsk";
186
+ PrefixV2["Ed25519Signature"] = "edsig";
187
+ PrefixV2["Secp256k1Signature"] = "spsig1";
188
+ PrefixV2["P256Signature"] = "p2sig";
189
+ PrefixV2["GenericSignature"] = "sig";
190
+ PrefixV2["ChainID"] = "Net";
191
+ PrefixV2["SaplingSpendingKey"] = "sask";
192
+ PrefixV2["EncryptedSaplingSpendingKey"] = "_sask";
193
+ PrefixV2["SaplingAddress"] = "zet1";
194
+ PrefixV2["GenericAggregateSignature"] = "asig";
195
+ PrefixV2["BLS12_381Signature"] = "BLsig";
196
+ PrefixV2["BLS12_381PublicKey"] = "BLpk";
197
+ PrefixV2["SlotHeader"] = "sh";
198
+ })(PrefixV2 || (exports.PrefixV2 = PrefixV2 = {}));
199
+ /**
200
+ * @description base58 prefix to bytes mapping
201
+ */
202
+ exports.prefixV2 = {
203
+ [PrefixV2.BlockHash]: new Uint8Array([1, 52]),
204
+ [PrefixV2.OperationHash]: new Uint8Array([5, 116]),
205
+ [PrefixV2.OperationListHash]: new Uint8Array([133, 233]),
206
+ [PrefixV2.OperationListListHash]: new Uint8Array([29, 159, 109]),
207
+ [PrefixV2.ProtocolHash]: new Uint8Array([2, 170]),
208
+ [PrefixV2.ContextHash]: new Uint8Array([79, 199]),
209
+ [PrefixV2.BlockMetadataHash]: new Uint8Array([234, 249]),
210
+ [PrefixV2.OperationMetadataHash]: new Uint8Array([5, 183]),
211
+ [PrefixV2.OperationMetadataListHash]: new Uint8Array([134, 39]),
212
+ [PrefixV2.OperationMetadataListListHash]: new Uint8Array([29, 159, 182]),
213
+ [PrefixV2.Ed25519PublicKeyHash]: new Uint8Array([6, 161, 159]),
214
+ [PrefixV2.Secp256k1PublicKeyHash]: new Uint8Array([6, 161, 161]),
215
+ [PrefixV2.P256PublicKeyHash]: new Uint8Array([6, 161, 164]),
216
+ [PrefixV2.ContractHash]: new Uint8Array([2, 90, 121]),
217
+ [PrefixV2.BlindedPublicKeyHash]: new Uint8Array([1, 2, 49, 223]),
218
+ [PrefixV2.BLS12_381PublicKeyHash]: new Uint8Array([6, 161, 166]),
219
+ [PrefixV2.TXRollupAddress]: new Uint8Array([1, 128, 120, 31]),
220
+ [PrefixV2.ZkRollupHash]: new Uint8Array([1, 23, 224, 125]),
221
+ [PrefixV2.ScRollupHash]: new Uint8Array([1, 118, 132, 217]),
222
+ [PrefixV2.SmartRollupHash]: new Uint8Array([6, 124, 117]),
223
+ [PrefixV2.CryptoboxPublicKeyHash]: new Uint8Array([153, 103]),
224
+ [PrefixV2.Ed25519Seed]: new Uint8Array([13, 15, 58, 7]),
225
+ [PrefixV2.Ed25519PublicKey]: new Uint8Array([13, 15, 37, 217]),
226
+ [PrefixV2.Secp256k1SecretKey]: new Uint8Array([17, 162, 224, 201]),
227
+ [PrefixV2.P256SecretKey]: new Uint8Array([16, 81, 238, 189]),
228
+ [PrefixV2.BLS12_381SecretKey]: new Uint8Array([3, 150, 192, 40]),
229
+ [PrefixV2.ValueHash]: new Uint8Array([1, 106, 242]),
230
+ [PrefixV2.CycleNonce]: new Uint8Array([69, 220, 169]),
231
+ [PrefixV2.ScriptExpr]: new Uint8Array([13, 44, 64, 27]),
232
+ [PrefixV2.InboxHash]: new Uint8Array([79, 148, 196]),
233
+ [PrefixV2.MessageHash]: new Uint8Array([79, 149, 30]),
234
+ [PrefixV2.CommitmentHash]: new Uint8Array([79, 148, 17]),
235
+ [PrefixV2.MessageResultHash]: new Uint8Array([18, 7, 206, 87]),
236
+ [PrefixV2.MessageResultListHash]: new Uint8Array([79, 146, 82]),
237
+ [PrefixV2.WithdrawListHash]: new Uint8Array([79, 150, 72]),
238
+ [PrefixV2.ScRollupStateHash]: new Uint8Array([17, 144, 122, 202]),
239
+ [PrefixV2.ScRollupCommitmentHash]: new Uint8Array([17, 144, 21, 100]),
240
+ [PrefixV2.SmartRollupStateHash]: new Uint8Array([17, 165, 235, 240]),
241
+ [PrefixV2.SmartRollupCommitmentHash]: new Uint8Array([17, 165, 134, 138]),
242
+ [PrefixV2.Ed25519EncryptedSeed]: new Uint8Array([7, 90, 60, 179, 41]),
243
+ [PrefixV2.Secp256k1EncryptedSecretKey]: new Uint8Array([9, 237, 241, 174, 150]),
244
+ [PrefixV2.P256EncryptedSecretKey]: new Uint8Array([9, 48, 57, 115, 171]),
245
+ [PrefixV2.BLS12_381EncryptedSecretKey]: new Uint8Array([2, 5, 30, 53, 25]),
246
+ [PrefixV2.Secp256k1EncryptedScalar]: new Uint8Array([1, 131, 36, 86, 248]),
247
+ [PrefixV2.Secp256k1PublicKey]: new Uint8Array([3, 254, 226, 86]),
248
+ [PrefixV2.P256PublicKey]: new Uint8Array([3, 178, 139, 127]),
249
+ [PrefixV2.Secp256k1Scalar]: new Uint8Array([38, 248, 136]),
250
+ [PrefixV2.Secp256k1Element]: new Uint8Array([5, 92, 0]),
251
+ [PrefixV2.Ed25519SecretKey]: new Uint8Array([43, 246, 78, 7]),
252
+ [PrefixV2.Ed25519Signature]: new Uint8Array([9, 245, 205, 134, 18]),
253
+ [PrefixV2.Secp256k1Signature]: new Uint8Array([13, 115, 101, 19, 63]),
254
+ [PrefixV2.P256Signature]: new Uint8Array([54, 240, 44, 52]),
255
+ [PrefixV2.GenericSignature]: new Uint8Array([4, 130, 43]),
256
+ [PrefixV2.ChainID]: new Uint8Array([87, 82, 0]),
257
+ [PrefixV2.SaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
258
+ [PrefixV2.EncryptedSaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
259
+ [PrefixV2.SaplingAddress]: new Uint8Array([18, 71, 40, 223]),
260
+ [PrefixV2.GenericAggregateSignature]: new Uint8Array([2, 75, 234, 101]),
261
+ [PrefixV2.BLS12_381Signature]: new Uint8Array([40, 171, 64, 207]),
262
+ [PrefixV2.BLS12_381PublicKey]: new Uint8Array([6, 149, 135, 204]),
263
+ [PrefixV2.SlotHeader]: new Uint8Array([2, 116, 180]),
264
+ };
265
+ /**
266
+ * @description base58 prefix to payload length mapping
267
+ */
268
+ exports.payloadLength = {
269
+ [PrefixV2.BlockHash]: 32,
270
+ [PrefixV2.OperationHash]: 32,
271
+ [PrefixV2.OperationListHash]: 32,
272
+ [PrefixV2.OperationListListHash]: 32,
273
+ [PrefixV2.ProtocolHash]: 32,
274
+ [PrefixV2.ContextHash]: 32,
275
+ [PrefixV2.BlockMetadataHash]: 32,
276
+ [PrefixV2.OperationMetadataHash]: 32,
277
+ [PrefixV2.OperationMetadataListHash]: 32,
278
+ [PrefixV2.OperationMetadataListListHash]: 32,
279
+ [PrefixV2.Ed25519PublicKeyHash]: 20,
280
+ [PrefixV2.Secp256k1PublicKeyHash]: 20,
281
+ [PrefixV2.P256PublicKeyHash]: 20,
282
+ [PrefixV2.ContractHash]: 20,
283
+ [PrefixV2.BlindedPublicKeyHash]: 20,
284
+ [PrefixV2.BLS12_381PublicKeyHash]: 20,
285
+ [PrefixV2.TXRollupAddress]: 20,
286
+ [PrefixV2.ZkRollupHash]: 20,
287
+ [PrefixV2.ScRollupHash]: 20,
288
+ [PrefixV2.SmartRollupHash]: 20,
289
+ [PrefixV2.CryptoboxPublicKeyHash]: 16,
290
+ [PrefixV2.Ed25519Seed]: 32,
291
+ [PrefixV2.Ed25519PublicKey]: 32,
292
+ [PrefixV2.Secp256k1SecretKey]: 32,
293
+ [PrefixV2.P256SecretKey]: 32,
294
+ [PrefixV2.BLS12_381SecretKey]: 32,
295
+ [PrefixV2.ValueHash]: 32,
296
+ [PrefixV2.CycleNonce]: 32,
297
+ [PrefixV2.ScriptExpr]: 32,
298
+ [PrefixV2.InboxHash]: 32,
299
+ [PrefixV2.MessageHash]: 32,
300
+ [PrefixV2.CommitmentHash]: 32,
301
+ [PrefixV2.MessageResultHash]: 32,
302
+ [PrefixV2.MessageResultListHash]: 32,
303
+ [PrefixV2.WithdrawListHash]: 32,
304
+ [PrefixV2.ScRollupStateHash]: 32,
305
+ [PrefixV2.ScRollupCommitmentHash]: 32,
306
+ [PrefixV2.SmartRollupStateHash]: 32,
307
+ [PrefixV2.SmartRollupCommitmentHash]: 32,
308
+ [PrefixV2.Ed25519EncryptedSeed]: 56,
309
+ [PrefixV2.Secp256k1EncryptedSecretKey]: 56,
310
+ [PrefixV2.P256EncryptedSecretKey]: 56,
311
+ [PrefixV2.BLS12_381EncryptedSecretKey]: 56,
312
+ [PrefixV2.Secp256k1EncryptedScalar]: 60,
313
+ [PrefixV2.Secp256k1PublicKey]: 33,
314
+ [PrefixV2.P256PublicKey]: 33,
315
+ [PrefixV2.Secp256k1Scalar]: 33,
316
+ [PrefixV2.Secp256k1Element]: 33,
317
+ [PrefixV2.Ed25519SecretKey]: 64,
318
+ [PrefixV2.Ed25519Signature]: 64,
319
+ [PrefixV2.Secp256k1Signature]: 64,
320
+ [PrefixV2.P256Signature]: 64,
321
+ [PrefixV2.GenericSignature]: 64,
322
+ [PrefixV2.ChainID]: 4,
323
+ [PrefixV2.SaplingSpendingKey]: 169,
324
+ [PrefixV2.EncryptedSaplingSpendingKey]: 193,
325
+ [PrefixV2.SaplingAddress]: 43,
326
+ [PrefixV2.GenericAggregateSignature]: 96,
327
+ [PrefixV2.BLS12_381Signature]: 96,
328
+ [PrefixV2.BLS12_381PublicKey]: 48,
329
+ [PrefixV2.SlotHeader]: 48,
330
+ };
@@ -23,13 +23,10 @@ Object.defineProperty(exports, "ProhibitedActionError", { enumerable: true, get:
23
23
  */
24
24
  class InvalidProtocolHashError extends core_1.ParameterValidationError {
25
25
  constructor(protocolHash, errorDetails) {
26
- super();
26
+ super(`The protocol hash '${protocolHash}' is invalid`, errorDetails);
27
27
  this.protocolHash = protocolHash;
28
- this.errorDetails = errorDetails;
29
28
  this.name = 'InvalidProtocolHashError';
30
- this.name = 'InvalidProtocolHashError';
31
- this.message = `The protocol hash '${protocolHash}' is invalid`;
32
- errorDetails ? (this.message += `: ${errorDetails}`) : null;
29
+ this.name = this.constructor.name;
33
30
  }
34
31
  }
35
32
  exports.InvalidProtocolHashError = InvalidProtocolHashError;
@@ -39,11 +36,10 @@ exports.InvalidProtocolHashError = InvalidProtocolHashError;
39
36
  */
40
37
  class ValueConversionError extends core_1.UnsupportedActionError {
41
38
  constructor(value, desiredType) {
42
- super();
39
+ super(`Unable to convert ${value} to a ${desiredType}`);
43
40
  this.value = value;
44
41
  this.desiredType = desiredType;
45
- this.name = 'ValueConversionError';
46
- this.message = `Unable to convert ${value} to a ${desiredType}`;
42
+ this.name = this.constructor.name;
47
43
  }
48
44
  }
49
45
  exports.ValueConversionError = ValueConversionError;