Skip to content
Snippets Groups Projects
Commit efb1a188 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] replace `naclb` by `sodium` #1371

parent c3c5bdc6
No related branches found
No related tags found
No related merge requests found
......@@ -4,8 +4,8 @@ node_modules/
npm-debug.log
bin/jpgp*.jar
.idea/
naclb/build
naclb/node_modules
sodium/build
sodium/node_modules
gui/nw
# Vim swap files
......
......@@ -4,8 +4,8 @@ node_modules/
npm-debug.log
bin/jpgp*.jar
.idea/
naclb/build
naclb/node_modules
sodium/build
sodium/node_modules
gui/nw
# Vim swap files
......
......@@ -16,7 +16,7 @@ import {decodeBase64, decodeUTF8, encodeBase64} from "./nacl-util"
const nacl = require('tweetnacl');
const seedrandom = require('seedrandom');
const naclBinding = require('naclb');
const sodium = require('sodium');
const crypto_sign_BYTES = 64;
......@@ -43,6 +43,10 @@ export class Key {
return Base58decode(this.secretKey)
}
private rawPub() {
return Base58decode(this.publicKey)
}
json() {
return {
pub: this.publicKey,
......@@ -55,8 +59,9 @@ export class Key {
}
signSync(msg:string) {
const m = decodeUTF8(msg);
const signedMsg = naclBinding.sign(m, this.rawSec());
const key = new sodium.Key.Sign(encodeBase64(this.rawPub()), encodeBase64(this.rawSec()), 'base64')
const signer = new sodium.Sign(key)
const signedMsg = signer.sign(msg, 'utf8').sign;
const sig = new Uint8Array(crypto_sign_BYTES);
for (let i = 0; i < sig.length; i++) {
sig[i] = signedMsg[i];
......@@ -89,12 +94,9 @@ export function verify(rawMsg:string, rawSig:string, rawPub:string) {
const msg = decodeUTF8(rawMsg);
const sig = decodeBase64(rawSig);
const pub = Base58decode(rawPub);
const m = new Uint8Array(crypto_sign_BYTES + msg.length);
const sm = new Uint8Array(crypto_sign_BYTES + msg.length);
let i;
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
// Call to verification lib...
return naclBinding.verify(m, sm, pub);
return sig.length === 64 && sodium.Sign.verifyDetached({
sign: sig,
publicKey: pub
}, msg);
}
This diff is collapsed.
......@@ -85,7 +85,6 @@
"moment": "2.19.3",
"morgan": "1.9.1",
"multimeter": "0.1.1",
"naclb": "1.3.11",
"nat-upnp": "^1.1.1",
"node-pre-gyp": "0.6.34",
"node-uuid": "1.4.8",
......@@ -97,6 +96,7 @@
"seedrandom": "3.0.1",
"sha1": "1.1.1",
"socks-proxy-agent": "4.0.2",
"sodium": "^3.0.2",
"sqlite3": "4.0.6",
"tail": "^2.0.2",
"tweetnacl": "0.14.3",
......
......@@ -76,7 +76,6 @@ echo $SRC
rm -Rf node_modules/duniter-ui/node_modules
# Because we are building in a VM, Node.js could not detect that the target is ARM. So we move the modules' binaries accordingly.
#mv node_modules/naclb/lib/binding/Release/node-v48-linux-x64 node_modules/naclb/lib/binding/Release/node-v48-linux-arm
#mv node_modules/wotb/lib/binding/Release/node-v48-linux-x64 node_modules/wotb/lib/binding/Release/node-v48-linux-arm
#mv node_modules/sqlite3/lib/binding/Release/node-v48-linux-x64 node_modules/sqlite3/lib/binding/Release/node-v48-linux-arm
......
......@@ -203,7 +203,7 @@ node-pre-gyp --runtime=node-webkit --target=$NW_VERSION configure \
cd "${RELEASES}/desktop_/node_modules/"
nw_compile wotb nw_copy
nw_compile naclb nw_copy
nw_compile sodium nw_copy
nw_compile leveldown nw_copy "build/Release/"
nw_compile sqlite3 nw_copy_node
......
......@@ -86,11 +86,11 @@ call node-pre-gyp --runtime=node-webkit --target=%NW_VERSION% --msvs_version=201
call node-pre-gyp --runtime=node-webkit --target=%NW_VERSION% --msvs_version=2015 configure
call node-pre-gyp --runtime=node-webkit --target=%NW_VERSION% --msvs_version=2015 build
copy %cd%\lib\binding\Release\node-webkit-%NW_RELEASE%-win32-x64\wotb.node %cd%\lib\binding\Release\node-v%ADDON_VERSION%-win32-x64\wotb.node /Y
cd ../naclb
cd ../sodium
call npm install --build-from-source
call node-pre-gyp --runtime=node-webkit --target=%NW_VERSION% --msvs_version=2015 configure
call node-pre-gyp --runtime=node-webkit --target=%NW_VERSION% --msvs_version=2015 build
copy %cd%\lib\binding\Release\node-webkit-%NW_RELEASE%-win32-x64\naclb.node %cd%\lib\binding\Release\node-v%ADDON_VERSION%-win32-x64\naclb.node /Y
copy %cd%\lib\binding\Release\node-webkit-%NW_RELEASE%-win32-x64\naclb.node %cd%\lib\binding\Release\node-v%ADDON_VERSION%-win32-x64\sodium.node /Y
cd ../leveldown
call npm install --build-from-source
echo "Patch de leveldown..."
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment