mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-10-20 18:56:18 +00:00
Remove build output committed beside the sources
19c8d69 (2026-01-11) and later commits added the build's output to every
package directory: 1484 .js/.d.ts files under cjs/ and at the package roots,
plus 14 copies of LICENSE (identical to the root one, which the build copies
into each package itself). Upstream keeps none of it. With the source
manifests pointing at them, imports resolved to this stale output instead of
src, and a JavaScript-checking build (@pezkuwi/dev 0.85.12) reads them as
inputs (TS5055).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
134f0ae3ce
commit
8c0bb78993
1498 files changed
-50566
No files matched your search
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -1,553 +0,0 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@pezkuwi/util-crypto'), require('@pezkuwi/util')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', '@pezkuwi/util-crypto', '@pezkuwi/util'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pezkuwiKeyring = {}, global.pezkuwiUtilCrypto, global.pezkuwiUtil));
|
||||
})(this, (function (exports, utilCrypto, util) { 'use strict';
|
||||
|
||||
const global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : window;
|
||||
|
||||
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
||||
const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
const PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
const PUB_LENGTH = 32;
|
||||
const SEC_LENGTH = 64;
|
||||
const SEED_LENGTH = 32;
|
||||
|
||||
const SEED_OFFSET = PAIR_HDR.length;
|
||||
function decodePair(passphrase, encrypted, _encType) {
|
||||
const encType = Array.isArray(_encType) || _encType === undefined
|
||||
? _encType
|
||||
: [_encType];
|
||||
const decrypted = utilCrypto.jsonDecryptData(encrypted, passphrase, encType);
|
||||
const header = decrypted.subarray(0, PAIR_HDR.length);
|
||||
if (!util.u8aEq(header, PAIR_HDR)) {
|
||||
throw new Error('Invalid encoding header found in body');
|
||||
}
|
||||
let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
|
||||
let divOffset = SEED_OFFSET + SEC_LENGTH;
|
||||
let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
||||
if (!util.u8aEq(divider, PAIR_DIV)) {
|
||||
divOffset = SEED_OFFSET + SEED_LENGTH;
|
||||
secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
|
||||
divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
||||
if (!util.u8aEq(divider, PAIR_DIV)) {
|
||||
throw new Error('Invalid encoding divider found in body');
|
||||
}
|
||||
}
|
||||
const pubOffset = divOffset + PAIR_DIV.length;
|
||||
const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
|
||||
return {
|
||||
publicKey,
|
||||
secretKey
|
||||
};
|
||||
}
|
||||
|
||||
function encodePair({ publicKey, secretKey }, passphrase) {
|
||||
if (!secretKey) {
|
||||
throw new Error('Expected a valid secretKey to be passed to encode');
|
||||
}
|
||||
const encoded = util.u8aConcat(PAIR_HDR, secretKey, PAIR_DIV, publicKey);
|
||||
if (!passphrase) {
|
||||
return encoded;
|
||||
}
|
||||
const { params, password, salt } = utilCrypto.scryptEncode(passphrase);
|
||||
const { encrypted, nonce } = utilCrypto.naclEncrypt(encoded, password.subarray(0, 32));
|
||||
return util.u8aConcat(utilCrypto.scryptToU8a(salt, params), nonce, encrypted);
|
||||
}
|
||||
|
||||
function pairToJson(type, { address, meta }, encoded, isEncrypted) {
|
||||
return util.objectSpread(utilCrypto.jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
|
||||
address,
|
||||
meta
|
||||
});
|
||||
}
|
||||
|
||||
const SIG_TYPE_NONE = new Uint8Array();
|
||||
const TYPE_FROM_SEED = {
|
||||
ecdsa: utilCrypto.secp256k1PairFromSeed,
|
||||
ed25519: utilCrypto.ed25519PairFromSeed,
|
||||
ethereum: utilCrypto.secp256k1PairFromSeed,
|
||||
sr25519: utilCrypto.sr25519PairFromSeed
|
||||
};
|
||||
const TYPE_PREFIX = {
|
||||
ecdsa: new Uint8Array([2]),
|
||||
ed25519: new Uint8Array([0]),
|
||||
ethereum: new Uint8Array([2]),
|
||||
sr25519: new Uint8Array([1])
|
||||
};
|
||||
const TYPE_SIGNATURE = {
|
||||
ecdsa: (m, p) => utilCrypto.secp256k1Sign(m, p, 'blake2'),
|
||||
ed25519: utilCrypto.ed25519Sign,
|
||||
ethereum: (m, p) => utilCrypto.secp256k1Sign(m, p, 'keccak'),
|
||||
sr25519: utilCrypto.sr25519Sign
|
||||
};
|
||||
const TYPE_ADDRESS = {
|
||||
ecdsa: (p) => p.length > 32 ? utilCrypto.blake2AsU8a(p) : p,
|
||||
ed25519: (p) => p,
|
||||
ethereum: (p) => p.length === 20 ? p : utilCrypto.keccakAsU8a(utilCrypto.secp256k1Expand(p)),
|
||||
sr25519: (p) => p
|
||||
};
|
||||
function isLocked(secretKey) {
|
||||
return !secretKey || util.u8aEmpty(secretKey);
|
||||
}
|
||||
function vrfHash(proof, context, extra) {
|
||||
return utilCrypto.blake2AsU8a(util.u8aConcat(context || '', extra || '', proof));
|
||||
}
|
||||
function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
|
||||
const decodePkcs8 = (passphrase, userEncoded) => {
|
||||
const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);
|
||||
if (decoded.secretKey.length === 64) {
|
||||
publicKey = decoded.publicKey;
|
||||
secretKey = decoded.secretKey;
|
||||
}
|
||||
else {
|
||||
const pair = TYPE_FROM_SEED[type](decoded.secretKey);
|
||||
publicKey = pair.publicKey;
|
||||
secretKey = pair.secretKey;
|
||||
}
|
||||
};
|
||||
const recode = (passphrase) => {
|
||||
isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
|
||||
encoded = encodePair({ publicKey, secretKey }, passphrase);
|
||||
encTypes = undefined;
|
||||
return encoded;
|
||||
};
|
||||
const encodeAddress = () => {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? utilCrypto.ethereumEncode(raw)
|
||||
: toSS58(raw);
|
||||
};
|
||||
return {
|
||||
get address() {
|
||||
return encodeAddress();
|
||||
},
|
||||
get addressRaw() {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? raw.slice(-20)
|
||||
: raw;
|
||||
},
|
||||
get isLocked() {
|
||||
return isLocked(secretKey);
|
||||
},
|
||||
get meta() {
|
||||
return meta;
|
||||
},
|
||||
get publicKey() {
|
||||
return publicKey;
|
||||
},
|
||||
get type() {
|
||||
return type;
|
||||
},
|
||||
decodePkcs8,
|
||||
derive: (suri, meta) => {
|
||||
if (type === 'ethereum') {
|
||||
throw new Error('Unable to derive on this keypair');
|
||||
}
|
||||
else if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot derive on a locked keypair');
|
||||
}
|
||||
const { path } = utilCrypto.keyExtractPath(suri);
|
||||
const derived = utilCrypto.keyFromPath({ publicKey, secretKey }, path, type);
|
||||
return createPair({ toSS58, type }, derived, meta, null);
|
||||
},
|
||||
encodePkcs8: (passphrase) => {
|
||||
return recode(passphrase);
|
||||
},
|
||||
lock: () => {
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional) => {
|
||||
meta = util.objectSpread({}, meta, additional);
|
||||
},
|
||||
sign: (message, options = {}) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
return util.u8aConcat(options.withType
|
||||
? TYPE_PREFIX[type]
|
||||
: SIG_TYPE_NONE, TYPE_SIGNATURE[type](util.u8aToU8a(message), { publicKey, secretKey }));
|
||||
},
|
||||
toJson: (passphrase) => {
|
||||
const address = ['ecdsa', 'ethereum'].includes(type)
|
||||
? publicKey.length === 20
|
||||
? util.u8aToHex(publicKey)
|
||||
: util.u8aToHex(utilCrypto.secp256k1Compress(publicKey))
|
||||
: encodeAddress();
|
||||
return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
|
||||
},
|
||||
unlock: (passphrase) => {
|
||||
return decodePkcs8(passphrase);
|
||||
},
|
||||
verify: (message, signature, signerPublic) => {
|
||||
return utilCrypto.signatureVerify(message, signature, TYPE_ADDRESS[type](util.u8aToU8a(signerPublic))).isValid;
|
||||
},
|
||||
vrfSign: (message, context, extra) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
if (type === 'sr25519') {
|
||||
return utilCrypto.sr25519VrfSign(message, { secretKey }, context, extra);
|
||||
}
|
||||
const proof = TYPE_SIGNATURE[type](util.u8aToU8a(message), { publicKey, secretKey });
|
||||
return util.u8aConcat(vrfHash(proof, context, extra), proof);
|
||||
},
|
||||
vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
|
||||
if (type === 'sr25519') {
|
||||
return utilCrypto.sr25519VrfVerify(message, vrfResult, publicKey, context, extra);
|
||||
}
|
||||
const result = utilCrypto.signatureVerify(message, util.u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](util.u8aToU8a(signerPublic)));
|
||||
return result.isValid && util.u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
const DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
||||
|
||||
class Pairs {
|
||||
#map = {};
|
||||
add(pair) {
|
||||
this.#map[utilCrypto.decodeAddress(pair.address).toString()] = pair;
|
||||
return pair;
|
||||
}
|
||||
all() {
|
||||
return Object.values(this.#map);
|
||||
}
|
||||
get(address) {
|
||||
const pair = this.#map[utilCrypto.decodeAddress(address).toString()];
|
||||
if (!pair) {
|
||||
throw new Error(`Unable to retrieve keypair '${util.isU8a(address) || util.isHex(address)
|
||||
? util.u8aToHex(util.u8aToU8a(address))
|
||||
: address}'`);
|
||||
}
|
||||
return pair;
|
||||
}
|
||||
remove(address) {
|
||||
delete this.#map[utilCrypto.decodeAddress(address).toString()];
|
||||
}
|
||||
}
|
||||
|
||||
const PairFromSeed = {
|
||||
ecdsa: (seed) => utilCrypto.secp256k1PairFromSeed(seed),
|
||||
ed25519: (seed) => utilCrypto.ed25519PairFromSeed(seed),
|
||||
ethereum: (seed) => utilCrypto.secp256k1PairFromSeed(seed),
|
||||
sr25519: (seed) => utilCrypto.sr25519PairFromSeed(seed)
|
||||
};
|
||||
function pairToPublic({ publicKey }) {
|
||||
return publicKey;
|
||||
}
|
||||
class Keyring {
|
||||
#pairs;
|
||||
#type;
|
||||
#ss58;
|
||||
decodeAddress = utilCrypto.decodeAddress;
|
||||
constructor(options = {}) {
|
||||
options.type = options.type || 'ed25519';
|
||||
if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
|
||||
throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
|
||||
}
|
||||
this.#pairs = new Pairs();
|
||||
this.#ss58 = options.ss58Format;
|
||||
this.#type = options.type;
|
||||
}
|
||||
get pairs() {
|
||||
return this.getPairs();
|
||||
}
|
||||
get publicKeys() {
|
||||
return this.getPublicKeys();
|
||||
}
|
||||
get type() {
|
||||
return this.#type;
|
||||
}
|
||||
addPair(pair) {
|
||||
return this.#pairs.add(pair);
|
||||
}
|
||||
addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
|
||||
const publicKey = this.decodeAddress(address, ignoreChecksum);
|
||||
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
|
||||
}
|
||||
addFromJson(json, ignoreChecksum) {
|
||||
return this.addPair(this.createFromJson(json, ignoreChecksum));
|
||||
}
|
||||
addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
|
||||
return this.addFromUri(mnemonic, meta, type, wordlist);
|
||||
}
|
||||
addFromPair(pair, meta = {}, type = this.type) {
|
||||
return this.addPair(this.createFromPair(pair, meta, type));
|
||||
}
|
||||
addFromSeed(seed, meta = {}, type = this.type) {
|
||||
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
|
||||
}
|
||||
addFromUri(suri, meta = {}, type = this.type, wordlist) {
|
||||
return this.addPair(this.createFromUri(suri, meta, type, wordlist));
|
||||
}
|
||||
createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
|
||||
if (version === '3' && content[0] !== 'pkcs8') {
|
||||
throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
|
||||
}
|
||||
const cryptoType = version === '0' || !Array.isArray(content)
|
||||
? this.type
|
||||
: content[1];
|
||||
const encType = !Array.isArray(type)
|
||||
? [type]
|
||||
: type;
|
||||
if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
|
||||
throw new Error(`Unknown crypto type ${cryptoType}`);
|
||||
}
|
||||
const publicKey = util.isHex(address)
|
||||
? util.hexToU8a(address)
|
||||
: this.decodeAddress(address, ignoreChecksum);
|
||||
const decoded = util.isHex(encoded)
|
||||
? util.hexToU8a(encoded)
|
||||
: utilCrypto.base64Decode(encoded);
|
||||
return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
|
||||
}
|
||||
createFromPair(pair, meta = {}, type = this.type) {
|
||||
return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
|
||||
}
|
||||
createFromUri(_suri, meta = {}, type = this.type, wordlist) {
|
||||
const suri = _suri.startsWith('//')
|
||||
? `${DEV_PHRASE}${_suri}`
|
||||
: _suri;
|
||||
const { derivePath, password, path, phrase } = utilCrypto.keyExtractSuri(suri);
|
||||
let seed;
|
||||
const isPhraseHex = util.isHex(phrase, 256);
|
||||
if (isPhraseHex) {
|
||||
seed = util.hexToU8a(phrase);
|
||||
}
|
||||
else {
|
||||
const parts = phrase.split(' ');
|
||||
if ([12, 15, 18, 21, 24].includes(parts.length)) {
|
||||
seed = type === 'ethereum'
|
||||
? utilCrypto.mnemonicToLegacySeed(phrase, '', false, 64)
|
||||
: utilCrypto.mnemonicToMiniSecret(phrase, password, wordlist);
|
||||
}
|
||||
else {
|
||||
if (phrase.length > 32) {
|
||||
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
|
||||
}
|
||||
seed = util.stringToU8a(phrase.padEnd(32));
|
||||
}
|
||||
}
|
||||
const derived = type === 'ethereum'
|
||||
? isPhraseHex
|
||||
? PairFromSeed[type](seed)
|
||||
: utilCrypto.hdEthereum(seed, derivePath.substring(1))
|
||||
: utilCrypto.keyFromPath(PairFromSeed[type](seed), path, type);
|
||||
return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
|
||||
}
|
||||
encodeAddress = (address, ss58Format) => {
|
||||
return this.type === 'ethereum'
|
||||
? utilCrypto.ethereumEncode(address)
|
||||
: utilCrypto.encodeAddress(address, ss58Format ?? this.#ss58);
|
||||
};
|
||||
getPair(address) {
|
||||
return this.#pairs.get(address);
|
||||
}
|
||||
getPairs() {
|
||||
return this.#pairs.all();
|
||||
}
|
||||
getPublicKeys() {
|
||||
return this.#pairs.all().map(pairToPublic);
|
||||
}
|
||||
removePair(address) {
|
||||
this.#pairs.remove(address);
|
||||
}
|
||||
setSS58Format(ss58) {
|
||||
this.#ss58 = ss58;
|
||||
}
|
||||
toJson(address, passphrase) {
|
||||
return this.#pairs.get(address).toJson(passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
const packageInfo = { name: '@pezkuwi/keyring', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('bundle-pezkuwi-keyring.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '14.0.10' };
|
||||
|
||||
const PAIRSSR25519 = [
|
||||
{
|
||||
p: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
||||
s: '0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011',
|
||||
seed: 'Alice',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f',
|
||||
s: '0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd',
|
||||
seed: 'Alice//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48',
|
||||
s: '0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325',
|
||||
seed: 'Bob',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e',
|
||||
s: '0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde',
|
||||
seed: 'Bob//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22',
|
||||
s: '0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c',
|
||||
seed: 'Charlie',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20',
|
||||
s: '0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568',
|
||||
seed: 'Dave',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e',
|
||||
s: '0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587',
|
||||
seed: 'Eve',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
|
||||
s: '0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426',
|
||||
seed: 'Ferdie',
|
||||
type: 'sr25519'
|
||||
}
|
||||
];
|
||||
const PAIRSETHEREUM = [
|
||||
{
|
||||
name: 'Alith',
|
||||
p: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
||||
s: '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133',
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Baltathar',
|
||||
p: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
||||
s: '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b',
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Charleth',
|
||||
p: '0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e',
|
||||
s: '0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b',
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Dorothy',
|
||||
p: '0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c',
|
||||
s: '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68',
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Ethan',
|
||||
p: '0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa',
|
||||
s: '0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4',
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Faith',
|
||||
p: '0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74',
|
||||
s: '0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df',
|
||||
type: 'ethereum'
|
||||
}
|
||||
];
|
||||
function createMeta(name, seed) {
|
||||
if (!name && !seed) {
|
||||
throw new Error('Testing pair should have either a name or a seed');
|
||||
}
|
||||
return {
|
||||
isTesting: true,
|
||||
name: name || seed?.replace('//', '_').toLowerCase()
|
||||
};
|
||||
}
|
||||
function createTestKeyring(options = {}, isDerived = true) {
|
||||
const keyring = new Keyring(options);
|
||||
const pairs = options.type === 'ethereum'
|
||||
? PAIRSETHEREUM
|
||||
: PAIRSSR25519;
|
||||
for (const { name, p, s, seed, type } of pairs) {
|
||||
const meta = createMeta(name, seed);
|
||||
const pair = !isDerived && !name && seed
|
||||
? keyring.addFromUri(seed, meta, options.type)
|
||||
: keyring.addPair(createPair({ toSS58: keyring.encodeAddress, type }, { publicKey: util.hexToU8a(p), secretKey: util.hexToU8a(s) }, meta));
|
||||
pair.lock = () => {
|
||||
};
|
||||
}
|
||||
return keyring;
|
||||
}
|
||||
|
||||
const publicKey = new Uint8Array(32);
|
||||
const address = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: 'nobody'
|
||||
};
|
||||
const json = {
|
||||
address,
|
||||
encoded: '',
|
||||
encoding: {
|
||||
content: ['pkcs8', 'ed25519'],
|
||||
type: 'none',
|
||||
version: '0'
|
||||
},
|
||||
meta
|
||||
};
|
||||
const pair = {
|
||||
address,
|
||||
addressRaw: publicKey,
|
||||
decodePkcs8: (_passphrase, _encoded) => undefined,
|
||||
derive: (_suri, _meta) => pair,
|
||||
encodePkcs8: (_passphrase) => new Uint8Array(0),
|
||||
isLocked: true,
|
||||
lock: () => {
|
||||
},
|
||||
meta,
|
||||
publicKey,
|
||||
setMeta: (_meta) => undefined,
|
||||
sign: (_message) => new Uint8Array(64),
|
||||
toJson: (_passphrase) => json,
|
||||
type: 'ed25519',
|
||||
unlock: (_passphrase) => undefined,
|
||||
verify: (_message, _signature) => false,
|
||||
vrfSign: (_message, _context, _extra) => new Uint8Array(96),
|
||||
vrfVerify: (_message, _vrfResult, _context, _extra) => false
|
||||
};
|
||||
function nobody() {
|
||||
return pair;
|
||||
}
|
||||
|
||||
function createTestPairs(options, isDerived = true) {
|
||||
const keyring = createTestKeyring(options, isDerived);
|
||||
const pairs = keyring.getPairs();
|
||||
const map = { nobody: nobody() };
|
||||
for (const p of pairs) {
|
||||
if (p.meta.name) {
|
||||
map[p.meta.name] = p;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Object.defineProperty(exports, "decodeAddress", {
|
||||
enumerable: true,
|
||||
get: function () { return utilCrypto.decodeAddress; }
|
||||
});
|
||||
Object.defineProperty(exports, "encodeAddress", {
|
||||
enumerable: true,
|
||||
get: function () { return utilCrypto.encodeAddress; }
|
||||
});
|
||||
Object.defineProperty(exports, "setSS58Format", {
|
||||
enumerable: true,
|
||||
get: function () { return utilCrypto.setSS58Format; }
|
||||
});
|
||||
exports.DEV_PHRASE = DEV_PHRASE;
|
||||
exports.DEV_SEED = DEV_SEED;
|
||||
exports.Keyring = Keyring;
|
||||
exports.createPair = createPair;
|
||||
exports.createTestKeyring = createTestKeyring;
|
||||
exports.createTestPairs = createTestPairs;
|
||||
exports.packageInfo = packageInfo;
|
||||
|
||||
}));
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
|
||||
export { Keyring } from './keyring.js';
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export { createPair } from './pair/index.js';
|
||||
export { createTestKeyring } from './testing.js';
|
||||
export { createTestPairs } from './testingPairs.js';
|
||||
export * from './defaults.js';
|
||||
@@ -1,7 +0,0 @@
|
||||
export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
|
||||
export { Keyring } from './keyring.js';
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export { createPair } from './pair/index.js';
|
||||
export { createTestKeyring } from './testing.js';
|
||||
export { createTestPairs } from './testingPairs.js';
|
||||
export * from './defaults.js';
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
export { decodeAddress, encodeAddress, setSS58Format } from '@pezkuwi/util-crypto';
|
||||
export { Keyring } from './keyring.js';
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export { createPair } from './pair/index.js';
|
||||
export { createTestKeyring } from './testing.js';
|
||||
export { createTestPairs } from './testingPairs.js';
|
||||
export * from './defaults.js';
|
||||
@@ -1,19 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTestPairs = exports.createTestKeyring = exports.createPair = exports.packageInfo = exports.Keyring = exports.setSS58Format = exports.encodeAddress = exports.decodeAddress = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
var util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
Object.defineProperty(exports, "decodeAddress", { enumerable: true, get: function () { return util_crypto_1.decodeAddress; } });
|
||||
Object.defineProperty(exports, "encodeAddress", { enumerable: true, get: function () { return util_crypto_1.encodeAddress; } });
|
||||
Object.defineProperty(exports, "setSS58Format", { enumerable: true, get: function () { return util_crypto_1.setSS58Format; } });
|
||||
var keyring_js_1 = require("./keyring.js");
|
||||
Object.defineProperty(exports, "Keyring", { enumerable: true, get: function () { return keyring_js_1.Keyring; } });
|
||||
var packageInfo_js_1 = require("./packageInfo.js");
|
||||
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
|
||||
var index_js_1 = require("./pair/index.js");
|
||||
Object.defineProperty(exports, "createPair", { enumerable: true, get: function () { return index_js_1.createPair; } });
|
||||
var testing_js_1 = require("./testing.js");
|
||||
Object.defineProperty(exports, "createTestKeyring", { enumerable: true, get: function () { return testing_js_1.createTestKeyring; } });
|
||||
var testingPairs_js_1 = require("./testingPairs.js");
|
||||
Object.defineProperty(exports, "createTestPairs", { enumerable: true, get: function () { return testingPairs_js_1.createTestPairs; } });
|
||||
tslib_1.__exportStar(require("./defaults.js"), exports);
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
export declare const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
||||
export declare const DEV_SEED = "0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e";
|
||||
@@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DEV_SEED = exports.DEV_PHRASE = void 0;
|
||||
exports.DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
exports.DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
import './packageDetect.js';
|
||||
import { Keyring } from './bundle.js';
|
||||
export * from './bundle.js';
|
||||
export default Keyring;
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
require("./packageDetect.js");
|
||||
const bundle_js_1 = require("./bundle.js");
|
||||
tslib_1.__exportStar(require("./bundle.js"), exports);
|
||||
exports.default = bundle_js_1.Keyring;
|
||||
Vendored
-145
@@ -1,145 +0,0 @@
|
||||
import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringInstance, KeyringOptions, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from './types.js';
|
||||
import { decodeAddress } from '@pezkuwi/util-crypto';
|
||||
/**
|
||||
* # @pezkuwi/keyring
|
||||
*
|
||||
* ## Overview
|
||||
*
|
||||
* @name Keyring
|
||||
* @summary Keyring management of user accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export declare class Keyring implements KeyringInstance {
|
||||
#private;
|
||||
decodeAddress: typeof decodeAddress;
|
||||
constructor(options?: KeyringOptions);
|
||||
/**
|
||||
* @description retrieve the pairs (alias for getPairs)
|
||||
*/
|
||||
get pairs(): KeyringPair[];
|
||||
/**
|
||||
* @description retrieve the publicKeys (alias for getPublicKeys)
|
||||
*/
|
||||
get publicKeys(): Uint8Array[];
|
||||
/**
|
||||
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
||||
*/
|
||||
get type(): KeypairType;
|
||||
/**
|
||||
* @name addPair
|
||||
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
*/
|
||||
addPair(pair: KeyringPair): KeyringPair;
|
||||
/**
|
||||
* @name addFromAddress
|
||||
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean, encType?: EncryptedJsonEncoding[]): KeyringPair;
|
||||
/**
|
||||
* @name addFromJson
|
||||
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
/**
|
||||
* @name addFromMnemonic
|
||||
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name addFromPair
|
||||
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name addFromSeed
|
||||
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name addFromUri
|
||||
* @summary Creates an account via an suri
|
||||
* @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)
|
||||
*/
|
||||
addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name createFromJson
|
||||
* @description Creates a pair from a JSON keyfile
|
||||
*/
|
||||
createFromJson({ address, encoded, encoding: { content, type, version }, meta }: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
/**
|
||||
* @name createFromPair
|
||||
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
createFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name createFromUri
|
||||
* @summary Creates a Keypair from an suri
|
||||
* @description This creates a pair from the suri, but does not add it to the keyring
|
||||
*/
|
||||
createFromUri(_suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name encodeAddress
|
||||
* @description Encodes the input into an ss58 representation
|
||||
*/
|
||||
encodeAddress: (address: Uint8Array | string, ss58Format?: number) => string;
|
||||
/**
|
||||
* @name getPair
|
||||
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
||||
* @description 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).
|
||||
*/
|
||||
getPair(address: string | Uint8Array): KeyringPair;
|
||||
/**
|
||||
* @name getPairs
|
||||
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
||||
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
getPairs(): KeyringPair[];
|
||||
/**
|
||||
* @name getPublicKeys
|
||||
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
||||
* @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.
|
||||
*/
|
||||
getPublicKeys(): Uint8Array[];
|
||||
/**
|
||||
* @name removePair
|
||||
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
||||
*/
|
||||
removePair(address: string | Uint8Array): void;
|
||||
/**
|
||||
* @name setSS58Format;
|
||||
* @description Sets the ss58 format for the keyring
|
||||
*/
|
||||
setSS58Format(ss58: number): void;
|
||||
/**
|
||||
* @name toJson
|
||||
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
||||
* @description 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.
|
||||
*/
|
||||
toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Keyring = void 0;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
const index_js_1 = require("./pair/index.js");
|
||||
const defaults_js_1 = require("./defaults.js");
|
||||
const pairs_js_1 = require("./pairs.js");
|
||||
const PairFromSeed = {
|
||||
ecdsa: (seed) => (0, util_crypto_1.secp256k1PairFromSeed)(seed),
|
||||
ed25519: (seed) => (0, util_crypto_1.ed25519PairFromSeed)(seed),
|
||||
ethereum: (seed) => (0, util_crypto_1.secp256k1PairFromSeed)(seed),
|
||||
sr25519: (seed) => (0, util_crypto_1.sr25519PairFromSeed)(seed)
|
||||
};
|
||||
function pairToPublic({ publicKey }) {
|
||||
return publicKey;
|
||||
}
|
||||
/**
|
||||
* # @pezkuwi/keyring
|
||||
*
|
||||
* ## Overview
|
||||
*
|
||||
* @name Keyring
|
||||
* @summary Keyring management of user accounts
|
||||
* @description 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.
|
||||
*/
|
||||
class Keyring {
|
||||
#pairs;
|
||||
#type;
|
||||
#ss58;
|
||||
decodeAddress = util_crypto_1.decodeAddress;
|
||||
constructor(options = {}) {
|
||||
options.type = options.type || 'ed25519';
|
||||
if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
|
||||
throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
|
||||
}
|
||||
this.#pairs = new pairs_js_1.Pairs();
|
||||
this.#ss58 = options.ss58Format;
|
||||
this.#type = options.type;
|
||||
}
|
||||
/**
|
||||
* @description retrieve the pairs (alias for getPairs)
|
||||
*/
|
||||
get pairs() {
|
||||
return this.getPairs();
|
||||
}
|
||||
/**
|
||||
* @description retrieve the publicKeys (alias for getPublicKeys)
|
||||
*/
|
||||
get publicKeys() {
|
||||
return this.getPublicKeys();
|
||||
}
|
||||
/**
|
||||
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
||||
*/
|
||||
get type() {
|
||||
return this.#type;
|
||||
}
|
||||
/**
|
||||
* @name addPair
|
||||
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
*/
|
||||
addPair(pair) {
|
||||
return this.#pairs.add(pair);
|
||||
}
|
||||
/**
|
||||
* @name addFromAddress
|
||||
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
|
||||
const publicKey = this.decodeAddress(address, ignoreChecksum);
|
||||
return this.addPair((0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
|
||||
}
|
||||
/**
|
||||
* @name addFromJson
|
||||
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromJson(json, ignoreChecksum) {
|
||||
return this.addPair(this.createFromJson(json, ignoreChecksum));
|
||||
}
|
||||
/**
|
||||
* @name addFromMnemonic
|
||||
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
|
||||
return this.addFromUri(mnemonic, meta, type, wordlist);
|
||||
}
|
||||
/**
|
||||
* @name addFromPair
|
||||
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
addFromPair(pair, meta = {}, type = this.type) {
|
||||
return this.addPair(this.createFromPair(pair, meta, type));
|
||||
}
|
||||
/**
|
||||
* @name addFromSeed
|
||||
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromSeed(seed, meta = {}, type = this.type) {
|
||||
return this.addPair((0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
|
||||
}
|
||||
/**
|
||||
* @name addFromUri
|
||||
* @summary Creates an account via an suri
|
||||
* @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)
|
||||
*/
|
||||
addFromUri(suri, meta = {}, type = this.type, wordlist) {
|
||||
return this.addPair(this.createFromUri(suri, meta, type, wordlist));
|
||||
}
|
||||
/**
|
||||
* @name createFromJson
|
||||
* @description Creates a pair from a JSON keyfile
|
||||
*/
|
||||
createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
|
||||
if (version === '3' && content[0] !== 'pkcs8') {
|
||||
throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
|
||||
}
|
||||
const cryptoType = version === '0' || !Array.isArray(content)
|
||||
? this.type
|
||||
: content[1];
|
||||
const encType = !Array.isArray(type)
|
||||
? [type]
|
||||
: type;
|
||||
if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
|
||||
throw new Error(`Unknown crypto type ${cryptoType}`);
|
||||
}
|
||||
// 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
|
||||
const publicKey = (0, util_1.isHex)(address)
|
||||
? (0, util_1.hexToU8a)(address)
|
||||
: this.decodeAddress(address, ignoreChecksum);
|
||||
const decoded = (0, util_1.isHex)(encoded)
|
||||
? (0, util_1.hexToU8a)(encoded)
|
||||
: (0, util_crypto_1.base64Decode)(encoded);
|
||||
return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
|
||||
}
|
||||
/**
|
||||
* @name createFromPair
|
||||
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
createFromPair(pair, meta = {}, type = this.type) {
|
||||
return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, pair, meta, null);
|
||||
}
|
||||
/**
|
||||
* @name createFromUri
|
||||
* @summary Creates a Keypair from an suri
|
||||
* @description This creates a pair from the suri, but does not add it to the keyring
|
||||
*/
|
||||
createFromUri(_suri, meta = {}, type = this.type, wordlist) {
|
||||
// here we only aut-add the dev phrase if we have a hard-derived path
|
||||
const suri = _suri.startsWith('//')
|
||||
? `${defaults_js_1.DEV_PHRASE}${_suri}`
|
||||
: _suri;
|
||||
const { derivePath, password, path, phrase } = (0, util_crypto_1.keyExtractSuri)(suri);
|
||||
let seed;
|
||||
const isPhraseHex = (0, util_1.isHex)(phrase, 256);
|
||||
if (isPhraseHex) {
|
||||
seed = (0, util_1.hexToU8a)(phrase);
|
||||
}
|
||||
else {
|
||||
const parts = phrase.split(' ');
|
||||
if ([12, 15, 18, 21, 24].includes(parts.length)) {
|
||||
seed = type === 'ethereum'
|
||||
? (0, util_crypto_1.mnemonicToLegacySeed)(phrase, '', false, 64)
|
||||
: (0, util_crypto_1.mnemonicToMiniSecret)(phrase, password, wordlist);
|
||||
}
|
||||
else {
|
||||
if (phrase.length > 32) {
|
||||
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
|
||||
}
|
||||
seed = (0, util_1.stringToU8a)(phrase.padEnd(32));
|
||||
}
|
||||
}
|
||||
const derived = type === 'ethereum'
|
||||
? isPhraseHex
|
||||
? PairFromSeed[type](seed) // for eth, if the private key is provided as suri, it must be derived only once
|
||||
: (0, util_crypto_1.hdEthereum)(seed, derivePath.substring(1))
|
||||
: (0, util_crypto_1.keyFromPath)(PairFromSeed[type](seed), path, type);
|
||||
return (0, index_js_1.createPair)({ toSS58: this.encodeAddress, type }, derived, meta, null);
|
||||
}
|
||||
/**
|
||||
* @name encodeAddress
|
||||
* @description Encodes the input into an ss58 representation
|
||||
*/
|
||||
encodeAddress = (address, ss58Format) => {
|
||||
return this.type === 'ethereum'
|
||||
? (0, util_crypto_1.ethereumEncode)(address)
|
||||
: (0, util_crypto_1.encodeAddress)(address, ss58Format ?? this.#ss58);
|
||||
};
|
||||
/**
|
||||
* @name getPair
|
||||
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
||||
* @description 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).
|
||||
*/
|
||||
getPair(address) {
|
||||
return this.#pairs.get(address);
|
||||
}
|
||||
/**
|
||||
* @name getPairs
|
||||
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
||||
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
getPairs() {
|
||||
return this.#pairs.all();
|
||||
}
|
||||
/**
|
||||
* @name getPublicKeys
|
||||
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
||||
* @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.
|
||||
*/
|
||||
getPublicKeys() {
|
||||
return this.#pairs.all().map(pairToPublic);
|
||||
}
|
||||
/**
|
||||
* @name removePair
|
||||
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
||||
*/
|
||||
removePair(address) {
|
||||
this.#pairs.remove(address);
|
||||
}
|
||||
/**
|
||||
* @name setSS58Format;
|
||||
* @description Sets the ss58 format for the keyring
|
||||
*/
|
||||
setSS58Format(ss58) {
|
||||
this.#ss58 = ss58;
|
||||
}
|
||||
/**
|
||||
* @name toJson
|
||||
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
||||
* @description 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.
|
||||
*/
|
||||
toJson(address, passphrase) {
|
||||
return this.#pairs.get(address).toJson(passphrase);
|
||||
}
|
||||
}
|
||||
exports.Keyring = Keyring;
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
export {};
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const packageInfo_1 = require("@pezkuwi/util/cjs/packageInfo");
|
||||
const packageInfo_2 = require("@pezkuwi/util-crypto/cjs/packageInfo");
|
||||
const packageInfo_js_1 = require("./packageInfo.js");
|
||||
(0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, [packageInfo_2.packageInfo, packageInfo_1.packageInfo]);
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
export declare const packageInfo: {
|
||||
name: string;
|
||||
path: string;
|
||||
type: string;
|
||||
version: string;
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.packageInfo = void 0;
|
||||
exports.packageInfo = { name: '@pezkuwi/keyring', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '14.0.10' };
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
import type { EncryptedJsonEncoding } from '@pezkuwi/util-crypto/types';
|
||||
/**
|
||||
* Decode a pair, taking into account the generation-specific formats and headers
|
||||
*
|
||||
* For divisor/headers, don't rely on the magic being static. These will
|
||||
* change between generations, aka with the long-awaited 4th generation
|
||||
* of the format. The external decode interface is the only way to use and decode these.
|
||||
**/
|
||||
export declare function decodePair(passphrase?: string, encrypted?: Uint8Array | null, _encType?: EncryptedJsonEncoding | EncryptedJsonEncoding[]): {
|
||||
publicKey: Uint8Array;
|
||||
secretKey: Uint8Array;
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.decodePair = decodePair;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
const defaults_js_1 = require("./defaults.js");
|
||||
const SEED_OFFSET = defaults_js_1.PAIR_HDR.length;
|
||||
/**
|
||||
* Decode a pair, taking into account the generation-specific formats and headers
|
||||
*
|
||||
* For divisor/headers, don't rely on the magic being static. These will
|
||||
* change between generations, aka with the long-awaited 4th generation
|
||||
* of the format. The external decode interface is the only way to use and decode these.
|
||||
**/
|
||||
function decodePair(passphrase, encrypted, _encType) {
|
||||
const encType = Array.isArray(_encType) || _encType === undefined
|
||||
? _encType
|
||||
: [_encType];
|
||||
const decrypted = (0, util_crypto_1.jsonDecryptData)(encrypted, passphrase, encType);
|
||||
const header = decrypted.subarray(0, defaults_js_1.PAIR_HDR.length);
|
||||
// check the start header (generations 1-3)
|
||||
if (!(0, util_1.u8aEq)(header, defaults_js_1.PAIR_HDR)) {
|
||||
throw new Error('Invalid encoding header found in body');
|
||||
}
|
||||
// setup for generation 3 format
|
||||
let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + defaults_js_1.SEC_LENGTH);
|
||||
let divOffset = SEED_OFFSET + defaults_js_1.SEC_LENGTH;
|
||||
let divider = decrypted.subarray(divOffset, divOffset + defaults_js_1.PAIR_DIV.length);
|
||||
// old-style (generation 1 & 2), we have the seed here
|
||||
if (!(0, util_1.u8aEq)(divider, defaults_js_1.PAIR_DIV)) {
|
||||
divOffset = SEED_OFFSET + defaults_js_1.SEED_LENGTH;
|
||||
secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
|
||||
divider = decrypted.subarray(divOffset, divOffset + defaults_js_1.PAIR_DIV.length);
|
||||
// check the divisior at this point (already checked for generation 3)
|
||||
if (!(0, util_1.u8aEq)(divider, defaults_js_1.PAIR_DIV)) {
|
||||
throw new Error('Invalid encoding divider found in body');
|
||||
}
|
||||
}
|
||||
const pubOffset = divOffset + defaults_js_1.PAIR_DIV.length;
|
||||
const publicKey = decrypted.subarray(pubOffset, pubOffset + defaults_js_1.PUB_LENGTH);
|
||||
return {
|
||||
publicKey,
|
||||
secretKey
|
||||
};
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
||||
export declare const PAIR_DIV: Uint8Array;
|
||||
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
||||
export declare const PAIR_HDR: Uint8Array;
|
||||
/** length of a public key */
|
||||
export declare const PUB_LENGTH = 32;
|
||||
/** length of a salt */
|
||||
export declare const SALT_LENGTH = 32;
|
||||
/** length of a secret key */
|
||||
export declare const SEC_LENGTH = 64;
|
||||
/** length of a user-input seed */
|
||||
export declare const SEED_LENGTH = 32;
|
||||
@@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SEED_LENGTH = exports.SEC_LENGTH = exports.SALT_LENGTH = exports.PUB_LENGTH = exports.PAIR_HDR = exports.PAIR_DIV = void 0;
|
||||
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
||||
exports.PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
||||
exports.PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
/** length of a public key */
|
||||
exports.PUB_LENGTH = 32;
|
||||
/** length of a salt */
|
||||
exports.SALT_LENGTH = 32;
|
||||
/** length of a secret key */
|
||||
exports.SEC_LENGTH = 64;
|
||||
/** length of a user-input seed */
|
||||
exports.SEED_LENGTH = 32;
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
import type { PairInfo } from './types.js';
|
||||
/**
|
||||
* Encode a pair with the latest generation format (generation 3)
|
||||
**/
|
||||
export declare function encodePair({ publicKey, secretKey }: PairInfo, passphrase?: string): Uint8Array;
|
||||
@@ -1,22 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.encodePair = encodePair;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
const defaults_js_1 = require("./defaults.js");
|
||||
/**
|
||||
* Encode a pair with the latest generation format (generation 3)
|
||||
**/
|
||||
function encodePair({ publicKey, secretKey }, passphrase) {
|
||||
if (!secretKey) {
|
||||
throw new Error('Expected a valid secretKey to be passed to encode');
|
||||
}
|
||||
const encoded = (0, util_1.u8aConcat)(defaults_js_1.PAIR_HDR, secretKey, defaults_js_1.PAIR_DIV, publicKey);
|
||||
if (!passphrase) {
|
||||
return encoded;
|
||||
}
|
||||
// this is only for generation 3 (previous generations are only handled in decoding)
|
||||
const { params, password, salt } = (0, util_crypto_1.scryptEncode)(passphrase);
|
||||
const { encrypted, nonce } = (0, util_crypto_1.naclEncrypt)(encoded, password.subarray(0, 32));
|
||||
return (0, util_1.u8aConcat)((0, util_crypto_1.scryptToU8a)(salt, params), nonce, encrypted);
|
||||
}
|
||||
Vendored
-40
@@ -1,40 +0,0 @@
|
||||
import type { EncryptedJsonEncoding, KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringPair, KeyringPair$Meta } from '../types.js';
|
||||
import type { PairInfo } from './types.js';
|
||||
interface Setup {
|
||||
toSS58: (publicKey: Uint8Array) => string;
|
||||
type: KeypairType;
|
||||
}
|
||||
/**
|
||||
* @name createPair
|
||||
* @summary Creates a keyring pair object
|
||||
* @description 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 via `setMeta`.
|
||||
* - `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 another `toJson` function and provides the state of the pair,
|
||||
* it generates arguments to be passed to the other `toJson` 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 to `toJson`
|
||||
* indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
|
||||
* The `toJson` function that it calls returns a JSON object with properties including the `address`
|
||||
* and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
|
||||
* an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
|
||||
* property that indicates whether the public key value of the `encoded` property is encoded or not.
|
||||
*/
|
||||
export declare function createPair({ toSS58, type }: Setup, { publicKey, secretKey }: PairInfo, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, encTypes?: EncryptedJsonEncoding[]): KeyringPair;
|
||||
export {};
|
||||
@@ -1,183 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createPair = createPair;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
const decode_js_1 = require("./decode.js");
|
||||
const encode_js_1 = require("./encode.js");
|
||||
const toJson_js_1 = require("./toJson.js");
|
||||
const SIG_TYPE_NONE = new Uint8Array();
|
||||
const TYPE_FROM_SEED = {
|
||||
ecdsa: util_crypto_1.secp256k1PairFromSeed,
|
||||
ed25519: util_crypto_1.ed25519PairFromSeed,
|
||||
ethereum: util_crypto_1.secp256k1PairFromSeed,
|
||||
sr25519: util_crypto_1.sr25519PairFromSeed
|
||||
};
|
||||
const TYPE_PREFIX = {
|
||||
ecdsa: new Uint8Array([2]),
|
||||
ed25519: new Uint8Array([0]),
|
||||
ethereum: new Uint8Array([2]),
|
||||
sr25519: new Uint8Array([1])
|
||||
};
|
||||
const TYPE_SIGNATURE = {
|
||||
ecdsa: (m, p) => (0, util_crypto_1.secp256k1Sign)(m, p, 'blake2'),
|
||||
ed25519: util_crypto_1.ed25519Sign,
|
||||
ethereum: (m, p) => (0, util_crypto_1.secp256k1Sign)(m, p, 'keccak'),
|
||||
sr25519: util_crypto_1.sr25519Sign
|
||||
};
|
||||
const TYPE_ADDRESS = {
|
||||
ecdsa: (p) => p.length > 32 ? (0, util_crypto_1.blake2AsU8a)(p) : p,
|
||||
ed25519: (p) => p,
|
||||
ethereum: (p) => p.length === 20 ? p : (0, util_crypto_1.keccakAsU8a)((0, util_crypto_1.secp256k1Expand)(p)),
|
||||
sr25519: (p) => p
|
||||
};
|
||||
function isLocked(secretKey) {
|
||||
return !secretKey || (0, util_1.u8aEmpty)(secretKey);
|
||||
}
|
||||
function vrfHash(proof, context, extra) {
|
||||
return (0, util_crypto_1.blake2AsU8a)((0, util_1.u8aConcat)(context || '', extra || '', proof));
|
||||
}
|
||||
/**
|
||||
* @name createPair
|
||||
* @summary Creates a keyring pair object
|
||||
* @description 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 via `setMeta`.
|
||||
* - `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 another `toJson` function and provides the state of the pair,
|
||||
* it generates arguments to be passed to the other `toJson` 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 to `toJson`
|
||||
* indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
|
||||
* The `toJson` function that it calls returns a JSON object with properties including the `address`
|
||||
* and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
|
||||
* an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
|
||||
* property that indicates whether the public key value of the `encoded` property is encoded or not.
|
||||
*/
|
||||
function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
|
||||
const decodePkcs8 = (passphrase, userEncoded) => {
|
||||
const decoded = (0, decode_js_1.decodePair)(passphrase, userEncoded || encoded, encTypes);
|
||||
if (decoded.secretKey.length === 64) {
|
||||
publicKey = decoded.publicKey;
|
||||
secretKey = decoded.secretKey;
|
||||
}
|
||||
else {
|
||||
const pair = TYPE_FROM_SEED[type](decoded.secretKey);
|
||||
publicKey = pair.publicKey;
|
||||
secretKey = pair.secretKey;
|
||||
}
|
||||
};
|
||||
const recode = (passphrase) => {
|
||||
isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
|
||||
encoded = (0, encode_js_1.encodePair)({ publicKey, secretKey }, passphrase); // re-encode, latest version
|
||||
encTypes = undefined; // swap to defaults, latest version follows
|
||||
return encoded;
|
||||
};
|
||||
const encodeAddress = () => {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? (0, util_crypto_1.ethereumEncode)(raw)
|
||||
: toSS58(raw);
|
||||
};
|
||||
return {
|
||||
get address() {
|
||||
return encodeAddress();
|
||||
},
|
||||
get addressRaw() {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? raw.slice(-20)
|
||||
: raw;
|
||||
},
|
||||
get isLocked() {
|
||||
return isLocked(secretKey);
|
||||
},
|
||||
get meta() {
|
||||
return meta;
|
||||
},
|
||||
get publicKey() {
|
||||
return publicKey;
|
||||
},
|
||||
get type() {
|
||||
return type;
|
||||
},
|
||||
// eslint-disable-next-line sort-keys
|
||||
decodePkcs8,
|
||||
derive: (suri, meta) => {
|
||||
if (type === 'ethereum') {
|
||||
throw new Error('Unable to derive on this keypair');
|
||||
}
|
||||
else if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot derive on a locked keypair');
|
||||
}
|
||||
const { path } = (0, util_crypto_1.keyExtractPath)(suri);
|
||||
const derived = (0, util_crypto_1.keyFromPath)({ publicKey, secretKey }, path, type);
|
||||
return createPair({ toSS58, type }, derived, meta, null);
|
||||
},
|
||||
encodePkcs8: (passphrase) => {
|
||||
return recode(passphrase);
|
||||
},
|
||||
lock: () => {
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional) => {
|
||||
meta = (0, util_1.objectSpread)({}, meta, additional);
|
||||
},
|
||||
sign: (message, options = {}) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
return (0, util_1.u8aConcat)(options.withType
|
||||
? TYPE_PREFIX[type]
|
||||
: SIG_TYPE_NONE, TYPE_SIGNATURE[type]((0, util_1.u8aToU8a)(message), { publicKey, secretKey }));
|
||||
},
|
||||
toJson: (passphrase) => {
|
||||
// NOTE: For ecdsa and ethereum, the publicKey cannot be extracted from the address. For these
|
||||
// pass the hex-encoded publicKey through to the address portion of the JSON (before decoding)
|
||||
// unless the publicKey is already an address
|
||||
const address = ['ecdsa', 'ethereum'].includes(type)
|
||||
? publicKey.length === 20
|
||||
? (0, util_1.u8aToHex)(publicKey)
|
||||
: (0, util_1.u8aToHex)((0, util_crypto_1.secp256k1Compress)(publicKey))
|
||||
: encodeAddress();
|
||||
return (0, toJson_js_1.pairToJson)(type, { address, meta }, recode(passphrase), !!passphrase);
|
||||
},
|
||||
unlock: (passphrase) => {
|
||||
return decodePkcs8(passphrase);
|
||||
},
|
||||
verify: (message, signature, signerPublic) => {
|
||||
return (0, util_crypto_1.signatureVerify)(message, signature, TYPE_ADDRESS[type]((0, util_1.u8aToU8a)(signerPublic))).isValid;
|
||||
},
|
||||
vrfSign: (message, context, extra) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
if (type === 'sr25519') {
|
||||
return (0, util_crypto_1.sr25519VrfSign)(message, { secretKey }, context, extra);
|
||||
}
|
||||
const proof = TYPE_SIGNATURE[type]((0, util_1.u8aToU8a)(message), { publicKey, secretKey });
|
||||
return (0, util_1.u8aConcat)(vrfHash(proof, context, extra), proof);
|
||||
},
|
||||
vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
|
||||
if (type === 'sr25519') {
|
||||
return (0, util_crypto_1.sr25519VrfVerify)(message, vrfResult, publicKey, context, extra);
|
||||
}
|
||||
const result = (0, util_crypto_1.signatureVerify)(message, (0, util_1.u8aConcat)(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type]((0, util_1.u8aToU8a)(signerPublic)));
|
||||
return result.isValid && (0, util_1.u8aEq)(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
|
||||
}
|
||||
};
|
||||
}
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
import type { KeyringPair } from '../types.js';
|
||||
export declare function nobody(): KeyringPair;
|
||||
@@ -1,43 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nobody = nobody;
|
||||
const publicKey = new Uint8Array(32);
|
||||
const address = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: 'nobody'
|
||||
};
|
||||
const json = {
|
||||
address,
|
||||
encoded: '',
|
||||
encoding: {
|
||||
content: ['pkcs8', 'ed25519'],
|
||||
type: 'none',
|
||||
version: '0'
|
||||
},
|
||||
meta
|
||||
};
|
||||
const pair = {
|
||||
address,
|
||||
addressRaw: publicKey,
|
||||
decodePkcs8: (_passphrase, _encoded) => undefined,
|
||||
derive: (_suri, _meta) => pair,
|
||||
encodePkcs8: (_passphrase) => new Uint8Array(0),
|
||||
isLocked: true,
|
||||
lock: () => {
|
||||
// no locking, it is always locked
|
||||
},
|
||||
meta,
|
||||
publicKey,
|
||||
setMeta: (_meta) => undefined,
|
||||
sign: (_message) => new Uint8Array(64),
|
||||
toJson: (_passphrase) => json,
|
||||
type: 'ed25519',
|
||||
unlock: (_passphrase) => undefined,
|
||||
verify: (_message, _signature) => false,
|
||||
vrfSign: (_message, _context, _extra) => new Uint8Array(96),
|
||||
vrfVerify: (_message, _vrfResult, _context, _extra) => false
|
||||
};
|
||||
function nobody() {
|
||||
return pair;
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringPair$Json, KeyringPair$Meta } from '../types.js';
|
||||
interface PairStateJson {
|
||||
address: string;
|
||||
meta: KeyringPair$Meta;
|
||||
}
|
||||
export declare function pairToJson(type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json;
|
||||
export {};
|
||||
@@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.pairToJson = pairToJson;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
function pairToJson(type, { address, meta }, encoded, isEncrypted) {
|
||||
return (0, util_1.objectSpread)((0, util_crypto_1.jsonEncryptFormat)(encoded, ['pkcs8', type], isEncrypted), {
|
||||
address,
|
||||
meta
|
||||
});
|
||||
}
|
||||
Vendored
-5
@@ -1,5 +0,0 @@
|
||||
export interface PairInfo {
|
||||
publicKey: Uint8Array;
|
||||
secretKey?: Uint8Array | undefined;
|
||||
seed?: Uint8Array | null;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
import type { KeyringPair, KeyringPairs } from './types.js';
|
||||
export declare class Pairs implements KeyringPairs {
|
||||
#private;
|
||||
add(pair: KeyringPair): KeyringPair;
|
||||
all(): KeyringPair[];
|
||||
get(address: string | Uint8Array): KeyringPair;
|
||||
remove(address: string | Uint8Array): void;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Pairs = void 0;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const util_crypto_1 = require("@pezkuwi/util-crypto");
|
||||
class Pairs {
|
||||
#map = {};
|
||||
add(pair) {
|
||||
this.#map[(0, util_crypto_1.decodeAddress)(pair.address).toString()] = pair;
|
||||
return pair;
|
||||
}
|
||||
all() {
|
||||
return Object.values(this.#map);
|
||||
}
|
||||
get(address) {
|
||||
const pair = this.#map[(0, util_crypto_1.decodeAddress)(address).toString()];
|
||||
if (!pair) {
|
||||
throw new Error(`Unable to retrieve keypair '${(0, util_1.isU8a)(address) || (0, util_1.isHex)(address)
|
||||
? (0, util_1.u8aToHex)((0, util_1.u8aToU8a)(address))
|
||||
: address}'`);
|
||||
}
|
||||
return pair;
|
||||
}
|
||||
remove(address) {
|
||||
delete this.#map[(0, util_crypto_1.decodeAddress)(address).toString()];
|
||||
}
|
||||
}
|
||||
exports.Pairs = Pairs;
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
import type { HexString } from '@pezkuwi/util/types';
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringInstance, KeyringOptions } from './types.js';
|
||||
interface PairDef {
|
||||
name?: string;
|
||||
p: HexString;
|
||||
s: HexString;
|
||||
seed?: string;
|
||||
type: KeypairType;
|
||||
}
|
||||
export declare const PAIRSSR25519: PairDef[];
|
||||
export declare const PAIRSETHEREUM: PairDef[];
|
||||
/**
|
||||
* @name testKeyring
|
||||
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export declare function createTestKeyring(options?: KeyringOptions, isDerived?: boolean): KeyringInstance;
|
||||
export {};
|
||||
@@ -1,126 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PAIRSETHEREUM = exports.PAIRSSR25519 = void 0;
|
||||
exports.createTestKeyring = createTestKeyring;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const index_js_1 = require("./pair/index.js");
|
||||
const keyring_js_1 = require("./keyring.js");
|
||||
exports.PAIRSSR25519 = [
|
||||
{
|
||||
p: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
||||
s: '0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011', // nosemgrep
|
||||
seed: 'Alice',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f',
|
||||
s: '0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd', // nosemgrep
|
||||
seed: 'Alice//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48',
|
||||
s: '0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325', // nosemgrep
|
||||
seed: 'Bob',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e',
|
||||
s: '0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde', // nosemgrep
|
||||
seed: 'Bob//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22',
|
||||
s: '0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c', // nosemgrep
|
||||
seed: 'Charlie',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20',
|
||||
s: '0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568', // nosemgrep
|
||||
seed: 'Dave',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e',
|
||||
s: '0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587', // nosemgrep
|
||||
seed: 'Eve',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
|
||||
s: '0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426', // nosemgrep
|
||||
seed: 'Ferdie',
|
||||
type: 'sr25519'
|
||||
}
|
||||
];
|
||||
exports.PAIRSETHEREUM = [
|
||||
{
|
||||
name: 'Alith',
|
||||
p: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
||||
s: '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Baltathar',
|
||||
p: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
||||
s: '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Charleth',
|
||||
p: '0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e',
|
||||
s: '0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Dorothy',
|
||||
p: '0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c',
|
||||
s: '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Ethan',
|
||||
p: '0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa',
|
||||
s: '0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Faith',
|
||||
p: '0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74',
|
||||
s: '0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df', // nosemgrep
|
||||
type: 'ethereum'
|
||||
}
|
||||
];
|
||||
function createMeta(name, seed) {
|
||||
if (!name && !seed) {
|
||||
throw new Error('Testing pair should have either a name or a seed');
|
||||
}
|
||||
return {
|
||||
isTesting: true,
|
||||
name: name || seed?.replace('//', '_').toLowerCase()
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @name testKeyring
|
||||
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
||||
* @description 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 createTestKeyring(options = {}, isDerived = true) {
|
||||
const keyring = new keyring_js_1.Keyring(options);
|
||||
const pairs = options.type === 'ethereum'
|
||||
? exports.PAIRSETHEREUM
|
||||
: exports.PAIRSSR25519;
|
||||
for (const { name, p, s, seed, type } of pairs) {
|
||||
const meta = createMeta(name, seed);
|
||||
const pair = !isDerived && !name && seed
|
||||
? keyring.addFromUri(seed, meta, options.type)
|
||||
: keyring.addPair((0, index_js_1.createPair)({ toSS58: keyring.encodeAddress, type }, { publicKey: (0, util_1.hexToU8a)(p), secretKey: (0, util_1.hexToU8a)(s) }, meta));
|
||||
pair.lock = () => {
|
||||
// we don't have lock/unlock functionality here
|
||||
};
|
||||
}
|
||||
return keyring;
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringOptions, KeyringPair } from './types.js';
|
||||
export interface TestKeyringMap {
|
||||
nobody: KeyringPair;
|
||||
[index: string]: KeyringPair;
|
||||
}
|
||||
export interface TestKeyringMapBizinikiwi extends TestKeyringMap {
|
||||
alice: KeyringPair;
|
||||
bob: KeyringPair;
|
||||
charlie: KeyringPair;
|
||||
dave: KeyringPair;
|
||||
eve: KeyringPair;
|
||||
ferdie: KeyringPair;
|
||||
}
|
||||
export interface TestKeyringMapEthereum extends TestKeyringMap {
|
||||
Alith: KeyringPair;
|
||||
Baltathar: KeyringPair;
|
||||
Charleth: KeyringPair;
|
||||
Dorothy: KeyringPair;
|
||||
Ethan: KeyringPair;
|
||||
Faith: KeyringPair;
|
||||
}
|
||||
export type DetectMap<O extends KeyringOptions | undefined> = DetectPairType<O> extends 'ethereum' ? TestKeyringMapEthereum : TestKeyringMapBizinikiwi;
|
||||
export type DetectPairType<O extends KeyringOptions | undefined> = O extends KeyringOptions ? O['type'] extends KeypairType ? O['type'] : 'sr25519' : 'sr25519';
|
||||
export declare function createTestPairs<O extends KeyringOptions, M = DetectMap<O>>(options?: O, isDerived?: boolean): M;
|
||||
@@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTestPairs = createTestPairs;
|
||||
const nobody_js_1 = require("./pair/nobody.js");
|
||||
const testing_js_1 = require("./testing.js");
|
||||
function createTestPairs(options, isDerived = true) {
|
||||
const keyring = (0, testing_js_1.createTestKeyring)(options, isDerived);
|
||||
const pairs = keyring.getPairs();
|
||||
const map = { nobody: (0, nobody_js_1.nobody)() };
|
||||
for (const p of pairs) {
|
||||
if (p.meta.name) {
|
||||
map[p.meta.name] = p;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
Vendored
-111
@@ -1,111 +0,0 @@
|
||||
import type { HexString } from '@pezkuwi/util/types';
|
||||
import type { EncryptedJson, Keypair, KeypairType, Prefix } from '@pezkuwi/util-crypto/types';
|
||||
export interface KeyringOptions {
|
||||
/** The ss58Format to use for address encoding (defaults to 42) */
|
||||
ss58Format?: Prefix;
|
||||
/** The type of keyring to create (defaults to ed25519) */
|
||||
type?: KeypairType;
|
||||
}
|
||||
export interface KeyringPair$MetaHardware {
|
||||
accountIndex?: number;
|
||||
accountOffset?: number;
|
||||
addressOffset?: number;
|
||||
hardwareType?: 'ledger';
|
||||
}
|
||||
export interface KeyringPair$MetaFlags {
|
||||
isDefaultAuthSelected?: boolean;
|
||||
isExternal?: boolean;
|
||||
isHardware?: boolean;
|
||||
isHidden?: boolean;
|
||||
isInjected?: boolean;
|
||||
isMultisig?: boolean;
|
||||
isProxied?: boolean;
|
||||
isRecent?: boolean;
|
||||
isTesting?: boolean;
|
||||
}
|
||||
export interface KeyringPair$MetaContract {
|
||||
abi: string;
|
||||
genesisHash?: HexString | null;
|
||||
}
|
||||
export interface KeyringPair$MetaExtension {
|
||||
source?: string;
|
||||
}
|
||||
export interface KeyringPair$MetaMultisig {
|
||||
threshold?: number;
|
||||
who?: string[];
|
||||
}
|
||||
export interface KeyringPair$MetaParent {
|
||||
parentAddress?: string;
|
||||
parentName?: string;
|
||||
}
|
||||
export interface KeyringPair$Meta extends KeyringPair$MetaExtension, KeyringPair$MetaFlags, KeyringPair$MetaHardware, KeyringPair$MetaMultisig, KeyringPair$MetaParent {
|
||||
address?: string;
|
||||
contract?: KeyringPair$MetaContract;
|
||||
genesisHash?: HexString | null;
|
||||
name?: string;
|
||||
suri?: string;
|
||||
tags?: string[];
|
||||
type?: KeypairType;
|
||||
whenCreated?: number;
|
||||
whenEdited?: number;
|
||||
whenUsed?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
export interface KeyringPair$Json extends EncryptedJson {
|
||||
/** The ss58 encoded address or the hex-encoded version (the latter is for ETH-compat chains) */
|
||||
address: string;
|
||||
/** The underlying metadata associated with the keypair */
|
||||
meta: KeyringPair$Meta;
|
||||
}
|
||||
export interface SignOptions {
|
||||
/** Create a MultiSignature-compatible output with an indicator type */
|
||||
withType?: boolean;
|
||||
}
|
||||
export interface KeyringPair {
|
||||
readonly address: string;
|
||||
readonly addressRaw: Uint8Array;
|
||||
readonly meta: KeyringPair$Meta;
|
||||
readonly isLocked: boolean;
|
||||
readonly publicKey: Uint8Array;
|
||||
readonly type: KeypairType;
|
||||
decodePkcs8(passphrase?: string, encoded?: Uint8Array): void;
|
||||
derive(suri: string, meta?: KeyringPair$Meta): KeyringPair;
|
||||
encodePkcs8(passphrase?: string): Uint8Array;
|
||||
lock(): void;
|
||||
setMeta(meta: KeyringPair$Meta): void;
|
||||
sign(message: string | Uint8Array, options?: SignOptions): Uint8Array;
|
||||
toJson(passphrase?: string): KeyringPair$Json;
|
||||
unlock(passphrase?: string): void;
|
||||
verify(message: string | Uint8Array, signature: Uint8Array, signerPublic: string | Uint8Array): boolean;
|
||||
vrfSign(message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array;
|
||||
vrfVerify(message: string | Uint8Array, vrfResult: Uint8Array, signerPublic: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
|
||||
}
|
||||
export interface KeyringPairs {
|
||||
add: (pair: KeyringPair) => KeyringPair;
|
||||
all: () => KeyringPair[];
|
||||
get: (address: string | Uint8Array) => KeyringPair;
|
||||
remove: (address: string | Uint8Array) => void;
|
||||
}
|
||||
export interface KeyringInstance {
|
||||
readonly pairs: KeyringPair[];
|
||||
readonly publicKeys: Uint8Array[];
|
||||
readonly type: KeypairType;
|
||||
decodeAddress(encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
|
||||
encodeAddress(key: Uint8Array | string, ss58Format?: Prefix): string;
|
||||
setSS58Format(ss58Format: Prefix): void;
|
||||
addPair(pair: KeyringPair): KeyringPair;
|
||||
addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
||||
addFromJson(pair: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
createFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
createFromPair(pair: Keypair, meta: KeyringPair$Meta, type: KeypairType): KeyringPair;
|
||||
createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
getPair(address: string | Uint8Array): KeyringPair;
|
||||
getPairs(): KeyringPair[];
|
||||
getPublicKeys(): Uint8Array[];
|
||||
removePair(address: string | Uint8Array): void;
|
||||
toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
export declare const DEV_PHRASE = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
|
||||
export declare const DEV_SEED = "0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e";
|
||||
@@ -1,2 +0,0 @@
|
||||
export const DEV_PHRASE = 'bottom drive obey lake curtain smoke basket hold race lonely fit walk';
|
||||
export const DEV_SEED = '0xfac7959dbfe72f052e5a0c3c8d6530f202b02fd8f9f5ca3580ec8deb7797479e';
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
import './packageDetect.js';
|
||||
import { Keyring } from './bundle.js';
|
||||
export * from './bundle.js';
|
||||
export default Keyring;
|
||||
@@ -1,4 +0,0 @@
|
||||
import './packageDetect.js';
|
||||
import { Keyring } from './bundle.js';
|
||||
export * from './bundle.js';
|
||||
export default Keyring;
|
||||
Vendored
-145
@@ -1,145 +0,0 @@
|
||||
import type { EncryptedJsonEncoding, Keypair, KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringInstance, KeyringOptions, KeyringPair, KeyringPair$Json, KeyringPair$Meta } from './types.js';
|
||||
import { decodeAddress } from '@pezkuwi/util-crypto';
|
||||
/**
|
||||
* # @pezkuwi/keyring
|
||||
*
|
||||
* ## Overview
|
||||
*
|
||||
* @name Keyring
|
||||
* @summary Keyring management of user accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export declare class Keyring implements KeyringInstance {
|
||||
#private;
|
||||
decodeAddress: typeof decodeAddress;
|
||||
constructor(options?: KeyringOptions);
|
||||
/**
|
||||
* @description retrieve the pairs (alias for getPairs)
|
||||
*/
|
||||
get pairs(): KeyringPair[];
|
||||
/**
|
||||
* @description retrieve the publicKeys (alias for getPublicKeys)
|
||||
*/
|
||||
get publicKeys(): Uint8Array[];
|
||||
/**
|
||||
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
||||
*/
|
||||
get type(): KeypairType;
|
||||
/**
|
||||
* @name addPair
|
||||
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
*/
|
||||
addPair(pair: KeyringPair): KeyringPair;
|
||||
/**
|
||||
* @name addFromAddress
|
||||
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean, encType?: EncryptedJsonEncoding[]): KeyringPair;
|
||||
/**
|
||||
* @name addFromJson
|
||||
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
/**
|
||||
* @name addFromMnemonic
|
||||
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name addFromPair
|
||||
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name addFromSeed
|
||||
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name addFromUri
|
||||
* @summary Creates an account via an suri
|
||||
* @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)
|
||||
*/
|
||||
addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name createFromJson
|
||||
* @description Creates a pair from a JSON keyfile
|
||||
*/
|
||||
createFromJson({ address, encoded, encoding: { content, type, version }, meta }: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
/**
|
||||
* @name createFromPair
|
||||
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
createFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
/**
|
||||
* @name createFromUri
|
||||
* @summary Creates a Keypair from an suri
|
||||
* @description This creates a pair from the suri, but does not add it to the keyring
|
||||
*/
|
||||
createFromUri(_suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
/**
|
||||
* @name encodeAddress
|
||||
* @description Encodes the input into an ss58 representation
|
||||
*/
|
||||
encodeAddress: (address: Uint8Array | string, ss58Format?: number) => string;
|
||||
/**
|
||||
* @name getPair
|
||||
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
||||
* @description 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).
|
||||
*/
|
||||
getPair(address: string | Uint8Array): KeyringPair;
|
||||
/**
|
||||
* @name getPairs
|
||||
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
||||
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
getPairs(): KeyringPair[];
|
||||
/**
|
||||
* @name getPublicKeys
|
||||
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
||||
* @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.
|
||||
*/
|
||||
getPublicKeys(): Uint8Array[];
|
||||
/**
|
||||
* @name removePair
|
||||
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
||||
*/
|
||||
removePair(address: string | Uint8Array): void;
|
||||
/**
|
||||
* @name setSS58Format;
|
||||
* @description Sets the ss58 format for the keyring
|
||||
*/
|
||||
setSS58Format(ss58: number): void;
|
||||
/**
|
||||
* @name toJson
|
||||
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
||||
* @description 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.
|
||||
*/
|
||||
toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
|
||||
}
|
||||
@@ -1,257 +0,0 @@
|
||||
import { hexToU8a, isHex, stringToU8a } from '@pezkuwi/util';
|
||||
import { base64Decode, decodeAddress, ed25519PairFromSeed as ed25519FromSeed, encodeAddress, ethereumEncode, hdEthereum, keyExtractSuri, keyFromPath, mnemonicToLegacySeed, mnemonicToMiniSecret, secp256k1PairFromSeed as secp256k1FromSeed, sr25519PairFromSeed as sr25519FromSeed } from '@pezkuwi/util-crypto';
|
||||
import { createPair } from './pair/index.js';
|
||||
import { DEV_PHRASE } from './defaults.js';
|
||||
import { Pairs } from './pairs.js';
|
||||
const PairFromSeed = {
|
||||
ecdsa: (seed) => secp256k1FromSeed(seed),
|
||||
ed25519: (seed) => ed25519FromSeed(seed),
|
||||
ethereum: (seed) => secp256k1FromSeed(seed),
|
||||
sr25519: (seed) => sr25519FromSeed(seed)
|
||||
};
|
||||
function pairToPublic({ publicKey }) {
|
||||
return publicKey;
|
||||
}
|
||||
/**
|
||||
* # @pezkuwi/keyring
|
||||
*
|
||||
* ## Overview
|
||||
*
|
||||
* @name Keyring
|
||||
* @summary Keyring management of user accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export class Keyring {
|
||||
#pairs;
|
||||
#type;
|
||||
#ss58;
|
||||
decodeAddress = decodeAddress;
|
||||
constructor(options = {}) {
|
||||
options.type = options.type || 'ed25519';
|
||||
if (!['ecdsa', 'ethereum', 'ed25519', 'sr25519'].includes(options.type || 'undefined')) {
|
||||
throw new Error(`Expected a keyring type of either 'ed25519', 'sr25519', 'ethereum' or 'ecdsa', found '${options.type || 'unknown'}`);
|
||||
}
|
||||
this.#pairs = new Pairs();
|
||||
this.#ss58 = options.ss58Format;
|
||||
this.#type = options.type;
|
||||
}
|
||||
/**
|
||||
* @description retrieve the pairs (alias for getPairs)
|
||||
*/
|
||||
get pairs() {
|
||||
return this.getPairs();
|
||||
}
|
||||
/**
|
||||
* @description retrieve the publicKeys (alias for getPublicKeys)
|
||||
*/
|
||||
get publicKeys() {
|
||||
return this.getPublicKeys();
|
||||
}
|
||||
/**
|
||||
* @description Returns the type of the keyring, ed25519, sr25519 or ecdsa
|
||||
*/
|
||||
get type() {
|
||||
return this.#type;
|
||||
}
|
||||
/**
|
||||
* @name addPair
|
||||
* @summary Stores an account, given a keyring pair, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
*/
|
||||
addPair(pair) {
|
||||
return this.#pairs.add(pair);
|
||||
}
|
||||
/**
|
||||
* @name addFromAddress
|
||||
* @summary Stores an account, given an account address, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromAddress(address, meta = {}, encoded = null, type = this.type, ignoreChecksum, encType) {
|
||||
const publicKey = this.decodeAddress(address, ignoreChecksum);
|
||||
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, { publicKey, secretKey: new Uint8Array() }, meta, encoded, encType));
|
||||
}
|
||||
/**
|
||||
* @name addFromJson
|
||||
* @summary Stores an account, given JSON data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromJson(json, ignoreChecksum) {
|
||||
return this.addPair(this.createFromJson(json, ignoreChecksum));
|
||||
}
|
||||
/**
|
||||
* @name addFromMnemonic
|
||||
* @summary Stores an account, given a mnemonic, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromMnemonic(mnemonic, meta = {}, type = this.type, wordlist) {
|
||||
return this.addFromUri(mnemonic, meta, type, wordlist);
|
||||
}
|
||||
/**
|
||||
* @name addFromPair
|
||||
* @summary Stores an account created from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
addFromPair(pair, meta = {}, type = this.type) {
|
||||
return this.addPair(this.createFromPair(pair, meta, type));
|
||||
}
|
||||
/**
|
||||
* @name addFromSeed
|
||||
* @summary Stores an account, given seed data, as a Key/Value (public key, pair) in Keyring Pair Dictionary
|
||||
* @description 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.
|
||||
*/
|
||||
addFromSeed(seed, meta = {}, type = this.type) {
|
||||
return this.addPair(createPair({ toSS58: this.encodeAddress, type }, PairFromSeed[type](seed), meta, null));
|
||||
}
|
||||
/**
|
||||
* @name addFromUri
|
||||
* @summary Creates an account via an suri
|
||||
* @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)
|
||||
*/
|
||||
addFromUri(suri, meta = {}, type = this.type, wordlist) {
|
||||
return this.addPair(this.createFromUri(suri, meta, type, wordlist));
|
||||
}
|
||||
/**
|
||||
* @name createFromJson
|
||||
* @description Creates a pair from a JSON keyfile
|
||||
*/
|
||||
createFromJson({ address, encoded, encoding: { content, type, version }, meta }, ignoreChecksum) {
|
||||
if (version === '3' && content[0] !== 'pkcs8') {
|
||||
throw new Error(`Unable to decode non-pkcs8 type, [${content.join(',')}] found}`);
|
||||
}
|
||||
const cryptoType = version === '0' || !Array.isArray(content)
|
||||
? this.type
|
||||
: content[1];
|
||||
const encType = !Array.isArray(type)
|
||||
? [type]
|
||||
: type;
|
||||
if (!['ed25519', 'sr25519', 'ecdsa', 'ethereum'].includes(cryptoType)) {
|
||||
throw new Error(`Unknown crypto type ${cryptoType}`);
|
||||
}
|
||||
// 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
|
||||
const publicKey = isHex(address)
|
||||
? hexToU8a(address)
|
||||
: this.decodeAddress(address, ignoreChecksum);
|
||||
const decoded = isHex(encoded)
|
||||
? hexToU8a(encoded)
|
||||
: base64Decode(encoded);
|
||||
return createPair({ toSS58: this.encodeAddress, type: cryptoType }, { publicKey, secretKey: new Uint8Array() }, meta, decoded, encType);
|
||||
}
|
||||
/**
|
||||
* @name createFromPair
|
||||
* @summary Creates a pair from an explicit publicKey/secreteKey combination
|
||||
*/
|
||||
createFromPair(pair, meta = {}, type = this.type) {
|
||||
return createPair({ toSS58: this.encodeAddress, type }, pair, meta, null);
|
||||
}
|
||||
/**
|
||||
* @name createFromUri
|
||||
* @summary Creates a Keypair from an suri
|
||||
* @description This creates a pair from the suri, but does not add it to the keyring
|
||||
*/
|
||||
createFromUri(_suri, meta = {}, type = this.type, wordlist) {
|
||||
// here we only aut-add the dev phrase if we have a hard-derived path
|
||||
const suri = _suri.startsWith('//')
|
||||
? `${DEV_PHRASE}${_suri}`
|
||||
: _suri;
|
||||
const { derivePath, password, path, phrase } = keyExtractSuri(suri);
|
||||
let seed;
|
||||
const isPhraseHex = isHex(phrase, 256);
|
||||
if (isPhraseHex) {
|
||||
seed = hexToU8a(phrase);
|
||||
}
|
||||
else {
|
||||
const parts = phrase.split(' ');
|
||||
if ([12, 15, 18, 21, 24].includes(parts.length)) {
|
||||
seed = type === 'ethereum'
|
||||
? mnemonicToLegacySeed(phrase, '', false, 64)
|
||||
: mnemonicToMiniSecret(phrase, password, wordlist);
|
||||
}
|
||||
else {
|
||||
if (phrase.length > 32) {
|
||||
throw new Error('specified phrase is not a valid mnemonic and is invalid as a raw seed at > 32 bytes');
|
||||
}
|
||||
seed = stringToU8a(phrase.padEnd(32));
|
||||
}
|
||||
}
|
||||
const derived = type === 'ethereum'
|
||||
? isPhraseHex
|
||||
? PairFromSeed[type](seed) // for eth, if the private key is provided as suri, it must be derived only once
|
||||
: hdEthereum(seed, derivePath.substring(1))
|
||||
: keyFromPath(PairFromSeed[type](seed), path, type);
|
||||
return createPair({ toSS58: this.encodeAddress, type }, derived, meta, null);
|
||||
}
|
||||
/**
|
||||
* @name encodeAddress
|
||||
* @description Encodes the input into an ss58 representation
|
||||
*/
|
||||
encodeAddress = (address, ss58Format) => {
|
||||
return this.type === 'ethereum'
|
||||
? ethereumEncode(address)
|
||||
: encodeAddress(address, ss58Format ?? this.#ss58);
|
||||
};
|
||||
/**
|
||||
* @name getPair
|
||||
* @summary Retrieves an account keyring pair from the Keyring Pair Dictionary, given an account address
|
||||
* @description 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).
|
||||
*/
|
||||
getPair(address) {
|
||||
return this.#pairs.get(address);
|
||||
}
|
||||
/**
|
||||
* @name getPairs
|
||||
* @summary Retrieves all account keyring pairs from the Keyring Pair Dictionary
|
||||
* @description Returns an array list of all the keyring pair values that are stored in the keyring pair dictionary.
|
||||
*/
|
||||
getPairs() {
|
||||
return this.#pairs.all();
|
||||
}
|
||||
/**
|
||||
* @name getPublicKeys
|
||||
* @summary Retrieves Public Keys of all Keyring Pairs stored in the Keyring Pair Dictionary
|
||||
* @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.
|
||||
*/
|
||||
getPublicKeys() {
|
||||
return this.#pairs.all().map(pairToPublic);
|
||||
}
|
||||
/**
|
||||
* @name removePair
|
||||
* @description Deletes the provided input address or public key from the stored Keyring Pair Dictionary.
|
||||
*/
|
||||
removePair(address) {
|
||||
this.#pairs.remove(address);
|
||||
}
|
||||
/**
|
||||
* @name setSS58Format;
|
||||
* @description Sets the ss58 format for the keyring
|
||||
*/
|
||||
setSS58Format(ss58) {
|
||||
this.#ss58 = ss58;
|
||||
}
|
||||
/**
|
||||
* @name toJson
|
||||
* @summary Returns a JSON object associated with the input argument that contains metadata assocated with an account
|
||||
* @description 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.
|
||||
*/
|
||||
toJson(address, passphrase) {
|
||||
return this.#pairs.get(address).toJson(passphrase);
|
||||
}
|
||||
}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
export {};
|
||||
@@ -1,5 +0,0 @@
|
||||
import { detectPackage } from '@pezkuwi/util';
|
||||
import { packageInfo as utilInfo } from '@pezkuwi/util/packageInfo';
|
||||
import { packageInfo as cryptoInfo } from '@pezkuwi/util-crypto/packageInfo';
|
||||
import { packageInfo } from './packageInfo.js';
|
||||
detectPackage(packageInfo, null, [cryptoInfo, utilInfo]);
|
||||
Vendored
-6
@@ -1,6 +0,0 @@
|
||||
export declare const packageInfo: {
|
||||
name: string;
|
||||
path: string;
|
||||
type: string;
|
||||
version: string;
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
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.10' };
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
import type { EncryptedJsonEncoding } from '@pezkuwi/util-crypto/types';
|
||||
/**
|
||||
* Decode a pair, taking into account the generation-specific formats and headers
|
||||
*
|
||||
* For divisor/headers, don't rely on the magic being static. These will
|
||||
* change between generations, aka with the long-awaited 4th generation
|
||||
* of the format. The external decode interface is the only way to use and decode these.
|
||||
**/
|
||||
export declare function decodePair(passphrase?: string, encrypted?: Uint8Array | null, _encType?: EncryptedJsonEncoding | EncryptedJsonEncoding[]): {
|
||||
publicKey: Uint8Array;
|
||||
secretKey: Uint8Array;
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
import { u8aEq } from '@pezkuwi/util';
|
||||
import { jsonDecryptData } from '@pezkuwi/util-crypto';
|
||||
import { PAIR_DIV, PAIR_HDR, PUB_LENGTH, SEC_LENGTH, SEED_LENGTH } from './defaults.js';
|
||||
const SEED_OFFSET = PAIR_HDR.length;
|
||||
/**
|
||||
* Decode a pair, taking into account the generation-specific formats and headers
|
||||
*
|
||||
* For divisor/headers, don't rely on the magic being static. These will
|
||||
* change between generations, aka with the long-awaited 4th generation
|
||||
* of the format. The external decode interface is the only way to use and decode these.
|
||||
**/
|
||||
export function decodePair(passphrase, encrypted, _encType) {
|
||||
const encType = Array.isArray(_encType) || _encType === undefined
|
||||
? _encType
|
||||
: [_encType];
|
||||
const decrypted = jsonDecryptData(encrypted, passphrase, encType);
|
||||
const header = decrypted.subarray(0, PAIR_HDR.length);
|
||||
// check the start header (generations 1-3)
|
||||
if (!u8aEq(header, PAIR_HDR)) {
|
||||
throw new Error('Invalid encoding header found in body');
|
||||
}
|
||||
// setup for generation 3 format
|
||||
let secretKey = decrypted.subarray(SEED_OFFSET, SEED_OFFSET + SEC_LENGTH);
|
||||
let divOffset = SEED_OFFSET + SEC_LENGTH;
|
||||
let divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
||||
// old-style (generation 1 & 2), we have the seed here
|
||||
if (!u8aEq(divider, PAIR_DIV)) {
|
||||
divOffset = SEED_OFFSET + SEED_LENGTH;
|
||||
secretKey = decrypted.subarray(SEED_OFFSET, divOffset);
|
||||
divider = decrypted.subarray(divOffset, divOffset + PAIR_DIV.length);
|
||||
// check the divisior at this point (already checked for generation 3)
|
||||
if (!u8aEq(divider, PAIR_DIV)) {
|
||||
throw new Error('Invalid encoding divider found in body');
|
||||
}
|
||||
}
|
||||
const pubOffset = divOffset + PAIR_DIV.length;
|
||||
const publicKey = decrypted.subarray(pubOffset, pubOffset + PUB_LENGTH);
|
||||
return {
|
||||
publicKey,
|
||||
secretKey
|
||||
};
|
||||
}
|
||||
Vendored
-12
@@ -1,12 +0,0 @@
|
||||
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
||||
export declare const PAIR_DIV: Uint8Array;
|
||||
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
||||
export declare const PAIR_HDR: Uint8Array;
|
||||
/** length of a public key */
|
||||
export declare const PUB_LENGTH = 32;
|
||||
/** length of a salt */
|
||||
export declare const SALT_LENGTH = 32;
|
||||
/** length of a secret key */
|
||||
export declare const SEC_LENGTH = 64;
|
||||
/** length of a user-input seed */
|
||||
export declare const SEED_LENGTH = 32;
|
||||
@@ -1,12 +0,0 @@
|
||||
/** public/secret section divider (generation 1-3, will change in 4, don't rely on value) */
|
||||
export const PAIR_DIV = new Uint8Array([161, 35, 3, 33, 0]);
|
||||
/** public/secret start block (generation 1-3, will change in 4, don't rely on value) */
|
||||
export const PAIR_HDR = new Uint8Array([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32]);
|
||||
/** length of a public key */
|
||||
export const PUB_LENGTH = 32;
|
||||
/** length of a salt */
|
||||
export const SALT_LENGTH = 32;
|
||||
/** length of a secret key */
|
||||
export const SEC_LENGTH = 64;
|
||||
/** length of a user-input seed */
|
||||
export const SEED_LENGTH = 32;
|
||||
Vendored
-5
@@ -1,5 +0,0 @@
|
||||
import type { PairInfo } from './types.js';
|
||||
/**
|
||||
* Encode a pair with the latest generation format (generation 3)
|
||||
**/
|
||||
export declare function encodePair({ publicKey, secretKey }: PairInfo, passphrase?: string): Uint8Array;
|
||||
@@ -1,19 +0,0 @@
|
||||
import { u8aConcat } from '@pezkuwi/util';
|
||||
import { naclEncrypt, scryptEncode, scryptToU8a } from '@pezkuwi/util-crypto';
|
||||
import { PAIR_DIV, PAIR_HDR } from './defaults.js';
|
||||
/**
|
||||
* Encode a pair with the latest generation format (generation 3)
|
||||
**/
|
||||
export function encodePair({ publicKey, secretKey }, passphrase) {
|
||||
if (!secretKey) {
|
||||
throw new Error('Expected a valid secretKey to be passed to encode');
|
||||
}
|
||||
const encoded = u8aConcat(PAIR_HDR, secretKey, PAIR_DIV, publicKey);
|
||||
if (!passphrase) {
|
||||
return encoded;
|
||||
}
|
||||
// this is only for generation 3 (previous generations are only handled in decoding)
|
||||
const { params, password, salt } = scryptEncode(passphrase);
|
||||
const { encrypted, nonce } = naclEncrypt(encoded, password.subarray(0, 32));
|
||||
return u8aConcat(scryptToU8a(salt, params), nonce, encrypted);
|
||||
}
|
||||
Vendored
-40
@@ -1,40 +0,0 @@
|
||||
import type { EncryptedJsonEncoding, KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringPair, KeyringPair$Meta } from '../types.js';
|
||||
import type { PairInfo } from './types.js';
|
||||
interface Setup {
|
||||
toSS58: (publicKey: Uint8Array) => string;
|
||||
type: KeypairType;
|
||||
}
|
||||
/**
|
||||
* @name createPair
|
||||
* @summary Creates a keyring pair object
|
||||
* @description 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 via `setMeta`.
|
||||
* - `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 another `toJson` function and provides the state of the pair,
|
||||
* it generates arguments to be passed to the other `toJson` 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 to `toJson`
|
||||
* indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
|
||||
* The `toJson` function that it calls returns a JSON object with properties including the `address`
|
||||
* and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
|
||||
* an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
|
||||
* property that indicates whether the public key value of the `encoded` property is encoded or not.
|
||||
*/
|
||||
export declare function createPair({ toSS58, type }: Setup, { publicKey, secretKey }: PairInfo, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, encTypes?: EncryptedJsonEncoding[]): KeyringPair;
|
||||
export {};
|
||||
@@ -1,180 +0,0 @@
|
||||
import { objectSpread, u8aConcat, u8aEmpty, u8aEq, u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
||||
import { blake2AsU8a, ed25519PairFromSeed as ed25519FromSeed, ed25519Sign, ethereumEncode, keccakAsU8a, keyExtractPath, keyFromPath, secp256k1Compress, secp256k1Expand, secp256k1PairFromSeed as secp256k1FromSeed, secp256k1Sign, signatureVerify, sr25519PairFromSeed as sr25519FromSeed, sr25519Sign, sr25519VrfSign, sr25519VrfVerify } from '@pezkuwi/util-crypto';
|
||||
import { decodePair } from './decode.js';
|
||||
import { encodePair } from './encode.js';
|
||||
import { pairToJson } from './toJson.js';
|
||||
const SIG_TYPE_NONE = new Uint8Array();
|
||||
const TYPE_FROM_SEED = {
|
||||
ecdsa: secp256k1FromSeed,
|
||||
ed25519: ed25519FromSeed,
|
||||
ethereum: secp256k1FromSeed,
|
||||
sr25519: sr25519FromSeed
|
||||
};
|
||||
const TYPE_PREFIX = {
|
||||
ecdsa: new Uint8Array([2]),
|
||||
ed25519: new Uint8Array([0]),
|
||||
ethereum: new Uint8Array([2]),
|
||||
sr25519: new Uint8Array([1])
|
||||
};
|
||||
const TYPE_SIGNATURE = {
|
||||
ecdsa: (m, p) => secp256k1Sign(m, p, 'blake2'),
|
||||
ed25519: ed25519Sign,
|
||||
ethereum: (m, p) => secp256k1Sign(m, p, 'keccak'),
|
||||
sr25519: sr25519Sign
|
||||
};
|
||||
const TYPE_ADDRESS = {
|
||||
ecdsa: (p) => p.length > 32 ? blake2AsU8a(p) : p,
|
||||
ed25519: (p) => p,
|
||||
ethereum: (p) => p.length === 20 ? p : keccakAsU8a(secp256k1Expand(p)),
|
||||
sr25519: (p) => p
|
||||
};
|
||||
function isLocked(secretKey) {
|
||||
return !secretKey || u8aEmpty(secretKey);
|
||||
}
|
||||
function vrfHash(proof, context, extra) {
|
||||
return blake2AsU8a(u8aConcat(context || '', extra || '', proof));
|
||||
}
|
||||
/**
|
||||
* @name createPair
|
||||
* @summary Creates a keyring pair object
|
||||
* @description 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 via `setMeta`.
|
||||
* - `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 another `toJson` function and provides the state of the pair,
|
||||
* it generates arguments to be passed to the other `toJson` 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 to `toJson`
|
||||
* indicating whether the public key has been encoded or not (if a passphrase argument was provided then it is encoded).
|
||||
* The `toJson` function that it calls returns a JSON object with properties including the `address`
|
||||
* and `meta` that are assigned with the values stored in the corresponding state variables of the account pair,
|
||||
* an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
|
||||
* property that indicates whether the public key value of the `encoded` property is encoded or not.
|
||||
*/
|
||||
export function createPair({ toSS58, type }, { publicKey, secretKey }, meta = {}, encoded = null, encTypes) {
|
||||
const decodePkcs8 = (passphrase, userEncoded) => {
|
||||
const decoded = decodePair(passphrase, userEncoded || encoded, encTypes);
|
||||
if (decoded.secretKey.length === 64) {
|
||||
publicKey = decoded.publicKey;
|
||||
secretKey = decoded.secretKey;
|
||||
}
|
||||
else {
|
||||
const pair = TYPE_FROM_SEED[type](decoded.secretKey);
|
||||
publicKey = pair.publicKey;
|
||||
secretKey = pair.secretKey;
|
||||
}
|
||||
};
|
||||
const recode = (passphrase) => {
|
||||
isLocked(secretKey) && encoded && decodePkcs8(passphrase, encoded);
|
||||
encoded = encodePair({ publicKey, secretKey }, passphrase); // re-encode, latest version
|
||||
encTypes = undefined; // swap to defaults, latest version follows
|
||||
return encoded;
|
||||
};
|
||||
const encodeAddress = () => {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? ethereumEncode(raw)
|
||||
: toSS58(raw);
|
||||
};
|
||||
return {
|
||||
get address() {
|
||||
return encodeAddress();
|
||||
},
|
||||
get addressRaw() {
|
||||
const raw = TYPE_ADDRESS[type](publicKey);
|
||||
return type === 'ethereum'
|
||||
? raw.slice(-20)
|
||||
: raw;
|
||||
},
|
||||
get isLocked() {
|
||||
return isLocked(secretKey);
|
||||
},
|
||||
get meta() {
|
||||
return meta;
|
||||
},
|
||||
get publicKey() {
|
||||
return publicKey;
|
||||
},
|
||||
get type() {
|
||||
return type;
|
||||
},
|
||||
// eslint-disable-next-line sort-keys
|
||||
decodePkcs8,
|
||||
derive: (suri, meta) => {
|
||||
if (type === 'ethereum') {
|
||||
throw new Error('Unable to derive on this keypair');
|
||||
}
|
||||
else if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot derive on a locked keypair');
|
||||
}
|
||||
const { path } = keyExtractPath(suri);
|
||||
const derived = keyFromPath({ publicKey, secretKey }, path, type);
|
||||
return createPair({ toSS58, type }, derived, meta, null);
|
||||
},
|
||||
encodePkcs8: (passphrase) => {
|
||||
return recode(passphrase);
|
||||
},
|
||||
lock: () => {
|
||||
secretKey = new Uint8Array();
|
||||
},
|
||||
setMeta: (additional) => {
|
||||
meta = objectSpread({}, meta, additional);
|
||||
},
|
||||
sign: (message, options = {}) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
return u8aConcat(options.withType
|
||||
? TYPE_PREFIX[type]
|
||||
: SIG_TYPE_NONE, TYPE_SIGNATURE[type](u8aToU8a(message), { publicKey, secretKey }));
|
||||
},
|
||||
toJson: (passphrase) => {
|
||||
// NOTE: For ecdsa and ethereum, the publicKey cannot be extracted from the address. For these
|
||||
// pass the hex-encoded publicKey through to the address portion of the JSON (before decoding)
|
||||
// unless the publicKey is already an address
|
||||
const address = ['ecdsa', 'ethereum'].includes(type)
|
||||
? publicKey.length === 20
|
||||
? u8aToHex(publicKey)
|
||||
: u8aToHex(secp256k1Compress(publicKey))
|
||||
: encodeAddress();
|
||||
return pairToJson(type, { address, meta }, recode(passphrase), !!passphrase);
|
||||
},
|
||||
unlock: (passphrase) => {
|
||||
return decodePkcs8(passphrase);
|
||||
},
|
||||
verify: (message, signature, signerPublic) => {
|
||||
return signatureVerify(message, signature, TYPE_ADDRESS[type](u8aToU8a(signerPublic))).isValid;
|
||||
},
|
||||
vrfSign: (message, context, extra) => {
|
||||
if (isLocked(secretKey)) {
|
||||
throw new Error('Cannot sign with a locked key pair');
|
||||
}
|
||||
if (type === 'sr25519') {
|
||||
return sr25519VrfSign(message, { secretKey }, context, extra);
|
||||
}
|
||||
const proof = TYPE_SIGNATURE[type](u8aToU8a(message), { publicKey, secretKey });
|
||||
return u8aConcat(vrfHash(proof, context, extra), proof);
|
||||
},
|
||||
vrfVerify: (message, vrfResult, signerPublic, context, extra) => {
|
||||
if (type === 'sr25519') {
|
||||
return sr25519VrfVerify(message, vrfResult, publicKey, context, extra);
|
||||
}
|
||||
const result = signatureVerify(message, u8aConcat(TYPE_PREFIX[type], vrfResult.subarray(32)), TYPE_ADDRESS[type](u8aToU8a(signerPublic)));
|
||||
return result.isValid && u8aEq(vrfResult.subarray(0, 32), vrfHash(vrfResult.subarray(32), context, extra));
|
||||
}
|
||||
};
|
||||
}
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
import type { KeyringPair } from '../types.js';
|
||||
export declare function nobody(): KeyringPair;
|
||||
@@ -1,40 +0,0 @@
|
||||
const publicKey = new Uint8Array(32);
|
||||
const address = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
|
||||
const meta = {
|
||||
isTesting: true,
|
||||
name: 'nobody'
|
||||
};
|
||||
const json = {
|
||||
address,
|
||||
encoded: '',
|
||||
encoding: {
|
||||
content: ['pkcs8', 'ed25519'],
|
||||
type: 'none',
|
||||
version: '0'
|
||||
},
|
||||
meta
|
||||
};
|
||||
const pair = {
|
||||
address,
|
||||
addressRaw: publicKey,
|
||||
decodePkcs8: (_passphrase, _encoded) => undefined,
|
||||
derive: (_suri, _meta) => pair,
|
||||
encodePkcs8: (_passphrase) => new Uint8Array(0),
|
||||
isLocked: true,
|
||||
lock: () => {
|
||||
// no locking, it is always locked
|
||||
},
|
||||
meta,
|
||||
publicKey,
|
||||
setMeta: (_meta) => undefined,
|
||||
sign: (_message) => new Uint8Array(64),
|
||||
toJson: (_passphrase) => json,
|
||||
type: 'ed25519',
|
||||
unlock: (_passphrase) => undefined,
|
||||
verify: (_message, _signature) => false,
|
||||
vrfSign: (_message, _context, _extra) => new Uint8Array(96),
|
||||
vrfVerify: (_message, _vrfResult, _context, _extra) => false
|
||||
};
|
||||
export function nobody() {
|
||||
return pair;
|
||||
}
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringPair$Json, KeyringPair$Meta } from '../types.js';
|
||||
interface PairStateJson {
|
||||
address: string;
|
||||
meta: KeyringPair$Meta;
|
||||
}
|
||||
export declare function pairToJson(type: KeypairType, { address, meta }: PairStateJson, encoded: Uint8Array, isEncrypted: boolean): KeyringPair$Json;
|
||||
export {};
|
||||
@@ -1,8 +0,0 @@
|
||||
import { objectSpread } from '@pezkuwi/util';
|
||||
import { jsonEncryptFormat } from '@pezkuwi/util-crypto';
|
||||
export function pairToJson(type, { address, meta }, encoded, isEncrypted) {
|
||||
return objectSpread(jsonEncryptFormat(encoded, ['pkcs8', type], isEncrypted), {
|
||||
address,
|
||||
meta
|
||||
});
|
||||
}
|
||||
Vendored
-5
@@ -1,5 +0,0 @@
|
||||
export interface PairInfo {
|
||||
publicKey: Uint8Array;
|
||||
secretKey?: Uint8Array | undefined;
|
||||
seed?: Uint8Array | null;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export {};
|
||||
Vendored
-8
@@ -1,8 +0,0 @@
|
||||
import type { KeyringPair, KeyringPairs } from './types.js';
|
||||
export declare class Pairs implements KeyringPairs {
|
||||
#private;
|
||||
add(pair: KeyringPair): KeyringPair;
|
||||
all(): KeyringPair[];
|
||||
get(address: string | Uint8Array): KeyringPair;
|
||||
remove(address: string | Uint8Array): void;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { isHex, isU8a, u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
||||
import { decodeAddress } from '@pezkuwi/util-crypto';
|
||||
export class Pairs {
|
||||
#map = {};
|
||||
add(pair) {
|
||||
this.#map[decodeAddress(pair.address).toString()] = pair;
|
||||
return pair;
|
||||
}
|
||||
all() {
|
||||
return Object.values(this.#map);
|
||||
}
|
||||
get(address) {
|
||||
const pair = this.#map[decodeAddress(address).toString()];
|
||||
if (!pair) {
|
||||
throw new Error(`Unable to retrieve keypair '${isU8a(address) || isHex(address)
|
||||
? u8aToHex(u8aToU8a(address))
|
||||
: address}'`);
|
||||
}
|
||||
return pair;
|
||||
}
|
||||
remove(address) {
|
||||
delete this.#map[decodeAddress(address).toString()];
|
||||
}
|
||||
}
|
||||
Vendored
-20
@@ -1,20 +0,0 @@
|
||||
import type { HexString } from '@pezkuwi/util/types';
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringInstance, KeyringOptions } from './types.js';
|
||||
interface PairDef {
|
||||
name?: string;
|
||||
p: HexString;
|
||||
s: HexString;
|
||||
seed?: string;
|
||||
type: KeypairType;
|
||||
}
|
||||
export declare const PAIRSSR25519: PairDef[];
|
||||
export declare const PAIRSETHEREUM: PairDef[];
|
||||
/**
|
||||
* @name testKeyring
|
||||
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export declare function createTestKeyring(options?: KeyringOptions, isDerived?: boolean): KeyringInstance;
|
||||
export {};
|
||||
@@ -1,122 +0,0 @@
|
||||
import { hexToU8a } from '@pezkuwi/util';
|
||||
import { createPair } from './pair/index.js';
|
||||
import { Keyring } from './keyring.js';
|
||||
export const PAIRSSR25519 = [
|
||||
{
|
||||
p: '0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d',
|
||||
s: '0x98319d4ff8a9508c4bb0cf0b5a78d760a0b2082c02775e6e82370816fedfff48925a225d97aa00682d6a59b95b18780c10d7032336e88f3442b42361f4a66011', // nosemgrep
|
||||
seed: 'Alice',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xbe5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f',
|
||||
s: '0xe8da6c9d810e020f5e3c7f5af2dea314cbeaa0d72bc6421e92c0808a0c584a6046ab28e97c3ffc77fe12b5a4d37e8cd4afbfebbf2391ffc7cb07c0f38c023efd', // nosemgrep
|
||||
seed: 'Alice//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48',
|
||||
s: '0x081ff694633e255136bdb456c20a5fc8fed21f8b964c11bb17ff534ce80ebd5941ae88f85d0c1bfc37be41c904e1dfc01de8c8067b0d6d5df25dd1ac0894a325', // nosemgrep
|
||||
seed: 'Bob',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xfe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e',
|
||||
s: '0xc006507cdfc267a21532394c49ca9b754ca71de21e15a1cdf807c7ceab6d0b6c3ed408d9d35311540dcd54931933e67cf1ea10d46f75408f82b789d9bd212fde', // nosemgrep
|
||||
seed: 'Bob//stash',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22',
|
||||
s: '0xa8f2d83016052e5d6d77b2f6fd5d59418922a09024cda701b3c34369ec43a7668faf12ff39cd4e5d92bb773972f41a7a5279ebc2ed92264bed8f47d344f8f18c', // nosemgrep
|
||||
seed: 'Charlie',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20',
|
||||
s: '0x20e05482ca4677e0edbc58ae9a3a59f6ed3b1a9484ba17e64d6fe8688b2b7b5d108c4487b9323b98b11fe36cb301b084e920f7b7895536809a6d62a451b25568', // nosemgrep
|
||||
seed: 'Dave',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e',
|
||||
s: '0x683576abfd5dc35273e4264c23095a1bf21c14517bece57c7f0cc5c0ed4ce06a3dbf386b7828f348abe15d76973a72009e6ef86a5c91db2990cb36bb657c6587', // nosemgrep
|
||||
seed: 'Eve',
|
||||
type: 'sr25519'
|
||||
},
|
||||
{
|
||||
p: '0x1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c',
|
||||
s: '0xb835c20f450079cf4f513900ae9faf8df06ad86c681884122c752a4b2bf74d4303e4f21bc6cc62bb4eeed5a9cce642c25e2d2ac1464093b50f6196d78e3a7426', // nosemgrep
|
||||
seed: 'Ferdie',
|
||||
type: 'sr25519'
|
||||
}
|
||||
];
|
||||
export const PAIRSETHEREUM = [
|
||||
{
|
||||
name: 'Alith',
|
||||
p: '0x02509540919faacf9ab52146c9aa40db68172d83777250b28e4679176e49ccdd9f',
|
||||
s: '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Baltathar',
|
||||
p: '0x033bc19e36ff1673910575b6727a974a9abd80c9a875d41ab3e2648dbfb9e4b518',
|
||||
s: '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Charleth',
|
||||
p: '0x0234637bdc0e89b5d46543bcbf8edff329d2702bc995e27e9af4b1ba009a3c2a5e',
|
||||
s: '0x0b6e18cafb6ed99687ec547bd28139cafdd2bffe70e6b688025de6b445aa5c5b', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Dorothy',
|
||||
p: '0x02a00d60b2b408c2a14c5d70cdd2c205db8985ef737a7e55ad20ea32cc9e7c417c',
|
||||
s: '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Ethan',
|
||||
p: '0x025cdc005b752651cd3f728fb9192182acb3a9c89e19072cbd5b03f3ee1f1b3ffa',
|
||||
s: '0x7dce9bc8babb68fec1409be38c8e1a52650206a7ed90ff956ae8a6d15eeaaef4', // nosemgrep
|
||||
type: 'ethereum'
|
||||
},
|
||||
{
|
||||
name: 'Faith',
|
||||
p: '0x037964b6c9d546da4646ada28a99e34acaa1d14e7aba861a9055f9bd200c8abf74',
|
||||
s: '0xb9d2ea9a615f3165812e8d44de0d24da9bbd164b65c4f0573e1ce2c8dbd9c8df', // nosemgrep
|
||||
type: 'ethereum'
|
||||
}
|
||||
];
|
||||
function createMeta(name, seed) {
|
||||
if (!name && !seed) {
|
||||
throw new Error('Testing pair should have either a name or a seed');
|
||||
}
|
||||
return {
|
||||
isTesting: true,
|
||||
name: name || seed?.replace('//', '_').toLowerCase()
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @name testKeyring
|
||||
* @summary Create an instance of Keyring pre-populated with locked test accounts
|
||||
* @description 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.
|
||||
*/
|
||||
export function createTestKeyring(options = {}, isDerived = true) {
|
||||
const keyring = new Keyring(options);
|
||||
const pairs = options.type === 'ethereum'
|
||||
? PAIRSETHEREUM
|
||||
: PAIRSSR25519;
|
||||
for (const { name, p, s, seed, type } of pairs) {
|
||||
const meta = createMeta(name, seed);
|
||||
const pair = !isDerived && !name && seed
|
||||
? keyring.addFromUri(seed, meta, options.type)
|
||||
: keyring.addPair(createPair({ toSS58: keyring.encodeAddress, type }, { publicKey: hexToU8a(p), secretKey: hexToU8a(s) }, meta));
|
||||
pair.lock = () => {
|
||||
// we don't have lock/unlock functionality here
|
||||
};
|
||||
}
|
||||
return keyring;
|
||||
}
|
||||
Vendored
-25
@@ -1,25 +0,0 @@
|
||||
import type { KeypairType } from '@pezkuwi/util-crypto/types';
|
||||
import type { KeyringOptions, KeyringPair } from './types.js';
|
||||
export interface TestKeyringMap {
|
||||
nobody: KeyringPair;
|
||||
[index: string]: KeyringPair;
|
||||
}
|
||||
export interface TestKeyringMapBizinikiwi extends TestKeyringMap {
|
||||
alice: KeyringPair;
|
||||
bob: KeyringPair;
|
||||
charlie: KeyringPair;
|
||||
dave: KeyringPair;
|
||||
eve: KeyringPair;
|
||||
ferdie: KeyringPair;
|
||||
}
|
||||
export interface TestKeyringMapEthereum extends TestKeyringMap {
|
||||
Alith: KeyringPair;
|
||||
Baltathar: KeyringPair;
|
||||
Charleth: KeyringPair;
|
||||
Dorothy: KeyringPair;
|
||||
Ethan: KeyringPair;
|
||||
Faith: KeyringPair;
|
||||
}
|
||||
export type DetectMap<O extends KeyringOptions | undefined> = DetectPairType<O> extends 'ethereum' ? TestKeyringMapEthereum : TestKeyringMapBizinikiwi;
|
||||
export type DetectPairType<O extends KeyringOptions | undefined> = O extends KeyringOptions ? O['type'] extends KeypairType ? O['type'] : 'sr25519' : 'sr25519';
|
||||
export declare function createTestPairs<O extends KeyringOptions, M = DetectMap<O>>(options?: O, isDerived?: boolean): M;
|
||||
@@ -1,13 +0,0 @@
|
||||
import { nobody } from './pair/nobody.js';
|
||||
import { createTestKeyring } from './testing.js';
|
||||
export function createTestPairs(options, isDerived = true) {
|
||||
const keyring = createTestKeyring(options, isDerived);
|
||||
const pairs = keyring.getPairs();
|
||||
const map = { nobody: nobody() };
|
||||
for (const p of pairs) {
|
||||
if (p.meta.name) {
|
||||
map[p.meta.name] = p;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
Vendored
-111
@@ -1,111 +0,0 @@
|
||||
import type { HexString } from '@pezkuwi/util/types';
|
||||
import type { EncryptedJson, Keypair, KeypairType, Prefix } from '@pezkuwi/util-crypto/types';
|
||||
export interface KeyringOptions {
|
||||
/** The ss58Format to use for address encoding (defaults to 42) */
|
||||
ss58Format?: Prefix;
|
||||
/** The type of keyring to create (defaults to ed25519) */
|
||||
type?: KeypairType;
|
||||
}
|
||||
export interface KeyringPair$MetaHardware {
|
||||
accountIndex?: number;
|
||||
accountOffset?: number;
|
||||
addressOffset?: number;
|
||||
hardwareType?: 'ledger';
|
||||
}
|
||||
export interface KeyringPair$MetaFlags {
|
||||
isDefaultAuthSelected?: boolean;
|
||||
isExternal?: boolean;
|
||||
isHardware?: boolean;
|
||||
isHidden?: boolean;
|
||||
isInjected?: boolean;
|
||||
isMultisig?: boolean;
|
||||
isProxied?: boolean;
|
||||
isRecent?: boolean;
|
||||
isTesting?: boolean;
|
||||
}
|
||||
export interface KeyringPair$MetaContract {
|
||||
abi: string;
|
||||
genesisHash?: HexString | null;
|
||||
}
|
||||
export interface KeyringPair$MetaExtension {
|
||||
source?: string;
|
||||
}
|
||||
export interface KeyringPair$MetaMultisig {
|
||||
threshold?: number;
|
||||
who?: string[];
|
||||
}
|
||||
export interface KeyringPair$MetaParent {
|
||||
parentAddress?: string;
|
||||
parentName?: string;
|
||||
}
|
||||
export interface KeyringPair$Meta extends KeyringPair$MetaExtension, KeyringPair$MetaFlags, KeyringPair$MetaHardware, KeyringPair$MetaMultisig, KeyringPair$MetaParent {
|
||||
address?: string;
|
||||
contract?: KeyringPair$MetaContract;
|
||||
genesisHash?: HexString | null;
|
||||
name?: string;
|
||||
suri?: string;
|
||||
tags?: string[];
|
||||
type?: KeypairType;
|
||||
whenCreated?: number;
|
||||
whenEdited?: number;
|
||||
whenUsed?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
export interface KeyringPair$Json extends EncryptedJson {
|
||||
/** The ss58 encoded address or the hex-encoded version (the latter is for ETH-compat chains) */
|
||||
address: string;
|
||||
/** The underlying metadata associated with the keypair */
|
||||
meta: KeyringPair$Meta;
|
||||
}
|
||||
export interface SignOptions {
|
||||
/** Create a MultiSignature-compatible output with an indicator type */
|
||||
withType?: boolean;
|
||||
}
|
||||
export interface KeyringPair {
|
||||
readonly address: string;
|
||||
readonly addressRaw: Uint8Array;
|
||||
readonly meta: KeyringPair$Meta;
|
||||
readonly isLocked: boolean;
|
||||
readonly publicKey: Uint8Array;
|
||||
readonly type: KeypairType;
|
||||
decodePkcs8(passphrase?: string, encoded?: Uint8Array): void;
|
||||
derive(suri: string, meta?: KeyringPair$Meta): KeyringPair;
|
||||
encodePkcs8(passphrase?: string): Uint8Array;
|
||||
lock(): void;
|
||||
setMeta(meta: KeyringPair$Meta): void;
|
||||
sign(message: string | Uint8Array, options?: SignOptions): Uint8Array;
|
||||
toJson(passphrase?: string): KeyringPair$Json;
|
||||
unlock(passphrase?: string): void;
|
||||
verify(message: string | Uint8Array, signature: Uint8Array, signerPublic: string | Uint8Array): boolean;
|
||||
vrfSign(message: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): Uint8Array;
|
||||
vrfVerify(message: string | Uint8Array, vrfResult: Uint8Array, signerPublic: string | Uint8Array, context?: string | Uint8Array, extra?: string | Uint8Array): boolean;
|
||||
}
|
||||
export interface KeyringPairs {
|
||||
add: (pair: KeyringPair) => KeyringPair;
|
||||
all: () => KeyringPair[];
|
||||
get: (address: string | Uint8Array) => KeyringPair;
|
||||
remove: (address: string | Uint8Array) => void;
|
||||
}
|
||||
export interface KeyringInstance {
|
||||
readonly pairs: KeyringPair[];
|
||||
readonly publicKeys: Uint8Array[];
|
||||
readonly type: KeypairType;
|
||||
decodeAddress(encoded: string | Uint8Array, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
|
||||
encodeAddress(key: Uint8Array | string, ss58Format?: Prefix): string;
|
||||
setSS58Format(ss58Format: Prefix): void;
|
||||
addPair(pair: KeyringPair): KeyringPair;
|
||||
addFromAddress(address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeypairType, ignoreChecksum?: boolean): KeyringPair;
|
||||
addFromJson(pair: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
addFromMnemonic(mnemonic: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
addFromPair(pair: Keypair, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
addFromSeed(seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeypairType): KeyringPair;
|
||||
addFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
createFromJson(json: KeyringPair$Json, ignoreChecksum?: boolean): KeyringPair;
|
||||
createFromPair(pair: Keypair, meta: KeyringPair$Meta, type: KeypairType): KeyringPair;
|
||||
createFromUri(suri: string, meta?: KeyringPair$Meta, type?: KeypairType, wordlist?: string[]): KeyringPair;
|
||||
getPair(address: string | Uint8Array): KeyringPair;
|
||||
getPairs(): KeyringPair[];
|
||||
getPublicKeys(): Uint8Array[];
|
||||
removePair(address: string | Uint8Array): void;
|
||||
toJson(address: string | Uint8Array, passphrase?: string): KeyringPair$Json;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export {};
|
||||
Reference in new issue
Block a user