@coinsenda/sdk

中文文档
1.9.0发布于 2026/09/15Apache-2.0CommonJS近 30 天下载 2042

NodeJS SDK for Coinsenda

原始使用文档
文档目录10 节
  1. Installation
  2. Prerequisites
  3. 1. Generate an RSA key pair
  4. 2. Register the public key in your Coinsenda account
  5. Authentication
  6. Full example
  7. Identifier in the signed token
  8. Environment
  9. Calling endpoints
  10. License

@coinsenda/sdk

Node.js SDK for Coinsenda — a crypto exchange platform.

Authentication uses RSA public key signatures. Before calling the SDK you must generate a key pair locally and register the public key in your Coinsenda account profile settings. The private key never leaves your environment.

Installation

npm install @coinsenda/sdk jsonwebtoken node-rsa

Prerequisites

1. Generate an RSA key pair

Create a 2048-bit RSA key pair on your machine. Store the private key securely — you will use it on every login.

const NodeRSA = require('node-rsa');

let key = new NodeRSA({ b: 2048 });
let public_key = key.exportKey('pkcs8-public-pem');
let private_key = key.exportKey('pkcs8-private-pem');

// Save private_key in a secrets manager or env variable — never commit it

You can also generate the pair with OpenSSL:

openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem

2. Register the public key in your Coinsenda account

Sign in to your Coinsenda account and open Profile Settings → API Public Key.

Paste the public key (PEM format) and save. Coinsenda stores it in your profile and uses it to verify future signature-based logins.

This step is required once per key pair. If you rotate keys, register the new public key before authenticating with the new private key.

Authentication

Every session needs:

RequirementDescription
Registered public keySaved in your Coinsenda profile settings
Private keyHeld locally; used to sign the login token

Full example

const NodeRSA = require('node-rsa');
const jwt = require('jsonwebtoken');
const { CoinsendaClient, isHttpSuccess } = require('@coinsenda/sdk');

async function authenticate(email, private_key_pem) {
  // 1. Create client
  let client = new CoinsendaClient({ domain: 'coinsenda.com' });

  // 2. Sign a short-lived token with your private key
  let rsa_key = new NodeRSA(private_key_pem, 'pkcs8-private-pem');
  let signed_token = jwt.sign(
    { email: email, iat: Math.floor(Date.now() / 1000) },
    rsa_key.exportKey('private'),
    { algorithm: 'RS256', expiresIn: '5m' }
  );

  // 3. Authenticate via POST /auth/pubkey
  let auth_result = await client.auth.passport.authPubkey({
    data: { signed_token }
  });

  if (!isHttpSuccess(auth_result.status)) {
    throw new Error(`Authentication failed: ${auth_result.status}`);
  }

  let response_data = auth_result.data?.data || auth_result.data;
  client.setJwt(response_data.jwt);
  client.setRefreshToken(response_data.refresh_token);

  return client;
}

// Usage
let client = await authenticate('[email protected]', process.env.COINSENDA_PRIVATE_KEY);

let profile = await client.transaction.user.__get__profile();
console.log(profile.data);

Identifier in the signed token

The payload you sign must identify your Coinsenda account:

FieldWhen to use
emailDefault — matches the email on your Coinsenda account
userIdWhen you know your Coinsenda user ID
phone_numberPhone-based accounts

Always include iat (issued-at timestamp). The token expires after 5 minutes — generate a new one for each login attempt.

Environment

// Production
new CoinsendaClient({ domain: 'coinsenda.com' });

// Staging
new CoinsendaClient({ domain: 'bitsenda.com' });

// Local development (requires config/environments.local.js)
new CoinsendaClient({ environment: 'local' });

Copy config/environments.local.example.js to config/environments.local.js and adjust ports if needed.

Calling endpoints

After authentication, all requests include Authorization: Bearer <jwt> automatically.

Methods follow client.{service}.{model}.{method}(data):

await client.account.user.__get__accounts();
await client.deposit.user.__get__deposits();
await client.withdraw.withdraw.addNewWithdrawPublic({ ... });

Responses are raw server objects: { status, data, headers }. Use isHttpSuccess(result.status) to check for 2xx.

License

Apache-2.0

版本与发布记录

@coinsenda/sdk 共发布 13 个版本,首次发布于 2026/03/07;过去 12 个月发布了 13 个版本。

版本发布日期距今
1.9.0latest2026/09/151 个月前
1.8.02026/09/052 个月前
1.7.02026/08/083 个月前
1.6.02026/06/234 个月前
1.5.12026/05/265 个月前
1.5.02026/05/265 个月前

关于 @coinsenda/sdk 的常见问题

@coinsenda/sdk 是什么?

NodeJS SDK for Coinsenda

如何安装 @coinsenda/sdk?

在项目目录运行 npm install @coinsenda/sdk,或使用 pnpm add / yarn add / bun add。

@coinsenda/sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/coinsenda__sdk 是否存在。

@coinsenda/sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@coinsenda/sdk 可以商用吗?

@coinsenda/sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@coinsenda/sdk 的下载量有多少?

根据 npm 官方下载统计,@coinsenda/sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,042 次,日均约 68 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coinsenda/sdk 还在维护吗?

最新版本 1.9.0 发布于 2026/09/15(1 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/03/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。