@reventlessdev/reventless-registration 1.0.0-alpha.1 → 1.0.0-alpha.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.
Files changed (23) hide show
  1. package/package.json +4 -4
  2. package/src/Registration/ContactAddressId.res +27 -3
  3. package/src/Registration/ContactAddressId.res.mjs +26 -2
  4. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +9 -6
  5. package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +16 -9
  6. package/src/Registration/InboundTranslation/SignUp.res +1 -0
  7. package/src/Registration/InboundTranslation/SignUp.res.mjs +3 -0
  8. package/src/Registration/InboundTranslation/SignUp_Translation.res +23 -12
  9. package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +13 -4
  10. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +7 -1
  11. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +4 -0
  12. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +6 -3
  13. package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +11 -2
  14. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +32 -5
  15. package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +10 -1
  16. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +30 -18
  17. package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +86 -36
  18. package/src/Registration/StateChange/Registrations.res +28 -2
  19. package/src/Registration/StateChange/Registrations.res.mjs +14 -0
  20. package/src/Registration/StateChange/Registrations_Decision.res +43 -13
  21. package/src/Registration/StateChange/Registrations_Decision.res.mjs +45 -26
  22. package/src/Registration/StateViewStream/RegistrationWindows.res +3 -0
  23. package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-registration",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
4
4
  "description": "Self-registration as a library of slices: a person with no account proves control of an address and ends up with one, admitted per role as the app declares",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
@@ -13,9 +13,9 @@
13
13
  "dependencies": {
14
14
  "sury": "11.0.0",
15
15
  "sury-ppx": "11.0.0",
16
- "@reventlessdev/reventless-spec": "3.0.0-alpha.176",
17
- "@reventlessdev/reventless-ppx": "1.0.0-alpha.107",
18
- "@reventlessdev/reventless-infra": "3.0.0-alpha.205"
16
+ "@reventlessdev/reventless-ppx": "1.0.0-alpha.108",
17
+ "@reventlessdev/reventless-spec": "3.0.0-alpha.185",
18
+ "@reventlessdev/reventless-infra": "3.0.0-alpha.214"
19
19
  },
20
20
  "devDependencies": {
21
21
  "rescript": "12.3.1"
@@ -1,6 +1,30 @@
1
- // The address a registration claims: the partition the registration ledger
2
- // decides about, and the tag that makes "this address is taken" one fact on
3
- // every platform. Its value is the address itself, lower-cased.
1
+ // The address a registration claims, as the ledger knows it: the partition it
2
+ // decides about, and the tag that makes "this address is taken" one fact on every
3
+ // platform.
4
+ //
5
+ // Its value is a keyed fingerprint of the lower-cased address, never the address.
6
+ // A tag is an index key, and an index key cannot be encrypted or erased, so the
7
+ // address itself is carried beside it in a field of its own on the events that
8
+ // must reach the person. The key is the deployment's (`secrets.fingerprint`) and
9
+ // is never rotated: rotating it would orphan every registration recorded under
10
+ // the old one.
4
11
  include Reventless.Id.Make({
5
12
  let key = "contactAddress"
6
13
  })
14
+
15
+ /** What the fingerprint is taken under, so no other use of the deployment's key
16
+ can produce the same value for an address. */
17
+ let purpose = "contactAddress"
18
+
19
+ /** The form every door takes the fingerprint of: an address differing only in
20
+ case or surrounding spaces is the same registration. */
21
+ let normalize = (address: Reventless.Email.t): Reventless.Email.t =>
22
+ address->Reventless.Email.toString->String.trim->String.toLowerCase->Reventless.Email.unsafe
23
+
24
+ /** The ledger's id for an address. Refused, never degraded to the address, when
25
+ the deployment holds no key. */
26
+ let fingerprint = (secrets: Reventless.Secrets.t, address: Reventless.Email.t): result<t, string> =>
27
+ switch secrets.fingerprint(~purpose, address->normalize->Reventless.Email.toString) {
28
+ | Ok(value) => Ok(makeFromString(value))
29
+ | Error(Unavailable(why)) => Error(`cannot fingerprint the address: ${why}`)
30
+ }
@@ -6,12 +6,33 @@ let include = Id$Reventless.Make({
6
6
  key: "contactAddress"
7
7
  });
8
8
 
9
+ let makeFromString = include.makeFromString;
10
+
11
+ let purpose = "contactAddress";
12
+
13
+ function normalize(address) {
14
+ return address.trim().toLowerCase();
15
+ }
16
+
17
+ function fingerprint(secrets, address) {
18
+ let value = secrets.fingerprint(purpose, address.trim().toLowerCase());
19
+ if (value.TAG === "Ok") {
20
+ return {
21
+ TAG: "Ok",
22
+ _0: makeFromString(value._0)
23
+ };
24
+ } else {
25
+ return {
26
+ TAG: "Error",
27
+ _0: `cannot fingerprint the address: ` + value._0._0
28
+ };
29
+ }
30
+ }
31
+
9
32
  let schema = include.schema;
10
33
 
11
34
  let make = include.make;
12
35
 
13
- let makeFromString = include.makeFromString;
14
-
15
36
  let toString = include.toString;
16
37
 
17
38
  let cmp = include.cmp;
@@ -25,5 +46,8 @@ export {
25
46
  toString,
26
47
  cmp,
27
48
  key,
49
+ purpose,
50
+ normalize,
51
+ fingerprint,
28
52
  }
29
53
  /* include Not a pure module */
@@ -17,19 +17,22 @@ let translate = async (
17
17
  | Ok(_) if input.password->String.length < minimumPasswordLength =>
18
18
  Error(`a password needs at least ${minimumPasswordLength->Int.toString} characters`)
19
19
  | Ok(email) =>
20
- let email = email->Reventless.Email.toString->String.toLowerCase
21
- switch capabilities.secrets.hash(input.proof->String.trim) {
22
- | Error(Unavailable(why)) => Error(`cannot hash the proof: ${why}`)
23
- | Ok(proofHash) =>
20
+ switch (
21
+ ContactAddressId.fingerprint(capabilities.secrets, email),
22
+ capabilities.secrets.hash(input.proof->String.trim),
23
+ ) {
24
+ | (Error(why), _) => Error(why)
25
+ | (_, Error(Unavailable(why))) => Error(`cannot hash the proof: ${why}`)
26
+ | (Ok(id), Ok(proofHash)) =>
24
27
  switch await capabilities.stash.put(~key=proofHash, ~value=input.password, ~ttl=passwordTtl) {
25
28
  | Error(failure) =>
26
29
  Error(`cannot hold the password: ${failure->Reventless.Stash.failureReason}`)
27
30
  | Ok() =>
28
31
  Ok([
29
32
  (
30
- email,
33
+ id->ContactAddressId.toString,
31
34
  SubmitRegistrationProof({
32
- email: ContactAddressId.makeFromString(email),
35
+ email: id,
33
36
  proofHash,
34
37
  presentedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
35
38
  }),
@@ -18,25 +18,32 @@ async function translate(input, capabilities, param) {
18
18
  _0: `a password needs at least ` + (12).toString() + ` characters`
19
19
  };
20
20
  }
21
- let email$1 = email._0.toLowerCase();
22
- let proofHash = capabilities.secrets.hash(input.proof.trim());
23
- if (proofHash.TAG !== "Ok") {
21
+ let match = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, email._0);
22
+ let match$1 = capabilities.secrets.hash(input.proof.trim());
23
+ if (match.TAG !== "Ok") {
24
24
  return {
25
25
  TAG: "Error",
26
- _0: `cannot hash the proof: ` + proofHash._0._0
26
+ _0: match._0
27
27
  };
28
28
  }
29
- let proofHash$1 = proofHash._0;
30
- let failure = await capabilities.stash.put(proofHash$1, input.password, 600);
29
+ let id = match._0;
30
+ if (match$1.TAG !== "Ok") {
31
+ return {
32
+ TAG: "Error",
33
+ _0: `cannot hash the proof: ` + match$1._0._0
34
+ };
35
+ }
36
+ let proofHash = match$1._0;
37
+ let failure = await capabilities.stash.put(proofHash, input.password, 600);
31
38
  if (failure.TAG === "Ok") {
32
39
  return {
33
40
  TAG: "Ok",
34
41
  _0: [[
35
- email$1,
42
+ ContactAddressId$ReventlessRegistration.toString(id),
36
43
  {
37
44
  TAG: "SubmitRegistrationProof",
38
- email: ContactAddressId$ReventlessRegistration.makeFromString(email$1),
39
- proofHash: proofHash$1,
45
+ email: id,
46
+ proofHash: proofHash,
40
47
  presentedAt: new Date().toISOString()
41
48
  }
42
49
  ]]
@@ -24,6 +24,7 @@ type externalInput = {email: string, role?: string}
24
24
  type command =
25
25
  | Register({
26
26
  email: ContactAddressId.t,
27
+ @pii({subject: "email"}) address: Reventless.Email.t,
27
28
  role: Reventless.Role.name,
28
29
  requestedAt: Reventless.DateTime.t,
29
30
  })
@@ -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 DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
7
9
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
@@ -14,6 +16,7 @@ let externalInputSchema = Sury.$schema(s => ({
14
16
  let commandSchema = Sury.$schema(s => ({
15
17
  TAG: "Register",
16
18
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
19
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
17
20
  role: s.m(Role$Reventless.nameSchema),
18
21
  requestedAt: s.m(DateTime$Reventless.schema)
19
22
  }));
@@ -13,7 +13,11 @@ module Make = (App: Reventless.Admission.Declaration) => {
13
13
  module Spec = Spec
14
14
  let moduleUrl = moduleUrl
15
15
 
16
- let translate = async (input: externalInput, ~capabilities as _, ~caller as _) =>
16
+ let translate = async (
17
+ input: externalInput,
18
+ ~capabilities: Reventless.Capabilities.t,
19
+ ~caller as _,
20
+ ) =>
17
21
  switch (Reventless.Email.fromString(input.email->String.trim), input.role) {
18
22
  | (Error(_), _) => Error("not an email address")
19
23
  | (Ok(email), role) =>
@@ -24,17 +28,24 @@ module Make = (App: Reventless.Admission.Declaration) => {
24
28
  ->Option.orElse(defaultRole(App.table)) {
25
29
  | None => Error("say which role to sign up for")
26
30
  | Some(role) =>
27
- let email = email->Reventless.Email.toString->String.toLowerCase
28
- Ok([
29
- (
30
- email,
31
- Register({
32
- email: ContactAddressId.makeFromString(email),
33
- role,
34
- requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
35
- }),
36
- ),
37
- ])
31
+ let address = email->ContactAddressId.normalize
32
+ switch ContactAddressId.fingerprint(capabilities.secrets, address) {
33
+ | Error(why) => Error(why)
34
+ | Ok(id) =>
35
+ // The envelope id is the fingerprint too: an id is stored beside the
36
+ // event, where the address must not be.
37
+ Ok([
38
+ (
39
+ id->ContactAddressId.toString,
40
+ Register({
41
+ email: id,
42
+ address,
43
+ role,
44
+ requestedAt: Date.make()->Date.toISOString->Reventless.DateTime.unsafe,
45
+ }),
46
+ ),
47
+ ])
48
+ }
38
49
  }
39
50
  }
40
51
  }
@@ -16,7 +16,7 @@ function defaultRole(table) {
16
16
  }
17
17
 
18
18
  function Make(App) {
19
- let translate = async (input, param, param$1) => {
19
+ let translate = async (input, capabilities, param) => {
20
20
  let match = Email$Reventless.fromString(input.email.trim());
21
21
  let match$1 = input.role;
22
22
  if (match.TAG !== "Ok") {
@@ -32,14 +32,23 @@ function Make(App) {
32
32
  _0: "say which role to sign up for"
33
33
  };
34
34
  }
35
- let email = match._0.toLowerCase();
35
+ let address = ContactAddressId$ReventlessRegistration.normalize(match._0);
36
+ let why = ContactAddressId$ReventlessRegistration.fingerprint(capabilities.secrets, address);
37
+ if (why.TAG !== "Ok") {
38
+ return {
39
+ TAG: "Error",
40
+ _0: why._0
41
+ };
42
+ }
43
+ let id = why._0;
36
44
  return {
37
45
  TAG: "Ok",
38
46
  _0: [[
39
- email,
47
+ ContactAddressId$ReventlessRegistration.toString(id),
40
48
  {
41
49
  TAG: "Register",
42
- email: ContactAddressId$ReventlessRegistration.makeFromString(email),
50
+ email: id,
51
+ address: address,
43
52
  role: role,
44
53
  requestedAt: new Date().toISOString()
45
54
  }
@@ -16,12 +16,18 @@
16
16
  type consumedEvent =
17
17
  | RegistrationProofAccepted({
18
18
  email: string,
19
+ @pii({subject: "email"}) address: Reventless.Email.t,
19
20
  roles: array<Reventless.Role.name>,
20
21
  proofHash: string,
21
22
  })
22
23
 
23
24
  @schema
24
- type outboundItem = {email: string, roles: array<Reventless.Role.name>, proofHash: string}
25
+ type outboundItem = {
26
+ email: string,
27
+ @pii({subject: "email"}) address: Reventless.Email.t,
28
+ roles: array<Reventless.Role.name>,
29
+ proofHash: string,
30
+ }
25
31
 
26
32
  @schema
27
33
  type inboundCommand = RecordRegistrationCompleted({email: ContactAddressId.t})
@@ -1,19 +1,23 @@
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 ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
7
9
 
8
10
  let consumedEventSchema = Sury.$schema(s => ({
9
11
  TAG: "RegistrationProofAccepted",
10
12
  email: s.m(Sury.string),
13
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
11
14
  roles: s.m(Sury.array(Role$Reventless.nameSchema)),
12
15
  proofHash: s.m(Sury.string)
13
16
  }));
14
17
 
15
18
  let outboundItemSchema = Sury.$schema(s => ({
16
19
  email: s.m(Sury.string),
20
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
17
21
  roles: s.m(Sury.array(Role$Reventless.nameSchema)),
18
22
  proofHash: s.m(Sury.string)
19
23
  }));
@@ -9,11 +9,14 @@ let retryTtl = 600
9
9
 
10
10
  let collect = (event, ~sourceId as _) =>
11
11
  switch event {
12
- | RegistrationProofAccepted({email, roles, proofHash}) => [
13
- (`${email}:${proofHash}`, {email, roles, proofHash}),
12
+ | RegistrationProofAccepted({email, address: Value(address), roles, proofHash}) => [
13
+ (`${email}:${proofHash}`, {email, address, roles, proofHash}),
14
14
  ]
15
+ // An address that was erased or forgotten has nobody left to write to.
16
+ | _ => []
15
17
  }
16
18
 
19
+ // `email` is already the ledger's id for the address: no key is needed to say so.
17
20
  let completed = (email: string) => Ok(
18
21
  Some((email, RecordRegistrationCompleted({email: ContactAddressId.makeFromString(email)}))),
19
22
  )
@@ -26,7 +29,7 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
26
29
  | Ok(None) => Error("the password expired before the account was made")
27
30
  | Ok(Some(password)) =>
28
31
  switch await capabilities.identityProvider.createPrincipal(
29
- ~contact=ToEmail(Reventless.Email.unsafe(item.email)),
32
+ ~contact=ToEmail(item.address),
30
33
  ~credential=Password(password),
31
34
  ~groups=groupsOf(item.roles),
32
35
  ) {
@@ -9,12 +9,21 @@ function groupsOf(roles) {
9
9
  }
10
10
 
11
11
  function collect(event, param) {
12
- let proofHash = event.proofHash;
12
+ let address = event.address;
13
13
  let email = event.email;
14
+ if (typeof address !== "object") {
15
+ if (address === "Erased") {
16
+ return [];
17
+ } else {
18
+ return [];
19
+ }
20
+ }
21
+ let proofHash = event.proofHash;
14
22
  return [[
15
23
  email + `:` + proofHash,
16
24
  {
17
25
  email: email,
26
+ address: address._0,
18
27
  roles: event.roles,
19
28
  proofHash: proofHash
20
29
  }
@@ -51,7 +60,7 @@ async function translate(_id, item, capabilities) {
51
60
  }
52
61
  let match = await capabilities.identityProvider.createPrincipal({
53
62
  TAG: "ToEmail",
54
- _0: item.email
63
+ _0: item.address
55
64
  }, {
56
65
  TAG: "Password",
57
66
  _0: password
@@ -1,5 +1,8 @@
1
1
  // SendRegistrationChallenge OutboundTranslationSlice.
2
2
  //
3
+ // Writes to the address a registration names. Work is keyed by the ledger's id
4
+ // for the address, its fingerprint, never by the address.
5
+ //
3
6
  // Writes to the address a registration names. A fresh registration gets a
4
7
  // secret to prove control of the address, and the ledger records its hash; an
5
8
  // invitation gets one too, worded as an invitation and holding for a week; a
@@ -15,19 +18,43 @@
15
18
 
16
19
  @schema
17
20
  type consumedEvent =
18
- | RegistrationRequested({email: string, requestedAt: Reventless.DateTime.t})
19
- | RegistrationAttemptedOnTakenAddress({email: string, attemptedAt: Reventless.DateTime.t})
20
- | RegistrationInvited({email: string, invitedBy: string, invitedAt: Reventless.DateTime.t})
21
+ | RegistrationRequested({
22
+ email: string,
23
+ @pii({subject: "email"}) address: Reventless.Email.t,
24
+ requestedAt: Reventless.DateTime.t,
25
+ })
26
+ | RegistrationAttemptedOnTakenAddress({
27
+ email: string,
28
+ @pii({subject: "email"}) address: Reventless.Email.t,
29
+ attemptedAt: Reventless.DateTime.t,
30
+ })
31
+ | RegistrationInvited({
32
+ email: string,
33
+ @pii({subject: "email"}) address: Reventless.Email.t,
34
+ roles: array<string>,
35
+ invitedBy: string,
36
+ invitedAt: Reventless.DateTime.t,
37
+ })
21
38
  | RegistrationChallengeReissued({
22
39
  email: string,
40
+ @pii({subject: "email"}) address: Reventless.Email.t,
23
41
  reissuedAt: Reventless.DateTime.t,
24
42
  invitedBy?: string,
25
43
  })
26
44
 
45
+ // `email` is the ledger's id for the address, `address` the address the mail goes to.
46
+
27
47
  /** `invited` words the secret as an invitation; it is left out for a sign-up
28
- and for the notice. */
48
+ and for the notice. `roles` names what the invitation grants, where the
49
+ event said: a reissued code does not. */
29
50
  @schema
30
- type outboundItem = {email: string, alreadyRegistered: bool, invited?: bool}
51
+ type outboundItem = {
52
+ email: string,
53
+ @pii({subject: "email"}) address: Reventless.Email.t,
54
+ alreadyRegistered: bool,
55
+ invited?: bool,
56
+ roles?: array<string>,
57
+ }
31
58
 
32
59
  @schema
33
60
  type inboundCommand =
@@ -1,6 +1,8 @@
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";
5
+ import * as Email$Reventless from "@reventlessdev/reventless-spec/src/semantic/Email.res.mjs";
4
6
  import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
5
7
  import * as DateTime$Reventless from "@reventlessdev/reventless-spec/src/semantic/DateTime.res.mjs";
6
8
  import * as ContactAddressId$ReventlessRegistration from "../ContactAddressId.res.mjs";
@@ -9,22 +11,27 @@ let consumedEventSchema = Sury.union([
9
11
  Sury.$schema(s => ({
10
12
  TAG: "RegistrationRequested",
11
13
  email: s.m(Sury.string),
14
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
12
15
  requestedAt: s.m(DateTime$Reventless.schema)
13
16
  })),
14
17
  Sury.$schema(s => ({
15
18
  TAG: "RegistrationAttemptedOnTakenAddress",
16
19
  email: s.m(Sury.string),
20
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
17
21
  attemptedAt: s.m(DateTime$Reventless.schema)
18
22
  })),
19
23
  Sury.$schema(s => ({
20
24
  TAG: "RegistrationInvited",
21
25
  email: s.m(Sury.string),
26
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
27
+ roles: s.m(Sury.array(Sury.string)),
22
28
  invitedBy: s.m(Sury.string),
23
29
  invitedAt: s.m(DateTime$Reventless.schema)
24
30
  })),
25
31
  Sury.$schema(s => ({
26
32
  TAG: "RegistrationChallengeReissued",
27
33
  email: s.m(Sury.string),
34
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
28
35
  reissuedAt: s.m(DateTime$Reventless.schema),
29
36
  invitedBy: s.m(Sury.$option(Sury.string))
30
37
  }))
@@ -32,8 +39,10 @@ let consumedEventSchema = Sury.union([
32
39
 
33
40
  let outboundItemSchema = Sury.$schema(s => ({
34
41
  email: s.m(Sury.string),
42
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
35
43
  alreadyRegistered: s.m(Sury.boolean),
36
- invited: s.m(Sury.$option(Sury.boolean))
44
+ invited: s.m(Sury.$option(Sury.boolean)),
45
+ roles: s.m(Sury.$option(Sury.array(Sury.string)))
37
46
  }));
38
47
 
39
48
  let inboundCommandSchema = Sury.$schema(s => ({
@@ -4,27 +4,32 @@
4
4
  // or a code reissued, is new work rather than work already done.
5
5
  let collect = (event, ~sourceId as _) =>
6
6
  switch event {
7
- | RegistrationRequested({email, requestedAt}) => [
8
- (`${email}:${requestedAt->Reventless.DateTime.toString}`, {email, alreadyRegistered: false}),
7
+ | RegistrationRequested({email, address: Value(address), requestedAt}) => [
8
+ (
9
+ `${email}:${requestedAt->Reventless.DateTime.toString}`,
10
+ {email, address, alreadyRegistered: false},
11
+ ),
9
12
  ]
10
- | RegistrationInvited({email, invitedAt}) => [
13
+ | RegistrationInvited({email, address: Value(address), roles, invitedAt}) => [
11
14
  (
12
15
  `${email}:invited:${invitedAt->Reventless.DateTime.toString}`,
13
- {email, alreadyRegistered: false, invited: true},
16
+ {email, address, alreadyRegistered: false, invited: true, roles},
14
17
  ),
15
18
  ]
16
- | RegistrationChallengeReissued({email, reissuedAt, ?invitedBy}) => [
19
+ | RegistrationChallengeReissued({email, address: Value(address), reissuedAt, ?invitedBy}) => [
17
20
  (
18
21
  `${email}:reissued:${reissuedAt->Reventless.DateTime.toString}`,
19
- {email, alreadyRegistered: false, invited: invitedBy->Option.isSome},
22
+ {email, address, alreadyRegistered: false, invited: invitedBy->Option.isSome},
20
23
  ),
21
24
  ]
22
- | RegistrationAttemptedOnTakenAddress({email, attemptedAt}) => [
25
+ | RegistrationAttemptedOnTakenAddress({email, address: Value(address), attemptedAt}) => [
23
26
  (
24
27
  `${email}:taken:${attemptedAt->Reventless.DateTime.toString}`,
25
- {email, alreadyRegistered: true},
28
+ {email, address, alreadyRegistered: true},
26
29
  ),
27
30
  ]
31
+ // An address that was erased or forgotten has nobody left to write to.
32
+ | _ => []
28
33
  }
29
34
 
30
35
  let expiresIn = (~invited) =>
@@ -37,18 +42,25 @@ let challengeBody = (~token) =>
37
42
  ~invited=false,
38
43
  )}.`
39
44
 
40
- let invitationBody = (~token) =>
41
- `You have been invited to create an account. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
45
+ /** What the invitation grants, as the mail says it: "as Merchandiser", or
46
+ nothing where the event did not say. */
47
+ let asRoles = (roles: option<array<string>>) =>
48
+ switch roles {
49
+ | Some([]) | None => ""
50
+ | Some(roles) => ` as ${roles->Array.join(" and ")}`
51
+ }
52
+
53
+ let invitationBody = (~token, ~roles=?) =>
54
+ `You have been invited to create an account${asRoles(
55
+ roles,
56
+ )}. Your code is ${token}. Enter it with this address and a password of your choice to accept. It expires in ${expiresIn(
42
57
  ~invited=true,
43
58
  )}.`
44
59
 
45
60
  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."
46
61
 
47
- let send = (capabilities: Reventless.Capabilities.t, ~email, ~subject, ~body) =>
48
- capabilities.messaging.send(
49
- ~recipient=ToEmail(Reventless.Email.unsafe(email)),
50
- ~message={subject, body},
51
- )
62
+ let send = (capabilities: Reventless.Capabilities.t, ~address, ~subject, ~body) =>
63
+ capabilities.messaging.send(~recipient=ToEmail(address), ~message={subject, body})
52
64
 
53
65
  /**
54
66
  Draw a secret, send it, and open a challenge against its hash — sending first,
@@ -58,7 +70,7 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
58
70
  if item.alreadyRegistered {
59
71
  switch await send(
60
72
  capabilities,
61
- ~email=item.email,
73
+ ~address=item.address,
62
74
  ~subject="Someone tried to register with your address",
63
75
  ~body=noticeBody,
64
76
  ) {
@@ -79,9 +91,9 @@ let translate = async (_id, item: outboundItem, ~capabilities: Reventless.Capabi
79
91
  | Ok(proofHash) =>
80
92
  switch await send(
81
93
  capabilities,
82
- ~email=item.email,
94
+ ~address=item.address,
83
95
  ~subject=invited ? "You are invited to create an account" : "Finish your registration",
84
- ~body=invited ? invitationBody(~token) : challengeBody(~token),
96
+ ~body=invited ? invitationBody(~token, ~roles=?item.roles) : challengeBody(~token),
85
97
  ) {
86
98
  | Ok(_) =>
87
99
  Ok(
@@ -9,43 +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
- return [[
14
- email + `:` + event.requestedAt,
15
- {
16
- email: email,
17
- alreadyRegistered: false
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
- return [[
23
- email$1 + `:taken:` + event.attemptedAt,
24
- {
25
- email: email$1,
26
- alreadyRegistered: true
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
- return [[
32
- email$2 + `:invited:` + event.invitedAt,
33
- {
34
- email: email$2,
35
- alreadyRegistered: false,
36
- invited: true
37
- }
38
- ]];
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
+ }
39
70
  case "RegistrationChallengeReissued" :
71
+ let address$3 = event.address;
40
72
  let email$3 = event.email;
41
- return [[
42
- email$3 + `:reissued:` + event.reissuedAt,
43
- {
44
- email: email$3,
45
- alreadyRegistered: false,
46
- invited: Stdlib_Option.isSome(event.invitedBy)
47
- }
48
- ]];
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
+ }
49
90
  }
50
91
  }
51
92
 
@@ -57,16 +98,24 @@ function challengeBody(token) {
57
98
  return `Your registration code is ` + token + `. Enter it with a password of your choice to finish. It expires in ` + expiresIn(false) + `.`;
58
99
  }
59
100
 
60
- function invitationBody(token) {
61
- return `You have been invited to create an account. Your code is ` + token + `. Enter it with this address and a password of your choice to accept. It expires in ` + expiresIn(true) + `.`;
101
+ function asRoles(roles) {
102
+ if (roles !== undefined && roles.length !== 0) {
103
+ return ` as ` + roles.join(" and ");
104
+ } else {
105
+ return "";
106
+ }
107
+ }
108
+
109
+ function invitationBody(token, roles) {
110
+ return `You have been invited to create an account` + asRoles(roles) + `. Your code is ` + token + `. Enter it with this address and a password of your choice to accept. It expires in ` + expiresIn(true) + `.`;
62
111
  }
63
112
 
64
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.";
65
114
 
66
- function send(capabilities, email, subject, body) {
115
+ function send(capabilities, address, subject, body) {
67
116
  return capabilities.messaging.send({
68
117
  TAG: "ToEmail",
69
- _0: email
118
+ _0: address
70
119
  }, {
71
120
  subject: subject,
72
121
  body: body
@@ -75,7 +124,7 @@ function send(capabilities, email, subject, body) {
75
124
 
76
125
  async function translate(_id, item, capabilities) {
77
126
  if (item.alreadyRegistered) {
78
- let failure = await send(capabilities, item.email, "Someone tried to register with your address", noticeBody);
127
+ let failure = await send(capabilities, item.address, "Someone tried to register with your address", noticeBody);
79
128
  if (failure.TAG === "Ok") {
80
129
  return {
81
130
  TAG: "Ok",
@@ -105,7 +154,7 @@ async function translate(_id, item, capabilities) {
105
154
  _0: `cannot hash a secret: ` + proofHash._0._0
106
155
  };
107
156
  }
108
- let failure$1 = await send(capabilities, item.email, invited ? "You are invited to create an account" : "Finish your registration", invited ? invitationBody(token$1) : challengeBody(token$1));
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));
109
158
  if (failure$1.TAG === "Ok") {
110
159
  return {
111
160
  TAG: "Ok",
@@ -140,6 +189,7 @@ export {
140
189
  collect,
141
190
  expiresIn,
142
191
  challengeBody,
192
+ asRoles,
143
193
  invitationBody,
144
194
  noticeBody,
145
195
  send,
@@ -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,7 +70,12 @@ type consumedEvent =
60
70
  proofHash: string,
61
71
  issuedAt: Reventless.DateTime.t,
62
72
  })
63
- | RegistrationProofAccepted({email: ContactAddressId.t, roles: array<string>, proofHash: string})
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})
66
81
 
@@ -78,6 +93,7 @@ type command =
78
93
  | @noApi
79
94
  Register({
80
95
  email: ContactAddressId.t,
96
+ @pii({subject: "email"}) address: Reventless.Email.t,
81
97
  role: @s.matches(Reventless.DcbTag.mark(Reventless.Role.nameSchema)) Reventless.Role.name,
82
98
  requestedAt: Reventless.DateTime.t,
83
99
  })
@@ -100,6 +116,7 @@ type command =
100
116
  | @noApi
101
117
  Invite({
102
118
  email: ContactAddressId.t,
119
+ @pii({subject: "email"}) address: Reventless.Email.t,
103
120
  roles: array<Reventless.Role.name>,
104
121
  invitedBy: string,
105
122
  requestedAt: Reventless.DateTime.t,
@@ -127,24 +144,28 @@ type error =
127
144
  type event =
128
145
  | RegistrationRequested({
129
146
  email: ContactAddressId.t,
147
+ @pii({subject: "email"}) address: Reventless.Email.t,
130
148
  roles: array<string>,
131
149
  requestedAt: Reventless.DateTime.t,
132
150
  })
133
151
  | RegistrationExpired({email: ContactAddressId.t})
134
152
  | RegistrationInvited({
135
153
  email: ContactAddressId.t,
154
+ @pii({subject: "email"}) address: Reventless.Email.t,
136
155
  roles: array<string>,
137
156
  invitedBy: string,
138
157
  invitedAt: Reventless.DateTime.t,
139
158
  })
140
159
  | RegistrationChallengeReissued({
141
160
  email: ContactAddressId.t,
161
+ @pii({subject: "email"}) address: Reventless.Email.t,
142
162
  reissuedAt: Reventless.DateTime.t,
143
163
  invitedBy?: string,
144
164
  })
145
165
  | RegistrationWithdrawn({email: ContactAddressId.t, withdrawnAt: Reventless.DateTime.t})
146
166
  | RegistrationAttemptedOnTakenAddress({
147
167
  email: ContactAddressId.t,
168
+ @pii({subject: "email"}) address: Reventless.Email.t,
148
169
  attemptedAt: Reventless.DateTime.t,
149
170
  })
150
171
  | RegistrationChallengeIssued({
@@ -152,6 +173,11 @@ type event =
152
173
  proofHash: string,
153
174
  issuedAt: Reventless.DateTime.t,
154
175
  })
155
- | RegistrationProofAccepted({email: ContactAddressId.t, roles: array<string>, proofHash: string})
176
+ | RegistrationProofAccepted({
177
+ email: ContactAddressId.t,
178
+ @pii({subject: "email"}) address: Reventless.Email.t,
179
+ roles: array<string>,
180
+ proofHash: string,
181
+ })
156
182
  | RegistrationProofRefused({email: ContactAddressId.t, reason: string})
157
183
  | RegistrationCompleted({email: ContactAddressId.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
  })),
@@ -77,6 +84,7 @@ let commandSchema = Sury.union([
77
84
  Sury.$schema(s => ({
78
85
  TAG: "Register",
79
86
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
87
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
80
88
  role: s.m(DcbTag$Reventless.mark(Role$Reventless.nameSchema)),
81
89
  requestedAt: s.m(DateTime$Reventless.schema)
82
90
  })),
@@ -99,6 +107,7 @@ let commandSchema = Sury.union([
99
107
  Sury.$schema(s => ({
100
108
  TAG: "Invite",
101
109
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
110
+ address: s.m(Pii$Reventless.mark("email", undefined, Email$Reventless.schema)),
102
111
  roles: s.m(Sury.array(Role$Reventless.nameSchema)),
103
112
  invitedBy: s.m(Sury.string),
104
113
  requestedAt: s.m(DateTime$Reventless.schema)
@@ -127,6 +136,7 @@ let eventSchema = Sury.union([
127
136
  Sury.$schema(s => ({
128
137
  TAG: "RegistrationRequested",
129
138
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
139
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
130
140
  roles: s.m(Sury.array(Sury.string)),
131
141
  requestedAt: s.m(DateTime$Reventless.schema)
132
142
  })),
@@ -137,6 +147,7 @@ let eventSchema = Sury.union([
137
147
  Sury.$schema(s => ({
138
148
  TAG: "RegistrationInvited",
139
149
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
150
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
140
151
  roles: s.m(Sury.array(Sury.string)),
141
152
  invitedBy: s.m(Sury.string),
142
153
  invitedAt: s.m(DateTime$Reventless.schema)
@@ -144,6 +155,7 @@ let eventSchema = Sury.union([
144
155
  Sury.$schema(s => ({
145
156
  TAG: "RegistrationChallengeReissued",
146
157
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
158
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
147
159
  reissuedAt: s.m(DateTime$Reventless.schema),
148
160
  invitedBy: s.m(Sury.$option(Sury.string))
149
161
  })),
@@ -155,6 +167,7 @@ let eventSchema = Sury.union([
155
167
  Sury.$schema(s => ({
156
168
  TAG: "RegistrationAttemptedOnTakenAddress",
157
169
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
170
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
158
171
  attemptedAt: s.m(DateTime$Reventless.schema)
159
172
  })),
160
173
  Sury.$schema(s => ({
@@ -166,6 +179,7 @@ let eventSchema = Sury.union([
166
179
  Sury.$schema(s => ({
167
180
  TAG: "RegistrationProofAccepted",
168
181
  email: s.m(DcbTag$Reventless.mark(ContactAddressId$ReventlessRegistration.schema)),
182
+ address: s.m(Pii$Reventless.marked("email", undefined, Email$Reventless.schema)),
169
183
  roles: s.m(Sury.array(Sury.string)),
170
184
  proofHash: s.m(Sury.string)
171
185
  })),
@@ -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({requestedAt: invitedAt, roles, invitedBy, challenge: None, proofHash: None}),
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: ByEmail(Reventless.Email.unsafe(email->ContactAddressId.toString)),
99
+ contact: contactOf(email),
84
100
  purpose: purposeOf(p),
85
101
  issuedAt,
86
102
  attempts: 0,
@@ -166,7 +182,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
166
182
  // decision: the policy is consulted before the address, so a closed
167
183
  // deployment sends nothing — not even the notice to an address that is
168
184
  // already registered.
169
- | Register({email, role, requestedAt}) =>
185
+ | Register({email, address, role, requestedAt}) =>
170
186
  if !admits(state.admission, ~table=App.table, ~role, ~at=requestedAt) {
171
187
  Ok([])
172
188
  } else {
@@ -177,7 +193,14 @@ module Make = (App: Reventless.Admission.Declaration) => {
177
193
  switch state.lastNoticeAt {
178
194
  | Some(last) if Guards.elapsedSeconds(~from=last, ~to_=requestedAt) < noticeCooldown =>
179
195
  Ok([])
180
- | _ => Ok([RegistrationAttemptedOnTakenAddress({email, attemptedAt: requestedAt})])
196
+ | _ =>
197
+ Ok([
198
+ RegistrationAttemptedOnTakenAddress({
199
+ email,
200
+ address: Value(address),
201
+ attemptedAt: requestedAt,
202
+ }),
203
+ ])
181
204
  }
182
205
  | Verified => Ok([])
183
206
  // A visitor cannot take over a claim, an inviter's included, while it holds.
@@ -185,22 +208,24 @@ module Make = (App: Reventless.Admission.Declaration) => {
185
208
  | Pending(_) =>
186
209
  Ok([
187
210
  RegistrationExpired({email: email}),
188
- RegistrationRequested({email, roles, requestedAt}),
211
+ RegistrationRequested({email, address: Value(address), roles, requestedAt}),
189
212
  ])
190
- | Unclaimed => Ok([RegistrationRequested({email, roles, requestedAt})])
213
+ | Unclaimed =>
214
+ Ok([RegistrationRequested({email, address: Value(address), roles, requestedAt})])
191
215
  }
192
216
  }
193
217
 
194
218
  // The policy is not consulted: it says whether visitors may sign themselves
195
219
  // up, and an invitation is not that. The table is, because it is the hard
196
220
  // cap on how each role is admitted.
197
- | Invite({email, roles, invitedBy, requestedAt}) =>
221
+ | Invite({email, address, roles, invitedBy, requestedAt}) =>
198
222
  switch roles->Array.find(r => !isByInvitation(App.table, r)) {
199
223
  | Some(role) => Error(NotByInvitation({role: (role :> string)}))
200
224
  | None if roles == [] => Error(NoRoleToGrant)
201
225
  | None =>
202
226
  let invited = RegistrationInvited({
203
227
  email,
228
+ address: Value(address),
204
229
  roles: roles->Array.map(r => (r :> string)),
205
230
  invitedBy,
206
231
  invitedAt: requestedAt,
@@ -219,7 +244,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
219
244
  switch state.stage {
220
245
  | Pending(p) =>
221
246
  switch Guards.onIssueRequested(
222
- ~contact=ByEmail(Reventless.Email.unsafe(email->ContactAddressId.toString)),
247
+ ~contact=contactOf(email),
223
248
  ~existing=p.challenge,
224
249
  ~now=issuedAt,
225
250
  ~policy=policyOf(p),
@@ -242,7 +267,12 @@ module Make = (App: Reventless.Admission.Declaration) => {
242
267
  if Guards.elapsedSeconds(~from=c.issuedAt, ~to_=requestedAt) >=
243
268
  policyOf(p).resendCooldown =>
244
269
  Ok([
245
- RegistrationChallengeReissued({email, reissuedAt: requestedAt, invitedBy: ?p.invitedBy}),
270
+ RegistrationChallengeReissued({
271
+ email,
272
+ address: p.address,
273
+ reissuedAt: requestedAt,
274
+ invitedBy: ?p.invitedBy,
275
+ }),
246
276
  ])
247
277
  | _ => Ok([])
248
278
  }
@@ -257,7 +287,7 @@ module Make = (App: Reventless.Admission.Declaration) => {
257
287
  ~now=presentedAt,
258
288
  ~policy=policyOf(p),
259
289
  ) {
260
- | Settle => Ok([RegistrationProofAccepted({email, roles, proofHash})])
290
+ | Settle => Ok([RegistrationProofAccepted({email, address: p.address, roles, proofHash})])
261
291
  | Refuse(reason) => Ok([RegistrationProofRefused({email, reason: refusalReason(reason)})])
262
292
  }
263
293
  // No challenge to answer: nothing to count it against, and nothing to say.
@@ -14,6 +14,13 @@ let initialState = {
14
14
  lastNoticeAt: undefined
15
15
  };
16
16
 
17
+ function contactOf(email) {
18
+ return {
19
+ TAG: "ByEmail",
20
+ _0: ContactAddressId$ReventlessRegistration.toString(email)
21
+ };
22
+ }
23
+
17
24
  function purposeOf(p) {
18
25
  return RegistrationChallenge$ReventlessRegistration.purposeOf(p.invitedBy);
19
26
  }
@@ -45,6 +52,7 @@ function evolve(state, event) {
45
52
  stage: {
46
53
  TAG: "Pending",
47
54
  _0: {
55
+ address: event.address,
48
56
  requestedAt: event.requestedAt,
49
57
  roles: event.roles,
50
58
  challenge: undefined,
@@ -59,6 +67,7 @@ function evolve(state, event) {
59
67
  stage: {
60
68
  TAG: "Pending",
61
69
  _0: {
70
+ address: event.address,
62
71
  requestedAt: event.invitedAt,
63
72
  roles: event.roles,
64
73
  invitedBy: event.invitedBy,
@@ -210,6 +219,7 @@ function Make(App) {
210
219
  case "Register" :
211
220
  let requestedAt = command.requestedAt;
212
221
  let role = command.role;
222
+ let address = command.address;
213
223
  let email = command.email;
214
224
  if (!admits(state.admission, App.table, role, requestedAt)) {
215
225
  return {
@@ -231,6 +241,10 @@ function Make(App) {
231
241
  {
232
242
  TAG: "RegistrationRequested",
233
243
  email: email,
244
+ address: {
245
+ TAG: "Value",
246
+ _0: address
247
+ },
234
248
  roles: roles,
235
249
  requestedAt: requestedAt
236
250
  }
@@ -250,6 +264,10 @@ function Make(App) {
250
264
  _0: [{
251
265
  TAG: "RegistrationRequested",
252
266
  email: email,
267
+ address: {
268
+ TAG: "Value",
269
+ _0: address
270
+ },
253
271
  roles: roles,
254
272
  requestedAt: requestedAt
255
273
  }]
@@ -261,33 +279,26 @@ function Make(App) {
261
279
  };
262
280
  case "Completed" :
263
281
  let last = state.lastNoticeAt;
264
- if (last !== undefined) {
265
- if (ContactVerification_Guards$ReventlessRegistration.elapsedSeconds(last, requestedAt) < 3600) {
266
- return {
267
- TAG: "Ok",
268
- _0: []
269
- };
270
- } else {
271
- return {
272
- TAG: "Ok",
273
- _0: [{
274
- TAG: "RegistrationAttemptedOnTakenAddress",
275
- email: email,
276
- attemptedAt: requestedAt
277
- }]
278
- };
279
- }
280
- } else {
282
+ if (last !== undefined && ContactVerification_Guards$ReventlessRegistration.elapsedSeconds(last, requestedAt) < 3600) {
281
283
  return {
282
284
  TAG: "Ok",
283
- _0: [{
284
- TAG: "RegistrationAttemptedOnTakenAddress",
285
- email: email,
286
- attemptedAt: requestedAt
287
- }]
285
+ _0: []
288
286
  };
289
287
  }
288
+ return {
289
+ TAG: "Ok",
290
+ _0: [{
291
+ TAG: "RegistrationAttemptedOnTakenAddress",
292
+ email: email,
293
+ address: {
294
+ TAG: "Value",
295
+ _0: address
296
+ },
297
+ attemptedAt: requestedAt
298
+ }]
299
+ };
290
300
  }
301
+ break;
291
302
  case "IssueRegistrationChallenge" :
292
303
  let issuedAt = command.issuedAt;
293
304
  let email$1 = command.email;
@@ -351,6 +362,7 @@ function Make(App) {
351
362
  _0: [{
352
363
  TAG: "RegistrationProofAccepted",
353
364
  email: email$2,
365
+ address: p$4.address,
354
366
  roles: p$4.roles,
355
367
  proofHash: proofHash
356
368
  }]
@@ -408,13 +420,18 @@ function Make(App) {
408
420
  _0: "NoRoleToGrant"
409
421
  };
410
422
  }
411
- let invited_1 = roles$1.map(r => r);
412
- let invited_2 = command.invitedBy;
423
+ let invited_1 = {
424
+ TAG: "Value",
425
+ _0: command.address
426
+ };
427
+ let invited_2 = roles$1.map(r => r);
428
+ let invited_3 = command.invitedBy;
413
429
  let invited = {
414
430
  TAG: "RegistrationInvited",
415
431
  email: email$3,
416
- roles: invited_1,
417
- invitedBy: invited_2,
432
+ address: invited_1,
433
+ roles: invited_2,
434
+ invitedBy: invited_3,
418
435
  invitedAt: requestedAt$1
419
436
  };
420
437
  let p$5 = state.stage;
@@ -468,6 +485,7 @@ function Make(App) {
468
485
  _0: [{
469
486
  TAG: "RegistrationChallengeReissued",
470
487
  email: command.email,
488
+ address: p$7.address,
471
489
  reissuedAt: requestedAt$2,
472
490
  invitedBy: p$7.invitedBy
473
491
  }]
@@ -528,6 +546,7 @@ export {
528
546
  Guards,
529
547
  initialState,
530
548
  noticeCooldown,
549
+ contactOf,
531
550
  purposeOf,
532
551
  policyOf,
533
552
  evolve,
@@ -25,3 +25,6 @@ type state = {
25
25
  type consumedEvent =
26
26
  | RegistrationOpened({role: string, until?: Reventless.DateTime.t})
27
27
  | RegistrationClosed({role: string})
28
+
29
+ /** This view says which roles are open; the platform tells the shell where to read it. */
30
+ let admissionDoor = Reventless.Admission.OpenRoles
@@ -52,6 +52,8 @@ let stateSchema$1 = Sury.$Metadata_set(stateSchema, StateAnnotations$Reventless.
52
52
 
53
53
  let name = "RegistrationWindows";
54
54
 
55
+ let admissionDoor = "OpenRoles";
56
+
55
57
  let Id;
56
58
 
57
59
  let subIdConfig;
@@ -65,6 +67,7 @@ let visibility = "Public";
65
67
  export {
66
68
  name,
67
69
  consumedEventSchema,
70
+ admissionDoor,
68
71
  config,
69
72
  Id,
70
73
  subIdConfig,