@reventlessdev/reventless-registration 0.0.0-stage → 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.
- package/LICENSE +202 -0
- package/README.md +50 -2
- package/package.json +38 -3
- package/rescript.json +28 -0
- package/src/ContactVerification.res +106 -0
- package/src/ContactVerification.res.mjs +60 -0
- package/src/ContactVerification_Guards.res +180 -0
- package/src/ContactVerification_Guards.res.mjs +97 -0
- package/src/Registration/ContactAddressId.res +30 -0
- package/src/Registration/ContactAddressId.res.mjs +53 -0
- package/src/Registration/InboundTranslation/CompleteRegistration.res +35 -0
- package/src/Registration/InboundTranslation/CompleteRegistration.res.mjs +58 -0
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res +43 -0
- package/src/Registration/InboundTranslation/CompleteRegistration_Translation.res.mjs +74 -0
- package/src/Registration/InboundTranslation/SignUp.res +36 -0
- package/src/Registration/InboundTranslation/SignUp.res.mjs +60 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res +51 -0
- package/src/Registration/InboundTranslation/SignUp_Translation.res.mjs +75 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res +40 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal.res.mjs +65 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res +49 -0
- package/src/Registration/OutboundTranslation/CreateRegisteredPrincipal_Translation.res.mjs +108 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res +72 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge.res.mjs +87 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res +115 -0
- package/src/Registration/OutboundTranslation/SendRegistrationChallenge_Translation.res.mjs +200 -0
- package/src/Registration/StateChange/RegistrationPolicy.res +58 -0
- package/src/Registration/StateChange/RegistrationPolicy.res.mjs +86 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res +43 -0
- package/src/Registration/StateChange/RegistrationPolicy_Decision.res.mjs +88 -0
- package/src/Registration/StateChange/Registrations.res +183 -0
- package/src/Registration/StateChange/Registrations.res.mjs +238 -0
- package/src/Registration/StateChange/Registrations_Decision.res +311 -0
- package/src/Registration/StateChange/Registrations_Decision.res.mjs +560 -0
- package/src/Registration/StateViewStream/RegistrationWindows.res +30 -0
- package/src/Registration/StateViewStream/RegistrationWindows.res.mjs +80 -0
- package/src/Registration/StateViewStream/RegistrationWindows_Projection.res +7 -0
- package/src/Registration/StateViewStream/RegistrationWindows_Projection.res.mjs +38 -0
- package/src/RegistrationChallenge.res +20 -0
- package/src/RegistrationChallenge.res.mjs +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2019-2026 Martin Lorenz
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reventlessdev/reventless-registration
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Self-registration as a library of slices. A person with no account proves control of
|
|
4
|
+
an address and ends up with one, in the groups of the roles the app admits them to.
|
|
5
|
+
Verify, then create: nothing makes an account until the proof settles, and "this
|
|
6
|
+
address is taken" is a DCB claim tag on the address, decided identically on every
|
|
7
|
+
platform.
|
|
8
|
+
|
|
9
|
+
A plugin is per app, so this package is not a plugin. An app's plugin lists it in
|
|
10
|
+
`src/plugin.json` and supplies its admission table:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"name": "Registration",
|
|
15
|
+
"slicesFrom": [{"package": "@reventlessdev/reventless-registration", "with": "Admission"}]
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```rescript
|
|
20
|
+
// src/Admission.res, over the plugin's own Roles.t
|
|
21
|
+
let table = Reventless.Admission.declare([(Roles.Shopper, SelfService), (Admin, Provisioned)])
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The plugin also lists this package in its `dependencies` and in its `rescript.json`
|
|
25
|
+
dependencies. The generator composes the slices as the plugin's own, under the
|
|
26
|
+
`Registration` chapter.
|
|
27
|
+
|
|
28
|
+
| Slice | Kind | What it does |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `RegistrationPolicy` | StateChange, administrators only | Opens and closes a self-service role, optionally until a time |
|
|
31
|
+
| `Registrations` | StateChange, relayed commands only | The ledger, partitioned by address. Besides a sign-up's arms, it takes an invitation (`Invite`), a reissued code and a withdrawal, which no door here reaches |
|
|
32
|
+
| `RegistrationWindows` | StateViewStream, anonymous | Which self-service roles are open now |
|
|
33
|
+
| `SignUp` | Inbound, anonymous | Starts a registration for a role |
|
|
34
|
+
| `CompleteRegistration` | Inbound, anonymous | Takes the proof and the password; the password goes to the stash, never to the log |
|
|
35
|
+
| `SendRegistrationChallenge` | Outbound, `Messaging` | Sends the code, or tells a registered address someone tried |
|
|
36
|
+
| `CreateRegisteredPrincipal` | Outbound, `Stash` + `IdentityProvider` | Makes the account once the proof is accepted |
|
|
37
|
+
|
|
38
|
+
A closed role, a role no visitor may have, a taken address and a fresh one all answer
|
|
39
|
+
an anonymous caller alike; only what arrives at the address differs.
|
|
40
|
+
|
|
41
|
+
The package ships the doors a visitor uses and no invitation door. A plugin that
|
|
42
|
+
provides one lists it beside these slices, marks it `let admissionDoor =
|
|
43
|
+
Reventless.Admission.Invite`, checks the inviter's roles, and relays `Invite` to the
|
|
44
|
+
ledger. The ledger refuses any role the app's table does not declare by invitation.
|
|
45
|
+
An invitation's code holds a week; a sign-up's holds a day.
|
|
46
|
+
|
|
47
|
+
The scenarios that pin these slices run in the plugins that list them, against that
|
|
48
|
+
plugin's own table: in this repository, `examples/online-shop-hybrid/registration`.
|
|
49
|
+
|
|
50
|
+
The doors admit anonymous callers, which only the local platform does today, so a
|
|
51
|
+
plugin listing these slices is hosted by the local platform only.
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-registration",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0-alpha.10",
|
|
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
|
+
"license": "Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"src/**/*.res",
|
|
8
|
+
"src/**/*.resi",
|
|
9
|
+
"src/**/*.res.mjs",
|
|
10
|
+
"rescript.json",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"sury": "11.0.0",
|
|
15
|
+
"sury-ppx": "11.0.0",
|
|
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
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"rescript": "12.3.1"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"rescript": "^12.3.1"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/ReventlessDev/reventless-core.git",
|
|
32
|
+
"directory": "reventless/registration"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rescript build",
|
|
36
|
+
"start": "rescript watch",
|
|
37
|
+
"clean": "rescript clean",
|
|
38
|
+
"rebuild": "pnpm run clean && pnpm run build",
|
|
39
|
+
"test": "echo \"The scenarios run in the plugins that list these slices; see README.md.\""
|
|
40
|
+
}
|
|
6
41
|
}
|
package/rescript.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reventlessdev/reventless-registration",
|
|
3
|
+
"package-specs": {
|
|
4
|
+
"module": "esmodule",
|
|
5
|
+
"in-source": true
|
|
6
|
+
},
|
|
7
|
+
"namespace": "ReventlessRegistration",
|
|
8
|
+
"ppx-flags": [
|
|
9
|
+
"@reventlessdev/reventless-ppx/bin",
|
|
10
|
+
"sury-ppx/bin"
|
|
11
|
+
],
|
|
12
|
+
"warnings": {
|
|
13
|
+
"error": "-44+101"
|
|
14
|
+
},
|
|
15
|
+
"sources": [
|
|
16
|
+
{
|
|
17
|
+
"dir": "src",
|
|
18
|
+
"subdirs": true
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"dependencies": [
|
|
22
|
+
"sury",
|
|
23
|
+
"@reventlessdev/reventless-spec",
|
|
24
|
+
"@reventlessdev/reventless-infra"
|
|
25
|
+
],
|
|
26
|
+
"compiler-flags": [],
|
|
27
|
+
"suffix": ".res.mjs"
|
|
28
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// A copy of the `ContactVerification` the hybrid example's ordering plugin
|
|
2
|
+
// holds, since neither may import the other. Registration is this competency's
|
|
3
|
+
// second consumer, and the two copies are the input its extraction into a trait
|
|
4
|
+
// package works from; until then, a change to one is a change to both.
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Proving that a person controls a contact address.
|
|
8
|
+
|
|
9
|
+
One secret, expiring, non-replayable, and dropped if the address changes
|
|
10
|
+
underneath it. What a settled proof *entitles* is the host's business and
|
|
11
|
+
deliberately absent: that is the part that would not survive a host swap.
|
|
12
|
+
*/
|
|
13
|
+
/** An address, not a channel. Narrower than `Messaging.recipient` on purpose —
|
|
14
|
+
a push token is not a claim anyone makes, so the wrong subject is not
|
|
15
|
+
constructible. */
|
|
16
|
+
type contact =
|
|
17
|
+
| ByEmail(Reventless.Email.t)
|
|
18
|
+
| ByPhone(Reventless.Phone.t)
|
|
19
|
+
|
|
20
|
+
/** Which channels an address is reachable over. One-to-many, which is why
|
|
21
|
+
address and channel stay separate types; intersected at runtime with the
|
|
22
|
+
channels the deployment's provider publishes. */
|
|
23
|
+
let channelsFor = (contact: contact): array<Reventless.Messaging.channel> =>
|
|
24
|
+
switch contact {
|
|
25
|
+
| ByEmail(_) => [Email]
|
|
26
|
+
| ByPhone(_) => [Sms]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Total, because being addressable is what makes something a subject. */
|
|
30
|
+
let toRecipient = (contact: contact): Reventless.Messaging.recipient =>
|
|
31
|
+
switch contact {
|
|
32
|
+
| ByEmail(email) => ToEmail(email)
|
|
33
|
+
| ByPhone(phone) => ToSms(phone)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Why the proof is being asked for. The same machinery serves a registration, a
|
|
37
|
+
contact change, an invitation and a recovery; without this the next four
|
|
38
|
+
consumers each rebuild it. */
|
|
39
|
+
type purpose =
|
|
40
|
+
| Registration
|
|
41
|
+
| ContactChange
|
|
42
|
+
| Invitation
|
|
43
|
+
| Recovery
|
|
44
|
+
| Custom(string)
|
|
45
|
+
|
|
46
|
+
type subject = {contact: contact, purpose: purpose}
|
|
47
|
+
|
|
48
|
+
/** How a challenge ended. `Superseded` is the address changing while it was
|
|
49
|
+
open — a fact about the host, not about the person. */
|
|
50
|
+
type outcome =
|
|
51
|
+
| Verified
|
|
52
|
+
| Expired
|
|
53
|
+
| Superseded
|
|
54
|
+
| Abandoned
|
|
55
|
+
|
|
56
|
+
/** What a secret is drawn from — the capability's own vocabulary rather than a
|
|
57
|
+
second copy of it. A link is followed and a code is typed off a screen, so
|
|
58
|
+
the two cannot share an alphabet, and the source that draws them is the one
|
|
59
|
+
place that should say which exist. */
|
|
60
|
+
type alphabet = Reventless.Secrets.alphabet
|
|
61
|
+
|
|
62
|
+
/** Keyed by channel — not globally, and not by contact. A 32-character link with
|
|
63
|
+
a 24-hour window is right for email and unusable over SMS, where a human
|
|
64
|
+
retypes the proof. Keying by contact would look identical today and quietly
|
|
65
|
+
hard-code one channel per address. */
|
|
66
|
+
type policy = {
|
|
67
|
+
tokenTtl: Reventless.Duration.t,
|
|
68
|
+
maxAttempts: int,
|
|
69
|
+
resendCooldown: Reventless.Duration.t,
|
|
70
|
+
proofLength: int,
|
|
71
|
+
proofAlphabet: alphabet,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A day to act on, and a long secret because nobody types it. */
|
|
75
|
+
let emailPolicy: policy = {
|
|
76
|
+
tokenTtl: 86400,
|
|
77
|
+
maxAttempts: 5,
|
|
78
|
+
resendCooldown: 60,
|
|
79
|
+
proofLength: 32,
|
|
80
|
+
proofAlphabet: UrlSafe,
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Short-lived and short, because it is read off one screen and typed into
|
|
84
|
+
another — and fewer attempts, because six digits is a guessable space. */
|
|
85
|
+
let smsPolicy: policy = {
|
|
86
|
+
tokenTtl: 600,
|
|
87
|
+
maxAttempts: 3,
|
|
88
|
+
resendCooldown: 60,
|
|
89
|
+
proofLength: 6,
|
|
90
|
+
proofAlphabet: Digits,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
`None` for `Push`, and that is structural rather than unfinished.
|
|
95
|
+
|
|
96
|
+
A push token is issued to one app install and relayed over an already
|
|
97
|
+
authenticated session, so a challenge echoed back proves only what registering
|
|
98
|
+
the token proved. Push presupposes the session it would be bootstrapping. An
|
|
99
|
+
arm that merely had no policy yet would invite someone to supply one.
|
|
100
|
+
*/
|
|
101
|
+
let policyFor = (channel: Reventless.Messaging.channel): option<policy> =>
|
|
102
|
+
switch channel {
|
|
103
|
+
| Email => Some(emailPolicy)
|
|
104
|
+
| Sms => Some(smsPolicy)
|
|
105
|
+
| Push => None
|
|
106
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function channelsFor(contact) {
|
|
5
|
+
if (contact.TAG === "ByEmail") {
|
|
6
|
+
return ["Email"];
|
|
7
|
+
} else {
|
|
8
|
+
return ["Sms"];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toRecipient(contact) {
|
|
13
|
+
if (contact.TAG === "ByEmail") {
|
|
14
|
+
return {
|
|
15
|
+
TAG: "ToEmail",
|
|
16
|
+
_0: contact._0
|
|
17
|
+
};
|
|
18
|
+
} else {
|
|
19
|
+
return {
|
|
20
|
+
TAG: "ToSms",
|
|
21
|
+
_0: contact._0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let emailPolicy = {
|
|
27
|
+
tokenTtl: 86400,
|
|
28
|
+
maxAttempts: 5,
|
|
29
|
+
resendCooldown: 60,
|
|
30
|
+
proofLength: 32,
|
|
31
|
+
proofAlphabet: "UrlSafe"
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let smsPolicy = {
|
|
35
|
+
tokenTtl: 600,
|
|
36
|
+
maxAttempts: 3,
|
|
37
|
+
resendCooldown: 60,
|
|
38
|
+
proofLength: 6,
|
|
39
|
+
proofAlphabet: "Digits"
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function policyFor(channel) {
|
|
43
|
+
switch (channel) {
|
|
44
|
+
case "Email" :
|
|
45
|
+
return emailPolicy;
|
|
46
|
+
case "Sms" :
|
|
47
|
+
return smsPolicy;
|
|
48
|
+
case "Push" :
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
channelsFor,
|
|
55
|
+
toRecipient,
|
|
56
|
+
emailPolicy,
|
|
57
|
+
smsPolicy,
|
|
58
|
+
policyFor,
|
|
59
|
+
}
|
|
60
|
+
/* No side effect */
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// A copy of the ordering plugin's `ContactVerification_Guards`, for the reason
|
|
2
|
+
// `ContactVerification.res` gives. Registration exercises the arm the first copy
|
|
3
|
+
// cannot: no host, so `hostContact` is `None`.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
The graft's decision rules, compiled once and called by every host: a proof for
|
|
7
|
+
an address the entity has moved off settles nothing, a settled challenge settles
|
|
8
|
+
once, and expiry is decided when the proof arrives rather than on a timer.
|
|
9
|
+
|
|
10
|
+
The host keeps its own state and builds a `verification` per call from fields it
|
|
11
|
+
already holds. The challenge is *not* host state — an aggregate is snapshotted,
|
|
12
|
+
and a secret in a snapshot is a secret in every backup of one.
|
|
13
|
+
*/
|
|
14
|
+
/** The two fields the rules read, as the host holds them. Its invariant, which
|
|
15
|
+
every host arm must preserve: `verifiedAddress` is `None` or equal to
|
|
16
|
+
`contact`. */
|
|
17
|
+
type verification = {
|
|
18
|
+
contact: ContactVerification.contact,
|
|
19
|
+
verifiedAddress: option<ContactVerification.contact>,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One challenge, as the trait's own ledger holds it. The secret itself is never
|
|
23
|
+
here — only whether a presented one matched, which the caller decides. */
|
|
24
|
+
type challenge = {
|
|
25
|
+
contact: ContactVerification.contact,
|
|
26
|
+
purpose: ContactVerification.purpose,
|
|
27
|
+
issuedAt: Reventless.DateTime.t,
|
|
28
|
+
attempts: int,
|
|
29
|
+
settled: bool,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What the host still owes a proof for, or `None` — the stand-down. A host
|
|
33
|
+
whose current address is already the verified one spends no capability call,
|
|
34
|
+
the same arm as a map picker having already supplied the point. */
|
|
35
|
+
let contactToVerify = (v: verification): option<ContactVerification.contact> =>
|
|
36
|
+
v.verifiedAddress == Some(v.contact) ? None : Some(v.contact)
|
|
37
|
+
|
|
38
|
+
let elapsedSeconds = (~from: Reventless.DateTime.t, ~to_: Reventless.DateTime.t): int =>
|
|
39
|
+
Int.fromFloat((Reventless.DateTime.millis(to_) -. Reventless.DateTime.millis(from)) /. 1000.)
|
|
40
|
+
|
|
41
|
+
/** Expiry is decided when the proof arrives, not by a scheduled fire. No
|
|
42
|
+
process-manager state to keep, and testable without controlling a clock. */
|
|
43
|
+
let hasExpired = (c: challenge, ~now, ~policy: ContactVerification.policy): bool =>
|
|
44
|
+
elapsedSeconds(~from=c.issuedAt, ~to_=now) >= policy.tokenTtl
|
|
45
|
+
|
|
46
|
+
/** Why a presented proof settles nothing. Named rather than one blank refusal,
|
|
47
|
+
because the host tells the subject which of these happened and tells an
|
|
48
|
+
anonymous caller nothing — that distinction is about who is asking, not about
|
|
49
|
+
whether the reason is known here. */
|
|
50
|
+
type refusal =
|
|
51
|
+
/** 🚨 The security control. The host's address changed while this challenge
|
|
52
|
+
was open, so the proof names an address its presenter may no longer hold.
|
|
53
|
+
Settling it would be "change the address, then present the old one's link",
|
|
54
|
+
which is an account takeover. */
|
|
55
|
+
| AddressSuperseded
|
|
56
|
+
| ChallengeExpired
|
|
57
|
+
| AlreadySettled
|
|
58
|
+
| AttemptsExhausted
|
|
59
|
+
| ProofMismatch
|
|
60
|
+
|
|
61
|
+
type proofVerdict =
|
|
62
|
+
| Settle
|
|
63
|
+
| Refuse(refusal)
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
The order of these checks is a security decision, not a style one.
|
|
67
|
+
|
|
68
|
+
Supersession is tested before anything else, so a stale challenge is refused on
|
|
69
|
+
the fact that makes it dangerous rather than on whichever of its other
|
|
70
|
+
properties happened to lapse first — a superseded challenge that had also
|
|
71
|
+
expired must not be reported as merely expired. The proof itself is compared
|
|
72
|
+
last, so none of the structural refusals depend on the secret.
|
|
73
|
+
|
|
74
|
+
`hostContact` is an option because the two flows this competency serves differ
|
|
75
|
+
in whether there *is* a host. Changing an address has one, and supersession is
|
|
76
|
+
checkable. Registering has none — the subject the address will belong to does
|
|
77
|
+
not exist yet — so `None` means "nothing to be superseded by", not "skip the
|
|
78
|
+
check". A ledger that simply does not track the host also passes `None`, and
|
|
79
|
+
relies on the host's own write-back guard, which is why that one is not
|
|
80
|
+
optional.
|
|
81
|
+
*/
|
|
82
|
+
let onProofPresented = (
|
|
83
|
+
c: challenge,
|
|
84
|
+
~hostContact: option<ContactVerification.contact>,
|
|
85
|
+
~proofMatches: bool,
|
|
86
|
+
~now: Reventless.DateTime.t,
|
|
87
|
+
~policy: ContactVerification.policy,
|
|
88
|
+
): proofVerdict =>
|
|
89
|
+
if hostContact->Option.mapOr(false, held => c.contact != held) {
|
|
90
|
+
Refuse(AddressSuperseded)
|
|
91
|
+
} else if c.settled {
|
|
92
|
+
Refuse(AlreadySettled)
|
|
93
|
+
} else if hasExpired(c, ~now, ~policy) {
|
|
94
|
+
Refuse(ChallengeExpired)
|
|
95
|
+
} else if c.attempts >= policy.maxAttempts {
|
|
96
|
+
Refuse(AttemptsExhausted)
|
|
97
|
+
} else if !proofMatches {
|
|
98
|
+
Refuse(ProofMismatch)
|
|
99
|
+
} else {
|
|
100
|
+
Settle
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type verdict = Append | Ignore
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
The write-back rule, applied where the host records the outcome.
|
|
107
|
+
|
|
108
|
+
Two guards, and the first is the same security control `onProofPresented`
|
|
109
|
+
applies to the challenge — deliberately duplicated rather than trusted once. The
|
|
110
|
+
ledger refusing to settle and the host refusing to record are different
|
|
111
|
+
failures: a verdict can reach the host by redelivery, by a replayed command, or
|
|
112
|
+
from a ledger that is simply wrong, and only this one is inside the host's own
|
|
113
|
+
consistency boundary. The second is the ordinary redelivery no-op.
|
|
114
|
+
*/
|
|
115
|
+
let onVerifiedReport = (v: verification, ~contact: ContactVerification.contact): verdict =>
|
|
116
|
+
if contact != v.contact {
|
|
117
|
+
Ignore
|
|
118
|
+
} else if v.verifiedAddress == Some(contact) {
|
|
119
|
+
Ignore
|
|
120
|
+
} else {
|
|
121
|
+
Append
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type issuance =
|
|
125
|
+
/** Mint a secret and send it. */
|
|
126
|
+
| Issue
|
|
127
|
+
/** An open challenge already covers this address, so a redelivered request
|
|
128
|
+
mints nothing and sends nothing. Commands arrive at least once, and a slice
|
|
129
|
+
re-publishes until its work clears. */
|
|
130
|
+
| AlreadyOpen
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
Whether a request to challenge an address produces a new secret.
|
|
134
|
+
|
|
135
|
+
Decided against the ledger's own state and nothing else. The stand-down —
|
|
136
|
+
whether an address is owed a proof at all — is `contactToVerify`, and it belongs
|
|
137
|
+
to whoever reads the host, because a ledger has no host to read. Folding the two
|
|
138
|
+
together read naturally with one host in view and stopped compiling the moment a
|
|
139
|
+
second flow had none.
|
|
140
|
+
*/
|
|
141
|
+
let onIssueRequested = (
|
|
142
|
+
~contact: ContactVerification.contact,
|
|
143
|
+
~existing: option<challenge>,
|
|
144
|
+
~now: Reventless.DateTime.t,
|
|
145
|
+
~policy: ContactVerification.policy,
|
|
146
|
+
): issuance =>
|
|
147
|
+
switch existing {
|
|
148
|
+
| Some(c) if c.contact == contact && !c.settled && !hasExpired(c, ~now, ~policy) => AlreadyOpen
|
|
149
|
+
| _ => Issue
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
type resend =
|
|
153
|
+
| Send
|
|
154
|
+
/** Asked for again too soon, carrying what is left of the cooldown so the host
|
|
155
|
+
can say when rather than only no. */
|
|
156
|
+
| TooSoon(Reventless.Duration.t)
|
|
157
|
+
/** Nothing open to send again. */
|
|
158
|
+
| NothingOpen
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
A deliberate "send it again". The same secret goes out rather than a fresh one,
|
|
162
|
+
so a link already sitting in a mailbox keeps working — minting a new one would
|
|
163
|
+
invalidate the message the person is looking at while they read it.
|
|
164
|
+
*/
|
|
165
|
+
let onResendRequested = (
|
|
166
|
+
~contact: ContactVerification.contact,
|
|
167
|
+
~existing: option<challenge>,
|
|
168
|
+
~now: Reventless.DateTime.t,
|
|
169
|
+
~policy: ContactVerification.policy,
|
|
170
|
+
): resend =>
|
|
171
|
+
switch existing {
|
|
172
|
+
| None => NothingOpen
|
|
173
|
+
| Some(c) =>
|
|
174
|
+
if c.contact != contact || c.settled || hasExpired(c, ~now, ~policy) {
|
|
175
|
+
NothingOpen
|
|
176
|
+
} else {
|
|
177
|
+
let waited = elapsedSeconds(~from=c.issuedAt, ~to_=now)
|
|
178
|
+
waited >= policy.resendCooldown ? Send : TooSoon(policy.resendCooldown - waited)
|
|
179
|
+
}
|
|
180
|
+
}
|