Convert Secp256k1Keypair to interface

This commit is contained in:
Simon Warta 2020-12-21 03:05:51 +01:00
parent fb49a6b4f5
commit 974412f60a
3 changed files with 6 additions and 10 deletions

View File

@ -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` types `sign` method renamed `signAmino`

View File

@ -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<Secp256k1Keypair> {
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

View File

@ -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<Secp256k1Keypair>;
static createSignature(messageHash: Uint8Array, privkey: Uint8Array): Promise<ExtendedSecp256k1Signature>;
@ -17,4 +15,3 @@ export declare class Secp256k1 {
static compressPubkey(pubkey: Uint8Array): Uint8Array;
static trimRecoveryByte(signature: Uint8Array): Uint8Array;
}
export {};