@@ -13,6 +13,10 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0
...
@@ -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])
## [Non-publié/Non-Stabilisé] (par [1000i100])
## [Version 3.4.1] - 2022-11-20 (par [1000i100])
### Corrections
- checkKey envoi désormais des erreurs nommées, utilisable pour guider les usagers.
## [Version 3.4.0] - 2022-11-15 (par [1000i100])
## [Version 3.4.0] - 2022-11-15 (par [1000i100])
### Ajouté
### Ajouté
- crypto.textEncrypt(jsonMessage, senderPrivateKey, receiverPubKey) retourne un json format cesium+ avec `jsonMessage.title` et `jsonMessage.content` chiffrés.
- crypto.textEncrypt(jsonMessage, senderPrivateKey, receiverPubKey) retourne un json format cesium+ avec `jsonMessage.title` et `jsonMessage.content` chiffrés.
...
@@ -101,8 +105,9 @@ et ce projet adhère au [versionnage sémantique](https://semver.org/spec/v2.0.0
...
@@ -101,8 +105,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.
if(b58pubKey.length<43)thrownewCustomError('too_short','Too short, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.');
if(b58pubKey.length>44)thrownewCustomError('too_long','Base58 string too long, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.');
if(!/^[A-HJ-NP-Za-km-z1-9]+$/.test(b58pubKey))thrownewCustomError('not_b58','Character out of base 58, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.');
if(b58.decode(b58pubKey).length>32)thrownewCustomError('too_long','binary key too long, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.');
returntrue;
}
exportfunctioncheckEd25519PubKey(b58pubKey){
exportfunctioncheckEd25519PubKey(b58pubKey){
constbinPubKey=pubKey2bin(b58pubKey);
constbinPubKey=pubKey2bin(b58pubKey);
ed25519.Point.fromHex(binPubKey);
try{
ed25519.Point.fromHex(binPubKey);
}catch (err){
thrownewCustomError('bad_ed25519_point',`Invalid public key : not a valid ed25519 point RFC8032 5.1.3 https://www.rfc-editor.org/rfc/rfc8032#page-11 Internal:${err}`);
}
returntrue;
returntrue;
}
}
exportfunctionisEd25519PubKey(b58pubKey){
exportfunctionisEd25519PubKey(b58pubKey){
...
@@ -138,11 +149,19 @@ export function isEd25519PubKey(b58pubKey){
...
@@ -138,11 +149,19 @@ export function isEd25519PubKey(b58pubKey){
if(!pubKey)thrownewCustomError('empty','Invalid public key : empty input.')
constb58pubKey=b58.encode(binPubKey);
letb58pubKey;
try{
constbinPubKey=pubKey2bin(pubKey)
b58pubKey=b58.encode(binPubKey);
}catch (err){
if(err.message.match(/base58/))thrownewCustomError('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/))thrownewCustomError('too_long','Binary key too long, see rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key for details.');
throwerr;
}
if(!checkRawPubKey)returntrue;
if(!checkRawPubKey)returntrue;
if(!isDuniterPubKey(b58pubKey))thrownewError("Invalid public key : this string don't follow rfc/0009_Duniter_Blockchain_Protocol_V11.md#public-key");
checkDuniterPubKey(b58pubKey);
if(!isEd25519PubKey(b58pubKey))thrownewError("Invalid public key : not a valid ed25519 point RFC8032 5.1.3 https://www.rfc-editor.org/rfc/rfc8032#page-11");
checkEd25519PubKey(b58pubKey);
returntrue;
returntrue;
}
}
exportfunctionisPubKey(pubKey){
exportfunctionisPubKey(pubKey){
...
@@ -229,3 +248,9 @@ export function textDecrypt(jsonMessage, receiverPrivateKey){
...
@@ -229,3 +248,9 @@ export function textDecrypt(jsonMessage, receiverPrivateKey){
@@ -128,8 +128,12 @@ test("isEd25519PubKey fail if point is not on ed25519", (t) => t.false(app.isEd2
...
@@ -128,8 +128,12 @@ 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 accept valid pubKey with no checksum',t=>t.true(app.checkKey(pubKey)));
test('checkKey throw if invalid pubkey is given',t=>t.throws(()=>app.checkKey(pubKey.replace(/6/,'9'))));
test('checkKey throw if empty pubkey is given',t=>t.throws(()=>app.checkKey(''),{name:'empty'}));
test('checkKey throw if empty pubkey is given',t=>t.throws(()=>app.checkKey('')));
test('checkKey throw if under_sized string is given',t=>t.throws(()=>app.checkKey('test'),{name:'too_short'}));
test('checkKey throw if over_sized string is given',t=>t.throws(()=>app.checkKey(pubKey+pubKey),{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'}));