Returns a set of functions as an API for validating, building, publishing and reading records dictated by ssb-dark-crystal-schema.
var DarkCrystal = require('scuttle-dark-crystal')
var darkCrystal = DarkCrystal(server) // a scuttlebutt server or connection to one
The easiest way to see which methods are exposed is to check out ./methods.js
Where opts
is an object with required properties:
name
a name referring to the secretsecret
the secret string itselfrecps
an array of ssb feedIds for the shard recipientsquorum
the minimum number of shards required to recombine
The secret is sharded and a root message, ritual message and one shard message for each recipient are published. If successful, the published messages will be passed as an object to the callback.
This method publishes invite
messages with a request to return a shard. If recipients
is falsey, invite messages to all shardholders associated with the given rootId will be published. If recipients
is an array containing one or more feedIds, invite messages to only the given recipients will be published, provided they hold shards associated with the given rootId. If successful, the published invite messages are passed to the callback.
This method can also be called : darkCrystal.recover.async.request(rootId, callback)
and it will send requests to al shard-holders
This will respond to a given invite message, by decrypting the associated shard and publishing an invite-reply
message providing the shard in the body
property. If successful, the reply message is passed to the callback.
This will attempt to recombine the decrypted shards included in reply messages associated with a given rootId. If successful the secret will be passed to the callback.
This also works for forwarded shards, you just need to provide the root from on of the fwds.
Takes a secret name as an argument and publishes a root message. If successful, the published message will be passed to the callback.
Takes an object with properties:
root
the ID of the root messageshards
the number of shardsquorum
the minimum number of shards required to recombine
A ritual message is published. If successful, the published message will be passed to the callback.
Takes an object with properties:
shards
an array of shard stringsrecps
an array of ssb feedIds for the shard recipientsrootId
the ID of the root message
For each shard, a shard message will be published to both the recipient and the sender. If successful, the published messages will be passed to the callback. In the case of at least one validation error, no messages will be published.
Returns a stream of shard messages identified by root id. Takes opts
- standard stream options.
Returns a stream of shards others have shared with you. Takes opts
- standard stream options like live
, reverse
etc.
Takes arguments
root
the id of the root message with which the shard is associatedrecp
the feedId of the recipient of the forwarded shard
Publishes a forward message which allows a shard to be sent to someone other than the owner of the secret.
Returns a stream of forwarded shard messages identified by root id. Takes opts
- standard stream options.
Returns a stream of all forwarded shards you have recieved. Takes opts
- standard stream options like live
, reverse
etc.
These are validation methods for each message type as described in ssb-dark-crystal-schema.
The request + reply schema is described by ssb-invite-schema, but there's additional validation added by the module to check the payload is shard-like