diff --git a/CHANGELOG.md b/CHANGELOG.md index 65c13f169c..56c8ae11d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/packages/cli/README.md b/packages/cli/README.md index 67fdef449c..fd53192cfc 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -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, diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 6db25cda04..d4319745e1 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -98,7 +98,6 @@ export async function main(originalArgs: readonly string[]): Promise { "encodeSecp256k1Signature", "logs", "makeCosmoshubPath", - "makeSignBytes", "makeStdSignDoc", "IndexedTx", "BroadcastTxResult", diff --git a/packages/launchpad/README.md b/packages/launchpad/README.md index 0985bb0699..294c8075fc 100644 --- a/packages/launchpad/README.md +++ b/packages/launchpad/README.md @@ -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, diff --git a/packages/launchpad/src/encoding.ts b/packages/launchpad/src/encoding.ts index 6f11b1682c..43ae5fd7a4 100644 --- a/packages/launchpad/src/encoding.ts +++ b/packages/launchpad/src/encoding.ts @@ -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)); -} diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 7220683dc9..57ac29e5cb 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -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, diff --git a/packages/launchpad/src/sequence.ts b/packages/launchpad/src/sequence.ts index cc9a8a3876..2b2050e41f 100644 --- a/packages/launchpad/src/sequence.ts +++ b/packages/launchpad/src/sequence.ts @@ -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); diff --git a/packages/launchpad/types/encoding.d.ts b/packages/launchpad/types/encoding.d.ts index bb0268626e..0e67241045 100644 --- a/packages/launchpad/types/encoding.d.ts +++ b/packages/launchpad/types/encoding.d.ts @@ -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; diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index a767b1efc8..f80e9a78e7 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -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,