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
This commit is contained in:
+1
-1
@@ -10,5 +10,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "0.17.4"
|
||||
"version": "0.18.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-crypto",
|
||||
"version": "0.17.4",
|
||||
"version": "0.18.0",
|
||||
"description": "A collection of useful crypto utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
|
||||
@@ -6,38 +6,18 @@
|
||||
import type { KeypairType } from '../../types';
|
||||
|
||||
const nacl = require('tweetnacl');
|
||||
const hexToU8a = require('@polkadot/util/hex/toU8a');
|
||||
const isHex = require('@polkadot/util/is/hex');
|
||||
const isU8a = require('@polkadot/util/is/u8a');
|
||||
const u8aFromString = require('@polkadot/util/u8a/fromString');
|
||||
|
||||
/**
|
||||
@name naclKeypairFromSeed
|
||||
@signature naclKeypairFromSeed (seed: Uint8Array | string): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@signature naclKeypairFromSeed (seed: Uint8Array): { secretKey: Uint8Array, publicKey: Uint8Array }
|
||||
@summary Creates a new public/secret keypair from a seed.
|
||||
@description
|
||||
Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed. Seed can be a `Uint8Array`, a hex string or a string of bytes.
|
||||
Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
|
||||
@example
|
||||
import { naclKeypairFromSeed } from '@polkadot/util-crypto';
|
||||
|
||||
naclKeypairFromSeed(...) // => { secretKey: [...], publicKey: [...] }
|
||||
*/
|
||||
module.exports = function naclKeypairFromSeed (seed: Uint8Array | string): KeypairType {
|
||||
if (isU8a(seed)) {
|
||||
// $FlowFixMe type has been determined
|
||||
return nacl.sign.keyPair.fromSeed(seed);
|
||||
}
|
||||
|
||||
// $FlowFixMe type has been determined
|
||||
if (isHex(seed)) {
|
||||
return nacl.sign.keyPair.fromSeed(
|
||||
// $FlowFixMe type has been determined
|
||||
hexToU8a(seed)
|
||||
);
|
||||
}
|
||||
|
||||
return nacl.sign.keyPair.fromSeed(
|
||||
// $FlowFixMe type has been determined
|
||||
u8aFromString(seed)
|
||||
);
|
||||
module.exports = function naclKeypairFromSeed (seed: Uint8Array): KeypairType {
|
||||
return nacl.sign.keyPair.fromSeed(seed);
|
||||
};
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const u8aFromString = require('@polkadot/util/u8a/fromString');
|
||||
const u8aToHex = require('@polkadot/util/u8a/toHex');
|
||||
|
||||
const { naclKeypairFromSeed } = require('../index');
|
||||
|
||||
describe('naclKeypairFromSeed', () => {
|
||||
// NOTE: Aligned with Rust test, b"12345678901234567890123456789012"
|
||||
const TEST = '12345678901234567890123456789012';
|
||||
const TEST = u8aFromString('12345678901234567890123456789012');
|
||||
const RESULT = {
|
||||
publicKey: new Uint8Array([
|
||||
0x2f, 0x8c, 0x61, 0x29, 0xd8, 0x16, 0xcf, 0x51,
|
||||
@@ -27,27 +26,9 @@ describe('naclKeypairFromSeed', () => {
|
||||
])
|
||||
};
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (string)', () => {
|
||||
it('generates a valid publicKey/secretKey pair (u8a)', () => {
|
||||
expect(
|
||||
naclKeypairFromSeed(TEST)
|
||||
).toEqual(RESULT);
|
||||
});
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (u8a)', () => {
|
||||
expect(
|
||||
naclKeypairFromSeed(
|
||||
u8aFromString(TEST)
|
||||
)
|
||||
).toEqual(RESULT);
|
||||
});
|
||||
|
||||
it('generates a valid publicKey/secretKey pair (hex)', () => {
|
||||
expect(
|
||||
naclKeypairFromSeed(
|
||||
u8aToHex(
|
||||
u8aFromString(TEST)
|
||||
)
|
||||
)
|
||||
).toEqual(RESULT);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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 { naclSign, naclKeypairFromSeed } = require('./index');
|
||||
|
||||
describe('naclSign', () => {
|
||||
@@ -9,7 +11,7 @@ describe('naclSign', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
secretKey = naclKeypairFromSeed(
|
||||
'12345678901234567890123456789012'
|
||||
u8aFromString('12345678901234567890123456789012')
|
||||
).secretKey;
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// 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 { naclVerify, naclKeypairFromSeed } = require('./index');
|
||||
|
||||
describe('naclSign', () => {
|
||||
@@ -10,7 +12,7 @@ describe('naclSign', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
publicKey = naclKeypairFromSeed(
|
||||
'12345678901234567890123456789012'
|
||||
u8aFromString('12345678901234567890123456789012')
|
||||
).publicKey;
|
||||
signature = new Uint8Array([28, 58, 206, 239, 249, 70, 59, 191, 166, 40, 219, 218, 235, 170, 25, 79, 10, 94, 9, 197, 34, 126, 1, 150, 246, 68, 28, 238, 36, 26, 172, 163, 168, 90, 202, 211, 126, 246, 57, 212, 43, 24, 88, 197, 240, 113, 118, 76, 37, 81, 91, 110, 236, 50, 144, 134, 100, 223, 220, 238, 34, 185, 211, 7]);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-keyring",
|
||||
"version": "0.17.4",
|
||||
"version": "0.18.0",
|
||||
"description": "Keyring management",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
@@ -31,8 +31,8 @@
|
||||
"test": "echo \"Tests only available from root wrapper\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.17.4",
|
||||
"@polkadot/util-crypto": "^0.17.4",
|
||||
"@polkadot/util": "^0.18.0",
|
||||
"@polkadot/util-crypto": "^0.18.0",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { KeyringPairEncrypted, KeyringPair } from './types';
|
||||
import type { KeyringPair } from './types';
|
||||
|
||||
const createPair = require('./pair');
|
||||
|
||||
module.exports = function decrypt (box: KeyringPairEncrypted, secret: Uint8Array | string): KeyringPair {
|
||||
module.exports = function decrypt (encoded: Uint8Array, passphrase: Uint8Array | string): KeyringPair {
|
||||
const pair = createPair({
|
||||
publicKey: box.publicKey,
|
||||
secretKey: new Uint8Array([])
|
||||
publicKey: new Uint8Array(32),
|
||||
secretKey: new Uint8Array(64)
|
||||
});
|
||||
|
||||
pair.decryptSelf(box, secret);
|
||||
pair.decodePkcs8(encoded, passphrase);
|
||||
|
||||
return pair;
|
||||
};
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
// 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 index = require('./index');
|
||||
|
||||
describe('decrypt', () => {
|
||||
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 = '12345678901234567890123456789012';
|
||||
const seedOne = u8aFromString('12345678901234567890123456789012');
|
||||
let keypair;
|
||||
let encrypted;
|
||||
|
||||
@@ -21,9 +23,7 @@ describe('decrypt', () => {
|
||||
|
||||
it('decrypts a previously encrypted', () => {
|
||||
expect(
|
||||
keypair.decrypt(encrypted, 'test')
|
||||
).toMatchObject({
|
||||
publicKey
|
||||
});
|
||||
keypair.decrypt(encrypted, 'test').publicKey()
|
||||
).toEqual(publicKey);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { KeyringPairEncrypted, KeyringPair } from './types';
|
||||
import type { KeyringPair } from './types';
|
||||
|
||||
module.exports = function encrypt (pair: ?KeyringPair, secret: Uint8Array | string): ?KeyringPairEncrypted {
|
||||
module.exports = function encrypt (pair: ?KeyringPair, passphrase: Uint8Array | string): ?Uint8Array {
|
||||
if (!pair) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return pair.encryptSelf(secret);
|
||||
return pair.encodePkcs8(passphrase);
|
||||
};
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
// 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 = '12345678901234567890123456789012';
|
||||
const seedOne = u8aFromString('12345678901234567890123456789012');
|
||||
let keypair;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -17,8 +22,12 @@ describe('encrypt', () => {
|
||||
|
||||
it('encrypts the key', () => {
|
||||
expect(
|
||||
keypair.encrypt(publicKey, 'test').publicKey
|
||||
).toEqual(publicKey);
|
||||
keypair.encrypt(publicKey, 'test')
|
||||
).toEqual(
|
||||
u8aConcat(
|
||||
PKCS8_HEADER, seedOne, PKCS8_DIVIDER, publicKey
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it('returns null for non-existing', () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { KeyringPairEncrypted, KeyringInstance, KeyringPair } from './types';
|
||||
import type { KeyringInstance, KeyringPair } from './types';
|
||||
|
||||
const naclKeypairFromSeed = require('@polkadot/util-crypto/nacl/keypair/fromSeed');
|
||||
|
||||
@@ -16,16 +16,16 @@ module.exports = function keyring (): KeyringInstance {
|
||||
const pairs = createPairs();
|
||||
|
||||
return {
|
||||
addFromSeed: (seed: Uint8Array | string): KeyringPair =>
|
||||
addFromSeed: (seed: Uint8Array): KeyringPair =>
|
||||
pairs.add(createPair(naclKeypairFromSeed(seed))),
|
||||
decrypt: (encrypted: KeyringPairEncrypted, secret: Uint8Array | string): KeyringPair =>
|
||||
pairs.add(decrypt(encrypted, secret)),
|
||||
encrypt: (publicKey: Uint8Array, secret: Uint8Array | string): ?KeyringPairEncrypted =>
|
||||
encrypt(pairs.get(publicKey), secret),
|
||||
decrypt: (encrypted: Uint8Array, passphrase: Uint8Array | string): KeyringPair =>
|
||||
pairs.add(decrypt(encrypted, passphrase)),
|
||||
encrypt: (publicKey: Uint8Array, passphrase: Uint8Array | string): ?Uint8Array =>
|
||||
encrypt(pairs.get(publicKey), passphrase),
|
||||
getPair: (publicKey: Uint8Array): ?KeyringPair =>
|
||||
pairs.get(publicKey),
|
||||
getPairs: pairs.all,
|
||||
getPublicKeys: (): Array<Uint8Array> =>
|
||||
pairs.all().map(({ publicKey }) => publicKey)
|
||||
pairs.all().map(({ publicKey }) => publicKey())
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
const hexToU8a = require('@polkadot/util/hex/toU8a');
|
||||
const u8aFromString = require('@polkadot/util/u8a/fromString');
|
||||
|
||||
const index = require('./index');
|
||||
|
||||
describe('keypair', () => {
|
||||
const publicKeyOne = 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 publicKeyTwo = new Uint8Array([215, 90, 152, 1, 130, 177, 10, 183, 213, 75, 254, 211, 201, 100, 7, 58, 14, 225, 114, 243, 218, 166, 35, 37, 175, 2, 26, 104, 247, 7, 81, 26]);
|
||||
const seedOne = '12345678901234567890123456789012';
|
||||
const seedTwo = '0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60';
|
||||
const seedOne = u8aFromString('12345678901234567890123456789012');
|
||||
const seedTwo = hexToU8a('0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60');
|
||||
let keypair;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -19,10 +22,8 @@ describe('keypair', () => {
|
||||
|
||||
it('adds the pair', () => {
|
||||
expect(
|
||||
keypair.addFromSeed(seedTwo)
|
||||
).toMatchObject({
|
||||
publicKey: publicKeyTwo
|
||||
});
|
||||
keypair.addFromSeed(seedTwo).publicKey()
|
||||
).toEqual(publicKeyTwo);
|
||||
});
|
||||
|
||||
it('allows publicKeys retrieval', () => {
|
||||
@@ -35,9 +36,7 @@ describe('keypair', () => {
|
||||
|
||||
it('allows retrieval of a specific item', () => {
|
||||
expect(
|
||||
keypair.getPair(publicKeyOne)
|
||||
).toMatchObject({
|
||||
publicKey: publicKeyOne
|
||||
});
|
||||
keypair.getPair(publicKeyOne).publicKey()
|
||||
).toEqual(publicKeyOne);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
// @flow
|
||||
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
const { PKCS8_DIVIDER, PKCS8_HEADER } = require('./defaults');
|
||||
|
||||
const KEY_LENGTH = 32;
|
||||
const SEED_OFFSET = PKCS8_HEADER.length;
|
||||
const PUBLIC_OFFSET = SEED_OFFSET + KEY_LENGTH + PKCS8_DIVIDER.length;
|
||||
|
||||
module.exports = function decode (encoded: Uint8Array, passphrase?: Uint8Array | string) {
|
||||
// TODO: decrypt using passphrase
|
||||
const publicKey = encoded.subarray(PUBLIC_OFFSET, PUBLIC_OFFSET + KEY_LENGTH);
|
||||
const seed = encoded.subarray(SEED_OFFSET, SEED_OFFSET + KEY_LENGTH);
|
||||
|
||||
return {
|
||||
publicKey,
|
||||
secretKey: u8aConcat(seed, publicKey)
|
||||
};
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
// 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.
|
||||
// @flow
|
||||
|
||||
import type { KeyringPairEncrypted } from '../types';
|
||||
|
||||
const kdf = require('@polkadot/util-crypto/kdf/asU8a');
|
||||
const naclDecrypt = require('@polkadot/util-crypto/nacl/decrypt');
|
||||
const assert = require('@polkadot/util/assert');
|
||||
|
||||
module.exports = function decrypt ({ crypto: { params: { nonce }, kdf: { rounds, salt }, text } }: KeyringPairEncrypted, secret: Uint8Array | string): Uint8Array {
|
||||
const { key } = kdf(secret, rounds, salt);
|
||||
const secretKey = naclDecrypt(text, key, nonce);
|
||||
|
||||
assert(secretKey, 'Unable to decrypt pair using secret');
|
||||
|
||||
// $FlowFixMe checking for type just above
|
||||
return ((secretKey: any): Uint8Array);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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.
|
||||
// @flow
|
||||
|
||||
const PKCS8_DIVIDER = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
const PKCS8_HEADER = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
|
||||
module.exports = {
|
||||
PKCS8_DIVIDER,
|
||||
PKCS8_HEADER
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
// @flow
|
||||
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
const { PKCS8_DIVIDER, PKCS8_HEADER } = require('./defaults');
|
||||
|
||||
module.exports = function encode (secretKey: Uint8Array, passphrase?: Uint8Array | string): Uint8Array {
|
||||
// TODO: encrypt using passphrase
|
||||
|
||||
return u8aConcat(
|
||||
PKCS8_HEADER,
|
||||
secretKey.subarray(0, 32),
|
||||
PKCS8_DIVIDER,
|
||||
secretKey.subarray(32, 64)
|
||||
);
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
// 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.
|
||||
// @flow
|
||||
|
||||
import type { KeyringPairEncrypted } from '../types';
|
||||
|
||||
const kdf = require('@polkadot/util-crypto/kdf/asU8a');
|
||||
const naclEncrypt = require('@polkadot/util-crypto/nacl/encrypt');
|
||||
|
||||
module.exports = function encrypt (message: Uint8Array, secret: Uint8Array | string, publicKey: Uint8Array): KeyringPairEncrypted {
|
||||
const { key, rounds, salt } = kdf(secret);
|
||||
const { encrypted, nonce } = naclEncrypt(message, key);
|
||||
|
||||
return {
|
||||
crypto: {
|
||||
params: {
|
||||
nonce
|
||||
},
|
||||
kdf: {
|
||||
rounds,
|
||||
salt
|
||||
},
|
||||
text: encrypted
|
||||
},
|
||||
publicKey
|
||||
};
|
||||
};
|
||||
@@ -4,22 +4,40 @@
|
||||
// @flow
|
||||
|
||||
import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { KeyringPairEncrypted, KeyringPair } from '../types';
|
||||
import type { KeyringPair } from '../types';
|
||||
|
||||
const naclFromSeed = require('@polkadot/util-crypto/nacl/keypair/fromSeed');
|
||||
const naclSign = require('@polkadot/util-crypto/nacl/sign');
|
||||
const naclVerify = require('@polkadot/util-crypto/nacl/verify');
|
||||
const assert = require('@polkadot/util/assert');
|
||||
|
||||
const decrypt = require('./decrypt');
|
||||
const encrypt = require('./encrypt');
|
||||
const decode = require('./decode');
|
||||
const encode = require('./encode');
|
||||
|
||||
function decodePkcs8 (encoded: Uint8Array, passphrase?: Uint8Array | string) {
|
||||
const { publicKey, secretKey } = decode(encoded, passphrase);
|
||||
const validate = naclFromSeed(secretKey.subarray(0, 32));
|
||||
|
||||
assert(validate.publicKey.toString() === publicKey.toString(), 'Pkcs8 decoded keys are not matching');
|
||||
|
||||
return {
|
||||
publicKey,
|
||||
secretKey
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = function pair ({ publicKey, secretKey }: KeypairType): KeyringPair {
|
||||
return {
|
||||
publicKey,
|
||||
decryptSelf: (encrypted: KeyringPairEncrypted, secret: Uint8Array | string): void => {
|
||||
secretKey = decrypt(encrypted, secret);
|
||||
decodePkcs8: (encoded: Uint8Array, passphrase?: Uint8Array | string): void => {
|
||||
const decoded = decodePkcs8(encoded, passphrase);
|
||||
|
||||
publicKey = decoded.publicKey;
|
||||
secretKey = decoded.secretKey;
|
||||
},
|
||||
encryptSelf: (secret: Uint8Array | string): KeyringPairEncrypted =>
|
||||
encrypt(secretKey, secret, publicKey),
|
||||
encodePkcs8: (passphrase?: Uint8Array | string): Uint8Array =>
|
||||
encode(secretKey, passphrase),
|
||||
publicKey: (): Uint8Array =>
|
||||
publicKey,
|
||||
sign: (message: Uint8Array): Uint8Array =>
|
||||
naclSign(message, secretKey),
|
||||
verify: (message: Uint8Array, signature: Uint8Array): boolean =>
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('pair', () => {
|
||||
|
||||
it('has a publicKey', () => {
|
||||
expect(
|
||||
keyring.one.publicKey
|
||||
keyring.one.publicKey()
|
||||
).toEqual(
|
||||
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])
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ module.exports = function pairs (): KeyringPairs {
|
||||
|
||||
return {
|
||||
add: (pair: KeyringPair): KeyringPair => {
|
||||
self[pair.publicKey] = pair;
|
||||
self[pair.publicKey()] = pair;
|
||||
|
||||
return pair;
|
||||
},
|
||||
|
||||
@@ -9,12 +9,17 @@ type TestKeyring = {
|
||||
[string]: KeyringPair
|
||||
};
|
||||
|
||||
const hexToU8a = require('@polkadot/util/hex/toU8a');
|
||||
const u8aFromString = require('@polkadot/util/u8a/fromString');
|
||||
|
||||
const createKeyring = require('./index');
|
||||
|
||||
function padSeed (seed: string): string {
|
||||
return seed.length < 32
|
||||
? padSeed(`${seed} `)
|
||||
: seed;
|
||||
function padSeed (seed: string): Uint8Array {
|
||||
while (seed.length < 32) {
|
||||
seed += ' ';
|
||||
}
|
||||
|
||||
return u8aFromString(seed);
|
||||
}
|
||||
|
||||
const SEEDS = {
|
||||
@@ -31,9 +36,9 @@ const SEEDS = {
|
||||
ferdie:
|
||||
padSeed('Ferdie'),
|
||||
one:
|
||||
'12345678901234567890123456789012',
|
||||
padSeed('12345678901234567890123456789012'),
|
||||
two:
|
||||
'0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60'
|
||||
hexToU8a('0x9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60')
|
||||
};
|
||||
|
||||
module.exports = function testKeyring (): TestKeyring {
|
||||
|
||||
@@ -3,27 +3,10 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
export type KeyringPairEncrypted$Cipher = 'xsalsa20-poly1305';
|
||||
|
||||
export type KeyringPairEncrypted = {
|
||||
crypto: {
|
||||
params: {
|
||||
nonce: Uint8Array
|
||||
},
|
||||
kdf: {
|
||||
rounds: number,
|
||||
salt: Uint8Array
|
||||
},
|
||||
text: Uint8Array
|
||||
},
|
||||
publicKey: Uint8Array
|
||||
};
|
||||
|
||||
export type KeyringPair = {
|
||||
publicKey: Uint8Array,
|
||||
|
||||
decryptSelf: (box: KeyringPairEncrypted, secret: Uint8Array | string) => void,
|
||||
encryptSelf: (secret: Uint8Array | string) => KeyringPairEncrypted,
|
||||
decodePkcs8: (encoded: Uint8Array, passphrase: Uint8Array | string) => void,
|
||||
encodePkcs8: (passphrase: Uint8Array | string) => Uint8Array,
|
||||
publicKey: () => Uint8Array,
|
||||
sign (message: Uint8Array): Uint8Array,
|
||||
verify (message: Uint8Array, signature: Uint8Array): boolean
|
||||
};
|
||||
@@ -35,9 +18,9 @@ export type KeyringPairs = {
|
||||
};
|
||||
|
||||
export type KeyringInstance = {
|
||||
addFromSeed (seed: Uint8Array | string): KeyringPair,
|
||||
decrypt (encrypted: KeyringPairEncrypted, secret: Uint8Array | string): KeyringPair,
|
||||
encrypt (publicKey: Uint8Array, secret: Uint8Array | string): ?KeyringPairEncrypted,
|
||||
addFromSeed (seed: Uint8Array): KeyringPair,
|
||||
decrypt (encrypted: Uint8Array, secret: Uint8Array | string): KeyringPair,
|
||||
encrypt (publicKey: Uint8Array, secret: Uint8Array | string): ?Uint8Array,
|
||||
getPair (publicKey: Uint8Array): ?KeyringPair,
|
||||
getPairs (): Array<KeyringPair>,
|
||||
getPublicKeys (): Array<Uint8Array>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-rlp",
|
||||
"version": "0.17.4",
|
||||
"version": "0.18.0",
|
||||
"description": "RLP encoding and decoding",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -29,7 +29,7 @@
|
||||
"test": "echo \"Tests only available from root wrapper\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.17.4",
|
||||
"@polkadot/util": "^0.18.0",
|
||||
"babel-runtime": "^6.26.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util-triehash",
|
||||
"version": "0.17.4",
|
||||
"version": "0.18.0",
|
||||
"description": "Creation of triehash values",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -29,9 +29,9 @@
|
||||
"test": "echo \"Tests only available from root wrapper\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.17.4",
|
||||
"@polkadot/util-crypto": "^0.17.4",
|
||||
"@polkadot/util-rlp": "^0.17.4",
|
||||
"@polkadot/util": "^0.18.0",
|
||||
"@polkadot/util-crypto": "^0.18.0",
|
||||
"@polkadot/util-rlp": "^0.18.0",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/util",
|
||||
"version": "0.17.4",
|
||||
"version": "0.18.0",
|
||||
"description": "A collection of useful utilities for @polkadot",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -29,7 +29,7 @@
|
||||
"test": "echo \"Tests only available from root wrapper\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api-jsonrpc": "^0.8.4"
|
||||
"@polkadot/api-jsonrpc": "^0.8.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.26.0",
|
||||
|
||||
@@ -79,9 +79,9 @@
|
||||
lodash "^4.2.0"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@polkadot/api-jsonrpc@^0.8.4":
|
||||
version "0.8.4"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.4.tgz#e4f34523a42e1772abf6c25ac604fb9b387ad10e"
|
||||
"@polkadot/api-jsonrpc@^0.8.5":
|
||||
version "0.8.5"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.8.5.tgz#f27afc6304dcf94b0e95f62b33b2091ba6b690e5"
|
||||
dependencies:
|
||||
babel-runtime "^6.26.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user