@galoymoney/client
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -70,5 +70,14 @@ import bolt11 from "bolt11"; | ||
}; | ||
export declare const InvalidIntraledgerReason: { | ||
readonly WrongDomain: "WrongDomain"; | ||
}; | ||
export type InvalidIntraledgerReason = (typeof InvalidIntraledgerReason)[keyof typeof InvalidIntraledgerReason]; | ||
export type IntraledgerPaymentDestination = { | ||
valid: true; | ||
paymentType: typeof PaymentType.Intraledger; | ||
handle: string; | ||
} | { | ||
paymentType: typeof PaymentType.Intraledger; | ||
valid: false; | ||
invalidReason: InvalidIntraledgerReason; | ||
}; | ||
@@ -75,0 +84,0 @@ export type ParsedPaymentDestination = UnknownPaymentDestination | NullInputPaymentDestination | LnurlPaymentDestination | LightningPaymentDestination | OnchainPaymentDestination | IntraledgerPaymentDestination; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parsePaymentDestination = exports.decodeInvoiceString = exports.getLightningInvoiceExpiryTime = exports.lightningInvoiceHasExpired = exports.InvalidOnchainDestinationReason = exports.InvalidLightningDestinationReason = exports.InvalidLnurlPaymentDestinationReason = exports.PaymentType = exports.getHashFromInvoice = exports.getDestination = exports.getDescription = exports.parseBolt11Network = void 0; | ||
exports.parsePaymentDestination = exports.decodeInvoiceString = exports.getLightningInvoiceExpiryTime = exports.lightningInvoiceHasExpired = exports.InvalidIntraledgerReason = exports.InvalidOnchainDestinationReason = exports.InvalidLightningDestinationReason = exports.InvalidLnurlPaymentDestinationReason = exports.PaymentType = exports.getHashFromInvoice = exports.getDestination = exports.getDescription = exports.parseBolt11Network = void 0; | ||
/* eslint-disable max-lines */ | ||
@@ -124,2 +124,5 @@ var bolt11_1 = __importDefault(require("bolt11")); | ||
}; | ||
exports.InvalidIntraledgerReason = { | ||
WrongDomain: "WrongDomain", | ||
}; | ||
var lightningInvoiceHasExpired = function (payReq) { | ||
@@ -194,3 +197,3 @@ return Boolean((payReq === null || payReq === void 0 ? void 0 : payReq.timeExpireDate) && payReq.timeExpireDate < Date.now() / 1000); | ||
var getIntraLedgerPayResponse = function (_a) { | ||
var protocol = _a.protocol, destinationWithoutProtocol = _a.destinationWithoutProtocol; | ||
var protocol = _a.protocol, destinationWithoutProtocol = _a.destinationWithoutProtocol, destination = _a.destination, lnAddressDomains = _a.lnAddressDomains; | ||
var paymentType = exports.PaymentType.Intraledger; | ||
@@ -200,4 +203,15 @@ var handle = protocol.match(/^(http|\/\/)/iu) | ||
: destinationWithoutProtocol; | ||
if (protocol.match(/^(http|\/\/)/iu)) { | ||
var domain_1 = new url_1.default.URL(destination).hostname; | ||
if (!lnAddressDomains.find(function (lnAddressDomain) { return lnAddressDomain === domain_1; })) { | ||
return { | ||
valid: false, | ||
paymentType: paymentType, | ||
invalidReason: exports.InvalidIntraledgerReason.WrongDomain, | ||
}; | ||
} | ||
} | ||
if (handle === null || handle === void 0 ? void 0 : handle.match(/(?!^(1|3|bc1|lnbc1))^[0-9a-z_]{3,50}$/iu)) { | ||
return { | ||
valid: true, | ||
paymentType: paymentType, | ||
@@ -216,7 +230,9 @@ handle: handle, | ||
if (lnAddress) { | ||
var username = lnAddress.username, domain_1 = lnAddress.domain; | ||
if (lnAddressDomains.find(function (lnAddressDomain) { return lnAddressDomain === domain_1; })) { | ||
var username = lnAddress.username, domain_2 = lnAddress.domain; | ||
if (lnAddressDomains.find(function (lnAddressDomain) { return lnAddressDomain === domain_2; })) { | ||
return getIntraLedgerPayResponse({ | ||
protocol: "", | ||
destinationWithoutProtocol: username, | ||
lnAddressDomains: lnAddressDomains, | ||
destination: destination, | ||
}); | ||
@@ -227,3 +243,3 @@ } | ||
paymentType: exports.PaymentType.Lnurl, | ||
lnurl: "".concat(username, "@").concat(domain_1), | ||
lnurl: "".concat(username, "@").concat(domain_2), | ||
}; | ||
@@ -377,3 +393,8 @@ } | ||
case exports.PaymentType.Intraledger: | ||
return getIntraLedgerPayResponse({ protocol: protocol, destinationWithoutProtocol: destinationWithoutProtocol }); | ||
return getIntraLedgerPayResponse({ | ||
protocol: protocol, | ||
destinationWithoutProtocol: destinationWithoutProtocol, | ||
destination: destination, | ||
lnAddressDomains: lnAddressDomains, | ||
}); | ||
case exports.PaymentType.Unified: | ||
@@ -380,0 +401,0 @@ return getUnifiedPayResponse({ |
{ | ||
"name": "@galoymoney/client", | ||
"main": "dist/index.js", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/galoymoney/galoy-client", |
67961
787