mirror of https://codeberg.org/pzp/pzp-promise.git
use db.identity.has
This commit is contained in:
parent
d70d119e7c
commit
9e98e36752
17
lib/index.js
17
lib/index.js
|
@ -180,20 +180,21 @@ module.exports = {
|
||||||
cb(new Error('Invalid token'))
|
cb(new Error('Invalid token'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const promise = /** @type {PPromise} */ (promises.get(token))
|
const promise = /** @type {IdentityAddPromise} */ (promises.get(token))
|
||||||
if (promise.type !== 'identity-add') {
|
const { type, identity } = promise
|
||||||
|
if (type !== 'identity-add') {
|
||||||
cb(new Error('Invalid token'))
|
cb(new Error('Invalid token'))
|
||||||
return
|
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(
|
local.db.identity.add(
|
||||||
{
|
{ identity, keypair, consent: addition.consent },
|
||||||
identity: promise.identity,
|
|
||||||
keypair: { curve: 'ed25519', public: addition.key.bytes },
|
|
||||||
consent: addition.consent,
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* @param {Error | null} err
|
* @param {Error | null} err
|
||||||
* @param {any} rec
|
* @param {any} rec
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"c8": "^7.11.0",
|
"c8": "^7.11.0",
|
||||||
"husky": "^4.3.0",
|
"husky": "^4.3.0",
|
||||||
"ppppp-caps": "github:staltz/ppppp-caps",
|
"ppppp-caps": "github:staltz/ppppp-caps",
|
||||||
"ppppp-db": "github:staltz/ppppp-db",
|
"ppppp-db": "file:../db",
|
||||||
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
|
|
Loading…
Reference in New Issue