From 64048e2a1f5f3e676d8c79c09e97983e5e079f39 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 5 Mar 2024 16:43:51 -0600 Subject: [PATCH] updates --- packages/credentials/src/utils.ts | 11 +++----- .../tests/verifiable-credential.spec.ts | 28 ++++++++++++++++++- web5-spec | 2 +- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/credentials/src/utils.ts b/packages/credentials/src/utils.ts index c45e00ed1..4bb705d4c 100644 --- a/packages/credentials/src/utils.ts +++ b/packages/credentials/src/utils.ts @@ -25,7 +25,7 @@ export function getCurrentXmlSchema112Timestamp(): string { * timestamps for verifiable credentials and other applications requiring precision to the second * without the need for millisecond granularity. * - * @param nbf The UNIX timestamp to convert, measured in seconds. + * @param timestampInSeconds The UNIX timestamp to convert, measured in seconds. * @example * ```ts * const issuanceDate = getXmlSchema112Timestamp(1633036800); // "2021-10-01T00:00:00Z" @@ -33,14 +33,11 @@ export function getCurrentXmlSchema112Timestamp(): string { * * @returns A date-time string in the format "yyyy-MM-ddTHH:mm:ssZ", compliant with XML Schema 1.1.2, based on the provided UNIX timestamp. */ -export function getXmlSchema112Timestamp(nbf: number): string { - // Convert nbf from seconds to milliseconds and create a new Date object - const date = new Date(nbf * 1000); +export function getXmlSchema112Timestamp(timestampInSeconds: number): string { + const date = new Date(timestampInSeconds * 1000); // Format the date to an ISO string and then remove milliseconds - const issuanceDate = date.toISOString().replace(/\.\d{3}/, ''); - - return issuanceDate; + return date.toISOString().replace(/\.\d{3}/, ''); } /** diff --git a/packages/credentials/tests/verifiable-credential.spec.ts b/packages/credentials/tests/verifiable-credential.spec.ts index 4fe949ec6..0017dfa86 100644 --- a/packages/credentials/tests/verifiable-credential.spec.ts +++ b/packages/credentials/tests/verifiable-credential.spec.ts @@ -7,7 +7,7 @@ import { DidDht, DidKey, DidIon, DidJwk } from '@web5/dids'; import { Jwt } from '../src/jwt.js'; import { VerifiableCredential } from '../src/verifiable-credential.js'; import CredentialsVerifyTestVector from '../../../web5-spec/test-vectors/credentials/verify.json' assert { type: 'json' }; -import { getCurrentXmlSchema112Timestamp } from '../src/utils.js'; +import { getCurrentXmlSchema112Timestamp, getXmlSchema112Timestamp } from '../src/utils.js'; describe('Verifiable Credential Tests', async() => { let issuerDid: BearerDid; @@ -91,6 +91,32 @@ describe('Verifiable Credential Tests', async() => { } }); + it('create and sign kyc vc with did:jwk', async () => { + const did = await DidJwk.create(); + + const vc = await VerifiableCredential.create({ + type : 'KnowYourCustomerCred', + subject : did.uri, + issuer : did.uri, + expirationDate : getXmlSchema112Timestamp(2687920690), // 2055-03-05 + data : { + country: 'us' + } + }); + + const vcJwt = await vc.sign({ did }); + + await VerifiableCredential.verify({ vcJwt }); + + for( const currentVc of [vc, VerifiableCredential.parseJwt({ vcJwt })]){ + expect(currentVc.issuer).to.equal(did.uri); + expect(currentVc.subject).to.equal(did.uri); + expect(currentVc.type).to.equal('KnowYourCustomerCred'); + expect(currentVc.vcDataModel.issuanceDate).to.not.be.undefined; + expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri, country: 'us'}); + } + }); + it('create and sign vc with did:ion', async () => { const did = await DidIon.create(); diff --git a/web5-spec b/web5-spec index 962c1f3b2..2a30f682d 160000 --- a/web5-spec +++ b/web5-spec @@ -1 +1 @@ -Subproject commit 962c1f3b25854f550a6d1edeea3599587c4ef9f9 +Subproject commit 2a30f682df78077296a63babb6d173d0554b6683