@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.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';
|
|
@@ -13,7 +11,7 @@ import RpcClient from 'jayson/lib/client/browser';
|
|
|
13
11
|
import http from 'http';
|
|
14
12
|
import https from 'https';
|
|
15
13
|
import secp256k1 from 'secp256k1';
|
|
16
|
-
import
|
|
14
|
+
import sha3 from 'js-sha3';
|
|
17
15
|
|
|
18
16
|
const toBuffer = arr => {
|
|
19
17
|
if (Buffer.isBuffer(arr)) {
|
|
@@ -25,743 +23,334 @@ const toBuffer = arr => {
|
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
var hash$1 = {};
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
var utils$9 = {};
|
|
29
|
+
|
|
30
|
+
var minimalisticAssert = assert$6;
|
|
31
|
+
|
|
32
|
+
function assert$6(val, msg) {
|
|
33
|
+
if (!val)
|
|
34
|
+
throw new Error(msg || 'Assertion failed');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
assert$6.equal = function assertEqual(l, r, msg) {
|
|
38
|
+
if (l != r)
|
|
39
|
+
throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
var inherits$1 = {exports: {}};
|
|
43
|
+
|
|
44
|
+
var inherits_browser = {exports: {}};
|
|
45
|
+
|
|
46
|
+
if (typeof Object.create === 'function') {
|
|
47
|
+
// implementation from standard node.js 'util' module
|
|
48
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
49
|
+
ctor.super_ = superCtor;
|
|
50
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
|
51
|
+
constructor: {
|
|
52
|
+
value: ctor,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
writable: true,
|
|
55
|
+
configurable: true
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
} else {
|
|
60
|
+
// old school shim for old browsers
|
|
61
|
+
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
62
|
+
ctor.super_ = superCtor;
|
|
63
|
+
var TempCtor = function () {};
|
|
64
|
+
TempCtor.prototype = superCtor.prototype;
|
|
65
|
+
ctor.prototype = new TempCtor();
|
|
66
|
+
ctor.prototype.constructor = ctor;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
var util = require('util');
|
|
72
|
+
if (typeof util.inherits !== 'function') throw '';
|
|
73
|
+
inherits$1.exports = util.inherits;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
inherits$1.exports = inherits_browser.exports;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var assert$5 = minimalisticAssert;
|
|
79
|
+
var inherits = inherits$1.exports;
|
|
80
|
+
|
|
81
|
+
utils$9.inherits = inherits;
|
|
82
|
+
|
|
83
|
+
function isSurrogatePair(msg, i) {
|
|
84
|
+
if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (i < 0 || i + 1 >= msg.length) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function toArray(msg, enc) {
|
|
94
|
+
if (Array.isArray(msg))
|
|
95
|
+
return msg.slice();
|
|
96
|
+
if (!msg)
|
|
97
|
+
return [];
|
|
98
|
+
var res = [];
|
|
99
|
+
if (typeof msg === 'string') {
|
|
100
|
+
if (!enc) {
|
|
101
|
+
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
102
|
+
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
103
|
+
// Apache License 2.0
|
|
104
|
+
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
105
|
+
var p = 0;
|
|
106
|
+
for (var i = 0; i < msg.length; i++) {
|
|
107
|
+
var c = msg.charCodeAt(i);
|
|
108
|
+
if (c < 128) {
|
|
109
|
+
res[p++] = c;
|
|
110
|
+
} else if (c < 2048) {
|
|
111
|
+
res[p++] = (c >> 6) | 192;
|
|
112
|
+
res[p++] = (c & 63) | 128;
|
|
113
|
+
} else if (isSurrogatePair(msg, i)) {
|
|
114
|
+
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
115
|
+
res[p++] = (c >> 18) | 240;
|
|
116
|
+
res[p++] = ((c >> 12) & 63) | 128;
|
|
117
|
+
res[p++] = ((c >> 6) & 63) | 128;
|
|
118
|
+
res[p++] = (c & 63) | 128;
|
|
119
|
+
} else {
|
|
120
|
+
res[p++] = (c >> 12) | 224;
|
|
121
|
+
res[p++] = ((c >> 6) & 63) | 128;
|
|
122
|
+
res[p++] = (c & 63) | 128;
|
|
55
123
|
}
|
|
124
|
+
}
|
|
125
|
+
} else if (enc === 'hex') {
|
|
126
|
+
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
127
|
+
if (msg.length % 2 !== 0)
|
|
128
|
+
msg = '0' + msg;
|
|
129
|
+
for (i = 0; i < msg.length; i += 2)
|
|
130
|
+
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
56
131
|
}
|
|
57
|
-
|
|
58
|
-
|
|
132
|
+
} else {
|
|
133
|
+
for (i = 0; i < msg.length; i++)
|
|
134
|
+
res[i] = msg[i] | 0;
|
|
135
|
+
}
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
utils$9.toArray = toArray;
|
|
139
|
+
|
|
140
|
+
function toHex(msg) {
|
|
141
|
+
var res = '';
|
|
142
|
+
for (var i = 0; i < msg.length; i++)
|
|
143
|
+
res += zero2(msg[i].toString(16));
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
utils$9.toHex = toHex;
|
|
147
|
+
|
|
148
|
+
function htonl(w) {
|
|
149
|
+
var res = (w >>> 24) |
|
|
150
|
+
((w >>> 8) & 0xff00) |
|
|
151
|
+
((w << 8) & 0xff0000) |
|
|
152
|
+
((w & 0xff) << 24);
|
|
153
|
+
return res >>> 0;
|
|
154
|
+
}
|
|
155
|
+
utils$9.htonl = htonl;
|
|
156
|
+
|
|
157
|
+
function toHex32(msg, endian) {
|
|
158
|
+
var res = '';
|
|
159
|
+
for (var i = 0; i < msg.length; i++) {
|
|
160
|
+
var w = msg[i];
|
|
161
|
+
if (endian === 'little')
|
|
162
|
+
w = htonl(w);
|
|
163
|
+
res += zero8(w.toString(16));
|
|
164
|
+
}
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
utils$9.toHex32 = toHex32;
|
|
168
|
+
|
|
169
|
+
function zero2(word) {
|
|
170
|
+
if (word.length === 1)
|
|
171
|
+
return '0' + word;
|
|
172
|
+
else
|
|
173
|
+
return word;
|
|
174
|
+
}
|
|
175
|
+
utils$9.zero2 = zero2;
|
|
176
|
+
|
|
177
|
+
function zero8(word) {
|
|
178
|
+
if (word.length === 7)
|
|
179
|
+
return '0' + word;
|
|
180
|
+
else if (word.length === 6)
|
|
181
|
+
return '00' + word;
|
|
182
|
+
else if (word.length === 5)
|
|
183
|
+
return '000' + word;
|
|
184
|
+
else if (word.length === 4)
|
|
185
|
+
return '0000' + word;
|
|
186
|
+
else if (word.length === 3)
|
|
187
|
+
return '00000' + word;
|
|
188
|
+
else if (word.length === 2)
|
|
189
|
+
return '000000' + word;
|
|
190
|
+
else if (word.length === 1)
|
|
191
|
+
return '0000000' + word;
|
|
192
|
+
else
|
|
193
|
+
return word;
|
|
194
|
+
}
|
|
195
|
+
utils$9.zero8 = zero8;
|
|
196
|
+
|
|
197
|
+
function join32(msg, start, end, endian) {
|
|
198
|
+
var len = end - start;
|
|
199
|
+
assert$5(len % 4 === 0);
|
|
200
|
+
var res = new Array(len / 4);
|
|
201
|
+
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
202
|
+
var w;
|
|
203
|
+
if (endian === 'big')
|
|
204
|
+
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
205
|
+
else
|
|
206
|
+
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
207
|
+
res[i] = w >>> 0;
|
|
208
|
+
}
|
|
209
|
+
return res;
|
|
210
|
+
}
|
|
211
|
+
utils$9.join32 = join32;
|
|
212
|
+
|
|
213
|
+
function split32(msg, endian) {
|
|
214
|
+
var res = new Array(msg.length * 4);
|
|
215
|
+
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
216
|
+
var m = msg[i];
|
|
217
|
+
if (endian === 'big') {
|
|
218
|
+
res[k] = m >>> 24;
|
|
219
|
+
res[k + 1] = (m >>> 16) & 0xff;
|
|
220
|
+
res[k + 2] = (m >>> 8) & 0xff;
|
|
221
|
+
res[k + 3] = m & 0xff;
|
|
222
|
+
} else {
|
|
223
|
+
res[k + 3] = m >>> 24;
|
|
224
|
+
res[k + 2] = (m >>> 16) & 0xff;
|
|
225
|
+
res[k + 1] = (m >>> 8) & 0xff;
|
|
226
|
+
res[k] = m & 0xff;
|
|
59
227
|
}
|
|
60
|
-
|
|
228
|
+
}
|
|
229
|
+
return res;
|
|
61
230
|
}
|
|
62
|
-
|
|
63
|
-
var LogLevel;
|
|
64
|
-
(function (LogLevel) {
|
|
65
|
-
LogLevel["DEBUG"] = "DEBUG";
|
|
66
|
-
LogLevel["INFO"] = "INFO";
|
|
67
|
-
LogLevel["WARNING"] = "WARNING";
|
|
68
|
-
LogLevel["ERROR"] = "ERROR";
|
|
69
|
-
LogLevel["OFF"] = "OFF";
|
|
70
|
-
})(LogLevel || (LogLevel = {}));
|
|
71
|
-
var ErrorCode;
|
|
72
|
-
(function (ErrorCode) {
|
|
73
|
-
///////////////////
|
|
74
|
-
// Generic Errors
|
|
75
|
-
// Unknown Error
|
|
76
|
-
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
77
|
-
// Not Implemented
|
|
78
|
-
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
79
|
-
// Unsupported Operation
|
|
80
|
-
// - operation
|
|
81
|
-
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
82
|
-
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
83
|
-
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
84
|
-
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
85
|
-
// Some sort of bad response from the server
|
|
86
|
-
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
87
|
-
// Timeout
|
|
88
|
-
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
89
|
-
///////////////////
|
|
90
|
-
// Operational Errors
|
|
91
|
-
// Buffer Overrun
|
|
92
|
-
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
93
|
-
// Numeric Fault
|
|
94
|
-
// - operation: the operation being executed
|
|
95
|
-
// - fault: the reason this faulted
|
|
96
|
-
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
97
|
-
///////////////////
|
|
98
|
-
// Argument Errors
|
|
99
|
-
// Missing new operator to an object
|
|
100
|
-
// - name: The name of the class
|
|
101
|
-
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
102
|
-
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
103
|
-
// - argument: The argument name that was invalid
|
|
104
|
-
// - value: The value of the argument
|
|
105
|
-
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
106
|
-
// Missing argument to a function:
|
|
107
|
-
// - count: The number of arguments received
|
|
108
|
-
// - expectedCount: The number of arguments expected
|
|
109
|
-
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
110
|
-
// Too many arguments
|
|
111
|
-
// - count: The number of arguments received
|
|
112
|
-
// - expectedCount: The number of arguments expected
|
|
113
|
-
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
114
|
-
///////////////////
|
|
115
|
-
// Blockchain Errors
|
|
116
|
-
// Call exception
|
|
117
|
-
// - transaction: the transaction
|
|
118
|
-
// - address?: the contract address
|
|
119
|
-
// - args?: The arguments passed into the function
|
|
120
|
-
// - method?: The Solidity method signature
|
|
121
|
-
// - errorSignature?: The EIP848 error signature
|
|
122
|
-
// - errorArgs?: The EIP848 error parameters
|
|
123
|
-
// - reason: The reason (only for EIP848 "Error(string)")
|
|
124
|
-
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
125
|
-
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
126
|
-
// - transaction: the transaction attempted
|
|
127
|
-
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
128
|
-
// Nonce has already been used
|
|
129
|
-
// - transaction: the transaction attempted
|
|
130
|
-
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
131
|
-
// The replacement fee for the transaction is too low
|
|
132
|
-
// - transaction: the transaction attempted
|
|
133
|
-
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
134
|
-
// The gas limit could not be estimated
|
|
135
|
-
// - transaction: the transaction passed to estimateGas
|
|
136
|
-
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
137
|
-
// The transaction was replaced by one with a higher gas price
|
|
138
|
-
// - reason: "cancelled", "replaced" or "repriced"
|
|
139
|
-
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
140
|
-
// - hash: original transaction hash
|
|
141
|
-
// - replacement: the full TransactionsResponse for the replacement
|
|
142
|
-
// - receipt: the receipt of the replacement
|
|
143
|
-
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
144
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
145
|
-
const HEX = "0123456789abcdef";
|
|
146
|
-
class Logger {
|
|
147
|
-
constructor(version) {
|
|
148
|
-
Object.defineProperty(this, "version", {
|
|
149
|
-
enumerable: true,
|
|
150
|
-
value: version,
|
|
151
|
-
writable: false
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
_log(logLevel, args) {
|
|
155
|
-
const level = logLevel.toLowerCase();
|
|
156
|
-
if (LogLevels[level] == null) {
|
|
157
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
158
|
-
}
|
|
159
|
-
if (_logLevel > LogLevels[level]) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
console.log.apply(console, args);
|
|
163
|
-
}
|
|
164
|
-
debug(...args) {
|
|
165
|
-
this._log(Logger.levels.DEBUG, args);
|
|
166
|
-
}
|
|
167
|
-
info(...args) {
|
|
168
|
-
this._log(Logger.levels.INFO, args);
|
|
169
|
-
}
|
|
170
|
-
warn(...args) {
|
|
171
|
-
this._log(Logger.levels.WARNING, args);
|
|
172
|
-
}
|
|
173
|
-
makeError(message, code, params) {
|
|
174
|
-
// Errors are being censored
|
|
175
|
-
if (_censorErrors) {
|
|
176
|
-
return this.makeError("censored error", code, {});
|
|
177
|
-
}
|
|
178
|
-
if (!code) {
|
|
179
|
-
code = Logger.errors.UNKNOWN_ERROR;
|
|
180
|
-
}
|
|
181
|
-
if (!params) {
|
|
182
|
-
params = {};
|
|
183
|
-
}
|
|
184
|
-
const messageDetails = [];
|
|
185
|
-
Object.keys(params).forEach((key) => {
|
|
186
|
-
const value = params[key];
|
|
187
|
-
try {
|
|
188
|
-
if (value instanceof Uint8Array) {
|
|
189
|
-
let hex = "";
|
|
190
|
-
for (let i = 0; i < value.length; i++) {
|
|
191
|
-
hex += HEX[value[i] >> 4];
|
|
192
|
-
hex += HEX[value[i] & 0x0f];
|
|
193
|
-
}
|
|
194
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
messageDetails.push(`code=${code}`);
|
|
205
|
-
messageDetails.push(`version=${this.version}`);
|
|
206
|
-
const reason = message;
|
|
207
|
-
if (messageDetails.length) {
|
|
208
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
209
|
-
}
|
|
210
|
-
// @TODO: Any??
|
|
211
|
-
const error = new Error(message);
|
|
212
|
-
error.reason = reason;
|
|
213
|
-
error.code = code;
|
|
214
|
-
Object.keys(params).forEach(function (key) {
|
|
215
|
-
error[key] = params[key];
|
|
216
|
-
});
|
|
217
|
-
return error;
|
|
218
|
-
}
|
|
219
|
-
throwError(message, code, params) {
|
|
220
|
-
throw this.makeError(message, code, params);
|
|
221
|
-
}
|
|
222
|
-
throwArgumentError(message, name, value) {
|
|
223
|
-
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
224
|
-
argument: name,
|
|
225
|
-
value: value
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
assert(condition, message, code, params) {
|
|
229
|
-
if (!!condition) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
this.throwError(message, code, params);
|
|
233
|
-
}
|
|
234
|
-
assertArgument(condition, message, name, value) {
|
|
235
|
-
if (!!condition) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
this.throwArgumentError(message, name, value);
|
|
239
|
-
}
|
|
240
|
-
checkNormalize(message) {
|
|
241
|
-
if (_normalizeError) {
|
|
242
|
-
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
243
|
-
operation: "String.prototype.normalize", form: _normalizeError
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
checkSafeUint53(value, message) {
|
|
248
|
-
if (typeof (value) !== "number") {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (message == null) {
|
|
252
|
-
message = "value not safe";
|
|
253
|
-
}
|
|
254
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
255
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
256
|
-
operation: "checkSafeInteger",
|
|
257
|
-
fault: "out-of-safe-range",
|
|
258
|
-
value: value
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
if (value % 1) {
|
|
262
|
-
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
263
|
-
operation: "checkSafeInteger",
|
|
264
|
-
fault: "non-integer",
|
|
265
|
-
value: value
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
270
|
-
if (message) {
|
|
271
|
-
message = ": " + message;
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
message = "";
|
|
275
|
-
}
|
|
276
|
-
if (count < expectedCount) {
|
|
277
|
-
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
278
|
-
count: count,
|
|
279
|
-
expectedCount: expectedCount
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
if (count > expectedCount) {
|
|
283
|
-
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
284
|
-
count: count,
|
|
285
|
-
expectedCount: expectedCount
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
checkNew(target, kind) {
|
|
290
|
-
if (target === Object || target == null) {
|
|
291
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
checkAbstract(target, kind) {
|
|
295
|
-
if (target === kind) {
|
|
296
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
297
|
-
}
|
|
298
|
-
else if (target === Object || target == null) {
|
|
299
|
-
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
static globalLogger() {
|
|
303
|
-
if (!_globalLogger) {
|
|
304
|
-
_globalLogger = new Logger(version$2);
|
|
305
|
-
}
|
|
306
|
-
return _globalLogger;
|
|
307
|
-
}
|
|
308
|
-
static setCensorship(censorship, permanent) {
|
|
309
|
-
if (!censorship && permanent) {
|
|
310
|
-
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
311
|
-
operation: "setCensorship"
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
if (_permanentCensorErrors) {
|
|
315
|
-
if (!censorship) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
319
|
-
operation: "setCensorship"
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
_censorErrors = !!censorship;
|
|
323
|
-
_permanentCensorErrors = !!permanent;
|
|
324
|
-
}
|
|
325
|
-
static setLogLevel(logLevel) {
|
|
326
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
327
|
-
if (level == null) {
|
|
328
|
-
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
_logLevel = level;
|
|
332
|
-
}
|
|
333
|
-
static from(version) {
|
|
334
|
-
return new Logger(version);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
Logger.errors = ErrorCode;
|
|
338
|
-
Logger.levels = LogLevel;
|
|
231
|
+
utils$9.split32 = split32;
|
|
339
232
|
|
|
340
|
-
|
|
233
|
+
function rotr32$1(w, b) {
|
|
234
|
+
return (w >>> b) | (w << (32 - b));
|
|
235
|
+
}
|
|
236
|
+
utils$9.rotr32 = rotr32$1;
|
|
341
237
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
function isHexable(value) {
|
|
345
|
-
return !!(value.toHexString);
|
|
238
|
+
function rotl32$2(w, b) {
|
|
239
|
+
return (w << b) | (w >>> (32 - b));
|
|
346
240
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
array.slice = function () {
|
|
352
|
-
const args = Array.prototype.slice.call(arguments);
|
|
353
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
354
|
-
};
|
|
355
|
-
return array;
|
|
241
|
+
utils$9.rotl32 = rotl32$2;
|
|
242
|
+
|
|
243
|
+
function sum32$3(a, b) {
|
|
244
|
+
return (a + b) >>> 0;
|
|
356
245
|
}
|
|
357
|
-
|
|
358
|
-
|
|
246
|
+
utils$9.sum32 = sum32$3;
|
|
247
|
+
|
|
248
|
+
function sum32_3$1(a, b, c) {
|
|
249
|
+
return (a + b + c) >>> 0;
|
|
359
250
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (value.constructor === Uint8Array) {
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
if (typeof (value) === "string") {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
for (let i = 0; i < value.length; i++) {
|
|
374
|
-
const v = value[i];
|
|
375
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return true;
|
|
251
|
+
utils$9.sum32_3 = sum32_3$1;
|
|
252
|
+
|
|
253
|
+
function sum32_4$2(a, b, c, d) {
|
|
254
|
+
return (a + b + c + d) >>> 0;
|
|
380
255
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (typeof (value) === "number") {
|
|
386
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
387
|
-
const result = [];
|
|
388
|
-
while (value) {
|
|
389
|
-
result.unshift(value & 0xff);
|
|
390
|
-
value = parseInt(String(value / 256));
|
|
391
|
-
}
|
|
392
|
-
if (result.length === 0) {
|
|
393
|
-
result.push(0);
|
|
394
|
-
}
|
|
395
|
-
return addSlice(new Uint8Array(result));
|
|
396
|
-
}
|
|
397
|
-
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
398
|
-
value = "0x" + value;
|
|
399
|
-
}
|
|
400
|
-
if (isHexable(value)) {
|
|
401
|
-
value = value.toHexString();
|
|
402
|
-
}
|
|
403
|
-
if (isHexString(value)) {
|
|
404
|
-
let hex = value.substring(2);
|
|
405
|
-
if (hex.length % 2) {
|
|
406
|
-
if (options.hexPad === "left") {
|
|
407
|
-
hex = "0x0" + hex.substring(2);
|
|
408
|
-
}
|
|
409
|
-
else if (options.hexPad === "right") {
|
|
410
|
-
hex += "0";
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
const result = [];
|
|
417
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
418
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
419
|
-
}
|
|
420
|
-
return addSlice(new Uint8Array(result));
|
|
421
|
-
}
|
|
422
|
-
if (isBytes(value)) {
|
|
423
|
-
return addSlice(new Uint8Array(value));
|
|
424
|
-
}
|
|
425
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
256
|
+
utils$9.sum32_4 = sum32_4$2;
|
|
257
|
+
|
|
258
|
+
function sum32_5$2(a, b, c, d, e) {
|
|
259
|
+
return (a + b + c + d + e) >>> 0;
|
|
426
260
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
261
|
+
utils$9.sum32_5 = sum32_5$2;
|
|
262
|
+
|
|
263
|
+
function sum64$1(buf, pos, ah, al) {
|
|
264
|
+
var bh = buf[pos];
|
|
265
|
+
var bl = buf[pos + 1];
|
|
266
|
+
|
|
267
|
+
var lo = (al + bl) >>> 0;
|
|
268
|
+
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
269
|
+
buf[pos] = hi >>> 0;
|
|
270
|
+
buf[pos + 1] = lo;
|
|
435
271
|
}
|
|
272
|
+
utils$9.sum64 = sum64$1;
|
|
436
273
|
|
|
437
|
-
|
|
274
|
+
function sum64_hi$1(ah, al, bh, bl) {
|
|
275
|
+
var lo = (al + bl) >>> 0;
|
|
276
|
+
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
277
|
+
return hi >>> 0;
|
|
278
|
+
}
|
|
279
|
+
utils$9.sum64_hi = sum64_hi$1;
|
|
438
280
|
|
|
439
|
-
|
|
281
|
+
function sum64_lo$1(ah, al, bh, bl) {
|
|
282
|
+
var lo = al + bl;
|
|
283
|
+
return lo >>> 0;
|
|
284
|
+
}
|
|
285
|
+
utils$9.sum64_lo = sum64_lo$1;
|
|
440
286
|
|
|
441
|
-
|
|
287
|
+
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
288
|
+
var carry = 0;
|
|
289
|
+
var lo = al;
|
|
290
|
+
lo = (lo + bl) >>> 0;
|
|
291
|
+
carry += lo < al ? 1 : 0;
|
|
292
|
+
lo = (lo + cl) >>> 0;
|
|
293
|
+
carry += lo < cl ? 1 : 0;
|
|
294
|
+
lo = (lo + dl) >>> 0;
|
|
295
|
+
carry += lo < dl ? 1 : 0;
|
|
442
296
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
throw new Error(msg || 'Assertion failed');
|
|
297
|
+
var hi = ah + bh + ch + dh + carry;
|
|
298
|
+
return hi >>> 0;
|
|
446
299
|
}
|
|
300
|
+
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
447
301
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
302
|
+
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
303
|
+
var lo = al + bl + cl + dl;
|
|
304
|
+
return lo >>> 0;
|
|
305
|
+
}
|
|
306
|
+
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
452
307
|
|
|
453
|
-
|
|
308
|
+
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
309
|
+
var carry = 0;
|
|
310
|
+
var lo = al;
|
|
311
|
+
lo = (lo + bl) >>> 0;
|
|
312
|
+
carry += lo < al ? 1 : 0;
|
|
313
|
+
lo = (lo + cl) >>> 0;
|
|
314
|
+
carry += lo < cl ? 1 : 0;
|
|
315
|
+
lo = (lo + dl) >>> 0;
|
|
316
|
+
carry += lo < dl ? 1 : 0;
|
|
317
|
+
lo = (lo + el) >>> 0;
|
|
318
|
+
carry += lo < el ? 1 : 0;
|
|
454
319
|
|
|
455
|
-
var
|
|
320
|
+
var hi = ah + bh + ch + dh + eh + carry;
|
|
321
|
+
return hi >>> 0;
|
|
322
|
+
}
|
|
323
|
+
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
456
324
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
462
|
-
constructor: {
|
|
463
|
-
value: ctor,
|
|
464
|
-
enumerable: false,
|
|
465
|
-
writable: true,
|
|
466
|
-
configurable: true
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
};
|
|
470
|
-
} else {
|
|
471
|
-
// old school shim for old browsers
|
|
472
|
-
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
473
|
-
ctor.super_ = superCtor;
|
|
474
|
-
var TempCtor = function () {};
|
|
475
|
-
TempCtor.prototype = superCtor.prototype;
|
|
476
|
-
ctor.prototype = new TempCtor();
|
|
477
|
-
ctor.prototype.constructor = ctor;
|
|
478
|
-
};
|
|
325
|
+
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
326
|
+
var lo = al + bl + cl + dl + el;
|
|
327
|
+
|
|
328
|
+
return lo >>> 0;
|
|
479
329
|
}
|
|
330
|
+
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
480
331
|
|
|
481
|
-
|
|
482
|
-
var
|
|
483
|
-
|
|
484
|
-
inherits$1.exports = util.inherits;
|
|
485
|
-
} catch (e) {
|
|
486
|
-
inherits$1.exports = inherits_browser.exports;
|
|
332
|
+
function rotr64_hi$1(ah, al, num) {
|
|
333
|
+
var r = (al << (32 - num)) | (ah >>> num);
|
|
334
|
+
return r >>> 0;
|
|
487
335
|
}
|
|
336
|
+
utils$9.rotr64_hi = rotr64_hi$1;
|
|
488
337
|
|
|
489
|
-
|
|
490
|
-
var
|
|
338
|
+
function rotr64_lo$1(ah, al, num) {
|
|
339
|
+
var r = (ah << (32 - num)) | (al >>> num);
|
|
340
|
+
return r >>> 0;
|
|
341
|
+
}
|
|
342
|
+
utils$9.rotr64_lo = rotr64_lo$1;
|
|
491
343
|
|
|
492
|
-
|
|
344
|
+
function shr64_hi$1(ah, al, num) {
|
|
345
|
+
return ah >>> num;
|
|
346
|
+
}
|
|
347
|
+
utils$9.shr64_hi = shr64_hi$1;
|
|
493
348
|
|
|
494
|
-
function
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
if (i < 0 || i + 1 >= msg.length) {
|
|
499
|
-
return false;
|
|
500
|
-
}
|
|
501
|
-
return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
|
|
349
|
+
function shr64_lo$1(ah, al, num) {
|
|
350
|
+
var r = (ah << (32 - num)) | (al >>> num);
|
|
351
|
+
return r >>> 0;
|
|
502
352
|
}
|
|
503
|
-
|
|
504
|
-
function toArray(msg, enc) {
|
|
505
|
-
if (Array.isArray(msg))
|
|
506
|
-
return msg.slice();
|
|
507
|
-
if (!msg)
|
|
508
|
-
return [];
|
|
509
|
-
var res = [];
|
|
510
|
-
if (typeof msg === 'string') {
|
|
511
|
-
if (!enc) {
|
|
512
|
-
// Inspired by stringToUtf8ByteArray() in closure-library by Google
|
|
513
|
-
// https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
|
|
514
|
-
// Apache License 2.0
|
|
515
|
-
// https://github.com/google/closure-library/blob/master/LICENSE
|
|
516
|
-
var p = 0;
|
|
517
|
-
for (var i = 0; i < msg.length; i++) {
|
|
518
|
-
var c = msg.charCodeAt(i);
|
|
519
|
-
if (c < 128) {
|
|
520
|
-
res[p++] = c;
|
|
521
|
-
} else if (c < 2048) {
|
|
522
|
-
res[p++] = (c >> 6) | 192;
|
|
523
|
-
res[p++] = (c & 63) | 128;
|
|
524
|
-
} else if (isSurrogatePair(msg, i)) {
|
|
525
|
-
c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
|
|
526
|
-
res[p++] = (c >> 18) | 240;
|
|
527
|
-
res[p++] = ((c >> 12) & 63) | 128;
|
|
528
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
529
|
-
res[p++] = (c & 63) | 128;
|
|
530
|
-
} else {
|
|
531
|
-
res[p++] = (c >> 12) | 224;
|
|
532
|
-
res[p++] = ((c >> 6) & 63) | 128;
|
|
533
|
-
res[p++] = (c & 63) | 128;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
} else if (enc === 'hex') {
|
|
537
|
-
msg = msg.replace(/[^a-z0-9]+/ig, '');
|
|
538
|
-
if (msg.length % 2 !== 0)
|
|
539
|
-
msg = '0' + msg;
|
|
540
|
-
for (i = 0; i < msg.length; i += 2)
|
|
541
|
-
res.push(parseInt(msg[i] + msg[i + 1], 16));
|
|
542
|
-
}
|
|
543
|
-
} else {
|
|
544
|
-
for (i = 0; i < msg.length; i++)
|
|
545
|
-
res[i] = msg[i] | 0;
|
|
546
|
-
}
|
|
547
|
-
return res;
|
|
548
|
-
}
|
|
549
|
-
utils$9.toArray = toArray;
|
|
550
|
-
|
|
551
|
-
function toHex(msg) {
|
|
552
|
-
var res = '';
|
|
553
|
-
for (var i = 0; i < msg.length; i++)
|
|
554
|
-
res += zero2(msg[i].toString(16));
|
|
555
|
-
return res;
|
|
556
|
-
}
|
|
557
|
-
utils$9.toHex = toHex;
|
|
558
|
-
|
|
559
|
-
function htonl(w) {
|
|
560
|
-
var res = (w >>> 24) |
|
|
561
|
-
((w >>> 8) & 0xff00) |
|
|
562
|
-
((w << 8) & 0xff0000) |
|
|
563
|
-
((w & 0xff) << 24);
|
|
564
|
-
return res >>> 0;
|
|
565
|
-
}
|
|
566
|
-
utils$9.htonl = htonl;
|
|
567
|
-
|
|
568
|
-
function toHex32(msg, endian) {
|
|
569
|
-
var res = '';
|
|
570
|
-
for (var i = 0; i < msg.length; i++) {
|
|
571
|
-
var w = msg[i];
|
|
572
|
-
if (endian === 'little')
|
|
573
|
-
w = htonl(w);
|
|
574
|
-
res += zero8(w.toString(16));
|
|
575
|
-
}
|
|
576
|
-
return res;
|
|
577
|
-
}
|
|
578
|
-
utils$9.toHex32 = toHex32;
|
|
579
|
-
|
|
580
|
-
function zero2(word) {
|
|
581
|
-
if (word.length === 1)
|
|
582
|
-
return '0' + word;
|
|
583
|
-
else
|
|
584
|
-
return word;
|
|
585
|
-
}
|
|
586
|
-
utils$9.zero2 = zero2;
|
|
587
|
-
|
|
588
|
-
function zero8(word) {
|
|
589
|
-
if (word.length === 7)
|
|
590
|
-
return '0' + word;
|
|
591
|
-
else if (word.length === 6)
|
|
592
|
-
return '00' + word;
|
|
593
|
-
else if (word.length === 5)
|
|
594
|
-
return '000' + word;
|
|
595
|
-
else if (word.length === 4)
|
|
596
|
-
return '0000' + word;
|
|
597
|
-
else if (word.length === 3)
|
|
598
|
-
return '00000' + word;
|
|
599
|
-
else if (word.length === 2)
|
|
600
|
-
return '000000' + word;
|
|
601
|
-
else if (word.length === 1)
|
|
602
|
-
return '0000000' + word;
|
|
603
|
-
else
|
|
604
|
-
return word;
|
|
605
|
-
}
|
|
606
|
-
utils$9.zero8 = zero8;
|
|
607
|
-
|
|
608
|
-
function join32(msg, start, end, endian) {
|
|
609
|
-
var len = end - start;
|
|
610
|
-
assert$5(len % 4 === 0);
|
|
611
|
-
var res = new Array(len / 4);
|
|
612
|
-
for (var i = 0, k = start; i < res.length; i++, k += 4) {
|
|
613
|
-
var w;
|
|
614
|
-
if (endian === 'big')
|
|
615
|
-
w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
|
|
616
|
-
else
|
|
617
|
-
w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
|
|
618
|
-
res[i] = w >>> 0;
|
|
619
|
-
}
|
|
620
|
-
return res;
|
|
621
|
-
}
|
|
622
|
-
utils$9.join32 = join32;
|
|
623
|
-
|
|
624
|
-
function split32(msg, endian) {
|
|
625
|
-
var res = new Array(msg.length * 4);
|
|
626
|
-
for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
|
|
627
|
-
var m = msg[i];
|
|
628
|
-
if (endian === 'big') {
|
|
629
|
-
res[k] = m >>> 24;
|
|
630
|
-
res[k + 1] = (m >>> 16) & 0xff;
|
|
631
|
-
res[k + 2] = (m >>> 8) & 0xff;
|
|
632
|
-
res[k + 3] = m & 0xff;
|
|
633
|
-
} else {
|
|
634
|
-
res[k + 3] = m >>> 24;
|
|
635
|
-
res[k + 2] = (m >>> 16) & 0xff;
|
|
636
|
-
res[k + 1] = (m >>> 8) & 0xff;
|
|
637
|
-
res[k] = m & 0xff;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return res;
|
|
641
|
-
}
|
|
642
|
-
utils$9.split32 = split32;
|
|
643
|
-
|
|
644
|
-
function rotr32$1(w, b) {
|
|
645
|
-
return (w >>> b) | (w << (32 - b));
|
|
646
|
-
}
|
|
647
|
-
utils$9.rotr32 = rotr32$1;
|
|
648
|
-
|
|
649
|
-
function rotl32$2(w, b) {
|
|
650
|
-
return (w << b) | (w >>> (32 - b));
|
|
651
|
-
}
|
|
652
|
-
utils$9.rotl32 = rotl32$2;
|
|
653
|
-
|
|
654
|
-
function sum32$3(a, b) {
|
|
655
|
-
return (a + b) >>> 0;
|
|
656
|
-
}
|
|
657
|
-
utils$9.sum32 = sum32$3;
|
|
658
|
-
|
|
659
|
-
function sum32_3$1(a, b, c) {
|
|
660
|
-
return (a + b + c) >>> 0;
|
|
661
|
-
}
|
|
662
|
-
utils$9.sum32_3 = sum32_3$1;
|
|
663
|
-
|
|
664
|
-
function sum32_4$2(a, b, c, d) {
|
|
665
|
-
return (a + b + c + d) >>> 0;
|
|
666
|
-
}
|
|
667
|
-
utils$9.sum32_4 = sum32_4$2;
|
|
668
|
-
|
|
669
|
-
function sum32_5$2(a, b, c, d, e) {
|
|
670
|
-
return (a + b + c + d + e) >>> 0;
|
|
671
|
-
}
|
|
672
|
-
utils$9.sum32_5 = sum32_5$2;
|
|
673
|
-
|
|
674
|
-
function sum64$1(buf, pos, ah, al) {
|
|
675
|
-
var bh = buf[pos];
|
|
676
|
-
var bl = buf[pos + 1];
|
|
677
|
-
|
|
678
|
-
var lo = (al + bl) >>> 0;
|
|
679
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
680
|
-
buf[pos] = hi >>> 0;
|
|
681
|
-
buf[pos + 1] = lo;
|
|
682
|
-
}
|
|
683
|
-
utils$9.sum64 = sum64$1;
|
|
684
|
-
|
|
685
|
-
function sum64_hi$1(ah, al, bh, bl) {
|
|
686
|
-
var lo = (al + bl) >>> 0;
|
|
687
|
-
var hi = (lo < al ? 1 : 0) + ah + bh;
|
|
688
|
-
return hi >>> 0;
|
|
689
|
-
}
|
|
690
|
-
utils$9.sum64_hi = sum64_hi$1;
|
|
691
|
-
|
|
692
|
-
function sum64_lo$1(ah, al, bh, bl) {
|
|
693
|
-
var lo = al + bl;
|
|
694
|
-
return lo >>> 0;
|
|
695
|
-
}
|
|
696
|
-
utils$9.sum64_lo = sum64_lo$1;
|
|
697
|
-
|
|
698
|
-
function sum64_4_hi$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
699
|
-
var carry = 0;
|
|
700
|
-
var lo = al;
|
|
701
|
-
lo = (lo + bl) >>> 0;
|
|
702
|
-
carry += lo < al ? 1 : 0;
|
|
703
|
-
lo = (lo + cl) >>> 0;
|
|
704
|
-
carry += lo < cl ? 1 : 0;
|
|
705
|
-
lo = (lo + dl) >>> 0;
|
|
706
|
-
carry += lo < dl ? 1 : 0;
|
|
707
|
-
|
|
708
|
-
var hi = ah + bh + ch + dh + carry;
|
|
709
|
-
return hi >>> 0;
|
|
710
|
-
}
|
|
711
|
-
utils$9.sum64_4_hi = sum64_4_hi$1;
|
|
712
|
-
|
|
713
|
-
function sum64_4_lo$1(ah, al, bh, bl, ch, cl, dh, dl) {
|
|
714
|
-
var lo = al + bl + cl + dl;
|
|
715
|
-
return lo >>> 0;
|
|
716
|
-
}
|
|
717
|
-
utils$9.sum64_4_lo = sum64_4_lo$1;
|
|
718
|
-
|
|
719
|
-
function sum64_5_hi$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
720
|
-
var carry = 0;
|
|
721
|
-
var lo = al;
|
|
722
|
-
lo = (lo + bl) >>> 0;
|
|
723
|
-
carry += lo < al ? 1 : 0;
|
|
724
|
-
lo = (lo + cl) >>> 0;
|
|
725
|
-
carry += lo < cl ? 1 : 0;
|
|
726
|
-
lo = (lo + dl) >>> 0;
|
|
727
|
-
carry += lo < dl ? 1 : 0;
|
|
728
|
-
lo = (lo + el) >>> 0;
|
|
729
|
-
carry += lo < el ? 1 : 0;
|
|
730
|
-
|
|
731
|
-
var hi = ah + bh + ch + dh + eh + carry;
|
|
732
|
-
return hi >>> 0;
|
|
733
|
-
}
|
|
734
|
-
utils$9.sum64_5_hi = sum64_5_hi$1;
|
|
735
|
-
|
|
736
|
-
function sum64_5_lo$1(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
|
|
737
|
-
var lo = al + bl + cl + dl + el;
|
|
738
|
-
|
|
739
|
-
return lo >>> 0;
|
|
740
|
-
}
|
|
741
|
-
utils$9.sum64_5_lo = sum64_5_lo$1;
|
|
742
|
-
|
|
743
|
-
function rotr64_hi$1(ah, al, num) {
|
|
744
|
-
var r = (al << (32 - num)) | (ah >>> num);
|
|
745
|
-
return r >>> 0;
|
|
746
|
-
}
|
|
747
|
-
utils$9.rotr64_hi = rotr64_hi$1;
|
|
748
|
-
|
|
749
|
-
function rotr64_lo$1(ah, al, num) {
|
|
750
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
751
|
-
return r >>> 0;
|
|
752
|
-
}
|
|
753
|
-
utils$9.rotr64_lo = rotr64_lo$1;
|
|
754
|
-
|
|
755
|
-
function shr64_hi$1(ah, al, num) {
|
|
756
|
-
return ah >>> num;
|
|
757
|
-
}
|
|
758
|
-
utils$9.shr64_hi = shr64_hi$1;
|
|
759
|
-
|
|
760
|
-
function shr64_lo$1(ah, al, num) {
|
|
761
|
-
var r = (ah << (32 - num)) | (al >>> num);
|
|
762
|
-
return r >>> 0;
|
|
763
|
-
}
|
|
764
|
-
utils$9.shr64_lo = shr64_lo$1;
|
|
353
|
+
utils$9.shr64_lo = shr64_lo$1;
|
|
765
354
|
|
|
766
355
|
var common$5 = {};
|
|
767
356
|
|
|
@@ -1643,57 +1232,466 @@ function Hmac(hash, key, enc) {
|
|
|
1643
1232
|
|
|
1644
1233
|
this._init(utils.toArray(key, enc));
|
|
1645
1234
|
}
|
|
1646
|
-
var hmac = Hmac;
|
|
1647
|
-
|
|
1648
|
-
Hmac.prototype._init = function init(key) {
|
|
1649
|
-
// Shorten key, if needed
|
|
1650
|
-
if (key.length > this.blockSize)
|
|
1651
|
-
key = new this.Hash().update(key).digest();
|
|
1652
|
-
assert$1(key.length <= this.blockSize);
|
|
1653
|
-
|
|
1654
|
-
// Add padding to key
|
|
1655
|
-
for (var i = key.length; i < this.blockSize; i++)
|
|
1656
|
-
key.push(0);
|
|
1657
|
-
|
|
1658
|
-
for (i = 0; i < key.length; i++)
|
|
1659
|
-
key[i] ^= 0x36;
|
|
1660
|
-
this.inner = new this.Hash().update(key);
|
|
1661
|
-
|
|
1662
|
-
// 0x36 ^ 0x5c = 0x6a
|
|
1663
|
-
for (i = 0; i < key.length; i++)
|
|
1664
|
-
key[i] ^= 0x6a;
|
|
1665
|
-
this.outer = new this.Hash().update(key);
|
|
1666
|
-
};
|
|
1667
|
-
|
|
1668
|
-
Hmac.prototype.update = function update(msg, enc) {
|
|
1669
|
-
this.inner.update(msg, enc);
|
|
1670
|
-
return this;
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
Hmac.prototype.digest = function digest(enc) {
|
|
1674
|
-
this.outer.update(this.inner.digest());
|
|
1675
|
-
return this.outer.digest(enc);
|
|
1676
|
-
};
|
|
1677
|
-
|
|
1678
|
-
(function (exports) {
|
|
1679
|
-
var hash = exports;
|
|
1680
|
-
|
|
1681
|
-
hash.utils = utils$9;
|
|
1682
|
-
hash.common = common$5;
|
|
1683
|
-
hash.sha = sha;
|
|
1684
|
-
hash.ripemd = ripemd;
|
|
1685
|
-
hash.hmac = hmac;
|
|
1235
|
+
var hmac = Hmac;
|
|
1236
|
+
|
|
1237
|
+
Hmac.prototype._init = function init(key) {
|
|
1238
|
+
// Shorten key, if needed
|
|
1239
|
+
if (key.length > this.blockSize)
|
|
1240
|
+
key = new this.Hash().update(key).digest();
|
|
1241
|
+
assert$1(key.length <= this.blockSize);
|
|
1242
|
+
|
|
1243
|
+
// Add padding to key
|
|
1244
|
+
for (var i = key.length; i < this.blockSize; i++)
|
|
1245
|
+
key.push(0);
|
|
1246
|
+
|
|
1247
|
+
for (i = 0; i < key.length; i++)
|
|
1248
|
+
key[i] ^= 0x36;
|
|
1249
|
+
this.inner = new this.Hash().update(key);
|
|
1250
|
+
|
|
1251
|
+
// 0x36 ^ 0x5c = 0x6a
|
|
1252
|
+
for (i = 0; i < key.length; i++)
|
|
1253
|
+
key[i] ^= 0x6a;
|
|
1254
|
+
this.outer = new this.Hash().update(key);
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
Hmac.prototype.update = function update(msg, enc) {
|
|
1258
|
+
this.inner.update(msg, enc);
|
|
1259
|
+
return this;
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
Hmac.prototype.digest = function digest(enc) {
|
|
1263
|
+
this.outer.update(this.inner.digest());
|
|
1264
|
+
return this.outer.digest(enc);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
(function (exports) {
|
|
1268
|
+
var hash = exports;
|
|
1269
|
+
|
|
1270
|
+
hash.utils = utils$9;
|
|
1271
|
+
hash.common = common$5;
|
|
1272
|
+
hash.sha = sha;
|
|
1273
|
+
hash.ripemd = ripemd;
|
|
1274
|
+
hash.hmac = hmac;
|
|
1275
|
+
|
|
1276
|
+
// Proxy hash functions to the main object
|
|
1277
|
+
hash.sha1 = hash.sha.sha1;
|
|
1278
|
+
hash.sha256 = hash.sha.sha256;
|
|
1279
|
+
hash.sha224 = hash.sha.sha224;
|
|
1280
|
+
hash.sha384 = hash.sha.sha384;
|
|
1281
|
+
hash.sha512 = hash.sha.sha512;
|
|
1282
|
+
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1283
|
+
}(hash$1));
|
|
1284
|
+
|
|
1285
|
+
var hash = hash$1;
|
|
1286
|
+
|
|
1287
|
+
const version$2 = "logger/5.5.0";
|
|
1288
|
+
|
|
1289
|
+
let _permanentCensorErrors = false;
|
|
1290
|
+
let _censorErrors = false;
|
|
1291
|
+
const LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
1292
|
+
let _logLevel = LogLevels["default"];
|
|
1293
|
+
let _globalLogger = null;
|
|
1294
|
+
function _checkNormalize() {
|
|
1295
|
+
try {
|
|
1296
|
+
const missing = [];
|
|
1297
|
+
// Make sure all forms of normalization are supported
|
|
1298
|
+
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
1299
|
+
try {
|
|
1300
|
+
if ("test".normalize(form) !== "test") {
|
|
1301
|
+
throw new Error("bad normalize");
|
|
1302
|
+
}
|
|
1303
|
+
;
|
|
1304
|
+
}
|
|
1305
|
+
catch (error) {
|
|
1306
|
+
missing.push(form);
|
|
1307
|
+
}
|
|
1308
|
+
});
|
|
1309
|
+
if (missing.length) {
|
|
1310
|
+
throw new Error("missing " + missing.join(", "));
|
|
1311
|
+
}
|
|
1312
|
+
if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) {
|
|
1313
|
+
throw new Error("broken implementation");
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
catch (error) {
|
|
1317
|
+
return error.message;
|
|
1318
|
+
}
|
|
1319
|
+
return null;
|
|
1320
|
+
}
|
|
1321
|
+
const _normalizeError = _checkNormalize();
|
|
1322
|
+
var LogLevel;
|
|
1323
|
+
(function (LogLevel) {
|
|
1324
|
+
LogLevel["DEBUG"] = "DEBUG";
|
|
1325
|
+
LogLevel["INFO"] = "INFO";
|
|
1326
|
+
LogLevel["WARNING"] = "WARNING";
|
|
1327
|
+
LogLevel["ERROR"] = "ERROR";
|
|
1328
|
+
LogLevel["OFF"] = "OFF";
|
|
1329
|
+
})(LogLevel || (LogLevel = {}));
|
|
1330
|
+
var ErrorCode;
|
|
1331
|
+
(function (ErrorCode) {
|
|
1332
|
+
///////////////////
|
|
1333
|
+
// Generic Errors
|
|
1334
|
+
// Unknown Error
|
|
1335
|
+
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1336
|
+
// Not Implemented
|
|
1337
|
+
ErrorCode["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
1338
|
+
// Unsupported Operation
|
|
1339
|
+
// - operation
|
|
1340
|
+
ErrorCode["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
1341
|
+
// Network Error (i.e. Ethereum Network, such as an invalid chain ID)
|
|
1342
|
+
// - event ("noNetwork" is not re-thrown in provider.ready; otherwise thrown)
|
|
1343
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1344
|
+
// Some sort of bad response from the server
|
|
1345
|
+
ErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
1346
|
+
// Timeout
|
|
1347
|
+
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
1348
|
+
///////////////////
|
|
1349
|
+
// Operational Errors
|
|
1350
|
+
// Buffer Overrun
|
|
1351
|
+
ErrorCode["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
1352
|
+
// Numeric Fault
|
|
1353
|
+
// - operation: the operation being executed
|
|
1354
|
+
// - fault: the reason this faulted
|
|
1355
|
+
ErrorCode["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
1356
|
+
///////////////////
|
|
1357
|
+
// Argument Errors
|
|
1358
|
+
// Missing new operator to an object
|
|
1359
|
+
// - name: The name of the class
|
|
1360
|
+
ErrorCode["MISSING_NEW"] = "MISSING_NEW";
|
|
1361
|
+
// Invalid argument (e.g. value is incompatible with type) to a function:
|
|
1362
|
+
// - argument: The argument name that was invalid
|
|
1363
|
+
// - value: The value of the argument
|
|
1364
|
+
ErrorCode["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
1365
|
+
// Missing argument to a function:
|
|
1366
|
+
// - count: The number of arguments received
|
|
1367
|
+
// - expectedCount: The number of arguments expected
|
|
1368
|
+
ErrorCode["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
1369
|
+
// Too many arguments
|
|
1370
|
+
// - count: The number of arguments received
|
|
1371
|
+
// - expectedCount: The number of arguments expected
|
|
1372
|
+
ErrorCode["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
1373
|
+
///////////////////
|
|
1374
|
+
// Blockchain Errors
|
|
1375
|
+
// Call exception
|
|
1376
|
+
// - transaction: the transaction
|
|
1377
|
+
// - address?: the contract address
|
|
1378
|
+
// - args?: The arguments passed into the function
|
|
1379
|
+
// - method?: The Solidity method signature
|
|
1380
|
+
// - errorSignature?: The EIP848 error signature
|
|
1381
|
+
// - errorArgs?: The EIP848 error parameters
|
|
1382
|
+
// - reason: The reason (only for EIP848 "Error(string)")
|
|
1383
|
+
ErrorCode["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
1384
|
+
// Insufficient funds (< value + gasLimit * gasPrice)
|
|
1385
|
+
// - transaction: the transaction attempted
|
|
1386
|
+
ErrorCode["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
1387
|
+
// Nonce has already been used
|
|
1388
|
+
// - transaction: the transaction attempted
|
|
1389
|
+
ErrorCode["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
1390
|
+
// The replacement fee for the transaction is too low
|
|
1391
|
+
// - transaction: the transaction attempted
|
|
1392
|
+
ErrorCode["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
1393
|
+
// The gas limit could not be estimated
|
|
1394
|
+
// - transaction: the transaction passed to estimateGas
|
|
1395
|
+
ErrorCode["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
1396
|
+
// The transaction was replaced by one with a higher gas price
|
|
1397
|
+
// - reason: "cancelled", "replaced" or "repriced"
|
|
1398
|
+
// - cancelled: true if reason == "cancelled" or reason == "replaced")
|
|
1399
|
+
// - hash: original transaction hash
|
|
1400
|
+
// - replacement: the full TransactionsResponse for the replacement
|
|
1401
|
+
// - receipt: the receipt of the replacement
|
|
1402
|
+
ErrorCode["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
1403
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
1404
|
+
const HEX = "0123456789abcdef";
|
|
1405
|
+
class Logger {
|
|
1406
|
+
constructor(version) {
|
|
1407
|
+
Object.defineProperty(this, "version", {
|
|
1408
|
+
enumerable: true,
|
|
1409
|
+
value: version,
|
|
1410
|
+
writable: false
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
_log(logLevel, args) {
|
|
1414
|
+
const level = logLevel.toLowerCase();
|
|
1415
|
+
if (LogLevels[level] == null) {
|
|
1416
|
+
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
1417
|
+
}
|
|
1418
|
+
if (_logLevel > LogLevels[level]) {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
console.log.apply(console, args);
|
|
1422
|
+
}
|
|
1423
|
+
debug(...args) {
|
|
1424
|
+
this._log(Logger.levels.DEBUG, args);
|
|
1425
|
+
}
|
|
1426
|
+
info(...args) {
|
|
1427
|
+
this._log(Logger.levels.INFO, args);
|
|
1428
|
+
}
|
|
1429
|
+
warn(...args) {
|
|
1430
|
+
this._log(Logger.levels.WARNING, args);
|
|
1431
|
+
}
|
|
1432
|
+
makeError(message, code, params) {
|
|
1433
|
+
// Errors are being censored
|
|
1434
|
+
if (_censorErrors) {
|
|
1435
|
+
return this.makeError("censored error", code, {});
|
|
1436
|
+
}
|
|
1437
|
+
if (!code) {
|
|
1438
|
+
code = Logger.errors.UNKNOWN_ERROR;
|
|
1439
|
+
}
|
|
1440
|
+
if (!params) {
|
|
1441
|
+
params = {};
|
|
1442
|
+
}
|
|
1443
|
+
const messageDetails = [];
|
|
1444
|
+
Object.keys(params).forEach((key) => {
|
|
1445
|
+
const value = params[key];
|
|
1446
|
+
try {
|
|
1447
|
+
if (value instanceof Uint8Array) {
|
|
1448
|
+
let hex = "";
|
|
1449
|
+
for (let i = 0; i < value.length; i++) {
|
|
1450
|
+
hex += HEX[value[i] >> 4];
|
|
1451
|
+
hex += HEX[value[i] & 0x0f];
|
|
1452
|
+
}
|
|
1453
|
+
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
1454
|
+
}
|
|
1455
|
+
else {
|
|
1456
|
+
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
catch (error) {
|
|
1460
|
+
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
messageDetails.push(`code=${code}`);
|
|
1464
|
+
messageDetails.push(`version=${this.version}`);
|
|
1465
|
+
const reason = message;
|
|
1466
|
+
if (messageDetails.length) {
|
|
1467
|
+
message += " (" + messageDetails.join(", ") + ")";
|
|
1468
|
+
}
|
|
1469
|
+
// @TODO: Any??
|
|
1470
|
+
const error = new Error(message);
|
|
1471
|
+
error.reason = reason;
|
|
1472
|
+
error.code = code;
|
|
1473
|
+
Object.keys(params).forEach(function (key) {
|
|
1474
|
+
error[key] = params[key];
|
|
1475
|
+
});
|
|
1476
|
+
return error;
|
|
1477
|
+
}
|
|
1478
|
+
throwError(message, code, params) {
|
|
1479
|
+
throw this.makeError(message, code, params);
|
|
1480
|
+
}
|
|
1481
|
+
throwArgumentError(message, name, value) {
|
|
1482
|
+
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
|
|
1483
|
+
argument: name,
|
|
1484
|
+
value: value
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
assert(condition, message, code, params) {
|
|
1488
|
+
if (!!condition) {
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
this.throwError(message, code, params);
|
|
1492
|
+
}
|
|
1493
|
+
assertArgument(condition, message, name, value) {
|
|
1494
|
+
if (!!condition) {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
this.throwArgumentError(message, name, value);
|
|
1498
|
+
}
|
|
1499
|
+
checkNormalize(message) {
|
|
1500
|
+
if (_normalizeError) {
|
|
1501
|
+
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1502
|
+
operation: "String.prototype.normalize", form: _normalizeError
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
checkSafeUint53(value, message) {
|
|
1507
|
+
if (typeof (value) !== "number") {
|
|
1508
|
+
return;
|
|
1509
|
+
}
|
|
1510
|
+
if (message == null) {
|
|
1511
|
+
message = "value not safe";
|
|
1512
|
+
}
|
|
1513
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
1514
|
+
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1515
|
+
operation: "checkSafeInteger",
|
|
1516
|
+
fault: "out-of-safe-range",
|
|
1517
|
+
value: value
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
if (value % 1) {
|
|
1521
|
+
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
|
|
1522
|
+
operation: "checkSafeInteger",
|
|
1523
|
+
fault: "non-integer",
|
|
1524
|
+
value: value
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
checkArgumentCount(count, expectedCount, message) {
|
|
1529
|
+
if (message) {
|
|
1530
|
+
message = ": " + message;
|
|
1531
|
+
}
|
|
1532
|
+
else {
|
|
1533
|
+
message = "";
|
|
1534
|
+
}
|
|
1535
|
+
if (count < expectedCount) {
|
|
1536
|
+
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
|
|
1537
|
+
count: count,
|
|
1538
|
+
expectedCount: expectedCount
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
if (count > expectedCount) {
|
|
1542
|
+
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
1543
|
+
count: count,
|
|
1544
|
+
expectedCount: expectedCount
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
checkNew(target, kind) {
|
|
1549
|
+
if (target === Object || target == null) {
|
|
1550
|
+
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
checkAbstract(target, kind) {
|
|
1554
|
+
if (target === kind) {
|
|
1555
|
+
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
1556
|
+
}
|
|
1557
|
+
else if (target === Object || target == null) {
|
|
1558
|
+
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
static globalLogger() {
|
|
1562
|
+
if (!_globalLogger) {
|
|
1563
|
+
_globalLogger = new Logger(version$2);
|
|
1564
|
+
}
|
|
1565
|
+
return _globalLogger;
|
|
1566
|
+
}
|
|
1567
|
+
static setCensorship(censorship, permanent) {
|
|
1568
|
+
if (!censorship && permanent) {
|
|
1569
|
+
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1570
|
+
operation: "setCensorship"
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
if (_permanentCensorErrors) {
|
|
1574
|
+
if (!censorship) {
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
1578
|
+
operation: "setCensorship"
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
_censorErrors = !!censorship;
|
|
1582
|
+
_permanentCensorErrors = !!permanent;
|
|
1583
|
+
}
|
|
1584
|
+
static setLogLevel(logLevel) {
|
|
1585
|
+
const level = LogLevels[logLevel.toLowerCase()];
|
|
1586
|
+
if (level == null) {
|
|
1587
|
+
Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
_logLevel = level;
|
|
1591
|
+
}
|
|
1592
|
+
static from(version) {
|
|
1593
|
+
return new Logger(version);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
Logger.errors = ErrorCode;
|
|
1597
|
+
Logger.levels = LogLevel;
|
|
1686
1598
|
|
|
1687
|
-
|
|
1688
|
-
hash.sha1 = hash.sha.sha1;
|
|
1689
|
-
hash.sha256 = hash.sha.sha256;
|
|
1690
|
-
hash.sha224 = hash.sha.sha224;
|
|
1691
|
-
hash.sha384 = hash.sha.sha384;
|
|
1692
|
-
hash.sha512 = hash.sha.sha512;
|
|
1693
|
-
hash.ripemd160 = hash.ripemd.ripemd160;
|
|
1694
|
-
}(hash$1));
|
|
1599
|
+
const version$1 = "bytes/5.5.0";
|
|
1695
1600
|
|
|
1696
|
-
|
|
1601
|
+
const logger = new Logger(version$1);
|
|
1602
|
+
///////////////////////////////
|
|
1603
|
+
function isHexable(value) {
|
|
1604
|
+
return !!(value.toHexString);
|
|
1605
|
+
}
|
|
1606
|
+
function addSlice(array) {
|
|
1607
|
+
if (array.slice) {
|
|
1608
|
+
return array;
|
|
1609
|
+
}
|
|
1610
|
+
array.slice = function () {
|
|
1611
|
+
const args = Array.prototype.slice.call(arguments);
|
|
1612
|
+
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
1613
|
+
};
|
|
1614
|
+
return array;
|
|
1615
|
+
}
|
|
1616
|
+
function isInteger(value) {
|
|
1617
|
+
return (typeof (value) === "number" && value == value && (value % 1) === 0);
|
|
1618
|
+
}
|
|
1619
|
+
function isBytes(value) {
|
|
1620
|
+
if (value == null) {
|
|
1621
|
+
return false;
|
|
1622
|
+
}
|
|
1623
|
+
if (value.constructor === Uint8Array) {
|
|
1624
|
+
return true;
|
|
1625
|
+
}
|
|
1626
|
+
if (typeof (value) === "string") {
|
|
1627
|
+
return false;
|
|
1628
|
+
}
|
|
1629
|
+
if (!isInteger(value.length) || value.length < 0) {
|
|
1630
|
+
return false;
|
|
1631
|
+
}
|
|
1632
|
+
for (let i = 0; i < value.length; i++) {
|
|
1633
|
+
const v = value[i];
|
|
1634
|
+
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
1635
|
+
return false;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
return true;
|
|
1639
|
+
}
|
|
1640
|
+
function arrayify(value, options) {
|
|
1641
|
+
if (!options) {
|
|
1642
|
+
options = {};
|
|
1643
|
+
}
|
|
1644
|
+
if (typeof (value) === "number") {
|
|
1645
|
+
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
1646
|
+
const result = [];
|
|
1647
|
+
while (value) {
|
|
1648
|
+
result.unshift(value & 0xff);
|
|
1649
|
+
value = parseInt(String(value / 256));
|
|
1650
|
+
}
|
|
1651
|
+
if (result.length === 0) {
|
|
1652
|
+
result.push(0);
|
|
1653
|
+
}
|
|
1654
|
+
return addSlice(new Uint8Array(result));
|
|
1655
|
+
}
|
|
1656
|
+
if (options.allowMissingPrefix && typeof (value) === "string" && value.substring(0, 2) !== "0x") {
|
|
1657
|
+
value = "0x" + value;
|
|
1658
|
+
}
|
|
1659
|
+
if (isHexable(value)) {
|
|
1660
|
+
value = value.toHexString();
|
|
1661
|
+
}
|
|
1662
|
+
if (isHexString(value)) {
|
|
1663
|
+
let hex = value.substring(2);
|
|
1664
|
+
if (hex.length % 2) {
|
|
1665
|
+
if (options.hexPad === "left") {
|
|
1666
|
+
hex = "0x0" + hex.substring(2);
|
|
1667
|
+
}
|
|
1668
|
+
else if (options.hexPad === "right") {
|
|
1669
|
+
hex += "0";
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
const result = [];
|
|
1676
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
1677
|
+
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
1678
|
+
}
|
|
1679
|
+
return addSlice(new Uint8Array(result));
|
|
1680
|
+
}
|
|
1681
|
+
if (isBytes(value)) {
|
|
1682
|
+
return addSlice(new Uint8Array(value));
|
|
1683
|
+
}
|
|
1684
|
+
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
1685
|
+
}
|
|
1686
|
+
function isHexString(value, length) {
|
|
1687
|
+
if (typeof (value) !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
1688
|
+
return false;
|
|
1689
|
+
}
|
|
1690
|
+
if (length && value.length !== 2 + 2 * length) {
|
|
1691
|
+
return false;
|
|
1692
|
+
}
|
|
1693
|
+
return true;
|
|
1694
|
+
}
|
|
1697
1695
|
|
|
1698
1696
|
const version = "sha2/5.5.0";
|
|
1699
1697
|
|
|
@@ -1725,8 +1723,7 @@ class Struct {
|
|
|
1725
1723
|
class Enum extends Struct {
|
|
1726
1724
|
constructor(properties) {
|
|
1727
1725
|
super(properties);
|
|
1728
|
-
|
|
1729
|
-
_defineProperty(this, "enum", '');
|
|
1726
|
+
this.enum = '';
|
|
1730
1727
|
|
|
1731
1728
|
if (Object.keys(properties).length !== 1) {
|
|
1732
1729
|
throw new Error('Enum can only take single value');
|
|
@@ -1766,8 +1763,7 @@ class PublicKey extends Struct {
|
|
|
1766
1763
|
*/
|
|
1767
1764
|
constructor(value) {
|
|
1768
1765
|
super({});
|
|
1769
|
-
|
|
1770
|
-
_defineProperty(this, "_bn", void 0);
|
|
1766
|
+
this._bn = void 0;
|
|
1771
1767
|
|
|
1772
1768
|
if (isPublicKeyData(value)) {
|
|
1773
1769
|
this._bn = value._bn;
|
|
@@ -1777,7 +1773,7 @@ class PublicKey extends Struct {
|
|
|
1777
1773
|
const decoded = bs58.decode(value);
|
|
1778
1774
|
|
|
1779
1775
|
if (decoded.length != 32) {
|
|
1780
|
-
throw new Error(
|
|
1776
|
+
throw new Error(`Invalid public key input`);
|
|
1781
1777
|
}
|
|
1782
1778
|
|
|
1783
1779
|
this._bn = new BN(decoded);
|
|
@@ -1786,7 +1782,7 @@ class PublicKey extends Struct {
|
|
|
1786
1782
|
}
|
|
1787
1783
|
|
|
1788
1784
|
if (this._bn.byteLength() > 32) {
|
|
1789
|
-
throw new Error(
|
|
1785
|
+
throw new Error(`Invalid public key input`);
|
|
1790
1786
|
}
|
|
1791
1787
|
}
|
|
1792
1788
|
}
|
|
@@ -1866,7 +1862,7 @@ class PublicKey extends Struct {
|
|
|
1866
1862
|
let buffer = Buffer.alloc(0);
|
|
1867
1863
|
seeds.forEach(function (seed) {
|
|
1868
1864
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1869
|
-
throw new TypeError(
|
|
1865
|
+
throw new TypeError(`Max seed length exceeded`);
|
|
1870
1866
|
}
|
|
1871
1867
|
|
|
1872
1868
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
@@ -1876,7 +1872,7 @@ class PublicKey extends Struct {
|
|
|
1876
1872
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1877
1873
|
|
|
1878
1874
|
if (is_on_curve(publicKeyBytes)) {
|
|
1879
|
-
throw new Error(
|
|
1875
|
+
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1880
1876
|
}
|
|
1881
1877
|
|
|
1882
1878
|
return new PublicKey(publicKeyBytes);
|
|
@@ -1910,7 +1906,7 @@ class PublicKey extends Struct {
|
|
|
1910
1906
|
return [address, nonce];
|
|
1911
1907
|
}
|
|
1912
1908
|
|
|
1913
|
-
throw new Error(
|
|
1909
|
+
throw new Error(`Unable to find a viable program address nonce`);
|
|
1914
1910
|
}
|
|
1915
1911
|
/**
|
|
1916
1912
|
* Check that a pubkey is on the ed25519 curve.
|
|
@@ -1922,15 +1918,13 @@ class PublicKey extends Struct {
|
|
|
1922
1918
|
}
|
|
1923
1919
|
|
|
1924
1920
|
}
|
|
1925
|
-
|
|
1926
|
-
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
1927
|
-
|
|
1921
|
+
PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
1928
1922
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
1929
1923
|
kind: 'struct',
|
|
1930
1924
|
fields: [['_bn', 'u256']]
|
|
1931
1925
|
}); // @ts-ignore
|
|
1932
1926
|
|
|
1933
|
-
let naclLowLevel =
|
|
1927
|
+
let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
|
|
1934
1928
|
// This function and its dependents were sourced from:
|
|
1935
1929
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
1936
1930
|
|
|
@@ -1997,7 +1991,7 @@ class Account {
|
|
|
1997
1991
|
* @param secretKey Secret key for the account
|
|
1998
1992
|
*/
|
|
1999
1993
|
constructor(secretKey) {
|
|
2000
|
-
|
|
1994
|
+
this._keypair = void 0;
|
|
2001
1995
|
|
|
2002
1996
|
if (secretKey) {
|
|
2003
1997
|
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
@@ -2133,16 +2127,11 @@ const PUBKEY_LENGTH = 32;
|
|
|
2133
2127
|
|
|
2134
2128
|
class Message {
|
|
2135
2129
|
constructor(args) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
_defineProperty(this, "instructions", void 0);
|
|
2143
|
-
|
|
2144
|
-
_defineProperty(this, "indexToProgramIds", new Map());
|
|
2145
|
-
|
|
2130
|
+
this.header = void 0;
|
|
2131
|
+
this.accountKeys = void 0;
|
|
2132
|
+
this.recentBlockhash = void 0;
|
|
2133
|
+
this.instructions = void 0;
|
|
2134
|
+
this.indexToProgramIds = new Map();
|
|
2146
2135
|
this.header = args.header;
|
|
2147
2136
|
this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
|
|
2148
2137
|
this.recentBlockhash = args.recentBlockhash;
|
|
@@ -2316,12 +2305,9 @@ class TransactionInstruction {
|
|
|
2316
2305
|
* Program input
|
|
2317
2306
|
*/
|
|
2318
2307
|
constructor(opts) {
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
_defineProperty(this, "data", Buffer.alloc(0));
|
|
2324
|
-
|
|
2308
|
+
this.keys = void 0;
|
|
2309
|
+
this.programId = void 0;
|
|
2310
|
+
this.data = Buffer.alloc(0);
|
|
2325
2311
|
this.programId = opts.programId;
|
|
2326
2312
|
this.keys = opts.keys;
|
|
2327
2313
|
|
|
@@ -2363,16 +2349,11 @@ class Transaction {
|
|
|
2363
2349
|
* Construct an empty Transaction
|
|
2364
2350
|
*/
|
|
2365
2351
|
constructor(opts) {
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
_defineProperty(this, "recentBlockhash", void 0);
|
|
2373
|
-
|
|
2374
|
-
_defineProperty(this, "nonceInfo", void 0);
|
|
2375
|
-
|
|
2352
|
+
this.signatures = [];
|
|
2353
|
+
this.feePayer = void 0;
|
|
2354
|
+
this.instructions = [];
|
|
2355
|
+
this.recentBlockhash = void 0;
|
|
2356
|
+
this.nonceInfo = void 0;
|
|
2376
2357
|
opts && Object.assign(this, opts);
|
|
2377
2358
|
}
|
|
2378
2359
|
/**
|
|
@@ -2436,7 +2417,7 @@ class Transaction {
|
|
|
2436
2417
|
|
|
2437
2418
|
for (let i = 0; i < this.instructions.length; i++) {
|
|
2438
2419
|
if (this.instructions[i].programId === undefined) {
|
|
2439
|
-
throw new Error(
|
|
2420
|
+
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2440
2421
|
}
|
|
2441
2422
|
}
|
|
2442
2423
|
|
|
@@ -2511,7 +2492,7 @@ class Transaction {
|
|
|
2511
2492
|
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.');
|
|
2512
2493
|
}
|
|
2513
2494
|
} else {
|
|
2514
|
-
throw new Error(
|
|
2495
|
+
throw new Error(`unknown signer: ${signature.publicKey.toString()}`);
|
|
2515
2496
|
}
|
|
2516
2497
|
}
|
|
2517
2498
|
|
|
@@ -2718,7 +2699,7 @@ class Transaction {
|
|
|
2718
2699
|
_partialSign(message, ...signers) {
|
|
2719
2700
|
const signData = message.serialize();
|
|
2720
2701
|
signers.forEach(signer => {
|
|
2721
|
-
const signature =
|
|
2702
|
+
const signature = nacl.sign.detached(signData, signer.secretKey);
|
|
2722
2703
|
|
|
2723
2704
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2724
2705
|
});
|
|
@@ -2746,7 +2727,7 @@ class Transaction {
|
|
|
2746
2727
|
const index = this.signatures.findIndex(sigpair => pubkey.equals(sigpair.publicKey));
|
|
2747
2728
|
|
|
2748
2729
|
if (index < 0) {
|
|
2749
|
-
throw new Error(
|
|
2730
|
+
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2750
2731
|
}
|
|
2751
2732
|
|
|
2752
2733
|
this.signatures[index].signature = Buffer.from(signature);
|
|
@@ -2774,7 +2755,7 @@ class Transaction {
|
|
|
2774
2755
|
return false;
|
|
2775
2756
|
}
|
|
2776
2757
|
} else {
|
|
2777
|
-
if (!
|
|
2758
|
+
if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
2778
2759
|
return false;
|
|
2779
2760
|
}
|
|
2780
2761
|
}
|
|
@@ -2822,12 +2803,12 @@ class Transaction {
|
|
|
2822
2803
|
signature
|
|
2823
2804
|
}, index) => {
|
|
2824
2805
|
if (signature !== null) {
|
|
2825
|
-
assert(signature.length === 64,
|
|
2806
|
+
assert(signature.length === 64, `signature has invalid length`);
|
|
2826
2807
|
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2827
2808
|
}
|
|
2828
2809
|
});
|
|
2829
2810
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
2830
|
-
assert(wireTransaction.length <= PACKET_DATA_SIZE,
|
|
2811
|
+
assert(wireTransaction.length <= PACKET_DATA_SIZE, `Transaction too large: ${wireTransaction.length} > ${PACKET_DATA_SIZE}`);
|
|
2831
2812
|
return wireTransaction;
|
|
2832
2813
|
}
|
|
2833
2814
|
/**
|
|
@@ -2946,7 +2927,7 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2946
2927
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2947
2928
|
|
|
2948
2929
|
if (status.err) {
|
|
2949
|
-
throw new Error(
|
|
2930
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2950
2931
|
}
|
|
2951
2932
|
|
|
2952
2933
|
return signature;
|
|
@@ -2989,7 +2970,7 @@ function decodeData(type, buffer) {
|
|
|
2989
2970
|
}
|
|
2990
2971
|
|
|
2991
2972
|
if (data.instruction !== type.index) {
|
|
2992
|
-
throw new Error(
|
|
2973
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2993
2974
|
}
|
|
2994
2975
|
|
|
2995
2976
|
return data;
|
|
@@ -3023,12 +3004,9 @@ class NonceAccount {
|
|
|
3023
3004
|
* @internal
|
|
3024
3005
|
*/
|
|
3025
3006
|
constructor(args) {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
_defineProperty(this, "feeCalculator", void 0);
|
|
3031
|
-
|
|
3007
|
+
this.authorizedPubkey = void 0;
|
|
3008
|
+
this.nonce = void 0;
|
|
3009
|
+
this.feeCalculator = void 0;
|
|
3032
3010
|
this.authorizedPubkey = args.authorizedPubkey;
|
|
3033
3011
|
this.nonce = args.nonce;
|
|
3034
3012
|
this.feeCalculator = args.feeCalculator;
|
|
@@ -3329,7 +3307,7 @@ class SystemInstruction {
|
|
|
3329
3307
|
|
|
3330
3308
|
static checkKeyLength(keys, expectedLength) {
|
|
3331
3309
|
if (keys.length < expectedLength) {
|
|
3332
|
-
throw new Error(
|
|
3310
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
3333
3311
|
}
|
|
3334
3312
|
}
|
|
3335
3313
|
|
|
@@ -3761,8 +3739,7 @@ class SystemProgram {
|
|
|
3761
3739
|
}
|
|
3762
3740
|
|
|
3763
3741
|
}
|
|
3764
|
-
|
|
3765
|
-
_defineProperty(SystemProgram, "programId", new PublicKey('11111111111111111111111111111111'));
|
|
3742
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3766
3743
|
|
|
3767
3744
|
// rest of the Transaction fields
|
|
3768
3745
|
//
|
|
@@ -3931,8 +3908,7 @@ class Loader {
|
|
|
3931
3908
|
}
|
|
3932
3909
|
|
|
3933
3910
|
}
|
|
3934
|
-
|
|
3935
|
-
_defineProperty(Loader, "chunkSize", CHUNK_SIZE);
|
|
3911
|
+
Loader.chunkSize = CHUNK_SIZE;
|
|
3936
3912
|
|
|
3937
3913
|
const BPF_LOADER_PROGRAM_ID = new PublicKey('BPFLoader2111111111111111111111111111111111');
|
|
3938
3914
|
/**
|
|
@@ -3983,14 +3959,10 @@ class AgentManager {
|
|
|
3983
3959
|
}
|
|
3984
3960
|
|
|
3985
3961
|
constructor(useHttps) {
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
_defineProperty(this, "_destroyTimeout", null);
|
|
3991
|
-
|
|
3992
|
-
_defineProperty(this, "_useHttps", void 0);
|
|
3993
|
-
|
|
3962
|
+
this._agent = void 0;
|
|
3963
|
+
this._activeRequests = 0;
|
|
3964
|
+
this._destroyTimeout = null;
|
|
3965
|
+
this._useHttps = void 0;
|
|
3994
3966
|
this._useHttps = useHttps === true;
|
|
3995
3967
|
this._agent = AgentManager._newAgent(this._useHttps);
|
|
3996
3968
|
}
|
|
@@ -4063,16 +4035,11 @@ class EpochSchedule {
|
|
|
4063
4035
|
|
|
4064
4036
|
/** The first slot of `firstNormalEpoch` */
|
|
4065
4037
|
constructor(slotsPerEpoch, leaderScheduleSlotOffset, warmup, firstNormalEpoch, firstNormalSlot) {
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
_defineProperty(this, "firstNormalEpoch", void 0);
|
|
4073
|
-
|
|
4074
|
-
_defineProperty(this, "firstNormalSlot", void 0);
|
|
4075
|
-
|
|
4038
|
+
this.slotsPerEpoch = void 0;
|
|
4039
|
+
this.leaderScheduleSlotOffset = void 0;
|
|
4040
|
+
this.warmup = void 0;
|
|
4041
|
+
this.firstNormalEpoch = void 0;
|
|
4042
|
+
this.firstNormalSlot = void 0;
|
|
4076
4043
|
this.slotsPerEpoch = slotsPerEpoch;
|
|
4077
4044
|
this.leaderScheduleSlotOffset = leaderScheduleSlotOffset;
|
|
4078
4045
|
this.warmup = warmup;
|
|
@@ -4124,9 +4091,7 @@ class EpochSchedule {
|
|
|
4124
4091
|
class SendTransactionError extends Error {
|
|
4125
4092
|
constructor(message, logs) {
|
|
4126
4093
|
super(message);
|
|
4127
|
-
|
|
4128
|
-
_defineProperty(this, "logs", void 0);
|
|
4129
|
-
|
|
4094
|
+
this.logs = void 0;
|
|
4130
4095
|
this.logs = logs;
|
|
4131
4096
|
}
|
|
4132
4097
|
|
|
@@ -4410,7 +4375,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4410
4375
|
break;
|
|
4411
4376
|
}
|
|
4412
4377
|
|
|
4413
|
-
console.log(
|
|
4378
|
+
console.log(`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`);
|
|
4414
4379
|
await sleep(waitTime);
|
|
4415
4380
|
waitTime *= 2;
|
|
4416
4381
|
}
|
|
@@ -4420,7 +4385,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4420
4385
|
if (res.ok) {
|
|
4421
4386
|
callback(null, text);
|
|
4422
4387
|
} else {
|
|
4423
|
-
callback(new Error(
|
|
4388
|
+
callback(new Error(`${res.status} ${res.statusText}: ${text}`));
|
|
4424
4389
|
}
|
|
4425
4390
|
} catch (err) {
|
|
4426
4391
|
if (err instanceof Error) callback(err);
|
|
@@ -5086,67 +5051,39 @@ class Connection {
|
|
|
5086
5051
|
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
5087
5052
|
*/
|
|
5088
5053
|
constructor(endpoint, commitmentOrConfig) {
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
_defineProperty(this, "_rpcWebSocket", void 0);
|
|
5104
|
-
|
|
5105
|
-
_defineProperty(this, "_rpcWebSocketConnected", false);
|
|
5106
|
-
|
|
5107
|
-
_defineProperty(this, "_rpcWebSocketHeartbeat", null);
|
|
5108
|
-
|
|
5109
|
-
_defineProperty(this, "_rpcWebSocketIdleTimeout", null);
|
|
5110
|
-
|
|
5111
|
-
_defineProperty(this, "_disableBlockhashCaching", false);
|
|
5112
|
-
|
|
5113
|
-
_defineProperty(this, "_pollingBlockhash", false);
|
|
5114
|
-
|
|
5115
|
-
_defineProperty(this, "_blockhashInfo", {
|
|
5054
|
+
this._commitment = void 0;
|
|
5055
|
+
this._confirmTransactionInitialTimeout = void 0;
|
|
5056
|
+
this._rpcEndpoint = void 0;
|
|
5057
|
+
this._rpcWsEndpoint = void 0;
|
|
5058
|
+
this._rpcClient = void 0;
|
|
5059
|
+
this._rpcRequest = void 0;
|
|
5060
|
+
this._rpcBatchRequest = void 0;
|
|
5061
|
+
this._rpcWebSocket = void 0;
|
|
5062
|
+
this._rpcWebSocketConnected = false;
|
|
5063
|
+
this._rpcWebSocketHeartbeat = null;
|
|
5064
|
+
this._rpcWebSocketIdleTimeout = null;
|
|
5065
|
+
this._disableBlockhashCaching = false;
|
|
5066
|
+
this._pollingBlockhash = false;
|
|
5067
|
+
this._blockhashInfo = {
|
|
5116
5068
|
recentBlockhash: null,
|
|
5117
5069
|
lastFetch: 0,
|
|
5118
5070
|
transactionSignatures: [],
|
|
5119
5071
|
simulatedSignatures: []
|
|
5120
|
-
}
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
_defineProperty(this, "_signatureSubscriptions", {});
|
|
5137
|
-
|
|
5138
|
-
_defineProperty(this, "_slotSubscriptionCounter", 0);
|
|
5139
|
-
|
|
5140
|
-
_defineProperty(this, "_slotSubscriptions", {});
|
|
5141
|
-
|
|
5142
|
-
_defineProperty(this, "_logsSubscriptionCounter", 0);
|
|
5143
|
-
|
|
5144
|
-
_defineProperty(this, "_logsSubscriptions", {});
|
|
5145
|
-
|
|
5146
|
-
_defineProperty(this, "_slotUpdateSubscriptionCounter", 0);
|
|
5147
|
-
|
|
5148
|
-
_defineProperty(this, "_slotUpdateSubscriptions", {});
|
|
5149
|
-
|
|
5072
|
+
};
|
|
5073
|
+
this._accountChangeSubscriptionCounter = 0;
|
|
5074
|
+
this._accountChangeSubscriptions = {};
|
|
5075
|
+
this._programAccountChangeSubscriptionCounter = 0;
|
|
5076
|
+
this._programAccountChangeSubscriptions = {};
|
|
5077
|
+
this._rootSubscriptionCounter = 0;
|
|
5078
|
+
this._rootSubscriptions = {};
|
|
5079
|
+
this._signatureSubscriptionCounter = 0;
|
|
5080
|
+
this._signatureSubscriptions = {};
|
|
5081
|
+
this._slotSubscriptionCounter = 0;
|
|
5082
|
+
this._slotSubscriptions = {};
|
|
5083
|
+
this._logsSubscriptionCounter = 0;
|
|
5084
|
+
this._logsSubscriptions = {};
|
|
5085
|
+
this._slotUpdateSubscriptionCounter = 0;
|
|
5086
|
+
this._slotUpdateSubscriptions = {};
|
|
5150
5087
|
let url = new URL(endpoint);
|
|
5151
5088
|
const useHttps = url.protocol === 'https:';
|
|
5152
5089
|
let wsEndpoint;
|
|
@@ -5281,10 +5218,24 @@ class Connection {
|
|
|
5281
5218
|
*/
|
|
5282
5219
|
|
|
5283
5220
|
|
|
5284
|
-
async getSupply(
|
|
5285
|
-
|
|
5221
|
+
async getSupply(config) {
|
|
5222
|
+
let configArg = {};
|
|
5223
|
+
|
|
5224
|
+
if (typeof config === 'string') {
|
|
5225
|
+
configArg = {
|
|
5226
|
+
commitment: config
|
|
5227
|
+
};
|
|
5228
|
+
} else if (config) {
|
|
5229
|
+
configArg = { ...config,
|
|
5230
|
+
commitment: config && config.commitment || this.commitment
|
|
5231
|
+
};
|
|
5232
|
+
} else {
|
|
5233
|
+
configArg = {
|
|
5234
|
+
commitment: this.commitment
|
|
5235
|
+
};
|
|
5236
|
+
}
|
|
5286
5237
|
|
|
5287
|
-
const unsafeRes = await this._rpcRequest('getSupply',
|
|
5238
|
+
const unsafeRes = await this._rpcRequest('getSupply', [configArg]);
|
|
5288
5239
|
const res = create(unsafeRes, GetSupplyRpcResult);
|
|
5289
5240
|
|
|
5290
5241
|
if ('error' in res) {
|
|
@@ -5506,7 +5457,7 @@ class Connection {
|
|
|
5506
5457
|
const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
|
|
5507
5458
|
|
|
5508
5459
|
if ('error' in res) {
|
|
5509
|
-
throw new Error(
|
|
5460
|
+
throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
|
|
5510
5461
|
}
|
|
5511
5462
|
|
|
5512
5463
|
return res.result;
|
|
@@ -5642,7 +5593,7 @@ class Connection {
|
|
|
5642
5593
|
|
|
5643
5594
|
if (response === null) {
|
|
5644
5595
|
const duration = (Date.now() - start) / 1000;
|
|
5645
|
-
throw new Error(
|
|
5596
|
+
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.`);
|
|
5646
5597
|
}
|
|
5647
5598
|
|
|
5648
5599
|
return response;
|
|
@@ -5795,16 +5746,11 @@ class Connection {
|
|
|
5795
5746
|
|
|
5796
5747
|
|
|
5797
5748
|
async getTotalSupply(commitment) {
|
|
5798
|
-
const
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
if ('error' in res) {
|
|
5804
|
-
throw new Error('failed to get total supply: ' + res.error.message);
|
|
5805
|
-
}
|
|
5806
|
-
|
|
5807
|
-
return res.result.value.total;
|
|
5749
|
+
const result = await this.getSupply({
|
|
5750
|
+
commitment,
|
|
5751
|
+
excludeNonCirculatingAccountsList: true
|
|
5752
|
+
});
|
|
5753
|
+
return result.value.total;
|
|
5808
5754
|
}
|
|
5809
5755
|
/**
|
|
5810
5756
|
* Fetch the cluster InflationGovernor parameters
|
|
@@ -6421,7 +6367,7 @@ class Connection {
|
|
|
6421
6367
|
await sleep(MS_PER_SLOT / 2);
|
|
6422
6368
|
}
|
|
6423
6369
|
|
|
6424
|
-
throw new Error(
|
|
6370
|
+
throw new Error(`Unable to obtain a new blockhash after ${Date.now() - startTime}ms`);
|
|
6425
6371
|
} finally {
|
|
6426
6372
|
this._pollingBlockhash = false;
|
|
6427
6373
|
}
|
|
@@ -6678,7 +6624,7 @@ class Connection {
|
|
|
6678
6624
|
}
|
|
6679
6625
|
|
|
6680
6626
|
if (err instanceof Error) {
|
|
6681
|
-
console.error(
|
|
6627
|
+
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
6682
6628
|
}
|
|
6683
6629
|
}
|
|
6684
6630
|
}
|
|
@@ -6698,7 +6644,7 @@ class Connection {
|
|
|
6698
6644
|
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
6699
6645
|
} catch (err) {
|
|
6700
6646
|
if (err instanceof Error) {
|
|
6701
|
-
console.error(
|
|
6647
|
+
console.error(`${rpcMethod} error:`, err.message);
|
|
6702
6648
|
}
|
|
6703
6649
|
}
|
|
6704
6650
|
}
|
|
@@ -6863,7 +6809,7 @@ class Connection {
|
|
|
6863
6809
|
|
|
6864
6810
|
this._updateSubscriptions();
|
|
6865
6811
|
} else {
|
|
6866
|
-
throw new Error(
|
|
6812
|
+
throw new Error(`Unknown account change id: ${id}`);
|
|
6867
6813
|
}
|
|
6868
6814
|
}
|
|
6869
6815
|
/**
|
|
@@ -6929,7 +6875,7 @@ class Connection {
|
|
|
6929
6875
|
|
|
6930
6876
|
this._updateSubscriptions();
|
|
6931
6877
|
} else {
|
|
6932
|
-
throw new Error(
|
|
6878
|
+
throw new Error(`Unknown program account change id: ${id}`);
|
|
6933
6879
|
}
|
|
6934
6880
|
}
|
|
6935
6881
|
/**
|
|
@@ -6959,7 +6905,7 @@ class Connection {
|
|
|
6959
6905
|
|
|
6960
6906
|
async removeOnLogsListener(id) {
|
|
6961
6907
|
if (!this._logsSubscriptions[id]) {
|
|
6962
|
-
throw new Error(
|
|
6908
|
+
throw new Error(`Unknown logs id: ${id}`);
|
|
6963
6909
|
}
|
|
6964
6910
|
|
|
6965
6911
|
const subInfo = this._logsSubscriptions[id];
|
|
@@ -7035,7 +6981,7 @@ class Connection {
|
|
|
7035
6981
|
|
|
7036
6982
|
this._updateSubscriptions();
|
|
7037
6983
|
} else {
|
|
7038
|
-
throw new Error(
|
|
6984
|
+
throw new Error(`Unknown slot change id: ${id}`);
|
|
7039
6985
|
}
|
|
7040
6986
|
}
|
|
7041
6987
|
/**
|
|
@@ -7088,7 +7034,7 @@ class Connection {
|
|
|
7088
7034
|
|
|
7089
7035
|
this._updateSubscriptions();
|
|
7090
7036
|
} else {
|
|
7091
|
-
throw new Error(
|
|
7037
|
+
throw new Error(`Unknown slot update id: ${id}`);
|
|
7092
7038
|
}
|
|
7093
7039
|
}
|
|
7094
7040
|
|
|
@@ -7229,7 +7175,7 @@ class Connection {
|
|
|
7229
7175
|
|
|
7230
7176
|
this._updateSubscriptions();
|
|
7231
7177
|
} else {
|
|
7232
|
-
throw new Error(
|
|
7178
|
+
throw new Error(`Unknown signature result id: ${id}`);
|
|
7233
7179
|
}
|
|
7234
7180
|
}
|
|
7235
7181
|
/**
|
|
@@ -7281,7 +7227,7 @@ class Connection {
|
|
|
7281
7227
|
|
|
7282
7228
|
this._updateSubscriptions();
|
|
7283
7229
|
} else {
|
|
7284
|
-
throw new Error(
|
|
7230
|
+
throw new Error(`Unknown root change id: ${id}`);
|
|
7285
7231
|
}
|
|
7286
7232
|
}
|
|
7287
7233
|
|
|
@@ -7302,7 +7248,7 @@ class Keypair {
|
|
|
7302
7248
|
* @param keypair ed25519 keypair
|
|
7303
7249
|
*/
|
|
7304
7250
|
constructor(keypair) {
|
|
7305
|
-
|
|
7251
|
+
this._keypair = void 0;
|
|
7306
7252
|
|
|
7307
7253
|
if (keypair) {
|
|
7308
7254
|
this._keypair = keypair;
|
|
@@ -7406,8 +7352,8 @@ class Ed25519Program {
|
|
|
7406
7352
|
signature,
|
|
7407
7353
|
instructionIndex
|
|
7408
7354
|
} = params;
|
|
7409
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES$1,
|
|
7410
|
-
assert(signature.length === SIGNATURE_BYTES,
|
|
7355
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
|
|
7356
|
+
assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
7411
7357
|
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
7412
7358
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
7413
7359
|
const messageDataOffset = signatureOffset + signature.length;
|
|
@@ -7445,12 +7391,12 @@ class Ed25519Program {
|
|
|
7445
7391
|
message,
|
|
7446
7392
|
instructionIndex
|
|
7447
7393
|
} = params;
|
|
7448
|
-
assert(privateKey.length === PRIVATE_KEY_BYTES$1,
|
|
7394
|
+
assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
7449
7395
|
|
|
7450
7396
|
try {
|
|
7451
7397
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
7452
7398
|
const publicKey = keypair.publicKey.toBytes();
|
|
7453
|
-
const signature =
|
|
7399
|
+
const signature = nacl.sign.detached(message, keypair.secretKey);
|
|
7454
7400
|
return this.createInstructionWithPublicKey({
|
|
7455
7401
|
publicKey,
|
|
7456
7402
|
message,
|
|
@@ -7458,13 +7404,12 @@ class Ed25519Program {
|
|
|
7458
7404
|
instructionIndex
|
|
7459
7405
|
});
|
|
7460
7406
|
} catch (error) {
|
|
7461
|
-
throw new Error(
|
|
7407
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
7462
7408
|
}
|
|
7463
7409
|
}
|
|
7464
7410
|
|
|
7465
7411
|
}
|
|
7466
|
-
|
|
7467
|
-
_defineProperty(Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
|
|
7412
|
+
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7468
7413
|
|
|
7469
7414
|
/**
|
|
7470
7415
|
* Address of the stake config account which configures the rate
|
|
@@ -7487,10 +7432,8 @@ class Authorized {
|
|
|
7487
7432
|
* @param withdrawer the withdraw authority
|
|
7488
7433
|
*/
|
|
7489
7434
|
constructor(staker, withdrawer) {
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
_defineProperty(this, "withdrawer", void 0);
|
|
7493
|
-
|
|
7435
|
+
this.staker = void 0;
|
|
7436
|
+
this.withdrawer = void 0;
|
|
7494
7437
|
this.staker = staker;
|
|
7495
7438
|
this.withdrawer = withdrawer;
|
|
7496
7439
|
}
|
|
@@ -7511,12 +7454,9 @@ class Lockup {
|
|
|
7511
7454
|
* Create a new Lockup object
|
|
7512
7455
|
*/
|
|
7513
7456
|
constructor(unixTimestamp, epoch, custodian) {
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
_defineProperty(this, "custodian", void 0);
|
|
7519
|
-
|
|
7457
|
+
this.unixTimestamp = void 0;
|
|
7458
|
+
this.epoch = void 0;
|
|
7459
|
+
this.custodian = void 0;
|
|
7520
7460
|
this.unixTimestamp = unixTimestamp;
|
|
7521
7461
|
this.epoch = epoch;
|
|
7522
7462
|
this.custodian = custodian;
|
|
@@ -7531,7 +7471,7 @@ class Lockup {
|
|
|
7531
7471
|
* Create stake account transaction params
|
|
7532
7472
|
*/
|
|
7533
7473
|
|
|
7534
|
-
|
|
7474
|
+
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
7535
7475
|
|
|
7536
7476
|
/**
|
|
7537
7477
|
* Stake Instruction class
|
|
@@ -7744,7 +7684,7 @@ class StakeInstruction {
|
|
|
7744
7684
|
|
|
7745
7685
|
static checkKeyLength(keys, expectedLength) {
|
|
7746
7686
|
if (keys.length < expectedLength) {
|
|
7747
|
-
throw new Error(
|
|
7687
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
7748
7688
|
}
|
|
7749
7689
|
}
|
|
7750
7690
|
|
|
@@ -8219,10 +8159,8 @@ class StakeProgram {
|
|
|
8219
8159
|
}
|
|
8220
8160
|
|
|
8221
8161
|
}
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
_defineProperty(StakeProgram, "space", 200);
|
|
8162
|
+
StakeProgram.programId = new PublicKey('Stake11111111111111111111111111111111111111');
|
|
8163
|
+
StakeProgram.space = 200;
|
|
8226
8164
|
|
|
8227
8165
|
const {
|
|
8228
8166
|
publicKeyCreate,
|
|
@@ -8252,12 +8190,12 @@ class Secp256k1Program {
|
|
|
8252
8190
|
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
8253
8191
|
*/
|
|
8254
8192
|
static publicKeyToEthAddress(publicKey) {
|
|
8255
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES,
|
|
8193
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8256
8194
|
|
|
8257
8195
|
try {
|
|
8258
|
-
return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8196
|
+
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8259
8197
|
} catch (error) {
|
|
8260
|
-
throw new Error(
|
|
8198
|
+
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8261
8199
|
}
|
|
8262
8200
|
}
|
|
8263
8201
|
/**
|
|
@@ -8308,7 +8246,7 @@ class Secp256k1Program {
|
|
|
8308
8246
|
ethAddress = rawAddress;
|
|
8309
8247
|
}
|
|
8310
8248
|
|
|
8311
|
-
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES,
|
|
8249
|
+
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES, `Address must be ${ETHEREUM_ADDRESS_BYTES} bytes but received ${ethAddress.length} bytes`);
|
|
8312
8250
|
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
|
8313
8251
|
const ethAddressOffset = dataStart;
|
|
8314
8252
|
const signatureOffset = dataStart + ethAddress.length;
|
|
@@ -8347,13 +8285,13 @@ class Secp256k1Program {
|
|
|
8347
8285
|
message,
|
|
8348
8286
|
instructionIndex
|
|
8349
8287
|
} = params;
|
|
8350
|
-
assert(pkey.length === PRIVATE_KEY_BYTES,
|
|
8288
|
+
assert(pkey.length === PRIVATE_KEY_BYTES, `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`);
|
|
8351
8289
|
|
|
8352
8290
|
try {
|
|
8353
8291
|
const privateKey = toBuffer(pkey);
|
|
8354
8292
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
8355
8293
|
|
|
8356
|
-
const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
|
|
8294
|
+
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
8357
8295
|
const {
|
|
8358
8296
|
signature,
|
|
8359
8297
|
recid: recoveryId
|
|
@@ -8366,13 +8304,12 @@ class Secp256k1Program {
|
|
|
8366
8304
|
instructionIndex
|
|
8367
8305
|
});
|
|
8368
8306
|
} catch (error) {
|
|
8369
|
-
throw new Error(
|
|
8307
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
8370
8308
|
}
|
|
8371
8309
|
}
|
|
8372
8310
|
|
|
8373
8311
|
}
|
|
8374
|
-
|
|
8375
|
-
_defineProperty(Secp256k1Program, "programId", new PublicKey('KeccakSecp256k11111111111111111111111111111'));
|
|
8312
|
+
Secp256k1Program.programId = new PublicKey('KeccakSecp256k11111111111111111111111111111');
|
|
8376
8313
|
|
|
8377
8314
|
const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
|
|
8378
8315
|
/**
|
|
@@ -8405,10 +8342,8 @@ class ValidatorInfo {
|
|
|
8405
8342
|
* @param info validator information
|
|
8406
8343
|
*/
|
|
8407
8344
|
constructor(key, info) {
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
_defineProperty(this, "info", void 0);
|
|
8411
|
-
|
|
8345
|
+
this.key = void 0;
|
|
8346
|
+
this.info = void 0;
|
|
8412
8347
|
this.key = key;
|
|
8413
8348
|
this.info = info;
|
|
8414
8349
|
}
|
|
@@ -8472,26 +8407,16 @@ class VoteAccount {
|
|
|
8472
8407
|
* @internal
|
|
8473
8408
|
*/
|
|
8474
8409
|
constructor(args) {
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
_defineProperty(this, "rootSlot", void 0);
|
|
8486
|
-
|
|
8487
|
-
_defineProperty(this, "epoch", void 0);
|
|
8488
|
-
|
|
8489
|
-
_defineProperty(this, "credits", void 0);
|
|
8490
|
-
|
|
8491
|
-
_defineProperty(this, "lastEpochCredits", void 0);
|
|
8492
|
-
|
|
8493
|
-
_defineProperty(this, "epochCredits", void 0);
|
|
8494
|
-
|
|
8410
|
+
this.nodePubkey = void 0;
|
|
8411
|
+
this.authorizedVoterPubkey = void 0;
|
|
8412
|
+
this.authorizedWithdrawerPubkey = void 0;
|
|
8413
|
+
this.commission = void 0;
|
|
8414
|
+
this.votes = void 0;
|
|
8415
|
+
this.rootSlot = void 0;
|
|
8416
|
+
this.epoch = void 0;
|
|
8417
|
+
this.credits = void 0;
|
|
8418
|
+
this.lastEpochCredits = void 0;
|
|
8419
|
+
this.epochCredits = void 0;
|
|
8495
8420
|
this.nodePubkey = args.nodePubkey;
|
|
8496
8421
|
this.authorizedVoterPubkey = args.authorizedVoterPubkey;
|
|
8497
8422
|
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
@@ -8554,7 +8479,7 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, options)
|
|
|
8554
8479
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
8555
8480
|
|
|
8556
8481
|
if (status.err) {
|
|
8557
|
-
throw new Error(
|
|
8482
|
+
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
8558
8483
|
}
|
|
8559
8484
|
|
|
8560
8485
|
return signature;
|
|
@@ -8586,7 +8511,7 @@ function clusterApiUrl(cluster, tls) {
|
|
|
8586
8511
|
const url = endpoint[key][cluster];
|
|
8587
8512
|
|
|
8588
8513
|
if (!url) {
|
|
8589
|
-
throw new Error(
|
|
8514
|
+
throw new Error(`Unknown ${key} cluster: ${cluster}`);
|
|
8590
8515
|
}
|
|
8591
8516
|
|
|
8592
8517
|
return url;
|