diff --git a/src.ts/_tests/test-wallet-hd.ts b/src.ts/_tests/test-wallet-hd.ts index 7b3894dd..e619b938 100644 --- a/src.ts/_tests/test-wallet-hd.ts +++ b/src.ts/_tests/test-wallet-hd.ts @@ -5,7 +5,7 @@ import { loadTests } from "./utils.js"; import { getBytes, wordlists, - HDNodeWallet, HDNodeVoidWallet, Mnemonic + QuaiHDWallet, HDNodeVoidWallet, Mnemonic } from "../index.js"; import type { Wordlist } from "../wordlists/index.js"; @@ -29,7 +29,7 @@ type Test = { }; describe("Test HDWallets", function() { - function checkWallet(wallet: HDNodeWallet | HDNodeVoidWallet, test: TestCaseMnemonicNode): void { + function checkWallet(wallet: QuaiHDWallet | HDNodeVoidWallet, test: TestCaseMnemonicNode): void { assert.equal(wallet.chainCode, test.chainCode, "chainCode"); assert.equal(wallet.depth, test.depth, "depth"); assert.equal(wallet.index, test.index, "index"); @@ -37,7 +37,7 @@ describe("Test HDWallets", function() { assert.equal(wallet.accountFingerprint, test.parentFingerprint, "parentFingerprint"); assert.equal(wallet.publicKey, test.publicKey, "publicKey"); - if (wallet instanceof HDNodeWallet) { + if (wallet instanceof QuaiHDWallet) { assert.equal(wallet.extendedKey, test.xpriv, "xpriv"); assert.equal(wallet.privateKey, test.privateKey, "privateKey"); assert.equal(wallet.neuter().extendedKey, test.xpub, "xpub"); @@ -80,8 +80,8 @@ describe("Test HDWallets", function() { for (const { test, checkMnemonic, phrase, password, wordlist } of checks) { it(`computes the HD keys by mnemonic: ${ test.name }`, function() { for (const subtest of test.nodes) { - const w = HDNodeWallet.fromPhrase(phrase, password, subtest.path, wordlist); - assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + const w = QuaiHDWallet.fromPhrase(phrase, password, subtest.path, wordlist); + assert.ok(w instanceof QuaiHDWallet, "instanceof QuaiHDWallet"); assert.equal(w.path, subtest.path, "path") checkWallet(w, subtest); assert.ok(!!w.mnemonic, "has mnemonic"); @@ -92,10 +92,10 @@ describe("Test HDWallets", function() { for (const { test } of checks) { it(`computes the HD keys by entropy: ${ test.name }`, function() { - const seedRoot = HDNodeWallet.fromSeed(test.seed); + const seedRoot = QuaiHDWallet.fromSeed(test.seed); for (const subtest of test.nodes) { const w = seedRoot.derivePath(subtest.path); - assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + assert.ok(w instanceof QuaiHDWallet, "instanceof QuaiHDWallet"); assert.equal(w.path, subtest.path, "path") checkWallet(w, subtest); assert.equal(w.mnemonic, null); @@ -106,8 +106,8 @@ describe("Test HDWallets", function() { for (const { test } of checks) { it(`computes the HD keys by enxtended private key: ${ test.name }`, function() { for (const subtest of test.nodes) { - const w = HDNodeWallet.fromExtendedKey(subtest.xpriv); - assert.ok(w instanceof HDNodeWallet, "instanceof HDNodeWallet"); + const w = QuaiHDWallet.fromExtendedKey(subtest.xpriv); + assert.ok(w instanceof QuaiHDWallet, "instanceof QuaiHDWallet"); checkWallet(w, subtest); assert.equal(w.mnemonic, null); } @@ -116,7 +116,7 @@ describe("Test HDWallets", function() { for (const { test, phrase, password, wordlist } of checks) { it(`computes the neutered HD keys by paths: ${ test.name }`, function() { - const root = HDNodeWallet.fromPhrase(phrase, password, "m", wordlist).neuter(); + const root = QuaiHDWallet.fromPhrase(phrase, password, "m", wordlist).neuter(); for (const subtest of test.nodes) { if (subtest.path.indexOf("'") >= 0) { assert.throws(() => { @@ -140,7 +140,7 @@ describe("Test HDWallets", function() { for (const { test } of checks) { it(`computes the neutered HD keys by enxtended public key: ${ test.name }`, function() { for (const subtest of test.nodes) { - const w = HDNodeWallet.fromExtendedKey(subtest.xpub); + const w = QuaiHDWallet.fromExtendedKey(subtest.xpub); assert.ok(w instanceof HDNodeVoidWallet, "instanceof HDNodeVoidWallet"); checkWallet(w, subtest); } diff --git a/src.ts/_tests/test-wallet-json.ts b/src.ts/_tests/test-wallet-json.ts index 911d4eef..c302996e 100644 --- a/src.ts/_tests/test-wallet-json.ts +++ b/src.ts/_tests/test-wallet-json.ts @@ -11,7 +11,7 @@ import { decryptCrowdsaleJson, decryptKeystoreJson, decryptKeystoreJsonSync, encryptKeystoreJson, encryptKeystoreJsonSync, isCrowdsaleJson, - HDNodeWallet, Wallet + QuaiHDWallet, Wallet } from "../index.js"; @@ -70,14 +70,14 @@ describe("Tests JSON Wallet Formats", function() { it("tests encrypting wallet with mnemonic", function() { this.timeout(20000); - const wallet = HDNodeWallet.createRandom("m/44'/60'/0'/0/0"); + const wallet = QuaiHDWallet.createRandom("m/44'/60'/0'/0/0"); assert.ok(wallet.mnemonic, "mnemonic"); const phrase = wallet.mnemonic.phrase; const json = wallet.encryptSync("foobar"); const wallet2 = Wallet.fromEncryptedJsonSync(json, "foobar"); - assert.ok(wallet2 instanceof HDNodeWallet && wallet2.mnemonic); + assert.ok(wallet2 instanceof QuaiHDWallet && wallet2.mnemonic); assert.equal(wallet2.mnemonic.phrase, phrase, "phrase"); assert.equal(wallet2.address, wallet.address, "address"); diff --git a/src.ts/_tests/test-wallet.ts b/src.ts/_tests/test-wallet.ts index 1e6cf94e..11a58cb7 100644 --- a/src.ts/_tests/test-wallet.ts +++ b/src.ts/_tests/test-wallet.ts @@ -8,7 +8,7 @@ import type { import { hexlify, randomBytes, Wallet } from "../index.js"; -import type { HDNodeWallet } from "../index.js"; +import type { QuaiHDWallet } from "../index.js"; describe("Test Private Key Wallet", function() { @@ -61,11 +61,11 @@ describe("Test Wallet Encryption", function() { const password = "foobar"; // Loop: - // 1 : random wallet (uses HDNodeWallet under the hood) + // 1 : random wallet (uses QuaiHDWallet under the hood) // 2 : Wallet using private key (uses Wallet explicitly) for (let i = 0; i < 2; i++) { - let wallet: Wallet | HDNodeWallet = Wallet.createRandom("m/44'/994'/0'/0"); + let wallet: Wallet | QuaiHDWallet = Wallet.createRandom("m/44'/994'/0'/0"); it("encrypts a random wallet: sync", function() { this.timeout(30000); diff --git a/src.ts/crypto/signing-key.ts b/src.ts/crypto/signing-key.ts index 78adf5b3..eb701e09 100644 --- a/src.ts/crypto/signing-key.ts +++ b/src.ts/crypto/signing-key.ts @@ -206,7 +206,7 @@ export class SigningKey { * This is not a common function most developers should require, but * can be useful for certain privacy-specific techniques. * - * For example, it is used by [**HDNodeWallet**](../classes/HDNodeWallet) to compute child + * For example, it is used by [**QuaiHDWallet**](../classes/QuaiHDWallet) to compute child * addresses from parent public keys and chain codes. * * @param {BytesLike} p0 - The first point to add. diff --git a/src.ts/quais.ts b/src.ts/quais.ts index fcfac619..0ae51cf4 100644 --- a/src.ts/quais.ts +++ b/src.ts/quais.ts @@ -118,7 +118,7 @@ export { // WALLET export { Mnemonic, - BaseWallet, HDNodeWallet, HDNodeVoidWallet, UTXOHDWallet, + BaseWallet, QuaiHDWallet, HDNodeVoidWallet, QiHDWallet, Wallet, diff --git a/src.ts/wallet/index.ts b/src.ts/wallet/index.ts index e5ed809e..4f05d018 100644 --- a/src.ts/wallet/index.ts +++ b/src.ts/wallet/index.ts @@ -10,7 +10,7 @@ * The class most developers will want to use is [Wallet](../classes/Wallet), which * can load a private key directly or from any common wallet format. * - * The [HDNodeWallet](../classes/HDNodeWallet) can be used when it is necessary to access + * The [QuaiHDWallet](../classes/QuaiHDWallet) can be used when it is necessary to access * low-level details of how an HD wallets are derived, exported * or imported. * @@ -23,9 +23,9 @@ export { getAccountPath, getIndexedAccountPath, quaiHDAccountPath, qiHDAccountPath, - HDNodeWallet, + QuaiHDWallet, HDNodeVoidWallet, -} from "./hdwallet.js"; +} from "./quai-hdwallet.js"; export { isCrowdsaleJson, decryptCrowdsaleJson } from "./json-crowdsale.js"; @@ -45,6 +45,6 @@ export type { KeystoreAccount, EncryptOptions } from "./json-keystore.js" -export { UTXOHDWallet } from "./utxohdwallet.js"; +export { QiHDWallet } from "./qi-hdwallet.js"; export { nobleCrypto } from "./musig-crypto.js"; \ No newline at end of file diff --git a/src.ts/wallet/utxohdwallet.ts b/src.ts/wallet/qi-hdwallet.ts similarity index 92% rename from src.ts/wallet/utxohdwallet.ts rename to src.ts/wallet/qi-hdwallet.ts index 5ad58d11..3ca220e4 100644 --- a/src.ts/wallet/utxohdwallet.ts +++ b/src.ts/wallet/qi-hdwallet.ts @@ -1,5 +1,5 @@ -import { N, ShardData } from '../constants'; +import { N, ShardData } from '../constants/index.js'; import { SigningKey, keccak256 as addressKeccak256 } from "../crypto/index.js"; import { BytesLike, @@ -65,7 +65,7 @@ const _guard = { }; * * @category Wallet */ -export class UTXOHDWallet extends BaseWallet { +export class QiHDWallet extends BaseWallet { /** * The compressed public key. */ @@ -153,23 +153,23 @@ export class UTXOHDWallet extends BaseWallet { this.#publicKey = signingKey.compressedPublicKey const fingerprint = dataSlice(ripemd160(sha256(this.#publicKey)), 0, 4); - defineProperties(this, { + defineProperties(this, { accountFingerprint, fingerprint, chainCode, path, index, depth }); - defineProperties(this, { mnemonic }); + defineProperties(this, { mnemonic }); } - connect(provider: null | Provider): UTXOHDWallet { - return new UTXOHDWallet(_guard, this.signingKey, this.accountFingerprint, + connect(provider: null | Provider): QiHDWallet { + return new QiHDWallet(_guard, this.signingKey, this.accountFingerprint, this.chainCode, this.path, this.index, this.depth, this.mnemonic, provider); } - derivePath(path: string): UTXOHDWallet { - return derivePath(this, path); + derivePath(path: string): QiHDWallet { + return derivePath(this, path); } - static #fromSeed(_seed: BytesLike, mnemonic: null | Mnemonic): UTXOHDWallet { + static #fromSeed(_seed: BytesLike, mnemonic: null | Mnemonic): QiHDWallet { assertArgument(isBytesLike(_seed), "invalid seed", "seed", "[REDACTED]"); const seed = getBytes(_seed, "seed"); @@ -178,7 +178,7 @@ export class UTXOHDWallet extends BaseWallet { const I = getBytes(computeHmac("sha512", MasterSecret, seed)); const signingKey = new SigningKey(hexlify(I.slice(0, 32))); - const result = new UTXOHDWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), + const result = new QiHDWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), "m", 0, 0, mnemonic, null); return result; } @@ -193,12 +193,12 @@ export class UTXOHDWallet extends BaseWallet { * @param {string} path - The BIP44 path to derive. * @param {string} [password] - The password to use for the mnemonic. * @param {Wordlist} [wordlist] - The wordlist to use for the mnemonic. - * @returns {UTXOHDWallet} The new HDNode. + * @returns {QiHDWallet} The new HDNode. */ - static createRandom( path: string, password?: string, wordlist?: Wordlist): UTXOHDWallet { + static createRandom( path: string, password?: string, wordlist?: Wordlist): QiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} const mnemonic = Mnemonic.fromEntropy(randomBytes(16), password, wordlist) - return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -206,11 +206,11 @@ export class UTXOHDWallet extends BaseWallet { * * @param {Mnemonic} mnemonic - The mnemonic to create the HDNode from. * @param {string} path - The BIP44 path to derive. - * @returns {UTXOHDWallet} The new HDNode. + * @returns {QiHDWallet} The new HDNode. */ - static fromMnemonic(mnemonic: Mnemonic, path: string): UTXOHDWallet { + static fromMnemonic(mnemonic: Mnemonic, path: string): QiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} - return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -220,12 +220,12 @@ export class UTXOHDWallet extends BaseWallet { * @param {string} path - The BIP44 path to derive. * @param {string} [password] - The password to use for the mnemonic. * @param {Wordlist} [wordlist] - The wordlist to use for the mnemonic. - * @returns {UTXOHDWallet} The new HDNode. + * @returns {QiHDWallet} The new HDNode. */ - static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): UTXOHDWallet { + static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): QiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} const mnemonic = Mnemonic.fromPhrase(phrase, password, wordlist) - return UTXOHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -244,9 +244,9 @@ export class UTXOHDWallet extends BaseWallet { * Return the child for `index`. * * @param {number} _index - The index to derive. - * @returns {UTXOHDWallet} The derived child. + * @returns {QiHDWallet} The derived child. */ - deriveChild(_index: Numeric): UTXOHDWallet { + deriveChild(_index: Numeric): QiHDWallet { const index = getNumber(_index, "index"); assertArgument(index <= 0xffffffff, "invalid index", "index", index); @@ -270,7 +270,7 @@ export class UTXOHDWallet extends BaseWallet { //BIP44 if we are at the account depth get that fingerprint, otherwise continue with the current one let newFingerprint = this.depth == 3 ? this.fingerprint : this.accountFingerprint; - return new UTXOHDWallet(_guard, ki, newFingerprint, hexlify(IR), + return new QiHDWallet(_guard, ki, newFingerprint, hexlify(IR), path, index, newDepth, this.mnemonic, this.provider); } @@ -280,14 +280,14 @@ export class UTXOHDWallet extends BaseWallet { * * @param {number} startingIndex - The index to derive. * @param {string} zone - The zone to derive the address for - * @returns {UTXOHDWallet} The derived address. + * @returns {QiHDWallet} The derived address. * @throws {Error} If the wallet's address derivation path is missing or if * a valid address cannot be derived for the specified zone after 1000 attempts. */ private deriveAddress(startingIndex: number, zone: string): AddressInfo{ if (!this.path) throw new Error("Missing wallet's address derivation path"); - let newWallet: UTXOHDWallet; + let newWallet: QiHDWallet; // helper function to check if the generated address is valid for the specified zone const isValidAddressForZone = (address: string) => { diff --git a/src.ts/wallet/hdwallet.ts b/src.ts/wallet/quai-hdwallet.ts similarity index 91% rename from src.ts/wallet/hdwallet.ts rename to src.ts/wallet/quai-hdwallet.ts index ca8ae20d..0833e9a5 100644 --- a/src.ts/wallet/hdwallet.ts +++ b/src.ts/wallet/quai-hdwallet.ts @@ -29,7 +29,7 @@ import { encodeBase58Check, zpad, HardenedBit, ser_I, derivePath, MasterSecret } const _guard = { }; /** - * An **HDNodeWallet** is a [Signer](../interfaces/Signer) backed by the private key derived + * An **QuaiHDWallet** is a [Signer](../interfaces/Signer) backed by the private key derived * from an HD Node using the [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) stantard. * * An HD Node forms a hierarchal structure with each HD Node having a @@ -38,7 +38,7 @@ const _guard = { }; * * @category Wallet */ -export class HDNodeWallet extends BaseWallet { +export class QuaiHDWallet extends BaseWallet { /** * The compressed public key. */ @@ -106,15 +106,15 @@ export class HDNodeWallet extends BaseWallet { this.#publicKey = signingKey.compressedPublicKey const fingerprint = dataSlice(ripemd160(sha256(this.#publicKey)), 0, 4); - defineProperties(this, { + defineProperties(this, { accountFingerprint, fingerprint, chainCode, path, index, depth }); - defineProperties(this, { mnemonic }); + defineProperties(this, { mnemonic }); } - connect(provider: null | Provider): HDNodeWallet { - return new HDNodeWallet(_guard, this.signingKey, this.accountFingerprint, + connect(provider: null | Provider): QuaiHDWallet { + return new QuaiHDWallet(_guard, this.signingKey, this.accountFingerprint, this.chainCode, this.path, this.index, this.depth, this.mnemonic, provider); } @@ -221,9 +221,9 @@ export class HDNodeWallet extends BaseWallet { * Return the child for `index`. * * @param {Numeric} _index - The index of the child to derive. - * @returns {HDNodeWallet} The derived child HD Node. + * @returns {QuaiHDWallet} The derived child HD Node. */ - deriveChild(_index: Numeric): HDNodeWallet { + deriveChild(_index: Numeric): QuaiHDWallet { const index = getNumber(_index, "index"); assertArgument(index <= 0xffffffff, "invalid index", "index", index); @@ -248,7 +248,7 @@ export class HDNodeWallet extends BaseWallet { //BIP44 if we are at the account depth get that fingerprint, otherwise continue with the current one let newFingerprint = this.depth == 3 ? this.fingerprint : this.accountFingerprint; - return new HDNodeWallet(_guard, ki, newFingerprint, hexlify(IR), + return new QuaiHDWallet(_guard, ki, newFingerprint, hexlify(IR), path, index, newDepth, this.mnemonic, this.provider); } @@ -257,17 +257,17 @@ export class HDNodeWallet extends BaseWallet { * Return the HDNode for `path` from this node. * * @param {string} path - The path to derive. - * @returns {HDNodeWallet} The derived HD Node. + * @returns {QuaiHDWallet} The derived HD Node. */ - derivePath(path: string): HDNodeWallet { - return derivePath(this, path); + derivePath(path: string): QuaiHDWallet { + return derivePath(this, path); } setCoinType(): void { this.coinType = Number(this.path?.split("/")[2].replace("'", "")); } - static #fromSeed(_seed: BytesLike, mnemonic: null | Mnemonic): HDNodeWallet { + static #fromSeed(_seed: BytesLike, mnemonic: null | Mnemonic): QuaiHDWallet { assertArgument(isBytesLike(_seed), "invalid seed", "seed", "[REDACTED]"); const seed = getBytes(_seed, "seed"); @@ -276,7 +276,7 @@ export class HDNodeWallet extends BaseWallet { const I = getBytes(computeHmac("sha512", MasterSecret, seed)); const signingKey = new SigningKey(hexlify(I.slice(0, 32))); - const result = new HDNodeWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), + const result = new QuaiHDWallet(_guard, signingKey, "0x00000000", hexlify(I.slice(32)), "m", 0, 0, mnemonic, null); return result; } @@ -286,12 +286,12 @@ export class HDNodeWallet extends BaseWallet { * * If the `extendedKey` will either have a prefix or `xpub` or * `xpriv`, returning a neutered HD Node ({@link HDNodeVoidWallet | **HDNodeVoidWallet**}) - * or full HD Node ({@link HDNodeWallet | **HDNodeWallet**}) respectively. + * or full HD Node ({@link QuaiHDWallet | **QuaiHDWallet**}) respectively. * * @param {string} extendedKey - The extended key to create the HD Node from. - * @returns {HDNodeWallet | HDNodeVoidWallet} The HD Node created from the extended key. + * @returns {QuaiHDWallet | HDNodeVoidWallet} The HD Node created from the extended key. */ - static fromExtendedKey(extendedKey: string): HDNodeWallet | HDNodeVoidWallet { + static fromExtendedKey(extendedKey: string): QuaiHDWallet | HDNodeVoidWallet { const bytes = toBeArray(decodeBase58(extendedKey)); // @TODO: redact assertArgument(bytes.length === 82 || encodeBase58Check(bytes.slice(0, 78)) === extendedKey, @@ -314,7 +314,7 @@ export class HDNodeWallet extends BaseWallet { // Private Key case "0x0488ade4": case "0x04358394 ": if (key[0] !== 0) { break; } - return new HDNodeWallet(_guard, new SigningKey(key.slice(1)), + return new QuaiHDWallet(_guard, new SigningKey(key.slice(1)), accountFingerprint, chainCode, null, index, depth, null, null); } @@ -328,12 +328,12 @@ export class HDNodeWallet extends BaseWallet { * @param {string} path - The BIP44 path to derive the HD Node from. * @param {string} [password] - The password to use for the mnemonic. * @param {Wordlist} [wordlist] - The wordlist to use for the mnemonic. - * @returns {HDNodeWallet} The new HD Node. + * @returns {QuaiHDWallet} The new HD Node. */ - static createRandom( path: string, password?: string, wordlist?: Wordlist): HDNodeWallet { + static createRandom( path: string, password?: string, wordlist?: Wordlist): QuaiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} const mnemonic = Mnemonic.fromEntropy(randomBytes(16), password, wordlist) - return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QuaiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -341,11 +341,11 @@ export class HDNodeWallet extends BaseWallet { * * @param {Mnemonic} mnemonic - The mnemonic to create the HD Node from. * @param {string} path - The BIP44 path to derive the HD Node from. - * @returns {HDNodeWallet} The new HD Node Wallet. + * @returns {QuaiHDWallet} The new HD Node Wallet. */ - static fromMnemonic(mnemonic: Mnemonic, path: string): HDNodeWallet { + static fromMnemonic(mnemonic: Mnemonic, path: string): QuaiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} - return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QuaiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -355,12 +355,12 @@ export class HDNodeWallet extends BaseWallet { * @param {string} path - The BIP44 path to derive the HD Node from. * @param {string} [password] - The password to use for the mnemonic. * @param {Wordlist} [wordlist] - The wordlist to use for the mnemonic. - * @returns {HDNodeWallet} The new HD Node Wallet. + * @returns {QuaiHDWallet} The new HD Node Wallet. */ - static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): HDNodeWallet { + static fromPhrase(phrase: string, path: string, password?: string, wordlist?: Wordlist): QuaiHDWallet { if (path == null || !this.isValidPath(path)) { throw new Error('Invalid path: ' + path)} const mnemonic = Mnemonic.fromPhrase(phrase, password, wordlist) - return HDNodeWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); + return QuaiHDWallet.#fromSeed(mnemonic.computeSeed(), mnemonic).derivePath(path); } /** @@ -381,10 +381,10 @@ export class HDNodeWallet extends BaseWallet { * Creates an HD Node from a `seed`. * * @param {BytesLike} seed - The seed to create the HD Node from. - * @returns {HDNodeWallet} The new HD Node Wallet. + * @returns {QuaiHDWallet} The new HD Node Wallet. */ - static fromSeed(seed: BytesLike): HDNodeWallet { - return HDNodeWallet.#fromSeed(seed, null); + static fromSeed(seed: BytesLike): QuaiHDWallet { + return QuaiHDWallet.#fromSeed(seed, null); } /** @@ -392,10 +392,10 @@ export class HDNodeWallet extends BaseWallet { * * @param {number} index - The index of the address to derive. * @param {string} [zone] - The zone of the address to derive. - * @returns {HDNodeWallet} The derived HD Node. + * @returns {QuaiHDWallet} The derived HD Node. * @throws {Error} If the path is missing or the zone is invalid. */ - deriveAddress(index: number, zone?: string): HDNodeWallet { + deriveAddress(index: number, zone?: string): QuaiHDWallet { if (!this.path) throw new Error("Missing Path"); //Case for a non quai/qi wallet where zone is not needed @@ -414,7 +414,7 @@ export class HDNodeWallet extends BaseWallet { throw new Error("Invalid zone"); } - let newWallet: HDNodeWallet; + let newWallet: QuaiHDWallet; let addrIndex: number = 0; let zoneIndex: number = index + 1; do { @@ -444,8 +444,8 @@ export class HDNodeWallet extends BaseWallet { * the children nodes of a [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) HD wallet addresses. * * The can be created by using an extended `xpub` key to - * {@link HDNodeWallet.fromExtendedKey | **HDNodeWallet.fromExtendedKey**} or by - * [nuetering](HDNodeWallet-neuter) a {@link HDNodeWallet | **HDNodeWallet**}. + * {@link QuaiHDWallet.fromExtendedKey | **QuaiHDWallet.fromExtendedKey**} or by + * [nuetering](QuaiHDWallet-neuter) a {@link QuaiHDWallet | **QuaiHDWallet**}. * * @category Wallet */ @@ -587,17 +587,17 @@ export class HDNodeVoidWallet extends VoidSigner { } /* -export class HDNodeWalletManager { - #root: HDNodeWallet; +export class QuaiHDWalletManager { + #root: QuaiHDWallet; 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); + this.#root = QuaiHDWallet.fromPhrase(phrase, password, path, locale); } - getSigner(index?: number): HDNodeWallet { + getSigner(index?: number): QuaiHDWallet { return this.#root.deriveChild((index == null) ? 0: index); } } diff --git a/src.ts/wallet/wallet.ts b/src.ts/wallet/wallet.ts index c26ba2cc..dfda0805 100644 --- a/src.ts/wallet/wallet.ts +++ b/src.ts/wallet/wallet.ts @@ -2,7 +2,7 @@ import { SigningKey } from "../crypto/index.js"; import { assertArgument } from "../utils/index.js"; import { BaseWallet } from "./base-wallet.js"; -import { HDNodeWallet } from "./hdwallet.js"; +import { QuaiHDWallet } from "./quai-hdwallet.js"; import { decryptCrowdsaleJson, isCrowdsaleJson } from "./json-crowdsale.js"; import { decryptKeystoreJson, decryptKeystoreJsonSync, @@ -16,7 +16,7 @@ import type { Provider } from "../providers/index.js"; import type { Wordlist } from "../quais.js"; import type { CrowdsaleAccount } from "./json-crowdsale.js"; import type { KeystoreAccount } from "./json-keystore.js"; -import { UTXOHDWallet } from "./utxohdwallet.js"; +import { QiHDWallet } from "./qi-hdwallet.js"; function stall(duration: number): Promise { @@ -88,12 +88,12 @@ export class Wallet extends BaseWallet { return encryptKeystoreJsonSync(account, password); } - static #fromAccount(account: null | CrowdsaleAccount | KeystoreAccount): HDNodeWallet | Wallet { + static #fromAccount(account: null | CrowdsaleAccount | KeystoreAccount): QuaiHDWallet | Wallet { assertArgument(account, "invalid JSON wallet", "json", "[ REDACTED ]"); if ("mnemonic" in account && account.mnemonic && account.mnemonic.locale === "en") { const mnemonic = Mnemonic.fromEntropy(account.mnemonic.entropy); - const wallet = HDNodeWallet.fromMnemonic(mnemonic, account.mnemonic.path || ''); // Add a check for undefined path + const wallet = QuaiHDWallet.fromMnemonic(mnemonic, account.mnemonic.path || ''); // Add a check for undefined path if (wallet.address === account.address && wallet.privateKey === account.privateKey) { return wallet; } @@ -118,9 +118,9 @@ export class Wallet extends BaseWallet { * @param {string} json - The JSON data to decrypt. * @param {Uint8Array | string} password - The password to decrypt the JSON data. * @param {ProgressCallback} [progress] - An optional callback to keep the user informed. - * @returns {Promise} The decrypted wallet. + * @returns {Promise} The decrypted wallet. */ - static async fromEncryptedJson(json: string, password: Uint8Array | string, progress?: ProgressCallback): Promise { + static async fromEncryptedJson(json: string, password: Uint8Array | string, progress?: ProgressCallback): Promise { let account: null | CrowdsaleAccount | KeystoreAccount = null; if (isKeystoreJson(json)) { account = await decryptKeystoreJson(json, password, progress); @@ -144,9 +144,9 @@ export class Wallet extends BaseWallet { * * @param {string} json - The JSON data to decrypt. * @param {Uint8Array | string} password - The password to decrypt the JSON data. - * @returns {HDNodeWallet | Wallet} The decrypted wallet. + * @returns {QuaiHDWallet | Wallet} The decrypted wallet. */ - static fromEncryptedJsonSync(json: string, password: Uint8Array | string): HDNodeWallet | Wallet { + static fromEncryptedJsonSync(json: string, password: Uint8Array | string): QuaiHDWallet | Wallet { let account: null | CrowdsaleAccount | KeystoreAccount = null; if (isKeystoreJson(json)) { account = decryptKeystoreJsonSync(json, password); @@ -160,31 +160,31 @@ export class Wallet extends BaseWallet { } /** - * Creates a new random {@link HDNodeWallet | **HDNodeWallet**} using the available + * Creates a new random {@link QuaiHDWallet | **QuaiHDWallet**} using the available * [cryptographic random source](randomBytes). * * If there is no crytographic random source, this will throw. * * @param {string} path - The derivation path for the wallet. * @param {Provider} [provider] - An optional provider to connect the wallet to. - * @returns {HDNodeWallet} The new wallet. + * @returns {QuaiHDWallet} The new wallet. */ - static createRandom(path: string, provider?: null | Provider): HDNodeWallet { - const wallet = HDNodeWallet.createRandom(path); + static createRandom(path: string, provider?: null | Provider): QuaiHDWallet { + const wallet = QuaiHDWallet.createRandom(path); if (provider) { return wallet.connect(provider); } return wallet; } /**"m/44'/60'/0'/0/0" - * Creates a {@link HDNodeWallet | **HDNodeWallet**} for `phrase`. + * Creates a {@link QuaiHDWallet | **QuaiHDWallet**} for `phrase`. * * @param {string} phrase - The mnemonic phrase to create the wallet with. * @param {string} path - The derivation path for the wallet. * @param {Provider} [provider] - An optional provider to connect the wallet to. * @param {Wordlist} [wordlist] - An optional wordlist to use for the mnemonic phrase. - * @returns {HDNodeWallet} The new wallet. + * @returns {QuaiHDWallet} The new wallet. */ - static fromPhrase(phrase: string, path: string, provider?: Provider, wordlist?: Wordlist): HDNodeWallet | UTXOHDWallet { + static fromPhrase(phrase: string, path: string, provider?: Provider, wordlist?: Wordlist): QuaiHDWallet | QiHDWallet { const splitPath = path.split('/'); if (splitPath.length < 3) throw new Error(`Incomplete path for wallet derivation ${path}`); let coinTypeStr = splitPath[2]; @@ -194,11 +194,11 @@ export class Wallet extends BaseWallet { let wallet; switch (coinType) { case 994: - wallet = HDNodeWallet.fromPhrase(phrase, path, undefined, wordlist); + wallet = QuaiHDWallet.fromPhrase(phrase, path, undefined, wordlist); if (provider) { return wallet.connect(provider); } return wallet; case 969: - wallet = UTXOHDWallet.fromPhrase(phrase, path, undefined, wordlist); + wallet = QiHDWallet.fromPhrase(phrase, path, undefined, wordlist); if (provider) { return wallet.connect(provider); } return wallet; default: