did-jwt-vc
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -7,6 +7,9 @@ import { VerifiableCredential, JWT, JwtPresentationPayload, JwtCredentialPayload, CredentialPayload, W3CCredential, Verifiable, PresentationPayload, W3CPresentation } from './types'; | ||
/** | ||
* Normalizes a credential payload into an unambiguous W3C credential data type | ||
* In case of conflict, Existing W3C Credential specific properties take precedence, | ||
* except for arrays and object types which get merged. | ||
* @param input either a JWT or JWT payload, or a VerifiableCredential | ||
* Normalizes a credential payload into an unambiguous W3C credential data type In case of conflict, existing W3C | ||
* Credential specific properties take precedence, except for arrays and object types which get merged. | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiableCredential | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -17,3 +20,3 @@ export declare function normalizeCredential(input: Partial<VerifiableCredential> | Partial<JwtCredentialPayload>, removeOriginalFields?: boolean): Verifiable<W3CCredential>; | ||
*/ | ||
declare type DeepPartial<T> = T extends Record<string, unknown> ? { | ||
type DeepPartial<T> = T extends Record<string, unknown> ? { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
@@ -25,8 +28,15 @@ } : T; | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - if true, removes original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
export declare function transformCredentialInput(input: Partial<CredentialPayload> | DeepPartial<JwtCredentialPayload>, removeOriginalFields?: boolean): JwtCredentialPayload; | ||
/** | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type | ||
* @param input either a JWT or JWT payload, or a VerifiablePresentation | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type. | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiablePresentation | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
*/ | ||
@@ -38,3 +48,6 @@ export declare function normalizePresentation(input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload> | JWT, removeOriginalFields?: boolean): Verifiable<W3CPresentation>; | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - when true, removes the original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
*/ | ||
@@ -41,0 +54,0 @@ export declare function transformPresentationInput(input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload>, removeOriginalFields?: boolean): JwtPresentationPayload; |
@@ -1,7 +0,7 @@ | ||
import { Resolvable } from 'did-resolver'; | ||
import { CreateCredentialOptions, CreatePresentationOptions, CredentialPayload, Issuer, JWT, JwtCredentialPayload, JwtPresentationPayload, PresentationPayload, Verifiable, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, VerifyCredentialOptions, VerifyCredentialPolicies, VerifyPresentationOptions, W3CCredential, W3CPresentation } from './types'; | ||
import { normalizeCredential, normalizePresentation, transformCredentialInput, transformPresentationInput } from './converters'; | ||
export { VC_ERROR, VC_JWT_ERROR } from './validators'; | ||
export { Issuer, CredentialPayload, PresentationPayload, JwtCredentialPayload, JwtPresentationPayload, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, Verifiable, W3CCredential, W3CPresentation, transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation, }; | ||
export { CreateCredentialOptions, CreatePresentationOptions, VerifyCredentialOptions, VerifyCredentialPolicies, VerifyPresentationOptions, }; | ||
import type { Resolvable } from 'did-resolver'; | ||
import type { CreateCredentialOptions, CreatePresentationOptions, CredentialPayload, Issuer, JWT, JwtCredentialPayload, JwtPresentationPayload, PresentationPayload, Verifiable, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, VerifyCredentialOptions, VerifyCredentialPolicies, VerifyPresentationOptions, W3CCredential, W3CPresentation } from './types.js'; | ||
import { normalizeCredential, normalizePresentation, transformCredentialInput, transformPresentationInput } from './converters.js'; | ||
export { VC_ERROR, VC_JWT_ERROR } from './validators.js'; | ||
export type { Issuer, CredentialPayload, PresentationPayload, JwtCredentialPayload, JwtPresentationPayload, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, Verifiable, W3CCredential, W3CPresentation, CreateCredentialOptions, CreatePresentationOptions, VerifyCredentialOptions, VerifyCredentialPolicies, VerifyPresentationOptions, }; | ||
export { transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation }; | ||
/** | ||
@@ -8,0 +8,0 @@ * Creates a VerifiableCredential given a `CredentialPayload` or `JwtCredentialPayload` and an `Issuer`. |
@@ -8,5 +8,13 @@ import { decodeJWT, JWT_ERROR, verifyJWT, createJWT, createMultisignatureJWT } from 'did-jwt'; | ||
const DEFAULT_VP_TYPE = 'VerifiablePresentation'; | ||
/** | ||
* The `JwtProof2020` is a synthetic proof type, usable for differentiating credentials by proof type when representing | ||
* JWT credentials as W3C VC JSON. It is not a registered W3C VC Data Model algorithm and should not be treated as | ||
* such. | ||
* | ||
* This proof type is only intended as a convenience and does not actually prove the validity of a VC/VP in JSON | ||
* representation. The actual verifiable credential or presentation is represented in the `jwt` property. | ||
*/ | ||
const DEFAULT_JWT_PROOF_TYPE = 'JwtProof2020'; | ||
/* | ||
/** | ||
* Additional W3C VC fields: | ||
@@ -33,3 +41,3 @@ * These are defined as optional top-level properties in the W3C spec but are not mapped to top-level JWT names, | ||
function cleanUndefined(input) { | ||
if (typeof input !== 'object') { | ||
if (typeof input !== 'object' || input === null) { | ||
return input; | ||
@@ -164,6 +172,9 @@ } | ||
/** | ||
* Normalizes a credential payload into an unambiguous W3C credential data type | ||
* In case of conflict, Existing W3C Credential specific properties take precedence, | ||
* except for arrays and object types which get merged. | ||
* @param input either a JWT or JWT payload, or a VerifiableCredential | ||
* Normalizes a credential payload into an unambiguous W3C credential data type In case of conflict, existing W3C | ||
* Credential specific properties take precedence, except for arrays and object types which get merged. | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiableCredential | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -202,3 +213,6 @@ function normalizeCredential(input, removeOriginalFields = true) { | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - if true, removes original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -369,4 +383,8 @@ function transformCredentialInput(input, removeOriginalFields = true) { | ||
/** | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type | ||
* @param input either a JWT or JWT payload, or a VerifiablePresentation | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type. | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiablePresentation | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
*/ | ||
@@ -405,3 +423,6 @@ function normalizePresentation(input, removeOriginalFields = true) { | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - when true, removes the original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
*/ | ||
@@ -408,0 +429,0 @@ function transformPresentationInput(input, removeOriginalFields = true) { |
@@ -11,5 +11,13 @@ (function (global, factory) { | ||
const DEFAULT_VP_TYPE = 'VerifiablePresentation'; | ||
/** | ||
* The `JwtProof2020` is a synthetic proof type, usable for differentiating credentials by proof type when representing | ||
* JWT credentials as W3C VC JSON. It is not a registered W3C VC Data Model algorithm and should not be treated as | ||
* such. | ||
* | ||
* This proof type is only intended as a convenience and does not actually prove the validity of a VC/VP in JSON | ||
* representation. The actual verifiable credential or presentation is represented in the `jwt` property. | ||
*/ | ||
const DEFAULT_JWT_PROOF_TYPE = 'JwtProof2020'; | ||
/* | ||
/** | ||
* Additional W3C VC fields: | ||
@@ -36,3 +44,3 @@ * These are defined as optional top-level properties in the W3C spec but are not mapped to top-level JWT names, | ||
function cleanUndefined(input) { | ||
if (typeof input !== 'object') { | ||
if (typeof input !== 'object' || input === null) { | ||
return input; | ||
@@ -167,6 +175,9 @@ } | ||
/** | ||
* Normalizes a credential payload into an unambiguous W3C credential data type | ||
* In case of conflict, Existing W3C Credential specific properties take precedence, | ||
* except for arrays and object types which get merged. | ||
* @param input either a JWT or JWT payload, or a VerifiableCredential | ||
* Normalizes a credential payload into an unambiguous W3C credential data type In case of conflict, existing W3C | ||
* Credential specific properties take precedence, except for arrays and object types which get merged. | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiableCredential | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -205,3 +216,6 @@ function normalizeCredential(input, removeOriginalFields = true) { | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - if true, removes original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -372,4 +386,8 @@ function transformCredentialInput(input, removeOriginalFields = true) { | ||
/** | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type | ||
* @param input either a JWT or JWT payload, or a VerifiablePresentation | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type. | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiablePresentation | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
*/ | ||
@@ -408,3 +426,6 @@ function normalizePresentation(input, removeOriginalFields = true) { | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - when true, removes the original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
*/ | ||
@@ -411,0 +432,0 @@ function transformPresentationInput(input, removeOriginalFields = true) { |
@@ -1,4 +0,3 @@ | ||
import { Signer, JWTVerified, JWTHeader, JWTOptions, JWTVerifyOptions } from 'did-jwt'; | ||
import type { Signer, JWTVerified, JWTHeader, JWTOptions, JWTVerifyOptions } from 'did-jwt'; | ||
export declare const JWT_ALG = "ES256K"; | ||
export declare const DID_FORMAT: RegExp; | ||
export declare const JWT_FORMAT: RegExp; | ||
@@ -8,4 +7,12 @@ export declare const DEFAULT_CONTEXT = "https://www.w3.org/2018/credentials/v1"; | ||
export declare const DEFAULT_VP_TYPE = "VerifiablePresentation"; | ||
/** | ||
* The `JwtProof2020` is a synthetic proof type, usable for differentiating credentials by proof type when representing | ||
* JWT credentials as W3C VC JSON. It is not a registered W3C VC Data Model algorithm and should not be treated as | ||
* such. | ||
* | ||
* This proof type is only intended as a convenience and does not actually prove the validity of a VC/VP in JSON | ||
* representation. The actual verifiable credential or presentation is represented in the `jwt` property. | ||
*/ | ||
export declare const DEFAULT_JWT_PROOF_TYPE = "JwtProof2020"; | ||
export declare type JwtCredentialSubject = Record<string, any>; | ||
export type JwtCredentialSubject = Record<string, any>; | ||
export interface CredentialStatus { | ||
@@ -54,8 +61,8 @@ id: string; | ||
} | ||
export declare type IssuerType = Extensible<{ | ||
export type IssuerType = Extensible<{ | ||
id: string; | ||
}> | string; | ||
export declare type DateType = string | Date; | ||
export type DateType = string | Date; | ||
/** | ||
* used as input when creating Verifiable Credentials | ||
* Used as input when creating Verifiable Credentials | ||
*/ | ||
@@ -80,3 +87,3 @@ interface FixedCredentialPayload { | ||
*/ | ||
export declare type CredentialPayload = Extensible<FixedCredentialPayload>; | ||
export type CredentialPayload = Extensible<FixedCredentialPayload>; | ||
/** | ||
@@ -95,4 +102,4 @@ * This is meant to reflect unambiguous types for the properties in `CredentialPayload` | ||
*/ | ||
declare type Replace<T, U> = Omit<T, keyof U> & U; | ||
declare type Extensible<T> = T & { | ||
type Replace<T, U> = Omit<T, keyof U> & U; | ||
type Extensible<T> = T & { | ||
[x: string]: any; | ||
@@ -103,3 +110,3 @@ }; | ||
* It is meant to be an unambiguous representation of the properties of a Credential and is usually the result of a | ||
* transformation method. | ||
* transformation method. See `transformCredentialInput()` for more details. | ||
* | ||
@@ -113,3 +120,3 @@ * `issuer` is always an object with an `id` property and potentially other app specific issuer claims | ||
*/ | ||
export declare type W3CCredential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>; | ||
export type W3CCredential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>; | ||
/** | ||
@@ -132,3 +139,3 @@ * used as input when creating Verifiable Presentations | ||
*/ | ||
export declare type PresentationPayload = Extensible<FixedPresentationPayload>; | ||
export type PresentationPayload = Extensible<FixedPresentationPayload>; | ||
interface NarrowPresentationDefinitions { | ||
@@ -143,3 +150,3 @@ '@context': string[]; | ||
* It is meant to be an unambiguous representation of the properties of a Presentation and is usually the result of a | ||
* transformation method. | ||
* transformation method. See `transformPresentationInput()` for more details. | ||
* | ||
@@ -150,3 +157,3 @@ * The `verifiableCredential` array should contain parsed `Verifiable<Credential>` elements. | ||
*/ | ||
export declare type W3CPresentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>; | ||
export type W3CPresentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>; | ||
export interface Proof { | ||
@@ -160,6 +167,6 @@ type?: string; | ||
*/ | ||
export declare type Verifiable<T> = Readonly<T> & { | ||
export type Verifiable<T> = Readonly<T> & { | ||
readonly proof: Proof; | ||
}; | ||
export declare type JWT = string; | ||
export type JWT = string; | ||
/** | ||
@@ -170,3 +177,3 @@ * A union type for both possible representations of a Credential (JWT and W3C standard) | ||
*/ | ||
export declare type VerifiableCredential = JWT | Verifiable<W3CCredential>; | ||
export type VerifiableCredential = JWT | Verifiable<W3CCredential>; | ||
/** | ||
@@ -177,4 +184,4 @@ * A union type for both possible representations of a Presentation (JWT and W3C standard) | ||
*/ | ||
export declare type VerifiablePresentation = JWT | Verifiable<W3CPresentation>; | ||
export declare type VerifiedJWT = JWTVerified; | ||
export type VerifiablePresentation = JWT | Verifiable<W3CPresentation>; | ||
export type VerifiedJWT = JWTVerified; | ||
/** | ||
@@ -187,3 +194,3 @@ * Represents the result of a Presentation verification. | ||
*/ | ||
export declare type VerifiedPresentation = VerifiedJWT & { | ||
export type VerifiedPresentation = VerifiedJWT & { | ||
verifiablePresentation: Verifiable<W3CPresentation>; | ||
@@ -198,3 +205,3 @@ }; | ||
*/ | ||
export declare type VerifiedCredential = VerifiedJWT & { | ||
export type VerifiedCredential = VerifiedJWT & { | ||
verifiableCredential: Verifiable<W3CCredential>; | ||
@@ -201,0 +208,0 @@ }; |
@@ -0,0 +0,0 @@ import { JwtCredentialSubject, DateType } from './types'; |
{ | ||
"name": "did-jwt-vc", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format", | ||
@@ -9,5 +9,3 @@ "type": "module", | ||
"module": "./lib/index.module.js", | ||
"unpkg": "./lib/index.umd.js", | ||
"types": "./lib/index.d.ts", | ||
"umd:main": "./lib/index.umd.js", | ||
"files": [ | ||
@@ -21,2 +19,3 @@ "lib", | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"require": "./lib/index.cjs", | ||
@@ -27,4 +26,4 @@ "import": "./lib/index.module.js" | ||
"scripts": { | ||
"test": "jest", | ||
"test:ci": "jest --coverage", | ||
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest", | ||
"test:ci": "yarn test --coverage", | ||
"build": "microbundle --compress=false", | ||
@@ -42,3 +41,3 @@ "format": "prettier --write \"src/**/*.ts\"", | ||
"dependencies": { | ||
"did-jwt": "^7.1.0", | ||
"did-jwt": "^7.2.0", | ||
"did-resolver": "^4.1.0" | ||
@@ -50,38 +49,27 @@ }, | ||
}, | ||
"jest": { | ||
"clearMocks": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.{ts,tsx}", | ||
"!src/**/*.d.ts", | ||
"!**/node_modules/**", | ||
"!**/__tests__/**" | ||
], | ||
"testEnvironment": "node", | ||
"testMatch": [ | ||
"**/__tests__/**/*.test.[jt]s" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.18.9", | ||
"@babel/preset-env": "7.18.9", | ||
"@babel/preset-typescript": "7.18.6", | ||
"@semantic-release/changelog": "6.0.1", | ||
"@babel/core": "7.21.8", | ||
"@babel/preset-env": "7.21.5", | ||
"@babel/preset-typescript": "7.21.5", | ||
"@semantic-release/changelog": "6.0.3", | ||
"@semantic-release/git": "10.0.1", | ||
"@types/elliptic": "6.4.14", | ||
"@types/faker": "6.6.9", | ||
"@types/jest": "28.1.6", | ||
"@types/node": "17.0.40", | ||
"@typescript-eslint/eslint-plugin": "5.30.7", | ||
"@typescript-eslint/parser": "5.30.7", | ||
"eslint": "8.20.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-jest": "26.6.0", | ||
"@types/jest": "29.5.1", | ||
"@types/node": "20.2.0", | ||
"@typescript-eslint/eslint-plugin": "5.59.6", | ||
"@typescript-eslint/parser": "5.59.6", | ||
"cross-env": "7.0.3", | ||
"eslint": "8.40.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint-plugin-jest": "27.2.1", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"ethr-did": "2.2.3", | ||
"ethr-did": "2.3.12", | ||
"faker": "6.6.6", | ||
"jest": "28.1.3", | ||
"microbundle": "0.15.0", | ||
"prettier": "2.7.1", | ||
"semantic-release": "19.0.3", | ||
"typescript": "4.7.4" | ||
"jest": "29.5.0", | ||
"microbundle": "0.15.1", | ||
"prettier": "2.8.8", | ||
"semantic-release": "21.0.2", | ||
"ts-jest": "29.1.0", | ||
"typescript": "5.0.4" | ||
}, | ||
@@ -88,0 +76,0 @@ "engines": { |
import { EthrDID } from 'ethr-did' | ||
import type { Issuer, JwtCredentialPayload } from '../index.js' | ||
import { | ||
createVerifiableCredentialJwt, | ||
createVerifiablePresentationJwt, | ||
Issuer, | ||
JwtCredentialPayload, | ||
verifyCredential, | ||
verifyPresentation, | ||
verifyPresentationPayloadOptions, | ||
} from '../index' | ||
} from '../index.js' | ||
import { decodeJWT, ES256KSigner, hexToBytes } from 'did-jwt' | ||
import { Resolvable } from 'did-resolver' | ||
import type { Resolvable } from 'did-resolver' | ||
import { | ||
CreatePresentationOptions, | ||
type CreatePresentationOptions, | ||
DEFAULT_CONTEXT, | ||
DEFAULT_VC_TYPE, | ||
DEFAULT_VP_TYPE, | ||
VerifyPresentationOptions, | ||
} from '../types' | ||
import { | ||
validateContext, | ||
validateCredentialSubject, | ||
validateJwtFormat, | ||
validateTimestamp, | ||
validateVcType, | ||
validateVpType, | ||
} from '../validators' | ||
type VerifyPresentationOptions, | ||
} from '../types.js' | ||
import elliptic from 'elliptic' | ||
import * as u8a from 'uint8arrays' | ||
import { jest } from '@jest/globals' | ||
const secp256k1 = new elliptic.ec('secp256k1') | ||
jest.mock('../validators') | ||
const mockValidateJwtFormat = <jest.Mock<typeof validateJwtFormat>>validateJwtFormat | ||
const mockValidateTimestamp = <jest.Mock<typeof validateTimestamp>>validateTimestamp | ||
const mockValidateContext = <jest.Mock<typeof validateContext>>validateContext | ||
const mockValidateVcType = <jest.Mock<typeof validateVcType>>validateVcType | ||
const mockValidateVpType = <jest.Mock<typeof validateVpType>>validateVpType | ||
const mockValidateCredentialSubject = <jest.Mock<typeof validateCredentialSubject>>validateCredentialSubject | ||
const DID_B = 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4' | ||
@@ -51,3 +37,3 @@ const EXTRA_CONTEXT_A = 'https://www.w3.org/2018/credentials/examples/v1' | ||
// tslint:disable-next-line: max-line-length | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjgwNDUyNjMsInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIiwiaHR0cHM6Ly93d3cudzMub3JnLzIwMTgvY3JlZGVudGlhbHMvZXhhbXBsZXMvdjEiXSwidHlwZSI6WyJWZXJpZmlhYmxlQ3JlZGVudGlhbCJdLCJ2ZXJpZmlhYmxlQ3JlZGVudGlhbCI6WyJleUowZVhBaU9pSktWMVFpTENKaGJHY2lPaUpGVXpJMU5rc3RVaUo5LmV5SnBZWFFpT2pFMU5qWTVNak15Tmprc0luTjFZaUk2SW1ScFpEcGxkR2h5T2pCNE5ETTFaR1l6WldSaE5UY3hOVFJqWmpoalpqYzVNall3TnprNE9ERm1Namt4TW1ZMU5HUmlOQ0lzSW01aVppSTZNVFUyTWprMU1ESTRNaXdpZG1NaU9uc2lRR052Ym5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hGMTIzMkY4NDBmM2FEN2QyM0ZjRGFBODRkNkM2NmRhYzI0RUZiMTk4In0.oAZju9YNgYQz_RELnlK0KPizXvP90le4Tw7kRqjrXAzY3ZcRMS6EJt58iC3wehVnt680FO0HvFXDrLk3eLfY8QA' | ||
@@ -146,16 +132,2 @@ const ethrDidIssuer = new EthrDID({ | ||
}) | ||
it('calls functions to validate required fields', async () => { | ||
expect.assertions(4) | ||
await createVerifiableCredentialJwt(verifiableCredentialPayload, issuer) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith(verifiableCredentialPayload.nbf) | ||
expect(mockValidateContext).toHaveBeenCalledWith(verifiableCredentialPayload.vc['@context']) | ||
expect(mockValidateVcType).toHaveBeenCalledWith(verifiableCredentialPayload.vc.type) | ||
expect(mockValidateCredentialSubject).toHaveBeenCalledWith(verifiableCredentialPayload.vc.credentialSubject) | ||
}) | ||
it('calls functions to validate optional fields if they are present', async () => { | ||
expect.assertions(1) | ||
const timestamp = Math.floor(new Date().getTime()) | ||
await createVerifiableCredentialJwt({ ...verifiableCredentialPayload, exp: timestamp }, issuer) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith(timestamp) | ||
}) | ||
}) | ||
@@ -286,12 +258,2 @@ | ||
}) | ||
it('calls functions to validate required fields', async () => { | ||
expect.assertions(2 + presentationPayload.vp.verifiableCredential.length) | ||
await createVerifiablePresentationJwt(presentationPayload, holder) | ||
expect(mockValidateContext).toHaveBeenCalledWith(presentationPayload.vp['@context']) | ||
expect(mockValidateVpType).toHaveBeenCalledWith(presentationPayload.vp.type) | ||
for (const vc of presentationPayload.vp.verifiableCredential) { | ||
expect(mockValidateJwtFormat).toHaveBeenCalledWith(vc) | ||
} | ||
}) | ||
it('creates a valid Presentation JWT if there are no credentials', async () => { | ||
@@ -313,14 +275,2 @@ expect.assertions(1) | ||
}) | ||
it('calls functions to validate optional fields if they are present', async () => { | ||
expect.assertions(1) | ||
const timestamp = Math.floor(new Date().getTime()) | ||
await createVerifiablePresentationJwt( | ||
{ | ||
...presentationPayload, | ||
exp: timestamp, | ||
}, | ||
holder | ||
) | ||
expect(mockValidateTimestamp).toHaveBeenCalledWith(timestamp) | ||
}) | ||
}) | ||
@@ -341,3 +291,3 @@ | ||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjM4MjQ4MDksImV4cCI6OTk2Mjk1MDI4Miwic3ViIjoiZGlkOmV0aHI6MHhmMTIzMmY4NDBmM2FkN2QyM2ZjZGFhODRkNmM2NmRhYzI0ZWZiMTk4IiwiY2xhaW0iOnsiZGVncmVlIjp7InR5cGUiOiJCYWNoZWxvckRlZ3JlZSIsIm5hbWUiOiJCYWNjYWxhdXLDqWF0IGVuIG11c2lxdWVzIG51bcOpcmlxdWVzIn19LCJpc3MiOiJkaWQ6ZXRocjoweGYzYmVhYzMwYzQ5OGQ5ZTI2ODY1ZjM0ZmNhYTU3ZGJiOTM1YjBkNzQifQ.OsKmaxoA2pt3_ixWK61BaMDc072g2PymBX_CCUSo-irvtIRUP5qBCcerhpASe5hOcTg5nNpNg0XYXnqyF9I4XwE' | ||
const verified = await verifyCredential(LEGACY_FORMAT_ATTESTATION, resolver) | ||
const verified = await verifyCredential(LEGACY_FORMAT_ATTESTATION, resolver, { policies: { format: false } }) | ||
// expect(verified.payload.vc).toBeDefined() | ||
@@ -344,0 +294,0 @@ expect(verified.verifiableCredential).toBeDefined() |
import * as validators from '../validators' | ||
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE } from '../types' | ||
export const DID_A = 'did:ethr:0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198' | ||
export const DID_B = 'did:ethr:0x435df3eda57154cf8cf7926079881f2912f54db4' | ||
export const INVALID_DID = 'this is not a valid did' | ||
export const INVALID_TIMESTAMP = 1563905309015 | ||
export const EXTRA_CONTEXT_A = 'https://www.w3.org/2018/credentials/examples/v1' | ||
@@ -9,0 +4,0 @@ export const EXTRA_CONTEXT_B = 'custom vc context' |
@@ -18,3 +18,3 @@ import { | ||
/* | ||
/** | ||
* Additional W3C VC fields: | ||
@@ -51,3 +51,3 @@ * These are defined as optional top-level properties in the W3C spec but are not mapped to top-level JWT names, | ||
function cleanUndefined<T>(input: T): T { | ||
if (typeof input !== 'object') { | ||
if (typeof input !== 'object' || input === null) { | ||
return input | ||
@@ -192,6 +192,9 @@ } | ||
/** | ||
* Normalizes a credential payload into an unambiguous W3C credential data type | ||
* In case of conflict, Existing W3C Credential specific properties take precedence, | ||
* except for arrays and object types which get merged. | ||
* @param input either a JWT or JWT payload, or a VerifiableCredential | ||
* Normalizes a credential payload into an unambiguous W3C credential data type In case of conflict, existing W3C | ||
* Credential specific properties take precedence, except for arrays and object types which get merged. | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiableCredential | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -233,3 +236,6 @@ export function normalizeCredential( | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - if true, removes original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VC JWT encoding } | ||
*/ | ||
@@ -438,4 +444,8 @@ export function transformCredentialInput( | ||
/** | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type | ||
* @param input either a JWT or JWT payload, or a VerifiablePresentation | ||
* Normalizes a presentation payload into an unambiguous W3C Presentation data type. | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
* | ||
* @param input - either a JWT or JWT payload, or a VerifiablePresentation | ||
* @param removeOriginalFields - if true, removes all fields that were transformed according to the W3C mapping | ||
*/ | ||
@@ -472,3 +482,6 @@ export function normalizePresentation( | ||
* Also, `nbf`, `exp` and `jti` properties can be explicitly set to `undefined` and they will be kept intact. | ||
* @param input either a JWT payload or a CredentialPayloadInput | ||
* @param input - either a JWT payload or a CredentialPayloadInput | ||
* @param removeOriginalFields - when true, removes the original W3C fields from the resulting object | ||
* | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#jwt-encoding | VP JWT encoding } | ||
*/ | ||
@@ -475,0 +488,0 @@ export function transformPresentationInput( |
import { createJWT, createMultisignatureJWT, verifyJWT } from 'did-jwt' | ||
import { Resolvable } from 'did-resolver' | ||
import * as validators from './validators' | ||
import { | ||
import type { Resolvable } from 'did-resolver' | ||
import * as validators from './validators.js' | ||
import { VC_ERROR } from './validators.js' | ||
import type { | ||
CreateCredentialOptions, | ||
@@ -10,3 +11,2 @@ CreatePresentationOptions, | ||
JWT, | ||
JWT_ALG, | ||
JwtCredentialPayload, | ||
@@ -25,3 +25,4 @@ JwtPresentationPayload, | ||
W3CPresentation, | ||
} from './types' | ||
} from './types.js' | ||
import { JWT_ALG } from './types.js' | ||
import { | ||
@@ -34,8 +35,7 @@ asArray, | ||
transformPresentationInput, | ||
} from './converters' | ||
import { VC_ERROR } from './validators' | ||
} from './converters.js' | ||
export { VC_ERROR, VC_JWT_ERROR } from './validators' | ||
export { VC_ERROR, VC_JWT_ERROR } from './validators.js' | ||
export { | ||
export type { | ||
Issuer, | ||
@@ -53,9 +53,2 @@ CredentialPayload, | ||
W3CPresentation, | ||
transformCredentialInput, | ||
transformPresentationInput, | ||
normalizeCredential, | ||
normalizePresentation, | ||
} | ||
export { | ||
CreateCredentialOptions, | ||
@@ -68,2 +61,4 @@ CreatePresentationOptions, | ||
export { transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation } | ||
/** | ||
@@ -70,0 +65,0 @@ * Creates a VerifiableCredential given a `CredentialPayload` or `JwtCredentialPayload` and an `Issuer`. |
@@ -1,5 +0,4 @@ | ||
import { Signer, JWTVerified, JWTHeader, JWTOptions, JWTVerifyOptions } from 'did-jwt' | ||
import type { Signer, JWTVerified, JWTHeader, JWTOptions, JWTVerifyOptions } from 'did-jwt' | ||
export const JWT_ALG = 'ES256K' | ||
export const DID_FORMAT = /^did:([a-zA-Z0-9_]+):([:[a-zA-Z0-9_.-]+)(\/[^#]*)?(#.*)?$/ | ||
export const JWT_FORMAT = /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/ | ||
@@ -9,2 +8,10 @@ export const DEFAULT_CONTEXT = 'https://www.w3.org/2018/credentials/v1' | ||
export const DEFAULT_VP_TYPE = 'VerifiablePresentation' | ||
/** | ||
* The `JwtProof2020` is a synthetic proof type, usable for differentiating credentials by proof type when representing | ||
* JWT credentials as W3C VC JSON. It is not a registered W3C VC Data Model algorithm and should not be treated as | ||
* such. | ||
* | ||
* This proof type is only intended as a convenience and does not actually prove the validity of a VC/VP in JSON | ||
* representation. The actual verifiable credential or presentation is represented in the `jwt` property. | ||
*/ | ||
export const DEFAULT_JWT_PROOF_TYPE = 'JwtProof2020' | ||
@@ -71,3 +78,3 @@ | ||
/** | ||
* used as input when creating Verifiable Credentials | ||
* Used as input when creating Verifiable Credentials | ||
*/ | ||
@@ -118,3 +125,3 @@ interface FixedCredentialPayload { | ||
* It is meant to be an unambiguous representation of the properties of a Credential and is usually the result of a | ||
* transformation method. | ||
* transformation method. See `transformCredentialInput()` for more details. | ||
* | ||
@@ -160,3 +167,3 @@ * `issuer` is always an object with an `id` property and potentially other app specific issuer claims | ||
* It is meant to be an unambiguous representation of the properties of a Presentation and is usually the result of a | ||
* transformation method. | ||
* transformation method. See `transformPresentationInput()` for more details. | ||
* | ||
@@ -163,0 +170,0 @@ * The `verifiableCredential` array should contain parsed `Verifiable<Credential>` elements. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
520893
24
26
6217
Updateddid-jwt@^7.2.0