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

did-jwt-vc

Package Overview
Dependencies
Maintainers
7
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

did-jwt-vc - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

8

CHANGELOG.md

@@ -0,1 +1,9 @@

## [1.0.2](https://github.com/decentralized-identity/did-jwt-vc/compare/1.0.1...1.0.2) (2020-06-29)
### Bug Fixes
* converting to jwt ([d7f9578](https://github.com/decentralized-identity/did-jwt-vc/commit/d7f95783c73eaaa521eab1fb352881884b59f42c)), closes [#37](https://github.com/decentralized-identity/did-jwt-vc/issues/37)
* **types:** widen types used as input ([c3e7a2e](https://github.com/decentralized-identity/did-jwt-vc/commit/c3e7a2e745145e985f60da7c343d9889d50e76dc))
## [1.0.1](https://github.com/decentralized-identity/did-jwt-vc/compare/1.0.0...1.0.1) (2020-06-26)

@@ -2,0 +10,0 @@

8

lib/converters.d.ts

@@ -1,2 +0,2 @@

import { VerifiableCredential, JWT, JwtPresentationPayload, JwtCredentialPayload, CredentialPayload, Credential, Verifiable, PresentationPayload, Presentation } from './types';
import { VerifiableCredential, JWT, JwtPresentationPayload, JwtCredentialPayload, CredentialPayload, W3CCredential, Verifiable, PresentationPayload, W3CPresentation } from './types';
export declare function asArray(input: any): any[];

@@ -11,3 +11,3 @@ export declare function isLegacyAttestationFormat(payload: any): boolean;

*/
export declare function normalizeCredential(input: Partial<VerifiableCredential> | Partial<JwtCredentialPayload>): Verifiable<Credential>;
export declare function normalizeCredential(input: Partial<VerifiableCredential> | Partial<JwtCredentialPayload>): Verifiable<W3CCredential>;
/**

@@ -30,3 +30,3 @@ * type used to signal a very loose input is accepted

*/
export declare function normalizePresentation(input: Partial<PresentationPayload> | Partial<JwtPresentationPayload> | JWT): Verifiable<Presentation>;
export declare function normalizePresentation(input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload> | JWT): Verifiable<W3CPresentation>;
/**

@@ -38,4 +38,4 @@ * Transforms a W3C Presentation payload into a JWT compatible encoding.

*/
export declare function transformPresentationInput(input: Partial<PresentationPayload> | Partial<JwtPresentationPayload>): JwtPresentationPayload;
export declare function transformPresentationInput(input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload>): JwtPresentationPayload;
export {};
//# sourceMappingURL=converters.d.ts.map

@@ -217,3 +217,3 @@ var __assign = (this && this.__assign) || function () {

if (!isNaN(converted)) {
result.nbf = converted / 1000;
result.nbf = Math.floor(converted / 1000);
delete result.issuanceDate;

@@ -225,3 +225,3 @@ }

if (!isNaN(converted)) {
result.exp = converted / 1000;
result.exp = Math.floor(converted / 1000);
delete result.expirationDate;

@@ -361,3 +361,3 @@ }

if (!isNaN(converted)) {
result.nbf = converted / 1000;
result.nbf = Math.floor(converted / 1000);
delete result.issuanceDate;

@@ -369,3 +369,3 @@ }

if (!isNaN(converted)) {
result.exp = converted / 1000;
result.exp = Math.floor(converted / 1000);
delete result.expirationDate;

@@ -372,0 +372,0 @@ }

@@ -1,5 +0,5 @@

import { JwtCredentialPayload, Issuer, JwtPresentationPayload, JWT, VerifiablePresentation, VerifiableCredential, CredentialPayload, PresentationPayload, Verifiable, Credential, Presentation, VerifiedCredential, VerifiedPresentation } from './types';
import { JwtCredentialPayload, Issuer, JwtPresentationPayload, JWT, VerifiablePresentation, VerifiableCredential, CredentialPayload, PresentationPayload, Verifiable, W3CCredential, W3CPresentation, VerifiedCredential, VerifiedPresentation } from './types';
import { DIDDocument } from 'did-resolver';
import { transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation } from './converters';
export { Issuer, JwtCredentialPayload, JwtPresentationPayload, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, Verifiable, Credential, Presentation, transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation };
export { Issuer, CredentialPayload, PresentationPayload, JwtCredentialPayload, JwtPresentationPayload, VerifiableCredential, VerifiablePresentation, VerifiedCredential, VerifiedPresentation, Verifiable, W3CCredential, W3CPresentation, transformCredentialInput, transformPresentationInput, normalizeCredential, normalizePresentation };
interface Resolvable {

@@ -6,0 +6,0 @@ resolve: (did: string) => Promise<DIDDocument>;

@@ -0,1 +1,12 @@

var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {

@@ -105,6 +116,6 @@ if (k2 === undefined) k2 = k;

return __generator(this, function (_a) {
parsedPayload = converters_1.transformCredentialInput(payload);
parsedPayload = __assign({ iat: undefined }, converters_1.transformCredentialInput(payload));
validateJwtCredentialPayload(parsedPayload);
return [2 /*return*/, did_jwt_1.createJWT(parsedPayload, {
issuer: issuer.did,
issuer: issuer.did || parsedPayload.iss,
signer: issuer.signer,

@@ -135,6 +146,6 @@ alg: issuer.alg || constants_1.JWT_ALG

return __generator(this, function (_a) {
parsedPayload = converters_1.transformPresentationInput(payload);
parsedPayload = __assign({ iat: undefined }, converters_1.transformPresentationInput(payload));
validateJwtPresentationPayload(parsedPayload);
return [2 /*return*/, did_jwt_1.createJWT(parsedPayload, {
issuer: issuer.did,
issuer: issuer.did || parsedPayload.iss,
signer: issuer.signer,

@@ -162,5 +173,5 @@ alg: issuer.alg || constants_1.JWT_ALG

if (payload.issuanceDate)
validators.validateTimestamp(new Date(payload.issuanceDate).valueOf() / 1000);
validators.validateTimestamp(payload.issuanceDate);
if (payload.expirationDate)
validators.validateTimestamp(new Date(payload.expirationDate).valueOf() / 1000);
validators.validateTimestamp(payload.expirationDate);
}

@@ -167,0 +178,0 @@ exports.validateCredentialPayload = validateCredentialPayload;

@@ -10,2 +10,3 @@ import { Signer, verifyJWT } from 'did-jwt';

export interface JwtCredentialPayload {
iss?: string;
sub: string;

@@ -31,2 +32,3 @@ vc: {

};
iss?: string;
aud?: string | string[];

@@ -47,5 +49,5 @@ nbf?: number;

interface FixedCredentialPayload {
'@context': string[];
'@context': string | string[];
id?: string;
type: string[];
type: string | string[];
issuer: IssuerType;

@@ -65,2 +67,4 @@ issuanceDate: DateType;

interface NarrowCredentialDefinitions {
'@context': string[];
type: string[];
issuer: Exclude<IssuerType, string>;

@@ -87,3 +91,3 @@ issuanceDate: string;

*/
export declare type Credential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>;
export declare type W3CCredential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>;
/**

@@ -93,8 +97,8 @@ * used as input when creating Verifiable Presentations

export interface FixedPresentationPayload {
'@context': string[];
type: string[];
'@context': string | string[];
type: string | string[];
id?: string;
verifiableCredential: VerifiableCredential[];
holder: string;
verifier?: string[];
verifier?: string | string[];
issuanceDate?: string;

@@ -105,3 +109,6 @@ expirationDate?: string;

interface NarrowPresentationDefinitions {
verifiableCredential: Verifiable<Credential>[];
'@context': string[];
type: string[];
verifier: string[];
verifiableCredential: Verifiable<W3CCredential>[];
}

@@ -115,3 +122,3 @@ /**

*/
export declare type Presentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>;
export declare type W3CPresentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>;
export interface Proof {

@@ -125,11 +132,11 @@ type?: string;

export declare type JWT = string;
export declare type VerifiablePresentation = Verifiable<Presentation> | JWT;
export declare type VerifiableCredential = JWT | Verifiable<Credential>;
export declare type VerifiablePresentation = Verifiable<W3CPresentation> | JWT;
export declare type VerifiableCredential = JWT | Verifiable<W3CCredential>;
declare type UnpackedPromise<T> = T extends Promise<infer U> ? U : T;
export declare type VerifiedJWT = UnpackedPromise<ReturnType<typeof verifyJWT>>;
export declare type VerifiedPresentation = VerifiedJWT & {
verifiablePresentation: Verifiable<Presentation>;
verifiablePresentation: Verifiable<W3CPresentation>;
};
export declare type VerifiedCredential = VerifiedJWT & {
verifiableCredential: Verifiable<Credential>;
verifiableCredential: Verifiable<W3CCredential>;
};

@@ -136,0 +143,0 @@ export interface Issuer {

@@ -1,5 +0,5 @@

import { JwtCredentialSubject } from './types';
import { JwtCredentialSubject, DateType } from './types';
import { VerifiableCredential } from 'src';
export declare function validateJwtFormat(value: VerifiableCredential): void;
export declare function validateTimestamp(value: number | string): void;
export declare function validateTimestamp(value: number | DateType): void;
export declare function validateContext(value: string | string[]): void;

@@ -6,0 +6,0 @@ export declare function validateVcType(value: string | string[]): void;

@@ -15,2 +15,5 @@ (function (factory) {

var converters_1 = require("./converters");
function isDateObject(input) {
return input && Object.prototype.toString.call(input) === '[object Date]' && !isNaN(input);
}
function validateJwtFormat(value) {

@@ -36,5 +39,5 @@ if (typeof value === 'string' && !value.match(constants_1.JWT_FORMAT)) {

else if (typeof value === 'string') {
validateTimestamp(new Date(value).valueOf() / 1000);
validateTimestamp(Math.floor(new Date(value).valueOf() / 1000));
}
else {
else if (!isDateObject(value)) {
throw new TypeError("\"" + value + "\" is not a valid time");

@@ -41,0 +44,0 @@ }

{
"name": "did-jwt-vc",
"version": "1.0.1",
"version": "1.0.2",
"description": "Create and verify W3C Verifiable Credentials and Presentations in JWT format",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -8,2 +8,4 @@ import {

import { DEFAULT_JWT_PROOF_TYPE } from '../constants'
import { CredentialPayload, PresentationPayload } from '../types'
import { validateJwtCredentialPayload, validateJwtPresentationPayload } from '..'

@@ -332,2 +334,21 @@ function encodeBase64Url(input: string): string {

it('transforms to a valid payload', () => {
const credential: CredentialPayload = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential', 'PublicProfile'],
issuer: { id: 'did:example:123' },
issuanceDate: new Date().toISOString(),
expirationDate: new Date(Date.now() + 365 * 24 * 3600 * 1000).toISOString(),
id: 'vc1',
credentialSubject: {
id: 'did:example:123',
name: 'Alice'
}
}
const transformed = transformCredentialInput(credential)
expect(() => {
validateJwtCredentialPayload(transformed)
}).not.toThrow()
})
describe('credentialSubject', () => {

@@ -534,3 +555,3 @@ it('uses credentialSubject.id as sub', () => {

vp: { verifiableCredential: [{ foo: 'baz' }] }
} as any)
})
expect(result).toMatchObject({

@@ -631,3 +652,3 @@ verifiableCredential: [{ foo: 'bar' }, { foo: 'baz' }]

it('merges type arrays for non-array types', () => {
const result = normalizePresentation({ type: 'foo', vp: { type: 'bar' } } as any)
const result = normalizePresentation({ type: 'foo', vp: { type: 'bar' } })
expect(result).toMatchObject({ type: ['foo', 'bar'] })

@@ -652,3 +673,3 @@ expect(result).not.toHaveProperty('vp')

it('merges @context arrays for non-array contexts', () => {
const result = normalizePresentation({ '@context': 'foo', context: 'bar', vp: { '@context': 'baz' } } as any)
const result = normalizePresentation({ '@context': 'foo', context: 'bar', vp: { '@context': 'baz' } })
expect(result).toMatchObject({ '@context': ['bar', 'foo', 'baz'] })

@@ -738,2 +759,19 @@ expect(result).not.toHaveProperty('vp')

it('transforms to a valid payload', () => {
const presentation: PresentationPayload = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation', 'PublicProfile'],
holder: 'did:example:123',
verifier: ['did:example:234'],
issuanceDate: new Date().toISOString(),
expirationDate: new Date(Date.now() + 365 * 24 * 3600 * 1000).toISOString(),
id: 'vp1',
verifiableCredential: ['header.payload.signature']
}
const transformed = transformPresentationInput(presentation)
expect(() => {
validateJwtPresentationPayload(transformed)
}).not.toThrow()
})
describe('verifiableCredential', () => {

@@ -744,3 +782,3 @@ it('merges verifiableCredentials arrays', () => {

vp: { verifiableCredential: [{ foo: 'bar' }, 'header.payload.signature'] }
} as any)
})
expect(result).toMatchObject({

@@ -756,3 +794,3 @@ vp: { verifiableCredential: [{ id: 'foo' }, { foo: 'bar' }, 'header.payload.signature'] }

vp: { verifiableCredential: { foo: 'bar' } }
} as any)
})
expect(result).toMatchObject({ vp: { verifiableCredential: [{ id: 'foo' }, { foo: 'bar' }] } })

@@ -766,3 +804,3 @@ expect(result).not.toHaveProperty('verifiableCredential')

vp: { verifiableCredential: [{ foo: 'bar' }, 'header.payload2.signature'] }
} as any)
})
expect(result).toMatchObject({

@@ -778,3 +816,3 @@ vp: { verifiableCredential: ['header.payload1.signature', { foo: 'bar' }, 'header.payload2.signature'] }

vp: { verifiableCredential: [null, { foo: 'bar' }, 'header.payload2.signature'] }
} as any)
})
expect(result).toMatchObject({ vp: { verifiableCredential: [{ foo: 'bar' }, 'header.payload2.signature'] } })

@@ -798,3 +836,3 @@ expect(result).not.toHaveProperty('verifiableCredential')

vp: { '@context': ['CC'] }
} as any)
})
expect(result).toMatchObject({ vp: { '@context': ['AA', 'BB', 'CC'] } })

@@ -830,3 +868,3 @@ expect(result).not.toHaveProperty('context')

it('merges type fields when not array types', () => {
const result = transformPresentationInput({ type: 'AA', vp: { type: ['BB'] } } as any)
const result = transformPresentationInput({ type: 'AA', vp: { type: ['BB'] } })
expect(result).toMatchObject({ vp: { type: ['AA', 'BB'] } })

@@ -833,0 +871,0 @@ expect(result).not.toHaveProperty('type')

@@ -8,3 +8,3 @@ import EthrDID from 'ethr-did'

} from '../index'
import { verifyJWT, decodeJWT } from 'did-jwt'
import { decodeJWT } from 'did-jwt'
import { DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, DEFAULT_CONTEXT } from '../constants'

@@ -11,0 +11,0 @@ import {

@@ -7,6 +7,6 @@ import {

CredentialPayload,
Credential,
W3CCredential,
Verifiable,
PresentationPayload,
Presentation
W3CPresentation
} from './types'

@@ -53,3 +53,3 @@ import { decodeJWT } from 'did-jwt'

function normalizeJwtCredentialPayload(input: Partial<JwtCredentialPayload>): Credential {
function normalizeJwtCredentialPayload(input: Partial<JwtCredentialPayload>): W3CCredential {
let result: Partial<CredentialPayload> = { ...input }

@@ -114,6 +114,6 @@

return result as Credential
return result as W3CCredential
}
function normalizeJwtCredential(input: JWT): Verifiable<Credential> {
function normalizeJwtCredential(input: JWT): Verifiable<W3CCredential> {
let decoded

@@ -142,3 +142,3 @@ try {

input: Partial<VerifiableCredential> | Partial<JwtCredentialPayload>
): Verifiable<Credential> {
): Verifiable<W3CCredential> {
if (typeof input === 'string') {

@@ -213,3 +213,3 @@ if (JWT_FORMAT.test(input)) {

if (!isNaN(converted)) {
result.nbf = converted / 1000
result.nbf = Math.floor(converted / 1000)
delete result.issuanceDate

@@ -222,3 +222,3 @@ }

if (!isNaN(converted)) {
result.exp = converted / 1000
result.exp = Math.floor(converted / 1000)
delete result.expirationDate

@@ -246,3 +246,3 @@ }

function normalizeJwtPresentationPayload(input: DeepPartial<JwtPresentationPayload>): Presentation {
function normalizeJwtPresentationPayload(input: DeepPartial<JwtPresentationPayload>): W3CPresentation {
const result: Partial<PresentationPayload> = { ...input }

@@ -304,6 +304,6 @@

return result as Presentation
return result as W3CPresentation
}
function normalizeJwtPresentation(input: JWT): Verifiable<Presentation> {
function normalizeJwtPresentation(input: JWT): Verifiable<W3CPresentation> {
let decoded

@@ -329,4 +329,4 @@ try {

export function normalizePresentation(
input: Partial<PresentationPayload> | Partial<JwtPresentationPayload> | JWT
): Verifiable<Presentation> {
input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload> | JWT
): Verifiable<W3CPresentation> {
if (typeof input === 'string') {

@@ -361,3 +361,3 @@ if (JWT_FORMAT.test(input)) {

export function transformPresentationInput(
input: Partial<PresentationPayload> | Partial<JwtPresentationPayload>
input: Partial<PresentationPayload> | DeepPartial<JwtPresentationPayload>
): JwtPresentationPayload {

@@ -387,3 +387,3 @@ const result: Partial<JwtPresentationPayload> = { vp: { ...input.vp }, ...input }

if (!isNaN(converted)) {
result.nbf = converted / 1000
result.nbf = Math.floor(converted / 1000)
delete result.issuanceDate

@@ -396,3 +396,3 @@ }

if (!isNaN(converted)) {
result.exp = converted / 1000
result.exp = Math.floor(converted / 1000)
delete result.expirationDate

@@ -399,0 +399,0 @@ }

@@ -14,4 +14,4 @@ import { createJWT, verifyJWT } from 'did-jwt'

Verifiable,
Credential,
Presentation,
W3CCredential,
W3CPresentation,
VerifiedCredential,

@@ -31,2 +31,4 @@ VerifiedPresentation

Issuer,
CredentialPayload,
PresentationPayload,
JwtCredentialPayload,

@@ -39,4 +41,4 @@ JwtPresentationPayload,

Verifiable,
Credential,
Presentation,
W3CCredential,
W3CPresentation,
transformCredentialInput,

@@ -70,6 +72,6 @@ transformPresentationInput,

): Promise<JWT> {
const parsedPayload = transformCredentialInput(payload)
const parsedPayload: JwtCredentialPayload = { iat: undefined, ...transformCredentialInput(payload) }
validateJwtCredentialPayload(parsedPayload)
return createJWT(parsedPayload, {
issuer: issuer.did,
issuer: issuer.did || parsedPayload.iss,
signer: issuer.signer,

@@ -98,6 +100,6 @@ alg: issuer.alg || JWT_ALG

): Promise<JWT> {
const parsedPayload = transformPresentationInput(payload)
const parsedPayload: JwtPresentationPayload = { iat: undefined, ...transformPresentationInput(payload) }
validateJwtPresentationPayload(parsedPayload)
return createJWT(parsedPayload, {
issuer: issuer.did,
issuer: issuer.did || parsedPayload.iss,
signer: issuer.signer,

@@ -120,4 +122,4 @@ alg: issuer.alg || JWT_ALG

validators.validateCredentialSubject(payload.credentialSubject)
if (payload.issuanceDate) validators.validateTimestamp(new Date(payload.issuanceDate).valueOf() / 1000)
if (payload.expirationDate) validators.validateTimestamp(new Date(payload.expirationDate).valueOf() / 1000)
if (payload.issuanceDate) validators.validateTimestamp(payload.issuanceDate)
if (payload.expirationDate) validators.validateTimestamp(payload.expirationDate)
}

@@ -124,0 +126,0 @@

@@ -13,2 +13,3 @@ import { Signer, verifyJWT } from 'did-jwt'

export interface JwtCredentialPayload {
iss?: string
sub: string

@@ -35,2 +36,3 @@ vc: {

}
iss?: string
aud?: string | string[]

@@ -49,5 +51,5 @@ nbf?: number

interface FixedCredentialPayload {
'@context': string[]
'@context': string | string[]
id?: string
type: string[]
type: string | string[]
issuer: IssuerType

@@ -69,2 +71,4 @@ issuanceDate: DateType

interface NarrowCredentialDefinitions {
'@context': string[]
type: string[]
issuer: Exclude<IssuerType, string>

@@ -91,3 +95,3 @@ issuanceDate: string

*/
export type Credential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>
export type W3CCredential = Extensible<Replace<FixedCredentialPayload, NarrowCredentialDefinitions>>

@@ -98,8 +102,8 @@ /**

export interface FixedPresentationPayload {
'@context': string[]
type: string[]
'@context': string | string[]
type: string | string[]
id?: string
verifiableCredential: VerifiableCredential[]
holder: string
verifier?: string[]
verifier?: string | string[]
issuanceDate?: string

@@ -112,3 +116,6 @@ expirationDate?: string

interface NarrowPresentationDefinitions {
verifiableCredential: Verifiable<Credential>[]
'@context': string[]
type: string[]
verifier: string[]
verifiableCredential: Verifiable<W3CCredential>[]
}

@@ -123,3 +130,3 @@

*/
export type Presentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>
export type W3CPresentation = Extensible<Replace<FixedPresentationPayload, NarrowPresentationDefinitions>>

@@ -134,4 +141,4 @@ export interface Proof {

export type VerifiablePresentation = Verifiable<Presentation> | JWT
export type VerifiableCredential = JWT | Verifiable<Credential>
export type VerifiablePresentation = Verifiable<W3CPresentation> | JWT
export type VerifiableCredential = JWT | Verifiable<W3CCredential>

@@ -142,7 +149,7 @@ type UnpackedPromise<T> = T extends Promise<infer U> ? U : T

export type VerifiedPresentation = VerifiedJWT & {
verifiablePresentation: Verifiable<Presentation>
verifiablePresentation: Verifiable<W3CPresentation>
}
export type VerifiedCredential = VerifiedJWT & {
verifiableCredential: Verifiable<Credential>
verifiableCredential: Verifiable<W3CCredential>
}

@@ -149,0 +156,0 @@

@@ -1,6 +0,10 @@

import { DID_FORMAT, DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, JWT_FORMAT } from './constants'
import { JwtCredentialSubject } from './types'
import { DEFAULT_CONTEXT, DEFAULT_VC_TYPE, DEFAULT_VP_TYPE, JWT_FORMAT } from './constants'
import { JwtCredentialSubject, DateType } from './types'
import { VerifiableCredential } from 'src'
import { asArray } from './converters'
function isDateObject(input: any) {
return input && Object.prototype.toString.call(input) === '[object Date]' && !isNaN(input)
}
export function validateJwtFormat(value: VerifiableCredential): void {

@@ -19,3 +23,3 @@ if (typeof value === 'string' && !value.match(JWT_FORMAT)) {

// 12 digits max is 999999999999 -> 09/27/33658 @ 1:46am (UTC)
export function validateTimestamp(value: number | string): void {
export function validateTimestamp(value: number | DateType): void {
if (typeof value === 'number') {

@@ -26,4 +30,4 @@ if (!(Number.isInteger(value) && value < 100000000000)) {

} else if (typeof value === 'string') {
validateTimestamp(new Date(value).valueOf() / 1000)
} else {
validateTimestamp(Math.floor(new Date(value).valueOf() / 1000))
} else if (!isDateObject(value)) {
throw new TypeError(`"${value}" is not a valid time`)

@@ -30,0 +34,0 @@ }

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

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