@firmachain/firma-js 0.2.32 → 0.2.35

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.
Files changed (87) hide show
  1. package/dist/index.js +5 -1
  2. package/dist/sdk/FirmaAuthzService.js +20 -20
  3. package/dist/sdk/FirmaBankService.js +2 -2
  4. package/dist/sdk/FirmaContractService.js +14 -16
  5. package/dist/sdk/FirmaCosmWasmService.js +27 -29
  6. package/dist/sdk/FirmaDistributionService.js +10 -10
  7. package/dist/sdk/FirmaFeeGrantService.js +6 -6
  8. package/dist/sdk/FirmaGovService.js +26 -26
  9. package/dist/sdk/FirmaIbcService.js +4 -4
  10. package/dist/sdk/FirmaIpfsService.js +1 -1
  11. package/dist/sdk/FirmaNftService.js +9 -9
  12. package/dist/sdk/FirmaStakingService.js +10 -10
  13. package/dist/sdk/FirmaTokenService.js +16 -16
  14. package/dist/sdk/FirmaUtil.d.ts +13 -1
  15. package/dist/sdk/FirmaUtil.js +145 -14
  16. package/dist/sdk/FirmaWalletService.js +3 -3
  17. package/dist/sdk/firmachain/amino/addresses.js +11 -11
  18. package/dist/sdk/firmachain/amino/aminotypes.js +36 -32
  19. package/dist/sdk/firmachain/amino/encoding.js +30 -26
  20. package/dist/sdk/firmachain/amino/multisig.js +5 -5
  21. package/dist/sdk/firmachain/amino/signature.js +4 -4
  22. package/dist/sdk/firmachain/amino/signdoc.js +1 -1
  23. package/dist/sdk/firmachain/amino/wallet.js +14 -10
  24. package/dist/sdk/firmachain/authz/AuthzQueryClient.js +3 -3
  25. package/dist/sdk/firmachain/authz/AuthzTxClient.d.ts +5 -4
  26. package/dist/sdk/firmachain/authz/AuthzTxClient.js +6 -3
  27. package/dist/sdk/firmachain/authz/index.js +5 -1
  28. package/dist/sdk/firmachain/bank/BankQueryClient.js +4 -4
  29. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +4 -3
  30. package/dist/sdk/firmachain/bank/BankTxClient.js +5 -2
  31. package/dist/sdk/firmachain/bank/index.js +5 -1
  32. package/dist/sdk/firmachain/common/CommonTxClient.d.ts +7 -0
  33. package/dist/sdk/firmachain/common/CommonTxClient.js +79 -0
  34. package/dist/sdk/firmachain/common/ITxClient.d.ts +3 -3
  35. package/dist/sdk/firmachain/common/ITxClient.js +14 -8
  36. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +2 -2
  37. package/dist/sdk/firmachain/common/LedgerWallet.js +14 -10
  38. package/dist/sdk/firmachain/common/accounts.js +2 -2
  39. package/dist/sdk/firmachain/common/index.js +5 -1
  40. package/dist/sdk/firmachain/common/signing.js +9 -5
  41. package/dist/sdk/firmachain/common/signingaminostargateclient.js +16 -16
  42. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +15 -8
  43. package/dist/sdk/firmachain/common/signingstargateclient.js +82 -19
  44. package/dist/sdk/firmachain/common/stargateclient.js +6 -6
  45. package/dist/sdk/firmachain/contract/ContractQueryClient.js +2 -2
  46. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +4 -3
  47. package/dist/sdk/firmachain/contract/ContractTxClient.js +5 -2
  48. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +4 -4
  49. package/dist/sdk/firmachain/contract/index.js +5 -1
  50. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +7 -7
  51. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.d.ts +8 -7
  52. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.js +9 -6
  53. package/dist/sdk/firmachain/cosmwasm/index.js +5 -1
  54. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +5 -5
  55. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +6 -5
  56. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +7 -4
  57. package/dist/sdk/firmachain/distribution/index.js +5 -1
  58. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +2 -2
  59. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +4 -3
  60. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +5 -2
  61. package/dist/sdk/firmachain/feegrant/index.js +5 -1
  62. package/dist/sdk/firmachain/google/protobuf/any.d.ts +1 -1
  63. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +27 -27
  64. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +1 -1
  65. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +1 -1
  66. package/dist/sdk/firmachain/gov/GovQueryClient.js +2 -2
  67. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +5 -4
  68. package/dist/sdk/firmachain/gov/GovTxClient.js +6 -3
  69. package/dist/sdk/firmachain/gov/index.js +5 -1
  70. package/dist/sdk/firmachain/ibc/IbcQueryClient.js +1 -1
  71. package/dist/sdk/firmachain/ibc/IbcTxClient.d.ts +3 -2
  72. package/dist/sdk/firmachain/ibc/IbcTxClient.js +4 -1
  73. package/dist/sdk/firmachain/ibc/index.js +5 -1
  74. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +5 -4
  75. package/dist/sdk/firmachain/nft/NftTxClient.js +6 -3
  76. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +6 -6
  77. package/dist/sdk/firmachain/nft/index.js +5 -1
  78. package/dist/sdk/firmachain/slashing/index.js +5 -1
  79. package/dist/sdk/firmachain/staking/StakingQueryClient.js +8 -8
  80. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +7 -6
  81. package/dist/sdk/firmachain/staking/StakingTxClient.js +8 -5
  82. package/dist/sdk/firmachain/staking/index.js +5 -1
  83. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +6 -5
  84. package/dist/sdk/firmachain/token/TokenTxClient.js +7 -4
  85. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +8 -8
  86. package/dist/sdk/firmachain/token/index.js +5 -1
  87. package/package.json +2 -4
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,6 +46,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
47
  }
37
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
38
52
  Object.defineProperty(exports, "__esModule", { value: true });
39
53
  exports.getSignAndBroadcastOption = exports.DefaultTxMisc = exports.FirmaUtil = void 0;
40
54
  var fs_1 = require("fs");
@@ -42,12 +56,19 @@ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
42
56
  var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
43
57
  var encoding_1 = require("@cosmjs/encoding");
44
58
  var LedgerSigningStargateClient_1 = require("./firmachain/common/LedgerSigningStargateClient");
59
+ var encoding_2 = require("@cosmjs/encoding");
60
+ var crypto_1 = require("@cosmjs/crypto");
61
+ var amino_1 = require("@cosmjs/amino");
62
+ var signingaminostargateclient_1 = require("./firmachain/common/signingaminostargateclient");
63
+ var proto_signing_1 = require("@cosmjs/proto-signing");
64
+ var signingstargateclient_1 = require("./firmachain/common/signingstargateclient");
65
+ var any_1 = require("./firmachain/google/protobuf/any");
66
+ var long_1 = __importDefault(require("long"));
67
+ var CommonTxClient_1 = require("./firmachain/common/CommonTxClient");
45
68
  var CryptoJS = require("crypto-js");
46
69
  var sha1 = require("crypto-js/sha1");
47
70
  var sha256 = require("crypto-js/sha256");
48
71
  var encHex = require("crypto-js/enc-hex");
49
- var signingaminostargateclient_1 = require("./firmachain/common/signingaminostargateclient");
50
- var proto_signing_1 = require("@cosmjs/proto-signing");
51
72
  var FirmaUtil = /** @class */ (function () {
52
73
  function FirmaUtil(firmaConfig) {
53
74
  FirmaUtil.config = firmaConfig;
@@ -89,22 +110,25 @@ var FirmaUtil = /** @class */ (function () {
89
110
  return Number.parseInt(newBig);
90
111
  };
91
112
  FirmaUtil.arrayBufferToBase64 = function (buffer) {
92
- var binary = '';
113
+ return Buffer.from(buffer).toString("base64");
114
+ /*var binary = '';
93
115
  var bytes = new Uint8Array(buffer);
94
116
  var len = bytes.byteLength;
95
117
  for (var i = 0; i < len; i++) {
96
118
  binary += String.fromCharCode(bytes[i]);
97
119
  }
98
- return btoa(binary);
120
+ return btoa(binary);*/
99
121
  };
100
122
  FirmaUtil.base64ToArrayBuffer = function (base64) {
101
- var binary_string = atob(base64);
102
- var len = binary_string.length;
103
- var bytes = new Uint8Array(len);
104
- for (var i = 0; i < len; i++) {
105
- bytes[i] = binary_string.charCodeAt(i);
106
- }
107
- return bytes;
123
+ var buffer = Buffer.from(base64, "base64");
124
+ return new Uint8Array(buffer);
125
+ /* var binary_string = atob(base64);
126
+ var len = binary_string.length;
127
+ var bytes = new Uint8Array(len);
128
+ for (var i = 0; i < len; i++) {
129
+ bytes[i] = binary_string.charCodeAt(i);
130
+ }
131
+ return bytes;*/
108
132
  };
109
133
  FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
110
134
  var fixedUTokenAmount = Math.floor(uTokenAmount);
@@ -201,7 +225,7 @@ var FirmaUtil = /** @class */ (function () {
201
225
  case 0:
202
226
  _a.trys.push([0, 2, , 3]);
203
227
  encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
204
- hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
228
+ hexTx = "0x".concat(Buffer.from(encodedTx).toString("hex"));
205
229
  queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
206
230
  return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
207
231
  case 1:
@@ -225,7 +249,7 @@ var FirmaUtil = /** @class */ (function () {
225
249
  case 0:
226
250
  _a.trys.push([0, 2, , 3]);
227
251
  encodedTx = Uint8Array.from(txRaw);
228
- hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
252
+ hexTx = "0x".concat(Buffer.from(encodedTx).toString("hex"));
229
253
  console.log("hexTx:" + hexTx);
230
254
  queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
231
255
  return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
@@ -245,7 +269,7 @@ var FirmaUtil = /** @class */ (function () {
245
269
  FirmaUtil.printLog = function (log) {
246
270
  if (FirmaUtil.config.isShowLog === false)
247
271
  return;
248
- console.log("[FirmaSDK] " + log);
272
+ console.log("[FirmaSDK] ".concat(log));
249
273
  };
250
274
  FirmaUtil.experimentalAdr36Sign = function (wallet, data) {
251
275
  return __awaiter(this, void 0, void 0, function () {
@@ -291,6 +315,113 @@ var FirmaUtil = /** @class */ (function () {
291
315
  });
292
316
  });
293
317
  };
318
+ FirmaUtil.recoverSigningAddress = function (signature, hash, recoveryIndex) {
319
+ return __awaiter(this, void 0, void 0, function () {
320
+ var sig, extendedSig, recoveredPubKey, _a;
321
+ return __generator(this, function (_b) {
322
+ switch (_b.label) {
323
+ case 0:
324
+ if (recoveryIndex > 3) {
325
+ throw new Error('Invalid recovery index');
326
+ }
327
+ sig = crypto_1.Secp256k1Signature.fromFixedLength((0, encoding_2.fromBase64)(signature));
328
+ extendedSig = new crypto_1.ExtendedSecp256k1Signature(sig.r(), sig.s(), recoveryIndex);
329
+ _b.label = 1;
330
+ case 1:
331
+ _b.trys.push([1, 3, , 4]);
332
+ return [4 /*yield*/, crypto_1.Secp256k1.recoverPubkey(extendedSig, hash)];
333
+ case 2:
334
+ recoveredPubKey = _b.sent();
335
+ return [2 /*return*/, (0, amino_1.pubkeyToAddress)({
336
+ type: 'tendermint/PubKeySecp256k1',
337
+ value: (0, encoding_2.toBase64)(crypto_1.Secp256k1.compressPubkey(recoveredPubKey)),
338
+ }, 'firma')];
339
+ case 3:
340
+ _a = _b.sent();
341
+ return [2 /*return*/, null];
342
+ case 4: return [2 /*return*/];
343
+ }
344
+ });
345
+ });
346
+ };
347
+ FirmaUtil.verifySignature = function (address, signature, hash) {
348
+ return __awaiter(this, void 0, void 0, function () {
349
+ var i, recoveredAddress;
350
+ return __generator(this, function (_a) {
351
+ switch (_a.label) {
352
+ case 0:
353
+ i = 0;
354
+ _a.label = 1;
355
+ case 1:
356
+ if (!(i < 4)) return [3 /*break*/, 4];
357
+ return [4 /*yield*/, this.recoverSigningAddress(signature, hash, i)];
358
+ case 2:
359
+ recoveredAddress = _a.sent();
360
+ if (recoveredAddress === address) {
361
+ return [2 /*return*/, true];
362
+ }
363
+ _a.label = 3;
364
+ case 3:
365
+ i++;
366
+ return [3 /*break*/, 1];
367
+ case 4: return [2 /*return*/, false];
368
+ }
369
+ });
370
+ });
371
+ };
372
+ FirmaUtil.verifyDirectSignature = function (address, signature, signDoc) {
373
+ var messageHash = (0, crypto_1.sha256)((0, proto_signing_1.makeSignBytes)(signDoc));
374
+ return this.verifySignature(address, signature, messageHash);
375
+ };
376
+ ;
377
+ FirmaUtil.parseSignDocValues = function (signDocString) {
378
+ return __assign(__assign({}, signDocString), { bodyBytes: (0, encoding_2.fromHex)(signDocString.bodyBytes), authInfoBytes: (0, encoding_2.fromHex)(signDocString.authInfoBytes), accountNumber: new long_1.default(signDocString.accountNumber) });
379
+ };
380
+ FirmaUtil.stringifySignDocValues = function (signDoc) {
381
+ return __assign(__assign({}, signDoc), { bodyBytes: (0, encoding_2.toHex)(signDoc.bodyBytes), authInfoBytes: (0, encoding_2.toHex)(signDoc.authInfoBytes), accountNumber: signDoc.accountNumber.toString(16) });
382
+ };
383
+ FirmaUtil.makeSignDoc = function (signerAddress, messages, txMisc) {
384
+ if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
385
+ return __awaiter(this, void 0, void 0, function () {
386
+ var result, chainID, serverUrl, registry;
387
+ return __generator(this, function (_a) {
388
+ switch (_a.label) {
389
+ case 0:
390
+ result = FirmaUtil.getSignAndBroadcastOption(FirmaUtil.config.denom, txMisc);
391
+ chainID = FirmaUtil.config.chainID;
392
+ serverUrl = FirmaUtil.config.rpcAddress;
393
+ registry = CommonTxClient_1.CommonTxClient.getRegistry();
394
+ return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.makeSignDocForSend(signerAddress, messages, result.fee, result.memo, serverUrl, chainID, registry)];
395
+ case 1: return [2 /*return*/, _a.sent()];
396
+ }
397
+ });
398
+ });
399
+ };
400
+ FirmaUtil.makeSignDocWithStringify = function (signerAddress, messages, txMisc) {
401
+ if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
402
+ return __awaiter(this, void 0, void 0, function () {
403
+ var signDoc, stringSignDoc;
404
+ return __generator(this, function (_a) {
405
+ switch (_a.label) {
406
+ case 0: return [4 /*yield*/, this.makeSignDoc(signerAddress, messages, txMisc)];
407
+ case 1:
408
+ signDoc = _a.sent();
409
+ stringSignDoc = this.stringifySignDocValues(signDoc);
410
+ return [2 /*return*/, stringSignDoc];
411
+ }
412
+ });
413
+ });
414
+ };
415
+ FirmaUtil.getAnyData = function (registry, message) {
416
+ var anyData = any_1.Any.fromPartial({
417
+ typeUrl: message.typeUrl,
418
+ value: registry.encode(message)
419
+ });
420
+ return anyData;
421
+ };
422
+ FirmaUtil.getCommonTxClient = function (aliceWallet) {
423
+ return new CommonTxClient_1.CommonTxClient(aliceWallet, FirmaUtil.config.rpcAddress);
424
+ };
294
425
  FirmaUtil.FctDecimal = 6;
295
426
  return FirmaUtil;
296
427
  }());
@@ -92,7 +92,7 @@ var FirmaWalletService = /** @class */ (function () {
92
92
  return __awaiter(this, void 0, void 0, function () {
93
93
  return __generator(this, function (_a) {
94
94
  switch (_a.label) {
95
- case 0: return [4 /*yield*/, LedgerWallet_1.signFromLedger(this.ledger, messages, option, registry)];
95
+ case 0: return [4 /*yield*/, (0, LedgerWallet_1.signFromLedger)(this.ledger, messages, option, registry)];
96
96
  case 1: return [2 /*return*/, _a.sent()];
97
97
  }
98
98
  });
@@ -123,7 +123,7 @@ var FirmaWalletService = /** @class */ (function () {
123
123
  };
124
124
  FirmaWalletService.getHdPath = function (hdPath, accountIndex) {
125
125
  try {
126
- return [crypto_1.stringToPath(hdPath + accountIndex + "'/0/0")];
126
+ return [(0, crypto_1.stringToPath)(hdPath + accountIndex + "'/0/0")];
127
127
  }
128
128
  catch (error) {
129
129
  FirmaUtil_1.FirmaUtil.printLog(error);
@@ -169,7 +169,7 @@ var FirmaWalletService = /** @class */ (function () {
169
169
  seed = _a.sent();
170
170
  hdpath = FirmaWalletService.getHdPath(this.getHdPath(), accountIndex);
171
171
  privkey = crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, seed, hdpath[0]).privkey;
172
- privateKey = "0x" + Buffer.from(privkey).toString("hex");
172
+ privateKey = "0x".concat(Buffer.from(privkey).toString("hex"));
173
173
  return [2 /*return*/, privateKey];
174
174
  case 2:
175
175
  error_3 = _a.sent();
@@ -8,32 +8,32 @@ var encoding_2 = require("./encoding");
8
8
  var pubkeys_1 = require("./pubkeys");
9
9
  function rawEd25519PubkeyToRawAddress(pubkeyData) {
10
10
  if (pubkeyData.length !== 32) {
11
- throw new Error("Invalid Ed25519 pubkey length: " + pubkeyData.length);
11
+ throw new Error("Invalid Ed25519 pubkey length: ".concat(pubkeyData.length));
12
12
  }
13
- return crypto_1.sha256(pubkeyData).slice(0, 20);
13
+ return (0, crypto_1.sha256)(pubkeyData).slice(0, 20);
14
14
  }
15
15
  exports.rawEd25519PubkeyToRawAddress = rawEd25519PubkeyToRawAddress;
16
16
  function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
17
17
  if (pubkeyData.length !== 33) {
18
- throw new Error("Invalid Secp256k1 pubkey length (compressed): " + pubkeyData.length);
18
+ throw new Error("Invalid Secp256k1 pubkey length (compressed): ".concat(pubkeyData.length));
19
19
  }
20
- return crypto_1.ripemd160(crypto_1.sha256(pubkeyData));
20
+ return (0, crypto_1.ripemd160)((0, crypto_1.sha256)(pubkeyData));
21
21
  }
22
22
  exports.rawSecp256k1PubkeyToRawAddress = rawSecp256k1PubkeyToRawAddress;
23
23
  // For secp256k1 this assumes we already have a compressed pubkey.
24
24
  function pubkeyToRawAddress(pubkey) {
25
- if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
26
- var pubkeyData = encoding_1.fromBase64(pubkey.value);
25
+ if ((0, pubkeys_1.isSecp256k1Pubkey)(pubkey)) {
26
+ var pubkeyData = (0, encoding_1.fromBase64)(pubkey.value);
27
27
  return rawSecp256k1PubkeyToRawAddress(pubkeyData);
28
28
  }
29
- else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
30
- var pubkeyData = encoding_1.fromBase64(pubkey.value);
29
+ else if ((0, pubkeys_1.isEd25519Pubkey)(pubkey)) {
30
+ var pubkeyData = (0, encoding_1.fromBase64)(pubkey.value);
31
31
  return rawEd25519PubkeyToRawAddress(pubkeyData);
32
32
  }
33
- else if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
33
+ else if ((0, pubkeys_1.isMultisigThresholdPubkey)(pubkey)) {
34
34
  // https://github.com/tendermint/tendermint/blob/38b401657e4ad7a7eeb3c30a3cbf512037df3740/crypto/multisig/threshold_pubkey.go#L71-L74
35
- var pubkeyData = encoding_2.encodeAminoPubkey(pubkey);
36
- return crypto_1.sha256(pubkeyData).slice(0, 20);
35
+ var pubkeyData = (0, encoding_2.encodeAminoPubkey)(pubkey);
36
+ return (0, crypto_1.sha256)(pubkeyData).slice(0, 20);
37
37
  }
38
38
  else {
39
39
  throw new Error("Unsupported public key type");
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -52,7 +56,7 @@ function omitDefault(input) {
52
56
  if (long_1.default.isLong(input)) {
53
57
  return input.isZero() ? undefined : input;
54
58
  }
55
- throw new Error("Got unsupported type '" + typeof input + "'");
59
+ throw new Error("Got unsupported type '".concat(typeof input, "'"));
56
60
  }
57
61
  function createDefaultTypes(prefix) {
58
62
  return {
@@ -64,7 +68,7 @@ function createDefaultTypes(prefix) {
64
68
  return ({
65
69
  from_address: fromAddress,
66
70
  to_address: toAddress,
67
- amount: __spreadArray([], __read(amount)),
71
+ amount: __spreadArray([], __read(amount), false),
68
72
  });
69
73
  },
70
74
  fromAmino: function (_a) {
@@ -72,7 +76,7 @@ function createDefaultTypes(prefix) {
72
76
  return ({
73
77
  fromAddress: from_address,
74
78
  toAddress: to_address,
75
- amount: __spreadArray([], __read(amount)),
79
+ amount: __spreadArray([], __read(amount), false),
76
80
  });
77
81
  },
78
82
  },
@@ -83,11 +87,11 @@ function createDefaultTypes(prefix) {
83
87
  return ({
84
88
  inputs: inputs.map(function (input) { return ({
85
89
  address: input.address,
86
- coins: __spreadArray([], __read(input.coins)),
90
+ coins: __spreadArray([], __read(input.coins), false),
87
91
  }); }),
88
92
  outputs: outputs.map(function (output) { return ({
89
93
  address: output.address,
90
- coins: __spreadArray([], __read(output.coins)),
94
+ coins: __spreadArray([], __read(output.coins), false),
91
95
  }); }),
92
96
  });
93
97
  },
@@ -96,11 +100,11 @@ function createDefaultTypes(prefix) {
96
100
  return ({
97
101
  inputs: inputs.map(function (input) { return ({
98
102
  address: input.address,
99
- coins: __spreadArray([], __read(input.coins)),
103
+ coins: __spreadArray([], __read(input.coins), false),
100
104
  }); }),
101
105
  outputs: outputs.map(function (output) { return ({
102
106
  address: output.address,
103
- coins: __spreadArray([], __read(output.coins)),
107
+ coins: __spreadArray([], __read(output.coins), false),
104
108
  }); }),
105
109
  });
106
110
  },
@@ -111,14 +115,14 @@ function createDefaultTypes(prefix) {
111
115
  toAmino: function (_a) {
112
116
  var amount = _a.amount, depositor = _a.depositor;
113
117
  return ({
114
- amount: __spreadArray([], __read(amount)),
118
+ amount: __spreadArray([], __read(amount), false),
115
119
  depositor: depositor,
116
120
  });
117
121
  },
118
122
  fromAmino: function (_a) {
119
123
  var amount = _a.amount, depositor = _a.depositor;
120
124
  return ({
121
- amount: __spreadArray([], __read(amount)),
125
+ amount: __spreadArray([], __read(amount), false),
122
126
  depositor: depositor,
123
127
  });
124
128
  },
@@ -205,7 +209,7 @@ function createDefaultTypes(prefix) {
205
209
  fromAmino: function (_a) {
206
210
  var option = _a.option, proposal_id = _a.proposal_id, voter = _a.voter;
207
211
  return {
208
- option: gov_1.voteOptionFromJSON(option),
212
+ option: (0, gov_1.voteOptionFromJSON)(option),
209
213
  proposalId: long_1.default.fromString(proposal_id),
210
214
  voter: voter,
211
215
  };
@@ -215,7 +219,7 @@ function createDefaultTypes(prefix) {
215
219
  aminoType: "cosmos-sdk/MsgSubmitProposal",
216
220
  toAmino: function (_a) {
217
221
  var initialDeposit = _a.initialDeposit, proposer = _a.proposer, content = _a.content;
218
- utils_1.assertDefinedAndNotNull(content);
222
+ (0, utils_1.assertDefinedAndNotNull)(content);
219
223
  var proposal;
220
224
  switch (content.typeUrl) {
221
225
  case "/cosmos.gov.v1beta1.TextProposal": {
@@ -230,7 +234,7 @@ function createDefaultTypes(prefix) {
230
234
  break;
231
235
  }
232
236
  default:
233
- throw new Error("Unsupported proposal type: '" + content.typeUrl + "'");
237
+ throw new Error("Unsupported proposal type: '".concat(content.typeUrl, "'"));
234
238
  }
235
239
  return {
236
240
  initial_deposit: initialDeposit,
@@ -244,10 +248,10 @@ function createDefaultTypes(prefix) {
244
248
  switch (content.type) {
245
249
  case "cosmos-sdk/TextProposal": {
246
250
  var value = content.value;
247
- utils_1.assert(utils_1.isNonNullObject(value));
251
+ (0, utils_1.assert)((0, utils_1.isNonNullObject)(value));
248
252
  var _b = value, title = _b.title, description = _b.description;
249
- utils_1.assert(typeof title === "string");
250
- utils_1.assert(typeof description === "string");
253
+ (0, utils_1.assert)(typeof title === "string");
254
+ (0, utils_1.assert)(typeof description === "string");
251
255
  any_content = any_1.Any.fromPartial({
252
256
  typeUrl: "/cosmos.gov.v1beta1.TextProposal",
253
257
  value: gov_1.TextProposal.encode(gov_1.TextProposal.fromPartial({
@@ -258,7 +262,7 @@ function createDefaultTypes(prefix) {
258
262
  break;
259
263
  }
260
264
  default:
261
- throw new Error("Unsupported proposal type: '" + content.type + "'");
265
+ throw new Error("Unsupported proposal type: '".concat(content.type, "'"));
262
266
  }
263
267
  return {
264
268
  initialDeposit: Array.from(initial_deposit),
@@ -272,7 +276,7 @@ function createDefaultTypes(prefix) {
272
276
  aminoType: "cosmos-sdk/MsgBeginRedelegate",
273
277
  toAmino: function (_a) {
274
278
  var delegatorAddress = _a.delegatorAddress, validatorSrcAddress = _a.validatorSrcAddress, validatorDstAddress = _a.validatorDstAddress, amount = _a.amount;
275
- utils_1.assertDefinedAndNotNull(amount, "missing amount");
279
+ (0, utils_1.assertDefinedAndNotNull)(amount, "missing amount");
276
280
  return {
277
281
  delegator_address: delegatorAddress,
278
282
  validator_src_address: validatorSrcAddress,
@@ -294,10 +298,10 @@ function createDefaultTypes(prefix) {
294
298
  aminoType: "cosmos-sdk/MsgCreateValidator",
295
299
  toAmino: function (_a) {
296
300
  var description = _a.description, commission = _a.commission, minSelfDelegation = _a.minSelfDelegation, delegatorAddress = _a.delegatorAddress, validatorAddress = _a.validatorAddress, pubkey = _a.pubkey, value = _a.value;
297
- utils_1.assertDefinedAndNotNull(description, "missing description");
298
- utils_1.assertDefinedAndNotNull(commission, "missing commission");
299
- utils_1.assertDefinedAndNotNull(pubkey, "missing pubkey");
300
- utils_1.assertDefinedAndNotNull(value, "missing value");
301
+ (0, utils_1.assertDefinedAndNotNull)(description, "missing description");
302
+ (0, utils_1.assertDefinedAndNotNull)(commission, "missing commission");
303
+ (0, utils_1.assertDefinedAndNotNull)(pubkey, "missing pubkey");
304
+ (0, utils_1.assertDefinedAndNotNull)(value, "missing value");
301
305
  return {
302
306
  description: {
303
307
  moniker: description.moniker,
@@ -314,16 +318,16 @@ function createDefaultTypes(prefix) {
314
318
  min_self_delegation: minSelfDelegation,
315
319
  delegator_address: delegatorAddress,
316
320
  validator_address: validatorAddress,
317
- pubkey: encoding_2.encodeBech32Pubkey({
321
+ pubkey: (0, encoding_2.encodeBech32Pubkey)({
318
322
  type: "tendermint/PubKeySecp256k1",
319
- value: encoding_1.toBase64(pubkey.value),
323
+ value: (0, encoding_1.toBase64)(pubkey.value),
320
324
  }, prefix),
321
325
  value: value,
322
326
  };
323
327
  },
324
328
  fromAmino: function (_a) {
325
329
  var description = _a.description, commission = _a.commission, min_self_delegation = _a.min_self_delegation, delegator_address = _a.delegator_address, validator_address = _a.validator_address, pubkey = _a.pubkey, value = _a.value;
326
- var decodedPubkey = encoding_2.decodeBech32Pubkey(pubkey);
330
+ var decodedPubkey = (0, encoding_2.decodeBech32Pubkey)(pubkey);
327
331
  if (decodedPubkey.type !== "tendermint/PubKeySecp256k1") {
328
332
  throw new Error("Only Secp256k1 public keys are supported");
329
333
  }
@@ -345,7 +349,7 @@ function createDefaultTypes(prefix) {
345
349
  validatorAddress: validator_address,
346
350
  pubkey: {
347
351
  typeUrl: "/cosmos.crypto.secp256k1.PubKey",
348
- value: encoding_1.fromBase64(decodedPubkey.value),
352
+ value: (0, encoding_1.fromBase64)(decodedPubkey.value),
349
353
  },
350
354
  value: value,
351
355
  };
@@ -355,7 +359,7 @@ function createDefaultTypes(prefix) {
355
359
  aminoType: "cosmos-sdk/MsgDelegate",
356
360
  toAmino: function (_a) {
357
361
  var delegatorAddress = _a.delegatorAddress, validatorAddress = _a.validatorAddress, amount = _a.amount;
358
- utils_1.assertDefinedAndNotNull(amount, "missing amount");
362
+ (0, utils_1.assertDefinedAndNotNull)(amount, "missing amount");
359
363
  return {
360
364
  delegator_address: delegatorAddress,
361
365
  validator_address: validatorAddress,
@@ -375,7 +379,7 @@ function createDefaultTypes(prefix) {
375
379
  aminoType: "cosmos-sdk/MsgEditValidator",
376
380
  toAmino: function (_a) {
377
381
  var description = _a.description, commissionRate = _a.commissionRate, minSelfDelegation = _a.minSelfDelegation, validatorAddress = _a.validatorAddress;
378
- utils_1.assertDefinedAndNotNull(description, "missing description");
382
+ (0, utils_1.assertDefinedAndNotNull)(description, "missing description");
379
383
  return {
380
384
  description: {
381
385
  moniker: description.moniker,
@@ -409,7 +413,7 @@ function createDefaultTypes(prefix) {
409
413
  aminoType: "cosmos-sdk/MsgUndelegate",
410
414
  toAmino: function (_a) {
411
415
  var delegatorAddress = _a.delegatorAddress, validatorAddress = _a.validatorAddress, amount = _a.amount;
412
- utils_1.assertDefinedAndNotNull(amount, "missing amount");
416
+ (0, utils_1.assertDefinedAndNotNull)(amount, "missing amount");
413
417
  return {
414
418
  delegator_address: delegatorAddress,
415
419
  validator_address: validatorAddress,
@@ -15,10 +15,14 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  }
16
16
  return ar;
17
17
  };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
19
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
- to[j] = from[i];
21
- return to;
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
22
26
  };
23
27
  var __values = (this && this.__values) || function(o) {
24
28
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -43,58 +47,58 @@ function encodeSecp256k1Pubkey(pubkey) {
43
47
  }
44
48
  return {
45
49
  type: pubkeys_1.pubkeyType.secp256k1,
46
- value: encoding_1.toBase64(pubkey),
50
+ value: (0, encoding_1.toBase64)(pubkey),
47
51
  };
48
52
  }
49
53
  exports.encodeSecp256k1Pubkey = encodeSecp256k1Pubkey;
50
54
  // As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
51
55
  // Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
52
56
  // Last bytes is varint-encoded length prefix
53
- var pubkeyAminoPrefixSecp256k1 = encoding_1.fromHex("eb5ae987" + "21" /* fixed length */);
54
- var pubkeyAminoPrefixEd25519 = encoding_1.fromHex("1624de64" + "20" /* fixed length */);
55
- var pubkeyAminoPrefixSr25519 = encoding_1.fromHex("0dfb1005" + "20" /* fixed length */);
57
+ var pubkeyAminoPrefixSecp256k1 = (0, encoding_1.fromHex)("eb5ae987" + "21" /* fixed length */);
58
+ var pubkeyAminoPrefixEd25519 = (0, encoding_1.fromHex)("1624de64" + "20" /* fixed length */);
59
+ var pubkeyAminoPrefixSr25519 = (0, encoding_1.fromHex)("0dfb1005" + "20" /* fixed length */);
56
60
  /** See https://github.com/tendermint/tendermint/commit/38b401657e4ad7a7eeb3c30a3cbf512037df3740 */
57
- var pubkeyAminoPrefixMultisigThreshold = encoding_1.fromHex("22c1f7e2" /* variable length not included */);
61
+ var pubkeyAminoPrefixMultisigThreshold = (0, encoding_1.fromHex)("22c1f7e2" /* variable length not included */);
58
62
  /**
59
63
  * Decodes a pubkey in the Amino binary format to a type/value object.
60
64
  */
61
65
  function decodeAminoPubkey(data) {
62
- if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSecp256k1)) {
66
+ if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixSecp256k1)) {
63
67
  var rest = data.slice(pubkeyAminoPrefixSecp256k1.length);
64
68
  if (rest.length !== 33) {
65
69
  throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey).");
66
70
  }
67
71
  return {
68
72
  type: pubkeys_1.pubkeyType.secp256k1,
69
- value: encoding_1.toBase64(rest),
73
+ value: (0, encoding_1.toBase64)(rest),
70
74
  };
71
75
  }
72
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixEd25519)) {
76
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixEd25519)) {
73
77
  var rest = data.slice(pubkeyAminoPrefixEd25519.length);
74
78
  if (rest.length !== 32) {
75
79
  throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey).");
76
80
  }
77
81
  return {
78
82
  type: pubkeys_1.pubkeyType.ed25519,
79
- value: encoding_1.toBase64(rest),
83
+ value: (0, encoding_1.toBase64)(rest),
80
84
  };
81
85
  }
82
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSr25519)) {
86
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixSr25519)) {
83
87
  var rest = data.slice(pubkeyAminoPrefixSr25519.length);
84
88
  if (rest.length !== 32) {
85
89
  throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey).");
86
90
  }
87
91
  return {
88
92
  type: pubkeys_1.pubkeyType.sr25519,
89
- value: encoding_1.toBase64(rest),
93
+ value: (0, encoding_1.toBase64)(rest),
90
94
  };
91
95
  }
92
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixMultisigThreshold)) {
96
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixMultisigThreshold)) {
93
97
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
94
98
  return decodeMultisigPubkey(data);
95
99
  }
96
100
  else {
97
- throw new Error("Unsupported public key type. Amino data starts with: " + encoding_1.toHex(data.slice(0, 5)));
101
+ throw new Error("Unsupported public key type. Amino data starts with: " + (0, encoding_1.toHex)(data.slice(0, 5)));
98
102
  }
99
103
  }
100
104
  exports.decodeAminoPubkey = decodeAminoPubkey;
@@ -133,7 +137,7 @@ function decodeMultisigPubkey(data) {
133
137
  var reader = Array.from(data);
134
138
  // remove multisig amino prefix;
135
139
  var prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length);
136
- if (!utils_1.arrayContentStartsWith(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
140
+ if (!(0, utils_1.arrayContentStartsWith)(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
137
141
  throw new Error("Invalid multisig prefix.");
138
142
  }
139
143
  // remove 0x08 threshold prefix;
@@ -188,18 +192,18 @@ function encodeUvarint(value) {
188
192
  */
189
193
  function encodeAminoPubkey(pubkey) {
190
194
  var e_1, _a;
191
- if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
195
+ if ((0, pubkeys_1.isMultisigThresholdPubkey)(pubkey)) {
192
196
  var out = Array.from(pubkeyAminoPrefixMultisigThreshold);
193
197
  out.push(0x08); // TODO: What is this?
194
198
  out.push.apply(// TODO: What is this?
195
- out, __spreadArray([], __read(encodeUvarint(pubkey.value.threshold))));
199
+ out, __spreadArray([], __read(encodeUvarint(pubkey.value.threshold)), false));
196
200
  try {
197
201
  for (var _b = __values(pubkey.value.pubkeys.map(function (p) { return encodeAminoPubkey(p); })), _c = _b.next(); !_c.done; _c = _b.next()) {
198
202
  var pubkeyData = _c.value;
199
203
  out.push(0x12); // TODO: What is this?
200
204
  out.push.apply(// TODO: What is this?
201
- out, __spreadArray([], __read(encodeUvarint(pubkeyData.length))));
202
- out.push.apply(out, __spreadArray([], __read(pubkeyData)));
205
+ out, __spreadArray([], __read(encodeUvarint(pubkeyData.length)), false));
206
+ out.push.apply(out, __spreadArray([], __read(pubkeyData), false));
203
207
  }
204
208
  }
205
209
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -211,11 +215,11 @@ function encodeAminoPubkey(pubkey) {
211
215
  }
212
216
  return new Uint8Array(out);
213
217
  }
214
- else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
215
- return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixEd25519)), __read(encoding_1.fromBase64(pubkey.value))));
218
+ else if ((0, pubkeys_1.isEd25519Pubkey)(pubkey)) {
219
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixEd25519), false), __read((0, encoding_1.fromBase64)(pubkey.value)), false));
216
220
  }
217
- else if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
218
- return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixSecp256k1)), __read(encoding_1.fromBase64(pubkey.value))));
221
+ else if ((0, pubkeys_1.isSecp256k1Pubkey)(pubkey)) {
222
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixSecp256k1), false), __read((0, encoding_1.fromBase64)(pubkey.value)), false));
219
223
  }
220
224
  else {
221
225
  throw new Error("Unsupported pubkey type");