diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d39c116..dd866eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ - @cosmjs/cosmwasm: Add `CosmWasmClient.getTx` method for searching by ID and remove such functionality from `CosmWasmClient.searchTx`. - @cosmjs/cosmwasm-stargate: Add new package for CosmWasm Stargate support. +- @cosmjs/crypto: Change `Secp256k1Keypair` from tagged type to simple + interface. - @cosmjs/launchpad: Add `Secp256k1Wallet` to manage a single raw secp256k1 keypair. - @cosmjs/launchpad: `OfflineSigner` type’s `sign` method renamed `signAmino` diff --git a/packages/crypto/src/secp256k1.ts b/packages/crypto/src/secp256k1.ts index ec05ed8e..d9357f98 100644 --- a/packages/crypto/src/secp256k1.ts +++ b/packages/crypto/src/secp256k1.ts @@ -1,20 +1,17 @@ import { fromHex, toHex } from "@cosmjs/encoding"; import BN from "bn.js"; import elliptic from "elliptic"; -import { As } from "type-tagger"; import { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature"; const secp256k1 = new elliptic.ec("secp256k1"); const secp256k1N = new BN("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", "hex"); -interface Keypair { +export interface Secp256k1Keypair { readonly pubkey: Uint8Array; readonly privkey: Uint8Array; } -export type Secp256k1Keypair = Keypair & As<"secp256k1-keypair">; - export class Secp256k1 { public static async makeKeypair(privkey: Uint8Array): Promise { if (privkey.length !== 32) { @@ -35,7 +32,7 @@ export class Secp256k1 { throw new Error("input data is not a valid secp256k1 private key"); } - const out: Keypair = { + const out: Secp256k1Keypair = { privkey: fromHex(keypair.getPrivate("hex")), // encodes uncompressed as // - 1-byte prefix "04" @@ -43,7 +40,7 @@ export class Secp256k1 { // - 32-byte y coordinate pubkey: Uint8Array.from(keypair.getPublic("array")), }; - return out as Secp256k1Keypair; + return out; } // Creates a signature that is diff --git a/packages/crypto/types/secp256k1.d.ts b/packages/crypto/types/secp256k1.d.ts index 7f0e6653..1b0d1422 100644 --- a/packages/crypto/types/secp256k1.d.ts +++ b/packages/crypto/types/secp256k1.d.ts @@ -1,10 +1,8 @@ -import { As } from "type-tagger"; import { ExtendedSecp256k1Signature, Secp256k1Signature } from "./secp256k1signature"; -interface Keypair { +export interface Secp256k1Keypair { readonly pubkey: Uint8Array; readonly privkey: Uint8Array; } -export declare type Secp256k1Keypair = Keypair & As<"secp256k1-keypair">; export declare class Secp256k1 { static makeKeypair(privkey: Uint8Array): Promise; static createSignature(messageHash: Uint8Array, privkey: Uint8Array): Promise; @@ -17,4 +15,3 @@ export declare class Secp256k1 { static compressPubkey(pubkey: Uint8Array): Uint8Array; static trimRecoveryByte(signature: Uint8Array): Uint8Array; } -export {};