connex icon indicating copy to clipboard operation
connex copied to clipboard

Add encryption service (encrypt/decrypt) to connex + Sync2

Open ifavo opened this issue 2 years ago • 0 comments

It would be great to handle string encryption using connex and Sync2.

The goal is to achieve something similar to sending private messages on the blockchain using public keys and decoding them on the recipient side. It can be implemented into a private chat system or for publishing private data without leaving the connex system.

Similar to this example:
https://github.com/pubkey/eth-crypto/blob/3c26820796d6613ce0e70c47732601283ee129ea/tutorials/encrypted-message.md

I suggest to either modify the signing service with a new option (encrypt|decrypt) or add a new encryption service:

connex.vendor.encryption('decrypt', {
    purpose: 'access to message reason',
    payload: {
        type: 'text',
        content: 'encrypted string'
    }
})
.request()
.then(decodedResult=>{
    console.log(decodedResult)
})
  • When the above snippet is run, the user is presented with a confirmation dialog in Sync2 similar to the signing service.
  • If confirmed, a snippet similar to (https://github.com/pubkey/eth-crypto/blob/master/src/decrypt-with-private-key.js) is run and the result returned.

In the end the following snippet should work:

const encodedString = await connex.vendor.encryption('encrypt', {
    purpose: 'encrypt private message',
    payload: {
        publicKey: 'publicKey',
        message: 'a message'
    }
})
.request()

// user is presented with confirmation dialog to confirm encryption

const decodedString = await connex.vendor.encryption('decrypt', {
    purpose: 'decrypt private message',
    payload: {
        encrypted: encodedString
    }
})
.request()

// user is presented with confirmation dialog to confirm decryption

to support multiple payloads without calling encryption/decryption for each, payload should also support a list/array of objects:

const encodedStrings = await connex.vendor.encryption('encrypt', {
    purpose: 'encrypt private message',
    payload: [
   {
        publicKey: 'publicKey#1',
        message: 'Hello World'
    },
   {
        publicKey: 'publicKey#2',
        message: 'Hello VeChain'
    }]
})
.request()

// encodedStrings is a list with both results

const decodedStrings = await connex.vendor.encryption('encrypt', {
    purpose: 'encrypt private message',
    payload: encodedStrings.map(encrypted => ({ encrypted }))
})
.request()


// decodedStrings is a list of the original messages

ifavo avatar Jun 17 '22 10:06 ifavo