-
Notifications
You must be signed in to change notification settings - Fork 0
/
key-path.js
30 lines (25 loc) · 771 Bytes
/
key-path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { resolve } = require('path')
const crypto = require('ara-crypto')
const rc = require('./rc')()
/**
* Generate path to stored local identity
* @param {Object} identity
* @return {String}
* @throws {TypeError}
*/
function createIdentityKeyPath(identity) {
if (null == identity || 'object' !== typeof identity) {
throw new TypeError('util.createIdentityKeyPath: Expecting identity object')
}
const { root } = rc.network.identity
let { publicKey } = identity
if (Array.isArray(publicKey) && 0 < publicKey.length) {
const { publicKeyHex } = publicKey[0]
publicKey = Buffer.from(publicKeyHex, 'hex')
}
const hash = crypto.blake2b(publicKey).toString('hex')
return resolve(root, hash)
}
module.exports = {
createIdentityKeyPath
}