How to use multihashes - 10 common examples

To help you get started, we’ve selected a few multihashes 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 decentralized-identity / sidetree / lib / core / versions / latest / Multihash.ts View on Github external
public static getHashAlgorithmCode (hash: Buffer): number {
    const multihash = multihashes.decode(hash);

    // Hash algorithm must be SHA-256.
    if (multihash.code !== 18) {
      throw new SidetreeError(ErrorCode.MultihashUnsupportedHashAlgorithm);
    }

    return multihash.code;
  }
github filecoin-project / lotus / lotuspond / front / src / Address.js View on Github external
async actorInfo(actor) {
    const c = new CID(actor.Code['/'])
    const mh = multihash.decode(c.multihash) // TODO: check identity

    let method = <span></span>
    if(this.props.method !== undefined &amp;&amp; mh.digest.toString()) {
      method = <span>.{methods[mh.digest.toString()][this.props.method]}</span>
    }

    let info = <span>({mh.digest.toString()}{method})</span>
    switch(mh.digest.toString()) {
      case 'paych':
        const actstate = await this.props.client.call('Filecoin.StateReadState', [actor, this.props.ts || null])
        info = <span>({mh.digest.toString()}{method} to <address>)
    }

    return info
  }
</address></span>
github decentralized-identity / element / packages / element-lib / src / func / func.js View on Github external
const payloadToHash = (payload) => {
  const encodedPayload = encodeJson(payload);
  const encodedOperationPayloadBuffer = Buffer.from(encodedPayload);
  const hash = crypto
    .createHash('sha256')
    .update(encodedOperationPayloadBuffer)
    .digest();
  const hashAlgorithmName = multihashes.codes[18]; // 18 is code for sha256
  const multihash = multihashes.encode(hash, hashAlgorithmName);
  const encodedMultihash = base64url.encode(multihash);
  return encodedMultihash;
};
github decentralized-identity / element / packages / element-lib / src / func / index.js View on Github external
const payloadToHash = (payload) => {
  const encodedPayload = encodeJson(payload);
  const encodedOperationPayloadBuffer = Buffer.from(encodedPayload);
  const hash = crypto
    .createHash('sha256')
    .update(encodedOperationPayloadBuffer)
    .digest();
  const hashAlgorithmName = multihashes.codes[18]; // 18 is code for sha256
  const multihash = multihashes.encode(hash, hashAlgorithmName);
  const encodedMultihash = base64url.encode(multihash);
  return encodedMultihash;
};
github ipld / js-ipld-ethereum / util / cidFromHash.js View on Github external
function cidFromHash (codec, rawhash, options) {
  // `CID` expects a string for the multicodec
  const codecName = multicodec.print[codec]
  options = options || {}
  const hashAlg = options.hashAlg || 'keccak-256'
  const version = typeof options.version === 'undefined' ? 1 : options.version
  const multihash = multihashes.encode(rawhash, hashAlg)
  return new CID(version, codecName, multihash)
}
github ipld / js-ipld-dag-cbor / test / util.spec.js View on Github external
it('.cid', async () => {
    const cid = await dagCBOR.util.cid(serializedObj)
    expect(cid.version).to.equal(1)
    expect(cid.codec).to.equal('dag-cbor')
    expect(cid.multihash).to.exist()
    const mh = multihash.decode(cid.multihash)
    expect(mh.name).to.equal('sha2-256')
  })
github ipld / js-ipld / test / ipld-bitcoin.js View on Github external
it('resolver.put with format', async () => {
        const cid = await resolver.put(node1, multicodec.BITCOIN_BLOCK)
        expect(cid.version).to.equal(1)
        expect(cid.codec).to.equal('bitcoin-block')
        expect(cid.multihash).to.exist()
        const mh = multihash.decode(cid.multihash)
        expect(mh.name).to.equal('dbl-sha2-256')
      })
github ipld / js-ipld / test / ipld-eth-block.js View on Github external
it('resolver.put with format', async () => {
        const cid = await resolver.put(node1, multicodec.ETH_BLOCK)
        expect(cid.version).to.equal(1)
        expect(cid.codec).to.equal('eth-block')
        expect(cid.multihash).to.exist()
        const mh = multihash.decode(cid.multihash)
        expect(mh.name).to.equal('keccak-256')
      })
github ipld / js-ipld / test / ipld-dag-pb.js View on Github external
it('resolver.put with format', async () => {
        const cid = await resolver.put(node1, multicodec.DAG_PB)
        expect(cid.version).to.equal(1)
        expect(cid.codec).to.equal('dag-pb')
        expect(cid.multihash).to.exist()
        const mh = multihash.decode(cid.multihash)
        expect(mh.name).to.equal('sha2-256')
      })
github ipld / js-ipld / test / ipld-git.js View on Github external
it('resolver.put with format', async () => {
        const cid = await resolver.put(blobNode, multicodec.GIT_RAW)
        expect(cid.version).to.equal(1)
        expect(cid.codec).to.equal('git-raw')
        expect(cid.multihash).to.exist()
        const mh = multihash.decode(cid.multihash)
        expect(mh.name).to.equal('sha1')
      })

multihashes

multihash implementation

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular multihashes functions