Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Feb 6, 2024
1 parent 933b4aa commit a6b75b5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
4 changes: 2 additions & 2 deletions packages/credentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Sign a `VerifiableCredential` with a DID:
First create a `Did` object as follows:

```javascript
import { DidKeyMethod } from '@web5/dids';
const issuer = await DidKeyMethod.create();
import { DidKey } from '@web5/dids';
const issuer: BearerDid = await DidKey.create();
```

Then sign the VC using the `did` object
Expand Down
4 changes: 1 addition & 3 deletions packages/credentials/tests/jwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import type { JwtHeaderParams, JwtPayload, PrivateKeyJwk } from '@web5/crypto';

import { expect } from 'chai';
import { Convert } from '@web5/common';
import { Secp256k1 } from '@web5/crypto';
import { Ed25519 } from '@web5/crypto';
import { DidKey, PortableDid } from '@web5/dids';

import { Jwt } from '../src/jwt.js';
import { Ed25519 } from '@web5/crypto';

describe('Jwt', () => {
describe('parse()', () => {
Expand Down Expand Up @@ -138,7 +137,6 @@ describe('Jwt', () => {

const did = await DidKey.fromKeys(portabldDid);

// const did = await DidKey.create({ options: { algorithm: 'secp256k1'} });
const header: JwtHeaderParams = { typ: 'JWT', alg: 'EdDSA', kid: did.didDocument.verificationMethod![0].id };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

Expand Down
12 changes: 6 additions & 6 deletions packages/credentials/tests/presentation-exchange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('PresentationExchange', () => {

const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
subject : issuerDid.uri!,
issuer : issuerDid.uri,
subject : issuerDid.uri,
data : new BitcoinCredential('btcAddress123'),
});

Expand All @@ -60,8 +60,8 @@ describe('PresentationExchange', () => {
it('should return the only one verifiable credential', async () => {
const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
subject : issuerDid.uri!,
issuer : issuerDid.uri,
subject : issuerDid.uri,
data : new OtherCredential('otherstuff'),
});

Expand Down Expand Up @@ -146,8 +146,8 @@ describe('PresentationExchange', () => {
it('should fail to create a presentation with vc that does not match presentation definition', async () => {
const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
subject : issuerDid.uri!,
issuer : issuerDid.uri,
subject : issuerDid.uri,
data : new OtherCredential('otherstuff'),
});

Expand Down
59 changes: 26 additions & 33 deletions packages/credentials/tests/verifiable-credential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import type { BearerDid, PortableDid } from '@web5/dids';

import sinon from 'sinon';
import { expect } from 'chai';
import { DidDht, DidKey, DidIon, Did } from '@web5/dids';
import { DidDht, DidKey, DidIon } from '@web5/dids';

import { Jwt } from '../src/jwt.js';
import { VerifiableCredential } from '../src/verifiable-credential.js';
import CredentialsVerifyTestVector from '../../../web5-spec/test-vectors/credentials/verify.json' assert { type: 'json' };

describe('Verifiable Credential Tests', async() => {
// const did = await DidKey.create();
let issuerDid: BearerDid;

class StreetCredibility {
Expand All @@ -25,11 +24,11 @@ describe('Verifiable Credential Tests', async() => {

describe('Verifiable Credential (VC)', () => {
it('create vc works', async () => {
const subjectDid = issuerDid.uri!;
const subjectDid = issuerDid.uri;

const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
issuer : issuerDid.uri,
subject : subjectDid,
data : new StreetCredibility('high', true),
});
Expand All @@ -46,8 +45,8 @@ describe('Verifiable Credential Tests', async() => {

const vc = await VerifiableCredential.create({
type : 'TBDeveloperCredential',
subject : did.uri!,
issuer : did.uri!,
subject : did.uri,
issuer : did.uri,
data : {
username: 'nitro'
}
Expand All @@ -58,11 +57,11 @@ describe('Verifiable Credential Tests', async() => {
await VerifiableCredential.verify({ vcJwt });

for( const currentVc of [vc, VerifiableCredential.parseJwt({ vcJwt })]){
expect(currentVc.issuer).to.equal(did.uri!);
expect(currentVc.subject).to.equal(did.uri!);
expect(currentVc.issuer).to.equal(did.uri);
expect(currentVc.subject).to.equal(did.uri);
expect(currentVc.type).to.equal('TBDeveloperCredential');
expect(currentVc.vcDataModel.issuanceDate).to.not.be.undefined;
expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri!, username: 'nitro'});
expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri, username: 'nitro'});
}
});

Expand All @@ -71,8 +70,8 @@ describe('Verifiable Credential Tests', async() => {

const vc = await VerifiableCredential.create({
type : 'TBDeveloperCredential',
subject : did.uri!,
issuer : did.uri!,
subject : did.uri,
issuer : did.uri,
data : {
username: 'nitro'
}
Expand All @@ -83,11 +82,11 @@ describe('Verifiable Credential Tests', async() => {
await VerifiableCredential.verify({ vcJwt });

for (const currentVc of [vc, VerifiableCredential.parseJwt({ vcJwt })]){
expect(currentVc.issuer).to.equal(did.uri!);
expect(currentVc.subject).to.equal(did.uri!);
expect(currentVc.issuer).to.equal(did.uri);
expect(currentVc.subject).to.equal(did.uri);
expect(currentVc.type).to.equal('TBDeveloperCredential');
expect(currentVc.vcDataModel.issuanceDate).to.not.be.undefined;
expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri!, username: 'nitro'});
expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri, username: 'nitro'});
}
});

Expand Down Expand Up @@ -141,11 +140,11 @@ describe('Verifiable Credential Tests', async() => {
});

it('signing with Ed25519 key works', async () => {
const subjectDid = issuerDid.uri!;
const subjectDid = issuerDid.uri;

const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
issuer : issuerDid.uri,
subject : subjectDid,
data : new StreetCredibility('high', true),
});
Expand All @@ -163,8 +162,8 @@ describe('Verifiable Credential Tests', async() => {

const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : did.uri!,
subject : did.uri!,
issuer : did.uri,
subject : did.uri,
data : new StreetCredibility('high', true),
});

Expand All @@ -184,13 +183,12 @@ describe('Verifiable Credential Tests', async() => {

it('parseJwt checks if missing vc property', async () => {
const did = await DidKey.create();
// const did = await DidKey.toKeys({ did: bearerDid });

const jwt = await Jwt.sign({
signerDid : did,
payload : {
iss : did.uri!,
sub : did.uri!
iss : did.uri,
sub : did.uri
}
});

Expand All @@ -202,8 +200,8 @@ describe('Verifiable Credential Tests', async() => {
it('parseJwt returns an instance of VerifiableCredential on success', async () => {
const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
subject : issuerDid.uri!,
issuer : issuerDid.uri,
subject : issuerDid.uri,
data : new StreetCredibility('high', true),
});

Expand Down Expand Up @@ -241,16 +239,16 @@ describe('Verifiable Credential Tests', async() => {
it('verify does not throw an exception with valid vc', async () => {
const vc = await VerifiableCredential.create({
type : 'StreetCred',
issuer : issuerDid.uri!,
subject : issuerDid.uri!,
issuer : issuerDid.uri,
subject : issuerDid.uri,
data : new StreetCredibility('high', true),
});

const vcJwt = await vc.sign({did: issuerDid});

const { issuer, subject, vc: credential } = await VerifiableCredential.verify({ vcJwt });
expect(issuer).to.equal(issuerDid.uri!);
expect(subject).to.equal(issuerDid.uri!);
expect(issuer).to.equal(issuerDid.uri);
expect(subject).to.equal(issuerDid.uri);
expect(credential).to.not.be.null;
});

Expand Down Expand Up @@ -387,12 +385,7 @@ describe('Verifiable Credential Tests', async() => {
const vectors = CredentialsVerifyTestVector.vectors;

for (const vector of vectors) {
const { input, errors, description } = vector;

// TODO: DID:JWK is not supported yet
if (description === 'verify a jwt verifiable credential signed with a did:jwk') {
continue;
}
const { input, errors } = vector;

if (errors) {
let errorOccurred = false;
Expand Down

0 comments on commit a6b75b5

Please sign in to comment.