@firmachain/firma-js 0.2.19 → 0.2.23

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 (157) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +136 -136
  3. package/dist/index.d.ts +4 -4
  4. package/dist/index.js +16 -16
  5. package/dist/sdk/FirmaBankService.d.ts +15 -15
  6. package/dist/sdk/FirmaBankService.js +211 -211
  7. package/dist/sdk/FirmaChainService.d.ts +8 -8
  8. package/dist/sdk/FirmaChainService.js +86 -86
  9. package/dist/sdk/FirmaConfig.d.ts +18 -16
  10. package/dist/sdk/FirmaConfig.js +63 -55
  11. package/dist/sdk/FirmaContractService.d.ts +31 -30
  12. package/dist/sdk/FirmaContractService.js +413 -394
  13. package/dist/sdk/FirmaDistributionService.d.ts +31 -31
  14. package/dist/sdk/FirmaDistributionService.js +524 -524
  15. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -21
  16. package/dist/sdk/FirmaFeeGrantService.js +341 -341
  17. package/dist/sdk/FirmaGovService.d.ts +35 -35
  18. package/dist/sdk/FirmaGovService.js +775 -775
  19. package/dist/sdk/FirmaIpfsService.d.ts +12 -12
  20. package/dist/sdk/FirmaIpfsService.js +185 -185
  21. package/dist/sdk/FirmaMobileSDK.d.ts +27 -27
  22. package/dist/sdk/FirmaMobileSDK.js +45 -45
  23. package/dist/sdk/FirmaNftService.d.ts +31 -28
  24. package/dist/sdk/FirmaNftService.js +372 -390
  25. package/dist/sdk/FirmaSDK.d.ts +29 -29
  26. package/dist/sdk/FirmaSDK.js +48 -48
  27. package/dist/sdk/FirmaSlashingService.d.ts +9 -9
  28. package/dist/sdk/FirmaSlashingService.js +105 -105
  29. package/dist/sdk/FirmaStakingService.d.ts +34 -34
  30. package/dist/sdk/FirmaStakingService.js +604 -604
  31. package/dist/sdk/FirmaTokenService.d.ts +26 -26
  32. package/dist/sdk/FirmaTokenService.js +416 -416
  33. package/dist/sdk/FirmaUtil.d.ts +35 -25
  34. package/dist/sdk/FirmaUtil.js +226 -201
  35. package/dist/sdk/FirmaWalletService.d.ts +36 -36
  36. package/dist/sdk/FirmaWalletService.js +309 -309
  37. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -5
  38. package/dist/sdk/firmachain/amino/addresses.js +46 -46
  39. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -281
  40. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -77
  41. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -22
  42. package/dist/sdk/firmachain/amino/aminotypes.js +521 -521
  43. package/dist/sdk/firmachain/amino/coins.d.ts +30 -30
  44. package/dist/sdk/firmachain/amino/coins.js +69 -69
  45. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -24
  46. package/dist/sdk/firmachain/amino/encoding.js +234 -234
  47. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -10
  48. package/dist/sdk/firmachain/amino/multisig.js +42 -42
  49. package/dist/sdk/firmachain/amino/paths.d.ts +6 -6
  50. package/dist/sdk/firmachain/amino/paths.js +18 -18
  51. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -47
  52. package/dist/sdk/firmachain/amino/pubkeys.js +29 -29
  53. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -94
  54. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -437
  55. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -23
  56. package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -141
  57. package/dist/sdk/firmachain/amino/signature.d.ts +16 -16
  58. package/dist/sdk/firmachain/amino/signature.js +36 -36
  59. package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -26
  60. package/dist/sdk/firmachain/amino/signdoc.js +42 -42
  61. package/dist/sdk/firmachain/amino/signer.d.ts +33 -33
  62. package/dist/sdk/firmachain/amino/signer.js +2 -2
  63. package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -15
  64. package/dist/sdk/firmachain/amino/stdtx.js +17 -17
  65. package/dist/sdk/firmachain/amino/wallet.d.ts +32 -32
  66. package/dist/sdk/firmachain/amino/wallet.js +132 -132
  67. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -12
  68. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -116
  69. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -17
  70. package/dist/sdk/firmachain/bank/BankTxClient.js +40 -40
  71. package/dist/sdk/firmachain/bank/index.d.ts +3 -3
  72. package/dist/sdk/firmachain/bank/index.js +15 -15
  73. package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -15
  74. package/dist/sdk/firmachain/common/ITxClient.js +102 -102
  75. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -27
  76. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -165
  77. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -14
  78. package/dist/sdk/firmachain/common/LedgerWallet.js +147 -147
  79. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -4
  80. package/dist/sdk/firmachain/common/QueryCommon.js +2 -2
  81. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -42
  82. package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -108
  83. package/dist/sdk/firmachain/common/TxCommon.d.ts +87 -94
  84. package/dist/sdk/firmachain/common/TxCommon.js +18 -34
  85. package/dist/sdk/firmachain/common/accounts.d.ts +16 -16
  86. package/dist/sdk/firmachain/common/accounts.js +64 -64
  87. package/dist/sdk/firmachain/common/index.d.ts +2 -2
  88. package/dist/sdk/firmachain/common/index.js +14 -14
  89. package/dist/sdk/firmachain/common/signing.d.ts +10 -10
  90. package/dist/sdk/firmachain/common/signing.js +75 -75
  91. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -37
  92. package/dist/sdk/firmachain/common/signingstargateclient.js +298 -298
  93. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -46
  94. package/dist/sdk/firmachain/common/stargateclient.js +211 -211
  95. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -31
  96. package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -141
  97. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -17
  98. package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -40
  99. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -69
  100. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -483
  101. package/dist/sdk/firmachain/contract/index.d.ts +3 -3
  102. package/dist/sdk/firmachain/contract/index.js +15 -15
  103. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -18
  104. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -167
  105. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -27
  106. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -48
  107. package/dist/sdk/firmachain/distribution/index.d.ts +3 -3
  108. package/dist/sdk/firmachain/distribution/index.js +15 -15
  109. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -17
  110. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -86
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -17
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -40
  113. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -76
  114. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -194
  115. package/dist/sdk/firmachain/feegrant/index.d.ts +2 -2
  116. package/dist/sdk/firmachain/feegrant/index.js +15 -15
  117. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -128
  118. package/dist/sdk/firmachain/google/protobuf/any.js +106 -106
  119. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -996
  120. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -5329
  121. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -91
  122. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -107
  123. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -109
  124. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -107
  125. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -61
  126. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -152
  127. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -22
  128. package/dist/sdk/firmachain/gov/GovTxClient.js +44 -44
  129. package/dist/sdk/firmachain/gov/index.d.ts +3 -3
  130. package/dist/sdk/firmachain/gov/index.js +15 -15
  131. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -17
  132. package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -121
  133. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -22
  134. package/dist/sdk/firmachain/nft/NftTxClient.js +44 -44
  135. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -86
  136. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -424
  137. package/dist/sdk/firmachain/nft/index.d.ts +3 -3
  138. package/dist/sdk/firmachain/nft/index.js +15 -15
  139. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -22
  140. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -101
  141. package/dist/sdk/firmachain/slashing/index.d.ts +2 -2
  142. package/dist/sdk/firmachain/slashing/index.js +14 -14
  143. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -93
  144. package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -223
  145. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -32
  146. package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -52
  147. package/dist/sdk/firmachain/staking/index.d.ts +3 -3
  148. package/dist/sdk/firmachain/staking/index.js +15 -15
  149. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -24
  150. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -106
  151. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -27
  152. package/dist/sdk/firmachain/token/TokenTxClient.js +48 -48
  153. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -116
  154. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -685
  155. package/dist/sdk/firmachain/token/index.d.ts +3 -3
  156. package/dist/sdk/firmachain/token/index.js +15 -15
  157. package/package.json +54 -54
@@ -1,298 +1,298 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __read = (this && this.__read) || function (o, n) {
54
- var m = typeof Symbol === "function" && o[Symbol.iterator];
55
- if (!m) return o;
56
- var i = m.call(o), r, ar = [], e;
57
- try {
58
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
- }
60
- catch (error) { e = { error: error }; }
61
- finally {
62
- try {
63
- if (r && !r.done && (m = i["return"])) m.call(i);
64
- }
65
- finally { if (e) throw e.error; }
66
- }
67
- return ar;
68
- };
69
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
70
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
71
- to[j] = from[i];
72
- return to;
73
- };
74
- var __importDefault = (this && this.__importDefault) || function (mod) {
75
- return (mod && mod.__esModule) ? mod : { "default": mod };
76
- };
77
- Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.SigningStargateClient = void 0;
79
- var encoding_1 = require("@cosmjs/encoding");
80
- var encoding_2 = require("@cosmjs/encoding");
81
- var proto_signing_1 = require("@cosmjs/proto-signing");
82
- var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
83
- var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
84
- var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
85
- var accounts_1 = require("./accounts");
86
- var stargateclient_1 = require("./stargateclient");
87
- var axios_1 = __importDefault(require("axios"));
88
- var math_1 = require("@cosmjs/math");
89
- var any_1 = require("../google/protobuf/any");
90
- var long_1 = __importDefault(require("long"));
91
- var encoding_3 = require("../amino/encoding");
92
- var SigningStargateClient = /** @class */ (function (_super) {
93
- __extends(SigningStargateClient, _super);
94
- function SigningStargateClient(tmClient, signer, registry) {
95
- var _this = _super.call(this, tmClient) || this;
96
- _this.registry = registry;
97
- _this.signer = signer;
98
- return _this;
99
- }
100
- SigningStargateClient.connectWithSigner = function (endpoint, signer, registry) {
101
- return __awaiter(this, void 0, void 0, function () {
102
- var tmClient;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0:
106
- this._endpoint = endpoint;
107
- return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
108
- case 1:
109
- tmClient = _a.sent();
110
- return [2 /*return*/, new SigningStargateClient(tmClient, signer, registry)];
111
- }
112
- });
113
- });
114
- };
115
- SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
116
- if (memo === void 0) { memo = ""; }
117
- return __awaiter(this, void 0, void 0, function () {
118
- var txRaw, txBytes;
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
122
- case 1:
123
- txRaw = _a.sent();
124
- txBytes = tx_1.TxRaw.encode(txRaw).finish();
125
- return [2 /*return*/, this.broadcastTx(txBytes)];
126
- }
127
- });
128
- });
129
- };
130
- SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
131
- return __awaiter(this, void 0, void 0, function () {
132
- var signerData, _a, accountNumber, sequence, chainId;
133
- return __generator(this, function (_b) {
134
- switch (_b.label) {
135
- case 0:
136
- if (!explicitSignerData) return [3 /*break*/, 1];
137
- signerData = explicitSignerData;
138
- return [3 /*break*/, 4];
139
- case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
140
- case 2:
141
- _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
142
- return [4 /*yield*/, this.getChainId()];
143
- case 3:
144
- chainId = _b.sent();
145
- signerData = {
146
- accountNumber: accountNumber,
147
- sequence: sequence,
148
- chainId: chainId,
149
- };
150
- _b.label = 4;
151
- case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
152
- }
153
- });
154
- });
155
- };
156
- SigningStargateClient.prototype.getChainId = function () {
157
- return __awaiter(this, void 0, void 0, function () {
158
- var response, chainId;
159
- return __generator(this, function (_a) {
160
- switch (_a.label) {
161
- case 0:
162
- if (!!this.chainId) return [3 /*break*/, 2];
163
- return [4 /*yield*/, this.forceGetTmClient().status()];
164
- case 1:
165
- response = _a.sent();
166
- chainId = response.nodeInfo.network;
167
- if (!chainId)
168
- throw new Error("Chain ID must not be empty");
169
- this.chainId = chainId;
170
- _a.label = 2;
171
- case 2: return [2 /*return*/, this.chainId];
172
- }
173
- });
174
- });
175
- };
176
- /**
177
- * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
178
- * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
179
- * The result is typically 20 bytes long but not restricted to that.
180
- */
181
- SigningStargateClient.prototype.toAccAddress = function (address) {
182
- return encoding_2.Bech32.decode(address).data;
183
- };
184
- SigningStargateClient.prototype.getAccount = function (address) {
185
- return __awaiter(this, void 0, void 0, function () {
186
- var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
187
- return __generator(this, function (_a) {
188
- switch (_a.label) {
189
- case 0:
190
- _a.trys.push([0, 2, , 3]);
191
- accAddress = this.toAccAddress(address);
192
- hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
193
- axios = axios_1.default.create({
194
- baseURL: SigningStargateClient._endpoint,
195
- headers: {
196
- Accept: "application/json",
197
- },
198
- timeout: 15000
199
- });
200
- path = "/abci_query?path=\"/store/acc/key\"";
201
- return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
202
- case 1:
203
- result = _a.sent();
204
- finalData = result.data.result.response.value;
205
- account = any_1.Any.decode(Buffer.from(finalData, "base64"));
206
- finalAccount = accounts_1.accountFromAny(account);
207
- return [2 /*return*/, finalAccount];
208
- case 2:
209
- error_1 = _a.sent();
210
- return [2 /*return*/, undefined];
211
- case 3: return [2 /*return*/];
212
- }
213
- });
214
- });
215
- };
216
- SigningStargateClient.prototype.getSequence = function (address) {
217
- return __awaiter(this, void 0, void 0, function () {
218
- var account;
219
- return __generator(this, function (_a) {
220
- switch (_a.label) {
221
- case 0: return [4 /*yield*/, this.getAccount(address)];
222
- case 1:
223
- account = _a.sent();
224
- if (!account) {
225
- throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
226
- }
227
- return [2 /*return*/, {
228
- accountNumber: account.accountNumber,
229
- sequence: account.sequence,
230
- }];
231
- }
232
- });
233
- });
234
- };
235
- SigningStargateClient.prototype.makeSignerInfos = function (signers, signMode) {
236
- return signers.map(function (_a) {
237
- var pubkey = _a.pubkey, sequence = _a.sequence;
238
- return ({
239
- publicKey: pubkey,
240
- modeInfo: {
241
- single: { mode: signMode },
242
- },
243
- sequence: long_1.default.fromNumber(sequence),
244
- });
245
- });
246
- };
247
- SigningStargateClient.prototype.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
248
- if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
249
- var authInfo = {
250
- signerInfos: this.makeSignerInfos(signers, signMode),
251
- fee: {
252
- amount: __spreadArray([], __read(feeAmount)),
253
- gasLimit: long_1.default.fromNumber(gasLimit),
254
- granter: granter,
255
- },
256
- };
257
- return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
258
- };
259
- SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
260
- var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
261
- return __awaiter(this, void 0, void 0, function () {
262
- var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
263
- return __generator(this, function (_c) {
264
- switch (_c.label) {
265
- case 0: return [4 /*yield*/, this.signer.getAccounts()];
266
- case 1:
267
- accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
268
- if (!accountFromSigner) {
269
- throw new Error("Failed to retrieve account from signer");
270
- }
271
- pubkey = proto_signing_1.encodePubkey(encoding_3.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
272
- txBodyEncodeObject = {
273
- typeUrl: "/cosmos.tx.v1beta1.TxBody",
274
- value: {
275
- messages: messages,
276
- memo: memo,
277
- },
278
- };
279
- txBodyBytes = this.registry.encode(txBodyEncodeObject);
280
- gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
281
- authInfoBytes = this.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
282
- signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
283
- return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
284
- case 2:
285
- _b = _c.sent(), signature = _b.signature, signed = _b.signed;
286
- return [2 /*return*/, tx_1.TxRaw.fromPartial({
287
- bodyBytes: signed.bodyBytes,
288
- authInfoBytes: signed.authInfoBytes,
289
- signatures: [encoding_1.fromBase64(signature.signature)],
290
- })];
291
- }
292
- });
293
- });
294
- };
295
- SigningStargateClient._endpoint = "";
296
- return SigningStargateClient;
297
- }(stargateclient_1.StargateClient));
298
- exports.SigningStargateClient = SigningStargateClient;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
70
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
71
+ to[j] = from[i];
72
+ return to;
73
+ };
74
+ var __importDefault = (this && this.__importDefault) || function (mod) {
75
+ return (mod && mod.__esModule) ? mod : { "default": mod };
76
+ };
77
+ Object.defineProperty(exports, "__esModule", { value: true });
78
+ exports.SigningStargateClient = void 0;
79
+ var encoding_1 = require("@cosmjs/encoding");
80
+ var encoding_2 = require("@cosmjs/encoding");
81
+ var proto_signing_1 = require("@cosmjs/proto-signing");
82
+ var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
83
+ var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
84
+ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
85
+ var accounts_1 = require("./accounts");
86
+ var stargateclient_1 = require("./stargateclient");
87
+ var axios_1 = __importDefault(require("axios"));
88
+ var math_1 = require("@cosmjs/math");
89
+ var any_1 = require("../google/protobuf/any");
90
+ var long_1 = __importDefault(require("long"));
91
+ var encoding_3 = require("../amino/encoding");
92
+ var SigningStargateClient = /** @class */ (function (_super) {
93
+ __extends(SigningStargateClient, _super);
94
+ function SigningStargateClient(tmClient, signer, registry) {
95
+ var _this = _super.call(this, tmClient) || this;
96
+ _this.registry = registry;
97
+ _this.signer = signer;
98
+ return _this;
99
+ }
100
+ SigningStargateClient.connectWithSigner = function (endpoint, signer, registry) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var tmClient;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ this._endpoint = endpoint;
107
+ return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
108
+ case 1:
109
+ tmClient = _a.sent();
110
+ return [2 /*return*/, new SigningStargateClient(tmClient, signer, registry)];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
116
+ if (memo === void 0) { memo = ""; }
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var txRaw, txBytes;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
122
+ case 1:
123
+ txRaw = _a.sent();
124
+ txBytes = tx_1.TxRaw.encode(txRaw).finish();
125
+ return [2 /*return*/, this.broadcastTx(txBytes)];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var signerData, _a, accountNumber, sequence, chainId;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ if (!explicitSignerData) return [3 /*break*/, 1];
137
+ signerData = explicitSignerData;
138
+ return [3 /*break*/, 4];
139
+ case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
140
+ case 2:
141
+ _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
142
+ return [4 /*yield*/, this.getChainId()];
143
+ case 3:
144
+ chainId = _b.sent();
145
+ signerData = {
146
+ accountNumber: accountNumber,
147
+ sequence: sequence,
148
+ chainId: chainId,
149
+ };
150
+ _b.label = 4;
151
+ case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
152
+ }
153
+ });
154
+ });
155
+ };
156
+ SigningStargateClient.prototype.getChainId = function () {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var response, chainId;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ if (!!this.chainId) return [3 /*break*/, 2];
163
+ return [4 /*yield*/, this.forceGetTmClient().status()];
164
+ case 1:
165
+ response = _a.sent();
166
+ chainId = response.nodeInfo.network;
167
+ if (!chainId)
168
+ throw new Error("Chain ID must not be empty");
169
+ this.chainId = chainId;
170
+ _a.label = 2;
171
+ case 2: return [2 /*return*/, this.chainId];
172
+ }
173
+ });
174
+ });
175
+ };
176
+ /**
177
+ * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
178
+ * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
179
+ * The result is typically 20 bytes long but not restricted to that.
180
+ */
181
+ SigningStargateClient.prototype.toAccAddress = function (address) {
182
+ return encoding_2.Bech32.decode(address).data;
183
+ };
184
+ SigningStargateClient.prototype.getAccount = function (address) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0:
190
+ _a.trys.push([0, 2, , 3]);
191
+ accAddress = this.toAccAddress(address);
192
+ hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
193
+ axios = axios_1.default.create({
194
+ baseURL: SigningStargateClient._endpoint,
195
+ headers: {
196
+ Accept: "application/json",
197
+ },
198
+ timeout: 15000
199
+ });
200
+ path = "/abci_query?path=\"/store/acc/key\"";
201
+ return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
202
+ case 1:
203
+ result = _a.sent();
204
+ finalData = result.data.result.response.value;
205
+ account = any_1.Any.decode(Buffer.from(finalData, "base64"));
206
+ finalAccount = accounts_1.accountFromAny(account);
207
+ return [2 /*return*/, finalAccount];
208
+ case 2:
209
+ error_1 = _a.sent();
210
+ return [2 /*return*/, undefined];
211
+ case 3: return [2 /*return*/];
212
+ }
213
+ });
214
+ });
215
+ };
216
+ SigningStargateClient.prototype.getSequence = function (address) {
217
+ return __awaiter(this, void 0, void 0, function () {
218
+ var account;
219
+ return __generator(this, function (_a) {
220
+ switch (_a.label) {
221
+ case 0: return [4 /*yield*/, this.getAccount(address)];
222
+ case 1:
223
+ account = _a.sent();
224
+ if (!account) {
225
+ throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
226
+ }
227
+ return [2 /*return*/, {
228
+ accountNumber: account.accountNumber,
229
+ sequence: account.sequence,
230
+ }];
231
+ }
232
+ });
233
+ });
234
+ };
235
+ SigningStargateClient.prototype.makeSignerInfos = function (signers, signMode) {
236
+ return signers.map(function (_a) {
237
+ var pubkey = _a.pubkey, sequence = _a.sequence;
238
+ return ({
239
+ publicKey: pubkey,
240
+ modeInfo: {
241
+ single: { mode: signMode },
242
+ },
243
+ sequence: long_1.default.fromNumber(sequence),
244
+ });
245
+ });
246
+ };
247
+ SigningStargateClient.prototype.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
248
+ if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
249
+ var authInfo = {
250
+ signerInfos: this.makeSignerInfos(signers, signMode),
251
+ fee: {
252
+ amount: __spreadArray([], __read(feeAmount)),
253
+ gasLimit: long_1.default.fromNumber(gasLimit),
254
+ granter: granter,
255
+ },
256
+ };
257
+ return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
258
+ };
259
+ SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
260
+ var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
263
+ return __generator(this, function (_c) {
264
+ switch (_c.label) {
265
+ case 0: return [4 /*yield*/, this.signer.getAccounts()];
266
+ case 1:
267
+ accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
268
+ if (!accountFromSigner) {
269
+ throw new Error("Failed to retrieve account from signer");
270
+ }
271
+ pubkey = proto_signing_1.encodePubkey(encoding_3.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
272
+ txBodyEncodeObject = {
273
+ typeUrl: "/cosmos.tx.v1beta1.TxBody",
274
+ value: {
275
+ messages: messages,
276
+ memo: memo,
277
+ },
278
+ };
279
+ txBodyBytes = this.registry.encode(txBodyEncodeObject);
280
+ gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
281
+ authInfoBytes = this.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
282
+ signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
283
+ return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
284
+ case 2:
285
+ _b = _c.sent(), signature = _b.signature, signed = _b.signed;
286
+ return [2 /*return*/, tx_1.TxRaw.fromPartial({
287
+ bodyBytes: signed.bodyBytes,
288
+ authInfoBytes: signed.authInfoBytes,
289
+ signatures: [encoding_1.fromBase64(signature.signature)],
290
+ })];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ SigningStargateClient._endpoint = "";
296
+ return SigningStargateClient;
297
+ }(stargateclient_1.StargateClient));
298
+ exports.SigningStargateClient = SigningStargateClient;