Rename to pzp

This commit is contained in:
Jacob Karlsson 2024-05-07 18:11:39 +02:00
parent 745eea3de0
commit 2a8c096c8b
9 changed files with 62 additions and 70 deletions

View File

@ -1,27 +0,0 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 2
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test

13
.woodpecker.yaml Normal file
View File

@ -0,0 +1,13 @@
matrix:
NODE_VERSION:
- 18
- 20
steps:
test:
when:
event: [push]
image: node:${NODE_VERSION}
commands:
- npm install
- npm test

View File

@ -1,3 +1,9 @@
# ppppp-invite # pzp-invite
**Work in progress** PZP invite code generator and parser
## Installation
```
npm install pzp-invite
```

View File

@ -4,10 +4,10 @@ const p = require('promisify-tuple')
/** /**
* @typedef {{ pubkey: string }} SHSE * @typedef {{ pubkey: string }} SHSE
* @typedef {ReturnType<import('ppppp-promise').init>} PPPPPPromise * @typedef {ReturnType<import('pzp-promise').init>} PZPPromise
* @typedef {ReturnType<import('ppppp-net').init>} PPPPPNet * @typedef {ReturnType<import('pzp-net').init>} PZPNet
* @typedef {ReturnType<import('ppppp-hub-client/plugin').init>} PPPPPHubClient * @typedef {ReturnType<import('pzp-hub-client/plugin').init>} PZPHubClient
* @typedef {import('ppppp-hub-client/plugin').HubMultiaddr} HubMultiaddr * @typedef {import('pzp-hub-client/plugin').HubMultiaddr} HubMultiaddr
* @typedef {{ * @typedef {{
* type: 'join', * type: 'join',
* multiaddr: string, * multiaddr: string,
@ -43,9 +43,9 @@ const p = require('promisify-tuple')
* } Command * } Command
* @typedef {{ * @typedef {{
* shse: SHSE; * shse: SHSE;
* promise: PPPPPPromise; * promise: PZPPromise;
* hubClient: PPPPPHubClient; * hubClient: PZPHubClient;
* net: PPPPPNet; * net: PZPNet;
* }} Peer * }} Peer
*/ */
@ -206,14 +206,14 @@ function parsePromiseAccountAddCommand(pieces, uri) {
} }
/** /**
* @param {`ppppp://invite/${string}`} uri * @param {`pzp://invite/${string}`} uri
* @returns {Array<Command>} * @returns {Array<Command>}
*/ */
function parse(uri) { function parse(uri) {
const url = new URL(uri) const url = new URL(uri)
if (url.protocol !== 'ppppp:') { if (url.protocol !== 'pzp:') {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid protocol in URI "${uri}" for invite.parse, expected "ppppp:"`) throw new Error(`Invalid protocol in URI "${uri}" for invite.parse, expected "pzp:"`)
} }
if (url.host !== 'invite') { if (url.host !== 'invite') {
// prettier-ignore // prettier-ignore
@ -386,7 +386,7 @@ function initInvite(peer, config) {
const followCommand = `follow/${opts.id}` const followCommand = `follow/${opts.id}`
// prettier-ignore // prettier-ignore
const uri = `ppppp://invite/${joinCommands.join('/')}/${followCommand}/${promiseCommand}` const uri = `pzp://invite/${joinCommands.join('/')}/${followCommand}/${promiseCommand}`
const url = `${protocol}://${hostname}/invite#${encodeURIComponent(uri)}` const url = `${protocol}://${hostname}/invite#${encodeURIComponent(uri)}`
cb(null, { uri, url }) cb(null, { uri, url })
} }
@ -435,7 +435,7 @@ function initInvite(peer, config) {
const tunnelCommand = `tunnel-connect/${pubkey}/${peer.shse.pubkey}` const tunnelCommand = `tunnel-connect/${pubkey}/${peer.shse.pubkey}`
// prettier-ignore // prettier-ignore
const uri = `ppppp://invite/${joinCommands.join('/')}/${tunnelCommand}/${promiseCommand}` const uri = `pzp://invite/${joinCommands.join('/')}/${tunnelCommand}/${promiseCommand}`
const url = `${protocol}://${hostname}/invite#${encodeURIComponent(uri)}` const url = `${protocol}://${hostname}/invite#${encodeURIComponent(uri)}`
cb(null, { uri, url }) cb(null, { uri, url })
} }

View File

@ -1,11 +1,11 @@
{ {
"name": "ppppp-invite", "name": "pzp-invite",
"version": "0.0.1", "version": "0.0.1",
"description": "PPPPP invite code generator and parser", "description": "PZP invite code generator and parser",
"homepage": "https://github.com/staltz/ppppp-invite", "homepage": "https://codeberg.org/pzp/pzp-invite",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/staltz/ppppp-invite.git" "url": "git@codeberg.org:pzp/pzp-invite.git"
}, },
"author": "Andre 'Staltz' Medeiros <contact@staltz.com>", "author": "Andre 'Staltz' Medeiros <contact@staltz.com>",
"license": "MIT", "license": "MIT",
@ -30,11 +30,11 @@
"@types/node": "^20.2.5", "@types/node": "^20.2.5",
"c8": "^7.11.0", "c8": "^7.11.0",
"husky": "^4.3.0", "husky": "^4.3.0",
"ppppp-caps": "github:staltz/ppppp-caps", "pzp-caps": "^1.0.0",
"ppppp-hub-client": "github:staltz/ppppp-hub-client", "pzp-hub-client": "^1.0.0",
"ppppp-keypair": "github:staltz/ppppp-keypair", "pzp-keypair": "^1.0.0",
"ppppp-net": "github:staltz/ppppp-net", "pzp-net": "^1.0.0",
"ppppp-promise": "github:staltz/ppppp-promise", "pzp-promise": "^1.0.0",
"prettier": "^2.6.2", "prettier": "^2.6.2",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",

View File

@ -1,11 +1,11 @@
`ppppp://invite` URIs are followed by any number of "commands", where each command has a name plus a fixed-length list of arguments. `pzp://invite` URIs are followed by any number of "commands", where each command has a name plus a fixed-length list of arguments.
## Inviting a new user to the network ## Inviting a new user to the network
**Invite URL:** **Invite URL:**
``` ```
ppppp://invite/join/HOSTFORMAT/HOST/TRANSPORT/PORT/TRANSFORM/CREDENTIALS/follow/ALICE_ID/promise.follow/account.ALICE_ID/ALICE_TOKEN pzp://invite/join/HOSTFORMAT/HOST/TRANSPORT/PORT/TRANSFORM/CREDENTIALS/follow/ALICE_ID/promise.follow/account.ALICE_ID/ALICE_TOKEN
``` ```
made of 3 "commands": made of 3 "commands":
@ -40,9 +40,9 @@ deactivate H
A->>B: Externally: send invite URL A->>B: Externally: send invite URL
B->>H: HTTP: open URL B->>H: HTTP: open URL
activate H activate H
H-->>B: HTML with PPPPP invite URI H-->>B: HTML with PZP invite URI
deactivate H deactivate H
B->>B: open PPPPP app B->>B: open PZP app
note over B: parse URI and detect 3 commands note over B: parse URI and detect 3 commands
note over B: execute command "join" note over B: execute command "join"
B->>H: connect with hubToken in SHSe B->>H: connect with hubToken in SHSe
@ -70,7 +70,7 @@ end
**Invite URL:** **Invite URL:**
``` ```
ppppp://invite/join/HOSTFORMAT/HOST/TRANSPORT/PORT/TRANSFORM/CREDENTIALS/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/peer.PUBKEY/OLD_TOKEN/promise.account-internal-encryption-key/peer.PUBKEY/OLD_TOKEN pzp://invite/join/HOSTFORMAT/HOST/TRANSPORT/PORT/TRANSFORM/CREDENTIALS/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/peer.PUBKEY/OLD_TOKEN/promise.account-internal-encryption-key/peer.PUBKEY/OLD_TOKEN
``` ```
made of 3 "commands": made of 3 "commands":

View File

@ -4,11 +4,11 @@ const Path = require('node:path')
const os = require('node:os') const os = require('node:os')
const p = require('node:util').promisify const p = require('node:util').promisify
const rimraf = require('rimraf') const rimraf = require('rimraf')
const Keypair = require('ppppp-keypair') const Keypair = require('pzp-keypair')
const caps = require('ppppp-caps') const caps = require('pzp-caps')
test('createForFriend()', async (t) => { test('createForFriend()', async (t) => {
const path = Path.join(os.tmpdir(), 'ppppp-promise-createForFriend-0') const path = Path.join(os.tmpdir(), 'pzp-promise-createForFriend-0')
rimraf.sync(path) rimraf.sync(path)
const keypair = Keypair.generate('ed25519', 'alice') const keypair = Keypair.generate('ed25519', 'alice')
@ -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/pubkey.${keypair.public}/MOCK_PROMISE` `pzp://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%2Fpubkey.${keypair.public}%2FMOCK_PROMISE` `https://example.com/invite#pzp%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)

View File

@ -4,11 +4,11 @@ const Path = require('node:path')
const os = require('node:os') const os = require('node:os')
const p = require('node:util').promisify const p = require('node:util').promisify
const rimraf = require('rimraf') const rimraf = require('rimraf')
const Keypair = require('ppppp-keypair') const Keypair = require('pzp-keypair')
const caps = require('ppppp-caps') const caps = require('pzp-caps')
test('createForMyself()', async (t) => { test('createForMyself()', async (t) => {
const path = Path.join(os.tmpdir(), 'ppppp-promise-createForMyself-0') const path = Path.join(os.tmpdir(), 'pzp-promise-createForMyself-0')
rimraf.sync(path) rimraf.sync(path)
const keypair = Keypair.generate('ed25519', 'alice') const keypair = Keypair.generate('ed25519', 'alice')
@ -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/pubkey.${keypair.public}/MOCK_PROMISE` `pzp://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%2Fpubkey.${keypair.public}%2FMOCK_PROMISE` `https://example.com/invite#pzp%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)

View File

@ -7,16 +7,16 @@ test('parse() error cases', (t) => {
plugin.parse('ssb://invite/join/ip4/127.0.0.1/tcp/HUB_PUBKEY/HUB_TOKEN') plugin.parse('ssb://invite/join/ip4/127.0.0.1/tcp/HUB_PUBKEY/HUB_TOKEN')
}) })
assert.throws(() => { assert.throws(() => {
plugin.parse('ppppp:invite') plugin.parse('pzp:invite')
}) })
assert.throws(() => { assert.throws(() => {
plugin.parse('ppppp:invite/join/ip4/127.0.0.1') plugin.parse('pzp:invite/join/ip4/127.0.0.1')
}) })
}) })
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/pubkey.ALICE/ALICE_TOKEN' 'pzp://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/pubkey.PUBKEY/OLD_TOKEN' 'pzp://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, [
{ {
@ -58,7 +58,7 @@ test('parse() good myself invite', (t) => {
test('parse() good tokenless join invite', (t) => { test('parse() good tokenless join invite', (t) => {
const commands = plugin.parse( const commands = plugin.parse(
'ppppp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY' 'pzp://invite/join/dns/example.com/tcp/8080/shse/PUBKEY'
) )
assert.deepEqual(commands, [ assert.deepEqual(commands, [
{ {