mirror of https://codeberg.org/pzp/pzp-db.git
tiny refactor around msgv3.createIdentity()
This commit is contained in:
parent
df98d499f1
commit
a442a26c2a
|
@ -178,17 +178,17 @@ function createRoot(id, domain, keypair) {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRandomNonce() {
|
||||||
|
return base58.encode(crypto.randomBytes(32))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Keypair} keypair
|
* @param {Keypair} keypair
|
||||||
* @param {string} domain
|
* @param {string} domain
|
||||||
* @param {string | (() => string)} nonce
|
* @param {string | (() => string)} nonce
|
||||||
* @returns {Msg}
|
* @returns {Msg}
|
||||||
*/
|
*/
|
||||||
function createIdentity(
|
function createIdentity(keypair, domain, nonce = getRandomNonce) {
|
||||||
keypair,
|
|
||||||
domain,
|
|
||||||
nonce = () => base58.encode(crypto.randomBytes(32))
|
|
||||||
) {
|
|
||||||
const actualNonce = typeof nonce === 'function' ? nonce() : nonce
|
const actualNonce = typeof nonce === 'function' ? nonce() : nonce
|
||||||
return create({
|
return create({
|
||||||
data: { add: keypair.public, nonce: actualNonce },
|
data: { add: keypair.public, nonce: actualNonce },
|
||||||
|
|
Loading…
Reference in New Issue