UNPKG

jsonld-signatures-merkleproof2019

Version:

A jsonld signature implementation to support MerkleProof2019 verification in Verifiable Credential context

39 lines (38 loc) 1.47 kB
import { BLOCKCHAINS } from '@blockcerts/explorer-lookup'; import { capitalize } from '../utils/string.js'; // merkleRoot2019: see https://w3c-dvcg.github.io/lds-merkle-proof-2019/#blockchain-keymap function getMerkleRoot2019Chain(anchor) { const dataArray = anchor.split(':'); let mainChain; switch (dataArray[1]) { case BLOCKCHAINS.mocknet.blinkCode: return getChainObject(BLOCKCHAINS.mocknet.signatureValue); case BLOCKCHAINS.bitcoin.blinkCode: mainChain = BLOCKCHAINS.bitcoin.name; break; case BLOCKCHAINS.ethmain.blinkCode: mainChain = BLOCKCHAINS.ethmain.name; break; default: throw new Error('Could not retrieve chain.'); } const network = dataArray[2]; const chainCodeSignatureValue = mainChain.toLowerCase() + capitalize(network); return getChainObject(chainCodeSignatureValue); } function getChainObject(chainCodeProofValue) { const chainObject = Object.keys(BLOCKCHAINS) .map(key => BLOCKCHAINS[key]) .find((entry) => entry.signatureValue === chainCodeProofValue); return chainObject; } export default function getChain(proof = null) { if (proof === null || proof === void 0 ? void 0 : proof.anchors) { const { anchors } = proof; const anchor = anchors[0]; if (typeof anchor === 'string') { return getMerkleRoot2019Chain(anchor); } } return null; }