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

v3.2.0 :

ADD : CheckKey
FIX : B64
parent 821c151a
No related branches found
No related tags found
No related merge requests found
Pipeline #14798 failed
...@@ -13,9 +13,12 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0 ...@@ -13,9 +13,12 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0
## [Non-publié/Non-Stabilisé] (par [1000i100]) ## [Non-publié/Non-Stabilisé] (par [1000i100])
## [Version 3.2.0] - 2022-01-31 (par [1000i100])
### Ajouté ### Ajouté
- crypto.checkKey(pubKeyWithChecksum) - crypto.checkKey(pubKeyWithChecksum)
- crypto.pubKey2checksum(b58pubKey, optionalBool:b58viewDependant, optionalBool:checksumWithoutLeadingZero) - EXPERIMENTAL : crypto.pubKey2checksum(b58pubKey, optionalBool:b58viewDependant, optionalBool:checksumWithoutLeadingZero) ATTENTION, la syntaxe pourrait changer selon ce qui est choisi comme algo de checksum recommandé dans les spec.
### Corrections
- correction des encodage et décodage base64 désormais conforme à la RFC 4648 §4 (standard le plus répandu)
## [Version 3.1.0] - 2021-04-01 (par [1000i100] & [Hugo]) ## [Version 3.1.0] - 2021-04-01 (par [1000i100] & [Hugo])
### Ajouté ### Ajouté
...@@ -71,8 +74,9 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0 ...@@ -71,8 +74,9 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0
- intégration des librairies de crypto nécessaires - intégration des librairies de crypto nécessaires
- calcul de la clef publique correspondant à chaque combinaison de secrets saisie, et comparaison à la clef publique de référence. - calcul de la clef publique correspondant à chaque combinaison de secrets saisie, et comparaison à la clef publique de référence.
[Non-publié/Non-Stabilisé]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.1.0...master [Non-publié/Non-Stabilisé]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.2.0...master
[Version 3.2.0]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.1.0...v3.2.0
[Version 3.1.0]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.3...v3.1.0 [Version 3.1.0]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.3...v3.1.0
[Version 3.0.2]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.1...v3.0.2 [Version 3.0.2]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.1...v3.0.2
[Version 3.0.1]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.0...v3.0.1 [Version 3.0.1]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.0.0...v3.0.1
......
{ {
"name": "g1lib", "name": "g1lib",
"version": "3.1.0", "version": "3.1.1",
"description": "An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.", "description": "An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.",
"main": "nodejs/all.mjs", "main": "nodejs/all.mjs",
"browser": "browser/all.mjs", "browser": "browser/all.mjs",
......
...@@ -9,20 +9,22 @@ export default basex; ...@@ -9,20 +9,22 @@ export default basex;
const _b64 = basex(B64_ALPHABET); const _b64 = basex(B64_ALPHABET);
export const b64 = { export const b64 = {
encode: source => { encode: source => {
const size = Math.ceil(source.length / 3) * 3; const bSource = (typeof source === 'string') ? (new TextEncoder()).encode(source) : new Uint8Array(source);
const sizedArray = new Uint8Array(size); const paddedSize = Math.ceil(bSource.length / 3) * 3;
const sizedArray = new Uint8Array(paddedSize);
if (typeof source === 'string') sizedArray.set((new TextEncoder()).encode(source)); sizedArray.set(bSource);
else sizedArray.set(source);
const b64str = _b64.encode(sizedArray).split(''); const b64str = _b64.encode(sizedArray).split('');
for (let i = 0; i < size - source.length; i++) b64str[b64str.length - 1 - i] = '='; const b64PaddedSize = paddedSize*4/3;
while (b64str.length < b64PaddedSize) b64str.unshift(B64_ALPHABET[0]);
for (let i = 0; i < paddedSize - bSource.length; i++) b64str[b64str.length - 1 - i] = '=';
return b64str.join(''); return b64str.join('');
}, },
decode: b64str => { decode: b64str => {
const rawArray = _b64.decode(b64str.replace(/=/g, 'A')); const rawArray = _b64.decode(b64str.replace(/=/g, 'A'));
const targetSize = Math.trunc(3 * b64str.length / 4 - (b64str.length - b64str.replace(/=/g, '').length)); const targetSize = Math.ceil(3 * b64str.length / 4);
return rawArray.slice(0, targetSize); const postCut = (b64str.match(/=/g)||[]).length;
const preCut = rawArray.length - targetSize;
return rawArray.slice(preCut, rawArray.length-postCut);
} }
}; };
......
...@@ -22,3 +22,14 @@ test('b64 should decode TWE= as Ma', t => t.is((new TextDecoder()).decode(app.b6 ...@@ -22,3 +22,14 @@ test('b64 should decode TWE= as Ma', t => t.is((new TextDecoder()).decode(app.b6
// Won't fix test('b64 should decode TWE as Ma', t => t.is((new TextDecoder()).decode(app.b64.decode('TWE')), 'Ma')); // Won't fix test('b64 should decode TWE as Ma', t => t.is((new TextDecoder()).decode(app.b64.decode('TWE')), 'Ma'));
test('b64 should decode TQ== as M', t => t.is((new TextDecoder()).decode(app.b64.decode('TQ==')), 'M')); test('b64 should decode TQ== as M', t => t.is((new TextDecoder()).decode(app.b64.decode('TQ==')), 'M'));
// Won't fix test('b64 should decode TQ as M', t => t.is((new TextDecoder()).decode(app.b64.decode('TQ')), 'M')); // Won't fix test('b64 should decode TQ as M', t => t.is((new TextDecoder()).decode(app.b64.decode('TQ')), 'M'));
test('[0,5,5] should be encoded as AAUF', t => t.is(app.b64.encode([0,5,5]), 'AAUF'));
test('AAUF should be decoded as [0,5,5]', t => t.deepEqual(app.b64.decode('AAUF'), new Uint8Array([0,5,5])));
test('[0,1] should be encoded as AAE=', t => t.is(app.b64.encode([0,1]), 'AAE='));
test('AAE= should be decoded as [0,1]', t => t.deepEqual(app.b64.decode('AAE='), new Uint8Array([0,1])));
//const unstableExample = 'AUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBVCmFAmx3dAyXpsWtwDnGel3LAcACxvXeG6QfGU9IEld9WwlvkDttnDTPgQL6TQkiMl0SCo=';
const unstableExample = 'AAUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBVCmFAmx3dAyXpsWtwDnGel3LAcACxvXeG6QfGU9IEld9WwlvkDttnDTPgQL6TQkiMl0SCo=';
test('b64 should be stable in decoding encoding process even on long string', t => t.is(app.b64.encode(app.b64.decode(unstableExample)), unstableExample));
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