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
|
||||
DATA_FILE_NAME=radata2
|
||||
# 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
|
||||
MS_TO_TOKEN_EXPIRATION=4500000
|
||||
# E2EE
|
||||
|
|
|
|||
8
.gitignore
vendored
8
.gitignore
vendored
|
|
@ -15,3 +15,11 @@ radata-*.tmp
|
|||
*.key
|
||||
|
||||
*-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": [
|
||||
{
|
||||
"name": "Attach",
|
||||
"port": 9229,
|
||||
"request": "attach",
|
||||
"skipFiles": ["<node_internals>/**"],
|
||||
"type": "pwa-node"
|
||||
},
|
||||
{
|
||||
"name": "Nodemon",
|
||||
"program": "${workspaceFolder}/main.js",
|
||||
|
|
@ -34,17 +41,14 @@
|
|||
"--",
|
||||
"-h",
|
||||
"0.0.0.0",
|
||||
"--trace-warnings",
|
||||
"--max-old-space-size=4096",
|
||||
"-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",
|
||||
"/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",
|
||||
"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",
|
||||
"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:attach": "node --inspect --trace-warnings --max-old-space-size=4096 main.js -h 0.0.0.0",
|
||||
"test": "mocha ./utils -b -t 50000 --recursive",
|
||||
"typecheck": "tsc",
|
||||
"lint": "eslint \"services/gunDB/**/*.js\"",
|
||||
|
|
@ -38,8 +39,7 @@
|
|||
"express-session": "^1.17.1",
|
||||
"google-proto-files": "^1.0.3",
|
||||
"graphviz": "0.0.8",
|
||||
"grpc": "1.24.4",
|
||||
"gun": "amark/gun#50af2d52ad6677fd5b95e5ed64fca7491c7877b5",
|
||||
"gun": "amark/gun#77162fcb68eb61f24d980fa3f3653598f56ee593",
|
||||
"husky": "^4.2.5",
|
||||
"hybrid-relay-client": "git://github.com/shocknet/hybridRelayClient#a99e57794cf7a62f0f5b6aef53a35d6b77d0a889",
|
||||
"jsonfile": "^4.0.0",
|
||||
|
|
@ -114,5 +114,6 @@
|
|||
},
|
||||
"engines": {
|
||||
"npm": "Use yarn!"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@3.1.1"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,7 +260,6 @@ const API = require('../contact-api/index')
|
|||
|
||||
const gun = Gun({
|
||||
axe: false,
|
||||
multicast: false,
|
||||
peers: Config.PEERS
|
||||
})
|
||||
|
||||
|
|
@ -482,5 +481,6 @@ module.exports = {
|
|||
getUser,
|
||||
mySEA,
|
||||
getMySecret,
|
||||
logoff,
|
||||
$$__SHOCKWALLET__ENCRYPTED__
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,14 +27,15 @@ const on = (cb, pub) => {
|
|||
listeners.add(cb)
|
||||
cb(pubToLastSeenApp)
|
||||
if (pub && pubsWithListeners.add(pub)) {
|
||||
pubToLastSeenApp[pub] = null;
|
||||
pubToLastSeenApp[pub] = null
|
||||
notifyListeners()
|
||||
require('../../Mediator')
|
||||
.getGun()
|
||||
.user(pub)
|
||||
.get(Key.LAST_SEEN_APP)
|
||||
.on(timestamp => {
|
||||
pubToLastSeenApp[pub] = typeof timestamp === 'number' ? timestamp : undefined
|
||||
pubToLastSeenApp[pub] =
|
||||
typeof timestamp === 'number' ? timestamp : undefined
|
||||
notifyListeners()
|
||||
})
|
||||
}
|
||||
|
|
@ -45,5 +46,5 @@ const on = (cb, pub) => {
|
|||
|
||||
module.exports = {
|
||||
getPubToLastSeenApp,
|
||||
on,
|
||||
}
|
||||
on
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,10 +179,12 @@ const startSocket = socket => {
|
|||
}
|
||||
|
||||
if (isAuthenticated()) {
|
||||
socket.onAny(() => {
|
||||
GunActions.setLastSeenApp().catch(e =>
|
||||
logger.info('error setting last seen app', e)
|
||||
)
|
||||
socket.onAny(async () => {
|
||||
try {
|
||||
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 {Unsubscribe} subscription.unsubscribe
|
||||
*/
|
||||
const attachUnsubscribe = ({
|
||||
deviceId,
|
||||
subscriptionId,
|
||||
unsubscribe
|
||||
}) => {
|
||||
const attachUnsubscribe = ({ deviceId, subscriptionId, unsubscribe }) => {
|
||||
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||
|
||||
const subscriptions = deviceSubscriptions
|
||||
|
|
@ -68,7 +64,7 @@ const remove = ({ deviceId, subscriptionId }) => {
|
|||
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||
|
||||
const subscriptions = deviceSubscriptions ?? new Map()
|
||||
const subscription = subscriptions.get(subscriptionId);
|
||||
const subscription = subscriptions.get(subscriptionId)
|
||||
|
||||
if (subscription?.unsubscribe) {
|
||||
subscription.unsubscribe()
|
||||
|
|
@ -84,7 +80,7 @@ const remove = ({ deviceId, subscriptionId }) => {
|
|||
* @param {string} subscription.deviceId
|
||||
*/
|
||||
const removeDevice = ({ deviceId }) => {
|
||||
const deviceSubscriptions = userSubscriptions.get(deviceId);
|
||||
const deviceSubscriptions = userSubscriptions.get(deviceId)
|
||||
|
||||
if (!deviceSubscriptions) {
|
||||
return
|
||||
|
|
@ -98,7 +94,7 @@ const removeDevice = ({ deviceId }) => {
|
|||
return subscription
|
||||
})
|
||||
|
||||
userSubscriptions.set(deviceId, new Map());
|
||||
userSubscriptions.set(deviceId, new Map())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,4 +120,4 @@ module.exports = {
|
|||
get,
|
||||
remove,
|
||||
removeDevice
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -518,6 +518,10 @@ module.exports = async (
|
|||
|
||||
await recreateLnServices()
|
||||
|
||||
if (GunDB.isAuthenticated()) {
|
||||
GunDB.logoff()
|
||||
}
|
||||
|
||||
const publicKey = await GunDB.authenticate(alias, password)
|
||||
|
||||
if (!publicKey) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"include": ["./services/gunDB/**/*.*", "./utils/lightningServices/**/*.*"],
|
||||
"exclude": ["./node_modules/**/*.*"],
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
/* eslint-disable no-use-before-define */
|
||||
/* 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="GunT.ts" />
|
||||
const uuid = require('uuid/v1')
|
||||
|
|
@ -133,7 +133,7 @@ let lastAlias = ''
|
|||
let lastPass = ''
|
||||
/** @type {GunT.UserPair|null} */
|
||||
let lastPair = null
|
||||
/** @type {import('gun/types/options').IGunConstructorOptions} */
|
||||
/** @type {import('gun/types/gun/IGunConstructorOptions').IGunConstructorOptions} */
|
||||
let lastOpts = {}
|
||||
let isAuthing = false
|
||||
|
||||
|
|
@ -282,6 +282,7 @@ const forge = () => {
|
|||
|
||||
/** @type {Smith.SmithMsgInit} */
|
||||
const initMsg = {
|
||||
// @ts-ignore TODO: Fix options typings
|
||||
opts: lastOpts,
|
||||
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}
|
||||
*/
|
||||
const Gun = opts => {
|
||||
|
|
|
|||
|
|
@ -1,28 +1,28 @@
|
|||
module.exports = {
|
||||
unprotectedRoutes: {
|
||||
GET: {
|
||||
"/healthz": true,
|
||||
"/ping": true,
|
||||
"/tunnel/status": true,
|
||||
'/healthz': true,
|
||||
'/ping': true,
|
||||
'/tunnel/status': true,
|
||||
// Errors out when viewing an API page from the browser
|
||||
"/favicon.ico": true,
|
||||
"/api/lnd/connect": true,
|
||||
"/api/lnd/wallet/status": true,
|
||||
"/api/lnd/auth": true,
|
||||
'/favicon.ico': true,
|
||||
'/api/lnd/connect': true,
|
||||
'/api/lnd/wallet/status': true,
|
||||
'/api/lnd/auth': true,
|
||||
//
|
||||
"/api/gun/auth": true,
|
||||
"/api/subscribeStream":true,
|
||||
"/":true,
|
||||
"/api/accessInfo":true,
|
||||
"/qrCodeGenerator":true,
|
||||
'/api/gun/auth': true,
|
||||
'/api/subscribeStream': true,
|
||||
'/': true,
|
||||
'/api/accessInfo': true,
|
||||
'/qrCodeGenerator': true
|
||||
},
|
||||
POST: {
|
||||
"/api/lnd/connect": true,
|
||||
"/api/lnd/wallet": true,
|
||||
"/api/lnd/wallet/existing": true,
|
||||
"/api/lnd/auth": true,
|
||||
"/api/security/exchangeKeys": true,
|
||||
"/api/encryption/exchange": true
|
||||
'/api/lnd/connect': true,
|
||||
'/api/lnd/wallet': true,
|
||||
'/api/lnd/wallet/existing': true,
|
||||
'/api/lnd/auth': true,
|
||||
'/api/security/exchangeKeys': true,
|
||||
'/api/encryption/exchange': true
|
||||
},
|
||||
PUT: {},
|
||||
DELETE: {},
|
||||
|
|
@ -39,11 +39,24 @@ module.exports = {
|
|||
sensitiveRoutes: {
|
||||
GET: {},
|
||||
POST: {
|
||||
"/api/lnd/connect": true,
|
||||
"/api/lnd/wallet": true
|
||||
'/api/lnd/connect': true,
|
||||
'/api/lnd/wallet': true
|
||||
},
|
||||
PUT: {},
|
||||
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