@yielded/auth-persistence 0.1.0-beta.10
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 +27 -0
- package/dist/Adapter.d.mts +30 -0
- package/dist/Adapter.mjs +25 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +7 -0
- package/dist/internal/PasswordPreparedPostconditions.d.mts +22 -0
- package/dist/internal/PasswordPreparedPostconditions.mjs +12 -0
- package/dist/internal/PasswordPreparedPostconditions.mjs.map +1 -0
- package/dist/internal/configuration.d.mts +174 -0
- package/dist/internal/configuration.mjs +7 -0
- package/dist/internal/configuration.mjs.map +1 -0
- package/dist/internal/email-kernel.d.mts +275 -0
- package/dist/internal/email-kernel.mjs +487 -0
- package/dist/internal/email-kernel.mjs.map +1 -0
- package/dist/internal/mapping-error.d.mts +10 -0
- package/dist/internal/mapping-error.mjs +30 -0
- package/dist/internal/mapping-error.mjs.map +1 -0
- package/dist/internal/models/common.d.mts +12 -0
- package/dist/internal/models/email-model.d.mts +353 -0
- package/dist/internal/models/email-model.mjs +21 -0
- package/dist/internal/models/email-model.mjs.map +1 -0
- package/dist/internal/models/passkey-model.d.mts +266 -0
- package/dist/internal/models/passkey-model.mjs +34 -0
- package/dist/internal/models/passkey-model.mjs.map +1 -0
- package/dist/internal/models/passkey-registration-ceremony-model.d.mts +49 -0
- package/dist/internal/models/passkey-registration-ceremony-model.mjs +18 -0
- package/dist/internal/models/passkey-registration-ceremony-model.mjs.map +1 -0
- package/dist/internal/models/passkey-write-model.d.mts +189 -0
- package/dist/internal/models/passkey-write-model.mjs +13 -0
- package/dist/internal/models/passkey-write-model.mjs.map +1 -0
- package/dist/internal/models/password-model.d.mts +328 -0
- package/dist/internal/models/password-model.mjs +23 -0
- package/dist/internal/models/password-model.mjs.map +1 -0
- package/dist/internal/models/proof-model.d.mts +285 -0
- package/dist/internal/models/proof-model.mjs +17 -0
- package/dist/internal/models/proof-model.mjs.map +1 -0
- package/dist/internal/models/session-model.d.mts +199 -0
- package/dist/internal/models/session-model.mjs +20 -0
- package/dist/internal/models/session-model.mjs.map +1 -0
- package/dist/internal/models/step-up-model.d.mts +66 -0
- package/dist/internal/models/step-up-model.mjs +9 -0
- package/dist/internal/models/step-up-model.mjs.map +1 -0
- package/dist/internal/oauth-app.d.mts +11 -0
- package/dist/internal/oauth-app.mjs +57 -0
- package/dist/internal/oauth-app.mjs.map +1 -0
- package/dist/internal/oauth-server.d.mts +10 -0
- package/dist/internal/oauth-server.mjs +66 -0
- package/dist/internal/oauth-server.mjs.map +1 -0
- package/dist/internal/passkey/admission.d.mts +6 -0
- package/dist/internal/passkey/admission.mjs +216 -0
- package/dist/internal/passkey/admission.mjs.map +1 -0
- package/dist/internal/passkey/credentials.d.mts +14 -0
- package/dist/internal/passkey/credentials.mjs +249 -0
- package/dist/internal/passkey/credentials.mjs.map +1 -0
- package/dist/internal/passkey/enrollment.mjs +138 -0
- package/dist/internal/passkey/enrollment.mjs.map +1 -0
- package/dist/internal/passkey/flow.d.mts +21 -0
- package/dist/internal/passkey/flow.mjs +452 -0
- package/dist/internal/passkey/flow.mjs.map +1 -0
- package/dist/internal/passkey/management.mjs +231 -0
- package/dist/internal/passkey/management.mjs.map +1 -0
- package/dist/internal/passkey/registration-ceremony.d.mts +9 -0
- package/dist/internal/passkey/registration-ceremony.mjs +129 -0
- package/dist/internal/passkey/registration-ceremony.mjs.map +1 -0
- package/dist/internal/passkey/registration-custody.d.mts +2 -0
- package/dist/internal/passkey/registration-custody.mjs +52 -0
- package/dist/internal/passkey/registration-custody.mjs.map +1 -0
- package/dist/internal/passkey/registration-write.mjs +211 -0
- package/dist/internal/passkey/registration-write.mjs.map +1 -0
- package/dist/internal/passkey/state.d.mts +10 -0
- package/dist/internal/passkey/state.mjs +234 -0
- package/dist/internal/passkey/state.mjs.map +1 -0
- package/dist/internal/passkey/target.d.mts +19 -0
- package/dist/internal/passkey/target.mjs +190 -0
- package/dist/internal/passkey/target.mjs.map +1 -0
- package/dist/internal/passkey/write-state.d.mts +17 -0
- package/dist/internal/passkey/write-state.mjs +345 -0
- package/dist/internal/passkey/write-state.mjs.map +1 -0
- package/dist/internal/passkey/write-target.mjs +192 -0
- package/dist/internal/passkey/write-target.mjs.map +1 -0
- package/dist/internal/passkey-kernel.d.mts +5592 -0
- package/dist/internal/passkey-kernel.mjs +49 -0
- package/dist/internal/passkey-kernel.mjs.map +1 -0
- package/dist/internal/passkeys.d.mts +7 -0
- package/dist/internal/passkeys.mjs +368 -0
- package/dist/internal/passkeys.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +290 -0
- package/dist/internal/password-kernel.mjs +704 -0
- package/dist/internal/password-kernel.mjs.map +1 -0
- package/dist/internal/persistence.d.mts +25 -0
- package/dist/internal/persistence.mjs +291 -0
- package/dist/internal/persistence.mjs.map +1 -0
- package/dist/internal/phone-kernel.d.mts +162 -0
- package/dist/internal/phone-kernel.mjs +434 -0
- package/dist/internal/phone-kernel.mjs.map +1 -0
- package/dist/internal/proof-kernel.d.mts +93 -0
- package/dist/internal/proof-kernel.mjs +619 -0
- package/dist/internal/proof-kernel.mjs.map +1 -0
- package/dist/internal/query-operations.d.mts +61 -0
- package/dist/internal/registration-contract.d.mts +16 -0
- package/dist/internal/registration.mjs +66 -0
- package/dist/internal/registration.mjs.map +1 -0
- package/dist/internal/session-kernel.d.mts +48 -0
- package/dist/internal/session-kernel.mjs +737 -0
- package/dist/internal/session-kernel.mjs.map +1 -0
- package/dist/internal/sql-persistence.d.mts +10 -0
- package/dist/internal/sql-persistence.mjs +37 -0
- package/dist/internal/sql-persistence.mjs.map +1 -0
- package/dist/internal/sql-query.mjs +207 -0
- package/dist/internal/sql-query.mjs.map +1 -0
- package/dist/internal/sql-table.d.mts +36 -0
- package/dist/internal/sql-table.mjs +81 -0
- package/dist/internal/sql-table.mjs.map +1 -0
- package/dist/internal/standalone.d.mts +9 -0
- package/dist/internal/standalone.mjs +13 -0
- package/dist/internal/standalone.mjs.map +1 -0
- package/dist/internal/step-up-state.d.mts +49 -0
- package/dist/internal/step-up-state.mjs +32 -0
- package/dist/internal/step-up-state.mjs.map +1 -0
- package/dist/internal/storage-mapping.mjs +686 -0
- package/dist/internal/storage-mapping.mjs.map +1 -0
- package/dist/internal/storage-tables.d.mts +913 -0
- package/dist/internal/storage-tables.mjs +387 -0
- package/dist/internal/storage-tables.mjs.map +1 -0
- package/dist/internal/storage-validation.mjs +58 -0
- package/dist/internal/storage-validation.mjs.map +1 -0
- package/dist/internal/transaction-execution-kernel.d.mts +38 -0
- package/dist/internal/transaction-execution-kernel.mjs +116 -0
- package/dist/internal/transaction-execution-kernel.mjs.map +1 -0
- package/dist/internal/transaction-kernel.d.mts +77 -0
- package/dist/internal/transaction-kernel.mjs +260 -0
- package/dist/internal/transaction-kernel.mjs.map +1 -0
- package/package.json +1 -0
- package/src/Adapter.ts +291 -0
- package/src/index.ts +6 -0
- package/src/internal/PasswordPreparedPostconditions.ts +30 -0
- package/src/internal/configuration.ts +282 -0
- package/src/internal/email-kernel.ts +1535 -0
- package/src/internal/mapping-error.ts +36 -0
- package/src/internal/models/common.ts +11 -0
- package/src/internal/models/email-model.ts +559 -0
- package/src/internal/models/passkey-model.ts +390 -0
- package/src/internal/models/passkey-registration-ceremony-model.ts +72 -0
- package/src/internal/models/passkey-write-model.ts +297 -0
- package/src/internal/models/password-model.ts +513 -0
- package/src/internal/models/proof-model.ts +424 -0
- package/src/internal/models/session-model.ts +375 -0
- package/src/internal/models/step-up-model.ts +135 -0
- package/src/internal/oauth-app.ts +82 -0
- package/src/internal/oauth-server.ts +89 -0
- package/src/internal/passkey/admission.ts +361 -0
- package/src/internal/passkey/credentials.ts +511 -0
- package/src/internal/passkey/enrollment.ts +326 -0
- package/src/internal/passkey/flow.ts +1062 -0
- package/src/internal/passkey/management.ts +421 -0
- package/src/internal/passkey/registration-ceremony.ts +283 -0
- package/src/internal/passkey/registration-custody.ts +91 -0
- package/src/internal/passkey/registration-write.ts +426 -0
- package/src/internal/passkey/state.ts +353 -0
- package/src/internal/passkey/target.ts +586 -0
- package/src/internal/passkey/write-state.ts +681 -0
- package/src/internal/passkey/write-target.ts +452 -0
- package/src/internal/passkey-kernel.ts +104 -0
- package/src/internal/passkeys.ts +606 -0
- package/src/internal/password-kernel.ts +2124 -0
- package/src/internal/persistence.ts +588 -0
- package/src/internal/phone-kernel.ts +846 -0
- package/src/internal/proof-kernel.ts +1954 -0
- package/src/internal/query-operations.ts +81 -0
- package/src/internal/registration-contract.ts +22 -0
- package/src/internal/registration.ts +161 -0
- package/src/internal/session-kernel.ts +2217 -0
- package/src/internal/sql-persistence.ts +45 -0
- package/src/internal/sql-query.ts +298 -0
- package/src/internal/sql-table.ts +104 -0
- package/src/internal/standalone.ts +30 -0
- package/src/internal/step-up-state.ts +139 -0
- package/src/internal/storage-mapping.ts +708 -0
- package/src/internal/storage-tables.ts +408 -0
- package/src/internal/storage-validation.ts +117 -0
- package/src/internal/transaction-execution-kernel.ts +313 -0
- package/src/internal/transaction-kernel.ts +593 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- existing mapped-row bridge; public adapters preserve table, ID, and Effect types. */
|
|
2
|
+
|
|
3
|
+
import type { PasskeyCeremony } from "@yielded/auth/Passkey";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
|
|
6
|
+
import { CurrentPasskeyTransaction } from "./state";
|
|
7
|
+
import type { makePasskeyStateKernel } from "./state";
|
|
8
|
+
|
|
9
|
+
export const makePasskeyRegistrationCustodyKernel = (
|
|
10
|
+
state: Pick<
|
|
11
|
+
ReturnType<typeof makePasskeyStateKernel>,
|
|
12
|
+
"ceremonyStorage" | "equal" | "handleKey" | "invariant"
|
|
13
|
+
>,
|
|
14
|
+
) => {
|
|
15
|
+
const { ceremonyStorage, equal, handleKey } = state;
|
|
16
|
+
const invariant: (value: unknown) => asserts value = state.invariant;
|
|
17
|
+
|
|
18
|
+
/** SQL-local writers have no external provisioning work. A definite terminal
|
|
19
|
+
* rejection can release only its exact still-reserved handle; ambiguous owners
|
|
20
|
+
* retain custody, and an accepted transaction no longer matches this reservation. */
|
|
21
|
+
const releaseRegistrationCustody = Effect.fn("passkey.releaseRegistrationCustody")(function* (
|
|
22
|
+
mapping: any,
|
|
23
|
+
ceremony: PasskeyCeremony,
|
|
24
|
+
) {
|
|
25
|
+
if (mapping.registration === undefined || ceremony.context._tag !== "Registration") return;
|
|
26
|
+
const owner = yield* CurrentPasskeyTransaction;
|
|
27
|
+
const handle = mapping.handle;
|
|
28
|
+
const intent = mapping.intent;
|
|
29
|
+
const hashed = handleKey(ceremony.profile.rpId, ceremony.context.userHandle);
|
|
30
|
+
|
|
31
|
+
const held = (yield* owner.read(
|
|
32
|
+
handle.table,
|
|
33
|
+
equal(handle.table, { [handle.handleKey]: hashed }),
|
|
34
|
+
{ limit: 1 },
|
|
35
|
+
)).rows[0];
|
|
36
|
+
|
|
37
|
+
const row = (yield* owner.read(
|
|
38
|
+
intent.table,
|
|
39
|
+
equal(intent.table, {
|
|
40
|
+
[intent.moduleId]: mapping.moduleId,
|
|
41
|
+
[intent.flowId]: ceremony.flowId,
|
|
42
|
+
}),
|
|
43
|
+
{ limit: 1 },
|
|
44
|
+
)).rows[0];
|
|
45
|
+
|
|
46
|
+
if (row === undefined || !intent.isPendingState(row[intent.state])) return;
|
|
47
|
+
invariant(
|
|
48
|
+
held !== undefined &&
|
|
49
|
+
handle.isReservedState(held[handle.state]) &&
|
|
50
|
+
held[handle.reservationId] === row[intent.reservationId] &&
|
|
51
|
+
row[intent.handleKey] === hashed &&
|
|
52
|
+
row[intent.commandId] === ceremony.commandId &&
|
|
53
|
+
row[intent.ceremonySnapshot] === ceremonyStorage.encode(ceremony),
|
|
54
|
+
);
|
|
55
|
+
yield* owner.update(
|
|
56
|
+
intent.table,
|
|
57
|
+
{ [intent.moduleId]: mapping.moduleId, [intent.flowId]: ceremony.flowId },
|
|
58
|
+
{ [intent.state]: intent.rejectedState, [intent.version]: owner.marker },
|
|
59
|
+
);
|
|
60
|
+
yield* owner.remove(handle.table, { [handle.handleKey]: hashed });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** Keep the command/flow tombstone after retention, without retaining the
|
|
64
|
+
* application registration payload or ceremony. Ambiguous custody is never scrubbed. */
|
|
65
|
+
const scrubRegistrationIntent = Effect.fn("passkey.scrubRegistrationIntent")(function* (
|
|
66
|
+
mapping: any,
|
|
67
|
+
ceremony: PasskeyCeremony,
|
|
68
|
+
) {
|
|
69
|
+
if (mapping.registration === undefined || ceremony.context._tag !== "Registration") return;
|
|
70
|
+
const owner = yield* CurrentPasskeyTransaction;
|
|
71
|
+
const intent = mapping.intent;
|
|
72
|
+
const identity = { [intent.moduleId]: mapping.moduleId, [intent.flowId]: ceremony.flowId };
|
|
73
|
+
|
|
74
|
+
const row = (yield* owner.read(intent.table, equal(intent.table, identity), { limit: 1 }))
|
|
75
|
+
.rows[0];
|
|
76
|
+
|
|
77
|
+
if (row === undefined) return;
|
|
78
|
+
invariant(
|
|
79
|
+
(row[intent.state] === intent.acceptedState || row[intent.state] === intent.rejectedState) &&
|
|
80
|
+
row[intent.commandId] === ceremony.commandId &&
|
|
81
|
+
row[intent.ceremonySnapshot] === ceremonyStorage.encode(ceremony),
|
|
82
|
+
);
|
|
83
|
+
yield* owner.update(intent.table, identity, {
|
|
84
|
+
[intent.applicationSnapshot]: "",
|
|
85
|
+
[intent.ceremonySnapshot]: "",
|
|
86
|
+
[intent.version]: owner.marker,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return { releaseRegistrationCustody, scrubRegistrationIntent };
|
|
91
|
+
};
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/* oxlint-disable no-explicit-any -- existing mapped-row bridge; public adapters preserve table, ID, and Effect types. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PasskeyLabel,
|
|
5
|
+
PasskeyRevision,
|
|
6
|
+
type PasskeyCeremony,
|
|
7
|
+
type PasskeyClaim,
|
|
8
|
+
type PasskeyRegistrationVerified,
|
|
9
|
+
type PasskeyMethodPolicy,
|
|
10
|
+
} from "@yielded/auth/Passkey";
|
|
11
|
+
import { SubjectId } from "@yielded/auth/Schema";
|
|
12
|
+
import { Effect, Schema } from "effect";
|
|
13
|
+
|
|
14
|
+
import type { QueryOperations } from "../query-operations";
|
|
15
|
+
import type { makeTransactionKernel } from "../transaction-kernel";
|
|
16
|
+
import type { makePasskeyAdmissionKernel } from "./admission";
|
|
17
|
+
import type { makePasskeyCredentialsKernel } from "./credentials";
|
|
18
|
+
import type { makePasskeyFlowKernel } from "./flow";
|
|
19
|
+
import type { makePasskeyRegistrationCustodyKernel } from "./registration-custody";
|
|
20
|
+
import { CurrentPasskeyTransaction } from "./state";
|
|
21
|
+
import type { makePasskeyStateKernel } from "./state";
|
|
22
|
+
import type { makePasskeyWriteStateKernel } from "./write-state";
|
|
23
|
+
|
|
24
|
+
export const makePasskeyRegistrationWriteKernel = (
|
|
25
|
+
operations: QueryOperations,
|
|
26
|
+
admission: Pick<
|
|
27
|
+
ReturnType<typeof makePasskeyAdmissionKernel>,
|
|
28
|
+
"lockAdmission" | "readCharges" | "guardChargeSet"
|
|
29
|
+
>,
|
|
30
|
+
credentials: Pick<
|
|
31
|
+
ReturnType<typeof makePasskeyCredentialsKernel>,
|
|
32
|
+
"readModule" | "readPolicyGuards"
|
|
33
|
+
>,
|
|
34
|
+
flow: Pick<
|
|
35
|
+
ReturnType<typeof makePasskeyFlowKernel>,
|
|
36
|
+
| "compatiblePolicy"
|
|
37
|
+
| "exactClaim"
|
|
38
|
+
| "issueAssertion"
|
|
39
|
+
| "liveCondition"
|
|
40
|
+
| "readFlow"
|
|
41
|
+
| "terminalFlow"
|
|
42
|
+
>,
|
|
43
|
+
registrationCustody: Pick<
|
|
44
|
+
ReturnType<typeof makePasskeyRegistrationCustodyKernel>,
|
|
45
|
+
"releaseRegistrationCustody"
|
|
46
|
+
>,
|
|
47
|
+
state: Pick<
|
|
48
|
+
ReturnType<typeof makePasskeyStateKernel>,
|
|
49
|
+
"ceremonyStorage" | "credentialKey" | "equal" | "handleKey" | "invariant"
|
|
50
|
+
>,
|
|
51
|
+
writeState: Pick<
|
|
52
|
+
ReturnType<typeof makePasskeyWriteStateKernel>,
|
|
53
|
+
"digest" | "insertCredential" | "jsonStorage" | "validRegistration"
|
|
54
|
+
>,
|
|
55
|
+
transactions: Pick<ReturnType<typeof makeTransactionKernel>, "both">,
|
|
56
|
+
) => {
|
|
57
|
+
const { sql } = operations;
|
|
58
|
+
const { lockAdmission, readCharges, guardChargeSet } = admission;
|
|
59
|
+
const { readModule, readPolicyGuards } = credentials;
|
|
60
|
+
|
|
61
|
+
const { compatiblePolicy, exactClaim, issueAssertion, liveCondition, readFlow, terminalFlow } =
|
|
62
|
+
flow;
|
|
63
|
+
|
|
64
|
+
const { releaseRegistrationCustody } = registrationCustody;
|
|
65
|
+
const { ceremonyStorage, credentialKey, equal, handleKey } = state;
|
|
66
|
+
const invariant: (value: unknown) => asserts value = state.invariant;
|
|
67
|
+
const { digest, insertCredential, jsonStorage, validRegistration } = writeState;
|
|
68
|
+
const { both } = transactions;
|
|
69
|
+
|
|
70
|
+
const registrationData = (mapping: any, registration: any) => {
|
|
71
|
+
const codec = jsonStorage(mapping.registration.schema);
|
|
72
|
+
const encoded = codec.encode(registration);
|
|
73
|
+
|
|
74
|
+
invariant(new TextEncoder().encode(encoded).length <= 1048576);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
encoded,
|
|
78
|
+
registration: codec.decode(encoded),
|
|
79
|
+
fingerprint: digest(mapping.registration.schema, registration),
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const describe = (mapping: any, registration: any) => {
|
|
84
|
+
const data = registrationData(mapping, registration);
|
|
85
|
+
|
|
86
|
+
const labels = Schema.decodeSync(
|
|
87
|
+
Schema.Struct({ name: PasskeyLabel, displayName: PasskeyLabel }),
|
|
88
|
+
)(mapping.registration.describe(data.registration));
|
|
89
|
+
|
|
90
|
+
return { ...data, ...labels };
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const inspectRegistration = Effect.fn("passkey.inspectRegistration")(function* (
|
|
94
|
+
mapping: any,
|
|
95
|
+
registration: any,
|
|
96
|
+
) {
|
|
97
|
+
const owner = yield* CurrentPasskeyTransaction;
|
|
98
|
+
const value = describe(mapping, registration);
|
|
99
|
+
const current = yield* readModule(mapping);
|
|
100
|
+
|
|
101
|
+
yield* readPolicyGuards(mapping);
|
|
102
|
+
|
|
103
|
+
const eligible =
|
|
104
|
+
current !== undefined &&
|
|
105
|
+
(yield* owner.check(mapping.registration.eligible(value.registration)));
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
fingerprint: value.fingerprint,
|
|
109
|
+
name: value.name,
|
|
110
|
+
displayName: value.displayName,
|
|
111
|
+
eligible,
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const issueRegistration = Effect.fn("passkey.issueRegistration")(function* (
|
|
116
|
+
mapping: any,
|
|
117
|
+
input: {
|
|
118
|
+
readonly ceremony: PasskeyCeremony;
|
|
119
|
+
readonly policy: PasskeyMethodPolicy;
|
|
120
|
+
readonly registration: any;
|
|
121
|
+
},
|
|
122
|
+
) {
|
|
123
|
+
const owner = yield* CurrentPasskeyTransaction;
|
|
124
|
+
const ceremony = input.ceremony;
|
|
125
|
+
|
|
126
|
+
if (
|
|
127
|
+
ceremony.moduleId !== mapping.moduleId ||
|
|
128
|
+
ceremony.purpose !== "registration" ||
|
|
129
|
+
ceremony.context._tag !== "Registration" ||
|
|
130
|
+
!ceremony.profile.primarySignIn ||
|
|
131
|
+
ceremony.profile.userVerification !== "required" ||
|
|
132
|
+
ceremony.profile.residentKey !== "required" ||
|
|
133
|
+
ceremony.allowedCredentials.length !== 0
|
|
134
|
+
)
|
|
135
|
+
return { _tag: "Rejected" } as const;
|
|
136
|
+
const value = describe(mapping, input.registration);
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
value.fingerprint !== ceremony.context.fingerprint ||
|
|
140
|
+
value.name !== ceremony.context.name ||
|
|
141
|
+
value.displayName !== ceremony.context.displayName
|
|
142
|
+
)
|
|
143
|
+
return { _tag: "Rejected" } as const;
|
|
144
|
+
if ((yield* readModule(mapping)) === undefined) return { _tag: "Rejected" } as const;
|
|
145
|
+
yield* lockAdmission(mapping);
|
|
146
|
+
yield* readPolicyGuards(mapping);
|
|
147
|
+
const eligible = mapping.registration.eligible(value.registration);
|
|
148
|
+
|
|
149
|
+
if (!(yield* owner.check(eligible))) return { _tag: "Rejected" } as const;
|
|
150
|
+
const handle = mapping.handle;
|
|
151
|
+
const hashed = handleKey(ceremony.profile.rpId, ceremony.context.userHandle);
|
|
152
|
+
|
|
153
|
+
const absentHandle = yield* owner.read(
|
|
154
|
+
handle.table,
|
|
155
|
+
equal(handle.table, { [handle.handleKey]: hashed }),
|
|
156
|
+
{ limit: 1 },
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const intent = mapping.intent;
|
|
160
|
+
|
|
161
|
+
const absentCommand = yield* owner.read(
|
|
162
|
+
intent.table,
|
|
163
|
+
equal(intent.table, {
|
|
164
|
+
[intent.moduleId]: mapping.moduleId,
|
|
165
|
+
[intent.commandId]: ceremony.commandId,
|
|
166
|
+
}),
|
|
167
|
+
{ limit: 1 },
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const absentFlow = yield* owner.read(
|
|
171
|
+
intent.table,
|
|
172
|
+
equal(intent.table, {
|
|
173
|
+
[intent.moduleId]: mapping.moduleId,
|
|
174
|
+
[intent.flowId]: ceremony.flowId,
|
|
175
|
+
}),
|
|
176
|
+
{ limit: 1 },
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
if (
|
|
180
|
+
absentHandle.rows.length !== 0 ||
|
|
181
|
+
absentCommand.rows.length !== 0 ||
|
|
182
|
+
absentFlow.rows.length !== 0
|
|
183
|
+
)
|
|
184
|
+
return { _tag: "Rejected" } as const;
|
|
185
|
+
const issued = yield* issueAssertion(mapping, ceremony, input.policy);
|
|
186
|
+
|
|
187
|
+
if (issued._tag !== "Issued") return issued;
|
|
188
|
+
|
|
189
|
+
const reserved = yield* owner.insert(
|
|
190
|
+
handle.table,
|
|
191
|
+
{
|
|
192
|
+
...handle.encodeInsert({ ceremony, reservationId: owner.marker }),
|
|
193
|
+
[handle.handleKey]: hashed,
|
|
194
|
+
[handle.rpId]: ceremony.profile.rpId,
|
|
195
|
+
[handle.userHandle]: ceremony.context.userHandle,
|
|
196
|
+
[handle.state]: handle.reservedState,
|
|
197
|
+
[handle.version]: owner.marker,
|
|
198
|
+
[handle.reservationId]: owner.marker,
|
|
199
|
+
[mapping.read.handleOwnership.subjectId]: null,
|
|
200
|
+
},
|
|
201
|
+
{ [handle.handleKey]: hashed },
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
absentHandle.rows = reserved.rows;
|
|
205
|
+
|
|
206
|
+
const inserted = yield* owner.insert(
|
|
207
|
+
intent.table,
|
|
208
|
+
{
|
|
209
|
+
...intent.encodeInsert({
|
|
210
|
+
ceremony,
|
|
211
|
+
registration: value.registration,
|
|
212
|
+
reservationId: owner.marker,
|
|
213
|
+
}),
|
|
214
|
+
[intent.moduleId]: mapping.moduleId,
|
|
215
|
+
[intent.flowId]: ceremony.flowId,
|
|
216
|
+
[intent.commandId]: ceremony.commandId,
|
|
217
|
+
[intent.state]: intent.pendingState,
|
|
218
|
+
[intent.version]: owner.marker,
|
|
219
|
+
[intent.fingerprint]: value.fingerprint,
|
|
220
|
+
[intent.handleKey]: hashed,
|
|
221
|
+
[intent.reservationId]: owner.marker,
|
|
222
|
+
[intent.ceremonySnapshot]: ceremonyStorage.encode(ceremony),
|
|
223
|
+
[intent.applicationSnapshot]: value.encoded,
|
|
224
|
+
},
|
|
225
|
+
{ [intent.moduleId]: mapping.moduleId, [intent.flowId]: ceremony.flowId },
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
absentCommand.rows = inserted.rows;
|
|
229
|
+
absentFlow.rows = inserted.rows;
|
|
230
|
+
owner.postconditions.push(eligible);
|
|
231
|
+
|
|
232
|
+
return issued;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const completeRegistration = Effect.fn("passkey.completeRegistration")(function* (
|
|
236
|
+
mapping: any,
|
|
237
|
+
input: {
|
|
238
|
+
readonly claim: PasskeyClaim;
|
|
239
|
+
readonly verified: PasskeyRegistrationVerified;
|
|
240
|
+
readonly nowMillis: number;
|
|
241
|
+
},
|
|
242
|
+
) {
|
|
243
|
+
const owner = yield* CurrentPasskeyTransaction;
|
|
244
|
+
const ceremony = input.claim.ceremony;
|
|
245
|
+
|
|
246
|
+
if (
|
|
247
|
+
ceremony.moduleId !== mapping.moduleId ||
|
|
248
|
+
ceremony.purpose !== "registration" ||
|
|
249
|
+
ceremony.context._tag !== "Registration"
|
|
250
|
+
)
|
|
251
|
+
return { _tag: "Rejected" } as const;
|
|
252
|
+
const current = yield* readModule(mapping);
|
|
253
|
+
|
|
254
|
+
if (current === undefined) return { _tag: "Rejected" } as const;
|
|
255
|
+
yield* lockAdmission(mapping);
|
|
256
|
+
yield* readPolicyGuards(mapping);
|
|
257
|
+
const tuple = mapping.read.credentialOwnership;
|
|
258
|
+
|
|
259
|
+
const absentCredential = yield* owner.read(
|
|
260
|
+
tuple.table,
|
|
261
|
+
equal(tuple.table, {
|
|
262
|
+
[tuple.credentialKey]: credentialKey(
|
|
263
|
+
ceremony.profile.rpId,
|
|
264
|
+
input.verified.protocolCredentialId,
|
|
265
|
+
),
|
|
266
|
+
}),
|
|
267
|
+
{ limit: 1, observe: false },
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const handle = mapping.handle;
|
|
271
|
+
const hashed = handleKey(ceremony.profile.rpId, ceremony.context.userHandle);
|
|
272
|
+
|
|
273
|
+
const held = (yield* owner.read(
|
|
274
|
+
handle.table,
|
|
275
|
+
equal(handle.table, { [handle.handleKey]: hashed }),
|
|
276
|
+
{ limit: 1 },
|
|
277
|
+
)).rows[0];
|
|
278
|
+
|
|
279
|
+
const intent = mapping.intent;
|
|
280
|
+
|
|
281
|
+
const row = (yield* owner.read(
|
|
282
|
+
intent.table,
|
|
283
|
+
equal(intent.table, {
|
|
284
|
+
[intent.moduleId]: mapping.moduleId,
|
|
285
|
+
[intent.flowId]: ceremony.flowId,
|
|
286
|
+
}),
|
|
287
|
+
{ limit: 1 },
|
|
288
|
+
)).rows[0];
|
|
289
|
+
|
|
290
|
+
const read = yield* readFlow(mapping, ceremony.flowId);
|
|
291
|
+
|
|
292
|
+
if (read === undefined || !exactClaim(read, input.claim)) return { _tag: "Rejected" } as const;
|
|
293
|
+
|
|
294
|
+
const reject = Effect.gen(function* () {
|
|
295
|
+
yield* releaseRegistrationCustody(mapping, ceremony);
|
|
296
|
+
yield* terminalFlow(mapping, read, "Rejected");
|
|
297
|
+
|
|
298
|
+
return { _tag: "Rejected" } as const;
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (
|
|
302
|
+
absentCredential.rows.length !== 0 ||
|
|
303
|
+
held === undefined ||
|
|
304
|
+
row === undefined ||
|
|
305
|
+
!handle.isReservedState(held[handle.state]) ||
|
|
306
|
+
!intent.isPendingState(row[intent.state]) ||
|
|
307
|
+
row[intent.commandId] !== ceremony.commandId ||
|
|
308
|
+
row[intent.ceremonySnapshot] !== ceremonyStorage.encode(ceremony) ||
|
|
309
|
+
row[intent.fingerprint] !== ceremony.context.fingerprint ||
|
|
310
|
+
row[intent.handleKey] !== hashed ||
|
|
311
|
+
held[handle.reservationId] !== row[intent.reservationId] ||
|
|
312
|
+
held[handle.rpId] !== ceremony.profile.rpId ||
|
|
313
|
+
held[handle.userHandle] !== ceremony.context.userHandle ||
|
|
314
|
+
!compatiblePolicy(ceremony, read.policy, current) ||
|
|
315
|
+
!validRegistration(ceremony, input.verified) ||
|
|
316
|
+
!input.verified.userVerified ||
|
|
317
|
+
!ceremony.profile.primarySignIn ||
|
|
318
|
+
!(yield* owner.check(liveCondition(mapping, ceremony, input.claim)))
|
|
319
|
+
)
|
|
320
|
+
return yield* reject;
|
|
321
|
+
|
|
322
|
+
const data = describe(
|
|
323
|
+
mapping,
|
|
324
|
+
jsonStorage(mapping.registration.schema).decode(row[intent.applicationSnapshot]),
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
if (
|
|
328
|
+
data.encoded !== row[intent.applicationSnapshot] ||
|
|
329
|
+
data.fingerprint !== ceremony.context.fingerprint ||
|
|
330
|
+
data.name !== ceremony.context.name ||
|
|
331
|
+
data.displayName !== ceremony.context.displayName
|
|
332
|
+
)
|
|
333
|
+
return yield* reject;
|
|
334
|
+
const eligible = mapping.registration.eligible(data.registration);
|
|
335
|
+
|
|
336
|
+
if (!(yield* owner.check(eligible))) return yield* reject;
|
|
337
|
+
|
|
338
|
+
const provision = mapping.registration.subject({
|
|
339
|
+
registration: data.registration,
|
|
340
|
+
ceremony,
|
|
341
|
+
marker: owner.marker,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const nativeId = provision.subjectId;
|
|
345
|
+
const subjectId = SubjectId.make(mapping.read.subjectIds.toSubject(nativeId));
|
|
346
|
+
|
|
347
|
+
invariant(
|
|
348
|
+
mapping.read.subjectIds.equals(mapping.read.subjectIds.toNative(subjectId), nativeId),
|
|
349
|
+
);
|
|
350
|
+
const table = mapping.read.subject;
|
|
351
|
+
|
|
352
|
+
const absentSubject = yield* owner.read(
|
|
353
|
+
table.table,
|
|
354
|
+
equal(table.table, { [table.id]: nativeId }),
|
|
355
|
+
{ limit: 1 },
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
if (absentSubject.rows.length !== 0) return yield* reject;
|
|
359
|
+
|
|
360
|
+
const values = {
|
|
361
|
+
...provision.values,
|
|
362
|
+
[table.id]: nativeId,
|
|
363
|
+
[table.status]: mapping.registration.activeStatus,
|
|
364
|
+
[table.securityRevision]: owner.marker,
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const inserted = yield* owner.insert(table.table, values, { [table.id]: nativeId });
|
|
368
|
+
|
|
369
|
+
absentSubject.rows = inserted.rows;
|
|
370
|
+
|
|
371
|
+
const subject = {
|
|
372
|
+
subjectId,
|
|
373
|
+
nativeId,
|
|
374
|
+
row: values,
|
|
375
|
+
revision: PasskeyRevision.make({
|
|
376
|
+
subjectId,
|
|
377
|
+
securityRevision: PasskeyRevision.fields.securityRevision.make(owner.marker),
|
|
378
|
+
credentials: [],
|
|
379
|
+
}),
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
yield* owner.update(
|
|
383
|
+
handle.table,
|
|
384
|
+
{ [handle.handleKey]: hashed },
|
|
385
|
+
{
|
|
386
|
+
[mapping.read.handleOwnership.subjectId]: nativeId,
|
|
387
|
+
[handle.state]: mapping.write.handleOwnership.ownedState,
|
|
388
|
+
[handle.version]: owner.marker,
|
|
389
|
+
[handle.reservationId]: null,
|
|
390
|
+
},
|
|
391
|
+
);
|
|
392
|
+
yield* readCharges(mapping, ceremony, read.policy);
|
|
393
|
+
yield* guardChargeSet(mapping, ceremony);
|
|
394
|
+
yield* insertCredential(
|
|
395
|
+
mapping,
|
|
396
|
+
subject,
|
|
397
|
+
ceremony,
|
|
398
|
+
input.verified,
|
|
399
|
+
yield* owner.now(mapping.clock),
|
|
400
|
+
);
|
|
401
|
+
yield* owner.update(
|
|
402
|
+
intent.table,
|
|
403
|
+
{ [intent.moduleId]: mapping.moduleId, [intent.flowId]: ceremony.flowId },
|
|
404
|
+
{ [intent.state]: intent.acceptedState, [intent.version]: owner.marker },
|
|
405
|
+
);
|
|
406
|
+
const flow = mapping.flow;
|
|
407
|
+
|
|
408
|
+
yield* owner.update(
|
|
409
|
+
flow.table,
|
|
410
|
+
{ [flow.moduleId]: mapping.moduleId, [flow.flowId]: ceremony.flowId },
|
|
411
|
+
{ [flow.state]: flow.states.RegistrationAccepted, [flow.version]: owner.marker },
|
|
412
|
+
);
|
|
413
|
+
owner.postconditions.push(
|
|
414
|
+
liveCondition(mapping, ceremony, input.claim),
|
|
415
|
+
mapping.registration.finalEligibility({
|
|
416
|
+
registration: data.registration,
|
|
417
|
+
subjectId: nativeId,
|
|
418
|
+
}),
|
|
419
|
+
sql`exists(select 1 from ${table.table} where ${both(owner.exact(table.table, values), table.activeCondition)})`,
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
return { _tag: "RegistrationAccepted" } as const;
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
return { inspectRegistration, issueRegistration, completeRegistration };
|
|
426
|
+
};
|