0.35.1 • Published 15 days ago

@kiltprotocol/vc-export v0.35.1

Weekly downloads
123
License
BSD-4-Clause
Repository
-
Last release
15 days ago

npm.io

Lint and Test

Data sovereignty and interoperability

Verifiable Credentials Compatibility Package

This package helps you to translate KILT credentials to the popular Verifiable Credential format and structure. It provides you with tools to export your existing KILT credentials to the widely understood Verifiable Credential, produce Verifiable Presentations from a Verifiable Credential, and to verify the associated proofs.

Contents

  • exporting
    • fromAttestedClaim(): translates AttestedClaim to VerifiableCredential
  • presentation utils
    • makePresentation(): creates VerifiablePresentation ()
    • removeProperties(): derives a new VerifiableCredential from an existing one with a reduced set of disclosed attributes
  • verification utils
    • functions that verify three proof types:
      • claimer's self-signed proof over the credential digest
      • credential digest proof that assures the integrity of disclosed attributes, claimer identity, legitimations and delegations
      • attestation proof that assures the credential is attested by the identity disclosed as the issuer and not revoked
    • a function to validate the disclosed claim properties against the schema of a KILT CType, which is a prescriptive schema detailing fields and their data types.
  • vc-js suites: tooling to integrate KILT VCs with vc-js and jsonld-signatures^5.0.0
    • suites: contains suites to verify the three KILT proof types that secure a KILT VC.
      • KiltIntegritySuite: provides integrity protection for essential components of the credential while allowing for blinding of claims relating to the credentialSubject.
      • KiltSignatureSuite: verifies the signature over the root hash of a KILT credential.
      • KiltAttestedSuite: provides lookup functionality to the KILT blockchain to check whether a credential is attested and still valid.
    • context: contains a json-ld @context definitions for KILT VCs.
    • documentLoader: an implementation of the DocumentLoader required to use vc-js / jsonld-signatures which allows to serve essential @context definitions to the json-ld processor, including the context included here.

Examples

Presenting a KILT AttestedClaim as a VerifiableCredential

Given we are in possession of an attested KILT claim and the associated KILT identity:

import Kilt from '@kiltprotocol/sdk-js'
import type { AttestedClaim, Identity } from '@kiltprotocol/sdk-js'
import VCUtils from '@kiltprotocol/vc-export'

let credential: AttestedClaim
let identity: Identity

// turn the KILT credential into a VerifiableCredential
const VC = VCUtils.fromAttestedClaim(credential)

// produce a reduced copy of the VC where only selected attributes are disclosed
const nameOnly = await VCUtils.presentation.removeProperties(VC, ['name'])
// or directly produce a VerifiablePresentation, which implicitly performs the step above
const presentation = await VCUtils.presentation.makePresentation(VC, ['name'])

A verifier can now check the proofs attached to the VerifiableCredential but can only see the disclosed attributes:

// Here's an example for verifying the attestation proof
let result
presentation.verifiableCredential.proof.foreach((proof) => {
  if (proof.type === VCUtils.types.KILT_ATTESTED_PROOF_TYPE)
    VCUtils.verification.verifyAttestedProof(proof)
})

if (result && result.verified) {
  console.log(
    `Name of the crook: ${presentation.verifiableCredential.credentialSubject.name}`
  ) // prints 'Billy The Kid'
  console.log(
    `Reward: ${presentation.verifiableCredential.credentialSubject.reward}`
  ) // undefined
}

Verifying a KILT VC with vc-js

Assuming we have a KILT credential expressed as a VC (credential), for example as produced by the example above.

import kilt from '@kiltprotocol/sdk-js'
import { vcjsSuites } from '@kiltprotocol/vc-export'
import vcjs from 'vc-js'
import jsigs from 'jsonld-signatures'

// 1. set up suites
const {
  KiltIntegritySuite,
  KiltSignatureSuite,
  KiltAttestedSuite,
} = vcjsSuites.suites
const signatureSuite = new KiltSignatureSuite()
const integritySuite = new KiltIntegritySuite()
// the KiltAttestedSuite requires a connection object that allows access to the KILT blockchain, which we can obtain via the KILT sdk
await kilt.init({ address: 'wss://full-nodes.kilt.io:443' })
const KiltConnection = await kilt.connect()
const attestedSuite = new KiltAttestedSuite({ KiltConnection })

// 2. verify credential schema
const schemaVerified = verificationUtils.validateSchema(credential).verified
// unfortunately the VC credentialSchema definition is underspecified in their context - we therefore have to remove it before credential verification
delete credential['credentialSchema']

// 3. obtain default kilt context loader
const { documentLoader } = vcjsSuites

// 4. obtain the `assertionMethod` proof purpose from `jsonld-signatures`
const purpose = new jsigs.purposes.AssertionProofPurpose()

// 5. call vc-js.verifyCredential with suites and context loader
const result = await vcjs.verifyCredential({
  credential,
  suite: [signatureSuite, integritySuite, attestedSuite],
  purpose,
  documentLoader,
})

// 6. make sure all `results` indicate successful verification
const verified = result.results.every((i) => i.verified === true)
0.35.1

15 days ago

0.35.1-rc.2

17 days ago

0.35.1-rc.1

18 days ago

0.35.0

3 months ago

0.35.0-rc.2

3 months ago

0.34.1-rc.1

5 months ago

0.35.0-rc.1

5 months ago

0.33.2-4

10 months ago

0.33.2-3

10 months ago

0.33.2-6

10 months ago

0.33.2-5

10 months ago

0.33.2-dip-1

7 months ago

0.33.2-dip-2

7 months ago

0.34.0-dip-1

6 months ago

0.34.0-dip-2

6 months ago

0.34.0-rc.0

10 months ago

0.34.0

9 months ago

0.34.0-rc.1

9 months ago

0.32.1

12 months ago

0.33.1-rc.1

11 months ago

0.33.0-rc.3

12 months ago

0.33.0-rc.2

12 months ago

0.33.0-rc.1

12 months ago

0.33.2-0

11 months ago

0.33.2-2

11 months ago

0.33.2-1

11 months ago

0.33.1

11 months ago

0.33.0

11 months ago

0.33.2-dip-0

11 months ago

0.32.1-rc.1

12 months ago

0.33.1-4

11 months ago

0.33.1-1

11 months ago

0.33.1-0

11 months ago

0.33.1-3

11 months ago

0.33.1-2

11 months ago

0.32.1-decoded-2

11 months ago

0.32.1-decoded-3

11 months ago

0.32.1-decoded-1

11 months ago

0.32.1-11

12 months ago

0.32.1-10

12 months ago

0.32.1-8

12 months ago

0.32.1-7

12 months ago

0.32.1-6

12 months ago

0.32.1-5

1 year ago

0.32.1-9

12 months ago

0.32.1-4

1 year ago

0.32.0

1 year ago

0.31.1

1 year ago

0.32.0-rc.2

1 year ago

0.32.0-rc.3

1 year ago

0.32.1-0

1 year ago

0.32.1-3

1 year ago

0.32.1-2

1 year ago

0.32.1-1

1 year ago

0.32.0-11

1 year ago

0.32.0-10

1 year ago

0.32.0-9

1 year ago

0.32.0-8

1 year ago

0.32.0-7

1 year ago

0.30.1-11

1 year ago

0.30.1-10

1 year ago

0.30.1-13

1 year ago

0.30.1-12

1 year ago

0.30.1-9

1 year ago

0.31.0-rc.1

1 year ago

0.31.0-rc.2

1 year ago

0.31.0

1 year ago

0.31.1-0

1 year ago

0.31.1-rc.1

1 year ago

0.32.0-6

1 year ago

0.32.0-5

1 year ago

0.32.0-4

1 year ago

0.32.0-3

1 year ago

0.32.0-2

1 year ago

0.30.0-43

2 years ago

0.30.0-48

1 year ago

0.30.0-47

2 years ago

0.30.0-46

2 years ago

0.30.0-45

2 years ago

0.30.0-44

2 years ago

0.30.1-6

1 year ago

0.30.1-5

1 year ago

0.30.1-4

1 year ago

0.30.1-3

1 year ago

0.30.1-2

1 year ago

0.30.1-1

1 year ago

0.30.1-0

1 year ago

0.30.0

1 year ago

0.30.1-8

1 year ago

0.30.1-7

1 year ago

0.30.0-rc.1

2 years ago

0.30.0-32

2 years ago

0.30.0-31

2 years ago

0.30.0-30

2 years ago

0.30.0-39

2 years ago

0.30.0-38

2 years ago

0.30.0-37

2 years ago

0.30.0-36

2 years ago

0.30.0-35

2 years ago

0.30.0-34

2 years ago

0.30.0-33

2 years ago

0.30.0-42

2 years ago

0.30.0-41

2 years ago

0.30.0-40

2 years ago

0.29.0

2 years ago

0.30.0-29

2 years ago

0.30.0-28

2 years ago

0.30.0-27

2 years ago

0.30.0-26

2 years ago

0.30.0-25

2 years ago

0.30.0-24

2 years ago

0.30.0-23

2 years ago

0.30.0-22

2 years ago

0.28.3

2 years ago

0.29.0-rc.3

2 years ago

0.29.0-rc.4

2 years ago

0.28.3-rc.1

2 years ago

0.30.0-10

2 years ago

0.30.0-19

2 years ago

0.30.0-18

2 years ago

0.30.0-17

2 years ago

0.30.0-16

2 years ago

0.30.0-15

2 years ago

0.30.0-14

2 years ago

0.30.0-13

2 years ago

0.30.0-12

2 years ago

0.30.0-11

2 years ago

0.30.0-21

2 years ago

0.30.0-20

2 years ago

0.30.0-7

2 years ago

0.30.0-6

2 years ago

0.30.0-5

2 years ago

0.30.0-4

2 years ago

0.30.0-3

2 years ago

0.30.0-2

2 years ago

0.30.0-1

2 years ago

0.30.0-9

2 years ago

0.30.0-8

2 years ago

0.28.2

2 years ago

0.29.0-rc.1

2 years ago

0.29.0-rc.2

2 years ago

0.29.0-48

2 years ago

0.29.0-49

2 years ago

0.29.0-46

2 years ago

0.29.0-47

2 years ago

0.29.0-40

2 years ago

0.29.0-41

2 years ago

0.29.0-44

2 years ago

0.29.0-45

2 years ago

0.29.0-42

2 years ago

0.29.0-43

2 years ago

0.29.0-51

2 years ago

0.29.0-52

2 years ago

0.29.0-50

2 years ago

0.29.0-55

2 years ago

0.29.0-56

2 years ago

0.29.0-53

2 years ago

0.29.0-54

2 years ago

0.29.0-37

2 years ago

0.29.0-38

2 years ago

0.29.0-35

2 years ago

0.29.0-36

2 years ago

0.29.0-39

2 years ago

0.29.0-33

2 years ago

0.29.0-34

2 years ago

0.29.0-31

2 years ago

0.29.0-32

2 years ago

0.28.0-14

2 years ago

0.28.0-13

2 years ago

0.28.0-12

2 years ago

0.29.0-26

2 years ago

0.29.0-27

2 years ago

0.29.0-24

2 years ago

0.29.0-25

2 years ago

0.29.0-28

2 years ago

0.29.0-29

2 years ago

0.29.0-22

2 years ago

0.29.0-23

2 years ago

0.29.0-20

2 years ago

0.29.0-21

2 years ago

0.29.0-30

2 years ago

0.28.1-rc.1

2 years ago

0.29.0-15

2 years ago

0.29.0-16

2 years ago

0.29.0-13

2 years ago

0.29.0-14

2 years ago

0.29.0-19

2 years ago

0.29.0-17

2 years ago

0.29.0-18

2 years ago

0.29.0-11

2 years ago

0.29.0-12

2 years ago

0.29.0-10

2 years ago

0.28.0-rc.2

2 years ago

0.28.0-rc.1

2 years ago

0.29.0-7

2 years ago

0.29.0-6

2 years ago

0.29.0-9

2 years ago

0.29.0-8

2 years ago

0.28.1

2 years ago

0.29.0-3

2 years ago

0.28.0

2 years ago

0.29.0-2

2 years ago

0.29.0-5

2 years ago

0.29.0-4

2 years ago

0.29.0-1

2 years ago

0.28.0-6

2 years ago

0.28.0-5

2 years ago

0.28.0-10

2 years ago

0.28.0-9

2 years ago

0.28.0-8

2 years ago

0.28.0-7

2 years ago

0.26.1-beta.1

2 years ago

0.28.0-2

2 years ago

0.28.0-1

2 years ago

0.28.0-4

2 years ago

0.28.0-3

2 years ago

0.26.1

2 years ago

0.27.0-beta.1

2 years ago

0.27.0-beta.3

2 years ago

0.27.0-beta.2

2 years ago

0.27.0

2 years ago

0.27.0-3

2 years ago

0.27.0-5

2 years ago

0.27.0-4

2 years ago

0.27.0-6

2 years ago

0.26.0

2 years ago

0.26.0-14

2 years ago

0.26.0-beta.2

2 years ago

0.26.0-beta.1

2 years ago

0.26.0-beta.3

2 years ago

0.26.0-rc.3

2 years ago

0.27.0-1

2 years ago

0.27.0-2

2 years ago

0.26.0-rc.4

2 years ago

0.25.3

2 years ago

0.25.2

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.25.0-7

2 years ago

0.25.0-4

2 years ago

0.25.0-5

2 years ago

0.25.5

2 years ago

0.25.0-3

2 years ago

0.26.0-11

2 years ago

0.26.0-10

2 years ago

0.26.0-13

2 years ago

0.26.0-12

2 years ago

0.26.0-1

2 years ago

0.26.0-2

2 years ago

0.26.0-3

2 years ago

0.26.0-4

2 years ago

0.26.0-5

2 years ago

0.26.0-6

2 years ago

0.26.0-7

2 years ago

0.26.0-8

2 years ago

0.26.0-9

2 years ago

0.26.0-rc.1

2 years ago

0.26.0-rc.2

2 years ago

0.24.0-21

2 years ago

0.24.0-22

2 years ago

0.24.0-20

2 years ago

0.24.0-14

3 years ago

0.24.0-15

3 years ago

0.24.0-13

3 years ago

0.24.0-18

3 years ago

0.25.0-1

2 years ago

0.24.0-19

2 years ago

0.24.0-16

3 years ago

0.24.0-17

3 years ago

0.25.0-2

2 years ago

0.24.0-beta.3

3 years ago

0.24.2

2 years ago

0.24.1

2 years ago

0.24.0

2 years ago

0.24.0-7

3 years ago

0.24.0-8

3 years ago

0.24.0-9

3 years ago

0.24.0-10

3 years ago

0.24.0-11

3 years ago

0.24.0-12

3 years ago

0.24.0-beta.1

3 years ago

0.24.0-beta.2

3 years ago

0.24.0-6

3 years ago

0.24.0-4

3 years ago

0.24.0-5

3 years ago

0.22.2-rc.4

3 years ago

0.22.2-rc.3

3 years ago

0.23.0-beta.3

3 years ago

0.23.0-beta.5

3 years ago

0.24.0-3

3 years ago

0.24.0-alpha.3

3 years ago

0.24.0-alpha.2

3 years ago

0.24.0-2

3 years ago

0.24.1-rc.1

3 years ago

0.24.0-1

3 years ago

0.22.2-2

3 years ago

0.22.2-1

3 years ago

0.22.2-0

3 years ago

0.22.1

3 years ago

0.22.1-1

3 years ago

0.22.1-0

3 years ago

0.22.0

3 years ago

0.23.0-beta.2

3 years ago

0.23.0-beta.1

3 years ago

0.21.1-9

3 years ago

0.21.1-7

3 years ago

0.21.1-8

3 years ago

0.21.1-6

3 years ago

0.21.1-10

3 years ago

0.21.1-11

3 years ago

0.21.1-12

3 years ago

0.21.1-13

3 years ago

0.22.0-rc.1

3 years ago

0.21.0

3 years ago

0.22.0-alpha.1

3 years ago

0.21.1-5

3 years ago

0.21.1-3

3 years ago

0.21.1-4

3 years ago

0.21.1-0

3 years ago

0.21.0-rc.9

3 years ago

0.21.0-rc.7

3 years ago

0.21.0-rc.8

3 years ago

0.20.1-2

3 years ago

0.21.0-rc.5

3 years ago

0.21.0-rc.3

3 years ago

0.21.0-rc.4

3 years ago

0.21.0-rc.1

3 years ago

0.21.0-rc.2

3 years ago

0.20.0

3 years ago

0.19.1-38

3 years ago

0.19.1-39

3 years ago

0.19.1-40

3 years ago

0.20.0-rc.4

3 years ago

0.20.1-0

3 years ago

0.20.0-rc.2

3 years ago

0.20.0-rc.1

3 years ago

0.19.1-37

3 years ago

0.19.1-34

3 years ago

0.19.1-35

3 years ago

0.19.1-36

3 years ago

0.19.1-31

3 years ago

0.19.1-32

3 years ago

0.19.1-33

3 years ago

0.19.1-30

3 years ago

0.19.1-29

3 years ago

0.19.1-28

3 years ago

0.19.1-27

3 years ago

0.19.1-26

3 years ago

0.19.1-25

3 years ago

0.19.1-24

3 years ago

0.19.1-23

3 years ago

0.19.1-22

3 years ago

0.19.1-20

3 years ago

0.19.1-21

3 years ago

0.19.1-19

3 years ago

0.19.1-17

3 years ago