toLegacy static method
Converts the provided commercioDoc
and returns a legacy.CommercioDoc
version compatible with a 2.1 chain.
Implementation
static legacy.CommercioDoc toLegacy(CommercioDoc commercioDoc) {
legacy.CommercioDocMetadataSchema? metadataSchema;
if (commercioDoc.metadata.schema != null) {
metadataSchema = legacy.CommercioDocMetadataSchema(
uri: commercioDoc.metadata.schema!.uri,
version: commercioDoc.metadata.schema!.version,
);
}
final metadata = legacy.CommercioDocMetadata(
contentUri: commercioDoc.metadata.contentUri,
schema: metadataSchema,
schemaType: commercioDoc.metadata.schemaType ?? '',
);
legacy.CommercioDocChecksum? checksum;
if (commercioDoc.checksum != null) {
checksum = legacy.CommercioDocChecksum(
algorithm: _checksumAlgorithmToLegacy(commercioDoc.checksum!.algorithm),
value: commercioDoc.checksum!.value,
);
}
legacy.CommercioDoSign? doSign;
if (commercioDoc.doSign != null) {
doSign = legacy.CommercioDoSign(
certificateProfile: commercioDoc.doSign!.certificateProfile,
signerIstance: commercioDoc.doSign!.signerIstance,
storageUri: commercioDoc.doSign!.storageUri,
vcrId: commercioDoc.doSign!.vcrId,
sdnData: commercioDoc.doSign!.sdnData
?.map((e) => _sdnDataToLegacy(e))
.toList(),
);
}
legacy.CommercioDocEncryptionData? encryptionData;
if (commercioDoc.encryptionData != null) {
encryptionData = legacy.CommercioDocEncryptionData(
encryptedData: commercioDoc.encryptionData!.encryptedData
.map((e) => e.value)
.toList(),
keys: commercioDoc.encryptionData!.keys
.map((e) => _encryptionDataKeyToLegacy(e))
.toList(),
);
}
return legacy.CommercioDoc(
senderDid: commercioDoc.senderDid,
recipientDids: commercioDoc.recipientDids,
uuid: commercioDoc.uuid,
metadata: metadata,
contentUri: commercioDoc.contentUri,
checksum: checksum,
doSign: doSign,
encryptionData: encryptionData,
);
}