繁体   English   中英

如何授予令牌客户访问不在区块链上的一堆文件的权限? (复仇)

[英]How can I give Token-Customers access to a bunch of files that are not on the Blockchain? (Ethereum)

最初,我只是想让他们看到Google云端硬盘链接,但这必须保持不变,这样客户就可以将链接彼此发送,即使人们必须使用智能合约来获得它。

您可以使用https://ipfs.io (分布式文件存储)和以太坊DApp解决此问题。 考虑到您提到要要求人们使用智能合约来访问文件,我想您需要在存储在IPFS上之前对文件进行加密。 因为IPFS是分布式的,所以只要知道文件存在,任何人都可以获取该文件,但是只有有权访问私钥的人才能读取该文件。

满足智能合约的条件后,您可以释放密钥。 由于以太坊智能合约无法进行实际的解密,因此您的web3应用程序需要执行此部分。

例如,在文件存储在IPFS之后的web3应用程序中:

addNewFile: function() {
    // encrypt the file
    var encryptedFile = CryptoJS.AES.encrypt(fileData, passPhrase);
    // store on the IPFS
    ipfs.files.write( ... => {
        // make sure it worked
        ...
        // (fileName is an IPFS-generated hash uniquely identifying the (encrypted) file
        // write it to the contract
        deployedFileContract.AddFileEntry(fileLocation, fileName, passPhrase, function(error) {
            // respond to error condition
        });
    });
};

retrieveEncyptedFile: function() { 
    ...
    deployedFileContract.RetrieveFileEntry.call(_pointer-to-file_, function(error, result) {
        // fetch an encrypted file as a readable stream from IPFS

        // decrypt it and probably do something funky with mime types to make sure it gets saved
        var decryptedFile =  CryptoJS.AES.decrypt(encryptedFileStream, passPhrase). ...

    });
...
};

所有这些都需要您的Solidity智能合约和一个web3应用程序。 您可以在浏览器中运行IPFS js客户端https://github.com/ipfs/js-ipfs ,或通过Nodejs或Go访问它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM