Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alby-tools

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alby-tools - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

dist/invoice.d.ts

4

dist/index.d.ts
import fetchWithLsat from "./lsat/fetch";
import { boost as sendBoostagram } from "./podcasting2/boostagrams";
import LightningAddress from "./lightning-address";
import Invoice from "./invoice";
export * as lsat from "./lsat/fetch";
export * as boostagrams from "./podcasting2/boostagrams";
export * as fiat from "./utils/fiat";
export { fetchWithLsat, sendBoostagram };
export { fetchWithLsat, sendBoostagram, LightningAddress, Invoice };
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

import t from"cross-fetch";class e{constructor(t){this.storage=t||{}}getItem(t){return this.storage[t]}setItem(t,e){this.storage[t]=e}}const a=async(a,o,r)=>{r||(r={});const s=r.webln||"undefined"!=typeof window&&window.webln;if(!s)throw new Error("WebLN is missing");let n=r.store||new e;o||(o={}),o.cache="no-store",o.mode="cors",o.headers||(o.headers={});const c=n.getItem(a);if(c){const e=JSON.parse(c);return o.headers.Authorization=`LSAT ${e.mac}:${e.preimage}`,await t(a,o)}o.headers["Accept-Authenticate"]="LSAT";const i=await t(a,o),u=i.headers.get("www-authenticate");if(!u)return i;const l=u.split(","),m=l[0].replace("LSAT macaroon=","").trim(),w=l[1].replace("invoice=","").trim();await s.enable();const d=await s.sendPayment(w);return n.setItem(a,JSON.stringify({mac:m,preimage:d.preimage})),o.headers.Authorization=`LSAT ${m}:${d.preimage}`,await t(a,o)};var o={__proto__:null,fetchWithLsat:a,default:a};const r=async(t,e)=>{let{boost:a,amount:o}=t;e||(e={});const r=e.webln||"undefined"!=typeof window&&window.webln;o||(o=Math.floor(a.value_msat/1e3));let s={destination:t.destination,amount:o,customRecords:{7629169:JSON.stringify(a)}};return t.customKey&&t.customValue&&(s.customRecords[t.customKey]=t.customValue),await r.enable(),await r.keysend(s)};var s={__proto__:null,boost:r,default:r};const n=async e=>{const a="https://getalby.com/api/rates/"+e.toLowerCase()+".json",o=await t(a);return(await o.json()).rate_float/1e8},c=async({satoshi:t,currency:e})=>{const a=await n(e);return Number(t)*a};var i={__proto__:null,getFiatBtcRate:n,getFiatValue:c,getSatoshiValue:async({amount:t,currency:e})=>{const a=await n(e);return Math.floor(Number(t)/a)},getFormattedFiatValue:async({satoshi:t,currency:e})=>(await c({satoshi:t,currency:e})).toLocaleString("en",{style:"currency",currency:e})};export{s as boostagrams,a as fetchWithLsat,i as fiat,o as lsat,r as sendBoostagram};
import t from"cross-fetch";import e from"crypto-js/enc-hex.js";import a from"crypto-js/sha256.js";import{decode as r}from"light-bolt11-decoder";class n{constructor(t){this.storage=void 0,this.storage=t||{}}getItem(t){return this.storage[t]}setItem(t,e){this.storage[t]=e}}const s=async(e,a,r)=>{r||(r={});const s=r.webln||globalThis.webln;if(!s)throw new Error("WebLN is missing");let i=r.store||new n;a||(a={}),a.cache="no-store",a.mode="cors",a.headers||(a.headers={});const o=i.getItem(e);if(o){const r=JSON.parse(o);return a.headers.Authorization=`LSAT ${r.mac}:${r.preimage}`,await t(e,a)}a.headers["Accept-Authenticate"]="LSAT";const c=await t(e,a),l=c.headers.get("www-authenticate");if(!l)return c;const h=l.split(","),m=h[0].replace("LSAT macaroon=","").trim(),u=h[1].replace("invoice=","").trim();await s.enable();const y=await s.sendPayment(u);return i.setItem(e,JSON.stringify({mac:m,preimage:y.preimage})),a.headers.Authorization=`LSAT ${m}:${y.preimage}`,await t(e,a)};var i={__proto__:null,fetchWithLsat:s,default:s};const o=async(t,e)=>{let{boost:a,amount:r}=t;e||(e={});const n=e.webln||globalThis.webln;r||(r=Math.floor(a.value_msat/1e3));let s={destination:t.destination,amount:r,customRecords:{7629169:JSON.stringify(a)}};return t.customKey&&t.customValue&&(s.customRecords[t.customKey]=t.customValue),await n.enable(),await n.keysend(s)};var c={__proto__:null,boost:o,default:o};const l=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,h=t=>!!t&&l.test(t),m=({amount:t,min:e,max:a})=>{const r=t>0&&t>=e&&t<=a;return r&&e===a?t===e:r},u=t=>{if("payRequest"!==t.tag)throw new Error("Invalid pay service params");const r=(t.callback+"").trim(),n=Math.ceil(Number(t.minSendable||0)/1e3),s=Math.floor(Number(t.maxSendable)/1e3);if(!n||!s||n>s)throw new Error("Invalid pay service params");let i,o;try{i=JSON.parse(t.metadata+""),o=a(t.metadata+"").toString(e)}catch(t){i=[],o=a("[]").toString(e)}let c,l="",h="",m="";for(let t=0;t<i.length;t++){const[e,a]=i[t];switch(e){case"text/plain":h=a;break;case"text/identifier":m=a;break;case"image/png;base64":case"image/jpeg;base64":l="data:"+e+","+a}}try{c=new URL(r).hostname}catch(t){}return{callback:r,fixed:n===s,min:n,max:s,domain:c,metadata:i,metadataHash:o,identifier:m,description:h,image:l,commentAllowed:Number(t.commentAllowed)||0,rawData:t,allowsNostr:t.allowsNostr||!1}};class y{constructor(t){var e,a;this.paymentRequest=void 0,this.paymentHash=void 0,this.preimage=void 0,this.verify=void 0,this.paymentRequest=t.pr,this.paymentHash=(t=>{if(!t)return null;try{const e=r(t);if(!e||!e.sections)return null;const a=e.sections.find(t=>"payment_hash"===t.name);return a&&a.value?a.value.toString():null}catch(t){return null}})(this.paymentRequest),this.verify=null!=(e=t.verify)?e:null,this.preimage=null!=(a=t.preimage)?a:null}async isPaid(){if(this.preimage)return this.validatePreimage(this.preimage);if(this.verify)return await this.verifyPayment();throw new Error("Could not verify payment")}validatePreimage(t){if(!t||!this.paymentHash)return!1;try{const r=a(e.parse(t)).toString(e);return this.paymentHash===r}catch(t){return!1}}async verifyPayment(){if(!this.verify)throw new Error("LNURL verify not available");const e=await t(this.verify),a=await e.json();return a.preimage&&(this.preimage=a.preimage),a.settled}}const p=/^((?:[^<>()\[\]\\.,;:\s@"]+(?:\.[^<>()\[\]\\.,;:\s@"]+)*)|(?:".+"))@((?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;class w{constructor(t,e){this.address=void 0,this.options=void 0,this.username=void 0,this.domain=void 0,this.pubkey=void 0,this.keysendData=void 0,this.lnurlpData=void 0,this.address=t,this.options={proxy:"https://lnaddressproxy.getalby.com/lightning-address-details"},this.options=Object.assign(this.options,e),this.parse(),this.lnurlpData={},this.keysendData={}}parse(){const t=p.exec(this.address.toLowerCase());t&&(this.username=t[1],this.domain=t[2])}async fetch(){return this.options.proxy?this.fetchWithProxy():this.fetchWithoutProxy()}async fetchWithProxy(){const e=await t(`${this.options.proxy}?${new URLSearchParams({ln:this.address}).toString()}`),a=await e.json();this.lnurlpData=a.lnurlp,this.keysendData=a.keysend}async fetchWithoutProxy(){try{const e=await t(this.lnurlpUrl());this.lnurlpData=await e.json()}catch(t){}try{const e=await t(this.keysendUrl());this.keysendData=await e.json()}catch(t){}}lnurlpUrl(){return`https://${this.domain}/.well-known/lnurlp/${this.username}`}keysendUrl(){return`https://${this.domain}/.well-known/keysend/${this.username}`}async generateInvoice(e){const a=await t(e),r=await a.json(),n=r&&r.pr&&r.pr.toString();if(!n)throw new Error("Invalid pay service invoice");const s={pr:n};return r&&r.verify&&(s.verify=r.verify.toString()),new y(s)}async requestInvoice(t){const e=1e3*t.satoshi,{callback:a,commentAllowed:r,min:n,max:s}=u(this.lnurlpData);if(!m({amount:e,min:n,max:s}))throw new Error("Invalid amount");if(!h(a))throw new Error("Callback must be a valid url");if(t.comment&&r>0&&t.comment.length>r)throw new Error(`The comment length must be ${r} characters or fewer`);const i={amount:e.toString()};t.comment&&(i.comment=t.comment);let o=new URL(a);return o.search=new URLSearchParams(i).toString(),this.generateInvoice(o)}async zap({satoshi:t,comment:r,relays:n,p:s,e:i}){const o=1e3*t,{callback:c,allowsNostr:l,min:y,max:p}=u(this.lnurlpData);if(!m({amount:o,min:y,max:p}))throw new Error("Invalid amount");if(!h(c))throw new Error("Callback must be a valid url");if(!l)throw new Error("Your provider does not support zaps");const w=await async function({satoshi:t,comment:r,p:n,e:s,relays:i}){if(!globalThis.nostr)throw new Error("Please use a nostr extension");const o=[["p",n],["relays",...i],["amount",t.toString()]];s&&o.push(["e",s]);const c={pubkey:await globalThis.nostr.getPublicKey(),created_at:Math.floor(Date.now()/1e3),kind:9734,tags:o,content:null!=r?r:""};return c.id=a(function(t){if(!function(t){if("string"!=typeof t.content)return!1;if("number"!=typeof t.created_at)return!1;if(!Array.isArray(t.tags))return!1;for(let e=0;e<t.tags.length;e++){const a=t.tags[e];if(!Array.isArray(a))return!1;for(let t=0;t<a.length;t++)if("object"==typeof a[t])return!1}return!0}(t))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,t.pubkey,t.created_at,t.kind,t.tags,t.content])}(c)).toString(e),await globalThis.nostr.signEvent(c)}({satoshi:o,comment:r,p:s,e:i,relays:n}),d={amount:o.toString(),nostr:JSON.stringify(w)};let g=new URL(c);return g.search=new URLSearchParams(d).toString(),this.generateInvoice(g)}}const d=async e=>{const a="https://getalby.com/api/rates/"+e.toLowerCase()+".json",r=await t(a);return(await r.json()).rate_float/1e8},g=async({satoshi:t,currency:e})=>{const a=await d(e);return Number(t)*a};var f={__proto__:null,getFiatBtcRate:d,getFiatValue:g,getSatoshiValue:async({amount:t,currency:e})=>{const a=await d(e);return Math.floor(Number(t)/a)},getFormattedFiatValue:async({satoshi:t,currency:e,locale:a})=>(a||(a="en"),(await g({satoshi:t,currency:e})).toLocaleString(a,{style:"currency",currency:e}))};export{y as Invoice,w as LightningAddress,c as boostagrams,s as fetchWithLsat,f as fiat,i as lsat,o as sendBoostagram};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

import e from"cross-fetch";var t=/*#__PURE__*/function(){function e(e){this.storage=e||{}}var t=e.prototype;return t.getItem=function(e){return this.storage[e]},t.setItem=function(e,t){this.storage[e]=t},e}(),r=function(r,n,o){try{var s,i=function(t){return s?t:(n.headers["Accept-Authenticate"]="LSAT",Promise.resolve(e(r,n)).then(function(t){var o=t.headers.get("www-authenticate");if(!o)return t;var s=o.split(","),i=s[0].replace("LSAT macaroon=","").trim(),c=s[1].replace("invoice=","").trim();return Promise.resolve(a.enable()).then(function(){return Promise.resolve(a.sendPayment(c)).then(function(t){return u.setItem(r,JSON.stringify({mac:i,preimage:t.preimage})),n.headers.Authorization="LSAT "+i+":"+t.preimage,Promise.resolve(e(r,n))})})}))};o||(o={});var a=o.webln||"undefined"!=typeof window&&window.webln;if(!a)throw new Error("WebLN is missing");var u=o.store||new t;n||(n={}),n.cache="no-store",n.mode="cors",n.headers||(n.headers={});var c=u.getItem(r),m=function(){if(c){var t=JSON.parse(c);return n.headers.Authorization="LSAT "+t.mac+":"+t.preimage,Promise.resolve(e(r,n)).then(function(e){return s=1,e})}}();return Promise.resolve(m&&m.then?m.then(i):i(m))}catch(e){return Promise.reject(e)}},n={__proto__:null,fetchWithLsat:r,default:r},o=function(e,t){try{var r=e.boost,n=e.amount;t||(t={});var o=t.webln||"undefined"!=typeof window&&window.webln;n||(n=Math.floor(r.value_msat/1e3));var s={destination:e.destination,amount:n,customRecords:{7629169:JSON.stringify(r)}};return e.customKey&&e.customValue&&(s.customRecords[e.customKey]=e.customValue),Promise.resolve(o.enable()).then(function(){return Promise.resolve(o.keysend(s))})}catch(e){return Promise.reject(e)}},s={__proto__:null,boost:o,default:o},i=function(t){try{var r="https://getalby.com/api/rates/"+t.toLowerCase()+".json";return Promise.resolve(e(r)).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.rate_float/1e8})})}catch(e){return Promise.reject(e)}},a=function(e){var t=e.satoshi;return Promise.resolve(i(e.currency)).then(function(e){return Number(t)*e})},u={__proto__:null,getFiatBtcRate:i,getFiatValue:a,getSatoshiValue:function(e){var t=e.amount;return Promise.resolve(i(e.currency)).then(function(e){return Math.floor(Number(t)/e)})},getFormattedFiatValue:function(e){var t=e.currency;return Promise.resolve(a({satoshi:e.satoshi,currency:t})).then(function(e){return e.toLocaleString("en",{style:"currency",currency:t})})}};export{s as boostagrams,r as fetchWithLsat,u as fiat,n as lsat,o as sendBoostagram};
import e from"cross-fetch";import r from"crypto-js/enc-hex.js";import t from"crypto-js/sha256.js";import{decode as n}from"light-bolt11-decoder";var o=/*#__PURE__*/function(){function e(e){this.storage=void 0,this.storage=e||{}}var r=e.prototype;return r.getItem=function(e){return this.storage[e]},r.setItem=function(e,r){this.storage[e]=r},e}(),i=function(r,t,n){try{var i,a=function(n){return i?n:(t.headers["Accept-Authenticate"]="LSAT",Promise.resolve(e(r,t)).then(function(n){var o=n.headers.get("www-authenticate");if(!o)return n;var i=o.split(","),a=i[0].replace("LSAT macaroon=","").trim(),c=i[1].replace("invoice=","").trim();return Promise.resolve(s.enable()).then(function(){return Promise.resolve(s.sendPayment(c)).then(function(n){return u.setItem(r,JSON.stringify({mac:a,preimage:n.preimage})),t.headers.Authorization="LSAT "+a+":"+n.preimage,Promise.resolve(e(r,t))})})}))};n||(n={});var s=n.webln||globalThis.webln;if(!s)throw new Error("WebLN is missing");var u=n.store||new o;t||(t={}),t.cache="no-store",t.mode="cors",t.headers||(t.headers={});var c=u.getItem(r),l=function(){if(c){var n=JSON.parse(c);return t.headers.Authorization="LSAT "+n.mac+":"+n.preimage,Promise.resolve(e(r,t)).then(function(e){return i=1,e})}}();return Promise.resolve(l&&l.then?l.then(a):a(l))}catch(e){return Promise.reject(e)}},a={__proto__:null,fetchWithLsat:i,default:i},s=function(e,r){try{var t=e.boost,n=e.amount;r||(r={});var o=r.webln||globalThis.webln;n||(n=Math.floor(t.value_msat/1e3));var i={destination:e.destination,amount:n,customRecords:{7629169:JSON.stringify(t)}};return e.customKey&&e.customValue&&(i.customRecords[e.customKey]=e.customValue),Promise.resolve(o.enable()).then(function(){return Promise.resolve(o.keysend(i))})}catch(e){return Promise.reject(e)}},u={__proto__:null,boost:s,default:s},c=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,l=function(e){return!!e&&c.test(e)},m=function(e){var r=e.amount,t=e.min,n=e.max,o=r>0&&r>=t&&r<=n;return o&&t===n?r===t:o},h=function(e){if("payRequest"!==e.tag)throw new Error("Invalid pay service params");var n,o,i=(e.callback+"").trim(),a=Math.ceil(Number(e.minSendable||0)/1e3),s=Math.floor(Number(e.maxSendable)/1e3);if(!a||!s||a>s)throw new Error("Invalid pay service params");try{n=JSON.parse(e.metadata+""),o=t(e.metadata+"").toString(r)}catch(e){n=[],o=t("[]").toString(r)}for(var u,c="",l="",m="",h=0;h<n.length;h++){var f=n[h],v=f[0],p=f[1];switch(v){case"text/plain":l=p;break;case"text/identifier":m=p;break;case"image/png;base64":case"image/jpeg;base64":c="data:"+v+","+p}}try{u=new URL(i).hostname}catch(e){}return{callback:i,fixed:a===s,min:a,max:s,domain:u,metadata:n,metadataHash:o,identifier:m,description:l,image:c,commentAllowed:Number(e.commentAllowed)||0,rawData:e,allowsNostr:e.allowsNostr||!1}},f=/*#__PURE__*/function(){function o(e){var r,t;this.paymentRequest=void 0,this.paymentHash=void 0,this.preimage=void 0,this.verify=void 0,this.paymentRequest=e.pr,this.paymentHash=function(e){if(!e)return null;try{var r=n(e);if(!r||!r.sections)return null;var t=r.sections.find(function(e){return"payment_hash"===e.name});return t&&t.value?t.value.toString():null}catch(e){return null}}(this.paymentRequest),this.verify=null!=(r=e.verify)?r:null,this.preimage=null!=(t=e.preimage)?t:null}var i=o.prototype;return i.isPaid=function(){try{var e=this;if(e.preimage)return Promise.resolve(e.validatePreimage(e.preimage));if(e.verify)return Promise.resolve(e.verifyPayment());throw new Error("Could not verify payment")}catch(e){return Promise.reject(e)}},i.validatePreimage=function(e){if(!e||!this.paymentHash)return!1;try{var n=t(r.parse(e)).toString(r);return this.paymentHash===n}catch(e){return!1}},i.verifyPayment=function(){try{var r=this;if(!r.verify)throw new Error("LNURL verify not available");return Promise.resolve(e(r.verify)).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.preimage&&(r.preimage=e.preimage),e.settled})})}catch(e){return Promise.reject(e)}},o}();function v(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}var p=/^((?:[^<>()\[\]\\.,;:\s@"]+(?:\.[^<>()\[\]\\.,;:\s@"]+)*)|(?:".+"))@((?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,y=/*#__PURE__*/function(){function n(e,r){this.address=void 0,this.options=void 0,this.username=void 0,this.domain=void 0,this.pubkey=void 0,this.keysendData=void 0,this.lnurlpData=void 0,this.address=e,this.options={proxy:"https://lnaddressproxy.getalby.com/lightning-address-details"},this.options=Object.assign(this.options,r),this.parse(),this.lnurlpData={},this.keysendData={}}var o=n.prototype;return o.parse=function(){var e=p.exec(this.address.toLowerCase());e&&(this.username=e[1],this.domain=e[2])},o.fetch=function(){try{var e=this;return Promise.resolve(e.options.proxy?e.fetchWithProxy():e.fetchWithoutProxy())}catch(e){return Promise.reject(e)}},o.fetchWithProxy=function(){try{var r=this;return Promise.resolve(e(r.options.proxy+"?"+new URLSearchParams({ln:r.address}).toString())).then(function(e){return Promise.resolve(e.json()).then(function(e){r.lnurlpData=e.lnurlp,r.keysendData=e.keysend})})}catch(e){return Promise.reject(e)}},o.fetchWithoutProxy=function(){try{var r=function(){var r=v(function(){return Promise.resolve(e(t.keysendUrl())).then(function(e){return Promise.resolve(e.json()).then(function(e){t.keysendData=e})})},function(){});if(r&&r.then)return r.then(function(){})},t=this,n=v(function(){return Promise.resolve(e(t.lnurlpUrl())).then(function(e){return Promise.resolve(e.json()).then(function(e){t.lnurlpData=e})})},function(){});return Promise.resolve(n&&n.then?n.then(r):r())}catch(e){return Promise.reject(e)}},o.lnurlpUrl=function(){return"https://"+this.domain+"/.well-known/lnurlp/"+this.username},o.keysendUrl=function(){return"https://"+this.domain+"/.well-known/keysend/"+this.username},o.generateInvoice=function(r){try{return Promise.resolve(e(r)).then(function(e){return Promise.resolve(e.json()).then(function(e){var r=e&&e.pr&&e.pr.toString();if(!r)throw new Error("Invalid pay service invoice");var t={pr:r};return e&&e.verify&&(t.verify=e.verify.toString()),new f(t)})})}catch(e){return Promise.reject(e)}},o.requestInvoice=function(e){try{var r=1e3*e.satoshi,t=h(this.lnurlpData),n=t.callback,o=t.commentAllowed;if(!m({amount:r,min:t.min,max:t.max}))throw new Error("Invalid amount");if(!l(n))throw new Error("Callback must be a valid url");if(e.comment&&o>0&&e.comment.length>o)throw new Error("The comment length must be "+o+" characters or fewer");var i={amount:r.toString()};e.comment&&(i.comment=e.comment);var a=new URL(n);return a.search=new URLSearchParams(i).toString(),Promise.resolve(this.generateInvoice(a))}catch(e){return Promise.reject(e)}},o.zap=function(e){var n=e.satoshi,o=e.comment,i=e.relays,a=e.p,s=e.e;try{var u=this,c=1e3*n,f=h(u.lnurlpData),v=f.callback,p=f.allowsNostr;if(!m({amount:c,min:f.min,max:f.max}))throw new Error("Invalid amount");if(!l(v))throw new Error("Callback must be a valid url");if(!p)throw new Error("Your provider does not support zaps");return Promise.resolve(function(e){var n=e.satoshi,o=e.comment,i=e.p,a=e.e,s=e.relays;try{if(!globalThis.nostr)throw new Error("Please use a nostr extension");var u=[["p",i],["relays"].concat(s),["amount",n.toString()]];return a&&u.push(["e",a]),Promise.resolve(globalThis.nostr.getPublicKey()).then(function(e){var n={pubkey:e,created_at:Math.floor(Date.now()/1e3),kind:9734,tags:u,content:null!=o?o:""};return n.id=t(function(e){if(!function(e){if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if(!Array.isArray(e.tags))return!1;for(var r=0;r<e.tags.length;r++){var t=e.tags[r];if(!Array.isArray(t))return!1;for(var n=0;n<t.length;n++)if("object"==typeof t[n])return!1}return!0}(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(n)).toString(r),Promise.resolve(globalThis.nostr.signEvent(n))})}catch(a){return Promise.reject(a)}}({satoshi:c,comment:o,p:a,e:s,relays:i})).then(function(e){var r={amount:c.toString(),nostr:JSON.stringify(e)},t=new URL(v);return t.search=new URLSearchParams(r).toString(),u.generateInvoice(t)})}catch(s){return Promise.reject(s)}},n}(),d=function(r){try{var t="https://getalby.com/api/rates/"+r.toLowerCase()+".json";return Promise.resolve(e(t)).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.rate_float/1e8})})}catch(e){return Promise.reject(e)}},g=function(e){var r=e.satoshi;return Promise.resolve(d(e.currency)).then(function(e){return Number(r)*e})},w={__proto__:null,getFiatBtcRate:d,getFiatValue:g,getSatoshiValue:function(e){var r=e.amount;return Promise.resolve(d(e.currency)).then(function(e){return Math.floor(Number(r)/e)})},getFormattedFiatValue:function(e){var r=e.currency,t=e.locale;return t||(t="en"),Promise.resolve(g({satoshi:e.satoshi,currency:r})).then(function(e){return e.toLocaleString(t,{style:"currency",currency:r})})}};export{f as Invoice,y as LightningAddress,u as boostagrams,i as fetchWithLsat,w as fiat,a as lsat,s as sendBoostagram};
//# sourceMappingURL=index.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cross-fetch")):"function"==typeof define&&define.amd?define(["exports","cross-fetch"],t):t((e||self).albyTools={},e.crossFetch)}(this,function(e,t){function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/r(t),o=/*#__PURE__*/function(){function e(e){this.storage=e||{}}var t=e.prototype;return t.getItem=function(e){return this.storage[e]},t.setItem=function(e,t){this.storage[e]=t},e}(),i=function(e,t,r){try{var i,s=function(r){return i?r:(t.headers["Accept-Authenticate"]="LSAT",Promise.resolve(n.default(e,t)).then(function(r){var o=r.headers.get("www-authenticate");if(!o)return r;var i=o.split(","),s=i[0].replace("LSAT macaroon=","").trim(),c=i[1].replace("invoice=","").trim();return Promise.resolve(a.enable()).then(function(){return Promise.resolve(a.sendPayment(c)).then(function(r){return u.setItem(e,JSON.stringify({mac:s,preimage:r.preimage})),t.headers.Authorization="LSAT "+s+":"+r.preimage,Promise.resolve(n.default(e,t))})})}))};r||(r={});var a=r.webln||"undefined"!=typeof window&&window.webln;if(!a)throw new Error("WebLN is missing");var u=r.store||new o;t||(t={}),t.cache="no-store",t.mode="cors",t.headers||(t.headers={});var c=u.getItem(e),f=function(){if(c){var r=JSON.parse(c);return t.headers.Authorization="LSAT "+r.mac+":"+r.preimage,Promise.resolve(n.default(e,t)).then(function(e){return i=1,e})}}();return Promise.resolve(f&&f.then?f.then(s):s(f))}catch(e){return Promise.reject(e)}},s={__proto__:null,fetchWithLsat:i,default:i},a=function(e,t){try{var r=e.boost,n=e.amount;t||(t={});var o=t.webln||"undefined"!=typeof window&&window.webln;n||(n=Math.floor(r.value_msat/1e3));var i={destination:e.destination,amount:n,customRecords:{7629169:JSON.stringify(r)}};return e.customKey&&e.customValue&&(i.customRecords[e.customKey]=e.customValue),Promise.resolve(o.enable()).then(function(){return Promise.resolve(o.keysend(i))})}catch(e){return Promise.reject(e)}},u=function(e){try{var t="https://getalby.com/api/rates/"+e.toLowerCase()+".json";return Promise.resolve(n.default(t)).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.rate_float/1e8})})}catch(e){return Promise.reject(e)}},c=function(e){var t=e.satoshi;return Promise.resolve(u(e.currency)).then(function(e){return Number(t)*e})},f={__proto__:null,getFiatBtcRate:u,getFiatValue:c,getSatoshiValue:function(e){var t=e.amount;return Promise.resolve(u(e.currency)).then(function(e){return Math.floor(Number(t)/e)})},getFormattedFiatValue:function(e){var t=e.currency;return Promise.resolve(c({satoshi:e.satoshi,currency:t})).then(function(e){return e.toLocaleString("en",{style:"currency",currency:t})})}};e.boostagrams={__proto__:null,boost:a,default:a},e.fetchWithLsat=i,e.fiat=f,e.lsat=s,e.sendBoostagram=a});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cross-fetch"),require("crypto-js/enc-hex.js"),require("crypto-js/sha256.js"),require("light-bolt11-decoder")):"function"==typeof define&&define.amd?define(["exports","cross-fetch","crypto-js/enc-hex.js","crypto-js/sha256.js","light-bolt11-decoder"],t):t((e||self).albyTools={},e.crossFetch,e.Hex,e.sha256,e.lightBolt11Decoder)}(this,function(e,t,r,n,o){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/a(t),s=/*#__PURE__*/a(r),u=/*#__PURE__*/a(n),c=/*#__PURE__*/function(){function e(e){this.storage=void 0,this.storage=e||{}}var t=e.prototype;return t.getItem=function(e){return this.storage[e]},t.setItem=function(e,t){this.storage[e]=t},e}(),l=function(e,t,r){try{var n,o=function(r){return n?r:(t.headers["Accept-Authenticate"]="LSAT",Promise.resolve(i.default(e,t)).then(function(r){var n=r.headers.get("www-authenticate");if(!n)return r;var o=n.split(","),u=o[0].replace("LSAT macaroon=","").trim(),c=o[1].replace("invoice=","").trim();return Promise.resolve(a.enable()).then(function(){return Promise.resolve(a.sendPayment(c)).then(function(r){return s.setItem(e,JSON.stringify({mac:u,preimage:r.preimage})),t.headers.Authorization="LSAT "+u+":"+r.preimage,Promise.resolve(i.default(e,t))})})}))};r||(r={});var a=r.webln||globalThis.webln;if(!a)throw new Error("WebLN is missing");var s=r.store||new c;t||(t={}),t.cache="no-store",t.mode="cors",t.headers||(t.headers={});var u=s.getItem(e),l=function(){if(u){var r=JSON.parse(u);return t.headers.Authorization="LSAT "+r.mac+":"+r.preimage,Promise.resolve(i.default(e,t)).then(function(e){return n=1,e})}}();return Promise.resolve(l&&l.then?l.then(o):o(l))}catch(e){return Promise.reject(e)}},h={__proto__:null,fetchWithLsat:l,default:l},m=function(e,t){try{var r=e.boost,n=e.amount;t||(t={});var o=t.webln||globalThis.webln;n||(n=Math.floor(r.value_msat/1e3));var a={destination:e.destination,amount:n,customRecords:{7629169:JSON.stringify(r)}};return e.customKey&&e.customValue&&(a.customRecords[e.customKey]=e.customValue),Promise.resolve(o.enable()).then(function(){return Promise.resolve(o.keysend(a))})}catch(e){return Promise.reject(e)}},f={__proto__:null,boost:m,default:m},v=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,d=function(e){return!!e&&v.test(e)},p=function(e){var t=e.amount,r=e.min,n=e.max,o=t>0&&t>=r&&t<=n;return o&&r===n?t===r:o},y=function(e){if("payRequest"!==e.tag)throw new Error("Invalid pay service params");var t,r,n=(e.callback+"").trim(),o=Math.ceil(Number(e.minSendable||0)/1e3),a=Math.floor(Number(e.maxSendable)/1e3);if(!o||!a||o>a)throw new Error("Invalid pay service params");try{t=JSON.parse(e.metadata+""),r=u.default(e.metadata+"").toString(s.default)}catch(e){t=[],r=u.default("[]").toString(s.default)}for(var i,c="",l="",h="",m=0;m<t.length;m++){var f=t[m],v=f[0],d=f[1];switch(v){case"text/plain":l=d;break;case"text/identifier":h=d;break;case"image/png;base64":case"image/jpeg;base64":c="data:"+v+","+d}}try{i=new URL(n).hostname}catch(e){}return{callback:n,fixed:o===a,min:o,max:a,domain:i,metadata:t,metadataHash:r,identifier:h,description:l,image:c,commentAllowed:Number(e.commentAllowed)||0,rawData:e,allowsNostr:e.allowsNostr||!1}},g=/*#__PURE__*/function(){function e(e){var t,r;this.paymentRequest=void 0,this.paymentHash=void 0,this.preimage=void 0,this.verify=void 0,this.paymentRequest=e.pr,this.paymentHash=function(e){if(!e)return null;try{var t=o.decode(e);if(!t||!t.sections)return null;var r=t.sections.find(function(e){return"payment_hash"===e.name});return r&&r.value?r.value.toString():null}catch(e){return null}}(this.paymentRequest),this.verify=null!=(t=e.verify)?t:null,this.preimage=null!=(r=e.preimage)?r:null}var t=e.prototype;return t.isPaid=function(){try{var e=this;if(e.preimage)return Promise.resolve(e.validatePreimage(e.preimage));if(e.verify)return Promise.resolve(e.verifyPayment());throw new Error("Could not verify payment")}catch(e){return Promise.reject(e)}},t.validatePreimage=function(e){if(!e||!this.paymentHash)return!1;try{var t=u.default(s.default.parse(e)).toString(s.default);return this.paymentHash===t}catch(e){return!1}},t.verifyPayment=function(){try{var e=this;if(!e.verify)throw new Error("LNURL verify not available");return Promise.resolve(i.default(e.verify)).then(function(t){return Promise.resolve(t.json()).then(function(t){return t.preimage&&(e.preimage=t.preimage),t.settled})})}catch(e){return Promise.reject(e)}},e}();function w(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var P=/^((?:[^<>()\[\]\\.,;:\s@"]+(?:\.[^<>()\[\]\\.,;:\s@"]+)*)|(?:".+"))@((?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,b=/*#__PURE__*/function(){function e(e,t){this.address=void 0,this.options=void 0,this.username=void 0,this.domain=void 0,this.pubkey=void 0,this.keysendData=void 0,this.lnurlpData=void 0,this.address=e,this.options={proxy:"https://lnaddressproxy.getalby.com/lightning-address-details"},this.options=Object.assign(this.options,t),this.parse(),this.lnurlpData={},this.keysendData={}}var t=e.prototype;return t.parse=function(){var e=P.exec(this.address.toLowerCase());e&&(this.username=e[1],this.domain=e[2])},t.fetch=function(){try{var e=this;return Promise.resolve(e.options.proxy?e.fetchWithProxy():e.fetchWithoutProxy())}catch(e){return Promise.reject(e)}},t.fetchWithProxy=function(){try{var e=this;return Promise.resolve(i.default(e.options.proxy+"?"+new URLSearchParams({ln:e.address}).toString())).then(function(t){return Promise.resolve(t.json()).then(function(t){e.lnurlpData=t.lnurlp,e.keysendData=t.keysend})})}catch(e){return Promise.reject(e)}},t.fetchWithoutProxy=function(){try{var e=function(){var e=w(function(){return Promise.resolve(i.default(t.keysendUrl())).then(function(e){return Promise.resolve(e.json()).then(function(e){t.keysendData=e})})},function(){});if(e&&e.then)return e.then(function(){})},t=this,r=w(function(){return Promise.resolve(i.default(t.lnurlpUrl())).then(function(e){return Promise.resolve(e.json()).then(function(e){t.lnurlpData=e})})},function(){});return Promise.resolve(r&&r.then?r.then(e):e())}catch(e){return Promise.reject(e)}},t.lnurlpUrl=function(){return"https://"+this.domain+"/.well-known/lnurlp/"+this.username},t.keysendUrl=function(){return"https://"+this.domain+"/.well-known/keysend/"+this.username},t.generateInvoice=function(e){try{return Promise.resolve(i.default(e)).then(function(e){return Promise.resolve(e.json()).then(function(e){var t=e&&e.pr&&e.pr.toString();if(!t)throw new Error("Invalid pay service invoice");var r={pr:t};return e&&e.verify&&(r.verify=e.verify.toString()),new g(r)})})}catch(e){return Promise.reject(e)}},t.requestInvoice=function(e){try{var t=1e3*e.satoshi,r=y(this.lnurlpData),n=r.callback,o=r.commentAllowed;if(!p({amount:t,min:r.min,max:r.max}))throw new Error("Invalid amount");if(!d(n))throw new Error("Callback must be a valid url");if(e.comment&&o>0&&e.comment.length>o)throw new Error("The comment length must be "+o+" characters or fewer");var a={amount:t.toString()};e.comment&&(a.comment=e.comment);var i=new URL(n);return i.search=new URLSearchParams(a).toString(),Promise.resolve(this.generateInvoice(i))}catch(e){return Promise.reject(e)}},t.zap=function(e){var t=e.satoshi,r=e.comment,n=e.relays,o=e.p,a=e.e;try{var i=this,c=1e3*t,l=y(i.lnurlpData),h=l.callback,m=l.allowsNostr;if(!p({amount:c,min:l.min,max:l.max}))throw new Error("Invalid amount");if(!d(h))throw new Error("Callback must be a valid url");if(!m)throw new Error("Your provider does not support zaps");return Promise.resolve(function(e){var t=e.satoshi,r=e.comment,n=e.p,o=e.e,a=e.relays;try{if(!globalThis.nostr)throw new Error("Please use a nostr extension");var i=[["p",n],["relays"].concat(a),["amount",t.toString()]];return o&&i.push(["e",o]),Promise.resolve(globalThis.nostr.getPublicKey()).then(function(e){var t={pubkey:e,created_at:Math.floor(Date.now()/1e3),kind:9734,tags:i,content:null!=r?r:""};return t.id=u.default(function(e){if(!function(e){if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if(!Array.isArray(e.tags))return!1;for(var t=0;t<e.tags.length;t++){var r=e.tags[t];if(!Array.isArray(r))return!1;for(var n=0;n<r.length;n++)if("object"==typeof r[n])return!1}return!0}(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}(t)).toString(s.default),Promise.resolve(globalThis.nostr.signEvent(t))})}catch(o){return Promise.reject(o)}}({satoshi:c,comment:r,p:o,e:a,relays:n})).then(function(e){var t={amount:c.toString(),nostr:JSON.stringify(e)},r=new URL(h);return r.search=new URLSearchParams(t).toString(),i.generateInvoice(r)})}catch(a){return Promise.reject(a)}},e}(),j=function(e){try{var t="https://getalby.com/api/rates/"+e.toLowerCase()+".json";return Promise.resolve(i.default(t)).then(function(e){return Promise.resolve(e.json()).then(function(e){return e.rate_float/1e8})})}catch(e){return Promise.reject(e)}},S=function(e){var t=e.satoshi;return Promise.resolve(j(e.currency)).then(function(e){return Number(t)*e})},x={__proto__:null,getFiatBtcRate:j,getFiatValue:S,getSatoshiValue:function(e){var t=e.amount;return Promise.resolve(j(e.currency)).then(function(e){return Math.floor(Number(t)/e)})},getFormattedFiatValue:function(e){var t=e.currency,r=e.locale;return r||(r="en"),Promise.resolve(S({satoshi:e.satoshi,currency:t})).then(function(e){return e.toLocaleString(r,{style:"currency",currency:t})})}};e.Invoice=g,e.LightningAddress=b,e.boostagrams=f,e.fetchWithLsat=l,e.fiat=x,e.lsat=h,e.sendBoostagram=m});
//# sourceMappingURL=index.umd.js.map

@@ -1,3 +0,3 @@

export function fetchWithLsat(url: any, fetchArgs: any, options: any): Promise<Response>;
export declare const fetchWithLsat: (url: string, fetchArgs: Record<string, any>, options: Record<string, any>) => Promise<Response>;
export default fetchWithLsat;
//# sourceMappingURL=fetch.d.ts.map

@@ -10,6 +10,7 @@ export declare const getFiatBtcRate: (currency: string) => Promise<number>;

}) => Promise<number>;
export declare const getFormattedFiatValue: ({ satoshi, currency }: {
export declare const getFormattedFiatValue: ({ satoshi, currency, locale }: {
satoshi: number | string;
currency: string;
locale: string;
}) => Promise<string>;
//# sourceMappingURL=fiat.d.ts.map

@@ -1,8 +0,8 @@

export default MemoryStorage;
declare class MemoryStorage {
constructor(initial: any);
storage: any;
constructor(initial?: any);
getItem(key: any): any;
setItem(key: any, value: any): void;
}
export default MemoryStorage;
//# sourceMappingURL=MemoryStorage.d.ts.map
{
"name": "alby-tools",
"version": "1.1.1",
"version": "1.2.0",
"description": "Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps",

@@ -32,5 +32,8 @@ "type": "module",

"dependencies": {
"cross-fetch": "^3.1.5"
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"light-bolt11-decoder": "^3.0.0"
},
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/node": "^18.11.0",

@@ -37,0 +40,0 @@ "microbundle": "^0.15.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc