Skip to content

Commit

Permalink
export vp (#423)
Browse files Browse the repository at this point in the history
* export vp

* fix unit test

* fix test
  • Loading branch information
nitro-neal authored Feb 27, 2024
1 parent 11d5cc0 commit ea9c48a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/credentials/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './jwt.js';
export * from './presentation-exchange.js';
export * from './verifiable-credential.js';
export * from './verifiable-presentation.js';
export * as utils from './utils.js';
6 changes: 3 additions & 3 deletions packages/credentials/src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
} from '@sphereon/ssi-types';

import {
DEFAULT_CONTEXT,
DEFAULT_VC_CONTEXT,
DEFAULT_VC_TYPE,
VerifiableCredential
} from './verifiable-credential.js';
Expand All @@ -23,8 +23,8 @@ export class SsiValidator {

static validateContext(value: ICredentialContextType | ICredentialContextType[]): void {
const input = this.asArray(value);
if (input.length < 1 || input.indexOf(DEFAULT_CONTEXT) === -1) {
throw new Error(`@context is missing default context "${DEFAULT_CONTEXT}"`);
if (input.length < 1 || input.indexOf(DEFAULT_VC_CONTEXT) === -1) {
throw new Error(`@context is missing default context "${DEFAULT_VC_CONTEXT}"`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/credentials/src/verifiable-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Jwt } from './jwt.js';
import { SsiValidator } from './validators.js';
import { getCurrentXmlSchema112Timestamp } from './utils.js';

export const DEFAULT_CONTEXT = 'https://www.w3.org/2018/credentials/v1';
export const DEFAULT_VC_CONTEXT = 'https://www.w3.org/2018/credentials/v1';
export const DEFAULT_VC_TYPE = 'VerifiableCredential';

/**
Expand Down Expand Up @@ -147,7 +147,7 @@ export class VerifiableCredential {
};

const vcDataModel: VcDataModel = {
'@context' : [DEFAULT_CONTEXT],
'@context' : [DEFAULT_VC_CONTEXT],
type : Array.isArray(type)
? [DEFAULT_VC_TYPE, ...type]
: (type ? [DEFAULT_VC_TYPE, type] : [DEFAULT_VC_TYPE]),
Expand Down
4 changes: 2 additions & 2 deletions packages/credentials/src/verifiable-presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { utils as cryptoUtils } from '@web5/crypto';

import { Jwt } from './jwt.js';
import { SsiValidator } from './validators.js';
import { DEFAULT_VC_CONTEXT } from './verifiable-credential.js';

export const DEFAULT_CONTEXT = 'https://www.w3.org/2018/credentials/v1';
export const DEFAULT_VP_TYPE = 'VerifiablePresentation';

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ export class VerifiablePresentation {
}

const vpDataModel: VpDataModel = {
'@context' : [DEFAULT_CONTEXT],
'@context' : [DEFAULT_VC_CONTEXT],
type : Array.isArray(type)
? [DEFAULT_VP_TYPE, ...type]
: (type ? [DEFAULT_VP_TYPE, type] : [DEFAULT_VP_TYPE]),
Expand Down
6 changes: 3 additions & 3 deletions packages/credentials/tests/ssi-validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { expect } from 'chai';

import { SsiValidator } from '../src/validators.js';
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE } from '../src/verifiable-credential.js';
import { DEFAULT_VC_CONTEXT, DEFAULT_VC_TYPE } from '../src/verifiable-credential.js';

describe('SsiValidator', () => {

describe('validateContext', () => {
it('should throw an error if the default context is missing', () => {
expect(() => SsiValidator.validateContext(['http://example.com'])).throw(`@context is missing default context "${DEFAULT_CONTEXT}"`);
expect(() => SsiValidator.validateContext(['http://example.com'])).throw(`@context is missing default context "${DEFAULT_VC_CONTEXT}"`);
});

it('should not throw an error if the default context is present', () => {
expect(() => SsiValidator.validateContext([DEFAULT_CONTEXT, 'http://example.com'])).not.throw();
expect(() => SsiValidator.validateContext([DEFAULT_VC_CONTEXT, 'http://example.com'])).not.throw();
});
});

Expand Down
2 changes: 1 addition & 1 deletion web5-spec

0 comments on commit ea9c48a

Please sign in to comment.