@aicent/rttp 0.1.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 +201 -0
- package/README.md +238 -0
- package/bin/rttp.mjs +85 -0
- package/package.json +54 -0
- package/src/conformance.d.mts +108 -0
- package/src/conformance.mjs +243 -0
- package/src/rttp-uri.d.mts +70 -0
- package/src/rttp-uri.mjs +322 -0
- package/src/vectors.json +198 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 2013-2019 Nikolay Kim and Andrew Svetlov
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# @aicent/rttp
|
|
2
|
+
|
|
3
|
+
**RTTP for JavaScript: `rttp://` intent addressing, `ROUTE_SHARD` derivation —
|
|
4
|
+
and the published conformance vectors that prove an implementation is right.**
|
|
5
|
+
|
|
6
|
+
[RFC-002 §10](https://rttp.com/RFC-002/) · v1.2.6 · zero dependencies · no build step
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Verify it in one command — no trust required
|
|
11
|
+
|
|
12
|
+
```console
|
|
13
|
+
$ npx @aicent/rttp
|
|
14
|
+
[PASS] all 25 checks passed (node, independent implementation)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
That is the point of this package. A specification is worth exactly what an
|
|
18
|
+
independent implementation can reproduce from it, so instead of asking you to
|
|
19
|
+
believe a table of numbers, the vectors ship inside the package and replay
|
|
20
|
+
locally — offline, no account, no network. `[PASS]` or it is not.
|
|
21
|
+
|
|
22
|
+
The JavaScript and Python sides **share no code**. They are separate
|
|
23
|
+
implementations of the same published vectors, and they agree byte for byte.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```console
|
|
30
|
+
npm install @aicent/rttp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Node 18+. No dependencies, no build step, no transitive tree to audit: the
|
|
34
|
+
published `src/` is exactly what runs.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Quickstart
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { parse } from '@aicent/rttp';
|
|
42
|
+
|
|
43
|
+
const r = parse('rttp://brain.epoekie.aicent/verify');
|
|
44
|
+
|
|
45
|
+
r.authority // 'brain.epoekie.aicent'
|
|
46
|
+
r.intent // 'brain'
|
|
47
|
+
r.pillar // 'epoekie'
|
|
48
|
+
r.root // 'aicent'
|
|
49
|
+
r.action // 'verify'
|
|
50
|
+
r.canonical_uri // 'rttp://brain.epoekie.aicent/verify'
|
|
51
|
+
r.route_shard_hex // '459e543b73d86005b72ba77d5756e83c' <- pure computation
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Addressing is **DNS-free** (RFC-002 §10.5): the routing hash is derived from the
|
|
55
|
+
authority by SHA-256, so no registry, resolver or network is involved. A URI
|
|
56
|
+
either yields a shard or throws — there is no fallback, and no `rttps`.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## The one rule that surprises people
|
|
61
|
+
|
|
62
|
+
**Malformed input is rejected, not normalised.** `rttp://…/VESSEL` and
|
|
63
|
+
`rttp://F3B2A1C4.…/vessel` both throw, because the canonical form is lowercase
|
|
64
|
+
US-ASCII (RFC-002 §10.3) and a case variant is not a spelling difference — it is
|
|
65
|
+
a *different string*. Admitting both would give one address two spellings, which
|
|
66
|
+
is the ambiguity §10.3 exists to remove.
|
|
67
|
+
|
|
68
|
+
Nothing here is ever accepted because a check could not be performed: this
|
|
69
|
+
package fails closed everywhere.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## The address and the prefix are different things
|
|
74
|
+
|
|
75
|
+
A user agent accepts `navigator.registerProtocolHandler()` only for schemes on its
|
|
76
|
+
own safelisted set, or for a scheme beginning `web+`. So a **web page** must use
|
|
77
|
+
the `web+rttp:` prefix to register a handler (RFC-002 §10.6) — but that prefix
|
|
78
|
+
describes the **client**, never the target.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
parse('web+rttp://logic.zcmk.aicent/pulse').canonical_uri
|
|
82
|
+
// 'rttp://logic.zcmk.aicent/pulse' <- always the canonical form, either way
|
|
83
|
+
|
|
84
|
+
parse('web+rttp://logic.zcmk.aicent/pulse').route_shard_hex
|
|
85
|
+
=== parse('rttp://logic.zcmk.aicent/pulse').route_shard_hex
|
|
86
|
+
// true - same authority, same path, same shard
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The output `scheme` field tells you which form arrived; everything else is
|
|
90
|
+
identical.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## API — main entry
|
|
95
|
+
|
|
96
|
+
| Export | What it does |
|
|
97
|
+
|:---|:---|
|
|
98
|
+
| `parse(uri)` | Validate, canonicalise, derive. Throws `RttpUriError`. |
|
|
99
|
+
| `parseAndDerive(uri)` | Identical to `parse`; the specification's own wording. |
|
|
100
|
+
| `deriveRouteShard(authority)` | `Uint8Array(16)` = `SHA-256(ASCII(authority))[0:16]`. |
|
|
101
|
+
| `deriveRouteShardHex(authority)` | The same, as 32 lowercase hex characters. |
|
|
102
|
+
| `isValidAction(value)` | §10.2 `action` form test. The verb set is **open**. |
|
|
103
|
+
| `RttpUriError` | The only error type thrown. |
|
|
104
|
+
| `SCHEME`, `BROWSER_HANDLER_SCHEME`, `ROUTE_SHARD_BYTES`, `HASH_INTENT_LEN`, `ACTION_MAX_LEN`, `SPEC_RELEASE` | Constants. |
|
|
105
|
+
|
|
106
|
+
### Returned fields
|
|
107
|
+
|
|
108
|
+
Field names are `snake_case` **on purpose**: the published conformance vectors use
|
|
109
|
+
those names, so this output and the Python package's output compare directly —
|
|
110
|
+
field for field, byte for byte.
|
|
111
|
+
|
|
112
|
+
| Field | Meaning |
|
|
113
|
+
|:---|:---|
|
|
114
|
+
| `scheme` | `rttp` or `web+rttp` — which form arrived |
|
|
115
|
+
| `intent` | 8 lowercase hex digits (32-bit routing hash) or a readable organ token |
|
|
116
|
+
| `intent_is_hash` / `intent_hash32` | Whether it is a hash-intent, and its value |
|
|
117
|
+
| `pillar`, `root` | The other two authority labels |
|
|
118
|
+
| `action` | Empty string when omitted (RFC-002 §10.4 default operation) |
|
|
119
|
+
| `action_omitted` | The same fact as a boolean |
|
|
120
|
+
| `authority` | `<intent>.<pillar>.<root>`, canonical |
|
|
121
|
+
| `canonical_uri` | Always begins `rttp://` |
|
|
122
|
+
| `route_shard` / `route_shard_hex` | The 16-byte routing hash, two ways |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## The conformance vectors — `@aicent/rttp/conformance`
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import { loadVectors, runConformance } from '@aicent/rttp/conformance';
|
|
130
|
+
|
|
131
|
+
const { checked, failures, passed } = runConformance(loadVectors());
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Or from the command line:
|
|
135
|
+
|
|
136
|
+
```console
|
|
137
|
+
npx @aicent/rttp # replay the shipped vectors
|
|
138
|
+
npx @aicent/rttp --vectors ./new.json # replay a different vector set
|
|
139
|
+
npx @aicent/rttp --json # machine-readable output
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
In CI:
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
- run: npx @aicent/rttp
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
| Export | What it does |
|
|
149
|
+
|:---|:---|
|
|
150
|
+
| `runConformance(vectors)` | Replay a vector set → `{ checked, failures, passed }` |
|
|
151
|
+
| `loadVectors(path?)` | Parse a vector set; defaults to the shipped one |
|
|
152
|
+
| `DEFAULT_VECTORS_PATH` | Absolute path of the shipped `vectors.json` |
|
|
153
|
+
| `parseUri(uri)` | The independent RFC-002 §10.2 implementation → `{ authority, action, shardHex }` |
|
|
154
|
+
| `buildFrame(fields)` | The independent 128-byte frame builder → `Buffer` |
|
|
155
|
+
| `ACTION_MAX_LEN` | `16` — the ACTION field's capacity |
|
|
156
|
+
|
|
157
|
+
`vectors.json` is plain JSON and ships inside the package, also reachable as the
|
|
158
|
+
subpath export `@aicent/rttp/vectors.json`. Any language can read it; that is
|
|
159
|
+
what it is for.
|
|
160
|
+
|
|
161
|
+
### What the 25 checks are
|
|
162
|
+
|
|
163
|
+
| Group | Count | What it proves |
|
|
164
|
+
|:---|:---|---:|
|
|
165
|
+
| `positive_uris` | 6 | Accept, canonicalise and derive — including a hash-intent, an omitted action, and the browser-handler prefix |
|
|
166
|
+
| `negative_uris` | 15 | **Reject** — uppercase, userinfo, query, fragment, port, multi-segment path, wrong authority shape, trailing slash, foreign scheme, surrounding whitespace |
|
|
167
|
+
| `frame_vectors` | 3 | URI → `ROUTE_SHARD` → the 128-byte `PulseHeader128`, bit for bit |
|
|
168
|
+
| `compat_vector_spec_rev_0` | 1 | A frame written before the v1.2.6 extension block still verifies |
|
|
169
|
+
|
|
170
|
+
Each vector is deterministic: fixed sequence numbers, fixed timestamp, fixed AID.
|
|
171
|
+
Two implementations either agree byte for byte or they do not.
|
|
172
|
+
|
|
173
|
+
### Why the checker lives in this package, and why that is still honest
|
|
174
|
+
|
|
175
|
+
`src/conformance.mjs` is written from RFC-002 §10.2 alone and **must never import
|
|
176
|
+
`src/rttp-uri.mjs`**. A conformance suite that reuses the code under test only
|
|
177
|
+
proves the code equals itself. The two files share no code, so the rule is
|
|
178
|
+
checkable by reading them.
|
|
179
|
+
|
|
180
|
+
They ship together for the same reason the Python wheel ships its self-test: so
|
|
181
|
+
that a stranger can verify an installed package **offline, with no repository
|
|
182
|
+
checkout**. A verification step that requires cloning an unrelated repository is
|
|
183
|
+
not a verification step.
|
|
184
|
+
|
|
185
|
+
`buildFrame` **refuses** an action longer than the field can hold rather than
|
|
186
|
+
truncating it: a silently shortened verb would be a routing decision made by the
|
|
187
|
+
codec, and the codec does not get to make that decision. (§10.2 sets no length
|
|
188
|
+
limit on `action` — a *parser* must accept a long one; a frame builder cannot.)
|
|
189
|
+
|
|
190
|
+
The vectors are **generated, not written**. `generated_by` in the JSON names the
|
|
191
|
+
generator, and the file says so itself: change the cases in the generator, not the
|
|
192
|
+
JSON. Hand-editing a conformance vector is how a specification quietly starts
|
|
193
|
+
agreeing with its own bugs.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Scope — what this package is not
|
|
198
|
+
|
|
199
|
+
| | |
|
|
200
|
+
|:---|:---|
|
|
201
|
+
| ✅ **Validation** | Real, and specified (RFC-002 §10.2 / §10.3). |
|
|
202
|
+
| ✅ **Canonicalisation** | Real, and specified. |
|
|
203
|
+
| ✅ **ROUTE_SHARD derivation** | Real, and specified. |
|
|
204
|
+
| ✅ **Conformance vectors + independent replay** | Published and generated. |
|
|
205
|
+
| ❌ **Framing, as a library API** | `buildFrame` is exported from `./conformance`, where it exists to replay frame vectors — it is not offered as a general codec. |
|
|
206
|
+
| ❌ **Transport** | Not here. There is no `send()`. |
|
|
207
|
+
| ❌ **Routing service** | Not here. The shard is computed locally; delivering a frame to that hash is an operator's job. |
|
|
208
|
+
| ❌ **Sealing (§11)** | Separate artifacts. |
|
|
209
|
+
| ❌ **Browsers** | Node only — it uses `node:crypto`. The derivation is trivial to reproduce elsewhere, and the vectors let you prove you did. |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Naming
|
|
214
|
+
|
|
215
|
+
| Ecosystem | Name | Status |
|
|
216
|
+
|:---|:---|:---|
|
|
217
|
+
| crates.io | `rttp` | held by this project |
|
|
218
|
+
| PyPI | `rttp` | the Python reference implementation |
|
|
219
|
+
| npm | **`@aicent/rttp`** | the bare `rttp` name on npm is held by an unrelated, unmaintained 2017 REST helper, and the `rttp` scope cannot be created at all — a personal account already holds that name. This package is therefore published under the organization this project controls; the package name itself is still just `rttp`. |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Specification status
|
|
224
|
+
|
|
225
|
+
* **`rttp` URI scheme** — submitted to IANA under RFC 7595, ticket **#1459939**,
|
|
226
|
+
Provisional, **under review**. It is **not yet registered** — as of 2026-09-17
|
|
227
|
+
the IANA "URI Schemes" registry contains no `rttp` entry. Please describe it
|
|
228
|
+
that way.
|
|
229
|
+
* **Frame layout** — RFC-002 §4.1, extended by `SPEC/RTTP-FRAME-EXT-v1.2.6.md`.
|
|
230
|
+
|
|
231
|
+
Where this package and the specification disagree, **the specification wins and
|
|
232
|
+
this package is wrong.** Please report it.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## License
|
|
237
|
+
|
|
238
|
+
Apache-2.0. See `LICENSE`.
|
package/bin/rttp.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* rttp - replay the RTTP conformance vectors.
|
|
4
|
+
*
|
|
5
|
+
* npx @aicent/rttp
|
|
6
|
+
* rttp --vectors ./newer-vectors.json
|
|
7
|
+
* rttp --json
|
|
8
|
+
*
|
|
9
|
+
* Exit status is 0 only when every check passes: `[PASS]` or it is not.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { DEFAULT_VECTORS_PATH, loadVectors, runConformance } from '../src/conformance.mjs';
|
|
13
|
+
|
|
14
|
+
const USAGE = `rttp - replay the RTTP conformance vectors
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
rttp [--vectors <file>] [--json] [--help]
|
|
18
|
+
|
|
19
|
+
Options:
|
|
20
|
+
--vectors <file> replay a different vector set (default: the one shipped
|
|
21
|
+
with this package)
|
|
22
|
+
--json emit machine-readable results
|
|
23
|
+
--help show this message
|
|
24
|
+
|
|
25
|
+
Exit status: 0 when every check passes, 1 otherwise.
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
function parseArgs(argv) {
|
|
29
|
+
const opts = { vectors: DEFAULT_VECTORS_PATH, json: false, help: false };
|
|
30
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
31
|
+
const arg = argv[i];
|
|
32
|
+
if (arg === '--help' || arg === '-h') opts.help = true;
|
|
33
|
+
else if (arg === '--json') opts.json = true;
|
|
34
|
+
else if (arg === '--vectors') {
|
|
35
|
+
i += 1;
|
|
36
|
+
if (argv[i] === undefined) {
|
|
37
|
+
console.error('rttp: --vectors needs a file path');
|
|
38
|
+
process.exit(2);
|
|
39
|
+
}
|
|
40
|
+
opts.vectors = argv[i];
|
|
41
|
+
} else {
|
|
42
|
+
console.error(`rttp: unknown argument ${JSON.stringify(arg)}`);
|
|
43
|
+
console.error(USAGE);
|
|
44
|
+
process.exit(2);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return opts;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
51
|
+
|
|
52
|
+
if (opts.help) {
|
|
53
|
+
process.stdout.write(USAGE);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let vectors;
|
|
58
|
+
try {
|
|
59
|
+
vectors = loadVectors(opts.vectors);
|
|
60
|
+
} catch (err) {
|
|
61
|
+
console.error(`rttp: cannot read vectors at ${opts.vectors}`);
|
|
62
|
+
console.error(` ${err.message}`);
|
|
63
|
+
process.exit(2);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const { checked, failures, passed } = runConformance(vectors);
|
|
67
|
+
|
|
68
|
+
if (opts.json) {
|
|
69
|
+
process.stdout.write(`${JSON.stringify({
|
|
70
|
+
passed,
|
|
71
|
+
checked,
|
|
72
|
+
failed: failures.length,
|
|
73
|
+
vectors: opts.vectors,
|
|
74
|
+
spec: vectors.spec,
|
|
75
|
+
applies_to: vectors.applies_to,
|
|
76
|
+
failures,
|
|
77
|
+
}, null, 2)}\n`);
|
|
78
|
+
} else if (passed) {
|
|
79
|
+
console.log(`[PASS] all ${checked} checks passed (node, independent implementation)`);
|
|
80
|
+
} else {
|
|
81
|
+
console.log(`[FAIL] ${failures.length} of ${checked} checks failed (node)`);
|
|
82
|
+
for (const item of failures) console.log(' -', item);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
process.exit(passed ? 0 : 1);
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aicent/rttp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "RTTP for JavaScript: rttp:// intent validation, canonicalisation and ROUTE_SHARD derivation (RFC-002 §10), plus the published conformance vectors and an independent replay of them, including the 128-byte frame. Zero dependencies, no build step.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rttp",
|
|
7
|
+
"uri",
|
|
8
|
+
"uri-scheme",
|
|
9
|
+
"intent-addressing",
|
|
10
|
+
"route-shard",
|
|
11
|
+
"frame",
|
|
12
|
+
"rfc-002",
|
|
13
|
+
"conformance",
|
|
14
|
+
"vectors",
|
|
15
|
+
"protocol"
|
|
16
|
+
],
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"author": "RTTP Working Group",
|
|
19
|
+
"homepage": "https://rttp.com/",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./src/rttp-uri.mjs",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./src/rttp-uri.d.mts",
|
|
25
|
+
"default": "./src/rttp-uri.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./conformance": {
|
|
28
|
+
"types": "./src/conformance.d.mts",
|
|
29
|
+
"default": "./src/conformance.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./vectors.json": "./src/vectors.json"
|
|
32
|
+
},
|
|
33
|
+
"bin": {
|
|
34
|
+
"rttp": "bin/rttp.mjs",
|
|
35
|
+
"rttp-conformance": "bin/rttp.mjs"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"src",
|
|
39
|
+
"bin",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18.0.0"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "node --test",
|
|
52
|
+
"prepublishOnly": "node --test"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for @aicent/rttp/conformance.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** One URI that a conforming implementation must accept. */
|
|
6
|
+
export interface PositiveUriVector {
|
|
7
|
+
uri: string;
|
|
8
|
+
canonical_uri: string;
|
|
9
|
+
authority: string;
|
|
10
|
+
intent: string;
|
|
11
|
+
intent_is_hash: boolean;
|
|
12
|
+
pillar: string;
|
|
13
|
+
root: string;
|
|
14
|
+
action: string;
|
|
15
|
+
action_omitted: boolean;
|
|
16
|
+
route_shard_hex: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** One URI that a conforming implementation must reject. */
|
|
20
|
+
export interface NegativeUriVector {
|
|
21
|
+
uri: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** One URI -> 128-byte frame vector. */
|
|
26
|
+
export interface FrameVector {
|
|
27
|
+
uri: string;
|
|
28
|
+
sequence_id: number;
|
|
29
|
+
ttl: number;
|
|
30
|
+
priority: number;
|
|
31
|
+
timestamp_ns: number;
|
|
32
|
+
aid_origin_hex: string;
|
|
33
|
+
action: string;
|
|
34
|
+
uri_anchored: boolean;
|
|
35
|
+
spec_rev: number;
|
|
36
|
+
route_shard_hex: string;
|
|
37
|
+
header_hex: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A frame written with the pre-extension layout (`SPEC_REV = 0`), which readers must still accept. */
|
|
41
|
+
export interface CompatVector {
|
|
42
|
+
uri: string;
|
|
43
|
+
spec_rev: number;
|
|
44
|
+
action: string;
|
|
45
|
+
action_omitted: boolean;
|
|
46
|
+
uri_anchored: boolean;
|
|
47
|
+
expected: string;
|
|
48
|
+
header_hex: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The published vector set. Generated - never hand-edited. */
|
|
52
|
+
export interface VectorSet {
|
|
53
|
+
spec: string;
|
|
54
|
+
applies_to: string[];
|
|
55
|
+
generated_by: string;
|
|
56
|
+
note: string;
|
|
57
|
+
route_shard_rule: string;
|
|
58
|
+
frame_size: number;
|
|
59
|
+
action_max_len: number;
|
|
60
|
+
positive_uris: PositiveUriVector[];
|
|
61
|
+
negative_uris: NegativeUriVector[];
|
|
62
|
+
frame_vectors: FrameVector[];
|
|
63
|
+
compat_vector_spec_rev_0: CompatVector;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Result of one `parseUri` call. */
|
|
67
|
+
export interface ParsedUri {
|
|
68
|
+
authority: string;
|
|
69
|
+
action: string;
|
|
70
|
+
shardHex: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Input to `buildFrame`. */
|
|
74
|
+
export interface FrameFields {
|
|
75
|
+
sequenceId: number | string | bigint;
|
|
76
|
+
ttl: number;
|
|
77
|
+
priority: number;
|
|
78
|
+
shardHex: string;
|
|
79
|
+
aidHex: string;
|
|
80
|
+
timestampNs: number | string | bigint;
|
|
81
|
+
action: string;
|
|
82
|
+
uriAnchored: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Outcome of replaying a vector set. */
|
|
86
|
+
export interface ConformanceResult {
|
|
87
|
+
checked: number;
|
|
88
|
+
failures: string[];
|
|
89
|
+
passed: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Absolute path of the vector set shipped inside this package. */
|
|
93
|
+
export declare const DEFAULT_VECTORS_PATH: string;
|
|
94
|
+
|
|
95
|
+
/** The ACTION field is 16 bytes. */
|
|
96
|
+
export declare const ACTION_MAX_LEN: 16;
|
|
97
|
+
|
|
98
|
+
/** Independent implementation of RFC-002 §10.2. Throws `Error`. */
|
|
99
|
+
export declare function parseUri(uri: string): ParsedUri;
|
|
100
|
+
|
|
101
|
+
/** Independent implementation of the 128-byte frame. Throws `Error`. */
|
|
102
|
+
export declare function buildFrame(fields: FrameFields): Buffer;
|
|
103
|
+
|
|
104
|
+
/** Load a vector set. Defaults to the one shipped with this package. */
|
|
105
|
+
export declare function loadVectors(path?: string): VectorSet;
|
|
106
|
+
|
|
107
|
+
/** Replay a vector set against the independent implementations. */
|
|
108
|
+
export declare function runConformance(vectors: VectorSet): ConformanceResult;
|