From 5f2cf289eb59b64d4a40649c8dad5f7e5a6512fc Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 23 Sep 2020 13:35:12 +0200 Subject: [PATCH] Remove PrehashType --- CHANGELOG.md | 3 +++ packages/launchpad/src/index.ts | 2 +- packages/launchpad/src/signer.ts | 8 +------- packages/launchpad/src/wallet.ts | 17 ----------------- packages/launchpad/types/index.d.ts | 2 +- packages/launchpad/types/signer.d.ts | 7 +------ packages/launchpad/types/wallet.d.ts | 2 -- 7 files changed, 7 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99187b7d..112dbb0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,9 @@ serialize a `StdSignDoc`: `makeStdSignDoc` and `serializeSignDoc`. - @cosmjs/launchpad: Let `OfflineSigner.sign` take an `StdSignDoc` instead of an encoded message. +- @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-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/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 7cf967f8..9fd6d7d0 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -98,7 +98,7 @@ export { } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; -export { AccountData, Algo, PrehashType, OfflineSigner } from "./signer"; +export { AccountData, Algo, OfflineSigner } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; diff --git a/packages/launchpad/src/signer.ts b/packages/launchpad/src/signer.ts index 1217d8f6..e2eb4868 100644 --- a/packages/launchpad/src/signer.ts +++ b/packages/launchpad/src/signer.ts @@ -1,8 +1,6 @@ import { StdSignDoc } from "./encoding"; import { StdSignature } from "./types"; -export type PrehashType = "sha256" | "sha512" | null; - export type Algo = "secp256k1" | "ed25519" | "sr25519"; export interface AccountData { @@ -24,9 +22,5 @@ export interface OfflineSigner { * @param signerAddress The address of the account that should sign the transaction * @param signDoc The content that should be signed */ - readonly sign: ( - signerAddress: string, - signDoc: StdSignDoc, - prehashType?: PrehashType, - ) => Promise; + readonly sign: (signerAddress: string, signDoc: StdSignDoc) => Promise; } diff --git a/packages/launchpad/src/wallet.ts b/packages/launchpad/src/wallet.ts index 6f4f2b44..1c64e773 100644 --- a/packages/launchpad/src/wallet.ts +++ b/packages/launchpad/src/wallet.ts @@ -3,29 +3,12 @@ import { HdPath, isArgon2idOptions, Random, - Sha256, - Sha512, Slip10RawIndex, xchacha20NonceLength, Xchacha20poly1305Ietf, } from "@cosmjs/crypto"; import { toAscii } from "@cosmjs/encoding"; -import { PrehashType } from "./signer"; - -export function prehash(bytes: Uint8Array, type: PrehashType): Uint8Array { - switch (type) { - case null: - return new Uint8Array([...bytes]); - case "sha256": - return new Sha256(bytes).digest(); - case "sha512": - return new Sha512(bytes).digest(); - default: - throw new Error("Unknown prehash type"); - } -} - /** * The Cosmoshub derivation path in the form `m/44'/118'/0'/0/a` * with 0-based account index `a`. diff --git a/packages/launchpad/types/index.d.ts b/packages/launchpad/types/index.d.ts index 6d9b9ee8..de247a1e 100644 --- a/packages/launchpad/types/index.d.ts +++ b/packages/launchpad/types/index.d.ts @@ -96,7 +96,7 @@ export { } from "./pubkey"; export { findSequenceForSignedTx } from "./sequence"; export { encodeSecp256k1Signature, decodeSignature } from "./signature"; -export { AccountData, Algo, PrehashType, OfflineSigner } from "./signer"; +export { AccountData, Algo, OfflineSigner } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types"; export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; diff --git a/packages/launchpad/types/signer.d.ts b/packages/launchpad/types/signer.d.ts index 2b0948a4..3a2e17e3 100644 --- a/packages/launchpad/types/signer.d.ts +++ b/packages/launchpad/types/signer.d.ts @@ -1,6 +1,5 @@ import { StdSignDoc } from "./encoding"; import { StdSignature } from "./types"; -export declare type PrehashType = "sha256" | "sha512" | null; export declare type Algo = "secp256k1" | "ed25519" | "sr25519"; export interface AccountData { /** A printable address (typically bech32 encoded) */ @@ -19,9 +18,5 @@ export interface OfflineSigner { * @param signerAddress The address of the account that should sign the transaction * @param signDoc The content that should be signed */ - readonly sign: ( - signerAddress: string, - signDoc: StdSignDoc, - prehashType?: PrehashType, - ) => Promise; + readonly sign: (signerAddress: string, signDoc: StdSignDoc) => Promise; } diff --git a/packages/launchpad/types/wallet.d.ts b/packages/launchpad/types/wallet.d.ts index f3e49071..6c433d32 100644 --- a/packages/launchpad/types/wallet.d.ts +++ b/packages/launchpad/types/wallet.d.ts @@ -1,6 +1,4 @@ import { HdPath } from "@cosmjs/crypto"; -import { PrehashType } from "./signer"; -export declare function prehash(bytes: Uint8Array, type: PrehashType): Uint8Array; /** * The Cosmoshub derivation path in the form `m/44'/118'/0'/0/a` * with 0-based account index `a`.