Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anoncreds): add legacy indy credential format #1220

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/anoncreds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
"test": "jest"
},
"dependencies": {
"@aries-framework/core": "0.3.3"
"@aries-framework/core": "0.3.3",
"@aries-framework/node": "0.3.3",
TimoGlastra marked this conversation as resolved.
Show resolved Hide resolved
"bn.js": "^5.2.1"
},
"devDependencies": {
"indy-sdk": "^1.16.0-dev-1636",
"rimraf": "^4.0.7",
"typescript": "~4.9.4"
}
Expand Down
89 changes: 89 additions & 0 deletions packages/anoncreds/src/formats/AnonCredsCredentialFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import type { AnonCredsCredential, AnonCredsCredentialOffer, AnonCredsCredentialRequest } from '../models'
import type { CredentialPreviewAttributeOptions, CredentialFormat, LinkedAttachment } from '@aries-framework/core'

/**
* This defines the module payload for calling CredentialsApi.createProposal
* or CredentialsApi.negotiateOffer
*/
export interface AnonCredsProposeCredentialFormat {
schemaIssuerId?: string
schemaId?: string
schemaName?: string
schemaVersion?: string

credentialDefinitionId?: string
issuerId?: string

attributes?: CredentialPreviewAttributeOptions[]
linkedAttachments?: LinkedAttachment[]

// Kept for backwards compatibility
schemaIssuerDid?: string
issuerDid?: string
}

/**
* This defines the module payload for calling CredentialsApi.acceptProposal
*/
export interface AnonCredsAcceptProposalFormat {
credentialDefinitionId?: string
attributes?: CredentialPreviewAttributeOptions[]
linkedAttachments?: LinkedAttachment[]
}

/**
* This defines the module payload for calling CredentialsApi.acceptOffer. No options are available for this
* method, so it's an empty object
*/
export type AnonCredsAcceptOfferFormat = Record<string, never>

/**
* This defines the module payload for calling CredentialsApi.offerCredential
* or CredentialsApi.negotiateProposal
*/
export interface AnonCredsOfferCredentialFormat {
credentialDefinitionId: string
attributes: CredentialPreviewAttributeOptions[]
linkedAttachments?: LinkedAttachment[]
}

/**
* This defines the module payload for calling CredentialsApi.acceptRequest. No options are available for this
* method, so it's an empty object
*/
export type AnonCredsAcceptRequestFormat = Record<string, never>

export interface AnonCredsCredentialFormat extends CredentialFormat {
formatKey: 'anoncreds'
credentialRecordType: 'anoncreds'
credentialFormats: {
createProposal: AnonCredsProposeCredentialFormat
acceptProposal: AnonCredsAcceptProposalFormat
createOffer: AnonCredsOfferCredentialFormat
acceptOffer: AnonCredsAcceptOfferFormat
createRequest: never // cannot start from createRequest
acceptRequest: AnonCredsAcceptRequestFormat
}
// TODO: update to new RFC once available
// Format data is based on RFC 0592
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0592-indy-attachments
formatData: {
proposal: {
schema_issuer_id?: string
schema_name?: string
schema_version?: string
schema_id?: string

cred_def_id?: string
issuer_id?: string

// TODO: we don't necessarily need to include these in the AnonCreds Format RFC
// as it's a new one and we can just forbid the use of legacy properties
schema_issuer_did?: string
issuer_did?: string
}
offer: AnonCredsCredentialOffer
request: AnonCredsCredentialRequest
credential: AnonCredsCredential
}
}
67 changes: 67 additions & 0 deletions packages/anoncreds/src/formats/LegacyIndyCredentialFormat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type {
AnonCredsAcceptOfferFormat,
AnonCredsAcceptProposalFormat,
AnonCredsAcceptRequestFormat,
AnonCredsOfferCredentialFormat,
} from './AnonCredsCredentialFormat'
import type { AnonCredsCredential, AnonCredsCredentialOffer, AnonCredsCredentialRequest } from '../models'
import type { CredentialPreviewAttributeOptions, CredentialFormat, LinkedAttachment } from '@aries-framework/core'

/**
* This defines the module payload for calling CredentialsApi.createProposal
* or CredentialsApi.negotiateOffer
*
* NOTE: This doesn't include the `issuerId` and `schemaIssuerId` properties that are present in the newer format.
*/
export interface LegacyIndyProposeCredentialFormat {
schemaIssuerDid?: string
schemaId?: string
schemaName?: string
schemaVersion?: string

credentialDefinitionId?: string
issuerDid?: string

attributes?: CredentialPreviewAttributeOptions[]
linkedAttachments?: LinkedAttachment[]
}

export interface LegacyIndyCredentialRequest extends AnonCredsCredentialRequest {
// prover_did is optional in AnonCreds credential request, but required in legacy format
prover_did: string
}

export interface LegacyIndyCredentialFormat extends CredentialFormat {
formatKey: 'indy'

// The stored type is the same as the anoncreds credential service
credentialRecordType: 'anoncreds'

// credential formats are the same as the AnonCreds credential format
credentialFormats: {
// The createProposal interface is different between the interfaces
createProposal: LegacyIndyProposeCredentialFormat
acceptProposal: AnonCredsAcceptProposalFormat
createOffer: AnonCredsOfferCredentialFormat
acceptOffer: AnonCredsAcceptOfferFormat
createRequest: never // cannot start from createRequest
acceptRequest: AnonCredsAcceptRequestFormat
}

// Format data is based on RFC 0592
// https://github.com/hyperledger/aries-rfcs/tree/main/features/0592-indy-attachments
formatData: {
proposal: {
schema_name?: string
schema_issuer_did?: string
schema_version?: string
schema_id?: string

cred_def_id?: string
issuer_did?: string
}
offer: AnonCredsCredentialOffer
request: LegacyIndyCredentialRequest
credential: AnonCredsCredential
}
}
Loading