Skip to content

Commit

Permalink
rename UTXOHDWallet to QiHDWallet and HDNodewallet to QuaiHDWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 authored and rileystephens28 committed May 15, 2024
1 parent 94fdccd commit 3f482dd
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 103 deletions.
22 changes: 11 additions & 11 deletions src.ts/_tests/test-wallet-hd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,15 +29,15 @@ 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");
assert.equal(wallet.fingerprint, test.fingerprint, "fingerprint");
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");
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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(() => {
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src.ts/_tests/test-wallet-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
decryptCrowdsaleJson, decryptKeystoreJson, decryptKeystoreJsonSync,
encryptKeystoreJson, encryptKeystoreJsonSync,
isCrowdsaleJson,
HDNodeWallet, Wallet
QuaiHDWallet, Wallet
} from "../index.js";


Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src.ts/_tests/test-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src.ts/crypto/signing-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src.ts/quais.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export {
// WALLET
export {
Mnemonic,
BaseWallet, HDNodeWallet, HDNodeVoidWallet, UTXOHDWallet,
BaseWallet, QuaiHDWallet, HDNodeVoidWallet, QiHDWallet,
Wallet,


Expand Down
8 changes: 4 additions & 4 deletions src.ts/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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";

Expand All @@ -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";
48 changes: 24 additions & 24 deletions src.ts/wallet/utxohdwallet.ts → src.ts/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -65,7 +65,7 @@ const _guard = { };
*
* @category Wallet
*/
export class UTXOHDWallet extends BaseWallet {
export class QiHDWallet extends BaseWallet {
/**
* The compressed public key.
*/
Expand Down Expand Up @@ -153,23 +153,23 @@ export class UTXOHDWallet extends BaseWallet {
this.#publicKey = signingKey.compressedPublicKey

const fingerprint = dataSlice(ripemd160(sha256(this.#publicKey)), 0, 4);
defineProperties<UTXOHDWallet>(this, {
defineProperties<QiHDWallet>(this, {
accountFingerprint, fingerprint,
chainCode, path, index, depth
});
defineProperties<UTXOHDWallet>(this, { mnemonic });
defineProperties<QiHDWallet>(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<UTXOHDWallet>(this, path);
derivePath(path: string): QiHDWallet {
return derivePath<QiHDWallet>(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");
Expand All @@ -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;
}
Expand All @@ -193,24 +193,24 @@ 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);
}

/**
* Create an HD Node from `mnemonic`.
*
* @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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand All @@ -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);

}
Expand All @@ -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) => {
Expand Down
Loading

0 comments on commit 3f482dd

Please sign in to comment.