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

connect-did-sdk

v0.1.15

Published

A Connect DID Authorization Center SDK that allows any hardware device to become a DID identity authentication device, providing a secure and convenient method for identity verification.

Downloads

244

Readme

NPM npm

Table of Contents

Getting Started

First, you need to install connect-did-sdk using npm

npm install connect-did-sdk --save

or yarn.

yarn add connect-did-sdk

Then, you need to import Connect-DID SDK in your code and create an instance before interacting with it:

// For CommonJS
const { ConnectDID } = require('connect-did-sdk');
const connectDID = new ConnectDID();
// For ES Module
import { ConnectDID } from 'connect-did-sdk'
const connectDID = new ConnectDID()

Now you could perform various operations using Connect-DID SDK.

CHANGELOG

TBD

API Documentation

Table of Contents

constructor(isTestNet?: boolean, isDebug?: boolean)

Create an instance of ConectDID SDK.

Parameter
  • isTestNet: network type. default false.
    • false: Main Net
    • true: Test Net.
  • isDebug: debug mode. default false.
Return Value

ConnectDID instance

Example
const connectDID = new ConnectDID();

requestNewDeviceData()

Popup to open a new device credential.

Parameter

N/A

Return Value

Device Data

interface IData<IDeviceData> {
    code: number;
    message: string;
    data: IDeviceData;
}

interface IDeviceData {
  name: string;
  credential: ICredential;
  publicKey: IPublicKey;
  ckbAddr: string;
}
Example
const deviceData = await connectDID.requestNewDeviceData();

requestDeviceData()

Popup to open a connection window for the current device.

Parameter

N/A

Return Value

Device Data

interface IData<IDeviceData> {
    code: number;
    message: string;
    data: IDeviceData;
}

interface IDeviceData {
  name: string;
  credential: ICredential;
  publicKey: IPublicKey;
  ckbAddr: string;
}
Example
const deviceData = await connectDID.requestDeviceData();

requestSignData(data: {msg: string})

Popup to open a window for signing a specified string data using the current hardware device authenticator.

Parameter
  • data:
    • msg: String to be signed.
Return Value

Signed hexadecimal string.

interface IData<string> {
    code: number;
    message: string;
    data: string;
}
Example
const signData = await connectDID.requestSignData({
  msg: "From .bit: e7343fdebaa9ec5aca009af3acb9c0664c94066f136f4d31b7b325dacf24f77c",
});

requestDeviceSignData(data: {msg: string})

Popup to open a window for signing a specified string data using the current hardware device authenticator.

Connection will be established before each signing operation.

Parameter
  • data:
    • msg: String to be signed.
Return Value

Signed hexadecimal string.

interface IData<ISignDeviceData> {
    code: number;
    message: string;
    data: ISignDeviceData;
}

interface ISignDeviceData {
  deviceData: IDeviceData;
  signData: string;
}
Example
const signDeviceData = await connectDID.requestDeviceSignData({
  msg: "From .bit: e7343fdebaa9ec5aca009af3acb9c0664c94066f136f4d31b7b325dacf24f77c",
});

requestRecoverDeviceData()

Popup to guide the user in recovering locally stored data that has been cleared due to clearing browser cache.

Parameter

N/A

Return Value

Device Data

interface IData<IDeviceData> {
    code: number;
    message: string;
    data: IDeviceData;
}

interface IDeviceData {
  name: string;
  credential: ICredential;
  publicKey: IPublicKey;
  ckbAddr: string;
}
Example
const result = await connectDID.requestRecoverDeviceData();

requestBackupData(data: {ckbAddr: string;isOpen?: boolean;})

Popup to guide the user in performing multi-device backup. Decoding requires the use of the decodeQRCode method to obtain data of type { name: string; ckbAddr: string }.

Parameter
  • isOpen: boolean Whether to directly open the backup operation popup. default true. If set to false, it will return the URL of the backup page.
  • ckbAddr: string CKB address of the old device for the purpose of backup on a new device.
Return Value

URL string

Example
const url = await tabCaller.requestBackupData({
  isOpen: false,
  ckbAddr: "ckt1qqexmutxu0c2jq9q4msy8cc6fh4q7q02xvr7dc347zw3ks3qka0m6qggqus2789zvyms45khp275rfgz5lvcl09e9yyqwg90rj3xzdc26tts402p55p20kv0hjujjjhadjy",
});

// the QR code contains the following information:  
{ 
  name: string; // usename
  ckbAddr:string // ckb address
}

decodeQRCode(data: string)

Decode the specified formatted data.

Parameter
  • data: string
Return Value

Decoded data.

Example
const result = tabCaller.decodeQRCode("a4646e616d65724368726f6d652d646f746269742d3036")

requestWaitingPage(onError: (error: IData) => void)

A waiting page has emerged. This approach proves valuable in situations where the timing of a delayed pop-up window is crucial, as such delayed pop-ups are often intercepted by web browsers as malicious behavior. This method offers a solution: when a delayed pop-up is necessary, a waiting window is prompted directly, and subsequent redirection of the window is controlled through the provided method.

Parameter
  • onError: (error: IData<any>) => void, The described function is a void function that takes an error parameter. It is invoked when an error occurs on the waiting page after it appears, and subsequent operations are terminated.
    • error: IData<any>,{code: number, message: string, data: any}
Return Value
  • onNext: ({method, params}: {method: EnumRequestMethods, params: any}) => Promise<IData<any>>, The next page that needs to be redirected to.
  • onFailed: () => Promise<IData<any>>, Directly redirecting to the failed pop-up page.
  • onClose: () => Promise<void>, Close the current page.
Example
const onError = (err: IData<any>) => {
  console.log(err);
};
const result = await tabCaller.requestWaitingPage(onError);

// const failedData = await result.onFailed();
// console.log(failedData);

// Close the window
// await result.onClose();

const signData = await result.onNext({
  method: EnumRequestMethods.REQUEST_SIGN_DATA,
  params: {
    msg: "e7debaa9009af3acb9c06f77c",
  }
});
console.log(signData);

ConnectDIDError

Connect-DID SDK Error

Return Value

Error Object.

export enum ActionErrorCode {
  ABORT = 1000,  // user reject
  NOT_FOUND = 3001, // cid not found
  NOT_EXIST = 3002, // cid not exist
  ERROR = 5000, // internal error
  UNKNOWN = 9999,

  SUCCESS = 2000,
}
Example
try {
  const result = tabCaller.decodeQRCode("{a: 232302323}")
} catch (e) {
  console.log(e)  //{code: 9999, message: "unknown error"}:
}

FAQ

TBA

Get Help

If you have questions or need help with Connect-DID SDK, there are several ways to get assistance:

Contribute

We welcome contributions to Connect-DID SDK! If you are interested in helping to improve the project, there are several ways you can contribute:

  • Report bugs or suggest improvements by opening an issue on the GitHub repository.
  • Submit a pull request with your changes to the code.

Please note that Connect-DID SDK is still under development, so any contribution (including pull requests) is welcome.

License

Connect-DID SDK (including all dependencies) is protected under the MIT License. This means that you are free to use, modify, and distribute the software as long as you include the original copyright and license notice. Please refer to the license for the full terms.