@synoi/gap 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 +195 -0
- package/README.md +223 -0
- package/dist/canonicalize.d.ts +19 -0
- package/dist/canonicalize.d.ts.map +1 -0
- package/dist/canonicalize.js +36 -0
- package/dist/canonicalize.js.map +1 -0
- package/dist/capabilities.d.ts +605 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +53 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/cdro.d.ts +63 -0
- package/dist/cdro.d.ts.map +1 -0
- package/dist/cdro.js +16 -0
- package/dist/cdro.js.map +1 -0
- package/dist/channels.d.ts +107 -0
- package/dist/channels.d.ts.map +1 -0
- package/dist/channels.js +29 -0
- package/dist/channels.js.map +1 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +36 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/oid.d.ts +28 -0
- package/dist/oid.d.ts.map +1 -0
- package/dist/oid.js +68 -0
- package/dist/oid.js.map +1 -0
- package/dist/receipts.d.ts +128 -0
- package/dist/receipts.d.ts.map +1 -0
- package/dist/receipts.js +14 -0
- package/dist/receipts.js.map +1 -0
- package/dist/revocations.d.ts +65 -0
- package/dist/revocations.d.ts.map +1 -0
- package/dist/revocations.js +22 -0
- package/dist/revocations.js.map +1 -0
- package/dist/validate.d.ts +59 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +835 -0
- package/dist/validate.js.map +1 -0
- package/dist/workflows.d.ts +186 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +14 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +55 -0
- package/src/canonicalize.ts +38 -0
- package/src/capabilities.ts +711 -0
- package/src/cdro.ts +92 -0
- package/src/channels.ts +183 -0
- package/src/constants.ts +46 -0
- package/src/index.ts +180 -0
- package/src/oid.ts +71 -0
- package/src/receipts.ts +169 -0
- package/src/revocations.ts +90 -0
- package/src/validate.ts +1008 -0
- package/src/workflows.ts +241 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
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 made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combined work of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the
|
|
117
|
+
License.
|
|
118
|
+
|
|
119
|
+
You may add Your own license statement for Your modifications and
|
|
120
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
121
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
122
|
+
Contribution, either on an unapproved or approved basis, and you
|
|
123
|
+
may elect to apply the Apache License to such modifications.
|
|
124
|
+
|
|
125
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
126
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
127
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
128
|
+
this License, without any additional terms or conditions.
|
|
129
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
130
|
+
the terms of any separate license agreement you may have executed
|
|
131
|
+
with Licensor regarding such Contributions.
|
|
132
|
+
|
|
133
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
134
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
135
|
+
except as required for reasonable and customary use in describing the
|
|
136
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
137
|
+
|
|
138
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
139
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
140
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
141
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
142
|
+
implied, including, without limitation, any warranties or conditions
|
|
143
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
144
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
145
|
+
appropriateness of using or reproducing the Work and assume any
|
|
146
|
+
risks associated with Your exercise of permissions under this License.
|
|
147
|
+
|
|
148
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
149
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
150
|
+
unless required by applicable law (such as deliberate and grossly
|
|
151
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special,
|
|
153
|
+
incidental, or exemplary damages of any character arising as a
|
|
154
|
+
result of this License or out of the use or inability to use the
|
|
155
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
156
|
+
work stoppage, computer failure or malfunction, or all other
|
|
157
|
+
commercial damages or losses), even if such Contributor has been
|
|
158
|
+
advised of the possibility of such damages.
|
|
159
|
+
|
|
160
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
161
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
162
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
163
|
+
obligations and/or rights consistent with this License. However, in
|
|
164
|
+
accepting such obligations, You may offer such conditions only on
|
|
165
|
+
Your own behalf and on Your sole responsibility, not on behalf of
|
|
166
|
+
any other Contributor, and only if You agree to indemnify, defend,
|
|
167
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
168
|
+
or claims asserted against, such Contributor by reason of your
|
|
169
|
+
accepting any such warranty or additional liability.
|
|
170
|
+
|
|
171
|
+
END OF TERMS AND CONDITIONS
|
|
172
|
+
|
|
173
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
174
|
+
|
|
175
|
+
To apply the Apache License to your work, attach the following
|
|
176
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
177
|
+
replaced with your own identifying information. (Don't include
|
|
178
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
179
|
+
comment syntax for the format in use. Please consult an
|
|
180
|
+
EXPLANATION document at apache.org for clarification of the
|
|
181
|
+
specific license version.
|
|
182
|
+
|
|
183
|
+
Copyright [yyyy] [name of copyright owner]
|
|
184
|
+
|
|
185
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
186
|
+
you may not use this file except in compliance with the License.
|
|
187
|
+
You may obtain a copy of the License at
|
|
188
|
+
|
|
189
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
190
|
+
|
|
191
|
+
Unless required by applicable law or agreed to in writing, software
|
|
192
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
193
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
194
|
+
See the License for the specific language governing permissions and
|
|
195
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# @synoi/gap
|
|
2
|
+
|
|
3
|
+
**GAP (Governed Action Protocol)** is the open wire protocol for a **Universal Action Coordination Fabric**, a single governed layer that connects AI agents, smart devices, industrial systems, games, medical devices, automation pipelines, and anything else that can declare what it does.
|
|
4
|
+
|
|
5
|
+
The protocol spec is published under CC0. This package is Apache-2.0.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## The Universal Action Coordination Fabric
|
|
10
|
+
|
|
11
|
+
Today every environment that involves AI or automated action builds its own integration layer: the game engine has a custom smart-home SDK, the industrial automation system has a proprietary command channel, the AI agent framework has its own tool-calling convention. Each is siloed. None of them share an audit trail. None of them share a revocation mechanism. None of them speak to each other.
|
|
12
|
+
|
|
13
|
+
GAP is the fabric underneath all of them. Any actor (an AI agent, a smart lock, a game engine, a SCADA valve controller, an MCP tool server, a medical device) speaks the same four-phase lifecycle:
|
|
14
|
+
|
|
15
|
+
1. **Declare**: the actor publishes a `CapabilityDeclaration`: what it can do, under what safety class, with what scope.
|
|
16
|
+
2. **Grant**: an operator issues a `CapabilityGrant`: who is allowed to invoke it, under what conditions, with what limits and expiry.
|
|
17
|
+
3. **Invoke**: an actor calls the capability. The fabric evaluates the grant, enforces preconditions, and routes to a human-approval workflow if required.
|
|
18
|
+
4. **Receipt**: every gate decision (allow, deny, defer, timeout) produces a content-addressed `GapDecisionReceipt`. L2+ conformant gateways sign receipts (Ed25519) and L4 gateways add a hybrid ML-DSA-65 signature. This package provides the receipt type definitions and OID computation; signature enforcement is a gateway implementation responsibility (see IMPLEMENTING.md).
|
|
19
|
+
|
|
20
|
+
The same grant that lets a game engine dim your lights also governs an industrial AI requesting a valve close. The same revocation call that removes a contractor's building access simultaneously revokes their AI agent's tool access. A conformant gateway's receipt log is structurally suitable as audit evidence in SOC 2, HIPAA, and similar review contexts. What you get from this package alone are the wire types and OID helpers; the guarantee requires a compliant gateway implementation.
|
|
21
|
+
|
|
22
|
+
The capability names, safety classes, and channel adapters change per environment. The protocol does not.
|
|
23
|
+
|
|
24
|
+
For concrete scenarios across gaming, industrial automation, healthcare, AI agent pipelines, smart home, physical security, and cross-environment coordination, see [USE_CASES.md](USE_CASES.md).
|
|
25
|
+
|
|
26
|
+
All four record types are **CDROs**: Content-addressed, Deterministic, Replayable Objects. Each CDRO has a content-addressed OID (`sha256:<hex>`) computed over its canonical JSON body. Any party can independently verify an OID.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Object model
|
|
31
|
+
|
|
32
|
+
Every top-level record is a `GapCdroEnvelope<TBody>`:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
interface GapCdroEnvelope<TBody> {
|
|
36
|
+
oid: string // "sha256:<hex>" -- content-addressed
|
|
37
|
+
type: GapObjectType // e.g. "gap:capability_grant"
|
|
38
|
+
gap_version: '1.0'
|
|
39
|
+
tenant_id: string
|
|
40
|
+
created_at_ms: number
|
|
41
|
+
created_by: string // actor OID
|
|
42
|
+
body: TBody // type-specific payload
|
|
43
|
+
signature?: string // optional Ed25519, base64
|
|
44
|
+
signature_key_id?: string
|
|
45
|
+
supersedes?: string // OID of replaced CDRO
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Object types and their body shapes:
|
|
50
|
+
|
|
51
|
+
| `type` | Body type |
|
|
52
|
+
|-------------------------------|-----------------------------|
|
|
53
|
+
| `gap:capability_declaration` | `CapabilityDeclarationBody` |
|
|
54
|
+
| `gap:capability_grant` | `CapabilityGrantBody` |
|
|
55
|
+
| `gap:capability_invocation` | `CapabilityInvocationBody` |
|
|
56
|
+
| `gap:workflow_definition` | `WorkflowDefinitionBody` |
|
|
57
|
+
| `gap:workflow_instance` | `WorkflowInstanceBody` |
|
|
58
|
+
| `gap:stage_transition` | `StageTransitionBody` |
|
|
59
|
+
| `gap:channel_event` | `ChannelEventBody` |
|
|
60
|
+
| `gap:decision_receipt` | `GapDecisionReceiptBody` |
|
|
61
|
+
| `gap:revocation_event` | `RevocationEventBody` |
|
|
62
|
+
| `gap:federation_handshake` | (reserved for GAP 1.1) |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Conformance tiers
|
|
67
|
+
|
|
68
|
+
GAP implementations declare a conformance tier:
|
|
69
|
+
|
|
70
|
+
| Tier | Requirements |
|
|
71
|
+
|------|-------------|
|
|
72
|
+
| **L1** | Validate CDRO envelopes. Compute and verify content-addressed OIDs. |
|
|
73
|
+
| **L2** | L1 + evaluate capability grants (expiry, scope, preconditions). Produce decision receipts for every gate decision. |
|
|
74
|
+
| **L3** | L2 + orchestrate multi-stage HITL workflows via channel adapters (SMS, push, overlay, webhook). |
|
|
75
|
+
| **L4** | L3 + leveled revocation (L1/L2/L3), hybrid ML-DSA-65 post-quantum signing, authorized-axis classification (AUTHORIZED/ORPHANED). (Federation reserved for 1.1: `gap:federation_handshake` is not required for L4 conformance in GAP 1.0.) |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install @synoi/gap
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Node >= 18 required (uses `TextEncoder` and `@noble/hashes`).
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Compute a content-addressed OID
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { computeGapOid } from '@synoi/gap'
|
|
95
|
+
|
|
96
|
+
const payload = {
|
|
97
|
+
type: 'gap:capability_declaration',
|
|
98
|
+
tenant_id: 'my-tenant',
|
|
99
|
+
created_at_ms: Date.now(),
|
|
100
|
+
created_by: 'actor:my-skill',
|
|
101
|
+
body: {
|
|
102
|
+
actor_type: 'skill',
|
|
103
|
+
actor_id: 'skill:my-skill',
|
|
104
|
+
actor_name: 'My Skill',
|
|
105
|
+
actor_version: '1.0.0',
|
|
106
|
+
capabilities: [{ capability: 'my.action', safety_class: 'A' }],
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const oid = computeGapOid(payload)
|
|
111
|
+
// => "sha256:..."
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Build and validate a declaration envelope
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import {
|
|
118
|
+
GAP_VERSION,
|
|
119
|
+
computeGapOid,
|
|
120
|
+
validateCapabilityDeclaration,
|
|
121
|
+
type CapabilityDeclaration,
|
|
122
|
+
type CapabilityDeclarationBody,
|
|
123
|
+
} from '@synoi/gap'
|
|
124
|
+
|
|
125
|
+
const body: CapabilityDeclarationBody = {
|
|
126
|
+
actor_type: 'skill',
|
|
127
|
+
actor_id: 'skill:my-skill',
|
|
128
|
+
actor_name: 'My Skill',
|
|
129
|
+
actor_version: '1.0.0',
|
|
130
|
+
capabilities: [
|
|
131
|
+
{ capability: 'my.action', safety_class: 'B' },
|
|
132
|
+
],
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const payload = {
|
|
136
|
+
type: 'gap:capability_declaration' as const,
|
|
137
|
+
tenant_id: 'my-tenant',
|
|
138
|
+
created_at_ms: Date.now(),
|
|
139
|
+
created_by: 'actor:operator',
|
|
140
|
+
body,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const decl: CapabilityDeclaration = {
|
|
144
|
+
...payload,
|
|
145
|
+
oid: computeGapOid(payload),
|
|
146
|
+
gap_version: GAP_VERSION,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const result = validateCapabilityDeclaration(decl)
|
|
150
|
+
if (!result.ok) {
|
|
151
|
+
console.error(result.errors)
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Check if an actor's result is a failure
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { isGapFailure, type GapFailure } from '@synoi/gap'
|
|
159
|
+
|
|
160
|
+
function handleResult(r: MyResult | GapFailure) {
|
|
161
|
+
if (isGapFailure(r)) {
|
|
162
|
+
console.error('gate denied:', r.reason, r.detail)
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
// r is MyResult
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Match capability patterns
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { capabilityMatches } from '@synoi/gap'
|
|
173
|
+
|
|
174
|
+
capabilityMatches('skill.*', 'skill.create') // true
|
|
175
|
+
capabilityMatches('skill.*', 'agent.create') // false
|
|
176
|
+
capabilityMatches('*', 'anything') // true
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Wire format stability
|
|
182
|
+
|
|
183
|
+
OIDs are computed over a **canonical JSON** form: keys sorted lexicographically, `undefined` values (absent keys in JavaScript) dropped from objects, `null` values kept as JSON `null`, arrays order-preserved. The `canonicalize` function is exported for implementors who need to reproduce OIDs outside this package.
|
|
184
|
+
|
|
185
|
+
The test vectors in `test/oid.test.ts` pin the canonical hashes against the gateway implementation. Any drift in canonical form will break those tests.
|
|
186
|
+
|
|
187
|
+
### Canonicalization constraints
|
|
188
|
+
|
|
189
|
+
Common implementation gotchas when reproducing OIDs in another language or runtime:
|
|
190
|
+
|
|
191
|
+
- **Integers only for numeric fields**: any number value in the hashed body must be an integer. Floats (e.g. `1.0` instead of `1`) are rejected and will produce a different OID.
|
|
192
|
+
- **UTF-8 byte sequences for strings**: string values must be serialized as raw UTF-8 bytes. Unicode escape sequences (`\uXXXX`) in the JSON encoding produce a different hash.
|
|
193
|
+
- **Keys sorted lexicographically at every nesting level**: this applies recursively to nested objects, not just the top-level envelope fields.
|
|
194
|
+
- **`null` is kept; absent keys are dropped**: serialize `null` values as JSON `null`. Keys with `undefined` values (or absent keys) must be omitted entirely, not written as `null`.
|
|
195
|
+
- **Five fields are stripped before hashing**: `oid`, `gap_version`, `signature`, `signature_key_id`, and `supersedes` are excluded from the canonical body. Do not include them when computing the OID.
|
|
196
|
+
|
|
197
|
+
For the full normative specification of the canonicalization algorithm, see [IMPLEMENTING.md](https://github.com/synoi/synoi-gap/blob/main/IMPLEMENTING.md).
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Documentation
|
|
202
|
+
|
|
203
|
+
| Document | What it covers |
|
|
204
|
+
|---|---|
|
|
205
|
+
| [IMPLEMENTING.md](https://github.com/synoi/synoi-gap/blob/main/IMPLEMENTING.md) | How to build a GAP-conformant server from scratch in any language: wire format, OID computation, HTTP surface, grant evaluation, receipts, conformance tiers, and wiring execution backends via channel adapters (RFC 2119 conventions) |
|
|
206
|
+
| [USE_CASES.md](https://github.com/synoi/synoi-gap/blob/main/USE_CASES.md) | Concrete scenarios across gaming, industrial automation, healthcare, AI agent pipelines, smart home, physical security, and cross-environment coordination |
|
|
207
|
+
| [openapi.yaml](https://github.com/synoi/synoi-gap/blob/main/openapi.yaml) | OpenAPI 3.1.0 specification for the full GAP HTTP surface (25+ endpoints, all schemas) |
|
|
208
|
+
| [ERROR_CODES.md](https://github.com/synoi/synoi-gap/blob/main/ERROR_CODES.md) | Machine-readable error code registry with conformance tier annotations |
|
|
209
|
+
| [CAPABILITY_TAXONOMY.md](https://github.com/synoi/synoi-gap/blob/main/CAPABILITY_TAXONOMY.md) | Canonical dotted-taxonomy capability names across 9 domains (home, industrial, medical, physical, financial, MCP, game, gap, messaging) |
|
|
210
|
+
| [OPTIONAL_CAPABILITIES_SPEC.md](https://github.com/synoi/synoi-gap/blob/main/OPTIONAL_CAPABILITIES_SPEC.md) | Normative spec for optional ambient effects: evaluation algorithm, security constraints, conformance |
|
|
211
|
+
| [THREAT_MODEL.md](https://github.com/synoi/synoi-gap/blob/main/THREAT_MODEL.md) | STRIDE threat model: 12 protocol components, ranked attack surface, mitigations index |
|
|
212
|
+
| [CONTRIBUTING.md](https://github.com/synoi/synoi-gap/blob/main/CONTRIBUTING.md) | How to contribute: dev setup, spec change process, capability taxonomy additions, security reporting |
|
|
213
|
+
| [profiles/](https://github.com/synoi/synoi-gap/tree/main/profiles) | Companion profiles extending GAP for specific sectors: gaming (`game.*`), healthcare (`hc.*`), supply chain/DevOps (`ci.*`), financial services (`fin.*`), AI/ML platforms (`ai.*`), legal (`legal.*`), consumer/household (`consumer.*`). Authoring guide and blank template included. |
|
|
214
|
+
| [python/](https://github.com/synoi/synoi-gap/tree/main/python) | Python SDK: `compute_gap_oid`, validators, `GapClient` async HTTP wrapper |
|
|
215
|
+
| [synoi-gard](https://github.com/synoi/synoi-gard) | Lightweight local single-tenant GAP runtime: SQLite grant and receipt stores, channel adapters (Hue, WLED, Home Assistant), desktop HITL toast. No account required. Graduates to the SynOI hosted gateway for multi-house or federation use. |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
Code (`src/`, `dist/`, `python/`, test files): Apache-2.0. See [LICENSE](https://github.com/synoi/synoi-gap/blob/main/LICENSE).
|
|
222
|
+
|
|
223
|
+
Protocol specification (`IMPLEMENTING.md`, `openapi.yaml`, `ERROR_CODES.md`, `CAPABILITY_TAXONOMY.md`, `OPTIONAL_CAPABILITIES_SPEC.md`): CC0 1.0 Universal (public domain dedication). Any implementation may speak the GAP wire format without restriction, attribution, or royalty. See [LICENSE-CC0.md](https://github.com/synoi/synoi-gap/blob/main/LICENSE-CC0.md).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* canonicalize.ts -- deterministic JSON serializer used by GAP OID computation.
|
|
3
|
+
*
|
|
4
|
+
* Implements RFC 8785 JCS canonical JSON. See IMPLEMENTING.md §2.2 for the
|
|
5
|
+
* normative rules. Rules:
|
|
6
|
+
*
|
|
7
|
+
* 1. Keys are sorted lexicographically at every object level.
|
|
8
|
+
* 2. Keys whose value is `undefined` are dropped entirely; `null` is kept
|
|
9
|
+
* and serialized as JSON null (RFC 8785 JCS: null is a first-class JSON value).
|
|
10
|
+
* 3. Arrays preserve order.
|
|
11
|
+
* 4. Scalars (string, number, boolean, null) serialize via JSON.stringify.
|
|
12
|
+
* 5. Float values (non-integer numbers) are forbidden. GAP CDROs use integer
|
|
13
|
+
* minor units (e.g. cents) for all money and millisecond integers for time.
|
|
14
|
+
* Passing a float throws a TypeError. Infinity and NaN also throw.
|
|
15
|
+
*
|
|
16
|
+
* The output is a string suitable for hashing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalize(value: unknown): string;
|
|
19
|
+
//# sourceMappingURL=canonicalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize.d.ts","sourceRoot":"","sources":["../src/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAmBnD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* canonicalize.ts -- deterministic JSON serializer used by GAP OID computation.
|
|
3
|
+
*
|
|
4
|
+
* Implements RFC 8785 JCS canonical JSON. See IMPLEMENTING.md §2.2 for the
|
|
5
|
+
* normative rules. Rules:
|
|
6
|
+
*
|
|
7
|
+
* 1. Keys are sorted lexicographically at every object level.
|
|
8
|
+
* 2. Keys whose value is `undefined` are dropped entirely; `null` is kept
|
|
9
|
+
* and serialized as JSON null (RFC 8785 JCS: null is a first-class JSON value).
|
|
10
|
+
* 3. Arrays preserve order.
|
|
11
|
+
* 4. Scalars (string, number, boolean, null) serialize via JSON.stringify.
|
|
12
|
+
* 5. Float values (non-integer numbers) are forbidden. GAP CDROs use integer
|
|
13
|
+
* minor units (e.g. cents) for all money and millisecond integers for time.
|
|
14
|
+
* Passing a float throws a TypeError. Infinity and NaN also throw.
|
|
15
|
+
*
|
|
16
|
+
* The output is a string suitable for hashing.
|
|
17
|
+
*/
|
|
18
|
+
export function canonicalize(value) {
|
|
19
|
+
if (typeof value === 'number') {
|
|
20
|
+
if (!isFinite(value)) {
|
|
21
|
+
throw new TypeError(`GAP canonicalize: non-finite number (${value}) is not allowed in canonical JSON`);
|
|
22
|
+
}
|
|
23
|
+
if (!Number.isInteger(value)) {
|
|
24
|
+
throw new TypeError('GAP canonicalize: float values are not allowed; use integer minor units (e.g. cents)');
|
|
25
|
+
}
|
|
26
|
+
return JSON.stringify(value);
|
|
27
|
+
}
|
|
28
|
+
if (value === null || typeof value !== 'object')
|
|
29
|
+
return JSON.stringify(value);
|
|
30
|
+
if (Array.isArray(value))
|
|
31
|
+
return '[' + value.map(canonicalize).join(',') + ']';
|
|
32
|
+
const obj = value;
|
|
33
|
+
const keys = Object.keys(obj).filter((k) => obj[k] !== undefined).sort();
|
|
34
|
+
return '{' + keys.map((k) => JSON.stringify(k) + ':' + canonicalize(obj[k])).join(',') + '}';
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=canonicalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize.js","sourceRoot":"","sources":["../src/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CACjB,wCAAwC,KAAK,oCAAoC,CAClF,CAAA;QACH,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,SAAS,CACjB,sFAAsF,CACvF,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;IAC9E,MAAM,GAAG,GAAG,KAAgC,CAAA;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,IAAI,EAAE,CAAA;IACxE,OAAO,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAA;AAC9F,CAAC"}
|