Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes keystone vault registration failure #5797

Open
wants to merge 3 commits into
base: sprint
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions src/hardware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
line += `# ${isKeystone ? 'Keystone' : ''} Multisig setup file (exported from Keeper)\n`;
line += `#${isKeystone ? ' Keystone' : ''} Multisig setup file (exported from Keeper)\n`;

It currently has double space if it is not keystone.

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}: `;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here has a space and the normal otpion doesn't, is that space needed?

line += `${signer.xpub}\n`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here it's \n and in the normal it's double \n can you confirm this difference is necessary?

} else {
line += `Derivation:${signer.derivationPath.replaceAll('h', "'")}\n`;
line += `${signer.masterFingerprint}:`;
line += `${signer.xpub}\n\n`;
}
});
return line;
};
Expand Down
26 changes: 22 additions & 4 deletions src/screens/QRScreens/RegisterWithQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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', {
Expand Down Expand Up @@ -71,8 +85,12 @@ function RegisterWithQR({ route, navigation }: any) {
showsVerticalScrollIndicator={false}
>
<Box style={styles.center}>
{signer.type === SignerType.SPECTER ? (
<KeeperQRCode qrData={walletConfig} size={width * 0.85} ecl="L" />
{[SignerType.SPECTER, SignerType.KEYSTONE].includes(signer.type) ? (
<KeeperQRCode
qrData={signer.type == SignerType.KEYSTONE ? qrContents : walletConfig}
size={width * 0.85}
ecl="L"
/>
) : (
<DisplayQR qrContents={qrContents} toBytes type="hex" />
)}
Expand Down
1 change: 1 addition & 0 deletions src/screens/Vault/SigningDeviceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const SignersReqVault = [
SignerType.TREZOR,
SignerType.BITBOX02,
SignerType.PORTAL,
SignerType.KEYSTONE,
];

export const CHANGE_INDEX_THRESHOLD = 100;
Expand Down
2 changes: 1 addition & 1 deletion src/services/qr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading