Skip to content

Commit

Permalink
feat: deriveKeyPair to derive a keypair from a private key (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeverinAlexB authored Feb 2, 2024
1 parent 962be07 commit ffb5f77
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ln-verifymessagejs",
"version": "1.1.0",
"version": "1.2.0",
"description": "Signs/checks message signatures like core-lightning checkmessge or lnd signmessage.",
"repository": {
"type": "git",
Expand Down
24 changes: 22 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,19 @@ export interface IKeyPair {
}
}

export function generateKeyPair(): IKeyPair {
const privKey = secp.utils.randomPrivateKey()
/**
* Derive keypair from a private key.
* @param privateKey Hex or Uint8Array
* @returns IKeyPair
*/
export function deriveKeyPair(privateKey: string | Uint8Array): IKeyPair {
let privKey: Uint8Array;
if (typeof privateKey === 'string' || privateKey instanceof String) {
privKey = hexToBytes(privateKey as string)
} else {
privKey = privateKey;
}

const pubKey = secp.getPublicKey(privKey, true)
return {
privateKey: {
Expand All @@ -80,6 +91,15 @@ export function generateKeyPair(): IKeyPair {
}
}

/**
* Generate a new keypair
* @returns
*/
export function generateKeyPair(): IKeyPair {
const privKey = secp.utils.randomPrivateKey()
return deriveKeyPair(privKey)
}

/**
* Creates a double sha256
* @param value
Expand Down

0 comments on commit ffb5f77

Please sign in to comment.