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 🙏

© 2026 – Pkg Stats / Ryan Hefner

did-sdk-js

v0.0.5

Published

js sdk for did and vc according to mcps did spec

Readme

did-sdk-js

js sdk for did and vc according to mcps did spec

Description

This library is js sdk according to mcps did/vc spec

Usage

DID

creatDID


import * as did from "did-sdk-js"
let regionId = "sxcu"  // region id for the did

let myDid = await did.DidDocument.creatDID(did.AlgoType.AlgoTypeSecp256k1, did.IDGenType.IDGenTypeBech32, regionId)
let myDoc = myDid.document  // document for the did
let mainPrivateInfo = myDid.didPrivateInfo[0]  // main private key for the did
let appPrivateInfo = myDid.didPrivateInfo[1]  // app private key for the did

console.log(myDoc.toString())  // document to string

console.log(mainPrivateInfo.keyId) // key id for the publickey of did. such as "#keys-main"/"#keys-app"
console.log(mainPrivateInfo.algo)  // algo type for the publickey of did. such as sm2/secp256k1
console.log(mainPrivateInfo.privateKeyHex)  // private key for the publickey in hex 
console.log(mainPrivateInfo.mnemonic)  // mnemonic for the private key
console.log(mainPrivateInfo.publicKeyHex)  // publickey in hex

resetPublicKey


import * as did from "did-sdk-js"

let myNewDid = await myDid.resetPublicKey(did.AlgoType.AlgoTypeSm2, did.DIDUrl.fragmentKeyIdApp, mainPrivateInfo)
let myDoc = myNewDid.document  // new document for the did
let newPrivateInfo = myNewDid.privateInfo  // main private key info for the app key of did

console.log(myDoc.toString())  // document to string

revoke


import * as did from "did-sdk-js"

let myRevokeDid = await myNewDid.resetPublicKey(did.AlgoType.AlgoTypeSm2, did.DIDUrl.fragmentKeyIdApp, mainPrivateInfo)

console.log(myRevokeDid.toString())  // document to string

console.log(myRevokeDid.isRevoked())  // true

VC

凭证创建/签发/加密/解密


  
  let issuerDid = await did.DidDocument.creatDID(did.AlgoType.AlgoTypeSecp256k1, did.IDGenType.IDGenTypeBech32, regionId)
  let issuerDoc = issuerDid.document
  let issuerMainPrivateKey = issuerDid.didPrivateInfo[0]
  let holderDid = await did.DidDocument.creatDID(did.AlgoType.AlgoTypeSecp256k1, did.IDGenType.IDGenTypeBech32, regionId)
  let holderDoc = holderDid.document
  let holderAppPrivateKey = holderDid.didPrivateInfo[1]

  // new a real name claim
  let rnc = new did.RealNameClaim()
  rnc.setPublicFamilyName("张")
  rnc.setPrivateGivenName("三")
  rnc.setPrivatePhone("12345678909")

  let validYears = 10 // valid time for the vc
  // create a vc
  let newVC = did.VerifiableCredential.creatVC([issuerDoc.id], [holderDoc.id], [rnc], validYears)
  console.log(newVC.toString())

  // issuer issue the vc
  await newVC.issue(issuerDoc, issuerMainPrivateKey)
  console.log(newVC.toString())

  // issuer encrypt the vc to itself and the holder
  let vcCipher = await newVC.encrypt(did.EncryptLevel.EncryptLevel1, [issuerDoc, holderDoc])
  console.log(vcCipher.toString())
 
  // the holder decrypt the vc
  let vcDecrypt = await vcCipher.decrypt(holderDoc.id, holderAppPrivateKey)
  console.log(vcDecrypt.toString())

自定义声明


 // 按照规范定义凭证类型、公开信息、私有信息等字段
 
 // 实现声明接口方法:集成common/Claim 类
 // 实现以下方法
 type(): string // 声明类型

 newPrivateData(): ClaimPrivateDataBase // 隐私信息对象创建方法

 newPublicData(): ClaimPublicDataBase // 公开信息对象创建方法

 newMetaData(): ClaimMetaBase // 元数据对象创建方法


// 注册声明
// 1:声明类型
// 2:声明的类名称
registerClaimType(type: string, claim: object)