@firmachain/firma-js 0.3.5 → 0.3.6-beta1

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.
@@ -1,11 +1,12 @@
1
1
  import { SignDoc, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
2
2
  import { Duration } from "cosmjs-types/google/protobuf/duration";
3
3
  import { EncodeObject, Registry } from "@cosmjs/proto-signing";
4
- import { SignAndBroadcastOptions, TxMisc, ArbitraryVerifyData } from "./firmachain/common";
4
+ import { SignAndBroadcastOptions, TxMisc } from "./firmachain/common";
5
5
  import { FirmaConfig } from "./FirmaConfig";
6
6
  import { FirmaWalletService } from "./FirmaWalletService";
7
- import { Any } from "./firmachain/google/protobuf/any";
7
+ import { Any } from "cosmjs-types/google/protobuf/any";
8
8
  import { CommonTxClient } from "./firmachain/common/CommonTxClient";
9
+ import { ArbitraryVerifyData } from "./firmachain/common/signingprotobufstargateclient";
9
10
  export declare class FirmaUtil {
10
11
  static config: FirmaConfig;
11
12
  static readonly FctDecimal: number;
@@ -41,6 +42,24 @@ export declare class FirmaUtil {
41
42
  }>;
42
43
  static getChainId(): Promise<string>;
43
44
  static printLog(log: any): void;
45
+ /**
46
+ * ADR-036 protobuf arbitrary signing (wrapper for protobufArbitrarySign)
47
+ *
48
+ * @param wallet - FirmaWalletService instance
49
+ * @param data - Arbitrary data string to sign
50
+ * @returns ArbitraryVerifyData for verification
51
+ */
52
+ static experimentalAdr36Sign(wallet: FirmaWalletService, data: string): Promise<ArbitraryVerifyData>;
53
+ /**
54
+ * ADR-036 protobuf arbitrary signature verification (wrapper for protobufArbitraryVerify)
55
+ *
56
+ * @param data - ArbitraryVerifyData to verify
57
+ * @param checkMsg - Original message that was signed
58
+ * @returns boolean indicating if the signature is valid
59
+ */
60
+ static experimentalAdr36Verify(data: ArbitraryVerifyData, checkMsg: string): Promise<boolean>;
61
+ static makeSignDoc(signerAddress: string, pubkey: string, messages: readonly EncodeObject[], txMisc?: TxMisc): Promise<SignDoc>;
62
+ static makeSignDocWithStringify(signerAddress: string, pubkey: string, messages: readonly EncodeObject[], txMisc?: TxMisc): Promise<string>;
44
63
  private static recoverSigningAddress;
45
64
  private static verifySignature;
46
65
  static verifyDirectSignature(address: string, signature: string, signDoc: SignDoc): Promise<boolean>;
@@ -61,23 +80,6 @@ export declare class FirmaUtil {
61
80
  * @returns Processed commission rate string safe for protobuf usage (atomics format or empty string)
62
81
  */
63
82
  static processCommissionRateAsDecimal(commissionRate: string): string;
64
- /**
65
- * ADR-036 protobuf arbitrary signing
66
- *
67
- * @param wallet - FirmaWalletService instance
68
- * @param signerAddress - Address of the signer
69
- * @param data - Arbitrary data to sign
70
- * @returns ArbitraryVerifyData for verification
71
- */
72
- static protobufArbitrarySign(wallet: FirmaWalletService, signerAddress: string, data: Uint8Array): Promise<ArbitraryVerifyData>;
73
- /**
74
- * ADR-036 protobuf arbitrary signature verification
75
- *
76
- * @param data - ArbitraryVerifyData to verify
77
- * @param originalMessage - Original message that was signed
78
- * @returns boolean indicating if the signature is valid
79
- */
80
- static protobufArbitraryVerify(data: ArbitraryVerifyData, originalMessage: Uint8Array): Promise<boolean>;
81
83
  }
82
84
  export declare const DefaultTxMisc: {
83
85
  memo: string;
@@ -79,16 +79,18 @@ exports.getSignAndBroadcastOption = exports.DefaultTxMisc = exports.FirmaUtil =
79
79
  var fs_1 = require("fs");
80
80
  var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
81
81
  var axios_1 = __importDefault(require("axios"));
82
+ var duration_1 = require("cosmjs-types/google/protobuf/duration");
82
83
  var encoding_1 = require("@cosmjs/encoding");
83
84
  var proto_signing_1 = require("@cosmjs/proto-signing");
84
85
  var crypto_1 = require("@cosmjs/crypto");
85
- var amino_1 = require("@cosmjs/amino");
86
- var any_1 = require("./firmachain/google/protobuf/any");
86
+ var any_1 = require("cosmjs-types/google/protobuf/any");
87
87
  var CommonTxClient_1 = require("./firmachain/common/CommonTxClient");
88
88
  var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
89
89
  var bignumber_js_1 = require("bignumber.js");
90
90
  var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
91
- var utils_1 = require("@cosmjs/utils");
91
+ var signingprotobufstargateclient_1 = require("./firmachain/common/signingprotobufstargateclient");
92
+ var signingstargateclient_1 = require("./firmachain/common/signingstargateclient");
93
+ var coin_1 = require("cosmjs-types/cosmos/base/v1beta1/coin");
92
94
  var CryptoJS = require("crypto-js");
93
95
  var sha1 = require("crypto-js/sha1");
94
96
  var sha256 = require("crypto-js/sha256");
@@ -107,9 +109,17 @@ var FirmaUtil = /** @class */ (function () {
107
109
  txMisc.gas = FirmaUtil.config.defaultGas;
108
110
  if (txMisc.feeGranter == null)
109
111
  txMisc.feeGranter = "";
110
- var gasFeeAmount = { denom: denom, amount: txMisc.fee.toString() };
111
- var defaultFee = { amount: [gasFeeAmount], gas: txMisc.gas.toString(), granter: txMisc.feeGranter };
112
- return { fee: defaultFee, memo: txMisc.memo };
112
+ var gasFeeAmount = coin_1.Coin.fromPartial({
113
+ denom: denom,
114
+ amount: txMisc.fee.toString(),
115
+ });
116
+ var fee = tx_1.Fee.fromPartial({
117
+ amount: [gasFeeAmount],
118
+ gasLimit: BigInt(txMisc.gas),
119
+ granter: txMisc.feeGranter,
120
+ payer: "",
121
+ });
122
+ return { fee: fee, memo: txMisc.memo };
113
123
  };
114
124
  FirmaUtil.getUTokenStringFromTokenStr = function (tokenAmount, decimal) {
115
125
  var fct = Number.parseFloat(tokenAmount);
@@ -135,24 +145,10 @@ var FirmaUtil = /** @class */ (function () {
135
145
  };
136
146
  FirmaUtil.arrayBufferToBase64 = function (buffer) {
137
147
  return Buffer.from(buffer).toString("base64");
138
- /*var binary = '';
139
- var bytes = new Uint8Array(buffer);
140
- var len = bytes.byteLength;
141
- for (var i = 0; i < len; i++) {
142
- binary += String.fromCharCode(bytes[i]);
143
- }
144
- return btoa(binary);*/
145
148
  };
146
149
  FirmaUtil.base64ToArrayBuffer = function (base64) {
147
150
  var buffer = Buffer.from(base64, "base64");
148
151
  return new Uint8Array(buffer);
149
- /* var binary_string = atob(base64);
150
- var len = binary_string.length;
151
- var bytes = new Uint8Array(len);
152
- for (var i = 0; i < len; i++) {
153
- bytes[i] = binary_string.charCodeAt(i);
154
- }
155
- return bytes;*/
156
152
  };
157
153
  FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
158
154
  var fixedUTokenAmount = Math.floor(uTokenAmount);
@@ -327,9 +323,104 @@ var FirmaUtil = /** @class */ (function () {
327
323
  return;
328
324
  console.log("[FirmaSDK] ".concat(log));
329
325
  };
326
+ /**
327
+ * ADR-036 protobuf arbitrary signing (wrapper for protobufArbitrarySign)
328
+ *
329
+ * @param wallet - FirmaWalletService instance
330
+ * @param data - Arbitrary data string to sign
331
+ * @returns ArbitraryVerifyData for verification
332
+ */
333
+ FirmaUtil.experimentalAdr36Sign = function (wallet, data) {
334
+ return __awaiter(this, void 0, void 0, function () {
335
+ var client, address, dataBytes, error_4;
336
+ return __generator(this, function (_a) {
337
+ switch (_a.label) {
338
+ case 0:
339
+ _a.trys.push([0, 4, , 5]);
340
+ return [4 /*yield*/, signingprotobufstargateclient_1.SigningProtobufStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress, wallet.getRawWallet(), {})];
341
+ case 1:
342
+ client = _a.sent();
343
+ return [4 /*yield*/, wallet.getAddress()];
344
+ case 2:
345
+ address = _a.sent();
346
+ dataBytes = Buffer.from(data, 'utf8');
347
+ return [4 /*yield*/, client.experimentalAdr36Sign(address, dataBytes)];
348
+ case 3: return [2 /*return*/, _a.sent()];
349
+ case 4:
350
+ error_4 = _a.sent();
351
+ FirmaUtil.printLog(error_4);
352
+ throw error_4;
353
+ case 5: return [2 /*return*/];
354
+ }
355
+ });
356
+ });
357
+ };
358
+ /**
359
+ * ADR-036 protobuf arbitrary signature verification (wrapper for protobufArbitraryVerify)
360
+ *
361
+ * @param data - ArbitraryVerifyData to verify
362
+ * @param checkMsg - Original message that was signed
363
+ * @returns boolean indicating if the signature is valid
364
+ */
365
+ FirmaUtil.experimentalAdr36Verify = function (data, checkMsg) {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ var error_5;
368
+ return __generator(this, function (_a) {
369
+ switch (_a.label) {
370
+ case 0:
371
+ _a.trys.push([0, 2, , 3]);
372
+ return [4 /*yield*/, signingprotobufstargateclient_1.SigningProtobufStargateClient.experimentalAdr36Verify(data, checkMsg)];
373
+ case 1: return [2 /*return*/, _a.sent()];
374
+ case 2:
375
+ error_5 = _a.sent();
376
+ FirmaUtil.printLog(error_5);
377
+ return [2 /*return*/, false];
378
+ case 3: return [2 /*return*/];
379
+ }
380
+ });
381
+ });
382
+ };
383
+ FirmaUtil.makeSignDoc = function (signerAddress, pubkey, 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, fee;
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
+ fee = {
395
+ amount: __spreadArray([], __read(result.fee.amount), false),
396
+ gasLimit: result.fee.gasLimit,
397
+ granter: result.fee.granter || "",
398
+ payer: ""
399
+ };
400
+ return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.makeSignDocForSend(signerAddress, pubkey, messages, fee, result.memo, serverUrl, chainID, registry)];
401
+ case 1: return [2 /*return*/, _a.sent()];
402
+ }
403
+ });
404
+ });
405
+ };
406
+ FirmaUtil.makeSignDocWithStringify = function (signerAddress, pubkey, messages, txMisc) {
407
+ if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
408
+ return __awaiter(this, void 0, void 0, function () {
409
+ var signDoc, stringSignDoc;
410
+ return __generator(this, function (_a) {
411
+ switch (_a.label) {
412
+ case 0: return [4 /*yield*/, this.makeSignDoc(signerAddress, pubkey, messages, txMisc)];
413
+ case 1:
414
+ signDoc = _a.sent();
415
+ stringSignDoc = this.stringifySignDocValues(signDoc);
416
+ return [2 /*return*/, stringSignDoc];
417
+ }
418
+ });
419
+ });
420
+ };
330
421
  FirmaUtil.recoverSigningAddress = function (signature, hash, recoveryIndex) {
331
422
  return __awaiter(this, void 0, void 0, function () {
332
- var sig, extendedSig, recoveredPubKey, _a;
423
+ var sig, extendedSig, recoveredPubKey, compressedPubkey, rawAddress, _a;
333
424
  return __generator(this, function (_b) {
334
425
  switch (_b.label) {
335
426
  case 0:
@@ -344,10 +435,9 @@ var FirmaUtil = /** @class */ (function () {
344
435
  return [4 /*yield*/, crypto_1.Secp256k1.recoverPubkey(extendedSig, hash)];
345
436
  case 2:
346
437
  recoveredPubKey = _b.sent();
347
- return [2 /*return*/, (0, amino_1.pubkeyToAddress)({
348
- type: 'tendermint/PubKeySecp256k1',
349
- value: (0, encoding_1.toBase64)(crypto_1.Secp256k1.compressPubkey(recoveredPubKey)),
350
- }, 'firma')];
438
+ compressedPubkey = crypto_1.Secp256k1.compressPubkey(recoveredPubKey);
439
+ rawAddress = (0, tendermint_rpc_1.rawSecp256k1PubkeyToRawAddress)(compressedPubkey);
440
+ return [2 /*return*/, (0, encoding_1.toBech32)('firma', rawAddress)];
351
441
  case 3:
352
442
  _a = _b.sent();
353
443
  return [2 /*return*/, null];
@@ -463,9 +553,7 @@ var FirmaUtil = /** @class */ (function () {
463
553
  };
464
554
  FirmaUtil.createDurationFromString = function (durationStr) {
465
555
  var _a = FirmaUtil.parseDurationString(durationStr), seconds = _a.seconds, nanos = _a.nanos;
466
- // Import Duration if not already imported
467
- var Duration = require("./firmachain/google/protobuf/duration").Duration;
468
- return Duration.fromPartial({
556
+ return duration_1.Duration.fromPartial({
469
557
  seconds: seconds,
470
558
  nanos: nanos
471
559
  });
@@ -498,129 +586,6 @@ var FirmaUtil = /** @class */ (function () {
498
586
  // Returns integer string
499
587
  return atomics.integerValue(bignumber_js_1.BigNumber.ROUND_DOWN).toString();
500
588
  };
501
- /**
502
- * ADR-036 protobuf arbitrary signing
503
- *
504
- * @param wallet - FirmaWalletService instance
505
- * @param signerAddress - Address of the signer
506
- * @param data - Arbitrary data to sign
507
- * @returns ArbitraryVerifyData for verification
508
- */
509
- FirmaUtil.protobufArbitrarySign = function (wallet, signerAddress, data) {
510
- return __awaiter(this, void 0, void 0, function () {
511
- var rawWallet, accounts, account, txBody, authInfo, signDoc, signBytes, hash, privKey, signature, sigBytes, error_4;
512
- return __generator(this, function (_a) {
513
- switch (_a.label) {
514
- case 0:
515
- _a.trys.push([0, 3, , 4]);
516
- rawWallet = wallet.getRawWallet();
517
- return [4 /*yield*/, rawWallet.getAccounts()];
518
- case 1:
519
- accounts = _a.sent();
520
- account = accounts.find(function (acc) { return acc.address === signerAddress; });
521
- if (!account) {
522
- throw new Error("Account not found in rawWallet");
523
- }
524
- txBody = tx_1.TxBody.fromPartial({
525
- messages: [],
526
- memo: new TextDecoder().decode(data),
527
- timeoutHeight: BigInt(0),
528
- });
529
- authInfo = tx_1.AuthInfo.fromPartial({
530
- signerInfos: [],
531
- fee: {
532
- amount: [],
533
- gasLimit: BigInt(0),
534
- payer: "",
535
- granter: ""
536
- }
537
- });
538
- signDoc = (0, proto_signing_1.makeSignDoc)(tx_1.TxBody.encode(txBody).finish(), tx_1.AuthInfo.encode(authInfo).finish(), "", // Empty chainId for arbitrary signing
539
- 0 // 0 account number for arbitrary signing
540
- );
541
- signBytes = (0, proto_signing_1.makeSignBytes)(signDoc);
542
- hash = (0, crypto_1.sha256)(signBytes);
543
- privKey = rawWallet["privkey"];
544
- if (!privKey) {
545
- throw new Error("Private key not accessible from wallet");
546
- }
547
- return [4 /*yield*/, crypto_1.Secp256k1.createSignature(hash, privKey)];
548
- case 2:
549
- signature = _a.sent();
550
- sigBytes = new Uint8Array(__spreadArray(__spreadArray([], __read(signature.r(32)), false), __read(signature.s(32)), false));
551
- return [2 /*return*/, {
552
- chainId: signDoc.chainId,
553
- accountNumber: signDoc.accountNumber.toString(),
554
- sequence: "0",
555
- bodyBytes: (0, encoding_1.toBase64)(signDoc.bodyBytes),
556
- authInfoBytes: (0, encoding_1.toBase64)(signDoc.authInfoBytes),
557
- signerAddress: signerAddress,
558
- pubkey: (0, encoding_1.toBase64)(account.pubkey),
559
- signature: (0, encoding_1.toBase64)(sigBytes),
560
- }];
561
- case 3:
562
- error_4 = _a.sent();
563
- FirmaUtil.printLog(error_4);
564
- throw error_4;
565
- case 4: return [2 /*return*/];
566
- }
567
- });
568
- });
569
- };
570
- /**
571
- * ADR-036 protobuf arbitrary signature verification
572
- *
573
- * @param data - ArbitraryVerifyData to verify
574
- * @param originalMessage - Original message that was signed
575
- * @returns boolean indicating if the signature is valid
576
- */
577
- FirmaUtil.protobufArbitraryVerify = function (data, originalMessage) {
578
- return __awaiter(this, void 0, void 0, function () {
579
- var signDoc, txBody, memoData, originalMessageString, signBytes, hash, pubkeyBytes, signatureBytes, secpSig, rawSignerAddr, bech32SignerAddr, isValid, error_5, error_6;
580
- return __generator(this, function (_a) {
581
- switch (_a.label) {
582
- case 0:
583
- _a.trys.push([0, 5, , 6]);
584
- signDoc = (0, proto_signing_1.makeSignDoc)((0, encoding_1.fromBase64)(data.bodyBytes), (0, encoding_1.fromBase64)(data.authInfoBytes), data.chainId, Number(data.accountNumber));
585
- txBody = tx_1.TxBody.decode(signDoc.bodyBytes);
586
- // For ADR-036 arbitrary signing, messages should be empty
587
- if (txBody.messages.length !== 0) {
588
- return [2 /*return*/, false];
589
- }
590
- memoData = txBody.memo;
591
- originalMessageString = new TextDecoder().decode(originalMessage);
592
- if (memoData !== originalMessageString) {
593
- return [2 /*return*/, false];
594
- }
595
- signBytes = (0, proto_signing_1.makeSignBytes)(signDoc);
596
- hash = (0, crypto_1.sha256)(signBytes);
597
- _a.label = 1;
598
- case 1:
599
- _a.trys.push([1, 3, , 4]);
600
- pubkeyBytes = (0, encoding_1.fromBase64)(data.pubkey);
601
- signatureBytes = (0, encoding_1.fromBase64)(data.signature);
602
- secpSig = crypto_1.Secp256k1Signature.fromFixedLength(signatureBytes);
603
- rawSignerAddr = (0, tendermint_rpc_1.rawSecp256k1PubkeyToRawAddress)(pubkeyBytes);
604
- bech32SignerAddr = (0, encoding_1.fromBech32)(data.signerAddress).data;
605
- if (!rawSignerAddr || !bech32SignerAddr || !(0, utils_1.arrayContentEquals)(rawSignerAddr, bech32SignerAddr)) {
606
- return [2 /*return*/, false];
607
- }
608
- return [4 /*yield*/, crypto_1.Secp256k1.verifySignature(secpSig, hash, pubkeyBytes)];
609
- case 2:
610
- isValid = _a.sent();
611
- return [2 /*return*/, isValid];
612
- case 3:
613
- error_5 = _a.sent();
614
- return [2 /*return*/, false];
615
- case 4: return [3 /*break*/, 6];
616
- case 5:
617
- error_6 = _a.sent();
618
- return [2 /*return*/, false];
619
- case 6: return [2 /*return*/];
620
- }
621
- });
622
- });
623
- };
624
589
  FirmaUtil.FctDecimal = 6;
625
590
  return FirmaUtil;
626
591
  }());
@@ -1,6 +1,5 @@
1
1
  import { DirectSecp256k1Wallet, EncodeObject, Registry } from "@cosmjs/proto-signing";
2
2
  import { FirmaConfig } from "./FirmaConfig";
3
- import { Secp256k1Wallet } from "@cosmjs/amino";
4
3
  import { LedgerWalletInterface } from "./firmachain/common/LedgerWallet";
5
4
  import { SignAndBroadcastOptions } from "./firmachain/common";
6
5
  import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
@@ -9,13 +8,11 @@ export declare class FirmaWalletService {
9
8
  private mnemonic;
10
9
  private privateKey;
11
10
  private accountIndex;
12
- private aminoWallet;
13
11
  private wallet;
14
12
  private ledger;
15
13
  getHdPath(): string;
16
14
  getPrefix(): string;
17
15
  getRawWallet(): DirectSecp256k1Wallet;
18
- getRawAminoWallet(): Secp256k1Wallet;
19
16
  getPrivateKey(): string;
20
17
  getMnemonic(): string;
21
18
  getPubKey(): Promise<string>;
@@ -40,7 +40,6 @@ exports.FirmaWalletService = void 0;
40
40
  var proto_signing_1 = require("@cosmjs/proto-signing");
41
41
  var crypto_1 = require("@cosmjs/crypto");
42
42
  var FirmaUtil_1 = require("./FirmaUtil");
43
- var amino_1 = require("@cosmjs/amino");
44
43
  var LedgerWallet_1 = require("./firmachain/common/LedgerWallet");
45
44
  var CryptoJS = require("crypto-js");
46
45
  var FirmaWalletService = /** @class */ (function () {
@@ -59,9 +58,6 @@ var FirmaWalletService = /** @class */ (function () {
59
58
  FirmaWalletService.prototype.getRawWallet = function () {
60
59
  return this.wallet;
61
60
  };
62
- FirmaWalletService.prototype.getRawAminoWallet = function () {
63
- return this.aminoWallet;
64
- };
65
61
  FirmaWalletService.prototype.getPrivateKey = function () {
66
62
  return this.privateKey;
67
63
  };
@@ -176,27 +172,23 @@ var FirmaWalletService = /** @class */ (function () {
176
172
  };
177
173
  FirmaWalletService.prototype.initFromPrivateKey = function (privateKey) {
178
174
  return __awaiter(this, void 0, void 0, function () {
179
- var tempPrivateKey, _a, _b, error_5;
180
- return __generator(this, function (_c) {
181
- switch (_c.label) {
175
+ var tempPrivateKey, _a, error_5;
176
+ return __generator(this, function (_b) {
177
+ switch (_b.label) {
182
178
  case 0:
183
- _c.trys.push([0, 3, , 4]);
179
+ _b.trys.push([0, 2, , 3]);
184
180
  tempPrivateKey = Buffer.from(privateKey.replace("0x", ""), "hex");
185
181
  _a = this;
186
182
  return [4 /*yield*/, proto_signing_1.DirectSecp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
187
183
  case 1:
188
- _a.wallet = _c.sent();
189
- _b = this;
190
- return [4 /*yield*/, amino_1.Secp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
191
- case 2:
192
- _b.aminoWallet = _c.sent();
184
+ _a.wallet = _b.sent();
193
185
  this.privateKey = privateKey;
194
- return [3 /*break*/, 4];
195
- case 3:
196
- error_5 = _c.sent();
186
+ return [3 /*break*/, 3];
187
+ case 2:
188
+ error_5 = _b.sent();
197
189
  FirmaUtil_1.FirmaUtil.printLog(error_5);
198
190
  throw error_5;
199
- case 4: return [2 /*return*/];
191
+ case 3: return [2 /*return*/];
200
192
  }
201
193
  });
202
194
  });
@@ -366,8 +358,8 @@ var FirmaWalletService = /** @class */ (function () {
366
358
  case 10:
367
359
  chainId = _a.sent();
368
360
  signerData = {
369
- account_number: Number(accountInfo.account_number),
370
- sequence: Number(accountInfo.sequence),
361
+ account_number: parseInt(accountInfo.account_number, 10),
362
+ sequence: parseInt(accountInfo.sequence, 10),
371
363
  chain_id: chainId,
372
364
  };
373
365
  return [4 /*yield*/, (0, LedgerWallet_1.signWithSignerProtobuf)(this.ledger, messages, signerData, option, registry)];
@@ -1,8 +1,9 @@
1
1
  import { Registry, EncodeObject } from "@cosmjs/proto-signing";
2
2
  import { SignAndBroadcastOptions } from ".";
3
- import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
3
+ import { SignDoc, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
4
4
  import { FirmaWalletService } from "../../FirmaWalletService";
5
5
  import { DeliverTxResponse } from "@cosmjs/stargate";
6
+ import { TxRawExt } from "./signingstargateclient";
6
7
  export declare class ITxClient {
7
8
  private readonly wallet;
8
9
  private readonly serverUrl;
@@ -14,4 +15,5 @@ export declare class ITxClient {
14
15
  broadcast(txRaw: TxRaw): Promise<DeliverTxResponse>;
15
16
  broadcastTxBytes(txBytes: Uint8Array): Promise<DeliverTxResponse>;
16
17
  signAndBroadcast(msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions): Promise<DeliverTxResponse>;
18
+ signDirectForSignDoc(signerAddress: string, signDoc: SignDoc): Promise<TxRawExt>;
17
19
  }
@@ -38,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ITxClient = void 0;
40
40
  var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
41
- var stargate_1 = require("@cosmjs/stargate");
41
+ var signingstargateclient_1 = require("./signingstargateclient");
42
42
  var ITxClient = /** @class */ (function () {
43
43
  function ITxClient(wallet, serverUrl, registry) {
44
44
  this.wallet = wallet;
@@ -56,7 +56,7 @@ var ITxClient = /** @class */ (function () {
56
56
  case 0:
57
57
  if (!this.wallet.isLedger()) return [3 /*break*/, 1];
58
58
  return [2 /*return*/, this.wallet.signLedger(msgs, { fee: fee, memo: memo }, this.registry)];
59
- case 1: return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
59
+ case 1: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
60
60
  case 2:
61
61
  client = _b.sent();
62
62
  return [4 /*yield*/, this.rawWallet.getAccounts()];
@@ -73,7 +73,7 @@ var ITxClient = /** @class */ (function () {
73
73
  var client, txBytes;
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
- case 0: return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
76
+ case 0: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
77
77
  case 1:
78
78
  client = _a.sent();
79
79
  txBytes = tx_1.TxRaw.encode(txRaw).finish();
@@ -88,7 +88,7 @@ var ITxClient = /** @class */ (function () {
88
88
  var client;
89
89
  return __generator(this, function (_a) {
90
90
  switch (_a.label) {
91
- case 0: return [4 /*yield*/, stargate_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
91
+ case 0: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
92
92
  case 1:
93
93
  client = _a.sent();
94
94
  return [4 /*yield*/, client.broadcastTx(txBytes)];
@@ -112,6 +112,20 @@ var ITxClient = /** @class */ (function () {
112
112
  });
113
113
  });
114
114
  };
115
+ ITxClient.prototype.signDirectForSignDoc = function (signerAddress, signDoc) {
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ var client;
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0: return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(this.serverUrl, this.rawWallet, { registry: this.registry })];
121
+ case 1:
122
+ client = _a.sent();
123
+ return [4 /*yield*/, client.signDirectForSignDoc(signerAddress, signDoc)];
124
+ case 2: return [2 /*return*/, _a.sent()];
125
+ }
126
+ });
127
+ });
128
+ };
115
129
  return ITxClient;
116
130
  }());
117
131
  exports.ITxClient = ITxClient;
@@ -130,7 +130,7 @@ function signWithSignerProtobuf(signer, messages, signerData, option, registry)
130
130
  denom: a.denom,
131
131
  amount: a.amount,
132
132
  }); });
133
- authInfoBytes = makeAuthInfoBytesDirect(pubkeyProto, feeAmount, parseInt(option.fee.gas), signerData.sequence);
133
+ authInfoBytes = makeAuthInfoBytesDirect(pubkeyProto, feeAmount, option.fee.gasLimit, signerData.sequence);
134
134
  signDoc = tx_1.SignDoc.fromPartial({
135
135
  bodyBytes: bodyBytes,
136
136
  authInfoBytes: authInfoBytes,
@@ -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 {
@@ -0,0 +1,32 @@
1
+ import { tendermint34, tendermint37 } from "@cosmjs/tendermint-rpc";
2
+ /**
3
+ * An event attribute.
4
+ *
5
+ * This is the same attribute type as tendermint34.Attribute and tendermint35.EventAttribute
6
+ * but `key` and `value` are unified to strings. The conversion
7
+ * from bytes to string in the Tendermint 0.34 case should be done by performing
8
+ * [lossy] UTF-8 decoding.
9
+ *
10
+ * [lossy]: https://doc.rust-lang.org/stable/std/string/struct.String.html#method.from_utf8_lossy
11
+ */
12
+ export interface Attribute {
13
+ readonly key: string;
14
+ readonly value: string;
15
+ }
16
+ /**
17
+ * The same event type as tendermint34.Event and tendermint35.Event
18
+ * but attribute keys and values are unified to strings. The conversion
19
+ * from bytes to string in the Tendermint 0.34 case should be done by performing
20
+ * [lossy] UTF-8 decoding.
21
+ *
22
+ * [lossy]: https://doc.rust-lang.org/stable/std/string/struct.String.html#method.from_utf8_lossy
23
+ */
24
+ export interface Event {
25
+ readonly type: string;
26
+ readonly attributes: readonly Attribute[];
27
+ }
28
+ /**
29
+ * Takes a Tendermint 0.34 or 0.37 event with binary encoded key and value
30
+ * and converts it into an `Event` with string attributes.
31
+ */
32
+ 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;