A request can be encrypted to make its details private to selected stakeholders. In this guide, we won't explain how encryption is managed under the hood. We will mention encryption or decryption of requests with payers and payees keys. Although in practice, we will use an intermediate symmetric key. See more details on .
The transaction layer manages the encryption, .
To manipulate encrypted requests you need a CipherProvider (recommended) or DecryptionProvider (deprecated). Both of them require direct access to the private key. They're best suited for backends.
EthereumPrivateKeyCipherProvider: Provides both encryption and decryption utilities.
EthereumPrivateKeyDecryptionProvider (deprecated) provides only decryption utilities.
Create an encrypted request
EthereumPrivateKeyCipherProvider
See on .
import { EthereumPrivateKeyCipherProvider } from '@requestnetwork/epk-cipher';
const cipherProvider = new EthereumPrivateKeyCipherProvider({
# Warning: private keys should never be stored in clear, this is a basic tutorial
key: '0x4025da5692759add08f98f4b056c41c71916a671cedc7584a80d73adc7fb43c0',
method: RequestNetwork.Types.Encryption.METHOD.ECIES,
});
const requestNetwork = new RequestNetwork({
cipherProvider,
signatureProvider,
useMockStorage: true,
});
Note: You must give at least one encryption key you can decrypt with the decryption provider. Otherwise, an error will be triggered after the creation.
EthereumPrivateKeyDecryptionProvider
Get invoice information from its request ID
Let's step back for a second: the requester sent a request that he encrypted with the payer's public key, as well as with his own, to retrieve it later. This is an essential and typical example, but a request can be encrypted with many keys to give access to its status and details.
If the decryption provider knows a private key matching one of the keys used at the creation, it can decrypt it. Like a clear request you can get it from its request id.
Like a clear request, you can update it if the decryption provider is instantiated with a matching private key.
//Accept
await request.accept(payerIdentity);
//Cancel
await request.cancel(payeeIdentity);
//Increase the expected amount
await request.decreaseExpectedAmountRequest(amount, payeeIdentity);
//Decrease the expected amount
await request.increaseExpectedAmountRequest(amount, payerIdentity);
Enabling/Disabling Decryption
// Disable decryption
cipherProvider.enableDecryption(false);
// Check if decryption is enabled
const isEnabled = cipherProvider.isDecryptionEnabled();
// Re-enable decryption
cipherProvider.enableDecryption(true);
Checking Capabilities
// Check if encryption is available
const canEncrypt = cipherProvider.isEncryptionAvailable();
// Check if decryption is available
const canDecrypt = cipherProvider.isDecryptionAvailable();
// Check if an identity is registered
const isRegistered = await cipherProvider.isIdentityRegistered({
type: 'ethereum_address',
value: '0x123...'
});// Some code