@layerzerolabs/lz-corekit-solana 3.0.15 → 3.0.16
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/CHANGELOG.md +9 -0
- package/README.md +112 -1
- package/dist/index.cjs +187 -389
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +201 -4
- package/dist/index.d.ts +201 -4
- package/dist/index.mjs +186 -388
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -10
package/dist/index.mjs
CHANGED
|
@@ -1,395 +1,10 @@
|
|
|
1
1
|
import { Connection, PublicKey, Keypair, sendAndConfirmRawTransaction } from '@solana/web3.js';
|
|
2
2
|
import { Block, TransactionResponse, TransactionReceipt, BlockWithTransactions, TransactionPending, SignedTransaction } from '@layerzerolabs/lz-core';
|
|
3
|
+
import { arrayify } from '@layerzerolabs/lz-utilities';
|
|
3
4
|
import * as bip39 from 'bip39';
|
|
4
5
|
import { derivePath } from 'ed25519-hd-key';
|
|
5
6
|
|
|
6
7
|
// src/providers/solana.ts
|
|
7
|
-
|
|
8
|
-
// ../../../node_modules/.store/@ethersproject-logger-npm-5.7.0-63fe9c3d29/package/lib.esm/_version.js
|
|
9
|
-
var version = "logger/5.7.0";
|
|
10
|
-
|
|
11
|
-
// ../../../node_modules/.store/@ethersproject-logger-npm-5.7.0-63fe9c3d29/package/lib.esm/index.js
|
|
12
|
-
var _permanentCensorErrors = false;
|
|
13
|
-
var _censorErrors = false;
|
|
14
|
-
var LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
|
|
15
|
-
var _logLevel = LogLevels["default"];
|
|
16
|
-
var _globalLogger = null;
|
|
17
|
-
function _checkNormalize() {
|
|
18
|
-
try {
|
|
19
|
-
const missing = [];
|
|
20
|
-
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
|
|
21
|
-
try {
|
|
22
|
-
if ("test".normalize(form) !== "test") {
|
|
23
|
-
throw new Error("bad normalize");
|
|
24
|
-
}
|
|
25
|
-
;
|
|
26
|
-
} catch (error) {
|
|
27
|
-
missing.push(form);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
if (missing.length) {
|
|
31
|
-
throw new Error("missing " + missing.join(", "));
|
|
32
|
-
}
|
|
33
|
-
if (String.fromCharCode(233).normalize("NFD") !== String.fromCharCode(101, 769)) {
|
|
34
|
-
throw new Error("broken implementation");
|
|
35
|
-
}
|
|
36
|
-
} catch (error) {
|
|
37
|
-
return error.message;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
var _normalizeError = _checkNormalize();
|
|
42
|
-
var LogLevel;
|
|
43
|
-
(function(LogLevel2) {
|
|
44
|
-
LogLevel2["DEBUG"] = "DEBUG";
|
|
45
|
-
LogLevel2["INFO"] = "INFO";
|
|
46
|
-
LogLevel2["WARNING"] = "WARNING";
|
|
47
|
-
LogLevel2["ERROR"] = "ERROR";
|
|
48
|
-
LogLevel2["OFF"] = "OFF";
|
|
49
|
-
})(LogLevel || (LogLevel = {}));
|
|
50
|
-
var ErrorCode;
|
|
51
|
-
(function(ErrorCode2) {
|
|
52
|
-
ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
53
|
-
ErrorCode2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
|
|
54
|
-
ErrorCode2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
|
|
55
|
-
ErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
56
|
-
ErrorCode2["SERVER_ERROR"] = "SERVER_ERROR";
|
|
57
|
-
ErrorCode2["TIMEOUT"] = "TIMEOUT";
|
|
58
|
-
ErrorCode2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
|
|
59
|
-
ErrorCode2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
|
|
60
|
-
ErrorCode2["MISSING_NEW"] = "MISSING_NEW";
|
|
61
|
-
ErrorCode2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
|
|
62
|
-
ErrorCode2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
|
|
63
|
-
ErrorCode2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
|
|
64
|
-
ErrorCode2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
|
|
65
|
-
ErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
66
|
-
ErrorCode2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
|
|
67
|
-
ErrorCode2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
|
|
68
|
-
ErrorCode2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
|
|
69
|
-
ErrorCode2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
|
|
70
|
-
ErrorCode2["ACTION_REJECTED"] = "ACTION_REJECTED";
|
|
71
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
72
|
-
var HEX = "0123456789abcdef";
|
|
73
|
-
var Logger = class _Logger {
|
|
74
|
-
constructor(version3) {
|
|
75
|
-
Object.defineProperty(this, "version", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
value: version3,
|
|
78
|
-
writable: false
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
_log(logLevel, args) {
|
|
82
|
-
const level = logLevel.toLowerCase();
|
|
83
|
-
if (LogLevels[level] == null) {
|
|
84
|
-
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
|
|
85
|
-
}
|
|
86
|
-
if (_logLevel > LogLevels[level]) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
console.log.apply(console, args);
|
|
90
|
-
}
|
|
91
|
-
debug(...args) {
|
|
92
|
-
this._log(_Logger.levels.DEBUG, args);
|
|
93
|
-
}
|
|
94
|
-
info(...args) {
|
|
95
|
-
this._log(_Logger.levels.INFO, args);
|
|
96
|
-
}
|
|
97
|
-
warn(...args) {
|
|
98
|
-
this._log(_Logger.levels.WARNING, args);
|
|
99
|
-
}
|
|
100
|
-
makeError(message, code, params) {
|
|
101
|
-
if (_censorErrors) {
|
|
102
|
-
return this.makeError("censored error", code, {});
|
|
103
|
-
}
|
|
104
|
-
if (!code) {
|
|
105
|
-
code = _Logger.errors.UNKNOWN_ERROR;
|
|
106
|
-
}
|
|
107
|
-
if (!params) {
|
|
108
|
-
params = {};
|
|
109
|
-
}
|
|
110
|
-
const messageDetails = [];
|
|
111
|
-
Object.keys(params).forEach((key) => {
|
|
112
|
-
const value = params[key];
|
|
113
|
-
try {
|
|
114
|
-
if (value instanceof Uint8Array) {
|
|
115
|
-
let hex = "";
|
|
116
|
-
for (let i = 0; i < value.length; i++) {
|
|
117
|
-
hex += HEX[value[i] >> 4];
|
|
118
|
-
hex += HEX[value[i] & 15];
|
|
119
|
-
}
|
|
120
|
-
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
|
|
121
|
-
} else {
|
|
122
|
-
messageDetails.push(key + "=" + JSON.stringify(value));
|
|
123
|
-
}
|
|
124
|
-
} catch (error2) {
|
|
125
|
-
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
messageDetails.push(`code=${code}`);
|
|
129
|
-
messageDetails.push(`version=${this.version}`);
|
|
130
|
-
const reason = message;
|
|
131
|
-
let url = "";
|
|
132
|
-
switch (code) {
|
|
133
|
-
case ErrorCode.NUMERIC_FAULT: {
|
|
134
|
-
url = "NUMERIC_FAULT";
|
|
135
|
-
const fault = message;
|
|
136
|
-
switch (fault) {
|
|
137
|
-
case "overflow":
|
|
138
|
-
case "underflow":
|
|
139
|
-
case "division-by-zero":
|
|
140
|
-
url += "-" + fault;
|
|
141
|
-
break;
|
|
142
|
-
case "negative-power":
|
|
143
|
-
case "negative-width":
|
|
144
|
-
url += "-unsupported";
|
|
145
|
-
break;
|
|
146
|
-
case "unbound-bitwise-result":
|
|
147
|
-
url += "-unbound-result";
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case ErrorCode.CALL_EXCEPTION:
|
|
153
|
-
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
154
|
-
case ErrorCode.MISSING_NEW:
|
|
155
|
-
case ErrorCode.NONCE_EXPIRED:
|
|
156
|
-
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
157
|
-
case ErrorCode.TRANSACTION_REPLACED:
|
|
158
|
-
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
159
|
-
url = code;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
if (url) {
|
|
163
|
-
message += " [ See: https://links.ethers.org/v5-errors-" + url + " ]";
|
|
164
|
-
}
|
|
165
|
-
if (messageDetails.length) {
|
|
166
|
-
message += " (" + messageDetails.join(", ") + ")";
|
|
167
|
-
}
|
|
168
|
-
const error = new Error(message);
|
|
169
|
-
error.reason = reason;
|
|
170
|
-
error.code = code;
|
|
171
|
-
Object.keys(params).forEach(function(key) {
|
|
172
|
-
error[key] = params[key];
|
|
173
|
-
});
|
|
174
|
-
return error;
|
|
175
|
-
}
|
|
176
|
-
throwError(message, code, params) {
|
|
177
|
-
throw this.makeError(message, code, params);
|
|
178
|
-
}
|
|
179
|
-
throwArgumentError(message, name, value) {
|
|
180
|
-
return this.throwError(message, _Logger.errors.INVALID_ARGUMENT, {
|
|
181
|
-
argument: name,
|
|
182
|
-
value
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
assert(condition, message, code, params) {
|
|
186
|
-
if (!!condition) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
this.throwError(message, code, params);
|
|
190
|
-
}
|
|
191
|
-
assertArgument(condition, message, name, value) {
|
|
192
|
-
if (!!condition) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
this.throwArgumentError(message, name, value);
|
|
196
|
-
}
|
|
197
|
-
checkNormalize(message) {
|
|
198
|
-
if (_normalizeError) {
|
|
199
|
-
this.throwError("platform missing String.prototype.normalize", _Logger.errors.UNSUPPORTED_OPERATION, {
|
|
200
|
-
operation: "String.prototype.normalize",
|
|
201
|
-
form: _normalizeError
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
checkSafeUint53(value, message) {
|
|
206
|
-
if (typeof value !== "number") {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
if (message == null) {
|
|
210
|
-
message = "value not safe";
|
|
211
|
-
}
|
|
212
|
-
if (value < 0 || value >= 9007199254740991) {
|
|
213
|
-
this.throwError(message, _Logger.errors.NUMERIC_FAULT, {
|
|
214
|
-
operation: "checkSafeInteger",
|
|
215
|
-
fault: "out-of-safe-range",
|
|
216
|
-
value
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (value % 1) {
|
|
220
|
-
this.throwError(message, _Logger.errors.NUMERIC_FAULT, {
|
|
221
|
-
operation: "checkSafeInteger",
|
|
222
|
-
fault: "non-integer",
|
|
223
|
-
value
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
checkArgumentCount(count, expectedCount, message) {
|
|
228
|
-
if (message) {
|
|
229
|
-
message = ": " + message;
|
|
230
|
-
} else {
|
|
231
|
-
message = "";
|
|
232
|
-
}
|
|
233
|
-
if (count < expectedCount) {
|
|
234
|
-
this.throwError("missing argument" + message, _Logger.errors.MISSING_ARGUMENT, {
|
|
235
|
-
count,
|
|
236
|
-
expectedCount
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
if (count > expectedCount) {
|
|
240
|
-
this.throwError("too many arguments" + message, _Logger.errors.UNEXPECTED_ARGUMENT, {
|
|
241
|
-
count,
|
|
242
|
-
expectedCount
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
checkNew(target, kind) {
|
|
247
|
-
if (target === Object || target == null) {
|
|
248
|
-
this.throwError("missing new", _Logger.errors.MISSING_NEW, { name: kind.name });
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
checkAbstract(target, kind) {
|
|
252
|
-
if (target === kind) {
|
|
253
|
-
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", _Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
|
|
254
|
-
} else if (target === Object || target == null) {
|
|
255
|
-
this.throwError("missing new", _Logger.errors.MISSING_NEW, { name: kind.name });
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
static globalLogger() {
|
|
259
|
-
if (!_globalLogger) {
|
|
260
|
-
_globalLogger = new _Logger(version);
|
|
261
|
-
}
|
|
262
|
-
return _globalLogger;
|
|
263
|
-
}
|
|
264
|
-
static setCensorship(censorship, permanent) {
|
|
265
|
-
if (!censorship && permanent) {
|
|
266
|
-
this.globalLogger().throwError("cannot permanently disable censorship", _Logger.errors.UNSUPPORTED_OPERATION, {
|
|
267
|
-
operation: "setCensorship"
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
if (_permanentCensorErrors) {
|
|
271
|
-
if (!censorship) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
this.globalLogger().throwError("error censorship permanent", _Logger.errors.UNSUPPORTED_OPERATION, {
|
|
275
|
-
operation: "setCensorship"
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
_censorErrors = !!censorship;
|
|
279
|
-
_permanentCensorErrors = !!permanent;
|
|
280
|
-
}
|
|
281
|
-
static setLogLevel(logLevel) {
|
|
282
|
-
const level = LogLevels[logLevel.toLowerCase()];
|
|
283
|
-
if (level == null) {
|
|
284
|
-
_Logger.globalLogger().warn("invalid log level - " + logLevel);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
_logLevel = level;
|
|
288
|
-
}
|
|
289
|
-
static from(version3) {
|
|
290
|
-
return new _Logger(version3);
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
Logger.errors = ErrorCode;
|
|
294
|
-
Logger.levels = LogLevel;
|
|
295
|
-
|
|
296
|
-
// ../../../node_modules/.store/@ethersproject-bytes-npm-5.7.0-4454fe4cb0/package/lib.esm/_version.js
|
|
297
|
-
var version2 = "bytes/5.7.0";
|
|
298
|
-
|
|
299
|
-
// ../../../node_modules/.store/@ethersproject-bytes-npm-5.7.0-4454fe4cb0/package/lib.esm/index.js
|
|
300
|
-
var logger = new Logger(version2);
|
|
301
|
-
function isHexable(value) {
|
|
302
|
-
return !!value.toHexString;
|
|
303
|
-
}
|
|
304
|
-
function addSlice(array) {
|
|
305
|
-
if (array.slice) {
|
|
306
|
-
return array;
|
|
307
|
-
}
|
|
308
|
-
array.slice = function() {
|
|
309
|
-
const args = Array.prototype.slice.call(arguments);
|
|
310
|
-
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
|
|
311
|
-
};
|
|
312
|
-
return array;
|
|
313
|
-
}
|
|
314
|
-
function isInteger(value) {
|
|
315
|
-
return typeof value === "number" && value == value && value % 1 === 0;
|
|
316
|
-
}
|
|
317
|
-
function isBytes(value) {
|
|
318
|
-
if (value == null) {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
if (value.constructor === Uint8Array) {
|
|
322
|
-
return true;
|
|
323
|
-
}
|
|
324
|
-
if (typeof value === "string") {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
for (let i = 0; i < value.length; i++) {
|
|
331
|
-
const v = value[i];
|
|
332
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return true;
|
|
337
|
-
}
|
|
338
|
-
function arrayify(value, options) {
|
|
339
|
-
if (!options) {
|
|
340
|
-
options = {};
|
|
341
|
-
}
|
|
342
|
-
if (typeof value === "number") {
|
|
343
|
-
logger.checkSafeUint53(value, "invalid arrayify value");
|
|
344
|
-
const result = [];
|
|
345
|
-
while (value) {
|
|
346
|
-
result.unshift(value & 255);
|
|
347
|
-
value = parseInt(String(value / 256));
|
|
348
|
-
}
|
|
349
|
-
if (result.length === 0) {
|
|
350
|
-
result.push(0);
|
|
351
|
-
}
|
|
352
|
-
return addSlice(new Uint8Array(result));
|
|
353
|
-
}
|
|
354
|
-
if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
|
|
355
|
-
value = "0x" + value;
|
|
356
|
-
}
|
|
357
|
-
if (isHexable(value)) {
|
|
358
|
-
value = value.toHexString();
|
|
359
|
-
}
|
|
360
|
-
if (isHexString(value)) {
|
|
361
|
-
let hex = value.substring(2);
|
|
362
|
-
if (hex.length % 2) {
|
|
363
|
-
if (options.hexPad === "left") {
|
|
364
|
-
hex = "0" + hex;
|
|
365
|
-
} else if (options.hexPad === "right") {
|
|
366
|
-
hex += "0";
|
|
367
|
-
} else {
|
|
368
|
-
logger.throwArgumentError("hex data is odd-length", "value", value);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
const result = [];
|
|
372
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
373
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
374
|
-
}
|
|
375
|
-
return addSlice(new Uint8Array(result));
|
|
376
|
-
}
|
|
377
|
-
if (isBytes(value)) {
|
|
378
|
-
return addSlice(new Uint8Array(value));
|
|
379
|
-
}
|
|
380
|
-
return logger.throwArgumentError("invalid arrayify value", "value", value);
|
|
381
|
-
}
|
|
382
|
-
function isHexString(value, length) {
|
|
383
|
-
if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// src/utils.ts
|
|
393
8
|
function toRawTransaction(transaction) {
|
|
394
9
|
const retval = typeof transaction === "string" ? arrayify(transaction) : transaction.serialize();
|
|
395
10
|
return retval;
|
|
@@ -397,10 +12,22 @@ function toRawTransaction(transaction) {
|
|
|
397
12
|
|
|
398
13
|
// src/providers/solana.ts
|
|
399
14
|
var SolanaProvider = class _SolanaProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of SolanaProvider.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} url - The URL of the Solana node.
|
|
19
|
+
*/
|
|
400
20
|
constructor(url) {
|
|
401
21
|
this.url = url;
|
|
402
22
|
this.nativeProvider = new Connection(url, "confirmed");
|
|
403
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an instance of SolanaProvider from the given source.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} source - The source to create the provider from.
|
|
28
|
+
* @returns {SolanaProvider} The created SolanaProvider instance.
|
|
29
|
+
* @throws {Error} If the source parameter is invalid.
|
|
30
|
+
*/
|
|
404
31
|
static from(source) {
|
|
405
32
|
if (typeof source === "string") {
|
|
406
33
|
return new _SolanaProvider(source);
|
|
@@ -408,24 +35,59 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
408
35
|
throw new Error("Invalid parameters");
|
|
409
36
|
}
|
|
410
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets the native Solana provider instance.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Connection} The native Solana provider instance.
|
|
42
|
+
*/
|
|
411
43
|
get native() {
|
|
412
44
|
return this.nativeProvider;
|
|
413
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets the balance of the specified address.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} address - The address to get the balance of.
|
|
50
|
+
* @returns {Promise<string>} A promise that resolves to the balance of the address.
|
|
51
|
+
*/
|
|
414
52
|
async getBalance(address) {
|
|
415
53
|
return this.nativeProvider.getBalance(new PublicKey(address)).then((balance) => balance.toString());
|
|
416
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets the block specified by slot.
|
|
57
|
+
*
|
|
58
|
+
* @param {BlockTag} slot - The slot to specify the block.
|
|
59
|
+
* @returns {Promise<Block>} A promise that resolves to the block.
|
|
60
|
+
*/
|
|
417
61
|
async getBlock(slot) {
|
|
418
62
|
const response = await this.nativeProvider.getParsedBlock(parseInt(slot.toString()), {
|
|
419
63
|
commitment: "confirmed"
|
|
420
64
|
});
|
|
421
65
|
return Block.from(response);
|
|
422
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current block number.
|
|
69
|
+
*
|
|
70
|
+
* @returns {Promise<number>} A promise that resolves to the current block number.
|
|
71
|
+
*/
|
|
423
72
|
async getBlockNumber() {
|
|
424
73
|
return this.nativeProvider.getBlockHeight({ commitment: "confirmed" });
|
|
425
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the current slot number for commitment.
|
|
77
|
+
*
|
|
78
|
+
* @param {Finality} [finality] - The commitment level (optional).
|
|
79
|
+
* @returns {Promise<number>} A promise that resolves to the current slot number.
|
|
80
|
+
*/
|
|
426
81
|
async getSlot(finality) {
|
|
427
82
|
return this.nativeProvider.getSlot(finality);
|
|
428
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets the UNIX timestamp for the block identified by slot.
|
|
86
|
+
*
|
|
87
|
+
* @param {BlockTag} slot - The slot to specify the block.
|
|
88
|
+
* @returns {Promise<number>} A promise that resolves to the UNIX timestamp of the block.
|
|
89
|
+
* @throws {Error} If the block timestamp is not available.
|
|
90
|
+
*/
|
|
429
91
|
async getBlockTimestamp(slot) {
|
|
430
92
|
const t = await this.nativeProvider.getBlockTime(parseInt(slot.toString()));
|
|
431
93
|
if (t === null) {
|
|
@@ -434,9 +96,10 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
434
96
|
return t;
|
|
435
97
|
}
|
|
436
98
|
/**
|
|
99
|
+
* Gets information about a transaction.
|
|
437
100
|
*
|
|
438
|
-
* @param txHash
|
|
439
|
-
* @returns TransactionResponse
|
|
101
|
+
* @param {string} txHash - The transaction hash is TransactionSignature in Solana
|
|
102
|
+
* @returns {Promise<TransactionResponse>} A promise that resolves to the transaction response
|
|
440
103
|
*/
|
|
441
104
|
async getTransaction(txHash) {
|
|
442
105
|
const response = await this.nativeProvider.getParsedTransaction(txHash, {
|
|
@@ -444,6 +107,13 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
444
107
|
});
|
|
445
108
|
return TransactionResponse.from(response);
|
|
446
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets the receipt of a transaction.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} txHash - The transaction hash is TransactionSignature in Solana
|
|
114
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
115
|
+
* @throws {Error} If the transaction is not found.
|
|
116
|
+
*/
|
|
447
117
|
async getTransactionReceipt(txHash) {
|
|
448
118
|
const response = await this.nativeProvider.getParsedTransaction(txHash, {
|
|
449
119
|
commitment: "confirmed"
|
|
@@ -453,11 +123,26 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
453
123
|
}
|
|
454
124
|
return TransactionReceipt.from(response);
|
|
455
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets the number of transactions sent from the specified address.
|
|
128
|
+
*
|
|
129
|
+
* @param {string | Promise<string>} _addressOrName - The address to get the number of transactions from.
|
|
130
|
+
* @param {BlockTag | Promise<BlockTag>} [_blockTag] - The block tag to get the number of transactions from (optional).
|
|
131
|
+
* @returns {Promise<number>} A promise that resolves to the number of transactions sent from the address.
|
|
132
|
+
* @throws {Error} Method not implemented.
|
|
133
|
+
*/
|
|
456
134
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
457
135
|
async getTransactionCount(_addressOrName, _blockTag) {
|
|
458
136
|
await Promise.resolve();
|
|
459
137
|
throw new Error("Method not implemented.");
|
|
460
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets the block with transactions specified by blockTag.
|
|
141
|
+
*
|
|
142
|
+
* @param {BlockTag} blockTag - The block tag to specify the block.
|
|
143
|
+
* @returns {Promise<BlockWithTransactions>} A promise that resolves to the block with transactions.
|
|
144
|
+
* @throws {Error} If the block is not found.
|
|
145
|
+
*/
|
|
461
146
|
async getBlockWithTransactions(blockTag) {
|
|
462
147
|
if (typeof blockTag === "string") {
|
|
463
148
|
blockTag = parseInt(blockTag);
|
|
@@ -468,12 +153,27 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
468
153
|
}
|
|
469
154
|
return BlockWithTransactions.from(response);
|
|
470
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Sends a signed transaction to the blockchain.
|
|
158
|
+
*
|
|
159
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
160
|
+
* @param {SendOptions} [sendOptions] - Optional parameters for sending the transaction.
|
|
161
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
162
|
+
*/
|
|
471
163
|
async sendTransaction(transaction, sendOptions) {
|
|
472
164
|
const _transaction = transaction.signed;
|
|
473
165
|
const rawTransaction = toRawTransaction(_transaction);
|
|
474
166
|
const response = await this.nativeProvider.sendRawTransaction(rawTransaction, sendOptions);
|
|
475
167
|
return TransactionPending.from(response);
|
|
476
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Confirms a pending transaction.
|
|
171
|
+
*
|
|
172
|
+
* @param {TransactionPending} pending - The pending transaction to confirm.
|
|
173
|
+
* @param {TransactionConfirmationStrategy} [opts] - Optional parameters for the confirmation.
|
|
174
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
175
|
+
* @throws {Error} If the transaction fails.
|
|
176
|
+
*/
|
|
477
177
|
async confirmTransaction(pending, opts) {
|
|
478
178
|
const strategy = opts ?? await (async () => {
|
|
479
179
|
const block = await this.nativeProvider.getLatestBlockhash("confirmed");
|
|
@@ -490,15 +190,35 @@ var SolanaProvider = class _SolanaProvider {
|
|
|
490
190
|
}
|
|
491
191
|
return Promise.resolve(TransactionReceipt.from(signature));
|
|
492
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Sends a signed transaction and waits for confirmation.
|
|
195
|
+
*
|
|
196
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
197
|
+
* @param {object} [opts] - Optional parameters for sending and confirming the transaction.
|
|
198
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
199
|
+
*/
|
|
493
200
|
async sendAndConfirm(transaction, opts) {
|
|
494
201
|
const pending = await this.sendTransaction(transaction, opts?.send);
|
|
495
202
|
return this.confirmTransaction(pending, opts?.confirm);
|
|
496
203
|
}
|
|
497
204
|
};
|
|
498
205
|
var SolanaSigner = class {
|
|
206
|
+
/**
|
|
207
|
+
* Creates an instance of SolanaSigner.
|
|
208
|
+
*
|
|
209
|
+
* @param {Keypair} keypair - The Solana keypair to use as the signer.
|
|
210
|
+
*/
|
|
499
211
|
constructor(keypair) {
|
|
500
212
|
this.keypair = keypair;
|
|
501
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates an instance of SolanaSigner from the given source.
|
|
216
|
+
*
|
|
217
|
+
* @param {Keypair | string} source - The source to create the signer from.
|
|
218
|
+
* @param {string} [path] - The derivation path (optional).
|
|
219
|
+
* @returns {SolanaSigner} The created SolanaSigner instance.
|
|
220
|
+
* @throws {Error} If the parameters are invalid.
|
|
221
|
+
*/
|
|
502
222
|
static from(source, path) {
|
|
503
223
|
if (source instanceof Keypair) {
|
|
504
224
|
return new this(source);
|
|
@@ -509,9 +229,21 @@ var SolanaSigner = class {
|
|
|
509
229
|
throw new Error("Invalid parameters");
|
|
510
230
|
}
|
|
511
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Gets the native Solana keypair instance.
|
|
234
|
+
*
|
|
235
|
+
* @returns {Keypair} The native Solana keypair instance.
|
|
236
|
+
*/
|
|
512
237
|
get native() {
|
|
513
238
|
return this.keypair;
|
|
514
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Connects the signer to a provider.
|
|
242
|
+
*
|
|
243
|
+
* @param {Provider} provider - The provider to connect to.
|
|
244
|
+
* @returns {this} The connected signer.
|
|
245
|
+
* @throws {Error} If the provider is not an instance of Connection.
|
|
246
|
+
*/
|
|
515
247
|
connect(provider) {
|
|
516
248
|
if (!(provider.native instanceof Connection)) {
|
|
517
249
|
throw new Error("Only @solana/web3.js Connection is supported.");
|
|
@@ -519,18 +251,45 @@ var SolanaSigner = class {
|
|
|
519
251
|
this.provider = provider.native;
|
|
520
252
|
return this;
|
|
521
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Gets the address of the signer.
|
|
256
|
+
*
|
|
257
|
+
* @returns {Promise<string>} A promise that resolves to the address of the signer.
|
|
258
|
+
*/
|
|
522
259
|
async getAddress() {
|
|
523
260
|
return Promise.resolve(this.keypair.publicKey.toBase58());
|
|
524
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Gets the address of the signer.
|
|
264
|
+
*
|
|
265
|
+
* @returns {string} The address of the signer.
|
|
266
|
+
*/
|
|
525
267
|
get address() {
|
|
526
268
|
return this.publicKey.toBase58();
|
|
527
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Gets the public key of the signer.
|
|
272
|
+
*
|
|
273
|
+
* @returns {PublicKey} The public key of the signer.
|
|
274
|
+
*/
|
|
528
275
|
get publicKey() {
|
|
529
276
|
return this.keypair.publicKey;
|
|
530
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Gets the secret key of the signer.
|
|
280
|
+
*
|
|
281
|
+
* @returns {Uint8Array} The secret key of the signer.
|
|
282
|
+
*/
|
|
531
283
|
get secretKey() {
|
|
532
284
|
return this.keypair.secretKey;
|
|
533
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Sends a signed transaction and waits for confirmation.
|
|
288
|
+
*
|
|
289
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
290
|
+
* @param {ConfirmOptions} [opts] - Optional parameters for sending and confirming the transaction.
|
|
291
|
+
* @returns {Promise<TransactionReceipt>} A promise that resolves to the transaction receipt.
|
|
292
|
+
*/
|
|
534
293
|
async sendAndConfirm(transaction, opts) {
|
|
535
294
|
const provider = this.assertAndGetProvider();
|
|
536
295
|
const _transaction = transaction.signed;
|
|
@@ -538,6 +297,13 @@ var SolanaSigner = class {
|
|
|
538
297
|
const response = await sendAndConfirmRawTransaction(provider, Buffer.from(rawTransaction), opts);
|
|
539
298
|
return TransactionReceipt.from(response);
|
|
540
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Sends a signed transaction.
|
|
302
|
+
*
|
|
303
|
+
* @param {SignedTransaction} transaction - The signed transaction to send.
|
|
304
|
+
* @param {SendOptions} [sendOptions] - Optional parameters for sending the transaction.
|
|
305
|
+
* @returns {Promise<TransactionPending>} A promise that resolves to the pending transaction.
|
|
306
|
+
*/
|
|
541
307
|
async sendTransaction(transaction, sendOptions) {
|
|
542
308
|
const provider = this.assertAndGetProvider();
|
|
543
309
|
const _transaction = transaction.signed;
|
|
@@ -545,6 +311,13 @@ var SolanaSigner = class {
|
|
|
545
311
|
const response = await provider.sendRawTransaction(rawTransaction, sendOptions);
|
|
546
312
|
return TransactionPending.from(response);
|
|
547
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Signs a transaction.
|
|
316
|
+
*
|
|
317
|
+
* @param {TransactionRequest} transaction - The transaction request to sign.
|
|
318
|
+
* @param {Commitment | GetLatestBlockhashConfig} [opts] - Optional parameters for signing the transaction.
|
|
319
|
+
* @returns {Promise<SignedTransaction>} A promise that resolves to the signed transaction.
|
|
320
|
+
*/
|
|
548
321
|
async signTransaction(transaction, opts) {
|
|
549
322
|
const tx = transaction.request;
|
|
550
323
|
if (isVersionedTransaction(tx)) {
|
|
@@ -554,10 +327,22 @@ var SolanaSigner = class {
|
|
|
554
327
|
}
|
|
555
328
|
return Promise.resolve(SignedTransaction.from(tx));
|
|
556
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Signs a buffer (e.g., a message hash) using the native Solana signer.
|
|
332
|
+
*
|
|
333
|
+
* @param {Uint8Array} _buffer - The buffer to sign.
|
|
334
|
+
* @returns {Promise<Uint8Array>} A promise that resolves to the signed buffer as a Uint8Array.
|
|
335
|
+
* @throws {Error} Method not implemented.
|
|
336
|
+
*/
|
|
557
337
|
async signBuffer(_buffer) {
|
|
558
338
|
await Promise.resolve();
|
|
559
339
|
throw new Error("Method not implemented.");
|
|
560
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Partially signs a transaction.
|
|
343
|
+
*
|
|
344
|
+
* @param {Transaction | VersionedTransaction} tx - The transaction to partially sign.
|
|
345
|
+
*/
|
|
561
346
|
partialSign(tx) {
|
|
562
347
|
if (isVersionedTransaction(tx)) {
|
|
563
348
|
tx.sign([this.keypair]);
|
|
@@ -565,12 +350,25 @@ var SolanaSigner = class {
|
|
|
565
350
|
tx.partialSign(this.keypair);
|
|
566
351
|
}
|
|
567
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Asserts that the provider is connected and returns it.
|
|
355
|
+
*
|
|
356
|
+
* @returns {Connection} The connected provider.
|
|
357
|
+
* @throws {Error} If the provider is not connected.
|
|
358
|
+
*/
|
|
568
359
|
assertAndGetProvider() {
|
|
569
360
|
if (!this.provider) {
|
|
570
361
|
throw new Error("Signer was not connected to a provider, did you forgot to connect to provider?");
|
|
571
362
|
}
|
|
572
363
|
return this.provider;
|
|
573
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Builds a transaction.
|
|
367
|
+
*
|
|
368
|
+
* @param {unknown} buildTxRequest - The transaction request to build.
|
|
369
|
+
* @returns {Promise<TransactionRequest>} A promise that resolves to the built transaction request.
|
|
370
|
+
* @throws {Error} Method not implemented.
|
|
371
|
+
*/
|
|
574
372
|
async buildTransaction(buildTxRequest) {
|
|
575
373
|
return Promise.reject(new Error("Method not implemented."));
|
|
576
374
|
}
|