BlueWallet/tests/unit/bip38.test.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-08-07 16:39:01 +02:00
import assert from 'assert';
import wif from 'wif';
import bip38 from 'bip38';
2018-07-08 00:01:26 +02:00
jest.setTimeout(180 * 1000);
2018-07-08 00:01:26 +02:00
it('bip38 decodes', async () => {
const encryptedKey = '6PRVWUbkzq2VVjRuv58jpwVjTeN46MeNmzUHqUjQptBJUHGcBakduhrUNc';
2021-08-07 16:39:01 +02:00
const decryptedKey = await bip38.decryptAsync(
2018-07-08 00:01:26 +02:00
encryptedKey,
'TestingOneTwoThree',
() => {},
{ N: 1, r: 8, p: 8 }, // using non-default parameters to speed it up (not-bip38 compliant)
);
2019-01-21 14:55:39 +01:00
assert.strictEqual(
wif.encode(0x80, decryptedKey.privateKey, decryptedKey.compressed),
'5KN7MzqK5wt2TP1fQCYyHBtDrXdJuXbUzm4A9rKAteGu3Qi5CVR',
);
2018-07-08 00:01:26 +02:00
});
2022-04-20 12:24:17 +02:00
// too slow, even on CI. unskip and manually run it if you need it
it.skip('bip38 decodes slow', async () => {
if (!(process.env.CI || process.env.TRAVIS)) {
// run only on CI
2018-07-08 00:05:01 +02:00
return;
2018-07-08 00:01:26 +02:00
}
const encryptedKey = '6PnU5voARjBBykwSddwCdcn6Eu9EcsK24Gs5zWxbJbPZYW7eiYQP8XgKbN';
2020-04-07 16:25:56 +02:00
let callbackWasCalled = false;
2021-08-07 16:39:01 +02:00
const decryptedKey = await bip38.decryptAsync(encryptedKey, 'qwerty', () => {
// callbacks make sense only with pure js scrypt implementation (nodejs and browsers).
// on RN scrypt is handled by native module and takes ~4 secs
2020-04-07 16:25:56 +02:00
callbackWasCalled = true;
});
2021-08-07 16:39:01 +02:00
2020-04-07 16:25:56 +02:00
assert.ok(callbackWasCalled);
2018-07-08 00:01:26 +02:00
2019-01-21 14:55:39 +01:00
assert.strictEqual(
wif.encode(0x80, decryptedKey.privateKey, decryptedKey.compressed),
'KxqRtpd9vFju297ACPKHrGkgXuberTveZPXbRDiQ3MXZycSQYtjc',
);
2021-08-07 16:39:01 +02:00
await assert.rejects(async () => await bip38.decryptAsync(encryptedKey, 'a'), {
message: 'Incorrect passphrase.',
});
2018-07-08 00:01:26 +02:00
});