UNPKG

jsonld-signatures-merkleproof2019

Version:

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

17 lines (16 loc) 895 B
import * as bitcoin from 'bitcoinjs-lib'; import * as secp256k1 from '@noble/secp256k1'; import { keccak256 } from '@ethersproject/keccak256'; import { Buffer as BufferPolyfill } from 'buffer'; export function computeBitcoinAddressFromPublicKey(publicKey, chain) { return bitcoin.payments.p2pkh({ pubkey: publicKey, network: bitcoin.networks[chain.code] }).address; } export function computeEthereumAddressFromPublicKey(publicKey, chain) { const buffer = typeof Buffer === 'undefined' ? BufferPolyfill : Buffer; const publicKeyString = publicKey.toString('hex'); // Convert to uncompressed format const publicKeyUncompressed = buffer.from(secp256k1.Point.fromHex(publicKeyString).toBytes(false)).toString('hex').slice(2); // Now apply keccak const address = keccak256(buffer.from(publicKeyUncompressed, 'hex')).slice(64 - 38); return `0x${address.toString()}`; }