#
Encrypt operations
Wax provides a simple interface for encrypting operation data within a transaction using the ITransaction
interface. Operation encrypting allows to push operations in transparent way, just by pushing markers when to start and stop encryption.
#
Operations That Can Be Encrypted
Currently, Hive supports encrypting the following operation data:
-
comment_operation
- Encrypts the
body
field. -
custom_json_operation
- Encrypts the
json
field. Custom JSON encryption is unique as it wraps the encrypted data in anencrypted
key. -
transfer_operation
- Encrypts the
memo
field. -
transfer_to_savings_operation
- Encrypts the
memo
field. -
transfer_from_savings_operation
- Encrypts the
memo
field. -
recurrent_transfer_operation
- Encrypts the
memo
field.
#
Encrypting Operations within a Transaction
These examples demonstrate how to handle encryption and decryption using both direct methods and the ITransaction
interface in the Wax library.
Actual encryption is performed while signing transaction!
#
One key encryption
Non-encrypted operations
startEncrypt
only enables encryption for the operation data above, other data is not encrypted.
import { createHiveChain } from "@hiveio/wax";
/* Import preconfigured beekeeper data specific to snippet examples */
const { signer1, publicKey1 } = globalThis.snippetsBeekeeperData;
const hiveChain = await createHiveChain();
// Create a transaction
const tx = await hiveChain.createTransaction();
// Start the encryption chain
tx.startEncrypt(publicKey1)
.pushOperation({ // Add encrypted operation
transfer_operation: {
from: "alice",
to: "bob",
amount: hiveChain.hiveCoins(5.100), // Send 5.100 HIVE (Note: Coins, not satoshis)
memo: "This memo will be encrypted"
}
})
.stopEncrypt(); // Stop the encryption chain
// Sign and build the transaction
await signer1.signTransaction(tx);
console.log(tx.transaction);
publicKey1
used for transaction signing can (and usually does) differ from the public key used for encryption.
Not implemented yet — planned for a future release.
#
Two keys encryption
import { createHiveChain } from "@hiveio/wax";
/* Import preconfigured beekeeper data specific to snippet examples */
const { signer1, publicKey1, publicKey2 } = globalThis.snippetsBeekeeperData;
const hiveChain = await createHiveChain();
// Create a transaction
const tx = await hiveChain.createTransaction();
// Start the encryption chain with two keys
tx.startEncrypt(publicKey1, publicKey2)
.pushOperation({ // Add encrypted operations
transfer_operation: {
from: "alice",
to: "bob",
amount: hiveChain.hiveCoins(5), // Send 5.000 HIVE (Note: Coins, not satoshis)
memo: "This memo will be encrypted with two keys"
}
})
.stopEncrypt(); // Stop the encryption chain
// Sign and build the transaction
await signer1.signTransaction(tx);
console.log(tx.transaction);
Not implemented yet — planned for a future release.
#
Mixed encryption
import { createHiveChain } from "@hiveio/wax";
/* Import preconfigured beekeeper data specific to snippet examples */
const { signer1, publicKey1, publicKey2 } = globalThis.snippetsBeekeeperData;
const hiveChain = await createHiveChain();
// Create a transaction
const tx = await hiveChain.createTransaction();
// Start the encryption chain with two keys
tx.startEncrypt(publicKey1, publicKey2)
.pushOperation({ // Add encrypted operations
transfer_operation: {
from: "alice",
to: "bob",
amount: hiveChain.hiveCoins(5.100), // Send 5.100 HIVE (Note: Coins, not satoshis)
memo: "This memo will be encrypted with two keys"
}
})
.stopEncrypt() // Stop the current encryption chain
.startEncrypt(publicKey1) // Start the encryption chain again, but with one key only
.pushOperation({ // Add other encrypted operations
transfer_operation: {
from: "alice",
to: "bob",
amount: hiveChain.hiveCoins(10.050), // Send 10.050 HIVE (Note: Coins, not satoshis)
memo: "This memo will be encrypted with one key only"
}
})
.stopEncrypt(); // Stop the encryption chain again (optionally)
// Sign and build the transaction
await signer1.signTransaction(tx);
console.log(tx.transaction);
publicKey1
used for transaction signing can (and usually does) differ from the public key used for encryption.
Not implemented yet — planned for a future release.