Skip to content

Commit f18ccbd

Browse files
chore(cat-voices): adapt signed documents paring (#3823)
* chore: adapt signed documents paring * chore: rename + throw exception for invalid signed docs
1 parent 13df13e commit f18ccbd

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/signed_document/signed_document_manager_impl.dart

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ final class SignedDocumentManagerImpl implements SignedDocumentManager {
4646
contentType: metadata.contentType,
4747
);
4848

49+
final signers = coseSign.signatures.map((e) => e.decodeCatalystId()).nonNulls.toList();
50+
4951
return _CoseSignedDocument(
5052
coseSign: coseSign,
5153
payload: payload,
52-
metadata: DocumentDataMetadata(
53-
contentType: DocumentContentType.json,
54-
type: DocumentType.proposalDocument,
55-
id: const SignedDocumentRef(id: 'id', ver: 'ver'),
56-
),
57-
signers: coseSign.signatures.map((e) => e.decodeCatalystId()).nonNulls.toList(),
54+
metadata: metadata.toModel(authors: signers),
55+
signers: signers,
5856
);
5957
}
6058

@@ -193,6 +191,43 @@ final class _CoseSignedDocument with EquatableMixin implements SignedDocument {
193191
}
194192
}
195193

194+
extension on SignedDocumentMetadata {
195+
DocumentDataMetadata toModel({
196+
List<CatalystId>? authors,
197+
}) {
198+
final id = this.id;
199+
final ver = this.ver;
200+
201+
if (id == null) {
202+
throw const FormatException('Signed document id was null');
203+
}
204+
if (ver == null) {
205+
throw const FormatException('Signed document ver was null');
206+
}
207+
208+
return DocumentDataMetadata(
209+
contentType: DocumentContentType.json,
210+
type: documentType,
211+
id: SignedDocumentRef(id: id, ver: ver),
212+
ref: ref?.toModel(),
213+
template: template?.toModel(),
214+
reply: reply?.toModel(),
215+
section: section,
216+
collaborators: collabs?.map(CatalystId.tryParse).nonNulls.toList(),
217+
parameters: DocumentParameters({
218+
?brandId?.toModel(),
219+
?campaignId?.toModel(),
220+
?categoryId?.toModel(),
221+
}),
222+
authors: authors,
223+
);
224+
}
225+
}
226+
227+
extension on SignedDocumentMetadataRef {
228+
SignedDocumentRef toModel() => SignedDocumentRef(id: id, ver: ver);
229+
}
230+
196231
extension _CoseSignatureExt on CoseSignature {
197232
CatalystId? decodeCatalystId() {
198233
final kid = protectedHeaders.kid;

0 commit comments

Comments
 (0)