Files
common/packages/util-keyring/src/encrypt.spec.js
T
Jaco Greeff 35d2f69b75 Pkcs8 bytes for pairs (non-encrypted) (#111)
* Upgrade dependencies

* Pkcs8 bytes for pairs (non-encrypted)

* Bump minor

* Pass only secretKey around for encoding

* Cleanup seed interface
2018-03-20 15:42:39 +01:00

39 lines
1.1 KiB
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
const u8aFromString = require('@polkadot/util/u8a/fromString');
const u8aConcat = require('@polkadot/util/u8a/concat');
const index = require('./index');
const { PKCS8_DIVIDER, PKCS8_HEADER } = require('./pair/defaults');
describe('encrypt', () => {
const publicKey = new Uint8Array([47, 140, 97, 41, 216, 22, 207, 81, 195, 116, 188, 127, 8, 195, 230, 62, 209, 86, 207, 120, 174, 251, 74, 101, 80, 217, 123, 135, 153, 121, 119, 238]);
const seedOne = u8aFromString('12345678901234567890123456789012');
let keypair;
beforeEach(() => {
keypair = index();
keypair.addFromSeed(seedOne);
});
it('encrypts the key', () => {
expect(
keypair.encrypt(publicKey, 'test')
).toEqual(
u8aConcat(
PKCS8_HEADER, seedOne, PKCS8_DIVIDER, publicKey
)
);
});
it('returns null for non-existing', () => {
expect(
keypair.encrypt(new Uint8Array([]), 'test')
).toEqual(null);
});
});