diff --git a/apps/frontend/src/pages/Setup/NewHardwareWalletScreen.tsx b/apps/frontend/src/pages/Setup/NewHardwareWalletScreen.tsx index 48db83fb..55984b57 100644 --- a/apps/frontend/src/pages/Setup/NewHardwareWalletScreen.tsx +++ b/apps/frontend/src/pages/Setup/NewHardwareWalletScreen.tsx @@ -34,7 +34,7 @@ import { PlatformContext, ConfigContext } from 'src/context'; import { HwiEnumerateResponse, - ColdcardElectrumExport, + ColdcardGenericJsonExport, File, AddressType, OnChainConfigWithoutId, @@ -240,28 +240,26 @@ const NewHardwareWalletScreen = ({ setStep, newAccount, setNewAccount }: Props) } }; - const importDeviceFromFile = (parsedFile: ColdcardElectrumExport) => { + const importDeviceFromFile = (parsedFile: ColdcardGenericJsonExport) => { try { - if (parsedFile.keystore.derivation !== "m/49'/0'/0'") { + // Assuming / Forcing P2WPKH + // TODO: provide more concise validation + if (parsedFile.bip84.name !== 'p2wpkh') { throw new Error('Invalid file'); } - const xpub = zpubToXpub(decode(parsedFile.keystore.xpub)); - const newDevice: HwiEnumerateWithXpubResponse = { - type: parsedFile.keystore.hw_type as HwiEnumerateWithXpubResponse['type'], - fingerprint: parsedFile.keystore.label.substring( - 'Coldcard Import '.length, - parsedFile.keystore.label.length - ), - xpub: xpub, + type: 'coldcard', + fingerprint: parsedFile.xfp, + xpub: parsedFile.bip84.xpub, model: 'unknown', path: 'unknown' }; const updatedImportedDevices = [...importedDevices, newDevice]; setImportedDevices(updatedImportedDevices); - setStep(3); + setPath(getP2wpkhDeriationPathForNetwork(currentBitcoinNetwork)); + setAddressType(AddressType.P2WPKH); } catch (e) { if (e instanceof Error) { openInModal(); diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 0ec1d10a..2bb28172 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -528,6 +528,57 @@ export interface ColdcardElectrumExport { seed_version: number; // 17 } +export interface ColdcardGenericJsonExport { + xpub: string; + xfp: string; + account: 0; + bip49: { + name: 'p2sh-p2wpkh'; + deriv: "m/49'/0'/0'"; + xpub: string; + xfp: string; + first: string; + _pub: string; + }; + bip44: { + name: 'p2pkh'; + deriv: "m/44'/0'/0'"; + xpub: string; + xfp: string; + first: string; + }; + bip84: { + name: 'p2wpkh'; + deriv: "m/84'/0'/0'"; + xpub: string; + xfp: string; + first: string; + _pub: string; + }; + bip48_2: { + name: 'p2wsh'; + deriv: "m/48'/0'/0'/2'"; + xpub: string; + xfp: string; + _pub: string; + }; + bip45: { + name: 'p2sh'; + deriv: "m/45'"; + xpub: string; + xfp: string; + _pub: string; + }; + chain: 'BTC'; + bip48_1: { + name: 'p2sh-p2wsh'; + deriv: "m/48'/0'/0'/1'"; + xpub: string; + xfp: string; + _pub: string; + }; +} + export interface ColdcardDeviceMultisigExportFile { p2sh_deriv: string; // m/45' p2sh: string; // xpub68ULYdfaSbytWGGNnutbcDLVyk3hyi3Tv5A8eftKDumTwTbRcT8u4QvZAWHRtqKMPb8serYEokayLLbicvwrar6TF1afmn3637v1Q6T2ZD