1
1
import { EmitterSubscription } from 'react-native' ;
2
2
import Keychain from '@synonymdev/react-native-keychain' ;
3
3
import * as bitcoin from 'bitcoinjs-lib' ;
4
+ import ecc from '@bitcoinerlab/secp256k1' ;
4
5
import RNFS from 'react-native-fs' ;
5
6
import { err , ok , Result } from '@synonymdev/result' ;
6
7
import { EPaymentType , TGetAddressHistory } from 'beignet' ;
@@ -1039,6 +1040,23 @@ export const parseUri = (
1039
1040
return ok ( { publicKey, ip, port } ) ;
1040
1041
} ;
1041
1042
1043
+ const isValidLightningNodePublicKey = ( pubkey : string ) : boolean => {
1044
+ const pubkeyBytes = new Uint8Array ( Buffer . from ( pubkey , 'hex' ) ) ;
1045
+ if ( pubkeyBytes . length !== 33 ) {
1046
+ return false ;
1047
+ }
1048
+
1049
+ if ( ! ecc . isPoint ( pubkeyBytes ) ) {
1050
+ return false ;
1051
+ }
1052
+
1053
+ if ( ! ecc . isPointCompressed ( pubkeyBytes ) ) {
1054
+ return false ;
1055
+ }
1056
+
1057
+ return true ;
1058
+ } ;
1059
+
1042
1060
/**
1043
1061
* Prompt LDK to add a specified peer.
1044
1062
* @param {string } peer
@@ -1056,6 +1074,10 @@ export const addPeer = async ({
1056
1074
return err ( parsedUri . error . message ) ;
1057
1075
}
1058
1076
1077
+ if ( ! isValidLightningNodePublicKey ( parsedUri . value . publicKey ) ) {
1078
+ return err ( i18n . t ( 'lightning:error_add_msg' ) ) ;
1079
+ }
1080
+
1059
1081
const res = await lm . addPeer ( {
1060
1082
pubKey : parsedUri . value . publicKey ,
1061
1083
address : parsedUri . value . ip ,
0 commit comments