Server SDK quick start.
Store and read protected records from your own server. Your server proves itself with a key only it holds; every request is signed and every record is sealed for the journey.
1. Create a workspace and a key
Create your account with a passkey, open your workspace and choose Create key and download. The file it saves holds your organisation ID, the key ID and the private key. Piipe keeps only the public half, so keep the file on the server that will use it and nowhere else.
2. Add the SDK
Two files, no dependencies, Node 20 or later: piipe.js and piipe-storage.js. Put them side by side.
3. Use it
const piipe = require('./piipe.js');
const workspace = piipe.connect(require('./piipe-key_0123456789abcdef.json'), {searchable: ['email']});
const customer = {object_id_type: 'customer', object_id: 'cust_1001'};
await workspace.create(customer, {email: 'alex@northstar.com', display_name: 'Alex'});
const {fields} = await workspace.read(customer, {fields: ['email']}); // only what you ask for
await workspace.update(customer, {display_name: 'Alex P', phone: null}); // null removes a field
await workspace.exists(customer); // true
await workspace.history(customer); // times of each revision, no values
await workspace.find('customer', {email: 'Alex@Northstar.com'}); // references holding that value
await workspace.list('customer', {limit: 100}); // references, a page at a time
await workspace.access(customer); // who did what to it, and when
await workspace.delete(customer); // erases every revision's fields
What to expect
- Keys. A read-only key can read and check; a read-and-write key can also create, update and delete. Revoking a key in the console stops it getting new sessions at once; a session already given runs out within 15 minutes.
- Fields. Each field is encrypted on your server under that field's own key before it is sent. A key you limit to named fields in the console is given those fields' keys and no others: it reads and sets its own fields, a read or change that names any other is rejected with
not_permitted, and the rest of the record stays closed to its server. - Search.
find(type, {field: value})returns the references of the records whose field holds exactly that value, ignoring case and outer spaces. It reaches the fields named insearchablewhen the record was written or last changed; give every server that writes the same list. The index holds a keyed digest of the value, never the value. - Listing.
list(type, {limit, after})returns references in the order they were created, withnextto pass asafterfor the following page;nullmeans the end. - Access log. Every create, read, update, delete and search hit is written to the record's log before its result is returned: the key, the operation, the revision, the field names and the time.
access(reference)reads it, a page at a time. No key can change or remove an entry, and the log remains after the record is deleted. - Records. Fields are strings by name. One record holds about 45,000 bytes of values. Each change is a new revision; an earlier revision can be read with
{revision: n}until the record is deleted. - Two servers, one record. If two requests change a record at once, one is applied and the other is tried again on the result. Nothing is half written.
- Errors. Calls reject with a
PiipeErrorwhosecodeis one ofnot_found,exists,changed,not_permitted,too_large,bad_reference,bad_fields,key,network,unavailable. - Limits today. Four keys to a workspace, and up to eight servers holding sessions in it at one time. A limited key names up to eight fields. A reference's ID is up to 1,000 bytes.
Without the SDK
The SDK does two things you can also do yourself. First it asks for a session: GET /a/p/challenge?for=token returns a one-time challenge, and GET /a/p/v1/token?o=<organisation>&k=<key>&c=<challenge>&s=<signature> returns a 15-minute storage session. The signature is ECDSA P-256 with SHA-256 over the bytes piipe-token-v1, a zero byte, the 16-byte organisation ID, the 8-byte key ID and the 32-byte challenge, sent as the two 32-byte numbers in base64url. Then it signs and seals each storage request with the session key and sends it to /s/; piipe-storage.js is the reference for that format, and piipe.js for how a record, its fields, its index entries and its access log are laid out.