refactor: move brother_node development artifact to dev/test-nodes subdirectory
Development Artifact Cleanup: ✅ BROTHER_NODE REORGANIZATION: Moved development test node to appropriate location - dev/test-nodes/brother_node/: Moved from root directory for better organization - Contains development configuration, test logs, and test chain data - No impact on production systems - purely development/testing artifact ✅ DEVELOPMENT ARTIFACTS IDENTIFIED: - Chain ID: aitbc-brother-chain (test/development chain) - Ports: 8010 (P2P) and 8011 (RPC) - different from production - Environment: .env file with test configuration - Logs: rpc.log and node.log from development testing session (March 15, 2026) ✅ ROOT DIRECTORY CLEANUP: Removed development clutter from production directory - brother_node/ moved to dev/test-nodes/brother_node/ - Root directory now contains only production-ready components - Development artifacts properly organized in dev/ subdirectory DIRECTORY STRUCTURE IMPROVEMENT: 📁 dev/test-nodes/: Development and testing node configurations 🏗️ Root Directory: Clean production structure with only essential components 🧪 Development Isolation: Test environments separated from production BENEFITS: ✅ Clean Production Directory: No development artifacts in root ✅ Better Organization: Development nodes grouped in dev/ subdirectory ✅ Clear Separation: Production vs development environments clearly distinguished ✅ Maintainability: Easier to identify and manage development components RESULT: Successfully moved brother_node development artifact to dev/test-nodes/ subdirectory, cleaning up the root directory while preserving development testing environment for future use.
This commit is contained in:
57
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.d.ts
generated
vendored
Executable file
57
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.d.ts
generated
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
import { AbstractSigner } from "../providers/index.js";
|
||||
import type { SigningKey } from "../crypto/index.js";
|
||||
import type { AuthorizationRequest, TypedDataDomain, TypedDataField } from "../hash/index.js";
|
||||
import type { Provider, TransactionRequest } from "../providers/index.js";
|
||||
import type { Authorization } from "../transaction/index.js";
|
||||
/**
|
||||
* The **BaseWallet** is a stream-lined implementation of a
|
||||
* [[Signer]] that operates with a private key.
|
||||
*
|
||||
* It is preferred to use the [[Wallet]] class, as it offers
|
||||
* additional functionality and simplifies loading a variety
|
||||
* of JSON formats, Mnemonic Phrases, etc.
|
||||
*
|
||||
* This class may be of use for those attempting to implement
|
||||
* a minimal Signer.
|
||||
*/
|
||||
export declare class BaseWallet extends AbstractSigner {
|
||||
#private;
|
||||
/**
|
||||
* The wallet address.
|
||||
*/
|
||||
readonly address: string;
|
||||
/**
|
||||
* Creates a new BaseWallet for %%privateKey%%, optionally
|
||||
* connected to %%provider%%.
|
||||
*
|
||||
* If %%provider%% is not specified, only offline methods can
|
||||
* be used.
|
||||
*/
|
||||
constructor(privateKey: SigningKey, provider?: null | Provider);
|
||||
/**
|
||||
* The [[SigningKey]] used for signing payloads.
|
||||
*/
|
||||
get signingKey(): SigningKey;
|
||||
/**
|
||||
* The private key for this wallet.
|
||||
*/
|
||||
get privateKey(): string;
|
||||
getAddress(): Promise<string>;
|
||||
connect(provider: null | Provider): BaseWallet;
|
||||
signTransaction(tx: TransactionRequest): Promise<string>;
|
||||
signMessage(message: string | Uint8Array): Promise<string>;
|
||||
/**
|
||||
* Returns the signature for %%message%% signed with this wallet.
|
||||
*/
|
||||
signMessageSync(message: string | Uint8Array): string;
|
||||
/**
|
||||
* Returns the Authorization for %%auth%%.
|
||||
*/
|
||||
authorizeSync(auth: AuthorizationRequest): Authorization;
|
||||
/**
|
||||
* Resolves to the Authorization for %%auth%%.
|
||||
*/
|
||||
authorize(auth: AuthorizationRequest): Promise<Authorization>;
|
||||
signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
|
||||
}
|
||||
//# sourceMappingURL=base-wallet.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"base-wallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/base-wallet.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAe,MAAM,uBAAuB,CAA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C,MAAM,CAAC;CAsB1I"}
|
||||
127
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.js
generated
vendored
Executable file
127
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.js
generated
vendored
Executable file
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaseWallet = void 0;
|
||||
const index_js_1 = require("../address/index.js");
|
||||
const index_js_2 = require("../hash/index.js");
|
||||
const index_js_3 = require("../providers/index.js");
|
||||
const index_js_4 = require("../transaction/index.js");
|
||||
const index_js_5 = require("../utils/index.js");
|
||||
/**
|
||||
* The **BaseWallet** is a stream-lined implementation of a
|
||||
* [[Signer]] that operates with a private key.
|
||||
*
|
||||
* It is preferred to use the [[Wallet]] class, as it offers
|
||||
* additional functionality and simplifies loading a variety
|
||||
* of JSON formats, Mnemonic Phrases, etc.
|
||||
*
|
||||
* This class may be of use for those attempting to implement
|
||||
* a minimal Signer.
|
||||
*/
|
||||
class BaseWallet extends index_js_3.AbstractSigner {
|
||||
/**
|
||||
* The wallet address.
|
||||
*/
|
||||
address;
|
||||
#signingKey;
|
||||
/**
|
||||
* Creates a new BaseWallet for %%privateKey%%, optionally
|
||||
* connected to %%provider%%.
|
||||
*
|
||||
* If %%provider%% is not specified, only offline methods can
|
||||
* be used.
|
||||
*/
|
||||
constructor(privateKey, provider) {
|
||||
super(provider);
|
||||
(0, index_js_5.assertArgument)(privateKey && typeof (privateKey.sign) === "function", "invalid private key", "privateKey", "[ REDACTED ]");
|
||||
this.#signingKey = privateKey;
|
||||
const address = (0, index_js_4.computeAddress)(this.signingKey.publicKey);
|
||||
(0, index_js_5.defineProperties)(this, { address });
|
||||
}
|
||||
// Store private values behind getters to reduce visibility
|
||||
// in console.log
|
||||
/**
|
||||
* The [[SigningKey]] used for signing payloads.
|
||||
*/
|
||||
get signingKey() { return this.#signingKey; }
|
||||
/**
|
||||
* The private key for this wallet.
|
||||
*/
|
||||
get privateKey() { return this.signingKey.privateKey; }
|
||||
async getAddress() { return this.address; }
|
||||
connect(provider) {
|
||||
return new BaseWallet(this.#signingKey, provider);
|
||||
}
|
||||
async signTransaction(tx) {
|
||||
tx = (0, index_js_3.copyRequest)(tx);
|
||||
// Replace any Addressable or ENS name with an address
|
||||
const { to, from } = await (0, index_js_5.resolveProperties)({
|
||||
to: (tx.to ? (0, index_js_1.resolveAddress)(tx.to, this) : undefined),
|
||||
from: (tx.from ? (0, index_js_1.resolveAddress)(tx.from, this) : undefined)
|
||||
});
|
||||
if (to != null) {
|
||||
tx.to = to;
|
||||
}
|
||||
if (from != null) {
|
||||
tx.from = from;
|
||||
}
|
||||
if (tx.from != null) {
|
||||
(0, index_js_5.assertArgument)((0, index_js_1.getAddress)((tx.from)) === this.address, "transaction from address mismatch", "tx.from", tx.from);
|
||||
delete tx.from;
|
||||
}
|
||||
// Build the transaction
|
||||
const btx = index_js_4.Transaction.from(tx);
|
||||
btx.signature = this.signingKey.sign(btx.unsignedHash);
|
||||
return btx.serialized;
|
||||
}
|
||||
async signMessage(message) {
|
||||
return this.signMessageSync(message);
|
||||
}
|
||||
// @TODO: Add a secialized signTx and signTyped sync that enforces
|
||||
// all parameters are known?
|
||||
/**
|
||||
* Returns the signature for %%message%% signed with this wallet.
|
||||
*/
|
||||
signMessageSync(message) {
|
||||
return this.signingKey.sign((0, index_js_2.hashMessage)(message)).serialized;
|
||||
}
|
||||
/**
|
||||
* Returns the Authorization for %%auth%%.
|
||||
*/
|
||||
authorizeSync(auth) {
|
||||
(0, index_js_5.assertArgument)(typeof (auth.address) === "string", "invalid address for authorizeSync", "auth.address", auth);
|
||||
const signature = this.signingKey.sign((0, index_js_2.hashAuthorization)(auth));
|
||||
return Object.assign({}, {
|
||||
address: (0, index_js_1.getAddress)(auth.address),
|
||||
nonce: (0, index_js_5.getBigInt)(auth.nonce || 0),
|
||||
chainId: (0, index_js_5.getBigInt)(auth.chainId || 0),
|
||||
}, { signature });
|
||||
}
|
||||
/**
|
||||
* Resolves to the Authorization for %%auth%%.
|
||||
*/
|
||||
async authorize(auth) {
|
||||
auth = Object.assign({}, auth, {
|
||||
address: await (0, index_js_1.resolveAddress)(auth.address, this)
|
||||
});
|
||||
return this.authorizeSync(await this.populateAuthorization(auth));
|
||||
}
|
||||
async signTypedData(domain, types, value) {
|
||||
// Populate any ENS names
|
||||
const populated = await index_js_2.TypedDataEncoder.resolveNames(domain, types, value, async (name) => {
|
||||
// @TODO: this should use resolveName; addresses don't
|
||||
// need a provider
|
||||
(0, index_js_5.assert)(this.provider != null, "cannot resolve ENS names without a provider", "UNSUPPORTED_OPERATION", {
|
||||
operation: "resolveName",
|
||||
info: { name }
|
||||
});
|
||||
const address = await this.provider.resolveName(name);
|
||||
(0, index_js_5.assert)(address != null, "unconfigured ENS name", "UNCONFIGURED_NAME", {
|
||||
value: name
|
||||
});
|
||||
return address;
|
||||
});
|
||||
return this.signingKey.sign(index_js_2.TypedDataEncoder.hash(populated.domain, types, populated.value)).serialized;
|
||||
}
|
||||
}
|
||||
exports.BaseWallet = BaseWallet;
|
||||
//# sourceMappingURL=base-wallet.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/base-wallet.js.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"base-wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/base-wallet.ts"],"names":[],"mappings":";;;AAAA,kDAAiE;AACjE,+CAE0B;AAC1B,oDAAoE;AACpE,sDAAsE;AACtE,gDAE2B;AAU3B;;;;;;;;;;GAUG;AACH,MAAa,UAAW,SAAQ,yBAAc;IAC1C;;OAEG;IACM,OAAO,CAAU;IAEjB,WAAW,CAAa;IAEjC;;;;;;OAMG;IACH,YAAY,UAAsB,EAAE,QAA0B;QAC1D,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,IAAA,yBAAc,EAAC,UAAU,IAAI,O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,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,2BAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IAC5G,CAAC;CACJ;AAlID,gCAkIC"}
|
||||
248
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.d.ts
generated
vendored
Executable file
248
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.d.ts
generated
vendored
Executable file
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Explain HD Wallets..
|
||||
*
|
||||
* @_subsection: api/wallet:HD Wallets [hd-wallets]
|
||||
*/
|
||||
import { SigningKey } from "../crypto/index.js";
|
||||
import { VoidSigner } from "../providers/index.js";
|
||||
import { BaseWallet } from "./base-wallet.js";
|
||||
import { Mnemonic } from "./mnemonic.js";
|
||||
import type { ProgressCallback } from "../crypto/index.js";
|
||||
import type { Provider } from "../providers/index.js";
|
||||
import type { BytesLike, Numeric } from "../utils/index.js";
|
||||
import type { Wordlist } from "../wordlists/index.js";
|
||||
/**
|
||||
* The default derivation path for Ethereum HD Nodes. (i.e. ``"m/44'/60'/0'/0/0"``)
|
||||
*/
|
||||
export declare const defaultPath: string;
|
||||
/**
|
||||
* An **HDNodeWallet** is a [[Signer]] backed by the private key derived
|
||||
* from an HD Node using the [[link-bip-32]] stantard.
|
||||
*
|
||||
* An HD Node forms a hierarchal structure with each HD Node having a
|
||||
* private key and the ability to derive child HD Nodes, defined by
|
||||
* a path indicating the index of each child.
|
||||
*/
|
||||
export declare class HDNodeWallet extends BaseWallet {
|
||||
#private;
|
||||
/**
|
||||
* The compressed public key.
|
||||
*/
|
||||
readonly publicKey: string;
|
||||
/**
|
||||
* The fingerprint.
|
||||
*
|
||||
* A fingerprint allows quick qay to detect parent and child nodes,
|
||||
* but developers should be prepared to deal with collisions as it
|
||||
* is only 4 bytes.
|
||||
*/
|
||||
readonly fingerprint: string;
|
||||
/**
|
||||
* The parent fingerprint.
|
||||
*/
|
||||
readonly parentFingerprint: string;
|
||||
/**
|
||||
* The mnemonic used to create this HD Node, if available.
|
||||
*
|
||||
* Sources such as extended keys do not encode the mnemonic, in
|
||||
* which case this will be ``null``.
|
||||
*/
|
||||
readonly mnemonic: null | Mnemonic;
|
||||
/**
|
||||
* The chaincode, which is effectively a public key used
|
||||
* to derive children.
|
||||
*/
|
||||
readonly chainCode: string;
|
||||
/**
|
||||
* The derivation path of this wallet.
|
||||
*
|
||||
* Since extended keys do not provide full path details, this
|
||||
* may be ``null``, if instantiated from a source that does not
|
||||
* encode it.
|
||||
*/
|
||||
readonly path: null | string;
|
||||
/**
|
||||
* The child index of this wallet. Values over ``2 *\* 31`` indicate
|
||||
* the node is hardened.
|
||||
*/
|
||||
readonly index: number;
|
||||
/**
|
||||
* The depth of this wallet, which is the number of components
|
||||
* in its path.
|
||||
*/
|
||||
readonly depth: number;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard: any, signingKey: SigningKey, parentFingerprint: string, chainCode: string, path: null | string, index: number, depth: number, mnemonic: null | Mnemonic, provider: null | Provider);
|
||||
connect(provider: null | Provider): HDNodeWallet;
|
||||
/**
|
||||
* Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* If %%progressCallback%% is specified, it will receive periodic
|
||||
* updates as the encryption process progreses.
|
||||
*/
|
||||
encrypt(password: Uint8Array | string, progressCallback?: ProgressCallback): Promise<string>;
|
||||
/**
|
||||
* Returns a [JSON Keystore Wallet](json-wallets) encryped with
|
||||
* %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](encrypt) instead,
|
||||
* which allows a [[ProgressCallback]] to keep the user informed.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until
|
||||
* it is complete, which may be a non-trivial duration.
|
||||
*/
|
||||
encryptSync(password: Uint8Array | string): string;
|
||||
/**
|
||||
* The extended key.
|
||||
*
|
||||
* This key will begin with the prefix ``xpriv`` and can be used to
|
||||
* reconstruct this HD Node to derive its children.
|
||||
*/
|
||||
get extendedKey(): string;
|
||||
/**
|
||||
* Returns true if this wallet has a path, providing a Type Guard
|
||||
* that the path is non-null.
|
||||
*/
|
||||
hasPath(): this is {
|
||||
path: string;
|
||||
};
|
||||
/**
|
||||
* Returns a neutered HD Node, which removes the private details
|
||||
* of an HD Node.
|
||||
*
|
||||
* A neutered node has no private key, but can be used to derive
|
||||
* child addresses and other public data about the HD Node.
|
||||
*/
|
||||
neuter(): HDNodeVoidWallet;
|
||||
/**
|
||||
* Return the child for %%index%%.
|
||||
*/
|
||||
deriveChild(_index: Numeric): HDNodeWallet;
|
||||
/**
|
||||
* Return the HDNode for %%path%% from this node.
|
||||
*/
|
||||
derivePath(path: string): HDNodeWallet;
|
||||
/**
|
||||
* Creates a new HD Node from %%extendedKey%%.
|
||||
*
|
||||
* If the %%extendedKey%% will either have a prefix or ``xpub`` or
|
||||
* ``xpriv``, returning a neutered HD Node ([[HDNodeVoidWallet]])
|
||||
* or full HD Node ([[HDNodeWallet) respectively.
|
||||
*/
|
||||
static fromExtendedKey(extendedKey: string): HDNodeWallet | HDNodeVoidWallet;
|
||||
/**
|
||||
* Creates a new random HDNode.
|
||||
*/
|
||||
static createRandom(password?: string, path?: string, wordlist?: Wordlist): HDNodeWallet;
|
||||
/**
|
||||
* Create an HD Node from %%mnemonic%%.
|
||||
*/
|
||||
static fromMnemonic(mnemonic: Mnemonic, path?: string): HDNodeWallet;
|
||||
/**
|
||||
* Creates an HD Node from a mnemonic %%phrase%%.
|
||||
*/
|
||||
static fromPhrase(phrase: string, password?: string, path?: string, wordlist?: Wordlist): HDNodeWallet;
|
||||
/**
|
||||
* Creates an HD Node from a %%seed%%.
|
||||
*/
|
||||
static fromSeed(seed: BytesLike): HDNodeWallet;
|
||||
}
|
||||
/**
|
||||
* A **HDNodeVoidWallet** cannot sign, but provides access to
|
||||
* the children nodes of a [[link-bip-32]] HD wallet addresses.
|
||||
*
|
||||
* The can be created by using an extended ``xpub`` key to
|
||||
* [[HDNodeWallet_fromExtendedKey]] or by
|
||||
* [nuetering](HDNodeWallet-neuter) a [[HDNodeWallet]].
|
||||
*/
|
||||
export declare class HDNodeVoidWallet extends VoidSigner {
|
||||
/**
|
||||
* The compressed public key.
|
||||
*/
|
||||
readonly publicKey: string;
|
||||
/**
|
||||
* The fingerprint.
|
||||
*
|
||||
* A fingerprint allows quick qay to detect parent and child nodes,
|
||||
* but developers should be prepared to deal with collisions as it
|
||||
* is only 4 bytes.
|
||||
*/
|
||||
readonly fingerprint: string;
|
||||
/**
|
||||
* The parent node fingerprint.
|
||||
*/
|
||||
readonly parentFingerprint: string;
|
||||
/**
|
||||
* The chaincode, which is effectively a public key used
|
||||
* to derive children.
|
||||
*/
|
||||
readonly chainCode: string;
|
||||
/**
|
||||
* The derivation path of this wallet.
|
||||
*
|
||||
* Since extended keys do not provider full path details, this
|
||||
* may be ``null``, if instantiated from a source that does not
|
||||
* enocde it.
|
||||
*/
|
||||
readonly path: null | string;
|
||||
/**
|
||||
* The child index of this wallet. Values over ``2 *\* 31`` indicate
|
||||
* the node is hardened.
|
||||
*/
|
||||
readonly index: number;
|
||||
/**
|
||||
* The depth of this wallet, which is the number of components
|
||||
* in its path.
|
||||
*/
|
||||
readonly depth: number;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard: any, address: string, publicKey: string, parentFingerprint: string, chainCode: string, path: null | string, index: number, depth: number, provider: null | Provider);
|
||||
connect(provider: null | Provider): HDNodeVoidWallet;
|
||||
/**
|
||||
* The extended key.
|
||||
*
|
||||
* This key will begin with the prefix ``xpub`` and can be used to
|
||||
* reconstruct this neutered key to derive its children addresses.
|
||||
*/
|
||||
get extendedKey(): string;
|
||||
/**
|
||||
* Returns true if this wallet has a path, providing a Type Guard
|
||||
* that the path is non-null.
|
||||
*/
|
||||
hasPath(): this is {
|
||||
path: string;
|
||||
};
|
||||
/**
|
||||
* Return the child for %%index%%.
|
||||
*/
|
||||
deriveChild(_index: Numeric): HDNodeVoidWallet;
|
||||
/**
|
||||
* Return the signer for %%path%% from this node.
|
||||
*/
|
||||
derivePath(path: string): HDNodeVoidWallet;
|
||||
}
|
||||
/**
|
||||
* Returns the [[link-bip-32]] path for the account at %%index%%.
|
||||
*
|
||||
* This is the pattern used by wallets like Ledger.
|
||||
*
|
||||
* There is also an [alternate pattern](getIndexedAccountPath) used by
|
||||
* some software.
|
||||
*/
|
||||
export declare function getAccountPath(_index: Numeric): string;
|
||||
/**
|
||||
* Returns the path using an alternative pattern for deriving accounts,
|
||||
* at %%index%%.
|
||||
*
|
||||
* This derivation path uses the //index// component rather than the
|
||||
* //account// component to derive sequential accounts.
|
||||
*
|
||||
* This is the pattern used by wallets like MetaMask.
|
||||
*/
|
||||
export declare function getIndexedAccountPath(_index: Numeric): string;
|
||||
//# sourceMappingURL=hdwallet.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"hdwallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/hdwallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAuC,UAAU,EAAU,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAUnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAKzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,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CAAC,KAAK,EAAG,MAAM,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAG,MAAM,CAAC;IAExB;;OAEG;gBACS,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,QAAQ;IAYtL,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,gBAAgB;IAKpD;;;;;OAKG;IACH,IAAI,WAAW,IAAI,MAAM,CAiBxB;IAED;;;OAGG;IACH,OAAO,IAAI,IAAI,IAAI;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;IAEnC;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB;IAqB9C;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB;CAG7C;AAmBD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAItD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAI7D"}
|
||||
506
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.js
generated
vendored
Executable file
506
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.js
generated
vendored
Executable file
@@ -0,0 +1,506 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getIndexedAccountPath = exports.getAccountPath = exports.HDNodeVoidWallet = exports.HDNodeWallet = exports.defaultPath = void 0;
|
||||
/**
|
||||
* Explain HD Wallets..
|
||||
*
|
||||
* @_subsection: api/wallet:HD Wallets [hd-wallets]
|
||||
*/
|
||||
const index_js_1 = require("../crypto/index.js");
|
||||
const index_js_2 = require("../providers/index.js");
|
||||
const index_js_3 = require("../transaction/index.js");
|
||||
const index_js_4 = require("../utils/index.js");
|
||||
const lang_en_js_1 = require("../wordlists/lang-en.js");
|
||||
const base_wallet_js_1 = require("./base-wallet.js");
|
||||
const mnemonic_js_1 = require("./mnemonic.js");
|
||||
const json_keystore_js_1 = require("./json-keystore.js");
|
||||
/**
|
||||
* The default derivation path for Ethereum HD Nodes. (i.e. ``"m/44'/60'/0'/0/0"``)
|
||||
*/
|
||||
exports.defaultPath = "m/44'/60'/0'/0/0";
|
||||
// "Bitcoin seed"
|
||||
const MasterSecret = new Uint8Array([66, 105, 116, 99, 111, 105, 110, 32, 115, 101, 101, 100]);
|
||||
const HardenedBit = 0x80000000;
|
||||
const N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
||||
const Nibbles = "0123456789abcdef";
|
||||
function zpad(value, length) {
|
||||
let result = "";
|
||||
while (value) {
|
||||
result = Nibbles[value % 16] + result;
|
||||
value = Math.trunc(value / 16);
|
||||
}
|
||||
while (result.length < length * 2) {
|
||||
result = "0" + result;
|
||||
}
|
||||
return "0x" + result;
|
||||
}
|
||||
function encodeBase58Check(_value) {
|
||||
const value = (0, index_js_4.getBytes)(_value);
|
||||
const check = (0, index_js_4.dataSlice)((0, index_js_1.sha256)((0, index_js_1.sha256)(value)), 0, 4);
|
||||
const bytes = (0, index_js_4.concat)([value, check]);
|
||||
return (0, index_js_4.encodeBase58)(bytes);
|
||||
}
|
||||
const _guard = {};
|
||||
function ser_I(index, chainCode, publicKey, privateKey) {
|
||||
const data = new Uint8Array(37);
|
||||
if (index & HardenedBit) {
|
||||
(0, index_js_4.assert)(privateKey != null, "cannot derive child of neutered node", "UNSUPPORTED_OPERATION", {
|
||||
operation: "deriveChild"
|
||||
});
|
||||
// Data = 0x00 || ser_256(k_par)
|
||||
data.set((0, index_js_4.getBytes)(privateKey), 1);
|
||||
}
|
||||
else {
|
||||
// Data = ser_p(point(k_par))
|
||||
data.set((0, index_js_4.getBytes)(publicKey));
|
||||
}
|
||||
// Data += ser_32(i)
|
||||
for (let i = 24; i >= 0; i -= 8) {
|
||||
data[33 + (i >> 3)] = ((index >> (24 - i)) & 0xff);
|
||||
}
|
||||
const I = (0, index_js_4.getBytes)((0, index_js_1.computeHmac)("sha512", chainCode, data));
|
||||
return { IL: I.slice(0, 32), IR: I.slice(32) };
|
||||
}
|
||||
function derivePath(node, path) {
|
||||
const components = path.split("/");
|
||||
(0, index_js_4.assertArgument)(components.length > 0, "invalid path", "path", path);
|
||||
if (components[0] === "m") {
|
||||
(0, index_js_4.assertArgument)(node.depth === 0, `cannot derive root path (i.e. path starting with "m/") for a node at non-zero depth ${node.depth}`, "path", path);
|
||||
components.shift();
|
||||
}
|
||||
let result = node;
|
||||
for (let i = 0; i < components.length; i++) {
|
||||
const component = components[i];
|
||||
if (component.match(/^[0-9]+'$/)) {
|
||||
const index = parseInt(component.substring(0, component.length - 1));
|
||||
(0, index_js_4.assertArgument)(index < HardenedBit, "invalid path index", `path[${i}]`, component);
|
||||
result = result.deriveChild(HardenedBit + index);
|
||||
}
|
||||
else if (component.match(/^[0-9]+$/)) {
|
||||
const index = parseInt(component);
|
||||
(0, index_js_4.assertArgument)(index < HardenedBit, "invalid path index", `path[${i}]`, component);
|
||||
result = result.deriveChild(index);
|
||||
}
|
||||
else {
|
||||
(0, index_js_4.assertArgument)(false, "invalid path component", `path[${i}]`, component);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* An **HDNodeWallet** is a [[Signer]] backed by the private key derived
|
||||
* from an HD Node using the [[link-bip-32]] stantard.
|
||||
*
|
||||
* An HD Node forms a hierarchal structure with each HD Node having a
|
||||
* private key and the ability to derive child HD Nodes, defined by
|
||||
* a path indicating the index of each child.
|
||||
*/
|
||||
class HDNodeWallet extends base_wallet_js_1.BaseWallet {
|
||||
/**
|
||||
* The compressed public key.
|
||||
*/
|
||||
publicKey;
|
||||
/**
|
||||
* The fingerprint.
|
||||
*
|
||||
* A fingerprint allows quick qay to detect parent and child nodes,
|
||||
* but developers should be prepared to deal with collisions as it
|
||||
* is only 4 bytes.
|
||||
*/
|
||||
fingerprint;
|
||||
/**
|
||||
* The parent fingerprint.
|
||||
*/
|
||||
parentFingerprint;
|
||||
/**
|
||||
* The mnemonic used to create this HD Node, if available.
|
||||
*
|
||||
* Sources such as extended keys do not encode the mnemonic, in
|
||||
* which case this will be ``null``.
|
||||
*/
|
||||
mnemonic;
|
||||
/**
|
||||
* The chaincode, which is effectively a public key used
|
||||
* to derive children.
|
||||
*/
|
||||
chainCode;
|
||||
/**
|
||||
* The derivation path of this wallet.
|
||||
*
|
||||
* Since extended keys do not provide full path details, this
|
||||
* may be ``null``, if instantiated from a source that does not
|
||||
* encode it.
|
||||
*/
|
||||
path;
|
||||
/**
|
||||
* The child index of this wallet. Values over ``2 *\* 31`` indicate
|
||||
* the node is hardened.
|
||||
*/
|
||||
index;
|
||||
/**
|
||||
* The depth of this wallet, which is the number of components
|
||||
* in its path.
|
||||
*/
|
||||
depth;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard, signingKey, parentFingerprint, chainCode, path, index, depth, mnemonic, provider) {
|
||||
super(signingKey, provider);
|
||||
(0, index_js_4.assertPrivate)(guard, _guard, "HDNodeWallet");
|
||||
(0, index_js_4.defineProperties)(this, { publicKey: signingKey.compressedPublicKey });
|
||||
const fingerprint = (0, index_js_4.dataSlice)((0, index_js_1.ripemd160)((0, index_js_1.sha256)(this.publicKey)), 0, 4);
|
||||
(0, index_js_4.defineProperties)(this, {
|
||||
parentFingerprint, fingerprint,
|
||||
chainCode, path, index, depth
|
||||
});
|
||||
(0, index_js_4.defineProperties)(this, { mnemonic });
|
||||
}
|
||||
connect(provider) {
|
||||
return new HDNodeWallet(_guard, this.signingKey, this.parentFingerprint, this.chainCode, this.path, this.index, this.depth, this.mnemonic, provider);
|
||||
}
|
||||
#account() {
|
||||
const account = { address: this.address, privateKey: this.privateKey };
|
||||
const m = this.mnemonic;
|
||||
if (this.path && m && m.wordlist.locale === "en" && m.password === "") {
|
||||
account.mnemonic = {
|
||||
path: this.path,
|
||||
locale: "en",
|
||||
entropy: m.entropy
|
||||
};
|
||||
}
|
||||
return account;
|
||||
}
|
||||
/**
|
||||
* Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* If %%progressCallback%% is specified, it will receive periodic
|
||||
* updates as the encryption process progreses.
|
||||
*/
|
||||
async encrypt(password, progressCallback) {
|
||||
return await (0, json_keystore_js_1.encryptKeystoreJson)(this.#account(), password, { progressCallback });
|
||||
}
|
||||
/**
|
||||
* Returns a [JSON Keystore Wallet](json-wallets) encryped with
|
||||
* %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](encrypt) instead,
|
||||
* which allows a [[ProgressCallback]] to keep the user informed.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until
|
||||
* it is complete, which may be a non-trivial duration.
|
||||
*/
|
||||
encryptSync(password) {
|
||||
return (0, json_keystore_js_1.encryptKeystoreJsonSync)(this.#account(), password);
|
||||
}
|
||||
/**
|
||||
* The extended key.
|
||||
*
|
||||
* This key will begin with the prefix ``xpriv`` and can be used to
|
||||
* reconstruct this HD Node to derive its children.
|
||||
*/
|
||||
get extendedKey() {
|
||||
// We only support the mainnet values for now, but if anyone needs
|
||||
// testnet values, let me know. I believe current sentiment is that
|
||||
// we should always use mainnet, and use BIP-44 to derive the network
|
||||
// - Mainnet: public=0x0488B21E, private=0x0488ADE4
|
||||
// - Testnet: public=0x043587CF, private=0x04358394
|
||||
(0, index_js_4.assert)(this.depth < 256, "Depth too deep", "UNSUPPORTED_OPERATION", { operation: "extendedKey" });
|
||||
return encodeBase58Check((0, index_js_4.concat)([
|
||||
"0x0488ADE4", zpad(this.depth, 1), this.parentFingerprint,
|
||||
zpad(this.index, 4), this.chainCode,
|
||||
(0, index_js_4.concat)(["0x00", this.privateKey])
|
||||
]));
|
||||
}
|
||||
/**
|
||||
* Returns true if this wallet has a path, providing a Type Guard
|
||||
* that the path is non-null.
|
||||
*/
|
||||
hasPath() { return (this.path != null); }
|
||||
/**
|
||||
* Returns a neutered HD Node, which removes the private details
|
||||
* of an HD Node.
|
||||
*
|
||||
* A neutered node has no private key, but can be used to derive
|
||||
* child addresses and other public data about the HD Node.
|
||||
*/
|
||||
neuter() {
|
||||
return new HDNodeVoidWallet(_guard, this.address, this.publicKey, this.parentFingerprint, this.chainCode, this.path, this.index, this.depth, this.provider);
|
||||
}
|
||||
/**
|
||||
* Return the child for %%index%%.
|
||||
*/
|
||||
deriveChild(_index) {
|
||||
const index = (0, index_js_4.getNumber)(_index, "index");
|
||||
(0, index_js_4.assertArgument)(index <= 0xffffffff, "invalid index", "index", index);
|
||||
// Base path
|
||||
let path = this.path;
|
||||
if (path) {
|
||||
path += "/" + (index & ~HardenedBit);
|
||||
if (index & HardenedBit) {
|
||||
path += "'";
|
||||
}
|
||||
}
|
||||
const { IR, IL } = ser_I(index, this.chainCode, this.publicKey, this.privateKey);
|
||||
const ki = new index_js_1.SigningKey((0, index_js_4.toBeHex)(((0, index_js_4.toBigInt)(IL) + BigInt(this.privateKey)) % N, 32));
|
||||
return new HDNodeWallet(_guard, ki, this.fingerprint, (0, index_js_4.hexlify)(IR), path, index, this.depth + 1, this.mnemonic, this.provider);
|
||||
}
|
||||
/**
|
||||
* Return the HDNode for %%path%% from this node.
|
||||
*/
|
||||
derivePath(path) {
|
||||
return derivePath(this, path);
|
||||
}
|
||||
static #fromSeed(_seed, mnemonic) {
|
||||
(0, index_js_4.assertArgument)((0, index_js_4.isBytesLike)(_seed), "invalid seed", "seed", "[REDACTED]");
|
||||
const seed = (0, index_js_4.getBytes)(_seed, "seed");
|
||||
(0, index_js_4.assertArgument)(seed.length >= 16 && seed.length <= 64, "invalid seed", "seed", "[REDACTED]");
|
||||
const I = (0, index_js_4.getBytes)((0, index_js_1.computeHmac)("sha512", MasterSecret, seed));
|
||||
const signingKey = new index_js_1.SigningKey((0, index_js_4.hexlify)(I.slice(0, 32)));
|
||||
return new HDNodeWallet(_guard, signingKey, "0x00000000", (0, index_js_4.hexlify)(I.slice(32)), "m", 0, 0, mnemonic, null);
|
||||
}
|
||||
/**
|
||||
* Creates a new HD Node from %%extendedKey%%.
|
||||
*
|
||||
* If the %%extendedKey%% will either have a prefix or ``xpub`` or
|
||||
* ``xpriv``, returning a neutered HD Node ([[HDNodeVoidWallet]])
|
||||
* or full HD Node ([[HDNodeWallet) respectively.
|
||||
*/
|
||||
static fromExtendedKey(extendedKey) {
|
||||
const bytes = (0, index_js_4.toBeArray)((0, index_js_4.decodeBase58)(extendedKey)); // @TODO: redact
|
||||
(0, index_js_4.assertArgument)(bytes.length === 82 || encodeBase58Check(bytes.slice(0, 78)) === extendedKey, "invalid extended key", "extendedKey", "[ REDACTED ]");
|
||||
const depth = bytes[4];
|
||||
const parentFingerprint = (0, index_js_4.hexlify)(bytes.slice(5, 9));
|
||||
const index = parseInt((0, index_js_4.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
||||
const chainCode = (0, index_js_4.hexlify)(bytes.slice(13, 45));
|
||||
const key = bytes.slice(45, 78);
|
||||
switch ((0, index_js_4.hexlify)(bytes.slice(0, 4))) {
|
||||
// Public Key
|
||||
case "0x0488b21e":
|
||||
case "0x043587cf": {
|
||||
const publicKey = (0, index_js_4.hexlify)(key);
|
||||
return new HDNodeVoidWallet(_guard, (0, index_js_3.computeAddress)(publicKey), publicKey, parentFingerprint, chainCode, null, index, depth, null);
|
||||
}
|
||||
// Private Key
|
||||
case "0x0488ade4":
|
||||
case "0x04358394 ":
|
||||
if (key[0] !== 0) {
|
||||
break;
|
||||
}
|
||||
return new HDNodeWallet(_guard, new index_js_1.SigningKey(key.slice(1)), parentFingerprint, chainCode, null, index, depth, null, null);
|
||||
}
|
||||
(0, index_js_4.assertArgument)(false, "invalid extended key prefix", "extendedKey", "[ REDACTED ]");
|
||||
}
|
||||
/**
|
||||
* Creates a new random HDNode.
|
||||
*/
|
||||
static createRandom(password, path, wordlist) {
|
||||
if (password == null) {
|
||||
password = "";
|
||||
}
|
||||
if (path == null) {
|
||||
path = exports.defaultPath;
|
||||
}
|
||||
if (wordlist == null) {
|
||||
wordlist = lang_en_js_1.LangEn.wordlist();
|
||||
}
|
||||
const mnemonic = mnemonic_js_1.Mnemonic.fromEntropy((0, index_js_1.randomBytes)(16), password, wordlist);
|
||||
return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path);
|
||||
}
|
||||
/**
|
||||
* Create an HD Node from %%mnemonic%%.
|
||||
*/
|
||||
static fromMnemonic(mnemonic, path) {
|
||||
if (!path) {
|
||||
path = exports.defaultPath;
|
||||
}
|
||||
return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path);
|
||||
}
|
||||
/**
|
||||
* Creates an HD Node from a mnemonic %%phrase%%.
|
||||
*/
|
||||
static fromPhrase(phrase, password, path, wordlist) {
|
||||
if (password == null) {
|
||||
password = "";
|
||||
}
|
||||
if (path == null) {
|
||||
path = exports.defaultPath;
|
||||
}
|
||||
if (wordlist == null) {
|
||||
wordlist = lang_en_js_1.LangEn.wordlist();
|
||||
}
|
||||
const mnemonic = mnemonic_js_1.Mnemonic.fromPhrase(phrase, password, wordlist);
|
||||
return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path);
|
||||
}
|
||||
/**
|
||||
* Creates an HD Node from a %%seed%%.
|
||||
*/
|
||||
static fromSeed(seed) {
|
||||
return HDNodeWallet.#fromSeed(seed, null);
|
||||
}
|
||||
}
|
||||
exports.HDNodeWallet = HDNodeWallet;
|
||||
/**
|
||||
* A **HDNodeVoidWallet** cannot sign, but provides access to
|
||||
* the children nodes of a [[link-bip-32]] HD wallet addresses.
|
||||
*
|
||||
* The can be created by using an extended ``xpub`` key to
|
||||
* [[HDNodeWallet_fromExtendedKey]] or by
|
||||
* [nuetering](HDNodeWallet-neuter) a [[HDNodeWallet]].
|
||||
*/
|
||||
class HDNodeVoidWallet extends index_js_2.VoidSigner {
|
||||
/**
|
||||
* The compressed public key.
|
||||
*/
|
||||
publicKey;
|
||||
/**
|
||||
* The fingerprint.
|
||||
*
|
||||
* A fingerprint allows quick qay to detect parent and child nodes,
|
||||
* but developers should be prepared to deal with collisions as it
|
||||
* is only 4 bytes.
|
||||
*/
|
||||
fingerprint;
|
||||
/**
|
||||
* The parent node fingerprint.
|
||||
*/
|
||||
parentFingerprint;
|
||||
/**
|
||||
* The chaincode, which is effectively a public key used
|
||||
* to derive children.
|
||||
*/
|
||||
chainCode;
|
||||
/**
|
||||
* The derivation path of this wallet.
|
||||
*
|
||||
* Since extended keys do not provider full path details, this
|
||||
* may be ``null``, if instantiated from a source that does not
|
||||
* enocde it.
|
||||
*/
|
||||
path;
|
||||
/**
|
||||
* The child index of this wallet. Values over ``2 *\* 31`` indicate
|
||||
* the node is hardened.
|
||||
*/
|
||||
index;
|
||||
/**
|
||||
* The depth of this wallet, which is the number of components
|
||||
* in its path.
|
||||
*/
|
||||
depth;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard, address, publicKey, parentFingerprint, chainCode, path, index, depth, provider) {
|
||||
super(address, provider);
|
||||
(0, index_js_4.assertPrivate)(guard, _guard, "HDNodeVoidWallet");
|
||||
(0, index_js_4.defineProperties)(this, { publicKey });
|
||||
const fingerprint = (0, index_js_4.dataSlice)((0, index_js_1.ripemd160)((0, index_js_1.sha256)(publicKey)), 0, 4);
|
||||
(0, index_js_4.defineProperties)(this, {
|
||||
publicKey, fingerprint, parentFingerprint, chainCode, path, index, depth
|
||||
});
|
||||
}
|
||||
connect(provider) {
|
||||
return new HDNodeVoidWallet(_guard, this.address, this.publicKey, this.parentFingerprint, this.chainCode, this.path, this.index, this.depth, provider);
|
||||
}
|
||||
/**
|
||||
* The extended key.
|
||||
*
|
||||
* This key will begin with the prefix ``xpub`` and can be used to
|
||||
* reconstruct this neutered key to derive its children addresses.
|
||||
*/
|
||||
get extendedKey() {
|
||||
// We only support the mainnet values for now, but if anyone needs
|
||||
// testnet values, let me know. I believe current sentiment is that
|
||||
// we should always use mainnet, and use BIP-44 to derive the network
|
||||
// - Mainnet: public=0x0488B21E, private=0x0488ADE4
|
||||
// - Testnet: public=0x043587CF, private=0x04358394
|
||||
(0, index_js_4.assert)(this.depth < 256, "Depth too deep", "UNSUPPORTED_OPERATION", { operation: "extendedKey" });
|
||||
return encodeBase58Check((0, index_js_4.concat)([
|
||||
"0x0488B21E",
|
||||
zpad(this.depth, 1),
|
||||
this.parentFingerprint,
|
||||
zpad(this.index, 4),
|
||||
this.chainCode,
|
||||
this.publicKey,
|
||||
]));
|
||||
}
|
||||
/**
|
||||
* Returns true if this wallet has a path, providing a Type Guard
|
||||
* that the path is non-null.
|
||||
*/
|
||||
hasPath() { return (this.path != null); }
|
||||
/**
|
||||
* Return the child for %%index%%.
|
||||
*/
|
||||
deriveChild(_index) {
|
||||
const index = (0, index_js_4.getNumber)(_index, "index");
|
||||
(0, index_js_4.assertArgument)(index <= 0xffffffff, "invalid index", "index", index);
|
||||
// Base path
|
||||
let path = this.path;
|
||||
if (path) {
|
||||
path += "/" + (index & ~HardenedBit);
|
||||
if (index & HardenedBit) {
|
||||
path += "'";
|
||||
}
|
||||
}
|
||||
const { IR, IL } = ser_I(index, this.chainCode, this.publicKey, null);
|
||||
const Ki = index_js_1.SigningKey.addPoints(IL, this.publicKey, true);
|
||||
const address = (0, index_js_3.computeAddress)(Ki);
|
||||
return new HDNodeVoidWallet(_guard, address, Ki, this.fingerprint, (0, index_js_4.hexlify)(IR), path, index, this.depth + 1, this.provider);
|
||||
}
|
||||
/**
|
||||
* Return the signer for %%path%% from this node.
|
||||
*/
|
||||
derivePath(path) {
|
||||
return derivePath(this, path);
|
||||
}
|
||||
}
|
||||
exports.HDNodeVoidWallet = HDNodeVoidWallet;
|
||||
/*
|
||||
export class HDNodeWalletManager {
|
||||
#root: HDNodeWallet;
|
||||
|
||||
constructor(phrase: string, password?: null | string, path?: null | string, locale?: null | Wordlist) {
|
||||
if (password == null) { password = ""; }
|
||||
if (path == null) { path = "m/44'/60'/0'/0"; }
|
||||
if (locale == null) { locale = LangEn.wordlist(); }
|
||||
this.#root = HDNodeWallet.fromPhrase(phrase, password, path, locale);
|
||||
}
|
||||
|
||||
getSigner(index?: number): HDNodeWallet {
|
||||
return this.#root.deriveChild((index == null) ? 0: index);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Returns the [[link-bip-32]] path for the account at %%index%%.
|
||||
*
|
||||
* This is the pattern used by wallets like Ledger.
|
||||
*
|
||||
* There is also an [alternate pattern](getIndexedAccountPath) used by
|
||||
* some software.
|
||||
*/
|
||||
function getAccountPath(_index) {
|
||||
const index = (0, index_js_4.getNumber)(_index, "index");
|
||||
(0, index_js_4.assertArgument)(index >= 0 && index < HardenedBit, "invalid account index", "index", index);
|
||||
return `m/44'/60'/${index}'/0/0`;
|
||||
}
|
||||
exports.getAccountPath = getAccountPath;
|
||||
/**
|
||||
* Returns the path using an alternative pattern for deriving accounts,
|
||||
* at %%index%%.
|
||||
*
|
||||
* This derivation path uses the //index// component rather than the
|
||||
* //account// component to derive sequential accounts.
|
||||
*
|
||||
* This is the pattern used by wallets like MetaMask.
|
||||
*/
|
||||
function getIndexedAccountPath(_index) {
|
||||
const index = (0, index_js_4.getNumber)(_index, "index");
|
||||
(0, index_js_4.assertArgument)(index >= 0 && index < HardenedBit, "invalid account index", "index", index);
|
||||
return `m/44'/60'/0'/0/${index}`;
|
||||
}
|
||||
exports.getIndexedAccountPath = getIndexedAccountPath;
|
||||
//# sourceMappingURL=hdwallet.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/hdwallet.js.map
generated
vendored
Executable file
File diff suppressed because one or more lines are too long
27
dev/env/node_modules/ethers/lib.commonjs/wallet/index.d.ts
generated
vendored
Executable file
27
dev/env/node_modules/ethers/lib.commonjs/wallet/index.d.ts
generated
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* When interacting with Ethereum, it is necessary to use a private
|
||||
* key authenticate actions by signing a payload.
|
||||
*
|
||||
* Wallets are the simplest way to expose the concept of an
|
||||
* //Externally Owner Account// (EOA) as it wraps a private key
|
||||
* and supports high-level methods to sign common types of interaction
|
||||
* and send transactions.
|
||||
*
|
||||
* The class most developers will want to use is [[Wallet]], which
|
||||
* can load a private key directly or from any common wallet format.
|
||||
*
|
||||
* The [[HDNodeWallet]] can be used when it is necessary to access
|
||||
* low-level details of how an HD wallets are derived, exported
|
||||
* or imported.
|
||||
*
|
||||
* @_section: api/wallet:Wallets [about-wallets]
|
||||
*/
|
||||
export { BaseWallet } from "./base-wallet.js";
|
||||
export { defaultPath, getAccountPath, getIndexedAccountPath, HDNodeWallet, HDNodeVoidWallet, } from "./hdwallet.js";
|
||||
export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js";
|
||||
export { isKeystoreJson, decryptKeystoreJsonSync, decryptKeystoreJson, encryptKeystoreJson, encryptKeystoreJsonSync } from "./json-keystore.js";
|
||||
export { Mnemonic } from "./mnemonic.js";
|
||||
export { Wallet } from "./wallet.js";
|
||||
export type { CrowdsaleAccount } from "./json-crowdsale.js";
|
||||
export type { KeystoreAccount, EncryptOptions } from "./json-keystore.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/index.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/index.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACH,WAAW,EAEX,cAAc,EAAE,qBAAqB,EAErC,YAAY,EACZ,gBAAgB,GACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EACH,cAAc,EACd,uBAAuB,EAAE,mBAAmB,EAC5C,mBAAmB,EAAE,uBAAuB,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,YAAY,EACR,eAAe,EAAE,cAAc,EAClC,MAAM,oBAAoB,CAAA"}
|
||||
43
dev/env/node_modules/ethers/lib.commonjs/wallet/index.js
generated
vendored
Executable file
43
dev/env/node_modules/ethers/lib.commonjs/wallet/index.js
generated
vendored
Executable file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
/**
|
||||
* When interacting with Ethereum, it is necessary to use a private
|
||||
* key authenticate actions by signing a payload.
|
||||
*
|
||||
* Wallets are the simplest way to expose the concept of an
|
||||
* //Externally Owner Account// (EOA) as it wraps a private key
|
||||
* and supports high-level methods to sign common types of interaction
|
||||
* and send transactions.
|
||||
*
|
||||
* The class most developers will want to use is [[Wallet]], which
|
||||
* can load a private key directly or from any common wallet format.
|
||||
*
|
||||
* The [[HDNodeWallet]] can be used when it is necessary to access
|
||||
* low-level details of how an HD wallets are derived, exported
|
||||
* or imported.
|
||||
*
|
||||
* @_section: api/wallet:Wallets [about-wallets]
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Wallet = exports.Mnemonic = exports.encryptKeystoreJsonSync = exports.encryptKeystoreJson = exports.decryptKeystoreJson = exports.decryptKeystoreJsonSync = exports.isKeystoreJson = exports.decryptCrowdsaleJson = exports.isCrowdsaleJson = exports.HDNodeVoidWallet = exports.HDNodeWallet = exports.getIndexedAccountPath = exports.getAccountPath = exports.defaultPath = exports.BaseWallet = void 0;
|
||||
var base_wallet_js_1 = require("./base-wallet.js");
|
||||
Object.defineProperty(exports, "BaseWallet", { enumerable: true, get: function () { return base_wallet_js_1.BaseWallet; } });
|
||||
var hdwallet_js_1 = require("./hdwallet.js");
|
||||
Object.defineProperty(exports, "defaultPath", { enumerable: true, get: function () { return hdwallet_js_1.defaultPath; } });
|
||||
Object.defineProperty(exports, "getAccountPath", { enumerable: true, get: function () { return hdwallet_js_1.getAccountPath; } });
|
||||
Object.defineProperty(exports, "getIndexedAccountPath", { enumerable: true, get: function () { return hdwallet_js_1.getIndexedAccountPath; } });
|
||||
Object.defineProperty(exports, "HDNodeWallet", { enumerable: true, get: function () { return hdwallet_js_1.HDNodeWallet; } });
|
||||
Object.defineProperty(exports, "HDNodeVoidWallet", { enumerable: true, get: function () { return hdwallet_js_1.HDNodeVoidWallet; } });
|
||||
var json_crowdsale_js_1 = require("./json-crowdsale.js");
|
||||
Object.defineProperty(exports, "isCrowdsaleJson", { enumerable: true, get: function () { return json_crowdsale_js_1.isCrowdsaleJson; } });
|
||||
Object.defineProperty(exports, "decryptCrowdsaleJson", { enumerable: true, get: function () { return json_crowdsale_js_1.decryptCrowdsaleJson; } });
|
||||
var json_keystore_js_1 = require("./json-keystore.js");
|
||||
Object.defineProperty(exports, "isKeystoreJson", { enumerable: true, get: function () { return json_keystore_js_1.isKeystoreJson; } });
|
||||
Object.defineProperty(exports, "decryptKeystoreJsonSync", { enumerable: true, get: function () { return json_keystore_js_1.decryptKeystoreJsonSync; } });
|
||||
Object.defineProperty(exports, "decryptKeystoreJson", { enumerable: true, get: function () { return json_keystore_js_1.decryptKeystoreJson; } });
|
||||
Object.defineProperty(exports, "encryptKeystoreJson", { enumerable: true, get: function () { return json_keystore_js_1.encryptKeystoreJson; } });
|
||||
Object.defineProperty(exports, "encryptKeystoreJsonSync", { enumerable: true, get: function () { return json_keystore_js_1.encryptKeystoreJsonSync; } });
|
||||
var mnemonic_js_1 = require("./mnemonic.js");
|
||||
Object.defineProperty(exports, "Mnemonic", { enumerable: true, get: function () { return mnemonic_js_1.Mnemonic; } });
|
||||
var wallet_js_1 = require("./wallet.js");
|
||||
Object.defineProperty(exports, "Wallet", { enumerable: true, get: function () { return wallet_js_1.Wallet; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/index.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/index.js.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src.ts/wallet/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,mDAA8C;AAArC,4GAAA,UAAU,OAAA;AAEnB,6CAOuB;AANnB,0GAAA,WAAW,OAAA;AAEX,6GAAA,cAAc,OAAA;AAAE,oHAAA,qBAAqB,OAAA;AAErC,2GAAA,YAAY,OAAA;AACZ,+GAAA,gBAAgB,OAAA;AAGpB,yDAA4E;AAAnE,oHAAA,eAAe,OAAA;AAAE,yHAAA,oBAAoB,OAAA;AAE9C,uDAI4B;AAHxB,kHAAA,cAAc,OAAA;AACd,2HAAA,uBAAuB,OAAA;AAAE,uHAAA,mBAAmB,OAAA;AAC5C,uHAAA,mBAAmB,OAAA;AAAE,2HAAA,uBAAuB,OAAA;AAGhD,6CAAyC;AAAhC,uGAAA,QAAQ,OAAA;AAEjB,yCAAqC;AAA5B,mGAAA,MAAM,OAAA"}
|
||||
27
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.d.ts
generated
vendored
Executable file
27
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.d.ts
generated
vendored
Executable file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @_subsection: api/wallet:JSON Wallets [json-wallets]
|
||||
*/
|
||||
/**
|
||||
* The data stored within a JSON Crowdsale wallet is fairly
|
||||
* minimal.
|
||||
*/
|
||||
export type CrowdsaleAccount = {
|
||||
privateKey: string;
|
||||
address: string;
|
||||
};
|
||||
/**
|
||||
* Returns true if %%json%% is a valid JSON Crowdsale wallet.
|
||||
*/
|
||||
export declare function isCrowdsaleJson(json: string): boolean;
|
||||
/**
|
||||
* Before Ethereum launched, it was necessary to create a wallet
|
||||
* format for backers to use, which would be used to receive ether
|
||||
* as a reward for contributing to the project.
|
||||
*
|
||||
* The [[link-crowdsale]] format is now obsolete, but it is still
|
||||
* useful to support and the additional code is fairly trivial as
|
||||
* all the primitives required are used through core portions of
|
||||
* the library.
|
||||
*/
|
||||
export declare function decryptCrowdsaleJson(json: string, _password: string | Uint8Array): CrowdsaleAccount;
|
||||
//# sourceMappingURL=json-crowdsale.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"json-crowdsale.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/json-crowdsale.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMrD;AAID;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,CA2BnG"}
|
||||
60
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.js
generated
vendored
Executable file
60
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.js
generated
vendored
Executable file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @_subsection: api/wallet:JSON Wallets [json-wallets]
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.decryptCrowdsaleJson = exports.isCrowdsaleJson = void 0;
|
||||
const aes_js_1 = require("aes-js");
|
||||
const index_js_1 = require("../address/index.js");
|
||||
const index_js_2 = require("../crypto/index.js");
|
||||
const index_js_3 = require("../hash/index.js");
|
||||
const index_js_4 = require("../utils/index.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
/**
|
||||
* Returns true if %%json%% is a valid JSON Crowdsale wallet.
|
||||
*/
|
||||
function isCrowdsaleJson(json) {
|
||||
try {
|
||||
const data = JSON.parse(json);
|
||||
if (data.encseed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
exports.isCrowdsaleJson = isCrowdsaleJson;
|
||||
// See: https://github.com/ethereum/pyethsaletool
|
||||
/**
|
||||
* Before Ethereum launched, it was necessary to create a wallet
|
||||
* format for backers to use, which would be used to receive ether
|
||||
* as a reward for contributing to the project.
|
||||
*
|
||||
* The [[link-crowdsale]] format is now obsolete, but it is still
|
||||
* useful to support and the additional code is fairly trivial as
|
||||
* all the primitives required are used through core portions of
|
||||
* the library.
|
||||
*/
|
||||
function decryptCrowdsaleJson(json, _password) {
|
||||
const data = JSON.parse(json);
|
||||
const password = (0, utils_js_1.getPassword)(_password);
|
||||
// Ethereum Address
|
||||
const address = (0, index_js_1.getAddress)((0, utils_js_1.spelunk)(data, "ethaddr:string!"));
|
||||
// Encrypted Seed
|
||||
const encseed = (0, utils_js_1.looseArrayify)((0, utils_js_1.spelunk)(data, "encseed:string!"));
|
||||
(0, index_js_4.assertArgument)(encseed && (encseed.length % 16) === 0, "invalid encseed", "json", json);
|
||||
const key = (0, index_js_4.getBytes)((0, index_js_2.pbkdf2)(password, password, 2000, 32, "sha256")).slice(0, 16);
|
||||
const iv = encseed.slice(0, 16);
|
||||
const encryptedSeed = encseed.slice(16);
|
||||
// Decrypt the seed
|
||||
const aesCbc = new aes_js_1.CBC(key, iv);
|
||||
const seed = (0, aes_js_1.pkcs7Strip)((0, index_js_4.getBytes)(aesCbc.decrypt(encryptedSeed)));
|
||||
// This wallet format is weird... Convert the binary encoded hex to a string.
|
||||
let seedHex = "";
|
||||
for (let i = 0; i < seed.length; i++) {
|
||||
seedHex += String.fromCharCode(seed[i]);
|
||||
}
|
||||
return { address, privateKey: (0, index_js_3.id)(seedHex) };
|
||||
}
|
||||
exports.decryptCrowdsaleJson = decryptCrowdsaleJson;
|
||||
//# sourceMappingURL=json-crowdsale.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-crowdsale.js.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"json-crowdsale.js","sourceRoot":"","sources":["../../src.ts/wallet/json-crowdsale.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mCAAyC;AAEzC,kDAAiD;AACjD,iDAA4C;AAC5C,+CAAsC;AACtC,gDAA6D;AAE7D,yCAAiE;AAYjE;;GAEG;AACH,SAAgB,eAAe,CAAC,IAAY;IACxC,IAAI;QACA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;SAAE;KACrC;IAAC,OAAO,KAAK,EAAE,GAAG;IACnB,OAAO,KAAK,CAAC;AACjB,CAAC;AAND,0CAMC;AAED,iDAAiD;AAEjD;;;;;;;;;GASG;AACH,SAAgB,oBAAoB,CAAC,IAAY,EAAE,SAA8B;IAC7E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,IAAA,sBAAW,EAAC,SAAS,CAAC,CAAC;IAEx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A3BD,oDA2BC"}
|
||||
89
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.d.ts
generated
vendored
Executable file
89
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.d.ts
generated
vendored
Executable file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* The JSON Wallet formats allow a simple way to store the private
|
||||
* keys needed in Ethereum along with related information and allows
|
||||
* for extensible forms of encryption.
|
||||
*
|
||||
* These utilities facilitate decrypting and encrypting the most common
|
||||
* JSON Wallet formats.
|
||||
*
|
||||
* @_subsection: api/wallet:JSON Wallets [json-wallets]
|
||||
*/
|
||||
import type { ProgressCallback } from "../crypto/index.js";
|
||||
import type { BytesLike } from "../utils/index.js";
|
||||
/**
|
||||
* The contents of a JSON Keystore Wallet.
|
||||
*/
|
||||
export type KeystoreAccount = {
|
||||
address: string;
|
||||
privateKey: string;
|
||||
mnemonic?: {
|
||||
path?: string;
|
||||
locale?: string;
|
||||
entropy: string;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* The parameters to use when encrypting a JSON Keystore Wallet.
|
||||
*/
|
||||
export type EncryptOptions = {
|
||||
progressCallback?: ProgressCallback;
|
||||
iv?: BytesLike;
|
||||
entropy?: BytesLike;
|
||||
client?: string;
|
||||
salt?: BytesLike;
|
||||
uuid?: string;
|
||||
scrypt?: {
|
||||
N?: number;
|
||||
r?: number;
|
||||
p?: number;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Returns true if %%json%% is a valid JSON Keystore Wallet.
|
||||
*/
|
||||
export declare function isKeystoreJson(json: string): boolean;
|
||||
/**
|
||||
* Returns the account details for the JSON Keystore Wallet %%json%%
|
||||
* using %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](decryptKeystoreJson)
|
||||
* instead, which allows a [[ProgressCallback]] to keep the user informed
|
||||
* as to the decryption status.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until decryption
|
||||
* is complete, which can take quite some time, depending on the wallet
|
||||
* paramters and platform.
|
||||
*/
|
||||
export declare function decryptKeystoreJsonSync(json: string, _password: string | Uint8Array): KeystoreAccount;
|
||||
/**
|
||||
* Resolves to the decrypted JSON Keystore Wallet %%json%% using the
|
||||
* %%password%%.
|
||||
*
|
||||
* If provided, %%progress%% will be called periodically during the
|
||||
* decrpytion to provide feedback, and if the function returns
|
||||
* ``false`` will halt decryption.
|
||||
*
|
||||
* The %%progressCallback%% will **always** receive ``0`` before
|
||||
* decryption begins and ``1`` when complete.
|
||||
*/
|
||||
export declare function decryptKeystoreJson(json: string, _password: string | Uint8Array, progress?: ProgressCallback): Promise<KeystoreAccount>;
|
||||
/**
|
||||
* Return the JSON Keystore Wallet for %%account%% encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* The %%options%% can be used to tune the password-based key
|
||||
* derivation function parameters, explicitly set the random values
|
||||
* used. Any provided [[ProgressCallback]] is ignord.
|
||||
*/
|
||||
export declare function encryptKeystoreJsonSync(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): string;
|
||||
/**
|
||||
* Resolved to the JSON Keystore Wallet for %%account%% encrypted
|
||||
* with %%password%%.
|
||||
*
|
||||
* The %%options%% can be used to tune the password-based key
|
||||
* derivation function parameters, explicitly set the random values
|
||||
* used and provide a [[ProgressCallback]] to receive periodic updates
|
||||
* on the completion status..
|
||||
*/
|
||||
export declare function encryptKeystoreJson(account: KeystoreAccount, password: string | Uint8Array, options?: EncryptOptions): Promise<string>;
|
||||
//# sourceMappingURL=json-keystore.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"json-keystore.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/json-keystore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAaH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAA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,cAAc,GAAG,MAAM,CAOjI;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAO5I"}
|
||||
295
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.js
generated
vendored
Executable file
295
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.js
generated
vendored
Executable file
@@ -0,0 +1,295 @@
|
||||
"use strict";
|
||||
/**
|
||||
* The JSON Wallet formats allow a simple way to store the private
|
||||
* keys needed in Ethereum along with related information and allows
|
||||
* for extensible forms of encryption.
|
||||
*
|
||||
* These utilities facilitate decrypting and encrypting the most common
|
||||
* JSON Wallet formats.
|
||||
*
|
||||
* @_subsection: api/wallet:JSON Wallets [json-wallets]
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.encryptKeystoreJson = exports.encryptKeystoreJsonSync = exports.decryptKeystoreJson = exports.decryptKeystoreJsonSync = exports.isKeystoreJson = void 0;
|
||||
const aes_js_1 = require("aes-js");
|
||||
const index_js_1 = require("../address/index.js");
|
||||
const index_js_2 = require("../crypto/index.js");
|
||||
const index_js_3 = require("../transaction/index.js");
|
||||
const index_js_4 = require("../utils/index.js");
|
||||
const utils_js_1 = require("./utils.js");
|
||||
const _version_js_1 = require("../_version.js");
|
||||
const defaultPath = "m/44'/60'/0'/0/0";
|
||||
/**
|
||||
* Returns true if %%json%% is a valid JSON Keystore Wallet.
|
||||
*/
|
||||
function isKeystoreJson(json) {
|
||||
try {
|
||||
const data = JSON.parse(json);
|
||||
const version = ((data.version != null) ? parseInt(data.version) : 0);
|
||||
if (version === 3) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
exports.isKeystoreJson = isKeystoreJson;
|
||||
function decrypt(data, key, ciphertext) {
|
||||
const cipher = (0, utils_js_1.spelunk)(data, "crypto.cipher:string");
|
||||
if (cipher === "aes-128-ctr") {
|
||||
const iv = (0, utils_js_1.spelunk)(data, "crypto.cipherparams.iv:data!");
|
||||
const aesCtr = new aes_js_1.CTR(key, iv);
|
||||
return (0, index_js_4.hexlify)(aesCtr.decrypt(ciphertext));
|
||||
}
|
||||
(0, index_js_4.assert)(false, "unsupported cipher", "UNSUPPORTED_OPERATION", {
|
||||
operation: "decrypt"
|
||||
});
|
||||
}
|
||||
function getAccount(data, _key) {
|
||||
const key = (0, index_js_4.getBytes)(_key);
|
||||
const ciphertext = (0, utils_js_1.spelunk)(data, "crypto.ciphertext:data!");
|
||||
const computedMAC = (0, index_js_4.hexlify)((0, index_js_2.keccak256)((0, index_js_4.concat)([key.slice(16, 32), ciphertext]))).substring(2);
|
||||
(0, index_js_4.assertArgument)(computedMAC === (0, utils_js_1.spelunk)(data, "crypto.mac:string!").toLowerCase(), "incorrect password", "password", "[ REDACTED ]");
|
||||
const privateKey = decrypt(data, key.slice(0, 16), ciphertext);
|
||||
const address = (0, index_js_3.computeAddress)(privateKey);
|
||||
if (data.address) {
|
||||
let check = data.address.toLowerCase();
|
||||
if (!check.startsWith("0x")) {
|
||||
check = "0x" + check;
|
||||
}
|
||||
(0, index_js_4.assertArgument)((0, index_js_1.getAddress)(check) === address, "keystore address/privateKey mismatch", "address", data.address);
|
||||
}
|
||||
const account = { address, privateKey };
|
||||
// Version 0.1 x-ethers metadata must contain an encrypted mnemonic phrase
|
||||
const version = (0, utils_js_1.spelunk)(data, "x-ethers.version:string");
|
||||
if (version === "0.1") {
|
||||
const mnemonicKey = key.slice(32, 64);
|
||||
const mnemonicCiphertext = (0, utils_js_1.spelunk)(data, "x-ethers.mnemonicCiphertext:data!");
|
||||
const mnemonicIv = (0, utils_js_1.spelunk)(data, "x-ethers.mnemonicCounter:data!");
|
||||
const mnemonicAesCtr = new aes_js_1.CTR(mnemonicKey, mnemonicIv);
|
||||
account.mnemonic = {
|
||||
path: ((0, utils_js_1.spelunk)(data, "x-ethers.path:string") || defaultPath),
|
||||
locale: ((0, utils_js_1.spelunk)(data, "x-ethers.locale:string") || "en"),
|
||||
entropy: (0, index_js_4.hexlify)((0, index_js_4.getBytes)(mnemonicAesCtr.decrypt(mnemonicCiphertext)))
|
||||
};
|
||||
}
|
||||
return account;
|
||||
}
|
||||
function getDecryptKdfParams(data) {
|
||||
const kdf = (0, utils_js_1.spelunk)(data, "crypto.kdf:string");
|
||||
if (kdf && typeof (kdf) === "string") {
|
||||
if (kdf.toLowerCase() === "scrypt") {
|
||||
const salt = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.salt:data!");
|
||||
const N = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.n:int!");
|
||||
const r = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.r:int!");
|
||||
const p = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.p:int!");
|
||||
// Make sure N is a power of 2
|
||||
(0, index_js_4.assertArgument)(N > 0 && (N & (N - 1)) === 0, "invalid kdf.N", "kdf.N", N);
|
||||
(0, index_js_4.assertArgument)(r > 0 && p > 0, "invalid kdf", "kdf", kdf);
|
||||
const dkLen = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.dklen:int!");
|
||||
(0, index_js_4.assertArgument)(dkLen === 32, "invalid kdf.dklen", "kdf.dflen", dkLen);
|
||||
return { name: "scrypt", salt, N, r, p, dkLen: 64 };
|
||||
}
|
||||
else if (kdf.toLowerCase() === "pbkdf2") {
|
||||
const salt = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.salt:data!");
|
||||
const prf = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.prf:string!");
|
||||
const algorithm = prf.split("-").pop();
|
||||
(0, index_js_4.assertArgument)(algorithm === "sha256" || algorithm === "sha512", "invalid kdf.pdf", "kdf.pdf", prf);
|
||||
const count = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.c:int!");
|
||||
const dkLen = (0, utils_js_1.spelunk)(data, "crypto.kdfparams.dklen:int!");
|
||||
(0, index_js_4.assertArgument)(dkLen === 32, "invalid kdf.dklen", "kdf.dklen", dkLen);
|
||||
return { name: "pbkdf2", salt, count, dkLen, algorithm };
|
||||
}
|
||||
}
|
||||
(0, index_js_4.assertArgument)(false, "unsupported key-derivation function", "kdf", kdf);
|
||||
}
|
||||
/**
|
||||
* Returns the account details for the JSON Keystore Wallet %%json%%
|
||||
* using %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](decryptKeystoreJson)
|
||||
* instead, which allows a [[ProgressCallback]] to keep the user informed
|
||||
* as to the decryption status.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until decryption
|
||||
* is complete, which can take quite some time, depending on the wallet
|
||||
* paramters and platform.
|
||||
*/
|
||||
function decryptKeystoreJsonSync(json, _password) {
|
||||
const data = JSON.parse(json);
|
||||
const password = (0, utils_js_1.getPassword)(_password);
|
||||
const params = getDecryptKdfParams(data);
|
||||
if (params.name === "pbkdf2") {
|
||||
const { salt, count, dkLen, algorithm } = params;
|
||||
const key = (0, index_js_2.pbkdf2)(password, salt, count, dkLen, algorithm);
|
||||
return getAccount(data, key);
|
||||
}
|
||||
(0, index_js_4.assert)(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params });
|
||||
const { salt, N, r, p, dkLen } = params;
|
||||
const key = (0, index_js_2.scryptSync)(password, salt, N, r, p, dkLen);
|
||||
return getAccount(data, key);
|
||||
}
|
||||
exports.decryptKeystoreJsonSync = decryptKeystoreJsonSync;
|
||||
function stall(duration) {
|
||||
return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); });
|
||||
}
|
||||
/**
|
||||
* Resolves to the decrypted JSON Keystore Wallet %%json%% using the
|
||||
* %%password%%.
|
||||
*
|
||||
* If provided, %%progress%% will be called periodically during the
|
||||
* decrpytion to provide feedback, and if the function returns
|
||||
* ``false`` will halt decryption.
|
||||
*
|
||||
* The %%progressCallback%% will **always** receive ``0`` before
|
||||
* decryption begins and ``1`` when complete.
|
||||
*/
|
||||
async function decryptKeystoreJson(json, _password, progress) {
|
||||
const data = JSON.parse(json);
|
||||
const password = (0, utils_js_1.getPassword)(_password);
|
||||
const params = getDecryptKdfParams(data);
|
||||
if (params.name === "pbkdf2") {
|
||||
if (progress) {
|
||||
progress(0);
|
||||
await stall(0);
|
||||
}
|
||||
const { salt, count, dkLen, algorithm } = params;
|
||||
const key = (0, index_js_2.pbkdf2)(password, salt, count, dkLen, algorithm);
|
||||
if (progress) {
|
||||
progress(1);
|
||||
await stall(0);
|
||||
}
|
||||
return getAccount(data, key);
|
||||
}
|
||||
(0, index_js_4.assert)(params.name === "scrypt", "cannot be reached", "UNKNOWN_ERROR", { params });
|
||||
const { salt, N, r, p, dkLen } = params;
|
||||
const key = await (0, index_js_2.scrypt)(password, salt, N, r, p, dkLen, progress);
|
||||
return getAccount(data, key);
|
||||
}
|
||||
exports.decryptKeystoreJson = decryptKeystoreJson;
|
||||
function getEncryptKdfParams(options) {
|
||||
// Check/generate the salt
|
||||
const salt = (options.salt != null) ? (0, index_js_4.getBytes)(options.salt, "options.salt") : (0, index_js_2.randomBytes)(32);
|
||||
// Override the scrypt password-based key derivation function parameters
|
||||
let N = (1 << 17), r = 8, p = 1;
|
||||
if (options.scrypt) {
|
||||
if (options.scrypt.N) {
|
||||
N = options.scrypt.N;
|
||||
}
|
||||
if (options.scrypt.r) {
|
||||
r = options.scrypt.r;
|
||||
}
|
||||
if (options.scrypt.p) {
|
||||
p = options.scrypt.p;
|
||||
}
|
||||
}
|
||||
(0, index_js_4.assertArgument)(typeof (N) === "number" && N > 0 && Number.isSafeInteger(N) && (BigInt(N) & BigInt(N - 1)) === BigInt(0), "invalid scrypt N parameter", "options.N", N);
|
||||
(0, index_js_4.assertArgument)(typeof (r) === "number" && r > 0 && Number.isSafeInteger(r), "invalid scrypt r parameter", "options.r", r);
|
||||
(0, index_js_4.assertArgument)(typeof (p) === "number" && p > 0 && Number.isSafeInteger(p), "invalid scrypt p parameter", "options.p", p);
|
||||
return { name: "scrypt", dkLen: 32, salt, N, r, p };
|
||||
}
|
||||
function _encryptKeystore(key, kdf, account, options) {
|
||||
const privateKey = (0, index_js_4.getBytes)(account.privateKey, "privateKey");
|
||||
// Override initialization vector
|
||||
const iv = (options.iv != null) ? (0, index_js_4.getBytes)(options.iv, "options.iv") : (0, index_js_2.randomBytes)(16);
|
||||
(0, index_js_4.assertArgument)(iv.length === 16, "invalid options.iv length", "options.iv", options.iv);
|
||||
// Override the uuid
|
||||
const uuidRandom = (options.uuid != null) ? (0, index_js_4.getBytes)(options.uuid, "options.uuid") : (0, index_js_2.randomBytes)(16);
|
||||
(0, index_js_4.assertArgument)(uuidRandom.length === 16, "invalid options.uuid length", "options.uuid", options.iv);
|
||||
// This will be used to encrypt the wallet (as per Web3 secret storage)
|
||||
// - 32 bytes As normal for the Web3 secret storage (derivedKey, macPrefix)
|
||||
// - 32 bytes AES key to encrypt mnemonic with (required here to be Ethers Wallet)
|
||||
const derivedKey = key.slice(0, 16);
|
||||
const macPrefix = key.slice(16, 32);
|
||||
// Encrypt the private key
|
||||
const aesCtr = new aes_js_1.CTR(derivedKey, iv);
|
||||
const ciphertext = (0, index_js_4.getBytes)(aesCtr.encrypt(privateKey));
|
||||
// Compute the message authentication code, used to check the password
|
||||
const mac = (0, index_js_2.keccak256)((0, index_js_4.concat)([macPrefix, ciphertext]));
|
||||
// See: https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
|
||||
const data = {
|
||||
address: account.address.substring(2).toLowerCase(),
|
||||
id: (0, index_js_4.uuidV4)(uuidRandom),
|
||||
version: 3,
|
||||
Crypto: {
|
||||
cipher: "aes-128-ctr",
|
||||
cipherparams: {
|
||||
iv: (0, index_js_4.hexlify)(iv).substring(2),
|
||||
},
|
||||
ciphertext: (0, index_js_4.hexlify)(ciphertext).substring(2),
|
||||
kdf: "scrypt",
|
||||
kdfparams: {
|
||||
salt: (0, index_js_4.hexlify)(kdf.salt).substring(2),
|
||||
n: kdf.N,
|
||||
dklen: 32,
|
||||
p: kdf.p,
|
||||
r: kdf.r
|
||||
},
|
||||
mac: mac.substring(2)
|
||||
}
|
||||
};
|
||||
// If we have a mnemonic, encrypt it into the JSON wallet
|
||||
if (account.mnemonic) {
|
||||
const client = (options.client != null) ? options.client : `ethers/${_version_js_1.version}`;
|
||||
const path = account.mnemonic.path || defaultPath;
|
||||
const locale = account.mnemonic.locale || "en";
|
||||
const mnemonicKey = key.slice(32, 64);
|
||||
const entropy = (0, index_js_4.getBytes)(account.mnemonic.entropy, "account.mnemonic.entropy");
|
||||
const mnemonicIv = (0, index_js_2.randomBytes)(16);
|
||||
const mnemonicAesCtr = new aes_js_1.CTR(mnemonicKey, mnemonicIv);
|
||||
const mnemonicCiphertext = (0, index_js_4.getBytes)(mnemonicAesCtr.encrypt(entropy));
|
||||
const now = new Date();
|
||||
const timestamp = (now.getUTCFullYear() + "-" +
|
||||
(0, utils_js_1.zpad)(now.getUTCMonth() + 1, 2) + "-" +
|
||||
(0, utils_js_1.zpad)(now.getUTCDate(), 2) + "T" +
|
||||
(0, utils_js_1.zpad)(now.getUTCHours(), 2) + "-" +
|
||||
(0, utils_js_1.zpad)(now.getUTCMinutes(), 2) + "-" +
|
||||
(0, utils_js_1.zpad)(now.getUTCSeconds(), 2) + ".0Z");
|
||||
const gethFilename = ("UTC--" + timestamp + "--" + data.address);
|
||||
data["x-ethers"] = {
|
||||
client, gethFilename, path, locale,
|
||||
mnemonicCounter: (0, index_js_4.hexlify)(mnemonicIv).substring(2),
|
||||
mnemonicCiphertext: (0, index_js_4.hexlify)(mnemonicCiphertext).substring(2),
|
||||
version: "0.1"
|
||||
};
|
||||
}
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
/**
|
||||
* Return the JSON Keystore Wallet for %%account%% encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* The %%options%% can be used to tune the password-based key
|
||||
* derivation function parameters, explicitly set the random values
|
||||
* used. Any provided [[ProgressCallback]] is ignord.
|
||||
*/
|
||||
function encryptKeystoreJsonSync(account, password, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
const passwordBytes = (0, utils_js_1.getPassword)(password);
|
||||
const kdf = getEncryptKdfParams(options);
|
||||
const key = (0, index_js_2.scryptSync)(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64);
|
||||
return _encryptKeystore((0, index_js_4.getBytes)(key), kdf, account, options);
|
||||
}
|
||||
exports.encryptKeystoreJsonSync = encryptKeystoreJsonSync;
|
||||
/**
|
||||
* Resolved to the JSON Keystore Wallet for %%account%% encrypted
|
||||
* with %%password%%.
|
||||
*
|
||||
* The %%options%% can be used to tune the password-based key
|
||||
* derivation function parameters, explicitly set the random values
|
||||
* used and provide a [[ProgressCallback]] to receive periodic updates
|
||||
* on the completion status..
|
||||
*/
|
||||
async function encryptKeystoreJson(account, password, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
const passwordBytes = (0, utils_js_1.getPassword)(password);
|
||||
const kdf = getEncryptKdfParams(options);
|
||||
const key = await (0, index_js_2.scrypt)(passwordBytes, kdf.salt, kdf.N, kdf.r, kdf.p, 64, options.progressCallback);
|
||||
return _encryptKeystore((0, index_js_4.getBytes)(key), kdf, account, options);
|
||||
}
|
||||
exports.encryptKeystoreJson = encryptKeystoreJson;
|
||||
//# sourceMappingURL=json-keystore.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/json-keystore.js.map
generated
vendored
Executable file
File diff suppressed because one or more lines are too long
65
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.d.ts
generated
vendored
Executable file
65
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.d.ts
generated
vendored
Executable file
@@ -0,0 +1,65 @@
|
||||
import type { BytesLike } from "../utils/index.js";
|
||||
import type { Wordlist } from "../wordlists/index.js";
|
||||
/**
|
||||
* A **Mnemonic** wraps all properties required to compute [[link-bip-39]]
|
||||
* seeds and convert between phrases and entropy.
|
||||
*/
|
||||
export declare class Mnemonic {
|
||||
/**
|
||||
* The mnemonic phrase of 12, 15, 18, 21 or 24 words.
|
||||
*
|
||||
* Use the [[wordlist]] ``split`` method to get the individual words.
|
||||
*/
|
||||
readonly phrase: string;
|
||||
/**
|
||||
* The password used for this mnemonic. If no password is used this
|
||||
* is the empty string (i.e. ``""``) as per the specification.
|
||||
*/
|
||||
readonly password: string;
|
||||
/**
|
||||
* The wordlist for this mnemonic.
|
||||
*/
|
||||
readonly wordlist: Wordlist;
|
||||
/**
|
||||
* The underlying entropy which the mnemonic encodes.
|
||||
*/
|
||||
readonly entropy: string;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard: any, entropy: string, phrase: string, password?: null | string, wordlist?: null | Wordlist);
|
||||
/**
|
||||
* Returns the seed for the mnemonic.
|
||||
*/
|
||||
computeSeed(): string;
|
||||
/**
|
||||
* Creates a new Mnemonic for the %%phrase%%.
|
||||
*
|
||||
* The default %%password%% is the empty string and the default
|
||||
* wordlist is the [English wordlists](LangEn).
|
||||
*/
|
||||
static fromPhrase(phrase: string, password?: null | string, wordlist?: null | Wordlist): Mnemonic;
|
||||
/**
|
||||
* Create a new **Mnemonic** from the %%entropy%%.
|
||||
*
|
||||
* The default %%password%% is the empty string and the default
|
||||
* wordlist is the [English wordlists](LangEn).
|
||||
*/
|
||||
static fromEntropy(_entropy: BytesLike, password?: null | string, wordlist?: null | Wordlist): Mnemonic;
|
||||
/**
|
||||
* Returns the phrase for %%mnemonic%%.
|
||||
*/
|
||||
static entropyToPhrase(_entropy: BytesLike, wordlist?: null | Wordlist): string;
|
||||
/**
|
||||
* Returns the entropy for %%phrase%%.
|
||||
*/
|
||||
static phraseToEntropy(phrase: string, wordlist?: null | Wordlist): string;
|
||||
/**
|
||||
* Returns true if %%phrase%% is a valid [[link-bip-39]] phrase.
|
||||
*
|
||||
* This checks all the provided words belong to the %%wordlist%%,
|
||||
* that the length is valid and the checksum is correct.
|
||||
*/
|
||||
static isValidMnemonic(phrase: string, wordlist?: null | Wordlist): boolean;
|
||||
}
|
||||
//# sourceMappingURL=mnemonic.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mnemonic.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/mnemonic.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAgGtD;;;GAGG;AACH,qBAAa,QAAQ;IACjB;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAG,MAAM,CAAC;IAEzB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAG,QAAQ,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAG,MAAM,CAAC;IAE1B;;OAEG;gBACS,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAO7G;;OAEG;IACH,WAAW,IAAI,MAAM;IAKrB;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ;IAOjG;;;;;OAKG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,QAAQ;IAMvG;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAK/E;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAI1E;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,OAAO;CAO9E"}
|
||||
169
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.js
generated
vendored
Executable file
169
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.js
generated
vendored
Executable file
@@ -0,0 +1,169 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Mnemonic = void 0;
|
||||
const index_js_1 = require("../crypto/index.js");
|
||||
const index_js_2 = require("../utils/index.js");
|
||||
const lang_en_js_1 = require("../wordlists/lang-en.js");
|
||||
// Returns a byte with the MSB bits set
|
||||
function getUpperMask(bits) {
|
||||
return ((1 << bits) - 1) << (8 - bits) & 0xff;
|
||||
}
|
||||
// Returns a byte with the LSB bits set
|
||||
function getLowerMask(bits) {
|
||||
return ((1 << bits) - 1) & 0xff;
|
||||
}
|
||||
function mnemonicToEntropy(mnemonic, wordlist) {
|
||||
(0, index_js_2.assertNormalize)("NFKD");
|
||||
if (wordlist == null) {
|
||||
wordlist = lang_en_js_1.LangEn.wordlist();
|
||||
}
|
||||
const words = wordlist.split(mnemonic);
|
||||
(0, index_js_2.assertArgument)((words.length % 3) === 0 && words.length >= 12 && words.length <= 24, "invalid mnemonic length", "mnemonic", "[ REDACTED ]");
|
||||
const entropy = new Uint8Array(Math.ceil(11 * words.length / 8));
|
||||
let offset = 0;
|
||||
for (let i = 0; i < words.length; i++) {
|
||||
let index = wordlist.getWordIndex(words[i].normalize("NFKD"));
|
||||
(0, index_js_2.assertArgument)(index >= 0, `invalid mnemonic word at index ${i}`, "mnemonic", "[ REDACTED ]");
|
||||
for (let bit = 0; bit < 11; bit++) {
|
||||
if (index & (1 << (10 - bit))) {
|
||||
entropy[offset >> 3] |= (1 << (7 - (offset % 8)));
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
const entropyBits = 32 * words.length / 3;
|
||||
const checksumBits = words.length / 3;
|
||||
const checksumMask = getUpperMask(checksumBits);
|
||||
const checksum = (0, index_js_2.getBytes)((0, index_js_1.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
||||
(0, index_js_2.assertArgument)(checksum === (entropy[entropy.length - 1] & checksumMask), "invalid mnemonic checksum", "mnemonic", "[ REDACTED ]");
|
||||
return (0, index_js_2.hexlify)(entropy.slice(0, entropyBits / 8));
|
||||
}
|
||||
function entropyToMnemonic(entropy, wordlist) {
|
||||
(0, index_js_2.assertArgument)((entropy.length % 4) === 0 && entropy.length >= 16 && entropy.length <= 32, "invalid entropy size", "entropy", "[ REDACTED ]");
|
||||
if (wordlist == null) {
|
||||
wordlist = lang_en_js_1.LangEn.wordlist();
|
||||
}
|
||||
const indices = [0];
|
||||
let remainingBits = 11;
|
||||
for (let i = 0; i < entropy.length; i++) {
|
||||
// Consume the whole byte (with still more to go)
|
||||
if (remainingBits > 8) {
|
||||
indices[indices.length - 1] <<= 8;
|
||||
indices[indices.length - 1] |= entropy[i];
|
||||
remainingBits -= 8;
|
||||
// This byte will complete an 11-bit index
|
||||
}
|
||||
else {
|
||||
indices[indices.length - 1] <<= remainingBits;
|
||||
indices[indices.length - 1] |= entropy[i] >> (8 - remainingBits);
|
||||
// Start the next word
|
||||
indices.push(entropy[i] & getLowerMask(8 - remainingBits));
|
||||
remainingBits += 3;
|
||||
}
|
||||
}
|
||||
// Compute the checksum bits
|
||||
const checksumBits = entropy.length / 4;
|
||||
const checksum = parseInt((0, index_js_1.sha256)(entropy).substring(2, 4), 16) & getUpperMask(checksumBits);
|
||||
// Shift the checksum into the word indices
|
||||
indices[indices.length - 1] <<= checksumBits;
|
||||
indices[indices.length - 1] |= (checksum >> (8 - checksumBits));
|
||||
return wordlist.join(indices.map((index) => wordlist.getWord(index)));
|
||||
}
|
||||
const _guard = {};
|
||||
/**
|
||||
* A **Mnemonic** wraps all properties required to compute [[link-bip-39]]
|
||||
* seeds and convert between phrases and entropy.
|
||||
*/
|
||||
class Mnemonic {
|
||||
/**
|
||||
* The mnemonic phrase of 12, 15, 18, 21 or 24 words.
|
||||
*
|
||||
* Use the [[wordlist]] ``split`` method to get the individual words.
|
||||
*/
|
||||
phrase;
|
||||
/**
|
||||
* The password used for this mnemonic. If no password is used this
|
||||
* is the empty string (i.e. ``""``) as per the specification.
|
||||
*/
|
||||
password;
|
||||
/**
|
||||
* The wordlist for this mnemonic.
|
||||
*/
|
||||
wordlist;
|
||||
/**
|
||||
* The underlying entropy which the mnemonic encodes.
|
||||
*/
|
||||
entropy;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
constructor(guard, entropy, phrase, password, wordlist) {
|
||||
if (password == null) {
|
||||
password = "";
|
||||
}
|
||||
if (wordlist == null) {
|
||||
wordlist = lang_en_js_1.LangEn.wordlist();
|
||||
}
|
||||
(0, index_js_2.assertPrivate)(guard, _guard, "Mnemonic");
|
||||
(0, index_js_2.defineProperties)(this, { phrase, password, wordlist, entropy });
|
||||
}
|
||||
/**
|
||||
* Returns the seed for the mnemonic.
|
||||
*/
|
||||
computeSeed() {
|
||||
const salt = (0, index_js_2.toUtf8Bytes)("mnemonic" + this.password, "NFKD");
|
||||
return (0, index_js_1.pbkdf2)((0, index_js_2.toUtf8Bytes)(this.phrase, "NFKD"), salt, 2048, 64, "sha512");
|
||||
}
|
||||
/**
|
||||
* Creates a new Mnemonic for the %%phrase%%.
|
||||
*
|
||||
* The default %%password%% is the empty string and the default
|
||||
* wordlist is the [English wordlists](LangEn).
|
||||
*/
|
||||
static fromPhrase(phrase, password, wordlist) {
|
||||
// Normalize the case and space; throws if invalid
|
||||
const entropy = mnemonicToEntropy(phrase, wordlist);
|
||||
phrase = entropyToMnemonic((0, index_js_2.getBytes)(entropy), wordlist);
|
||||
return new Mnemonic(_guard, entropy, phrase, password, wordlist);
|
||||
}
|
||||
/**
|
||||
* Create a new **Mnemonic** from the %%entropy%%.
|
||||
*
|
||||
* The default %%password%% is the empty string and the default
|
||||
* wordlist is the [English wordlists](LangEn).
|
||||
*/
|
||||
static fromEntropy(_entropy, password, wordlist) {
|
||||
const entropy = (0, index_js_2.getBytes)(_entropy, "entropy");
|
||||
const phrase = entropyToMnemonic(entropy, wordlist);
|
||||
return new Mnemonic(_guard, (0, index_js_2.hexlify)(entropy), phrase, password, wordlist);
|
||||
}
|
||||
/**
|
||||
* Returns the phrase for %%mnemonic%%.
|
||||
*/
|
||||
static entropyToPhrase(_entropy, wordlist) {
|
||||
const entropy = (0, index_js_2.getBytes)(_entropy, "entropy");
|
||||
return entropyToMnemonic(entropy, wordlist);
|
||||
}
|
||||
/**
|
||||
* Returns the entropy for %%phrase%%.
|
||||
*/
|
||||
static phraseToEntropy(phrase, wordlist) {
|
||||
return mnemonicToEntropy(phrase, wordlist);
|
||||
}
|
||||
/**
|
||||
* Returns true if %%phrase%% is a valid [[link-bip-39]] phrase.
|
||||
*
|
||||
* This checks all the provided words belong to the %%wordlist%%,
|
||||
* that the length is valid and the checksum is correct.
|
||||
*/
|
||||
static isValidMnemonic(phrase, wordlist) {
|
||||
try {
|
||||
mnemonicToEntropy(phrase, wordlist);
|
||||
return true;
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.Mnemonic = Mnemonic;
|
||||
//# sourceMappingURL=mnemonic.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/mnemonic.js.map
generated
vendored
Executable file
File diff suppressed because one or more lines are too long
8
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.d.ts
generated
vendored
Executable file
8
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.d.ts
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @_ignore
|
||||
*/
|
||||
export declare function looseArrayify(hexString: string): Uint8Array;
|
||||
export declare function zpad(value: String | number, length: number): String;
|
||||
export declare function getPassword(password: string | Uint8Array): Uint8Array;
|
||||
export declare function spelunk<T>(object: any, _path: string): T;
|
||||
//# sourceMappingURL=utils.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAK3D;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAInE;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAKrE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CA8DxD"}
|
||||
149
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.js
generated
vendored
Executable file
149
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.js
generated
vendored
Executable file
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
/**
|
||||
* @_ignore
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.spelunk = exports.getPassword = exports.zpad = exports.looseArrayify = void 0;
|
||||
const index_js_1 = require("../utils/index.js");
|
||||
function looseArrayify(hexString) {
|
||||
if (typeof (hexString) === "string" && !hexString.startsWith("0x")) {
|
||||
hexString = "0x" + hexString;
|
||||
}
|
||||
return (0, index_js_1.getBytesCopy)(hexString);
|
||||
}
|
||||
exports.looseArrayify = looseArrayify;
|
||||
function zpad(value, length) {
|
||||
value = String(value);
|
||||
while (value.length < length) {
|
||||
value = '0' + value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
exports.zpad = zpad;
|
||||
function getPassword(password) {
|
||||
if (typeof (password) === 'string') {
|
||||
return (0, index_js_1.toUtf8Bytes)(password, "NFKC");
|
||||
}
|
||||
return (0, index_js_1.getBytesCopy)(password);
|
||||
}
|
||||
exports.getPassword = getPassword;
|
||||
function spelunk(object, _path) {
|
||||
const match = _path.match(/^([a-z0-9$_.-]*)(:([a-z]+))?(!)?$/i);
|
||||
(0, index_js_1.assertArgument)(match != null, "invalid path", "path", _path);
|
||||
const path = match[1];
|
||||
const type = match[3];
|
||||
const reqd = (match[4] === "!");
|
||||
let cur = object;
|
||||
for (const comp of path.toLowerCase().split('.')) {
|
||||
// Search for a child object with a case-insensitive matching key
|
||||
if (Array.isArray(cur)) {
|
||||
if (!comp.match(/^[0-9]+$/)) {
|
||||
break;
|
||||
}
|
||||
cur = cur[parseInt(comp)];
|
||||
}
|
||||
else if (typeof (cur) === "object") {
|
||||
let found = null;
|
||||
for (const key in cur) {
|
||||
if (key.toLowerCase() === comp) {
|
||||
found = cur[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
cur = found;
|
||||
}
|
||||
else {
|
||||
cur = null;
|
||||
}
|
||||
if (cur == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
(0, index_js_1.assertArgument)(!reqd || cur != null, "missing required value", "path", path);
|
||||
if (type && cur != null) {
|
||||
if (type === "int") {
|
||||
if (typeof (cur) === "string" && cur.match(/^-?[0-9]+$/)) {
|
||||
return parseInt(cur);
|
||||
}
|
||||
else if (Number.isSafeInteger(cur)) {
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
if (type === "number") {
|
||||
if (typeof (cur) === "string" && cur.match(/^-?[0-9.]*$/)) {
|
||||
return parseFloat(cur);
|
||||
}
|
||||
}
|
||||
if (type === "data") {
|
||||
if (typeof (cur) === "string") {
|
||||
return looseArrayify(cur);
|
||||
}
|
||||
}
|
||||
if (type === "array" && Array.isArray(cur)) {
|
||||
return cur;
|
||||
}
|
||||
if (type === typeof (cur)) {
|
||||
return cur;
|
||||
}
|
||||
(0, index_js_1.assertArgument)(false, `wrong type found for ${type} `, "path", path);
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
exports.spelunk = spelunk;
|
||||
/*
|
||||
export function follow(object: any, path: string): null | string {
|
||||
let currentChild = object;
|
||||
|
||||
for (const comp of path.toLowerCase().split('/')) {
|
||||
|
||||
// Search for a child object with a case-insensitive matching key
|
||||
let matchingChild = null;
|
||||
for (const key in currentChild) {
|
||||
if (key.toLowerCase() === comp) {
|
||||
matchingChild = currentChild[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchingChild === null) { return null; }
|
||||
|
||||
currentChild = matchingChild;
|
||||
}
|
||||
|
||||
return currentChild;
|
||||
}
|
||||
|
||||
// "path/to/something:type!"
|
||||
export function followRequired(data: any, path: string): string {
|
||||
const value = follow(data, path);
|
||||
if (value != null) { return value; }
|
||||
return logger.throwArgumentError("invalid value", `data:${ path }`,
|
||||
JSON.stringify(data));
|
||||
}
|
||||
*/
|
||||
// See: https://www.ietf.org/rfc/rfc4122.txt (Section 4.4)
|
||||
/*
|
||||
export function uuidV4(randomBytes: BytesLike): string {
|
||||
const bytes = getBytes(randomBytes, "randomBytes");
|
||||
|
||||
// Section: 4.1.3:
|
||||
// - time_hi_and_version[12:16] = 0b0100
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
||||
|
||||
// Section 4.4
|
||||
// - clock_seq_hi_and_reserved[6] = 0b0
|
||||
// - clock_seq_hi_and_reserved[7] = 0b1
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||
|
||||
const value = hexlify(bytes);
|
||||
|
||||
return [
|
||||
value.substring(2, 10),
|
||||
value.substring(10, 14),
|
||||
value.substring(14, 18),
|
||||
value.substring(18, 22),
|
||||
value.substring(22, 34),
|
||||
].join("-");
|
||||
}
|
||||
*/
|
||||
//# sourceMappingURL=utils.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/utils.js.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src.ts/wallet/utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gDAE2B;AAE3B,SAAgB,aAAa,CAAC,SAAiB;IAC3C,IAAI,OAAM,CAAC,SAAS,CAAC,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC/D,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;KAChC;IACD,OAAO,IAAA,uBAAY,EAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AALD,sCAKC;AAED,SAAgB,IAAI,CAAC,KAAsB,EAAE,MAAc;IACvD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE;QAAE,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;KAAE;IACtD,OAAO,KAAK,CAAC;AACjB,CAAC;AAJD,oBAIC;AAED,SAAgB,WAAW,CAAC,QAA6B;IACrD,IAAI,OAAM,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE;QAC/B,OAAO,IAAA,sBAAW,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;KACxC;IACD,OAAO,IAAA,uBAAY,EAAC,QAAQ,CAAC,CAAC;AAClC,CAA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ib.commonjs/wallet/wallet.d.ts
generated
vendored
Executable file
@@ -0,0 +1,71 @@
|
||||
import { SigningKey } from "../crypto/index.js";
|
||||
import { BaseWallet } from "./base-wallet.js";
|
||||
import { HDNodeWallet } from "./hdwallet.js";
|
||||
import type { ProgressCallback } from "../crypto/index.js";
|
||||
import type { Provider } from "../providers/index.js";
|
||||
/**
|
||||
* A **Wallet** manages a single private key which is used to sign
|
||||
* transactions, messages and other common payloads.
|
||||
*
|
||||
* This class is generally the main entry point for developers
|
||||
* that wish to use a private key directly, as it can create
|
||||
* instances from a large variety of common sources, including
|
||||
* raw private key, [[link-bip-39]] mnemonics and encrypte JSON
|
||||
* wallets.
|
||||
*/
|
||||
export declare class Wallet extends BaseWallet {
|
||||
#private;
|
||||
/**
|
||||
* Create a new wallet for the private %%key%%, optionally connected
|
||||
* to %%provider%%.
|
||||
*/
|
||||
constructor(key: string | SigningKey, provider?: null | Provider);
|
||||
connect(provider: null | Provider): Wallet;
|
||||
/**
|
||||
* Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* If %%progressCallback%% is specified, it will receive periodic
|
||||
* updates as the encryption process progreses.
|
||||
*/
|
||||
encrypt(password: Uint8Array | string, progressCallback?: ProgressCallback): Promise<string>;
|
||||
/**
|
||||
* Returns a [JSON Keystore Wallet](json-wallets) encryped with
|
||||
* %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](encrypt) instead,
|
||||
* which allows a [[ProgressCallback]] to keep the user informed.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until
|
||||
* it is complete, which may be a non-trivial duration.
|
||||
*/
|
||||
encryptSync(password: Uint8Array | string): string;
|
||||
/**
|
||||
* Creates (asynchronously) a **Wallet** by decrypting the %%json%%
|
||||
* with %%password%%.
|
||||
*
|
||||
* If %%progress%% is provided, it is called periodically during
|
||||
* decryption so that any UI can be updated.
|
||||
*/
|
||||
static fromEncryptedJson(json: string, password: Uint8Array | string, progress?: ProgressCallback): Promise<HDNodeWallet | Wallet>;
|
||||
/**
|
||||
* Creates a **Wallet** by decrypting the %%json%% with %%password%%.
|
||||
*
|
||||
* The [[fromEncryptedJson]] method is preferred, as this method
|
||||
* will lock up and freeze the UI during decryption, which may take
|
||||
* some time.
|
||||
*/
|
||||
static fromEncryptedJsonSync(json: string, password: Uint8Array | string): HDNodeWallet | Wallet;
|
||||
/**
|
||||
* Creates a new random [[HDNodeWallet]] using the available
|
||||
* [cryptographic random source](randomBytes).
|
||||
*
|
||||
* If there is no crytographic random source, this will throw.
|
||||
*/
|
||||
static createRandom(provider?: null | Provider): HDNodeWallet;
|
||||
/**
|
||||
* Creates a [[HDNodeWallet]] for %%phrase%%.
|
||||
*/
|
||||
static fromPhrase(phrase: string, provider?: Provider): HDNodeWallet;
|
||||
}
|
||||
//# sourceMappingURL=wallet.d.ts.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.d.ts.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.d.ts.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAS7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAUtD;;;;;;;;;GASG;AACH,qBAAa,MAAO,SAAQ,UAAU;;IAElC;;;OAGG;gBACS,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ;IAShE,OAAO,CAAC,QAAQ,EAAE,IAAI,GAAG,QAAQ,GAAG,MAAM;IAI1C;;;;;;OAMG;IACG,OAAO,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlG;;;;;;;;;OASG;IACH,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM;IAyBlD;;;;;;OAMG;WACU,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC;IAexI;;;;;;OAMG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM;IAahG;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,YAAY;IAM7D;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY;CAKvE"}
|
||||
148
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.js
generated
vendored
Executable file
148
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.js
generated
vendored
Executable file
@@ -0,0 +1,148 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Wallet = void 0;
|
||||
const index_js_1 = require("../crypto/index.js");
|
||||
const index_js_2 = require("../utils/index.js");
|
||||
const base_wallet_js_1 = require("./base-wallet.js");
|
||||
const hdwallet_js_1 = require("./hdwallet.js");
|
||||
const json_crowdsale_js_1 = require("./json-crowdsale.js");
|
||||
const json_keystore_js_1 = require("./json-keystore.js");
|
||||
const mnemonic_js_1 = require("./mnemonic.js");
|
||||
function stall(duration) {
|
||||
return new Promise((resolve) => { setTimeout(() => { resolve(); }, duration); });
|
||||
}
|
||||
/**
|
||||
* A **Wallet** manages a single private key which is used to sign
|
||||
* transactions, messages and other common payloads.
|
||||
*
|
||||
* This class is generally the main entry point for developers
|
||||
* that wish to use a private key directly, as it can create
|
||||
* instances from a large variety of common sources, including
|
||||
* raw private key, [[link-bip-39]] mnemonics and encrypte JSON
|
||||
* wallets.
|
||||
*/
|
||||
class Wallet extends base_wallet_js_1.BaseWallet {
|
||||
/**
|
||||
* Create a new wallet for the private %%key%%, optionally connected
|
||||
* to %%provider%%.
|
||||
*/
|
||||
constructor(key, provider) {
|
||||
if (typeof (key) === "string" && !key.startsWith("0x")) {
|
||||
key = "0x" + key;
|
||||
}
|
||||
let signingKey = (typeof (key) === "string") ? new index_js_1.SigningKey(key) : key;
|
||||
super(signingKey, provider);
|
||||
}
|
||||
connect(provider) {
|
||||
return new Wallet(this.signingKey, provider);
|
||||
}
|
||||
/**
|
||||
* Resolves to a [JSON Keystore Wallet](json-wallets) encrypted with
|
||||
* %%password%%.
|
||||
*
|
||||
* If %%progressCallback%% is specified, it will receive periodic
|
||||
* updates as the encryption process progreses.
|
||||
*/
|
||||
async encrypt(password, progressCallback) {
|
||||
const account = { address: this.address, privateKey: this.privateKey };
|
||||
return await (0, json_keystore_js_1.encryptKeystoreJson)(account, password, { progressCallback });
|
||||
}
|
||||
/**
|
||||
* Returns a [JSON Keystore Wallet](json-wallets) encryped with
|
||||
* %%password%%.
|
||||
*
|
||||
* It is preferred to use the [async version](encrypt) instead,
|
||||
* which allows a [[ProgressCallback]] to keep the user informed.
|
||||
*
|
||||
* This method will block the event loop (freezing all UI) until
|
||||
* it is complete, which may be a non-trivial duration.
|
||||
*/
|
||||
encryptSync(password) {
|
||||
const account = { address: this.address, privateKey: this.privateKey };
|
||||
return (0, json_keystore_js_1.encryptKeystoreJsonSync)(account, password);
|
||||
}
|
||||
static #fromAccount(account) {
|
||||
(0, index_js_2.assertArgument)(account, "invalid JSON wallet", "json", "[ REDACTED ]");
|
||||
if ("mnemonic" in account && account.mnemonic && account.mnemonic.locale === "en") {
|
||||
const mnemonic = mnemonic_js_1.Mnemonic.fromEntropy(account.mnemonic.entropy);
|
||||
const wallet = hdwallet_js_1.HDNodeWallet.fromMnemonic(mnemonic, account.mnemonic.path);
|
||||
if (wallet.address === account.address && wallet.privateKey === account.privateKey) {
|
||||
return wallet;
|
||||
}
|
||||
console.log("WARNING: JSON mismatch address/privateKey != mnemonic; fallback onto private key");
|
||||
}
|
||||
const wallet = new Wallet(account.privateKey);
|
||||
(0, index_js_2.assertArgument)(wallet.address === account.address, "address/privateKey mismatch", "json", "[ REDACTED ]");
|
||||
return wallet;
|
||||
}
|
||||
/**
|
||||
* Creates (asynchronously) a **Wallet** by decrypting the %%json%%
|
||||
* with %%password%%.
|
||||
*
|
||||
* If %%progress%% is provided, it is called periodically during
|
||||
* decryption so that any UI can be updated.
|
||||
*/
|
||||
static async fromEncryptedJson(json, password, progress) {
|
||||
let account = null;
|
||||
if ((0, json_keystore_js_1.isKeystoreJson)(json)) {
|
||||
account = await (0, json_keystore_js_1.decryptKeystoreJson)(json, password, progress);
|
||||
}
|
||||
else if ((0, json_crowdsale_js_1.isCrowdsaleJson)(json)) {
|
||||
if (progress) {
|
||||
progress(0);
|
||||
await stall(0);
|
||||
}
|
||||
account = (0, json_crowdsale_js_1.decryptCrowdsaleJson)(json, password);
|
||||
if (progress) {
|
||||
progress(1);
|
||||
await stall(0);
|
||||
}
|
||||
}
|
||||
return Wallet.#fromAccount(account);
|
||||
}
|
||||
/**
|
||||
* Creates a **Wallet** by decrypting the %%json%% with %%password%%.
|
||||
*
|
||||
* The [[fromEncryptedJson]] method is preferred, as this method
|
||||
* will lock up and freeze the UI during decryption, which may take
|
||||
* some time.
|
||||
*/
|
||||
static fromEncryptedJsonSync(json, password) {
|
||||
let account = null;
|
||||
if ((0, json_keystore_js_1.isKeystoreJson)(json)) {
|
||||
account = (0, json_keystore_js_1.decryptKeystoreJsonSync)(json, password);
|
||||
}
|
||||
else if ((0, json_crowdsale_js_1.isCrowdsaleJson)(json)) {
|
||||
account = (0, json_crowdsale_js_1.decryptCrowdsaleJson)(json, password);
|
||||
}
|
||||
else {
|
||||
(0, index_js_2.assertArgument)(false, "invalid JSON wallet", "json", "[ REDACTED ]");
|
||||
}
|
||||
return Wallet.#fromAccount(account);
|
||||
}
|
||||
/**
|
||||
* Creates a new random [[HDNodeWallet]] using the available
|
||||
* [cryptographic random source](randomBytes).
|
||||
*
|
||||
* If there is no crytographic random source, this will throw.
|
||||
*/
|
||||
static createRandom(provider) {
|
||||
const wallet = hdwallet_js_1.HDNodeWallet.createRandom();
|
||||
if (provider) {
|
||||
return wallet.connect(provider);
|
||||
}
|
||||
return wallet;
|
||||
}
|
||||
/**
|
||||
* Creates a [[HDNodeWallet]] for %%phrase%%.
|
||||
*/
|
||||
static fromPhrase(phrase, provider) {
|
||||
const wallet = hdwallet_js_1.HDNodeWallet.fromPhrase(phrase);
|
||||
if (provider) {
|
||||
return wallet.connect(provider);
|
||||
}
|
||||
return wallet;
|
||||
}
|
||||
}
|
||||
exports.Wallet = Wallet;
|
||||
//# sourceMappingURL=wallet.js.map
|
||||
1
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.js.map
generated
vendored
Executable file
1
dev/env/node_modules/ethers/lib.commonjs/wallet/wallet.js.map
generated
vendored
Executable file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src.ts/wallet/wallet.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,gDAAmD;AAEnD,qDAA8C;AAC9C,+CAA6C;AAC7C,2DAA6E;AAC7E,yDAI4B;AAC5B,+CAAyC;AASzC,SAAS,KAAK,CAAC,QAAgB;IAC3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAA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