use db.identity.has

This commit is contained in:
Andre Staltz 2023-07-18 23:51:02 +03:00
parent d70d119e7c
commit 9e98e36752
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 10 additions and 9 deletions

View File

@ -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

View File

@ -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",