From 9e98e367529e108d144250ee778c26e4ebe24133 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Tue, 18 Jul 2023 23:51:02 +0300 Subject: [PATCH] use db.identity.has --- lib/index.js | 17 +++++++++-------- package.json | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/index.js b/lib/index.js index 753fdb6..f66d873 100644 --- a/lib/index.js +++ b/lib/index.js @@ -180,20 +180,21 @@ module.exports = { cb(new Error('Invalid token')) return } - const promise = /** @type {PPromise} */ (promises.get(token)) - if (promise.type !== 'identity-add') { + const promise = /** @type {IdentityAddPromise} */ (promises.get(token)) + const { type, identity } = promise + if (type !== 'identity-add') { cb(new Error('Invalid token')) return } - // TODO identity.has, and if true, then call cb with false + const keypair = { curve: 'ed25519', public: addition.key.bytes } + if (local.db.identity.has({ identity, keypair })) { + cb(null, false) + return + } local.db.identity.add( - { - identity: promise.identity, - keypair: { curve: 'ed25519', public: addition.key.bytes }, - consent: addition.consent, - }, + { identity, keypair, consent: addition.consent }, /** * @param {Error | null} err * @param {any} rec diff --git a/package.json b/package.json index 10f6108..0262372 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "c8": "^7.11.0", "husky": "^4.3.0", "ppppp-caps": "github:staltz/ppppp-caps", - "ppppp-db": "github:staltz/ppppp-db", + "ppppp-db": "file:../db", "ppppp-keypair": "github:staltz/ppppp-keypair", "prettier": "^2.6.2", "pretty-quick": "^3.1.3",