Class Keyring
- java.lang.Object
-
- org.polkadot.common.keyring.Keyring
-
- All Implemented Interfaces:
Types.KeyringInstance
public class Keyring extends java.lang.Object implements Types.KeyringInstance
# @polkadot/keyring## Overview Keyring management of user accounts Allows generation of keyring pairs from a variety of input combinations, such as json object containing account address or public key, account metadata, and account encoded using `addFromJson`, or by providing those values as arguments separately to `addFromAddress`, or by providing the mnemonic (seed phrase) and account metadata as arguments to `addFromMnemonic`. Stores the keyring pairs in a keyring pair dictionary. Removal of the keyring pairs from the keyring pair dictionary is achieved using `removePair`. Retrieval of all the stored pairs via `getPairs` or perform lookup of a pair for a given account address or public key using `getPair`. JSON metadata associated with an account may be obtained using `toJson` accompanied by the account passphrase.
-
-
Constructor Summary
Constructors Constructor Description Keyring(Types.KeyringOptions options)
-
Method Summary
Modifier and Type Method Description Types.KeyringPairaddFromAddress(java.lang.String address, Types.KeyringPairMeta meta, byte[] encoded, java.lang.String type, boolean ignoreChecksum)Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to explicitely provide separate inputs including account address or public key, and optionally the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file of an account backup), and then generates a keyring pair from them that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.Types.KeyringPairaddFromJson(Types.KeyringPairJson pair, boolean ignoreChecksum)Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to provide a json object argument that contains account information (that may be obtained from the json file of an account backup), and then generates a keyring pair from it that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.Types.KeyringPairaddFromMnemonic(java.lang.String mnemonic, Types.KeyringPairMeta meta, java.lang.String type)Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to provide a mnemonic (seed phrase that is provided when account is originally created) argument and a metadata argument that contains account information (that may be obtained from the json file of an account backup), and then generates a keyring pair from it that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.Types.KeyringPairaddFromSeed(byte[] seed, Types.KeyringPairMeta meta, java.lang.String type)Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.Types.KeyringPairaddFromUri(java.lang.String suri, Types.KeyringPairMeta meta, java.lang.String type)Creates an account via an suri Extracts the phrase, path and password from a SURI format for specifying secret keys `/ // /// ` (the `///password` may be omitted, and `/ ` and `// ` maybe repeated and mixed). Types.KeyringPairaddPair(Types.KeyringPair pair)Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair DictionaryTypes.KeyringPaircreateFromUri(java.lang.String _suri, Types.KeyringPairMeta meta, java.lang.String type)Creates a Keypair from an suri This creates a pair from the suri, but does not add it to the keyringbyte[]decodeAddress(java.lang.Object encoded, boolean ignoreChecksum)java.lang.StringencodeAddress(byte[] key)Types.KeyringPairgetPair(java.lang.String address)Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address Returns a keyring pair value from the keyring pair dictionary by performing a key lookup using the provided account address or public key (after decoding it).java.util.List<Types.KeyringPair>getPairs()Retrieves all account keyring pairs from the Keyring Pair Dictionary Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.java.util.List<byte[]>getPublicKeys()Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.java.lang.StringgetType()Returns the type of the keyring, either ed25519 of sr25519voidremovePair(java.lang.String address)Deletes the provided input address or public key from the stored Keyring Pair Dictionary.voidsetAddressPrefix(int prefix)Types.KeyringPairJsontoJson(java.lang.String address, java.lang.String passphrase)Returns a JSON object associated with the input argument that contains metadata assocated with an account Returns a JSON object containing the metadata associated with an account when valid address or public key and when the account passphrase is provided if the account secret is not already unlocked and available in memory.
-
-
-
Constructor Detail
-
Keyring
public Keyring(Types.KeyringOptions options)
-
-
Method Detail
-
getPairs
public java.util.List<Types.KeyringPair> getPairs()
Retrieves all account keyring pairs from the Keyring Pair Dictionary Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.- Specified by:
getPairsin interfaceTypes.KeyringInstance
-
getPublicKeys
public java.util.List<byte[]> getPublicKeys()
Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.- Specified by:
getPublicKeysin interfaceTypes.KeyringInstance
-
getType
public java.lang.String getType()
Returns the type of the keyring, either ed25519 of sr25519- Specified by:
getTypein interfaceTypes.KeyringInstance
-
decodeAddress
public byte[] decodeAddress(java.lang.Object encoded, boolean ignoreChecksum)- Specified by:
decodeAddressin interfaceTypes.KeyringInstance
-
encodeAddress
public java.lang.String encodeAddress(byte[] key)
- Specified by:
encodeAddressin interfaceTypes.KeyringInstance
-
setAddressPrefix
public void setAddressPrefix(int prefix)
- Specified by:
setAddressPrefixin interfaceTypes.KeyringInstance
-
addPair
public Types.KeyringPair addPair(Types.KeyringPair pair)
Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary- Specified by:
addPairin interfaceTypes.KeyringInstance
-
addFromAddress
public Types.KeyringPair addFromAddress(java.lang.String address, Types.KeyringPairMeta meta, byte[] encoded, java.lang.String type, boolean ignoreChecksum)
Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to explicitely provide separate inputs including account address or public key, and optionally the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file of an account backup), and then generates a keyring pair from them that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.- Specified by:
addFromAddressin interfaceTypes.KeyringInstance
-
addFromJson
public Types.KeyringPair addFromJson(Types.KeyringPairJson pair, boolean ignoreChecksum)
Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to provide a json object argument that contains account information (that may be obtained from the json file of an account backup), and then generates a keyring pair from it that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.- Specified by:
addFromJsonin interfaceTypes.KeyringInstance
-
addFromMnemonic
public Types.KeyringPair addFromMnemonic(java.lang.String mnemonic, Types.KeyringPairMeta meta, java.lang.String type)
Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to provide a mnemonic (seed phrase that is provided when account is originally created) argument and a metadata argument that contains account information (that may be obtained from the json file of an account backup), and then generates a keyring pair from it that it passes to `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.- Specified by:
addFromMnemonicin interfaceTypes.KeyringInstance
-
addFromSeed
public Types.KeyringPair addFromSeed(byte[] seed, Types.KeyringPairMeta meta, java.lang.String type)
Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value. Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.- Specified by:
addFromSeedin interfaceTypes.KeyringInstance
-
addFromUri
public Types.KeyringPair addFromUri(java.lang.String suri, Types.KeyringPairMeta meta, java.lang.String type)
Creates an account via an suri Extracts the phrase, path and password from a SURI format for specifying secret keys `/ // /// ` (the `///password` may be omitted, and `/ ` and `// ` maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded) - Specified by:
addFromUriin interfaceTypes.KeyringInstance
-
createFromUri
public Types.KeyringPair createFromUri(java.lang.String _suri, Types.KeyringPairMeta meta, java.lang.String type)
Creates a Keypair from an suri This creates a pair from the suri, but does not add it to the keyring- Specified by:
createFromUriin interfaceTypes.KeyringInstance
-
getPair
public Types.KeyringPair getPair(java.lang.String address)
Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address Returns a keyring pair value from the keyring pair dictionary by performing a key lookup using the provided account address or public key (after decoding it).- Specified by:
getPairin interfaceTypes.KeyringInstance
-
removePair
public void removePair(java.lang.String address)
Deletes the provided input address or public key from the stored Keyring Pair Dictionary.- Specified by:
removePairin interfaceTypes.KeyringInstance
-
toJson
public Types.KeyringPairJson toJson(java.lang.String address, java.lang.String passphrase)
Returns a JSON object associated with the input argument that contains metadata assocated with an account Returns a JSON object containing the metadata associated with an account when valid address or public key and when the account passphrase is provided if the account secret is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user may backup their account to a JSON file that contains this information.- Specified by:
toJsonin interfaceTypes.KeyringInstance
-
-