From 85201f07d9600bf70f6d4a27477b7293c1bfc64b Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 10 Aug 2023 10:54:15 +0300 Subject: [PATCH] rename identity to account --- lib/index.js | 40 ++++++++++++++++++------------------ package.json | 8 +++++--- test/createForFriend.test.js | 4 ++-- test/createForMyself.test.js | 6 +++--- test/parse.test.js | 8 ++++---- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0b81b43..8876009 100644 --- a/lib/index.js +++ b/lib/index.js @@ -35,21 +35,21 @@ const p = require('promisify-tuple') * token: string, * }} PromiseFollowCommand * - * @typedef {`promise.follow/identity.${string}/${string}`} PromiseFollowCommandStr + * @typedef {`promise.follow/account.${string}/${string}`} PromiseFollowCommandStr * * @typedef {{ - * type: 'promise.identity-add', + * type: 'promise.account-add', * issuerID: string, * token: string, - * }} PromiseIdentityAddCommand + * }} PromiseAccountAddCommand * - * @typedef {`promise.identity-add/identity.${string}/${string}`} PromiseIdentityAddCommandStr + * @typedef {`promise.account-add/account.${string}/${string}`} PromiseAccountAddCommandStr * * @typedef {| JoinCommand * | FollowCommand * | TunnelConnectCommand * | PromiseFollowCommand - * | PromiseIdentityAddCommand + * | PromiseAccountAddCommand * } Command */ @@ -148,7 +148,7 @@ function parsePromiseFollowCommand(pieces, uri) { pieces.shift() pieces.shift() const [issuerType, issuerID] = issuerAndType.split('.') - if (issuerType !== 'identity') { + if (issuerType !== 'account') { // prettier-ignore 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} pieces * @param {string} uri - * @returns {PromiseIdentityAddCommand} + * @returns {PromiseAccountAddCommand} */ -function parsePromiseIdentityAddCommand(pieces, uri) { +function parsePromiseAccountAddCommand(pieces, uri) { const [, issuerAndType, token] = pieces if (!issuerAndType) { // 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) { // 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() const [issuerType, issuerID] = issuerAndType.split('.') - if (issuerType !== 'identity') { + if (issuerType !== 'account') { // 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': commands.push(parsePromiseFollowCommand(pieces, uri)) break - case 'promise.identity-add': - commands.push(parsePromiseIdentityAddCommand(pieces, uri)) + case 'promise.account-add': + commands.push(parsePromiseAccountAddCommand(pieces, uri)) break default: throw new Error(`Unknown command: "${pieces[0]}"`) @@ -306,7 +306,7 @@ module.exports = { /** @type {FollowCommandStr} */ const followCommand = `follow/${opts.id}` /** @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 url = `http://${host}/invite#${encodeURIComponent(uri)}` @@ -361,8 +361,8 @@ module.exports = { if (shse.name !== 'shse') return cb(new Error(ERROR_MSG)) const [pubkey] = shse.data - // Create identity-add promise - const promise = { type: 'identity-add', identity: opts.id } + // Create account-add promise + const promise = { type: 'account-add', account: opts.id } const [err3, token] = await p(local.promise.create)(promise) if (err3) return cb(err3) @@ -370,8 +370,8 @@ module.exports = { const joinCommand = `join/${host}/${port}/${pubkey}/${hubToken}` /** @type {TunnelConnectCommandStr} */ const tunnelCommand = `tunnel-connect/${pubkey}/${local.shse.pubkey}` - /** @type {PromiseIdentityAddCommandStr} */ - const promiseCommand = `promise.identity-add/identity.${opts.id}/${token}` + /** @type {PromiseAccountAddCommandStr} */ + const promiseCommand = `promise.account-add/account.${opts.id}/${token}` const uri = `ppppp://invite/${joinCommand}/${tunnelCommand}/${promiseCommand}` const url = `http://${host}/invite#${encodeURIComponent(uri)}` cb(null, { uri, url }) diff --git a/package.json b/package.json index daa3eb8..aa3f101 100644 --- a/package.json +++ b/package.json @@ -37,12 +37,14 @@ "pretty-quick": "^3.1.3", "rimraf": "^5.0.1", "secret-handshake-ext": "0.0.8", - "secret-stack": "ssbc/secret-stack#bare-mode", + "secret-stack": "~7.1.0", "typescript": "^5.0.2" }, "scripts": { - "build": "tsc", - "test": "node --test", + "clean-check": "tsc --build --clean", + "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-staged": "pretty-quick --staged --pattern \"(test|lib)/**/*.js\"", "coverage": "c8 --reporter=lcov npm run test" diff --git a/test/createForFriend.test.js b/test/createForFriend.test.js index 22e3f77..2c5f40e 100644 --- a/test/createForFriend.test.js +++ b/test/createForFriend.test.js @@ -78,11 +78,11 @@ test('createForFriend()', async (t) => { }) assert.equal( 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( 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) diff --git a/test/createForMyself.test.js b/test/createForMyself.test.js index 1df6a45..658ba33 100644 --- a/test/createForMyself.test.js +++ b/test/createForMyself.test.js @@ -49,7 +49,7 @@ test('createForMyself()', async (t) => { return { create(opts, cb) { createPromiseCalled = true - assert.deepEqual(opts, { type: 'identity-add', identity: 'MOCK_ID' }) + assert.deepEqual(opts, { type: 'account-add', account: 'MOCK_ID' }) cb(null, 'MOCK_PROMISE') }, } @@ -78,11 +78,11 @@ test('createForMyself()', async (t) => { }) assert.equal( 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( 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) diff --git a/test/parse.test.js b/test/parse.test.js index c3656cc..ecf49be 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -16,7 +16,7 @@ test('parse() error cases', (t) => { test('parse() good friend invite', (t) => { 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, [ { @@ -37,7 +37,7 @@ test('parse() good friend invite', (t) => { test('parse() good myself invite', (t) => { 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, [ { @@ -49,8 +49,8 @@ test('parse() good myself invite', (t) => { address: 'tunnel:HUB_PUBKEY:OLD_PUBKEY~shse:OLD_PUBKEY', }, { - type: 'promise.identity-add', - issuerID: 'IDENTITY_ID', + type: 'promise.account-add', + issuerID: 'ACCOUNT_ID', token: 'OLD_TOKEN', }, ])