alby-js-sdk
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -1,2 +0,2 @@ | ||
import e from"crypto-js";import t from"cross-fetch";import{generatePrivateKey as n,relayInit as s,nip19 as r,getPublicKey as o,signEvent as i,getEventHash as a,nip04 as c}from"nostr-tools";function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},h.apply(this,arguments)}function u(e,t){if(null==e)return{};var n,s,r={},o=Object.keys(e);for(s=0;s<o.length;s++)t.indexOf(n=o[s])>=0||(r[n]=e[n]);return r}function l(e){return Object.entries(e).map(([e,t])=>e&&t?`${e}=${t}`:"").join("&")}function d(e,t){return`Basic ${btoa(`${e}:${t}`)}`}const p=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],m="https://api.getalby.com";async function y(e,n,s=0){const r=await t(e,n);if(429===r.status&&s>0){const t=Number(r.headers.get("x-rate-limit-reset")),o=Number(r.headers.get("x-rate-limit-remaining")),i=1e3*t-Date.now();let a=1e3;return 0===o&&(a=i),await new Promise(e=>setTimeout(e,a)),y(e,n,s-1)}return r}class w extends Error{constructor(e,t,n,s){super(),this.status=void 0,this.statusText=void 0,this.headers=void 0,this.error=void 0,this.status=e,this.statusText=t,this.headers=n,this.error=s}}async function f(e){let{auth:t,endpoint:n,params:s={},request_body:r,method:o,max_retries:i,base_url:a=m,headers:c}=e,d=u(e,p);const f=new URL(a+n);f.search=l(s);const g="POST"===o&&!!r,b=t?await t.getAuthHeader(f.href,o):void 0,v=await y(f.toString(),h({headers:h({},g?{"Content-Type":"application/json; charset=utf-8"}:void 0,b,c),method:o,body:g?JSON.stringify(r):void 0},d),i);if(!v.ok){const e=await v.json();throw new w(v.status,v.statusText,v.headers,e)}return v}async function g(e){return(await f(e)).json()}const b=["expires_in"],v=["token"];function _(e){const{expires_in:t}=e;return h({},u(e,b),!!t&&{expires_at:Date.now()+1e3*t})}class k{constructor(e){this.bearer_token=void 0,this.bearer_token=e}getAuthHeader(){return{Authorization:`Bearer ${this.bearer_token}`}}}var E={__proto__:null,OAuth2User:class{constructor(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;const{token:t}=e,n=u(e,v);this.options=h({client_secret:""},n),this.token=t}async refreshAccessToken(){var e;const t=null==(e=this.token)?void 0:e.refresh_token,{client_id:n,client_secret:s,request_options:r}=this.options;if(!n)throw new Error("client_id is required");if(!t)throw new Error("refresh_token is required");const o=_(await g(h({},r,{endpoint:"/oauth/token",params:{client_id:n,grant_type:"refresh_token",refresh_token:t},method:"POST",headers:h({},null==r?void 0:r.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:d(n,s)})})));return this.token=o,{token:o}}isAccessTokenExpired(){var e,t;const n=null==(e=this.token)?void 0:e.refresh_token,s=null==(t=this.token)?void 0:t.expires_at;return!s||!!n&&s<=Date.now()+1e3}async requestAccessToken(e){const{client_id:t,client_secret:n,callback:s,request_options:r}=this.options,o=this.code_verifier;if(!t)throw new Error("client_id is required");if(!s)throw new Error("callback is required");const i={code:e,grant_type:"authorization_code",code_verifier:o,client_id:t,redirect_uri:s},a=_(await g(h({},r,{endpoint:"/oauth/token",params:i,method:"POST",headers:h({},null==r?void 0:r.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:d(t,n)})})));return this.token=a,{token:a}}generateAuthURL(t){t||(t={}),console.log(t);const{client_id:n,callback:s,scopes:r}=this.options;if(!s)throw new Error("callback required");if(!r)throw new Error("scopes required");let o;if("S256"===t.code_challenge_method){const t=e.lib.WordArray.random(64);this.code_verifier=t.toString(),this.code_challenge=e.SHA256(this.code_verifier).toString(e.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),o="S256"}else"plain"===t.code_challenge_method&&t.code_challenge&&(this.code_challenge=t.code_challenge,this.code_verifier=t.code_challenge,o="plain");const i=this.code_challenge,a=new URL("https://getalby.com/oauth");return a.search=l(h({},t,{client_id:n,scope:r.join(" "),response_type:"code",redirect_uri:s,code_challenge_method:o,code_challenge:i})),a.toString()}async getAuthHeader(){var e;if(null==(e=this.token)||!e.access_token)throw new Error("access_token is required");return this.isAccessTokenExpired()&&await this.refreshAccessToken(),{Authorization:`Bearer ${this.token.access_token}`}}},OAuth2Bearer:k},P={__proto__:null,OAuthClient:class{},AuthClient:class{}};const O={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}};class T{static parseWalletConnectUrl(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");const t=new URL(e),n={};n.walletPubkey=t.host;const s=t.searchParams.get("secret"),r=t.searchParams.get("relay");return s&&(n.secret=s),r&&(n.relayUrl=r),n}static withNewSecret(e){return(e=e||{}).secret=n(),new T(e)}constructor(e){var t;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,e&&e.nostrWalletConnectUrl&&(e=h({},T.parseWalletConnectUrl(e.nostrWalletConnectUrl),e));const n=O[(null==(t=e)?void 0:t.providerName)||"alby"];this.options=h({},n,e||{}),this.relayUrl=this.options.relayUrl,this.relay=s(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?r.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?r.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}on(e,t){this.subscribers[e]=t}notify(e,t){const n=this.subscribers[e];n&&n(t)}getNostrWalletConnectUrl(e=!0){let t=`nostr+walletconnect://${this.walletPubkey}?relay=${this.relayUrl}&pubkey=${this.publicKey}`;return e&&(t=`${t}&secret=${this.secret}`),t}get nostrWalletConnectUrl(){return this.getNostrWalletConnectUrl()}get connected(){return 1===this.relay.status}get publicKey(){if(!this.secret)throw new Error("Missing secret key");return o(this.secret)}signEvent(e){if(!this.secret)throw new Error("Missing secret key");return i(e,this.secret)}getEventHash(e){return a(e)}async enable(){if(this.connected)return Promise.resolve();await this.relay.connect()}close(){return this.relay.close()}async encrypt(e,t){if(!this.secret)throw new Error("Missing secret");return await c.encrypt(this.secret,e,t)}async decrypt(e,t){if(!this.secret)throw new Error("Missing secret");return await c.decrypt(this.secret,e,t)}async getInfo(){return{methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"}}sendPayment(e){var t=this;return this.checkConnected(),new Promise(async function(n,s){const r={method:"pay_invoice",params:{invoice:e}},o=await t.encrypt(t.walletPubkey,JSON.stringify(r));let i={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:o};i.pubkey=t.publicKey,i.id=t.getEventHash(i),i.sig=t.signEvent(i);let a=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[i.id]}]),c=setTimeout(function(){a.unsub(),s(`reply timeout: event ${i.id}`)},6e4);a.on("event",async function(e){var r;clearTimeout(c),a.unsub();const o=await t.decrypt(t.walletPubkey,e.content);let i;try{i=JSON.parse(o)}catch(e){return void s({error:"invalid response",code:"INTERNAL"})}var h,u;23195==e.kind&&null!=(r=i.result)&&r.preimage?(n({preimage:i.result.preimage}),t.notify("sendPayment",e.content)):s({error:null==(h=i.error)?void 0:h.message,code:null==(u=i.error)?void 0:u.code})});let h=t.relay.publish(i),u=setTimeout(function(){s({error:`Publish timeout: event ${i.id}`})},5e3);h.on("failed",e=>{clearTimeout(u),s({error:`Failed to publish request: ${e}`})}),h.on("ok",()=>{clearTimeout(u)})})}getAuthorizationUrl(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");const t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t}initNWC(e={}){e.name||(e.name=document.location.host);const t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,s=window.outerWidth/2+window.screenX-200;return new Promise((e,r)=>{const o=window.open(t.toString(),`${document.title} - Wallet Connect`,`height=600,width=400,top=${n},left=${s}`);if(!o)return void r();const i=n=>{const s=n.data;s&&"nwc:success"===s.type&&n.origin===`${t.protocol}//${t.host}`&&(e(s),clearInterval(a),window.removeEventListener("message",i),o&&o.close())},a=setInterval(()=>{o&&o.closed&&(r(),clearInterval(a),window.removeEventListener("message",i))},500);window.addEventListener("message",i)})}checkConnected(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")}}const q=T;function A(e){const t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}class x{constructor(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new k(e):e,this.defaultRequestOptions=h({},t,{headers:h({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}accountBalance(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))}accountSummary(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))}accountInformation(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))}accountValue4Value(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))}incomingInvoices(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))}outgoingInvoices(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))}getInvoice(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:`/invoices/${e}`,method:"GET"}))}createInvoice(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))}keysend(e,t){let n,s;return Array.isArray(e)?(n="/payments/keysend/multi",s={keysends:e}):(n="/payments/keysend",s=e),g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:s,method:"POST"}))}sendPayment(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))}sendBoostagram(e,t){let n,s;return Array.isArray(e)?(n="/payments/keysend/multi",s={keysends:e.map(e=>A(e))}):(n="/payments/keysend",s=A(e)),g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:s,method:"POST"}))}sendToAlbyAccount(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))}createWebhookEndpoint(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))}deleteWebhookEndpoint(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:`/webhook_endpoints/${e}`,method:"DELETE"}))}}var U={__proto__:null,NostrWebLNProvider:T,NWC:q,OauthWeblnProvider:class{constructor(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new x(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}on(e,t){this.subscribers[e]=t}notify(e,t){const n=this.subscribers[e];n&&n(t)}async enable(){var e;if(!this.isExecuting){if(null!=(e=this.auth.token)&&e.access_token)return{enabled:!0};if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");try{this.isExecuting=!0,await this.openAuthorization()}finally{this.isExecuting=!1}}}async sendPayment(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.sendPayment({invoice:e});if(t.error)throw new Error(t.message);return this.notify("sendPayment",t),{preimage:t.payment_preimage}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}async keysend(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.keysend(e);if(t.error)throw new Error(t.message);return this.notify("keysend",t),{preimage:t.payment_preimage}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}async getInfo(){return{alias:"Alby"}}async makeInvoice(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo});return this.notify("makeInvoice",t),{paymentRequest:t.payment_request}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}openAuthorization(){var e=this;const t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,s=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise((r,o)=>{const i=window.open(s,`${document.title} - WebLN enable`,`height=700,width=600,top=${t},left=${n}`);let a=!1;window.addEventListener("message",async function(t){const n=t.data;if(n&&"alby:oauth:success"===n.type&&t.origin===`${document.location.protocol}//${document.location.host}`&&!a){a=!0,console.info("Processing OAuth code response");const t=n.payload.code;try{await e.auth.requestAccessToken(t),e.client=new x(e.auth),i&&i.close(),e.notify("enable"),r({enabled:!0})}catch(e){console.error(e),o({enabled:!1})}}})})}}};export{x as Client,E as auth,P as types,U as webln}; | ||
import e from"crypto-js";import t from"cross-fetch";import{generatePrivateKey as n,relayInit as s,nip19 as r,getPublicKey as o,signEvent as i,getEventHash as a,nip04 as c}from"nostr-tools";function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},h.apply(this,arguments)}function u(e,t){if(null==e)return{};var n,s,r={},o=Object.keys(e);for(s=0;s<o.length;s++)t.indexOf(n=o[s])>=0||(r[n]=e[n]);return r}function l(e){return Object.entries(e).map(([e,t])=>e&&t?`${e}=${t}`:"").join("&")}function d(e,t){return`Basic ${btoa(`${e}:${t}`)}`}const p=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],m="https://api.getalby.com";async function y(e,n,s=0){const r=await t(e,n);if(429===r.status&&s>0){const t=Number(r.headers.get("x-rate-limit-reset")),o=Number(r.headers.get("x-rate-limit-remaining")),i=1e3*t-Date.now();let a=1e3;return 0===o&&(a=i),await new Promise(e=>setTimeout(e,a)),y(e,n,s-1)}return r}class w extends Error{constructor(e,t,n,s){super(),this.status=void 0,this.statusText=void 0,this.headers=void 0,this.error=void 0,this.status=e,this.statusText=t,this.headers=n,this.error=s}}async function f(e){let{auth:t,endpoint:n,params:s={},request_body:r,method:o,max_retries:i,base_url:a=m,headers:c}=e,d=u(e,p);const f=new URL(a+n);f.search=l(s);const g="POST"===o&&!!r,b=t?await t.getAuthHeader(f.href,o):void 0,v=await y(f.toString(),h({headers:h({},g?{"Content-Type":"application/json; charset=utf-8"}:void 0,b,c),method:o,body:g?JSON.stringify(r):void 0},d),i);if(!v.ok){const e=await v.json();throw new w(v.status,v.statusText,v.headers,e)}return v}async function g(e){return(await f(e)).json()}const b=["expires_in"],v=["token"];function _(e){const{expires_in:t}=e;return h({},u(e,b),!!t&&{expires_at:Date.now()+1e3*t})}class k{constructor(e){this.bearer_token=void 0,this.bearer_token=e}getAuthHeader(){return{Authorization:`Bearer ${this.bearer_token}`}}}var E={__proto__:null,OAuth2User:class{constructor(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;const{token:t}=e,n=u(e,v);this.options=h({client_secret:""},n),this.token=t}async refreshAccessToken(){var e;const t=null==(e=this.token)?void 0:e.refresh_token,{client_id:n,client_secret:s,request_options:r}=this.options;if(!n)throw new Error("client_id is required");if(!t)throw new Error("refresh_token is required");const o=_(await g(h({},r,{endpoint:"/oauth/token",params:{client_id:n,grant_type:"refresh_token",refresh_token:t},method:"POST",headers:h({},null==r?void 0:r.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:d(n,s)})})));return this.token=o,{token:o}}isAccessTokenExpired(){var e,t;const n=null==(e=this.token)?void 0:e.refresh_token,s=null==(t=this.token)?void 0:t.expires_at;return!s||!!n&&s<=Date.now()+1e3}async requestAccessToken(e){const{client_id:t,client_secret:n,callback:s,request_options:r}=this.options,o=this.code_verifier;if(!t)throw new Error("client_id is required");if(!s)throw new Error("callback is required");const i={code:e,grant_type:"authorization_code",code_verifier:o,client_id:t,redirect_uri:s},a=_(await g(h({},r,{endpoint:"/oauth/token",params:i,method:"POST",headers:h({},null==r?void 0:r.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:d(t,n)})})));return this.token=a,{token:a}}generateAuthURL(t){t||(t={}),console.log(t);const{client_id:n,callback:s,scopes:r}=this.options;if(!s)throw new Error("callback required");if(!r)throw new Error("scopes required");let o;if("S256"===t.code_challenge_method){const t=e.lib.WordArray.random(64);this.code_verifier=t.toString(),this.code_challenge=e.SHA256(this.code_verifier).toString(e.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),o="S256"}else"plain"===t.code_challenge_method&&t.code_challenge&&(this.code_challenge=t.code_challenge,this.code_verifier=t.code_challenge,o="plain");const i=this.code_challenge,a=new URL("https://getalby.com/oauth");return a.search=l(h({},t,{client_id:n,scope:r.join(" "),response_type:"code",redirect_uri:s,code_challenge_method:o,code_challenge:i})),a.toString()}async getAuthHeader(){var e;if(null==(e=this.token)||!e.access_token)throw new Error("access_token is required");return this.isAccessTokenExpired()&&await this.refreshAccessToken(),{Authorization:`Bearer ${this.token.access_token}`}}},OAuth2Bearer:k},P={__proto__:null,OAuthClient:class{},AuthClient:class{}};const O={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}};class T{static parseWalletConnectUrl(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");const t=new URL(e),n={};n.walletPubkey=t.host;const s=t.searchParams.get("secret"),r=t.searchParams.get("relay");return s&&(n.secret=s),r&&(n.relayUrl=r),n}static withNewSecret(e){return(e=e||{}).secret=n(),new T(e)}constructor(e){var t;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,e&&e.nostrWalletConnectUrl&&(e=h({},T.parseWalletConnectUrl(e.nostrWalletConnectUrl),e));const n=O[(null==(t=e)?void 0:t.providerName)||"alby"];this.options=h({},n,e||{}),this.relayUrl=this.options.relayUrl,this.relay=s(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?r.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?r.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}on(e,t){this.subscribers[e]=t}notify(e,t){const n=this.subscribers[e];n&&n(t)}getNostrWalletConnectUrl(e=!0){let t=`nostr+walletconnect://${this.walletPubkey}?relay=${this.relayUrl}&pubkey=${this.publicKey}`;return e&&(t=`${t}&secret=${this.secret}`),t}get nostrWalletConnectUrl(){return this.getNostrWalletConnectUrl()}get connected(){return 1===this.relay.status}get publicKey(){if(!this.secret)throw new Error("Missing secret key");return o(this.secret)}signEvent(e){if(!this.secret)throw new Error("Missing secret key");return i(e,this.secret)}getEventHash(e){return a(e)}async enable(){if(this.connected)return Promise.resolve();await this.relay.connect()}close(){return this.relay.close()}async encrypt(e,t){if(!this.secret)throw new Error("Missing secret");return await c.encrypt(this.secret,e,t)}async decrypt(e,t){if(!this.secret)throw new Error("Missing secret");return await c.decrypt(this.secret,e,t)}async getInfo(){return{methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"}}sendPayment(e){var t=this;return this.checkConnected(),new Promise(async function(n,s){const r={method:"pay_invoice",params:{invoice:e}},o=await t.encrypt(t.walletPubkey,JSON.stringify(r));let i={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:o};i.pubkey=t.publicKey,i.id=t.getEventHash(i),i.sig=t.signEvent(i);let a=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[i.id]}]),c=setTimeout(function(){a.unsub(),s({error:`reply timeout: event ${i.id}`,code:"INTERNAL"})},6e4);a.on("event",async function(e){var r;clearTimeout(c),a.unsub();const o=await t.decrypt(t.walletPubkey,e.content);let i;try{i=JSON.parse(o)}catch(e){return void s({error:"invalid response",code:"INTERNAL"})}var h,u;23195==e.kind&&null!=(r=i.result)&&r.preimage?(n({preimage:i.result.preimage}),t.notify("sendPayment",e.content)):s({error:null==(h=i.error)?void 0:h.message,code:null==(u=i.error)?void 0:u.code})});let h=t.relay.publish(i),u=setTimeout(function(){s({error:`Publish timeout: event ${i.id}`})},5e3);h.on("failed",e=>{clearTimeout(u),s({error:`Failed to publish request: ${e}`})}),h.on("ok",()=>{clearTimeout(u)})})}getAuthorizationUrl(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");const t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t}initNWC(e={}){e.name||(e.name=document.location.host);const t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,s=window.outerWidth/2+window.screenX-200;return new Promise((e,r)=>{const o=window.open(t.toString(),`${document.title} - Wallet Connect`,`height=600,width=400,top=${n},left=${s}`);if(!o)return void r();const i=n=>{const s=n.data;s&&"nwc:success"===s.type&&n.origin===`${t.protocol}//${t.host}`&&(e(s),clearInterval(a),window.removeEventListener("message",i),o&&o.close())},a=setInterval(()=>{o&&o.closed&&(r(),clearInterval(a),window.removeEventListener("message",i))},500);window.addEventListener("message",i)})}checkConnected(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")}}const q=T;function A(e){const t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}class x{constructor(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new k(e):e,this.defaultRequestOptions=h({},t,{headers:h({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}accountBalance(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))}accountSummary(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))}accountInformation(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))}accountValue4Value(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))}incomingInvoices(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))}outgoingInvoices(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))}getInvoice(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:`/invoices/${e}`,method:"GET"}))}createInvoice(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))}keysend(e,t){let n,s;return Array.isArray(e)?(n="/payments/keysend/multi",s={keysends:e}):(n="/payments/keysend",s=e),g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:s,method:"POST"}))}sendPayment(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))}sendBoostagram(e,t){let n,s;return Array.isArray(e)?(n="/payments/keysend/multi",s={keysends:e.map(e=>A(e))}):(n="/payments/keysend",s=A(e)),g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:s,method:"POST"}))}sendToAlbyAccount(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))}createWebhookEndpoint(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))}deleteWebhookEndpoint(e,t){return g(h({auth:this.auth},this.defaultRequestOptions,t,{endpoint:`/webhook_endpoints/${e}`,method:"DELETE"}))}}var U={__proto__:null,NostrWebLNProvider:T,NWC:q,OauthWeblnProvider:class{constructor(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new x(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}on(e,t){this.subscribers[e]=t}notify(e,t){const n=this.subscribers[e];n&&n(t)}async enable(){var e;if(!this.isExecuting){if(null!=(e=this.auth.token)&&e.access_token)return{enabled:!0};if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");try{this.isExecuting=!0,await this.openAuthorization()}finally{this.isExecuting=!1}}}async sendPayment(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.sendPayment({invoice:e});if(t.error)throw new Error(t.message);return this.notify("sendPayment",t),{preimage:t.payment_preimage}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}async keysend(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.keysend(e);if(t.error)throw new Error(t.message);return this.notify("keysend",t),{preimage:t.payment_preimage}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}async getInfo(){return{alias:"Alby"}}async makeInvoice(e){if(!this.isExecuting)try{this.isExecuting=!0;const t=await this.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo});return this.notify("makeInvoice",t),{paymentRequest:t.payment_request}}catch(e){let t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)}finally{this.isExecuting=!1}}openAuthorization(){var e=this;const t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,s=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise((r,o)=>{const i=window.open(s,`${document.title} - WebLN enable`,`height=700,width=600,top=${t},left=${n}`);let a=!1;window.addEventListener("message",async function(t){const n=t.data;if(n&&"alby:oauth:success"===n.type&&t.origin===`${document.location.protocol}//${document.location.host}`&&!a){a=!0,console.info("Processing OAuth code response");const t=n.payload.code;try{await e.auth.requestAccessToken(t),e.client=new x(e.auth),i&&i.close(),e.notify("enable"),r({enabled:!0})}catch(e){console.error(e),o({enabled:!1})}}})})}}};export{x as Client,E as auth,P as types,U as webln}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import e from"crypto-js";import t from"cross-fetch";import{generatePrivateKey as n,relayInit as r,nip19 as o,signEvent as i,getEventHash as s,nip04 as u,getPublicKey as c}from"nostr-tools";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(this,arguments)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function f(e,t,n){return f=d()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&l(o,n.prototype),o},f.apply(null,arguments)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return f(e,arguments,h(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,e)},p(e)}function m(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}function v(e){return Object.entries(e).map(function(e){var t=e[0],n=e[1];return t&&n?t+"="+n:""}).join("&")}function y(e,t){return"Basic "+btoa(e+":"+t)}var w=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],b=function(e){return Promise.resolve(g(e)).then(function(e){return e.json()})},g=function(e){var t=e.auth,n=e.endpoint,r=e.params,o=void 0===r?{}:r,i=e.request_body,s=e.method,u=e.max_retries,c=e.base_url,h=void 0===c?_:c,l=e.headers,d=m(e,w);try{var f=function(e){return Promise.resolve(P(p.toString(),a({headers:a({},y?{"Content-Type":"application/json; charset=utf-8"}:void 0,e,l),method:s,body:y?JSON.stringify(i):void 0},d),u)).then(function(e){var t=function(){if(!e.ok)return Promise.resolve(e.json()).then(function(t){throw new k(e.status,e.statusText,e.headers,t)})}();return t&&t.then?t.then(function(t){return e}):e})},p=new URL(h+n);p.search=v(o);var y="POST"===s&&!!i;return Promise.resolve(t?Promise.resolve(t.getAuthHeader(p.href,s)).then(f):f(void 0))}catch(e){return Promise.reject(e)}},P=function e(n,r,o){void 0===o&&(o=0);try{return Promise.resolve(t(n,r)).then(function(t){var i,s=function(){if(429===t.status&&o>0){var s=Number(t.headers.get("x-rate-limit-reset")),u=Number(t.headers.get("x-rate-limit-remaining")),c=1e3*s-Date.now(),a=1e3;return 0===u&&(a=c),Promise.resolve(new Promise(function(e){return setTimeout(e,a)})).then(function(){var t=e(n,r,o-1);return i=1,t})}}();return s&&s.then?s.then(function(e){return i?e:t}):i?s:t})}catch(e){return Promise.reject(e)}},_="https://api.getalby.com",k=/*#__PURE__*/function(e){var t,n;function r(t,n,r,o){var i;return(i=e.call(this)||this).status=void 0,i.statusText=void 0,i.headers=void 0,i.error=void 0,i.status=t,i.statusText=n,i.headers=r,i.error=o,i}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,l(t,n),r}(/*#__PURE__*/p(Error)),E=["expires_in"],O=["token"];function T(e){var t=e.expires_in;return a({},m(e,E),!!t&&{expires_at:Date.now()+1e3*t})}var j=/*#__PURE__*/function(){function t(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;var t=e.token,n=m(e,O);this.options=a({client_secret:""},n),this.token=t}var n=t.prototype;return n.refreshAccessToken=function(){try{var e,t=this,n=null==(e=t.token)?void 0:e.refresh_token,r=t.options,o=r.client_id,i=r.client_secret,s=r.request_options;if(!o)throw new Error("client_id is required");if(!n)throw new Error("refresh_token is required");return Promise.resolve(b(a({},s,{endpoint:"/oauth/token",params:{client_id:o,grant_type:"refresh_token",refresh_token:n},method:"POST",headers:a({},null==s?void 0:s.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:y(o,i)})}))).then(function(e){var n=T(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},n.isAccessTokenExpired=function(){var e,t,n=null==(e=this.token)?void 0:e.refresh_token,r=null==(t=this.token)?void 0:t.expires_at;return!r||!!n&&r<=Date.now()+1e3},n.requestAccessToken=function(e){try{var t=this,n=t.options,r=n.client_id,o=n.client_secret,i=n.callback,s=n.request_options,u=t.code_verifier;if(!r)throw new Error("client_id is required");if(!i)throw new Error("callback is required");return Promise.resolve(b(a({},s,{endpoint:"/oauth/token",params:{code:e,grant_type:"authorization_code",code_verifier:u,client_id:r,redirect_uri:i},method:"POST",headers:a({},null==s?void 0:s.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:y(r,o)})}))).then(function(e){var n=T(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},n.generateAuthURL=function(t){t||(t={}),console.log(t);var n,r=this.options,o=r.client_id,i=r.callback,s=r.scopes;if(!i)throw new Error("callback required");if(!s)throw new Error("scopes required");if("S256"===t.code_challenge_method){var u=e.lib.WordArray.random(64);this.code_verifier=u.toString(),this.code_challenge=e.SHA256(this.code_verifier).toString(e.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),n="S256"}else"plain"===t.code_challenge_method&&t.code_challenge&&(this.code_challenge=t.code_challenge,this.code_verifier=t.code_challenge,n="plain");var c=this.code_challenge,h=new URL("https://getalby.com/oauth");return h.search=v(a({},t,{client_id:o,scope:s.join(" "),response_type:"code",redirect_uri:i,code_challenge_method:n,code_challenge:c})),h.toString()},n.getAuthHeader=function(){try{var e,t=function(){return{Authorization:"Bearer "+n.token.access_token}},n=this;if(null==(e=n.token)||!e.access_token)throw new Error("access_token is required");var r=function(){if(n.isAccessTokenExpired())return Promise.resolve(n.refreshAccessToken()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},t}(),q=/*#__PURE__*/function(){function e(e){this.bearer_token=void 0,this.bearer_token=e}return e.prototype.getAuthHeader=function(){return{Authorization:"Bearer "+this.bearer_token}},e}(),A={__proto__:null,OAuth2User:j,OAuth2Bearer:q},x={__proto__:null,OAuthClient:function(){},AuthClient:function(){}},R={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}},U=/*#__PURE__*/function(){function e(t){var n;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,t&&t.nostrWalletConnectUrl&&(t=a({},e.parseWalletConnectUrl(t.nostrWalletConnectUrl),t));var i=R[(null==(n=t)?void 0:n.providerName)||"alby"];this.options=a({},i,t||{}),this.relayUrl=this.options.relayUrl,this.relay=r(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?o.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?o.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}e.parseWalletConnectUrl=function(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");var t=new URL(e),n={};n.walletPubkey=t.host;var r=t.searchParams.get("secret"),o=t.searchParams.get("relay");return r&&(n.secret=r),o&&(n.relayUrl=o),n},e.withNewSecret=function(t){return(t=t||{}).secret=n(),new e(t)};var t,h,l=e.prototype;return l.on=function(e,t){this.subscribers[e]=t},l.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},l.getNostrWalletConnectUrl=function(e){void 0===e&&(e=!0);var t="nostr+walletconnect://"+this.walletPubkey+"?relay="+this.relayUrl+"&pubkey="+this.publicKey;return e&&(t=t+"&secret="+this.secret),t},l.signEvent=function(e){if(!this.secret)throw new Error("Missing secret key");return i(e,this.secret)},l.getEventHash=function(e){return s(e)},l.enable=function(){try{return this.connected?Promise.resolve():Promise.resolve(this.relay.connect()).then(function(){})}catch(e){return Promise.reject(e)}},l.close=function(){return this.relay.close()},l.encrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(u.encrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},l.decrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(u.decrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},l.getInfo=function(){try{return Promise.resolve({methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"})}catch(e){return Promise.reject(e)}},l.sendPayment=function(e){var t=this;return this.checkConnected(),new Promise(function(n,r){try{return Promise.resolve(t.encrypt(t.walletPubkey,JSON.stringify({method:"pay_invoice",params:{invoice:e}}))).then(function(e){var o={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:e};o.pubkey=t.publicKey,o.id=t.getEventHash(o),o.sig=t.signEvent(o);var i=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[o.id]}]),s=setTimeout(function(){i.unsub(),r("reply timeout: event "+o.id)},6e4);i.on("event",function(e){try{return clearTimeout(s),i.unsub(),Promise.resolve(t.decrypt(t.walletPubkey,e.content)).then(function(o){var i,s,u,c;try{s=JSON.parse(o)}catch(e){return void r({error:"invalid response",code:"INTERNAL"})}23195==e.kind&&null!=(i=s.result)&&i.preimage?(n({preimage:s.result.preimage}),t.notify("sendPayment",e.content)):r({error:null==(u=s.error)?void 0:u.message,code:null==(c=s.error)?void 0:c.code})})}catch(e){return Promise.reject(e)}});var u=t.relay.publish(o),c=setTimeout(function(){r({error:"Publish timeout: event "+o.id})},5e3);u.on("failed",function(e){clearTimeout(c),r({error:"Failed to publish request: "+e})}),u.on("ok",function(){clearTimeout(c)})})}catch(e){return Promise.reject(e)}})},l.getAuthorizationUrl=function(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");var t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t},l.initNWC=function(e){void 0===e&&(e={}),e.name||(e.name=document.location.host);var t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,r=window.outerWidth/2+window.screenX-200;return new Promise(function(e,o){var i=window.open(t.toString(),document.title+" - Wallet Connect","height=600,width=400,top="+n+",left="+r);if(i){var s=function n(r){var o=r.data;o&&"nwc:success"===o.type&&r.origin===t.protocol+"//"+t.host&&(e(o),clearInterval(u),window.removeEventListener("message",n),i&&i.close())},u=setInterval(function(){i&&i.closed&&(o(),clearInterval(u),window.removeEventListener("message",s))},500);window.addEventListener("message",s)}else o()})},l.checkConnected=function(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")},t=e,(h=[{key:"nostrWalletConnectUrl",get:function(){return this.getNostrWalletConnectUrl()}},{key:"connected",get:function(){return 1===this.relay.status}},{key:"publicKey",get:function(){if(!this.secret)throw new Error("Missing secret key");return c(this.secret)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,h),Object.defineProperty(t,"prototype",{writable:!1}),e}(),S=U;function W(e){var t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}var C=/*#__PURE__*/function(){function e(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new q(e):e,this.defaultRequestOptions=a({},t,{headers:a({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}var t=e.prototype;return t.accountBalance=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))},t.accountSummary=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))},t.accountInformation=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))},t.accountValue4Value=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))},t.incomingInvoices=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))},t.outgoingInvoices=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))},t.getInvoice=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/"+e,method:"GET"}))},t.createInvoice=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))},t.keysend=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e}):(n="/payments/keysend",r=e),b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendPayment=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))},t.sendBoostagram=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e.map(function(e){return W(e)})}):(n="/payments/keysend",r=W(e)),b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendToAlbyAccount=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))},t.createWebhookEndpoint=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))},t.deleteWebhookEndpoint=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints/"+e,method:"DELETE"}))},e}();function N(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}function I(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var L={__proto__:null,NostrWebLNProvider:U,NWC:S,OauthWeblnProvider:/*#__PURE__*/function(){function e(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new C(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}var t=e.prototype;return t.on=function(e,t){this.subscribers[e]=t},t.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},t.enable=function(){try{var e,t=this;return t.isExecuting?Promise.resolve():null!=(e=t.auth.token)&&e.access_token?Promise.resolve({enabled:!0}):Promise.resolve(function(){if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");var e=N(function(){return t.isExecuting=!0,Promise.resolve(t.openAuthorization()).then(function(){})},function(e,n){if(t.isExecuting=!1,e)throw n;return n});if(e&&e.then)return e.then(function(){})}())}catch(e){return Promise.reject(e)}},t.sendPayment=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.sendPayment({invoice:e})).then(function(e){if(e.error)throw new Error(e.message);return t.notify("sendPayment",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.keysend=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.keysend(e)).then(function(e){if(e.error)throw new Error(e.message);return t.notify("keysend",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.getInfo=function(){try{return Promise.resolve({alias:"Alby"})}catch(e){return Promise.reject(e)}},t.makeInvoice=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo})).then(function(e){return t.notify("makeInvoice",e),{paymentRequest:e.payment_request}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.openAuthorization=function(){var e=this,t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,r=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise(function(o,i){var s=window.open(r,document.title+" - WebLN enable","height=700,width=600,top="+t+",left="+n),u=!1;window.addEventListener("message",function(t){try{var n=t.data,r=function(){if(n&&"alby:oauth:success"===n.type&&t.origin===document.location.protocol+"//"+document.location.host&&!u){u=!0,console.info("Processing OAuth code response");var r=n.payload.code,c=I(function(){return Promise.resolve(e.auth.requestAccessToken(r)).then(function(){e.client=new C(e.auth),s&&s.close(),e.notify("enable"),o({enabled:!0})})},function(e){console.error(e),i({enabled:!1})});if(c&&c.then)return c.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})})},e}()};export{C as Client,A as auth,x as types,L as webln}; | ||
import e from"crypto-js";import t from"cross-fetch";import{generatePrivateKey as n,relayInit as r,nip19 as o,signEvent as i,getEventHash as s,nip04 as u,getPublicKey as c}from"nostr-tools";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(this,arguments)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function f(e,t,n){return f=d()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&l(o,n.prototype),o},f.apply(null,arguments)}function p(e){var t="function"==typeof Map?new Map:void 0;return p=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return f(e,arguments,h(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),l(n,e)},p(e)}function m(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}function v(e){return Object.entries(e).map(function(e){var t=e[0],n=e[1];return t&&n?t+"="+n:""}).join("&")}function y(e,t){return"Basic "+btoa(e+":"+t)}var w=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],b=function(e){return Promise.resolve(g(e)).then(function(e){return e.json()})},g=function(e){var t=e.auth,n=e.endpoint,r=e.params,o=void 0===r?{}:r,i=e.request_body,s=e.method,u=e.max_retries,c=e.base_url,h=void 0===c?_:c,l=e.headers,d=m(e,w);try{var f=function(e){return Promise.resolve(P(p.toString(),a({headers:a({},y?{"Content-Type":"application/json; charset=utf-8"}:void 0,e,l),method:s,body:y?JSON.stringify(i):void 0},d),u)).then(function(e){var t=function(){if(!e.ok)return Promise.resolve(e.json()).then(function(t){throw new k(e.status,e.statusText,e.headers,t)})}();return t&&t.then?t.then(function(t){return e}):e})},p=new URL(h+n);p.search=v(o);var y="POST"===s&&!!i;return Promise.resolve(t?Promise.resolve(t.getAuthHeader(p.href,s)).then(f):f(void 0))}catch(e){return Promise.reject(e)}},P=function e(n,r,o){void 0===o&&(o=0);try{return Promise.resolve(t(n,r)).then(function(t){var i,s=function(){if(429===t.status&&o>0){var s=Number(t.headers.get("x-rate-limit-reset")),u=Number(t.headers.get("x-rate-limit-remaining")),c=1e3*s-Date.now(),a=1e3;return 0===u&&(a=c),Promise.resolve(new Promise(function(e){return setTimeout(e,a)})).then(function(){var t=e(n,r,o-1);return i=1,t})}}();return s&&s.then?s.then(function(e){return i?e:t}):i?s:t})}catch(e){return Promise.reject(e)}},_="https://api.getalby.com",k=/*#__PURE__*/function(e){var t,n;function r(t,n,r,o){var i;return(i=e.call(this)||this).status=void 0,i.statusText=void 0,i.headers=void 0,i.error=void 0,i.status=t,i.statusText=n,i.headers=r,i.error=o,i}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,l(t,n),r}(/*#__PURE__*/p(Error)),E=["expires_in"],O=["token"];function T(e){var t=e.expires_in;return a({},m(e,E),!!t&&{expires_at:Date.now()+1e3*t})}var j=/*#__PURE__*/function(){function t(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;var t=e.token,n=m(e,O);this.options=a({client_secret:""},n),this.token=t}var n=t.prototype;return n.refreshAccessToken=function(){try{var e,t=this,n=null==(e=t.token)?void 0:e.refresh_token,r=t.options,o=r.client_id,i=r.client_secret,s=r.request_options;if(!o)throw new Error("client_id is required");if(!n)throw new Error("refresh_token is required");return Promise.resolve(b(a({},s,{endpoint:"/oauth/token",params:{client_id:o,grant_type:"refresh_token",refresh_token:n},method:"POST",headers:a({},null==s?void 0:s.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:y(o,i)})}))).then(function(e){var n=T(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},n.isAccessTokenExpired=function(){var e,t,n=null==(e=this.token)?void 0:e.refresh_token,r=null==(t=this.token)?void 0:t.expires_at;return!r||!!n&&r<=Date.now()+1e3},n.requestAccessToken=function(e){try{var t=this,n=t.options,r=n.client_id,o=n.client_secret,i=n.callback,s=n.request_options,u=t.code_verifier;if(!r)throw new Error("client_id is required");if(!i)throw new Error("callback is required");return Promise.resolve(b(a({},s,{endpoint:"/oauth/token",params:{code:e,grant_type:"authorization_code",code_verifier:u,client_id:r,redirect_uri:i},method:"POST",headers:a({},null==s?void 0:s.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:y(r,o)})}))).then(function(e){var n=T(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},n.generateAuthURL=function(t){t||(t={}),console.log(t);var n,r=this.options,o=r.client_id,i=r.callback,s=r.scopes;if(!i)throw new Error("callback required");if(!s)throw new Error("scopes required");if("S256"===t.code_challenge_method){var u=e.lib.WordArray.random(64);this.code_verifier=u.toString(),this.code_challenge=e.SHA256(this.code_verifier).toString(e.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),n="S256"}else"plain"===t.code_challenge_method&&t.code_challenge&&(this.code_challenge=t.code_challenge,this.code_verifier=t.code_challenge,n="plain");var c=this.code_challenge,h=new URL("https://getalby.com/oauth");return h.search=v(a({},t,{client_id:o,scope:s.join(" "),response_type:"code",redirect_uri:i,code_challenge_method:n,code_challenge:c})),h.toString()},n.getAuthHeader=function(){try{var e,t=function(){return{Authorization:"Bearer "+n.token.access_token}},n=this;if(null==(e=n.token)||!e.access_token)throw new Error("access_token is required");var r=function(){if(n.isAccessTokenExpired())return Promise.resolve(n.refreshAccessToken()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},t}(),q=/*#__PURE__*/function(){function e(e){this.bearer_token=void 0,this.bearer_token=e}return e.prototype.getAuthHeader=function(){return{Authorization:"Bearer "+this.bearer_token}},e}(),A={__proto__:null,OAuth2User:j,OAuth2Bearer:q},x={__proto__:null,OAuthClient:function(){},AuthClient:function(){}},R={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}},U=/*#__PURE__*/function(){function e(t){var n;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,t&&t.nostrWalletConnectUrl&&(t=a({},e.parseWalletConnectUrl(t.nostrWalletConnectUrl),t));var i=R[(null==(n=t)?void 0:n.providerName)||"alby"];this.options=a({},i,t||{}),this.relayUrl=this.options.relayUrl,this.relay=r(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?o.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?o.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}e.parseWalletConnectUrl=function(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");var t=new URL(e),n={};n.walletPubkey=t.host;var r=t.searchParams.get("secret"),o=t.searchParams.get("relay");return r&&(n.secret=r),o&&(n.relayUrl=o),n},e.withNewSecret=function(t){return(t=t||{}).secret=n(),new e(t)};var t,h,l=e.prototype;return l.on=function(e,t){this.subscribers[e]=t},l.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},l.getNostrWalletConnectUrl=function(e){void 0===e&&(e=!0);var t="nostr+walletconnect://"+this.walletPubkey+"?relay="+this.relayUrl+"&pubkey="+this.publicKey;return e&&(t=t+"&secret="+this.secret),t},l.signEvent=function(e){if(!this.secret)throw new Error("Missing secret key");return i(e,this.secret)},l.getEventHash=function(e){return s(e)},l.enable=function(){try{return this.connected?Promise.resolve():Promise.resolve(this.relay.connect()).then(function(){})}catch(e){return Promise.reject(e)}},l.close=function(){return this.relay.close()},l.encrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(u.encrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},l.decrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(u.decrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},l.getInfo=function(){try{return Promise.resolve({methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"})}catch(e){return Promise.reject(e)}},l.sendPayment=function(e){var t=this;return this.checkConnected(),new Promise(function(n,r){try{return Promise.resolve(t.encrypt(t.walletPubkey,JSON.stringify({method:"pay_invoice",params:{invoice:e}}))).then(function(e){var o={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:e};o.pubkey=t.publicKey,o.id=t.getEventHash(o),o.sig=t.signEvent(o);var i=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[o.id]}]),s=setTimeout(function(){i.unsub(),r({error:"reply timeout: event "+o.id,code:"INTERNAL"})},6e4);i.on("event",function(e){try{return clearTimeout(s),i.unsub(),Promise.resolve(t.decrypt(t.walletPubkey,e.content)).then(function(o){var i,s,u,c;try{s=JSON.parse(o)}catch(e){return void r({error:"invalid response",code:"INTERNAL"})}23195==e.kind&&null!=(i=s.result)&&i.preimage?(n({preimage:s.result.preimage}),t.notify("sendPayment",e.content)):r({error:null==(u=s.error)?void 0:u.message,code:null==(c=s.error)?void 0:c.code})})}catch(e){return Promise.reject(e)}});var u=t.relay.publish(o),c=setTimeout(function(){r({error:"Publish timeout: event "+o.id})},5e3);u.on("failed",function(e){clearTimeout(c),r({error:"Failed to publish request: "+e})}),u.on("ok",function(){clearTimeout(c)})})}catch(e){return Promise.reject(e)}})},l.getAuthorizationUrl=function(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");var t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t},l.initNWC=function(e){void 0===e&&(e={}),e.name||(e.name=document.location.host);var t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,r=window.outerWidth/2+window.screenX-200;return new Promise(function(e,o){var i=window.open(t.toString(),document.title+" - Wallet Connect","height=600,width=400,top="+n+",left="+r);if(i){var s=function n(r){var o=r.data;o&&"nwc:success"===o.type&&r.origin===t.protocol+"//"+t.host&&(e(o),clearInterval(u),window.removeEventListener("message",n),i&&i.close())},u=setInterval(function(){i&&i.closed&&(o(),clearInterval(u),window.removeEventListener("message",s))},500);window.addEventListener("message",s)}else o()})},l.checkConnected=function(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")},t=e,(h=[{key:"nostrWalletConnectUrl",get:function(){return this.getNostrWalletConnectUrl()}},{key:"connected",get:function(){return 1===this.relay.status}},{key:"publicKey",get:function(){if(!this.secret)throw new Error("Missing secret key");return c(this.secret)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,h),Object.defineProperty(t,"prototype",{writable:!1}),e}(),S=U;function W(e){var t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}var C=/*#__PURE__*/function(){function e(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new q(e):e,this.defaultRequestOptions=a({},t,{headers:a({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}var t=e.prototype;return t.accountBalance=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))},t.accountSummary=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))},t.accountInformation=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))},t.accountValue4Value=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))},t.incomingInvoices=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))},t.outgoingInvoices=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))},t.getInvoice=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/"+e,method:"GET"}))},t.createInvoice=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))},t.keysend=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e}):(n="/payments/keysend",r=e),b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendPayment=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))},t.sendBoostagram=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e.map(function(e){return W(e)})}):(n="/payments/keysend",r=W(e)),b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendToAlbyAccount=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))},t.createWebhookEndpoint=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))},t.deleteWebhookEndpoint=function(e,t){return b(a({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints/"+e,method:"DELETE"}))},e}();function N(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}function I(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var L={__proto__:null,NostrWebLNProvider:U,NWC:S,OauthWeblnProvider:/*#__PURE__*/function(){function e(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new C(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}var t=e.prototype;return t.on=function(e,t){this.subscribers[e]=t},t.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},t.enable=function(){try{var e,t=this;return t.isExecuting?Promise.resolve():null!=(e=t.auth.token)&&e.access_token?Promise.resolve({enabled:!0}):Promise.resolve(function(){if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");var e=N(function(){return t.isExecuting=!0,Promise.resolve(t.openAuthorization()).then(function(){})},function(e,n){if(t.isExecuting=!1,e)throw n;return n});if(e&&e.then)return e.then(function(){})}())}catch(e){return Promise.reject(e)}},t.sendPayment=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.sendPayment({invoice:e})).then(function(e){if(e.error)throw new Error(e.message);return t.notify("sendPayment",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.keysend=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.keysend(e)).then(function(e){if(e.error)throw new Error(e.message);return t.notify("keysend",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.getInfo=function(){try{return Promise.resolve({alias:"Alby"})}catch(e){return Promise.reject(e)}},t.makeInvoice=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(N(function(){return I(function(){return t.isExecuting=!0,Promise.resolve(t.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo})).then(function(e){return t.notify("makeInvoice",e),{paymentRequest:e.payment_request}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.openAuthorization=function(){var e=this,t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,r=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise(function(o,i){var s=window.open(r,document.title+" - WebLN enable","height=700,width=600,top="+t+",left="+n),u=!1;window.addEventListener("message",function(t){try{var n=t.data,r=function(){if(n&&"alby:oauth:success"===n.type&&t.origin===document.location.protocol+"//"+document.location.host&&!u){u=!0,console.info("Processing OAuth code response");var r=n.payload.code,c=I(function(){return Promise.resolve(e.auth.requestAccessToken(r)).then(function(){e.client=new C(e.auth),s&&s.close(),e.notify("enable"),o({enabled:!0})})},function(e){console.error(e),i({enabled:!1})});if(c&&c.then)return c.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})})},e}()};export{C as Client,A as auth,x as types,L as webln}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("crypto-js"),require("cross-fetch"),require("nostr-tools")):"function"==typeof define&&define.amd?define(["exports","crypto-js","cross-fetch","nostr-tools"],t):t((e||self).albyJsSdk={},e.cryptoJs,e.crossFetch,e.nostrTools)}(this,function(e,t,n,r){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/o(t),s=/*#__PURE__*/o(n);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function l(e,t,n){return l=h()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&a(o,n.prototype),o},l.apply(null,arguments)}function d(e){var t="function"==typeof Map?new Map:void 0;return d=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,e)},d(e)}function f(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}function p(e){return Object.entries(e).map(function(e){var t=e[0],n=e[1];return t&&n?t+"="+n:""}).join("&")}function m(e,t){return"Basic "+btoa(e+":"+t)}var v=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],y=function(e){return Promise.resolve(b(e)).then(function(e){return e.json()})},b=function(e){var t=e.auth,n=e.endpoint,r=e.params,o=void 0===r?{}:r,i=e.request_body,s=e.method,c=e.max_retries,a=e.base_url,h=void 0===a?g:a,l=e.headers,d=f(e,v);try{var m=function(e){return Promise.resolve(w(y.toString(),u({headers:u({},b?{"Content-Type":"application/json; charset=utf-8"}:void 0,e,l),method:s,body:b?JSON.stringify(i):void 0},d),c)).then(function(e){var t=function(){if(!e.ok)return Promise.resolve(e.json()).then(function(t){throw new P(e.status,e.statusText,e.headers,t)})}();return t&&t.then?t.then(function(t){return e}):e})},y=new URL(h+n);y.search=p(o);var b="POST"===s&&!!i;return Promise.resolve(t?Promise.resolve(t.getAuthHeader(y.href,s)).then(m):m(void 0))}catch(e){return Promise.reject(e)}},w=function e(t,n,r){void 0===r&&(r=0);try{return Promise.resolve(s.default(t,n)).then(function(o){var i,s=function(){if(429===o.status&&r>0){var s=Number(o.headers.get("x-rate-limit-reset")),u=Number(o.headers.get("x-rate-limit-remaining")),c=1e3*s-Date.now(),a=1e3;return 0===u&&(a=c),Promise.resolve(new Promise(function(e){return setTimeout(e,a)})).then(function(){var o=e(t,n,r-1);return i=1,o})}}();return s&&s.then?s.then(function(e){return i?e:o}):i?s:o})}catch(e){return Promise.reject(e)}},g="https://api.getalby.com",P=/*#__PURE__*/function(e){var t,n;function r(t,n,r,o){var i;return(i=e.call(this)||this).status=void 0,i.statusText=void 0,i.headers=void 0,i.error=void 0,i.status=t,i.statusText=n,i.headers=r,i.error=o,i}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,a(t,n),r}(/*#__PURE__*/d(Error)),_=["expires_in"],k=["token"];function E(e){var t=e.expires_in;return u({},f(e,_),!!t&&{expires_at:Date.now()+1e3*t})}var O=/*#__PURE__*/function(){function e(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;var t=e.token,n=f(e,k);this.options=u({client_secret:""},n),this.token=t}var t=e.prototype;return t.refreshAccessToken=function(){try{var e,t=this,n=null==(e=t.token)?void 0:e.refresh_token,r=t.options,o=r.client_id,i=r.client_secret,s=r.request_options;if(!o)throw new Error("client_id is required");if(!n)throw new Error("refresh_token is required");return Promise.resolve(y(u({},s,{endpoint:"/oauth/token",params:{client_id:o,grant_type:"refresh_token",refresh_token:n},method:"POST",headers:u({},null==s?void 0:s.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:m(o,i)})}))).then(function(e){var n=E(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},t.isAccessTokenExpired=function(){var e,t,n=null==(e=this.token)?void 0:e.refresh_token,r=null==(t=this.token)?void 0:t.expires_at;return!r||!!n&&r<=Date.now()+1e3},t.requestAccessToken=function(e){try{var t=this,n=t.options,r=n.client_id,o=n.client_secret,i=n.callback,s=n.request_options,c=t.code_verifier;if(!r)throw new Error("client_id is required");if(!i)throw new Error("callback is required");return Promise.resolve(y(u({},s,{endpoint:"/oauth/token",params:{code:e,grant_type:"authorization_code",code_verifier:c,client_id:r,redirect_uri:i},method:"POST",headers:u({},null==s?void 0:s.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:m(r,o)})}))).then(function(e){var n=E(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},t.generateAuthURL=function(e){e||(e={}),console.log(e);var t,n=this.options,r=n.client_id,o=n.callback,s=n.scopes;if(!o)throw new Error("callback required");if(!s)throw new Error("scopes required");if("S256"===e.code_challenge_method){var c=i.default.lib.WordArray.random(64);this.code_verifier=c.toString(),this.code_challenge=i.default.SHA256(this.code_verifier).toString(i.default.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),t="S256"}else"plain"===e.code_challenge_method&&e.code_challenge&&(this.code_challenge=e.code_challenge,this.code_verifier=e.code_challenge,t="plain");var a=this.code_challenge,h=new URL("https://getalby.com/oauth");return h.search=p(u({},e,{client_id:r,scope:s.join(" "),response_type:"code",redirect_uri:o,code_challenge_method:t,code_challenge:a})),h.toString()},t.getAuthHeader=function(){try{var e,t=function(){return{Authorization:"Bearer "+n.token.access_token}},n=this;if(null==(e=n.token)||!e.access_token)throw new Error("access_token is required");var r=function(){if(n.isAccessTokenExpired())return Promise.resolve(n.refreshAccessToken()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},e}(),T=/*#__PURE__*/function(){function e(e){this.bearer_token=void 0,this.bearer_token=e}return e.prototype.getAuthHeader=function(){return{Authorization:"Bearer "+this.bearer_token}},e}(),j={__proto__:null,OAuth2User:O,OAuth2Bearer:T},q={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}},x=/*#__PURE__*/function(){function e(t){var n;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,t&&t.nostrWalletConnectUrl&&(t=u({},e.parseWalletConnectUrl(t.nostrWalletConnectUrl),t));var o=q[(null==(n=t)?void 0:n.providerName)||"alby"];this.options=u({},o,t||{}),this.relayUrl=this.options.relayUrl,this.relay=r.relayInit(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?r.nip19.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?r.nip19.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}e.parseWalletConnectUrl=function(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");var t=new URL(e),n={};n.walletPubkey=t.host;var r=t.searchParams.get("secret"),o=t.searchParams.get("relay");return r&&(n.secret=r),o&&(n.relayUrl=o),n},e.withNewSecret=function(t){return(t=t||{}).secret=r.generatePrivateKey(),new e(t)};var t,n,o=e.prototype;return o.on=function(e,t){this.subscribers[e]=t},o.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},o.getNostrWalletConnectUrl=function(e){void 0===e&&(e=!0);var t="nostr+walletconnect://"+this.walletPubkey+"?relay="+this.relayUrl+"&pubkey="+this.publicKey;return e&&(t=t+"&secret="+this.secret),t},o.signEvent=function(e){if(!this.secret)throw new Error("Missing secret key");return r.signEvent(e,this.secret)},o.getEventHash=function(e){return r.getEventHash(e)},o.enable=function(){try{return this.connected?Promise.resolve():Promise.resolve(this.relay.connect()).then(function(){})}catch(e){return Promise.reject(e)}},o.close=function(){return this.relay.close()},o.encrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(r.nip04.encrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},o.decrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(r.nip04.decrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},o.getInfo=function(){try{return Promise.resolve({methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"})}catch(e){return Promise.reject(e)}},o.sendPayment=function(e){var t=this;return this.checkConnected(),new Promise(function(n,r){try{return Promise.resolve(t.encrypt(t.walletPubkey,JSON.stringify({method:"pay_invoice",params:{invoice:e}}))).then(function(e){var o={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:e};o.pubkey=t.publicKey,o.id=t.getEventHash(o),o.sig=t.signEvent(o);var i=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[o.id]}]),s=setTimeout(function(){i.unsub(),r("reply timeout: event "+o.id)},6e4);i.on("event",function(e){try{return clearTimeout(s),i.unsub(),Promise.resolve(t.decrypt(t.walletPubkey,e.content)).then(function(o){var i,s,u,c;try{s=JSON.parse(o)}catch(e){return void r({error:"invalid response",code:"INTERNAL"})}23195==e.kind&&null!=(i=s.result)&&i.preimage?(n({preimage:s.result.preimage}),t.notify("sendPayment",e.content)):r({error:null==(u=s.error)?void 0:u.message,code:null==(c=s.error)?void 0:c.code})})}catch(e){return Promise.reject(e)}});var u=t.relay.publish(o),c=setTimeout(function(){r({error:"Publish timeout: event "+o.id})},5e3);u.on("failed",function(e){clearTimeout(c),r({error:"Failed to publish request: "+e})}),u.on("ok",function(){clearTimeout(c)})})}catch(e){return Promise.reject(e)}})},o.getAuthorizationUrl=function(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");var t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t},o.initNWC=function(e){void 0===e&&(e={}),e.name||(e.name=document.location.host);var t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,r=window.outerWidth/2+window.screenX-200;return new Promise(function(e,o){var i=window.open(t.toString(),document.title+" - Wallet Connect","height=600,width=400,top="+n+",left="+r);if(i){var s=function n(r){var o=r.data;o&&"nwc:success"===o.type&&r.origin===t.protocol+"//"+t.host&&(e(o),clearInterval(u),window.removeEventListener("message",n),i&&i.close())},u=setInterval(function(){i&&i.closed&&(o(),clearInterval(u),window.removeEventListener("message",s))},500);window.addEventListener("message",s)}else o()})},o.checkConnected=function(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")},t=e,(n=[{key:"nostrWalletConnectUrl",get:function(){return this.getNostrWalletConnectUrl()}},{key:"connected",get:function(){return 1===this.relay.status}},{key:"publicKey",get:function(){if(!this.secret)throw new Error("Missing secret key");return r.getPublicKey(this.secret)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),A=x;function R(e){var t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}var U=/*#__PURE__*/function(){function e(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new T(e):e,this.defaultRequestOptions=u({},t,{headers:u({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}var t=e.prototype;return t.accountBalance=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))},t.accountSummary=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))},t.accountInformation=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))},t.accountValue4Value=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))},t.incomingInvoices=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))},t.outgoingInvoices=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))},t.getInvoice=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/"+e,method:"GET"}))},t.createInvoice=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))},t.keysend=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e}):(n="/payments/keysend",r=e),y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendPayment=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))},t.sendBoostagram=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e.map(function(e){return R(e)})}):(n="/payments/keysend",r=R(e)),y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendToAlbyAccount=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))},t.createWebhookEndpoint=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))},t.deleteWebhookEndpoint=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints/"+e,method:"DELETE"}))},e}();function S(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}function W(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var C={__proto__:null,NostrWebLNProvider:x,NWC:A,OauthWeblnProvider:/*#__PURE__*/function(){function e(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new U(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}var t=e.prototype;return t.on=function(e,t){this.subscribers[e]=t},t.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},t.enable=function(){try{var e,t=this;return t.isExecuting?Promise.resolve():null!=(e=t.auth.token)&&e.access_token?Promise.resolve({enabled:!0}):Promise.resolve(function(){if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");var e=S(function(){return t.isExecuting=!0,Promise.resolve(t.openAuthorization()).then(function(){})},function(e,n){if(t.isExecuting=!1,e)throw n;return n});if(e&&e.then)return e.then(function(){})}())}catch(e){return Promise.reject(e)}},t.sendPayment=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.sendPayment({invoice:e})).then(function(e){if(e.error)throw new Error(e.message);return t.notify("sendPayment",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.keysend=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.keysend(e)).then(function(e){if(e.error)throw new Error(e.message);return t.notify("keysend",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.getInfo=function(){try{return Promise.resolve({alias:"Alby"})}catch(e){return Promise.reject(e)}},t.makeInvoice=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo})).then(function(e){return t.notify("makeInvoice",e),{paymentRequest:e.payment_request}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.openAuthorization=function(){var e=this,t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,r=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise(function(o,i){var s=window.open(r,document.title+" - WebLN enable","height=700,width=600,top="+t+",left="+n),u=!1;window.addEventListener("message",function(t){try{var n=t.data,r=function(){if(n&&"alby:oauth:success"===n.type&&t.origin===document.location.protocol+"//"+document.location.host&&!u){u=!0,console.info("Processing OAuth code response");var r=n.payload.code,c=W(function(){return Promise.resolve(e.auth.requestAccessToken(r)).then(function(){e.client=new U(e.auth),s&&s.close(),e.notify("enable"),o({enabled:!0})})},function(e){console.error(e),i({enabled:!1})});if(c&&c.then)return c.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})})},e}()};e.Client=U,e.auth=j,e.types={__proto__:null,OAuthClient:function(){},AuthClient:function(){}},e.webln=C}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("crypto-js"),require("cross-fetch"),require("nostr-tools")):"function"==typeof define&&define.amd?define(["exports","crypto-js","cross-fetch","nostr-tools"],t):t((e||self).albyJsSdk={},e.cryptoJs,e.crossFetch,e.nostrTools)}(this,function(e,t,n,r){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/o(t),s=/*#__PURE__*/o(n);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},u.apply(this,arguments)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function h(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function l(e,t,n){return l=h()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&a(o,n.prototype),o},l.apply(null,arguments)}function d(e){var t="function"==typeof Map?new Map:void 0;return d=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return l(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,e)},d(e)}function f(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}function p(e){return Object.entries(e).map(function(e){var t=e[0],n=e[1];return t&&n?t+"="+n:""}).join("&")}function m(e,t){return"Basic "+btoa(e+":"+t)}var v=["auth","endpoint","params","request_body","method","max_retries","base_url","headers"],y=function(e){return Promise.resolve(b(e)).then(function(e){return e.json()})},b=function(e){var t=e.auth,n=e.endpoint,r=e.params,o=void 0===r?{}:r,i=e.request_body,s=e.method,c=e.max_retries,a=e.base_url,h=void 0===a?g:a,l=e.headers,d=f(e,v);try{var m=function(e){return Promise.resolve(w(y.toString(),u({headers:u({},b?{"Content-Type":"application/json; charset=utf-8"}:void 0,e,l),method:s,body:b?JSON.stringify(i):void 0},d),c)).then(function(e){var t=function(){if(!e.ok)return Promise.resolve(e.json()).then(function(t){throw new P(e.status,e.statusText,e.headers,t)})}();return t&&t.then?t.then(function(t){return e}):e})},y=new URL(h+n);y.search=p(o);var b="POST"===s&&!!i;return Promise.resolve(t?Promise.resolve(t.getAuthHeader(y.href,s)).then(m):m(void 0))}catch(e){return Promise.reject(e)}},w=function e(t,n,r){void 0===r&&(r=0);try{return Promise.resolve(s.default(t,n)).then(function(o){var i,s=function(){if(429===o.status&&r>0){var s=Number(o.headers.get("x-rate-limit-reset")),u=Number(o.headers.get("x-rate-limit-remaining")),c=1e3*s-Date.now(),a=1e3;return 0===u&&(a=c),Promise.resolve(new Promise(function(e){return setTimeout(e,a)})).then(function(){var o=e(t,n,r-1);return i=1,o})}}();return s&&s.then?s.then(function(e){return i?e:o}):i?s:o})}catch(e){return Promise.reject(e)}},g="https://api.getalby.com",P=/*#__PURE__*/function(e){var t,n;function r(t,n,r,o){var i;return(i=e.call(this)||this).status=void 0,i.statusText=void 0,i.headers=void 0,i.error=void 0,i.status=t,i.statusText=n,i.headers=r,i.error=o,i}return n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,a(t,n),r}(/*#__PURE__*/d(Error)),_=["expires_in"],k=["token"];function E(e){var t=e.expires_in;return u({},f(e,_),!!t&&{expires_at:Date.now()+1e3*t})}var O=/*#__PURE__*/function(){function e(e){this.token=void 0,this.options=void 0,this.code_verifier=void 0,this.code_challenge=void 0;var t=e.token,n=f(e,k);this.options=u({client_secret:""},n),this.token=t}var t=e.prototype;return t.refreshAccessToken=function(){try{var e,t=this,n=null==(e=t.token)?void 0:e.refresh_token,r=t.options,o=r.client_id,i=r.client_secret,s=r.request_options;if(!o)throw new Error("client_id is required");if(!n)throw new Error("refresh_token is required");return Promise.resolve(y(u({},s,{endpoint:"/oauth/token",params:{client_id:o,grant_type:"refresh_token",refresh_token:n},method:"POST",headers:u({},null==s?void 0:s.headers,{"Content-type":"application/x-www-form-urlencoded"},{Authorization:m(o,i)})}))).then(function(e){var n=E(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},t.isAccessTokenExpired=function(){var e,t,n=null==(e=this.token)?void 0:e.refresh_token,r=null==(t=this.token)?void 0:t.expires_at;return!r||!!n&&r<=Date.now()+1e3},t.requestAccessToken=function(e){try{var t=this,n=t.options,r=n.client_id,o=n.client_secret,i=n.callback,s=n.request_options,c=t.code_verifier;if(!r)throw new Error("client_id is required");if(!i)throw new Error("callback is required");return Promise.resolve(y(u({},s,{endpoint:"/oauth/token",params:{code:e,grant_type:"authorization_code",code_verifier:c,client_id:r,redirect_uri:i},method:"POST",headers:u({},null==s?void 0:s.headers,{"Content-Type":"application/x-www-form-urlencoded"},{Authorization:m(r,o)})}))).then(function(e){var n=E(e);return t.token=n,{token:n}})}catch(e){return Promise.reject(e)}},t.generateAuthURL=function(e){e||(e={}),console.log(e);var t,n=this.options,r=n.client_id,o=n.callback,s=n.scopes;if(!o)throw new Error("callback required");if(!s)throw new Error("scopes required");if("S256"===e.code_challenge_method){var c=i.default.lib.WordArray.random(64);this.code_verifier=c.toString(),this.code_challenge=i.default.SHA256(this.code_verifier).toString(i.default.enc.Base64).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=+$/,""),t="S256"}else"plain"===e.code_challenge_method&&e.code_challenge&&(this.code_challenge=e.code_challenge,this.code_verifier=e.code_challenge,t="plain");var a=this.code_challenge,h=new URL("https://getalby.com/oauth");return h.search=p(u({},e,{client_id:r,scope:s.join(" "),response_type:"code",redirect_uri:o,code_challenge_method:t,code_challenge:a})),h.toString()},t.getAuthHeader=function(){try{var e,t=function(){return{Authorization:"Bearer "+n.token.access_token}},n=this;if(null==(e=n.token)||!e.access_token)throw new Error("access_token is required");var r=function(){if(n.isAccessTokenExpired())return Promise.resolve(n.refreshAccessToken()).then(function(){})}();return Promise.resolve(r&&r.then?r.then(t):t())}catch(e){return Promise.reject(e)}},e}(),T=/*#__PURE__*/function(){function e(e){this.bearer_token=void 0,this.bearer_token=e}return e.prototype.getAuthHeader=function(){return{Authorization:"Bearer "+this.bearer_token}},e}(),j={__proto__:null,OAuth2User:O,OAuth2Bearer:T},q={alby:{authorizationUrl:"https://nwc.getalby.com/apps/new",relayUrl:"wss://relay.getalby.com/v1",walletPubkey:"69effe7b49a6dd5cf525bd0905917a5005ffe480b58eeb8e861418cf3ae760d9"}},x=/*#__PURE__*/function(){function e(t){var n;this.relay=void 0,this.relayUrl=void 0,this.secret=void 0,this.walletPubkey=void 0,this.options=void 0,this.subscribers=void 0,t&&t.nostrWalletConnectUrl&&(t=u({},e.parseWalletConnectUrl(t.nostrWalletConnectUrl),t));var o=q[(null==(n=t)?void 0:n.providerName)||"alby"];this.options=u({},o,t||{}),this.relayUrl=this.options.relayUrl,this.relay=r.relayInit(this.relayUrl),this.options.secret&&(this.secret=this.options.secret.toLowerCase().startsWith("nsec")?r.nip19.decode(this.options.secret).data:this.options.secret),this.walletPubkey=this.options.walletPubkey.toLowerCase().startsWith("npub")?r.nip19.decode(this.options.walletPubkey).data:this.options.walletPubkey,this.subscribers={},void 0===globalThis.WebSocket&&console.error("WebSocket is undefined. Make sure to `import websocket-polyfill` for nodejs environments")}e.parseWalletConnectUrl=function(e){e=e.replace("nostrwalletconnect://","http://").replace("nostr+walletconnect://","http://");var t=new URL(e),n={};n.walletPubkey=t.host;var r=t.searchParams.get("secret"),o=t.searchParams.get("relay");return r&&(n.secret=r),o&&(n.relayUrl=o),n},e.withNewSecret=function(t){return(t=t||{}).secret=r.generatePrivateKey(),new e(t)};var t,n,o=e.prototype;return o.on=function(e,t){this.subscribers[e]=t},o.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},o.getNostrWalletConnectUrl=function(e){void 0===e&&(e=!0);var t="nostr+walletconnect://"+this.walletPubkey+"?relay="+this.relayUrl+"&pubkey="+this.publicKey;return e&&(t=t+"&secret="+this.secret),t},o.signEvent=function(e){if(!this.secret)throw new Error("Missing secret key");return r.signEvent(e,this.secret)},o.getEventHash=function(e){return r.getEventHash(e)},o.enable=function(){try{return this.connected?Promise.resolve():Promise.resolve(this.relay.connect()).then(function(){})}catch(e){return Promise.reject(e)}},o.close=function(){return this.relay.close()},o.encrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(r.nip04.encrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},o.decrypt=function(e,t){try{if(!this.secret)throw new Error("Missing secret");return Promise.resolve(r.nip04.decrypt(this.secret,e,t))}catch(e){return Promise.reject(e)}},o.getInfo=function(){try{return Promise.resolve({methods:["getInfo","sendPayment"],node:{},supports:["lightning"],version:"NWC"})}catch(e){return Promise.reject(e)}},o.sendPayment=function(e){var t=this;return this.checkConnected(),new Promise(function(n,r){try{return Promise.resolve(t.encrypt(t.walletPubkey,JSON.stringify({method:"pay_invoice",params:{invoice:e}}))).then(function(e){var o={kind:23194,created_at:Math.floor(Date.now()/1e3),tags:[["p",t.walletPubkey]],content:e};o.pubkey=t.publicKey,o.id=t.getEventHash(o),o.sig=t.signEvent(o);var i=t.relay.sub([{kinds:[23195],authors:[t.walletPubkey],"#e":[o.id]}]),s=setTimeout(function(){i.unsub(),r({error:"reply timeout: event "+o.id,code:"INTERNAL"})},6e4);i.on("event",function(e){try{return clearTimeout(s),i.unsub(),Promise.resolve(t.decrypt(t.walletPubkey,e.content)).then(function(o){var i,s,u,c;try{s=JSON.parse(o)}catch(e){return void r({error:"invalid response",code:"INTERNAL"})}23195==e.kind&&null!=(i=s.result)&&i.preimage?(n({preimage:s.result.preimage}),t.notify("sendPayment",e.content)):r({error:null==(u=s.error)?void 0:u.message,code:null==(c=s.error)?void 0:c.code})})}catch(e){return Promise.reject(e)}});var u=t.relay.publish(o),c=setTimeout(function(){r({error:"Publish timeout: event "+o.id})},5e3);u.on("failed",function(e){clearTimeout(c),r({error:"Failed to publish request: "+e})}),u.on("ok",function(){clearTimeout(c)})})}catch(e){return Promise.reject(e)}})},o.getAuthorizationUrl=function(e){if(!this.options.authorizationUrl)throw new Error("Missing authorizationUrl option");var t=new URL(this.options.authorizationUrl);return null!=e&&e.name&&t.searchParams.set("c",null==e?void 0:e.name),t.searchParams.set("pubkey",this.publicKey),null!=e&&e.returnTo&&t.searchParams.set("return_to",e.returnTo),t},o.initNWC=function(e){void 0===e&&(e={}),e.name||(e.name=document.location.host);var t=this.getAuthorizationUrl(e),n=window.outerHeight/2+window.screenY-300,r=window.outerWidth/2+window.screenX-200;return new Promise(function(e,o){var i=window.open(t.toString(),document.title+" - Wallet Connect","height=600,width=400,top="+n+",left="+r);if(i){var s=function n(r){var o=r.data;o&&"nwc:success"===o.type&&r.origin===t.protocol+"//"+t.host&&(e(o),clearInterval(u),window.removeEventListener("message",n),i&&i.close())},u=setInterval(function(){i&&i.closed&&(o(),clearInterval(u),window.removeEventListener("message",s))},500);window.addEventListener("message",s)}else o()})},o.checkConnected=function(){if(!this.connected)throw new Error("please call enable() and await the promise before calling this function")},t=e,(n=[{key:"nostrWalletConnectUrl",get:function(){return this.getNostrWalletConnectUrl()}},{key:"connected",get:function(){return 1===this.relay.status}},{key:"publicKey",get:function(){if(!this.secret)throw new Error("Missing secret key");return r.getPublicKey(this.secret)}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),A=x;function R(e){var t={};return e.recipient.customKey&&e.recipient.customValue&&(t[e.recipient.customKey]=e.recipient.customValue),t[7629169]=JSON.stringify(e.boostagram),{destination:e.recipient.address,amount:e.amount,customRecords:t}}var U=/*#__PURE__*/function(){function e(e,t){this.auth=void 0,this.defaultRequestOptions=void 0,this.auth="string"==typeof e?new T(e):e,this.defaultRequestOptions=u({},t,{headers:u({"User-Agent":"alby-js-api"},null==t?void 0:t.headers)})}var t=e.prototype;return t.accountBalance=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/balance",params:e,method:"GET"}))},t.accountSummary=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/summary",params:e,method:"GET"}))},t.accountInformation=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/me",params:e,method:"GET"}))},t.accountValue4Value=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/user/value4value",params:e,method:"GET"}))},t.incomingInvoices=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/incoming",params:e,method:"GET"}))},t.outgoingInvoices=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/outgoing",params:e,method:"GET"}))},t.getInvoice=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices/"+e,method:"GET"}))},t.createInvoice=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/invoices",request_body:e,method:"POST"}))},t.keysend=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e}):(n="/payments/keysend",r=e),y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendPayment=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/bolt11",request_body:e,method:"POST"}))},t.sendBoostagram=function(e,t){var n,r;return Array.isArray(e)?(n="/payments/keysend/multi",r={keysends:e.map(function(e){return R(e)})}):(n="/payments/keysend",r=R(e)),y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:n,request_body:r,method:"POST"}))},t.sendToAlbyAccount=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/payments/keysend",request_body:{destination:"030a58b8653d32b99200a2334cfe913e51dc7d155aa0116c176657a4f1722677a3",customRecords:{696969:e.account},amount:e.amount,memo:e.memo},method:"POST"}))},t.createWebhookEndpoint=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints",request_body:e,method:"POST"}))},t.deleteWebhookEndpoint=function(e,t){return y(u({auth:this.auth},this.defaultRequestOptions,t,{endpoint:"/webhook_endpoints/"+e,method:"DELETE"}))},e}();function S(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}function W(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}var C={__proto__:null,NostrWebLNProvider:x,NWC:A,OauthWeblnProvider:/*#__PURE__*/function(){function e(e){this.client=void 0,this.auth=void 0,this.oauth=void 0,this.subscribers=void 0,this.isExecuting=void 0,this.auth=e.auth,this.client=new U(e.auth),this.oauth=!0,this.subscribers={},this.isExecuting=!1}var t=e.prototype;return t.on=function(e,t){this.subscribers[e]=t},t.notify=function(e,t){var n=this.subscribers[e];n&&n(t)},t.enable=function(){try{var e,t=this;return t.isExecuting?Promise.resolve():null!=(e=t.auth.token)&&e.access_token?Promise.resolve({enabled:!0}):Promise.resolve(function(){if("undefined"==typeof window||void 0===window.document)throw new Error("Missing access token");var e=S(function(){return t.isExecuting=!0,Promise.resolve(t.openAuthorization()).then(function(){})},function(e,n){if(t.isExecuting=!1,e)throw n;return n});if(e&&e.then)return e.then(function(){})}())}catch(e){return Promise.reject(e)}},t.sendPayment=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.sendPayment({invoice:e})).then(function(e){if(e.error)throw new Error(e.message);return t.notify("sendPayment",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.keysend=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.keysend(e)).then(function(e){if(e.error)throw new Error(e.message);return t.notify("keysend",e),{preimage:e.payment_preimage}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.getInfo=function(){try{return Promise.resolve({alias:"Alby"})}catch(e){return Promise.reject(e)}},t.makeInvoice=function(e){try{var t=this;return t.isExecuting?Promise.resolve():Promise.resolve(S(function(){return W(function(){return t.isExecuting=!0,Promise.resolve(t.client.createInvoice({amount:parseInt(e.amount.toString()),description:e.defaultMemo})).then(function(e){return t.notify("makeInvoice",e),{paymentRequest:e.payment_request}})},function(e){var t="Unknown Error";throw e instanceof Error&&(t=e.message),new Error(t)})},function(e,n){if(t.isExecuting=!1,e)throw n;return n}))}catch(e){return Promise.reject(e)}},t.openAuthorization=function(){var e=this,t=window.outerHeight/2+window.screenY-350,n=window.outerWidth/2+window.screenX-300,r=this.auth.generateAuthURL({code_challenge_method:"S256"});return new Promise(function(o,i){var s=window.open(r,document.title+" - WebLN enable","height=700,width=600,top="+t+",left="+n),u=!1;window.addEventListener("message",function(t){try{var n=t.data,r=function(){if(n&&"alby:oauth:success"===n.type&&t.origin===document.location.protocol+"//"+document.location.host&&!u){u=!0,console.info("Processing OAuth code response");var r=n.payload.code,c=W(function(){return Promise.resolve(e.auth.requestAccessToken(r)).then(function(){e.client=new U(e.auth),s&&s.close(),e.notify("enable"),o({enabled:!0})})},function(e){console.error(e),i({enabled:!1})});if(c&&c.then)return c.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}})})},e}()};e.Client=U,e.auth=j,e.types={__proto__:null,OAuthClient:function(){},AuthClient:function(){}},e.webln=C}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "alby-js-sdk", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "The SDK to integrate with Nostr Wallet Connect and the Alby API", | ||
@@ -5,0 +5,0 @@ "type": "module", |
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
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
318053