Merge pull request #497 from shocknet/bug/gun-issues
Upgrade to latest GunDB and fix Auth issues
This commit is contained in:
commit
9b6ee160ed
15 changed files with 8863 additions and 5912 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
# Gun db storage
|
# Gun db storage
|
||||||
DATA_FILE_NAME=radata2
|
DATA_FILE_NAME=radata2
|
||||||
# Gun peer
|
# Gun peer
|
||||||
["https://gun.shock.network/gun","https://gun-eu.shock.network/gun"]
|
PEERS=["https://gun.shock.network/gun","https://gun-eu.shock.network/gun"]
|
||||||
# API Device Token
|
# API Device Token
|
||||||
MS_TO_TOKEN_EXPIRATION=4500000
|
MS_TO_TOKEN_EXPIRATION=4500000
|
||||||
# E2EE
|
# E2EE
|
||||||
|
|
|
||||||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -15,3 +15,11 @@ radata-*.tmp
|
||||||
*.key
|
*.key
|
||||||
|
|
||||||
*-audit.json
|
*-audit.json
|
||||||
|
# Yarn v2
|
||||||
|
.pnp.*
|
||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/sdks
|
||||||
|
!.yarn/versions
|
||||||
22
.vscode/launch.json
vendored
22
.vscode/launch.json
vendored
|
|
@ -1,5 +1,12 @@
|
||||||
{
|
{
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Attach",
|
||||||
|
"port": 9229,
|
||||||
|
"request": "attach",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"type": "pwa-node"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Nodemon",
|
"name": "Nodemon",
|
||||||
"program": "${workspaceFolder}/main.js",
|
"program": "${workspaceFolder}/main.js",
|
||||||
|
|
@ -34,17 +41,14 @@
|
||||||
"--",
|
"--",
|
||||||
"-h",
|
"-h",
|
||||||
"0.0.0.0",
|
"0.0.0.0",
|
||||||
|
"--trace-warnings",
|
||||||
|
"--max-old-space-size=4096",
|
||||||
"-c",
|
"-c",
|
||||||
"-s",
|
|
||||||
"9835",
|
|
||||||
"-l",
|
|
||||||
"127.0.0.1:10001",
|
|
||||||
"-r",
|
|
||||||
"localhost:9735",
|
|
||||||
"-m",
|
|
||||||
"/home/danlugo92/.polar/networks/1/volumes/lnd/alice/data/chain/bitcoin/regtest/admin.macaroon",
|
|
||||||
"-d",
|
"-d",
|
||||||
"/home/danlugo92/.polar/networks/1/volumes/lnd/alice/tls.cert"
|
"C:\\Users\\Predator\\AppData\\Local\\Lnd\\tls.cert",
|
||||||
|
"-m",
|
||||||
|
"C:\\Users\\Predator\\AppData\\Local\\Lnd\\data\\chain\\bitcoin\\mainnet\\admin.macaroon",
|
||||||
|
"--tunnel"
|
||||||
],
|
],
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"skipFiles": ["<node_internals>/**"],
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
|
|
||||||
768
.yarn/releases/yarn-3.1.1.cjs
vendored
Normal file
768
.yarn/releases/yarn-3.1.1.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
2
.yarnrc.yml
Normal file
2
.yarnrc.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
yarnPath: .yarn/releases/yarn-3.1.1.cjs
|
||||||
|
nodeLinker: node-modules
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
"start": "node main.js -h 0.0.0.0 -c",
|
"start": "node main.js -h 0.0.0.0 -c",
|
||||||
"dev": "node --trace-warnings --max-old-space-size=4096 main.js -h 0.0.0.0",
|
"dev": "node --trace-warnings --max-old-space-size=4096 main.js -h 0.0.0.0",
|
||||||
"dev:watch": "nodemon main.js -- -h 0.0.0.0",
|
"dev:watch": "nodemon main.js -- -h 0.0.0.0",
|
||||||
|
"dev:attach": "node --inspect --trace-warnings --max-old-space-size=4096 main.js -h 0.0.0.0",
|
||||||
"test": "mocha ./utils -b -t 50000 --recursive",
|
"test": "mocha ./utils -b -t 50000 --recursive",
|
||||||
"typecheck": "tsc",
|
"typecheck": "tsc",
|
||||||
"lint": "eslint \"services/gunDB/**/*.js\"",
|
"lint": "eslint \"services/gunDB/**/*.js\"",
|
||||||
|
|
@ -38,8 +39,7 @@
|
||||||
"express-session": "^1.17.1",
|
"express-session": "^1.17.1",
|
||||||
"google-proto-files": "^1.0.3",
|
"google-proto-files": "^1.0.3",
|
||||||
"graphviz": "0.0.8",
|
"graphviz": "0.0.8",
|
||||||
"grpc": "1.24.4",
|
"gun": "amark/gun#77162fcb68eb61f24d980fa3f3653598f56ee593",
|
||||||
"gun": "amark/gun#50af2d52ad6677fd5b95e5ed64fca7491c7877b5",
|
|
||||||
"husky": "^4.2.5",
|
"husky": "^4.2.5",
|
||||||
"hybrid-relay-client": "git://github.com/shocknet/hybridRelayClient#a99e57794cf7a62f0f5b6aef53a35d6b77d0a889",
|
"hybrid-relay-client": "git://github.com/shocknet/hybridRelayClient#a99e57794cf7a62f0f5b6aef53a35d6b77d0a889",
|
||||||
"jsonfile": "^4.0.0",
|
"jsonfile": "^4.0.0",
|
||||||
|
|
@ -114,5 +114,6 @@
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"npm": "Use yarn!"
|
"npm": "Use yarn!"
|
||||||
}
|
},
|
||||||
|
"packageManager": "yarn@3.1.1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,6 @@ const API = require('../contact-api/index')
|
||||||
|
|
||||||
const gun = Gun({
|
const gun = Gun({
|
||||||
axe: false,
|
axe: false,
|
||||||
multicast: false,
|
|
||||||
peers: Config.PEERS
|
peers: Config.PEERS
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -482,5 +481,6 @@ module.exports = {
|
||||||
getUser,
|
getUser,
|
||||||
mySEA,
|
mySEA,
|
||||||
getMySecret,
|
getMySecret,
|
||||||
|
logoff,
|
||||||
$$__SHOCKWALLET__ENCRYPTED__
|
$$__SHOCKWALLET__ENCRYPTED__
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,15 @@ const on = (cb, pub) => {
|
||||||
listeners.add(cb)
|
listeners.add(cb)
|
||||||
cb(pubToLastSeenApp)
|
cb(pubToLastSeenApp)
|
||||||
if (pub && pubsWithListeners.add(pub)) {
|
if (pub && pubsWithListeners.add(pub)) {
|
||||||
pubToLastSeenApp[pub] = null;
|
pubToLastSeenApp[pub] = null
|
||||||
notifyListeners()
|
notifyListeners()
|
||||||
require('../../Mediator')
|
require('../../Mediator')
|
||||||
.getGun()
|
.getGun()
|
||||||
.user(pub)
|
.user(pub)
|
||||||
.get(Key.LAST_SEEN_APP)
|
.get(Key.LAST_SEEN_APP)
|
||||||
.on(timestamp => {
|
.on(timestamp => {
|
||||||
pubToLastSeenApp[pub] = typeof timestamp === 'number' ? timestamp : undefined
|
pubToLastSeenApp[pub] =
|
||||||
|
typeof timestamp === 'number' ? timestamp : undefined
|
||||||
notifyListeners()
|
notifyListeners()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -45,5 +46,5 @@ const on = (cb, pub) => {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getPubToLastSeenApp,
|
getPubToLastSeenApp,
|
||||||
on,
|
on
|
||||||
}
|
}
|
||||||
|
|
@ -179,10 +179,12 @@ const startSocket = socket => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAuthenticated()) {
|
if (isAuthenticated()) {
|
||||||
socket.onAny(() => {
|
socket.onAny(async () => {
|
||||||
GunActions.setLastSeenApp().catch(e =>
|
try {
|
||||||
logger.info('error setting last seen app', e)
|
await GunActions.setLastSeenApp()
|
||||||
)
|
} catch (err) {
|
||||||
|
logger.info('error setting last seen app', err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,7 @@ const add = ({ deviceId, subscriptionId, unsubscribe, metadata }) => {
|
||||||
* @param {string} subscription.subscriptionId
|
* @param {string} subscription.subscriptionId
|
||||||
* @param {Unsubscribe} subscription.unsubscribe
|
* @param {Unsubscribe} subscription.unsubscribe
|
||||||
*/
|
*/
|
||||||
const attachUnsubscribe = ({
|
const attachUnsubscribe = ({ deviceId, subscriptionId, unsubscribe }) => {
|
||||||
deviceId,
|
|
||||||
subscriptionId,
|
|
||||||
unsubscribe
|
|
||||||
}) => {
|
|
||||||
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||||
|
|
||||||
const subscriptions = deviceSubscriptions
|
const subscriptions = deviceSubscriptions
|
||||||
|
|
@ -68,7 +64,7 @@ const remove = ({ deviceId, subscriptionId }) => {
|
||||||
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||||
|
|
||||||
const subscriptions = deviceSubscriptions ?? new Map()
|
const subscriptions = deviceSubscriptions ?? new Map()
|
||||||
const subscription = subscriptions.get(subscriptionId);
|
const subscription = subscriptions.get(subscriptionId)
|
||||||
|
|
||||||
if (subscription?.unsubscribe) {
|
if (subscription?.unsubscribe) {
|
||||||
subscription.unsubscribe()
|
subscription.unsubscribe()
|
||||||
|
|
@ -84,7 +80,7 @@ const remove = ({ deviceId, subscriptionId }) => {
|
||||||
* @param {string} subscription.deviceId
|
* @param {string} subscription.deviceId
|
||||||
*/
|
*/
|
||||||
const removeDevice = ({ deviceId }) => {
|
const removeDevice = ({ deviceId }) => {
|
||||||
const deviceSubscriptions = userSubscriptions.get(deviceId);
|
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||||
|
|
||||||
if (!deviceSubscriptions) {
|
if (!deviceSubscriptions) {
|
||||||
return
|
return
|
||||||
|
|
@ -98,7 +94,7 @@ const removeDevice = ({ deviceId }) => {
|
||||||
return subscription
|
return subscription
|
||||||
})
|
})
|
||||||
|
|
||||||
userSubscriptions.set(deviceId, new Map());
|
userSubscriptions.set(deviceId, new Map())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -518,6 +518,10 @@ module.exports = async (
|
||||||
|
|
||||||
await recreateLnServices()
|
await recreateLnServices()
|
||||||
|
|
||||||
|
if (GunDB.isAuthenticated()) {
|
||||||
|
GunDB.logoff()
|
||||||
|
}
|
||||||
|
|
||||||
const publicKey = await GunDB.authenticate(alias, password)
|
const publicKey = await GunDB.authenticate(alias, password)
|
||||||
|
|
||||||
if (!publicKey) {
|
if (!publicKey) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"include": ["./services/gunDB/**/*.*", "./utils/lightningServices/**/*.*"],
|
"include": ["./services/gunDB/**/*.*", "./utils/lightningServices/**/*.*"],
|
||||||
|
"exclude": ["./node_modules/**/*.*"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
/* Basic Options */
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
/* eslint-disable no-use-before-define */
|
/* eslint-disable no-use-before-define */
|
||||||
/* eslint-disable func-style */
|
/* eslint-disable func-style */
|
||||||
// @ts-check
|
// @ts-no-check TODO: Temporarily disabled TS checking due to new GunDB version
|
||||||
/// <reference path="Smith.ts" />
|
/// <reference path="Smith.ts" />
|
||||||
/// <reference path="GunT.ts" />
|
/// <reference path="GunT.ts" />
|
||||||
const uuid = require('uuid/v1')
|
const uuid = require('uuid/v1')
|
||||||
|
|
@ -133,7 +133,7 @@ let lastAlias = ''
|
||||||
let lastPass = ''
|
let lastPass = ''
|
||||||
/** @type {GunT.UserPair|null} */
|
/** @type {GunT.UserPair|null} */
|
||||||
let lastPair = null
|
let lastPair = null
|
||||||
/** @type {import('gun/types/options').IGunConstructorOptions} */
|
/** @type {import('gun/types/gun/IGunConstructorOptions').IGunConstructorOptions} */
|
||||||
let lastOpts = {}
|
let lastOpts = {}
|
||||||
let isAuthing = false
|
let isAuthing = false
|
||||||
|
|
||||||
|
|
@ -282,6 +282,7 @@ const forge = () => {
|
||||||
|
|
||||||
/** @type {Smith.SmithMsgInit} */
|
/** @type {Smith.SmithMsgInit} */
|
||||||
const initMsg = {
|
const initMsg = {
|
||||||
|
// @ts-ignore TODO: Fix options typings
|
||||||
opts: lastOpts,
|
opts: lastOpts,
|
||||||
type: 'init'
|
type: 'init'
|
||||||
}
|
}
|
||||||
|
|
@ -728,7 +729,7 @@ function createUserReplica() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('gun/types/options').IGunConstructorOptions} opts
|
* @param {import('gun/types/gun/IGunConstructorOptions').IGunConstructorOptions} opts
|
||||||
* @returns {Smith.GunSmithNode}
|
* @returns {Smith.GunSmithNode}
|
||||||
*/
|
*/
|
||||||
const Gun = opts => {
|
const Gun = opts => {
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
unprotectedRoutes: {
|
unprotectedRoutes: {
|
||||||
GET: {
|
GET: {
|
||||||
"/healthz": true,
|
'/healthz': true,
|
||||||
"/ping": true,
|
'/ping': true,
|
||||||
"/tunnel/status": true,
|
'/tunnel/status': true,
|
||||||
// Errors out when viewing an API page from the browser
|
// Errors out when viewing an API page from the browser
|
||||||
"/favicon.ico": true,
|
'/favicon.ico': true,
|
||||||
"/api/lnd/connect": true,
|
'/api/lnd/connect': true,
|
||||||
"/api/lnd/wallet/status": true,
|
'/api/lnd/wallet/status': true,
|
||||||
"/api/lnd/auth": true,
|
'/api/lnd/auth': true,
|
||||||
//
|
//
|
||||||
"/api/gun/auth": true,
|
'/api/gun/auth': true,
|
||||||
"/api/subscribeStream":true,
|
'/api/subscribeStream': true,
|
||||||
"/":true,
|
'/': true,
|
||||||
"/api/accessInfo":true,
|
'/api/accessInfo': true,
|
||||||
"/qrCodeGenerator":true,
|
'/qrCodeGenerator': true
|
||||||
},
|
},
|
||||||
POST: {
|
POST: {
|
||||||
"/api/lnd/connect": true,
|
'/api/lnd/connect': true,
|
||||||
"/api/lnd/wallet": true,
|
'/api/lnd/wallet': true,
|
||||||
"/api/lnd/wallet/existing": true,
|
'/api/lnd/wallet/existing': true,
|
||||||
"/api/lnd/auth": true,
|
'/api/lnd/auth': true,
|
||||||
"/api/security/exchangeKeys": true,
|
'/api/security/exchangeKeys': true,
|
||||||
"/api/encryption/exchange": true
|
'/api/encryption/exchange': true
|
||||||
},
|
},
|
||||||
PUT: {},
|
PUT: {},
|
||||||
DELETE: {},
|
DELETE: {},
|
||||||
|
|
@ -39,11 +39,24 @@ module.exports = {
|
||||||
sensitiveRoutes: {
|
sensitiveRoutes: {
|
||||||
GET: {},
|
GET: {},
|
||||||
POST: {
|
POST: {
|
||||||
"/api/lnd/connect": true,
|
'/api/lnd/connect': true,
|
||||||
"/api/lnd/wallet": true
|
'/api/lnd/wallet': true
|
||||||
},
|
},
|
||||||
PUT: {},
|
PUT: {},
|
||||||
DELETE: {}
|
DELETE: {}
|
||||||
},
|
},
|
||||||
nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/tunnel/status', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream", "/", "/api/accessInfo","/qrCodeGenerator"]
|
nonEncryptedRoutes: [
|
||||||
|
'/api/security/exchangeKeys',
|
||||||
|
'/api/encryption/exchange',
|
||||||
|
'/healthz',
|
||||||
|
'/ping',
|
||||||
|
'/tunnel/status',
|
||||||
|
'/api/lnd/wallet/status',
|
||||||
|
'/api/gun/auth',
|
||||||
|
'/api/subscribeStream',
|
||||||
|
'/',
|
||||||
|
'/api/accessInfo',
|
||||||
|
'/qrCodeGenerator',
|
||||||
|
'/gun'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue