1.0.1 • Published 2 years ago

everscale-vc-sdk-radiance v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Verifiable Credentials using the Everscale SDK

SDK for creating, signing and verifying Verifiable Credentials(VC) and Verifiable Presentation(VP) using JavaScript

Table of Contents

Install

Requires Node.js to work

Enter commands to install SDK

npm install everscale-vc-sdk-radiance

Description

JavaScript SDK that allows you to work with Verifiable Credentials(VC) and Verifiable Presentation(VP) developed according to the Verifiable Credentials Data Model v1.1 specification and uses the Everscale blockchain to store the user's status and store the VC.

The main functionality that our SDK provides:

1) Signature (issuance) of Verifiable Credentials (VC). 2) Creation of Verifiable Presentation (VP), with and without a signature. 3) Verification of Verifiable Credentials(VC) 4) Verification of Verifiable Presentation(VP). 5) Create a credentialStatus and look it up on the Everscale blockchain. 6) Storing Verifiable Credentials(VC) by the holder on the Everscale blockchain.

Security

The basic security of your system depends on your own decisions (where do you store your private keys, what you put in the IDs, etc.). The security of storage in the Everscale Verifiable Credentials (VC) blockchain is carried out by data encryption and Everscale.

Specification

Description of all sdk functions by modules

Contracts

smart-contracts

Addresses for the ResolverContract contract:

0:904bfbc6681f1fdf884e558e1e1634615eba657dd7227c5bd37ea8b428b7c62a - main.ton.dev

0:a867a0dd47aa4f3145e3438e38fdbcb9548feb8c13387da2bdd0343b7ea9b4cb - net.ton.dev

Quick start

Issuing a Verifiable Credentials(VC)

Function signs and issues Verifiable Credentials Accepts: 1) credential - unsigned credentials 2) secretKey - secret key of the issuer

const vc = require('everscale-vc-sdk-radiance')


const credential = {
    "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://www.w3.org/2018/credentials/examples/v1"
    ],
    "id": "https://example.com/credentials/1872",
    "type": ["VerifiableCredential", "AlumniCredential"],
    "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
    "issuanceDate": "2010-01-01T19:23:24Z",
    "credentialSubject": {
        "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
        "alumniOf": "Example University"
    }
}

const secretKey = "7e8b57b7e7519ae5cbce869311d6c824c7a113e4e3d4ca6e929e488e66442faa"

vc.moduleVC.issueVC(credential, secretKey).then((data) => {
    console.log(JSON.stringify(data, null, 2))
})

Creating a Verifiable Presentation(VP)

Creating a Verifiable Presentation (VP) is divided into 2 parts:

  • Creating a presentation without a signature
  • Signature presentation

Creating an unsigned presentation

Accepts: 1) verifiableCredential - one or more Verifiable Credentials(VC) 2) id - is optional and can be used as a unique identifier for Verifiable Presentation(VP) 3) holder - is optional, but if present must be the URI of the object that creates the Verifiable Presentation(VP)

const vc = require('everscale-vc-sdk-radiance')

const verifiableCredential = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",        
    "https://www.w3.org/2018/credentials/examples/v1"
  ],
  "id": "https://example.com/credentials/1872",      
  "type": [
    "VerifiableCredential",
    "AlumniCredential"
  ],
  "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
  "issuanceDate": "2010-01-01T19:23:24Z",
  "credentialSubject": {
    "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
    "alumniOf": "Example University"
  },
  "proof": {
    "type": "Ed25519Signature2020",
    "created": "2022-05-05T06:48:08.658Z",
    "verificationMethod": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
    "proofPurpose": "assertionMethod",
    "proofValue": "1dd750eb48f71da5d0ddf1562daa9d815619e9a08f6067a908f654241383ee1aed0e35e85e6fc141c670819d7e445fc105dd387cfcc855f304b48e536242c208"
  }
}

const id = "12332"
const holder = "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e"

vc.moduleVP.createPresentation(verifiableCredential, id, holder).then((data) => {
    console.log(JSON.stringify(data, null, 2))
})

Signature presentation

Accepts: 1) presentation - the presentation created above 2) issuerDID - URI that leads to the signer's verification method 3) secretKey - secret key by which the presentation will be signed

const vc = require('everscale-vc-sdk-radiance')

const presentation = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1"
  ],
  "type": [
    "VerifiablePresentation"
  ],
  "verifiableCredential": [
    {
      "@context": [
        "https://www.w3.org/2018/credentials/v1",        
        "https://www.w3.org/2018/credentials/examples/v1"
      ],
      "id": "https://example.com/credentials/1872",      
      "type": [
        "VerifiableCredential",
        "AlumniCredential"
      ],
      "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
      "issuanceDate": "2010-01-01T19:23:24Z",
      "credentialSubject": {
        "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
        "alumniOf": "Example University"
      },
      "proof": {
        "type": "Ed25519Signature2020",
        "created": "2022-05-05T06:48:08.658Z",
        "verificationMethod": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
        "proofPurpose": "assertionMethod",
        "proofValue": "1dd750eb48f71da5d0ddf1562daa9d815619e9a08f6067a908f654241383ee1aed0e35e85e6fc141c670819d7e445fc105dd387cfcc855f304b48e536242c208"
      }
    }
  ],
  "id": "12332",
  "holder": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e"
}

const issuerDID = "did:everscale:7fbf2d23174967c903adef03075f482798f24d5693d05cb65345b3e5ff7e2d89"
const secretKey = "e99ea25d95f8015f86aede1acebc09addd4cff2656cf3f443032e9af2c5de421"

vc.moduleVP.signPresentation(presentation, issuerDID, secretKey).then((data) => {
    console.log(JSON.stringify(data, null, 2))
})

Verify of Verifiable Credentials(VC)

Accepts: 1) VC - Verifiable Credentials 2) publicKey - public key of the issuer

const vc = require('everscale-vc-sdk-radiance')

const VC = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",        
    "https://www.w3.org/2018/credentials/examples/v1"
  ],
  "id": "https://example.com/credentials/1872",      
  "type": [
    "VerifiableCredential",
    "AlumniCredential"
  ],
  "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
  "issuanceDate": "2010-01-01T19:23:24Z",
  "credentialSubject": {
    "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
    "alumniOf": "Example University"
  },
  "proof": {
    "type": "Ed25519Signature2020",
    "created": "2022-05-05T06:48:08.658Z",
    "verificationMethod": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
    "proofPurpose": "assertionMethod",
    "proofValue": "1dd750eb48f71da5d0ddf1562daa9d815619e9a08f6067a908f654241383ee1aed0e35e85e6fc141c670819d7e445fc105dd387cfcc855f304b48e536242c208"
  }
}

const publicKey = "a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260"

vc.moduleVC.verifyVC(VC, publicKey).then(console.log)

Verify of Verifiable Presentation(VP)

Accepts: 1) verifiablePresentation - Verifiable Presentation(VP) 2) publicKey - the public key of the signer

const vc = require('everscale-vc-sdk-radiance')

const verifiablePresentation = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1"
  ],
  "type": [
    "VerifiablePresentation"
  ],
  "verifiableCredential": [
    {
      "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://www.w3.org/2018/credentials/examples/v1"
      ],
      "id": "https://example.com/credentials/1872",
      "type": [
        "VerifiableCredential",
        "AlumniCredential"
      ],
      "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
      "issuanceDate": "2010-01-01T19:23:24Z",
      "credentialSubject": {
        "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
        "alumniOf": "Example University"
      },
      "proof": {
        "type": "Ed25519Signature2020",
        "created": "2022-05-05T06:48:08.658Z",
        "verificationMethod": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
        "proofPurpose": "assertionMethod",
        "proofValue": "1dd750eb48f71da5d0ddf1562daa9d815619e9a08f6067a908f654241383ee1aed0e35e85e6fc141c670819d7e445fc105dd387cfcc855f304b48e536242c208"
      }
    }
  ],
  "id": "12332",
  "holder": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
  "proof": {
    "type": "Ed25519Signature2020",
    "created": "2022-05-05T07:09:58.939Z",
    "verificationMethod": "did:everscale:7fbf2d23174967c903adef03075f482798f24d5693d05cb65345b3e5ff7e2d89",
    "proofPurpose": "assertionMethod",
    "proofValue": "fe2101dc2da954413bc69e0f35cf2e2fef633d52d401389292459398c3e53d475c63c09ac953b09f8e6b2b0c59ca4103d9502870b5449bf114f8924e4d65bf07"
  }
}

const publicKey = "7fbf2d23174967c903adef03075f482798f24d5693d05cb65345b3e5ff7e2d89"

vc.moduleVP.verifyPresentation(verifiablePresentation, publicKey).then(console.log)

createStatus

Accepts: statusVCRoot - The Account created with the tonclient/appkit contract that issues the status userAccount - Account from which the transaction will be made holder - VC holder address for which the status is being created

const { TonClient, signerKeys, signerNone } = require('@eversdk/core')
const { libNode } = require('@eversdk/lib-node')
const { Account } = require('@eversdk/appkit')
const vc = require('everscale-vc-sdk-radiance')
const { ClientContract } = require('everscale-vc-sdk-radiance/src/build/ClientContract')
const { StatusVCRootContract } = require('everscale-vc-sdk-radiance/src/build/StatusVCRootContract')

TonClient.useBinaryLibrary(libNode)

const client = new TonClient({
  network: {
    endpoints: ["net.ton.dev"]
  }
})

const statusRoot = new Account(StatusVCRootContract, {
  address: "0:3c09dbbc7a3aa9cb1cae3b307a063cf111e38166d7dd1940bed083ce4dce8228",
  client: client
})

const issuer = new Account(ClientContract, {
  address: "0:9f918cb6c22d28e82ebb57c79fbbbde00318b6402024d33895ccd5256806a245",
  signer: signerKeys({
      public: 'a1d6d37f31b71c570f8c78d06c955719a7194f23b203851a8be8ea82c9f4035d',
      secret: '3b61258adaada3a048513bbb54c658dc3a656bdaffb391c057196476da5f4e04'
  }),
  client: client
})

const holder = "47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e"


vc.moduleEver.createStatus(statusRoot, issuer, holder).then(console.log)

storage Verifiable Credentials(VC) in the Evrescale blockchain

A contract was specifically created to store data in the blockchain, but you can’t just store Verifiable Credentials (VC) in a contract. To protect it, we will encrypt the VC and then enter it into the contract.

const vc = require('everscale-vc-sdk-radiance')
const { ClientContract } = require('everscale-vc-sdk-radiance/src/build/ClientContract')
const { TonClient, signerKeys, signerNone } = require('@eversdk/core')
const { libNode } = require('@eversdk/lib-node')
const { Account } = require('@eversdk/appkit')

TonClient.useBinaryLibrary(libNode)

const client = new TonClient({
  network: {
    endpoints: ["net.ton.dev"]
  }
})


const verifiableCredential = {
  "@context": [
    "https://www.w3.org/2018/credentials/v1",        
    "https://www.w3.org/2018/credentials/examples/v1"
  ],
  "id": "https://example.com/credentials/1872",      
  "type": [
    "VerifiableCredential",
    "AlumniCredential"
  ],
  "issuer": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
  "issuanceDate": "2010-01-01T19:23:24Z",
  "credentialSubject": {
    "id": "did:everscale:47325e80e3cef5922d3a3583ae5c405ded7bda781cb069f2bc932a6c3d6ec62e",
    "alumniOf": "Example University"
  },
  "proof": {
    "type": "Ed25519Signature2020",
    "created": "2022-05-05T06:48:08.658Z",
    "verificationMethod": "did:everscale:a341b9ab6235a525cb59192c7a1c7637599d01d3e3a8a76a6dc86ed53a0cf260",
    "proofPurpose": "assertionMethod",
    "proofValue": "1dd750eb48f71da5d0ddf1562daa9d815619e9a08f6067a908f654241383ee1aed0e35e85e6fc141c670819d7e445fc105dd387cfcc855f304b48e536242c208"
  }
}

const userAccount = new Account(ClientContract, {
  address: "0:1d1e24b5036dcbd810c76d7fe03697a992de332ff4436a79c563d27e62a61d87",
  signer: signerKeys({
    public: 'a8fea093d3ae5daab36cdc04bcc8685dce354195c5bbb16bebf771d0ef413bd6',
    secret: '7406c4501581667fa2d8b5d6f35b569dbb420cb1bacbdc9f0723e2f5f2d63ff2'
  }),
  client: client
})

var dataVC = await vc.moduleEver.newAddressVC(client)
      
  await userAccount.run("transfer", {
    dest: dataVC.address,
    value: 210000000
  })

  

  await moduleEver.deployVC(dataVC.address, dataVC.keys, client, await userAccount.getAddress(), "JSON", 
    await moduleVC.encryptVerifiableCredential(verifiableCredential, userAccount.signer.keys.secret)).then(console.log)