Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandelmonkey/bae110e4c46cc0cb1e8c36b19f861062 to your computer and use it in GitHub Desktop.
Save mandelmonkey/bae110e4c46cc0cb1e8c36b19f861062 to your computer and use it in GitHub Desktop.
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function requestProvider(_) {
if (_ === void 0) { _ = {}; }
if (typeof window === 'undefined') {
throw new Error('Must be called in a browser context');
}
var webln = window.webln;
if (!webln) {
throw new Error('Your browser does not support WebLN');
}
return webln.enable().then(function () { return webln; });
}
exports.requestProvider = requestProvider;
},{}],2:[function(require,module,exports){
var requestProvider = require('webln/lib/client');
$(document).ready(function () {
if ($('#connectBtn') != null || $('#connectBtn') != undefined) {
document.getElementById('connectBtn').onclick = async function authNode(){
let webln;
try {
webln = await requestProvider.requestProvider();
} catch (err) {
// Handle users without WebLN
toast("error","Download the extension of Lightning Joule to connect your lightning node <a href='https://lightningjoule.com/'><button type='button' id='okBtn' class='nes-btn -btn-primary'>Install</button></a>");
}
// Elsewhere in the code...
if (webln) {
// Call webln function
let auth;
auth = await webln.getInfo()
localStorage.setItem("uniqueId", auth.node.pubkey);
if (auth.node.pubkey) {
let newUser = false;
var request = $.ajax({
url: '/nonce',
type: 'post',
data: {
publicKey: auth.node.pubkey
},
headers: {
'x-csrf-token': $('[name=_csrf]').val()
},
dataType: 'json'
});
request.done(function (data) {
if (data) {
toast(data.type, data.msg)
if (data.msg === "Welcome to Satoshis Games") {
newUser = true;
}
webln.signMessage(data.nonce, async (success) => {
}).then(function (data) {
if (data) {
var request = $.ajax({
url: '/verify',
type: 'post',
data: {
publicKey: auth.node.pubkey,
signature: data.signature
},
headers: {
'x-csrf-token': $('[name=_csrf]').val()
},
dataType: 'json'
});
request.done(function (data) {
if (data.msg) {
toast(data.type, data.msg)
}
setTimeout(() => {
if (newUser) {
location.replace("/profile")
} else {
location.reload()
}
}, 800);
});
request.fail(function (data) {
toast('success', data.msg)
setTimeout(function(){
window.location.replace('/');
}, 600);
});
}
})
}
});
request.fail(function (data) {
toast('success', data.msg)
setTimeout(function(){
window.location.replace('/');
}, 600);
});
}
}
}
}
});
},{"webln/lib/client":1}]},{},[2]);
function updateDB(auth) {
var request = $.ajax({
url: "/newuser",
data: {
unique_key: auth.node.pubkey,
username: auth.node.alias,
twitter: ""
},
type: 'post',
headers: {
'x-csrf-token': $('[name=_csrf]').val()
},
dataType: 'json'
});
request.done(function () {
var request = $.ajax({
url: '/autologin',
type: 'post',
data: {
unique_key: localStorage.getItem('uniqueId')
},
headers: {
'x-csrf-token': $('[name=_csrf]').val()
},
dataType: 'json'
});
request.done(function (data) {
if (data.type) {
toast(data.type, data.msg)
}else{
toast("success", data.msg)
setTimeout(function(){
window.location.replace('/');
}, 600);
}
});
request.fail(function (data) {
toast('success', data.msg)
setTimeout(function(){
window.location.replace('/');
}, 600);
});
});
request.fail(function (data) {
toast('success', data.msg)
setTimeout(function(){
window.location.replace('/');
}, 600);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment