@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.cjs.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var nacl = require('tweetnacl');
|
|
6
5
|
var buffer = require('buffer');
|
|
6
|
+
var sha512 = require('@noble/hashes/sha512');
|
|
7
|
+
var ed25519 = require('@noble/ed25519');
|
|
7
8
|
var BN = require('bn.js');
|
|
8
9
|
var bs58 = require('bs58');
|
|
10
|
+
var sha256 = require('@noble/hashes/sha256');
|
|
9
11
|
var borsh = require('borsh');
|
|
10
12
|
var BufferLayout = require('@solana/buffer-layout');
|
|
11
13
|
var bigintBuffer = require('bigint-buffer');
|
|
@@ -15,8 +17,9 @@ var RpcClient = require('jayson/lib/client/browser');
|
|
|
15
17
|
var http = require('http');
|
|
16
18
|
var https = require('https');
|
|
17
19
|
var nodeFetch = require('node-fetch');
|
|
18
|
-
var secp256k1 = require('secp256k1');
|
|
19
20
|
var sha3 = require('js-sha3');
|
|
21
|
+
var hmac = require('@noble/hashes/hmac');
|
|
22
|
+
var secp256k1 = require('@noble/secp256k1');
|
|
20
23
|
|
|
21
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
25
|
|
|
@@ -38,7 +41,7 @@ function _interopNamespace(e) {
|
|
|
38
41
|
return Object.freeze(n);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
var
|
|
44
|
+
var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
|
|
42
45
|
var BN__default = /*#__PURE__*/_interopDefaultLegacy(BN);
|
|
43
46
|
var bs58__default = /*#__PURE__*/_interopDefaultLegacy(bs58);
|
|
44
47
|
var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
|
|
@@ -46,1745 +49,53 @@ var RpcClient__default = /*#__PURE__*/_interopDefaultLegacy(RpcClient);
|
|
|
46
49
|
var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
47
50
|
var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
48
51
|
var nodeFetch__namespace = /*#__PURE__*/_interopNamespace(nodeFetch);
|
|
49
|
-
var secp256k1__default = /*#__PURE__*/_interopDefaultLegacy(secp256k1);
|
|
50
52
|
var sha3__default = /*#__PURE__*/_interopDefaultLegacy(sha3);
|
|
53
|
+
var secp256k1__namespace = /*#__PURE__*/_interopNamespace(secp256k1);
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
return buffer.Buffer.from(arr);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
var hash$1 = {};
|
|
63
|
-
|
|
64
|
-
var utils$9 = {};
|
|
65
|
-
|
|
66
|
-
var minimalisticAssert = assert$6;
|
|
55
|
+
/**
|
|
56
|
+
* A 64 byte secret key, the first 32 bytes of which is the
|
|
57
|
+
* private scalar and the last 32 bytes is the public key.
|
|
58
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
59
|
+
*/
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
if (!val)
|
|
70
|
-
throw new Error(msg || 'Assertion failed');
|
|
71
|
-
}
|
|
61
|
+
ed25519__namespace.utils.sha512Sync = (...m) => sha512.sha512(ed25519__namespace.utils.concatBytes(...m));
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const generatePrivateKey = ed25519__namespace.utils.randomPrivateKey;
|
|
64
|
+
const generateKeypair = () => {
|
|
65
|
+
const privateScalar = ed25519__namespace.utils.randomPrivateKey();
|
|
66
|
+
const publicKey = getPublicKey(privateScalar);
|
|
67
|
+
const secretKey = new Uint8Array(64);
|
|
68
|
+
secretKey.set(privateScalar);
|
|
69
|
+
secretKey.set(publicKey, 32);
|
|
70
|
+
return {
|
|
71
|
+
publicKey,
|
|
72
|
+
secretKey
|
|
73
|
+
};
|
|
76
74
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (hasRequiredInherits_browser) return inherits_browser.exports;
|
|
86
|
-
hasRequiredInherits_browser = 1;
|
|
87
|
-
if (typeof Object.create === 'function') {
|
|
88
|
-
// implementation from standard node.js 'util' module
|
|
89
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
90
|
-
if (superCtor) {
|
|
91
|
-
ctor.super_ = superCtor;
|
|
92
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
93
|
-
constructor: {
|
|
94
|
-
value: ctor,
|
|
95
|
-
enumerable: false,
|
|
96
|
-
writable: true,
|
|
97
|
-
configurable: true
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
} else {
|
|
103
|
-
// old school shim for old browsers
|
|
104
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
105
|
-
if (superCtor) {
|
|
106
|
-
ctor.super_ = superCtor;
|
|
107
|
-
var TempCtor = function () {};
|
|
108
|
-
TempCtor.prototype = superCtor.prototype;
|
|
109
|
-
ctor.prototype = new TempCtor();
|
|
110
|
-
ctor.prototype.constructor = ctor;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return inherits_browser.exports;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
(function (module) {
|
|
118
|
-
try {
|
|
119
|
-
var util = require('util');
|
|
120
|
-
/* istanbul ignore next */
|
|
121
|
-
if (typeof util.inherits !== 'function') throw '';
|
|
122
|
-
module.exports = util.inherits;
|
|
123
|
-
} catch (e) {
|
|
124
|
-
/* istanbul ignore next */
|
|
125
|
-
module.exports = requireInherits_browser();
|
|
126
|
-
}
|
|
127
|
-
} (inherits$1));
|
|
128
|
-
|
|
129
|
-
var assert$5 = minimalisticAssert;
|
|
130
|
-
var inherits = inherits$1.exports;
|
|
131
|
-
|
|
132
|
-
utils$9.inherits = inherits;
|
|
133
|
-
|
|
134
|
-
function isSurrogatePair(msg, i) {
|
|
135
|
-
if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
if (i < 0 || i + 1 >= msg.length) {
|
|
75
|
+
const getPublicKey = ed25519__namespace.sync.getPublicKey;
|
|
76
|
+
function isOnCurve(publicKey) {
|
|
77
|
+
try {
|
|
78
|
+
ed25519__namespace.Point.fromHex(publicKey, true
|
|
79
|
+
/* strict */
|
|
80
|
+
);
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
139
83
|
return false;
|
|
140
84
|
}
|
|
141
|
-
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function toArray(msg, enc) {
|
|
145
|
-
if (Array.isArray(msg))
|
|
146
|
-
return msg.slice();
|
|
147
|
-
if (!msg)
|
|
148
|
-
return [];
|
|
149
|
-
var res = [];
|
|
150
|
-
if (typeof msg === 'string') {
|
|
151
|
-
if (!enc) {
|
|
152
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
153
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
154
|
-
// Apache License 2.0
|
|
155
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
156
|
-
var p = 0;
|
|
157
|
-
for (var i = 0; i < msg.length; i++) {
|
|
158
|
-
var c = msg.charCodeAt(i);
|
|
159
|
-
if (c < 128) {
|
|
160
|
-
res[p++] = c;
|
|
161
|
-
} else if (c < 2048) {
|
|
162
|
-
res[p++] = (c >> 6) | 192;
|
|
163
|
-
res[p++] = (c & 63) | 128;
|
|
164
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
165
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
166
|
-
res[p++] = (c >> 18) | 240;
|
|
167
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
168
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
169
|
-
res[p++] = (c & 63) | 128;
|
|
170
|
-
} else {
|
|
171
|
-
res[p++] = (c >> 12) | 224;
|
|
172
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
173
|
-
res[p++] = (c & 63) | 128;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
} else if (enc === 'hex') {
|
|
177
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
178
|
-
if (msg.length % 2 !== 0)
|
|
179
|
-
msg = '0' + msg;
|
|
180
|
-
for (i = 0; i < msg.length; i += 2)
|
|
181
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
for (i = 0; i < msg.length; i++)
|
|
185
|
-
res[i] = msg[i] | 0;
|
|
186
|
-
}
|
|
187
|
-
return res;
|
|
188
|
-
}
|
|
189
|
-
utils$9.toArray = toArray;
|
|
190
|
-
|
|
191
|
-
function toHex(msg) {
|
|
192
|
-
var res = '';
|
|
193
|
-
for (var i = 0; i < msg.length; i++)
|
|
194
|
-
res += zero2(msg[i].toString(16));
|
|
195
|
-
return res;
|
|
196
|
-
}
|
|
197
|
-
utils$9.toHex = toHex;
|
|
198
|
-
|
|
199
|
-
function htonl(w) {
|
|
200
|
-
var res = (w >>> 24) |
|
|
201
|
-
((w >>> 8) & 0xff00) |
|
|
202
|
-
((w << 8) & 0xff0000) |
|
|
203
|
-
((w & 0xff) << 24);
|
|
204
|
-
return res >>> 0;
|
|
205
|
-
}
|
|
206
|
-
utils$9.htonl = htonl;
|
|
207
|
-
|
|
208
|
-
function toHex32(msg, endian) {
|
|
209
|
-
var res = '';
|
|
210
|
-
for (var i = 0; i < msg.length; i++) {
|
|
211
|
-
var w = msg[i];
|
|
212
|
-
if (endian === 'little')
|
|
213
|
-
w = htonl(w);
|
|
214
|
-
res += zero8(w.toString(16));
|
|
215
|
-
}
|
|
216
|
-
return res;
|
|
217
|
-
}
|
|
218
|
-
utils$9.toHex32 = toHex32;
|
|
219
|
-
|
|
220
|
-
function zero2(word) {
|
|
221
|
-
if (word.length === 1)
|
|
222
|
-
return '0' + word;
|
|
223
|
-
else
|
|
224
|
-
return word;
|
|
225
|
-
}
|
|
226
|
-
utils$9.zero2 = zero2;
|
|
227
|
-
|
|
228
|
-
function zero8(word) {
|
|
229
|
-
if (word.length === 7)
|
|
230
|
-
return '0' + word;
|
|
231
|
-
else if (word.length === 6)
|
|
232
|
-
return '00' + word;
|
|
233
|
-
else if (word.length === 5)
|
|
234
|
-
return '000' + word;
|
|
235
|
-
else if (word.length === 4)
|
|
236
|
-
return '0000' + word;
|
|
237
|
-
else if (word.length === 3)
|
|
238
|
-
return '00000' + word;
|
|
239
|
-
else if (word.length === 2)
|
|
240
|
-
return '000000' + word;
|
|
241
|
-
else if (word.length === 1)
|
|
242
|
-
return '0000000' + word;
|
|
243
|
-
else
|
|
244
|
-
return word;
|
|
245
|
-
}
|
|
246
|
-
utils$9.zero8 = zero8;
|
|
247
|
-
|
|
248
|
-
function join32(msg, start, end, endian) {
|
|
249
|
-
var len = end - start;
|
|
250
|
-
assert$5(len % 4 === 0);
|
|
251
|
-
var res = new Array(len / 4);
|
|
252
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
253
|
-
var w;
|
|
254
|
-
if (endian === 'big')
|
|
255
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
256
|
-
else
|
|
257
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
258
|
-
res[i] = w >>> 0;
|
|
259
|
-
}
|
|
260
|
-
return res;
|
|
261
|
-
}
|
|
262
|
-
utils$9.join32 = join32;
|
|
263
|
-
|
|
264
|
-
function split32(msg, endian) {
|
|
265
|
-
var res = new Array(msg.length * 4);
|
|
266
|
-
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
267
|
-
var m = msg[i];
|
|
268
|
-
if (endian === 'big') {
|
|
269
|
-
res[k] = m >>> 24;
|
|
270
|
-
res[k + 1] = (m >>> 16) & 0xff;
|
|
271
|
-
res[k + 2] = (m >>> 8) & 0xff;
|
|
272
|
-
res[k + 3] = m & 0xff;
|
|
273
|
-
} else {
|
|
274
|
-
res[k + 3] = m >>> 24;
|
|
275
|
-
res[k + 2] = (m >>> 16) & 0xff;
|
|
276
|
-
res[k + 1] = (m >>> 8) & 0xff;
|
|
277
|
-
res[k] = m & 0xff;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return res;
|
|
281
|
-
}
|
|
282
|
-
utils$9.split32 = split32;
|
|
283
|
-
|
|
284
|
-
function rotr32$1(w, b) {
|
|
285
|
-
return (w >>> b) | (w << (32 - b));
|
|
286
|
-
}
|
|
287
|
-
utils$9.rotr32 = rotr32$1;
|
|
288
|
-
|
|
289
|
-
function rotl32$2(w, b) {
|
|
290
|
-
return (w << b) | (w >>> (32 - b));
|
|
291
|
-
}
|
|
292
|
-
utils$9.rotl32 = rotl32$2;
|
|
293
|
-
|
|
294
|
-
function sum32$3(a, b) {
|
|
295
|
-
return (a + b) >>> 0;
|
|
296
|
-
}
|
|
297
|
-
utils$9.sum32 = sum32$3;
|
|
298
|
-
|
|
299
|
-
function sum32_3$1(a, b, c) {
|
|
300
|
-
return (a + b + c) >>> 0;
|
|
301
|
-
}
|
|
302
|
-
utils$9.sum32_3 = sum32_3$1;
|
|
303
|
-
|
|
304
|
-
function sum32_4$2(a, b, c, d) {
|
|
305
|
-
return (a + b + c + d) >>> 0;
|
|
306
|
-
}
|
|
307
|
-
utils$9.sum32_4 = sum32_4$2;
|
|
308
|
-
|
|
309
|
-
function sum32_5$2(a, b, c, d, e) {
|
|
310
|
-
return (a + b + c + d + e) >>> 0;
|
|
311
|
-
}
|
|
312
|
-
utils$9.sum32_5 = sum32_5$2;
|
|
313
|
-
|
|
314
|
-
function sum64$1(buf, pos, ah, al) {
|
|
315
|
-
var bh = buf[pos];
|
|
316
|
-
var bl = buf[pos + 1];
|
|
317
|
-
|
|
318
|
-
var lo = (al + bl) >>> 0;
|
|
319
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
320
|
-
buf[pos] = hi >>> 0;
|
|
321
|
-
buf[pos + 1] = lo;
|
|
322
|
-
}
|
|
323
|
-
utils$9.sum64 = sum64$1;
|
|
324
|
-
|
|
325
|
-
function sum64_hi$1(ah, al, bh, bl) {
|
|
326
|
-
var lo = (al + bl) >>> 0;
|
|
327
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
328
|
-
return hi >>> 0;
|
|
329
85
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
function sum64_lo$1(ah, al, bh, bl) {
|
|
333
|
-
var lo = al + bl;
|
|
334
|
-
return lo >>> 0;
|
|
335
|
-
}
|
|
336
|
-
utils$9.sum64_lo = sum64_lo$1;
|
|
337
|
-
|
|
338
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
339
|
-
var carry = 0;
|
|
340
|
-
var lo = al;
|
|
341
|
-
lo = (lo + bl) >>> 0;
|
|
342
|
-
carry += lo < al ? 1 : 0;
|
|
343
|
-
lo = (lo + cl) >>> 0;
|
|
344
|
-
carry += lo < cl ? 1 : 0;
|
|
345
|
-
lo = (lo + dl) >>> 0;
|
|
346
|
-
carry += lo < dl ? 1 : 0;
|
|
347
|
-
|
|
348
|
-
var hi = ah + bh + ch + dh + carry;
|
|
349
|
-
return hi >>> 0;
|
|
350
|
-
}
|
|
351
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
352
|
-
|
|
353
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
354
|
-
var lo = al + bl + cl + dl;
|
|
355
|
-
return lo >>> 0;
|
|
356
|
-
}
|
|
357
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
358
|
-
|
|
359
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
360
|
-
var carry = 0;
|
|
361
|
-
var lo = al;
|
|
362
|
-
lo = (lo + bl) >>> 0;
|
|
363
|
-
carry += lo < al ? 1 : 0;
|
|
364
|
-
lo = (lo + cl) >>> 0;
|
|
365
|
-
carry += lo < cl ? 1 : 0;
|
|
366
|
-
lo = (lo + dl) >>> 0;
|
|
367
|
-
carry += lo < dl ? 1 : 0;
|
|
368
|
-
lo = (lo + el) >>> 0;
|
|
369
|
-
carry += lo < el ? 1 : 0;
|
|
370
|
-
|
|
371
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
372
|
-
return hi >>> 0;
|
|
373
|
-
}
|
|
374
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
375
|
-
|
|
376
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
377
|
-
var lo = al + bl + cl + dl + el;
|
|
378
|
-
|
|
379
|
-
return lo >>> 0;
|
|
380
|
-
}
|
|
381
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
382
|
-
|
|
383
|
-
function rotr64_hi$1(ah, al, num) {
|
|
384
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
385
|
-
return r >>> 0;
|
|
386
|
-
}
|
|
387
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
388
|
-
|
|
389
|
-
function rotr64_lo$1(ah, al, num) {
|
|
390
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
391
|
-
return r >>> 0;
|
|
392
|
-
}
|
|
393
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
394
|
-
|
|
395
|
-
function shr64_hi$1(ah, al, num) {
|
|
396
|
-
return ah >>> num;
|
|
397
|
-
}
|
|
398
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
399
|
-
|
|
400
|
-
function shr64_lo$1(ah, al, num) {
|
|
401
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
402
|
-
return r >>> 0;
|
|
403
|
-
}
|
|
404
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
405
|
-
|
|
406
|
-
var common$5 = {};
|
|
407
|
-
|
|
408
|
-
var utils$8 = utils$9;
|
|
409
|
-
var assert$4 = minimalisticAssert;
|
|
410
|
-
|
|
411
|
-
function BlockHash$4() {
|
|
412
|
-
this.pending = null;
|
|
413
|
-
this.pendingTotal = 0;
|
|
414
|
-
this.blockSize = this.constructor.blockSize;
|
|
415
|
-
this.outSize = this.constructor.outSize;
|
|
416
|
-
this.hmacStrength = this.constructor.hmacStrength;
|
|
417
|
-
this.padLength = this.constructor.padLength / 8;
|
|
418
|
-
this.endian = 'big';
|
|
419
|
-
|
|
420
|
-
this._delta8 = this.blockSize / 8;
|
|
421
|
-
this._delta32 = this.blockSize / 32;
|
|
422
|
-
}
|
|
423
|
-
common$5.BlockHash = BlockHash$4;
|
|
424
|
-
|
|
425
|
-
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
426
|
-
// Convert message to array, pad it, and join into 32bit blocks
|
|
427
|
-
msg = utils$8.toArray(msg, enc);
|
|
428
|
-
if (!this.pending)
|
|
429
|
-
this.pending = msg;
|
|
430
|
-
else
|
|
431
|
-
this.pending = this.pending.concat(msg);
|
|
432
|
-
this.pendingTotal += msg.length;
|
|
86
|
+
const sign = (message, secretKey) => ed25519__namespace.sync.sign(message, secretKey.slice(0, 32));
|
|
87
|
+
const verify = ed25519__namespace.sync.verify;
|
|
433
88
|
|
|
434
|
-
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
var r = msg.length % this._delta8;
|
|
440
|
-
this.pending = msg.slice(msg.length - r, msg.length);
|
|
441
|
-
if (this.pending.length === 0)
|
|
442
|
-
this.pending = null;
|
|
443
|
-
|
|
444
|
-
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
445
|
-
for (var i = 0; i < msg.length; i += this._delta32)
|
|
446
|
-
this._update(msg, i, i + this._delta32);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return this;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
BlockHash$4.prototype.digest = function digest(enc) {
|
|
453
|
-
this.update(this._pad());
|
|
454
|
-
assert$4(this.pending === null);
|
|
455
|
-
|
|
456
|
-
return this._digest(enc);
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
BlockHash$4.prototype._pad = function pad() {
|
|
460
|
-
var len = this.pendingTotal;
|
|
461
|
-
var bytes = this._delta8;
|
|
462
|
-
var k = bytes - ((len + this.padLength) % bytes);
|
|
463
|
-
var res = new Array(k + this.padLength);
|
|
464
|
-
res[0] = 0x80;
|
|
465
|
-
for (var i = 1; i < k; i++)
|
|
466
|
-
res[i] = 0;
|
|
467
|
-
|
|
468
|
-
// Append length
|
|
469
|
-
len <<= 3;
|
|
470
|
-
if (this.endian === 'big') {
|
|
471
|
-
for (var t = 8; t < this.padLength; t++)
|
|
472
|
-
res[i++] = 0;
|
|
473
|
-
|
|
474
|
-
res[i++] = 0;
|
|
475
|
-
res[i++] = 0;
|
|
476
|
-
res[i++] = 0;
|
|
477
|
-
res[i++] = 0;
|
|
478
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
479
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
480
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
481
|
-
res[i++] = len & 0xff;
|
|
89
|
+
const toBuffer = arr => {
|
|
90
|
+
if (buffer.Buffer.isBuffer(arr)) {
|
|
91
|
+
return arr;
|
|
92
|
+
} else if (arr instanceof Uint8Array) {
|
|
93
|
+
return buffer.Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
482
94
|
} else {
|
|
483
|
-
|
|
484
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
485
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
486
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
487
|
-
res[i++] = 0;
|
|
488
|
-
res[i++] = 0;
|
|
489
|
-
res[i++] = 0;
|
|
490
|
-
res[i++] = 0;
|
|
491
|
-
|
|
492
|
-
for (t = 8; t < this.padLength; t++)
|
|
493
|
-
res[i++] = 0;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return res;
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
var sha = {};
|
|
500
|
-
|
|
501
|
-
var common$4 = {};
|
|
502
|
-
|
|
503
|
-
var utils$7 = utils$9;
|
|
504
|
-
var rotr32 = utils$7.rotr32;
|
|
505
|
-
|
|
506
|
-
function ft_1$1(s, x, y, z) {
|
|
507
|
-
if (s === 0)
|
|
508
|
-
return ch32$1(x, y, z);
|
|
509
|
-
if (s === 1 || s === 3)
|
|
510
|
-
return p32(x, y, z);
|
|
511
|
-
if (s === 2)
|
|
512
|
-
return maj32$1(x, y, z);
|
|
513
|
-
}
|
|
514
|
-
common$4.ft_1 = ft_1$1;
|
|
515
|
-
|
|
516
|
-
function ch32$1(x, y, z) {
|
|
517
|
-
return (x & y) ^ ((~x) & z);
|
|
518
|
-
}
|
|
519
|
-
common$4.ch32 = ch32$1;
|
|
520
|
-
|
|
521
|
-
function maj32$1(x, y, z) {
|
|
522
|
-
return (x & y) ^ (x & z) ^ (y & z);
|
|
523
|
-
}
|
|
524
|
-
common$4.maj32 = maj32$1;
|
|
525
|
-
|
|
526
|
-
function p32(x, y, z) {
|
|
527
|
-
return x ^ y ^ z;
|
|
528
|
-
}
|
|
529
|
-
common$4.p32 = p32;
|
|
530
|
-
|
|
531
|
-
function s0_256$1(x) {
|
|
532
|
-
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
533
|
-
}
|
|
534
|
-
common$4.s0_256 = s0_256$1;
|
|
535
|
-
|
|
536
|
-
function s1_256$1(x) {
|
|
537
|
-
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
538
|
-
}
|
|
539
|
-
common$4.s1_256 = s1_256$1;
|
|
540
|
-
|
|
541
|
-
function g0_256$1(x) {
|
|
542
|
-
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
543
|
-
}
|
|
544
|
-
common$4.g0_256 = g0_256$1;
|
|
545
|
-
|
|
546
|
-
function g1_256$1(x) {
|
|
547
|
-
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
548
|
-
}
|
|
549
|
-
common$4.g1_256 = g1_256$1;
|
|
550
|
-
|
|
551
|
-
var utils$6 = utils$9;
|
|
552
|
-
var common$3 = common$5;
|
|
553
|
-
var shaCommon$1 = common$4;
|
|
554
|
-
|
|
555
|
-
var rotl32$1 = utils$6.rotl32;
|
|
556
|
-
var sum32$2 = utils$6.sum32;
|
|
557
|
-
var sum32_5$1 = utils$6.sum32_5;
|
|
558
|
-
var ft_1 = shaCommon$1.ft_1;
|
|
559
|
-
var BlockHash$3 = common$3.BlockHash;
|
|
560
|
-
|
|
561
|
-
var sha1_K = [
|
|
562
|
-
0x5A827999, 0x6ED9EBA1,
|
|
563
|
-
0x8F1BBCDC, 0xCA62C1D6
|
|
564
|
-
];
|
|
565
|
-
|
|
566
|
-
function SHA1() {
|
|
567
|
-
if (!(this instanceof SHA1))
|
|
568
|
-
return new SHA1();
|
|
569
|
-
|
|
570
|
-
BlockHash$3.call(this);
|
|
571
|
-
this.h = [
|
|
572
|
-
0x67452301, 0xefcdab89, 0x98badcfe,
|
|
573
|
-
0x10325476, 0xc3d2e1f0 ];
|
|
574
|
-
this.W = new Array(80);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
utils$6.inherits(SHA1, BlockHash$3);
|
|
578
|
-
var _1 = SHA1;
|
|
579
|
-
|
|
580
|
-
SHA1.blockSize = 512;
|
|
581
|
-
SHA1.outSize = 160;
|
|
582
|
-
SHA1.hmacStrength = 80;
|
|
583
|
-
SHA1.padLength = 64;
|
|
584
|
-
|
|
585
|
-
SHA1.prototype._update = function _update(msg, start) {
|
|
586
|
-
var W = this.W;
|
|
587
|
-
|
|
588
|
-
for (var i = 0; i < 16; i++)
|
|
589
|
-
W[i] = msg[start + i];
|
|
590
|
-
|
|
591
|
-
for(; i < W.length; i++)
|
|
592
|
-
W[i] = rotl32$1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
|
|
593
|
-
|
|
594
|
-
var a = this.h[0];
|
|
595
|
-
var b = this.h[1];
|
|
596
|
-
var c = this.h[2];
|
|
597
|
-
var d = this.h[3];
|
|
598
|
-
var e = this.h[4];
|
|
599
|
-
|
|
600
|
-
for (i = 0; i < W.length; i++) {
|
|
601
|
-
var s = ~~(i / 20);
|
|
602
|
-
var t = sum32_5$1(rotl32$1(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
|
|
603
|
-
e = d;
|
|
604
|
-
d = c;
|
|
605
|
-
c = rotl32$1(b, 30);
|
|
606
|
-
b = a;
|
|
607
|
-
a = t;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
this.h[0] = sum32$2(this.h[0], a);
|
|
611
|
-
this.h[1] = sum32$2(this.h[1], b);
|
|
612
|
-
this.h[2] = sum32$2(this.h[2], c);
|
|
613
|
-
this.h[3] = sum32$2(this.h[3], d);
|
|
614
|
-
this.h[4] = sum32$2(this.h[4], e);
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
SHA1.prototype._digest = function digest(enc) {
|
|
618
|
-
if (enc === 'hex')
|
|
619
|
-
return utils$6.toHex32(this.h, 'big');
|
|
620
|
-
else
|
|
621
|
-
return utils$6.split32(this.h, 'big');
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
var utils$5 = utils$9;
|
|
625
|
-
var common$2 = common$5;
|
|
626
|
-
var shaCommon = common$4;
|
|
627
|
-
var assert$3 = minimalisticAssert;
|
|
628
|
-
|
|
629
|
-
var sum32$1 = utils$5.sum32;
|
|
630
|
-
var sum32_4$1 = utils$5.sum32_4;
|
|
631
|
-
var sum32_5 = utils$5.sum32_5;
|
|
632
|
-
var ch32 = shaCommon.ch32;
|
|
633
|
-
var maj32 = shaCommon.maj32;
|
|
634
|
-
var s0_256 = shaCommon.s0_256;
|
|
635
|
-
var s1_256 = shaCommon.s1_256;
|
|
636
|
-
var g0_256 = shaCommon.g0_256;
|
|
637
|
-
var g1_256 = shaCommon.g1_256;
|
|
638
|
-
|
|
639
|
-
var BlockHash$2 = common$2.BlockHash;
|
|
640
|
-
|
|
641
|
-
var sha256_K = [
|
|
642
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
|
643
|
-
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
644
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
645
|
-
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
646
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
|
647
|
-
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
648
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
|
649
|
-
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
650
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
651
|
-
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
652
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
|
653
|
-
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
654
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
|
655
|
-
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
656
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
657
|
-
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
658
|
-
];
|
|
659
|
-
|
|
660
|
-
function SHA256$1() {
|
|
661
|
-
if (!(this instanceof SHA256$1))
|
|
662
|
-
return new SHA256$1();
|
|
663
|
-
|
|
664
|
-
BlockHash$2.call(this);
|
|
665
|
-
this.h = [
|
|
666
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
667
|
-
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
668
|
-
];
|
|
669
|
-
this.k = sha256_K;
|
|
670
|
-
this.W = new Array(64);
|
|
671
|
-
}
|
|
672
|
-
utils$5.inherits(SHA256$1, BlockHash$2);
|
|
673
|
-
var _256 = SHA256$1;
|
|
674
|
-
|
|
675
|
-
SHA256$1.blockSize = 512;
|
|
676
|
-
SHA256$1.outSize = 256;
|
|
677
|
-
SHA256$1.hmacStrength = 192;
|
|
678
|
-
SHA256$1.padLength = 64;
|
|
679
|
-
|
|
680
|
-
SHA256$1.prototype._update = function _update(msg, start) {
|
|
681
|
-
var W = this.W;
|
|
682
|
-
|
|
683
|
-
for (var i = 0; i < 16; i++)
|
|
684
|
-
W[i] = msg[start + i];
|
|
685
|
-
for (; i < W.length; i++)
|
|
686
|
-
W[i] = sum32_4$1(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
|
|
687
|
-
|
|
688
|
-
var a = this.h[0];
|
|
689
|
-
var b = this.h[1];
|
|
690
|
-
var c = this.h[2];
|
|
691
|
-
var d = this.h[3];
|
|
692
|
-
var e = this.h[4];
|
|
693
|
-
var f = this.h[5];
|
|
694
|
-
var g = this.h[6];
|
|
695
|
-
var h = this.h[7];
|
|
696
|
-
|
|
697
|
-
assert$3(this.k.length === W.length);
|
|
698
|
-
for (i = 0; i < W.length; i++) {
|
|
699
|
-
var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
|
|
700
|
-
var T2 = sum32$1(s0_256(a), maj32(a, b, c));
|
|
701
|
-
h = g;
|
|
702
|
-
g = f;
|
|
703
|
-
f = e;
|
|
704
|
-
e = sum32$1(d, T1);
|
|
705
|
-
d = c;
|
|
706
|
-
c = b;
|
|
707
|
-
b = a;
|
|
708
|
-
a = sum32$1(T1, T2);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
this.h[0] = sum32$1(this.h[0], a);
|
|
712
|
-
this.h[1] = sum32$1(this.h[1], b);
|
|
713
|
-
this.h[2] = sum32$1(this.h[2], c);
|
|
714
|
-
this.h[3] = sum32$1(this.h[3], d);
|
|
715
|
-
this.h[4] = sum32$1(this.h[4], e);
|
|
716
|
-
this.h[5] = sum32$1(this.h[5], f);
|
|
717
|
-
this.h[6] = sum32$1(this.h[6], g);
|
|
718
|
-
this.h[7] = sum32$1(this.h[7], h);
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
SHA256$1.prototype._digest = function digest(enc) {
|
|
722
|
-
if (enc === 'hex')
|
|
723
|
-
return utils$5.toHex32(this.h, 'big');
|
|
724
|
-
else
|
|
725
|
-
return utils$5.split32(this.h, 'big');
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
var utils$4 = utils$9;
|
|
729
|
-
var SHA256 = _256;
|
|
730
|
-
|
|
731
|
-
function SHA224() {
|
|
732
|
-
if (!(this instanceof SHA224))
|
|
733
|
-
return new SHA224();
|
|
734
|
-
|
|
735
|
-
SHA256.call(this);
|
|
736
|
-
this.h = [
|
|
737
|
-
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
|
738
|
-
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 ];
|
|
739
|
-
}
|
|
740
|
-
utils$4.inherits(SHA224, SHA256);
|
|
741
|
-
var _224 = SHA224;
|
|
742
|
-
|
|
743
|
-
SHA224.blockSize = 512;
|
|
744
|
-
SHA224.outSize = 224;
|
|
745
|
-
SHA224.hmacStrength = 192;
|
|
746
|
-
SHA224.padLength = 64;
|
|
747
|
-
|
|
748
|
-
SHA224.prototype._digest = function digest(enc) {
|
|
749
|
-
// Just truncate output
|
|
750
|
-
if (enc === 'hex')
|
|
751
|
-
return utils$4.toHex32(this.h.slice(0, 7), 'big');
|
|
752
|
-
else
|
|
753
|
-
return utils$4.split32(this.h.slice(0, 7), 'big');
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
var utils$3 = utils$9;
|
|
757
|
-
var common$1 = common$5;
|
|
758
|
-
var assert$2 = minimalisticAssert;
|
|
759
|
-
|
|
760
|
-
var rotr64_hi = utils$3.rotr64_hi;
|
|
761
|
-
var rotr64_lo = utils$3.rotr64_lo;
|
|
762
|
-
var shr64_hi = utils$3.shr64_hi;
|
|
763
|
-
var shr64_lo = utils$3.shr64_lo;
|
|
764
|
-
var sum64 = utils$3.sum64;
|
|
765
|
-
var sum64_hi = utils$3.sum64_hi;
|
|
766
|
-
var sum64_lo = utils$3.sum64_lo;
|
|
767
|
-
var sum64_4_hi = utils$3.sum64_4_hi;
|
|
768
|
-
var sum64_4_lo = utils$3.sum64_4_lo;
|
|
769
|
-
var sum64_5_hi = utils$3.sum64_5_hi;
|
|
770
|
-
var sum64_5_lo = utils$3.sum64_5_lo;
|
|
771
|
-
|
|
772
|
-
var BlockHash$1 = common$1.BlockHash;
|
|
773
|
-
|
|
774
|
-
var sha512_K = [
|
|
775
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
776
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
777
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
778
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
779
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
780
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
781
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
782
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
783
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
784
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
785
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
786
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
787
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
788
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
789
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
790
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
791
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
792
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
793
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
794
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
795
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
796
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
797
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
798
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
799
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
800
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
801
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
802
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
803
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
804
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
805
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
806
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
807
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
808
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
809
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
810
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
811
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
812
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
813
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
814
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
815
|
-
];
|
|
816
|
-
|
|
817
|
-
function SHA512$1() {
|
|
818
|
-
if (!(this instanceof SHA512$1))
|
|
819
|
-
return new SHA512$1();
|
|
820
|
-
|
|
821
|
-
BlockHash$1.call(this);
|
|
822
|
-
this.h = [
|
|
823
|
-
0x6a09e667, 0xf3bcc908,
|
|
824
|
-
0xbb67ae85, 0x84caa73b,
|
|
825
|
-
0x3c6ef372, 0xfe94f82b,
|
|
826
|
-
0xa54ff53a, 0x5f1d36f1,
|
|
827
|
-
0x510e527f, 0xade682d1,
|
|
828
|
-
0x9b05688c, 0x2b3e6c1f,
|
|
829
|
-
0x1f83d9ab, 0xfb41bd6b,
|
|
830
|
-
0x5be0cd19, 0x137e2179 ];
|
|
831
|
-
this.k = sha512_K;
|
|
832
|
-
this.W = new Array(160);
|
|
833
|
-
}
|
|
834
|
-
utils$3.inherits(SHA512$1, BlockHash$1);
|
|
835
|
-
var _512 = SHA512$1;
|
|
836
|
-
|
|
837
|
-
SHA512$1.blockSize = 1024;
|
|
838
|
-
SHA512$1.outSize = 512;
|
|
839
|
-
SHA512$1.hmacStrength = 192;
|
|
840
|
-
SHA512$1.padLength = 128;
|
|
841
|
-
|
|
842
|
-
SHA512$1.prototype._prepareBlock = function _prepareBlock(msg, start) {
|
|
843
|
-
var W = this.W;
|
|
844
|
-
|
|
845
|
-
// 32 x 32bit words
|
|
846
|
-
for (var i = 0; i < 32; i++)
|
|
847
|
-
W[i] = msg[start + i];
|
|
848
|
-
for (; i < W.length; i += 2) {
|
|
849
|
-
var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
|
|
850
|
-
var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
|
|
851
|
-
var c1_hi = W[i - 14]; // i - 7
|
|
852
|
-
var c1_lo = W[i - 13];
|
|
853
|
-
var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
|
|
854
|
-
var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
|
|
855
|
-
var c3_hi = W[i - 32]; // i - 16
|
|
856
|
-
var c3_lo = W[i - 31];
|
|
857
|
-
|
|
858
|
-
W[i] = sum64_4_hi(
|
|
859
|
-
c0_hi, c0_lo,
|
|
860
|
-
c1_hi, c1_lo,
|
|
861
|
-
c2_hi, c2_lo,
|
|
862
|
-
c3_hi, c3_lo);
|
|
863
|
-
W[i + 1] = sum64_4_lo(
|
|
864
|
-
c0_hi, c0_lo,
|
|
865
|
-
c1_hi, c1_lo,
|
|
866
|
-
c2_hi, c2_lo,
|
|
867
|
-
c3_hi, c3_lo);
|
|
95
|
+
return buffer.Buffer.from(arr);
|
|
868
96
|
}
|
|
869
97
|
};
|
|
870
98
|
|
|
871
|
-
SHA512$1.prototype._update = function _update(msg, start) {
|
|
872
|
-
this._prepareBlock(msg, start);
|
|
873
|
-
|
|
874
|
-
var W = this.W;
|
|
875
|
-
|
|
876
|
-
var ah = this.h[0];
|
|
877
|
-
var al = this.h[1];
|
|
878
|
-
var bh = this.h[2];
|
|
879
|
-
var bl = this.h[3];
|
|
880
|
-
var ch = this.h[4];
|
|
881
|
-
var cl = this.h[5];
|
|
882
|
-
var dh = this.h[6];
|
|
883
|
-
var dl = this.h[7];
|
|
884
|
-
var eh = this.h[8];
|
|
885
|
-
var el = this.h[9];
|
|
886
|
-
var fh = this.h[10];
|
|
887
|
-
var fl = this.h[11];
|
|
888
|
-
var gh = this.h[12];
|
|
889
|
-
var gl = this.h[13];
|
|
890
|
-
var hh = this.h[14];
|
|
891
|
-
var hl = this.h[15];
|
|
892
|
-
|
|
893
|
-
assert$2(this.k.length === W.length);
|
|
894
|
-
for (var i = 0; i < W.length; i += 2) {
|
|
895
|
-
var c0_hi = hh;
|
|
896
|
-
var c0_lo = hl;
|
|
897
|
-
var c1_hi = s1_512_hi(eh, el);
|
|
898
|
-
var c1_lo = s1_512_lo(eh, el);
|
|
899
|
-
var c2_hi = ch64_hi(eh, el, fh, fl, gh);
|
|
900
|
-
var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
|
|
901
|
-
var c3_hi = this.k[i];
|
|
902
|
-
var c3_lo = this.k[i + 1];
|
|
903
|
-
var c4_hi = W[i];
|
|
904
|
-
var c4_lo = W[i + 1];
|
|
905
|
-
|
|
906
|
-
var T1_hi = sum64_5_hi(
|
|
907
|
-
c0_hi, c0_lo,
|
|
908
|
-
c1_hi, c1_lo,
|
|
909
|
-
c2_hi, c2_lo,
|
|
910
|
-
c3_hi, c3_lo,
|
|
911
|
-
c4_hi, c4_lo);
|
|
912
|
-
var T1_lo = sum64_5_lo(
|
|
913
|
-
c0_hi, c0_lo,
|
|
914
|
-
c1_hi, c1_lo,
|
|
915
|
-
c2_hi, c2_lo,
|
|
916
|
-
c3_hi, c3_lo,
|
|
917
|
-
c4_hi, c4_lo);
|
|
918
|
-
|
|
919
|
-
c0_hi = s0_512_hi(ah, al);
|
|
920
|
-
c0_lo = s0_512_lo(ah, al);
|
|
921
|
-
c1_hi = maj64_hi(ah, al, bh, bl, ch);
|
|
922
|
-
c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
|
|
923
|
-
|
|
924
|
-
var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
925
|
-
var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
|
|
926
|
-
|
|
927
|
-
hh = gh;
|
|
928
|
-
hl = gl;
|
|
929
|
-
|
|
930
|
-
gh = fh;
|
|
931
|
-
gl = fl;
|
|
932
|
-
|
|
933
|
-
fh = eh;
|
|
934
|
-
fl = el;
|
|
935
|
-
|
|
936
|
-
eh = sum64_hi(dh, dl, T1_hi, T1_lo);
|
|
937
|
-
el = sum64_lo(dl, dl, T1_hi, T1_lo);
|
|
938
|
-
|
|
939
|
-
dh = ch;
|
|
940
|
-
dl = cl;
|
|
941
|
-
|
|
942
|
-
ch = bh;
|
|
943
|
-
cl = bl;
|
|
944
|
-
|
|
945
|
-
bh = ah;
|
|
946
|
-
bl = al;
|
|
947
|
-
|
|
948
|
-
ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
949
|
-
al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
sum64(this.h, 0, ah, al);
|
|
953
|
-
sum64(this.h, 2, bh, bl);
|
|
954
|
-
sum64(this.h, 4, ch, cl);
|
|
955
|
-
sum64(this.h, 6, dh, dl);
|
|
956
|
-
sum64(this.h, 8, eh, el);
|
|
957
|
-
sum64(this.h, 10, fh, fl);
|
|
958
|
-
sum64(this.h, 12, gh, gl);
|
|
959
|
-
sum64(this.h, 14, hh, hl);
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
SHA512$1.prototype._digest = function digest(enc) {
|
|
963
|
-
if (enc === 'hex')
|
|
964
|
-
return utils$3.toHex32(this.h, 'big');
|
|
965
|
-
else
|
|
966
|
-
return utils$3.split32(this.h, 'big');
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
function ch64_hi(xh, xl, yh, yl, zh) {
|
|
970
|
-
var r = (xh & yh) ^ ((~xh) & zh);
|
|
971
|
-
if (r < 0)
|
|
972
|
-
r += 0x100000000;
|
|
973
|
-
return r;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
function ch64_lo(xh, xl, yh, yl, zh, zl) {
|
|
977
|
-
var r = (xl & yl) ^ ((~xl) & zl);
|
|
978
|
-
if (r < 0)
|
|
979
|
-
r += 0x100000000;
|
|
980
|
-
return r;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
function maj64_hi(xh, xl, yh, yl, zh) {
|
|
984
|
-
var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
|
|
985
|
-
if (r < 0)
|
|
986
|
-
r += 0x100000000;
|
|
987
|
-
return r;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
function maj64_lo(xh, xl, yh, yl, zh, zl) {
|
|
991
|
-
var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
|
|
992
|
-
if (r < 0)
|
|
993
|
-
r += 0x100000000;
|
|
994
|
-
return r;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
function s0_512_hi(xh, xl) {
|
|
998
|
-
var c0_hi = rotr64_hi(xh, xl, 28);
|
|
999
|
-
var c1_hi = rotr64_hi(xl, xh, 2); // 34
|
|
1000
|
-
var c2_hi = rotr64_hi(xl, xh, 7); // 39
|
|
1001
|
-
|
|
1002
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1003
|
-
if (r < 0)
|
|
1004
|
-
r += 0x100000000;
|
|
1005
|
-
return r;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
function s0_512_lo(xh, xl) {
|
|
1009
|
-
var c0_lo = rotr64_lo(xh, xl, 28);
|
|
1010
|
-
var c1_lo = rotr64_lo(xl, xh, 2); // 34
|
|
1011
|
-
var c2_lo = rotr64_lo(xl, xh, 7); // 39
|
|
1012
|
-
|
|
1013
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1014
|
-
if (r < 0)
|
|
1015
|
-
r += 0x100000000;
|
|
1016
|
-
return r;
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function s1_512_hi(xh, xl) {
|
|
1020
|
-
var c0_hi = rotr64_hi(xh, xl, 14);
|
|
1021
|
-
var c1_hi = rotr64_hi(xh, xl, 18);
|
|
1022
|
-
var c2_hi = rotr64_hi(xl, xh, 9); // 41
|
|
1023
|
-
|
|
1024
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1025
|
-
if (r < 0)
|
|
1026
|
-
r += 0x100000000;
|
|
1027
|
-
return r;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
function s1_512_lo(xh, xl) {
|
|
1031
|
-
var c0_lo = rotr64_lo(xh, xl, 14);
|
|
1032
|
-
var c1_lo = rotr64_lo(xh, xl, 18);
|
|
1033
|
-
var c2_lo = rotr64_lo(xl, xh, 9); // 41
|
|
1034
|
-
|
|
1035
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1036
|
-
if (r < 0)
|
|
1037
|
-
r += 0x100000000;
|
|
1038
|
-
return r;
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
function g0_512_hi(xh, xl) {
|
|
1042
|
-
var c0_hi = rotr64_hi(xh, xl, 1);
|
|
1043
|
-
var c1_hi = rotr64_hi(xh, xl, 8);
|
|
1044
|
-
var c2_hi = shr64_hi(xh, xl, 7);
|
|
1045
|
-
|
|
1046
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1047
|
-
if (r < 0)
|
|
1048
|
-
r += 0x100000000;
|
|
1049
|
-
return r;
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
function g0_512_lo(xh, xl) {
|
|
1053
|
-
var c0_lo = rotr64_lo(xh, xl, 1);
|
|
1054
|
-
var c1_lo = rotr64_lo(xh, xl, 8);
|
|
1055
|
-
var c2_lo = shr64_lo(xh, xl, 7);
|
|
1056
|
-
|
|
1057
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1058
|
-
if (r < 0)
|
|
1059
|
-
r += 0x100000000;
|
|
1060
|
-
return r;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
function g1_512_hi(xh, xl) {
|
|
1064
|
-
var c0_hi = rotr64_hi(xh, xl, 19);
|
|
1065
|
-
var c1_hi = rotr64_hi(xl, xh, 29); // 61
|
|
1066
|
-
var c2_hi = shr64_hi(xh, xl, 6);
|
|
1067
|
-
|
|
1068
|
-
var r = c0_hi ^ c1_hi ^ c2_hi;
|
|
1069
|
-
if (r < 0)
|
|
1070
|
-
r += 0x100000000;
|
|
1071
|
-
return r;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
function g1_512_lo(xh, xl) {
|
|
1075
|
-
var c0_lo = rotr64_lo(xh, xl, 19);
|
|
1076
|
-
var c1_lo = rotr64_lo(xl, xh, 29); // 61
|
|
1077
|
-
var c2_lo = shr64_lo(xh, xl, 6);
|
|
1078
|
-
|
|
1079
|
-
var r = c0_lo ^ c1_lo ^ c2_lo;
|
|
1080
|
-
if (r < 0)
|
|
1081
|
-
r += 0x100000000;
|
|
1082
|
-
return r;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
var utils$2 = utils$9;
|
|
1086
|
-
|
|
1087
|
-
var SHA512 = _512;
|
|
1088
|
-
|
|
1089
|
-
function SHA384() {
|
|
1090
|
-
if (!(this instanceof SHA384))
|
|
1091
|
-
return new SHA384();
|
|
1092
|
-
|
|
1093
|
-
SHA512.call(this);
|
|
1094
|
-
this.h = [
|
|
1095
|
-
0xcbbb9d5d, 0xc1059ed8,
|
|
1096
|
-
0x629a292a, 0x367cd507,
|
|
1097
|
-
0x9159015a, 0x3070dd17,
|
|
1098
|
-
0x152fecd8, 0xf70e5939,
|
|
1099
|
-
0x67332667, 0xffc00b31,
|
|
1100
|
-
0x8eb44a87, 0x68581511,
|
|
1101
|
-
0xdb0c2e0d, 0x64f98fa7,
|
|
1102
|
-
0x47b5481d, 0xbefa4fa4 ];
|
|
1103
|
-
}
|
|
1104
|
-
utils$2.inherits(SHA384, SHA512);
|
|
1105
|
-
var _384 = SHA384;
|
|
1106
|
-
|
|
1107
|
-
SHA384.blockSize = 1024;
|
|
1108
|
-
SHA384.outSize = 384;
|
|
1109
|
-
SHA384.hmacStrength = 192;
|
|
1110
|
-
SHA384.padLength = 128;
|
|
1111
|
-
|
|
1112
|
-
SHA384.prototype._digest = function digest(enc) {
|
|
1113
|
-
if (enc === 'hex')
|
|
1114
|
-
return utils$2.toHex32(this.h.slice(0, 12), 'big');
|
|
1115
|
-
else
|
|
1116
|
-
return utils$2.split32(this.h.slice(0, 12), 'big');
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
sha.sha1 = _1;
|
|
1120
|
-
sha.sha224 = _224;
|
|
1121
|
-
sha.sha256 = _256;
|
|
1122
|
-
sha.sha384 = _384;
|
|
1123
|
-
sha.sha512 = _512;
|
|
1124
|
-
|
|
1125
|
-
var ripemd = {};
|
|
1126
|
-
|
|
1127
|
-
var utils$1 = utils$9;
|
|
1128
|
-
var common = common$5;
|
|
1129
|
-
|
|
1130
|
-
var rotl32 = utils$1.rotl32;
|
|
1131
|
-
var sum32 = utils$1.sum32;
|
|
1132
|
-
var sum32_3 = utils$1.sum32_3;
|
|
1133
|
-
var sum32_4 = utils$1.sum32_4;
|
|
1134
|
-
var BlockHash = common.BlockHash;
|
|
1135
|
-
|
|
1136
|
-
function RIPEMD160() {
|
|
1137
|
-
if (!(this instanceof RIPEMD160))
|
|
1138
|
-
return new RIPEMD160();
|
|
1139
|
-
|
|
1140
|
-
BlockHash.call(this);
|
|
1141
|
-
|
|
1142
|
-
this.h = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ];
|
|
1143
|
-
this.endian = 'little';
|
|
1144
|
-
}
|
|
1145
|
-
utils$1.inherits(RIPEMD160, BlockHash);
|
|
1146
|
-
ripemd.ripemd160 = RIPEMD160;
|
|
1147
|
-
|
|
1148
|
-
RIPEMD160.blockSize = 512;
|
|
1149
|
-
RIPEMD160.outSize = 160;
|
|
1150
|
-
RIPEMD160.hmacStrength = 192;
|
|
1151
|
-
RIPEMD160.padLength = 64;
|
|
1152
|
-
|
|
1153
|
-
RIPEMD160.prototype._update = function update(msg, start) {
|
|
1154
|
-
var A = this.h[0];
|
|
1155
|
-
var B = this.h[1];
|
|
1156
|
-
var C = this.h[2];
|
|
1157
|
-
var D = this.h[3];
|
|
1158
|
-
var E = this.h[4];
|
|
1159
|
-
var Ah = A;
|
|
1160
|
-
var Bh = B;
|
|
1161
|
-
var Ch = C;
|
|
1162
|
-
var Dh = D;
|
|
1163
|
-
var Eh = E;
|
|
1164
|
-
for (var j = 0; j < 80; j++) {
|
|
1165
|
-
var T = sum32(
|
|
1166
|
-
rotl32(
|
|
1167
|
-
sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
|
|
1168
|
-
s[j]),
|
|
1169
|
-
E);
|
|
1170
|
-
A = E;
|
|
1171
|
-
E = D;
|
|
1172
|
-
D = rotl32(C, 10);
|
|
1173
|
-
C = B;
|
|
1174
|
-
B = T;
|
|
1175
|
-
T = sum32(
|
|
1176
|
-
rotl32(
|
|
1177
|
-
sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
|
|
1178
|
-
sh[j]),
|
|
1179
|
-
Eh);
|
|
1180
|
-
Ah = Eh;
|
|
1181
|
-
Eh = Dh;
|
|
1182
|
-
Dh = rotl32(Ch, 10);
|
|
1183
|
-
Ch = Bh;
|
|
1184
|
-
Bh = T;
|
|
1185
|
-
}
|
|
1186
|
-
T = sum32_3(this.h[1], C, Dh);
|
|
1187
|
-
this.h[1] = sum32_3(this.h[2], D, Eh);
|
|
1188
|
-
this.h[2] = sum32_3(this.h[3], E, Ah);
|
|
1189
|
-
this.h[3] = sum32_3(this.h[4], A, Bh);
|
|
1190
|
-
this.h[4] = sum32_3(this.h[0], B, Ch);
|
|
1191
|
-
this.h[0] = T;
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
RIPEMD160.prototype._digest = function digest(enc) {
|
|
1195
|
-
if (enc === 'hex')
|
|
1196
|
-
return utils$1.toHex32(this.h, 'little');
|
|
1197
|
-
else
|
|
1198
|
-
return utils$1.split32(this.h, 'little');
|
|
1199
|
-
};
|
|
1200
|
-
|
|
1201
|
-
function f(j, x, y, z) {
|
|
1202
|
-
if (j <= 15)
|
|
1203
|
-
return x ^ y ^ z;
|
|
1204
|
-
else if (j <= 31)
|
|
1205
|
-
return (x & y) | ((~x) & z);
|
|
1206
|
-
else if (j <= 47)
|
|
1207
|
-
return (x | (~y)) ^ z;
|
|
1208
|
-
else if (j <= 63)
|
|
1209
|
-
return (x & z) | (y & (~z));
|
|
1210
|
-
else
|
|
1211
|
-
return x ^ (y | (~z));
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
function K(j) {
|
|
1215
|
-
if (j <= 15)
|
|
1216
|
-
return 0x00000000;
|
|
1217
|
-
else if (j <= 31)
|
|
1218
|
-
return 0x5a827999;
|
|
1219
|
-
else if (j <= 47)
|
|
1220
|
-
return 0x6ed9eba1;
|
|
1221
|
-
else if (j <= 63)
|
|
1222
|
-
return 0x8f1bbcdc;
|
|
1223
|
-
else
|
|
1224
|
-
return 0xa953fd4e;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function Kh(j) {
|
|
1228
|
-
if (j <= 15)
|
|
1229
|
-
return 0x50a28be6;
|
|
1230
|
-
else if (j <= 31)
|
|
1231
|
-
return 0x5c4dd124;
|
|
1232
|
-
else if (j <= 47)
|
|
1233
|
-
return 0x6d703ef3;
|
|
1234
|
-
else if (j <= 63)
|
|
1235
|
-
return 0x7a6d76e9;
|
|
1236
|
-
else
|
|
1237
|
-
return 0x00000000;
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
var r = [
|
|
1241
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
1242
|
-
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
|
1243
|
-
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
|
1244
|
-
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
|
1245
|
-
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
|
|
1246
|
-
];
|
|
1247
|
-
|
|
1248
|
-
var rh = [
|
|
1249
|
-
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
|
1250
|
-
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
|
1251
|
-
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
|
1252
|
-
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
|
1253
|
-
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
|
|
1254
|
-
];
|
|
1255
|
-
|
|
1256
|
-
var s = [
|
|
1257
|
-
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
|
1258
|
-
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
|
1259
|
-
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
|
1260
|
-
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
|
1261
|
-
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
|
|
1262
|
-
];
|
|
1263
|
-
|
|
1264
|
-
var sh = [
|
|
1265
|
-
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
|
1266
|
-
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
|
1267
|
-
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
|
1268
|
-
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
|
1269
|
-
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
|
|
1270
|
-
];
|
|
1271
|
-
|
|
1272
|
-
var utils = utils$9;
|
|
1273
|
-
var assert$1 = minimalisticAssert;
|
|
1274
|
-
|
|
1275
|
-
function Hmac(hash, key, enc) {
|
|
1276
|
-
if (!(this instanceof Hmac))
|
|
1277
|
-
return new Hmac(hash, key, enc);
|
|
1278
|
-
this.Hash = hash;
|
|
1279
|
-
this.blockSize = hash.blockSize / 8;
|
|
1280
|
-
this.outSize = hash.outSize / 8;
|
|
1281
|
-
this.inner = null;
|
|
1282
|
-
this.outer = null;
|
|
1283
|
-
|
|
1284
|
-
this._init(utils.toArray(key, enc));
|
|
1285
|
-
}
|
|
1286
|
-
var hmac = Hmac;
|
|
1287
|
-
|
|
1288
|
-
Hmac.prototype._init = function init(key) {
|
|
1289
|
-
// Shorten key, if needed
|
|
1290
|
-
if (key.length > this.blockSize)
|
|
1291
|
-
key = new this.Hash().update(key).digest();
|
|
1292
|
-
assert$1(key.length <= this.blockSize);
|
|
1293
|
-
|
|
1294
|
-
// Add padding to key
|
|
1295
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1296
|
-
key.push(0);
|
|
1297
|
-
|
|
1298
|
-
for (i = 0; i < key.length; i++)
|
|
1299
|
-
key[i] ^= 0x36;
|
|
1300
|
-
this.inner = new this.Hash().update(key);
|
|
1301
|
-
|
|
1302
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1303
|
-
for (i = 0; i < key.length; i++)
|
|
1304
|
-
key[i] ^= 0x6a;
|
|
1305
|
-
this.outer = new this.Hash().update(key);
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1309
|
-
this.inner.update(msg, enc);
|
|
1310
|
-
return this;
|
|
1311
|
-
};
|
|
1312
|
-
|
|
1313
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1314
|
-
this.outer.update(this.inner.digest());
|
|
1315
|
-
return this.outer.digest(enc);
|
|
1316
|
-
};
|
|
1317
|
-
|
|
1318
|
-
(function (exports) {
|
|
1319
|
-
var hash = exports;
|
|
1320
|
-
|
|
1321
|
-
hash.utils = utils$9;
|
|
1322
|
-
hash.common = common$5;
|
|
1323
|
-
hash.sha = sha;
|
|
1324
|
-
hash.ripemd = ripemd;
|
|
1325
|
-
hash.hmac = hmac;
|
|
1326
|
-
|
|
1327
|
-
// Proxy hash functions to the main object
|
|
1328
|
-
hash.sha1 = hash.sha.sha1;
|
|
1329
|
-
hash.sha256 = hash.sha.sha256;
|
|
1330
|
-
hash.sha224 = hash.sha.sha224;
|
|
1331
|
-
hash.sha384 = hash.sha.sha384;
|
|
1332
|
-
hash.sha512 = hash.sha.sha512;
|
|
1333
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1334
|
-
} (hash$1));
|
|
1335
|
-
|
|
1336
|
-
var hash = hash$1;
|
|
1337
|
-
|
|
1338
|
-
const version$2 = "logger/5.6.0";
|
|
1339
|
-
|
|
1340
|
-
let _permanentCensorErrors = false;
|
|
1341
|
-
let _censorErrors = false;
|
|
1342
|
-
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1343
|
-
let _logLevel = LogLevels["default"];
|
|
1344
|
-
let _globalLogger = null;
|
|
1345
|
-
function _checkNormalize() {
|
|
1346
|
-
try {
|
|
1347
|
-
const missing = [];
|
|
1348
|
-
// Make sure all forms of normalization are supported
|
|
1349
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1350
|
-
try {
|
|
1351
|
-
if ("test".normalize(form) !== "test") {
|
|
1352
|
-
throw new Error("bad normalize");
|
|
1353
|
-
}
|
|
1354
|
-
;
|
|
1355
|
-
}
|
|
1356
|
-
catch (error) {
|
|
1357
|
-
missing.push(form);
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
if (missing.length) {
|
|
1361
|
-
throw new Error("missing " + missing.join(", "));
|
|
1362
|
-
}
|
|
1363
|
-
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1364
|
-
throw new Error("broken implementation");
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
catch (error) {
|
|
1368
|
-
return error.message;
|
|
1369
|
-
}
|
|
1370
|
-
return null;
|
|
1371
|
-
}
|
|
1372
|
-
const _normalizeError = _checkNormalize();
|
|
1373
|
-
var LogLevel;
|
|
1374
|
-
(function (LogLevel) {
|
|
1375
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
1376
|
-
LogLevel["INFO"] = "INFO";
|
|
1377
|
-
LogLevel["WARNING"] = "WARNING";
|
|
1378
|
-
LogLevel["ERROR"] = "ERROR";
|
|
1379
|
-
LogLevel["OFF"] = "OFF";
|
|
1380
|
-
})(LogLevel || (LogLevel = {}));
|
|
1381
|
-
var ErrorCode;
|
|
1382
|
-
(function (ErrorCode) {
|
|
1383
|
-
///////////////////
|
|
1384
|
-
// Generic Errors
|
|
1385
|
-
// Unknown Error
|
|
1386
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1387
|
-
// Not Implemented
|
|
1388
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1389
|
-
// Unsupported Operation
|
|
1390
|
-
// - operation
|
|
1391
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1392
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1393
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1394
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1395
|
-
// Some sort of bad response from the server
|
|
1396
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1397
|
-
// Timeout
|
|
1398
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1399
|
-
///////////////////
|
|
1400
|
-
// Operational Errors
|
|
1401
|
-
// Buffer Overrun
|
|
1402
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1403
|
-
// Numeric Fault
|
|
1404
|
-
// - operation: the operation being executed
|
|
1405
|
-
// - fault: the reason this faulted
|
|
1406
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1407
|
-
///////////////////
|
|
1408
|
-
// Argument Errors
|
|
1409
|
-
// Missing new operator to an object
|
|
1410
|
-
// - name: The name of the class
|
|
1411
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1412
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1413
|
-
// - argument: The argument name that was invalid
|
|
1414
|
-
// - value: The value of the argument
|
|
1415
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1416
|
-
// Missing argument to a function:
|
|
1417
|
-
// - count: The number of arguments received
|
|
1418
|
-
// - expectedCount: The number of arguments expected
|
|
1419
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1420
|
-
// Too many arguments
|
|
1421
|
-
// - count: The number of arguments received
|
|
1422
|
-
// - expectedCount: The number of arguments expected
|
|
1423
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1424
|
-
///////////////////
|
|
1425
|
-
// Blockchain Errors
|
|
1426
|
-
// Call exception
|
|
1427
|
-
// - transaction: the transaction
|
|
1428
|
-
// - address?: the contract address
|
|
1429
|
-
// - args?: The arguments passed into the function
|
|
1430
|
-
// - method?: The Solidity method signature
|
|
1431
|
-
// - errorSignature?: The EIP848 error signature
|
|
1432
|
-
// - errorArgs?: The EIP848 error parameters
|
|
1433
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1434
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1435
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1436
|
-
// - transaction: the transaction attempted
|
|
1437
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1438
|
-
// Nonce has already been used
|
|
1439
|
-
// - transaction: the transaction attempted
|
|
1440
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1441
|
-
// The replacement fee for the transaction is too low
|
|
1442
|
-
// - transaction: the transaction attempted
|
|
1443
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1444
|
-
// The gas limit could not be estimated
|
|
1445
|
-
// - transaction: the transaction passed to estimateGas
|
|
1446
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1447
|
-
// The transaction was replaced by one with a higher gas price
|
|
1448
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
1449
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1450
|
-
// - hash: original transaction hash
|
|
1451
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
1452
|
-
// - receipt: the receipt of the replacement
|
|
1453
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1454
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
1455
|
-
const HEX = "0123456789abcdef";
|
|
1456
|
-
class Logger {
|
|
1457
|
-
constructor(version) {
|
|
1458
|
-
Object.defineProperty(this, "version", {
|
|
1459
|
-
enumerable: true,
|
|
1460
|
-
value: version,
|
|
1461
|
-
writable: false
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
_log(logLevel, args) {
|
|
1465
|
-
const level = logLevel.toLowerCase();
|
|
1466
|
-
if (LogLevels[level] == null) {
|
|
1467
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1468
|
-
}
|
|
1469
|
-
if (_logLevel > LogLevels[level]) {
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1472
|
-
console.log.apply(console, args);
|
|
1473
|
-
}
|
|
1474
|
-
debug(...args) {
|
|
1475
|
-
this._log(Logger.levels.DEBUG, args);
|
|
1476
|
-
}
|
|
1477
|
-
info(...args) {
|
|
1478
|
-
this._log(Logger.levels.INFO, args);
|
|
1479
|
-
}
|
|
1480
|
-
warn(...args) {
|
|
1481
|
-
this._log(Logger.levels.WARNING, args);
|
|
1482
|
-
}
|
|
1483
|
-
makeError(message, code, params) {
|
|
1484
|
-
// Errors are being censored
|
|
1485
|
-
if (_censorErrors) {
|
|
1486
|
-
return this.makeError("censored error", code, {});
|
|
1487
|
-
}
|
|
1488
|
-
if (!code) {
|
|
1489
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
1490
|
-
}
|
|
1491
|
-
if (!params) {
|
|
1492
|
-
params = {};
|
|
1493
|
-
}
|
|
1494
|
-
const messageDetails = [];
|
|
1495
|
-
Object.keys(params).forEach((key) => {
|
|
1496
|
-
const value = params[key];
|
|
1497
|
-
try {
|
|
1498
|
-
if (value instanceof Uint8Array) {
|
|
1499
|
-
let hex = "";
|
|
1500
|
-
for (let i = 0; i < value.length; i++) {
|
|
1501
|
-
hex += HEX[value[i] >> 4];
|
|
1502
|
-
hex += HEX[value[i] & 0x0f];
|
|
1503
|
-
}
|
|
1504
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1505
|
-
}
|
|
1506
|
-
else {
|
|
1507
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
catch (error) {
|
|
1511
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
messageDetails.push(`code=${code}`);
|
|
1515
|
-
messageDetails.push(`version=${this.version}`);
|
|
1516
|
-
const reason = message;
|
|
1517
|
-
let url = "";
|
|
1518
|
-
switch (code) {
|
|
1519
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
1520
|
-
url = "NUMERIC_FAULT";
|
|
1521
|
-
const fault = message;
|
|
1522
|
-
switch (fault) {
|
|
1523
|
-
case "overflow":
|
|
1524
|
-
case "underflow":
|
|
1525
|
-
case "division-by-zero":
|
|
1526
|
-
url += "-" + fault;
|
|
1527
|
-
break;
|
|
1528
|
-
case "negative-power":
|
|
1529
|
-
case "negative-width":
|
|
1530
|
-
url += "-unsupported";
|
|
1531
|
-
break;
|
|
1532
|
-
case "unbound-bitwise-result":
|
|
1533
|
-
url += "-unbound-result";
|
|
1534
|
-
break;
|
|
1535
|
-
}
|
|
1536
|
-
break;
|
|
1537
|
-
}
|
|
1538
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
1539
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
1540
|
-
case ErrorCode.MISSING_NEW:
|
|
1541
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
1542
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
1543
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
1544
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
1545
|
-
url = code;
|
|
1546
|
-
break;
|
|
1547
|
-
}
|
|
1548
|
-
if (url) {
|
|
1549
|
-
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
1550
|
-
}
|
|
1551
|
-
if (messageDetails.length) {
|
|
1552
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
1553
|
-
}
|
|
1554
|
-
// @TODO: Any??
|
|
1555
|
-
const error = new Error(message);
|
|
1556
|
-
error.reason = reason;
|
|
1557
|
-
error.code = code;
|
|
1558
|
-
Object.keys(params).forEach(function (key) {
|
|
1559
|
-
error[key] = params[key];
|
|
1560
|
-
});
|
|
1561
|
-
return error;
|
|
1562
|
-
}
|
|
1563
|
-
throwError(message, code, params) {
|
|
1564
|
-
throw this.makeError(message, code, params);
|
|
1565
|
-
}
|
|
1566
|
-
throwArgumentError(message, name, value) {
|
|
1567
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1568
|
-
argument: name,
|
|
1569
|
-
value: value
|
|
1570
|
-
});
|
|
1571
|
-
}
|
|
1572
|
-
assert(condition, message, code, params) {
|
|
1573
|
-
if (!!condition) {
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
this.throwError(message, code, params);
|
|
1577
|
-
}
|
|
1578
|
-
assertArgument(condition, message, name, value) {
|
|
1579
|
-
if (!!condition) {
|
|
1580
|
-
return;
|
|
1581
|
-
}
|
|
1582
|
-
this.throwArgumentError(message, name, value);
|
|
1583
|
-
}
|
|
1584
|
-
checkNormalize(message) {
|
|
1585
|
-
if (_normalizeError) {
|
|
1586
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1587
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
checkSafeUint53(value, message) {
|
|
1592
|
-
if (typeof (value) !== "number") {
|
|
1593
|
-
return;
|
|
1594
|
-
}
|
|
1595
|
-
if (message == null) {
|
|
1596
|
-
message = "value not safe";
|
|
1597
|
-
}
|
|
1598
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1599
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1600
|
-
operation: "checkSafeInteger",
|
|
1601
|
-
fault: "out-of-safe-range",
|
|
1602
|
-
value: value
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
if (value % 1) {
|
|
1606
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1607
|
-
operation: "checkSafeInteger",
|
|
1608
|
-
fault: "non-integer",
|
|
1609
|
-
value: value
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
1614
|
-
if (message) {
|
|
1615
|
-
message = ": " + message;
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
message = "";
|
|
1619
|
-
}
|
|
1620
|
-
if (count < expectedCount) {
|
|
1621
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1622
|
-
count: count,
|
|
1623
|
-
expectedCount: expectedCount
|
|
1624
|
-
});
|
|
1625
|
-
}
|
|
1626
|
-
if (count > expectedCount) {
|
|
1627
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1628
|
-
count: count,
|
|
1629
|
-
expectedCount: expectedCount
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
checkNew(target, kind) {
|
|
1634
|
-
if (target === Object || target == null) {
|
|
1635
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
checkAbstract(target, kind) {
|
|
1639
|
-
if (target === kind) {
|
|
1640
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1641
|
-
}
|
|
1642
|
-
else if (target === Object || target == null) {
|
|
1643
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
static globalLogger() {
|
|
1647
|
-
if (!_globalLogger) {
|
|
1648
|
-
_globalLogger = new Logger(version$2);
|
|
1649
|
-
}
|
|
1650
|
-
return _globalLogger;
|
|
1651
|
-
}
|
|
1652
|
-
static setCensorship(censorship, permanent) {
|
|
1653
|
-
if (!censorship && permanent) {
|
|
1654
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1655
|
-
operation: "setCensorship"
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
if (_permanentCensorErrors) {
|
|
1659
|
-
if (!censorship) {
|
|
1660
|
-
return;
|
|
1661
|
-
}
|
|
1662
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1663
|
-
operation: "setCensorship"
|
|
1664
|
-
});
|
|
1665
|
-
}
|
|
1666
|
-
_censorErrors = !!censorship;
|
|
1667
|
-
_permanentCensorErrors = !!permanent;
|
|
1668
|
-
}
|
|
1669
|
-
static setLogLevel(logLevel) {
|
|
1670
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
1671
|
-
if (level == null) {
|
|
1672
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1673
|
-
return;
|
|
1674
|
-
}
|
|
1675
|
-
_logLevel = level;
|
|
1676
|
-
}
|
|
1677
|
-
static from(version) {
|
|
1678
|
-
return new Logger(version);
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
Logger.errors = ErrorCode;
|
|
1682
|
-
Logger.levels = LogLevel;
|
|
1683
|
-
|
|
1684
|
-
const version$1 = "bytes/5.6.0";
|
|
1685
|
-
|
|
1686
|
-
const logger = new Logger(version$1);
|
|
1687
|
-
///////////////////////////////
|
|
1688
|
-
function isHexable(value) {
|
|
1689
|
-
return !!(value.toHexString);
|
|
1690
|
-
}
|
|
1691
|
-
function addSlice(array) {
|
|
1692
|
-
if (array.slice) {
|
|
1693
|
-
return array;
|
|
1694
|
-
}
|
|
1695
|
-
array.slice = function () {
|
|
1696
|
-
const args = Array.prototype.slice.call(arguments);
|
|
1697
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1698
|
-
};
|
|
1699
|
-
return array;
|
|
1700
|
-
}
|
|
1701
|
-
function isInteger(value) {
|
|
1702
|
-
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1703
|
-
}
|
|
1704
|
-
function isBytes(value) {
|
|
1705
|
-
if (value == null) {
|
|
1706
|
-
return false;
|
|
1707
|
-
}
|
|
1708
|
-
if (value.constructor === Uint8Array) {
|
|
1709
|
-
return true;
|
|
1710
|
-
}
|
|
1711
|
-
if (typeof (value) === "string") {
|
|
1712
|
-
return false;
|
|
1713
|
-
}
|
|
1714
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
1715
|
-
return false;
|
|
1716
|
-
}
|
|
1717
|
-
for (let i = 0; i < value.length; i++) {
|
|
1718
|
-
const v = value[i];
|
|
1719
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1720
|
-
return false;
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
return true;
|
|
1724
|
-
}
|
|
1725
|
-
function arrayify(value, options) {
|
|
1726
|
-
if (!options) {
|
|
1727
|
-
options = {};
|
|
1728
|
-
}
|
|
1729
|
-
if (typeof (value) === "number") {
|
|
1730
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1731
|
-
const result = [];
|
|
1732
|
-
while (value) {
|
|
1733
|
-
result.unshift(value & 0xff);
|
|
1734
|
-
value = parseInt(String(value / 256));
|
|
1735
|
-
}
|
|
1736
|
-
if (result.length === 0) {
|
|
1737
|
-
result.push(0);
|
|
1738
|
-
}
|
|
1739
|
-
return addSlice(new Uint8Array(result));
|
|
1740
|
-
}
|
|
1741
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1742
|
-
value = "0x" + value;
|
|
1743
|
-
}
|
|
1744
|
-
if (isHexable(value)) {
|
|
1745
|
-
value = value.toHexString();
|
|
1746
|
-
}
|
|
1747
|
-
if (isHexString(value)) {
|
|
1748
|
-
let hex = value.substring(2);
|
|
1749
|
-
if (hex.length % 2) {
|
|
1750
|
-
if (options.hexPad === "left") {
|
|
1751
|
-
hex = "0x0" + hex.substring(2);
|
|
1752
|
-
}
|
|
1753
|
-
else if (options.hexPad === "right") {
|
|
1754
|
-
hex += "0";
|
|
1755
|
-
}
|
|
1756
|
-
else {
|
|
1757
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
const result = [];
|
|
1761
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
1762
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1763
|
-
}
|
|
1764
|
-
return addSlice(new Uint8Array(result));
|
|
1765
|
-
}
|
|
1766
|
-
if (isBytes(value)) {
|
|
1767
|
-
return addSlice(new Uint8Array(value));
|
|
1768
|
-
}
|
|
1769
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1770
|
-
}
|
|
1771
|
-
function isHexString(value, length) {
|
|
1772
|
-
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1773
|
-
return false;
|
|
1774
|
-
}
|
|
1775
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
1776
|
-
return false;
|
|
1777
|
-
}
|
|
1778
|
-
return true;
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
const version = "sha2/5.6.0";
|
|
1782
|
-
|
|
1783
|
-
new Logger(version);
|
|
1784
|
-
function sha256(data) {
|
|
1785
|
-
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
99
|
class Struct {
|
|
1789
100
|
constructor(properties) {
|
|
1790
101
|
Object.assign(this, properties);
|
|
@@ -1827,6 +138,11 @@ const SOLANA_SCHEMA = new Map();
|
|
|
1827
138
|
*/
|
|
1828
139
|
|
|
1829
140
|
const MAX_SEED_LENGTH = 32;
|
|
141
|
+
/**
|
|
142
|
+
* Size of public key in bytes
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
const PUBLIC_KEY_LENGTH = 32;
|
|
1830
146
|
/**
|
|
1831
147
|
* Value to be converted into public key
|
|
1832
148
|
*/
|
|
@@ -1857,7 +173,7 @@ class PublicKey extends Struct {
|
|
|
1857
173
|
// assume base 58 encoding by default
|
|
1858
174
|
const decoded = bs58__default["default"].decode(value);
|
|
1859
175
|
|
|
1860
|
-
if (decoded.length !=
|
|
176
|
+
if (decoded.length != PUBLIC_KEY_LENGTH) {
|
|
1861
177
|
throw new Error(`Invalid public key input`);
|
|
1862
178
|
}
|
|
1863
179
|
|
|
@@ -1910,7 +226,7 @@ class PublicKey extends Struct {
|
|
|
1910
226
|
toBuffer() {
|
|
1911
227
|
const b = this._bn.toArrayLike(buffer.Buffer);
|
|
1912
228
|
|
|
1913
|
-
if (b.length ===
|
|
229
|
+
if (b.length === PUBLIC_KEY_LENGTH) {
|
|
1914
230
|
return b;
|
|
1915
231
|
}
|
|
1916
232
|
|
|
@@ -1937,8 +253,8 @@ class PublicKey extends Struct {
|
|
|
1937
253
|
|
|
1938
254
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1939
255
|
const buffer$1 = buffer.Buffer.concat([fromPublicKey.toBuffer(), buffer.Buffer.from(seed), programId.toBuffer()]);
|
|
1940
|
-
const
|
|
1941
|
-
return new PublicKey(
|
|
256
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
257
|
+
return new PublicKey(publicKeyBytes);
|
|
1942
258
|
}
|
|
1943
259
|
/**
|
|
1944
260
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1957,10 +273,9 @@ class PublicKey extends Struct {
|
|
|
1957
273
|
buffer$1 = buffer.Buffer.concat([buffer$1, toBuffer(seed)]);
|
|
1958
274
|
});
|
|
1959
275
|
buffer$1 = buffer.Buffer.concat([buffer$1, programId.toBuffer(), buffer.Buffer.from('ProgramDerivedAddress')]);
|
|
1960
|
-
|
|
1961
|
-
let publicKeyBytes = new BN__default["default"](hash, 16).toArray(undefined, 32);
|
|
276
|
+
const publicKeyBytes = sha256.sha256(buffer$1);
|
|
1962
277
|
|
|
1963
|
-
if (
|
|
278
|
+
if (isOnCurve(publicKeyBytes)) {
|
|
1964
279
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1965
280
|
}
|
|
1966
281
|
|
|
@@ -2024,7 +339,7 @@ class PublicKey extends Struct {
|
|
|
2024
339
|
|
|
2025
340
|
static isOnCurve(pubkeyData) {
|
|
2026
341
|
const pubkey = new PublicKey(pubkeyData);
|
|
2027
|
-
return
|
|
342
|
+
return isOnCurve(pubkey.toBytes());
|
|
2028
343
|
}
|
|
2029
344
|
|
|
2030
345
|
}
|
|
@@ -2032,56 +347,7 @@ PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
|
2032
347
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
2033
348
|
kind: 'struct',
|
|
2034
349
|
fields: [['_bn', 'u256']]
|
|
2035
|
-
});
|
|
2036
|
-
|
|
2037
|
-
let naclLowLevel = nacl__default["default"].lowlevel; // Check that a pubkey is on the curve.
|
|
2038
|
-
// This function and its dependents were sourced from:
|
|
2039
|
-
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
2040
|
-
|
|
2041
|
-
function is_on_curve(p) {
|
|
2042
|
-
var r = [naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf(), naclLowLevel.gf()];
|
|
2043
|
-
var t = naclLowLevel.gf(),
|
|
2044
|
-
chk = naclLowLevel.gf(),
|
|
2045
|
-
num = naclLowLevel.gf(),
|
|
2046
|
-
den = naclLowLevel.gf(),
|
|
2047
|
-
den2 = naclLowLevel.gf(),
|
|
2048
|
-
den4 = naclLowLevel.gf(),
|
|
2049
|
-
den6 = naclLowLevel.gf();
|
|
2050
|
-
naclLowLevel.set25519(r[2], gf1);
|
|
2051
|
-
naclLowLevel.unpack25519(r[1], p);
|
|
2052
|
-
naclLowLevel.S(num, r[1]);
|
|
2053
|
-
naclLowLevel.M(den, num, naclLowLevel.D);
|
|
2054
|
-
naclLowLevel.Z(num, num, r[2]);
|
|
2055
|
-
naclLowLevel.A(den, r[2], den);
|
|
2056
|
-
naclLowLevel.S(den2, den);
|
|
2057
|
-
naclLowLevel.S(den4, den2);
|
|
2058
|
-
naclLowLevel.M(den6, den4, den2);
|
|
2059
|
-
naclLowLevel.M(t, den6, num);
|
|
2060
|
-
naclLowLevel.M(t, t, den);
|
|
2061
|
-
naclLowLevel.pow2523(t, t);
|
|
2062
|
-
naclLowLevel.M(t, t, num);
|
|
2063
|
-
naclLowLevel.M(t, t, den);
|
|
2064
|
-
naclLowLevel.M(t, t, den);
|
|
2065
|
-
naclLowLevel.M(r[0], t, den);
|
|
2066
|
-
naclLowLevel.S(chk, r[0]);
|
|
2067
|
-
naclLowLevel.M(chk, chk, den);
|
|
2068
|
-
if (neq25519(chk, num)) naclLowLevel.M(r[0], r[0], I);
|
|
2069
|
-
naclLowLevel.S(chk, r[0]);
|
|
2070
|
-
naclLowLevel.M(chk, chk, den);
|
|
2071
|
-
if (neq25519(chk, num)) return 0;
|
|
2072
|
-
return 1;
|
|
2073
|
-
}
|
|
2074
|
-
|
|
2075
|
-
let gf1 = naclLowLevel.gf([1]);
|
|
2076
|
-
let I = naclLowLevel.gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
2077
|
-
|
|
2078
|
-
function neq25519(a, b) {
|
|
2079
|
-
var c = new Uint8Array(32),
|
|
2080
|
-
d = new Uint8Array(32);
|
|
2081
|
-
naclLowLevel.pack25519(c, a);
|
|
2082
|
-
naclLowLevel.pack25519(d, b);
|
|
2083
|
-
return naclLowLevel.crypto_verify_32(c, 0, d, 0);
|
|
2084
|
-
}
|
|
350
|
+
});
|
|
2085
351
|
|
|
2086
352
|
/**
|
|
2087
353
|
* An account key pair (public and secret keys).
|
|
@@ -2092,6 +358,8 @@ function neq25519(a, b) {
|
|
|
2092
358
|
class Account {
|
|
2093
359
|
/** @internal */
|
|
2094
360
|
|
|
361
|
+
/** @internal */
|
|
362
|
+
|
|
2095
363
|
/**
|
|
2096
364
|
* Create a new Account object
|
|
2097
365
|
*
|
|
@@ -2101,12 +369,21 @@ class Account {
|
|
|
2101
369
|
* @param secretKey Secret key for the account
|
|
2102
370
|
*/
|
|
2103
371
|
constructor(secretKey) {
|
|
2104
|
-
this.
|
|
372
|
+
this._publicKey = void 0;
|
|
373
|
+
this._secretKey = void 0;
|
|
2105
374
|
|
|
2106
375
|
if (secretKey) {
|
|
2107
|
-
|
|
376
|
+
const secretKeyBuffer = toBuffer(secretKey);
|
|
377
|
+
|
|
378
|
+
if (secretKey.length !== 64) {
|
|
379
|
+
throw new Error('bad secret key size');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
this._publicKey = secretKeyBuffer.slice(32, 64);
|
|
383
|
+
this._secretKey = secretKeyBuffer.slice(0, 32);
|
|
2108
384
|
} else {
|
|
2109
|
-
this.
|
|
385
|
+
this._secretKey = toBuffer(generatePrivateKey());
|
|
386
|
+
this._publicKey = toBuffer(getPublicKey(this._secretKey));
|
|
2110
387
|
}
|
|
2111
388
|
}
|
|
2112
389
|
/**
|
|
@@ -2115,15 +392,17 @@ class Account {
|
|
|
2115
392
|
|
|
2116
393
|
|
|
2117
394
|
get publicKey() {
|
|
2118
|
-
return new PublicKey(this.
|
|
395
|
+
return new PublicKey(this._publicKey);
|
|
2119
396
|
}
|
|
2120
397
|
/**
|
|
2121
|
-
* The **unencrypted** secret key for this account
|
|
398
|
+
* The **unencrypted** secret key for this account. The first 32 bytes
|
|
399
|
+
* is the private scalar and the last 32 bytes is the public key.
|
|
400
|
+
* Read more: https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/
|
|
2122
401
|
*/
|
|
2123
402
|
|
|
2124
403
|
|
|
2125
404
|
get secretKey() {
|
|
2126
|
-
return
|
|
405
|
+
return buffer.Buffer.concat([this._secretKey, this._publicKey], 64);
|
|
2127
406
|
}
|
|
2128
407
|
|
|
2129
408
|
}
|
|
@@ -2138,6 +417,7 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
|
|
|
2138
417
|
* 8 bytes is the size of the fragment header
|
|
2139
418
|
*/
|
|
2140
419
|
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
420
|
+
const VERSION_PREFIX_MASK = 0x7f;
|
|
2141
421
|
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2142
422
|
|
|
2143
423
|
class TransactionExpiredBlockheightExceededError extends Error {
|
|
@@ -2170,6 +450,13 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
2170
450
|
const publicKey = (property = 'publicKey') => {
|
|
2171
451
|
return BufferLayout__namespace.blob(32, property);
|
|
2172
452
|
};
|
|
453
|
+
/**
|
|
454
|
+
* Layout for a signature
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
const signature = (property = 'signature') => {
|
|
458
|
+
return BufferLayout__namespace.blob(64, property);
|
|
459
|
+
};
|
|
2173
460
|
|
|
2174
461
|
/**
|
|
2175
462
|
* Layout for a Rust String type
|
|
@@ -2281,11 +568,9 @@ function encodeLength(bytes, len) {
|
|
|
2281
568
|
}
|
|
2282
569
|
}
|
|
2283
570
|
|
|
2284
|
-
const PUBKEY_LENGTH = 32;
|
|
2285
571
|
/**
|
|
2286
572
|
* List of instructions to be processed atomically
|
|
2287
573
|
*/
|
|
2288
|
-
|
|
2289
574
|
class Message {
|
|
2290
575
|
constructor(args) {
|
|
2291
576
|
this.header = void 0;
|
|
@@ -2300,6 +585,26 @@ class Message {
|
|
|
2300
585
|
this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
|
|
2301
586
|
}
|
|
2302
587
|
|
|
588
|
+
get version() {
|
|
589
|
+
return 'legacy';
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
get staticAccountKeys() {
|
|
593
|
+
return this.accountKeys;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
get compiledInstructions() {
|
|
597
|
+
return this.instructions.map(ix => ({
|
|
598
|
+
programIdIndex: ix.programIdIndex,
|
|
599
|
+
accountKeyIndexes: ix.accounts,
|
|
600
|
+
data: bs58__default["default"].decode(ix.data)
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
get addressTableLookups() {
|
|
605
|
+
return [];
|
|
606
|
+
}
|
|
607
|
+
|
|
2303
608
|
isAccountSigner(index) {
|
|
2304
609
|
return index < this.header.numRequiredSignatures;
|
|
2305
610
|
}
|
|
@@ -2376,19 +681,24 @@ class Message {
|
|
|
2376
681
|
// Slice up wire data
|
|
2377
682
|
let byteArray = [...buffer$1];
|
|
2378
683
|
const numRequiredSignatures = byteArray.shift();
|
|
684
|
+
|
|
685
|
+
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
686
|
+
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
687
|
+
}
|
|
688
|
+
|
|
2379
689
|
const numReadonlySignedAccounts = byteArray.shift();
|
|
2380
690
|
const numReadonlyUnsignedAccounts = byteArray.shift();
|
|
2381
691
|
const accountCount = decodeLength(byteArray);
|
|
2382
692
|
let accountKeys = [];
|
|
2383
693
|
|
|
2384
694
|
for (let i = 0; i < accountCount; i++) {
|
|
2385
|
-
const account = byteArray.slice(0,
|
|
2386
|
-
byteArray = byteArray.slice(
|
|
695
|
+
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
696
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
2387
697
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
2388
698
|
}
|
|
2389
699
|
|
|
2390
|
-
const recentBlockhash = byteArray.slice(0,
|
|
2391
|
-
byteArray = byteArray.slice(
|
|
700
|
+
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
701
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
2392
702
|
const instructionCount = decodeLength(byteArray);
|
|
2393
703
|
let instructions = [];
|
|
2394
704
|
|
|
@@ -2429,6 +739,194 @@ function assert (condition, message) {
|
|
|
2429
739
|
}
|
|
2430
740
|
}
|
|
2431
741
|
|
|
742
|
+
/**
|
|
743
|
+
* Message constructor arguments
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
class MessageV0 {
|
|
747
|
+
constructor(args) {
|
|
748
|
+
this.header = void 0;
|
|
749
|
+
this.staticAccountKeys = void 0;
|
|
750
|
+
this.recentBlockhash = void 0;
|
|
751
|
+
this.compiledInstructions = void 0;
|
|
752
|
+
this.addressTableLookups = void 0;
|
|
753
|
+
this.header = args.header;
|
|
754
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
755
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
756
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
757
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
get version() {
|
|
761
|
+
return 0;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
serialize() {
|
|
765
|
+
const encodedStaticAccountKeysLength = Array();
|
|
766
|
+
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
767
|
+
const serializedInstructions = this.serializeInstructions();
|
|
768
|
+
const encodedInstructionsLength = Array();
|
|
769
|
+
encodeLength(encodedInstructionsLength, this.compiledInstructions.length);
|
|
770
|
+
const serializedAddressTableLookups = this.serializeAddressTableLookups();
|
|
771
|
+
const encodedAddressTableLookupsLength = Array();
|
|
772
|
+
encodeLength(encodedAddressTableLookupsLength, this.addressTableLookups.length);
|
|
773
|
+
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')]);
|
|
774
|
+
const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
|
|
775
|
+
const MESSAGE_VERSION_0_PREFIX = 1 << 7;
|
|
776
|
+
const serializedMessageLength = messageLayout.encode({
|
|
777
|
+
prefix: MESSAGE_VERSION_0_PREFIX,
|
|
778
|
+
header: this.header,
|
|
779
|
+
staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
|
|
780
|
+
staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
|
|
781
|
+
recentBlockhash: bs58__default["default"].decode(this.recentBlockhash),
|
|
782
|
+
instructionsLength: new Uint8Array(encodedInstructionsLength),
|
|
783
|
+
serializedInstructions,
|
|
784
|
+
addressTableLookupsLength: new Uint8Array(encodedAddressTableLookupsLength),
|
|
785
|
+
serializedAddressTableLookups
|
|
786
|
+
}, serializedMessage);
|
|
787
|
+
return serializedMessage.slice(0, serializedMessageLength);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
serializeInstructions() {
|
|
791
|
+
let serializedLength = 0;
|
|
792
|
+
const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
|
|
793
|
+
|
|
794
|
+
for (const instruction of this.compiledInstructions) {
|
|
795
|
+
const encodedAccountKeyIndexesLength = Array();
|
|
796
|
+
encodeLength(encodedAccountKeyIndexesLength, instruction.accountKeyIndexes.length);
|
|
797
|
+
const encodedDataLength = Array();
|
|
798
|
+
encodeLength(encodedDataLength, instruction.data.length);
|
|
799
|
+
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')]);
|
|
800
|
+
serializedLength += instructionLayout.encode({
|
|
801
|
+
programIdIndex: instruction.programIdIndex,
|
|
802
|
+
encodedAccountKeyIndexesLength: new Uint8Array(encodedAccountKeyIndexesLength),
|
|
803
|
+
accountKeyIndexes: instruction.accountKeyIndexes,
|
|
804
|
+
encodedDataLength: new Uint8Array(encodedDataLength),
|
|
805
|
+
data: instruction.data
|
|
806
|
+
}, serializedInstructions, serializedLength);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
return serializedInstructions.slice(0, serializedLength);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
serializeAddressTableLookups() {
|
|
813
|
+
let serializedLength = 0;
|
|
814
|
+
const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
|
|
815
|
+
|
|
816
|
+
for (const lookup of this.addressTableLookups) {
|
|
817
|
+
const encodedWritableIndexesLength = Array();
|
|
818
|
+
encodeLength(encodedWritableIndexesLength, lookup.writableIndexes.length);
|
|
819
|
+
const encodedReadonlyIndexesLength = Array();
|
|
820
|
+
encodeLength(encodedReadonlyIndexesLength, lookup.readonlyIndexes.length);
|
|
821
|
+
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')]);
|
|
822
|
+
serializedLength += addressTableLookupLayout.encode({
|
|
823
|
+
accountKey: lookup.accountKey.toBytes(),
|
|
824
|
+
encodedWritableIndexesLength: new Uint8Array(encodedWritableIndexesLength),
|
|
825
|
+
writableIndexes: lookup.writableIndexes,
|
|
826
|
+
encodedReadonlyIndexesLength: new Uint8Array(encodedReadonlyIndexesLength),
|
|
827
|
+
readonlyIndexes: lookup.readonlyIndexes
|
|
828
|
+
}, serializedAddressTableLookups, serializedLength);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
return serializedAddressTableLookups.slice(0, serializedLength);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
static deserialize(serializedMessage) {
|
|
835
|
+
let byteArray = [...serializedMessage];
|
|
836
|
+
const prefix = byteArray.shift();
|
|
837
|
+
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
838
|
+
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
839
|
+
const version = maskedPrefix;
|
|
840
|
+
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
841
|
+
const header = {
|
|
842
|
+
numRequiredSignatures: byteArray.shift(),
|
|
843
|
+
numReadonlySignedAccounts: byteArray.shift(),
|
|
844
|
+
numReadonlyUnsignedAccounts: byteArray.shift()
|
|
845
|
+
};
|
|
846
|
+
const staticAccountKeys = [];
|
|
847
|
+
const staticAccountKeysLength = decodeLength(byteArray);
|
|
848
|
+
|
|
849
|
+
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
850
|
+
staticAccountKeys.push(new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)));
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
const recentBlockhash = bs58__default["default"].encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
|
|
854
|
+
const instructionCount = decodeLength(byteArray);
|
|
855
|
+
const compiledInstructions = [];
|
|
856
|
+
|
|
857
|
+
for (let i = 0; i < instructionCount; i++) {
|
|
858
|
+
const programIdIndex = byteArray.shift();
|
|
859
|
+
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
860
|
+
const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
|
|
861
|
+
const dataLength = decodeLength(byteArray);
|
|
862
|
+
const data = new Uint8Array(byteArray.splice(0, dataLength));
|
|
863
|
+
compiledInstructions.push({
|
|
864
|
+
programIdIndex,
|
|
865
|
+
accountKeyIndexes,
|
|
866
|
+
data
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
const addressTableLookupsCount = decodeLength(byteArray);
|
|
871
|
+
const addressTableLookups = [];
|
|
872
|
+
|
|
873
|
+
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
874
|
+
const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
|
|
875
|
+
const writableIndexesLength = decodeLength(byteArray);
|
|
876
|
+
const writableIndexes = byteArray.splice(0, writableIndexesLength);
|
|
877
|
+
const readonlyIndexesLength = decodeLength(byteArray);
|
|
878
|
+
const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
|
|
879
|
+
addressTableLookups.push({
|
|
880
|
+
accountKey,
|
|
881
|
+
writableIndexes,
|
|
882
|
+
readonlyIndexes
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
return new MessageV0({
|
|
887
|
+
header,
|
|
888
|
+
staticAccountKeys,
|
|
889
|
+
recentBlockhash,
|
|
890
|
+
compiledInstructions,
|
|
891
|
+
addressTableLookups
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// eslint-disable-next-line no-redeclare
|
|
898
|
+
const VersionedMessage = {
|
|
899
|
+
deserializeMessageVersion(serializedMessage) {
|
|
900
|
+
const prefix = serializedMessage[0];
|
|
901
|
+
const maskedPrefix = prefix & VERSION_PREFIX_MASK; // if the highest bit of the prefix is not set, the message is not versioned
|
|
902
|
+
|
|
903
|
+
if (maskedPrefix === prefix) {
|
|
904
|
+
return 'legacy';
|
|
905
|
+
} // the lower 7 bits of the prefix indicate the message version
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
return maskedPrefix;
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
deserialize: serializedMessage => {
|
|
912
|
+
const version = VersionedMessage.deserializeMessageVersion(serializedMessage);
|
|
913
|
+
|
|
914
|
+
if (version === 'legacy') {
|
|
915
|
+
return Message.from(serializedMessage);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
if (version === 0) {
|
|
919
|
+
return MessageV0.deserialize(serializedMessage);
|
|
920
|
+
} else {
|
|
921
|
+
throw new Error(`Transaction message version ${version} deserialization is not supported`);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Transaction signature as base-58 encoded string
|
|
928
|
+
*/
|
|
929
|
+
|
|
2432
930
|
exports.TransactionStatus = void 0;
|
|
2433
931
|
/**
|
|
2434
932
|
* Default (empty) signature
|
|
@@ -2954,7 +1452,7 @@ class Transaction {
|
|
|
2954
1452
|
_partialSign(message, ...signers) {
|
|
2955
1453
|
const signData = message.serialize();
|
|
2956
1454
|
signers.forEach(signer => {
|
|
2957
|
-
const signature =
|
|
1455
|
+
const signature = sign(signData, signer.secretKey);
|
|
2958
1456
|
|
|
2959
1457
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2960
1458
|
});
|
|
@@ -3010,7 +1508,7 @@ class Transaction {
|
|
|
3010
1508
|
return false;
|
|
3011
1509
|
}
|
|
3012
1510
|
} else {
|
|
3013
|
-
if (!
|
|
1511
|
+
if (!verify(signature, signData, publicKey.toBuffer())) {
|
|
3014
1512
|
return false;
|
|
3015
1513
|
}
|
|
3016
1514
|
}
|
|
@@ -3157,6 +1655,70 @@ class Transaction {
|
|
|
3157
1655
|
|
|
3158
1656
|
}
|
|
3159
1657
|
|
|
1658
|
+
/**
|
|
1659
|
+
* Versioned transaction class
|
|
1660
|
+
*/
|
|
1661
|
+
class VersionedTransaction {
|
|
1662
|
+
constructor(message, signatures) {
|
|
1663
|
+
this.signatures = void 0;
|
|
1664
|
+
this.message = void 0;
|
|
1665
|
+
|
|
1666
|
+
if (signatures !== undefined) {
|
|
1667
|
+
assert(signatures.length === message.header.numRequiredSignatures, 'Expected signatures length to be equal to the number of required signatures');
|
|
1668
|
+
this.signatures = signatures;
|
|
1669
|
+
} else {
|
|
1670
|
+
const defaultSignatures = [];
|
|
1671
|
+
|
|
1672
|
+
for (let i = 0; i < message.header.numRequiredSignatures; i++) {
|
|
1673
|
+
defaultSignatures.push(new Uint8Array(SIGNATURE_LENGTH_IN_BYTES));
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
this.signatures = defaultSignatures;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
this.message = message;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
serialize() {
|
|
1683
|
+
const serializedMessage = this.message.serialize();
|
|
1684
|
+
const encodedSignaturesLength = Array();
|
|
1685
|
+
encodeLength(encodedSignaturesLength, this.signatures.length);
|
|
1686
|
+
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')]);
|
|
1687
|
+
const serializedTransaction = new Uint8Array(2048);
|
|
1688
|
+
const serializedTransactionLength = transactionLayout.encode({
|
|
1689
|
+
encodedSignaturesLength: new Uint8Array(encodedSignaturesLength),
|
|
1690
|
+
signatures: this.signatures,
|
|
1691
|
+
serializedMessage
|
|
1692
|
+
}, serializedTransaction);
|
|
1693
|
+
return serializedTransaction.slice(0, serializedTransactionLength);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
static deserialize(serializedTransaction) {
|
|
1697
|
+
let byteArray = [...serializedTransaction];
|
|
1698
|
+
const signatures = [];
|
|
1699
|
+
const signaturesLength = decodeLength(byteArray);
|
|
1700
|
+
|
|
1701
|
+
for (let i = 0; i < signaturesLength; i++) {
|
|
1702
|
+
signatures.push(new Uint8Array(byteArray.splice(0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1706
|
+
return new VersionedTransaction(message, signatures);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
sign(signers) {
|
|
1710
|
+
const messageData = this.message.serialize();
|
|
1711
|
+
const signerPubkeys = this.message.staticAccountKeys.slice(0, this.message.header.numRequiredSignatures);
|
|
1712
|
+
|
|
1713
|
+
for (const signer of signers) {
|
|
1714
|
+
const signerIndex = signerPubkeys.findIndex(pubkey => pubkey.equals(signer.publicKey));
|
|
1715
|
+
assert(signerIndex >= 0, `Cannot sign with non signer key ${signer.publicKey.toBase58()}`);
|
|
1716
|
+
this.signatures[signerIndex] = sign(messageData, signer.secretKey);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
}
|
|
1721
|
+
|
|
3160
1722
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
3161
1723
|
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
3162
1724
|
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
@@ -4602,24 +3164,26 @@ const LookupTableMetaLayout = {
|
|
|
4602
3164
|
BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u8(), -1), 'authority')])
|
|
4603
3165
|
};
|
|
4604
3166
|
|
|
4605
|
-
const
|
|
4606
|
-
|
|
3167
|
+
const URL_RE = /^[^:]+:\/\/([^:[]+|\[[^\]]+\])(:\d+)?(.*)/i;
|
|
4607
3168
|
function makeWebsocketUrl(endpoint) {
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
3169
|
+
const matches = endpoint.match(URL_RE);
|
|
3170
|
+
|
|
3171
|
+
if (matches == null) {
|
|
3172
|
+
throw TypeError(`Failed to validate endpoint URL \`${endpoint}\``);
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
const [_, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
3176
|
+
hostish, portWithColon, rest] = matches;
|
|
3177
|
+
const protocol = endpoint.startsWith('https:') ? 'wss:' : 'ws:';
|
|
3178
|
+
const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
|
|
3179
|
+
const websocketPort = // Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
4612
3180
|
// is explictly specifying the endpoint port (HTTP-based RPC), assuming
|
|
4613
3181
|
// we're directly trying to connect to solana-validator's ws listening port.
|
|
4614
3182
|
// When the endpoint omits the port, we're connecting to the protocol
|
|
4615
3183
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
4616
3184
|
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
url.port = String(Number(url.port) + 1);
|
|
4620
|
-
}
|
|
4621
|
-
|
|
4622
|
-
return url.toString();
|
|
3185
|
+
startPort == null ? '' : `:${startPort + 1}`;
|
|
3186
|
+
return `${protocol}//${hostish}${websocketPort}${rest}`;
|
|
4623
3187
|
}
|
|
4624
3188
|
|
|
4625
3189
|
var _process$env$npm_pack;
|
|
@@ -4639,7 +3203,17 @@ const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
|
|
|
4639
3203
|
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
|
|
4640
3204
|
*/
|
|
4641
3205
|
|
|
3206
|
+
/* @internal */
|
|
3207
|
+
function assertEndpointUrl(putativeUrl) {
|
|
3208
|
+
if (/^https?:/.test(putativeUrl) === false) {
|
|
3209
|
+
throw new TypeError('Endpoint URL must start with `http:` or `https:`.');
|
|
3210
|
+
}
|
|
3211
|
+
|
|
3212
|
+
return putativeUrl;
|
|
3213
|
+
}
|
|
4642
3214
|
/** @internal */
|
|
3215
|
+
|
|
3216
|
+
|
|
4643
3217
|
function extractCommitmentFromConfig(commitmentOrConfig) {
|
|
4644
3218
|
let commitment;
|
|
4645
3219
|
let config;
|
|
@@ -4834,12 +3408,14 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
|
|
|
4834
3408
|
* A performance sample
|
|
4835
3409
|
*/
|
|
4836
3410
|
|
|
4837
|
-
function createRpcClient(url,
|
|
3411
|
+
function createRpcClient(url, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
|
|
4838
3412
|
const fetch = customFetch ? customFetch : fetchImpl;
|
|
4839
3413
|
let agentManager;
|
|
4840
3414
|
|
|
4841
3415
|
{
|
|
4842
|
-
agentManager = new AgentManager(
|
|
3416
|
+
agentManager = new AgentManager(url.startsWith('https:')
|
|
3417
|
+
/* useHttps */
|
|
3418
|
+
);
|
|
4843
3419
|
}
|
|
4844
3420
|
|
|
4845
3421
|
let fetchWithMiddleware;
|
|
@@ -5646,8 +4222,6 @@ class Connection {
|
|
|
5646
4222
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
5647
4223
|
this._subscriptionsByHash = {};
|
|
5648
4224
|
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
5649
|
-
let url = new URL(endpoint);
|
|
5650
|
-
const useHttps = url.protocol === 'https:';
|
|
5651
4225
|
let wsEndpoint;
|
|
5652
4226
|
let httpHeaders;
|
|
5653
4227
|
let fetch;
|
|
@@ -5666,9 +4240,9 @@ class Connection {
|
|
|
5666
4240
|
disableRetryOnRateLimit = commitmentOrConfig.disableRetryOnRateLimit;
|
|
5667
4241
|
}
|
|
5668
4242
|
|
|
5669
|
-
this._rpcEndpoint = endpoint;
|
|
4243
|
+
this._rpcEndpoint = assertEndpointUrl(endpoint);
|
|
5670
4244
|
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
5671
|
-
this._rpcClient = createRpcClient(
|
|
4245
|
+
this._rpcClient = createRpcClient(endpoint, httpHeaders, fetch, fetchMiddleware, disableRetryOnRateLimit);
|
|
5672
4246
|
this._rpcRequest = createRpcRequest(this._rpcClient);
|
|
5673
4247
|
this._rpcBatchRequest = createRpcBatchRequest(this._rpcClient);
|
|
5674
4248
|
this._rpcWebSocket = new rpcWebsockets.Client(this._rpcWsEndpoint, {
|
|
@@ -8345,12 +6919,7 @@ class Keypair {
|
|
|
8345
6919
|
*/
|
|
8346
6920
|
constructor(keypair) {
|
|
8347
6921
|
this._keypair = void 0;
|
|
8348
|
-
|
|
8349
|
-
if (keypair) {
|
|
8350
|
-
this._keypair = keypair;
|
|
8351
|
-
} else {
|
|
8352
|
-
this._keypair = nacl__default["default"].sign.keyPair();
|
|
8353
|
-
}
|
|
6922
|
+
this._keypair = keypair !== null && keypair !== void 0 ? keypair : generateKeypair();
|
|
8354
6923
|
}
|
|
8355
6924
|
/**
|
|
8356
6925
|
* Generate a new random keypair
|
|
@@ -8358,7 +6927,7 @@ class Keypair {
|
|
|
8358
6927
|
|
|
8359
6928
|
|
|
8360
6929
|
static generate() {
|
|
8361
|
-
return new Keypair(
|
|
6930
|
+
return new Keypair(generateKeypair());
|
|
8362
6931
|
}
|
|
8363
6932
|
/**
|
|
8364
6933
|
* Create a keypair from a raw secret key byte array.
|
|
@@ -8375,19 +6944,27 @@ class Keypair {
|
|
|
8375
6944
|
|
|
8376
6945
|
|
|
8377
6946
|
static fromSecretKey(secretKey, options) {
|
|
8378
|
-
|
|
6947
|
+
if (secretKey.byteLength !== 64) {
|
|
6948
|
+
throw new Error('bad secret key size');
|
|
6949
|
+
}
|
|
6950
|
+
|
|
6951
|
+
const publicKey = secretKey.slice(32, 64);
|
|
8379
6952
|
|
|
8380
6953
|
if (!options || !options.skipValidation) {
|
|
8381
|
-
const
|
|
8382
|
-
const
|
|
8383
|
-
const signature = nacl__default["default"].sign.detached(signData, keypair.secretKey);
|
|
6954
|
+
const privateScalar = secretKey.slice(0, 32);
|
|
6955
|
+
const computedPublicKey = getPublicKey(privateScalar);
|
|
8384
6956
|
|
|
8385
|
-
|
|
8386
|
-
|
|
6957
|
+
for (let ii = 0; ii < 32; ii++) {
|
|
6958
|
+
if (publicKey[ii] !== computedPublicKey[ii]) {
|
|
6959
|
+
throw new Error('provided secretKey is invalid');
|
|
6960
|
+
}
|
|
8387
6961
|
}
|
|
8388
6962
|
}
|
|
8389
6963
|
|
|
8390
|
-
return new Keypair(
|
|
6964
|
+
return new Keypair({
|
|
6965
|
+
publicKey,
|
|
6966
|
+
secretKey
|
|
6967
|
+
});
|
|
8391
6968
|
}
|
|
8392
6969
|
/**
|
|
8393
6970
|
* Generate a keypair from a 32 byte seed.
|
|
@@ -8397,7 +6974,14 @@ class Keypair {
|
|
|
8397
6974
|
|
|
8398
6975
|
|
|
8399
6976
|
static fromSeed(seed) {
|
|
8400
|
-
|
|
6977
|
+
const publicKey = getPublicKey(seed);
|
|
6978
|
+
const secretKey = new Uint8Array(64);
|
|
6979
|
+
secretKey.set(seed);
|
|
6980
|
+
secretKey.set(publicKey, 32);
|
|
6981
|
+
return new Keypair({
|
|
6982
|
+
publicKey,
|
|
6983
|
+
secretKey
|
|
6984
|
+
});
|
|
8401
6985
|
}
|
|
8402
6986
|
/**
|
|
8403
6987
|
* The public key for this keypair
|
|
@@ -8949,7 +7533,7 @@ class Ed25519Program {
|
|
|
8949
7533
|
try {
|
|
8950
7534
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
8951
7535
|
const publicKey = keypair.publicKey.toBytes();
|
|
8952
|
-
const signature =
|
|
7536
|
+
const signature = sign(message, keypair.secretKey);
|
|
8953
7537
|
return this.createInstructionWithPublicKey({
|
|
8954
7538
|
publicKey,
|
|
8955
7539
|
message,
|
|
@@ -8964,10 +7548,21 @@ class Ed25519Program {
|
|
|
8964
7548
|
}
|
|
8965
7549
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
8966
7550
|
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
7551
|
+
// library interoperable with the synchronous APIs in web3.js.
|
|
7552
|
+
|
|
7553
|
+
secp256k1__namespace.utils.hmacSha256Sync = (key, ...msgs) => {
|
|
7554
|
+
const h = hmac.hmac.create(sha256.sha256, key);
|
|
7555
|
+
msgs.forEach(msg => h.update(msg));
|
|
7556
|
+
return h.digest();
|
|
7557
|
+
};
|
|
7558
|
+
|
|
7559
|
+
const ecdsaSign = (msgHash, privKey) => secp256k1__namespace.signSync(msgHash, privKey, {
|
|
7560
|
+
der: false,
|
|
7561
|
+
recovered: true
|
|
7562
|
+
});
|
|
7563
|
+
secp256k1__namespace.utils.isValidPrivateKey;
|
|
7564
|
+
const publicKeyCreate = secp256k1__namespace.getPublicKey;
|
|
7565
|
+
|
|
8971
7566
|
const PRIVATE_KEY_BYTES = 32;
|
|
8972
7567
|
const ETHEREUM_ADDRESS_BYTES = 20;
|
|
8973
7568
|
const PUBLIC_KEY_BYTES = 64;
|
|
@@ -9091,13 +7686,12 @@ class Secp256k1Program {
|
|
|
9091
7686
|
|
|
9092
7687
|
try {
|
|
9093
7688
|
const privateKey = toBuffer(pkey);
|
|
9094
|
-
const publicKey = publicKeyCreate(privateKey, false
|
|
7689
|
+
const publicKey = publicKeyCreate(privateKey, false
|
|
7690
|
+
/* isCompressed */
|
|
7691
|
+
).slice(1); // throw away leading byte
|
|
9095
7692
|
|
|
9096
7693
|
const messageHash = buffer.Buffer.from(sha3__default["default"].keccak_256.update(toBuffer(message)).digest());
|
|
9097
|
-
const
|
|
9098
|
-
signature,
|
|
9099
|
-
recid: recoveryId
|
|
9100
|
-
} = ecdsaSign(messageHash, privateKey);
|
|
7694
|
+
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
9101
7695
|
return this.createInstructionWithPublicKey({
|
|
9102
7696
|
publicKey,
|
|
9103
7697
|
message,
|
|
@@ -10209,6 +8803,23 @@ class VoteProgram {
|
|
|
10209
8803
|
data
|
|
10210
8804
|
});
|
|
10211
8805
|
}
|
|
8806
|
+
/**
|
|
8807
|
+
* Generate a transaction to withdraw safely from a Vote account.
|
|
8808
|
+
*
|
|
8809
|
+
* This function was created as a safeguard for vote accounts running validators, `safeWithdraw`
|
|
8810
|
+
* checks that the withdraw amount will not exceed the specified balance while leaving enough left
|
|
8811
|
+
* to cover rent. If you wish to close the vote account by withdrawing the full amount, call the
|
|
8812
|
+
* `withdraw` method directly.
|
|
8813
|
+
*/
|
|
8814
|
+
|
|
8815
|
+
|
|
8816
|
+
static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
|
|
8817
|
+
if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
|
|
8818
|
+
throw new Error('Withdraw will leave vote account with insuffcient funds.');
|
|
8819
|
+
}
|
|
8820
|
+
|
|
8821
|
+
return VoteProgram.withdraw(params);
|
|
8822
|
+
}
|
|
10212
8823
|
|
|
10213
8824
|
}
|
|
10214
8825
|
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
@@ -10260,15 +8871,14 @@ class ValidatorInfo {
|
|
|
10260
8871
|
|
|
10261
8872
|
|
|
10262
8873
|
static fromConfigData(buffer$1) {
|
|
10263
|
-
const PUBKEY_LENGTH = 32;
|
|
10264
8874
|
let byteArray = [...buffer$1];
|
|
10265
8875
|
const configKeyCount = decodeLength(byteArray);
|
|
10266
8876
|
if (configKeyCount !== 2) return null;
|
|
10267
8877
|
const configKeys = [];
|
|
10268
8878
|
|
|
10269
8879
|
for (let i = 0; i < 2; i++) {
|
|
10270
|
-
const publicKey = new PublicKey(byteArray.slice(0,
|
|
10271
|
-
byteArray = byteArray.slice(
|
|
8880
|
+
const publicKey = new PublicKey(byteArray.slice(0, PUBLIC_KEY_LENGTH));
|
|
8881
|
+
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
10272
8882
|
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10273
8883
|
byteArray = byteArray.slice(1);
|
|
10274
8884
|
configKeys.push({
|
|
@@ -10504,9 +9114,11 @@ exports.Loader = Loader;
|
|
|
10504
9114
|
exports.Lockup = Lockup;
|
|
10505
9115
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|
|
10506
9116
|
exports.Message = Message;
|
|
9117
|
+
exports.MessageV0 = MessageV0;
|
|
10507
9118
|
exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
10508
9119
|
exports.NonceAccount = NonceAccount;
|
|
10509
9120
|
exports.PACKET_DATA_SIZE = PACKET_DATA_SIZE;
|
|
9121
|
+
exports.PUBLIC_KEY_LENGTH = PUBLIC_KEY_LENGTH;
|
|
10510
9122
|
exports.PublicKey = PublicKey;
|
|
10511
9123
|
exports.SIGNATURE_LENGTH_IN_BYTES = SIGNATURE_LENGTH_IN_BYTES;
|
|
10512
9124
|
exports.SOLANA_SCHEMA = SOLANA_SCHEMA;
|
|
@@ -10537,8 +9149,11 @@ exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheig
|
|
|
10537
9149
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
10538
9150
|
exports.TransactionInstruction = TransactionInstruction;
|
|
10539
9151
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
9152
|
+
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
10540
9153
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|
|
10541
9154
|
exports.ValidatorInfo = ValidatorInfo;
|
|
9155
|
+
exports.VersionedMessage = VersionedMessage;
|
|
9156
|
+
exports.VersionedTransaction = VersionedTransaction;
|
|
10542
9157
|
exports.VoteAccount = VoteAccount;
|
|
10543
9158
|
exports.VoteAuthorizationLayout = VoteAuthorizationLayout;
|
|
10544
9159
|
exports.VoteInit = VoteInit;
|