Skip to content

Commit e264126

Browse files
CP-12568: Filter out new derivation path (#3356)
1 parent 3892a7b commit e264126

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/core-mobile/app/new/features/ledger/consts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export const SOLANA_DERIVATION_PATH = "44'/501'/0'/0'/0"
3131
// Solana derivation path prefix for generating indexed paths
3232
export const SOLANA_DERIVATION_PATH_PREFIX = "44'/501'/0'/0'"
3333

34+
// Deprecated Avalanche public key path prefix
35+
export const DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX = "m/44'/9000'/0'"
36+
3437
/**
3538
* Generate a Solana derivation path for a specific account index
3639
* @param accountIndex - The account index to generate the path for

packages/core-mobile/app/seedless/services/transformKeyInfosToPubkeys.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cs from '@cubist-labs/cubesigner-sdk'
22
import { strip0x } from '@avalabs/core-utils-sdk'
33
import { AddressPublicKey, Curve } from 'utils/publicKeys'
4+
import { DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX } from 'features/ledger/consts'
45

56
export const transformKeyInfosToPubKeys = (
67
keyInfos: cs.KeyInfo[]
@@ -9,7 +10,23 @@ export const transformKeyInfosToPubKeys = (
910
const requiredKeyTypes: cs.KeyTypeApi[] = [cs.Secp256k1.Evm, cs.Secp256k1.Ava]
1011
const optionalKeyTypes: cs.KeyTypeApi[] = [cs.Ed25519.Solana]
1112
const allowedKeyTypes = [...requiredKeyTypes, ...optionalKeyTypes]
12-
const keys = keyInfos
13+
14+
// we are migrating to the new account model with new derivation path spec for Ava and AvaTest: m/44'/${coinIndex}'/${accountIndex}'/0/0
15+
// in the backend, we are returning the keys with new spec and existing spec for backward compatibility,
16+
// to prepare for this change, we need to filter out the keys with new spec to avoid getting the wrong derivation path
17+
const filteredKeyInfos = keyInfos?.filter(k => {
18+
if (
19+
k.key_type === cs.Secp256k1.Ava ||
20+
k.key_type === cs.Secp256k1.AvaTest
21+
) {
22+
return k.derivation_info?.derivation_path?.startsWith(
23+
DEPRECATED_AVALANCHE_DERIVATION_PATH_PREFIX
24+
)
25+
}
26+
return true
27+
})
28+
29+
const keys = filteredKeyInfos
1330
?.filter(
1431
k =>
1532
k.enabled &&

0 commit comments

Comments
 (0)