Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Mar 5, 2024
1 parent 4fed152 commit 64048e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
11 changes: 4 additions & 7 deletions packages/credentials/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ 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"
* ```
*
* @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}/, '');
}

/**
Expand Down
28 changes: 27 additions & 1 deletion packages/credentials/tests/verifiable-credential.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion web5-spec

0 comments on commit 64048e2

Please sign in to comment.