monkey-patch conn base64 key to base58

This commit is contained in:
Andre Staltz 2023-07-12 18:06:24 +03:00
parent 51f06784b5
commit a97fe9a0c2
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 17 additions and 11 deletions

View File

@ -1,3 +1,4 @@
const bs58 = require('bs58')
const debug = require('debug')('ppppp:hub-client')
const pull = require('pull-stream')
const run = require('promisify-tuple')
@ -31,7 +32,9 @@ const makeTunnelPlugin = (hubs, sstack) => (/** @type {any}} */ msConfig) => {
pull.filter(({ type }) => type === 'connected'),
pull.drain(async ({ address, key, details }) => {
if (!key) return
if (hubs.has(key)) return
// TODO: once secret-stack is updated, we won't need this anymore:
const pubkey = bs58.encode(Buffer.from(key, 'base64'))
if (hubs.has(pubkey)) return
if (!details?.rpc) return
if (address.startsWith('tunnel:')) return
const rpc = details.rpc
@ -41,13 +44,13 @@ const makeTunnelPlugin = (hubs, sstack) => (/** @type {any}} */ msConfig) => {
debug('failure when calling hub.metadata: %s', err.message ?? err)
return
}
debug('connected to hub %s', key)
if (hubs.has(key)) {
hubs.get(key)?.cancel()
hubs.delete(key)
debug('connected to hub %s', pubkey)
if (hubs.has(pubkey)) {
hubs.get(pubkey)?.cancel()
hubs.delete(pubkey)
}
const obs = new HubObserver(sstack, key, address, res, rpc, onConnect)
hubs.set(key, obs)
const obs = new HubObserver(sstack, pubkey, address, res, rpc, onConnect)
hubs.set(pubkey, obs)
})
)
@ -57,9 +60,11 @@ const makeTunnelPlugin = (hubs, sstack) => (/** @type {any}} */ msConfig) => {
pull.filter(({ type }) => type === 'disconnected'),
pull.drain(({ key }) => {
if (!key) return
if (!hubs.has(key)) return
hubs.get(key)?.close()
hubs.delete(key)
// TODO: once secret-stack is updated, we won't need this anymore:
const pubkey = bs58.encode(Buffer.from(key, 'base64'))
if (!hubs.has(pubkey)) return
hubs.get(pubkey)?.close()
hubs.delete(pubkey)
})
)

View File

@ -23,6 +23,7 @@
"node": ">=16"
},
"dependencies": {
"bs58": "^5.0.0",
"debug": "^4.3.4",
"promisify-tuple": "~1.2.0",
"pull-notify": "~0.1.2",
@ -32,8 +33,8 @@
},
"devDependencies": {
"@types/debug": "^4.1.8",
"@types/node": "16.x",
"@types/pull-stream": "^3.6.2",
"bs58": "^5.0.0",
"c8": "7",
"husky": "^4.3.0",
"prettier": "^2.6.2",