@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.
- package/dist/lib/constants.js +1 -128
- package/dist/lib/encoding.js +603 -0
- package/dist/lib/taquito-utils.js +16 -710
- package/dist/lib/validators.js +10 -27
- package/dist/lib/verify-signature.js +20 -35
- package/dist/lib/version.js +2 -2
- package/dist/taquito-utils.es6.js +2690 -958
- package/dist/taquito-utils.es6.js.map +1 -1
- package/dist/taquito-utils.umd.js +2578 -858
- package/dist/taquito-utils.umd.js.map +1 -1
- package/dist/types/constants.d.ts +0 -101
- package/dist/types/encoding.d.ts +184 -0
- package/dist/types/taquito-utils.d.ts +1 -234
- package/dist/types/validators.d.ts +1 -6
- package/dist/types/verify-signature.d.ts +0 -8
- package/package.json +8 -8
package/dist/lib/validators.js
CHANGED
|
@@ -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
|
|
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) ===
|
|
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,
|
|
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
|
|
58
|
+
return core_1.ValidationResult.OTHER;
|
|
60
59
|
}
|
|
61
|
-
return
|
|
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,
|
|
80
|
-
return validatePrefixedValue(addr,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
9
|
-
const
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
80
|
+
case constants_1.PrefixV2.P256PublicKey:
|
|
80
81
|
return verifyP2Signature(sig, msg, pk);
|
|
81
|
-
case
|
|
82
|
+
case constants_1.PrefixV2.Secp256k1PublicKey:
|
|
82
83
|
return verifySpSignature(sig, msg, pk);
|
|
83
|
-
case
|
|
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
|
|
116
|
-
|
|
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
|
|
112
|
+
return nist_1.p256.verify(sig, hash, publicKey);
|
|
128
113
|
}
|
|
129
114
|
catch (_a) {
|
|
130
115
|
return false;
|
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": "
|
|
6
|
+
"commitHash": "7912b77f57f943dff619383900bd46a7a593a244",
|
|
7
|
+
"version": "24.0.0-beta.0"
|
|
8
8
|
};
|