tiny refactor around msgv3.createIdentity()

This commit is contained in:
Andre Staltz 2023-06-25 20:50:02 +03:00
parent df98d499f1
commit a442a26c2a
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 5 additions and 5 deletions

View File

@ -178,17 +178,17 @@ function createRoot(id, domain, keypair) {
return msg
}
function getRandomNonce() {
return base58.encode(crypto.randomBytes(32))
}
/**
* @param {Keypair} keypair
* @param {string} domain
* @param {string | (() => string)} nonce
* @returns {Msg}
*/
function createIdentity(
keypair,
domain,
nonce = () => base58.encode(crypto.randomBytes(32))
) {
function createIdentity(keypair, domain, nonce = getRandomNonce) {
const actualNonce = typeof nonce === 'function' ? nonce() : nonce
return create({
data: { add: keypair.public, nonce: actualNonce },