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

foxone-js-opensdk

v1.2.2

Published

Downloads

21

Readme

Fox.ONE JS-Open-SDK

安装

项目依赖 axios,请先安装axios

npm install axios
npm install foxone-js-opensdk

使用

// 在javascript文件中引入:
import FoxSDK from 'foxone-js-opensdk'
let sdk = new FoxSDK() 

// 默认是生产环境,配置开发环境:
// let sdk = new FoxSDK({env: 'development'}) 

// 配置token
sdk.api.config({
    headers: {
        // token 从后台获取的token
       'Authorization': `Bearer ${token}`
    }
})

// 使用
sdk.getAccountDetail().then(res => {
    // code
}).catch(err => {
    // error
})

返回的格式以及错误处理

Fox.ONE Open SDK中的接口返回类型是Promise,sdk会判断网络请求返回的状态,如果请求成功,resolve()中返回的是data。如果请求失败,reject()中会返回code(错误码)和message(错误消息),可以在catch()方法中捕捉错误码和错误消息,进行相应的错误处理。

// 网络请求返回的数据结构
{
    code: 0, // code === 0 表示操作成功,其他的值表示请求失败
    data: {
       // data   
    }    
}

关于私钥(pin)

FoxONE 不保存用户的私钥,一旦丢失无法通过后台找回,请务必提醒用户牢记密码。

API 接口

下面的response是网络请求成功返回的response,并删除了一些有返回但是不会用上的字段。

getAccountDetail() ⇒ Promise

获取账户信息

response:

{
    "code": 0,
    "data": {
        "user": {
            "avatar": "", // 头像
            "bio": "", // 简介
            "createdAt": 1540198807, // 创建时间
            "email": "", // 电子邮件
            "fullname": "", // fullname
            "isPinSet": true, // 是否设置了pin
            "isPwdSet": true, // 是否设置了密码
            "mixinUserId": "", 
            "tel": "86 18656007000", // 手机号
            "userId": 20518 // id
        }
    }
}

verifyPIN(pin) ⇒ Promise

验证pin是否正确

request

| 字段 | type | require | 描述 | | ---- | ------ | ------- | ---- | | pin | String | true | |

response

{"code":0,"data":{}}

setPIN(pin) ⇒ Promise

设置pin

request

| 字段 | type | require | 描述 | | ---- | ------ | ------- | ------------------- | | Pin | String | true | 6位数字组成的字符串 |

response

{"code":0,"data":{}}

modifyPIN(pin, newPin) ⇒ Promise

修改pin

request

| 字段 | type | require | 描述 | | ------ | ------ | ------- | ------------------------------ | | pin | String | true | 旧的pin码 | | newPin | String | true | 新的pin码,6位数字组成的字符串 |

response

{"code":0,"data":{}}

loadAssets() ⇒ Promise

获取FoxONE支持的资产详情列表。

注意eos资产和其他资产的区别: EOS标识使用的是账户名称(accountName)和账户标识(accountTag),其他资产的标识使用的是publicKey。

changeBtc、changeUsd、priceBtc、priceUsd是从mixin返回的数据。可以根据change,price字段结合汇率接口计算出当前不同币种的价格。

response

{
    "code": 0,
    "data": {
        "assets": [
            {
                "name": "EOS",
                "symbol": "EOS", // 简称
                "publicKey": "", // 资产标识
                "accountName": "eoswithmixin", // eos账户名称
                "accountTag": "2f06d6944a63343661b1db4dcb21c129",  // eos账户标识
                "assetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d", // mixinAssetId
                "assetKey": "", 
                "balance": 0.005, // 余额
                "chain": { // 主链信息
                    "coinId": 5,
                    "logo": "https://www.fox.one/assets/coins/eos.png",
                    "mixinAssetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                    "name": "EOS",
                    "symbol": "EOS"
                },
                "chainId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                "change": -0.01022158, // 价格变化,btc计价
                "changeBtc": -0.01513198, // 价格变化,btc计价
                "changeUsd": 0.007236840585224058, // 价格变化,usd计价
                "confirmations": 64, // 转账需要多少区块确认
                "icon": "https://www.fox.one/assets/coins/eos.png", 
                "price": 32.33471769, // 当前价格 人民币计价
                "priceBtc": 0.00082601, // 当前价格 btc计价
                "priceUsd": 4.64989319 // 当前价格 usd计价
            }
        ]
    }
}

loadAsset(id) ⇒ Promise

获取单个资产的详情

request

| 字段 | type | require | 描述 | | ---- | ------ | ------- | ------------ | | id | String | true | mixinAssetId |

response

{
    "code": 0,
    "data": {
        "asset": {
            "name": "EOS",
            "symbol": "EOS", // 简称
            "publicKey": "", // 资产标识
            "accountName": "eoswithmixin", // eos账户名称
            "accountTag": "2f06d6944a63343661b1db4dcb21c129",  // eos账户标识
            "assetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d", // mixinAssetId
            "assetKey": "", 
            "balance": 0.005, // 余额
            "chain": { // 主链信息
                "coinId": 5,
                "logo": "https://www.fox.one/assets/coins/eos.png",
                "mixinAssetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                "name": "EOS",
                "symbol": "EOS"
            },
            "chainId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
            "change": -0.01022158, // 价格变化 
            "changeBtc": -0.01513198, // 价格变化,btc计价
            "changeUsd": 0.007236840585224058, // 价格变化,usd计价
            "confirmations": 64, // 转账需要多少区块确认
            "icon": "https://www.fox.one/assets/coins/eos.png", 
            "price": 32.33471769, // 当前价格
            "priceBtc": 0.00082601, // 当前价格 btc计价
            "priceUsd": 4.64989319 // 当前价格 usd计价
        }
    }
}

loadEnabledCoins() ⇒ Promise

支持提币的资产列表

response

{
    "code": 0,
    "data": {
        "assets": [
            {
                "name": "EOS",
                "symbol": "EOS", // 简称
                "publicKey": "", // 资产标识
                "accountName": "eoswithmixin", // eos账户名称
                "accountTag": "2f06d6944a63343661b1db4dcb21c129",  // eos账户标识
                "assetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d", // mixinAssetId
                "assetKey": "", 
                "balance": 0.005, // 余额
                "chain": { // 主链信息
                    "coinId": 5,
                    "logo": "https://www.fox.one/assets/coins/eos.png",
                    "mixinAssetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                    "name": "EOS",
                    "symbol": "EOS"
                },
                "chainId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                "change": -0.01022158, // 价格变化,btc计价
                "changeBtc": -0.01513198, // 价格变化,btc计价
                "changeUsd": 0.007236840585224058, // 价格变化,usd计价
                "confirmations": 64, // 转账需要多少区块确认
                "icon": "https://www.fox.one/assets/coins/eos.png", 
                "price": 32.33471769, // 当前价格 人民币计价
                "priceBtc": 0.00082601, // 当前价格 btc计价
                "priceUsd": 4.64989319 // 当前价格 usd计价
            }
        ]
    }
}

loadUserAssets() ⇒ Promise

用户的资产列表

Response

{
    "code": 0,
    "data": {
        "assets": [
            {
                "name": "EOS",
                "symbol": "EOS", // 简称
                "publicKey": "", // 资产标识
                "accountName": "eoswithmixin", // eos账户名称
                "accountTag": "2f06d6944a63343661b1db4dcb21c129",  // eos账户标识
                "assetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d", // mixinAssetId
                "assetKey": "", 
                "balance": 0.005, // 余额
                "chain": { // 主链信息
                    "coinId": 5,
                    "logo": "https://www.fox.one/assets/coins/eos.png",
                    "mixinAssetId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                    "name": "EOS",
                    "symbol": "EOS"
                },
                "chainId": "6cfe566e-4aad-470b-8c9a-2fd35b49c68d",
                "change": -0.01022158, // 价格变化,btc计价
                "changeBtc": -0.01513198, // 价格变化,btc计价
                "changeUsd": 0.007236840585224058, // 价格变化,usd计价
                "confirmations": 64, // 转账需要多少区块确认
                "icon": "https://www.fox.one/assets/coins/eos.png", 
                "price": 32.33471769, // 当前价格 人民币计价
                "priceBtc": 0.00082601, // 当前价格 btc计价
                "priceUsd": 4.64989319 // 当前价格 usd计价
            }
        ]
    }
}

withdraw(data, pin) ⇒ Promise

提币

request

| 字段 | type | require | 描述 | | -------------- | ------ | ------- | ------------------------------------------------------------ | | data | Object | true | 包含提币所需信息的对象 | | data.assetId | String | true | 资产id | | data.publicKey | String | true | 币种是eos时应该传eos的accountName,其他币种传资产对应的pulicKey | | data.label | String | false | 币种是eos时传eos的accountTag,其他币种可以不传 | | data.amount | String | true | 提币的数量 | | data.memo | String | true | 备注 | | pin | String | true | pin |

response

{
    "code":0,
    "data": {
        "snapshot":{
            "coinId":2437, 
            "snapshotId":"70574d71-0fc7-49ad-a776-d8e0e8a360e1",  
            "assetId":"965e5c6e-434c-3fa9-b780-c50f43cd955c", 
            "traceId":"fd34e783-ef45-4d71-82cb-315b10c5aede",
            "amount":-10, // 数量
            "memo":"sss", // 备注
            "createdAt":1542356956, // 创建时间
            "counterUserId":"1f898df6-06aa-398b-ac8ef448ecfa994c", // 
            "sender":"", // 发送方地址。mixin内部转账为空
            "receiver":"", // 接受方地址。mixin内部转账为空
            "transactionHash":""
        }
    }
}

loadSnapshots(params) ⇒ Promise

转账、交易等操作详细信息的列表

request

| 字段 | type | require | 描述 | | -------------- | ------ | ------- | ------------------------------------------ | | params | Object | true | 请求的参数 | | params.assetId | string | True | Mixing assetId,需要获取的币种id | | params.cursor | String | False | 分页请求中下一页的指针 | | params.limit | Number | False | 每页返回的数量,默认20条,最小10,最大50。 |

response

{
    "code": 0,
    "data": {
        "pagination": { // 分页
            "nextCursor": "MTU0MTIxNTI0MTgyODk1NzAwMA==",
            "hasNext": true
        },
        "snapshots": [
            { 
                "amount": 1.024, // 数量
                "asset": { // 资产信息
                    "assetId": "965e5c6e-434c-3fa9-b780-c50f43cd955c", 
                    "chainId": "43d61dcd-e413-450d-80b8-101d5e903357", // 主链id
                    "coinId": 2437, 
                    "icon": "https://images.mixin.one/0sQY63dDMkWTURkJVjowWY6Le4ICjAFuu3ANVyZA4uI3UdkbuOT5fjJUT82ArNYmZvVcxDXyNjxoOv0TAYbQTNKS=s128",
                    "name": "Chui Niu Bi",
                    "symbol": "CNB"
                },
                "assetId": "965e5c6e-434c-3fa9-b780-c50f43cd955c",  // mixinAssetId
                "createdAt": 1542351842, // 创建时间
                "extraData": {},  
                "insideMixin": true, // 是否是Mixin网络内
                "memo": "I wish you good luck!", // 备注
                "opponent": { // 对方信息
                    "avatar": "https://images.mixin.one/dhB4QJLEhEFhzc8mH3mSFyL2kdjFVecF-BCdnYJhCA42kjl6txWGdgrbLqEVFM-_Cf6BE3d-seO6RhbSRYGVDmM=s256",
                    "foxId": 0,
                    "fullname": "FoxOne", 
                    "mixinId": "7f361fd2-e649-411f-8774-74fe07376874"
                },  
                "opponentId": "7f361fd2-e649-411f-8774-74fe07376874", // 对方的mixinId
                "receiver": "", // 接受方
                "sender": "", // 发送方
                "snapshotId": "ed8a9aae-514d-4051-a496-d94e93bad883", 
                "source": "TRANSFER_INITIALIZED", // 操作类型
                "traceId": "e039a437-ee24-42f2-a14c-baef70e36044", // 唯一标识,防重放
                "transactionHash": "", 
                "userId": "df7a373b-422a-32e4-b170-8c2e07f7ed0d"
            }
        ]
    }
}
// source (操作类型) 字段取值范围:
DEPOSIT_CONFIRMED //充值
TRANSFER_INITIALIZED // 转账, 结合数量(amount)可以判断是转入还是转出,amount大于0是转入,小于0是转出
WITHDRAWAL_INITIALIZE // 提现
WITHDRAWAL_FEE_CHARGED // 提现手续费
WITHDRAWAL_FAILED // 提现失败
O1_OPEN_ACCOUNT // OceanOne账户开通
O1_PUT_ORDER // OceanOne下单
O1_CANCEL_ORDER // OceanOne撤单
O1_ORDER_CANCELED // OceanOne订单退回
O1_ORDER_REFUND // OceanOne订单取消
O1_ORDER_MATCHED // OceanOne订单成交
FOX_REDPACKET_REWARD  // 收到红包
FOX_REDPACKET_PAY // 发出红包
FOX_REDPACKET_REFUND  // 红包退款

loadFee() ⇒ Promise

交易手续费

response

{
    "code":0,
    "data":{
        "fee":{
            "amount":"0", // 数量
            "assetId":"965e5c6e-434c-3fa9-b780-c50f43cd955c", // mixinAssetId
            "coinId":2437 
        }
    }
}

currency()⇒ Promise

获取汇率数据

response

{
    "code": 0,
    "data": {
        "cnyTickers": [
            {
                "timestamp": 1542438000000,
                "from": "IDR",
                "to": "CNY",
                "price": "0.000475",
                "changeIn24h": "-0.0041928721174004"
            },
            {
                "timestamp": 1542438000000,
                "from": "MYR",
                "to": "CNY",
                "price": "1.656725",
                "changeIn24h": "0.000504864758447"
            },
            {
                "timestamp": 1542438001000,
                "from": "JPY",
                "to": "CNY",
                "price": "0.061488",
                "changeIn24h": "0.0032632815559326"
            },
            {
                "timestamp": 1542438001000,
                "from": "SGD",
                "to": "CNY",
                "price": "5.055761",
                "changeIn24h": "0.0015082762051105"
            },
            {
                "timestamp": 1542438001000,
                "from": "USD",
                "to": "CNY",
                "price": "6.938041",
                "changeIn24h": "-0.0002533214578693"
            },
            {
                "timestamp": 1542439802000,
                "from": "BTC",
                "to": "CNY",
                "price": "38949.11425768",
                "changeIn24h": "-0.0130212018940632"
            }
        ],
        "currencies": {
            "bitcny": "1",
            "usd": "6.938041",
            "usdt": "6.945"
        }
    }
}

错误码

服务端错误码

| code | 描述 | | ---- | ------------------------------------------- | | 1 | invalid operation | | 2 | unknown error | | 3 | server error | | 4 | visit too frequently | | 5 | login too frequently | | 6 | forbidden operation | | 1553 | You have not set PIN yet, please set first. | | 1554 | PIN is incorrect, please try again. | | 1560 | mixin has bind with other user | | 1561 | mixin has not bind | | 1586 | item is not exist | | 1587 | no data changed | | 1600 | wallet not initialized | | 1601 | invalid public key | | 2048 | invalid application |

客户端错误码

| code | 描述 | | ---- | -------------- | | -1 | 参数校验不通过 |

更新日志

2019.1.14

  • 限制pin的格式为6位数字组成的字符串,设置pin和修改pin的时候添加校验

  • 更新文档说明