signature : Change lib to allow import from password
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
This commit is contained in:
+26
-10
@@ -2,25 +2,40 @@ import {test, expect} from 'bun:test'
|
||||
|
||||
import {signature} from '../index'
|
||||
|
||||
test('base case', async () => {
|
||||
let keypair = await signature.gen_keypair()
|
||||
async function base_case(keypair: signature.KeyPair) {
|
||||
let data = new TextEncoder().encode("Message 123 !")
|
||||
|
||||
const sig = (await signature.sign(keypair[0], data)).expect("Should sign the message")
|
||||
let verification = await signature.verify(keypair[1], data, sig)
|
||||
|
||||
expect(verification).toBe(true)
|
||||
}
|
||||
async function inverted(keypair: signature.KeyPair) {
|
||||
let data = new TextEncoder().encode("Message 123 !")
|
||||
|
||||
const sig = (await signature.sign(keypair[1], data)).expect("Should sign the message")
|
||||
let verification = await signature.verify(keypair[0], data, sig)
|
||||
expect(verification).toBe(false)
|
||||
}
|
||||
|
||||
test('base case', async () => {
|
||||
let keypair = await signature.gen_keypair()
|
||||
return base_case(keypair)
|
||||
})
|
||||
|
||||
test('base case with password', async () => {
|
||||
let keypair = await signature.from_password("Yeet", new Uint8Array(16))
|
||||
return base_case(keypair)
|
||||
})
|
||||
|
||||
test('inverted with password', async () => {
|
||||
let keypair = await signature.from_password("Yeet", new Uint8Array(16))
|
||||
return inverted(keypair)
|
||||
})
|
||||
|
||||
test('inverted keys', async () => {
|
||||
let keypair = await signature.gen_keypair()
|
||||
let data = new TextEncoder().encode("Message 123 !")
|
||||
|
||||
;(await signature.sign(keypair[1], data)).expect_err("Shouldn't sign the message with the wrong key")
|
||||
|
||||
const sig = (await signature.sign(keypair[0], data)).expect("Should sign the message")
|
||||
let verification = await signature.verify(keypair[0], data, sig)
|
||||
expect(verification).toBe(false)
|
||||
return inverted(keypair)
|
||||
})
|
||||
|
||||
test('tampered message', async () => {
|
||||
@@ -51,7 +66,8 @@ test('tampered signature', async () => {
|
||||
let data = new TextEncoder().encode("Message 123 !")
|
||||
|
||||
const sig = (await signature.sign(keypair[0], data)).expect("Should sign the message")
|
||||
let verification = await signature.verify(keypair[1], data, sig.slice(0, -1))
|
||||
sig[0] ^= 1
|
||||
let verification = await signature.verify(keypair[1], data, sig)
|
||||
|
||||
expect(verification).toBe(false)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user