@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.
@@ -11,11 +11,10 @@ exports.validatePublicKey = validatePublicKey;
11
11
  exports.validateOperation = validateOperation;
12
12
  exports.validateProtocol = validateProtocol;
13
13
  exports.validateBlock = validateBlock;
14
- exports.invalidDetail = invalidDetail;
15
14
  exports.validateSpendingKey = validateSpendingKey;
16
15
  exports.validateSmartRollupAddress = validateSmartRollupAddress;
17
16
  const constants_1 = require("./constants");
18
- const taquito_utils_1 = require("./taquito-utils");
17
+ const encoding_1 = require("./encoding");
19
18
  const core_1 = require("@taquito/core");
20
19
  var core_2 = require("@taquito/core");
21
20
  Object.defineProperty(exports, "ValidationResult", { enumerable: true, get: function () { return core_2.ValidationResult; } });
@@ -31,7 +30,7 @@ Object.defineProperty(exports, "ValidationResult", { enumerable: true, get: func
31
30
  * ```
32
31
  */
33
32
  function isValidPrefixedValue(value, prefixes) {
34
- return validatePrefixedValue(value, prefixes) === taquito_utils_1.ValidationResult.VALID;
33
+ return validatePrefixedValue(value, prefixes) === core_1.ValidationResult.VALID;
35
34
  }
36
35
  /**
37
36
  * @description This function is called by the validation functions ([[validateAddress]], [[validateChain]], [[validateContractAddress]], [[validateKeyHash]], [[validateSignature]], [[validatePublicKey]]).
@@ -50,15 +49,15 @@ function isValidPrefixedValue(value, prefixes) {
50
49
  */
51
50
  function validatePrefixedValue(value, prefixes) {
52
51
  try {
53
- (0, taquito_utils_1.b58DecodeAndCheckPrefix)(value, prefixes);
52
+ (0, encoding_1.b58DecodeAndCheckPrefix)(value, prefixes);
54
53
  }
55
54
  catch (err) {
56
55
  if (err instanceof core_1.ParameterValidationError && err.result !== undefined) {
57
56
  return err.result;
58
57
  }
59
- return taquito_utils_1.ValidationResult.OTHER;
58
+ return core_1.ValidationResult.OTHER;
60
59
  }
61
- return taquito_utils_1.ValidationResult.VALID;
60
+ return core_1.ValidationResult.VALID;
62
61
  }
63
62
  /**
64
63
  * @description Used to check if an address or a contract address is valid.
@@ -76,8 +75,8 @@ function validatePrefixedValue(value, prefixes) {
76
75
  * ```
77
76
  */
78
77
  function validateAddress(value) {
79
- const [addr] = (0, taquito_utils_1.splitAddress)(value !== null && value !== void 0 ? value : '');
80
- return validatePrefixedValue(addr, taquito_utils_1.addressPrefixes);
78
+ const [addr] = (0, encoding_1.splitAddress)(value !== null && value !== void 0 ? value : '');
79
+ return validatePrefixedValue(addr, encoding_1.addressPrefixes);
81
80
  }
82
81
  /**
83
82
  * @description Used to check if a chain id is valid.
@@ -131,7 +130,7 @@ function validateContractAddress(value) {
131
130
  * ```
132
131
  */
133
132
  function validateKeyHash(value) {
134
- return validatePrefixedValue(value, taquito_utils_1.publicKeyHashPrefixes);
133
+ return validatePrefixedValue(value, encoding_1.publicKeyHashPrefixes);
135
134
  }
136
135
  /**
137
136
  * @description Used to check if a signature is valid.
@@ -149,7 +148,7 @@ function validateKeyHash(value) {
149
148
  * ```
150
149
  */
151
150
  function validateSignature(value) {
152
- return validatePrefixedValue(value, taquito_utils_1.signaturePrefixes);
151
+ return validatePrefixedValue(value, encoding_1.signaturePrefixes);
153
152
  }
154
153
  /**
155
154
  * @description Used to check if a public key is valid.
@@ -167,7 +166,7 @@ function validateSignature(value) {
167
166
  * ```
168
167
  */
169
168
  function validatePublicKey(value) {
170
- return validatePrefixedValue(value, taquito_utils_1.publicKeyPrefixes);
169
+ return validatePrefixedValue(value, encoding_1.publicKeyPrefixes);
171
170
  }
172
171
  /**
173
172
  * @description Used to check if an operation hash is valid.
@@ -223,22 +222,6 @@ function validateProtocol(value) {
223
222
  function validateBlock(value) {
224
223
  return validatePrefixedValue(value, [constants_1.PrefixV2.BlockHash]);
225
224
  }
226
- /**
227
- * @deprecated this function will be removed in the next minor release
228
- * @description generates a readable error string from a validation result
229
- */
230
- function invalidDetail(validation) {
231
- switch (validation) {
232
- case taquito_utils_1.ValidationResult.NO_PREFIX_MATCHED:
233
- return 'with unsupported prefix';
234
- case taquito_utils_1.ValidationResult.INVALID_CHECKSUM:
235
- return 'failed checksum';
236
- case taquito_utils_1.ValidationResult.INVALID_LENGTH:
237
- return 'with incorrect length';
238
- default:
239
- return '';
240
- }
241
- }
242
225
  /**
243
226
  * @description Used to check if a spending key is valid.
244
227
  * @returns
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.POP_DST = exports.BLS12_381_DST = void 0;
4
4
  exports.verifySignature = verifySignature;
5
- exports.validatePkAndExtractPrefix = validatePkAndExtractPrefix;
6
5
  const ed25519_1 = require("@stablelib/ed25519");
7
6
  const blake2b_1 = require("@stablelib/blake2b");
8
- const taquito_utils_1 = require("./taquito-utils");
9
- const elliptic_1 = require("elliptic");
7
+ const encoding_1 = require("./encoding");
8
+ const constants_1 = require("./constants");
9
+ const secp256k1_1 = require("@noble/curves/secp256k1");
10
+ const nist_1 = require("@noble/curves/nist");
10
11
  const core_1 = require("@taquito/core");
11
12
  const bls12_381_1 = require("@noble/curves/bls12-381");
12
13
  exports.BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
@@ -33,7 +34,7 @@ exports.POP_DST = 'BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
33
34
  function verifySignature(message, publicKey, signature, watermark, pop) {
34
35
  const [pk, pre] = (() => {
35
36
  try {
36
- return (0, taquito_utils_1.b58DecodeAndCheckPrefix)(publicKey, taquito_utils_1.publicKeyPrefixes);
37
+ return (0, encoding_1.b58DecodeAndCheckPrefix)(publicKey, encoding_1.publicKeyPrefixes);
37
38
  }
38
39
  catch (err) {
39
40
  if (err instanceof core_1.ParameterValidationError) {
@@ -46,7 +47,7 @@ function verifySignature(message, publicKey, signature, watermark, pop) {
46
47
  })();
47
48
  const sig = (() => {
48
49
  try {
49
- const [sig] = (0, taquito_utils_1.b58DecodeAndCheckPrefix)(signature, taquito_utils_1.signaturePrefixes);
50
+ const [sig] = (0, encoding_1.b58DecodeAndCheckPrefix)(signature, encoding_1.signaturePrefixes);
50
51
  return sig;
51
52
  }
52
53
  catch (err) {
@@ -60,48 +61,33 @@ function verifySignature(message, publicKey, signature, watermark, pop) {
60
61
  })();
61
62
  let msg;
62
63
  if (typeof message === 'string') {
63
- msg = (0, taquito_utils_1.hex2buf)(message);
64
+ msg = (0, encoding_1.hex2buf)(message);
64
65
  }
65
66
  else {
66
67
  msg = message;
67
68
  }
68
69
  if (msg.length === 0) {
69
- throw new core_1.InvalidMessageError((0, taquito_utils_1.buf2hex)(msg), `can't be empty`);
70
+ throw new core_1.InvalidMessageError((0, encoding_1.buf2hex)(msg), `can't be empty`);
70
71
  }
71
72
  if (typeof watermark !== 'undefined') {
72
- msg = (0, taquito_utils_1.mergebuf)(watermark, msg);
73
+ msg = (0, encoding_1.mergebuf)(watermark, msg);
73
74
  }
74
75
  if (pop) {
75
76
  return verifyBLSPopSignature(sig, msg, pk);
76
77
  }
77
78
  else {
78
79
  switch (pre) {
79
- case taquito_utils_1.PrefixV2.P256PublicKey:
80
+ case constants_1.PrefixV2.P256PublicKey:
80
81
  return verifyP2Signature(sig, msg, pk);
81
- case taquito_utils_1.PrefixV2.Secp256k1PublicKey:
82
+ case constants_1.PrefixV2.Secp256k1PublicKey:
82
83
  return verifySpSignature(sig, msg, pk);
83
- case taquito_utils_1.PrefixV2.Ed25519PublicKey:
84
+ case constants_1.PrefixV2.Ed25519PublicKey:
84
85
  return verifyEdSignature(sig, msg, pk);
85
86
  default:
86
87
  return verifyBLSSignature(sig, msg, pk);
87
88
  }
88
89
  }
89
90
  }
90
- /**
91
- * @deprecated use b58DecodeAndCheckPrefix instead, this function will be removed in the next minor release
92
- * @description validates a public key and extracts the prefix
93
- */
94
- function validatePkAndExtractPrefix(publicKey) {
95
- if (publicKey === '') {
96
- throw new core_1.InvalidPublicKeyError(publicKey, `can't be empty`);
97
- }
98
- const pkPrefix = publicKey.substring(0, 4);
99
- const publicKeyValidation = (0, taquito_utils_1.validatePublicKey)(publicKey);
100
- if (publicKeyValidation !== taquito_utils_1.ValidationResult.VALID) {
101
- throw new core_1.InvalidPublicKeyError(publicKey, (0, taquito_utils_1.invalidDetail)(publicKeyValidation));
102
- }
103
- return pkPrefix;
104
- }
105
91
  function verifyEdSignature(sig, msg, publicKey) {
106
92
  const hash = (0, blake2b_1.hash)(msg, 32);
107
93
  try {
@@ -112,19 +98,18 @@ function verifyEdSignature(sig, msg, publicKey) {
112
98
  }
113
99
  }
114
100
  function verifySpSignature(sig, msg, publicKey) {
115
- const key = new elliptic_1.default.ec('secp256k1').keyFromPublic(publicKey);
116
- return verifySpOrP2Sig(sig, msg, key);
101
+ const hash = (0, blake2b_1.hash)(msg, 32);
102
+ try {
103
+ return secp256k1_1.secp256k1.verify(sig, hash, publicKey);
104
+ }
105
+ catch (_a) {
106
+ return false;
107
+ }
117
108
  }
118
109
  function verifyP2Signature(sig, msg, publicKey) {
119
- const key = new elliptic_1.default.ec('p256').keyFromPublic(publicKey);
120
- return verifySpOrP2Sig(sig, msg, key);
121
- }
122
- function verifySpOrP2Sig(sig, msg, key) {
123
- const r = sig.slice(0, 32);
124
- const s = sig.slice(32);
125
110
  const hash = (0, blake2b_1.hash)(msg, 32);
126
111
  try {
127
- return key.verify(hash, { r, s });
112
+ return nist_1.p256.verify(sig, hash, publicKey);
128
113
  }
129
114
  catch (_a) {
130
115
  return false;
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5
5
  exports.VERSION = {
6
- "commitHash": "42048d039f6d4345fc59d04b03650bcb8e27bb62",
7
- "version": "23.0.3"
6
+ "commitHash": "7912b77f57f943dff619383900bd46a7a593a244",
7
+ "version": "24.0.0-beta.0"
8
8
  };