npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@krebitdao/eip712-vc

v1.0.3

Published

Krebit SDK for EIP712 Verified Credentials

Downloads

5

Readme

eip712-vc

Krebit EIP712 Verifiable Credentials SDK

Docs

This repository hosts the Krebit EIP712-VC tools, based on W3C Ethereum EIP712 Signature 2021 Draft.

It provides functions for creating both W3C compliant Verifiable Credentials, and also a Solidity compatible version that can be used in contracts like krebit-contracts.

Overview

Installation

$ npm install -s @krebitdao/eip721-vc

Configuring the EIP712 Domain

import {
  EIP712VC,
  VerifiableCredential,
  EIP712VerifiableCredential,
  DEFAULT_CONTEXT,
  EIP712_CONTEXT,
  DEFAULT_VC_TYPE,
  getEIP712Credential
} from '@krebitdao/eip721-vc';

let eip712vc = new EIP712VC({
  name: 'Krebit',
  version: '0.1',
  chainId: 4,
  verifyingContract: '0x00000000000000000000000000000000000000000000'
});

W3C EIP712 Verifiable Credentials

Creating

import { Wallet } from '@ethersproject/wallet';

let issuanceDate = Date.now();
let expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 3);

let issuerType = [{ name: 'id', type: 'string' }];

let credentialSubjectTypes = {
  CredentialSubject: [
    { name: 'type', type: 'string' },
    { name: 'id', type: 'string' },
    { name: 'name', type: 'string' },
    { name: 'child', type: 'Person' }
  ],
  Person: [
    { name: 'type', type: 'string' },
    { name: 'name', type: 'string' }
  ]
};

let credential = {
  '@context': [DEFAULT_CONTEXT, EIP712_CONTEXT],
  type: [DEFAULT_VC_TYPE],
  id: 'https://example.org/person/1234',
  issuer: {
    id: 'did:issuer'
  },
  credentialSubject: {
    type: 'Person',
    id: 'did:example:bbbbaaaa',
    name: 'Vitalik',
    child: {
      type: 'Person',
      name: 'Ethereum'
    }
  },
  credentialSchema: {
    id: 'https://example.com/schemas/v1',
    type: 'Eip712SchemaValidator2021'
  },
  issuanceDate: new Date(issuanceDate).toISOString(),
  expirationDate: new Date(expirationDate).toISOString(),
  proof: {
    verificationMethod: 'did:issuer#key-1',
    ethereumAddress: 'acc1',
    created: new Date(issuanceDate).toISOString(),
    proofPurpose: 'assertionMethod',
    type: 'EthereumEip712Signature2021'
  }
};

const wallet = Wallet.createRandom();

const vc: VerifiableCredential = await eip712vc.createW3CVerifiableCredential(
  credential,
  credentialSubjectTypes,
  async (data: TypedMessage<EIP712MessageTypes>) => {
    // Replace this fuction with your own signing code
    return signTypedData_v4(
      Buffer.from(wallet._signingKey().privateKey.slice(2), 'hex'),
      { data }
    );
  }
);

Creating Solidity Compatible EIP712 Verifiable Credentials

Creating

import { Wallet } from '@ethersproject/wallet';

let issuanceDate = Date.now();
let expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 3);

let issuerType = [
  { name: 'id', type: 'string' },
  { name: 'ethereumAddress', type: 'address' }
];

let credentialSubjectTypes = {
  CredentialSubject: [
    { name: 'id', type: 'string' },
    { name: 'ethereumAddress', type: 'address' },
    { name: '_type', type: 'string' },
    { name: 'typeSchema', type: 'string' },
    { name: 'value', type: 'string' },
    { name: 'encrypted', type: 'string' },
    { name: 'trust', type: 'uint8' },
    { name: 'stake', type: 'uint256' },
    { name: 'nbf', type: 'uint256' },
    { name: 'exp', type: 'uint256' }
  ]
};

let credential = {
  '@context': [DEFAULT_CONTEXT, EIP712_CONTEXT],
  type: [DEFAULT_VC_TYPE],
  id: 'https://example.org/person/1234',
  issuer: {
    id: 'did:issuer',
    ethereumAddress: 'acc1'
  },
  credentialSubject: {
    id: 'did:user',
    ethereumAddress: 'acc1',
    type: 'fullName',
    typeSchema: 'ceramic://def',
    value: 'encrypted',
    encrypted:
      '0x0c94bf56745f8d3d9d49b77b345c780a0c11ea997229f925f39a1946d51856fb',
    trust: 50,
    stake: 6,
    nbf: Math.floor(issuanceDate / 1000),
    exp: Math.floor(expirationDate.getTime() / 1000)
  },
  credentialSchema: {
    id: 'https://example.com/schemas/v1',
    type: 'Eip712SchemaValidator2021'
  },
  issuanceDate: new Date(issuanceDate).toISOString(),
  expirationDate: new Date(expirationDate).toISOString()
};

let eip712Credential = getEIP712Credential(credential);

const vc: EIP712VerifiableCredential = await eip712vc.createEIP712VerifiableCredential(
  eip712Credential,
  credentialSubjectTypes,
  async (data: TypedMessage<EIP712MessageTypes>) => {
    // Replace this fuction with your own signing code
    return signTypedData_v4(
      Buffer.from(wallet._signingKey().privateKey.slice(2), 'hex'),
      { data }
    );
  }
);

Creating Krebit Compatible EIP712 Verifiable Credentials

Creating

import { getKrebitCredentialTypes } from '@krebitdao/eip721-vc';

let issuanceDate = Date.now();
let expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 3);

let credential = {
  '@context': [DEFAULT_CONTEXT, EIP712_CONTEXT],
  type: [DEFAULT_VC_TYPE],
  id: 'https://example.org/person/1234',
  issuer: {
    id: 'did:issuer',
    ethereumAddress: 'acc1'
  },
  credentialSubject: {
    id: 'did:user',
    ethereumAddress: 'acc1',
    type: 'fullName',
    typeSchema: 'ceramic://def',
    value: 'encrypted',
    encrypted:
      '0x0c94bf56745f8d3d9d49b77b345c780a0c11ea997229f925f39a1946d51856fb',
    trust: 50,
    stake: 6,
    nbf: Math.floor(issuanceDate / 1000),
    exp: Math.floor(expirationDate.getTime() / 1000)
  },
  credentialSchema: {
    id: 'https://example.com/schemas/v1',
    type: 'Eip712SchemaValidator2021'
  },
  issuanceDate: new Date(issuanceDate).toISOString(),
  expirationDate: new Date(expirationDate).toISOString()
};

let eip712Credential = getEIP712Credential(credential);

let krebitTypes = getKrebitCredentialTypes();

const vc = await eip712vc.createEIP712VerifiableCredential(
  eip712Credential,
  krebitTypes,
  async data => {
    // Replace this fuction with your own signing code
    return await issuerSigner._signTypedData(
      {
        name: 'Krebit',
        version: '0.1',
        chainId: 4,
        verifyingContract: '0x00000000000000000000000000000000000000000000'
      },
      krebitTypes,
      credential
    );
  }
);

Verifying

eip712vc.verifyEIP712Credential(
  issuerAddress,
  eip712Credential,
  krebitTypes,
  vc.proof.proofValue,
  async (data: TypedMessage<EIP712MessageTypes>, proofValue: string) => {
    // Replace this fuction with your own signing code
    return recoverTypedSignature_v4({ data, sig: proofValue });
  }
);

Learn More

The guides in the docs site will teach about different concepts of the Krebit Protocol.

Contribute

Krebit Protocol exists thanks to its contributors. There are many ways you can participate and help build public goods. Check out the Krebit Gitcoin Grants!

License

Krebit EIP712-VC is released under the ISC License.