Make messages in makeSignBytes a list

this fixes a bug introduced in 2d14efa4cd
This commit is contained in:
Simon Warta 2020-02-04 15:09:33 +01:00
parent 555534ba1b
commit 63e3ab037c
4 changed files with 17 additions and 7 deletions

View File

@ -38,7 +38,7 @@ export class CosmWasmCodec implements TxCodec {
sequence: nonceToSequence(nonce),
};
const signBytes = makeSignBytes(
built.value.msg[0],
built.value.msg,
built.value.fee,
Caip5.decode(unsigned.chainId),
built.value.memo || "",

View File

@ -28,23 +28,33 @@ export function marshalTx(tx: StdTx): Uint8Array {
return Encoding.toUtf8(json);
}
interface SignJson {
readonly account_number: string;
readonly chain_id: string;
readonly fee: StdFee;
readonly memo: string;
readonly msgs: readonly Msg[];
readonly sequence: string;
}
export function makeSignBytes(
msg: Msg,
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,
account: NonceInfo,
): Uint8Array {
const signMsg = sortJson({
const signJson: SignJson = {
// eslint-disable-next-line @typescript-eslint/camelcase
account_number: account.account_number.toString(),
// eslint-disable-next-line @typescript-eslint/camelcase
chain_id: chainId,
fee: fee,
memo: memo,
msgs: msg,
msgs: msgs,
sequence: account.sequence.toString(),
});
};
const signMsg = sortJson(signJson);
return toUtf8(JSON.stringify(signMsg));
}

View File

@ -152,7 +152,7 @@ describe("RestClient", () => {
const client = new RestClient(httpUrl);
const account = (await client.authAccounts(faucetAddress)).result.value;
const signBytes = makeSignBytes(theMsg, fee, defaultNetworkId, memo, account) as SignableBytes;
const signBytes = makeSignBytes([theMsg], fee, defaultNetworkId, memo, account) as SignableBytes;
const rawSignature = await wallet.createTransactionSignature(signer, signBytes, PrehashType.Sha256);
const signature = encodeSecp256k1Signature(signer.pubkey.data, rawSignature);

View File

@ -2,7 +2,7 @@ import { Msg, NonceInfo, StdFee, StdSignature, StdTx } from "./types";
export declare function sortJson(json: any): any;
export declare function marshalTx(tx: StdTx): Uint8Array;
export declare function makeSignBytes(
msg: Msg,
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,