iricity-frontier-shared 0.5.0__tar.gz
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.
- iricity_frontier_shared-0.5.0/LICENSE +178 -0
- iricity_frontier_shared-0.5.0/PKG-INFO +118 -0
- iricity_frontier_shared-0.5.0/README.md +90 -0
- iricity_frontier_shared-0.5.0/pyproject.toml +50 -0
- iricity_frontier_shared-0.5.0/setup.cfg +4 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/__init__.py +128 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/base58.py +47 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/canonical.py +131 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/conformance.py +267 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/credential.py +306 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/envelope.py +228 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/hashing.py +52 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/keys.py +235 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/receipt.py +277 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/vectors/v3/vectors.json +2114 -0
- iricity_frontier_shared-0.5.0/src/frontier_shared/vectors/v3/vectors.lock.json +5 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/PKG-INFO +118 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/SOURCES.txt +23 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/dependency_links.txt +1 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/entry_points.txt +2 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/requires.txt +4 -0
- iricity_frontier_shared-0.5.0/src/iricity_frontier_shared.egg-info/top_level.txt +1 -0
- iricity_frontier_shared-0.5.0/tests/test_conformance.py +33 -0
- iricity_frontier_shared-0.5.0/tests/test_credential.py +90 -0
- iricity_frontier_shared-0.5.0/tests/test_primitives.py +194 -0
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
Copyright 2026 Iricity Leadership Private Limited (OPC)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iricity-frontier-shared
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Python implementation of the Frontier State Protocol primitives: RFC 8785 canonical JSON, SHA-256 hashing, ed25519 identity as did:key, signed envelopes, signed receipt chains and regulator-issued authorization credentials (eddsa-jcs-2022), verified against the published conformance vectors.
|
|
5
|
+
Author: Iricity Leadership Private Limited
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/iricity/iricity-frontier-shared-py
|
|
8
|
+
Project-URL: Vectors, https://github.com/iricity/iricity-frontier-shared
|
|
9
|
+
Keywords: canonical-json,rfc8785,ed25519,did-key,receipts,provenance,space
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: cryptography>=42
|
|
25
|
+
Provides-Extra: test
|
|
26
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# frontier-shared (Python)
|
|
30
|
+
|
|
31
|
+
Python implementation of the Frontier State Protocol primitives, byte-for-byte compatible with the JavaScript reference `@iricity/frontier-shared`. Its purpose is to prove that the specification is portable: it passes the published conformance vectors with no suite skipped.
|
|
32
|
+
|
|
33
|
+
| Module | Provides | Standard |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `frontier_shared.canonical` | `canonical_json`, `format_number` | RFC 8785, ECMAScript number formatting |
|
|
36
|
+
| `frontier_shared.hashing` | `hash_payload`, `hash_record`, `hash_text`, `hash_bytes`, `sha256_hex` | SHA-256 over canonical JSON, `sha256:` prefixed hex |
|
|
37
|
+
| `frontier_shared.base58` | `base58_encode`, `base58_decode` | base58btc, multibase `z` |
|
|
38
|
+
| `frontier_shared.keys` | `KeyPair`, `did_from_public_key_bytes`, `sign_bytes`, `verify_bytes` | W3C did:key, RFC 8032 Ed25519 |
|
|
39
|
+
| `frontier_shared.envelope` | `create_envelope`, `verify_envelope` | `state-envelope/1` |
|
|
40
|
+
| `frontier_shared.receipt` | `create_receipt_record`, `verify_receipt_record`, `verify_receipt_chain` | `state-receipt/1` |
|
|
41
|
+
| `frontier_shared.credential` | `issue_authorization_credential`, `verify_credential`, `verify_authorization_credential`, `credential_hash_data` | regulator-issued authorizations: W3C Verifiable Credentials with an `eddsa-jcs-2022` Data Integrity proof |
|
|
42
|
+
| `frontier_shared.conformance` | `run_conformance`, console script `frontier-shared-conformance` | vectors version 3, nine suites |
|
|
43
|
+
|
|
44
|
+
Only runtime dependency: `cryptography`.
|
|
45
|
+
|
|
46
|
+
## Install and verify
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
pip install iricity-frontier-shared
|
|
50
|
+
frontier-shared-conformance
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
conformance vectors 2: 60 passed, 0 failed, 0 skipped
|
|
55
|
+
RESULT: conformant
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Pass a path to run against a different vectors file, for example the one in the JavaScript repository:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
frontier-shared-conformance ../iricity-frontier-shared/conformance/vectors.json
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Use
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from frontier_shared import KeyPair, create_envelope, verify_envelope, create_receipt_record, verify_receipt_chain
|
|
68
|
+
|
|
69
|
+
node = KeyPair.generate()
|
|
70
|
+
envelope = create_envelope(omm, "ccsds.omm.json/1", node)
|
|
71
|
+
verify_envelope(envelope) # {'verified': True, 'signer': 'did:key:z6Mk…', ...}
|
|
72
|
+
|
|
73
|
+
first = create_receipt_record(record=record, issuer=node)
|
|
74
|
+
second = create_receipt_record(record=next_record, previous_hash=first["receipt_hash"], issuer=node)
|
|
75
|
+
verify_receipt_chain([first, second], require_genesis=True)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Objects produced here verify in the JavaScript implementation and vice versa; the vectors pin the signing inputs, hashes and encodings on both sides, and 26 rejection vectors pin what both verifiers must refuse. Verifiers never raise on malformed input; every problem is an entry in `errors`.
|
|
79
|
+
|
|
80
|
+
## Where the traps were
|
|
81
|
+
|
|
82
|
+
Four places decide whether a second implementation matches the bytes, and all four are covered by vectors:
|
|
83
|
+
|
|
84
|
+
1. **Numbers.** RFC 8785 uses the ECMAScript Number-to-string algorithm (`1e+21`, `1e-7`, `123456789012345680000`, `-0` as `0`), and every JSON number is a double, so an integer literal at or above 2**53 rounds the way JavaScript rounds it. `format_number` implements both from the shortest round-trip digits.
|
|
85
|
+
2. **Strings.** Only `"`, `\`, control characters below U+0020 and lone surrogates are escaped; `/` and non-ASCII are not.
|
|
86
|
+
3. **Key order.** Object members sort by UTF-16 code units, not code points. The vector with a supplementary-plane key exists for this.
|
|
87
|
+
4. **Signing inputs.** Domain tag plus canonical JSON of the header (envelopes) or the core fields (receipts), nothing else.
|
|
88
|
+
|
|
89
|
+
## Credentials
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from frontier_shared import KeyPair, issue_authorization_credential, verify_credential, verify_authorization_credential
|
|
93
|
+
|
|
94
|
+
regulator = KeyPair.generate()
|
|
95
|
+
credential = issue_authorization_credential(
|
|
96
|
+
{"subject_id": "station_vu2abc", "capability": "transmit", "jurisdiction": "IN",
|
|
97
|
+
"bands": [{"lower_hz": 144_000_000, "upper_hz": 146_000_000, "service": "amateur"}],
|
|
98
|
+
"max_eirp_dbw": 20, "valid_from": "2026-01-01T00:00:00.000Z", "valid_until": "2031-01-01T00:00:00.000Z"},
|
|
99
|
+
regulator,
|
|
100
|
+
)
|
|
101
|
+
verify_credential(credential, at="2027-01-01T00:00:00Z")["verified"] # True
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A credential issued here verifies in the JavaScript reference and the reverse; the `credential` suite of vectors version 3 pins the proof values byte for byte. `verify_authorization_credential(record, at=...)` binds a `regulator_issued` authorization record to the credential it carries. This package verifies and issues credentials; building the authorization record itself (its derived `authorization_id`) is done with the JavaScript constructors or by the registry.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
pip install -e .[test]
|
|
110
|
+
pytest
|
|
111
|
+
python -m frontier_shared.conformance
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Vectors are vendored under `src/frontier_shared/vectors/v3/` with the lock file from the JavaScript repository; a test fails if the copy drifts from the lock. A new vectors version is a new directory.
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
Apache-2.0.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frontier-shared (Python)
|
|
2
|
+
|
|
3
|
+
Python implementation of the Frontier State Protocol primitives, byte-for-byte compatible with the JavaScript reference `@iricity/frontier-shared`. Its purpose is to prove that the specification is portable: it passes the published conformance vectors with no suite skipped.
|
|
4
|
+
|
|
5
|
+
| Module | Provides | Standard |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| `frontier_shared.canonical` | `canonical_json`, `format_number` | RFC 8785, ECMAScript number formatting |
|
|
8
|
+
| `frontier_shared.hashing` | `hash_payload`, `hash_record`, `hash_text`, `hash_bytes`, `sha256_hex` | SHA-256 over canonical JSON, `sha256:` prefixed hex |
|
|
9
|
+
| `frontier_shared.base58` | `base58_encode`, `base58_decode` | base58btc, multibase `z` |
|
|
10
|
+
| `frontier_shared.keys` | `KeyPair`, `did_from_public_key_bytes`, `sign_bytes`, `verify_bytes` | W3C did:key, RFC 8032 Ed25519 |
|
|
11
|
+
| `frontier_shared.envelope` | `create_envelope`, `verify_envelope` | `state-envelope/1` |
|
|
12
|
+
| `frontier_shared.receipt` | `create_receipt_record`, `verify_receipt_record`, `verify_receipt_chain` | `state-receipt/1` |
|
|
13
|
+
| `frontier_shared.credential` | `issue_authorization_credential`, `verify_credential`, `verify_authorization_credential`, `credential_hash_data` | regulator-issued authorizations: W3C Verifiable Credentials with an `eddsa-jcs-2022` Data Integrity proof |
|
|
14
|
+
| `frontier_shared.conformance` | `run_conformance`, console script `frontier-shared-conformance` | vectors version 3, nine suites |
|
|
15
|
+
|
|
16
|
+
Only runtime dependency: `cryptography`.
|
|
17
|
+
|
|
18
|
+
## Install and verify
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
pip install iricity-frontier-shared
|
|
22
|
+
frontier-shared-conformance
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
conformance vectors 2: 60 passed, 0 failed, 0 skipped
|
|
27
|
+
RESULT: conformant
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Pass a path to run against a different vectors file, for example the one in the JavaScript repository:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
frontier-shared-conformance ../iricity-frontier-shared/conformance/vectors.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Use
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from frontier_shared import KeyPair, create_envelope, verify_envelope, create_receipt_record, verify_receipt_chain
|
|
40
|
+
|
|
41
|
+
node = KeyPair.generate()
|
|
42
|
+
envelope = create_envelope(omm, "ccsds.omm.json/1", node)
|
|
43
|
+
verify_envelope(envelope) # {'verified': True, 'signer': 'did:key:z6Mk…', ...}
|
|
44
|
+
|
|
45
|
+
first = create_receipt_record(record=record, issuer=node)
|
|
46
|
+
second = create_receipt_record(record=next_record, previous_hash=first["receipt_hash"], issuer=node)
|
|
47
|
+
verify_receipt_chain([first, second], require_genesis=True)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Objects produced here verify in the JavaScript implementation and vice versa; the vectors pin the signing inputs, hashes and encodings on both sides, and 26 rejection vectors pin what both verifiers must refuse. Verifiers never raise on malformed input; every problem is an entry in `errors`.
|
|
51
|
+
|
|
52
|
+
## Where the traps were
|
|
53
|
+
|
|
54
|
+
Four places decide whether a second implementation matches the bytes, and all four are covered by vectors:
|
|
55
|
+
|
|
56
|
+
1. **Numbers.** RFC 8785 uses the ECMAScript Number-to-string algorithm (`1e+21`, `1e-7`, `123456789012345680000`, `-0` as `0`), and every JSON number is a double, so an integer literal at or above 2**53 rounds the way JavaScript rounds it. `format_number` implements both from the shortest round-trip digits.
|
|
57
|
+
2. **Strings.** Only `"`, `\`, control characters below U+0020 and lone surrogates are escaped; `/` and non-ASCII are not.
|
|
58
|
+
3. **Key order.** Object members sort by UTF-16 code units, not code points. The vector with a supplementary-plane key exists for this.
|
|
59
|
+
4. **Signing inputs.** Domain tag plus canonical JSON of the header (envelopes) or the core fields (receipts), nothing else.
|
|
60
|
+
|
|
61
|
+
## Credentials
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from frontier_shared import KeyPair, issue_authorization_credential, verify_credential, verify_authorization_credential
|
|
65
|
+
|
|
66
|
+
regulator = KeyPair.generate()
|
|
67
|
+
credential = issue_authorization_credential(
|
|
68
|
+
{"subject_id": "station_vu2abc", "capability": "transmit", "jurisdiction": "IN",
|
|
69
|
+
"bands": [{"lower_hz": 144_000_000, "upper_hz": 146_000_000, "service": "amateur"}],
|
|
70
|
+
"max_eirp_dbw": 20, "valid_from": "2026-01-01T00:00:00.000Z", "valid_until": "2031-01-01T00:00:00.000Z"},
|
|
71
|
+
regulator,
|
|
72
|
+
)
|
|
73
|
+
verify_credential(credential, at="2027-01-01T00:00:00Z")["verified"] # True
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A credential issued here verifies in the JavaScript reference and the reverse; the `credential` suite of vectors version 3 pins the proof values byte for byte. `verify_authorization_credential(record, at=...)` binds a `regulator_issued` authorization record to the credential it carries. This package verifies and issues credentials; building the authorization record itself (its derived `authorization_id`) is done with the JavaScript constructors or by the registry.
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
pip install -e .[test]
|
|
82
|
+
pytest
|
|
83
|
+
python -m frontier_shared.conformance
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Vectors are vendored under `src/frontier_shared/vectors/v3/` with the lock file from the JavaScript repository; a test fails if the copy drifts from the lock. A new vectors version is a new directory.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
Apache-2.0.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "iricity-frontier-shared"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "Python implementation of the Frontier State Protocol primitives: RFC 8785 canonical JSON, SHA-256 hashing, ed25519 identity as did:key, signed envelopes, signed receipt chains and regulator-issued authorization credentials (eddsa-jcs-2022), verified against the published conformance vectors."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Iricity Leadership Private Limited" }]
|
|
14
|
+
keywords = ["canonical-json", "rfc8785", "ed25519", "did-key", "receipts", "provenance", "space"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Topic :: Security :: Cryptography",
|
|
26
|
+
"Topic :: Scientific/Engineering",
|
|
27
|
+
]
|
|
28
|
+
dependencies = ["cryptography>=42"]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
test = ["pytest>=8"]
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
frontier-shared-conformance = "frontier_shared.conformance:main"
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/iricity/iricity-frontier-shared-py"
|
|
38
|
+
Vectors = "https://github.com/iricity/iricity-frontier-shared"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
package-dir = { "" = "src" }
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.package-data]
|
|
47
|
+
frontier_shared = ["vectors/v3/*.json"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Frontier State Protocol primitives, Python implementation.
|
|
2
|
+
|
|
3
|
+
Byte-for-byte compatible with the JavaScript reference (`@iricity/frontier-shared`),
|
|
4
|
+
proven by the shared conformance vectors in ``frontier_shared/vectors``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .base58 import base58_decode, base58_encode, multibase_decode_base58btc, multibase_encode_base58btc
|
|
8
|
+
from .canonical import MAX_DEPTH, canonical_json, format_number
|
|
9
|
+
from .credential import (
|
|
10
|
+
AUTHORIZATION_CREDENTIAL_TYPE,
|
|
11
|
+
AUTHORIZATION_VOCAB,
|
|
12
|
+
CREDENTIAL_CONTEXT_V2,
|
|
13
|
+
CREDENTIAL_SUBJECT_FIELDS,
|
|
14
|
+
CRYPTOSUITE,
|
|
15
|
+
DATA_INTEGRITY_PROOF,
|
|
16
|
+
PROOF_PURPOSE,
|
|
17
|
+
credential_hash_data,
|
|
18
|
+
credential_subject_from_authorization,
|
|
19
|
+
issue_authorization_credential,
|
|
20
|
+
verify_authorization_credential,
|
|
21
|
+
verify_credential,
|
|
22
|
+
)
|
|
23
|
+
from .envelope import (
|
|
24
|
+
ENVELOPE_DOMAIN_TAG,
|
|
25
|
+
ENVELOPE_VERSION,
|
|
26
|
+
TIMESTAMP_PATTERN,
|
|
27
|
+
create_envelope,
|
|
28
|
+
envelope_hash,
|
|
29
|
+
envelope_header,
|
|
30
|
+
envelope_id_from_hash,
|
|
31
|
+
envelope_signing_input,
|
|
32
|
+
is_timestamp,
|
|
33
|
+
verify_envelope,
|
|
34
|
+
)
|
|
35
|
+
from .hashing import HASH_PREFIX, hash_bytes, hash_payload, hash_record, hash_text, is_hash_ref, sha256_hex, sha256_hex_bytes
|
|
36
|
+
from .keys import (
|
|
37
|
+
ED25519_MULTICODEC_PREFIX,
|
|
38
|
+
KeyPair,
|
|
39
|
+
decode_signature,
|
|
40
|
+
did_from_public_key_bytes,
|
|
41
|
+
encode_signature,
|
|
42
|
+
fingerprint_did,
|
|
43
|
+
is_did_key,
|
|
44
|
+
is_valid_signature_text,
|
|
45
|
+
public_key_bytes_from_did,
|
|
46
|
+
public_key_multibase_from_did,
|
|
47
|
+
resolve_signer,
|
|
48
|
+
sign_bytes,
|
|
49
|
+
verify_bytes,
|
|
50
|
+
)
|
|
51
|
+
from .receipt import (
|
|
52
|
+
RECEIPT_DOMAIN_TAG,
|
|
53
|
+
RECEIPT_SIGNATURE_ALGORITHMS,
|
|
54
|
+
RECEIPT_VERSION,
|
|
55
|
+
compute_receipt_hash,
|
|
56
|
+
create_receipt_record,
|
|
57
|
+
derive_receipt_id,
|
|
58
|
+
receipt_core,
|
|
59
|
+
receipt_signing_input,
|
|
60
|
+
verify_receipt_chain,
|
|
61
|
+
verify_receipt_record,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
__version__ = "0.5.0"
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
"__version__",
|
|
68
|
+
"issue_authorization_credential",
|
|
69
|
+
"verify_credential",
|
|
70
|
+
"verify_authorization_credential",
|
|
71
|
+
"credential_hash_data",
|
|
72
|
+
"credential_subject_from_authorization",
|
|
73
|
+
"CREDENTIAL_CONTEXT_V2",
|
|
74
|
+
"AUTHORIZATION_VOCAB",
|
|
75
|
+
"AUTHORIZATION_CREDENTIAL_TYPE",
|
|
76
|
+
"CREDENTIAL_SUBJECT_FIELDS",
|
|
77
|
+
"CRYPTOSUITE",
|
|
78
|
+
"DATA_INTEGRITY_PROOF",
|
|
79
|
+
"PROOF_PURPOSE",
|
|
80
|
+
"canonical_json",
|
|
81
|
+
"format_number",
|
|
82
|
+
"MAX_DEPTH",
|
|
83
|
+
"hash_text",
|
|
84
|
+
"is_valid_signature_text",
|
|
85
|
+
"is_timestamp",
|
|
86
|
+
"TIMESTAMP_PATTERN",
|
|
87
|
+
"envelope_id_from_hash",
|
|
88
|
+
"derive_receipt_id",
|
|
89
|
+
"HASH_PREFIX",
|
|
90
|
+
"sha256_hex",
|
|
91
|
+
"sha256_hex_bytes",
|
|
92
|
+
"hash_payload",
|
|
93
|
+
"hash_bytes",
|
|
94
|
+
"hash_record",
|
|
95
|
+
"is_hash_ref",
|
|
96
|
+
"base58_encode",
|
|
97
|
+
"base58_decode",
|
|
98
|
+
"multibase_encode_base58btc",
|
|
99
|
+
"multibase_decode_base58btc",
|
|
100
|
+
"ED25519_MULTICODEC_PREFIX",
|
|
101
|
+
"KeyPair",
|
|
102
|
+
"resolve_signer",
|
|
103
|
+
"did_from_public_key_bytes",
|
|
104
|
+
"public_key_bytes_from_did",
|
|
105
|
+
"public_key_multibase_from_did",
|
|
106
|
+
"is_did_key",
|
|
107
|
+
"fingerprint_did",
|
|
108
|
+
"sign_bytes",
|
|
109
|
+
"verify_bytes",
|
|
110
|
+
"encode_signature",
|
|
111
|
+
"decode_signature",
|
|
112
|
+
"ENVELOPE_VERSION",
|
|
113
|
+
"ENVELOPE_DOMAIN_TAG",
|
|
114
|
+
"create_envelope",
|
|
115
|
+
"verify_envelope",
|
|
116
|
+
"envelope_header",
|
|
117
|
+
"envelope_hash",
|
|
118
|
+
"envelope_signing_input",
|
|
119
|
+
"RECEIPT_VERSION",
|
|
120
|
+
"RECEIPT_DOMAIN_TAG",
|
|
121
|
+
"RECEIPT_SIGNATURE_ALGORITHMS",
|
|
122
|
+
"create_receipt_record",
|
|
123
|
+
"verify_receipt_record",
|
|
124
|
+
"verify_receipt_chain",
|
|
125
|
+
"receipt_core",
|
|
126
|
+
"receipt_signing_input",
|
|
127
|
+
"compute_receipt_hash",
|
|
128
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Base58btc (Bitcoin alphabet), as used by multibase prefix 'z'."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = ["base58_encode", "base58_decode", "multibase_encode_base58btc", "multibase_decode_base58btc"]
|
|
6
|
+
|
|
7
|
+
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
8
|
+
_INDEX = {char: index for index, char in enumerate(ALPHABET)}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def base58_encode(data: bytes) -> str:
|
|
12
|
+
data = bytes(data)
|
|
13
|
+
if not data:
|
|
14
|
+
return ""
|
|
15
|
+
value = int.from_bytes(data, "big")
|
|
16
|
+
encoded = ""
|
|
17
|
+
while value > 0:
|
|
18
|
+
value, remainder = divmod(value, 58)
|
|
19
|
+
encoded = ALPHABET[remainder] + encoded
|
|
20
|
+
leading = len(data) - len(data.lstrip(b"\x00"))
|
|
21
|
+
return "1" * leading + encoded
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def base58_decode(text: str) -> bytes:
|
|
25
|
+
if not isinstance(text, str):
|
|
26
|
+
raise TypeError("base58_decode expects a string")
|
|
27
|
+
if text == "":
|
|
28
|
+
return b""
|
|
29
|
+
value = 0
|
|
30
|
+
for char in text:
|
|
31
|
+
digit = _INDEX.get(char)
|
|
32
|
+
if digit is None:
|
|
33
|
+
raise ValueError(f"base58_decode: invalid character {char!r}")
|
|
34
|
+
value = value * 58 + digit
|
|
35
|
+
body = b"" if value == 0 else value.to_bytes((value.bit_length() + 7) // 8, "big")
|
|
36
|
+
leading = len(text) - len(text.lstrip("1"))
|
|
37
|
+
return b"\x00" * leading + body
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def multibase_encode_base58btc(data: bytes) -> str:
|
|
41
|
+
return "z" + base58_encode(data)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def multibase_decode_base58btc(text: str) -> bytes:
|
|
45
|
+
if not isinstance(text, str) or not text.startswith("z"):
|
|
46
|
+
raise ValueError('expected a multibase base58btc string starting with "z"')
|
|
47
|
+
return base58_decode(text[1:])
|