8000 feat(solana): scan Phantom paths by aeitwoen · Pull Request #437 · agntn/keys · GitHub
[go: up one dir, main page]

Skip to content
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
1 change: 1 addition & 0 deletions src/tool-operations/hd-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function bip39ScanSource(
ed25519: nodeWalker(getSLIP10MasterKey(seed)),
};
const curveOf = (scheme: ScanScheme): keyof typeof walkers => {
if (scheme.curve !== undefined) return scheme.curve;
if (scheme.addressType === "ed25519" || scheme.addressType === "secp256k1") {
return scheme.addressType;
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/hd-scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface ScanScheme {
readonly path: string;
/** Address type the wallet writes, or the Sui signature scheme. */
readonly addressType?: AddressType;
/** Curve the path walks when it isn't the chain' 8000 ;s, like Sollet feeding a BIP32 key to ed25519. */
readonly curve?: "secp256k1";
}

/** How far the scan walks each placeholder. */
Expand Down Expand Up @@ -131,6 +133,8 @@ const CHAIN_SCHEMES: Readonly<Record<string, readonly ScanScheme[]>> = {
solana: [
{ name: "bip44", path: "m/44'/501'/{index}'/0'" },
{ name: "bip44-account", path: "m/44'/501'/{index}'" },
{ name: "ledger-root", path: "m/44'/501'" },
{ name: "sollet", path: "m/501'/{index}'/0/0", curve: "secp256k1" },
],
stellar: [{ name: "sep5", path: "m/44'/148'/{index}'" }],
aptos: [{ name: "bip44", path: "m/44'/637'/{index}'/0'/0'" }],
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,14 @@ export const hdScanVectors = {
address: "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
path: "m/86'/0'/0'/0/0",
},
/** Ledger's root Solana address of the reference mnemonic, from qntx/kobe's vectors. */
solanaRoot: { address: "D2PPQSYFe83nDzk96FqGumVU8JA7J8vj2Rhjc2oXzEi5", path: "m/44'/501'" },
/** bip32 2.0.5 and tweetnacl 1.0.3 in incognitochain/incognito-extension-2.0's Sollet test. */
sollet: {
mnemonic: "iron language purpose cargo access peanut insane pencil still burst sing nurse",
address: "FTTRznSXjgQg8CxfvsgxbKCNTYCZ3m6kNVTxaXyj2zNC",
path: "m/501'/0'/0/0",
},
} as const;

/** Entropy that means something. Digests from coreutils `md5sum`, `sha1sum` and `sha256sum`. */
Expand Down
10 changes: 9 additions & 1 deletion test/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,13 @@ describe("keys MCP server", () => {
expect(await scan({ chain: "solana", mnemonic: reference, address: solana.address })).toContain(
`Path: ${solana.path}`,
);
const { solanaRoot, sollet } = hdScanVectors;
expect(
await scan({ chain: "solana", mnemonic: reference, address: solanaRoot.address }),
).toContain(`Match: ledger-root, 41 addresses checked\nPath: ${solanaRoot.path}`);
expect(
await scan({ chain: "solana", mnemonic: sollet.mnemonic, address: sollet.address }),
).toContain(`Match: sollet, 42 addresses checked\nPath: ${sollet.path}`);
for (const [path, scheme] of [
["m/44'/60'/3'/0/0", "ledger-live"],
["m/44'/60'/0'/4", "ledger-legacy"],
Expand Down Expand Up @@ -1634,7 +1641,7 @@ describe("keys MCP server", () => {
).toContain("Warning: BIP39 checksum is invalid.");
}, 15_000);

/* On testnet only the `-testnet` schemes write anything mainnet does not already cover. */
/* Only `-testnet` schemes add paths on testnet; a scheme on a foreign curve has no derive. */
it.each(TOOL_CHAINS.filter((chain) => scanSchemes(chain, { network: "mainnet" }) !== undefined))(
"reaches the address keys_hd_wallet_derive gives on every %s scheme",
async (chain) => {
Expand All @@ -1643,6 +1650,7 @@ describe("keys MCP server", () => {
const schemes = TOOL_NETWORKS.flatMap((network) =>
(scanSchemes(chain, { network }) ?? [])
.filter((scheme) => network === "mainnet" || scheme.name.endsWith("-testnet"))
.filter((scheme) => scheme.curve === undefined)
.map((scheme) => ({ network, scheme })),
);
for (const { network, scheme } of schemes) {
Expand Down
Loading
0