@tearleads/client-sdk 0.1.249 → 0.1.250
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/principalPolicy/mergeProjectionPolicyEvidence.js +1 -4
- package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map +1 -1
- package/data/persistence/principalPolicy/heldOrganizationDirectories.js +6 -1
- package/data/persistence/principalPolicy/heldOrganizationDirectories.js.map +1 -1
- package/data/persistence/principalPolicy/principalPolicyBundleIntegrity.js +1 -1
- package/data/persistence/principalPolicy/principalPolicyBundleIntegrity.js.map +1 -1
- package/data/persistence/principalPolicy/verifiedPrincipalPolicyCurrent.js +1 -5
- package/data/persistence/principalPolicy/verifiedPrincipalPolicyCurrent.js.map +1 -1
- package/data/principals/organizationGroupDirectoryRequest.js +0 -2
- package/data/principals/organizationGroupDirectoryRequest.js.map +1 -1
- package/data/principals/organizationPolicyRequest.js +0 -2
- package/data/principals/organizationPolicyRequest.js.map +1 -1
- package/data/principals/principalPolicyRequest.js +0 -2
- package/data/principals/principalPolicyRequest.js.map +1 -1
- package/internal/api-client/ApiClient.d.ts +0 -58
- package/internal/api-client/client/apiClientContext.d.ts +0 -30
- package/internal/api-client/client/documents.d.ts +0 -12
- package/internal/api-client/client/principalPolicies.d.ts +0 -18
- package/internal/api-client/client/writerProjections.d.ts +0 -12
- package/internal/api-client/heldDirectoryCitations.d.ts +8 -4
- package/internal/api-client/heldDirectoryCitations.js +6 -10
- package/internal/api-client/heldDirectoryCitations.js.map +1 -1
- package/internal/api-client/organizationPolicyHistory.d.ts +0 -6
- package/internal/api-client/principalPolicyRequests.d.ts +0 -18
- package/internal/api-client/verifiedManifestCitations.js +3 -3
- package/internal/api-client/verifiedManifestCitations.js.map +1 -1
- package/internal/crypto/index.d.ts +1 -1
- package/internal/crypto/index.js.map +1 -1
- package/internal/crypto/keying/principalPolicyPayload.js +2 -12
- package/internal/crypto/keying/principalPolicyPayload.js.map +1 -1
- package/internal/crypto/keying/principalPolicyTypes.d.ts +5 -6
- package/internal/crypto/keying/principalPolicyTypes.js.map +1 -1
- package/internal/crypto/principalState.d.ts +1 -1
- package/internal/crypto/principalState.js.map +1 -1
- package/internal/crypto/principalStateTypes.d.ts +0 -1
- package/internal/crypto/principalStateTypes.js.map +1 -1
- package/internal/validators/operation/auth.d.ts +0 -24
- package/internal/validators/operation/documentMutations.d.ts +0 -48
- package/internal/validators/operation/organizationPolicyHistory.d.ts +0 -24
- package/internal/validators/operation/organizations.d.ts +0 -48
- package/internal/validators/operation/principals.d.ts +0 -56
- package/internal/validators/operation/writerProjections.d.ts +0 -48
- package/internal/validators/request/organization.d.ts +0 -32
- package/internal/validators/request/organizationProvisioning.d.ts +0 -72
- package/internal/validators/request/principal.d.ts +4 -48
- package/internal/validators/request/principal.js +4 -2
- package/internal/validators/request/principal.js.map +1 -1
- package/internal/validators/request/registration.d.ts +0 -24
- package/internal/validators/response/container.d.ts +0 -48
- package/internal/validators/response/documentMutation.d.ts +0 -96
- package/internal/validators/response/organizationPolicyHistory.d.ts +0 -24
- package/internal/validators/response/policyEvidenceWire.d.ts +5 -3
- package/internal/validators/response/policyEvidenceWire.js +6 -4
- package/internal/validators/response/policyEvidenceWire.js.map +1 -1
- package/internal/validators/response/principal.d.ts +0 -48
- package/internal/validators/response/principalPolicyPage.d.ts +0 -48
- package/internal/validators/response/principalSnapshot.d.ts +4 -24
- package/internal/validators/response/principalSnapshot.js +4 -6
- package/internal/validators/response/principalSnapshot.js.map +1 -1
- package/internal/validators/response/projectionPolicyEvidence.d.ts +0 -48
- package/package.json +1 -1
- package/workflows/organizations/groupPolicy/currentPolicyMutationAcknowledgement.js +1 -6
- package/workflows/organizations/groupPolicy/currentPolicyMutationAcknowledgement.js.map +1 -1
- package/workflows/organizations/groupPolicy/groupPolicyMutationAcknowledgement.js +1 -6
- package/workflows/organizations/groupPolicy/groupPolicyMutationAcknowledgement.js.map +1 -1
- package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js +4 -6
- package/workflows/organizations/policyHistory/organizationPolicyHistoryVerification.js.map +1 -1
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js +1 -7
- package/workflows/organizations/principalPolicy/principalPolicyReceiptArtifacts.js.map +1 -1
- package/workflows/principals/policyCache/principalPolicyCacheValidation.js +0 -13
- package/workflows/principals/policyCache/principalPolicyCacheValidation.js.map +1 -1
- package/workflows/principals/publicHistory/publicProjectionDirectory.js +4 -5
- package/workflows/principals/publicHistory/publicProjectionDirectory.js.map +1 -1
- package/workflows/registration/provisioningBootstrapBuilders.d.ts +0 -6
- package/workflows/registration/registrationPrincipalPolicyPersistence.js +1 -7
- package/workflows/registration/registrationPrincipalPolicyPersistence.js.map +1 -1
|
@@ -12,10 +12,7 @@ function newer(previous, next) {
|
|
|
12
12
|
}
|
|
13
13
|
function payloadsConflict(previous, payload) {
|
|
14
14
|
return (!principalHeadMatchesReference(previous.reference, payload.reference) ||
|
|
15
|
-
previous.payload.
|
|
16
|
-
previous.payload.principalType !== payload.payload.principalType ||
|
|
17
|
-
previous.payload.ciphertext !== payload.payload.ciphertext ||
|
|
18
|
-
previous.payload.ciphertextHash !== payload.payload.ciphertextHash);
|
|
15
|
+
previous.payload.ciphertext !== payload.payload.ciphertext);
|
|
19
16
|
}
|
|
20
17
|
function keepNewestGroups(groups, candidates) {
|
|
21
18
|
for (const group of candidates) {
|
package/data/keyingProjectionVerification/principalPolicy/mergeProjectionPolicyEvidence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeProjectionPolicyEvidence.js","sourceRoot":"","sources":["mergeProjectionPolicyEvidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAK5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0DAA0D,CAAC;AAEzG,SAAS,KAAK,CACZ,QAAiE,EACjE,IAA0C;IAE1C,IA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C;YACjD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAC3D,IAAI,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC;gBACjD,MAAM,IAAI,uBAAuB,CAC/B,eAAe,EACf,6DAA6D,CAC9D,CAAC;YACJ,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IACD,OAAO;QACL,YAAY,EAAE,SAAS,EAAE,YAAY,IAAI,IAAI;QAC7C,oBAAoB,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC5C,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["import { KeyingVerificationError } from \"@tearleads/crypto\";\nimport type {\n PrincipalPolicyHistorySourceResponse,\n ProjectionPolicyEvidenceResponse,\n} from \"@tearleads/validators/response\";\nimport { principalHeadMatchesReference } from \"../../principalContracts/organizationAuthorityDescriptor\";\n\nfunction newer(\n previous: PrincipalPolicyHistorySourceResponse | null | undefined,\n next: PrincipalPolicyHistorySourceResponse,\n): boolean {\n if (!previous) return true;\n if (previous.head.principalId !== next.head.principalId)\n throw new KeyingVerificationError(\n \"object_mismatch\",\n \"Projection evidence crosses principals\",\n );\n if (\n previous.head.version === next.head.version &&\n !principalHeadMatchesReference(previous.head, next.head)\n )\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Projection evidence contains conflicting heads\",\n );\n return previous.head.version < next.head.version;\n}\n\ntype OrganizationPayload =\n ProjectionPolicyEvidenceResponse[\"organizationPayloads\"][number];\n\nfunction payloadsConflict(\n previous: OrganizationPayload,\n payload: OrganizationPayload,\n): boolean {\n return (\n !principalHeadMatchesReference(previous.reference, payload.reference) ||\n previous.payload.ciphertext !== payload.payload.ciphertext\n );\n}\n\nfunction keepNewestGroups(\n groups: Map<string, PrincipalPolicyHistorySourceResponse>,\n candidates: readonly PrincipalPolicyHistorySourceResponse[],\n): void {\n for (const group of candidates) {\n const prior = groups.get(group.head.principalId);\n if (newer(prior, group)) groups.set(group.head.principalId, group);\n }\n}\n\n/** Combine proof material when locally composing projections; verification follows. */\nexport function mergeProjectionPolicyEvidence(\n evidence: readonly ProjectionPolicyEvidenceResponse[],\n): ProjectionPolicyEvidenceResponse {\n let directory: ProjectionPolicyEvidenceResponse | undefined;\n const groups = new Map<string, PrincipalPolicyHistorySourceResponse>();\n const payloads = new Map<string, OrganizationPayload>();\n for (const proof of evidence) {\n const organization = proof.organization;\n if (organization && newer(directory?.organization, organization))\n directory = proof;\n for (const payload of proof.organizationPayloads) {\n const previous = payloads.get(payload.reference.stateHash);\n if (previous && payloadsConflict(previous, payload))\n throw new KeyingVerificationError(\n \"hash_mismatch\",\n \"Projection evidence contains conflicting directory payloads\",\n );\n payloads.set(payload.reference.stateHash, payload);\n }\n keepNewestGroups(groups, proof.groups);\n }\n return {\n organization: directory?.organization ?? null,\n organizationPayloads: [...payloads.values()],\n groups: [...groups.values()],\n };\n}\n"]}
|
|
@@ -34,7 +34,12 @@ export async function heldDirectoryCitations(execSql, organizationId) {
|
|
|
34
34
|
directoryState.stateHash === row.stateHash &&
|
|
35
35
|
directoryState.principalType === "organization" &&
|
|
36
36
|
directoryState.principalId === organizationId)
|
|
37
|
-
|
|
37
|
+
// Only the ciphertext travels on: a payload cached before #2903 P23
|
|
38
|
+
// also carries fields that no reader uses.
|
|
39
|
+
citations.push({
|
|
40
|
+
directoryState,
|
|
41
|
+
directoryPayload: { ciphertext: directoryPayload.ciphertext },
|
|
42
|
+
});
|
|
38
43
|
}
|
|
39
44
|
return citations;
|
|
40
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heldOrganiz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AAC;YACjD,cAAc,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS;YAC1C,cAAc,CAAC,aAAa,KAAK,cAAc;YAC/C,cAAc,CAAC,WAAW,KAAK,cAAc;YAE7C,oEAAoE;YACpE,2CAA2C;YAC3C,SAAS,CAAC,IAAI,CAAC;gBACb,cAAc;gBACd,gBAAgB,EAAE,EAAE,UAAU,EAAE,gBAAgB,CAAC,UAAU,EAAE;aAC9D,CAAC,CAAC;IACP,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAwB,EAAE,cAAsB;IACzE,OAAO,EAAE;SACN,MAAM,CAAC;QACN,SAAS,EAAE,sBAAsB,CAAC,SAAS;QAC3C,SAAS,EAAE,sBAAsB,CAAC,gBAAgB;QAClD,WAAW,EAAE,sBAAsB,CAAC,kBAAkB;KACvD,CAAC;SACD,IAAI,CAAC,sBAAsB,CAAC;SAC5B,KAAK,CACJ,GAAG,CACD,EAAE,CAAC,sBAAsB,CAAC,aAAa,EAAE,cAAc,CAAC,EACxD,EAAE,CAAC,sBAAsB,CAAC,WAAW,EAAE,cAAc,CAAC,CACvD,CACF;SACA,OAAO,CACN,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EACtC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EACtC,GAAG,CAAC,sBAAsB,CAAC,SAAS,CAAC,CACtC;SACA,KAAK,CAAC,0BAA0B,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { HeldDirectoryCitation } from \"@tearleads/api-client\";\nimport {\n isPrincipalStatePayloadResponse,\n isPrincipalStateResponse,\n} from \"@tearleads/validators/response\";\nimport { KNOWN_DIRECTORY_HINT_LIMIT } from \"@tearleads/validators/util\";\nimport { and, asc, desc, eq } from \"drizzle-orm\";\nimport { principalPolicyBundles } from \"../../sqlite/schema/principalPolicySchema\";\nimport {\n type ClientSQLiteDatabase,\n getClientSQLitePersistenceRuntime,\n} from \"../../sqlite/sqlitePersistenceRuntime\";\nimport type { ExecSql } from \"../../sqlite/sqlSchema\";\n\nfunction parsed(json: string): unknown {\n try {\n return JSON.parse(json);\n } catch {\n return null;\n }\n}\n\n/**\n * The organization directory payloads this device holds in its verified\n * policy bundles, its current state first, at most\n * `KNOWN_DIRECTORY_HINT_LIMIT`. Each travels with its signed state: the\n * request cites a payload only when its bytes hash to that state's\n * `payloadCiphertextHash`, so a refill is exactly the bytes the server would\n * send.\n */\nexport async function heldDirectoryCitations(\n execSql: ExecSql,\n organizationId: string,\n): Promise<HeldDirectoryCitation[]> {\n // Citing only saves bytes: a device that has stored no policy bundle yet\n // (so no table) or cannot read them cites no directory.\n const rows = await heldDirectoryRows(\n getClientSQLitePersistenceRuntime(execSql).db,\n organizationId,\n ).catch(() => []);\n const citations: HeldDirectoryCitation[] = [];\n for (const row of rows) {\n const directoryState = parsed(row.stateJson);\n const directoryPayload = parsed(row.payloadJson);\n // A row must name its own state of this organization, so a request\n // never cites another organization's state hash.\n if (\n isPrincipalStateResponse(directoryState) &&\n isPrincipalStatePayloadResponse(directoryPayload) &&\n directoryState.stateHash === row.stateHash &&\n directoryState.principalType === \"organization\" &&\n directoryState.principalId === organizationId\n )\n // Only the ciphertext travels on: a payload cached before #2903 P23\n // also carries fields that no reader uses.\n citations.push({\n directoryState,\n directoryPayload: { ciphertext: directoryPayload.ciphertext },\n });\n }\n return citations;\n}\n\nfunction heldDirectoryRows(db: ClientSQLiteDatabase, organizationId: string) {\n return db\n .select({\n stateHash: principalPolicyBundles.stateHash,\n stateJson: principalPolicyBundles.currentStateJson,\n payloadJson: principalPolicyBundles.currentPayloadJson,\n })\n .from(principalPolicyBundles)\n .where(\n and(\n eq(principalPolicyBundles.principalType, \"organization\"),\n eq(principalPolicyBundles.principalId, organizationId),\n ),\n )\n .orderBy(\n desc(principalPolicyBundles.isCurrent),\n desc(principalPolicyBundles.updatedAt),\n asc(principalPolicyBundles.stateHash),\n )\n .limit(KNOWN_DIRECTORY_HINT_LIMIT);\n}\n"]}
|
|
@@ -22,7 +22,7 @@ function securityContent(bundle) {
|
|
|
22
22
|
...bundle.currentMemberEnvelopes,
|
|
23
23
|
envelopes: [...bundle.currentMemberEnvelopes.envelopes].sort((a, b) => compareCanonicalStrings(canonical(a), canonical(b))),
|
|
24
24
|
},
|
|
25
|
-
currentPayload:
|
|
25
|
+
currentPayload: { ciphertext: bundle.currentPayload.ciphertext },
|
|
26
26
|
currentProjection: normalizePrincipalProjectionMembers(bundle.currentProjection),
|
|
27
27
|
currentGrants: normalizePrincipalContainerGrants(bundle.currentGrants),
|
|
28
28
|
currentState: withoutCreatedAt(bundle.currentState),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicyBundleIntegrity.js","sourceRoot":"","sources":["principalPolicyBundleIntegrity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAEL,mCAAmC,GACpC,MAAM,+BAA+B,CAAC;AAEvC,SAAS,WAAW,CAClB,GAAoC;IAEpC,MAAM,MAAM,GAAG,mCAAmC,CAAC,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,+BAA+B,CAAC,MAAM,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,yBAAyB,CAC9B,KAAK,EACL,0CAA0C,CAC3C,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,KAAQ;IAER,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC;IAC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\n compareCanonicalStrings,\n KeyingVerificationError,\n normalizePrincipalContainerGrants,\n normalizePrincipalProjectionMembers,\n} from \"@tearleads/crypto\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { isPrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { canonicalKeyingJsonString } from \"../../keying/canonicalJson\";\nimport {\n type StoredPrincipalPolicyBundleJson,\n storedPrincipalPolicyBundleFromJson,\n} from \"./storedPrincipalPolicyBundle\";\n\nfunction parseBundle(\n row: StoredPrincipalPolicyBundleJson,\n): PrincipalPolicyBundleResponse {\n const bundle = storedPrincipalPolicyBundleFromJson(row);\n if (!isPrincipalPolicyBundleResponse(bundle)) {\n throw new Error(\"Stored principal policy bundle is invalid\");\n }\n return bundle;\n}\n\nfunction canonical(value: unknown): string {\n return canonicalKeyingJsonString(\n value,\n \"principal policy bundle security content\",\n );\n}\n\nfunction withoutCreatedAt<T extends { readonly createdAt: string }>(\n value: T,\n): Omit<T, \"createdAt\"> {\n const { createdAt: _createdAt, ...content } = value;\n return content;\n}\n\nfunction securityContent(bundle: PrincipalPolicyBundleResponse) {\n return {\n currentMemberEnvelopes: {\n ...bundle.currentMemberEnvelopes,\n envelopes: [...bundle.currentMemberEnvelopes.envelopes].sort((a, b) =>\n compareCanonicalStrings(canonical(a), canonical(b)),\n ),\n },\n currentPayload: { ciphertext: bundle.currentPayload.ciphertext },\n currentProjection: normalizePrincipalProjectionMembers(\n bundle.currentProjection,\n ),\n currentGrants: normalizePrincipalContainerGrants(bundle.currentGrants),\n currentState: withoutCreatedAt(bundle.currentState),\n previousStates: bundle.previousStates.map((entry) => ({\n projection: normalizePrincipalProjectionMembers(entry.projection),\n grants: normalizePrincipalContainerGrants(entry.grants),\n state: withoutCreatedAt(entry.state),\n })),\n };\n}\n\nexport function assertSameHeadPrincipalPolicyBundle(\n stored: StoredPrincipalPolicyBundleJson,\n incoming: StoredPrincipalPolicyBundleJson,\n): void {\n try {\n if (\n canonical(securityContent(parseBundle(stored))) ===\n canonical(securityContent(parseBundle(incoming)))\n ) {\n return;\n }\n } catch {\n // Invalid same-head cache content is also an integrity conflict: replacing\n // it would erase the only durable evidence that the head was inconsistent.\n }\n throw new KeyingVerificationError(\n \"equivocation\",\n \"principal policy bundle content conflicts with the cached bundle at the same head\",\n );\n}\n"]}
|
|
@@ -18,11 +18,7 @@ async function assertCurrentPayloadMatches(input) {
|
|
|
18
18
|
const { current, policy } = input;
|
|
19
19
|
const payloadHash = await computePrincipalStatePayloadCiphertextHash(current.currentPayload.ciphertext);
|
|
20
20
|
const envelopesRoot = await memberEnvelopesRoot(current);
|
|
21
|
-
if (
|
|
22
|
-
current.currentPayload.principalId !== policy.principalId ||
|
|
23
|
-
current.currentPayload.stateHash !== policy.stateHash ||
|
|
24
|
-
current.currentPayload.ciphertextHash !== payloadHash ||
|
|
25
|
-
policy.state.payloadCiphertextHash !== payloadHash ||
|
|
21
|
+
if (policy.state.payloadCiphertextHash !== payloadHash ||
|
|
26
22
|
current.currentMemberEnvelopes.principalType !== policy.principalType ||
|
|
27
23
|
current.currentMemberEnvelopes.principalId !== policy.principalId ||
|
|
28
24
|
current.currentMemberEnvelopes.stateHash !== policy.stateHash ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiedPrincipalPolicyCurrent.js","sourceRoot":"","sources":["verifiedPrincipalPolicyCurrent.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mCAAmC,EACnC,0CAA0C,EAC1C,uBAAuB,EACvB,iCAAiC,EACjC,mCAAmC,EACnC,sCAAsC,GAGvC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAMvE,SAAS,eAAe,CAAC,OAAe;IACtC,MAAM,IAAI,uBAAuB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED,KAAK,UAAU,mBAAmB,CAChC,OAAmC;IAEnC,IAAI,CAAC;QACH,OA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,MAAM,CAAC,UAAU,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,EAChD,CAAC;QACD,eAAe,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IACE,yBAAyB,CACvB,OAAO,CAAC,YAAY,EACpB,gCAAgC,CACjC;QACC,yBAAyB,CACvB,MAAM,CAAC,KAAK,EACZ,iCAAiC,CAClC;QACH,yBAAyB,CACvB,mCAAmC,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAC9D,qCAAqC,CACtC;YACC,yBAAyB,CACvB,mCAAmC,CAAC,MAAM,CAAC,UAAU,CAAC,EACtD,sCAAsC,CACvC;QACH,yBAAyB,CACvB,iCAAiC,CAAC,OAAO,CAAC,aAAa,CAAC,EACxD,iCAAiC,CAClC;YACC,yBAAyB,CACvB,iCAAiC,CAAC,MAAM,CAAC,MAAM,CAAC,EAChD,kCAAkC,CACnC,EACH,CAAC;QACD,eAAe,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,2BAA2B,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type { PrincipalPolicyPageCurrent } from \"@tearleads/api-client\";\nimport {\n computePrincipalMemberEnvelopesRoot,\n computePrincipalStatePayloadCiphertextHash,\n KeyingVerificationError,\n normalizePrincipalContainerGrants,\n normalizePrincipalProjectionMembers,\n PrincipalMemberEnvelopeValidationError,\n type VerifiedPrincipalPolicy,\n type VerifiedPrincipalPolicyCurrent,\n} from \"@tearleads/crypto\";\nimport { canonicalKeyingJsonString } from \"../../keying/canonicalJson\";\n\ntype VerifiedCurrentPolicy =\n | VerifiedPrincipalPolicy\n | VerifiedPrincipalPolicyCurrent;\n\nfunction currentMismatch(message: string): never {\n throw new KeyingVerificationError(\"equivocation\", message);\n}\n\nasync function memberEnvelopesRoot(\n current: PrincipalPolicyPageCurrent,\n): Promise<string> {\n try {\n return await computePrincipalMemberEnvelopesRoot(\n current.currentMemberEnvelopes.envelopes,\n );\n } catch (error) {\n if (error instanceof PrincipalMemberEnvelopeValidationError) {\n throw new KeyingVerificationError(\"invalid_shape\", error.message);\n }\n throw error;\n }\n}\n\nasync function assertCurrentPayloadMatches(input: {\n current: PrincipalPolicyPageCurrent;\n policy: VerifiedCurrentPolicy;\n}): Promise<void> {\n const { current, policy } = input;\n const payloadHash = await computePrincipalStatePayloadCiphertextHash(\n current.currentPayload.ciphertext,\n );\n const envelopesRoot = await memberEnvelopesRoot(current);\n if (\n policy.state.payloadCiphertextHash !== payloadHash ||\n current.currentMemberEnvelopes.principalType !== policy.principalType ||\n current.currentMemberEnvelopes.principalId !== policy.principalId ||\n current.currentMemberEnvelopes.stateHash !== policy.stateHash ||\n current.currentMemberEnvelopes.epoch !== policy.keyEpoch ||\n envelopesRoot !== policy.state.memberEnvelopesRoot\n ) {\n currentMismatch(\"Verified principal policy current payload mismatch\");\n }\n}\n\n/** Bind current wire artifacts to already verified policy evidence; never authenticate history. */\nexport async function assertCurrentMatchesVerifiedPolicy(input: {\n current: PrincipalPolicyPageCurrent;\n policy: VerifiedCurrentPolicy;\n}): Promise<void> {\n const { current, policy } = input;\n if (\n current.currentState.principalType !== policy.principalType ||\n current.currentState.principalId !== policy.principalId ||\n current.currentState.version !== policy.version ||\n current.currentState.keyEpoch !== policy.keyEpoch ||\n current.currentState.stateHash !== policy.stateHash ||\n policy.checkpoint.version !== policy.version ||\n policy.checkpoint.stateHash !== policy.stateHash\n ) {\n currentMismatch(\"Verified principal policy current head mismatch\");\n }\n if (\n canonicalKeyingJsonString(\n current.currentState,\n \"principal policy current state\",\n ) !==\n canonicalKeyingJsonString(\n policy.state,\n \"verified principal policy state\",\n ) ||\n canonicalKeyingJsonString(\n normalizePrincipalProjectionMembers(current.currentProjection),\n \"principal policy current projection\",\n ) !==\n canonicalKeyingJsonString(\n normalizePrincipalProjectionMembers(policy.projection),\n \"verified principal policy projection\",\n ) ||\n canonicalKeyingJsonString(\n normalizePrincipalContainerGrants(current.currentGrants),\n \"principal policy current grants\",\n ) !==\n canonicalKeyingJsonString(\n normalizePrincipalContainerGrants(policy.grants),\n \"verified principal policy grants\",\n )\n ) {\n currentMismatch(\"Verified principal policy current content mismatch\");\n }\n\n await assertCurrentPayloadMatches(input);\n}\n"]}
|
|
@@ -57,9 +57,7 @@ export async function buildOrganizationGroupDirectoryPolicyRequest(input) {
|
|
|
57
57
|
}), input.signingKeyPair.signingPrivateKey);
|
|
58
58
|
return {
|
|
59
59
|
encryptedPayload: {
|
|
60
|
-
cipherSuite: "aes-256-gcm",
|
|
61
60
|
ciphertext: payloadCiphertext,
|
|
62
|
-
ciphertextHash: state.payloadCiphertextHash,
|
|
63
61
|
},
|
|
64
62
|
grants: [],
|
|
65
63
|
memberEnvelopes: keying.memberEnvelopes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationGroupDirectoryRequest.js","sourceRoot":"","sources":["organizationGroupDirectoryRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,mCAAmC,EAGnC,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EACL,qCAAqC,EACrC,+BAA+B,GAGhC,MAAM,uDAAuD,CAAC;AAE/D,OAAO,EAEL,2BAA2B,GAC5B,MAAM,+BAA+B,CAAC;AAEvC,MAAM,UAAU,qBAAqB,CACnC,IAA6B;IAE7B,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,KAG5C;IACC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvD,OAAO,+BAA+B,CAAC;QACrC,GAAG,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CACnC,CAAC,IAAI,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MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAChE,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,UAAU;QACV,MAAM,EAAE,EAAE;QACV,iBAAiB;QACjB,iBAAiB,EAAE,IAAI;QACvB,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,wBAAwB,EAAE,KAAK,CAAC,kBAAkB;KACnD,CAAC,EACF,KAAK,CAAC,cAAc,CAAC,iBAAiB,CACvC,CAAC;IAEF,OAAO;QACL,gBAAgB,EAAE;YAChB,UAAU,EAAE,iBAAiB;SAC9B;QACD,MAAM,EAAE,EAAE;QACV,eAAe,EAAE,MAAM,CAAC,eAAe;QACvC,UAAU;QACV,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n normalizePrincipalProjectionMembers,\n type ReferencedPrincipalHead,\n type SigningKeyPair,\n signPrincipalState,\n} from \"@tearleads/crypto\";\nimport type {\n PrincipalProjectionMemberRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport {\n encodeOrganizationAuthorityDescriptor,\n normalizeOrganizationGroupHeads,\n type OrganizationAuthorityDescriptor,\n type OrganizationGroupHead,\n} from \"../principalContracts/organizationAuthorityDescriptor\";\nimport type { TrustedUserIdentity } from \"../trustedUserIdentity\";\nimport {\n type OrganizationDirectoryCurrentPolicy,\n organizationDirectoryKeying,\n} from \"./organizationDirectoryKeying\";\n\nexport function organizationGroupHead(\n head: ReferencedPrincipalHead,\n): OrganizationGroupHead {\n if (head.principalType !== \"group\") {\n throw new Error(\"Organization directory can contain only group heads\");\n }\n return { ...head, principalType: \"group\" };\n}\n\nexport function replaceOrganizationGroupHead(input: {\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly nextHead: ReferencedPrincipalHead;\n}): OrganizationGroupHead[] {\n const nextHead = organizationGroupHead(input.nextHead);\n return normalizeOrganizationGroupHeads([\n ...input.descriptor.groupHeads.filter(\n (head) => head.principalId !== nextHead.principalId,\n ),\n nextHead,\n ]);\n}\n\n/**\n * The organization's successor directory state. Its key follows the Admins\n * projection (see `organizationDirectoryKeying`): `currentUserSecretKey` is\n * the signer's KEM secret, needed only to keep the key while admins grow;\n * without it a growth rotates.\n */\nexport async function buildOrganizationGroupDirectoryPolicyRequest(input: {\n readonly adminProjection: readonly PrincipalProjectionMemberRequest[];\n readonly adminUsers: readonly TrustedUserIdentity[];\n readonly currentPolicy: OrganizationDirectoryCurrentPolicy &\n Pick<PrincipalPolicyBundleResponse, \"currentState\">;\n readonly currentUserSecretKey: Uint8Array | null;\n readonly descriptor: OrganizationAuthorityDescriptor;\n readonly groupHeads: readonly OrganizationGroupHead[];\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<PutPrincipalPolicyRequest> {\n const projection = normalizePrincipalProjectionMembers(input.adminProjection);\n if (\n projection.length === 0 ||\n projection.some((member) => member.role !== \"admin\")\n ) {\n throw new Error(\"Organization policy must mirror the Admins projection\");\n }\n const keying = await organizationDirectoryKeying({\n currentPolicy: input.currentPolicy,\n currentUserSecretKey: input.currentUserSecretKey,\n projection,\n signerUserId: input.signerUserId,\n users: input.adminUsers,\n });\n const payloadCiphertext = encodeOrganizationAuthorityDescriptor({\n ...input.descriptor,\n groupHeads: input.groupHeads,\n });\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"organization\",\n principalId: input.descriptor.organizationId,\n version: input.currentPolicy.currentState.version + 1,\n prevStateHash: input.currentPolicy.currentState.stateHash,\n keyEpoch: keying.keyEpoch,\n encapsulationPublicKey: keying.encapsulationPublicKey,\n keyFingerprint: keying.keyFingerprint,\n members: projection.map((member) => ({ userId: member.userId })),\n memberEnvelopes: keying.memberEnvelopes,\n projection,\n grants: [],\n payloadCiphertext,\n externalAuthority: null,\n signedAt: new Date().toISOString(),\n signerUserId: input.signerUserId,\n signerUserKeyFingerprint: input.signingFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n encryptedPayload: {\n ciphertext: payloadCiphertext,\n },\n grants: [],\n memberEnvelopes: keying.memberEnvelopes,\n projection,\n state,\n };\n}\n"]}
|
|
@@ -59,9 +59,7 @@ export async function buildInitialOrganizationPolicyRequest(input) {
|
|
|
59
59
|
return {
|
|
60
60
|
state,
|
|
61
61
|
encryptedPayload: {
|
|
62
|
-
cipherSuite: "aes-256-gcm",
|
|
63
62
|
ciphertext: payloadCiphertext,
|
|
64
|
-
ciphertextHash: state.payloadCiphertextHash,
|
|
65
63
|
},
|
|
66
64
|
projection,
|
|
67
65
|
grants: [],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organizationPolicyRequest.js","sourceRoot":"","sources":["organizationPolicyRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,yBAAyB,EAGzB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,qCAAqC,EAAE,MAAM,uDAAuD,CAAC;AAC9G,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAErG,MAAM,CAAC,KAAK,UAAU,qCAAqC,CAAC,KAS3D;IACC,MAAM,eAAe,GAAG,yBAAyB,EAAE,CAAC;IACpD,MAAM,wBAAwB,GAAG,MAAM,aAAa,CAClD,KAAK,CAAC,cAAc,CAAC,gBAAgB,CACtC,CAAC;IACF,MAAM,+BAA+B,GAAG,MAAM,aAAa,CACzD,KAAK,CAAC,sBAAsB,CAC7B,CAAC;IACF,MAAM,UAAU,GAAG;QACjB,MAAM,+BAA+B,CACnC;YACE,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,mBAAmB,EAAE,KAAK,CAAC,mBAAm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Q,EAAE,CAAC;QACX,sBAAsB,EAAE,aAAa,CAAC,eAAe,CAAC,SAAS,CAAC;QAChE,cAAc,EAAE,MAAM,aAAa,CAAC,eAAe,CAAC,SAAS,CAAC;QAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;QACnC,eAAe;QACf,UAAU;QACV,MAAM,EAAE,EAAE;QACV,iBAAiB;QACjB,iBAAiB,EAAE,IAAI;QACvB,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,YAAY,EAAE,KAAK,CAAC,MAAM;QAC1B,wBAAwB;KACzB,CAAC,EACF,KAAK,CAAC,cAAc,CAAC,iBAAiB,CACvC,CAAC;IAEF,OAAO;QACL,KAAK;QACL,gBAAgB,EAAE;YAChB,UAAU,EAAE,iBAAiB;SAC9B;QACD,UAAU;QACV,MAAM,EAAE,EAAE;QACV,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n generateKemSeedAndKeyPair,\n type ReferencedPrincipalHead,\n type SigningKeyPair,\n signPrincipalState,\n toFingerprint,\n wrapDekForRecipients,\n} from \"@tearleads/crypto\";\nimport { bytesToBase64 } from \"@tearleads/encoding\";\nimport type { RegistrationRequest } from \"@tearleads/validators/request\";\nimport { encodeOrganizationAuthorityDescriptor } from \"../principalContracts/organizationAuthorityDescriptor\";\nimport { createPrincipalProjectionMember } from \"../principalContracts/principalIdentityCommitments\";\n\nexport async function buildInitialOrganizationPolicyRequest(input: {\n identityTrustDomain: string;\n adminGroupId: string;\n groupHeads: readonly ReferencedPrincipalHead[];\n encapsulationPublicKey: Uint8Array;\n memberGroupId: string;\n organizationId: string;\n signingKeyPair: SigningKeyPair;\n userId: string;\n}): Promise<RegistrationRequest[\"initialOrganizationPolicy\"]> {\n const organizationKem = generateKemSeedAndKeyPair();\n const signerUserKeyFingerprint = await toFingerprint(\n input.signingKeyPair.signingPublicKey,\n );\n const userEncapsulationKeyFingerprint = await toFingerprint(\n input.encapsulationPublicKey,\n );\n const projection = [\n await createPrincipalProjectionMember(\n {\n userId: input.userId,\n identityTrustDomain: input.identityTrustDomain,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n encapsulationPublicKey: input.encapsulationPublicKey,\n },\n \"admin\",\n ),\n ];\n const payloadCiphertext = encodeOrganizationAuthorityDescriptor({\n version: 2,\n organizationId: input.organizationId,\n adminGroupId: input.adminGroupId,\n memberGroupId: input.memberGroupId,\n groupHeads: input.groupHeads.map((head) => {\n if (head.principalType !== \"group\") {\n throw new Error(\"Organization directory can contain only group heads\");\n }\n return { ...head, principalType: \"group\" };\n }),\n });\n const [memberEnvelope] = await wrapDekForRecipients(\n organizationKem.secretKey,\n [input.encapsulationPublicKey],\n );\n\n if (!memberEnvelope) {\n throw new Error(\"Failed to wrap organization key for registering user\");\n }\n const memberEnvelopes = [\n {\n userId: input.userId,\n memberKeyFingerprint: userEncapsulationKeyFingerprint,\n kemCipherText: bytesToBase64(memberEnvelope.kemCipherText),\n wrappedKey: bytesToBase64(memberEnvelope.wrappedKey),\n },\n ];\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"organization\",\n principalId: input.organizationId,\n version: 1,\n prevStateHash: null,\n keyEpoch: 1,\n encapsulationPublicKey: bytesToBase64(organizationKem.publicKey),\n keyFingerprint: await toFingerprint(organizationKem.publicKey),\n members: [{ userId: input.userId }],\n memberEnvelopes,\n projection,\n grants: [],\n payloadCiphertext,\n externalAuthority: null,\n signedAt: new Date().toISOString(),\n signerUserId: input.userId,\n signerUserKeyFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n state,\n encryptedPayload: {\n ciphertext: payloadCiphertext,\n },\n projection,\n grants: [],\n memberEnvelopes,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicyRequest.js","sourceRoot":"","sources":["principalPolicyRequest.ts"],"names":[],"mappings":"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EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;QACzD,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,IAAI,IAAI;QAClD,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,MAAM,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;QACvD,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;QAC1B,eAAe;QACf,iBAAiB;QACjB,WAAW,EAAE,KAAK,CAAC,OAAO;QAC1B,UAAU;QACV,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,kBAAkB,EAAE,aAAa;KAClC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CAAC,KAQ1D;IACC,OAAO,8BAA8B,CAAC;QACpC,GAAG,KAAK;QACR,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n type EncapsulationKeyPair,\n encodeBuiltinGroupMetadata,\n encryptGroupMetadata,\n type GroupMetadataKey,\n generateKemSeedAndKeyPair,\n normalizePrincipalContainerGrants,\n normalizePrincipalProjectionMembers,\n type PrincipalContainerGrant,\n type PrincipalPolicyExternalAuthority,\n readGroupMetadata,\n type SigningKeyPair,\n signPrincipalState,\n toFingerprint,\n wrapDekForRecipients,\n} from \"@tearleads/crypto\";\nimport { bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n CreateOrganizationGroupRequest,\n PrincipalMemberEnvelopeRequest,\n PrincipalProjectionMemberRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { createPrincipalProjectionMember } from \"../principalContracts/principalIdentityCommitments\";\n\ninterface BuildInitialGroupPolicyInput {\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly externalAuthority?:\n | PrincipalPolicyExternalAuthority[\"currentHead\"]\n | null;\n readonly groupId: string;\n readonly grants?: readonly PrincipalContainerGrant[] | undefined;\n readonly includeSignerAsAdmin?: boolean;\n readonly name: string;\n readonly metadataKey?: GroupMetadataKey;\n readonly builtinRole?: \"admins\" | \"members\";\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}\n\nfunction projectionToStateMembers(\n projection: ReadonlyArray<PrincipalProjectionMemberRequest>,\n) {\n return projection.map((member) => ({ userId: member.userId }));\n}\n\n/**\n * Code points that must never appear in a group name: control and format\n * characters (bidi overrides, zero-width joiners, newlines), lone surrogates\n * (re-encoded as U+FFFD when signed, so the signed name would no longer match\n * the one sent to the server), and every other default-ignorable code point\n * (Hangul fillers, variation selectors), which render as nothing and would\n * let one name pass for another. A group name is an identifier here, so this\n * deliberately refuses ZWJ emoji sequences as well. One predicate serves the\n * signing-time and the share-time refusal so the two cannot drift.\n */\nfunction hasForbiddenGroupNameCharacter(name: string): boolean {\n return /[\\p{Cc}\\p{Cf}\\p{Cs}\\p{Default_Ignorable_Code_Point}]/u.test(name);\n}\n\n/**\n * The comparison key for a group display name: width- and compatibility-\n * normalized, stripped of control, format, and default-ignorable characters,\n * whitespace-collapsed, and case-folded. Two names that a user cannot tell\n * apart in a picker must compare equal, or a look-alike name would slip past\n * the share-time binding. Cross-script homoglyphs (Latin \"A\" against Greek\n * \"Α\") are not folded: that needs the UTS #39 confusables table, and both\n * names would still have to be signed groups the organization's own admins\n * created.\n */\nexport function canonicalGroupNameKey(name: string): string {\n return (\n name\n .normalize(\"NFKC\")\n .replace(/[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}]/gu, \"\")\n .replace(/\\s+/gu, \" \")\n .trim()\n .toLocaleLowerCase(\"en-US\")\n // Case folding can leave the string un-normalized (U+0130 lowercases to\n // \"i\" plus a combining dot), so normalize once more after it.\n .normalize(\"NFKC\")\n );\n}\n\ntype GroupPolicyNameInput = Pick<\n PrincipalPolicyBundleResponse,\n \"currentState\" | \"currentPayload\"\n>;\n\nexport type GroupPolicyNameReader = (\n bundle: GroupPolicyNameInput,\n) => Promise<string>;\n\n/** Read only after the policy and its organization-directory binding verify. */\nexport async function readGroupPolicyPayloadName(\n bundle: GroupPolicyNameInput,\n readEncryptedName?: GroupPolicyNameReader,\n): Promise<string> {\n const metadata = readGroupMetadata(bundle.currentPayload.ciphertext);\n if (\"role\" in metadata)\n return metadata.role === \"admins\" ? \"Admins\" : \"Members\";\n if (!readEncryptedName)\n throw new Error(\"Group metadata decryption context is unavailable\");\n return readEncryptedName(bundle);\n}\n\n/** One binding predicate for every operation selected by a read-model label. */\nexport async function groupPolicyNameMismatch(\n bundle: GroupPolicyNameInput,\n expectedGroupName: string,\n readEncryptedName?: GroupPolicyNameReader,\n): Promise<\"forbidden_characters\" | \"name_mismatch\" | null> {\n if (hasForbiddenGroupNameCharacter(expectedGroupName)) {\n return \"forbidden_characters\";\n }\n const signedName = await readGroupPolicyPayloadName(\n bundle,\n readEncryptedName,\n );\n if (hasForbiddenGroupNameCharacter(signedName)) return \"forbidden_characters\";\n return canonicalGroupNameKey(signedName) ===\n canonicalGroupNameKey(expectedGroupName)\n ? null\n : \"name_mismatch\";\n}\n\nexport async function signedGroupPolicyRequest(input: {\n readonly currentPolicy?: Pick<PrincipalPolicyBundleResponse, \"currentState\">;\n readonly encapsulationPublicKey: string;\n readonly externalAuthority:\n | PrincipalPolicyExternalAuthority[\"currentHead\"]\n | null;\n readonly keyEpoch: number;\n readonly keyFingerprint: string;\n readonly grants: ReadonlyArray<PrincipalContainerGrant>;\n readonly memberEnvelopes: ReadonlyArray<PrincipalMemberEnvelopeRequest>;\n readonly payloadCiphertext: string;\n readonly principalId: string;\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly signedAt: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<PutPrincipalPolicyRequest> {\n const projection = normalizePrincipalProjectionMembers(input.projection);\n const grants = normalizePrincipalContainerGrants(input.grants);\n const payloadCiphertext = input.payloadCiphertext;\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"group\",\n principalId: input.principalId,\n version: input.currentPolicy\n ? input.currentPolicy.currentState.version + 1\n : 1,\n prevStateHash: input.currentPolicy?.currentState.stateHash ?? null,\n keyEpoch: input.keyEpoch,\n encapsulationPublicKey: input.encapsulationPublicKey,\n keyFingerprint: input.keyFingerprint,\n members: projectionToStateMembers(projection),\n memberEnvelopes: [...input.memberEnvelopes],\n projection,\n grants,\n payloadCiphertext,\n externalAuthority: input.externalAuthority,\n signedAt: input.signedAt,\n signerUserId: input.signerUserId,\n signerUserKeyFingerprint: input.signingFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n state,\n encryptedPayload: {\n cipherSuite: \"aes-256-gcm\",\n ciphertext: payloadCiphertext,\n ciphertextHash: state.payloadCiphertextHash,\n },\n projection,\n grants,\n memberEnvelopes: [...input.memberEnvelopes],\n };\n}\n\nexport async function buildInitialGroupPolicyRequest(\n input: BuildInitialGroupPolicyInput,\n): Promise<CreateOrganizationGroupRequest> {\n const groupKem = generateKemSeedAndKeyPair();\n const withSigner = input.includeSignerAsAdmin ?? true;\n const projection = withSigner\n ? [\n await createPrincipalProjectionMember(\n {\n userId: input.signerUserId,\n identityTrustDomain: input.identityTrustDomain,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n encapsulationPublicKey: input.creatorEncapsulationKeyPair.publicKey,\n },\n \"admin\",\n ),\n ]\n : [];\n const memberEnvelopes: PrincipalMemberEnvelopeRequest[] = [];\n\n if (withSigner) {\n const creatorFingerprint = await toFingerprint(\n input.creatorEncapsulationKeyPair.publicKey,\n );\n const [creatorEnvelope] = await wrapDekForRecipients(groupKem.secretKey, [\n input.creatorEncapsulationKeyPair.publicKey,\n ]);\n\n if (!creatorEnvelope) {\n throw new Error(\"Failed to wrap group key for creator\");\n }\n\n memberEnvelopes.push({\n userId: input.signerUserId,\n memberKeyFingerprint: creatorFingerprint,\n kemCipherText: bytesToBase64(creatorEnvelope.kemCipherText),\n wrappedKey: bytesToBase64(creatorEnvelope.wrappedKey),\n });\n }\n const name = input.name.trim();\n // A name is compared by canonical key but displayed raw, so an invisible\n // code point would let one signed name render as another. Refuse them\n // where the name is signed.\n if (name.length === 0 || hasForbiddenGroupNameCharacter(name)) {\n throw new Error(\n \"Group names must be non-empty and contain no control, format, or surrogate characters\",\n );\n }\n const payloadCiphertext = input.builtinRole\n ? encodeBuiltinGroupMetadata(input.builtinRole)\n : input.metadataKey\n ? await encryptGroupMetadata({\n key: input.metadataKey,\n groupId: input.groupId,\n name,\n })\n : (() => {\n throw new Error(\"Group metadata encryption context is unavailable\");\n })();\n const policyRequest = await signedGroupPolicyRequest({\n encapsulationPublicKey: bytesToBase64(groupKem.publicKey),\n externalAuthority: input.externalAuthority ?? null,\n keyEpoch: 1,\n keyFingerprint: await toFingerprint(groupKem.publicKey),\n grants: input.grants ?? [],\n memberEnvelopes,\n payloadCiphertext,\n principalId: input.groupId,\n projection,\n signedAt: new Date().toISOString(),\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n\n return {\n groupId: input.groupId,\n initialGroupPolicy: policyRequest,\n };\n}\n\n/**\n * Members at bootstrap holds the registering user alone.\n *\n * It used to also contain the Admins group as a nested member, so that admins\n * were implicitly members. Principals contain only users now, so an admin is an\n * ordinary Members entry — and bootstrap has exactly one user, who is that\n * admin.\n */\nexport async function buildInitialMemberGroupPolicyRequest(input: {\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly groupId: string;\n readonly grants?: readonly PrincipalContainerGrant[] | undefined;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<CreateOrganizationGroupRequest> {\n return buildInitialGroupPolicyRequest({\n ...input,\n name: \"Members\",\n builtinRole: \"members\",\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"principalPolicyRequest.js","sourceRoot":"","sources":["principalPolicyRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAE/B,0BAA0B,EAC1B,oBAAoB,EAEpB,yBAAyB,EACzB,iCAAiC,EACjC,mCAAmC,EAGnC,iBAAiB,EAEjB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAmBrG,SAAS,wBAAwB,CAC/B,UAA2D;IAE3D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,8BAA8B,CAAC,IAAY;IAClD,OAAO,uDAAuD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,CACL,IAAI;SACD,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,kDAAkD,EAAE,EAAE,CAAC;SAC/D,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,IAAI,EAAE;SACN,iBAAiB,CAAC,OAAO,CAAC;QAC3B,wEAAwE;QACxE,8DAA8D;SAC7D,SAAS,CAAC,MAAM,CAAC,CACrB,CAAC;AACJ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K,CAAC,WAAW;gBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,IAAI;aACL,CAAC;YACJ,CAAC,CAAC,CAAC,GAAG,EAAE;gBACJ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,CAAC,CAAC,EAAE,CAAC;IACX,MAAM,aAAa,GAAG,MAAM,wBAAwB,CAAC;QACnD,sBAAsB,EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;QACzD,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,IAAI,IAAI;QAClD,QAAQ,EAAE,CAAC;QACX,cAAc,EAAE,MAAM,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;QACvD,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,EAAE;QAC1B,eAAe;QACf,iBAAiB;QACjB,WAAW,EAAE,KAAK,CAAC,OAAO;QAC1B,UAAU;QACV,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,cAAc,EAAE,KAAK,CAAC,cAAc;KACrC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,kBAAkB,EAAE,aAAa;KAClC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CAAC,KAQ1D;IACC,OAAO,8BAA8B,CAAC;QACpC,GAAG,KAAK;QACR,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n buildPrincipalStateSigningInput,\n type EncapsulationKeyPair,\n encodeBuiltinGroupMetadata,\n encryptGroupMetadata,\n type GroupMetadataKey,\n generateKemSeedAndKeyPair,\n normalizePrincipalContainerGrants,\n normalizePrincipalProjectionMembers,\n type PrincipalContainerGrant,\n type PrincipalPolicyExternalAuthority,\n readGroupMetadata,\n type SigningKeyPair,\n signPrincipalState,\n toFingerprint,\n wrapDekForRecipients,\n} from \"@tearleads/crypto\";\nimport { bytesToBase64 } from \"@tearleads/encoding\";\nimport type {\n CreateOrganizationGroupRequest,\n PrincipalMemberEnvelopeRequest,\n PrincipalProjectionMemberRequest,\n PutPrincipalPolicyRequest,\n} from \"@tearleads/validators/request\";\nimport type { PrincipalPolicyBundleResponse } from \"@tearleads/validators/response\";\nimport { createPrincipalProjectionMember } from \"../principalContracts/principalIdentityCommitments\";\n\ninterface BuildInitialGroupPolicyInput {\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly externalAuthority?:\n | PrincipalPolicyExternalAuthority[\"currentHead\"]\n | null;\n readonly groupId: string;\n readonly grants?: readonly PrincipalContainerGrant[] | undefined;\n readonly includeSignerAsAdmin?: boolean;\n readonly name: string;\n readonly metadataKey?: GroupMetadataKey;\n readonly builtinRole?: \"admins\" | \"members\";\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}\n\nfunction projectionToStateMembers(\n projection: ReadonlyArray<PrincipalProjectionMemberRequest>,\n) {\n return projection.map((member) => ({ userId: member.userId }));\n}\n\n/**\n * Code points that must never appear in a group name: control and format\n * characters (bidi overrides, zero-width joiners, newlines), lone surrogates\n * (re-encoded as U+FFFD when signed, so the signed name would no longer match\n * the one sent to the server), and every other default-ignorable code point\n * (Hangul fillers, variation selectors), which render as nothing and would\n * let one name pass for another. A group name is an identifier here, so this\n * deliberately refuses ZWJ emoji sequences as well. One predicate serves the\n * signing-time and the share-time refusal so the two cannot drift.\n */\nfunction hasForbiddenGroupNameCharacter(name: string): boolean {\n return /[\\p{Cc}\\p{Cf}\\p{Cs}\\p{Default_Ignorable_Code_Point}]/u.test(name);\n}\n\n/**\n * The comparison key for a group display name: width- and compatibility-\n * normalized, stripped of control, format, and default-ignorable characters,\n * whitespace-collapsed, and case-folded. Two names that a user cannot tell\n * apart in a picker must compare equal, or a look-alike name would slip past\n * the share-time binding. Cross-script homoglyphs (Latin \"A\" against Greek\n * \"Α\") are not folded: that needs the UTS #39 confusables table, and both\n * names would still have to be signed groups the organization's own admins\n * created.\n */\nexport function canonicalGroupNameKey(name: string): string {\n return (\n name\n .normalize(\"NFKC\")\n .replace(/[\\p{Cc}\\p{Cf}\\p{Default_Ignorable_Code_Point}]/gu, \"\")\n .replace(/\\s+/gu, \" \")\n .trim()\n .toLocaleLowerCase(\"en-US\")\n // Case folding can leave the string un-normalized (U+0130 lowercases to\n // \"i\" plus a combining dot), so normalize once more after it.\n .normalize(\"NFKC\")\n );\n}\n\ntype GroupPolicyNameInput = Pick<\n PrincipalPolicyBundleResponse,\n \"currentState\" | \"currentPayload\"\n>;\n\nexport type GroupPolicyNameReader = (\n bundle: GroupPolicyNameInput,\n) => Promise<string>;\n\n/** Read only after the policy and its organization-directory binding verify. */\nexport async function readGroupPolicyPayloadName(\n bundle: GroupPolicyNameInput,\n readEncryptedName?: GroupPolicyNameReader,\n): Promise<string> {\n const metadata = readGroupMetadata(bundle.currentPayload.ciphertext);\n if (\"role\" in metadata)\n return metadata.role === \"admins\" ? \"Admins\" : \"Members\";\n if (!readEncryptedName)\n throw new Error(\"Group metadata decryption context is unavailable\");\n return readEncryptedName(bundle);\n}\n\n/** One binding predicate for every operation selected by a read-model label. */\nexport async function groupPolicyNameMismatch(\n bundle: GroupPolicyNameInput,\n expectedGroupName: string,\n readEncryptedName?: GroupPolicyNameReader,\n): Promise<\"forbidden_characters\" | \"name_mismatch\" | null> {\n if (hasForbiddenGroupNameCharacter(expectedGroupName)) {\n return \"forbidden_characters\";\n }\n const signedName = await readGroupPolicyPayloadName(\n bundle,\n readEncryptedName,\n );\n if (hasForbiddenGroupNameCharacter(signedName)) return \"forbidden_characters\";\n return canonicalGroupNameKey(signedName) ===\n canonicalGroupNameKey(expectedGroupName)\n ? null\n : \"name_mismatch\";\n}\n\nexport async function signedGroupPolicyRequest(input: {\n readonly currentPolicy?: Pick<PrincipalPolicyBundleResponse, \"currentState\">;\n readonly encapsulationPublicKey: string;\n readonly externalAuthority:\n | PrincipalPolicyExternalAuthority[\"currentHead\"]\n | null;\n readonly keyEpoch: number;\n readonly keyFingerprint: string;\n readonly grants: ReadonlyArray<PrincipalContainerGrant>;\n readonly memberEnvelopes: ReadonlyArray<PrincipalMemberEnvelopeRequest>;\n readonly payloadCiphertext: string;\n readonly principalId: string;\n readonly projection: ReadonlyArray<PrincipalProjectionMemberRequest>;\n readonly signedAt: string;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<PutPrincipalPolicyRequest> {\n const projection = normalizePrincipalProjectionMembers(input.projection);\n const grants = normalizePrincipalContainerGrants(input.grants);\n const payloadCiphertext = input.payloadCiphertext;\n const state = await signPrincipalState(\n await buildPrincipalStateSigningInput({\n principalType: \"group\",\n principalId: input.principalId,\n version: input.currentPolicy\n ? input.currentPolicy.currentState.version + 1\n : 1,\n prevStateHash: input.currentPolicy?.currentState.stateHash ?? null,\n keyEpoch: input.keyEpoch,\n encapsulationPublicKey: input.encapsulationPublicKey,\n keyFingerprint: input.keyFingerprint,\n members: projectionToStateMembers(projection),\n memberEnvelopes: [...input.memberEnvelopes],\n projection,\n grants,\n payloadCiphertext,\n externalAuthority: input.externalAuthority,\n signedAt: input.signedAt,\n signerUserId: input.signerUserId,\n signerUserKeyFingerprint: input.signingFingerprint,\n }),\n input.signingKeyPair.signingPrivateKey,\n );\n\n return {\n state,\n encryptedPayload: {\n ciphertext: payloadCiphertext,\n },\n projection,\n grants,\n memberEnvelopes: [...input.memberEnvelopes],\n };\n}\n\nexport async function buildInitialGroupPolicyRequest(\n input: BuildInitialGroupPolicyInput,\n): Promise<CreateOrganizationGroupRequest> {\n const groupKem = generateKemSeedAndKeyPair();\n const withSigner = input.includeSignerAsAdmin ?? true;\n const projection = withSigner\n ? [\n await createPrincipalProjectionMember(\n {\n userId: input.signerUserId,\n identityTrustDomain: input.identityTrustDomain,\n signingPublicKey: input.signingKeyPair.signingPublicKey,\n encapsulationPublicKey: input.creatorEncapsulationKeyPair.publicKey,\n },\n \"admin\",\n ),\n ]\n : [];\n const memberEnvelopes: PrincipalMemberEnvelopeRequest[] = [];\n\n if (withSigner) {\n const creatorFingerprint = await toFingerprint(\n input.creatorEncapsulationKeyPair.publicKey,\n );\n const [creatorEnvelope] = await wrapDekForRecipients(groupKem.secretKey, [\n input.creatorEncapsulationKeyPair.publicKey,\n ]);\n\n if (!creatorEnvelope) {\n throw new Error(\"Failed to wrap group key for creator\");\n }\n\n memberEnvelopes.push({\n userId: input.signerUserId,\n memberKeyFingerprint: creatorFingerprint,\n kemCipherText: bytesToBase64(creatorEnvelope.kemCipherText),\n wrappedKey: bytesToBase64(creatorEnvelope.wrappedKey),\n });\n }\n const name = input.name.trim();\n // A name is compared by canonical key but displayed raw, so an invisible\n // code point would let one signed name render as another. Refuse them\n // where the name is signed.\n if (name.length === 0 || hasForbiddenGroupNameCharacter(name)) {\n throw new Error(\n \"Group names must be non-empty and contain no control, format, or surrogate characters\",\n );\n }\n const payloadCiphertext = input.builtinRole\n ? encodeBuiltinGroupMetadata(input.builtinRole)\n : input.metadataKey\n ? await encryptGroupMetadata({\n key: input.metadataKey,\n groupId: input.groupId,\n name,\n })\n : (() => {\n throw new Error(\"Group metadata encryption context is unavailable\");\n })();\n const policyRequest = await signedGroupPolicyRequest({\n encapsulationPublicKey: bytesToBase64(groupKem.publicKey),\n externalAuthority: input.externalAuthority ?? null,\n keyEpoch: 1,\n keyFingerprint: await toFingerprint(groupKem.publicKey),\n grants: input.grants ?? [],\n memberEnvelopes,\n payloadCiphertext,\n principalId: input.groupId,\n projection,\n signedAt: new Date().toISOString(),\n signerUserId: input.signerUserId,\n signingFingerprint: input.signingFingerprint,\n signingKeyPair: input.signingKeyPair,\n });\n\n return {\n groupId: input.groupId,\n initialGroupPolicy: policyRequest,\n };\n}\n\n/**\n * Members at bootstrap holds the registering user alone.\n *\n * It used to also contain the Admins group as a nested member, so that admins\n * were implicitly members. Principals contain only users now, so an admin is an\n * ordinary Members entry — and bootstrap has exactly one user, who is that\n * admin.\n */\nexport async function buildInitialMemberGroupPolicyRequest(input: {\n readonly identityTrustDomain: string;\n readonly creatorEncapsulationKeyPair: EncapsulationKeyPair;\n readonly groupId: string;\n readonly grants?: readonly PrincipalContainerGrant[] | undefined;\n readonly signerUserId: string;\n readonly signingFingerprint: string;\n readonly signingKeyPair: SigningKeyPair;\n}): Promise<CreateOrganizationGroupRequest> {\n return buildInitialGroupPolicyRequest({\n ...input,\n name: \"Members\",\n builtinRole: \"members\",\n });\n}\n"]}
|
|
@@ -300,13 +300,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
300
300
|
stateHash: string;
|
|
301
301
|
};
|
|
302
302
|
currentPayload: {
|
|
303
|
-
cipherSuite: "aes-256-gcm";
|
|
304
303
|
ciphertext: string;
|
|
305
|
-
ciphertextHash: string;
|
|
306
|
-
createdAt: string;
|
|
307
|
-
principalId: string;
|
|
308
|
-
principalType: "group" | "organization";
|
|
309
|
-
stateHash: string;
|
|
310
304
|
};
|
|
311
305
|
currentProjection: {
|
|
312
306
|
identityBundleFingerprint: string;
|
|
@@ -409,13 +403,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
409
403
|
stateHash: string;
|
|
410
404
|
};
|
|
411
405
|
currentPayload: {
|
|
412
|
-
cipherSuite: "aes-256-gcm";
|
|
413
406
|
ciphertext: string;
|
|
414
|
-
ciphertextHash: string;
|
|
415
|
-
createdAt: string;
|
|
416
|
-
principalId: string;
|
|
417
|
-
principalType: "group" | "organization";
|
|
418
|
-
stateHash: string;
|
|
419
407
|
};
|
|
420
408
|
currentProjection: {
|
|
421
409
|
identityBundleFingerprint: string;
|
|
@@ -536,13 +524,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
536
524
|
stateHash: string;
|
|
537
525
|
};
|
|
538
526
|
currentPayload: {
|
|
539
|
-
cipherSuite: "aes-256-gcm";
|
|
540
527
|
ciphertext: string;
|
|
541
|
-
ciphertextHash: string;
|
|
542
|
-
createdAt: string;
|
|
543
|
-
principalId: string;
|
|
544
|
-
principalType: "group" | "organization";
|
|
545
|
-
stateHash: string;
|
|
546
528
|
};
|
|
547
529
|
currentProjection: {
|
|
548
530
|
identityBundleFingerprint: string;
|
|
@@ -583,9 +565,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
583
565
|
} | null>;
|
|
584
566
|
putPrincipalPolicy: (principalType: "organization", principalId: string, input: {
|
|
585
567
|
encryptedPayload: {
|
|
586
|
-
cipherSuite: "aes-256-gcm";
|
|
587
568
|
ciphertext: string;
|
|
588
|
-
ciphertextHash: string;
|
|
589
569
|
};
|
|
590
570
|
grants: {
|
|
591
571
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -707,9 +687,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
707
687
|
} | null>;
|
|
708
688
|
putPrincipalPolicyResult: (principalType: "organization", principalId: string, input: {
|
|
709
689
|
encryptedPayload: {
|
|
710
|
-
cipherSuite: "aes-256-gcm";
|
|
711
690
|
ciphertext: string;
|
|
712
|
-
ciphertextHash: string;
|
|
713
691
|
};
|
|
714
692
|
grants: {
|
|
715
693
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -936,9 +914,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
936
914
|
createOrganizationGroup: (organizationId: string, input: {
|
|
937
915
|
organizationPolicy: {
|
|
938
916
|
encryptedPayload: {
|
|
939
|
-
cipherSuite: "aes-256-gcm";
|
|
940
917
|
ciphertext: string;
|
|
941
|
-
ciphertextHash: string;
|
|
942
918
|
};
|
|
943
919
|
grants: {
|
|
944
920
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -1029,9 +1005,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
1029
1005
|
groupId: string;
|
|
1030
1006
|
initialGroupPolicy: {
|
|
1031
1007
|
encryptedPayload: {
|
|
1032
|
-
cipherSuite: "aes-256-gcm";
|
|
1033
1008
|
ciphertext: string;
|
|
1034
|
-
ciphertextHash: string;
|
|
1035
1009
|
};
|
|
1036
1010
|
grants: {
|
|
1037
1011
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -1171,9 +1145,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
1171
1145
|
createOrganizationGroupResult: (organizationId: string, input: {
|
|
1172
1146
|
organizationPolicy: {
|
|
1173
1147
|
encryptedPayload: {
|
|
1174
|
-
cipherSuite: "aes-256-gcm";
|
|
1175
1148
|
ciphertext: string;
|
|
1176
|
-
ciphertextHash: string;
|
|
1177
1149
|
};
|
|
1178
1150
|
grants: {
|
|
1179
1151
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -1264,9 +1236,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
1264
1236
|
groupId: string;
|
|
1265
1237
|
initialGroupPolicy: {
|
|
1266
1238
|
encryptedPayload: {
|
|
1267
|
-
cipherSuite: "aes-256-gcm";
|
|
1268
1239
|
ciphertext: string;
|
|
1269
|
-
ciphertextHash: string;
|
|
1270
1240
|
};
|
|
1271
1241
|
grants: {
|
|
1272
1242
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -1406,9 +1376,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
1406
1376
|
deleteOrganizationGroup: (organizationId: string, groupId: string, input: {
|
|
1407
1377
|
organizationPolicy: {
|
|
1408
1378
|
encryptedPayload: {
|
|
1409
|
-
cipherSuite: "aes-256-gcm";
|
|
1410
1379
|
ciphertext: string;
|
|
1411
|
-
ciphertextHash: string;
|
|
1412
1380
|
};
|
|
1413
1381
|
grants: {
|
|
1414
1382
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -1537,9 +1505,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
1537
1505
|
deleteOrganizationGroupResult: (organizationId: string, groupId: string, input: {
|
|
1538
1506
|
organizationPolicy: {
|
|
1539
1507
|
encryptedPayload: {
|
|
1540
|
-
cipherSuite: "aes-256-gcm";
|
|
1541
1508
|
ciphertext: string;
|
|
1542
|
-
ciphertextHash: string;
|
|
1543
1509
|
};
|
|
1544
1510
|
grants: {
|
|
1545
1511
|
accessLevel: "write" | "admin" | "read";
|
|
@@ -2696,13 +2662,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
2696
2662
|
version: number;
|
|
2697
2663
|
};
|
|
2698
2664
|
payload: {
|
|
2699
|
-
cipherSuite: "aes-256-gcm";
|
|
2700
2665
|
ciphertext: string;
|
|
2701
|
-
ciphertextHash: string;
|
|
2702
|
-
createdAt: string;
|
|
2703
|
-
principalId: string;
|
|
2704
|
-
principalType: "group" | "organization";
|
|
2705
|
-
stateHash: string;
|
|
2706
2666
|
};
|
|
2707
2667
|
}[];
|
|
2708
2668
|
groups: {
|
|
@@ -2798,13 +2758,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
2798
2758
|
version: number;
|
|
2799
2759
|
};
|
|
2800
2760
|
payload: {
|
|
2801
|
-
cipherSuite: "aes-256-gcm";
|
|
2802
2761
|
ciphertext: string;
|
|
2803
|
-
ciphertextHash: string;
|
|
2804
|
-
createdAt: string;
|
|
2805
|
-
principalId: string;
|
|
2806
|
-
principalType: "group" | "organization";
|
|
2807
|
-
stateHash: string;
|
|
2808
2762
|
};
|
|
2809
2763
|
}[];
|
|
2810
2764
|
groups: {
|
|
@@ -3014,13 +2968,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
3014
2968
|
version: number;
|
|
3015
2969
|
};
|
|
3016
2970
|
payload: {
|
|
3017
|
-
cipherSuite: "aes-256-gcm";
|
|
3018
2971
|
ciphertext: string;
|
|
3019
|
-
ciphertextHash: string;
|
|
3020
|
-
createdAt: string;
|
|
3021
|
-
principalId: string;
|
|
3022
|
-
principalType: "group" | "organization";
|
|
3023
|
-
stateHash: string;
|
|
3024
2972
|
};
|
|
3025
2973
|
}[];
|
|
3026
2974
|
groups: {
|
|
@@ -3102,13 +3050,7 @@ export declare class ApiClient extends ApiClientAreas {
|
|
|
3102
3050
|
version: number;
|
|
3103
3051
|
};
|
|
3104
3052
|
payload: {
|
|
3105
|
-
cipherSuite: "aes-256-gcm";
|
|
3106
3053
|
ciphertext: string;
|
|
3107
|
-
ciphertextHash: string;
|
|
3108
|
-
createdAt: string;
|
|
3109
|
-
principalId: string;
|
|
3110
|
-
principalType: "group" | "organization";
|
|
3111
|
-
stateHash: string;
|
|
3112
3054
|
};
|
|
3113
3055
|
}[];
|
|
3114
3056
|
groups: {
|
|
@@ -135,13 +135,7 @@ export declare class ApiClientContext {
|
|
|
135
135
|
version: number;
|
|
136
136
|
};
|
|
137
137
|
payload: {
|
|
138
|
-
cipherSuite: "aes-256-gcm";
|
|
139
138
|
ciphertext: string;
|
|
140
|
-
ciphertextHash: string;
|
|
141
|
-
createdAt: string;
|
|
142
|
-
principalId: string;
|
|
143
|
-
principalType: "group" | "organization";
|
|
144
|
-
stateHash: string;
|
|
145
139
|
};
|
|
146
140
|
}[];
|
|
147
141
|
groups: {
|
|
@@ -222,13 +216,7 @@ export declare class ApiClientContext {
|
|
|
222
216
|
version: number;
|
|
223
217
|
};
|
|
224
218
|
payload: {
|
|
225
|
-
cipherSuite: "aes-256-gcm";
|
|
226
219
|
ciphertext: string;
|
|
227
|
-
ciphertextHash: string;
|
|
228
|
-
createdAt: string;
|
|
229
|
-
principalId: string;
|
|
230
|
-
principalType: "group" | "organization";
|
|
231
|
-
stateHash: string;
|
|
232
220
|
};
|
|
233
221
|
}[];
|
|
234
222
|
groups: {
|
|
@@ -375,13 +363,7 @@ export declare class ApiClientContext {
|
|
|
375
363
|
version: number;
|
|
376
364
|
};
|
|
377
365
|
payload: {
|
|
378
|
-
cipherSuite: "aes-256-gcm";
|
|
379
366
|
ciphertext: string;
|
|
380
|
-
ciphertextHash: string;
|
|
381
|
-
createdAt: string;
|
|
382
|
-
principalId: string;
|
|
383
|
-
principalType: "group" | "organization";
|
|
384
|
-
stateHash: string;
|
|
385
367
|
};
|
|
386
368
|
}[];
|
|
387
369
|
groups: {
|
|
@@ -462,13 +444,7 @@ export declare class ApiClientContext {
|
|
|
462
444
|
version: number;
|
|
463
445
|
};
|
|
464
446
|
payload: {
|
|
465
|
-
cipherSuite: "aes-256-gcm";
|
|
466
447
|
ciphertext: string;
|
|
467
|
-
ciphertextHash: string;
|
|
468
|
-
createdAt: string;
|
|
469
|
-
principalId: string;
|
|
470
|
-
principalType: "group" | "organization";
|
|
471
|
-
stateHash: string;
|
|
472
448
|
};
|
|
473
449
|
}[];
|
|
474
450
|
groups: {
|
|
@@ -710,13 +686,7 @@ export declare class ApiClientContext {
|
|
|
710
686
|
stateHash: string;
|
|
711
687
|
};
|
|
712
688
|
currentPayload: {
|
|
713
|
-
cipherSuite: "aes-256-gcm";
|
|
714
689
|
ciphertext: string;
|
|
715
|
-
ciphertextHash: string;
|
|
716
|
-
createdAt: string;
|
|
717
|
-
principalId: string;
|
|
718
|
-
principalType: "group" | "organization";
|
|
719
|
-
stateHash: string;
|
|
720
690
|
};
|
|
721
691
|
currentProjection: {
|
|
722
692
|
identityBundleFingerprint: string;
|
|
@@ -174,13 +174,7 @@ export declare class DocumentArea {
|
|
|
174
174
|
version: number;
|
|
175
175
|
};
|
|
176
176
|
payload: {
|
|
177
|
-
cipherSuite: "aes-256-gcm";
|
|
178
177
|
ciphertext: string;
|
|
179
|
-
ciphertextHash: string;
|
|
180
|
-
createdAt: string;
|
|
181
|
-
principalId: string;
|
|
182
|
-
principalType: "group" | "organization";
|
|
183
|
-
stateHash: string;
|
|
184
178
|
};
|
|
185
179
|
}[];
|
|
186
180
|
groups: {
|
|
@@ -276,13 +270,7 @@ export declare class DocumentArea {
|
|
|
276
270
|
version: number;
|
|
277
271
|
};
|
|
278
272
|
payload: {
|
|
279
|
-
cipherSuite: "aes-256-gcm";
|
|
280
273
|
ciphertext: string;
|
|
281
|
-
ciphertextHash: string;
|
|
282
|
-
createdAt: string;
|
|
283
|
-
principalId: string;
|
|
284
|
-
principalType: "group" | "organization";
|
|
285
|
-
stateHash: string;
|
|
286
274
|
};
|
|
287
275
|
}[];
|
|
288
276
|
groups: {
|