Comparing version 0.1.0 to 0.2.0
@@ -17,3 +17,3 @@ { | ||
}, | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A public-private key library for post-quantum cryptography (early stage, use with caution)", | ||
@@ -20,0 +20,0 @@ "bugs": { |
@@ -41,4 +41,4 @@ export type KeyPair = { | ||
* | ||
* @returns Whether the signature is valid. | ||
* @returns The signed message, or null if invalid. | ||
*/ | ||
export declare function verify(signature: string, publicKey: string): Promise<boolean>; | ||
export declare function verify(signature: string, publicKey: string): Promise<{message: string} | null>; |
@@ -227,5 +227,5 @@ import { ml_kem512 } from "@noble/post-quantum/ml-kem"; | ||
* | ||
* @returns Whether the signature is valid. | ||
* @returns The signed message, or null if invalid. | ||
*/ | ||
export async function verify(signature: string, publicKey: string): Promise<boolean> { | ||
export async function verify(signature: string, publicKey: string): Promise<{message: string} | null> { | ||
//extract and decode the public key | ||
@@ -245,9 +245,11 @@ const publicKeyEncoded = publicKey | ||
const message = new TextEncoder().encode(JSON.parse(Buffer.from(signature, "base64").toString("utf-8")).raw); | ||
const signatureArray = new Uint8Array(Buffer.from(JSON.parse(Buffer.from(signature, "base64").toString("utf-8")).sig, "base64")); | ||
const jp = JSON.parse(Buffer.from(signature, "base64").toString("utf-8")); | ||
const message = new TextEncoder().encode(jp.raw); | ||
const signatureArray = new Uint8Array(Buffer.from(jp.sig, "base64")); | ||
const isValid = await sign.verify(signatureArray, message, falconPublicKey); | ||
return isValid; | ||
return isValid ? {message: jp.raw} : null; | ||
} | ||
21650
295