diff --git a/src/hardware/index.ts b/src/hardware/index.ts index ff9eef2a2..062956a95 100644 --- a/src/hardware/index.ts +++ b/src/hardware/index.ts @@ -209,16 +209,26 @@ export const getSignerNameFromType = (type: SignerType, isMock = false, isAmf = return name; }; -export const getWalletConfig = ({ vault }: { vault: Vault }) => { - let line = '# Multisig setup file (exported from Keeper)\n'; +export const getWalletConfig = ({ vault, signerType }: { vault: Vault; signerType?: string }) => { + const isKeystone = signerType === SignerType.KEYSTONE; + let line = ''; + if (isKeystone) line += 'Y q'; + line += `#${isKeystone ? ' Keystone' : ''} Multisig setup file (exported from Keeper)\n`; + if (isKeystone) line += '#\n'; line += `Name: ${vault.presentationData.name}\n`; line += `Policy: ${vault.scheme.m} of ${vault.scheme.n}\n`; + if (isKeystone) line += `Derivation: ${vault.signers[0].derivationPath.replaceAll('h', "'")}\n`; line += 'Format: P2WSH\n'; line += '\n'; vault.signers.forEach((signer) => { - line += `Derivation:${signer.derivationPath.replaceAll('h', "'")}\n`; - line += `${signer.masterFingerprint}:`; - line += `${signer.xpub}\n\n`; + if (isKeystone) { + line += `${signer.masterFingerprint}: `; + line += `${signer.xpub}\n`; + } else { + line += `Derivation:${signer.derivationPath.replaceAll('h', "'")}\n`; + line += `${signer.masterFingerprint}:`; + line += `${signer.xpub}\n`; + } }); return line; }; diff --git a/src/screens/QRScreens/RegisterWithQR.tsx b/src/screens/QRScreens/RegisterWithQR.tsx index 18ae62dbe..3e6a6d74d 100644 --- a/src/screens/QRScreens/RegisterWithQR.tsx +++ b/src/screens/QRScreens/RegisterWithQR.tsx @@ -19,6 +19,8 @@ import KeeperQRCode from 'src/components/KeeperQRCode'; import useToastMessage from 'src/hooks/useToastMessage'; import TickIcon from 'src/assets/images/icon_tick.svg'; import ShareWithNfc from '../NFCChannel/ShareWithNfc'; +import { UR, UREncoder } from '@ngraveio/bc-ur'; +import { getFragmentedData } from 'src/services/qr'; const { width } = Dimensions.get('window'); @@ -36,10 +38,22 @@ function RegisterWithQR({ route, navigation }: any) { '/<0;1>/*', '' )}${activeVault.isMultiSig ? ' )' : ''}` - : getWalletConfig({ vault: activeVault }); - const qrContents = Buffer.from(walletConfig, 'ascii').toString('hex'); + : getWalletConfig({ vault: activeVault, signerType: signer.type }); + let qrContents: any = Buffer.from(walletConfig, 'ascii').toString('hex'); const { showToast } = useToastMessage(); + try { + if (signer.type === SignerType.KEYSTONE) { + const messageBuffer = Buffer.from(walletConfig); + const ur = UR.fromBuffer(messageBuffer); + const maxFragmentLength = 1000; + const encoder = new UREncoder(ur, maxFragmentLength); + qrContents = getFragmentedData(encoder).toString().toUpperCase(); + } + } catch (error) { + console.log('🚀 ~ RegisterWithQR ~ error:', error); + } + const markAsRegistered = () => { dispatch( updateKeyDetails(vaultKey, 'registered', { @@ -71,8 +85,12 @@ function RegisterWithQR({ route, navigation }: any) { showsVerticalScrollIndicator={false} > - {signer.type === SignerType.SPECTER ? ( - + {[SignerType.SPECTER, SignerType.KEYSTONE].includes(signer.type) ? ( + ) : ( )} diff --git a/src/screens/Vault/SigningDeviceDetails.tsx b/src/screens/Vault/SigningDeviceDetails.tsx index 1e80eb490..34c001430 100644 --- a/src/screens/Vault/SigningDeviceDetails.tsx +++ b/src/screens/Vault/SigningDeviceDetails.tsx @@ -87,6 +87,7 @@ export const SignersReqVault = [ SignerType.TREZOR, SignerType.BITBOX02, SignerType.PORTAL, + SignerType.KEYSTONE, ]; export const CHANGE_INDEX_THRESHOLD = 100; diff --git a/src/services/qr/index.ts b/src/services/qr/index.ts index 9e3e61f18..d6b792556 100644 --- a/src/services/qr/index.ts +++ b/src/services/qr/index.ts @@ -82,7 +82,7 @@ export const encodeBytesUR = (data, rotation, type: BufferEncoding = 'hex') => { return [data]; }; -const getFragmentedData = (encoder) => { +export const getFragmentedData = (encoder) => { const fragments = []; for (let c = 1; c <= encoder.fragmentsLength; c++) { const ur = encoder.nextPart();