npm run dev
(this enables hot reload when SDK files change)npm run build
without hot reload.Note: the tests/ folder contains its own package.json and node_modules, and depends on the "external library" @elastosfoundation/did-js-sdk.
npm link ..
(every time after calling npm install
or npm update
) from the tests/ folder. This command uses the local version of the DID SDK, that is just in the folder above tests.Start the simulated DID chain once:
npm run simchain
Several independant options:
Or:
npm run test:node
Or:
We are still optimizing tests migrated from the Java implementation. Running all tests on an up-to-date CPU can take several hours. The main source of this problem has been located in the BigNumber operations of the Elliptic library and the key operations of the hdkey-secp256r1 library. Since there shouldn't be huge impacts on the runtime code, the selected solution has been to develop an automated CI to automatically run tests remotely. Here are some metrics and graphics to show latency sources:
Profiling metrics showing 'mul' method latency
Latency from deriveChild hdkey-secp256r1
Call hierarchy:
Latency from jmulAdd of Elliptic
Call hierarchy:
A DIDAdapter is required to publish transactions to the DID chain. Different environments require different adapters such as:
Using the Elastos Essentials Connector that provides a DID Adapter over Wallet connect (to let the wallet app sign transactions):
Pseudo code:
let didAdapter = new EssentialsConnector.DIDAdapter();
DIDBackend.initialize(didAdapter);
// In the connectivity SDK
class EssentialsConnector.DIDAdapter {
createdIdTransaction(payload) {
let web3provider = new WalletConnectWeb3Provider();
ler web3 = new Web3(web3provider);
web3.methods.publishDID(payload);
}
}
DID SDK tests use a custom adapter with a hardcoded wallet to automate transactions signing and publishing:
class LocalDIDAdapter {
createdIdTransaction() {
let acc = {...privatekey-walletwithtestnetfundsinside...};
acc.sign();
publishUsingLocalWeb3Instance();
}
}
let didAdapter = new DIDSDK.Tests.LocalDIDAdapter();
DIDBackend.initialize(didAdapter);
```
#### Custom way:
class MyDIDAdapter extends DID.DefaultDIDAdapter { createdIdTransaction(payload) { // DO custom RPC call } }
let didAdapter = new MyDIDAdapter(); DIDBackend.initialize(didAdapter);
## How to publish to npmjs.com
### Publishing account (NPM)
- Be a member of organization: @elastosfoundation
### Useful commands
- `npm adduser` (once)
- `npm login` (once)
- Increase version number in package.json
- `npm publish --access=public`
Generated using TypeDoc