Skip to content

Commit

Permalink
BC-UR QR scanning: add bytes and crypto-psbt handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Nov 4, 2024
1 parent e2eb3f0 commit 75f9995
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion views/HandleAnythingQRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Header } from 'react-native-elements';
import { observer } from 'mobx-react';
import { URDecoder } from '@ngraveio/bc-ur';
import { StackNavigationProp } from '@react-navigation/stack';
import { CryptoAccount } from '@keystonehq/bc-ur-registry';
import { Bytes, CryptoAccount, CryptoPSBT } from '@keystonehq/bc-ur-registry';

import LoadingIndicator from '../components/LoadingIndicator';
import QRCodeScanner from '../components/QRCodeScanner';
Expand Down Expand Up @@ -137,6 +137,28 @@ export default class HandleAnythingQRScanner extends React.Component<
e
);
}
} else if (ur._type === 'crypto-psbt') {
const data = CryptoPSBT.fromCBOR(ur._cborPayload);
const psbt = data.getPSBT();
handleData = Buffer.from(psbt).toString('base64');
} else if (ur._type === 'bytes') {
const data = Bytes.fromCBOR(ur._cborPayload);
handleData = Buffer.from(data.getData()).toString();

// TODO
// For some reason the cH starting byte from Base64-encoded
// PSBTs is being replaced with a linebreak
if (
handleData.includes('NidP8BA') &&
(handleData.startsWith('\r\n') ||
handleData.startsWith('\n') ||
handleData.startsWith('\r'))
) {
handleData = handleData.replace(
/(\r\n|\n|\r)/gm,
'cH'
);
}
} else {
// Decode the CBOR message to a Buffer
const decoded = ur.decodeCBOR();
Expand Down

0 comments on commit 75f9995

Please sign in to comment.