Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kevzzsk committed Jul 17, 2023
1 parent 3f5b7e1 commit b65ae2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
8 changes: 4 additions & 4 deletions packages/sdk/src/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BIP32Factory, { BIP32Interface } from "bip32";

import { Network } from "../config/types";
import { getWalletKeys } from "../keys";
import {createTransaction, getDerivationPath, getNetwork, getPathLevels, toXOnly} from "../utils";
import { createTransaction, getDerivationPath, getNetwork, toXOnly } from "../utils";
import { AddressFormats, addressFormats, addressNameToType, AddressTypes, addressTypeToName } from "./formats";

export function getAddressFormat(address: string, network: Network) {
Expand Down Expand Up @@ -129,8 +129,8 @@ export function getAccountDataFromHdNode({

const addressType = addressNameToType[format];

const fullDerivationPath = getDerivationPath(format, accountIndex, index)
const child = hdNode.derivePath(fullDerivationPath)
const fullDerivationPath = getDerivationPath(format, accountIndex, index);
const child = hdNode.derivePath(fullDerivationPath);

const pubKey = format === "taproot" ? toXOnly(child.publicKey) : child.publicKey;
const paymentObj = createTransaction(pubKey, addressType, network);
Expand Down Expand Up @@ -180,7 +180,7 @@ export type Address = {
export type Account = Address & {
priv: string;
type: AddressTypes;
derivationPath: string
derivationPath: string;
};

type GetAddressesOptions = {
Expand Down
24 changes: 14 additions & 10 deletions packages/sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,34 @@ export function createTransaction(
return bitcoin.payments[type]({ pubkey: key, network: networkObj });
}

export function getDerivationPath(formatType:AddressFormats, accountIndex = 0 , index = 0 ){
export function getDerivationPath(formatType: AddressFormats, accountIndex = 0, index = 0) {
const pathFormat = {
legacy: `m/44'/0'/${accountIndex}'/0/${index}`,
segwit: `m/49'/0'/${accountIndex}'/0/${index}`,
bech32: `m/84'/0'/${accountIndex}'/0/${index}`,
taproot: `m/86'/0'/${accountIndex}'/0/${index}`
}
return pathFormat[formatType]

};
return pathFormat[formatType];
}

export function getPathLevels(fullDerivationPath: string){
const [, purpose, coinType, account,change,addressIndex] = fullDerivationPath.split("/")
export function getPathLevels(fullDerivationPath: string) {
const [, purpose, coinType, account, change, addressIndex] = fullDerivationPath.split("/");
return {
purpose: purpose.replace("'", ""),
coinType: coinType.replace("'", ""),
account: account.replace("'",""),
account: account.replace("'", ""),
change,
addressIndex
}
};
}

export function hdNodeToChild(node: BIP32Interface, formatType: AddressFormats = "legacy", index = 0, accountIndex= 0) {
const fullDerivationPath = getDerivationPath(formatType, accountIndex, index)
export function hdNodeToChild(
node: BIP32Interface,
formatType: AddressFormats = "legacy",
index = 0,
accountIndex = 0
) {
const fullDerivationPath = getDerivationPath(formatType, accountIndex, index);

return node.derivePath(fullDerivationPath);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/wallet/Ordit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ export class Ordit {
}
}

getAddress(type: AddressFormats, accountIndex: number, addressIndex:number) {
getAddress(type: AddressFormats, accountIndex: number, addressIndex: number) {
if (!this.#hdNode) throw new Error("No HD node found. Please reinitialize with BIP39 words or seed.");

return getAccountDataFromHdNode({ hdNode: this.#hdNode, format: type, network: this.#network, accountIndex, index:addressIndex });
return getAccountDataFromHdNode({
hdNode: this.#hdNode,
format: type,
network: this.#network,
accountIndex,
index: addressIndex
});
}

signPsbt(value: string, { finalized = true }: { finalized?: boolean }) {
Expand Down

0 comments on commit b65ae2f

Please sign in to comment.