@solana/web3.js 1.29.3 → 1.31.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/README.md +2 -2
- package/lib/index.browser.esm.js +1018 -1089
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +913 -988
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +12 -1
- package/lib/index.esm.js +910 -985
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +28735 -28823
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +31 -31
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +19 -1
- package/package.json +9 -9
- package/src/account.ts +1 -1
- package/src/connection.ts +31 -10
- package/src/keypair.ts +1 -1
- package/src/publickey.ts +3 -3
- package/src/secp256k1-program.ts +5 -5
package/lib/index.browser.esm.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as nacl from 'tweetnacl';
|
|
3
|
-
import nacl__default from 'tweetnacl';
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
4
2
|
import { Buffer } from 'buffer';
|
|
5
3
|
import BN from 'bn.js';
|
|
6
4
|
import bs58 from 'bs58';
|
|
@@ -10,7 +8,7 @@ import { coerce, instance, string, tuple, literal, unknown, union, type, optiona
|
|
|
10
8
|
import { Client } from 'rpc-websockets';
|
|
11
9
|
import RpcClient from 'jayson/lib/client/browser';
|
|
12
10
|
import secp256k1 from 'secp256k1';
|
|
13
|
-
import
|
|
11
|
+
import sha3 from 'js-sha3';
|
|
14
12
|
|
|
15
13
|
const toBuffer = arr => {
|
|
16
14
|
if (Buffer.isBuffer(arr)) {
|
|
@@ -22,884 +20,475 @@ const toBuffer = arr => {
|
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
function getDefaultExportFromCjs (x) {
|
|
26
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var hash$1 = {};
|
|
30
|
+
|
|
31
|
+
var utils$9 = {};
|
|
32
|
+
|
|
33
|
+
var minimalisticAssert = assert$6;
|
|
34
|
+
|
|
35
|
+
function assert$6(val, msg) {
|
|
36
|
+
if (!val)
|
|
37
|
+
throw new Error(msg || 'Assertion failed');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
assert$6.equal = function assertEqual(l, r, msg) {
|
|
41
|
+
if (l != r)
|
|
42
|
+
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var inherits_browser = {exports: {}};
|
|
46
|
+
|
|
47
|
+
if (typeof Object.create === 'function') {
|
|
48
|
+
// implementation from standard node.js 'util' module
|
|
49
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
50
|
+
ctor.super_ = superCtor;
|
|
51
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
|
52
|
+
constructor: {
|
|
53
|
+
value: ctor,
|
|
54
|
+
enumerable: false,
|
|
55
|
+
writable: true,
|
|
56
|
+
configurable: true
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
// old school shim for old browsers
|
|
62
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
63
|
+
ctor.super_ = superCtor;
|
|
64
|
+
var TempCtor = function () {};
|
|
65
|
+
TempCtor.prototype = superCtor.prototype;
|
|
66
|
+
ctor.prototype = new TempCtor();
|
|
67
|
+
ctor.prototype.constructor = ctor;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var assert$5 = minimalisticAssert;
|
|
72
|
+
var inherits = inherits_browser.exports;
|
|
73
|
+
|
|
74
|
+
utils$9.inherits = inherits;
|
|
75
|
+
|
|
76
|
+
function isSurrogatePair(msg, i) {
|
|
77
|
+
if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (i < 0 || i + 1 >= msg.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function toArray(msg, enc) {
|
|
87
|
+
if (Array.isArray(msg))
|
|
88
|
+
return msg.slice();
|
|
89
|
+
if (!msg)
|
|
90
|
+
return [];
|
|
91
|
+
var res = [];
|
|
92
|
+
if (typeof msg === 'string') {
|
|
93
|
+
if (!enc) {
|
|
94
|
+
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
95
|
+
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
96
|
+
// Apache License 2.0
|
|
97
|
+
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
98
|
+
var p = 0;
|
|
99
|
+
for (var i = 0; i < msg.length; i++) {
|
|
100
|
+
var c = msg.charCodeAt(i);
|
|
101
|
+
if (c < 128) {
|
|
102
|
+
res[p++] = c;
|
|
103
|
+
} else if (c < 2048) {
|
|
104
|
+
res[p++] = (c >> 6) | 192;
|
|
105
|
+
res[p++] = (c & 63) | 128;
|
|
106
|
+
} else if (isSurrogatePair(msg, i)) {
|
|
107
|
+
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
108
|
+
res[p++] = (c >> 18) | 240;
|
|
109
|
+
res[p++] = ((c >> 12) & 63) | 128;
|
|
110
|
+
res[p++] = ((c >> 6) & 63) | 128;
|
|
111
|
+
res[p++] = (c & 63) | 128;
|
|
112
|
+
} else {
|
|
113
|
+
res[p++] = (c >> 12) | 224;
|
|
114
|
+
res[p++] = ((c >> 6) & 63) | 128;
|
|
115
|
+
res[p++] = (c & 63) | 128;
|
|
52
116
|
}
|
|
117
|
+
}
|
|
118
|
+
} else if (enc === 'hex') {
|
|
119
|
+
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
120
|
+
if (msg.length % 2 !== 0)
|
|
121
|
+
msg = '0' + msg;
|
|
122
|
+
for (i = 0; i < msg.length; i += 2)
|
|
123
|
+
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
53
124
|
}
|
|
54
|
-
|
|
55
|
-
|
|
125
|
+
} else {
|
|
126
|
+
for (i = 0; i < msg.length; i++)
|
|
127
|
+
res[i] = msg[i] | 0;
|
|
128
|
+
}
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
utils$9.toArray = toArray;
|
|
132
|
+
|
|
133
|
+
function toHex(msg) {
|
|
134
|
+
var res = '';
|
|
135
|
+
for (var i = 0; i < msg.length; i++)
|
|
136
|
+
res += zero2(msg[i].toString(16));
|
|
137
|
+
return res;
|
|
138
|
+
}
|
|
139
|
+
utils$9.toHex = toHex;
|
|
140
|
+
|
|
141
|
+
function htonl(w) {
|
|
142
|
+
var res = (w >>> 24) |
|
|
143
|
+
((w >>> 8) & 0xff00) |
|
|
144
|
+
((w << 8) & 0xff0000) |
|
|
145
|
+
((w & 0xff) << 24);
|
|
146
|
+
return res >>> 0;
|
|
147
|
+
}
|
|
148
|
+
utils$9.htonl = htonl;
|
|
149
|
+
|
|
150
|
+
function toHex32(msg, endian) {
|
|
151
|
+
var res = '';
|
|
152
|
+
for (var i = 0; i < msg.length; i++) {
|
|
153
|
+
var w = msg[i];
|
|
154
|
+
if (endian === 'little')
|
|
155
|
+
w = htonl(w);
|
|
156
|
+
res += zero8(w.toString(16));
|
|
157
|
+
}
|
|
158
|
+
return res;
|
|
159
|
+
}
|
|
160
|
+
utils$9.toHex32 = toHex32;
|
|
161
|
+
|
|
162
|
+
function zero2(word) {
|
|
163
|
+
if (word.length === 1)
|
|
164
|
+
return '0' + word;
|
|
165
|
+
else
|
|
166
|
+
return word;
|
|
167
|
+
}
|
|
168
|
+
utils$9.zero2 = zero2;
|
|
169
|
+
|
|
170
|
+
function zero8(word) {
|
|
171
|
+
if (word.length === 7)
|
|
172
|
+
return '0' + word;
|
|
173
|
+
else if (word.length === 6)
|
|
174
|
+
return '00' + word;
|
|
175
|
+
else if (word.length === 5)
|
|
176
|
+
return '000' + word;
|
|
177
|
+
else if (word.length === 4)
|
|
178
|
+
return '0000' + word;
|
|
179
|
+
else if (word.length === 3)
|
|
180
|
+
return '00000' + word;
|
|
181
|
+
else if (word.length === 2)
|
|
182
|
+
return '000000' + word;
|
|
183
|
+
else if (word.length === 1)
|
|
184
|
+
return '0000000' + word;
|
|
185
|
+
else
|
|
186
|
+
return word;
|
|
187
|
+
}
|
|
188
|
+
utils$9.zero8 = zero8;
|
|
189
|
+
|
|
190
|
+
function join32(msg, start, end, endian) {
|
|
191
|
+
var len = end - start;
|
|
192
|
+
assert$5(len % 4 === 0);
|
|
193
|
+
var res = new Array(len / 4);
|
|
194
|
+
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
195
|
+
var w;
|
|
196
|
+
if (endian === 'big')
|
|
197
|
+
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
198
|
+
else
|
|
199
|
+
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
200
|
+
res[i] = w >>> 0;
|
|
201
|
+
}
|
|
202
|
+
return res;
|
|
203
|
+
}
|
|
204
|
+
utils$9.join32 = join32;
|
|
205
|
+
|
|
206
|
+
function split32(msg, endian) {
|
|
207
|
+
var res = new Array(msg.length * 4);
|
|
208
|
+
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
209
|
+
var m = msg[i];
|
|
210
|
+
if (endian === 'big') {
|
|
211
|
+
res[k] = m >>> 24;
|
|
212
|
+
res[k + 1] = (m >>> 16) & 0xff;
|
|
213
|
+
res[k + 2] = (m >>> 8) & 0xff;
|
|
214
|
+
res[k + 3] = m & 0xff;
|
|
215
|
+
} else {
|
|
216
|
+
res[k + 3] = m >>> 24;
|
|
217
|
+
res[k + 2] = (m >>> 16) & 0xff;
|
|
218
|
+
res[k + 1] = (m >>> 8) & 0xff;
|
|
219
|
+
res[k] = m & 0xff;
|
|
56
220
|
}
|
|
57
|
-
|
|
221
|
+
}
|
|
222
|
+
return res;
|
|
58
223
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
LogLevel["INFO"] = "INFO";
|
|
64
|
-
LogLevel["WARNING"] = "WARNING";
|
|
65
|
-
LogLevel["ERROR"] = "ERROR";
|
|
66
|
-
LogLevel["OFF"] = "OFF";
|
|
67
|
-
})(LogLevel || (LogLevel = {}));
|
|
68
|
-
var ErrorCode;
|
|
69
|
-
(function (ErrorCode) {
|
|
70
|
-
///////////////////
|
|
71
|
-
// Generic Errors
|
|
72
|
-
// Unknown Error
|
|
73
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
74
|
-
// Not Implemented
|
|
75
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
76
|
-
// Unsupported Operation
|
|
77
|
-
// - operation
|
|
78
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
79
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
80
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
81
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
82
|
-
// Some sort of bad response from the server
|
|
83
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
84
|
-
// Timeout
|
|
85
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
86
|
-
///////////////////
|
|
87
|
-
// Operational Errors
|
|
88
|
-
// Buffer Overrun
|
|
89
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
90
|
-
// Numeric Fault
|
|
91
|
-
// - operation: the operation being executed
|
|
92
|
-
// - fault: the reason this faulted
|
|
93
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
94
|
-
///////////////////
|
|
95
|
-
// Argument Errors
|
|
96
|
-
// Missing new operator to an object
|
|
97
|
-
// - name: The name of the class
|
|
98
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
99
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
100
|
-
// - argument: The argument name that was invalid
|
|
101
|
-
// - value: The value of the argument
|
|
102
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
103
|
-
// Missing argument to a function:
|
|
104
|
-
// - count: The number of arguments received
|
|
105
|
-
// - expectedCount: The number of arguments expected
|
|
106
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
107
|
-
// Too many arguments
|
|
108
|
-
// - count: The number of arguments received
|
|
109
|
-
// - expectedCount: The number of arguments expected
|
|
110
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
111
|
-
///////////////////
|
|
112
|
-
// Blockchain Errors
|
|
113
|
-
// Call exception
|
|
114
|
-
// - transaction: the transaction
|
|
115
|
-
// - address?: the contract address
|
|
116
|
-
// - args?: The arguments passed into the function
|
|
117
|
-
// - method?: The Solidity method signature
|
|
118
|
-
// - errorSignature?: The EIP848 error signature
|
|
119
|
-
// - errorArgs?: The EIP848 error parameters
|
|
120
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
121
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
122
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
123
|
-
// - transaction: the transaction attempted
|
|
124
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
125
|
-
// Nonce has already been used
|
|
126
|
-
// - transaction: the transaction attempted
|
|
127
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
128
|
-
// The replacement fee for the transaction is too low
|
|
129
|
-
// - transaction: the transaction attempted
|
|
130
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
131
|
-
// The gas limit could not be estimated
|
|
132
|
-
// - transaction: the transaction passed to estimateGas
|
|
133
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
134
|
-
// The transaction was replaced by one with a higher gas price
|
|
135
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
136
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
137
|
-
// - hash: original transaction hash
|
|
138
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
139
|
-
// - receipt: the receipt of the replacement
|
|
140
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
141
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
142
|
-
const HEX = "0123456789abcdef";
|
|
143
|
-
class Logger {
|
|
144
|
-
constructor(version) {
|
|
145
|
-
Object.defineProperty(this, "version", {
|
|
146
|
-
enumerable: true,
|
|
147
|
-
value: version,
|
|
148
|
-
writable: false
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
_log(logLevel, args) {
|
|
152
|
-
const level = logLevel.toLowerCase();
|
|
153
|
-
if (LogLevels[level] == null) {
|
|
154
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
155
|
-
}
|
|
156
|
-
if (_logLevel > LogLevels[level]) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
console.log.apply(console, args);
|
|
160
|
-
}
|
|
161
|
-
debug(...args) {
|
|
162
|
-
this._log(Logger.levels.DEBUG, args);
|
|
163
|
-
}
|
|
164
|
-
info(...args) {
|
|
165
|
-
this._log(Logger.levels.INFO, args);
|
|
166
|
-
}
|
|
167
|
-
warn(...args) {
|
|
168
|
-
this._log(Logger.levels.WARNING, args);
|
|
169
|
-
}
|
|
170
|
-
makeError(message, code, params) {
|
|
171
|
-
// Errors are being censored
|
|
172
|
-
if (_censorErrors) {
|
|
173
|
-
return this.makeError("censored error", code, {});
|
|
174
|
-
}
|
|
175
|
-
if (!code) {
|
|
176
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
177
|
-
}
|
|
178
|
-
if (!params) {
|
|
179
|
-
params = {};
|
|
180
|
-
}
|
|
181
|
-
const messageDetails = [];
|
|
182
|
-
Object.keys(params).forEach((key) => {
|
|
183
|
-
const value = params[key];
|
|
184
|
-
try {
|
|
185
|
-
if (value instanceof Uint8Array) {
|
|
186
|
-
let hex = "";
|
|
187
|
-
for (let i = 0; i < value.length; i++) {
|
|
188
|
-
hex += HEX[value[i] >> 4];
|
|
189
|
-
hex += HEX[value[i] & 0x0f];
|
|
190
|
-
}
|
|
191
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
messageDetails.push(`code=${code}`);
|
|
202
|
-
messageDetails.push(`version=${this.version}`);
|
|
203
|
-
const reason = message;
|
|
204
|
-
if (messageDetails.length) {
|
|
205
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
206
|
-
}
|
|
207
|
-
// @TODO: Any??
|
|
208
|
-
const error = new Error(message);
|
|
209
|
-
error.reason = reason;
|
|
210
|
-
error.code = code;
|
|
211
|
-
Object.keys(params).forEach(function (key) {
|
|
212
|
-
error[key] = params[key];
|
|
213
|
-
});
|
|
214
|
-
return error;
|
|
215
|
-
}
|
|
216
|
-
throwError(message, code, params) {
|
|
217
|
-
throw this.makeError(message, code, params);
|
|
218
|
-
}
|
|
219
|
-
throwArgumentError(message, name, value) {
|
|
220
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
221
|
-
argument: name,
|
|
222
|
-
value: value
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
assert(condition, message, code, params) {
|
|
226
|
-
if (!!condition) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
this.throwError(message, code, params);
|
|
230
|
-
}
|
|
231
|
-
assertArgument(condition, message, name, value) {
|
|
232
|
-
if (!!condition) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
this.throwArgumentError(message, name, value);
|
|
236
|
-
}
|
|
237
|
-
checkNormalize(message) {
|
|
238
|
-
if (_normalizeError) {
|
|
239
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
240
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
checkSafeUint53(value, message) {
|
|
245
|
-
if (typeof (value) !== "number") {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
if (message == null) {
|
|
249
|
-
message = "value not safe";
|
|
250
|
-
}
|
|
251
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
252
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
253
|
-
operation: "checkSafeInteger",
|
|
254
|
-
fault: "out-of-safe-range",
|
|
255
|
-
value: value
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
if (value % 1) {
|
|
259
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
260
|
-
operation: "checkSafeInteger",
|
|
261
|
-
fault: "non-integer",
|
|
262
|
-
value: value
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
267
|
-
if (message) {
|
|
268
|
-
message = ": " + message;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
message = "";
|
|
272
|
-
}
|
|
273
|
-
if (count < expectedCount) {
|
|
274
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
275
|
-
count: count,
|
|
276
|
-
expectedCount: expectedCount
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
if (count > expectedCount) {
|
|
280
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
281
|
-
count: count,
|
|
282
|
-
expectedCount: expectedCount
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
checkNew(target, kind) {
|
|
287
|
-
if (target === Object || target == null) {
|
|
288
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
checkAbstract(target, kind) {
|
|
292
|
-
if (target === kind) {
|
|
293
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
294
|
-
}
|
|
295
|
-
else if (target === Object || target == null) {
|
|
296
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
static globalLogger() {
|
|
300
|
-
if (!_globalLogger) {
|
|
301
|
-
_globalLogger = new Logger(version$2);
|
|
302
|
-
}
|
|
303
|
-
return _globalLogger;
|
|
304
|
-
}
|
|
305
|
-
static setCensorship(censorship, permanent) {
|
|
306
|
-
if (!censorship && permanent) {
|
|
307
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
308
|
-
operation: "setCensorship"
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
if (_permanentCensorErrors) {
|
|
312
|
-
if (!censorship) {
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
316
|
-
operation: "setCensorship"
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
_censorErrors = !!censorship;
|
|
320
|
-
_permanentCensorErrors = !!permanent;
|
|
321
|
-
}
|
|
322
|
-
static setLogLevel(logLevel) {
|
|
323
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
324
|
-
if (level == null) {
|
|
325
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
_logLevel = level;
|
|
329
|
-
}
|
|
330
|
-
static from(version) {
|
|
331
|
-
return new Logger(version);
|
|
332
|
-
}
|
|
224
|
+
utils$9.split32 = split32;
|
|
225
|
+
|
|
226
|
+
function rotr32$1(w, b) {
|
|
227
|
+
return (w >>> b) | (w << (32 - b));
|
|
333
228
|
}
|
|
334
|
-
|
|
335
|
-
Logger.levels = LogLevel;
|
|
229
|
+
utils$9.rotr32 = rotr32$1;
|
|
336
230
|
|
|
337
|
-
|
|
231
|
+
function rotl32$2(w, b) {
|
|
232
|
+
return (w << b) | (w >>> (32 - b));
|
|
233
|
+
}
|
|
234
|
+
utils$9.rotl32 = rotl32$2;
|
|
338
235
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
function isHexable(value) {
|
|
342
|
-
return !!(value.toHexString);
|
|
236
|
+
function sum32$3(a, b) {
|
|
237
|
+
return (a + b) >>> 0;
|
|
343
238
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
array.slice = function () {
|
|
349
|
-
const args = Array.prototype.slice.call(arguments);
|
|
350
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
351
|
-
};
|
|
352
|
-
return array;
|
|
239
|
+
utils$9.sum32 = sum32$3;
|
|
240
|
+
|
|
241
|
+
function sum32_3$1(a, b, c) {
|
|
242
|
+
return (a + b + c) >>> 0;
|
|
353
243
|
}
|
|
354
|
-
|
|
355
|
-
|
|
244
|
+
utils$9.sum32_3 = sum32_3$1;
|
|
245
|
+
|
|
246
|
+
function sum32_4$2(a, b, c, d) {
|
|
247
|
+
return (a + b + c + d) >>> 0;
|
|
356
248
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (value.constructor === Uint8Array) {
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
if (typeof (value) === "string") {
|
|
365
|
-
return false;
|
|
366
|
-
}
|
|
367
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
for (let i = 0; i < value.length; i++) {
|
|
371
|
-
const v = value[i];
|
|
372
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
373
|
-
return false;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return true;
|
|
249
|
+
utils$9.sum32_4 = sum32_4$2;
|
|
250
|
+
|
|
251
|
+
function sum32_5$2(a, b, c, d, e) {
|
|
252
|
+
return (a + b + c + d + e) >>> 0;
|
|
377
253
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
if (result.length === 0) {
|
|
390
|
-
result.push(0);
|
|
391
|
-
}
|
|
392
|
-
return addSlice(new Uint8Array(result));
|
|
393
|
-
}
|
|
394
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
395
|
-
value = "0x" + value;
|
|
396
|
-
}
|
|
397
|
-
if (isHexable(value)) {
|
|
398
|
-
value = value.toHexString();
|
|
399
|
-
}
|
|
400
|
-
if (isHexString(value)) {
|
|
401
|
-
let hex = value.substring(2);
|
|
402
|
-
if (hex.length % 2) {
|
|
403
|
-
if (options.hexPad === "left") {
|
|
404
|
-
hex = "0x0" + hex.substring(2);
|
|
405
|
-
}
|
|
406
|
-
else if (options.hexPad === "right") {
|
|
407
|
-
hex += "0";
|
|
408
|
-
}
|
|
409
|
-
else {
|
|
410
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const result = [];
|
|
414
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
415
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
416
|
-
}
|
|
417
|
-
return addSlice(new Uint8Array(result));
|
|
418
|
-
}
|
|
419
|
-
if (isBytes(value)) {
|
|
420
|
-
return addSlice(new Uint8Array(value));
|
|
421
|
-
}
|
|
422
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
254
|
+
utils$9.sum32_5 = sum32_5$2;
|
|
255
|
+
|
|
256
|
+
function sum64$1(buf, pos, ah, al) {
|
|
257
|
+
var bh = buf[pos];
|
|
258
|
+
var bl = buf[pos + 1];
|
|
259
|
+
|
|
260
|
+
var lo = (al + bl) >>> 0;
|
|
261
|
+
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
262
|
+
buf[pos] = hi >>> 0;
|
|
263
|
+
buf[pos + 1] = lo;
|
|
423
264
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
return true;
|
|
265
|
+
utils$9.sum64 = sum64$1;
|
|
266
|
+
|
|
267
|
+
function sum64_hi$1(ah, al, bh, bl) {
|
|
268
|
+
var lo = (al + bl) >>> 0;
|
|
269
|
+
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
270
|
+
return hi >>> 0;
|
|
432
271
|
}
|
|
272
|
+
utils$9.sum64_hi = sum64_hi$1;
|
|
433
273
|
|
|
434
|
-
|
|
274
|
+
function sum64_lo$1(ah, al, bh, bl) {
|
|
275
|
+
var lo = al + bl;
|
|
276
|
+
return lo >>> 0;
|
|
277
|
+
}
|
|
278
|
+
utils$9.sum64_lo = sum64_lo$1;
|
|
435
279
|
|
|
436
|
-
function
|
|
437
|
-
|
|
280
|
+
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
281
|
+
var carry = 0;
|
|
282
|
+
var lo = al;
|
|
283
|
+
lo = (lo + bl) >>> 0;
|
|
284
|
+
carry += lo < al ? 1 : 0;
|
|
285
|
+
lo = (lo + cl) >>> 0;
|
|
286
|
+
carry += lo < cl ? 1 : 0;
|
|
287
|
+
lo = (lo + dl) >>> 0;
|
|
288
|
+
carry += lo < dl ? 1 : 0;
|
|
289
|
+
|
|
290
|
+
var hi = ah + bh + ch + dh + carry;
|
|
291
|
+
return hi >>> 0;
|
|
438
292
|
}
|
|
293
|
+
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
439
294
|
|
|
440
|
-
|
|
295
|
+
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
296
|
+
var lo = al + bl + cl + dl;
|
|
297
|
+
return lo >>> 0;
|
|
298
|
+
}
|
|
299
|
+
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
441
300
|
|
|
442
|
-
|
|
301
|
+
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
302
|
+
var carry = 0;
|
|
303
|
+
var lo = al;
|
|
304
|
+
lo = (lo + bl) >>> 0;
|
|
305
|
+
carry += lo < al ? 1 : 0;
|
|
306
|
+
lo = (lo + cl) >>> 0;
|
|
307
|
+
carry += lo < cl ? 1 : 0;
|
|
308
|
+
lo = (lo + dl) >>> 0;
|
|
309
|
+
carry += lo < dl ? 1 : 0;
|
|
310
|
+
lo = (lo + el) >>> 0;
|
|
311
|
+
carry += lo < el ? 1 : 0;
|
|
443
312
|
|
|
444
|
-
var
|
|
313
|
+
var hi = ah + bh + ch + dh + eh + carry;
|
|
314
|
+
return hi >>> 0;
|
|
315
|
+
}
|
|
316
|
+
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
445
317
|
|
|
446
|
-
function
|
|
447
|
-
|
|
448
|
-
|
|
318
|
+
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
319
|
+
var lo = al + bl + cl + dl + el;
|
|
320
|
+
|
|
321
|
+
return lo >>> 0;
|
|
449
322
|
}
|
|
323
|
+
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
450
324
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
325
|
+
function rotr64_hi$1(ah, al, num) {
|
|
326
|
+
var r = (al << (32 - num)) | (ah >>> num);
|
|
327
|
+
return r >>> 0;
|
|
328
|
+
}
|
|
329
|
+
utils$9.rotr64_hi = rotr64_hi$1;
|
|
455
330
|
|
|
456
|
-
|
|
331
|
+
function rotr64_lo$1(ah, al, num) {
|
|
332
|
+
var r = (ah << (32 - num)) | (al >>> num);
|
|
333
|
+
return r >>> 0;
|
|
334
|
+
}
|
|
335
|
+
utils$9.rotr64_lo = rotr64_lo$1;
|
|
457
336
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
461
|
-
ctor.super_ = superCtor;
|
|
462
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
463
|
-
constructor: {
|
|
464
|
-
value: ctor,
|
|
465
|
-
enumerable: false,
|
|
466
|
-
writable: true,
|
|
467
|
-
configurable: true
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
};
|
|
471
|
-
} else {
|
|
472
|
-
// old school shim for old browsers
|
|
473
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
474
|
-
ctor.super_ = superCtor;
|
|
475
|
-
var TempCtor = function () {};
|
|
476
|
-
TempCtor.prototype = superCtor.prototype;
|
|
477
|
-
ctor.prototype = new TempCtor();
|
|
478
|
-
ctor.prototype.constructor = ctor;
|
|
479
|
-
};
|
|
337
|
+
function shr64_hi$1(ah, al, num) {
|
|
338
|
+
return ah >>> num;
|
|
480
339
|
}
|
|
340
|
+
utils$9.shr64_hi = shr64_hi$1;
|
|
481
341
|
|
|
482
|
-
|
|
483
|
-
var
|
|
342
|
+
function shr64_lo$1(ah, al, num) {
|
|
343
|
+
var r = (ah << (32 - num)) | (al >>> num);
|
|
344
|
+
return r >>> 0;
|
|
345
|
+
}
|
|
346
|
+
utils$9.shr64_lo = shr64_lo$1;
|
|
484
347
|
|
|
485
|
-
|
|
348
|
+
var common$5 = {};
|
|
486
349
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
350
|
+
var utils$8 = utils$9;
|
|
351
|
+
var assert$4 = minimalisticAssert;
|
|
352
|
+
|
|
353
|
+
function BlockHash$4() {
|
|
354
|
+
this.pending = null;
|
|
355
|
+
this.pendingTotal = 0;
|
|
356
|
+
this.blockSize = this.constructor.blockSize;
|
|
357
|
+
this.outSize = this.constructor.outSize;
|
|
358
|
+
this.hmacStrength = this.constructor.hmacStrength;
|
|
359
|
+
this.padLength = this.constructor.padLength / 8;
|
|
360
|
+
this.endian = 'big';
|
|
361
|
+
|
|
362
|
+
this._delta8 = this.blockSize / 8;
|
|
363
|
+
this._delta32 = this.blockSize / 32;
|
|
495
364
|
}
|
|
365
|
+
common$5.BlockHash = BlockHash$4;
|
|
496
366
|
|
|
497
|
-
function
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (!
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
506
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
507
|
-
// Apache License 2.0
|
|
508
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
509
|
-
var p = 0;
|
|
510
|
-
for (var i = 0; i < msg.length; i++) {
|
|
511
|
-
var c = msg.charCodeAt(i);
|
|
512
|
-
if (c < 128) {
|
|
513
|
-
res[p++] = c;
|
|
514
|
-
} else if (c < 2048) {
|
|
515
|
-
res[p++] = (c >> 6) | 192;
|
|
516
|
-
res[p++] = (c & 63) | 128;
|
|
517
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
518
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
519
|
-
res[p++] = (c >> 18) | 240;
|
|
520
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
521
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
522
|
-
res[p++] = (c & 63) | 128;
|
|
523
|
-
} else {
|
|
524
|
-
res[p++] = (c >> 12) | 224;
|
|
525
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
526
|
-
res[p++] = (c & 63) | 128;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
} else if (enc === 'hex') {
|
|
530
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
531
|
-
if (msg.length % 2 !== 0)
|
|
532
|
-
msg = '0' + msg;
|
|
533
|
-
for (i = 0; i < msg.length; i += 2)
|
|
534
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
535
|
-
}
|
|
536
|
-
} else {
|
|
537
|
-
for (i = 0; i < msg.length; i++)
|
|
538
|
-
res[i] = msg[i] | 0;
|
|
539
|
-
}
|
|
540
|
-
return res;
|
|
541
|
-
}
|
|
542
|
-
utils$9.toArray = toArray;
|
|
367
|
+
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
368
|
+
// Convert message to array, pad it, and join into 32bit blocks
|
|
369
|
+
msg = utils$8.toArray(msg, enc);
|
|
370
|
+
if (!this.pending)
|
|
371
|
+
this.pending = msg;
|
|
372
|
+
else
|
|
373
|
+
this.pending = this.pending.concat(msg);
|
|
374
|
+
this.pendingTotal += msg.length;
|
|
543
375
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
res += zero2(msg[i].toString(16));
|
|
548
|
-
return res;
|
|
549
|
-
}
|
|
550
|
-
utils$9.toHex = toHex;
|
|
376
|
+
// Enough data, try updating
|
|
377
|
+
if (this.pending.length >= this._delta8) {
|
|
378
|
+
msg = this.pending;
|
|
551
379
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
return res >>> 0;
|
|
558
|
-
}
|
|
559
|
-
utils$9.htonl = htonl;
|
|
380
|
+
// Process pending data in blocks
|
|
381
|
+
var r = msg.length % this._delta8;
|
|
382
|
+
this.pending = msg.slice(msg.length - r, msg.length);
|
|
383
|
+
if (this.pending.length === 0)
|
|
384
|
+
this.pending = null;
|
|
560
385
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
var w = msg[i];
|
|
565
|
-
if (endian === 'little')
|
|
566
|
-
w = htonl(w);
|
|
567
|
-
res += zero8(w.toString(16));
|
|
386
|
+
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
387
|
+
for (var i = 0; i < msg.length; i += this._delta32)
|
|
388
|
+
this._update(msg, i, i + this._delta32);
|
|
568
389
|
}
|
|
569
|
-
return res;
|
|
570
|
-
}
|
|
571
|
-
utils$9.toHex32 = toHex32;
|
|
572
390
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return '0' + word;
|
|
576
|
-
else
|
|
577
|
-
return word;
|
|
578
|
-
}
|
|
579
|
-
utils$9.zero2 = zero2;
|
|
391
|
+
return this;
|
|
392
|
+
};
|
|
580
393
|
|
|
581
|
-
function
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
else if (word.length === 6)
|
|
585
|
-
return '00' + word;
|
|
586
|
-
else if (word.length === 5)
|
|
587
|
-
return '000' + word;
|
|
588
|
-
else if (word.length === 4)
|
|
589
|
-
return '0000' + word;
|
|
590
|
-
else if (word.length === 3)
|
|
591
|
-
return '00000' + word;
|
|
592
|
-
else if (word.length === 2)
|
|
593
|
-
return '000000' + word;
|
|
594
|
-
else if (word.length === 1)
|
|
595
|
-
return '0000000' + word;
|
|
596
|
-
else
|
|
597
|
-
return word;
|
|
598
|
-
}
|
|
599
|
-
utils$9.zero8 = zero8;
|
|
394
|
+
BlockHash$4.prototype.digest = function digest(enc) {
|
|
395
|
+
this.update(this._pad());
|
|
396
|
+
assert$4(this.pending === null);
|
|
600
397
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
assert$5(len % 4 === 0);
|
|
604
|
-
var res = new Array(len / 4);
|
|
605
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
606
|
-
var w;
|
|
607
|
-
if (endian === 'big')
|
|
608
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
609
|
-
else
|
|
610
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
611
|
-
res[i] = w >>> 0;
|
|
612
|
-
}
|
|
613
|
-
return res;
|
|
614
|
-
}
|
|
615
|
-
utils$9.join32 = join32;
|
|
398
|
+
return this._digest(enc);
|
|
399
|
+
};
|
|
616
400
|
|
|
617
|
-
function
|
|
618
|
-
var
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
res[
|
|
631
|
-
|
|
401
|
+
BlockHash$4.prototype._pad = function pad() {
|
|
402
|
+
var len = this.pendingTotal;
|
|
403
|
+
var bytes = this._delta8;
|
|
404
|
+
var k = bytes - ((len + this.padLength) % bytes);
|
|
405
|
+
var res = new Array(k + this.padLength);
|
|
406
|
+
res[0] = 0x80;
|
|
407
|
+
for (var i = 1; i < k; i++)
|
|
408
|
+
res[i] = 0;
|
|
409
|
+
|
|
410
|
+
// Append length
|
|
411
|
+
len <<= 3;
|
|
412
|
+
if (this.endian === 'big') {
|
|
413
|
+
for (var t = 8; t < this.padLength; t++)
|
|
414
|
+
res[i++] = 0;
|
|
415
|
+
|
|
416
|
+
res[i++] = 0;
|
|
417
|
+
res[i++] = 0;
|
|
418
|
+
res[i++] = 0;
|
|
419
|
+
res[i++] = 0;
|
|
420
|
+
res[i++] = (len >>> 24) & 0xff;
|
|
421
|
+
res[i++] = (len >>> 16) & 0xff;
|
|
422
|
+
res[i++] = (len >>> 8) & 0xff;
|
|
423
|
+
res[i++] = len & 0xff;
|
|
424
|
+
} else {
|
|
425
|
+
res[i++] = len & 0xff;
|
|
426
|
+
res[i++] = (len >>> 8) & 0xff;
|
|
427
|
+
res[i++] = (len >>> 16) & 0xff;
|
|
428
|
+
res[i++] = (len >>> 24) & 0xff;
|
|
429
|
+
res[i++] = 0;
|
|
430
|
+
res[i++] = 0;
|
|
431
|
+
res[i++] = 0;
|
|
432
|
+
res[i++] = 0;
|
|
433
|
+
|
|
434
|
+
for (t = 8; t < this.padLength; t++)
|
|
435
|
+
res[i++] = 0;
|
|
632
436
|
}
|
|
437
|
+
|
|
633
438
|
return res;
|
|
634
|
-
}
|
|
635
|
-
utils$9.split32 = split32;
|
|
439
|
+
};
|
|
636
440
|
|
|
637
|
-
|
|
638
|
-
return (w >>> b) | (w << (32 - b));
|
|
639
|
-
}
|
|
640
|
-
utils$9.rotr32 = rotr32$1;
|
|
441
|
+
var sha = {};
|
|
641
442
|
|
|
642
|
-
|
|
643
|
-
return (w << b) | (w >>> (32 - b));
|
|
644
|
-
}
|
|
645
|
-
utils$9.rotl32 = rotl32$2;
|
|
443
|
+
var common$4 = {};
|
|
646
444
|
|
|
647
|
-
|
|
648
|
-
|
|
445
|
+
var utils$7 = utils$9;
|
|
446
|
+
var rotr32 = utils$7.rotr32;
|
|
447
|
+
|
|
448
|
+
function ft_1$1(s, x, y, z) {
|
|
449
|
+
if (s === 0)
|
|
450
|
+
return ch32$1(x, y, z);
|
|
451
|
+
if (s === 1 || s === 3)
|
|
452
|
+
return p32(x, y, z);
|
|
453
|
+
if (s === 2)
|
|
454
|
+
return maj32$1(x, y, z);
|
|
649
455
|
}
|
|
650
|
-
|
|
456
|
+
common$4.ft_1 = ft_1$1;
|
|
651
457
|
|
|
652
|
-
function
|
|
653
|
-
return (
|
|
458
|
+
function ch32$1(x, y, z) {
|
|
459
|
+
return (x & y) ^ ((~x) & z);
|
|
654
460
|
}
|
|
655
|
-
|
|
461
|
+
common$4.ch32 = ch32$1;
|
|
656
462
|
|
|
657
|
-
function
|
|
658
|
-
return (
|
|
463
|
+
function maj32$1(x, y, z) {
|
|
464
|
+
return (x & y) ^ (x & z) ^ (y & z);
|
|
659
465
|
}
|
|
660
|
-
|
|
466
|
+
common$4.maj32 = maj32$1;
|
|
661
467
|
|
|
662
|
-
function
|
|
663
|
-
return
|
|
468
|
+
function p32(x, y, z) {
|
|
469
|
+
return x ^ y ^ z;
|
|
664
470
|
}
|
|
665
|
-
|
|
471
|
+
common$4.p32 = p32;
|
|
666
472
|
|
|
667
|
-
function
|
|
668
|
-
|
|
669
|
-
|
|
473
|
+
function s0_256$1(x) {
|
|
474
|
+
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
475
|
+
}
|
|
476
|
+
common$4.s0_256 = s0_256$1;
|
|
670
477
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
buf[pos] = hi >>> 0;
|
|
674
|
-
buf[pos + 1] = lo;
|
|
478
|
+
function s1_256$1(x) {
|
|
479
|
+
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
675
480
|
}
|
|
676
|
-
|
|
481
|
+
common$4.s1_256 = s1_256$1;
|
|
677
482
|
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
681
|
-
return hi >>> 0;
|
|
483
|
+
function g0_256$1(x) {
|
|
484
|
+
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
682
485
|
}
|
|
683
|
-
|
|
486
|
+
common$4.g0_256 = g0_256$1;
|
|
684
487
|
|
|
685
|
-
function
|
|
686
|
-
|
|
687
|
-
return lo >>> 0;
|
|
488
|
+
function g1_256$1(x) {
|
|
489
|
+
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
688
490
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
692
|
-
var carry = 0;
|
|
693
|
-
var lo = al;
|
|
694
|
-
lo = (lo + bl) >>> 0;
|
|
695
|
-
carry += lo < al ? 1 : 0;
|
|
696
|
-
lo = (lo + cl) >>> 0;
|
|
697
|
-
carry += lo < cl ? 1 : 0;
|
|
698
|
-
lo = (lo + dl) >>> 0;
|
|
699
|
-
carry += lo < dl ? 1 : 0;
|
|
700
|
-
|
|
701
|
-
var hi = ah + bh + ch + dh + carry;
|
|
702
|
-
return hi >>> 0;
|
|
703
|
-
}
|
|
704
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
705
|
-
|
|
706
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
707
|
-
var lo = al + bl + cl + dl;
|
|
708
|
-
return lo >>> 0;
|
|
709
|
-
}
|
|
710
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
711
|
-
|
|
712
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
713
|
-
var carry = 0;
|
|
714
|
-
var lo = al;
|
|
715
|
-
lo = (lo + bl) >>> 0;
|
|
716
|
-
carry += lo < al ? 1 : 0;
|
|
717
|
-
lo = (lo + cl) >>> 0;
|
|
718
|
-
carry += lo < cl ? 1 : 0;
|
|
719
|
-
lo = (lo + dl) >>> 0;
|
|
720
|
-
carry += lo < dl ? 1 : 0;
|
|
721
|
-
lo = (lo + el) >>> 0;
|
|
722
|
-
carry += lo < el ? 1 : 0;
|
|
723
|
-
|
|
724
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
725
|
-
return hi >>> 0;
|
|
726
|
-
}
|
|
727
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
728
|
-
|
|
729
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
730
|
-
var lo = al + bl + cl + dl + el;
|
|
731
|
-
|
|
732
|
-
return lo >>> 0;
|
|
733
|
-
}
|
|
734
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
735
|
-
|
|
736
|
-
function rotr64_hi$1(ah, al, num) {
|
|
737
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
738
|
-
return r >>> 0;
|
|
739
|
-
}
|
|
740
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
741
|
-
|
|
742
|
-
function rotr64_lo$1(ah, al, num) {
|
|
743
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
744
|
-
return r >>> 0;
|
|
745
|
-
}
|
|
746
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
747
|
-
|
|
748
|
-
function shr64_hi$1(ah, al, num) {
|
|
749
|
-
return ah >>> num;
|
|
750
|
-
}
|
|
751
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
752
|
-
|
|
753
|
-
function shr64_lo$1(ah, al, num) {
|
|
754
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
755
|
-
return r >>> 0;
|
|
756
|
-
}
|
|
757
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
758
|
-
|
|
759
|
-
var common$5 = {};
|
|
760
|
-
|
|
761
|
-
var utils$8 = utils$9;
|
|
762
|
-
var assert$4 = minimalisticAssert;
|
|
763
|
-
|
|
764
|
-
function BlockHash$4() {
|
|
765
|
-
this.pending = null;
|
|
766
|
-
this.pendingTotal = 0;
|
|
767
|
-
this.blockSize = this.constructor.blockSize;
|
|
768
|
-
this.outSize = this.constructor.outSize;
|
|
769
|
-
this.hmacStrength = this.constructor.hmacStrength;
|
|
770
|
-
this.padLength = this.constructor.padLength / 8;
|
|
771
|
-
this.endian = 'big';
|
|
772
|
-
|
|
773
|
-
this._delta8 = this.blockSize / 8;
|
|
774
|
-
this._delta32 = this.blockSize / 32;
|
|
775
|
-
}
|
|
776
|
-
common$5.BlockHash = BlockHash$4;
|
|
777
|
-
|
|
778
|
-
BlockHash$4.prototype.update = function update(msg, enc) {
|
|
779
|
-
// Convert message to array, pad it, and join into 32bit blocks
|
|
780
|
-
msg = utils$8.toArray(msg, enc);
|
|
781
|
-
if (!this.pending)
|
|
782
|
-
this.pending = msg;
|
|
783
|
-
else
|
|
784
|
-
this.pending = this.pending.concat(msg);
|
|
785
|
-
this.pendingTotal += msg.length;
|
|
786
|
-
|
|
787
|
-
// Enough data, try updating
|
|
788
|
-
if (this.pending.length >= this._delta8) {
|
|
789
|
-
msg = this.pending;
|
|
790
|
-
|
|
791
|
-
// Process pending data in blocks
|
|
792
|
-
var r = msg.length % this._delta8;
|
|
793
|
-
this.pending = msg.slice(msg.length - r, msg.length);
|
|
794
|
-
if (this.pending.length === 0)
|
|
795
|
-
this.pending = null;
|
|
796
|
-
|
|
797
|
-
msg = utils$8.join32(msg, 0, msg.length - r, this.endian);
|
|
798
|
-
for (var i = 0; i < msg.length; i += this._delta32)
|
|
799
|
-
this._update(msg, i, i + this._delta32);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return this;
|
|
803
|
-
};
|
|
804
|
-
|
|
805
|
-
BlockHash$4.prototype.digest = function digest(enc) {
|
|
806
|
-
this.update(this._pad());
|
|
807
|
-
assert$4(this.pending === null);
|
|
808
|
-
|
|
809
|
-
return this._digest(enc);
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
BlockHash$4.prototype._pad = function pad() {
|
|
813
|
-
var len = this.pendingTotal;
|
|
814
|
-
var bytes = this._delta8;
|
|
815
|
-
var k = bytes - ((len + this.padLength) % bytes);
|
|
816
|
-
var res = new Array(k + this.padLength);
|
|
817
|
-
res[0] = 0x80;
|
|
818
|
-
for (var i = 1; i < k; i++)
|
|
819
|
-
res[i] = 0;
|
|
820
|
-
|
|
821
|
-
// Append length
|
|
822
|
-
len <<= 3;
|
|
823
|
-
if (this.endian === 'big') {
|
|
824
|
-
for (var t = 8; t < this.padLength; t++)
|
|
825
|
-
res[i++] = 0;
|
|
826
|
-
|
|
827
|
-
res[i++] = 0;
|
|
828
|
-
res[i++] = 0;
|
|
829
|
-
res[i++] = 0;
|
|
830
|
-
res[i++] = 0;
|
|
831
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
832
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
833
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
834
|
-
res[i++] = len & 0xff;
|
|
835
|
-
} else {
|
|
836
|
-
res[i++] = len & 0xff;
|
|
837
|
-
res[i++] = (len >>> 8) & 0xff;
|
|
838
|
-
res[i++] = (len >>> 16) & 0xff;
|
|
839
|
-
res[i++] = (len >>> 24) & 0xff;
|
|
840
|
-
res[i++] = 0;
|
|
841
|
-
res[i++] = 0;
|
|
842
|
-
res[i++] = 0;
|
|
843
|
-
res[i++] = 0;
|
|
844
|
-
|
|
845
|
-
for (t = 8; t < this.padLength; t++)
|
|
846
|
-
res[i++] = 0;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
return res;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
var sha = {};
|
|
853
|
-
|
|
854
|
-
var common$4 = {};
|
|
855
|
-
|
|
856
|
-
var utils$7 = utils$9;
|
|
857
|
-
var rotr32 = utils$7.rotr32;
|
|
858
|
-
|
|
859
|
-
function ft_1$1(s, x, y, z) {
|
|
860
|
-
if (s === 0)
|
|
861
|
-
return ch32$1(x, y, z);
|
|
862
|
-
if (s === 1 || s === 3)
|
|
863
|
-
return p32(x, y, z);
|
|
864
|
-
if (s === 2)
|
|
865
|
-
return maj32$1(x, y, z);
|
|
866
|
-
}
|
|
867
|
-
common$4.ft_1 = ft_1$1;
|
|
868
|
-
|
|
869
|
-
function ch32$1(x, y, z) {
|
|
870
|
-
return (x & y) ^ ((~x) & z);
|
|
871
|
-
}
|
|
872
|
-
common$4.ch32 = ch32$1;
|
|
873
|
-
|
|
874
|
-
function maj32$1(x, y, z) {
|
|
875
|
-
return (x & y) ^ (x & z) ^ (y & z);
|
|
876
|
-
}
|
|
877
|
-
common$4.maj32 = maj32$1;
|
|
878
|
-
|
|
879
|
-
function p32(x, y, z) {
|
|
880
|
-
return x ^ y ^ z;
|
|
881
|
-
}
|
|
882
|
-
common$4.p32 = p32;
|
|
883
|
-
|
|
884
|
-
function s0_256$1(x) {
|
|
885
|
-
return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
|
|
886
|
-
}
|
|
887
|
-
common$4.s0_256 = s0_256$1;
|
|
888
|
-
|
|
889
|
-
function s1_256$1(x) {
|
|
890
|
-
return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
|
|
891
|
-
}
|
|
892
|
-
common$4.s1_256 = s1_256$1;
|
|
893
|
-
|
|
894
|
-
function g0_256$1(x) {
|
|
895
|
-
return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
|
|
896
|
-
}
|
|
897
|
-
common$4.g0_256 = g0_256$1;
|
|
898
|
-
|
|
899
|
-
function g1_256$1(x) {
|
|
900
|
-
return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
|
|
901
|
-
}
|
|
902
|
-
common$4.g1_256 = g1_256$1;
|
|
491
|
+
common$4.g1_256 = g1_256$1;
|
|
903
492
|
|
|
904
493
|
var utils$6 = utils$9;
|
|
905
494
|
var common$3 = common$5;
|
|
@@ -1636,57 +1225,466 @@ function Hmac(hash, key, enc) {
|
|
|
1636
1225
|
|
|
1637
1226
|
this._init(utils.toArray(key, enc));
|
|
1638
1227
|
}
|
|
1639
|
-
var hmac = Hmac;
|
|
1640
|
-
|
|
1641
|
-
Hmac.prototype._init = function init(key) {
|
|
1642
|
-
// Shorten key, if needed
|
|
1643
|
-
if (key.length > this.blockSize)
|
|
1644
|
-
key = new this.Hash().update(key).digest();
|
|
1645
|
-
assert$1(key.length <= this.blockSize);
|
|
1646
|
-
|
|
1647
|
-
// Add padding to key
|
|
1648
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1649
|
-
key.push(0);
|
|
1650
|
-
|
|
1651
|
-
for (i = 0; i < key.length; i++)
|
|
1652
|
-
key[i] ^= 0x36;
|
|
1653
|
-
this.inner = new this.Hash().update(key);
|
|
1654
|
-
|
|
1655
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1656
|
-
for (i = 0; i < key.length; i++)
|
|
1657
|
-
key[i] ^= 0x6a;
|
|
1658
|
-
this.outer = new this.Hash().update(key);
|
|
1659
|
-
};
|
|
1660
|
-
|
|
1661
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1662
|
-
this.inner.update(msg, enc);
|
|
1663
|
-
return this;
|
|
1664
|
-
};
|
|
1665
|
-
|
|
1666
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1667
|
-
this.outer.update(this.inner.digest());
|
|
1668
|
-
return this.outer.digest(enc);
|
|
1669
|
-
};
|
|
1670
|
-
|
|
1671
|
-
(function (exports) {
|
|
1672
|
-
var hash = exports;
|
|
1673
|
-
|
|
1674
|
-
hash.utils = utils$9;
|
|
1675
|
-
hash.common = common$5;
|
|
1676
|
-
hash.sha = sha;
|
|
1677
|
-
hash.ripemd = ripemd;
|
|
1678
|
-
hash.hmac = hmac;
|
|
1228
|
+
var hmac = Hmac;
|
|
1229
|
+
|
|
1230
|
+
Hmac.prototype._init = function init(key) {
|
|
1231
|
+
// Shorten key, if needed
|
|
1232
|
+
if (key.length > this.blockSize)
|
|
1233
|
+
key = new this.Hash().update(key).digest();
|
|
1234
|
+
assert$1(key.length <= this.blockSize);
|
|
1235
|
+
|
|
1236
|
+
// Add padding to key
|
|
1237
|
+
for (var i = key.length; i < this.blockSize; i++)
|
|
1238
|
+
key.push(0);
|
|
1239
|
+
|
|
1240
|
+
for (i = 0; i < key.length; i++)
|
|
1241
|
+
key[i] ^= 0x36;
|
|
1242
|
+
this.inner = new this.Hash().update(key);
|
|
1243
|
+
|
|
1244
|
+
// 0x36 ^ 0x5c = 0x6a
|
|
1245
|
+
for (i = 0; i < key.length; i++)
|
|
1246
|
+
key[i] ^= 0x6a;
|
|
1247
|
+
this.outer = new this.Hash().update(key);
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
Hmac.prototype.update = function update(msg, enc) {
|
|
1251
|
+
this.inner.update(msg, enc);
|
|
1252
|
+
return this;
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
Hmac.prototype.digest = function digest(enc) {
|
|
1256
|
+
this.outer.update(this.inner.digest());
|
|
1257
|
+
return this.outer.digest(enc);
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
(function (exports) {
|
|
1261
|
+
var hash = exports;
|
|
1262
|
+
|
|
1263
|
+
hash.utils = utils$9;
|
|
1264
|
+
hash.common = common$5;
|
|
1265
|
+
hash.sha = sha;
|
|
1266
|
+
hash.ripemd = ripemd;
|
|
1267
|
+
hash.hmac = hmac;
|
|
1268
|
+
|
|
1269
|
+
// Proxy hash functions to the main object
|
|
1270
|
+
hash.sha1 = hash.sha.sha1;
|
|
1271
|
+
hash.sha256 = hash.sha.sha256;
|
|
1272
|
+
hash.sha224 = hash.sha.sha224;
|
|
1273
|
+
hash.sha384 = hash.sha.sha384;
|
|
1274
|
+
hash.sha512 = hash.sha.sha512;
|
|
1275
|
+
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1276
|
+
}(hash$1));
|
|
1277
|
+
|
|
1278
|
+
var hash = hash$1;
|
|
1279
|
+
|
|
1280
|
+
const version$2 = "logger/5.5.0";
|
|
1281
|
+
|
|
1282
|
+
let _permanentCensorErrors = false;
|
|
1283
|
+
let _censorErrors = false;
|
|
1284
|
+
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1285
|
+
let _logLevel = LogLevels["default"];
|
|
1286
|
+
let _globalLogger = null;
|
|
1287
|
+
function _checkNormalize() {
|
|
1288
|
+
try {
|
|
1289
|
+
const missing = [];
|
|
1290
|
+
// Make sure all forms of normalization are supported
|
|
1291
|
+
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1292
|
+
try {
|
|
1293
|
+
if ("test".normalize(form) !== "test") {
|
|
1294
|
+
throw new Error("bad normalize");
|
|
1295
|
+
}
|
|
1296
|
+
;
|
|
1297
|
+
}
|
|
1298
|
+
catch (error) {
|
|
1299
|
+
missing.push(form);
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
if (missing.length) {
|
|
1303
|
+
throw new Error("missing " + missing.join(", "));
|
|
1304
|
+
}
|
|
1305
|
+
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1306
|
+
throw new Error("broken implementation");
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
catch (error) {
|
|
1310
|
+
return error.message;
|
|
1311
|
+
}
|
|
1312
|
+
return null;
|
|
1313
|
+
}
|
|
1314
|
+
const _normalizeError = _checkNormalize();
|
|
1315
|
+
var LogLevel;
|
|
1316
|
+
(function (LogLevel) {
|
|
1317
|
+
LogLevel["DEBUG"] = "DEBUG";
|
|
1318
|
+
LogLevel["INFO"] = "INFO";
|
|
1319
|
+
LogLevel["WARNING"] = "WARNING";
|
|
1320
|
+
LogLevel["ERROR"] = "ERROR";
|
|
1321
|
+
LogLevel["OFF"] = "OFF";
|
|
1322
|
+
})(LogLevel || (LogLevel = {}));
|
|
1323
|
+
var ErrorCode;
|
|
1324
|
+
(function (ErrorCode) {
|
|
1325
|
+
///////////////////
|
|
1326
|
+
// Generic Errors
|
|
1327
|
+
// Unknown Error
|
|
1328
|
+
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1329
|
+
// Not Implemented
|
|
1330
|
+
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1331
|
+
// Unsupported Operation
|
|
1332
|
+
// - operation
|
|
1333
|
+
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1334
|
+
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1335
|
+
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1336
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1337
|
+
// Some sort of bad response from the server
|
|
1338
|
+
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1339
|
+
// Timeout
|
|
1340
|
+
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1341
|
+
///////////////////
|
|
1342
|
+
// Operational Errors
|
|
1343
|
+
// Buffer Overrun
|
|
1344
|
+
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1345
|
+
// Numeric Fault
|
|
1346
|
+
// - operation: the operation being executed
|
|
1347
|
+
// - fault: the reason this faulted
|
|
1348
|
+
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1349
|
+
///////////////////
|
|
1350
|
+
// Argument Errors
|
|
1351
|
+
// Missing new operator to an object
|
|
1352
|
+
// - name: The name of the class
|
|
1353
|
+
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1354
|
+
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1355
|
+
// - argument: The argument name that was invalid
|
|
1356
|
+
// - value: The value of the argument
|
|
1357
|
+
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1358
|
+
// Missing argument to a function:
|
|
1359
|
+
// - count: The number of arguments received
|
|
1360
|
+
// - expectedCount: The number of arguments expected
|
|
1361
|
+
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1362
|
+
// Too many arguments
|
|
1363
|
+
// - count: The number of arguments received
|
|
1364
|
+
// - expectedCount: The number of arguments expected
|
|
1365
|
+
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1366
|
+
///////////////////
|
|
1367
|
+
// Blockchain Errors
|
|
1368
|
+
// Call exception
|
|
1369
|
+
// - transaction: the transaction
|
|
1370
|
+
// - address?: the contract address
|
|
1371
|
+
// - args?: The arguments passed into the function
|
|
1372
|
+
// - method?: The Solidity method signature
|
|
1373
|
+
// - errorSignature?: The EIP848 error signature
|
|
1374
|
+
// - errorArgs?: The EIP848 error parameters
|
|
1375
|
+
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1376
|
+
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1377
|
+
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1378
|
+
// - transaction: the transaction attempted
|
|
1379
|
+
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1380
|
+
// Nonce has already been used
|
|
1381
|
+
// - transaction: the transaction attempted
|
|
1382
|
+
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1383
|
+
// The replacement fee for the transaction is too low
|
|
1384
|
+
// - transaction: the transaction attempted
|
|
1385
|
+
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1386
|
+
// The gas limit could not be estimated
|
|
1387
|
+
// - transaction: the transaction passed to estimateGas
|
|
1388
|
+
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1389
|
+
// The transaction was replaced by one with a higher gas price
|
|
1390
|
+
// - reason: "cancelled", "replaced" or "repriced"
|
|
1391
|
+
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1392
|
+
// - hash: original transaction hash
|
|
1393
|
+
// - replacement: the full TransactionsResponse for the replacement
|
|
1394
|
+
// - receipt: the receipt of the replacement
|
|
1395
|
+
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1396
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
1397
|
+
const HEX = "0123456789abcdef";
|
|
1398
|
+
class Logger {
|
|
1399
|
+
constructor(version) {
|
|
1400
|
+
Object.defineProperty(this, "version", {
|
|
1401
|
+
enumerable: true,
|
|
1402
|
+
value: version,
|
|
1403
|
+
writable: false
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
_log(logLevel, args) {
|
|
1407
|
+
const level = logLevel.toLowerCase();
|
|
1408
|
+
if (LogLevels[level] == null) {
|
|
1409
|
+
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1410
|
+
}
|
|
1411
|
+
if (_logLevel > LogLevels[level]) {
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
console.log.apply(console, args);
|
|
1415
|
+
}
|
|
1416
|
+
debug(...args) {
|
|
1417
|
+
this._log(Logger.levels.DEBUG, args);
|
|
1418
|
+
}
|
|
1419
|
+
info(...args) {
|
|
1420
|
+
this._log(Logger.levels.INFO, args);
|
|
1421
|
+
}
|
|
1422
|
+
warn(...args) {
|
|
1423
|
+
this._log(Logger.levels.WARNING, args);
|
|
1424
|
+
}
|
|
1425
|
+
makeError(message, code, params) {
|
|
1426
|
+
// Errors are being censored
|
|
1427
|
+
if (_censorErrors) {
|
|
1428
|
+
return this.makeError("censored error", code, {});
|
|
1429
|
+
}
|
|
1430
|
+
if (!code) {
|
|
1431
|
+
code = Logger.errors.UNKNOWN_ERROR;
|
|
1432
|
+
}
|
|
1433
|
+
if (!params) {
|
|
1434
|
+
params = {};
|
|
1435
|
+
}
|
|
1436
|
+
const messageDetails = [];
|
|
1437
|
+
Object.keys(params).forEach((key) => {
|
|
1438
|
+
const value = params[key];
|
|
1439
|
+
try {
|
|
1440
|
+
if (value instanceof Uint8Array) {
|
|
1441
|
+
let hex = "";
|
|
1442
|
+
for (let i = 0; i < value.length; i++) {
|
|
1443
|
+
hex += HEX[value[i] >> 4];
|
|
1444
|
+
hex += HEX[value[i] & 0x0f];
|
|
1445
|
+
}
|
|
1446
|
+
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1447
|
+
}
|
|
1448
|
+
else {
|
|
1449
|
+
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
catch (error) {
|
|
1453
|
+
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
messageDetails.push(`code=${code}`);
|
|
1457
|
+
messageDetails.push(`version=${this.version}`);
|
|
1458
|
+
const reason = message;
|
|
1459
|
+
if (messageDetails.length) {
|
|
1460
|
+
message += " (" + messageDetails.join(", ") + ")";
|
|
1461
|
+
}
|
|
1462
|
+
// @TODO: Any??
|
|
1463
|
+
const error = new Error(message);
|
|
1464
|
+
error.reason = reason;
|
|
1465
|
+
error.code = code;
|
|
1466
|
+
Object.keys(params).forEach(function (key) {
|
|
1467
|
+
error[key] = params[key];
|
|
1468
|
+
});
|
|
1469
|
+
return error;
|
|
1470
|
+
}
|
|
1471
|
+
throwError(message, code, params) {
|
|
1472
|
+
throw this.makeError(message, code, params);
|
|
1473
|
+
}
|
|
1474
|
+
throwArgumentError(message, name, value) {
|
|
1475
|
+
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1476
|
+
argument: name,
|
|
1477
|
+
value: value
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
assert(condition, message, code, params) {
|
|
1481
|
+
if (!!condition) {
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
this.throwError(message, code, params);
|
|
1485
|
+
}
|
|
1486
|
+
assertArgument(condition, message, name, value) {
|
|
1487
|
+
if (!!condition) {
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
this.throwArgumentError(message, name, value);
|
|
1491
|
+
}
|
|
1492
|
+
checkNormalize(message) {
|
|
1493
|
+
if (_normalizeError) {
|
|
1494
|
+
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1495
|
+
operation: "String.prototype.normalize", form: _normalizeError
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
checkSafeUint53(value, message) {
|
|
1500
|
+
if (typeof (value) !== "number") {
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
if (message == null) {
|
|
1504
|
+
message = "value not safe";
|
|
1505
|
+
}
|
|
1506
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1507
|
+
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1508
|
+
operation: "checkSafeInteger",
|
|
1509
|
+
fault: "out-of-safe-range",
|
|
1510
|
+
value: value
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
if (value % 1) {
|
|
1514
|
+
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1515
|
+
operation: "checkSafeInteger",
|
|
1516
|
+
fault: "non-integer",
|
|
1517
|
+
value: value
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
checkArgumentCount(count, expectedCount, message) {
|
|
1522
|
+
if (message) {
|
|
1523
|
+
message = ": " + message;
|
|
1524
|
+
}
|
|
1525
|
+
else {
|
|
1526
|
+
message = "";
|
|
1527
|
+
}
|
|
1528
|
+
if (count < expectedCount) {
|
|
1529
|
+
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1530
|
+
count: count,
|
|
1531
|
+
expectedCount: expectedCount
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
if (count > expectedCount) {
|
|
1535
|
+
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1536
|
+
count: count,
|
|
1537
|
+
expectedCount: expectedCount
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
checkNew(target, kind) {
|
|
1542
|
+
if (target === Object || target == null) {
|
|
1543
|
+
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
checkAbstract(target, kind) {
|
|
1547
|
+
if (target === kind) {
|
|
1548
|
+
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1549
|
+
}
|
|
1550
|
+
else if (target === Object || target == null) {
|
|
1551
|
+
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
static globalLogger() {
|
|
1555
|
+
if (!_globalLogger) {
|
|
1556
|
+
_globalLogger = new Logger(version$2);
|
|
1557
|
+
}
|
|
1558
|
+
return _globalLogger;
|
|
1559
|
+
}
|
|
1560
|
+
static setCensorship(censorship, permanent) {
|
|
1561
|
+
if (!censorship && permanent) {
|
|
1562
|
+
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1563
|
+
operation: "setCensorship"
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
if (_permanentCensorErrors) {
|
|
1567
|
+
if (!censorship) {
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1571
|
+
operation: "setCensorship"
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
_censorErrors = !!censorship;
|
|
1575
|
+
_permanentCensorErrors = !!permanent;
|
|
1576
|
+
}
|
|
1577
|
+
static setLogLevel(logLevel) {
|
|
1578
|
+
const level = LogLevels[logLevel.toLowerCase()];
|
|
1579
|
+
if (level == null) {
|
|
1580
|
+
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
_logLevel = level;
|
|
1584
|
+
}
|
|
1585
|
+
static from(version) {
|
|
1586
|
+
return new Logger(version);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
Logger.errors = ErrorCode;
|
|
1590
|
+
Logger.levels = LogLevel;
|
|
1679
1591
|
|
|
1680
|
-
|
|
1681
|
-
hash.sha1 = hash.sha.sha1;
|
|
1682
|
-
hash.sha256 = hash.sha.sha256;
|
|
1683
|
-
hash.sha224 = hash.sha.sha224;
|
|
1684
|
-
hash.sha384 = hash.sha.sha384;
|
|
1685
|
-
hash.sha512 = hash.sha.sha512;
|
|
1686
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1687
|
-
}(hash$1));
|
|
1592
|
+
const version$1 = "bytes/5.5.0";
|
|
1688
1593
|
|
|
1689
|
-
|
|
1594
|
+
const logger = new Logger(version$1);
|
|
1595
|
+
///////////////////////////////
|
|
1596
|
+
function isHexable(value) {
|
|
1597
|
+
return !!(value.toHexString);
|
|
1598
|
+
}
|
|
1599
|
+
function addSlice(array) {
|
|
1600
|
+
if (array.slice) {
|
|
1601
|
+
return array;
|
|
1602
|
+
}
|
|
1603
|
+
array.slice = function () {
|
|
1604
|
+
const args = Array.prototype.slice.call(arguments);
|
|
1605
|
+
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1606
|
+
};
|
|
1607
|
+
return array;
|
|
1608
|
+
}
|
|
1609
|
+
function isInteger(value) {
|
|
1610
|
+
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1611
|
+
}
|
|
1612
|
+
function isBytes(value) {
|
|
1613
|
+
if (value == null) {
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
if (value.constructor === Uint8Array) {
|
|
1617
|
+
return true;
|
|
1618
|
+
}
|
|
1619
|
+
if (typeof (value) === "string") {
|
|
1620
|
+
return false;
|
|
1621
|
+
}
|
|
1622
|
+
if (!isInteger(value.length) || value.length < 0) {
|
|
1623
|
+
return false;
|
|
1624
|
+
}
|
|
1625
|
+
for (let i = 0; i < value.length; i++) {
|
|
1626
|
+
const v = value[i];
|
|
1627
|
+
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1628
|
+
return false;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return true;
|
|
1632
|
+
}
|
|
1633
|
+
function arrayify(value, options) {
|
|
1634
|
+
if (!options) {
|
|
1635
|
+
options = {};
|
|
1636
|
+
}
|
|
1637
|
+
if (typeof (value) === "number") {
|
|
1638
|
+
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1639
|
+
const result = [];
|
|
1640
|
+
while (value) {
|
|
1641
|
+
result.unshift(value & 0xff);
|
|
1642
|
+
value = parseInt(String(value / 256));
|
|
1643
|
+
}
|
|
1644
|
+
if (result.length === 0) {
|
|
1645
|
+
result.push(0);
|
|
1646
|
+
}
|
|
1647
|
+
return addSlice(new Uint8Array(result));
|
|
1648
|
+
}
|
|
1649
|
+
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1650
|
+
value = "0x" + value;
|
|
1651
|
+
}
|
|
1652
|
+
if (isHexable(value)) {
|
|
1653
|
+
value = value.toHexString();
|
|
1654
|
+
}
|
|
1655
|
+
if (isHexString(value)) {
|
|
1656
|
+
let hex = value.substring(2);
|
|
1657
|
+
if (hex.length % 2) {
|
|
1658
|
+
if (options.hexPad === "left") {
|
|
1659
|
+
hex = "0x0" + hex.substring(2);
|
|
1660
|
+
}
|
|
1661
|
+
else if (options.hexPad === "right") {
|
|
1662
|
+
hex += "0";
|
|
1663
|
+
}
|
|
1664
|
+
else {
|
|
1665
|
+
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
const result = [];
|
|
1669
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
1670
|
+
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1671
|
+
}
|
|
1672
|
+
return addSlice(new Uint8Array(result));
|
|
1673
|
+
}
|
|
1674
|
+
if (isBytes(value)) {
|
|
1675
|
+
return addSlice(new Uint8Array(value));
|
|
1676
|
+
}
|
|
1677
|
+
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1678
|
+
}
|
|
1679
|
+
function isHexString(value, length) {
|
|
1680
|
+
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1681
|
+
return false;
|
|
1682
|
+
}
|
|
1683
|
+
if (length && value.length !== 2 + 2 * length) {
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
return true;
|
|
1687
|
+
}
|
|
1690
1688
|
|
|
1691
1689
|
const version = "sha2/5.5.0";
|
|
1692
1690
|
|
|
@@ -1718,8 +1716,7 @@ class Struct {
|
|
|
1718
1716
|
class Enum extends Struct {
|
|
1719
1717
|
constructor(properties) {
|
|
1720
1718
|
super(properties);
|
|
1721
|
-
|
|
1722
|
-
_defineProperty(this, "enum", '');
|
|
1719
|
+
this.enum = '';
|
|
1723
1720
|
|
|
1724
1721
|
if (Object.keys(properties).length !== 1) {
|
|
1725
1722
|
throw new Error('Enum can only take single value');
|
|
@@ -1759,8 +1756,7 @@ class PublicKey extends Struct {
|
|
|
1759
1756
|
*/
|
|
1760
1757
|
constructor(value) {
|
|
1761
1758
|
super({});
|
|
1762
|
-
|
|
1763
|
-
_defineProperty(this, "_bn", void 0);
|
|
1759
|
+
this._bn = void 0;
|
|
1764
1760
|
|
|
1765
1761
|
if (isPublicKeyData(value)) {
|
|
1766
1762
|
this._bn = value._bn;
|
|
@@ -1770,7 +1766,7 @@ class PublicKey extends Struct {
|
|
|
1770
1766
|
const decoded = bs58.decode(value);
|
|
1771
1767
|
|
|
1772
1768
|
if (decoded.length != 32) {
|
|
1773
|
-
throw new Error(
|
|
1769
|
+
throw new Error(`Invalid public key input`);
|
|
1774
1770
|
}
|
|
1775
1771
|
|
|
1776
1772
|
this._bn = new BN(decoded);
|
|
@@ -1779,7 +1775,7 @@ class PublicKey extends Struct {
|
|
|
1779
1775
|
}
|
|
1780
1776
|
|
|
1781
1777
|
if (this._bn.byteLength() > 32) {
|
|
1782
|
-
throw new Error(
|
|
1778
|
+
throw new Error(`Invalid public key input`);
|
|
1783
1779
|
}
|
|
1784
1780
|
}
|
|
1785
1781
|
}
|
|
@@ -1859,7 +1855,7 @@ class PublicKey extends Struct {
|
|
|
1859
1855
|
let buffer = Buffer.alloc(0);
|
|
1860
1856
|
seeds.forEach(function (seed) {
|
|
1861
1857
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1862
|
-
throw new TypeError(
|
|
1858
|
+
throw new TypeError(`Max seed length exceeded`);
|
|
1863
1859
|
}
|
|
1864
1860
|
|
|
1865
1861
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
@@ -1869,7 +1865,7 @@ class PublicKey extends Struct {
|
|
|
1869
1865
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1870
1866
|
|
|
1871
1867
|
if (is_on_curve(publicKeyBytes)) {
|
|
1872
|
-
throw new Error(
|
|
1868
|
+
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1873
1869
|
}
|
|
1874
1870
|
|
|
1875
1871
|
return new PublicKey(publicKeyBytes);
|
|
@@ -1903,7 +1899,7 @@ class PublicKey extends Struct {
|
|
|
1903
1899
|
return [address, nonce];
|
|
1904
1900
|
}
|
|
1905
1901
|
|
|
1906
|
-
throw new Error(
|
|
1902
|
+
throw new Error(`Unable to find a viable program address nonce`);
|
|
1907
1903
|
}
|
|
1908
1904
|
/**
|
|
1909
1905
|
* Check that a pubkey is on the ed25519 curve.
|
|
@@ -1915,15 +1911,13 @@ class PublicKey extends Struct {
|
|
|
1915
1911
|
}
|
|
1916
1912
|
|
|
1917
1913
|
}
|
|
1918
|
-
|
|
1919
|
-
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
1920
|
-
|
|
1914
|
+
PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
1921
1915
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
1922
1916
|
kind: 'struct',
|
|
1923
1917
|
fields: [['_bn', 'u256']]
|
|
1924
1918
|
}); // @ts-ignore
|
|
1925
1919
|
|
|
1926
|
-
let naclLowLevel =
|
|
1920
|
+
let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
|
|
1927
1921
|
// This function and its dependents were sourced from:
|
|
1928
1922
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
1929
1923
|
|
|
@@ -1990,7 +1984,7 @@ class Account {
|
|
|
1990
1984
|
* @param secretKey Secret key for the account
|
|
1991
1985
|
*/
|
|
1992
1986
|
constructor(secretKey) {
|
|
1993
|
-
|
|
1987
|
+
this._keypair = void 0;
|
|
1994
1988
|
|
|
1995
1989
|
if (secretKey) {
|
|
1996
1990
|
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
@@ -2126,16 +2120,11 @@ const PUBKEY_LENGTH = 32;
|
|
|
2126
2120
|
|
|
2127
2121
|
class Message {
|
|
2128
2122
|
constructor(args) {
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
_defineProperty(this, "instructions", void 0);
|
|
2136
|
-
|
|
2137
|
-
_defineProperty(this, "indexToProgramIds", new Map());
|
|
2138
|
-
|
|
2123
|
+
this.header = void 0;
|
|
2124
|
+
this.accountKeys = void 0;
|
|
2125
|
+
this.recentBlockhash = void 0;
|
|
2126
|
+
this.instructions = void 0;
|
|
2127
|
+
this.indexToProgramIds = new Map();
|
|
2139
2128
|
this.header = args.header;
|
|
2140
2129
|
this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
|
|
2141
2130
|
this.recentBlockhash = args.recentBlockhash;
|
|
@@ -2309,12 +2298,9 @@ class TransactionInstruction {
|
|
|
2309
2298
|
* Program input
|
|
2310
2299
|
*/
|
|
2311
2300
|
constructor(opts) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
_defineProperty(this, "data", Buffer.alloc(0));
|
|
2317
|
-
|
|
2301
|
+
this.keys = void 0;
|
|
2302
|
+
this.programId = void 0;
|
|
2303
|
+
this.data = Buffer.alloc(0);
|
|
2318
2304
|
this.programId = opts.programId;
|
|
2319
2305
|
this.keys = opts.keys;
|
|
2320
2306
|
|
|
@@ -2356,16 +2342,11 @@ class Transaction {
|
|
|
2356
2342
|
* Construct an empty Transaction
|
|
2357
2343
|
*/
|
|
2358
2344
|
constructor(opts) {
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
_defineProperty(this, "recentBlockhash", void 0);
|
|
2366
|
-
|
|
2367
|
-
_defineProperty(this, "nonceInfo", void 0);
|
|
2368
|
-
|
|
2345
|
+
this.signatures = [];
|
|
2346
|
+
this.feePayer = void 0;
|
|
2347
|
+
this.instructions = [];
|
|
2348
|
+
this.recentBlockhash = void 0;
|
|
2349
|
+
this.nonceInfo = void 0;
|
|
2369
2350
|
opts && Object.assign(this, opts);
|
|
2370
2351
|
}
|
|
2371
2352
|
/**
|
|
@@ -2429,7 +2410,7 @@ class Transaction {
|
|
|
2429
2410
|
|
|
2430
2411
|
for (let i = 0; i < this.instructions.length; i++) {
|
|
2431
2412
|
if (this.instructions[i].programId === undefined) {
|
|
2432
|
-
throw new Error(
|
|
2413
|
+
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2433
2414
|
}
|
|
2434
2415
|
}
|
|
2435
2416
|
|
|
@@ -2504,7 +2485,7 @@ class Transaction {
|
|
|
2504
2485
|
console.warn('Transaction references a signature that is unnecessary, ' + 'only the fee payer and instruction signer accounts should sign a transaction. ' + 'This behavior is deprecated and will throw an error in the next major version release.');
|
|
2505
2486
|
}
|
|
2506
2487
|
} else {
|
|
2507
|
-
throw new Error(
|
|
2488
|
+
throw new Error(`unknown signer: ${signature.publicKey.toString()}`);
|
|
2508
2489
|
}
|
|
2509
2490
|
}
|
|
2510
2491
|
|
|
@@ -2711,7 +2692,7 @@ class Transaction {
|
|
|
2711
2692
|
_partialSign(message, ...signers) {
|
|
2712
2693
|
const signData = message.serialize();
|
|
2713
2694
|
signers.forEach(signer => {
|
|
2714
|
-
const signature =
|
|
2695
|
+
const signature = nacl.sign.detached(signData, signer.secretKey);
|
|
2715
2696
|
|
|
2716
2697
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2717
2698
|
});
|
|
@@ -2739,7 +2720,7 @@ class Transaction {
|
|
|
2739
2720
|
const index = this.signatures.findIndex(sigpair => pubkey.equals(sigpair.publicKey));
|
|
2740
2721
|
|
|
2741
2722
|
if (index < 0) {
|
|
2742
|
-
throw new Error(
|
|
2723
|
+
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2743
2724
|
}
|
|
2744
2725
|
|
|
2745
2726
|
this.signatures[index].signature = Buffer.from(signature);
|
|
@@ -2767,7 +2748,7 @@ class Transaction {
|
|
|
2767
2748
|
return false;
|
|
2768
2749
|
}
|
|
2769
2750
|
} else {
|
|
2770
|
-
if (!
|
|
2751
|
+
if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
2771
2752
|
return false;
|
|
2772
2753
|
}
|
|
2773
2754
|
}
|
|
@@ -2815,12 +2796,12 @@ class Transaction {
|
|
|
2815
2796
|
signature
|
|
2816
2797
|
}, index) => {
|
|
2817
2798
|
if (signature !== null) {
|
|
2818
|
-
assert(signature.length === 64,
|
|
2799
|
+
assert(signature.length === 64, `signature has invalid length`);
|
|
2819
2800
|
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2820
2801
|
}
|
|
2821
2802
|
});
|
|
2822
2803
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
2823
|
-
assert(wireTransaction.length <= PACKET_DATA_SIZE,
|
|
2804
|
+
assert(wireTransaction.length <= PACKET_DATA_SIZE, `Transaction too large: ${wireTransaction.length} > ${PACKET_DATA_SIZE}`);
|
|
2824
2805
|
return wireTransaction;
|
|
2825
2806
|
}
|
|
2826
2807
|
/**
|
|
@@ -2939,7 +2920,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2939
2920
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2940
2921
|
|
|
2941
2922
|
if (status.err) {
|
|
2942
|
-
throw new Error(
|
|
2923
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2943
2924
|
}
|
|
2944
2925
|
|
|
2945
2926
|
return signature;
|
|
@@ -2982,7 +2963,7 @@ function decodeData(type, buffer) {
|
|
|
2982
2963
|
}
|
|
2983
2964
|
|
|
2984
2965
|
if (data.instruction !== type.index) {
|
|
2985
|
-
throw new Error(
|
|
2966
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2986
2967
|
}
|
|
2987
2968
|
|
|
2988
2969
|
return data;
|
|
@@ -3016,12 +2997,9 @@ class NonceAccount {
|
|
|
3016
2997
|
* @internal
|
|
3017
2998
|
*/
|
|
3018
2999
|
constructor(args) {
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
_defineProperty(this, "feeCalculator", void 0);
|
|
3024
|
-
|
|
3000
|
+
this.authorizedPubkey = void 0;
|
|
3001
|
+
this.nonce = void 0;
|
|
3002
|
+
this.feeCalculator = void 0;
|
|
3025
3003
|
this.authorizedPubkey = args.authorizedPubkey;
|
|
3026
3004
|
this.nonce = args.nonce;
|
|
3027
3005
|
this.feeCalculator = args.feeCalculator;
|
|
@@ -3322,7 +3300,7 @@ class SystemInstruction {
|
|
|
3322
3300
|
|
|
3323
3301
|
static checkKeyLength(keys, expectedLength) {
|
|
3324
3302
|
if (keys.length < expectedLength) {
|
|
3325
|
-
throw new Error(
|
|
3303
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
3326
3304
|
}
|
|
3327
3305
|
}
|
|
3328
3306
|
|
|
@@ -3754,8 +3732,7 @@ class SystemProgram {
|
|
|
3754
3732
|
}
|
|
3755
3733
|
|
|
3756
3734
|
}
|
|
3757
|
-
|
|
3758
|
-
_defineProperty(SystemProgram, "programId", new PublicKey('11111111111111111111111111111111'));
|
|
3735
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3759
3736
|
|
|
3760
3737
|
// rest of the Transaction fields
|
|
3761
3738
|
//
|
|
@@ -3924,8 +3901,7 @@ class Loader {
|
|
|
3924
3901
|
}
|
|
3925
3902
|
|
|
3926
3903
|
}
|
|
3927
|
-
|
|
3928
|
-
_defineProperty(Loader, "chunkSize", CHUNK_SIZE);
|
|
3904
|
+
Loader.chunkSize = CHUNK_SIZE;
|
|
3929
3905
|
|
|
3930
3906
|
const BPF_LOADER_PROGRAM_ID = new PublicKey('BPFLoader2111111111111111111111111111111111');
|
|
3931
3907
|
/**
|
|
@@ -4564,16 +4540,11 @@ class EpochSchedule {
|
|
|
4564
4540
|
|
|
4565
4541
|
/** The first slot of `firstNormalEpoch` */
|
|
4566
4542
|
constructor(slotsPerEpoch, leaderScheduleSlotOffset, warmup, firstNormalEpoch, firstNormalSlot) {
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
_defineProperty(this, "firstNormalEpoch", void 0);
|
|
4574
|
-
|
|
4575
|
-
_defineProperty(this, "firstNormalSlot", void 0);
|
|
4576
|
-
|
|
4543
|
+
this.slotsPerEpoch = void 0;
|
|
4544
|
+
this.leaderScheduleSlotOffset = void 0;
|
|
4545
|
+
this.warmup = void 0;
|
|
4546
|
+
this.firstNormalEpoch = void 0;
|
|
4547
|
+
this.firstNormalSlot = void 0;
|
|
4577
4548
|
this.slotsPerEpoch = slotsPerEpoch;
|
|
4578
4549
|
this.leaderScheduleSlotOffset = leaderScheduleSlotOffset;
|
|
4579
4550
|
this.warmup = warmup;
|
|
@@ -4625,9 +4596,7 @@ class EpochSchedule {
|
|
|
4625
4596
|
class SendTransactionError extends Error {
|
|
4626
4597
|
constructor(message, logs) {
|
|
4627
4598
|
super(message);
|
|
4628
|
-
|
|
4629
|
-
_defineProperty(this, "logs", void 0);
|
|
4630
|
-
|
|
4599
|
+
this.logs = void 0;
|
|
4631
4600
|
this.logs = logs;
|
|
4632
4601
|
}
|
|
4633
4602
|
|
|
@@ -4906,7 +4875,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4906
4875
|
break;
|
|
4907
4876
|
}
|
|
4908
4877
|
|
|
4909
|
-
console.log(
|
|
4878
|
+
console.log(`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`);
|
|
4910
4879
|
await sleep(waitTime);
|
|
4911
4880
|
waitTime *= 2;
|
|
4912
4881
|
}
|
|
@@ -4916,7 +4885,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4916
4885
|
if (res.ok) {
|
|
4917
4886
|
callback(null, text);
|
|
4918
4887
|
} else {
|
|
4919
|
-
callback(new Error(
|
|
4888
|
+
callback(new Error(`${res.status} ${res.statusText}: ${text}`));
|
|
4920
4889
|
}
|
|
4921
4890
|
} catch (err) {
|
|
4922
4891
|
if (err instanceof Error) callback(err);
|
|
@@ -5581,67 +5550,39 @@ class Connection {
|
|
|
5581
5550
|
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
5582
5551
|
*/
|
|
5583
5552
|
constructor(endpoint, commitmentOrConfig) {
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
_defineProperty(this, "_rpcWebSocket", void 0);
|
|
5599
|
-
|
|
5600
|
-
_defineProperty(this, "_rpcWebSocketConnected", false);
|
|
5601
|
-
|
|
5602
|
-
_defineProperty(this, "_rpcWebSocketHeartbeat", null);
|
|
5603
|
-
|
|
5604
|
-
_defineProperty(this, "_rpcWebSocketIdleTimeout", null);
|
|
5605
|
-
|
|
5606
|
-
_defineProperty(this, "_disableBlockhashCaching", false);
|
|
5607
|
-
|
|
5608
|
-
_defineProperty(this, "_pollingBlockhash", false);
|
|
5609
|
-
|
|
5610
|
-
_defineProperty(this, "_blockhashInfo", {
|
|
5553
|
+
this._commitment = void 0;
|
|
5554
|
+
this._confirmTransactionInitialTimeout = void 0;
|
|
5555
|
+
this._rpcEndpoint = void 0;
|
|
5556
|
+
this._rpcWsEndpoint = void 0;
|
|
5557
|
+
this._rpcClient = void 0;
|
|
5558
|
+
this._rpcRequest = void 0;
|
|
5559
|
+
this._rpcBatchRequest = void 0;
|
|
5560
|
+
this._rpcWebSocket = void 0;
|
|
5561
|
+
this._rpcWebSocketConnected = false;
|
|
5562
|
+
this._rpcWebSocketHeartbeat = null;
|
|
5563
|
+
this._rpcWebSocketIdleTimeout = null;
|
|
5564
|
+
this._disableBlockhashCaching = false;
|
|
5565
|
+
this._pollingBlockhash = false;
|
|
5566
|
+
this._blockhashInfo = {
|
|
5611
5567
|
recentBlockhash: null,
|
|
5612
5568
|
lastFetch: 0,
|
|
5613
5569
|
transactionSignatures: [],
|
|
5614
5570
|
simulatedSignatures: []
|
|
5615
|
-
}
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
_defineProperty(this, "_signatureSubscriptions", {});
|
|
5632
|
-
|
|
5633
|
-
_defineProperty(this, "_slotSubscriptionCounter", 0);
|
|
5634
|
-
|
|
5635
|
-
_defineProperty(this, "_slotSubscriptions", {});
|
|
5636
|
-
|
|
5637
|
-
_defineProperty(this, "_logsSubscriptionCounter", 0);
|
|
5638
|
-
|
|
5639
|
-
_defineProperty(this, "_logsSubscriptions", {});
|
|
5640
|
-
|
|
5641
|
-
_defineProperty(this, "_slotUpdateSubscriptionCounter", 0);
|
|
5642
|
-
|
|
5643
|
-
_defineProperty(this, "_slotUpdateSubscriptions", {});
|
|
5644
|
-
|
|
5571
|
+
};
|
|
5572
|
+
this._accountChangeSubscriptionCounter = 0;
|
|
5573
|
+
this._accountChangeSubscriptions = {};
|
|
5574
|
+
this._programAccountChangeSubscriptionCounter = 0;
|
|
5575
|
+
this._programAccountChangeSubscriptions = {};
|
|
5576
|
+
this._rootSubscriptionCounter = 0;
|
|
5577
|
+
this._rootSubscriptions = {};
|
|
5578
|
+
this._signatureSubscriptionCounter = 0;
|
|
5579
|
+
this._signatureSubscriptions = {};
|
|
5580
|
+
this._slotSubscriptionCounter = 0;
|
|
5581
|
+
this._slotSubscriptions = {};
|
|
5582
|
+
this._logsSubscriptionCounter = 0;
|
|
5583
|
+
this._logsSubscriptions = {};
|
|
5584
|
+
this._slotUpdateSubscriptionCounter = 0;
|
|
5585
|
+
this._slotUpdateSubscriptions = {};
|
|
5645
5586
|
let url = new URL(endpoint);
|
|
5646
5587
|
const useHttps = url.protocol === 'https:';
|
|
5647
5588
|
let wsEndpoint;
|
|
@@ -5776,10 +5717,24 @@ class Connection {
|
|
|
5776
5717
|
*/
|
|
5777
5718
|
|
|
5778
5719
|
|
|
5779
|
-
async getSupply(
|
|
5780
|
-
|
|
5720
|
+
async getSupply(config) {
|
|
5721
|
+
let configArg = {};
|
|
5722
|
+
|
|
5723
|
+
if (typeof config === 'string') {
|
|
5724
|
+
configArg = {
|
|
5725
|
+
commitment: config
|
|
5726
|
+
};
|
|
5727
|
+
} else if (config) {
|
|
5728
|
+
configArg = { ...config,
|
|
5729
|
+
commitment: config && config.commitment || this.commitment
|
|
5730
|
+
};
|
|
5731
|
+
} else {
|
|
5732
|
+
configArg = {
|
|
5733
|
+
commitment: this.commitment
|
|
5734
|
+
};
|
|
5735
|
+
}
|
|
5781
5736
|
|
|
5782
|
-
const unsafeRes = await this._rpcRequest('getSupply',
|
|
5737
|
+
const unsafeRes = await this._rpcRequest('getSupply', [configArg]);
|
|
5783
5738
|
const res = create(unsafeRes, GetSupplyRpcResult);
|
|
5784
5739
|
|
|
5785
5740
|
if ('error' in res) {
|
|
@@ -6001,7 +5956,7 @@ class Connection {
|
|
|
6001
5956
|
const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
|
|
6002
5957
|
|
|
6003
5958
|
if ('error' in res) {
|
|
6004
|
-
throw new Error(
|
|
5959
|
+
throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
|
|
6005
5960
|
}
|
|
6006
5961
|
|
|
6007
5962
|
return res.result;
|
|
@@ -6137,7 +6092,7 @@ class Connection {
|
|
|
6137
6092
|
|
|
6138
6093
|
if (response === null) {
|
|
6139
6094
|
const duration = (Date.now() - start) / 1000;
|
|
6140
|
-
throw new Error(
|
|
6095
|
+
throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
|
6141
6096
|
}
|
|
6142
6097
|
|
|
6143
6098
|
return response;
|
|
@@ -6290,16 +6245,11 @@ class Connection {
|
|
|
6290
6245
|
|
|
6291
6246
|
|
|
6292
6247
|
async getTotalSupply(commitment) {
|
|
6293
|
-
const
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
if ('error' in res) {
|
|
6299
|
-
throw new Error('failed to get total supply: ' + res.error.message);
|
|
6300
|
-
}
|
|
6301
|
-
|
|
6302
|
-
return res.result.value.total;
|
|
6248
|
+
const result = await this.getSupply({
|
|
6249
|
+
commitment,
|
|
6250
|
+
excludeNonCirculatingAccountsList: true
|
|
6251
|
+
});
|
|
6252
|
+
return result.value.total;
|
|
6303
6253
|
}
|
|
6304
6254
|
/**
|
|
6305
6255
|
* Fetch the cluster InflationGovernor parameters
|
|
@@ -6916,7 +6866,7 @@ class Connection {
|
|
|
6916
6866
|
await sleep(MS_PER_SLOT / 2);
|
|
6917
6867
|
}
|
|
6918
6868
|
|
|
6919
|
-
throw new Error(
|
|
6869
|
+
throw new Error(`Unable to obtain a new blockhash after ${Date.now() - startTime}ms`);
|
|
6920
6870
|
} finally {
|
|
6921
6871
|
this._pollingBlockhash = false;
|
|
6922
6872
|
}
|
|
@@ -7173,7 +7123,7 @@ class Connection {
|
|
|
7173
7123
|
}
|
|
7174
7124
|
|
|
7175
7125
|
if (err instanceof Error) {
|
|
7176
|
-
console.error(
|
|
7126
|
+
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
7177
7127
|
}
|
|
7178
7128
|
}
|
|
7179
7129
|
}
|
|
@@ -7193,7 +7143,7 @@ class Connection {
|
|
|
7193
7143
|
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
7194
7144
|
} catch (err) {
|
|
7195
7145
|
if (err instanceof Error) {
|
|
7196
|
-
console.error(
|
|
7146
|
+
console.error(`${rpcMethod} error:`, err.message);
|
|
7197
7147
|
}
|
|
7198
7148
|
}
|
|
7199
7149
|
}
|
|
@@ -7358,7 +7308,7 @@ class Connection {
|
|
|
7358
7308
|
|
|
7359
7309
|
this._updateSubscriptions();
|
|
7360
7310
|
} else {
|
|
7361
|
-
throw new Error(
|
|
7311
|
+
throw new Error(`Unknown account change id: ${id}`);
|
|
7362
7312
|
}
|
|
7363
7313
|
}
|
|
7364
7314
|
/**
|
|
@@ -7424,7 +7374,7 @@ class Connection {
|
|
|
7424
7374
|
|
|
7425
7375
|
this._updateSubscriptions();
|
|
7426
7376
|
} else {
|
|
7427
|
-
throw new Error(
|
|
7377
|
+
throw new Error(`Unknown program account change id: ${id}`);
|
|
7428
7378
|
}
|
|
7429
7379
|
}
|
|
7430
7380
|
/**
|
|
@@ -7454,7 +7404,7 @@ class Connection {
|
|
|
7454
7404
|
|
|
7455
7405
|
async removeOnLogsListener(id) {
|
|
7456
7406
|
if (!this._logsSubscriptions[id]) {
|
|
7457
|
-
throw new Error(
|
|
7407
|
+
throw new Error(`Unknown logs id: ${id}`);
|
|
7458
7408
|
}
|
|
7459
7409
|
|
|
7460
7410
|
const subInfo = this._logsSubscriptions[id];
|
|
@@ -7530,7 +7480,7 @@ class Connection {
|
|
|
7530
7480
|
|
|
7531
7481
|
this._updateSubscriptions();
|
|
7532
7482
|
} else {
|
|
7533
|
-
throw new Error(
|
|
7483
|
+
throw new Error(`Unknown slot change id: ${id}`);
|
|
7534
7484
|
}
|
|
7535
7485
|
}
|
|
7536
7486
|
/**
|
|
@@ -7583,7 +7533,7 @@ class Connection {
|
|
|
7583
7533
|
|
|
7584
7534
|
this._updateSubscriptions();
|
|
7585
7535
|
} else {
|
|
7586
|
-
throw new Error(
|
|
7536
|
+
throw new Error(`Unknown slot update id: ${id}`);
|
|
7587
7537
|
}
|
|
7588
7538
|
}
|
|
7589
7539
|
|
|
@@ -7724,7 +7674,7 @@ class Connection {
|
|
|
7724
7674
|
|
|
7725
7675
|
this._updateSubscriptions();
|
|
7726
7676
|
} else {
|
|
7727
|
-
throw new Error(
|
|
7677
|
+
throw new Error(`Unknown signature result id: ${id}`);
|
|
7728
7678
|
}
|
|
7729
7679
|
}
|
|
7730
7680
|
/**
|
|
@@ -7776,7 +7726,7 @@ class Connection {
|
|
|
7776
7726
|
|
|
7777
7727
|
this._updateSubscriptions();
|
|
7778
7728
|
} else {
|
|
7779
|
-
throw new Error(
|
|
7729
|
+
throw new Error(`Unknown root change id: ${id}`);
|
|
7780
7730
|
}
|
|
7781
7731
|
}
|
|
7782
7732
|
|
|
@@ -7797,7 +7747,7 @@ class Keypair {
|
|
|
7797
7747
|
* @param keypair ed25519 keypair
|
|
7798
7748
|
*/
|
|
7799
7749
|
constructor(keypair) {
|
|
7800
|
-
|
|
7750
|
+
this._keypair = void 0;
|
|
7801
7751
|
|
|
7802
7752
|
if (keypair) {
|
|
7803
7753
|
this._keypair = keypair;
|
|
@@ -7901,8 +7851,8 @@ class Ed25519Program {
|
|
|
7901
7851
|
signature,
|
|
7902
7852
|
instructionIndex
|
|
7903
7853
|
} = params;
|
|
7904
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES$1,
|
|
7905
|
-
assert(signature.length === SIGNATURE_BYTES,
|
|
7854
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
|
|
7855
|
+
assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
7906
7856
|
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
7907
7857
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
7908
7858
|
const messageDataOffset = signatureOffset + signature.length;
|
|
@@ -7940,12 +7890,12 @@ class Ed25519Program {
|
|
|
7940
7890
|
message,
|
|
7941
7891
|
instructionIndex
|
|
7942
7892
|
} = params;
|
|
7943
|
-
assert(privateKey.length === PRIVATE_KEY_BYTES$1,
|
|
7893
|
+
assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
7944
7894
|
|
|
7945
7895
|
try {
|
|
7946
7896
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
7947
7897
|
const publicKey = keypair.publicKey.toBytes();
|
|
7948
|
-
const signature =
|
|
7898
|
+
const signature = nacl.sign.detached(message, keypair.secretKey);
|
|
7949
7899
|
return this.createInstructionWithPublicKey({
|
|
7950
7900
|
publicKey,
|
|
7951
7901
|
message,
|
|
@@ -7953,13 +7903,12 @@ class Ed25519Program {
|
|
|
7953
7903
|
instructionIndex
|
|
7954
7904
|
});
|
|
7955
7905
|
} catch (error) {
|
|
7956
|
-
throw new Error(
|
|
7906
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
7957
7907
|
}
|
|
7958
7908
|
}
|
|
7959
7909
|
|
|
7960
7910
|
}
|
|
7961
|
-
|
|
7962
|
-
_defineProperty(Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
|
|
7911
|
+
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7963
7912
|
|
|
7964
7913
|
/**
|
|
7965
7914
|
* Address of the stake config account which configures the rate
|
|
@@ -7982,10 +7931,8 @@ class Authorized {
|
|
|
7982
7931
|
* @param withdrawer the withdraw authority
|
|
7983
7932
|
*/
|
|
7984
7933
|
constructor(staker, withdrawer) {
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
_defineProperty(this, "withdrawer", void 0);
|
|
7988
|
-
|
|
7934
|
+
this.staker = void 0;
|
|
7935
|
+
this.withdrawer = void 0;
|
|
7989
7936
|
this.staker = staker;
|
|
7990
7937
|
this.withdrawer = withdrawer;
|
|
7991
7938
|
}
|
|
@@ -8006,12 +7953,9 @@ class Lockup {
|
|
|
8006
7953
|
* Create a new Lockup object
|
|
8007
7954
|
*/
|
|
8008
7955
|
constructor(unixTimestamp, epoch, custodian) {
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
_defineProperty(this, "custodian", void 0);
|
|
8014
|
-
|
|
7956
|
+
this.unixTimestamp = void 0;
|
|
7957
|
+
this.epoch = void 0;
|
|
7958
|
+
this.custodian = void 0;
|
|
8015
7959
|
this.unixTimestamp = unixTimestamp;
|
|
8016
7960
|
this.epoch = epoch;
|
|
8017
7961
|
this.custodian = custodian;
|
|
@@ -8026,7 +7970,7 @@ class Lockup {
|
|
|
8026
7970
|
* Create stake account transaction params
|
|
8027
7971
|
*/
|
|
8028
7972
|
|
|
8029
|
-
|
|
7973
|
+
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
8030
7974
|
|
|
8031
7975
|
/**
|
|
8032
7976
|
* Stake Instruction class
|
|
@@ -8239,7 +8183,7 @@ class StakeInstruction {
|
|
|
8239
8183
|
|
|
8240
8184
|
static checkKeyLength(keys, expectedLength) {
|
|
8241
8185
|
if (keys.length < expectedLength) {
|
|
8242
|
-
throw new Error(
|
|
8186
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8243
8187
|
}
|
|
8244
8188
|
}
|
|
8245
8189
|
|
|
@@ -8714,10 +8658,8 @@ class StakeProgram {
|
|
|
8714
8658
|
}
|
|
8715
8659
|
|
|
8716
8660
|
}
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
_defineProperty(StakeProgram, "space", 200);
|
|
8661
|
+
StakeProgram.programId = new PublicKey('Stake11111111111111111111111111111111111111');
|
|
8662
|
+
StakeProgram.space = 200;
|
|
8721
8663
|
|
|
8722
8664
|
const {
|
|
8723
8665
|
publicKeyCreate,
|
|
@@ -8747,12 +8689,12 @@ class Secp256k1Program {
|
|
|
8747
8689
|
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
8748
8690
|
*/
|
|
8749
8691
|
static publicKeyToEthAddress(publicKey) {
|
|
8750
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES,
|
|
8692
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8751
8693
|
|
|
8752
8694
|
try {
|
|
8753
|
-
return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8695
|
+
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8754
8696
|
} catch (error) {
|
|
8755
|
-
throw new Error(
|
|
8697
|
+
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8756
8698
|
}
|
|
8757
8699
|
}
|
|
8758
8700
|
/**
|
|
@@ -8803,7 +8745,7 @@ class Secp256k1Program {
|
|
|
8803
8745
|
ethAddress = rawAddress;
|
|
8804
8746
|
}
|
|
8805
8747
|
|
|
8806
|
-
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES,
|
|
8748
|
+
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES, `Address must be ${ETHEREUM_ADDRESS_BYTES} bytes but received ${ethAddress.length} bytes`);
|
|
8807
8749
|
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
|
8808
8750
|
const ethAddressOffset = dataStart;
|
|
8809
8751
|
const signatureOffset = dataStart + ethAddress.length;
|
|
@@ -8842,13 +8784,13 @@ class Secp256k1Program {
|
|
|
8842
8784
|
message,
|
|
8843
8785
|
instructionIndex
|
|
8844
8786
|
} = params;
|
|
8845
|
-
assert(pkey.length === PRIVATE_KEY_BYTES,
|
|
8787
|
+
assert(pkey.length === PRIVATE_KEY_BYTES, `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`);
|
|
8846
8788
|
|
|
8847
8789
|
try {
|
|
8848
8790
|
const privateKey = toBuffer(pkey);
|
|
8849
8791
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
8850
8792
|
|
|
8851
|
-
const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
|
|
8793
|
+
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
8852
8794
|
const {
|
|
8853
8795
|
signature,
|
|
8854
8796
|
recid: recoveryId
|
|
@@ -8861,13 +8803,12 @@ class Secp256k1Program {
|
|
|
8861
8803
|
instructionIndex
|
|
8862
8804
|
});
|
|
8863
8805
|
} catch (error) {
|
|
8864
|
-
throw new Error(
|
|
8806
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
8865
8807
|
}
|
|
8866
8808
|
}
|
|
8867
8809
|
|
|
8868
8810
|
}
|
|
8869
|
-
|
|
8870
|
-
_defineProperty(Secp256k1Program, "programId", new PublicKey('KeccakSecp256k11111111111111111111111111111'));
|
|
8811
|
+
Secp256k1Program.programId = new PublicKey('KeccakSecp256k11111111111111111111111111111');
|
|
8871
8812
|
|
|
8872
8813
|
const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
|
|
8873
8814
|
/**
|
|
@@ -8900,10 +8841,8 @@ class ValidatorInfo {
|
|
|
8900
8841
|
* @param info validator information
|
|
8901
8842
|
*/
|
|
8902
8843
|
constructor(key, info) {
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
_defineProperty(this, "info", void 0);
|
|
8906
|
-
|
|
8844
|
+
this.key = void 0;
|
|
8845
|
+
this.info = void 0;
|
|
8907
8846
|
this.key = key;
|
|
8908
8847
|
this.info = info;
|
|
8909
8848
|
}
|
|
@@ -8967,26 +8906,16 @@ class VoteAccount {
|
|
|
8967
8906
|
* @internal
|
|
8968
8907
|
*/
|
|
8969
8908
|
constructor(args) {
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
_defineProperty(this, "rootSlot", void 0);
|
|
8981
|
-
|
|
8982
|
-
_defineProperty(this, "epoch", void 0);
|
|
8983
|
-
|
|
8984
|
-
_defineProperty(this, "credits", void 0);
|
|
8985
|
-
|
|
8986
|
-
_defineProperty(this, "lastEpochCredits", void 0);
|
|
8987
|
-
|
|
8988
|
-
_defineProperty(this, "epochCredits", void 0);
|
|
8989
|
-
|
|
8909
|
+
this.nodePubkey = void 0;
|
|
8910
|
+
this.authorizedVoterPubkey = void 0;
|
|
8911
|
+
this.authorizedWithdrawerPubkey = void 0;
|
|
8912
|
+
this.commission = void 0;
|
|
8913
|
+
this.votes = void 0;
|
|
8914
|
+
this.rootSlot = void 0;
|
|
8915
|
+
this.epoch = void 0;
|
|
8916
|
+
this.credits = void 0;
|
|
8917
|
+
this.lastEpochCredits = void 0;
|
|
8918
|
+
this.epochCredits = void 0;
|
|
8990
8919
|
this.nodePubkey = args.nodePubkey;
|
|
8991
8920
|
this.authorizedVoterPubkey = args.authorizedVoterPubkey;
|
|
8992
8921
|
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
@@ -9049,7 +8978,7 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, options)
|
|
|
9049
8978
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
9050
8979
|
|
|
9051
8980
|
if (status.err) {
|
|
9052
|
-
throw new Error(
|
|
8981
|
+
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
9053
8982
|
}
|
|
9054
8983
|
|
|
9055
8984
|
return signature;
|
|
@@ -9081,7 +9010,7 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9081
9010
|
const url = endpoint[key][cluster];
|
|
9082
9011
|
|
|
9083
9012
|
if (!url) {
|
|
9084
|
-
throw new Error(
|
|
9013
|
+
throw new Error(`Unknown ${key} cluster: ${cluster}`);
|
|
9085
9014
|
}
|
|
9086
9015
|
|
|
9087
9016
|
return url;
|