Remove makeSignBytes

This commit is contained in:
Simon Warta 2020-09-23 16:52:57 +02:00
parent 751861e501
commit 14c285748a
9 changed files with 12 additions and 37 deletions

View File

@ -53,6 +53,8 @@
- @cosmjs/launchpad: Remove `PrehashType` and the prehash type argument in
`OfflineSigner.sign` because the signer now needs to know how to serialize an
`StdSignDoc`.
- @cosmjs/launchpad: Remove `makeSignBytes` in favour of `makeStdSignDoc` and
`serializeSignDoc`.
- @cosmjs/launchpad-ledger: Add package supporting Ledger device integration for
Launchpad. Two new classes are provided: `LedgerSigner` (for most use cases)
and `LaunchpadLedger` for more fine-grained access.

View File

@ -66,7 +66,7 @@ const sendTokensMsg: MsgSend = {
},
};
const signBytes = makeSignBytes(
const signDoc = makeStdSignDoc(
[sendTokensMsg],
defaultFee,
defaultNetworkId,
@ -74,7 +74,7 @@ const signBytes = makeSignBytes(
account_number,
sequence,
);
const signature = await pen.sign(signBytes);
const { signature } = await wallet.sign(faucetAddress, signDoc);
const signedTx: StdTx = {
msg: [sendTokensMsg],
fee: defaultFee,

View File

@ -98,7 +98,6 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
"encodeSecp256k1Signature",
"logs",
"makeCosmoshubPath",
"makeSignBytes",
"makeStdSignDoc",
"IndexedTx",
"BroadcastTxResult",

View File

@ -173,7 +173,7 @@ import { MsgExecuteContract, setupWasmExtension } from "@cosmjs/cosmwasm";
import {
assertIsPostTxSuccess,
LcdClient,
makeSignBytes,
makeStdSignDoc,
setupAuthExtension,
StdFee,
StdTx,
@ -205,7 +205,7 @@ const memo = "Time for action";
const { account_number, sequence } = (
await client.auth.account(myAddress)
).result.value;
const signBytes = makeSignBytes(
const signDoc = makeStdSignDoc(
[msg],
fee,
apiUrl,
@ -213,7 +213,7 @@ const signBytes = makeSignBytes(
account_number,
sequence,
);
const signature = await signer.sign(myAddress, signBytes);
const { signature } = await signer.sign(myAddress, signDoc);
const signedTx: StdTx = {
msg: [msg],
fee: fee,

View File

@ -59,15 +59,3 @@ export function serializeSignDoc(signDoc: StdSignDoc): Uint8Array {
const sortedSignDoc = sortJson(signDoc);
return toUtf8(JSON.stringify(sortedSignDoc));
}
/** A convenience helper to create the StdSignDoc and serialize it */
export function makeSignBytes(
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,
accountNumber: number | string,
sequence: number | string,
): Uint8Array {
return serializeSignDoc(makeStdSignDoc(msgs, fee, chainId, memo, accountNumber, sequence));
}

View File

@ -28,7 +28,7 @@ export {
isSearchBySentFromOrToQuery,
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes, makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,

View File

@ -1,6 +1,6 @@
import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto";
import { makeSignBytes } from "./encoding";
import { makeStdSignDoc, serializeSignDoc } from "./encoding";
import { decodeSignature } from "./signature";
import { CosmosSdkTx } from "./types";
@ -30,13 +30,8 @@ export async function findSequenceForSignedTx(
for (let s = min; s < upperBound; s++) {
// console.log(`Trying sequence ${s}`);
const signBytes = makeSignBytes(
tx.value.msg,
tx.value.fee,
chainId,
tx.value.memo || "",
accountNumber,
s,
const signBytes = serializeSignDoc(
makeStdSignDoc(tx.value.msg, tx.value.fee, chainId, tx.value.memo || "", accountNumber, s),
);
const prehashed = new Sha256(signBytes).digest();
const valid = await Secp256k1.verifySignature(secp256keSignature, prehashed, pubkey);

View File

@ -22,12 +22,3 @@ export declare function makeStdSignDoc(
sequence: number | string,
): StdSignDoc;
export declare function serializeSignDoc(signDoc: StdSignDoc): Uint8Array;
/** A convenience helper to create the StdSignDoc and serialize it */
export declare function makeSignBytes(
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,
accountNumber: number | string,
sequence: number | string,
): Uint8Array;

View File

@ -26,7 +26,7 @@ export {
isSearchBySentFromOrToQuery,
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes, makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,