Skip to content

Commit

Permalink
feat: generic attachment handler
Browse files Browse the repository at this point in the history
fixed fct declaration and henceforth tests

Co-authored-by: annelein <anneleinvanreijen@gmail.com>

Signed-off-by: morrieinmaas <moritz@animo.id>
  • Loading branch information
morrieinmaas committed Dec 15, 2021
1 parent 92acbb6 commit eed46e3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/decorators/attachment/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class AttachmentData {
}
}

public getDataAsJson = () => {
public getDataAsJson() {
if (this.base64 !== null && typeof this.base64 === 'string') {
return JsonEncoder.fromBase64(this.base64)
} else if (this.json !== null) {
return this.json
} else {
throw new AriesFrameworkError('No data available.')
throw new AriesFrameworkError('No attachment data available.')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class IssueCredentialMessage extends AgentMessage {
const attachment = this.credentialAttachments.find((attachment) => attachment.id === INDY_CREDENTIAL_ATTACHMENT_ID)

// Extract credential from attachment
const credentialJson = attachment ? attachment.data.getDataAsJson() : null
const credentialJson = attachment?.data ? attachment.data.getDataAsJson() : null

return credentialJson
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class OfferCredentialMessage extends AgentMessage {
const attachment = this.offerAttachments.find((attachment) => attachment.id === INDY_CREDENTIAL_OFFER_ATTACHMENT_ID)

// Extract credential offer from attachment
const credentialOfferJson = attachment ? attachment.data.getDataAsJson() : null
const credentialOfferJson = attachment?.data ? attachment.data.getDataAsJson() : null

return credentialOfferJson
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class RequestCredentialMessage extends AgentMessage {
(attachment) => attachment.id === INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID
)
// Extract proof request from attachment
const credentialReqJson = attachment ? attachment.data.getDataAsJson() : null
const credentialReqJson = attachment?.data ? attachment.data.getDataAsJson() : null

return credentialReqJson
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ export class PresentationMessage extends AgentMessage {
public get indyProof(): IndyProof | null {
const attachment = this.presentationAttachments.find((attachment) => attachment.id === INDY_PROOF_ATTACHMENT_ID)

// Return null if attachment is not found
if (!attachment?.data?.base64) {
return null
}

const proofJson = JsonEncoder.fromBase64(attachment.data.base64)
const proofJson = attachment?.data ? attachment.data.getDataAsJson() : null

return proofJson
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class RequestPresentationMessage extends AgentMessage {
(attachment) => attachment.id === INDY_PROOF_REQUEST_ATTACHMENT_ID
)
// Extract proof request from attachment
const proofRequestJson = attachment ? attachment.data.getDataAsJson() : null
const proofRequestJson = attachment?.data ? attachment.data.getDataAsJson() : null
const proofRequest = JsonTransformer.fromJSON(proofRequestJson, ProofRequest)

return proofRequest
Expand Down

0 comments on commit eed46e3

Please sign in to comment.