mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Rename to Secp256k1Wallet.fromKey
This commit is contained in:
parent
2921c15ea0
commit
0091d9a684
@ -10,16 +10,16 @@ describe("Secp256k1Wallet", () => {
|
|||||||
const defaultAddress = "cosmos1kxt5x5q2l57ma2d434pqpafxdm0mgeg9c8cvtx";
|
const defaultAddress = "cosmos1kxt5x5q2l57ma2d434pqpafxdm0mgeg9c8cvtx";
|
||||||
const defaultPubkey = fromHex("03f146c27639179e5b67b8646108f48e1a78b146c74939e34afaa5414ad5c93f8a");
|
const defaultPubkey = fromHex("03f146c27639179e5b67b8646108f48e1a78b146c74939e34afaa5414ad5c93f8a");
|
||||||
|
|
||||||
describe("fromPrivkey", () => {
|
describe("fromKey", () => {
|
||||||
it("works", async () => {
|
it("works", async () => {
|
||||||
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
|
const signer = await Secp256k1Wallet.fromKey(defaultPrivkey);
|
||||||
expect(signer).toBeTruthy();
|
expect(signer).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getAccounts", () => {
|
describe("getAccounts", () => {
|
||||||
it("resolves to a list of accounts", async () => {
|
it("resolves to a list of accounts", async () => {
|
||||||
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
|
const signer = await Secp256k1Wallet.fromKey(defaultPrivkey);
|
||||||
const accounts = await signer.getAccounts();
|
const accounts = await signer.getAccounts();
|
||||||
expect(accounts.length).toEqual(1);
|
expect(accounts.length).toEqual(1);
|
||||||
expect(accounts[0]).toEqual({
|
expect(accounts[0]).toEqual({
|
||||||
@ -32,7 +32,7 @@ describe("Secp256k1Wallet", () => {
|
|||||||
|
|
||||||
describe("sign", () => {
|
describe("sign", () => {
|
||||||
it("resolves to valid signature if enabled", async () => {
|
it("resolves to valid signature if enabled", async () => {
|
||||||
const signer = await Secp256k1Wallet.fromPrivkey(defaultPrivkey);
|
const signer = await Secp256k1Wallet.fromKey(defaultPrivkey);
|
||||||
const signDoc: StdSignDoc = {
|
const signDoc: StdSignDoc = {
|
||||||
msgs: [],
|
msgs: [],
|
||||||
fee: { amount: [], gas: "23" },
|
fee: { amount: [], gas: "23" },
|
||||||
|
@ -12,12 +12,12 @@ import { AccountData, OfflineSigner, SignResponse } from "./signer";
|
|||||||
*/
|
*/
|
||||||
export class Secp256k1Wallet implements OfflineSigner {
|
export class Secp256k1Wallet implements OfflineSigner {
|
||||||
/**
|
/**
|
||||||
* Creates a Secp256k1 key signer from the given private key
|
* Creates a Secp256k1Wallet from the given private key
|
||||||
*
|
*
|
||||||
* @param privkey The private key.
|
* @param privkey The private key.
|
||||||
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
|
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
|
||||||
*/
|
*/
|
||||||
public static async fromPrivkey(privkey: Uint8Array, prefix = "cosmos"): Promise<Secp256k1Wallet> {
|
public static async fromKey(privkey: Uint8Array, prefix = "cosmos"): Promise<Secp256k1Wallet> {
|
||||||
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
const uncompressed = (await Secp256k1.makeKeypair(privkey)).pubkey;
|
||||||
return new Secp256k1Wallet(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
|
return new Secp256k1Wallet(privkey, Secp256k1.compressPubkey(uncompressed), prefix);
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ import { AccountData, OfflineSigner, SignResponse } from "./signer";
|
|||||||
*/
|
*/
|
||||||
export declare class Secp256k1Wallet implements OfflineSigner {
|
export declare class Secp256k1Wallet implements OfflineSigner {
|
||||||
/**
|
/**
|
||||||
* Creates a Secp256k1 key signer from the given private key
|
* Creates a Secp256k1Wallet from the given private key
|
||||||
*
|
*
|
||||||
* @param privkey The private key.
|
* @param privkey The private key.
|
||||||
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
|
* @param prefix The bech32 address prefix (human readable part). Defaults to "cosmos".
|
||||||
*/
|
*/
|
||||||
static fromPrivkey(privkey: Uint8Array, prefix?: string): Promise<Secp256k1Wallet>;
|
static fromKey(privkey: Uint8Array, prefix?: string): Promise<Secp256k1Wallet>;
|
||||||
private readonly pubkey;
|
private readonly pubkey;
|
||||||
private readonly privkey;
|
private readonly privkey;
|
||||||
private readonly prefix;
|
private readonly prefix;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user