Skip to content

Commit

Permalink
add more address fetch reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Feb 26, 2024
1 parent 8ad20cd commit a883e1c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 35 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
68 changes: 33 additions & 35 deletions src/api/addresses.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
27 changes: 27 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit a883e1c

Please sign in to comment.