实现chainpoint v2存在性证明方法
blockchain-proofs的Python项目详细描述
生成和验证块链证明/收据(用于证明存在)的实现。目前它只支持chainpoint v2(<;http://www.chainpoint.org/>;),但它可以很容易地扩展。
请注意,它还验证merkleroot是否正确存储在区块链(testnet或mainnet)中。
将来,库可能会合并其他方法,如opentimestamp(<;https://github.com/opentimestamps>;)
安装
$ pip install blockchain-proofs
示例用法
$ python
>>> from blockchain_proofs import ChainPointV2 >>> leafs = ['a', 'b', 'c'] >>> cp = ChainPointV2() >>> cp.add_leaf(leafs, True) >>> cp.make_tree() >>> cp.get_leaf_count() 3 >>> cp.get_merkle_root() '7075152d03a5cd92104887b476862778ec0c87be5c2fa1c0a90f87c49fad6eff' >>> cp.get_receipt(0, "e8b4177a30c8af5dd5f33adbc530e8970b593af1001b322c289e60b4ce395e13") {'type': 'ChainpointSHA256v2', 'targetHash': 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', 'anchors': [{'type': 'BTCOpReturn', 'sourceId': 'e8b4177a30c8af5dd5f33adbc530e8970b593af1001b322c289e60b4ce395e13'}], 'proof': [{'right': '3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d'}, {'right': '2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6'}], '@context': 'https://w3id.org/chainpoint/v2', 'merkleRoot': '7075152d03a5cd92104887b476862778ec0c87be5c2fa1c0a90f87c49fad6eff'}