Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sphereon/ssi-types

Package Overview
Dependencies
Maintainers
4
Versions
1168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sphereon/ssi-types - npm Package Compare versions

Comparing version 0.8.1-unstable.65 to 0.8.1-unstable.73

36

dist/mapper/credential-mapper.d.ts

@@ -5,5 +5,11 @@ import { ICredential, IPresentation, IVerifiableCredential, IVerifiablePresentation, JwtDecodedVerifiableCredential, JwtDecodedVerifiablePresentation, OriginalVerifiableCredential, OriginalVerifiablePresentation, WrappedVerifiableCredential, WrappedVerifiablePresentation } from '../types';

static decodeVerifiableCredential(credential: OriginalVerifiableCredential): JwtDecodedVerifiableCredential | IVerifiableCredential;
static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation): WrappedVerifiablePresentation;
static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[]): WrappedVerifiableCredential[];
static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential): WrappedVerifiableCredential;
static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation, opts?: {
maxTimeSkewInMS?: number;
}): WrappedVerifiablePresentation;
static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[], opts?: {
maxTimeSkewInMS?: number;
}): WrappedVerifiableCredential[];
static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
maxTimeSkewInMS?: number;
}): WrappedVerifiableCredential;
static isJwtEncoded(original: OriginalVerifiableCredential | OriginalVerifiablePresentation): boolean;

@@ -13,9 +19,21 @@ private static isJsonLdString;

static isJwtDecodedPresentation(original: OriginalVerifiablePresentation): boolean;
static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean): IPresentation;
static jwtDecodedPresentationToUniformPresentation(decoded: JwtDecodedVerifiablePresentation, makeCredentialsUniform?: boolean): IPresentation;
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential;
static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation;
static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential;
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential;
static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform?: boolean, opts?: {
maxTimeSkewInMS?: number;
}): IPresentation;
static jwtDecodedPresentationToUniformPresentation(decoded: JwtDecodedVerifiablePresentation, makeCredentialsUniform?: boolean, opts?: {
maxTimeSkewInMS?: number;
}): IPresentation;
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: {
maxTimeSkewInMS?: number;
}): ICredential;
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: {
maxTimeSkewInMS?: number;
}): IPresentation;
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: {
maxTimeSkewInMS?: number;
}): ICredential;
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: {
maxTimeSkewInMS?: number;
}): ICredential;
}
//# sourceMappingURL=credential-mapper.d.ts.map

@@ -39,3 +39,3 @@ "use strict";

}
static toWrappedVerifiablePresentation(presentation) {
static toWrappedVerifiablePresentation(presentation, opts) {
const original = presentation;

@@ -48,5 +48,5 @@ const isJwtEncoded = CredentialMapper.isJwtEncoded(original);

const vp = isJwtEncoded || isJwtDecoded
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false)
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts)
: decoded;
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential);
const vcs = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts);
// todo: We probably want to add proofs as well

@@ -62,6 +62,6 @@ return {

}
static toWrappedVerifiableCredentials(verifiableCredentials) {
return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential);
static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts));
}
static toWrappedVerifiableCredential(verifiableCredential) {
static toWrappedVerifiableCredential(verifiableCredential, opts) {
const original = verifiableCredential;

@@ -73,3 +73,3 @@ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);

const credential = isJwtDecoded || isJwtDecoded
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded)
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts)
: decoded;

@@ -98,9 +98,9 @@ const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc';

}
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true) {
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform);
static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
return CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, jwt_decode_1.default)(jwt), makeCredentialsUniform, opts);
}
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true) {
static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
const presentation = Object.assign({}, decoded.vp);
if (makeCredentialsUniform) {
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(CredentialMapper.toUniformCredential); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
}

@@ -127,3 +127,3 @@ // Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)

}
static toUniformCredential(verifiableCredential) {
static toUniformCredential(verifiableCredential, opts) {
const original = verifiableCredential;

@@ -134,3 +134,3 @@ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential);

if (isJwtDecoded || isJwtEncoded) {
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded);
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
}

@@ -141,3 +141,3 @@ else {

}
static toUniformPresentation(presentation) {
static toUniformPresentation(presentation, opts) {
var _a;

@@ -151,12 +151,13 @@ const original = presentation;

: decoded;
uniformPresentation.verifiableCredential = (_a = uniformPresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a.map(CredentialMapper.toUniformCredential); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
uniformPresentation.verifiableCredential = (_a = uniformPresentation.verifiableCredential) === null || _a === void 0 ? void 0 : _a.map((vc) => CredentialMapper.toUniformCredential(vc, opts)); // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
return uniformPresentation;
}
static jwtEncodedCredentialToUniformCredential(jwt) {
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt));
static jwtEncodedCredentialToUniformCredential(jwt, opts) {
return CredentialMapper.jwtDecodedCredentialToUniformCredential((0, jwt_decode_1.default)(jwt), opts);
}
static jwtDecodedCredentialToUniformCredential(decoded) {
static jwtDecodedCredentialToUniformCredential(decoded, opts) {
const credential = Object.assign({}, decoded.vc);
// Since this is a credential, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)
delete credential.proof;
const maxSkewInMS = (opts === null || opts === void 0 ? void 0 : opts.maxTimeSkewInMS) !== undefined ? opts.maxTimeSkewInMS : 999;
if (decoded.exp) {

@@ -168,3 +169,6 @@ const expDate = credential.expirationDate;

if (expDate && expDate !== expDateAsStr) {
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime());
if (!maxSkewInMS || diff > maxSkewInMS) {
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
}
}

@@ -179,3 +183,6 @@ credential.expirationDate = expDateAsStr;

if (issuanceDate && issuanceDate !== nbfDateAsStr) {
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime());
if (!maxSkewInMS || diff > maxSkewInMS) {
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
}
}

@@ -182,0 +189,0 @@ credential.issuanceDate = nbfDateAsStr;

{
"name": "@sphereon/ssi-types",
"description": "SSI Common Types",
"version": "0.8.1-unstable.65+d66c11e",
"version": "0.8.1-unstable.73+0cd067d",
"main": "dist/index.js",

@@ -40,3 +40,3 @@ "types": "dist/index.d.ts",

],
"gitHead": "d66c11ea4977275629555d84be0f1e8dd23cfa35"
"gitHead": "0cd067d71cca9832da452ed00e03bde91159c691"
}

@@ -43,3 +43,6 @@ import {

static toWrappedVerifiablePresentation(presentation: OriginalVerifiablePresentation): WrappedVerifiablePresentation {
static toWrappedVerifiablePresentation(
presentation: OriginalVerifiablePresentation,
opts?: { maxTimeSkewInMS?: number }
): WrappedVerifiablePresentation {
const original = presentation

@@ -54,5 +57,5 @@ const isJwtEncoded: boolean = CredentialMapper.isJwtEncoded(original)

isJwtEncoded || isJwtDecoded
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false)
? CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded as JwtDecodedVerifiablePresentation, false, opts)
: (decoded as IPresentation)
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential)
const vcs: WrappedVerifiableCredential[] = CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential, opts)

@@ -73,7 +76,13 @@ // todo: We probably want to add proofs as well

static toWrappedVerifiableCredentials(verifiableCredentials: OriginalVerifiableCredential[]): WrappedVerifiableCredential[] {
return verifiableCredentials.map(CredentialMapper.toWrappedVerifiableCredential)
static toWrappedVerifiableCredentials(
verifiableCredentials: OriginalVerifiableCredential[],
opts?: { maxTimeSkewInMS?: number }
): WrappedVerifiableCredential[] {
return verifiableCredentials.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, opts))
}
static toWrappedVerifiableCredential(verifiableCredential: OriginalVerifiableCredential): WrappedVerifiableCredential {
static toWrappedVerifiableCredential(
verifiableCredential: OriginalVerifiableCredential,
opts?: { maxTimeSkewInMS?: number }
): WrappedVerifiableCredential {
const original = verifiableCredential

@@ -89,3 +98,3 @@

isJwtDecoded || isJwtDecoded
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
? CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
: (decoded as ICredential)

@@ -119,4 +128,8 @@ const format = isJwtDecoded || isJwtDecoded ? 'jwt_vc' : 'ldp_vc'

static jwtEncodedPresentationToUniformPresentation(jwt: string, makeCredentialsUniform: boolean = true): IPresentation {
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform)
static jwtEncodedPresentationToUniformPresentation(
jwt: string,
makeCredentialsUniform: boolean = true,
opts?: { maxTimeSkewInMS?: number }
): IPresentation {
return CredentialMapper.jwtDecodedPresentationToUniformPresentation(jwt_decode(jwt), makeCredentialsUniform, opts)
}

@@ -126,3 +139,4 @@

decoded: JwtDecodedVerifiablePresentation,
makeCredentialsUniform: boolean = true
makeCredentialsUniform: boolean = true,
opts?: { maxTimeSkewInMS?: number }
): IPresentation {

@@ -133,3 +147,5 @@ const presentation: IPresentation = {

if (makeCredentialsUniform) {
presentation.verifiableCredential = decoded.vp.verifiableCredential.map(CredentialMapper.toUniformCredential) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
presentation.verifiableCredential = decoded.vp.verifiableCredential.map((vc) =>
CredentialMapper.toUniformCredential(vc, opts)
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)
}

@@ -158,3 +174,3 @@ // Since this is a presentation, we delete any proof just to be sure (should not occur on JWT, but better safe than sorry)

static toUniformCredential(verifiableCredential: OriginalVerifiableCredential): ICredential {
static toUniformCredential(verifiableCredential: OriginalVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
const original = verifiableCredential

@@ -167,3 +183,3 @@ const decoded = CredentialMapper.decodeVerifiableCredential(verifiableCredential)

if (isJwtDecoded || isJwtEncoded) {
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential)
return CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded as JwtDecodedVerifiableCredential, opts)
} else {

@@ -174,3 +190,3 @@ return decoded as ICredential

static toUniformPresentation(presentation: OriginalVerifiablePresentation): IPresentation {
static toUniformPresentation(presentation: OriginalVerifiablePresentation, opts?: { maxTimeSkewInMS?: number }): IPresentation {
const original = presentation

@@ -184,4 +200,4 @@ const decoded = CredentialMapper.decodeVerifiablePresentation(original)

: (decoded as IPresentation)
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map(
CredentialMapper.toUniformCredential
uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) =>
CredentialMapper.toUniformCredential(vc, opts)
) as IVerifiableCredential[] // We cast it because we IPresentation needs a VC. The internal Credential doesn't have the required Proof anymore (that is intended)

@@ -191,7 +207,7 @@ return uniformPresentation

static jwtEncodedCredentialToUniformCredential(jwt: string): ICredential {
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt))
static jwtEncodedCredentialToUniformCredential(jwt: string, opts?: { maxTimeSkewInMS?: number }): ICredential {
return CredentialMapper.jwtDecodedCredentialToUniformCredential(jwt_decode(jwt), opts)
}
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential): ICredential {
static jwtDecodedCredentialToUniformCredential(decoded: JwtDecodedVerifiableCredential, opts?: { maxTimeSkewInMS?: number }): ICredential {
const credential: ICredential = {

@@ -203,2 +219,4 @@ ...(decoded.vc as ICredential),

const maxSkewInMS = opts?.maxTimeSkewInMS !== undefined ? opts.maxTimeSkewInMS : 999
if (decoded.exp) {

@@ -210,3 +228,6 @@ const expDate = credential.expirationDate

if (expDate && expDate !== expDateAsStr) {
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime())
if (!maxSkewInMS || diff > maxSkewInMS) {
throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`)
}
}

@@ -222,3 +243,6 @@ credential.expirationDate = expDateAsStr

if (issuanceDate && issuanceDate !== nbfDateAsStr) {
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime())
if (!maxSkewInMS || diff > maxSkewInMS) {
throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`)
}
}

@@ -225,0 +249,0 @@ credential.issuanceDate = nbfDateAsStr

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc