dark-payment
Advanced tools
Comparing version 0.1.0 to 0.1.1
const crypto = require('asmcrypto.js'); | ||
const axios = require('axios'); | ||
// | ||
const random = (len) => { | ||
const random = len => { | ||
const numbers = Buffer.alloc(len); | ||
@@ -15,11 +15,9 @@ for (let i = 0; i < numbers.length; i += 1) { | ||
const iv = random(12); | ||
const encrypted = crypto.AES_GCM.encrypt( | ||
Buffer.from(content), | ||
Buffer.from(key, 'base64'), | ||
iv, | ||
); | ||
return Buffer.from(JSON.stringify({ | ||
ct: Buffer.from(encrypted, 'hex').toString('base64'), | ||
iv: iv.toString('base64'), | ||
})).toString('base64'); | ||
const encrypted = crypto.AES_GCM.encrypt(Buffer.from(content), Buffer.from(key, 'base64'), iv); | ||
return Buffer.from( | ||
JSON.stringify({ | ||
ct: Buffer.from(encrypted, 'hex').toString('base64'), | ||
iv: iv.toString('base64'), | ||
}) | ||
).toString('base64'); | ||
}; | ||
@@ -30,5 +28,7 @@ | ||
const out = {}; | ||
Object.keys(obj).forEach((key) => { | ||
Object.keys(obj).forEach(key => { | ||
let value = obj[key]; | ||
if (typeof value === 'object' && !(value == null || value === {})) { value = clearEmptyValues(value); } | ||
if (typeof value === 'object' && !(value == null || value === {})) { | ||
value = clearEmptyValues(value); | ||
} | ||
if (typeof value === 'boolean' || typeof value === 'number' || value != null) { | ||
@@ -65,5 +65,6 @@ out[key] = value; | ||
// | ||
const tokenize = ({ | ||
apiAccountId, apiSecretKey, walletId, source, darkApiUrl, darkApiSecretKey, | ||
}, fn) => { | ||
const tokenize = ( | ||
{ apiAccountId, apiSecretKey, walletId, source, darkApiUrl, darkApiSecretKey }, | ||
fn | ||
) => { | ||
const apisignature = encryptByGCM(`${apiAccountId}.${apiSecretKey}`, darkApiSecretKey); | ||
@@ -75,11 +76,16 @@ axios({ | ||
data: source, | ||
}).then((response) => { | ||
const res = response.data; | ||
if (res && fn) { | ||
fn(res.status, source.token); | ||
} | ||
}).catch((err) => { | ||
const message = Object.assign({ data: { message: '' } }, err.response).data.message || err.message; | ||
if (fn) { fn('error', message); } | ||
}); | ||
}) | ||
.then(response => { | ||
const res = response.data; | ||
if (res && fn) { | ||
fn(res.status, source.token); | ||
} | ||
}) | ||
.catch(err => { | ||
const message = | ||
Object.assign({ data: { message: '' } }, err.response).data.message || err.message; | ||
if (fn) { | ||
fn('error', message); | ||
} | ||
}); | ||
}; | ||
@@ -99,3 +105,7 @@ | ||
const p = params[i].split('=', 2); | ||
if (p.length === 1) { out[p[0]] = ''; } else { out[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' ')); } | ||
if (p.length === 1) { | ||
out[p[0]] = ''; | ||
} else { | ||
out[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' ')); | ||
} | ||
} | ||
@@ -109,3 +119,3 @@ return out; | ||
// | ||
const sortList = (obj) => { | ||
const sortList = obj => { | ||
const list = {}; | ||
@@ -121,5 +131,5 @@ const keys = Object.keys(obj).sort(); | ||
// | ||
const makeString = (arr) => { | ||
const makeString = arr => { | ||
let str = ''; | ||
Object.keys(arr).forEach((key) => { | ||
Object.keys(arr).forEach(key => { | ||
str += `${key}=${arr[key]}&`; | ||
@@ -131,5 +141,5 @@ }); | ||
// | ||
const makeArray = (obj) => { | ||
const makeArray = obj => { | ||
const arr = []; | ||
Object.keys(obj).forEach((key) => { | ||
Object.keys(obj).forEach(key => { | ||
arr.push(`${key}=${obj[key]}`); | ||
@@ -144,5 +154,6 @@ }); | ||
// | ||
const getBaseString = options => `${encodeURIComponent(options.type)}&${ | ||
encodeURIComponent(getUrlBase(options.url))}&${ | ||
encodeURIComponent(makeString(sortList(options.params)))}`; | ||
const getBaseString = options => | ||
`${encodeURIComponent(options.type)}&${encodeURIComponent( | ||
getUrlBase(options.url) | ||
)}&${encodeURIComponent(makeString(sortList(options.params)))}`; | ||
@@ -149,0 +160,0 @@ module.exports = { |
{ | ||
"name": "dark-payment", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Provide payment client", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node index.js" | ||
}, | ||
"engines": { | ||
"node": "8.11.0" | ||
}, | ||
"homepage": "https://gitlab.com/darkpos/dark-payment#README", | ||
"repository": { | ||
@@ -16,3 +14,3 @@ "type": "git", | ||
}, | ||
"author": "DarkPOS", | ||
"author": "DarkPOS Dev Team", | ||
"license": "ISC", | ||
@@ -19,0 +17,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
20831
716
1