@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/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
@@ -4354,215 +4354,200 @@ var indexMinimal = {};
4354
4354
 
4355
4355
  var minimal$1 = {};
4356
4356
 
4357
- var aspromise;
4358
- var hasRequiredAspromise;
4359
-
4360
- function requireAspromise () {
4361
- if (hasRequiredAspromise) return aspromise;
4362
- hasRequiredAspromise = 1;
4363
- aspromise = asPromise;
4357
+ var aspromise = asPromise;
4364
4358
 
4365
- /**
4366
- * Callback as used by {@link util.asPromise}.
4367
- * @typedef asPromiseCallback
4368
- * @type {function}
4369
- * @param {Error|null} error Error, if any
4370
- * @param {...*} params Additional arguments
4371
- * @returns {undefined}
4372
- */
4359
+ /**
4360
+ * Callback as used by {@link util.asPromise}.
4361
+ * @typedef asPromiseCallback
4362
+ * @type {function}
4363
+ * @param {Error|null} error Error, if any
4364
+ * @param {...*} params Additional arguments
4365
+ * @returns {undefined}
4366
+ */
4373
4367
 
4374
- /**
4375
- * Returns a promise from a node-style callback function.
4376
- * @memberof util
4377
- * @param {asPromiseCallback} fn Function to call
4378
- * @param {*} ctx Function context
4379
- * @param {...*} params Function arguments
4380
- * @returns {Promise<*>} Promisified function
4381
- */
4382
- function asPromise(fn, ctx/*, varargs */) {
4383
- var params = new Array(arguments.length - 1),
4384
- offset = 0,
4385
- index = 2,
4386
- pending = true;
4387
- while (index < arguments.length)
4388
- params[offset++] = arguments[index++];
4389
- return new Promise(function executor(resolve, reject) {
4390
- params[offset] = function callback(err/*, varargs */) {
4391
- if (pending) {
4392
- pending = false;
4393
- if (err)
4394
- reject(err);
4395
- else {
4396
- var params = new Array(arguments.length - 1),
4397
- offset = 0;
4398
- while (offset < params.length)
4399
- params[offset++] = arguments[offset];
4400
- resolve.apply(null, params);
4401
- }
4402
- }
4403
- };
4404
- try {
4405
- fn.apply(ctx || null, params);
4406
- } catch (err) {
4407
- if (pending) {
4408
- pending = false;
4409
- reject(err);
4410
- }
4411
- }
4412
- });
4413
- }
4414
- return aspromise;
4368
+ /**
4369
+ * Returns a promise from a node-style callback function.
4370
+ * @memberof util
4371
+ * @param {asPromiseCallback} fn Function to call
4372
+ * @param {*} ctx Function context
4373
+ * @param {...*} params Function arguments
4374
+ * @returns {Promise<*>} Promisified function
4375
+ */
4376
+ function asPromise(fn, ctx/*, varargs */) {
4377
+ var params = new Array(arguments.length - 1),
4378
+ offset = 0,
4379
+ index = 2,
4380
+ pending = true;
4381
+ while (index < arguments.length)
4382
+ params[offset++] = arguments[index++];
4383
+ return new Promise(function executor(resolve, reject) {
4384
+ params[offset] = function callback(err/*, varargs */) {
4385
+ if (pending) {
4386
+ pending = false;
4387
+ if (err)
4388
+ reject(err);
4389
+ else {
4390
+ var params = new Array(arguments.length - 1),
4391
+ offset = 0;
4392
+ while (offset < params.length)
4393
+ params[offset++] = arguments[offset];
4394
+ resolve.apply(null, params);
4395
+ }
4396
+ }
4397
+ };
4398
+ try {
4399
+ fn.apply(ctx || null, params);
4400
+ } catch (err) {
4401
+ if (pending) {
4402
+ pending = false;
4403
+ reject(err);
4404
+ }
4405
+ }
4406
+ });
4415
4407
  }
4416
4408
 
4417
4409
  var base64$1 = {};
4418
4410
 
4419
- var hasRequiredBase64;
4420
-
4421
- function requireBase64 () {
4422
- if (hasRequiredBase64) return base64$1;
4423
- hasRequiredBase64 = 1;
4424
- (function (exports) {
4411
+ (function (exports) {
4425
4412
 
4426
- /**
4427
- * A minimal base64 implementation for number arrays.
4428
- * @memberof util
4429
- * @namespace
4430
- */
4431
- var base64 = exports;
4413
+ /**
4414
+ * A minimal base64 implementation for number arrays.
4415
+ * @memberof util
4416
+ * @namespace
4417
+ */
4418
+ var base64 = exports;
4432
4419
 
4433
- /**
4434
- * Calculates the byte length of a base64 encoded string.
4435
- * @param {string} string Base64 encoded string
4436
- * @returns {number} Byte length
4437
- */
4438
- base64.length = function length(string) {
4439
- var p = string.length;
4440
- if (!p)
4441
- return 0;
4442
- var n = 0;
4443
- while (--p % 4 > 1 && string.charAt(p) === "=")
4444
- ++n;
4445
- return Math.ceil(string.length * 3) / 4 - n;
4446
- };
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
+ };
4447
4434
 
4448
- // Base64 encoding table
4449
- var b64 = new Array(64);
4435
+ // Base64 encoding table
4436
+ var b64 = new Array(64);
4450
4437
 
4451
- // Base64 decoding table
4452
- var s64 = new Array(123);
4438
+ // Base64 decoding table
4439
+ var s64 = new Array(123);
4453
4440
 
4454
- // 65..90, 97..122, 48..57, 43, 47
4455
- for (var i = 0; i < 64;)
4456
- 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++;
4457
4444
 
4458
- /**
4459
- * Encodes a buffer to a base64 encoded string.
4460
- * @param {Uint8Array} buffer Source buffer
4461
- * @param {number} start Source start
4462
- * @param {number} end Source end
4463
- * @returns {string} Base64 encoded string
4464
- */
4465
- base64.encode = function encode(buffer, start, end) {
4466
- var parts = null,
4467
- chunk = [];
4468
- var i = 0, // output index
4469
- j = 0, // goto index
4470
- t; // temporary
4471
- while (start < end) {
4472
- var b = buffer[start++];
4473
- switch (j) {
4474
- case 0:
4475
- chunk[i++] = b64[b >> 2];
4476
- t = (b & 3) << 4;
4477
- j = 1;
4478
- break;
4479
- case 1:
4480
- chunk[i++] = b64[t | b >> 4];
4481
- t = (b & 15) << 2;
4482
- j = 2;
4483
- break;
4484
- case 2:
4485
- chunk[i++] = b64[t | b >> 6];
4486
- chunk[i++] = b64[b & 63];
4487
- j = 0;
4488
- break;
4489
- }
4490
- if (i > 8191) {
4491
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
4492
- i = 0;
4493
- }
4494
- }
4495
- if (j) {
4496
- chunk[i++] = b64[t];
4497
- chunk[i++] = 61;
4498
- if (j === 1)
4499
- chunk[i++] = 61;
4500
- }
4501
- if (parts) {
4502
- if (i)
4503
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
4504
- return parts.join("");
4505
- }
4506
- return String.fromCharCode.apply(String, chunk.slice(0, i));
4507
- };
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
+ };
4508
4495
 
4509
- var invalidEncoding = "invalid encoding";
4496
+ var invalidEncoding = "invalid encoding";
4510
4497
 
4511
- /**
4512
- * Decodes a base64 encoded string to a buffer.
4513
- * @param {string} string Source string
4514
- * @param {Uint8Array} buffer Destination buffer
4515
- * @param {number} offset Destination offset
4516
- * @returns {number} Number of bytes written
4517
- * @throws {Error} If encoding is invalid
4518
- */
4519
- base64.decode = function decode(string, buffer, offset) {
4520
- var start = offset;
4521
- var j = 0, // goto index
4522
- t; // temporary
4523
- for (var i = 0; i < string.length;) {
4524
- var c = string.charCodeAt(i++);
4525
- if (c === 61 && j > 1)
4526
- break;
4527
- if ((c = s64[c]) === undefined)
4528
- throw Error(invalidEncoding);
4529
- switch (j) {
4530
- case 0:
4531
- t = c;
4532
- j = 1;
4533
- break;
4534
- case 1:
4535
- buffer[offset++] = t << 2 | (c & 48) >> 4;
4536
- t = c;
4537
- j = 2;
4538
- break;
4539
- case 2:
4540
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
4541
- t = c;
4542
- j = 3;
4543
- break;
4544
- case 3:
4545
- buffer[offset++] = (t & 3) << 6 | c;
4546
- j = 0;
4547
- break;
4548
- }
4549
- }
4550
- if (j === 1)
4551
- throw Error(invalidEncoding);
4552
- return offset - start;
4553
- };
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
+ };
4554
4541
 
4555
- /**
4556
- * Tests if the specified string appears to be base64 encoded.
4557
- * @param {string} string String to test
4558
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
4559
- */
4560
- base64.test = function test(string) {
4561
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
4562
- };
4563
- } (base64$1));
4564
- return base64$1;
4565
- }
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));
4566
4551
 
4567
4552
  var eventemitter;
4568
4553
  var hasRequiredEventemitter;
@@ -5132,60 +5117,52 @@ function requireUtf8 () {
5132
5117
  return utf8$2;
5133
5118
  }
5134
5119
 
5135
- var pool_1;
5136
- var hasRequiredPool;
5137
-
5138
- function requirePool () {
5139
- if (hasRequiredPool) return pool_1;
5140
- hasRequiredPool = 1;
5141
- pool_1 = pool;
5120
+ var pool_1 = pool;
5142
5121
 
5143
- /**
5144
- * An allocator as used by {@link util.pool}.
5145
- * @typedef PoolAllocator
5146
- * @type {function}
5147
- * @param {number} size Buffer size
5148
- * @returns {Uint8Array} Buffer
5149
- */
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
+ */
5150
5129
 
5151
- /**
5152
- * A slicer as used by {@link util.pool}.
5153
- * @typedef PoolSlicer
5154
- * @type {function}
5155
- * @param {number} start Start offset
5156
- * @param {number} end End offset
5157
- * @returns {Uint8Array} Buffer slice
5158
- * @this {Uint8Array}
5159
- */
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
+ */
5160
5139
 
5161
- /**
5162
- * A general purpose buffer pool.
5163
- * @memberof util
5164
- * @function
5165
- * @param {PoolAllocator} alloc Allocator
5166
- * @param {PoolSlicer} slice Slicer
5167
- * @param {number} [size=8192] Slab size
5168
- * @returns {PoolAllocator} Pooled allocator
5169
- */
5170
- function pool(alloc, slice, size) {
5171
- var SIZE = size || 8192;
5172
- var MAX = SIZE >>> 1;
5173
- var slab = null;
5174
- var offset = SIZE;
5175
- return function pool_alloc(size) {
5176
- if (size < 1 || size > MAX)
5177
- return alloc(size);
5178
- if (offset + size > SIZE) {
5179
- slab = alloc(SIZE);
5180
- offset = 0;
5181
- }
5182
- var buf = slice.call(slab, offset, offset += size);
5183
- if (offset & 7) // align to 32 bit
5184
- offset = (offset | 7) + 1;
5185
- return buf;
5186
- };
5187
- }
5188
- 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
+ };
5189
5166
  }
5190
5167
 
5191
5168
  var longbits;
@@ -5405,10 +5382,10 @@ function requireMinimal () {
5405
5382
  var util = exports;
5406
5383
 
5407
5384
  // used to return a Promise where callback is omitted
5408
- util.asPromise = requireAspromise();
5385
+ util.asPromise = aspromise;
5409
5386
 
5410
5387
  // converts to / from base64 encoded strings
5411
- util.base64 = requireBase64();
5388
+ util.base64 = base64$1;
5412
5389
 
5413
5390
  // base class of rpc.Service
5414
5391
  util.EventEmitter = requireEventemitter();
@@ -5423,7 +5400,7 @@ function requireMinimal () {
5423
5400
  util.utf8 = requireUtf8();
5424
5401
 
5425
5402
  // provides a node-like buffer pool in the browser
5426
- util.pool = requirePool();
5403
+ util.pool = pool_1;
5427
5404
 
5428
5405
  // utility to work with the low and high bits of a 64 bit value
5429
5406
  util.LongBits = requireLongbits();
@@ -10156,7 +10133,7 @@ class Client extends BaseXChainClient {
10156
10133
  const messageAction = undefined;
10157
10134
  const offset = (params === null || params === void 0 ? void 0 : params.offset) || 0;
10158
10135
  const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
10159
- 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());
10160
10137
  const txMinHeight = undefined;
10161
10138
  const txMaxHeight = undefined;
10162
10139
  if (limit + offset > MAX_PAGES_PER_FUNCTION_CALL * MAX_TX_COUNT_PER_PAGE) {
@@ -10362,11 +10339,7 @@ class Client extends BaseXChainClient {
10362
10339
  return privKey.pubKey();
10363
10340
  }
10364
10341
  /**
10365
- * Get the current address.
10366
- *
10367
- * @returns {Address} The current address.
10368
- *
10369
- * @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
10370
10343
  */
10371
10344
  getAddress(index = 0) {
10372
10345
  const address = this.cosmosClient.getAddressFromMnemonic(this.phrase, this.getFullDerivationPath(index));
@@ -10375,6 +10348,18 @@ class Client extends BaseXChainClient {
10375
10348
  }
10376
10349
  return address;
10377
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
+ }
10378
10363
  /**
10379
10364
  * Validate the given address.
10380
10365
  *
@@ -10658,7 +10643,7 @@ class Client extends BaseXChainClient {
10658
10643
  }
10659
10644
  const privKey = this.getPrivateKey(walletIndex);
10660
10645
  const signerPubkey = privKey.pubKey();
10661
- const fromAddress = this.getAddress(walletIndex);
10646
+ const fromAddress = yield this.getAddressAsync(walletIndex);
10662
10647
  const fromAddressAcc = cosmosclient.AccAddress.fromString(fromAddress);
10663
10648
  const depositTxBody = yield buildDepositTx({
10664
10649
  msgNativeTx: {
@@ -10773,7 +10758,7 @@ class Client extends BaseXChainClient {
10773
10758
  }
10774
10759
  }
10775
10760
  const txBody = yield buildTransferTx({
10776
- fromAddress: this.getAddress(walletIndex),
10761
+ fromAddress: yield this.getAddressAsync(walletIndex),
10777
10762
  toAddress: recipient,
10778
10763
  memo,
10779
10764
  assetAmount: amount,