@ibgib/ts-gib 0.4.9 → 0.5.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/.vscode/settings.json +3 -1
- package/CHANGELOG.md +20 -0
- package/README.md +30 -5
- package/dist/V1/constants.d.mts +30 -1
- package/dist/V1/constants.d.mts.map +1 -1
- package/dist/V1/constants.mjs +30 -1
- package/dist/V1/constants.mjs.map +1 -1
- package/dist/V1/factory.d.mts +17 -2
- package/dist/V1/factory.d.mts.map +1 -1
- package/dist/V1/factory.mjs +15 -0
- package/dist/V1/factory.mjs.map +1 -1
- package/dist/V1/sha256v1.d.mts.map +1 -1
- package/dist/V1/sha256v1.mjs +1 -1
- package/dist/V1/sha256v1.mjs.map +1 -1
- package/dist/V1/transforms/fork.d.mts.map +1 -1
- package/dist/V1/transforms/fork.mjs +2 -1
- package/dist/V1/transforms/fork.mjs.map +1 -1
- package/dist/V1/transforms/index.d.mts +1 -1
- package/dist/V1/transforms/index.d.mts.map +1 -1
- package/dist/V1/transforms/index.mjs +1 -1
- package/dist/V1/transforms/index.mjs.map +1 -1
- package/dist/V1/transforms/mut8.d.mts.map +1 -1
- package/dist/V1/transforms/mut8.mjs +2 -1
- package/dist/V1/transforms/mut8.mjs.map +1 -1
- package/dist/V1/transforms/rel8.d.mts.map +1 -1
- package/dist/V1/transforms/rel8.mjs +2 -1
- package/dist/V1/transforms/rel8.mjs.map +1 -1
- package/dist/V1/transforms/transform-helper.d.mts.map +1 -1
- package/dist/V1/transforms/transform-helper.mjs +2 -1
- package/dist/V1/transforms/transform-helper.mjs.map +1 -1
- package/dist/V1/v1-helper.d.mts +38 -0
- package/dist/V1/v1-helper.d.mts.map +1 -0
- package/dist/V1/v1-helper.mjs +87 -0
- package/dist/V1/v1-helper.mjs.map +1 -0
- package/dist/V1/validate-helper.d.mts +83 -0
- package/dist/V1/validate-helper.d.mts.map +1 -0
- package/dist/V1/validate-helper.mjs +227 -0
- package/dist/V1/validate-helper.mjs.map +1 -0
- package/dist/helper.d.mts +0 -54
- package/dist/helper.d.mts.map +1 -1
- package/dist/helper.mjs +0 -114
- package/dist/helper.mjs.map +1 -1
- package/dist/types.d.mts +39 -8
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +31 -0
- package/dist/types.mjs.map +1 -1
- package/jasmine-browser.json +2 -2
- package/package.json +5 -1
- package/src/V1/constants.mts +31 -3
- package/src/V1/factory.mts +18 -2
- package/src/V1/factory.spec.mts +2 -1
- package/src/V1/sha256v1.mts +5 -5
- package/src/V1/transforms/fork.mts +2 -1
- package/src/V1/transforms/fork.spec.mts +2 -1
- package/src/V1/transforms/index.mts +1 -1
- package/src/V1/transforms/mut8.mts +2 -1
- package/src/V1/transforms/mut8.spec.mts +4 -3
- package/src/V1/transforms/rel8.mts +2 -1
- package/src/V1/transforms/rel8.spec.mts +2 -1
- package/src/V1/transforms/transform-helper.mts +3 -2
- package/src/V1/transforms/transform-helper.spec.mts +6 -5
- package/src/V1/v1-helper.mts +90 -0
- package/src/V1/validate-helper.mts +286 -0
- package/src/helper.mts +0 -116
- package/src/helper.spec.mts +47 -115
- package/src/types.mts +40 -9
- package/dist/index.cjs +0 -4
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/index.d.cts.map +0 -1
- package/src/index.cts +0 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { getIbGibAddr } from '../helper.mjs';
|
|
2
|
+
import { clone, } from '@ibgib/helper-gib';
|
|
3
|
+
import * as cTsGib from './constants.mjs';
|
|
4
|
+
import { getGibInfo } from './transforms/transform-helper.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Helper function that checks the given `ibGib` to see if it
|
|
7
|
+
* either has a tjp or is a tjp itself.
|
|
8
|
+
*
|
|
9
|
+
* ## notes
|
|
10
|
+
*
|
|
11
|
+
* Only unique ibGibs are meant to have tjps, or rather, if an
|
|
12
|
+
* ibGib timeline is expected to be unique over "time", then the
|
|
13
|
+
* tjp is an extremely convenient mechanism that provides a
|
|
14
|
+
* "name" for that timeline.
|
|
15
|
+
*
|
|
16
|
+
* Otherwise, if they are not unique, then successive "different"
|
|
17
|
+
* timelines cannot be easily referenced by their first unique
|
|
18
|
+
* frame in time, making it much harder to pub/sub updates among
|
|
19
|
+
* other things. (If there are no unique frames, then they are
|
|
20
|
+
* the same ibGib.)
|
|
21
|
+
*
|
|
22
|
+
* ## tjp = temporal junction point
|
|
23
|
+
*
|
|
24
|
+
* I've written elsewhere on this as well. Refer to B2tF2.
|
|
25
|
+
*
|
|
26
|
+
* @returns true if the ibGib has/is a tjp, else false
|
|
27
|
+
*/
|
|
28
|
+
export function hasTjp({ ibGib }) {
|
|
29
|
+
const lc = `[${hasTjp.name}]`;
|
|
30
|
+
if (!ibGib) {
|
|
31
|
+
console.warn(`${lc} ibGib falsy. (W: 884178562f5b4f15933ac4d98db74cc6)`);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (ibGib.data?.isTjp || ibGib.rel8ns?.tjp?.length > 0) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
// dna transforms do not have tjp
|
|
38
|
+
const dnaPrimitives = ['fork^gib', 'mut8^gib', 'rel8^gib'];
|
|
39
|
+
if ((ibGib.rel8ns?.ancestor ?? []).some(x => dnaPrimitives.includes(x))) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (!ibGib.gib) {
|
|
43
|
+
console.warn(`${lc} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (ibGib.gib.includes(cTsGib.GIB_DELIMITER)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (ibGib.gib === cTsGib.GIB) {
|
|
50
|
+
// primitive
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// use more expensive getGibInfo call.
|
|
54
|
+
// could possibly just return false at this point, but since gib info
|
|
55
|
+
// would change if we change our standards for gib, this is nicer.
|
|
56
|
+
const gibInfo = getGibInfo({ ibGibAddr: getIbGibAddr({ ibGib }) });
|
|
57
|
+
return gibInfo.tjpGib ? true : false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* If you have an ibgib object, it may also contain other properties/functions.
|
|
61
|
+
*
|
|
62
|
+
* This helper function takes the incoming object and returns a copy
|
|
63
|
+
* @param param0
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export function toDto({ ibGib, }) {
|
|
67
|
+
const lc = `[${toDto.name}]`;
|
|
68
|
+
if (!ibGib.ib) {
|
|
69
|
+
console.warn(`${lc} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`);
|
|
70
|
+
}
|
|
71
|
+
if (!ibGib.gib) {
|
|
72
|
+
console.warn(`${lc} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`);
|
|
73
|
+
}
|
|
74
|
+
let dtoIbGib = { ib: (ibGib.ib || '').slice() };
|
|
75
|
+
if (ibGib.gib) {
|
|
76
|
+
dtoIbGib.gib = ibGib.gib.slice();
|
|
77
|
+
}
|
|
78
|
+
;
|
|
79
|
+
if (ibGib.data) {
|
|
80
|
+
dtoIbGib.data = clone(ibGib.data);
|
|
81
|
+
}
|
|
82
|
+
if (ibGib.rel8ns) {
|
|
83
|
+
dtoIbGib.rel8ns = clone(ibGib.rel8ns);
|
|
84
|
+
}
|
|
85
|
+
return dtoIbGib;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=v1-helper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1-helper.mjs","sourceRoot":"","sources":["../../src/V1/v1-helper.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAU,KAAK,GAAU,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,MAAM,MAAM,iBAAiB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AAC;IACnE,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAyD,EAC1E,KAAK,GAGR;IACG,MAAM,EAAE,GAAG,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC;IAC7B,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,2DAA2D,CAAC,CAAC;KAAE;IAClG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;QAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,4DAA4D,CAAC,CAAC;KAAE;IAEpG,IAAI,QAAQ,GAA6B,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;IAC1E,IAAI,KAAK,CAAC,GAAG,EAAE;QAAE,QAAQ,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;KAAE;IAAA,CAAC;IACrD,IAAI,KAAK,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;KAAE;IACtD,IAAI,KAAK,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;KAAE;IAE5D,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Ib, IbGibAddr } from '../types.mjs';
|
|
2
|
+
import { IbGib_V1 } from './types.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* validates the ibGib's address (`ib` and `gib` properties) and recalculates
|
|
5
|
+
* the `gib` against the `ibGib.gib`.
|
|
6
|
+
*
|
|
7
|
+
* this validates not only that the punctiliar gib hash for this ibgib record
|
|
8
|
+
* hashes to the same value, but it also checks the internal tjp address and
|
|
9
|
+
* ensures that it is the same tjp gib in the gib field.
|
|
10
|
+
*
|
|
11
|
+
* ## notes
|
|
12
|
+
*
|
|
13
|
+
* * By checking the tjp gib is the same in the address as in the tjp rel8n, we
|
|
14
|
+
* are providing (extremely?) good corroboration that the tjp listed in the
|
|
15
|
+
* address is accurate. However, it may still be theoretically possible to
|
|
16
|
+
* forge an ibgib that both hashes to the punctiliar hash and matches up this
|
|
17
|
+
* tjpAddr.gib. This would be AFAICT quite challenging.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateIbGibIntrinsically({ ibGib }: {
|
|
20
|
+
ibGib: IbGib_V1;
|
|
21
|
+
}): Promise<string[] | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Naive synchronous validation for ibgib addresses.
|
|
24
|
+
*
|
|
25
|
+
* @returns error string array if validation errors found, else null
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateIbGibAddr({ addr, delimiter, version, }: {
|
|
28
|
+
addr: IbGibAddr;
|
|
29
|
+
delimiter?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
}): string[] | null;
|
|
32
|
+
/**
|
|
33
|
+
* Naive validation of ib.
|
|
34
|
+
*
|
|
35
|
+
* @returns errors array if found, else null
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateIb({ ib, ibGibAddrDelimiter, version, }: {
|
|
38
|
+
ib: Ib;
|
|
39
|
+
ibGibAddrDelimiter?: string;
|
|
40
|
+
version?: string;
|
|
41
|
+
}): string[] | null;
|
|
42
|
+
/**
|
|
43
|
+
* validates a `gib` of some ibGib/ibGibAddr.
|
|
44
|
+
*
|
|
45
|
+
* @returns array of validation error strings (if any) or null
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateGib({ gib, gibDelimiter, ibGibAddrDelimiter, version, }: {
|
|
48
|
+
/**
|
|
49
|
+
* gib to validate.
|
|
50
|
+
*
|
|
51
|
+
* ## notes
|
|
52
|
+
*
|
|
53
|
+
* If the gib has a tjp embedded in it (i.e. the associated ibgib has a
|
|
54
|
+
* tjp), then this will call validation on that tjpGib recursively.
|
|
55
|
+
*/
|
|
56
|
+
gib: Ib;
|
|
57
|
+
/**
|
|
58
|
+
* This is a delimiter used with tjpGibs.
|
|
59
|
+
*
|
|
60
|
+
* atow this is a dot (`'.'`).
|
|
61
|
+
*
|
|
62
|
+
* ## notes
|
|
63
|
+
*
|
|
64
|
+
* THIS IS NOT THE SAME THING AS THE `ibGibAddrDelimiter`!
|
|
65
|
+
*/
|
|
66
|
+
gibDelimiter?: string;
|
|
67
|
+
/**
|
|
68
|
+
* This is a delimiter used with the entire ibGibAddr.
|
|
69
|
+
*
|
|
70
|
+
* atow this is a caret (`'^'`).
|
|
71
|
+
*
|
|
72
|
+
* ## notes
|
|
73
|
+
*
|
|
74
|
+
* THIS IS NOT THE SAME THING AS THE `gibDelimiter`!
|
|
75
|
+
*/
|
|
76
|
+
ibGibAddrDelimiter?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Ignored atow, but in the future, probably will be used.
|
|
79
|
+
* May end up being an IbGibAddr but who knows.
|
|
80
|
+
*/
|
|
81
|
+
version?: string;
|
|
82
|
+
}): string[] | null;
|
|
83
|
+
//# sourceMappingURL=validate-helper.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-helper.d.mts","sourceRoot":"","sources":["../../src/V1/validate-helper.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,SAAS,EAAG,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAG,MAAM,aAAa,CAAC;AAYxC;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,0BAA0B,CAAC,EAC7C,KAAK,EACR,EAAE;IACC,KAAK,EAAE,QAAQ,CAAA;CAClB,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CA2D3B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAC9B,IAAI,EACJ,SAAS,EACT,OAAO,GACV,EAAE;IACC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,EAAE,GAAG,IAAI,CAoClB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EACvB,EAAE,EACF,kBAAkB,EAClB,OAAO,GACV,EAAE;IACC,EAAE,EAAE,EAAE,CAAC;IACP,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,EAAE,GAAG,IAAI,CAqBlB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EACxB,GAAG,EACH,YAAY,EACZ,kBAAkB,EAClB,OAAO,GACV,EAAE;IACC;;;;;;;OAOG;IACH,GAAG,EAAE,EAAE,CAAC;IACR;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,MAAM,EAAE,GAAG,IAAI,CA2DlB"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { IBGIB_DELIMITER, IB, GIB_DELIMITER, } from './constants.mjs';
|
|
2
|
+
import { isPrimitive, getGib, getGibInfo } from './transforms/transform-helper.mjs';
|
|
3
|
+
// import { hasTjp, toDto } from './ibgib';
|
|
4
|
+
import { hasTjp, toDto } from './v1-helper.mjs';
|
|
5
|
+
import { HEXADECIMAL_HASH_STRING_REGEXP_32, HEXADECIMAL_HASH_STRING_REGEXP_64 } from '@ibgib/helper-gib';
|
|
6
|
+
import { getIbAndGib, getIbGibAddr } from '../helper.mjs';
|
|
7
|
+
const logalot = false;
|
|
8
|
+
/**
|
|
9
|
+
* validates the ibGib's address (`ib` and `gib` properties) and recalculates
|
|
10
|
+
* the `gib` against the `ibGib.gib`.
|
|
11
|
+
*
|
|
12
|
+
* this validates not only that the punctiliar gib hash for this ibgib record
|
|
13
|
+
* hashes to the same value, but it also checks the internal tjp address and
|
|
14
|
+
* ensures that it is the same tjp gib in the gib field.
|
|
15
|
+
*
|
|
16
|
+
* ## notes
|
|
17
|
+
*
|
|
18
|
+
* * By checking the tjp gib is the same in the address as in the tjp rel8n, we
|
|
19
|
+
* are providing (extremely?) good corroboration that the tjp listed in the
|
|
20
|
+
* address is accurate. However, it may still be theoretically possible to
|
|
21
|
+
* forge an ibgib that both hashes to the punctiliar hash and matches up this
|
|
22
|
+
* tjpAddr.gib. This would be AFAICT quite challenging.
|
|
23
|
+
*/
|
|
24
|
+
export async function validateIbGibIntrinsically({ ibGib }) {
|
|
25
|
+
const lc = `[${validateIbGibIntrinsically.name}]`;
|
|
26
|
+
try {
|
|
27
|
+
let errors = [];
|
|
28
|
+
if (ibGib) {
|
|
29
|
+
const addr = getIbGibAddr({ ibGib });
|
|
30
|
+
errors = validateIbGibAddr({ addr }) ?? [];
|
|
31
|
+
if (errors.length > 0) {
|
|
32
|
+
console.error(`${lc} errors found in addr: ${addr}`);
|
|
33
|
+
return errors; // <<<< returns early
|
|
34
|
+
}
|
|
35
|
+
// rest of the function assumes correctly formatted ib and gib
|
|
36
|
+
// if it's a primitive, the caller knows (or should know!) there are no
|
|
37
|
+
// metadata guarantees.
|
|
38
|
+
if (isPrimitive({ gib: ibGib.gib })) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
// this validates not only that the punctiliar gib hash for this ibgib record
|
|
42
|
+
// hashes to the same value, but it also checks the internal tjp address and
|
|
43
|
+
// ensures that it is the same tjp gib.
|
|
44
|
+
// not necessary the dto here, but I'm sensitive at this point.
|
|
45
|
+
let gottenGib = await getGib({ ibGib: toDto({ ibGib }), hasTjp: hasTjp({ ibGib }) });
|
|
46
|
+
if (gottenGib !== ibGib.gib) {
|
|
47
|
+
if (ibGib.data?.src && ibGib.data.srcAddr && ibGib.ib === 'rel8') {
|
|
48
|
+
// this is NOT the place to do this, but I'm plodding through trying to think of how to fix it
|
|
49
|
+
// this is what it looks like in data
|
|
50
|
+
// {
|
|
51
|
+
// "rel8nsToAddByAddr":{
|
|
52
|
+
// "comment":["comment 11221^F6B9477984D31FEF5FD25297CA39126A64ADDE2C91C1A2D670CCFE3965DEC4C9.847F0E9A1B2738DC167B32AA9B2D7D9B88B76F21848B1F193E994BB21F90DAEE"]
|
|
53
|
+
// },
|
|
54
|
+
// "dna":true,
|
|
55
|
+
// "nCounter":true,
|
|
56
|
+
// "type":"rel8"
|
|
57
|
+
// }
|
|
58
|
+
delete ibGib.data.src;
|
|
59
|
+
delete ibGib.data.srcAddr;
|
|
60
|
+
gottenGib = await getGib({ ibGib: toDto({ ibGib }), hasTjp: hasTjp({ ibGib }) });
|
|
61
|
+
if (gottenGib !== ibGib.gib) {
|
|
62
|
+
errors.push(`Ibgib invalid intrinsically - gottenGib (${gottenGib}) does not equal ibGib.gib (${ibGib.gib}). (E: 020b71479e944b2198fe436e7e137786)`);
|
|
63
|
+
// } else {
|
|
64
|
+
// debugger;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
errors.push(`Ibgib invalid intrinsically - gottenGib (${gottenGib}) does not equal ibGib.gib (${ibGib.gib}). (E: 7416db016878430ca3c5b20697f164ed)`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return errors.length > 0 ? errors : null;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
errors.push(`ibGib is itself falsy. (E: 4fb98caf6ed24ef7b35a19cef56e2d7e)`);
|
|
75
|
+
return errors;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error(`${lc} ${error.message}`);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Naive synchronous validation for ibgib addresses.
|
|
85
|
+
*
|
|
86
|
+
* @returns error string array if validation errors found, else null
|
|
87
|
+
*/
|
|
88
|
+
export function validateIbGibAddr({ addr, delimiter, version, }) {
|
|
89
|
+
const lc = `[${validateIbGibAddr.name}]`;
|
|
90
|
+
try {
|
|
91
|
+
let errors = [];
|
|
92
|
+
if (version) {
|
|
93
|
+
console.warn(`${lc} version not implemented yet. Ignoring. (W: 2d19db16ec0c4766b5d35248787671f3)`);
|
|
94
|
+
}
|
|
95
|
+
// validate as a whole
|
|
96
|
+
if (!addr) {
|
|
97
|
+
errors.push(`addr required. (E: e9a54041aa0b41c1bb2324d9d2d42c7f)`);
|
|
98
|
+
return errors;
|
|
99
|
+
}
|
|
100
|
+
delimiter = delimiter || IBGIB_DELIMITER;
|
|
101
|
+
if (!addr.includes(delimiter)) {
|
|
102
|
+
errors.push(`No delimiter (${delimiter}) found. (E: 05e28dcb70ff44019edc53ed508bd1e8)`);
|
|
103
|
+
}
|
|
104
|
+
if (addr.startsWith(delimiter)) {
|
|
105
|
+
errors.push(`addr starts with delim. (E: d29f808c5a47452f9bb3ea684694c6eb)`);
|
|
106
|
+
}
|
|
107
|
+
// validate pieces...
|
|
108
|
+
const { ib, gib } = getIbAndGib({ ibGibAddr: addr, delimiter });
|
|
109
|
+
// ...ib
|
|
110
|
+
const resValidateIb = validateIb({ ib, ibGibAddrDelimiter: delimiter, version });
|
|
111
|
+
if (resValidateIb) {
|
|
112
|
+
errors = errors.concat(resValidateIb);
|
|
113
|
+
}
|
|
114
|
+
// ...gib
|
|
115
|
+
const resValidateGib = validateGib({ gib, ibGibAddrDelimiter: delimiter, version });
|
|
116
|
+
if (resValidateGib) {
|
|
117
|
+
errors = errors.concat(resValidateGib);
|
|
118
|
+
}
|
|
119
|
+
if (errors.length > 0) {
|
|
120
|
+
if (logalot) {
|
|
121
|
+
console.log(`${lc} errors.length > 0. errors: ${errors.join('|')} (I: 9c18f993e138f15613e4c6a340d41722)`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// we're done
|
|
125
|
+
return errors.length > 0 ? errors : null;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error(`${lc} ${error.message}`);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Naive validation of ib.
|
|
134
|
+
*
|
|
135
|
+
* @returns errors array if found, else null
|
|
136
|
+
*/
|
|
137
|
+
export function validateIb({ ib, ibGibAddrDelimiter, version, }) {
|
|
138
|
+
const lc = `[${validateIb.name}]`;
|
|
139
|
+
try {
|
|
140
|
+
const errors = [];
|
|
141
|
+
if (version) {
|
|
142
|
+
console.warn(`${lc} version not implemented yet. Ignoring. (W: 71228ba4ed994aaa8149910e295ab087)`);
|
|
143
|
+
}
|
|
144
|
+
if (!ib) {
|
|
145
|
+
errors.push(`ib required. (E: a76d06c7b9c24db3a731a91dbe46acd5)`);
|
|
146
|
+
return errors;
|
|
147
|
+
}
|
|
148
|
+
if (ib === IB) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
ibGibAddrDelimiter = ibGibAddrDelimiter || IBGIB_DELIMITER;
|
|
152
|
+
if (ib.includes(ibGibAddrDelimiter)) {
|
|
153
|
+
errors.push(`ib contains ibGibAddrDelimiter (${ibGibAddrDelimiter}) (E: 09e61b46c3e84874bc02b6918f1f2c39)`);
|
|
154
|
+
}
|
|
155
|
+
return errors.length > 0 ? errors : null;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
console.error(`${lc} ${error.message}`);
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* validates a `gib` of some ibGib/ibGibAddr.
|
|
164
|
+
*
|
|
165
|
+
* @returns array of validation error strings (if any) or null
|
|
166
|
+
*/
|
|
167
|
+
export function validateGib({ gib, gibDelimiter, ibGibAddrDelimiter, version, }) {
|
|
168
|
+
const lc = `[${validateGib.name}]`;
|
|
169
|
+
try {
|
|
170
|
+
const errors = [];
|
|
171
|
+
if (version) {
|
|
172
|
+
console.warn(`${lc} version not implemented yet. Ignoring. (E: 90ced1db69774702b92acb261bdaee23)`);
|
|
173
|
+
}
|
|
174
|
+
if (!gib) {
|
|
175
|
+
errors.push(`gib required. (E: e217de4035b04086827199f4bace189c)`);
|
|
176
|
+
return errors;
|
|
177
|
+
}
|
|
178
|
+
ibGibAddrDelimiter = ibGibAddrDelimiter || IBGIB_DELIMITER;
|
|
179
|
+
/** Need to move this to ts-gib */
|
|
180
|
+
const INVALID_GIB_CHARS = [ibGibAddrDelimiter];
|
|
181
|
+
const invalidCharsFound = [];
|
|
182
|
+
INVALID_GIB_CHARS.forEach(invalidChar => {
|
|
183
|
+
if (gib.includes(invalidChar)) {
|
|
184
|
+
invalidCharsFound.push(invalidChar);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (invalidCharsFound.length > 0) {
|
|
188
|
+
errors.push(`gib (${gib}}) contains invalid characters: (${JSON.stringify(invalidCharsFound.join(','))}) (E: 1e584258d9e049ba9ce7e516f3ab97f1)`);
|
|
189
|
+
}
|
|
190
|
+
// punctiliar = point, i.e., a single point in the universe, either a
|
|
191
|
+
// single point in time in a tjp ibgib's timeline, or a single point in
|
|
192
|
+
// space that lives outside of time (has no tjp thus no timeline).
|
|
193
|
+
//
|
|
194
|
+
// So if we've gotten here in code, then our gib is truthy and doesn't
|
|
195
|
+
// contain invalid characters.
|
|
196
|
+
const { punctiliarHash, tjpGib, isPrimitive } = getGibInfo({ gib, gibDelimiter: gibDelimiter || GIB_DELIMITER });
|
|
197
|
+
// automatically valid if it's a primitive, as the caller should expect
|
|
198
|
+
// no cryptographical guarantees
|
|
199
|
+
if (isPrimitive) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
// Gib is not primitive so must have at least the punctiliar hash.
|
|
203
|
+
if (!punctiliarHash) {
|
|
204
|
+
throw new Error(`${lc} punctiliarHash is falsy on a non-primitive gib. (E: 72835394918241bdb2632bf0510bdae5)`);
|
|
205
|
+
}
|
|
206
|
+
const punctiliarHashIs_32 = punctiliarHash.match(HEXADECIMAL_HASH_STRING_REGEXP_32);
|
|
207
|
+
const punctiliarHashIs_64 = punctiliarHash.match(HEXADECIMAL_HASH_STRING_REGEXP_64);
|
|
208
|
+
if (!punctiliarHashIs_32 && !punctiliarHashIs_64) {
|
|
209
|
+
errors.push('gib punctiliar hash is neither a 32- or 64-char hash string. (E: d47ff6d6e14b4c02a62107090c8dad39)');
|
|
210
|
+
}
|
|
211
|
+
if (tjpGib) {
|
|
212
|
+
// if it is an ibgib in a timeline, that timeline has a tjp and this
|
|
213
|
+
// gib has a tjpGib component. So we must recursively validate the
|
|
214
|
+
// tjpGib
|
|
215
|
+
const tjpGibValidationErrors = validateGib({ gib: tjpGib });
|
|
216
|
+
if ((tjpGibValidationErrors ?? []).length > 0) {
|
|
217
|
+
errors.push(`tjpGib has errors (E: d6b79228d4a64c0b967cdb0efcea4d0d). tjpGibValidationErrors: ${tjpGibValidationErrors.join('. ')}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return errors.length > 0 ? errors : null;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.error(`${lc} ${error.message}`);
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=validate-helper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-helper.mjs","sourceRoot":"","sources":["../../src/V1/validate-helper.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAO,EAAE,EAAE,aAAa,GAAG,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAEpF,2CAA2C;AAE3C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,E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AAkE;QAClE,IAAI,CAAC,cAAc,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,GAAG,EAAE,wFAAwF,CAAC,CAAC;SAAE;QACxI,MAAM,mBAAmB,GAAG,cAAe,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrF,MAAM,mBAAmB,GAAG,cAAe,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrF,IAAI,CAAC,mBAAmB,IAAI,CAAC,mBAAmB,EAAE;YAC9C,MAAM,CAAC,IAAI,CAAC,oGAAoG,CAAC,CAAC;SACrH;QAED,IAAI,MAAM,EAAE;YACR,oEAAoE;YACpE,kEAAkE;YAClE,SAAS;YACT,MAAM,sBAAsB,GAAG,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;YAC5D,IAAI,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3C,MAAM,CAAC,IAAI,CAAC,oFAAoF,sBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACzI;SACJ;QAED,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;KAC5C;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,KAAK,CAAC;KACf;AACL,CAAC"}
|
package/dist/helper.d.mts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { Ib, Gib, IbGib, IbGibAddr, IbAndGib } from './types.mjs';
|
|
2
|
-
export type HashAlgorithm = 'SHA-256' | 'SHA-512';
|
|
3
|
-
export declare const HashAlgorithm: {
|
|
4
|
-
[key: string]: HashAlgorithm;
|
|
5
|
-
};
|
|
6
|
-
export declare function clone(obj: any): any;
|
|
7
|
-
export declare function getTimestamp(): string;
|
|
8
2
|
/**
|
|
9
3
|
* Gets the ib^gib address from the given ib and gib or
|
|
10
4
|
* from the ibGib object.
|
|
@@ -26,52 +20,4 @@ export declare function getIbAndGib({ ibGib, ibGibAddr, delimiter }: {
|
|
|
26
20
|
ibGib?: IbGib;
|
|
27
21
|
delimiter?: string;
|
|
28
22
|
}): IbAndGib;
|
|
29
|
-
/**
|
|
30
|
-
* Simple hash function.
|
|
31
|
-
*
|
|
32
|
-
* NOTE:
|
|
33
|
-
* This is not used for ibGib.gib values (ATOW)
|
|
34
|
-
* but rather as a helper function for generating random UUIDs.
|
|
35
|
-
*
|
|
36
|
-
* @param s string to hash
|
|
37
|
-
* @param algorithm to use, currently only 'SHA-256'
|
|
38
|
-
*/
|
|
39
|
-
export declare function hash({ s, algorithm, }: {
|
|
40
|
-
s: string;
|
|
41
|
-
algorithm?: HashAlgorithm;
|
|
42
|
-
}): Promise<string>;
|
|
43
|
-
/**
|
|
44
|
-
* Simple func to generate UUID (sha-256 hash basically).
|
|
45
|
-
*
|
|
46
|
-
* @param seedSize size of seed for UUID generation
|
|
47
|
-
*/
|
|
48
|
-
export declare function getUUID(seedSize?: number): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
* Syntactic sugar for JSON.stringify(obj, null, 2);
|
|
51
|
-
*
|
|
52
|
-
* @param obj to pretty stringify
|
|
53
|
-
*/
|
|
54
|
-
export declare function pretty(obj: any): string;
|
|
55
|
-
/**
|
|
56
|
-
* Just delays given number of ms.
|
|
57
|
-
*
|
|
58
|
-
* @param ms milliseconds to delay
|
|
59
|
-
*/
|
|
60
|
-
export declare function delay(ms: number): Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* extracts the error message from an error object/string/falsy arg.
|
|
63
|
-
*
|
|
64
|
-
* ## notes
|
|
65
|
-
*
|
|
66
|
-
* * some libs throw errors, some throw just strings.
|
|
67
|
-
* * who knows what else it could be.
|
|
68
|
-
*
|
|
69
|
-
* ## todo
|
|
70
|
-
*
|
|
71
|
-
* * extract inner errors/causes if we ever use this function extensively.
|
|
72
|
-
*
|
|
73
|
-
* @param error the error object in the catch area of the try..catch block.
|
|
74
|
-
* @returns error.message if it's a string, error itself if it's a string, or canned error messages if it's falsy or none of the above.
|
|
75
|
-
*/
|
|
76
|
-
export declare function extractErrorMsg(error: any): string;
|
|
77
23
|
//# sourceMappingURL=helper.d.mts.map
|
package/dist/helper.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.mts","sourceRoot":"","sources":["../src/helper.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.d.mts","sourceRoot":"","sources":["../src/helper.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGlE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EACzB,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAe,EAClC,EAAE;IACC,EAAE,CAAC,EAAE,EAAE,CAAC;IACR,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB,UAIA;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,SAAS,EACT,SAAe,EAClB,EAAE;IACC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,QAAQ,CAyCX"}
|
package/dist/helper.mjs
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
let crypto = globalThis.crypto;
|
|
2
|
-
let { subtle } = crypto;
|
|
3
|
-
export const HashAlgorithm = {
|
|
4
|
-
'sha_256': 'SHA-256',
|
|
5
|
-
'sha_512': 'SHA-512',
|
|
6
|
-
};
|
|
7
|
-
export function clone(obj) {
|
|
8
|
-
return JSON.parse(JSON.stringify(obj));
|
|
9
|
-
}
|
|
10
|
-
export function getTimestamp() {
|
|
11
|
-
return (new Date()).toUTCString();
|
|
12
|
-
}
|
|
13
1
|
/**
|
|
14
2
|
* Gets the ib^gib address from the given ib and gib or
|
|
15
3
|
* from the ibGib object.
|
|
@@ -74,106 +62,4 @@ export function getIbAndGib({ ibGib, ibGibAddr, delimiter = '^' }) {
|
|
|
74
62
|
};
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Simple hash function.
|
|
79
|
-
*
|
|
80
|
-
* NOTE:
|
|
81
|
-
* This is not used for ibGib.gib values (ATOW)
|
|
82
|
-
* but rather as a helper function for generating random UUIDs.
|
|
83
|
-
*
|
|
84
|
-
* @param s string to hash
|
|
85
|
-
* @param algorithm to use, currently only 'SHA-256'
|
|
86
|
-
*/
|
|
87
|
-
export async function hash({ s, algorithm = 'SHA-256', }) {
|
|
88
|
-
if (!s) {
|
|
89
|
-
return '';
|
|
90
|
-
}
|
|
91
|
-
const validAlgorithms = Object.values(HashAlgorithm);
|
|
92
|
-
if (!validAlgorithms.includes(algorithm)) {
|
|
93
|
-
console.error(`Only ${validAlgorithms} implemented`);
|
|
94
|
-
return '';
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const msgUint8 = new TextEncoder().encode(s);
|
|
98
|
-
const buffer = await subtle.digest(algorithm, msgUint8);
|
|
99
|
-
const asArray = Array.from(new Uint8Array(buffer));
|
|
100
|
-
return asArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
103
|
-
console.error(extractErrorMsg(e.message));
|
|
104
|
-
return '';
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Simple func to generate UUID (sha-256 hash basically).
|
|
109
|
-
*
|
|
110
|
-
* @param seedSize size of seed for UUID generation
|
|
111
|
-
*/
|
|
112
|
-
export async function getUUID(seedSize = 64) {
|
|
113
|
-
let uuid = '';
|
|
114
|
-
if (seedSize < 32) {
|
|
115
|
-
throw new Error(`Seed size must be at least 32`);
|
|
116
|
-
}
|
|
117
|
-
if (!globalThis.crypto) {
|
|
118
|
-
throw new Error(`Cannot create UUID, as unknown crypto library version. If using node.js, v19+ is required. (E: c02cee3fd8a94f678d3f4ebe9dc49797)`);
|
|
119
|
-
}
|
|
120
|
-
const values = crypto.getRandomValues(new Uint8Array(16));
|
|
121
|
-
uuid = await hash({ s: values.join('') });
|
|
122
|
-
if (!uuid) {
|
|
123
|
-
throw new Error(`Did not create UUID...hmm...`);
|
|
124
|
-
}
|
|
125
|
-
return uuid;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Syntactic sugar for JSON.stringify(obj, null, 2);
|
|
129
|
-
*
|
|
130
|
-
* @param obj to pretty stringify
|
|
131
|
-
*/
|
|
132
|
-
export function pretty(obj) {
|
|
133
|
-
return JSON.stringify(obj, null, 2);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Just delays given number of ms.
|
|
137
|
-
*
|
|
138
|
-
* @param ms milliseconds to delay
|
|
139
|
-
*/
|
|
140
|
-
export async function delay(ms) {
|
|
141
|
-
return new Promise(resolve => {
|
|
142
|
-
setTimeout(() => {
|
|
143
|
-
resolve();
|
|
144
|
-
}, ms);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* extracts the error message from an error object/string/falsy arg.
|
|
149
|
-
*
|
|
150
|
-
* ## notes
|
|
151
|
-
*
|
|
152
|
-
* * some libs throw errors, some throw just strings.
|
|
153
|
-
* * who knows what else it could be.
|
|
154
|
-
*
|
|
155
|
-
* ## todo
|
|
156
|
-
*
|
|
157
|
-
* * extract inner errors/causes if we ever use this function extensively.
|
|
158
|
-
*
|
|
159
|
-
* @param error the error object in the catch area of the try..catch block.
|
|
160
|
-
* @returns error.message if it's a string, error itself if it's a string, or canned error messages if it's falsy or none of the above.
|
|
161
|
-
*/
|
|
162
|
-
export function extractErrorMsg(error) {
|
|
163
|
-
if (!error && error !== 0) {
|
|
164
|
-
return '[error is falsy]';
|
|
165
|
-
}
|
|
166
|
-
else if (typeof error === 'string') {
|
|
167
|
-
return error;
|
|
168
|
-
}
|
|
169
|
-
else if (typeof error.message === 'string') {
|
|
170
|
-
return error.message;
|
|
171
|
-
}
|
|
172
|
-
else if (typeof error === 'number') {
|
|
173
|
-
return JSON.stringify(error);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return `[error is not a string and error.message is not a string. typeof error: ${typeof error}]`;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
65
|
//# sourceMappingURL=helper.mjs.map
|
package/dist/helper.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.mjs","sourceRoot":"","sources":["../src/helper.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.mjs","sourceRoot":"","sources":["../src/helper.mts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,EACzB,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,GAAG,GAAG,EAMlC;IACG,EAAE,GAAG,EAAE,IAAI,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC;IAC3B,GAAG,GAAG,GAAG,IAAI,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC;IAC9B,OAAO,EAAE,GAAG,SAAS,GAAG,GAAG,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EACxB,KAAK,EACL,SAAS,EACT,SAAS,GAAG,GAAG,EAKlB;IACG,MAAM,EAAE,GAAG,eAAe,CAAC;IAC3B,IAAI,CAAC,SAAS,EAAE;QACZ,IAAI,KAAK,EAAE;YACP,SAAS,GA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