Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change default to pulling 10 keys #5345

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getTaprootAccountDerivationPath } from '@shared/crypto/bitcoin/p2tr-add
import { getNativeSegwitAccountDerivationPath } from '@shared/crypto/bitcoin/p2wpkh-address-gen';
import { delay } from '@shared/utils';

import { defaultNumberOfKeysToPullFromLedgerDevice } from '../../generic-flows/request-keys/use-request-ledger-keys';
import {
WalletPolicyDetails,
createNativeSegwitDefaultWalletPolicy,
Expand Down Expand Up @@ -55,10 +56,13 @@ interface PullBitcoinKeysFromLedgerDeviceArgs {
}
export function pullBitcoinKeysFromLedgerDevice(bitcoinApp: BitcoinApp, targetId = '') {
return async ({ onRequestKey, network }: PullBitcoinKeysFromLedgerDeviceArgs) => {
const amountOfKeysToExtractFromDevice = 5;
const fingerprint = await bitcoinApp.getMasterFingerprint();
const keys: { id: string; path: string; policy: string; targetId: string }[] = [];
for (let accountIndex = 0; accountIndex < amountOfKeysToExtractFromDevice; accountIndex++) {
for (
let accountIndex = 0;
accountIndex < defaultNumberOfKeysToPullFromLedgerDevice;
accountIndex++
) {
onRequestKey?.(accountIndex);
const { path, policy } = await getNativeSegwitExtendedPublicKey({
bitcoinApp,
Expand All @@ -68,7 +72,11 @@ export function pullBitcoinKeysFromLedgerDevice(bitcoinApp: BitcoinApp, targetId
});
keys.push({ id: createWalletIdDecoratedPath(path, 'default'), path, policy, targetId });
}
for (let accountIndex = 0; accountIndex < amountOfKeysToExtractFromDevice; accountIndex++) {
for (
let accountIndex = 0;
accountIndex < defaultNumberOfKeysToPullFromLedgerDevice;
accountIndex++
) {
onRequestKey?.(accountIndex + 5);
const { path, policy } = await getTaprootExtendedPublicKey({
bitcoinApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { defaultWalletKeyId } from '@shared/utils';
import { ledgerRequestKeysRoutes } from '@app/features/ledger/generic-flows/request-keys/ledger-request-keys-route-generator';
import { LedgerRequestKeysContext } from '@app/features/ledger/generic-flows/request-keys/ledger-request-keys.context';
import { RequestKeysFlow } from '@app/features/ledger/generic-flows/request-keys/request-keys-flow';
import { useRequestLedgerKeys } from '@app/features/ledger/generic-flows/request-keys/use-request-ledger-keys';
import {
defaultNumberOfKeysToPullFromLedgerDevice,
useRequestLedgerKeys,
} from '@app/features/ledger/generic-flows/request-keys/use-request-ledger-keys';
import { useLedgerNavigate } from '@app/features/ledger/hooks/use-ledger-navigate';
import {
connectLedgerStacksApp,
Expand Down Expand Up @@ -42,7 +45,9 @@ function LedgerRequestStacksKeys() {
async pullKeysFromDevice(app) {
const resp = await pullStacksKeysFromLedgerDevice(app)({
onRequestKey(accountIndex) {
ledgerNavigate.toDeviceBusyStep(`Requesting STX addresses (${accountIndex + 1}…5)`);
ledgerNavigate.toDeviceBusyStep(
`Requesting STX addresses (${accountIndex + 1}…${defaultNumberOfKeysToPullFromLedgerDevice})`
);
},
});
if (resp.status === 'failure') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@shared/crypto/stacks/stacks.utils';
import { delay } from '@shared/utils';

import { defaultNumberOfKeysToPullFromLedgerDevice } from '../../generic-flows/request-keys/use-request-ledger-keys';
import {
StacksAppKeysResponseItem,
requestPublicKeyForStxAccount,
Expand Down Expand Up @@ -45,8 +46,8 @@ export function pullStacksKeysFromLedgerDevice(stacksApp: StacksApp) {
onRequestKey,
}: PullStacksKeysFromLedgerDeviceArgs): PullStacksKeysFromLedgerResponse => {
const publicKeys = [];
const amountOfKeysToExtractFromDevice = 5;
for (let index = 0; index < amountOfKeysToExtractFromDevice; index++) {

for (let index = 0; index < defaultNumberOfKeysToPullFromLedgerDevice; index++) {
if (onRequestKey) onRequestKey(index);
const stxPublicKeyResp = await requestPublicKeyForStxAccount(stacksApp)(index);
const dataPublicKeyResp = await requestPublicKeyForIdentityAccount(stacksApp)(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from '../../utils/generic-ledger-utils';
import { StacksAppVersion } from '../../utils/stacks-ledger-utils';

export const defaultNumberOfKeysToPullFromLedgerDevice = 10;

interface UseRequestLedgerKeysArgs<App extends BitcoinApp | StacksApp> {
chain: SupportedBlockchains;
isAppOpen({ name }: { name: string }): boolean;
Expand Down
Loading