@galoymoney/client
Advanced tools
Comparing version 0.1.54 to 0.1.55
import { LnUrlPayServiceArgs, LnUrlPayServiceResponse, LnUrlRequestInvoiceArgs, LnUrlRequestInvoiceResponse } from "lnurl-pay/dist/types/types"; | ||
import { Network } from "../parsing-v2"; | ||
declare type isLnurlPaymentSameNodeArgs = { | ||
lnUrlOrAddress: string; | ||
ourNode: string; | ||
network: Network; | ||
}; | ||
export declare const fetchLnurlPaymentParams: ({ lnUrlOrAddress, onionAllowed, fetchGet, }: LnUrlPayServiceArgs) => Promise<LnUrlPayServiceResponse>; | ||
export declare const fetchLnurlInvoice: ({ lnUrlOrAddress, tokens, comment, fetchGet, onionAllowed, }: LnUrlRequestInvoiceArgs) => Promise<LnUrlRequestInvoiceResponse>; | ||
export declare const isLnurlPaymentSameNode: ({ lnUrlOrAddress, ourNode, }: isLnurlPaymentSameNodeArgs) => Promise<boolean>; | ||
export declare const isLnurlPaymentSameNode: ({ lnUrlOrAddress, ourNode, network, }: isLnurlPaymentSameNodeArgs) => Promise<boolean>; | ||
export {}; |
@@ -46,2 +46,3 @@ "use strict"; | ||
var bolt11_1 = __importDefault(require("bolt11")); | ||
var parsing_v2_1 = require("../parsing-v2"); | ||
var fetchLnurlPaymentParams = function (_a) { | ||
@@ -72,3 +73,3 @@ var lnUrlOrAddress = _a.lnUrlOrAddress, _b = _a.onionAllowed, onionAllowed = _b === void 0 ? false : _b, fetchGet = _a.fetchGet; | ||
var isLnurlPaymentSameNode = function (_a) { | ||
var lnUrlOrAddress = _a.lnUrlOrAddress, ourNode = _a.ourNode; | ||
var lnUrlOrAddress = _a.lnUrlOrAddress, ourNode = _a.ourNode, network = _a.network; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -84,3 +85,3 @@ var invoice, decoded; | ||
invoice = (_b.sent()).invoice; | ||
decoded = bolt11_1.default.decode(invoice); | ||
decoded = bolt11_1.default.decode(invoice, (0, parsing_v2_1.parseBolt11Network)(network)); | ||
return [2 /*return*/, ourNode === (0, parsing_1.getDestination)(decoded)]; | ||
@@ -87,0 +88,0 @@ } |
import bolt11 from "bolt11"; | ||
export declare type Network = "mainnet" | "signet" | "regtest"; | ||
export declare const parseBolt11Network: (network: string) => bolt11.Network; | ||
export declare const getDescription: (decoded: bolt11.PaymentRequestObject) => string | undefined; | ||
export declare const getDestination: (decoded: bolt11.PaymentRequestObject) => string | undefined; | ||
export declare const getHashFromInvoice: (invoice: string) => string | undefined; | ||
export declare type Network = "mainnet" | "signet" | "regtest"; | ||
export declare const getHashFromInvoice: (invoice: string, network: Network) => string | undefined; | ||
export declare enum PaymentType { | ||
@@ -68,3 +69,3 @@ Lightning = "lightning", | ||
export declare const getLightningInvoiceExpiryTime: (payReq: bolt11.PaymentRequestObject) => number; | ||
export declare const decodeInvoiceString: (invoice: string) => bolt11.PaymentRequestObject; | ||
export declare const decodeInvoiceString: (invoice: string, network: Network) => bolt11.PaymentRequestObject; | ||
declare type ParsePaymentDestinationArgs = { | ||
@@ -71,0 +72,0 @@ destination: string; |
@@ -6,3 +6,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 = void 0; | ||
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; | ||
var bolt11_1 = __importDefault(require("bolt11")); | ||
@@ -12,3 +12,3 @@ var url_1 = __importDefault(require("url")); | ||
var lnurl_pay_1 = require("lnurl-pay"); | ||
var parseNetwork = function (network) { | ||
var parseBitcoinJsNetwork = function (network) { | ||
if (network === "mainnet") { | ||
@@ -25,2 +25,37 @@ return bitcoinjs_lib_1.networks.bitcoin; | ||
}; | ||
// This is a hack to get around the fact that bolt11 doesn't support signet | ||
var parseBolt11Network = function (network) { | ||
if (network === "mainnet") { | ||
return { | ||
bech32: "bc", | ||
pubKeyHash: 0x00, | ||
scriptHash: 0x05, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
else if (network === "signet") { | ||
return { | ||
bech32: "tb", | ||
pubKeyHash: 0x6f, | ||
scriptHash: 0xc4, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
else if (network === "regtest") { | ||
return { | ||
bech32: "bcrt", | ||
pubKeyHash: 0x6f, | ||
scriptHash: 0xc4, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
return { | ||
// default network is bitcoin | ||
bech32: "bc", | ||
pubKeyHash: 0x00, | ||
scriptHash: 0x05, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
}; | ||
exports.parseBolt11Network = parseBolt11Network; | ||
var getDescription = function (decoded) { | ||
@@ -36,5 +71,5 @@ var _a; | ||
exports.getDestination = getDestination; | ||
var getHashFromInvoice = function (invoice) { | ||
var getHashFromInvoice = function (invoice, network) { | ||
var _a; | ||
var decoded = bolt11_1.default.decode(invoice); | ||
var decoded = bolt11_1.default.decode(invoice, (0, exports.parseBolt11Network)(network)); | ||
var data = (_a = decoded.tags.find(function (value) { return value.tagName === "payment_hash"; })) === null || _a === void 0 ? void 0 : _a.data; | ||
@@ -78,4 +113,4 @@ if (data) { | ||
exports.getLightningInvoiceExpiryTime = getLightningInvoiceExpiryTime; | ||
var decodeInvoiceString = function (invoice) { | ||
return bolt11_1.default.decode(invoice); | ||
var decodeInvoiceString = function (invoice, network) { | ||
return bolt11_1.default.decode(invoice, (0, exports.parseBolt11Network)(network)); | ||
}; | ||
@@ -199,3 +234,3 @@ exports.decodeInvoiceString = decodeInvoiceString; | ||
try { | ||
payReq = bolt11_1.default.decode(lnProtocol); | ||
payReq = bolt11_1.default.decode(lnProtocol, (0, exports.parseBolt11Network)(network)); | ||
} | ||
@@ -256,3 +291,3 @@ catch (err) { | ||
// will throw if address is not valid | ||
bitcoinjs_lib_1.address.toOutputScript(path, parseNetwork(network)); | ||
bitcoinjs_lib_1.address.toOutputScript(path, parseBitcoinJsNetwork(network)); | ||
return { | ||
@@ -259,0 +294,0 @@ valid: true, |
import bolt11 from "bolt11"; | ||
export declare const getDescription: (decoded: bolt11.PaymentRequestObject) => string | undefined; | ||
export declare const getDestination: (decoded: bolt11.PaymentRequestObject) => string | undefined; | ||
export declare const getHashFromInvoice: (invoice: string) => string | undefined; | ||
export declare const getHashFromInvoice: (invoice: string, network?: bolt11.Network) => string | undefined; | ||
export declare type Network = "mainnet" | "signet" | "regtest"; | ||
@@ -21,3 +21,3 @@ export declare type PaymentType = "lightning" | "onchain" | "intraledger" | "lnurl"; | ||
export declare const getLightningInvoiceExpiryTime: (payReq: bolt11.PaymentRequestObject) => number; | ||
export declare const decodeInvoiceString: (invoice: string) => bolt11.PaymentRequestObject; | ||
export declare const decodeInvoiceString: (invoice: string, network?: bolt11.Network) => bolt11.PaymentRequestObject; | ||
declare type ParsePaymentDestinationArgs = { | ||
@@ -24,0 +24,0 @@ destination: string; |
@@ -11,3 +11,3 @@ "use strict"; | ||
var lnurl_pay_1 = require("lnurl-pay"); | ||
var parseNetwork = function (network) { | ||
var parseBitcoinJsNetwork = function (network) { | ||
if (network === "mainnet") { | ||
@@ -24,2 +24,36 @@ return bitcoinjs_lib_1.networks.bitcoin; | ||
}; | ||
// This is a hack to get around the fact that bolt11 doesn't support signet | ||
var parseBolt11Network = function (network) { | ||
if (network === "mainnet") { | ||
return { | ||
bech32: "bc", | ||
pubKeyHash: 0x00, | ||
scriptHash: 0x05, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
else if (network === "signet") { | ||
return { | ||
bech32: "tb", | ||
pubKeyHash: 0x6f, | ||
scriptHash: 0xc4, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
else if (network === "regtest") { | ||
return { | ||
bech32: "bcrt", | ||
pubKeyHash: 0x6f, | ||
scriptHash: 0xc4, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
} | ||
return { | ||
// default network is bitcoin | ||
bech32: "bc", | ||
pubKeyHash: 0x00, | ||
scriptHash: 0x05, | ||
validWitnessVersions: [0, 1], | ||
}; | ||
}; | ||
var getDescription = function (decoded) { | ||
@@ -35,5 +69,5 @@ var _a; | ||
exports.getDestination = getDestination; | ||
var getHashFromInvoice = function (invoice) { | ||
var getHashFromInvoice = function (invoice, network) { | ||
var _a; | ||
var decoded = bolt11_1.default.decode(invoice); | ||
var decoded = bolt11_1.default.decode(invoice, network); | ||
var data = (_a = decoded.tags.find(function (value) { return value.tagName === "payment_hash"; })) === null || _a === void 0 ? void 0 : _a.data; | ||
@@ -53,4 +87,4 @@ if (data) { | ||
exports.getLightningInvoiceExpiryTime = getLightningInvoiceExpiryTime; | ||
var decodeInvoiceString = function (invoice) { | ||
return bolt11_1.default.decode(invoice); | ||
var decodeInvoiceString = function (invoice, network) { | ||
return bolt11_1.default.decode(invoice, network); | ||
}; | ||
@@ -129,3 +163,3 @@ exports.decodeInvoiceString = decodeInvoiceString; | ||
try { | ||
payReq = bolt11_1.default.decode(lnProtocol); | ||
payReq = bolt11_1.default.decode(lnProtocol, parseBolt11Network(network)); | ||
} | ||
@@ -189,3 +223,3 @@ catch (err) { | ||
// will throw if address is not valid | ||
bitcoinjs_lib_1.address.toOutputScript(path, parseNetwork(network)); | ||
bitcoinjs_lib_1.address.toOutputScript(path, parseBitcoinJsNetwork(network)); | ||
return { | ||
@@ -192,0 +226,0 @@ valid: true, |
{ | ||
"name": "@galoymoney/client", | ||
"main": "dist/index.js", | ||
"version": "0.1.54", | ||
"version": "0.1.55", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/galoymoney/galoy-client", |
Sorry, the diff of this file is not supported yet
557651
10045