Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export vp #423

Merged
merged 4 commits into from
Feb 27, 2024
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
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
Loading