@sbc/seraph-id-sdk
v2.0.1
Published
Seraph ID SDK
Downloads
8
Maintainers
Readme
Overview
This is the JavaScript SDK for Seraph ID - self-severeign identity solution on NEO blockchain platform. This project aims to be a lightweight and simple helper to use Seraph ID wallets, claims issuance and verification in the browser.
Visit the Seraph ID official web page to learn more about self-sovereign identity!
Getting started
Installation
Node.js
npm i @sbc/seraph-id-sdk --save
Usage
Node.js
var seraphId = require('@sbc/seraph-id-sdk');
Seraph ID Owner
Create a new wallet:
var wallet = new seraphId.SeraphIDWallet({ name: 'MyWallet' });
Generate a new DID (here for private network):
var myDID = wallet.createDID(DIDNetwork.PrivateNet); // e.g. did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs
Add a claim issued by Seraph ID issuer:
wallet.addClaim(claim);
Encrypt and export wallet:
wallet.encryptAll('password');
var exportedWalletJson = wallet.export();
Import wallet, decrypt it and get all claims of a specified DID or a claim by ID:
var wallet = new seraphId.SeraphIDWallet(exportedWalletJson);
wallet.decryptAll('password');
var allClaims = wallet.getAllClaims('did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs');
var claim = wallet.getClaim('claimId');
Seraph ID Issuer
Create issuer instance:
var issuer = new seraphId.SeraphIDIssuer('issuerSmartContractScriptHash', 'http://localhost:10332', 'http://localhost:4000/api/main_net', DIDNetwork.PrivateNet);
Create a new (revokable) credentials schema:
issuer.registerNewSchema('schemaName', ['firstName', 'lastName', 'age'], true);
Create and issue a claim:
var claim = issuer.createClaim('claimId', 'schemaName', {'firstName': 'John', 'lastName': 'Doe', 'age': 26}, 'did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs');
issuer.issueClaim(claim, 'issuerPrivateKey');
Revoke previously issued claim (if schema allows revocation):
issuer.revokeClaimById('claimId');
Seraph ID Verifier
Create verifier instance:
var verifier = new seraphId.SeraphIDVerifier('issuerSmartContractScriptHash', 'http://localhost:10332', 'http://localhost:4000/api/main_net', DIDNetwork.PrivateNet);
Get meta-data of issuer's credentials schema:
var schema = verifier.getSchemaDetails('schemaName');
Verify the given owner's claim offline (having issuer's public key):
var verfied = verifier.verifyOffline(claim, 'issuerPublicKey');
Verify the given owner's claim online (calling issuer's smart contract):
var verfied = verifier.verify(claim);
Validate the given owner's claim. Validation includes online verification, claim revocation and validity dates check. Optionally custom validation function can be passed.
var valid = verifier.validateClaim(claim, function customClaimValidator(clm) {
return clm.attributes.age > 18;
});
Check if issuer of owner's claim is trusted by the given Root of Trust:
var trusted = verifier.isIssuerTrusted('scriptHashOfRoTSmartContract', claim.issuerDID, claim.schema);
Seraph ID Root of Trust
Create Root of Trust instance:
var rot = new seraphId.SeraphIDRootOfTrust('rotSmartContractScriptHash', 'http://localhost:10332', 'http://localhost:4000/api/main_net', DIDNetwork.PrivateNet);
Register issuer's DID and schema as trusted:
rot.registerIssuer('did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs', 'SchemaName', 'rootOfTrustPrivateKey');
Remove trust for issuer's DID and schema from RoT:
rot.deactivateIssuer('did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs', 'SchemaName', 'rootOfTrustPrivateKey');
Check if issuer is trusted with the given schema:
var trusted = rot.isTrusted('did:neoid:priv:AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs', 'SchemaName');
Contributing
Setup
This repository is a typescript repository using Yarn. Please ensure the following is installed:
- Yarn (v 1.16.0 or higher)
- Node (latest LTS)
git clone https://github.com/swisscom-blockchain/seraph-id-sdk.git
cd seraph-id-sdk
yarn
yarn build
Testing
Before executing unit tests, please make sure to have:
- Issuer's smart contract deployed on your network.
- Network information and test data maintained properly in
__tests__/test-data.json
file.
yarn test
References
- Seraph ID official page: https://seraphid.io
- Seraph ID demo application on GitHub
- Seraph ID smart contract templates and examples on GitHub
License
- Open-source MIT.