verifyIPFS – 验证IPFS区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,verifyIPFS – 验证IPFS区块链毕设代写 是一篇很好的国外资料

verifyIPFS

Smart contract library functions for recreating the hash of an ipfs object given its content.

Usage

Add the data file to IPFS:

ipfs add testfile -q 

Will return:

QmRsjnNkEpnDdmYB7wMR7FSy1eGZ12pDuhST3iNLJTzAXF 

Now try the same thing with the generateHash-function:

(truffle console)

truffle(default)> fs = require('fs') truffle(default)> var verify; verifyIPFS.new().then(a => {verify = a}) truffle(default)> var testfile = fs.readFileSync('./testfile').toString() truffle(default)> verify.generateHash(testfile).then(a => {console.log(web3.toAscii(a))}) 

returns

QmRsjnNkEpnDdmYB7wMR7FSy1eGZ12pDuhST3iNLJTzAXF 

Functions:

generateHash returns the IPFS-hash in byte format of a given string:

function generateHash(string contentString) constant returns (bytes) 

verifyHash takes a string and an IPFS-hash, and returns true if they match:

function verifyHash(string contentString, string hash) constant returns (bool) { 

toBase58 converts bytes from hex format to base58:

function toBase58(bytes source) constant returns (bytes) { 

Limitations:

Does not work for IPFS objects that are in several chunks. Contact me if you find an IPFS object in one chunk that does not work.

Why this is useful:

This allows you to store large data files on the blockchain by their IPFS hash instead of directly in contract storage. If you at a later point need any part of the data on the blockchain, you can submit it with a transaction, validate it cryptographically using this contract and then do your computations only referring to the contents of the IPFS object in memory!

License

See full MIT License including:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

验证IPFS

智能合约库函数,用于根据ipfs对象的内容重新创建其哈希

使用

将数据文件添加到IPFS:

ipfs add testfile -q 

将返回:

QmRsjnNkEpnDdmYB7wMR7FSy1eGZ12pDuhST3iNLJTzAXF 

现在尝试使用generateHash函数执行相同的操作:

(块菌控制台)

truffle(default)> fs = require('fs') truffle(default)> var verify; verifyIPFS.new().then(a => {verify = a}) truffle(default)> var testfile = fs.readFileSync('./testfile').toString() truffle(default)> verify.generateHash(testfile).then(a => {console.log(web3.toAscii(a))}) 

返回

QmRsjnNkEpnDdmYB7wMR7FSy1eGZ12pDuhST3iNLJTzAXF 

功能:

generateHash以给定字符串的字节格式返回IPFS哈希:

function generateHash(string contentString) constant returns (bytes) 

验证哈希接受字符串和IPFS哈希,如果匹配,则返回true:

function verifyHash(string contentString, string hash) constant returns (bool) { 

toBase58将字节从十六进制格式转换为base58:

function toBase58(bytes source) constant returns (bytes) { 

限制:

不适用于多个块中的IPFS对象。如果在一个块中发现IPFS对象不起作用,请与我联系

为什么有用:

这允许您通过IPFS散列将大型数据文件存储在区块链blockchain上,而不是直接存储在契约存储中。如果您以后需要区块链blockchain上的任何部分数据,您可以将其与交易一起提交,使用此合约以加密方式验证,然后仅参考内存中IPFS对象的内容进行计算

许可证

请参阅完整的MIT许可证,包括:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/23816.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » verifyIPFS – 验证IPFS区块链毕设代写

提供最优质的资源集合

立即查看 了解详情