@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/client.d.ts CHANGED
@@ -127,6 +127,10 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
127
127
  * Throws an error if phrase has not been set before
128
128
  **/
129
129
  getPubKey(index?: number): cosmosclient.PubKey;
130
+ /**
131
+ * @deprecated this function eventually will be removed use getAddressAsync instead
132
+ */
133
+ getAddress(index?: number): string;
130
134
  /**
131
135
  * Get the current address.
132
136
  *
@@ -134,7 +138,7 @@ declare class Client extends BaseXChainClient implements ThorchainClient, XChain
134
138
  *
135
139
  * @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.
136
140
  */
137
- getAddress(index?: number): string;
141
+ getAddressAsync(walletIndex?: number): Promise<Address>;
138
142
  /**
139
143
  * Validate the given address.
140
144
  *
package/lib/index.esm.js CHANGED
@@ -4408,153 +4408,146 @@ function asPromise(fn, ctx/*, varargs */) {
4408
4408
 
4409
4409
  var base64$1 = {};
4410
4410
 
4411
- var hasRequiredBase64;
4412
-
4413
- function requireBase64 () {
4414
- if (hasRequiredBase64) return base64$1;
4415
- hasRequiredBase64 = 1;
4416
- (function (exports) {
4411
+ (function (exports) {
4417
4412
 
4418
- /**
4419
- * A minimal base64 implementation for number arrays.
4420
- * @memberof util
4421
- * @namespace
4422
- */
4423
- var base64 = exports;
4413
+ /**
4414
+ * A minimal base64 implementation for number arrays.
4415
+ * @memberof util
4416
+ * @namespace
4417
+ */
4418
+ var base64 = exports;
4424
4419
 
4425
- /**
4426
- * Calculates the byte length of a base64 encoded string.
4427
- * @param {string} string Base64 encoded string
4428
- * @returns {number} Byte length
4429
- */
4430
- base64.length = function length(string) {
4431
- var p = string.length;
4432
- if (!p)
4433
- return 0;
4434
- var n = 0;
4435
- while (--p % 4 > 1 && string.charAt(p) === "=")
4436
- ++n;
4437
- return Math.ceil(string.length * 3) / 4 - n;
4438
- };
4420
+ /**
4421
+ * Calculates the byte length of a base64 encoded string.
4422
+ * @param {string} string Base64 encoded string
4423
+ * @returns {number} Byte length
4424
+ */
4425
+ base64.length = function length(string) {
4426
+ var p = string.length;
4427
+ if (!p)
4428
+ return 0;
4429
+ var n = 0;
4430
+ while (--p % 4 > 1 && string.charAt(p) === "=")
4431
+ ++n;
4432
+ return Math.ceil(string.length * 3) / 4 - n;
4433
+ };
4439
4434
 
4440
- // Base64 encoding table
4441
- var b64 = new Array(64);
4435
+ // Base64 encoding table
4436
+ var b64 = new Array(64);
4442
4437
 
4443
- // Base64 decoding table
4444
- var s64 = new Array(123);
4438
+ // Base64 decoding table
4439
+ var s64 = new Array(123);
4445
4440
 
4446
- // 65..90, 97..122, 48..57, 43, 47
4447
- for (var i = 0; i < 64;)
4448
- s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4441
+ // 65..90, 97..122, 48..57, 43, 47
4442
+ for (var i = 0; i < 64;)
4443
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
4449
4444
 
4450
- /**
4451
- * Encodes a buffer to a base64 encoded string.
4452
- * @param {Uint8Array} buffer Source buffer
4453
- * @param {number} start Source start
4454
- * @param {number} end Source end
4455
- * @returns {string} Base64 encoded string
4456
- */
4457
- base64.encode = function encode(buffer, start, end) {
4458
- var parts = null,
4459
- chunk = [];
4460
- var i = 0, // output index
4461
- j = 0, // goto index
4462
- t; // temporary
4463
- while (start < end) {
4464
- var b = buffer[start++];
4465
- switch (j) {
4466
- case 0:
4467
- chunk[i++] = b64[b >> 2];
4468
- t = (b & 3) << 4;
4469
- j = 1;
4470
- break;
4471
- case 1:
4472
- chunk[i++] = b64[t | b >> 4];
4473
- t = (b & 15) << 2;
4474
- j = 2;
4475
- break;
4476
- case 2:
4477
- chunk[i++] = b64[t | b >> 6];
4478
- chunk[i++] = b64[b & 63];
4479
- j = 0;
4480
- break;
4481
- }
4482
- if (i > 8191) {
4483
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4484
- i = 0;
4485
- }
4486
- }
4487
- if (j) {
4488
- chunk[i++] = b64[t];
4489
- chunk[i++] = 61;
4490
- if (j === 1)
4491
- chunk[i++] = 61;
4492
- }
4493
- if (parts) {
4494
- if (i)
4495
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4496
- return parts.join("");
4497
- }
4498
- return String.fromCharCode.apply(String, chunk.slice(0, i));
4499
- };
4445
+ /**
4446
+ * Encodes a buffer to a base64 encoded string.
4447
+ * @param {Uint8Array} buffer Source buffer
4448
+ * @param {number} start Source start
4449
+ * @param {number} end Source end
4450
+ * @returns {string} Base64 encoded string
4451
+ */
4452
+ base64.encode = function encode(buffer, start, end) {
4453
+ var parts = null,
4454
+ chunk = [];
4455
+ var i = 0, // output index
4456
+ j = 0, // goto index
4457
+ t; // temporary
4458
+ while (start < end) {
4459
+ var b = buffer[start++];
4460
+ switch (j) {
4461
+ case 0:
4462
+ chunk[i++] = b64[b >> 2];
4463
+ t = (b & 3) << 4;
4464
+ j = 1;
4465
+ break;
4466
+ case 1:
4467
+ chunk[i++] = b64[t | b >> 4];
4468
+ t = (b & 15) << 2;
4469
+ j = 2;
4470
+ break;
4471
+ case 2:
4472
+ chunk[i++] = b64[t | b >> 6];
4473
+ chunk[i++] = b64[b & 63];
4474
+ j = 0;
4475
+ break;
4476
+ }
4477
+ if (i > 8191) {
4478
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4479
+ i = 0;
4480
+ }
4481
+ }
4482
+ if (j) {
4483
+ chunk[i++] = b64[t];
4484
+ chunk[i++] = 61;
4485
+ if (j === 1)
4486
+ chunk[i++] = 61;
4487
+ }
4488
+ if (parts) {
4489
+ if (i)
4490
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4491
+ return parts.join("");
4492
+ }
4493
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
4494
+ };
4500
4495
 
4501
- var invalidEncoding = "invalid encoding";
4496
+ var invalidEncoding = "invalid encoding";
4502
4497
 
4503
- /**
4504
- * Decodes a base64 encoded string to a buffer.
4505
- * @param {string} string Source string
4506
- * @param {Uint8Array} buffer Destination buffer
4507
- * @param {number} offset Destination offset
4508
- * @returns {number} Number of bytes written
4509
- * @throws {Error} If encoding is invalid
4510
- */
4511
- base64.decode = function decode(string, buffer, offset) {
4512
- var start = offset;
4513
- var j = 0, // goto index
4514
- t; // temporary
4515
- for (var i = 0; i < string.length;) {
4516
- var c = string.charCodeAt(i++);
4517
- if (c === 61 && j > 1)
4518
- break;
4519
- if ((c = s64[c]) === undefined)
4520
- throw Error(invalidEncoding);
4521
- switch (j) {
4522
- case 0:
4523
- t = c;
4524
- j = 1;
4525
- break;
4526
- case 1:
4527
- buffer[offset++] = t << 2 | (c & 48) >> 4;
4528
- t = c;
4529
- j = 2;
4530
- break;
4531
- case 2:
4532
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4533
- t = c;
4534
- j = 3;
4535
- break;
4536
- case 3:
4537
- buffer[offset++] = (t & 3) << 6 | c;
4538
- j = 0;
4539
- break;
4540
- }
4541
- }
4542
- if (j === 1)
4543
- throw Error(invalidEncoding);
4544
- return offset - start;
4545
- };
4498
+ /**
4499
+ * Decodes a base64 encoded string to a buffer.
4500
+ * @param {string} string Source string
4501
+ * @param {Uint8Array} buffer Destination buffer
4502
+ * @param {number} offset Destination offset
4503
+ * @returns {number} Number of bytes written
4504
+ * @throws {Error} If encoding is invalid
4505
+ */
4506
+ base64.decode = function decode(string, buffer, offset) {
4507
+ var start = offset;
4508
+ var j = 0, // goto index
4509
+ t; // temporary
4510
+ for (var i = 0; i < string.length;) {
4511
+ var c = string.charCodeAt(i++);
4512
+ if (c === 61 && j > 1)
4513
+ break;
4514
+ if ((c = s64[c]) === undefined)
4515
+ throw Error(invalidEncoding);
4516
+ switch (j) {
4517
+ case 0:
4518
+ t = c;
4519
+ j = 1;
4520
+ break;
4521
+ case 1:
4522
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
4523
+ t = c;
4524
+ j = 2;
4525
+ break;
4526
+ case 2:
4527
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4528
+ t = c;
4529
+ j = 3;
4530
+ break;
4531
+ case 3:
4532
+ buffer[offset++] = (t & 3) << 6 | c;
4533
+ j = 0;
4534
+ break;
4535
+ }
4536
+ }
4537
+ if (j === 1)
4538
+ throw Error(invalidEncoding);
4539
+ return offset - start;
4540
+ };
4546
4541
 
4547
- /**
4548
- * Tests if the specified string appears to be base64 encoded.
4549
- * @param {string} string String to test
4550
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
4551
- */
4552
- base64.test = function test(string) {
4553
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4554
- };
4555
- } (base64$1));
4556
- return base64$1;
4557
- }
4542
+ /**
4543
+ * Tests if the specified string appears to be base64 encoded.
4544
+ * @param {string} string String to test
4545
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
4546
+ */
4547
+ base64.test = function test(string) {
4548
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4549
+ };
4550
+ } (base64$1));
4558
4551
 
4559
4552
  var eventemitter;
4560
4553
  var hasRequiredEventemitter;
@@ -4983,21 +4976,29 @@ function requireFloat () {
4983
4976
  return float;
4984
4977
  }
4985
4978
 
4986
- var inquire_1 = inquire;
4979
+ var inquire_1;
4980
+ var hasRequiredInquire;
4981
+
4982
+ function requireInquire () {
4983
+ if (hasRequiredInquire) return inquire_1;
4984
+ hasRequiredInquire = 1;
4985
+ inquire_1 = inquire;
4987
4986
 
4988
- /**
4989
- * Requires a module only if available.
4990
- * @memberof util
4991
- * @param {string} moduleName Module to require
4992
- * @returns {?Object} Required module if available and not empty, otherwise `null`
4993
- */
4994
- function inquire(moduleName) {
4995
- try {
4996
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
4997
- if (mod && (mod.length || Object.keys(mod).length))
4998
- return mod;
4999
- } catch (e) {} // eslint-disable-line no-empty
5000
- return null;
4987
+ /**
4988
+ * Requires a module only if available.
4989
+ * @memberof util
4990
+ * @param {string} moduleName Module to require
4991
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
4992
+ */
4993
+ function inquire(moduleName) {
4994
+ try {
4995
+ var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
4996
+ if (mod && (mod.length || Object.keys(mod).length))
4997
+ return mod;
4998
+ } catch (e) {} // eslint-disable-line no-empty
4999
+ return null;
5000
+ }
5001
+ return inquire_1;
5001
5002
  }
5002
5003
 
5003
5004
  var utf8$2 = {};
@@ -5116,60 +5117,52 @@ function requireUtf8 () {
5116
5117
  return utf8$2;
5117
5118
  }
5118
5119
 
5119
- var pool_1;
5120
- var hasRequiredPool;
5121
-
5122
- function requirePool () {
5123
- if (hasRequiredPool) return pool_1;
5124
- hasRequiredPool = 1;
5125
- pool_1 = pool;
5120
+ var pool_1 = pool;
5126
5121
 
5127
- /**
5128
- * An allocator as used by {@link util.pool}.
5129
- * @typedef PoolAllocator
5130
- * @type {function}
5131
- * @param {number} size Buffer size
5132
- * @returns {Uint8Array} Buffer
5133
- */
5122
+ /**
5123
+ * An allocator as used by {@link util.pool}.
5124
+ * @typedef PoolAllocator
5125
+ * @type {function}
5126
+ * @param {number} size Buffer size
5127
+ * @returns {Uint8Array} Buffer
5128
+ */
5134
5129
 
5135
- /**
5136
- * A slicer as used by {@link util.pool}.
5137
- * @typedef PoolSlicer
5138
- * @type {function}
5139
- * @param {number} start Start offset
5140
- * @param {number} end End offset
5141
- * @returns {Uint8Array} Buffer slice
5142
- * @this {Uint8Array}
5143
- */
5130
+ /**
5131
+ * A slicer as used by {@link util.pool}.
5132
+ * @typedef PoolSlicer
5133
+ * @type {function}
5134
+ * @param {number} start Start offset
5135
+ * @param {number} end End offset
5136
+ * @returns {Uint8Array} Buffer slice
5137
+ * @this {Uint8Array}
5138
+ */
5144
5139
 
5145
- /**
5146
- * A general purpose buffer pool.
5147
- * @memberof util
5148
- * @function
5149
- * @param {PoolAllocator} alloc Allocator
5150
- * @param {PoolSlicer} slice Slicer
5151
- * @param {number} [size=8192] Slab size
5152
- * @returns {PoolAllocator} Pooled allocator
5153
- */
5154
- function pool(alloc, slice, size) {
5155
- var SIZE = size || 8192;
5156
- var MAX = SIZE >>> 1;
5157
- var slab = null;
5158
- var offset = SIZE;
5159
- return function pool_alloc(size) {
5160
- if (size < 1 || size > MAX)
5161
- return alloc(size);
5162
- if (offset + size > SIZE) {
5163
- slab = alloc(SIZE);
5164
- offset = 0;
5165
- }
5166
- var buf = slice.call(slab, offset, offset += size);
5167
- if (offset & 7) // align to 32 bit
5168
- offset = (offset | 7) + 1;
5169
- return buf;
5170
- };
5171
- }
5172
- return pool_1;
5140
+ /**
5141
+ * A general purpose buffer pool.
5142
+ * @memberof util
5143
+ * @function
5144
+ * @param {PoolAllocator} alloc Allocator
5145
+ * @param {PoolSlicer} slice Slicer
5146
+ * @param {number} [size=8192] Slab size
5147
+ * @returns {PoolAllocator} Pooled allocator
5148
+ */
5149
+ function pool(alloc, slice, size) {
5150
+ var SIZE = size || 8192;
5151
+ var MAX = SIZE >>> 1;
5152
+ var slab = null;
5153
+ var offset = SIZE;
5154
+ return function pool_alloc(size) {
5155
+ if (size < 1 || size > MAX)
5156
+ return alloc(size);
5157
+ if (offset + size > SIZE) {
5158
+ slab = alloc(SIZE);
5159
+ offset = 0;
5160
+ }
5161
+ var buf = slice.call(slab, offset, offset += size);
5162
+ if (offset & 7) // align to 32 bit
5163
+ offset = (offset | 7) + 1;
5164
+ return buf;
5165
+ };
5173
5166
  }
5174
5167
 
5175
5168
  var longbits;
@@ -5392,7 +5385,7 @@ function requireMinimal () {
5392
5385
  util.asPromise = aspromise;
5393
5386
 
5394
5387
  // converts to / from base64 encoded strings
5395
- util.base64 = requireBase64();
5388
+ util.base64 = base64$1;
5396
5389
 
5397
5390
  // base class of rpc.Service
5398
5391
  util.EventEmitter = requireEventemitter();
@@ -5401,13 +5394,13 @@ function requireMinimal () {
5401
5394
  util.float = requireFloat();
5402
5395
 
5403
5396
  // requires modules optionally and hides the call from bundlers
5404
- util.inquire = inquire_1;
5397
+ util.inquire = requireInquire();
5405
5398
 
5406
5399
  // converts to / from utf8 encoded strings
5407
5400
  util.utf8 = requireUtf8();
5408
5401
 
5409
5402
  // provides a node-like buffer pool in the browser
5410
- util.pool = requirePool();
5403
+ util.pool = pool_1;
5411
5404
 
5412
5405
  // utility to work with the low and high bits of a 64 bit value
5413
5406
  util.LongBits = requireLongbits();
@@ -10140,7 +10133,7 @@ class Client extends BaseXChainClient {
10140
10133
  const messageAction = undefined;
10141
10134
  const offset = (params === null || params === void 0 ? void 0 : params.offset) || 0;
10142
10135
  const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
10143
- const address = (params === null || params === void 0 ? void 0 : params.address) || this.getAddress();
10136
+ const address = (params === null || params === void 0 ? void 0 : params.address) || (yield this.getAddressAsync());
10144
10137
  const txMinHeight = undefined;
10145
10138
  const txMaxHeight = undefined;
10146
10139
  if (limit + offset > MAX_PAGES_PER_FUNCTION_CALL * MAX_TX_COUNT_PER_PAGE) {
@@ -10346,11 +10339,7 @@ class Client extends BaseXChainClient {
10346
10339
  return privKey.pubKey();
10347
10340
  }
10348
10341
  /**
10349
- * Get the current address.
10350
- *
10351
- * @returns {Address} The current address.
10352
- *
10353
- * @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.
10342
+ * @deprecated this function eventually will be removed use getAddressAsync instead
10354
10343
  */
10355
10344
  getAddress(index = 0) {
10356
10345
  const address = this.cosmosClient.getAddressFromMnemonic(this.phrase, this.getFullDerivationPath(index));
@@ -10359,6 +10348,18 @@ class Client extends BaseXChainClient {
10359
10348
  }
10360
10349
  return address;
10361
10350
  }
10351
+ /**
10352
+ * Get the current address.
10353
+ *
10354
+ * @returns {Address} The current address.
10355
+ *
10356
+ * @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.
10357
+ */
10358
+ getAddressAsync(walletIndex = 0) {
10359
+ return __awaiter(this, void 0, void 0, function* () {
10360
+ return this.getAddress(walletIndex);
10361
+ });
10362
+ }
10362
10363
  /**
10363
10364
  * Validate the given address.
10364
10365
  *
@@ -10404,21 +10405,19 @@ class Client extends BaseXChainClient {
10404
10405
  }
10405
10406
  catch (error) {
10406
10407
  for (const fallback of FallBackUrls) {
10407
- for (const network of Object.keys(fallback)) {
10408
- try {
10409
- const networkObj = fallback[network];
10410
- const clientUrl = networkObj.node;
10411
- const cosmosClient = new CosmosSDKClient({
10412
- server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10413
- chainId: this.getChainId(network),
10414
- prefix: getPrefix(network),
10415
- });
10416
- const tx = yield cosmosClient.txsHashGet(txId);
10417
- return tx;
10418
- }
10419
- catch (error) {
10420
- // Handle specific error if needed
10421
- }
10408
+ try {
10409
+ const networkObj = fallback[this.network];
10410
+ const clientUrl = networkObj.node;
10411
+ const cosmosClient = new CosmosSDKClient({
10412
+ server: Array.isArray(clientUrl) ? clientUrl[0] : clientUrl,
10413
+ chainId: this.getChainId(this.network),
10414
+ prefix: getPrefix(this.network),
10415
+ });
10416
+ const tx = yield cosmosClient.txsHashGet(txId);
10417
+ return tx;
10418
+ }
10419
+ catch (error) {
10420
+ // Handle specific error if needed
10422
10421
  }
10423
10422
  }
10424
10423
  return null;
@@ -10644,7 +10643,7 @@ class Client extends BaseXChainClient {
10644
10643
  }
10645
10644
  const privKey = this.getPrivateKey(walletIndex);
10646
10645
  const signerPubkey = privKey.pubKey();
10647
- const fromAddress = this.getAddress(walletIndex);
10646
+ const fromAddress = yield this.getAddressAsync(walletIndex);
10648
10647
  const fromAddressAcc = cosmosclient.AccAddress.fromString(fromAddress);
10649
10648
  const depositTxBody = yield buildDepositTx({
10650
10649
  msgNativeTx: {
@@ -10759,7 +10758,7 @@ class Client extends BaseXChainClient {
10759
10758
  }
10760
10759
  }
10761
10760
  const txBody = yield buildTransferTx({
10762
- fromAddress: this.getAddress(walletIndex),
10761
+ fromAddress: yield this.getAddressAsync(walletIndex),
10763
10762
  toAddress: recipient,
10764
10763
  memo,
10765
10764
  assetAmount: amount,