Giter Club home page Giter Club logo

verifiable-credentials.w3c's Introduction

verifiable-credentials.w3c

$ git clone https://github.com/burhon97/verifiable-credentials.w3c.git
$ cd verifiable-credentials.w3c
$ npm install
  • Run command for create verifiable credential
node --experimental-json-modules create.js
  • Run command for create verifiable presentation
node --experimental-json-modules createPresentation.js
  • Run command for verify credential
node --experimental-json-modules verifyCredential.js
  • Run command for verify presentation
node --experimental-json-modules verifyPresentation.js

Usage

Create Verifiable Credential

import { JsonWebKey, JsonWebSignature } from "@transmute/json-web-signature";
import { documentLoader } from "./documentLoader.js";
import { verifiable } from "@transmute/vc.js";

export const key = {
  id: "did:key:z6MktWjP95fMqCMrfNULcdszFeTVUCE1zcgz3Hv5bVAisHgk#z6MktWjP95fMqCMrfNULcdszFeTVUCE1zcgz3Hv5bVAisHgk",
  type: "Ed25519VerificationKey2018",
  controller: "did:key:z6MktWjP95fMqCMrfNULcdszFeTVUCE1zcgz3Hv5bVAisHgk",
  publicKeyBase58: "F4ULYqQvVesPYsddw4v9QYuVecxAajSdMH19mDChx4uN",
  privateKeyBase58:
    "3SCL1scPSwPGb5QkoPCwyxrP1JJzsh3Ch47weF3LQDfJqQtTCQoPt8TnTRyCoEtKspLdhd74oDc4atJvRMNpmQTr",
};

const credential = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3id.org/security/suites/jws-2020/v1",
  ],
  id: "http://example.edu/credentials/3732",
  type: ["VerifiableCredential"],
  issuer: {
    id: "did:key:z6MktWjP95fMqCMrfNULcdszFeTVUCE1zcgz3Hv5bVAisHgk",
  },
  issuanceDate: "2010-01-01T19:23:24Z",
  credentialSubject: {
    id: "did:example:ebfeb1f712ebc6f1c276e12ec21",
  },
};

export const resultCredential = await verifiable.credential.create({
  credential,
  format: ["vc", "vc-jwt"],
  documentLoader: documentLoader,
  suite: new JsonWebSignature({
    key: await JsonWebKey.from(key),
  }),
});

console.log("create credential: ", resultCredential);

// #result
// create credential:  {
//   items: [
//     {
//       '@context': [Array],
//       id: 'http://example.edu/credentials/3732',
//       type: [Array],
//       issuer: [Object],
//       issuanceDate: '2010-01-01T19:23:24Z',
//       credentialSubject: [Object],
//       proof: [Object]
//     },
// ...
// ...
//   ]
// }

Create Verifiable Presentation

import { JsonWebKey, JsonWebSignature } from "@transmute/json-web-signature";
import { documentLoader } from "./documentLoader.js";
import { key } from "./create.js";
import { verifiable } from "@transmute/vc.js";

const presentation = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",
    "https://w3id.org/security/suites/jws-2020/v1",
  ],
  type: ["VerifiablePresentation"],
  holder: {
    id: key.controller,
  },
};

export const resultPresentation = await verifiable.presentation.create({
  presentation,
  format: ["vp", "vp-jwt"],
  documentLoader: documentLoader,
  challenge: "123", // this is supplied by the verifier / presentation recipient
  suite: new JsonWebSignature({
    key: await JsonWebKey.from(key),
  }),
});

console.log("create presentation: ", resultPresentation);

// #result
// create presentation:  {
//   items: [
//     {
//       '@context': [Array],
//       type: [Array],
//       holder: [Object],
//       proof: [Object]
//     },
// ...
// ...
//   ]
// }

Verify Presentation

import { JsonWebSignature } from "@transmute/json-web-signature";
import { documentLoader } from "./documentLoader.js";
import { verifiable } from "@transmute/vc.js";
import { resultPresentation } from "./createPresentation.js";

const result = await verifiable.presentation.verify({
  presentation: resultPresentation.items[0],
  format: ["vp", "vp-jwt"],
  documentLoader: documentLoader,
  challenge: "123", // this is supplied by the verifier / presentation recipient
  suite: new JsonWebSignature(),
});

console.log("verify presentaion: ", result);

// #result
// verify presentaion:  {
//   verified: true,
//   presentation: { verified: true, results: [ [Object] ] }
// }

Verify Credential

import { JsonWebSignature } from "@transmute/json-web-signature";
import { documentLoader } from "./documentLoader.js";
import { verifiable } from "@transmute/vc.js";
import { resultCredential } from "./create.js";

const result = await verifiable.credential.verify({
  credential: resultCredential.items[0],
  format: ["vc", "vc-jwt"],
  documentLoader: documentLoader,
  suite: [new JsonWebSignature()],
});

console.log("verify credential: ", result);

// #result
// verify credential:  { verified: true }

verifiable-credentials.w3c's People

Contributors

burhon97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.