Class: PibIdentity

PibIdentity(impl)

new PibIdentity(impl)

A PibIdentity is at the top level in PIB's Identity-Key-Certificate hierarchy. An identity has a Name, and contains zero or more keys, at most one of which is set as the default key of this identity. Properties of a key can be accessed after obtaining a PibKey object. Create a PibIdentity which uses the impl backend implementation. This constructor should only be called by PibIdentityContainer.
Parameters:
Name Type Description
impl PibIdentityImpl The PibIdentityImpl.
Source:

Methods

addKeyPromise_(key, keyName, useSync) → {Promise|SyncPromise}

Add the key. If a key with the same name already exists, overwrite the key. If no default key for the identity has been set, then set the added key as default for the identity. This should only be called by KeyChain.
Parameters:
Name Type Description
key Buffer The public key bits. This copies the buffer.
keyName Name The name of the key. This copies the name.
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 which returns the PibKey object, or a promise rejected with Error if the backend implementation instance is invalid.
Type
Promise | SyncPromise

getDefaultKey(onComplete, onError) → {PibKey}

Get the default key of this Identity.
Parameters:
Name Type Description
onComplete function (optional) This calls onComplete(key) with the PibKey object of the default key. If omitted, the return value is described below. (Some database libraries only use a callback, so onComplete is required to use these.) 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 (optional) If defined, then onComplete must be defined and if there is an exception, then this calls onError(exception) with the exception. 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.) 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:
Throws:
Pib.Error if the default key has not been set, or Error if the backend implementation instance is invalid. However, if onComplete and onError are defined, then if there is an exception return undefined and call onError(exception).
Returns:
If onComplete is omitted, return the PibKey object of the default key. Otherwise, if onComplete is supplied then return undefined and use onComplete as described above.
Type
PibKey

getDefaultKeyPromise(useSync) → {Promise|SyncPromise}

Get the default key of this Identity.
Parameters:
Name Type Description
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 which returns the PibKey object of the default key, or a promise rejected with Pib.Error if the default key has not been set, or a promise rejected with Error if the backend implementation instance is invalid.
Type
Promise | SyncPromise

getKey(keyName, onComplete, onError) → {PibKey}

Get the key with name keyName.
Parameters:
Name Type Description
keyName Name The name of the key.
onComplete function (optional) This calls onComplete(key) with the PibKey object. If omitted, the return value is described below. (Some database libraries only use a callback, so onComplete is required to use these.) 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 (optional) If defined, then onComplete must be defined and if there is an exception, then this calls onError(exception) with the exception. 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.) 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:
Throws:
Pib.Error if the key does not exist, or Error if the backend implementation instance is invalid. However, if onComplete and onError are defined, then if there is an exception return undefined and call onError(exception).
Returns:
If onComplete is omitted, return the PibKey object. Otherwise, if onComplete is supplied then return undefined and use onComplete as described above.
Type
PibKey

getKeyPromise(keyName, useSync) → {Promise|SyncPromise}

Get the key with name keyName.
Parameters:
Name Type Description
keyName Name The name of the 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 which returns the PibKey object, or a promise rejected with Pib.Error if the key does not exist, or a promise rejected with Error if the backend implementation instance is invalid.
Type
Promise | SyncPromise

getKeys_() → {PibKeyContainer}

Get the PibKeyContainer in the PibIdentityImpl. This should only be called by KeyChain.
Source:
Returns:
The PibKeyContainer.
Type
PibKeyContainer

getName() → {Name}

Get the name of the identity.
Source:
Throws:
Error if the backend implementation instance is invalid.
Returns:
The name of the identity. You must not change the Name object. If you need to change it then make a copy.
Type
Name

lock_() → {PibIdentityImpl}

Check the validity of the impl_ instance.
Source:
Throws:
Error if the backend implementation instance is invalid.
Returns:
The PibIdentityImpl when the instance is valid.
Type
PibIdentityImpl

removeKeyPromise_(keyName, useSync) → {Promise|SyncPromise}

Remove the key with keyName and its related certificates. If the key does not exist, do nothing. This should only be called by KeyChain.
Parameters:
Name Type Description
keyName Name The name of the 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 which fulfills when finished, or a promise rejected with Error if the backend implementation instance is invalid.
Type
Promise | SyncPromise

setDefaultKeyPromise_(key, keyName, useSync) → {SyncPromise}

setDefaultKey has two forms: setDefaultKey(keyName, useSync) - Set the key with name keyName as the default key of the identity. setDefaultKey(key, keyName, useSync) - Add a key with name keyName and set it as the default key of the identity. This should only be called by KeyChain.
Parameters:
Name Type Description
key Buffer The buffer of encoded key bytes. (This is only used when calling setDefaultKey(key, keyName). )
keyName Name The name of the key. This copies the name.
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 which returns the PibKey object of the default key, or a promise rejected with Error the name of the key does not match the identity name (or if the backend implementation instance is invalid), or a promise rejected with Pib.Error if calling setDefaultKey(keyName) and the key does not exist, or if calling setDefaultKey(key, keyName) and a key with the same name already exists.
Type
SyncPromise