Skip to content
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
14 changes: 4 additions & 10 deletions modules/sdk-core/src/coins/ofcToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SignedTransaction,
ITransactionRecipient,
} from '../';
import { isBolt11Invoice, LIGHTNING_INVOICE } from '../lightning';
import { isBolt11Invoice } from '../lightning';

import { Ofc } from './ofc';

Expand Down Expand Up @@ -76,25 +76,19 @@ export class OfcToken extends Ofc {
throw new Error(`invalid argument - lightning invoice is only supported for bitcoin`);
}

// amount for bolt11 invoices is either 'invoice' or a non-zero bigint
if (recipient.amount === LIGHTNING_INVOICE) {
return;
}
// try to parse the amount as a bigint
// amount for bolt11 invoices must be a non-zero bigint
let amount: bigint;
try {
amount = BigInt(recipient.amount);
} catch (e) {
throw new Error(
`invalid argument ${recipient.amount} for amount - lightning invoice amount must be >= 0 or ${LIGHTNING_INVOICE}`
`invalid argument ${recipient.amount} for amount - lightning invoice amount must be a non-zero bigint`
);
}
if (amount > 0n) {
return;
}
throw new Error(
`invalid argument for amount - lightning invoice amount must be a non-zero bigint or ${LIGHTNING_INVOICE}`
);
throw new Error(`invalid argument for amount - lightning invoice amount must be a non-zero bigint`);
}

super.checkRecipient(recipient);
Expand Down
2 changes: 0 additions & 2 deletions modules/sdk-core/src/lightning.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const LIGHTNING_INVOICE = 'invoice';

export function isBolt11Invoice(value: unknown): value is string {
if (typeof value !== 'string') {
return false;
Expand Down
Loading