@taquito/utils 16.1.2 → 16.2.0-beta-RC.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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/ed25519'), require('@stablelib/blake2b'), require('blakejs'), require('bs58check'), require('bignumber.js'), require('elliptic'), require('typedarray-to-buffer')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/ed25519', '@stablelib/blake2b', 'blakejs', 'bs58check', 'bignumber.js', 'elliptic', 'typedarray-to-buffer'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.ed25519, global.blake2b, global.blake, global.bs58check, global.BigNumber, global.elliptic, global.toBuffer));
5
- })(this, (function (exports, buffer, ed25519, blake2b, blake, bs58check, BigNumber, elliptic, toBuffer) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/ed25519'), require('@stablelib/blake2b'), require('blakejs'), require('bs58check'), require('@taquito/core'), require('bignumber.js'), require('elliptic'), require('typedarray-to-buffer')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/ed25519', '@stablelib/blake2b', 'blakejs', 'bs58check', '@taquito/core', 'bignumber.js', 'elliptic', 'typedarray-to-buffer'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.ed25519, global.blake2b, global.blake, global.bs58check, global.core, global.BigNumber, global.elliptic, global.toBuffer));
5
+ })(this, (function (exports, buffer, ed25519, blake2b, blake, bs58check, core, BigNumber, elliptic, toBuffer) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -141,194 +141,6 @@
141
141
  [exports.Prefix.SRC1]: 32,
142
142
  };
143
143
 
144
- /**
145
- * @category Error
146
- * @description Error that indicates an invalid key being passed or used
147
- */
148
- class InvalidKeyError extends Error {
149
- constructor(key, errorDetail) {
150
- super();
151
- this.key = key;
152
- this.errorDetail = errorDetail;
153
- this.name = 'InvalidKeyError';
154
- const baseMessage = `The key ${key} is invalid.`;
155
- this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
156
- }
157
- }
158
- /**
159
- * @category Error
160
- * @description Error that indicates an Invalid Public Key being passed or used
161
- */
162
- class InvalidPublicKeyError extends Error {
163
- constructor(publicKey, errorDetail) {
164
- super();
165
- this.publicKey = publicKey;
166
- this.name = 'InvalidPublicKeyError';
167
- const baseMessage = `The public key '${publicKey}' is invalid.`;
168
- this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
169
- }
170
- }
171
- /**
172
- * @category Error
173
- * @description Error that indicates an invalid signature being passed or used
174
- */
175
- class InvalidSignatureError extends Error {
176
- constructor(signature, errorDetail) {
177
- super();
178
- this.signature = signature;
179
- this.name = 'InvalidSignatureError';
180
- const baseMessage = `The signature '${signature}' is invalid.`;
181
- this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
182
- }
183
- }
184
- /**
185
- * @category Error
186
- * @description Error that indicates an invalid message being passed or used
187
- */
188
- class InvalidMessageError extends Error {
189
- constructor(msg, errorDetail) {
190
- super();
191
- this.msg = msg;
192
- this.errorDetail = errorDetail;
193
- this.name = 'InvalidMessageError';
194
- const baseMessage = `The message '${msg}' is invalid.`;
195
- this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
196
- }
197
- }
198
- /**
199
- * @category Error
200
- * @description Error that indicates an invalid contract address being passed or used
201
- */
202
- class InvalidContractAddressError extends Error {
203
- constructor(contractAddress) {
204
- super(`The contract address '${contractAddress}' is invalid`);
205
- this.contractAddress = contractAddress;
206
- this.name = 'InvalidContractAddressError';
207
- }
208
- }
209
- /**
210
- * @category Error
211
- * @description Error that indicates an invalid address being passed or used (both contract and implicit)
212
- */
213
- class InvalidAddressError extends Error {
214
- constructor(address, errorDetail) {
215
- super();
216
- this.address = address;
217
- this.name = 'InvalidAddressError';
218
- const baseMessage = `The address '${address}' is invalid.`;
219
- this.message = errorDetail ? `${baseMessage} ${errorDetail}` : baseMessage;
220
- }
221
- }
222
- /**
223
- * @category Error
224
- * @description Error that indicates an invalid chain id being passed or used
225
- */
226
- class InvalidChainIdError extends Error {
227
- constructor(chainId) {
228
- super(`The chain id '${chainId}' is invalid`);
229
- this.chainId = chainId;
230
- this.name = 'InvalidChainIdError';
231
- }
232
- }
233
- /**
234
- * @category Error
235
- * @description Error that indicates an invalid key hash being passed or used
236
- */
237
- class InvalidKeyHashError extends Error {
238
- constructor(keyHash) {
239
- super(`The public key hash '${keyHash}' is invalid`);
240
- this.keyHash = keyHash;
241
- this.name = 'InvalidKeyHashError';
242
- }
243
- }
244
- /**
245
- * @category Error
246
- * @description Error that indicates an invalid block hash being passed or used
247
- */ class InvalidBlockHashError extends Error {
248
- constructor(blockHash) {
249
- super(`The block hash '${blockHash}' is invalid`);
250
- this.blockHash = blockHash;
251
- this.name = 'InvalidBlockHashError';
252
- }
253
- }
254
- /**
255
- * @category Error
256
- * @description Error that indicates invalid protocol hash being passed or used
257
- */
258
- class InvalidProtocolHashError extends Error {
259
- constructor(protocolHash) {
260
- super(`The protocol hash '${protocolHash}' is invalid`);
261
- this.protocolHash = protocolHash;
262
- this.name = 'InvalidProtocolHashError';
263
- }
264
- }
265
- /**
266
- * @category Error
267
- * @description Error that indicates an invalid operation hash being passed or used
268
- */ class InvalidOperationHashError extends Error {
269
- constructor(operationHash) {
270
- super(`The operation hash '${operationHash}' is invalid`);
271
- this.operationHash = operationHash;
272
- this.name = 'InvalidOperationHashError';
273
- }
274
- }
275
- /**
276
- * @category Error
277
- * @description Error that indicates an invalid operation kind being passed or used
278
- */
279
- class InvalidOperationKindError extends Error {
280
- constructor(operationKind) {
281
- super(`The operation kind '${operationKind}' is unsupported`);
282
- this.operationKind = operationKind;
283
- this.name = 'InvalidOperationKindError';
284
- }
285
- }
286
- /**
287
- * @category Error
288
- * @description General error that indicates something is no longer supported and/or deprecated
289
- */
290
- class DeprecationError extends Error {
291
- constructor(message) {
292
- super(message);
293
- this.message = message;
294
- this.name = 'DeprecationError';
295
- }
296
- }
297
- /**
298
- * @category Error
299
- * @description General error that indicates an action is prohibited or not allowed
300
- */
301
- class ProhibitedActionError extends Error {
302
- constructor(message) {
303
- super(message);
304
- this.message = message;
305
- this.name = 'ProhibitedActionError';
306
- }
307
- }
308
- /**
309
- * @category Error
310
- * @description General error that indicates a failure when trying to convert data from one type to another
311
- */
312
- class ValueConversionError extends Error {
313
- constructor(value, desiredType) {
314
- super(`Unable to convert ${value} to a ${desiredType}`);
315
- this.value = value;
316
- this.desiredType = desiredType;
317
- this.name = 'ValueConversionError';
318
- }
319
- }
320
- /**
321
- * @category Error
322
- * @description Error that indicates an invalid hex string being passed or used
323
- */
324
- class InvalidHexStringError extends Error {
325
- constructor(message) {
326
- super(message);
327
- this.message = message;
328
- this.name = 'InvalidHexStringError';
329
- }
330
- }
331
-
332
144
  /**
333
145
  * @description Verify signature of a payload
334
146
  *
@@ -337,7 +149,7 @@
337
149
  * @param publicKey The public key to verify the signature against
338
150
  * @param signature The signature to verify
339
151
  * @returns A boolean indicating if the signature matches
340
- *
152
+ * @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
341
153
  * @example
342
154
  * ```
343
155
  * const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
@@ -369,44 +181,28 @@
369
181
  }
370
182
  function validateMessageNotEmpty(message) {
371
183
  if (message === '') {
372
- throw new InvalidMessageError(message, 'The message provided for verifying signature cannot be empty.');
184
+ throw new core.InvalidMessageError(message, ': Cannot be empty.');
373
185
  }
374
186
  return message;
375
187
  }
376
188
  function validatePkAndExtractPrefix(publicKey) {
377
189
  if (publicKey === '') {
378
- throw new InvalidPublicKeyError(publicKey, 'Public key cannot be empty');
190
+ throw new core.InvalidPublicKeyError(publicKey, ': Can not be empty');
379
191
  }
380
192
  const pkPrefix = publicKey.substring(0, 4);
381
- const validation = validatePublicKey(publicKey);
382
- if (validation !== exports.ValidationResult.VALID) {
383
- if (validation === exports.ValidationResult.INVALID_CHECKSUM) {
384
- throw new InvalidPublicKeyError(publicKey, 'The public key provided has an invalid checksum');
385
- }
386
- else if (validation === exports.ValidationResult.INVALID_LENGTH) {
387
- throw new InvalidPublicKeyError(publicKey, 'The public key provided has an invalid length');
388
- }
389
- else if (validation === exports.ValidationResult.NO_PREFIX_MATCHED) {
390
- throw new InvalidPublicKeyError(publicKey, `The public key provided has an unsupported prefix: ${pkPrefix}`);
391
- }
193
+ const publicKeyValidation = validatePublicKey(publicKey);
194
+ if (publicKeyValidation !== exports.ValidationResult.VALID) {
195
+ throw new core.InvalidPublicKeyError(publicKey, invalidErrorDetail(publicKeyValidation));
392
196
  }
393
197
  return pkPrefix;
394
198
  }
395
199
  function validateSigAndExtractPrefix(signature) {
396
200
  const signaturePrefix = signature.startsWith('sig')
397
- ? signature.substr(0, 3)
398
- : signature.substr(0, 5);
201
+ ? signature.substring(0, 3)
202
+ : signature.substring(0, 5);
399
203
  const validation = validateSignature(signature);
400
204
  if (validation !== exports.ValidationResult.VALID) {
401
- if (validation === exports.ValidationResult.INVALID_CHECKSUM) {
402
- throw new InvalidSignatureError(signature, `invalid checksum`);
403
- }
404
- else if (validation === exports.ValidationResult.INVALID_LENGTH) {
405
- throw new InvalidSignatureError(signature, 'invalid length');
406
- }
407
- else if (validation === exports.ValidationResult.NO_PREFIX_MATCHED) {
408
- throw new InvalidSignatureError(signaturePrefix, 'unsupported prefix');
409
- }
205
+ throw new core.InvalidSignatureError(signature, invalidErrorDetail(validation));
410
206
  }
411
207
  return signaturePrefix;
412
208
  }
@@ -441,6 +237,34 @@
441
237
  return false;
442
238
  }
443
239
 
240
+ /**
241
+ * @category Error
242
+ * @description Error indicates invalid protocol hash being passed or used
243
+ */
244
+ class InvalidProtocolHashError extends core.ParameterValidationError {
245
+ constructor(protocolHash, errorDetails) {
246
+ super();
247
+ this.protocolHash = protocolHash;
248
+ this.name = 'InvalidProtocolHashError';
249
+ this.name = 'InvalidProtocolHashError';
250
+ this.message = `The protocol hash '${protocolHash}' is invalid`;
251
+ errorDetails ? (this.message += `: ${errorDetails}`) : null;
252
+ }
253
+ }
254
+ /**
255
+ * @category Error
256
+ * @description Error indicates unable to convert data type from one to another
257
+ */
258
+ class ValueConversionError extends core.UnsupportedActionError {
259
+ constructor(value, desiredType) {
260
+ super();
261
+ this.value = value;
262
+ this.desiredType = desiredType;
263
+ this.name = 'ValueConversionError';
264
+ this.message = `Unable to convert ${value} to a ${desiredType}`;
265
+ }
266
+ }
267
+
444
268
  exports.ValidationResult = void 0;
445
269
  (function (ValidationResult) {
446
270
  ValidationResult[ValidationResult["NO_PREFIX_MATCHED"] = 0] = "NO_PREFIX_MATCHED";
@@ -499,6 +323,7 @@
499
323
  const operationPrefix = [exports.Prefix.O];
500
324
  const protocolPrefix = [exports.Prefix.P];
501
325
  const blockPrefix = [exports.Prefix.B];
326
+ const smartRollupPrefix = [exports.Prefix.SR1];
502
327
  /**
503
328
  * @description Used to check if an address or a contract address is valid.
504
329
  *
@@ -515,7 +340,11 @@
515
340
  * ```
516
341
  */
517
342
  function validateAddress(value) {
518
- return validatePrefixedValue(value, [...implicitPrefix, ...contractPrefix]);
343
+ return validatePrefixedValue(value, [
344
+ ...implicitPrefix,
345
+ ...contractPrefix,
346
+ ...smartRollupPrefix,
347
+ ]);
519
348
  }
520
349
  /**
521
350
  * @description Used to check if a chain id is valid.
@@ -668,12 +497,27 @@
668
497
  */
669
498
  function validateSpendingKey(value) {
670
499
  return validatePrefixedValue(value, [exports.Prefix.SASK]);
500
+ }
501
+ function invalidErrorDetail(validation) {
502
+ switch (validation) {
503
+ case exports.ValidationResult.NO_PREFIX_MATCHED:
504
+ return ': Invalid prefix';
505
+ case exports.ValidationResult.INVALID_CHECKSUM:
506
+ return ': Checksum failed';
507
+ case exports.ValidationResult.INVALID_LENGTH:
508
+ return ': Invalid length';
509
+ default:
510
+ return '';
511
+ }
512
+ }
513
+ function validateSmartRollupAddress(value) {
514
+ return validatePrefixedValue(value, [...smartRollupPrefix]);
671
515
  }
672
516
 
673
517
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
674
518
  const VERSION = {
675
- "commitHash": "bcc2118ddfafc1995fd125cd74d198fda042bf48",
676
- "version": "16.1.2"
519
+ "commitHash": "babcbaf464fd3571a3b88cf7023fefe87809d86d",
520
+ "version": "16.2.0-beta-RC.0"
677
521
  };
678
522
 
679
523
  const TZ_DECIMALS = 6;
@@ -854,6 +698,7 @@
854
698
  * @description Convert an hex string to a Uint8Array
855
699
  *
856
700
  * @param hex Hex string to convert
701
+ * @throws {@link ValueConversionError}
857
702
  */
858
703
  const hex2buf = (hex) => {
859
704
  const match = hex.match(/[\da-f]{2}/gi);
@@ -1008,7 +853,7 @@
1008
853
  */
1009
854
  function hex2Bytes(hex) {
1010
855
  if (!hex.match(/[\da-f]{2}/gi)) {
1011
- throw new InvalidHexStringError(`The hex string ${hex} does not have an even number of characters`);
856
+ throw new core.InvalidHexStringError(hex, `: Expecting even number of characters`);
1012
857
  }
1013
858
  return buffer.Buffer.from(hex, 'hex');
1014
859
  }
@@ -1065,21 +910,63 @@
1065
910
  return hex.startsWith('0x') ? hex.slice(2) : hex;
1066
911
  }
1067
912
 
1068
- exports.DeprecationError = DeprecationError;
1069
- exports.InvalidAddressError = InvalidAddressError;
1070
- exports.InvalidBlockHashError = InvalidBlockHashError;
1071
- exports.InvalidChainIdError = InvalidChainIdError;
1072
- exports.InvalidContractAddressError = InvalidContractAddressError;
1073
- exports.InvalidHexStringError = InvalidHexStringError;
1074
- exports.InvalidKeyError = InvalidKeyError;
1075
- exports.InvalidKeyHashError = InvalidKeyHashError;
1076
- exports.InvalidMessageError = InvalidMessageError;
1077
- exports.InvalidOperationHashError = InvalidOperationHashError;
1078
- exports.InvalidOperationKindError = InvalidOperationKindError;
913
+ Object.defineProperty(exports, 'DeprecationError', {
914
+ enumerable: true,
915
+ get: function () { return core.DeprecationError; }
916
+ });
917
+ Object.defineProperty(exports, 'InvalidAddressError', {
918
+ enumerable: true,
919
+ get: function () { return core.InvalidAddressError; }
920
+ });
921
+ Object.defineProperty(exports, 'InvalidBlockHashError', {
922
+ enumerable: true,
923
+ get: function () { return core.InvalidBlockHashError; }
924
+ });
925
+ Object.defineProperty(exports, 'InvalidChainIdError', {
926
+ enumerable: true,
927
+ get: function () { return core.InvalidChainIdError; }
928
+ });
929
+ Object.defineProperty(exports, 'InvalidContractAddressError', {
930
+ enumerable: true,
931
+ get: function () { return core.InvalidContractAddressError; }
932
+ });
933
+ Object.defineProperty(exports, 'InvalidHexStringError', {
934
+ enumerable: true,
935
+ get: function () { return core.InvalidHexStringError; }
936
+ });
937
+ Object.defineProperty(exports, 'InvalidKeyError', {
938
+ enumerable: true,
939
+ get: function () { return core.InvalidKeyError; }
940
+ });
941
+ Object.defineProperty(exports, 'InvalidKeyHashError', {
942
+ enumerable: true,
943
+ get: function () { return core.InvalidKeyHashError; }
944
+ });
945
+ Object.defineProperty(exports, 'InvalidMessageError', {
946
+ enumerable: true,
947
+ get: function () { return core.InvalidMessageError; }
948
+ });
949
+ Object.defineProperty(exports, 'InvalidOperationHashError', {
950
+ enumerable: true,
951
+ get: function () { return core.InvalidOperationHashError; }
952
+ });
953
+ Object.defineProperty(exports, 'InvalidOperationKindError', {
954
+ enumerable: true,
955
+ get: function () { return core.InvalidOperationKindError; }
956
+ });
957
+ Object.defineProperty(exports, 'InvalidPublicKeyError', {
958
+ enumerable: true,
959
+ get: function () { return core.InvalidPublicKeyError; }
960
+ });
961
+ Object.defineProperty(exports, 'InvalidSignatureError', {
962
+ enumerable: true,
963
+ get: function () { return core.InvalidSignatureError; }
964
+ });
965
+ Object.defineProperty(exports, 'ProhibitedActionError', {
966
+ enumerable: true,
967
+ get: function () { return core.ProhibitedActionError; }
968
+ });
1079
969
  exports.InvalidProtocolHashError = InvalidProtocolHashError;
1080
- exports.InvalidPublicKeyError = InvalidPublicKeyError;
1081
- exports.InvalidSignatureError = InvalidSignatureError;
1082
- exports.ProhibitedActionError = ProhibitedActionError;
1083
970
  exports.VERSION = VERSION;
1084
971
  exports.ValueConversionError = ValueConversionError;
1085
972
  exports.b58cdecode = b58cdecode;
@@ -1099,6 +986,7 @@
1099
986
  exports.getPkhfromPk = getPkhfromPk;
1100
987
  exports.hex2Bytes = hex2Bytes;
1101
988
  exports.hex2buf = hex2buf;
989
+ exports.invalidErrorDetail = invalidErrorDetail;
1102
990
  exports.isValidPrefix = isValidPrefix;
1103
991
  exports.mergebuf = mergebuf;
1104
992
  exports.mic2arr = mic2arr;
@@ -1117,6 +1005,7 @@
1117
1005
  exports.validateProtocol = validateProtocol;
1118
1006
  exports.validatePublicKey = validatePublicKey;
1119
1007
  exports.validateSignature = validateSignature;
1008
+ exports.validateSmartRollupAddress = validateSmartRollupAddress;
1120
1009
  exports.validateSpendingKey = validateSpendingKey;
1121
1010
  exports.verifySignature = verifySignature;
1122
1011