Add createFromUri (#101)

* Add createFromUri

* Bump util dep
This commit is contained in:
Jaco Greeff
2019-03-21 11:22:31 +01:00
committed by GitHub
parent 50da19ba37
commit ec98152643
7 changed files with 97 additions and 36 deletions
+6
View File
@@ -1,3 +1,9 @@
# 0.33.1
- Rename createUri and createExternal to addExternal and addUr
- Rename addAccountPair to addPair
- Add additional createFromUri function to create pair, but not add it
# 0.32.1
- Add createUri to create an account from a path uri
+2 -2
View File
@@ -24,8 +24,8 @@
"react": "*"
},
"devDependencies": {
"@polkadot/keyring": "^0.39.1",
"@polkadot/util-crypto": "^0.39.1",
"@polkadot/keyring": "^0.40.0-beta.0",
"@polkadot/util-crypto": "^0.40.0-beta.0",
"xmlserializer": "^0.6.1"
}
}
+2 -2
View File
@@ -17,9 +17,9 @@
"styled-components": "^4.1.3"
},
"devDependencies": {
"@polkadot/keyring": "^0.39.1",
"@polkadot/keyring": "^0.40.0-beta.0",
"@polkadot/types": "^0.49.1",
"@polkadot/util": "^0.39.1"
"@polkadot/util": "^0.40.0-beta.0"
},
"peerDependencies": {
"@polkadot/keyring": "*",
+35 -28
View File
@@ -20,11 +20,34 @@ import keyringOption from './options';
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll({ type: 'ed25519' | 'sr25519' })` is triggered
// from the API after the chain is received
export class Keyring extends Base implements KeyringStruct {
addAccountPair (pair: KeyringPair, password: string): KeyringPair {
this.keyring.addPair(pair);
this.saveAccount(pair, password);
addExternal (publicKey: Uint8Array, meta: KeyringPair$Meta = {}): CreateResult {
const pair = this.keyring.addFromAddress(publicKey, { ...meta, isExternal: true }, null);
const json = this.saveAccount(pair);
return pair;
return {
json,
pair
};
}
addPair (pair: KeyringPair, password: string): CreateResult {
this.keyring.addPair(pair);
const json = this.saveAccount(pair, password);
return {
json,
pair
};
}
addUri (suri: string, password?: string, meta: KeyringPair$Meta = {}, type?: KeypairType): CreateResult {
const pair = this.keyring.addFromUri(suri, meta, type);
const json = this.saveAccount(pair, password);
return {
json,
pair
};
}
backupAccount (pair: KeyringPair, password: string): KeyringPair$Json {
@@ -38,41 +61,25 @@ export class Keyring extends Base implements KeyringStruct {
}
createAccount (seed: Uint8Array, password?: string, meta?: KeyringPair$Meta): KeyringPair {
console.warn('createAccount deprecated, use createUri instead');
console.warn('createAccount deprecated, use addUri instead');
return this.createUri(u8aToHex(seed), password, meta).pair;
return this.addUri(u8aToHex(seed), password, meta).pair;
}
createAccountExternal (publicKey: Uint8Array, meta?: KeyringPair$Meta): KeyringPair {
console.warn('createAccountExternal deprecated, use createUri instead');
console.warn('createAccountExternal deprecated, use addExternal instead');
return this.createExternal(publicKey, meta).pair;
return this.addExternal(publicKey, meta).pair;
}
createAccountMnemonic (seed: string, password?: string, meta?: KeyringPair$Meta): KeyringPair {
console.warn('createAccountMnemonic deprecated, use createUri instead');
return this.createUri(seed, password, meta).pair;
return this.addUri(seed, password, meta).pair;
}
createExternal (publicKey: Uint8Array, meta: KeyringPair$Meta = {}): CreateResult {
const pair = this.keyring.addFromAddress(publicKey, { ...meta, isExternal: true }, null);
const json = this.saveAccount(pair);
return {
json,
pair
};
}
createUri (suri: string, password?: string, meta: KeyringPair$Meta = {}, type?: KeypairType): CreateResult {
const pair = this.keyring.addFromUri(suri, meta, type);
const json = this.saveAccount(pair, password);
return {
json,
pair
};
createFromUri (suri: string, meta: KeyringPair$Meta = {}, type?: KeypairType): KeyringPair {
return this.keyring.createFromUri(suri, meta, type);
}
encryptAccount (pair: KeyringPair, password: string): void {
@@ -194,7 +201,7 @@ export class Keyring extends Base implements KeyringStruct {
// unlock, save account and then lock (locking cleans secretKey, so needs to be last)
pair.decodePkcs8(password);
this.addAccountPair(pair, password);
this.addPair(pair, password);
pair.lock();
return pair;
+4 -3
View File
@@ -42,13 +42,14 @@ export interface KeyringStruct {
readonly addresses: AddressSubject;
readonly keyring: BaseKeyringInstance | undefined;
addAccountPair: (pair: KeyringPair, password: string) => KeyringPair;
addExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => CreateResult;
addPair: (pair: KeyringPair, password: string) => CreateResult;
addUri: (suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType) => CreateResult;
backupAccount: (pair: KeyringPair, password: string) => KeyringPair$Json;
createAccount: (seed: Uint8Array, password?: string, meta?: KeyringPair$Meta) => KeyringPair;
createAccountExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => KeyringPair;
createAccountMnemonic: (seed: string, password?: string, meta?: KeyringPair$Meta) => KeyringPair;
createExternal: (publicKey: Uint8Array, meta?: KeyringPair$Meta) => CreateResult;
createUri: (suri: string, password?: string, meta?: KeyringPair$Meta, type?: KeypairType) => CreateResult;
createFromUri (suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
decodeAddress: (key: string | Uint8Array) => Uint8Array;
encodeAddress: (key: string | Uint8Array) => string;
encryptAccount: (pair: KeyringPair, password: string) => void;
+1 -1
View File
@@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.3.4",
"@polkadot/util": "^0.39.1",
"@polkadot/util": "^0.40.0-beta.0",
"@types/store": "^2.0.1",
"store": "^2.0.12"
}
+47
View File
@@ -1694,6 +1694,17 @@
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
"@polkadot/keyring@^0.40.0-beta.0":
version "0.40.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.40.0-beta.0.tgz#6091a65a77614e96bd6c0f5e8d2eea5b4d6a465e"
integrity sha512-4xvrWJ6jUXVaOpOvBJMRLfhwH33S6saAwA45pEHg9hOMvORfsWQzSOE/wqHsLKxnkDJwxih2SsRz+/lC3ARBLg==
dependencies:
"@babel/runtime" "^7.4.0"
"@polkadot/util" "^0.40.0-beta.0"
"@polkadot/util-crypto" "^0.40.0-beta.0"
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
"@polkadot/ts@^0.1.56":
version "0.1.56"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.56.tgz#ffd6e9c95704a7fb90b918193b9dc5c440114b27"
@@ -1729,6 +1740,27 @@
tweetnacl "^1.0.1"
xxhashjs "^0.2.2"
"@polkadot/util-crypto@^0.40.0-beta.0":
version "0.40.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.40.0-beta.0.tgz#96684763846047e5eb8054f80e32756b214fa042"
integrity sha512-jlcHOUGKzdXCyAPz3owpLgWuXUHY0XdGlbGZFkb9Mh7bKvXjoF/uHfIODj/7l9lwstWA2iVpeGsKWAYjLM1h3Q==
dependencies:
"@babel/runtime" "^7.4.0"
"@polkadot/util" "^0.40.0-beta.0"
"@polkadot/wasm-crypto" "^0.2.1"
"@polkadot/wasm-schnorrkel" "^0.2.1"
"@types/bip39" "^2.4.2"
"@types/pbkdf2" "^3.0.0"
"@types/secp256k1" "^3.5.0"
"@types/webassembly-js-api" "^0.0.2"
"@types/xxhashjs" "^0.2.1"
bip39 "^2.5.0"
blakejs "^1.1.0"
js-sha3 "^0.8.0"
secp256k1 "^3.6.2"
tweetnacl "^1.0.1"
xxhashjs "^0.2.2"
"@polkadot/util@^0.39.1":
version "0.39.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.39.1.tgz#553155a0610e879abf51210a4f99af9c1e3ce25b"
@@ -1744,6 +1776,21 @@
ip-regex "^4.0.0"
moment "^2.24.0"
"@polkadot/util@^0.40.0-beta.0":
version "0.40.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.40.0-beta.0.tgz#d68c73b720a92ae29a13659f1181ffed72fe5b80"
integrity sha512-pc+RCbxlOgZnag0OiDgd73HeUqClCQj4TuoxTMDgitbI53EkaMualSaPQ/DqlXWXUtG8frjKEEwF9QXUlQhpPw==
dependencies:
"@babel/runtime" "^7.4.0"
"@types/bn.js" "^4.11.4"
"@types/deasync" "^0.1.0"
"@types/ip-regex" "^3.0.0"
bn.js "^4.11.8"
camelcase "^5.2.0"
chalk "^2.4.2"
ip-regex "^4.0.0"
moment "^2.24.0"
"@polkadot/wasm-crypto@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-0.2.1.tgz#ba5eedf02f762d38fd705c57cba31db7f6e7eb1c"