在节点中创建bitpay客户端

时间:2015-02-22 18:28:43

标签: javascript node.js

如果我尝试在npm安装bitpay之后在节点中创建一个bitpay客户端并将其提供给我在bitpay.com上生成的api密钥。

var client = BitPay.createClient('apikey');

我明白了:

assert.js:92  throw new assert.AssertionError({
AssertionError: Not enough entropy. Minimum is: 192 bits
at new HmacDRBG (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/node_modules/elliptic/lib/elliptic/hmac-drbg.js:24:3)
at EC.sign (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/node_modules/elliptic/lib/elliptic/ec/index.js:94:14)
at Object.BitAuth.sign (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/node_modules/bitauth/lib/bitauth.js:101:25)
at RESTClient._sendRequest (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:156:46)
at RESTClient.get (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:282:28)
at RESTClient._getAccessTokens (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:81:19)
at new RESTClient (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/lib/rest-client.js:51:17)
at Object.module.exports.createClient (/home/enigma/WebstormProjects/expensereports/node_modules/bitpay/index.js:10:12)
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/btc.controller.js:6:21)
at Module._compile (module.js:456:26)

如果我尝试网站提供的方式:

$ npm install bitpay
var BitPay = require('bitpay');
var client = new BitPay('apikey');
client.on('ready', function() {
   client.post('invoices', { price: 10.00, currency: 'USD' });
});

抱怨

var client = new BitPay('apikey'
TypeError: object is not a function
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/btc.controller.js:6:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/enigma/WebstormProjects/expensereports/server/api/btc/index.js:4:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

我还尝试了其他几种方式,但我的问题是如何连接到这项服务?

如果我使用bitpay keygen在本地创建api.key文件。如何在bitpay.com上的设置中设置此项以避免{“错误”:“无效令牌”}?

1 个答案:

答案 0 :(得分:0)

此API令牌无效的现实可能性。显示的第一条错误消息表示API令牌的长度太短,因此无效。请确认您输入了正确的API密钥并将其作为字符串输入。您确定在复制和粘贴时没有删除令牌的第一个字符吗?你确定你没有选错标记吗?例如:

var client = new BitPay('MY_192_BIT_HUGE_API_TOKEN'); //192 bit string

致以最诚挚的问候,