rename identity to account

This commit is contained in:
Andre Staltz 2023-08-10 10:54:15 +03:00
parent 2c753a76a8
commit 85201f07d9
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
5 changed files with 34 additions and 32 deletions

View File

@ -35,21 +35,21 @@ const p = require('promisify-tuple')
* token: string, * token: string,
* }} PromiseFollowCommand * }} PromiseFollowCommand
* *
* @typedef {`promise.follow/identity.${string}/${string}`} PromiseFollowCommandStr * @typedef {`promise.follow/account.${string}/${string}`} PromiseFollowCommandStr
* *
* @typedef {{ * @typedef {{
* type: 'promise.identity-add', * type: 'promise.account-add',
* issuerID: string, * issuerID: string,
* token: string, * token: string,
* }} PromiseIdentityAddCommand * }} PromiseAccountAddCommand
* *
* @typedef {`promise.identity-add/identity.${string}/${string}`} PromiseIdentityAddCommandStr * @typedef {`promise.account-add/account.${string}/${string}`} PromiseAccountAddCommandStr
* *
* @typedef {| JoinCommand * @typedef {| JoinCommand
* | FollowCommand * | FollowCommand
* | TunnelConnectCommand * | TunnelConnectCommand
* | PromiseFollowCommand * | PromiseFollowCommand
* | PromiseIdentityAddCommand * | PromiseAccountAddCommand
* } Command * } Command
*/ */
@ -148,7 +148,7 @@ function parsePromiseFollowCommand(pieces, uri) {
pieces.shift() pieces.shift()
pieces.shift() pieces.shift()
const [issuerType, issuerID] = issuerAndType.split('.') const [issuerType, issuerID] = issuerAndType.split('.')
if (issuerType !== 'identity') { if (issuerType !== 'account') {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, invalid promise.follow issuer type "${issuerType}"`) throw new Error(`Invalid URI "${uri}" for invite.parse, invalid promise.follow issuer type "${issuerType}"`)
} }
@ -158,27 +158,27 @@ function parsePromiseFollowCommand(pieces, uri) {
/** /**
* @param {Array<string>} pieces * @param {Array<string>} pieces
* @param {string} uri * @param {string} uri
* @returns {PromiseIdentityAddCommand} * @returns {PromiseAccountAddCommand}
*/ */
function parsePromiseIdentityAddCommand(pieces, uri) { function parsePromiseAccountAddCommand(pieces, uri) {
const [, issuerAndType, token] = pieces const [, issuerAndType, token] = pieces
if (!issuerAndType) { if (!issuerAndType) {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.identity-add issuer`) throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.account-add issuer`)
} }
if (!token) { if (!token) {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, missing promise.identity-add token`) 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()
const [issuerType, issuerID] = issuerAndType.split('.') const [issuerType, issuerID] = issuerAndType.split('.')
if (issuerType !== 'identity') { if (issuerType !== 'account') {
// prettier-ignore // prettier-ignore
throw new Error(`Invalid URI "${uri}" for invite.parse, invalid promise.identity-add issuer type "${issuerType}"`) throw new Error(`Invalid URI "${uri}" for invite.parse, invalid promise.account-add issuer type "${issuerType}"`)
} }
return { type: 'promise.identity-add', issuerID, token } return { type: 'promise.account-add', issuerID, token }
} }
/** /**
@ -216,8 +216,8 @@ function parse(uri) {
case 'promise.follow': case 'promise.follow':
commands.push(parsePromiseFollowCommand(pieces, uri)) commands.push(parsePromiseFollowCommand(pieces, uri))
break break
case 'promise.identity-add': case 'promise.account-add':
commands.push(parsePromiseIdentityAddCommand(pieces, uri)) commands.push(parsePromiseAccountAddCommand(pieces, uri))
break break
default: default:
throw new Error(`Unknown command: "${pieces[0]}"`) throw new Error(`Unknown command: "${pieces[0]}"`)
@ -306,7 +306,7 @@ module.exports = {
/** @type {FollowCommandStr} */ /** @type {FollowCommandStr} */
const followCommand = `follow/${opts.id}` const followCommand = `follow/${opts.id}`
/** @type {PromiseFollowCommandStr} */ /** @type {PromiseFollowCommandStr} */
const promiseCommand = `promise.follow/identity.${opts.id}/${token}` const promiseCommand = `promise.follow/account.${opts.id}/${token}`
const uri = `ppppp://invite/${joinCommand}/${followCommand}/${promiseCommand}` const uri = `ppppp://invite/${joinCommand}/${followCommand}/${promiseCommand}`
const url = `http://${host}/invite#${encodeURIComponent(uri)}` const url = `http://${host}/invite#${encodeURIComponent(uri)}`
@ -361,8 +361,8 @@ module.exports = {
if (shse.name !== 'shse') return cb(new Error(ERROR_MSG)) if (shse.name !== 'shse') return cb(new Error(ERROR_MSG))
const [pubkey] = shse.data const [pubkey] = shse.data
// Create identity-add promise // Create account-add promise
const promise = { type: 'identity-add', identity: opts.id } const promise = { type: 'account-add', account: opts.id }
const [err3, token] = await p(local.promise.create)(promise) const [err3, token] = await p(local.promise.create)(promise)
if (err3) return cb(err3) if (err3) return cb(err3)
@ -370,8 +370,8 @@ module.exports = {
const joinCommand = `join/${host}/${port}/${pubkey}/${hubToken}` const joinCommand = `join/${host}/${port}/${pubkey}/${hubToken}`
/** @type {TunnelConnectCommandStr} */ /** @type {TunnelConnectCommandStr} */
const tunnelCommand = `tunnel-connect/${pubkey}/${local.shse.pubkey}` const tunnelCommand = `tunnel-connect/${pubkey}/${local.shse.pubkey}`
/** @type {PromiseIdentityAddCommandStr} */ /** @type {PromiseAccountAddCommandStr} */
const promiseCommand = `promise.identity-add/identity.${opts.id}/${token}` const promiseCommand = `promise.account-add/account.${opts.id}/${token}`
const uri = `ppppp://invite/${joinCommand}/${tunnelCommand}/${promiseCommand}` const uri = `ppppp://invite/${joinCommand}/${tunnelCommand}/${promiseCommand}`
const url = `http://${host}/invite#${encodeURIComponent(uri)}` const url = `http://${host}/invite#${encodeURIComponent(uri)}`
cb(null, { uri, url }) cb(null, { uri, url })

View File

@ -37,12 +37,14 @@
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"secret-handshake-ext": "0.0.8", "secret-handshake-ext": "0.0.8",
"secret-stack": "ssbc/secret-stack#bare-mode", "secret-stack": "~7.1.0",
"typescript": "^5.0.2" "typescript": "^5.0.2"
}, },
"scripts": { "scripts": {
"build": "tsc", "clean-check": "tsc --build --clean",
"test": "node --test", "prepublishOnly": "npm run clean-check && tsc --build",
"postpublish": "npm run clean-check",
"test": "npm run clean-check && node --test",
"format-code": "prettier --write \"(test|lib)/**/*.js\"", "format-code": "prettier --write \"(test|lib)/**/*.js\"",
"format-code-staged": "pretty-quick --staged --pattern \"(test|lib)/**/*.js\"", "format-code-staged": "pretty-quick --staged --pattern \"(test|lib)/**/*.js\"",
"coverage": "c8 --reporter=lcov npm run test" "coverage": "c8 --reporter=lcov npm run test"

View File

@ -78,11 +78,11 @@ test('createForFriend()', async (t) => {
}) })
assert.equal( assert.equal(
uri, uri,
`ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/follow/MOCK_ID/promise.follow/identity.MOCK_ID/MOCK_PROMISE` `ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/follow/MOCK_ID/promise.follow/account.MOCK_ID/MOCK_PROMISE`
) )
assert.equal( assert.equal(
url, url,
`http://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fexample.com%2F8008%2FHUB_PUBKEY%2FMOCK_TOKEN%2Ffollow%2FMOCK_ID%2Fpromise.follow%2Fidentity.MOCK_ID%2FMOCK_PROMISE` `http://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fexample.com%2F8008%2FHUB_PUBKEY%2FMOCK_TOKEN%2Ffollow%2FMOCK_ID%2Fpromise.follow%2Faccount.MOCK_ID%2FMOCK_PROMISE`
) )
assert.ok(connectCalled) assert.ok(connectCalled)

View File

@ -49,7 +49,7 @@ test('createForMyself()', async (t) => {
return { return {
create(opts, cb) { create(opts, cb) {
createPromiseCalled = true createPromiseCalled = true
assert.deepEqual(opts, { type: 'identity-add', identity: 'MOCK_ID' }) assert.deepEqual(opts, { type: 'account-add', account: 'MOCK_ID' })
cb(null, 'MOCK_PROMISE') cb(null, 'MOCK_PROMISE')
}, },
} }
@ -78,11 +78,11 @@ test('createForMyself()', async (t) => {
}) })
assert.equal( assert.equal(
uri, uri,
`ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/tunnel-connect/HUB_PUBKEY/${local.shse.pubkey}/promise.identity-add/identity.MOCK_ID/MOCK_PROMISE` `ppppp://invite/join/example.com/8008/HUB_PUBKEY/MOCK_TOKEN/tunnel-connect/HUB_PUBKEY/${local.shse.pubkey}/promise.account-add/account.MOCK_ID/MOCK_PROMISE`
) )
assert.equal( assert.equal(
url, url,
`http://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fexample.com%2F8008%2FHUB_PUBKEY%2FMOCK_TOKEN%2Ftunnel-connect%2FHUB_PUBKEY%2F${local.shse.pubkey}%2Fpromise.identity-add%2Fidentity.MOCK_ID%2FMOCK_PROMISE` `http://example.com/invite#ppppp%3A%2F%2Finvite%2Fjoin%2Fexample.com%2F8008%2FHUB_PUBKEY%2FMOCK_TOKEN%2Ftunnel-connect%2FHUB_PUBKEY%2F${local.shse.pubkey}%2Fpromise.account-add%2Faccount.MOCK_ID%2FMOCK_PROMISE`
) )
assert.ok(connectCalled) assert.ok(connectCalled)

View File

@ -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/HOST/PORT/PUBKEY/TOKEN/follow/ALICE/promise.follow/identity.ALICE/ALICE_TOKEN' 'ppppp://invite/join/HOST/PORT/PUBKEY/TOKEN/follow/ALICE/promise.follow/account.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/HOST/PORT/PUBKEY/TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.identity-add/identity.IDENTITY_ID/OLD_TOKEN' 'ppppp://invite/join/HOST/PORT/PUBKEY/TOKEN/tunnel-connect/HUB_PUBKEY/OLD_PUBKEY/promise.account-add/account.ACCOUNT_ID/OLD_TOKEN'
) )
assert.deepEqual(commands, [ assert.deepEqual(commands, [
{ {
@ -49,8 +49,8 @@ test('parse() good myself invite', (t) => {
address: 'tunnel:HUB_PUBKEY:OLD_PUBKEY~shse:OLD_PUBKEY', address: 'tunnel:HUB_PUBKEY:OLD_PUBKEY~shse:OLD_PUBKEY',
}, },
{ {
type: 'promise.identity-add', type: 'promise.account-add',
issuerID: 'IDENTITY_ID', issuerID: 'ACCOUNT_ID',
token: 'OLD_TOKEN', token: 'OLD_TOKEN',
}, },
]) ])