Skip to content

Latest commit

 

History

History
364 lines (262 loc) · 16.6 KB

lib.md

File metadata and controls

364 lines (262 loc) · 16.6 KB

Library API docs

Constants

attestationVersion

The current attestation version this database writes.

Functions

dbGet(db, id, attr, sigKey, [encKey], [reduced], [leaveEncrypted])Promise.<(object|null)>

Get verified output from the database. Only properly signed entries will be returned.

If the value is encrypted and encKey is not provided, a NeedsKeyError will be raised, as this means the signature cannot be validated either.

If the attestation version is unknown, a BadVersionError will be raised.

The "encrypted" boolean will not be changed.

Timestamping is currently not validated.

null is returned if the key doesn't exist in the database.

Providing a batch instead of a db is allowed.

dbIsEncrypted(db, id, attr)Promise.<(boolean|null)>

Returns if the attribute is listed as encrypted.

No signatures are validated.

null is returned if the key doesn't exist in the database.

If the attestation version is unknown, a BadVersionError will be raised.

dbRawValue(db, id, attr)Promise.<*>

Returns only the decoded value of the given attribute. No signatures are validated!

Specifically the attestation value is returned.

null is returned if the key doesn't exist in the database.

If the attestation version is unknown, a BadVersionError will be raised.

openDB(path)Hyperbee

Creates hypercore/hyperbee at given path.

setSigningKey(privKey)

Set a global signing key for write operations.

dbPut(db, id, attr, value, [encryptionKey])Promise.<*>

Put data in the database.

dbPutMultiple(db, data, [encryptionKey])

Put data in the database, adding multiple key-value pairs at once. This is much faster because timestamping can be batched, but each timestamp proof will be larger than with dbPut.

dbAppend(db, id, attr, value, [encryptionKey])Promise.<*>

Appends to an array in the database.

If the given attribute doesn't exist an array will be created.

If a non-array object is already stored under the given attribute a NotArrayError will be thrown.

The new value of the array is returned.

A batch is used so that the append is treated as one locked atomic operation, not a separate read and write.

dbAddRelation(db, id, childOrParent, relationType, relationCid)

Add a relation to the database according to our relationship schema.

If the given key and/or relationType doesn't exist it will be created.

Duplicate CIDs in the array are allowed.

A batch is used so that the change is treated as one locked atomic operation, not a separate read and write.

dbRemoveRelation(db, id, childOrParent, relationType, relationCid)

Same as dbAddRelation. The first CID that matches the given one is removed.

dbUpgrade(db, id, attr, sigKey, [encryptionKey])Promise.<*>

Upgrade the OTS timestamp of an attestation, then save that new timestamp.

decryptValue(msgWithNonce, encryptionKey)*

Decrypt and decode an encrypted value from the database.

Throws a DecryptError if decryption fails.

keyFromPem(pemPath)Promise.<Buffer>

Extracts a 32-byte ed25519 private key from the given PEM/ASN encoded key file, such as those generated by openssl.

attToVC(att)string

Convert an attestation from the database into Verifiable Credentials format.

isAttVersionSupported(ver)boolean

Find out if this attestation can be decoded.

attestationVersion

The current attestation version this database writes.

Kind: global constant

dbGet(db, id, attr, sigKey, [encKey], [reduced], [leaveEncrypted]) ⇒ Promise.<(object|null)>

Get verified output from the database. Only properly signed entries will be returned.

If the value is encrypted and encKey is not provided, a NeedsKeyError will be raised, as this means the signature cannot be validated either.

If the attestation version is unknown, a BadVersionError will be raised.

The "encrypted" boolean will not be changed.

Timestamping is currently not validated.

null is returned if the key doesn't exist in the database.

Providing a batch instead of a db is allowed.

Kind: global function
Returns: Promise.<(object|null)> - - see schema docs

Param Type Default Description
db * Hyperbee or batch
id string CID
attr string attribute/key
sigKey Uint8Array ed25519 public key
[encKey] Uint8Array false 32 byte key, if decryption is needed
[reduced] boolean false if set to true only the value and timestamp are returned, not the whole object
[leaveEncrypted] boolean false set to true to leave value encrypted

dbIsEncrypted(db, id, attr) ⇒ Promise.<(boolean|null)>

Returns if the attribute is listed as encrypted.

No signatures are validated.

null is returned if the key doesn't exist in the database.

If the attestation version is unknown, a BadVersionError will be raised.

Kind: global function

Param Type Description
db * Hyperbee or batch
id string CID
attr string attribute/key

dbRawValue(db, id, attr) ⇒ Promise.<*>

Returns only the decoded value of the given attribute. No signatures are validated!

Specifically the attestation value is returned.

null is returned if the key doesn't exist in the database.

If the attestation version is unknown, a BadVersionError will be raised.

Kind: global function

Param Type Description
db * Hyperbee or batch
id string CID
attr string attribute/key

openDB(path) ⇒ Hyperbee

Creates hypercore/hyperbee at given path.

Kind: global function
Returns: Hyperbee - database

Param Type
path String

setSigningKey(privKey)

Set a global signing key for write operations.

Kind: global function

Param Type Description
privKey Uint8Array ed25519 private key

dbPut(db, id, attr, value, [encryptionKey]) ⇒ Promise.<*>

Put data in the database.

Kind: global function
Returns: Promise.<*> - - underlying hyperbee db.put result, usually undefined

Param Type Default Description
db * Hyperbee or batch
id string CID
attr string attribute/key
value * data to be stored, as JavaScript object
[encryptionKey] Uint8Array false 32 byte key, if encryption is needed

dbPutMultiple(db, data, [encryptionKey])

Put data in the database, adding multiple key-value pairs at once. This is much faster because timestamping can be batched, but each timestamp proof will be larger than with dbPut.

Kind: global function

Param Type Default Description
db * Hyperbee
data * array of triples: [cidString, attrString, valueObject]
[encryptionKey] Uint8Array false 32 byte key, if encryption is needed

dbAppend(db, id, attr, value, [encryptionKey]) ⇒ Promise.<*>

Appends to an array in the database.

If the given attribute doesn't exist an array will be created.

If a non-array object is already stored under the given attribute a NotArrayError will be thrown.

The new value of the array is returned.

A batch is used so that the append is treated as one locked atomic operation, not a separate read and write.

Kind: global function
Returns: Promise.<*> - - array as now stored in database

Param Type Default Description
db * Hyperbee
id string CID
attr string attribute/key
value * data to be stored, as JavaScript object
[encryptionKey] Uint8Array false 32 byte key, if encryption is needed

dbAddRelation(db, id, childOrParent, relationType, relationCid)

Add a relation to the database according to our relationship schema.

If the given key and/or relationType doesn't exist it will be created.

Duplicate CIDs in the array are allowed.

A batch is used so that the change is treated as one locked atomic operation, not a separate read and write.

Kind: global function

Param Type Description
db * Hyperbee
id string CID
childOrParent string is either "children" or "parents" as the db key
relationType string is a type for the relation like "derived" or "transcoded"
relationCid CID is the CID object to be added as a relation

dbRemoveRelation(db, id, childOrParent, relationType, relationCid)

Same as dbAddRelation. The first CID that matches the given one is removed.

Kind: global function

Param Type Description
db * Hyperbee
id string CID
childOrParent string is either "children" or "parents" as the db key
relationType string is a type for the relation like "derived" or "transcoded"
relationCid CID is the CID object to be added as a relation

dbUpgrade(db, id, attr, sigKey, [encryptionKey]) ⇒ Promise.<*>

Upgrade the OTS timestamp of an attestation, then save that new timestamp.

Kind: global function
Returns: Promise.<*> - - underlying hyperbee db.put result, usually undefined

Param Type Default Description
db * Hyperbee or batch
id string CID
attr string attribute/key
sigKey Uint8Array ed25519 public key
[encryptionKey] Uint8Array false 32 byte key, if encryption is needed

decryptValue(msgWithNonce, encryptionKey) ⇒ *

Decrypt and decode an encrypted value from the database.

Throws a DecryptError if decryption fails.

Kind: global function
Returns: * - - the decrypted value as a JavaScript object (NOT dag-cbor bytes)

Param Type Description
msgWithNonce * the bytes of attestation.value as a Uint8Array or Buffer
encryptionKey * a 32 byte decryption key (Uint8Array or Buffer)

keyFromPem(pemPath) ⇒ Promise.<Buffer>

Extracts a 32-byte ed25519 private key from the given PEM/ASN encoded key file, such as those generated by openssl.

Kind: global function

Param Type Description
pemPath string path to .pem file

attToVC(att) ⇒ string

Convert an attestation from the database into Verifiable Credentials format.

Kind: global function
Returns: string - - VC as string of JSON

Param Type Description
att object object returned by dbGet

isAttVersionSupported(ver) ⇒ boolean

Find out if this attestation can be decoded.

Kind: global function

Param Type Description
ver string | undefined | null attestation version string (X.Y)