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

react-native-webln

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-webln - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

2

dist/inject-txt.d.ts

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

declare const _default: "(() => {\n \"use strict\";\n if (!window.ReactNativeWebView) {\n return;\n }\n const WebLNPromiseCallback = {};\n const timeout = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));\n let requestId = 0;\n let weblnEnabled = false;\n window.webln = {\n enable: async () => {\n if (document.domain !== \"tippin.me\") {\n weblnEnabled = true;\n }\n return;\n },\n getInfo: async () => {\n return await postMessage({\n type: \"getInfo\",\n data: null,\n });\n },\n makeInvoice: async (args) => {\n const result = await postMessage({\n type: \"makeInvoice\",\n data: args,\n });\n checkedInvoices.push((\"lightning:\" + result.paymentRequest).toUpperCase());\n return result;\n },\n sendPayment: async (paymentRequest) => {\n return await postMessage({\n type: \"sendPayment\",\n data: paymentRequest,\n });\n },\n signMessage: async () => {\n return {\n message: \"\",\n signature: \"\",\n };\n },\n verifyMessage: async () => {\n return;\n },\n };\n const postMessage = async (message, waitForCallback = true) => {\n const currentId = requestId++;\n window.ReactNativeWebView.postMessage(JSON.stringify({\n ...message,\n id: currentId,\n }));\n if (!waitForCallback) {\n return;\n }\n while (!WebLNPromiseCallback[currentId]) {\n await timeout(1000);\n }\n if (WebLNPromiseCallback[currentId] instanceof Error) {\n throw WebLNPromiseCallback[currentId];\n }\n return WebLNPromiseCallback[currentId];\n };\n document.addEventListener(\"webln\", (event) => {\n WebLNPromiseCallback[event.detail.id] = event.detail.data;\n });\n const checkedInvoices = [];\n if (window.reactNativeWebLNCheckTags) {\n const checkATags = async () => {\n const aTags = document.querySelectorAll(\"a\");\n for (const aTag of aTags) {\n if (aTag.href &&\n aTag.href.toUpperCase().startsWith(\"LIGHTNING:\") &&\n aTag.href.length > \"LIGHTNING:\".length) {\n const invoice = aTag.href.toUpperCase().replace(\"LIGHTNING:\", \"\");\n if (checkedInvoices.includes(invoice)) {\n return;\n }\n if (weblnEnabled && invoice.startsWith(\"LNBC\")) {\n return;\n }\n debug(\"Found: \" + aTag.href);\n checkedInvoices.push(invoice);\n await postMessage({\n type: \"nonwebln_foundInvoice\",\n data: invoice\n }, false);\n break;\n }\n }\n };\n setInterval(() => {\n checkATags();\n }, 850);\n }\n const debug = async (message) => {\n if (window.reactNativeWebLNDebug) {\n await postMessage({\n type: \"debug\",\n data: message,\n }, false);\n }\n };\n})();";
declare const _default: "(() => {\n \"use strict\";\n if (!window.ReactNativeWebView) {\n return;\n }\n const WebLNPromiseCallback = {};\n const timeout = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));\n let requestId = 0;\n let weblnEnabled = false;\n window.webln = {\n enable: async () => {\n if (document.domain !== \"tippin.me\") {\n weblnEnabled = true;\n }\n return;\n },\n getInfo: async () => {\n return await postMessage({\n type: \"getInfo\",\n data: null,\n });\n },\n makeInvoice: async (args) => {\n const result = await postMessage({\n type: \"makeInvoice\",\n data: args,\n });\n checkedInvoices.push((\"lightning:\" + result.paymentRequest).toUpperCase());\n return result;\n },\n sendPayment: async (paymentRequest) => {\n return await postMessage({\n type: \"sendPayment\",\n data: paymentRequest,\n });\n },\n signMessage: async (message) => {\n return await postMessage({\n type: \"signMessage\",\n data: message,\n });\n },\n verifyMessage: async (signature, message) => {\n return await postMessage({\n type: \"verifyMessage\",\n data: {\n signature,\n message,\n },\n });\n },\n };\n const postMessage = async (message, waitForCallback = true) => {\n const currentId = requestId++;\n window.ReactNativeWebView.postMessage(JSON.stringify({\n ...message,\n id: currentId,\n }));\n if (!waitForCallback) {\n return;\n }\n while (!WebLNPromiseCallback[currentId]) {\n await timeout(1000);\n }\n if (WebLNPromiseCallback[currentId] instanceof Error) {\n throw WebLNPromiseCallback[currentId];\n }\n return WebLNPromiseCallback[currentId];\n };\n document.addEventListener(\"webln\", (event) => {\n WebLNPromiseCallback[event.detail.id] = event.detail.data;\n });\n const checkedInvoices = [];\n if (window.reactNativeWebLNCheckTags) {\n const checkATags = async () => {\n const aTags = document.querySelectorAll(\"a\");\n for (const aTag of aTags) {\n if (aTag.href &&\n aTag.href.toUpperCase().startsWith(\"LIGHTNING:\") &&\n aTag.href.length > \"LIGHTNING:\".length) {\n const invoice = aTag.href.toUpperCase().replace(\"LIGHTNING:\", \"\");\n if (checkedInvoices.includes(invoice)) {\n return;\n }\n if (weblnEnabled && invoice.startsWith(\"LNBC\")) {\n return;\n }\n debug(\"Found: \" + aTag.href);\n checkedInvoices.push(invoice);\n await postMessage({\n type: \"nonwebln_foundInvoice\",\n data: invoice\n }, false);\n break;\n }\n }\n };\n setInterval(() => {\n checkATags();\n }, 850);\n }\n const debug = async (message) => {\n if (window.reactNativeWebLNDebug) {\n await postMessage({\n type: \"debug\",\n data: message,\n }, false);\n }\n };\n})();";
export default _default;

@@ -39,10 +39,16 @@ "use strict";

},
signMessage: async () => {
return {
message: "",
signature: "",
};
signMessage: async (message) => {
return await postMessage({
type: "signMessage",
data: message,
});
},
verifyMessage: async () => {
return;
verifyMessage: async (signature, message) => {
return await postMessage({
type: "verifyMessage",
data: {
signature,
message,
},
});
},

@@ -49,0 +55,0 @@ };

@@ -6,3 +6,3 @@ "use strict";

console.error("react-native-webln: Reference to webview is not properly set.\n" +
"postMessageHandler needs to have a ref to webview in other to work");
"postMessageHandler needs to have a ref to webview in order to work");
}

@@ -50,7 +50,9 @@ requests.foundInvoice = requests.foundInvoice || (async () => { });

case "signMessage": {
injectResponseToWebView(webview.current, id, new Error("Not implemented."));
const response = await requests.signMessage(request.data);
injectResponseToWebView(webview.current, id, JSON.stringify(response));
break;
}
case "verifyMessage": {
injectResponseToWebView(webview.current, id, new Error("Not implemented."));
const response = await requests.verifyMessage(request.data.signature, request.data.message);
injectResponseToWebView(webview.current, id, JSON.stringify(response));
break;

@@ -57,0 +59,0 @@ }

@@ -66,10 +66,16 @@ import { WebLNProvider, RequestInvoiceResponse } from "webln";

},
signMessage: async () => {
return {
message: "",
signature: "",
};
signMessage: async (message) => {
return await postMessage({
type: "signMessage",
data: message,
});
},
verifyMessage: async () => {
return;
verifyMessage: async (signature, message) => {
return await postMessage({
type: "verifyMessage",
data: {
signature,
message,
},
});
},

@@ -148,2 +154,2 @@ };

};
})();
})();

@@ -18,3 +18,3 @@ import { MutableRefObject } from "react";

"react-native-webln: Reference to webview is not properly set.\n" +
"postMessageHandler needs to have a ref to webview in other to work"
"postMessageHandler needs to have a ref to webview in order to work"
);

@@ -65,7 +65,9 @@ }

case "signMessage": {
injectResponseToWebView(webview.current, id, new Error("Not implemented."));
const response = await requests.signMessage(request.data);
injectResponseToWebView(webview.current, id, JSON.stringify(response));
break;
}
case "verifyMessage": {
injectResponseToWebView(webview.current, id, new Error("Not implemented."));
const response = await requests.verifyMessage(request.data.signature, request.data.message);
injectResponseToWebView(webview.current, id, JSON.stringify(response));
break;

@@ -100,2 +102,2 @@ }

onMessageHandler,
}
}
{
"name": "react-native-webln",
"description": "Library for supporting WebLN in a WebView",
"version": "0.1.10",
"version": "0.1.11",
"main": "dist/index",

@@ -6,0 +6,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc