dhid
v0.6.4
Published
w3c did and vc sdk for dehub
Downloads
5
Maintainers
Readme
Dhid-SDK
W3C DID and VC SDK for dehub project. At the same time, the DID in this project is compatible with the Ethereum account system.
Features
- W3C DID and VC (included VP) creation and verification
- DID to DID safe message channel
- VC-based ZKP creation and verification
Installing 🚀
NodeJS
/home/name/some_project> npm i dhidGetting started 🚗
creat did, vc and make zk proof
import { keys, Keyring, generateMnemonicFromSeed, VerifiableCredentialBuilder} from 'dhid';
// DID
const mnemonic = generateMnemonicFromSeed('any type of string');
const kering = new Keyring();
const did = keys.fromMnemonic(kering, mnemonic);
// VC
const vcBuilder = VerifiableCredentialBuilder.fromRawCredential(rawCredential,ctype)
.setExpirationDate(null)
.setIssuanceDate(Date.now());
const vc: VerifiableCredential<false> = await vcBuilder.build(attester,false);
// ZKP
const constraints: ProgramConstraints[] = [
{
fields: [4],
operation: ["gte"],
value: 18,
},
];
const program = unstable_generateProgram(7, constraints);
const programHash = generateProgramHash(program);
const secretInput = toMidenInput(credential, [4]);
const zkpResult = executeZkProgram(program, "", secretInput);Test example 🔬
Test structre is developed based on jest. This is some test examples you can run.
yarn test src/protocol/did/did/did.spec.ts
yarn test src/protocol/vc/credential/index.spec.ts
yarn test src/utility/mnemonic/mnemonic.spec.ts