UNPKG

8.34 kBTypeScriptView Raw
1import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@polkadot/util-crypto/types';
2import type { KeyringInstance, KeyringOptions, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from './types';
3import { decodeAddress } from '@polkadot/util-crypto';
4/**
5 * # @polkadot/keyring
6 *
7 * ## Overview
8 *
9 * @name Keyring
10 * @summary Keyring management of user accounts
11 * @description Allows generation of keyring pairs from a variety of input combinations, such as
12 * json object containing account address or public key, account metadata, and account encoded using
13 * `addFromJson`, or by providing those values as arguments separately to `addFromAddress`,
14 * or by providing the mnemonic (seed phrase) and account metadata as arguments to `addFromMnemonic`.
15 * Stores the keyring pairs in a keyring pair dictionary. Removal of the keyring pairs from the keyring pair
16 * dictionary is achieved using `removePair`. Retrieval of all the stored pairs via `getPairs` or perform
17 * lookup of a pair for a given account address or public key using `getPair`. JSON metadata associated with
18 * an account may be obtained using `toJson` accompanied by the account passphrase.
19 */
20export declare class Keyring implements KeyringInstance {
21 #private;
22 decodeAddress: typeof decodeAddress;
23 constructor(options?: KeyringOptions);
24 /**
25 * @description retrieve the pairs (alias for getPairs)
26 */
27 get pairs(): KeyringPair[];
28 /**
29 * @description retrieve the publicKeys (alias for getPublicKeys)
30 */
31 get publicKeys(): Uint8Array[];
32 /**
33 * @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
34 */
35 get type(): KeypairType;
36 /**
37 * @name addPair
38 * @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
39 */
40 addPair(pair: KeyringPair): KeyringPair;
41 /**
42 * @name addFromAddress
43 * @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
44 * @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
45 * the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
46 * of an account backup), and then generates a keyring pair from them that it passes to
47 * `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.
48 */
49 addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean, encType?: EncryptedJsonEncoding[]): KeyringPair;
50 /**
51 * @name addFromJson
52 * @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
53 * @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
54 * of an account backup), and then generates a keyring pair from it that it passes to
55 * `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.
56 */
57 addFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
58 /**
59 * @name addFromMnemonic
60 * @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
61 * @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
62 * argument and a metadata argument that contains account information (that may be obtained from the json file
63 * of an account backup), and then generates a keyring pair from it that it passes to
64 * `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.
65 */
66 addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
67 /**
68 * @name addFromPair
69 * @summary Stores an account created from an explicit publicKey/secreteKey combination
70 */
71 addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
72 /**
73 * @name addFromSeed
74 * @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
75 * @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
76 * Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
77 * `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.
78 */
79 addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
80 /**
81 * @name addFromUri
82 * @summary Creates an account via an suri
83 * @description 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)
84 */
85 addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
86 /**
87 * @name createFromJson
88 * @description Creates a pair from a JSON keyfile
89 */
90 createFromJson({ address, encoded, encoding: { content, type, version }, meta }: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
91 /**
92 * @name createFromPair
93 * @summary Creates a pair from an explicit publicKey/secreteKey combination
94 */
95 createFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
96 /**
97 * @name createFromUri
98 * @summary Creates a Keypair from an suri
99 * @description This creates a pair from the suri, but does not add it to the keyring
100 */
101 createFromUri(_suri: string, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
102 /**
103 * @name encodeAddress
104 * @description Encodes the input into an ss58 representation
105 */
106 encodeAddress: (address: Uint8Array | string, ss58Format?: number) => string;
107 /**
108 * @name getPair
109 * @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
110 * @description Returns a keyring pair value from the keyring pair dictionary by performing
111 * a key lookup using the provided account address or public key (after decoding it).
112 */
113 getPair(address: string | Uint8Array): KeyringPair;
114 /**
115 * @name getPairs
116 * @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
117 * @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
118 */
119 getPairs(): KeyringPair[];
120 /**
121 * @name getPublicKeys
122 * @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
123 * @description 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.
124 */
125 getPublicKeys(): Uint8Array[];
126 /**
127 * @name removePair
128 * @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
129 */
130 removePair(address: string | Uint8Array): void;
131 /**
132 * @name setSS58Format;
133 * @description Sets the ss58 format for the keyring
134 */
135 setSS58Format(ss58: number): void;
136 /**
137 * @name toJson
138 * @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
139 * @description Returns a JSON object containing the metadata associated with an account
140 * when valid address or public key and when the account passphrase is provided if the account secret
141 * is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
142 * may backup their account to a JSON file that contains this information.
143 */
144 toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
145}
146
\No newline at end of file