-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updating DIDComm protocols closer to specification
Signed-off-by: Curtish <[email protected]>
- Loading branch information
Showing
20 changed files
with
651 additions
and
657 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 24 additions & 17 deletions
41
src/edge-agent/protocols/issueCredential/CredentialPreview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import { ProtocolType } from "../ProtocolTypes"; | ||
import { Nil, isArray, isObject, notEmptyString } from "../../../utils"; | ||
|
||
/** | ||
* Specification: | ||
* https://github.com/decentralized-identity/waci-didcomm/tree/main/issue_credential#preview-credential | ||
*/ | ||
|
||
export interface CredentialPreview { | ||
// type: ProtocolType.DidcommCredentialPreview; | ||
type: string; | ||
id?: string; | ||
body: { | ||
attributes: Attribute[]; | ||
}; | ||
} | ||
|
||
export interface Attribute { | ||
name: string; | ||
value: string; | ||
mimeType?: string; | ||
media_type?: string | Nil; | ||
} | ||
|
||
export interface CredentialPreview { | ||
type: ProtocolType.DidcommCredentialPreview; | ||
attributes: Attribute[]; | ||
} | ||
export const validateCredentialPreview = (value: unknown): value is CredentialPreview => isObject(value) | ||
&& notEmptyString(value.type) | ||
&& isObject(value.body) | ||
&& isArray(value.body.attributes) | ||
&& value.body.attributes.every(validateAttribute); | ||
|
||
export function createCredentialPreviewAttribute( | ||
name: string, | ||
value: string, | ||
mimeType?: string | ||
): Attribute { | ||
return { | ||
name, | ||
value, | ||
mimeType, | ||
}; | ||
} | ||
const validateAttribute = (value: unknown): value is Attribute => isObject(value) | ||
&& notEmptyString(value.name) | ||
&& notEmptyString(value.value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.