@firmachain/firma-js 0.2.64 → 0.3.1
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/README.md +1 -1
- package/dist/sdk/FirmaAuthzService.d.ts +8 -8
- package/dist/sdk/FirmaAuthzService.js +12 -6
- package/dist/sdk/FirmaBankService.d.ts +4 -4
- package/dist/sdk/FirmaContractService.d.ts +4 -4
- package/dist/sdk/FirmaCosmWasmCw20.d.ts +14 -14
- package/dist/sdk/FirmaCosmWasmCw721.d.ts +14 -14
- package/dist/sdk/FirmaCosmWasmCwBridge.d.ts +9 -9
- package/dist/sdk/FirmaCosmWasmCwMarketplace.d.ts +8 -8
- package/dist/sdk/FirmaCosmWasmService.d.ts +8 -8
- package/dist/sdk/FirmaCosmWasmService.js +2 -3
- package/dist/sdk/FirmaDistributionService.d.ts +6 -6
- package/dist/sdk/FirmaFeeGrantService.d.ts +4 -4
- package/dist/sdk/FirmaGovService.d.ts +27 -16
- package/dist/sdk/FirmaGovService.js +305 -195
- package/dist/sdk/FirmaIbcService.d.ts +3 -4
- package/dist/sdk/FirmaIbcService.js +5 -2
- package/dist/sdk/FirmaNftService.d.ts +5 -5
- package/dist/sdk/FirmaStakingService.d.ts +6 -6
- package/dist/sdk/FirmaTokenService.d.ts +5 -5
- package/dist/sdk/FirmaUtil.d.ts +1 -1
- package/dist/sdk/FirmaUtil.js +12 -14
- package/dist/sdk/firmachain/amino/addresses.js +1 -1
- package/dist/sdk/firmachain/amino/aminomsgs.d.ts +10 -0
- package/dist/sdk/firmachain/amino/aminomsgs.js +5 -1
- package/dist/sdk/firmachain/amino/aminotypes.js +27 -10
- package/dist/sdk/firmachain/amino/coins.d.ts +14 -2
- package/dist/sdk/firmachain/amino/coins.js +26 -5
- package/dist/sdk/firmachain/amino/encoding.d.ts +10 -1
- package/dist/sdk/firmachain/amino/encoding.js +21 -3
- package/dist/sdk/firmachain/amino/signdoc.d.ts +21 -3
- package/dist/sdk/firmachain/amino/signdoc.js +37 -11
- package/dist/sdk/firmachain/amino/signer.d.ts +2 -1
- package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +7 -6
- package/dist/sdk/firmachain/authz/AuthzTxTypes.js +7 -6
- package/dist/sdk/firmachain/bank/BankQueryClient.js +1 -1
- package/dist/sdk/firmachain/common/CommonTxClient.js +11 -9
- package/dist/sdk/firmachain/common/ITxClient.d.ts +6 -6
- package/dist/sdk/firmachain/common/ITxClient.js +82 -24
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +4 -9
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +37 -32
- package/dist/sdk/firmachain/common/LedgerWallet.js +4 -8
- package/dist/sdk/firmachain/common/TxCommon.d.ts +1 -2
- package/dist/sdk/firmachain/common/accounts.d.ts +7 -3
- package/dist/sdk/firmachain/common/accounts.js +28 -33
- package/dist/sdk/firmachain/common/aminotypes.d.ts +19 -0
- package/dist/sdk/firmachain/common/aminotypes.js +74 -0
- package/dist/sdk/firmachain/common/events.d.ts +32 -0
- package/dist/sdk/firmachain/common/events.js +18 -0
- package/dist/sdk/firmachain/common/fee.d.ts +26 -0
- package/dist/sdk/firmachain/common/fee.js +83 -0
- package/dist/sdk/firmachain/common/index.d.ts +1 -0
- package/dist/sdk/firmachain/common/index.js +3 -0
- package/dist/sdk/firmachain/common/modules/auth/queries.d.ts +15 -0
- package/dist/sdk/firmachain/common/modules/auth/queries.js +64 -0
- package/dist/sdk/firmachain/common/modules/authz/aminomessages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/authz/aminomessages.js +15 -0
- package/dist/sdk/firmachain/common/modules/authz/messages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/authz/messages.js +9 -0
- package/dist/sdk/firmachain/common/modules/authz/queries.d.ts +10 -0
- package/dist/sdk/firmachain/common/modules/authz/queries.js +88 -0
- package/dist/sdk/firmachain/common/modules/bank/aminomessages.d.ts +35 -0
- package/dist/sdk/firmachain/common/modules/bank/aminomessages.js +85 -0
- package/dist/sdk/firmachain/common/modules/bank/messages.d.ts +8 -0
- package/dist/sdk/firmachain/common/modules/bank/messages.js +12 -0
- package/dist/sdk/firmachain/common/modules/bank/queries.d.ts +15 -0
- package/dist/sdk/firmachain/common/modules/bank/queries.js +128 -0
- package/dist/sdk/firmachain/common/modules/crisis/aminomessages.d.ts +14 -0
- package/dist/sdk/firmachain/common/modules/crisis/aminomessages.js +11 -0
- package/dist/sdk/firmachain/common/modules/distribution/aminomessages.d.ts +44 -0
- package/dist/sdk/firmachain/common/modules/distribution/aminomessages.js +113 -0
- package/dist/sdk/firmachain/common/modules/distribution/messages.d.ts +8 -0
- package/dist/sdk/firmachain/common/modules/distribution/messages.js +15 -0
- package/dist/sdk/firmachain/common/modules/distribution/queries.d.ts +16 -0
- package/dist/sdk/firmachain/common/modules/distribution/queries.js +171 -0
- package/dist/sdk/firmachain/common/modules/evidence/aminomessages.d.ts +18 -0
- package/dist/sdk/firmachain/common/modules/evidence/aminomessages.js +11 -0
- package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.js +14 -0
- package/dist/sdk/firmachain/common/modules/feegrant/messages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/feegrant/messages.js +8 -0
- package/dist/sdk/firmachain/common/modules/feegrant/queries.d.ts +9 -0
- package/dist/sdk/firmachain/common/modules/feegrant/queries.js +81 -0
- package/dist/sdk/firmachain/common/modules/gov/aminomessages.d.ts +79 -0
- package/dist/sdk/firmachain/common/modules/gov/aminomessages.js +152 -0
- package/dist/sdk/firmachain/common/modules/gov/messages.d.ts +29 -0
- package/dist/sdk/firmachain/common/modules/gov/messages.js +38 -0
- package/dist/sdk/firmachain/common/modules/gov/queries.d.ts +19 -0
- package/dist/sdk/firmachain/common/modules/gov/queries.js +160 -0
- package/dist/sdk/firmachain/common/modules/group/aminomessages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/group/aminomessages.js +8 -0
- package/dist/sdk/firmachain/common/modules/group/messages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/group/messages.js +28 -0
- package/dist/sdk/firmachain/common/modules/ibc/aminomessages.d.ts +38 -0
- package/dist/sdk/firmachain/common/modules/ibc/aminomessages.js +55 -0
- package/dist/sdk/firmachain/common/modules/ibc/messages.d.ts +8 -0
- package/dist/sdk/firmachain/common/modules/ibc/messages.js +32 -0
- package/dist/sdk/firmachain/common/modules/ibc/queries.d.ts +58 -0
- package/dist/sdk/firmachain/common/modules/ibc/queries.js +576 -0
- package/dist/sdk/firmachain/common/modules/index.d.ts +32 -0
- package/dist/sdk/firmachain/common/modules/index.js +101 -0
- package/dist/sdk/firmachain/common/modules/mint/queries.d.ts +21 -0
- package/dist/sdk/firmachain/common/modules/mint/queries.js +95 -0
- package/dist/sdk/firmachain/common/modules/slashing/aminomessages.d.ts +12 -0
- package/dist/sdk/firmachain/common/modules/slashing/aminomessages.js +11 -0
- package/dist/sdk/firmachain/common/modules/slashing/queries.d.ts +10 -0
- package/dist/sdk/firmachain/common/modules/slashing/queries.js +88 -0
- package/dist/sdk/firmachain/common/modules/staking/aminomessages.d.ts +112 -0
- package/dist/sdk/firmachain/common/modules/staking/aminomessages.js +234 -0
- package/dist/sdk/firmachain/common/modules/staking/messages.d.ts +33 -0
- package/dist/sdk/firmachain/common/modules/staking/messages.js +37 -0
- package/dist/sdk/firmachain/common/modules/staking/queries.d.ts +23 -0
- package/dist/sdk/firmachain/common/modules/staking/queries.js +242 -0
- package/dist/sdk/firmachain/common/modules/tx/queries.d.ts +11 -0
- package/dist/sdk/firmachain/common/modules/tx/queries.js +103 -0
- package/dist/sdk/firmachain/common/modules/vesting/aminomessages.d.ts +16 -0
- package/dist/sdk/firmachain/common/modules/vesting/aminomessages.js +56 -0
- package/dist/sdk/firmachain/common/modules/vesting/messages.d.ts +2 -0
- package/dist/sdk/firmachain/common/modules/vesting/messages.js +7 -0
- package/dist/sdk/firmachain/common/queryclient/index.d.ts +2 -0
- package/dist/sdk/firmachain/common/queryclient/index.js +10 -0
- package/dist/sdk/firmachain/common/queryclient/queryclient.d.ts +75 -0
- package/dist/sdk/firmachain/common/queryclient/queryclient.js +157 -0
- package/dist/sdk/firmachain/common/queryclient/utils.d.ts +33 -0
- package/dist/sdk/firmachain/common/queryclient/utils.js +101 -0
- package/dist/sdk/firmachain/common/search.d.ts +10 -0
- package/dist/sdk/firmachain/common/search.js +7 -0
- package/dist/sdk/firmachain/common/signing.d.ts +8 -3
- package/dist/sdk/firmachain/common/signing.js +24 -12
- package/dist/sdk/firmachain/common/signingstargateclient.d.ts +107 -30
- package/dist/sdk/firmachain/common/signingstargateclient.js +445 -128
- package/dist/sdk/firmachain/common/stargateclient.d.ts +184 -20
- package/dist/sdk/firmachain/common/stargateclient.js +351 -35
- package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +2 -2
- package/dist/sdk/firmachain/contract/ContractTxClient.js +4 -4
- package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +1 -1
- package/dist/sdk/firmachain/contract/ContractTxTypes.js +3 -3
- package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +1 -1
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +5 -5
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +10 -8
- package/dist/sdk/firmachain/google/protobuf/any.d.ts +3 -2
- package/dist/sdk/firmachain/google/protobuf/any.js +2 -1
- package/dist/sdk/firmachain/google/protobuf/duration.d.ts +3 -2
- package/dist/sdk/firmachain/google/protobuf/duration.js +2 -1
- package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +3 -2
- package/dist/sdk/firmachain/google/protobuf/timestamp.js +2 -1
- package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +13 -1
- package/dist/sdk/firmachain/gov/GovQueryClient.js +9 -2
- package/dist/sdk/firmachain/gov/GovTxClient.d.ts +12 -0
- package/dist/sdk/firmachain/gov/GovTxClient.js +11 -1
- package/dist/sdk/firmachain/nft/NftTxClient.d.ts +3 -3
- package/dist/sdk/firmachain/nft/NftTxClient.js +6 -6
- package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +1 -1
- package/dist/sdk/firmachain/nft/NftTxTypes.js +4 -4
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +1 -0
- package/dist/sdk/firmachain/staking/StakingQueryClient.js +0 -1
- package/dist/sdk/firmachain/token/TokenTxClient.d.ts +4 -4
- package/dist/sdk/firmachain/token/TokenTxClient.js +8 -8
- package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +1 -1
- package/dist/sdk/firmachain/token/TokenTxTypes.js +5 -5
- package/dist/test/00.wallet.test.js +15 -9
- package/dist/test/01.contract_tx.test.js +53 -45
- package/dist/test/02.contract_query.test.js +54 -31
- package/dist/test/03.contract_scenario.test.js +170 -326
- package/dist/test/04.bank_tx.test.js +58 -59
- package/dist/test/05.bank_query.test.js +51 -56
- package/dist/test/06.feegrant_tx.test.js +74 -89
- package/dist/test/07.feegrant_query.test.js +69 -27
- package/dist/test/08.gas_estimate.test.js +422 -392
- package/dist/test/09.ipfs.test.js +3 -3
- package/dist/test/10.nft_tx.test.js +108 -76
- package/dist/test/11.nft_query.test.js +41 -46
- package/dist/test/12.staking_tx.test.js +81 -98
- package/dist/test/13.staking_query.test.js +66 -12
- package/dist/test/14.distribution_tx.test.js +69 -78
- package/dist/test/15.distribution_query.test.js +81 -57
- package/dist/test/16.gov_tx.test.js +247 -107
- package/dist/test/17.gov_query.test.js +48 -9
- package/dist/test/18.util.test.js +6 -1
- package/dist/test/19.chain.test.js +50 -4
- package/dist/test/20.slashing_query.test.js +31 -1
- package/dist/test/21.token_tx.test.js +48 -56
- package/dist/test/22.token_query.test.js +24 -20
- package/dist/test/23.authz_tx.test.js +119 -240
- package/dist/test/24.authz_query.test.js +116 -56
- package/dist/test/25.cosmwasm_tx.test.js +95 -57
- package/dist/test/26.cosmwasm_query.test.js +66 -26
- package/dist/test/27.arbitary_sign.test.js +59 -67
- package/dist/test/28.ibc_tx.test.js +29 -17
- package/dist/test/29.mint_query.test.js +2 -0
- package/dist/test/30.cw20_tx.test.js +161 -226
- package/dist/test/31.cw20_query.test.js +183 -37
- package/dist/test/32.cw721_tx.test.js +147 -149
- package/dist/test/33.cw721_query.test.js +188 -36
- package/dist/test/34.cw_bridge_tx.test.js +266 -155
- package/dist/test/35.cw_bridge_tx_low.test.js +221 -81
- package/dist/test/36.cw_bridge_query.test.js +157 -21
- package/dist/test/37.cw_marketplace_tx.test.js +22 -22
- package/dist/test/38.cw_marketplace_query.test.js +9 -9
- package/dist/test/config_test.d.ts +10 -4
- package/dist/test/config_test.js +16 -9
- package/dist/test/config_test.sample.d.ts +11 -0
- package/dist/test/config_test.sample.js +14 -0
- package/package.json +9 -7
- package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +0 -50
- package/dist/sdk/firmachain/common/signingaminostargateclient.js +0 -267
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -75,78 +86,316 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
75
86
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
87
|
};
|
|
77
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
-
exports.SigningStargateClient = void 0;
|
|
89
|
+
exports.SigningStargateClient = exports.isMsgSignData = exports.createDefaultAminoConverters = exports.defaultRegistryTypes = void 0;
|
|
90
|
+
var amino_1 = require("@cosmjs/amino");
|
|
91
|
+
var crypto_1 = require("@cosmjs/crypto");
|
|
79
92
|
var encoding_1 = require("@cosmjs/encoding");
|
|
80
|
-
var
|
|
93
|
+
var math_1 = require("@cosmjs/math");
|
|
81
94
|
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
82
95
|
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
96
|
+
var utils_1 = require("@cosmjs/utils");
|
|
97
|
+
var coin_1 = require("cosmjs-types/cosmos/base/v1beta1/coin");
|
|
98
|
+
var tx_1 = require("cosmjs-types/cosmos/distribution/v1beta1/tx");
|
|
99
|
+
var tx_2 = require("cosmjs-types/cosmos/staking/v1beta1/tx");
|
|
83
100
|
var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
|
|
84
|
-
var
|
|
85
|
-
var
|
|
101
|
+
var tx_3 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
102
|
+
var tx_4 = require("cosmjs-types/ibc/applications/transfer/v1/tx");
|
|
103
|
+
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
104
|
+
var aminotypes_1 = require("./aminotypes");
|
|
105
|
+
var fee_1 = require("./fee");
|
|
106
|
+
var modules_1 = require("./modules");
|
|
107
|
+
var modules_2 = require("./modules");
|
|
86
108
|
var stargateclient_1 = require("./stargateclient");
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
var FirmaUtil_1 = require("../../FirmaUtil");
|
|
110
|
+
exports.defaultRegistryTypes = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
|
|
111
|
+
["/cosmos.base.v1beta1.Coin", coin_1.Coin]
|
|
112
|
+
], __read(modules_1.authzTypes)), __read(modules_1.bankTypes)), __read(modules_1.distributionTypes)), __read(modules_1.feegrantTypes)), __read(modules_1.govTypes)), __read(modules_1.groupTypes)), __read(modules_1.stakingTypes)), __read(modules_1.ibcTypes)), __read(modules_1.vestingTypes));
|
|
113
|
+
function createDefaultAminoConverters() {
|
|
114
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, modules_2.createAuthzAminoConverters()), modules_2.createBankAminoConverters()), modules_2.createDistributionAminoConverters()), modules_2.createGovAminoConverters()), modules_2.createStakingAminoConverters()), modules_2.createIbcAminoConverters()), modules_2.createFeegrantAminoConverters()), modules_2.createVestingAminoConverters());
|
|
115
|
+
}
|
|
116
|
+
exports.createDefaultAminoConverters = createDefaultAminoConverters;
|
|
117
|
+
function isMsgSignData(msg) {
|
|
118
|
+
var castedMsg = msg;
|
|
119
|
+
if (castedMsg.type !== "sign/MsgSignData")
|
|
120
|
+
return false;
|
|
121
|
+
if (!utils_1.isNonNullObject(castedMsg.value))
|
|
122
|
+
return false;
|
|
123
|
+
if (typeof castedMsg.value.signer !== "string")
|
|
124
|
+
return false;
|
|
125
|
+
if (typeof castedMsg.value.data !== "string")
|
|
126
|
+
return false;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
exports.isMsgSignData = isMsgSignData;
|
|
92
130
|
var SigningStargateClient = /** @class */ (function (_super) {
|
|
93
131
|
__extends(SigningStargateClient, _super);
|
|
94
|
-
function SigningStargateClient(
|
|
95
|
-
var _this = _super.call(this,
|
|
132
|
+
function SigningStargateClient(cometClient, signer, options) {
|
|
133
|
+
var _this = _super.call(this, cometClient, options) || this;
|
|
134
|
+
// Starting with Cosmos SDK 0.47, we see many cases in which 1.3 is not enough anymore
|
|
135
|
+
// E.g. https://github.com/cosmos/cosmos-sdk/issues/16020
|
|
136
|
+
_this.defaultGasMultiplier = 1.4;
|
|
137
|
+
var _a = options.registry, registry = _a === void 0 ? new proto_signing_1.Registry(exports.defaultRegistryTypes) : _a, _b = options.aminoTypes, aminoTypes = _b === void 0 ? new aminotypes_1.AminoTypes(createDefaultAminoConverters()) : _b;
|
|
96
138
|
_this.registry = registry;
|
|
139
|
+
_this.aminoTypes = aminoTypes;
|
|
97
140
|
_this.signer = signer;
|
|
141
|
+
_this.broadcastTimeoutMs = options.broadcastTimeoutMs;
|
|
142
|
+
_this.broadcastPollIntervalMs = options.broadcastPollIntervalMs;
|
|
143
|
+
_this.gasPrice = options.gasPrice;
|
|
98
144
|
return _this;
|
|
99
145
|
}
|
|
100
|
-
|
|
101
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Creates an instance by connecting to the given CometBFT RPC endpoint.
|
|
148
|
+
*
|
|
149
|
+
* This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client.
|
|
150
|
+
* To set the Comet client explicitly, use `createWithSigner`.
|
|
151
|
+
*/
|
|
152
|
+
SigningStargateClient.connectWithSigner = function (endpoint, signer, options) {
|
|
153
|
+
if (options === void 0) { options = {}; }
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var cometClient;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, tendermint_rpc_1.connectComet(endpoint)];
|
|
159
|
+
case 1:
|
|
160
|
+
cometClient = _a.sent();
|
|
161
|
+
return [2 /*return*/, SigningStargateClient.createWithSigner(cometClient, signer, options)];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Creates an instance from a manually created Comet client.
|
|
168
|
+
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
|
|
169
|
+
*/
|
|
170
|
+
SigningStargateClient.createWithSigner = function (cometClient, signer, options) {
|
|
171
|
+
if (options === void 0) { options = {}; }
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
return [2 /*return*/, new SigningStargateClient(cometClient, signer, options)];
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Creates a client in offline mode.
|
|
180
|
+
*
|
|
181
|
+
* This should only be used in niche cases where you know exactly what you're doing,
|
|
182
|
+
* e.g. when building an offline signing application.
|
|
183
|
+
*
|
|
184
|
+
* When you try to use online functionality with such a signer, an
|
|
185
|
+
* exception will be raised.
|
|
186
|
+
*/
|
|
187
|
+
SigningStargateClient.offline = function (signer, options) {
|
|
188
|
+
if (options === void 0) { options = {}; }
|
|
189
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
+
return __generator(this, function (_a) {
|
|
191
|
+
return [2 /*return*/, new SigningStargateClient(undefined, signer, options)];
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
SigningStargateClient.prototype.simulate = function (signerAddress, messages, memo) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var anyMsgs, accountFromSigner, pubkey, sequence, gasInfo;
|
|
198
|
+
var _this = this;
|
|
199
|
+
return __generator(this, function (_a) {
|
|
200
|
+
switch (_a.label) {
|
|
201
|
+
case 0:
|
|
202
|
+
anyMsgs = messages.map(function (m) { return _this.registry.encodeAsAny(m); });
|
|
203
|
+
return [4 /*yield*/, this.signer.getAccounts()];
|
|
204
|
+
case 1:
|
|
205
|
+
accountFromSigner = (_a.sent()).find(function (account) { return account.address === signerAddress; });
|
|
206
|
+
if (!accountFromSigner) {
|
|
207
|
+
throw new Error("Failed to retrieve account from signer");
|
|
208
|
+
}
|
|
209
|
+
pubkey = amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey);
|
|
210
|
+
return [4 /*yield*/, this.getSequence(signerAddress)];
|
|
211
|
+
case 2:
|
|
212
|
+
sequence = (_a.sent()).sequence;
|
|
213
|
+
return [4 /*yield*/, this.forceGetQueryClient().tx.simulate(anyMsgs, memo, pubkey, sequence)];
|
|
214
|
+
case 3:
|
|
215
|
+
gasInfo = (_a.sent()).gasInfo;
|
|
216
|
+
utils_1.assertDefined(gasInfo);
|
|
217
|
+
return [2 /*return*/, math_1.Uint53.fromString(gasInfo.gasUsed.toString()).toNumber()];
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
SigningStargateClient.prototype.sendTokens = function (senderAddress, recipientAddress, amount, fee, memo) {
|
|
223
|
+
if (memo === void 0) { memo = ""; }
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
var sendMsg;
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
sendMsg = {
|
|
228
|
+
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
|
229
|
+
value: {
|
|
230
|
+
fromAddress: senderAddress,
|
|
231
|
+
toAddress: recipientAddress,
|
|
232
|
+
amount: __spreadArray([], __read(amount)),
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
return [2 /*return*/, this.signAndBroadcast(senderAddress, [sendMsg], fee, memo)];
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
SigningStargateClient.prototype.delegateTokens = function (delegatorAddress, validatorAddress, amount, fee, memo) {
|
|
240
|
+
if (memo === void 0) { memo = ""; }
|
|
241
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
242
|
+
var delegateMsg;
|
|
243
|
+
return __generator(this, function (_a) {
|
|
244
|
+
delegateMsg = {
|
|
245
|
+
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
|
246
|
+
value: tx_2.MsgDelegate.fromPartial({
|
|
247
|
+
delegatorAddress: delegatorAddress,
|
|
248
|
+
validatorAddress: validatorAddress,
|
|
249
|
+
amount: amount,
|
|
250
|
+
}),
|
|
251
|
+
};
|
|
252
|
+
return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [delegateMsg], fee, memo)];
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
SigningStargateClient.prototype.undelegateTokens = function (delegatorAddress, validatorAddress, amount, fee, memo) {
|
|
257
|
+
if (memo === void 0) { memo = ""; }
|
|
258
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
259
|
+
var undelegateMsg;
|
|
260
|
+
return __generator(this, function (_a) {
|
|
261
|
+
undelegateMsg = {
|
|
262
|
+
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
|
263
|
+
value: tx_2.MsgUndelegate.fromPartial({
|
|
264
|
+
delegatorAddress: delegatorAddress,
|
|
265
|
+
validatorAddress: validatorAddress,
|
|
266
|
+
amount: amount,
|
|
267
|
+
}),
|
|
268
|
+
};
|
|
269
|
+
return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [undelegateMsg], fee, memo)];
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
SigningStargateClient.prototype.withdrawRewards = function (delegatorAddress, validatorAddress, fee, memo) {
|
|
274
|
+
if (memo === void 0) { memo = ""; }
|
|
275
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
+
var withdrawMsg;
|
|
277
|
+
return __generator(this, function (_a) {
|
|
278
|
+
withdrawMsg = {
|
|
279
|
+
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
280
|
+
value: tx_1.MsgWithdrawDelegatorReward.fromPartial({
|
|
281
|
+
delegatorAddress: delegatorAddress,
|
|
282
|
+
validatorAddress: validatorAddress,
|
|
283
|
+
}),
|
|
284
|
+
};
|
|
285
|
+
return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [withdrawMsg], fee, memo)];
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* @deprecated This API does not support setting the memo field of `MsgTransfer` (only the transaction memo).
|
|
291
|
+
* We'll remove this method at some point because trying to wrap the various message types is a losing strategy.
|
|
292
|
+
* Please migrate to `signAndBroadcast` with an `MsgTransferEncodeObject` created in the caller code instead.
|
|
293
|
+
* @see https://github.com/cosmos/cosmjs/issues/1493
|
|
294
|
+
*/
|
|
295
|
+
SigningStargateClient.prototype.sendIbcTokens = function (senderAddress, recipientAddress, transferAmount, sourcePort, sourceChannel, timeoutHeight,
|
|
296
|
+
/** timeout in seconds */
|
|
297
|
+
timeoutTimestamp, fee, memo) {
|
|
298
|
+
if (memo === void 0) { memo = ""; }
|
|
299
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
300
|
+
var timeoutTimestampNanoseconds, transferMsg;
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
timeoutTimestampNanoseconds = timeoutTimestamp
|
|
303
|
+
? BigInt(timeoutTimestamp) * BigInt(1000000000)
|
|
304
|
+
: undefined;
|
|
305
|
+
transferMsg = {
|
|
306
|
+
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
|
307
|
+
value: tx_4.MsgTransfer.fromPartial({
|
|
308
|
+
sourcePort: sourcePort,
|
|
309
|
+
sourceChannel: sourceChannel,
|
|
310
|
+
sender: senderAddress,
|
|
311
|
+
receiver: recipientAddress,
|
|
312
|
+
token: transferAmount,
|
|
313
|
+
timeoutHeight: timeoutHeight,
|
|
314
|
+
timeoutTimestamp: timeoutTimestampNanoseconds,
|
|
315
|
+
}),
|
|
316
|
+
};
|
|
317
|
+
return [2 /*return*/, this.signAndBroadcast(senderAddress, [transferMsg], fee, memo)];
|
|
318
|
+
});
|
|
319
|
+
});
|
|
102
320
|
};
|
|
103
|
-
SigningStargateClient.
|
|
321
|
+
SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo, timeoutHeight) {
|
|
322
|
+
if (memo === void 0) { memo = ""; }
|
|
104
323
|
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
-
var
|
|
324
|
+
var usedFee, gasEstimation, multiplier, txRaw, txBytes;
|
|
106
325
|
return __generator(this, function (_a) {
|
|
107
326
|
switch (_a.label) {
|
|
108
327
|
case 0:
|
|
109
|
-
|
|
110
|
-
|
|
328
|
+
if (!(fee == "auto" || typeof fee === "number")) return [3 /*break*/, 2];
|
|
329
|
+
utils_1.assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
|
|
330
|
+
return [4 /*yield*/, this.simulate(signerAddress, messages, memo)];
|
|
111
331
|
case 1:
|
|
112
|
-
|
|
113
|
-
|
|
332
|
+
gasEstimation = _a.sent();
|
|
333
|
+
multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier;
|
|
334
|
+
usedFee = fee_1.calculateFee(Math.round(gasEstimation * multiplier), this.gasPrice);
|
|
335
|
+
return [3 /*break*/, 3];
|
|
336
|
+
case 2:
|
|
337
|
+
usedFee = fee;
|
|
338
|
+
_a.label = 3;
|
|
339
|
+
case 3: return [4 /*yield*/, this.sign(signerAddress, messages, usedFee, memo, undefined, timeoutHeight)];
|
|
340
|
+
case 4:
|
|
341
|
+
txRaw = _a.sent();
|
|
342
|
+
txBytes = tx_3.TxRaw.encode(txRaw).finish();
|
|
343
|
+
return [2 /*return*/, this.broadcastTx(txBytes, this.broadcastTimeoutMs, this.broadcastPollIntervalMs)];
|
|
114
344
|
}
|
|
115
345
|
});
|
|
116
346
|
});
|
|
117
347
|
};
|
|
118
|
-
|
|
348
|
+
/**
|
|
349
|
+
* This method is useful if you want to send a transaction in broadcast,
|
|
350
|
+
* without waiting for it to be placed inside a block, because for example
|
|
351
|
+
* I would like to receive the hash to later track the transaction with another tool.
|
|
352
|
+
* @returns Returns the hash of the transaction
|
|
353
|
+
*/
|
|
354
|
+
SigningStargateClient.prototype.signAndBroadcastSync = function (signerAddress, messages, fee, memo, timeoutHeight) {
|
|
119
355
|
if (memo === void 0) { memo = ""; }
|
|
120
356
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var txRaw, txBytes;
|
|
357
|
+
var usedFee, gasEstimation, multiplier, txRaw, txBytes;
|
|
122
358
|
return __generator(this, function (_a) {
|
|
123
359
|
switch (_a.label) {
|
|
124
|
-
case 0:
|
|
360
|
+
case 0:
|
|
361
|
+
if (!(fee == "auto" || typeof fee === "number")) return [3 /*break*/, 2];
|
|
362
|
+
utils_1.assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
|
|
363
|
+
return [4 /*yield*/, this.simulate(signerAddress, messages, memo)];
|
|
125
364
|
case 1:
|
|
365
|
+
gasEstimation = _a.sent();
|
|
366
|
+
multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier;
|
|
367
|
+
usedFee = fee_1.calculateFee(Math.round(gasEstimation * multiplier), this.gasPrice);
|
|
368
|
+
return [3 /*break*/, 3];
|
|
369
|
+
case 2:
|
|
370
|
+
usedFee = fee;
|
|
371
|
+
_a.label = 3;
|
|
372
|
+
case 3: return [4 /*yield*/, this.sign(signerAddress, messages, usedFee, memo, undefined, timeoutHeight)];
|
|
373
|
+
case 4:
|
|
126
374
|
txRaw = _a.sent();
|
|
127
|
-
txBytes =
|
|
128
|
-
return [2 /*return*/, this.
|
|
375
|
+
txBytes = tx_3.TxRaw.encode(txRaw).finish();
|
|
376
|
+
return [2 /*return*/, this.broadcastTxSync(txBytes)];
|
|
129
377
|
}
|
|
130
378
|
});
|
|
131
379
|
});
|
|
132
380
|
};
|
|
133
381
|
SigningStargateClient.makeSignDocForSend = function (signerAddress, pubkeyStr, messages, fee, memo, serverUrl, chainId, registry) {
|
|
134
382
|
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
-
var _a, accountNumber, sequence, account, rawSecp256k1Pubkey, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes;
|
|
383
|
+
var client, _a, accountNumber, sequence, account, rawSecp256k1Pubkey, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, feePayer, authInfoBytes;
|
|
136
384
|
return __generator(this, function (_b) {
|
|
137
385
|
switch (_b.label) {
|
|
138
|
-
case 0:
|
|
139
|
-
SigningStargateClient._endpoint = serverUrl;
|
|
140
|
-
return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
|
|
386
|
+
case 0: return [4 /*yield*/, SigningStargateClient.connect(serverUrl)];
|
|
141
387
|
case 1:
|
|
142
|
-
|
|
143
|
-
return [4 /*yield*/,
|
|
388
|
+
client = _b.sent();
|
|
389
|
+
return [4 /*yield*/, client.getSequence(signerAddress)];
|
|
144
390
|
case 2:
|
|
391
|
+
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
392
|
+
return [4 /*yield*/, client.getAccount(signerAddress)];
|
|
393
|
+
case 3:
|
|
145
394
|
account = _b.sent();
|
|
146
395
|
if (account == null)
|
|
147
396
|
throw new Error("Failed to retrieve account from signer");
|
|
148
397
|
rawSecp256k1Pubkey = encoding_1.fromBase64(pubkeyStr);
|
|
149
|
-
pubkey = proto_signing_1.encodePubkey(
|
|
398
|
+
pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(rawSecp256k1Pubkey));
|
|
150
399
|
txBodyEncodeObject = {
|
|
151
400
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
152
401
|
value: {
|
|
@@ -156,13 +405,24 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
156
405
|
};
|
|
157
406
|
txBodyBytes = registry.encode(txBodyEncodeObject);
|
|
158
407
|
gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
159
|
-
|
|
408
|
+
feePayer = signerAddress;
|
|
409
|
+
authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter, feePayer);
|
|
160
410
|
return [2 /*return*/, proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber)];
|
|
161
411
|
}
|
|
162
412
|
});
|
|
163
413
|
});
|
|
164
414
|
};
|
|
165
|
-
|
|
415
|
+
/**
|
|
416
|
+
* Gets account number and sequence from the API, creates a sign doc,
|
|
417
|
+
* creates a single signature and assembles the signed transaction.
|
|
418
|
+
*
|
|
419
|
+
* The sign mode (SIGN_MODE_DIRECT or SIGN_MODE_LEGACY_AMINO_JSON) is determined by this client's signer.
|
|
420
|
+
*
|
|
421
|
+
* You can pass signer data (account number, sequence and chain ID) explicitly instead of querying them
|
|
422
|
+
* from the chain. This is needed when signing for a multisig account, but it also allows for offline signing
|
|
423
|
+
* (See the SigningStargateClient.offline constructor).
|
|
424
|
+
*/
|
|
425
|
+
SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData, timeoutHeight) {
|
|
166
426
|
return __awaiter(this, void 0, void 0, function () {
|
|
167
427
|
var signerData, _a, accountNumber, sequence, chainId;
|
|
168
428
|
return __generator(this, function (_b) {
|
|
@@ -171,7 +431,7 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
171
431
|
if (!explicitSignerData) return [3 /*break*/, 1];
|
|
172
432
|
signerData = explicitSignerData;
|
|
173
433
|
return [3 /*break*/, 4];
|
|
174
|
-
case 1: return [4 /*yield*/,
|
|
434
|
+
case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
|
|
175
435
|
case 2:
|
|
176
436
|
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
177
437
|
return [4 /*yield*/, this.getChainId()];
|
|
@@ -183,7 +443,9 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
183
443
|
chainId: chainId,
|
|
184
444
|
};
|
|
185
445
|
_b.label = 4;
|
|
186
|
-
case 4: return [2 /*return*/, this.
|
|
446
|
+
case 4: return [2 /*return*/, proto_signing_1.isOfflineDirectSigner(this.signer)
|
|
447
|
+
? this.signDirect(signerAddress, messages, fee, memo, signerData, timeoutHeight)
|
|
448
|
+
: this.signAmino(signerAddress, messages, fee, memo, signerData, timeoutHeight)];
|
|
187
449
|
}
|
|
188
450
|
});
|
|
189
451
|
});
|
|
@@ -195,7 +457,7 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
195
457
|
switch (_a.label) {
|
|
196
458
|
case 0:
|
|
197
459
|
if (!!this.chainId) return [3 /*break*/, 2];
|
|
198
|
-
return [4 /*yield*/, this.
|
|
460
|
+
return [4 /*yield*/, this.forceGetCometClient().status()];
|
|
199
461
|
case 1:
|
|
200
462
|
response = _a.sent();
|
|
201
463
|
chainId = response.nodeInfo.network;
|
|
@@ -208,117 +470,81 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
208
470
|
});
|
|
209
471
|
});
|
|
210
472
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
214
|
-
* The result is typically 20 bytes long but not restricted to that.
|
|
215
|
-
*/
|
|
216
|
-
SigningStargateClient.toAccAddress = function (address) {
|
|
217
|
-
return encoding_2.Bech32.decode(address).data;
|
|
218
|
-
};
|
|
219
|
-
SigningStargateClient.getAccount = function (address) {
|
|
473
|
+
SigningStargateClient.prototype.signAmino = function (signerAddress, messages, fee, memo, _a, timeoutHeight) {
|
|
474
|
+
var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
|
|
220
475
|
return __awaiter(this, void 0, void 0, function () {
|
|
221
|
-
var
|
|
222
|
-
|
|
223
|
-
|
|
476
|
+
var accountFromSigner, pubkey, signMode, msgs, signDoc, _b, signature, signed, signedTxBody, signedTxBodyEncodeObject, signedTxBodyBytes, signedGasLimit, signedSequence, signedAuthInfoBytes;
|
|
477
|
+
var _this = this;
|
|
478
|
+
return __generator(this, function (_c) {
|
|
479
|
+
switch (_c.label) {
|
|
224
480
|
case 0:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
|
|
228
|
-
axios = axios_1.default.create({
|
|
229
|
-
baseURL: SigningStargateClient._endpoint,
|
|
230
|
-
headers: {
|
|
231
|
-
Accept: "application/json",
|
|
232
|
-
},
|
|
233
|
-
timeout: 15000
|
|
234
|
-
});
|
|
235
|
-
path = "/abci_query?path=\"/store/acc/key\"";
|
|
236
|
-
return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
|
|
481
|
+
utils_1.assert(!proto_signing_1.isOfflineDirectSigner(this.signer));
|
|
482
|
+
return [4 /*yield*/, this.signer.getAccounts()];
|
|
237
483
|
case 1:
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
finalAccount = accounts_1.accountFromAny(account);
|
|
242
|
-
return [2 /*return*/, finalAccount];
|
|
243
|
-
case 2:
|
|
244
|
-
error_1 = _a.sent();
|
|
245
|
-
return [2 /*return*/, undefined];
|
|
246
|
-
case 3: return [2 /*return*/];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
SigningStargateClient.getSequence = function (address) {
|
|
252
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var account;
|
|
254
|
-
return __generator(this, function (_a) {
|
|
255
|
-
switch (_a.label) {
|
|
256
|
-
case 0: return [4 /*yield*/, this.getAccount(address)];
|
|
257
|
-
case 1:
|
|
258
|
-
account = _a.sent();
|
|
259
|
-
if (!account) {
|
|
260
|
-
throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
|
|
484
|
+
accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
|
|
485
|
+
if (!accountFromSigner) {
|
|
486
|
+
throw new Error("Failed to retrieve account from signer");
|
|
261
487
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
488
|
+
pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
489
|
+
signMode = signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
|
|
490
|
+
msgs = messages.map(function (msg) { return _this.aminoTypes.toAmino(msg); });
|
|
491
|
+
signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight);
|
|
492
|
+
return [4 /*yield*/, this.signer.signAmino(signerAddress, signDoc)];
|
|
493
|
+
case 2:
|
|
494
|
+
_b = _c.sent(), signature = _b.signature, signed = _b.signed;
|
|
495
|
+
signedTxBody = {
|
|
496
|
+
messages: signed.msgs.map(function (msg) { return _this.aminoTypes.fromAmino(msg); }),
|
|
497
|
+
memo: signed.memo,
|
|
498
|
+
timeoutHeight: timeoutHeight,
|
|
499
|
+
};
|
|
500
|
+
signedTxBodyEncodeObject = {
|
|
501
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
502
|
+
value: signedTxBody,
|
|
503
|
+
};
|
|
504
|
+
signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
|
|
505
|
+
signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
|
|
506
|
+
signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
|
|
507
|
+
signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signed.fee.granter, signed.fee.payer, signMode);
|
|
508
|
+
return [2 /*return*/, tx_3.TxRaw.fromPartial({
|
|
509
|
+
bodyBytes: signedTxBodyBytes,
|
|
510
|
+
authInfoBytes: signedAuthInfoBytes,
|
|
511
|
+
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
512
|
+
})];
|
|
266
513
|
}
|
|
267
514
|
});
|
|
268
515
|
});
|
|
269
516
|
};
|
|
270
|
-
SigningStargateClient.
|
|
271
|
-
return signers.map(function (_a) {
|
|
272
|
-
var pubkey = _a.pubkey, sequence = _a.sequence;
|
|
273
|
-
return ({
|
|
274
|
-
publicKey: pubkey,
|
|
275
|
-
modeInfo: {
|
|
276
|
-
single: { mode: signMode },
|
|
277
|
-
},
|
|
278
|
-
sequence: long_1.default.fromNumber(sequence),
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
};
|
|
282
|
-
SigningStargateClient.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
|
|
283
|
-
if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
|
|
284
|
-
var authInfo = {
|
|
285
|
-
signerInfos: this.makeSignerInfos(signers, signMode),
|
|
286
|
-
fee: {
|
|
287
|
-
amount: __spreadArray([], __read(feeAmount)),
|
|
288
|
-
gasLimit: long_1.default.fromNumber(gasLimit),
|
|
289
|
-
granter: granter,
|
|
290
|
-
},
|
|
291
|
-
};
|
|
292
|
-
return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
|
|
293
|
-
};
|
|
294
|
-
SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
|
|
517
|
+
SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a, timeoutHeight) {
|
|
295
518
|
var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
|
|
296
519
|
return __awaiter(this, void 0, void 0, function () {
|
|
297
520
|
var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
|
|
298
521
|
return __generator(this, function (_c) {
|
|
299
522
|
switch (_c.label) {
|
|
300
|
-
case 0:
|
|
523
|
+
case 0:
|
|
524
|
+
utils_1.assert(proto_signing_1.isOfflineDirectSigner(this.signer));
|
|
525
|
+
return [4 /*yield*/, this.signer.getAccounts()];
|
|
301
526
|
case 1:
|
|
302
527
|
accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
|
|
303
528
|
if (!accountFromSigner) {
|
|
304
529
|
throw new Error("Failed to retrieve account from signer");
|
|
305
530
|
}
|
|
306
|
-
pubkey = proto_signing_1.encodePubkey(
|
|
531
|
+
pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
|
307
532
|
txBodyEncodeObject = {
|
|
308
533
|
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
309
534
|
value: {
|
|
310
535
|
messages: messages,
|
|
311
536
|
memo: memo,
|
|
537
|
+
timeoutHeight: timeoutHeight,
|
|
312
538
|
},
|
|
313
539
|
};
|
|
314
540
|
txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
315
541
|
gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
316
|
-
authInfoBytes =
|
|
542
|
+
authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter, fee.payer);
|
|
317
543
|
signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
318
|
-
return [4 /*yield*/, this.
|
|
544
|
+
return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
|
|
319
545
|
case 2:
|
|
320
546
|
_b = _c.sent(), signature = _b.signature, signed = _b.signed;
|
|
321
|
-
return [2 /*return*/,
|
|
547
|
+
return [2 /*return*/, tx_3.TxRaw.fromPartial({
|
|
322
548
|
bodyBytes: signed.bodyBytes,
|
|
323
549
|
authInfoBytes: signed.authInfoBytes,
|
|
324
550
|
signatures: [encoding_1.fromBase64(signature.signature)],
|
|
@@ -327,31 +553,122 @@ var SigningStargateClient = /** @class */ (function (_super) {
|
|
|
327
553
|
});
|
|
328
554
|
});
|
|
329
555
|
};
|
|
330
|
-
SigningStargateClient.
|
|
556
|
+
SigningStargateClient.experimentalAdr36Verify = function (data, checkMsg) {
|
|
557
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
558
|
+
var newSignature, signed, accountNumber, sequence, chainId, signedMessages, sourceMsg, signatures, signature, signBytes, prehashed, secpSignature, rawSecp256k1Pubkey, rawSignerAddress, ok;
|
|
559
|
+
return __generator(this, function (_a) {
|
|
560
|
+
switch (_a.label) {
|
|
561
|
+
case 0:
|
|
562
|
+
newSignature = amino_1.encodeSecp256k1Signature(FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.pubkey), FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.signature));
|
|
563
|
+
signed = {
|
|
564
|
+
fee: {
|
|
565
|
+
gas: "0",
|
|
566
|
+
amount: [],
|
|
567
|
+
},
|
|
568
|
+
msg: [{
|
|
569
|
+
type: data.type,
|
|
570
|
+
value: { signer: data.signer, data: data.data }
|
|
571
|
+
}],
|
|
572
|
+
signatures: [newSignature],
|
|
573
|
+
memo: ""
|
|
574
|
+
};
|
|
575
|
+
// Restrictions from ADR-036
|
|
576
|
+
if (signed.memo !== "")
|
|
577
|
+
throw new Error("Memo must be empty.");
|
|
578
|
+
if (signed.fee.gas !== "0")
|
|
579
|
+
throw new Error("Fee gas must 0.");
|
|
580
|
+
if (signed.fee.amount.length !== 0)
|
|
581
|
+
throw new Error("Fee amount must be an empty array.");
|
|
582
|
+
accountNumber = 0;
|
|
583
|
+
sequence = 0;
|
|
584
|
+
chainId = "";
|
|
585
|
+
signedMessages = signed.msg;
|
|
586
|
+
if (!signedMessages.every(isMsgSignData)) {
|
|
587
|
+
throw new Error("Found message that is not the expected type.");
|
|
588
|
+
}
|
|
589
|
+
if (signedMessages.length === 0) {
|
|
590
|
+
throw new Error("No message found. Without messages we cannot determine the signer address.");
|
|
591
|
+
}
|
|
592
|
+
sourceMsg = Buffer.from(signedMessages[0].value.data, 'base64').toString();
|
|
593
|
+
if (sourceMsg !== checkMsg) {
|
|
594
|
+
throw new Error("Different Msg error. source:" + sourceMsg + ", target:" + checkMsg);
|
|
595
|
+
}
|
|
596
|
+
signatures = signed.signatures;
|
|
597
|
+
if (signatures.length !== 1)
|
|
598
|
+
throw new Error("Must have exactly one signature to be supported.");
|
|
599
|
+
signature = signatures[0];
|
|
600
|
+
if (!amino_1.isSecp256k1Pubkey(signature.pub_key)) {
|
|
601
|
+
throw new Error("Only secp256k1 signatures are supported.");
|
|
602
|
+
}
|
|
603
|
+
signBytes = amino_1.serializeSignDoc(amino_1.makeSignDoc(signed.msg, signed.fee, chainId, signed.memo, accountNumber, sequence));
|
|
604
|
+
prehashed = crypto_1.sha256(signBytes);
|
|
605
|
+
secpSignature = crypto_1.Secp256k1Signature.fromFixedLength(encoding_1.fromBase64(signature.signature));
|
|
606
|
+
rawSecp256k1Pubkey = encoding_1.fromBase64(signature.pub_key.value);
|
|
607
|
+
rawSignerAddress = amino_1.rawSecp256k1PubkeyToRawAddress(rawSecp256k1Pubkey);
|
|
608
|
+
if (signedMessages.some(function (msg) { return !utils_1.arrayContentEquals(encoding_1.fromBech32(msg.value.signer).data, rawSignerAddress); })) {
|
|
609
|
+
throw new Error("Found mismatch between signer in message and public key");
|
|
610
|
+
}
|
|
611
|
+
return [4 /*yield*/, crypto_1.Secp256k1.verifySignature(secpSignature, prehashed, rawSecp256k1Pubkey)];
|
|
612
|
+
case 1:
|
|
613
|
+
ok = _a.sent();
|
|
614
|
+
return [2 /*return*/, ok];
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
SigningStargateClient.prototype.experimentalAdr36Sign = function (signerAddress, data) {
|
|
331
620
|
return __awaiter(this, void 0, void 0, function () {
|
|
332
|
-
var accountFromSigner, _a, signature, signed,
|
|
621
|
+
var accountNumber, sequence, chainId, fee, memo, datas, msgs, accountFromSigner, signDoc, _a, signature, signed, signatureResult, decodeData, jsonData;
|
|
333
622
|
return __generator(this, function (_b) {
|
|
334
623
|
switch (_b.label) {
|
|
335
|
-
case 0:
|
|
624
|
+
case 0:
|
|
625
|
+
accountNumber = 0;
|
|
626
|
+
sequence = 0;
|
|
627
|
+
chainId = "";
|
|
628
|
+
fee = {
|
|
629
|
+
gas: "0",
|
|
630
|
+
amount: [],
|
|
631
|
+
//granter: "" // added by DH
|
|
632
|
+
};
|
|
633
|
+
memo = "";
|
|
634
|
+
datas = Array.isArray(data) ? data : [data];
|
|
635
|
+
msgs = datas.map(function (d) { return ({
|
|
636
|
+
type: "sign/MsgSignData",
|
|
637
|
+
value: {
|
|
638
|
+
signer: signerAddress,
|
|
639
|
+
data: encoding_1.toBase64(d),
|
|
640
|
+
},
|
|
641
|
+
}); });
|
|
642
|
+
return [4 /*yield*/, this.signer.getAccounts()];
|
|
336
643
|
case 1:
|
|
337
644
|
accountFromSigner = (_b.sent()).find(function (account) { return account.address === signerAddress; });
|
|
338
645
|
if (!accountFromSigner) {
|
|
339
646
|
throw new Error("Failed to retrieve account from signer");
|
|
340
647
|
}
|
|
341
|
-
|
|
648
|
+
if (!("signAmino" in this.signer)) {
|
|
649
|
+
throw new Error("The signer does not support signAmino. Please use an OfflineAminoSigner instance.");
|
|
650
|
+
}
|
|
651
|
+
signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence);
|
|
652
|
+
return [4 /*yield*/, this.signer.signAmino(signerAddress, signDoc)];
|
|
342
653
|
case 2:
|
|
343
654
|
_a = _b.sent(), signature = _a.signature, signed = _a.signed;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
655
|
+
if (!fast_deep_equal_1.default(signDoc, signed)) {
|
|
656
|
+
throw new Error("The signed document differs from the signing instruction. This is not supported for ADR-036.");
|
|
657
|
+
}
|
|
658
|
+
signatureResult = amino_1.makeStdTx(signDoc, signature);
|
|
659
|
+
decodeData = amino_1.decodeSignature(signatureResult.signatures[0]);
|
|
660
|
+
jsonData = {
|
|
661
|
+
type: "sign/MsgSignData",
|
|
662
|
+
signer: signatureResult.msg[0].value.signer,
|
|
663
|
+
data: signatureResult.msg[0].value.data,
|
|
664
|
+
pubkey: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.pubkey),
|
|
665
|
+
signature: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.signature)
|
|
666
|
+
};
|
|
667
|
+
return [2 /*return*/, jsonData];
|
|
350
668
|
}
|
|
351
669
|
});
|
|
352
670
|
});
|
|
353
671
|
};
|
|
354
|
-
SigningStargateClient._endpoint = "";
|
|
355
672
|
return SigningStargateClient;
|
|
356
673
|
}(stargateclient_1.StargateClient));
|
|
357
674
|
exports.SigningStargateClient = SigningStargateClient;
|