@firmachain/firma-js 0.2.37 → 0.2.38
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.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/sdk/FirmaAuthzService.d.ts +41 -0
- package/dist/sdk/FirmaAuthzService.js +633 -0
- package/dist/sdk/FirmaBankService.d.ts +17 -0
- package/dist/sdk/FirmaBankService.js +236 -0
- package/dist/sdk/FirmaChainService.d.ts +8 -0
- package/dist/sdk/FirmaChainService.js +86 -0
- package/dist/sdk/FirmaConfig.d.ts +18 -0
- package/dist/sdk/FirmaConfig.js +63 -0
- package/dist/sdk/FirmaContractService.d.ts +32 -0
- package/dist/sdk/FirmaContractService.js +434 -0
- package/dist/sdk/FirmaCosmWasmService.d.ts +38 -0
- package/dist/sdk/FirmaCosmWasmService.js +667 -0
- package/dist/sdk/FirmaDistributionService.d.ts +32 -0
- package/dist/sdk/FirmaDistributionService.js +527 -0
- package/dist/sdk/FirmaFeeGrantService.d.ts +21 -0
- package/dist/sdk/FirmaFeeGrantService.js +341 -0
- package/dist/sdk/FirmaGovService.d.ts +35 -0
- package/dist/sdk/FirmaGovService.js +775 -0
- package/dist/sdk/FirmaIbcService.d.ts +15 -0
- package/dist/sdk/FirmaIbcService.js +144 -0
- package/dist/sdk/FirmaIpfsService.d.ts +12 -0
- package/dist/sdk/FirmaIpfsService.js +185 -0
- package/dist/sdk/FirmaMobileSDK.d.ts +29 -0
- package/dist/sdk/FirmaMobileSDK.js +48 -0
- package/dist/sdk/FirmaNftService.d.ts +31 -0
- package/dist/sdk/FirmaNftService.js +372 -0
- package/dist/sdk/FirmaSDK.d.ts +35 -0
- package/dist/sdk/FirmaSDK.js +57 -0
- package/dist/sdk/FirmaSlashingService.d.ts +9 -0
- package/dist/sdk/FirmaSlashingService.js +105 -0
- package/dist/sdk/FirmaStakingService.d.ts +47 -0
- package/dist/sdk/FirmaStakingService.js +611 -0
- package/dist/sdk/FirmaTokenService.d.ts +26 -0
- package/dist/sdk/FirmaTokenService.js +416 -0
- package/dist/sdk/FirmaUtil.d.ts +56 -0
- package/dist/sdk/FirmaUtil.js +430 -0
- package/dist/sdk/FirmaWalletService.d.ts +39 -0
- package/dist/sdk/FirmaWalletService.js +317 -0
- package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
- package/dist/sdk/firmachain/amino/addresses.js +46 -0
- package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
- package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
- package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
- package/dist/sdk/firmachain/amino/aminotypes.js +525 -0
- package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
- package/dist/sdk/firmachain/amino/coins.js +69 -0
- package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
- package/dist/sdk/firmachain/amino/encoding.js +238 -0
- package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
- package/dist/sdk/firmachain/amino/multisig.js +42 -0
- package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
- package/dist/sdk/firmachain/amino/paths.js +18 -0
- package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
- package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
- package/dist/sdk/firmachain/amino/signature.d.ts +16 -0
- package/dist/sdk/firmachain/amino/signature.js +36 -0
- package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -0
- package/dist/sdk/firmachain/amino/signdoc.js +42 -0
- package/dist/sdk/firmachain/amino/signer.d.ts +32 -0
- package/dist/sdk/firmachain/amino/signer.js +2 -0
- package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -0
- package/dist/sdk/firmachain/amino/stdtx.js +17 -0
- package/dist/sdk/firmachain/amino/wallet.d.ts +32 -0
- package/dist/sdk/firmachain/amino/wallet.js +136 -0
- package/dist/sdk/firmachain/authz/AuthzQueryClient.d.ts +48 -0
- package/dist/sdk/firmachain/authz/AuthzQueryClient.js +142 -0
- package/dist/sdk/firmachain/authz/AuthzTxClient.d.ts +23 -0
- package/dist/sdk/firmachain/authz/AuthzTxClient.js +47 -0
- package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +147 -0
- package/dist/sdk/firmachain/authz/AuthzTxTypes.js +358 -0
- package/dist/sdk/firmachain/authz/index.d.ts +3 -0
- package/dist/sdk/firmachain/authz/index.js +19 -0
- package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -0
- package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -0
- package/dist/sdk/firmachain/bank/BankTxClient.d.ts +18 -0
- package/dist/sdk/firmachain/bank/BankTxClient.js +43 -0
- package/dist/sdk/firmachain/bank/index.d.ts +3 -0
- package/dist/sdk/firmachain/bank/index.js +19 -0
- package/dist/sdk/firmachain/common/CommonTxClient.d.ts +7 -0
- package/dist/sdk/firmachain/common/CommonTxClient.js +79 -0
- package/dist/sdk/firmachain/common/ITxClient.d.ts +18 -0
- package/dist/sdk/firmachain/common/ITxClient.js +117 -0
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
- package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -0
- package/dist/sdk/firmachain/common/LedgerWallet.js +151 -0
- package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -0
- package/dist/sdk/firmachain/common/QueryCommon.js +2 -0
- package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -0
- package/dist/sdk/firmachain/common/TendermintQueryClient.js +111 -0
- package/dist/sdk/firmachain/common/TxCommon.d.ts +87 -0
- package/dist/sdk/firmachain/common/TxCommon.js +18 -0
- package/dist/sdk/firmachain/common/accounts.d.ts +16 -0
- package/dist/sdk/firmachain/common/accounts.js +64 -0
- package/dist/sdk/firmachain/common/index.d.ts +2 -0
- package/dist/sdk/firmachain/common/index.js +18 -0
- package/dist/sdk/firmachain/common/signing.d.ts +10 -0
- package/dist/sdk/firmachain/common/signing.js +79 -0
- package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +50 -0
- package/dist/sdk/firmachain/common/signingaminostargateclient.js +267 -0
- package/dist/sdk/firmachain/common/signingstargateclient.d.ts +44 -0
- package/dist/sdk/firmachain/common/signingstargateclient.js +361 -0
- package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -0
- package/dist/sdk/firmachain/common/stargateclient.js +211 -0
- package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -0
- package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -0
- package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +18 -0
- package/dist/sdk/firmachain/contract/ContractTxClient.js +43 -0
- package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -0
- package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -0
- package/dist/sdk/firmachain/contract/index.d.ts +3 -0
- package/dist/sdk/firmachain/contract/index.js +19 -0
- package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.d.ts +52 -0
- package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +193 -0
- package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.d.ts +38 -0
- package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.js +59 -0
- package/dist/sdk/firmachain/cosmwasm/index.d.ts +3 -0
- package/dist/sdk/firmachain/cosmwasm/index.js +19 -0
- package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -0
- package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -0
- package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +28 -0
- package/dist/sdk/firmachain/distribution/DistributionTxClient.js +51 -0
- package/dist/sdk/firmachain/distribution/index.d.ts +3 -0
- package/dist/sdk/firmachain/distribution/index.js +19 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +18 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +43 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -0
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -0
- package/dist/sdk/firmachain/feegrant/index.d.ts +2 -0
- package/dist/sdk/firmachain/feegrant/index.js +19 -0
- package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -0
- package/dist/sdk/firmachain/google/protobuf/any.js +106 -0
- package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -0
- package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -0
- package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -0
- package/dist/sdk/firmachain/google/protobuf/duration.js +107 -0
- package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -0
- package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -0
- package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -0
- package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -0
- package/dist/sdk/firmachain/gov/GovTxClient.d.ts +23 -0
- package/dist/sdk/firmachain/gov/GovTxClient.js +47 -0
- package/dist/sdk/firmachain/gov/index.d.ts +3 -0
- package/dist/sdk/firmachain/gov/index.js +19 -0
- package/dist/sdk/firmachain/ibc/IbcQueryClient.d.ts +34 -0
- package/dist/sdk/firmachain/ibc/IbcQueryClient.js +71 -0
- package/dist/sdk/firmachain/ibc/IbcTxClient.d.ts +13 -0
- package/dist/sdk/firmachain/ibc/IbcTxClient.js +39 -0
- package/dist/sdk/firmachain/ibc/index.d.ts +3 -0
- package/dist/sdk/firmachain/ibc/index.js +19 -0
- package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -0
- package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -0
- package/dist/sdk/firmachain/nft/NftTxClient.d.ts +23 -0
- package/dist/sdk/firmachain/nft/NftTxClient.js +47 -0
- package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -0
- package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -0
- package/dist/sdk/firmachain/nft/index.d.ts +3 -0
- package/dist/sdk/firmachain/nft/index.js +19 -0
- package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -0
- package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -0
- package/dist/sdk/firmachain/slashing/index.d.ts +2 -0
- package/dist/sdk/firmachain/slashing/index.js +18 -0
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +106 -0
- package/dist/sdk/firmachain/staking/StakingQueryClient.js +243 -0
- package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +33 -0
- package/dist/sdk/firmachain/staking/StakingTxClient.js +55 -0
- package/dist/sdk/firmachain/staking/index.d.ts +3 -0
- package/dist/sdk/firmachain/staking/index.js +19 -0
- package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -0
- package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -0
- package/dist/sdk/firmachain/token/TokenTxClient.d.ts +28 -0
- package/dist/sdk/firmachain/token/TokenTxClient.js +51 -0
- package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -0
- package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -0
- package/dist/sdk/firmachain/token/index.d.ts +3 -0
- package/dist/sdk/firmachain/token/index.js +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.SigningAminoStargateClient = exports.isMsgSignData = void 0;
|
|
58
|
+
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
59
|
+
//import { StdFee } from ".";
|
|
60
|
+
var accounts_1 = require("./accounts");
|
|
61
|
+
var stargateclient_1 = require("./stargateclient");
|
|
62
|
+
var axios_1 = __importDefault(require("axios"));
|
|
63
|
+
var any_1 = require("../google/protobuf/any");
|
|
64
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
65
|
+
var amino_1 = require("@cosmjs/amino");
|
|
66
|
+
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
67
|
+
var utils_1 = require("@cosmjs/utils");
|
|
68
|
+
var tx_1 = require("@cosmjs/launchpad/build/tx");
|
|
69
|
+
var amino_2 = require("@cosmjs/amino");
|
|
70
|
+
var crypto_1 = require("@cosmjs/crypto");
|
|
71
|
+
var crypto_2 = require("@cosmjs/crypto");
|
|
72
|
+
var utils_2 = require("@cosmjs/utils");
|
|
73
|
+
var encoding_2 = require("@cosmjs/encoding");
|
|
74
|
+
var amino_3 = require("@cosmjs/amino");
|
|
75
|
+
var FirmaUtil_1 = require("../../FirmaUtil");
|
|
76
|
+
function isMsgSignData(msg) {
|
|
77
|
+
var castedMsg = msg;
|
|
78
|
+
if (castedMsg.type !== "sign/MsgSignData")
|
|
79
|
+
return false;
|
|
80
|
+
if (!(0, utils_1.isNonNullObject)(castedMsg.value))
|
|
81
|
+
return false;
|
|
82
|
+
if (typeof castedMsg.value.signer !== "string")
|
|
83
|
+
return false;
|
|
84
|
+
if (typeof castedMsg.value.data !== "string")
|
|
85
|
+
return false;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
exports.isMsgSignData = isMsgSignData;
|
|
89
|
+
var SigningAminoStargateClient = /** @class */ (function (_super) {
|
|
90
|
+
__extends(SigningAminoStargateClient, _super);
|
|
91
|
+
function SigningAminoStargateClient(tmClient, signer) {
|
|
92
|
+
var _this = _super.call(this, tmClient) || this;
|
|
93
|
+
_this.signer = signer;
|
|
94
|
+
return _this;
|
|
95
|
+
}
|
|
96
|
+
SigningAminoStargateClient.connectWithSigner = function (endpoint, signer, registry) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var tmClient;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
this._endpoint = endpoint;
|
|
103
|
+
return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
|
|
104
|
+
case 1:
|
|
105
|
+
tmClient = _a.sent();
|
|
106
|
+
return [2 /*return*/, new SigningAminoStargateClient(tmClient, signer)];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
SigningAminoStargateClient.prototype.experimentalAdr36Sign = function (signerAddress, data) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var accountNumber, sequence, chainId, fee, memo, datas, msgs, accountFromSigner, signDoc, _a, signature, signed, signatureResult, decodeData, jsonData;
|
|
114
|
+
return __generator(this, function (_b) {
|
|
115
|
+
switch (_b.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
accountNumber = 0;
|
|
118
|
+
sequence = 0;
|
|
119
|
+
chainId = "";
|
|
120
|
+
fee = {
|
|
121
|
+
gas: "0",
|
|
122
|
+
amount: [],
|
|
123
|
+
//granter: "" // added by DH
|
|
124
|
+
};
|
|
125
|
+
memo = "";
|
|
126
|
+
datas = Array.isArray(data) ? data : [data];
|
|
127
|
+
msgs = datas.map(function (d) { return ({
|
|
128
|
+
type: "sign/MsgSignData",
|
|
129
|
+
value: {
|
|
130
|
+
signer: signerAddress,
|
|
131
|
+
data: (0, encoding_1.toBase64)(d),
|
|
132
|
+
},
|
|
133
|
+
}); });
|
|
134
|
+
return [4 /*yield*/, this.signer.getAccounts()];
|
|
135
|
+
case 1:
|
|
136
|
+
accountFromSigner = (_b.sent()).find(function (account) { return account.address === signerAddress; });
|
|
137
|
+
if (!accountFromSigner) {
|
|
138
|
+
throw new Error("Failed to retrieve account from signer");
|
|
139
|
+
}
|
|
140
|
+
signDoc = (0, amino_1.makeSignDoc)(msgs, fee, chainId, memo, accountNumber, sequence);
|
|
141
|
+
return [4 /*yield*/, this.signer.signAmino(signerAddress, signDoc)];
|
|
142
|
+
case 2:
|
|
143
|
+
_a = _b.sent(), signature = _a.signature, signed = _a.signed;
|
|
144
|
+
if (!(0, fast_deep_equal_1.default)(signDoc, signed)) {
|
|
145
|
+
throw new Error("The signed document differs from the signing instruction. This is not supported for ADR-036.");
|
|
146
|
+
}
|
|
147
|
+
signatureResult = (0, tx_1.makeStdTx)(signDoc, signature);
|
|
148
|
+
decodeData = (0, amino_1.decodeSignature)(signatureResult.signatures[0]);
|
|
149
|
+
jsonData = {
|
|
150
|
+
type: "sign/MsgSignData",
|
|
151
|
+
signer: signatureResult.msg[0].value.signer,
|
|
152
|
+
data: signatureResult.msg[0].value.data,
|
|
153
|
+
pubkey: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.pubkey),
|
|
154
|
+
signature: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.signature)
|
|
155
|
+
};
|
|
156
|
+
return [2 /*return*/, jsonData];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
SigningAminoStargateClient.experimentalAdr36Verify = function (data, checkMsg) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
+
var newSignature, signed, accountNumber, sequence, chainId, signedMessages, sourceMsg, signatures, signature, signBytes, prehashed, secpSignature, rawSecp256k1Pubkey, rawSignerAddress, ok;
|
|
164
|
+
return __generator(this, function (_a) {
|
|
165
|
+
switch (_a.label) {
|
|
166
|
+
case 0:
|
|
167
|
+
newSignature = (0, amino_1.encodeSecp256k1Signature)(FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.pubkey), FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.signature));
|
|
168
|
+
signed = {
|
|
169
|
+
fee: {
|
|
170
|
+
gas: "0",
|
|
171
|
+
amount: [],
|
|
172
|
+
},
|
|
173
|
+
msg: [{
|
|
174
|
+
type: data.type,
|
|
175
|
+
value: { signer: data.signer, data: data.data }
|
|
176
|
+
}],
|
|
177
|
+
signatures: [newSignature],
|
|
178
|
+
memo: ""
|
|
179
|
+
};
|
|
180
|
+
// Restrictions from ADR-036
|
|
181
|
+
if (signed.memo !== "")
|
|
182
|
+
throw new Error("Memo must be empty.");
|
|
183
|
+
if (signed.fee.gas !== "0")
|
|
184
|
+
throw new Error("Fee gas must 0.");
|
|
185
|
+
if (signed.fee.amount.length !== 0)
|
|
186
|
+
throw new Error("Fee amount must be an empty array.");
|
|
187
|
+
accountNumber = 0;
|
|
188
|
+
sequence = 0;
|
|
189
|
+
chainId = "";
|
|
190
|
+
signedMessages = signed.msg;
|
|
191
|
+
if (!signedMessages.every(isMsgSignData)) {
|
|
192
|
+
throw new Error("Found message that is not the expected type.");
|
|
193
|
+
}
|
|
194
|
+
if (signedMessages.length === 0) {
|
|
195
|
+
throw new Error("No message found. Without messages we cannot determine the signer address.");
|
|
196
|
+
}
|
|
197
|
+
sourceMsg = Buffer.from(signedMessages[0].value.data, 'base64').toString();
|
|
198
|
+
if (sourceMsg !== checkMsg) {
|
|
199
|
+
throw new Error("Different Msg error. source:" + sourceMsg + ", target:" + checkMsg);
|
|
200
|
+
}
|
|
201
|
+
signatures = signed.signatures;
|
|
202
|
+
if (signatures.length !== 1)
|
|
203
|
+
throw new Error("Must have exactly one signature to be supported.");
|
|
204
|
+
signature = signatures[0];
|
|
205
|
+
if (!(0, amino_2.isSecp256k1Pubkey)(signature.pub_key)) {
|
|
206
|
+
throw new Error("Only secp256k1 signatures are supported.");
|
|
207
|
+
}
|
|
208
|
+
signBytes = (0, amino_2.serializeSignDoc)((0, amino_1.makeSignDoc)(signed.msg, signed.fee, chainId, signed.memo, accountNumber, sequence));
|
|
209
|
+
prehashed = (0, crypto_1.sha256)(signBytes);
|
|
210
|
+
secpSignature = crypto_2.Secp256k1Signature.fromFixedLength((0, encoding_2.fromBase64)(signature.signature));
|
|
211
|
+
rawSecp256k1Pubkey = (0, encoding_2.fromBase64)(signature.pub_key.value);
|
|
212
|
+
rawSignerAddress = (0, amino_3.rawSecp256k1PubkeyToRawAddress)(rawSecp256k1Pubkey);
|
|
213
|
+
if (signedMessages.some(function (msg) { return !(0, utils_2.arrayContentEquals)(encoding_1.Bech32.decode(msg.value.signer).data, rawSignerAddress); })) {
|
|
214
|
+
throw new Error("Found mismatch between signer in message and public key");
|
|
215
|
+
}
|
|
216
|
+
return [4 /*yield*/, crypto_2.Secp256k1.verifySignature(secpSignature, prehashed, rawSecp256k1Pubkey)];
|
|
217
|
+
case 1:
|
|
218
|
+
ok = _a.sent();
|
|
219
|
+
return [2 /*return*/, ok];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
|
|
226
|
+
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
227
|
+
* The result is typically 20 bytes long but not restricted to that.
|
|
228
|
+
*/
|
|
229
|
+
SigningAminoStargateClient.prototype.toAccAddress = function (address) {
|
|
230
|
+
return encoding_1.Bech32.decode(address).data;
|
|
231
|
+
};
|
|
232
|
+
SigningAminoStargateClient.prototype.getAccount = function (address) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
_a.trys.push([0, 2, , 3]);
|
|
239
|
+
accAddress = this.toAccAddress(address);
|
|
240
|
+
hexAccAddress = "0x01".concat(Buffer.from(accAddress).toString("hex"));
|
|
241
|
+
axios = axios_1.default.create({
|
|
242
|
+
baseURL: SigningAminoStargateClient._endpoint,
|
|
243
|
+
headers: {
|
|
244
|
+
Accept: "application/json",
|
|
245
|
+
},
|
|
246
|
+
timeout: 15000
|
|
247
|
+
});
|
|
248
|
+
path = "/abci_query?path=\"/store/acc/key\"";
|
|
249
|
+
return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
|
|
250
|
+
case 1:
|
|
251
|
+
result = _a.sent();
|
|
252
|
+
finalData = result.data.result.response.value;
|
|
253
|
+
account = any_1.Any.decode(Buffer.from(finalData, "base64"));
|
|
254
|
+
finalAccount = (0, accounts_1.accountFromAny)(account);
|
|
255
|
+
return [2 /*return*/, finalAccount];
|
|
256
|
+
case 2:
|
|
257
|
+
error_1 = _a.sent();
|
|
258
|
+
return [2 /*return*/, undefined];
|
|
259
|
+
case 3: return [2 /*return*/];
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
SigningAminoStargateClient._endpoint = "";
|
|
265
|
+
return SigningAminoStargateClient;
|
|
266
|
+
}(stargateclient_1.StargateClient));
|
|
267
|
+
exports.SigningAminoStargateClient = SigningAminoStargateClient;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EncodeObject, OfflineDirectSigner, Registry } from "@cosmjs/proto-signing";
|
|
2
|
+
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
|
|
3
|
+
import { SignDoc, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
4
|
+
import { StdFee } from ".";
|
|
5
|
+
import { Account } from "./accounts";
|
|
6
|
+
import { BroadcastTxResponse, StargateClient } from "./stargateclient";
|
|
7
|
+
export interface SignerData {
|
|
8
|
+
readonly accountNumber: number;
|
|
9
|
+
readonly sequence: number;
|
|
10
|
+
readonly chainId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SequenceResponse {
|
|
13
|
+
readonly accountNumber: number;
|
|
14
|
+
readonly sequence: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TxRawExt {
|
|
17
|
+
readonly txRaw: TxRaw;
|
|
18
|
+
readonly signature: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SigningStargateClient extends StargateClient {
|
|
21
|
+
private readonly signer;
|
|
22
|
+
private readonly registry;
|
|
23
|
+
private chainId;
|
|
24
|
+
private static _endpoint;
|
|
25
|
+
private getSigner;
|
|
26
|
+
static connectWithSigner(endpoint: string, signer: OfflineDirectSigner | undefined, registry: Registry): Promise<SigningStargateClient>;
|
|
27
|
+
protected constructor(tmClient: Tendermint34Client | undefined, signer: OfflineDirectSigner | undefined, registry: Registry);
|
|
28
|
+
signAndBroadcast(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo?: string): Promise<BroadcastTxResponse>;
|
|
29
|
+
static makeSignDocForSend(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, serverUrl: string, chainId: string, registry: Registry): Promise<SignDoc>;
|
|
30
|
+
sign(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, explicitSignerData?: SignerData): Promise<TxRaw>;
|
|
31
|
+
getChainId(): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
|
|
34
|
+
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
35
|
+
* The result is typically 20 bytes long but not restricted to that.
|
|
36
|
+
*/
|
|
37
|
+
private static toAccAddress;
|
|
38
|
+
static getAccount(address: string): Promise<Account | undefined>;
|
|
39
|
+
static getSequence(address: string): Promise<SequenceResponse>;
|
|
40
|
+
private static makeSignerInfos;
|
|
41
|
+
private static makeAuthInfoBytes;
|
|
42
|
+
private signDirect;
|
|
43
|
+
signDirectForSignDoc(signerAddress: string, signDoc: SignDoc): Promise<TxRawExt>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
+
if (!m) return o;
|
|
56
|
+
var i = m.call(o), r, ar = [], e;
|
|
57
|
+
try {
|
|
58
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
+
}
|
|
60
|
+
catch (error) { e = { error: error }; }
|
|
61
|
+
finally {
|
|
62
|
+
try {
|
|
63
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
+
}
|
|
65
|
+
finally { if (e) throw e.error; }
|
|
66
|
+
}
|
|
67
|
+
return ar;
|
|
68
|
+
};
|
|
69
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
70
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
71
|
+
if (ar || !(i in from)) {
|
|
72
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
73
|
+
ar[i] = from[i];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
77
|
+
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
81
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
|
+
exports.SigningStargateClient = void 0;
|
|
83
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
84
|
+
var encoding_2 = require("@cosmjs/encoding");
|
|
85
|
+
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
86
|
+
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
87
|
+
var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
|
|
88
|
+
var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
89
|
+
var accounts_1 = require("./accounts");
|
|
90
|
+
var stargateclient_1 = require("./stargateclient");
|
|
91
|
+
var axios_1 = __importDefault(require("axios"));
|
|
92
|
+
var math_1 = require("@cosmjs/math");
|
|
93
|
+
var any_1 = require("../google/protobuf/any");
|
|
94
|
+
var long_1 = __importDefault(require("long"));
|
|
95
|
+
var encoding_3 = require("../amino/encoding");
|
|
96
|
+
var SigningStargateClient = /** @class */ (function (_super) {
|
|
97
|
+
__extends(SigningStargateClient, _super);
|
|
98
|
+
function SigningStargateClient(tmClient, signer, registry) {
|
|
99
|
+
var _this = _super.call(this, tmClient) || this;
|
|
100
|
+
_this.registry = registry;
|
|
101
|
+
_this.signer = signer;
|
|
102
|
+
return _this;
|
|
103
|
+
}
|
|
104
|
+
SigningStargateClient.prototype.getSigner = function () {
|
|
105
|
+
return this.signer;
|
|
106
|
+
};
|
|
107
|
+
SigningStargateClient.connectWithSigner = function (endpoint, signer, registry) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var tmClient;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
this._endpoint = endpoint;
|
|
114
|
+
return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
|
|
115
|
+
case 1:
|
|
116
|
+
tmClient = _a.sent();
|
|
117
|
+
return [2 /*return*/, new SigningStargateClient(tmClient, signer, registry)];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
|
|
123
|
+
if (memo === void 0) { memo = ""; }
|
|
124
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
+
var txRaw, txBytes;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
|
|
129
|
+
case 1:
|
|
130
|
+
txRaw = _a.sent();
|
|
131
|
+
txBytes = tx_1.TxRaw.encode(txRaw).finish();
|
|
132
|
+
return [2 /*return*/, this.broadcastTx(txBytes)];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
SigningStargateClient.makeSignDocForSend = function (signerAddress, messages, fee, memo, serverUrl, chainId, registry) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
var _a, accountNumber, sequence, account, rawSecp256k1Pubkey, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes;
|
|
140
|
+
return __generator(this, function (_b) {
|
|
141
|
+
switch (_b.label) {
|
|
142
|
+
case 0:
|
|
143
|
+
SigningStargateClient._endpoint = serverUrl;
|
|
144
|
+
return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
|
|
145
|
+
case 1:
|
|
146
|
+
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
147
|
+
return [4 /*yield*/, SigningStargateClient.getAccount(signerAddress)];
|
|
148
|
+
case 2:
|
|
149
|
+
account = _b.sent();
|
|
150
|
+
if (account == null)
|
|
151
|
+
throw new Error("Failed to retrieve account from signer");
|
|
152
|
+
rawSecp256k1Pubkey = (0, encoding_1.fromBase64)(account.pubkey.value);
|
|
153
|
+
pubkey = (0, proto_signing_1.encodePubkey)((0, encoding_3.encodeSecp256k1Pubkey)(rawSecp256k1Pubkey));
|
|
154
|
+
txBodyEncodeObject = {
|
|
155
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
156
|
+
value: {
|
|
157
|
+
messages: messages,
|
|
158
|
+
memo: memo,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
txBodyBytes = registry.encode(txBodyEncodeObject);
|
|
162
|
+
gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
163
|
+
authInfoBytes = this.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
|
|
164
|
+
return [2 /*return*/, (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, accountNumber)];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
var signerData, _a, accountNumber, sequence, chainId;
|
|
172
|
+
return __generator(this, function (_b) {
|
|
173
|
+
switch (_b.label) {
|
|
174
|
+
case 0:
|
|
175
|
+
if (!explicitSignerData) return [3 /*break*/, 1];
|
|
176
|
+
signerData = explicitSignerData;
|
|
177
|
+
return [3 /*break*/, 4];
|
|
178
|
+
case 1: return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
|
|
179
|
+
case 2:
|
|
180
|
+
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
181
|
+
return [4 /*yield*/, this.getChainId()];
|
|
182
|
+
case 3:
|
|
183
|
+
chainId = _b.sent();
|
|
184
|
+
signerData = {
|
|
185
|
+
accountNumber: accountNumber,
|
|
186
|
+
sequence: sequence,
|
|
187
|
+
chainId: chainId,
|
|
188
|
+
};
|
|
189
|
+
_b.label = 4;
|
|
190
|
+
case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
SigningStargateClient.prototype.getChainId = function () {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
197
|
+
var response, chainId;
|
|
198
|
+
return __generator(this, function (_a) {
|
|
199
|
+
switch (_a.label) {
|
|
200
|
+
case 0:
|
|
201
|
+
if (!!this.chainId) return [3 /*break*/, 2];
|
|
202
|
+
return [4 /*yield*/, this.forceGetTmClient().status()];
|
|
203
|
+
case 1:
|
|
204
|
+
response = _a.sent();
|
|
205
|
+
chainId = response.nodeInfo.network;
|
|
206
|
+
if (!chainId)
|
|
207
|
+
throw new Error("Chain ID must not be empty");
|
|
208
|
+
this.chainId = chainId;
|
|
209
|
+
_a.label = 2;
|
|
210
|
+
case 2: return [2 /*return*/, this.chainId];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
|
|
217
|
+
* This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
|
|
218
|
+
* The result is typically 20 bytes long but not restricted to that.
|
|
219
|
+
*/
|
|
220
|
+
SigningStargateClient.toAccAddress = function (address) {
|
|
221
|
+
return encoding_2.Bech32.decode(address).data;
|
|
222
|
+
};
|
|
223
|
+
SigningStargateClient.getAccount = function (address) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
+
var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
|
|
226
|
+
return __generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
_a.trys.push([0, 2, , 3]);
|
|
230
|
+
accAddress = this.toAccAddress(address);
|
|
231
|
+
hexAccAddress = "0x01".concat(Buffer.from(accAddress).toString("hex"));
|
|
232
|
+
axios = axios_1.default.create({
|
|
233
|
+
baseURL: SigningStargateClient._endpoint,
|
|
234
|
+
headers: {
|
|
235
|
+
Accept: "application/json",
|
|
236
|
+
},
|
|
237
|
+
timeout: 15000
|
|
238
|
+
});
|
|
239
|
+
path = "/abci_query?path=\"/store/acc/key\"";
|
|
240
|
+
return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
|
|
241
|
+
case 1:
|
|
242
|
+
result = _a.sent();
|
|
243
|
+
finalData = result.data.result.response.value;
|
|
244
|
+
account = any_1.Any.decode(Buffer.from(finalData, "base64"));
|
|
245
|
+
finalAccount = (0, accounts_1.accountFromAny)(account);
|
|
246
|
+
return [2 /*return*/, finalAccount];
|
|
247
|
+
case 2:
|
|
248
|
+
error_1 = _a.sent();
|
|
249
|
+
return [2 /*return*/, undefined];
|
|
250
|
+
case 3: return [2 /*return*/];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
SigningStargateClient.getSequence = function (address) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
+
var account;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0: return [4 /*yield*/, this.getAccount(address)];
|
|
261
|
+
case 1:
|
|
262
|
+
account = _a.sent();
|
|
263
|
+
if (!account) {
|
|
264
|
+
throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
|
|
265
|
+
}
|
|
266
|
+
return [2 /*return*/, {
|
|
267
|
+
accountNumber: account.accountNumber,
|
|
268
|
+
sequence: account.sequence,
|
|
269
|
+
}];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
SigningStargateClient.makeSignerInfos = function (signers, signMode) {
|
|
275
|
+
return signers.map(function (_a) {
|
|
276
|
+
var pubkey = _a.pubkey, sequence = _a.sequence;
|
|
277
|
+
return ({
|
|
278
|
+
publicKey: pubkey,
|
|
279
|
+
modeInfo: {
|
|
280
|
+
single: { mode: signMode },
|
|
281
|
+
},
|
|
282
|
+
sequence: long_1.default.fromNumber(sequence),
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
SigningStargateClient.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
|
|
287
|
+
if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
|
|
288
|
+
var authInfo = {
|
|
289
|
+
signerInfos: this.makeSignerInfos(signers, signMode),
|
|
290
|
+
fee: {
|
|
291
|
+
amount: __spreadArray([], __read(feeAmount), false),
|
|
292
|
+
gasLimit: long_1.default.fromNumber(gasLimit),
|
|
293
|
+
granter: granter,
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
|
|
297
|
+
};
|
|
298
|
+
SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
|
|
299
|
+
var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
|
|
302
|
+
return __generator(this, function (_c) {
|
|
303
|
+
switch (_c.label) {
|
|
304
|
+
case 0: return [4 /*yield*/, this.getSigner().getAccounts()];
|
|
305
|
+
case 1:
|
|
306
|
+
accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
|
|
307
|
+
if (!accountFromSigner) {
|
|
308
|
+
throw new Error("Failed to retrieve account from signer");
|
|
309
|
+
}
|
|
310
|
+
pubkey = (0, proto_signing_1.encodePubkey)((0, encoding_3.encodeSecp256k1Pubkey)(accountFromSigner.pubkey));
|
|
311
|
+
txBodyEncodeObject = {
|
|
312
|
+
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
|
313
|
+
value: {
|
|
314
|
+
messages: messages,
|
|
315
|
+
memo: memo,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
319
|
+
gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
|
|
320
|
+
authInfoBytes = SigningStargateClient.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
|
|
321
|
+
signDoc = (0, proto_signing_1.makeSignDoc)(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
|
322
|
+
return [4 /*yield*/, this.getSigner().signDirect(signerAddress, signDoc)];
|
|
323
|
+
case 2:
|
|
324
|
+
_b = _c.sent(), signature = _b.signature, signed = _b.signed;
|
|
325
|
+
return [2 /*return*/, tx_1.TxRaw.fromPartial({
|
|
326
|
+
bodyBytes: signed.bodyBytes,
|
|
327
|
+
authInfoBytes: signed.authInfoBytes,
|
|
328
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
329
|
+
})];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
SigningStargateClient.prototype.signDirectForSignDoc = function (signerAddress, signDoc) {
|
|
335
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
336
|
+
var accountFromSigner, _a, signature, signed, txRaw;
|
|
337
|
+
return __generator(this, function (_b) {
|
|
338
|
+
switch (_b.label) {
|
|
339
|
+
case 0: return [4 /*yield*/, this.getSigner().getAccounts()];
|
|
340
|
+
case 1:
|
|
341
|
+
accountFromSigner = (_b.sent()).find(function (account) { return account.address === signerAddress; });
|
|
342
|
+
if (!accountFromSigner) {
|
|
343
|
+
throw new Error("Failed to retrieve account from signer");
|
|
344
|
+
}
|
|
345
|
+
return [4 /*yield*/, this.getSigner().signDirect(signerAddress, signDoc)];
|
|
346
|
+
case 2:
|
|
347
|
+
_a = _b.sent(), signature = _a.signature, signed = _a.signed;
|
|
348
|
+
txRaw = tx_1.TxRaw.fromPartial({
|
|
349
|
+
bodyBytes: signed.bodyBytes,
|
|
350
|
+
authInfoBytes: signed.authInfoBytes,
|
|
351
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
352
|
+
});
|
|
353
|
+
return [2 /*return*/, { txRaw: txRaw, signature: signature.signature }];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
SigningStargateClient._endpoint = "";
|
|
359
|
+
return SigningStargateClient;
|
|
360
|
+
}(stargateclient_1.StargateClient));
|
|
361
|
+
exports.SigningStargateClient = SigningStargateClient;
|