proto-signing: Update makeAuthInfo

This commit is contained in:
willclarktech 2020-10-14 17:11:01 +02:00
parent 7d0d7b8df6
commit b06dedbc2e
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 16 additions and 11 deletions

View File

@ -2,24 +2,30 @@
import Long from "long";
import { omitDefaults } from "./adr27";
import { cosmos } from "./codec";
import { cosmos, google } from "./codec";
const { SignDoc, AuthInfo } = cosmos.tx;
const { SignDoc, AuthInfo } = cosmos.tx.v1beta1;
/**
* Creates and serializes an AuthInfo document using SIGN_MODE_DIRECT.
*/
export function makeAuthInfo(pubkeys: readonly cosmos.crypto.IPublicKey[], gasLimit: number): Uint8Array {
export function makeAuthInfo(
pubkeys: readonly google.protobuf.IAny[],
feeAmount: cosmos.base.v1beta1.Coin[],
gasLimit: number,
sequence: number,
): Uint8Array {
const authInfo = {
signerInfos: pubkeys.map(
(pubkey): cosmos.tx.ISignerInfo => ({
(pubkey): cosmos.tx.v1beta1.ISignerInfo => ({
publicKey: pubkey,
modeInfo: {
single: { mode: cosmos.tx.signing.SignMode.SIGN_MODE_DIRECT },
single: { mode: cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT },
},
sequence: sequence ? Long.fromNumber(sequence) : undefined,
}),
),
fee: { gasLimit: Long.fromNumber(gasLimit) },
fee: { amount: feeAmount, gasLimit: Long.fromNumber(gasLimit) },
};
return Uint8Array.from(AuthInfo.encode(authInfo).finish());
}
@ -29,7 +35,6 @@ export function makeSignBytes(
authInfo: Uint8Array,
chainId: string,
accountNumber: number,
sequence: number,
): Uint8Array {
const signDoc = SignDoc.create(
omitDefaults({
@ -37,7 +42,6 @@ export function makeSignBytes(
authInfoBytes: authInfo,
chainId: chainId,
accountNumber: accountNumber,
accountSequence: sequence,
}),
);
return Uint8Array.from(SignDoc.encode(signDoc).finish());

View File

@ -1,15 +1,16 @@
import { cosmos } from "./codec";
import { cosmos, google } from "./codec";
/**
* Creates and serializes an AuthInfo document using SIGN_MODE_DIRECT.
*/
export declare function makeAuthInfo(
pubkeys: readonly cosmos.crypto.IPublicKey[],
pubkeys: readonly google.protobuf.IAny[],
feeAmount: cosmos.base.v1beta1.Coin[],
gasLimit: number,
sequence: number,
): Uint8Array;
export declare function makeSignBytes(
txBody: Uint8Array,
authInfo: Uint8Array,
chainId: string,
accountNumber: number,
sequence: number,
): Uint8Array;