├── .editorconfig
├── .eslintignore
├── .eslintrc.json
├── .gitignore
├── .prettierignore
├── .prettierrc
├── .travis.yml
├── LICENSE
├── README.md
├── index.html
├── index.js
├── lib
├── config.js
├── constants.js
├── evaluate.js
├── get.js
├── submit.js
├── submitFiles.js
├── utils
│ ├── helpers.js
│ ├── index.js
│ ├── network.js
│ └── proofs.js
└── verify.js
├── package.json
├── tests
├── config-test.js
├── data
│ ├── hashes.json
│ ├── nodes.json
│ ├── proof-handles.json
│ ├── proofs-response.json
│ ├── proofs.json
│ └── submit-hashes.json
├── e2e-test.js
├── evaluate-test.js
├── get-test.js
├── helpers-test.js
├── helpers.js
├── network-test.js
├── proof-test.js
├── submit-test.js
├── submitFile-test.js
└── verify-test.js
├── webpack.config.js
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: https://EditorConfig.org
2 |
3 | root = true
4 |
5 | [*]
6 | indent_style = space
7 | indent_size = 2
8 | end_of_line = lf
9 | charset = utf-8
10 | trim_trailing_whitespace = true
11 | insert_final_newline = true
12 |
13 | [*.md]
14 | trim_trailing_whitespace = false
15 |
16 | [*.txt]
17 | trim_trailing_whitespace = false
18 |
19 | [Makefile]
20 | indent_style = tab
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | dist/*
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "es6": true,
4 | "node": true,
5 | "browser": true
6 | },
7 | "extends": ["eslint:recommended", "plugin:prettier/recommended"],
8 | "parserOptions": {
9 | "ecmaVersion": 2018,
10 | "sourceType": "module"
11 | },
12 | "overrides": {
13 | "files": ["tests/**/*-test.js"],
14 | "env": {
15 | "mocha": true
16 | }
17 | },
18 | "plugins": ["prettier"],
19 | "rules": {
20 | "prettier/prettier": "error",
21 | "linebreak-style": ["error", "unix"],
22 | "no-console": "off",
23 | "camelcase": [
24 | "error",
25 | {
26 | "properties": "never",
27 | "ignoreDestructuring": true
28 | }
29 | ]
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | .DS_Store
3 | .nyc_output
4 | node_modules/
5 | npm-debug.log*
6 | yarn-debug.log*
7 | yarn-error.log*
8 | .vscode
9 | node_modules/
10 | dist/
11 | yarn-error.log
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | dist/*
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "semi": false,
4 | "printWidth": 120
5 | }
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '10'
4 | cache:
5 | directories:
6 | - node_modules
7 | before_script: yarn run webpack
8 | script:
9 | - yarn run test:$TEST_TYPE
10 | after_success: yarn run coverage
11 | matrix:
12 | include:
13 | - name: 'style tests'
14 | env: TEST_TYPE=lint
15 | - name: 'unit tests'
16 | env: TEST_TYPE=unit
17 | - name: 'e2e tests'
18 | env: TEST_TYPE=e2e
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Important: This package is now deprecated. Please use [chainpoint-js](https://github.com/chainpoint/chainpoint-js) instead.
2 |
3 | # Chainpoint Client (JavaScript)
4 |
5 | [](https://github.com/prettier/prettier)
6 | [](https://www.npmjs.com/package/chainpoint-client)
7 | [](https://www.npmjs.com/package/chainpoint-client)
8 | [](https://travis-ci.com/chainpoint/chainpoint-client-js)
9 | [](https://coveralls.io/github/chainpoint/chainpoint-client-js?branch=master)
10 |
11 | ## About
12 |
13 | A client for creating and verifying [Chainpoint](https://chainpoint.org) proofs.
14 |
15 | The Chainpoint Client handles communication with a distributed network of Nodes that make up the Chainpoint Network.
16 |
17 | The Chainpoint Client lets you submit hashes to a Chainpoint Node on the Chainpoint Network. Nodes periodically aggregate hashes and send data to Core for anchoring the hash to public blockchains.
18 |
19 | The Chainpoint Client lets you retrieve and verify a Chainpoint proof. Each proof cryptographically proves the integrity and existence of data at a point in time.
20 |
21 | This client can be used in both Browser and Node.js based JavaScript applications using `callback` functions, Promises (using `.then`, `.catch`), or Promises (using `async`/`await`) functional styles.
22 |
23 | **Important:** This library has been updated for v2 of the Chainpoint network. This means that it won't work for older proofs and instead interacts with nodes on the new network.
24 | If you would like to still use this library for older proofs, please downgrade to v1.x.x
25 |
26 | ## Proof Creation and Verification Overview
27 |
28 | Creating a Chainpoint proof is an asynchronous process. This client handles all the steps for submitting hashes, retrieving proofs, and verifying proofs.
29 |
30 | ### Submit Hash(es)
31 |
32 | This is an HTTP request that passes an Array of hash(es) to a Node. The Node will return a Version 1 UUID for each hash submitted. This `hashidNode` is used later for retrieving a proof.
33 |
34 | ### Get Proof(s)
35 |
36 | Proofs are first anchored to the 'Calendar' chain maintained by every Chainpoint Core. This takes up to ten seconds. Retrieving a `hashIdNode` at this stage returns a proof anchored to the Calendar.
37 |
38 | Proofs are appended with data as they are anchored to additional blockchains. For example, it takes 60 - 90 minutes to anchor a proof to Bitcoin. Calling getProofs will now append the first proof with data that anchors it to the Bitcoin Blockchain.
39 |
40 | Nodes retain proofs for 24 hours. Each client must retrieve and permanently store each Chainpoint proof.
41 |
42 | ### Verify Proof(s)
43 |
44 | Anyone with a Chainpoint proof can verify that it cryptographically anchors to one or more of the public blockchains. The verification process performs the operations in the proof to re-create a Merkle root. This value is compared to a Merkle root stored in the public blockchain. If the values match, the proof is valid.
45 |
46 | ### Evaluate Proof(s)
47 |
48 | This function is similar to the Verify function. The difference with this function is that it only calculates and returns the expected values for each anchor. This function does not verify that the expected values exist on the public blockchains. In most common cases, you will want to use Verify instead.
49 |
50 | ## TL;DR
51 |
52 | [Try It Out with RunKit](https://runkit.com/grempe/tierion-chainpoint-client-async-example)
53 |
54 | ```javascript
55 | const chp = require('chainpoint-client')
56 |
57 | async function runIt() {
58 | // A few sample SHA-256 proofs to anchor
59 | let hashes = [
60 | '1d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
61 | '2d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
62 | '3d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a'
63 | ]
64 |
65 | // Submit each hash to three randomly selected Nodes
66 | let proofHandles = await chp.submitHashes(hashes)
67 | console.log('Submitted Proof Objects: Expand objects below to inspect.')
68 | console.log(proofHandles)
69 |
70 | // Wait for Calendar proofs to be available
71 | console.log('Sleeping 12 seconds to wait for proofs to generate...')
72 | await new Promise(resolve => setTimeout(resolve, 12000))
73 |
74 | // Retrieve a Calendar proof for each hash that was submitted
75 | let proofs = await chp.getProofs(proofHandles)
76 | console.log('Proof Objects: Expand objects below to inspect.')
77 | console.log(proofs)
78 |
79 | // Verify every anchor in every Calendar proof
80 | let verifiedProofs = await chp.verifyProofs(proofs)
81 | console.log('Verified Proof Objects: Expand objects below to inspect.')
82 | console.log(verifiedProofs)
83 | }
84 |
85 | runIt()
86 | ```
87 |
88 | ## Public API
89 |
90 | The following public functions are exported from this client. All functions in the client library are written
91 | using Promises in the async/await style where possible. Previous versions were written in the Nodejs callback
92 | style, but that has since been deprecated.
93 |
94 | Additionally, the output of each function in the process has been designed so that it can be used as the input to the next with no need to manipulate the data.
95 |
96 | ### `submitHashes(hashes, uris)`
97 |
98 | #### Description
99 |
100 | Use this function to submit an Array of hashes, and receive back the information needed to later retrieve a proof for each of those hashes using the `getProofs()` function.
101 |
102 | By default hashes are submitted to three Nodes to help ensure a proof will become available at the appropriate time. Only one such proof need be permanently stored, the others provide redundancy.
103 |
104 | #### Arguments
105 |
106 | The `hashes` argument expects an Array of hashes, where each hash is a Hexadecimal String `[a-fA-F0-9]` between 160 bits (20 Bytes, 40 Hex characters) and 512 bits (64 Bytes, 128 Hex characters) in length. The Hex string must be an even length.
107 |
108 | We recommend using the SHA-256 cryptographic one-way hash function for all hashes submitted.
109 |
110 | The optional `uris` argument accepts an Array of Node URI's as returned by the `getNodes()` function. Each element of the returned Array is a full URI with `scheme://hostname[:port]` (e.g. `http://127.0.0.1` or `http://127.0.0.1:80`).
111 |
112 | #### Return Values
113 |
114 | The return value from this function is an Array of Objects, one for each hash submitted. Each result Object has the information needed to retrieve a proof for a submitted hash. There will be one Object for every Node a hash was submitted to.
115 |
116 | The Array of Objects, referred to as `proofHandles` can also be submitted directly as the argument to the `getProofs()` function. It typically takes about 10 seconds for initial Calendar proofs to become available.
117 |
118 | The Object will contain:
119 |
120 | `uri` : The URI of the Node(s) the hash was submitted to. This is the only Node that can retrieve this particular proof.
121 |
122 | `hash` : A copy of the hash that was originally submitted that will be embedded in a future proof. This allows for easier correlation between hashes submitted and the Hash ID handle needed to retrieve a proof.
123 |
124 | `hashIdNode` : The Version 1 UUID that can be used to retrieve the proof for a submitted hash from the `/proofs/:id` endpoint of the Node it was submitted to.
125 |
126 | `groupId` : A Version 1 UUID which is used to group Proof Handles that have the same corresponding hash. The groupId can later be used to optimize the proof retrieval process.
127 |
128 | Example Return Value
129 |
130 | ```javascript
131 | ;[
132 | {
133 | uri: 'http://0.0.0.0',
134 | hash: '1d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
135 | proofId: 'df500460-d7d1-11e8-992b-0178d9540713',
136 | groupId: 'dfa4b410-d7d1-11e8-a6e3-c763418c848e'
137 | },
138 | {
139 | uri: 'http://0.0.0.0',
140 | hash: '2d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
141 | proofId: 'df502b70-d7d1-11e8-992b-0187b4b6e491',
142 | groupId: 'dfa4b411-d7d1-11e8-a6e3-c763418c848e'
143 | }
144 | ]
145 | ```
146 |
147 | ### `submitFileHashes(paths, uris)`
148 |
149 | #### Description
150 |
151 | Use this function to submit hashes calculated from an Array of file paths, and receive back the information needed to later retrieve a proof for each of those hashes using the `getProofs()` function.
152 |
153 | By default hashes are submitted to three Nodes to help ensure a proof will become available at the appropriate time. Only one such proof need be permanently stored, the others provide redundancy.
154 |
155 | #### Arguments
156 |
157 | The `paths` argument expects an Array of valid file paths.
158 |
159 | The SHA-256 cryptographic one-way hash function will be used on all files in the paths submitted.
160 |
161 | The optional `uris` argument accepts an Array of Node URI's as returned by the `getNodes()` function. Each element of the returned Array is a full URI with `scheme://hostname[:port]` (e.g. `http://127.0.0.1` or `http://127.0.0.1:80`).
162 |
163 | #### Return Values
164 |
165 | The return value from this function is an Array of Objects, one for each hash submitted. Each result Object has the information needed to retrieve a proof for a submitted hash. There will be one Object for every Node a hash was submitted to.
166 |
167 | The Array of Objects, referred to as `proofHandles` can also be submitted directly as the argument to the `getProofs()` function. It typically takes about 10 seconds for initial Calendar proofs to become available.
168 |
169 | The Object will contain:
170 |
171 | `uri` : The URI of the Node(s) the hash was submitted to. This is the only Node that can retrieve this particular proof.
172 |
173 | `hash` : A copy of the hash that was originally submitted that will be embedded in a future proof. This allows for easier correlation between hashes submitted and the Hash ID handle needed to retrieve a proof.
174 |
175 | `hashIdNode` : The Version 1 UUID that can be used to retrieve the proof for a submitted hash from the `/proofs/:id` endpoint of the Node it was submitted to.
176 |
177 | `path` : The path of the file represented by this object.
178 |
179 | `groupId` : A Version 1 UUID which is used to group Proof Handles that have the same corresponding hash. The groupId can later be used to optimize the proof retrieval process.
180 |
181 | Example Return Value
182 |
183 | ```javascript
184 | ;[
185 | {
186 | uri: 'http://0.0.0.0',
187 | hash: '9d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
188 | proofId: 'a512e430-d3cb-11e7-aeb7-01eecbb37e34',
189 | path: './datafile.json',
190 | groupId: 'dc1c8cd0-d7d3-11e8-8a5c-7fe62f82e5c3'
191 | },
192 | {
193 | uri: 'http://0.0.0.0',
194 | hash: '9d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a',
195 | proofId: 'a4b6e180-d3cb-11e7-90bc-014342a27e15',
196 | path: './folder/otherfile.csv',
197 | groupId: 'dc1c8cd1-d7d3-11e8-8a5c-7fe62f82e5c3'
198 | }
199 | ]
200 | ```
201 |
202 | ### `getProofs(proofHandles)`
203 |
204 | #### Description
205 |
206 | This function is used to retrieve Chainpoint proofs from the Nodes that are responsible for creating each proof.
207 |
208 | #### Arguments
209 |
210 | The `proofHandles` argument accepts an Array of Objects. Each object must have the `uri` and `hashIdNode` properties. The argument is of the same form as the output from the `submitHashes()` function.
211 |
212 | The `uri` property should be the base URI (e.g. `http://0.0.0.0`) of an online Node that is responsible for generating a particular proof.
213 |
214 | The `hashIdNode` property is a valid Version 1 UUID as provided by the return of the `submitHashes()` function.
215 |
216 | #### Return Values
217 |
218 | This function will return an Array of Objects, each composed of the following properties:
219 |
220 | ```javascript
221 | {
222 | hashIdNode: "",
223 | proof: "",
224 | anchorsComplete: []
225 | }
226 | ```
227 |
228 | `hashIdNode` : The Version 1 UUID used to retrieve the proof.
229 |
230 | `proof` : The Base64 encoded binary form of the proof. See [https://github.com/chainpoint/chainpoint-binary](https://github.com/chainpoint/chainpoint-binary) for more information about proof formats. That library can also be used to convert from one form to another. If the proof is not yet available, or cannot be retrieved, this will be set to `null`.
231 |
232 | `anchorsComplete` : An Array of Strings that indicates which blockchains the proof is anchored to at the time of retrieval. One or more of `cal` (Calendar), `btc` (Bitcoin), or `eth` (Ethereum) (you may also see `tcal` or `tbtc` for
233 | testnet calendar anchors and testnet bitcoin anchors respectively). If the proof is not yet available, or cannot be retrieved, this will be set to `[]` (An empty Array).
234 |
235 | Example Return Value
236 |
237 | ```javascript
238 | ;[
239 | {
240 | proofId: 'e47f00b0-d3fb-11e7-9dd9-015eb614885c',
241 | proof:
242 | 'eJylVc1qZFUQ9jlcu+10VZ3/rAKCT+DKTahzqk7SENKhux3HZRRcO/oEo5EZB1wIrn2PgA/jdzMZBye9EDzQNPfce+vUV9/P/e712dheH/z54c/Lw+Fmf7pefxU2drLdXazHpW6ub7ab68P6Wbw7fH3jbz79Z+vuUveX92cTS4qITA85G/Xaau0lsIzcNZN7FIlcrUnPMmz0wtOlNXYvofHrm912O883dv9JcoohGK1iNl0xu660NF8Rl8ktJkmFf1tOPd/58M0ztz+EhFYkKwqfSzhlOpX6xeu+0+tx6fsX3/5ypd2v3ujFxc4v9LDd/by92X//5IHfh16dL1vb3fnbe8tzP96+vLr/4XqzPzyTU06VSuFIdGpJtcxpappm7m3kEgOuJabBJl2GBoCvjv+USubKo1aZpQwfpkEDRauucTYlaaEGppa4FhRLSh2VuVtp1oKpdDWLyW1Gwu3c2G5/2t682l/qSlK+ffW2bUB54OfuACi/PkLBTM8Kpza9JurZrCeeM5GNaDF2Vg0ZPFVPohbbFJ6Wa+dhNErRqTna3Ze7zf7FfV+0AWmEEw7pJMUTkbTGUX5tulv/30PWpgd9z8o3j6z0w3jKyl8ffXz7cgfdxSJubc5AENdE6WYFs7c6eY7SKI3Yi1DsOgTjJHTHKUBxrZah+V9TBNFnXQuVnspsrgapFsy/hcjFZuvoP1QAaD59cPIIdgc0nafW0lWotA8LHojp7WLOTCkPOCR0cJgwnjFnjR6oJ2MgIYtauIh2ibk76gaTisLSa31XB2s+Lsj+gyWS0cYyms+oOmwHwO/Oz/hFFfU0CP2Tt9BhNEmN2oxQbKylhJKxM8a7txY8bx7xrJ7Lw4wwuJGB2VKdnSquLJeStSpVgmAJ7A7vLoaThMOoLTt24JQ+Q9ZjNQOZxuGhSx6Jos/u8FVHY1181NnIK4dGwTKlJTtyVsCNM4DrPtuTmhCHyezchKMs7eYM1OitthkCmAsJUikt8yzRfUQei1o7DN47tIJkOlYzBsScLuFGGMCkwX2Bamla8bYYthVkHQQBpAHe56acyEchDNjisZo12GgKqI20gg1UcYytN4+Ihe5hlh7YJViKozLrAPTpS9dtQp7HaqJLR5MTIcTQCQIpDlbOyF1TpUixjp6RWAvkjkypHGud8C7AxTSP1SzuME9VnGo+Ug8jtw6CK/YlB1F2CIgKNyR1aosXuaWpHmJJedajHFGKnA0yQu5Dsci90BGqYXmTvWFkzXoVyLiARSmlGK4sFITlSPlYTWU4N9tMMLgoOKKJbgesBA/2aAKbxTLr4Iqp41ihNnpY1Kw08/iw5pN0RSS9T9dXnHOssf6njMTnDiKLCHumPvISB8IemuJjWQgx06pDB6CENKFj6DZQJoP78WXo5SEj/wbUW3Ki',
243 | anchorsComplete: ['tcal', 'tbtc']
244 | }
245 | ]
246 | ```
247 |
248 | ### `verifyProofs (proofs, uri)`
249 |
250 | #### Description
251 |
252 | This function is used to verify proofs by comparing the values arrived at by parsing and performing the operations in a proof against the Chainpoint calendar or public blockchains.
253 |
254 | #### Arguments
255 |
256 | The `proofs` argument accepts an Array of Strings or Objects.
257 |
258 | If a String, it is expected to be a Chainpoint 4.0 proof in either Base64 encoded binary, or JSON-LD form.
259 |
260 | If an Object it can be a Chainpoint 4.0 proof as an Object, or have a `proof` property containing a String proof as described above as is created by the output of `getProofs()`.
261 |
262 | Proof types can be mixed freely in the `proofs` arg Array.
263 |
264 | The `uri` property should be the base URI (e.g. `http://0.0.0.0`) of an online Node that will be responsible for providing a hash value from the Calendar block specified in the proof. The hash value provided will then be compared to the result of calculating all of the operations in the proof locally. If the locally calculated values matches the server provided value it verifies that the proof is valid.
265 |
266 | At no time is the proof sent over the Internet during this process (although it is safe to do so).
267 |
268 | #### Return Values
269 |
270 | This function will return an Array of Objects. Each object represents an Anchor in a proof along with all of the relevant data.
271 |
272 | For example, a single proof that is anchored to both the Chainpoint Calendar, and to the Bitcoin blockchain, will return two objects. One for each of those anchors.
273 |
274 | Example Return Value
275 |
276 | ```javascript
277 | ;[
278 | {
279 | hash: 'daeaedcd320c0fb2adefaab15ec03a424bb7a89aa0ec918c6c4906c366c67e36',
280 | proof_id: '5e0433d0-46da-11ea-a79e-017f19452571',
281 | hash_received: '2020-02-03T23:10:28Z',
282 | uri: 'http://127.0.0.1/calendar/695928/hash',
283 | type: 'cal',
284 | anchorId: '695928',
285 | expectedValue: 'ff0fb5903d3b6deed2ee2ebc033813e7b0357de4af2e7b1d52784baad40a0d13',
286 | verified: true,
287 | verifiedAt: '2017-11-28T22:52:20Z'
288 | },
289 | {
290 | hash: 'daeaedcd320c0fb2adefaab15ec03a424bb7a89aa0ec918c6c4906c366c67e36',
291 | proof_id: '5e0433d0-46da-11ea-a79e-017f19452571',
292 | hash_received: '2020-02-03T23:10:28Z',
293 | uri: 'http://127.0.0.1/calendar/696030/data',
294 | type: 'btc',
295 | anchorId: '496469',
296 | expectedValue: 'de999f26afcdd855552ca91184aba496baa48bf59a7125180d7c1d7d520ea88b',
297 | verified: true,
298 | verifiedAt: '2017-11-28T22:52:20Z'
299 | }
300 | ]
301 | ```
302 |
303 | ### `evaluateProofs (proofs)`
304 |
305 | #### Description
306 |
307 | This function is used to evaluate proofs and returns the values arrived at by parsing and performing the operations in a proof.
308 |
309 | For example, this can be used to easily verify that a proof that is anchored to the Bitcoin blockchain is valid, without trusting any other third party service. The only thing required is a copy of the Bitcoin block headers, available from any BTC full node or block explorer.
310 |
311 | #### Arguments
312 |
313 | The `proofs` argument accepts an Array of Strings or Objects.
314 |
315 | If a String, it is expected to be a Chainpoint 4.0 proof in either Base64 encoded binary, or JSON-LD form.
316 |
317 | If an Object it can be a Chainpoint 4.0 proof as an Object, or have a `proof` property containing a String proof as described above as is created by the output of `getProofs()`.
318 |
319 | Proof types can be mixed freely in the `proofs` arg Array.
320 |
321 | This process is handled entirely offline. At no time is the proof sent over the Internet during this process (although it is safe to do so).
322 |
323 | #### Return Values
324 |
325 | This function will return an Array of Objects. Each object represents an Anchor in a proof along with all of the relevant data.
326 |
327 | For example, a single proof that is anchored to both the Chainpoint Calendar, and to the Bitcoin blockchain, will return two objects. One for each of those anchors.
328 |
329 | Example Return Value
330 |
331 | ```javascript
332 | ;[
333 | {
334 | hash: 'daeaedcd320c0fb2adefaab15ec03a424bb7a89aa0ec918c6c4906c366c67e36',
335 | proof_id: '5e0433d0-46da-11ea-a79e-017f19452571',
336 | hash_received: '2020-02-03T23:10:28Z',
337 | uri: 'http://127.0.0.1/calendar/695928/hash',
338 | type: 'cal',
339 | anchorId: '695928',
340 | expectedValue: 'ff0fb5903d3b6deed2ee2ebc033813e7b0357de4af2e7b1d52784baad40a0d13'
341 | },
342 | {
343 | hash: 'daeaedcd320c0fb2adefaab15ec03a424bb7a89aa0ec918c6c4906c366c67e36',
344 | proof_id: '5e0433d0-46da-11ea-a79e-017f19452571',
345 | hash_received: '2020-02-03T23:10:28Z',
346 | uri: 'http://127.0.0.1/calendar/696030/data',
347 | type: 'btc',
348 | anchorId: '496469',
349 | expectedValue: 'de999f26afcdd855552ca91184aba496baa48bf59a7125180d7c1d7d520ea88b'
350 | }
351 | ]
352 | ```
353 |
354 | In this case, you can use a block explorer to confirm that BTC block ID `496469` has a block Merkle root value (`expectedValue`) of `de999f26afcdd855552ca91184aba496baa48bf59a7125180d7c1d7d520ea88b`. If it does, that means this proof can be provably said to anchor its hash to that Bitcoin block.
355 |
356 | ### `getCores (num)`
357 |
358 | #### Description
359 |
360 | This is a utility function that allows you to perform DNS based auto-discovery of a available Core instance URI addresses.
361 |
362 | This function is not required to be explicitly called when using the main functions of this library. It will be called internally as needed.
363 |
364 | #### Arguments
365 |
366 | The optional `num` argument determines the maximum number of Cores that should be returned in a single request in randomized order.
367 |
368 | #### Return Values
369 |
370 | This function returns an Array of String URIs.
371 |
372 | ### `getNodes (num)`
373 |
374 | #### Description
375 |
376 | This is a utility function that allows you to perform DNS based auto-discovery of Node URIs.
377 |
378 | This function is not required to be explicitly called when using the main functions of this library. It will be called internally as needed.
379 |
380 | #### Arguments
381 |
382 | The optional `num` argument determines the maximum number of Nodes that should be returned in a single request in randomized order. The number of URI's returned are ultimately limited by the number of Nodes returned by Core's auto-discovery mechanism.
383 |
384 | #### Return Values
385 |
386 | This function returns an Array of String URIs. The list of Nodes returned are for Nodes that have recently been audited and found to be healthy.
387 |
388 | ## Usage : Functional Styles
389 |
390 | This client can be used with several popular JavaScript API styles in both Node.js and the Browser.
391 | The choice of API style is left to the developer and should be based on support for
392 | each style in the intended runtime platform and the developer's preference.
393 |
394 | The callback style is fully supported everywhere,
395 | while Promises and `async/await` support will depend on the version of Node.js or Browser
396 | being targetted. Each public API exported from this module supports each style equally.
397 |
398 | ### Callback Style Example [DEPRECATED]
399 |
400 | ```javascript
401 | var cp = require('chainpoint-client')
402 |
403 | let hashes = ['9d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a']
404 |
405 | cp.submitHashes(hashes, function(err, data) {
406 | if (err) {
407 | // `err` will contain any returned Error object and halt execution
408 | throw err
409 | }
410 |
411 | // If no error `data` will contain the returned values
412 | console.log(JSON.stringify(data, null, 2))
413 | })
414 | ```
415 |
416 | ### Promises `.then/.catch` Style Example
417 |
418 | ```javascript
419 | var cp = require('chainpoint-client')
420 |
421 | let hashes = ['9d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a']
422 |
423 | cp.submitHashes(hashes, testNodesArray)
424 | .then(function(data) {
425 | // `data` will contain the returned values
426 | console.log(JSON.stringify(data, null, 2))
427 | })
428 | .catch(function(err) {
429 | // `err` will contain any returned Error object
430 | console.log(err)
431 | })
432 | ```
433 |
434 | ### Promises `async/await` Style Example
435 |
436 | ```javascript
437 | var cp = require('chainpoint-client')
438 |
439 | let hashes = ['9d2a9e92b561440e8d27a21eed114f7018105db00262af7d7087f7dea9986b0a']
440 |
441 | async function runIt() {
442 | let data = await cp.submitHashes(hashes)
443 | console.log(JSON.stringify(data, null, 2))
444 | }
445 |
446 | runIt()
447 | ```
448 |
449 | ### JavaScript Client-Side Frameworks Example
450 |
451 | Note: If you are using any client-side JavaScript framework (ex. Angular, React, etc) remember to import chainpoint-client in the following manner:
452 |
453 | ```js
454 | import chainpoint from 'chainpoint-client/dist/bundle.web'
455 | ```
456 |
457 | or
458 |
459 | ```js
460 | const chainpoint = require('chainpoint-client/dist/bundle.web')
461 | ```
462 |
463 | ### Browser Script Tag Example
464 |
465 | You can copy `dist/bundle.web.js` into your app to be served from your own web server and included in a script tag.
466 |
467 | Or install the `npm` package in a place available to your web server pages and set the `script src` tag as shown in the example below. A set of window global functions (e.g. `chainpointClient.submitHashes()`) will then be available for use in a fashion similar to that shown in the examples above.
468 |
469 | ```html
470 |
38 |
39 |
88 |