diff --git a/CHANGELOG.fr.md b/CHANGELOG.fr.md index 448826a02b014899406d9515c42f1544eea13f69..8c18354ed5d6c3450ea339d8f4a2a7ac3727ee08 100644 --- a/CHANGELOG.fr.md +++ b/CHANGELOG.fr.md @@ -13,6 +13,10 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0 ## [Non-publié/Non-Stabilisé] (par [1000i100]) +## [Version 3.4.2] - 2022-11-20 (par [1000i100]) +### Corrections +- checkKey ne complète plus automatiquement les clef trop courtes et envoi donc l'erreur attendue pour les clefs trops courtes. + ## [Version 3.4.1] - 2022-11-20 (par [1000i100]) ### Corrections - checkKey envoi désormais des erreurs nommées, utilisable pour guider les usagers. @@ -105,8 +109,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 - 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.4.1...main +[Non-publié/Non-Stabilisé]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.4.2...main +[Version 3.4.2]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.4.1...v3.4.2 [Version 3.4.1]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.4.0...v3.4.1 [Version 3.4.0]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.3.3...v3.4.0 [Version 3.3.3]: https://git.duniter.org/libs/g1lib.js/-/compare/v3.3.2...v3.3.3 diff --git a/npm/package.json b/npm/package.json index 277098002b7697316fff7a38953cff31fe8dbcf4..4b0c1277f74f11de8e93e582722ad7afbc4381a3 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "g1lib", - "version": "3.4.1", + "version": "3.4.2", "description": "An ubiquitous static javascript toolbox lib for Ǧ1 / Duniter ecosystem with reliability in mind.", "main": "nodejs/all.mjs", "browser": "browser/all.mjs", diff --git a/src/crypto.mjs b/src/crypto.mjs index 36d66f6d625bc29eaef275d90e4838afdb8e8802..428ced0d44efa2f66008dcf0571d46c93741e407 100644 --- a/src/crypto.mjs +++ b/src/crypto.mjs @@ -153,7 +153,7 @@ export function checkKey(pubKey, checkRawPubKey= true) { let b58pubKey; try { const binPubKey = pubKey2bin(pubKey) - b58pubKey = b58.encode(binPubKey); + b58pubKey = typeof pubKey === 'string' ? pubKey : b58.encode(binPubKey); } catch (err){ if(err.message.match(/base58/)) throw new CustomError('not_b58', 'Character out of base 58, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.'); if(err.message.match(/out of bounds/)) throw new CustomError('too_long','Binary key too long, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.'); diff --git a/src/crypto.test.mjs b/src/crypto.test.mjs index 6c07e9b88a4dca01f685b9f4ce9f010220d66ef1..745321615935a8751dd05842cd860dbe5e616539 100644 --- a/src/crypto.test.mjs +++ b/src/crypto.test.mjs @@ -130,7 +130,11 @@ test("isEd25519PubKey fail if point is not on ed25519", (t) => t.false(app.isEd2 test('checkKey accept valid pubKey with no checksum', t => t.true(app.checkKey(pubKey))); test('checkKey throw if empty pubkey is given', t => t.throws(() => app.checkKey(''),{name:'empty'})); test('checkKey throw if under_sized string is given', t => t.throws(() => app.checkKey('test'),{name:'too_short'})); +test('checkKey throw too_short if 41 characters long string is given', t => t.throws(() => app.checkKey('fffffffffffffffffffffffffffffffffffffffff'),{name:'too_short'})); +test('checkKey throw too_short if 42 characters long string is given', t => t.throws(() => app.checkKey('ffffffffffffffffffffffffffffffffffffffffff'),{name:'too_short'})); +test('checkKey throw too_long if given string is 44 characters but more than 32bits', t => t.throws(() => app.checkKey('ffffffffffffffffffffffffffffffffffffffffffff'),{name:'too_long'})); test('checkKey throw if over_sized string is given', t => t.throws(() => app.checkKey(pubKey+pubKey),{name:'too_long'})); +test('checkKey throw too_long if 45 characters long string is given', t => t.throws(() => app.checkKey('fffffffffffffffffffffffffffffffffffffffffffff'),{name:'too_long'})); test('checkKey throw if invalid pubkey is given (not on ed25519 curve)', t => t.throws(() => app.checkKey(pubKey.replace(/6/,'9')),{name:'bad_ed25519_point'})); test('checkKey throw if checksum is incorrect', t => t.throws(() => app.checkKey(`${pubKey}:111`),{name:'bad_checksum'})); test('checkKey throw if not b58 string is given', t => t.throws(() => app.checkKey(`___`),{name:'not_b58'}));