@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 +14 -11
- package/dist/lib/constants.js +213 -2
- package/dist/lib/errors.js +4 -8
- package/dist/lib/taquito-utils.js +504 -251
- package/dist/lib/validators.js +71 -80
- package/dist/lib/verify-signature.js +99 -57
- package/dist/lib/version.js +2 -2
- package/dist/taquito-utils.es6.js +903 -429
- package/dist/taquito-utils.es6.js.map +1 -1
- package/dist/taquito-utils.umd.js +929 -435
- package/dist/taquito-utils.umd.js.map +1 -1
- package/dist/types/constants.d.ts +90 -0
- package/dist/types/errors.d.ts +2 -3
- package/dist/types/taquito-utils.d.ts +156 -103
- package/dist/types/validators.d.ts +32 -20
- package/dist/types/verify-signature.d.ts +12 -6
- package/package.json +4 -3
package/dist/lib/validators.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValidationResult = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.isValidPrefixedValue = isValidPrefixedValue;
|
|
5
5
|
exports.validateAddress = validateAddress;
|
|
6
6
|
exports.validateChain = validateChain;
|
|
7
7
|
exports.validateContractAddress = validateContractAddress;
|
|
@@ -11,75 +11,60 @@ exports.validatePublicKey = validatePublicKey;
|
|
|
11
11
|
exports.validateOperation = validateOperation;
|
|
12
12
|
exports.validateProtocol = validateProtocol;
|
|
13
13
|
exports.validateBlock = validateBlock;
|
|
14
|
-
exports.validateSpendingKey = validateSpendingKey;
|
|
15
14
|
exports.invalidDetail = invalidDetail;
|
|
15
|
+
exports.validateSpendingKey = validateSpendingKey;
|
|
16
16
|
exports.validateSmartRollupAddress = validateSmartRollupAddress;
|
|
17
17
|
const constants_1 = require("./constants");
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
const taquito_utils_1 = require("./taquito-utils");
|
|
19
|
+
const core_1 = require("@taquito/core");
|
|
20
|
+
var core_2 = require("@taquito/core");
|
|
21
|
+
Object.defineProperty(exports, "ValidationResult", { enumerable: true, get: function () { return core_2.ValidationResult; } });
|
|
22
|
+
/**
|
|
23
|
+
* @description Used to check if a value has one of the allowed prefixes.
|
|
24
|
+
* @returns true if the value has one of the allowed prefixes, false otherwise
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* import { isValidPrefixedValue } from '@taquito/utils';
|
|
28
|
+
* const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
|
|
29
|
+
* const isValid = isValidPrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
|
|
30
|
+
* console.log(isValid) // true
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function isValidPrefixedValue(value, prefixes) {
|
|
34
|
+
return validatePrefixedValue(value, prefixes) === taquito_utils_1.ValidationResult.VALID;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* @description This function is called by the validation functions ([[validateAddress]], [[validateChain]], [[validateContractAddress]], [[validateKeyHash]], [[validateSignature]], [[validatePublicKey]]).
|
|
34
|
-
* Verify if the value
|
|
35
|
-
*
|
|
36
|
-
* check if the length of the value matches the prefix type or return `INVALID_LENGTH`.
|
|
37
|
-
* If all checks pass, return `VALID`.
|
|
38
|
-
*
|
|
38
|
+
* Verify if the value can be decoded or return `1` (INVALID_CHECKSUM) / `5` (INVALID_ENCODING), then check if the prefix is valid or allowed or return `0` (NO_PREFIX_MATCHED) / `4` (PREFIX_NOT_ALLOWED)
|
|
39
|
+
* If all checks pass, return `3` (VALID).
|
|
39
40
|
* @param value Value to validate
|
|
40
41
|
* @param prefixes prefix the value should have
|
|
42
|
+
* @returns 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
43
|
+
* @example
|
|
44
|
+
* ```
|
|
45
|
+
* import { validatePrefixedValue } from '@taquito/utils';
|
|
46
|
+
* const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
|
|
47
|
+
* const validation = validatePrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
|
|
48
|
+
* console.log(validation) // 3
|
|
49
|
+
* ```
|
|
41
50
|
*/
|
|
42
51
|
function validatePrefixedValue(value, prefixes) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return ValidationResult.NO_PREFIX_MATCHED;
|
|
46
|
-
}
|
|
47
|
-
const prefixKey = match[0];
|
|
48
|
-
if (!isValidPrefix(prefixKey)) {
|
|
49
|
-
return ValidationResult.NO_PREFIX_MATCHED;
|
|
50
|
-
}
|
|
51
|
-
// Check whether annotation exist before starting validation
|
|
52
|
-
if (value.includes('%')) {
|
|
53
|
-
value = value.split('%')[0];
|
|
52
|
+
try {
|
|
53
|
+
(0, taquito_utils_1.b58DecodeAndCheckPrefix)(value, prefixes);
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (err instanceof core_1.ParameterValidationError && err.result !== undefined) {
|
|
57
|
+
return err.result;
|
|
58
|
+
}
|
|
59
|
+
return taquito_utils_1.ValidationResult.OTHER;
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
let decoded = bs58check_1.default.decodeUnsafe(value);
|
|
61
|
-
if (!decoded) {
|
|
62
|
-
return ValidationResult.INVALID_CHECKSUM;
|
|
63
|
-
}
|
|
64
|
-
decoded = decoded.slice(constants_1.prefix[prefixKey].length);
|
|
65
|
-
if (decoded.length !== constants_1.prefixLength[prefixKey]) {
|
|
66
|
-
return ValidationResult.INVALID_LENGTH;
|
|
67
|
-
}
|
|
68
|
-
return ValidationResult.VALID;
|
|
61
|
+
return taquito_utils_1.ValidationResult.VALID;
|
|
69
62
|
}
|
|
70
|
-
const implicitPrefix = [constants_1.Prefix.TZ1, constants_1.Prefix.TZ2, constants_1.Prefix.TZ3, constants_1.Prefix.TZ4];
|
|
71
|
-
const contractPrefix = [constants_1.Prefix.KT1];
|
|
72
|
-
const signaturePrefix = [constants_1.Prefix.EDSIG, constants_1.Prefix.P2SIG, constants_1.Prefix.SPSIG, constants_1.Prefix.SIG];
|
|
73
|
-
const pkPrefix = [constants_1.Prefix.EDPK, constants_1.Prefix.SPPK, constants_1.Prefix.P2PK, constants_1.Prefix.BLPK];
|
|
74
|
-
const operationPrefix = [constants_1.Prefix.O];
|
|
75
|
-
const protocolPrefix = [constants_1.Prefix.P];
|
|
76
|
-
const blockPrefix = [constants_1.Prefix.B];
|
|
77
|
-
const smartRollupPrefix = [constants_1.Prefix.SR1];
|
|
78
63
|
/**
|
|
79
64
|
* @description Used to check if an address or a contract address is valid.
|
|
80
65
|
*
|
|
81
66
|
* @returns
|
|
82
|
-
* 0
|
|
67
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
83
68
|
*
|
|
84
69
|
* @example
|
|
85
70
|
* ```
|
|
@@ -91,13 +76,14 @@ const smartRollupPrefix = [constants_1.Prefix.SR1];
|
|
|
91
76
|
* ```
|
|
92
77
|
*/
|
|
93
78
|
function validateAddress(value) {
|
|
94
|
-
|
|
79
|
+
const [addr] = (0, taquito_utils_1.splitAddress)(value !== null && value !== void 0 ? value : '');
|
|
80
|
+
return validatePrefixedValue(addr, taquito_utils_1.addressPrefixes);
|
|
95
81
|
}
|
|
96
82
|
/**
|
|
97
83
|
* @description Used to check if a chain id is valid.
|
|
98
84
|
*
|
|
99
85
|
* @returns
|
|
100
|
-
* 0
|
|
86
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
101
87
|
*
|
|
102
88
|
* @example
|
|
103
89
|
* ```
|
|
@@ -109,13 +95,13 @@ function validateAddress(value) {
|
|
|
109
95
|
* ```
|
|
110
96
|
*/
|
|
111
97
|
function validateChain(value) {
|
|
112
|
-
return validatePrefixedValue(value, [constants_1.
|
|
98
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.ChainID]);
|
|
113
99
|
}
|
|
114
100
|
/**
|
|
115
101
|
* @description Used to check if a contract address is valid.
|
|
116
102
|
*
|
|
117
103
|
* @returns
|
|
118
|
-
* 0
|
|
104
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
119
105
|
*
|
|
120
106
|
* @example
|
|
121
107
|
* ```
|
|
@@ -127,13 +113,13 @@ function validateChain(value) {
|
|
|
127
113
|
* ```
|
|
128
114
|
*/
|
|
129
115
|
function validateContractAddress(value) {
|
|
130
|
-
return validatePrefixedValue(value,
|
|
116
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.ContractHash]);
|
|
131
117
|
}
|
|
132
118
|
/**
|
|
133
119
|
* @description Used to check if a key hash is valid.
|
|
134
120
|
*
|
|
135
121
|
* @returns
|
|
136
|
-
* 0
|
|
122
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
137
123
|
*
|
|
138
124
|
* @example
|
|
139
125
|
* ```
|
|
@@ -145,13 +131,13 @@ function validateContractAddress(value) {
|
|
|
145
131
|
* ```
|
|
146
132
|
*/
|
|
147
133
|
function validateKeyHash(value) {
|
|
148
|
-
return validatePrefixedValue(value,
|
|
134
|
+
return validatePrefixedValue(value, taquito_utils_1.publicKeyHashPrefixes);
|
|
149
135
|
}
|
|
150
136
|
/**
|
|
151
137
|
* @description Used to check if a signature is valid.
|
|
152
138
|
*
|
|
153
139
|
* @returns
|
|
154
|
-
* 0
|
|
140
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
155
141
|
*
|
|
156
142
|
* @example
|
|
157
143
|
* ```
|
|
@@ -163,13 +149,13 @@ function validateKeyHash(value) {
|
|
|
163
149
|
* ```
|
|
164
150
|
*/
|
|
165
151
|
function validateSignature(value) {
|
|
166
|
-
return validatePrefixedValue(value,
|
|
152
|
+
return validatePrefixedValue(value, taquito_utils_1.signaturePrefixes);
|
|
167
153
|
}
|
|
168
154
|
/**
|
|
169
155
|
* @description Used to check if a public key is valid.
|
|
170
156
|
*
|
|
171
157
|
* @returns
|
|
172
|
-
* 0
|
|
158
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
173
159
|
*
|
|
174
160
|
* @example
|
|
175
161
|
* ```
|
|
@@ -181,13 +167,13 @@ function validateSignature(value) {
|
|
|
181
167
|
* ```
|
|
182
168
|
*/
|
|
183
169
|
function validatePublicKey(value) {
|
|
184
|
-
return validatePrefixedValue(value,
|
|
170
|
+
return validatePrefixedValue(value, taquito_utils_1.publicKeyPrefixes);
|
|
185
171
|
}
|
|
186
172
|
/**
|
|
187
173
|
* @description Used to check if an operation hash is valid.
|
|
188
174
|
*
|
|
189
175
|
* @returns
|
|
190
|
-
* 0
|
|
176
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
191
177
|
*
|
|
192
178
|
* @example
|
|
193
179
|
* ```
|
|
@@ -199,13 +185,13 @@ function validatePublicKey(value) {
|
|
|
199
185
|
* ```
|
|
200
186
|
*/
|
|
201
187
|
function validateOperation(value) {
|
|
202
|
-
return validatePrefixedValue(value,
|
|
188
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.OperationHash]);
|
|
203
189
|
}
|
|
204
190
|
/**
|
|
205
191
|
* @description Used to check if a protocol hash is valid.
|
|
206
192
|
*
|
|
207
193
|
* @returns
|
|
208
|
-
* 0
|
|
194
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
209
195
|
*
|
|
210
196
|
* @example
|
|
211
197
|
* ```
|
|
@@ -217,13 +203,13 @@ function validateOperation(value) {
|
|
|
217
203
|
* ```
|
|
218
204
|
*/
|
|
219
205
|
function validateProtocol(value) {
|
|
220
|
-
return validatePrefixedValue(value,
|
|
206
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.ProtocolHash]);
|
|
221
207
|
}
|
|
222
208
|
/**
|
|
223
209
|
* @description Used to check if a block hash is valid.
|
|
224
210
|
*
|
|
225
211
|
* @returns
|
|
226
|
-
* 0
|
|
212
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
227
213
|
*
|
|
228
214
|
* @example
|
|
229
215
|
* ```
|
|
@@ -235,28 +221,33 @@ function validateProtocol(value) {
|
|
|
235
221
|
* ```
|
|
236
222
|
*/
|
|
237
223
|
function validateBlock(value) {
|
|
238
|
-
return validatePrefixedValue(value,
|
|
224
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.BlockHash]);
|
|
239
225
|
}
|
|
240
226
|
/**
|
|
241
|
-
* @
|
|
242
|
-
* @
|
|
243
|
-
*
|
|
227
|
+
* @deprecated this function will be removed in the next minor release
|
|
228
|
+
* @description generates a readable error string from a validation result
|
|
244
229
|
*/
|
|
245
|
-
function validateSpendingKey(value) {
|
|
246
|
-
return validatePrefixedValue(value, [constants_1.Prefix.SASK]);
|
|
247
|
-
}
|
|
248
230
|
function invalidDetail(validation) {
|
|
249
231
|
switch (validation) {
|
|
250
|
-
case ValidationResult.NO_PREFIX_MATCHED:
|
|
232
|
+
case taquito_utils_1.ValidationResult.NO_PREFIX_MATCHED:
|
|
251
233
|
return 'with unsupported prefix';
|
|
252
|
-
case ValidationResult.INVALID_CHECKSUM:
|
|
234
|
+
case taquito_utils_1.ValidationResult.INVALID_CHECKSUM:
|
|
253
235
|
return 'failed checksum';
|
|
254
|
-
case ValidationResult.INVALID_LENGTH:
|
|
236
|
+
case taquito_utils_1.ValidationResult.INVALID_LENGTH:
|
|
255
237
|
return 'with incorrect length';
|
|
256
238
|
default:
|
|
257
239
|
return '';
|
|
258
240
|
}
|
|
259
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* @description Used to check if a spending key is valid.
|
|
244
|
+
* @returns
|
|
245
|
+
* 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
|
|
246
|
+
*
|
|
247
|
+
*/
|
|
248
|
+
function validateSpendingKey(value) {
|
|
249
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.SaplingSpendingKey]);
|
|
250
|
+
}
|
|
260
251
|
function validateSmartRollupAddress(value) {
|
|
261
|
-
return validatePrefixedValue(value, [
|
|
252
|
+
return validatePrefixedValue(value, [constants_1.PrefixV2.SmartRollupHash]);
|
|
262
253
|
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.POP_DST = exports.BLS12_381_DST = void 0;
|
|
3
4
|
exports.verifySignature = verifySignature;
|
|
4
5
|
exports.validatePkAndExtractPrefix = validatePkAndExtractPrefix;
|
|
5
6
|
const ed25519_1 = require("@stablelib/ed25519");
|
|
6
7
|
const blake2b_1 = require("@stablelib/blake2b");
|
|
7
8
|
const taquito_utils_1 = require("./taquito-utils");
|
|
8
9
|
const elliptic_1 = require("elliptic");
|
|
9
|
-
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
|
|
10
10
|
const core_1 = require("@taquito/core");
|
|
11
|
+
const bls12_381_1 = require("@noble/curves/bls12-381");
|
|
12
|
+
exports.BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
|
|
13
|
+
exports.POP_DST = 'BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
|
|
11
14
|
/**
|
|
12
15
|
* @description Verify signature of a payload
|
|
13
|
-
*
|
|
14
|
-
* @param messageBytes The forged message including the magic byte (11 for block,
|
|
15
|
-
* 12 for preattestation, 13 for attestation, 3 for generic, 5 for the PACK format of michelson)
|
|
16
|
+
* @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
|
|
16
17
|
* @param publicKey The public key to verify the signature against
|
|
17
18
|
* @param signature The signature to verify
|
|
19
|
+
* @param watermark Optional if not included in the message
|
|
20
|
+
* @param pop Optional if verifying proof of possession signature
|
|
18
21
|
* @returns A boolean indicating if the signature matches
|
|
19
22
|
* @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
|
|
20
23
|
* @example
|
|
@@ -27,35 +30,67 @@ const core_1 = require("@taquito/core");
|
|
|
27
30
|
* ```
|
|
28
31
|
*
|
|
29
32
|
*/
|
|
30
|
-
function verifySignature(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function verifySignature(message, publicKey, signature, watermark, pop) {
|
|
34
|
+
const [pk, pre] = (() => {
|
|
35
|
+
try {
|
|
36
|
+
return (0, taquito_utils_1.b58DecodeAndCheckPrefix)(publicKey, taquito_utils_1.publicKeyPrefixes);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err instanceof core_1.ParameterValidationError) {
|
|
40
|
+
throw new core_1.InvalidPublicKeyError(publicKey, err.result);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
const sig = (() => {
|
|
48
|
+
try {
|
|
49
|
+
const [sig] = (0, taquito_utils_1.b58DecodeAndCheckPrefix)(signature, taquito_utils_1.signaturePrefixes);
|
|
50
|
+
return sig;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (err instanceof core_1.ParameterValidationError) {
|
|
54
|
+
throw new core_1.InvalidSignatureError(signature, err.result);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
let msg;
|
|
62
|
+
if (typeof message === 'string') {
|
|
63
|
+
msg = (0, taquito_utils_1.hex2buf)(message);
|
|
38
64
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return verifyEdSignature(decodedSig, bytesHash, decodedPublicKey);
|
|
65
|
+
else {
|
|
66
|
+
msg = message;
|
|
42
67
|
}
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
if (msg.length === 0) {
|
|
69
|
+
throw new core_1.InvalidMessageError((0, taquito_utils_1.buf2hex)(msg), `can't be empty`);
|
|
45
70
|
}
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
if (typeof watermark !== 'undefined') {
|
|
72
|
+
msg = (0, taquito_utils_1.mergebuf)(watermark, msg);
|
|
48
73
|
}
|
|
49
|
-
|
|
50
|
-
return
|
|
74
|
+
if (pop) {
|
|
75
|
+
return verifyBLSPopSignature(sig, msg, pk);
|
|
51
76
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
else {
|
|
78
|
+
switch (pre) {
|
|
79
|
+
case taquito_utils_1.PrefixV2.P256PublicKey:
|
|
80
|
+
return verifyP2Signature(sig, msg, pk);
|
|
81
|
+
case taquito_utils_1.PrefixV2.Secp256k1PublicKey:
|
|
82
|
+
return verifySpSignature(sig, msg, pk);
|
|
83
|
+
case taquito_utils_1.PrefixV2.Ed25519PublicKey:
|
|
84
|
+
return verifyEdSignature(sig, msg, pk);
|
|
85
|
+
default:
|
|
86
|
+
return verifyBLSSignature(sig, msg, pk);
|
|
87
|
+
}
|
|
56
88
|
}
|
|
57
|
-
return message;
|
|
58
89
|
}
|
|
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
|
+
*/
|
|
59
94
|
function validatePkAndExtractPrefix(publicKey) {
|
|
60
95
|
if (publicKey === '') {
|
|
61
96
|
throw new core_1.InvalidPublicKeyError(publicKey, `can't be empty`);
|
|
@@ -67,43 +102,50 @@ function validatePkAndExtractPrefix(publicKey) {
|
|
|
67
102
|
}
|
|
68
103
|
return pkPrefix;
|
|
69
104
|
}
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
? signature.substring(0, 3)
|
|
73
|
-
: signature.substring(0, 5);
|
|
74
|
-
const validation = (0, taquito_utils_1.validateSignature)(signature);
|
|
75
|
-
if (validation !== taquito_utils_1.ValidationResult.VALID) {
|
|
76
|
-
throw new core_1.InvalidSignatureError(signature, (0, taquito_utils_1.invalidDetail)(validation));
|
|
77
|
-
}
|
|
78
|
-
return signaturePrefix;
|
|
79
|
-
}
|
|
80
|
-
function verifyEdSignature(decodedSig, bytesHash, decodedPublicKey) {
|
|
105
|
+
function verifyEdSignature(sig, msg, publicKey) {
|
|
106
|
+
const hash = (0, blake2b_1.hash)(msg, 32);
|
|
81
107
|
try {
|
|
82
|
-
return (0, ed25519_1.verify)(
|
|
108
|
+
return (0, ed25519_1.verify)(publicKey, hash, sig);
|
|
83
109
|
}
|
|
84
|
-
catch (
|
|
110
|
+
catch (_a) {
|
|
85
111
|
return false;
|
|
86
112
|
}
|
|
87
113
|
}
|
|
88
|
-
function verifySpSignature(
|
|
89
|
-
const key = new elliptic_1.default.ec('secp256k1').keyFromPublic(
|
|
90
|
-
return verifySpOrP2Sig(
|
|
114
|
+
function verifySpSignature(sig, msg, publicKey) {
|
|
115
|
+
const key = new elliptic_1.default.ec('secp256k1').keyFromPublic(publicKey);
|
|
116
|
+
return verifySpOrP2Sig(sig, msg, key);
|
|
91
117
|
}
|
|
92
|
-
function verifyP2Signature(
|
|
93
|
-
const key = new elliptic_1.default.ec('p256').keyFromPublic(
|
|
94
|
-
return verifySpOrP2Sig(
|
|
118
|
+
function verifyP2Signature(sig, msg, publicKey) {
|
|
119
|
+
const key = new elliptic_1.default.ec('p256').keyFromPublic(publicKey);
|
|
120
|
+
return verifySpOrP2Sig(sig, msg, key);
|
|
95
121
|
}
|
|
96
|
-
function verifySpOrP2Sig(
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
function verifySpOrP2Sig(sig, msg, key) {
|
|
123
|
+
const r = sig.slice(0, 32);
|
|
124
|
+
const s = sig.slice(32);
|
|
125
|
+
const hash = (0, blake2b_1.hash)(msg, 32);
|
|
126
|
+
try {
|
|
127
|
+
return key.verify(hash, { r, s });
|
|
128
|
+
}
|
|
129
|
+
catch (_a) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const bls = bls12_381_1.bls12_381.longSignatures; // AKA MinPK
|
|
134
|
+
function verifyBLSSignature(sig, msg, publicKey) {
|
|
135
|
+
try {
|
|
136
|
+
const point = bls.hash(msg, exports.BLS12_381_DST);
|
|
137
|
+
return bls.verify(sig, point, publicKey);
|
|
138
|
+
}
|
|
139
|
+
catch (_a) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function verifyBLSPopSignature(sig, msg, publicKey) {
|
|
144
|
+
try {
|
|
145
|
+
const point = bls.hash(msg, exports.POP_DST);
|
|
146
|
+
return bls.verify(sig, point, publicKey);
|
|
147
|
+
}
|
|
148
|
+
catch (_a) {
|
|
149
|
+
return false;
|
|
107
150
|
}
|
|
108
|
-
return false;
|
|
109
151
|
}
|
package/dist/lib/version.js
CHANGED
|
@@ -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": "
|
|
7
|
-
"version": "23.0.0-beta.
|
|
6
|
+
"commitHash": "10b3de10de15ae68d47b1fca922d3129d2f79641",
|
|
7
|
+
"version": "23.0.0-beta.1"
|
|
8
8
|
};
|