Skip to content

Commit

Permalink
Merge pull request #41 from seanjameshan/fix/export-needed-types
Browse files Browse the repository at this point in the history
fix: export needed types
  • Loading branch information
janek26 authored Nov 3, 2021
2 parents 350008a + c51fe40 commit 4741bfe
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ellipticalCurve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ function fixMessage(msg: string) {

export const genKeyPair = ec.genKeyPair.bind(ec);

export function getKeyPair(pk: BigNumberish): EC.KeyPair {
export type KeyPair = EC.KeyPair;
export type Signature = EC.Signature;

export function getKeyPair(pk: BigNumberish): KeyPair {
const pkBn = toBN(pk);
return ec.keyFromPrivate(removeHexPrefix(toHex(pkBn)), 'hex');
}

export function getStarkKey(keyPair: EC.KeyPair): string {
export function getStarkKey(keyPair: KeyPair): string {
// this method needs to be run to generate the .pub property used below
// the result can be dumped
keyPair.getPublic(true, 'hex');
Expand All @@ -57,7 +60,7 @@ export function getStarkKey(keyPair: EC.KeyPair): string {
key should be an KeyPair with a valid private key.
Returns an Signature.
*/
export function sign(keyPair: EC.KeyPair, msgHash: string): EC.Signature {
export function sign(keyPair: KeyPair, msgHash: string): Signature {
const msgHashBN = toBN(addHexPrefix(msgHash));
// Verify message hash has valid length.
assertInRange(msgHashBN, ZERO, toBN(addHexPrefix(MAX_ECDSA_VAL)), 'msgHash');
Expand All @@ -77,7 +80,7 @@ export function sign(keyPair: EC.KeyPair, msgHash: string): EC.Signature {
msgSignature should be an Signature.
Returns a boolean true if the verification succeeds.
*/
export function verify(keyPair: EC.KeyPair, msgHash: string, sig: EC.Signature): boolean {
export function verify(keyPair: KeyPair, msgHash: string, sig: Signature): boolean {
const msgHashBN = toBN(addHexPrefix(msgHash));
assertInRange(msgHashBN, ZERO, toBN(addHexPrefix(MAX_ECDSA_VAL)), 'msgHash');
const { r, s } = sig;
Expand Down

0 comments on commit 4741bfe

Please sign in to comment.