@pezkuwi/keyring 14.0.23 → 14.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle-pezkuwi-keyring.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/pair/defaults.d.ts +2 -2
- package/package.json +11 -11
- package/packageInfo.js +1 -1
- package/pair/defaults.d.ts +2 -2
- package/build/LICENSE +0 -201
- package/build/README.md +0 -17
- package/build/bundle.d.ts +0 -7
- package/build/bundle.js +0 -7
- package/build/cjs/bundle.d.ts +0 -7
- package/build/cjs/bundle.js +0 -19
- package/build/cjs/defaults.d.ts +0 -2
- package/build/cjs/defaults.js +0 -5
- package/build/cjs/index.d.ts +0 -4
- package/build/cjs/index.js +0 -7
- package/build/cjs/keyring.d.ts +0 -145
- package/build/cjs/keyring.js +0 -261
- package/build/cjs/package.json +0 -3
- package/build/cjs/packageDetect.d.ts +0 -1
- package/build/cjs/packageDetect.js +0 -7
- package/build/cjs/packageInfo.d.ts +0 -6
- package/build/cjs/packageInfo.js +0 -4
- package/build/cjs/pair/decode.d.ts +0 -12
- package/build/cjs/pair/decode.js +0 -45
- package/build/cjs/pair/defaults.d.ts +0 -12
- package/build/cjs/pair/defaults.js +0 -15
- package/build/cjs/pair/encode.d.ts +0 -5
- package/build/cjs/pair/encode.js +0 -22
- package/build/cjs/pair/index.d.ts +0 -40
- package/build/cjs/pair/index.js +0 -183
- package/build/cjs/pair/nobody.d.ts +0 -2
- package/build/cjs/pair/nobody.js +0 -43
- package/build/cjs/pair/toJson.d.ts +0 -8
- package/build/cjs/pair/toJson.js +0 -11
- package/build/cjs/pair/types.d.ts +0 -5
- package/build/cjs/pair/types.js +0 -2
- package/build/cjs/pairs.d.ts +0 -8
- package/build/cjs/pairs.js +0 -28
- package/build/cjs/testing.d.ts +0 -20
- package/build/cjs/testing.js +0 -126
- package/build/cjs/testingPairs.d.ts +0 -25
- package/build/cjs/testingPairs.js +0 -16
- package/build/cjs/types.d.ts +0 -111
- package/build/cjs/types.js +0 -2
- package/build/defaults.d.ts +0 -2
- package/build/defaults.js +0 -2
- package/build/index.d.ts +0 -4
- package/build/index.js +0 -4
- package/build/keyring.d.ts +0 -145
- package/build/keyring.js +0 -257
- package/build/package.json +0 -294
- package/build/packageDetect.d.ts +0 -1
- package/build/packageDetect.js +0 -5
- package/build/packageInfo.d.ts +0 -6
- package/build/packageInfo.js +0 -1
- package/build/pair/decode.d.ts +0 -12
- package/build/pair/decode.js +0 -42
- package/build/pair/defaults.d.ts +0 -12
- package/build/pair/defaults.js +0 -12
- package/build/pair/encode.d.ts +0 -5
- package/build/pair/encode.js +0 -19
- package/build/pair/index.d.ts +0 -40
- package/build/pair/index.js +0 -180
- package/build/pair/nobody.d.ts +0 -2
- package/build/pair/nobody.js +0 -40
- package/build/pair/toJson.d.ts +0 -8
- package/build/pair/toJson.js +0 -8
- package/build/pair/types.d.ts +0 -5
- package/build/pair/types.js +0 -1
- package/build/pairs.d.ts +0 -8
- package/build/pairs.js +0 -24
- package/build/testing.d.ts +0 -20
- package/build/testing.js +0 -122
- package/build/testingPairs.d.ts +0 -25
- package/build/testingPairs.js +0 -13
- package/build/types.d.ts +0 -111
- package/build/types.js +0 -1
- package/build-deno/README.md +0 -17
- package/build-deno/bundle.ts +0 -10
- package/build-deno/defaults.ts +0 -4
- package/build-deno/index.ts +0 -8
- package/build-deno/keyring.ts +0 -305
- package/build-deno/mod.ts +0 -2
- package/build-deno/packageDetect.ts +0 -9
- package/build-deno/packageInfo.ts +0 -3
- package/build-deno/pair/decode.ts +0 -54
- package/build-deno/pair/defaults.ts +0 -18
- package/build-deno/pair/encode.ts +0 -28
- package/build-deno/pair/index.ts +0 -218
- package/build-deno/pair/nobody.ts +0 -58
- package/build-deno/pair/toJson.ts +0 -18
- package/build-deno/pair/types.ts +0 -6
- package/build-deno/pairs.ts +0 -39
- package/build-deno/testing.ts +0 -150
- package/build-deno/testingPairs.ts +0 -54
- package/build-deno/types.ts +0 -129
- package/build-tsc/bundle.d.ts +0 -7
- package/build-tsc/defaults.d.ts +0 -2
- package/build-tsc/index.d.ts +0 -4
- package/build-tsc/keyring.d.ts +0 -145
- package/build-tsc/packageDetect.d.ts +0 -1
- package/build-tsc/packageInfo.d.ts +0 -6
- package/build-tsc/pair/decode.d.ts +0 -12
- package/build-tsc/pair/defaults.d.ts +0 -12
- package/build-tsc/pair/encode.d.ts +0 -5
- package/build-tsc/pair/index.d.ts +0 -40
- package/build-tsc/pair/nobody.d.ts +0 -2
- package/build-tsc/pair/toJson.d.ts +0 -8
- package/build-tsc/pair/types.d.ts +0 -5
- package/build-tsc/pairs.d.ts +0 -8
- package/build-tsc/testing.d.ts +0 -20
- package/build-tsc/testingPairs.d.ts +0 -25
- package/build-tsc/types.d.ts +0 -111
- package/build-tsc-cjs/bundle.js +0 -19
- package/build-tsc-cjs/defaults.js +0 -5
- package/build-tsc-cjs/index.js +0 -7
- package/build-tsc-cjs/keyring.js +0 -261
- package/build-tsc-cjs/packageDetect.js +0 -7
- package/build-tsc-cjs/packageInfo.js +0 -4
- package/build-tsc-cjs/pair/decode.js +0 -45
- package/build-tsc-cjs/pair/defaults.js +0 -15
- package/build-tsc-cjs/pair/encode.js +0 -22
- package/build-tsc-cjs/pair/index.js +0 -183
- package/build-tsc-cjs/pair/nobody.js +0 -43
- package/build-tsc-cjs/pair/toJson.js +0 -11
- package/build-tsc-cjs/pair/types.js +0 -2
- package/build-tsc-cjs/pairs.js +0 -28
- package/build-tsc-cjs/testing.js +0 -126
- package/build-tsc-cjs/testingPairs.js +0 -16
- package/build-tsc-cjs/types.js +0 -2
- package/build-tsc-esm/bundle.js +0 -7
- package/build-tsc-esm/defaults.js +0 -2
- package/build-tsc-esm/index.js +0 -4
- package/build-tsc-esm/keyring.js +0 -257
- package/build-tsc-esm/packageDetect.js +0 -5
- package/build-tsc-esm/packageInfo.js +0 -1
- package/build-tsc-esm/pair/decode.js +0 -42
- package/build-tsc-esm/pair/defaults.js +0 -12
- package/build-tsc-esm/pair/encode.js +0 -19
- package/build-tsc-esm/pair/index.js +0 -180
- package/build-tsc-esm/pair/nobody.js +0 -40
- package/build-tsc-esm/pair/toJson.js +0 -8
- package/build-tsc-esm/pair/types.js +0 -1
- package/build-tsc-esm/pairs.js +0 -24
- package/build-tsc-esm/testing.js +0 -122
- package/build-tsc-esm/testingPairs.js +0 -13
- package/build-tsc-esm/types.js +0 -1
- package/src/bundle.ts +0 -16
- package/src/defaults.ts +0 -8
- package/src/index.spec.ts +0 -609
- package/src/index.ts +0 -10
- package/src/keyring.ts +0 -307
- package/src/mod.ts +0 -4
- package/src/packageDetect.ts +0 -13
- package/src/packageInfo.ts +0 -6
- package/src/pair/decode.spec.ts +0 -26
- package/src/pair/decode.ts +0 -56
- package/src/pair/defaults.ts +0 -20
- package/src/pair/encode.spec.ts +0 -28
- package/src/pair/encode.ts +0 -30
- package/src/pair/index.spec.ts +0 -189
- package/src/pair/index.ts +0 -220
- package/src/pair/nobody.ts +0 -62
- package/src/pair/toJson.spec.ts +0 -42
- package/src/pair/toJson.ts +0 -20
- package/src/pair/types.ts +0 -8
- package/src/pair/vrf.spec.ts +0 -47
- package/src/pairs.ts +0 -41
- package/src/suri.spec.ts +0 -109
- package/src/testing.ts +0 -156
- package/src/testingPairs.spec.ts +0 -79
- package/src/testingPairs.ts +0 -56
- package/src/types.ts +0 -131
- package/tsconfig.build.json +0 -16
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.spec.json +0 -18
- package/tsconfig.spec.tsbuildinfo +0 -1
package/build/keyring.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { hexToU8a, isHex, stringToU8a } from '@pezkuwi/util';
|
|
2
|
-
import { base64Decode, decodeAddress, ed25519PairFromSeed as ed25519FromSeed, encodeAddress, ethereumEncode, hdEthereum, keyExtractSuri, keyFromPath, mnemonicToLegacySeed, mnemonicToMiniSecret, secp256k1PairFromSeed as secp256k1FromSeed, sr25519PairFromSeed as sr25519FromSeed } from '@pezkuwi/util-crypto';
|
|
3
|
-
import { createPair } from './pair/index.js';
|
|
4
|
-
import { DEV_PHRASE } from './defaults.js';
|
|
5
|
-
import { Pairs } from './pairs.js';
|
|
6
|
-
const PairFromSeed = {
|
|
7
|
-
ecdsa: (seed) => secp256k1FromSeed(seed),
|
|
8
|
-
ed25519: (seed) => ed25519FromSeed(seed),
|
|
9
|
-
ethereum: (seed) => secp256k1FromSeed(seed),
|
|
10
|
-
sr25519: (seed) => sr25519FromSeed(seed)
|
|
11
|
-
};
|
|
12
|
-
function pairToPublic({ publicKey }) {
|
|
13
|
-
return publicKey;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* # @pezkuwi/keyring
|
|
17
|
-
*
|
|
18
|
-
* ## Overview
|
|
19
|
-
*
|
|
20
|
-
* @name Keyring
|
|
21
|
-
* @summary Keyring management of user accounts
|
|
22
|
-
* @description Allows generation of keyring pairs from a variety of input combinations, such as
|
|
23
|
-
* json object containing account address or public key, account metadata, and account encoded using
|
|
24
|
-
* `addFromJson`, or by providing those values as arguments separately to `addFromAddress`,
|
|
25
|
-
* or by providing the mnemonic (seed phrase) and account metadata as arguments to `addFromMnemonic`.
|
|
26
|
-
* Stores the keyring pairs in a keyring pair dictionary. Removal of the keyring pairs from the keyring pair
|
|
27
|
-
* dictionary is achieved using `removePair`. Retrieval of all the stored pairs via `getPairs` or perform
|
|
28
|
-
* lookup of a pair for a given account address or public key using `getPair`. JSON metadata associated with
|
|
29
|
-
* an account may be obtained using `toJson` accompanied by the account passphrase.
|
|
30
|
-
*/
|
|
31
|
-
export class Keyring {
|
|
32
|
-
#pairs;
|
|
33
|
-
#type;
|
|
34
|
-
#ss58;
|
|
35
|
-
decodeAddress = decodeAddress;
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
options.type = options.type || 'ed25519';
|
|
38
|
-
if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
|
|
39
|
-
throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
|
|
40
|
-
}
|
|
41
|
-
this.#pairs = new Pairs();
|
|
42
|
-
this.#ss58 = options.ss58Format;
|
|
43
|
-
this.#type = options.type;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @description retrieve the pairs (alias for getPairs)
|
|
47
|
-
*/
|
|
48
|
-
get pairs() {
|
|
49
|
-
return this.getPairs();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @description retrieve the publicKeys (alias for getPublicKeys)
|
|
53
|
-
*/
|
|
54
|
-
get publicKeys() {
|
|
55
|
-
return this.getPublicKeys();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
|
59
|
-
*/
|
|
60
|
-
get type() {
|
|
61
|
-
return this.#type;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @name addPair
|
|
65
|
-
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
66
|
-
*/
|
|
67
|
-
addPair(pair) {
|
|
68
|
-
return this.#pairs.add(pair);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* @name addFromAddress
|
|
72
|
-
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
73
|
-
* @description Allows user to explicitly provide separate inputs including account address or public key, and optionally
|
|
74
|
-
* the associated account metadata, and the default encoded value as arguments (that may be obtained from the json file
|
|
75
|
-
* of an account backup), and then generates a keyring pair from them that it passes to
|
|
76
|
-
* `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.
|
|
77
|
-
*/
|
|
78
|
-
addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
|
|
79
|
-
const publicKey = this.decodeAddress(address, ignoreChecksum);
|
|
80
|
-
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @name addFromJson
|
|
84
|
-
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
85
|
-
* @description Allows user to provide a json object argument that contains account information (that may be obtained from the json file
|
|
86
|
-
* of an account backup), and then generates a keyring pair from it that it passes to
|
|
87
|
-
* `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.
|
|
88
|
-
*/
|
|
89
|
-
addFromJson(json, ignoreChecksum) {
|
|
90
|
-
return this.addPair(this.createFromJson(json, ignoreChecksum));
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* @name addFromMnemonic
|
|
94
|
-
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
95
|
-
* @description Allows user to provide a mnemonic (seed phrase that is provided when account is originally created)
|
|
96
|
-
* argument and a metadata argument that contains account information (that may be obtained from the json file
|
|
97
|
-
* of an account backup), and then generates a keyring pair from it that it passes to
|
|
98
|
-
* `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.
|
|
99
|
-
*/
|
|
100
|
-
addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
|
|
101
|
-
return this.addFromUri(mnemonic, meta, type, wordlist);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* @name addFromPair
|
|
105
|
-
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
|
106
|
-
*/
|
|
107
|
-
addFromPair(pair, meta = {}, type = this.type) {
|
|
108
|
-
return this.addPair(this.createFromPair(pair, meta, type));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* @name addFromSeed
|
|
112
|
-
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
|
113
|
-
* @description Stores in a keyring pair dictionary the public key of the pair as a key and the pair as the associated value.
|
|
114
|
-
* Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
|
|
115
|
-
* `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.
|
|
116
|
-
*/
|
|
117
|
-
addFromSeed(seed, meta = {}, type = this.type) {
|
|
118
|
-
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @name addFromUri
|
|
122
|
-
* @summary Creates an account via an suri
|
|
123
|
-
* @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)
|
|
124
|
-
*/
|
|
125
|
-
addFromUri(suri, meta = {}, type = this.type, wordlist) {
|
|
126
|
-
return this.addPair(this.createFromUri(suri, meta, type, wordlist));
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* @name createFromJson
|
|
130
|
-
* @description Creates a pair from a JSON keyfile
|
|
131
|
-
*/
|
|
132
|
-
createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
|
|
133
|
-
if (version === '3' && content[0] !== 'pkcs8') {
|
|
134
|
-
throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
|
|
135
|
-
}
|
|
136
|
-
const cryptoType = version === '0' || !Array.isArray(content)
|
|
137
|
-
? this.type
|
|
138
|
-
: content[1];
|
|
139
|
-
const encType = !Array.isArray(type)
|
|
140
|
-
? [type]
|
|
141
|
-
: type;
|
|
142
|
-
if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
|
|
143
|
-
throw new Error(`Unknown crypto type ${cryptoType}`);
|
|
144
|
-
}
|
|
145
|
-
// Here the address and publicKey are 32 bytes and isomorphic. This is why the address field needs to be the public key for ethereum type pairs
|
|
146
|
-
const publicKey = isHex(address)
|
|
147
|
-
? hexToU8a(address)
|
|
148
|
-
: this.decodeAddress(address, ignoreChecksum);
|
|
149
|
-
const decoded = isHex(encoded)
|
|
150
|
-
? hexToU8a(encoded)
|
|
151
|
-
: base64Decode(encoded);
|
|
152
|
-
return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @name createFromPair
|
|
156
|
-
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
|
157
|
-
*/
|
|
158
|
-
createFromPair(pair, meta = {}, type = this.type) {
|
|
159
|
-
return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* @name createFromUri
|
|
163
|
-
* @summary Creates a Keypair from an suri
|
|
164
|
-
* @description This creates a pair from the suri, but does not add it to the keyring
|
|
165
|
-
*/
|
|
166
|
-
createFromUri(_suri, meta = {}, type = this.type, wordlist) {
|
|
167
|
-
// here we only aut-add the dev phrase if we have a hard-derived path
|
|
168
|
-
const suri = _suri.startsWith('//')
|
|
169
|
-
? `${DEV_PHRASE}${_suri}`
|
|
170
|
-
: _suri;
|
|
171
|
-
const { derivePath, password, path, phrase } = keyExtractSuri(suri);
|
|
172
|
-
let seed;
|
|
173
|
-
const isPhraseHex = isHex(phrase, 256);
|
|
174
|
-
if (isPhraseHex) {
|
|
175
|
-
seed = hexToU8a(phrase);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const parts = phrase.split(' ');
|
|
179
|
-
if ([12, 15, 18, 21, 24].includes(parts.length)) {
|
|
180
|
-
seed = type === 'ethereum'
|
|
181
|
-
? mnemonicToLegacySeed(phrase, '', false, 64)
|
|
182
|
-
: mnemonicToMiniSecret(phrase, password, wordlist);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
if (phrase.length > 32) {
|
|
186
|
-
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
|
|
187
|
-
}
|
|
188
|
-
seed = stringToU8a(phrase.padEnd(32));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const derived = type === 'ethereum'
|
|
192
|
-
? isPhraseHex
|
|
193
|
-
? PairFromSeed[type](seed) // for eth, if the private key is provided as suri, it must be derived only once
|
|
194
|
-
: hdEthereum(seed, derivePath.substring(1))
|
|
195
|
-
: keyFromPath(PairFromSeed[type](seed), path, type);
|
|
196
|
-
return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* @name encodeAddress
|
|
200
|
-
* @description Encodes the input into an ss58 representation
|
|
201
|
-
*/
|
|
202
|
-
encodeAddress = (address, ss58Format) => {
|
|
203
|
-
return this.type === 'ethereum'
|
|
204
|
-
? ethereumEncode(address)
|
|
205
|
-
: encodeAddress(address, ss58Format ?? this.#ss58);
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* @name getPair
|
|
209
|
-
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
|
210
|
-
* @description Returns a keyring pair value from the keyring pair dictionary by performing
|
|
211
|
-
* a key lookup using the provided account address or public key (after decoding it).
|
|
212
|
-
*/
|
|
213
|
-
getPair(address) {
|
|
214
|
-
return this.#pairs.get(address);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* @name getPairs
|
|
218
|
-
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
|
219
|
-
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
|
220
|
-
*/
|
|
221
|
-
getPairs() {
|
|
222
|
-
return this.#pairs.all();
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* @name getPublicKeys
|
|
226
|
-
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
|
227
|
-
* @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.
|
|
228
|
-
*/
|
|
229
|
-
getPublicKeys() {
|
|
230
|
-
return this.#pairs.all().map(pairToPublic);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* @name removePair
|
|
234
|
-
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
|
235
|
-
*/
|
|
236
|
-
removePair(address) {
|
|
237
|
-
this.#pairs.remove(address);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* @name setSS58Format;
|
|
241
|
-
* @description Sets the ss58 format for the keyring
|
|
242
|
-
*/
|
|
243
|
-
setSS58Format(ss58) {
|
|
244
|
-
this.#ss58 = ss58;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* @name toJson
|
|
248
|
-
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
|
249
|
-
* @description Returns a JSON object containing the metadata associated with an account
|
|
250
|
-
* when valid address or public key and when the account passphrase is provided if the account secret
|
|
251
|
-
* is not already unlocked and available in memory. Note that in [Polkadot-JS Apps](https://github.com/polkadot-js/apps) the user
|
|
252
|
-
* may backup their account to a JSON file that contains this information.
|
|
253
|
-
*/
|
|
254
|
-
toJson(address, passphrase) {
|
|
255
|
-
return this.#pairs.get(address).toJson(passphrase);
|
|
256
|
-
}
|
|
257
|
-
}
|
package/build/package.json
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "Dijital Kurdistan Tech Institute <dev@pezkuwichain.io>",
|
|
3
|
-
"bugs": "https://github.com/pezkuwichain/pezkuwi-common/issues",
|
|
4
|
-
"description": "Keyring management",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=18"
|
|
7
|
-
},
|
|
8
|
-
"homepage": "https://github.com/pezkuwichain/pezkuwi-common/tree/master/packages/keyring#readme",
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"name": "@pezkuwi/keyring",
|
|
11
|
-
"repository": {
|
|
12
|
-
"directory": "packages/keyring",
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/pezkuwichain/pezkuwi-common.git"
|
|
15
|
-
},
|
|
16
|
-
"sideEffects": [
|
|
17
|
-
"./packageDetect.js",
|
|
18
|
-
"./cjs/packageDetect.js"
|
|
19
|
-
],
|
|
20
|
-
"type": "module",
|
|
21
|
-
"version": "14.0.23",
|
|
22
|
-
"main": "./cjs/index.js",
|
|
23
|
-
"module": "./cjs/index.js",
|
|
24
|
-
"types": "./cjs/index.d.ts",
|
|
25
|
-
"exports": {
|
|
26
|
-
"./cjs/package.json": "./cjs/package.json",
|
|
27
|
-
"./cjs/*": "./cjs/*.js",
|
|
28
|
-
".": {
|
|
29
|
-
"module": {
|
|
30
|
-
"types": "./index.d.ts",
|
|
31
|
-
"default": "./index.js"
|
|
32
|
-
},
|
|
33
|
-
"require": {
|
|
34
|
-
"types": "./cjs/index.d.ts",
|
|
35
|
-
"default": "./cjs/index.js"
|
|
36
|
-
},
|
|
37
|
-
"default": {
|
|
38
|
-
"types": "./index.d.ts",
|
|
39
|
-
"default": "./index.js"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
"./bundle": {
|
|
43
|
-
"module": {
|
|
44
|
-
"types": "./bundle.d.ts",
|
|
45
|
-
"default": "./bundle.js"
|
|
46
|
-
},
|
|
47
|
-
"require": {
|
|
48
|
-
"types": "./cjs/bundle.d.ts",
|
|
49
|
-
"default": "./cjs/bundle.js"
|
|
50
|
-
},
|
|
51
|
-
"default": {
|
|
52
|
-
"types": "./bundle.d.ts",
|
|
53
|
-
"default": "./bundle.js"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"./defaults": {
|
|
57
|
-
"module": {
|
|
58
|
-
"types": "./defaults.d.ts",
|
|
59
|
-
"default": "./defaults.js"
|
|
60
|
-
},
|
|
61
|
-
"require": {
|
|
62
|
-
"types": "./cjs/defaults.d.ts",
|
|
63
|
-
"default": "./cjs/defaults.js"
|
|
64
|
-
},
|
|
65
|
-
"default": {
|
|
66
|
-
"types": "./defaults.d.ts",
|
|
67
|
-
"default": "./defaults.js"
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
"./keyring": {
|
|
71
|
-
"module": {
|
|
72
|
-
"types": "./keyring.d.ts",
|
|
73
|
-
"default": "./keyring.js"
|
|
74
|
-
},
|
|
75
|
-
"require": {
|
|
76
|
-
"types": "./cjs/keyring.d.ts",
|
|
77
|
-
"default": "./cjs/keyring.js"
|
|
78
|
-
},
|
|
79
|
-
"default": {
|
|
80
|
-
"types": "./keyring.d.ts",
|
|
81
|
-
"default": "./keyring.js"
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
"./package.json": {
|
|
85
|
-
"require": "./cjs/package.json",
|
|
86
|
-
"default": "./package.json"
|
|
87
|
-
},
|
|
88
|
-
"./packageDetect": {
|
|
89
|
-
"module": {
|
|
90
|
-
"types": "./packageDetect.d.ts",
|
|
91
|
-
"default": "./packageDetect.js"
|
|
92
|
-
},
|
|
93
|
-
"require": {
|
|
94
|
-
"types": "./cjs/packageDetect.d.ts",
|
|
95
|
-
"default": "./cjs/packageDetect.js"
|
|
96
|
-
},
|
|
97
|
-
"default": {
|
|
98
|
-
"types": "./packageDetect.d.ts",
|
|
99
|
-
"default": "./packageDetect.js"
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
"./packageInfo.js": {
|
|
103
|
-
"module": {
|
|
104
|
-
"types": "./packageInfo.d.ts",
|
|
105
|
-
"default": "./packageInfo.js"
|
|
106
|
-
},
|
|
107
|
-
"require": {
|
|
108
|
-
"types": "./cjs/packageInfo.d.ts",
|
|
109
|
-
"default": "./cjs/packageInfo.js"
|
|
110
|
-
},
|
|
111
|
-
"default": {
|
|
112
|
-
"types": "./packageInfo.d.ts",
|
|
113
|
-
"default": "./packageInfo.js"
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
"./packageInfo": {
|
|
117
|
-
"module": {
|
|
118
|
-
"types": "./packageInfo.d.ts",
|
|
119
|
-
"default": "./packageInfo.js"
|
|
120
|
-
},
|
|
121
|
-
"require": {
|
|
122
|
-
"types": "./cjs/packageInfo.d.ts",
|
|
123
|
-
"default": "./cjs/packageInfo.js"
|
|
124
|
-
},
|
|
125
|
-
"default": {
|
|
126
|
-
"types": "./packageInfo.d.ts",
|
|
127
|
-
"default": "./packageInfo.js"
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
"./pair": {
|
|
131
|
-
"module": {
|
|
132
|
-
"types": "./pair/index.d.ts",
|
|
133
|
-
"default": "./pair/index.js"
|
|
134
|
-
},
|
|
135
|
-
"require": {
|
|
136
|
-
"types": "./cjs/pair/index.d.ts",
|
|
137
|
-
"default": "./cjs/pair/index.js"
|
|
138
|
-
},
|
|
139
|
-
"default": {
|
|
140
|
-
"types": "./pair/index.d.ts",
|
|
141
|
-
"default": "./pair/index.js"
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
"./pair/decode": {
|
|
145
|
-
"module": {
|
|
146
|
-
"types": "./pair/decode.d.ts",
|
|
147
|
-
"default": "./pair/decode.js"
|
|
148
|
-
},
|
|
149
|
-
"require": {
|
|
150
|
-
"types": "./cjs/pair/decode.d.ts",
|
|
151
|
-
"default": "./cjs/pair/decode.js"
|
|
152
|
-
},
|
|
153
|
-
"default": {
|
|
154
|
-
"types": "./pair/decode.d.ts",
|
|
155
|
-
"default": "./pair/decode.js"
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
"./pair/defaults": {
|
|
159
|
-
"module": {
|
|
160
|
-
"types": "./pair/defaults.d.ts",
|
|
161
|
-
"default": "./pair/defaults.js"
|
|
162
|
-
},
|
|
163
|
-
"require": {
|
|
164
|
-
"types": "./cjs/pair/defaults.d.ts",
|
|
165
|
-
"default": "./cjs/pair/defaults.js"
|
|
166
|
-
},
|
|
167
|
-
"default": {
|
|
168
|
-
"types": "./pair/defaults.d.ts",
|
|
169
|
-
"default": "./pair/defaults.js"
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
"./pair/encode": {
|
|
173
|
-
"module": {
|
|
174
|
-
"types": "./pair/encode.d.ts",
|
|
175
|
-
"default": "./pair/encode.js"
|
|
176
|
-
},
|
|
177
|
-
"require": {
|
|
178
|
-
"types": "./cjs/pair/encode.d.ts",
|
|
179
|
-
"default": "./cjs/pair/encode.js"
|
|
180
|
-
},
|
|
181
|
-
"default": {
|
|
182
|
-
"types": "./pair/encode.d.ts",
|
|
183
|
-
"default": "./pair/encode.js"
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
"./pair/nobody": {
|
|
187
|
-
"module": {
|
|
188
|
-
"types": "./pair/nobody.d.ts",
|
|
189
|
-
"default": "./pair/nobody.js"
|
|
190
|
-
},
|
|
191
|
-
"require": {
|
|
192
|
-
"types": "./cjs/pair/nobody.d.ts",
|
|
193
|
-
"default": "./cjs/pair/nobody.js"
|
|
194
|
-
},
|
|
195
|
-
"default": {
|
|
196
|
-
"types": "./pair/nobody.d.ts",
|
|
197
|
-
"default": "./pair/nobody.js"
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
"./pair/toJson": {
|
|
201
|
-
"module": {
|
|
202
|
-
"types": "./pair/toJson.d.ts",
|
|
203
|
-
"default": "./pair/toJson.js"
|
|
204
|
-
},
|
|
205
|
-
"require": {
|
|
206
|
-
"types": "./cjs/pair/toJson.d.ts",
|
|
207
|
-
"default": "./cjs/pair/toJson.js"
|
|
208
|
-
},
|
|
209
|
-
"default": {
|
|
210
|
-
"types": "./pair/toJson.d.ts",
|
|
211
|
-
"default": "./pair/toJson.js"
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
"./pair/types": {
|
|
215
|
-
"module": {
|
|
216
|
-
"types": "./pair/types.d.ts",
|
|
217
|
-
"default": "./pair/types.js"
|
|
218
|
-
},
|
|
219
|
-
"require": {
|
|
220
|
-
"types": "./cjs/pair/types.d.ts",
|
|
221
|
-
"default": "./cjs/pair/types.js"
|
|
222
|
-
},
|
|
223
|
-
"default": {
|
|
224
|
-
"types": "./pair/types.d.ts",
|
|
225
|
-
"default": "./pair/types.js"
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
"./pairs": {
|
|
229
|
-
"module": {
|
|
230
|
-
"types": "./pairs.d.ts",
|
|
231
|
-
"default": "./pairs.js"
|
|
232
|
-
},
|
|
233
|
-
"require": {
|
|
234
|
-
"types": "./cjs/pairs.d.ts",
|
|
235
|
-
"default": "./cjs/pairs.js"
|
|
236
|
-
},
|
|
237
|
-
"default": {
|
|
238
|
-
"types": "./pairs.d.ts",
|
|
239
|
-
"default": "./pairs.js"
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
"./testing": {
|
|
243
|
-
"module": {
|
|
244
|
-
"types": "./testing.d.ts",
|
|
245
|
-
"default": "./testing.js"
|
|
246
|
-
},
|
|
247
|
-
"require": {
|
|
248
|
-
"types": "./cjs/testing.d.ts",
|
|
249
|
-
"default": "./cjs/testing.js"
|
|
250
|
-
},
|
|
251
|
-
"default": {
|
|
252
|
-
"types": "./testing.d.ts",
|
|
253
|
-
"default": "./testing.js"
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
"./testingPairs": {
|
|
257
|
-
"module": {
|
|
258
|
-
"types": "./testingPairs.d.ts",
|
|
259
|
-
"default": "./testingPairs.js"
|
|
260
|
-
},
|
|
261
|
-
"require": {
|
|
262
|
-
"types": "./cjs/testingPairs.d.ts",
|
|
263
|
-
"default": "./cjs/testingPairs.js"
|
|
264
|
-
},
|
|
265
|
-
"default": {
|
|
266
|
-
"types": "./testingPairs.d.ts",
|
|
267
|
-
"default": "./testingPairs.js"
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
"./types": {
|
|
271
|
-
"module": {
|
|
272
|
-
"types": "./types.d.ts",
|
|
273
|
-
"default": "./types.js"
|
|
274
|
-
},
|
|
275
|
-
"require": {
|
|
276
|
-
"types": "./cjs/types.d.ts",
|
|
277
|
-
"default": "./cjs/types.js"
|
|
278
|
-
},
|
|
279
|
-
"default": {
|
|
280
|
-
"types": "./types.d.ts",
|
|
281
|
-
"default": "./types.js"
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
"dependencies": {
|
|
286
|
-
"@pezkuwi/util": "14.0.23",
|
|
287
|
-
"@pezkuwi/util-crypto": "14.0.23",
|
|
288
|
-
"tslib": "^2.8.0"
|
|
289
|
-
},
|
|
290
|
-
"peerDependencies": {
|
|
291
|
-
"@pezkuwi/util": "14.0.23",
|
|
292
|
-
"@pezkuwi/util-crypto": "14.0.23"
|
|
293
|
-
}
|
|
294
|
-
}
|
package/build/packageDetect.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/build/packageDetect.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { detectPackage } from '@pezkuwi/util';
|
|
2
|
-
import { packageInfo as utilInfo } from '@pezkuwi/util/packageInfo';
|
|
3
|
-
import { packageInfo as cryptoInfo } from '@pezkuwi/util-crypto/packageInfo';
|
|
4
|
-
import { packageInfo } from './packageInfo.js';
|
|
5
|
-
detectPackage(packageInfo, null, [cryptoInfo, utilInfo]);
|
package/build/packageInfo.d.ts
DELETED
package/build/packageInfo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const packageInfo = { name: '@pezkuwi/keyring', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.23' };
|
package/build/pair/decode.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { EncryptedJsonEncoding } from '@pezkuwi/util-crypto/types';
|
|
2
|
-
/**
|
|
3
|
-
* Decode a pair, taking into account the generation-specific formats and headers
|
|
4
|
-
*
|
|
5
|
-
* For divisor/headers, don't rely on the magic being static. These will
|
|
6
|
-
* change between generations, aka with the long-awaited 4th generation
|
|
7
|
-
* of the format. The external decode interface is the only way to use and decode these.
|
|
8
|
-
**/
|
|
9
|
-
export declare function decodePair(passphrase?: string, encrypted?: Uint8Array | null, _encType?: EncryptedJsonEncoding | EncryptedJsonEncoding[]): {
|
|
10
|
-
publicKey: Uint8Array;
|
|
11
|
-
secretKey: Uint8Array;
|
|
12
|
-
};
|
package/build/pair/decode.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { u8aEq } from '@pezkuwi/util';
|
|
2
|
-
import { jsonDecryptData } from '@pezkuwi/util-crypto';
|
|
3
|
-
import { PAIR_DIV, PAIR_HDR, PUB_LENGTH, SEC_LENGTH, SEED_LENGTH } from './defaults.js';
|
|
4
|
-
const SEED_OFFSET = PAIR_HDR.length;
|
|
5
|
-
/**
|
|
6
|
-
* Decode a pair, taking into account the generation-specific formats and headers
|
|
7
|
-
*
|
|
8
|
-
* For divisor/headers, don't rely on the magic being static. These will
|
|
9
|
-
* change between generations, aka with the long-awaited 4th generation
|
|
10
|
-
* of the format. The external decode interface is the only way to use and decode these.
|
|
11
|
-
**/
|
|
12
|
-
export function decodePair(passphrase, encrypted, _encType) {
|
|
13
|
-
const encType = Array.isArray(_encType) || _encType === undefined
|
|
14
|
-
? _encType
|
|
15
|
-
: [_encType];
|
|
16
|
-
const decrypted = jsonDecryptData(encrypted, passphrase, encType);
|
|
17
|
-
const header = decrypted.subarray(0, PAIR_HDR.length);
|
|
18
|
-
// check the start header (generations 1-3)
|
|
19
|
-
if (!u8aEq(header, PAIR_HDR)) {
|
|
20
|
-
throw new Error('Invalid encoding header found in body');
|
|
21
|
-
}
|
|
22
|
-
// setup for generation 3 format
|
|
23
|
-
let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
|
|
24
|
-
let divOffset = SEED_OFFSET + SEC_LENGTH;
|
|
25
|
-
let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
|
26
|
-
// old-style (generation 1 & 2), we have the seed here
|
|
27
|
-
if (!u8aEq(divider, PAIR_DIV)) {
|
|
28
|
-
divOffset = SEED_OFFSET + SEED_LENGTH;
|
|
29
|
-
secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
|
|
30
|
-
divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
|
31
|
-
// check the divisior at this point (already checked for generation 3)
|
|
32
|
-
if (!u8aEq(divider, PAIR_DIV)) {
|
|
33
|
-
throw new Error('Invalid encoding divider found in body');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const pubOffset = divOffset + PAIR_DIV.length;
|
|
37
|
-
const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
|
|
38
|
-
return {
|
|
39
|
-
publicKey,
|
|
40
|
-
secretKey
|
|
41
|
-
};
|
|
42
|
-
}
|
package/build/pair/defaults.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
|
2
|
-
export declare const PAIR_DIV: Uint8Array<ArrayBuffer>;
|
|
3
|
-
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
|
4
|
-
export declare const PAIR_HDR: Uint8Array<ArrayBuffer>;
|
|
5
|
-
/** length of a public key */
|
|
6
|
-
export declare const PUB_LENGTH = 32;
|
|
7
|
-
/** length of a salt */
|
|
8
|
-
export declare const SALT_LENGTH = 32;
|
|
9
|
-
/** length of a secret key */
|
|
10
|
-
export declare const SEC_LENGTH = 64;
|
|
11
|
-
/** length of a user-input seed */
|
|
12
|
-
export declare const SEED_LENGTH = 32;
|
package/build/pair/defaults.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
|
2
|
-
export const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
|
|
3
|
-
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
|
4
|
-
export const PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
|
5
|
-
/** length of a public key */
|
|
6
|
-
export const PUB_LENGTH = 32;
|
|
7
|
-
/** length of a salt */
|
|
8
|
-
export const SALT_LENGTH = 32;
|
|
9
|
-
/** length of a secret key */
|
|
10
|
-
export const SEC_LENGTH = 64;
|
|
11
|
-
/** length of a user-input seed */
|
|
12
|
-
export const SEED_LENGTH = 32;
|