npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chenyufei2022/did-js-sdk

v2.2.2

Published

Elastos DID Typescript SDK

Downloads

60

Readme

Elastos DID Typescript SDK

SDK development workflow

  • From the SDK folder: npm run dev (this enables hot reload when SDK files change)
  • Or npm run build without hot reload.

Writing tests

Note: the tests/ folder contains its own package.json and node_modules, and depends on the "external library" @elastosfoundation/did-js-sdk.

  • Open the tests/ folder as root in a different instance of vscode, this is the only way for now to let vscode display typescript types and issues correctly.
  • 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.
  • Run one or several tests using one of the options below.

Running tests

Start the simulated DID chain once:

  • From the tests/ folder:
  • npm run simchain

Several independant options:

  • In vscode, Menu -> Run -> Start debugging

Or:

  • From the command line (SDK or tests/ folders):
  • npm run test:node

Or:

  • Using jest runner:
  • Click run or debug directly from the code, above test descriptions.

Performance issue

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

Metrics Source profile data

Latency from deriveChild hdkey-secp256r1

Metrics

Call hierarchy:

  • TestData.getUser1Document
  • TestData.generateKeyPair
  • HDKey.deriveWithPath - derive(hdkey-secp256r1)
    • deriveChild(hdkey-secp256r1)

Latency from jmulAdd of Elliptic

Metrics

Call hierarchy:

  • DIDDocument.isValid
  • DIDDocument.isGenuine
  • DIDDocument.verifyDigest - EcdsaSigner.verify
    • verify(Elliptic)
    • jmulAdd(Elliptic)
    • _wnafMulAdd(Elliptic)

The DID Adapter

A DIDAdapter is required to publish transactions to the DID chain. Different environments require different adapters such as:

From the browser

Easy way, for mobile or web app developers

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);
    }
}

Tests:

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`