Skip to content
Merged
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
16 changes: 16 additions & 0 deletions test/helpers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,29 @@ export async function getAddressFromQRCode(which: addressType): Promise<string>
let address = '';
if (which === 'bitcoin') {
address = uri.replace(/^bitcoin:/, '').replace(/\?.*$/, '');
// Accept Bech32 HRPs across networks: mainnet (bc1), testnet/signet (tb1), regtest (bcrt1)
const allowedBitcoinHrp = ['bc1', 'tb1', 'bcrt1'];
const addrLower = address.toLowerCase();
if (!allowedBitcoinHrp.some((p) => addrLower.startsWith(p))) {
throw new Error(
`Invalid Bitcoin address HRP: ${address}. Expected one of: ${allowedBitcoinHrp.join(', ')}`
);
}
} else if (which === 'lightning') {
const query = uri.split('?')[1] ?? '';
const params = new URLSearchParams(query);
const ln = params.get('lightning');
if (!ln) {
throw new Error(`No lightning invoice found in uri: ${uri}`);
}
// Accept BOLT11 HRPs across networks: mainnet (lnbc), testnet (lntb), signet (lntbs), regtest (lnbcrt)
const allowedLightningHrp = ['lnbc', 'lntb', 'lntbs', 'lnbcrt'];
const lnLower = ln.toLowerCase();
if (!allowedLightningHrp.some((p) => lnLower.startsWith(p))) {
throw new Error(
`Invalid lightning invoice HRP: ${ln}. Expected one of: ${allowedLightningHrp.join(', ')}`
);
}
address = ln;
} else {
throw new Error(`Unknown address type: ${which}`);
Expand Down