virtualeconomy / js-v-sdk

[DEPRECATED and please use https://github.com/virtualeconomy/js-vsys instead] Java Script library for V Systems
https://www.npmjs.com/package/@virtualeconomy/js-v-sdk
MIT License
10 stars 5 forks source link

Documentation on "Encryption standards for V.systems" #59

Open Primerz opened 3 years ago

Primerz commented 3 years ago

As explained by the Vsys team (here https://github.com/virtualeconomy/js-v-sdk/wiki/How-to-Encrypt-and-Decrypt-a-message) it is possible to encrypt a message in a transaction using js-nacl, the key-pair from the vsystems account are compatible with it, meanwhile, for the McEliece algorithm it is not specified how could we transfers the public key to someone, therefore, it is potentially, useless.

In some chain, it is possible to have a transaction object property called "is_encrypted" which can correlate to "nacl" for example, very good for a standardized way to use it.

Also, a question that I have is the size limit of the message embed in a transaction.

Primerz commented 3 years ago

UPDATE: NaCl has been implemented on https://wallet.crypto.red/, it works and the string result is somehow sometimes smaller than 160 characters.

Since there is no property is_message_encrypted or such, the web app mentioned above offer a "tool" not a module which detect and decrypt the message, why not creating instruction like "E_NACL {{encrypted_text}}", it takes 7 chars... and "E_MCLE ..." too.

Primerz commented 3 years ago
function mc_eliece_encrypt(message, public_key, callback_function) {

    const message_uint8array = new TextEncoder().encode(message);
    const public_key_uint8array = new TextEncoder().encode(public_key);

    mceliece.encrypt(message_uint8array, public_key_uint8array).then(function(response_uint8array){

        callback_function(null, base58.encode(response_uint8array));

    }).catch(function(error){

        callback_function(error, "");
    });
}

function mc_eliece_decrypt(encrypted_message, private_key, callback_function) {

    const encrypted_message_uint8array = new TextEncoder().encode(encrypted_message);
    const private_key_uint8array = new TextEncoder().encode(private_key);

    mceliece.decrypt(encrypted_message_uint8array, private_key_uint8array).then(function(response_uint8array){

        callback_function(null, base58.encode(response_uint8array));

    }).catch(function(error){

        callback_function(error, "");
    });
}

I am not sure the keypair of Vsys is compatible with McEliece...

EDIT: Note (As seen on https://www.npmjs.com/package/mceliece-js): McEliece generally shouldn't be used to directly encrypt your data; in most cases, you'll want to pair it with a symmetric cipher and use it to encrypt symmetric keys. ADDITION: Unless rebuilding a new network and computing library with the new algorithms available (https://ianix.com/pqcrypto/pqcrypto-deployment.html) on the internet since NaCl use salsa20/20 (http://cr.yp.to/highspeed/coolnacl-20120725.pdf) for example and Curve25519 it could use New Hope and ChaCha20/20 but it seems that only 8 rounds on 12 or 20 can be actually broken (one less for ChaCha20) so the library seems still very secure and perfectly adapted for use in transactions. If VSYS decide to use encryption it could also propose something such as extendedNaCl, a combination of https://www.newhopecrypto.org/ and the current NaCl lib with some small update or maybe copying some of the https://github.com/cyph/cyph work and even https://www.youtube.com/channel/UC7zz9AQLYzoMNsmotzC__1Q knowledge Fortunately NaCl is to me LARGELY a good choice before a release of a potential xNaCl or else. Waiting on new algorithms to be discovered maybe an optional is_encrypted transactions property even Zcash hasn't solved the issue yet (issue 805).

faddat commented 3 years ago

@Primerz can you please let me know the goal?

passing encrypted info between users or something else?

vipertechofficial commented 3 years ago

@faddat Yes to encrypt the transaction's message, McEliece doesn't seem to fit (the VSYS key-pair can't achieve to work with it), more than that, it isn't recommended to use McEliece to encrypt messages, rather it should be used to encrypt a symmetrical key.

So we probably should remove McEliece from the recommendation, meanwhile, NaCl works great, cool enough, the vsystems blockchain could provide a format such as "NACL:{encrypted_message}" in order for all application to recognize encrypted memo.

Primerz commented 3 years ago

Screenshot from 2021-06-30 22-55-57 Screenshot from 2021-06-30 22-56-46 App screenshot: https://github.com/crypto-red/crypto-red.github.io

I think an auto decrypt mechanism along with a way to encrypt message is recommendable, also can't deal with McEliece by the way nevertheless NaCl works fine. :)