How to use the libp2p-crypto.keys.unmarshalPublicKey function in libp2p-crypto

To help you get started, we’ve selected a few libp2p-crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudflare / ipfs-ext / src / verify.js View on Github external
async ipnsPublicKey(peer, parsed) {
    let raw = peer.toBytes()

    // Check if the public key is just embedded in the peer ID.
    if (raw.length > 1 && raw[0] == 0x00) {
      return keys.unmarshalPublicKey(raw)
    }

    // Extract the public key from the IPNS record.
    return crypto.subtle.digest("SHA-256", parsed.pubKey).then((digest) => {
      let mh = multihash.encode(Buffer.from(digest), "sha2-256")
      if (!raw.equals(mh)) {
        throw new Error("given unexpected public key")
      }
      return keys.unmarshalPublicKey(parsed.pubKey)
    })
  }
github validitylabs / hopr / src / utils / index.js View on Github external
module.exports.addPubKey = async peerId => {
    if (PeerId.isPeerId(peerId) && peerId.pubKey) return peerId

    peerId.pubKey = await libp2p_crypto.unmarshalPublicKey(Multihash.decode(peerId.toBytes()).digest)

    return peerId
}
github validitylabs / hopr / src / utils / index.js View on Github external
serializedPeerInfos.map(async serializedPeerInfo => {
            const peerId = PeerId.createFromBytes(serializedPeerInfo[0])

            if (serializedPeerInfo.length === 3) {
                peerId.pubKey = libp2p_crypto.unmarshalPublicKey(serializedPeerInfo[2])
            }

            const peerInfo = await PeerInfo.create(peerId)
            serializedPeerInfo[1].forEach(multiaddr => peerInfo.multiaddrs.add(Multiaddr(multiaddr)))
            peerBook.put(peerInfo)
        })
    )
github cloudflare / ipfs-ext / src / verify.js View on Github external
return crypto.subtle.digest("SHA-256", parsed.pubKey).then((digest) => {
      let mh = multihash.encode(Buffer.from(digest), "sha2-256")
      if (!raw.equals(mh)) {
        throw new Error("given unexpected public key")
      }
      return keys.unmarshalPublicKey(parsed.pubKey)
    })
  }