Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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>
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')
})
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})
}
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)
}
})
}
function isMultihash(hash) {
var formatted = convertToString(hash);
try {
var buffer = new Buffer(base58.decode(formatted));
multihash.decode(buffer);
return true;
} catch (e) {
return false;
}
}