Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'multihashes' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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;
}
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 && 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>
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;
};
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;
};
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)
}
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')
})
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')
})
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')
})
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')
})
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')
})