Send encrypted messages on AO. Like an encrypted voicemail.
Useful for collecting private DAPP logs from users at their discretion!
Process Lua source code at ar://p5zkcW3sysfkGrkN9oc_DfVNQ9PkI3hsb-8CyPeZZdg
npm i @memetic-block/ao-encrypted-messages
- Deploy, update, & view an encrypted inbox on AO!
- Programmatic interface
- Supports
Curve25519
- Uses
tweetnacl
under the hood for encryption - Forwards encrypted messages to
Process.Owner
const wallet = JSON.parse(readFileSync('path-to-jwk').toString())
const encryptedMessages = await EncryptedMessages.spawn(wallet)
console.log(`Spawned new EncryptedMessages process at ${encryptedMessages.processId}`)
A newly spawned Encrypted Inbox doesn't have a public key to receive messages so one needs to be set before it can receive messages.
You can update the Encryption Public Key as often as you want! Old messages will still be retained with the public key they were originally sent with.
const publicKey = 'your Curve25519 PUBLIC key'
const result = await encryptedMessages.setEncryptionPublicKey(publicKey)
console.log(
`Set encryption key ${result.publicKey} on EncryptedMessage process ${encryptedMessages.processId}`,
result
)
Send an encrypted message with a generated throw-away keypair
const message = "Hold the line, love isn't always on time"
const { messageId } = await encryptedMessages.sendEncryptedMessage(message)
Send an encrypted message with a given keypair and nonce - both optional.
const secretKey = 'your Curve25519 PRIVATE key'
const nonce = 'Quis custodiet ipsos custodes?'
const { messageId } = await encryptedMessages.sendEncryptedMessage(
message,
{ secretKey, nonce }
)
List all messages contained in the process. They are still encrypted.
const { messages } = await encryptedMessages.listEncryptedMessages()
console.log(`Got ${Object.keys(messages).length} encrypted messages`)
console.log(messages)
Fetch an individual encrypted message by its AO message ID. It's still encrypted.
const {
message,
nonce,
publicKey,
recipientPublicKey
} = await encryptedMessages.getEncryptedMessage(messageId)
Optionally, you can supply the secret key to automatically decrypt a fetched message.
const secretKey = 'your Curve25519 PRIVATE key'
const {
message,
nonce,
publicKey,
recipientPublicKey
} = await encryptedMessages.getEncryptedMessage(messageId, secretKey)
Request
[
{
"name": "Action",
"value": "Set-Encryption-Public-Key"
},
{
"name": "EncryptionPublicKey",
"value": "your Curve25519 PUBLIC key"
}
]
Success Result
{
"Data": "your Curve25519 PUBLIC key"
}
Request
[
{
"name": "Action",
"value": "Get-Encryption-Public-Key"
}
]
Success Result
{
"Data": "your Curve25519 PUBLIC key"
}
Request
Tags
[
{
"name": "Action",
"value": "Send-Encrypted-Message"
}
]
Data
{
"message": "the encrypted message",
"publicKey": "the public key of the keypair used to encrypt the message",
"recipientPublicKey": "the current public key of the message recipient",
"nonce": "nonce used for unique message id"
}
Success Result
Reply to Sender
{
"Data": "nonce for this message"
}
Forward to Process.Owner
{
"Data": {
"nonce": "nonce for this message",
"messageId": "ao messageId of the message",
"from": "sender address"
}
}
Request
[
{
"name": "Action",
"value": "List-Encrypted-Messages"
}
]
Success Result
{
"Data": { "<nonce>": "<messageId>", ... }
}
PRs welcome!