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 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 },