UNPKG

factom-identity-lib

Version:

Library to read and update Factom identities

67 lines (57 loc) 1.88 kB
const { getIdentityRootChain, getServerManagementSubchain } = require('./identity-chains'); const cbAddress = require('./coinbase-address'); const eff = require('./efficiency'); async function getIdentity(cli, rootChainId) { const rootChain = await getIdentityRootChain(cli, rootChainId); const managementSubchain = await getServerManagementSubchain( cli, rootChain.serverManagementSubchainId, rootChainId ); const coinbaseAddress = cbAddress.extract( rootChainId, rootChain.entries, rootChain.identityKeys[0] ); const efficiency = eff.extract( rootChainId, managementSubchain.entries, rootChain.identityKeys[0] ); return { rootChainId, serverManagementSubchainId: rootChain.serverManagementSubchainId.toString('hex'), coinbaseAddress, efficiency, identityKeys: rootChain.identityKeys.map(ik => ik.toString('hex')) }; } async function getIdentityHistory(cli, rootChainId) { const rootChain = await getIdentityRootChain(cli, rootChainId); const managementSubchain = await getServerManagementSubchain( cli, rootChain.serverManagementSubchainId, rootChainId ); const coinbaseAddressHistory = cbAddress.extractHistory( rootChainId, rootChain.entries, rootChain.identityKeys[0] ); const efficiencyHistory = eff.extractHistory( rootChainId, managementSubchain.entries, rootChain.identityKeys[0] ); return { rootChainId, serverManagementSubchainId: rootChain.serverManagementSubchainId.toString('hex'), coinbaseAddressHistory, efficiencyHistory, identityKeys: rootChain.identityKeys.map(ik => ik.toString('hex')) }; } module.exports = { getIdentity, getIdentityHistory };