-
Notifications
You must be signed in to change notification settings - Fork 310
/
signingcosmwasmclient.ts
652 lines (618 loc) · 21.8 KB
/
signingcosmwasmclient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/* eslint-disable @typescript-eslint/naming-convention */
import { encodeSecp256k1Pubkey, makeSignDoc as makeSignDocAmino } from "@cosmjs/amino";
import { sha256 } from "@cosmjs/crypto";
import { fromBase64, toHex, toUtf8 } from "@cosmjs/encoding";
import { Int53, Uint53 } from "@cosmjs/math";
import {
EncodeObject,
encodePubkey,
isOfflineDirectSigner,
makeAuthInfoBytes,
makeSignDoc,
OfflineSigner,
Registry,
TxBodyEncodeObject,
} from "@cosmjs/proto-signing";
import {
AminoTypes,
calculateFee,
Coin,
createBankAminoConverters,
defaultRegistryTypes as defaultStargateTypes,
DeliverTxResponse,
Event,
GasPrice,
isDeliverTxFailure,
logs,
MsgDelegateEncodeObject,
MsgSendEncodeObject,
MsgUndelegateEncodeObject,
MsgWithdrawDelegatorRewardEncodeObject,
SignerData,
StdFee,
} from "@cosmjs/stargate";
import { HttpEndpoint, Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { assert, assertDefined } from "@cosmjs/utils";
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
import { MsgDelegate, MsgUndelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import {
MsgClearAdmin,
MsgExecuteContract,
MsgInstantiateContract,
MsgMigrateContract,
MsgStoreCode,
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import Long from "long";
import pako from "pako";
import { CosmWasmClient } from "./cosmwasmclient";
import {
createWasmAminoConverters,
JsonObject,
MsgClearAdminEncodeObject,
MsgExecuteContractEncodeObject,
MsgInstantiateContractEncodeObject,
MsgMigrateContractEncodeObject,
MsgStoreCodeEncodeObject,
MsgUpdateAdminEncodeObject,
wasmTypes,
} from "./modules";
export interface UploadResult {
/** Size of the original wasm code in bytes */
readonly originalSize: number;
/** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */
readonly originalChecksum: string;
/** Size of the compressed wasm code in bytes */
readonly compressedSize: number;
/** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */
readonly compressedChecksum: string;
/** The ID of the code asigned by the chain */
readonly codeId: number;
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
}
/**
* The options of an .instantiate() call.
* All properties are optional.
*/
export interface InstantiateOptions {
readonly memo?: string;
/**
* The funds that are transferred from the sender to the newly created contract.
* The funds are transferred as part of the message execution after the contract address is
* created and before the instantiation message is executed by the contract.
*
* Only native tokens are supported.
*/
readonly funds?: readonly Coin[];
/**
* A bech32 encoded address of an admin account.
* Caution: an admin has the privilege to upgrade a contract. If this is not desired, do not set this value.
*/
readonly admin?: string;
}
export interface InstantiateResult {
/** The address of the newly instantiated contract */
readonly contractAddress: string;
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
}
/**
* Result type of updateAdmin and clearAdmin
*/
export interface ChangeAdminResult {
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
}
export interface MigrateResult {
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
}
export interface ExecuteInstruction {
contractAddress: string;
msg: JsonObject;
funds?: readonly Coin[];
}
export interface ExecuteResult {
readonly logs: readonly logs.Log[];
/** Block height in which the transaction is included */
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
readonly events: readonly Event[];
readonly gasWanted: number;
readonly gasUsed: number;
}
function createDeliverTxResponseErrorMessage(result: DeliverTxResponse): string {
return `Error when broadcasting tx ${result.transactionHash} at height ${result.height}. Code: ${result.code}; Raw log: ${result.rawLog}`;
}
function createDefaultRegistry(): Registry {
return new Registry([...defaultStargateTypes, ...wasmTypes]);
}
export interface SigningCosmWasmClientOptions {
readonly registry?: Registry;
readonly aminoTypes?: AminoTypes;
readonly prefix?: string;
readonly broadcastTimeoutMs?: number;
readonly broadcastPollIntervalMs?: number;
readonly gasPrice?: GasPrice;
}
export class SigningCosmWasmClient extends CosmWasmClient {
public readonly registry: Registry;
public readonly broadcastTimeoutMs: number | undefined;
public readonly broadcastPollIntervalMs: number | undefined;
private readonly signer: OfflineSigner;
private readonly aminoTypes: AminoTypes;
private readonly gasPrice: GasPrice | undefined;
public static async connectWithSigner(
endpoint: string | HttpEndpoint,
signer: OfflineSigner,
options: SigningCosmWasmClientOptions = {},
): Promise<SigningCosmWasmClient> {
const tmClient = await Tendermint34Client.connect(endpoint);
return new SigningCosmWasmClient(tmClient, signer, options);
}
/**
* Creates a client in offline mode.
*
* This should only be used in niche cases where you know exactly what you're doing,
* e.g. when building an offline signing application.
*
* When you try to use online functionality with such a signer, an
* exception will be raised.
*/
public static async offline(
signer: OfflineSigner,
options: SigningCosmWasmClientOptions = {},
): Promise<SigningCosmWasmClient> {
return new SigningCosmWasmClient(undefined, signer, options);
}
protected constructor(
tmClient: Tendermint34Client | undefined,
signer: OfflineSigner,
options: SigningCosmWasmClientOptions,
) {
super(tmClient);
const {
registry = createDefaultRegistry(),
aminoTypes = new AminoTypes({ ...createWasmAminoConverters(), ...createBankAminoConverters() }),
} = options;
this.registry = registry;
this.aminoTypes = aminoTypes;
this.signer = signer;
this.broadcastTimeoutMs = options.broadcastTimeoutMs;
this.broadcastPollIntervalMs = options.broadcastPollIntervalMs;
this.gasPrice = options.gasPrice;
}
public async simulate(
signerAddress: string,
messages: readonly EncodeObject[],
memo: string | undefined,
): Promise<number> {
const anyMsgs = messages.map((m) => this.registry.encodeAsAny(m));
const accountFromSigner = (await this.signer.getAccounts()).find(
(account) => account.address === signerAddress,
);
if (!accountFromSigner) {
throw new Error("Failed to retrieve account from signer");
}
const pubkey = encodeSecp256k1Pubkey(accountFromSigner.pubkey);
const { sequence } = await this.getSequence(signerAddress);
const { gasInfo } = await this.forceGetQueryClient().tx.simulate(anyMsgs, memo, pubkey, sequence);
assertDefined(gasInfo);
return Uint53.fromString(gasInfo.gasUsed.toString()).toNumber();
}
/** Uploads code and returns a receipt, including the code ID */
public async upload(
senderAddress: string,
wasmCode: Uint8Array,
fee: StdFee | "auto" | number,
memo = "",
): Promise<UploadResult> {
const compressed = pako.gzip(wasmCode, { level: 9 });
const storeCodeMsg: MsgStoreCodeEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: MsgStoreCode.fromPartial({
sender: senderAddress,
wasmByteCode: compressed,
}),
};
const result = await this.signAndBroadcast(senderAddress, [storeCodeMsg], fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
const parsedLogs = logs.parseRawLog(result.rawLog);
const codeIdAttr = logs.findAttribute(parsedLogs, "store_code", "code_id");
return {
originalSize: wasmCode.length,
originalChecksum: toHex(sha256(wasmCode)),
compressedSize: compressed.length,
compressedChecksum: toHex(sha256(compressed)),
codeId: Number.parseInt(codeIdAttr.value, 10),
logs: parsedLogs,
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async instantiate(
senderAddress: string,
codeId: number,
msg: JsonObject,
label: string,
fee: StdFee | "auto" | number,
options: InstantiateOptions = {},
): Promise<InstantiateResult> {
const instantiateContractMsg: MsgInstantiateContractEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: MsgInstantiateContract.fromPartial({
sender: senderAddress,
codeId: Long.fromString(new Uint53(codeId).toString()),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...(options.funds || [])],
admin: options.admin,
}),
};
const result = await this.signAndBroadcast(senderAddress, [instantiateContractMsg], fee, options.memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
const parsedLogs = logs.parseRawLog(result.rawLog);
const contractAddressAttr = logs.findAttribute(parsedLogs, "instantiate", "_contract_address");
return {
contractAddress: contractAddressAttr.value,
logs: parsedLogs,
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async updateAdmin(
senderAddress: string,
contractAddress: string,
newAdmin: string,
fee: StdFee | "auto" | number,
memo = "",
): Promise<ChangeAdminResult> {
const updateAdminMsg: MsgUpdateAdminEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
value: MsgUpdateAdmin.fromPartial({
sender: senderAddress,
contract: contractAddress,
newAdmin: newAdmin,
}),
};
const result = await this.signAndBroadcast(senderAddress, [updateAdminMsg], fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
return {
logs: logs.parseRawLog(result.rawLog),
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async clearAdmin(
senderAddress: string,
contractAddress: string,
fee: StdFee | "auto" | number,
memo = "",
): Promise<ChangeAdminResult> {
const clearAdminMsg: MsgClearAdminEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
value: MsgClearAdmin.fromPartial({
sender: senderAddress,
contract: contractAddress,
}),
};
const result = await this.signAndBroadcast(senderAddress, [clearAdminMsg], fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
return {
logs: logs.parseRawLog(result.rawLog),
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async migrate(
senderAddress: string,
contractAddress: string,
codeId: number,
migrateMsg: JsonObject,
fee: StdFee | "auto" | number,
memo = "",
): Promise<MigrateResult> {
const migrateContractMsg: MsgMigrateContractEncodeObject = {
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
value: MsgMigrateContract.fromPartial({
sender: senderAddress,
contract: contractAddress,
codeId: Long.fromString(new Uint53(codeId).toString()),
msg: toUtf8(JSON.stringify(migrateMsg)),
}),
};
const result = await this.signAndBroadcast(senderAddress, [migrateContractMsg], fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
return {
logs: logs.parseRawLog(result.rawLog),
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async execute(
senderAddress: string,
contractAddress: string,
msg: JsonObject,
fee: StdFee | "auto" | number,
memo = "",
funds?: readonly Coin[],
): Promise<ExecuteResult> {
const instruction: ExecuteInstruction = {
contractAddress: contractAddress,
msg: msg,
funds: funds,
};
return this.executeMultiple(senderAddress, [instruction], fee, memo);
}
/**
* Like `execute` but allows executing multiple messages in one transaction.
*/
public async executeMultiple(
senderAddress: string,
instructions: readonly ExecuteInstruction[],
fee: StdFee | "auto" | number,
memo = "",
): Promise<ExecuteResult> {
const msgs: MsgExecuteContractEncodeObject[] = instructions.map((i) => ({
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: MsgExecuteContract.fromPartial({
sender: senderAddress,
contract: i.contractAddress,
msg: toUtf8(JSON.stringify(i.msg)),
funds: [...(i.funds || [])],
}),
}));
const result = await this.signAndBroadcast(senderAddress, msgs, fee, memo);
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
return {
logs: logs.parseRawLog(result.rawLog),
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
gasWanted: result.gasWanted,
gasUsed: result.gasUsed,
};
}
public async sendTokens(
senderAddress: string,
recipientAddress: string,
amount: readonly Coin[],
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
const sendMsg: MsgSendEncodeObject = {
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: {
fromAddress: senderAddress,
toAddress: recipientAddress,
amount: [...amount],
},
};
return this.signAndBroadcast(senderAddress, [sendMsg], fee, memo);
}
public async delegateTokens(
delegatorAddress: string,
validatorAddress: string,
amount: Coin,
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
const delegateMsg: MsgDelegateEncodeObject = {
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
value: MsgDelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
};
return this.signAndBroadcast(delegatorAddress, [delegateMsg], fee, memo);
}
public async undelegateTokens(
delegatorAddress: string,
validatorAddress: string,
amount: Coin,
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
const undelegateMsg: MsgUndelegateEncodeObject = {
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
value: MsgUndelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
};
return this.signAndBroadcast(delegatorAddress, [undelegateMsg], fee, memo);
}
public async withdrawRewards(
delegatorAddress: string,
validatorAddress: string,
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
const withdrawDelegatorRewardMsg: MsgWithdrawDelegatorRewardEncodeObject = {
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
value: MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress }),
};
return this.signAndBroadcast(delegatorAddress, [withdrawDelegatorRewardMsg], fee, memo);
}
/**
* Creates a transaction with the given messages, fee and memo. Then signs and broadcasts the transaction.
*
* @param signerAddress The address that will sign transactions using this instance. The signer must be able to sign with this address.
* @param messages
* @param fee
* @param memo
*/
public async signAndBroadcast(
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
let usedFee: StdFee;
if (fee == "auto" || typeof fee === "number") {
assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
const gasEstimation = await this.simulate(signerAddress, messages, memo);
const multiplier = typeof fee === "number" ? fee : 1.3;
usedFee = calculateFee(Math.round(gasEstimation * multiplier), this.gasPrice);
} else {
usedFee = fee;
}
const txRaw = await this.sign(signerAddress, messages, usedFee, memo);
const txBytes = TxRaw.encode(txRaw).finish();
return this.broadcastTx(txBytes, this.broadcastTimeoutMs, this.broadcastPollIntervalMs);
}
public async sign(
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee,
memo: string,
explicitSignerData?: SignerData,
): Promise<TxRaw> {
let signerData: SignerData;
if (explicitSignerData) {
signerData = explicitSignerData;
} else {
const { accountNumber, sequence } = await this.getSequence(signerAddress);
const chainId = await this.getChainId();
signerData = {
accountNumber: accountNumber,
sequence: sequence,
chainId: chainId,
};
}
return isOfflineDirectSigner(this.signer)
? this.signDirect(signerAddress, messages, fee, memo, signerData)
: this.signAmino(signerAddress, messages, fee, memo, signerData);
}
private async signAmino(
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee,
memo: string,
{ accountNumber, sequence, chainId }: SignerData,
): Promise<TxRaw> {
assert(!isOfflineDirectSigner(this.signer));
const accountFromSigner = (await this.signer.getAccounts()).find(
(account) => account.address === signerAddress,
);
if (!accountFromSigner) {
throw new Error("Failed to retrieve account from signer");
}
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence);
const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc);
const signedTxBody: TxBodyEncodeObject = {
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: signed.msgs.map((msg) => this.aminoTypes.fromAmino(msg)),
memo: signed.memo,
},
};
const signedTxBodyBytes = this.registry.encode(signedTxBody);
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
const signedSequence = Int53.fromString(signed.sequence).toNumber();
const signedAuthInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence: signedSequence }],
signed.fee.amount,
signedGasLimit,
signed.fee.granter,
signed.fee.payer,
signMode,
);
return TxRaw.fromPartial({
bodyBytes: signedTxBodyBytes,
authInfoBytes: signedAuthInfoBytes,
signatures: [fromBase64(signature.signature)],
});
}
private async signDirect(
signerAddress: string,
messages: readonly EncodeObject[],
fee: StdFee,
memo: string,
{ accountNumber, sequence, chainId }: SignerData,
): Promise<TxRaw> {
assert(isOfflineDirectSigner(this.signer));
const accountFromSigner = (await this.signer.getAccounts()).find(
(account) => account.address === signerAddress,
);
if (!accountFromSigner) {
throw new Error("Failed to retrieve account from signer");
}
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
const txBody: TxBodyEncodeObject = {
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: messages,
memo: memo,
},
};
const txBodyBytes = this.registry.encode(txBody);
const gasLimit = Int53.fromString(fee.gas).toNumber();
const authInfoBytes = makeAuthInfoBytes(
[{ pubkey, sequence }],
fee.amount,
gasLimit,
fee.granter,
fee.payer,
);
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
const { signature, signed } = await this.signer.signDirect(signerAddress, signDoc);
return TxRaw.fromPartial({
bodyBytes: signed.bodyBytes,
authInfoBytes: signed.authInfoBytes,
signatures: [fromBase64(signature.signature)],
});
}
}