mirror of https://codeberg.org/pzp/pzp-invite.git
update secret-stack to 8.1
This commit is contained in:
parent
b08e3d7c9f
commit
149b2dd86f
79
lib/index.js
79
lib/index.js
|
@ -67,17 +67,13 @@ function parseJoinCommand(pieces, uri) {
|
|||
// prettier-ignore
|
||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing join hub pubkey`)
|
||||
}
|
||||
// TODO: base58 validation for the token
|
||||
if (!token) {
|
||||
// prettier-ignore
|
||||
throw new Error(`Invalid URI "${uri}" for invite.parse, missing join hub token`)
|
||||
}
|
||||
// TODO: base58 validation for the token, if present at all
|
||||
pieces.shift()
|
||||
pieces.shift()
|
||||
pieces.shift()
|
||||
pieces.shift()
|
||||
pieces.shift()
|
||||
const shse = `shse:${pubkey}:${token}`
|
||||
const shse = token ? `shse:${pubkey}:${token}` : `shse:${pubkey}`
|
||||
const address = `net:${host}:${port}~${shse}` // TODO: add ws address here
|
||||
return { type: 'join', address }
|
||||
}
|
||||
|
@ -221,53 +217,14 @@ function parse(uri) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {{ shse: SHSE | null }} peer
|
||||
* @returns {asserts peer is { shse: SHSE }}
|
||||
*/
|
||||
function assertSHSEExists(peer) {
|
||||
if (!peer.shse) throw new Error('"invite" plugin requires "shse" plugin')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ promise: PPPPPPromise | null }} peer
|
||||
* @returns {asserts peer is { promise: PPPPPPromise }}
|
||||
*/
|
||||
function assertPromisePlugin(peer) {
|
||||
// prettier-ignore
|
||||
if (!peer.promise) throw new Error('"invite" plugin requires "promise" plugin')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ conn: ConnPlugin | null }} peer
|
||||
* @returns {asserts peer is { conn: ConnPlugin }}
|
||||
*/
|
||||
function assertConnPlugin(peer) {
|
||||
if (!peer.conn) throw new Error('"invite" plugin requires "conn" plugin')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'invite',
|
||||
manifest: {
|
||||
createForFriend: 'async',
|
||||
createForMyself: 'async',
|
||||
parse: 'sync',
|
||||
},
|
||||
|
||||
parse,
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* shse: SHSE | null;
|
||||
* promise: PPPPPPromise | null;
|
||||
* conn: ConnPlugin | null;
|
||||
* shse: SHSE;
|
||||
* promise: PPPPPPromise;
|
||||
* conn: ConnPlugin;
|
||||
* }} peer
|
||||
* @param {unknown} config
|
||||
*/
|
||||
init(peer, config) {
|
||||
assertSHSEExists(peer)
|
||||
assertPromisePlugin(peer)
|
||||
assertConnPlugin(peer)
|
||||
|
||||
function initInvite(peer, config) {
|
||||
/**
|
||||
* @param {{
|
||||
* hubs?: number,
|
||||
|
@ -278,12 +235,6 @@ module.exports = {
|
|||
* @param {CB<{uri: string, url: string}>} cb
|
||||
*/
|
||||
async function createForFriend(opts, cb) {
|
||||
try {
|
||||
assertConnPlugin(peer)
|
||||
assertPromisePlugin(peer)
|
||||
} catch (err) {
|
||||
return cb(/**@type {Error}*/ (err))
|
||||
}
|
||||
if (typeof opts !== 'object') {
|
||||
return cb(new Error('invite.createForFriend is missing opts argument'))
|
||||
}
|
||||
|
@ -348,13 +299,6 @@ module.exports = {
|
|||
* @param {CB<{uri: string, url: string}>} cb
|
||||
*/
|
||||
async function createForMyself(opts, cb) {
|
||||
try {
|
||||
assertSHSEExists(peer)
|
||||
assertConnPlugin(peer)
|
||||
assertPromisePlugin(peer)
|
||||
} catch (err) {
|
||||
return cb(/**@type {Error}*/ (err))
|
||||
}
|
||||
if (typeof opts !== 'object') {
|
||||
return cb(new Error('invite.createForMyself is missing opts argument'))
|
||||
}
|
||||
|
@ -410,5 +354,14 @@ module.exports = {
|
|||
}
|
||||
|
||||
return { createForFriend, createForMyself, parse }
|
||||
},
|
||||
}
|
||||
|
||||
exports.name = 'invite'
|
||||
exports.needs = ['shse', 'promise', 'conn']
|
||||
exports.manifest = {
|
||||
createForFriend: 'async',
|
||||
createForMyself: 'async',
|
||||
parse: 'sync',
|
||||
}
|
||||
exports.init = initInvite
|
||||
exports.parse = parse
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
"pretty-quick": "^3.1.3",
|
||||
"rimraf": "^5.0.1",
|
||||
"secret-handshake-ext": "0.0.11",
|
||||
"secret-stack": "~8.0.0",
|
||||
"secret-stack": "~8.1.0",
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue