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

PSBT: BC-UR: use 'crypto-psbt' instead of 'bytes' formatting #2519

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
15 changes: 0 additions & 15 deletions views/HandleAnythingQRScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions views/PSBT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -102,9 +102,6 @@ export default class PSBT extends React.Component<PSBTProps, PSBTState> {

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
Expand All @@ -117,7 +114,8 @@ export default class PSBT extends React.Component<PSBTProps, PSBTState> {
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({
Expand Down
Loading