@solana/web3.js 1.54.0 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.cjs.js +202 -1818
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +202 -1818
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +202 -1839
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +145 -10
- package/lib/index.esm.js +202 -1839
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +19249 -25998
- 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 +202 -1818
- package/lib/index.native.js.map +1 -1
- package/package.json +5 -6
- package/src/account.ts +18 -9
- package/src/connection.ts +244 -21
- package/src/keypair.ts +19 -24
- package/src/message/versioned.ts +12 -3
- 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.cjs.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var nacl = require('tweetnacl');
|
|
6
5
|
var buffer = require('buffer');
|
|
6
|
+
var sha512 = require('@noble/hashes/sha512');
|
|
7
|
+
var ed25519 = require('@noble/ed25519');
|
|
7
8
|
var BN = require('bn.js');
|
|
8
9
|
var bs58 = require('bs58');
|
|
10
|
+
var sha256 = require('@noble/hashes/sha256');
|
|
9
11
|
var borsh = require('borsh');
|
|
10
12
|
var BufferLayout = require('@solana/buffer-layout');
|
|
11
13
|
var bigintBuffer = require('bigint-buffer');
|
|
@@ -15,8 +17,9 @@ var RpcClient = require('jayson/lib/client/browser');
|
|
|
15
17
|
var http = require('http');
|
|
16
18
|
var https = require('https');
|
|
17
19
|
var nodeFetch = require('node-fetch');
|
|
18
|
-
var secp256k1 = require('secp256k1');
|
|
19
20
|
var sha3 = require('js-sha3');
|
|
21
|
+
var hmac = require('@noble/hashes/hmac');
|
|
22
|
+
var secp256k1 = require('@noble/secp256k1');
|
|
20
23
|
|
|
21
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
25
|
|
|
@@ -38,7 +41,7 @@ function _interopNamespace(e) {
|
|
|
38
41
|
return Object.freeze(n);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
var
|
|
44
|
+
var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
|
|
42
45
|
var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
|
|
43
46
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
44
47
|
var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
|
|
@@ -46,1745 +49,53 @@ var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
|
46
49
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
47
50
|
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
48
51
|
var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
|
|
49
|
-
var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
|
|
50
52
|
var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
|
|
53
|
+
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
return buffer.Buffer.from(arr);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
var hash$1 = {};
|
|
63
|
-
|
|
64
|
-
var utils$9 = {};
|
|
55
|
+
/**
|
|
56
|
+
* A 64 byte secret key, the first 32 bytes of which is the
|
|
57
|
+
* private scalar and the last 32 bytes is the public key.
|
|
58
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
59
|
+
*/
|
|
65
60
|
|
|
66
|
-
|
|
61
|
+
ed25519__namespace.utils.sha512Sync = (...m) => sha512.sha512(ed25519__namespace.utils.concatBytes(...m));
|
|
67
62
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const generatePrivateKey = ed25519__namespace.utils.randomPrivateKey;
|
|
64
|
+
const generateKeypair = () => {
|
|
65
|
+
const privateScalar = ed25519__namespace.utils.randomPrivateKey();
|
|
66
|
+
const publicKey = getPublicKey(privateScalar);
|
|
67
|
+
const secretKey = new Uint8Array(64);
|
|
68
|
+
secretKey.set(privateScalar);
|
|
69
|
+
secretKey.set(publicKey, 32);
|
|
70
|
+
return {
|
|
71
|
+
publicKey,
|
|
72
|
+
secretKey
|
|
73
|
+
};
|
|
76
74
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (hasRequiredInherits_browser) return inherits_browser.exports;
|
|
86
|
-
hasRequiredInherits_browser = 1;
|
|
87
|
-
if (typeof Object.create === 'function') {
|
|
88
|
-
// implementation from standard node.js 'util' module
|
|
89
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
90
|
-
if (superCtor) {
|
|
91
|
-
ctor.super_ = superCtor;
|
|
92
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
93
|
-
constructor: {
|
|
94
|
-
value: ctor,
|
|
95
|
-
enumerable: false,
|
|
96
|
-
writable: true,
|
|
97
|
-
configurable: true
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
} else {
|
|
103
|
-
// old school shim for old browsers
|
|
104
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
105
|
-
if (superCtor) {
|
|
106
|
-
ctor.super_ = superCtor;
|
|
107
|
-
var TempCtor = function () {};
|
|
108
|
-
TempCtor.prototype = superCtor.prototype;
|
|
109
|
-
ctor.prototype = new TempCtor();
|
|
110
|
-
ctor.prototype.constructor = ctor;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return inherits_browser.exports;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
(function (module) {
|
|
118
|
-
try {
|
|
119
|
-
var util = require('util');
|
|
120
|
-
/* istanbul ignore next */
|
|
121
|
-
if (typeof util.inherits !== 'function') throw '';
|
|
122
|
-
module.exports = util.inherits;
|
|
123
|
-
} catch (e) {
|
|
124
|
-
/* istanbul ignore next */
|
|
125
|
-
module.exports = requireInherits_browser();
|
|
126
|
-
}
|
|
127
|
-
} (inherits$1));
|
|
128
|
-
|
|
129
|
-
var assert$5 = minimalisticAssert;
|
|
130
|
-
var inherits = inherits$1.exports;
|
|
131
|
-
|
|
132
|
-
utils$9.inherits = inherits;
|
|
133
|
-
|
|
134
|
-
function isSurrogatePair(msg, i) {
|
|
135
|
-
if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
if (i < 0 || i + 1 >= msg.length) {
|
|
75
|
+
const getPublicKey = ed25519__namespace.sync.getPublicKey;
|
|
76
|
+
function isOnCurve(publicKey) {
|
|
77
|
+
try {
|
|
78
|
+
ed25519__namespace.Point.fromHex(publicKey, true
|
|
79
|
+
/* strict */
|
|
80
|
+
);
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
139
83
|
return false;
|
|
140
84
|
}
|
|
141
|
-
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function toArray(msg, enc) {
|
|
145
|
-
if (Array.isArray(msg))
|
|
146
|
-
return msg.slice();
|
|
147
|
-
if (!msg)
|
|
148
|
-
return [];
|
|
149
|
-
var res = [];
|
|
150
|
-
if (typeof msg === 'string') {
|
|
151
|
-
if (!enc) {
|
|
152
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
153
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
154
|
-
// Apache License 2.0
|
|
155
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
156
|
-
var p = 0;
|
|
157
|
-
for (var i = 0; i < msg.length; i++) {
|
|
158
|
-
var c = msg.charCodeAt(i);
|
|
159
|
-
if (c < 128) {
|
|
160
|
-
res[p++] = c;
|
|
161
|
-
} else if (c < 2048) {
|
|
162
|
-
res[p++] = (c >> 6) | 192;
|
|
163
|
-
res[p++] = (c & 63) | 128;
|
|
164
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
165
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
166
|
-
res[p++] = (c >> 18) | 240;
|
|
167
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
168
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
169
|
-
res[p++] = (c & 63) | 128;
|
|
170
|
-
} else {
|
|
171
|
-
res[p++] = (c >> 12) | 224;
|
|
172
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
173
|
-
res[p++] = (c & 63) | 128;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} else if (enc === 'hex') {
|
|
177
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
178
|
-
if (msg.length % 2 !== 0)
|
|
179
|
-
msg = '0' + msg;
|
|
180
|
-
for (i = 0; i < msg.length; i += 2)
|
|
181
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
for (i = 0; i < msg.length; i++)
|
|
185
|
-
res[i] = msg[i] | 0;
|
|
186
|
-
}
|
|
187
|
-
return res;
|
|
188
|
-
}
|
|
189
|
-
utils$9.toArray = toArray;
|
|
190
|
-
|
|
191
|
-
function toHex(msg) {
|
|
192
|
-
var res = '';
|
|
193
|
-
for (var i = 0; i < msg.length; i++)
|
|
194
|
-
res += zero2(msg[i].toString(16));
|
|
195
|
-
return res;
|
|
196
|
-
}
|
|
197
|
-
utils$9.toHex = toHex;
|
|
198
|
-
|
|
199
|
-
function htonl(w) {
|
|
200
|
-
var res = (w >>> 24) |
|
|
201
|
-
((w >>> 8) & 0xff00) |
|
|
202
|
-
((w << 8) & 0xff0000) |
|
|
203
|
-
((w & 0xff) << 24);
|
|
204
|
-
return res >>> 0;
|
|
205
|
-
}
|
|
206
|
-
utils$9.htonl = htonl;
|
|
207
|
-
|
|
208
|
-
function toHex32(msg, endian) {
|
|
209
|
-
var res = '';
|
|
210
|
-
for (var i = 0; i < msg.length; i++) {
|
|
211
|
-
var w = msg[i];
|
|
212
|
-
if (endian === 'little')
|
|
213
|
-
w = htonl(w);
|
|
214
|
-
res += zero8(w.toString(16));
|
|
215
|
-
}
|
|
216
|
-
return res;
|
|
217
|
-
}
|
|
218
|
-
utils$9.toHex32 = toHex32;
|
|
219
|
-
|
|
220
|
-
function zero2(word) {
|
|
221
|
-
if (word.length === 1)
|
|
222
|
-
return '0' + word;
|
|
223
|
-
else
|
|
224
|
-
return word;
|
|
225
|
-
}
|
|
226
|
-
utils$9.zero2 = zero2;
|
|
227
|
-
|
|
228
|
-
function zero8(word) {
|
|
229
|
-
if (word.length === 7)
|
|
230
|
-
return '0' + word;
|
|
231
|
-
else if (word.length === 6)
|
|
232
|
-
return '00' + word;
|
|
233
|
-
else if (word.length === 5)
|
|
234
|
-
return '000' + word;
|
|
235
|
-
else if (word.length === 4)
|
|
236
|
-
return '0000' + word;
|
|
237
|
-
else if (word.length === 3)
|
|
238
|
-
return '00000' + word;
|
|
239
|
-
else if (word.length === 2)
|
|
240
|
-
return '000000' + word;
|
|
241
|
-
else if (word.length === 1)
|
|
242
|
-
return '0000000' + word;
|
|
243
|
-
else
|
|
244
|
-
return word;
|
|
245
|
-
}
|
|
246
|
-
utils$9.zero8 = zero8;
|
|
247
|
-
|
|
248
|
-
function join32(msg, start, end, endian) {
|
|
249
|
-
var len = end - start;
|
|
250
|
-
assert$5(len % 4 === 0);
|
|
251
|
-
var res = new Array(len / 4);
|
|
252
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
253
|
-
var w;
|
|
254
|
-
if (endian === 'big')
|
|
255
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
256
|
-
else
|
|
257
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
258
|
-
res[i] = w >>> 0;
|
|
259
|
-
}
|
|
260
|
-
return res;
|
|
261
|
-
}
|
|
262
|
-
utils$9.join32 = join32;
|
|
263
|
-
|
|
264
|
-
function split32(msg, endian) {
|
|
265
|
-
var res = new Array(msg.length * 4);
|
|
266
|
-
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
267
|
-
var m = msg[i];
|
|
268
|
-
if (endian === 'big') {
|
|
269
|
-
res[k] = m >>> 24;
|
|
270
|
-
res[k + 1] = (m >>> 16) & 0xff;
|
|
271
|
-
res[k + 2] = (m >>> 8) & 0xff;
|
|
272
|
-
res[k + 3] = m & 0xff;
|
|
273
|
-
} else {
|
|
274
|
-
res[k + 3] = m >>> 24;
|
|
275
|
-
res[k + 2] = (m >>> 16) & 0xff;
|
|
276
|
-
res[k + 1] = (m >>> 8) & 0xff;
|
|
277
|
-
res[k] = m & 0xff;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return res;
|
|
281
85
|
}
|
|
282
|
-
|
|
86
|
+
const sign = (message, secretKey) => ed25519__namespace.sync.sign(message, secretKey.slice(0, 32));
|
|
87
|
+
const verify = ed25519__namespace.sync.verify;
|
|
283
88
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
function rotl32$2(w, b) {
|
|
290
|
-
return (w << b) | (w >>> (32 - b));
|
|
291
|
-
}
|
|
292
|
-
utils$9.rotl32 = rotl32$2;
|
|
293
|
-
|
|
294
|
-
function sum32$3(a, b) {
|
|
295
|
-
return (a + b) >>> 0;
|
|
296
|
-
}
|
|
297
|
-
utils$9.sum32 = sum32$3;
|
|
298
|
-
|
|
299
|
-
function sum32_3$1(a, b, c) {
|
|
300
|
-
return (a + b + c) >>> 0;
|
|
301
|
-
}
|
|
302
|
-
utils$9.sum32_3 = sum32_3$1;
|
|
303
|
-
|
|
304
|
-
function sum32_4$2(a, b, c, d) {
|
|
305
|
-
return (a + b + c + d) >>> 0;
|
|
306
|
-
}
|
|
307
|
-
utils$9.sum32_4 = sum32_4$2;
|
|
308
|
-
|
|
309
|
-
function sum32_5$2(a, b, c, d, e) {
|
|
310
|
-
return (a + b + c + d + e) >>> 0;
|
|
311
|
-
}
|
|
312
|
-
utils$9.sum32_5 = sum32_5$2;
|
|
313
|
-
|
|
314
|
-
function sum64$1(buf, pos, ah, al) {
|
|
315
|
-
var bh = buf[pos];
|
|
316
|
-
var bl = buf[pos + 1];
|
|
317
|
-
|
|
318
|
-
var lo = (al + bl) >>> 0;
|
|
319
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
320
|
-
buf[pos] = hi >>> 0;
|
|
321
|
-
buf[pos + 1] = lo;
|
|
322
|
-
}
|
|
323
|
-
utils$9.sum64 = sum64$1;
|
|
324
|
-
|
|
325
|
-
function sum64_hi$1(ah, al, bh, bl) {
|
|
326
|
-
var lo = (al + bl) >>> 0;
|
|
327
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
328
|
-
return hi >>> 0;
|
|
329
|
-
}
|
|
330
|
-
utils$9.sum64_hi = sum64_hi$1;
|
|
331
|
-
|
|
332
|
-
function sum64_lo$1(ah, al, bh, bl) {
|
|
333
|
-
var lo = al + bl;
|
|
334
|
-
return lo >>> 0;
|
|
335
|
-
}
|
|
336
|
-
utils$9.sum64_lo = sum64_lo$1;
|
|
337
|
-
|
|
338
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
339
|
-
var carry = 0;
|
|
340
|
-
var lo = al;
|
|
341
|
-
lo = (lo + bl) >>> 0;
|
|
342
|
-
carry += lo < al ? 1 : 0;
|
|
343
|
-
lo = (lo + cl) >>> 0;
|
|
344
|
-
carry += lo < cl ? 1 : 0;
|
|
345
|
-
lo = (lo + dl) >>> 0;
|
|
346
|
-
carry += lo < dl ? 1 : 0;
|
|
347
|
-
|
|
348
|
-
var hi = ah + bh + ch + dh + carry;
|
|
349
|
-
return hi >>> 0;
|
|
350
|
-
}
|
|
351
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
352
|
-
|
|
353
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
354
|
-
var lo = al + bl + cl + dl;
|
|
355
|
-
return lo >>> 0;
|
|
356
|
-
}
|
|
357
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
358
|
-
|
|
359
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
360
|
-
var carry = 0;
|
|
361
|
-
var lo = al;
|
|
362
|
-
lo = (lo + bl) >>> 0;
|
|
363
|
-
carry += lo < al ? 1 : 0;
|
|
364
|
-
lo = (lo + cl) >>> 0;
|
|
365
|
-
carry += lo < cl ? 1 : 0;
|
|
366
|
-
lo = (lo + dl) >>> 0;
|
|
367
|
-
carry += lo < dl ? 1 : 0;
|
|
368
|
-
lo = (lo + el) >>> 0;
|
|
369
|
-
carry += lo < el ? 1 : 0;
|
|
370
|
-
|
|
371
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
372
|
-
return hi >>> 0;
|
|
373
|
-
}
|
|
374
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
375
|
-
|
|
376
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
377
|
-
var lo = al + bl + cl + dl + el;
|
|
378
|
-
|
|
379
|
-
return lo >>> 0;
|
|
380
|
-
}
|
|
381
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
382
|
-
|
|
383
|
-
function rotr64_hi$1(ah, al, num) {
|
|
384
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
385
|
-
return r >>> 0;
|
|
386
|
-
}
|
|
387
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
388
|
-
|
|
389
|
-
function rotr64_lo$1(ah, al, num) {
|
|
390
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
391
|
-
return r >>> 0;
|
|
392
|
-
}
|
|
393
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
394
|
-
|
|
395
|
-
function shr64_hi$1(ah, al, num) {
|
|
396
|
-
return ah >>> num;
|
|
397
|
-
}
|
|
398
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
399
|
-
|
|
400
|
-
function shr64_lo$1(ah, al, num) {
|
|
401
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
402
|
-
return r >>> 0;
|
|
403
|
-
}
|
|
404
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
405
|
-
|
|
406
|
-
var common$5 = {};
|
|
407
|
-
|
|
408
|
-
var utils$8 = utils$9;
|
|
409
|
-
var assert$4 = minimalisticAssert;
|
|
410
|
-
|
|
411
|
-
function BlockHash$4() {
|
|
412
|
-
this.pending = null;
|
|
413
|
-
this.pendingTotal = 0;
|
|
414
|
-
this.blockSize = this.constructor.blockSize;
|
|
415
|
-
this.outSize = this.constructor.outSize;
|
|
416
|
-
this.hmacStrength = this.constructor.hmacStrength;
|
|
417
|
-
this.padLength = this.constructor.padLength / 8;
|
|
418
|
-
this.endian = 'big';
|
|
419
|
-
|
|
420
|
-
this._delta8 = this.blockSize / 8;
|
|
421
|
-
this._delta32 = this.blockSize / 32;
|
|
422
|
-
}
|
|
423
|
-
common$5.BlockHash = BlockHash$4;
|
|
424
|
-
|
|
425
|
-
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
426
|
-
// Convert message to array, pad it, and join into 32bit blocks
|
|
427
|
-
msg = utils$8.toArray(msg, enc);
|
|
428
|
-
if (!this.pending)
|
|
429
|
-
this.pending = msg;
|
|
430
|
-
else
|
|
431
|
-
this.pending = this.pending.concat(msg);
|
|
432
|
-
this.pendingTotal += msg.length;
|
|
433
|
-
|
|
434
|
-
// Enough data, try updating
|
|
435
|
-
if (this.pending.length >= this._delta8) {
|
|
436
|
-
msg = this.pending;
|
|
437
|
-
|
|
438
|
-
// Process pending data in blocks
|
|
439
|
-
var r = msg.length % this._delta8;
|
|
440
|
-
this.pending = msg.slice(msg.length - r, msg.length);
|
|
441
|
-
if (this.pending.length === 0)
|
|
442
|
-
this.pending = null;
|
|
443
|
-
|
|
444
|
-
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
445
|
-
for (var i = 0; i < msg.length; i += this._delta32)
|
|
446
|
-
this._update(msg, i, i + this._delta32);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return this;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
BlockHash$4.prototype.digest = function digest(enc) {
|
|
453
|
-
this.update(this._pad());
|
|
454
|
-
assert$4(this.pending === null);
|
|
455
|
-
|
|
456
|
-
return this._digest(enc);
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
BlockHash$4.prototype._pad = function pad() {
|
|
460
|
-
var len = this.pendingTotal;
|
|
461
|
-
var bytes = this._delta8;
|
|
462
|
-
var k = bytes - ((len + this.padLength) % bytes);
|
|
463
|
-
var res = new Array(k + this.padLength);
|
|
464
|
-
res[0] = 0x80;
|
|
465
|
-
for (var i = 1; i < k; i++)
|
|
466
|
-
res[i] = 0;
|
|
467
|
-
|
|
468
|
-
// Append length
|
|
469
|
-
len <<= 3;
|
|
470
|
-
if (this.endian === 'big') {
|
|
471
|
-
for (var t = 8; t < this.padLength; t++)
|
|
472
|
-
res[i++] = 0;
|
|
473
|
-
|
|
474
|
-
res[i++] = 0;
|
|
475
|
-
res[i++] = 0;
|
|
476
|
-
res[i++] = 0;
|
|
477
|
-
res[i++] = 0;
|
|
478
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
479
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
480
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
481
|
-
res[i++] = len & 0xff;
|
|
89
|
+
const toBuffer = arr => {
|
|
90
|
+
if (buffer.Buffer.isBuffer(arr)) {
|
|
91
|
+
return arr;
|
|
92
|
+
} else if (arr instanceof Uint8Array) {
|
|
93
|
+
return buffer.Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
482
94
|
} else {
|
|
483
|
-
|
|
484
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
485
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
486
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
487
|
-
res[i++] = 0;
|
|
488
|
-
res[i++] = 0;
|
|
489
|
-
res[i++] = 0;
|
|
490
|
-
res[i++] = 0;
|
|
491
|
-
|
|
492
|
-
for (t = 8; t < this.padLength; t++)
|
|
493
|
-
res[i++] = 0;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return res;
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
var sha = {};
|
|
500
|
-
|
|
501
|
-
var common$4 = {};
|
|
502
|
-
|
|
503
|
-
var utils$7 = utils$9;
|
|
504
|
-
var rotr32 = utils$7.rotr32;
|
|
505
|
-
|
|
506
|
-
function ft_1$1(s, x, y, z) {
|
|
507
|
-
if (s === 0)
|
|
508
|
-
return ch32$1(x, y, z);
|
|
509
|
-
if (s === 1 || s === 3)
|
|
510
|
-
return p32(x, y, z);
|
|
511
|
-
if (s === 2)
|
|
512
|
-
return maj32$1(x, y, z);
|
|
513
|
-
}
|
|
514
|
-
common$4.ft_1 = ft_1$1;
|
|
515
|
-
|
|
516
|
-
function ch32$1(x, y, z) {
|
|
517
|
-
return (x & y) ^ ((~x) & z);
|
|
518
|
-
}
|
|
519
|
-
common$4.ch32 = ch32$1;
|
|
520
|
-
|
|
521
|
-
function maj32$1(x, y, z) {
|
|
522
|
-
return (x & y) ^ (x & z) ^ (y & z);
|
|
523
|
-
}
|
|
524
|
-
common$4.maj32 = maj32$1;
|
|
525
|
-
|
|
526
|
-
function p32(x, y, z) {
|
|
527
|
-
return x ^ y ^ z;
|
|
528
|
-
}
|
|
529
|
-
common$4.p32 = p32;
|
|
530
|
-
|
|
531
|
-
function s0_256$1(x) {
|
|
532
|
-
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
533
|
-
}
|
|
534
|
-
common$4.s0_256 = s0_256$1;
|
|
535
|
-
|
|
536
|
-
function s1_256$1(x) {
|
|
537
|
-
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
538
|
-
}
|
|
539
|
-
common$4.s1_256 = s1_256$1;
|
|
540
|
-
|
|
541
|
-
function g0_256$1(x) {
|
|
542
|
-
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
543
|
-
}
|
|
544
|
-
common$4.g0_256 = g0_256$1;
|
|
545
|
-
|
|
546
|
-
function g1_256$1(x) {
|
|
547
|
-
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
548
|
-
}
|
|
549
|
-
common$4.g1_256 = g1_256$1;
|
|
550
|
-
|
|
551
|
-
var utils$6 = utils$9;
|
|
552
|
-
var common$3 = common$5;
|
|
553
|
-
var shaCommon$1 = common$4;
|
|
554
|
-
|
|
555
|
-
var rotl32$1 = utils$6.rotl32;
|
|
556
|
-
var sum32$2 = utils$6.sum32;
|
|
557
|
-
var sum32_5$1 = utils$6.sum32_5;
|
|
558
|
-
var ft_1 = shaCommon$1.ft_1;
|
|
559
|
-
var BlockHash$3 = common$3.BlockHash;
|
|
560
|
-
|
|
561
|
-
var sha1_K = [
|
|
562
|
-
0x5A827999, 0x6ED9EBA1,
|
|
563
|
-
0x8F1BBCDC, 0xCA62C1D6
|
|
564
|
-
];
|
|
565
|
-
|
|
566
|
-
function SHA1() {
|
|
567
|
-
if (!(this instanceof SHA1))
|
|
568
|
-
return new SHA1();
|
|
569
|
-
|
|
570
|
-
BlockHash$3.call(this);
|
|
571
|
-
this.h = [
|
|
572
|
-
0x67452301, 0xefcdab89, 0x98badcfe,
|
|
573
|
-
0x10325476, 0xc3d2e1f0 ];
|
|
574
|
-
this.W = new Array(80);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
utils$6.inherits(SHA1, BlockHash$3);
|
|
578
|
-
var _1 = SHA1;
|
|
579
|
-
|
|
580
|
-
SHA1.blockSize = 512;
|
|
581
|
-
SHA1.outSize = 160;
|
|
582
|
-
SHA1.hmacStrength = 80;
|
|
583
|
-
SHA1.padLength = 64;
|
|
584
|
-
|
|
585
|
-
SHA1.prototype._update = function _update(msg, start) {
|
|
586
|
-
var W = this.W;
|
|
587
|
-
|
|
588
|
-
for (var i = 0; i < 16; i++)
|
|
589
|
-
W[i] = msg[start + i];
|
|
590
|
-
|
|
591
|
-
for(; i < W.length; i++)
|
|
592
|
-
W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
|
|
593
|
-
|
|
594
|
-
var a = this.h[0];
|
|
595
|
-
var b = this.h[1];
|
|
596
|
-
var c = this.h[2];
|
|
597
|
-
var d = this.h[3];
|
|
598
|
-
var e = this.h[4];
|
|
599
|
-
|
|
600
|
-
for (i = 0; i < W.length; i++) {
|
|
601
|
-
var s = ~~(i / 20);
|
|
602
|
-
var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
|
|
603
|
-
e = d;
|
|
604
|
-
d = c;
|
|
605
|
-
c = rotl32$1(b, 30);
|
|
606
|
-
b = a;
|
|
607
|
-
a = t;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
this.h[0] = sum32$2(this.h[0], a);
|
|
611
|
-
this.h[1] = sum32$2(this.h[1], b);
|
|
612
|
-
this.h[2] = sum32$2(this.h[2], c);
|
|
613
|
-
this.h[3] = sum32$2(this.h[3], d);
|
|
614
|
-
this.h[4] = sum32$2(this.h[4], e);
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
SHA1.prototype._digest = function digest(enc) {
|
|
618
|
-
if (enc === 'hex')
|
|
619
|
-
return utils$6.toHex32(this.h, 'big');
|
|
620
|
-
else
|
|
621
|
-
return utils$6.split32(this.h, 'big');
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
var utils$5 = utils$9;
|
|
625
|
-
var common$2 = common$5;
|
|
626
|
-
var shaCommon = common$4;
|
|
627
|
-
var assert$3 = minimalisticAssert;
|
|
628
|
-
|
|
629
|
-
var sum32$1 = utils$5.sum32;
|
|
630
|
-
var sum32_4$1 = utils$5.sum32_4;
|
|
631
|
-
var sum32_5 = utils$5.sum32_5;
|
|
632
|
-
var ch32 = shaCommon.ch32;
|
|
633
|
-
var maj32 = shaCommon.maj32;
|
|
634
|
-
var s0_256 = shaCommon.s0_256;
|
|
635
|
-
var s1_256 = shaCommon.s1_256;
|
|
636
|
-
var g0_256 = shaCommon.g0_256;
|
|
637
|
-
var g1_256 = shaCommon.g1_256;
|
|
638
|
-
|
|
639
|
-
var BlockHash$2 = common$2.BlockHash;
|
|
640
|
-
|
|
641
|
-
var sha256_K = [
|
|
642
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
643
|
-
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
644
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
645
|
-
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
646
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
647
|
-
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
648
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
649
|
-
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
650
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
651
|
-
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
652
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
653
|
-
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
654
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
655
|
-
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
656
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
657
|
-
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
658
|
-
];
|
|
659
|
-
|
|
660
|
-
function SHA256$1() {
|
|
661
|
-
if (!(this instanceof SHA256$1))
|
|
662
|
-
return new SHA256$1();
|
|
663
|
-
|
|
664
|
-
BlockHash$2.call(this);
|
|
665
|
-
this.h = [
|
|
666
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
667
|
-
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
668
|
-
];
|
|
669
|
-
this.k = sha256_K;
|
|
670
|
-
this.W = new Array(64);
|
|
671
|
-
}
|
|
672
|
-
utils$5.inherits(SHA256$1, BlockHash$2);
|
|
673
|
-
var _256 = SHA256$1;
|
|
674
|
-
|
|
675
|
-
SHA256$1.blockSize = 512;
|
|
676
|
-
SHA256$1.outSize = 256;
|
|
677
|
-
SHA256$1.hmacStrength = 192;
|
|
678
|
-
SHA256$1.padLength = 64;
|
|
679
|
-
|
|
680
|
-
SHA256$1.prototype._update = function _update(msg, start) {
|
|
681
|
-
var W = this.W;
|
|
682
|
-
|
|
683
|
-
for (var i = 0; i < 16; i++)
|
|
684
|
-
W[i] = msg[start + i];
|
|
685
|
-
for (; i < W.length; i++)
|
|
686
|
-
W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
|
|
687
|
-
|
|
688
|
-
var a = this.h[0];
|
|
689
|
-
var b = this.h[1];
|
|
690
|
-
var c = this.h[2];
|
|
691
|
-
var d = this.h[3];
|
|
692
|
-
var e = this.h[4];
|
|
693
|
-
var f = this.h[5];
|
|
694
|
-
var g = this.h[6];
|
|
695
|
-
var h = this.h[7];
|
|
696
|
-
|
|
697
|
-
assert$3(this.k.length === W.length);
|
|
698
|
-
for (i = 0; i < W.length; i++) {
|
|
699
|
-
var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
|
700
|
-
var T2 = sum32$1(s0_256(a), maj32(a, b, c));
|
|
701
|
-
h = g;
|
|
702
|
-
g = f;
|
|
703
|
-
f = e;
|
|
704
|
-
e = sum32$1(d, T1);
|
|
705
|
-
d = c;
|
|
706
|
-
c = b;
|
|
707
|
-
b = a;
|
|
708
|
-
a = sum32$1(T1, T2);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
this.h[0] = sum32$1(this.h[0], a);
|
|
712
|
-
this.h[1] = sum32$1(this.h[1], b);
|
|
713
|
-
this.h[2] = sum32$1(this.h[2], c);
|
|
714
|
-
this.h[3] = sum32$1(this.h[3], d);
|
|
715
|
-
this.h[4] = sum32$1(this.h[4], e);
|
|
716
|
-
this.h[5] = sum32$1(this.h[5], f);
|
|
717
|
-
this.h[6] = sum32$1(this.h[6], g);
|
|
718
|
-
this.h[7] = sum32$1(this.h[7], h);
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
SHA256$1.prototype._digest = function digest(enc) {
|
|
722
|
-
if (enc === 'hex')
|
|
723
|
-
return utils$5.toHex32(this.h, 'big');
|
|
724
|
-
else
|
|
725
|
-
return utils$5.split32(this.h, 'big');
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
var utils$4 = utils$9;
|
|
729
|
-
var SHA256 = _256;
|
|
730
|
-
|
|
731
|
-
function SHA224() {
|
|
732
|
-
if (!(this instanceof SHA224))
|
|
733
|
-
return new SHA224();
|
|
734
|
-
|
|
735
|
-
SHA256.call(this);
|
|
736
|
-
this.h = [
|
|
737
|
-
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
|
738
|
-
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
|
|
739
|
-
}
|
|
740
|
-
utils$4.inherits(SHA224, SHA256);
|
|
741
|
-
var _224 = SHA224;
|
|
742
|
-
|
|
743
|
-
SHA224.blockSize = 512;
|
|
744
|
-
SHA224.outSize = 224;
|
|
745
|
-
SHA224.hmacStrength = 192;
|
|
746
|
-
SHA224.padLength = 64;
|
|
747
|
-
|
|
748
|
-
SHA224.prototype._digest = function digest(enc) {
|
|
749
|
-
// Just truncate output
|
|
750
|
-
if (enc === 'hex')
|
|
751
|
-
return utils$4.toHex32(this.h.slice(0, 7), 'big');
|
|
752
|
-
else
|
|
753
|
-
return utils$4.split32(this.h.slice(0, 7), 'big');
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
var utils$3 = utils$9;
|
|
757
|
-
var common$1 = common$5;
|
|
758
|
-
var assert$2 = minimalisticAssert;
|
|
759
|
-
|
|
760
|
-
var rotr64_hi = utils$3.rotr64_hi;
|
|
761
|
-
var rotr64_lo = utils$3.rotr64_lo;
|
|
762
|
-
var shr64_hi = utils$3.shr64_hi;
|
|
763
|
-
var shr64_lo = utils$3.shr64_lo;
|
|
764
|
-
var sum64 = utils$3.sum64;
|
|
765
|
-
var sum64_hi = utils$3.sum64_hi;
|
|
766
|
-
var sum64_lo = utils$3.sum64_lo;
|
|
767
|
-
var sum64_4_hi = utils$3.sum64_4_hi;
|
|
768
|
-
var sum64_4_lo = utils$3.sum64_4_lo;
|
|
769
|
-
var sum64_5_hi = utils$3.sum64_5_hi;
|
|
770
|
-
var sum64_5_lo = utils$3.sum64_5_lo;
|
|
771
|
-
|
|
772
|
-
var BlockHash$1 = common$1.BlockHash;
|
|
773
|
-
|
|
774
|
-
var sha512_K = [
|
|
775
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
776
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
777
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
778
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
779
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
780
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
781
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
782
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
783
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
784
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
785
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
786
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
787
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
788
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
789
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
790
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
791
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
792
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
793
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
794
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
795
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
796
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
797
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
798
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
799
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
800
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
801
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
802
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
803
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
804
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
805
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
806
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
807
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
808
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
809
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
810
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
811
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
812
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
813
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
814
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
815
|
-
];
|
|
816
|
-
|
|
817
|
-
function SHA512$1() {
|
|
818
|
-
if (!(this instanceof SHA512$1))
|
|
819
|
-
return new SHA512$1();
|
|
820
|
-
|
|
821
|
-
BlockHash$1.call(this);
|
|
822
|
-
this.h = [
|
|
823
|
-
0x6a09e667, 0xf3bcc908,
|
|
824
|
-
0xbb67ae85, 0x84caa73b,
|
|
825
|
-
0x3c6ef372, 0xfe94f82b,
|
|
826
|
-
0xa54ff53a, 0x5f1d36f1,
|
|
827
|
-
0x510e527f, 0xade682d1,
|
|
828
|
-
0x9b05688c, 0x2b3e6c1f,
|
|
829
|
-
0x1f83d9ab, 0xfb41bd6b,
|
|
830
|
-
0x5be0cd19, 0x137e2179 ];
|
|
831
|
-
this.k = sha512_K;
|
|
832
|
-
this.W = new Array(160);
|
|
833
|
-
}
|
|
834
|
-
utils$3.inherits(SHA512$1, BlockHash$1);
|
|
835
|
-
var _512 = SHA512$1;
|
|
836
|
-
|
|
837
|
-
SHA512$1.blockSize = 1024;
|
|
838
|
-
SHA512$1.outSize = 512;
|
|
839
|
-
SHA512$1.hmacStrength = 192;
|
|
840
|
-
SHA512$1.padLength = 128;
|
|
841
|
-
|
|
842
|
-
SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
|
|
843
|
-
var W = this.W;
|
|
844
|
-
|
|
845
|
-
// 32 x 32bit words
|
|
846
|
-
for (var i = 0; i < 32; i++)
|
|
847
|
-
W[i] = msg[start + i];
|
|
848
|
-
for (; i < W.length; i += 2) {
|
|
849
|
-
var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
|
|
850
|
-
var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
|
|
851
|
-
var c1_hi = W[i - 14]; // i - 7
|
|
852
|
-
var c1_lo = W[i - 13];
|
|
853
|
-
var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
|
|
854
|
-
var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
|
|
855
|
-
var c3_hi = W[i - 32]; // i - 16
|
|
856
|
-
var c3_lo = W[i - 31];
|
|
857
|
-
|
|
858
|
-
W[i] = sum64_4_hi(
|
|
859
|
-
c0_hi, c0_lo,
|
|
860
|
-
c1_hi, c1_lo,
|
|
861
|
-
c2_hi, c2_lo,
|
|
862
|
-
c3_hi, c3_lo);
|
|
863
|
-
W[i + 1] = sum64_4_lo(
|
|
864
|
-
c0_hi, c0_lo,
|
|
865
|
-
c1_hi, c1_lo,
|
|
866
|
-
c2_hi, c2_lo,
|
|
867
|
-
c3_hi, c3_lo);
|
|
95
|
+
return buffer.Buffer.from(arr);
|
|
868
96
|
}
|
|
869
97
|
};
|
|
870
98
|
|
|
871
|
-
SHA512$1.prototype._update = function _update(msg, start) {
|
|
872
|
-
this._prepareBlock(msg, start);
|
|
873
|
-
|
|
874
|
-
var W = this.W;
|
|
875
|
-
|
|
876
|
-
var ah = this.h[0];
|
|
877
|
-
var al = this.h[1];
|
|
878
|
-
var bh = this.h[2];
|
|
879
|
-
var bl = this.h[3];
|
|
880
|
-
var ch = this.h[4];
|
|
881
|
-
var cl = this.h[5];
|
|
882
|
-
var dh = this.h[6];
|
|
883
|
-
var dl = this.h[7];
|
|
884
|
-
var eh = this.h[8];
|
|
885
|
-
var el = this.h[9];
|
|
886
|
-
var fh = this.h[10];
|
|
887
|
-
var fl = this.h[11];
|
|
888
|
-
var gh = this.h[12];
|
|
889
|
-
var gl = this.h[13];
|
|
890
|
-
var hh = this.h[14];
|
|
891
|
-
var hl = this.h[15];
|
|
892
|
-
|
|
893
|
-
assert$2(this.k.length === W.length);
|
|
894
|
-
for (var i = 0; i < W.length; i += 2) {
|
|
895
|
-
var c0_hi = hh;
|
|
896
|
-
var c0_lo = hl;
|
|
897
|
-
var c1_hi = s1_512_hi(eh, el);
|
|
898
|
-
var c1_lo = s1_512_lo(eh, el);
|
|
899
|
-
var c2_hi = ch64_hi(eh, el, fh, fl, gh);
|
|
900
|
-
var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
|
|
901
|
-
var c3_hi = this.k[i];
|
|
902
|
-
var c3_lo = this.k[i + 1];
|
|
903
|
-
var c4_hi = W[i];
|
|
904
|
-
var c4_lo = W[i + 1];
|
|
905
|
-
|
|
906
|
-
var T1_hi = sum64_5_hi(
|
|
907
|
-
c0_hi, c0_lo,
|
|
908
|
-
c1_hi, c1_lo,
|
|
909
|
-
c2_hi, c2_lo,
|
|
910
|
-
c3_hi, c3_lo,
|
|
911
|
-
c4_hi, c4_lo);
|
|
912
|
-
var T1_lo = sum64_5_lo(
|
|
913
|
-
c0_hi, c0_lo,
|
|
914
|
-
c1_hi, c1_lo,
|
|
915
|
-
c2_hi, c2_lo,
|
|
916
|
-
c3_hi, c3_lo,
|
|
917
|
-
c4_hi, c4_lo);
|
|
918
|
-
|
|
919
|
-
c0_hi = s0_512_hi(ah, al);
|
|
920
|
-
c0_lo = s0_512_lo(ah, al);
|
|
921
|
-
c1_hi = maj64_hi(ah, al, bh, bl, ch);
|
|
922
|
-
c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
|
|
923
|
-
|
|
924
|
-
var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
925
|
-
var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
926
|
-
|
|
927
|
-
hh = gh;
|
|
928
|
-
hl = gl;
|
|
929
|
-
|
|
930
|
-
gh = fh;
|
|
931
|
-
gl = fl;
|
|
932
|
-
|
|
933
|
-
fh = eh;
|
|
934
|
-
fl = el;
|
|
935
|
-
|
|
936
|
-
eh = sum64_hi(dh, dl, T1_hi, T1_lo);
|
|
937
|
-
el = sum64_lo(dl, dl, T1_hi, T1_lo);
|
|
938
|
-
|
|
939
|
-
dh = ch;
|
|
940
|
-
dl = cl;
|
|
941
|
-
|
|
942
|
-
ch = bh;
|
|
943
|
-
cl = bl;
|
|
944
|
-
|
|
945
|
-
bh = ah;
|
|
946
|
-
bl = al;
|
|
947
|
-
|
|
948
|
-
ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
949
|
-
al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
sum64(this.h, 0, ah, al);
|
|
953
|
-
sum64(this.h, 2, bh, bl);
|
|
954
|
-
sum64(this.h, 4, ch, cl);
|
|
955
|
-
sum64(this.h, 6, dh, dl);
|
|
956
|
-
sum64(this.h, 8, eh, el);
|
|
957
|
-
sum64(this.h, 10, fh, fl);
|
|
958
|
-
sum64(this.h, 12, gh, gl);
|
|
959
|
-
sum64(this.h, 14, hh, hl);
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
SHA512$1.prototype._digest = function digest(enc) {
|
|
963
|
-
if (enc === 'hex')
|
|
964
|
-
return utils$3.toHex32(this.h, 'big');
|
|
965
|
-
else
|
|
966
|
-
return utils$3.split32(this.h, 'big');
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
function ch64_hi(xh, xl, yh, yl, zh) {
|
|
970
|
-
var r = (xh & yh) ^ ((~xh) & zh);
|
|
971
|
-
if (r < 0)
|
|
972
|
-
r += 0x100000000;
|
|
973
|
-
return r;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
function ch64_lo(xh, xl, yh, yl, zh, zl) {
|
|
977
|
-
var r = (xl & yl) ^ ((~xl) & zl);
|
|
978
|
-
if (r < 0)
|
|
979
|
-
r += 0x100000000;
|
|
980
|
-
return r;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function maj64_hi(xh, xl, yh, yl, zh) {
|
|
984
|
-
var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
|
|
985
|
-
if (r < 0)
|
|
986
|
-
r += 0x100000000;
|
|
987
|
-
return r;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
function maj64_lo(xh, xl, yh, yl, zh, zl) {
|
|
991
|
-
var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
|
|
992
|
-
if (r < 0)
|
|
993
|
-
r += 0x100000000;
|
|
994
|
-
return r;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
function s0_512_hi(xh, xl) {
|
|
998
|
-
var c0_hi = rotr64_hi(xh, xl, 28);
|
|
999
|
-
var c1_hi = rotr64_hi(xl, xh, 2); // 34
|
|
1000
|
-
var c2_hi = rotr64_hi(xl, xh, 7); // 39
|
|
1001
|
-
|
|
1002
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1003
|
-
if (r < 0)
|
|
1004
|
-
r += 0x100000000;
|
|
1005
|
-
return r;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
function s0_512_lo(xh, xl) {
|
|
1009
|
-
var c0_lo = rotr64_lo(xh, xl, 28);
|
|
1010
|
-
var c1_lo = rotr64_lo(xl, xh, 2); // 34
|
|
1011
|
-
var c2_lo = rotr64_lo(xl, xh, 7); // 39
|
|
1012
|
-
|
|
1013
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1014
|
-
if (r < 0)
|
|
1015
|
-
r += 0x100000000;
|
|
1016
|
-
return r;
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function s1_512_hi(xh, xl) {
|
|
1020
|
-
var c0_hi = rotr64_hi(xh, xl, 14);
|
|
1021
|
-
var c1_hi = rotr64_hi(xh, xl, 18);
|
|
1022
|
-
var c2_hi = rotr64_hi(xl, xh, 9); // 41
|
|
1023
|
-
|
|
1024
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1025
|
-
if (r < 0)
|
|
1026
|
-
r += 0x100000000;
|
|
1027
|
-
return r;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
function s1_512_lo(xh, xl) {
|
|
1031
|
-
var c0_lo = rotr64_lo(xh, xl, 14);
|
|
1032
|
-
var c1_lo = rotr64_lo(xh, xl, 18);
|
|
1033
|
-
var c2_lo = rotr64_lo(xl, xh, 9); // 41
|
|
1034
|
-
|
|
1035
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1036
|
-
if (r < 0)
|
|
1037
|
-
r += 0x100000000;
|
|
1038
|
-
return r;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
function g0_512_hi(xh, xl) {
|
|
1042
|
-
var c0_hi = rotr64_hi(xh, xl, 1);
|
|
1043
|
-
var c1_hi = rotr64_hi(xh, xl, 8);
|
|
1044
|
-
var c2_hi = shr64_hi(xh, xl, 7);
|
|
1045
|
-
|
|
1046
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1047
|
-
if (r < 0)
|
|
1048
|
-
r += 0x100000000;
|
|
1049
|
-
return r;
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
function g0_512_lo(xh, xl) {
|
|
1053
|
-
var c0_lo = rotr64_lo(xh, xl, 1);
|
|
1054
|
-
var c1_lo = rotr64_lo(xh, xl, 8);
|
|
1055
|
-
var c2_lo = shr64_lo(xh, xl, 7);
|
|
1056
|
-
|
|
1057
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1058
|
-
if (r < 0)
|
|
1059
|
-
r += 0x100000000;
|
|
1060
|
-
return r;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
function g1_512_hi(xh, xl) {
|
|
1064
|
-
var c0_hi = rotr64_hi(xh, xl, 19);
|
|
1065
|
-
var c1_hi = rotr64_hi(xl, xh, 29); // 61
|
|
1066
|
-
var c2_hi = shr64_hi(xh, xl, 6);
|
|
1067
|
-
|
|
1068
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1069
|
-
if (r < 0)
|
|
1070
|
-
r += 0x100000000;
|
|
1071
|
-
return r;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
function g1_512_lo(xh, xl) {
|
|
1075
|
-
var c0_lo = rotr64_lo(xh, xl, 19);
|
|
1076
|
-
var c1_lo = rotr64_lo(xl, xh, 29); // 61
|
|
1077
|
-
var c2_lo = shr64_lo(xh, xl, 6);
|
|
1078
|
-
|
|
1079
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1080
|
-
if (r < 0)
|
|
1081
|
-
r += 0x100000000;
|
|
1082
|
-
return r;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
var utils$2 = utils$9;
|
|
1086
|
-
|
|
1087
|
-
var SHA512 = _512;
|
|
1088
|
-
|
|
1089
|
-
function SHA384() {
|
|
1090
|
-
if (!(this instanceof SHA384))
|
|
1091
|
-
return new SHA384();
|
|
1092
|
-
|
|
1093
|
-
SHA512.call(this);
|
|
1094
|
-
this.h = [
|
|
1095
|
-
0xcbbb9d5d, 0xc1059ed8,
|
|
1096
|
-
0x629a292a, 0x367cd507,
|
|
1097
|
-
0x9159015a, 0x3070dd17,
|
|
1098
|
-
0x152fecd8, 0xf70e5939,
|
|
1099
|
-
0x67332667, 0xffc00b31,
|
|
1100
|
-
0x8eb44a87, 0x68581511,
|
|
1101
|
-
0xdb0c2e0d, 0x64f98fa7,
|
|
1102
|
-
0x47b5481d, 0xbefa4fa4 ];
|
|
1103
|
-
}
|
|
1104
|
-
utils$2.inherits(SHA384, SHA512);
|
|
1105
|
-
var _384 = SHA384;
|
|
1106
|
-
|
|
1107
|
-
SHA384.blockSize = 1024;
|
|
1108
|
-
SHA384.outSize = 384;
|
|
1109
|
-
SHA384.hmacStrength = 192;
|
|
1110
|
-
SHA384.padLength = 128;
|
|
1111
|
-
|
|
1112
|
-
SHA384.prototype._digest = function digest(enc) {
|
|
1113
|
-
if (enc === 'hex')
|
|
1114
|
-
return utils$2.toHex32(this.h.slice(0, 12), 'big');
|
|
1115
|
-
else
|
|
1116
|
-
return utils$2.split32(this.h.slice(0, 12), 'big');
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
sha.sha1 = _1;
|
|
1120
|
-
sha.sha224 = _224;
|
|
1121
|
-
sha.sha256 = _256;
|
|
1122
|
-
sha.sha384 = _384;
|
|
1123
|
-
sha.sha512 = _512;
|
|
1124
|
-
|
|
1125
|
-
var ripemd = {};
|
|
1126
|
-
|
|
1127
|
-
var utils$1 = utils$9;
|
|
1128
|
-
var common = common$5;
|
|
1129
|
-
|
|
1130
|
-
var rotl32 = utils$1.rotl32;
|
|
1131
|
-
var sum32 = utils$1.sum32;
|
|
1132
|
-
var sum32_3 = utils$1.sum32_3;
|
|
1133
|
-
var sum32_4 = utils$1.sum32_4;
|
|
1134
|
-
var BlockHash = common.BlockHash;
|
|
1135
|
-
|
|
1136
|
-
function RIPEMD160() {
|
|
1137
|
-
if (!(this instanceof RIPEMD160))
|
|
1138
|
-
return new RIPEMD160();
|
|
1139
|
-
|
|
1140
|
-
BlockHash.call(this);
|
|
1141
|
-
|
|
1142
|
-
this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
|
|
1143
|
-
this.endian = 'little';
|
|
1144
|
-
}
|
|
1145
|
-
utils$1.inherits(RIPEMD160, BlockHash);
|
|
1146
|
-
ripemd.ripemd160 = RIPEMD160;
|
|
1147
|
-
|
|
1148
|
-
RIPEMD160.blockSize = 512;
|
|
1149
|
-
RIPEMD160.outSize = 160;
|
|
1150
|
-
RIPEMD160.hmacStrength = 192;
|
|
1151
|
-
RIPEMD160.padLength = 64;
|
|
1152
|
-
|
|
1153
|
-
RIPEMD160.prototype._update = function update(msg, start) {
|
|
1154
|
-
var A = this.h[0];
|
|
1155
|
-
var B = this.h[1];
|
|
1156
|
-
var C = this.h[2];
|
|
1157
|
-
var D = this.h[3];
|
|
1158
|
-
var E = this.h[4];
|
|
1159
|
-
var Ah = A;
|
|
1160
|
-
var Bh = B;
|
|
1161
|
-
var Ch = C;
|
|
1162
|
-
var Dh = D;
|
|
1163
|
-
var Eh = E;
|
|
1164
|
-
for (var j = 0; j < 80; j++) {
|
|
1165
|
-
var T = sum32(
|
|
1166
|
-
rotl32(
|
|
1167
|
-
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
|
1168
|
-
s[j]),
|
|
1169
|
-
E);
|
|
1170
|
-
A = E;
|
|
1171
|
-
E = D;
|
|
1172
|
-
D = rotl32(C, 10);
|
|
1173
|
-
C = B;
|
|
1174
|
-
B = T;
|
|
1175
|
-
T = sum32(
|
|
1176
|
-
rotl32(
|
|
1177
|
-
sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
|
|
1178
|
-
sh[j]),
|
|
1179
|
-
Eh);
|
|
1180
|
-
Ah = Eh;
|
|
1181
|
-
Eh = Dh;
|
|
1182
|
-
Dh = rotl32(Ch, 10);
|
|
1183
|
-
Ch = Bh;
|
|
1184
|
-
Bh = T;
|
|
1185
|
-
}
|
|
1186
|
-
T = sum32_3(this.h[1], C, Dh);
|
|
1187
|
-
this.h[1] = sum32_3(this.h[2], D, Eh);
|
|
1188
|
-
this.h[2] = sum32_3(this.h[3], E, Ah);
|
|
1189
|
-
this.h[3] = sum32_3(this.h[4], A, Bh);
|
|
1190
|
-
this.h[4] = sum32_3(this.h[0], B, Ch);
|
|
1191
|
-
this.h[0] = T;
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
RIPEMD160.prototype._digest = function digest(enc) {
|
|
1195
|
-
if (enc === 'hex')
|
|
1196
|
-
return utils$1.toHex32(this.h, 'little');
|
|
1197
|
-
else
|
|
1198
|
-
return utils$1.split32(this.h, 'little');
|
|
1199
|
-
};
|
|
1200
|
-
|
|
1201
|
-
function f(j, x, y, z) {
|
|
1202
|
-
if (j <= 15)
|
|
1203
|
-
return x ^ y ^ z;
|
|
1204
|
-
else if (j <= 31)
|
|
1205
|
-
return (x & y) | ((~x) & z);
|
|
1206
|
-
else if (j <= 47)
|
|
1207
|
-
return (x | (~y)) ^ z;
|
|
1208
|
-
else if (j <= 63)
|
|
1209
|
-
return (x & z) | (y & (~z));
|
|
1210
|
-
else
|
|
1211
|
-
return x ^ (y | (~z));
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
function K(j) {
|
|
1215
|
-
if (j <= 15)
|
|
1216
|
-
return 0x00000000;
|
|
1217
|
-
else if (j <= 31)
|
|
1218
|
-
return 0x5a827999;
|
|
1219
|
-
else if (j <= 47)
|
|
1220
|
-
return 0x6ed9eba1;
|
|
1221
|
-
else if (j <= 63)
|
|
1222
|
-
return 0x8f1bbcdc;
|
|
1223
|
-
else
|
|
1224
|
-
return 0xa953fd4e;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function Kh(j) {
|
|
1228
|
-
if (j <= 15)
|
|
1229
|
-
return 0x50a28be6;
|
|
1230
|
-
else if (j <= 31)
|
|
1231
|
-
return 0x5c4dd124;
|
|
1232
|
-
else if (j <= 47)
|
|
1233
|
-
return 0x6d703ef3;
|
|
1234
|
-
else if (j <= 63)
|
|
1235
|
-
return 0x7a6d76e9;
|
|
1236
|
-
else
|
|
1237
|
-
return 0x00000000;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
var r = [
|
|
1241
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
1242
|
-
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
1243
|
-
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
|
1244
|
-
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
|
1245
|
-
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
|
|
1246
|
-
];
|
|
1247
|
-
|
|
1248
|
-
var rh = [
|
|
1249
|
-
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
|
1250
|
-
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
|
1251
|
-
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
|
1252
|
-
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
|
1253
|
-
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
|
|
1254
|
-
];
|
|
1255
|
-
|
|
1256
|
-
var s = [
|
|
1257
|
-
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
|
1258
|
-
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
|
1259
|
-
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
|
1260
|
-
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
|
1261
|
-
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
|
|
1262
|
-
];
|
|
1263
|
-
|
|
1264
|
-
var sh = [
|
|
1265
|
-
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
|
1266
|
-
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
|
1267
|
-
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
|
1268
|
-
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
|
1269
|
-
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
|
|
1270
|
-
];
|
|
1271
|
-
|
|
1272
|
-
var utils = utils$9;
|
|
1273
|
-
var assert$1 = minimalisticAssert;
|
|
1274
|
-
|
|
1275
|
-
function Hmac(hash, key, enc) {
|
|
1276
|
-
if (!(this instanceof Hmac))
|
|
1277
|
-
return new Hmac(hash, key, enc);
|
|
1278
|
-
this.Hash = hash;
|
|
1279
|
-
this.blockSize = hash.blockSize / 8;
|
|
1280
|
-
this.outSize = hash.outSize / 8;
|
|
1281
|
-
this.inner = null;
|
|
1282
|
-
this.outer = null;
|
|
1283
|
-
|
|
1284
|
-
this._init(utils.toArray(key, enc));
|
|
1285
|
-
}
|
|
1286
|
-
var hmac = Hmac;
|
|
1287
|
-
|
|
1288
|
-
Hmac.prototype._init = function init(key) {
|
|
1289
|
-
// Shorten key, if needed
|
|
1290
|
-
if (key.length > this.blockSize)
|
|
1291
|
-
key = new this.Hash().update(key).digest();
|
|
1292
|
-
assert$1(key.length <= this.blockSize);
|
|
1293
|
-
|
|
1294
|
-
// Add padding to key
|
|
1295
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1296
|
-
key.push(0);
|
|
1297
|
-
|
|
1298
|
-
for (i = 0; i < key.length; i++)
|
|
1299
|
-
key[i] ^= 0x36;
|
|
1300
|
-
this.inner = new this.Hash().update(key);
|
|
1301
|
-
|
|
1302
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1303
|
-
for (i = 0; i < key.length; i++)
|
|
1304
|
-
key[i] ^= 0x6a;
|
|
1305
|
-
this.outer = new this.Hash().update(key);
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1309
|
-
this.inner.update(msg, enc);
|
|
1310
|
-
return this;
|
|
1311
|
-
};
|
|
1312
|
-
|
|
1313
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1314
|
-
this.outer.update(this.inner.digest());
|
|
1315
|
-
return this.outer.digest(enc);
|
|
1316
|
-
};
|
|
1317
|
-
|
|
1318
|
-
(function (exports) {
|
|
1319
|
-
var hash = exports;
|
|
1320
|
-
|
|
1321
|
-
hash.utils = utils$9;
|
|
1322
|
-
hash.common = common$5;
|
|
1323
|
-
hash.sha = sha;
|
|
1324
|
-
hash.ripemd = ripemd;
|
|
1325
|
-
hash.hmac = hmac;
|
|
1326
|
-
|
|
1327
|
-
// Proxy hash functions to the main object
|
|
1328
|
-
hash.sha1 = hash.sha.sha1;
|
|
1329
|
-
hash.sha256 = hash.sha.sha256;
|
|
1330
|
-
hash.sha224 = hash.sha.sha224;
|
|
1331
|
-
hash.sha384 = hash.sha.sha384;
|
|
1332
|
-
hash.sha512 = hash.sha.sha512;
|
|
1333
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1334
|
-
} (hash$1));
|
|
1335
|
-
|
|
1336
|
-
var hash = hash$1;
|
|
1337
|
-
|
|
1338
|
-
const version$2 = "logger/5.6.0";
|
|
1339
|
-
|
|
1340
|
-
let _permanentCensorErrors = false;
|
|
1341
|
-
let _censorErrors = false;
|
|
1342
|
-
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1343
|
-
let _logLevel = LogLevels["default"];
|
|
1344
|
-
let _globalLogger = null;
|
|
1345
|
-
function _checkNormalize() {
|
|
1346
|
-
try {
|
|
1347
|
-
const missing = [];
|
|
1348
|
-
// Make sure all forms of normalization are supported
|
|
1349
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1350
|
-
try {
|
|
1351
|
-
if ("test".normalize(form) !== "test") {
|
|
1352
|
-
throw new Error("bad normalize");
|
|
1353
|
-
}
|
|
1354
|
-
;
|
|
1355
|
-
}
|
|
1356
|
-
catch (error) {
|
|
1357
|
-
missing.push(form);
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
if (missing.length) {
|
|
1361
|
-
throw new Error("missing " + missing.join(", "));
|
|
1362
|
-
}
|
|
1363
|
-
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1364
|
-
throw new Error("broken implementation");
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
catch (error) {
|
|
1368
|
-
return error.message;
|
|
1369
|
-
}
|
|
1370
|
-
return null;
|
|
1371
|
-
}
|
|
1372
|
-
const _normalizeError = _checkNormalize();
|
|
1373
|
-
var LogLevel;
|
|
1374
|
-
(function (LogLevel) {
|
|
1375
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
1376
|
-
LogLevel["INFO"] = "INFO";
|
|
1377
|
-
LogLevel["WARNING"] = "WARNING";
|
|
1378
|
-
LogLevel["ERROR"] = "ERROR";
|
|
1379
|
-
LogLevel["OFF"] = "OFF";
|
|
1380
|
-
})(LogLevel || (LogLevel = {}));
|
|
1381
|
-
var ErrorCode;
|
|
1382
|
-
(function (ErrorCode) {
|
|
1383
|
-
///////////////////
|
|
1384
|
-
// Generic Errors
|
|
1385
|
-
// Unknown Error
|
|
1386
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1387
|
-
// Not Implemented
|
|
1388
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1389
|
-
// Unsupported Operation
|
|
1390
|
-
// - operation
|
|
1391
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1392
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1393
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1394
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1395
|
-
// Some sort of bad response from the server
|
|
1396
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1397
|
-
// Timeout
|
|
1398
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1399
|
-
///////////////////
|
|
1400
|
-
// Operational Errors
|
|
1401
|
-
// Buffer Overrun
|
|
1402
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1403
|
-
// Numeric Fault
|
|
1404
|
-
// - operation: the operation being executed
|
|
1405
|
-
// - fault: the reason this faulted
|
|
1406
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1407
|
-
///////////////////
|
|
1408
|
-
// Argument Errors
|
|
1409
|
-
// Missing new operator to an object
|
|
1410
|
-
// - name: The name of the class
|
|
1411
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1412
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1413
|
-
// - argument: The argument name that was invalid
|
|
1414
|
-
// - value: The value of the argument
|
|
1415
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1416
|
-
// Missing argument to a function:
|
|
1417
|
-
// - count: The number of arguments received
|
|
1418
|
-
// - expectedCount: The number of arguments expected
|
|
1419
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1420
|
-
// Too many arguments
|
|
1421
|
-
// - count: The number of arguments received
|
|
1422
|
-
// - expectedCount: The number of arguments expected
|
|
1423
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1424
|
-
///////////////////
|
|
1425
|
-
// Blockchain Errors
|
|
1426
|
-
// Call exception
|
|
1427
|
-
// - transaction: the transaction
|
|
1428
|
-
// - address?: the contract address
|
|
1429
|
-
// - args?: The arguments passed into the function
|
|
1430
|
-
// - method?: The Solidity method signature
|
|
1431
|
-
// - errorSignature?: The EIP848 error signature
|
|
1432
|
-
// - errorArgs?: The EIP848 error parameters
|
|
1433
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1434
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1435
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1436
|
-
// - transaction: the transaction attempted
|
|
1437
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1438
|
-
// Nonce has already been used
|
|
1439
|
-
// - transaction: the transaction attempted
|
|
1440
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1441
|
-
// The replacement fee for the transaction is too low
|
|
1442
|
-
// - transaction: the transaction attempted
|
|
1443
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1444
|
-
// The gas limit could not be estimated
|
|
1445
|
-
// - transaction: the transaction passed to estimateGas
|
|
1446
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1447
|
-
// The transaction was replaced by one with a higher gas price
|
|
1448
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
1449
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1450
|
-
// - hash: original transaction hash
|
|
1451
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
1452
|
-
// - receipt: the receipt of the replacement
|
|
1453
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1454
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
1455
|
-
const HEX = "0123456789abcdef";
|
|
1456
|
-
class Logger {
|
|
1457
|
-
constructor(version) {
|
|
1458
|
-
Object.defineProperty(this, "version", {
|
|
1459
|
-
enumerable: true,
|
|
1460
|
-
value: version,
|
|
1461
|
-
writable: false
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
_log(logLevel, args) {
|
|
1465
|
-
const level = logLevel.toLowerCase();
|
|
1466
|
-
if (LogLevels[level] == null) {
|
|
1467
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1468
|
-
}
|
|
1469
|
-
if (_logLevel > LogLevels[level]) {
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1472
|
-
console.log.apply(console, args);
|
|
1473
|
-
}
|
|
1474
|
-
debug(...args) {
|
|
1475
|
-
this._log(Logger.levels.DEBUG, args);
|
|
1476
|
-
}
|
|
1477
|
-
info(...args) {
|
|
1478
|
-
this._log(Logger.levels.INFO, args);
|
|
1479
|
-
}
|
|
1480
|
-
warn(...args) {
|
|
1481
|
-
this._log(Logger.levels.WARNING, args);
|
|
1482
|
-
}
|
|
1483
|
-
makeError(message, code, params) {
|
|
1484
|
-
// Errors are being censored
|
|
1485
|
-
if (_censorErrors) {
|
|
1486
|
-
return this.makeError("censored error", code, {});
|
|
1487
|
-
}
|
|
1488
|
-
if (!code) {
|
|
1489
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
1490
|
-
}
|
|
1491
|
-
if (!params) {
|
|
1492
|
-
params = {};
|
|
1493
|
-
}
|
|
1494
|
-
const messageDetails = [];
|
|
1495
|
-
Object.keys(params).forEach((key) => {
|
|
1496
|
-
const value = params[key];
|
|
1497
|
-
try {
|
|
1498
|
-
if (value instanceof Uint8Array) {
|
|
1499
|
-
let hex = "";
|
|
1500
|
-
for (let i = 0; i < value.length; i++) {
|
|
1501
|
-
hex += HEX[value[i] >> 4];
|
|
1502
|
-
hex += HEX[value[i] & 0x0f];
|
|
1503
|
-
}
|
|
1504
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1505
|
-
}
|
|
1506
|
-
else {
|
|
1507
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
catch (error) {
|
|
1511
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
messageDetails.push(`code=${code}`);
|
|
1515
|
-
messageDetails.push(`version=${this.version}`);
|
|
1516
|
-
const reason = message;
|
|
1517
|
-
let url = "";
|
|
1518
|
-
switch (code) {
|
|
1519
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
1520
|
-
url = "NUMERIC_FAULT";
|
|
1521
|
-
const fault = message;
|
|
1522
|
-
switch (fault) {
|
|
1523
|
-
case "overflow":
|
|
1524
|
-
case "underflow":
|
|
1525
|
-
case "division-by-zero":
|
|
1526
|
-
url += "-" + fault;
|
|
1527
|
-
break;
|
|
1528
|
-
case "negative-power":
|
|
1529
|
-
case "negative-width":
|
|
1530
|
-
url += "-unsupported";
|
|
1531
|
-
break;
|
|
1532
|
-
case "unbound-bitwise-result":
|
|
1533
|
-
url += "-unbound-result";
|
|
1534
|
-
break;
|
|
1535
|
-
}
|
|
1536
|
-
break;
|
|
1537
|
-
}
|
|
1538
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
1539
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
1540
|
-
case ErrorCode.MISSING_NEW:
|
|
1541
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
1542
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
1543
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
1544
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
1545
|
-
url = code;
|
|
1546
|
-
break;
|
|
1547
|
-
}
|
|
1548
|
-
if (url) {
|
|
1549
|
-
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
1550
|
-
}
|
|
1551
|
-
if (messageDetails.length) {
|
|
1552
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
1553
|
-
}
|
|
1554
|
-
// @TODO: Any??
|
|
1555
|
-
const error = new Error(message);
|
|
1556
|
-
error.reason = reason;
|
|
1557
|
-
error.code = code;
|
|
1558
|
-
Object.keys(params).forEach(function (key) {
|
|
1559
|
-
error[key] = params[key];
|
|
1560
|
-
});
|
|
1561
|
-
return error;
|
|
1562
|
-
}
|
|
1563
|
-
throwError(message, code, params) {
|
|
1564
|
-
throw this.makeError(message, code, params);
|
|
1565
|
-
}
|
|
1566
|
-
throwArgumentError(message, name, value) {
|
|
1567
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1568
|
-
argument: name,
|
|
1569
|
-
value: value
|
|
1570
|
-
});
|
|
1571
|
-
}
|
|
1572
|
-
assert(condition, message, code, params) {
|
|
1573
|
-
if (!!condition) {
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
this.throwError(message, code, params);
|
|
1577
|
-
}
|
|
1578
|
-
assertArgument(condition, message, name, value) {
|
|
1579
|
-
if (!!condition) {
|
|
1580
|
-
return;
|
|
1581
|
-
}
|
|
1582
|
-
this.throwArgumentError(message, name, value);
|
|
1583
|
-
}
|
|
1584
|
-
checkNormalize(message) {
|
|
1585
|
-
if (_normalizeError) {
|
|
1586
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1587
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
checkSafeUint53(value, message) {
|
|
1592
|
-
if (typeof (value) !== "number") {
|
|
1593
|
-
return;
|
|
1594
|
-
}
|
|
1595
|
-
if (message == null) {
|
|
1596
|
-
message = "value not safe";
|
|
1597
|
-
}
|
|
1598
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1599
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1600
|
-
operation: "checkSafeInteger",
|
|
1601
|
-
fault: "out-of-safe-range",
|
|
1602
|
-
value: value
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
if (value % 1) {
|
|
1606
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1607
|
-
operation: "checkSafeInteger",
|
|
1608
|
-
fault: "non-integer",
|
|
1609
|
-
value: value
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
1614
|
-
if (message) {
|
|
1615
|
-
message = ": " + message;
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
message = "";
|
|
1619
|
-
}
|
|
1620
|
-
if (count < expectedCount) {
|
|
1621
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1622
|
-
count: count,
|
|
1623
|
-
expectedCount: expectedCount
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
if (count > expectedCount) {
|
|
1627
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1628
|
-
count: count,
|
|
1629
|
-
expectedCount: expectedCount
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
checkNew(target, kind) {
|
|
1634
|
-
if (target === Object || target == null) {
|
|
1635
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
checkAbstract(target, kind) {
|
|
1639
|
-
if (target === kind) {
|
|
1640
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1641
|
-
}
|
|
1642
|
-
else if (target === Object || target == null) {
|
|
1643
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
static globalLogger() {
|
|
1647
|
-
if (!_globalLogger) {
|
|
1648
|
-
_globalLogger = new Logger(version$2);
|
|
1649
|
-
}
|
|
1650
|
-
return _globalLogger;
|
|
1651
|
-
}
|
|
1652
|
-
static setCensorship(censorship, permanent) {
|
|
1653
|
-
if (!censorship && permanent) {
|
|
1654
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1655
|
-
operation: "setCensorship"
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
if (_permanentCensorErrors) {
|
|
1659
|
-
if (!censorship) {
|
|
1660
|
-
return;
|
|
1661
|
-
}
|
|
1662
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1663
|
-
operation: "setCensorship"
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
_censorErrors = !!censorship;
|
|
1667
|
-
_permanentCensorErrors = !!permanent;
|
|
1668
|
-
}
|
|
1669
|
-
static setLogLevel(logLevel) {
|
|
1670
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
1671
|
-
if (level == null) {
|
|
1672
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1673
|
-
return;
|
|
1674
|
-
}
|
|
1675
|
-
_logLevel = level;
|
|
1676
|
-
}
|
|
1677
|
-
static from(version) {
|
|
1678
|
-
return new Logger(version);
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
Logger.errors = ErrorCode;
|
|
1682
|
-
Logger.levels = LogLevel;
|
|
1683
|
-
|
|
1684
|
-
const version$1 = "bytes/5.6.0";
|
|
1685
|
-
|
|
1686
|
-
const logger = new Logger(version$1);
|
|
1687
|
-
///////////////////////////////
|
|
1688
|
-
function isHexable(value) {
|
|
1689
|
-
return !!(value.toHexString);
|
|
1690
|
-
}
|
|
1691
|
-
function addSlice(array) {
|
|
1692
|
-
if (array.slice) {
|
|
1693
|
-
return array;
|
|
1694
|
-
}
|
|
1695
|
-
array.slice = function () {
|
|
1696
|
-
const args = Array.prototype.slice.call(arguments);
|
|
1697
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1698
|
-
};
|
|
1699
|
-
return array;
|
|
1700
|
-
}
|
|
1701
|
-
function isInteger(value) {
|
|
1702
|
-
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1703
|
-
}
|
|
1704
|
-
function isBytes(value) {
|
|
1705
|
-
if (value == null) {
|
|
1706
|
-
return false;
|
|
1707
|
-
}
|
|
1708
|
-
if (value.constructor === Uint8Array) {
|
|
1709
|
-
return true;
|
|
1710
|
-
}
|
|
1711
|
-
if (typeof (value) === "string") {
|
|
1712
|
-
return false;
|
|
1713
|
-
}
|
|
1714
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
1715
|
-
return false;
|
|
1716
|
-
}
|
|
1717
|
-
for (let i = 0; i < value.length; i++) {
|
|
1718
|
-
const v = value[i];
|
|
1719
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1720
|
-
return false;
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
return true;
|
|
1724
|
-
}
|
|
1725
|
-
function arrayify(value, options) {
|
|
1726
|
-
if (!options) {
|
|
1727
|
-
options = {};
|
|
1728
|
-
}
|
|
1729
|
-
if (typeof (value) === "number") {
|
|
1730
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1731
|
-
const result = [];
|
|
1732
|
-
while (value) {
|
|
1733
|
-
result.unshift(value & 0xff);
|
|
1734
|
-
value = parseInt(String(value / 256));
|
|
1735
|
-
}
|
|
1736
|
-
if (result.length === 0) {
|
|
1737
|
-
result.push(0);
|
|
1738
|
-
}
|
|
1739
|
-
return addSlice(new Uint8Array(result));
|
|
1740
|
-
}
|
|
1741
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1742
|
-
value = "0x" + value;
|
|
1743
|
-
}
|
|
1744
|
-
if (isHexable(value)) {
|
|
1745
|
-
value = value.toHexString();
|
|
1746
|
-
}
|
|
1747
|
-
if (isHexString(value)) {
|
|
1748
|
-
let hex = value.substring(2);
|
|
1749
|
-
if (hex.length % 2) {
|
|
1750
|
-
if (options.hexPad === "left") {
|
|
1751
|
-
hex = "0x0" + hex.substring(2);
|
|
1752
|
-
}
|
|
1753
|
-
else if (options.hexPad === "right") {
|
|
1754
|
-
hex += "0";
|
|
1755
|
-
}
|
|
1756
|
-
else {
|
|
1757
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
const result = [];
|
|
1761
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
1762
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1763
|
-
}
|
|
1764
|
-
return addSlice(new Uint8Array(result));
|
|
1765
|
-
}
|
|
1766
|
-
if (isBytes(value)) {
|
|
1767
|
-
return addSlice(new Uint8Array(value));
|
|
1768
|
-
}
|
|
1769
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1770
|
-
}
|
|
1771
|
-
function isHexString(value, length) {
|
|
1772
|
-
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1773
|
-
return false;
|
|
1774
|
-
}
|
|
1775
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
1776
|
-
return false;
|
|
1777
|
-
}
|
|
1778
|
-
return true;
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
const version = "sha2/5.6.0";
|
|
1782
|
-
|
|
1783
|
-
new Logger(version);
|
|
1784
|
-
function sha256(data) {
|
|
1785
|
-
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
99
|
class Struct {
|
|
1789
100
|
constructor(properties) {
|
|
1790
101
|
Object.assign(this, properties);
|
|
@@ -1942,8 +253,8 @@ class PublicKey extends Struct {
|
|
|
1942
253
|
|
|
1943
254
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1944
255
|
const buffer$1 = buffer.Buffer.concat([fromPublicKey.toBuffer(), buffer.Buffer.from(seed), programId.toBuffer()]);
|
|
1945
|
-
const
|
|
1946
|
-
return new PublicKey(
|
|
256
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
257
|
+
return new PublicKey(publicKeyBytes);
|
|
1947
258
|
}
|
|
1948
259
|
/**
|
|
1949
260
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1962,10 +273,9 @@ class PublicKey extends Struct {
|
|
|
1962
273
|
buffer$1 = buffer.Buffer.concat([buffer$1, toBuffer(seed)]);
|
|
1963
274
|
});
|
|
1964
275
|
buffer$1 = buffer.Buffer.concat([buffer$1, programId.toBuffer(), buffer.Buffer.from('ProgramDerivedAddress')]);
|
|
1965
|
-
|
|
1966
|
-
let publicKeyBytes = new BN__default["default"](hash, 16).toArray(undefined, 32);
|
|
276
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
1967
277
|
|
|
1968
|
-
if (
|
|
278
|
+
if (isOnCurve(publicKeyBytes)) {
|
|
1969
279
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1970
280
|
}
|
|
1971
281
|
|
|
@@ -2029,7 +339,7 @@ class PublicKey extends Struct {
|
|
|
2029
339
|
|
|
2030
340
|
static isOnCurve(pubkeyData) {
|
|
2031
341
|
const pubkey = new PublicKey(pubkeyData);
|
|
2032
|
-
return
|
|
342
|
+
return isOnCurve(pubkey.toBytes());
|
|
2033
343
|
}
|
|
2034
344
|
|
|
2035
345
|
}
|
|
@@ -2037,56 +347,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
|
2037
347
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
2038
348
|
kind: 'struct',
|
|
2039
349
|
fields: [['_bn', 'u256']]
|
|
2040
|
-
});
|
|
2041
|
-
|
|
2042
|
-
let naclLowLevel = nacl__default["default"].lowlevel; // Check that a pubkey is on the curve.
|
|
2043
|
-
// This function and its dependents were sourced from:
|
|
2044
|
-
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
2045
|
-
|
|
2046
|
-
function is_on_curve(p) {
|
|
2047
|
-
var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
|
|
2048
|
-
var t = naclLowLevel.gf(),
|
|
2049
|
-
chk = naclLowLevel.gf(),
|
|
2050
|
-
num = naclLowLevel.gf(),
|
|
2051
|
-
den = naclLowLevel.gf(),
|
|
2052
|
-
den2 = naclLowLevel.gf(),
|
|
2053
|
-
den4 = naclLowLevel.gf(),
|
|
2054
|
-
den6 = naclLowLevel.gf();
|
|
2055
|
-
naclLowLevel.set25519(r[2], gf1);
|
|
2056
|
-
naclLowLevel.unpack25519(r[1], p);
|
|
2057
|
-
naclLowLevel.S(num, r[1]);
|
|
2058
|
-
naclLowLevel.M(den, num, naclLowLevel.D);
|
|
2059
|
-
naclLowLevel.Z(num, num, r[2]);
|
|
2060
|
-
naclLowLevel.A(den, r[2], den);
|
|
2061
|
-
naclLowLevel.S(den2, den);
|
|
2062
|
-
naclLowLevel.S(den4, den2);
|
|
2063
|
-
naclLowLevel.M(den6, den4, den2);
|
|
2064
|
-
naclLowLevel.M(t, den6, num);
|
|
2065
|
-
naclLowLevel.M(t, t, den);
|
|
2066
|
-
naclLowLevel.pow2523(t, t);
|
|
2067
|
-
naclLowLevel.M(t, t, num);
|
|
2068
|
-
naclLowLevel.M(t, t, den);
|
|
2069
|
-
naclLowLevel.M(t, t, den);
|
|
2070
|
-
naclLowLevel.M(r[0], t, den);
|
|
2071
|
-
naclLowLevel.S(chk, r[0]);
|
|
2072
|
-
naclLowLevel.M(chk, chk, den);
|
|
2073
|
-
if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
|
|
2074
|
-
naclLowLevel.S(chk, r[0]);
|
|
2075
|
-
naclLowLevel.M(chk, chk, den);
|
|
2076
|
-
if (neq25519(chk, num)) return 0;
|
|
2077
|
-
return 1;
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
let gf1 = naclLowLevel.gf([1]);
|
|
2081
|
-
let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
2082
|
-
|
|
2083
|
-
function neq25519(a, b) {
|
|
2084
|
-
var c = new Uint8Array(32),
|
|
2085
|
-
d = new Uint8Array(32);
|
|
2086
|
-
naclLowLevel.pack25519(c, a);
|
|
2087
|
-
naclLowLevel.pack25519(d, b);
|
|
2088
|
-
return naclLowLevel.crypto_verify_32(c, 0, d, 0);
|
|
2089
|
-
}
|
|
350
|
+
});
|
|
2090
351
|
|
|
2091
352
|
/**
|
|
2092
353
|
* An account key pair (public and secret keys).
|
|
@@ -2097,6 +358,8 @@ function neq25519(a, b) {
|
|
|
2097
358
|
class Account {
|
|
2098
359
|
/** @internal */
|
|
2099
360
|
|
|
361
|
+
/** @internal */
|
|
362
|
+
|
|
2100
363
|
/**
|
|
2101
364
|
* Create a new Account object
|
|
2102
365
|
*
|
|
@@ -2106,12 +369,21 @@ class Account {
|
|
|
2106
369
|
* @param secretKey Secret key for the account
|
|
2107
370
|
*/
|
|
2108
371
|
constructor(secretKey) {
|
|
2109
|
-
this.
|
|
372
|
+
this._publicKey = void 0;
|
|
373
|
+
this._secretKey = void 0;
|
|
2110
374
|
|
|
2111
375
|
if (secretKey) {
|
|
2112
|
-
|
|
376
|
+
const secretKeyBuffer = toBuffer(secretKey);
|
|
377
|
+
|
|
378
|
+
if (secretKey.length !== 64) {
|
|
379
|
+
throw new Error('bad secret key size');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
this._publicKey = secretKeyBuffer.slice(32, 64);
|
|
383
|
+
this._secretKey = secretKeyBuffer.slice(0, 32);
|
|
2113
384
|
} else {
|
|
2114
|
-
this.
|
|
385
|
+
this._secretKey = toBuffer(generatePrivateKey());
|
|
386
|
+
this._publicKey = toBuffer(getPublicKey(this._secretKey));
|
|
2115
387
|
}
|
|
2116
388
|
}
|
|
2117
389
|
/**
|
|
@@ -2120,15 +392,17 @@ class Account {
|
|
|
2120
392
|
|
|
2121
393
|
|
|
2122
394
|
get publicKey() {
|
|
2123
|
-
return new PublicKey(this.
|
|
395
|
+
return new PublicKey(this._publicKey);
|
|
2124
396
|
}
|
|
2125
397
|
/**
|
|
2126
|
-
* The **unencrypted** secret key for this account
|
|
398
|
+
* The **unencrypted** secret key for this account. The first 32 bytes
|
|
399
|
+
* is the private scalar and the last 32 bytes is the public key.
|
|
400
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
2127
401
|
*/
|
|
2128
402
|
|
|
2129
403
|
|
|
2130
404
|
get secretKey() {
|
|
2131
|
-
return
|
|
405
|
+
return buffer.Buffer.concat([this._secretKey, this._publicKey], 64);
|
|
2132
406
|
}
|
|
2133
407
|
|
|
2134
408
|
}
|
|
@@ -2622,16 +896,24 @@ class MessageV0 {
|
|
|
2622
896
|
|
|
2623
897
|
// eslint-disable-next-line no-redeclare
|
|
2624
898
|
const VersionedMessage = {
|
|
2625
|
-
|
|
899
|
+
deserializeMessageVersion(serializedMessage) {
|
|
2626
900
|
const prefix = serializedMessage[0];
|
|
2627
901
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
|
|
2628
902
|
|
|
2629
903
|
if (maskedPrefix === prefix) {
|
|
2630
|
-
return
|
|
904
|
+
return 'legacy';
|
|
2631
905
|
} // the lower 7 bits of the prefix indicate the message version
|
|
2632
906
|
|
|
2633
907
|
|
|
2634
|
-
|
|
908
|
+
return maskedPrefix;
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
deserialize: serializedMessage => {
|
|
912
|
+
const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
|
|
913
|
+
|
|
914
|
+
if (version === 'legacy') {
|
|
915
|
+
return Message.from(serializedMessage);
|
|
916
|
+
}
|
|
2635
917
|
|
|
2636
918
|
if (version === 0) {
|
|
2637
919
|
return MessageV0.deserialize(serializedMessage);
|
|
@@ -2641,6 +923,10 @@ const VersionedMessage = {
|
|
|
2641
923
|
}
|
|
2642
924
|
};
|
|
2643
925
|
|
|
926
|
+
/**
|
|
927
|
+
* Transaction signature as base-58 encoded string
|
|
928
|
+
*/
|
|
929
|
+
|
|
2644
930
|
exports.TransactionStatus = void 0;
|
|
2645
931
|
/**
|
|
2646
932
|
* Default (empty) signature
|
|
@@ -3166,7 +1452,7 @@ class Transaction {
|
|
|
3166
1452
|
_partialSign(message, ...signers) {
|
|
3167
1453
|
const signData = message.serialize();
|
|
3168
1454
|
signers.forEach(signer => {
|
|
3169
|
-
const signature =
|
|
1455
|
+
const signature = sign(signData, signer.secretKey);
|
|
3170
1456
|
|
|
3171
1457
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
3172
1458
|
});
|
|
@@ -3222,7 +1508,7 @@ class Transaction {
|
|
|
3222
1508
|
return false;
|
|
3223
1509
|
}
|
|
3224
1510
|
} else {
|
|
3225
|
-
if (!
|
|
1511
|
+
if (!verify(signature, signData, publicKey.toBuffer())) {
|
|
3226
1512
|
return false;
|
|
3227
1513
|
}
|
|
3228
1514
|
}
|
|
@@ -3427,7 +1713,7 @@ class VersionedTransaction {
|
|
|
3427
1713
|
for (const signer of signers) {
|
|
3428
1714
|
const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
|
|
3429
1715
|
assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
|
|
3430
|
-
this.signatures[signerIndex] =
|
|
1716
|
+
this.signatures[signerIndex] = sign(messageData, signer.secretKey);
|
|
3431
1717
|
}
|
|
3432
1718
|
}
|
|
3433
1719
|
|
|
@@ -5011,6 +3297,28 @@ function notificationResultAndContext(value) {
|
|
|
5011
3297
|
value
|
|
5012
3298
|
});
|
|
5013
3299
|
}
|
|
3300
|
+
/**
|
|
3301
|
+
* @internal
|
|
3302
|
+
*/
|
|
3303
|
+
|
|
3304
|
+
|
|
3305
|
+
function versionedMessageFromResponse(version, response) {
|
|
3306
|
+
if (version === 0) {
|
|
3307
|
+
return new MessageV0({
|
|
3308
|
+
header: response.header,
|
|
3309
|
+
staticAccountKeys: response.accountKeys.map(accountKey => new PublicKey(accountKey)),
|
|
3310
|
+
recentBlockhash: response.recentBlockhash,
|
|
3311
|
+
compiledInstructions: response.instructions.map(ix => ({
|
|
3312
|
+
programIdIndex: ix.programIdIndex,
|
|
3313
|
+
accountKeyIndexes: ix.accounts,
|
|
3314
|
+
data: bs58__default["default"].decode(ix.data)
|
|
3315
|
+
})),
|
|
3316
|
+
addressTableLookups: response.addressTableLookups
|
|
3317
|
+
});
|
|
3318
|
+
} else {
|
|
3319
|
+
return new Message(response);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
5014
3322
|
/**
|
|
5015
3323
|
* The level of commitment desired when querying state
|
|
5016
3324
|
* <pre>
|
|
@@ -5574,6 +3882,11 @@ const GetSignatureStatusesRpcResult = jsonRpcResultAndContext(superstruct.array(
|
|
|
5574
3882
|
*/
|
|
5575
3883
|
|
|
5576
3884
|
const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult(superstruct.number());
|
|
3885
|
+
const AddressTableLookupStruct = superstruct.type({
|
|
3886
|
+
accountKey: PublicKeyFromString,
|
|
3887
|
+
writableIndexes: superstruct.array(superstruct.number()),
|
|
3888
|
+
readonlyIndexes: superstruct.array(superstruct.number())
|
|
3889
|
+
});
|
|
5577
3890
|
const ConfirmedTransactionResult = superstruct.type({
|
|
5578
3891
|
signatures: superstruct.array(superstruct.string()),
|
|
5579
3892
|
message: superstruct.type({
|
|
@@ -5588,7 +3901,8 @@ const ConfirmedTransactionResult = superstruct.type({
|
|
|
5588
3901
|
data: superstruct.string(),
|
|
5589
3902
|
programIdIndex: superstruct.number()
|
|
5590
3903
|
})),
|
|
5591
|
-
recentBlockhash: superstruct.string()
|
|
3904
|
+
recentBlockhash: superstruct.string(),
|
|
3905
|
+
addressTableLookups: superstruct.optional(superstruct.array(AddressTableLookupStruct))
|
|
5592
3906
|
})
|
|
5593
3907
|
});
|
|
5594
3908
|
const ParsedInstructionResult = superstruct.type({
|
|
@@ -5631,7 +3945,8 @@ const ParsedConfirmedTransactionResult = superstruct.type({
|
|
|
5631
3945
|
writable: superstruct.boolean()
|
|
5632
3946
|
})),
|
|
5633
3947
|
instructions: superstruct.array(ParsedOrRawInstruction),
|
|
5634
|
-
recentBlockhash: superstruct.string()
|
|
3948
|
+
recentBlockhash: superstruct.string(),
|
|
3949
|
+
addressTableLookups: superstruct.optional(superstruct.nullable(superstruct.array(AddressTableLookupStruct)))
|
|
5635
3950
|
})
|
|
5636
3951
|
});
|
|
5637
3952
|
const TokenBalanceResult = superstruct.type({
|
|
@@ -5684,6 +3999,7 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
|
|
|
5684
3999
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
5685
4000
|
loadedAddresses: superstruct.optional(LoadedAddressesResult)
|
|
5686
4001
|
});
|
|
4002
|
+
const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
|
|
5687
4003
|
/**
|
|
5688
4004
|
* Expected JSON RPC response for the "getBlock" message
|
|
5689
4005
|
*/
|
|
@@ -5694,7 +4010,8 @@ const GetBlockRpcResult = jsonRpcResult(superstruct.nullable(superstruct.type({
|
|
|
5694
4010
|
parentSlot: superstruct.number(),
|
|
5695
4011
|
transactions: superstruct.array(superstruct.type({
|
|
5696
4012
|
transaction: ConfirmedTransactionResult,
|
|
5697
|
-
meta: superstruct.nullable(ConfirmedTransactionMetaResult)
|
|
4013
|
+
meta: superstruct.nullable(ConfirmedTransactionMetaResult),
|
|
4014
|
+
version: superstruct.optional(TransactionVersionStruct)
|
|
5698
4015
|
})),
|
|
5699
4016
|
rewards: superstruct.optional(superstruct.array(superstruct.type({
|
|
5700
4017
|
pubkey: superstruct.string(),
|
|
@@ -5746,7 +4063,8 @@ const GetTransactionRpcResult = jsonRpcResult(superstruct.nullable(superstruct.t
|
|
|
5746
4063
|
slot: superstruct.number(),
|
|
5747
4064
|
meta: ConfirmedTransactionMetaResult,
|
|
5748
4065
|
blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
|
|
5749
|
-
transaction: ConfirmedTransactionResult
|
|
4066
|
+
transaction: ConfirmedTransactionResult,
|
|
4067
|
+
version: superstruct.optional(TransactionVersionStruct)
|
|
5750
4068
|
})));
|
|
5751
4069
|
/**
|
|
5752
4070
|
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
@@ -5756,7 +4074,8 @@ const GetParsedTransactionRpcResult = jsonRpcResult(superstruct.nullable(superst
|
|
|
5756
4074
|
slot: superstruct.number(),
|
|
5757
4075
|
transaction: ParsedConfirmedTransactionResult,
|
|
5758
4076
|
meta: superstruct.nullable(ParsedConfirmedTransactionMetaResult),
|
|
5759
|
-
blockTime: superstruct.optional(superstruct.nullable(superstruct.number()))
|
|
4077
|
+
blockTime: superstruct.optional(superstruct.nullable(superstruct.number())),
|
|
4078
|
+
version: superstruct.optional(TransactionVersionStruct)
|
|
5760
4079
|
})));
|
|
5761
4080
|
/**
|
|
5762
4081
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
@@ -6999,9 +5318,16 @@ class Connection {
|
|
|
6999
5318
|
}
|
|
7000
5319
|
/**
|
|
7001
5320
|
* Fetch a processed block from the cluster.
|
|
5321
|
+
*
|
|
5322
|
+
* @deprecated Instead, call `getBlock` using a `GetVersionedBlockConfig` by
|
|
5323
|
+
* setting the `maxSupportedTransactionVersion` property.
|
|
7002
5324
|
*/
|
|
7003
5325
|
|
|
7004
5326
|
|
|
5327
|
+
/**
|
|
5328
|
+
* Fetch a processed block from the cluster.
|
|
5329
|
+
*/
|
|
5330
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
7005
5331
|
async getBlock(slot, rawConfig) {
|
|
7006
5332
|
const {
|
|
7007
5333
|
commitment,
|
|
@@ -7024,16 +5350,15 @@ class Connection {
|
|
|
7024
5350
|
return { ...result,
|
|
7025
5351
|
transactions: result.transactions.map(({
|
|
7026
5352
|
transaction,
|
|
7027
|
-
meta
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
})
|
|
5353
|
+
meta,
|
|
5354
|
+
version
|
|
5355
|
+
}) => ({
|
|
5356
|
+
meta,
|
|
5357
|
+
transaction: { ...transaction,
|
|
5358
|
+
message: versionedMessageFromResponse(version, transaction.message)
|
|
5359
|
+
},
|
|
5360
|
+
version
|
|
5361
|
+
}))
|
|
7037
5362
|
};
|
|
7038
5363
|
}
|
|
7039
5364
|
/*
|
|
@@ -7093,9 +5418,17 @@ class Connection {
|
|
|
7093
5418
|
}
|
|
7094
5419
|
/**
|
|
7095
5420
|
* Fetch a confirmed or finalized transaction from the cluster.
|
|
5421
|
+
*
|
|
5422
|
+
* @deprecated Instead, call `getTransaction` using a
|
|
5423
|
+
* `GetVersionedTransactionConfig` by setting the
|
|
5424
|
+
* `maxSupportedTransactionVersion` property.
|
|
7096
5425
|
*/
|
|
7097
5426
|
|
|
7098
5427
|
|
|
5428
|
+
/**
|
|
5429
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
5430
|
+
*/
|
|
5431
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
7099
5432
|
async getTransaction(signature, rawConfig) {
|
|
7100
5433
|
const {
|
|
7101
5434
|
commitment,
|
|
@@ -7117,7 +5450,7 @@ class Connection {
|
|
|
7117
5450
|
if (!result) return result;
|
|
7118
5451
|
return { ...result,
|
|
7119
5452
|
transaction: { ...result.transaction,
|
|
7120
|
-
message:
|
|
5453
|
+
message: versionedMessageFromResponse(result.version, result.transaction.message)
|
|
7121
5454
|
}
|
|
7122
5455
|
};
|
|
7123
5456
|
}
|
|
@@ -7176,9 +5509,19 @@ class Connection {
|
|
|
7176
5509
|
/**
|
|
7177
5510
|
* Fetch transaction details for a batch of confirmed transactions.
|
|
7178
5511
|
* Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
|
|
5512
|
+
*
|
|
5513
|
+
* @deprecated Instead, call `getTransactions` using a
|
|
5514
|
+
* `GetVersionedTransactionConfig` by setting the
|
|
5515
|
+
* `maxSupportedTransactionVersion` property.
|
|
7179
5516
|
*/
|
|
7180
5517
|
|
|
7181
5518
|
|
|
5519
|
+
/**
|
|
5520
|
+
* Fetch transaction details for a batch of confirmed transactions.
|
|
5521
|
+
* Similar to {@link getParsedTransactions} but returns a {@link
|
|
5522
|
+
* VersionedTransactionResponse}.
|
|
5523
|
+
*/
|
|
5524
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
7182
5525
|
async getTransactions(signatures, commitmentOrConfig) {
|
|
7183
5526
|
const {
|
|
7184
5527
|
commitment,
|
|
@@ -7206,7 +5549,7 @@ class Connection {
|
|
|
7206
5549
|
if (!result) return result;
|
|
7207
5550
|
return { ...result,
|
|
7208
5551
|
transaction: { ...result.transaction,
|
|
7209
|
-
message:
|
|
5552
|
+
message: versionedMessageFromResponse(result.version, result.transaction.message)
|
|
7210
5553
|
}
|
|
7211
5554
|
};
|
|
7212
5555
|
});
|
|
@@ -8633,12 +6976,7 @@ class Keypair {
|
|
|
8633
6976
|
*/
|
|
8634
6977
|
constructor(keypair) {
|
|
8635
6978
|
this._keypair = void 0;
|
|
8636
|
-
|
|
8637
|
-
if (keypair) {
|
|
8638
|
-
this._keypair = keypair;
|
|
8639
|
-
} else {
|
|
8640
|
-
this._keypair = nacl__default["default"].sign.keyPair();
|
|
8641
|
-
}
|
|
6979
|
+
this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
|
|
8642
6980
|
}
|
|
8643
6981
|
/**
|
|
8644
6982
|
* Generate a new random keypair
|
|
@@ -8646,7 +6984,7 @@ class Keypair {
|
|
|
8646
6984
|
|
|
8647
6985
|
|
|
8648
6986
|
static generate() {
|
|
8649
|
-
return new Keypair(
|
|
6987
|
+
return new Keypair(generateKeypair());
|
|
8650
6988
|
}
|
|
8651
6989
|
/**
|
|
8652
6990
|
* Create a keypair from a raw secret key byte array.
|
|
@@ -8663,19 +7001,27 @@ class Keypair {
|
|
|
8663
7001
|
|
|
8664
7002
|
|
|
8665
7003
|
static fromSecretKey(secretKey, options) {
|
|
8666
|
-
|
|
7004
|
+
if (secretKey.byteLength !== 64) {
|
|
7005
|
+
throw new Error('bad secret key size');
|
|
7006
|
+
}
|
|
7007
|
+
|
|
7008
|
+
const publicKey = secretKey.slice(32, 64);
|
|
8667
7009
|
|
|
8668
7010
|
if (!options || !options.skipValidation) {
|
|
8669
|
-
const
|
|
8670
|
-
const
|
|
8671
|
-
const signature = nacl__default["default"].sign.detached(signData, keypair.secretKey);
|
|
7011
|
+
const privateScalar = secretKey.slice(0, 32);
|
|
7012
|
+
const computedPublicKey = getPublicKey(privateScalar);
|
|
8672
7013
|
|
|
8673
|
-
|
|
8674
|
-
|
|
7014
|
+
for (let ii = 0; ii < 32; ii++) {
|
|
7015
|
+
if (publicKey[ii] !== computedPublicKey[ii]) {
|
|
7016
|
+
throw new Error('provided secretKey is invalid');
|
|
7017
|
+
}
|
|
8675
7018
|
}
|
|
8676
7019
|
}
|
|
8677
7020
|
|
|
8678
|
-
return new Keypair(
|
|
7021
|
+
return new Keypair({
|
|
7022
|
+
publicKey,
|
|
7023
|
+
secretKey
|
|
7024
|
+
});
|
|
8679
7025
|
}
|
|
8680
7026
|
/**
|
|
8681
7027
|
* Generate a keypair from a 32 byte seed.
|
|
@@ -8685,7 +7031,14 @@ class Keypair {
|
|
|
8685
7031
|
|
|
8686
7032
|
|
|
8687
7033
|
static fromSeed(seed) {
|
|
8688
|
-
|
|
7034
|
+
const publicKey = getPublicKey(seed);
|
|
7035
|
+
const secretKey = new Uint8Array(64);
|
|
7036
|
+
secretKey.set(seed);
|
|
7037
|
+
secretKey.set(publicKey, 32);
|
|
7038
|
+
return new Keypair({
|
|
7039
|
+
publicKey,
|
|
7040
|
+
secretKey
|
|
7041
|
+
});
|
|
8689
7042
|
}
|
|
8690
7043
|
/**
|
|
8691
7044
|
* The public key for this keypair
|
|
@@ -9237,7 +7590,7 @@ class Ed25519Program {
|
|
|
9237
7590
|
try {
|
|
9238
7591
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
9239
7592
|
const publicKey = keypair.publicKey.toBytes();
|
|
9240
|
-
const signature =
|
|
7593
|
+
const signature = sign(message, keypair.secretKey);
|
|
9241
7594
|
return this.createInstructionWithPublicKey({
|
|
9242
7595
|
publicKey,
|
|
9243
7596
|
message,
|
|
@@ -9252,10 +7605,21 @@ class Ed25519Program {
|
|
|
9252
7605
|
}
|
|
9253
7606
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
9254
7607
|
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
7608
|
+
// library interoperable with the synchronous APIs in web3.js.
|
|
7609
|
+
|
|
7610
|
+
secp256k1__namespace.utils.hmacSha256Sync = (key, ...msgs) => {
|
|
7611
|
+
const h = hmac.hmac.create(sha256.sha256, key);
|
|
7612
|
+
msgs.forEach(msg => h.update(msg));
|
|
7613
|
+
return h.digest();
|
|
7614
|
+
};
|
|
7615
|
+
|
|
7616
|
+
const ecdsaSign = (msgHash, privKey) => secp256k1__namespace.signSync(msgHash, privKey, {
|
|
7617
|
+
der: false,
|
|
7618
|
+
recovered: true
|
|
7619
|
+
});
|
|
7620
|
+
secp256k1__namespace.utils.isValidPrivateKey;
|
|
7621
|
+
const publicKeyCreate = secp256k1__namespace.getPublicKey;
|
|
7622
|
+
|
|
9259
7623
|
const PRIVATE_KEY_BYTES = 32;
|
|
9260
7624
|
const ETHEREUM_ADDRESS_BYTES = 20;
|
|
9261
7625
|
const PUBLIC_KEY_BYTES = 64;
|
|
@@ -9379,13 +7743,12 @@ class Secp256k1Program {
|
|
|
9379
7743
|
|
|
9380
7744
|
try {
|
|
9381
7745
|
const privateKey = toBuffer(pkey);
|
|
9382
|
-
const publicKey = publicKeyCreate(privateKey, false
|
|
7746
|
+
const publicKey = publicKeyCreate(privateKey, false
|
|
7747
|
+
/* isCompressed */
|
|
7748
|
+
).slice(1); // throw away leading byte
|
|
9383
7749
|
|
|
9384
7750
|
const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
|
|
9385
|
-
const
|
|
9386
|
-
signature,
|
|
9387
|
-
recid: recoveryId
|
|
9388
|
-
} = ecdsaSign(messageHash, privateKey);
|
|
7751
|
+
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
9389
7752
|
return this.createInstructionWithPublicKey({
|
|
9390
7753
|
publicKey,
|
|
9391
7754
|
message,
|