forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from blu3beri/feat/w3crecord
feat(core): w3cCredentialRecord and w3cCredentialRepository
- Loading branch information
Showing
8 changed files
with
145 additions
and
30 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
39 changes: 23 additions & 16 deletions
39
packages/core/src/modules/vc/models/credential/W3cCredentialRecord.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,35 +1,42 @@ | ||
import type { TagsBase } from '../../../../storage/BaseRecord' | ||
|
||
import { Type } from 'class-transformer' | ||
import jsonld from 'jsonld' | ||
|
||
import { BaseRecord } from '../../../../storage/BaseRecord' | ||
import { uuid } from '../../../../utils/uuid' | ||
|
||
import { W3cVerifiableCredential } from './W3cVerifiableCredential' | ||
|
||
export interface W3cCredentialRecordOptions { | ||
id?: string | ||
createdAt?: Date | ||
credential: W3cVerifiableCredential | ||
tags: CustomW3cCredentialTags | ||
} | ||
|
||
/** | ||
* K-TODO: Set the appropriate tags | ||
* @see https://github.com/hyperledger/aries-cloudagent-python/blob/e77d087bdd5f1f803616730e33d4e3f0801b5f8d/aries_cloudagent/storage/vc_holder/xform.py | ||
* | ||
* NOTE: Credential.type entries need to be expanded before storing them as tags | ||
*/ | ||
export class W3cCredentialRecord extends BaseRecord { | ||
public constructor(options: W3cCredentialRecordOptions) { | ||
super() | ||
if (options) { | ||
this.credential = options.credential | ||
} | ||
} | ||
export type CustomW3cCredentialTags = TagsBase & { | ||
expandedTypes?: Array<string> | ||
} | ||
|
||
export class W3cCredentialRecord extends BaseRecord<TagsBase, CustomW3cCredentialTags> { | ||
public static readonly type = 'W3cCredentialRecord' | ||
public readonly type = W3cCredentialRecord.type | ||
|
||
@Type(() => W3cVerifiableCredential) | ||
public credential!: W3cVerifiableCredential | ||
|
||
public getTags(): TagsBase { | ||
return { | ||
...this._tags, | ||
public constructor(props: W3cCredentialRecordOptions) { | ||
super() | ||
if (props) { | ||
this.id = props.id ?? uuid() | ||
this.createdAt = props.createdAt ?? new Date() | ||
this._tags = props.tags | ||
this.credential = props.credential | ||
} | ||
} | ||
|
||
public getTags() { | ||
return this._tags | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/core/src/modules/vc/models/credential/W3cCredentialRepository.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { inject, scoped, Lifecycle } from 'tsyringe' | ||
|
||
import { InjectionSymbols } from '../../../../constants' | ||
import { Repository } from '../../../../storage/Repository' | ||
import { StorageService } from '../../../../storage/StorageService' | ||
|
||
import { W3cCredentialRecord } from './W3cCredentialRecord' | ||
|
||
@scoped(Lifecycle.ContainerScoped) | ||
export class W3cCredentialRepository extends Repository<W3cCredentialRecord> { | ||
public constructor(@inject(InjectionSymbols.StorageService) storageService: StorageService<W3cCredentialRecord>) { | ||
super(W3cCredentialRecord, storageService) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/core/src/modules/vc/models/credential/W3cCredentialState.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Issue Credential states as defined in RFC 0453 | ||
* | ||
* @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0453-issue-credential-v2/README.md#states | ||
*/ | ||
export enum W3cCredentialState { | ||
ProposalSent = 'proposal-sent', | ||
ProposalReceived = 'proposal-received', | ||
OfferSent = 'offer-sent', | ||
OfferReceived = 'offer-received', | ||
RequestSent = 'request-sent', | ||
RequestReceived = 'request-received', | ||
CredentialIssued = 'credential-issued', | ||
CredentialReceived = 'credential-received', | ||
Done = 'done', | ||
} |
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
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