@firmachain/firma-js 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sdk/FirmaUtil.d.ts +21 -19
- package/dist/sdk/FirmaUtil.js +116 -151
- package/dist/sdk/FirmaWalletService.d.ts +0 -3
- package/dist/sdk/FirmaWalletService.js +11 -19
- package/dist/sdk/firmachain/common/ITxClient.d.ts +3 -1
- package/dist/sdk/firmachain/common/ITxClient.js +18 -4
- package/dist/sdk/firmachain/common/LedgerWallet.js +1 -1
- package/dist/sdk/firmachain/common/SigningProtobufStargateClient.d.ts +34 -0
- package/dist/sdk/firmachain/common/SigningProtobufStargateClient.js +319 -0
- package/dist/sdk/firmachain/common/SigningStargateClient.d.ts +37 -0
- package/dist/sdk/firmachain/common/SigningStargateClient.js +322 -0
- package/dist/sdk/firmachain/common/StargateClient.d.ts +161 -0
- package/dist/sdk/firmachain/common/StargateClient.js +433 -0
- package/dist/sdk/firmachain/common/TxCommon.d.ts +2 -16
- package/dist/sdk/firmachain/common/accounts.d.ts +4 -0
- package/dist/sdk/firmachain/common/events.d.ts +36 -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 +90 -0
- package/dist/sdk/firmachain/common/signing.d.ts +19 -0
- package/dist/sdk/firmachain/common/signing.js +132 -0
- package/dist/test/26.cosmwasm_query.test.js +1 -3
- package/dist/test/27.arbitrary_sign.test.js +61 -30
- package/dist/test/config_test.d.ts +9 -9
- package/dist/test/config_test.js +27 -26
- package/package.json +1 -1
- package/dist/sdk/firmachain/common/coins.d.ts +0 -30
- package/dist/sdk/firmachain/common/coins.js +0 -69
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __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 = exports.defaultRegistryTypes = void 0;
|
|
83
|
+
var encoding_1 = require("@cosmjs/encoding");
|
|
84
|
+
var proto_signing_1 = require("@cosmjs/proto-signing");
|
|
85
|
+
var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
|
|
86
|
+
var coin_1 = require("cosmjs-types/cosmos/base/v1beta1/coin");
|
|
87
|
+
var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
88
|
+
var keys_1 = require("cosmjs-types/cosmos/crypto/secp256k1/keys");
|
|
89
|
+
var axios_1 = __importDefault(require("axios"));
|
|
90
|
+
var accounts_1 = require("./accounts");
|
|
91
|
+
var StargateClient_1 = require("./StargateClient");
|
|
92
|
+
var any_1 = require("cosmjs-types/google/protobuf/any");
|
|
93
|
+
var modules_1 = require("@cosmjs/stargate/build/modules");
|
|
94
|
+
var signing_1 = require("./signing");
|
|
95
|
+
exports.defaultRegistryTypes = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
|
|
96
|
+
["/cosmos.base.v1beta1.Coin", coin_1.Coin]
|
|
97
|
+
], __read(modules_1.authzTypes), false), __read(modules_1.bankTypes), false), __read(modules_1.distributionTypes), false), __read(modules_1.feegrantTypes), false), __read(modules_1.govTypes), false), __read(modules_1.groupTypes), false), __read(modules_1.stakingTypes), false), __read(modules_1.ibcTypes), false), __read(modules_1.vestingTypes), false);
|
|
98
|
+
var SigningStargateClient = /** @class */ (function (_super) {
|
|
99
|
+
__extends(SigningStargateClient, _super);
|
|
100
|
+
function SigningStargateClient(cometClient, signer, options) {
|
|
101
|
+
var _this = _super.call(this, cometClient, options) || this;
|
|
102
|
+
var _a = options.registry, registry = _a === void 0 ? new proto_signing_1.Registry(exports.defaultRegistryTypes) : _a;
|
|
103
|
+
_this.registry = registry;
|
|
104
|
+
_this.signer = signer;
|
|
105
|
+
return _this;
|
|
106
|
+
}
|
|
107
|
+
SigningStargateClient.connectWithSigner = function (endpoint, signer, options) {
|
|
108
|
+
if (options === void 0) { options = {}; }
|
|
109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
+
var cometClient;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, (0, tendermint_rpc_1.connectComet)(endpoint)];
|
|
114
|
+
case 1:
|
|
115
|
+
cometClient = _a.sent();
|
|
116
|
+
return [2 /*return*/, SigningStargateClient.createWithSigner(cometClient, signer, options)];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
SigningStargateClient.createWithSigner = function (cometClient, signer, options) {
|
|
122
|
+
if (options === void 0) { options = {}; }
|
|
123
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
return [2 /*return*/, new SigningStargateClient(cometClient, signer, options)];
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
|
|
130
|
+
if (memo === void 0) { memo = ""; }
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
var txRaw, txBytes;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
|
|
136
|
+
case 1:
|
|
137
|
+
txRaw = _a.sent();
|
|
138
|
+
txBytes = tx_1.TxRaw.encode(txRaw).finish();
|
|
139
|
+
return [2 /*return*/, this.broadcastTx(txBytes)];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
SigningStargateClient.makeSignDocForSend = function (signerAddress, pubkeyStr, messages, fee, memo, serverUrl, chainId, registry) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var _a, accountNumber, sequence, account, pubkeyBytes, pubkey, pubkeyAny, anyMsgs, txBody, bodyBytes, authInfoBytes;
|
|
147
|
+
return __generator(this, function (_b) {
|
|
148
|
+
switch (_b.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
SigningStargateClient._endpoint = serverUrl;
|
|
151
|
+
return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
|
|
152
|
+
case 1:
|
|
153
|
+
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
154
|
+
return [4 /*yield*/, SigningStargateClient.getAccount(signerAddress)];
|
|
155
|
+
case 2:
|
|
156
|
+
account = _b.sent();
|
|
157
|
+
if (account == null)
|
|
158
|
+
throw new Error("Failed to retrieve account from signer");
|
|
159
|
+
pubkeyBytes = (0, encoding_1.fromBase64)(pubkeyStr);
|
|
160
|
+
pubkey = keys_1.PubKey.fromPartial({
|
|
161
|
+
key: pubkeyBytes,
|
|
162
|
+
});
|
|
163
|
+
pubkeyAny = {
|
|
164
|
+
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
|
165
|
+
value: keys_1.PubKey.encode(pubkey).finish(),
|
|
166
|
+
};
|
|
167
|
+
anyMsgs = messages.map(function (msg) { return registry.encodeAsAny(msg); });
|
|
168
|
+
txBody = tx_1.TxBody.fromPartial({
|
|
169
|
+
messages: anyMsgs,
|
|
170
|
+
memo: memo,
|
|
171
|
+
});
|
|
172
|
+
bodyBytes = tx_1.TxBody.encode(txBody).finish();
|
|
173
|
+
authInfoBytes = (0, signing_1.makeAuthInfoBytesProtobuf)([{ pubkey: pubkeyAny, sequence: sequence }], fee.amount, fee.gasLimit, fee.granter, fee.payer);
|
|
174
|
+
return [2 /*return*/, (0, signing_1.makeSignDocProtobuf)(bodyBytes, authInfoBytes, chainId, accountNumber)];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
181
|
+
var signerData, _a, accountNumber, sequence, chainId;
|
|
182
|
+
return __generator(this, function (_b) {
|
|
183
|
+
switch (_b.label) {
|
|
184
|
+
case 0:
|
|
185
|
+
if (!explicitSignerData) return [3 /*break*/, 1];
|
|
186
|
+
signerData = explicitSignerData;
|
|
187
|
+
return [3 /*break*/, 4];
|
|
188
|
+
case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
|
|
189
|
+
case 2:
|
|
190
|
+
_a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
|
|
191
|
+
return [4 /*yield*/, this.getChainId()];
|
|
192
|
+
case 3:
|
|
193
|
+
chainId = _b.sent();
|
|
194
|
+
signerData = {
|
|
195
|
+
accountNumber: accountNumber,
|
|
196
|
+
sequence: sequence,
|
|
197
|
+
chainId: chainId,
|
|
198
|
+
};
|
|
199
|
+
_b.label = 4;
|
|
200
|
+
case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
|
|
206
|
+
var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var accountFromSigner, pubkey, pubkeyAny, anyMsgs, txBody, bodyBytes, authInfoBytes, signDoc, _b, signature, signed;
|
|
209
|
+
var _this = this;
|
|
210
|
+
return __generator(this, function (_c) {
|
|
211
|
+
switch (_c.label) {
|
|
212
|
+
case 0: return [4 /*yield*/, this.signer.getAccounts()];
|
|
213
|
+
case 1:
|
|
214
|
+
accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
|
|
215
|
+
if (!accountFromSigner) {
|
|
216
|
+
throw new Error("Failed to retrieve account from signer");
|
|
217
|
+
}
|
|
218
|
+
pubkey = keys_1.PubKey.fromPartial({
|
|
219
|
+
key: accountFromSigner.pubkey,
|
|
220
|
+
});
|
|
221
|
+
pubkeyAny = {
|
|
222
|
+
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
|
223
|
+
value: keys_1.PubKey.encode(pubkey).finish(),
|
|
224
|
+
};
|
|
225
|
+
anyMsgs = messages.map(function (msg) { return _this.registry.encodeAsAny(msg); });
|
|
226
|
+
txBody = tx_1.TxBody.fromPartial({
|
|
227
|
+
messages: anyMsgs,
|
|
228
|
+
memo: memo,
|
|
229
|
+
});
|
|
230
|
+
bodyBytes = tx_1.TxBody.encode(txBody).finish();
|
|
231
|
+
authInfoBytes = (0, signing_1.makeAuthInfoBytesProtobuf)([{ pubkey: pubkeyAny, sequence: sequence }], fee.amount, fee.gasLimit, fee.granter, fee.payer);
|
|
232
|
+
signDoc = (0, signing_1.makeSignDocProtobuf)(bodyBytes, authInfoBytes, chainId, accountNumber);
|
|
233
|
+
return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
|
|
234
|
+
case 2:
|
|
235
|
+
_b = _c.sent(), signature = _b.signature, signed = _b.signed;
|
|
236
|
+
return [2 /*return*/, tx_1.TxRaw.fromPartial({
|
|
237
|
+
bodyBytes: signed.bodyBytes,
|
|
238
|
+
authInfoBytes: signed.authInfoBytes,
|
|
239
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
240
|
+
})];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
SigningStargateClient.prototype.signDirectForSignDoc = function (signerAddress, signDoc) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
+
var accountFromSigner, _a, signature, signed, txRaw;
|
|
248
|
+
return __generator(this, function (_b) {
|
|
249
|
+
switch (_b.label) {
|
|
250
|
+
case 0: return [4 /*yield*/, this.signer.getAccounts()];
|
|
251
|
+
case 1:
|
|
252
|
+
accountFromSigner = (_b.sent()).find(function (account) { return account.address === signerAddress; });
|
|
253
|
+
if (!accountFromSigner) {
|
|
254
|
+
throw new Error("Failed to retrieve account from signer");
|
|
255
|
+
}
|
|
256
|
+
return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
|
|
257
|
+
case 2:
|
|
258
|
+
_a = _b.sent(), signature = _a.signature, signed = _a.signed;
|
|
259
|
+
txRaw = tx_1.TxRaw.fromPartial({
|
|
260
|
+
bodyBytes: signed.bodyBytes,
|
|
261
|
+
authInfoBytes: signed.authInfoBytes,
|
|
262
|
+
signatures: [(0, encoding_1.fromBase64)(signature.signature)],
|
|
263
|
+
});
|
|
264
|
+
return [2 /*return*/, { txRaw: txRaw, signature: signature.signature }];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
SigningStargateClient.getSequence = function (address) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
+
var account;
|
|
272
|
+
return __generator(this, function (_a) {
|
|
273
|
+
switch (_a.label) {
|
|
274
|
+
case 0: return [4 /*yield*/, this.getAccount(address)];
|
|
275
|
+
case 1:
|
|
276
|
+
account = _a.sent();
|
|
277
|
+
if (!account) {
|
|
278
|
+
throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
|
|
279
|
+
}
|
|
280
|
+
return [2 /*return*/, {
|
|
281
|
+
accountNumber: account.accountNumber,
|
|
282
|
+
sequence: account.sequence,
|
|
283
|
+
}];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
SigningStargateClient.getAccount = function (address) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
290
|
+
var accAddress, hexAccAddress, axiosInstance, path, result, finalData, account, error_1;
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
_a.trys.push([0, 2, , 3]);
|
|
295
|
+
accAddress = (0, encoding_1.fromBech32)(address).data;
|
|
296
|
+
hexAccAddress = "0x01".concat(Buffer.from(accAddress).toString("hex"));
|
|
297
|
+
axiosInstance = axios_1.default.create({
|
|
298
|
+
baseURL: SigningStargateClient._endpoint,
|
|
299
|
+
headers: {
|
|
300
|
+
Accept: "application/json",
|
|
301
|
+
},
|
|
302
|
+
timeout: 15000
|
|
303
|
+
});
|
|
304
|
+
path = "/abci_query?path=\"/store/acc/key\"";
|
|
305
|
+
return [4 /*yield*/, axiosInstance.get(path, { params: { data: hexAccAddress } })];
|
|
306
|
+
case 1:
|
|
307
|
+
result = _a.sent();
|
|
308
|
+
finalData = result.data.result.response.value;
|
|
309
|
+
account = any_1.Any.decode(Buffer.from(finalData, "base64"));
|
|
310
|
+
return [2 /*return*/, (0, accounts_1.accountFromAny)(account)];
|
|
311
|
+
case 2:
|
|
312
|
+
error_1 = _a.sent();
|
|
313
|
+
return [2 /*return*/, null];
|
|
314
|
+
case 3: return [2 /*return*/];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
SigningStargateClient._endpoint = "";
|
|
320
|
+
return SigningStargateClient;
|
|
321
|
+
}(StargateClient_1.StargateClient));
|
|
322
|
+
exports.SigningStargateClient = SigningStargateClient;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { CometClient, HttpEndpoint } from "@cosmjs/tendermint-rpc";
|
|
2
|
+
import { AuthExtension, BankExtension, QueryClient, StakingExtension, TxExtension } from "@cosmjs/stargate";
|
|
3
|
+
import { Account, AccountParser } from "./accounts";
|
|
4
|
+
import { Event } from "./events";
|
|
5
|
+
export declare class TimeoutError extends Error {
|
|
6
|
+
readonly txId: string;
|
|
7
|
+
constructor(message: string, txId: string);
|
|
8
|
+
}
|
|
9
|
+
export interface BlockHeader {
|
|
10
|
+
readonly version: {
|
|
11
|
+
readonly block: string;
|
|
12
|
+
readonly app: string;
|
|
13
|
+
};
|
|
14
|
+
readonly height: number;
|
|
15
|
+
readonly chainId: string;
|
|
16
|
+
/** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */
|
|
17
|
+
readonly time: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Block {
|
|
20
|
+
/** The ID is a hash of the block header (uppercase hex) */
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly header: BlockHeader;
|
|
23
|
+
/** Array of raw transactions */
|
|
24
|
+
readonly txs: readonly Uint8Array[];
|
|
25
|
+
}
|
|
26
|
+
/** A transaction that is indexed as part of the transaction history */
|
|
27
|
+
export interface IndexedTx {
|
|
28
|
+
readonly height: number;
|
|
29
|
+
/** The position of the transaction within the block. This is a 0-based index. */
|
|
30
|
+
readonly txIndex: number;
|
|
31
|
+
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
|
|
32
|
+
readonly hash: string;
|
|
33
|
+
/** Transaction execution error code. 0 on success. */
|
|
34
|
+
readonly code: number;
|
|
35
|
+
readonly events: readonly Event[];
|
|
36
|
+
/**
|
|
37
|
+
* Raw transaction bytes stored in Tendermint.
|
|
38
|
+
*
|
|
39
|
+
* If you hash this, you get the transaction hash (= transaction ID):
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* import { sha256 } from "@cosmjs/crypto";
|
|
43
|
+
* import { toHex } from "@cosmjs/encoding";
|
|
44
|
+
*
|
|
45
|
+
* const transactionId = toHex(sha256(indexTx.tx)).toUpperCase();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Use `decodeTxRaw` from @cosmjs/proto-signing to decode this.
|
|
49
|
+
*/
|
|
50
|
+
readonly tx: Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* The message responses extracted from events.
|
|
53
|
+
* This field contains structured message response data parsed from transaction events.
|
|
54
|
+
*/
|
|
55
|
+
readonly msgResponses: Array<{
|
|
56
|
+
readonly typeUrl: string;
|
|
57
|
+
readonly value: Uint8Array;
|
|
58
|
+
}>;
|
|
59
|
+
readonly gasUsed: bigint;
|
|
60
|
+
readonly gasWanted: bigint;
|
|
61
|
+
}
|
|
62
|
+
export interface SequenceResponse {
|
|
63
|
+
readonly accountNumber: number;
|
|
64
|
+
readonly sequence: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The response after successfully broadcasting a transaction.
|
|
68
|
+
* Success or failure refer to the execution result.
|
|
69
|
+
*/
|
|
70
|
+
export interface DeliverTxResponse {
|
|
71
|
+
readonly height: number;
|
|
72
|
+
/** The position of the transaction within the block. This is a 0-based index. */
|
|
73
|
+
readonly txIndex: number;
|
|
74
|
+
/** Error code. The transaction suceeded if and only if code is 0. */
|
|
75
|
+
readonly code: number;
|
|
76
|
+
readonly transactionHash: string;
|
|
77
|
+
readonly events: readonly Event[];
|
|
78
|
+
/**
|
|
79
|
+
* The message responses extracted from events.
|
|
80
|
+
* This field contains structured message response data parsed from transaction events.
|
|
81
|
+
*/
|
|
82
|
+
readonly msgResponses: Array<{
|
|
83
|
+
readonly typeUrl: string;
|
|
84
|
+
readonly value: Uint8Array;
|
|
85
|
+
}>;
|
|
86
|
+
readonly gasUsed: bigint;
|
|
87
|
+
readonly gasWanted: bigint;
|
|
88
|
+
}
|
|
89
|
+
export type BroadcastTxResponse = DeliverTxResponse;
|
|
90
|
+
export declare function isDeliverTxFailure(result: DeliverTxResponse): boolean;
|
|
91
|
+
export declare function isDeliverTxSuccess(result: DeliverTxResponse): boolean;
|
|
92
|
+
export declare function isBroadcastTxFailure(result: BroadcastTxResponse): boolean;
|
|
93
|
+
export declare function isBroadcastTxSuccess(result: BroadcastTxResponse): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Ensures the given result is a success. Throws a detailed error message otherwise.
|
|
96
|
+
*/
|
|
97
|
+
export declare function assertIsDeliverTxSuccess(result: DeliverTxResponse): void;
|
|
98
|
+
/**
|
|
99
|
+
* Ensures the given result is a failure. Throws a detailed error message otherwise.
|
|
100
|
+
*/
|
|
101
|
+
export declare function assertIsDeliverTxFailure(result: DeliverTxResponse): void;
|
|
102
|
+
/**
|
|
103
|
+
* An error when broadcasting the transaction. This contains the CheckTx errors
|
|
104
|
+
* from the blockchain. Once a transaction is included in a block no BroadcastTxError
|
|
105
|
+
* is thrown, even if the execution fails (DeliverTx errors).
|
|
106
|
+
*/
|
|
107
|
+
export declare class BroadcastTxError extends Error {
|
|
108
|
+
readonly code: number;
|
|
109
|
+
readonly codespace: string;
|
|
110
|
+
readonly log: string | undefined;
|
|
111
|
+
constructor(code: number, codespace: string, log: string | undefined);
|
|
112
|
+
}
|
|
113
|
+
/** Use for testing only */
|
|
114
|
+
export interface PrivateStargateClient {
|
|
115
|
+
readonly cometClient: CometClient | undefined;
|
|
116
|
+
}
|
|
117
|
+
export interface StargateClientOptions {
|
|
118
|
+
readonly accountParser?: AccountParser;
|
|
119
|
+
}
|
|
120
|
+
export declare class StargateClient {
|
|
121
|
+
private readonly cometClient;
|
|
122
|
+
private readonly queryClient;
|
|
123
|
+
private chainId;
|
|
124
|
+
private readonly accountParser;
|
|
125
|
+
/**
|
|
126
|
+
* Creates an instance by connecting to the given CometBFT RPC endpoint.
|
|
127
|
+
*
|
|
128
|
+
* This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client.
|
|
129
|
+
* To set the Comet client explicitly, use `create`.
|
|
130
|
+
*/
|
|
131
|
+
static connect(endpoint: string | HttpEndpoint, options?: StargateClientOptions): Promise<StargateClient>;
|
|
132
|
+
/**
|
|
133
|
+
* Creates an instance from a manually created Comet client.
|
|
134
|
+
* Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
|
|
135
|
+
*/
|
|
136
|
+
static create(cometClient: CometClient, options?: StargateClientOptions): Promise<StargateClient>;
|
|
137
|
+
protected constructor(cometClient: CometClient | undefined, options?: StargateClientOptions);
|
|
138
|
+
protected getCometClient(): CometClient | undefined;
|
|
139
|
+
protected forceGetCometClient(): CometClient;
|
|
140
|
+
protected getQueryClient(): (QueryClient & AuthExtension & BankExtension & StakingExtension & TxExtension) | undefined;
|
|
141
|
+
protected forceGetQueryClient(): QueryClient & AuthExtension & BankExtension & StakingExtension & TxExtension;
|
|
142
|
+
getChainId(): Promise<string>;
|
|
143
|
+
getHeight(): Promise<number>;
|
|
144
|
+
getAccount(searchAddress: string): Promise<Account | null>;
|
|
145
|
+
getSequence(address: string): Promise<SequenceResponse>;
|
|
146
|
+
getTx(id: string): Promise<IndexedTx | null>;
|
|
147
|
+
disconnect(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Broadcasts a signed transaction to the network and monitors its inclusion in a block.
|
|
150
|
+
*
|
|
151
|
+
* If broadcasting is rejected by the node for some reason (e.g. because of a CheckTx failure),
|
|
152
|
+
* an error is thrown.
|
|
153
|
+
*
|
|
154
|
+
* If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
|
|
155
|
+
*
|
|
156
|
+
* If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
|
|
157
|
+
* usually needs to check for execution success or failure.
|
|
158
|
+
*/
|
|
159
|
+
broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number): Promise<DeliverTxResponse>;
|
|
160
|
+
private txsQuery;
|
|
161
|
+
}
|