@zanii/subprocessor 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 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,38 @@
1
+ # @zanii/subprocessor
2
+
3
+ **Which third parties actually touched it?** The fear behind every AI DPA — *"you sent my
4
+ data to OpenAI, who sent it where?"* This makes the onward-transfer chain a **first-class
5
+ provable graph**: which downstream processors saw the data, under which agreement, tied to
6
+ the junction. The exact GDPR Art. 28 answer.
7
+
8
+ ```sh
9
+ npm install @zanii/subprocessor @zanii/core
10
+ ```
11
+
12
+ ```ts
13
+ import { buildTransfer, verifyTransfers, subprocessorGraph } from '@zanii/subprocessor';
14
+
15
+ await zanii.record(buildTransfer({ from: 'controller', to: 'openai',
16
+ agreement: { type: 'zero-retention' }, ts: now, ref: dataRef }));
17
+
18
+ // verify the recorded onward chain against your DECLARED subprocessor list:
19
+ const r = verifyTransfers(transfers, ['openai', 'anthropic', 'stripe']);
20
+ r.ok; // false if data reached any party NOT on the declared list — a provable Art. 28 violation
21
+
22
+ subprocessorGraph(transfers, declared); // { parties, edges, undeclared, missing_agreement_id }
23
+ ```
24
+
25
+ Python: `from zanii.subprocessor import build_transfer, verify_transfers, subprocessor_graph`
26
+
27
+ ## The load-bearing check
28
+
29
+ Every `to` must be in the declared subprocessor list. A transfer to an **undeclared** party
30
+ is surfaced (`undeclared`) as a provable violation — discovered by the check, not after a
31
+ breach. dpa/scc transfers with no agreement id are flagged too. Composes
32
+ `@zanii/data-custody`'s `junction` and `@zanii/x402`'s settlement.
33
+
34
+ ## The limit, stated up front
35
+
36
+ Proves the transfers that were **recorded**. It cannot prove an off-record leak — a
37
+ processor that received plaintext and emitted nothing (that's the enclave/broker problem).
38
+ An agreement id is a reference, not a guarantee the counterparty honored it.
@@ -0,0 +1,73 @@
1
+ export interface Agreement {
2
+ /** e.g. `zero-retention`, `dpa`, `scc` (standard contractual clauses). */
3
+ type: 'zero-retention' | 'dpa' | 'scc' | 'other';
4
+ /** The agreement identifier/reference. */
5
+ id?: string;
6
+ }
7
+ export interface Transfer {
8
+ v: 1;
9
+ type: 'subprocessor.transfer';
10
+ /** Optional data-object ref (`@zanii/data-custody`) this transfer moved. */
11
+ ref?: string;
12
+ /** The party disclosing (a DID, a processor name). */
13
+ from: string;
14
+ /** The party receiving — must be in the declared subprocessor list. */
15
+ to: string;
16
+ agreement: Agreement;
17
+ /** Optional destination region (compose with `@zanii/residency`). */
18
+ region?: string;
19
+ /** Optional settlement/junction reference (`@zanii/x402` tx, an API-call id). */
20
+ junction?: string;
21
+ ts: string;
22
+ }
23
+ export interface TransferInput {
24
+ from: string;
25
+ to: string;
26
+ agreement: Agreement;
27
+ ts: string;
28
+ ref?: string;
29
+ region?: string;
30
+ junction?: string;
31
+ }
32
+ /** Build one onward-transfer record. Record it; the `to` is checked against your declared list. */
33
+ export declare function buildTransfer(input: TransferInput): {
34
+ target: string;
35
+ payload: Record<string, unknown>;
36
+ };
37
+ export declare function transferHash(t: Transfer): string;
38
+ export interface SubprocessorGraph {
39
+ /** Every party that appears (as sender or receiver). */
40
+ parties: string[];
41
+ /** The recorded hops. */
42
+ edges: Array<{
43
+ from: string;
44
+ to: string;
45
+ agreement: Agreement;
46
+ ts: string;
47
+ }>;
48
+ /** Receivers NOT in the declared subprocessor list — the violations. */
49
+ undeclared: string[];
50
+ /** Transfers with no agreement id where one is required (dpa/scc). */
51
+ missing_agreement_id: Array<{
52
+ to: string;
53
+ ts: string;
54
+ }>;
55
+ }
56
+ /**
57
+ * Build the onward-transfer graph and check it against the **declared** subprocessor
58
+ * allow-list. `undeclared` is the load-bearing output: any receiver not on the list is a
59
+ * provable Art. 28 violation. `missing_agreement_id` flags dpa/scc transfers with no id.
60
+ * Pure — pass the transfers you recorded (from the ledger).
61
+ */
62
+ export declare function subprocessorGraph(transfers: Transfer[], declared: string[]): SubprocessorGraph;
63
+ export interface TransferCheck {
64
+ ok: boolean;
65
+ reasons: string[];
66
+ }
67
+ /**
68
+ * The compliance verdict for one data object's transfers: every receiver is declared, and
69
+ * every dpa/scc transfer carries an agreement id. `ok` means the recorded onward chain is
70
+ * clean; it does not assert no off-record transfer happened (see the limit).
71
+ */
72
+ export declare function verifyTransfers(transfers: Transfer[], declared: string[]): TransferCheck;
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,SAAS;IACxB,0EAA0E;IAC1E,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,CAAC;IACjD,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,uBAAuB,CAAC;IAC9B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,SAAS,CAAC;IACrB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,SAAS,CAAC;IACrB,EAAE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The fear behind every AI DPA: "you sent my data to OpenAI, who sent it where?" This
5
+ * makes the onward-transfer chain a **first-class provable graph** — which downstream
6
+ * processors saw the data, under which agreement (zero-retention, a DPA id), tied to the
7
+ * junction. It extends `@zanii/data-custody`'s `junction` field and `@zanii/x402`'s
8
+ * settlement into the exact GDPR Art. 28 answer buyers want.
9
+ *
10
+ * A **transfer** is one hop: `from → to`, under an `agreement`, at a time. Transfers form
11
+ * a graph (a controller → OpenAI → OpenAI's own subprocessors). The load-bearing check:
12
+ * every `to` must appear in the **declared subprocessor list**; a transfer to an
13
+ * undeclared party is a provable, flagged violation — not discovered after a breach.
14
+ *
15
+ * ## The limit, stated up front
16
+ *
17
+ * This proves the transfers that were **recorded**. It cannot prove an off-record leak —
18
+ * a processor that received plaintext and emitted no transfer receipt. That residual is
19
+ * the credential-custody / enclave problem (`@zanii/broker`, `@zanii/attest`), unchanged.
20
+ * And an agreement id is a reference, not a guarantee the counterparty honored it.
21
+ */
22
+ import { jcsHash } from '@zanii/core';
23
+ /** Build one onward-transfer record. Record it; the `to` is checked against your declared list. */
24
+ export function buildTransfer(input) {
25
+ if (!input.from || !input.to)
26
+ throw new Error('from and to are required');
27
+ if (input.from === input.to)
28
+ throw new Error('a transfer must cross parties (from != to)');
29
+ if (!input.agreement?.type)
30
+ throw new Error('agreement.type is required');
31
+ if (Number.isNaN(Date.parse(input.ts)))
32
+ throw new Error('ts must be an ISO timestamp');
33
+ const t = {
34
+ v: 1,
35
+ type: 'subprocessor.transfer',
36
+ from: input.from,
37
+ to: input.to,
38
+ agreement: input.agreement,
39
+ ts: input.ts,
40
+ };
41
+ if (input.ref !== undefined)
42
+ t.ref = input.ref;
43
+ if (input.region !== undefined)
44
+ t.region = input.region;
45
+ if (input.junction !== undefined)
46
+ t.junction = input.junction;
47
+ return { target: `subprocessor.transfer.${input.agreement.type}`, payload: t };
48
+ }
49
+ export function transferHash(t) {
50
+ return jcsHash(t);
51
+ }
52
+ /**
53
+ * Build the onward-transfer graph and check it against the **declared** subprocessor
54
+ * allow-list. `undeclared` is the load-bearing output: any receiver not on the list is a
55
+ * provable Art. 28 violation. `missing_agreement_id` flags dpa/scc transfers with no id.
56
+ * Pure — pass the transfers you recorded (from the ledger).
57
+ */
58
+ export function subprocessorGraph(transfers, declared) {
59
+ const parties = new Set();
60
+ const edges = [];
61
+ const undeclared = new Set();
62
+ const missing = [];
63
+ for (const t of transfers) {
64
+ parties.add(t.from);
65
+ parties.add(t.to);
66
+ edges.push({ from: t.from, to: t.to, agreement: t.agreement, ts: t.ts });
67
+ if (!declared.includes(t.to))
68
+ undeclared.add(t.to);
69
+ if ((t.agreement.type === 'dpa' || t.agreement.type === 'scc') && !t.agreement.id) {
70
+ missing.push({ to: t.to, ts: t.ts });
71
+ }
72
+ }
73
+ return {
74
+ parties: [...parties].sort(),
75
+ edges: edges.sort((a, b) => Date.parse(a.ts) - Date.parse(b.ts)),
76
+ undeclared: [...undeclared].sort(),
77
+ missing_agreement_id: missing,
78
+ };
79
+ }
80
+ /**
81
+ * The compliance verdict for one data object's transfers: every receiver is declared, and
82
+ * every dpa/scc transfer carries an agreement id. `ok` means the recorded onward chain is
83
+ * clean; it does not assert no off-record transfer happened (see the limit).
84
+ */
85
+ export function verifyTransfers(transfers, declared) {
86
+ const g = subprocessorGraph(transfers, declared);
87
+ const reasons = [];
88
+ for (const u of g.undeclared)
89
+ reasons.push(`data reached '${u}', which is NOT a declared subprocessor`);
90
+ for (const m of g.missing_agreement_id)
91
+ reasons.push(`transfer to '${m.to}' at ${m.ts} has no agreement id (dpa/scc requires one)`);
92
+ return { ok: reasons.length === 0, reasons };
93
+ }
94
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAoCtC,mGAAmG;AACnG,MAAM,UAAU,a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,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAChE,UAAU,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE;QAClC,oBAAoB,EAAE,OAAO;KAC9B,CAAC;AACJ,CAAC;AAOD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,SAAqB,EAAE,QAAkB;IACvE,MAAM,CAAC,GAAG,iBAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,yCAAyC,CAAC,CAAC;IACxG,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,oBAAoB;QAAE,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,6CAA6C,CAAC,CAAC;IACpI,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;AAC/C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@zanii/subprocessor",
3
+ "version": "0.1.0",
4
+ "description": "Prove the onward-transfer chain - which downstream processors actually saw the data, under which agreement (zero-retention, DPA id), tied to the junction/settlement. Answers the exact GDPR Art. 28 question every AI DPA raises: 'you sent my data to OpenAI, who sent it where?' A transfer to a party not in the declared subprocessor list is a provable, flagged violation. Proves recorded transfers; an off-record leak needs an attested enclave.",
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,137 @@
1
+ /**
2
+ * @zanii/subprocessor — which third parties actually touched it?
3
+ *
4
+ * The fear behind every AI DPA: "you sent my data to OpenAI, who sent it where?" This
5
+ * makes the onward-transfer chain a **first-class provable graph** — which downstream
6
+ * processors saw the data, under which agreement (zero-retention, a DPA id), tied to the
7
+ * junction. It extends `@zanii/data-custody`'s `junction` field and `@zanii/x402`'s
8
+ * settlement into the exact GDPR Art. 28 answer buyers want.
9
+ *
10
+ * A **transfer** is one hop: `from → to`, under an `agreement`, at a time. Transfers form
11
+ * a graph (a controller → OpenAI → OpenAI's own subprocessors). The load-bearing check:
12
+ * every `to` must appear in the **declared subprocessor list**; a transfer to an
13
+ * undeclared party is a provable, flagged violation — not discovered after a breach.
14
+ *
15
+ * ## The limit, stated up front
16
+ *
17
+ * This proves the transfers that were **recorded**. It cannot prove an off-record leak —
18
+ * a processor that received plaintext and emitted no transfer receipt. That residual is
19
+ * the credential-custody / enclave problem (`@zanii/broker`, `@zanii/attest`), unchanged.
20
+ * And an agreement id is a reference, not a guarantee the counterparty honored it.
21
+ */
22
+ import { jcsHash } from '@zanii/core';
23
+
24
+ export interface Agreement {
25
+ /** e.g. `zero-retention`, `dpa`, `scc` (standard contractual clauses). */
26
+ type: 'zero-retention' | 'dpa' | 'scc' | 'other';
27
+ /** The agreement identifier/reference. */
28
+ id?: string;
29
+ }
30
+
31
+ export interface Transfer {
32
+ v: 1;
33
+ type: 'subprocessor.transfer';
34
+ /** Optional data-object ref (`@zanii/data-custody`) this transfer moved. */
35
+ ref?: string;
36
+ /** The party disclosing (a DID, a processor name). */
37
+ from: string;
38
+ /** The party receiving — must be in the declared subprocessor list. */
39
+ to: string;
40
+ agreement: Agreement;
41
+ /** Optional destination region (compose with `@zanii/residency`). */
42
+ region?: string;
43
+ /** Optional settlement/junction reference (`@zanii/x402` tx, an API-call id). */
44
+ junction?: string;
45
+ ts: string;
46
+ }
47
+
48
+ export interface TransferInput {
49
+ from: string;
50
+ to: string;
51
+ agreement: Agreement;
52
+ ts: string;
53
+ ref?: string;
54
+ region?: string;
55
+ junction?: string;
56
+ }
57
+
58
+ /** Build one onward-transfer record. Record it; the `to` is checked against your declared list. */
59
+ export function buildTransfer(input: TransferInput): { target: string; payload: Record<string, unknown> } {
60
+ if (!input.from || !input.to) throw new Error('from and to are required');
61
+ if (input.from === input.to) throw new Error('a transfer must cross parties (from != to)');
62
+ if (!input.agreement?.type) throw new Error('agreement.type is required');
63
+ if (Number.isNaN(Date.parse(input.ts))) throw new Error('ts must be an ISO timestamp');
64
+ const t: Transfer = {
65
+ v: 1,
66
+ type: 'subprocessor.transfer',
67
+ from: input.from,
68
+ to: input.to,
69
+ agreement: input.agreement,
70
+ ts: input.ts,
71
+ };
72
+ if (input.ref !== undefined) t.ref = input.ref;
73
+ if (input.region !== undefined) t.region = input.region;
74
+ if (input.junction !== undefined) t.junction = input.junction;
75
+ return { target: `subprocessor.transfer.${input.agreement.type}`, payload: t as unknown as Record<string, unknown> };
76
+ }
77
+
78
+ export function transferHash(t: Transfer): string {
79
+ return jcsHash(t as unknown as Record<string, unknown>);
80
+ }
81
+
82
+ export interface SubprocessorGraph {
83
+ /** Every party that appears (as sender or receiver). */
84
+ parties: string[];
85
+ /** The recorded hops. */
86
+ edges: Array<{ from: string; to: string; agreement: Agreement; ts: string }>;
87
+ /** Receivers NOT in the declared subprocessor list — the violations. */
88
+ undeclared: string[];
89
+ /** Transfers with no agreement id where one is required (dpa/scc). */
90
+ missing_agreement_id: Array<{ to: string; ts: string }>;
91
+ }
92
+
93
+ /**
94
+ * Build the onward-transfer graph and check it against the **declared** subprocessor
95
+ * allow-list. `undeclared` is the load-bearing output: any receiver not on the list is a
96
+ * provable Art. 28 violation. `missing_agreement_id` flags dpa/scc transfers with no id.
97
+ * Pure — pass the transfers you recorded (from the ledger).
98
+ */
99
+ export function subprocessorGraph(transfers: Transfer[], declared: string[]): SubprocessorGraph {
100
+ const parties = new Set<string>();
101
+ const edges: SubprocessorGraph['edges'] = [];
102
+ const undeclared = new Set<string>();
103
+ const missing: SubprocessorGraph['missing_agreement_id'] = [];
104
+ for (const t of transfers) {
105
+ parties.add(t.from);
106
+ parties.add(t.to);
107
+ edges.push({ from: t.from, to: t.to, agreement: t.agreement, ts: t.ts });
108
+ if (!declared.includes(t.to)) undeclared.add(t.to);
109
+ if ((t.agreement.type === 'dpa' || t.agreement.type === 'scc') && !t.agreement.id) {
110
+ missing.push({ to: t.to, ts: t.ts });
111
+ }
112
+ }
113
+ return {
114
+ parties: [...parties].sort(),
115
+ edges: edges.sort((a, b) => Date.parse(a.ts) - Date.parse(b.ts)),
116
+ undeclared: [...undeclared].sort(),
117
+ missing_agreement_id: missing,
118
+ };
119
+ }
120
+
121
+ export interface TransferCheck {
122
+ ok: boolean;
123
+ reasons: string[];
124
+ }
125
+
126
+ /**
127
+ * The compliance verdict for one data object's transfers: every receiver is declared, and
128
+ * every dpa/scc transfer carries an agreement id. `ok` means the recorded onward chain is
129
+ * clean; it does not assert no off-record transfer happened (see the limit).
130
+ */
131
+ export function verifyTransfers(transfers: Transfer[], declared: string[]): TransferCheck {
132
+ const g = subprocessorGraph(transfers, declared);
133
+ const reasons: string[] = [];
134
+ for (const u of g.undeclared) reasons.push(`data reached '${u}', which is NOT a declared subprocessor`);
135
+ for (const m of g.missing_agreement_id) reasons.push(`transfer to '${m.to}' at ${m.ts} has no agreement id (dpa/scc requires one)`);
136
+ return { ok: reasons.length === 0, reasons };
137
+ }