Rename to Secp256k1Wallet

This commit is contained in:
Simon Warta 2020-10-27 13:41:54 +01:00
parent 04a74aac83
commit 2921c15ea0
3 changed files with 20 additions and 10 deletions

View File

@ -3,23 +3,23 @@ import { Secp256k1, Secp256k1Signature, Sha256 } from "@cosmjs/crypto";
import { fromBase64, fromHex } from "@cosmjs/encoding";
import { serializeSignDoc, StdSignDoc } from "./encoding";
import { Secp256k1Key } from "./secp256k1key";
import { Secp256k1Wallet } from "./secp256k1wallet";
describe("Secp256k1Key", () => {
describe("Secp256k1Wallet", () => {
const defaultPrivkey = fromHex("b8c462d2bb0c1a92edf44f735021f16c270f28ee2c3d1cb49943a5e70a3c763e");
const defaultAddress = "cosmos1kxt5x5q2l57ma2d434pqpafxdm0mgeg9c8cvtx";
const defaultPubkey = fromHex("03f146c27639179e5b67b8646108f48e1a78b146c74939e34afaa5414ad5c93f8a");
describe("fromPrivkey", () => {
it("works", async () => {
const signer = await Secp256k1Key.fromPrivkey(defaultPrivkey);
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
expect(signer).toBeTruthy();
});
});
describe("getAccounts", () => {
it("resolves to a list of accounts", async () => {
const signer = await Secp256k1Key.fromPrivkey(defaultPrivkey);
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
const accounts = await signer.getAccounts();
expect(accounts.length).toEqual(1);
expect(accounts[0]).toEqual({
@ -32,7 +32,7 @@ describe("Secp256k1Key", () => {
describe("sign", () => {
it("resolves to valid signature if enabled", async () => {
const signer = await Secp256k1Key.fromPrivkey(defaultPrivkey);
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
const signDoc: StdSignDoc = {
msgs: [],
fee: { amount: [], gas: "23" },

View File

@ -5,16 +5,21 @@ import { serializeSignDoc, StdSignDoc } from "./encoding";
import { encodeSecp256k1Signature } from "./signature";
import { AccountData, OfflineSigner, SignResponse } from "./signer";
export class Secp256k1Key implements OfflineSigner {
/**
* A wallet that holds a single secp256k1 keypair.
*
* If you want to work with BIP39 mnemonics and multiple accounts, use Secp256k1HdWallet.
*/
export class Secp256k1Wallet implements OfflineSigner {
/**
* Creates a Secp256k1 key signer from the given private key
*
* @param privkey The private key.
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
*/
public static async fromPrivkey(privkey: Uint8Array, prefix = "cosmos"): Promise<Secp256k1Key> {
public static async fromPrivkey(privkey: Uint8Array, prefix = "cosmos"): Promise<Secp256k1Wallet> {
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
return new Secp256k1Key(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
return new Secp256k1Wallet(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
}
private readonly pubkey: Uint8Array;

View File

@ -1,13 +1,18 @@
import { StdSignDoc } from "./encoding";
import { AccountData, OfflineSigner, SignResponse } from "./signer";
export declare class Secp256k1Key implements OfflineSigner {
/**
* A wallet that holds a single secp256k1 keypair.
*
* If you want to work with BIP39 mnemonics and multiple accounts, use Secp256k1HdWallet.
*/
export declare class Secp256k1Wallet implements OfflineSigner {
/**
* Creates a Secp256k1 key signer from the given private key
*
* @param privkey The private key.
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
*/
static fromPrivkey(privkey: Uint8Array, prefix?: string): Promise<Secp256k1Key>;
static fromPrivkey(privkey: Uint8Array, prefix?: string): Promise<Secp256k1Wallet>;
private readonly pubkey;
private readonly privkey;
private readonly prefix;