-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nwc auth docs, husky commit (#325)
- Loading branch information
Showing
7 changed files
with
166 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn commitlint --edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<button id="connect-button" onclick="window.launchNwc()">Connect NWC</button> | ||
<button id="reset-button" onclick="window.resetNwc()">Reset</button> | ||
|
||
<script type="module"> | ||
import { webln, nwc } from "https://esm.sh/@getalby/[email protected]"; // jsdelivr.net, skypack.dev also work | ||
import { | ||
generateSecretKey, | ||
getPublicKey, | ||
} from "https://esm.sh/[email protected]"; // jsdelivr.net, skypack.dev also work | ||
import { | ||
bytesToHex, | ||
hexToBytes, | ||
} from "https://esm.sh/@noble/[email protected]/utils"; // jsdelivr.net, skypack.dev also work | ||
|
||
const params = new URL(window.location.href).searchParams; | ||
const walletPubkey = params.get("pubkey"); | ||
const relayUrl = params.get("relay"); | ||
const lud16 = params.get("lud16"); | ||
const secret = window.localStorage.getItem("demo_secret"); | ||
|
||
if (walletPubkey && relayUrl) { | ||
try { | ||
if (!secret) { | ||
throw new Error("No secret saved locally"); | ||
} | ||
window.document.getElementById("connect-button").remove(); | ||
const nwcClient = new nwc.NWCClient({ | ||
secret, | ||
walletPubkey, | ||
relayUrl, | ||
lud16, | ||
}); | ||
const weblnProvider = new webln.NostrWebLNProvider({ | ||
client: nwcClient, | ||
}); | ||
await weblnProvider.enable(); | ||
const result = await weblnProvider.getInfo(); | ||
alert("Info response: " + JSON.stringify(result) + " lud16: " + lud16); | ||
} catch (error) { | ||
console.error(error); | ||
alert("Something went wrong: " + error); | ||
} | ||
} else { | ||
window.document.getElementById("reset-button").remove(); | ||
} | ||
|
||
window.resetNwc = async () => { | ||
window.localStorage.removeItem("demo_secret"); | ||
window.location.href = window.origin; | ||
}; | ||
|
||
window.launchNwc = async () => { | ||
try { | ||
if (!window.origin.startsWith("http")) { | ||
alert( | ||
"Please use a webserver from this directory e.g. python3 -m http.server", | ||
); | ||
} | ||
|
||
const secret = bytesToHex(generateSecretKey()); | ||
const pubkey = getPublicKey(hexToBytes(secret)); | ||
window.localStorage.setItem("demo_secret", secret); | ||
const authorizationBasePath = prompt( | ||
"Auth URL", | ||
"https://my.albyhub.com/apps/new", | ||
); | ||
const authUrl = await nwc.NWCClient.getAuthorizationUrl( | ||
authorizationBasePath, | ||
{ | ||
name: "Deeplink " + Date.now(), | ||
returnTo: window.location.href, | ||
}, | ||
pubkey, | ||
); | ||
window.location = authUrl; | ||
} catch (error) { | ||
console.error(error); | ||
alert("Something went wrong: " + error); | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<button id="connect-button" onclick="window.launchNwc()">Connect NWC</button> | ||
<button id="reset-button" onclick="window.resetNwc()">Reset</button> | ||
|
||
<script type="module"> | ||
import { nwc } from "https://esm.sh/@getalby/[email protected]"; // jsdelivr.net, skypack.dev also work | ||
import { | ||
generateSecretKey, | ||
getPublicKey, | ||
} from "https://esm.sh/[email protected]"; // jsdelivr.net, skypack.dev also work | ||
import { | ||
bytesToHex, | ||
hexToBytes, | ||
} from "https://esm.sh/@noble/[email protected]/utils"; // jsdelivr.net, skypack.dev also work | ||
|
||
const params = new URL(window.location.href).searchParams; | ||
const walletPubkey = params.get("pubkey"); | ||
const relayUrl = params.get("relay"); | ||
const lud16 = params.get("lud16"); | ||
const secret = window.localStorage.getItem("demo_secret"); | ||
|
||
if (walletPubkey && relayUrl) { | ||
try { | ||
if (!secret) { | ||
throw new Error("No secret saved locally"); | ||
} | ||
window.document.getElementById("connect-button").remove(); | ||
const nwcClient = new nwc.NWCClient({ | ||
secret, | ||
walletPubkey, | ||
relayUrl, | ||
lud16, | ||
}); | ||
const result = await nwcClient.getInfo(); | ||
alert("Info response: " + JSON.stringify(result) + " lud16: " + lud16); | ||
} catch (error) { | ||
console.error(error); | ||
alert("Something went wrong: " + error); | ||
} | ||
} else { | ||
window.document.getElementById("reset-button").remove(); | ||
} | ||
|
||
window.resetNwc = async () => { | ||
window.localStorage.removeItem("demo_secret"); | ||
window.location.href = window.origin; | ||
}; | ||
|
||
window.launchNwc = async () => { | ||
try { | ||
if (!window.origin.startsWith("http")) { | ||
alert( | ||
"Please use a webserver from this directory e.g. python3 -m http.server", | ||
); | ||
} | ||
|
||
const secret = bytesToHex(generateSecretKey()); | ||
const pubkey = getPublicKey(hexToBytes(secret)); | ||
window.localStorage.setItem("demo_secret", secret); | ||
const authorizationBasePath = prompt( | ||
"Auth URL", | ||
"https://my.albyhub.com/apps/new", | ||
); | ||
const authUrl = await nwc.NWCClient.getAuthorizationUrl( | ||
authorizationBasePath, | ||
{ | ||
name: "Deeplink " + Date.now(), | ||
returnTo: window.location.href, | ||
}, | ||
pubkey, | ||
); | ||
window.location = authUrl; | ||
} catch (error) { | ||
console.error(error); | ||
alert("Something went wrong: " + error); | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters