How to use the multihashes.decode function in multihashes

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 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')
      })
github filecoin-project / lotus / lotuspond / front / src / State.js View on Github external
async componentDidMount() {
    const tipset = this.props.tipset || await this.props.client.call("Filecoin.ChainHead", [])
    const actstate = await this.props.client.call('Filecoin.StateReadState', [this.props.actor, tipset.Cids])

    const c = new CID(this.props.actor.Code['/'])
    const mh = multihash.decode(c.multihash)
    let code = mh.digest.toString()

    this.setState({...actstate, code: code})
  }
github validitylabs / hopr / src / js / messageDelivery / handlers.js View on Github external
case 1:
                            header.beta = data
                            state++
                            read(end, next)
                            break
                        case 2:
                            header.gamma = data
                            header = new Header(header.alpha, header.beta, header.gamma).forwardTransform(secretKey)
                            state++
                            read(end, next)
                            break;
                        case 3:
                            const { key, iv } = Header.deriveCipherParameters(header.derived_secret)
                            const plaintext = prp.createPRP(key, iv).inverse(data).toString()

                            const ownhash = multihash.decode(node.peerInfo.id.toBytes()).digest

                            if (ownhash.compare(header.address) === 0) {
                                callback(null, plaintext)
                            } else {
                                forwardMessage(node, header, plaintext)
                            }
                            reply(end, payments.createAckMessage(node.peerInfo.id.toBytes()))
                            break
                        default:
                            throw Error('Error while trying to parse header.')
                    }
                } else {
                    reply(end, null)
                }
            })
        }
github ipfs-shipyard / ipfs-companion / lib / npm / is-ipfs.js View on Github external
function isMultihash(hash) {
  var formatted = convertToString(hash);
  try {
    var buffer = new Buffer(base58.decode(formatted));
    multihash.decode(buffer);
    return true;
  } catch (e) {
    return false;
  }
}

multihashes

multihash implementation

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular multihashes functions