Add Secp256k1Pen.address
This commit is contained in:
parent
091e60556d
commit
c70bf607c8
@ -28,7 +28,7 @@ describe("Sec256k1Pen", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("createSignature", () => {
|
||||
describe("sign", () => {
|
||||
it("creates correct signatures", async () => {
|
||||
const pen = await Secp256k1Pen.fromMnemonic(
|
||||
"special sign fit simple patrol salute grocery chicken wheat radar tonight ceiling",
|
||||
@ -44,4 +44,13 @@ describe("Sec256k1Pen", () => {
|
||||
expect(valid).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("address", () => {
|
||||
it("creates same address as Go imlementation", async () => {
|
||||
const pen = await Secp256k1Pen.fromMnemonic(
|
||||
"oyster design unusual machine spread century engine gravity focus cave carry slot",
|
||||
);
|
||||
expect(pen.address("cosmos")).toEqual("cosmos1cjsxept9rkggzxztslae9ndgpdyt2408lk850u");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
Slip10RawIndex,
|
||||
} from "@iov/crypto";
|
||||
|
||||
import { rawSecp256k1PubkeyToAddress } from "./address";
|
||||
import { encodeSecp256k1Signature } from "./signature";
|
||||
import { StdSignature } from "./types";
|
||||
|
||||
@ -84,4 +85,8 @@ export class Secp256k1Pen implements Pen {
|
||||
const fixedLengthSignature = new Uint8Array([...signature.r(32), ...signature.s(32)]);
|
||||
return encodeSecp256k1Signature(this.pubkey, fixedLengthSignature);
|
||||
}
|
||||
|
||||
public address(prefix: string): string {
|
||||
return rawSecp256k1PubkeyToAddress(this.pubkey, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
1
packages/sdk/types/pen.d.ts
vendored
1
packages/sdk/types/pen.d.ts
vendored
@ -29,4 +29,5 @@ export declare class Secp256k1Pen implements Pen {
|
||||
* Creates and returns a signature
|
||||
*/
|
||||
sign(signBytes: Uint8Array, prehashType?: PrehashType): Promise<StdSignature>;
|
||||
address(prefix: string): string;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user