@0xcert/cert 中文文档教程
Asset Certification Module
数据互操作性和保证
Purpose
这是 0xcert 框架的核心原则——数据互操作性和保证。 该模块允许您获取任意数量的应用程序数据并将其汇总为加密安全且简洁的值。
除了简单的散列(您可以在其中发送所有应用程序数据以确认简洁的值)之外,我们还支持部分公开 数据。 这允许您发送应用程序数据的部分和可以追溯到哈希的加密证明。
这种技术称为 Merkle 树,这就是为什么您能够使用 BitTorrent 从多个对等点下载文件,其中一些可能是敌对的,并确认每个部分是否正确……所有这些都来自一个微小的磁力链接。
此模块应用此技术,并允许您针对任何应用程序的任意 JSON 对象使用它。 从这个角度来看,所有其他 0xcert 框架模块都与使用此模块并将其连接到区块链有关。
Walkthrough
您是应用程序开发人员,您有一些应用程序数据需要向公众或某些第三方做出保证。 也许您是非营利性公司的国家注册商,您想要发布有关您注册的实体的一些事实。
您最了解您的应用程序,您可以按照自己喜欢的方式对数据进行建模:
// Define certificate with JSON schema definition.
const cert = new Cert({ schema: { ... } });
// Calculate schema ID
const id = await cert.identify();
接下来,获取实际的应用程序数据并对其进行公证:
// Define arbitrary data object.
const data = { ... };
// Notarize data object (returns all recipes for all data keys).
const evidence = await cert.notarize(data);
// Generate root hash from complete data object.
const imprint = await cert.imprint(data);
该印记简洁地代表了所有数据。 你可以发布它。 同时发布您的数据模型,它只是一个字段和类型的列表,您的应用程序数据将存储在其中。
现在您想要向公众或某些第三方公开一些数据。
// Expose selected data keys (returns recipes and exposed values from which an imprint can be calculated).
const evidence = await cert.disclose(data, [ ...paths ]);
你完成了。 第三方(或公众)可以拿走你的公开数据模型,你公开的具体数据和你提供的证据,以及……。
// Verify data object against recipes generated with function `disclose` (if object is valid, an imprint is the root hash).
const imprint = await cert.calculate(data, recipes);
??? 砰! 他们能够证实您之前发布的印记。
What we just accomplished
作为非营利性公司的国家注册处,您有权访问有关公司的信息。 也许这包括官员姓名、税务信息等。 根据您的声誉,您可以发布此数据的摘要,公众相信这些数据来自您的尽职调查,而无需公开任何细节。
为了获得贷款,公司的一名高级职员想要出示您的证明,证明该高级职员与公司有关联。 这已经可以使用纸张和电话来完成。 但是上述方法允许官员在不打扰您的情况下执行此操作,并且通过他们的银行进行更快的尽职调查。
Next steps
- These certificates can be published on the Ethereum blockchain. This provides irrefutability (i.e. what has been certified cannot be denied). :arrow_right: See our Asset Ledger Module.
- See how these certificates also enable enterprise commerce and other applications. :arrow_right: See our Ethereum Gateway Module.
- You can use the techniques above even without sharing any data. For example, you can prove the corporation revenue is over 1MM USD without exposing the actual amount. To learn more, visit your local library to read about zero-knowledge proofs.
The big picture
0xcert Framework 是一个免费的开源 JavaScript 库,它提供用于构建强大的去中心化应用程序的工具。 请参阅官方文档了解更多详情。
该模块是 0xcert Framework 的组成部分之一。 它是用 TypeScript 编写的,并且得到积极维护。 源代码可在 GitHub 上找到,您还可以在其中找到我们的 问题跟踪器。
???? Asset Certification Module
Data interoperability and assurance
Purpose
This is the core tenet of the 0xcert Framework — data interoperability and assurance. This module allows you to take any amount of application data and summarize it into a cryptographically-secure and succinct value.
In addition to just a simple hash — where you could send all the application data to confirm the succinct value — we also support partially exposing data. This allows you to send part of the application data and a cryptographic proof which can be traced back to the hash.
This technique is called a Merkle tree and it is why you are able to download a file using BitTorrent, from multiple peers, some of which may be hostile, and confirm if each part is correct… all from a tiny little magnet link.
This module applies this technique and allows you to use it against any arbitrary JSON object for any application. To put this into perspective, all of the other 0xcert Framework modules are concerned with using this module and connecting it to the blockchain.
Walkthrough
You are the application developer and you have some application data which you need to make assurances about to the public or some third party. Maybe you are a national registrar of non-profit corporations and you want to publish some facts about entities that you have registered.
You know your application best and you can model the data how you like:
// Define certificate with JSON schema definition.
const cert = new Cert({ schema: { ... } });
// Calculate schema ID
const id = await cert.identify();
Next, get the actual application data and notarize it:
// Define arbitrary data object.
const data = { ... };
// Notarize data object (returns all recipes for all data keys).
const evidence = await cert.notarize(data);
// Generate root hash from complete data object.
const imprint = await cert.imprint(data);
That imprint succinctly repsents all the data. You can publish it. Also publish your data model, which is just a list of fields and types that your application data will be stored in.
Now you would like to expose some of the data either to the public or some third party.
// Expose selected data keys (returns recipes and exposed values from which an imprint can be calculated).
const evidence = await cert.disclose(data, [ ...paths ]);
You are done. The third party (or the public) can take your public data model, the specific data you have exposed and the evidence you have provided, and ….
// Verify data object against recipes generated with function `disclose` (if object is valid, an imprint is the root hash).
const imprint = await cert.calculate(data, recipes);
???? Bam! They are able to corroborate against the imprint which you have previously published.
What we just accomplished
As the national registrar of non-profit corporations, you have priviledged access to information about corporations. Perhaps this includes names of officers, tax information and more. Based on your reputation, you are able to publish a summary of this data which the public trusts is from your due diligence, without making any details public.
In order to secure a loan, one of the officers of the corporation wants to present your attestation that the officer is associated with the corporation. This can already be done using paper and phone calls. But the above approach allows the officer to do this without bothering you and with a much faster due diligence through their bank.
Next steps
- These certificates can be published on the Ethereum blockchain. This provides irrefutability (i.e. what has been certified cannot be denied). :arrow_right: See our Asset Ledger Module.
- See how these certificates also enable enterprise commerce and other applications. :arrow_right: See our Ethereum Gateway Module.
- You can use the techniques above even without sharing any data. For example, you can prove the corporation revenue is over 1MM USD without exposing the actual amount. To learn more, visit your local library to read about zero-knowledge proofs.
The big picture
The 0xcert Framework is a free and open-source JavaScript library that provides tools for building powerful decentralized applications. Please refer to the official documentation for more details.
This module is one of the bricks of the 0xcert Framework. It's written with TypeScript and it's actively maintained. The source code is available on GitHub where you can also find our issue tracker.