mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-08-15 12:15:36 +00:00
Compare commits
25 Commits
v0.1.0
...
release-it
Author | SHA1 | Date | |
---|---|---|---|
|
fee2aa4681 | ||
|
1f34dcbfb6 | ||
|
3a64d95eb5 | ||
|
926d1bca18 | ||
|
6d601f4186 | ||
|
2d05bf88f9 | ||
|
10e0d602bd | ||
|
eea0a49130 | ||
|
3e95478b3b | ||
|
4496cbf560 | ||
|
0efc46b014 | ||
|
eafe2f9f55 | ||
|
24afdeb257 | ||
|
34051f0a9f | ||
|
14779088f1 | ||
|
aad0bd97c8 | ||
|
429e807994 | ||
|
bb8d1cfaa0 | ||
|
cda36bfcb3 | ||
|
d21d89fb36 | ||
|
df9c330411 | ||
|
2a17ff6056 | ||
|
33ac6ac60f | ||
|
e9f7c11bbb | ||
|
9aabe933e9 |
26
.gitignore
vendored
26
.gitignore
vendored
@@ -1,13 +1,19 @@
|
|||||||
npm-debug.log
|
# mac shit
|
||||||
node_modules
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.local.json5
|
|
||||||
yarn.lock
|
# nyc test coverage
|
||||||
/project.sublime-workspace
|
.nyc_output
|
||||||
/public/css/style.css.map
|
|
||||||
/.idea
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
npm-debug.log
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# vscode
|
||||||
/.vscode
|
/.vscode
|
||||||
*.pid
|
*.pid
|
||||||
/coverage
|
|
||||||
package-lock.json
|
|
||||||
*.html
|
|
||||||
|
39
CHANGELOG.md
Normal file
39
CHANGELOG.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
### Changelog
|
||||||
|
|
||||||
|
#### [v0.1.1](https://github.com/eCollect/node-ebics-client/compare/v0.1.0...v0.1.1)
|
||||||
|
|
||||||
|
> 7 November 2019
|
||||||
|
|
||||||
|
- Closes #17 and #13 [`#21`](https://github.com/eCollect/node-ebics-client/pull/21)
|
||||||
|
- Drop moment dependency [`#20`](https://github.com/eCollect/node-ebics-client/pull/20)
|
||||||
|
|
||||||
|
- feat: add nyc and cleanup .gitignore [`3e95478`](https://github.com/eCollect/node-ebics-client/commit/3e95478b3be719c86f32c7df10c42e46b7518669)
|
||||||
|
- feat: drop bn.js [`eea0a49`](https://github.com/eCollect/node-ebics-client/commit/eea0a49130e30c123b110120c69d7b7c19fd12ba)
|
||||||
|
- feat add BigNumber tests [`0efc46b`](https://github.com/eCollect/node-ebics-client/commit/0efc46b0143cd6deda0e5e748a9da06616a2e55b)
|
||||||
|
|
||||||
|
#### [v0.1.0](https://github.com/eCollect/node-ebics-client/compare/v0.0.4...v0.1.0)
|
||||||
|
|
||||||
|
> 5 November 2019
|
||||||
|
|
||||||
|
- Feat: handle unsual exponent migrate to node-forge [`#16`](https://github.com/eCollect/node-ebics-client/pull/16)
|
||||||
|
- Add order generation tests and fix linting [`#15`](https://github.com/eCollect/node-ebics-client/pull/15)
|
||||||
|
- test script run mocha [`#14`](https://github.com/eCollect/node-ebics-client/pull/14)
|
||||||
|
- chore: readme maintenance [`#11`](https://github.com/eCollect/node-ebics-client/pull/11)
|
||||||
|
- Provide examples [`#10`](https://github.com/eCollect/node-ebics-client/pull/10)
|
||||||
|
- * Add Z53 order type [`#7`](https://github.com/eCollect/node-ebics-client/pull/7)
|
||||||
|
- remove eCollect from constant and minor verbose error handeling [`#2`](https://github.com/eCollect/node-ebics-client/pull/2)
|
||||||
|
- add iso pain format XCT order type [`#1`](https://github.com/eCollect/node-ebics-client/pull/1)
|
||||||
|
- remove eCollect from constant and minor verbose error handaling [`#4`](https://github.com/eCollect/node-ebics-client/pull/4)
|
||||||
|
- add iso pain format XCT order type [`#5`](https://github.com/eCollect/node-ebics-client/pull/5)
|
||||||
|
- Fix parsing of the bank keys in the HPB response [`#3`](https://github.com/eCollect/node-ebics-client/pull/3)
|
||||||
|
|
||||||
|
- feat: prepare order generation tests [`e40f79c`](https://github.com/eCollect/node-ebics-client/commit/e40f79cee68a194272c93f07e763175b213a77a1)
|
||||||
|
- chore: cleanup [`0c01420`](https://github.com/eCollect/node-ebics-client/commit/0c01420c1e14992a4169098ccd47cd196b899f06)
|
||||||
|
|
||||||
|
#### v0.0.4
|
||||||
|
|
||||||
|
> 3 September 2018
|
||||||
|
|
||||||
|
- Major changes. Separating responsibilities. Orders builder, serializer. [`ff9a3a1`](https://github.com/eCollect/node-ebics-client/commit/ff9a3a16b47d0a25674134c875bfd651995837e4)
|
||||||
|
- initial commit [`1f947ff`](https://github.com/eCollect/node-ebics-client/commit/1f947ff1480c522f89fa1f547581b55e2378d920)
|
||||||
|
- code optimization [`1876360`](https://github.com/eCollect/node-ebics-client/commit/187636019c290d757aca77d4c14fb4f2519acd38)
|
12
README.md
12
README.md
@@ -1,6 +1,13 @@
|
|||||||
# node-ebics-client
|
# node-ebics-client
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://travis-ci.org/eCollect/node-ebics-client" title="Build Status"><img src="https://travis-ci.org/eCollect/node-ebics-client.svg?branch=master" alt="Build Status" /></a>
|
<a href="https://travis-ci.org/eCollect/node-ebics-client" title="Build Status"><img src="https://travis-ci.org/eCollect/node-ebics-client.svg?branch=master" alt="Build Status" /></a>
|
||||||
|
<a href="https://www.npmjs.com/package/ebics-client" title="Build Status">
|
||||||
|
<img alt="ebics-client" src="https://img.shields.io/npm/v/ebics-client">
|
||||||
|
</a>
|
||||||
|
<a href="https://snyk.io/test/github/ecollect/node-ebics-client" title="Known Vulnerabilities">
|
||||||
|
<img src="https://snyk.io/test/github/ecollect/node-ebics-client/badge.svg" alt="Known Vulnerabilities">
|
||||||
|
</a>
|
||||||
|
<a href="/eCollect/node-ebics-client/blob/master/LICENSE" title="GPL-3.0"><img alt="GPL-3.0" src="https://img.shields.io/github/license/eCollect/node-ebics-client"></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
Pure node.js ( >=8 ) implementation of [EBICS](https://en.wikipedia.org/wiki/Electronic_Banking_Internet_Communication_Standard) ( Electronic Banking Internet Communication ).
|
Pure node.js ( >=8 ) implementation of [EBICS](https://en.wikipedia.org/wiki/Electronic_Banking_Internet_Communication_Standard) ( Electronic Banking Internet Communication ).
|
||||||
@@ -14,6 +21,7 @@ The client is currently tested and verified to work with the following banks:
|
|||||||
* [Credit Suisse (Schweiz) AG](https://www.credit-suisse.com/ch/en.html)
|
* [Credit Suisse (Schweiz) AG](https://www.credit-suisse.com/ch/en.html)
|
||||||
* [Zürcher Kantonalbank](https://www.zkb.ch/en/lg/ew.html)
|
* [Zürcher Kantonalbank](https://www.zkb.ch/en/lg/ew.html)
|
||||||
* [Raiffeisen Schweiz](https://www.raiffeisen.ch/rch/de.html)
|
* [Raiffeisen Schweiz](https://www.raiffeisen.ch/rch/de.html)
|
||||||
|
* [BW Bank](https://www.bw-bank.de/de/home.html)
|
||||||
|
|
||||||
|
|
||||||
## Inspiration
|
## Inspiration
|
||||||
@@ -23,4 +31,6 @@ The basic concept of this library was inspired by the [EPICS](https://github.com
|
|||||||
|
|
||||||
## Copyright
|
## Copyright
|
||||||
|
|
||||||
Copyright: eCollect AG, 2018-9.
|
Copyright: eCollect AG, 2018-9.
|
||||||
|
Licensed under the [GPLv3](LICENSE) license.
|
||||||
|
|
||||||
|
25
changelog-template.hbs
Normal file
25
changelog-template.hbs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
### Changelog
|
||||||
|
|
||||||
|
{{#each releases}}
|
||||||
|
{{#if href}}
|
||||||
|
###{{#unless major}}#{{/unless}} [{{title}}]({{href}})
|
||||||
|
{{else}}
|
||||||
|
#### {{title}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if tag}}
|
||||||
|
> {{niceDate}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if summary}}
|
||||||
|
{{summary}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#each merges}}
|
||||||
|
- {{message}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}
|
||||||
|
{{/each}}
|
||||||
|
{{#commit-list commits heading='' message='' exclude='wip: '}}
|
||||||
|
- {{#if breaking}}**Breaking change:** {{/if}}{{subject}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
|
||||||
|
{{/commit-list}}
|
||||||
|
|
||||||
|
{{/each}}
|
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const moment = require('moment');
|
|
||||||
const handlebars = require('handlebars');
|
const handlebars = require('handlebars');
|
||||||
const Crypto = require('./crypto/Crypto');
|
const Crypto = require('./crypto/Crypto');
|
||||||
// const BN = require('bn.js');
|
const { date } = require('./utils.js');
|
||||||
|
|
||||||
const registerHelpers = () => {
|
const registerHelpers = () => {
|
||||||
handlebars.registerHelper('today', () => moment().format('DD.MM.YYYY'));
|
handlebars.registerHelper('today', () => date.toISODate(Date.now(), false));
|
||||||
|
|
||||||
handlebars.registerHelper('now', () => moment().format('HH:mm:ss'));
|
handlebars.registerHelper('now', () => date.toISOTime(Date.now(), false));
|
||||||
|
|
||||||
handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(k.e()) * 8);
|
handlebars.registerHelper('keyExponentBits', k => Buffer.byteLength(k.e()) * 8);
|
||||||
|
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const packageJson = require('../package.json');
|
const { version } = require('../package.json');
|
||||||
|
|
||||||
const name = 'Node Ebics Client';
|
const name = 'Node Ebics Client';
|
||||||
const { version } = packageJson;
|
|
||||||
const orderOperations = {
|
const orderOperations = {
|
||||||
ini: 'INI',
|
ini: 'INI',
|
||||||
upload: 'UPLOAD',
|
upload: 'UPLOAD',
|
||||||
|
66
lib/crypto/BigNumber.js
Normal file
66
lib/crypto/BigNumber.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const { jsbn: { BigInteger } } = require('node-forge');
|
||||||
|
|
||||||
|
class BigNumber {
|
||||||
|
constructor(value, radix = 10) {
|
||||||
|
if (value === null || value === undefined)
|
||||||
|
throw new Error('value is missing.');
|
||||||
|
|
||||||
|
this._n = new BigInteger(null);
|
||||||
|
|
||||||
|
if (value instanceof BigNumber)
|
||||||
|
this._n = value._n;
|
||||||
|
else if (value instanceof BigInteger)
|
||||||
|
this._n = value;
|
||||||
|
else if (typeof value === 'number')
|
||||||
|
this._n.fromInt(value);
|
||||||
|
else if (typeof value === 'string')
|
||||||
|
this._n.fromString(value, radix);
|
||||||
|
else if (Buffer.isBuffer(value))
|
||||||
|
this._n.fromString(value.toString('hex'), 16);
|
||||||
|
else if (Array.isArray(value))
|
||||||
|
this._n.fromString(Buffer.from(value).toString('hex'), 16);
|
||||||
|
else
|
||||||
|
throw new TypeError('Unsupported value type.');
|
||||||
|
}
|
||||||
|
|
||||||
|
toBEBuffer(length) {
|
||||||
|
const arr = this._n.toByteArray();
|
||||||
|
if (length === undefined)
|
||||||
|
return Buffer.from(arr);
|
||||||
|
|
||||||
|
if (arr.length > length)
|
||||||
|
throw new Error('Number out of range.');
|
||||||
|
|
||||||
|
while (arr.length < length)
|
||||||
|
arr.unshift(0);
|
||||||
|
|
||||||
|
return Buffer.from(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString(radix = 10) {
|
||||||
|
const result = this._n.toString(radix);
|
||||||
|
if (radix === 16)
|
||||||
|
return result.padStart(2, '0');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
and(num) {
|
||||||
|
return new BigNumber(this._n.and(new BigNumber(num)._n));
|
||||||
|
}
|
||||||
|
|
||||||
|
mul(num) {
|
||||||
|
return new BigNumber(this._n.multiply(new BigNumber(num)._n));
|
||||||
|
}
|
||||||
|
|
||||||
|
mod(num) {
|
||||||
|
return new BigNumber(this._n.mod(new BigNumber(num)._n));
|
||||||
|
}
|
||||||
|
|
||||||
|
shrn(num) {
|
||||||
|
return new BigNumber(this._n.shiftRight(new BigNumber(num)._n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BigNumber;
|
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
const BN = require('bn.js');
|
const BigNumber = require('./BigNumber.js');
|
||||||
|
|
||||||
const mgf1 = require('./MGF1');
|
const mgf1 = require('./MGF1');
|
||||||
|
|
||||||
const modPow = (base, power, mod) => {
|
const modPow = (base, power, mod) => {
|
||||||
let result = new BN(1);
|
let result = new BigNumber(1);
|
||||||
|
|
||||||
while (power > 0) {
|
while (power > 0) {
|
||||||
result = power.and(new BN(1)) == 1 ? (result.mul(base)).mod(mod) : result; // eslint-disable-line
|
result = power.and(new BigNumber(1)) == 1 ? (result.mul(base)).mod(mod) : result; // eslint-disable-line
|
||||||
base = (base.mul(base)).mod(mod);
|
base = (base.mul(base)).mod(mod);
|
||||||
power = power.shrn(1);
|
power = power.shrn(1);
|
||||||
}
|
}
|
||||||
@@ -28,10 +27,13 @@ const emsaPSS = (msg, salt) => {
|
|||||||
const dbMask = mgf1.generate(mTickHash, db.length);
|
const dbMask = mgf1.generate(mTickHash, db.length);
|
||||||
const maskedDb = mgf1.xor(db, dbMask);
|
const maskedDb = mgf1.xor(db, dbMask);
|
||||||
|
|
||||||
let maskedDbMsb = mgf1.rjust(new BN(maskedDb.slice(0, 1), 2).toString(2), 8, '0');
|
let maskedDbMsb = mgf1.rjust(new BigNumber(maskedDb.slice(0, 1)).toString(2), 8, '0');
|
||||||
|
|
||||||
|
|
||||||
maskedDbMsb = `0${maskedDbMsb.substr(1)}`;
|
maskedDbMsb = `0${maskedDbMsb.substr(1)}`;
|
||||||
maskedDb[0] = (new BN(maskedDbMsb, 2).toBuffer())[0]; // eslint-disable-line
|
// console.log((new BN(maskedDbMsb, 2).toBuffer())[0], new BigNumber(maskedDbMsb, 2).toBuffer()[0]);
|
||||||
|
// maskedDb[0] = (new BN(maskedDbMsb, 2).toBuffer())[0]; // eslint-disable-line
|
||||||
|
maskedDb[0] = new BigNumber(maskedDbMsb, 2).toBEBuffer()[0]; // eslint-disable-line
|
||||||
|
|
||||||
return Buffer.concat([maskedDb, mTickHash, Buffer.from('BC', 'hex')]);
|
return Buffer.concat([maskedDb, mTickHash, Buffer.from('BC', 'hex')]);
|
||||||
};
|
};
|
||||||
@@ -65,11 +67,12 @@ module.exports = class Crypto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static sign(key, msg, salt = crypto.randomBytes(32)) {
|
static sign(key, msg, salt = crypto.randomBytes(32)) {
|
||||||
const base = new BN(emsaPSS(msg, salt));
|
// console.log(key.d());
|
||||||
const power = new BN(key.d());
|
const base = new BigNumber(emsaPSS(msg, salt));
|
||||||
const mod = new BN(key.n());
|
const power = new BigNumber(key.d());
|
||||||
|
const mod = new BigNumber(key.n());
|
||||||
|
|
||||||
return (modPow(base, power, mod)).toBuffer().toString('base64');
|
return (modPow(base, power, mod)).toBEBuffer().toString('base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
static pad(d) {
|
static pad(d) {
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const BN = require('bn.js');
|
|
||||||
|
const BigNumber = require('./BigNumber.js');
|
||||||
|
|
||||||
const MFG_LEN = 32;
|
const MFG_LEN = 32;
|
||||||
|
|
||||||
const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise
|
const divceil = (a, b) => ~~(((a + b) - 1) / b); // eslint-disable-line no-bitwise
|
||||||
const rjust = (string, width, padding) => {
|
const rjust = (string, width, padding = ' ') => {
|
||||||
padding = padding || ' ';
|
|
||||||
padding = padding.substr(0, 1);
|
padding = padding.substr(0, 1);
|
||||||
if (string.length < width)
|
if (string.length < width)
|
||||||
return padding.repeat(width - string.length) + string;
|
return padding.repeat(width - string.length) + string;
|
||||||
@@ -26,7 +26,7 @@ const i2osp = (x, len) => {
|
|||||||
if (x >= 256 ** len)
|
if (x >= 256 ** len)
|
||||||
throw new Error('Integer too large');
|
throw new Error('Integer too large');
|
||||||
|
|
||||||
return Buffer.from(rjust((Buffer.from((new BN(x)).toArray('be', 4)).toString()).replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex
|
return Buffer.from(rjust(new BigNumber(x).toBEBuffer(4).toString().replace(/\x00/gi, ''), len, '\x00')); // eslint-disable-line no-control-regex
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
34
lib/utils.js
34
lib/utils.js
@@ -1,18 +1,46 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const prefixNumber = (n) => {
|
||||||
|
if (n < 10)
|
||||||
|
return `0${n}`;
|
||||||
|
return n.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
const date = {
|
||||||
|
getDateObject(d = Date.now()) {
|
||||||
|
const dateObject = new Date(d);
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
if (isNaN(dateObject))
|
||||||
|
throw new Error(`${d} is invalid date.`);
|
||||||
|
return dateObject;
|
||||||
|
},
|
||||||
|
toISODate(d = Date.now(), utc = true) {
|
||||||
|
const t = date.getDateObject(d);
|
||||||
|
if (utc)
|
||||||
|
return `${t.getUTCFullYear()}-${prefixNumber(t.getUTCMonth() + 1)}-${prefixNumber(t.getUTCDate())}`;
|
||||||
|
return `${t.getFullYear()}-${prefixNumber(t.getMonth() + 1)}-${prefixNumber(t.getDate())}`;
|
||||||
|
},
|
||||||
|
toISOTime(d = Date.now(), utc = true) {
|
||||||
|
const t = date.getDateObject(d);
|
||||||
|
if (utc)
|
||||||
|
return `${prefixNumber(t.getUTCHours())}:${prefixNumber(t.getUTCMinutes())}:${prefixNumber(t.getUTCSeconds())}`;
|
||||||
|
return `${prefixNumber(t.getHours())}:${prefixNumber(t.getMinutes())}:${prefixNumber(t.getSeconds())}`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const dateRange = (start, end) => {
|
const dateRange = (start, end) => {
|
||||||
if (start && end)
|
if (start && end)
|
||||||
return {
|
return {
|
||||||
DateRange: {
|
DateRange: {
|
||||||
Start: start,
|
Start: date.toISODate(start),
|
||||||
End: end,
|
End: date.toISODate(end),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dateRange,
|
dateRange,
|
||||||
|
date,
|
||||||
};
|
};
|
||||||
|
3813
package-lock.json
generated
Normal file
3813
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ebics-client",
|
"name": "ebics-client",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Node.js ISO 20022 Compliant EBICS Client",
|
"description": "Node.js ISO 20022 Compliant EBICS Client",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"test": "mocha test/**/*.js"
|
"test": "nyc mocha test/**/*.js",
|
||||||
|
"version": "auto-changelog -p && git add CHANGELOG.md",
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -15,10 +16,21 @@
|
|||||||
"EBICS",
|
"EBICS",
|
||||||
"ISO20022",
|
"ISO20022",
|
||||||
"nodejs",
|
"nodejs",
|
||||||
"api"
|
"api",
|
||||||
|
"banking"
|
||||||
],
|
],
|
||||||
"author": "eCollect Sofia Tech Team",
|
"author": "eCollect Sofia Tech Team",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Dimitar Nanov",
|
||||||
|
"url": "https://nanov.io",
|
||||||
|
"email": "dimitar@nanov.io"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Vladislav Hristov",
|
||||||
|
"url": "https://github.com/vladhristov",
|
||||||
|
"email": "vlad.s.ch@gmail.com"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Vasyl Stashuk",
|
"name": "Vasyl Stashuk",
|
||||||
"url": "https://github.com/vasyas"
|
"url": "https://github.com/vasyas"
|
||||||
@@ -28,12 +40,11 @@
|
|||||||
"url": "https://github.com/yagop"
|
"url": "https://github.com/yagop"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bn.js": "^5.0.0",
|
"auto-changelog": "^1.16.2",
|
||||||
"handlebars": "^4.4.3",
|
"handlebars": "^4.4.3",
|
||||||
"js2xmlparser": "^4.0.0",
|
"js2xmlparser": "^4.0.0",
|
||||||
"moment": "^2.24.0",
|
|
||||||
"node-forge": "^0.9.1",
|
"node-forge": "^0.9.1",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"uuid": "^3.3.3",
|
"uuid": "^3.3.3",
|
||||||
@@ -47,6 +58,7 @@
|
|||||||
"eslint-config-ecollect-base": "^0.1.2",
|
"eslint-config-ecollect-base": "^0.1.2",
|
||||||
"eslint-plugin-import": "^2.18.2",
|
"eslint-plugin-import": "^2.18.2",
|
||||||
"libxmljs": "^0.19.7",
|
"libxmljs": "^0.19.7",
|
||||||
"mocha": "^6.2.2"
|
"mocha": "^6.2.2",
|
||||||
|
"nyc": "^14.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
test/unit/BigNumber.js
Normal file
47
test/unit/BigNumber.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-env node, mocha */
|
||||||
|
|
||||||
|
const { assert } = require('chai');
|
||||||
|
const { jsbn: { BigInteger } } = require('node-forge');
|
||||||
|
|
||||||
|
const BigNumber = require('../../lib/crypto/BigNumber');
|
||||||
|
|
||||||
|
const types = [
|
||||||
|
{ name: 'BigNumber', value: new BigNumber(11) },
|
||||||
|
{ name: 'BigInteger', value: new BigInteger('11') },
|
||||||
|
{ name: 'string with default radix', value: '11' },
|
||||||
|
{ name: 'string with radix 16', value: '0b', radix: 16 },
|
||||||
|
{ name: 'Buffer', value: Buffer.from('0b', 'hex') },
|
||||||
|
{ name: 'Array', value: [11] },
|
||||||
|
];
|
||||||
|
|
||||||
|
describe('BigNumber', () => {
|
||||||
|
describe('creating an instance', () => {
|
||||||
|
it('should throw with no value given', () => assert.throws(() => new BigNumber()));
|
||||||
|
it('should throw wrong value type', () => assert.throws(() => new BigNumber({})));
|
||||||
|
|
||||||
|
for (const { name, value, radix } of types) {
|
||||||
|
let instance;
|
||||||
|
describe(`out of ${name}`, () => {
|
||||||
|
it('create instance', () => assert.doesNotThrow(() => {
|
||||||
|
instance = new BigNumber(value, radix);
|
||||||
|
}));
|
||||||
|
it('toString with radix 10', () => assert.equal(instance.toString(), '11'));
|
||||||
|
it('toString with radix 16', () => assert.equal(instance.toString(16), '0b'));
|
||||||
|
it('toBEBuffer without length', () => assert.equal(instance.toBEBuffer().toString('hex'), '0b'));
|
||||||
|
it('toBEBuffer with length', () => assert.equal(instance.toBEBuffer(4).toString('hex'), '0000000b'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
describe('exports', () => {
|
||||||
|
it('toBEBuffer with too short length should throw', () => assert.throw(() => new BigNumber(837462187362).toBEBuffer(1)));
|
||||||
|
});
|
||||||
|
describe('operators', () => {
|
||||||
|
const num = new BigNumber(1);
|
||||||
|
it('and', () => assert.equal(num.and(1), 1));
|
||||||
|
it('mul', () => assert.equal(num.mul(2), 2));
|
||||||
|
it('mod', () => assert.equal(num.mod(1), 0));
|
||||||
|
it('shrn', () => assert.equal(num.shrn(1), 0));
|
||||||
|
});
|
||||||
|
});
|
29
test/unit/utils.js
Normal file
29
test/unit/utils.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-env node, mocha */
|
||||||
|
|
||||||
|
const { assert } = require('chai');
|
||||||
|
|
||||||
|
const utils = require('../../lib/utils');
|
||||||
|
|
||||||
|
describe('utils', () => {
|
||||||
|
describe('dateRange', () => {
|
||||||
|
describe('dateRange', () => {
|
||||||
|
it('should generate empty object with partial parameters', () => {
|
||||||
|
assert.isEmpty(utils.dateRange());
|
||||||
|
});
|
||||||
|
it('should throw with invalid date', () => {
|
||||||
|
assert.throws(() => utils.dateRange('2018-15-15', '2018-20-20'));
|
||||||
|
});
|
||||||
|
it('should work for valid string input', () => {
|
||||||
|
assert.containsAllDeepKeys(utils.dateRange('2018-01-15', '2018-01-20'), { DateRange: { Start: '2018-01-15', End: '2018-01-20' } });
|
||||||
|
});
|
||||||
|
it('should work for Date string input', () => {
|
||||||
|
assert.containsAllDeepKeys(utils.dateRange(new Date('2018-01-15'), new Date('2018-01-20')), { DateRange: { Start: '2018-01-15', End: '2018-01-20' } });
|
||||||
|
});
|
||||||
|
it('should work for timestamp string input', () => {
|
||||||
|
assert.containsAllDeepKeys(utils.dateRange(new Date('2018-01-15').getTime(), new Date('2018-01-20').getTime()), { DateRange: { Start: '2018-01-15', End: '2018-01-20' } });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user