@xchainjs/xchain-thorchain 0.28.10 → 0.28.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -4436,153 +4436,146 @@ function asPromise(fn, ctx/*, varargs */) {
4436
4436
 
4437
4437
  var base64$1 = {};
4438
4438
 
4439
- var hasRequiredBase64;
4440
-
4441
- function requireBase64 () {
4442
- if (hasRequiredBase64) return base64$1;
4443
- hasRequiredBase64 = 1;
4444
- (function (exports) {
4439
+ (function (exports) {
4445
4440
 
4446
- /**
4447
- * A minimal base64 implementation for number arrays.
4448
- * @memberof util
4449
- * @namespace
4450
- */
4451
- var base64 = exports;
4441
+ /**
4442
+ * A minimal base64 implementation for number arrays.
4443
+ * @memberof util
4444
+ * @namespace
4445
+ */
4446
+ var base64 = exports;
4452
4447
 
4453
- /**
4454
- * Calculates the byte length of a base64 encoded string.
4455
- * @param {string} string Base64 encoded string
4456
- * @returns {number} Byte length
4457
- */
4458
- base64.length = function length(string) {
4459
- var p = string.length;
4460
- if (!p)
4461
- return 0;
4462
- var n = 0;
4463
- while (--p % 4 > 1 && string.charAt(p) === "=")
4464
- ++n;
4465
- return Math.ceil(string.length * 3) / 4 - n;
4466
- };
4448
+ /**
4449
+ * Calculates the byte length of a base64 encoded string.
4450
+ * @param {string} string Base64 encoded string
4451
+ * @returns {number} Byte length
4452
+ */
4453
+ base64.length = function length(string) {
4454
+ var p = string.length;
4455
+ if (!p)
4456
+ return 0;
4457
+ var n = 0;
4458
+ while (--p % 4 > 1 && string.charAt(p) === "=")
4459
+ ++n;
4460
+ return Math.ceil(string.length * 3) / 4 - n;
4461
+ };
4467
4462
 
4468
- // Base64 encoding table
4469
- var b64 = new Array(64);
4463
+ // Base64 encoding table
4464
+ var b64 = new Array(64);
4470
4465
 
4471
- // Base64 decoding table
4472
- var s64 = new Array(123);
4466
+ // Base64 decoding table
4467
+ var s64 = new Array(123);
4473
4468
 
4474
- // 65..90, 97..122, 48..57, 43, 47
4475
- for (var i = 0; i < 64;)
4476
- s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4469
+ // 65..90, 97..122, 48..57, 43, 47
4470
+ for (var i = 0; i < 64;)
4471
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4477
4472
 
4478
- /**
4479
- * Encodes a buffer to a base64 encoded string.
4480
- * @param {Uint8Array} buffer Source buffer
4481
- * @param {number} start Source start
4482
- * @param {number} end Source end
4483
- * @returns {string} Base64 encoded string
4484
- */
4485
- base64.encode = function encode(buffer, start, end) {
4486
- var parts = null,
4487
- chunk = [];
4488
- var i = 0, // output index
4489
- j = 0, // goto index
4490
- t; // temporary
4491
- while (start < end) {
4492
- var b = buffer[start++];
4493
- switch (j) {
4494
- case 0:
4495
- chunk[i++] = b64[b >> 2];
4496
- t = (b & 3) << 4;
4497
- j = 1;
4498
- break;
4499
- case 1:
4500
- chunk[i++] = b64[t | b >> 4];
4501
- t = (b & 15) << 2;
4502
- j = 2;
4503
- break;
4504
- case 2:
4505
- chunk[i++] = b64[t | b >> 6];
4506
- chunk[i++] = b64[b & 63];
4507
- j = 0;
4508
- break;
4509
- }
4510
- if (i > 8191) {
4511
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4512
- i = 0;
4513
- }
4514
- }
4515
- if (j) {
4516
- chunk[i++] = b64[t];
4517
- chunk[i++] = 61;
4518
- if (j === 1)
4519
- chunk[i++] = 61;
4520
- }
4521
- if (parts) {
4522
- if (i)
4523
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4524
- return parts.join("");
4525
- }
4526
- return String.fromCharCode.apply(String, chunk.slice(0, i));
4527
- };
4473
+ /**
4474
+ * Encodes a buffer to a base64 encoded string.
4475
+ * @param {Uint8Array} buffer Source buffer
4476
+ * @param {number} start Source start
4477
+ * @param {number} end Source end
4478
+ * @returns {string} Base64 encoded string
4479
+ */
4480
+ base64.encode = function encode(buffer, start, end) {
4481
+ var parts = null,
4482
+ chunk = [];
4483
+ var i = 0, // output index
4484
+ j = 0, // goto index
4485
+ t; // temporary
4486
+ while (start < end) {
4487
+ var b = buffer[start++];
4488
+ switch (j) {
4489
+ case 0:
4490
+ chunk[i++] = b64[b >> 2];
4491
+ t = (b & 3) << 4;
4492
+ j = 1;
4493
+ break;
4494
+ case 1:
4495
+ chunk[i++] = b64[t | b >> 4];
4496
+ t = (b & 15) << 2;
4497
+ j = 2;
4498
+ break;
4499
+ case 2:
4500
+ chunk[i++] = b64[t | b >> 6];
4501
+ chunk[i++] = b64[b & 63];
4502
+ j = 0;
4503
+ break;
4504
+ }
4505
+ if (i > 8191) {
4506
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4507
+ i = 0;
4508
+ }
4509
+ }
4510
+ if (j) {
4511
+ chunk[i++] = b64[t];
4512
+ chunk[i++] = 61;
4513
+ if (j === 1)
4514
+ chunk[i++] = 61;
4515
+ }
4516
+ if (parts) {
4517
+ if (i)
4518
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4519
+ return parts.join("");
4520
+ }
4521
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
4522
+ };
4528
4523
 
4529
- var invalidEncoding = "invalid encoding";
4524
+ var invalidEncoding = "invalid encoding";
4530
4525
 
4531
- /**
4532
- * Decodes a base64 encoded string to a buffer.
4533
- * @param {string} string Source string
4534
- * @param {Uint8Array} buffer Destination buffer
4535
- * @param {number} offset Destination offset
4536
- * @returns {number} Number of bytes written
4537
- * @throws {Error} If encoding is invalid
4538
- */
4539
- base64.decode = function decode(string, buffer, offset) {
4540
- var start = offset;
4541
- var j = 0, // goto index
4542
- t; // temporary
4543
- for (var i = 0; i < string.length;) {
4544
- var c = string.charCodeAt(i++);
4545
- if (c === 61 && j > 1)
4546
- break;
4547
- if ((c = s64[c]) === undefined)
4548
- throw Error(invalidEncoding);
4549
- switch (j) {
4550
- case 0:
4551
- t = c;
4552
- j = 1;
4553
- break;
4554
- case 1:
4555
- buffer[offset++] = t << 2 | (c & 48) >> 4;
4556
- t = c;
4557
- j = 2;
4558
- break;
4559
- case 2:
4560
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4561
- t = c;
4562
- j = 3;
4563
- break;
4564
- case 3:
4565
- buffer[offset++] = (t & 3) << 6 | c;
4566
- j = 0;
4567
- break;
4568
- }
4569
- }
4570
- if (j === 1)
4571
- throw Error(invalidEncoding);
4572
- return offset - start;
4573
- };
4526
+ /**
4527
+ * Decodes a base64 encoded string to a buffer.
4528
+ * @param {string} string Source string
4529
+ * @param {Uint8Array} buffer Destination buffer
4530
+ * @param {number} offset Destination offset
4531
+ * @returns {number} Number of bytes written
4532
+ * @throws {Error} If encoding is invalid
4533
+ */
4534
+ base64.decode = function decode(string, buffer, offset) {
4535
+ var start = offset;
4536
+ var j = 0, // goto index
4537
+ t; // temporary
4538
+ for (var i = 0; i < string.length;) {
4539
+ var c = string.charCodeAt(i++);
4540
+ if (c === 61 && j > 1)
4541
+ break;
4542
+ if ((c = s64[c]) === undefined)
4543
+ throw Error(invalidEncoding);
4544
+ switch (j) {
4545
+ case 0:
4546
+ t = c;
4547
+ j = 1;
4548
+ break;
4549
+ case 1:
4550
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
4551
+ t = c;
4552
+ j = 2;
4553
+ break;
4554
+ case 2:
4555
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4556
+ t = c;
4557
+ j = 3;
4558
+ break;
4559
+ case 3:
4560
+ buffer[offset++] = (t & 3) << 6 | c;
4561
+ j = 0;
4562
+ break;
4563
+ }
4564
+ }
4565
+ if (j === 1)
4566
+ throw Error(invalidEncoding);
4567
+ return offset - start;
4568
+ };
4574
4569
 
4575
- /**
4576
- * Tests if the specified string appears to be base64 encoded.
4577
- * @param {string} string String to test
4578
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
4579
- */
4580
- base64.test = function test(string) {
4581
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4582
- };
4583
- } (base64$1));
4584
- return base64$1;
4585
- }
4570
+ /**
4571
+ * Tests if the specified string appears to be base64 encoded.
4572
+ * @param {string} string String to test
4573
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
4574
+ */
4575
+ base64.test = function test(string) {
4576
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4577
+ };
4578
+ } (base64$1));
4586
4579
 
4587
4580
  var eventemitter;
4588
4581
  var hasRequiredEventemitter;
@@ -5011,21 +5004,29 @@ function requireFloat () {
5011
5004
  return float;
5012
5005
  }
5013
5006
 
5014
- var inquire_1 = inquire;
5007
+ var inquire_1;
5008
+ var hasRequiredInquire;
5009
+
5010
+ function requireInquire () {
5011
+ if (hasRequiredInquire) return inquire_1;
5012
+ hasRequiredInquire = 1;
5013
+ inquire_1 = inquire;
5015
5014
 
5016
- /**
5017
- * Requires a module only if available.
5018
- * @memberof util
5019
- * @param {string} moduleName Module to require
5020
- * @returns {?Object} Required module if available and not empty, otherwise `null`
5021
- */
5022
- function inquire(moduleName) {
5023
- try {
5024
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
5025
- if (mod && (mod.length || Object.keys(mod).length))
5026
- return mod;
5027
- } catch (e) {} // eslint-disable-line no-empty
5028
- return null;
5015
+ /**
5016
+ * Requires a module only if available.
5017
+ * @memberof util
5018
+ * @param {string} moduleName Module to require
5019
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
5020
+ */
5021
+ function inquire(moduleName) {
5022
+ try {
5023
+ var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
5024
+ if (mod && (mod.length || Object.keys(mod).length))
5025
+ return mod;
5026
+ } catch (e) {} // eslint-disable-line no-empty
5027
+ return null;
5028
+ }
5029
+ return inquire_1;
5029
5030
  }
5030
5031
 
5031
5032
  var utf8$2 = {};
@@ -5144,60 +5145,52 @@ function requireUtf8 () {
5144
5145
  return utf8$2;
5145
5146
  }
5146
5147
 
5147
- var pool_1;
5148
- var hasRequiredPool;
5149
-
5150
- function requirePool () {
5151
- if (hasRequiredPool) return pool_1;
5152
- hasRequiredPool = 1;
5153
- pool_1 = pool;
5148
+ var pool_1 = pool;
5154
5149
 
5155
- /**
5156
- * An allocator as used by {@link util.pool}.
5157
- * @typedef PoolAllocator
5158
- * @type {function}
5159
- * @param {number} size Buffer size
5160
- * @returns {Uint8Array} Buffer
5161
- */
5150
+ /**
5151
+ * An allocator as used by {@link util.pool}.
5152
+ * @typedef PoolAllocator
5153
+ * @type {function}
5154
+ * @param {number} size Buffer size
5155
+ * @returns {Uint8Array} Buffer
5156
+ */
5162
5157
 
5163
- /**
5164
- * A slicer as used by {@link util.pool}.
5165
- * @typedef PoolSlicer
5166
- * @type {function}
5167
- * @param {number} start Start offset
5168
- * @param {number} end End offset
5169
- * @returns {Uint8Array} Buffer slice
5170
- * @this {Uint8Array}
5171
- */
5158
+ /**
5159
+ * A slicer as used by {@link util.pool}.
5160
+ * @typedef PoolSlicer
5161
+ * @type {function}
5162
+ * @param {number} start Start offset
5163
+ * @param {number} end End offset
5164
+ * @returns {Uint8Array} Buffer slice
5165
+ * @this {Uint8Array}
5166
+ */
5172
5167
 
5173
- /**
5174
- * A general purpose buffer pool.
5175
- * @memberof util
5176
- * @function
5177
- * @param {PoolAllocator} alloc Allocator
5178
- * @param {PoolSlicer} slice Slicer
5179
- * @param {number} [size=8192] Slab size
5180
- * @returns {PoolAllocator} Pooled allocator
5181
- */
5182
- function pool(alloc, slice, size) {
5183
- var SIZE = size || 8192;
5184
- var MAX = SIZE >>> 1;
5185
- var slab = null;
5186
- var offset = SIZE;
5187
- return function pool_alloc(size) {
5188
- if (size < 1 || size > MAX)
5189
- return alloc(size);
5190
- if (offset + size > SIZE) {
5191
- slab = alloc(SIZE);
5192
- offset = 0;
5193
- }
5194
- var buf = slice.call(slab, offset, offset += size);
5195
- if (offset & 7) // align to 32 bit
5196
- offset = (offset | 7) + 1;
5197
- return buf;
5198
- };
5199
- }
5200
- return pool_1;
5168
+ /**
5169
+ * A general purpose buffer pool.
5170
+ * @memberof util
5171
+ * @function
5172
+ * @param {PoolAllocator} alloc Allocator
5173
+ * @param {PoolSlicer} slice Slicer
5174
+ * @param {number} [size=8192] Slab size
5175
+ * @returns {PoolAllocator} Pooled allocator
5176
+ */
5177
+ function pool(alloc, slice, size) {
5178
+ var SIZE = size || 8192;
5179
+ var MAX = SIZE >>> 1;
5180
+ var slab = null;
5181
+ var offset = SIZE;
5182
+ return function pool_alloc(size) {
5183
+ if (size < 1 || size > MAX)
5184
+ return alloc(size);
5185
+ if (offset + size > SIZE) {
5186
+ slab = alloc(SIZE);
5187
+ offset = 0;
5188
+ }
5189
+ var buf = slice.call(slab, offset, offset += size);
5190
+ if (offset & 7) // align to 32 bit
5191
+ offset = (offset | 7) + 1;
5192
+ return buf;
5193
+ };
5201
5194
  }
5202
5195
 
5203
5196
  var longbits;
@@ -5420,7 +5413,7 @@ function requireMinimal () {
5420
5413
  util.asPromise = aspromise;
5421
5414
 
5422
5415
  // converts to / from base64 encoded strings
5423
- util.base64 = requireBase64();
5416
+ util.base64 = base64$1;
5424
5417
 
5425
5418
  // base class of rpc.Service
5426
5419
  util.EventEmitter = requireEventemitter();
@@ -5429,13 +5422,13 @@ function requireMinimal () {
5429
5422
  util.float = requireFloat();
5430
5423
 
5431
5424
  // requires modules optionally and hides the call from bundlers
5432
- util.inquire = inquire_1;
5425
+ util.inquire = requireInquire();
5433
5426
 
5434
5427
  // converts to / from utf8 encoded strings
5435
5428
  util.utf8 = requireUtf8();
5436
5429
 
5437
5430
  // provides a node-like buffer pool in the browser
5438
- util.pool = requirePool();
5431
+ util.pool = pool_1;
5439
5432
 
5440
5433
  // utility to work with the low and high bits of a 64 bit value
5441
5434
  util.LongBits = requireLongbits();
@@ -10168,7 +10161,7 @@ class Client extends xchainClient.BaseXChainClient {
10168
10161
  const messageAction = undefined;
10169
10162
  const offset = (params === null || params === void 0 ? void 0 : params.offset) || 0;
10170
10163
  const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
10171
- const address = (params === null || params === void 0 ? void 0 : params.address) || this.getAddress();
10164
+ const address = (params === null || params === void 0 ? void 0 : params.address) || (yield this.getAddressAsync());
10172
10165
  const txMinHeight = undefined;
10173
10166
  const txMaxHeight = undefined;
10174
10167
  if (limit + offset > MAX_PAGES_PER_FUNCTION_CALL * MAX_TX_COUNT_PER_PAGE) {
@@ -10374,11 +10367,7 @@ class Client extends xchainClient.BaseXChainClient {
10374
10367
  return privKey.pubKey();
10375
10368
  }
10376
10369
  /**
10377
- * Get the current address.
10378
- *
10379
- * @returns {Address} The current address.
10380
- *
10381
- * @throws {Error} Thrown if phrase has not been set before. A phrase is needed to create a wallet and to derive an address from it.
10370
+ * @deprecated this function eventually will be removed use getAddressAsync instead
10382
10371
  */
10383
10372
  getAddress(index = 0) {
10384
10373
  const address = this.cosmosClient.getAddressFromMnemonic(this.phrase, this.getFullDerivationPath(index));
@@ -10387,6 +10376,18 @@ class Client extends xchainClient.BaseXChainClient {
10387
10376
  }
10388
10377
  return address;
10389
10378
  }
10379
+ /**
10380
+ * Get the current address.
10381
+ *
10382
+ * @returns {Address} The current address.
10383
+ *
10384
+ * @throws {Error} Thrown if phrase has not been set before. A phrase is needed to create a wallet and to derive an address from it.
10385
+ */
10386
+ getAddressAsync(walletIndex = 0) {
10387
+ return __awaiter(this, void 0, void 0, function* () {
10388
+ return this.getAddress(walletIndex);
10389
+ });
10390
+ }
10390
10391
  /**
10391
10392
  * Validate the given address.
10392
10393
  *
@@ -10432,21 +10433,19 @@ class Client extends xchainClient.BaseXChainClient {
10432
10433
  }
10433
10434
  catch (error) {
10434
10435
  for (const fallback of FallBackUrls) {
10435
- for (const network of Object.keys(fallback)) {
10436
- try {
10437
- const networkObj = fallback[network];
10438
- const clientUrl = networkObj.node;
10439
- const cosmosClient = new xchainCosmos.CosmosSDKClient({
10440
- server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10441
- chainId: this.getChainId(network),
10442
- prefix: getPrefix(network),
10443
- });
10444
- const tx = yield cosmosClient.txsHashGet(txId);
10445
- return tx;
10446
- }
10447
- catch (error) {
10448
- // Handle specific error if needed
10449
- }
10436
+ try {
10437
+ const networkObj = fallback[this.network];
10438
+ const clientUrl = networkObj.node;
10439
+ const cosmosClient = new xchainCosmos.CosmosSDKClient({
10440
+ server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10441
+ chainId: this.getChainId(this.network),
10442
+ prefix: getPrefix(this.network),
10443
+ });
10444
+ const tx = yield cosmosClient.txsHashGet(txId);
10445
+ return tx;
10446
+ }
10447
+ catch (error) {
10448
+ // Handle specific error if needed
10450
10449
  }
10451
10450
  }
10452
10451
  return null;
@@ -10672,7 +10671,7 @@ class Client extends xchainClient.BaseXChainClient {
10672
10671
  }
10673
10672
  const privKey = this.getPrivateKey(walletIndex);
10674
10673
  const signerPubkey = privKey.pubKey();
10675
- const fromAddress = this.getAddress(walletIndex);
10674
+ const fromAddress = yield this.getAddressAsync(walletIndex);
10676
10675
  const fromAddressAcc = cosmosclient__default["default"].AccAddress.fromString(fromAddress);
10677
10676
  const depositTxBody = yield buildDepositTx({
10678
10677
  msgNativeTx: {
@@ -10787,7 +10786,7 @@ class Client extends xchainClient.BaseXChainClient {
10787
10786
  }
10788
10787
  }
10789
10788
  const txBody = yield buildTransferTx({
10790
- fromAddress: this.getAddress(walletIndex),
10789
+ fromAddress: yield this.getAddressAsync(walletIndex),
10791
10790
  toAddress: recipient,
10792
10791
  memo,
10793
10792
  assetAmount: amount,