@tokensrc/codex 1.13.4 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -3
- package/dist/client.d.ts +29 -1
- package/dist/client.js +221 -2
- package/dist/client.js.map +1 -1
- package/dist/command-directory.d.ts +1 -0
- package/dist/command-directory.js +3 -2
- package/dist/command-directory.js.map +1 -1
- package/dist/commands.d.ts +8 -2
- package/dist/commands.js +567 -40
- package/dist/commands.js.map +1 -1
- package/dist/console-status.js +1 -1
- package/dist/console-status.js.map +1 -1
- package/dist/credential-supervisor.d.ts +17 -0
- package/dist/credential-supervisor.js +84 -0
- package/dist/credential-supervisor.js.map +1 -0
- package/dist/credentials.d.ts +75 -3
- package/dist/credentials.js +357 -12
- package/dist/credentials.js.map +1 -1
- package/dist/enrollment-envelope.d.ts +18 -0
- package/dist/enrollment-envelope.js +112 -0
- package/dist/enrollment-envelope.js.map +1 -0
- package/dist/enrollment-flow.d.ts +27 -0
- package/dist/enrollment-flow.js +224 -0
- package/dist/enrollment-flow.js.map +1 -0
- package/dist/enrollment-login.d.ts +26 -0
- package/dist/enrollment-login.js +104 -0
- package/dist/enrollment-login.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/managed-credential-v3-envelope.d.ts +60 -0
- package/dist/managed-credential-v3-envelope.js +234 -0
- package/dist/managed-credential-v3-envelope.js.map +1 -0
- package/dist/managed-credential-v3-flow.d.ts +45 -0
- package/dist/managed-credential-v3-flow.js +499 -0
- package/dist/managed-credential-v3-flow.js.map +1 -0
- package/dist/managed-credential-v3-journal.d.ts +192 -0
- package/dist/managed-credential-v3-journal.js +153 -0
- package/dist/managed-credential-v3-journal.js.map +1 -0
- package/dist/managed-credential-v3.d.ts +117 -0
- package/dist/managed-credential-v3.js +423 -0
- package/dist/managed-credential-v3.js.map +1 -0
- package/dist/migration-login-batch.d.ts +66 -0
- package/dist/migration-login-batch.js +202 -0
- package/dist/migration-login-batch.js.map +1 -0
- package/dist/private-file.d.ts +10 -0
- package/dist/private-file.js +77 -2
- package/dist/private-file.js.map +1 -1
- package/dist/profile.d.ts +10 -0
- package/dist/profile.js +55 -2
- package/dist/profile.js.map +1 -1
- package/dist/protocol.d.ts +1070 -0
- package/dist/protocol.js +560 -0
- package/dist/protocol.js.map +1 -1
- package/dist/retirement-flow.d.ts +38 -0
- package/dist/retirement-flow.js +78 -0
- package/dist/retirement-flow.js.map +1 -0
- package/dist/runtime.d.ts +4 -1
- package/dist/runtime.js +29 -4
- package/dist/runtime.js.map +1 -1
- package/dist/selection.d.ts +10 -1
- package/dist/selection.js +38 -2
- package/dist/selection.js.map +1 -1
- package/dist/short-lived-delivery-flow.d.ts +41 -0
- package/dist/short-lived-delivery-flow.js +141 -0
- package/dist/short-lived-delivery-flow.js.map +1 -0
- package/dist/short-lived-delivery-journal.d.ts +34 -0
- package/dist/short-lived-delivery-journal.js +137 -0
- package/dist/short-lived-delivery-journal.js.map +1 -0
- package/dist/short-lived-delivery.d.ts +26 -0
- package/dist/short-lived-delivery.js +139 -0
- package/dist/short-lived-delivery.js.map +1 -0
- package/dist/tui.js +23 -0
- package/dist/tui.js.map +1 -1
- package/dist/types.d.ts +6 -2
- package/package.json +2 -2
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const EnrollmentJournalSchema: z.ZodObject<{
|
|
4
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
5
|
+
tenantId: z.ZodString;
|
|
6
|
+
subject: z.ZodString;
|
|
7
|
+
clientRequestId: z.ZodString;
|
|
8
|
+
idempotencyKey: z.ZodString;
|
|
9
|
+
createdAt: z.ZodString;
|
|
10
|
+
updatedAt: z.ZodString;
|
|
11
|
+
kind: z.ZodLiteral<"ENROLLMENT">;
|
|
12
|
+
providerAccountId: z.ZodString;
|
|
13
|
+
envelope: z.ZodObject<{
|
|
14
|
+
version: z.ZodLiteral<1>;
|
|
15
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
16
|
+
keyId: z.ZodString;
|
|
17
|
+
ephemeralPublicKey: z.ZodString;
|
|
18
|
+
salt: z.ZodString;
|
|
19
|
+
nonce: z.ZodString;
|
|
20
|
+
ciphertext: z.ZodString;
|
|
21
|
+
authenticationTag: z.ZodString;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
declare const DeliveryJournalSchema: z.ZodObject<{
|
|
25
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
26
|
+
tenantId: z.ZodString;
|
|
27
|
+
subject: z.ZodString;
|
|
28
|
+
clientRequestId: z.ZodString;
|
|
29
|
+
idempotencyKey: z.ZodString;
|
|
30
|
+
createdAt: z.ZodString;
|
|
31
|
+
updatedAt: z.ZodString;
|
|
32
|
+
kind: z.ZodLiteral<"DELIVERY">;
|
|
33
|
+
enrollmentId: z.ZodString;
|
|
34
|
+
assignmentId: z.ZodString;
|
|
35
|
+
managedAccountId: z.ZodString;
|
|
36
|
+
providerAccountId: z.ZodString;
|
|
37
|
+
lineageId: z.ZodString;
|
|
38
|
+
generationVersion: z.ZodNumber;
|
|
39
|
+
clientKey: z.ZodObject<{
|
|
40
|
+
version: z.ZodLiteral<1>;
|
|
41
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
42
|
+
publicKey: z.ZodString;
|
|
43
|
+
}, z.core.$strict>;
|
|
44
|
+
privateKeyPkcs8: z.ZodString;
|
|
45
|
+
ackIdempotencyKey: z.ZodString;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
declare const ReportJournalSchema: z.ZodObject<{
|
|
48
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
49
|
+
tenantId: z.ZodString;
|
|
50
|
+
subject: z.ZodString;
|
|
51
|
+
clientRequestId: z.ZodString;
|
|
52
|
+
idempotencyKey: z.ZodString;
|
|
53
|
+
createdAt: z.ZodString;
|
|
54
|
+
updatedAt: z.ZodString;
|
|
55
|
+
kind: z.ZodLiteral<"REPORT">;
|
|
56
|
+
lineageId: z.ZodString;
|
|
57
|
+
expectedGenerationVersion: z.ZodNumber;
|
|
58
|
+
rotationMode: z.ZodEnum<{
|
|
59
|
+
RETAINED: "RETAINED";
|
|
60
|
+
ROTATED: "ROTATED";
|
|
61
|
+
}>;
|
|
62
|
+
envelope: z.ZodObject<{
|
|
63
|
+
version: z.ZodLiteral<1>;
|
|
64
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
65
|
+
keyId: z.ZodString;
|
|
66
|
+
ephemeralPublicKey: z.ZodString;
|
|
67
|
+
salt: z.ZodString;
|
|
68
|
+
nonce: z.ZodString;
|
|
69
|
+
ciphertext: z.ZodString;
|
|
70
|
+
authenticationTag: z.ZodString;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
accessTokenHealth: z.ZodEnum<{
|
|
73
|
+
EXPIRED: "EXPIRED";
|
|
74
|
+
HEALTHY: "HEALTHY";
|
|
75
|
+
REJECTED: "REJECTED";
|
|
76
|
+
UNKNOWN: "UNKNOWN";
|
|
77
|
+
}>;
|
|
78
|
+
refreshTokenHealth: z.ZodEnum<{
|
|
79
|
+
HEALTHY: "HEALTHY";
|
|
80
|
+
REJECTED: "REJECTED";
|
|
81
|
+
UNKNOWN: "UNKNOWN";
|
|
82
|
+
}>;
|
|
83
|
+
observedAt: z.ZodString;
|
|
84
|
+
credentialExpiresAt: z.ZodString;
|
|
85
|
+
accessTokenDigest: z.ZodString;
|
|
86
|
+
refreshTokenDigest: z.ZodString;
|
|
87
|
+
idTokenDigest: z.ZodString;
|
|
88
|
+
}, z.core.$strict>;
|
|
89
|
+
declare const JournalSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
90
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
91
|
+
tenantId: z.ZodString;
|
|
92
|
+
subject: z.ZodString;
|
|
93
|
+
clientRequestId: z.ZodString;
|
|
94
|
+
idempotencyKey: z.ZodString;
|
|
95
|
+
createdAt: z.ZodString;
|
|
96
|
+
updatedAt: z.ZodString;
|
|
97
|
+
kind: z.ZodLiteral<"ENROLLMENT">;
|
|
98
|
+
providerAccountId: z.ZodString;
|
|
99
|
+
envelope: z.ZodObject<{
|
|
100
|
+
version: z.ZodLiteral<1>;
|
|
101
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
102
|
+
keyId: z.ZodString;
|
|
103
|
+
ephemeralPublicKey: z.ZodString;
|
|
104
|
+
salt: z.ZodString;
|
|
105
|
+
nonce: z.ZodString;
|
|
106
|
+
ciphertext: z.ZodString;
|
|
107
|
+
authenticationTag: z.ZodString;
|
|
108
|
+
}, z.core.$strict>;
|
|
109
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
110
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
111
|
+
tenantId: z.ZodString;
|
|
112
|
+
subject: z.ZodString;
|
|
113
|
+
clientRequestId: z.ZodString;
|
|
114
|
+
idempotencyKey: z.ZodString;
|
|
115
|
+
createdAt: z.ZodString;
|
|
116
|
+
updatedAt: z.ZodString;
|
|
117
|
+
kind: z.ZodLiteral<"DELIVERY">;
|
|
118
|
+
enrollmentId: z.ZodString;
|
|
119
|
+
assignmentId: z.ZodString;
|
|
120
|
+
managedAccountId: z.ZodString;
|
|
121
|
+
providerAccountId: z.ZodString;
|
|
122
|
+
lineageId: z.ZodString;
|
|
123
|
+
generationVersion: z.ZodNumber;
|
|
124
|
+
clientKey: z.ZodObject<{
|
|
125
|
+
version: z.ZodLiteral<1>;
|
|
126
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
127
|
+
publicKey: z.ZodString;
|
|
128
|
+
}, z.core.$strict>;
|
|
129
|
+
privateKeyPkcs8: z.ZodString;
|
|
130
|
+
ackIdempotencyKey: z.ZodString;
|
|
131
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
132
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
133
|
+
tenantId: z.ZodString;
|
|
134
|
+
subject: z.ZodString;
|
|
135
|
+
clientRequestId: z.ZodString;
|
|
136
|
+
idempotencyKey: z.ZodString;
|
|
137
|
+
createdAt: z.ZodString;
|
|
138
|
+
updatedAt: z.ZodString;
|
|
139
|
+
kind: z.ZodLiteral<"REPORT">;
|
|
140
|
+
lineageId: z.ZodString;
|
|
141
|
+
expectedGenerationVersion: z.ZodNumber;
|
|
142
|
+
rotationMode: z.ZodEnum<{
|
|
143
|
+
RETAINED: "RETAINED";
|
|
144
|
+
ROTATED: "ROTATED";
|
|
145
|
+
}>;
|
|
146
|
+
envelope: z.ZodObject<{
|
|
147
|
+
version: z.ZodLiteral<1>;
|
|
148
|
+
algorithm: z.ZodLiteral<"X25519-HKDF-SHA256-AES-256-GCM">;
|
|
149
|
+
keyId: z.ZodString;
|
|
150
|
+
ephemeralPublicKey: z.ZodString;
|
|
151
|
+
salt: z.ZodString;
|
|
152
|
+
nonce: z.ZodString;
|
|
153
|
+
ciphertext: z.ZodString;
|
|
154
|
+
authenticationTag: z.ZodString;
|
|
155
|
+
}, z.core.$strict>;
|
|
156
|
+
accessTokenHealth: z.ZodEnum<{
|
|
157
|
+
EXPIRED: "EXPIRED";
|
|
158
|
+
HEALTHY: "HEALTHY";
|
|
159
|
+
REJECTED: "REJECTED";
|
|
160
|
+
UNKNOWN: "UNKNOWN";
|
|
161
|
+
}>;
|
|
162
|
+
refreshTokenHealth: z.ZodEnum<{
|
|
163
|
+
HEALTHY: "HEALTHY";
|
|
164
|
+
REJECTED: "REJECTED";
|
|
165
|
+
UNKNOWN: "UNKNOWN";
|
|
166
|
+
}>;
|
|
167
|
+
observedAt: z.ZodString;
|
|
168
|
+
credentialExpiresAt: z.ZodString;
|
|
169
|
+
accessTokenDigest: z.ZodString;
|
|
170
|
+
refreshTokenDigest: z.ZodString;
|
|
171
|
+
idTokenDigest: z.ZodString;
|
|
172
|
+
}, z.core.$strict>], "kind">;
|
|
173
|
+
export type ManagedCodexV3OperationJournal = z.infer<typeof JournalSchema>;
|
|
174
|
+
export type ManagedCodexV3EnrollmentJournal = z.infer<typeof EnrollmentJournalSchema>;
|
|
175
|
+
export type ManagedCodexV3DeliveryJournal = z.infer<typeof DeliveryJournalSchema>;
|
|
176
|
+
export type ManagedCodexV3ReportJournal = z.infer<typeof ReportJournalSchema>;
|
|
177
|
+
export declare function readManagedCodexV3OperationJournal(env?: NodeJS.ProcessEnv): Promise<ManagedCodexV3OperationJournal | undefined>;
|
|
178
|
+
export declare function writeManagedCodexV3OperationJournal(value: ManagedCodexV3OperationJournal, env?: NodeJS.ProcessEnv): Promise<ManagedCodexV3OperationJournal>;
|
|
179
|
+
export declare function replaceManagedCodexV3OperationWithDelivery(input: {
|
|
180
|
+
previous: ManagedCodexV3EnrollmentJournal;
|
|
181
|
+
delivery: Omit<ManagedCodexV3DeliveryJournal, "schemaVersion" | "kind" | "createdAt" | "updatedAt" | "privateKeyPkcs8">;
|
|
182
|
+
privateKey: KeyObject;
|
|
183
|
+
now: number;
|
|
184
|
+
env?: NodeJS.ProcessEnv;
|
|
185
|
+
}): Promise<ManagedCodexV3DeliveryJournal>;
|
|
186
|
+
export declare function openManagedCodexV3DeliveryJournalKey(journal: ManagedCodexV3DeliveryJournal): KeyObject;
|
|
187
|
+
export declare function clearManagedCodexV3OperationJournal(expected: {
|
|
188
|
+
kind: ManagedCodexV3OperationJournal["kind"];
|
|
189
|
+
clientRequestId: string;
|
|
190
|
+
idempotencyKey: string;
|
|
191
|
+
}, env?: NodeJS.ProcessEnv): Promise<void>;
|
|
192
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createPrivateKey } from "node:crypto";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { CodexShortLivedDeliveryClientKeySchema, CodexV3AccessTokenHealthSchema, CodexV3CredentialEnvelopeSchema, CodexV3RefreshTokenHealthSchema } from "./protocol.js";
|
|
6
|
+
import { readJsonIfExists, removePrivateFileDurably, withPrivateFileLock, writePrivateJson } from "./private-file.js";
|
|
7
|
+
const Instant = z.string().datetime({ offset: true });
|
|
8
|
+
const Id = z.string().min(1).max(512);
|
|
9
|
+
const Stable = z.string().min(8).max(255);
|
|
10
|
+
const Digest = z.string().length(64).regex(/^[0-9a-f]{64}$/);
|
|
11
|
+
const Base = {
|
|
12
|
+
schemaVersion: z.literal(3),
|
|
13
|
+
tenantId: Id,
|
|
14
|
+
subject: Id,
|
|
15
|
+
clientRequestId: Stable,
|
|
16
|
+
idempotencyKey: Stable,
|
|
17
|
+
createdAt: Instant,
|
|
18
|
+
updatedAt: Instant
|
|
19
|
+
};
|
|
20
|
+
const EnrollmentJournalSchema = z.strictObject({
|
|
21
|
+
...Base,
|
|
22
|
+
kind: z.literal("ENROLLMENT"),
|
|
23
|
+
providerAccountId: Id,
|
|
24
|
+
envelope: CodexV3CredentialEnvelopeSchema
|
|
25
|
+
});
|
|
26
|
+
const DeliveryJournalSchema = z.strictObject({
|
|
27
|
+
...Base,
|
|
28
|
+
kind: z.literal("DELIVERY"),
|
|
29
|
+
enrollmentId: Id,
|
|
30
|
+
assignmentId: Id,
|
|
31
|
+
managedAccountId: Id,
|
|
32
|
+
providerAccountId: Id,
|
|
33
|
+
lineageId: Id,
|
|
34
|
+
generationVersion: z.number().int().positive(),
|
|
35
|
+
clientKey: CodexShortLivedDeliveryClientKeySchema,
|
|
36
|
+
privateKeyPkcs8: z.string().min(1).max(512).regex(/^[A-Za-z0-9_-]+$/),
|
|
37
|
+
ackIdempotencyKey: Stable
|
|
38
|
+
});
|
|
39
|
+
const ReportJournalSchema = z.strictObject({
|
|
40
|
+
...Base,
|
|
41
|
+
kind: z.literal("REPORT"),
|
|
42
|
+
lineageId: Id,
|
|
43
|
+
expectedGenerationVersion: z.number().int().positive(),
|
|
44
|
+
rotationMode: z.enum(["ROTATED", "RETAINED"]),
|
|
45
|
+
envelope: CodexV3CredentialEnvelopeSchema,
|
|
46
|
+
accessTokenHealth: CodexV3AccessTokenHealthSchema,
|
|
47
|
+
refreshTokenHealth: CodexV3RefreshTokenHealthSchema,
|
|
48
|
+
observedAt: Instant,
|
|
49
|
+
credentialExpiresAt: Instant,
|
|
50
|
+
accessTokenDigest: Digest,
|
|
51
|
+
refreshTokenDigest: Digest,
|
|
52
|
+
idTokenDigest: Digest
|
|
53
|
+
});
|
|
54
|
+
const JournalSchema = z.discriminatedUnion("kind", [
|
|
55
|
+
EnrollmentJournalSchema,
|
|
56
|
+
DeliveryJournalSchema,
|
|
57
|
+
ReportJournalSchema
|
|
58
|
+
]);
|
|
59
|
+
function path(env) {
|
|
60
|
+
return join(env.CODEX_HOME?.trim() || join(homedir(), ".codex"), ".numa-managed-credential-v3-operation.json");
|
|
61
|
+
}
|
|
62
|
+
export async function readManagedCodexV3OperationJournal(env = process.env) {
|
|
63
|
+
const raw = await readJsonIfExists(path(env));
|
|
64
|
+
if (raw === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
const parsed = JournalSchema.safeParse(raw);
|
|
67
|
+
if (!parsed.success)
|
|
68
|
+
throw Object.assign(new Error("The private v3 credential operation journal is invalid."), {
|
|
69
|
+
code: "managed_codex_v3_journal_invalid"
|
|
70
|
+
});
|
|
71
|
+
return parsed.data;
|
|
72
|
+
}
|
|
73
|
+
export async function writeManagedCodexV3OperationJournal(value, env = process.env) {
|
|
74
|
+
const target = path(env);
|
|
75
|
+
return withPrivateFileLock(target, async () => {
|
|
76
|
+
const parsed = JournalSchema.parse(value);
|
|
77
|
+
const current = await readManagedCodexV3OperationJournal(env);
|
|
78
|
+
if (current) {
|
|
79
|
+
if (JSON.stringify(current) === JSON.stringify(parsed))
|
|
80
|
+
return current;
|
|
81
|
+
throw Object.assign(new Error("Another v3 credential operation is already pending."), {
|
|
82
|
+
code: "managed_codex_v3_state_conflict"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
await writePrivateJson(target, parsed);
|
|
86
|
+
return parsed;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export async function replaceManagedCodexV3OperationWithDelivery(input) {
|
|
90
|
+
const env = input.env ?? process.env;
|
|
91
|
+
const target = path(env);
|
|
92
|
+
return withPrivateFileLock(target, async () => {
|
|
93
|
+
const current = await readManagedCodexV3OperationJournal(env);
|
|
94
|
+
if (!current || current.kind !== "ENROLLMENT"
|
|
95
|
+
|| current.clientRequestId !== input.previous.clientRequestId
|
|
96
|
+
|| current.idempotencyKey !== input.previous.idempotencyKey) {
|
|
97
|
+
throw Object.assign(new Error("The v3 operation journal changed before delivery."), {
|
|
98
|
+
code: "managed_codex_v3_state_conflict"
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (input.privateKey.asymmetricKeyType !== "x25519")
|
|
102
|
+
throw new Error("Invalid v3 delivery private key.");
|
|
103
|
+
const encoded = input.privateKey.export({ format: "der", type: "pkcs8" });
|
|
104
|
+
if (!Buffer.isBuffer(encoded))
|
|
105
|
+
throw new Error("Unable to export v3 delivery private key.");
|
|
106
|
+
try {
|
|
107
|
+
const timestamp = new Date(input.now).toISOString();
|
|
108
|
+
const value = DeliveryJournalSchema.parse({
|
|
109
|
+
schemaVersion: 3,
|
|
110
|
+
kind: "DELIVERY",
|
|
111
|
+
...input.delivery,
|
|
112
|
+
privateKeyPkcs8: encoded.toString("base64url"),
|
|
113
|
+
createdAt: current.createdAt,
|
|
114
|
+
updatedAt: timestamp
|
|
115
|
+
});
|
|
116
|
+
await writePrivateJson(target, value);
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
encoded.fill(0);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export function openManagedCodexV3DeliveryJournalKey(journal) {
|
|
125
|
+
const encoded = Buffer.from(journal.privateKeyPkcs8, "base64url");
|
|
126
|
+
try {
|
|
127
|
+
if (encoded.toString("base64url") !== journal.privateKeyPkcs8)
|
|
128
|
+
throw new Error("non-canonical key");
|
|
129
|
+
const key = createPrivateKey({ key: encoded, format: "der", type: "pkcs8" });
|
|
130
|
+
if (key.asymmetricKeyType !== "x25519")
|
|
131
|
+
throw new Error("unexpected key type");
|
|
132
|
+
return key;
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
encoded.fill(0);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function clearManagedCodexV3OperationJournal(expected, env = process.env) {
|
|
139
|
+
const target = path(env);
|
|
140
|
+
await withPrivateFileLock(target, async () => {
|
|
141
|
+
const current = await readManagedCodexV3OperationJournal(env);
|
|
142
|
+
if (!current)
|
|
143
|
+
return;
|
|
144
|
+
if (current.kind !== expected.kind || current.clientRequestId !== expected.clientRequestId
|
|
145
|
+
|| current.idempotencyKey !== expected.idempotencyKey) {
|
|
146
|
+
throw Object.assign(new Error("The v3 operation journal changed unexpectedly."), {
|
|
147
|
+
code: "managed_codex_v3_state_conflict"
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
await removePrivateFileDurably(target);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=managed-credential-v3-journal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"managed-credential-v3-journal.js","sourceRoot":"","sources":["../src/managed-credential-v3-journal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAkB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,sCAAsC,EACtC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B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e;eACrF,OAAO,CAAC,cAAc,KAAK,QAAQ,CAAC,cAAc,EAAE,CAAC;YACxD,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,EAAE;gBAC/E,IAAI,EAAE,iCAAiC;aACxC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ManagedCodexV3StateSchema: z.ZodObject<{
|
|
3
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
4
|
+
tenantId: z.ZodString;
|
|
5
|
+
enrollmentId: z.ZodString;
|
|
6
|
+
assignmentId: z.ZodString;
|
|
7
|
+
managedAccountId: z.ZodString;
|
|
8
|
+
providerAccountId: z.ZodString;
|
|
9
|
+
lineageId: z.ZodString;
|
|
10
|
+
generationVersion: z.ZodNumber;
|
|
11
|
+
authorityMode: z.ZodEnum<{
|
|
12
|
+
CLIENT_MANAGED: "CLIENT_MANAGED";
|
|
13
|
+
DELIVERY_PENDING: "DELIVERY_PENDING";
|
|
14
|
+
}>;
|
|
15
|
+
authorityEpoch: z.ZodNullable<z.ZodNumber>;
|
|
16
|
+
deliveryId: z.ZodString;
|
|
17
|
+
ackIdempotencyKey: z.ZodString;
|
|
18
|
+
credentialExpiresAt: z.ZodString;
|
|
19
|
+
ackExpiresAt: z.ZodString;
|
|
20
|
+
ackedAt: z.ZodNullable<z.ZodString>;
|
|
21
|
+
phase: z.ZodEnum<{
|
|
22
|
+
INSTALLED: "INSTALLED";
|
|
23
|
+
INSTALLED_PENDING_ACK: "INSTALLED_PENDING_ACK";
|
|
24
|
+
INSTALLING: "INSTALLING";
|
|
25
|
+
}>;
|
|
26
|
+
accessTokenDigest: z.ZodString;
|
|
27
|
+
refreshTokenDigest: z.ZodString;
|
|
28
|
+
idTokenDigest: z.ZodString;
|
|
29
|
+
updatedAt: z.ZodString;
|
|
30
|
+
lastReportedAt: z.ZodNullable<z.ZodString>;
|
|
31
|
+
previous: z.ZodNullable<z.ZodObject<{
|
|
32
|
+
assignmentId: z.ZodString;
|
|
33
|
+
lineageId: z.ZodString;
|
|
34
|
+
generationVersion: z.ZodNumber;
|
|
35
|
+
authorityEpoch: z.ZodNullable<z.ZodNumber>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type ManagedCodexV3State = z.infer<typeof ManagedCodexV3StateSchema>;
|
|
39
|
+
export interface ManagedCodexV3CredentialInput {
|
|
40
|
+
tenantId: string;
|
|
41
|
+
enrollmentId: string;
|
|
42
|
+
assignmentId: string;
|
|
43
|
+
managedAccountId: string;
|
|
44
|
+
providerAccountId: string;
|
|
45
|
+
lineageId: string;
|
|
46
|
+
generationVersion: number;
|
|
47
|
+
deliveryId: string;
|
|
48
|
+
ackIdempotencyKey: string;
|
|
49
|
+
refreshToken: string;
|
|
50
|
+
accessToken: string;
|
|
51
|
+
idToken: string;
|
|
52
|
+
credentialExpiresAt: string;
|
|
53
|
+
ackExpiresAt: string;
|
|
54
|
+
lastRefresh?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ManagedCodexV3CredentialObservation {
|
|
57
|
+
state: ManagedCodexV3State;
|
|
58
|
+
rotationMode: "ROTATED" | "RETAINED";
|
|
59
|
+
accessTokenHealth: "HEALTHY" | "EXPIRED" | "UNKNOWN";
|
|
60
|
+
refreshTokenHealth: "HEALTHY" | "UNKNOWN";
|
|
61
|
+
observedAt: string;
|
|
62
|
+
credentialExpiresAt: string;
|
|
63
|
+
credentials: {
|
|
64
|
+
refreshToken: string;
|
|
65
|
+
accessToken: string;
|
|
66
|
+
idToken: string;
|
|
67
|
+
providerAccountId: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export declare function readManagedCodexV3State(env?: NodeJS.ProcessEnv): Promise<ManagedCodexV3State | undefined>;
|
|
71
|
+
export declare function managedCodexV3StateExists(env?: NodeJS.ProcessEnv): Promise<boolean>;
|
|
72
|
+
export declare function withCurrentCodexFullCredentials<T>(env: NodeJS.ProcessEnv, consume: (credentials: {
|
|
73
|
+
refreshToken: string;
|
|
74
|
+
accessToken: string;
|
|
75
|
+
idToken: string;
|
|
76
|
+
providerAccountId: string;
|
|
77
|
+
expiresAt: string;
|
|
78
|
+
lastRefresh?: string;
|
|
79
|
+
}) => Promise<T>): Promise<T>;
|
|
80
|
+
export declare function installManagedCodexV3Credentials(raw: ManagedCodexV3CredentialInput, now?: number, env?: NodeJS.ProcessEnv, hooks?: {
|
|
81
|
+
afterInstallingState?: () => Promise<void>;
|
|
82
|
+
afterAuthWrite?: () => Promise<void>;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
action: "INSTALLED" | "REPLACED" | "UNCHANGED" | "RECOVERED";
|
|
85
|
+
authPath: string;
|
|
86
|
+
statePath: string;
|
|
87
|
+
state: ManagedCodexV3State;
|
|
88
|
+
}>;
|
|
89
|
+
export declare function markManagedCodexV3DeliveryAcknowledged(input: {
|
|
90
|
+
deliveryId: string;
|
|
91
|
+
generationVersion: number;
|
|
92
|
+
authorityEpoch: number;
|
|
93
|
+
ackedAt: string;
|
|
94
|
+
}, env?: NodeJS.ProcessEnv): Promise<ManagedCodexV3State>;
|
|
95
|
+
export declare function withManagedCodexV3CredentialObservation<T>(env: NodeJS.ProcessEnv, now: number, consume: (observation: ManagedCodexV3CredentialObservation) => Promise<T>): Promise<T | undefined>;
|
|
96
|
+
export declare function commitManagedCodexV3GenerationReport(input: {
|
|
97
|
+
lineageId: string;
|
|
98
|
+
previousGenerationVersion: number;
|
|
99
|
+
generationVersion: number;
|
|
100
|
+
authorityEpoch: number;
|
|
101
|
+
credentialExpiresAt: string;
|
|
102
|
+
observedAt: string;
|
|
103
|
+
tokenDigests: {
|
|
104
|
+
accessTokenDigest: string;
|
|
105
|
+
refreshTokenDigest: string;
|
|
106
|
+
idTokenDigest: string;
|
|
107
|
+
};
|
|
108
|
+
}, env?: NodeJS.ProcessEnv): Promise<ManagedCodexV3State>;
|
|
109
|
+
export declare function codexV3CredentialDigests(credentials: {
|
|
110
|
+
accessToken: string;
|
|
111
|
+
refreshToken: string;
|
|
112
|
+
idToken: string;
|
|
113
|
+
}): {
|
|
114
|
+
accessTokenDigest: string;
|
|
115
|
+
refreshTokenDigest: string;
|
|
116
|
+
idTokenDigest: string;
|
|
117
|
+
};
|