Tovanix(原 NexCore)平台全能 Node.js 客户端,覆盖 Payment / Exchange / Energy / SMTP / Withdraw / Account / VCard 7 大命名空间全部 44 个 v1 公开 endpoint.
零运行时依赖(仅 Node.js 标准库 http/https/crypto).
- Node.js 16+
- 内置 TypeScript 类型(
index.d.ts)
npm install @nexcore/sdk
# or
pnpm add @nexcore/sdk
# or
yarn add @nexcore/sdk(SDK 包发布到 npm 后)
cp -r sdk/node/{index.js,index.d.ts,package.json,src} your-project/lib/nexcore/index.js 公开入口(re-export Client + NexCoreError)
index.d.ts TypeScript 类型定义
package.json
src/
├── client.js 主客户端
├── http.js 底层 HTTP 传输
├── errors.js 统一异常 NexCoreError
└── namespaces/
├── payment.js 多链收款(7 endpoints)
├── exchange.js 汇率(5 endpoints)
├── energy.js TRON 能量租赁(8 endpoints)
├── smtp.js SMTP 聚合 API(6 endpoints)
├── withdraw.js 提币(4 endpoints,RSA 签名)
├── account.js 账户(2 endpoints)
└── vcard.js 虚拟信用卡(12 endpoints)
const { Client, NexCoreError } = require('@nexcore/sdk');
const client = new Client({
baseUrl: 'https://your-domain.com',
paymentAppId: 'APP20260412XXXX',
paymentAppKey: 'your_app_key_here',
energyApiKey: 'energy_api_key_here',
energySecretKey: 'energy_secret_key_here',
smtpApiKey: 'smk_xxx',
timeout: 30000,
});
(async () => {
try {
const order = await client.payment.createOrder({
out_order_id: `ORDER_${Date.now()}`,
amount: '100.00',
currency: 'CNY',
trade_type: 'usdt.trc20',
call_type: 'rotation',
});
console.log('支付地址:', order.pay_address);
const rate = await client.exchange.getRate('USDT', 'CNY');
console.log('USDT/CNY:', rate.rate);
const est = await client.energy.estimateEnergy('TXxxxxxxxxxxxxxxxxxxxxx');
console.log('建议能量:', est.suggested_energy);
const mail = await client.smtp.send({
to: 'user@example.com',
subject: '验证码',
body: '<h1>123456</h1>',
is_html: true,
});
console.log('消息 ID:', mail.message_id);
} catch (e) {
if (e instanceof NexCoreError) {
console.error(`Error #${e.code}: ${e.message} (trace: ${e.requestId})`);
}
}
})();import { Client, NexCoreError } from '@nexcore/sdk';
const client = new Client({ baseUrl: 'https://your-domain.com', /* ... */ });
const order = await client.payment.createOrder({ /* ... */ });完整类型定义在 index.d.ts.
| 方法 | HTTP | endpoint |
|---|---|---|
createOrder(params) |
POST | /api/v1/pay/create |
queryOrder(outOrderId) |
GET | /api/v1/pay/query |
closeOrder(outOrderId) |
POST | /api/v1/pay/close |
getAppConfig() |
GET | /api/v1/pay/app-config |
bindAddress(userId, tradeType) |
POST | /api/v1/pay/bind-address |
getUserAddress(userId) |
POST | /api/v1/pay/get-address |
unbindAddress(userId) |
POST | /api/v1/pay/unbind-address |
sign(params) |
(工具) | HMAC-SHA256 签名 |
verifyNotifySign(payload) |
(工具) | webhook 校验(常量时间) |
| 方法 | HTTP | endpoint |
|---|---|---|
getRate(from, to) |
GET | /api/v1/rate |
convert(from, to, amount) |
POST | /api/v1/convert |
getRates(symbols, base?) |
GET | /api/v1/rates |
getFiatRates(base) |
GET | /api/v1/rates/fiat |
getAllRates(base) |
GET | /api/v1/rates/all |
注:getRates 的 base 可不传,由后端取默认(USDT).
| 方法 | HTTP | endpoint |
|---|---|---|
getInfo() |
GET | /api/v1/energy/info |
getPrice(energyAmount, period) |
GET | /api/v1/energy/price?energy_amount=&period= |
estimateEnergy(toAddress) |
GET | /api/v1/energy/estimate-energy?to_address= |
createOrder(params) |
POST | /api/v1/energy/order |
createOnetimeOrder(params) |
POST | /api/v1/energy/order/onetime |
queryOrder(serial) |
GET | /api/v1/energy/order/:serial |
listOrders(filter) |
GET | /api/v1/energy/orders |
reclaimOrder(serial) |
POST | /api/v1/energy/order/reclaim |
注:租期 period 枚举 1H / 1D / 3D / 7D / 30D;createOrder 必填 receive_address / energy_amount / period,可选 out_trade_no / remark.
| 方法 | HTTP | endpoint |
|---|---|---|
send(params, opts?) |
POST | /api/v1/smtp/send |
sendBatch(params, opts?) |
POST | /api/v1/smtp/send/batch |
sendTemplate(params) |
POST | /api/v1/smtp/send/template |
getQuota() |
GET | /api/v1/smtp/quota |
getStatus(messageId) |
GET | /api/v1/smtp/status/:message_id |
reportInbound(params) |
POST | /api/v1/smtp/inbound |
send可选字段:from_name/reply_to/text_body/headers/cc/bcc/attachments/account_id/send_at(定时,RFC3339);opts.idempotencyKey写入Idempotency-Key幂等头sendBatch必填recipients数组(元素{to, variables?, from_name?}),静态subject+body或template_code二选一;同样支持opts.idempotencyKeysendTemplate必填to+template_code,可选variables/from_namegetQuota返回daily_limit/daily_used/daily_remaining/monthly_*/expire_atreportInbound上报退信/投诉(email与message_id至少其一,type=bounce|complaint)
| 方法 | HTTP | endpoint |
|---|---|---|
createWithdraw(params) |
POST | /api/v1/withdraw |
getWithdraw(orderId) |
GET | /api/v1/withdraw/:id |
getWithdrawableBalance() |
GET | /api/v1/balance/withdrawable |
quoteFee(chain, symbol, amount) |
GET | /api/v1/fee/quote(amount 必填) |
sign(...) / verifyCallback(...) |
(工具) | RSA 签名 / 平台回调验签 |
| 方法 | HTTP | endpoint |
|---|---|---|
getBalance() |
GET | /api/v1/account/balance |
getDepositAddress() |
GET | /api/v1/account/deposit-address |
| 方法 | HTTP | endpoint |
|---|---|---|
getInfo() / listBins() / listCards() |
GET | /api/v1/vcard/*(读,X-API-Key) |
getCardTransactions(cardId) / listOrders(query) / getOrder(orderId) |
GET | 同上 |
updateCardRemark(cardId, remark) |
POST | 同上 |
getCardDetails(cardId) / getCardCode(cardId) |
GET | 敏感读(HMAC 头签名) |
openCard(params) / rechargeCard(cardId, params) / cancelCard(cardId) |
POST | 资金操作(HMAC 头签名) |
const express = require('express');
const app = express();
app.use(express.json());
app.post('/payment/notify', (req, res) => {
if (!client.payment.verifyNotifySign(req.body)) {
return res.status(400).send('invalid sign');
}
// 处理回调... 务必幂等
res.send('OK');
});verifyNotifySign 内部用 crypto.timingSafeEqual,常量时间比较防时序攻击.
NexCoreError:
code— 平台错误码(0=成功)message— 错误描述requestId— 服务端追踪 ID(响应头X-Trace-Id)httpStatus— HTTP 状态码
见 examples/:
create_order.js— 完整下单webhook_express.js— Express 接收回调