use base58 encoding for signatures
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-30 17:16:29 +01:00
parent 142e9ec458
commit 612686a224
4 changed files with 2068 additions and 2726 deletions

View File

@ -10,8 +10,21 @@
const crypto = require ('../../index');
// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function, max-statements
describe ('crypto helper', () => {
beforeEach (() => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
});
afterEach (() => {
jasmine.clock ()
.uninstall ();
});
it ('random_hex', () => {
const hex = crypto.random_hex (16);
expect (hex.length)
@ -200,12 +213,6 @@ describe ('crypto helper', () => {
});
it ('should not fail verification if timeout unspecified', () => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
@ -215,18 +222,9 @@ describe ('crypto helper', () => {
const dec = crypto.verify_signature (str, 'baz');
expect (obj)
.toEqual (dec);
jasmine.clock ()
.uninstall ();
});
it ('should reject old signatures', () => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
@ -236,18 +234,9 @@ describe ('crypto helper', () => {
const dec = crypto.verify_signature (str, 'baz', 1);
expect (dec)
.toEqual (null);
jasmine.clock ()
.uninstall ();
});
it ('should not reject valid signatures', () => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
@ -257,18 +246,9 @@ describe ('crypto helper', () => {
const dec = crypto.verify_signature (str, 'baz', 100);
expect (obj)
.toEqual (dec);
jasmine.clock ()
.uninstall ();
});
it ('should verify signature using function retrieved timeout', () => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz', { to: 100 });
@ -278,18 +258,9 @@ describe ('crypto helper', () => {
const dec = crypto.verify_signature (str, 'baz', (info) => info.to);
expect (obj)
.toEqual (dec);
jasmine.clock ()
.uninstall ();
});
it ('verify_signature on almost timed out packet', () => {
jasmine.clock ()
.install ();
const base_time = (new Date);
jasmine.clock ()
.mockDate (base_time);
const obj = { foo: 'bar' };
const str = crypto.sign_object (obj, 'baz');
@ -298,16 +269,29 @@ describe ('crypto helper', () => {
const dec = crypto.verify_signature (str, 'baz', 10);
expect (obj)
.toEqual (dec);
jasmine.clock ()
.uninstall ();
});
it ('should decode problematic token', () => {
// eslint-disable-next-line max-len
// eslint-disable-next-line max-len
const str = 'wEJbzvUywiaiGWZUG6CtCXNkNmRGyVoi9icytpTe4gZhsb8Gk.5PZbhGL525mdV7EmYomTwUei6qULpLaZwSXy92eaUDNgbyXPHsr9dfUCeEBpTqmzuq3VtmmV43epUyWRoHocAsV3.2';
const obj = crypto.decode_signed (str);
expect (obj)
.toEqual ({ id: 1 });
});
it ('should automatically reencode b64 tokens', () => {
// eslint-disable-next-line max-len
const str = 'eyJpYXQiOjE1ODE0NDAwMTIyODgsIm9iaiI6eyJpZCI6MX19.24ZOsWrnfkNe%2FbM0r7DaVJMqE2bfn2aAM%2BZSzWeSf31OCTlXXNWD34RBL2X5v3UliYQ4IIsLNBFbaW9texPHug%3D%3D';
const obj = crypto.decode_signed (str);
expect (obj)
.toEqual ({ id: 1 });
});
it ('verify_signature on b64 string', () => {
// eslint-disable-next-line max-len
const str = 'eyJpYXQiOjE2MDkzNDQ4MDMyMjcsIm9iaiI6eyJpZCI6MX19.N762xuMaNbT%2Fqb0uTKST68BZgSnmNxXaHl4GY7iAKqaDDEwZn3biYfg5DgJ45QgPZrndchczDjUqLkyXoqw4KQ%3D%3D';
const obj = crypto.verify_signature (str, 'baz');
expect (obj)
.toEqual ({ id: 1 });
});
});