1.3.2 • Published 3 years ago
envelope-js v1.3.2
envelope-js
A javascript tool for cryptographically "boxing" and "unboxing" messages following the envelope spec.
envelope supports encryption to individuals and groups
Example Usage
var { box, unbox, CloakedMsgId } = require('envelope-js')...
API
box(plain_text, feed_id, prev_msg_id, msg_key, recp_keys) => ciphertext
where:
plain_textBuffer is the content to be "enveloped"feed_idBuffer is a type-format-key (TFK) encoded value for the feed authoring a messageprev_msg_idBuffer is a TFK encoded value of the id of last message of this feeds chainmsg_keyBuffer a randomised 32 Bytes which will be the unique key for this messagerecps_keysArray is a collection of items of form{ key, scheme }, wherekeyBuffer is the key the particular recipientschemeString|Buffer is the type of key / the key management scheme for this recipient
unbox(ciphertext, feed_id, prev_msg_id, trial_keys, max_attempts) => plain_text | null
where:
ciphertextBuffer is envelopefeed_idBuffer is a type-format-key (TFK) encoded value for the feed authoring a messageprev_msg_idBuffer is a TFK encoded value of the id of last message of this feeds chaintrial_keysArray is a collection of items of form{ key, scheme }, wherekeyBuffer is the key the particular recipientschemeString|Buffer is the type of key / the key management scheme for this recipient
max_attemptsInteger (default: 8) how many key_slots you want to assume the envelope hasplain_textBuffer the envelope contents
NOTE: we also expose unboxKey and unboxBody for convenience.
DeriveSecret(feed_id, prev_msg_id) => derive
Used for taking a msg_key (the one-time key for a particular envelope) and deriving other keys used in the envelope (e.g. read_key)
where:
feed_idBuffer is a TFK encoded id for the feed the envelope is part ofprev_msg_idBuffer is a TFK encoded id for the message prior to one where our envelope is- NOTE if this is the first message, then the K part of
prev_msg_id's TFK is a zero-filled Buffer.
- NOTE if this is the first message, then the K part of
derive(key, labels) => new_keyfunction where:keyBuffer is a seed key which we're going to derive fromlabelsArray is a an array of Strings which help define a derivation
new CloakedMsgId(public_msg_id, read_key) => cloakedMsgId
Determine a cloaked message id for a published message following the envelope-spec/cloaked_msg_id/README.md
where:
public_msg_idBuffer is the id of a enveloped message that's been published (it has an id as it's part of a feed / chain)read_keyBuffer is the read capability (NOT themsg_key) for this message envelopecloakedMsgIdis an instance with methods:toBuffer() => Bufferwhich returns the cloaked id key as a BuffertoString(encoding) => Stringwhich returns the cloaked id key as a Buffer (encoding defaults to 'base64')mock() => cloakedMsgIda method for testing. populates the id with random content. if using this, instantiate with no args.
slp.encode(info) => Buffer
where info is an Array of Buffers.
This is "short length-prefixed encoding", see https://github.com/ssbc/envelope-spec/blob/master/encoding/slp.md
...
License
MIT