From dfc7c392ca537361b04d0826a4918c3cb01a2b66 Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Wed, 6 Nov 2024 10:24:37 -0500 Subject: [PATCH] PSBT: BC-UR: use 'crypto-psbt' instead of 'bytes' formatting --- views/HandleAnythingQRScanner.tsx | 15 --------------- views/PSBT.tsx | 8 +++----- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/views/HandleAnythingQRScanner.tsx b/views/HandleAnythingQRScanner.tsx index 0e48526c8..78dfe5184 100644 --- a/views/HandleAnythingQRScanner.tsx +++ b/views/HandleAnythingQRScanner.tsx @@ -144,21 +144,6 @@ export default class HandleAnythingQRScanner extends React.Component< } 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(); diff --git a/views/PSBT.tsx b/views/PSBT.tsx index f4aeb0886..098278171 100644 --- a/views/PSBT.tsx +++ b/views/PSBT.tsx @@ -2,9 +2,9 @@ import * as React from 'react'; import { ScrollView, StyleSheet, Text, View } from 'react-native'; import { inject, observer } from 'mobx-react'; import { ButtonGroup } from 'react-native-elements'; -import { UR, UREncoder } from '@ngraveio/bc-ur'; import { Route } from '@react-navigation/native'; import { StackNavigationProp } from '@react-navigation/stack'; +import { CryptoPSBT } from '@keystonehq/bc-ur-registry'; const bitcoin = require('bitcoinjs-lib'); @@ -102,9 +102,6 @@ export default class PSBT extends React.Component { const messageBuffer = Buffer.from(fundedPsbt); - // First step is to create a UR object from a Buffer - const ur = UR.fromBuffer(messageBuffer); - // Then, create the UREncoder object // The maximum amount of fragments to be generated in total @@ -117,7 +114,8 @@ export default class PSBT extends React.Component { const firstSeqNum = 0; // Create the encoder object - const encoder = new UREncoder(ur, maxFragmentLength, firstSeqNum); + const cryptoPSBT = new CryptoPSBT(messageBuffer); + const encoder = cryptoPSBT.toUREncoder(maxFragmentLength, firstSeqNum); // this.setState({