change how tunnel-connect commands parse

This commit is contained in:
Andre Staltz 2023-07-20 20:07:23 +03:00
parent 7283a1e5b7
commit 2c753a76a8
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 26 additions and 4 deletions

View File

@ -24,8 +24,7 @@ const p = require('promisify-tuple')
*
* @typedef {{
* type: 'tunnel-connect',
* hubPubkey: string,
* targetPubkey: string,
* address: string,
* }} TunnelConnectCommand
*
* @typedef {`tunnel-connect/${string}/${string}`} TunnelConnectCommandStr
@ -126,7 +125,8 @@ function parseTunnelConnectCommand(pieces, uri) {
pieces.shift()
pieces.shift()
pieces.shift()
return { type: 'tunnel-connect', hubPubkey, targetPubkey }
const address = `tunnel:${hubPubkey}:${targetPubkey}~shse:${targetPubkey}`
return { type: 'tunnel-connect', address }
}
/**

View File

@ -14,7 +14,7 @@ test('parse() error cases', (t) => {
})
})
test('parse() good cases', (t) => {
test('parse() good friend invite', (t) => {
const commands = plugin.parse(
'ppppp://invite/join/HOST/PORT/PUBKEY/TOKEN/follow/ALICE/promise.follow/identity.ALICE/ALICE_TOKEN'
)
@ -34,3 +34,25 @@ test('parse() good cases', (t) => {
},
])
})
test('parse() good myself invite', (t) => {
const commands = plugin.parse(
'ppppp://invite/join/HOST/PORT/PUBKEY/TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.identity-add/identity.IDENTITY_ID/OLD_TOKEN'
)
assert.deepEqual(commands, [
{
type: 'join',
address: 'net:HOST:PORT~shse:PUBKEY:TOKEN',
},
{
type: 'tunnel-connect',
address: 'tunnel:HUB_PUBKEY:OLD_PUBKEY~shse:OLD_PUBKEY',
},
{
type: 'promise.identity-add',
issuerID: 'IDENTITY_ID',
token: 'OLD_TOKEN',
},
])
})