# Lit Verifiable Credentials SDK

### Installation:
`yarn add lit-vc-sdk`

`npm install lit-vc-sdk`

### Usage

The lit-vc-sdk uses Ceramic to store conditions.  By default, the SDK connects to the Ceramic Clay Testnet.  This can be changed
by adding `CERAMIC_NETWORK="<your desired network address>"` to the .env

## Planned functions and status (Sept 2022)

### Issuer Functions

| Function                                     | Description                                               | Status   |
|----------------------------------------------|-----------------------------------------------------------|----------|
| [issueCredential](#issueCredential-function) | issue and sign a verifiable credential (VC) to a receiver | beta     |
| revokeCredential                             | revoke previously issues credential                       | not done |

### Receiver/User Functions

| Function                                               | Description                                               | Status   |
|--------------------------------------------------------|-----------------------------------------------------------|----------|
| [verifyCredential](#verifyCredential-function)         | verify an issued credential                               | beta     |
| [generatePresentation](#generatePresentation-function) | generate a verifiable presentation (VP) for a selected VC | beta     |
| acceptCredential                                       | accept a credential issued to a the user                  | not done |
| burnCredential                                         | remove a previously issued credential                     | not done |
| requestCredential                                      | request a credential from an issuer                       | not done |
| transferCredential                                     | transfer a credential to another PKP                      | not done |

### Verifier Functions

| Function                                           | Description                         | Status   |
|----------------------------------------------------|-------------------------------------|----------|
| [verifyPresentation](#verifyPresentation-function) | verify an issued VP                 | beta     |
| requestDecryption                                  | request decryption rights over a VP | not done |


## Functions

---

### issueCredential <a name="issueCredential-function"></a>

issues a verifiable credential to a receiver

```
issueCredential(credential: Credential, proof: Proof, recipient: string): Promise<IssueCredentialResponse>
```

*Parameters*

**credential** ([Credential](#credential-interface)): credential object

**receiver** (string): PKP Public key of VC receiving party 

*Returns*

[//]: # (Promise<[IssueCredentialResponse]&#40;#issue-credential-response-interface&#41;>: A promise containing the Ceramic stream ID of the stored VC, and the dataSigned string to verify &#40;What is this actually called?&#41;)

**Promise\<string>**: A promise containing the Ceramic stream ID of the stored VC

---

### verifyCredential <a name="verifyCredential-function"></a>

verifies a previously issued credential

```
verifyCredential(vcId: string, issuer: string): Promise<any>
```

*Parameters*

**vcId**(string): the Ceramic stream ID of the credential to verify

**issuer**(string): the PKP public key of the VC owner

*Returns*

**Promise\<[VerifyCredentialResponse](#verify-credential-response-interface)>**: A promise containing an object that includes a boolean `verified` property, as well as the verified credential obj.

---

### generatePresentation <a name="generatePresentation-function"></a>

generates a VP for a given VC

```
generatePresentation(presentation: Presentation, credential: Credential[], issuer: string): Promise<any>
```

*Parameters*

**presentation** ([Presentation](#presentation-interface)): the presentation object

**credential** ([Credential](#credential-interface)[]): an array of the credentials to include in the VP

**issuer** (string): the PKP public key of the party issuing the VP

*Returns*

**Promise\<[GeneratePresentationResponse](#generate-presentation-response-interface)>**: A promise containing the Ceramic stream ID of the stored VP

---

### verifyPresentation <a name="verifyPresentation-function"></a>

verifies a previously issued presentation and the contained credentials

```
verifyPresentation(vcId: string, issuer: string): Promise<VerifyPresentationResponse>
```

*Parameters*

**vcId**(string): the Ceramic stream ID of the presentation to verify

**issuer**(string): the PKP public key of the VC owner

*Returns*

**Promise\<[VerifyPresentationResponse](#verify-presentation-response-interface)>**: A promise containing an object that includes a boolean `verified` property, as well as the verified presentation obj.

---

## Types

---

**Credential**<a name="credential-interface"></a>
```
interface Credential {
  "@context": string[],
  id: string,
  type: string[],
  issuer: string,
  issuanceDate: string,
  credentialSubject: CredentialSubject,
  proof?: Proof
}
```

**Presentation**<a name="presentation-interface"></a>
```
interface Presentation {
  "@context": string[],
  type: string,
  proof?: Proof,
  issuer?: string
  verifiableCredential?: Credential[]
}
```

**Proof**<a name="proof-interface"></a>
```
interface Proof {
  type: string,
  created: string,
  proofPurpose: string,
  verificationMethod: string,
  jws: string
}
```

**VerifyCredentialResponse**<a name="verify-credential-response-interface"></a>
```
interface VerifyCredentialResponse {
  recoveredCredential: Credential
  verified: boolean
}
```

**GeneratePresentationResponse**<a name="generate-presentation-response-interface"></a>
```
interface GeneratePresentationResponse {
  docId: string,
  presentation: Presentation
}
```

**VerifyPresentationResponse**<a name="verify-presentation-response-interface"></a>
```
interface VerifyPresentationResponse {
  recoveredPresentation: Presentation
  verified: boolean
}
```