@agimon-ai/po-identity 0.0.2-alpha.11 → 0.0.2-alpha.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -263
- package/dist/account.cjs +26 -0
- package/dist/account.d.mts +6 -0
- package/dist/account.mjs +6 -0
- package/dist/constants/accountPages.cjs +26 -0
- package/dist/constants/accountPages.d.mts +11 -0
- package/dist/constants/accountPages.mjs +24 -0
- package/dist/desktopAccount.cjs +6 -0
- package/dist/desktopAccount.d.mts +3 -0
- package/dist/desktopAccount.mjs +1 -0
- package/dist/extensions/native.cjs +21 -0
- package/dist/extensions/native.d.mts +8 -0
- package/dist/extensions/native.mjs +17 -0
- package/dist/phone.cjs +15 -0
- package/dist/phone.d.mts +9 -0
- package/dist/phone.mjs +5 -0
- package/dist/services/accountGrants/index.cjs +102 -0
- package/dist/services/accountGrants/index.d.mts +36 -0
- package/dist/services/accountGrants/index.mjs +102 -0
- package/dist/services/accountRoster/index.cjs +300 -0
- package/dist/services/accountRoster/index.d.mts +100 -0
- package/dist/services/accountRoster/index.mjs +291 -0
- package/dist/services/accountTrust/index.cjs +163 -0
- package/dist/services/accountTrust/index.d.mts +75 -0
- package/dist/services/accountTrust/index.mjs +159 -0
- package/dist/services/desktopAccount/index.cjs +395 -0
- package/dist/services/desktopAccount/index.d.mts +14 -0
- package/dist/services/desktopAccount/index.mjs +392 -0
- package/dist/services/desktopAccount/type.d.mts +75 -0
- package/dist/services/hostedAccount/index.cjs +197 -0
- package/dist/services/hostedAccount/index.d.mts +26 -0
- package/dist/services/hostedAccount/index.mjs +195 -0
- package/dist/services/hostedAccount/type.d.mts +43 -0
- package/dist/services/hostedAccountFlow/index.cjs +159 -0
- package/dist/services/hostedAccountFlow/index.d.mts +26 -0
- package/dist/services/hostedAccountFlow/index.mjs +158 -0
- package/dist/services/hostedAccountFlow/type.d.mts +51 -0
- package/dist/services/issuerSelection/index.cjs +24 -0
- package/dist/services/issuerSelection/index.d.mts +12 -0
- package/dist/services/issuerSelection/index.mjs +24 -0
- package/dist/services/phoneAccount/index.cjs +392 -0
- package/dist/services/phoneAccount/index.d.mts +162 -0
- package/dist/services/phoneAccount/index.mjs +391 -0
- package/dist/services/phoneAccount/type.d.mts +45 -0
- package/dist/services/phoneAccountFlow/index.cjs +594 -0
- package/dist/services/phoneAccountFlow/index.d.mts +41 -0
- package/dist/services/phoneAccountFlow/index.mjs +592 -0
- package/dist/services/phoneAccountFlow/type.d.mts +122 -0
- package/dist/services/teamClient/index.cjs +181 -0
- package/dist/services/teamClient/index.d.mts +32 -0
- package/dist/services/teamClient/index.mjs +179 -0
- package/dist/services/teamClient/type.d.mts +38 -0
- package/dist/team.cjs +5 -0
- package/dist/team.d.mts +3 -0
- package/dist/team.mjs +1 -0
- package/package.json +30 -35
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/apiContracts.cjs +0 -280
- package/dist/apiContracts.d.mts +0 -202
- package/dist/apiContracts.mjs +0 -273
- package/dist/extensions/server.cjs +0 -97
- package/dist/extensions/server.d.mts +0 -5
- package/dist/extensions/server.mjs +0 -91
- package/dist/index.cjs +0 -14
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -7
- package/dist/services/appleTokens/index.cjs +0 -68
- package/dist/services/appleTokens/index.d.mts +0 -16
- package/dist/services/appleTokens/index.mjs +0 -68
- package/dist/services/emailSender/index.cjs +0 -22
- package/dist/services/emailSender/index.d.mts +0 -16
- package/dist/services/emailSender/index.mjs +0 -22
- package/dist/services/identityConfiguration/index.cjs +0 -51
- package/dist/services/identityConfiguration/index.d.mts +0 -39
- package/dist/services/identityConfiguration/index.mjs +0 -51
- package/dist/services/identityHome/index.cjs +0 -1236
- package/dist/services/identityHome/index.d.mts +0 -121
- package/dist/services/identityHome/index.mjs +0 -1235
- package/dist/services/identityHome/roster.cjs +0 -274
- package/dist/services/identityHome/roster.mjs +0 -272
- package/dist/services/sqliteAdapter/index.cjs +0 -138
- package/dist/services/sqliteAdapter/index.d.mts +0 -8
- package/dist/services/sqliteAdapter/index.mjs +0 -137
package/README.md
CHANGED
|
@@ -1,268 +1,16 @@
|
|
|
1
1
|
# Po identity
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
owner membership and unique subject marker in one transaction.
|
|
3
|
+
The account client for Po. It signs people in and keeps their device trust on the phone, Desktop and
|
|
4
|
+
web, and manages their Team. It holds no auth server code: the issuer lives in
|
|
5
|
+
`@agimon-ai/po-auth-server`, and the wire shapes both sides share live in `@agimon-ai/po-core`.
|
|
7
6
|
|
|
8
|
-
##
|
|
7
|
+
## Entries
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
- `./phone`: the phone's account (`createPhoneAccount`, `createHostedAccount`) and their sign-in flows.
|
|
10
|
+
- `./account`: account pages, device trust, the host roster and renewable consent grants.
|
|
11
|
+
- `./desktopAccount`: Desktop's "Sign in with Po" device authorization, run in the main process.
|
|
12
|
+
- `./team`: the Team client shared by web, Desktop and the phone. Each platform lends its own
|
|
13
|
+
credentials and fetch; the renderer never sees a cookie.
|
|
14
|
+
- `./extensions/native`: the bundled phone plugin.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- `PO_IDENTITY_ISSUER`, `PO_IDENTITY_JWT_KEY_WRAP` (at least 32 characters).
|
|
19
|
-
- `PO_UNSENDBOX_ENDPOINT`, `PO_UNSENDBOX_ORGANIZATION_ID`, `PO_UNSENDBOX_API_KEY`, `PO_UNSENDBOX_FROM`.
|
|
20
|
-
|
|
21
|
-
Optional OAuth configuration: `PO_APPLE_CLIENT_ID`, `PO_APPLE_CLIENT_SECRET`, `PO_APPLE_BUNDLE_ID`,
|
|
22
|
-
`PO_GOOGLE_CLIENT_ID`, `PO_GOOGLE_CLIENT_SECRET`, `PO_MICROSOFT_CLIENT_ID`,
|
|
23
|
-
`PO_MICROSOFT_CLIENT_SECRET`, `PO_GITHUB_CLIENT_ID`, `PO_GITHUB_CLIENT_SECRET`.
|
|
24
|
-
An enabled provider requires its secret. Apple's client secret is a server-held Apple client-secret
|
|
25
|
-
JWT, never an app credential. Operators must renew it before expiry. Native code exchange uses the
|
|
26
|
-
bundle ID when configured, rather than silently exchanging a native code as a web Services ID.
|
|
27
|
-
|
|
28
|
-
`PO_IDENTITY_WEB_RP_ID` enables web account passkeys against the configured issuer origin. Native
|
|
29
|
-
account passkeys remain disabled. Expo trusts `po://`; native scheme/capability changes belong
|
|
30
|
-
to phase 2. SSO includes OIDC and SAML, with no unsolicited-login override.
|
|
31
|
-
|
|
32
|
-
Node stores `identity.sqlite` under the admitted Po home, respecting `PO_HOME`. The Worker binds
|
|
33
|
-
`PO_IDENTITY` to one `PoIdentityObject` per configured issuer. Secrets are operator bindings, not
|
|
34
|
-
checked-in values. Hosts must serve the issuer through trusted HTTPS in production.
|
|
35
|
-
|
|
36
|
-
## Issuer endpoints
|
|
37
|
-
|
|
38
|
-
All paths are under `/api/auth/`. Node mounts them only when the global identity API is composed.
|
|
39
|
-
The Worker branches to the identity object before its legacy attach-token gate. Other routes keep
|
|
40
|
-
their existing authorization. Better Auth's session-only `/token` and built-in deletion endpoints
|
|
41
|
-
are disabled: they must not bypass device binding or the deletion outbox.
|
|
42
|
-
|
|
43
|
-
- Better Auth: email OTP, magic link, configured social providers, SSO and optional web passkeys.
|
|
44
|
-
- `GET jwks`: public signing keys. Private keys and OAuth tokens are wrapped at rest.
|
|
45
|
-
- `POST personal-org`: authenticated lazy provisioning.
|
|
46
|
-
- `POST devices/enroll`: authenticated first-device TOFU with proof of the new private key.
|
|
47
|
-
A durable enrollment marker forbids another TOFU after enrollment or revocation.
|
|
48
|
-
Returns a 256-bit recovery code once; only a salted PBKDF2-SHA-256 hash (600,000 iterations)
|
|
49
|
-
is stored. Optional `assurance: "hardware" | "software"` is signed and stored as self-reported.
|
|
50
|
-
Software enrollment is allowed; App Attest and Play Integrity are future attestation upgrades.
|
|
51
|
-
Later devices need a current trusted-device C10 `approval` or an owned hub's `hubEnrollment`.
|
|
52
|
-
- `POST identity-token`: session plus fresh enrolled-device proof, current person and membership.
|
|
53
|
-
C1 claims bind the device JWK thumbprint and network audience, with a 600-second lifetime.
|
|
54
|
-
- `POST delegated-token`: fresh calling-host proof plus enrolled-device-signed C5 consent. It needs
|
|
55
|
-
no person session. The composition must supply `callingHostKey(networkId, hostId)` from current
|
|
56
|
-
roster authority. Without that port it fails closed, not to a caller-advertised key. C2 binds
|
|
57
|
-
the host key, host ID and grant ID; expiry is the smaller of one hour and grant expiry.
|
|
58
|
-
- `POST device-key`: cookie-free lookup with `IdentityDeviceKeyRequest` from `apiContracts`.
|
|
59
|
-
Send `{proof}` signed with `po/host-request/v1` over `{issuer, hostId, keyId, issuedAt,
|
|
60
|
-
expiresAt, nonce}` by the hub key previously admitted through `hubs/claim`. Lifetime is at
|
|
61
|
-
most 60 seconds, with the same conservative 30-second skew deadline. Nonces (16 to 128
|
|
62
|
-
base64url characters) are durably single-use per host, including failed key lookups.
|
|
63
|
-
Returns `{keyId, issuer, subject, publicKey, revoked, revocationEpoch, trust, organizationId}`
|
|
64
|
-
from the registry,
|
|
65
|
-
never from caller-advertised keys. Only the claiming person's keys or keys of current
|
|
66
|
-
members of a hub's claimed organization where its claimant is still a member are visible. Unknown, out-of-scope, malformed,
|
|
67
|
-
stale, replayed, unenrolled and revoked-host requests all return the same no-store 404.
|
|
68
|
-
Migration 3 preserves legacy owner-only hub scope; fresh valid claims record org scopes,
|
|
69
|
-
including multiple organizations per hub.
|
|
70
|
-
The registry's `identity_hub.revoked` flag refuses lookup and further enrollment/claims.
|
|
71
|
-
- `GET devices`: same-person device list, public account keys, trust, self-reported assurance,
|
|
72
|
-
current person `revocationEpoch`, the durable `hasEnrolled` marker and any pending recovery.
|
|
73
|
-
- `POST devices/approval/request`: signed-in new-key `approval-request` proof creates an opaque
|
|
74
|
-
16-character, five-minute code. `GET devices/approval?code=...` is same-person lookup/polling;
|
|
75
|
-
`POST devices/approval` admits the trusted device's signed C10 envelope. The new device then
|
|
76
|
-
calls `devices/enroll` with a fresh new-key proof and that approval. Final admission is durable
|
|
77
|
-
and single-use. Both devices must be signed in; no email address enters the approval.
|
|
78
|
-
- `POST hubs/claim`: current enrolled-device C10 claim plus the nested QR host attestation records
|
|
79
|
-
the person's hub key. The hub must independently enforce its own local pin; the issuer never
|
|
80
|
-
authorizes on its behalf. Advertised unregistered hub keys cannot approve enrollment.
|
|
81
|
-
- `POST devices/recovery/code`: `{proof, recoveryCode}` with action `recover-code` enrolls at once
|
|
82
|
-
and consumes the code. `POST devices/recovery/start`: `{proof}` with action `recover-start`
|
|
83
|
-
persists a 72-hour due time. It durably queues a start email with a cancel link and one notice
|
|
84
|
-
per trusted device through `notifyTrustedDevice`. Missing or failed delivery ports leave jobs
|
|
85
|
-
pending. The email token is hashed in the pending row and wrapped in the delivery outbox.
|
|
86
|
-
- `POST devices/recovery/cancel`: `{cancelToken}` from email, or `{proof}` signed by a trusted
|
|
87
|
-
same-person device or the requesting new device. Action `cancel-recovery` binds
|
|
88
|
-
`targetDeviceId` to the recovery ID. The email GET only displays confirmation, avoiding
|
|
89
|
-
mutation by link scanners. Completion durably queues a second email.
|
|
90
|
-
- `POST devices/recovery/admin-approve`: current enrolled org owner/admin proof, action
|
|
91
|
-
`admin-approve`, `org` the limiting organization and `targetDeviceId` the pending recovery ID.
|
|
92
|
-
The signed-in pending device and admin must both belong to that organization. The resulting
|
|
93
|
-
device can mint only for that org and cannot approve unrestricted devices or claim hubs.
|
|
94
|
-
- `POST devices/revoke`: enrolled-device proof and a same-person target. Revocation immediately
|
|
95
|
-
stops new mints, including C2 grants signed by that device.
|
|
96
|
-
- `GET revocations?after=<sequence>`: public cursor feed, no addresses or credentials, no cache.
|
|
97
|
-
Enrolled hosts can fetch it without a person cookie or host proof.
|
|
98
|
-
- `POST delete-account`: refuses a sole company owner with other members, deletes person-owned
|
|
99
|
-
identity and device records, emits revocation, and durably queues personal-org/cloud-workspace
|
|
100
|
-
purge and Apple revocation before removing credentials.
|
|
101
|
-
|
|
102
|
-
Proofs use `identityProofFields(issuer, subject, action, proof)` with the tag
|
|
103
|
-
`po/identity-mint/v1` and P-256 SHA-256 P1363 base64url signatures. Actions include `enroll`, `mint`, `delegate`, `revoke`, `approval-request`, `recover-code`,
|
|
104
|
-
`recover-start`, `cancel-recovery` and `admin-approve`. The helper binds timestamps, nonce, org, device ID, optional enrollment
|
|
105
|
-
key, optional revocation target and the exact serialized grant. Proof times are milliseconds;
|
|
106
|
-
JWT dates are seconds. Proof lifetime is at most 60 seconds. Future issue time is at most 30
|
|
107
|
-
seconds; acceptance ends at expiry minus 30 seconds, inclusive. When supplied, assurance appends `["assurance", value]` to the signed fields; omitted assurance
|
|
108
|
-
keeps phase-1 signed bytes unchanged. Nonces are admitted durably in
|
|
109
|
-
transactions before tokens are released. Signing is followed by a current-authority recheck.
|
|
110
|
-
A destination still needs phase-3 JWT validation, C3/C4 proofs, durable nonce admission and local
|
|
111
|
-
authorization. Issuance is not workspace permission.
|
|
112
|
-
|
|
113
|
-
Native Apple sign-in sends `authorizationCode` beside `idToken: { token, nonce }` to
|
|
114
|
-
`sign-in/social`. Missing code or nonce is refused. The issuer verifies Apple's JWKS, issuer,
|
|
115
|
-
audience, time and nonce, exchanges the one-use code, verifies the exchanged subject and stores
|
|
116
|
-
an encrypted issuer/subject/provider-bound refresh credential before returning a session.
|
|
117
|
-
Deletion retains that ciphertext through Apple outages and retries via the outbox. No refresh
|
|
118
|
-
token is returned to the app. Provider response bodies and addresses are never logged.
|
|
119
|
-
|
|
120
|
-
## Persistence and limits
|
|
121
|
-
|
|
122
|
-
The SQLite adapter is the Better Auth spike adapter moved into runtime source, with literal predicates,
|
|
123
|
-
one-row versus many-row mutations, transaction-local executors, counts and versioned migration
|
|
124
|
-
admission. Initial schema creation is tied to the pinned plugin versions. Plugin/schema upgrades
|
|
125
|
-
need explicit new migrations; this is not a general Better Auth migration engine or a completed
|
|
126
|
-
upstream adapter conformance certification. The Node/workerd rollback and concurrency tests
|
|
127
|
-
now import the real package adapter.
|
|
128
|
-
|
|
129
|
-
Node drains the identity outbox on start and periodically. Recovery uses the injected
|
|
130
|
-
`scheduleRecovery` port and a Node scheduler. The identity DO's single alarm multiplexes recovery
|
|
131
|
-
due times and outbox retries; both deadlines are restored from SQLite after reconstruction.
|
|
132
|
-
`runDueRecovery` uses the injected clock and atomically completes only due, uncancelled requests.
|
|
133
|
-
|
|
134
|
-
Every completed recovery increments the person's epoch atomically with device insertion and a
|
|
135
|
-
feed row carrying `epoch`. The recovered device stores that enrollment epoch. SQLite refuses
|
|
136
|
-
non-increasing epoch updates. Other enrolled devices stay trusted, but C5 `revocationEpoch` must
|
|
137
|
-
exactly equal the current epoch to mint C2. Missing grant epochs mean zero, deliberately voiding
|
|
138
|
-
all legacy grants after the first recovery. C1/C2 JWTs carry `revocation_epoch`.
|
|
139
|
-
|
|
140
|
-
Phase 3 still needs destination JWT/feed checks. A pre-recovery identity token can remain valid
|
|
141
|
-
until its own expiry, at most ten minutes, at a destination that has not fetched the feed.
|
|
142
|
-
Delegated tokens retain their existing at-most-one-hour expiry. Propagation is not bounded here.
|
|
143
|
-
|
|
144
|
-
Hub policy is exported as `createHubDeviceTrust` from core's remote-access store. Owner claims,
|
|
145
|
-
account pins and replay admission persist in `hub-trust.json`. Approval requires a device already
|
|
146
|
-
pinned here and verified current issuer device authority. Recovered keys need a fresh QR pin in
|
|
147
|
-
the current recovery epoch. Issuer enrollment alone is never owner-level authority. Phase 3 must
|
|
148
|
-
compose this gate into federation control routes; it is intentionally not wired into legacy
|
|
149
|
-
layer-2 native registration, whose host-scoped keys differ from the account device key.
|
|
150
|
-
|
|
151
|
-
### Phase-4 provisioning API
|
|
152
|
-
|
|
153
|
-
`ensurePersonalOrg(subject, 'cloud-workspace')` atomically creates the personal org, owner membership,
|
|
154
|
-
unique `(issuer, subject)` marker, first workspace allocation and materialization outbox item.
|
|
155
|
-
Concurrent calls and retries return the same `{orgId, workspaceId}`. Slug collisions retry inside
|
|
156
|
-
that transaction (up to 16 attempts). Existing subject-only markers migrate without replacing orgs.
|
|
157
|
-
`PersonalOrgTrigger` reserves `own-hub-link` for phase 5; it is currently refused.
|
|
158
|
-
|
|
159
|
-
The authenticated `POST personal-org` accepts `{trigger: "cloud-workspace"}` and returns
|
|
160
|
-
`{organizationId, orgId, workspaceId}` for bootstrap before device enrollment and token minting.
|
|
161
|
-
Legacy `{}` and `personalOrg(subject)` remain org-only compatibility calls. Signup still creates no org.
|
|
162
|
-
|
|
163
|
-
The trusted internal API also exposes `allocateWorkspace(subject, orgId)` (a new allocation per call),
|
|
164
|
-
`listOrgWorkspaces(subject, orgId)` and `isWorkspaceAllocatedToOrg(subject, orgId, workspaceId)`.
|
|
165
|
-
All require a current account and org membership. The last method returns false for unallocated ids.
|
|
166
|
-
The Worker must authenticate the subject before calling these methods; they are not bearer endpoints.
|
|
167
|
-
`orgRole` and `federationAuthority` expose live membership and device/epoch authority to its verifier.
|
|
168
|
-
The latter fails closed on issuer, membership, device revocation and restricted-org mismatches.
|
|
169
|
-
|
|
170
|
-
`listProvisioningOutbox()` returns typed `{id, kind: "materialize-workspace", payload: {orgId, workspaceId}}`
|
|
171
|
-
items only. `ackProvisioningOutbox(id)` is idempotent and cannot ack recovery, purge or Apple jobs.
|
|
172
|
-
Alternatively the host supplies `materializeWorkspace(payload)` and calls `drainOutbox()` (also used
|
|
173
|
-
by `runDueRecovery`). Missing consumers and failed deliveries stay pending. Materialization is an
|
|
174
|
-
at-least-once, separate cross-object step: its consumer must be idempotent. Hosts restore retry
|
|
175
|
-
alarms from persisted pending jobs on boot and schedule after allocation. Identity commits never
|
|
176
|
-
claim cross-object atomicity. Deletion cancels personal-org allocation/materialization records and
|
|
177
|
-
queues the existing purge job. Host-side purge and in-flight materialization need coordinated
|
|
178
|
-
idempotent handling; production alarm delivery and full cloud deletion remain Worker verification.
|
|
179
|
-
|
|
180
|
-
Types are exported from the package root and `apiContracts`. No dependency changes are required.
|
|
181
|
-
Registry migration 4 adds provisioning tables and repairs the monotonic epoch update trigger when
|
|
182
|
-
opening older v2 databases that did not have it. SQLite upgrade tests preserve v2 devices, hubs and
|
|
183
|
-
pending outbox data. The purge consumer is a host port. Until wired, purge jobs remain pending durably.
|
|
184
|
-
No purge SLA, roster cadence or emergency JWKS-cache bound is invented here.
|
|
185
|
-
Calling-host roster authority and destination authorization remain separate phases. Apple exchange/revocation tests use fake HTTP providers. Real providers, native
|
|
186
|
-
Apple return, deployment, production quotas and provider key rotation remain unverified.
|
|
187
|
-
|
|
188
|
-
## Phase-1 local evidence
|
|
189
|
-
|
|
190
|
-
Final checks in the multihost worktree:
|
|
191
|
-
|
|
192
|
-
```sh
|
|
193
|
-
NX_DAEMON=false pnpm nx run-many -p @agimon-ai/po-identity @agimon-ai/po-cloudflare @agimon-ai/po-core @agimon-ai/po-web-security @agimon-ai/po -t lint,typecheck,build --parallel=1 --output-style=static
|
|
194
|
-
NX_DAEMON=false pnpm nx run @agimon-ai/po-cloudflare:test --maxWorkers=1 --output-style=static
|
|
195
|
-
NX_DAEMON=false pnpm nx run-many -p @agimon-ai/po-identity @agimon-ai/po-core @agimon-ai/po-web-security @agimon-ai/po -t test --parallel=1 --output-style=static
|
|
196
|
-
pnpm --filter @agimon-ai/po-cloudflare exec wrangler deploy --dry-run --outdir .wrangler/identity-bundle
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
All listed Nx targets passed. Full test counts: identity 11, Cloudflare 64, core 1,981, security 126,
|
|
200
|
-
CLI 962 passed with one existing skipped test. A parallel run hit the already documented isolate
|
|
201
|
-
memory-test duration bound; the isolated rerun and full single-worker Cloudflare suite passed.
|
|
202
|
-
No isolate code, assertions or time bounds were changed. Worktree-local vibe-lint preflight,
|
|
203
|
-
including `po-edge-portable`, and `git diff --check` passed.
|
|
204
|
-
|
|
205
|
-
Wrangler 4.150.0 reported total upload **13,553.00 KiB raw, 3,129.00 KiB gzip**. The main emitted
|
|
206
|
-
`worker.js` was **13,375,137 raw bytes, 2,969,373 gzip bytes**; total upload also includes WASM.
|
|
207
|
-
This is the composed Po Worker, including identity and SAML, not the smaller Better Auth and SAML spikes.
|
|
208
|
-
It exceeds a 3 MiB compressed free-worker ceiling. Paid-plan limits, deployment, CPU/startup
|
|
209
|
-
budgets and actual production-provider behavior were not verified. Dry-run artifacts remain ignored.
|
|
210
|
-
|
|
211
|
-
## Phase-2 verification boundary
|
|
212
|
-
|
|
213
|
-
Focused protocol tests cover signed approval chains, forgery/expiry/replay refusal, owned-hub
|
|
214
|
-
attestation admission, one-use recovery codes, software assurance, org-only admin recovery,
|
|
215
|
-
monotonic epochs, stale/invalid grant epochs, email and device cancellation, exact 72-hour
|
|
216
|
-
completion and restart. A shared fixture runs the real KDF and signature/envelope helpers on
|
|
217
|
-
both Node SQLite and workerd DO SQLite, with only delivery, scheduling and time injected.
|
|
218
|
-
The hub-store tests cover account-association round trips, durable claims and approval chains,
|
|
219
|
-
and recovered-device owner denial until QR. A diagnostic spy checks no recovery address is logged.
|
|
220
|
-
|
|
221
|
-
Real email deliverability, the native push adapter, production DO alarm delivery across eviction,
|
|
222
|
-
production issuer-to-hub authority synchronization and end-to-end native QR attestation remain
|
|
223
|
-
unverified. No dependency or lockfile changes are needed by this protocol implementation.
|
|
224
|
-
|
|
225
|
-
## Network roster issuer (phase 5)
|
|
226
|
-
|
|
227
|
-
- `GET /api/auth/roster-metadata` publishes `{issuer, rosterPublicKey}`. The key is base64url DER
|
|
228
|
-
P-256 SPKI, not PEM. Claim-time discovery must fetch it from the already trusted issuer and pin
|
|
229
|
-
it locally, never trust a key in a roster response. The dedicated private roster key is persisted
|
|
230
|
-
encrypted with `jwtKeyWrap`. No route exposes it. Rotation currently requires every hub to re-pin;
|
|
231
|
-
the upgrade path is signed key-transition records.
|
|
232
|
-
- `POST /api/networks/own-hub-link` returns `{networkId}` and lazily creates one personal org per
|
|
233
|
-
person in the existing transaction. It does not allocate a cloud workspace.
|
|
234
|
-
- `GET /api/networks/:networkId/roster` returns an issuer-signed C6 envelope. Current member identity
|
|
235
|
-
tokens (ES256, issuer and network audience, live membership, device and recovery epoch) or existing
|
|
236
|
-
signed-in sessions are accepted. Host polling may instead send `x-po-roster-proof`: a JSON
|
|
237
|
-
`po/host-request/v1` envelope signed by the current host key, with `{networkId, hostId,
|
|
238
|
-
destination: issuer, method: 'GET', path: exactPathname, nonce, issuedAt, expiresAt}`. Envelope freshness
|
|
239
|
-
and durable single-use nonces apply; removed or evicted hosts cannot poll.
|
|
240
|
-
- `POST /api/networks/:networkId/hosts` accepts `{entry}` from the entry owner's current membership;
|
|
241
|
-
`POST /api/networks/:networkId/changes` accepts `{change}` from an owner or admin. A change names
|
|
242
|
-
the next epoch. Before any epoch or eviction write, the issuer verifies host entries against the
|
|
243
|
-
submitting owner's enrolled, non-revoked device, and eviction/voter changes against a current
|
|
244
|
-
org owner's enrolled, non-revoked device. Durable records verify as of issuance, with at most
|
|
245
|
-
30 seconds of future skew. Term changes require a current voter host's own key and verify at
|
|
246
|
-
the current time. These enrollment checks do not replace `applyRoster` with independently pinned keys.
|
|
247
|
-
Host entries, changes and all Better Auth membership writes advance the epoch transactionally.
|
|
248
|
-
Membership removal permanently marks that person's host IDs unavailable.
|
|
249
|
-
- Composition APIs on `createIdentityHome()` are `networkRoster(subject, networkId)`,
|
|
250
|
-
`registerRosterHost(subject, networkId, entry)`, `registerRosterChange(subject, networkId, change)`,
|
|
251
|
-
`rosterIssuerPublicKey()`, `hostKey(networkId, hostId)`, `rosterPins(subject, networkId)`, and
|
|
252
|
-
`registerCloudRosterHost(subject, networkId, {hostId, publicKey, endpoints?})`. The cloud helper
|
|
253
|
-
signs with the issuer and uses reserved device key ID `issuer-roster`; identical calls preserve
|
|
254
|
-
the original owner and epoch. `rosterPins` supplies `{hostId, issuer, subject, keyId, publicKey}`
|
|
255
|
-
records for Po Cloud only. Its trust ceiling is issuer-enrolled devices, not local hub pins.
|
|
256
|
-
|
|
257
|
-
Snapshots retain all evictions, the latest voter change per live host, and the current epoch's term
|
|
258
|
-
changes. The issuer orders these records and may withhold changes. A new joiner skips an eviction
|
|
259
|
-
it cannot verify only if the target host is absent from both its local state and the snapshot.
|
|
260
|
-
It then lacks that tombstone, so a malicious issuer could later re-include an old device-signed host
|
|
261
|
-
entry. Independent hub pins remain mandatory. Compaction requires a signed checkpoint. Roster authorization does not replace C9 quorum commitment, and this issuer
|
|
262
|
-
does not claim Byzantine safety or availability in small networks.
|
|
263
|
-
|
|
264
|
-
Durable device host entries and owner voter/eviction decisions verify as of issuance, including on
|
|
265
|
-
catch-up after their declared expiry. The fresh issuer snapshot supplies freshness. Term diagnostics
|
|
266
|
-
still verify at the current time. Local pin revocation or rotation removes the old key's authority,
|
|
267
|
-
so its old records stop verifying. A compromised still-pinned owner key can backdate records until
|
|
268
|
-
it is unpinned; the issuer cannot correct a host's local trust decision.
|
|
16
|
+
Better Auth's client API and its Expo client are pinned to 1.7.12, the same release as the server.
|
package/dist/account.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_accountPages = require("./constants/accountPages.cjs");
|
|
3
|
+
const require_index = require("./services/accountGrants/index.cjs");
|
|
4
|
+
const require_index$1 = require("./services/accountRoster/index.cjs");
|
|
5
|
+
const require_index$2 = require("./services/accountTrust/index.cjs");
|
|
6
|
+
const require_index$3 = require("./services/issuerSelection/index.cjs");
|
|
7
|
+
exports.ACCOUNT_BACK = require_accountPages.ACCOUNT_BACK;
|
|
8
|
+
exports.ACCOUNT_METHODS = require_accountPages.ACCOUNT_METHODS;
|
|
9
|
+
exports.SIGN_IN_UNREACHABLE = require_accountPages.SIGN_IN_UNREACHABLE;
|
|
10
|
+
exports.acceptDeviceApproval = require_index$2.acceptDeviceApproval;
|
|
11
|
+
exports.claimPairedHub = require_index$1.claimPairedHub;
|
|
12
|
+
exports.consumeAccountEvictions = require_index$1.consumeAccountEvictions;
|
|
13
|
+
exports.createAccountGrants = require_index.createAccountGrants;
|
|
14
|
+
exports.createAccountTrust = require_index$2.createAccountTrust;
|
|
15
|
+
exports.createIssuerSelection = require_index$3.createIssuerSelection;
|
|
16
|
+
exports.discoverAccountComputer = require_index$1.discoverAccountComputer;
|
|
17
|
+
exports.hasOwnerControl = require_index$2.hasOwnerControl;
|
|
18
|
+
exports.identityIssuer = require_index$2.identityIssuer;
|
|
19
|
+
exports.issuerNamespace = require_index$2.issuerNamespace;
|
|
20
|
+
exports.pairedAccountHost = require_index$1.pairedAccountHost;
|
|
21
|
+
exports.readAccountRosters = require_index$1.readAccountRosters;
|
|
22
|
+
exports.readVisibleAccountHosts = require_index$1.readVisibleAccountHosts;
|
|
23
|
+
exports.registerHostInRoster = require_index$1.registerHostInRoster;
|
|
24
|
+
exports.removeAccountHub = require_index$1.removeAccountHub;
|
|
25
|
+
exports.setAccountHostVisibility = require_index$1.setAccountHostVisibility;
|
|
26
|
+
exports.unlinkAccountHub = require_index$1.unlinkAccountHub;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ACCOUNT_BACK, ACCOUNT_METHODS, AccountPage, SIGN_IN_UNREACHABLE } from "./constants/accountPages.mjs";
|
|
2
|
+
import { AccountKeyPort, AccountRecord, AccountStorage, acceptDeviceApproval, createAccountTrust, hasOwnerControl, identityIssuer, issuerNamespace } from "./services/accountTrust/index.mjs";
|
|
3
|
+
import { GrantPorts, GrantScope, GrantStorage, SavedGrant, SignedGrant, createAccountGrants } from "./services/accountGrants/index.mjs";
|
|
4
|
+
import { AccountHost, HostRosterRegistrationPorts, claimPairedHub, consumeAccountEvictions, discoverAccountComputer, pairedAccountHost, readAccountRosters, readVisibleAccountHosts, registerHostInRoster, removeAccountHub, setAccountHostVisibility, unlinkAccountHub } from "./services/accountRoster/index.mjs";
|
|
5
|
+
import { createIssuerSelection } from "./services/issuerSelection/index.mjs";
|
|
6
|
+
export { ACCOUNT_BACK, ACCOUNT_METHODS, AccountHost, AccountKeyPort, AccountPage, AccountRecord, AccountStorage, GrantPorts, GrantScope, GrantStorage, HostRosterRegistrationPorts, SIGN_IN_UNREACHABLE, SavedGrant, SignedGrant, acceptDeviceApproval, claimPairedHub, consumeAccountEvictions, createAccountGrants, createAccountTrust, createIssuerSelection, discoverAccountComputer, hasOwnerControl, identityIssuer, issuerNamespace, pairedAccountHost, readAccountRosters, readVisibleAccountHosts, registerHostInRoster, removeAccountHub, setAccountHostVisibility, unlinkAccountHub };
|
package/dist/account.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ACCOUNT_BACK, ACCOUNT_METHODS, SIGN_IN_UNREACHABLE } from "./constants/accountPages.mjs";
|
|
2
|
+
import { createAccountGrants } from "./services/accountGrants/index.mjs";
|
|
3
|
+
import { claimPairedHub, consumeAccountEvictions, discoverAccountComputer, pairedAccountHost, readAccountRosters, readVisibleAccountHosts, registerHostInRoster, removeAccountHub, setAccountHostVisibility, unlinkAccountHub } from "./services/accountRoster/index.mjs";
|
|
4
|
+
import { acceptDeviceApproval, createAccountTrust, hasOwnerControl, identityIssuer, issuerNamespace } from "./services/accountTrust/index.mjs";
|
|
5
|
+
import { createIssuerSelection } from "./services/issuerSelection/index.mjs";
|
|
6
|
+
export { ACCOUNT_BACK, ACCOUNT_METHODS, SIGN_IN_UNREACHABLE, acceptDeviceApproval, claimPairedHub, consumeAccountEvictions, createAccountGrants, createAccountTrust, createIssuerSelection, discoverAccountComputer, hasOwnerControl, identityIssuer, issuerNamespace, pairedAccountHost, readAccountRosters, readVisibleAccountHosts, registerHostInRoster, removeAccountHub, setAccountHostVisibility, unlinkAccountHub };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/constants/accountPages.ts
|
|
2
|
+
const ACCOUNT_METHODS = [
|
|
3
|
+
"Email code",
|
|
4
|
+
"Apple",
|
|
5
|
+
"Google",
|
|
6
|
+
"Microsoft",
|
|
7
|
+
"GitHub"
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Where Back leads. First run has no stack header, so without this a sub-page is a dead end. Each target is an
|
|
11
|
+
* action the account flow already handles.
|
|
12
|
+
*/
|
|
13
|
+
const ACCOUNT_BACK = {
|
|
14
|
+
methods: "welcome",
|
|
15
|
+
email: "welcome",
|
|
16
|
+
"email-code": "Email code",
|
|
17
|
+
approve: "account",
|
|
18
|
+
devices: "account",
|
|
19
|
+
delete: "account",
|
|
20
|
+
recovery: "account"
|
|
21
|
+
};
|
|
22
|
+
const SIGN_IN_UNREACHABLE = "Po can't reach your sign-in server right now. You can still pair a computer without an account.";
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.ACCOUNT_BACK = ACCOUNT_BACK;
|
|
25
|
+
exports.ACCOUNT_METHODS = ACCOUNT_METHODS;
|
|
26
|
+
exports.SIGN_IN_UNREACHABLE = SIGN_IN_UNREACHABLE;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/constants/accountPages.d.ts
|
|
2
|
+
/** The pages of the phone's self-hosted account flow. */
|
|
3
|
+
export type AccountPage = 'welcome' | 'methods' | 'email' | 'email-code' | 'recovery-chooser' | 'confirm' | 'recovery-code' | 'later-device' | 'approve' | 'recovery' | 'wait' | 'account' | 'devices' | 'delete' | 'team' | 'cloud';
|
|
4
|
+
export declare const ACCOUNT_METHODS: readonly ['Email code', 'Apple', 'Google', 'Microsoft', 'GitHub'];
|
|
5
|
+
/**
|
|
6
|
+
* Where Back leads. First run has no stack header, so without this a sub-page is a dead end. Each target is an
|
|
7
|
+
* action the account flow already handles.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ACCOUNT_BACK: Partial<Record<AccountPage, string>>;
|
|
10
|
+
export declare const SIGN_IN_UNREACHABLE = "Po can't reach your sign-in server right now. You can still pair a computer without an account.";
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/constants/accountPages.ts
|
|
2
|
+
const ACCOUNT_METHODS = [
|
|
3
|
+
"Email code",
|
|
4
|
+
"Apple",
|
|
5
|
+
"Google",
|
|
6
|
+
"Microsoft",
|
|
7
|
+
"GitHub"
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* Where Back leads. First run has no stack header, so without this a sub-page is a dead end. Each target is an
|
|
11
|
+
* action the account flow already handles.
|
|
12
|
+
*/
|
|
13
|
+
const ACCOUNT_BACK = {
|
|
14
|
+
methods: "welcome",
|
|
15
|
+
email: "welcome",
|
|
16
|
+
"email-code": "Email code",
|
|
17
|
+
approve: "account",
|
|
18
|
+
devices: "account",
|
|
19
|
+
delete: "account",
|
|
20
|
+
recovery: "account"
|
|
21
|
+
};
|
|
22
|
+
const SIGN_IN_UNREACHABLE = "Po can't reach your sign-in server right now. You can still pair a computer without an account.";
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ACCOUNT_BACK, ACCOUNT_METHODS, SIGN_IN_UNREACHABLE };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_index = require("./services/desktopAccount/index.cjs");
|
|
3
|
+
exports.CLOUD_ISSUER_ENV = require_index.CLOUD_ISSUER_ENV;
|
|
4
|
+
exports.DEFAULT_CLOUD_ISSUER = require_index.DEFAULT_CLOUD_ISSUER;
|
|
5
|
+
exports.createCloudAccount = require_index.createCloudAccount;
|
|
6
|
+
exports.resolveCloudIssuer = require_index.resolveCloudIssuer;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CloudAccount, CloudAccountOptions, CloudAccountRecord, CloudAccountStatus, CloudAccountStore, CloudProxy, CloudSignInStart } from "./services/desktopAccount/type.mjs";
|
|
2
|
+
import { CLOUD_ISSUER_ENV, DEFAULT_CLOUD_ISSUER, createCloudAccount, resolveCloudIssuer } from "./services/desktopAccount/index.mjs";
|
|
3
|
+
export { CLOUD_ISSUER_ENV, type CloudAccount, type CloudAccountOptions, type CloudAccountRecord, type CloudAccountStatus, type CloudAccountStore, type CloudProxy, type CloudSignInStart, DEFAULT_CLOUD_ISSUER, createCloudAccount, resolveCloudIssuer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CLOUD_ISSUER_ENV, DEFAULT_CLOUD_ISSUER, createCloudAccount, resolveCloudIssuer } from "./services/desktopAccount/index.mjs";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region src/extensions/native.ts
|
|
6
|
+
/**
|
|
7
|
+
* The phone ships this plugin inside the app (po-native `bundledPlugins`), so its account and
|
|
8
|
+
* first-run fills exist before any computer is paired and never come from a host download.
|
|
9
|
+
*/
|
|
10
|
+
const nativePlugin = (0, require("@agimon-ai/po-core/native").defineNativePlugin)({
|
|
11
|
+
id: "identity",
|
|
12
|
+
packageName: "@agimon-ai/po-identity",
|
|
13
|
+
host: { fills: [{
|
|
14
|
+
slot: "onboarding-region",
|
|
15
|
+
id: "account",
|
|
16
|
+
component: ({ children }) => children
|
|
17
|
+
}] }
|
|
18
|
+
});
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.default = nativePlugin;
|
|
21
|
+
exports.nativePlugin = nativePlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/extensions/native.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The phone ships this plugin inside the app (po-native `bundledPlugins`), so its account and
|
|
4
|
+
* first-run fills exist before any computer is paired and never come from a host download.
|
|
5
|
+
*/
|
|
6
|
+
export declare const nativePlugin: import("@agimon-ai/po-core/native").WebPluginDefinition;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { nativePlugin as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineNativePlugin } from "@agimon-ai/po-core/native";
|
|
2
|
+
//#region src/extensions/native.ts
|
|
3
|
+
/**
|
|
4
|
+
* The phone ships this plugin inside the app (po-native `bundledPlugins`), so its account and
|
|
5
|
+
* first-run fills exist before any computer is paired and never come from a host download.
|
|
6
|
+
*/
|
|
7
|
+
const nativePlugin = defineNativePlugin({
|
|
8
|
+
id: "identity",
|
|
9
|
+
packageName: "@agimon-ai/po-identity",
|
|
10
|
+
host: { fills: [{
|
|
11
|
+
slot: "onboarding-region",
|
|
12
|
+
id: "account",
|
|
13
|
+
component: ({ children }) => children
|
|
14
|
+
}] }
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { nativePlugin as default, nativePlugin };
|
package/dist/phone.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_index = require("./services/phoneAccount/index.cjs");
|
|
3
|
+
const require_index$1 = require("./services/hostedAccount/index.cjs");
|
|
4
|
+
const require_index$2 = require("./services/hostedAccountFlow/index.cjs");
|
|
5
|
+
const require_index$3 = require("./services/phoneAccountFlow/index.cjs");
|
|
6
|
+
exports.accountViewModel = require_index$3.accountViewModel;
|
|
7
|
+
exports.clearExpoSession = require_index.clearExpoSession;
|
|
8
|
+
exports.createHostedAccount = require_index$1.createHostedAccount;
|
|
9
|
+
exports.createHostedAccountFlow = require_index$2.createHostedAccountFlow;
|
|
10
|
+
exports.createPhoneAccount = require_index.createPhoneAccount;
|
|
11
|
+
exports.createPhoneAccountFlow = require_index$3.createPhoneAccountFlow;
|
|
12
|
+
exports.hostedAccountViewModel = require_index$2.hostedAccountViewModel;
|
|
13
|
+
exports.hostedBootstrapOf = require_index$1.hostedBootstrapOf;
|
|
14
|
+
exports.recoveredComputers = require_index$3.recoveredComputers;
|
|
15
|
+
exports.teamSlug = require_index$1.teamSlug;
|
package/dist/phone.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PhoneAccountHost, PhoneAppleCredential, PhoneHostRequest, PhonePairedHost, PhoneSecureStore } from "./services/phoneAccount/type.mjs";
|
|
2
|
+
import { HostedAccountHost, HostedBootstrap, HostedSession, HostedTeam } from "./services/hostedAccount/type.mjs";
|
|
3
|
+
import { HostedAccount, createHostedAccount, hostedBootstrapOf, teamSlug } from "./services/hostedAccount/index.mjs";
|
|
4
|
+
import { HostedAccountFlowHost, HostedAccountFlowState, HostedAccountViewModel } from "./services/hostedAccountFlow/type.mjs";
|
|
5
|
+
import { HostedAccountFlow, createHostedAccountFlow, hostedAccountViewModel } from "./services/hostedAccountFlow/index.mjs";
|
|
6
|
+
import { AccountClient, PhoneAccount, clearExpoSession, createPhoneAccount } from "./services/phoneAccount/index.mjs";
|
|
7
|
+
import { AccountFlowState, AccountViewModel, FlowCloudHost, FlowPairedHost, PhoneAccountFlowHost, RecoveredComputer } from "./services/phoneAccountFlow/type.mjs";
|
|
8
|
+
import { PhoneAccountFlow, accountViewModel, createPhoneAccountFlow, recoveredComputers } from "./services/phoneAccountFlow/index.mjs";
|
|
9
|
+
export { AccountClient, type AccountFlowState, type AccountViewModel, type FlowCloudHost, type FlowPairedHost, HostedAccount, HostedAccountFlow, type HostedAccountFlowHost, type HostedAccountFlowState, type HostedAccountHost, type HostedAccountViewModel, type HostedBootstrap, type HostedSession, type HostedTeam, PhoneAccount, PhoneAccountFlow, type PhoneAccountFlowHost, type PhoneAccountHost, type PhoneAppleCredential, type PhoneHostRequest, type PhonePairedHost, type PhoneSecureStore, type RecoveredComputer, accountViewModel, clearExpoSession, createHostedAccount, createHostedAccountFlow, createPhoneAccount, createPhoneAccountFlow, hostedAccountViewModel, hostedBootstrapOf, recoveredComputers, teamSlug };
|
package/dist/phone.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { clearExpoSession, createPhoneAccount } from "./services/phoneAccount/index.mjs";
|
|
2
|
+
import { createHostedAccount, hostedBootstrapOf, teamSlug } from "./services/hostedAccount/index.mjs";
|
|
3
|
+
import { createHostedAccountFlow, hostedAccountViewModel } from "./services/hostedAccountFlow/index.mjs";
|
|
4
|
+
import { accountViewModel, createPhoneAccountFlow, recoveredComputers } from "./services/phoneAccountFlow/index.mjs";
|
|
5
|
+
export { accountViewModel, clearExpoSession, createHostedAccount, createHostedAccountFlow, createPhoneAccount, createPhoneAccountFlow, hostedAccountViewModel, hostedBootstrapOf, recoveredComputers, teamSlug };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
let _agimon_ai_po_core_native = require("@agimon-ai/po-core/native");
|
|
2
|
+
let _agimon_ai_po_web_security_browser = require("@agimon-ai/po-web-security/browser");
|
|
3
|
+
//#region src/services/accountGrants/index.ts
|
|
4
|
+
/** Native consent lifecycle. Session and calendar callers receive the envelope to hand to their host. */
|
|
5
|
+
function createAccountGrants(ports) {
|
|
6
|
+
let writes = Promise.resolve();
|
|
7
|
+
function serial(action) {
|
|
8
|
+
const result = writes.then(action);
|
|
9
|
+
writes = result.catch(() => void 0);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
async function sign(record, scope, grantId = crypto.randomUUID()) {
|
|
13
|
+
if (!Number.isSafeInteger(record.revocationEpoch) || record.revocationEpoch < 0) throw new Error("Refresh your account before sharing work.");
|
|
14
|
+
if (!scope.operations.length || scope.operations.some((operation) => !operation)) throw new Error("Choose the work this host may do.");
|
|
15
|
+
const now = ports.now();
|
|
16
|
+
return ports.sign(record, {
|
|
17
|
+
...scope,
|
|
18
|
+
issuer: record.issuer,
|
|
19
|
+
subject: record.subject,
|
|
20
|
+
deviceKeyId: record.deviceId,
|
|
21
|
+
revocationEpoch: record.revocationEpoch,
|
|
22
|
+
grantId,
|
|
23
|
+
notBefore: now,
|
|
24
|
+
issuedAt: now,
|
|
25
|
+
expiresAt: now + _agimon_ai_po_web_security_browser.FEDERATION_FRESHNESS.grant,
|
|
26
|
+
redelegable: false
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const start = (issuer, workId, scope) => serial(async () => {
|
|
30
|
+
if (scope.callingHostId === scope.targetHostId && !scope.operations.includes("settings.global.read")) return void 0;
|
|
31
|
+
const record = await ports.account(issuer);
|
|
32
|
+
if (record.issuer !== issuer) throw new Error("The account belongs to another identity home.");
|
|
33
|
+
const envelope = await sign(record, scope);
|
|
34
|
+
const saved = await ports.storage.read(issuer);
|
|
35
|
+
await ports.storage.write(issuer, [...saved.filter((item) => item.workId !== workId || item.envelope.payload.callingHostId !== scope.callingHostId || item.envelope.payload.networkId !== scope.networkId), {
|
|
36
|
+
workId,
|
|
37
|
+
envelope
|
|
38
|
+
}]);
|
|
39
|
+
await ports.deliver?.(workId, envelope);
|
|
40
|
+
return envelope;
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
clear: (issuer) => serial(() => ports.storage.write(issuer, [])),
|
|
44
|
+
/** Provider permissions are renewed explicitly and posted together, never renewed only on this phone. */
|
|
45
|
+
providerConsent(issuer, scope, packageName) {
|
|
46
|
+
return serial(async () => {
|
|
47
|
+
const record = await ports.account(issuer);
|
|
48
|
+
if (record.issuer !== issuer) throw new Error("The account belongs to another identity home.");
|
|
49
|
+
const { read, write } = (0, _agimon_ai_po_core_native.splitConsentOperations)(scope.operations);
|
|
50
|
+
if (!read.length || !write.length) throw new Error("This provider needs both read and write operations.");
|
|
51
|
+
const grants = [];
|
|
52
|
+
for (const operations of [read, write]) grants.push(await sign(record, {
|
|
53
|
+
...scope,
|
|
54
|
+
operations,
|
|
55
|
+
constraints: { package: packageName }
|
|
56
|
+
}));
|
|
57
|
+
return grants;
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
start,
|
|
61
|
+
onSessionStart: start,
|
|
62
|
+
onJobCreated: start,
|
|
63
|
+
/** Expired grants need an explicit renew action, never silent consent on open. */
|
|
64
|
+
onAppOpen(issuer) {
|
|
65
|
+
return serial(async () => {
|
|
66
|
+
const saved = await ports.storage.read(issuer);
|
|
67
|
+
const now = ports.now();
|
|
68
|
+
const due = saved.filter(({ envelope: { payload } }) => payload.issuer === issuer && payload.expiresAt > now && payload.expiresAt - now <= _agimon_ai_po_web_security_browser.FEDERATION_FRESHNESS.grantRenewalWindow);
|
|
69
|
+
if (!due.length) return [];
|
|
70
|
+
const record = await ports.account(issuer);
|
|
71
|
+
const renewed = [];
|
|
72
|
+
for (const item of due) {
|
|
73
|
+
if (record.issuer !== issuer || item.envelope.payload.subject !== record.subject || item.envelope.payload.revocationEpoch !== record.revocationEpoch) continue;
|
|
74
|
+
const envelope = await sign(record, item.envelope.payload, item.envelope.payload.grantId);
|
|
75
|
+
item.envelope = envelope;
|
|
76
|
+
await ports.deliver?.(item.workId, envelope);
|
|
77
|
+
renewed.push(envelope);
|
|
78
|
+
}
|
|
79
|
+
await ports.storage.write(issuer, saved);
|
|
80
|
+
return renewed;
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
renew(issuer, grantId) {
|
|
84
|
+
return serial(async () => {
|
|
85
|
+
const saved = await ports.storage.read(issuer);
|
|
86
|
+
const item = saved.find(({ envelope }) => envelope.payload.grantId === grantId && envelope.payload.issuer === issuer);
|
|
87
|
+
if (!item) throw new Error("This shared work is no longer saved on this phone.");
|
|
88
|
+
const record = await ports.account(issuer);
|
|
89
|
+
if (record.issuer !== issuer || record.subject !== item.envelope.payload.subject) throw new Error("Sign in to the account that shared this work.");
|
|
90
|
+
item.envelope = await sign(record, item.envelope.payload, grantId);
|
|
91
|
+
await ports.deliver?.(item.workId, item.envelope);
|
|
92
|
+
await ports.storage.write(issuer, saved);
|
|
93
|
+
return item.envelope;
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
async notice(issuer, event, callingHostId) {
|
|
97
|
+
return (await ports.storage.read(issuer)).find(({ workId, envelope }) => workId === event.workId && envelope.payload.grantId === event.grantId && envelope.payload.issuer === issuer && envelope.payload.callingHostId === callingHostId);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
exports.createAccountGrants = createAccountGrants;
|