@layerzerolabs/lz-corekit-solana 3.0.2-initia.5 → 3.0.2

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 CHANGED
@@ -1,13 +1,5 @@
1
1
  # @layerzerolabs/lz-corekit-solana
2
2
 
3
- ## 3.0.2-initia.5
4
-
5
- ### Patch Changes
6
-
7
- - Build new initia,aptos,bsc,movement snpashot images(initiad upgrade to 0.5.6)
8
- - Updated dependencies
9
- - @layerzerolabs/lz-core@3.0.2-initia.5
10
-
11
3
  ## 3.0.2
12
4
 
13
5
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var bytes = require('@ethersproject/bytes');
4
3
  var web3_js = require('@solana/web3.js');
5
4
  var lzCore = require('@layerzerolabs/lz-core');
5
+ var bytes = require('@ethersproject/bytes');
6
6
  var bip39 = require('bip39');
7
7
  var ed25519HdKey = require('ed25519-hd-key');
8
8
  var secp256k1 = require('@noble/secp256k1');
@@ -27,6 +27,398 @@ function _interopNamespace(e) {
27
27
 
28
28
  var bip39__namespace = /*#__PURE__*/_interopNamespace(bip39);
29
29
 
30
+ // src/providers/solana.ts
31
+
32
+ // ../../../node_modules/.store/@ethersproject-logger-npm-5.7.0-63fe9c3d29/package/lib.esm/_version.js
33
+ var version = "logger/5.7.0";
34
+
35
+ // ../../../node_modules/.store/@ethersproject-logger-npm-5.7.0-63fe9c3d29/package/lib.esm/index.js
36
+ var _permanentCensorErrors = false;
37
+ var _censorErrors = false;
38
+ var LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
39
+ var _logLevel = LogLevels["default"];
40
+ var _globalLogger = null;
41
+ function _checkNormalize() {
42
+ try {
43
+ const missing = [];
44
+ ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
45
+ try {
46
+ if ("test".normalize(form) !== "test") {
47
+ throw new Error("bad normalize");
48
+ }
49
+ ;
50
+ } catch (error) {
51
+ missing.push(form);
52
+ }
53
+ });
54
+ if (missing.length) {
55
+ throw new Error("missing " + missing.join(", "));
56
+ }
57
+ if (String.fromCharCode(233).normalize("NFD") !== String.fromCharCode(101, 769)) {
58
+ throw new Error("broken implementation");
59
+ }
60
+ } catch (error) {
61
+ return error.message;
62
+ }
63
+ return null;
64
+ }
65
+ var _normalizeError = _checkNormalize();
66
+ var LogLevel;
67
+ (function(LogLevel2) {
68
+ LogLevel2["DEBUG"] = "DEBUG";
69
+ LogLevel2["INFO"] = "INFO";
70
+ LogLevel2["WARNING"] = "WARNING";
71
+ LogLevel2["ERROR"] = "ERROR";
72
+ LogLevel2["OFF"] = "OFF";
73
+ })(LogLevel || (LogLevel = {}));
74
+ var ErrorCode;
75
+ (function(ErrorCode2) {
76
+ ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
77
+ ErrorCode2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
78
+ ErrorCode2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
79
+ ErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
80
+ ErrorCode2["SERVER_ERROR"] = "SERVER_ERROR";
81
+ ErrorCode2["TIMEOUT"] = "TIMEOUT";
82
+ ErrorCode2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
83
+ ErrorCode2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
84
+ ErrorCode2["MISSING_NEW"] = "MISSING_NEW";
85
+ ErrorCode2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
86
+ ErrorCode2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
87
+ ErrorCode2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
88
+ ErrorCode2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
89
+ ErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
90
+ ErrorCode2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
91
+ ErrorCode2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
92
+ ErrorCode2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
93
+ ErrorCode2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
94
+ ErrorCode2["ACTION_REJECTED"] = "ACTION_REJECTED";
95
+ })(ErrorCode || (ErrorCode = {}));
96
+ var HEX = "0123456789abcdef";
97
+ var Logger = class _Logger {
98
+ constructor(version3) {
99
+ Object.defineProperty(this, "version", {
100
+ enumerable: true,
101
+ value: version3,
102
+ writable: false
103
+ });
104
+ }
105
+ _log(logLevel, args) {
106
+ const level = logLevel.toLowerCase();
107
+ if (LogLevels[level] == null) {
108
+ this.throwArgumentError("invalid log level name", "logLevel", logLevel);
109
+ }
110
+ if (_logLevel > LogLevels[level]) {
111
+ return;
112
+ }
113
+ console.log.apply(console, args);
114
+ }
115
+ debug(...args) {
116
+ this._log(_Logger.levels.DEBUG, args);
117
+ }
118
+ info(...args) {
119
+ this._log(_Logger.levels.INFO, args);
120
+ }
121
+ warn(...args) {
122
+ this._log(_Logger.levels.WARNING, args);
123
+ }
124
+ makeError(message, code, params) {
125
+ if (_censorErrors) {
126
+ return this.makeError("censored error", code, {});
127
+ }
128
+ if (!code) {
129
+ code = _Logger.errors.UNKNOWN_ERROR;
130
+ }
131
+ if (!params) {
132
+ params = {};
133
+ }
134
+ const messageDetails = [];
135
+ Object.keys(params).forEach((key) => {
136
+ const value = params[key];
137
+ try {
138
+ if (value instanceof Uint8Array) {
139
+ let hex = "";
140
+ for (let i = 0; i < value.length; i++) {
141
+ hex += HEX[value[i] >> 4];
142
+ hex += HEX[value[i] & 15];
143
+ }
144
+ messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
145
+ } else {
146
+ messageDetails.push(key + "=" + JSON.stringify(value));
147
+ }
148
+ } catch (error2) {
149
+ messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
150
+ }
151
+ });
152
+ messageDetails.push(`code=${code}`);
153
+ messageDetails.push(`version=${this.version}`);
154
+ const reason = message;
155
+ let url = "";
156
+ switch (code) {
157
+ case ErrorCode.NUMERIC_FAULT: {
158
+ url = "NUMERIC_FAULT";
159
+ const fault = message;
160
+ switch (fault) {
161
+ case "overflow":
162
+ case "underflow":
163
+ case "division-by-zero":
164
+ url += "-" + fault;
165
+ break;
166
+ case "negative-power":
167
+ case "negative-width":
168
+ url += "-unsupported";
169
+ break;
170
+ case "unbound-bitwise-result":
171
+ url += "-unbound-result";
172
+ break;
173
+ }
174
+ break;
175
+ }
176
+ case ErrorCode.CALL_EXCEPTION:
177
+ case ErrorCode.INSUFFICIENT_FUNDS:
178
+ case ErrorCode.MISSING_NEW:
179
+ case ErrorCode.NONCE_EXPIRED:
180
+ case ErrorCode.REPLACEMENT_UNDERPRICED:
181
+ case ErrorCode.TRANSACTION_REPLACED:
182
+ case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
183
+ url = code;
184
+ break;
185
+ }
186
+ if (url) {
187
+ message += " [ See: https://links.ethers.org/v5-errors-" + url + " ]";
188
+ }
189
+ if (messageDetails.length) {
190
+ message += " (" + messageDetails.join(", ") + ")";
191
+ }
192
+ const error = new Error(message);
193
+ error.reason = reason;
194
+ error.code = code;
195
+ Object.keys(params).forEach(function(key) {
196
+ error[key] = params[key];
197
+ });
198
+ return error;
199
+ }
200
+ throwError(message, code, params) {
201
+ throw this.makeError(message, code, params);
202
+ }
203
+ throwArgumentError(message, name, value) {
204
+ return this.throwError(message, _Logger.errors.INVALID_ARGUMENT, {
205
+ argument: name,
206
+ value
207
+ });
208
+ }
209
+ assert(condition, message, code, params) {
210
+ if (!!condition) {
211
+ return;
212
+ }
213
+ this.throwError(message, code, params);
214
+ }
215
+ assertArgument(condition, message, name, value) {
216
+ if (!!condition) {
217
+ return;
218
+ }
219
+ this.throwArgumentError(message, name, value);
220
+ }
221
+ checkNormalize(message) {
222
+ if (_normalizeError) {
223
+ this.throwError("platform missing String.prototype.normalize", _Logger.errors.UNSUPPORTED_OPERATION, {
224
+ operation: "String.prototype.normalize",
225
+ form: _normalizeError
226
+ });
227
+ }
228
+ }
229
+ checkSafeUint53(value, message) {
230
+ if (typeof value !== "number") {
231
+ return;
232
+ }
233
+ if (message == null) {
234
+ message = "value not safe";
235
+ }
236
+ if (value < 0 || value >= 9007199254740991) {
237
+ this.throwError(message, _Logger.errors.NUMERIC_FAULT, {
238
+ operation: "checkSafeInteger",
239
+ fault: "out-of-safe-range",
240
+ value
241
+ });
242
+ }
243
+ if (value % 1) {
244
+ this.throwError(message, _Logger.errors.NUMERIC_FAULT, {
245
+ operation: "checkSafeInteger",
246
+ fault: "non-integer",
247
+ value
248
+ });
249
+ }
250
+ }
251
+ checkArgumentCount(count, expectedCount, message) {
252
+ if (message) {
253
+ message = ": " + message;
254
+ } else {
255
+ message = "";
256
+ }
257
+ if (count < expectedCount) {
258
+ this.throwError("missing argument" + message, _Logger.errors.MISSING_ARGUMENT, {
259
+ count,
260
+ expectedCount
261
+ });
262
+ }
263
+ if (count > expectedCount) {
264
+ this.throwError("too many arguments" + message, _Logger.errors.UNEXPECTED_ARGUMENT, {
265
+ count,
266
+ expectedCount
267
+ });
268
+ }
269
+ }
270
+ checkNew(target, kind) {
271
+ if (target === Object || target == null) {
272
+ this.throwError("missing new", _Logger.errors.MISSING_NEW, { name: kind.name });
273
+ }
274
+ }
275
+ checkAbstract(target, kind) {
276
+ if (target === kind) {
277
+ this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", _Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
278
+ } else if (target === Object || target == null) {
279
+ this.throwError("missing new", _Logger.errors.MISSING_NEW, { name: kind.name });
280
+ }
281
+ }
282
+ static globalLogger() {
283
+ if (!_globalLogger) {
284
+ _globalLogger = new _Logger(version);
285
+ }
286
+ return _globalLogger;
287
+ }
288
+ static setCensorship(censorship, permanent) {
289
+ if (!censorship && permanent) {
290
+ this.globalLogger().throwError("cannot permanently disable censorship", _Logger.errors.UNSUPPORTED_OPERATION, {
291
+ operation: "setCensorship"
292
+ });
293
+ }
294
+ if (_permanentCensorErrors) {
295
+ if (!censorship) {
296
+ return;
297
+ }
298
+ this.globalLogger().throwError("error censorship permanent", _Logger.errors.UNSUPPORTED_OPERATION, {
299
+ operation: "setCensorship"
300
+ });
301
+ }
302
+ _censorErrors = !!censorship;
303
+ _permanentCensorErrors = !!permanent;
304
+ }
305
+ static setLogLevel(logLevel) {
306
+ const level = LogLevels[logLevel.toLowerCase()];
307
+ if (level == null) {
308
+ _Logger.globalLogger().warn("invalid log level - " + logLevel);
309
+ return;
310
+ }
311
+ _logLevel = level;
312
+ }
313
+ static from(version3) {
314
+ return new _Logger(version3);
315
+ }
316
+ };
317
+ Logger.errors = ErrorCode;
318
+ Logger.levels = LogLevel;
319
+
320
+ // ../../../node_modules/.store/@ethersproject-bytes-npm-5.7.0-4454fe4cb0/package/lib.esm/_version.js
321
+ var version2 = "bytes/5.7.0";
322
+
323
+ // ../../../node_modules/.store/@ethersproject-bytes-npm-5.7.0-4454fe4cb0/package/lib.esm/index.js
324
+ var logger = new Logger(version2);
325
+ function isHexable(value) {
326
+ return !!value.toHexString;
327
+ }
328
+ function addSlice(array) {
329
+ if (array.slice) {
330
+ return array;
331
+ }
332
+ array.slice = function() {
333
+ const args = Array.prototype.slice.call(arguments);
334
+ return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
335
+ };
336
+ return array;
337
+ }
338
+ function isInteger(value) {
339
+ return typeof value === "number" && value == value && value % 1 === 0;
340
+ }
341
+ function isBytes(value) {
342
+ if (value == null) {
343
+ return false;
344
+ }
345
+ if (value.constructor === Uint8Array) {
346
+ return true;
347
+ }
348
+ if (typeof value === "string") {
349
+ return false;
350
+ }
351
+ if (!isInteger(value.length) || value.length < 0) {
352
+ return false;
353
+ }
354
+ for (let i = 0; i < value.length; i++) {
355
+ const v = value[i];
356
+ if (!isInteger(v) || v < 0 || v >= 256) {
357
+ return false;
358
+ }
359
+ }
360
+ return true;
361
+ }
362
+ function arrayify(value, options) {
363
+ if (!options) {
364
+ options = {};
365
+ }
366
+ if (typeof value === "number") {
367
+ logger.checkSafeUint53(value, "invalid arrayify value");
368
+ const result = [];
369
+ while (value) {
370
+ result.unshift(value & 255);
371
+ value = parseInt(String(value / 256));
372
+ }
373
+ if (result.length === 0) {
374
+ result.push(0);
375
+ }
376
+ return addSlice(new Uint8Array(result));
377
+ }
378
+ if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
379
+ value = "0x" + value;
380
+ }
381
+ if (isHexable(value)) {
382
+ value = value.toHexString();
383
+ }
384
+ if (isHexString(value)) {
385
+ let hex = value.substring(2);
386
+ if (hex.length % 2) {
387
+ if (options.hexPad === "left") {
388
+ hex = "0" + hex;
389
+ } else if (options.hexPad === "right") {
390
+ hex += "0";
391
+ } else {
392
+ logger.throwArgumentError("hex data is odd-length", "value", value);
393
+ }
394
+ }
395
+ const result = [];
396
+ for (let i = 0; i < hex.length; i += 2) {
397
+ result.push(parseInt(hex.substring(i, i + 2), 16));
398
+ }
399
+ return addSlice(new Uint8Array(result));
400
+ }
401
+ if (isBytes(value)) {
402
+ return addSlice(new Uint8Array(value));
403
+ }
404
+ return logger.throwArgumentError("invalid arrayify value", "value", value);
405
+ }
406
+ function isHexString(value, length) {
407
+ if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
408
+ return false;
409
+ }
410
+ if (length && value.length !== 2 + 2 * length) {
411
+ return false;
412
+ }
413
+ return true;
414
+ }
415
+
416
+ // src/utils.ts
417
+ function toRawTransaction(transaction) {
418
+ const retval = typeof transaction === "string" ? arrayify(transaction) : transaction.serialize();
419
+ return retval;
420
+ }
421
+
30
422
  // src/providers/solana.ts
31
423
  var SolanaProvider = class _SolanaProvider {
32
424
  constructor(url) {
@@ -102,14 +494,16 @@ var SolanaProvider = class _SolanaProvider {
102
494
  }
103
495
  async sendTransaction(transaction, sendOptions) {
104
496
  const _transaction = transaction.signed;
105
- const response = await this.nativeProvider.sendRawTransaction(Buffer.from(bytes.arrayify(_transaction)), sendOptions);
497
+ const rawTransaction = toRawTransaction(_transaction);
498
+ const response = await this.nativeProvider.sendRawTransaction(rawTransaction, sendOptions);
106
499
  return lzCore.TransactionPending.from(response);
107
500
  }
108
501
  async sendAndConfirm(transaction, opts) {
109
502
  const _transaction = transaction.signed;
503
+ const rawTransaction = toRawTransaction(_transaction);
110
504
  const response = await web3_js.sendAndConfirmRawTransaction(
111
505
  this.nativeProvider,
112
- Buffer.from(bytes.arrayify(_transaction)),
506
+ Buffer.from(rawTransaction),
113
507
  opts
114
508
  );
115
509
  return lzCore.TransactionReceipt.from(response);
@@ -185,42 +579,26 @@ var SolanaSigner = class {
185
579
  }
186
580
  async sendAndConfirm(transaction, opts) {
187
581
  const provider = this.assertAndGetProvider();
188
- const stx = bytes.arrayify(transaction.signed);
189
- const response = await web3_js.sendAndConfirmRawTransaction(provider, Buffer.from(stx), opts);
582
+ const _transaction = transaction.signed;
583
+ const rawTransaction = toRawTransaction(_transaction);
584
+ const response = await web3_js.sendAndConfirmRawTransaction(provider, Buffer.from(rawTransaction), opts);
190
585
  return lzCore.TransactionReceipt.from(response);
191
586
  }
192
587
  async sendTransaction(transaction, sendOptions) {
193
588
  const provider = this.assertAndGetProvider();
194
- const stx = bytes.arrayify(transaction.signed);
195
- const response = await provider.sendRawTransaction(stx, sendOptions);
589
+ const _transaction = transaction.signed;
590
+ const rawTransaction = toRawTransaction(_transaction);
591
+ const response = await provider.sendRawTransaction(rawTransaction, sendOptions);
196
592
  return lzCore.TransactionPending.from(response);
197
593
  }
198
594
  async signTransaction(transaction, opts) {
199
- const populatedTransaction = transaction.request;
200
- const provider = this.assertAndGetProvider();
201
- const tx = await this.buildTxByPopulatedTx(populatedTransaction, opts);
595
+ const tx = transaction.request;
202
596
  if (isVersionedTransaction(tx)) {
203
- if (populatedTransaction.signers) {
204
- tx.sign(populatedTransaction.signers);
205
- }
206
597
  tx.sign([this.keypair]);
207
598
  } else {
208
- tx.feePayer = tx.feePayer ?? this.publicKey;
209
- tx.recentBlockhash = (await provider.getLatestBlockhash(opts)).blockhash;
210
- if (populatedTransaction.signers) {
211
- for (const signer of populatedTransaction.signers) {
212
- tx.partialSign(signer);
213
- }
214
- }
215
- if (populatedTransaction.lzSingers) {
216
- for (const signer of populatedTransaction.lzSingers) {
217
- signer.partialSign(tx);
218
- }
219
- }
220
599
  tx.partialSign(this.keypair);
221
600
  }
222
- const response = bytes.hexlify(tx.serialize());
223
- return lzCore.SignedTransaction.from(response);
601
+ return Promise.resolve(lzCore.SignedTransaction.from(tx));
224
602
  }
225
603
  async signBuffer(_buffer) {
226
604
  await Promise.resolve();
@@ -233,17 +611,6 @@ var SolanaSigner = class {
233
611
  tx.partialSign(this.keypair);
234
612
  }
235
613
  }
236
- async buildTxByPopulatedTx(populatedTransaction, commitmentOrConfig) {
237
- const provider = this.assertAndGetProvider();
238
- const tx = new web3_js.VersionedTransaction(
239
- new web3_js.TransactionMessage({
240
- payerKey: this.publicKey,
241
- recentBlockhash: await provider.getLatestBlockhash(commitmentOrConfig).then((r) => r.blockhash),
242
- instructions: populatedTransaction.instructions
243
- }).compileToV0Message()
244
- );
245
- return tx;
246
- }
247
614
  assertAndGetProvider() {
248
615
  if (!this.provider) {
249
616
  throw new Error("Signer was not connected to a provider, did you forgot to connect to provider?");