@firmachain/firma-js 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -1
- package/dist/sdk/FirmaAuthzService.d.ts +8 -7
- package/dist/sdk/FirmaAuthzService.js +12 -22
- package/dist/sdk/FirmaBankService.js +2 -2
- package/dist/sdk/FirmaChainService.js +1 -1
- package/dist/sdk/FirmaContractService.d.ts +1 -1
- package/dist/sdk/FirmaContractService.js +6 -6
- package/dist/sdk/FirmaCosmWasmCw20.d.ts +2 -2
- package/dist/sdk/FirmaCosmWasmCw20.js +8 -8
- package/dist/sdk/FirmaCosmWasmCw721.d.ts +2 -2
- package/dist/sdk/FirmaCosmWasmCw721.js +12 -12
- package/dist/sdk/FirmaCosmWasmCwBridge.d.ts +1 -1
- package/dist/sdk/FirmaCosmWasmCwBridge.js +8 -8
- package/dist/sdk/FirmaCosmWasmCwMarketplace.d.ts +1 -1
- package/dist/sdk/FirmaCosmWasmCwMarketplace.js +5 -5
- package/dist/sdk/FirmaCosmWasmService.d.ts +1 -1
- package/dist/sdk/FirmaCosmWasmService.js +13 -13
- package/dist/sdk/FirmaDistributionService.d.ts +1 -1
- package/dist/sdk/FirmaDistributionService.js +6 -6
- package/dist/sdk/FirmaFeeGrantService.d.ts +7 -6
- package/dist/sdk/FirmaFeeGrantService.js +9 -26
- package/dist/sdk/FirmaGovService.d.ts +1 -1
- package/dist/sdk/FirmaGovService.js +14 -14
- package/dist/sdk/FirmaIbcService.d.ts +3 -3
- package/dist/sdk/FirmaIbcService.js +11 -8
- package/dist/sdk/FirmaIpfsService.js +1 -1
- package/dist/sdk/FirmaMintService.js +1 -1
- package/dist/sdk/FirmaNftService.d.ts +1 -1
- package/dist/sdk/FirmaNftService.js +6 -6
- package/dist/sdk/FirmaSlashingService.js +1 -1
- package/dist/sdk/FirmaStakingService.d.ts +3 -3
- package/dist/sdk/FirmaStakingService.js +6 -6
- package/dist/sdk/FirmaTokenService.d.ts +1 -1
- package/dist/sdk/FirmaTokenService.js +5 -5
- package/dist/sdk/FirmaUtil.d.ts +25 -24
- package/dist/sdk/FirmaUtil.js +199 -144
- package/dist/sdk/FirmaWalletService.d.ts +6 -7
- package/dist/sdk/FirmaWalletService.js +78 -36
- package/dist/sdk/firmachain/authz/AuthzQueryClient.js +4 -4
- package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +8 -11
- package/dist/sdk/firmachain/authz/AuthzTxTypes.js +6 -10
- package/dist/sdk/firmachain/authz/index.js +5 -1
- package/dist/sdk/firmachain/bank/BankQueryClient.js +5 -5
- package/dist/sdk/firmachain/bank/index.js +5 -1
- package/dist/sdk/firmachain/common/ITxClient.d.ts +2 -4
- package/dist/sdk/firmachain/common/ITxClient.js +20 -92
- package/dist/sdk/firmachain/common/LedgerWallet.d.ts +19 -3
- package/dist/sdk/firmachain/common/LedgerWallet.js +138 -68
- package/dist/sdk/firmachain/common/TendermintQueryClient.js +1 -1
- package/dist/sdk/firmachain/common/TxCommon.d.ts +13 -29
- package/dist/sdk/firmachain/common/accounts.d.ts +1 -1
- package/dist/sdk/firmachain/common/accounts.js +7 -7
- package/dist/sdk/firmachain/{amino → common}/coins.d.ts +2 -14
- package/dist/sdk/firmachain/{amino → common}/coins.js +4 -25
- package/dist/sdk/firmachain/common/index.d.ts +0 -1
- package/dist/sdk/firmachain/common/index.js +5 -4
- package/dist/sdk/firmachain/{amino → common}/wallet.js +15 -11
- package/dist/sdk/firmachain/contract/ContractQueryClient.js +3 -3
- package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +6 -6
- package/dist/sdk/firmachain/contract/index.js +5 -1
- package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +9 -9
- package/dist/sdk/firmachain/cosmwasm/index.js +5 -1
- package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +6 -6
- package/dist/sdk/firmachain/distribution/index.js +5 -1
- package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +3 -3
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +4 -45
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +3 -82
- package/dist/sdk/firmachain/feegrant/index.js +5 -1
- package/dist/sdk/firmachain/google/protobuf/any.d.ts +3 -3
- package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +29 -29
- package/dist/sdk/firmachain/google/protobuf/duration.d.ts +3 -3
- package/dist/sdk/firmachain/gov/GovQueryClient.js +3 -3
- package/dist/sdk/firmachain/gov/index.js +5 -1
- package/dist/sdk/firmachain/ibc/IbcQueryClient.js +2 -2
- package/dist/sdk/firmachain/ibc/index.js +5 -1
- package/dist/sdk/firmachain/mint/MintQueryClient.js +1 -1
- package/dist/sdk/firmachain/mint/index.js +5 -1
- package/dist/sdk/firmachain/nft/NftQueryClient.js +1 -1
- package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +8 -8
- package/dist/sdk/firmachain/nft/index.js +5 -1
- package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +1 -1
- package/dist/sdk/firmachain/slashing/index.js +5 -1
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +2 -2
- package/dist/sdk/firmachain/staking/StakingQueryClient.js +10 -9
- package/dist/sdk/firmachain/staking/index.js +5 -1
- package/dist/sdk/firmachain/token/TokenQueryClient.js +1 -1
- package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +11 -11
- package/dist/sdk/firmachain/token/TokenTxTypes.js +1 -1
- package/dist/sdk/firmachain/token/index.js +5 -1
- package/dist/test/00.wallet.test.js +4 -4
- package/dist/test/01.contract_tx.test.js +5 -5
- package/dist/test/02.contract_query.test.js +15 -15
- package/dist/test/03.contract_scenario.test.js +28 -28
- package/dist/test/04.bank_tx.test.js +4 -4
- package/dist/test/05.bank_query.test.js +9 -9
- package/dist/test/06.feegrant_tx.test.js +59 -35
- package/dist/test/07.feegrant_query.test.js +18 -15
- package/dist/test/08.gas_estimate.test.js +110 -70
- package/dist/test/09.ipfs.test.js +4 -4
- package/dist/test/10.nft_tx.test.js +7 -7
- package/dist/test/11.nft_query.test.js +9 -9
- package/dist/test/12.staking_tx.test.js +27 -15
- package/dist/test/13.staking_query.test.js +20 -20
- package/dist/test/14.distribution_tx.test.js +8 -8
- package/dist/test/15.distribution_query.test.js +15 -15
- package/dist/test/16.gov_tx.test.js +17 -17
- package/dist/test/17.gov_query.test.js +19 -19
- package/dist/test/18.util.test.js +105 -63
- package/dist/test/19.chain.test.js +38 -38
- package/dist/test/20.slashing_query.test.js +25 -25
- package/dist/test/21.token_tx.test.js +6 -6
- package/dist/test/22.token_query.test.js +4 -4
- package/dist/test/23.authz_tx.test.js +77 -47
- package/dist/test/24.authz_query.test.js +66 -67
- package/dist/test/25.cosmwasm_tx.test.js +7 -7
- package/dist/test/26.cosmwasm_query.test.js +127 -59
- package/dist/test/{27.arbitary_sign.test.js → 27.arbitrary_sign.test.js} +34 -62
- package/dist/test/28.ibc_tx.test.js +8 -8
- package/dist/test/29.mint_query.test.js +2 -2
- package/dist/test/30.cw20_tx.test.js +20 -20
- package/dist/test/31.cw20_query.test.js +24 -24
- package/dist/test/32.cw721_tx.test.js +19 -19
- package/dist/test/33.cw721_query.test.js +32 -32
- package/dist/test/34.cw_bridge_tx.test.js +19 -19
- package/dist/test/35.cw_bridge_tx_low.test.js +13 -13
- package/dist/test/36.cw_bridge_query.test.js +20 -20
- package/dist/test/37.cw_marketplace_tx.test.js +32 -32
- package/dist/test/38.cw_marketplace_query.test.js +2 -2
- package/package.json +9 -10
- package/dist/sdk/firmachain/amino/addresses.d.ts +0 -5
- package/dist/sdk/firmachain/amino/addresses.js +0 -46
- package/dist/sdk/firmachain/amino/aminomsgs.d.ts +0 -291
- package/dist/sdk/firmachain/amino/aminomsgs.js +0 -81
- package/dist/sdk/firmachain/amino/aminotypes.d.ts +0 -22
- package/dist/sdk/firmachain/amino/aminotypes.js +0 -538
- package/dist/sdk/firmachain/amino/encoding.d.ts +0 -33
- package/dist/sdk/firmachain/amino/encoding.js +0 -252
- package/dist/sdk/firmachain/amino/multisig.d.ts +0 -10
- package/dist/sdk/firmachain/amino/multisig.js +0 -42
- package/dist/sdk/firmachain/amino/pubkeys.d.ts +0 -47
- package/dist/sdk/firmachain/amino/pubkeys.js +0 -29
- package/dist/sdk/firmachain/amino/signature.d.ts +0 -16
- package/dist/sdk/firmachain/amino/signature.js +0 -36
- package/dist/sdk/firmachain/amino/signdoc.d.ts +0 -44
- package/dist/sdk/firmachain/amino/signdoc.js +0 -68
- package/dist/sdk/firmachain/amino/signer.d.ts +0 -33
- package/dist/sdk/firmachain/amino/signer.js +0 -2
- package/dist/sdk/firmachain/amino/stdtx.d.ts +0 -15
- package/dist/sdk/firmachain/amino/stdtx.js +0 -17
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +0 -22
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +0 -170
- package/dist/sdk/firmachain/common/aminotypes.d.ts +0 -19
- package/dist/sdk/firmachain/common/aminotypes.js +0 -74
- package/dist/sdk/firmachain/common/events.d.ts +0 -32
- package/dist/sdk/firmachain/common/events.js +0 -18
- package/dist/sdk/firmachain/common/fee.d.ts +0 -26
- package/dist/sdk/firmachain/common/fee.js +0 -83
- package/dist/sdk/firmachain/common/modules/auth/queries.d.ts +0 -15
- package/dist/sdk/firmachain/common/modules/auth/queries.js +0 -64
- package/dist/sdk/firmachain/common/modules/authz/aminomessages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/authz/aminomessages.js +0 -15
- package/dist/sdk/firmachain/common/modules/authz/messages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/authz/messages.js +0 -9
- package/dist/sdk/firmachain/common/modules/authz/queries.d.ts +0 -10
- package/dist/sdk/firmachain/common/modules/authz/queries.js +0 -88
- package/dist/sdk/firmachain/common/modules/bank/aminomessages.d.ts +0 -35
- package/dist/sdk/firmachain/common/modules/bank/aminomessages.js +0 -85
- package/dist/sdk/firmachain/common/modules/bank/messages.d.ts +0 -8
- package/dist/sdk/firmachain/common/modules/bank/messages.js +0 -12
- package/dist/sdk/firmachain/common/modules/bank/queries.d.ts +0 -15
- package/dist/sdk/firmachain/common/modules/bank/queries.js +0 -128
- package/dist/sdk/firmachain/common/modules/crisis/aminomessages.d.ts +0 -14
- package/dist/sdk/firmachain/common/modules/crisis/aminomessages.js +0 -11
- package/dist/sdk/firmachain/common/modules/distribution/aminomessages.d.ts +0 -44
- package/dist/sdk/firmachain/common/modules/distribution/aminomessages.js +0 -113
- package/dist/sdk/firmachain/common/modules/distribution/messages.d.ts +0 -8
- package/dist/sdk/firmachain/common/modules/distribution/messages.js +0 -15
- package/dist/sdk/firmachain/common/modules/distribution/queries.d.ts +0 -16
- package/dist/sdk/firmachain/common/modules/distribution/queries.js +0 -171
- package/dist/sdk/firmachain/common/modules/evidence/aminomessages.d.ts +0 -18
- package/dist/sdk/firmachain/common/modules/evidence/aminomessages.js +0 -11
- package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.js +0 -14
- package/dist/sdk/firmachain/common/modules/feegrant/messages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/feegrant/messages.js +0 -8
- package/dist/sdk/firmachain/common/modules/feegrant/queries.d.ts +0 -9
- package/dist/sdk/firmachain/common/modules/feegrant/queries.js +0 -81
- package/dist/sdk/firmachain/common/modules/gov/aminomessages.d.ts +0 -79
- package/dist/sdk/firmachain/common/modules/gov/aminomessages.js +0 -152
- package/dist/sdk/firmachain/common/modules/gov/messages.d.ts +0 -29
- package/dist/sdk/firmachain/common/modules/gov/messages.js +0 -39
- package/dist/sdk/firmachain/common/modules/gov/queries.d.ts +0 -19
- package/dist/sdk/firmachain/common/modules/gov/queries.js +0 -160
- package/dist/sdk/firmachain/common/modules/group/aminomessages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/group/aminomessages.js +0 -8
- package/dist/sdk/firmachain/common/modules/group/messages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/group/messages.js +0 -28
- package/dist/sdk/firmachain/common/modules/ibc/aminomessages.d.ts +0 -38
- package/dist/sdk/firmachain/common/modules/ibc/aminomessages.js +0 -55
- package/dist/sdk/firmachain/common/modules/ibc/messages.d.ts +0 -8
- package/dist/sdk/firmachain/common/modules/ibc/messages.js +0 -32
- package/dist/sdk/firmachain/common/modules/ibc/queries.d.ts +0 -58
- package/dist/sdk/firmachain/common/modules/ibc/queries.js +0 -576
- package/dist/sdk/firmachain/common/modules/index.d.ts +0 -32
- package/dist/sdk/firmachain/common/modules/index.js +0 -101
- package/dist/sdk/firmachain/common/modules/mint/queries.d.ts +0 -21
- package/dist/sdk/firmachain/common/modules/mint/queries.js +0 -95
- package/dist/sdk/firmachain/common/modules/slashing/aminomessages.d.ts +0 -12
- package/dist/sdk/firmachain/common/modules/slashing/aminomessages.js +0 -11
- package/dist/sdk/firmachain/common/modules/slashing/queries.d.ts +0 -10
- package/dist/sdk/firmachain/common/modules/slashing/queries.js +0 -88
- package/dist/sdk/firmachain/common/modules/staking/aminomessages.d.ts +0 -112
- package/dist/sdk/firmachain/common/modules/staking/aminomessages.js +0 -234
- package/dist/sdk/firmachain/common/modules/staking/messages.d.ts +0 -33
- package/dist/sdk/firmachain/common/modules/staking/messages.js +0 -37
- package/dist/sdk/firmachain/common/modules/staking/queries.d.ts +0 -23
- package/dist/sdk/firmachain/common/modules/staking/queries.js +0 -242
- package/dist/sdk/firmachain/common/modules/tx/queries.d.ts +0 -11
- package/dist/sdk/firmachain/common/modules/tx/queries.js +0 -103
- package/dist/sdk/firmachain/common/modules/vesting/aminomessages.d.ts +0 -16
- package/dist/sdk/firmachain/common/modules/vesting/aminomessages.js +0 -56
- package/dist/sdk/firmachain/common/modules/vesting/messages.d.ts +0 -2
- package/dist/sdk/firmachain/common/modules/vesting/messages.js +0 -7
- package/dist/sdk/firmachain/common/queryclient/index.d.ts +0 -2
- package/dist/sdk/firmachain/common/queryclient/index.js +0 -10
- package/dist/sdk/firmachain/common/queryclient/queryclient.d.ts +0 -75
- package/dist/sdk/firmachain/common/queryclient/queryclient.js +0 -157
- package/dist/sdk/firmachain/common/queryclient/utils.d.ts +0 -33
- package/dist/sdk/firmachain/common/queryclient/utils.js +0 -101
- package/dist/sdk/firmachain/common/search.d.ts +0 -10
- package/dist/sdk/firmachain/common/search.js +0 -7
- package/dist/sdk/firmachain/common/signing.d.ts +0 -15
- package/dist/sdk/firmachain/common/signing.js +0 -87
- package/dist/sdk/firmachain/common/signingstargateclient.d.ts +0 -121
- package/dist/sdk/firmachain/common/signingstargateclient.js +0 -674
- package/dist/sdk/firmachain/common/stargateclient.d.ts +0 -210
- package/dist/sdk/firmachain/common/stargateclient.js +0 -527
- package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +0 -110
- package/dist/sdk/firmachain/google/protobuf/timestamp.js +0 -108
- /package/dist/sdk/firmachain/{amino → common}/paths.d.ts +0 -0
- /package/dist/sdk/firmachain/{amino → common}/paths.js +0 -0
- /package/dist/sdk/firmachain/{amino → common}/wallet.d.ts +0 -0
- /package/dist/test/{27.arbitary_sign.test.d.ts → 27.arbitrary_sign.test.d.ts} +0 -0
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
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;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -62,10 +62,14 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
62
62
|
}
|
|
63
63
|
return ar;
|
|
64
64
|
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
66
|
-
for (var i = 0,
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
69
73
|
};
|
|
70
74
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
71
75
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -74,18 +78,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
74
78
|
exports.getSignAndBroadcastOption = exports.DefaultTxMisc = exports.FirmaUtil = void 0;
|
|
75
79
|
var fs_1 = require("fs");
|
|
76
80
|
var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
77
|
-
var
|
|
81
|
+
var axios_1 = __importDefault(require("axios"));
|
|
78
82
|
var encoding_1 = require("@cosmjs/encoding");
|
|
79
|
-
var
|
|
80
|
-
var encoding_2 = require("@cosmjs/encoding");
|
|
83
|
+
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
81
84
|
var crypto_1 = require("@cosmjs/crypto");
|
|
82
85
|
var amino_1 = require("@cosmjs/amino");
|
|
83
|
-
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
84
|
-
var signingstargateclient_1 = require("./firmachain/common/signingstargateclient");
|
|
85
86
|
var any_1 = require("./firmachain/google/protobuf/any");
|
|
86
|
-
var long_1 = __importDefault(require("long"));
|
|
87
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
88
87
|
var CommonTxClient_1 = require("./firmachain/common/CommonTxClient");
|
|
88
|
+
var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
|
|
89
|
+
var bignumber_js_1 = require("bignumber.js");
|
|
90
|
+
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
91
|
+
var utils_1 = require("@cosmjs/utils");
|
|
89
92
|
var CryptoJS = require("crypto-js");
|
|
90
93
|
var sha1 = require("crypto-js/sha1");
|
|
91
94
|
var sha256 = require("crypto-js/sha256");
|
|
@@ -200,7 +203,7 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
200
203
|
FirmaUtil.isValidAddress = function (address) {
|
|
201
204
|
try {
|
|
202
205
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
203
|
-
encoding_1.fromBech32(address).data;
|
|
206
|
+
(0, encoding_1.fromBech32)(address).data;
|
|
204
207
|
return true;
|
|
205
208
|
}
|
|
206
209
|
catch (e) {
|
|
@@ -208,64 +211,65 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
208
211
|
return false;
|
|
209
212
|
};
|
|
210
213
|
FirmaUtil.buf2hex = function (buffer) {
|
|
211
|
-
return __spreadArray([], __read(new Uint8Array(buffer))).map(function (x) { return x.toString(16).padStart(2, '0'); })
|
|
214
|
+
return __spreadArray([], __read(new Uint8Array(buffer)), false).map(function (x) { return x.toString(16).padStart(2, '0'); })
|
|
212
215
|
.join('');
|
|
213
216
|
};
|
|
214
217
|
// for evm address support
|
|
215
218
|
FirmaUtil.getHexAddressFromAddress = function (address) {
|
|
216
|
-
var data = encoding_1.fromBech32(address).data;
|
|
219
|
+
var data = (0, encoding_1.fromBech32)(address).data;
|
|
217
220
|
return "0x" + FirmaUtil.buf2hex(data);
|
|
218
221
|
};
|
|
219
222
|
FirmaUtil.getValOperAddressFromAccAddress = function (address) {
|
|
220
|
-
var data = encoding_1.fromBech32(address).data;
|
|
221
|
-
return encoding_1.toBech32(FirmaUtil.config.prefix + "valoper", data);
|
|
223
|
+
var data = (0, encoding_1.fromBech32)(address).data;
|
|
224
|
+
return (0, encoding_1.toBech32)(FirmaUtil.config.prefix + "valoper", data);
|
|
222
225
|
};
|
|
223
226
|
FirmaUtil.getValConsAddressFromAccAddress = function (consensusPubkey) {
|
|
224
|
-
var ed25519PubkeyRaw =
|
|
225
|
-
var addressData = crypto_1.sha256(ed25519PubkeyRaw).slice(0, 20);
|
|
226
|
-
return encoding_1.toBech32(FirmaUtil.config.prefix + "valcons", addressData);
|
|
227
|
+
var ed25519PubkeyRaw = (0, encoding_1.fromBase64)(consensusPubkey);
|
|
228
|
+
var addressData = (0, crypto_1.sha256)(ed25519PubkeyRaw).slice(0, 20);
|
|
229
|
+
return (0, encoding_1.toBech32)(FirmaUtil.config.prefix + "valcons", addressData);
|
|
227
230
|
};
|
|
228
231
|
FirmaUtil.getAccAddressFromValOperAddress = function (address) {
|
|
229
|
-
var data = encoding_1.fromBech32(address).data;
|
|
230
|
-
return encoding_1.toBech32(FirmaUtil.config.prefix, data);
|
|
232
|
+
var data = (0, encoding_1.fromBech32)(address).data;
|
|
233
|
+
return (0, encoding_1.toBech32)(FirmaUtil.config.prefix, data);
|
|
231
234
|
};
|
|
232
|
-
FirmaUtil.
|
|
235
|
+
FirmaUtil.estimateGas = function (txRaw) {
|
|
233
236
|
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
-
var
|
|
237
|
+
var encodedTx, hexTx, queryClient, gas, multiplier, error_1;
|
|
235
238
|
return __generator(this, function (_a) {
|
|
236
239
|
switch (_a.label) {
|
|
237
240
|
case 0:
|
|
238
|
-
_a.trys.push([0,
|
|
239
|
-
|
|
241
|
+
_a.trys.push([0, 2, , 3]);
|
|
242
|
+
encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
|
|
243
|
+
hexTx = "0x".concat(Buffer.from(encodedTx).toString("hex"));
|
|
244
|
+
queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
|
|
245
|
+
return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
|
|
240
246
|
case 1:
|
|
241
|
-
|
|
242
|
-
|
|
247
|
+
gas = _a.sent();
|
|
248
|
+
multiplier = 1.15;
|
|
249
|
+
return [2 /*return*/, Math.ceil(gas * multiplier)];
|
|
243
250
|
case 2:
|
|
244
|
-
sequence = _a.sent();
|
|
245
|
-
return [2 /*return*/, sequence];
|
|
246
|
-
case 3:
|
|
247
251
|
error_1 = _a.sent();
|
|
248
252
|
FirmaUtil.printLog(error_1);
|
|
249
253
|
throw error_1;
|
|
250
|
-
case
|
|
254
|
+
case 3: return [2 /*return*/];
|
|
251
255
|
}
|
|
252
256
|
});
|
|
253
257
|
});
|
|
254
258
|
};
|
|
255
|
-
FirmaUtil.
|
|
259
|
+
FirmaUtil.estimateGasRaw = function (txRaw) {
|
|
256
260
|
return __awaiter(this, void 0, void 0, function () {
|
|
257
261
|
var encodedTx, hexTx, queryClient, gas, multiplier, error_2;
|
|
258
262
|
return __generator(this, function (_a) {
|
|
259
263
|
switch (_a.label) {
|
|
260
264
|
case 0:
|
|
261
265
|
_a.trys.push([0, 2, , 3]);
|
|
262
|
-
encodedTx = Uint8Array.from(
|
|
263
|
-
hexTx = "0x"
|
|
266
|
+
encodedTx = Uint8Array.from(txRaw);
|
|
267
|
+
hexTx = "0x".concat(Buffer.from(encodedTx).toString("hex"));
|
|
264
268
|
queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
|
|
265
269
|
return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
|
|
266
270
|
case 1:
|
|
267
271
|
gas = _a.sent();
|
|
268
|
-
multiplier = 1.
|
|
272
|
+
multiplier = 1.25;
|
|
269
273
|
return [2 /*return*/, Math.ceil(gas * multiplier)];
|
|
270
274
|
case 2:
|
|
271
275
|
error_2 = _a.sent();
|
|
@@ -276,78 +280,52 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
276
280
|
});
|
|
277
281
|
});
|
|
278
282
|
};
|
|
279
|
-
FirmaUtil.
|
|
283
|
+
FirmaUtil.getAccountInfo = function (address) {
|
|
280
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
-
var
|
|
285
|
+
var res, json, baseAccount, result, error_3;
|
|
282
286
|
return __generator(this, function (_a) {
|
|
283
287
|
switch (_a.label) {
|
|
284
288
|
case 0:
|
|
285
289
|
_a.trys.push([0, 2, , 3]);
|
|
286
|
-
|
|
287
|
-
hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
|
|
288
|
-
queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
|
|
289
|
-
return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
|
|
290
|
+
return [4 /*yield*/, axios_1.default.get("".concat(FirmaUtil.config.restApiAddress, "/cosmos/auth/v1beta1/accounts/").concat(address))];
|
|
290
291
|
case 1:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
res = _a.sent();
|
|
293
|
+
if (res.status !== 200) {
|
|
294
|
+
throw new Error("HTTP ".concat(res.status, ": ").concat(res.statusText));
|
|
295
|
+
}
|
|
296
|
+
json = res.data;
|
|
297
|
+
baseAccount = json.account.base_account || json.account;
|
|
298
|
+
result = {
|
|
299
|
+
account_number: baseAccount.account_number,
|
|
300
|
+
sequence: baseAccount.sequence,
|
|
301
|
+
};
|
|
302
|
+
return [2 /*return*/, result];
|
|
294
303
|
case 2:
|
|
295
304
|
error_3 = _a.sent();
|
|
296
|
-
FirmaUtil.printLog(error_3);
|
|
297
305
|
throw error_3;
|
|
298
306
|
case 3: return [2 /*return*/];
|
|
299
307
|
}
|
|
300
308
|
});
|
|
301
309
|
});
|
|
302
310
|
};
|
|
303
|
-
FirmaUtil.
|
|
304
|
-
if (FirmaUtil.config.isShowLog === false)
|
|
305
|
-
return;
|
|
306
|
-
console.log("[FirmaSDK] " + log);
|
|
307
|
-
};
|
|
308
|
-
FirmaUtil.experimentalAdr36Sign = function (wallet, data) {
|
|
311
|
+
FirmaUtil.getChainId = function () {
|
|
309
312
|
return __awaiter(this, void 0, void 0, function () {
|
|
310
|
-
var
|
|
313
|
+
var res, json;
|
|
311
314
|
return __generator(this, function (_a) {
|
|
312
315
|
switch (_a.label) {
|
|
313
|
-
case 0:
|
|
314
|
-
_a.trys.push([0, 4, , 5]);
|
|
315
|
-
registry = new proto_signing_1.Registry();
|
|
316
|
-
return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress, wallet.getRawAminoWallet(), { registry: registry })];
|
|
316
|
+
case 0: return [4 /*yield*/, axios_1.default.get("".concat(FirmaUtil.config.restApiAddress, "/cosmos/base/tendermint/v1beta1/node_info"))];
|
|
317
317
|
case 1:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
address = _a.sent();
|
|
322
|
-
userData = Buffer.from(data);
|
|
323
|
-
return [4 /*yield*/, client.experimentalAdr36Sign(address, userData)];
|
|
324
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
325
|
-
case 4:
|
|
326
|
-
error_4 = _a.sent();
|
|
327
|
-
FirmaUtil.printLog(error_4);
|
|
328
|
-
throw error_4;
|
|
329
|
-
case 5: return [2 /*return*/];
|
|
318
|
+
res = _a.sent();
|
|
319
|
+
json = res.data;
|
|
320
|
+
return [2 /*return*/, json.default_node_info.network];
|
|
330
321
|
}
|
|
331
322
|
});
|
|
332
323
|
});
|
|
333
324
|
};
|
|
334
|
-
FirmaUtil.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
switch (_a.label) {
|
|
339
|
-
case 0:
|
|
340
|
-
_a.trys.push([0, 2, , 3]);
|
|
341
|
-
return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.experimentalAdr36Verify(data, checkMsg)];
|
|
342
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
343
|
-
case 2:
|
|
344
|
-
error_5 = _a.sent();
|
|
345
|
-
FirmaUtil.printLog(error_5);
|
|
346
|
-
throw error_5;
|
|
347
|
-
case 3: return [2 /*return*/];
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
325
|
+
FirmaUtil.printLog = function (log) {
|
|
326
|
+
if (FirmaUtil.config.isShowLog === false)
|
|
327
|
+
return;
|
|
328
|
+
console.log("[FirmaSDK] ".concat(log));
|
|
351
329
|
};
|
|
352
330
|
FirmaUtil.recoverSigningAddress = function (signature, hash, recoveryIndex) {
|
|
353
331
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -358,7 +336,7 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
358
336
|
if (recoveryIndex > 3) {
|
|
359
337
|
throw new Error('Invalid recovery index');
|
|
360
338
|
}
|
|
361
|
-
sig = crypto_1.Secp256k1Signature.fromFixedLength(
|
|
339
|
+
sig = crypto_1.Secp256k1Signature.fromFixedLength((0, encoding_1.fromBase64)(signature));
|
|
362
340
|
extendedSig = new crypto_1.ExtendedSecp256k1Signature(sig.r(), sig.s(), recoveryIndex);
|
|
363
341
|
_b.label = 1;
|
|
364
342
|
case 1:
|
|
@@ -366,9 +344,9 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
366
344
|
return [4 /*yield*/, crypto_1.Secp256k1.recoverPubkey(extendedSig, hash)];
|
|
367
345
|
case 2:
|
|
368
346
|
recoveredPubKey = _b.sent();
|
|
369
|
-
return [2 /*return*/, amino_1.pubkeyToAddress({
|
|
347
|
+
return [2 /*return*/, (0, amino_1.pubkeyToAddress)({
|
|
370
348
|
type: 'tendermint/PubKeySecp256k1',
|
|
371
|
-
value:
|
|
349
|
+
value: (0, encoding_1.toBase64)(crypto_1.Secp256k1.compressPubkey(recoveredPubKey)),
|
|
372
350
|
}, 'firma')];
|
|
373
351
|
case 3:
|
|
374
352
|
_a = _b.sent();
|
|
@@ -404,48 +382,16 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
404
382
|
});
|
|
405
383
|
};
|
|
406
384
|
FirmaUtil.verifyDirectSignature = function (address, signature, signDoc) {
|
|
407
|
-
var messageHash = crypto_1.sha256(proto_signing_1.makeSignBytes(signDoc));
|
|
385
|
+
var messageHash = (0, crypto_1.sha256)((0, proto_signing_1.makeSignBytes)(signDoc));
|
|
408
386
|
return this.verifySignature(address, signature, messageHash);
|
|
409
387
|
};
|
|
410
388
|
;
|
|
411
389
|
FirmaUtil.parseSignDocValues = function (signDocString) {
|
|
412
390
|
var signDoc = JSON.parse(signDocString);
|
|
413
|
-
return __assign(__assign({}, signDoc), { bodyBytes:
|
|
391
|
+
return __assign(__assign({}, signDoc), { bodyBytes: (0, encoding_1.fromHex)(signDoc.bodyBytes), authInfoBytes: (0, encoding_1.fromHex)(signDoc.authInfoBytes), accountNumber: BigInt(signDoc.accountNumber) });
|
|
414
392
|
};
|
|
415
393
|
FirmaUtil.stringifySignDocValues = function (signDoc) {
|
|
416
|
-
return JSON.stringify(__assign(__assign({}, signDoc), { bodyBytes:
|
|
417
|
-
};
|
|
418
|
-
FirmaUtil.makeSignDoc = function (signerAddress, pubkey, messages, txMisc) {
|
|
419
|
-
if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
|
|
420
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
421
|
-
var result, chainID, serverUrl, registry;
|
|
422
|
-
return __generator(this, function (_a) {
|
|
423
|
-
switch (_a.label) {
|
|
424
|
-
case 0:
|
|
425
|
-
result = FirmaUtil.getSignAndBroadcastOption(FirmaUtil.config.denom, txMisc);
|
|
426
|
-
chainID = FirmaUtil.config.chainID;
|
|
427
|
-
serverUrl = FirmaUtil.config.rpcAddress;
|
|
428
|
-
registry = CommonTxClient_1.CommonTxClient.getRegistry();
|
|
429
|
-
return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.makeSignDocForSend(signerAddress, pubkey, messages, result.fee, result.memo, serverUrl, chainID, registry)];
|
|
430
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
FirmaUtil.makeSignDocWithStringify = function (signerAddress, pubkey, messages, txMisc) {
|
|
436
|
-
if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
|
|
437
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
-
var signDoc, stringSignDoc;
|
|
439
|
-
return __generator(this, function (_a) {
|
|
440
|
-
switch (_a.label) {
|
|
441
|
-
case 0: return [4 /*yield*/, this.makeSignDoc(signerAddress, pubkey, messages, txMisc)];
|
|
442
|
-
case 1:
|
|
443
|
-
signDoc = _a.sent();
|
|
444
|
-
stringSignDoc = this.stringifySignDocValues(signDoc);
|
|
445
|
-
return [2 /*return*/, stringSignDoc];
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
});
|
|
394
|
+
return JSON.stringify(__assign(__assign({}, signDoc), { bodyBytes: (0, encoding_1.toHex)(signDoc.bodyBytes), authInfoBytes: (0, encoding_1.toHex)(signDoc.authInfoBytes), accountNumber: signDoc.accountNumber.toString() }));
|
|
449
395
|
};
|
|
450
396
|
FirmaUtil.getAnyData = function (registry, message) {
|
|
451
397
|
var anyData = any_1.Any.fromPartial({
|
|
@@ -457,13 +403,6 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
457
403
|
FirmaUtil.getCommonTxClient = function (aliceWallet) {
|
|
458
404
|
return new CommonTxClient_1.CommonTxClient(aliceWallet, FirmaUtil.config.rpcAddress);
|
|
459
405
|
};
|
|
460
|
-
/**
|
|
461
|
-
* Parses a duration string to a Duration object.
|
|
462
|
-
* Supports formats like "336h0m0s", "21d", "1000ms", "1s", "1m", "1h", "1ns", "1µs"/"1us"
|
|
463
|
-
*
|
|
464
|
-
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
465
|
-
* @returns Duration object with seconds and nanos fields
|
|
466
|
-
*/
|
|
467
406
|
FirmaUtil.parseDurationString = function (durationStr) {
|
|
468
407
|
if (!durationStr || durationStr.trim() === "") {
|
|
469
408
|
return { seconds: BigInt(0), nanos: 0 };
|
|
@@ -508,7 +447,7 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
508
447
|
}
|
|
509
448
|
}
|
|
510
449
|
if (!hasMatches) {
|
|
511
|
-
throw new Error("Invalid duration format: "
|
|
450
|
+
throw new Error("Invalid duration format: ".concat(durationStr));
|
|
512
451
|
}
|
|
513
452
|
// Convert excess nanos to seconds
|
|
514
453
|
var extraSeconds = Math.floor(totalNanos / 1000000000);
|
|
@@ -522,13 +461,6 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
522
461
|
nanos: Math.floor(finalNanos)
|
|
523
462
|
};
|
|
524
463
|
};
|
|
525
|
-
/**
|
|
526
|
-
* Creates a Duration object from a duration string.
|
|
527
|
-
* This is a convenience method that combines parseDurationString with Duration.fromPartial.
|
|
528
|
-
*
|
|
529
|
-
* @param durationStr - Duration string to parse (e.g., "336h0m0s", "21d")
|
|
530
|
-
* @returns Duration object ready to use with protobuf
|
|
531
|
-
*/
|
|
532
464
|
FirmaUtil.createDurationFromString = function (durationStr) {
|
|
533
465
|
var _a = FirmaUtil.parseDurationString(durationStr), seconds = _a.seconds, nanos = _a.nanos;
|
|
534
466
|
// Import Duration if not already imported
|
|
@@ -548,13 +480,13 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
548
480
|
FirmaUtil.processCommissionRateAsDecimal = function (commissionRate) {
|
|
549
481
|
var trimmed = commissionRate.trim();
|
|
550
482
|
if (!commissionRate || trimmed === "") {
|
|
551
|
-
throw new Error("Invalid commission rate format: "
|
|
483
|
+
throw new Error("Invalid commission rate format: ".concat(commissionRate));
|
|
552
484
|
}
|
|
553
485
|
if (!/^-?\d+\.?\d*$/.test(trimmed)) {
|
|
554
|
-
throw new Error("Invalid commission rate format: "
|
|
486
|
+
throw new Error("Invalid commission rate format: ".concat(commissionRate));
|
|
555
487
|
}
|
|
556
488
|
// Validates input and creates BigNumber instance
|
|
557
|
-
var commissionRateBN = new bignumber_js_1.
|
|
489
|
+
var commissionRateBN = new bignumber_js_1.BigNumber(trimmed);
|
|
558
490
|
// Checks if it's a valid finite number
|
|
559
491
|
if (!commissionRateBN.isFinite())
|
|
560
492
|
throw new Error("Invalid commission rate format: " + commissionRate);
|
|
@@ -562,9 +494,132 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
562
494
|
if (commissionRateBN.isNegative() || commissionRateBN.isGreaterThan(1))
|
|
563
495
|
throw new Error("Invalid commission rate range. Must be between 0 and 1 inclusive.");
|
|
564
496
|
// Converts to atomics format (multiply by 10^18)
|
|
565
|
-
var atomics = commissionRateBN.multipliedBy(new bignumber_js_1.
|
|
497
|
+
var atomics = commissionRateBN.multipliedBy(new bignumber_js_1.BigNumber(10).pow(18));
|
|
566
498
|
// Returns integer string
|
|
567
|
-
return atomics.integerValue(bignumber_js_1.
|
|
499
|
+
return atomics.integerValue(bignumber_js_1.BigNumber.ROUND_DOWN).toString();
|
|
500
|
+
};
|
|
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
|
+
});
|
|
568
623
|
};
|
|
569
624
|
FirmaUtil.FctDecimal = 6;
|
|
570
625
|
return FirmaUtil;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { DirectSecp256k1Wallet, Registry } from "@cosmjs/proto-signing";
|
|
2
|
-
import { EncodeObject } from "@cosmjs/proto-signing";
|
|
1
|
+
import { DirectSecp256k1Wallet, EncodeObject, Registry } from "@cosmjs/proto-signing";
|
|
3
2
|
import { FirmaConfig } from "./FirmaConfig";
|
|
4
|
-
import {
|
|
3
|
+
import { Secp256k1Wallet } from "@cosmjs/amino";
|
|
5
4
|
import { LedgerWalletInterface } from "./firmachain/common/LedgerWallet";
|
|
5
|
+
import { SignAndBroadcastOptions } from "./firmachain/common";
|
|
6
6
|
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
7
|
-
import { Secp256k1Wallet } from "@cosmjs/amino";
|
|
8
7
|
export declare class FirmaWalletService {
|
|
9
8
|
private readonly config;
|
|
10
9
|
private mnemonic;
|
|
@@ -19,9 +18,6 @@ export declare class FirmaWalletService {
|
|
|
19
18
|
getRawAminoWallet(): Secp256k1Wallet;
|
|
20
19
|
getPrivateKey(): string;
|
|
21
20
|
getMnemonic(): string;
|
|
22
|
-
isLedger(): boolean;
|
|
23
|
-
initFromLedger(ledger: LedgerWalletInterface): Promise<FirmaWalletService>;
|
|
24
|
-
signLedger(messages: EncodeObject[], option: SignAndBroadcastOptions, registry: Registry): Promise<TxRaw>;
|
|
25
21
|
getPubKey(): Promise<string>;
|
|
26
22
|
getAddress(): Promise<string>;
|
|
27
23
|
constructor(config: FirmaConfig);
|
|
@@ -37,4 +33,7 @@ export declare class FirmaWalletService {
|
|
|
37
33
|
fromMnemonic(mnemonic: string, accountIndex?: number): Promise<FirmaWalletService>;
|
|
38
34
|
fromPrivateKey(privateKey: string): Promise<FirmaWalletService>;
|
|
39
35
|
generateMnemonic(): Promise<string>;
|
|
36
|
+
isLedger(): boolean;
|
|
37
|
+
initFromLedger(ledger: LedgerWalletInterface): Promise<FirmaWalletService>;
|
|
38
|
+
signLedger(messages: EncodeObject[], option: SignAndBroadcastOptions, registry: Registry): Promise<TxRaw>;
|
|
40
39
|
}
|