Skip to content

Commit

Permalink
feat: Add JSON-LD Credential and Presentation handling/sign support t…
Browse files Browse the repository at this point in the history
…hat is compatible with React-Native
  • Loading branch information
nklomp committed Nov 28, 2021
1 parent 143927c commit 995f55e
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 45 deletions.
19 changes: 13 additions & 6 deletions packages/ssi-sdk-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,42 @@

---

__Warning: This package still is in every early development. Breaking changes without notice will happen at this point!__
**Warning: This package still is in every early development. Breaking changes without notice will happen at this point!**

---

# ssi-sdk-core
A Veramo plugin whit types/interfaces and utility functions shared by multiple plugins

A Veramo plugin whit types/interfaces and utility functions shared by multiple plugins

### Installation

```shell
yarn add @sphereon/ssi-sdk-core
```

### Build

```shell
yarn build
```

### Test

The test command runs:
* `prettier`
* `jest`
* `coverage`

- `prettier`
- `jest`
- `coverage`

You can also run only a single section of these tests, using for example `yarn test:unit`.

```shell
yarn test
```

### Utility scripts

There are other utility scripts that help with development.

* `yarn fix` - runs `eslint --fix` as well as `prettier` to fix code style.
- `yarn fix` - runs `eslint --fix` as well as `prettier` to fix code style.
4 changes: 2 additions & 2 deletions packages/ssi-sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
},
"dependencies": {
"@sphereon/did-uni-client": "^0.3.3",
"@veramo/core": "^3.1.0",
"@veramo/did-manager": "^3.1.0",
"@veramo/core": "^3.1.1-next.12",
"@veramo/did-manager": "^3.1.1-next.12",
"debug": "^4.1.1",
"did-jwt-vc": "^2.1.7",
"events": "^3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ssi-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './utils';
export * from './types';
export * from './utils'
export * from './types'
34 changes: 0 additions & 34 deletions packages/ssi-sdk-core/src/types/ICredential.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/ssi-sdk-core/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './ICredential'
export * from './vc-data-models'
export * from './presentation-exchange'
30 changes: 30 additions & 0 deletions packages/ssi-sdk-core/src/types/presentation-exchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export interface PresentationSubmission {
/**
* A UUID or some other unique ID to identify this Presentation Submission
*/
id: string
/**
* A UUID or some other unique ID to identify this Presentation Definition
*/
definition_id: string
/**
* List of descriptors of how the claims are being mapped to presentation definition
*/
descriptor_map: Array<Descriptor>
}

export interface Descriptor {
/**
* ID to identify the descriptor from Presentation Definition Input Descriptor it coresponds to.
*/
id: string
/**
* The path where the verifiable credential is located in the presentation submission json
*/
path: string
path_nested?: Descriptor
/**
* The Proof or JWT algorith that the proof is in
*/
format: string
}
38 changes: 38 additions & 0 deletions packages/ssi-sdk-core/src/types/signatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ProofPurpose, SignatureTypes } from './vc-data-models'

export interface ProofOptions {
/**
* The signature type. For instance RsaSignature2018
*/
type?: SignatureTypes | string

/**
* Type supports selective disclosure?
*/
typeSupportsSelectiveDisclosure?: boolean

/**
* A challenge protecting against replay attacks
*/
challenge?: string

/**
* A domain protecting against replay attacks
*/
domain?: string

/**
* The purpose of this proof, for instance assertionMethod or authentication, see https://www.w3.org/TR/vc-data-model/#proofs-signatures-0
*/
proofPurpose?: ProofPurpose | string

/**
* The ISO8601 date-time string for creation. You can update the Proof value later in the callback. If not supplied the current date/time will be used
*/
created?: string

/**
* Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
*/
nonce?: string
}
94 changes: 94 additions & 0 deletions packages/ssi-sdk-core/src/types/vc-data-models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
VerifiablePresentation,
CompactJWT,
UnsignedCredential,
CredentialSubject,
VerifiableCredential,
UnsignedPresentation,
ProofType,
CredentialStatus,
} from '@veramo/core'
import { PresentationSubmission } from './presentation-exchange'

export type W3CVerifiablePresentationSP = VerifiablePresentation | VerifiablePresentationSP | CompactJWT
export type W3CVerifiableCredentialSP = VerifiableCredential | VerifiableCredentialSP | CompactJWT

export enum SignatureTypes {
Ed25519Signature2018 = 'Ed25519Signature2018',
Ed25519Signature2020 = 'Ed25519Signature2020',
EcdsaSecp256k1Signature2019 = 'EcdsaSecp256k1Signature2019',
EcdsaSecp256k1RecoverySignature2020 = 'EcdsaSecp256k1RecoverySignature2020',
JsonWebSignature2020 = 'JsonWebSignature2020',
RsaSignature2018 = 'RsaSignature2018',
GpgSignature2020 = 'GpgSignature2020',
JcsEd25519Signature2020 = 'JcsEd25519Signature2020',
BbsBlsSignatureProof2020 = 'BbsBlsSignatureProof2020',
BbsBlsBoundSignatureProof2020 = 'BbsBlsBoundSignatureProof2020',
}

export enum ProofPurpose {
assertionMethod = 'assertionMethod',
authentication = 'authentication',
keyAgreement = 'keyAgreement',
contractAgreement = 'contactAgreement',
capabilityInvocation = 'capabilityInvocation',
capabilityDelegation = 'capabilityDelegation',
}

export interface CredentialStatusSP extends CredentialStatus {
id: string
type: string
revocationListIndex?: string
revocationListCredential?: string
}

/*export interface ICredentialIssuer {
id: string
[x: string]: unknown
}*/

/*export interface ICredentialSubject {
id?: string
[x: string]: unknown
}*/

export interface CredentialProofSP extends ProofType {
type: string | SignatureTypes // The proof type
created: string // The ISO8601 date-time string for creation
proofPurpose: ProofPurpose | string // The specific intent for the proof
verificationMethod: string // A set of parameters required to independently verify the proof
challenge?: string // A challenge to protect against replay attacks
domain?: string // A string restricting the (usage of a) proof to the domain and protects against replay attacks
proofValue?: string // One of any number of valid representations of proof values
jws?: string // JWS based proof
nonce?: string // Similar to challenge. A nonce to protect against replay attacks, used in some ZKP proofs
requiredRevealStatements?: string[] // The parts of the proof that must be revealed in a derived proof

[x: string]: string | string[] | undefined
}

export interface UnsignedCredentialSP extends UnsignedCredential {
credentialSubject: CredentialSubject[] | CredentialSubject
credentialStatus?: CredentialStatusSP
validFrom?: string
validUntil?: string
}

export interface VerifiableCredentialSP extends UnsignedCredentialSP {
proof: CredentialProofSP | CredentialProofSP[]
}

export interface UnsignedPresentationSP extends UnsignedPresentation {
type: string[] | string
verifiableCredential: W3CVerifiableCredentialSP[]
presentation_submission?: PresentationSubmission

[x: string]: any
}

export interface VerifiablePresentationSP extends UnsignedPresentationSP {
// Last one is from Veramo
proof: CredentialProofSP | CredentialProofSP[] | { proof: ProofType }
}

0 comments on commit 995f55e

Please sign in to comment.