From e769cd46467fc3fd5017f4c8713cdeb17dbd7a75 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sun, 15 Dec 2019 21:47:13 +0100 Subject: [PATCH] [fix] add new functions sign and verify that use upgraded tweetnacl --- app/lib/common-libs/crypto/keyring.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/lib/common-libs/crypto/keyring.ts b/app/lib/common-libs/crypto/keyring.ts index 778f2a3ba..a20eb7a41 100644 --- a/app/lib/common-libs/crypto/keyring.ts +++ b/app/lib/common-libs/crypto/keyring.ts @@ -63,6 +63,20 @@ export class Key { } return encodeBase64(sig) }; + + sign(msg:string) { + return Promise.resolve(this.signSync(msg)) + } + + signSync(msg:string) { + const m = decodeUTF8(msg); + const signedMsg = nacl.sign(m, this.rawSec()); + const sig = new Uint8Array(crypto_sign_BYTES); + for (let i = 0; i < sig.length; i++) { + sig[i] = signedMsg[i]; + } + return encodeBase64(sig) + }; } export function randomKey() { @@ -98,3 +112,16 @@ export function verifyBuggy(rawMsg:string, rawSig:string, rawPub:string) { // Call to verification lib... return naclBinding.verify(m, sm, pub); } + +/** + * Verify a signature against data & public key. + * Return true of false as callback argument. + */ +export function verify(rawMsg:string, rawSig:string, rawPub:string) { + const msg = decodeUTF8(rawMsg); + const sig = decodeBase64(rawSig); + const pub = Base58decode(rawPub); + + // Call to verification lib... + return nacl.sign.detached.verify(msg, sig, pub); +} -- GitLab