@atlasauth/pca-abe 0.2.0 → 0.4.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/README.md +19 -4
- package/dist/abe.d.ts +83 -42
- package/dist/abe.js +290 -117
- package/dist/abe.js.map +1 -1
- package/dist/aead.js +1 -1
- package/dist/aead.js.map +1 -1
- package/dist/attributes.d.ts +28 -7
- package/dist/attributes.js +48 -27
- package/dist/attributes.js.map +1 -1
- package/dist/bls.d.ts +35 -12
- package/dist/bls.js +81 -11
- package/dist/bls.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/pca.d.ts +3 -2
- package/dist/pca.js.map +1 -1
- package/dist/policy.d.ts +7 -0
- package/dist/policy.js +21 -4
- package/dist/policy.js.map +1 -1
- package/dist/sss.d.ts +6 -0
- package/dist/sss.js +33 -19
- package/dist/sss.js.map +1 -1
- package/dist/wire.d.ts +0 -2
- package/dist/wire.js +0 -10
- package/dist/wire.js.map +1 -1
- package/package.json +3 -2
- package/dist/ibe.d.ts +0 -24
- package/dist/ibe.js +0 -71
- package/dist/ibe.js.map +0 -1
package/dist/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":";;;AAiDA,0CA2DC;AAOD,8BAKC;AAGD,4CAIC;AA/HD,+BAAyC;AACzC,iCAAsD;AAiCtD,oFAAoF;AACvE,QAAA,gBAAgB,GAAG,IAAI,CAAC;AAErC;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEnC;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAAe;IAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,SAAS,IAAI,CAAC,CAAU,EAAE,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AED,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IACvC,IAAI,IAAI,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CAAC,IAAmB,EAAE,KAA0B;IACvE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,EAAE;QAAE,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;YAAE,GAAG,EAAE,CAAC;IAChE,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,oGAAoG;AACpG,SAAgB,gBAAgB,CAAC,IAAmB,EAAE,OAAoB,IAAI,GAAG,EAAE;IACjF,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QACzC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,EAAE;YAAE,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/sss.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export declare function splitSecret(secret: bigint, t: number, n: number): Share
|
|
|
22
22
|
* original secret; with duplicate x's it returns null (fail-closed).
|
|
23
23
|
*/
|
|
24
24
|
export declare function recoverSecret(shares: Share[]): bigint | null;
|
|
25
|
+
/**
|
|
26
|
+
* Lagrange coefficients `L_i(0) = prod_{j != i} x_j / (x_j - x_i)` for the evaluation points `xs`. The same
|
|
27
|
+
* coefficients interpolate "in the exponent" (the pairing-based DecryptNode of Bethencourt-Sahai-Waters).
|
|
28
|
+
* Null (fail-closed) on an empty set, a zero point, or points that coincide as field elements.
|
|
29
|
+
*/
|
|
30
|
+
export declare function lagrangeAtZero(xs: readonly bigint[]): bigint[] | null;
|
|
25
31
|
/** Convenience: a fresh random secret scalar together with its 32-byte big-endian encoding. */
|
|
26
32
|
export declare function randomSecret(): {
|
|
27
33
|
scalar: bigint;
|
package/dist/sss.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.splitSecret = splitSecret;
|
|
4
4
|
exports.recoverSecret = recoverSecret;
|
|
5
|
+
exports.lagrangeAtZero = lagrangeAtZero;
|
|
5
6
|
exports.randomSecret = randomSecret;
|
|
6
7
|
const bls_1 = require("./bls");
|
|
7
8
|
/**
|
|
@@ -33,38 +34,51 @@ function splitSecret(secret, t, n) {
|
|
|
33
34
|
* original secret; with duplicate x's it returns null (fail-closed).
|
|
34
35
|
*/
|
|
35
36
|
function recoverSecret(shares) {
|
|
36
|
-
|
|
37
|
+
const coeffs = lagrangeAtZero(shares.map((s) => s.x));
|
|
38
|
+
if (coeffs === null)
|
|
39
|
+
return null;
|
|
40
|
+
let secret = 0n;
|
|
41
|
+
for (let i = 0; i < shares.length; i++) {
|
|
42
|
+
const si = shares[i];
|
|
43
|
+
const ci = coeffs[i];
|
|
44
|
+
if (si === undefined || ci === undefined)
|
|
45
|
+
return null;
|
|
46
|
+
secret = (0, bls_1.frAdd)(secret, (0, bls_1.frMul)(si.y, ci));
|
|
47
|
+
}
|
|
48
|
+
return secret;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Lagrange coefficients `L_i(0) = prod_{j != i} x_j / (x_j - x_i)` for the evaluation points `xs`. The same
|
|
52
|
+
* coefficients interpolate "in the exponent" (the pairing-based DecryptNode of Bethencourt-Sahai-Waters).
|
|
53
|
+
* Null (fail-closed) on an empty set, a zero point, or points that coincide as field elements.
|
|
54
|
+
*/
|
|
55
|
+
function lagrangeAtZero(xs) {
|
|
56
|
+
if (xs.length === 0)
|
|
37
57
|
return null;
|
|
38
58
|
const seen = new Set();
|
|
39
|
-
for (const
|
|
40
|
-
|
|
59
|
+
for (const x of xs) {
|
|
60
|
+
// Compare evaluation points as FIELD elements: x and x + r are the same point (and would make a Lagrange denominator 0).
|
|
61
|
+
const xr = (0, bls_1.frCreate)(x);
|
|
62
|
+
if (xr === 0n)
|
|
41
63
|
return null;
|
|
42
|
-
const k =
|
|
64
|
+
const k = xr.toString();
|
|
43
65
|
if (seen.has(k))
|
|
44
66
|
return null;
|
|
45
67
|
seen.add(k);
|
|
46
68
|
}
|
|
47
|
-
|
|
48
|
-
for (let i = 0; i <
|
|
49
|
-
const si = shares[i];
|
|
50
|
-
if (si === undefined)
|
|
51
|
-
return null;
|
|
52
|
-
// Lagrange basis L_i(0) = prod_{j != i} x_j / (x_j - x_i).
|
|
69
|
+
const out = [];
|
|
70
|
+
for (let i = 0; i < xs.length; i++) {
|
|
53
71
|
let num = 1n;
|
|
54
72
|
let den = 1n;
|
|
55
|
-
for (let j = 0; j <
|
|
73
|
+
for (let j = 0; j < xs.length; j++) {
|
|
56
74
|
if (j === i)
|
|
57
75
|
continue;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return null;
|
|
61
|
-
num = (0, bls_1.frMul)(num, sj.x);
|
|
62
|
-
den = (0, bls_1.frMul)(den, (0, bls_1.frSub)(sj.x, si.x));
|
|
76
|
+
num = (0, bls_1.frMul)(num, xs[j] ?? 0n);
|
|
77
|
+
den = (0, bls_1.frMul)(den, (0, bls_1.frSub)(xs[j] ?? 0n, xs[i] ?? 0n));
|
|
63
78
|
}
|
|
64
|
-
|
|
65
|
-
secret = (0, bls_1.frAdd)(secret, (0, bls_1.frMul)(si.y, coeff));
|
|
79
|
+
out.push((0, bls_1.frMul)(num, (0, bls_1.frInv)(den)));
|
|
66
80
|
}
|
|
67
|
-
return
|
|
81
|
+
return out;
|
|
68
82
|
}
|
|
69
83
|
/** Convenience: a fresh random secret scalar together with its 32-byte big-endian encoding. */
|
|
70
84
|
function randomSecret() {
|
package/dist/sss.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sss.js","sourceRoot":"","sources":["../src/sss.ts"],"names":[],"mappings":";;AAqBA,kCAgBC;AAOD,
|
|
1
|
+
{"version":3,"file":"sss.js","sourceRoot":"","sources":["../src/sss.ts"],"names":[],"mappings":";;AAqBA,kCAgBC;AAOD,sCAWC;AAOD,wCAuBC;AAGD,oCAGC;AA3FD,+BAA0F;AAiB1F;;;GAGG;AACH,SAAgB,WAAW,CAAC,MAAc,EAAE,CAAS,EAAE,CAAS;IAC9D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5E,MAAM,IAAI,UAAU,CAAC,4BAA4B,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;IACD,kDAAkD;IAClD,MAAM,MAAM,GAAa,CAAC,MAAM,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAAE,MAAM,CAAC,IAAI,CAAC,IAAA,kBAAY,GAAE,CAAC,CAAC;IACxD,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,oCAAoC;QACpC,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC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AE,CAAC;AAClD,CAAC"}
|
package/dist/wire.d.ts
CHANGED
|
@@ -10,5 +10,3 @@ export declare function unb64u(s: unknown): Uint8Array | null;
|
|
|
10
10
|
export declare function isObject(x: unknown): x is Record<string, unknown>;
|
|
11
11
|
export declare function isString(x: unknown): x is string;
|
|
12
12
|
export declare function isPosInt(x: unknown): x is number;
|
|
13
|
-
/** XOR two equal-length byte arrays; null if lengths differ. */
|
|
14
|
-
export declare function xorBytes(a: Uint8Array, b: Uint8Array): Uint8Array | null;
|
package/dist/wire.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.unb64u = unb64u;
|
|
|
10
10
|
exports.isObject = isObject;
|
|
11
11
|
exports.isString = isString;
|
|
12
12
|
exports.isPosInt = isPosInt;
|
|
13
|
-
exports.xorBytes = xorBytes;
|
|
14
13
|
/** Encode bytes as unpadded base64url. */
|
|
15
14
|
function b64u(bytes) {
|
|
16
15
|
return Buffer.from(bytes).toString('base64url');
|
|
@@ -41,13 +40,4 @@ function isString(x) {
|
|
|
41
40
|
function isPosInt(x) {
|
|
42
41
|
return typeof x === 'number' && Number.isInteger(x) && x > 0;
|
|
43
42
|
}
|
|
44
|
-
/** XOR two equal-length byte arrays; null if lengths differ. */
|
|
45
|
-
function xorBytes(a, b) {
|
|
46
|
-
if (a.length !== b.length)
|
|
47
|
-
return null;
|
|
48
|
-
const out = new Uint8Array(a.length);
|
|
49
|
-
for (let i = 0; i < a.length; i++)
|
|
50
|
-
out[i] = (a[i] ?? 0) ^ (b[i] ?? 0);
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
43
|
//# sourceMappingURL=wire.js.map
|
package/dist/wire.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAGH,oBAEC;AAGD,wBAWC;AAED,4BAEC;AAED,4BAEC;AAED,4BAEC;
|
|
1
|
+
{"version":3,"file":"wire.js","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-1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlasauth/pca-abe",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Proof-carrying encryption for PCA: attribute/policy-based encryption on BLS12-381 so a tool payload decrypts only for a holder whose capability satisfies the policy — binding confidentiality to proven authority.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"attribute-based encryption",
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@noble/curves": "^1.6.0",
|
|
35
35
|
"@noble/hashes": "^1.5.0",
|
|
36
|
-
"@atlasauth/pca": "0.
|
|
36
|
+
"@atlasauth/pca": "0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
+
"fast-check": "^3.23.1",
|
|
39
40
|
"typescript": "^5.6.3",
|
|
40
41
|
"vitest": "^2.1.4"
|
|
41
42
|
},
|
package/dist/ibe.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type G1Point } from './bls';
|
|
2
|
-
/** A per-leaf encapsulation: the ephemeral `U` (G2, compressed) that pins the derived KEM key. */
|
|
3
|
-
export interface Encapsulation {
|
|
4
|
-
/** Compressed G2 ephemeral `U = x * g2`. */
|
|
5
|
-
U: Uint8Array;
|
|
6
|
-
/** 32-byte symmetric key derived from the GT secret (encryptor side). */
|
|
7
|
-
key: Uint8Array;
|
|
8
|
-
}
|
|
9
|
-
/** Compute `P_pub = s * g2` (the master public element) for master secret `s`. */
|
|
10
|
-
export declare function masterPublic(s: bigint): Uint8Array;
|
|
11
|
-
/** Issue the BF decryption key `d_A = s * H1(A)` (G1, compressed) for attribute `A`. */
|
|
12
|
-
export declare function keygenAttr(s: bigint, attr: string): Uint8Array;
|
|
13
|
-
/**
|
|
14
|
-
* Encapsulate to attribute `A` under master public `pPubBytes`. Returns the ephemeral `U` and the
|
|
15
|
-
* 32-byte KEM key. `salt` is the ciphertext-wide HKDF salt (bound into every derived key). Returns null
|
|
16
|
-
* only if `pPubBytes` is not a valid G2 point.
|
|
17
|
-
*/
|
|
18
|
-
export declare function encapsulate(pPubBytes: Uint8Array, attr: string, salt: Uint8Array): Encapsulation | null;
|
|
19
|
-
/**
|
|
20
|
-
* Decapsulate: recover the 32-byte KEM key from decryption key `dA` (G1) and ephemeral `uBytes` (G2).
|
|
21
|
-
* Returns null (fail-closed) if either point is malformed. The attribute string must match the one used
|
|
22
|
-
* at encapsulation (it is bound into the KDF).
|
|
23
|
-
*/
|
|
24
|
-
export declare function decapsulate(dA: G1Point, attr: string, uBytes: Uint8Array, salt: Uint8Array): Uint8Array | null;
|
package/dist/ibe.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.masterPublic = masterPublic;
|
|
4
|
-
exports.keygenAttr = keygenAttr;
|
|
5
|
-
exports.encapsulate = encapsulate;
|
|
6
|
-
exports.decapsulate = decapsulate;
|
|
7
|
-
const bls_1 = require("./bls");
|
|
8
|
-
/**
|
|
9
|
-
* Boneh-Franklin Identity-Based Encryption as a Key-Encapsulation Mechanism (BF-IBE KEM) on BLS12-381.
|
|
10
|
-
*
|
|
11
|
-
* Treat each ATTRIBUTE string as a BF "identity". For master secret `s` and public `P_pub = s * g2`:
|
|
12
|
-
* - the decryption key for attribute `A` is `d_A = s * H1(A)` in G1 (issued by `keygen`),
|
|
13
|
-
* - encapsulation to `A` picks a fresh ephemeral `x`, publishes `U = x * g2` in G2, and derives the
|
|
14
|
-
* shared GT secret `K_GT = e(H1(A), P_pub)^x = e(H1(A), g2)^{s*x}`,
|
|
15
|
-
* - decapsulation with `d_A` recomputes `K_GT = e(d_A, U) = e(s*H1(A), x*g2) = e(H1(A), g2)^{s*x}`.
|
|
16
|
-
*
|
|
17
|
-
* The two sides agree, and a holder WITHOUT `d_A` cannot compute `K_GT` without solving Bilinear
|
|
18
|
-
* Diffie-Hellman. The GT secret is run through HKDF-SHA256 (modelled as a random oracle) to a 32-byte
|
|
19
|
-
* symmetric key that masks the payload share.
|
|
20
|
-
*
|
|
21
|
-
* SECURITY: confidentiality holds under the Bilinear Diffie-Hellman assumption in the random-oracle
|
|
22
|
-
* model (standard BF-IBE). This is NOT a proof of knowledge / NIZK: it binds confidentiality to
|
|
23
|
-
* possession of attribute keys, not to an interactive or non-interactive proof.
|
|
24
|
-
*/
|
|
25
|
-
const KEM_KDF_INFO = 'atlas-pca-abe/kem/v1';
|
|
26
|
-
/** Compute `P_pub = s * g2` (the master public element) for master secret `s`. */
|
|
27
|
-
function masterPublic(s) {
|
|
28
|
-
return (0, bls_1.g2ToBytes)((0, bls_1.g2Mul)(bls_1.G2_BASE, s));
|
|
29
|
-
}
|
|
30
|
-
/** Issue the BF decryption key `d_A = s * H1(A)` (G1, compressed) for attribute `A`. */
|
|
31
|
-
function keygenAttr(s, attr) {
|
|
32
|
-
const qA = (0, bls_1.hashAttrToG1)(attr);
|
|
33
|
-
return (0, bls_1.g1ToBytes)(qA.multiply(s));
|
|
34
|
-
}
|
|
35
|
-
function kemKey(gtBytes, salt, attr, uBytes) {
|
|
36
|
-
// Bind the derived key to BOTH the attribute and the specific ephemeral so a key cannot be replayed
|
|
37
|
-
// across attributes or ciphertexts even if (hypothetically) a GT value repeated.
|
|
38
|
-
const info = `${KEM_KDF_INFO}|${attr}|${Buffer.from(uBytes).toString('base64url')}`;
|
|
39
|
-
return (0, bls_1.kdf32)(gtBytes, salt, info);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Encapsulate to attribute `A` under master public `pPubBytes`. Returns the ephemeral `U` and the
|
|
43
|
-
* 32-byte KEM key. `salt` is the ciphertext-wide HKDF salt (bound into every derived key). Returns null
|
|
44
|
-
* only if `pPubBytes` is not a valid G2 point.
|
|
45
|
-
*/
|
|
46
|
-
function encapsulate(pPubBytes, attr, salt) {
|
|
47
|
-
const pPub = (0, bls_1.g2FromBytes)(pPubBytes);
|
|
48
|
-
if (pPub === null)
|
|
49
|
-
return null;
|
|
50
|
-
const qA = (0, bls_1.hashAttrToG1)(attr);
|
|
51
|
-
const x = (0, bls_1.randomScalar)();
|
|
52
|
-
const uBytes = (0, bls_1.g2ToBytes)((0, bls_1.g2Mul)(bls_1.G2_BASE, x));
|
|
53
|
-
// K_GT = e(Q_A, P_pub)^x
|
|
54
|
-
const kGt = (0, bls_1.gtPow)((0, bls_1.pairing)(qA, pPub), x);
|
|
55
|
-
const key = kemKey((0, bls_1.gtToBytes)(kGt), salt, attr, uBytes);
|
|
56
|
-
return { U: uBytes, key };
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Decapsulate: recover the 32-byte KEM key from decryption key `dA` (G1) and ephemeral `uBytes` (G2).
|
|
60
|
-
* Returns null (fail-closed) if either point is malformed. The attribute string must match the one used
|
|
61
|
-
* at encapsulation (it is bound into the KDF).
|
|
62
|
-
*/
|
|
63
|
-
function decapsulate(dA, attr, uBytes, salt) {
|
|
64
|
-
const U = (0, bls_1.g2FromBytes)(uBytes);
|
|
65
|
-
if (U === null)
|
|
66
|
-
return null;
|
|
67
|
-
// K_GT = e(d_A, U)
|
|
68
|
-
const kGt = (0, bls_1.pairing)(dA, U);
|
|
69
|
-
return kemKey((0, bls_1.gtToBytes)(kGt), salt, attr, uBytes);
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=ibe.js.map
|
package/dist/ibe.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ibe.js","sourceRoot":"","sources":["../src/ibe.ts"],"names":[],"mappings":";;AA4CA,oCAEC;AAGD,gCAGC;AAcD,kCAUC;AAOD,kCAMC;AAzFD,+BAae;AAEf;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,YAAY,GAAG,sBAAsB,CAAC;AAU5C,kFAAkF;AAClF,SAAgB,YAAY,CAAC,CAAS;IACpC,OAAO,IAAA,eAAS,EAAC,IAAA,W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