@xchainjs/xchain-thorchain 0.28.11 → 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
@@ -4382,215 +4382,200 @@ var indexMinimal = {};
4382
4382
 
4383
4383
  var minimal$1 = {};
4384
4384
 
4385
- var aspromise;
4386
- var hasRequiredAspromise;
4387
-
4388
- function requireAspromise () {
4389
- if (hasRequiredAspromise) return aspromise;
4390
- hasRequiredAspromise = 1;
4391
- aspromise = asPromise;
4385
+ var aspromise = asPromise;
4392
4386
 
4393
- /**
4394
- * Callback as used by {@link util.asPromise}.
4395
- * @typedef asPromiseCallback
4396
- * @type {function}
4397
- * @param {Error|null} error Error, if any
4398
- * @param {...*} params Additional arguments
4399
- * @returns {undefined}
4400
- */
4387
+ /**
4388
+ * Callback as used by {@link util.asPromise}.
4389
+ * @typedef asPromiseCallback
4390
+ * @type {function}
4391
+ * @param {Error|null} error Error, if any
4392
+ * @param {...*} params Additional arguments
4393
+ * @returns {undefined}
4394
+ */
4401
4395
 
4402
- /**
4403
- * Returns a promise from a node-style callback function.
4404
- * @memberof util
4405
- * @param {asPromiseCallback} fn Function to call
4406
- * @param {*} ctx Function context
4407
- * @param {...*} params Function arguments
4408
- * @returns {Promise<*>} Promisified function
4409
- */
4410
- function asPromise(fn, ctx/*, varargs */) {
4411
- var params = new Array(arguments.length - 1),
4412
- offset = 0,
4413
- index = 2,
4414
- pending = true;
4415
- while (index < arguments.length)
4416
- params[offset++] = arguments[index++];
4417
- return new Promise(function executor(resolve, reject) {
4418
- params[offset] = function callback(err/*, varargs */) {
4419
- if (pending) {
4420
- pending = false;
4421
- if (err)
4422
- reject(err);
4423
- else {
4424
- var params = new Array(arguments.length - 1),
4425
- offset = 0;
4426
- while (offset < params.length)
4427
- params[offset++] = arguments[offset];
4428
- resolve.apply(null, params);
4429
- }
4430
- }
4431
- };
4432
- try {
4433
- fn.apply(ctx || null, params);
4434
- } catch (err) {
4435
- if (pending) {
4436
- pending = false;
4437
- reject(err);
4438
- }
4439
- }
4440
- });
4441
- }
4442
- return aspromise;
4396
+ /**
4397
+ * Returns a promise from a node-style callback function.
4398
+ * @memberof util
4399
+ * @param {asPromiseCallback} fn Function to call
4400
+ * @param {*} ctx Function context
4401
+ * @param {...*} params Function arguments
4402
+ * @returns {Promise<*>} Promisified function
4403
+ */
4404
+ function asPromise(fn, ctx/*, varargs */) {
4405
+ var params = new Array(arguments.length - 1),
4406
+ offset = 0,
4407
+ index = 2,
4408
+ pending = true;
4409
+ while (index < arguments.length)
4410
+ params[offset++] = arguments[index++];
4411
+ return new Promise(function executor(resolve, reject) {
4412
+ params[offset] = function callback(err/*, varargs */) {
4413
+ if (pending) {
4414
+ pending = false;
4415
+ if (err)
4416
+ reject(err);
4417
+ else {
4418
+ var params = new Array(arguments.length - 1),
4419
+ offset = 0;
4420
+ while (offset < params.length)
4421
+ params[offset++] = arguments[offset];
4422
+ resolve.apply(null, params);
4423
+ }
4424
+ }
4425
+ };
4426
+ try {
4427
+ fn.apply(ctx || null, params);
4428
+ } catch (err) {
4429
+ if (pending) {
4430
+ pending = false;
4431
+ reject(err);
4432
+ }
4433
+ }
4434
+ });
4443
4435
  }
4444
4436
 
4445
4437
  var base64$1 = {};
4446
4438
 
4447
- var hasRequiredBase64;
4448
-
4449
- function requireBase64 () {
4450
- if (hasRequiredBase64) return base64$1;
4451
- hasRequiredBase64 = 1;
4452
- (function (exports) {
4439
+ (function (exports) {
4453
4440
 
4454
- /**
4455
- * A minimal base64 implementation for number arrays.
4456
- * @memberof util
4457
- * @namespace
4458
- */
4459
- var base64 = exports;
4441
+ /**
4442
+ * A minimal base64 implementation for number arrays.
4443
+ * @memberof util
4444
+ * @namespace
4445
+ */
4446
+ var base64 = exports;
4460
4447
 
4461
- /**
4462
- * Calculates the byte length of a base64 encoded string.
4463
- * @param {string} string Base64 encoded string
4464
- * @returns {number} Byte length
4465
- */
4466
- base64.length = function length(string) {
4467
- var p = string.length;
4468
- if (!p)
4469
- return 0;
4470
- var n = 0;
4471
- while (--p % 4 > 1 && string.charAt(p) === "=")
4472
- ++n;
4473
- return Math.ceil(string.length * 3) / 4 - n;
4474
- };
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
+ };
4475
4462
 
4476
- // Base64 encoding table
4477
- var b64 = new Array(64);
4463
+ // Base64 encoding table
4464
+ var b64 = new Array(64);
4478
4465
 
4479
- // Base64 decoding table
4480
- var s64 = new Array(123);
4466
+ // Base64 decoding table
4467
+ var s64 = new Array(123);
4481
4468
 
4482
- // 65..90, 97..122, 48..57, 43, 47
4483
- for (var i = 0; i < 64;)
4484
- 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++;
4485
4472
 
4486
- /**
4487
- * Encodes a buffer to a base64 encoded string.
4488
- * @param {Uint8Array} buffer Source buffer
4489
- * @param {number} start Source start
4490
- * @param {number} end Source end
4491
- * @returns {string} Base64 encoded string
4492
- */
4493
- base64.encode = function encode(buffer, start, end) {
4494
- var parts = null,
4495
- chunk = [];
4496
- var i = 0, // output index
4497
- j = 0, // goto index
4498
- t; // temporary
4499
- while (start < end) {
4500
- var b = buffer[start++];
4501
- switch (j) {
4502
- case 0:
4503
- chunk[i++] = b64[b >> 2];
4504
- t = (b & 3) << 4;
4505
- j = 1;
4506
- break;
4507
- case 1:
4508
- chunk[i++] = b64[t | b >> 4];
4509
- t = (b & 15) << 2;
4510
- j = 2;
4511
- break;
4512
- case 2:
4513
- chunk[i++] = b64[t | b >> 6];
4514
- chunk[i++] = b64[b & 63];
4515
- j = 0;
4516
- break;
4517
- }
4518
- if (i > 8191) {
4519
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4520
- i = 0;
4521
- }
4522
- }
4523
- if (j) {
4524
- chunk[i++] = b64[t];
4525
- chunk[i++] = 61;
4526
- if (j === 1)
4527
- chunk[i++] = 61;
4528
- }
4529
- if (parts) {
4530
- if (i)
4531
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4532
- return parts.join("");
4533
- }
4534
- return String.fromCharCode.apply(String, chunk.slice(0, i));
4535
- };
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
+ };
4536
4523
 
4537
- var invalidEncoding = "invalid encoding";
4524
+ var invalidEncoding = "invalid encoding";
4538
4525
 
4539
- /**
4540
- * Decodes a base64 encoded string to a buffer.
4541
- * @param {string} string Source string
4542
- * @param {Uint8Array} buffer Destination buffer
4543
- * @param {number} offset Destination offset
4544
- * @returns {number} Number of bytes written
4545
- * @throws {Error} If encoding is invalid
4546
- */
4547
- base64.decode = function decode(string, buffer, offset) {
4548
- var start = offset;
4549
- var j = 0, // goto index
4550
- t; // temporary
4551
- for (var i = 0; i < string.length;) {
4552
- var c = string.charCodeAt(i++);
4553
- if (c === 61 && j > 1)
4554
- break;
4555
- if ((c = s64[c]) === undefined)
4556
- throw Error(invalidEncoding);
4557
- switch (j) {
4558
- case 0:
4559
- t = c;
4560
- j = 1;
4561
- break;
4562
- case 1:
4563
- buffer[offset++] = t << 2 | (c & 48) >> 4;
4564
- t = c;
4565
- j = 2;
4566
- break;
4567
- case 2:
4568
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4569
- t = c;
4570
- j = 3;
4571
- break;
4572
- case 3:
4573
- buffer[offset++] = (t & 3) << 6 | c;
4574
- j = 0;
4575
- break;
4576
- }
4577
- }
4578
- if (j === 1)
4579
- throw Error(invalidEncoding);
4580
- return offset - start;
4581
- };
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
+ };
4582
4569
 
4583
- /**
4584
- * Tests if the specified string appears to be base64 encoded.
4585
- * @param {string} string String to test
4586
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
4587
- */
4588
- base64.test = function test(string) {
4589
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4590
- };
4591
- } (base64$1));
4592
- return base64$1;
4593
- }
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));
4594
4579
 
4595
4580
  var eventemitter;
4596
4581
  var hasRequiredEventemitter;
@@ -5160,60 +5145,52 @@ function requireUtf8 () {
5160
5145
  return utf8$2;
5161
5146
  }
5162
5147
 
5163
- var pool_1;
5164
- var hasRequiredPool;
5165
-
5166
- function requirePool () {
5167
- if (hasRequiredPool) return pool_1;
5168
- hasRequiredPool = 1;
5169
- pool_1 = pool;
5148
+ var pool_1 = pool;
5170
5149
 
5171
- /**
5172
- * An allocator as used by {@link util.pool}.
5173
- * @typedef PoolAllocator
5174
- * @type {function}
5175
- * @param {number} size Buffer size
5176
- * @returns {Uint8Array} Buffer
5177
- */
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
+ */
5178
5157
 
5179
- /**
5180
- * A slicer as used by {@link util.pool}.
5181
- * @typedef PoolSlicer
5182
- * @type {function}
5183
- * @param {number} start Start offset
5184
- * @param {number} end End offset
5185
- * @returns {Uint8Array} Buffer slice
5186
- * @this {Uint8Array}
5187
- */
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
+ */
5188
5167
 
5189
- /**
5190
- * A general purpose buffer pool.
5191
- * @memberof util
5192
- * @function
5193
- * @param {PoolAllocator} alloc Allocator
5194
- * @param {PoolSlicer} slice Slicer
5195
- * @param {number} [size=8192] Slab size
5196
- * @returns {PoolAllocator} Pooled allocator
5197
- */
5198
- function pool(alloc, slice, size) {
5199
- var SIZE = size || 8192;
5200
- var MAX = SIZE >>> 1;
5201
- var slab = null;
5202
- var offset = SIZE;
5203
- return function pool_alloc(size) {
5204
- if (size < 1 || size > MAX)
5205
- return alloc(size);
5206
- if (offset + size > SIZE) {
5207
- slab = alloc(SIZE);
5208
- offset = 0;
5209
- }
5210
- var buf = slice.call(slab, offset, offset += size);
5211
- if (offset & 7) // align to 32 bit
5212
- offset = (offset | 7) + 1;
5213
- return buf;
5214
- };
5215
- }
5216
- 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
+ };
5217
5194
  }
5218
5195
 
5219
5196
  var longbits;
@@ -5433,10 +5410,10 @@ function requireMinimal () {
5433
5410
  var util = exports;
5434
5411
 
5435
5412
  // used to return a Promise where callback is omitted
5436
- util.asPromise = requireAspromise();
5413
+ util.asPromise = aspromise;
5437
5414
 
5438
5415
  // converts to / from base64 encoded strings
5439
- util.base64 = requireBase64();
5416
+ util.base64 = base64$1;
5440
5417
 
5441
5418
  // base class of rpc.Service
5442
5419
  util.EventEmitter = requireEventemitter();
@@ -5451,7 +5428,7 @@ function requireMinimal () {
5451
5428
  util.utf8 = requireUtf8();
5452
5429
 
5453
5430
  // provides a node-like buffer pool in the browser
5454
- util.pool = requirePool();
5431
+ util.pool = pool_1;
5455
5432
 
5456
5433
  // utility to work with the low and high bits of a 64 bit value
5457
5434
  util.LongBits = requireLongbits();
@@ -10184,7 +10161,7 @@ class Client extends xchainClient.BaseXChainClient {
10184
10161
  const messageAction = undefined;
10185
10162
  const offset = (params === null || params === void 0 ? void 0 : params.offset) || 0;
10186
10163
  const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
10187
- 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());
10188
10165
  const txMinHeight = undefined;
10189
10166
  const txMaxHeight = undefined;
10190
10167
  if (limit + offset > MAX_PAGES_PER_FUNCTION_CALL * MAX_TX_COUNT_PER_PAGE) {
@@ -10390,11 +10367,7 @@ class Client extends xchainClient.BaseXChainClient {
10390
10367
  return privKey.pubKey();
10391
10368
  }
10392
10369
  /**
10393
- * Get the current address.
10394
- *
10395
- * @returns {Address} The current address.
10396
- *
10397
- * @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
10398
10371
  */
10399
10372
  getAddress(index = 0) {
10400
10373
  const address = this.cosmosClient.getAddressFromMnemonic(this.phrase, this.getFullDerivationPath(index));
@@ -10403,6 +10376,18 @@ class Client extends xchainClient.BaseXChainClient {
10403
10376
  }
10404
10377
  return address;
10405
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
+ }
10406
10391
  /**
10407
10392
  * Validate the given address.
10408
10393
  *
@@ -10686,7 +10671,7 @@ class Client extends xchainClient.BaseXChainClient {
10686
10671
  }
10687
10672
  const privKey = this.getPrivateKey(walletIndex);
10688
10673
  const signerPubkey = privKey.pubKey();
10689
- const fromAddress = this.getAddress(walletIndex);
10674
+ const fromAddress = yield this.getAddressAsync(walletIndex);
10690
10675
  const fromAddressAcc = cosmosclient__default["default"].AccAddress.fromString(fromAddress);
10691
10676
  const depositTxBody = yield buildDepositTx({
10692
10677
  msgNativeTx: {
@@ -10801,7 +10786,7 @@ class Client extends xchainClient.BaseXChainClient {
10801
10786
  }
10802
10787
  }
10803
10788
  const txBody = yield buildTransferTx({
10804
- fromAddress: this.getAddress(walletIndex),
10789
+ fromAddress: yield this.getAddressAsync(walletIndex),
10805
10790
  toAddress: recipient,
10806
10791
  memo,
10807
10792
  assetAmount: amount,