Browse Source

Minor arrangement

pull/2/head
Jør∂¡ 3 years ago
parent
commit
1fb63cb385
1 changed files with 10 additions and 8 deletions
  1. +10
    -8
      src/index.ts

+ 10
- 8
src/index.ts

@ -37,14 +37,6 @@ export function decodePoint(hexPoint: string): Point {
return secp256k1.keyFromPublic(Buffer.from(hexPoint, "hex")).getPublic() return secp256k1.keyFromPublic(Buffer.from(hexPoint, "hex")).getPublic()
} }
function random(bytes: number) {
let k: BigNumber
do {
k = new BigNumber(randomBytes(bytes))
} while (k.toString() == "0" && k.gcd(n).toString() != "1")
return k
}
export function newKeyPair() { export function newKeyPair() {
const sk = random(32) const sk = random(32)
return { sk: sk, pk: G.mul(sk) } return { sk: sk, pk: G.mul(sk) }
@ -141,6 +133,16 @@ export function signatureFromHex(hexSignature: string): UnblindedSignature {
return { s, f } return { s, f }
} }
// HELPERS
function random(bytes: number) {
let k: BigNumber
do {
k = new BigNumber(randomBytes(bytes))
} while (k.toString() == "0" && k.gcd(n).toString() != "1")
return k
}
function zeroPad(hexString: string, byteLength: number) { function zeroPad(hexString: string, byteLength: number) {
if (hexString.length > (byteLength * 2)) throw new Error("Out of bounds") if (hexString.length > (byteLength * 2)) throw new Error("Out of bounds")
while (hexString.length < (byteLength * 2)) { while (hexString.length < (byteLength * 2)) {

Loading…
Cancel
Save