From e2eb3f0f448f4e444a736dad7b23c12b8b7974bc Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Sun, 3 Nov 2024 23:06:40 -0500 Subject: [PATCH 1/2] LND: OpenChan: External funding: ensure outputs are passed for single chan --- stores/ChannelsStore.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stores/ChannelsStore.ts b/stores/ChannelsStore.ts index 54d2f75f0..7506bc03d 100644 --- a/stores/ChannelsStore.ts +++ b/stores/ChannelsStore.ts @@ -923,9 +923,13 @@ export default class ChannelsStore { }; BackendUtils.openChannelStream(request) .then((data: any) => { - const { pending_chan_id } = data.result; + const { psbt_fund, pending_chan_id } = data.result; this.pending_chan_ids.push(pending_chan_id); - this.handleChannelOpen(request); + if (psbt_fund?.funding_address) { + outputs[psbt_fund.funding_address] = + psbt_fund.funding_amount; + } + this.handleChannelOpen(request, outputs); }) .catch((error: Error) => { this.handleChannelOpenError(error); From 75f99958e2641710f371f6be136b25a4ca24519c Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Sun, 3 Nov 2024 23:09:09 -0500 Subject: [PATCH 2/2] BC-UR QR scanning: add bytes and crypto-psbt handling --- views/HandleAnythingQRScanner.tsx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/views/HandleAnythingQRScanner.tsx b/views/HandleAnythingQRScanner.tsx index 557ebc3be..0e48526c8 100644 --- a/views/HandleAnythingQRScanner.tsx +++ b/views/HandleAnythingQRScanner.tsx @@ -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'; @@ -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();