@galoymoney/client
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -10,2 +10,3 @@ import bolt11 from "bolt11"; | ||
readonly Intraledger: "intraledger"; | ||
readonly IntraledgerWithFlag: "intraledgerWithFlag"; | ||
readonly Onchain: "onchain"; | ||
@@ -72,5 +73,9 @@ readonly Lnurl: "lnurl"; | ||
}; | ||
export declare const IntraledgerFlag: { | ||
readonly Usd: "usd"; | ||
}; | ||
export declare const InvalidIntraledgerReason: { | ||
readonly WrongDomain: "WrongDomain"; | ||
}; | ||
export type IntraledgerFlag = (typeof IntraledgerFlag)[keyof typeof IntraledgerFlag]; | ||
export type InvalidIntraledgerReason = (typeof InvalidIntraledgerReason)[keyof typeof InvalidIntraledgerReason]; | ||
@@ -82,2 +87,7 @@ export type IntraledgerPaymentDestination = { | ||
} | { | ||
valid: true; | ||
paymentType: typeof PaymentType.IntraledgerWithFlag; | ||
handle: string; | ||
flag: IntraledgerFlag; | ||
} | { | ||
valid: false; | ||
@@ -84,0 +94,0 @@ paymentType: typeof PaymentType.Intraledger; |
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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; | ||
exports.parsePaymentDestination = exports.decodeInvoiceString = exports.getLightningInvoiceExpiryTime = exports.lightningInvoiceHasExpired = exports.InvalidIntraledgerReason = exports.IntraledgerFlag = exports.InvalidOnchainDestinationReason = exports.InvalidLightningDestinationReason = exports.InvalidLnurlPaymentDestinationReason = exports.PaymentType = exports.getHashFromInvoice = exports.getDestination = exports.getDescription = exports.parseBolt11Network = void 0; | ||
/* eslint-disable max-lines */ | ||
@@ -106,2 +106,3 @@ var bolt11_1 = __importDefault(require("bolt11")); | ||
Intraledger: "intraledger", | ||
IntraledgerWithFlag: "intraledgerWithFlag", | ||
Onchain: "onchain", | ||
@@ -126,2 +127,5 @@ Lnurl: "lnurl", | ||
}; | ||
exports.IntraledgerFlag = { | ||
Usd: "usd", | ||
}; | ||
exports.InvalidIntraledgerReason = { | ||
@@ -142,2 +146,3 @@ WrongDomain: "WrongDomain", | ||
exports.decodeInvoiceString = decodeInvoiceString; | ||
var reUsername = /(?!^(1|3|bc1|lnbc1))^[0-9a-z_]{3,50}$/iu; | ||
// from https://github.com/bitcoin/bips/blob/master/bip-0020.mediawiki#Transfer%20amount/size | ||
@@ -207,10 +212,16 @@ var reAmount = /^(([\d.]+)(X(\d+))?|x([\da-f]*)(\.([\da-f]*))?(X([\da-f]+))?)$/iu; | ||
: destinationWithoutProtocol; | ||
if (handle === null || handle === void 0 ? void 0 : handle.match(/(?!^(1|3|bc1|lnbc1))^[0-9a-z_]{3,50}$/iu)) { | ||
if (handle === null || handle === void 0 ? void 0 : handle.match(reUsername)) { | ||
return exports.PaymentType.Intraledger; | ||
} | ||
var handleAndFlag = handle === null || handle === void 0 ? void 0 : handle.split("+"); | ||
if ((handleAndFlag === null || handleAndFlag === void 0 ? void 0 : handleAndFlag.length) === 2 && | ||
handleAndFlag[0].match(reUsername) && | ||
Object.values(exports.IntraledgerFlag).includes(handleAndFlag[1].toLowerCase())) { | ||
return exports.PaymentType.IntraledgerWithFlag; | ||
} | ||
return exports.PaymentType.Unknown; | ||
}; | ||
var getIntraLedgerPayResponse = function (_a) { | ||
var _b; | ||
var destinationWithoutProtocol = _a.destinationWithoutProtocol, destination = _a.destination, lnAddressDomains = _a.lnAddressDomains; | ||
var paymentType = exports.PaymentType.Intraledger; | ||
var handle = destinationWithoutProtocol.match(/^(http|\/\/)/iu) | ||
@@ -224,3 +235,3 @@ ? destinationWithoutProtocol.split("/")[destinationWithoutProtocol.split("/").length - 1] | ||
valid: false, | ||
paymentType: paymentType, | ||
paymentType: exports.PaymentType.Intraledger, | ||
handle: handle, | ||
@@ -231,9 +242,21 @@ invalidReason: exports.InvalidIntraledgerReason.WrongDomain, | ||
} | ||
if (handle === null || handle === void 0 ? void 0 : handle.match(/(?!^(1|3|bc1|lnbc1))^[0-9a-z_]{3,50}$/iu)) { | ||
if (handle === null || handle === void 0 ? void 0 : handle.match(reUsername)) { | ||
return { | ||
valid: true, | ||
paymentType: paymentType, | ||
paymentType: exports.PaymentType.Intraledger, | ||
handle: handle, | ||
}; | ||
} | ||
var handleAndFlag = handle === null || handle === void 0 ? void 0 : handle.split("+"); | ||
var flag = (_b = handleAndFlag[1]) === null || _b === void 0 ? void 0 : _b.toLowerCase(); | ||
if ((handleAndFlag === null || handleAndFlag === void 0 ? void 0 : handleAndFlag.length) === 2 && | ||
handleAndFlag[0].match(reUsername) && | ||
flag === exports.IntraledgerFlag.Usd) { | ||
return { | ||
valid: true, | ||
paymentType: exports.PaymentType.IntraledgerWithFlag, | ||
handle: handleAndFlag[0], | ||
flag: flag, | ||
}; | ||
} | ||
return { | ||
@@ -409,2 +432,3 @@ valid: false, | ||
case exports.PaymentType.Intraledger: | ||
case exports.PaymentType.IntraledgerWithFlag: | ||
return getIntraLedgerPayResponse({ | ||
@@ -411,0 +435,0 @@ destinationWithoutProtocol: destinationWithoutProtocol, |
{ | ||
"name": "@galoymoney/client", | ||
"main": "dist/index.js", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/galoymoney/galoy-client", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63644
735