From a883e1c9478e16c1d8bc395a7f4e638edece6920 Mon Sep 17 00:00:00 2001 From: netbonus <151201453+netbonus@users.noreply.github.com> Date: Mon, 26 Feb 2024 10:04:25 -0500 Subject: [PATCH] add more address fetch reqs --- .nvmrc | 1 + src/api/addresses.ts | 68 +++++++++++++++++++++----------------------- src/constants.ts | 27 ++++++++++++++++++ 3 files changed, 61 insertions(+), 35 deletions(-) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..19c7bdba --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/src/api/addresses.ts b/src/api/addresses.ts index 6bbf3a17..6f36ccba 100644 --- a/src/api/addresses.ts +++ b/src/api/addresses.ts @@ -1,6 +1,9 @@ import { + BTC_LEGACY_CHANGE_DERIVATION, BTC_LEGACY_DERIVATION, + BTC_SEGWIT_CHANGE_DERIVATION, BTC_SEGWIT_DERIVATION, + BTC_WRAPPED_SEGWIT_CHANGE_DERIVATION, BTC_WRAPPED_SEGWIT_DERIVATION, DEFAULT_ETH_DERIVATION, LEDGER_LEGACY_DERIVATION, @@ -60,41 +63,36 @@ export const fetchAddress = async ( }).then((addrs) => addrs[0]); }; -export const fetchBtcLegacyAddresses = async ( - { n, startPathIndex }: FetchAddressesParams = { - n: MAX_ADDR, - startPathIndex: 0, - }, -) => { - return fetchAddresses({ - startPath: getStartPath(BTC_LEGACY_DERIVATION, startPathIndex), - n, - }); -}; - -export const fetchBtcSegwitAddresses = async ( - { n, startPathIndex }: FetchAddressesParams = { - n: MAX_ADDR, - startPathIndex: 0, - }, -) => { - return fetchAddresses({ - startPath: getStartPath(BTC_SEGWIT_DERIVATION, startPathIndex), - n, - }); -}; - -export const fetchBtcWrappedSegwitAddresses = async ( - { n, startPathIndex }: FetchAddressesParams = { - n: MAX_ADDR, - startPathIndex: 0, - }, -) => { - return fetchAddresses({ - startPath: getStartPath(BTC_WRAPPED_SEGWIT_DERIVATION, startPathIndex), - n, - }); -}; +function createFetchBtcAddressesFunction(derivationPath: number[]) { + return async ( + { n, startPathIndex }: FetchAddressesParams = { + n: MAX_ADDR, + startPathIndex: 0, + }, + ) => { + return fetchAddresses({ + startPath: getStartPath(derivationPath, startPathIndex), + n, + }); + }; +} +export const fetchBtcLegacyAddresses = createFetchBtcAddressesFunction( + BTC_LEGACY_DERIVATION, +); +export const fetchBtcSegwitAddresses = createFetchBtcAddressesFunction( + BTC_SEGWIT_DERIVATION, +); +export const fetchBtcWrappedSegwitAddresses = createFetchBtcAddressesFunction( + BTC_WRAPPED_SEGWIT_DERIVATION, +); +export const fetchBtcLegacyChangeAddresses = createFetchBtcAddressesFunction( + BTC_LEGACY_CHANGE_DERIVATION, +); +export const fetchBtcSegwitChangeAddresses = createFetchBtcAddressesFunction( + BTC_SEGWIT_CHANGE_DERIVATION, +); +export const fetchBtcWrappedSegwitChangeAddresses = + createFetchBtcAddressesFunction(BTC_WRAPPED_SEGWIT_CHANGE_DERIVATION); export const fetchSolanaAddresses = async ( { n, startPathIndex }: FetchAddressesParams = { diff --git a/src/constants.ts b/src/constants.ts index 21316129..a435e792 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -521,6 +521,15 @@ export const BTC_LEGACY_DERIVATION = [ 0, ]; +/** @internal */ +export const BTC_LEGACY_CHANGE_DERIVATION = [ + HARDENED_OFFSET + 44, + HARDENED_OFFSET + 0, + HARDENED_OFFSET, + 0, + 0, +]; + /** @internal */ export const BTC_SEGWIT_DERIVATION = [ HARDENED_OFFSET + 84, @@ -530,6 +539,15 @@ export const BTC_SEGWIT_DERIVATION = [ 0, ]; +/** @internal */ +export const BTC_SEGWIT_CHANGE_DERIVATION = [ + HARDENED_OFFSET + 84, + HARDENED_OFFSET, + HARDENED_OFFSET, + 1, + 0, +]; + /** @internal */ export const BTC_WRAPPED_SEGWIT_DERIVATION = [ HARDENED_OFFSET + 49, @@ -539,6 +557,15 @@ export const BTC_WRAPPED_SEGWIT_DERIVATION = [ 0, ]; +/** @internal */ +export const BTC_WRAPPED_SEGWIT_CHANGE_DERIVATION = [ + HARDENED_OFFSET + 49, + HARDENED_OFFSET, + HARDENED_OFFSET, + 0, + 0, +]; + /** @internal */ export const SOLANA_DERIVATION = [ HARDENED_OFFSET + 44,