New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bitwala

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitwala - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.npmignore

158

index.js

@@ -1,1 +0,157 @@

console.log('Hello World');
'use strict';
const request = require('request');
const signing = require('./lib/signing');
const verifications = require('./lib/verifications');
const bitwala = {
client(params) {
const token = params.token;
const env = params.env;
if (!token || !token._id || !token.secret || !env) {
throw 'missing-initialization-parameters';
}
if (env !== 'sandbox' && env !== 'production' && env !== 'dev') {
throw 'incorrect-env';
}
const instance = {
_config: {
token,
env
},
_getSignature(params) {
return signing.getSignature(Object.assign(params, {secret: this._config.token.secret}));
},
_getNonce() {
return new Date().getTime();
},
_call(method, path, data, cb) {
const endpoint = {
dev: 'http://localhost:3000',
sandbox: 'https://sandbox.bitwala.io',
production: 'https://my.bitwala.io'
}[this._config.env] + '/api/v1';
const nonce = this._getNonce();
const options = {
url: endpoint + path,
method: method,
headers: {
'Content-Type': 'application/vnd.api+json',
'x-bitwala-token': this._config.token._id,
'x-bitwala-signature': this._getSignature({method, nonce, url: '/api/v1' + path, data}),
'x-bitwala-nonce': nonce
}
}
if (data) {
if (method === 'GET') {
options.qs = data;
} else if (method === 'POST') {
options.body = JSON.stringify(data);
}
}
if (cb) {
request(options, function(err, res, body) {
try {
body = JSON.parse(body);
if (err) {
return cb(err);
}
if (body.status === 'error') {
return cb(body);
}
if (body.status === 'success') {
return cb(null, body.data);
}
return cb(null, body.data);
} catch (err) {
console.error('Could not parse response');
return cb('Could not parse response');
}
});
} else {
return new Promise(function(resolve, reject) {
request(options, function(err, res, body) {
try {
body = JSON.parse(body);
if (err) {
return reject(err);
}
if (body.status === 'error') {
return reject(body);
}
if (body.status === 'success') {
return resolve(body.data);
}
} catch (err) {
console.log(err);
console.error('Could not parse response');
return reject('Could not parse response');
}
});
});
}
},
info(key, cb) {
let path;
if (typeof key === 'function') {
path = '/info',
cb = key;
} else if (!key) {
path = '/info';
} else if (key === 'inputs') {
path = '/info/inputs';
} else if (key === 'outputs') {
path = '/info/outputs';
} else if (key) {
throw `not-supported`;
}
return instance._call('GET', path, null, cb);
},
auth(cb) {
return instance._call('GET', '/auth', null, cb);
},
transactions: {
get(query, cb) {
return instance._call('GET', '/transactions', query, cb);
},
create(transaction, cb) {
return instance._call('POST', '/transactions', transaction, cb);
},
refresh(query, cb) {
return instance._call('POST', '/transactions/refresh', query, cb);
},
cancel(query, cb) {
return instance._call('POST', '/transactions/cancel', query, cb);
}
}
}
return instance;
},
verifications
}
module.exports = bitwala;

8

package.json
{
"name": "bitwala",
"version": "0.0.1",
"version": "0.0.2",
"description": "Node client for the Bitwala API (docs.bitwala.apiary.io)",

@@ -23,3 +23,7 @@ "main": "index.js",

},
"homepage": "https://github.com/bitwala/api-node-client#readme"
"homepage": "https://github.com/bitwala/api-node-client#readme",
"dependencies": {
"request": "^2.81.0",
"querystring": "^0.2.0"
}
}

@@ -1,2 +0,156 @@

# api-node-client
Node client for the Bitwala API
# API Node Client
Node client for the [Bitwala](https://www.bitwala.io).
For a detailed explanation of our API routes, please [check out the documentation](http://docs.bitwala.apiary.io)
## Quick Start
1. Go to https://my.bitwala.io/api-apps
2. Create an app and store your token ID and secret
3. `yarn add bitwala`
4.
```js
import bitwala from 'bitwala';
const token = {
_id: 'SuBnyc6d564P49Uuls',
secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};
const client = bitwala.client({
token: token,
env: 'sandbox'
});
client.info('inputs')
.then(data => console.log(data))
.catch(err => console.error(err));
/*
[
{
"collection": "BitcoinInvoices",
"currency": "XBT"
}
]
*/
```
## Environments
The client can be initialised with the `sandbox` or `production` env.
For a breakdown of the differences, see our [docs](http://docs.bitwala.apiary.io/#introduction/environments).
## Methods
| Endpoint | Method | Client |
|-----------------|--------|-------------------|
| `/info` | GET | `.info()` |
| `/info/inputs` | GET | `.info('inputs')` |
| `/info/outputs` | GET | `.info('outputs')` |
| `/auth` | GET | `.auth()` |
| `/transactions?page=1`| GET | `.transactions.get({page: 1})` |
| `/transactions?transactionId=transactionId`| GET | `.transactions.get({transactionId: 'YRTvEJxAEm3MB1GI'})` |
| `/transactions?ref=ref`| GET | `.transactions.get({ref: 'YRTvEJxAEm3MB1GI'})` |
| `/transactions`| POST | `.transactions.create(yourTransactionObj})` |
| `/transactions/refresh`| POST | `.transactions.refresh({transactionId: transactionId}})` |
| `/transactions/refresh`| POST | `.transactions.refresh({transactionId: transactionId}})` |
## Promises / Callbacks
All api calls can be used with promises or callbacks.
With callbacks
```js
client.info((e, data) => {
if (e) {
return console.error(e);
}
console.log(data);
})
```
With promises
```js
client.info()
.then(data => console.log(data));
```
With `await` and `async` (if you're using ES7)
```js
(async function () {
let data;
try {
await data = client.info();
} catch (err) {
console.error(err);
}
console.log(data);
})();
```
## Examples
### Get a transaction by `ref`
```js
client.transactions.get({ref: 'My custom id'});
.then(r => console.log(r))
.catch(err => console.log(err));
```
### Create a transfer to Germany
```js
client.transactions.create({
ref: 'My custom id',
webhookUrl: '...', // example: https://test.com/callbacks/bitwala
inputs: [{
collection: 'BitcoinInvoices',
doc: {
currency: 'XBT',
convertedCurrency: 'EUR',
convertedAmount: 100
}
}],
outputs: [{
collection: 'BankTransfers',
doc: {
amount: 100,
currency: 'EUR',
reference: 'January Salary',
bankAccount: {
recipientType: 'INDIVIDUAL',
firstName: 'Satoshi',
lastName: 'Nakamoto',
iban: 'DE89370400440532013000',
currency: 'EUR'
}
}
}]
}).then(r => console.log(r))
.catch(err => console.log(err));
```
### Receive and verify webhooks
```js
import bitwala from 'bitwala';
import express from 'express';
import bodyParser from 'body-parser';
const token = {
_id: 'SuBnyc6d564P49Uuls',
secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};
const router = express.Router();
router.use(bodyParser.json({
limit: '100kb',
type: 'application/*+json'
}));
router.post('/callbacks/bitwala', function (req, res, next) {
// !important: use body-parser
const signatureOk = bitwala.verifications.verifyCallback(req, token.secret);
...
res.success();
});
...
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc