@333eco/origin-verify 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,125 +1,7 @@
1
- Creative Commons Legal Code
1
+ @333eco/origin-verify is offered under your choice of two licenses (SPDX: CC0-1.0 OR Apache-2.0):
2
2
 
3
- CC0 1.0 Universal
3
+ - CC0 1.0 Universal (public domain dedication): see LICENSE-CC0
4
+ - Apache License 2.0: see LICENSE-APACHE
4
5
 
5
- The authoritative text of this licence is published at
6
- https://creativecommons.org/publicdomain/zero/1.0/legalcode
7
- and governs in the event of any discrepancy with the copy below.
8
-
9
- CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
10
- LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
11
- ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
12
- INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
13
- REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
14
- PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
15
- THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
16
- HEREUNDER.
17
-
18
- Statement of Purpose
19
-
20
- The laws of most jurisdictions throughout the world automatically confer
21
- exclusive Copyright and Related Rights (defined below) upon the creator
22
- and subsequent owner(s) (each and all, an "owner") of an original work of
23
- authorship and/or a database (each, a "Work").
24
-
25
- Certain owners wish to permanently relinquish those rights to a Work for
26
- the purpose of contributing to a commons of creative, cultural and
27
- scientific works ("Commons") that the public can reliably and without fear
28
- of later claims of infringement build upon, modify, incorporate in other
29
- works, reuse and redistribute as freely as possible in any form whatsoever
30
- and for any purposes, including without limitation commercial purposes.
31
- These owners may contribute to the Commons to promote the ideal of a free
32
- culture and the further production of creative, cultural and scientific
33
- works, or to gain reputation or greater distribution for their Work in
34
- part through the use and efforts of others.
35
-
36
- For these and/or other purposes and motivations, and without any
37
- expectation of additional consideration or compensation, the person
38
- associating CC0 with a Work (the "Affirmer"), to the extent that he or she
39
- is an owner of Copyright and Related Rights in the Work, voluntarily
40
- elects to apply CC0 to the Work and publicly distribute the Work under its
41
- terms, with knowledge of his or her Copyright and Related Rights in the
42
- Work and the meaning and intended legal effect of CC0 on those rights.
43
-
44
- 1. Copyright and Related Rights. A Work made available under CC0 may be
45
- protected by copyright and related or neighboring rights ("Copyright and
46
- Related Rights"). Copyright and Related Rights include, but are not
47
- limited to, the following:
48
-
49
- i. the right to reproduce, adapt, distribute, perform, display,
50
- communicate, and translate a Work;
51
- ii. moral rights retained by the original author(s) and/or performer(s);
52
- iii. publicity and privacy rights pertaining to a person's image or
53
- likeness depicted in a Work;
54
- iv. rights protecting against unfair competition in regards to a Work,
55
- subject to the limitations in paragraph 4(a), below;
56
- v. rights protecting the extraction, dissemination, use and reuse of
57
- data in a Work;
58
- vi. database rights (such as those arising under Directive 96/9/EC of the
59
- European Parliament and of the Council of 11 March 1996 on the legal
60
- protection of databases, and under any national implementation
61
- thereof, including any amended or successor version of such
62
- directive); and
63
- vii. other similar, equivalent or corresponding rights throughout the
64
- world based on applicable law or treaty, and any national
65
- implementations thereof.
66
-
67
- 2. Waiver. To the greatest extent permitted by, but not in contravention
68
- of, applicable law, Affirmer hereby overtly, fully, permanently,
69
- irrevocably and unconditionally waives, abandons, and surrenders all of
70
- Affirmer's Copyright and Related Rights and associated claims and causes
71
- of action, whether now known or unknown (including existing as well as
72
- future claims and causes of action), in the Work (i) in all territories
73
- worldwide, (ii) for the maximum duration provided by applicable law or
74
- treaty (including future time extensions), (iii) in any current or future
75
- medium and for any number of copies, and (iv) for any purpose whatsoever,
76
- including without limitation commercial, advertising or promotional
77
- purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
78
- member of the public at large and to the detriment of Affirmer's heirs and
79
- successors, fully intending that such Waiver shall not be subject to
80
- revocation, rescission, cancellation, termination, or any other legal or
81
- equitable action to disrupt the quiet enjoyment of the Work by the public
82
- as contemplated by Affirmer's express Statement of Purpose.
83
-
84
- 3. Public License Fallback. Should any part of the Waiver for any reason
85
- be judged legally invalid or ineffective under applicable law, then the
86
- Waiver shall be preserved to the maximum extent permitted taking into
87
- account Affirmer's express Statement of Purpose. In addition, to the
88
- extent the Waiver is so judged Affirmer hereby grants to each affected
89
- person a royalty-free, non transferable, non sublicensable, non exclusive,
90
- irrevocable and unconditional license to exercise Affirmer's Copyright and
91
- Related Rights in the Work (i) in all territories worldwide, (ii) for the
92
- maximum duration provided by applicable law or treaty (including future
93
- time extensions), (iii) in any current or future medium and for any number
94
- of copies, and (iv) for any purpose whatsoever, including without
95
- limitation commercial, advertising or promotional purposes (the
96
- "License"). The License shall be deemed effective as of the date CC0 was
97
- applied by Affirmer to the Work. Should any part of the License for any
98
- reason be judged legally invalid or ineffective under applicable law, such
99
- partial invalidity or ineffectiveness shall not invalidate the remainder
100
- of the License, and in such case Affirmer hereby affirms that he or she
101
- will not (i) exercise any of his or her remaining Copyright and Related
102
- Rights in the Work or (ii) assert any associated claims and causes of
103
- action with respect to the Work, in either case contrary to Affirmer's
104
- express Statement of Purpose.
105
-
106
- 4. Limitations and Disclaimers.
107
-
108
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
109
- surrendered, licensed or otherwise affected by this document.
110
- b. Affirmer offers the Work as-is and makes no representations or
111
- warranties of any kind concerning the Work, express, implied,
112
- statutory or otherwise, including without limitation warranties of
113
- title, merchantability, fitness for a particular purpose, non
114
- infringement, or the absence of latent or other defects, accuracy, or
115
- the present or absence of errors, whether or not discoverable, all to
116
- the greatest extent permissible under applicable law.
117
- c. Affirmer disclaims responsibility for clearing rights of other persons
118
- that may apply to the Work or any use thereof, including without
119
- limitation any person's Copyright and Related Rights in the Work.
120
- Further, Affirmer disclaims responsibility for obtaining any necessary
121
- consents, permissions or other rights required for any use of the
122
- Work.
123
- d. Affirmer understands and acknowledges that Creative Commons is not a
124
- party to this document and has no duty or obligation with respect to
125
- this CC0 or use of the Work.
6
+ Pick whichever suits you; you need follow only the one you pick. Neither grants any right in the HeartBank® or other
7
+ trademarks, which are not licensed here.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,73 @@
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, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
package/LICENSE-CC0 ADDED
@@ -0,0 +1,125 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ The authoritative text of this licence is published at
6
+ https://creativecommons.org/publicdomain/zero/1.0/legalcode
7
+ and governs in the event of any discrepancy with the copy below.
8
+
9
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
10
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
11
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
12
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
13
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
14
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
15
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
16
+ HEREUNDER.
17
+
18
+ Statement of Purpose
19
+
20
+ The laws of most jurisdictions throughout the world automatically confer
21
+ exclusive Copyright and Related Rights (defined below) upon the creator
22
+ and subsequent owner(s) (each and all, an "owner") of an original work of
23
+ authorship and/or a database (each, a "Work").
24
+
25
+ Certain owners wish to permanently relinquish those rights to a Work for
26
+ the purpose of contributing to a commons of creative, cultural and
27
+ scientific works ("Commons") that the public can reliably and without fear
28
+ of later claims of infringement build upon, modify, incorporate in other
29
+ works, reuse and redistribute as freely as possible in any form whatsoever
30
+ and for any purposes, including without limitation commercial purposes.
31
+ These owners may contribute to the Commons to promote the ideal of a free
32
+ culture and the further production of creative, cultural and scientific
33
+ works, or to gain reputation or greater distribution for their Work in
34
+ part through the use and efforts of others.
35
+
36
+ For these and/or other purposes and motivations, and without any
37
+ expectation of additional consideration or compensation, the person
38
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
39
+ is an owner of Copyright and Related Rights in the Work, voluntarily
40
+ elects to apply CC0 to the Work and publicly distribute the Work under its
41
+ terms, with knowledge of his or her Copyright and Related Rights in the
42
+ Work and the meaning and intended legal effect of CC0 on those rights.
43
+
44
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
45
+ protected by copyright and related or neighboring rights ("Copyright and
46
+ Related Rights"). Copyright and Related Rights include, but are not
47
+ limited to, the following:
48
+
49
+ i. the right to reproduce, adapt, distribute, perform, display,
50
+ communicate, and translate a Work;
51
+ ii. moral rights retained by the original author(s) and/or performer(s);
52
+ iii. publicity and privacy rights pertaining to a person's image or
53
+ likeness depicted in a Work;
54
+ iv. rights protecting against unfair competition in regards to a Work,
55
+ subject to the limitations in paragraph 4(a), below;
56
+ v. rights protecting the extraction, dissemination, use and reuse of
57
+ data in a Work;
58
+ vi. database rights (such as those arising under Directive 96/9/EC of the
59
+ European Parliament and of the Council of 11 March 1996 on the legal
60
+ protection of databases, and under any national implementation
61
+ thereof, including any amended or successor version of such
62
+ directive); and
63
+ vii. other similar, equivalent or corresponding rights throughout the
64
+ world based on applicable law or treaty, and any national
65
+ implementations thereof.
66
+
67
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
68
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
69
+ irrevocably and unconditionally waives, abandons, and surrenders all of
70
+ Affirmer's Copyright and Related Rights and associated claims and causes
71
+ of action, whether now known or unknown (including existing as well as
72
+ future claims and causes of action), in the Work (i) in all territories
73
+ worldwide, (ii) for the maximum duration provided by applicable law or
74
+ treaty (including future time extensions), (iii) in any current or future
75
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
76
+ including without limitation commercial, advertising or promotional
77
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
78
+ member of the public at large and to the detriment of Affirmer's heirs and
79
+ successors, fully intending that such Waiver shall not be subject to
80
+ revocation, rescission, cancellation, termination, or any other legal or
81
+ equitable action to disrupt the quiet enjoyment of the Work by the public
82
+ as contemplated by Affirmer's express Statement of Purpose.
83
+
84
+ 3. Public License Fallback. Should any part of the Waiver for any reason
85
+ be judged legally invalid or ineffective under applicable law, then the
86
+ Waiver shall be preserved to the maximum extent permitted taking into
87
+ account Affirmer's express Statement of Purpose. In addition, to the
88
+ extent the Waiver is so judged Affirmer hereby grants to each affected
89
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
90
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
91
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
92
+ maximum duration provided by applicable law or treaty (including future
93
+ time extensions), (iii) in any current or future medium and for any number
94
+ of copies, and (iv) for any purpose whatsoever, including without
95
+ limitation commercial, advertising or promotional purposes (the
96
+ "License"). The License shall be deemed effective as of the date CC0 was
97
+ applied by Affirmer to the Work. Should any part of the License for any
98
+ reason be judged legally invalid or ineffective under applicable law, such
99
+ partial invalidity or ineffectiveness shall not invalidate the remainder
100
+ of the License, and in such case Affirmer hereby affirms that he or she
101
+ will not (i) exercise any of his or her remaining Copyright and Related
102
+ Rights in the Work or (ii) assert any associated claims and causes of
103
+ action with respect to the Work, in either case contrary to Affirmer's
104
+ express Statement of Purpose.
105
+
106
+ 4. Limitations and Disclaimers.
107
+
108
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
109
+ surrendered, licensed or otherwise affected by this document.
110
+ b. Affirmer offers the Work as-is and makes no representations or
111
+ warranties of any kind concerning the Work, express, implied,
112
+ statutory or otherwise, including without limitation warranties of
113
+ title, merchantability, fitness for a particular purpose, non
114
+ infringement, or the absence of latent or other defects, accuracy, or
115
+ the present or absence of errors, whether or not discoverable, all to
116
+ the greatest extent permissible under applicable law.
117
+ c. Affirmer disclaims responsibility for clearing rights of other persons
118
+ that may apply to the Work or any use thereof, including without
119
+ limitation any person's Copyright and Related Rights in the Work.
120
+ Further, Affirmer disclaims responsibility for obtaining any necessary
121
+ consents, permissions or other rights required for any use of the
122
+ Work.
123
+ d. Affirmer understands and acknowledges that Creative Commons is not a
124
+ party to this document and has no duty or obligation with respect to
125
+ this CC0 or use of the Work.
package/README.md CHANGED
@@ -44,6 +44,34 @@ Four states. Each stands alone and none implies another.
44
44
 
45
45
  ⚠️ The DCT hash most people reach for fails on pixel art: half the coefficients of a mirror-symmetric sprite are near zero, so their bits are noise. Measured on 150 pictures × 5 re-encodings, 40 of them symmetric sprites: this hash finds 99.7% of the same picture within distance 8, with 0.8% of different pictures within 8.
46
46
 
47
+ ## A proof inside the file
48
+
49
+ A pack can travel inside the PNG or JPEG it describes, so the file can be checked with nothing else and no network:
50
+
51
+ ```js
52
+ import { embedPack, verifyFile } from "@333eco/origin-verify";
53
+ const carried = embedPack(fileBytes, pack); // a copy with the proof inside; refuses a pack for any other file
54
+ const result = await verifyFile(carried, trust);
55
+ ```
56
+
57
+ The proof sits in a private PNG chunk or in JPEG APP9 segments. The picture isn't touched, and taking the proof out gives back exactly the bytes that were signed, which is how a reader knows it belongs to this file. Embedding again replaces the proof, so a pack can be renewed as it gains its timestamps.
58
+
59
+ - A pack with an `opening` carries the passkey's signature. The file then proves a passkey signed it, and it shows that passkey's public key: anyone can link every file carrying the same key. Include one only if the signer chooses to.
60
+ - Most platforms strip or re-encode what they receive, and the proof goes with it. Then look the file up by what it still is, below.
61
+ - A carried proof is a snapshot. It can't say whether the signer withdrew the record later, so `verifyFile` reports `withdrawalChecked: false`. Only the log can answer that.
62
+
63
+ ## A receipt inside the file
64
+
65
+ A record joins the log at its next checkpoint, so the moment a file is signed there is no proof yet, only the record, signed by the log's record key. A file can carry that:
66
+
67
+ ```js
68
+ import { embedReceipt, verifyFile } from "@333eco/origin-verify";
69
+ const carried = embedReceipt(fileBytes, entry); // `entry` is the signed record; refuses one for any other file
70
+ const { ok, receipt } = await verifyFile(carried, trust); // ok is FALSE; receipt is { index, witnessedAt } when its signature is good
71
+ ```
72
+
73
+ A receipt shows, with no network, that the log's record key signed for exactly this file, and when. It is not a proof that the record is in the log, so `ok` stays false. `embedPack` replaces it once the proof exists, and a receipt never replaces a proof.
74
+
47
75
  ## Honest limits
48
76
 
49
77
  - `trust.mjs` pins the log's keys and the timestamp authorities' roots. If you got this package from somewhere you don't trust, nothing here helps. npm provenance links each version to this repository's source.
@@ -51,4 +79,4 @@ Four states. Each stands alone and none implies another.
51
79
  - A Bitcoin header proves its own work, but its height is the word of whoever supplied it. The CLI asks blockstream.info; check against your own node if it matters.
52
80
  - It verifies. It never grades a person or a work, and it has no opinion on whether something is genuine.
53
81
 
54
- CC0.
82
+ Your choice of CC0-1.0 or Apache-2.0 (see `LICENSE`).
package/embed.mjs ADDED
@@ -0,0 +1,132 @@
1
+ // Carries a record's pack inside the file it describes, so the file can be checked with nothing else (founder 2026-11-08).
2
+ // The pack goes in one removable place: a private PNG chunk, or JPEG APP9 segments. Taking it out gives back the signed bytes exactly, and that is
3
+ // how a reader knows the proof belongs to this file. The picture is never touched, so `pixels` and `phash` are the same with or without it.
4
+ // ⚠️ A pack is a snapshot: it cannot say the signer did not withdraw the record later. Only the log can (`withdrawalChecked: false` in verifyFile).
5
+ import { concat, hex, sha256, text, u32, utf8 } from "./primitives.mjs";
6
+
7
+ const MAX_PACK = 8 * 1024 * 1024;
8
+ const LABEL = utf8("b-origin-pack\0");
9
+ const PNG_SIG = [137, 80, 78, 71, 13, 10, 26, 10];
10
+ // Ancillary, private, and NOT safe to copy (the last letter is upper case): an editor that changes the image and does not know this chunk must drop it.
11
+ const PNG_TYPE = utf8("orGN");
12
+ const IEND = utf8("IEND");
13
+ const JPEG_DATA = 65533 - LABEL.length - 4; // an APP segment holds 65533 bytes after its length field
14
+
15
+ const CRC = Uint32Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; });
16
+ const crc32 = (...parts) => { let c = 0xffffffff; for (const p of parts) for (let i = 0; i < p.length; i++) c = CRC[(c ^ p[i]) & 255] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; };
17
+ const same = (b, at, want) => at + want.length <= b.length && want.every((x, i) => b[at + i] === x);
18
+ const u32At = (b, at) => new DataView(b.buffer, b.byteOffset + at, 4).getUint32(0);
19
+ const u16 = (n) => new Uint8Array([n >> 8, n & 255]);
20
+ const u16At = (b, at) => (b[at] << 8) | b[at + 1];
21
+ const isPng = (b) => same(b, 0, PNG_SIG);
22
+ const isJpeg = (b) => b.length > 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff;
23
+
24
+ /** Where a PNG's chunks are, or why it can't be read. */
25
+ function pngChunks(b) {
26
+ const out = [];
27
+ for (let i = 8; i < b.length;) {
28
+ if (i + 12 > b.length) return { why: "the PNG is cut short" };
29
+ const n = u32At(b, i), end = i + 12 + n;
30
+ if (end > b.length) return { why: "the PNG is cut short" };
31
+ out.push({ at: i, end, type: b.subarray(i + 4, i + 8), data: b.subarray(i + 8, i + 8 + n), crc: u32At(b, i + 8 + n) });
32
+ if (same(b, i + 4, IEND)) return { chunks: out };
33
+ i = end;
34
+ }
35
+ return { why: "the PNG has no end" };
36
+ }
37
+ /** Our segments in a JPEG's header, in file order. Reads only up to the image data. */
38
+ function jpegOurs(b) {
39
+ const ours = [];
40
+ for (let i = 2; i + 2 <= b.length;) {
41
+ if (b[i] !== 0xff) return { why: "the JPEG's header is damaged" };
42
+ const m = b[i + 1];
43
+ if (m === 0xff) { i++; continue; }
44
+ if (m === 0xda || m === 0xd9) return { ours };
45
+ if (m === 0x01 || (m >= 0xd0 && m <= 0xd7)) { i += 2; continue; }
46
+ if (i + 4 > b.length) return { why: "the JPEG's header is damaged" };
47
+ const n = u16At(b, i + 2);
48
+ if (n < 2 || i + 2 + n > b.length) return { why: "the JPEG's header is damaged" };
49
+ if (m === 0xe9 && same(b, i + 4, LABEL)) ours.push({ at: i, end: i + 2 + n, seq: u16At(b, i + 4 + LABEL.length), total: u16At(b, i + 6 + LABEL.length), data: b.subarray(i + 8 + LABEL.length, i + 2 + n) });
50
+ i += 2 + n;
51
+ }
52
+ return { why: "the JPEG's header is damaged" };
53
+ }
54
+ const without = (b, ranges) => { const parts = []; let at = 0; for (const r of ranges) { parts.push(b.subarray(at, r.at)); at = r.end; } parts.push(b.subarray(at)); return concat(...parts); };
55
+ function parsePack(raw) {
56
+ if (raw.length > MAX_PACK) return { damaged: "the proof is too large" };
57
+ try { return { pack: JSON.parse(text(raw)) }; } catch { return { damaged: "the proof can't be read" }; }
58
+ }
59
+
60
+ /**
61
+ * The proof a file carries: null if none, { format, damaged } if it is broken, or { format, pack, original } where `original` is the file without it.
62
+ * ⛔ This only reads. Nothing here says the proof is good, or that it belongs to this file: verifyFile does.
63
+ */
64
+ export function readEmbedded(bytes) {
65
+ const b = new Uint8Array(bytes);
66
+ if (isPng(b)) {
67
+ const { chunks, why } = pngChunks(b);
68
+ if (why) return null;
69
+ const ours = chunks.filter((c) => same(c.type, 0, PNG_TYPE));
70
+ if (!ours.length) return null;
71
+ if (ours.length > 1) return { format: "png", damaged: "the file carries more than one proof" };
72
+ const [c] = ours;
73
+ if (crc32(c.type, c.data) !== c.crc) return { format: "png", damaged: "the proof was changed" };
74
+ if (!same(c.data, 0, LABEL)) return { format: "png", damaged: "the proof can't be read" };
75
+ const p = parsePack(c.data.subarray(LABEL.length));
76
+ return p.damaged ? { format: "png", ...p } : { format: "png", pack: p.pack, original: without(b, [c]) };
77
+ }
78
+ if (isJpeg(b)) {
79
+ const { ours, why } = jpegOurs(b);
80
+ if (why || !ours.length) return null;
81
+ const total = ours[0].total;
82
+ if (ours.length !== total || ours.some((s, i) => s.seq !== i || s.total !== total)) return { format: "jpeg", damaged: "part of the proof is missing" };
83
+ const p = parsePack(concat(...ours.map((s) => s.data)));
84
+ return p.damaged ? { format: "jpeg", ...p } : { format: "jpeg", pack: p.pack, original: without(b, ours) };
85
+ }
86
+ return null;
87
+ }
88
+
89
+ /**
90
+ * A copy of the file with this pack inside. Refuses a pack for any other file. A proof already there is replaced, so a pack can be renewed as it gains its clocks.
91
+ * A pack that holds an `opening` shows the passkey's public key to anyone with the file: every file that carries that opening's key can be linked to the others. That is the signer's choice to make.
92
+ */
93
+ export function embedPack(bytes, pack) {
94
+ if (pack?.kind !== "b-origin-pack" || pack.entry?.t !== "record") throw new TypeError("not a B-Origin pack for a record");
95
+ return carry(bytes, pack);
96
+ }
97
+ /**
98
+ * A copy of the file with its RECEIPT inside: the signed record itself, the moment it exists, before the log's next checkpoint can prove it is there.
99
+ * It shows the log's record key signed for exactly this file at that time. ⛔ It is not a proof: verifyFile answers `ok: false` with a `receipt`, so
100
+ * nobody mistakes one for the other. embedPack replaces it when the proof exists; a receipt never replaces a proof.
101
+ */
102
+ export function embedReceipt(bytes, entry) {
103
+ if (entry?.t !== "record" || typeof entry.witnessSig !== "string") throw new TypeError("not a signed record");
104
+ if (readEmbedded(new Uint8Array(bytes))?.pack?.kind === "b-origin-pack") throw new Error("this file already carries a proof");
105
+ return carry(bytes, { kind: "b-origin-receipt", v: 1, entry });
106
+ }
107
+ function carry(bytes, pack) {
108
+ const b = new Uint8Array(bytes), had = readEmbedded(b);
109
+ if (had?.damaged) throw new Error(`can't renew: ${had.damaged}`);
110
+ const base = had ? had.original : b;
111
+ if (hex(sha256(base)) !== pack.entry.claim?.sha256) throw new Error("this pack describes a different file");
112
+ const raw = utf8(JSON.stringify(pack));
113
+ if (raw.length > MAX_PACK) throw new Error("the pack is too large to carry");
114
+ if (isPng(base)) {
115
+ const { chunks, why } = pngChunks(base);
116
+ if (why) throw new Error(why);
117
+ const end = chunks[chunks.length - 1], data = concat(LABEL, raw);
118
+ return concat(base.subarray(0, end.at), u32(data.length), PNG_TYPE, data, u32(crc32(PNG_TYPE, data)), base.subarray(end.at));
119
+ }
120
+ if (isJpeg(base)) {
121
+ const total = Math.ceil(raw.length / JPEG_DATA);
122
+ if (total > 0xffff) throw new Error("the pack is too large to carry");
123
+ const parts = [base.subarray(0, 2)];
124
+ for (let i = 0; i < total; i++) {
125
+ const data = raw.subarray(i * JPEG_DATA, (i + 1) * JPEG_DATA);
126
+ parts.push(new Uint8Array([0xff, 0xe9]), u16(2 + LABEL.length + 4 + data.length), LABEL, u16(i), u16(total), data);
127
+ }
128
+ parts.push(base.subarray(2));
129
+ return concat(...parts);
130
+ }
131
+ throw new Error("a proof can be carried only in a PNG or a JPEG: keep the pack beside any other file");
132
+ }
package/index.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  // @333eco/origin-verify. CC0. Checks a B-Origin record with no help from its operator: no runtime dependencies, in a browser or in Node.
2
2
  // ⚠️ Written apart from the service on purpose: it shares no code with services/b, and it checks proofs with RFC 9162's
3
3
  // iterative algorithms where the service builds them with RFC 6962's recursion. One author's blind spots still apply.
4
- import { b64, b64u, concat, der, derSigToRaw, ed25519, eq, hmacSha256, sha256, text, toB64, toB64u, u32, u64, utf8 } from "./primitives.mjs";
4
+ import { b64, b64u, concat, der, derSigToRaw, ed25519, eq, hex, hmacSha256, sha256, text, toB64, toB64u, u32, u64, utf8 } from "./primitives.mjs";
5
5
  import { checkOts, checkTimestamp } from "./clocks.mjs";
6
6
  export { checkOts, checkTimestamp } from "./clocks.mjs";
7
7
  export { hashFile, decodePng, phashOf, phashDistance } from "./media.mjs";
8
+ import { readEmbedded } from "./embed.mjs";
9
+ export { embedPack, embedReceipt, readEmbedded } from "./embed.mjs";
8
10
 
9
11
  const NODE = new Uint8Array([1]), LEAF = new Uint8Array([0]);
10
12
  const odd = (n) => n % 2 === 1;
@@ -374,3 +376,24 @@ export async function verifyPack(pack, trust, { header } = {}) {
374
376
  }
375
377
  return out;
376
378
  }
379
+
380
+ /**
381
+ * Checks a file by the proof inside it, with no network. The proof counts only if taking it out gives back exactly the bytes the record names.
382
+ * ⚠️ `withdrawalChecked` is always false here: a pack is a snapshot, and whether the signer has since withdrawn the record is a question for the log (findRecords).
383
+ */
384
+ export async function verifyFile(bytes, trust, opts = {}) {
385
+ const found = readEmbedded(bytes);
386
+ if (!found) return { ok: false, embedded: false, why: "this file carries no proof" };
387
+ if (found.damaged) return { ok: false, embedded: true, why: found.damaged };
388
+ const claim = found.pack?.entry?.claim;
389
+ if (found.pack?.entry?.t !== "record" || !claim) return { ok: false, embedded: true, why: "the proof is not for a record" };
390
+ if (hex(sha256(found.original)) !== claim.sha256) return { ok: false, embedded: true, why: "this proof describes a different file" };
391
+ if (found.pack.kind === "b-origin-receipt") {
392
+ // ⛔ Never ok: a receipt says the record key signed for this file, and nothing about the log. A caller that reads only `ok` is not misled.
393
+ if (found.pack.v !== 1 || !(await checkWitnessSignature(found.pack.entry, trust))) return { ok: false, embedded: true, why: "the receipt's signature is not the log's" };
394
+ return { ok: false, embedded: true, format: found.format, claim, receipt: { index: found.pack.entry.index, witnessedAt: found.pack.entry.witnessedAt }, withdrawalChecked: false, why: "a receipt: signed by the log's record key, not yet shown to be in the log" };
395
+ }
396
+ const out = await verifyPack(found.pack, trust, opts);
397
+ if (!out.ok) return { ...out, embedded: true };
398
+ return { ...out, embedded: true, format: found.format, claim, withdrawalChecked: false };
399
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@333eco/origin-verify",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Checks a B-Origin record with no help from its operator: signatures, its place in the public log, witness cosignatures, RFC 3161 tokens, OpenTimestamps proofs against Bitcoin, and a signer's reveal. Browser or Node, no runtime dependencies.",
5
- "license": "CC0-1.0",
5
+ "license": "CC0-1.0 OR Apache-2.0",
6
6
  "author": "Thon Ly",
7
7
  "homepage": "https://github.com/333eco/origin-verify.333.eco#readme",
8
8
  "repository": {
@@ -32,10 +32,10 @@
32
32
  "primitives.mjs",
33
33
  "clocks.mjs",
34
34
  "media.mjs",
35
+ "embed.mjs",
35
36
  "trust.mjs",
36
37
  "cli.mjs",
37
- "README.md"
38
- ],
38
+ "README.md", "LICENSE", "LICENSE-CC0", "LICENSE-APACHE"],
39
39
  "bin": {
40
40
  "origin-verify": "./cli.mjs"
41
41
  },