diff --git a/app/lib/common-libs/crypto/base58.ts b/app/lib/common-libs/crypto/base58.ts deleted file mode 100644 index af39dd46bbb14e9560b781d3a4ce197c20516bbd..0000000000000000000000000000000000000000 --- a/app/lib/common-libs/crypto/base58.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Source file from duniter: Crypto-currency software to manage libre currency such as Äž1 -// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com> -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -const bs58 = require('bs58') - -export const Base58encode = (bytes: Buffer) => bs58.encode(bytes) - -export const Base58decode = (data:any) => new Uint8Array(bs58.decode(data)) diff --git a/app/lib/common-libs/crypto/nacl-util.ts b/app/lib/common-libs/crypto/nacl-util.ts deleted file mode 100644 index b381860b101da1b28c527eeab18071088ee83d04..0000000000000000000000000000000000000000 --- a/app/lib/common-libs/crypto/nacl-util.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Source file from duniter: Crypto-currency software to manage libre currency such as Äž1 -// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com> -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. - -declare function escape(s:string): string; -declare function unescape(s:string): string; - -export const decodeUTF8 = function(s:string) { - let i, d = unescape(encodeURIComponent(s)), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; -} - -export const encodeUTF8 = function(arr:any[]) { - let i, s = []; - for (i = 0; i < arr.length; i++) s.push(String.fromCharCode(arr[i])); - return decodeURIComponent(escape(s.join(''))) -} - -export const encodeBase64 = function(arr:Uint8Array) { - if (typeof btoa === 'undefined' || !window) { - return (new Buffer(arr)).toString('base64'); - } else { - let i, s = [], len = arr.length; - for (i = 0; i < len; i++) s.push(String.fromCharCode(arr[i])); - return btoa(s.join('')); - } -} - -export const decodeBase64 = function(s:string) { - if (typeof atob === 'undefined' || !window) { - return new Uint8Array(Array.prototype.slice.call(new Buffer(s, 'base64'), 0)); - } else { - let i, d = atob(s), b = new Uint8Array(d.length); - for (i = 0; i < d.length; i++) b[i] = d.charCodeAt(i); - return b; - } -} \ No newline at end of file diff --git a/app/lib/common-libs/index.ts b/app/lib/common-libs/index.ts index 856bc80fb7eeb58b8e66ebd4ddbd66ebc4b9c7d3..ea6df33cb39e30b0d8206d7b242e4661172131fa 100644 --- a/app/lib/common-libs/index.ts +++ b/app/lib/common-libs/index.ts @@ -12,18 +12,11 @@ // GNU Affero General Public License for more details. import * as rawer from './rawer' -import {Base58decode, Base58encode} from "./crypto/base58" import {unlock as txunlock} from "./txunlock" import {hashf} from "../common"; -const base58 = { - decode: Base58decode, - encode: Base58encode -} - export { rawer, - base58, txunlock, hashf } diff --git a/package.json b/package.json index b785d1618e209f1e3b36ec63043e032244d8c957..78f4a05430ce5d5f97d8e33449880b2955230354 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "async": "2.2.0", "bindings": "1.2.1", "body-parser": "1.17.1", - "bs58": "^4.0.1", "child-process-promise": "^2.2.1", "cli-table": "^0.3.1", "colors": "1.1.2", diff --git a/test/fast/crypto/crypto.ts b/test/fast/crypto/crypto.ts index d5e2e388d7f48ef39de43eec40e5d07831cd295d..a1cf7df733dc4e227c5ea7cd5e05b5510598d05f 100644 --- a/test/fast/crypto/crypto.ts +++ b/test/fast/crypto/crypto.ts @@ -12,44 +12,27 @@ // GNU Affero General Public License for more details. "use strict"; -import {Base58decode, Base58encode} from "../../../app/lib/common-libs/crypto/base58" -import {decodeBase64, encodeBase64} from "../../../app/lib/common-libs/crypto/nacl-util" import {Key} from "../../../app/lib/common-libs/crypto/keyring" import {verify} from "duniteroxyde" const should = require('should'); -const enc = encodeBase64 -const dec = decodeBase64 - -let pub:Uint8Array, sec:Uint8Array, rawPub:string, rawSec:string +let rawPub:string, rawSec:string describe('ed25519 tests:', function(){ before(async () => { // Generate the keypair const keyPair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'); - pub = Base58decode(keyPair.publicKey); - sec = Base58decode(keyPair.secretKey); - rawPub = Base58encode(new Buffer(pub)); - rawSec = Base58encode(new Buffer(sec)); + rawPub = keyPair.publicKey; + rawSec = keyPair.secretKey; }) - //it('good signature from existing secret key should be verified', function(done){ - // const keys = nacl.sign.scryptKeyPair.fromSecretKey(dec("TM0Imyj/ltqdtsNG7BFOD1uKMZ81q6Yk2oz27U+4pvs9QBfD6EOJWpK3CqdNG368nJgszy7ElozAzVXxKvRmDA==")); - // const msg = "cg=="; - // const goodSig = dec("52Hh9omo9rxklulAE7gvVeYvAq0GgXYoZE2NB/gzehpCYIT04bMcGIs5bhYLaH93oib34jsVMWs9Udadr1B+AQ=="); - // const sig = crypto.signSync(msg, keys.secretKey); - // sig.should.equal(enc(goodSig)); - // crypto.verify(msg, sig, enc(keys.publicKey)).should.be.true; - // done(); - //}); - it('good signature from generated key should be verified', function(done){ const msg = "Some message to be signed"; const sig = new Key(rawPub, rawSec).signSync(msg); const verified = verify(msg, sig, rawPub); - verified.should.equal(true); + should(verified).equal(true); done(); }); @@ -57,7 +40,7 @@ describe('ed25519 tests:', function(){ const msg = "Some message to be signed"; const sig = new Key(rawPub, rawSec).signSync(msg); const verified = verify(msg + 'delta', sig, rawPub); - verified.should.equal(false); + should(verified).equal(false); done(); }); @@ -70,7 +53,7 @@ describe('ed25519 tests:', function(){ "Endpoints:\n" + "BASIC_MERKLED_API g1.duniter.org 10901\n" const verified = verify(msg, "u8t1IoWrB/C7T+2rS0rKYJfjPG4FN/HkKGFiUO5tILIzjFDvxxQiVC+0o/Vaz805SMmqJvXqornI71U7//+wCg==", "3AF7bhGQRt6ymcBZgZTBMoDsEtSwruSarjNG8kDnaueX"); - verified.should.equal(true); + should(verified).equal(true); done(); }); @@ -84,7 +67,7 @@ describe('ed25519 tests:', function(){ "BASIC_MERKLED_API g1.duniter.tednet.fr 37.187.0.204 8999\n" + "BMAS g1.duniter.tednet.fr 9000\n" const verified = verify(msg, "ImvQDdpGv2M6CxSnBuseM/azJhBUGzWVgQhIvb5L2oGLm2GyLk/Sbi5wkb4IjbjbQfdRPdlcx5zxaHhvZCiWAA==", "Com8rJukCozHZyFao6AheSsfDQdPApxQRnz7QYFf64mm"); - verified.should.equal(true); + should(verified).equal(true); done(); }); @@ -92,7 +75,7 @@ describe('ed25519 tests:', function(){ const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; const rawSig = "fJusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQAACs7OawDfpsV6cEMPcXxrQTCTRMrTN/rRrl20hN5zC9DQ=="; const verified = verify(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); - verified.should.equal(false); + should(verified).equal(false); done(); }); @@ -100,7 +83,7 @@ describe('ed25519 tests:', function(){ const msg = "InnerHash: 8B194B5C38CF0A38D16256405AC3E5FA5C2ABD26BE4DCC0C7ED5CC9824E6155B\nNonce: 30400000119992\n"; const rawSig = "aZusVDRJA8akPse/sv4uK8ekUuvTGj1OoKYVdMQQ/3+VMaDJ02I795GBBaLgjypZFEKYlPMssJMn/X+F/pxgAw=="; const verified = verify(msg, rawSig, "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx"); - verified.should.equal(true); + should(verified).equal(true); done(); }); }); diff --git a/test/fast/modules/common/common-crypto-test.ts b/test/fast/modules/common/common-crypto-test.ts index eb63628cac13700c052547fa378da79b8be130de..6b6b64390b3509a6017cbf0d5c07b4cff11d3262 100644 --- a/test/fast/modules/common/common-crypto-test.ts +++ b/test/fast/modules/common/common-crypto-test.ts @@ -13,7 +13,6 @@ import {Key} from "../../../../app/lib/common-libs/crypto/keyring" import {verify} from "duniteroxyde" -import {Base58decode, Base58encode} from "../../../../app/lib/common-libs/crypto/base58" const should = require('should'); @@ -24,10 +23,8 @@ describe('ed25519 tests:', function(){ before(async () => { // Generate the keypair const keyPair = new Key('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'); - pub = Base58decode(keyPair.publicKey); - sec = Base58decode(keyPair.secretKey); - rawPub = Base58encode(new Buffer(pub)); - rawSec = Base58encode(new Buffer(sec)); + rawPub = keyPair.publicKey; + rawSec = keyPair.secretKey; }) //it('good signature from existing secret key should be verified', function(done){ diff --git a/test/fast/modules/keypair/keypair-crypto-test.ts b/test/fast/modules/keypair/keypair-crypto-test.ts index 1424c649e671eec4885987c3de6bebad613b8595..7d9537fcf83805bdc5cc06b901a9f721e395e580 100644 --- a/test/fast/modules/keypair/keypair-crypto-test.ts +++ b/test/fast/modules/keypair/keypair-crypto-test.ts @@ -19,19 +19,19 @@ describe('Scrypt salt // key', () => { it('abc // abc', async () => { const pair = await Scrypt('abc', 'abc'); - pair.should.have.property('pub').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); - pair.should.have.property('sec').equal('51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'); + should(pair).have.property('pub').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); + should(pair).have.property('sec').equal('51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'); }) it('abc // def', async () => { const pair = await Scrypt('abc', 'def'); - pair.should.have.property('pub').equal('G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU'); - pair.should.have.property('sec').equal('58LDg8QLmF5pv6Dn9h7X4yFKfMTdP8fdAiWVcyDoTRJu454fwRihCLULH4MW37zncsg4ruoTGJPZneWk22QmG1w4'); + should(pair).have.property('pub').equal('G2CBgZBPLe6FSFUgpx2Jf1Aqsgta6iib3vmDRA1yLiqU'); + should(pair).have.property('sec').equal('58LDg8QLmF5pv6Dn9h7X4yFKfMTdP8fdAiWVcyDoTRJu454fwRihCLULH4MW37zncsg4ruoTGJPZneWk22QmG1w4'); }) it('azerty // def', async () => { const pair = await Scrypt('azerty', 'def'); - pair.should.have.property('pub').equal('3dbw4NYVEm5mwTH6bFrqBhan1k39qNHubkQWdrw2C5AD'); - pair.should.have.property('sec').equal('4kemdi17CPkkBPnjXiPFf6oBhdGiiqhCL3R4Tuafe9THK8mzBs1evHw5r9u3f8xts2zn6VCBJYVrRMzdaEaWn5Ch'); + should(pair).have.property('pub').equal('3dbw4NYVEm5mwTH6bFrqBhan1k39qNHubkQWdrw2C5AD'); + should(pair).have.property('sec').equal('4kemdi17CPkkBPnjXiPFf6oBhdGiiqhCL3R4Tuafe9THK8mzBs1evHw5r9u3f8xts2zn6VCBJYVrRMzdaEaWn5Ch'); }) }) diff --git a/yarn.lock b/yarn.lock index cf6c078c19ce6b710a618bd7ec72171d34ef66da..db292ef1566697f8931b3f39fc60a0e6b981ca34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -578,13 +578,6 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= -base-x@^3.0.2: - version "3.0.5" - resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.5.tgz#d3ada59afed05b921ab581ec3112e6444ba0795a" - integrity sha512-C3picSgzPSLE+jW3tcBzJoGwitOtazb5B+5YmAxZm2ybmTi9LNgAtDO/jjVEBZwHoXmDBZ9m/IELj3elJVRBcA== - dependencies: - safe-buffer "^5.0.1" - base64-js@^1.0.2: version "1.3.0" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3" @@ -737,13 +730,6 @@ browser-stdout@1.3.0: resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" integrity sha1-81HTKWnTL6XXpVZxVCY9korjvR8= -bs58@^4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" - integrity sha1-vhYedsNU9veIrkBx9j806MTwpCo= - dependencies: - base-x "^3.0.2" - buffer-alloc-unsafe@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz#bd7dc26ae2972d0eda253be061dba992349c19f0"