Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf1c187969 | ||
|
|
16d077c87d | ||
|
|
00374effc5 | ||
|
|
891a855fb8 | ||
|
|
854cb56621 |
+9
-1
@@ -1,6 +1,14 @@
|
|||||||
|
# 1.4.1
|
||||||
|
|
||||||
|
- **Breaking change** To set the `ss58Format`, you should now use `setSS58Format` as opposed to the old `setAddressPrefix`
|
||||||
|
- Renamed `keyring.setAddressPrefix` to `keyring.setSS58Format`
|
||||||
|
- Deprecated `addressPrefix` on the keyring options, added the `ss58Format` as a replacement (aligning with chain properties - the old version is still accepted)
|
||||||
|
- Added `stringToHex` and `hexToString` conversion utilities to `@polkadot/util`
|
||||||
|
- Swap to [Babel 7.6.0](https://babeljs.io/) for all compilation, for latest improvements in code generation
|
||||||
|
|
||||||
# 1.3.1
|
# 1.3.1
|
||||||
|
|
||||||
- Remove the `ExtError` class, always prefer the standard JS `Error` object for errors. This would bre a breaking change for any appliactions using `ExtError`
|
- Remove the `ExtError` class, always prefer the standard JS `Error` object for errors. This would bre a breaking change for any applications using `ExtError`
|
||||||
|
|
||||||
# 1.2.1
|
# 1.2.1
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "1.3.1"
|
"version": "1.4.1"
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"yarn": "^1.10.1"
|
"yarn": "^1.10.1"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"babel-core": "^7.0.0-bridge.0",
|
"babel-core": "^7.0.0-bridge.0",
|
||||||
"typescript": "^3.6.2"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "polkadot-dev-build-ts && polkadot-dev-build-docs",
|
"build": "polkadot-dev-build-ts && polkadot-dev-build-docs",
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
"test:one": "jest"
|
"test:one": "jest"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.5.5",
|
"@babel/core": "^7.6.0",
|
||||||
"@polkadot/dev": "^0.31.0-beta.7",
|
"@polkadot/dev": "^0.31.0-beta.8",
|
||||||
"@polkadot/ts": "^0.1.71",
|
"@polkadot/ts": "^0.1.72",
|
||||||
"gh-pages": "^2.1.1"
|
"gh-pages": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/chainspec",
|
"name": "@polkadot/chainspec",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "Contains chain specifications for known chains",
|
"description": "Contains chain specifications for known chains",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/chainspec#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/chainspec#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1"
|
"@polkadot/util": "^1.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/db",
|
"name": "@polkadot/db",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "Implementation of a basic sync in-memory and on-disk databases with overlays",
|
"description": "Implementation of a basic sync in-memory and on-disk databases with overlays",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,9 +25,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/db#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/db#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/trie-hash": "^1.3.1",
|
"@polkadot/trie-hash": "^1.4.1",
|
||||||
"@polkadot/util": "^1.3.1",
|
"@polkadot/util": "^1.4.1",
|
||||||
"lru_map": "^0.3.3"
|
"lru_map": "^0.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/keyring",
|
"name": "@polkadot/keyring",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "Keyring management",
|
"description": "Keyring management",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/keyring#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1",
|
"@polkadot/util": "^1.4.1",
|
||||||
"@polkadot/util-crypto": "^1.3.1"
|
"@polkadot/util-crypto": "^1.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
import { hexToU8a, stringToU8a } from '@polkadot/util';
|
||||||
import { cryptoWaitReady, setAddressPrefix } from '@polkadot/util-crypto';
|
import { cryptoWaitReady, setSS58Format } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
import Keyring from '.';
|
import Keyring from '.';
|
||||||
|
|
||||||
@@ -25,6 +25,10 @@ describe('keypair', (): void => {
|
|||||||
keypair.addFromSeed(seedOne, {});
|
keypair.addFromSeed(seedOne, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach((): void => {
|
||||||
|
setSS58Format(42);
|
||||||
|
});
|
||||||
|
|
||||||
it('adds the pair', (): void => {
|
it('adds the pair', (): void => {
|
||||||
expect(
|
expect(
|
||||||
keypair.addFromSeed(seedTwo, {}).publicKey
|
keypair.addFromSeed(seedTwo, {}).publicKey
|
||||||
@@ -40,7 +44,7 @@ describe('keypair', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds from a mnemonic', (): void => {
|
it('adds from a mnemonic', (): void => {
|
||||||
setAddressPrefix(68);
|
setSS58Format(68);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address
|
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address
|
||||||
@@ -93,6 +97,10 @@ describe('keypair', (): void => {
|
|||||||
keypair.addFromSeed(seedOne, {});
|
keypair.addFromSeed(seedOne, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach((): void => {
|
||||||
|
setSS58Format(42);
|
||||||
|
});
|
||||||
|
|
||||||
it('creates with dev phrase when only path specified', (): void => {
|
it('creates with dev phrase when only path specified', (): void => {
|
||||||
expect(
|
expect(
|
||||||
keypair.createFromUri('//Alice').address
|
keypair.createFromUri('//Alice').address
|
||||||
@@ -106,7 +114,7 @@ describe('keypair', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('adds from a mnemonic', (): void => {
|
it('adds from a mnemonic', (): void => {
|
||||||
setAddressPrefix(68);
|
setSS58Format(68);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address
|
keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { assertSingletonPackage } from '@polkadot/util';
|
import { assertSingletonPackage } from '@polkadot/util';
|
||||||
import { decodeAddress, encodeAddress, setAddressPrefix } from '@polkadot/util-crypto';
|
import { decodeAddress, encodeAddress, setSS58Format } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
import Keyring from './keyring';
|
import Keyring from './keyring';
|
||||||
|
|
||||||
@@ -15,5 +15,5 @@ export {
|
|||||||
Keyring,
|
Keyring,
|
||||||
decodeAddress,
|
decodeAddress,
|
||||||
encodeAddress,
|
encodeAddress,
|
||||||
setAddressPrefix
|
setSS58Format
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { KeypairType } from '@polkadot/util-crypto/types';
|
|||||||
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$Meta, KeyringOptions } from './types';
|
import { KeyringInstance, KeyringPair, KeyringPair$Json, KeyringPair$Meta, KeyringOptions } from './types';
|
||||||
|
|
||||||
import { assert, hexToU8a, isNumber, isHex, stringToU8a } from '@polkadot/util';
|
import { assert, hexToU8a, isNumber, isHex, stringToU8a } from '@polkadot/util';
|
||||||
import { decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, mnemonicToMiniSecret, setAddressPrefix } from '@polkadot/util-crypto';
|
import { decodeAddress, encodeAddress, keyExtractSuri, keyFromPath, naclKeypairFromSeed as naclFromSeed, schnorrkelKeypairFromSeed as schnorrkelFromSeed, mnemonicToMiniSecret, setSS58Format } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
import { DEV_PHRASE } from './defaults';
|
import { DEV_PHRASE } from './defaults';
|
||||||
import createPair from './pair';
|
import createPair from './pair';
|
||||||
@@ -37,17 +37,20 @@ export default class Keyring implements KeyringInstance {
|
|||||||
|
|
||||||
public encodeAddress = encodeAddress;
|
public encodeAddress = encodeAddress;
|
||||||
|
|
||||||
public setAddressPrefix = setAddressPrefix;
|
public setSS58Format = setSS58Format;
|
||||||
|
|
||||||
public constructor (options: KeyringOptions = {}) {
|
public constructor (options: KeyringOptions = {}) {
|
||||||
options.type = options.type || 'ed25519';
|
options.type = options.type || 'ed25519';
|
||||||
|
options.ss58Format = options.ss58Format || options.addressPrefix;
|
||||||
|
|
||||||
assert(options && ['ed25519', 'sr25519'].includes(options.type || 'undefined'), `Expected a keyring type of either 'ed25519' or 'sr25519', found '${options.type}`);
|
assert(options && ['ed25519', 'sr25519'].includes(options.type || 'undefined'), `Expected a keyring type of either 'ed25519' or 'sr25519', found '${options.type}`);
|
||||||
|
|
||||||
this._pairs = new Pairs();
|
this._pairs = new Pairs();
|
||||||
this._type = options.type;
|
this._type = options.type;
|
||||||
|
|
||||||
setAddressPrefix(isNumber(options.addressPrefix) ? options.addressPrefix : 42);
|
if (isNumber(options.ss58Format)) {
|
||||||
|
setSS58Format(options.ss58Format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { setAddressPrefix } from '@polkadot/util-crypto';
|
import { setSS58Format } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
import testingPairs from '../testingPairs';
|
import testingPairs from '../testingPairs';
|
||||||
import createPair from '.';
|
import createPair from '.';
|
||||||
@@ -61,7 +61,7 @@ describe('pair', (): void => {
|
|||||||
'5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua'
|
'5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua'
|
||||||
);
|
);
|
||||||
|
|
||||||
setAddressPrefix(68);
|
setSS58Format(68);
|
||||||
|
|
||||||
expect(keyring.alice.address).toEqual(
|
expect(keyring.alice.address).toEqual(
|
||||||
'7sGUeMak588SPY2YMmmuKUuLz7u2WQpf74F9dCFtSLB2td9d'
|
'7sGUeMak588SPY2YMmmuKUuLz7u2WQpf74F9dCFtSLB2td9d'
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import { Prefix } from '@polkadot/util-crypto/address/types';
|
|||||||
import { KeypairType } from '@polkadot/util-crypto/types';
|
import { KeypairType } from '@polkadot/util-crypto/types';
|
||||||
|
|
||||||
export interface KeyringOptions {
|
export interface KeyringOptions {
|
||||||
|
// @deprecated
|
||||||
addressPrefix?: Prefix;
|
addressPrefix?: Prefix;
|
||||||
|
ss58Format?: Prefix;
|
||||||
type?: KeypairType;
|
type?: KeypairType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ export interface KeyringInstance {
|
|||||||
|
|
||||||
decodeAddress (encoded: string | Uint8Array, ignoreChecksum?: boolean): Uint8Array;
|
decodeAddress (encoded: string | Uint8Array, ignoreChecksum?: boolean): Uint8Array;
|
||||||
encodeAddress (key: Uint8Array | string): string;
|
encodeAddress (key: Uint8Array | string): string;
|
||||||
setAddressPrefix (prefix: Prefix): void;
|
setSS58Format (prefix: Prefix): void;
|
||||||
|
|
||||||
addPair (pair: KeyringPair): KeyringPair;
|
addPair (pair: KeyringPair): KeyringPair;
|
||||||
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/trie-codec",
|
"name": "@polkadot/trie-codec",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "This is an implementation of the codec for Substrate Trie",
|
"description": "This is an implementation of the codec for Substrate Trie",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-codec#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-codec#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1"
|
"@polkadot/util": "^1.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/trie-db",
|
"name": "@polkadot/trie-db",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "This is an implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper, adapted for Polkadot",
|
"description": "This is an implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper, adapted for Polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,16 +25,16 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-db#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-db#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/db": "^1.3.1",
|
"@polkadot/db": "^1.4.1",
|
||||||
"@polkadot/trie-codec": "^1.3.1",
|
"@polkadot/trie-codec": "^1.4.1",
|
||||||
"@polkadot/trie-hash": "^1.3.1",
|
"@polkadot/trie-hash": "^1.4.1",
|
||||||
"@polkadot/util": "^1.3.1",
|
"@polkadot/util": "^1.4.1",
|
||||||
"@polkadot/util-crypto": "^1.3.1"
|
"@polkadot/util-crypto": "^1.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/chainspec": "^1.3.1",
|
"@polkadot/chainspec": "^1.4.1",
|
||||||
"@polkadot/util-rlp": "^1.3.1",
|
"@polkadot/util-rlp": "^1.4.1",
|
||||||
"ethereumjs-testing": "1.0.4"
|
"ethereumjs-testing": "1.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/trie-hash",
|
"name": "@polkadot/trie-hash",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "Generates trie roots from key-value pairs",
|
"description": "Generates trie roots from key-value pairs",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,10 +25,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/trie-hash#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1"
|
"@polkadot/util": "^1.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/chainspec": "^1.3.1"
|
"@polkadot/chainspec": "^1.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util-crypto",
|
"name": "@polkadot/util-crypto",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "A collection of useful crypto utilities for @polkadot",
|
"description": "A collection of useful crypto utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,8 +25,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-crypto#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1",
|
"@polkadot/util": "^1.4.1",
|
||||||
"@polkadot/wasm-crypto": "^0.14.1",
|
"@polkadot/wasm-crypto": "^0.14.1",
|
||||||
"@types/bip39": "^2.4.2",
|
"@types/bip39": "^2.4.2",
|
||||||
"@types/bs58": "^4.0.0",
|
"@types/bs58": "^4.0.0",
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ describe('encode', (): void => {
|
|||||||
).toEqual('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua');
|
).toEqual('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can re-encode an address', (): void => {
|
||||||
|
expect(
|
||||||
|
encode('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 68)
|
||||||
|
).toEqual('7sL6eNJj5ZGV5cn3hhV2deRUsivXfBfMH76wCALCqWj1EKzv');
|
||||||
|
});
|
||||||
|
|
||||||
it('fails when non-valid publicKey provided', (): void => {
|
it('fails when non-valid publicKey provided', (): void => {
|
||||||
expect(
|
expect(
|
||||||
(): string => encode(
|
(): string => encode(
|
||||||
|
|||||||
@@ -7,13 +7,15 @@ import { Prefix } from './types';
|
|||||||
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L34
|
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L34
|
||||||
|
|
||||||
import bs58 from 'bs58';
|
import bs58 from 'bs58';
|
||||||
import { assert, u8aConcat, u8aToBuffer, u8aToU8a } from '@polkadot/util';
|
import { assert, u8aConcat, u8aToBuffer } from '@polkadot/util';
|
||||||
|
|
||||||
|
import decode from './decode';
|
||||||
import defaults from './defaults';
|
import defaults from './defaults';
|
||||||
import sshash from './sshash';
|
import sshash from './sshash';
|
||||||
|
|
||||||
export default function encode (_key: Uint8Array | string, prefix: Prefix = defaults.prefix): string {
|
export default function encode (_key: Uint8Array | string, prefix: Prefix = defaults.prefix): string {
|
||||||
const key = u8aToU8a(_key);
|
// decode it, this means we can re-encode an address
|
||||||
|
const key = decode(_key);
|
||||||
|
|
||||||
assert(defaults.allowedDecodedLengths.includes(key.length), `Expected a valid key to convert, with length ${defaults.allowedDecodedLengths}`);
|
assert(defaults.allowedDecodedLengths.includes(key.length), `Expected a valid key to convert, with length ${defaults.allowedDecodedLengths}`);
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
import checkAddress from './check';
|
import checkAddress from './check';
|
||||||
import decodeAddress from './decode';
|
import decodeAddress from './decode';
|
||||||
import encodeAddress from './encode';
|
import encodeAddress from './encode';
|
||||||
import setAddressPrefix from './setPrefix';
|
import setSS58Format from './setSS58Format';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
checkAddress,
|
checkAddress,
|
||||||
decodeAddress,
|
decodeAddress,
|
||||||
encodeAddress,
|
encodeAddress,
|
||||||
setAddressPrefix
|
setSS58Format
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -3,11 +3,11 @@
|
|||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import encode from './encode';
|
import encode from './encode';
|
||||||
import setPrefix from './setPrefix';
|
import setSS58Format from './setSS58Format';
|
||||||
|
|
||||||
describe('setPrefix', (): void => {
|
describe('setSS58Format', (): void => {
|
||||||
beforeEach((): void => {
|
beforeEach((): void => {
|
||||||
setPrefix(68);
|
setSS58Format(68);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets and allows encoding using', (): void => {
|
it('sets and allows encoding using', (): void => {
|
||||||
+1
-1
@@ -6,6 +6,6 @@ import { Prefix } from './types';
|
|||||||
|
|
||||||
import defaults from './defaults';
|
import defaults from './defaults';
|
||||||
|
|
||||||
export default function setPrefix (prefix: Prefix): void {
|
export default function setSS58Format (prefix: Prefix): void {
|
||||||
defaults.prefix = prefix;
|
defaults.prefix = prefix;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util-rlp",
|
"name": "@polkadot/util-rlp",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "RLP encoding and decoding",
|
"description": "RLP encoding and decoding",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -27,8 +27,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-rlp#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util-rlp#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@polkadot/util": "^1.3.1"
|
"@polkadot/util": "^1.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ethereumjs-testing": "1.0.4"
|
"ethereumjs-testing": "1.0.4"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/util",
|
"name": "@polkadot/util",
|
||||||
"version": "1.3.1",
|
"version": "1.4.1",
|
||||||
"description": "A collection of useful utilities for @polkadot",
|
"description": "A collection of useful utilities for @polkadot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
"homepage": "https://github.com/polkadot-js/common/tree/master/packages/util#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.5.5",
|
"@babel/runtime": "^7.6.0",
|
||||||
"@types/bn.js": "^4.11.5",
|
"@types/bn.js": "^4.11.5",
|
||||||
"bn.js": "^4.11.8",
|
"bn.js": "^4.11.8",
|
||||||
"camelcase": "^5.3.1",
|
"camelcase": "^5.3.1",
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ export { default as hexHasPrefix } from './hasPrefix';
|
|||||||
export { default as hexStripPrefix } from './stripPrefix';
|
export { default as hexStripPrefix } from './stripPrefix';
|
||||||
export { default as hexToBn } from './toBn';
|
export { default as hexToBn } from './toBn';
|
||||||
export { default as hexToNumber } from './toNumber';
|
export { default as hexToNumber } from './toNumber';
|
||||||
|
export { default as hexToString } from './toString';
|
||||||
export { default as hexToU8a } from './toU8a';
|
export { default as hexToU8a } from './toU8a';
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2017-2019 @polkadot/util 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 { hexToString } from '.';
|
||||||
|
|
||||||
|
describe('hexToString', (): void => {
|
||||||
|
it('converts an empty to ""', (): void => {
|
||||||
|
expect(
|
||||||
|
hexToString()
|
||||||
|
).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts to a string from hex', (): void => {
|
||||||
|
expect(
|
||||||
|
hexToString('0x68656c6c6f')
|
||||||
|
).toEqual('hello');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2017-2019 @polkadot/util 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 u8aToString from '../u8a/toString';
|
||||||
|
import hexToU8a from './toU8a';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name hexToU8a
|
||||||
|
* @summary Creates a Uint8Array object from a hex string.
|
||||||
|
* @description
|
||||||
|
* Hex input values return the actual bytes value converted to a string. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||||
|
* @example
|
||||||
|
* <BR>
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { hexToString } from '@polkadot/util';
|
||||||
|
*
|
||||||
|
* hexToU8a('0x68656c6c6f'); // hello
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default function hexToString (_value?: string | null): string {
|
||||||
|
return u8aToString(
|
||||||
|
hexToU8a(_value)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import hexStripPrefix from './stripPrefix';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @name hexToU8a
|
* @name hexToU8a
|
||||||
* @summary Creates a Buffer object from a hex string.
|
* @summary Creates a Uint8Array object from a hex string.
|
||||||
* @description
|
* @description
|
||||||
* `null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
* `null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
@@ -9,5 +9,6 @@
|
|||||||
export { default as stringCamelCase } from './camelCase';
|
export { default as stringCamelCase } from './camelCase';
|
||||||
export { default as stringLowerFirst } from './lowerFirst';
|
export { default as stringLowerFirst } from './lowerFirst';
|
||||||
export { default as stringShorten } from './shorten';
|
export { default as stringShorten } from './shorten';
|
||||||
|
export { default as stringToHex } from './toHex';
|
||||||
export { default as stringToU8a } from './toU8a';
|
export { default as stringToU8a } from './toU8a';
|
||||||
export { default as stringUpperFirst } from './upperFirst';
|
export { default as stringUpperFirst } from './upperFirst';
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2017-2019 @polkadot/util 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 { stringToHex } from '.';
|
||||||
|
|
||||||
|
describe('hexToString', (): void => {
|
||||||
|
it('converts an empty to ""', (): void => {
|
||||||
|
expect(
|
||||||
|
stringToHex()
|
||||||
|
).toEqual('0x');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('converts to a hex from string', (): void => {
|
||||||
|
expect(
|
||||||
|
stringToHex('hello')
|
||||||
|
).toEqual('0x68656c6c6f');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2017-2019 @polkadot/util 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 u8aToHex from '../u8a/toHex';
|
||||||
|
import stringToU8a from './toU8a';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name stringToHex
|
||||||
|
* @summary Creates a hex string from a utf-8 string
|
||||||
|
* @description
|
||||||
|
* String input values return the actual encoded hex value.
|
||||||
|
* @example
|
||||||
|
* <BR>
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { stringToHex } from '@polkadot/util';
|
||||||
|
*
|
||||||
|
* stringToU8a('hello'); // 0x68656c6c6f
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default function stringToHex (value?: string): string {
|
||||||
|
return u8aToHex(
|
||||||
|
stringToU8a(value)
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user