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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dotwallet-jssdk

v1.2.7

Published

The DotWallet APIs for JS

Downloads

3

Readme

The DotWallet APIs for JS

📦 Install

yarn add dotwallet-jssdk

or

npm i dotwallet-jssdk

✨ Usage

import DotWallet, { ENV } from "dotwallet-jssdk";

const wallet = new DotWallet({
  clientID: "dotwallet-app-id",
  clientSecret: "dotwallet-app-secret", // 可选
  redirectUrl: "redirect url",
  // 调试测试环境
  env: ENV.Test,
});

wallet.login();

其中环境枚举

enum ENV {
  Test = "test",
  Production = "production",
  Staging = "staging",
}

🔨 Methods

1. login()

跳转 DotWallet 开放平台登录授权。授权成功跳转回调地址并带 code 和 state 回来

2. getToken()

通过 code 换 access_token 和 refresh_token

const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");

wallet.getToken({
  code,
  clientSecret: "dotwallet-app-secret";
});

参数:

| 参数名 | 必选 | 类型 | 说明 | | ------------ | ---- | ------ | --------------------------------------------------------------------------- | | code | 是 | string | 授权成功后回调地址 query 参数里面 code | | clientSecret | 否 | string | 可选项。(刷新 token 需要传 clientSecret,也可在 new Dotwallet 时全局传入) |

返回示例:

{
  "accessToken": "JWT access token",
  "refreshToken": "PDIWLOLXXQM5KAWINUFP7G",
  "scope": "user.info",
  "tokenType": "Bearer",
  "expiresIn": 7200
}

2.1 refreshToken()

通过 refresh_token 刷新 access_token 和 refresh_token

wallet.refreshToken({
  refreshToken: "Y7RD2CUKWLGDLNYEUGZMYG",
  clientSecret: "dotwallet-app-secret",
});

参数:

| 参数名 | 必选 | 类型 | 说明 | | ------------ | ---- | ------ | --------------------------------------------------------------------------- | | refreshToken | 是 | string | | | clientSecret | 否 | string | 可选项。(刷新 token 需要传 clientSecret,也可在 new Dotwallet 时全局传入) |

返回示例:

{
  "accessToken": "JWT access token",
  "refreshToken": "PDIWLOLXXQM5KAWINUFP7G",
  "scope": "user.info",
  "tokenType": "Bearer",
  "expiresIn": 7200
}

3. getMetaIDUserInfo()

获取用户信息

返回示例

{
  "name": "你好",
  "nameEncrypt": 0,
  "phone": 1231111111,
  "phoneEncrypt": 0,
  "email": "[email protected]",
  "emailEncrypt": 0,
  "headUrl": "https://xxxx.png",
  "headUrlEncrypt": 0,
  "showId": "xxxx",
  "address": "xxxx",
  "infoTxId": "xxxx",
  "protocolTxId": "xxxx",
  "timestamp": 12672112
}

4. sendMetaDataTx()

发起 Protocols node 操作

const data = await wallet.sendMetaDataTx({
  nodeName: "SimpleMicroblog",
  metaIdTag: "metaid",
  brfcId: "987654321",
  encrypt: 0,
  payCurrency: "BSV",
  payTo: [
    {
      amount: 2000,
      address: "1ad59XtDJMeaMAuXasFad1EU4h",
    },
  ],
  path: "/Protocols/SimpleMicroblog",
  dataType: "application/json",
  attachments: [
    {
      fileName: "PC0b3c7d089fa7d55720d6cf.png",
      fileType: "image/png",
      data: "89504ae426082",
      encrypt: 0,
    },
  ],
  data: JSON.stringify({ content: "这是一个测试内容", title: "测试标题" }),
  needConfirm: true,
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ----------- | ---- | ------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | nodeName | 是 | string | | 节点标识名字 | | dataType | 是 | string | text/plain | 可选项目。data 对应的数据类型,可用数据类型请参考:https://www.iana.org/assignments/media-types/media-types.xhtmls。默认为text/plain | | encoding | 是 | string | UTF-8 | 对应 metaID encoding | | data | 是 | string | 'NULL' | 对应 metaID data | | attachments | 否 | array | [] | 附件 | | encrypt | 是 | number | 0 | 识该节点内容是否加密。本协议版本支持两种方式:0 为不加密;1 为 ECIES 加密,即加密 key 为对应节点的公钥,采用对应节点路径的私钥解密。默认为 0 不加密。 | | version | 是 | string | 0.0.9 | 对应 metaID version | | brfcId | 是 | string | | 协议 Id | | path | 是 | string | '' | 如果不是第一层 protocols 子节点, 需要带上完整路径 比如/Protocols/ShowBuzz 将在这个节点下创建 Node | | payCurrency | 否 | string | bsv | 指定转账计价币种,支持 bsv 和 usd 两种,如果是 bsv 则计价单位为聪,如果是 usd 则计价单位为美元 | | payTo | 否 | array | [] | 同时向指定地址转账,交易输出格式为 [{address: 'XXXXXXXXXX', amount: 1000}] | | metaIdTag | 否 | string | metaid | 固定为 metaid | | nodeKey | 否 | string | | 编辑数据时需要指定当前节点的 publicKey | | checkOnly | 否 | boolean | false | 是否广播节点,默认 false 广播,为 true 时返回节点费率,txid 之类信息,不广播 | | needConfirm | 否 | boolean | true | 用户是否需要支付前确认 |

attachments:

| 参数 | 必须 | 类型 | 默认值 | 描述 | | -------- | ---- | ------ | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | fileName | true | string | | 文件名 | | fileType | true | string | | 文件格式 | | data | true | string | | 文件 hex(16 进制)数据,explame:buffer.toString("hex") | | encrypt | true | number | | 识该节点内容是否加密。本协议版本支持两种方式:0 为不加密;1 为 ECIES 加密,即加密 key 为对应节点的公钥,采用对应节点路径的私钥解密。默认为 0 不加密。 |

5. eciesEncryptData()

ECIES 加密数据

wallet.eciesEncryptData({
  data: "",
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ---- | ---- | ------ | ------ | --------- | | data | 是 | string | | data 数据 |

返回结果样例:

{
  "message": "Encrypt data success",
  "content": "<加密后的值>"
}

6. eciesDecryptData()

ECIES 解密数据

例子

wallet.eciesDecryptData({
  data: "",
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ---- | ---- | ------ | ------ | --------- | | data | 是 | string | | data 数据 |

返回结果样例:

{
  "code": 200,
  "status": "success",
  "data": {
    "message": "Decrypt data success",
    "content": "<加密后的值>"
  }
}

7. ecdhEncryptData()

ECDH 加密数据

例子

wallet.ecdhEncryptData({
  data: {
    msg: "",
    publickey: "",
  },
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ---- | ---- | ------ | ------ | --------- | | data | 是 | string | | data 数据 |

返回结果样例:

{
  "code": 200,
  "status": "success",
  "data": {
    "message": "Encrypt data success",
    "content": "<加密后的值>"
  }
}

8. ecdhDecryptData()

ECDH 解密数据

例子

wallet.ecdhDecryptData({
  data: {
    msg: "",
    publickey: "",
  },
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ---- | ---- | ------ | ------ | --------- | | data | 是 | string | | data 数据 |

返回结果样例:

{
  "code": 200,
  "status": "success",
  "data": {
    "message": "Decrypt data success",
    "content": "<加密后的值>"
  }
}

9. payToAddress()

转账

例子

wallet.payToAddress({
  data: {
    to: [
      {
        address: "xxx",
        amount: 123,
      },
    ],
  },
  currency: "bsv",
});

参数说明

| 参数 | 必须 | 类型 | 默认值 | 描述 | | -------- | ---- | ------ | ------ | ----------- | | to | 是 | Array | | 目标 | | currency | 是 | string | bsv | sats 或 bsv |

to:

| 参数 | 必须 | 类型 | 默认值 | 描述 | | ------- | ---- | ------ | ------ | -------------------- | | address | 是 | string | | 目标地址,或 paymail | | amount | 是 | number | | 金额 |

返回结果样例:

{
  "code": 200,
  "status": "success",
  "data": {
    "txId": "dssdfsfds"
  }
}

DotWalletForMataID

提供 metaid 版本,相比 DotWallet 参数额外增加了 callback 回调方法。

callback 方法的入参为

interface MetaIDCallBackParams<T> {
  code: number;
  status: "success" | "failure";
  data: T;
}

以 getToken 方法为例

import { DotWalletForMetaID, ENV } from "dotwallet-jssdk"

const CLIENT_ID = "xxx";
const CLIENT_SECRET = "xxx";

const walletForMetaID = new DotWalletForMetaID({
  clientID: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  redirectUrl: window.origin,
  env: ENV.Staging,
});

...

// 跳转打点开放平台登录授权后,使用 getToken 获取 DotWalletToken 信息
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");

walletForMetaID.getToken({
  code,
  clientSecret: "dotwallet-app-secret";
  callback: (res) => {
    // TODO
    console.log(res);
    // 成功
    // {
    //   code: 200,
    //   status: "success",
    //   data: {
    //     accessToken: "eyJhxxxxxxxxxx",
    //     expiresIn: 7200,
    //     refreshToken: "xxxxxxxxxxx",
    //     scope: "autopay.bsv",
    //     tokenType: "Bearer",
    //   },
    // }

    // 失败
    // {
    //   code: 400,
    //   status: "failure",
    //   data: "所提供的授权授权(例如,授权代码,资源所有者凭证)或刷新令牌无效,已过期,已吊销xxxxxxx",
    // }
  }
});

💿 Example

Quick Overview

run serve

npm run dev

open http://localhost:3000/