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

View File

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