@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.
@@ -1,765 +1,2191 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('buffer'), require('@stablelib/blake2b'), require('bs58check'), require('bignumber.js'), require('typedarray-to-buffer'), require('@taquito/core'), require('@stablelib/ed25519'), require('elliptic'), require('@noble/curves/bls12-381')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'buffer', '@stablelib/blake2b', 'bs58check', 'bignumber.js', 'typedarray-to-buffer', '@taquito/core', '@stablelib/ed25519', 'elliptic', '@noble/curves/bls12-381'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.buffer, global.blake2b, global.bs58check, global.BigNumber, global.toBuffer, global.core, global.ed25519, global.elliptic, global.bls12381));
5
- })(this, (function (exports, buffer, blake2b, bs58check, BigNumber, toBuffer, core, ed25519, elliptic, bls12381) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stablelib/blake2b'), require('bs58check'), require('bignumber.js'), require('typedarray-to-buffer'), require('@taquito/core'), require('@stablelib/ed25519'), require('@noble/curves/secp256k1'), require('@noble/curves/nist'), require('@noble/curves/bls12-381')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@stablelib/blake2b', 'bs58check', 'bignumber.js', 'typedarray-to-buffer', '@taquito/core', '@stablelib/ed25519', '@noble/curves/secp256k1', '@noble/curves/nist', '@noble/curves/bls12-381'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoUtils = {}, global.blake2b, global.bs58check, global.BigNumber, global.toBuffer, global.core, global.ed25519, global.secp256k1, global.nist, global.bls12381));
5
+ })(this, (function (exports, blake2b, bs58check, BigNumber, toBuffer, core, ed25519, secp256k1, nist, bls12381) { 'use strict';
6
+
7
+ var global$1 = (typeof global !== "undefined" ? global :
8
+ typeof self !== "undefined" ? self :
9
+ typeof window !== "undefined" ? window : {});
10
+
11
+ var lookup = [];
12
+ var revLookup = [];
13
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
14
+ var inited = false;
15
+ function init () {
16
+ inited = true;
17
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
18
+ for (var i = 0, len = code.length; i < len; ++i) {
19
+ lookup[i] = code[i];
20
+ revLookup[code.charCodeAt(i)] = i;
21
+ }
22
+
23
+ revLookup['-'.charCodeAt(0)] = 62;
24
+ revLookup['_'.charCodeAt(0)] = 63;
25
+ }
26
+
27
+ function toByteArray (b64) {
28
+ if (!inited) {
29
+ init();
30
+ }
31
+ var i, j, l, tmp, placeHolders, arr;
32
+ var len = b64.length;
33
+
34
+ if (len % 4 > 0) {
35
+ throw new Error('Invalid string. Length must be a multiple of 4')
36
+ }
37
+
38
+ // the number of equal signs (place holders)
39
+ // if there are two placeholders, than the two characters before it
40
+ // represent one byte
41
+ // if there is only one, then the three characters before it represent 2 bytes
42
+ // this is just a cheap hack to not do indexOf twice
43
+ placeHolders = b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0;
44
+
45
+ // base64 is 4/3 + up to two characters of the original data
46
+ arr = new Arr(len * 3 / 4 - placeHolders);
47
+
48
+ // if there are placeholders, only get up to the last complete 4 chars
49
+ l = placeHolders > 0 ? len - 4 : len;
50
+
51
+ var L = 0;
52
+
53
+ for (i = 0, j = 0; i < l; i += 4, j += 3) {
54
+ tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)];
55
+ arr[L++] = (tmp >> 16) & 0xFF;
56
+ arr[L++] = (tmp >> 8) & 0xFF;
57
+ arr[L++] = tmp & 0xFF;
58
+ }
59
+
60
+ if (placeHolders === 2) {
61
+ tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
62
+ arr[L++] = tmp & 0xFF;
63
+ } else if (placeHolders === 1) {
64
+ tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2);
65
+ arr[L++] = (tmp >> 8) & 0xFF;
66
+ arr[L++] = tmp & 0xFF;
67
+ }
68
+
69
+ return arr
70
+ }
71
+
72
+ function tripletToBase64 (num) {
73
+ return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
74
+ }
75
+
76
+ function encodeChunk (uint8, start, end) {
77
+ var tmp;
78
+ var output = [];
79
+ for (var i = start; i < end; i += 3) {
80
+ tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
81
+ output.push(tripletToBase64(tmp));
82
+ }
83
+ return output.join('')
84
+ }
85
+
86
+ function fromByteArray (uint8) {
87
+ if (!inited) {
88
+ init();
89
+ }
90
+ var tmp;
91
+ var len = uint8.length;
92
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
93
+ var output = '';
94
+ var parts = [];
95
+ var maxChunkLength = 16383; // must be multiple of 3
96
+
97
+ // go through the array every three bytes, we'll deal with trailing stuff later
98
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
99
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
100
+ }
101
+
102
+ // pad the end with zeros, but make sure to not forget the extra bytes
103
+ if (extraBytes === 1) {
104
+ tmp = uint8[len - 1];
105
+ output += lookup[tmp >> 2];
106
+ output += lookup[(tmp << 4) & 0x3F];
107
+ output += '==';
108
+ } else if (extraBytes === 2) {
109
+ tmp = (uint8[len - 2] << 8) + (uint8[len - 1]);
110
+ output += lookup[tmp >> 10];
111
+ output += lookup[(tmp >> 4) & 0x3F];
112
+ output += lookup[(tmp << 2) & 0x3F];
113
+ output += '=';
114
+ }
115
+
116
+ parts.push(output);
117
+
118
+ return parts.join('')
119
+ }
120
+
121
+ function read (buffer, offset, isLE, mLen, nBytes) {
122
+ var e, m;
123
+ var eLen = nBytes * 8 - mLen - 1;
124
+ var eMax = (1 << eLen) - 1;
125
+ var eBias = eMax >> 1;
126
+ var nBits = -7;
127
+ var i = isLE ? (nBytes - 1) : 0;
128
+ var d = isLE ? -1 : 1;
129
+ var s = buffer[offset + i];
130
+
131
+ i += d;
132
+
133
+ e = s & ((1 << (-nBits)) - 1);
134
+ s >>= (-nBits);
135
+ nBits += eLen;
136
+ for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
137
+
138
+ m = e & ((1 << (-nBits)) - 1);
139
+ e >>= (-nBits);
140
+ nBits += mLen;
141
+ for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
142
+
143
+ if (e === 0) {
144
+ e = 1 - eBias;
145
+ } else if (e === eMax) {
146
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
147
+ } else {
148
+ m = m + Math.pow(2, mLen);
149
+ e = e - eBias;
150
+ }
151
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
152
+ }
153
+
154
+ function write (buffer, value, offset, isLE, mLen, nBytes) {
155
+ var e, m, c;
156
+ var eLen = nBytes * 8 - mLen - 1;
157
+ var eMax = (1 << eLen) - 1;
158
+ var eBias = eMax >> 1;
159
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
160
+ var i = isLE ? 0 : (nBytes - 1);
161
+ var d = isLE ? 1 : -1;
162
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
163
+
164
+ value = Math.abs(value);
165
+
166
+ if (isNaN(value) || value === Infinity) {
167
+ m = isNaN(value) ? 1 : 0;
168
+ e = eMax;
169
+ } else {
170
+ e = Math.floor(Math.log(value) / Math.LN2);
171
+ if (value * (c = Math.pow(2, -e)) < 1) {
172
+ e--;
173
+ c *= 2;
174
+ }
175
+ if (e + eBias >= 1) {
176
+ value += rt / c;
177
+ } else {
178
+ value += rt * Math.pow(2, 1 - eBias);
179
+ }
180
+ if (value * c >= 2) {
181
+ e++;
182
+ c /= 2;
183
+ }
184
+
185
+ if (e + eBias >= eMax) {
186
+ m = 0;
187
+ e = eMax;
188
+ } else if (e + eBias >= 1) {
189
+ m = (value * c - 1) * Math.pow(2, mLen);
190
+ e = e + eBias;
191
+ } else {
192
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
193
+ e = 0;
194
+ }
195
+ }
196
+
197
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
198
+
199
+ e = (e << mLen) | m;
200
+ eLen += mLen;
201
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
202
+
203
+ buffer[offset + i - d] |= s * 128;
204
+ }
205
+
206
+ var toString = {}.toString;
207
+
208
+ var isArray = Array.isArray || function (arr) {
209
+ return toString.call(arr) == '[object Array]';
210
+ };
211
+
212
+ /*!
213
+ * The buffer module from node.js, for the browser.
214
+ *
215
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
216
+ * @license MIT
217
+ */
218
+ /* eslint-disable no-proto */
219
+
220
+
221
+ var INSPECT_MAX_BYTES = 50;
6
222
 
7
- // ref https://gitlab.com/tezos/tezos/-/blob/master/src/lib_crypto/base58.ml
8
223
  /**
9
- * @deprecated use PrefixV2 instead, this enum will be removed in the next minor release
10
- * @description base58 prefix definition enum
224
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
225
+ * === true Use Uint8Array implementation (fastest)
226
+ * === false Use Object implementation (most compatible, even IE6)
227
+ *
228
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
229
+ * Opera 11.6+, iOS 4.2+.
230
+ *
231
+ * Due to various browser bugs, sometimes the Object implementation will be used even
232
+ * when the browser supports typed arrays.
233
+ *
234
+ * Note:
235
+ *
236
+ * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
237
+ * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
238
+ *
239
+ * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
240
+ *
241
+ * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
242
+ * incorrect length in some situations.
243
+
244
+ * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
245
+ * get the Object implementation, which is slower but behaves correctly.
246
+ */
247
+ Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== undefined
248
+ ? global$1.TYPED_ARRAY_SUPPORT
249
+ : true;
250
+
251
+ /*
252
+ * Export kMaxLength after typed array support is determined.
11
253
  */
12
- exports.Prefix = void 0;
13
- (function (Prefix) {
14
- Prefix["TZ1"] = "tz1";
15
- Prefix["TZ2"] = "tz2";
16
- Prefix["TZ3"] = "tz3";
17
- Prefix["TZ4"] = "tz4";
18
- Prefix["KT"] = "KT";
19
- Prefix["KT1"] = "KT1";
20
- Prefix["EDSK"] = "edsk";
21
- Prefix["EDSK2"] = "edsk2";
22
- Prefix["SPSK"] = "spsk";
23
- Prefix["P2SK"] = "p2sk";
24
- Prefix["BLSK"] = "BLsk";
25
- Prefix["EDPK"] = "edpk";
26
- Prefix["SPPK"] = "sppk";
27
- Prefix["P2PK"] = "p2pk";
28
- Prefix["BLPK"] = "BLpk";
29
- Prefix["EDESK"] = "edesk";
30
- Prefix["SPESK"] = "spesk";
31
- Prefix["P2ESK"] = "p2esk";
32
- Prefix["BLESK"] = "BLesk";
33
- Prefix["EDSIG"] = "edsig";
34
- Prefix["SPSIG"] = "spsig";
35
- Prefix["P2SIG"] = "p2sig";
36
- Prefix["BLSIG"] = "BLsig";
37
- Prefix["SIG"] = "sig";
38
- Prefix["NET"] = "Net";
39
- Prefix["NCE"] = "nce";
40
- Prefix["B"] = "B";
41
- Prefix["O"] = "o";
42
- Prefix["LO"] = "Lo";
43
- Prefix["LLO"] = "LLo";
44
- Prefix["P"] = "P";
45
- Prefix["CO"] = "Co";
46
- Prefix["ID"] = "id";
47
- Prefix["EXPR"] = "expr";
48
- Prefix["TZ"] = "TZ";
49
- Prefix["VH"] = "vh";
50
- Prefix["SASK"] = "sask";
51
- Prefix["ZET1"] = "zet1";
52
- Prefix["SR1"] = "sr1";
53
- Prefix["SRC1"] = "src1";
54
- Prefix["SH"] = "sh";
55
- })(exports.Prefix || (exports.Prefix = {}));
254
+ kMaxLength();
255
+
256
+ function kMaxLength () {
257
+ return Buffer.TYPED_ARRAY_SUPPORT
258
+ ? 0x7fffffff
259
+ : 0x3fffffff
260
+ }
261
+
262
+ function createBuffer (that, length) {
263
+ if (kMaxLength() < length) {
264
+ throw new RangeError('Invalid typed array length')
265
+ }
266
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
267
+ // Return an augmented `Uint8Array` instance, for best performance
268
+ that = new Uint8Array(length);
269
+ that.__proto__ = Buffer.prototype;
270
+ } else {
271
+ // Fallback: Return an object instance of the Buffer class
272
+ if (that === null) {
273
+ that = new Buffer(length);
274
+ }
275
+ that.length = length;
276
+ }
277
+
278
+ return that
279
+ }
280
+
56
281
  /**
57
- * @deprecated use prefixV2 instead this constant will be removed in the next minor release
58
- * @description base58 prefix to bytes mapping
282
+ * The Buffer constructor returns instances of `Uint8Array` that have their
283
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
284
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
285
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
286
+ * returns a single octet.
287
+ *
288
+ * The `Uint8Array` prototype remains unmodified.
59
289
  */
60
- const prefix = {
61
- [exports.Prefix.TZ1]: new Uint8Array([6, 161, 159]),
62
- [exports.Prefix.TZ2]: new Uint8Array([6, 161, 161]),
63
- [exports.Prefix.TZ3]: new Uint8Array([6, 161, 164]),
64
- [exports.Prefix.TZ4]: new Uint8Array([6, 161, 166]),
65
- [exports.Prefix.KT]: new Uint8Array([2, 90, 121]),
66
- [exports.Prefix.KT1]: new Uint8Array([2, 90, 121]),
67
- [exports.Prefix.EDSK]: new Uint8Array([43, 246, 78, 7]),
68
- [exports.Prefix.EDSK2]: new Uint8Array([13, 15, 58, 7]),
69
- [exports.Prefix.SPSK]: new Uint8Array([17, 162, 224, 201]),
70
- [exports.Prefix.P2SK]: new Uint8Array([16, 81, 238, 189]),
71
- [exports.Prefix.BLSK]: new Uint8Array([3, 150, 192, 40]),
72
- [exports.Prefix.EDPK]: new Uint8Array([13, 15, 37, 217]),
73
- [exports.Prefix.SPPK]: new Uint8Array([3, 254, 226, 86]),
74
- [exports.Prefix.P2PK]: new Uint8Array([3, 178, 139, 127]),
75
- [exports.Prefix.BLPK]: new Uint8Array([6, 149, 135, 204]),
76
- [exports.Prefix.EDESK]: new Uint8Array([7, 90, 60, 179, 41]),
77
- [exports.Prefix.SPESK]: new Uint8Array([0x09, 0xed, 0xf1, 0xae, 0x96]),
78
- [exports.Prefix.P2ESK]: new Uint8Array([0x09, 0x30, 0x39, 0x73, 0xab]),
79
- [exports.Prefix.BLESK]: new Uint8Array([2, 5, 30, 53, 25]),
80
- [exports.Prefix.EDSIG]: new Uint8Array([9, 245, 205, 134, 18]),
81
- [exports.Prefix.SPSIG]: new Uint8Array([13, 115, 101, 19, 63]),
82
- [exports.Prefix.P2SIG]: new Uint8Array([54, 240, 44, 52]),
83
- [exports.Prefix.BLSIG]: new Uint8Array([40, 171, 64, 207]),
84
- [exports.Prefix.SIG]: new Uint8Array([4, 130, 43]),
85
- [exports.Prefix.NET]: new Uint8Array([87, 82, 0]),
86
- [exports.Prefix.NCE]: new Uint8Array([69, 220, 169]),
87
- [exports.Prefix.B]: new Uint8Array([1, 52]),
88
- [exports.Prefix.O]: new Uint8Array([5, 116]),
89
- [exports.Prefix.LO]: new Uint8Array([133, 233]),
90
- [exports.Prefix.LLO]: new Uint8Array([29, 159, 109]),
91
- [exports.Prefix.P]: new Uint8Array([2, 170]),
92
- [exports.Prefix.CO]: new Uint8Array([79, 179]),
93
- [exports.Prefix.ID]: new Uint8Array([153, 103]),
94
- [exports.Prefix.EXPR]: new Uint8Array([13, 44, 64, 27]),
95
- // Legacy prefix
96
- [exports.Prefix.TZ]: new Uint8Array([2, 90, 121]),
97
- [exports.Prefix.VH]: new Uint8Array([1, 106, 242]),
98
- [exports.Prefix.SASK]: new Uint8Array([11, 237, 20, 92]),
99
- [exports.Prefix.ZET1]: new Uint8Array([18, 71, 40, 223]),
100
- [exports.Prefix.SR1]: new Uint8Array([6, 124, 117]),
101
- [exports.Prefix.SRC1]: new Uint8Array([17, 165, 134, 138]),
102
- [exports.Prefix.SH]: new Uint8Array([2, 116, 180]),
290
+
291
+ function Buffer (arg, encodingOrOffset, length) {
292
+ if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
293
+ return new Buffer(arg, encodingOrOffset, length)
294
+ }
295
+
296
+ // Common case.
297
+ if (typeof arg === 'number') {
298
+ if (typeof encodingOrOffset === 'string') {
299
+ throw new Error(
300
+ 'If encoding is specified then the first argument must be a string'
301
+ )
302
+ }
303
+ return allocUnsafe(this, arg)
304
+ }
305
+ return from(this, arg, encodingOrOffset, length)
306
+ }
307
+
308
+ Buffer.poolSize = 8192; // not used by this implementation
309
+
310
+ // TODO: Legacy, not needed anymore. Remove in next major version.
311
+ Buffer._augment = function (arr) {
312
+ arr.__proto__ = Buffer.prototype;
313
+ return arr
103
314
  };
315
+
316
+ function from (that, value, encodingOrOffset, length) {
317
+ if (typeof value === 'number') {
318
+ throw new TypeError('"value" argument must not be a number')
319
+ }
320
+
321
+ if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
322
+ return fromArrayBuffer(that, value, encodingOrOffset, length)
323
+ }
324
+
325
+ if (typeof value === 'string') {
326
+ return fromString(that, value, encodingOrOffset)
327
+ }
328
+
329
+ return fromObject(that, value)
330
+ }
331
+
104
332
  /**
105
- * @deprecated use payloadLength instead this constant will be removed in the next minor release
106
- * @description base58 prefix to payload length mapping
107
- */
108
- const prefixLength = {
109
- [exports.Prefix.TZ1]: 20,
110
- [exports.Prefix.TZ2]: 20,
111
- [exports.Prefix.TZ3]: 20,
112
- [exports.Prefix.TZ4]: 20,
113
- [exports.Prefix.KT]: 20,
114
- [exports.Prefix.KT1]: 20,
115
- [exports.Prefix.EDPK]: 32,
116
- [exports.Prefix.SPPK]: 33,
117
- [exports.Prefix.P2PK]: 33,
118
- [exports.Prefix.BLPK]: 48,
119
- [exports.Prefix.EDSIG]: 64,
120
- [exports.Prefix.SPSIG]: 64,
121
- [exports.Prefix.P2SIG]: 64,
122
- [exports.Prefix.BLSIG]: 96,
123
- [exports.Prefix.SIG]: 64,
124
- [exports.Prefix.NET]: 4,
125
- [exports.Prefix.B]: 32,
126
- [exports.Prefix.P]: 32,
127
- [exports.Prefix.O]: 32,
128
- [exports.Prefix.VH]: 32,
129
- [exports.Prefix.SASK]: 169,
130
- [exports.Prefix.ZET1]: 43,
131
- [exports.Prefix.SR1]: 20,
132
- [exports.Prefix.SRC1]: 32,
133
- [exports.Prefix.SH]: 48,
333
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
334
+ * if value is a number.
335
+ * Buffer.from(str[, encoding])
336
+ * Buffer.from(array)
337
+ * Buffer.from(buffer)
338
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
339
+ **/
340
+ Buffer.from = function (value, encodingOrOffset, length) {
341
+ return from(null, value, encodingOrOffset, length)
134
342
  };
343
+
344
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
345
+ Buffer.prototype.__proto__ = Uint8Array.prototype;
346
+ Buffer.__proto__ = Uint8Array;
347
+ if (typeof Symbol !== 'undefined' && Symbol.species &&
348
+ Buffer[Symbol.species] === Buffer) ;
349
+ }
350
+
351
+ function assertSize (size) {
352
+ if (typeof size !== 'number') {
353
+ throw new TypeError('"size" argument must be a number')
354
+ } else if (size < 0) {
355
+ throw new RangeError('"size" argument must not be negative')
356
+ }
357
+ }
358
+
359
+ function alloc (that, size, fill, encoding) {
360
+ assertSize(size);
361
+ if (size <= 0) {
362
+ return createBuffer(that, size)
363
+ }
364
+ if (fill !== undefined) {
365
+ // Only pay attention to encoding if it's a string. This
366
+ // prevents accidentally sending in a number that would
367
+ // be interpretted as a start offset.
368
+ return typeof encoding === 'string'
369
+ ? createBuffer(that, size).fill(fill, encoding)
370
+ : createBuffer(that, size).fill(fill)
371
+ }
372
+ return createBuffer(that, size)
373
+ }
374
+
135
375
  /**
136
- * @description base58 name to prefix mapping
137
- */
138
- exports.PrefixV2 = void 0;
139
- (function (PrefixV2) {
140
- PrefixV2["BlockHash"] = "B";
141
- PrefixV2["OperationHash"] = "o";
142
- PrefixV2["OperationListHash"] = "Lo";
143
- PrefixV2["OperationListListHash"] = "LLo";
144
- PrefixV2["ProtocolHash"] = "P";
145
- PrefixV2["ContextHash"] = "Co";
146
- PrefixV2["BlockMetadataHash"] = "bm";
147
- PrefixV2["OperationMetadataHash"] = "r";
148
- PrefixV2["OperationMetadataListHash"] = "Lr";
149
- PrefixV2["OperationMetadataListListHash"] = "LLr";
150
- PrefixV2["Ed25519PublicKeyHash"] = "tz1";
151
- PrefixV2["Secp256k1PublicKeyHash"] = "tz2";
152
- PrefixV2["P256PublicKeyHash"] = "tz3";
153
- PrefixV2["ContractHash"] = "KT1";
154
- PrefixV2["BlindedPublicKeyHash"] = "btz1";
155
- PrefixV2["BLS12_381PublicKeyHash"] = "tz4";
156
- PrefixV2["TXRollupAddress"] = "txr1";
157
- PrefixV2["ZkRollupHash"] = "epx1";
158
- PrefixV2["ScRollupHash"] = "scr1";
159
- PrefixV2["SmartRollupHash"] = "sr1";
160
- PrefixV2["CryptoboxPublicKeyHash"] = "id";
161
- PrefixV2["Ed25519Seed"] = "edsk";
162
- PrefixV2["Ed25519PublicKey"] = "edpk";
163
- PrefixV2["Secp256k1SecretKey"] = "spsk";
164
- PrefixV2["P256SecretKey"] = "p2sk";
165
- PrefixV2["BLS12_381SecretKey"] = "BLsk";
166
- PrefixV2["ValueHash"] = "vh";
167
- PrefixV2["CycleNonce"] = "nce";
168
- PrefixV2["ScriptExpr"] = "expr";
169
- PrefixV2["InboxHash"] = "txi";
170
- PrefixV2["MessageHash"] = "txm";
171
- PrefixV2["CommitmentHash"] = "txc";
172
- PrefixV2["MessageResultHash"] = "txmr";
173
- PrefixV2["MessageResultListHash"] = "txM";
174
- PrefixV2["WithdrawListHash"] = "txw";
175
- PrefixV2["ScRollupStateHash"] = "scs1";
176
- PrefixV2["ScRollupCommitmentHash"] = "scc1";
177
- PrefixV2["SmartRollupStateHash"] = "srs1";
178
- PrefixV2["SmartRollupCommitmentHash"] = "src1";
179
- PrefixV2["Ed25519EncryptedSeed"] = "edesk";
180
- PrefixV2["Secp256k1EncryptedSecretKey"] = "spesk";
181
- PrefixV2["P256EncryptedSecretKey"] = "p2esk";
182
- PrefixV2["BLS12_381EncryptedSecretKey"] = "BLesk";
183
- PrefixV2["Secp256k1EncryptedScalar"] = "seesk";
184
- PrefixV2["Secp256k1PublicKey"] = "sppk";
185
- PrefixV2["P256PublicKey"] = "p2pk";
186
- PrefixV2["Secp256k1Scalar"] = "SSp";
187
- PrefixV2["Secp256k1Element"] = "GSp";
188
- PrefixV2["Ed25519SecretKey"] = "_edsk";
189
- PrefixV2["Ed25519Signature"] = "edsig";
190
- PrefixV2["Secp256k1Signature"] = "spsig1";
191
- PrefixV2["P256Signature"] = "p2sig";
192
- PrefixV2["GenericSignature"] = "sig";
193
- PrefixV2["ChainID"] = "Net";
194
- PrefixV2["SaplingSpendingKey"] = "sask";
195
- PrefixV2["EncryptedSaplingSpendingKey"] = "_sask";
196
- PrefixV2["SaplingAddress"] = "zet1";
197
- PrefixV2["GenericAggregateSignature"] = "asig";
198
- PrefixV2["BLS12_381Signature"] = "BLsig";
199
- PrefixV2["BLS12_381PublicKey"] = "BLpk";
200
- PrefixV2["SlotHeader"] = "sh";
201
- })(exports.PrefixV2 || (exports.PrefixV2 = {}));
376
+ * Creates a new filled Buffer instance.
377
+ * alloc(size[, fill[, encoding]])
378
+ **/
379
+ Buffer.alloc = function (size, fill, encoding) {
380
+ return alloc(null, size, fill, encoding)
381
+ };
382
+
383
+ function allocUnsafe (that, size) {
384
+ assertSize(size);
385
+ that = createBuffer(that, size < 0 ? 0 : checked(size) | 0);
386
+ if (!Buffer.TYPED_ARRAY_SUPPORT) {
387
+ for (var i = 0; i < size; ++i) {
388
+ that[i] = 0;
389
+ }
390
+ }
391
+ return that
392
+ }
393
+
202
394
  /**
203
- * @description base58 prefix to bytes mapping
204
- */
205
- const prefixV2 = {
206
- [exports.PrefixV2.BlockHash]: new Uint8Array([1, 52]),
207
- [exports.PrefixV2.OperationHash]: new Uint8Array([5, 116]),
208
- [exports.PrefixV2.OperationListHash]: new Uint8Array([133, 233]),
209
- [exports.PrefixV2.OperationListListHash]: new Uint8Array([29, 159, 109]),
210
- [exports.PrefixV2.ProtocolHash]: new Uint8Array([2, 170]),
211
- [exports.PrefixV2.ContextHash]: new Uint8Array([79, 199]),
212
- [exports.PrefixV2.BlockMetadataHash]: new Uint8Array([234, 249]),
213
- [exports.PrefixV2.OperationMetadataHash]: new Uint8Array([5, 183]),
214
- [exports.PrefixV2.OperationMetadataListHash]: new Uint8Array([134, 39]),
215
- [exports.PrefixV2.OperationMetadataListListHash]: new Uint8Array([29, 159, 182]),
216
- [exports.PrefixV2.Ed25519PublicKeyHash]: new Uint8Array([6, 161, 159]),
217
- [exports.PrefixV2.Secp256k1PublicKeyHash]: new Uint8Array([6, 161, 161]),
218
- [exports.PrefixV2.P256PublicKeyHash]: new Uint8Array([6, 161, 164]),
219
- [exports.PrefixV2.ContractHash]: new Uint8Array([2, 90, 121]),
220
- [exports.PrefixV2.BlindedPublicKeyHash]: new Uint8Array([1, 2, 49, 223]),
221
- [exports.PrefixV2.BLS12_381PublicKeyHash]: new Uint8Array([6, 161, 166]),
222
- [exports.PrefixV2.TXRollupAddress]: new Uint8Array([1, 128, 120, 31]),
223
- [exports.PrefixV2.ZkRollupHash]: new Uint8Array([1, 23, 224, 125]),
224
- [exports.PrefixV2.ScRollupHash]: new Uint8Array([1, 118, 132, 217]),
225
- [exports.PrefixV2.SmartRollupHash]: new Uint8Array([6, 124, 117]),
226
- [exports.PrefixV2.CryptoboxPublicKeyHash]: new Uint8Array([153, 103]),
227
- [exports.PrefixV2.Ed25519Seed]: new Uint8Array([13, 15, 58, 7]),
228
- [exports.PrefixV2.Ed25519PublicKey]: new Uint8Array([13, 15, 37, 217]),
229
- [exports.PrefixV2.Secp256k1SecretKey]: new Uint8Array([17, 162, 224, 201]),
230
- [exports.PrefixV2.P256SecretKey]: new Uint8Array([16, 81, 238, 189]),
231
- [exports.PrefixV2.BLS12_381SecretKey]: new Uint8Array([3, 150, 192, 40]),
232
- [exports.PrefixV2.ValueHash]: new Uint8Array([1, 106, 242]),
233
- [exports.PrefixV2.CycleNonce]: new Uint8Array([69, 220, 169]),
234
- [exports.PrefixV2.ScriptExpr]: new Uint8Array([13, 44, 64, 27]),
235
- [exports.PrefixV2.InboxHash]: new Uint8Array([79, 148, 196]),
236
- [exports.PrefixV2.MessageHash]: new Uint8Array([79, 149, 30]),
237
- [exports.PrefixV2.CommitmentHash]: new Uint8Array([79, 148, 17]),
238
- [exports.PrefixV2.MessageResultHash]: new Uint8Array([18, 7, 206, 87]),
239
- [exports.PrefixV2.MessageResultListHash]: new Uint8Array([79, 146, 82]),
240
- [exports.PrefixV2.WithdrawListHash]: new Uint8Array([79, 150, 72]),
241
- [exports.PrefixV2.ScRollupStateHash]: new Uint8Array([17, 144, 122, 202]),
242
- [exports.PrefixV2.ScRollupCommitmentHash]: new Uint8Array([17, 144, 21, 100]),
243
- [exports.PrefixV2.SmartRollupStateHash]: new Uint8Array([17, 165, 235, 240]),
244
- [exports.PrefixV2.SmartRollupCommitmentHash]: new Uint8Array([17, 165, 134, 138]),
245
- [exports.PrefixV2.Ed25519EncryptedSeed]: new Uint8Array([7, 90, 60, 179, 41]),
246
- [exports.PrefixV2.Secp256k1EncryptedSecretKey]: new Uint8Array([9, 237, 241, 174, 150]),
247
- [exports.PrefixV2.P256EncryptedSecretKey]: new Uint8Array([9, 48, 57, 115, 171]),
248
- [exports.PrefixV2.BLS12_381EncryptedSecretKey]: new Uint8Array([2, 5, 30, 53, 25]),
249
- [exports.PrefixV2.Secp256k1EncryptedScalar]: new Uint8Array([1, 131, 36, 86, 248]),
250
- [exports.PrefixV2.Secp256k1PublicKey]: new Uint8Array([3, 254, 226, 86]),
251
- [exports.PrefixV2.P256PublicKey]: new Uint8Array([3, 178, 139, 127]),
252
- [exports.PrefixV2.Secp256k1Scalar]: new Uint8Array([38, 248, 136]),
253
- [exports.PrefixV2.Secp256k1Element]: new Uint8Array([5, 92, 0]),
254
- [exports.PrefixV2.Ed25519SecretKey]: new Uint8Array([43, 246, 78, 7]),
255
- [exports.PrefixV2.Ed25519Signature]: new Uint8Array([9, 245, 205, 134, 18]),
256
- [exports.PrefixV2.Secp256k1Signature]: new Uint8Array([13, 115, 101, 19, 63]),
257
- [exports.PrefixV2.P256Signature]: new Uint8Array([54, 240, 44, 52]),
258
- [exports.PrefixV2.GenericSignature]: new Uint8Array([4, 130, 43]),
259
- [exports.PrefixV2.ChainID]: new Uint8Array([87, 82, 0]),
260
- [exports.PrefixV2.SaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
261
- [exports.PrefixV2.EncryptedSaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
262
- [exports.PrefixV2.SaplingAddress]: new Uint8Array([18, 71, 40, 223]),
263
- [exports.PrefixV2.GenericAggregateSignature]: new Uint8Array([2, 75, 234, 101]),
264
- [exports.PrefixV2.BLS12_381Signature]: new Uint8Array([40, 171, 64, 207]),
265
- [exports.PrefixV2.BLS12_381PublicKey]: new Uint8Array([6, 149, 135, 204]),
266
- [exports.PrefixV2.SlotHeader]: new Uint8Array([2, 116, 180]),
395
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
396
+ * */
397
+ Buffer.allocUnsafe = function (size) {
398
+ return allocUnsafe(null, size)
267
399
  };
268
400
  /**
269
- * @description base58 prefix to payload length mapping
401
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
270
402
  */
271
- const payloadLength = {
272
- [exports.PrefixV2.BlockHash]: 32,
273
- [exports.PrefixV2.OperationHash]: 32,
274
- [exports.PrefixV2.OperationListHash]: 32,
275
- [exports.PrefixV2.OperationListListHash]: 32,
276
- [exports.PrefixV2.ProtocolHash]: 32,
277
- [exports.PrefixV2.ContextHash]: 32,
278
- [exports.PrefixV2.BlockMetadataHash]: 32,
279
- [exports.PrefixV2.OperationMetadataHash]: 32,
280
- [exports.PrefixV2.OperationMetadataListHash]: 32,
281
- [exports.PrefixV2.OperationMetadataListListHash]: 32,
282
- [exports.PrefixV2.Ed25519PublicKeyHash]: 20,
283
- [exports.PrefixV2.Secp256k1PublicKeyHash]: 20,
284
- [exports.PrefixV2.P256PublicKeyHash]: 20,
285
- [exports.PrefixV2.ContractHash]: 20,
286
- [exports.PrefixV2.BlindedPublicKeyHash]: 20,
287
- [exports.PrefixV2.BLS12_381PublicKeyHash]: 20,
288
- [exports.PrefixV2.TXRollupAddress]: 20,
289
- [exports.PrefixV2.ZkRollupHash]: 20,
290
- [exports.PrefixV2.ScRollupHash]: 20,
291
- [exports.PrefixV2.SmartRollupHash]: 20,
292
- [exports.PrefixV2.CryptoboxPublicKeyHash]: 16,
293
- [exports.PrefixV2.Ed25519Seed]: 32,
294
- [exports.PrefixV2.Ed25519PublicKey]: 32,
295
- [exports.PrefixV2.Secp256k1SecretKey]: 32,
296
- [exports.PrefixV2.P256SecretKey]: 32,
297
- [exports.PrefixV2.BLS12_381SecretKey]: 32,
298
- [exports.PrefixV2.ValueHash]: 32,
299
- [exports.PrefixV2.CycleNonce]: 32,
300
- [exports.PrefixV2.ScriptExpr]: 32,
301
- [exports.PrefixV2.InboxHash]: 32,
302
- [exports.PrefixV2.MessageHash]: 32,
303
- [exports.PrefixV2.CommitmentHash]: 32,
304
- [exports.PrefixV2.MessageResultHash]: 32,
305
- [exports.PrefixV2.MessageResultListHash]: 32,
306
- [exports.PrefixV2.WithdrawListHash]: 32,
307
- [exports.PrefixV2.ScRollupStateHash]: 32,
308
- [exports.PrefixV2.ScRollupCommitmentHash]: 32,
309
- [exports.PrefixV2.SmartRollupStateHash]: 32,
310
- [exports.PrefixV2.SmartRollupCommitmentHash]: 32,
311
- [exports.PrefixV2.Ed25519EncryptedSeed]: 56,
312
- [exports.PrefixV2.Secp256k1EncryptedSecretKey]: 56,
313
- [exports.PrefixV2.P256EncryptedSecretKey]: 56,
314
- [exports.PrefixV2.BLS12_381EncryptedSecretKey]: 56,
315
- [exports.PrefixV2.Secp256k1EncryptedScalar]: 60,
316
- [exports.PrefixV2.Secp256k1PublicKey]: 33,
317
- [exports.PrefixV2.P256PublicKey]: 33,
318
- [exports.PrefixV2.Secp256k1Scalar]: 33,
319
- [exports.PrefixV2.Secp256k1Element]: 33,
320
- [exports.PrefixV2.Ed25519SecretKey]: 64,
321
- [exports.PrefixV2.Ed25519Signature]: 64,
322
- [exports.PrefixV2.Secp256k1Signature]: 64,
323
- [exports.PrefixV2.P256Signature]: 64,
324
- [exports.PrefixV2.GenericSignature]: 64,
325
- [exports.PrefixV2.ChainID]: 4,
326
- [exports.PrefixV2.SaplingSpendingKey]: 169,
327
- [exports.PrefixV2.EncryptedSaplingSpendingKey]: 193,
328
- [exports.PrefixV2.SaplingAddress]: 43,
329
- [exports.PrefixV2.GenericAggregateSignature]: 96,
330
- [exports.PrefixV2.BLS12_381Signature]: 96,
331
- [exports.PrefixV2.BLS12_381PublicKey]: 48,
332
- [exports.PrefixV2.SlotHeader]: 48,
403
+ Buffer.allocUnsafeSlow = function (size) {
404
+ return allocUnsafe(null, size)
333
405
  };
334
406
 
335
- /**
336
- * @description Used to check if a value has one of the allowed prefixes.
337
- * @returns true if the value has one of the allowed prefixes, false otherwise
338
- * @example
339
- * ```
340
- * import { isValidPrefixedValue } from '@taquito/utils';
341
- * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
342
- * const isValid = isValidPrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
343
- * console.log(isValid) // true
344
- * ```
345
- */
346
- function isValidPrefixedValue(value, prefixes) {
347
- return validatePrefixedValue(value, prefixes) === core.ValidationResult.VALID;
407
+ function fromString (that, string, encoding) {
408
+ if (typeof encoding !== 'string' || encoding === '') {
409
+ encoding = 'utf8';
410
+ }
411
+
412
+ if (!Buffer.isEncoding(encoding)) {
413
+ throw new TypeError('"encoding" must be a valid string encoding')
414
+ }
415
+
416
+ var length = byteLength(string, encoding) | 0;
417
+ that = createBuffer(that, length);
418
+
419
+ var actual = that.write(string, encoding);
420
+
421
+ if (actual !== length) {
422
+ // Writing a hex string, for example, that contains invalid characters will
423
+ // cause everything after the first invalid character to be ignored. (e.g.
424
+ // 'abxxcd' will be treated as 'ab')
425
+ that = that.slice(0, actual);
426
+ }
427
+
428
+ return that
348
429
  }
349
- /**
350
- * @description This function is called by the validation functions ([[validateAddress]], [[validateChain]], [[validateContractAddress]], [[validateKeyHash]], [[validateSignature]], [[validatePublicKey]]).
351
- * 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)
352
- * If all checks pass, return `3` (VALID).
353
- * @param value Value to validate
354
- * @param prefixes prefix the value should have
355
- * @returns 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
356
- * @example
357
- * ```
358
- * import { validatePrefixedValue } from '@taquito/utils';
359
- * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
360
- * const validation = validatePrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
361
- * console.log(validation) // 3
362
- * ```
363
- */
364
- function validatePrefixedValue(value, prefixes) {
365
- try {
366
- b58DecodeAndCheckPrefix(value, prefixes);
430
+
431
+ function fromArrayLike (that, array) {
432
+ var length = array.length < 0 ? 0 : checked(array.length) | 0;
433
+ that = createBuffer(that, length);
434
+ for (var i = 0; i < length; i += 1) {
435
+ that[i] = array[i] & 255;
436
+ }
437
+ return that
438
+ }
439
+
440
+ function fromArrayBuffer (that, array, byteOffset, length) {
441
+ array.byteLength; // this throws if `array` is not a valid ArrayBuffer
442
+
443
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
444
+ throw new RangeError('\'offset\' is out of bounds')
445
+ }
446
+
447
+ if (array.byteLength < byteOffset + (length || 0)) {
448
+ throw new RangeError('\'length\' is out of bounds')
449
+ }
450
+
451
+ if (byteOffset === undefined && length === undefined) {
452
+ array = new Uint8Array(array);
453
+ } else if (length === undefined) {
454
+ array = new Uint8Array(array, byteOffset);
455
+ } else {
456
+ array = new Uint8Array(array, byteOffset, length);
457
+ }
458
+
459
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
460
+ // Return an augmented `Uint8Array` instance, for best performance
461
+ that = array;
462
+ that.__proto__ = Buffer.prototype;
463
+ } else {
464
+ // Fallback: Return an object instance of the Buffer class
465
+ that = fromArrayLike(that, array);
466
+ }
467
+ return that
468
+ }
469
+
470
+ function fromObject (that, obj) {
471
+ if (internalIsBuffer(obj)) {
472
+ var len = checked(obj.length) | 0;
473
+ that = createBuffer(that, len);
474
+
475
+ if (that.length === 0) {
476
+ return that
367
477
  }
368
- catch (err) {
369
- if (err instanceof core.ParameterValidationError && err.result !== undefined) {
370
- return err.result;
371
- }
372
- return core.ValidationResult.OTHER;
478
+
479
+ obj.copy(that, 0, 0, len);
480
+ return that
481
+ }
482
+
483
+ if (obj) {
484
+ if ((typeof ArrayBuffer !== 'undefined' &&
485
+ obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
486
+ if (typeof obj.length !== 'number' || isnan(obj.length)) {
487
+ return createBuffer(that, 0)
488
+ }
489
+ return fromArrayLike(that, obj)
373
490
  }
374
- return core.ValidationResult.VALID;
491
+
492
+ if (obj.type === 'Buffer' && isArray(obj.data)) {
493
+ return fromArrayLike(that, obj.data)
494
+ }
495
+ }
496
+
497
+ throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
375
498
  }
376
- /**
377
- * @description Used to check if an address or a contract address is valid.
378
- *
379
- * @returns
380
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
381
- *
382
- * @example
383
- * ```
384
- * import { validateAddress } from '@taquito/utils';
385
- * const pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
386
- * const validation = validateAddress(pkh)
387
- * console.log(validation)
388
- * // This example return 3 which correspond to VALID
389
- * ```
390
- */
391
- function validateAddress(value) {
392
- const [addr] = splitAddress(value !== null && value !== void 0 ? value : '');
393
- return validatePrefixedValue(addr, addressPrefixes);
499
+
500
+ function checked (length) {
501
+ // Note: cannot use `length < kMaxLength()` here because that fails when
502
+ // length is NaN (which is otherwise coerced to zero.)
503
+ if (length >= kMaxLength()) {
504
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
505
+ 'size: 0x' + kMaxLength().toString(16) + ' bytes')
506
+ }
507
+ return length | 0
394
508
  }
395
- /**
396
- * @description Used to check if a chain id is valid.
397
- *
398
- * @returns
399
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
400
- *
401
- * @example
402
- * ```
403
- * import { validateChain } from '@taquito/utils';
404
- * const chainId = 'NetXdQprcVkpaWU'
405
- * const validation = validateChain(chainId)
406
- * console.log(validation)
407
- * // This example return 3 which correspond to VALID
408
- * ```
409
- */
410
- function validateChain(value) {
411
- return validatePrefixedValue(value, [exports.PrefixV2.ChainID]);
509
+ Buffer.isBuffer = isBuffer;
510
+ function internalIsBuffer (b) {
511
+ return !!(b != null && b._isBuffer)
412
512
  }
413
- /**
414
- * @description Used to check if a contract address is valid.
415
- *
416
- * @returns
417
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
418
- *
419
- * @example
420
- * ```
421
- * import { validateContractAddress } from '@taquito/utils';
422
- * const contractAddress = 'KT1JVErLYTgtY8uGGZ4mso2npTSxqVLDRVbC'
423
- * const validation = validateContractAddress(contractAddress)
424
- * console.log(validation)
425
- * // This example return 3 which correspond to VALID
426
- * ```
427
- */
428
- function validateContractAddress(value) {
429
- return validatePrefixedValue(value, [exports.PrefixV2.ContractHash]);
513
+
514
+ Buffer.compare = function compare (a, b) {
515
+ if (!internalIsBuffer(a) || !internalIsBuffer(b)) {
516
+ throw new TypeError('Arguments must be Buffers')
517
+ }
518
+
519
+ if (a === b) return 0
520
+
521
+ var x = a.length;
522
+ var y = b.length;
523
+
524
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
525
+ if (a[i] !== b[i]) {
526
+ x = a[i];
527
+ y = b[i];
528
+ break
529
+ }
530
+ }
531
+
532
+ if (x < y) return -1
533
+ if (y < x) return 1
534
+ return 0
535
+ };
536
+
537
+ Buffer.isEncoding = function isEncoding (encoding) {
538
+ switch (String(encoding).toLowerCase()) {
539
+ case 'hex':
540
+ case 'utf8':
541
+ case 'utf-8':
542
+ case 'ascii':
543
+ case 'latin1':
544
+ case 'binary':
545
+ case 'base64':
546
+ case 'ucs2':
547
+ case 'ucs-2':
548
+ case 'utf16le':
549
+ case 'utf-16le':
550
+ return true
551
+ default:
552
+ return false
553
+ }
554
+ };
555
+
556
+ Buffer.concat = function concat (list, length) {
557
+ if (!isArray(list)) {
558
+ throw new TypeError('"list" argument must be an Array of Buffers')
559
+ }
560
+
561
+ if (list.length === 0) {
562
+ return Buffer.alloc(0)
563
+ }
564
+
565
+ var i;
566
+ if (length === undefined) {
567
+ length = 0;
568
+ for (i = 0; i < list.length; ++i) {
569
+ length += list[i].length;
570
+ }
571
+ }
572
+
573
+ var buffer = Buffer.allocUnsafe(length);
574
+ var pos = 0;
575
+ for (i = 0; i < list.length; ++i) {
576
+ var buf = list[i];
577
+ if (!internalIsBuffer(buf)) {
578
+ throw new TypeError('"list" argument must be an Array of Buffers')
579
+ }
580
+ buf.copy(buffer, pos);
581
+ pos += buf.length;
582
+ }
583
+ return buffer
584
+ };
585
+
586
+ function byteLength (string, encoding) {
587
+ if (internalIsBuffer(string)) {
588
+ return string.length
589
+ }
590
+ if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
591
+ (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
592
+ return string.byteLength
593
+ }
594
+ if (typeof string !== 'string') {
595
+ string = '' + string;
596
+ }
597
+
598
+ var len = string.length;
599
+ if (len === 0) return 0
600
+
601
+ // Use a for loop to avoid recursion
602
+ var loweredCase = false;
603
+ for (;;) {
604
+ switch (encoding) {
605
+ case 'ascii':
606
+ case 'latin1':
607
+ case 'binary':
608
+ return len
609
+ case 'utf8':
610
+ case 'utf-8':
611
+ case undefined:
612
+ return utf8ToBytes(string).length
613
+ case 'ucs2':
614
+ case 'ucs-2':
615
+ case 'utf16le':
616
+ case 'utf-16le':
617
+ return len * 2
618
+ case 'hex':
619
+ return len >>> 1
620
+ case 'base64':
621
+ return base64ToBytes(string).length
622
+ default:
623
+ if (loweredCase) return utf8ToBytes(string).length // assume utf8
624
+ encoding = ('' + encoding).toLowerCase();
625
+ loweredCase = true;
626
+ }
627
+ }
430
628
  }
431
- /**
432
- * @description Used to check if a key hash is valid.
433
- *
434
- * @returns
435
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
436
- *
437
- * @example
438
- * ```
439
- * import { validateKeyHash } from '@taquito/utils';
440
- * const keyHashWithoutPrefix = '1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
441
- * const validation = validateKeyHash(keyHashWithoutPrefix)
442
- * console.log(validation)
443
- * // This example return 0 which correspond to NO_PREFIX_MATCHED
444
- * ```
445
- */
446
- function validateKeyHash(value) {
447
- return validatePrefixedValue(value, publicKeyHashPrefixes);
629
+ Buffer.byteLength = byteLength;
630
+
631
+ function slowToString (encoding, start, end) {
632
+ var loweredCase = false;
633
+
634
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
635
+ // property of a typed array.
636
+
637
+ // This behaves neither like String nor Uint8Array in that we set start/end
638
+ // to their upper/lower bounds if the value passed is out of range.
639
+ // undefined is handled specially as per ECMA-262 6th Edition,
640
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
641
+ if (start === undefined || start < 0) {
642
+ start = 0;
643
+ }
644
+ // Return early if start > this.length. Done here to prevent potential uint32
645
+ // coercion fail below.
646
+ if (start > this.length) {
647
+ return ''
648
+ }
649
+
650
+ if (end === undefined || end > this.length) {
651
+ end = this.length;
652
+ }
653
+
654
+ if (end <= 0) {
655
+ return ''
656
+ }
657
+
658
+ // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
659
+ end >>>= 0;
660
+ start >>>= 0;
661
+
662
+ if (end <= start) {
663
+ return ''
664
+ }
665
+
666
+ if (!encoding) encoding = 'utf8';
667
+
668
+ while (true) {
669
+ switch (encoding) {
670
+ case 'hex':
671
+ return hexSlice(this, start, end)
672
+
673
+ case 'utf8':
674
+ case 'utf-8':
675
+ return utf8Slice(this, start, end)
676
+
677
+ case 'ascii':
678
+ return asciiSlice(this, start, end)
679
+
680
+ case 'latin1':
681
+ case 'binary':
682
+ return latin1Slice(this, start, end)
683
+
684
+ case 'base64':
685
+ return base64Slice(this, start, end)
686
+
687
+ case 'ucs2':
688
+ case 'ucs-2':
689
+ case 'utf16le':
690
+ case 'utf-16le':
691
+ return utf16leSlice(this, start, end)
692
+
693
+ default:
694
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
695
+ encoding = (encoding + '').toLowerCase();
696
+ loweredCase = true;
697
+ }
698
+ }
448
699
  }
449
- /**
450
- * @description Used to check if a signature is valid.
451
- *
452
- * @returns
453
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
454
- *
455
- * @example
456
- * ```
457
- * import { validateSignature } from '@taquito/utils';
458
- * const signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg'
459
- * const validation = validateSignature(signature)
460
- * console.log(validation)
461
- * // This example return 3 which correspond to VALID
462
- * ```
463
- */
464
- function validateSignature(value) {
465
- return validatePrefixedValue(value, signaturePrefixes);
700
+
701
+ // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
702
+ // Buffer instances.
703
+ Buffer.prototype._isBuffer = true;
704
+
705
+ function swap (b, n, m) {
706
+ var i = b[n];
707
+ b[n] = b[m];
708
+ b[m] = i;
466
709
  }
467
- /**
468
- * @description Used to check if a public key is valid.
469
- *
470
- * @returns
471
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
472
- *
473
- * @example
474
- * ```
475
- * import { validatePublicKey } from '@taquito/utils';
476
- * const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g'
477
- * const validation = validatePublicKey(publicKey)
478
- * console.log(validation)
479
- * // This example return 3 which correspond to VALID
480
- * ```
481
- */
482
- function validatePublicKey(value) {
483
- return validatePrefixedValue(value, publicKeyPrefixes);
710
+
711
+ Buffer.prototype.swap16 = function swap16 () {
712
+ var len = this.length;
713
+ if (len % 2 !== 0) {
714
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
715
+ }
716
+ for (var i = 0; i < len; i += 2) {
717
+ swap(this, i, i + 1);
718
+ }
719
+ return this
720
+ };
721
+
722
+ Buffer.prototype.swap32 = function swap32 () {
723
+ var len = this.length;
724
+ if (len % 4 !== 0) {
725
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
726
+ }
727
+ for (var i = 0; i < len; i += 4) {
728
+ swap(this, i, i + 3);
729
+ swap(this, i + 1, i + 2);
730
+ }
731
+ return this
732
+ };
733
+
734
+ Buffer.prototype.swap64 = function swap64 () {
735
+ var len = this.length;
736
+ if (len % 8 !== 0) {
737
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
738
+ }
739
+ for (var i = 0; i < len; i += 8) {
740
+ swap(this, i, i + 7);
741
+ swap(this, i + 1, i + 6);
742
+ swap(this, i + 2, i + 5);
743
+ swap(this, i + 3, i + 4);
744
+ }
745
+ return this
746
+ };
747
+
748
+ Buffer.prototype.toString = function toString () {
749
+ var length = this.length | 0;
750
+ if (length === 0) return ''
751
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
752
+ return slowToString.apply(this, arguments)
753
+ };
754
+
755
+ Buffer.prototype.equals = function equals (b) {
756
+ if (!internalIsBuffer(b)) throw new TypeError('Argument must be a Buffer')
757
+ if (this === b) return true
758
+ return Buffer.compare(this, b) === 0
759
+ };
760
+
761
+ Buffer.prototype.inspect = function inspect () {
762
+ var str = '';
763
+ var max = INSPECT_MAX_BYTES;
764
+ if (this.length > 0) {
765
+ str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
766
+ if (this.length > max) str += ' ... ';
767
+ }
768
+ return '<Buffer ' + str + '>'
769
+ };
770
+
771
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
772
+ if (!internalIsBuffer(target)) {
773
+ throw new TypeError('Argument must be a Buffer')
774
+ }
775
+
776
+ if (start === undefined) {
777
+ start = 0;
778
+ }
779
+ if (end === undefined) {
780
+ end = target ? target.length : 0;
781
+ }
782
+ if (thisStart === undefined) {
783
+ thisStart = 0;
784
+ }
785
+ if (thisEnd === undefined) {
786
+ thisEnd = this.length;
787
+ }
788
+
789
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
790
+ throw new RangeError('out of range index')
791
+ }
792
+
793
+ if (thisStart >= thisEnd && start >= end) {
794
+ return 0
795
+ }
796
+ if (thisStart >= thisEnd) {
797
+ return -1
798
+ }
799
+ if (start >= end) {
800
+ return 1
801
+ }
802
+
803
+ start >>>= 0;
804
+ end >>>= 0;
805
+ thisStart >>>= 0;
806
+ thisEnd >>>= 0;
807
+
808
+ if (this === target) return 0
809
+
810
+ var x = thisEnd - thisStart;
811
+ var y = end - start;
812
+ var len = Math.min(x, y);
813
+
814
+ var thisCopy = this.slice(thisStart, thisEnd);
815
+ var targetCopy = target.slice(start, end);
816
+
817
+ for (var i = 0; i < len; ++i) {
818
+ if (thisCopy[i] !== targetCopy[i]) {
819
+ x = thisCopy[i];
820
+ y = targetCopy[i];
821
+ break
822
+ }
823
+ }
824
+
825
+ if (x < y) return -1
826
+ if (y < x) return 1
827
+ return 0
828
+ };
829
+
830
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
831
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
832
+ //
833
+ // Arguments:
834
+ // - buffer - a Buffer to search
835
+ // - val - a string, Buffer, or number
836
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
837
+ // - encoding - an optional encoding, relevant is val is a string
838
+ // - dir - true for indexOf, false for lastIndexOf
839
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
840
+ // Empty buffer means no match
841
+ if (buffer.length === 0) return -1
842
+
843
+ // Normalize byteOffset
844
+ if (typeof byteOffset === 'string') {
845
+ encoding = byteOffset;
846
+ byteOffset = 0;
847
+ } else if (byteOffset > 0x7fffffff) {
848
+ byteOffset = 0x7fffffff;
849
+ } else if (byteOffset < -2147483648) {
850
+ byteOffset = -2147483648;
851
+ }
852
+ byteOffset = +byteOffset; // Coerce to Number.
853
+ if (isNaN(byteOffset)) {
854
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
855
+ byteOffset = dir ? 0 : (buffer.length - 1);
856
+ }
857
+
858
+ // Normalize byteOffset: negative offsets start from the end of the buffer
859
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
860
+ if (byteOffset >= buffer.length) {
861
+ if (dir) return -1
862
+ else byteOffset = buffer.length - 1;
863
+ } else if (byteOffset < 0) {
864
+ if (dir) byteOffset = 0;
865
+ else return -1
866
+ }
867
+
868
+ // Normalize val
869
+ if (typeof val === 'string') {
870
+ val = Buffer.from(val, encoding);
871
+ }
872
+
873
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
874
+ if (internalIsBuffer(val)) {
875
+ // Special case: looking for empty string/buffer always fails
876
+ if (val.length === 0) {
877
+ return -1
878
+ }
879
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
880
+ } else if (typeof val === 'number') {
881
+ val = val & 0xFF; // Search for a byte value [0-255]
882
+ if (Buffer.TYPED_ARRAY_SUPPORT &&
883
+ typeof Uint8Array.prototype.indexOf === 'function') {
884
+ if (dir) {
885
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
886
+ } else {
887
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
888
+ }
889
+ }
890
+ return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
891
+ }
892
+
893
+ throw new TypeError('val must be string, number or Buffer')
484
894
  }
485
- /**
486
- * @description Used to check if an operation hash is valid.
487
- *
488
- * @returns
489
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
490
- *
491
- * @example
492
- * ```
493
- * import { validateOperation } from '@taquito/utils';
494
- * const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
495
- * const validation = validateOperation(operationHash)
496
- * console.log(validation)
497
- * // This example return 3 which correspond to VALID
498
- * ```
499
- */
500
- function validateOperation(value) {
501
- return validatePrefixedValue(value, [exports.PrefixV2.OperationHash]);
895
+
896
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
897
+ var indexSize = 1;
898
+ var arrLength = arr.length;
899
+ var valLength = val.length;
900
+
901
+ if (encoding !== undefined) {
902
+ encoding = String(encoding).toLowerCase();
903
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
904
+ encoding === 'utf16le' || encoding === 'utf-16le') {
905
+ if (arr.length < 2 || val.length < 2) {
906
+ return -1
907
+ }
908
+ indexSize = 2;
909
+ arrLength /= 2;
910
+ valLength /= 2;
911
+ byteOffset /= 2;
912
+ }
913
+ }
914
+
915
+ function read (buf, i) {
916
+ if (indexSize === 1) {
917
+ return buf[i]
918
+ } else {
919
+ return buf.readUInt16BE(i * indexSize)
920
+ }
921
+ }
922
+
923
+ var i;
924
+ if (dir) {
925
+ var foundIndex = -1;
926
+ for (i = byteOffset; i < arrLength; i++) {
927
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
928
+ if (foundIndex === -1) foundIndex = i;
929
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
930
+ } else {
931
+ if (foundIndex !== -1) i -= i - foundIndex;
932
+ foundIndex = -1;
933
+ }
934
+ }
935
+ } else {
936
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
937
+ for (i = byteOffset; i >= 0; i--) {
938
+ var found = true;
939
+ for (var j = 0; j < valLength; j++) {
940
+ if (read(arr, i + j) !== read(val, j)) {
941
+ found = false;
942
+ break
943
+ }
944
+ }
945
+ if (found) return i
946
+ }
947
+ }
948
+
949
+ return -1
502
950
  }
503
- /**
504
- * @description Used to check if a protocol hash is valid.
505
- *
506
- * @returns
507
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
508
- *
509
- * @example
510
- * ```
511
- * import { validateProtocol } from '@taquito/utils';
512
- * const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
513
- * const validation = validateProtocol(protocolHash)
514
- * console.log(validation)
515
- * // This example return 3 which correspond to VALID
516
- * ```
517
- */
518
- function validateProtocol(value) {
519
- return validatePrefixedValue(value, [exports.PrefixV2.ProtocolHash]);
951
+
952
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
953
+ return this.indexOf(val, byteOffset, encoding) !== -1
954
+ };
955
+
956
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
957
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
958
+ };
959
+
960
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
961
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
962
+ };
963
+
964
+ function hexWrite (buf, string, offset, length) {
965
+ offset = Number(offset) || 0;
966
+ var remaining = buf.length - offset;
967
+ if (!length) {
968
+ length = remaining;
969
+ } else {
970
+ length = Number(length);
971
+ if (length > remaining) {
972
+ length = remaining;
973
+ }
974
+ }
975
+
976
+ // must be an even number of digits
977
+ var strLen = string.length;
978
+ if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
979
+
980
+ if (length > strLen / 2) {
981
+ length = strLen / 2;
982
+ }
983
+ for (var i = 0; i < length; ++i) {
984
+ var parsed = parseInt(string.substr(i * 2, 2), 16);
985
+ if (isNaN(parsed)) return i
986
+ buf[offset + i] = parsed;
987
+ }
988
+ return i
520
989
  }
521
- /**
522
- * @description Used to check if a block hash is valid.
523
- *
524
- * @returns
525
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
526
- *
527
- * @example
528
- * ```
529
- * import { validateBlock } from '@taquito/utils';
530
- * const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
531
- * const validation = validateBlock(blockHash)
532
- * console.log(validation)
533
- * // This example return 3 which correspond to VALID
534
- * ```
535
- */
536
- function validateBlock(value) {
537
- return validatePrefixedValue(value, [exports.PrefixV2.BlockHash]);
990
+
991
+ function utf8Write (buf, string, offset, length) {
992
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
538
993
  }
539
- /**
540
- * @deprecated this function will be removed in the next minor release
541
- * @description generates a readable error string from a validation result
542
- */
543
- function invalidDetail(validation) {
544
- switch (validation) {
545
- case core.ValidationResult.NO_PREFIX_MATCHED:
546
- return 'with unsupported prefix';
547
- case core.ValidationResult.INVALID_CHECKSUM:
548
- return 'failed checksum';
549
- case core.ValidationResult.INVALID_LENGTH:
550
- return 'with incorrect length';
551
- default:
552
- return '';
553
- }
994
+
995
+ function asciiWrite (buf, string, offset, length) {
996
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
554
997
  }
555
- /**
556
- * @description Used to check if a spending key is valid.
557
- * @returns
558
- * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
559
- *
560
- */
561
- function validateSpendingKey(value) {
562
- return validatePrefixedValue(value, [exports.PrefixV2.SaplingSpendingKey]);
998
+
999
+ function latin1Write (buf, string, offset, length) {
1000
+ return asciiWrite(buf, string, offset, length)
563
1001
  }
564
- function validateSmartRollupAddress(value) {
565
- return validatePrefixedValue(value, [exports.PrefixV2.SmartRollupHash]);
1002
+
1003
+ function base64Write (buf, string, offset, length) {
1004
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
566
1005
  }
567
1006
 
568
- // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
569
- const VERSION = {
570
- "commitHash": "42048d039f6d4345fc59d04b03650bcb8e27bb62",
571
- "version": "23.0.3"
1007
+ function ucs2Write (buf, string, offset, length) {
1008
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1009
+ }
1010
+
1011
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
1012
+ // Buffer#write(string)
1013
+ if (offset === undefined) {
1014
+ encoding = 'utf8';
1015
+ length = this.length;
1016
+ offset = 0;
1017
+ // Buffer#write(string, encoding)
1018
+ } else if (length === undefined && typeof offset === 'string') {
1019
+ encoding = offset;
1020
+ length = this.length;
1021
+ offset = 0;
1022
+ // Buffer#write(string, offset[, length][, encoding])
1023
+ } else if (isFinite(offset)) {
1024
+ offset = offset | 0;
1025
+ if (isFinite(length)) {
1026
+ length = length | 0;
1027
+ if (encoding === undefined) encoding = 'utf8';
1028
+ } else {
1029
+ encoding = length;
1030
+ length = undefined;
1031
+ }
1032
+ // legacy write(string, encoding, offset, length) - remove in v0.13
1033
+ } else {
1034
+ throw new Error(
1035
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1036
+ )
1037
+ }
1038
+
1039
+ var remaining = this.length - offset;
1040
+ if (length === undefined || length > remaining) length = remaining;
1041
+
1042
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1043
+ throw new RangeError('Attempt to write outside buffer bounds')
1044
+ }
1045
+
1046
+ if (!encoding) encoding = 'utf8';
1047
+
1048
+ var loweredCase = false;
1049
+ for (;;) {
1050
+ switch (encoding) {
1051
+ case 'hex':
1052
+ return hexWrite(this, string, offset, length)
1053
+
1054
+ case 'utf8':
1055
+ case 'utf-8':
1056
+ return utf8Write(this, string, offset, length)
1057
+
1058
+ case 'ascii':
1059
+ return asciiWrite(this, string, offset, length)
1060
+
1061
+ case 'latin1':
1062
+ case 'binary':
1063
+ return latin1Write(this, string, offset, length)
1064
+
1065
+ case 'base64':
1066
+ // Warning: maxLength not taken into account in base64Write
1067
+ return base64Write(this, string, offset, length)
1068
+
1069
+ case 'ucs2':
1070
+ case 'ucs-2':
1071
+ case 'utf16le':
1072
+ case 'utf-16le':
1073
+ return ucs2Write(this, string, offset, length)
1074
+
1075
+ default:
1076
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1077
+ encoding = ('' + encoding).toLowerCase();
1078
+ loweredCase = true;
1079
+ }
1080
+ }
572
1081
  };
573
1082
 
574
- const BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
575
- const POP_DST = 'BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
576
- /**
577
- * @description Verify signature of a payload
578
- * @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
579
- * @param publicKey The public key to verify the signature against
580
- * @param signature The signature to verify
581
- * @param watermark Optional if not included in the message
582
- * @param pop Optional if verifying proof of possession signature
583
- * @returns A boolean indicating if the signature matches
584
- * @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
585
- * @example
586
- * ```
587
- * const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
588
- * const pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';
589
- * const sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'
590
- *
591
- * const response = verifySignature(message, pk, sig);
592
- * ```
593
- *
594
- */
595
- function verifySignature(message, publicKey, signature, watermark, pop) {
596
- const [pk, pre] = (() => {
597
- try {
598
- return b58DecodeAndCheckPrefix(publicKey, publicKeyPrefixes);
599
- }
600
- catch (err) {
601
- if (err instanceof core.ParameterValidationError) {
602
- throw new core.InvalidPublicKeyError(publicKey, err.result);
603
- }
604
- else {
605
- throw err;
1083
+ Buffer.prototype.toJSON = function toJSON () {
1084
+ return {
1085
+ type: 'Buffer',
1086
+ data: Array.prototype.slice.call(this._arr || this, 0)
1087
+ }
1088
+ };
1089
+
1090
+ function base64Slice (buf, start, end) {
1091
+ if (start === 0 && end === buf.length) {
1092
+ return fromByteArray(buf)
1093
+ } else {
1094
+ return fromByteArray(buf.slice(start, end))
1095
+ }
1096
+ }
1097
+
1098
+ function utf8Slice (buf, start, end) {
1099
+ end = Math.min(buf.length, end);
1100
+ var res = [];
1101
+
1102
+ var i = start;
1103
+ while (i < end) {
1104
+ var firstByte = buf[i];
1105
+ var codePoint = null;
1106
+ var bytesPerSequence = (firstByte > 0xEF) ? 4
1107
+ : (firstByte > 0xDF) ? 3
1108
+ : (firstByte > 0xBF) ? 2
1109
+ : 1;
1110
+
1111
+ if (i + bytesPerSequence <= end) {
1112
+ var secondByte, thirdByte, fourthByte, tempCodePoint;
1113
+
1114
+ switch (bytesPerSequence) {
1115
+ case 1:
1116
+ if (firstByte < 0x80) {
1117
+ codePoint = firstByte;
1118
+ }
1119
+ break
1120
+ case 2:
1121
+ secondByte = buf[i + 1];
1122
+ if ((secondByte & 0xC0) === 0x80) {
1123
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1124
+ if (tempCodePoint > 0x7F) {
1125
+ codePoint = tempCodePoint;
606
1126
  }
607
- }
608
- })();
609
- const sig = (() => {
610
- try {
611
- const [sig] = b58DecodeAndCheckPrefix(signature, signaturePrefixes);
612
- return sig;
613
- }
614
- catch (err) {
615
- if (err instanceof core.ParameterValidationError) {
616
- throw new core.InvalidSignatureError(signature, err.result);
1127
+ }
1128
+ break
1129
+ case 3:
1130
+ secondByte = buf[i + 1];
1131
+ thirdByte = buf[i + 2];
1132
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1133
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1134
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1135
+ codePoint = tempCodePoint;
617
1136
  }
618
- else {
619
- throw err;
1137
+ }
1138
+ break
1139
+ case 4:
1140
+ secondByte = buf[i + 1];
1141
+ thirdByte = buf[i + 2];
1142
+ fourthByte = buf[i + 3];
1143
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1144
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1145
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1146
+ codePoint = tempCodePoint;
620
1147
  }
621
- }
622
- })();
623
- let msg;
624
- if (typeof message === 'string') {
625
- msg = hex2buf(message);
626
- }
627
- else {
628
- msg = message;
629
- }
630
- if (msg.length === 0) {
631
- throw new core.InvalidMessageError(buf2hex(msg), `can't be empty`);
632
- }
633
- if (typeof watermark !== 'undefined') {
634
- msg = mergebuf(watermark, msg);
635
- }
636
- if (pop) {
637
- return verifyBLSPopSignature(sig, msg, pk);
638
- }
639
- else {
640
- switch (pre) {
641
- case exports.PrefixV2.P256PublicKey:
642
- return verifyP2Signature(sig, msg, pk);
643
- case exports.PrefixV2.Secp256k1PublicKey:
644
- return verifySpSignature(sig, msg, pk);
645
- case exports.PrefixV2.Ed25519PublicKey:
646
- return verifyEdSignature(sig, msg, pk);
647
- default:
648
- return verifyBLSSignature(sig, msg, pk);
649
- }
650
- }
651
- }
652
- /**
653
- * @deprecated use b58DecodeAndCheckPrefix instead, this function will be removed in the next minor release
654
- * @description validates a public key and extracts the prefix
655
- */
656
- function validatePkAndExtractPrefix(publicKey) {
657
- if (publicKey === '') {
658
- throw new core.InvalidPublicKeyError(publicKey, `can't be empty`);
659
- }
660
- const pkPrefix = publicKey.substring(0, 4);
661
- const publicKeyValidation = validatePublicKey(publicKey);
662
- if (publicKeyValidation !== core.ValidationResult.VALID) {
663
- throw new core.InvalidPublicKeyError(publicKey, invalidDetail(publicKeyValidation));
664
- }
665
- return pkPrefix;
666
- }
667
- function verifyEdSignature(sig, msg, publicKey) {
668
- const hash = blake2b.hash(msg, 32);
669
- try {
670
- return ed25519.verify(publicKey, hash, sig);
1148
+ }
1149
+ }
671
1150
  }
672
- catch (_a) {
673
- return false;
1151
+
1152
+ if (codePoint === null) {
1153
+ // we did not generate a valid codePoint so insert a
1154
+ // replacement char (U+FFFD) and advance only 1 byte
1155
+ codePoint = 0xFFFD;
1156
+ bytesPerSequence = 1;
1157
+ } else if (codePoint > 0xFFFF) {
1158
+ // encode to utf16 (surrogate pair dance)
1159
+ codePoint -= 0x10000;
1160
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1161
+ codePoint = 0xDC00 | codePoint & 0x3FF;
674
1162
  }
1163
+
1164
+ res.push(codePoint);
1165
+ i += bytesPerSequence;
1166
+ }
1167
+
1168
+ return decodeCodePointsArray(res)
675
1169
  }
676
- function verifySpSignature(sig, msg, publicKey) {
677
- const key = new elliptic.ec('secp256k1').keyFromPublic(publicKey);
678
- return verifySpOrP2Sig(sig, msg, key);
1170
+
1171
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1172
+ // the lowest limit is Chrome, with 0x10000 args.
1173
+ // We go 1 magnitude less, for safety
1174
+ var MAX_ARGUMENTS_LENGTH = 0x1000;
1175
+
1176
+ function decodeCodePointsArray (codePoints) {
1177
+ var len = codePoints.length;
1178
+ if (len <= MAX_ARGUMENTS_LENGTH) {
1179
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1180
+ }
1181
+
1182
+ // Decode in chunks to avoid "call stack size exceeded".
1183
+ var res = '';
1184
+ var i = 0;
1185
+ while (i < len) {
1186
+ res += String.fromCharCode.apply(
1187
+ String,
1188
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1189
+ );
1190
+ }
1191
+ return res
679
1192
  }
680
- function verifyP2Signature(sig, msg, publicKey) {
681
- const key = new elliptic.ec('p256').keyFromPublic(publicKey);
682
- return verifySpOrP2Sig(sig, msg, key);
1193
+
1194
+ function asciiSlice (buf, start, end) {
1195
+ var ret = '';
1196
+ end = Math.min(buf.length, end);
1197
+
1198
+ for (var i = start; i < end; ++i) {
1199
+ ret += String.fromCharCode(buf[i] & 0x7F);
1200
+ }
1201
+ return ret
683
1202
  }
684
- function verifySpOrP2Sig(sig, msg, key) {
685
- const r = sig.slice(0, 32);
686
- const s = sig.slice(32);
687
- const hash = blake2b.hash(msg, 32);
688
- try {
689
- return key.verify(hash, { r, s });
690
- }
691
- catch (_a) {
692
- return false;
693
- }
1203
+
1204
+ function latin1Slice (buf, start, end) {
1205
+ var ret = '';
1206
+ end = Math.min(buf.length, end);
1207
+
1208
+ for (var i = start; i < end; ++i) {
1209
+ ret += String.fromCharCode(buf[i]);
1210
+ }
1211
+ return ret
694
1212
  }
695
- const bls = bls12381.bls12_381.longSignatures; // AKA MinPK
696
- function verifyBLSSignature(sig, msg, publicKey) {
697
- try {
698
- const point = bls.hash(msg, BLS12_381_DST);
699
- return bls.verify(sig, point, publicKey);
700
- }
701
- catch (_a) {
702
- return false;
703
- }
1213
+
1214
+ function hexSlice (buf, start, end) {
1215
+ var len = buf.length;
1216
+
1217
+ if (!start || start < 0) start = 0;
1218
+ if (!end || end < 0 || end > len) end = len;
1219
+
1220
+ var out = '';
1221
+ for (var i = start; i < end; ++i) {
1222
+ out += toHex(buf[i]);
1223
+ }
1224
+ return out
704
1225
  }
705
- function verifyBLSPopSignature(sig, msg, publicKey) {
706
- try {
707
- const point = bls.hash(msg, POP_DST);
708
- return bls.verify(sig, point, publicKey);
709
- }
710
- catch (_a) {
711
- return false;
712
- }
1226
+
1227
+ function utf16leSlice (buf, start, end) {
1228
+ var bytes = buf.slice(start, end);
1229
+ var res = '';
1230
+ for (var i = 0; i < bytes.length; i += 2) {
1231
+ res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
1232
+ }
1233
+ return res
713
1234
  }
714
1235
 
715
- /**
716
- * @category Error
717
- * @description Error that indicates invalid protocol hash being passed or used
1236
+ Buffer.prototype.slice = function slice (start, end) {
1237
+ var len = this.length;
1238
+ start = ~~start;
1239
+ end = end === undefined ? len : ~~end;
1240
+
1241
+ if (start < 0) {
1242
+ start += len;
1243
+ if (start < 0) start = 0;
1244
+ } else if (start > len) {
1245
+ start = len;
1246
+ }
1247
+
1248
+ if (end < 0) {
1249
+ end += len;
1250
+ if (end < 0) end = 0;
1251
+ } else if (end > len) {
1252
+ end = len;
1253
+ }
1254
+
1255
+ if (end < start) end = start;
1256
+
1257
+ var newBuf;
1258
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1259
+ newBuf = this.subarray(start, end);
1260
+ newBuf.__proto__ = Buffer.prototype;
1261
+ } else {
1262
+ var sliceLen = end - start;
1263
+ newBuf = new Buffer(sliceLen, undefined);
1264
+ for (var i = 0; i < sliceLen; ++i) {
1265
+ newBuf[i] = this[i + start];
1266
+ }
1267
+ }
1268
+
1269
+ return newBuf
1270
+ };
1271
+
1272
+ /*
1273
+ * Need to make sure that buffer isn't trying to write out of bounds.
718
1274
  */
719
- class InvalidProtocolHashError extends core.ParameterValidationError {
720
- constructor(protocolHash, errorDetails) {
721
- super(`The protocol hash '${protocolHash}' is invalid`, errorDetails);
722
- this.protocolHash = protocolHash;
723
- this.name = 'InvalidProtocolHashError';
724
- this.name = this.constructor.name;
725
- }
1275
+ function checkOffset (offset, ext, length) {
1276
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1277
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
726
1278
  }
727
- /**
728
- * @category Error
729
- * @description Error that indicates unable to convert data type from one to another
730
- */
731
- class ValueConversionError extends core.UnsupportedActionError {
732
- constructor(value, desiredType) {
733
- super(`Unable to convert ${value} to a ${desiredType}`);
734
- this.value = value;
735
- this.desiredType = desiredType;
736
- this.name = this.constructor.name;
737
- }
1279
+
1280
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1281
+ offset = offset | 0;
1282
+ byteLength = byteLength | 0;
1283
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1284
+
1285
+ var val = this[offset];
1286
+ var mul = 1;
1287
+ var i = 0;
1288
+ while (++i < byteLength && (mul *= 0x100)) {
1289
+ val += this[offset + i] * mul;
1290
+ }
1291
+
1292
+ return val
1293
+ };
1294
+
1295
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1296
+ offset = offset | 0;
1297
+ byteLength = byteLength | 0;
1298
+ if (!noAssert) {
1299
+ checkOffset(offset, byteLength, this.length);
1300
+ }
1301
+
1302
+ var val = this[offset + --byteLength];
1303
+ var mul = 1;
1304
+ while (byteLength > 0 && (mul *= 0x100)) {
1305
+ val += this[offset + --byteLength] * mul;
1306
+ }
1307
+
1308
+ return val
1309
+ };
1310
+
1311
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1312
+ if (!noAssert) checkOffset(offset, 1, this.length);
1313
+ return this[offset]
1314
+ };
1315
+
1316
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1317
+ if (!noAssert) checkOffset(offset, 2, this.length);
1318
+ return this[offset] | (this[offset + 1] << 8)
1319
+ };
1320
+
1321
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1322
+ if (!noAssert) checkOffset(offset, 2, this.length);
1323
+ return (this[offset] << 8) | this[offset + 1]
1324
+ };
1325
+
1326
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1327
+ if (!noAssert) checkOffset(offset, 4, this.length);
1328
+
1329
+ return ((this[offset]) |
1330
+ (this[offset + 1] << 8) |
1331
+ (this[offset + 2] << 16)) +
1332
+ (this[offset + 3] * 0x1000000)
1333
+ };
1334
+
1335
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1336
+ if (!noAssert) checkOffset(offset, 4, this.length);
1337
+
1338
+ return (this[offset] * 0x1000000) +
1339
+ ((this[offset + 1] << 16) |
1340
+ (this[offset + 2] << 8) |
1341
+ this[offset + 3])
1342
+ };
1343
+
1344
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1345
+ offset = offset | 0;
1346
+ byteLength = byteLength | 0;
1347
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1348
+
1349
+ var val = this[offset];
1350
+ var mul = 1;
1351
+ var i = 0;
1352
+ while (++i < byteLength && (mul *= 0x100)) {
1353
+ val += this[offset + i] * mul;
1354
+ }
1355
+ mul *= 0x80;
1356
+
1357
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1358
+
1359
+ return val
1360
+ };
1361
+
1362
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1363
+ offset = offset | 0;
1364
+ byteLength = byteLength | 0;
1365
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
1366
+
1367
+ var i = byteLength;
1368
+ var mul = 1;
1369
+ var val = this[offset + --i];
1370
+ while (i > 0 && (mul *= 0x100)) {
1371
+ val += this[offset + --i] * mul;
1372
+ }
1373
+ mul *= 0x80;
1374
+
1375
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
1376
+
1377
+ return val
1378
+ };
1379
+
1380
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1381
+ if (!noAssert) checkOffset(offset, 1, this.length);
1382
+ if (!(this[offset] & 0x80)) return (this[offset])
1383
+ return ((0xff - this[offset] + 1) * -1)
1384
+ };
1385
+
1386
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1387
+ if (!noAssert) checkOffset(offset, 2, this.length);
1388
+ var val = this[offset] | (this[offset + 1] << 8);
1389
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1390
+ };
1391
+
1392
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1393
+ if (!noAssert) checkOffset(offset, 2, this.length);
1394
+ var val = this[offset + 1] | (this[offset] << 8);
1395
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
1396
+ };
1397
+
1398
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1399
+ if (!noAssert) checkOffset(offset, 4, this.length);
1400
+
1401
+ return (this[offset]) |
1402
+ (this[offset + 1] << 8) |
1403
+ (this[offset + 2] << 16) |
1404
+ (this[offset + 3] << 24)
1405
+ };
1406
+
1407
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1408
+ if (!noAssert) checkOffset(offset, 4, this.length);
1409
+
1410
+ return (this[offset] << 24) |
1411
+ (this[offset + 1] << 16) |
1412
+ (this[offset + 2] << 8) |
1413
+ (this[offset + 3])
1414
+ };
1415
+
1416
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1417
+ if (!noAssert) checkOffset(offset, 4, this.length);
1418
+ return read(this, offset, true, 23, 4)
1419
+ };
1420
+
1421
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1422
+ if (!noAssert) checkOffset(offset, 4, this.length);
1423
+ return read(this, offset, false, 23, 4)
1424
+ };
1425
+
1426
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1427
+ if (!noAssert) checkOffset(offset, 8, this.length);
1428
+ return read(this, offset, true, 52, 8)
1429
+ };
1430
+
1431
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1432
+ if (!noAssert) checkOffset(offset, 8, this.length);
1433
+ return read(this, offset, false, 52, 8)
1434
+ };
1435
+
1436
+ function checkInt (buf, value, offset, ext, max, min) {
1437
+ if (!internalIsBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1438
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1439
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
738
1440
  }
739
1441
 
740
- const TZ_DECIMALS = 6;
741
- const MTZ_DECIMALS = 3;
742
- function getDecimal(format) {
743
- switch (format) {
744
- case 'tz':
745
- return TZ_DECIMALS;
746
- case 'mtz':
747
- return MTZ_DECIMALS;
748
- case 'mutez':
749
- default:
750
- return 0;
751
- }
1442
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1443
+ value = +value;
1444
+ offset = offset | 0;
1445
+ byteLength = byteLength | 0;
1446
+ if (!noAssert) {
1447
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1448
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1449
+ }
1450
+
1451
+ var mul = 1;
1452
+ var i = 0;
1453
+ this[offset] = value & 0xFF;
1454
+ while (++i < byteLength && (mul *= 0x100)) {
1455
+ this[offset + i] = (value / mul) & 0xFF;
1456
+ }
1457
+
1458
+ return offset + byteLength
1459
+ };
1460
+
1461
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1462
+ value = +value;
1463
+ offset = offset | 0;
1464
+ byteLength = byteLength | 0;
1465
+ if (!noAssert) {
1466
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
1467
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
1468
+ }
1469
+
1470
+ var i = byteLength - 1;
1471
+ var mul = 1;
1472
+ this[offset + i] = value & 0xFF;
1473
+ while (--i >= 0 && (mul *= 0x100)) {
1474
+ this[offset + i] = (value / mul) & 0xFF;
1475
+ }
1476
+
1477
+ return offset + byteLength
1478
+ };
1479
+
1480
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1481
+ value = +value;
1482
+ offset = offset | 0;
1483
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
1484
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1485
+ this[offset] = (value & 0xff);
1486
+ return offset + 1
1487
+ };
1488
+
1489
+ function objectWriteUInt16 (buf, value, offset, littleEndian) {
1490
+ if (value < 0) value = 0xffff + value + 1;
1491
+ for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
1492
+ buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
1493
+ (littleEndian ? i : 1 - i) * 8;
1494
+ }
752
1495
  }
753
- function format(from = 'mutez', to = 'mutez', amount) {
754
- const bigNum = new BigNumber(amount);
755
- if (bigNum.isNaN()) {
756
- return amount;
1496
+
1497
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1498
+ value = +value;
1499
+ offset = offset | 0;
1500
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1501
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1502
+ this[offset] = (value & 0xff);
1503
+ this[offset + 1] = (value >>> 8);
1504
+ } else {
1505
+ objectWriteUInt16(this, value, offset, true);
1506
+ }
1507
+ return offset + 2
1508
+ };
1509
+
1510
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1511
+ value = +value;
1512
+ offset = offset | 0;
1513
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
1514
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1515
+ this[offset] = (value >>> 8);
1516
+ this[offset + 1] = (value & 0xff);
1517
+ } else {
1518
+ objectWriteUInt16(this, value, offset, false);
1519
+ }
1520
+ return offset + 2
1521
+ };
1522
+
1523
+ function objectWriteUInt32 (buf, value, offset, littleEndian) {
1524
+ if (value < 0) value = 0xffffffff + value + 1;
1525
+ for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
1526
+ buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff;
1527
+ }
1528
+ }
1529
+
1530
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1531
+ value = +value;
1532
+ offset = offset | 0;
1533
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1534
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1535
+ this[offset + 3] = (value >>> 24);
1536
+ this[offset + 2] = (value >>> 16);
1537
+ this[offset + 1] = (value >>> 8);
1538
+ this[offset] = (value & 0xff);
1539
+ } else {
1540
+ objectWriteUInt32(this, value, offset, true);
1541
+ }
1542
+ return offset + 4
1543
+ };
1544
+
1545
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1546
+ value = +value;
1547
+ offset = offset | 0;
1548
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
1549
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1550
+ this[offset] = (value >>> 24);
1551
+ this[offset + 1] = (value >>> 16);
1552
+ this[offset + 2] = (value >>> 8);
1553
+ this[offset + 3] = (value & 0xff);
1554
+ } else {
1555
+ objectWriteUInt32(this, value, offset, false);
1556
+ }
1557
+ return offset + 4
1558
+ };
1559
+
1560
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1561
+ value = +value;
1562
+ offset = offset | 0;
1563
+ if (!noAssert) {
1564
+ var limit = Math.pow(2, 8 * byteLength - 1);
1565
+
1566
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1567
+ }
1568
+
1569
+ var i = 0;
1570
+ var mul = 1;
1571
+ var sub = 0;
1572
+ this[offset] = value & 0xFF;
1573
+ while (++i < byteLength && (mul *= 0x100)) {
1574
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1575
+ sub = 1;
1576
+ }
1577
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1578
+ }
1579
+
1580
+ return offset + byteLength
1581
+ };
1582
+
1583
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1584
+ value = +value;
1585
+ offset = offset | 0;
1586
+ if (!noAssert) {
1587
+ var limit = Math.pow(2, 8 * byteLength - 1);
1588
+
1589
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
1590
+ }
1591
+
1592
+ var i = byteLength - 1;
1593
+ var mul = 1;
1594
+ var sub = 0;
1595
+ this[offset + i] = value & 0xFF;
1596
+ while (--i >= 0 && (mul *= 0x100)) {
1597
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1598
+ sub = 1;
1599
+ }
1600
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
1601
+ }
1602
+
1603
+ return offset + byteLength
1604
+ };
1605
+
1606
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1607
+ value = +value;
1608
+ offset = offset | 0;
1609
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -128);
1610
+ if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value);
1611
+ if (value < 0) value = 0xff + value + 1;
1612
+ this[offset] = (value & 0xff);
1613
+ return offset + 1
1614
+ };
1615
+
1616
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1617
+ value = +value;
1618
+ offset = offset | 0;
1619
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1620
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1621
+ this[offset] = (value & 0xff);
1622
+ this[offset + 1] = (value >>> 8);
1623
+ } else {
1624
+ objectWriteUInt16(this, value, offset, true);
1625
+ }
1626
+ return offset + 2
1627
+ };
1628
+
1629
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1630
+ value = +value;
1631
+ offset = offset | 0;
1632
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -32768);
1633
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1634
+ this[offset] = (value >>> 8);
1635
+ this[offset + 1] = (value & 0xff);
1636
+ } else {
1637
+ objectWriteUInt16(this, value, offset, false);
1638
+ }
1639
+ return offset + 2
1640
+ };
1641
+
1642
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1643
+ value = +value;
1644
+ offset = offset | 0;
1645
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1646
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1647
+ this[offset] = (value & 0xff);
1648
+ this[offset + 1] = (value >>> 8);
1649
+ this[offset + 2] = (value >>> 16);
1650
+ this[offset + 3] = (value >>> 24);
1651
+ } else {
1652
+ objectWriteUInt32(this, value, offset, true);
1653
+ }
1654
+ return offset + 4
1655
+ };
1656
+
1657
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1658
+ value = +value;
1659
+ offset = offset | 0;
1660
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -2147483648);
1661
+ if (value < 0) value = 0xffffffff + value + 1;
1662
+ if (Buffer.TYPED_ARRAY_SUPPORT) {
1663
+ this[offset] = (value >>> 24);
1664
+ this[offset + 1] = (value >>> 16);
1665
+ this[offset + 2] = (value >>> 8);
1666
+ this[offset + 3] = (value & 0xff);
1667
+ } else {
1668
+ objectWriteUInt32(this, value, offset, false);
1669
+ }
1670
+ return offset + 4
1671
+ };
1672
+
1673
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
1674
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
1675
+ if (offset < 0) throw new RangeError('Index out of range')
1676
+ }
1677
+
1678
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
1679
+ if (!noAssert) {
1680
+ checkIEEE754(buf, value, offset, 4);
1681
+ }
1682
+ write(buf, value, offset, littleEndian, 23, 4);
1683
+ return offset + 4
1684
+ }
1685
+
1686
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1687
+ return writeFloat(this, value, offset, true, noAssert)
1688
+ };
1689
+
1690
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1691
+ return writeFloat(this, value, offset, false, noAssert)
1692
+ };
1693
+
1694
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
1695
+ if (!noAssert) {
1696
+ checkIEEE754(buf, value, offset, 8);
1697
+ }
1698
+ write(buf, value, offset, littleEndian, 52, 8);
1699
+ return offset + 8
1700
+ }
1701
+
1702
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1703
+ return writeDouble(this, value, offset, true, noAssert)
1704
+ };
1705
+
1706
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1707
+ return writeDouble(this, value, offset, false, noAssert)
1708
+ };
1709
+
1710
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1711
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1712
+ if (!start) start = 0;
1713
+ if (!end && end !== 0) end = this.length;
1714
+ if (targetStart >= target.length) targetStart = target.length;
1715
+ if (!targetStart) targetStart = 0;
1716
+ if (end > 0 && end < start) end = start;
1717
+
1718
+ // Copy 0 bytes; we're done
1719
+ if (end === start) return 0
1720
+ if (target.length === 0 || this.length === 0) return 0
1721
+
1722
+ // Fatal error conditions
1723
+ if (targetStart < 0) {
1724
+ throw new RangeError('targetStart out of bounds')
1725
+ }
1726
+ if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
1727
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
1728
+
1729
+ // Are we oob?
1730
+ if (end > this.length) end = this.length;
1731
+ if (target.length - targetStart < end - start) {
1732
+ end = target.length - targetStart + start;
1733
+ }
1734
+
1735
+ var len = end - start;
1736
+ var i;
1737
+
1738
+ if (this === target && start < targetStart && targetStart < end) {
1739
+ // descending copy from end
1740
+ for (i = len - 1; i >= 0; --i) {
1741
+ target[i + targetStart] = this[i + start];
1742
+ }
1743
+ } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
1744
+ // ascending copy from start
1745
+ for (i = 0; i < len; ++i) {
1746
+ target[i + targetStart] = this[i + start];
1747
+ }
1748
+ } else {
1749
+ Uint8Array.prototype.set.call(
1750
+ target,
1751
+ this.subarray(start, start + len),
1752
+ targetStart
1753
+ );
1754
+ }
1755
+
1756
+ return len
1757
+ };
1758
+
1759
+ // Usage:
1760
+ // buffer.fill(number[, offset[, end]])
1761
+ // buffer.fill(buffer[, offset[, end]])
1762
+ // buffer.fill(string[, offset[, end]][, encoding])
1763
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
1764
+ // Handle string cases:
1765
+ if (typeof val === 'string') {
1766
+ if (typeof start === 'string') {
1767
+ encoding = start;
1768
+ start = 0;
1769
+ end = this.length;
1770
+ } else if (typeof end === 'string') {
1771
+ encoding = end;
1772
+ end = this.length;
1773
+ }
1774
+ if (val.length === 1) {
1775
+ var code = val.charCodeAt(0);
1776
+ if (code < 256) {
1777
+ val = code;
1778
+ }
1779
+ }
1780
+ if (encoding !== undefined && typeof encoding !== 'string') {
1781
+ throw new TypeError('encoding must be a string')
1782
+ }
1783
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1784
+ throw new TypeError('Unknown encoding: ' + encoding)
1785
+ }
1786
+ } else if (typeof val === 'number') {
1787
+ val = val & 255;
1788
+ }
1789
+
1790
+ // Invalid ranges are not set to a default, so can range check early.
1791
+ if (start < 0 || this.length < start || this.length < end) {
1792
+ throw new RangeError('Out of range index')
1793
+ }
1794
+
1795
+ if (end <= start) {
1796
+ return this
1797
+ }
1798
+
1799
+ start = start >>> 0;
1800
+ end = end === undefined ? this.length : end >>> 0;
1801
+
1802
+ if (!val) val = 0;
1803
+
1804
+ var i;
1805
+ if (typeof val === 'number') {
1806
+ for (i = start; i < end; ++i) {
1807
+ this[i] = val;
1808
+ }
1809
+ } else {
1810
+ var bytes = internalIsBuffer(val)
1811
+ ? val
1812
+ : utf8ToBytes(new Buffer(val, encoding).toString());
1813
+ var len = bytes.length;
1814
+ for (i = 0; i < end - start; ++i) {
1815
+ this[i + start] = bytes[i % len];
1816
+ }
1817
+ }
1818
+
1819
+ return this
1820
+ };
1821
+
1822
+ // HELPER FUNCTIONS
1823
+ // ================
1824
+
1825
+ var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
1826
+
1827
+ function base64clean (str) {
1828
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
1829
+ str = stringtrim(str).replace(INVALID_BASE64_RE, '');
1830
+ // Node converts strings with length < 2 to ''
1831
+ if (str.length < 2) return ''
1832
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1833
+ while (str.length % 4 !== 0) {
1834
+ str = str + '=';
1835
+ }
1836
+ return str
1837
+ }
1838
+
1839
+ function stringtrim (str) {
1840
+ if (str.trim) return str.trim()
1841
+ return str.replace(/^\s+|\s+$/g, '')
1842
+ }
1843
+
1844
+ function toHex (n) {
1845
+ if (n < 16) return '0' + n.toString(16)
1846
+ return n.toString(16)
1847
+ }
1848
+
1849
+ function utf8ToBytes (string, units) {
1850
+ units = units || Infinity;
1851
+ var codePoint;
1852
+ var length = string.length;
1853
+ var leadSurrogate = null;
1854
+ var bytes = [];
1855
+
1856
+ for (var i = 0; i < length; ++i) {
1857
+ codePoint = string.charCodeAt(i);
1858
+
1859
+ // is surrogate component
1860
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
1861
+ // last char was a lead
1862
+ if (!leadSurrogate) {
1863
+ // no lead yet
1864
+ if (codePoint > 0xDBFF) {
1865
+ // unexpected trail
1866
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1867
+ continue
1868
+ } else if (i + 1 === length) {
1869
+ // unpaired lead
1870
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1871
+ continue
1872
+ }
1873
+
1874
+ // valid lead
1875
+ leadSurrogate = codePoint;
1876
+
1877
+ continue
1878
+ }
1879
+
1880
+ // 2 leads in a row
1881
+ if (codePoint < 0xDC00) {
1882
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
1883
+ leadSurrogate = codePoint;
1884
+ continue
1885
+ }
1886
+
1887
+ // valid surrogate pair
1888
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
1889
+ } else if (leadSurrogate) {
1890
+ // valid bmp char, but last char was a lead
1891
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
757
1892
  }
758
- return bigNum
759
- .multipliedBy(Math.pow(10, getDecimal(from)))
760
- .dividedBy(Math.pow(10, getDecimal(to)));
1893
+
1894
+ leadSurrogate = null;
1895
+
1896
+ // encode utf8
1897
+ if (codePoint < 0x80) {
1898
+ if ((units -= 1) < 0) break
1899
+ bytes.push(codePoint);
1900
+ } else if (codePoint < 0x800) {
1901
+ if ((units -= 2) < 0) break
1902
+ bytes.push(
1903
+ codePoint >> 0x6 | 0xC0,
1904
+ codePoint & 0x3F | 0x80
1905
+ );
1906
+ } else if (codePoint < 0x10000) {
1907
+ if ((units -= 3) < 0) break
1908
+ bytes.push(
1909
+ codePoint >> 0xC | 0xE0,
1910
+ codePoint >> 0x6 & 0x3F | 0x80,
1911
+ codePoint & 0x3F | 0x80
1912
+ );
1913
+ } else if (codePoint < 0x110000) {
1914
+ if ((units -= 4) < 0) break
1915
+ bytes.push(
1916
+ codePoint >> 0x12 | 0xF0,
1917
+ codePoint >> 0xC & 0x3F | 0x80,
1918
+ codePoint >> 0x6 & 0x3F | 0x80,
1919
+ codePoint & 0x3F | 0x80
1920
+ );
1921
+ } else {
1922
+ throw new Error('Invalid code point')
1923
+ }
1924
+ }
1925
+
1926
+ return bytes
1927
+ }
1928
+
1929
+ function asciiToBytes (str) {
1930
+ var byteArray = [];
1931
+ for (var i = 0; i < str.length; ++i) {
1932
+ // Node's code seems to be doing this and not & 0x7F..
1933
+ byteArray.push(str.charCodeAt(i) & 0xFF);
1934
+ }
1935
+ return byteArray
1936
+ }
1937
+
1938
+ function utf16leToBytes (str, units) {
1939
+ var c, hi, lo;
1940
+ var byteArray = [];
1941
+ for (var i = 0; i < str.length; ++i) {
1942
+ if ((units -= 2) < 0) break
1943
+
1944
+ c = str.charCodeAt(i);
1945
+ hi = c >> 8;
1946
+ lo = c % 256;
1947
+ byteArray.push(lo);
1948
+ byteArray.push(hi);
1949
+ }
1950
+
1951
+ return byteArray
1952
+ }
1953
+
1954
+
1955
+ function base64ToBytes (str) {
1956
+ return toByteArray(base64clean(str))
1957
+ }
1958
+
1959
+ function blitBuffer (src, dst, offset, length) {
1960
+ for (var i = 0; i < length; ++i) {
1961
+ if ((i + offset >= dst.length) || (i >= src.length)) break
1962
+ dst[i + offset] = src[i];
1963
+ }
1964
+ return i
1965
+ }
1966
+
1967
+ function isnan (val) {
1968
+ return val !== val // eslint-disable-line no-self-compare
1969
+ }
1970
+
1971
+
1972
+ // the following is from is-buffer, also by Feross Aboukhadijeh and with same lisence
1973
+ // The _isBuffer check is for Safari 5-7 support, because it's missing
1974
+ // Object.prototype.constructor. Remove this eventually
1975
+ function isBuffer(obj) {
1976
+ return obj != null && (!!obj._isBuffer || isFastBuffer(obj) || isSlowBuffer(obj))
761
1977
  }
762
1978
 
1979
+ function isFastBuffer (obj) {
1980
+ return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
1981
+ }
1982
+
1983
+ // For Node v0.10 support. Remove this eventually.
1984
+ function isSlowBuffer (obj) {
1985
+ return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isFastBuffer(obj.slice(0, 0))
1986
+ }
1987
+
1988
+ // ref https://gitlab.com/tezos/tezos/-/blob/master/src/lib_crypto/base58.ml
1989
+ /**
1990
+ * @description base58 name to prefix mapping
1991
+ */
1992
+ exports.PrefixV2 = void 0;
1993
+ (function (PrefixV2) {
1994
+ PrefixV2["BlockHash"] = "B";
1995
+ PrefixV2["OperationHash"] = "o";
1996
+ PrefixV2["OperationListHash"] = "Lo";
1997
+ PrefixV2["OperationListListHash"] = "LLo";
1998
+ PrefixV2["ProtocolHash"] = "P";
1999
+ PrefixV2["ContextHash"] = "Co";
2000
+ PrefixV2["BlockMetadataHash"] = "bm";
2001
+ PrefixV2["OperationMetadataHash"] = "r";
2002
+ PrefixV2["OperationMetadataListHash"] = "Lr";
2003
+ PrefixV2["OperationMetadataListListHash"] = "LLr";
2004
+ PrefixV2["Ed25519PublicKeyHash"] = "tz1";
2005
+ PrefixV2["Secp256k1PublicKeyHash"] = "tz2";
2006
+ PrefixV2["P256PublicKeyHash"] = "tz3";
2007
+ PrefixV2["ContractHash"] = "KT1";
2008
+ PrefixV2["BlindedPublicKeyHash"] = "btz1";
2009
+ PrefixV2["BLS12_381PublicKeyHash"] = "tz4";
2010
+ PrefixV2["TXRollupAddress"] = "txr1";
2011
+ PrefixV2["ZkRollupHash"] = "epx1";
2012
+ PrefixV2["ScRollupHash"] = "scr1";
2013
+ PrefixV2["SmartRollupHash"] = "sr1";
2014
+ PrefixV2["CryptoboxPublicKeyHash"] = "id";
2015
+ PrefixV2["Ed25519Seed"] = "edsk";
2016
+ PrefixV2["Ed25519PublicKey"] = "edpk";
2017
+ PrefixV2["Secp256k1SecretKey"] = "spsk";
2018
+ PrefixV2["P256SecretKey"] = "p2sk";
2019
+ PrefixV2["BLS12_381SecretKey"] = "BLsk";
2020
+ PrefixV2["ValueHash"] = "vh";
2021
+ PrefixV2["CycleNonce"] = "nce";
2022
+ PrefixV2["ScriptExpr"] = "expr";
2023
+ PrefixV2["InboxHash"] = "txi";
2024
+ PrefixV2["MessageHash"] = "txm";
2025
+ PrefixV2["CommitmentHash"] = "txc";
2026
+ PrefixV2["MessageResultHash"] = "txmr";
2027
+ PrefixV2["MessageResultListHash"] = "txM";
2028
+ PrefixV2["WithdrawListHash"] = "txw";
2029
+ PrefixV2["ScRollupStateHash"] = "scs1";
2030
+ PrefixV2["ScRollupCommitmentHash"] = "scc1";
2031
+ PrefixV2["SmartRollupStateHash"] = "srs1";
2032
+ PrefixV2["SmartRollupCommitmentHash"] = "src1";
2033
+ PrefixV2["Ed25519EncryptedSeed"] = "edesk";
2034
+ PrefixV2["Secp256k1EncryptedSecretKey"] = "spesk";
2035
+ PrefixV2["P256EncryptedSecretKey"] = "p2esk";
2036
+ PrefixV2["BLS12_381EncryptedSecretKey"] = "BLesk";
2037
+ PrefixV2["Secp256k1EncryptedScalar"] = "seesk";
2038
+ PrefixV2["Secp256k1PublicKey"] = "sppk";
2039
+ PrefixV2["P256PublicKey"] = "p2pk";
2040
+ PrefixV2["Secp256k1Scalar"] = "SSp";
2041
+ PrefixV2["Secp256k1Element"] = "GSp";
2042
+ PrefixV2["Ed25519SecretKey"] = "_edsk";
2043
+ PrefixV2["Ed25519Signature"] = "edsig";
2044
+ PrefixV2["Secp256k1Signature"] = "spsig1";
2045
+ PrefixV2["P256Signature"] = "p2sig";
2046
+ PrefixV2["GenericSignature"] = "sig";
2047
+ PrefixV2["ChainID"] = "Net";
2048
+ PrefixV2["SaplingSpendingKey"] = "sask";
2049
+ PrefixV2["EncryptedSaplingSpendingKey"] = "_sask";
2050
+ PrefixV2["SaplingAddress"] = "zet1";
2051
+ PrefixV2["GenericAggregateSignature"] = "asig";
2052
+ PrefixV2["BLS12_381Signature"] = "BLsig";
2053
+ PrefixV2["BLS12_381PublicKey"] = "BLpk";
2054
+ PrefixV2["SlotHeader"] = "sh";
2055
+ })(exports.PrefixV2 || (exports.PrefixV2 = {}));
2056
+ /**
2057
+ * @description base58 prefix to bytes mapping
2058
+ */
2059
+ const prefixV2 = {
2060
+ [exports.PrefixV2.BlockHash]: new Uint8Array([1, 52]),
2061
+ [exports.PrefixV2.OperationHash]: new Uint8Array([5, 116]),
2062
+ [exports.PrefixV2.OperationListHash]: new Uint8Array([133, 233]),
2063
+ [exports.PrefixV2.OperationListListHash]: new Uint8Array([29, 159, 109]),
2064
+ [exports.PrefixV2.ProtocolHash]: new Uint8Array([2, 170]),
2065
+ [exports.PrefixV2.ContextHash]: new Uint8Array([79, 199]),
2066
+ [exports.PrefixV2.BlockMetadataHash]: new Uint8Array([234, 249]),
2067
+ [exports.PrefixV2.OperationMetadataHash]: new Uint8Array([5, 183]),
2068
+ [exports.PrefixV2.OperationMetadataListHash]: new Uint8Array([134, 39]),
2069
+ [exports.PrefixV2.OperationMetadataListListHash]: new Uint8Array([29, 159, 182]),
2070
+ [exports.PrefixV2.Ed25519PublicKeyHash]: new Uint8Array([6, 161, 159]),
2071
+ [exports.PrefixV2.Secp256k1PublicKeyHash]: new Uint8Array([6, 161, 161]),
2072
+ [exports.PrefixV2.P256PublicKeyHash]: new Uint8Array([6, 161, 164]),
2073
+ [exports.PrefixV2.ContractHash]: new Uint8Array([2, 90, 121]),
2074
+ [exports.PrefixV2.BlindedPublicKeyHash]: new Uint8Array([1, 2, 49, 223]),
2075
+ [exports.PrefixV2.BLS12_381PublicKeyHash]: new Uint8Array([6, 161, 166]),
2076
+ [exports.PrefixV2.TXRollupAddress]: new Uint8Array([1, 128, 120, 31]),
2077
+ [exports.PrefixV2.ZkRollupHash]: new Uint8Array([1, 23, 224, 125]),
2078
+ [exports.PrefixV2.ScRollupHash]: new Uint8Array([1, 118, 132, 217]),
2079
+ [exports.PrefixV2.SmartRollupHash]: new Uint8Array([6, 124, 117]),
2080
+ [exports.PrefixV2.CryptoboxPublicKeyHash]: new Uint8Array([153, 103]),
2081
+ [exports.PrefixV2.Ed25519Seed]: new Uint8Array([13, 15, 58, 7]),
2082
+ [exports.PrefixV2.Ed25519PublicKey]: new Uint8Array([13, 15, 37, 217]),
2083
+ [exports.PrefixV2.Secp256k1SecretKey]: new Uint8Array([17, 162, 224, 201]),
2084
+ [exports.PrefixV2.P256SecretKey]: new Uint8Array([16, 81, 238, 189]),
2085
+ [exports.PrefixV2.BLS12_381SecretKey]: new Uint8Array([3, 150, 192, 40]),
2086
+ [exports.PrefixV2.ValueHash]: new Uint8Array([1, 106, 242]),
2087
+ [exports.PrefixV2.CycleNonce]: new Uint8Array([69, 220, 169]),
2088
+ [exports.PrefixV2.ScriptExpr]: new Uint8Array([13, 44, 64, 27]),
2089
+ [exports.PrefixV2.InboxHash]: new Uint8Array([79, 148, 196]),
2090
+ [exports.PrefixV2.MessageHash]: new Uint8Array([79, 149, 30]),
2091
+ [exports.PrefixV2.CommitmentHash]: new Uint8Array([79, 148, 17]),
2092
+ [exports.PrefixV2.MessageResultHash]: new Uint8Array([18, 7, 206, 87]),
2093
+ [exports.PrefixV2.MessageResultListHash]: new Uint8Array([79, 146, 82]),
2094
+ [exports.PrefixV2.WithdrawListHash]: new Uint8Array([79, 150, 72]),
2095
+ [exports.PrefixV2.ScRollupStateHash]: new Uint8Array([17, 144, 122, 202]),
2096
+ [exports.PrefixV2.ScRollupCommitmentHash]: new Uint8Array([17, 144, 21, 100]),
2097
+ [exports.PrefixV2.SmartRollupStateHash]: new Uint8Array([17, 165, 235, 240]),
2098
+ [exports.PrefixV2.SmartRollupCommitmentHash]: new Uint8Array([17, 165, 134, 138]),
2099
+ [exports.PrefixV2.Ed25519EncryptedSeed]: new Uint8Array([7, 90, 60, 179, 41]),
2100
+ [exports.PrefixV2.Secp256k1EncryptedSecretKey]: new Uint8Array([9, 237, 241, 174, 150]),
2101
+ [exports.PrefixV2.P256EncryptedSecretKey]: new Uint8Array([9, 48, 57, 115, 171]),
2102
+ [exports.PrefixV2.BLS12_381EncryptedSecretKey]: new Uint8Array([2, 5, 30, 53, 25]),
2103
+ [exports.PrefixV2.Secp256k1EncryptedScalar]: new Uint8Array([1, 131, 36, 86, 248]),
2104
+ [exports.PrefixV2.Secp256k1PublicKey]: new Uint8Array([3, 254, 226, 86]),
2105
+ [exports.PrefixV2.P256PublicKey]: new Uint8Array([3, 178, 139, 127]),
2106
+ [exports.PrefixV2.Secp256k1Scalar]: new Uint8Array([38, 248, 136]),
2107
+ [exports.PrefixV2.Secp256k1Element]: new Uint8Array([5, 92, 0]),
2108
+ [exports.PrefixV2.Ed25519SecretKey]: new Uint8Array([43, 246, 78, 7]),
2109
+ [exports.PrefixV2.Ed25519Signature]: new Uint8Array([9, 245, 205, 134, 18]),
2110
+ [exports.PrefixV2.Secp256k1Signature]: new Uint8Array([13, 115, 101, 19, 63]),
2111
+ [exports.PrefixV2.P256Signature]: new Uint8Array([54, 240, 44, 52]),
2112
+ [exports.PrefixV2.GenericSignature]: new Uint8Array([4, 130, 43]),
2113
+ [exports.PrefixV2.ChainID]: new Uint8Array([87, 82, 0]),
2114
+ [exports.PrefixV2.SaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
2115
+ [exports.PrefixV2.EncryptedSaplingSpendingKey]: new Uint8Array([11, 237, 20, 92]),
2116
+ [exports.PrefixV2.SaplingAddress]: new Uint8Array([18, 71, 40, 223]),
2117
+ [exports.PrefixV2.GenericAggregateSignature]: new Uint8Array([2, 75, 234, 101]),
2118
+ [exports.PrefixV2.BLS12_381Signature]: new Uint8Array([40, 171, 64, 207]),
2119
+ [exports.PrefixV2.BLS12_381PublicKey]: new Uint8Array([6, 149, 135, 204]),
2120
+ [exports.PrefixV2.SlotHeader]: new Uint8Array([2, 116, 180]),
2121
+ };
2122
+ /**
2123
+ * @description base58 prefix to payload length mapping
2124
+ */
2125
+ const payloadLength = {
2126
+ [exports.PrefixV2.BlockHash]: 32,
2127
+ [exports.PrefixV2.OperationHash]: 32,
2128
+ [exports.PrefixV2.OperationListHash]: 32,
2129
+ [exports.PrefixV2.OperationListListHash]: 32,
2130
+ [exports.PrefixV2.ProtocolHash]: 32,
2131
+ [exports.PrefixV2.ContextHash]: 32,
2132
+ [exports.PrefixV2.BlockMetadataHash]: 32,
2133
+ [exports.PrefixV2.OperationMetadataHash]: 32,
2134
+ [exports.PrefixV2.OperationMetadataListHash]: 32,
2135
+ [exports.PrefixV2.OperationMetadataListListHash]: 32,
2136
+ [exports.PrefixV2.Ed25519PublicKeyHash]: 20,
2137
+ [exports.PrefixV2.Secp256k1PublicKeyHash]: 20,
2138
+ [exports.PrefixV2.P256PublicKeyHash]: 20,
2139
+ [exports.PrefixV2.ContractHash]: 20,
2140
+ [exports.PrefixV2.BlindedPublicKeyHash]: 20,
2141
+ [exports.PrefixV2.BLS12_381PublicKeyHash]: 20,
2142
+ [exports.PrefixV2.TXRollupAddress]: 20,
2143
+ [exports.PrefixV2.ZkRollupHash]: 20,
2144
+ [exports.PrefixV2.ScRollupHash]: 20,
2145
+ [exports.PrefixV2.SmartRollupHash]: 20,
2146
+ [exports.PrefixV2.CryptoboxPublicKeyHash]: 16,
2147
+ [exports.PrefixV2.Ed25519Seed]: 32,
2148
+ [exports.PrefixV2.Ed25519PublicKey]: 32,
2149
+ [exports.PrefixV2.Secp256k1SecretKey]: 32,
2150
+ [exports.PrefixV2.P256SecretKey]: 32,
2151
+ [exports.PrefixV2.BLS12_381SecretKey]: 32,
2152
+ [exports.PrefixV2.ValueHash]: 32,
2153
+ [exports.PrefixV2.CycleNonce]: 32,
2154
+ [exports.PrefixV2.ScriptExpr]: 32,
2155
+ [exports.PrefixV2.InboxHash]: 32,
2156
+ [exports.PrefixV2.MessageHash]: 32,
2157
+ [exports.PrefixV2.CommitmentHash]: 32,
2158
+ [exports.PrefixV2.MessageResultHash]: 32,
2159
+ [exports.PrefixV2.MessageResultListHash]: 32,
2160
+ [exports.PrefixV2.WithdrawListHash]: 32,
2161
+ [exports.PrefixV2.ScRollupStateHash]: 32,
2162
+ [exports.PrefixV2.ScRollupCommitmentHash]: 32,
2163
+ [exports.PrefixV2.SmartRollupStateHash]: 32,
2164
+ [exports.PrefixV2.SmartRollupCommitmentHash]: 32,
2165
+ [exports.PrefixV2.Ed25519EncryptedSeed]: 56,
2166
+ [exports.PrefixV2.Secp256k1EncryptedSecretKey]: 56,
2167
+ [exports.PrefixV2.P256EncryptedSecretKey]: 56,
2168
+ [exports.PrefixV2.BLS12_381EncryptedSecretKey]: 56,
2169
+ [exports.PrefixV2.Secp256k1EncryptedScalar]: 60,
2170
+ [exports.PrefixV2.Secp256k1PublicKey]: 33,
2171
+ [exports.PrefixV2.P256PublicKey]: 33,
2172
+ [exports.PrefixV2.Secp256k1Scalar]: 33,
2173
+ [exports.PrefixV2.Secp256k1Element]: 33,
2174
+ [exports.PrefixV2.Ed25519SecretKey]: 64,
2175
+ [exports.PrefixV2.Ed25519Signature]: 64,
2176
+ [exports.PrefixV2.Secp256k1Signature]: 64,
2177
+ [exports.PrefixV2.P256Signature]: 64,
2178
+ [exports.PrefixV2.GenericSignature]: 64,
2179
+ [exports.PrefixV2.ChainID]: 4,
2180
+ [exports.PrefixV2.SaplingSpendingKey]: 169,
2181
+ [exports.PrefixV2.EncryptedSaplingSpendingKey]: 193,
2182
+ [exports.PrefixV2.SaplingAddress]: 43,
2183
+ [exports.PrefixV2.GenericAggregateSignature]: 96,
2184
+ [exports.PrefixV2.BLS12_381Signature]: 96,
2185
+ [exports.PrefixV2.BLS12_381PublicKey]: 48,
2186
+ [exports.PrefixV2.SlotHeader]: 48,
2187
+ };
2188
+
763
2189
  /**
764
2190
  * @packageDocumentation
765
2191
  * @module @taquito/utils
@@ -1238,184 +2664,490 @@
1238
2664
  * @param str String to convert
1239
2665
  */
1240
2666
  function stringToBytes(str) {
1241
- return buffer.Buffer.from(str, 'utf8').toString('hex');
2667
+ return Buffer.from(str, 'utf8').toString('hex');
1242
2668
  }
1243
2669
  /**
1244
2670
  * @description Convert byte string representation to string
1245
2671
  * @param hex byte string to convert
1246
2672
  */
1247
- function bytesToString(hex) {
1248
- return buffer.Buffer.from(hex2buf(hex)).toString('utf8');
2673
+ function bytesToString(hex) {
2674
+ return Buffer.from(hex2buf(hex)).toString('utf8');
2675
+ }
2676
+ /**
2677
+ * @description Convert hex string/UintArray/Buffer to bytes
2678
+ * @param hex String value to convert to bytes
2679
+ */
2680
+ function hex2Bytes(hex) {
2681
+ const hexDigits = stripHexPrefix(hex);
2682
+ if (!hexDigits.match(/^(0x)?([\da-f]{2})*$/gi)) {
2683
+ throw new core.InvalidHexStringError(hex, `Expecting even number of characters: 0-9, a-z, A-Z, optionally prefixed with 0x`);
2684
+ }
2685
+ return Buffer.from(hexDigits, 'hex');
2686
+ }
2687
+ /**
2688
+ * @description Converts a number or Bignumber to hexadecimal string
2689
+ * @param val The value that will be converted to a hexadecimal string value
2690
+ */
2691
+ function toHexBuf(val, bitLength = 8) {
2692
+ return Buffer.from(num2PaddedHex(val, bitLength), 'hex');
2693
+ }
2694
+ function numToHexBuffer(val, bitLength = 8) {
2695
+ return Buffer.from(num2PaddedHex(val, bitLength), 'hex');
2696
+ }
2697
+ /**
2698
+ * @description Converts a number or BigNumber to a padded hexadecimal string
2699
+ * @param val The value that will be converted into a padded hexadecimal string value
2700
+ * @param bitLength The length of bits
2701
+ *
2702
+ */
2703
+ function num2PaddedHex(val, bitLength = 8) {
2704
+ if (new BigNumber(val).isPositive()) {
2705
+ const nibbleLength = Math.ceil(bitLength / 4);
2706
+ const hex = val.toString(16);
2707
+ // check whether nibble (4 bits) length is higher or lower than the current hex string length
2708
+ let targetLength = hex.length >= nibbleLength ? hex.length : nibbleLength;
2709
+ // make sure the hex string target length is even
2710
+ targetLength = targetLength % 2 == 0 ? targetLength : targetLength + 1;
2711
+ return padHexWithZero(hex, targetLength);
2712
+ }
2713
+ else {
2714
+ const twosCompliment = new BigNumber(2)
2715
+ .pow(bitLength)
2716
+ .minus(new BigNumber(val).abs());
2717
+ return twosCompliment.toString(16);
2718
+ }
2719
+ }
2720
+ function padHexWithZero(hex, targetLength) {
2721
+ const padString = '0';
2722
+ if (hex.length >= targetLength) {
2723
+ return hex;
2724
+ }
2725
+ else {
2726
+ const padLength = targetLength - hex.length;
2727
+ return padString.repeat(padLength) + hex;
2728
+ }
2729
+ }
2730
+ /**
2731
+ *
2732
+ * @description Strips the first 2 characters of a hex string (0x)
2733
+ *
2734
+ * @param hex string to strip prefix from
2735
+ */
2736
+ function stripHexPrefix(hex) {
2737
+ return hex.startsWith('0x') ? hex.slice(2) : hex;
2738
+ }
2739
+ function splitAddress(addr) {
2740
+ const i = addr.indexOf('%');
2741
+ if (i >= 0) {
2742
+ return [addr.slice(0, i), addr.slice(i)];
2743
+ }
2744
+ else {
2745
+ return [addr, null];
2746
+ }
2747
+ }
2748
+ function compareArrays(a, b) {
2749
+ let i = 0;
2750
+ while (i < a.length && i < b.length && a[i] === b[i])
2751
+ i++;
2752
+ const aa = i < a.length ? a[i] : 0;
2753
+ const bb = i < b.length ? b[i] : 0;
2754
+ return aa < bb ? -1 : aa > bb ? 1 : 0;
2755
+ }
2756
+
2757
+ /**
2758
+ * @description Used to check if a value has one of the allowed prefixes.
2759
+ * @returns true if the value has one of the allowed prefixes, false otherwise
2760
+ * @example
2761
+ * ```
2762
+ * import { isValidPrefixedValue } from '@taquito/utils';
2763
+ * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
2764
+ * const isValid = isValidPrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
2765
+ * console.log(isValid) // true
2766
+ * ```
2767
+ */
2768
+ function isValidPrefixedValue(value, prefixes) {
2769
+ return validatePrefixedValue(value, prefixes) === core.ValidationResult.VALID;
2770
+ }
2771
+ /**
2772
+ * @description This function is called by the validation functions ([[validateAddress]], [[validateChain]], [[validateContractAddress]], [[validateKeyHash]], [[validateSignature]], [[validatePublicKey]]).
2773
+ * 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)
2774
+ * If all checks pass, return `3` (VALID).
2775
+ * @param value Value to validate
2776
+ * @param prefixes prefix the value should have
2777
+ * @returns 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2778
+ * @example
2779
+ * ```
2780
+ * import { validatePrefixedValue } from '@taquito/utils';
2781
+ * const value = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
2782
+ * const validation = validatePrefixedValue(value, [PrefixV2.Ed25519PublicKeyHash])
2783
+ * console.log(validation) // 3
2784
+ * ```
2785
+ */
2786
+ function validatePrefixedValue(value, prefixes) {
2787
+ try {
2788
+ b58DecodeAndCheckPrefix(value, prefixes);
2789
+ }
2790
+ catch (err) {
2791
+ if (err instanceof core.ParameterValidationError && err.result !== undefined) {
2792
+ return err.result;
2793
+ }
2794
+ return core.ValidationResult.OTHER;
2795
+ }
2796
+ return core.ValidationResult.VALID;
2797
+ }
2798
+ /**
2799
+ * @description Used to check if an address or a contract address is valid.
2800
+ *
2801
+ * @returns
2802
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2803
+ *
2804
+ * @example
2805
+ * ```
2806
+ * import { validateAddress } from '@taquito/utils';
2807
+ * const pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
2808
+ * const validation = validateAddress(pkh)
2809
+ * console.log(validation)
2810
+ * // This example return 3 which correspond to VALID
2811
+ * ```
2812
+ */
2813
+ function validateAddress(value) {
2814
+ const [addr] = splitAddress(value !== null && value !== void 0 ? value : '');
2815
+ return validatePrefixedValue(addr, addressPrefixes);
2816
+ }
2817
+ /**
2818
+ * @description Used to check if a chain id is valid.
2819
+ *
2820
+ * @returns
2821
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2822
+ *
2823
+ * @example
2824
+ * ```
2825
+ * import { validateChain } from '@taquito/utils';
2826
+ * const chainId = 'NetXdQprcVkpaWU'
2827
+ * const validation = validateChain(chainId)
2828
+ * console.log(validation)
2829
+ * // This example return 3 which correspond to VALID
2830
+ * ```
2831
+ */
2832
+ function validateChain(value) {
2833
+ return validatePrefixedValue(value, [exports.PrefixV2.ChainID]);
2834
+ }
2835
+ /**
2836
+ * @description Used to check if a contract address is valid.
2837
+ *
2838
+ * @returns
2839
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2840
+ *
2841
+ * @example
2842
+ * ```
2843
+ * import { validateContractAddress } from '@taquito/utils';
2844
+ * const contractAddress = 'KT1JVErLYTgtY8uGGZ4mso2npTSxqVLDRVbC'
2845
+ * const validation = validateContractAddress(contractAddress)
2846
+ * console.log(validation)
2847
+ * // This example return 3 which correspond to VALID
2848
+ * ```
2849
+ */
2850
+ function validateContractAddress(value) {
2851
+ return validatePrefixedValue(value, [exports.PrefixV2.ContractHash]);
2852
+ }
2853
+ /**
2854
+ * @description Used to check if a key hash is valid.
2855
+ *
2856
+ * @returns
2857
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2858
+ *
2859
+ * @example
2860
+ * ```
2861
+ * import { validateKeyHash } from '@taquito/utils';
2862
+ * const keyHashWithoutPrefix = '1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
2863
+ * const validation = validateKeyHash(keyHashWithoutPrefix)
2864
+ * console.log(validation)
2865
+ * // This example return 0 which correspond to NO_PREFIX_MATCHED
2866
+ * ```
2867
+ */
2868
+ function validateKeyHash(value) {
2869
+ return validatePrefixedValue(value, publicKeyHashPrefixes);
2870
+ }
2871
+ /**
2872
+ * @description Used to check if a signature is valid.
2873
+ *
2874
+ * @returns
2875
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2876
+ *
2877
+ * @example
2878
+ * ```
2879
+ * import { validateSignature } from '@taquito/utils';
2880
+ * const signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg'
2881
+ * const validation = validateSignature(signature)
2882
+ * console.log(validation)
2883
+ * // This example return 3 which correspond to VALID
2884
+ * ```
2885
+ */
2886
+ function validateSignature(value) {
2887
+ return validatePrefixedValue(value, signaturePrefixes);
2888
+ }
2889
+ /**
2890
+ * @description Used to check if a public key is valid.
2891
+ *
2892
+ * @returns
2893
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2894
+ *
2895
+ * @example
2896
+ * ```
2897
+ * import { validatePublicKey } from '@taquito/utils';
2898
+ * const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g'
2899
+ * const validation = validatePublicKey(publicKey)
2900
+ * console.log(validation)
2901
+ * // This example return 3 which correspond to VALID
2902
+ * ```
2903
+ */
2904
+ function validatePublicKey(value) {
2905
+ return validatePrefixedValue(value, publicKeyPrefixes);
2906
+ }
2907
+ /**
2908
+ * @description Used to check if an operation hash is valid.
2909
+ *
2910
+ * @returns
2911
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2912
+ *
2913
+ * @example
2914
+ * ```
2915
+ * import { validateOperation } from '@taquito/utils';
2916
+ * const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
2917
+ * const validation = validateOperation(operationHash)
2918
+ * console.log(validation)
2919
+ * // This example return 3 which correspond to VALID
2920
+ * ```
2921
+ */
2922
+ function validateOperation(value) {
2923
+ return validatePrefixedValue(value, [exports.PrefixV2.OperationHash]);
2924
+ }
2925
+ /**
2926
+ * @description Used to check if a protocol hash is valid.
2927
+ *
2928
+ * @returns
2929
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2930
+ *
2931
+ * @example
2932
+ * ```
2933
+ * import { validateProtocol } from '@taquito/utils';
2934
+ * const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
2935
+ * const validation = validateProtocol(protocolHash)
2936
+ * console.log(validation)
2937
+ * // This example return 3 which correspond to VALID
2938
+ * ```
2939
+ */
2940
+ function validateProtocol(value) {
2941
+ return validatePrefixedValue(value, [exports.PrefixV2.ProtocolHash]);
1249
2942
  }
1250
2943
  /**
1251
- * @description Convert hex string/UintArray/Buffer to bytes
1252
- * @param hex String value to convert to bytes
2944
+ * @description Used to check if a block hash is valid.
2945
+ *
2946
+ * @returns
2947
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2948
+ *
2949
+ * @example
2950
+ * ```
2951
+ * import { validateBlock } from '@taquito/utils';
2952
+ * const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
2953
+ * const validation = validateBlock(blockHash)
2954
+ * console.log(validation)
2955
+ * // This example return 3 which correspond to VALID
2956
+ * ```
1253
2957
  */
1254
- function hex2Bytes(hex) {
1255
- const hexDigits = stripHexPrefix(hex);
1256
- if (!hexDigits.match(/^(0x)?([\da-f]{2})*$/gi)) {
1257
- throw new core.InvalidHexStringError(hex, `Expecting even number of characters: 0-9, a-z, A-Z, optionally prefixed with 0x`);
1258
- }
1259
- return buffer.Buffer.from(hexDigits, 'hex');
2958
+ function validateBlock(value) {
2959
+ return validatePrefixedValue(value, [exports.PrefixV2.BlockHash]);
1260
2960
  }
1261
2961
  /**
1262
- * @description Converts a number or Bignumber to hexadecimal string
1263
- * @param val The value that will be converted to a hexadecimal string value
2962
+ * @description Used to check if a spending key is valid.
2963
+ * @returns
2964
+ * 0 = NO_PREFIX_MATCHED, 1 = INVALID_CHECKSUM, 2 = INVALID_LENGTH, 3 = VALID, 4 = PREFIX_NOT_ALLOWED, 5 = INVALID_ENCODING, 6 = OTHER,
2965
+ *
1264
2966
  */
1265
- function toHexBuf(val, bitLength = 8) {
1266
- return buffer.Buffer.from(num2PaddedHex(val, bitLength), 'hex');
2967
+ function validateSpendingKey(value) {
2968
+ return validatePrefixedValue(value, [exports.PrefixV2.SaplingSpendingKey]);
1267
2969
  }
1268
- function numToHexBuffer(val, bitLength = 8) {
1269
- return buffer.Buffer.from(num2PaddedHex(val, bitLength), 'hex');
2970
+ function validateSmartRollupAddress(value) {
2971
+ return validatePrefixedValue(value, [exports.PrefixV2.SmartRollupHash]);
1270
2972
  }
2973
+
2974
+ // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
2975
+ const VERSION = {
2976
+ "commitHash": "7912b77f57f943dff619383900bd46a7a593a244",
2977
+ "version": "24.0.0-beta.0"
2978
+ };
2979
+
2980
+ const BLS12_381_DST = 'BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
2981
+ const POP_DST = 'BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_';
1271
2982
  /**
1272
- * @description Converts a number or BigNumber to a padded hexadecimal string
1273
- * @param val The value that will be converted into a padded hexadecimal string value
1274
- * @param bitLength The length of bits
2983
+ * @description Verify signature of a payload
2984
+ * @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
2985
+ * @param publicKey The public key to verify the signature against
2986
+ * @param signature The signature to verify
2987
+ * @param watermark Optional if not included in the message
2988
+ * @param pop Optional if verifying proof of possession signature
2989
+ * @returns A boolean indicating if the signature matches
2990
+ * @throws {@link InvalidPublicKeyError} | {@link InvalidSignatureError} | {@link InvalidMessageError}
2991
+ * @example
2992
+ * ```
2993
+ * const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
2994
+ * const pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';
2995
+ * const sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'
2996
+ *
2997
+ * const response = verifySignature(message, pk, sig);
2998
+ * ```
1275
2999
  *
1276
3000
  */
1277
- function num2PaddedHex(val, bitLength = 8) {
1278
- if (new BigNumber(val).isPositive()) {
1279
- const nibbleLength = Math.ceil(bitLength / 4);
1280
- const hex = val.toString(16);
1281
- // check whether nibble (4 bits) length is higher or lower than the current hex string length
1282
- let targetLength = hex.length >= nibbleLength ? hex.length : nibbleLength;
1283
- // make sure the hex string target length is even
1284
- targetLength = targetLength % 2 == 0 ? targetLength : targetLength + 1;
1285
- return padHexWithZero(hex, targetLength);
3001
+ function verifySignature(message, publicKey, signature, watermark, pop) {
3002
+ const [pk, pre] = (() => {
3003
+ try {
3004
+ return b58DecodeAndCheckPrefix(publicKey, publicKeyPrefixes);
3005
+ }
3006
+ catch (err) {
3007
+ if (err instanceof core.ParameterValidationError) {
3008
+ throw new core.InvalidPublicKeyError(publicKey, err.result);
3009
+ }
3010
+ else {
3011
+ throw err;
3012
+ }
3013
+ }
3014
+ })();
3015
+ const sig = (() => {
3016
+ try {
3017
+ const [sig] = b58DecodeAndCheckPrefix(signature, signaturePrefixes);
3018
+ return sig;
3019
+ }
3020
+ catch (err) {
3021
+ if (err instanceof core.ParameterValidationError) {
3022
+ throw new core.InvalidSignatureError(signature, err.result);
3023
+ }
3024
+ else {
3025
+ throw err;
3026
+ }
3027
+ }
3028
+ })();
3029
+ let msg;
3030
+ if (typeof message === 'string') {
3031
+ msg = hex2buf(message);
1286
3032
  }
1287
3033
  else {
1288
- const twosCompliment = new BigNumber(2)
1289
- .pow(bitLength)
1290
- .minus(new BigNumber(val).abs());
1291
- return twosCompliment.toString(16);
3034
+ msg = message;
1292
3035
  }
1293
- }
1294
- function padHexWithZero(hex, targetLength) {
1295
- const padString = '0';
1296
- if (hex.length >= targetLength) {
1297
- return hex;
3036
+ if (msg.length === 0) {
3037
+ throw new core.InvalidMessageError(buf2hex(msg), `can't be empty`);
1298
3038
  }
1299
- else {
1300
- const padLength = targetLength - hex.length;
1301
- return padString.repeat(padLength) + hex;
3039
+ if (typeof watermark !== 'undefined') {
3040
+ msg = mergebuf(watermark, msg);
1302
3041
  }
1303
- }
1304
- /**
1305
- *
1306
- * @description Strips the first 2 characters of a hex string (0x)
1307
- *
1308
- * @param hex string to strip prefix from
1309
- */
1310
- function stripHexPrefix(hex) {
1311
- return hex.startsWith('0x') ? hex.slice(2) : hex;
1312
- }
1313
- function splitAddress(addr) {
1314
- const i = addr.indexOf('%');
1315
- if (i >= 0) {
1316
- return [addr.slice(0, i), addr.slice(i)];
3042
+ if (pop) {
3043
+ return verifyBLSPopSignature(sig, msg, pk);
1317
3044
  }
1318
3045
  else {
1319
- return [addr, null];
3046
+ switch (pre) {
3047
+ case exports.PrefixV2.P256PublicKey:
3048
+ return verifyP2Signature(sig, msg, pk);
3049
+ case exports.PrefixV2.Secp256k1PublicKey:
3050
+ return verifySpSignature(sig, msg, pk);
3051
+ case exports.PrefixV2.Ed25519PublicKey:
3052
+ return verifyEdSignature(sig, msg, pk);
3053
+ default:
3054
+ return verifyBLSSignature(sig, msg, pk);
3055
+ }
1320
3056
  }
1321
3057
  }
1322
- function compareArrays(a, b) {
1323
- let i = 0;
1324
- while (i < a.length && i < b.length && a[i] === b[i])
1325
- i++;
1326
- const aa = i < a.length ? a[i] : 0;
1327
- const bb = i < b.length ? b[i] : 0;
1328
- return aa < bb ? -1 : aa > bb ? 1 : 0;
3058
+ function verifyEdSignature(sig, msg, publicKey) {
3059
+ const hash = blake2b.hash(msg, 32);
3060
+ try {
3061
+ return ed25519.verify(publicKey, hash, sig);
3062
+ }
3063
+ catch (_a) {
3064
+ return false;
3065
+ }
1329
3066
  }
1330
- /**
1331
- * @deprecated use b58DecodeAndCheckPrefix instead, this function will be removed in the next minor release
1332
- * @description Base58 decode a string and remove the prefix from it
1333
- * @param enc Value to base58 decode
1334
- * @param prefixArg prefix to remove from the decoded string
1335
- */
1336
- function b58cdecode(enc, prefixArg) {
1337
- return bs58check.decode(enc).slice(prefixArg.length);
3067
+ function verifySpSignature(sig, msg, publicKey) {
3068
+ const hash = blake2b.hash(msg, 32);
3069
+ try {
3070
+ return secp256k1.secp256k1.verify(sig, hash, publicKey);
3071
+ }
3072
+ catch (_a) {
3073
+ return false;
3074
+ }
1338
3075
  }
1339
- /**
1340
- * @deprecated use b58Encode instead, this function will be removed in the next minor release
1341
- * @description Base58 encode a string or a Uint8Array and append a prefix to it
1342
- * @param value Value to base58 encode
1343
- * @param prefix prefix to append to the encoded string
1344
- */
1345
- function b58cencode(value, prefix) {
1346
- const payloadAr = typeof value === 'string' ? hex2buf(value) : value;
1347
- const n = new Uint8Array(prefix.length + payloadAr.length);
1348
- n.set(prefix);
1349
- n.set(payloadAr, prefix.length);
1350
- return bs58check.encode(toBuffer(n));
3076
+ function verifyP2Signature(sig, msg, publicKey) {
3077
+ const hash = blake2b.hash(msg, 32);
3078
+ try {
3079
+ return nist.p256.verify(sig, hash, publicKey);
3080
+ }
3081
+ catch (_a) {
3082
+ return false;
3083
+ }
1351
3084
  }
1352
- /**
1353
- * @deprecated use b58DecodePublicKey, b58DecodePublicKeyHash, b58DecodeBlsAddress, b58DecodeAddress instead, this function will be removed in the next minor release
1354
- * @description Base58 decode a string with predefined prefix
1355
- * @param payload Value to base58 decode
1356
- */
1357
- function b58decode(payload) {
1358
- const buf = bs58check.decode(payload);
1359
- const prefixMap = {
1360
- [prefix.tz1.toString()]: '0000',
1361
- [prefix.tz2.toString()]: '0001',
1362
- [prefix.tz3.toString()]: '0002',
1363
- [prefix.tz4.toString()]: '0003',
1364
- };
1365
- const pref = prefixMap[new Uint8Array(buf.slice(0, 3)).toString()];
1366
- if (pref) {
1367
- // tz addresses
1368
- const hex = buf2hex(buf.slice(3));
1369
- return pref + hex;
3085
+ const bls = bls12381.bls12_381.longSignatures; // AKA MinPK
3086
+ function verifyBLSSignature(sig, msg, publicKey) {
3087
+ try {
3088
+ const point = bls.hash(msg, BLS12_381_DST);
3089
+ return bls.verify(sig, point, publicKey);
1370
3090
  }
1371
- else {
1372
- // other (kt addresses)
1373
- return '01' + buf2hex(buf.slice(3, 42)) + '00';
3091
+ catch (_a) {
3092
+ return false;
1374
3093
  }
1375
3094
  }
1376
- /**
1377
- * @deprecated use b58DecodeBlsAddress instead, this function will be removed in the next minor release
1378
- * @description b58 decode a string without predefined prefix
1379
- * @param payload Value to base58 decode
1380
- * @returns string of bytes
1381
- */
1382
- function b58decodeL2Address(payload) {
1383
- const buf = bs58check.decode(payload);
1384
- // tz4 address currently
1385
- return buf2hex(buf.slice(3, 42));
3095
+ function verifyBLSPopSignature(sig, msg, publicKey) {
3096
+ try {
3097
+ const point = bls.hash(msg, POP_DST);
3098
+ return bls.verify(sig, point, publicKey);
3099
+ }
3100
+ catch (_a) {
3101
+ return false;
3102
+ }
1386
3103
  }
3104
+
1387
3105
  /**
1388
- * @deprecated use encodeAddress instead, this function will be removed in the next minor release
1389
- * @description Base58 encode an address using predefined prefix
1390
- * @param value Address to base58 encode (tz1, tz2, tz3 or KT1)
3106
+ * @category Error
3107
+ * @description Error that indicates invalid protocol hash being passed or used
1391
3108
  */
1392
- function encodePubKey(value) {
1393
- return encodeAddress(value);
3109
+ class InvalidProtocolHashError extends core.ParameterValidationError {
3110
+ constructor(protocolHash, errorDetails) {
3111
+ super(`The protocol hash '${protocolHash}' is invalid`, errorDetails);
3112
+ this.protocolHash = protocolHash;
3113
+ this.name = 'InvalidProtocolHashError';
3114
+ this.name = this.constructor.name;
3115
+ }
1394
3116
  }
1395
3117
  /**
1396
- * @deprecated use encodeBlsAddress instead, this function will be removed in the next minor release
1397
- * @description Base58 encode an address without predefined prefix
1398
- * @param value Address to base58 encode (tz4) hex dec
1399
- * @returns return address
3118
+ * @category Error
3119
+ * @description Error that indicates unable to convert data type from one to another
1400
3120
  */
1401
- function encodeL2Address(value) {
1402
- return b58cencode(value, prefix.tz4);
3121
+ class ValueConversionError extends core.UnsupportedActionError {
3122
+ constructor(value, desiredType) {
3123
+ super(`Unable to convert ${value} to a ${desiredType}`);
3124
+ this.value = value;
3125
+ this.desiredType = desiredType;
3126
+ this.name = this.constructor.name;
3127
+ }
1403
3128
  }
1404
- /**
1405
- * @deprecated use stringToBytes instead, this function will be removed in the next minor release
1406
- * @description Convert a string to bytes
1407
- * @param str String to convert
1408
- */
1409
- function char2Bytes(str) {
1410
- return buffer.Buffer.from(str, 'utf8').toString('hex');
3129
+
3130
+ const TZ_DECIMALS = 6;
3131
+ const MTZ_DECIMALS = 3;
3132
+ function getDecimal(format) {
3133
+ switch (format) {
3134
+ case 'tz':
3135
+ return TZ_DECIMALS;
3136
+ case 'mtz':
3137
+ return MTZ_DECIMALS;
3138
+ case 'mutez':
3139
+ default:
3140
+ return 0;
3141
+ }
1411
3142
  }
1412
- /**
1413
- * @deprecated use bytesToString instead, this function will be removed in the next minor release
1414
- * @description Convert bytes to a string
1415
- * @param hex Bytes to convert
1416
- */
1417
- function bytes2Char(hex) {
1418
- return buffer.Buffer.from(hex2buf(hex)).toString('utf8');
3143
+ function format(from = 'mutez', to = 'mutez', amount) {
3144
+ const bigNum = new BigNumber(amount);
3145
+ if (bigNum.isNaN()) {
3146
+ return amount;
3147
+ }
3148
+ return bigNum
3149
+ .multipliedBy(Math.pow(10, getDecimal(from)))
3150
+ .dividedBy(Math.pow(10, getDecimal(to)));
1419
3151
  }
1420
3152
 
1421
3153
  Object.defineProperty(exports, "DeprecationError", {
@@ -1490,36 +3222,25 @@
1490
3222
  exports.b58DecodePublicKey = b58DecodePublicKey;
1491
3223
  exports.b58DecodePublicKeyHash = b58DecodePublicKeyHash;
1492
3224
  exports.b58Encode = b58Encode;
1493
- exports.b58cdecode = b58cdecode;
1494
- exports.b58cencode = b58cencode;
1495
- exports.b58decode = b58decode;
1496
- exports.b58decodeL2Address = b58decodeL2Address;
1497
3225
  exports.buf2hex = buf2hex;
1498
- exports.bytes2Char = bytes2Char;
1499
3226
  exports.bytesToString = bytesToString;
1500
- exports.char2Bytes = char2Bytes;
1501
3227
  exports.compareArrays = compareArrays;
1502
3228
  exports.encodeAddress = encodeAddress;
1503
3229
  exports.encodeBlsAddress = encodeBlsAddress;
1504
3230
  exports.encodeExpr = encodeExpr;
1505
3231
  exports.encodeKey = encodeKey;
1506
3232
  exports.encodeKeyHash = encodeKeyHash;
1507
- exports.encodeL2Address = encodeL2Address;
1508
3233
  exports.encodeOpHash = encodeOpHash;
1509
- exports.encodePubKey = encodePubKey;
1510
3234
  exports.format = format;
1511
3235
  exports.getPkhfromPk = getPkhfromPk;
1512
3236
  exports.hex2Bytes = hex2Bytes;
1513
3237
  exports.hex2buf = hex2buf;
1514
- exports.invalidDetail = invalidDetail;
1515
3238
  exports.isValidPrefixedValue = isValidPrefixedValue;
1516
3239
  exports.mergebuf = mergebuf;
1517
3240
  exports.mic2arr = mic2arr;
1518
3241
  exports.num2PaddedHex = num2PaddedHex;
1519
3242
  exports.numToHexBuffer = numToHexBuffer;
1520
3243
  exports.payloadLength = payloadLength;
1521
- exports.prefix = prefix;
1522
- exports.prefixLength = prefixLength;
1523
3244
  exports.publicKeyHashPrefixes = publicKeyHashPrefixes;
1524
3245
  exports.publicKeyPrefixes = publicKeyPrefixes;
1525
3246
  exports.signaturePrefixes = signaturePrefixes;
@@ -1533,7 +3254,6 @@
1533
3254
  exports.validateContractAddress = validateContractAddress;
1534
3255
  exports.validateKeyHash = validateKeyHash;
1535
3256
  exports.validateOperation = validateOperation;
1536
- exports.validatePkAndExtractPrefix = validatePkAndExtractPrefix;
1537
3257
  exports.validateProtocol = validateProtocol;
1538
3258
  exports.validatePublicKey = validatePublicKey;
1539
3259
  exports.validateSignature = validateSignature;