Class: SharedContainer
container.SharedContainer
The SharedContainer
is used to securely share data between a number of
accessors using a shared-key encryption scheme where the content data is
encrypted using a randomly generated shared key that is then encrypted with each
accessors public key and stored along the encrypted data. Accessors can then
retrieve the shared key by decrypting it using their private key and use it to
recover the original data.
Hierarchy
Constructors
constructor
• new SharedContainer()
Inherited from
Properties
_key
• Protected
Optional
_key: Uint8Array
The key used for encryption. Sub classes must set this property in the unlock method.
Inherited from
Defined in
_propertySerializationOptions
• _propertySerializationOptions:
SerializationOptions
[]
Inherited from
BaseContainer._propertySerializationOptions
Defined in
accessors
• accessors: Accessor
[] = []
The ids and encrypted keys of all accessors
Defined in
encryptedData
• Optional
encryptedData: Uint8Array
Encrypted data
Inherited from
Defined in
encryptionParams
• encryptionParams: AESEncryptionParams
Parameters used for encryption of content data
Inherited from
BaseContainer.encryptionParams
Defined in
keyParams
• keyParams: RSAEncryptionParams
Parameters used to wrap the shared encryption key
Defined in
Accessors
kind
• get
kind(): string
A string representing the objects "type", useful for segmenting storage, among other things. Defaults to the lowercase class name, but can be overwritten by subclasses
Returns
string
Inherited from
BaseContainer.kind
Defined in
Methods
_fromRaw
▸ Protected
_fromRaw(raw
): void
Restore values from a raw object. The default implementation simply copies over all iterable properties from the base object. Overwrite this method for properties that require special treatment
Parameters
Name | Type |
---|---|
raw |
any |
Returns
void
Inherited from
Defined in
_toRaw
▸ Protected
_toRaw(version
): any
Transform this object into a raw javascript object used for serialization. The default implementation simply copies all iterable properties not included in the [[exlude]] array and calls toRaw on any properties that are themselfes instances of Serializable. This method should be overwritten by subclasses if certain properties require special treatment.
Parameters
Name | Type |
---|---|
version |
undefined | string |
Returns
any
Inherited from
Defined in
clone
▸ clone(): SharedContainer
Creates a deep clone of the object
Returns
Inherited from
Defined in
fromBytes
▸ fromBytes(bytes
): SharedContainer
Deserializes the object from a byte array
Parameters
Name | Type |
---|---|
bytes |
Uint8Array |
Returns
Inherited from
Defined in
fromJSON
▸ fromJSON(json
): SharedContainer
Deserializes the object from a JSON string
Parameters
Name | Type |
---|---|
json |
string |
Returns
Inherited from
Defined in
fromRaw
▸ fromRaw(raw
): SharedContainer
Restores propertiers from a raw object of the same form generated by
toRaw. The base implementation blindly
copies over values from the raw object via Object.assign
so subclasses should
explictly process any propertyies that need special treatment.
Also takes are of validation and "upgrading" in case the raw object has an old version. Use the protected _fromRaw method to implement subclass-specific behavior.
Parameters
Name | Type |
---|---|
raw |
any |
Returns
Inherited from
Defined in
getData
▸ getData(): Promise
<Uint8Array
>
Decrypts and extracts the plain text data from the container. This will usually require unlocking the container first.
Returns
Promise
<Uint8Array
>
Inherited from
Defined in
lock
▸ lock(): void
Locks the container, removing the possibility to extract the plain text data via getData until the container is unlocked again. Subclasses extending this class must take care to delete any keys or other sensitive data that may have been stored temporarily after unlocking the container.
Returns
void
Inherited from
Defined in
setData
▸ setData(data
): Promise
<void
>
Encrypts the provided data
and stores it in the container
Parameters
Name | Type |
---|---|
data |
Uint8Array |
Returns
Promise
<void
>
Inherited from
Defined in
toBytes
▸ toBytes(): Uint8Array
Returns a serialization of the object in form of a byte array
Returns
Uint8Array
Inherited from
Defined in
toJSON
▸ toJSON(): string
Returns a JSON serialization of the object
Returns
string
Inherited from
Defined in
toRaw
▸ toRaw(version?
): any
Creates a raw javascript object representation of the class, which can be used for storage or data transmission. Also handles "downgrading" to previous versions. Use _toRaw for subclass-specific behavior.
Parameters
Name | Type |
---|---|
version? |
string |
Returns
any
Inherited from
Defined in
unlock
▸ unlock(__namedParameters
): Promise
<void
>
Unlocks the container using the id and private key of a given accessor. The id is used to look up the corresponding encrypted key while the private key is used to decrypt it.
Parameters
Name | Type |
---|---|
__namedParameters |
Object |
__namedParameters.id |
string |
__namedParameters.privateKey |
Uint8Array |
Returns
Promise
<void
>
Overrides
Defined in
updateAccessors
▸ updateAccessors(subjects
): Promise
<void
>
Updates the containers accessors, generating a new shared key and encrypting it with the public keys of the provided subjects. Non-empty containers need to be unlocked first.
Parameters
Name | Type |
---|---|
subjects |
{ id : string ; publicKey : Uint8Array }[] |
Returns
Promise
<void
>
Defined in
validate
▸ validate(): boolean
This is called during deserialization and should verify that all properties have been populated with values of the correct type. Subclasses should implement this method based on their class structure.
Returns
boolean