@reventlessdev/reventless-registration 1.0.0-alpha.2 → 1.0.0-alpha.20
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/package.json +4 -4
- package/src/Registration/ContactAddressId.res +27 -3
- package/src/Registration/ContactAddressId.res.mjs +26 -2
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
- package/src/Registration/InboundTranslation/SignUp.res +1 -0
- package/src/Registration/InboundTranslation/SignUp.res.mjs +3 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res +23 -12
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +13 -4
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +7 -1
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +4 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +6 -3
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +11 -2
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +24 -3
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +7 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +17 -15
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +75 -35
- package/src/Registration/StateChange/Registrations.res +33 -2
- package/src/Registration/StateChange/Registrations.res.mjs +31 -1
- package/src/Registration/StateChange/Registrations_Decision.res +54 -13
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +75 -26
|
@@ -9,44 +9,84 @@ import * as RegistrationChallenge$ReventlessRegistration from "../../Registratio
|
|
|
9
9
|
function collect(event, param) {
|
|
10
10
|
switch (event.TAG) {
|
|
11
11
|
case "RegistrationRequested" :
|
|
12
|
+
let address = event.address;
|
|
12
13
|
let email = event.email;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (typeof address !== "object") {
|
|
15
|
+
if (address === "Erased") {
|
|
16
|
+
return [];
|
|
17
|
+
} else {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
return [[
|
|
22
|
+
email + `:` + event.requestedAt,
|
|
23
|
+
{
|
|
24
|
+
email: email,
|
|
25
|
+
address: address._0,
|
|
26
|
+
alreadyRegistered: false
|
|
27
|
+
}
|
|
28
|
+
]];
|
|
29
|
+
}
|
|
20
30
|
case "RegistrationAttemptedOnTakenAddress" :
|
|
31
|
+
let address$1 = event.address;
|
|
21
32
|
let email$1 = event.email;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
if (typeof address$1 !== "object") {
|
|
34
|
+
if (address$1 === "Erased") {
|
|
35
|
+
return [];
|
|
36
|
+
} else {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
return [[
|
|
41
|
+
email$1 + `:taken:` + event.attemptedAt,
|
|
42
|
+
{
|
|
43
|
+
email: email$1,
|
|
44
|
+
address: address$1._0,
|
|
45
|
+
alreadyRegistered: true
|
|
46
|
+
}
|
|
47
|
+
]];
|
|
48
|
+
}
|
|
29
49
|
case "RegistrationInvited" :
|
|
50
|
+
let address$2 = event.address;
|
|
30
51
|
let email$2 = event.email;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
if (typeof address$2 !== "object") {
|
|
53
|
+
if (address$2 === "Erased") {
|
|
54
|
+
return [];
|
|
55
|
+
} else {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
return [[
|
|
60
|
+
email$2 + `:invited:` + event.invitedAt,
|
|
61
|
+
{
|
|
62
|
+
email: email$2,
|
|
63
|
+
address: address$2._0,
|
|
64
|
+
alreadyRegistered: false,
|
|
65
|
+
invited: true,
|
|
66
|
+
roles: event.roles
|
|
67
|
+
}
|
|
68
|
+
]];
|
|
69
|
+
}
|
|
40
70
|
case "RegistrationChallengeReissued" :
|
|
71
|
+
let address$3 = event.address;
|
|
41
72
|
let email$3 = event.email;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
if (typeof address$3 !== "object") {
|
|
74
|
+
if (address$3 === "Erased") {
|
|
75
|
+
return [];
|
|
76
|
+
} else {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
return [[
|
|
81
|
+
email$3 + `:reissued:` + event.reissuedAt,
|
|
82
|
+
{
|
|
83
|
+
email: email$3,
|
|
84
|
+
address: address$3._0,
|
|
85
|
+
alreadyRegistered: false,
|
|
86
|
+
invited: Stdlib_Option.isSome(event.invitedBy)
|
|
87
|
+
}
|
|
88
|
+
]];
|
|
89
|
+
}
|
|
50
90
|
}
|
|
51
91
|
}
|
|
52
92
|
|
|
@@ -72,10 +112,10 @@ function invitationBody(token, roles) {
|
|
|
72
112
|
|
|
73
113
|
let noticeBody = "Someone asked to register an account with this address, which already has one. If it was you, sign in instead. If it was not, there is nothing to do: no account was changed.";
|
|
74
114
|
|
|
75
|
-
function send(capabilities,
|
|
115
|
+
function send(capabilities, address, subject, body) {
|
|
76
116
|
return capabilities.messaging.send({
|
|
77
117
|
TAG: "ToEmail",
|
|
78
|
-
_0:
|
|
118
|
+
_0: address
|
|
79
119
|
}, {
|
|
80
120
|
subject: subject,
|
|
81
121
|
body: body
|
|
@@ -84,7 +124,7 @@ function send(capabilities, email, subject, body) {
|
|
|
84
124
|
|
|
85
125
|
async function translate(_id, item, capabilities) {
|
|
86
126
|
if (item.alreadyRegistered) {
|
|
87
|
-
let failure = await send(capabilities, item.
|
|
127
|
+
let failure = await send(capabilities, item.address, "Someone tried to register with your address", noticeBody);
|
|
88
128
|
if (failure.TAG === "Ok") {
|
|
89
129
|
return {
|
|
90
130
|
TAG: "Ok",
|
|
@@ -114,7 +154,7 @@ async function translate(_id, item, capabilities) {
|
|
|
114
154
|
_0: `cannot hash a secret: ` + proofHash._0._0
|
|
115
155
|
};
|
|
116
156
|
}
|
|
117
|
-
let failure$1 = await send(capabilities, item.
|
|
157
|
+
let failure$1 = await send(capabilities, item.address, invited ? "You are invited to create an account" : "Finish your registration", invited ? invitationBody(token$1, item.roles) : challengeBody(token$1));
|
|
118
158
|
if (failure$1.TAG === "Ok") {
|
|
119
159
|
return {
|
|
120
160
|
TAG: "Ok",
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
// translations in this chapter: they stamp the time a request arrived, and they
|
|
16
16
|
// hash a presented proof so its plaintext never reaches this slice or the log.
|
|
17
17
|
//
|
|
18
|
+
// **The address is not the key.** `email` is the address's keyed fingerprint
|
|
19
|
+
// (`ContactAddressId`), which is what tags and partitions the ledger; an index key
|
|
20
|
+
// cannot be erased. The address itself rides in `address`, on the events that must
|
|
21
|
+
// reach the person and on the commands that start a claim, so it lives only where
|
|
22
|
+
// a payload field can be encrypted or erased.
|
|
23
|
+
//
|
|
18
24
|
// **Its answers do not tell an anonymous caller anything.** A closed policy, a
|
|
19
25
|
// pending registration and an address already registered all leave the door
|
|
20
26
|
// answering the same way; only what is sent to the address differs.
|
|
@@ -35,24 +41,28 @@ type consumedEvent =
|
|
|
35
41
|
})
|
|
36
42
|
| RegistrationRequested({
|
|
37
43
|
email: ContactAddressId.t,
|
|
44
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
38
45
|
roles: array<string>,
|
|
39
46
|
requestedAt: Reventless.DateTime.t,
|
|
40
47
|
})
|
|
41
48
|
| RegistrationExpired({email: ContactAddressId.t})
|
|
42
49
|
| RegistrationInvited({
|
|
43
50
|
email: ContactAddressId.t,
|
|
51
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
44
52
|
roles: array<string>,
|
|
45
53
|
invitedBy: string,
|
|
46
54
|
invitedAt: Reventless.DateTime.t,
|
|
47
55
|
})
|
|
48
56
|
| RegistrationChallengeReissued({
|
|
49
57
|
email: ContactAddressId.t,
|
|
58
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
50
59
|
reissuedAt: Reventless.DateTime.t,
|
|
51
60
|
invitedBy?: string,
|
|
52
61
|
})
|
|
53
62
|
| RegistrationWithdrawn({email: ContactAddressId.t, withdrawnAt: Reventless.DateTime.t})
|
|
54
63
|
| RegistrationAttemptedOnTakenAddress({
|
|
55
64
|
email: ContactAddressId.t,
|
|
65
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
56
66
|
attemptedAt: Reventless.DateTime.t,
|
|
57
67
|
})
|
|
58
68
|
| RegistrationChallengeIssued({
|
|
@@ -60,9 +70,15 @@ type consumedEvent =
|
|
|
60
70
|
proofHash: string,
|
|
61
71
|
issuedAt: Reventless.DateTime.t,
|
|
62
72
|
})
|
|
63
|
-
| RegistrationProofAccepted({
|
|
73
|
+
| RegistrationProofAccepted({
|
|
74
|
+
email: ContactAddressId.t,
|
|
75
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
76
|
+
roles: array<string>,
|
|
77
|
+
proofHash: string,
|
|
78
|
+
})
|
|
64
79
|
| RegistrationProofRefused({email: ContactAddressId.t, reason: string})
|
|
65
80
|
| RegistrationCompleted({email: ContactAddressId.t})
|
|
81
|
+
| RegistrationReleased({email: ContactAddressId.t, releasedAt: Reventless.DateTime.t})
|
|
66
82
|
|
|
67
83
|
// `Register` names the role asked for, and the policy is read by it. The
|
|
68
84
|
// registration records the roles it grants as
|
|
@@ -78,6 +94,7 @@ type command =
|
|
|
78
94
|
| @noApi
|
|
79
95
|
Register({
|
|
80
96
|
email: ContactAddressId.t,
|
|
97
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
81
98
|
role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
|
|
82
99
|
requestedAt: Reventless.DateTime.t,
|
|
83
100
|
})
|
|
@@ -100,6 +117,7 @@ type command =
|
|
|
100
117
|
| @noApi
|
|
101
118
|
Invite({
|
|
102
119
|
email: ContactAddressId.t,
|
|
120
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
103
121
|
roles: array<Reventless.Role.name>,
|
|
104
122
|
invitedBy: string,
|
|
105
123
|
requestedAt: Reventless.DateTime.t,
|
|
@@ -113,6 +131,9 @@ type command =
|
|
|
113
131
|
})
|
|
114
132
|
// Releases an address a registration holds and nobody has proved yet.
|
|
115
133
|
| @noApi WithdrawRegistration({email: ContactAddressId.t, withdrawnAt: Reventless.DateTime.t})
|
|
134
|
+
// Releases the address of an account that was erased, so its person may
|
|
135
|
+
// register again. Only the erasure workflow sends it, after the account is gone.
|
|
136
|
+
| @noApi ReleaseRegistration({email: ContactAddressId.t, releasedAt: Reventless.DateTime.t})
|
|
116
137
|
|
|
117
138
|
// Every outcome of a command relayed for an anonymous caller is a recorded fact
|
|
118
139
|
// or a quiet no-op, never an error: an error is the one answer a caller could
|
|
@@ -127,24 +148,28 @@ type error =
|
|
|
127
148
|
type event =
|
|
128
149
|
| RegistrationRequested({
|
|
129
150
|
email: ContactAddressId.t,
|
|
151
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
130
152
|
roles: array<string>,
|
|
131
153
|
requestedAt: Reventless.DateTime.t,
|
|
132
154
|
})
|
|
133
155
|
| RegistrationExpired({email: ContactAddressId.t})
|
|
134
156
|
| RegistrationInvited({
|
|
135
157
|
email: ContactAddressId.t,
|
|
158
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
136
159
|
roles: array<string>,
|
|
137
160
|
invitedBy: string,
|
|
138
161
|
invitedAt: Reventless.DateTime.t,
|
|
139
162
|
})
|
|
140
163
|
| RegistrationChallengeReissued({
|
|
141
164
|
email: ContactAddressId.t,
|
|
165
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
142
166
|
reissuedAt: Reventless.DateTime.t,
|
|
143
167
|
invitedBy?: string,
|
|
144
168
|
})
|
|
145
169
|
| RegistrationWithdrawn({email: ContactAddressId.t, withdrawnAt: Reventless.DateTime.t})
|
|
146
170
|
| RegistrationAttemptedOnTakenAddress({
|
|
147
171
|
email: ContactAddressId.t,
|
|
172
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
148
173
|
attemptedAt: Reventless.DateTime.t,
|
|
149
174
|
})
|
|
150
175
|
| RegistrationChallengeIssued({
|
|
@@ -152,6 +177,12 @@ type event =
|
|
|
152
177
|
proofHash: string,
|
|
153
178
|
issuedAt: Reventless.DateTime.t,
|
|
154
179
|
})
|
|
155
|
-
| RegistrationProofAccepted({
|
|
180
|
+
| RegistrationProofAccepted({
|
|
181
|
+
email: ContactAddressId.t,
|
|
182
|
+
@pii({subject: "email"}) address: Reventless.Email.t,
|
|
183
|
+
roles: array<string>,
|
|
184
|
+
proofHash: string,
|
|
185
|
+
})
|
|
156
186
|
| RegistrationProofRefused({email: ContactAddressId.t, reason: string})
|
|
157
187
|
| RegistrationCompleted({email: ContactAddressId.t})
|
|
188
|
+
| RegistrationReleased({email: ContactAddressId.t, releasedAt: Reventless.DateTime.t})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Sury from "sury";
|
|
4
|
+
import * as Pii$Reventless from "@reventlessdev/reventless-spec/src/components/Pii.res.mjs";
|
|
4
5
|
import * as Role$Reventless from "@reventlessdev/reventless-spec/src/types/Role.res.mjs";
|
|
6
|
+
import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
|
|
5
7
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
6
8
|
import * as Api$ReventlessInfra from "@reventlessdev/reventless-infra/src/components/Api.res.mjs";
|
|
7
9
|
import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
|
|
@@ -20,6 +22,7 @@ let consumedEventSchema = Sury.union([
|
|
|
20
22
|
Sury.$schema(s => ({
|
|
21
23
|
TAG: "RegistrationRequested",
|
|
22
24
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
25
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
23
26
|
roles: s.m(Sury.array(Sury.string)),
|
|
24
27
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
25
28
|
})),
|
|
@@ -30,6 +33,7 @@ let consumedEventSchema = Sury.union([
|
|
|
30
33
|
Sury.$schema(s => ({
|
|
31
34
|
TAG: "RegistrationInvited",
|
|
32
35
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
36
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
33
37
|
roles: s.m(Sury.array(Sury.string)),
|
|
34
38
|
invitedBy: s.m(Sury.string),
|
|
35
39
|
invitedAt: s.m(DateTime$Reventless.schema)
|
|
@@ -37,6 +41,7 @@ let consumedEventSchema = Sury.union([
|
|
|
37
41
|
Sury.$schema(s => ({
|
|
38
42
|
TAG: "RegistrationChallengeReissued",
|
|
39
43
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
44
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
40
45
|
reissuedAt: s.m(DateTime$Reventless.schema),
|
|
41
46
|
invitedBy: s.m(Sury.$option(Sury.string))
|
|
42
47
|
})),
|
|
@@ -48,6 +53,7 @@ let consumedEventSchema = Sury.union([
|
|
|
48
53
|
Sury.$schema(s => ({
|
|
49
54
|
TAG: "RegistrationAttemptedOnTakenAddress",
|
|
50
55
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
56
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
51
57
|
attemptedAt: s.m(DateTime$Reventless.schema)
|
|
52
58
|
})),
|
|
53
59
|
Sury.$schema(s => ({
|
|
@@ -59,6 +65,7 @@ let consumedEventSchema = Sury.union([
|
|
|
59
65
|
Sury.$schema(s => ({
|
|
60
66
|
TAG: "RegistrationProofAccepted",
|
|
61
67
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
68
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
62
69
|
roles: s.m(Sury.array(Sury.string)),
|
|
63
70
|
proofHash: s.m(Sury.string)
|
|
64
71
|
})),
|
|
@@ -70,6 +77,11 @@ let consumedEventSchema = Sury.union([
|
|
|
70
77
|
Sury.$schema(s => ({
|
|
71
78
|
TAG: "RegistrationCompleted",
|
|
72
79
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
80
|
+
})),
|
|
81
|
+
Sury.$schema(s => ({
|
|
82
|
+
TAG: "RegistrationReleased",
|
|
83
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
84
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
73
85
|
}))
|
|
74
86
|
]);
|
|
75
87
|
|
|
@@ -77,6 +89,7 @@ let commandSchema = Sury.union([
|
|
|
77
89
|
Sury.$schema(s => ({
|
|
78
90
|
TAG: "Register",
|
|
79
91
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
92
|
+
address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
|
|
80
93
|
role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
|
|
81
94
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
82
95
|
})),
|
|
@@ -99,6 +112,7 @@ let commandSchema = Sury.union([
|
|
|
99
112
|
Sury.$schema(s => ({
|
|
100
113
|
TAG: "Invite",
|
|
101
114
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
115
|
+
address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
|
|
102
116
|
roles: s.m(Sury.array(Role$Reventless.nameSchema)),
|
|
103
117
|
invitedBy: s.m(Sury.string),
|
|
104
118
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
@@ -112,6 +126,11 @@ let commandSchema = Sury.union([
|
|
|
112
126
|
TAG: "WithdrawRegistration",
|
|
113
127
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
114
128
|
withdrawnAt: s.m(DateTime$Reventless.schema)
|
|
129
|
+
})),
|
|
130
|
+
Sury.$schema(s => ({
|
|
131
|
+
TAG: "ReleaseRegistration",
|
|
132
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
133
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
115
134
|
}))
|
|
116
135
|
]);
|
|
117
136
|
|
|
@@ -127,6 +146,7 @@ let eventSchema = Sury.union([
|
|
|
127
146
|
Sury.$schema(s => ({
|
|
128
147
|
TAG: "RegistrationRequested",
|
|
129
148
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
149
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
130
150
|
roles: s.m(Sury.array(Sury.string)),
|
|
131
151
|
requestedAt: s.m(DateTime$Reventless.schema)
|
|
132
152
|
})),
|
|
@@ -137,6 +157,7 @@ let eventSchema = Sury.union([
|
|
|
137
157
|
Sury.$schema(s => ({
|
|
138
158
|
TAG: "RegistrationInvited",
|
|
139
159
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
160
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
140
161
|
roles: s.m(Sury.array(Sury.string)),
|
|
141
162
|
invitedBy: s.m(Sury.string),
|
|
142
163
|
invitedAt: s.m(DateTime$Reventless.schema)
|
|
@@ -144,6 +165,7 @@ let eventSchema = Sury.union([
|
|
|
144
165
|
Sury.$schema(s => ({
|
|
145
166
|
TAG: "RegistrationChallengeReissued",
|
|
146
167
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
168
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
147
169
|
reissuedAt: s.m(DateTime$Reventless.schema),
|
|
148
170
|
invitedBy: s.m(Sury.$option(Sury.string))
|
|
149
171
|
})),
|
|
@@ -155,6 +177,7 @@ let eventSchema = Sury.union([
|
|
|
155
177
|
Sury.$schema(s => ({
|
|
156
178
|
TAG: "RegistrationAttemptedOnTakenAddress",
|
|
157
179
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
180
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
158
181
|
attemptedAt: s.m(DateTime$Reventless.schema)
|
|
159
182
|
})),
|
|
160
183
|
Sury.$schema(s => ({
|
|
@@ -166,6 +189,7 @@ let eventSchema = Sury.union([
|
|
|
166
189
|
Sury.$schema(s => ({
|
|
167
190
|
TAG: "RegistrationProofAccepted",
|
|
168
191
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
192
|
+
address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
|
|
169
193
|
roles: s.m(Sury.array(Sury.string)),
|
|
170
194
|
proofHash: s.m(Sury.string)
|
|
171
195
|
})),
|
|
@@ -177,6 +201,11 @@ let eventSchema = Sury.union([
|
|
|
177
201
|
Sury.$schema(s => ({
|
|
178
202
|
TAG: "RegistrationCompleted",
|
|
179
203
|
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema))
|
|
204
|
+
})),
|
|
205
|
+
Sury.$schema(s => ({
|
|
206
|
+
TAG: "RegistrationReleased",
|
|
207
|
+
email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
|
|
208
|
+
releasedAt: s.m(DateTime$Reventless.schema)
|
|
180
209
|
}))
|
|
181
210
|
]);
|
|
182
211
|
|
|
@@ -187,7 +216,8 @@ let commandSchema$1 = Api$ReventlessInfra.markNoApiVariants(commandSchema, [
|
|
|
187
216
|
"RecordRegistrationCompleted",
|
|
188
217
|
"Invite",
|
|
189
218
|
"ReissueRegistrationChallenge",
|
|
190
|
-
"WithdrawRegistration"
|
|
219
|
+
"WithdrawRegistration",
|
|
220
|
+
"ReleaseRegistration"
|
|
191
221
|
]);
|
|
192
222
|
|
|
193
223
|
function authorizationOf(param) {
|
|
@@ -17,6 +17,9 @@ type policyState =
|
|
|
17
17
|
| Open(option<Reventless.DateTime.t>)
|
|
18
18
|
|
|
19
19
|
type pending = {
|
|
20
|
+
/** The address the claim was made for: where its code goes, and what an
|
|
21
|
+
accepted proof makes an account for. */
|
|
22
|
+
address: Reventless.Pii.t<Reventless.Email.t>,
|
|
20
23
|
/** When the claim was made, or its code last reissued: what a claim with no
|
|
21
24
|
challenge out lapses from. */
|
|
22
25
|
requestedAt: Reventless.DateTime.t,
|
|
@@ -50,6 +53,12 @@ let initialState = {admission: Unset, stage: Unclaimed, lastNoticeAt: None}
|
|
|
50
53
|
so the door cannot be used to flood a registered person's inbox. */
|
|
51
54
|
let noticeCooldown = 3600
|
|
52
55
|
|
|
56
|
+
/** The contact a challenge is held against. The guards only compare it, so the
|
|
57
|
+
ledger's id for the address serves, and no address is needed to decide. */
|
|
58
|
+
let contactOf = (email: ContactAddressId.t): ContactVerification.contact => ByEmail(
|
|
59
|
+
Reventless.Email.unsafe(email->ContactAddressId.toString),
|
|
60
|
+
)
|
|
61
|
+
|
|
53
62
|
let purposeOf = (p: pending) => RegistrationChallenge.purposeOf(~invitedBy=p.invitedBy)
|
|
54
63
|
|
|
55
64
|
/** The challenge rules a pending registration is held to: an invitation's code
|
|
@@ -60,13 +69,20 @@ let evolve = (state, event) =>
|
|
|
60
69
|
switch event {
|
|
61
70
|
| RegistrationOpened({?until}) => {...state, admission: Open(until)}
|
|
62
71
|
| RegistrationClosed(_) => {...state, admission: Closed}
|
|
63
|
-
| RegistrationRequested({roles, requestedAt}) => {
|
|
72
|
+
| RegistrationRequested({address, roles, requestedAt}) => {
|
|
64
73
|
...state,
|
|
65
|
-
stage: Pending({requestedAt, roles, challenge: None, proofHash: None}),
|
|
74
|
+
stage: Pending({address, requestedAt, roles, challenge: None, proofHash: None}),
|
|
66
75
|
}
|
|
67
|
-
| RegistrationInvited({roles, invitedBy, invitedAt}) => {
|
|
76
|
+
| RegistrationInvited({address, roles, invitedBy, invitedAt}) => {
|
|
68
77
|
...state,
|
|
69
|
-
stage: Pending({
|
|
78
|
+
stage: Pending({
|
|
79
|
+
address,
|
|
80
|
+
requestedAt: invitedAt,
|
|
81
|
+
roles,
|
|
82
|
+
invitedBy,
|
|
83
|
+
challenge: None,
|
|
84
|
+
proofHash: None,
|
|
85
|
+
}),
|
|
70
86
|
}
|
|
71
87
|
| RegistrationExpired(_) | RegistrationWithdrawn(_) => {...state, stage: Unclaimed}
|
|
72
88
|
| RegistrationAttemptedOnTakenAddress({attemptedAt}) => {
|
|
@@ -80,7 +96,7 @@ let evolve = (state, event) =>
|
|
|
80
96
|
stage: Pending({
|
|
81
97
|
...p,
|
|
82
98
|
challenge: Some({
|
|
83
|
-
contact:
|
|
99
|
+
contact: contactOf(email),
|
|
84
100
|
purpose: purposeOf(p),
|
|
85
101
|
issuedAt,
|
|
86
102
|
attempts: 0,
|
|
@@ -112,6 +128,9 @@ let evolve = (state, event) =>
|
|
|
112
128
|
}
|
|
113
129
|
| RegistrationProofAccepted(_) => {...state, stage: Verified}
|
|
114
130
|
| RegistrationCompleted(_) => {...state, stage: Completed}
|
|
131
|
+
// The account was erased: the address is nobody's, and nobody was told of an
|
|
132
|
+
// attempt on it.
|
|
133
|
+
| RegistrationReleased(_) => {...state, stage: Unclaimed, lastNoticeAt: None}
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
/** Whether the policy admits a registration for `role` that arrived at `at`.
|
|
@@ -166,7 +185,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
166
185
|
// decision: the policy is consulted before the address, so a closed
|
|
167
186
|
// deployment sends nothing — not even the notice to an address that is
|
|
168
187
|
// already registered.
|
|
169
|
-
| Register({email, role, requestedAt}) =>
|
|
188
|
+
| Register({email, address, role, requestedAt}) =>
|
|
170
189
|
if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt) {
|
|
171
190
|
Ok([])
|
|
172
191
|
} else {
|
|
@@ -177,7 +196,14 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
177
196
|
switch state.lastNoticeAt {
|
|
178
197
|
| Some(last) if Guards.elapsedSeconds(~from=last, ~to_=requestedAt) < noticeCooldown =>
|
|
179
198
|
Ok([])
|
|
180
|
-
| _ =>
|
|
199
|
+
| _ =>
|
|
200
|
+
Ok([
|
|
201
|
+
RegistrationAttemptedOnTakenAddress({
|
|
202
|
+
email,
|
|
203
|
+
address: Value(address),
|
|
204
|
+
attemptedAt: requestedAt,
|
|
205
|
+
}),
|
|
206
|
+
])
|
|
181
207
|
}
|
|
182
208
|
| Verified => Ok([])
|
|
183
209
|
// A visitor cannot take over a claim, an inviter's included, while it holds.
|
|
@@ -185,22 +211,24 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
185
211
|
| Pending(_) =>
|
|
186
212
|
Ok([
|
|
187
213
|
RegistrationExpired({email: email}),
|
|
188
|
-
RegistrationRequested({email, roles, requestedAt}),
|
|
214
|
+
RegistrationRequested({email, address: Value(address), roles, requestedAt}),
|
|
189
215
|
])
|
|
190
|
-
| Unclaimed =>
|
|
216
|
+
| Unclaimed =>
|
|
217
|
+
Ok([RegistrationRequested({email, address: Value(address), roles, requestedAt})])
|
|
191
218
|
}
|
|
192
219
|
}
|
|
193
220
|
|
|
194
221
|
// The policy is not consulted: it says whether visitors may sign themselves
|
|
195
222
|
// up, and an invitation is not that. The table is, because it is the hard
|
|
196
223
|
// cap on how each role is admitted.
|
|
197
|
-
| Invite({email, roles, invitedBy, requestedAt}) =>
|
|
224
|
+
| Invite({email, address, roles, invitedBy, requestedAt}) =>
|
|
198
225
|
switch roles->Array.find(r => !isByInvitation(App.table, r)) {
|
|
199
226
|
| Some(role) => Error(NotByInvitation({role: (role :> string)}))
|
|
200
227
|
| None if roles == [] => Error(NoRoleToGrant)
|
|
201
228
|
| None =>
|
|
202
229
|
let invited = RegistrationInvited({
|
|
203
230
|
email,
|
|
231
|
+
address: Value(address),
|
|
204
232
|
roles: roles->Array.map(r => (r :> string)),
|
|
205
233
|
invitedBy,
|
|
206
234
|
invitedAt: requestedAt,
|
|
@@ -219,7 +247,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
219
247
|
switch state.stage {
|
|
220
248
|
| Pending(p) =>
|
|
221
249
|
switch Guards.onIssueRequested(
|
|
222
|
-
~contact=
|
|
250
|
+
~contact=contactOf(email),
|
|
223
251
|
~existing=p.challenge,
|
|
224
252
|
~now=issuedAt,
|
|
225
253
|
~policy=policyOf(p),
|
|
@@ -242,7 +270,12 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
242
270
|
if Guards.elapsedSeconds(~from=c.issuedAt, ~to_=requestedAt) >=
|
|
243
271
|
policyOf(p).resendCooldown =>
|
|
244
272
|
Ok([
|
|
245
|
-
RegistrationChallengeReissued({
|
|
273
|
+
RegistrationChallengeReissued({
|
|
274
|
+
email,
|
|
275
|
+
address: p.address,
|
|
276
|
+
reissuedAt: requestedAt,
|
|
277
|
+
invitedBy: ?p.invitedBy,
|
|
278
|
+
}),
|
|
246
279
|
])
|
|
247
280
|
| _ => Ok([])
|
|
248
281
|
}
|
|
@@ -257,7 +290,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
257
290
|
~now=presentedAt,
|
|
258
291
|
~policy=policyOf(p),
|
|
259
292
|
) {
|
|
260
|
-
| Settle => Ok([RegistrationProofAccepted({email, roles, proofHash})])
|
|
293
|
+
| Settle => Ok([RegistrationProofAccepted({email, address: p.address, roles, proofHash})])
|
|
261
294
|
| Refuse(reason) => Ok([RegistrationProofRefused({email, reason: refusalReason(reason)})])
|
|
262
295
|
}
|
|
263
296
|
// No challenge to answer: nothing to count it against, and nothing to say.
|
|
@@ -272,6 +305,14 @@ module Make = (App: Reventless.Admission.Declaration) => {
|
|
|
272
305
|
| Unclaimed | Verified | Completed => Ok([])
|
|
273
306
|
}
|
|
274
307
|
|
|
308
|
+
// Only an account: a claim nobody proved is withdrawn, and one being turned
|
|
309
|
+
// into an account is released once the account exists and is erased.
|
|
310
|
+
| ReleaseRegistration({email, releasedAt}) =>
|
|
311
|
+
switch state.stage {
|
|
312
|
+
| Completed => Ok([RegistrationReleased({email, releasedAt})])
|
|
313
|
+
| Unclaimed | Pending(_) | Verified => Ok([])
|
|
314
|
+
}
|
|
315
|
+
|
|
275
316
|
| RecordRegistrationCompleted({email}) =>
|
|
276
317
|
switch state.stage {
|
|
277
318
|
| Verified => Ok([RegistrationCompleted({email: email})])
|