@solana/web3.js 1.53.0 → 1.55.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 +459 -1825
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +455 -1826
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +462 -1847
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +114 -12
- package/lib/index.esm.js +458 -1848
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +19272 -25771
- 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 +459 -1824
- package/lib/index.native.js.map +1 -1
- package/package.json +5 -7
- package/src/account.ts +18 -9
- package/src/connection.ts +11 -9
- package/src/keypair.ts +19 -24
- package/src/layout.ts +7 -0
- package/src/message/index.ts +19 -6
- package/src/message/legacy.ts +58 -9
- package/src/message/v0.ts +324 -0
- package/src/message/versioned.ts +36 -0
- package/src/programs/ed25519.ts +2 -2
- package/src/programs/secp256k1.ts +6 -5
- package/src/programs/vote.ts +21 -0
- package/src/publickey.ts +14 -73
- package/src/transaction/constants.ts +2 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/legacy.ts +3 -5
- package/src/transaction/versioned.ts +105 -0
- package/src/utils/ed25519.ts +46 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/makeWebsocketUrl.ts +22 -16
- package/src/utils/secp256k1.ts +18 -0
- package/src/validator-info.ts +3 -5
- package/src/utils/__forks__/react-native/url-impl.ts +0 -2
- package/src/utils/url-impl.ts +0 -2
package/lib/index.browser.cjs.js
CHANGED
|
@@ -2,18 +2,21 @@
|
|
|
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');
|
|
12
14
|
var superstruct = require('superstruct');
|
|
13
15
|
var rpcWebsockets = require('rpc-websockets');
|
|
14
16
|
var RpcClient = require('jayson/lib/client/browser');
|
|
15
|
-
var secp256k1 = require('secp256k1');
|
|
16
17
|
var sha3 = require('js-sha3');
|
|
18
|
+
var hmac = require('@noble/hashes/hmac');
|
|
19
|
+
var secp256k1 = require('@noble/secp256k1');
|
|
17
20
|
|
|
18
21
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
22
|
|
|
@@ -35,1729 +38,58 @@ function _interopNamespace(e) {
|
|
|
35
38
|
return Object.freeze(n);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
var
|
|
41
|
+
var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
|
|
39
42
|
var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
|
|
40
43
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
41
44
|
var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
|
|
42
45
|
var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
43
|
-
var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
|
|
44
46
|
var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
|
|
47
|
+
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} else {
|
|
52
|
-
return buffer.Buffer.from(arr);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var hash$1 = {};
|
|
57
|
-
|
|
58
|
-
var utils$9 = {};
|
|
59
|
-
|
|
60
|
-
var minimalisticAssert = assert$6;
|
|
49
|
+
/**
|
|
50
|
+
* A 64 byte secret key, the first 32 bytes of which is the
|
|
51
|
+
* private scalar and the last 32 bytes is the public key.
|
|
52
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
53
|
+
*/
|
|
61
54
|
|
|
62
|
-
|
|
63
|
-
if (!val)
|
|
64
|
-
throw new Error(msg || 'Assertion failed');
|
|
65
|
-
}
|
|
55
|
+
ed25519__namespace.utils.sha512Sync = (...m) => sha512.sha512(ed25519__namespace.utils.concatBytes(...m));
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (superCtor) {
|
|
78
|
-
ctor.super_ = superCtor;
|
|
79
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
80
|
-
constructor: {
|
|
81
|
-
value: ctor,
|
|
82
|
-
enumerable: false,
|
|
83
|
-
writable: true,
|
|
84
|
-
configurable: true
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
} else {
|
|
90
|
-
// old school shim for old browsers
|
|
91
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
92
|
-
if (superCtor) {
|
|
93
|
-
ctor.super_ = superCtor;
|
|
94
|
-
var TempCtor = function () {};
|
|
95
|
-
TempCtor.prototype = superCtor.prototype;
|
|
96
|
-
ctor.prototype = new TempCtor();
|
|
97
|
-
ctor.prototype.constructor = ctor;
|
|
98
|
-
}
|
|
57
|
+
const generatePrivateKey = ed25519__namespace.utils.randomPrivateKey;
|
|
58
|
+
const generateKeypair = () => {
|
|
59
|
+
const privateScalar = ed25519__namespace.utils.randomPrivateKey();
|
|
60
|
+
const publicKey = getPublicKey(privateScalar);
|
|
61
|
+
const secretKey = new Uint8Array(64);
|
|
62
|
+
secretKey.set(privateScalar);
|
|
63
|
+
secretKey.set(publicKey, 32);
|
|
64
|
+
return {
|
|
65
|
+
publicKey,
|
|
66
|
+
secretKey
|
|
99
67
|
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (i < 0 || i + 1 >= msg.length) {
|
|
68
|
+
};
|
|
69
|
+
const getPublicKey = ed25519__namespace.sync.getPublicKey;
|
|
70
|
+
function isOnCurve(publicKey) {
|
|
71
|
+
try {
|
|
72
|
+
ed25519__namespace.Point.fromHex(publicKey, true
|
|
73
|
+
/* strict */
|
|
74
|
+
);
|
|
75
|
+
return true;
|
|
76
|
+
} catch {
|
|
112
77
|
return false;
|
|
113
78
|
}
|
|
114
|
-
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function toArray(msg, enc) {
|
|
118
|
-
if (Array.isArray(msg))
|
|
119
|
-
return msg.slice();
|
|
120
|
-
if (!msg)
|
|
121
|
-
return [];
|
|
122
|
-
var res = [];
|
|
123
|
-
if (typeof msg === 'string') {
|
|
124
|
-
if (!enc) {
|
|
125
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
126
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
127
|
-
// Apache License 2.0
|
|
128
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
129
|
-
var p = 0;
|
|
130
|
-
for (var i = 0; i < msg.length; i++) {
|
|
131
|
-
var c = msg.charCodeAt(i);
|
|
132
|
-
if (c < 128) {
|
|
133
|
-
res[p++] = c;
|
|
134
|
-
} else if (c < 2048) {
|
|
135
|
-
res[p++] = (c >> 6) | 192;
|
|
136
|
-
res[p++] = (c & 63) | 128;
|
|
137
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
138
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
139
|
-
res[p++] = (c >> 18) | 240;
|
|
140
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
141
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
142
|
-
res[p++] = (c & 63) | 128;
|
|
143
|
-
} else {
|
|
144
|
-
res[p++] = (c >> 12) | 224;
|
|
145
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
146
|
-
res[p++] = (c & 63) | 128;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else if (enc === 'hex') {
|
|
150
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
151
|
-
if (msg.length % 2 !== 0)
|
|
152
|
-
msg = '0' + msg;
|
|
153
|
-
for (i = 0; i < msg.length; i += 2)
|
|
154
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
for (i = 0; i < msg.length; i++)
|
|
158
|
-
res[i] = msg[i] | 0;
|
|
159
|
-
}
|
|
160
|
-
return res;
|
|
161
|
-
}
|
|
162
|
-
utils$9.toArray = toArray;
|
|
163
|
-
|
|
164
|
-
function toHex(msg) {
|
|
165
|
-
var res = '';
|
|
166
|
-
for (var i = 0; i < msg.length; i++)
|
|
167
|
-
res += zero2(msg[i].toString(16));
|
|
168
|
-
return res;
|
|
169
|
-
}
|
|
170
|
-
utils$9.toHex = toHex;
|
|
171
|
-
|
|
172
|
-
function htonl(w) {
|
|
173
|
-
var res = (w >>> 24) |
|
|
174
|
-
((w >>> 8) & 0xff00) |
|
|
175
|
-
((w << 8) & 0xff0000) |
|
|
176
|
-
((w & 0xff) << 24);
|
|
177
|
-
return res >>> 0;
|
|
178
|
-
}
|
|
179
|
-
utils$9.htonl = htonl;
|
|
180
|
-
|
|
181
|
-
function toHex32(msg, endian) {
|
|
182
|
-
var res = '';
|
|
183
|
-
for (var i = 0; i < msg.length; i++) {
|
|
184
|
-
var w = msg[i];
|
|
185
|
-
if (endian === 'little')
|
|
186
|
-
w = htonl(w);
|
|
187
|
-
res += zero8(w.toString(16));
|
|
188
|
-
}
|
|
189
|
-
return res;
|
|
190
|
-
}
|
|
191
|
-
utils$9.toHex32 = toHex32;
|
|
192
|
-
|
|
193
|
-
function zero2(word) {
|
|
194
|
-
if (word.length === 1)
|
|
195
|
-
return '0' + word;
|
|
196
|
-
else
|
|
197
|
-
return word;
|
|
198
|
-
}
|
|
199
|
-
utils$9.zero2 = zero2;
|
|
200
|
-
|
|
201
|
-
function zero8(word) {
|
|
202
|
-
if (word.length === 7)
|
|
203
|
-
return '0' + word;
|
|
204
|
-
else if (word.length === 6)
|
|
205
|
-
return '00' + word;
|
|
206
|
-
else if (word.length === 5)
|
|
207
|
-
return '000' + word;
|
|
208
|
-
else if (word.length === 4)
|
|
209
|
-
return '0000' + word;
|
|
210
|
-
else if (word.length === 3)
|
|
211
|
-
return '00000' + word;
|
|
212
|
-
else if (word.length === 2)
|
|
213
|
-
return '000000' + word;
|
|
214
|
-
else if (word.length === 1)
|
|
215
|
-
return '0000000' + word;
|
|
216
|
-
else
|
|
217
|
-
return word;
|
|
218
|
-
}
|
|
219
|
-
utils$9.zero8 = zero8;
|
|
220
|
-
|
|
221
|
-
function join32(msg, start, end, endian) {
|
|
222
|
-
var len = end - start;
|
|
223
|
-
assert$5(len % 4 === 0);
|
|
224
|
-
var res = new Array(len / 4);
|
|
225
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
226
|
-
var w;
|
|
227
|
-
if (endian === 'big')
|
|
228
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
229
|
-
else
|
|
230
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
231
|
-
res[i] = w >>> 0;
|
|
232
|
-
}
|
|
233
|
-
return res;
|
|
234
|
-
}
|
|
235
|
-
utils$9.join32 = join32;
|
|
236
|
-
|
|
237
|
-
function split32(msg, endian) {
|
|
238
|
-
var res = new Array(msg.length * 4);
|
|
239
|
-
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
240
|
-
var m = msg[i];
|
|
241
|
-
if (endian === 'big') {
|
|
242
|
-
res[k] = m >>> 24;
|
|
243
|
-
res[k + 1] = (m >>> 16) & 0xff;
|
|
244
|
-
res[k + 2] = (m >>> 8) & 0xff;
|
|
245
|
-
res[k + 3] = m & 0xff;
|
|
246
|
-
} else {
|
|
247
|
-
res[k + 3] = m >>> 24;
|
|
248
|
-
res[k + 2] = (m >>> 16) & 0xff;
|
|
249
|
-
res[k + 1] = (m >>> 8) & 0xff;
|
|
250
|
-
res[k] = m & 0xff;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return res;
|
|
254
|
-
}
|
|
255
|
-
utils$9.split32 = split32;
|
|
256
|
-
|
|
257
|
-
function rotr32$1(w, b) {
|
|
258
|
-
return (w >>> b) | (w << (32 - b));
|
|
259
|
-
}
|
|
260
|
-
utils$9.rotr32 = rotr32$1;
|
|
261
|
-
|
|
262
|
-
function rotl32$2(w, b) {
|
|
263
|
-
return (w << b) | (w >>> (32 - b));
|
|
264
|
-
}
|
|
265
|
-
utils$9.rotl32 = rotl32$2;
|
|
266
|
-
|
|
267
|
-
function sum32$3(a, b) {
|
|
268
|
-
return (a + b) >>> 0;
|
|
269
79
|
}
|
|
270
|
-
|
|
80
|
+
const sign = (message, secretKey) => ed25519__namespace.sync.sign(message, secretKey.slice(0, 32));
|
|
81
|
+
const verify = ed25519__namespace.sync.verify;
|
|
271
82
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
function sum32_4$2(a, b, c, d) {
|
|
278
|
-
return (a + b + c + d) >>> 0;
|
|
279
|
-
}
|
|
280
|
-
utils$9.sum32_4 = sum32_4$2;
|
|
281
|
-
|
|
282
|
-
function sum32_5$2(a, b, c, d, e) {
|
|
283
|
-
return (a + b + c + d + e) >>> 0;
|
|
284
|
-
}
|
|
285
|
-
utils$9.sum32_5 = sum32_5$2;
|
|
286
|
-
|
|
287
|
-
function sum64$1(buf, pos, ah, al) {
|
|
288
|
-
var bh = buf[pos];
|
|
289
|
-
var bl = buf[pos + 1];
|
|
290
|
-
|
|
291
|
-
var lo = (al + bl) >>> 0;
|
|
292
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
293
|
-
buf[pos] = hi >>> 0;
|
|
294
|
-
buf[pos + 1] = lo;
|
|
295
|
-
}
|
|
296
|
-
utils$9.sum64 = sum64$1;
|
|
297
|
-
|
|
298
|
-
function sum64_hi$1(ah, al, bh, bl) {
|
|
299
|
-
var lo = (al + bl) >>> 0;
|
|
300
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
301
|
-
return hi >>> 0;
|
|
302
|
-
}
|
|
303
|
-
utils$9.sum64_hi = sum64_hi$1;
|
|
304
|
-
|
|
305
|
-
function sum64_lo$1(ah, al, bh, bl) {
|
|
306
|
-
var lo = al + bl;
|
|
307
|
-
return lo >>> 0;
|
|
308
|
-
}
|
|
309
|
-
utils$9.sum64_lo = sum64_lo$1;
|
|
310
|
-
|
|
311
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
312
|
-
var carry = 0;
|
|
313
|
-
var lo = al;
|
|
314
|
-
lo = (lo + bl) >>> 0;
|
|
315
|
-
carry += lo < al ? 1 : 0;
|
|
316
|
-
lo = (lo + cl) >>> 0;
|
|
317
|
-
carry += lo < cl ? 1 : 0;
|
|
318
|
-
lo = (lo + dl) >>> 0;
|
|
319
|
-
carry += lo < dl ? 1 : 0;
|
|
320
|
-
|
|
321
|
-
var hi = ah + bh + ch + dh + carry;
|
|
322
|
-
return hi >>> 0;
|
|
323
|
-
}
|
|
324
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
325
|
-
|
|
326
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
327
|
-
var lo = al + bl + cl + dl;
|
|
328
|
-
return lo >>> 0;
|
|
329
|
-
}
|
|
330
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
331
|
-
|
|
332
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
333
|
-
var carry = 0;
|
|
334
|
-
var lo = al;
|
|
335
|
-
lo = (lo + bl) >>> 0;
|
|
336
|
-
carry += lo < al ? 1 : 0;
|
|
337
|
-
lo = (lo + cl) >>> 0;
|
|
338
|
-
carry += lo < cl ? 1 : 0;
|
|
339
|
-
lo = (lo + dl) >>> 0;
|
|
340
|
-
carry += lo < dl ? 1 : 0;
|
|
341
|
-
lo = (lo + el) >>> 0;
|
|
342
|
-
carry += lo < el ? 1 : 0;
|
|
343
|
-
|
|
344
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
345
|
-
return hi >>> 0;
|
|
346
|
-
}
|
|
347
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
348
|
-
|
|
349
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
350
|
-
var lo = al + bl + cl + dl + el;
|
|
351
|
-
|
|
352
|
-
return lo >>> 0;
|
|
353
|
-
}
|
|
354
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
355
|
-
|
|
356
|
-
function rotr64_hi$1(ah, al, num) {
|
|
357
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
358
|
-
return r >>> 0;
|
|
359
|
-
}
|
|
360
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
361
|
-
|
|
362
|
-
function rotr64_lo$1(ah, al, num) {
|
|
363
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
364
|
-
return r >>> 0;
|
|
365
|
-
}
|
|
366
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
367
|
-
|
|
368
|
-
function shr64_hi$1(ah, al, num) {
|
|
369
|
-
return ah >>> num;
|
|
370
|
-
}
|
|
371
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
372
|
-
|
|
373
|
-
function shr64_lo$1(ah, al, num) {
|
|
374
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
375
|
-
return r >>> 0;
|
|
376
|
-
}
|
|
377
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
378
|
-
|
|
379
|
-
var common$5 = {};
|
|
380
|
-
|
|
381
|
-
var utils$8 = utils$9;
|
|
382
|
-
var assert$4 = minimalisticAssert;
|
|
383
|
-
|
|
384
|
-
function BlockHash$4() {
|
|
385
|
-
this.pending = null;
|
|
386
|
-
this.pendingTotal = 0;
|
|
387
|
-
this.blockSize = this.constructor.blockSize;
|
|
388
|
-
this.outSize = this.constructor.outSize;
|
|
389
|
-
this.hmacStrength = this.constructor.hmacStrength;
|
|
390
|
-
this.padLength = this.constructor.padLength / 8;
|
|
391
|
-
this.endian = 'big';
|
|
392
|
-
|
|
393
|
-
this._delta8 = this.blockSize / 8;
|
|
394
|
-
this._delta32 = this.blockSize / 32;
|
|
395
|
-
}
|
|
396
|
-
common$5.BlockHash = BlockHash$4;
|
|
397
|
-
|
|
398
|
-
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
399
|
-
// Convert message to array, pad it, and join into 32bit blocks
|
|
400
|
-
msg = utils$8.toArray(msg, enc);
|
|
401
|
-
if (!this.pending)
|
|
402
|
-
this.pending = msg;
|
|
403
|
-
else
|
|
404
|
-
this.pending = this.pending.concat(msg);
|
|
405
|
-
this.pendingTotal += msg.length;
|
|
406
|
-
|
|
407
|
-
// Enough data, try updating
|
|
408
|
-
if (this.pending.length >= this._delta8) {
|
|
409
|
-
msg = this.pending;
|
|
410
|
-
|
|
411
|
-
// Process pending data in blocks
|
|
412
|
-
var r = msg.length % this._delta8;
|
|
413
|
-
this.pending = msg.slice(msg.length - r, msg.length);
|
|
414
|
-
if (this.pending.length === 0)
|
|
415
|
-
this.pending = null;
|
|
416
|
-
|
|
417
|
-
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
418
|
-
for (var i = 0; i < msg.length; i += this._delta32)
|
|
419
|
-
this._update(msg, i, i + this._delta32);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
return this;
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
BlockHash$4.prototype.digest = function digest(enc) {
|
|
426
|
-
this.update(this._pad());
|
|
427
|
-
assert$4(this.pending === null);
|
|
428
|
-
|
|
429
|
-
return this._digest(enc);
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
BlockHash$4.prototype._pad = function pad() {
|
|
433
|
-
var len = this.pendingTotal;
|
|
434
|
-
var bytes = this._delta8;
|
|
435
|
-
var k = bytes - ((len + this.padLength) % bytes);
|
|
436
|
-
var res = new Array(k + this.padLength);
|
|
437
|
-
res[0] = 0x80;
|
|
438
|
-
for (var i = 1; i < k; i++)
|
|
439
|
-
res[i] = 0;
|
|
440
|
-
|
|
441
|
-
// Append length
|
|
442
|
-
len <<= 3;
|
|
443
|
-
if (this.endian === 'big') {
|
|
444
|
-
for (var t = 8; t < this.padLength; t++)
|
|
445
|
-
res[i++] = 0;
|
|
446
|
-
|
|
447
|
-
res[i++] = 0;
|
|
448
|
-
res[i++] = 0;
|
|
449
|
-
res[i++] = 0;
|
|
450
|
-
res[i++] = 0;
|
|
451
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
452
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
453
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
454
|
-
res[i++] = len & 0xff;
|
|
83
|
+
const toBuffer = arr => {
|
|
84
|
+
if (buffer.Buffer.isBuffer(arr)) {
|
|
85
|
+
return arr;
|
|
86
|
+
} else if (arr instanceof Uint8Array) {
|
|
87
|
+
return buffer.Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
455
88
|
} else {
|
|
456
|
-
|
|
457
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
458
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
459
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
460
|
-
res[i++] = 0;
|
|
461
|
-
res[i++] = 0;
|
|
462
|
-
res[i++] = 0;
|
|
463
|
-
res[i++] = 0;
|
|
464
|
-
|
|
465
|
-
for (t = 8; t < this.padLength; t++)
|
|
466
|
-
res[i++] = 0;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return res;
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
var sha = {};
|
|
473
|
-
|
|
474
|
-
var common$4 = {};
|
|
475
|
-
|
|
476
|
-
var utils$7 = utils$9;
|
|
477
|
-
var rotr32 = utils$7.rotr32;
|
|
478
|
-
|
|
479
|
-
function ft_1$1(s, x, y, z) {
|
|
480
|
-
if (s === 0)
|
|
481
|
-
return ch32$1(x, y, z);
|
|
482
|
-
if (s === 1 || s === 3)
|
|
483
|
-
return p32(x, y, z);
|
|
484
|
-
if (s === 2)
|
|
485
|
-
return maj32$1(x, y, z);
|
|
486
|
-
}
|
|
487
|
-
common$4.ft_1 = ft_1$1;
|
|
488
|
-
|
|
489
|
-
function ch32$1(x, y, z) {
|
|
490
|
-
return (x & y) ^ ((~x) & z);
|
|
491
|
-
}
|
|
492
|
-
common$4.ch32 = ch32$1;
|
|
493
|
-
|
|
494
|
-
function maj32$1(x, y, z) {
|
|
495
|
-
return (x & y) ^ (x & z) ^ (y & z);
|
|
496
|
-
}
|
|
497
|
-
common$4.maj32 = maj32$1;
|
|
498
|
-
|
|
499
|
-
function p32(x, y, z) {
|
|
500
|
-
return x ^ y ^ z;
|
|
501
|
-
}
|
|
502
|
-
common$4.p32 = p32;
|
|
503
|
-
|
|
504
|
-
function s0_256$1(x) {
|
|
505
|
-
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
506
|
-
}
|
|
507
|
-
common$4.s0_256 = s0_256$1;
|
|
508
|
-
|
|
509
|
-
function s1_256$1(x) {
|
|
510
|
-
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
511
|
-
}
|
|
512
|
-
common$4.s1_256 = s1_256$1;
|
|
513
|
-
|
|
514
|
-
function g0_256$1(x) {
|
|
515
|
-
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
516
|
-
}
|
|
517
|
-
common$4.g0_256 = g0_256$1;
|
|
518
|
-
|
|
519
|
-
function g1_256$1(x) {
|
|
520
|
-
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
521
|
-
}
|
|
522
|
-
common$4.g1_256 = g1_256$1;
|
|
523
|
-
|
|
524
|
-
var utils$6 = utils$9;
|
|
525
|
-
var common$3 = common$5;
|
|
526
|
-
var shaCommon$1 = common$4;
|
|
527
|
-
|
|
528
|
-
var rotl32$1 = utils$6.rotl32;
|
|
529
|
-
var sum32$2 = utils$6.sum32;
|
|
530
|
-
var sum32_5$1 = utils$6.sum32_5;
|
|
531
|
-
var ft_1 = shaCommon$1.ft_1;
|
|
532
|
-
var BlockHash$3 = common$3.BlockHash;
|
|
533
|
-
|
|
534
|
-
var sha1_K = [
|
|
535
|
-
0x5A827999, 0x6ED9EBA1,
|
|
536
|
-
0x8F1BBCDC, 0xCA62C1D6
|
|
537
|
-
];
|
|
538
|
-
|
|
539
|
-
function SHA1() {
|
|
540
|
-
if (!(this instanceof SHA1))
|
|
541
|
-
return new SHA1();
|
|
542
|
-
|
|
543
|
-
BlockHash$3.call(this);
|
|
544
|
-
this.h = [
|
|
545
|
-
0x67452301, 0xefcdab89, 0x98badcfe,
|
|
546
|
-
0x10325476, 0xc3d2e1f0 ];
|
|
547
|
-
this.W = new Array(80);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
utils$6.inherits(SHA1, BlockHash$3);
|
|
551
|
-
var _1 = SHA1;
|
|
552
|
-
|
|
553
|
-
SHA1.blockSize = 512;
|
|
554
|
-
SHA1.outSize = 160;
|
|
555
|
-
SHA1.hmacStrength = 80;
|
|
556
|
-
SHA1.padLength = 64;
|
|
557
|
-
|
|
558
|
-
SHA1.prototype._update = function _update(msg, start) {
|
|
559
|
-
var W = this.W;
|
|
560
|
-
|
|
561
|
-
for (var i = 0; i < 16; i++)
|
|
562
|
-
W[i] = msg[start + i];
|
|
563
|
-
|
|
564
|
-
for(; i < W.length; i++)
|
|
565
|
-
W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
|
|
566
|
-
|
|
567
|
-
var a = this.h[0];
|
|
568
|
-
var b = this.h[1];
|
|
569
|
-
var c = this.h[2];
|
|
570
|
-
var d = this.h[3];
|
|
571
|
-
var e = this.h[4];
|
|
572
|
-
|
|
573
|
-
for (i = 0; i < W.length; i++) {
|
|
574
|
-
var s = ~~(i / 20);
|
|
575
|
-
var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
|
|
576
|
-
e = d;
|
|
577
|
-
d = c;
|
|
578
|
-
c = rotl32$1(b, 30);
|
|
579
|
-
b = a;
|
|
580
|
-
a = t;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
this.h[0] = sum32$2(this.h[0], a);
|
|
584
|
-
this.h[1] = sum32$2(this.h[1], b);
|
|
585
|
-
this.h[2] = sum32$2(this.h[2], c);
|
|
586
|
-
this.h[3] = sum32$2(this.h[3], d);
|
|
587
|
-
this.h[4] = sum32$2(this.h[4], e);
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
SHA1.prototype._digest = function digest(enc) {
|
|
591
|
-
if (enc === 'hex')
|
|
592
|
-
return utils$6.toHex32(this.h, 'big');
|
|
593
|
-
else
|
|
594
|
-
return utils$6.split32(this.h, 'big');
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
var utils$5 = utils$9;
|
|
598
|
-
var common$2 = common$5;
|
|
599
|
-
var shaCommon = common$4;
|
|
600
|
-
var assert$3 = minimalisticAssert;
|
|
601
|
-
|
|
602
|
-
var sum32$1 = utils$5.sum32;
|
|
603
|
-
var sum32_4$1 = utils$5.sum32_4;
|
|
604
|
-
var sum32_5 = utils$5.sum32_5;
|
|
605
|
-
var ch32 = shaCommon.ch32;
|
|
606
|
-
var maj32 = shaCommon.maj32;
|
|
607
|
-
var s0_256 = shaCommon.s0_256;
|
|
608
|
-
var s1_256 = shaCommon.s1_256;
|
|
609
|
-
var g0_256 = shaCommon.g0_256;
|
|
610
|
-
var g1_256 = shaCommon.g1_256;
|
|
611
|
-
|
|
612
|
-
var BlockHash$2 = common$2.BlockHash;
|
|
613
|
-
|
|
614
|
-
var sha256_K = [
|
|
615
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
616
|
-
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
617
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
618
|
-
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
619
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
620
|
-
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
621
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
622
|
-
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
623
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
624
|
-
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
625
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
626
|
-
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
627
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
628
|
-
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
629
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
630
|
-
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
631
|
-
];
|
|
632
|
-
|
|
633
|
-
function SHA256$1() {
|
|
634
|
-
if (!(this instanceof SHA256$1))
|
|
635
|
-
return new SHA256$1();
|
|
636
|
-
|
|
637
|
-
BlockHash$2.call(this);
|
|
638
|
-
this.h = [
|
|
639
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
640
|
-
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
641
|
-
];
|
|
642
|
-
this.k = sha256_K;
|
|
643
|
-
this.W = new Array(64);
|
|
644
|
-
}
|
|
645
|
-
utils$5.inherits(SHA256$1, BlockHash$2);
|
|
646
|
-
var _256 = SHA256$1;
|
|
647
|
-
|
|
648
|
-
SHA256$1.blockSize = 512;
|
|
649
|
-
SHA256$1.outSize = 256;
|
|
650
|
-
SHA256$1.hmacStrength = 192;
|
|
651
|
-
SHA256$1.padLength = 64;
|
|
652
|
-
|
|
653
|
-
SHA256$1.prototype._update = function _update(msg, start) {
|
|
654
|
-
var W = this.W;
|
|
655
|
-
|
|
656
|
-
for (var i = 0; i < 16; i++)
|
|
657
|
-
W[i] = msg[start + i];
|
|
658
|
-
for (; i < W.length; i++)
|
|
659
|
-
W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
|
|
660
|
-
|
|
661
|
-
var a = this.h[0];
|
|
662
|
-
var b = this.h[1];
|
|
663
|
-
var c = this.h[2];
|
|
664
|
-
var d = this.h[3];
|
|
665
|
-
var e = this.h[4];
|
|
666
|
-
var f = this.h[5];
|
|
667
|
-
var g = this.h[6];
|
|
668
|
-
var h = this.h[7];
|
|
669
|
-
|
|
670
|
-
assert$3(this.k.length === W.length);
|
|
671
|
-
for (i = 0; i < W.length; i++) {
|
|
672
|
-
var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
|
673
|
-
var T2 = sum32$1(s0_256(a), maj32(a, b, c));
|
|
674
|
-
h = g;
|
|
675
|
-
g = f;
|
|
676
|
-
f = e;
|
|
677
|
-
e = sum32$1(d, T1);
|
|
678
|
-
d = c;
|
|
679
|
-
c = b;
|
|
680
|
-
b = a;
|
|
681
|
-
a = sum32$1(T1, T2);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
this.h[0] = sum32$1(this.h[0], a);
|
|
685
|
-
this.h[1] = sum32$1(this.h[1], b);
|
|
686
|
-
this.h[2] = sum32$1(this.h[2], c);
|
|
687
|
-
this.h[3] = sum32$1(this.h[3], d);
|
|
688
|
-
this.h[4] = sum32$1(this.h[4], e);
|
|
689
|
-
this.h[5] = sum32$1(this.h[5], f);
|
|
690
|
-
this.h[6] = sum32$1(this.h[6], g);
|
|
691
|
-
this.h[7] = sum32$1(this.h[7], h);
|
|
692
|
-
};
|
|
693
|
-
|
|
694
|
-
SHA256$1.prototype._digest = function digest(enc) {
|
|
695
|
-
if (enc === 'hex')
|
|
696
|
-
return utils$5.toHex32(this.h, 'big');
|
|
697
|
-
else
|
|
698
|
-
return utils$5.split32(this.h, 'big');
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
var utils$4 = utils$9;
|
|
702
|
-
var SHA256 = _256;
|
|
703
|
-
|
|
704
|
-
function SHA224() {
|
|
705
|
-
if (!(this instanceof SHA224))
|
|
706
|
-
return new SHA224();
|
|
707
|
-
|
|
708
|
-
SHA256.call(this);
|
|
709
|
-
this.h = [
|
|
710
|
-
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
|
711
|
-
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
|
|
712
|
-
}
|
|
713
|
-
utils$4.inherits(SHA224, SHA256);
|
|
714
|
-
var _224 = SHA224;
|
|
715
|
-
|
|
716
|
-
SHA224.blockSize = 512;
|
|
717
|
-
SHA224.outSize = 224;
|
|
718
|
-
SHA224.hmacStrength = 192;
|
|
719
|
-
SHA224.padLength = 64;
|
|
720
|
-
|
|
721
|
-
SHA224.prototype._digest = function digest(enc) {
|
|
722
|
-
// Just truncate output
|
|
723
|
-
if (enc === 'hex')
|
|
724
|
-
return utils$4.toHex32(this.h.slice(0, 7), 'big');
|
|
725
|
-
else
|
|
726
|
-
return utils$4.split32(this.h.slice(0, 7), 'big');
|
|
727
|
-
};
|
|
728
|
-
|
|
729
|
-
var utils$3 = utils$9;
|
|
730
|
-
var common$1 = common$5;
|
|
731
|
-
var assert$2 = minimalisticAssert;
|
|
732
|
-
|
|
733
|
-
var rotr64_hi = utils$3.rotr64_hi;
|
|
734
|
-
var rotr64_lo = utils$3.rotr64_lo;
|
|
735
|
-
var shr64_hi = utils$3.shr64_hi;
|
|
736
|
-
var shr64_lo = utils$3.shr64_lo;
|
|
737
|
-
var sum64 = utils$3.sum64;
|
|
738
|
-
var sum64_hi = utils$3.sum64_hi;
|
|
739
|
-
var sum64_lo = utils$3.sum64_lo;
|
|
740
|
-
var sum64_4_hi = utils$3.sum64_4_hi;
|
|
741
|
-
var sum64_4_lo = utils$3.sum64_4_lo;
|
|
742
|
-
var sum64_5_hi = utils$3.sum64_5_hi;
|
|
743
|
-
var sum64_5_lo = utils$3.sum64_5_lo;
|
|
744
|
-
|
|
745
|
-
var BlockHash$1 = common$1.BlockHash;
|
|
746
|
-
|
|
747
|
-
var sha512_K = [
|
|
748
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
749
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
750
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
751
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
752
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
753
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
754
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
755
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
756
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
757
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
758
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
759
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
760
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
761
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
762
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
763
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
764
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
765
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
766
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
767
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
768
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
769
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
770
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
771
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
772
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
773
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
774
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
775
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
776
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
777
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
778
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
779
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
780
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
781
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
782
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
783
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
784
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
785
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
786
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
787
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
788
|
-
];
|
|
789
|
-
|
|
790
|
-
function SHA512$1() {
|
|
791
|
-
if (!(this instanceof SHA512$1))
|
|
792
|
-
return new SHA512$1();
|
|
793
|
-
|
|
794
|
-
BlockHash$1.call(this);
|
|
795
|
-
this.h = [
|
|
796
|
-
0x6a09e667, 0xf3bcc908,
|
|
797
|
-
0xbb67ae85, 0x84caa73b,
|
|
798
|
-
0x3c6ef372, 0xfe94f82b,
|
|
799
|
-
0xa54ff53a, 0x5f1d36f1,
|
|
800
|
-
0x510e527f, 0xade682d1,
|
|
801
|
-
0x9b05688c, 0x2b3e6c1f,
|
|
802
|
-
0x1f83d9ab, 0xfb41bd6b,
|
|
803
|
-
0x5be0cd19, 0x137e2179 ];
|
|
804
|
-
this.k = sha512_K;
|
|
805
|
-
this.W = new Array(160);
|
|
806
|
-
}
|
|
807
|
-
utils$3.inherits(SHA512$1, BlockHash$1);
|
|
808
|
-
var _512 = SHA512$1;
|
|
809
|
-
|
|
810
|
-
SHA512$1.blockSize = 1024;
|
|
811
|
-
SHA512$1.outSize = 512;
|
|
812
|
-
SHA512$1.hmacStrength = 192;
|
|
813
|
-
SHA512$1.padLength = 128;
|
|
814
|
-
|
|
815
|
-
SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
|
|
816
|
-
var W = this.W;
|
|
817
|
-
|
|
818
|
-
// 32 x 32bit words
|
|
819
|
-
for (var i = 0; i < 32; i++)
|
|
820
|
-
W[i] = msg[start + i];
|
|
821
|
-
for (; i < W.length; i += 2) {
|
|
822
|
-
var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
|
|
823
|
-
var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
|
|
824
|
-
var c1_hi = W[i - 14]; // i - 7
|
|
825
|
-
var c1_lo = W[i - 13];
|
|
826
|
-
var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
|
|
827
|
-
var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
|
|
828
|
-
var c3_hi = W[i - 32]; // i - 16
|
|
829
|
-
var c3_lo = W[i - 31];
|
|
830
|
-
|
|
831
|
-
W[i] = sum64_4_hi(
|
|
832
|
-
c0_hi, c0_lo,
|
|
833
|
-
c1_hi, c1_lo,
|
|
834
|
-
c2_hi, c2_lo,
|
|
835
|
-
c3_hi, c3_lo);
|
|
836
|
-
W[i + 1] = sum64_4_lo(
|
|
837
|
-
c0_hi, c0_lo,
|
|
838
|
-
c1_hi, c1_lo,
|
|
839
|
-
c2_hi, c2_lo,
|
|
840
|
-
c3_hi, c3_lo);
|
|
89
|
+
return buffer.Buffer.from(arr);
|
|
841
90
|
}
|
|
842
91
|
};
|
|
843
92
|
|
|
844
|
-
SHA512$1.prototype._update = function _update(msg, start) {
|
|
845
|
-
this._prepareBlock(msg, start);
|
|
846
|
-
|
|
847
|
-
var W = this.W;
|
|
848
|
-
|
|
849
|
-
var ah = this.h[0];
|
|
850
|
-
var al = this.h[1];
|
|
851
|
-
var bh = this.h[2];
|
|
852
|
-
var bl = this.h[3];
|
|
853
|
-
var ch = this.h[4];
|
|
854
|
-
var cl = this.h[5];
|
|
855
|
-
var dh = this.h[6];
|
|
856
|
-
var dl = this.h[7];
|
|
857
|
-
var eh = this.h[8];
|
|
858
|
-
var el = this.h[9];
|
|
859
|
-
var fh = this.h[10];
|
|
860
|
-
var fl = this.h[11];
|
|
861
|
-
var gh = this.h[12];
|
|
862
|
-
var gl = this.h[13];
|
|
863
|
-
var hh = this.h[14];
|
|
864
|
-
var hl = this.h[15];
|
|
865
|
-
|
|
866
|
-
assert$2(this.k.length === W.length);
|
|
867
|
-
for (var i = 0; i < W.length; i += 2) {
|
|
868
|
-
var c0_hi = hh;
|
|
869
|
-
var c0_lo = hl;
|
|
870
|
-
var c1_hi = s1_512_hi(eh, el);
|
|
871
|
-
var c1_lo = s1_512_lo(eh, el);
|
|
872
|
-
var c2_hi = ch64_hi(eh, el, fh, fl, gh);
|
|
873
|
-
var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
|
|
874
|
-
var c3_hi = this.k[i];
|
|
875
|
-
var c3_lo = this.k[i + 1];
|
|
876
|
-
var c4_hi = W[i];
|
|
877
|
-
var c4_lo = W[i + 1];
|
|
878
|
-
|
|
879
|
-
var T1_hi = sum64_5_hi(
|
|
880
|
-
c0_hi, c0_lo,
|
|
881
|
-
c1_hi, c1_lo,
|
|
882
|
-
c2_hi, c2_lo,
|
|
883
|
-
c3_hi, c3_lo,
|
|
884
|
-
c4_hi, c4_lo);
|
|
885
|
-
var T1_lo = sum64_5_lo(
|
|
886
|
-
c0_hi, c0_lo,
|
|
887
|
-
c1_hi, c1_lo,
|
|
888
|
-
c2_hi, c2_lo,
|
|
889
|
-
c3_hi, c3_lo,
|
|
890
|
-
c4_hi, c4_lo);
|
|
891
|
-
|
|
892
|
-
c0_hi = s0_512_hi(ah, al);
|
|
893
|
-
c0_lo = s0_512_lo(ah, al);
|
|
894
|
-
c1_hi = maj64_hi(ah, al, bh, bl, ch);
|
|
895
|
-
c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
|
|
896
|
-
|
|
897
|
-
var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
898
|
-
var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
899
|
-
|
|
900
|
-
hh = gh;
|
|
901
|
-
hl = gl;
|
|
902
|
-
|
|
903
|
-
gh = fh;
|
|
904
|
-
gl = fl;
|
|
905
|
-
|
|
906
|
-
fh = eh;
|
|
907
|
-
fl = el;
|
|
908
|
-
|
|
909
|
-
eh = sum64_hi(dh, dl, T1_hi, T1_lo);
|
|
910
|
-
el = sum64_lo(dl, dl, T1_hi, T1_lo);
|
|
911
|
-
|
|
912
|
-
dh = ch;
|
|
913
|
-
dl = cl;
|
|
914
|
-
|
|
915
|
-
ch = bh;
|
|
916
|
-
cl = bl;
|
|
917
|
-
|
|
918
|
-
bh = ah;
|
|
919
|
-
bl = al;
|
|
920
|
-
|
|
921
|
-
ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
922
|
-
al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
sum64(this.h, 0, ah, al);
|
|
926
|
-
sum64(this.h, 2, bh, bl);
|
|
927
|
-
sum64(this.h, 4, ch, cl);
|
|
928
|
-
sum64(this.h, 6, dh, dl);
|
|
929
|
-
sum64(this.h, 8, eh, el);
|
|
930
|
-
sum64(this.h, 10, fh, fl);
|
|
931
|
-
sum64(this.h, 12, gh, gl);
|
|
932
|
-
sum64(this.h, 14, hh, hl);
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
SHA512$1.prototype._digest = function digest(enc) {
|
|
936
|
-
if (enc === 'hex')
|
|
937
|
-
return utils$3.toHex32(this.h, 'big');
|
|
938
|
-
else
|
|
939
|
-
return utils$3.split32(this.h, 'big');
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
function ch64_hi(xh, xl, yh, yl, zh) {
|
|
943
|
-
var r = (xh & yh) ^ ((~xh) & zh);
|
|
944
|
-
if (r < 0)
|
|
945
|
-
r += 0x100000000;
|
|
946
|
-
return r;
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
function ch64_lo(xh, xl, yh, yl, zh, zl) {
|
|
950
|
-
var r = (xl & yl) ^ ((~xl) & zl);
|
|
951
|
-
if (r < 0)
|
|
952
|
-
r += 0x100000000;
|
|
953
|
-
return r;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
function maj64_hi(xh, xl, yh, yl, zh) {
|
|
957
|
-
var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
|
|
958
|
-
if (r < 0)
|
|
959
|
-
r += 0x100000000;
|
|
960
|
-
return r;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
function maj64_lo(xh, xl, yh, yl, zh, zl) {
|
|
964
|
-
var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
|
|
965
|
-
if (r < 0)
|
|
966
|
-
r += 0x100000000;
|
|
967
|
-
return r;
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
function s0_512_hi(xh, xl) {
|
|
971
|
-
var c0_hi = rotr64_hi(xh, xl, 28);
|
|
972
|
-
var c1_hi = rotr64_hi(xl, xh, 2); // 34
|
|
973
|
-
var c2_hi = rotr64_hi(xl, xh, 7); // 39
|
|
974
|
-
|
|
975
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
976
|
-
if (r < 0)
|
|
977
|
-
r += 0x100000000;
|
|
978
|
-
return r;
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function s0_512_lo(xh, xl) {
|
|
982
|
-
var c0_lo = rotr64_lo(xh, xl, 28);
|
|
983
|
-
var c1_lo = rotr64_lo(xl, xh, 2); // 34
|
|
984
|
-
var c2_lo = rotr64_lo(xl, xh, 7); // 39
|
|
985
|
-
|
|
986
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
987
|
-
if (r < 0)
|
|
988
|
-
r += 0x100000000;
|
|
989
|
-
return r;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
function s1_512_hi(xh, xl) {
|
|
993
|
-
var c0_hi = rotr64_hi(xh, xl, 14);
|
|
994
|
-
var c1_hi = rotr64_hi(xh, xl, 18);
|
|
995
|
-
var c2_hi = rotr64_hi(xl, xh, 9); // 41
|
|
996
|
-
|
|
997
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
998
|
-
if (r < 0)
|
|
999
|
-
r += 0x100000000;
|
|
1000
|
-
return r;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
function s1_512_lo(xh, xl) {
|
|
1004
|
-
var c0_lo = rotr64_lo(xh, xl, 14);
|
|
1005
|
-
var c1_lo = rotr64_lo(xh, xl, 18);
|
|
1006
|
-
var c2_lo = rotr64_lo(xl, xh, 9); // 41
|
|
1007
|
-
|
|
1008
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1009
|
-
if (r < 0)
|
|
1010
|
-
r += 0x100000000;
|
|
1011
|
-
return r;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
function g0_512_hi(xh, xl) {
|
|
1015
|
-
var c0_hi = rotr64_hi(xh, xl, 1);
|
|
1016
|
-
var c1_hi = rotr64_hi(xh, xl, 8);
|
|
1017
|
-
var c2_hi = shr64_hi(xh, xl, 7);
|
|
1018
|
-
|
|
1019
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1020
|
-
if (r < 0)
|
|
1021
|
-
r += 0x100000000;
|
|
1022
|
-
return r;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
function g0_512_lo(xh, xl) {
|
|
1026
|
-
var c0_lo = rotr64_lo(xh, xl, 1);
|
|
1027
|
-
var c1_lo = rotr64_lo(xh, xl, 8);
|
|
1028
|
-
var c2_lo = shr64_lo(xh, xl, 7);
|
|
1029
|
-
|
|
1030
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1031
|
-
if (r < 0)
|
|
1032
|
-
r += 0x100000000;
|
|
1033
|
-
return r;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
function g1_512_hi(xh, xl) {
|
|
1037
|
-
var c0_hi = rotr64_hi(xh, xl, 19);
|
|
1038
|
-
var c1_hi = rotr64_hi(xl, xh, 29); // 61
|
|
1039
|
-
var c2_hi = shr64_hi(xh, xl, 6);
|
|
1040
|
-
|
|
1041
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1042
|
-
if (r < 0)
|
|
1043
|
-
r += 0x100000000;
|
|
1044
|
-
return r;
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
function g1_512_lo(xh, xl) {
|
|
1048
|
-
var c0_lo = rotr64_lo(xh, xl, 19);
|
|
1049
|
-
var c1_lo = rotr64_lo(xl, xh, 29); // 61
|
|
1050
|
-
var c2_lo = shr64_lo(xh, xl, 6);
|
|
1051
|
-
|
|
1052
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1053
|
-
if (r < 0)
|
|
1054
|
-
r += 0x100000000;
|
|
1055
|
-
return r;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
var utils$2 = utils$9;
|
|
1059
|
-
|
|
1060
|
-
var SHA512 = _512;
|
|
1061
|
-
|
|
1062
|
-
function SHA384() {
|
|
1063
|
-
if (!(this instanceof SHA384))
|
|
1064
|
-
return new SHA384();
|
|
1065
|
-
|
|
1066
|
-
SHA512.call(this);
|
|
1067
|
-
this.h = [
|
|
1068
|
-
0xcbbb9d5d, 0xc1059ed8,
|
|
1069
|
-
0x629a292a, 0x367cd507,
|
|
1070
|
-
0x9159015a, 0x3070dd17,
|
|
1071
|
-
0x152fecd8, 0xf70e5939,
|
|
1072
|
-
0x67332667, 0xffc00b31,
|
|
1073
|
-
0x8eb44a87, 0x68581511,
|
|
1074
|
-
0xdb0c2e0d, 0x64f98fa7,
|
|
1075
|
-
0x47b5481d, 0xbefa4fa4 ];
|
|
1076
|
-
}
|
|
1077
|
-
utils$2.inherits(SHA384, SHA512);
|
|
1078
|
-
var _384 = SHA384;
|
|
1079
|
-
|
|
1080
|
-
SHA384.blockSize = 1024;
|
|
1081
|
-
SHA384.outSize = 384;
|
|
1082
|
-
SHA384.hmacStrength = 192;
|
|
1083
|
-
SHA384.padLength = 128;
|
|
1084
|
-
|
|
1085
|
-
SHA384.prototype._digest = function digest(enc) {
|
|
1086
|
-
if (enc === 'hex')
|
|
1087
|
-
return utils$2.toHex32(this.h.slice(0, 12), 'big');
|
|
1088
|
-
else
|
|
1089
|
-
return utils$2.split32(this.h.slice(0, 12), 'big');
|
|
1090
|
-
};
|
|
1091
|
-
|
|
1092
|
-
sha.sha1 = _1;
|
|
1093
|
-
sha.sha224 = _224;
|
|
1094
|
-
sha.sha256 = _256;
|
|
1095
|
-
sha.sha384 = _384;
|
|
1096
|
-
sha.sha512 = _512;
|
|
1097
|
-
|
|
1098
|
-
var ripemd = {};
|
|
1099
|
-
|
|
1100
|
-
var utils$1 = utils$9;
|
|
1101
|
-
var common = common$5;
|
|
1102
|
-
|
|
1103
|
-
var rotl32 = utils$1.rotl32;
|
|
1104
|
-
var sum32 = utils$1.sum32;
|
|
1105
|
-
var sum32_3 = utils$1.sum32_3;
|
|
1106
|
-
var sum32_4 = utils$1.sum32_4;
|
|
1107
|
-
var BlockHash = common.BlockHash;
|
|
1108
|
-
|
|
1109
|
-
function RIPEMD160() {
|
|
1110
|
-
if (!(this instanceof RIPEMD160))
|
|
1111
|
-
return new RIPEMD160();
|
|
1112
|
-
|
|
1113
|
-
BlockHash.call(this);
|
|
1114
|
-
|
|
1115
|
-
this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
|
|
1116
|
-
this.endian = 'little';
|
|
1117
|
-
}
|
|
1118
|
-
utils$1.inherits(RIPEMD160, BlockHash);
|
|
1119
|
-
ripemd.ripemd160 = RIPEMD160;
|
|
1120
|
-
|
|
1121
|
-
RIPEMD160.blockSize = 512;
|
|
1122
|
-
RIPEMD160.outSize = 160;
|
|
1123
|
-
RIPEMD160.hmacStrength = 192;
|
|
1124
|
-
RIPEMD160.padLength = 64;
|
|
1125
|
-
|
|
1126
|
-
RIPEMD160.prototype._update = function update(msg, start) {
|
|
1127
|
-
var A = this.h[0];
|
|
1128
|
-
var B = this.h[1];
|
|
1129
|
-
var C = this.h[2];
|
|
1130
|
-
var D = this.h[3];
|
|
1131
|
-
var E = this.h[4];
|
|
1132
|
-
var Ah = A;
|
|
1133
|
-
var Bh = B;
|
|
1134
|
-
var Ch = C;
|
|
1135
|
-
var Dh = D;
|
|
1136
|
-
var Eh = E;
|
|
1137
|
-
for (var j = 0; j < 80; j++) {
|
|
1138
|
-
var T = sum32(
|
|
1139
|
-
rotl32(
|
|
1140
|
-
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
|
1141
|
-
s[j]),
|
|
1142
|
-
E);
|
|
1143
|
-
A = E;
|
|
1144
|
-
E = D;
|
|
1145
|
-
D = rotl32(C, 10);
|
|
1146
|
-
C = B;
|
|
1147
|
-
B = T;
|
|
1148
|
-
T = sum32(
|
|
1149
|
-
rotl32(
|
|
1150
|
-
sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
|
|
1151
|
-
sh[j]),
|
|
1152
|
-
Eh);
|
|
1153
|
-
Ah = Eh;
|
|
1154
|
-
Eh = Dh;
|
|
1155
|
-
Dh = rotl32(Ch, 10);
|
|
1156
|
-
Ch = Bh;
|
|
1157
|
-
Bh = T;
|
|
1158
|
-
}
|
|
1159
|
-
T = sum32_3(this.h[1], C, Dh);
|
|
1160
|
-
this.h[1] = sum32_3(this.h[2], D, Eh);
|
|
1161
|
-
this.h[2] = sum32_3(this.h[3], E, Ah);
|
|
1162
|
-
this.h[3] = sum32_3(this.h[4], A, Bh);
|
|
1163
|
-
this.h[4] = sum32_3(this.h[0], B, Ch);
|
|
1164
|
-
this.h[0] = T;
|
|
1165
|
-
};
|
|
1166
|
-
|
|
1167
|
-
RIPEMD160.prototype._digest = function digest(enc) {
|
|
1168
|
-
if (enc === 'hex')
|
|
1169
|
-
return utils$1.toHex32(this.h, 'little');
|
|
1170
|
-
else
|
|
1171
|
-
return utils$1.split32(this.h, 'little');
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
function f(j, x, y, z) {
|
|
1175
|
-
if (j <= 15)
|
|
1176
|
-
return x ^ y ^ z;
|
|
1177
|
-
else if (j <= 31)
|
|
1178
|
-
return (x & y) | ((~x) & z);
|
|
1179
|
-
else if (j <= 47)
|
|
1180
|
-
return (x | (~y)) ^ z;
|
|
1181
|
-
else if (j <= 63)
|
|
1182
|
-
return (x & z) | (y & (~z));
|
|
1183
|
-
else
|
|
1184
|
-
return x ^ (y | (~z));
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
function K(j) {
|
|
1188
|
-
if (j <= 15)
|
|
1189
|
-
return 0x00000000;
|
|
1190
|
-
else if (j <= 31)
|
|
1191
|
-
return 0x5a827999;
|
|
1192
|
-
else if (j <= 47)
|
|
1193
|
-
return 0x6ed9eba1;
|
|
1194
|
-
else if (j <= 63)
|
|
1195
|
-
return 0x8f1bbcdc;
|
|
1196
|
-
else
|
|
1197
|
-
return 0xa953fd4e;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
function Kh(j) {
|
|
1201
|
-
if (j <= 15)
|
|
1202
|
-
return 0x50a28be6;
|
|
1203
|
-
else if (j <= 31)
|
|
1204
|
-
return 0x5c4dd124;
|
|
1205
|
-
else if (j <= 47)
|
|
1206
|
-
return 0x6d703ef3;
|
|
1207
|
-
else if (j <= 63)
|
|
1208
|
-
return 0x7a6d76e9;
|
|
1209
|
-
else
|
|
1210
|
-
return 0x00000000;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
var r = [
|
|
1214
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
1215
|
-
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
1216
|
-
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
|
1217
|
-
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
|
1218
|
-
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
|
|
1219
|
-
];
|
|
1220
|
-
|
|
1221
|
-
var rh = [
|
|
1222
|
-
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
|
1223
|
-
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
|
1224
|
-
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
|
1225
|
-
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
|
1226
|
-
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
|
|
1227
|
-
];
|
|
1228
|
-
|
|
1229
|
-
var s = [
|
|
1230
|
-
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
|
1231
|
-
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
|
1232
|
-
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
|
1233
|
-
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
|
1234
|
-
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
|
|
1235
|
-
];
|
|
1236
|
-
|
|
1237
|
-
var sh = [
|
|
1238
|
-
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
|
1239
|
-
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
|
1240
|
-
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
|
1241
|
-
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
|
1242
|
-
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
|
|
1243
|
-
];
|
|
1244
|
-
|
|
1245
|
-
var utils = utils$9;
|
|
1246
|
-
var assert$1 = minimalisticAssert;
|
|
1247
|
-
|
|
1248
|
-
function Hmac(hash, key, enc) {
|
|
1249
|
-
if (!(this instanceof Hmac))
|
|
1250
|
-
return new Hmac(hash, key, enc);
|
|
1251
|
-
this.Hash = hash;
|
|
1252
|
-
this.blockSize = hash.blockSize / 8;
|
|
1253
|
-
this.outSize = hash.outSize / 8;
|
|
1254
|
-
this.inner = null;
|
|
1255
|
-
this.outer = null;
|
|
1256
|
-
|
|
1257
|
-
this._init(utils.toArray(key, enc));
|
|
1258
|
-
}
|
|
1259
|
-
var hmac = Hmac;
|
|
1260
|
-
|
|
1261
|
-
Hmac.prototype._init = function init(key) {
|
|
1262
|
-
// Shorten key, if needed
|
|
1263
|
-
if (key.length > this.blockSize)
|
|
1264
|
-
key = new this.Hash().update(key).digest();
|
|
1265
|
-
assert$1(key.length <= this.blockSize);
|
|
1266
|
-
|
|
1267
|
-
// Add padding to key
|
|
1268
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1269
|
-
key.push(0);
|
|
1270
|
-
|
|
1271
|
-
for (i = 0; i < key.length; i++)
|
|
1272
|
-
key[i] ^= 0x36;
|
|
1273
|
-
this.inner = new this.Hash().update(key);
|
|
1274
|
-
|
|
1275
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1276
|
-
for (i = 0; i < key.length; i++)
|
|
1277
|
-
key[i] ^= 0x6a;
|
|
1278
|
-
this.outer = new this.Hash().update(key);
|
|
1279
|
-
};
|
|
1280
|
-
|
|
1281
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1282
|
-
this.inner.update(msg, enc);
|
|
1283
|
-
return this;
|
|
1284
|
-
};
|
|
1285
|
-
|
|
1286
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1287
|
-
this.outer.update(this.inner.digest());
|
|
1288
|
-
return this.outer.digest(enc);
|
|
1289
|
-
};
|
|
1290
|
-
|
|
1291
|
-
(function (exports) {
|
|
1292
|
-
var hash = exports;
|
|
1293
|
-
|
|
1294
|
-
hash.utils = utils$9;
|
|
1295
|
-
hash.common = common$5;
|
|
1296
|
-
hash.sha = sha;
|
|
1297
|
-
hash.ripemd = ripemd;
|
|
1298
|
-
hash.hmac = hmac;
|
|
1299
|
-
|
|
1300
|
-
// Proxy hash functions to the main object
|
|
1301
|
-
hash.sha1 = hash.sha.sha1;
|
|
1302
|
-
hash.sha256 = hash.sha.sha256;
|
|
1303
|
-
hash.sha224 = hash.sha.sha224;
|
|
1304
|
-
hash.sha384 = hash.sha.sha384;
|
|
1305
|
-
hash.sha512 = hash.sha.sha512;
|
|
1306
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1307
|
-
} (hash$1));
|
|
1308
|
-
|
|
1309
|
-
var hash = hash$1;
|
|
1310
|
-
|
|
1311
|
-
const version$2 = "logger/5.6.0";
|
|
1312
|
-
|
|
1313
|
-
let _permanentCensorErrors = false;
|
|
1314
|
-
let _censorErrors = false;
|
|
1315
|
-
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1316
|
-
let _logLevel = LogLevels["default"];
|
|
1317
|
-
let _globalLogger = null;
|
|
1318
|
-
function _checkNormalize() {
|
|
1319
|
-
try {
|
|
1320
|
-
const missing = [];
|
|
1321
|
-
// Make sure all forms of normalization are supported
|
|
1322
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1323
|
-
try {
|
|
1324
|
-
if ("test".normalize(form) !== "test") {
|
|
1325
|
-
throw new Error("bad normalize");
|
|
1326
|
-
}
|
|
1327
|
-
;
|
|
1328
|
-
}
|
|
1329
|
-
catch (error) {
|
|
1330
|
-
missing.push(form);
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
if (missing.length) {
|
|
1334
|
-
throw new Error("missing " + missing.join(", "));
|
|
1335
|
-
}
|
|
1336
|
-
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1337
|
-
throw new Error("broken implementation");
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
catch (error) {
|
|
1341
|
-
return error.message;
|
|
1342
|
-
}
|
|
1343
|
-
return null;
|
|
1344
|
-
}
|
|
1345
|
-
const _normalizeError = _checkNormalize();
|
|
1346
|
-
var LogLevel;
|
|
1347
|
-
(function (LogLevel) {
|
|
1348
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
1349
|
-
LogLevel["INFO"] = "INFO";
|
|
1350
|
-
LogLevel["WARNING"] = "WARNING";
|
|
1351
|
-
LogLevel["ERROR"] = "ERROR";
|
|
1352
|
-
LogLevel["OFF"] = "OFF";
|
|
1353
|
-
})(LogLevel || (LogLevel = {}));
|
|
1354
|
-
var ErrorCode;
|
|
1355
|
-
(function (ErrorCode) {
|
|
1356
|
-
///////////////////
|
|
1357
|
-
// Generic Errors
|
|
1358
|
-
// Unknown Error
|
|
1359
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1360
|
-
// Not Implemented
|
|
1361
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1362
|
-
// Unsupported Operation
|
|
1363
|
-
// - operation
|
|
1364
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1365
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1366
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1367
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1368
|
-
// Some sort of bad response from the server
|
|
1369
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1370
|
-
// Timeout
|
|
1371
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1372
|
-
///////////////////
|
|
1373
|
-
// Operational Errors
|
|
1374
|
-
// Buffer Overrun
|
|
1375
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1376
|
-
// Numeric Fault
|
|
1377
|
-
// - operation: the operation being executed
|
|
1378
|
-
// - fault: the reason this faulted
|
|
1379
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1380
|
-
///////////////////
|
|
1381
|
-
// Argument Errors
|
|
1382
|
-
// Missing new operator to an object
|
|
1383
|
-
// - name: The name of the class
|
|
1384
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1385
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1386
|
-
// - argument: The argument name that was invalid
|
|
1387
|
-
// - value: The value of the argument
|
|
1388
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1389
|
-
// Missing argument to a function:
|
|
1390
|
-
// - count: The number of arguments received
|
|
1391
|
-
// - expectedCount: The number of arguments expected
|
|
1392
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1393
|
-
// Too many arguments
|
|
1394
|
-
// - count: The number of arguments received
|
|
1395
|
-
// - expectedCount: The number of arguments expected
|
|
1396
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1397
|
-
///////////////////
|
|
1398
|
-
// Blockchain Errors
|
|
1399
|
-
// Call exception
|
|
1400
|
-
// - transaction: the transaction
|
|
1401
|
-
// - address?: the contract address
|
|
1402
|
-
// - args?: The arguments passed into the function
|
|
1403
|
-
// - method?: The Solidity method signature
|
|
1404
|
-
// - errorSignature?: The EIP848 error signature
|
|
1405
|
-
// - errorArgs?: The EIP848 error parameters
|
|
1406
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1407
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1408
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1409
|
-
// - transaction: the transaction attempted
|
|
1410
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1411
|
-
// Nonce has already been used
|
|
1412
|
-
// - transaction: the transaction attempted
|
|
1413
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1414
|
-
// The replacement fee for the transaction is too low
|
|
1415
|
-
// - transaction: the transaction attempted
|
|
1416
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1417
|
-
// The gas limit could not be estimated
|
|
1418
|
-
// - transaction: the transaction passed to estimateGas
|
|
1419
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1420
|
-
// The transaction was replaced by one with a higher gas price
|
|
1421
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
1422
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1423
|
-
// - hash: original transaction hash
|
|
1424
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
1425
|
-
// - receipt: the receipt of the replacement
|
|
1426
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1427
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
1428
|
-
const HEX = "0123456789abcdef";
|
|
1429
|
-
class Logger {
|
|
1430
|
-
constructor(version) {
|
|
1431
|
-
Object.defineProperty(this, "version", {
|
|
1432
|
-
enumerable: true,
|
|
1433
|
-
value: version,
|
|
1434
|
-
writable: false
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
_log(logLevel, args) {
|
|
1438
|
-
const level = logLevel.toLowerCase();
|
|
1439
|
-
if (LogLevels[level] == null) {
|
|
1440
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1441
|
-
}
|
|
1442
|
-
if (_logLevel > LogLevels[level]) {
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
console.log.apply(console, args);
|
|
1446
|
-
}
|
|
1447
|
-
debug(...args) {
|
|
1448
|
-
this._log(Logger.levels.DEBUG, args);
|
|
1449
|
-
}
|
|
1450
|
-
info(...args) {
|
|
1451
|
-
this._log(Logger.levels.INFO, args);
|
|
1452
|
-
}
|
|
1453
|
-
warn(...args) {
|
|
1454
|
-
this._log(Logger.levels.WARNING, args);
|
|
1455
|
-
}
|
|
1456
|
-
makeError(message, code, params) {
|
|
1457
|
-
// Errors are being censored
|
|
1458
|
-
if (_censorErrors) {
|
|
1459
|
-
return this.makeError("censored error", code, {});
|
|
1460
|
-
}
|
|
1461
|
-
if (!code) {
|
|
1462
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
1463
|
-
}
|
|
1464
|
-
if (!params) {
|
|
1465
|
-
params = {};
|
|
1466
|
-
}
|
|
1467
|
-
const messageDetails = [];
|
|
1468
|
-
Object.keys(params).forEach((key) => {
|
|
1469
|
-
const value = params[key];
|
|
1470
|
-
try {
|
|
1471
|
-
if (value instanceof Uint8Array) {
|
|
1472
|
-
let hex = "";
|
|
1473
|
-
for (let i = 0; i < value.length; i++) {
|
|
1474
|
-
hex += HEX[value[i] >> 4];
|
|
1475
|
-
hex += HEX[value[i] & 0x0f];
|
|
1476
|
-
}
|
|
1477
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1478
|
-
}
|
|
1479
|
-
else {
|
|
1480
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
catch (error) {
|
|
1484
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1485
|
-
}
|
|
1486
|
-
});
|
|
1487
|
-
messageDetails.push(`code=${code}`);
|
|
1488
|
-
messageDetails.push(`version=${this.version}`);
|
|
1489
|
-
const reason = message;
|
|
1490
|
-
let url = "";
|
|
1491
|
-
switch (code) {
|
|
1492
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
1493
|
-
url = "NUMERIC_FAULT";
|
|
1494
|
-
const fault = message;
|
|
1495
|
-
switch (fault) {
|
|
1496
|
-
case "overflow":
|
|
1497
|
-
case "underflow":
|
|
1498
|
-
case "division-by-zero":
|
|
1499
|
-
url += "-" + fault;
|
|
1500
|
-
break;
|
|
1501
|
-
case "negative-power":
|
|
1502
|
-
case "negative-width":
|
|
1503
|
-
url += "-unsupported";
|
|
1504
|
-
break;
|
|
1505
|
-
case "unbound-bitwise-result":
|
|
1506
|
-
url += "-unbound-result";
|
|
1507
|
-
break;
|
|
1508
|
-
}
|
|
1509
|
-
break;
|
|
1510
|
-
}
|
|
1511
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
1512
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
1513
|
-
case ErrorCode.MISSING_NEW:
|
|
1514
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
1515
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
1516
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
1517
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
1518
|
-
url = code;
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
if (url) {
|
|
1522
|
-
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
1523
|
-
}
|
|
1524
|
-
if (messageDetails.length) {
|
|
1525
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
1526
|
-
}
|
|
1527
|
-
// @TODO: Any??
|
|
1528
|
-
const error = new Error(message);
|
|
1529
|
-
error.reason = reason;
|
|
1530
|
-
error.code = code;
|
|
1531
|
-
Object.keys(params).forEach(function (key) {
|
|
1532
|
-
error[key] = params[key];
|
|
1533
|
-
});
|
|
1534
|
-
return error;
|
|
1535
|
-
}
|
|
1536
|
-
throwError(message, code, params) {
|
|
1537
|
-
throw this.makeError(message, code, params);
|
|
1538
|
-
}
|
|
1539
|
-
throwArgumentError(message, name, value) {
|
|
1540
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1541
|
-
argument: name,
|
|
1542
|
-
value: value
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
assert(condition, message, code, params) {
|
|
1546
|
-
if (!!condition) {
|
|
1547
|
-
return;
|
|
1548
|
-
}
|
|
1549
|
-
this.throwError(message, code, params);
|
|
1550
|
-
}
|
|
1551
|
-
assertArgument(condition, message, name, value) {
|
|
1552
|
-
if (!!condition) {
|
|
1553
|
-
return;
|
|
1554
|
-
}
|
|
1555
|
-
this.throwArgumentError(message, name, value);
|
|
1556
|
-
}
|
|
1557
|
-
checkNormalize(message) {
|
|
1558
|
-
if (_normalizeError) {
|
|
1559
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1560
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
checkSafeUint53(value, message) {
|
|
1565
|
-
if (typeof (value) !== "number") {
|
|
1566
|
-
return;
|
|
1567
|
-
}
|
|
1568
|
-
if (message == null) {
|
|
1569
|
-
message = "value not safe";
|
|
1570
|
-
}
|
|
1571
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1572
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1573
|
-
operation: "checkSafeInteger",
|
|
1574
|
-
fault: "out-of-safe-range",
|
|
1575
|
-
value: value
|
|
1576
|
-
});
|
|
1577
|
-
}
|
|
1578
|
-
if (value % 1) {
|
|
1579
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1580
|
-
operation: "checkSafeInteger",
|
|
1581
|
-
fault: "non-integer",
|
|
1582
|
-
value: value
|
|
1583
|
-
});
|
|
1584
|
-
}
|
|
1585
|
-
}
|
|
1586
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
1587
|
-
if (message) {
|
|
1588
|
-
message = ": " + message;
|
|
1589
|
-
}
|
|
1590
|
-
else {
|
|
1591
|
-
message = "";
|
|
1592
|
-
}
|
|
1593
|
-
if (count < expectedCount) {
|
|
1594
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1595
|
-
count: count,
|
|
1596
|
-
expectedCount: expectedCount
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
if (count > expectedCount) {
|
|
1600
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1601
|
-
count: count,
|
|
1602
|
-
expectedCount: expectedCount
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
checkNew(target, kind) {
|
|
1607
|
-
if (target === Object || target == null) {
|
|
1608
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
checkAbstract(target, kind) {
|
|
1612
|
-
if (target === kind) {
|
|
1613
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1614
|
-
}
|
|
1615
|
-
else if (target === Object || target == null) {
|
|
1616
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
static globalLogger() {
|
|
1620
|
-
if (!_globalLogger) {
|
|
1621
|
-
_globalLogger = new Logger(version$2);
|
|
1622
|
-
}
|
|
1623
|
-
return _globalLogger;
|
|
1624
|
-
}
|
|
1625
|
-
static setCensorship(censorship, permanent) {
|
|
1626
|
-
if (!censorship && permanent) {
|
|
1627
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1628
|
-
operation: "setCensorship"
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
if (_permanentCensorErrors) {
|
|
1632
|
-
if (!censorship) {
|
|
1633
|
-
return;
|
|
1634
|
-
}
|
|
1635
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1636
|
-
operation: "setCensorship"
|
|
1637
|
-
});
|
|
1638
|
-
}
|
|
1639
|
-
_censorErrors = !!censorship;
|
|
1640
|
-
_permanentCensorErrors = !!permanent;
|
|
1641
|
-
}
|
|
1642
|
-
static setLogLevel(logLevel) {
|
|
1643
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
1644
|
-
if (level == null) {
|
|
1645
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1646
|
-
return;
|
|
1647
|
-
}
|
|
1648
|
-
_logLevel = level;
|
|
1649
|
-
}
|
|
1650
|
-
static from(version) {
|
|
1651
|
-
return new Logger(version);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
Logger.errors = ErrorCode;
|
|
1655
|
-
Logger.levels = LogLevel;
|
|
1656
|
-
|
|
1657
|
-
const version$1 = "bytes/5.6.0";
|
|
1658
|
-
|
|
1659
|
-
const logger = new Logger(version$1);
|
|
1660
|
-
///////////////////////////////
|
|
1661
|
-
function isHexable(value) {
|
|
1662
|
-
return !!(value.toHexString);
|
|
1663
|
-
}
|
|
1664
|
-
function addSlice(array) {
|
|
1665
|
-
if (array.slice) {
|
|
1666
|
-
return array;
|
|
1667
|
-
}
|
|
1668
|
-
array.slice = function () {
|
|
1669
|
-
const args = Array.prototype.slice.call(arguments);
|
|
1670
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1671
|
-
};
|
|
1672
|
-
return array;
|
|
1673
|
-
}
|
|
1674
|
-
function isInteger(value) {
|
|
1675
|
-
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1676
|
-
}
|
|
1677
|
-
function isBytes(value) {
|
|
1678
|
-
if (value == null) {
|
|
1679
|
-
return false;
|
|
1680
|
-
}
|
|
1681
|
-
if (value.constructor === Uint8Array) {
|
|
1682
|
-
return true;
|
|
1683
|
-
}
|
|
1684
|
-
if (typeof (value) === "string") {
|
|
1685
|
-
return false;
|
|
1686
|
-
}
|
|
1687
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
1688
|
-
return false;
|
|
1689
|
-
}
|
|
1690
|
-
for (let i = 0; i < value.length; i++) {
|
|
1691
|
-
const v = value[i];
|
|
1692
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1693
|
-
return false;
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
return true;
|
|
1697
|
-
}
|
|
1698
|
-
function arrayify(value, options) {
|
|
1699
|
-
if (!options) {
|
|
1700
|
-
options = {};
|
|
1701
|
-
}
|
|
1702
|
-
if (typeof (value) === "number") {
|
|
1703
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1704
|
-
const result = [];
|
|
1705
|
-
while (value) {
|
|
1706
|
-
result.unshift(value & 0xff);
|
|
1707
|
-
value = parseInt(String(value / 256));
|
|
1708
|
-
}
|
|
1709
|
-
if (result.length === 0) {
|
|
1710
|
-
result.push(0);
|
|
1711
|
-
}
|
|
1712
|
-
return addSlice(new Uint8Array(result));
|
|
1713
|
-
}
|
|
1714
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1715
|
-
value = "0x" + value;
|
|
1716
|
-
}
|
|
1717
|
-
if (isHexable(value)) {
|
|
1718
|
-
value = value.toHexString();
|
|
1719
|
-
}
|
|
1720
|
-
if (isHexString(value)) {
|
|
1721
|
-
let hex = value.substring(2);
|
|
1722
|
-
if (hex.length % 2) {
|
|
1723
|
-
if (options.hexPad === "left") {
|
|
1724
|
-
hex = "0x0" + hex.substring(2);
|
|
1725
|
-
}
|
|
1726
|
-
else if (options.hexPad === "right") {
|
|
1727
|
-
hex += "0";
|
|
1728
|
-
}
|
|
1729
|
-
else {
|
|
1730
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
const result = [];
|
|
1734
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
1735
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1736
|
-
}
|
|
1737
|
-
return addSlice(new Uint8Array(result));
|
|
1738
|
-
}
|
|
1739
|
-
if (isBytes(value)) {
|
|
1740
|
-
return addSlice(new Uint8Array(value));
|
|
1741
|
-
}
|
|
1742
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1743
|
-
}
|
|
1744
|
-
function isHexString(value, length) {
|
|
1745
|
-
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1746
|
-
return false;
|
|
1747
|
-
}
|
|
1748
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
1749
|
-
return false;
|
|
1750
|
-
}
|
|
1751
|
-
return true;
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
const version = "sha2/5.6.0";
|
|
1755
|
-
|
|
1756
|
-
new Logger(version);
|
|
1757
|
-
function sha256(data) {
|
|
1758
|
-
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
93
|
class Struct {
|
|
1762
94
|
constructor(properties) {
|
|
1763
95
|
Object.assign(this, properties);
|
|
@@ -1800,6 +132,11 @@ const SOLANA_SCHEMA = new Map();
|
|
|
1800
132
|
*/
|
|
1801
133
|
|
|
1802
134
|
const MAX_SEED_LENGTH = 32;
|
|
135
|
+
/**
|
|
136
|
+
* Size of public key in bytes
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
const PUBLIC_KEY_LENGTH = 32;
|
|
1803
140
|
/**
|
|
1804
141
|
* Value to be converted into public key
|
|
1805
142
|
*/
|
|
@@ -1830,7 +167,7 @@ class PublicKey extends Struct {
|
|
|
1830
167
|
// assume base 58 encoding by default
|
|
1831
168
|
const decoded = bs58__default["default"].decode(value);
|
|
1832
169
|
|
|
1833
|
-
if (decoded.length !=
|
|
170
|
+
if (decoded.length != PUBLIC_KEY_LENGTH) {
|
|
1834
171
|
throw new Error(`Invalid public key input`);
|
|
1835
172
|
}
|
|
1836
173
|
|
|
@@ -1883,7 +220,7 @@ class PublicKey extends Struct {
|
|
|
1883
220
|
toBuffer() {
|
|
1884
221
|
const b = this._bn.toArrayLike(buffer.Buffer);
|
|
1885
222
|
|
|
1886
|
-
if (b.length ===
|
|
223
|
+
if (b.length === PUBLIC_KEY_LENGTH) {
|
|
1887
224
|
return b;
|
|
1888
225
|
}
|
|
1889
226
|
|
|
@@ -1910,8 +247,8 @@ class PublicKey extends Struct {
|
|
|
1910
247
|
|
|
1911
248
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1912
249
|
const buffer$1 = buffer.Buffer.concat([fromPublicKey.toBuffer(), buffer.Buffer.from(seed), programId.toBuffer()]);
|
|
1913
|
-
const
|
|
1914
|
-
return new PublicKey(
|
|
250
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
251
|
+
return new PublicKey(publicKeyBytes);
|
|
1915
252
|
}
|
|
1916
253
|
/**
|
|
1917
254
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1930,10 +267,9 @@ class PublicKey extends Struct {
|
|
|
1930
267
|
buffer$1 = buffer.Buffer.concat([buffer$1, toBuffer(seed)]);
|
|
1931
268
|
});
|
|
1932
269
|
buffer$1 = buffer.Buffer.concat([buffer$1, programId.toBuffer(), buffer.Buffer.from('ProgramDerivedAddress')]);
|
|
1933
|
-
|
|
1934
|
-
let publicKeyBytes = new BN__default["default"](hash, 16).toArray(undefined, 32);
|
|
270
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
1935
271
|
|
|
1936
|
-
if (
|
|
272
|
+
if (isOnCurve(publicKeyBytes)) {
|
|
1937
273
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1938
274
|
}
|
|
1939
275
|
|
|
@@ -1997,7 +333,7 @@ class PublicKey extends Struct {
|
|
|
1997
333
|
|
|
1998
334
|
static isOnCurve(pubkeyData) {
|
|
1999
335
|
const pubkey = new PublicKey(pubkeyData);
|
|
2000
|
-
return
|
|
336
|
+
return isOnCurve(pubkey.toBytes());
|
|
2001
337
|
}
|
|
2002
338
|
|
|
2003
339
|
}
|
|
@@ -2005,56 +341,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
|
2005
341
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
2006
342
|
kind: 'struct',
|
|
2007
343
|
fields: [['_bn', 'u256']]
|
|
2008
|
-
});
|
|
2009
|
-
|
|
2010
|
-
let naclLowLevel = nacl__default["default"].lowlevel; // Check that a pubkey is on the curve.
|
|
2011
|
-
// This function and its dependents were sourced from:
|
|
2012
|
-
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
2013
|
-
|
|
2014
|
-
function is_on_curve(p) {
|
|
2015
|
-
var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
|
|
2016
|
-
var t = naclLowLevel.gf(),
|
|
2017
|
-
chk = naclLowLevel.gf(),
|
|
2018
|
-
num = naclLowLevel.gf(),
|
|
2019
|
-
den = naclLowLevel.gf(),
|
|
2020
|
-
den2 = naclLowLevel.gf(),
|
|
2021
|
-
den4 = naclLowLevel.gf(),
|
|
2022
|
-
den6 = naclLowLevel.gf();
|
|
2023
|
-
naclLowLevel.set25519(r[2], gf1);
|
|
2024
|
-
naclLowLevel.unpack25519(r[1], p);
|
|
2025
|
-
naclLowLevel.S(num, r[1]);
|
|
2026
|
-
naclLowLevel.M(den, num, naclLowLevel.D);
|
|
2027
|
-
naclLowLevel.Z(num, num, r[2]);
|
|
2028
|
-
naclLowLevel.A(den, r[2], den);
|
|
2029
|
-
naclLowLevel.S(den2, den);
|
|
2030
|
-
naclLowLevel.S(den4, den2);
|
|
2031
|
-
naclLowLevel.M(den6, den4, den2);
|
|
2032
|
-
naclLowLevel.M(t, den6, num);
|
|
2033
|
-
naclLowLevel.M(t, t, den);
|
|
2034
|
-
naclLowLevel.pow2523(t, t);
|
|
2035
|
-
naclLowLevel.M(t, t, num);
|
|
2036
|
-
naclLowLevel.M(t, t, den);
|
|
2037
|
-
naclLowLevel.M(t, t, den);
|
|
2038
|
-
naclLowLevel.M(r[0], t, den);
|
|
2039
|
-
naclLowLevel.S(chk, r[0]);
|
|
2040
|
-
naclLowLevel.M(chk, chk, den);
|
|
2041
|
-
if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
|
|
2042
|
-
naclLowLevel.S(chk, r[0]);
|
|
2043
|
-
naclLowLevel.M(chk, chk, den);
|
|
2044
|
-
if (neq25519(chk, num)) return 0;
|
|
2045
|
-
return 1;
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
let gf1 = naclLowLevel.gf([1]);
|
|
2049
|
-
let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
2050
|
-
|
|
2051
|
-
function neq25519(a, b) {
|
|
2052
|
-
var c = new Uint8Array(32),
|
|
2053
|
-
d = new Uint8Array(32);
|
|
2054
|
-
naclLowLevel.pack25519(c, a);
|
|
2055
|
-
naclLowLevel.pack25519(d, b);
|
|
2056
|
-
return naclLowLevel.crypto_verify_32(c, 0, d, 0);
|
|
2057
|
-
}
|
|
344
|
+
});
|
|
2058
345
|
|
|
2059
346
|
/**
|
|
2060
347
|
* An account key pair (public and secret keys).
|
|
@@ -2065,6 +352,8 @@ function neq25519(a, b) {
|
|
|
2065
352
|
class Account {
|
|
2066
353
|
/** @internal */
|
|
2067
354
|
|
|
355
|
+
/** @internal */
|
|
356
|
+
|
|
2068
357
|
/**
|
|
2069
358
|
* Create a new Account object
|
|
2070
359
|
*
|
|
@@ -2074,12 +363,21 @@ class Account {
|
|
|
2074
363
|
* @param secretKey Secret key for the account
|
|
2075
364
|
*/
|
|
2076
365
|
constructor(secretKey) {
|
|
2077
|
-
this.
|
|
366
|
+
this._publicKey = void 0;
|
|
367
|
+
this._secretKey = void 0;
|
|
2078
368
|
|
|
2079
369
|
if (secretKey) {
|
|
2080
|
-
|
|
370
|
+
const secretKeyBuffer = toBuffer(secretKey);
|
|
371
|
+
|
|
372
|
+
if (secretKey.length !== 64) {
|
|
373
|
+
throw new Error('bad secret key size');
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
this._publicKey = secretKeyBuffer.slice(32, 64);
|
|
377
|
+
this._secretKey = secretKeyBuffer.slice(0, 32);
|
|
2081
378
|
} else {
|
|
2082
|
-
this.
|
|
379
|
+
this._secretKey = toBuffer(generatePrivateKey());
|
|
380
|
+
this._publicKey = toBuffer(getPublicKey(this._secretKey));
|
|
2083
381
|
}
|
|
2084
382
|
}
|
|
2085
383
|
/**
|
|
@@ -2088,15 +386,17 @@ class Account {
|
|
|
2088
386
|
|
|
2089
387
|
|
|
2090
388
|
get publicKey() {
|
|
2091
|
-
return new PublicKey(this.
|
|
389
|
+
return new PublicKey(this._publicKey);
|
|
2092
390
|
}
|
|
2093
391
|
/**
|
|
2094
|
-
* The **unencrypted** secret key for this account
|
|
392
|
+
* The **unencrypted** secret key for this account. The first 32 bytes
|
|
393
|
+
* is the private scalar and the last 32 bytes is the public key.
|
|
394
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
2095
395
|
*/
|
|
2096
396
|
|
|
2097
397
|
|
|
2098
398
|
get secretKey() {
|
|
2099
|
-
return
|
|
399
|
+
return buffer.Buffer.concat([this._secretKey, this._publicKey], 64);
|
|
2100
400
|
}
|
|
2101
401
|
|
|
2102
402
|
}
|
|
@@ -2111,6 +411,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
|
|
|
2111
411
|
* 8 bytes is the size of the fragment header
|
|
2112
412
|
*/
|
|
2113
413
|
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
414
|
+
const VERSION_PREFIX_MASK = 0x7f;
|
|
2114
415
|
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2115
416
|
|
|
2116
417
|
class TransactionExpiredBlockheightExceededError extends Error {
|
|
@@ -2143,6 +444,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
2143
444
|
const publicKey = (property = 'publicKey') => {
|
|
2144
445
|
return BufferLayout__namespace.blob(32, property);
|
|
2145
446
|
};
|
|
447
|
+
/**
|
|
448
|
+
* Layout for a signature
|
|
449
|
+
*/
|
|
450
|
+
|
|
451
|
+
const signature = (property = 'signature') => {
|
|
452
|
+
return BufferLayout__namespace.blob(64, property);
|
|
453
|
+
};
|
|
2146
454
|
|
|
2147
455
|
/**
|
|
2148
456
|
* Layout for a Rust String type
|
|
@@ -2254,11 +562,9 @@ function encodeLength(bytes, len) {
|
|
|
2254
562
|
}
|
|
2255
563
|
}
|
|
2256
564
|
|
|
2257
|
-
const PUBKEY_LENGTH = 32;
|
|
2258
565
|
/**
|
|
2259
566
|
* List of instructions to be processed atomically
|
|
2260
567
|
*/
|
|
2261
|
-
|
|
2262
568
|
class Message {
|
|
2263
569
|
constructor(args) {
|
|
2264
570
|
this.header = void 0;
|
|
@@ -2273,6 +579,26 @@ class Message {
|
|
|
2273
579
|
this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
|
|
2274
580
|
}
|
|
2275
581
|
|
|
582
|
+
get version() {
|
|
583
|
+
return 'legacy';
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
get staticAccountKeys() {
|
|
587
|
+
return this.accountKeys;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
get compiledInstructions() {
|
|
591
|
+
return this.instructions.map(ix => ({
|
|
592
|
+
programIdIndex: ix.programIdIndex,
|
|
593
|
+
accountKeyIndexes: ix.accounts,
|
|
594
|
+
data: bs58__default["default"].decode(ix.data)
|
|
595
|
+
}));
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
get addressTableLookups() {
|
|
599
|
+
return [];
|
|
600
|
+
}
|
|
601
|
+
|
|
2276
602
|
isAccountSigner(index) {
|
|
2277
603
|
return index < this.header.numRequiredSignatures;
|
|
2278
604
|
}
|
|
@@ -2349,19 +675,24 @@ class Message {
|
|
|
2349
675
|
// Slice up wire data
|
|
2350
676
|
let byteArray = [...buffer$1];
|
|
2351
677
|
const numRequiredSignatures = byteArray.shift();
|
|
678
|
+
|
|
679
|
+
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
680
|
+
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
681
|
+
}
|
|
682
|
+
|
|
2352
683
|
const numReadonlySignedAccounts = byteArray.shift();
|
|
2353
684
|
const numReadonlyUnsignedAccounts = byteArray.shift();
|
|
2354
685
|
const accountCount = decodeLength(byteArray);
|
|
2355
686
|
let accountKeys = [];
|
|
2356
687
|
|
|
2357
688
|
for (let i = 0; i < accountCount; i++) {
|
|
2358
|
-
const account = byteArray.slice(0,
|
|
2359
|
-
byteArray = byteArray.slice(
|
|
689
|
+
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
690
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
2360
691
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2361
692
|
}
|
|
2362
693
|
|
|
2363
|
-
const recentBlockhash = byteArray.slice(0,
|
|
2364
|
-
byteArray = byteArray.slice(
|
|
694
|
+
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
695
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
2365
696
|
const instructionCount = decodeLength(byteArray);
|
|
2366
697
|
let instructions = [];
|
|
2367
698
|
|
|
@@ -2402,6 +733,194 @@ function assert (condition, message) {
|
|
|
2402
733
|
}
|
|
2403
734
|
}
|
|
2404
735
|
|
|
736
|
+
/**
|
|
737
|
+
* Message constructor arguments
|
|
738
|
+
*/
|
|
739
|
+
|
|
740
|
+
class MessageV0 {
|
|
741
|
+
constructor(args) {
|
|
742
|
+
this.header = void 0;
|
|
743
|
+
this.staticAccountKeys = void 0;
|
|
744
|
+
this.recentBlockhash = void 0;
|
|
745
|
+
this.compiledInstructions = void 0;
|
|
746
|
+
this.addressTableLookups = void 0;
|
|
747
|
+
this.header = args.header;
|
|
748
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
749
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
750
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
751
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
get version() {
|
|
755
|
+
return 0;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
serialize() {
|
|
759
|
+
const encodedStaticAccountKeysLength = Array();
|
|
760
|
+
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
761
|
+
const serializedInstructions = this.serializeInstructions();
|
|
762
|
+
const encodedInstructionsLength = Array();
|
|
763
|
+
encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
|
|
764
|
+
const serializedAddressTableLookups = this.serializeAddressTableLookups();
|
|
765
|
+
const encodedAddressTableLookupsLength = Array();
|
|
766
|
+
encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
|
|
767
|
+
const messageLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('prefix'), BufferLayout__namespace.struct([BufferLayout__namespace.u8('numRequiredSignatures'), BufferLayout__namespace.u8('numReadonlySignedAccounts'), BufferLayout__namespace.u8('numReadonlyUnsignedAccounts')], 'header'), BufferLayout__namespace.blob(encodedStaticAccountKeysLength.length, 'staticAccountKeysLength'), BufferLayout__namespace.seq(publicKey(), this.staticAccountKeys.length, 'staticAccountKeys'), publicKey('recentBlockhash'), BufferLayout__namespace.blob(encodedInstructionsLength.length, 'instructionsLength'), BufferLayout__namespace.blob(serializedInstructions.length, 'serializedInstructions'), BufferLayout__namespace.blob(encodedAddressTableLookupsLength.length, 'addressTableLookupsLength'), BufferLayout__namespace.blob(serializedAddressTableLookups.length, 'serializedAddressTableLookups')]);
|
|
768
|
+
const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
|
|
769
|
+
const MESSAGE_VERSION_0_PREFIX = 1 << 7;
|
|
770
|
+
const serializedMessageLength = messageLayout.encode({
|
|
771
|
+
prefix: MESSAGE_VERSION_0_PREFIX,
|
|
772
|
+
header: this.header,
|
|
773
|
+
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
|
774
|
+
staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
|
|
775
|
+
recentBlockhash: bs58__default["default"].decode(this.recentBlockhash),
|
|
776
|
+
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
|
777
|
+
serializedInstructions,
|
|
778
|
+
addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
|
|
779
|
+
serializedAddressTableLookups
|
|
780
|
+
}, serializedMessage);
|
|
781
|
+
return serializedMessage.slice(0, serializedMessageLength);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
serializeInstructions() {
|
|
785
|
+
let serializedLength = 0;
|
|
786
|
+
const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
|
|
787
|
+
|
|
788
|
+
for (const instruction of this.compiledInstructions) {
|
|
789
|
+
const encodedAccountKeyIndexesLength = Array();
|
|
790
|
+
encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
|
|
791
|
+
const encodedDataLength = Array();
|
|
792
|
+
encodeLength(encodedDataLength, instruction.data.length);
|
|
793
|
+
const instructionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u8('programIdIndex'), BufferLayout__namespace.blob(encodedAccountKeyIndexesLength.length, 'encodedAccountKeyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), instruction.accountKeyIndexes.length, 'accountKeyIndexes'), BufferLayout__namespace.blob(encodedDataLength.length, 'encodedDataLength'), BufferLayout__namespace.blob(instruction.data.length, 'data')]);
|
|
794
|
+
serializedLength += instructionLayout.encode({
|
|
795
|
+
programIdIndex: instruction.programIdIndex,
|
|
796
|
+
encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
|
|
797
|
+
accountKeyIndexes: instruction.accountKeyIndexes,
|
|
798
|
+
encodedDataLength: new Uint8Array(encodedDataLength),
|
|
799
|
+
data: instruction.data
|
|
800
|
+
}, serializedInstructions, serializedLength);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
return serializedInstructions.slice(0, serializedLength);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
serializeAddressTableLookups() {
|
|
807
|
+
let serializedLength = 0;
|
|
808
|
+
const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
|
|
809
|
+
|
|
810
|
+
for (const lookup of this.addressTableLookups) {
|
|
811
|
+
const encodedWritableIndexesLength = Array();
|
|
812
|
+
encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
|
|
813
|
+
const encodedReadonlyIndexesLength = Array();
|
|
814
|
+
encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
|
|
815
|
+
const addressTableLookupLayout = BufferLayout__namespace.struct([publicKey('accountKey'), BufferLayout__namespace.blob(encodedWritableIndexesLength.length, 'encodedWritableIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.writableIndexes.length, 'writableIndexes'), BufferLayout__namespace.blob(encodedReadonlyIndexesLength.length, 'encodedReadonlyIndexesLength'), BufferLayout__namespace.seq(BufferLayout__namespace.u8(), lookup.readonlyIndexes.length, 'readonlyIndexes')]);
|
|
816
|
+
serializedLength += addressTableLookupLayout.encode({
|
|
817
|
+
accountKey: lookup.accountKey.toBytes(),
|
|
818
|
+
encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
|
|
819
|
+
writableIndexes: lookup.writableIndexes,
|
|
820
|
+
encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
|
|
821
|
+
readonlyIndexes: lookup.readonlyIndexes
|
|
822
|
+
}, serializedAddressTableLookups, serializedLength);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return serializedAddressTableLookups.slice(0, serializedLength);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
static deserialize(serializedMessage) {
|
|
829
|
+
let byteArray = [...serializedMessage];
|
|
830
|
+
const prefix = byteArray.shift();
|
|
831
|
+
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
832
|
+
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
833
|
+
const version = maskedPrefix;
|
|
834
|
+
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
835
|
+
const header = {
|
|
836
|
+
numRequiredSignatures: byteArray.shift(),
|
|
837
|
+
numReadonlySignedAccounts: byteArray.shift(),
|
|
838
|
+
numReadonlyUnsignedAccounts: byteArray.shift()
|
|
839
|
+
};
|
|
840
|
+
const staticAccountKeys = [];
|
|
841
|
+
const staticAccountKeysLength = decodeLength(byteArray);
|
|
842
|
+
|
|
843
|
+
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
844
|
+
staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
|
|
848
|
+
const instructionCount = decodeLength(byteArray);
|
|
849
|
+
const compiledInstructions = [];
|
|
850
|
+
|
|
851
|
+
for (let i = 0; i < instructionCount; i++) {
|
|
852
|
+
const programIdIndex = byteArray.shift();
|
|
853
|
+
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
854
|
+
const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
|
|
855
|
+
const dataLength = decodeLength(byteArray);
|
|
856
|
+
const data = new Uint8Array(byteArray.splice(0, dataLength));
|
|
857
|
+
compiledInstructions.push({
|
|
858
|
+
programIdIndex,
|
|
859
|
+
accountKeyIndexes,
|
|
860
|
+
data
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
const addressTableLookupsCount = decodeLength(byteArray);
|
|
865
|
+
const addressTableLookups = [];
|
|
866
|
+
|
|
867
|
+
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
868
|
+
const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
|
|
869
|
+
const writableIndexesLength = decodeLength(byteArray);
|
|
870
|
+
const writableIndexes = byteArray.splice(0, writableIndexesLength);
|
|
871
|
+
const readonlyIndexesLength = decodeLength(byteArray);
|
|
872
|
+
const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
|
|
873
|
+
addressTableLookups.push({
|
|
874
|
+
accountKey,
|
|
875
|
+
writableIndexes,
|
|
876
|
+
readonlyIndexes
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return new MessageV0({
|
|
881
|
+
header,
|
|
882
|
+
staticAccountKeys,
|
|
883
|
+
recentBlockhash,
|
|
884
|
+
compiledInstructions,
|
|
885
|
+
addressTableLookups
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
// eslint-disable-next-line no-redeclare
|
|
892
|
+
const VersionedMessage = {
|
|
893
|
+
deserializeMessageVersion(serializedMessage) {
|
|
894
|
+
const prefix = serializedMessage[0];
|
|
895
|
+
const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
|
|
896
|
+
|
|
897
|
+
if (maskedPrefix === prefix) {
|
|
898
|
+
return 'legacy';
|
|
899
|
+
} // the lower 7 bits of the prefix indicate the message version
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
return maskedPrefix;
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
deserialize: serializedMessage => {
|
|
906
|
+
const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
|
|
907
|
+
|
|
908
|
+
if (version === 'legacy') {
|
|
909
|
+
return Message.from(serializedMessage);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
if (version === 0) {
|
|
913
|
+
return MessageV0.deserialize(serializedMessage);
|
|
914
|
+
} else {
|
|
915
|
+
throw new Error(`Transaction message version ${version} deserialization is not supported`);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Transaction signature as base-58 encoded string
|
|
922
|
+
*/
|
|
923
|
+
|
|
2405
924
|
exports.TransactionStatus = void 0;
|
|
2406
925
|
/**
|
|
2407
926
|
* Default (empty) signature
|
|
@@ -2927,7 +1446,7 @@ class Transaction {
|
|
|
2927
1446
|
_partialSign(message, ...signers) {
|
|
2928
1447
|
const signData = message.serialize();
|
|
2929
1448
|
signers.forEach(signer => {
|
|
2930
|
-
const signature =
|
|
1449
|
+
const signature = sign(signData, signer.secretKey);
|
|
2931
1450
|
|
|
2932
1451
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2933
1452
|
});
|
|
@@ -2983,7 +1502,7 @@ class Transaction {
|
|
|
2983
1502
|
return false;
|
|
2984
1503
|
}
|
|
2985
1504
|
} else {
|
|
2986
|
-
if (!
|
|
1505
|
+
if (!verify(signature, signData, publicKey.toBuffer())) {
|
|
2987
1506
|
return false;
|
|
2988
1507
|
}
|
|
2989
1508
|
}
|
|
@@ -3130,6 +1649,70 @@ class Transaction {
|
|
|
3130
1649
|
|
|
3131
1650
|
}
|
|
3132
1651
|
|
|
1652
|
+
/**
|
|
1653
|
+
* Versioned transaction class
|
|
1654
|
+
*/
|
|
1655
|
+
class VersionedTransaction {
|
|
1656
|
+
constructor(message, signatures) {
|
|
1657
|
+
this.signatures = void 0;
|
|
1658
|
+
this.message = void 0;
|
|
1659
|
+
|
|
1660
|
+
if (signatures !== undefined) {
|
|
1661
|
+
assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
|
|
1662
|
+
this.signatures = signatures;
|
|
1663
|
+
} else {
|
|
1664
|
+
const defaultSignatures = [];
|
|
1665
|
+
|
|
1666
|
+
for (let i = 0; i < message.header.numRequiredSignatures; i++) {
|
|
1667
|
+
defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
this.signatures = defaultSignatures;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
this.message = message;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
serialize() {
|
|
1677
|
+
const serializedMessage = this.message.serialize();
|
|
1678
|
+
const encodedSignaturesLength = Array();
|
|
1679
|
+
encodeLength(encodedSignaturesLength, this.signatures.length);
|
|
1680
|
+
const transactionLayout = BufferLayout__namespace.struct([BufferLayout__namespace.blob(encodedSignaturesLength.length, 'encodedSignaturesLength'), BufferLayout__namespace.seq(signature(), this.signatures.length, 'signatures'), BufferLayout__namespace.blob(serializedMessage.length, 'serializedMessage')]);
|
|
1681
|
+
const serializedTransaction = new Uint8Array(2048);
|
|
1682
|
+
const serializedTransactionLength = transactionLayout.encode({
|
|
1683
|
+
encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
|
|
1684
|
+
signatures: this.signatures,
|
|
1685
|
+
serializedMessage
|
|
1686
|
+
}, serializedTransaction);
|
|
1687
|
+
return serializedTransaction.slice(0, serializedTransactionLength);
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
static deserialize(serializedTransaction) {
|
|
1691
|
+
let byteArray = [...serializedTransaction];
|
|
1692
|
+
const signatures = [];
|
|
1693
|
+
const signaturesLength = decodeLength(byteArray);
|
|
1694
|
+
|
|
1695
|
+
for (let i = 0; i < signaturesLength; i++) {
|
|
1696
|
+
signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1700
|
+
return new VersionedTransaction(message, signatures);
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
sign(signers) {
|
|
1704
|
+
const messageData = this.message.serialize();
|
|
1705
|
+
const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
|
|
1706
|
+
|
|
1707
|
+
for (const signer of signers) {
|
|
1708
|
+
const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
|
|
1709
|
+
assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
|
|
1710
|
+
this.signatures[signerIndex] = sign(messageData, signer.secretKey);
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
}
|
|
1715
|
+
|
|
3133
1716
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
3134
1717
|
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
3135
1718
|
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
@@ -4523,24 +3106,26 @@ const LookupTableMetaLayout = {
|
|
|
4523
3106
|
BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
|
|
4524
3107
|
};
|
|
4525
3108
|
|
|
4526
|
-
const
|
|
4527
|
-
|
|
3109
|
+
const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
|
|
4528
3110
|
function makeWebsocketUrl(endpoint) {
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
3111
|
+
const matches = endpoint.match(URL_RE);
|
|
3112
|
+
|
|
3113
|
+
if (matches == null) {
|
|
3114
|
+
throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3117
|
+
const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3118
|
+
hostish, portWithColon, rest] = matches;
|
|
3119
|
+
const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
|
|
3120
|
+
const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
|
|
3121
|
+
const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
4533
3122
|
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
4534
3123
|
// we're directly trying to connect to solana-validator's ws listening port.
|
|
4535
3124
|
// When the endpoint omits the port, we're connecting to the protocol
|
|
4536
3125
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
4537
3126
|
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
url.port = String(Number(url.port) + 1);
|
|
4541
|
-
}
|
|
4542
|
-
|
|
4543
|
-
return url.toString();
|
|
3127
|
+
startPort == null ? '' : `:${startPort + 1}`;
|
|
3128
|
+
return `${protocol}//${hostish}${websocketPort}${rest}`;
|
|
4544
3129
|
}
|
|
4545
3130
|
|
|
4546
3131
|
var _process$env$npm_pack;
|
|
@@ -4560,7 +3145,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
|
|
|
4560
3145
|
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
|
|
4561
3146
|
*/
|
|
4562
3147
|
|
|
3148
|
+
/* @internal */
|
|
3149
|
+
function assertEndpointUrl(putativeUrl) {
|
|
3150
|
+
if (/^https?:/.test(putativeUrl) === false) {
|
|
3151
|
+
throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
return putativeUrl;
|
|
3155
|
+
}
|
|
4563
3156
|
/** @internal */
|
|
3157
|
+
|
|
3158
|
+
|
|
4564
3159
|
function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
4565
3160
|
let commitment;
|
|
4566
3161
|
let config;
|
|
@@ -4755,7 +3350,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
|
|
|
4755
3350
|
* A performance sample
|
|
4756
3351
|
*/
|
|
4757
3352
|
|
|
4758
|
-
function createRpcClient(url,
|
|
3353
|
+
function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
|
|
4759
3354
|
const fetch = customFetch ? customFetch : fetchImpl;
|
|
4760
3355
|
|
|
4761
3356
|
let fetchWithMiddleware;
|
|
@@ -5561,8 +4156,6 @@ class Connection {
|
|
|
5561
4156
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
5562
4157
|
this._subscriptionsByHash = {};
|
|
5563
4158
|
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
5564
|
-
let url = new URL(endpoint);
|
|
5565
|
-
const useHttps = url.protocol === 'https:';
|
|
5566
4159
|
let wsEndpoint;
|
|
5567
4160
|
let httpHeaders;
|
|
5568
4161
|
let fetch;
|
|
@@ -5581,9 +4174,9 @@ class Connection {
|
|
|
5581
4174
|
disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
|
|
5582
4175
|
}
|
|
5583
4176
|
|
|
5584
|
-
this._rpcEndpoint = endpoint;
|
|
4177
|
+
this._rpcEndpoint = assertEndpointUrl(endpoint);
|
|
5585
4178
|
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
5586
|
-
this._rpcClient = createRpcClient(
|
|
4179
|
+
this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
|
|
5587
4180
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
5588
4181
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
5589
4182
|
this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
|
|
@@ -8260,12 +6853,7 @@ class Keypair {
|
|
|
8260
6853
|
*/
|
|
8261
6854
|
constructor(keypair) {
|
|
8262
6855
|
this._keypair = void 0;
|
|
8263
|
-
|
|
8264
|
-
if (keypair) {
|
|
8265
|
-
this._keypair = keypair;
|
|
8266
|
-
} else {
|
|
8267
|
-
this._keypair = nacl__default["default"].sign.keyPair();
|
|
8268
|
-
}
|
|
6856
|
+
this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
|
|
8269
6857
|
}
|
|
8270
6858
|
/**
|
|
8271
6859
|
* Generate a new random keypair
|
|
@@ -8273,7 +6861,7 @@ class Keypair {
|
|
|
8273
6861
|
|
|
8274
6862
|
|
|
8275
6863
|
static generate() {
|
|
8276
|
-
return new Keypair(
|
|
6864
|
+
return new Keypair(generateKeypair());
|
|
8277
6865
|
}
|
|
8278
6866
|
/**
|
|
8279
6867
|
* Create a keypair from a raw secret key byte array.
|
|
@@ -8290,19 +6878,27 @@ class Keypair {
|
|
|
8290
6878
|
|
|
8291
6879
|
|
|
8292
6880
|
static fromSecretKey(secretKey, options) {
|
|
8293
|
-
|
|
6881
|
+
if (secretKey.byteLength !== 64) {
|
|
6882
|
+
throw new Error('bad secret key size');
|
|
6883
|
+
}
|
|
6884
|
+
|
|
6885
|
+
const publicKey = secretKey.slice(32, 64);
|
|
8294
6886
|
|
|
8295
6887
|
if (!options || !options.skipValidation) {
|
|
8296
|
-
const
|
|
8297
|
-
const
|
|
8298
|
-
const signature = nacl__default["default"].sign.detached(signData, keypair.secretKey);
|
|
6888
|
+
const privateScalar = secretKey.slice(0, 32);
|
|
6889
|
+
const computedPublicKey = getPublicKey(privateScalar);
|
|
8299
6890
|
|
|
8300
|
-
|
|
8301
|
-
|
|
6891
|
+
for (let ii = 0; ii < 32; ii++) {
|
|
6892
|
+
if (publicKey[ii] !== computedPublicKey[ii]) {
|
|
6893
|
+
throw new Error('provided secretKey is invalid');
|
|
6894
|
+
}
|
|
8302
6895
|
}
|
|
8303
6896
|
}
|
|
8304
6897
|
|
|
8305
|
-
return new Keypair(
|
|
6898
|
+
return new Keypair({
|
|
6899
|
+
publicKey,
|
|
6900
|
+
secretKey
|
|
6901
|
+
});
|
|
8306
6902
|
}
|
|
8307
6903
|
/**
|
|
8308
6904
|
* Generate a keypair from a 32 byte seed.
|
|
@@ -8312,7 +6908,14 @@ class Keypair {
|
|
|
8312
6908
|
|
|
8313
6909
|
|
|
8314
6910
|
static fromSeed(seed) {
|
|
8315
|
-
|
|
6911
|
+
const publicKey = getPublicKey(seed);
|
|
6912
|
+
const secretKey = new Uint8Array(64);
|
|
6913
|
+
secretKey.set(seed);
|
|
6914
|
+
secretKey.set(publicKey, 32);
|
|
6915
|
+
return new Keypair({
|
|
6916
|
+
publicKey,
|
|
6917
|
+
secretKey
|
|
6918
|
+
});
|
|
8316
6919
|
}
|
|
8317
6920
|
/**
|
|
8318
6921
|
* The public key for this keypair
|
|
@@ -8864,7 +7467,7 @@ class Ed25519Program {
|
|
|
8864
7467
|
try {
|
|
8865
7468
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
8866
7469
|
const publicKey = keypair.publicKey.toBytes();
|
|
8867
|
-
const signature =
|
|
7470
|
+
const signature = sign(message, keypair.secretKey);
|
|
8868
7471
|
return this.createInstructionWithPublicKey({
|
|
8869
7472
|
publicKey,
|
|
8870
7473
|
message,
|
|
@@ -8879,10 +7482,21 @@ class Ed25519Program {
|
|
|
8879
7482
|
}
|
|
8880
7483
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
8881
7484
|
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
7485
|
+
// library interoperable with the synchronous APIs in web3.js.
|
|
7486
|
+
|
|
7487
|
+
secp256k1__namespace.utils.hmacSha256Sync = (key, ...msgs) => {
|
|
7488
|
+
const h = hmac.hmac.create(sha256.sha256, key);
|
|
7489
|
+
msgs.forEach(msg => h.update(msg));
|
|
7490
|
+
return h.digest();
|
|
7491
|
+
};
|
|
7492
|
+
|
|
7493
|
+
const ecdsaSign = (msgHash, privKey) => secp256k1__namespace.signSync(msgHash, privKey, {
|
|
7494
|
+
der: false,
|
|
7495
|
+
recovered: true
|
|
7496
|
+
});
|
|
7497
|
+
secp256k1__namespace.utils.isValidPrivateKey;
|
|
7498
|
+
const publicKeyCreate = secp256k1__namespace.getPublicKey;
|
|
7499
|
+
|
|
8886
7500
|
const PRIVATE_KEY_BYTES = 32;
|
|
8887
7501
|
const ETHEREUM_ADDRESS_BYTES = 20;
|
|
8888
7502
|
const PUBLIC_KEY_BYTES = 64;
|
|
@@ -9006,13 +7620,12 @@ class Secp256k1Program {
|
|
|
9006
7620
|
|
|
9007
7621
|
try {
|
|
9008
7622
|
const privateKey = toBuffer(pkey);
|
|
9009
|
-
const publicKey = publicKeyCreate(privateKey, false
|
|
7623
|
+
const publicKey = publicKeyCreate(privateKey, false
|
|
7624
|
+
/* isCompressed */
|
|
7625
|
+
).slice(1); // throw away leading byte
|
|
9010
7626
|
|
|
9011
7627
|
const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
|
|
9012
|
-
const
|
|
9013
|
-
signature,
|
|
9014
|
-
recid: recoveryId
|
|
9015
|
-
} = ecdsaSign(messageHash, privateKey);
|
|
7628
|
+
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
9016
7629
|
return this.createInstructionWithPublicKey({
|
|
9017
7630
|
publicKey,
|
|
9018
7631
|
message,
|
|
@@ -10124,6 +8737,23 @@ class VoteProgram {
|
|
|
10124
8737
|
data
|
|
10125
8738
|
});
|
|
10126
8739
|
}
|
|
8740
|
+
/**
|
|
8741
|
+
* Generate a transaction to withdraw safely from a Vote account.
|
|
8742
|
+
*
|
|
8743
|
+
* This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
|
|
8744
|
+
* checks that the withdraw amount will not exceed the specified balance while leaving enough left
|
|
8745
|
+
* to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
|
|
8746
|
+
* `withdraw` method directly.
|
|
8747
|
+
*/
|
|
8748
|
+
|
|
8749
|
+
|
|
8750
|
+
static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
|
|
8751
|
+
if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
|
|
8752
|
+
throw new Error('Withdraw will leave vote account with insuffcient funds.');
|
|
8753
|
+
}
|
|
8754
|
+
|
|
8755
|
+
return VoteProgram.withdraw(params);
|
|
8756
|
+
}
|
|
10127
8757
|
|
|
10128
8758
|
}
|
|
10129
8759
|
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
@@ -10175,15 +8805,14 @@ class ValidatorInfo {
|
|
|
10175
8805
|
|
|
10176
8806
|
|
|
10177
8807
|
static fromConfigData(buffer$1) {
|
|
10178
|
-
const PUBKEY_LENGTH = 32;
|
|
10179
8808
|
let byteArray = [...buffer$1];
|
|
10180
8809
|
const configKeyCount = decodeLength(byteArray);
|
|
10181
8810
|
if (configKeyCount !== 2) return null;
|
|
10182
8811
|
const configKeys = [];
|
|
10183
8812
|
|
|
10184
8813
|
for (let i = 0; i < 2; i++) {
|
|
10185
|
-
const publicKey = new PublicKey(byteArray.slice(0,
|
|
10186
|
-
byteArray = byteArray.slice(
|
|
8814
|
+
const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
|
|
8815
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
10187
8816
|
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10188
8817
|
byteArray = byteArray.slice(1);
|
|
10189
8818
|
configKeys.push({
|
|
@@ -10419,9 +9048,11 @@ exports.Loader = Loader;
|
|
|
10419
9048
|
exports.Lockup = Lockup;
|
|
10420
9049
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|
|
10421
9050
|
exports.Message = Message;
|
|
9051
|
+
exports.MessageV0 = MessageV0;
|
|
10422
9052
|
exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
10423
9053
|
exports.NonceAccount = NonceAccount;
|
|
10424
9054
|
exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
|
|
9055
|
+
exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
|
|
10425
9056
|
exports.PublicKey = PublicKey;
|
|
10426
9057
|
exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
|
|
10427
9058
|
exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
|
|
@@ -10452,8 +9083,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
|
|
|
10452
9083
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
10453
9084
|
exports.TransactionInstruction = TransactionInstruction;
|
|
10454
9085
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
9086
|
+
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
10455
9087
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
10456
9088
|
exports.ValidatorInfo = ValidatorInfo;
|
|
9089
|
+
exports.VersionedMessage = VersionedMessage;
|
|
9090
|
+
exports.VersionedTransaction = VersionedTransaction;
|
|
10457
9091
|
exports.VoteAccount = VoteAccount;
|
|
10458
9092
|
exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
|
|
10459
9093
|
exports.VoteInit = VoteInit;
|