Skip to content

Commit

Permalink
fix: change default to pulling 10 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed May 8, 2024
1 parent 7a89337 commit b5c9c79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
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

0 comments on commit b5c9c79

Please sign in to comment.