Class: SdsdkZtdf
The SdsdkZtdf
class represents a container of encrypted data in the Zero Trust Data Format (ZTDF). It contains the methods and properties needed to manage the encrypted data and its associated manifest.
Properties
manifest
- Type:
ZtdfManifest
- Description: The manifest associated with the encrypted data.
payload
- Type:
Uint8Array
- Description: The encrypted data as a byte array.
b64Payload
- Type:
string
- Description: The encrypted data as a Base64-encoded string.
Methods
toJson()
- Description: Converts the instance to a serializable JSON object.
- Returns: A JSON object containing the metadata, Base64-encoded payload, and associated manifest.
fromJson(input)
- Description: Creates a new
SdsdkZtdf
instance from a JSON object. - Parameters:
input
: The JSON object to convert.
- Returns: A new
SdsdkZtdf
instance. - Throws:
SdsdkError
if the input is invalid or required properties are missing.
Example Usage
javascript
const jsonData = {
metadata: {
version: 1,
},
b64payload: 'aBase64EncodedString',
manifest: {
// Manifest properties
},
};
const ztdfInstance = SdsdkZtdf.fromJson(jsonData);
// Accessing instance properties
console.log(ztdfInstance.manifest);
console.log(ztdfInstance.payload);
console.log(ztdfInstance.b64Payload);
// Converting the instance to a JSON object
const jsonData2 = ztdfInstance.toJson();
console.log(jsonData2);
// Serialize into base64 data
b64OfZtdfInstance = Buffer.from(JSON.stringify(jsonData2)).toString('base64');