Class: Consumer

Consumer

new Consumer(face, keyChain, groupName, consumerName, database)

A Consumer manages fetched group keys used to decrypt a data packet in the group-based encryption protocol. Create a Consumer to use the given ConsumerDb, Face and other values.
Parameters:
Name Type Description
face Face The face used for data packet and key fetching.
keyChain KeyChain The keyChain used to verify data packets.
groupName Name The reading group name that the consumer belongs to. This makes a copy of the Name.
consumerName Name The identity of the consumer. This makes a copy of the Name.
database ConsumerDb The ConsumerDb database for storing decryption keys.
Source:

Methods

(static) decrypt_(encryptedContent, keyBits, onPlainText, onError)

Decrypt encryptedContent using keyBits.
Parameters:
Name Type Description
encryptedContent Blob | EncryptedContent The EncryptedContent to decrypt, or a Blob which is first decoded as an EncryptedContent.
keyBits Blob The key value.
onPlainText function When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob.
onError function This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode.
Source:

(static) decryptPromise_(encryptedContent, keyBits) → {Promise|SyncPromise}

Decrypt encryptedContent using keyBits.
Parameters:
Name Type Description
encryptedContent Blob | EncryptedContent The EncryptedContent to decrypt, or a Blob which is first decoded as an EncryptedContent.
keyBits Blob The key value.
Source:
Returns:
A promise that returns the decrypted Blob, or that is rejected with Consumer.Error or other error.
Type
Promise | SyncPromise

(static) Error(errorCode, message)

Consume.Error is used internally from promised-based methods to reject with an error object that has the errorCode and message returned through the onError callback.
Parameters:
Name Type Description
errorCode number An error code from EncryptError.ErrorCode.
message string The error message.
Source:

addDecryptionKey(keyName, keyBlob, onComplete, onError)

Add a new decryption key with keyName and keyBlob to the database.
Parameters:
Name Type Description
keyName Name The key name.
keyBlob Blob The encoded key.
onComplete function (optional) This calls onComplete() when the key is added. (Some database libraries only use a callback, so onComplete is required to use these.)
onError function (optional) If defined, then onComplete must be defined and if there is an exception, then this calls onError(exception) where exception is Error if the consumer name is not a prefix of the key name, or ConsumerDb.Error if a key with the same keyName already exists, or other database error. If onComplete is defined but onError is undefined, then this will log any thrown exception. (Some database libraries only use a callback, so onError is required to be notified of an exception.)
Source:

addDecryptionKeyPromise(keyName, keyBlob, useSync) → {Promise|SyncPromise}

Add a new decryption key with keyName and keyBlob to the database.
Parameters:
Name Type Description
keyName Name The key name.
keyBlob Blob The encoded key.
useSync boolean (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise.
Source:
Returns:
A promise that fulfills when the key is added, or that is rejected with Error if the consumer name is not a prefix of the key name, or ConsumerDb.Error if a key with the same keyName already exists, or other database error.
Type
Promise | SyncPromise

consume(contentName, onConsumeComplete, onError)

Express an Interest to fetch the content packet with contentName, and decrypt it, fetching keys as needed.
Parameters:
Name Type Description
contentName Name The name of the content packet.
onConsumeComplete function When the content packet is fetched and decrypted, this calls onConsumeComplete(contentData, result) where contentData is the fetched Data packet and result is the decrypted plain text Blob. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
onError function This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.
Source:

decryptCKey_(cKeyData, onPlainText, onError)

Decrypt cKeyData.
Parameters:
Name Type Description
cKeyData Data The C-KEY data packet.
onPlainText function When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob.
onError function This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode.
Source:

decryptContent_(data, onPlainText, onError)

Decrypt the data packet.
Parameters:
Name Type Description
data Data The data packet. This does not verify the packet.
onPlainText function When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob.
onError function This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode.
Source:

decryptDKeyPromise_(dKeyData) → {Promise|SyncPromise}

Decrypt dKeyData.
Parameters:
Name Type Description
dKeyData Data The D-KEY data packet.
Source:
Returns:
A promise that returns the decrypted Blob, or that is rejected with Consumer.Error or other error.
Type
Promise | SyncPromise

getDecryptionKeyPromise_(decryptionKeyName) → {Promise|SyncPromise}

Get the encoded blob of the decryption key with decryptionKeyName from the database.
Parameters:
Name Type Description
decryptionKeyName Name The key name.
Source:
Returns:
A promise that returns a Blob with the encoded key (or an isNull Blob if cannot find the key with decryptionKeyName), or that is rejected with ConsumerDb.Error for a database error.
Type
Promise | SyncPromise

setGroup(groupName)

Set the group name.
Parameters:
Name Type Description
groupName Name The reading group name that the consumer belongs to. This makes a copy of the Name.
Source: