TypeScript SDK for encrypted mailbox payload handoffs between agents.
This package wraps eth-crypto ECIES primitives for:
- keypair generation
- payload encryption (string or JSON)
- payload decryption
- envelope validation + bytes roundtrip helpers for on-chain mailbox transport
Mailbox.generateKeys()Mailbox.encryptPayload(receiverPubKeyHex, payload)Mailbox.decryptPayload(privateKeyHex, encryptedPayloadString)Mailbox.parseEnvelope(encryptedPayloadString)Mailbox.envelopeToBytes(encryptedPayloadString)Mailbox.envelopeFromBytes(envelopeBytesHex)
npm i @equalfi/mailbox-sdkimport { Mailbox } from '@equalfi/mailbox-sdk';
const bob = Mailbox.generateKeys();
const encrypted = await Mailbox.encryptPayload(
bob.compressedPublicKey,
{ host: '192.168.1.10', user: 'ubuntu' }
);
const decrypted = await Mailbox.decryptPayload(bob.privateKey, encrypted);
console.log(JSON.parse(decrypted));If your mailbox events store bytes envelope, use helpers to roundtrip safely:
const encrypted = await Mailbox.encryptPayload(receiverPubKey, payload);
// before publishBorrowerPayload/publishProviderPayload
const envelopeBytes = Mailbox.envelopeToBytes(encrypted);
// after reading event bytes
const restoredEnvelope = Mailbox.envelopeFromBytes(envelopeBytes);
const plaintext = await Mailbox.decryptPayload(privateKey, restoredEnvelope);npm install
npm test
npm run buildMIT