Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

TypeScript Refactor #19

Merged
merged 16 commits into from
Jun 19, 2020
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
30 changes: 0 additions & 30 deletions .github/workflows/integration-test.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/json-web-key-2020.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: json-web-key-2020
on: [push]
jobs:
json-web-key-2020:
runs-on: ubuntu-latest
env:
working-directory: ./packages/json-web-key-2020
steps:
- name: Begin CI...
uses: actions/checkout@v2
- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install
run: npm install
- name: Lint
working-directory: ${{ env.working-directory }}
run: npm run lint
- name: Test
working-directory: ${{ env.working-directory }}
run: npm run test
- name: Build
working-directory: ${{ env.working-directory }}
run: npm run build
25 changes: 25 additions & 0 deletions .github/workflows/json-web-signature-2020.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: json-web-signature-2020
on: [push]
jobs:
json-web-signature-2020:
runs-on: ubuntu-latest
env:
working-directory: ./packages/json-web-signature-2020
steps:
- name: Begin CI...
uses: actions/checkout@v2
- name: Use Node 12
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install
run: npm install
- name: Lint
working-directory: ${{ env.working-directory }}
run: npm run lint
- name: Test
working-directory: ${{ env.working-directory }}
run: npm run test
- name: Build
working-directory: ${{ env.working-directory }}
run: npm run build
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
coverage
8 changes: 0 additions & 8 deletions .npmignore

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
173 changes: 104 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Linked Data Signatures for JWS

![Integration Tests](https://github.com/w3c-ccg/lds-jws2020/workflows/Integration%20Tests/badge.svg) [![codecov](https://codecov.io/gh/transmute-industries/lds-jws2020/branch/master/graph/badge.svg)](https://codecov.io/gh/transmute-industries/lds-jws2020)
![json-web-signature-2020](https://github.com/w3c-ccg/lds-jws2020/workflows/json-web-signature-2020/badge.svg)

[View On Github](https://github.com/w3c-ccg/lds-jws2020)

- [View Linked Data Signature Suite Vocabulary](https://w3c-ccg.github.io/lds-jws2020/contexts/)
- [View Linked Data Signature Suite Context](https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v0.0.jsonld)


## Security Considerations

You should be aware that some of these curves are not considered safe:
Expand All @@ -20,80 +19,134 @@ If you will only ever need to support Ed25519 or only Secp256k1, you should cons

- [EcdsaSecp256k1Signature2019](https://github.com/decentralized-identity/lds-ecdsa-secp256k1-2019.js)

## Usage
## Supported JOSE Algss

The expected alg will be determined by the following table.

| kty | crvOrSize | signature | keyAgreement | encryption |
| --- | --------- | --------- | ------------ | -------------- |
| OKP | Ed25519 | EdDSA | | |
| OKP | X25519 | | ECDH | ECDH-ES+A256KW |
| EC | secp256k1 | ES256K | ECDH | |
| RSA | 2048 | PS256 | | RSA-OAEP |
| EC | P-256 | ES256 | ECDH | ECDH-ES+A256KW |
| EC | P-384 | ES384 | ECDH | ECDH-ES+A256KW |

Anything else will result in an unsupported alg error.

## Usage

Install:

```
npm i lds-jws2020 --save
npm i @transmute/json-web-signature-2020 --save
```

Use with vc-js:

```js
const key = new JsonWebKeyLinkedDataKeyClass2020({
id: `did:example:123#_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A`,
```ts
import {
JsonWebKey,
JsonWebSignature2020,
} from "@transmute/json-web-signature-2020";

// You will need a custom document loader to do pretty much anything
// with LD Proofs, especially to work with DIDs
// Search this repo for "documentLoader" to learn more.
import { documentLoader } from "../somwhere...";

const key = new JsonWebKey({
type: "JsonWebKey2020",
controller: 'did:example:123',
id: "did:example:123#DTXI1UCGeLHx3B6GmZtMQuR8b3KDdaayEYPJN8iME6o",
controller: "did:example:123",
publicKeyJwk: {
crv: "Ed25519",
x: "fJ-HI45g-LjZI6poTa122g5u6hRYzPRyJCY5pq9dfSQ",
kty: "OKP",
kid: "DTXI1UCGeLHx3B6GmZtMQuR8b3KDdaayEYPJN8iME6o",
},
privateKeyJwk: {
"crv": "Ed25519",
"x": "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ",
"d": "tP7VWE16yMQWUO2G250yvoevfbfxY25GjHglTP3ZOyU",
"kty": "OKP",
"kid": "_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A"
}
crv: "Ed25519",
x: "fJ-HI45g-LjZI6poTa122g5u6hRYzPRyJCY5pq9dfSQ",
d: "94-6uUZUPMUuAXzJykpTrGIjKfvAXp6ocKz8ipBYkg4",
kty: "OKP",
kid: "DTXI1UCGeLHx3B6GmZtMQuR8b3KDdaayEYPJN8iME6o",
},
});

const suite = new JsonWebSignature2020({
LDKeyClass: JsonWebKeyLinkedDataKeyClass2020,
linkedDataSigantureType: "JsonWebSignature2020",
linkedDataSignatureVerificationKeyType: "JsonWebKey2020",
key
key,
date: "2019-12-11T03:50:55Z",
});

const vc = await vc.issue({
credential: { ...credential },
compactProof: false,
suite
const verifiableCredential = await vc.issue({
credential: {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
],
id: "http://example.gov/credentials/3732",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
issuer: { id: "did:example:123" },
issuanceDate: "2020-03-10T04:24:12.164Z",
credentialSubject: {
id: "did:example:456",
degree: {
type: "BachelorDegree",
name: "Bachelor of Science and Arts",
},
},
},
suite,
});

const result = await vc.verify({
credential: vc,
compactProof: false,
credential: {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
],
id: "http://example.gov/credentials/3732",
type: ["VerifiableCredential", "UniversityDegreeCredential"],
issuer: {
id: "did:key:z6MkpP568Jfkc1n51vdEut2EebtvhFXkod7S6LMZTVPGsZiZ",
},
issuanceDate: "2020-03-10T04:24:12.164Z",
credentialSubject: {
id: "did:key:z6MkpP568Jfkc1n51vdEut2EebtvhFXkod7S6LMZTVPGsZiZ",
degree: {
type: "BachelorDegree",
name: "Bachelor of Science and Arts",
},
},
proof: {
// Not that /JsonWebSignature2020 !== JsonWebSignature2020
// This issue will persist as long as vc-js does not support JsonWebSignature2020
// See https://github.com/digitalbazaar/vc-js/issues/80
type: "/JsonWebSignature2020",
"dct:created": {
type: "xsd:dateTime",
"@value": "2019-12-11T03:50:55Z",
},
"https://w3id.org/security#jws":
"eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..i2zKj2p9Ek_LyTmZRD--AjqbKCDo863BLR5TAcwiUBJO7XS9e-C2LrgQOS4iBz_zuLqMgYTBYPqibER3Rr0iCw",
"https://w3id.org/security#proofPurpose": {
id: "https://w3id.org/security#assertionMethod",
},
"https://w3id.org/security#verificationMethod": {
id:
"did:key:z6MkpP568Jfkc1n51vdEut2EebtvhFXkod7S6LMZTVPGsZiZ#DTXI1UCGeLHx3B6GmZtMQuR8b3KDdaayEYPJN8iME6o",
},
},
},
documentLoader: documentLoader,
purpose: new AssertionProofPurpose(),
suite
suite,
});
```

## Developer Getting Started

```
npm i
npm run test
npm run coverage
npm run docs
```

## Supported JWS Algs

The expected alg will be determined by the following table.

| kty | crvOrSize | alg |
| --- | --------- | ------ |
| OKP | Ed25519 | EdDSA |
| EC | secp256k1 | ES256K |
| RSA | 2048 | PS256 |
| EC | P-256 | ES256 |
| EC | P-384 | ES384 |
| EC | P-521 | ES512 |

Anything else will result in an unsupported alg error.

### Suite Details

Per [ld-signatures](https://w3c-dvcg.github.io/ld-signatures/#signature-suites), this Signature Suite defines the following:
Per [ld-signatures](https://w3c-ccg.github.io/ld-signatures/#signature-suites), this Signature Suite defines the following:

```json
{
Expand All @@ -112,24 +165,6 @@ See the [Linked Data Signature Suite Vocabulary](https://w3c-ccg.github.io/lds-j
- [example keystore](https://w3c-ccg.github.io/lds-jws2020/example/didDocJwks.json).
- [example did document](https://w3c-ccg.github.io/lds-jws2020/example/didDoc.json)

#### Deprecated Examples

This is an example of a JwsVerificationKey2020 which remains defined in the context for backwards-compatibility, but shouldn't be used by new implementations.

```js
const key = new JsonWebKeyLinkedDataKeyClass2020({
id: `did:example:123#_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A`,
type: "JwsVerificationKey2020",
controller: 'did:example:123',
privateKeyJwk: {
"crv": "Ed25519",
"x": "VCpo2LMLhn6iWku8MKvSLg2ZAoC-nlOyPVQaO3FxVeQ",
"d": "tP7VWE16yMQWUO2G250yvoevfbfxY25GjHglTP3ZOyU",
"kty": "OKP",
"kid": "_Qq0UL2Fq651Q0Fjd6TvnYE-faHiOpRlPVQcY_-tA4A"
}
});

## Credits and Support

Works with:
Expand Down
Loading