update secret-stack to 8.1

This commit is contained in:
Andre Staltz 2024-01-08 11:53:32 +02:00
parent b08e3d7c9f
commit 149b2dd86f
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 135 additions and 182 deletions

View File

@ -67,17 +67,13 @@ function parseJoinCommand(pieces, uri) {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, missing join hub pubkey`) throw new Error(`Invalid URI "${uri}" for invite.parse, missing join hub pubkey`)
} }
// TODO: base58 validation for the token // TODO: base58 validation for the token, if present at all
if (!token) {
// prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, missing join hub token`)
}
pieces.shift() pieces.shift()
pieces.shift() pieces.shift()
pieces.shift() 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 const address = `net:${host}:${port}~${shse}` // TODO: add ws address here
return { type: 'join', address } return { type: 'join', address }
} }
@ -220,54 +216,15 @@ function parse(uri) {
return commands return commands
} }
/**
* @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 {{ * @param {{
* shse: SHSE | null; * shse: SHSE;
* promise: PPPPPPromise | null; * promise: PPPPPPromise;
* conn: ConnPlugin | null; * conn: ConnPlugin;
* }} peer * }} peer
* @param {unknown} config * @param {unknown} config
*/ */
init(peer, config) { function initInvite(peer, config) {
assertSHSEExists(peer)
assertPromisePlugin(peer)
assertConnPlugin(peer)
/** /**
* @param {{ * @param {{
* hubs?: number, * hubs?: number,
@ -278,12 +235,6 @@ module.exports = {
* @param {CB<{uri: string, url: string}>} cb * @param {CB<{uri: string, url: string}>} cb
*/ */
async function createForFriend(opts, cb) { async function createForFriend(opts, cb) {
try {
assertConnPlugin(peer)
assertPromisePlugin(peer)
} catch (err) {
return cb(/**@type {Error}*/ (err))
}
if (typeof opts !== 'object') { if (typeof opts !== 'object') {
return cb(new Error('invite.createForFriend is missing opts argument')) return cb(new Error('invite.createForFriend is missing opts argument'))
} }
@ -348,13 +299,6 @@ module.exports = {
* @param {CB<{uri: string, url: string}>} cb * @param {CB<{uri: string, url: string}>} cb
*/ */
async function createForMyself(opts, cb) { async function createForMyself(opts, cb) {
try {
assertSHSEExists(peer)
assertConnPlugin(peer)
assertPromisePlugin(peer)
} catch (err) {
return cb(/**@type {Error}*/ (err))
}
if (typeof opts !== 'object') { if (typeof opts !== 'object') {
return cb(new Error('invite.createForMyself is missing opts argument')) return cb(new Error('invite.createForMyself is missing opts argument'))
} }
@ -410,5 +354,14 @@ module.exports = {
} }
return { createForFriend, createForMyself, parse } 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

View File

@ -37,7 +37,7 @@
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"secret-handshake-ext": "0.0.11", "secret-handshake-ext": "0.0.11",
"secret-stack": "~8.0.0", "secret-stack": "~8.1.0",
"typescript": "^5.1.3" "typescript": "^5.1.3"
}, },
"scripts": { "scripts": {