How to use encryption
Example #1. Send encrypted transaction
const { encryptDataField } = require('@swisstronik/utils')
// Encrypts data field and sends encrypted transaction
// * signer β ethers signer with connected provider
// * destination - destination address
// * data β raw (unencrypted) transaction `data` field
// * value β amount of aswtr to be sent within transaction
const sendShieldedTransaction = async (signer, destination, data, value) => {
// Encrypt transaction data. `encryptDataField` function also returns
// used encryption key to be able decrypt node response. It will be useful
// in case if you're sending some query (for example, request PERC20 balance)
const [encryptedData] = await encryptDataField(
signer.provider.connection.url,
data,
// encryptionKey β also you can provide encryption key by yourself
// if you want to be able to decrypt transaction payload in the future.
// Otherwise, it will generate random encryption key using `tweetnacl`
// library
)
// Construct and sign transaction with encrypted data. This transaction will
// be sent as a regular Ethereum transaction
return await signer.sendTransaction({
from: signer.address,
to: destination,
data: encryptedData,
value,
})
}Example #2. Send encrypted balanceOf request
Last updated