@prson/login-sdk 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +364 -2
- package/dist/api.d.ts +59 -0
- package/dist/api.js +41 -0
- package/dist/bind.d.ts +224 -0
- package/dist/bind.js +1384 -0
- package/dist/crypto.d.ts +352 -0
- package/dist/crypto.js +159 -0
- package/dist/csp.d.ts +39 -0
- package/dist/csp.js +125 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +28 -0
- package/dist/index.d.ts +363 -0
- package/dist/index.js +6278 -0
- package/dist/index.js.map +7 -0
- package/dist/notify.d.ts +8 -0
- package/dist/notify.js +17 -0
- package/dist/point_phone_overlay.d.ts +41 -0
- package/dist/point_phone_overlay.js +161 -0
- package/dist/qr.d.ts +105 -0
- package/dist/qr.js +149 -0
- package/dist/requests.d.ts +279 -0
- package/dist/requests.js +128 -0
- package/dist/select_overlay.d.ts +70 -0
- package/dist/select_overlay.js +430 -0
- package/dist/session.d.ts +645 -0
- package/dist/session.js +1455 -0
- package/dist/signaling.d.ts +49 -0
- package/dist/signaling.js +92 -0
- package/dist/status.d.ts +48 -0
- package/dist/status.js +105 -0
- package/dist/transport.d.ts +50 -0
- package/dist/transport.js +212 -0
- package/dist/verification.d.ts +56 -0
- package/dist/verification.js +169 -0
- package/dist/verify.d.ts +69 -0
- package/dist/verify.js +331 -0
- package/package.json +59 -4
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 [yyyy] [name of copyright owner]
|
|
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,365 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @prson/login-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> The browser package. Drops into any website with one `<script>` tag
|
|
4
|
+
> (or `npm install @prson/login-sdk` for modular bundlers).
|
|
5
|
+
>
|
|
6
|
+
> See [`../../README.md`](../../README.md) for the whole-system
|
|
7
|
+
> overview, [`../../ARCHITECTURE.md`](../../ARCHITECTURE.md) for the
|
|
8
|
+
> wire format, [`../../SECURITY.md`](../../SECURITY.md) for the threat
|
|
9
|
+
> model.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Install from npm (below), or load the browser bundle from
|
|
14
|
+
`https://prson.net/vendor/prson-login/prson-login.js` (see *CDN* below).
|
|
15
|
+
|
|
16
|
+
### Bundled
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @prson/login-sdk
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { PrsonLogin } from "@prson/login-sdk";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### CDN (no build step)
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script type="module">
|
|
30
|
+
import { PrsonLogin } from "https://prson.net/vendor/prson-login/prson-login.js";
|
|
31
|
+
// Optional: the styled QR card (registers itself; no exports needed).
|
|
32
|
+
import "https://prson.net/vendor/prson-login/prson-login-ui.js";
|
|
33
|
+
</script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The bundle is an unversioned ES module built from this repository's
|
|
37
|
+
`main`; pin your own copy if you need a fixed version.
|
|
38
|
+
|
|
39
|
+
## The full API surface, in one block
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
type SignInOptions = {
|
|
43
|
+
/** Bound into the KB-JWT `aud`. The SDK reads `window.location.origin`
|
|
44
|
+
* if you omit it; pass it explicitly only if your origin chain is
|
|
45
|
+
* unusual (iframe, custom protocol). */
|
|
46
|
+
domain?: string;
|
|
47
|
+
|
|
48
|
+
/** What you require from the holder. The SDK presents this to the
|
|
49
|
+
* user in the wallet's login drawer — the user can refuse. */
|
|
50
|
+
required?: {
|
|
51
|
+
/** 0..6. Omitted ⇒ 1 (a live selfie, checked on the phone). 5 needs a
|
|
52
|
+
* chip-checked passport or ID card. See "Choose your level" in the
|
|
53
|
+
* top-level README. */
|
|
54
|
+
minVerificationLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
55
|
+
|
|
56
|
+
/** Standard SD-JWT-VC claim names (e.g. "given_name", "birthdate").
|
|
57
|
+
* Omit to ask for `verified_human` only. */
|
|
58
|
+
requiredClaims?: string[];
|
|
59
|
+
|
|
60
|
+
/** Predicate ids from the Prson fragment catalog (e.g. "age_gte_18",
|
|
61
|
+
* "issuing_country_in_eu"). Signed on-demand at presentation. */
|
|
62
|
+
predicates?: string[];
|
|
63
|
+
|
|
64
|
+
/** Default: "personal". */
|
|
65
|
+
identityType?: "personal" | "organization";
|
|
66
|
+
|
|
67
|
+
/** Ask for a unique-human id: the same `uniqueIdHash` for one person
|
|
68
|
+
* on your site whatever phone or install they use (level 5+).
|
|
69
|
+
* `result.prsonId` is NOT one per person; this is. Verify it on your
|
|
70
|
+
* server with `verifyUniqueHumanId`. */
|
|
71
|
+
uniqueHumanId?: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** If `true`, the SDK ALSO accepts a self-signed **anonymous-wallet**
|
|
75
|
+
* credential — no verified-human claim, no document fields, just a
|
|
76
|
+
* proof the user controls a Prson wallet on this domain. The
|
|
77
|
+
* wallet's drawer surfaces a "Sign in anonymously" option to the
|
|
78
|
+
* user. `result.claims.anonymous === true` indicates this branch
|
|
79
|
+
* fired. Default false. */
|
|
80
|
+
allowAnonymous?: boolean;
|
|
81
|
+
|
|
82
|
+
/** App-to-app return leg (same-device native flows): an https URL on
|
|
83
|
+
* YOUR login domain — typically your Universal Link / Android App
|
|
84
|
+
* Link — that the wallet opens after delivering the credential, so
|
|
85
|
+
* the OS bounces the user back into your native app. https-only,
|
|
86
|
+
* host must equal the login domain exactly (enforced here AND in
|
|
87
|
+
* the wallet). See SIGN-IN-WITH-PRSON-IDENTITY.md §App-to-app. */
|
|
88
|
+
returnUrl?: string;
|
|
89
|
+
|
|
90
|
+
/** 1..15. Default 10. The credential's `exp` is clamped to this. */
|
|
91
|
+
ttlMinutes?: number;
|
|
92
|
+
|
|
93
|
+
/** UI placement options. */
|
|
94
|
+
ui?: {
|
|
95
|
+
/** DOM selector or HTMLElement to mount the QR + status into. */
|
|
96
|
+
mountQrInto?: string | HTMLElement;
|
|
97
|
+
|
|
98
|
+
/** Theme. Default: matches `prefers-color-scheme`. */
|
|
99
|
+
theme?: "light" | "dark" | "auto";
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Pre-render the QR but DON'T resolve until you call `.proceed()`.
|
|
103
|
+
* Useful when the QR is shown well before the user is ready to
|
|
104
|
+
* scan and you want to control the moment the signaling WS opens. */
|
|
105
|
+
defer?: boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
type SignInResult = {
|
|
109
|
+
/** Compact SD-JWT-VC presentation (issuer JWS + disclosures + KB-JWT). */
|
|
110
|
+
sdJwtVc: string;
|
|
111
|
+
|
|
112
|
+
/** The person's Prson ID for your site: stable across sign-ins, different
|
|
113
|
+
* on every other site. Use it as the user id (it is `cnf.jwk.x`). */
|
|
114
|
+
prsonId: string;
|
|
115
|
+
|
|
116
|
+
/** Verified + decoded disclosed claims, ready to consume. */
|
|
117
|
+
claims: Record<string, unknown>;
|
|
118
|
+
|
|
119
|
+
/** Holder Ed25519 public JWK from cnf.jwk (the key behind `prsonId`). */
|
|
120
|
+
cnf: { jwk: { kty: "OKP"; crv: "Ed25519"; x: string } };
|
|
121
|
+
|
|
122
|
+
/** Credential metadata. */
|
|
123
|
+
credential: {
|
|
124
|
+
vct: string; // VCT URI
|
|
125
|
+
iss: string; // "did:web:app.prson.net"
|
|
126
|
+
kid: string; // notary key thumbprint
|
|
127
|
+
expiresAt: number;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** Live handle for the renewal cycle. */
|
|
131
|
+
session: PrsonLoginSession;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
class PrsonLoginSession {
|
|
135
|
+
readonly expiresAt: number; // ms epoch of credential.exp
|
|
136
|
+
|
|
137
|
+
/** Subscribe to wallet-pushed renewals. Each renewal is already
|
|
138
|
+
* fully verified by the SDK (same checks as the initial sign-in). */
|
|
139
|
+
onRenewed(cb: (fresh: SignInResult) => void): void;
|
|
140
|
+
|
|
141
|
+
/** Fires when the session ends for any reason. */
|
|
142
|
+
onExpiry(cb: (reason: ExpiryReason) => void): void;
|
|
143
|
+
|
|
144
|
+
/** Voluntary local close; tells the wallet the user signed out. */
|
|
145
|
+
close(): void;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
type ExpiryReason =
|
|
149
|
+
| "ttl_reached" // No renewal arrived; the credential lapsed.
|
|
150
|
+
| "wallet_signed_out" // Wallet pushed a `revoke` message.
|
|
151
|
+
| "user_revoked" // Host page called session.close().
|
|
152
|
+
| "network_loss" // WebRTC data channel dropped > 60s.
|
|
153
|
+
| "credential_revoked"; // Future: notary status-list flagged this VC.
|
|
154
|
+
|
|
155
|
+
class PrsonLogin {
|
|
156
|
+
static signIn(opts: SignInOptions): Promise<SignInResult>;
|
|
157
|
+
|
|
158
|
+
/** Re-attach to a session from a previously-stored handle (e.g. the
|
|
159
|
+
* user reloads the page; the SDK can rebind via cnf.jwk). */
|
|
160
|
+
static restore(opts: {
|
|
161
|
+
cnfJwk: SignInResult["cnf"]["jwk"];
|
|
162
|
+
onExpiry?: (reason: ExpiryReason) => void;
|
|
163
|
+
}): Promise<PrsonLoginSession | null>;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 30-second integration
|
|
168
|
+
|
|
169
|
+
```html
|
|
170
|
+
<button id="prson-login-btn">Sign in with Prson</button>
|
|
171
|
+
<div id="prson-login-qr"></div>
|
|
172
|
+
|
|
173
|
+
<script type="module">
|
|
174
|
+
import { PrsonLogin } from "@prson/login-sdk";
|
|
175
|
+
|
|
176
|
+
document.querySelector("#prson-login-btn").addEventListener("click", async () => {
|
|
177
|
+
const result = await PrsonLogin.signIn({
|
|
178
|
+
required: {
|
|
179
|
+
minVerificationLevel: 5,
|
|
180
|
+
predicates: ["age_gte_18"],
|
|
181
|
+
},
|
|
182
|
+
ttlMinutes: 10,
|
|
183
|
+
ui: { mountQrInto: "#prson-login-qr" },
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// result.prsonId is the person's ID on your site (stable across
|
|
187
|
+
// sessions, different on every other site). Forward the full
|
|
188
|
+
// result.sdJwtVc to your backend and re-verify it there with
|
|
189
|
+
// @prson/login-verifier, which gives you the same prsonId.
|
|
190
|
+
await fetch("/api/login", {
|
|
191
|
+
method: "POST",
|
|
192
|
+
body: JSON.stringify({ presentation: result.sdJwtVc }),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Show who is signed in, right away (the ID, or the account name
|
|
196
|
+
// your backend maps it to). Whoever scans the code first signs in,
|
|
197
|
+
// so the person at this screen must be able to see it's them.
|
|
198
|
+
document.querySelector("#who").textContent = `Signed in as ${result.prsonId.slice(0, 8)}…`;
|
|
199
|
+
|
|
200
|
+
result.session.onRenewed(fresh => {
|
|
201
|
+
// Push the fresh credential to your backend on each renewal so
|
|
202
|
+
// server-side TTL tracks the wallet's view of the world.
|
|
203
|
+
fetch("/api/login/renew", { method: "POST", body: JSON.stringify({ presentation: fresh.sdJwtVc }) });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
result.session.onExpiry(reason => {
|
|
207
|
+
console.log("Signed out:", reason);
|
|
208
|
+
location.href = "/";
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
</script>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Plain-HTML, no-bundler, no-npm
|
|
215
|
+
|
|
216
|
+
```html
|
|
217
|
+
<script type="module">
|
|
218
|
+
import { PrsonLogin } from "https://prson.net/vendor/prson-login/prson-login.js";
|
|
219
|
+
|
|
220
|
+
const r = await PrsonLogin.signIn({
|
|
221
|
+
required: { minVerificationLevel: 5 },
|
|
222
|
+
ui: { mountQrInto: "#prson-login-qr" },
|
|
223
|
+
});
|
|
224
|
+
document.querySelector("#hello").textContent = `Hi ${r.claims.given_name ?? "human"}`;
|
|
225
|
+
</script>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Behaviour notes
|
|
229
|
+
|
|
230
|
+
- **Content-Security-Policy.** A site with a CSP must allow Prson's hosts
|
|
231
|
+
in `connect-src` and give the injected styles a nonce
|
|
232
|
+
(`<meta property="csp-nonce" nonce="…">`). The exact lines are in the
|
|
233
|
+
top-level README, under "Content-Security-Policy". A blocked request
|
|
234
|
+
makes `signIn()` reject with `PrsonCspError`, which says what to add.
|
|
235
|
+
- **Codes last 3 minutes** and work once. The dialog offers "Get a new
|
|
236
|
+
code" when one expires, and `signIn()` keeps waiting.
|
|
237
|
+
|
|
238
|
+
- **Same-device detection.** If the SDK detects a touch device + the
|
|
239
|
+
Prson app is installed (universal-link probe), the QR is replaced
|
|
240
|
+
by a "Sign in with Prson" button. The user taps it, the wallet
|
|
241
|
+
opens, the rest is identical.
|
|
242
|
+
- **Native apps (app-to-app).** Open your login page in a Custom Tab /
|
|
243
|
+
`SFSafariViewController` and set `returnUrl` to your Universal Link /
|
|
244
|
+
App Link — the wallet bounces the user back into your app after the
|
|
245
|
+
credential lands. Always use your WEB domain as the audience (never
|
|
246
|
+
the package name): same pairwise user id as your website, and the OS
|
|
247
|
+
app-link verification proves the app↔domain binding. Full pattern:
|
|
248
|
+
`SIGN-IN-WITH-PRSON-IDENTITY.md` §App-to-app.
|
|
249
|
+
- **QR refresh.** Every QR encodes a one-shot `reqId` bound to a
|
|
250
|
+
Cloudflare-Worker draft that's good for **60 seconds** to be
|
|
251
|
+
claimed by a wallet. If the user idles past the draft expiry, the
|
|
252
|
+
SDK calls `POST /session/draft` again and re-renders the QR.
|
|
253
|
+
- **Show who signed in.** A QR can be scanned by anyone who sees it
|
|
254
|
+
(or relayed by a phishing page), and the first phone to claim it signs
|
|
255
|
+
the browser in. Right after `signIn()` resolves — or from the
|
|
256
|
+
`signed_in` event / `session.prsonId` — show the signed-in identity on
|
|
257
|
+
the page (the Prson ID, or the account your backend maps it to), and
|
|
258
|
+
let the person sign out if it isn't them. The page also shows
|
|
259
|
+
"scanned" as soon as any phone claims the code.
|
|
260
|
+
- **Secrets stay on the page.** The live channel never carries password
|
|
261
|
+
or one-time-code values (`type="password"`, or `autocomplete`
|
|
262
|
+
`current-password` / `new-password` / `one-time-code`): `bindInput`
|
|
263
|
+
answers `unsupported`, `bindForm` and `enableRemoteNavigation` skip
|
|
264
|
+
those fields, and an `input` request never sends a password's current
|
|
265
|
+
value.
|
|
266
|
+
- **Authenticated channel.** Every data-channel envelope must come from
|
|
267
|
+
the wallet session key the signed presentation names (KB-JWT
|
|
268
|
+
`prson_wsk`); anything else is dropped. With a Prson app too old to
|
|
269
|
+
sign that key, sign-in still works but remote navigation, mouse and
|
|
270
|
+
file input are off for the session (a console warning says so).
|
|
271
|
+
- **Relay-only WebRTC.** The browser waits for the relay's TURN servers
|
|
272
|
+
(sent once a phone has claimed the code) and uses only relay
|
|
273
|
+
candidates, so its IP addresses never reach the phone.
|
|
274
|
+
- **Renewals.** The SDK *receives* renewals but never *requests* them
|
|
275
|
+
— the wallet is in charge. Your backend just needs to accept a new
|
|
276
|
+
presentation on each `onRenewed`. Within a session a renewal must be
|
|
277
|
+
newer (`iat`) than the last one accepted and is never accepted twice.
|
|
278
|
+
- **Session storage.** The SDK doesn't persist anything to
|
|
279
|
+
localStorage / cookies by default. The host page decides how to
|
|
280
|
+
encode the cnf.jwk identifier (server-side session cookie is the
|
|
281
|
+
obvious default).
|
|
282
|
+
|
|
283
|
+
## Notifications (opt-in)
|
|
284
|
+
|
|
285
|
+
`signIn({ notifications: true })` makes the wallet offer an unticked "Let
|
|
286
|
+
{site} send you notifications" row. If the person ticks it,
|
|
287
|
+
`result.notifications.handle` is a handle for them at your domain (random per
|
|
288
|
+
site). Send it to your backend with the presentation and send from there with
|
|
289
|
+
`@prson/login-verifier`'s `sendNotification` (an API key with `notify:write`).
|
|
290
|
+
A 410 means they turned you off: forget the handle. Rules and limits:
|
|
291
|
+
`documentation/SITE_NOTIFICATIONS.md`.
|
|
292
|
+
|
|
293
|
+
## Backend verification
|
|
294
|
+
|
|
295
|
+
Use [`@prson/login-verifier`](../verifier-node/) — drop-in for
|
|
296
|
+
Node.js. The full verifier in 20 lines:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import { verifyPresentation } from "@prson/login-verifier";
|
|
300
|
+
|
|
301
|
+
app.post("/api/login", async (req, res) => {
|
|
302
|
+
const { presentation } = req.body;
|
|
303
|
+
const result = await verifyPresentation(presentation, {
|
|
304
|
+
expectedAudience: `https://${req.hostname}`,
|
|
305
|
+
expectedNonce: req.session.prsonNonce, // you stored this when you served the page
|
|
306
|
+
});
|
|
307
|
+
if (!result.ok) return res.status(401).send(result.reason);
|
|
308
|
+
|
|
309
|
+
req.session.userId = result.prsonId; // stable per-site id
|
|
310
|
+
res.json({ claims: result.claims });
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Verifications: "sign this PDF", "prove you're 18"
|
|
315
|
+
|
|
316
|
+
Sign-in hands you a credential in the browser. A **verification** is an
|
|
317
|
+
organisation's request made by your server with your API key
|
|
318
|
+
(`POST https://api.prson.net/v1/verifications`): a fact, a verified
|
|
319
|
+
document, a selfie, or a signature on a PDF with the person's
|
|
320
|
+
government-verified name (upload the PDF with
|
|
321
|
+
`POST /v1/verifications/documents`, then a `document_signature`
|
|
322
|
+
requirement). `awaitVerification` shows its `share_url` (a QR code on a
|
|
323
|
+
computer, an "Open in Prson" button on a phone) and waits until your
|
|
324
|
+
server says it's answered. The API key stays on your server.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import { awaitVerification, VerificationClosedError } from "@prson/login-sdk";
|
|
328
|
+
|
|
329
|
+
// Your server created the verification and returns its id and share_url.
|
|
330
|
+
const { id, share_url } = await (await fetch("/api/contract/sign", { method: "POST" })).json();
|
|
331
|
+
try {
|
|
332
|
+
await awaitVerification({
|
|
333
|
+
shareUrl: share_url,
|
|
334
|
+
title: "Sign the rental agreement",
|
|
335
|
+
// Your server calls GET /v1/verifications/{id} (or remembers the verification.* webhooks).
|
|
336
|
+
checkStatus: async (signal) => (await (await fetch(`/api/verifications/${id}`, { signal })).json()).status,
|
|
337
|
+
});
|
|
338
|
+
// fulfilled: your server downloads the signed PDF from the response's signature.download_path.
|
|
339
|
+
} catch (e) {
|
|
340
|
+
if (e instanceof VerificationClosedError) console.log(`The request was ${e.status}`);
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The signed PDF is the uploaded file plus a PAdES signature (B-T, with a
|
|
345
|
+
timestamp) by a certificate naming the person as their chip-read
|
|
346
|
+
identity document does, under the Prson Root CA. It is an **advanced**
|
|
347
|
+
electronic signature under eIDAS, not a qualified one. The response
|
|
348
|
+
carries both SHA-256 hashes (as uploaded, as signed) in Prson's signed
|
|
349
|
+
verdict, and the signed file's first bytes are exactly your upload.
|
|
350
|
+
|
|
351
|
+
## Build status
|
|
352
|
+
|
|
353
|
+
- **Spec**: stable (this folder).
|
|
354
|
+
- **Implementation**: working. `src/index.ts` implements the API above:
|
|
355
|
+
`PrsonLogin.signIn` and the live `PrsonLoginSession`, the request
|
|
356
|
+
channel (`bindInput`, `bindForm`, `bindMouse`,
|
|
357
|
+
`enableRemoteNavigation`), presentation and status-list checks,
|
|
358
|
+
website notifications (`NOTIFY_HANDLE`, `notifyHandleFrom`) and
|
|
359
|
+
verifications (`awaitVerification`). One exception:
|
|
360
|
+
`PrsonLogin.restore()` always resolves `null`, because the SDK keeps
|
|
361
|
+
no state across page loads (your server's session is the source of
|
|
362
|
+
truth). Tests: `npm test`.
|
|
363
|
+
- **Distribution**: npm (`@prson/login-sdk`) and the browser bundle at
|
|
364
|
+
`https://prson.net/vendor/prson-login/`. See
|
|
365
|
+
[`../../CHANGELOG.md`](../../CHANGELOG.md).
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The verifier-side request blob the SDK assembles + sends to /session/draft. */
|
|
2
|
+
export type VerifierRequest = {
|
|
3
|
+
domain: string;
|
|
4
|
+
nonce: string;
|
|
5
|
+
browserPk: string;
|
|
6
|
+
required: {
|
|
7
|
+
/** 0 = pseudonymous (unverified identity) accepted; omitted ⇒ 1. */
|
|
8
|
+
minVerificationLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
9
|
+
requiredClaims?: string[];
|
|
10
|
+
predicates?: string[];
|
|
11
|
+
identityType?: "personal" | "organization";
|
|
12
|
+
/** Require a domain-scoped unique-human id (document-anchored). */
|
|
13
|
+
uniqueHumanId?: boolean;
|
|
14
|
+
};
|
|
15
|
+
ttlMaxMinutes: number;
|
|
16
|
+
/** Data-channel envelope version the SDK speaks (2 = sender-authenticated). */
|
|
17
|
+
envelopeVersion?: number;
|
|
18
|
+
};
|
|
19
|
+
export type DraftResult = {
|
|
20
|
+
reqId: string;
|
|
21
|
+
/** Bearer used on the WS upgrade `Sec-WebSocket-Protocol` header. */
|
|
22
|
+
draftToken: string;
|
|
23
|
+
/** wss URL the SDK opens to join the Durable Object as the browser peer. */
|
|
24
|
+
signalingWss: string;
|
|
25
|
+
/** Epoch s — caller has until this moment for a wallet to claim. */
|
|
26
|
+
draftExpiresAt: number;
|
|
27
|
+
/**
|
|
28
|
+
* **Server-issued timestamp** (epoch seconds, M-3 / v2). The Worker
|
|
29
|
+
* stamped it at draft creation and stored it in the DO. The wallet
|
|
30
|
+
* MUST echo this value verbatim in its `prson-login-claim/v2`
|
|
31
|
+
* signature — the Worker rebuilds the canonical bytes using its
|
|
32
|
+
* stored copy, so any tamper breaks the signature. The SDK threads
|
|
33
|
+
* it through the QR (`t=` param).
|
|
34
|
+
*/
|
|
35
|
+
serverTs: number;
|
|
36
|
+
/**
|
|
37
|
+
* OLDER relays only: Cloudflare TURN credentials for the browser side,
|
|
38
|
+
* minted at draft time. Current relays omit this and instead send
|
|
39
|
+
* `{ "type": "ice", "iceServers": [...] }` over the WebSocket once a
|
|
40
|
+
* wallet has claimed the code, so no relay capacity is minted for a
|
|
41
|
+
* code nobody scans. Either way the browser runs relay-only (see
|
|
42
|
+
* transport.ts `rtcConfigFor`). Wire grammar matches `RTCIceServer`.
|
|
43
|
+
*/
|
|
44
|
+
turn?: {
|
|
45
|
+
urls: string | string[];
|
|
46
|
+
username: string;
|
|
47
|
+
credential: string;
|
|
48
|
+
expiresAt?: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* POST /session/draft on the Cloudflare Worker. Anonymous + IP rate-
|
|
53
|
+
* limited at 30 drafts/IP/min (no TURN allocated yet — the Worker
|
|
54
|
+
* waits for a wallet to claim before issuing any relay capacity).
|
|
55
|
+
*/
|
|
56
|
+
export declare function createDraft(request: VerifierRequest, opts?: {
|
|
57
|
+
signalingBase?: string;
|
|
58
|
+
fetchImpl?: typeof fetch;
|
|
59
|
+
}): Promise<DraftResult>;
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed HTTPS wrappers around the Cloudflare Worker's session API.
|
|
3
|
+
*
|
|
4
|
+
* The SDK does NOT depend on Firebase. The Worker is the single API
|
|
5
|
+
* surface: anonymous /session/draft for the browser, wallet-signed
|
|
6
|
+
* /session/claim for the wallet. See `../../../../cloudflare-workers/signaling-worker`
|
|
7
|
+
* for the server impl and `../../ARCHITECTURE.md` for the spec.
|
|
8
|
+
*/
|
|
9
|
+
import { PrsonLoginError } from "./errors.js";
|
|
10
|
+
import { SIGNALING_BASE } from "./index.js";
|
|
11
|
+
/**
|
|
12
|
+
* POST /session/draft on the Cloudflare Worker. Anonymous + IP rate-
|
|
13
|
+
* limited at 30 drafts/IP/min (no TURN allocated yet — the Worker
|
|
14
|
+
* waits for a wallet to claim before issuing any relay capacity).
|
|
15
|
+
*/
|
|
16
|
+
export async function createDraft(request, opts = {}) {
|
|
17
|
+
const base = opts.signalingBase ?? SIGNALING_BASE;
|
|
18
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
19
|
+
const res = await fetchImpl(`${base}/session/draft`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
mode: "cors",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
body: JSON.stringify({ request }),
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) {
|
|
26
|
+
const text = await safeText(res);
|
|
27
|
+
if (res.status === 429) {
|
|
28
|
+
throw new PrsonLoginError("rate_limited", "Too many login sessions from this network — please retry shortly.");
|
|
29
|
+
}
|
|
30
|
+
throw new PrsonLoginError("network", `createDraft failed: HTTP ${res.status} ${text || res.statusText}`);
|
|
31
|
+
}
|
|
32
|
+
return (await res.json());
|
|
33
|
+
}
|
|
34
|
+
async function safeText(res) {
|
|
35
|
+
try {
|
|
36
|
+
return await res.text();
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
}
|