IDENTITY SDK
This package facilitate the interaction with Identities stored in the BlockChain.
Specifications
Functionality
- Deploy identities
- List and Manage keys on an Identity
- List and manage Claims on an Identity.
- Issue claims for an Identity.
- Fetch claim data using their URI.
- Request access to claim private data using their URI.
- Use access grants to access private data of claims.
Usage
Installation
Install with npm install @investorid/identity-sdk
Then require with:
const IdentitySDK = require('@investorid/identity-sdk');
Tutorials
BlockChain Provider
To interact with the BlockChain, you will need to instantiate a Provider.
The SDK is using Ethers to connect with Ethereum network.
Thus, any provider supported by Ethers can be used with the SDK.
This means any standard web3 provider should by supported.
Connect to a default provider:
IdentitySDK.Config.setProvider('ropsten');
const ropstenProvider = IdentitySDK.Config.getProvider();
IdentitySDK.Config.setProvider('homestead');
const mainProvider = IdentitySDK.Config.getProvider();
Connect to JSON RPC:
let httpProvider = new IdentitySDK.Providers.JsonRpcProvider();
IdentitySDK.Config.setProvider(httpProvider);
Connect to any Web3 Provider:
let currentProvider = new web3.providers.HttpProvider('http://localhost:8545');
let web3Provider = new IdentitySDK.Providers.Web3Provider(currentProvider);
IdentitySDK.Config.setProvider(web3Provider);
Connect to metamask:
let provider = new IdentitySDK.Providers.Web3Provider(web3.currentProvider);
IdentitySDK.Config.setProvider(web3Provider);
Please refer to the Ethers Providers Documentation for more information.
Configuration
Providers
By default, unsecured providers are not allowed. The SDK will refuse to fetch data on these endpoints.
A claim that has an uri which is not an HTTPS endpoint won't be retrieved.
Allow unsecured endpoints with:
const IdentitySDK = require('@investorid/identity-sdk');
IdentitySDK.Config.config({ allowUnsecuredProviders: true });
SignerModule
Many interaction with identities, and especially claims, require to sign a challenge message.
Functions requiring these signatures expect a SignerModule as argument.
A SignerModule must expose a .getPublicKey() and a .signMessage(message: string) functions.
This is, for instance, a valid SignerModule:
const jsrasign = require('jsrasign');
const signer = new SignerModule({
getPublicKey: async () => ({
key: "-----BEGIN CERTIFICATE----- my_super_public_key -----END CERTIFICATE-----",
type: "X.509",
signingMethod: "SHA-256",
}),
signMessage: async (message) => {
const signer = new jsrsasign.Signature({ alg: 'SHA256withRSA' });
signer.init("-----BEGIN CERTIFICATE----- my_super_PRIVATE_no_really_super_secret_PRIVATE_key -----END CERTIFICATE-----");
signer.updateString(message);
return signer.sign();
},
});
As a convenient method, a SignerModule can be created from an ethers Wallet:
const wallet = new IdentitySDK.Providers.Wallet('PRIVATE_KEY', provider);
const signer = new IdentitySDK.SignerModule(wallet);
It can be used in functions such as Claim.requestAccess()
:
claim.requestAccess(IdentitySDK.utils.enums.AccessGrantType.PERSISTENT, signer);
Examples
Find examples in the Example folder.
Load a contract
const IdentitySDK = require('@investorid/identity-sdk');
const provider = new IdentitySDK.Providers.JsonRpcProvider();
(async () => {
const identity = new IdentitySDK.Identity();
console.log(identity.instantiateAtAddress('0xadD92F8Ef0729E969c5a98Ea5740c9b644B362e3', provider));
console.log(await identity.instance.getClaimIdsByType(1));
})();
Get claims of an Identity
const IdentitySDK = require('@investorid/identity-sdk');
const provider = new IdentitySDK.Providers.JsonRpcProvider();
(async () => {
const identity = new IdentitySDK.Identity('0xadD92F8Ef0729E969c5a98Ea5740c9b644B362e3', provider);
const claims = await identity.getClaimsByType(1);
console.log(claims);
})();
Get keys of an Identity
const IdentitySDK = require('@investorid/identity-sdk');
const provider = new IdentitySDK.Providers.JsonRpcProvider();
(async () => {
const identity = new IdentitySDK.Identity('0xadD92F8Ef0729E969c5a98Ea5740c9b644B362e3', provider);
const keys = await identity.getKeysByPurpose(IdentitySDK.utils.enums.KeyPurpose.CLAIM);
console.log(keys);
console.log(await identity.getKeyPurpose(keys[0].key));
})();
Deploy an identity
const IdentitySDK = require('@investorid/identity-sdk');
const provider = new IdentitySDK.Providers.JsonRpcProvider();
const CLAIM_ISSUER_PRIVATE_KEY = 'issuer_private_key';
const claimIssuerWallet = new IdentitySDK.Providers.Wallet(CLAIM_ISSUER_PRIVATE_KEY, provider);
const DEPLOY_PRIVATE_KEY = 'deploy_private_key';
const deployWallet = new IdentitySDK.Providers.Wallet(DEPLOY_PRIVATE_KEY, provider);
(async () => {
const identity = await IdentitySDK.Identity.deployNew(deployWallet);
await identity.addKey(IdentitySDK.utils.crypto.keccak256(claimIssuerWallet.address), IdentitySDK.utils.enums.KeyPurpose.CLAIM, IdentitySDK.utils.enums.KeyType.ECDSA);
identity.useProvider(claimIssuerWallet);
await identity.addClaim(IdentitySDK.utils.enums.ClaimType.KYC, IdentitySDK.utils.enums.ClaimScheme.SOME, claimIssuerWallet.address, "a signature", "what a lot of data", "http://localhost:8080/claims/666");
})();
Get details of a claim
const IdentitySDK = require('@investorid/identity-sdk');
const provider = new IdentitySDK.Providers.JsonRpcProvider();
(async () => {
IdentitySDK.config({ allowUnsecuredProviders: true });
const identity = new IdentitySDK.Identity('0xadD92F8Ef0729E969c5a98Ea5740c9b644B362e3', provider);
const claims = await identity.getClaimsByType(IdentitySDK.utils.enums.ClaimType.KYC);
const claim = new IdentitySDK.Claim(claims[0]);
await claim.populate();
console.log(claim);
})();
Development
Don't forget to npm install
first.
Build with npm run build
.
This will build package into the dist/
folder from the TypeScript sources.
This will also build the TypeDoc website into docs/type_doc
.
Lint with npm run lint