@firmachain/firma-js 0.3.5 → 0.3.6

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 (28) hide show
  1. package/dist/sdk/FirmaUtil.d.ts +21 -19
  2. package/dist/sdk/FirmaUtil.js +116 -151
  3. package/dist/sdk/FirmaWalletService.d.ts +0 -3
  4. package/dist/sdk/FirmaWalletService.js +11 -19
  5. package/dist/sdk/firmachain/common/ITxClient.d.ts +3 -1
  6. package/dist/sdk/firmachain/common/ITxClient.js +18 -4
  7. package/dist/sdk/firmachain/common/LedgerWallet.js +1 -1
  8. package/dist/sdk/firmachain/common/SigningProtobufStargateClient.d.ts +34 -0
  9. package/dist/sdk/firmachain/common/SigningProtobufStargateClient.js +319 -0
  10. package/dist/sdk/firmachain/common/SigningStargateClient.d.ts +37 -0
  11. package/dist/sdk/firmachain/common/SigningStargateClient.js +322 -0
  12. package/dist/sdk/firmachain/common/StargateClient.d.ts +161 -0
  13. package/dist/sdk/firmachain/common/StargateClient.js +433 -0
  14. package/dist/sdk/firmachain/common/TxCommon.d.ts +2 -16
  15. package/dist/sdk/firmachain/common/accounts.d.ts +4 -0
  16. package/dist/sdk/firmachain/common/events.d.ts +36 -0
  17. package/dist/sdk/firmachain/common/events.js +18 -0
  18. package/dist/sdk/firmachain/common/fee.d.ts +26 -0
  19. package/dist/sdk/firmachain/common/fee.js +90 -0
  20. package/dist/sdk/firmachain/common/signing.d.ts +19 -0
  21. package/dist/sdk/firmachain/common/signing.js +132 -0
  22. package/dist/test/26.cosmwasm_query.test.js +1 -3
  23. package/dist/test/27.arbitrary_sign.test.js +61 -30
  24. package/dist/test/config_test.d.ts +9 -9
  25. package/dist/test/config_test.js +27 -26
  26. package/package.json +1 -1
  27. package/dist/sdk/firmachain/common/coins.d.ts +0 -30
  28. package/dist/sdk/firmachain/common/coins.js +0 -69
@@ -0,0 +1,433 @@
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 __values = (this && this.__values) || function(o) {
54
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
55
+ if (m) return m.call(o);
56
+ if (o && typeof o.length === "number") return {
57
+ next: function () {
58
+ if (o && i >= o.length) o = void 0;
59
+ return { value: o && o[i++], done: !o };
60
+ }
61
+ };
62
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.StargateClient = exports.BroadcastTxError = exports.assertIsDeliverTxFailure = exports.assertIsDeliverTxSuccess = exports.isBroadcastTxSuccess = exports.isBroadcastTxFailure = exports.isDeliverTxSuccess = exports.isDeliverTxFailure = exports.TimeoutError = void 0;
66
+ /* eslint-disable @typescript-eslint/naming-convention */
67
+ var encoding_1 = require("@cosmjs/encoding");
68
+ var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
69
+ var utils_1 = require("@cosmjs/utils");
70
+ var stargate_1 = require("@cosmjs/stargate");
71
+ var accounts_1 = require("./accounts");
72
+ var events_1 = require("./events");
73
+ var TimeoutError = /** @class */ (function (_super) {
74
+ __extends(TimeoutError, _super);
75
+ function TimeoutError(message, txId) {
76
+ var _this = _super.call(this, message) || this;
77
+ _this.txId = txId;
78
+ return _this;
79
+ }
80
+ return TimeoutError;
81
+ }(Error));
82
+ exports.TimeoutError = TimeoutError;
83
+ function isDeliverTxFailure(result) {
84
+ return !!result.code;
85
+ }
86
+ exports.isDeliverTxFailure = isDeliverTxFailure;
87
+ function isDeliverTxSuccess(result) {
88
+ return !isDeliverTxFailure(result);
89
+ }
90
+ exports.isDeliverTxSuccess = isDeliverTxSuccess;
91
+ function isBroadcastTxFailure(result) {
92
+ return !!result.code;
93
+ }
94
+ exports.isBroadcastTxFailure = isBroadcastTxFailure;
95
+ function isBroadcastTxSuccess(result) {
96
+ return !isBroadcastTxFailure(result);
97
+ }
98
+ exports.isBroadcastTxSuccess = isBroadcastTxSuccess;
99
+ /**
100
+ * Ensures the given result is a success. Throws a detailed error message otherwise.
101
+ */
102
+ function assertIsDeliverTxSuccess(result) {
103
+ if (isDeliverTxFailure(result)) {
104
+ throw new Error("Error when broadcasting tx ".concat(result.transactionHash, " at height ").concat(result.height, ". Code: ").concat(result.code, "; Check events for details."));
105
+ }
106
+ }
107
+ exports.assertIsDeliverTxSuccess = assertIsDeliverTxSuccess;
108
+ /**
109
+ * Ensures the given result is a failure. Throws a detailed error message otherwise.
110
+ */
111
+ function assertIsDeliverTxFailure(result) {
112
+ if (isDeliverTxSuccess(result)) {
113
+ throw new Error("Transaction ".concat(result.transactionHash, " did not fail at height ").concat(result.height, ". Code: ").concat(result.code, "; Check events for details."));
114
+ }
115
+ }
116
+ exports.assertIsDeliverTxFailure = assertIsDeliverTxFailure;
117
+ /**
118
+ * An error when broadcasting the transaction. This contains the CheckTx errors
119
+ * from the blockchain. Once a transaction is included in a block no BroadcastTxError
120
+ * is thrown, even if the execution fails (DeliverTx errors).
121
+ */
122
+ var BroadcastTxError = /** @class */ (function (_super) {
123
+ __extends(BroadcastTxError, _super);
124
+ function BroadcastTxError(code, codespace, log) {
125
+ var _this = _super.call(this, "Broadcasting transaction failed with code ".concat(code, " (codespace: ").concat(codespace, "). Log: ").concat(log)) || this;
126
+ _this.code = code;
127
+ _this.codespace = codespace;
128
+ _this.log = log;
129
+ return _this;
130
+ }
131
+ return BroadcastTxError;
132
+ }(Error));
133
+ exports.BroadcastTxError = BroadcastTxError;
134
+ /**
135
+ * Extracts message responses from transaction events.
136
+ * In Cosmos SDK v0.50+, message responses are embedded in events rather than separate data fields.
137
+ */
138
+ function extractMsgResponsesFromEvents(events) {
139
+ var e_1, _a, e_2, _b;
140
+ var msgResponses = [];
141
+ try {
142
+ for (var events_2 = __values(events), events_2_1 = events_2.next(); !events_2_1.done; events_2_1 = events_2.next()) {
143
+ var event_1 = events_2_1.value;
144
+ if (event_1.type === "message") {
145
+ try {
146
+ // Look for message response data in message events
147
+ for (var _c = (e_2 = void 0, __values(event_1.attributes)), _d = _c.next(); !_d.done; _d = _c.next()) {
148
+ var attr = _d.value;
149
+ if (attr.key === "module" || attr.key === "action") {
150
+ // Extract type information for message responses
151
+ var typeUrl = "/cosmos.".concat(attr.value);
152
+ msgResponses.push({
153
+ typeUrl: typeUrl,
154
+ value: new Uint8Array(), // In v0.50, detailed response data is in other events
155
+ });
156
+ }
157
+ }
158
+ }
159
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
160
+ finally {
161
+ try {
162
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
163
+ }
164
+ finally { if (e_2) throw e_2.error; }
165
+ }
166
+ }
167
+ }
168
+ }
169
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
170
+ finally {
171
+ try {
172
+ if (events_2_1 && !events_2_1.done && (_a = events_2.return)) _a.call(events_2);
173
+ }
174
+ finally { if (e_1) throw e_1.error; }
175
+ }
176
+ return msgResponses;
177
+ }
178
+ var StargateClient = /** @class */ (function () {
179
+ function StargateClient(cometClient, options) {
180
+ if (options === void 0) { options = {}; }
181
+ if (cometClient) {
182
+ this.cometClient = cometClient;
183
+ this.queryClient = stargate_1.QueryClient.withExtensions(cometClient, stargate_1.setupAuthExtension, stargate_1.setupBankExtension, stargate_1.setupStakingExtension, stargate_1.setupTxExtension);
184
+ }
185
+ var _a = options.accountParser, accountParser = _a === void 0 ? accounts_1.accountFromAny : _a;
186
+ this.accountParser = accountParser;
187
+ }
188
+ /**
189
+ * Creates an instance by connecting to the given CometBFT RPC endpoint.
190
+ *
191
+ * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client.
192
+ * To set the Comet client explicitly, use `create`.
193
+ */
194
+ StargateClient.connect = function (endpoint, options) {
195
+ if (options === void 0) { options = {}; }
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var cometClient;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0: return [4 /*yield*/, (0, tendermint_rpc_1.connectComet)(endpoint)];
201
+ case 1:
202
+ cometClient = _a.sent();
203
+ return [2 /*return*/, StargateClient.create(cometClient, options)];
204
+ }
205
+ });
206
+ });
207
+ };
208
+ /**
209
+ * Creates an instance from a manually created Comet client.
210
+ * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
211
+ */
212
+ StargateClient.create = function (cometClient, options) {
213
+ if (options === void 0) { options = {}; }
214
+ return __awaiter(this, void 0, void 0, function () {
215
+ return __generator(this, function (_a) {
216
+ return [2 /*return*/, new StargateClient(cometClient, options)];
217
+ });
218
+ });
219
+ };
220
+ StargateClient.prototype.getCometClient = function () {
221
+ return this.cometClient;
222
+ };
223
+ StargateClient.prototype.forceGetCometClient = function () {
224
+ if (!this.cometClient) {
225
+ throw new Error("Comet client not available. You cannot use online functionality in offline mode.");
226
+ }
227
+ return this.cometClient;
228
+ };
229
+ StargateClient.prototype.getQueryClient = function () {
230
+ return this.queryClient;
231
+ };
232
+ StargateClient.prototype.forceGetQueryClient = function () {
233
+ if (!this.queryClient) {
234
+ throw new Error("Query client not available. You cannot use online functionality in offline mode.");
235
+ }
236
+ return this.queryClient;
237
+ };
238
+ StargateClient.prototype.getChainId = function () {
239
+ return __awaiter(this, void 0, void 0, function () {
240
+ var response, chainId;
241
+ return __generator(this, function (_a) {
242
+ switch (_a.label) {
243
+ case 0:
244
+ if (!!this.chainId) return [3 /*break*/, 2];
245
+ return [4 /*yield*/, this.forceGetCometClient().status()];
246
+ case 1:
247
+ response = _a.sent();
248
+ chainId = response.nodeInfo.network;
249
+ if (!chainId)
250
+ throw new Error("Chain ID must not be empty");
251
+ this.chainId = chainId;
252
+ _a.label = 2;
253
+ case 2: return [2 /*return*/, this.chainId];
254
+ }
255
+ });
256
+ });
257
+ };
258
+ StargateClient.prototype.getHeight = function () {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var status;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0: return [4 /*yield*/, this.forceGetCometClient().status()];
264
+ case 1:
265
+ status = _a.sent();
266
+ return [2 /*return*/, status.syncInfo.latestBlockHeight];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ StargateClient.prototype.getAccount = function (searchAddress) {
272
+ return __awaiter(this, void 0, void 0, function () {
273
+ var account, error_1;
274
+ return __generator(this, function (_a) {
275
+ switch (_a.label) {
276
+ case 0:
277
+ _a.trys.push([0, 2, , 3]);
278
+ return [4 /*yield*/, this.forceGetQueryClient().auth.account(searchAddress)];
279
+ case 1:
280
+ account = _a.sent();
281
+ return [2 /*return*/, account ? this.accountParser(account) : null];
282
+ case 2:
283
+ error_1 = _a.sent();
284
+ if (/rpc error: code = NotFound/i.test(error_1.toString())) {
285
+ return [2 /*return*/, null];
286
+ }
287
+ throw error_1;
288
+ case 3: return [2 /*return*/];
289
+ }
290
+ });
291
+ });
292
+ };
293
+ StargateClient.prototype.getSequence = function (address) {
294
+ return __awaiter(this, void 0, void 0, function () {
295
+ var account;
296
+ return __generator(this, function (_a) {
297
+ switch (_a.label) {
298
+ case 0: return [4 /*yield*/, this.getAccount(address)];
299
+ case 1:
300
+ account = _a.sent();
301
+ if (!account) {
302
+ throw new Error("Account '".concat(address, "' does not exist on chain. Send some tokens there before trying to query sequence."));
303
+ }
304
+ return [2 /*return*/, {
305
+ accountNumber: account.accountNumber,
306
+ sequence: account.sequence,
307
+ }];
308
+ }
309
+ });
310
+ });
311
+ };
312
+ StargateClient.prototype.getTx = function (id) {
313
+ var _a;
314
+ return __awaiter(this, void 0, void 0, function () {
315
+ var results;
316
+ return __generator(this, function (_b) {
317
+ switch (_b.label) {
318
+ case 0: return [4 /*yield*/, this.txsQuery("tx.hash='".concat(id, "'"))];
319
+ case 1:
320
+ results = _b.sent();
321
+ return [2 /*return*/, (_a = results[0]) !== null && _a !== void 0 ? _a : null];
322
+ }
323
+ });
324
+ });
325
+ };
326
+ StargateClient.prototype.disconnect = function () {
327
+ if (this.cometClient)
328
+ this.cometClient.disconnect();
329
+ };
330
+ /**
331
+ * Broadcasts a signed transaction to the network and monitors its inclusion in a block.
332
+ *
333
+ * If broadcasting is rejected by the node for some reason (e.g. because of a CheckTx failure),
334
+ * an error is thrown.
335
+ *
336
+ * If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
337
+ *
338
+ * If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
339
+ * usually needs to check for execution success or failure.
340
+ */
341
+ StargateClient.prototype.broadcastTx = function (tx, timeoutMs, pollIntervalMs) {
342
+ var _a;
343
+ if (timeoutMs === void 0) { timeoutMs = 60000; }
344
+ if (pollIntervalMs === void 0) { pollIntervalMs = 3000; }
345
+ return __awaiter(this, void 0, void 0, function () {
346
+ var timedOut, txPollTimeout, pollForTx, broadcasted, transactionId;
347
+ var _this = this;
348
+ return __generator(this, function (_b) {
349
+ switch (_b.label) {
350
+ case 0:
351
+ timedOut = false;
352
+ txPollTimeout = setTimeout(function () {
353
+ timedOut = true;
354
+ }, timeoutMs);
355
+ pollForTx = function (txId) { return __awaiter(_this, void 0, void 0, function () {
356
+ var result;
357
+ return __generator(this, function (_a) {
358
+ switch (_a.label) {
359
+ case 0:
360
+ if (timedOut) {
361
+ throw new TimeoutError("Transaction with ID ".concat(txId, " was submitted but was not yet found on the chain. You might want to check later. There was a wait of ").concat(timeoutMs / 1000, " seconds."), txId);
362
+ }
363
+ return [4 /*yield*/, (0, utils_1.sleep)(pollIntervalMs)];
364
+ case 1:
365
+ _a.sent();
366
+ return [4 /*yield*/, this.getTx(txId)];
367
+ case 2:
368
+ result = _a.sent();
369
+ return [2 /*return*/, result
370
+ ? {
371
+ code: result.code,
372
+ height: result.height,
373
+ txIndex: result.txIndex,
374
+ events: result.events,
375
+ transactionHash: txId,
376
+ msgResponses: result.msgResponses,
377
+ gasUsed: result.gasUsed,
378
+ gasWanted: result.gasWanted,
379
+ }
380
+ : pollForTx(txId)];
381
+ }
382
+ });
383
+ }); };
384
+ return [4 /*yield*/, this.forceGetCometClient().broadcastTxSync({ tx: tx })];
385
+ case 1:
386
+ broadcasted = _b.sent();
387
+ if (broadcasted.code) {
388
+ return [2 /*return*/, Promise.reject(new BroadcastTxError(broadcasted.code, (_a = broadcasted.codespace) !== null && _a !== void 0 ? _a : "", broadcasted.log))];
389
+ }
390
+ transactionId = (0, encoding_1.toHex)(broadcasted.hash).toUpperCase();
391
+ return [2 /*return*/, new Promise(function (resolve, reject) {
392
+ return pollForTx(transactionId).then(function (value) {
393
+ clearTimeout(txPollTimeout);
394
+ resolve(value);
395
+ }, function (error) {
396
+ clearTimeout(txPollTimeout);
397
+ reject(error);
398
+ });
399
+ })];
400
+ }
401
+ });
402
+ });
403
+ };
404
+ StargateClient.prototype.txsQuery = function (query) {
405
+ return __awaiter(this, void 0, void 0, function () {
406
+ var results;
407
+ return __generator(this, function (_a) {
408
+ switch (_a.label) {
409
+ case 0: return [4 /*yield*/, this.forceGetCometClient().txSearchAll({ query: query })];
410
+ case 1:
411
+ results = _a.sent();
412
+ return [2 /*return*/, results.txs.map(function (tx) {
413
+ var events = tx.result.events.map(events_1.fromTendermintEvent);
414
+ var msgResponses = extractMsgResponsesFromEvents(events);
415
+ return {
416
+ height: tx.height,
417
+ txIndex: tx.index,
418
+ hash: (0, encoding_1.toHex)(tx.hash).toUpperCase(),
419
+ code: tx.result.code,
420
+ events: events,
421
+ tx: tx.tx,
422
+ msgResponses: msgResponses,
423
+ gasUsed: tx.result.gasUsed,
424
+ gasWanted: tx.result.gasWanted,
425
+ };
426
+ })];
427
+ }
428
+ });
429
+ });
430
+ };
431
+ return StargateClient;
432
+ }());
433
+ exports.StargateClient = StargateClient;
@@ -1,4 +1,4 @@
1
- import { StdFee } from "@cosmjs/stargate";
1
+ import { Fee } from "cosmjs-types/cosmos/tx/v1beta1/tx";
2
2
  export declare const DefaultBasicFeeGrantOption: {
3
3
  spendLimit: undefined;
4
4
  expiration: undefined;
@@ -10,7 +10,7 @@ export interface TxMisc {
10
10
  feeGranter?: string;
11
11
  }
12
12
  export interface SignAndBroadcastOptions {
13
- fee: StdFee;
13
+ fee: Fee;
14
14
  memo: string;
15
15
  }
16
16
  export interface MsgCreateValidator {
@@ -54,17 +54,3 @@ export declare enum VotingOption {
54
54
  VOTE_OPTION_NO_WITH_VETO = 4,
55
55
  UNRECOGNIZED = -1
56
56
  }
57
- export interface ArbitraryVerifyData {
58
- chainId: string;
59
- accountNumber: string;
60
- sequence: string;
61
- bodyBytes: string;
62
- authInfoBytes: string;
63
- signerAddress: string;
64
- pubkey: string;
65
- signature: string;
66
- }
67
- export interface MsgSignArbitraryData {
68
- signer: string;
69
- data: Uint8Array;
70
- }
@@ -1,5 +1,9 @@
1
1
  import { Pubkey } from "@cosmjs/amino";
2
2
  import { Any } from "cosmjs-types/google/protobuf/any";
3
+ /**
4
+ * This file is copied from @cosmjs/stargate.
5
+ * https://github.com/cosmos/cosmjs/blob/v0.34.0/packages/stargate/src/accounts.ts
6
+ */
3
7
  export interface Account {
4
8
  /** Bech32 account address */
5
9
  readonly address: string;
@@ -0,0 +1,36 @@
1
+ import { tendermint34, tendermint37 } from "@cosmjs/tendermint-rpc";
2
+ /**
3
+ * This file is copied from @cosmjs/stargate.
4
+ * https://github.com/cosmos/cosmjs/blob/v0.34.0/packages/stargate/src/events.ts
5
+ */
6
+ /**
7
+ * An event attribute.
8
+ *
9
+ * This is the same attribute type as tendermint34.Attribute and tendermint35.EventAttribute
10
+ * but `key` and `value` are unified to strings. The conversion
11
+ * from bytes to string in the Tendermint 0.34 case should be done by performing
12
+ * [lossy] UTF-8 decoding.
13
+ *
14
+ * [lossy]: https://doc.rust-lang.org/stable/std/string/struct.String.html#method.from_utf8_lossy
15
+ */
16
+ export interface Attribute {
17
+ readonly key: string;
18
+ readonly value: string;
19
+ }
20
+ /**
21
+ * The same event type as tendermint34.Event and tendermint35.Event
22
+ * but attribute keys and values are unified to strings. The conversion
23
+ * from bytes to string in the Tendermint 0.34 case should be done by performing
24
+ * [lossy] UTF-8 decoding.
25
+ *
26
+ * [lossy]: https://doc.rust-lang.org/stable/std/string/struct.String.html#method.from_utf8_lossy
27
+ */
28
+ export interface Event {
29
+ readonly type: string;
30
+ readonly attributes: readonly Attribute[];
31
+ }
32
+ /**
33
+ * Takes a Tendermint 0.34 or 0.37 event with binary encoded key and value
34
+ * and converts it into an `Event` with string attributes.
35
+ */
36
+ export declare function fromTendermintEvent(event: tendermint34.Event | tendermint37.Event): Event;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fromTendermintEvent = void 0;
4
+ var encoding_1 = require("@cosmjs/encoding");
5
+ /**
6
+ * Takes a Tendermint 0.34 or 0.37 event with binary encoded key and value
7
+ * and converts it into an `Event` with string attributes.
8
+ */
9
+ function fromTendermintEvent(event) {
10
+ return {
11
+ type: event.type,
12
+ attributes: event.attributes.map(function (attr) { return ({
13
+ key: typeof attr.key == "string" ? attr.key : (0, encoding_1.fromUtf8)(attr.key, true),
14
+ value: typeof attr.value == "string" ? attr.value : (0, encoding_1.fromUtf8)(attr.value, true),
15
+ }); }),
16
+ };
17
+ }
18
+ exports.fromTendermintEvent = fromTendermintEvent;
@@ -0,0 +1,26 @@
1
+ import { Decimal } from "@cosmjs/math";
2
+ import { Fee } from "cosmjs-types/cosmos/tx/v1beta1/tx";
3
+ /**
4
+ * A gas price, i.e. the price of a single unit of gas. This is typically a fraction of
5
+ * the smallest fee token unit, such as 0.012utoken.
6
+ */
7
+ export declare class GasPrice {
8
+ readonly amount: Decimal;
9
+ readonly denom: string;
10
+ constructor(amount: Decimal, denom: string);
11
+ /**
12
+ * Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString("0.012utoken")`.
13
+ *
14
+ * The denom must match the Cosmos SDK 0.42 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).
15
+ * See `GasPrice` in @cosmjs/stargate for a more generic matcher.
16
+ *
17
+ * Separators are not yet supported.
18
+ */
19
+ static fromString(gasPrice: string): GasPrice;
20
+ /**
21
+ * Returns a string representation of this gas price, e.g. "0.025uatom".
22
+ * This can be used as an input to `GasPrice.fromString`.
23
+ */
24
+ toString(): string;
25
+ }
26
+ export declare function calculateFee(gasLimit: number, gasPrice: GasPrice | string): Fee;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.calculateFee = exports.GasPrice = void 0;
20
+ var math_1 = require("@cosmjs/math");
21
+ var proto_signing_1 = require("@cosmjs/proto-signing");
22
+ /**
23
+ * This file is copied from @cosmjs/stargate.
24
+ * https://github.com/cosmos/cosmjs/blob/v0.34.0/packages/stargate/src/fee.ts
25
+ * For future support of next version of cosmos and cosmjs. Not used in this project and firmachain ecosystem for now.
26
+ */
27
+ /**
28
+ * Denom checker for the Cosmos SDK 0.42 denom pattern
29
+ * (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).
30
+ *
31
+ * This is like a regexp but with helpful error messages.
32
+ */
33
+ function checkDenom(denom) {
34
+ if (denom.length < 3 || denom.length > 128) {
35
+ throw new Error("Denom must be between 3 and 128 characters");
36
+ }
37
+ }
38
+ /**
39
+ * A gas price, i.e. the price of a single unit of gas. This is typically a fraction of
40
+ * the smallest fee token unit, such as 0.012utoken.
41
+ */
42
+ var GasPrice = /** @class */ (function () {
43
+ function GasPrice(amount, denom) {
44
+ this.amount = amount;
45
+ this.denom = denom;
46
+ }
47
+ /**
48
+ * Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString("0.012utoken")`.
49
+ *
50
+ * The denom must match the Cosmos SDK 0.42 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).
51
+ * See `GasPrice` in @cosmjs/stargate for a more generic matcher.
52
+ *
53
+ * Separators are not yet supported.
54
+ */
55
+ GasPrice.fromString = function (gasPrice) {
56
+ // Use Decimal.fromUserInput and checkDenom for detailed checks and helpful error messages
57
+ var matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
58
+ if (!matchResult) {
59
+ throw new Error("Invalid gas price string");
60
+ }
61
+ var _a = __read(matchResult, 3), _ = _a[0], amount = _a[1], denom = _a[2];
62
+ checkDenom(denom);
63
+ var fractionalDigits = 18;
64
+ var decimalAmount = math_1.Decimal.fromUserInput(amount, fractionalDigits);
65
+ return new GasPrice(decimalAmount, denom);
66
+ };
67
+ /**
68
+ * Returns a string representation of this gas price, e.g. "0.025uatom".
69
+ * This can be used as an input to `GasPrice.fromString`.
70
+ */
71
+ GasPrice.prototype.toString = function () {
72
+ return this.amount.toString() + this.denom;
73
+ };
74
+ return GasPrice;
75
+ }());
76
+ exports.GasPrice = GasPrice;
77
+ function calculateFee(gasLimit, gasPrice) {
78
+ var processedGasPrice = typeof gasPrice === "string" ? GasPrice.fromString(gasPrice) : gasPrice;
79
+ var denom = processedGasPrice.denom, gasPriceAmount = processedGasPrice.amount;
80
+ // Note: Amount can exceed the safe integer range (https://github.com/cosmos/cosmjs/issues/1134),
81
+ // which we handle by converting from Decimal to string without going through number.
82
+ var amount = gasPriceAmount.multiply(new math_1.Uint53(gasLimit)).ceil().toString();
83
+ return {
84
+ gasLimit: BigInt(gasLimit),
85
+ amount: (0, proto_signing_1.coins)(amount, denom),
86
+ payer: "",
87
+ granter: ""
88
+ };
89
+ }
90
+ exports.calculateFee = calculateFee;
@@ -0,0 +1,19 @@
1
+ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
2
+ import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
3
+ import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
4
+ import { Any } from "cosmjs-types/google/protobuf/any";
5
+ export interface SignerData {
6
+ readonly pubkey: Any;
7
+ readonly sequence: number;
8
+ }
9
+ export declare function makeAuthInfoBytes(signers: ReadonlyArray<SignerData>, feeAmount: readonly Coin[], gasLimit: number, granter?: string, payer?: string, signMode?: SignMode): Uint8Array;
10
+ export declare function makeSignDoc(bodyBytes: Uint8Array, authInfoBytes: Uint8Array, chainId: string, accountNumber: number): SignDoc;
11
+ export declare function makeSignBytes(signDoc: SignDoc): Uint8Array;
12
+ /**
13
+ * Creates AuthInfo bytes for protobuf signing with enhanced type safety
14
+ */
15
+ export declare function makeAuthInfoBytesProtobuf(signers: ReadonlyArray<SignerData>, feeAmount: readonly Coin[], gasLimit: bigint | number, granter?: string, payer?: string): Uint8Array;
16
+ /**
17
+ * Creates a protobuf SignDoc with validation
18
+ */
19
+ export declare function makeSignDocProtobuf(bodyBytes: Uint8Array, authInfoBytes: Uint8Array, chainId: string, accountNumber: bigint | number): SignDoc;