Move address helpers to util-crypto (#416)
* Move address helpers to util * Move address helpers to @polkadot/util-crypto
This commit is contained in:
@@ -3,10 +3,9 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
import { cryptoWaitReady, setAddressPrefix } from '@polkadot/util-crypto';
|
||||
|
||||
import Keyring from '.';
|
||||
import setPrefix from './address/setPrefix';
|
||||
|
||||
describe('keypair', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -41,7 +40,7 @@ describe('keypair', () => {
|
||||
});
|
||||
|
||||
it('adds from a mnemonic', () => {
|
||||
setPrefix(68);
|
||||
setAddressPrefix(68);
|
||||
|
||||
expect(
|
||||
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address()
|
||||
@@ -107,7 +106,7 @@ describe('keypair', () => {
|
||||
});
|
||||
|
||||
it('adds from a mnemonic', () => {
|
||||
setPrefix(68);
|
||||
setAddressPrefix(68);
|
||||
|
||||
expect(
|
||||
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address()
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { assertSingletonPackage } from '@polkadot/util';
|
||||
import { decodeAddress, encodeAddress, setAddressPrefix } from '@polkadot/util-crypto';
|
||||
|
||||
import { decodeAddress, encodeAddress, setAddressPrefix } from './address';
|
||||
import { default as Keyring } from './keyring';
|
||||
|
||||
assertSingletonPackage('@polkadot/keyring');
|
||||
|
||||
@@ -6,9 +6,8 @@ import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$Meta, KeyringOptions } from './types';
|
||||
|
||||
import { assert, hexToU8a, isNumber, isHex, stringToU8a } from '@polkadot/util';
|
||||
import { keyExtractSuri, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, mnemonicToMiniSecret, keyFromPath } from '@polkadot/util-crypto';
|
||||
import { decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, mnemonicToMiniSecret, setAddressPrefix } from '@polkadot/util-crypto';
|
||||
|
||||
import { decodeAddress, encodeAddress, setAddressPrefix } from './address';
|
||||
import { DEV_PHRASE } from './defaults';
|
||||
import createPair from './pair';
|
||||
import Pairs from './pairs';
|
||||
|
||||
@@ -6,9 +6,8 @@ import { Keypair, KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
import { PairInfo } from './types';
|
||||
|
||||
import { naclKeypairFromSeed as naclFromSeed, naclSign, naclVerify, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVerify } from '@polkadot/util-crypto';
|
||||
import { encodeAddress, naclKeypairFromSeed as naclFromSeed, naclSign, naclVerify, schnorrkelKeypairFromSeed as schnorrkelFromSeed, schnorrkelSign, schnorrkelVerify } from '@polkadot/util-crypto';
|
||||
|
||||
import { encodeAddress } from '../address';
|
||||
import decode from './decode';
|
||||
import encode from './encode';
|
||||
import toJson from './toJson';
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
import { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
|
||||
import addressEncode from '../address/encode';
|
||||
import { encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
const publicKey = new Uint8Array(32);
|
||||
const address = addressEncode(publicKey);
|
||||
const address = encodeAddress(publicKey);
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: 'nobody'
|
||||
|
||||
@@ -6,8 +6,7 @@ import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { KeyringPair$Json, KeyringPair$Meta } from '../types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { encodeAddress } from '../address';
|
||||
import { encodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
type PairStateJson = KeyringPair$Meta & {
|
||||
publicKey: Uint8Array
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
import { KeyringPairs, KeyringPair } from './types';
|
||||
|
||||
import { assert, isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import addressDecode from './address/decode';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
type KeyringPairMap = {
|
||||
// @ts-ignore we use coercion :(
|
||||
@@ -33,7 +32,7 @@ export default class Pairs implements KeyringPairs {
|
||||
|
||||
get (address: string | Uint8Array): KeyringPair {
|
||||
// @ts-ignore we use coercion :(
|
||||
const pair = this._map[addressDecode(address)];
|
||||
const pair = this._map[decodeAddress(address)];
|
||||
|
||||
assert(pair, () => {
|
||||
const formatted: string = isU8a(address) || isHex(address)
|
||||
@@ -48,6 +47,6 @@ export default class Pairs implements KeyringPairs {
|
||||
|
||||
remove (address: string | Uint8Array): void {
|
||||
// @ts-ignore we use coercion :(
|
||||
delete this._map[addressDecode(address)];
|
||||
delete this._map[decodeAddress(address)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Prefix } from '@polkadot/util-crypto/address/types';
|
||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { Prefix } from './address/types';
|
||||
|
||||
export type KeyringOptions = {
|
||||
addressPrefix?: Prefix,
|
||||
|
||||
@@ -135,7 +135,7 @@ export default class Trie extends Impl implements TrieDb {
|
||||
}
|
||||
|
||||
entries (): Array<TrieEntry> {
|
||||
l.debug(() => 'retreiving trie entries');
|
||||
l.debug(() => 'retrieving trie entries');
|
||||
|
||||
const start = Date.now();
|
||||
const entries = this._entries(this.rootHash);
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import testingPairs from '../testingPairs';
|
||||
import testingPairs from '../../../keyring/src/testingPairs';
|
||||
import decode from './decode';
|
||||
|
||||
describe('decode', () => {
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import testingPairs from '../testingPairs';
|
||||
import testingPairs from '../../../keyring/src/testingPairs';
|
||||
import encode from './encode';
|
||||
|
||||
const keyring = testingPairs({ type: 'ed25519' }, false);
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import blake2AsU8a from '../blake2/asU8a';
|
||||
|
||||
const SS58_PREFIX = stringToU8a('SS58PRE');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2019 @polkadot/keyring authors & contributors
|
||||
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@@ -6,6 +6,7 @@ import './polyfill';
|
||||
|
||||
import wasmCrypto from '@polkadot/wasm-crypto';
|
||||
|
||||
export * from './address';
|
||||
export * from './blake2';
|
||||
export * from './keccak';
|
||||
export * from './key';
|
||||
|
||||
Reference in New Issue
Block a user