cyphera 0.0.1-alpha.1

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,190 @@
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 the 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 the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Horizon Digital Engineering LLC
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # cyphera
2
+
3
+ Data protection SDK for Node.js — format-preserving encryption (FF1/FF3), AES-GCM, data masking, and hashing. Zero dependencies.
4
+
5
+ ```
6
+ npm install cyphera
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```javascript
12
+ const { Cyphera } = require("cyphera");
13
+
14
+ // Auto-discover: checks CYPHERA_POLICY_FILE env, ./cyphera.json, /etc/cyphera/cyphera.json
15
+ const c = Cyphera.load();
16
+
17
+ // Or load from a specific file
18
+ const c = Cyphera.fromFile("./config/cyphera.json");
19
+
20
+ // Or inline config
21
+ const c = new Cyphera({
22
+ policies: {
23
+ ssn: { engine: "ff1", key_ref: "my-key", tag: "T01" },
24
+ },
25
+ keys: {
26
+ "my-key": { material: "2B7E151628AED2A6ABF7158809CF4F3C" },
27
+ },
28
+ });
29
+
30
+ // Protect
31
+ const encrypted = c.protect("123-45-6789", "ssn");
32
+ // → "T01i6J-xF-07pX" (tagged, dashes preserved)
33
+
34
+ // Access (tag-based, no policy name needed)
35
+ const decrypted = c.access(encrypted);
36
+ // → "123-45-6789"
37
+ ```
38
+
39
+ ## Policy File (cyphera.json)
40
+
41
+ ```json
42
+ {
43
+ "policies": {
44
+ "ssn": { "engine": "ff1", "key_ref": "my-key", "tag": "T01" },
45
+ "cc": { "engine": "ff1", "key_ref": "my-key", "tag": "T02" },
46
+ "ssn_mask": { "engine": "mask", "pattern": "last4", "tag_enabled": false }
47
+ },
48
+ "keys": {
49
+ "my-key": { "material": "2B7E151628AED2A6ABF7158809CF4F3C" }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ## Cross-Language Compatible
55
+
56
+ Java, Rust, and Node produce identical output for the same inputs:
57
+
58
+ ```
59
+ Input: 123-45-6789
60
+ Java: T01i6J-xF-07pX
61
+ Rust: T01i6J-xF-07pX
62
+ Node: T01i6J-xF-07pX
63
+ ```
64
+
65
+ ## Status
66
+
67
+ Alpha. API is unstable. Zero runtime dependencies — pure Node.js `crypto` module.
68
+
69
+ ## License
70
+
71
+ Apache 2.0 — Copyright 2026 Horizon Digital Engineering LLC
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "cyphera",
3
+ "version": "0.0.1-alpha.1",
4
+ "description": "Data protection SDK — format-preserving encryption (FF1/FF3), AES-GCM, data masking, and hashing. Zero dependencies.",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "node --test src/*.test.js"
8
+ },
9
+ "keywords": [
10
+ "encryption",
11
+ "fpe",
12
+ "format-preserving-encryption",
13
+ "data-protection",
14
+ "masking",
15
+ "ff1",
16
+ "ff3",
17
+ "field-level-encryption"
18
+ ],
19
+ "author": "Leslie Gutschow <leslie.gutschow@horizondigital.dev>",
20
+ "homepage": "https://cyphera.io",
21
+ "license": "Apache-2.0",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/cyphera-labs/cyphera-node.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/cyphera-labs/cyphera-node/issues"
28
+ },
29
+ "engines": {
30
+ "node": ">=16.0.0"
31
+ },
32
+ "files": [
33
+ "src/**/*.js",
34
+ "LICENSE",
35
+ "README.md"
36
+ ]
37
+ }
package/src/cyphera.js ADDED
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ const crypto = require("crypto");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { FF1 } = require("./ff1");
6
+ const { FF3 } = require("./ff3");
7
+
8
+ const ALPHABETS = {
9
+ digits: "0123456789",
10
+ alpha_lower: "abcdefghijklmnopqrstuvwxyz",
11
+ alpha_upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
12
+ alpha: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
13
+ alphanumeric: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
14
+ };
15
+
16
+ function resolveAlphabet(name) {
17
+ if (!name) return ALPHABETS.alphanumeric;
18
+ return ALPHABETS[name] || name; // literal custom alphabet if not a known name
19
+ }
20
+
21
+ class Cyphera {
22
+ constructor(config) {
23
+ this._policies = {};
24
+ this._tagIndex = {};
25
+ this._keys = {};
26
+
27
+ // Load keys
28
+ const keys = config.keys || {};
29
+ for (const [name, val] of Object.entries(keys)) {
30
+ const material = typeof val === "string" ? val : val.material;
31
+ this._keys[name] = Buffer.from(material, "hex");
32
+ }
33
+
34
+ // Load policies + build tag index
35
+ const policies = config.policies || {};
36
+ for (const [name, pol] of Object.entries(policies)) {
37
+ const tagEnabled = pol.tag_enabled !== false; // default true
38
+ const tag = pol.tag || null;
39
+
40
+ if (tagEnabled && !tag) {
41
+ throw new Error(`Policy '${name}' has tag_enabled=true but no tag specified`);
42
+ }
43
+
44
+ if (tagEnabled && tag) {
45
+ if (this._tagIndex[tag]) {
46
+ throw new Error(`Tag collision: '${tag}' used by both '${this._tagIndex[tag]}' and '${name}'`);
47
+ }
48
+ this._tagIndex[tag] = name;
49
+ }
50
+
51
+ this._policies[name] = {
52
+ engine: pol.engine || "ff1",
53
+ alphabet: resolveAlphabet(pol.alphabet),
54
+ keyRef: pol.key_ref || null,
55
+ tag,
56
+ tagEnabled,
57
+ tagLength: pol.tag_length || 3,
58
+ pattern: pol.pattern || null,
59
+ algorithm: pol.algorithm || "sha256",
60
+ };
61
+ }
62
+ }
63
+
64
+ protect(value, policyName) {
65
+ const policy = this._getPolicy(policyName);
66
+
67
+ switch (policy.engine) {
68
+ case "ff1": return this._protectFpe(value, policy, false);
69
+ case "ff3": return this._protectFpe(value, policy, true);
70
+ case "mask": return this._protectMask(value, policy);
71
+ case "hash": return this._protectHash(value, policy);
72
+ default: throw new Error(`Unknown engine: ${policy.engine}`);
73
+ }
74
+ }
75
+
76
+ access(protectedValue, policyName) {
77
+ if (policyName) {
78
+ // Explicit policy
79
+ const policy = this._getPolicy(policyName);
80
+ return this._accessFpe(protectedValue, policy);
81
+ }
82
+
83
+ // Tag-based lookup — check longest tags first
84
+ const tags = Object.keys(this._tagIndex).sort((a, b) => b.length - a.length);
85
+ for (const tag of tags) {
86
+ if (protectedValue.startsWith(tag)) {
87
+ const policy = this._getPolicy(this._tagIndex[tag]);
88
+ return this._accessFpe(protectedValue, policy);
89
+ }
90
+ }
91
+
92
+ throw new Error("No matching tag found. Use access(value, policyName) for untagged values.");
93
+ }
94
+
95
+ // ── FPE protect ──
96
+
97
+ _protectFpe(value, policy, isFF3) {
98
+ const key = this._resolveKey(policy.keyRef);
99
+ const alphabet = policy.alphabet;
100
+
101
+ // 1. Strip passthroughs
102
+ const { encryptable, positions, chars } = this._extractPassthroughs(value, alphabet);
103
+
104
+ // 2. Check zero encryptable
105
+ if (encryptable.length === 0) {
106
+ throw new Error("No encryptable characters in input");
107
+ }
108
+
109
+ // 3. Encrypt
110
+ let encrypted;
111
+ if (isFF3) {
112
+ const cipher = new FF3(key, Buffer.alloc(8), alphabet);
113
+ encrypted = cipher.encrypt(encryptable);
114
+ } else {
115
+ const cipher = new FF1(key, Buffer.alloc(0), alphabet);
116
+ encrypted = cipher.encrypt(encryptable);
117
+ }
118
+
119
+ // 4. Reinsert passthroughs
120
+ const withPt = this._reinsertPassthroughs(encrypted, positions, chars);
121
+
122
+ // 5. Prepend tag
123
+ if (policy.tagEnabled && policy.tag) {
124
+ return policy.tag + withPt;
125
+ }
126
+ return withPt;
127
+ }
128
+
129
+ // ── FPE access ──
130
+
131
+ _accessFpe(protectedValue, policy) {
132
+ if (!["ff1", "ff3"].includes(policy.engine)) {
133
+ throw new Error(`Cannot reverse '${policy.engine}' — not reversible`);
134
+ }
135
+
136
+ const key = this._resolveKey(policy.keyRef);
137
+ const alphabet = policy.alphabet;
138
+
139
+ // 1. Strip tag
140
+ let withoutTag = protectedValue;
141
+ if (policy.tagEnabled && policy.tag) {
142
+ withoutTag = protectedValue.slice(policy.tag.length);
143
+ }
144
+
145
+ // 2. Strip passthroughs
146
+ const { encryptable, positions, chars } = this._extractPassthroughs(withoutTag, alphabet);
147
+
148
+ // 3. Decrypt
149
+ let decrypted;
150
+ if (policy.engine === "ff3") {
151
+ const cipher = new FF3(key, Buffer.alloc(8), alphabet);
152
+ decrypted = cipher.decrypt(encryptable);
153
+ } else {
154
+ const cipher = new FF1(key, Buffer.alloc(0), alphabet);
155
+ decrypted = cipher.decrypt(encryptable);
156
+ }
157
+
158
+ // 4. Reinsert passthroughs
159
+ return this._reinsertPassthroughs(decrypted, positions, chars);
160
+ }
161
+
162
+ // ── Mask ──
163
+
164
+ _protectMask(value, policy) {
165
+ if (!policy.pattern) throw new Error("Mask policy requires 'pattern'");
166
+ const len = value.length;
167
+ const mask = "*";
168
+
169
+ switch (policy.pattern) {
170
+ case "last4": case "last_4":
171
+ return mask.repeat(Math.max(0, len - 4)) + value.slice(-4);
172
+ case "last2": case "last_2":
173
+ return mask.repeat(Math.max(0, len - 2)) + value.slice(-2);
174
+ case "first1": case "first_1":
175
+ return value.slice(0, 1) + mask.repeat(Math.max(0, len - 1));
176
+ case "first3": case "first_3":
177
+ return value.slice(0, 3) + mask.repeat(Math.max(0, len - 3));
178
+ case "full":
179
+ default:
180
+ return mask.repeat(len);
181
+ }
182
+ }
183
+
184
+ // ── Hash ──
185
+
186
+ _protectHash(value, policy) {
187
+ const algo = policy.algorithm.replace("-", "").toLowerCase();
188
+ let javaAlgo;
189
+ switch (algo) {
190
+ case "sha256": javaAlgo = "sha256"; break;
191
+ case "sha384": javaAlgo = "sha384"; break;
192
+ case "sha512": javaAlgo = "sha512"; break;
193
+ default: throw new Error(`Unsupported hash algorithm: ${policy.algorithm}`);
194
+ }
195
+
196
+ if (policy.keyRef) {
197
+ const key = this._resolveKey(policy.keyRef);
198
+ const hmac = crypto.createHmac(javaAlgo, key);
199
+ hmac.update(value, "utf8");
200
+ return hmac.digest("hex");
201
+ }
202
+
203
+ const hash = crypto.createHash(javaAlgo);
204
+ hash.update(value, "utf8");
205
+ return hash.digest("hex");
206
+ }
207
+
208
+ // ── Helpers ──
209
+
210
+ _getPolicy(name) {
211
+ const p = this._policies[name];
212
+ if (!p) throw new Error(`Unknown policy: ${name}`);
213
+ return p;
214
+ }
215
+
216
+ _resolveKey(keyRef) {
217
+ if (!keyRef) throw new Error("No key_ref in policy");
218
+ const key = this._keys[keyRef];
219
+ if (!key) throw new Error(`Unknown key: ${keyRef}`);
220
+ return key;
221
+ }
222
+
223
+ _extractPassthroughs(value, alphabet) {
224
+ let encryptable = "";
225
+ const positions = [];
226
+ const chars = [];
227
+
228
+ for (let i = 0; i < value.length; i++) {
229
+ if (alphabet.includes(value[i])) {
230
+ encryptable += value[i];
231
+ } else {
232
+ positions.push(i);
233
+ chars.push(value[i]);
234
+ }
235
+ }
236
+
237
+ return { encryptable, positions, chars };
238
+ }
239
+
240
+ _reinsertPassthroughs(encrypted, positions, chars) {
241
+ let result = encrypted;
242
+ for (let i = 0; i < positions.length; i++) {
243
+ const pos = positions[i];
244
+ if (pos <= result.length) {
245
+ result = result.slice(0, pos) + chars[i] + result.slice(pos);
246
+ } else {
247
+ result += chars[i];
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+ }
253
+
254
+ /**
255
+ * Load from a JSON file path.
256
+ */
257
+ Cyphera.fromFile = function (filePath) {
258
+ const contents = fs.readFileSync(filePath, "utf8");
259
+ const config = JSON.parse(contents);
260
+ return new Cyphera(config);
261
+ };
262
+
263
+ /**
264
+ * Auto-discover policy file using standard precedence:
265
+ * 1. CYPHERA_POLICY_FILE env var
266
+ * 2. ./cyphera.json
267
+ * 3. /etc/cyphera/cyphera.json
268
+ */
269
+ Cyphera.load = function () {
270
+ const envPath = process.env.CYPHERA_POLICY_FILE;
271
+ if (envPath && fs.existsSync(envPath)) {
272
+ return Cyphera.fromFile(envPath);
273
+ }
274
+
275
+ const localPath = path.resolve("cyphera.json");
276
+ if (fs.existsSync(localPath)) {
277
+ return Cyphera.fromFile(localPath);
278
+ }
279
+
280
+ const systemPath = "/etc/cyphera/cyphera.json";
281
+ if (fs.existsSync(systemPath)) {
282
+ return Cyphera.fromFile(systemPath);
283
+ }
284
+
285
+ throw new Error(
286
+ "No policy file found. Checked: CYPHERA_POLICY_FILE env, ./cyphera.json, /etc/cyphera/cyphera.json"
287
+ );
288
+ };
289
+
290
+ module.exports = { Cyphera, ALPHABETS };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ const { describe, it } = require("node:test");
3
+ const assert = require("node:assert");
4
+ const { Cyphera } = require("./cyphera");
5
+
6
+ const config = {
7
+ policies: {
8
+ ssn: { engine: "ff1", key_ref: "test-key", tag: "T01" },
9
+ ssn_digits: { engine: "ff1", alphabet: "digits", tag_enabled: false, key_ref: "test-key" },
10
+ ssn_mask: { engine: "mask", pattern: "last4", tag_enabled: false },
11
+ ssn_hash: { engine: "hash", algorithm: "sha256", key_ref: "test-key", tag_enabled: false },
12
+ },
13
+ keys: {
14
+ "test-key": { material: "2B7E151628AED2A6ABF7158809CF4F3C" },
15
+ },
16
+ };
17
+
18
+ describe("Cyphera SDK", () => {
19
+ it("protect and access with tag", () => {
20
+ const c = new Cyphera(config);
21
+ const protected_ = c.protect("123456789", "ssn");
22
+ assert.ok(protected_.startsWith("T01"));
23
+ assert.ok(protected_.length > "123456789".length);
24
+ const accessed = c.access(protected_);
25
+ assert.strictEqual(accessed, "123456789");
26
+ });
27
+
28
+ it("protect and access with passthroughs", () => {
29
+ const c = new Cyphera(config);
30
+ const protected_ = c.protect("123-45-6789", "ssn");
31
+ assert.ok(protected_.includes("-"));
32
+ const accessed = c.access(protected_);
33
+ assert.strictEqual(accessed, "123-45-6789");
34
+ });
35
+
36
+ it("untagged digits roundtrip", () => {
37
+ const c = new Cyphera(config);
38
+ const protected_ = c.protect("123456789", "ssn_digits");
39
+ assert.strictEqual(protected_.length, 9);
40
+ const accessed = c.access(protected_, "ssn_digits");
41
+ assert.strictEqual(accessed, "123456789");
42
+ });
43
+
44
+ it("deterministic", () => {
45
+ const c = new Cyphera(config);
46
+ const a = c.protect("123456789", "ssn");
47
+ const b = c.protect("123456789", "ssn");
48
+ assert.strictEqual(a, b);
49
+ });
50
+
51
+ it("mask last4", () => {
52
+ const c = new Cyphera(config);
53
+ const result = c.protect("123-45-6789", "ssn_mask");
54
+ assert.strictEqual(result, "*******6789");
55
+ });
56
+
57
+ it("hash deterministic", () => {
58
+ const c = new Cyphera(config);
59
+ const a = c.protect("123-45-6789", "ssn_hash");
60
+ const b = c.protect("123-45-6789", "ssn_hash");
61
+ assert.strictEqual(a, b);
62
+ assert.ok(/^[0-9a-f]+$/.test(a));
63
+ });
64
+
65
+ it("access non-reversible throws", () => {
66
+ const c = new Cyphera(config);
67
+ const masked = c.protect("123-45-6789", "ssn_mask");
68
+ assert.throws(() => c.access(masked), /No matching tag/);
69
+ });
70
+
71
+ it("tag collision throws", () => {
72
+ assert.throws(() => new Cyphera({
73
+ policies: {
74
+ a: { engine: "ff1", key_ref: "k", tag: "ABC" },
75
+ b: { engine: "ff1", key_ref: "k", tag: "ABC" },
76
+ },
77
+ keys: { k: { material: "2B7E151628AED2A6ABF7158809CF4F3C" } },
78
+ }), /Tag collision/);
79
+ });
80
+
81
+ it("tag required when enabled throws", () => {
82
+ assert.throws(() => new Cyphera({
83
+ policies: {
84
+ a: { engine: "ff1", key_ref: "k" },
85
+ },
86
+ keys: { k: { material: "2B7E151628AED2A6ABF7158809CF4F3C" } },
87
+ }), /no tag specified/);
88
+ });
89
+
90
+ it("unicode passthroughs roundtrip", () => {
91
+ const c = new Cyphera(config);
92
+ const protected_ = c.protect("José123456", "ssn");
93
+ const accessed = c.access(protected_);
94
+ assert.strictEqual(accessed, "José123456");
95
+ });
96
+ });
package/src/ff1.js ADDED
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ const crypto = require("crypto");
3
+
4
+ const DIGITS = "0123456789";
5
+ const ALPHANUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz";
6
+
7
+ class FF1 {
8
+ constructor(key, tweak, alphabet = ALPHANUMERIC) {
9
+ if (![16, 24, 32].includes(key.length)) throw new Error("Key must be 16, 24, or 32 bytes");
10
+ if (alphabet.length < 2) throw new Error("Alphabet must have >= 2 chars");
11
+ this.key = key;
12
+ this.tweak = tweak;
13
+ this.alphabet = alphabet;
14
+ this.radix = BigInt(alphabet.length);
15
+ this.charMap = {};
16
+ for (let i = 0; i < alphabet.length; i++) this.charMap[alphabet[i]] = i;
17
+ }
18
+
19
+ encrypt(plaintext) {
20
+ const digits = this._toDigits(plaintext);
21
+ const result = this._ff1Encrypt(digits, this.tweak);
22
+ return this._fromDigits(result);
23
+ }
24
+
25
+ decrypt(ciphertext) {
26
+ const digits = this._toDigits(ciphertext);
27
+ const result = this._ff1Decrypt(digits, this.tweak);
28
+ return this._fromDigits(result);
29
+ }
30
+
31
+ _toDigits(s) { return [...s].map(c => this.charMap[c]); }
32
+ _fromDigits(d) { return d.map(i => this.alphabet[i]).join(""); }
33
+
34
+ _aes(block) {
35
+ const cipher = crypto.createCipheriv(`aes-${this.key.length * 8}-ecb`, this.key, null);
36
+ cipher.setAutoPadding(false);
37
+ return Buffer.concat([cipher.update(block), cipher.final()]);
38
+ }
39
+
40
+ _prf(data) {
41
+ let y = Buffer.alloc(16);
42
+ for (let i = 0; i < data.length; i += 16) {
43
+ const tmp = Buffer.alloc(16);
44
+ for (let j = 0; j < 16; j++) tmp[j] = y[j] ^ data[i + j];
45
+ y = this._aes(tmp);
46
+ }
47
+ return y;
48
+ }
49
+
50
+ _expandS(R, d) {
51
+ const blocks = Math.ceil(d / 16);
52
+ const out = Buffer.alloc(blocks * 16);
53
+ R.copy(out, 0);
54
+ let prev = Buffer.from(R);
55
+ for (let j = 1; j < blocks; j++) {
56
+ const x = Buffer.alloc(16);
57
+ x.writeBigUInt64BE(BigInt(j), 8);
58
+ for (let k = 0; k < 16; k++) x[k] ^= prev[k];
59
+ const enc = this._aes(x);
60
+ enc.copy(out, j * 16);
61
+ prev = enc;
62
+ }
63
+ return out.subarray(0, d);
64
+ }
65
+
66
+ _num(digits) {
67
+ let r = 0n;
68
+ for (const d of digits) r = r * this.radix + BigInt(d);
69
+ return r;
70
+ }
71
+
72
+ _str(num, len) {
73
+ const r = new Array(len).fill(0);
74
+ for (let i = len - 1; i >= 0; i--) { r[i] = Number(num % this.radix); num /= this.radix; }
75
+ return r;
76
+ }
77
+
78
+ _computeB(v) {
79
+ let pow = this.radix ** BigInt(v) - 1n;
80
+ return Math.ceil(pow === 0n ? 1 : Number(pow.toString(2).length) / 8);
81
+ }
82
+
83
+ _buildP(u, n, t) {
84
+ const P = Buffer.alloc(16);
85
+ P[0] = 1; P[1] = 2; P[2] = 1;
86
+ P[3] = Number(this.radix >> 16n) & 0xFF; P[4] = Number(this.radix >> 8n) & 0xFF; P[5] = Number(this.radix) & 0xFF;
87
+ P[6] = 10; P[7] = u;
88
+ P.writeUInt32BE(n, 8);
89
+ P.writeUInt32BE(t, 12);
90
+ return P;
91
+ }
92
+
93
+ _buildQ(T, i, numBytes, b) {
94
+ const pad = (16 - ((T.length + 1 + b) % 16)) % 16;
95
+ const Q = Buffer.alloc(T.length + pad + 1 + b);
96
+ T.copy(Q, 0);
97
+ Q[T.length + pad] = i;
98
+ const start = Math.max(0, numBytes.length - b);
99
+ const dest = Q.length - (numBytes.length - start);
100
+ numBytes.copy(Q, dest, start);
101
+ return Q;
102
+ }
103
+
104
+ _bigIntToBytes(x, b) {
105
+ const hex = x.toString(16).padStart(b * 2, "0");
106
+ return Buffer.from(hex.slice(-b * 2), "hex");
107
+ }
108
+
109
+ _ff1Encrypt(pt, T) {
110
+ const n = pt.length, u = Math.floor(n / 2), v = n - u;
111
+ let A = pt.slice(0, u), B = pt.slice(u);
112
+ const b = this._computeB(v);
113
+ const d = 4 * Math.ceil(b / 4) + 4;
114
+ const P = this._buildP(u, n, T.length);
115
+
116
+ for (let i = 0; i < 10; i++) {
117
+ const numB = this._bigIntToBytes(this._num(B), b);
118
+ const Q = this._buildQ(T, i, numB, b);
119
+ const R = this._prf(Buffer.concat([P, Q]));
120
+ const S = this._expandS(R, d);
121
+ const y = BigInt("0x" + S.toString("hex"));
122
+ const m = i % 2 === 0 ? u : v;
123
+ const c = (this._num(A) + y) % (this.radix ** BigInt(m));
124
+ [A, B] = [B, this._str(c, m)];
125
+ }
126
+ return [...A, ...B];
127
+ }
128
+
129
+ _ff1Decrypt(ct, T) {
130
+ const n = ct.length, u = Math.floor(n / 2), v = n - u;
131
+ let A = ct.slice(0, u), B = ct.slice(u);
132
+ const b = this._computeB(v);
133
+ const d = 4 * Math.ceil(b / 4) + 4;
134
+ const P = this._buildP(u, n, T.length);
135
+
136
+ for (let i = 9; i >= 0; i--) {
137
+ const numA = this._bigIntToBytes(this._num(A), b);
138
+ const Q = this._buildQ(T, i, numA, b);
139
+ const R = this._prf(Buffer.concat([P, Q]));
140
+ const S = this._expandS(R, d);
141
+ const y = BigInt("0x" + S.toString("hex"));
142
+ const m = i % 2 === 0 ? u : v;
143
+ const mod = this.radix ** BigInt(m);
144
+ let c = (this._num(B) - y) % mod;
145
+ if (c < 0n) c += mod;
146
+ [B, A] = [A, this._str(c, m)];
147
+ }
148
+ return [...A, ...B];
149
+ }
150
+ }
151
+
152
+ module.exports = { FF1, DIGITS, ALPHANUMERIC };
@@ -0,0 +1,17 @@
1
+ const { describe, it } = require("node:test");
2
+ const assert = require("node:assert/strict");
3
+ const { FF1, DIGITS, ALPHANUMERIC } = require("./ff1");
4
+
5
+ const hex = (s) => Buffer.from(s, "hex");
6
+
7
+ describe("FF1 NIST Vectors", () => {
8
+ it("sample 1", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3C"), Buffer.alloc(0), DIGITS); assert.equal(c.encrypt("0123456789"), "2433477484"); assert.equal(c.decrypt("2433477484"), "0123456789"); });
9
+ it("sample 2", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3C"), hex("39383736353433323130"), DIGITS); assert.equal(c.encrypt("0123456789"), "6124200773"); assert.equal(c.decrypt("6124200773"), "0123456789"); });
10
+ it("sample 3", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3C"), hex("3737373770717273373737"), ALPHANUMERIC); assert.equal(c.encrypt("0123456789abcdefghi"), "a9tv40mll9kdu509eum"); assert.equal(c.decrypt("a9tv40mll9kdu509eum"), "0123456789abcdefghi"); });
11
+ it("sample 4", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F"), Buffer.alloc(0), DIGITS); assert.equal(c.encrypt("0123456789"), "2830668132"); assert.equal(c.decrypt("2830668132"), "0123456789"); });
12
+ it("sample 5", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F"), hex("39383736353433323130"), DIGITS); assert.equal(c.encrypt("0123456789"), "2496655549"); assert.equal(c.decrypt("2496655549"), "0123456789"); });
13
+ it("sample 6", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F"), hex("3737373770717273373737"), ALPHANUMERIC); assert.equal(c.encrypt("0123456789abcdefghi"), "xbj3kv35jrawxv32ysr"); assert.equal(c.decrypt("xbj3kv35jrawxv32ysr"), "0123456789abcdefghi"); });
14
+ it("sample 7", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F7F036D6F04FC6A94"), Buffer.alloc(0), DIGITS); assert.equal(c.encrypt("0123456789"), "6657667009"); assert.equal(c.decrypt("6657667009"), "0123456789"); });
15
+ it("sample 8", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F7F036D6F04FC6A94"), hex("39383736353433323130"), DIGITS); assert.equal(c.encrypt("0123456789"), "1001623463"); assert.equal(c.decrypt("1001623463"), "0123456789"); });
16
+ it("sample 9", () => { const c = new FF1(hex("2B7E151628AED2A6ABF7158809CF4F3CEF4359D8D580AA4F7F036D6F04FC6A94"), hex("3737373770717273373737"), ALPHANUMERIC); assert.equal(c.encrypt("0123456789abcdefghi"), "xs8a0azh2avyalyzuwd"); assert.equal(c.decrypt("xs8a0azh2avyalyzuwd"), "0123456789abcdefghi"); });
17
+ });
package/src/ff3.js ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ const crypto = require("crypto");
3
+
4
+ const DIGITS = "0123456789";
5
+ const ALPHANUMERIC = "0123456789abcdefghijklmnopqrstuvwxyz";
6
+
7
+ class FF3 {
8
+ constructor(key, tweak, alphabet = ALPHANUMERIC) {
9
+ if (![16, 24, 32].includes(key.length)) throw new Error("Key must be 16, 24, or 32 bytes");
10
+ if (tweak.length !== 8) throw new Error("Tweak must be exactly 8 bytes");
11
+ if (alphabet.length < 2) throw new Error("Alphabet must have >= 2 chars");
12
+ // FF3 reverses the key
13
+ this.key = Buffer.from([...key].reverse());
14
+ this.tweak = tweak;
15
+ this.alphabet = alphabet;
16
+ this.radix = BigInt(alphabet.length);
17
+ this.charMap = {};
18
+ for (let i = 0; i < alphabet.length; i++) this.charMap[alphabet[i]] = i;
19
+ }
20
+
21
+ encrypt(plaintext) {
22
+ const digits = this._toDigits(plaintext);
23
+ return this._fromDigits(this._ff3Encrypt(digits));
24
+ }
25
+
26
+ decrypt(ciphertext) {
27
+ const digits = this._toDigits(ciphertext);
28
+ return this._fromDigits(this._ff3Decrypt(digits));
29
+ }
30
+
31
+ _toDigits(s) { return [...s].map(c => this.charMap[c]); }
32
+ _fromDigits(d) { return d.map(i => this.alphabet[i]).join(""); }
33
+
34
+ _aes(block) {
35
+ const cipher = crypto.createCipheriv(`aes-${this.key.length * 8}-ecb`, this.key, null);
36
+ cipher.setAutoPadding(false);
37
+ return Buffer.concat([cipher.update(block), cipher.final()]);
38
+ }
39
+
40
+ _num(digits) {
41
+ let r = 0n;
42
+ for (const d of digits) r = r * this.radix + BigInt(d);
43
+ return r;
44
+ }
45
+
46
+ _str(num, len) {
47
+ const r = new Array(len).fill(0);
48
+ for (let i = len - 1; i >= 0; i--) { r[i] = Number(num % this.radix); num /= this.radix; }
49
+ return r;
50
+ }
51
+
52
+ _calcP(round, w, half) {
53
+ const input = Buffer.alloc(16);
54
+ w.copy(input, 0);
55
+ input[3] ^= round;
56
+
57
+ const revHalf = [...half].reverse();
58
+ const halfNum = this._num(revHalf);
59
+ let hb;
60
+ if (halfNum === 0n) {
61
+ hb = Buffer.alloc(1);
62
+ } else {
63
+ const hex = halfNum.toString(16);
64
+ hb = Buffer.from(hex.length % 2 ? "0" + hex : hex, "hex");
65
+ }
66
+ if (hb.length <= 12) {
67
+ hb.copy(input, 16 - hb.length);
68
+ } else {
69
+ hb.copy(input, 4, hb.length - 12);
70
+ }
71
+
72
+ const revInput = Buffer.from([...input].reverse());
73
+ const aesOut = this._aes(revInput);
74
+ const revOut = Buffer.from([...aesOut].reverse());
75
+ return BigInt("0x" + revOut.toString("hex"));
76
+ }
77
+
78
+ _ff3Encrypt(pt) {
79
+ const n = pt.length, u = Math.ceil(n / 2), v = n - u;
80
+ let A = pt.slice(0, u), B = pt.slice(u);
81
+
82
+ for (let i = 0; i < 8; i++) {
83
+ const w = i % 2 === 0 ? this.tweak.subarray(4, 8) : this.tweak.subarray(0, 4);
84
+ if (i % 2 === 0) {
85
+ const p = this._calcP(i, w, B);
86
+ const m = this.radix ** BigInt(u);
87
+ const aNum = this._num([...A].reverse());
88
+ const y = (aNum + p) % m;
89
+ A = this._str(y, u).reverse();
90
+ } else {
91
+ const p = this._calcP(i, w, A);
92
+ const m = this.radix ** BigInt(v);
93
+ const bNum = this._num([...B].reverse());
94
+ const y = (bNum + p) % m;
95
+ B = this._str(y, v).reverse();
96
+ }
97
+ }
98
+ return [...A, ...B];
99
+ }
100
+
101
+ _ff3Decrypt(ct) {
102
+ const n = ct.length, u = Math.ceil(n / 2), v = n - u;
103
+ let A = ct.slice(0, u), B = ct.slice(u);
104
+
105
+ for (let i = 7; i >= 0; i--) {
106
+ const w = i % 2 === 0 ? this.tweak.subarray(4, 8) : this.tweak.subarray(0, 4);
107
+ if (i % 2 === 0) {
108
+ const p = this._calcP(i, w, B);
109
+ const m = this.radix ** BigInt(u);
110
+ const aNum = this._num([...A].reverse());
111
+ let y = (aNum - p) % m;
112
+ if (y < 0n) y += m;
113
+ A = this._str(y, u).reverse();
114
+ } else {
115
+ const p = this._calcP(i, w, A);
116
+ const m = this.radix ** BigInt(v);
117
+ const bNum = this._num([...B].reverse());
118
+ let y = (bNum - p) % m;
119
+ if (y < 0n) y += m;
120
+ B = this._str(y, v).reverse();
121
+ }
122
+ }
123
+ return [...A, ...B];
124
+ }
125
+ }
126
+
127
+ module.exports = { FF3, DIGITS, ALPHANUMERIC };
@@ -0,0 +1,30 @@
1
+ const { describe, it } = require("node:test");
2
+ const assert = require("node:assert/strict");
3
+ const { FF3, DIGITS } = require("./ff3");
4
+
5
+ const hex = (s) => Buffer.from(s, "hex");
6
+ const R26 = "0123456789abcdefghijklmnop";
7
+
8
+ function nist(keyHex, tweakHex, alphabet, pt, ct) {
9
+ const c = new FF3(hex(keyHex), hex(tweakHex), alphabet);
10
+ assert.equal(c.encrypt(pt), ct, `encrypt(${pt})`);
11
+ assert.equal(c.decrypt(ct), pt, `decrypt(${ct})`);
12
+ }
13
+
14
+ describe("FF3 NIST Vectors", () => {
15
+ it("s01", () => nist("EF4359D8D580AA4F7F036D6F04FC6A94", "D8E7920AFA330A73", DIGITS, "890121234567890000", "750918814058654607"));
16
+ it("s02", () => nist("EF4359D8D580AA4F7F036D6F04FC6A94", "9A768A92F60E12D8", DIGITS, "890121234567890000", "018989839189395384"));
17
+ it("s03", () => nist("EF4359D8D580AA4F7F036D6F04FC6A94", "D8E7920AFA330A73", DIGITS, "89012123456789000000789000000", "48598367162252569629397416226"));
18
+ it("s04", () => nist("EF4359D8D580AA4F7F036D6F04FC6A94", "0000000000000000", DIGITS, "89012123456789000000789000000", "34695224821734535122613701434"));
19
+ it("s05", () => nist("EF4359D8D580AA4F7F036D6F04FC6A94", "9A768A92F60E12D8", R26, "0123456789abcdefghi", "g2pk40i992fn20cjakb"));
20
+ it("s06", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6", "D8E7920AFA330A73", DIGITS, "890121234567890000", "646965393875028755"));
21
+ it("s07", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6", "9A768A92F60E12D8", DIGITS, "890121234567890000", "961610514491424446"));
22
+ it("s08", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6", "D8E7920AFA330A73", DIGITS, "89012123456789000000789000000", "53048884065350204541786380807"));
23
+ it("s09", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6", "0000000000000000", DIGITS, "89012123456789000000789000000", "98083802678820389295041483512"));
24
+ it("s10", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6", "9A768A92F60E12D8", R26, "0123456789abcdefghi", "i0ihe2jfj7a9opf9p88"));
25
+ it("s11", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "D8E7920AFA330A73", DIGITS, "890121234567890000", "922011205562777495"));
26
+ it("s12", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "9A768A92F60E12D8", DIGITS, "890121234567890000", "504149865578056140"));
27
+ it("s13", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "D8E7920AFA330A73", DIGITS, "89012123456789000000789000000", "04344343235792599165734622699"));
28
+ it("s14", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "0000000000000000", DIGITS, "89012123456789000000789000000", "30859239999374053872365555822"));
29
+ it("s15", () => nist("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6ABF7158809CF4F3C", "9A768A92F60E12D8", R26, "0123456789abcdefghi", "p0b2godfja9bhb7bk38"));
30
+ });
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ const { FF1 } = require("./ff1");
3
+ const { FF3 } = require("./ff3");
4
+ const { Cyphera, ALPHABETS } = require("./cyphera");
5
+
6
+ module.exports = { Cyphera, FF1, FF3, ALPHABETS };