Skip to content
Snippets Groups Projects
Commit f66bd413 authored by Millicent Billette's avatar Millicent Billette
Browse files

nearly publishable

parent 51b870d5
No related branches found
No related tags found
No related merge requests found
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_size = 2
charset = utf-8
[*.{yml,yaml}]
indent_style = space
*.log*
*generated*
generated/
node_modules/
.idea/
*.exe
*.log
const fs = require("fs");
try{fs.writeFileSync("generated/vendors/nacl.js",(fs.readFileSync("node_modules/tweetnacl/nacl-fast.js","utf8"))
.replace("(function(nacl) {","var nacl = {};")
.replace("})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {}));","export default nacl;")
,"utf8");} catch (e) {console.error(e);}
const fs = require('fs');
try {
fs.writeFileSync('generated/vendors/nacl.mjs',
(fs.readFileSync('node_modules/tweetnacl/nacl-fast.js', 'utf8'))
.replace('(function(nacl) {', 'var nacl = {};')
.replace('})(typeof module !== \'undefined\' && module.exports ? module.exports : (self.nacl = self.nacl || {}));', 'export default nacl;')
, 'utf8');
} catch (error) {
console.error(error);
}
try{fs.writeFileSync("generated/vendors/scrypt.js",(fs.readFileSync("node_modules/scrypt-async-modern/dist/index.js","utf8"))
.replace("exports.default = scrypt;","export default scrypt;")
.replace(`Object.defineProperty(exports, "__esModule", { value: true });`,"")
,"utf8");} catch (e) {console.error(e);}
try {
fs.writeFileSync('generated/vendors/scrypt.mjs',
(fs.readFileSync('node_modules/scrypt-async-modern/dist/index.js', 'utf8'))
.replace('exports.default = scrypt;', 'export default scrypt;')
.replace('Object.defineProperty(exports, "__esModule", { value: true });', '')
, 'utf8');
} catch (error) {
console.error(error);
}
......@@ -21,7 +21,12 @@
},
"license": "AGPL-3.0",
"ava": {},
"nyc": {
"c8": {
"all": true,
"branches": 0.080,
"lines": 0.080,
"functions": 0.080,
"statements": 0.080,
"report-dir": "../coverage",
"temp-dir": "../nyc_output.temp",
"reporter": [
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -16,14 +16,14 @@
"test:dev": "run-p test:dev:**",
"test:dev:qualityCheck": "xo",
"test:dev:runTests": "ava",
"test:dev:duplication": "jscpd",
"test:dev:duplication": "jscpd ./ -s",
"test:production": "run-s test:production:**",
"test:production:qualityCheck": "xo",
"test:production:duplication": "jscpd",
"test:production:complexity-report": "./node_modules/.bin/es6-plato -r -d generated/complexity-report src",
"test:production:test2npm": "cp src/*.test.js generated/npm/",
"test:production:runTests": "cd generated/npm/ && nyc ava",
"test:production:clean": "rm generated/npm/*.test.js"
"test:production:duplication": "jscpd ./",
"xtest:production:complexity-report": "./node_modules/.bin/es6-plato -r -d generated/plato-complexity-report ./**/*.mjs",
"test:production:test2npm": "cp src/*.test.mjs generated/npm/",
"test:production:runTests": "cd generated/npm/ && c8 ava",
"test:production:clean": "rm generated/npm/*.test.mjs"
},
"dependencies": {
"scrypt-async-modern": "^3.0.12",
......@@ -31,18 +31,45 @@
},
"devDependencies": {
"ava": "^3.14.0",
"es6-plato": "^1.2.3",
"jscpd": "^3.3.22",
"jscpd-badge-reporter": "^1.1.3",
"mkdirp": "^1.0.4",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"c8": "^7.3.5",
"rollup": "^2.34.2",
"xo": "^0.36.1"
},
"ava": {},
"disabledDependenciesTODOAddComplexityQualityCheck": {
"es6-plato": "^1.2.3",
"code-forensics": "^2.3.1",
"codehawk-cli": "^6.0.3"
},
"ava": {},
"jscpd": {
"threshold": 0.1,
"reporters": ["html", "console", "badge"],
"reporters": [
"html",
"console",
"badge"
],
"formatsExts": {
"javascript": [
"js",
"mjs",
"es6"
],
"json": [
"json"
],
"yaml": [
"yml",
"yaml"
],
"markdown": [
"md"
]
},
"gitignore": true,
"output": "generated/jscpd/"
}
......
export {b58,b16, saltPass2seed, seed2keyPair,idSecPass2rawAll, raw2b58, idSecPass2cleanKeys}
import nacl from "../generated/vendors/nacl.js";
import scrypt from "../generated/vendors/scrypt.js";
import nacl from "../generated/vendors/nacl.mjs";
import scrypt from "../generated/vendors/scrypt.mjs";
async function idSecPass2rawAll(idSec,pass) {
const rawSeed = await saltPass2seed(idSec,pass);
......
const idSec = "a";
const mdp = "b";
//base58
const pubKey = "AoxVA41dGL2s4ogMNdbCw3FFYjFo5FPK36LuiW1tjGbG";
const secretKey = "3ZsmZhnRv137dS1s7Q3jFGKLTDyhkwguPHfnWBxzDCTTHKWGnYw9zBk3gcCUJCc72TEUuyzM7cqpo7c5LYhs1Qtv";
const seed = "9eADqX8V6VcPdJCHCVYiE1Vnift9nFNrvr9aTaXA5RJc";
import * as app from "./crypto.mjs";
describe('crypto', () => {
it('b58 should decode/encode well', () => {
expect(app.b58.encode(app.b58.decode(pubKey))).toEqual(pubKey);
});
it('saltPass2seed should convert salt & password to seed with scrypt', async () => {
expect(app.b58.encode(await app.saltPass2seed(idSec,mdp))).toEqual(seed);
});
it('seed2keyPair should generate public and private key nacl/sodium way.', async () => {
const rawSeed = app.b58.decode(seed);
const rawKeyPair = app.seed2keyPair(rawSeed);
expect(app.b58.encode(rawKeyPair.publicKey)).toEqual(pubKey);
expect(app.b58.encode(rawKeyPair.secretKey)).toEqual(secretKey);
});
it('idSecPass2cleanKeys should output clean base58 keys and seed', async () => {
const res = await app.idSecPass2cleanKeys(idSec,mdp);
expect(res.publicKey).toEqual(pubKey);
expect(res.secretKey).toEqual(secretKey);
expect(res.seed).toEqual(seed);
expect(res.idSec).toEqual(idSec);
expect(res.password).toEqual(mdp);
});
});
import test from 'ava';
import * as app from "./crypto.mjs";
const idSec = "a";
const mdp = "b";
//base58
const pubKey = "AoxVA41dGL2s4ogMNdbCw3FFYjFo5FPK36LuiW1tjGbG";
const secretKey = "3ZsmZhnRv137dS1s7Q3jFGKLTDyhkwguPHfnWBxzDCTTHKWGnYw9zBk3gcCUJCc72TEUuyzM7cqpo7c5LYhs1Qtv";
const seed = "9eADqX8V6VcPdJCHCVYiE1Vnift9nFNrvr9aTaXA5RJc";
test('b58 should decode/encode well', t => {
t.is(app.b58.encode(app.b58.decode(pubKey)), pubKey);
});
test('saltPass2seed should convert salt & password to seed with scrypt', async t => {
t.is(app.b58.encode(await app.saltPass2seed(idSec, mdp)), seed);
});
test('seed2keyPair should generate public and private key nacl/sodium way.', async t => {
const rawSeed = app.b58.decode(seed);
const rawKeyPair = app.seed2keyPair(rawSeed);
t.is(app.b58.encode(rawKeyPair.publicKey), pubKey);
t.is(app.b58.encode(rawKeyPair.secretKey), secretKey);
});
test('idSecPass2cleanKeys should output clean base58 keys and seed', async t => {
const res = await app.idSecPass2cleanKeys(idSec, mdp);
t.is(res.publicKey, pubKey);
t.is(res.secretKey, secretKey);
t.is(res.seed, seed);
t.is(res.idSec, idSec);
t.is(res.password, mdp);
});
import * as app from "./dictionaryBuilder.mjs";
describe('dictionaryBuilder', () => {
beforeEach(app.resetCache);
it('add no accents variant', () => {
expect(app.noAccentVariant("Ǧ1")).toEqual(["Ǧ1","G1"]);
});
it('add case variants', () => {
expect(app.casesVariants("moT")).toEqual(["moT","mot","Mot","MOT"]);
});
it('add multi word case variants', () => {
expect(app.casesVariants("autre mot")).toEqual(["autre mot","Autre Mot","AUTRE MOT"]);
});
it('regLikeVariants remove ref:: lines', () => {
expect(app.regLikeVariants("ref::truc")).toEqual([]);
});
it('regLikeVariants handle <ref>', () => {
expect(app.regLikeVariants("<ref> <ref>",["ref::truc","ref::bidule","<ref> <ref>"])).toEqual(["truc truc","bidule truc", "truc bidule", "bidule bidule"]);
expect(app.regLikeVariants("<ref> <ref>",["ref::(truc|bidule)","<ref> <ref>"])).toEqual(["truc truc","bidule truc", "truc bidule", "bidule bidule"]);
});
it('regLikeVariants handle =ref>', () => {
expect(app.regLikeVariants("=ref> =ref>",["ref::truc","ref::bidule","=ref> =ref>"])).toEqual(["truc truc","bidule bidule"]);
expect(app.regLikeVariants("=ref> =ref>",["ref::(truc|bidule)","=ref> =ref>"])).toEqual(["truc truc","bidule bidule"]);
});
it('regLikeVariants handle multiple =ref>', () => {
expect(app.regLikeVariants("=ref> =ref2> =ref> =ref2>",
["ref::(truc|bidule)","ref2::(machin|chose)","=ref> =ref>"]
)).toEqual(["truc machin truc machin","bidule machin bidule machin","truc chose truc chose","bidule chose bidule chose"]);
});
it('regLikeVariants handle (this|that)', () => {
expect(app.regLikeVariants("(this|that)")).toEqual(["this","that"]);
});
it('regLikeVariants handle [ -_]', () => {
expect(app.regLikeVariants("[ -_]")).toEqual([" ","-","_"]);
});
it('regLikeVariants handle [a-f]', () => {
expect(app.regLikeVariants("[a-f]")).toEqual(["a","b","c","d","e","f"]);
expect(app.regLikeVariants("[7-9]")).toEqual(["7","8","9"]);
expect(app.regLikeVariants("[C-F]")).toEqual(["C","D","E","F"]);
});
it('regLikeVariants handle [a-c-]', () => {
expect(app.regLikeVariants("[a-c-]")).toEqual(["a","b","c","-"]);
});
it('regLikeVariants handle {qty}', () => {
expect(app.regLikeVariants("a{5}")).toEqual(["aaaaa"]);
});
it('regLikeVariants handle {min,max}', () => {
expect(app.regLikeVariants("b{3,5}")).toEqual(["bbb","bbbb","bbbbb"]);
});
it('regLikeVariants handle (string){qty}', () => {
expect(app.regLikeVariants("c'est (toto|tata){0,2}")).toEqual(["c'est ","c'est toto","c'est totototo","c'est tata","c'est tatatoto","c'est tototata","c'est tatatata"]);
});
it('regLikeVariants handle nested -([a-f]|<ref>){0,1}', () => {
expect(app.regLikeVariants("-([B-D]|<ref>){0,1}",["ref::plop"])).toEqual(["-","-B","-plop","-C","-D"]);
});
it('regLikeVariants handle plop:\\:', () => {
expect(app.regLikeVariants("plop:\\:ici")).toEqual(["plop::ici"]);
expect(app.regLikeVariants("plop\\::ici")).toEqual(["plop::ici"]);
expect(app.regLikeVariants("plop::ici")).toEqual([]);
});
it('regLikeVariants handle [\\]*]', () => {
expect(app.regLikeVariants("[\\]*]")).toEqual(["]","*"]);
});
});
import test from 'ava';
import * as app from "./dictionaryBuilder.mjs";
test.beforeEach(app.resetCache);
test('add no accents variant', t => {
t.deepEqual(app.noAccentVariant("Ǧ1") , ["Ǧ1", "G1"]);
});
test('add case variants', t => {
t.deepEqual(app.casesVariants("moT") , ["moT", "mot", "Mot", "MOT"]);
});
test('add multi word case variants', t => {
t.deepEqual(app.casesVariants("autre mot") , ["autre mot", "Autre Mot", "AUTRE MOT"]);
});
test('regLikeVariants remove ref:: lines', t => {
t.deepEqual(app.regLikeVariants("ref::truc") , []);
});
test('regLikeVariants handle <ref>', t => {
t.deepEqual(app.regLikeVariants("<ref> <ref>", ["ref::truc", "ref::bidule", "<ref> <ref>"]) , ["truc truc", "bidule truc", "truc bidule", "bidule bidule"]);
t.deepEqual(app.regLikeVariants("<ref> <ref>", ["ref::(truc|bidule)", "<ref> <ref>"]) , ["truc truc", "bidule truc", "truc bidule", "bidule bidule"]);
});
test('regLikeVariants handle =ref>', t => {
t.deepEqual(app.regLikeVariants("=ref> =ref>", ["ref::truc", "ref::bidule", "=ref> =ref>"]) , ["truc truc", "bidule bidule"]);
t.deepEqual(app.regLikeVariants("=ref> =ref>", ["ref::(truc|bidule)", "=ref> =ref>"]) , ["truc truc", "bidule bidule"]);
});
test('regLikeVariants handle multiple =ref>', t => {
t.deepEqual(
app.regLikeVariants("=ref> =ref2> =ref> =ref2>",["ref::(truc|bidule)", "ref2::(machin|chose)", "=ref> =ref>"]),
["truc machin truc machin", "bidule machin bidule machin", "truc chose truc chose", "bidule chose bidule chose"]);
});
test('regLikeVariants handle (this|that)', t => {
t.deepEqual(app.regLikeVariants("(this|that)") , ["this", "that"]);
});
test('regLikeVariants handle [ -_]', t => {
t.deepEqual(app.regLikeVariants("[ -_]") , [" ", "-", "_"]);
});
test('regLikeVariants handle [a-f]', t => {
t.deepEqual(app.regLikeVariants("[a-f]") , ["a", "b", "c", "d", "e", "f"]);
t.deepEqual(app.regLikeVariants("[7-9]") , ["7", "8", "9"]);
t.deepEqual(app.regLikeVariants("[C-F]") , ["C", "D", "E", "F"]);
});
test('regLikeVariants handle [a-c-]', t => {
t.deepEqual(app.regLikeVariants("[a-c-]") , ["a", "b", "c", "-"]);
});
test('regLikeVariants handle {qty}', t => {
t.deepEqual(app.regLikeVariants("a{5}") , ["aaaaa"]);
});
test('regLikeVariants handle {min,max}', t => {
t.deepEqual(app.regLikeVariants("b{3,5}") , ["bbb", "bbbb", "bbbbb"]);
});
test('regLikeVariants handle (string){qty}', t => {
t.deepEqual(app.regLikeVariants("c'est (toto|tata){0,2}") , ["c'est ", "c'est toto", "c'est totototo", "c'est tata", "c'est tatatoto", "c'est tototata", "c'est tatatata"]);
});
test.serial('regLikeVariants handle nested -([a-f]|<ref>){0,1}', t => {
t.deepEqual(
app.regLikeVariants("-([B-D]|<ref>){0,1}", ["ref::plop"]),
["-", "-B", "-plop", "-C", "-D"]);
});
test('regLikeVariants handle plop:\\:', t => {
t.deepEqual(app.regLikeVariants("plop:\\:ici") , ["plop::ici"]);
t.deepEqual(app.regLikeVariants("plop\\::ici") , ["plop::ici"]);
t.deepEqual(app.regLikeVariants("plop::ici") , []);
});
test('regLikeVariants handle [\\]*]', t => {
t.deepEqual(app.regLikeVariants("[\\]*]") , ["]", "*"]);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment