From b65ae2fbaa635d7f6e84a75a97839aeeaee8742a Mon Sep 17 00:00:00 2001 From: KevinK Date: Mon, 17 Jul 2023 17:38:32 +0800 Subject: [PATCH] fix lint issues --- packages/sdk/src/addresses/index.ts | 8 ++++---- packages/sdk/src/utils/index.ts | 24 ++++++++++++++---------- packages/sdk/src/wallet/Ordit.ts | 10 ++++++++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/packages/sdk/src/addresses/index.ts b/packages/sdk/src/addresses/index.ts index 67ca2752..870b7cf6 100644 --- a/packages/sdk/src/addresses/index.ts +++ b/packages/sdk/src/addresses/index.ts @@ -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) { @@ -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); @@ -180,7 +180,7 @@ export type Address = { export type Account = Address & { priv: string; type: AddressTypes; - derivationPath: string + derivationPath: string; }; type GetAddressesOptions = { diff --git a/packages/sdk/src/utils/index.ts b/packages/sdk/src/utils/index.ts index 079638de..d6e95f1c 100644 --- a/packages/sdk/src/utils/index.ts +++ b/packages/sdk/src/utils/index.ts @@ -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); } diff --git a/packages/sdk/src/wallet/Ordit.ts b/packages/sdk/src/wallet/Ordit.ts index 3cf8d750..083b0370 100644 --- a/packages/sdk/src/wallet/Ordit.ts +++ b/packages/sdk/src/wallet/Ordit.ts @@ -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 }) {