Skip to content

An sm2-sd-2023 Data Integrity cryptosuite for use with jsonld-signatures.

License

Notifications You must be signed in to change notification settings

Instun/sm2-sd-2023-cryptosuite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An SM2 Selective Disclosure Data Integrity Cryptosuite (@instun/sm2-sd-2023-cryptosuite)

A selective disclosure Data Integrity cryptosuite based on SM2 for use with jsonld-signatures.

Install

npm install @instun/sm2-sd-2023-cryptosuite

Basic Usage

Creating a base proof

import * as Sm2Multikey from '@instun/sm2-multikey';
import * as sm2Sd2023Cryptosuite from '@instun/sm2-sd-2023-cryptosuite';
import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
import jsigs from 'jsonld-signatures';

// Setup key pair
const publicKeyMultibase = 'zEPJcCQ4kKGebz5ombkjw9mgikPckWeYDLhvZBzPckNsfjBa4';
const secretKeyMultibase = 'z4G1CtDVyCTyctEtfS6WD768wvhPWeN6zyMhJURHmWQwB3K4';
const controller = `did:key:${publicKeyMultibase}`;
const keyPair = await Sm2Multikey.from({
  type: 'Multikey',
  controller,
  id: `${controller}#${publicKeyMultibase}`,
  publicKeyMultibase,
  secretKeyMultibase
});

// Create and sign credential
const credential = {
  '@context': [
    'https://www.w3.org/2018/credentials/v1',
    'https://w3id.org/security/data-integrity/v2'
  ],
  type: ['VerifiableCredential'],
  issuer: controller,
  issuanceDate: '2024-01-01T19:23:24Z',
  credentialSubject: {
    id: 'urn:example:123',
    name: 'John Doe'
  }
};

const suite = new DataIntegrityProof({
  signer: keyPair.signer(),
  cryptosuite: sm2Sd2023Cryptosuite.createSignCryptosuite()
});

const signedCredential = await jsigs.sign(credential, {
  suite,
  purpose: new jsigs.purposes.AssertionProofPurpose(),
  documentLoader
});

Creating a derived proof

const suite = new DataIntegrityProof({
  cryptosuite: sm2Sd2023Cryptosuite.createDiscloseCryptosuite({
    selectivePointers: ['/credentialSubject/id']
  })
});

const derivedCredential = await jsigs.derive(signedCredential, {
  suite,
  purpose: new jsigs.purposes.AssertionProofPurpose(),
  documentLoader
});

Verifying a proof

const suite = new DataIntegrityProof({
  cryptosuite: sm2Sd2023Cryptosuite.createVerifyCryptosuite()
});

const result = await jsigs.verify(derivedCredential, {
  suite,
  purpose: new jsigs.purposes.AssertionProofPurpose(),
  documentLoader
});

Advanced Features

  • Mandatory field disclosure
  • Selective disclosure of multiple fields
  • Custom document loaders
  • Different proof purposes

For detailed examples of advanced usage, see our documentation.

Commercial Support

Commercial support available from Instun: [email protected]

License

Copyright (c) 2024 Instun, Inc. All rights reserved.

About

An sm2-sd-2023 Data Integrity cryptosuite for use with jsonld-signatures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published