mirror of https://codeberg.org/pzp/pzp-invite.git
flip promise command args around again
The issuer should come first because it's not actually a promise method() argument. It's an identifier to know who to connect to when calling the method.
This commit is contained in:
parent
e931f4ebbd
commit
731395ea97
28
lib/index.js
28
lib/index.js
|
@ -28,13 +28,13 @@ const p = require('promisify-tuple')
|
||||||
* issuer: ['account' | 'pubkey', string],
|
* issuer: ['account' | 'pubkey', string],
|
||||||
* token: string,
|
* token: string,
|
||||||
* }} PromiseFollowCommand
|
* }} PromiseFollowCommand
|
||||||
* @typedef {`promise.follow/${string}/${'account' | 'pubkey'}.${string}`} PromiseFollowCommandStr
|
* @typedef {`promise.follow/${'account' | 'pubkey'}.${string}/${string}`} PromiseFollowCommandStr
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* type: 'promise.account-add',
|
* type: 'promise.account-add',
|
||||||
* issuer: ['account' | 'pubkey', string],
|
* issuer: ['account' | 'pubkey', string],
|
||||||
* token: string,
|
* token: string,
|
||||||
* }} PromiseAccountAddCommand
|
* }} PromiseAccountAddCommand
|
||||||
* @typedef {`promise.account-add/${string}/${'account' | 'pubkey'}.${string}`} PromiseAccountAddCommandStr
|
* @typedef {`promise.account-add/${'account' | 'pubkey'}.${string}/${string}`} PromiseAccountAddCommandStr
|
||||||
* @typedef {| JoinCommand
|
* @typedef {| JoinCommand
|
||||||
* | FollowCommand
|
* | FollowCommand
|
||||||
* | TunnelConnectCommand
|
* | TunnelConnectCommand
|
||||||
|
@ -152,15 +152,15 @@ function parseTunnelConnectCommand(pieces, uri) {
|
||||||
* @returns {PromiseFollowCommand}
|
* @returns {PromiseFollowCommand}
|
||||||
*/
|
*/
|
||||||
function parsePromiseFollowCommand(pieces, uri) {
|
function parsePromiseFollowCommand(pieces, uri) {
|
||||||
const [label, token, issuerAndType] = pieces
|
const [label, issuerAndType, token] = pieces
|
||||||
if (!token) {
|
|
||||||
// prettier-ignore
|
|
||||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.follow token`)
|
|
||||||
}
|
|
||||||
if (!issuerAndType) {
|
if (!issuerAndType) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.follow issuer`)
|
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.follow issuer`)
|
||||||
}
|
}
|
||||||
|
if (!token) {
|
||||||
|
// prettier-ignore
|
||||||
|
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.follow token`)
|
||||||
|
}
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
|
@ -182,15 +182,15 @@ function parsePromiseFollowCommand(pieces, uri) {
|
||||||
* @returns {PromiseAccountAddCommand}
|
* @returns {PromiseAccountAddCommand}
|
||||||
*/
|
*/
|
||||||
function parsePromiseAccountAddCommand(pieces, uri) {
|
function parsePromiseAccountAddCommand(pieces, uri) {
|
||||||
const [label, token, issuerAndType] = pieces
|
const [label, issuerAndType, token] = pieces
|
||||||
if (!token) {
|
|
||||||
// prettier-ignore
|
|
||||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.account-add token`)
|
|
||||||
}
|
|
||||||
if (!issuerAndType) {
|
if (!issuerAndType) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.account-add issuer`)
|
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.account-add issuer`)
|
||||||
}
|
}
|
||||||
|
if (!token) {
|
||||||
|
// prettier-ignore
|
||||||
|
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.account-add token`)
|
||||||
|
}
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
pieces.shift()
|
pieces.shift()
|
||||||
|
@ -380,7 +380,7 @@ function initInvite(peer, config) {
|
||||||
})
|
})
|
||||||
if (err2) return cb(err2)
|
if (err2) return cb(err2)
|
||||||
/** @type {PromiseFollowCommandStr} */
|
/** @type {PromiseFollowCommandStr} */
|
||||||
const promiseCommand = `promise.follow/${token}/pubkey.${peer.shse.pubkey}`
|
const promiseCommand = `promise.follow/pubkey.${peer.shse.pubkey}/${token}`
|
||||||
|
|
||||||
// Create follow command
|
// Create follow command
|
||||||
/** @type {FollowCommandStr} */
|
/** @type {FollowCommandStr} */
|
||||||
|
@ -429,7 +429,7 @@ function initInvite(peer, config) {
|
||||||
const [err3, token] = await p(peer.promise.create)(promise)
|
const [err3, token] = await p(peer.promise.create)(promise)
|
||||||
if (err3) return cb(err3)
|
if (err3) return cb(err3)
|
||||||
/** @type {PromiseAccountAddCommandStr} */
|
/** @type {PromiseAccountAddCommandStr} */
|
||||||
const promiseCommand = `promise.account-add/${token}/pubkey.${peer.shse.pubkey}`
|
const promiseCommand = `promise.account-add/pubkey.${peer.shse.pubkey}/${token}`
|
||||||
|
|
||||||
// Create tunnel-connect command
|
// Create tunnel-connect command
|
||||||
/** @type {TunnelConnectCommandStr} */
|
/** @type {TunnelConnectCommandStr} */
|
||||||
|
|
|
@ -89,11 +89,11 @@ test('createForFriend()', async (t) => {
|
||||||
})
|
})
|
||||||
assert.equal(
|
assert.equal(
|
||||||
uri,
|
uri,
|
||||||
`ppppp://invite/join/dns/example.com/tcp/8008/shse/HUB_PUBKEY.MOCK_TOKEN/follow/MOCK_ID/promise.follow/MOCK_PROMISE/pubkey.${keypair.public}`
|
`ppppp://invite/join/dns/example.com/tcp/8008/shse/HUB_PUBKEY.MOCK_TOKEN/follow/MOCK_ID/promise.follow/pubkey.${keypair.public}/MOCK_PROMISE`
|
||||||
)
|
)
|
||||||
assert.equal(
|
assert.equal(
|
||||||
url,
|
url,
|
||||||
`https://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fdns%2Fexample.com%2Ftcp%2F8008%2Fshse%2FHUB_PUBKEY.MOCK_TOKEN%2Ffollow%2FMOCK_ID%2Fpromise.follow%2FMOCK_PROMISE%2Fpubkey.${keypair.public}`
|
`https://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fdns%2Fexample.com%2Ftcp%2F8008%2Fshse%2FHUB_PUBKEY.MOCK_TOKEN%2Ffollow%2FMOCK_ID%2Fpromise.follow%2Fpubkey.${keypair.public}%2FMOCK_PROMISE`
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.ok(connectCalled)
|
assert.ok(connectCalled)
|
||||||
|
|
|
@ -87,11 +87,11 @@ test('createForMyself()', async (t) => {
|
||||||
})
|
})
|
||||||
assert.equal(
|
assert.equal(
|
||||||
uri,
|
uri,
|
||||||
`ppppp://invite/join/dns/example.com/tcp/8008/shse/HUB_PUBKEY.MOCK_TOKEN/tunnel-connect/HUB_PUBKEY/${local.shse.pubkey}/promise.account-add/MOCK_PROMISE/pubkey.${keypair.public}`
|
`ppppp://invite/join/dns/example.com/tcp/8008/shse/HUB_PUBKEY.MOCK_TOKEN/tunnel-connect/HUB_PUBKEY/${local.shse.pubkey}/promise.account-add/pubkey.${keypair.public}/MOCK_PROMISE`
|
||||||
)
|
)
|
||||||
assert.equal(
|
assert.equal(
|
||||||
url,
|
url,
|
||||||
`https://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fdns%2Fexample.com%2Ftcp%2F8008%2Fshse%2FHUB_PUBKEY.MOCK_TOKEN%2Ftunnel-connect%2FHUB_PUBKEY%2F${local.shse.pubkey}%2Fpromise.account-add%2FMOCK_PROMISE%2Fpubkey.${keypair.public}`
|
`https://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fdns%2Fexample.com%2Ftcp%2F8008%2Fshse%2FHUB_PUBKEY.MOCK_TOKEN%2Ftunnel-connect%2FHUB_PUBKEY%2F${local.shse.pubkey}%2Fpromise.account-add%2Fpubkey.${keypair.public}%2FMOCK_PROMISE`
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.ok(connectCalled)
|
assert.ok(connectCalled)
|
||||||
|
|
|
@ -16,7 +16,7 @@ test('parse() error cases', (t) => {
|
||||||
|
|
||||||
test('parse() good friend invite', (t) => {
|
test('parse() good friend invite', (t) => {
|
||||||
const commands = plugin.parse(
|
const commands = plugin.parse(
|
||||||
'ppppp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/follow/ALICE/promise.follow/ALICE_TOKEN/pubkey.ALICE'
|
'ppppp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/follow/ALICE/promise.follow/pubkey.ALICE/ALICE_TOKEN'
|
||||||
)
|
)
|
||||||
assert.deepEqual(commands, [
|
assert.deepEqual(commands, [
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ test('parse() good friend invite', (t) => {
|
||||||
|
|
||||||
test('parse() good myself invite', (t) => {
|
test('parse() good myself invite', (t) => {
|
||||||
const commands = plugin.parse(
|
const commands = plugin.parse(
|
||||||
'ppppp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/OLD_TOKEN/pubkey.PUBKEY'
|
'ppppp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY.TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/pubkey.PUBKEY/OLD_TOKEN'
|
||||||
)
|
)
|
||||||
assert.deepEqual(commands, [
|
assert.deepEqual(commands, [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue