@tearleads/client-sdk 0.1.241 → 0.1.242
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/data/keyingProjectionVerification/checkpoints/checkpointContext.js +12 -3
- package/data/keyingProjectionVerification/checkpoints/checkpointContext.js.map +1 -1
- package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js +73 -8
- package/data/keyingProjectionVerification/checkpoints/verifiedBundleBytes.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerAncestorCitations.js +20 -4
- package/data/keyingProjectionVerification/container/containerAncestorCitations.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerManifestVerification.js +43 -32
- package/data/keyingProjectionVerification/container/containerManifestVerification.js.map +1 -1
- package/data/keyingProjectionVerification/container/containerSignedParentReference.js +129 -0
- package/data/keyingProjectionVerification/container/containerSignedParentReference.js.map +1 -0
- package/data/keyingProjectionVerification/document/documentManifestVerification.js +28 -7
- package/data/keyingProjectionVerification/document/documentManifestVerification.js.map +1 -1
- package/data/persistence/verifiedCitations/bundleCitationRows.js.map +1 -1
- package/data/persistence/verifiedCitations/citationCollection.js +2 -2
- package/data/persistence/verifiedCitations/citationCollection.js.map +1 -1
- package/data/persistence/verifiedManifestBundlePersistence.d.ts +3 -2
- package/data/persistence/verifiedManifestBundlePersistence.js +1 -1
- package/data/persistence/verifiedManifestBundlePersistence.js.map +1 -1
- package/internal/api-client/verifiedManifestCitations.d.ts +4 -3
- package/internal/api-client/verifiedManifestCitations.js +3 -3
- package/internal/api-client/verifiedManifestCitations.js.map +1 -1
- package/internal/validators/operation/writerProjections.d.ts +8 -8
- package/internal/validators/response/container.d.ts +4 -4
- package/internal/validators/response/documentMutation.d.ts +4 -4
- package/internal/validators/response/manifestBundleReferences.js +4 -3
- package/internal/validators/response/manifestBundleReferences.js.map +1 -1
- package/internal/validators/response/writerProjectionWire.d.ts +4 -4
- package/internal/validators/response/writerProjectionWire.js +8 -5
- package/internal/validators/response/writerProjectionWire.js.map +1 -1
- package/internal/validators/util/index.d.ts +1 -0
- package/internal/validators/util/index.js +1 -0
- package/internal/validators/util/index.js.map +1 -1
- package/internal/validators/util/servedManifestBundle.d.ts +71 -0
- package/internal/validators/util/servedManifestBundle.js +100 -0
- package/internal/validators/util/servedManifestBundle.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AccessManifestBundleWireResponse } from "./accessManifestBundle.js";
|
|
3
|
+
declare const servedManifestState: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A served bundle's reduced state. It is deliberately not a state record, and
|
|
6
|
+
* it carries a brand only parsing or `toServedAccessManifestBundle` gives, so
|
|
7
|
+
* TypeScript refuses a served bundle wherever a full one is required (a purge
|
|
8
|
+
* proof, a verifier input) and a full bundle wherever a served one is (a held
|
|
9
|
+
* citation); `completeServedAccessManifestBundle` is the one conversion that
|
|
10
|
+
* reads it.
|
|
11
|
+
*/
|
|
12
|
+
export interface ServedManifestState {
|
|
13
|
+
readonly [servedManifestState]: true;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A bundle as a writer projection serves it. Its `state` carries only what the
|
|
17
|
+
* bundle's own signed bytes do not: the derived fields the hash-committed
|
|
18
|
+
* manifest names (version, object id, organization, epoch, predecessor and
|
|
19
|
+
* event hash) and, for a container, the key epoch and public key its signed
|
|
20
|
+
* body names are left off, and the client fills them back from those bytes
|
|
21
|
+
* when it decodes. The verifier still requires the completed state to equal
|
|
22
|
+
* the state it derives.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ServedAccessManifestBundleWireResponseSchema: z.ZodType<{
|
|
25
|
+
event: {
|
|
26
|
+
body: unknown;
|
|
27
|
+
event: Record<string, unknown>;
|
|
28
|
+
eventHash: string;
|
|
29
|
+
};
|
|
30
|
+
manifest: Record<string, unknown>;
|
|
31
|
+
manifestHash: string;
|
|
32
|
+
state: ServedManifestState;
|
|
33
|
+
}, {
|
|
34
|
+
event: {
|
|
35
|
+
body: unknown;
|
|
36
|
+
event: Record<string, unknown>;
|
|
37
|
+
eventHash: string;
|
|
38
|
+
};
|
|
39
|
+
manifest: Record<string, unknown>;
|
|
40
|
+
manifestHash: string;
|
|
41
|
+
state: ServedManifestState;
|
|
42
|
+
}, z.core.$ZodTypeInternals<{
|
|
43
|
+
event: {
|
|
44
|
+
body: unknown;
|
|
45
|
+
event: Record<string, unknown>;
|
|
46
|
+
eventHash: string;
|
|
47
|
+
};
|
|
48
|
+
manifest: Record<string, unknown>;
|
|
49
|
+
manifestHash: string;
|
|
50
|
+
state: ServedManifestState;
|
|
51
|
+
}, {
|
|
52
|
+
event: {
|
|
53
|
+
body: unknown;
|
|
54
|
+
event: Record<string, unknown>;
|
|
55
|
+
eventHash: string;
|
|
56
|
+
};
|
|
57
|
+
manifest: Record<string, unknown>;
|
|
58
|
+
manifestHash: string;
|
|
59
|
+
state: ServedManifestState;
|
|
60
|
+
}>>;
|
|
61
|
+
export type ServedAccessManifestBundleWireResponse = z.infer<typeof ServedAccessManifestBundleWireResponseSchema>;
|
|
62
|
+
/** The bundle as served: its state without the fields its signed bytes name. */
|
|
63
|
+
export declare function toServedAccessManifestBundle(bundle: AccessManifestBundleWireResponse): ServedAccessManifestBundleWireResponse;
|
|
64
|
+
/**
|
|
65
|
+
* The decoded bundle: the served state with every field its signed bytes
|
|
66
|
+
* name taken from those bytes. A field the bytes lack stays absent, so the
|
|
67
|
+
* verifier refuses the bundle as it would a malformed state.
|
|
68
|
+
*/
|
|
69
|
+
export declare function completeServedAccessManifestBundle(bundle: ServedAccessManifestBundleWireResponse): AccessManifestBundleWireResponse;
|
|
70
|
+
export declare function isServedAccessManifestBundleWireResponse(value: unknown): value is ServedAccessManifestBundleWireResponse;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isPlainObject } from "../isPlainObject.js";
|
|
3
|
+
import { registerJsonSchemaView } from "../jsonSchema.js";
|
|
4
|
+
import { loosePlainObject, nonEmptyStringSchema, plainObjectSchema, } from "../schema.js";
|
|
5
|
+
import { AccessEventBundleWireResponseSchema, } from "./accessManifestBundle.js";
|
|
6
|
+
/** Any plain object is a served state on the wire; the brand is static. */
|
|
7
|
+
function isServedManifestState(value) {
|
|
8
|
+
return isPlainObject(value);
|
|
9
|
+
}
|
|
10
|
+
function asServedManifestState(state) {
|
|
11
|
+
const value = state;
|
|
12
|
+
if (!isServedManifestState(value)) {
|
|
13
|
+
throw new TypeError("A served state must be a plain object");
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A bundle as a writer projection serves it. Its `state` carries only what the
|
|
19
|
+
* bundle's own signed bytes do not: the derived fields the hash-committed
|
|
20
|
+
* manifest names (version, object id, organization, epoch, predecessor and
|
|
21
|
+
* event hash) and, for a container, the key epoch and public key its signed
|
|
22
|
+
* body names are left off, and the client fills them back from those bytes
|
|
23
|
+
* when it decodes. The verifier still requires the completed state to equal
|
|
24
|
+
* the state it derives.
|
|
25
|
+
*/
|
|
26
|
+
export const ServedAccessManifestBundleWireResponseSchema = loosePlainObject({
|
|
27
|
+
event: AccessEventBundleWireResponseSchema,
|
|
28
|
+
manifest: plainObjectSchema,
|
|
29
|
+
manifestHash: nonEmptyStringSchema,
|
|
30
|
+
state: registerJsonSchemaView(z.custom(isServedManifestState), z.looseObject({})),
|
|
31
|
+
});
|
|
32
|
+
const MANIFEST_FIELDS = [
|
|
33
|
+
"version",
|
|
34
|
+
"organizationId",
|
|
35
|
+
"epoch",
|
|
36
|
+
"previousManifestHash",
|
|
37
|
+
"eventHash",
|
|
38
|
+
];
|
|
39
|
+
const CONTAINER_BODY_FIELDS = [
|
|
40
|
+
"containerKeyEpochId",
|
|
41
|
+
"containerKeyPublicKey",
|
|
42
|
+
];
|
|
43
|
+
function objectIdField(manifest) {
|
|
44
|
+
const objectKind = Reflect.get(manifest, "objectKind");
|
|
45
|
+
if (objectKind === "container")
|
|
46
|
+
return "containerId";
|
|
47
|
+
if (objectKind === "document")
|
|
48
|
+
return "documentId";
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** The fields of `state` this bundle's own signed bytes name, by source. */
|
|
52
|
+
function signedStateFields(bundle) {
|
|
53
|
+
const { manifest } = bundle;
|
|
54
|
+
const objectId = objectIdField(manifest);
|
|
55
|
+
if (objectId === null)
|
|
56
|
+
return [];
|
|
57
|
+
const body = bundle.event.body;
|
|
58
|
+
return [
|
|
59
|
+
...MANIFEST_FIELDS.map((field) => [field, manifest, field]),
|
|
60
|
+
[objectId, manifest, "objectId"],
|
|
61
|
+
...(objectId === "containerId" && isPlainObject(body)
|
|
62
|
+
? CONTAINER_BODY_FIELDS.map((field) => [field, body, field])
|
|
63
|
+
: []),
|
|
64
|
+
];
|
|
65
|
+
}
|
|
66
|
+
/** The bundle as served: its state without the fields its signed bytes name. */
|
|
67
|
+
export function toServedAccessManifestBundle(bundle) {
|
|
68
|
+
const state = { ...bundle.state };
|
|
69
|
+
for (const [field] of signedStateFields(bundle))
|
|
70
|
+
delete state[field];
|
|
71
|
+
return {
|
|
72
|
+
event: bundle.event,
|
|
73
|
+
manifest: bundle.manifest,
|
|
74
|
+
manifestHash: bundle.manifestHash,
|
|
75
|
+
state: asServedManifestState(state),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The decoded bundle: the served state with every field its signed bytes
|
|
80
|
+
* name taken from those bytes. A field the bytes lack stays absent, so the
|
|
81
|
+
* verifier refuses the bundle as it would a malformed state.
|
|
82
|
+
*/
|
|
83
|
+
export function completeServedAccessManifestBundle(bundle) {
|
|
84
|
+
const served = bundle.state;
|
|
85
|
+
const state = isPlainObject(served)
|
|
86
|
+
? { ...served }
|
|
87
|
+
: {};
|
|
88
|
+
for (const [field, source, key] of signedStateFields(bundle)) {
|
|
89
|
+
const value = Reflect.get(source, key);
|
|
90
|
+
if (value === undefined)
|
|
91
|
+
delete state[field];
|
|
92
|
+
else
|
|
93
|
+
state[field] = value;
|
|
94
|
+
}
|
|
95
|
+
return { ...bundle, state };
|
|
96
|
+
}
|
|
97
|
+
export function isServedAccessManifestBundleWireResponse(value) {
|
|
98
|
+
return ServedAccessManifestBundleWireResponseSchema.safeParse(value).success;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=servedManifestBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"servedManifestBundle.js","sourceRoot":"","sources":["servedManifestBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mCAAmC,GAEpC,MAAM,wBAAwB,CAAC;AAgBhC,2EAA2E;AAC3E,SAAS,qBAAqB,CAAC,KAAc;IAC3C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,qBAAqB,CAC5B,KAA8B;IAE9B,MAAM,KAAK,GAAY,KAAK,CAAC;IAC7B,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4CAA4C,GAAG,gBAAgB,CAAC;IAC3E,KAAK,EAAE,mCAAmC;IAC1C,QAAQ,EAAE,iBAAiB;IAC3B,YAAY,EAAE,oBAAoB;IAClC,KAAK,EAAE,sBAAsB,CAC3B,CAAC,CAAC,MAAM,CAAsB,qBAAqB,CAAC,EACpD,C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M,KAAK,GAA4B,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IAC3D,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IACrE,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAC;KACpC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAA8C;IAE9C,MAAM,MAAM,GAAY,MAAM,CAAC,KAAK,CAAC;IACrC,MAAM,KAAK,GAA4B,aAAa,CAAC,MAAM,CAAC;QAC1D,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE;QACf,CAAC,CAAC,EAAE,CAAC;IACP,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACvC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;;YACxC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IAC5B,CAAC;IACD,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,wCAAwC,CACtD,KAAc;IAEd,OAAO,4CAA4C,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC/E,CAAC","sourcesContent":["import { z } from \"zod\";\nimport { isPlainObject } from \"../isPlainObject\";\nimport { registerJsonSchemaView } from \"../jsonSchema\";\nimport {\n loosePlainObject,\n nonEmptyStringSchema,\n plainObjectSchema,\n} from \"../schema\";\nimport {\n AccessEventBundleWireResponseSchema,\n type AccessManifestBundleWireResponse,\n} from \"./accessManifestBundle\";\n\ndeclare const servedManifestState: unique symbol;\n\n/**\n * A served bundle's reduced state. It is deliberately not a state record, and\n * it carries a brand only parsing or `toServedAccessManifestBundle` gives, so\n * TypeScript refuses a served bundle wherever a full one is required (a purge\n * proof, a verifier input) and a full bundle wherever a served one is (a held\n * citation); `completeServedAccessManifestBundle` is the one conversion that\n * reads it.\n */\nexport interface ServedManifestState {\n readonly [servedManifestState]: true;\n}\n\n/** Any plain object is a served state on the wire; the brand is static. */\nfunction isServedManifestState(value: unknown): value is ServedManifestState {\n return isPlainObject(value);\n}\n\nfunction asServedManifestState(\n state: Record<string, unknown>,\n): ServedManifestState {\n const value: unknown = state;\n if (!isServedManifestState(value)) {\n throw new TypeError(\"A served state must be a plain object\");\n }\n return value;\n}\n\n/**\n * A bundle as a writer projection serves it. Its `state` carries only what the\n * bundle's own signed bytes do not: the derived fields the hash-committed\n * manifest names (version, object id, organization, epoch, predecessor and\n * event hash) and, for a container, the key epoch and public key its signed\n * body names are left off, and the client fills them back from those bytes\n * when it decodes. The verifier still requires the completed state to equal\n * the state it derives.\n */\nexport const ServedAccessManifestBundleWireResponseSchema = loosePlainObject({\n event: AccessEventBundleWireResponseSchema,\n manifest: plainObjectSchema,\n manifestHash: nonEmptyStringSchema,\n state: registerJsonSchemaView(\n z.custom<ServedManifestState>(isServedManifestState),\n z.looseObject({}),\n ),\n});\n\nexport type ServedAccessManifestBundleWireResponse = z.infer<\n typeof ServedAccessManifestBundleWireResponseSchema\n>;\n\nconst MANIFEST_FIELDS = [\n \"version\",\n \"organizationId\",\n \"epoch\",\n \"previousManifestHash\",\n \"eventHash\",\n] as const;\nconst CONTAINER_BODY_FIELDS = [\n \"containerKeyEpochId\",\n \"containerKeyPublicKey\",\n] as const;\n\nfunction objectIdField(manifest: Record<string, unknown>): string | null {\n const objectKind = Reflect.get(manifest, \"objectKind\");\n if (objectKind === \"container\") return \"containerId\";\n if (objectKind === \"document\") return \"documentId\";\n return null;\n}\n\n/** The fields of `state` this bundle's own signed bytes name, by source. */\nfunction signedStateFields(\n bundle: Pick<AccessManifestBundleWireResponse, \"event\" | \"manifest\">,\n): readonly (readonly [string, Record<string, unknown>, string])[] {\n const { manifest } = bundle;\n const objectId = objectIdField(manifest);\n if (objectId === null) return [];\n const body = bundle.event.body;\n return [\n ...MANIFEST_FIELDS.map((field) => [field, manifest, field] as const),\n [objectId, manifest, \"objectId\"] as const,\n ...(objectId === \"containerId\" && isPlainObject(body)\n ? CONTAINER_BODY_FIELDS.map((field) => [field, body, field] as const)\n : []),\n ];\n}\n\n/** The bundle as served: its state without the fields its signed bytes name. */\nexport function toServedAccessManifestBundle(\n bundle: AccessManifestBundleWireResponse,\n): ServedAccessManifestBundleWireResponse {\n const state: Record<string, unknown> = { ...bundle.state };\n for (const [field] of signedStateFields(bundle)) delete state[field];\n return {\n event: bundle.event,\n manifest: bundle.manifest,\n manifestHash: bundle.manifestHash,\n state: asServedManifestState(state),\n };\n}\n\n/**\n * The decoded bundle: the served state with every field its signed bytes\n * name taken from those bytes. A field the bytes lack stays absent, so the\n * verifier refuses the bundle as it would a malformed state.\n */\nexport function completeServedAccessManifestBundle(\n bundle: ServedAccessManifestBundleWireResponse,\n): AccessManifestBundleWireResponse {\n const served: unknown = bundle.state;\n const state: Record<string, unknown> = isPlainObject(served)\n ? { ...served }\n : {};\n for (const [field, source, key] of signedStateFields(bundle)) {\n const value = Reflect.get(source, key);\n if (value === undefined) delete state[field];\n else state[field] = value;\n }\n return { ...bundle, state };\n}\n\nexport function isServedAccessManifestBundleWireResponse(\n value: unknown,\n): value is ServedAccessManifestBundleWireResponse {\n return ServedAccessManifestBundleWireResponseSchema.safeParse(value).success;\n}\n"]}
|
package/package.json
CHANGED