@zanii/residency 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 +159 -0
- package/README.md +39 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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 Derivative
|
|
95
|
+
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; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
|
|
125
|
+
|
|
126
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
127
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
128
|
+
unless required by applicable law (such as deliberate and grossly
|
|
129
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
130
|
+
liable to You for damages, including any direct, indirect, special,
|
|
131
|
+
incidental, or consequential damages of any character arising as a
|
|
132
|
+
result of this License or out of the use or inability to use the
|
|
133
|
+
Work.
|
|
134
|
+
|
|
135
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
136
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
137
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
138
|
+
or other liability obligations and/or rights consistent with this
|
|
139
|
+
License. However, in accepting such obligations, You may act only
|
|
140
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
141
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
142
|
+
defend, and hold each Contributor harmless for any liability
|
|
143
|
+
incurred by, or claims asserted against, such Contributor.
|
|
144
|
+
|
|
145
|
+
END OF TERMS AND CONDITIONS
|
|
146
|
+
|
|
147
|
+
Copyright 2026 Zanii
|
|
148
|
+
|
|
149
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
150
|
+
you may not use this file except in compliance with the License.
|
|
151
|
+
You may obtain a copy of the License at
|
|
152
|
+
|
|
153
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
154
|
+
|
|
155
|
+
Unless required by applicable law or agreed to in writing, software
|
|
156
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
157
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
158
|
+
See the License for the specific language governing permissions and
|
|
159
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @zanii/residency
|
|
2
|
+
|
|
3
|
+
**Did my data leave the country?** Bind a **region attestation** to each data touch,
|
|
4
|
+
confirm it's inside a declared jurisdiction, and emit a receipt when it crosses a border.
|
|
5
|
+
Answers the 2026 sovereignty fear: *"prove it never left the UAE / the EU."*
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @zanii/residency @zanii/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { buildResidencyClaim, verifyResidency, detectCrossings, JURISDICTION_PRESETS } from '@zanii/residency';
|
|
13
|
+
|
|
14
|
+
const claim = buildResidencyClaim({ jurisdiction: 'UAE',
|
|
15
|
+
regionAttestation: { region: 'me-central-1', source: 'aws:instance-identity', evidence }, ts: now });
|
|
16
|
+
await zanii.record(claim);
|
|
17
|
+
|
|
18
|
+
// verify: your injected geo verifier authenticates the region, then it must be in the allow-set
|
|
19
|
+
const r = await verifyResidency(claim.payload, { allowedRegions: JURISDICTION_PRESETS.UAE, verifyRegion });
|
|
20
|
+
r.ok; r.crossed; // crossed = the region left the declared jurisdiction — a border crossing
|
|
21
|
+
|
|
22
|
+
detectCrossings(sequence, JURISDICTION_PRESETS.UAE); // exit/return points across a history
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Python: `from zanii.residency import build_residency_claim, verify_residency, detect_crossings, ...`
|
|
26
|
+
|
|
27
|
+
## Injected geo verification & declared jurisdictions
|
|
28
|
+
|
|
29
|
+
We can't derive where a server ran — the region signal comes from the cloud provider or a
|
|
30
|
+
TEE's attested geolocation, authenticated by **your** `verifyRegion` (the `@zanii/attest`
|
|
31
|
+
discipline). And jurisdiction is **declared, not assumed**: you pass an explicit
|
|
32
|
+
`allowedRegions` set — your compliance team owns it. Presets (`UAE`, `GCC`, `EU`) are
|
|
33
|
+
convenience only.
|
|
34
|
+
|
|
35
|
+
## The limit, stated up front
|
|
36
|
+
|
|
37
|
+
Only as strong as the region attestation source. A claim proves "a signal your verifier
|
|
38
|
+
trusts said this ran in region R, and R is in your declared jurisdiction." Bind a signal
|
|
39
|
+
you verify.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** A raw region signal — the shape your `verifyRegion` authenticates. Contents are yours. */
|
|
2
|
+
export interface RegionAttestation {
|
|
3
|
+
/** Region/country code, e.g. `AE`, `me-central-1`, `eu-central-1`. */
|
|
4
|
+
region: string;
|
|
5
|
+
/** Where the signal came from, e.g. `aws:instance-identity`, `tee:geo`, `azure:imds`. */
|
|
6
|
+
source: string;
|
|
7
|
+
/** Opaque provider evidence your verifier checks (a signed doc, a quote). */
|
|
8
|
+
evidence?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Injected: authenticate a region signal, return the trusted region + source, or null. */
|
|
11
|
+
export type RegionVerifier = (attestation: RegionAttestation) => Promise<{
|
|
12
|
+
region: string;
|
|
13
|
+
source: string;
|
|
14
|
+
} | null> | {
|
|
15
|
+
region: string;
|
|
16
|
+
source: string;
|
|
17
|
+
} | null;
|
|
18
|
+
/** Convenience presets — extend or replace with your own compliance-owned lists. */
|
|
19
|
+
export declare const JURISDICTION_PRESETS: Record<string, string[]>;
|
|
20
|
+
export interface ResidencyClaim {
|
|
21
|
+
v: 1;
|
|
22
|
+
type: 'residency.claim';
|
|
23
|
+
/** Optional data-object ref (`@zanii/data-custody`) this residency applies to. */
|
|
24
|
+
ref?: string;
|
|
25
|
+
/** The declared jurisdiction name (informational — the allow-set is the real check). */
|
|
26
|
+
jurisdiction: string;
|
|
27
|
+
/** The region signal, verified by the injected verifier at check time. */
|
|
28
|
+
region_attestation: RegionAttestation;
|
|
29
|
+
ts: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ResidencyInput {
|
|
32
|
+
jurisdiction: string;
|
|
33
|
+
regionAttestation: RegionAttestation;
|
|
34
|
+
ts: string;
|
|
35
|
+
ref?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Build a residency claim for a touch. Record it (or attach to a `@zanii/data-custody` touch). */
|
|
38
|
+
export declare function buildResidencyClaim(input: ResidencyInput): {
|
|
39
|
+
target: string;
|
|
40
|
+
payload: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
export declare function claimHash(claim: ResidencyClaim): string;
|
|
43
|
+
export interface ResidencyCheck {
|
|
44
|
+
ok: boolean;
|
|
45
|
+
reasons: string[];
|
|
46
|
+
/** The verified region (from the injected verifier), when it authenticated. */
|
|
47
|
+
region: string | null;
|
|
48
|
+
/** true when the region is outside the declared allow-set — a border crossing. */
|
|
49
|
+
crossed: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verify a residency claim: the injected verifier must authenticate the region signal,
|
|
53
|
+
* AND the returned region must be in `allowedRegions`. A region outside the set is a
|
|
54
|
+
* **border crossing** (`crossed: true`) — not silently ignored.
|
|
55
|
+
*/
|
|
56
|
+
export declare function verifyResidency(claim: ResidencyClaim, opts: {
|
|
57
|
+
allowedRegions: string[];
|
|
58
|
+
verifyRegion: RegionVerifier;
|
|
59
|
+
}): Promise<ResidencyCheck>;
|
|
60
|
+
/**
|
|
61
|
+
* Across an ordered sequence of verified regions (each `{ ts, region }`, oldest first),
|
|
62
|
+
* find every point where the region left the declared allow-set. Each crossing names the
|
|
63
|
+
* ts and the region it moved to — the evidence for "when did it leave, and to where."
|
|
64
|
+
*/
|
|
65
|
+
export declare function detectCrossings(sequence: Array<{
|
|
66
|
+
ts: string;
|
|
67
|
+
region: string;
|
|
68
|
+
}>, allowedRegions: string[]): Array<{
|
|
69
|
+
ts: string;
|
|
70
|
+
region: string;
|
|
71
|
+
direction: 'exit' | 'return';
|
|
72
|
+
}>;
|
|
73
|
+
/** Does an agent's scope permit acting in this region? (`residency.<region>` targets, reusing core.) */
|
|
74
|
+
export declare function residencyAllowed(effectiveScopes: string[], region: string): boolean;
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,6FAA6F;AAC7F,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,2FAA2F;AAC3F,MAAM,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,iBAAiB,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAEhK,oFAAoF;AACpF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAIzD,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,iBAAiB,CAAC;IACxB,kFAAkF;IAClF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,YAAY,EAAE,MAAM,CAAC;IAC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AAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEnF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/residency — did my data leave the country?
|
|
3
|
+
*
|
|
4
|
+
* The biggest 2026 sovereignty fear (EU localization, UAE PDPL residency, GCC rules) is
|
|
5
|
+
* that nothing proves where data *physically* went. This binds a **region attestation**
|
|
6
|
+
* to each data touch: confirm the attested region is inside a declared jurisdiction, and
|
|
7
|
+
* emit a receipt the moment it crosses a border.
|
|
8
|
+
*
|
|
9
|
+
* ## Injected geo verification (the `@zanii/attest` discipline)
|
|
10
|
+
*
|
|
11
|
+
* We cannot derive where a server ran — the region signal comes from the cloud provider
|
|
12
|
+
* (an AWS/Azure region identity, an instance-identity document) or a TEE's attested
|
|
13
|
+
* geolocation. You pass a `verifyRegion` that authenticates that signal and returns the
|
|
14
|
+
* region. **We verify the binding; you supply the geo trust root.**
|
|
15
|
+
*
|
|
16
|
+
* ## Jurisdiction is declared, not assumed
|
|
17
|
+
*
|
|
18
|
+
* We do not maintain a geopolitical database of "what is in the EU." You declare a
|
|
19
|
+
* jurisdiction as an explicit **allow-set of regions** (`allowedRegions`) — your compliance
|
|
20
|
+
* team owns that list. A couple of presets are provided as convenience, nothing more.
|
|
21
|
+
*
|
|
22
|
+
* ## The limit, stated up front
|
|
23
|
+
*
|
|
24
|
+
* The proof is only as strong as the region attestation source. A residency claim proves
|
|
25
|
+
* "a signal your verifier trusts said this touch ran in region R, and R is in your declared
|
|
26
|
+
* jurisdiction." It cannot prove residency your geo source can't — bind a signal you verify.
|
|
27
|
+
*/
|
|
28
|
+
import { jcsHash, scopesAllow } from '@zanii/core';
|
|
29
|
+
/** Convenience presets — extend or replace with your own compliance-owned lists. */
|
|
30
|
+
export const JURISDICTION_PRESETS = {
|
|
31
|
+
UAE: ['AE', 'me-central-1', 'me-south-1'],
|
|
32
|
+
GCC: ['AE', 'SA', 'BH', 'KW', 'OM', 'QA', 'me-central-1', 'me-south-1'],
|
|
33
|
+
EU: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'eu-central-1', 'eu-west-1', 'eu-west-3', 'eu-north-1'],
|
|
34
|
+
};
|
|
35
|
+
/** Build a residency claim for a touch. Record it (or attach to a `@zanii/data-custody` touch). */
|
|
36
|
+
export function buildResidencyClaim(input) {
|
|
37
|
+
if (!input.jurisdiction)
|
|
38
|
+
throw new Error('jurisdiction is required');
|
|
39
|
+
if (!input.regionAttestation?.region)
|
|
40
|
+
throw new Error('regionAttestation.region is required');
|
|
41
|
+
if (Number.isNaN(Date.parse(input.ts)))
|
|
42
|
+
throw new Error('ts must be an ISO timestamp');
|
|
43
|
+
const claim = {
|
|
44
|
+
v: 1,
|
|
45
|
+
type: 'residency.claim',
|
|
46
|
+
jurisdiction: input.jurisdiction,
|
|
47
|
+
region_attestation: input.regionAttestation,
|
|
48
|
+
ts: input.ts,
|
|
49
|
+
};
|
|
50
|
+
if (input.ref !== undefined)
|
|
51
|
+
claim.ref = input.ref;
|
|
52
|
+
return { target: 'residency.claim', payload: claim };
|
|
53
|
+
}
|
|
54
|
+
export function claimHash(claim) {
|
|
55
|
+
return jcsHash(claim);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Verify a residency claim: the injected verifier must authenticate the region signal,
|
|
59
|
+
* AND the returned region must be in `allowedRegions`. A region outside the set is a
|
|
60
|
+
* **border crossing** (`crossed: true`) — not silently ignored.
|
|
61
|
+
*/
|
|
62
|
+
export async function verifyResidency(claim, opts) {
|
|
63
|
+
const reasons = [];
|
|
64
|
+
if (claim?.v !== 1 || claim.type !== 'residency.claim') {
|
|
65
|
+
return { ok: false, reasons: ['not a residency claim (v1)'], region: null, crossed: false };
|
|
66
|
+
}
|
|
67
|
+
const verified = await opts.verifyRegion(claim.region_attestation);
|
|
68
|
+
if (!verified) {
|
|
69
|
+
return { ok: false, reasons: ['region signal failed the injected verifier'], region: null, crossed: false };
|
|
70
|
+
}
|
|
71
|
+
const inside = opts.allowedRegions.includes(verified.region);
|
|
72
|
+
if (!inside)
|
|
73
|
+
reasons.push(`region ${verified.region} is OUTSIDE the declared jurisdiction (${opts.allowedRegions.join(', ')}) — border crossed`);
|
|
74
|
+
return { ok: inside, reasons, region: verified.region, crossed: !inside };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Across an ordered sequence of verified regions (each `{ ts, region }`, oldest first),
|
|
78
|
+
* find every point where the region left the declared allow-set. Each crossing names the
|
|
79
|
+
* ts and the region it moved to — the evidence for "when did it leave, and to where."
|
|
80
|
+
*/
|
|
81
|
+
export function detectCrossings(sequence, allowedRegions) {
|
|
82
|
+
const crossings = [];
|
|
83
|
+
let inside = null;
|
|
84
|
+
const ordered = [...sequence].sort((a, b) => Date.parse(a.ts) - Date.parse(b.ts));
|
|
85
|
+
for (const s of ordered) {
|
|
86
|
+
const now = allowedRegions.includes(s.region);
|
|
87
|
+
if (inside !== null && now !== inside) {
|
|
88
|
+
crossings.push({ ts: s.ts, region: s.region, direction: now ? 'return' : 'exit' });
|
|
89
|
+
}
|
|
90
|
+
inside = now;
|
|
91
|
+
}
|
|
92
|
+
return crossings;
|
|
93
|
+
}
|
|
94
|
+
/** Does an agent's scope permit acting in this region? (`residency.<region>` targets, reusing core.) */
|
|
95
|
+
export function residencyAllowed(effectiveScopes, region) {
|
|
96
|
+
return scopesAllow(effectiveScopes, `residency.${region}`);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,OAAO,EAAE,W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,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,QAA+C,EAC/C,cAAwB;IAExB,MAAM,SAAS,GAAwE,EAAE,CAAC;IAC1F,IAAI,MAAM,GAAmB,IAAI,CAAC;IAClC,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClF,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC9C,IAAI,MAAM,KAAK,IAAI,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;YACtC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACrF,CAAC;QACD,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,gBAAgB,CAAC,eAAyB,EAAE,MAAc;IACxE,OAAO,WAAW,CAAC,eAAe,EAAE,aAAa,MAAM,EAAE,CAAC,CAAC;AAC7D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zanii/residency",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Prove where an agent's data physically stayed - bind a region attestation to each data touch, confirm the attested region is inside a declared jurisdiction, and emit a receipt the moment it crosses a border. Answers 'prove it never left the UAE / the EU.' The region signal is INJECTED (cloud-provider region / TEE geolocation) - we verify the binding, you supply the geo trust root; the proof is only as strong as that source.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://ledger.zanii.agency",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^26.1.0",
|
|
30
|
+
"typescript": "^5.8.2",
|
|
31
|
+
"vitest": "^3.0.9"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@zanii/core": "0.4.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc -p tsconfig.build.json",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zanii/residency — did my data leave the country?
|
|
3
|
+
*
|
|
4
|
+
* The biggest 2026 sovereignty fear (EU localization, UAE PDPL residency, GCC rules) is
|
|
5
|
+
* that nothing proves where data *physically* went. This binds a **region attestation**
|
|
6
|
+
* to each data touch: confirm the attested region is inside a declared jurisdiction, and
|
|
7
|
+
* emit a receipt the moment it crosses a border.
|
|
8
|
+
*
|
|
9
|
+
* ## Injected geo verification (the `@zanii/attest` discipline)
|
|
10
|
+
*
|
|
11
|
+
* We cannot derive where a server ran — the region signal comes from the cloud provider
|
|
12
|
+
* (an AWS/Azure region identity, an instance-identity document) or a TEE's attested
|
|
13
|
+
* geolocation. You pass a `verifyRegion` that authenticates that signal and returns the
|
|
14
|
+
* region. **We verify the binding; you supply the geo trust root.**
|
|
15
|
+
*
|
|
16
|
+
* ## Jurisdiction is declared, not assumed
|
|
17
|
+
*
|
|
18
|
+
* We do not maintain a geopolitical database of "what is in the EU." You declare a
|
|
19
|
+
* jurisdiction as an explicit **allow-set of regions** (`allowedRegions`) — your compliance
|
|
20
|
+
* team owns that list. A couple of presets are provided as convenience, nothing more.
|
|
21
|
+
*
|
|
22
|
+
* ## The limit, stated up front
|
|
23
|
+
*
|
|
24
|
+
* The proof is only as strong as the region attestation source. A residency claim proves
|
|
25
|
+
* "a signal your verifier trusts said this touch ran in region R, and R is in your declared
|
|
26
|
+
* jurisdiction." It cannot prove residency your geo source can't — bind a signal you verify.
|
|
27
|
+
*/
|
|
28
|
+
import { jcsHash, scopesAllow } from '@zanii/core';
|
|
29
|
+
|
|
30
|
+
/** A raw region signal — the shape your `verifyRegion` authenticates. Contents are yours. */
|
|
31
|
+
export interface RegionAttestation {
|
|
32
|
+
/** Region/country code, e.g. `AE`, `me-central-1`, `eu-central-1`. */
|
|
33
|
+
region: string;
|
|
34
|
+
/** Where the signal came from, e.g. `aws:instance-identity`, `tee:geo`, `azure:imds`. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** Opaque provider evidence your verifier checks (a signed doc, a quote). */
|
|
37
|
+
evidence?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Injected: authenticate a region signal, return the trusted region + source, or null. */
|
|
41
|
+
export type RegionVerifier = (attestation: RegionAttestation) => Promise<{ region: string; source: string } | null> | { region: string; source: string } | null;
|
|
42
|
+
|
|
43
|
+
/** Convenience presets — extend or replace with your own compliance-owned lists. */
|
|
44
|
+
export const JURISDICTION_PRESETS: Record<string, string[]> = {
|
|
45
|
+
UAE: ['AE', 'me-central-1', 'me-south-1'],
|
|
46
|
+
GCC: ['AE', 'SA', 'BH', 'KW', 'OM', 'QA', 'me-central-1', 'me-south-1'],
|
|
47
|
+
EU: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'eu-central-1', 'eu-west-1', 'eu-west-3', 'eu-north-1'],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export interface ResidencyClaim {
|
|
51
|
+
v: 1;
|
|
52
|
+
type: 'residency.claim';
|
|
53
|
+
/** Optional data-object ref (`@zanii/data-custody`) this residency applies to. */
|
|
54
|
+
ref?: string;
|
|
55
|
+
/** The declared jurisdiction name (informational — the allow-set is the real check). */
|
|
56
|
+
jurisdiction: string;
|
|
57
|
+
/** The region signal, verified by the injected verifier at check time. */
|
|
58
|
+
region_attestation: RegionAttestation;
|
|
59
|
+
ts: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ResidencyInput {
|
|
63
|
+
jurisdiction: string;
|
|
64
|
+
regionAttestation: RegionAttestation;
|
|
65
|
+
ts: string;
|
|
66
|
+
ref?: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Build a residency claim for a touch. Record it (or attach to a `@zanii/data-custody` touch). */
|
|
70
|
+
export function buildResidencyClaim(input: ResidencyInput): { target: string; payload: Record<string, unknown> } {
|
|
71
|
+
if (!input.jurisdiction) throw new Error('jurisdiction is required');
|
|
72
|
+
if (!input.regionAttestation?.region) throw new Error('regionAttestation.region is required');
|
|
73
|
+
if (Number.isNaN(Date.parse(input.ts))) throw new Error('ts must be an ISO timestamp');
|
|
74
|
+
const claim: ResidencyClaim = {
|
|
75
|
+
v: 1,
|
|
76
|
+
type: 'residency.claim',
|
|
77
|
+
jurisdiction: input.jurisdiction,
|
|
78
|
+
region_attestation: input.regionAttestation,
|
|
79
|
+
ts: input.ts,
|
|
80
|
+
};
|
|
81
|
+
if (input.ref !== undefined) claim.ref = input.ref;
|
|
82
|
+
return { target: 'residency.claim', payload: claim as unknown as Record<string, unknown> };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function claimHash(claim: ResidencyClaim): string {
|
|
86
|
+
return jcsHash(claim as unknown as Record<string, unknown>);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ResidencyCheck {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
reasons: string[];
|
|
92
|
+
/** The verified region (from the injected verifier), when it authenticated. */
|
|
93
|
+
region: string | null;
|
|
94
|
+
/** true when the region is outside the declared allow-set — a border crossing. */
|
|
95
|
+
crossed: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Verify a residency claim: the injected verifier must authenticate the region signal,
|
|
100
|
+
* AND the returned region must be in `allowedRegions`. A region outside the set is a
|
|
101
|
+
* **border crossing** (`crossed: true`) — not silently ignored.
|
|
102
|
+
*/
|
|
103
|
+
export async function verifyResidency(
|
|
104
|
+
claim: ResidencyClaim,
|
|
105
|
+
opts: { allowedRegions: string[]; verifyRegion: RegionVerifier },
|
|
106
|
+
): Promise<ResidencyCheck> {
|
|
107
|
+
const reasons: string[] = [];
|
|
108
|
+
if (claim?.v !== 1 || claim.type !== 'residency.claim') {
|
|
109
|
+
return { ok: false, reasons: ['not a residency claim (v1)'], region: null, crossed: false };
|
|
110
|
+
}
|
|
111
|
+
const verified = await opts.verifyRegion(claim.region_attestation);
|
|
112
|
+
if (!verified) {
|
|
113
|
+
return { ok: false, reasons: ['region signal failed the injected verifier'], region: null, crossed: false };
|
|
114
|
+
}
|
|
115
|
+
const inside = opts.allowedRegions.includes(verified.region);
|
|
116
|
+
if (!inside) reasons.push(`region ${verified.region} is OUTSIDE the declared jurisdiction (${opts.allowedRegions.join(', ')}) — border crossed`);
|
|
117
|
+
return { ok: inside, reasons, region: verified.region, crossed: !inside };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Across an ordered sequence of verified regions (each `{ ts, region }`, oldest first),
|
|
122
|
+
* find every point where the region left the declared allow-set. Each crossing names the
|
|
123
|
+
* ts and the region it moved to — the evidence for "when did it leave, and to where."
|
|
124
|
+
*/
|
|
125
|
+
export function detectCrossings(
|
|
126
|
+
sequence: Array<{ ts: string; region: string }>,
|
|
127
|
+
allowedRegions: string[],
|
|
128
|
+
): Array<{ ts: string; region: string; direction: 'exit' | 'return' }> {
|
|
129
|
+
const crossings: Array<{ ts: string; region: string; direction: 'exit' | 'return' }> = [];
|
|
130
|
+
let inside: boolean | null = null;
|
|
131
|
+
const ordered = [...sequence].sort((a, b) => Date.parse(a.ts) - Date.parse(b.ts));
|
|
132
|
+
for (const s of ordered) {
|
|
133
|
+
const now = allowedRegions.includes(s.region);
|
|
134
|
+
if (inside !== null && now !== inside) {
|
|
135
|
+
crossings.push({ ts: s.ts, region: s.region, direction: now ? 'return' : 'exit' });
|
|
136
|
+
}
|
|
137
|
+
inside = now;
|
|
138
|
+
}
|
|
139
|
+
return crossings;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Does an agent's scope permit acting in this region? (`residency.<region>` targets, reusing core.) */
|
|
143
|
+
export function residencyAllowed(effectiveScopes: string[], region: string): boolean {
|
|
144
|
+
return scopesAllow(effectiveScopes, `residency.${region}`);
|
|
145
|
+
}
|