@polkadot/keyring
- Version 13.3.1
- Published
- 156 kB
- 3 dependencies
- Apache-2.0 license
Install
npm i @polkadot/keyring
yarn add @polkadot/keyring
pnpm add @polkadot/keyring
Overview
Keyring management
Index
Variables
Functions
Classes
Variables
variable DEV_PHRASE
const DEV_PHRASE: string;
variable DEV_SEED
const DEV_SEED: string;
variable packageInfo
const packageInfo: { name: string; path: string; type: string; version: string };
Functions
function createPair
createPair: ( { toSS58, type }: Setup, { publicKey, secretKey }: PairInfo, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, encTypes?: EncryptedJsonEncoding[]) => KeyringPair;
createPair Creates a keyring pair object Creates a keyring pair object with provided account public key, metadata, and encoded arguments. The keyring pair stores the account state including the encoded address and associated metadata.
It has properties whose values are functions that may be called to perform account actions:
-
address
function retrieves the address associated with the account. -decodedPkcs8
function is called with the account passphrase and account encoded public key. It decodes the encoded public key using the passphrase provided to obtain the decoded account public key and associated secret key that are then available in memory, and changes the account address stored in the state of the pair to correspond to the address of the decoded public key. -encodePkcs8
function when provided with the correct passphrase associated with the account pair and when the secret key is in memory (when the account pair is not locked) it returns an encoded public key of the account. -meta
is the metadata that is stored in the state of the pair, either when it was originally created or set viasetMeta
. -publicKey
returns the public key stored in memory for the pair. -sign
may be used to return a signature by signing a provided message with the secret key (if it is in memory) using Nacl. -toJson
calls anothertoJson
function and provides the state of the pair, it generates arguments to be passed to the othertoJson
function including an encoded public key of the account that it generates using the secret key from memory (if it has been made available in memory) and the optionally provided passphrase argument. It passes a third boolean argument totoJson
indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded). ThetoJson
function that it calls returns a JSON object with properties including theaddress
andmeta
that are assigned with the values stored in the corresponding state variables of the account pair, anencoded
property that is assigned with the encoded public key in hex format, and anencoding
property that indicates whether the public key value of theencoded
property is encoded or not.
function createTestKeyring
createTestKeyring: ( options?: KeyringOptions, isDerived?: boolean) => KeyringInstance;
testKeyring Create an instance of Keyring pre-populated with locked test accounts The test accounts (i.e. alice, bob, dave, eve, ferdie) are available on the dev chain and each test account is initialized with DOT funds.
function createTestPairs
createTestPairs: <O extends KeyringOptions, M = DetectMap<O>>( options?: O, isDerived?: boolean) => M;
Classes
class Keyring
class Keyring implements KeyringInstance {}
# @polkadot/keyring
## Overview
Keyring 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 toaddFromAddress
, or by providing the mnemonic (seed phrase) and account metadata as arguments toaddFromMnemonic
. Stores the keyring pairs in a keyring pair dictionary. Removal of the keyring pairs from the keyring pair dictionary is achieved usingremovePair
. Retrieval of all the stored pairs viagetPairs
or perform lookup of a pair for a given account address or public key usinggetPair
. JSON metadata associated with an account may be obtained usingtoJson
accompanied by the account passphrase.
constructor
constructor(options?: KeyringOptions);
property decodeAddress
decodeAddress: any;
property encodeAddress
encodeAddress: (address: Uint8Array | string, ss58Format?: number) => string;
encodeAddress Encodes the input into an ss58 representation
property pairs
readonly pairs: KeyringPair[];
retrieve the pairs (alias for getPairs)
property publicKeys
readonly publicKeys: Uint8Array[];
retrieve the publicKeys (alias for getPublicKeys)
property type
readonly type: KeypairType;
Returns the type of the keyring, ed25519, sr25519 or ecdsa
method addFromAddress
addFromAddress: ( address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean, encType?: EncryptedJsonEncoding[]) => KeyringPair;
addFromAddress Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary Allows user to explicitly 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.
method addFromJson
addFromJson: (json: KeyringPair$Json, ignoreChecksum?: boolean) => KeyringPair;
addFromJson 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.
method addFromMnemonic
addFromMnemonic: ( mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
addFromMnemonic 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.
method addFromPair
addFromPair: ( pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
addFromPair Stores an account created from an explicit publicKey/secreteKey combination
method addFromSeed
addFromSeed: ( seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
addFromSeed 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.
method addFromUri
addFromUri: ( suri: string, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
addFromUri Creates an account via an suri Extracts the phrase, path and password from a SURI format for specifying secret keys
<secret>/<soft-key>//<hard-key>///<password>
(the///password
may be omitted, and/<soft-key>
and//<hard-key>
maybe repeated and mixed). The secret can be a hex string, mnemonic phrase or a string (to be padded)
method addPair
addPair: (pair: KeyringPair) => KeyringPair;
addPair Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
method createFromJson
createFromJson: ( { address, encoded, encoding: { content, type, version }, meta, }: KeyringPair$Json, ignoreChecksum?: boolean) => KeyringPair;
createFromJson Creates a pair from a JSON keyfile
method createFromPair
createFromPair: ( pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
createFromPair Creates a pair from an explicit publicKey/secreteKey combination
method createFromUri
createFromUri: ( _suri: string, meta?: KeyringPair$Meta, type?: KeypairType) => KeyringPair;
createFromUri Creates a Keypair from an suri This creates a pair from the suri, but does not add it to the keyring
method getPair
getPair: (address: string | Uint8Array) => KeyringPair;
getPair 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).
method getPairs
getPairs: () => 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.
method getPublicKeys
getPublicKeys: () => Uint8Array[];
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.
method removePair
removePair: (address: string | Uint8Array) => void;
removePair Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
method setSS58Format
setSS58Format: (ss58: number) => void;
setSS58Format; Sets the ss58 format for the keyring
method toJson
toJson: (address: string | Uint8Array, passphrase?: string) => KeyringPair$Json;
toJson 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.
Package Files (7)
Dependencies (3)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (2)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@polkadot/keyring
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@polkadot/keyring)
- HTML<a href="https://www.jsdocs.io/package/@polkadot/keyring"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4178 ms. - Missing or incorrect documentation? Open an issue for this package.