@solana/web3.js 1.54.0 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.cjs.js +117 -1798
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +117 -1798
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +117 -1819
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -6
- package/lib/index.esm.js +117 -1819
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +19245 -26059
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +8 -5
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +117 -1798
- package/lib/index.native.js.map +1 -1
- package/package.json +5 -6
- package/src/account.ts +18 -9
- package/src/keypair.ts +19 -24
- package/src/programs/ed25519.ts +2 -2
- package/src/programs/secp256k1.ts +6 -5
- package/src/publickey.ts +7 -71
- package/src/transaction/legacy.ts +3 -5
- package/src/transaction/versioned.ts +2 -5
- package/src/utils/ed25519.ts +46 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/secp256k1.ts +18 -0
package/lib/index.browser.esm.js
CHANGED
|
@@ -1,1732 +1,64 @@
|
|
|
1
|
-
import nacl from 'tweetnacl';
|
|
2
1
|
import { Buffer } from 'buffer';
|
|
2
|
+
import { sha512 } from '@noble/hashes/sha512';
|
|
3
|
+
import * as ed25519 from '@noble/ed25519';
|
|
3
4
|
import BN from 'bn.js';
|
|
4
5
|
import bs58 from 'bs58';
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
5
7
|
import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
6
8
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
7
9
|
import { blob } from '@solana/buffer-layout';
|
|
8
10
|
import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
9
|
-
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$
|
|
11
|
+
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$1 } from 'superstruct';
|
|
10
12
|
import { Client } from 'rpc-websockets';
|
|
11
13
|
import RpcClient from 'jayson/lib/client/browser';
|
|
12
|
-
import secp256k1 from 'secp256k1';
|
|
13
14
|
import sha3 from 'js-sha3';
|
|
15
|
+
import { hmac } from '@noble/hashes/hmac';
|
|
16
|
+
import * as secp256k1 from '@noble/secp256k1';
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
return Buffer.from(arr);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
var hash$1 = {};
|
|
26
|
-
|
|
27
|
-
var utils$9 = {};
|
|
28
|
-
|
|
29
|
-
var minimalisticAssert = assert$6;
|
|
30
|
-
|
|
31
|
-
function assert$6(val, msg) {
|
|
32
|
-
if (!val)
|
|
33
|
-
throw new Error(msg || 'Assertion failed');
|
|
34
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* A 64 byte secret key, the first 32 bytes of which is the
|
|
20
|
+
* private scalar and the last 32 bytes is the public key.
|
|
21
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
22
|
+
*/
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
if (l != r)
|
|
38
|
-
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
|
39
|
-
};
|
|
24
|
+
ed25519.utils.sha512Sync = (...m) => sha512(ed25519.utils.concatBytes(...m));
|
|
40
25
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
enumerable: false,
|
|
52
|
-
writable: true,
|
|
53
|
-
configurable: true
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
} else {
|
|
59
|
-
// old school shim for old browsers
|
|
60
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
61
|
-
if (superCtor) {
|
|
62
|
-
ctor.super_ = superCtor;
|
|
63
|
-
var TempCtor = function () {};
|
|
64
|
-
TempCtor.prototype = superCtor.prototype;
|
|
65
|
-
ctor.prototype = new TempCtor();
|
|
66
|
-
ctor.prototype.constructor = ctor;
|
|
67
|
-
}
|
|
26
|
+
const generatePrivateKey = ed25519.utils.randomPrivateKey;
|
|
27
|
+
const generateKeypair = () => {
|
|
28
|
+
const privateScalar = ed25519.utils.randomPrivateKey();
|
|
29
|
+
const publicKey = getPublicKey(privateScalar);
|
|
30
|
+
const secretKey = new Uint8Array(64);
|
|
31
|
+
secretKey.set(privateScalar);
|
|
32
|
+
secretKey.set(publicKey, 32);
|
|
33
|
+
return {
|
|
34
|
+
publicKey,
|
|
35
|
+
secretKey
|
|
68
36
|
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
if (i < 0 || i + 1 >= msg.length) {
|
|
37
|
+
};
|
|
38
|
+
const getPublicKey = ed25519.sync.getPublicKey;
|
|
39
|
+
function isOnCurve(publicKey) {
|
|
40
|
+
try {
|
|
41
|
+
ed25519.Point.fromHex(publicKey, true
|
|
42
|
+
/* strict */
|
|
43
|
+
);
|
|
44
|
+
return true;
|
|
45
|
+
} catch {
|
|
81
46
|
return false;
|
|
82
47
|
}
|
|
83
|
-
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function toArray(msg, enc) {
|
|
87
|
-
if (Array.isArray(msg))
|
|
88
|
-
return msg.slice();
|
|
89
|
-
if (!msg)
|
|
90
|
-
return [];
|
|
91
|
-
var res = [];
|
|
92
|
-
if (typeof msg === 'string') {
|
|
93
|
-
if (!enc) {
|
|
94
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
95
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
96
|
-
// Apache License 2.0
|
|
97
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
98
|
-
var p = 0;
|
|
99
|
-
for (var i = 0; i < msg.length; i++) {
|
|
100
|
-
var c = msg.charCodeAt(i);
|
|
101
|
-
if (c < 128) {
|
|
102
|
-
res[p++] = c;
|
|
103
|
-
} else if (c < 2048) {
|
|
104
|
-
res[p++] = (c >> 6) | 192;
|
|
105
|
-
res[p++] = (c & 63) | 128;
|
|
106
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
107
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
108
|
-
res[p++] = (c >> 18) | 240;
|
|
109
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
110
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
111
|
-
res[p++] = (c & 63) | 128;
|
|
112
|
-
} else {
|
|
113
|
-
res[p++] = (c >> 12) | 224;
|
|
114
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
115
|
-
res[p++] = (c & 63) | 128;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} else if (enc === 'hex') {
|
|
119
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
120
|
-
if (msg.length % 2 !== 0)
|
|
121
|
-
msg = '0' + msg;
|
|
122
|
-
for (i = 0; i < msg.length; i += 2)
|
|
123
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
for (i = 0; i < msg.length; i++)
|
|
127
|
-
res[i] = msg[i] | 0;
|
|
128
|
-
}
|
|
129
|
-
return res;
|
|
130
|
-
}
|
|
131
|
-
utils$9.toArray = toArray;
|
|
132
|
-
|
|
133
|
-
function toHex(msg) {
|
|
134
|
-
var res = '';
|
|
135
|
-
for (var i = 0; i < msg.length; i++)
|
|
136
|
-
res += zero2(msg[i].toString(16));
|
|
137
|
-
return res;
|
|
138
|
-
}
|
|
139
|
-
utils$9.toHex = toHex;
|
|
140
|
-
|
|
141
|
-
function htonl(w) {
|
|
142
|
-
var res = (w >>> 24) |
|
|
143
|
-
((w >>> 8) & 0xff00) |
|
|
144
|
-
((w << 8) & 0xff0000) |
|
|
145
|
-
((w & 0xff) << 24);
|
|
146
|
-
return res >>> 0;
|
|
147
|
-
}
|
|
148
|
-
utils$9.htonl = htonl;
|
|
149
|
-
|
|
150
|
-
function toHex32(msg, endian) {
|
|
151
|
-
var res = '';
|
|
152
|
-
for (var i = 0; i < msg.length; i++) {
|
|
153
|
-
var w = msg[i];
|
|
154
|
-
if (endian === 'little')
|
|
155
|
-
w = htonl(w);
|
|
156
|
-
res += zero8(w.toString(16));
|
|
157
|
-
}
|
|
158
|
-
return res;
|
|
159
|
-
}
|
|
160
|
-
utils$9.toHex32 = toHex32;
|
|
161
|
-
|
|
162
|
-
function zero2(word) {
|
|
163
|
-
if (word.length === 1)
|
|
164
|
-
return '0' + word;
|
|
165
|
-
else
|
|
166
|
-
return word;
|
|
167
|
-
}
|
|
168
|
-
utils$9.zero2 = zero2;
|
|
169
|
-
|
|
170
|
-
function zero8(word) {
|
|
171
|
-
if (word.length === 7)
|
|
172
|
-
return '0' + word;
|
|
173
|
-
else if (word.length === 6)
|
|
174
|
-
return '00' + word;
|
|
175
|
-
else if (word.length === 5)
|
|
176
|
-
return '000' + word;
|
|
177
|
-
else if (word.length === 4)
|
|
178
|
-
return '0000' + word;
|
|
179
|
-
else if (word.length === 3)
|
|
180
|
-
return '00000' + word;
|
|
181
|
-
else if (word.length === 2)
|
|
182
|
-
return '000000' + word;
|
|
183
|
-
else if (word.length === 1)
|
|
184
|
-
return '0000000' + word;
|
|
185
|
-
else
|
|
186
|
-
return word;
|
|
187
|
-
}
|
|
188
|
-
utils$9.zero8 = zero8;
|
|
189
|
-
|
|
190
|
-
function join32(msg, start, end, endian) {
|
|
191
|
-
var len = end - start;
|
|
192
|
-
assert$5(len % 4 === 0);
|
|
193
|
-
var res = new Array(len / 4);
|
|
194
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
195
|
-
var w;
|
|
196
|
-
if (endian === 'big')
|
|
197
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
198
|
-
else
|
|
199
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
200
|
-
res[i] = w >>> 0;
|
|
201
|
-
}
|
|
202
|
-
return res;
|
|
203
|
-
}
|
|
204
|
-
utils$9.join32 = join32;
|
|
205
|
-
|
|
206
|
-
function split32(msg, endian) {
|
|
207
|
-
var res = new Array(msg.length * 4);
|
|
208
|
-
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
209
|
-
var m = msg[i];
|
|
210
|
-
if (endian === 'big') {
|
|
211
|
-
res[k] = m >>> 24;
|
|
212
|
-
res[k + 1] = (m >>> 16) & 0xff;
|
|
213
|
-
res[k + 2] = (m >>> 8) & 0xff;
|
|
214
|
-
res[k + 3] = m & 0xff;
|
|
215
|
-
} else {
|
|
216
|
-
res[k + 3] = m >>> 24;
|
|
217
|
-
res[k + 2] = (m >>> 16) & 0xff;
|
|
218
|
-
res[k + 1] = (m >>> 8) & 0xff;
|
|
219
|
-
res[k] = m & 0xff;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return res;
|
|
223
|
-
}
|
|
224
|
-
utils$9.split32 = split32;
|
|
225
|
-
|
|
226
|
-
function rotr32$1(w, b) {
|
|
227
|
-
return (w >>> b) | (w << (32 - b));
|
|
228
|
-
}
|
|
229
|
-
utils$9.rotr32 = rotr32$1;
|
|
230
|
-
|
|
231
|
-
function rotl32$2(w, b) {
|
|
232
|
-
return (w << b) | (w >>> (32 - b));
|
|
233
|
-
}
|
|
234
|
-
utils$9.rotl32 = rotl32$2;
|
|
235
|
-
|
|
236
|
-
function sum32$3(a, b) {
|
|
237
|
-
return (a + b) >>> 0;
|
|
238
|
-
}
|
|
239
|
-
utils$9.sum32 = sum32$3;
|
|
240
|
-
|
|
241
|
-
function sum32_3$1(a, b, c) {
|
|
242
|
-
return (a + b + c) >>> 0;
|
|
243
|
-
}
|
|
244
|
-
utils$9.sum32_3 = sum32_3$1;
|
|
245
|
-
|
|
246
|
-
function sum32_4$2(a, b, c, d) {
|
|
247
|
-
return (a + b + c + d) >>> 0;
|
|
248
|
-
}
|
|
249
|
-
utils$9.sum32_4 = sum32_4$2;
|
|
250
|
-
|
|
251
|
-
function sum32_5$2(a, b, c, d, e) {
|
|
252
|
-
return (a + b + c + d + e) >>> 0;
|
|
253
|
-
}
|
|
254
|
-
utils$9.sum32_5 = sum32_5$2;
|
|
255
|
-
|
|
256
|
-
function sum64$1(buf, pos, ah, al) {
|
|
257
|
-
var bh = buf[pos];
|
|
258
|
-
var bl = buf[pos + 1];
|
|
259
|
-
|
|
260
|
-
var lo = (al + bl) >>> 0;
|
|
261
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
262
|
-
buf[pos] = hi >>> 0;
|
|
263
|
-
buf[pos + 1] = lo;
|
|
264
|
-
}
|
|
265
|
-
utils$9.sum64 = sum64$1;
|
|
266
|
-
|
|
267
|
-
function sum64_hi$1(ah, al, bh, bl) {
|
|
268
|
-
var lo = (al + bl) >>> 0;
|
|
269
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
270
|
-
return hi >>> 0;
|
|
271
|
-
}
|
|
272
|
-
utils$9.sum64_hi = sum64_hi$1;
|
|
273
|
-
|
|
274
|
-
function sum64_lo$1(ah, al, bh, bl) {
|
|
275
|
-
var lo = al + bl;
|
|
276
|
-
return lo >>> 0;
|
|
277
|
-
}
|
|
278
|
-
utils$9.sum64_lo = sum64_lo$1;
|
|
279
|
-
|
|
280
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
281
|
-
var carry = 0;
|
|
282
|
-
var lo = al;
|
|
283
|
-
lo = (lo + bl) >>> 0;
|
|
284
|
-
carry += lo < al ? 1 : 0;
|
|
285
|
-
lo = (lo + cl) >>> 0;
|
|
286
|
-
carry += lo < cl ? 1 : 0;
|
|
287
|
-
lo = (lo + dl) >>> 0;
|
|
288
|
-
carry += lo < dl ? 1 : 0;
|
|
289
|
-
|
|
290
|
-
var hi = ah + bh + ch + dh + carry;
|
|
291
|
-
return hi >>> 0;
|
|
292
|
-
}
|
|
293
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
294
|
-
|
|
295
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
296
|
-
var lo = al + bl + cl + dl;
|
|
297
|
-
return lo >>> 0;
|
|
298
|
-
}
|
|
299
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
300
|
-
|
|
301
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
302
|
-
var carry = 0;
|
|
303
|
-
var lo = al;
|
|
304
|
-
lo = (lo + bl) >>> 0;
|
|
305
|
-
carry += lo < al ? 1 : 0;
|
|
306
|
-
lo = (lo + cl) >>> 0;
|
|
307
|
-
carry += lo < cl ? 1 : 0;
|
|
308
|
-
lo = (lo + dl) >>> 0;
|
|
309
|
-
carry += lo < dl ? 1 : 0;
|
|
310
|
-
lo = (lo + el) >>> 0;
|
|
311
|
-
carry += lo < el ? 1 : 0;
|
|
312
|
-
|
|
313
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
314
|
-
return hi >>> 0;
|
|
315
|
-
}
|
|
316
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
317
|
-
|
|
318
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
319
|
-
var lo = al + bl + cl + dl + el;
|
|
320
|
-
|
|
321
|
-
return lo >>> 0;
|
|
322
|
-
}
|
|
323
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
324
|
-
|
|
325
|
-
function rotr64_hi$1(ah, al, num) {
|
|
326
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
327
|
-
return r >>> 0;
|
|
328
|
-
}
|
|
329
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
330
|
-
|
|
331
|
-
function rotr64_lo$1(ah, al, num) {
|
|
332
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
333
|
-
return r >>> 0;
|
|
334
|
-
}
|
|
335
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
336
|
-
|
|
337
|
-
function shr64_hi$1(ah, al, num) {
|
|
338
|
-
return ah >>> num;
|
|
339
|
-
}
|
|
340
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
341
|
-
|
|
342
|
-
function shr64_lo$1(ah, al, num) {
|
|
343
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
344
|
-
return r >>> 0;
|
|
345
|
-
}
|
|
346
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
347
|
-
|
|
348
|
-
var common$5 = {};
|
|
349
|
-
|
|
350
|
-
var utils$8 = utils$9;
|
|
351
|
-
var assert$4 = minimalisticAssert;
|
|
352
|
-
|
|
353
|
-
function BlockHash$4() {
|
|
354
|
-
this.pending = null;
|
|
355
|
-
this.pendingTotal = 0;
|
|
356
|
-
this.blockSize = this.constructor.blockSize;
|
|
357
|
-
this.outSize = this.constructor.outSize;
|
|
358
|
-
this.hmacStrength = this.constructor.hmacStrength;
|
|
359
|
-
this.padLength = this.constructor.padLength / 8;
|
|
360
|
-
this.endian = 'big';
|
|
361
|
-
|
|
362
|
-
this._delta8 = this.blockSize / 8;
|
|
363
|
-
this._delta32 = this.blockSize / 32;
|
|
364
48
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
368
|
-
// Convert message to array, pad it, and join into 32bit blocks
|
|
369
|
-
msg = utils$8.toArray(msg, enc);
|
|
370
|
-
if (!this.pending)
|
|
371
|
-
this.pending = msg;
|
|
372
|
-
else
|
|
373
|
-
this.pending = this.pending.concat(msg);
|
|
374
|
-
this.pendingTotal += msg.length;
|
|
375
|
-
|
|
376
|
-
// Enough data, try updating
|
|
377
|
-
if (this.pending.length >= this._delta8) {
|
|
378
|
-
msg = this.pending;
|
|
379
|
-
|
|
380
|
-
// Process pending data in blocks
|
|
381
|
-
var r = msg.length % this._delta8;
|
|
382
|
-
this.pending = msg.slice(msg.length - r, msg.length);
|
|
383
|
-
if (this.pending.length === 0)
|
|
384
|
-
this.pending = null;
|
|
385
|
-
|
|
386
|
-
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
387
|
-
for (var i = 0; i < msg.length; i += this._delta32)
|
|
388
|
-
this._update(msg, i, i + this._delta32);
|
|
389
|
-
}
|
|
49
|
+
const sign = (message, secretKey) => ed25519.sync.sign(message, secretKey.slice(0, 32));
|
|
50
|
+
const verify = ed25519.sync.verify;
|
|
390
51
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
assert$4(this.pending === null);
|
|
397
|
-
|
|
398
|
-
return this._digest(enc);
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
BlockHash$4.prototype._pad = function pad() {
|
|
402
|
-
var len = this.pendingTotal;
|
|
403
|
-
var bytes = this._delta8;
|
|
404
|
-
var k = bytes - ((len + this.padLength) % bytes);
|
|
405
|
-
var res = new Array(k + this.padLength);
|
|
406
|
-
res[0] = 0x80;
|
|
407
|
-
for (var i = 1; i < k; i++)
|
|
408
|
-
res[i] = 0;
|
|
409
|
-
|
|
410
|
-
// Append length
|
|
411
|
-
len <<= 3;
|
|
412
|
-
if (this.endian === 'big') {
|
|
413
|
-
for (var t = 8; t < this.padLength; t++)
|
|
414
|
-
res[i++] = 0;
|
|
415
|
-
|
|
416
|
-
res[i++] = 0;
|
|
417
|
-
res[i++] = 0;
|
|
418
|
-
res[i++] = 0;
|
|
419
|
-
res[i++] = 0;
|
|
420
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
421
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
422
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
423
|
-
res[i++] = len & 0xff;
|
|
52
|
+
const toBuffer = arr => {
|
|
53
|
+
if (Buffer.isBuffer(arr)) {
|
|
54
|
+
return arr;
|
|
55
|
+
} else if (arr instanceof Uint8Array) {
|
|
56
|
+
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
424
57
|
} else {
|
|
425
|
-
|
|
426
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
427
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
428
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
429
|
-
res[i++] = 0;
|
|
430
|
-
res[i++] = 0;
|
|
431
|
-
res[i++] = 0;
|
|
432
|
-
res[i++] = 0;
|
|
433
|
-
|
|
434
|
-
for (t = 8; t < this.padLength; t++)
|
|
435
|
-
res[i++] = 0;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return res;
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
var sha = {};
|
|
442
|
-
|
|
443
|
-
var common$4 = {};
|
|
444
|
-
|
|
445
|
-
var utils$7 = utils$9;
|
|
446
|
-
var rotr32 = utils$7.rotr32;
|
|
447
|
-
|
|
448
|
-
function ft_1$1(s, x, y, z) {
|
|
449
|
-
if (s === 0)
|
|
450
|
-
return ch32$1(x, y, z);
|
|
451
|
-
if (s === 1 || s === 3)
|
|
452
|
-
return p32(x, y, z);
|
|
453
|
-
if (s === 2)
|
|
454
|
-
return maj32$1(x, y, z);
|
|
455
|
-
}
|
|
456
|
-
common$4.ft_1 = ft_1$1;
|
|
457
|
-
|
|
458
|
-
function ch32$1(x, y, z) {
|
|
459
|
-
return (x & y) ^ ((~x) & z);
|
|
460
|
-
}
|
|
461
|
-
common$4.ch32 = ch32$1;
|
|
462
|
-
|
|
463
|
-
function maj32$1(x, y, z) {
|
|
464
|
-
return (x & y) ^ (x & z) ^ (y & z);
|
|
465
|
-
}
|
|
466
|
-
common$4.maj32 = maj32$1;
|
|
467
|
-
|
|
468
|
-
function p32(x, y, z) {
|
|
469
|
-
return x ^ y ^ z;
|
|
470
|
-
}
|
|
471
|
-
common$4.p32 = p32;
|
|
472
|
-
|
|
473
|
-
function s0_256$1(x) {
|
|
474
|
-
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
475
|
-
}
|
|
476
|
-
common$4.s0_256 = s0_256$1;
|
|
477
|
-
|
|
478
|
-
function s1_256$1(x) {
|
|
479
|
-
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
480
|
-
}
|
|
481
|
-
common$4.s1_256 = s1_256$1;
|
|
482
|
-
|
|
483
|
-
function g0_256$1(x) {
|
|
484
|
-
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
485
|
-
}
|
|
486
|
-
common$4.g0_256 = g0_256$1;
|
|
487
|
-
|
|
488
|
-
function g1_256$1(x) {
|
|
489
|
-
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
490
|
-
}
|
|
491
|
-
common$4.g1_256 = g1_256$1;
|
|
492
|
-
|
|
493
|
-
var utils$6 = utils$9;
|
|
494
|
-
var common$3 = common$5;
|
|
495
|
-
var shaCommon$1 = common$4;
|
|
496
|
-
|
|
497
|
-
var rotl32$1 = utils$6.rotl32;
|
|
498
|
-
var sum32$2 = utils$6.sum32;
|
|
499
|
-
var sum32_5$1 = utils$6.sum32_5;
|
|
500
|
-
var ft_1 = shaCommon$1.ft_1;
|
|
501
|
-
var BlockHash$3 = common$3.BlockHash;
|
|
502
|
-
|
|
503
|
-
var sha1_K = [
|
|
504
|
-
0x5A827999, 0x6ED9EBA1,
|
|
505
|
-
0x8F1BBCDC, 0xCA62C1D6
|
|
506
|
-
];
|
|
507
|
-
|
|
508
|
-
function SHA1() {
|
|
509
|
-
if (!(this instanceof SHA1))
|
|
510
|
-
return new SHA1();
|
|
511
|
-
|
|
512
|
-
BlockHash$3.call(this);
|
|
513
|
-
this.h = [
|
|
514
|
-
0x67452301, 0xefcdab89, 0x98badcfe,
|
|
515
|
-
0x10325476, 0xc3d2e1f0 ];
|
|
516
|
-
this.W = new Array(80);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
utils$6.inherits(SHA1, BlockHash$3);
|
|
520
|
-
var _1 = SHA1;
|
|
521
|
-
|
|
522
|
-
SHA1.blockSize = 512;
|
|
523
|
-
SHA1.outSize = 160;
|
|
524
|
-
SHA1.hmacStrength = 80;
|
|
525
|
-
SHA1.padLength = 64;
|
|
526
|
-
|
|
527
|
-
SHA1.prototype._update = function _update(msg, start) {
|
|
528
|
-
var W = this.W;
|
|
529
|
-
|
|
530
|
-
for (var i = 0; i < 16; i++)
|
|
531
|
-
W[i] = msg[start + i];
|
|
532
|
-
|
|
533
|
-
for(; i < W.length; i++)
|
|
534
|
-
W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
|
|
535
|
-
|
|
536
|
-
var a = this.h[0];
|
|
537
|
-
var b = this.h[1];
|
|
538
|
-
var c = this.h[2];
|
|
539
|
-
var d = this.h[3];
|
|
540
|
-
var e = this.h[4];
|
|
541
|
-
|
|
542
|
-
for (i = 0; i < W.length; i++) {
|
|
543
|
-
var s = ~~(i / 20);
|
|
544
|
-
var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
|
|
545
|
-
e = d;
|
|
546
|
-
d = c;
|
|
547
|
-
c = rotl32$1(b, 30);
|
|
548
|
-
b = a;
|
|
549
|
-
a = t;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
this.h[0] = sum32$2(this.h[0], a);
|
|
553
|
-
this.h[1] = sum32$2(this.h[1], b);
|
|
554
|
-
this.h[2] = sum32$2(this.h[2], c);
|
|
555
|
-
this.h[3] = sum32$2(this.h[3], d);
|
|
556
|
-
this.h[4] = sum32$2(this.h[4], e);
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
SHA1.prototype._digest = function digest(enc) {
|
|
560
|
-
if (enc === 'hex')
|
|
561
|
-
return utils$6.toHex32(this.h, 'big');
|
|
562
|
-
else
|
|
563
|
-
return utils$6.split32(this.h, 'big');
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
var utils$5 = utils$9;
|
|
567
|
-
var common$2 = common$5;
|
|
568
|
-
var shaCommon = common$4;
|
|
569
|
-
var assert$3 = minimalisticAssert;
|
|
570
|
-
|
|
571
|
-
var sum32$1 = utils$5.sum32;
|
|
572
|
-
var sum32_4$1 = utils$5.sum32_4;
|
|
573
|
-
var sum32_5 = utils$5.sum32_5;
|
|
574
|
-
var ch32 = shaCommon.ch32;
|
|
575
|
-
var maj32 = shaCommon.maj32;
|
|
576
|
-
var s0_256 = shaCommon.s0_256;
|
|
577
|
-
var s1_256 = shaCommon.s1_256;
|
|
578
|
-
var g0_256 = shaCommon.g0_256;
|
|
579
|
-
var g1_256 = shaCommon.g1_256;
|
|
580
|
-
|
|
581
|
-
var BlockHash$2 = common$2.BlockHash;
|
|
582
|
-
|
|
583
|
-
var sha256_K = [
|
|
584
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
585
|
-
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
586
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
587
|
-
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
588
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
589
|
-
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
590
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
591
|
-
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
592
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
593
|
-
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
594
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
595
|
-
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
596
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
597
|
-
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
598
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
599
|
-
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
600
|
-
];
|
|
601
|
-
|
|
602
|
-
function SHA256$1() {
|
|
603
|
-
if (!(this instanceof SHA256$1))
|
|
604
|
-
return new SHA256$1();
|
|
605
|
-
|
|
606
|
-
BlockHash$2.call(this);
|
|
607
|
-
this.h = [
|
|
608
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
609
|
-
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
610
|
-
];
|
|
611
|
-
this.k = sha256_K;
|
|
612
|
-
this.W = new Array(64);
|
|
613
|
-
}
|
|
614
|
-
utils$5.inherits(SHA256$1, BlockHash$2);
|
|
615
|
-
var _256 = SHA256$1;
|
|
616
|
-
|
|
617
|
-
SHA256$1.blockSize = 512;
|
|
618
|
-
SHA256$1.outSize = 256;
|
|
619
|
-
SHA256$1.hmacStrength = 192;
|
|
620
|
-
SHA256$1.padLength = 64;
|
|
621
|
-
|
|
622
|
-
SHA256$1.prototype._update = function _update(msg, start) {
|
|
623
|
-
var W = this.W;
|
|
624
|
-
|
|
625
|
-
for (var i = 0; i < 16; i++)
|
|
626
|
-
W[i] = msg[start + i];
|
|
627
|
-
for (; i < W.length; i++)
|
|
628
|
-
W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
|
|
629
|
-
|
|
630
|
-
var a = this.h[0];
|
|
631
|
-
var b = this.h[1];
|
|
632
|
-
var c = this.h[2];
|
|
633
|
-
var d = this.h[3];
|
|
634
|
-
var e = this.h[4];
|
|
635
|
-
var f = this.h[5];
|
|
636
|
-
var g = this.h[6];
|
|
637
|
-
var h = this.h[7];
|
|
638
|
-
|
|
639
|
-
assert$3(this.k.length === W.length);
|
|
640
|
-
for (i = 0; i < W.length; i++) {
|
|
641
|
-
var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
|
642
|
-
var T2 = sum32$1(s0_256(a), maj32(a, b, c));
|
|
643
|
-
h = g;
|
|
644
|
-
g = f;
|
|
645
|
-
f = e;
|
|
646
|
-
e = sum32$1(d, T1);
|
|
647
|
-
d = c;
|
|
648
|
-
c = b;
|
|
649
|
-
b = a;
|
|
650
|
-
a = sum32$1(T1, T2);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
this.h[0] = sum32$1(this.h[0], a);
|
|
654
|
-
this.h[1] = sum32$1(this.h[1], b);
|
|
655
|
-
this.h[2] = sum32$1(this.h[2], c);
|
|
656
|
-
this.h[3] = sum32$1(this.h[3], d);
|
|
657
|
-
this.h[4] = sum32$1(this.h[4], e);
|
|
658
|
-
this.h[5] = sum32$1(this.h[5], f);
|
|
659
|
-
this.h[6] = sum32$1(this.h[6], g);
|
|
660
|
-
this.h[7] = sum32$1(this.h[7], h);
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
SHA256$1.prototype._digest = function digest(enc) {
|
|
664
|
-
if (enc === 'hex')
|
|
665
|
-
return utils$5.toHex32(this.h, 'big');
|
|
666
|
-
else
|
|
667
|
-
return utils$5.split32(this.h, 'big');
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
var utils$4 = utils$9;
|
|
671
|
-
var SHA256 = _256;
|
|
672
|
-
|
|
673
|
-
function SHA224() {
|
|
674
|
-
if (!(this instanceof SHA224))
|
|
675
|
-
return new SHA224();
|
|
676
|
-
|
|
677
|
-
SHA256.call(this);
|
|
678
|
-
this.h = [
|
|
679
|
-
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
|
680
|
-
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
|
|
681
|
-
}
|
|
682
|
-
utils$4.inherits(SHA224, SHA256);
|
|
683
|
-
var _224 = SHA224;
|
|
684
|
-
|
|
685
|
-
SHA224.blockSize = 512;
|
|
686
|
-
SHA224.outSize = 224;
|
|
687
|
-
SHA224.hmacStrength = 192;
|
|
688
|
-
SHA224.padLength = 64;
|
|
689
|
-
|
|
690
|
-
SHA224.prototype._digest = function digest(enc) {
|
|
691
|
-
// Just truncate output
|
|
692
|
-
if (enc === 'hex')
|
|
693
|
-
return utils$4.toHex32(this.h.slice(0, 7), 'big');
|
|
694
|
-
else
|
|
695
|
-
return utils$4.split32(this.h.slice(0, 7), 'big');
|
|
696
|
-
};
|
|
697
|
-
|
|
698
|
-
var utils$3 = utils$9;
|
|
699
|
-
var common$1 = common$5;
|
|
700
|
-
var assert$2 = minimalisticAssert;
|
|
701
|
-
|
|
702
|
-
var rotr64_hi = utils$3.rotr64_hi;
|
|
703
|
-
var rotr64_lo = utils$3.rotr64_lo;
|
|
704
|
-
var shr64_hi = utils$3.shr64_hi;
|
|
705
|
-
var shr64_lo = utils$3.shr64_lo;
|
|
706
|
-
var sum64 = utils$3.sum64;
|
|
707
|
-
var sum64_hi = utils$3.sum64_hi;
|
|
708
|
-
var sum64_lo = utils$3.sum64_lo;
|
|
709
|
-
var sum64_4_hi = utils$3.sum64_4_hi;
|
|
710
|
-
var sum64_4_lo = utils$3.sum64_4_lo;
|
|
711
|
-
var sum64_5_hi = utils$3.sum64_5_hi;
|
|
712
|
-
var sum64_5_lo = utils$3.sum64_5_lo;
|
|
713
|
-
|
|
714
|
-
var BlockHash$1 = common$1.BlockHash;
|
|
715
|
-
|
|
716
|
-
var sha512_K = [
|
|
717
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
718
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
719
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
720
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
721
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
722
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
723
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
724
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
725
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
726
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
727
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
728
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
729
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
730
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
731
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
732
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
733
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
734
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
735
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
736
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
737
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
738
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
739
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
740
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
741
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
742
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
743
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
744
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
745
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
746
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
747
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
748
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
749
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
750
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
751
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
752
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
753
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
754
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
755
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
756
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
757
|
-
];
|
|
758
|
-
|
|
759
|
-
function SHA512$1() {
|
|
760
|
-
if (!(this instanceof SHA512$1))
|
|
761
|
-
return new SHA512$1();
|
|
762
|
-
|
|
763
|
-
BlockHash$1.call(this);
|
|
764
|
-
this.h = [
|
|
765
|
-
0x6a09e667, 0xf3bcc908,
|
|
766
|
-
0xbb67ae85, 0x84caa73b,
|
|
767
|
-
0x3c6ef372, 0xfe94f82b,
|
|
768
|
-
0xa54ff53a, 0x5f1d36f1,
|
|
769
|
-
0x510e527f, 0xade682d1,
|
|
770
|
-
0x9b05688c, 0x2b3e6c1f,
|
|
771
|
-
0x1f83d9ab, 0xfb41bd6b,
|
|
772
|
-
0x5be0cd19, 0x137e2179 ];
|
|
773
|
-
this.k = sha512_K;
|
|
774
|
-
this.W = new Array(160);
|
|
775
|
-
}
|
|
776
|
-
utils$3.inherits(SHA512$1, BlockHash$1);
|
|
777
|
-
var _512 = SHA512$1;
|
|
778
|
-
|
|
779
|
-
SHA512$1.blockSize = 1024;
|
|
780
|
-
SHA512$1.outSize = 512;
|
|
781
|
-
SHA512$1.hmacStrength = 192;
|
|
782
|
-
SHA512$1.padLength = 128;
|
|
783
|
-
|
|
784
|
-
SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
|
|
785
|
-
var W = this.W;
|
|
786
|
-
|
|
787
|
-
// 32 x 32bit words
|
|
788
|
-
for (var i = 0; i < 32; i++)
|
|
789
|
-
W[i] = msg[start + i];
|
|
790
|
-
for (; i < W.length; i += 2) {
|
|
791
|
-
var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
|
|
792
|
-
var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
|
|
793
|
-
var c1_hi = W[i - 14]; // i - 7
|
|
794
|
-
var c1_lo = W[i - 13];
|
|
795
|
-
var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
|
|
796
|
-
var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
|
|
797
|
-
var c3_hi = W[i - 32]; // i - 16
|
|
798
|
-
var c3_lo = W[i - 31];
|
|
799
|
-
|
|
800
|
-
W[i] = sum64_4_hi(
|
|
801
|
-
c0_hi, c0_lo,
|
|
802
|
-
c1_hi, c1_lo,
|
|
803
|
-
c2_hi, c2_lo,
|
|
804
|
-
c3_hi, c3_lo);
|
|
805
|
-
W[i + 1] = sum64_4_lo(
|
|
806
|
-
c0_hi, c0_lo,
|
|
807
|
-
c1_hi, c1_lo,
|
|
808
|
-
c2_hi, c2_lo,
|
|
809
|
-
c3_hi, c3_lo);
|
|
58
|
+
return Buffer.from(arr);
|
|
810
59
|
}
|
|
811
60
|
};
|
|
812
61
|
|
|
813
|
-
SHA512$1.prototype._update = function _update(msg, start) {
|
|
814
|
-
this._prepareBlock(msg, start);
|
|
815
|
-
|
|
816
|
-
var W = this.W;
|
|
817
|
-
|
|
818
|
-
var ah = this.h[0];
|
|
819
|
-
var al = this.h[1];
|
|
820
|
-
var bh = this.h[2];
|
|
821
|
-
var bl = this.h[3];
|
|
822
|
-
var ch = this.h[4];
|
|
823
|
-
var cl = this.h[5];
|
|
824
|
-
var dh = this.h[6];
|
|
825
|
-
var dl = this.h[7];
|
|
826
|
-
var eh = this.h[8];
|
|
827
|
-
var el = this.h[9];
|
|
828
|
-
var fh = this.h[10];
|
|
829
|
-
var fl = this.h[11];
|
|
830
|
-
var gh = this.h[12];
|
|
831
|
-
var gl = this.h[13];
|
|
832
|
-
var hh = this.h[14];
|
|
833
|
-
var hl = this.h[15];
|
|
834
|
-
|
|
835
|
-
assert$2(this.k.length === W.length);
|
|
836
|
-
for (var i = 0; i < W.length; i += 2) {
|
|
837
|
-
var c0_hi = hh;
|
|
838
|
-
var c0_lo = hl;
|
|
839
|
-
var c1_hi = s1_512_hi(eh, el);
|
|
840
|
-
var c1_lo = s1_512_lo(eh, el);
|
|
841
|
-
var c2_hi = ch64_hi(eh, el, fh, fl, gh);
|
|
842
|
-
var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
|
|
843
|
-
var c3_hi = this.k[i];
|
|
844
|
-
var c3_lo = this.k[i + 1];
|
|
845
|
-
var c4_hi = W[i];
|
|
846
|
-
var c4_lo = W[i + 1];
|
|
847
|
-
|
|
848
|
-
var T1_hi = sum64_5_hi(
|
|
849
|
-
c0_hi, c0_lo,
|
|
850
|
-
c1_hi, c1_lo,
|
|
851
|
-
c2_hi, c2_lo,
|
|
852
|
-
c3_hi, c3_lo,
|
|
853
|
-
c4_hi, c4_lo);
|
|
854
|
-
var T1_lo = sum64_5_lo(
|
|
855
|
-
c0_hi, c0_lo,
|
|
856
|
-
c1_hi, c1_lo,
|
|
857
|
-
c2_hi, c2_lo,
|
|
858
|
-
c3_hi, c3_lo,
|
|
859
|
-
c4_hi, c4_lo);
|
|
860
|
-
|
|
861
|
-
c0_hi = s0_512_hi(ah, al);
|
|
862
|
-
c0_lo = s0_512_lo(ah, al);
|
|
863
|
-
c1_hi = maj64_hi(ah, al, bh, bl, ch);
|
|
864
|
-
c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
|
|
865
|
-
|
|
866
|
-
var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
867
|
-
var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
868
|
-
|
|
869
|
-
hh = gh;
|
|
870
|
-
hl = gl;
|
|
871
|
-
|
|
872
|
-
gh = fh;
|
|
873
|
-
gl = fl;
|
|
874
|
-
|
|
875
|
-
fh = eh;
|
|
876
|
-
fl = el;
|
|
877
|
-
|
|
878
|
-
eh = sum64_hi(dh, dl, T1_hi, T1_lo);
|
|
879
|
-
el = sum64_lo(dl, dl, T1_hi, T1_lo);
|
|
880
|
-
|
|
881
|
-
dh = ch;
|
|
882
|
-
dl = cl;
|
|
883
|
-
|
|
884
|
-
ch = bh;
|
|
885
|
-
cl = bl;
|
|
886
|
-
|
|
887
|
-
bh = ah;
|
|
888
|
-
bl = al;
|
|
889
|
-
|
|
890
|
-
ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
891
|
-
al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
sum64(this.h, 0, ah, al);
|
|
895
|
-
sum64(this.h, 2, bh, bl);
|
|
896
|
-
sum64(this.h, 4, ch, cl);
|
|
897
|
-
sum64(this.h, 6, dh, dl);
|
|
898
|
-
sum64(this.h, 8, eh, el);
|
|
899
|
-
sum64(this.h, 10, fh, fl);
|
|
900
|
-
sum64(this.h, 12, gh, gl);
|
|
901
|
-
sum64(this.h, 14, hh, hl);
|
|
902
|
-
};
|
|
903
|
-
|
|
904
|
-
SHA512$1.prototype._digest = function digest(enc) {
|
|
905
|
-
if (enc === 'hex')
|
|
906
|
-
return utils$3.toHex32(this.h, 'big');
|
|
907
|
-
else
|
|
908
|
-
return utils$3.split32(this.h, 'big');
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
function ch64_hi(xh, xl, yh, yl, zh) {
|
|
912
|
-
var r = (xh & yh) ^ ((~xh) & zh);
|
|
913
|
-
if (r < 0)
|
|
914
|
-
r += 0x100000000;
|
|
915
|
-
return r;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
function ch64_lo(xh, xl, yh, yl, zh, zl) {
|
|
919
|
-
var r = (xl & yl) ^ ((~xl) & zl);
|
|
920
|
-
if (r < 0)
|
|
921
|
-
r += 0x100000000;
|
|
922
|
-
return r;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
function maj64_hi(xh, xl, yh, yl, zh) {
|
|
926
|
-
var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
|
|
927
|
-
if (r < 0)
|
|
928
|
-
r += 0x100000000;
|
|
929
|
-
return r;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
function maj64_lo(xh, xl, yh, yl, zh, zl) {
|
|
933
|
-
var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
|
|
934
|
-
if (r < 0)
|
|
935
|
-
r += 0x100000000;
|
|
936
|
-
return r;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
function s0_512_hi(xh, xl) {
|
|
940
|
-
var c0_hi = rotr64_hi(xh, xl, 28);
|
|
941
|
-
var c1_hi = rotr64_hi(xl, xh, 2); // 34
|
|
942
|
-
var c2_hi = rotr64_hi(xl, xh, 7); // 39
|
|
943
|
-
|
|
944
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
945
|
-
if (r < 0)
|
|
946
|
-
r += 0x100000000;
|
|
947
|
-
return r;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
function s0_512_lo(xh, xl) {
|
|
951
|
-
var c0_lo = rotr64_lo(xh, xl, 28);
|
|
952
|
-
var c1_lo = rotr64_lo(xl, xh, 2); // 34
|
|
953
|
-
var c2_lo = rotr64_lo(xl, xh, 7); // 39
|
|
954
|
-
|
|
955
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
956
|
-
if (r < 0)
|
|
957
|
-
r += 0x100000000;
|
|
958
|
-
return r;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
function s1_512_hi(xh, xl) {
|
|
962
|
-
var c0_hi = rotr64_hi(xh, xl, 14);
|
|
963
|
-
var c1_hi = rotr64_hi(xh, xl, 18);
|
|
964
|
-
var c2_hi = rotr64_hi(xl, xh, 9); // 41
|
|
965
|
-
|
|
966
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
967
|
-
if (r < 0)
|
|
968
|
-
r += 0x100000000;
|
|
969
|
-
return r;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
function s1_512_lo(xh, xl) {
|
|
973
|
-
var c0_lo = rotr64_lo(xh, xl, 14);
|
|
974
|
-
var c1_lo = rotr64_lo(xh, xl, 18);
|
|
975
|
-
var c2_lo = rotr64_lo(xl, xh, 9); // 41
|
|
976
|
-
|
|
977
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
978
|
-
if (r < 0)
|
|
979
|
-
r += 0x100000000;
|
|
980
|
-
return r;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function g0_512_hi(xh, xl) {
|
|
984
|
-
var c0_hi = rotr64_hi(xh, xl, 1);
|
|
985
|
-
var c1_hi = rotr64_hi(xh, xl, 8);
|
|
986
|
-
var c2_hi = shr64_hi(xh, xl, 7);
|
|
987
|
-
|
|
988
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
989
|
-
if (r < 0)
|
|
990
|
-
r += 0x100000000;
|
|
991
|
-
return r;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
function g0_512_lo(xh, xl) {
|
|
995
|
-
var c0_lo = rotr64_lo(xh, xl, 1);
|
|
996
|
-
var c1_lo = rotr64_lo(xh, xl, 8);
|
|
997
|
-
var c2_lo = shr64_lo(xh, xl, 7);
|
|
998
|
-
|
|
999
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1000
|
-
if (r < 0)
|
|
1001
|
-
r += 0x100000000;
|
|
1002
|
-
return r;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
function g1_512_hi(xh, xl) {
|
|
1006
|
-
var c0_hi = rotr64_hi(xh, xl, 19);
|
|
1007
|
-
var c1_hi = rotr64_hi(xl, xh, 29); // 61
|
|
1008
|
-
var c2_hi = shr64_hi(xh, xl, 6);
|
|
1009
|
-
|
|
1010
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1011
|
-
if (r < 0)
|
|
1012
|
-
r += 0x100000000;
|
|
1013
|
-
return r;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
function g1_512_lo(xh, xl) {
|
|
1017
|
-
var c0_lo = rotr64_lo(xh, xl, 19);
|
|
1018
|
-
var c1_lo = rotr64_lo(xl, xh, 29); // 61
|
|
1019
|
-
var c2_lo = shr64_lo(xh, xl, 6);
|
|
1020
|
-
|
|
1021
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1022
|
-
if (r < 0)
|
|
1023
|
-
r += 0x100000000;
|
|
1024
|
-
return r;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
var utils$2 = utils$9;
|
|
1028
|
-
|
|
1029
|
-
var SHA512 = _512;
|
|
1030
|
-
|
|
1031
|
-
function SHA384() {
|
|
1032
|
-
if (!(this instanceof SHA384))
|
|
1033
|
-
return new SHA384();
|
|
1034
|
-
|
|
1035
|
-
SHA512.call(this);
|
|
1036
|
-
this.h = [
|
|
1037
|
-
0xcbbb9d5d, 0xc1059ed8,
|
|
1038
|
-
0x629a292a, 0x367cd507,
|
|
1039
|
-
0x9159015a, 0x3070dd17,
|
|
1040
|
-
0x152fecd8, 0xf70e5939,
|
|
1041
|
-
0x67332667, 0xffc00b31,
|
|
1042
|
-
0x8eb44a87, 0x68581511,
|
|
1043
|
-
0xdb0c2e0d, 0x64f98fa7,
|
|
1044
|
-
0x47b5481d, 0xbefa4fa4 ];
|
|
1045
|
-
}
|
|
1046
|
-
utils$2.inherits(SHA384, SHA512);
|
|
1047
|
-
var _384 = SHA384;
|
|
1048
|
-
|
|
1049
|
-
SHA384.blockSize = 1024;
|
|
1050
|
-
SHA384.outSize = 384;
|
|
1051
|
-
SHA384.hmacStrength = 192;
|
|
1052
|
-
SHA384.padLength = 128;
|
|
1053
|
-
|
|
1054
|
-
SHA384.prototype._digest = function digest(enc) {
|
|
1055
|
-
if (enc === 'hex')
|
|
1056
|
-
return utils$2.toHex32(this.h.slice(0, 12), 'big');
|
|
1057
|
-
else
|
|
1058
|
-
return utils$2.split32(this.h.slice(0, 12), 'big');
|
|
1059
|
-
};
|
|
1060
|
-
|
|
1061
|
-
sha.sha1 = _1;
|
|
1062
|
-
sha.sha224 = _224;
|
|
1063
|
-
sha.sha256 = _256;
|
|
1064
|
-
sha.sha384 = _384;
|
|
1065
|
-
sha.sha512 = _512;
|
|
1066
|
-
|
|
1067
|
-
var ripemd = {};
|
|
1068
|
-
|
|
1069
|
-
var utils$1 = utils$9;
|
|
1070
|
-
var common = common$5;
|
|
1071
|
-
|
|
1072
|
-
var rotl32 = utils$1.rotl32;
|
|
1073
|
-
var sum32 = utils$1.sum32;
|
|
1074
|
-
var sum32_3 = utils$1.sum32_3;
|
|
1075
|
-
var sum32_4 = utils$1.sum32_4;
|
|
1076
|
-
var BlockHash = common.BlockHash;
|
|
1077
|
-
|
|
1078
|
-
function RIPEMD160() {
|
|
1079
|
-
if (!(this instanceof RIPEMD160))
|
|
1080
|
-
return new RIPEMD160();
|
|
1081
|
-
|
|
1082
|
-
BlockHash.call(this);
|
|
1083
|
-
|
|
1084
|
-
this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
|
|
1085
|
-
this.endian = 'little';
|
|
1086
|
-
}
|
|
1087
|
-
utils$1.inherits(RIPEMD160, BlockHash);
|
|
1088
|
-
ripemd.ripemd160 = RIPEMD160;
|
|
1089
|
-
|
|
1090
|
-
RIPEMD160.blockSize = 512;
|
|
1091
|
-
RIPEMD160.outSize = 160;
|
|
1092
|
-
RIPEMD160.hmacStrength = 192;
|
|
1093
|
-
RIPEMD160.padLength = 64;
|
|
1094
|
-
|
|
1095
|
-
RIPEMD160.prototype._update = function update(msg, start) {
|
|
1096
|
-
var A = this.h[0];
|
|
1097
|
-
var B = this.h[1];
|
|
1098
|
-
var C = this.h[2];
|
|
1099
|
-
var D = this.h[3];
|
|
1100
|
-
var E = this.h[4];
|
|
1101
|
-
var Ah = A;
|
|
1102
|
-
var Bh = B;
|
|
1103
|
-
var Ch = C;
|
|
1104
|
-
var Dh = D;
|
|
1105
|
-
var Eh = E;
|
|
1106
|
-
for (var j = 0; j < 80; j++) {
|
|
1107
|
-
var T = sum32(
|
|
1108
|
-
rotl32(
|
|
1109
|
-
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
|
1110
|
-
s[j]),
|
|
1111
|
-
E);
|
|
1112
|
-
A = E;
|
|
1113
|
-
E = D;
|
|
1114
|
-
D = rotl32(C, 10);
|
|
1115
|
-
C = B;
|
|
1116
|
-
B = T;
|
|
1117
|
-
T = sum32(
|
|
1118
|
-
rotl32(
|
|
1119
|
-
sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
|
|
1120
|
-
sh[j]),
|
|
1121
|
-
Eh);
|
|
1122
|
-
Ah = Eh;
|
|
1123
|
-
Eh = Dh;
|
|
1124
|
-
Dh = rotl32(Ch, 10);
|
|
1125
|
-
Ch = Bh;
|
|
1126
|
-
Bh = T;
|
|
1127
|
-
}
|
|
1128
|
-
T = sum32_3(this.h[1], C, Dh);
|
|
1129
|
-
this.h[1] = sum32_3(this.h[2], D, Eh);
|
|
1130
|
-
this.h[2] = sum32_3(this.h[3], E, Ah);
|
|
1131
|
-
this.h[3] = sum32_3(this.h[4], A, Bh);
|
|
1132
|
-
this.h[4] = sum32_3(this.h[0], B, Ch);
|
|
1133
|
-
this.h[0] = T;
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
RIPEMD160.prototype._digest = function digest(enc) {
|
|
1137
|
-
if (enc === 'hex')
|
|
1138
|
-
return utils$1.toHex32(this.h, 'little');
|
|
1139
|
-
else
|
|
1140
|
-
return utils$1.split32(this.h, 'little');
|
|
1141
|
-
};
|
|
1142
|
-
|
|
1143
|
-
function f(j, x, y, z) {
|
|
1144
|
-
if (j <= 15)
|
|
1145
|
-
return x ^ y ^ z;
|
|
1146
|
-
else if (j <= 31)
|
|
1147
|
-
return (x & y) | ((~x) & z);
|
|
1148
|
-
else if (j <= 47)
|
|
1149
|
-
return (x | (~y)) ^ z;
|
|
1150
|
-
else if (j <= 63)
|
|
1151
|
-
return (x & z) | (y & (~z));
|
|
1152
|
-
else
|
|
1153
|
-
return x ^ (y | (~z));
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
function K(j) {
|
|
1157
|
-
if (j <= 15)
|
|
1158
|
-
return 0x00000000;
|
|
1159
|
-
else if (j <= 31)
|
|
1160
|
-
return 0x5a827999;
|
|
1161
|
-
else if (j <= 47)
|
|
1162
|
-
return 0x6ed9eba1;
|
|
1163
|
-
else if (j <= 63)
|
|
1164
|
-
return 0x8f1bbcdc;
|
|
1165
|
-
else
|
|
1166
|
-
return 0xa953fd4e;
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
function Kh(j) {
|
|
1170
|
-
if (j <= 15)
|
|
1171
|
-
return 0x50a28be6;
|
|
1172
|
-
else if (j <= 31)
|
|
1173
|
-
return 0x5c4dd124;
|
|
1174
|
-
else if (j <= 47)
|
|
1175
|
-
return 0x6d703ef3;
|
|
1176
|
-
else if (j <= 63)
|
|
1177
|
-
return 0x7a6d76e9;
|
|
1178
|
-
else
|
|
1179
|
-
return 0x00000000;
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
var r = [
|
|
1183
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
1184
|
-
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
1185
|
-
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
|
1186
|
-
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
|
1187
|
-
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
|
|
1188
|
-
];
|
|
1189
|
-
|
|
1190
|
-
var rh = [
|
|
1191
|
-
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
|
1192
|
-
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
|
1193
|
-
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
|
1194
|
-
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
|
1195
|
-
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
|
|
1196
|
-
];
|
|
1197
|
-
|
|
1198
|
-
var s = [
|
|
1199
|
-
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
|
1200
|
-
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
|
1201
|
-
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
|
1202
|
-
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
|
1203
|
-
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
|
|
1204
|
-
];
|
|
1205
|
-
|
|
1206
|
-
var sh = [
|
|
1207
|
-
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
|
1208
|
-
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
|
1209
|
-
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
|
1210
|
-
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
|
1211
|
-
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
|
|
1212
|
-
];
|
|
1213
|
-
|
|
1214
|
-
var utils = utils$9;
|
|
1215
|
-
var assert$1 = minimalisticAssert;
|
|
1216
|
-
|
|
1217
|
-
function Hmac(hash, key, enc) {
|
|
1218
|
-
if (!(this instanceof Hmac))
|
|
1219
|
-
return new Hmac(hash, key, enc);
|
|
1220
|
-
this.Hash = hash;
|
|
1221
|
-
this.blockSize = hash.blockSize / 8;
|
|
1222
|
-
this.outSize = hash.outSize / 8;
|
|
1223
|
-
this.inner = null;
|
|
1224
|
-
this.outer = null;
|
|
1225
|
-
|
|
1226
|
-
this._init(utils.toArray(key, enc));
|
|
1227
|
-
}
|
|
1228
|
-
var hmac = Hmac;
|
|
1229
|
-
|
|
1230
|
-
Hmac.prototype._init = function init(key) {
|
|
1231
|
-
// Shorten key, if needed
|
|
1232
|
-
if (key.length > this.blockSize)
|
|
1233
|
-
key = new this.Hash().update(key).digest();
|
|
1234
|
-
assert$1(key.length <= this.blockSize);
|
|
1235
|
-
|
|
1236
|
-
// Add padding to key
|
|
1237
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1238
|
-
key.push(0);
|
|
1239
|
-
|
|
1240
|
-
for (i = 0; i < key.length; i++)
|
|
1241
|
-
key[i] ^= 0x36;
|
|
1242
|
-
this.inner = new this.Hash().update(key);
|
|
1243
|
-
|
|
1244
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1245
|
-
for (i = 0; i < key.length; i++)
|
|
1246
|
-
key[i] ^= 0x6a;
|
|
1247
|
-
this.outer = new this.Hash().update(key);
|
|
1248
|
-
};
|
|
1249
|
-
|
|
1250
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1251
|
-
this.inner.update(msg, enc);
|
|
1252
|
-
return this;
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1256
|
-
this.outer.update(this.inner.digest());
|
|
1257
|
-
return this.outer.digest(enc);
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
|
-
(function (exports) {
|
|
1261
|
-
var hash = exports;
|
|
1262
|
-
|
|
1263
|
-
hash.utils = utils$9;
|
|
1264
|
-
hash.common = common$5;
|
|
1265
|
-
hash.sha = sha;
|
|
1266
|
-
hash.ripemd = ripemd;
|
|
1267
|
-
hash.hmac = hmac;
|
|
1268
|
-
|
|
1269
|
-
// Proxy hash functions to the main object
|
|
1270
|
-
hash.sha1 = hash.sha.sha1;
|
|
1271
|
-
hash.sha256 = hash.sha.sha256;
|
|
1272
|
-
hash.sha224 = hash.sha.sha224;
|
|
1273
|
-
hash.sha384 = hash.sha.sha384;
|
|
1274
|
-
hash.sha512 = hash.sha.sha512;
|
|
1275
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1276
|
-
} (hash$1));
|
|
1277
|
-
|
|
1278
|
-
var hash = hash$1;
|
|
1279
|
-
|
|
1280
|
-
const version$2 = "logger/5.6.0";
|
|
1281
|
-
|
|
1282
|
-
let _permanentCensorErrors = false;
|
|
1283
|
-
let _censorErrors = false;
|
|
1284
|
-
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1285
|
-
let _logLevel = LogLevels["default"];
|
|
1286
|
-
let _globalLogger = null;
|
|
1287
|
-
function _checkNormalize() {
|
|
1288
|
-
try {
|
|
1289
|
-
const missing = [];
|
|
1290
|
-
// Make sure all forms of normalization are supported
|
|
1291
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1292
|
-
try {
|
|
1293
|
-
if ("test".normalize(form) !== "test") {
|
|
1294
|
-
throw new Error("bad normalize");
|
|
1295
|
-
}
|
|
1296
|
-
;
|
|
1297
|
-
}
|
|
1298
|
-
catch (error) {
|
|
1299
|
-
missing.push(form);
|
|
1300
|
-
}
|
|
1301
|
-
});
|
|
1302
|
-
if (missing.length) {
|
|
1303
|
-
throw new Error("missing " + missing.join(", "));
|
|
1304
|
-
}
|
|
1305
|
-
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1306
|
-
throw new Error("broken implementation");
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
catch (error) {
|
|
1310
|
-
return error.message;
|
|
1311
|
-
}
|
|
1312
|
-
return null;
|
|
1313
|
-
}
|
|
1314
|
-
const _normalizeError = _checkNormalize();
|
|
1315
|
-
var LogLevel;
|
|
1316
|
-
(function (LogLevel) {
|
|
1317
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
1318
|
-
LogLevel["INFO"] = "INFO";
|
|
1319
|
-
LogLevel["WARNING"] = "WARNING";
|
|
1320
|
-
LogLevel["ERROR"] = "ERROR";
|
|
1321
|
-
LogLevel["OFF"] = "OFF";
|
|
1322
|
-
})(LogLevel || (LogLevel = {}));
|
|
1323
|
-
var ErrorCode;
|
|
1324
|
-
(function (ErrorCode) {
|
|
1325
|
-
///////////////////
|
|
1326
|
-
// Generic Errors
|
|
1327
|
-
// Unknown Error
|
|
1328
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1329
|
-
// Not Implemented
|
|
1330
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1331
|
-
// Unsupported Operation
|
|
1332
|
-
// - operation
|
|
1333
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1334
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1335
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1336
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1337
|
-
// Some sort of bad response from the server
|
|
1338
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1339
|
-
// Timeout
|
|
1340
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1341
|
-
///////////////////
|
|
1342
|
-
// Operational Errors
|
|
1343
|
-
// Buffer Overrun
|
|
1344
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1345
|
-
// Numeric Fault
|
|
1346
|
-
// - operation: the operation being executed
|
|
1347
|
-
// - fault: the reason this faulted
|
|
1348
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1349
|
-
///////////////////
|
|
1350
|
-
// Argument Errors
|
|
1351
|
-
// Missing new operator to an object
|
|
1352
|
-
// - name: The name of the class
|
|
1353
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1354
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1355
|
-
// - argument: The argument name that was invalid
|
|
1356
|
-
// - value: The value of the argument
|
|
1357
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1358
|
-
// Missing argument to a function:
|
|
1359
|
-
// - count: The number of arguments received
|
|
1360
|
-
// - expectedCount: The number of arguments expected
|
|
1361
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1362
|
-
// Too many arguments
|
|
1363
|
-
// - count: The number of arguments received
|
|
1364
|
-
// - expectedCount: The number of arguments expected
|
|
1365
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1366
|
-
///////////////////
|
|
1367
|
-
// Blockchain Errors
|
|
1368
|
-
// Call exception
|
|
1369
|
-
// - transaction: the transaction
|
|
1370
|
-
// - address?: the contract address
|
|
1371
|
-
// - args?: The arguments passed into the function
|
|
1372
|
-
// - method?: The Solidity method signature
|
|
1373
|
-
// - errorSignature?: The EIP848 error signature
|
|
1374
|
-
// - errorArgs?: The EIP848 error parameters
|
|
1375
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1376
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1377
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1378
|
-
// - transaction: the transaction attempted
|
|
1379
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1380
|
-
// Nonce has already been used
|
|
1381
|
-
// - transaction: the transaction attempted
|
|
1382
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1383
|
-
// The replacement fee for the transaction is too low
|
|
1384
|
-
// - transaction: the transaction attempted
|
|
1385
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1386
|
-
// The gas limit could not be estimated
|
|
1387
|
-
// - transaction: the transaction passed to estimateGas
|
|
1388
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1389
|
-
// The transaction was replaced by one with a higher gas price
|
|
1390
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
1391
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1392
|
-
// - hash: original transaction hash
|
|
1393
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
1394
|
-
// - receipt: the receipt of the replacement
|
|
1395
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1396
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
1397
|
-
const HEX = "0123456789abcdef";
|
|
1398
|
-
class Logger {
|
|
1399
|
-
constructor(version) {
|
|
1400
|
-
Object.defineProperty(this, "version", {
|
|
1401
|
-
enumerable: true,
|
|
1402
|
-
value: version,
|
|
1403
|
-
writable: false
|
|
1404
|
-
});
|
|
1405
|
-
}
|
|
1406
|
-
_log(logLevel, args) {
|
|
1407
|
-
const level = logLevel.toLowerCase();
|
|
1408
|
-
if (LogLevels[level] == null) {
|
|
1409
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1410
|
-
}
|
|
1411
|
-
if (_logLevel > LogLevels[level]) {
|
|
1412
|
-
return;
|
|
1413
|
-
}
|
|
1414
|
-
console.log.apply(console, args);
|
|
1415
|
-
}
|
|
1416
|
-
debug(...args) {
|
|
1417
|
-
this._log(Logger.levels.DEBUG, args);
|
|
1418
|
-
}
|
|
1419
|
-
info(...args) {
|
|
1420
|
-
this._log(Logger.levels.INFO, args);
|
|
1421
|
-
}
|
|
1422
|
-
warn(...args) {
|
|
1423
|
-
this._log(Logger.levels.WARNING, args);
|
|
1424
|
-
}
|
|
1425
|
-
makeError(message, code, params) {
|
|
1426
|
-
// Errors are being censored
|
|
1427
|
-
if (_censorErrors) {
|
|
1428
|
-
return this.makeError("censored error", code, {});
|
|
1429
|
-
}
|
|
1430
|
-
if (!code) {
|
|
1431
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
1432
|
-
}
|
|
1433
|
-
if (!params) {
|
|
1434
|
-
params = {};
|
|
1435
|
-
}
|
|
1436
|
-
const messageDetails = [];
|
|
1437
|
-
Object.keys(params).forEach((key) => {
|
|
1438
|
-
const value = params[key];
|
|
1439
|
-
try {
|
|
1440
|
-
if (value instanceof Uint8Array) {
|
|
1441
|
-
let hex = "";
|
|
1442
|
-
for (let i = 0; i < value.length; i++) {
|
|
1443
|
-
hex += HEX[value[i] >> 4];
|
|
1444
|
-
hex += HEX[value[i] & 0x0f];
|
|
1445
|
-
}
|
|
1446
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1447
|
-
}
|
|
1448
|
-
else {
|
|
1449
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
catch (error) {
|
|
1453
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1454
|
-
}
|
|
1455
|
-
});
|
|
1456
|
-
messageDetails.push(`code=${code}`);
|
|
1457
|
-
messageDetails.push(`version=${this.version}`);
|
|
1458
|
-
const reason = message;
|
|
1459
|
-
let url = "";
|
|
1460
|
-
switch (code) {
|
|
1461
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
1462
|
-
url = "NUMERIC_FAULT";
|
|
1463
|
-
const fault = message;
|
|
1464
|
-
switch (fault) {
|
|
1465
|
-
case "overflow":
|
|
1466
|
-
case "underflow":
|
|
1467
|
-
case "division-by-zero":
|
|
1468
|
-
url += "-" + fault;
|
|
1469
|
-
break;
|
|
1470
|
-
case "negative-power":
|
|
1471
|
-
case "negative-width":
|
|
1472
|
-
url += "-unsupported";
|
|
1473
|
-
break;
|
|
1474
|
-
case "unbound-bitwise-result":
|
|
1475
|
-
url += "-unbound-result";
|
|
1476
|
-
break;
|
|
1477
|
-
}
|
|
1478
|
-
break;
|
|
1479
|
-
}
|
|
1480
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
1481
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
1482
|
-
case ErrorCode.MISSING_NEW:
|
|
1483
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
1484
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
1485
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
1486
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
1487
|
-
url = code;
|
|
1488
|
-
break;
|
|
1489
|
-
}
|
|
1490
|
-
if (url) {
|
|
1491
|
-
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
1492
|
-
}
|
|
1493
|
-
if (messageDetails.length) {
|
|
1494
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
1495
|
-
}
|
|
1496
|
-
// @TODO: Any??
|
|
1497
|
-
const error = new Error(message);
|
|
1498
|
-
error.reason = reason;
|
|
1499
|
-
error.code = code;
|
|
1500
|
-
Object.keys(params).forEach(function (key) {
|
|
1501
|
-
error[key] = params[key];
|
|
1502
|
-
});
|
|
1503
|
-
return error;
|
|
1504
|
-
}
|
|
1505
|
-
throwError(message, code, params) {
|
|
1506
|
-
throw this.makeError(message, code, params);
|
|
1507
|
-
}
|
|
1508
|
-
throwArgumentError(message, name, value) {
|
|
1509
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1510
|
-
argument: name,
|
|
1511
|
-
value: value
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
assert(condition, message, code, params) {
|
|
1515
|
-
if (!!condition) {
|
|
1516
|
-
return;
|
|
1517
|
-
}
|
|
1518
|
-
this.throwError(message, code, params);
|
|
1519
|
-
}
|
|
1520
|
-
assertArgument(condition, message, name, value) {
|
|
1521
|
-
if (!!condition) {
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
this.throwArgumentError(message, name, value);
|
|
1525
|
-
}
|
|
1526
|
-
checkNormalize(message) {
|
|
1527
|
-
if (_normalizeError) {
|
|
1528
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1529
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
checkSafeUint53(value, message) {
|
|
1534
|
-
if (typeof (value) !== "number") {
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
if (message == null) {
|
|
1538
|
-
message = "value not safe";
|
|
1539
|
-
}
|
|
1540
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1541
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1542
|
-
operation: "checkSafeInteger",
|
|
1543
|
-
fault: "out-of-safe-range",
|
|
1544
|
-
value: value
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
if (value % 1) {
|
|
1548
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1549
|
-
operation: "checkSafeInteger",
|
|
1550
|
-
fault: "non-integer",
|
|
1551
|
-
value: value
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
1556
|
-
if (message) {
|
|
1557
|
-
message = ": " + message;
|
|
1558
|
-
}
|
|
1559
|
-
else {
|
|
1560
|
-
message = "";
|
|
1561
|
-
}
|
|
1562
|
-
if (count < expectedCount) {
|
|
1563
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1564
|
-
count: count,
|
|
1565
|
-
expectedCount: expectedCount
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
if (count > expectedCount) {
|
|
1569
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1570
|
-
count: count,
|
|
1571
|
-
expectedCount: expectedCount
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
checkNew(target, kind) {
|
|
1576
|
-
if (target === Object || target == null) {
|
|
1577
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
checkAbstract(target, kind) {
|
|
1581
|
-
if (target === kind) {
|
|
1582
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1583
|
-
}
|
|
1584
|
-
else if (target === Object || target == null) {
|
|
1585
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
static globalLogger() {
|
|
1589
|
-
if (!_globalLogger) {
|
|
1590
|
-
_globalLogger = new Logger(version$2);
|
|
1591
|
-
}
|
|
1592
|
-
return _globalLogger;
|
|
1593
|
-
}
|
|
1594
|
-
static setCensorship(censorship, permanent) {
|
|
1595
|
-
if (!censorship && permanent) {
|
|
1596
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1597
|
-
operation: "setCensorship"
|
|
1598
|
-
});
|
|
1599
|
-
}
|
|
1600
|
-
if (_permanentCensorErrors) {
|
|
1601
|
-
if (!censorship) {
|
|
1602
|
-
return;
|
|
1603
|
-
}
|
|
1604
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1605
|
-
operation: "setCensorship"
|
|
1606
|
-
});
|
|
1607
|
-
}
|
|
1608
|
-
_censorErrors = !!censorship;
|
|
1609
|
-
_permanentCensorErrors = !!permanent;
|
|
1610
|
-
}
|
|
1611
|
-
static setLogLevel(logLevel) {
|
|
1612
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
1613
|
-
if (level == null) {
|
|
1614
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1615
|
-
return;
|
|
1616
|
-
}
|
|
1617
|
-
_logLevel = level;
|
|
1618
|
-
}
|
|
1619
|
-
static from(version) {
|
|
1620
|
-
return new Logger(version);
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
Logger.errors = ErrorCode;
|
|
1624
|
-
Logger.levels = LogLevel;
|
|
1625
|
-
|
|
1626
|
-
const version$1 = "bytes/5.6.0";
|
|
1627
|
-
|
|
1628
|
-
const logger = new Logger(version$1);
|
|
1629
|
-
///////////////////////////////
|
|
1630
|
-
function isHexable(value) {
|
|
1631
|
-
return !!(value.toHexString);
|
|
1632
|
-
}
|
|
1633
|
-
function addSlice(array) {
|
|
1634
|
-
if (array.slice) {
|
|
1635
|
-
return array;
|
|
1636
|
-
}
|
|
1637
|
-
array.slice = function () {
|
|
1638
|
-
const args = Array.prototype.slice.call(arguments);
|
|
1639
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1640
|
-
};
|
|
1641
|
-
return array;
|
|
1642
|
-
}
|
|
1643
|
-
function isInteger(value) {
|
|
1644
|
-
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1645
|
-
}
|
|
1646
|
-
function isBytes(value) {
|
|
1647
|
-
if (value == null) {
|
|
1648
|
-
return false;
|
|
1649
|
-
}
|
|
1650
|
-
if (value.constructor === Uint8Array) {
|
|
1651
|
-
return true;
|
|
1652
|
-
}
|
|
1653
|
-
if (typeof (value) === "string") {
|
|
1654
|
-
return false;
|
|
1655
|
-
}
|
|
1656
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
1657
|
-
return false;
|
|
1658
|
-
}
|
|
1659
|
-
for (let i = 0; i < value.length; i++) {
|
|
1660
|
-
const v = value[i];
|
|
1661
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1662
|
-
return false;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return true;
|
|
1666
|
-
}
|
|
1667
|
-
function arrayify(value, options) {
|
|
1668
|
-
if (!options) {
|
|
1669
|
-
options = {};
|
|
1670
|
-
}
|
|
1671
|
-
if (typeof (value) === "number") {
|
|
1672
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1673
|
-
const result = [];
|
|
1674
|
-
while (value) {
|
|
1675
|
-
result.unshift(value & 0xff);
|
|
1676
|
-
value = parseInt(String(value / 256));
|
|
1677
|
-
}
|
|
1678
|
-
if (result.length === 0) {
|
|
1679
|
-
result.push(0);
|
|
1680
|
-
}
|
|
1681
|
-
return addSlice(new Uint8Array(result));
|
|
1682
|
-
}
|
|
1683
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1684
|
-
value = "0x" + value;
|
|
1685
|
-
}
|
|
1686
|
-
if (isHexable(value)) {
|
|
1687
|
-
value = value.toHexString();
|
|
1688
|
-
}
|
|
1689
|
-
if (isHexString(value)) {
|
|
1690
|
-
let hex = value.substring(2);
|
|
1691
|
-
if (hex.length % 2) {
|
|
1692
|
-
if (options.hexPad === "left") {
|
|
1693
|
-
hex = "0x0" + hex.substring(2);
|
|
1694
|
-
}
|
|
1695
|
-
else if (options.hexPad === "right") {
|
|
1696
|
-
hex += "0";
|
|
1697
|
-
}
|
|
1698
|
-
else {
|
|
1699
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
const result = [];
|
|
1703
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
1704
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1705
|
-
}
|
|
1706
|
-
return addSlice(new Uint8Array(result));
|
|
1707
|
-
}
|
|
1708
|
-
if (isBytes(value)) {
|
|
1709
|
-
return addSlice(new Uint8Array(value));
|
|
1710
|
-
}
|
|
1711
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1712
|
-
}
|
|
1713
|
-
function isHexString(value, length) {
|
|
1714
|
-
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1715
|
-
return false;
|
|
1716
|
-
}
|
|
1717
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
1718
|
-
return false;
|
|
1719
|
-
}
|
|
1720
|
-
return true;
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
const version = "sha2/5.6.0";
|
|
1724
|
-
|
|
1725
|
-
new Logger(version);
|
|
1726
|
-
function sha256(data) {
|
|
1727
|
-
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
62
|
class Struct {
|
|
1731
63
|
constructor(properties) {
|
|
1732
64
|
Object.assign(this, properties);
|
|
@@ -1884,8 +216,8 @@ class PublicKey extends Struct {
|
|
|
1884
216
|
|
|
1885
217
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1886
218
|
const buffer = Buffer.concat([fromPublicKey.toBuffer(), Buffer.from(seed), programId.toBuffer()]);
|
|
1887
|
-
const
|
|
1888
|
-
return new PublicKey(
|
|
219
|
+
const publicKeyBytes = sha256(buffer);
|
|
220
|
+
return new PublicKey(publicKeyBytes);
|
|
1889
221
|
}
|
|
1890
222
|
/**
|
|
1891
223
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1904,10 +236,9 @@ class PublicKey extends Struct {
|
|
|
1904
236
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
1905
237
|
});
|
|
1906
238
|
buffer = Buffer.concat([buffer, programId.toBuffer(), Buffer.from('ProgramDerivedAddress')]);
|
|
1907
|
-
|
|
1908
|
-
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
239
|
+
const publicKeyBytes = sha256(buffer);
|
|
1909
240
|
|
|
1910
|
-
if (
|
|
241
|
+
if (isOnCurve(publicKeyBytes)) {
|
|
1911
242
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1912
243
|
}
|
|
1913
244
|
|
|
@@ -1971,7 +302,7 @@ class PublicKey extends Struct {
|
|
|
1971
302
|
|
|
1972
303
|
static isOnCurve(pubkeyData) {
|
|
1973
304
|
const pubkey = new PublicKey(pubkeyData);
|
|
1974
|
-
return
|
|
305
|
+
return isOnCurve(pubkey.toBytes());
|
|
1975
306
|
}
|
|
1976
307
|
|
|
1977
308
|
}
|
|
@@ -1979,56 +310,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
|
1979
310
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
1980
311
|
kind: 'struct',
|
|
1981
312
|
fields: [['_bn', 'u256']]
|
|
1982
|
-
});
|
|
1983
|
-
|
|
1984
|
-
let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
|
|
1985
|
-
// This function and its dependents were sourced from:
|
|
1986
|
-
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
1987
|
-
|
|
1988
|
-
function is_on_curve(p) {
|
|
1989
|
-
var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
|
|
1990
|
-
var t = naclLowLevel.gf(),
|
|
1991
|
-
chk = naclLowLevel.gf(),
|
|
1992
|
-
num = naclLowLevel.gf(),
|
|
1993
|
-
den = naclLowLevel.gf(),
|
|
1994
|
-
den2 = naclLowLevel.gf(),
|
|
1995
|
-
den4 = naclLowLevel.gf(),
|
|
1996
|
-
den6 = naclLowLevel.gf();
|
|
1997
|
-
naclLowLevel.set25519(r[2], gf1);
|
|
1998
|
-
naclLowLevel.unpack25519(r[1], p);
|
|
1999
|
-
naclLowLevel.S(num, r[1]);
|
|
2000
|
-
naclLowLevel.M(den, num, naclLowLevel.D);
|
|
2001
|
-
naclLowLevel.Z(num, num, r[2]);
|
|
2002
|
-
naclLowLevel.A(den, r[2], den);
|
|
2003
|
-
naclLowLevel.S(den2, den);
|
|
2004
|
-
naclLowLevel.S(den4, den2);
|
|
2005
|
-
naclLowLevel.M(den6, den4, den2);
|
|
2006
|
-
naclLowLevel.M(t, den6, num);
|
|
2007
|
-
naclLowLevel.M(t, t, den);
|
|
2008
|
-
naclLowLevel.pow2523(t, t);
|
|
2009
|
-
naclLowLevel.M(t, t, num);
|
|
2010
|
-
naclLowLevel.M(t, t, den);
|
|
2011
|
-
naclLowLevel.M(t, t, den);
|
|
2012
|
-
naclLowLevel.M(r[0], t, den);
|
|
2013
|
-
naclLowLevel.S(chk, r[0]);
|
|
2014
|
-
naclLowLevel.M(chk, chk, den);
|
|
2015
|
-
if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
|
|
2016
|
-
naclLowLevel.S(chk, r[0]);
|
|
2017
|
-
naclLowLevel.M(chk, chk, den);
|
|
2018
|
-
if (neq25519(chk, num)) return 0;
|
|
2019
|
-
return 1;
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
let gf1 = naclLowLevel.gf([1]);
|
|
2023
|
-
let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
2024
|
-
|
|
2025
|
-
function neq25519(a, b) {
|
|
2026
|
-
var c = new Uint8Array(32),
|
|
2027
|
-
d = new Uint8Array(32);
|
|
2028
|
-
naclLowLevel.pack25519(c, a);
|
|
2029
|
-
naclLowLevel.pack25519(d, b);
|
|
2030
|
-
return naclLowLevel.crypto_verify_32(c, 0, d, 0);
|
|
2031
|
-
}
|
|
313
|
+
});
|
|
2032
314
|
|
|
2033
315
|
/**
|
|
2034
316
|
* An account key pair (public and secret keys).
|
|
@@ -2039,6 +321,8 @@ function neq25519(a, b) {
|
|
|
2039
321
|
class Account {
|
|
2040
322
|
/** @internal */
|
|
2041
323
|
|
|
324
|
+
/** @internal */
|
|
325
|
+
|
|
2042
326
|
/**
|
|
2043
327
|
* Create a new Account object
|
|
2044
328
|
*
|
|
@@ -2048,12 +332,21 @@ class Account {
|
|
|
2048
332
|
* @param secretKey Secret key for the account
|
|
2049
333
|
*/
|
|
2050
334
|
constructor(secretKey) {
|
|
2051
|
-
this.
|
|
335
|
+
this._publicKey = void 0;
|
|
336
|
+
this._secretKey = void 0;
|
|
2052
337
|
|
|
2053
338
|
if (secretKey) {
|
|
2054
|
-
|
|
339
|
+
const secretKeyBuffer = toBuffer(secretKey);
|
|
340
|
+
|
|
341
|
+
if (secretKey.length !== 64) {
|
|
342
|
+
throw new Error('bad secret key size');
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
this._publicKey = secretKeyBuffer.slice(32, 64);
|
|
346
|
+
this._secretKey = secretKeyBuffer.slice(0, 32);
|
|
2055
347
|
} else {
|
|
2056
|
-
this.
|
|
348
|
+
this._secretKey = toBuffer(generatePrivateKey());
|
|
349
|
+
this._publicKey = toBuffer(getPublicKey(this._secretKey));
|
|
2057
350
|
}
|
|
2058
351
|
}
|
|
2059
352
|
/**
|
|
@@ -2062,15 +355,17 @@ class Account {
|
|
|
2062
355
|
|
|
2063
356
|
|
|
2064
357
|
get publicKey() {
|
|
2065
|
-
return new PublicKey(this.
|
|
358
|
+
return new PublicKey(this._publicKey);
|
|
2066
359
|
}
|
|
2067
360
|
/**
|
|
2068
|
-
* The **unencrypted** secret key for this account
|
|
361
|
+
* The **unencrypted** secret key for this account. The first 32 bytes
|
|
362
|
+
* is the private scalar and the last 32 bytes is the public key.
|
|
363
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
2069
364
|
*/
|
|
2070
365
|
|
|
2071
366
|
|
|
2072
367
|
get secretKey() {
|
|
2073
|
-
return
|
|
368
|
+
return Buffer.concat([this._secretKey, this._publicKey], 64);
|
|
2074
369
|
}
|
|
2075
370
|
|
|
2076
371
|
}
|
|
@@ -2583,6 +878,10 @@ const VersionedMessage = {
|
|
|
2583
878
|
}
|
|
2584
879
|
};
|
|
2585
880
|
|
|
881
|
+
/**
|
|
882
|
+
* Transaction signature as base-58 encoded string
|
|
883
|
+
*/
|
|
884
|
+
|
|
2586
885
|
let TransactionStatus;
|
|
2587
886
|
/**
|
|
2588
887
|
* Default (empty) signature
|
|
@@ -3108,7 +1407,7 @@ class Transaction {
|
|
|
3108
1407
|
_partialSign(message, ...signers) {
|
|
3109
1408
|
const signData = message.serialize();
|
|
3110
1409
|
signers.forEach(signer => {
|
|
3111
|
-
const signature =
|
|
1410
|
+
const signature = sign(signData, signer.secretKey);
|
|
3112
1411
|
|
|
3113
1412
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
3114
1413
|
});
|
|
@@ -3164,7 +1463,7 @@ class Transaction {
|
|
|
3164
1463
|
return false;
|
|
3165
1464
|
}
|
|
3166
1465
|
} else {
|
|
3167
|
-
if (!
|
|
1466
|
+
if (!verify(signature, signData, publicKey.toBuffer())) {
|
|
3168
1467
|
return false;
|
|
3169
1468
|
}
|
|
3170
1469
|
}
|
|
@@ -3369,7 +1668,7 @@ class VersionedTransaction {
|
|
|
3369
1668
|
for (const signer of signers) {
|
|
3370
1669
|
const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
|
|
3371
1670
|
assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
|
|
3372
|
-
this.signatures[signerIndex] =
|
|
1671
|
+
this.signatures[signerIndex] = sign(messageData, signer.secretKey);
|
|
3373
1672
|
}
|
|
3374
1673
|
}
|
|
3375
1674
|
|
|
@@ -8515,12 +6814,7 @@ class Keypair {
|
|
|
8515
6814
|
*/
|
|
8516
6815
|
constructor(keypair) {
|
|
8517
6816
|
this._keypair = void 0;
|
|
8518
|
-
|
|
8519
|
-
if (keypair) {
|
|
8520
|
-
this._keypair = keypair;
|
|
8521
|
-
} else {
|
|
8522
|
-
this._keypair = nacl.sign.keyPair();
|
|
8523
|
-
}
|
|
6817
|
+
this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
|
|
8524
6818
|
}
|
|
8525
6819
|
/**
|
|
8526
6820
|
* Generate a new random keypair
|
|
@@ -8528,7 +6822,7 @@ class Keypair {
|
|
|
8528
6822
|
|
|
8529
6823
|
|
|
8530
6824
|
static generate() {
|
|
8531
|
-
return new Keypair(
|
|
6825
|
+
return new Keypair(generateKeypair());
|
|
8532
6826
|
}
|
|
8533
6827
|
/**
|
|
8534
6828
|
* Create a keypair from a raw secret key byte array.
|
|
@@ -8545,19 +6839,27 @@ class Keypair {
|
|
|
8545
6839
|
|
|
8546
6840
|
|
|
8547
6841
|
static fromSecretKey(secretKey, options) {
|
|
8548
|
-
|
|
6842
|
+
if (secretKey.byteLength !== 64) {
|
|
6843
|
+
throw new Error('bad secret key size');
|
|
6844
|
+
}
|
|
6845
|
+
|
|
6846
|
+
const publicKey = secretKey.slice(32, 64);
|
|
8549
6847
|
|
|
8550
6848
|
if (!options || !options.skipValidation) {
|
|
8551
|
-
const
|
|
8552
|
-
const
|
|
8553
|
-
const signature = nacl.sign.detached(signData, keypair.secretKey);
|
|
6849
|
+
const privateScalar = secretKey.slice(0, 32);
|
|
6850
|
+
const computedPublicKey = getPublicKey(privateScalar);
|
|
8554
6851
|
|
|
8555
|
-
|
|
8556
|
-
|
|
6852
|
+
for (let ii = 0; ii < 32; ii++) {
|
|
6853
|
+
if (publicKey[ii] !== computedPublicKey[ii]) {
|
|
6854
|
+
throw new Error('provided secretKey is invalid');
|
|
6855
|
+
}
|
|
8557
6856
|
}
|
|
8558
6857
|
}
|
|
8559
6858
|
|
|
8560
|
-
return new Keypair(
|
|
6859
|
+
return new Keypair({
|
|
6860
|
+
publicKey,
|
|
6861
|
+
secretKey
|
|
6862
|
+
});
|
|
8561
6863
|
}
|
|
8562
6864
|
/**
|
|
8563
6865
|
* Generate a keypair from a 32 byte seed.
|
|
@@ -8567,7 +6869,14 @@ class Keypair {
|
|
|
8567
6869
|
|
|
8568
6870
|
|
|
8569
6871
|
static fromSeed(seed) {
|
|
8570
|
-
|
|
6872
|
+
const publicKey = getPublicKey(seed);
|
|
6873
|
+
const secretKey = new Uint8Array(64);
|
|
6874
|
+
secretKey.set(seed);
|
|
6875
|
+
secretKey.set(publicKey, 32);
|
|
6876
|
+
return new Keypair({
|
|
6877
|
+
publicKey,
|
|
6878
|
+
secretKey
|
|
6879
|
+
});
|
|
8571
6880
|
}
|
|
8572
6881
|
/**
|
|
8573
6882
|
* The public key for this keypair
|
|
@@ -9119,7 +7428,7 @@ class Ed25519Program {
|
|
|
9119
7428
|
try {
|
|
9120
7429
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
9121
7430
|
const publicKey = keypair.publicKey.toBytes();
|
|
9122
|
-
const signature =
|
|
7431
|
+
const signature = sign(message, keypair.secretKey);
|
|
9123
7432
|
return this.createInstructionWithPublicKey({
|
|
9124
7433
|
publicKey,
|
|
9125
7434
|
message,
|
|
@@ -9134,10 +7443,21 @@ class Ed25519Program {
|
|
|
9134
7443
|
}
|
|
9135
7444
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
9136
7445
|
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
7446
|
+
// library interoperable with the synchronous APIs in web3.js.
|
|
7447
|
+
|
|
7448
|
+
secp256k1.utils.hmacSha256Sync = (key, ...msgs) => {
|
|
7449
|
+
const h = hmac.create(sha256, key);
|
|
7450
|
+
msgs.forEach(msg => h.update(msg));
|
|
7451
|
+
return h.digest();
|
|
7452
|
+
};
|
|
7453
|
+
|
|
7454
|
+
const ecdsaSign = (msgHash, privKey) => secp256k1.signSync(msgHash, privKey, {
|
|
7455
|
+
der: false,
|
|
7456
|
+
recovered: true
|
|
7457
|
+
});
|
|
7458
|
+
secp256k1.utils.isValidPrivateKey;
|
|
7459
|
+
const publicKeyCreate = secp256k1.getPublicKey;
|
|
7460
|
+
|
|
9141
7461
|
const PRIVATE_KEY_BYTES = 32;
|
|
9142
7462
|
const ETHEREUM_ADDRESS_BYTES = 20;
|
|
9143
7463
|
const PUBLIC_KEY_BYTES = 64;
|
|
@@ -9261,13 +7581,12 @@ class Secp256k1Program {
|
|
|
9261
7581
|
|
|
9262
7582
|
try {
|
|
9263
7583
|
const privateKey = toBuffer(pkey);
|
|
9264
|
-
const publicKey = publicKeyCreate(privateKey, false
|
|
7584
|
+
const publicKey = publicKeyCreate(privateKey, false
|
|
7585
|
+
/* isCompressed */
|
|
7586
|
+
).slice(1); // throw away leading byte
|
|
9265
7587
|
|
|
9266
7588
|
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
9267
|
-
const
|
|
9268
|
-
signature,
|
|
9269
|
-
recid: recoveryId
|
|
9270
|
-
} = ecdsaSign(messageHash, privateKey);
|
|
7589
|
+
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
9271
7590
|
return this.createInstructionWithPublicKey({
|
|
9272
7591
|
publicKey,
|
|
9273
7592
|
message,
|
|
@@ -10467,7 +8786,7 @@ class ValidatorInfo {
|
|
|
10467
8786
|
if (configKeys[1].isSigner) {
|
|
10468
8787
|
const rawInfo = rustString().decode(Buffer.from(byteArray));
|
|
10469
8788
|
const info = JSON.parse(rawInfo);
|
|
10470
|
-
assert$
|
|
8789
|
+
assert$1(info, InfoString);
|
|
10471
8790
|
return new ValidatorInfo(configKeys[1].publicKey, info);
|
|
10472
8791
|
}
|
|
10473
8792
|
}
|