Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Added readme #42

Merged
merged 36 commits into from May 19, 2021
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e28510c
initial commit
mtnieto Jun 8, 2020
9ac2b43
added chaincode to repo
mtnieto Jun 8, 2020
940efe9
Updated readme
mtnieto Jun 8, 2020
b42241a
contributors file
mtnieto Jun 8, 2020
33087d2
Merge remote-tracking branch 'ioc/master'
ryjones Jun 30, 2020
2e3eaaa
Migrated private repo (#13)
adlrocha Jul 2, 2020
bf3718e
Updated Controllers and contributors (#16)
mtnieto Jul 20, 2020
8e11807
Getting started (#18)
mtnieto Jul 23, 2020
bd4cf30
Mongo driver changed (#21)
mtnieto Oct 27, 2020
eeb9b9a
Bump lodash from 4.17.15 to 4.17.20 in /trustid-sdk (#20)
dependabot[bot] Oct 27, 2020
3327a5d
Bump bl from 2.2.0 to 2.2.1 in /trustid-sdk (#19)
dependabot[bot] Oct 27, 2020
337070a
added update service functionalities, upadate docs, logging and error…
mtnieto Jan 15, 2021
914351d
Bump highlight.js from 9.18.1 to 9.18.5 in /trustid-sdk (#22)
dependabot[bot] Jan 15, 2021
cb1b0b9
Bump lodash from 4.17.15 to 4.17.20 in /trustid-sdk (#28)
dependabot[bot] Jan 15, 2021
453b4f4
Bump axios from 0.19.2 to 0.21.1 in /trustid-sdk (#24)
dependabot[bot] Feb 18, 2021
c0245bb
Bump ini from 1.3.5 to 1.3.8 in /trustid-sdk (#23)
dependabot[bot] Mar 18, 2021
77e9e76
Bump elliptic from 6.5.3 to 6.5.4 in /trustid-sdk (#31)
dependabot[bot] Mar 18, 2021
f3528f5
Bump y18n from 3.2.1 to 3.2.2 in /trustid-sdk
dependabot[bot] Mar 31, 2021
d94adc1
Bump y18n from 3.2.1 to 3.2.2 in /trustid-sdk
dependabot[bot] Mar 31, 2021
95e7abe
added recovery functions
mtnieto Apr 15, 2021
20b3039
added recovery functions
mtnieto Apr 15, 2021
7d20fed
added recovery functions (#35)
mtnieto Apr 15, 2021
7599ce6
Deleted Comment
mtnieto Apr 16, 2021
1bf4c32
Deleted Comment
mtnieto Apr 16, 2021
1b4f0ce
Deleted Comment
mtnieto Apr 16, 2021
7b740fa
Deleted Comment
mtnieto Apr 16, 2021
622fc29
deleted comment
mtnieto Apr 16, 2021
ea24997
deleted comment
mtnieto Apr 16, 2021
7301a85
Merge branch 'master' of https://github.com/hyperledger-labs/TrustID
mtnieto Apr 16, 2021
627789d
Merge branch 'master' of https://github.com/hyperledger-labs/TrustID
mtnieto Apr 16, 2021
72cbf7f
Deleted comment (#37)
mtnieto Apr 16, 2021
9dee78b
Merge branch 'master' of https://github.com/hyperledger-labs/TrustID
mtnieto Apr 16, 2021
26cf070
Merge branch 'master' of https://github.com/hyperledger-labs/TrustID
mtnieto Apr 16, 2021
e3ba658
Merge branch 'master' of github.com:telefonicablockchain/TrustID
mtnieto Apr 16, 2021
b37c503
added readme
mtnieto May 19, 2021
5dcdd38
Merge branch 'hyperledger-labs:master' into master
mtnieto May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
173 changes: 173 additions & 0 deletions trustid-sdk/README.md
@@ -0,0 +1,173 @@
# TRUSTID SDK


This SDK exposes all the functionalities required to interact with
TRUSTID-based DLT networks.

### Install
* To install this library you need access to the private repo:
```
$ npm install @hyperledger-labs/trustid-sdk@1.0.0

```

### Getting started

To use the sdk it's necessary to read the [Getting started guide](../README.md)

The SDK to connect with Hyperledger Fabric will need to configure the connection. On one side we need the hyperledger fabric standard [connection profile](./connection-profile.json), on the othe side we will need to complete de following configuration in a JSON object.
```js
{
stateStore: '',
caURL: '',
caName: '',
caAdmin: '',
caPassword: '',
tlsOptions: {
trustedRoots:"",
verify: false
},
mspId: '',
walletID: '',
asLocalhost: ,
ccp: connection profile commented bellow,
chaincodeName: "name of the identity chaincode deployed",
fcn: "proxy",
channel: ""
}

```

### Example of use
You can find a set of examples using the SDK in the [examples](../examples) directory.

```js
// Use library
var id = require('trustid-sdk')
import { TrustIdHf, Keystore, FileKeystore } from 'trustid-sdk';
import {AccessPolicy, PolicyType} from 'trustid-sdk';

// Initialize wallet
wal = id.Wallet.Instance;

// Create Keystore
ks = new FileKeystore();
// Set keystore in wallet
wal.setKeystore(ks)
// LoadKeystore from file
wal.loadKeystore('file', './keystore')
// Set endpoint of driver and store in variable to use it.
let ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
let config = {
stateStore: '/tmp/statestore',
caURL: 'https://ca.org1.telefonica.com:7054',
caName: 'ca.org1.telefonica.com',
caAdmin: 'adminCA',
caPassword: 'adminpw',
tlsOptions: {
trustedRoots:"-----BEGIN CERTIFICATE-----MIICTjCCAfSgAwIBAgIRAPz6Z66RGDs2BDghYGuShw4wCgYIKoZIzj0EAwIwcTELMAkGA1UEBhMCRVMxDzANBgNVBAgTBk1hZHJpZDEPMA0GA1UEBxMGTWFkcmlkMRwwGgYDVQQKExNvcmcxLnRlbGVmb25pY2EuY29tMSIwIAYDVQQDExl0bHNjYS5vcmcxLnRlbGVmb25pY2EuY29tMB4XDTIwMDUxMjEzMDIwMFoXDTMwMDUxMDEzMDIwMFowcTELMAkGA1UEBhMCRVMxDzANBgNVBAgTBk1hZHJpZDEPMA0GA1UEBxMGTWFkcmlkMRwwGgYDVQQKExNvcmcxLnRlbGVmb25pY2EuY29tMSIwIAYDVQQDExl0bHNjYS5vcmcxLnRlbGVmb25pY2EuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaJraPeAMD+qMba9gNfzwhhfSQNDStqhkvGdPKfxjl+5YoZ+AZkf5qXUPCbSVFh2rlIagZQzcxLnxRmwguEDJjaNtMGswDgYDVR0PAQH/BAQDAgGmMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAPBgNVHRMBAf8EBTADAQH/MCkGA1UdDgQiBCDxTrECkDkA2zbsZ7US807jJKKmZ6E90QYkjC7szbQrQDAKBggqhkjOPQQDAgNIADBFAiEAmFFB79r8Jqu4QEgNRQEWEWrY9g70pEUIL4cwq7Zj//UCIDoOuRhihvbFsLTSNbK31VzmL5lXvZGwzvS60n9xk33B-----END CERTIFICATE-----",
verify: false
},
mspId: 'org1MSP',
walletID: 'admin',
asLocalhost: true,
ccp: ccp,
chaincodeName: "identitycc",
fcn: "proxy",
channel: "telefonicachannel"
}

const trustID = new TrustIdHf(config);
wal.addNetwork("hf", trustID);
await wal.networks["hf"].configureDriver();

// Use the wallet and the driver
wal.generateDID("RSA")
await wal.networks["hf"].createIdentity(wal.getDID("default"))
await trustID.getIdentity(wal.getDID("default"), wal.getDID("default").id);

let access: AccessPolicy = {policy: PolicyType.PublicPolicy};

await trustID.createService(wal.getDID("default"), `vtn:trustos:service:1`, "chaincode", access, "mychannel");

```

### Structure
The library has the following modules:


* `wallet.ts`: Core module of the library. It wraps all the state and
logic for identity management and interaction with TrustID networks.
To start using the SDK a new wallet needs to be initialized. A wallet
exposes the following methods:
* `public setKeystore(keystore: Keystore): void`: Sets a type of keystore, supported: In memory, filesystem, mongodb
* `public generateDID(type: string, controller: string, passphrase): DID`: Generates an identity
* `public storeDID(did: DID): Promise<boolean>`: Stores the did in the keystore
* `public updateDID(did: DID): Promise<boolean> `: Updates info from DID
* `public listDID(): string[]`: Returns dids stored in keystore
* `public recoverKeySSS(id: string, secrets: Buffer[], newPassword: string): Promise<void>`: Recovers the key
* `public updatePassword(id: string, oldPassphrase:,passphrase: string=""): Promise<void> `: Updates the password to unlock the did
* `public updateTempKeyDID(id: string, passphrase:,tempPassphrase: string=""): Promise<void>`: Unlocks the account with a temporal key
* `public addNetwork(id: string, network: TrustID): void`: Adds a new network to interact to.


* `class DID`: Has the following structure.
* `public id: string`: Id string that identifies the DID.
* `public pubkey: string`: PublicKey of the DID.
* `public type: string`: Key type (RSA / EC / OKP).
* `public controller: string`: Verifier of the identity
* `public access: number`: Access level. This is the access level to be checked in the service AccessPolicy threshold.
* `private privkey: string`: Private Key of the DID.

And exposes the following functions:
* `public unlockAccount(passphrase: string = ""): void`: Unlocks private key in order to use the DID.
* `public lockAccount(): any`: Locks the private key for a DID.
* `public sign(payload: object, passphrase: string = ""): string`: Sign a payload with a specific DID.
* `public verify(signature: string, id: string = "default"): any`: Verifies a signature from a DID.

* `TrustID.ts`: Interface that enables the inteoperation between the drivers and the different functionalities of TrustID. The only component implemented currently is the `trustIDhf.ts` enabling the interaction with Hyperledger Fabric TrustID
networks.

* `configureDriver(endpoint: string): void`: Sets the network endpoint to interact with the TrustID network.
* `disconnectDriver(endpoint: string): void`: Disconects the network endpoint to interact with the TrustID network.
* `createIdentity(did: DID): Promise<object>`: Create an identity in TrustID. It generates a new DID in the wallet and register it in the network.
* `importIdentity(did: DID, controller?: DID)`: Imports an existing identity to the chaincode
* `verifyIdentity(adminDID: DID, id:string): Promise<object>`: Verifies an identity as an admin.
* `getIdentity(did: DID, id: string): * Promise<object>`: Gets a registered identity from TrustID.
* `revokeIdentity(adminDID: DID, id: string): Promise<object>`: Revokes a registered identity. Only supported by the owner or controller of the DID.
* `createService(did: DID, serviceDID: string, name: string, isPublic: boolean): Promise<object>`: Creates a new service in the TrustID network.
* `updateService(did: DID, serviceDID: string, access: Access, isPublic: boolean): Promise<object>`: Updates the information from a service.
* `updateServiceAccess(did: DID, serviceDID: string, access: AccessPolicy): Promise<object>`: Updates the access from a service.
* `getService(did: DID, serviceDID: string): Promise<object>`: Gets information from a registered service.
* `invoke (did: DID, serviceDID: string, args: string[], channel: string): Promise<object>`: Invokes a function of a registered service in the TrustID network.
* `query(did: DID, serviceDID: string, args: string[], channel: string): Promise<object>`: Queries a function of a registered service in the TrustID network

* `PolicyType (policy: PolicyType, threshold:?Number, registry:?object)`: It
defined the policyType to be used for a service. There are currently three
types of policyTypes supported (more could be easily added according to
your needs)
* PublicPolicy: Grants public access by any user to your service.
* SameControllerPolicy: Only verified identities whose controller is the
same controller who created the service has access to the service (this
policy comes pretty handy when you want to define "corporate-wide" services).
* FineGrainedPolicy: Grants fine-grained access to users to your service.
In this policy you explicitly define the access of users to the service.
There are two ways of using this policyType, you can define a threshold
so every user with an access level equal or higher than the threshold
is granted access to the service; or you could use fine-grained
access levels defined in the registry, where you would add the following
tuple: `{<did>, <access_role>}`. Thus, only users in the registry
with an access level over the threshold will be granted access to the
service with `access_role` permissions.



* `keystore.ts`: Interface that enables the implementation of keystore storages.
There are currently two implementations of keystore supported: `FileKeystore.ts` (to store DIDs in file keystore)and `MongoKeystore.ts` (to store DIDs in MongoDB).

* `abstract getDID(id: string): DID`: Get specific DID from keystore.
* `abstract storeDID(did: DID): boolean`: Store DID in keystore.
* `public storeInMemory(did: DID): boolean`: Store DID inMemory for easy and performant use.
* `public listDID(): string[]`: List DIDs in memory.
* `public setDefault(did: DID): boolean`: Set DID as default identity for the keystore wallet.