Implement signature

This commit is contained in:
2024-06-06 01:50:26 +02:00
parent 1f8ff50fd3
commit 4d9aaa2619
+21
View File
@@ -0,0 +1,21 @@
import logger from 'log'
import * as ed from '@noble/ed25519'
const log = logger('crypto:signature')
export async function gen_privkey() : Promise<Uint8Array> {
log.trace("generate keypair")
return ed.utils.randomPrivateKey()
}
export async function get_pubkey(privkey: Uint8Array) : Promise<Uint8Array> {
log.trace("derive pubky")
return ed.getPublicKeyAsync(privkey)
}
export async function sign(message: Uint8Array, privkey: Uint8Array) : Promise<Uint8Array> {
log.trace("sign")
return ed.signAsync(message, privkey)
}
export async function verify(message: Uint8Array, pubkey: Uint8Array, signature: Uint8Array) : Promise<boolean> {
log.trace("verify")
return ed.verifyAsync(signature, message, pubkey)
}