diff --git a/README.md b/README.md
index 805ae8f..195e361 100644
--- a/README.md
+++ b/README.md
@@ -26,8 +26,10 @@ https://bitcoin-connect.com
You can use Bitcoin Connect without any build tools:
+> NOTE: LNC connector is not supported!
+
```html
-
+
```
## 🤙 Usage
diff --git a/demos/html/index.html b/demos/html/index.html
index 4717623..fb7b749 100644
--- a/demos/html/index.html
+++ b/demos/html/index.html
@@ -4,7 +4,7 @@
Bitcoin Connect
-
+
diff --git a/demos/html/minimal.html b/demos/html/minimal.html
index e1f0826..fee0aae 100644
--- a/demos/html/minimal.html
+++ b/demos/html/minimal.html
@@ -4,7 +4,7 @@
Bitcoin Connect
-
+
diff --git a/demos/react/package.json b/demos/react/package.json
index 7d25b8b..2a772af 100644
--- a/demos/react/package.json
+++ b/demos/react/package.json
@@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
- "@getalby/bitcoin-connect-react": "^2.0.0",
+ "@getalby/bitcoin-connect-react": "^2.1.3",
"@getalby/lightning-tools": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
diff --git a/demos/react/yarn.lock b/demos/react/yarn.lock
index d6c62e0..108d008 100644
--- a/demos/react/yarn.lock
+++ b/demos/react/yarn.lock
@@ -149,19 +149,20 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.46.0.tgz#3f7802972e8b6fe3f88ed1aabc74ec596c456db6"
integrity sha512-a8TLtmPi8xzPkCbp/OGFUo5yhRkHM2Ko9kOWP4znJr0WAhWyThaw3PnwX4vOTWOAMsV2uRt32PPDcEz63esSaA==
-"@getalby/bitcoin-connect-react@^2.0.0":
- version "2.0.0"
- resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect-react/-/bitcoin-connect-react-2.0.0.tgz#f99f78754b1627619b511760274efb40f9723c92"
- integrity sha512-PlpXDk/p3y+2zyWRlgkKc+t5XN6wbJr9xZSWYayYFs+i988lrE1BqcydGAoYI6SotoaYpt3FDyOKgGfB4dyzsw==
+"@getalby/bitcoin-connect-react@^2.1.3":
+ version "2.1.3"
+ resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect-react/-/bitcoin-connect-react-2.1.3.tgz#0a072964b5807f34b8c86cad5f40747887f9dade"
+ integrity sha512-uEJW4Y2p9YEYfxZgL7v/57C+GElV1IWv/6q5AQyPLi6udgJugeU8vU1pcYefV7CeLvobROA7E+jf2Kn/Hj9pkA==
dependencies:
- "@getalby/bitcoin-connect" "^2.0.0"
+ "@getalby/bitcoin-connect" "^2.1.3"
-"@getalby/bitcoin-connect@^2.0.0":
- version "2.0.0"
- resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect/-/bitcoin-connect-2.0.0.tgz#9ae7f139a616a65a55008d8b8d808ebd6fc316c6"
- integrity sha512-cLtEHenPiF8n/gbC8jG81D8lgPgRhSsNM3TeIBHbMQComyciuB2/Yth6sh4CNUefAbAN5Br97guaNGur4umBZg==
+"@getalby/bitcoin-connect@^2.1.3":
+ version "2.1.3"
+ resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect/-/bitcoin-connect-2.1.3.tgz#7485ad3279f7800b0f924d63658adcef371ee6e0"
+ integrity sha512-kX93lJUemFWcwkgXbXJHi9mj3uyyXhlQLwt2/x3Pi29RKzU2rmXocdxZqP6SfwWxtFwuwAfmMRqmxusUbVurTQ==
dependencies:
"@getalby/sdk" "^2.4.0"
+ "@lightninglabs/lnc-web" "^0.2.6-alpha"
lit "^2.2.4"
zustand "^4.4.1"
@@ -201,6 +202,19 @@
resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45"
integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==
+"@lightninglabs/lnc-core@0.2.6-alpha":
+ version "0.2.6-alpha"
+ resolved "https://registry.yarnpkg.com/@lightninglabs/lnc-core/-/lnc-core-0.2.6-alpha.tgz#1b93d5aeefb09bb3dedcb82988368b15e223f8fd"
+ integrity sha512-bw2EQG78pPKMZMFwV+TR99RUbYgPVUKQYMLGGKIOvhPds3dBWSDZpMoqOyW/WidWGXF/ugPHzud8lDbKKhNXgA==
+
+"@lightninglabs/lnc-web@^0.2.6-alpha":
+ version "0.2.6-alpha"
+ resolved "https://registry.yarnpkg.com/@lightninglabs/lnc-web/-/lnc-web-0.2.6-alpha.tgz#34f54f65691ff8cdef6eb159321b70c94f198f9e"
+ integrity sha512-SrqR8xaDnFLgNzPe5om7REOAhSOP95jQNIHP0GY0Lv895eDjrI6CPkfCFcX97INoDWYHBvDT8DZeYkBvlznVNA==
+ dependencies:
+ "@lightninglabs/lnc-core" "0.2.6-alpha"
+ crypto-js "4.1.1"
+
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz#64df34e2f12e68e78ac57e571d25ec07fa460ca9"
@@ -584,7 +598,7 @@ cross-spawn@^7.0.2:
shebang-command "^2.0.0"
which "^2.0.1"
-crypto-js@^4.1.1:
+crypto-js@4.1.1, crypto-js@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
diff --git a/package.json b/package.json
index 9a25b0d..9586803 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@getalby/bitcoin-connect",
- "version": "2.0.0",
+ "version": "2.1.3",
"description": "Web components to connect to a lightning wallet and power a website with WebLN",
"type": "module",
"source": "src/index.ts",
@@ -19,7 +19,7 @@
"scripts": {
"prebuild": "yarn run clean",
"prepack": "yarn run build",
- "build:browser": "esbuild dist/index.modern.js --bundle --outfile=dist/index.browser.js",
+ "build:browser": "esbuild dist/index.modern.js --bundle --external:@lightninglabs/lnc-web --outfile=dist/index.browser.js",
"build": "microbundle && yarn build:browser",
"clean": "rm -rf dist",
"dev": "yarn --cwd dev/vite dev",
diff --git a/react/package.json b/react/package.json
index bd54b21..ad5cc73 100644
--- a/react/package.json
+++ b/react/package.json
@@ -1,6 +1,6 @@
{
"name": "@getalby/bitcoin-connect-react",
- "version": "2.0.0",
+ "version": "2.1.3",
"type": "module",
"source": "src/index.ts",
"main": "./dist/index.cjs",
@@ -21,7 +21,7 @@
"build": "microbundle --globals react=React --jsx React.createElement --jsxFragment React.Fragment --jsxImportSource react"
},
"dependencies": {
- "@getalby/bitcoin-connect": "^2.0.0"
+ "@getalby/bitcoin-connect": "^2.1.3"
},
"devDependencies": {
"@types/react": "^18.2.21",
diff --git a/react/yarn.lock b/react/yarn.lock
index 4e05d26..f52bb01 100644
--- a/react/yarn.lock
+++ b/react/yarn.lock
@@ -1018,12 +1018,13 @@
"@babel/helper-validator-identifier" "^7.22.5"
to-fast-properties "^2.0.0"
-"@getalby/bitcoin-connect@^2.0.0":
- version "2.0.0"
- resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect/-/bitcoin-connect-2.0.0.tgz#9ae7f139a616a65a55008d8b8d808ebd6fc316c6"
- integrity sha512-cLtEHenPiF8n/gbC8jG81D8lgPgRhSsNM3TeIBHbMQComyciuB2/Yth6sh4CNUefAbAN5Br97guaNGur4umBZg==
+"@getalby/bitcoin-connect@^2.1.3":
+ version "2.1.3"
+ resolved "https://registry.yarnpkg.com/@getalby/bitcoin-connect/-/bitcoin-connect-2.1.3.tgz#7485ad3279f7800b0f924d63658adcef371ee6e0"
+ integrity sha512-kX93lJUemFWcwkgXbXJHi9mj3uyyXhlQLwt2/x3Pi29RKzU2rmXocdxZqP6SfwWxtFwuwAfmMRqmxusUbVurTQ==
dependencies:
"@getalby/sdk" "^2.4.0"
+ "@lightninglabs/lnc-web" "^0.2.6-alpha"
lit "^2.2.4"
zustand "^4.4.1"
@@ -1076,6 +1077,19 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"
+"@lightninglabs/lnc-core@0.2.6-alpha":
+ version "0.2.6-alpha"
+ resolved "https://registry.yarnpkg.com/@lightninglabs/lnc-core/-/lnc-core-0.2.6-alpha.tgz#1b93d5aeefb09bb3dedcb82988368b15e223f8fd"
+ integrity sha512-bw2EQG78pPKMZMFwV+TR99RUbYgPVUKQYMLGGKIOvhPds3dBWSDZpMoqOyW/WidWGXF/ugPHzud8lDbKKhNXgA==
+
+"@lightninglabs/lnc-web@^0.2.6-alpha":
+ version "0.2.6-alpha"
+ resolved "https://registry.yarnpkg.com/@lightninglabs/lnc-web/-/lnc-web-0.2.6-alpha.tgz#34f54f65691ff8cdef6eb159321b70c94f198f9e"
+ integrity sha512-SrqR8xaDnFLgNzPe5om7REOAhSOP95jQNIHP0GY0Lv895eDjrI6CPkfCFcX97INoDWYHBvDT8DZeYkBvlznVNA==
+ dependencies:
+ "@lightninglabs/lnc-core" "0.2.6-alpha"
+ crypto-js "4.1.1"
+
"@lit-labs/ssr-dom-shim@^1.0.0", "@lit-labs/ssr-dom-shim@^1.1.0":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.1.1.tgz#64df34e2f12e68e78ac57e571d25ec07fa460ca9"
@@ -1584,7 +1598,7 @@ cosmiconfig@^7.0.0:
path-type "^4.0.0"
yaml "^1.10.0"
-crypto-js@^4.1.1:
+crypto-js@4.1.1, crypto-js@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
diff --git a/src/components/connectors/bc-lnc-connector.ts b/src/components/connectors/bc-lnc-connector.ts
index b06d0fb..484a52d 100644
--- a/src/components/connectors/bc-lnc-connector.ts
+++ b/src/components/connectors/bc-lnc-connector.ts
@@ -1,7 +1,7 @@
import {customElement} from 'lit/decorators.js';
import {ConnectorElement} from './ConnectorElement';
-import {lnc} from '../../connectors/LNCConnector';
import {lncIcon} from '../icons/connectors/lncIcon';
+import {getLNC} from '../../connectors/LNCConnector';
@customElement('bc-lnc-connector')
export class LNCConnector extends ConnectorElement {
@@ -9,13 +9,17 @@ export class LNCConnector extends ConnectorElement {
super('lnc', 'LNC', '#101727', lncIcon);
}
- protected _onClick() {
+ protected async _onClick() {
// TODO: improve UX for entering pairing phrase, allow scanning QR code?
const pairingPhrase = window.prompt('Enter pairing phrase');
if (!pairingPhrase) {
return;
}
+ const lnc = await getLNC();
+ if (!lnc) {
+ throw new Error('LNC not supported');
+ }
lnc.credentials.pairingPhrase = pairingPhrase;
this._connect({});
diff --git a/src/connectors/LNCConnector.ts b/src/connectors/LNCConnector.ts
index 9b6cca2..2b475e6 100644
--- a/src/connectors/LNCConnector.ts
+++ b/src/connectors/LNCConnector.ts
@@ -13,11 +13,27 @@ import {
WebLNProvider,
WebLNRequestMethod,
} from '@webbtc/webln-types';
-import LNC from '@lightninglabs/lnc-web';
+import type LNC from '@lightninglabs/lnc-web';
import {base64ToHex} from '../utils/base64ToHex';
// global instance of LNC
-export const lnc = new LNC();
+let lnc: LNC;
+
+export async function getLNC() {
+ try {
+ if (lnc) {
+ return lnc;
+ }
+ const LNC = (await import('@lightninglabs/lnc-web')).default;
+ lnc = new LNC();
+ return lnc;
+ } catch (error) {
+ console.error(error);
+ throw new Error('LNC is not available');
+ }
+}
+
+export {lnc};
// NOTE: as per NWC and other connectors - the user must put trust in the website to not use funds
// without the user's permission.
const lncPassword = 'ONLY CONNECT TO TRUSTED WEBSITES';
@@ -28,6 +44,7 @@ export class LNCConnector extends Connector {
}
override async init() {
+ await getLNC();
window.webln = new LNCWebLNProvider();
try {