@rakomi/react-native 0.0.0 → 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/COMPLIANCE.md ADDED
@@ -0,0 +1,90 @@
1
+ # Compliance — `@rakomi/react-native`
2
+
3
+ Regulatory cross-reference for tenants in EU-regulated industries.
4
+
5
+ ## CRA — Reg. (EU) 2024/2847 (Cyber Resilience Act)
6
+
7
+ This package is a "product with digital elements" under CRA Art. 3(1). Same posture as `@rakomi/node` and `@rakomi/react`.
8
+
9
+ | CRA reference | Compliance posture |
10
+ |---|---|
11
+ | Art. 13 — Vulnerability handling | Documented secure vulnerability-handling process; vulnerability records retained with the technical documentation. Internal fix targets (e.g. 14 days for High severity) are an operational SLA, **not** a statutory deadline. See `SECURITY.md`. |
12
+ | Art. 14 — Reporting of actively exploited vulnerabilities & severe incidents | Statutory reporting to the designated authority on the CRA timeline (early warning → notification → final report) and informing impacted users; published advisories via GitHub Security Advisories. See `SECURITY.md`. |
13
+ | Annex I — Essential cybersecurity requirements | Secure defaults: fixed asymmetric token-signature verification, PKCE with S256 challenge (RFC 7636), biometric opt-in, ephemeral session, minimal attack surface. **Passkeys:** no passkey library is bundled or depended on by **this package** — the OS ceremony is reached through a module the host supplies. Read that precisely: it removes third-party ceremony code from *our* dependency tree and therefore from *our* SBOM; the module you wire **is** on the credential path and is **your** supply-chain surface, so account for it in yours. The bridge itself carries no bearer token, emits nothing to telemetry or the console, and an unwired adapter fails closed (`PASSKEY_NOT_SUPPORTED`) rather than falling back to a different ceremony. Proving test: `test/passkey-native-adapter.test.ts` (`@asserts CTRL-CRA-ANNEXI-SECURE-DEFAULT`). |
14
+
15
+ ## GDPR — Reg. (EU) 2016/679
16
+
17
+ | Article | Posture |
18
+ |---|---|
19
+ | Art. 25 — Data protection by design | No PII collected client-side beyond what API requires; analytics opt-in via `onEvent` only. **Passkeys — sign-in:** identified sign-in takes an opaque, server-issued user handle, never an email or a username. **Passkeys — registration (state this plainly):** the registration options the server issues carry the account's `user.name` / `user.displayName`, which today is the user's **email address**. It crosses the bridge to the host-supplied module and is passed to the platform credential provider, which stores it with the credential and may **sync it to the user's platform account** (iCloud Keychain / Google Password Manager). This is inherent to WebAuthn — the value is what the user is shown when they pick a passkey — not a choice this SDK makes, and it is disclosed here rather than glossed. The SDK adds no identifier of its own. **Errors:** the credential-envelope validator names the failing FIELD, never its VALUE; error messages relayed from the server or from the host's own callbacks are passed through verbatim and are the tenant's surface to control. |
20
+ | Art. 28 — Processor obligations | SDK is a data-processor adjunct; tenant is data controller. DPA covers the relationship. |
21
+ | Art. 32 — Security of processing | Pseudonymisation + encryption at rest (Keychain) + access control (biometric opt-in). **Passkeys — key material:** the private key is created and held by the platform credential provider; it never enters SDK memory and the SDK holds no passkey material at rest. Proving test: `test/use-passkeys.test.tsx` (`@asserts CTRL-GDPR-32-NO-SECRET-TO-ADAPTER` — no access token, step-up token or bearer secret reaches the ceremony adapter). |
22
+ | Art. 32 — Security of processing (session integrity) | A completed ceremony whose session was **not** actually stored is reported as a failure, never as a success — the SDK re-reads the token runtime and matches the session identity before it reports a sign-in. Proving test: `test/use-passkeys.test.tsx` (the session-confirmation polarities). |
23
+ | Art. 32 — Security of processing (re-authentication gate) | Management actions (list / rename / delete) are re-authentication-gated. **The gate is enforced by the API, not by this SDK** — the SDK transmits the step-up token it is given and does not itself decide whether one is sufficient. Stated here because an SDK compliance doc must not claim credit for a server-side control. |
24
+ | Art. 9 — Special categories (negative scope) | **No biometric data is processed by this SDK.** A fingerprint or face is consumed by the operating system to unlock the authenticator; the SDK receives only the resulting assertion. It never reads, stores, transmits or infers a biometric template, so Art. 9's special-category regime is not engaged by anything this library does. (Whether YOUR app processes biometrics for other purposes is your assessment.) |
25
+
26
+ ## eIDAS 2 — Reg. (EU) 2024/1183 (EUDI Wallet)
27
+
28
+ End-of-2026 mandate. The `NativeAuthAdapter` exposes a typed forward-compat slot (`verifiers?: AttestationVerifier[]`) to non-breakingly add EUDI PID verification once the EU Wallet implementing acts publish.
29
+
30
+ ## NIS2 — Dir. (EU) 2022/2555
31
+
32
+ NIS2 Art. 21 measures are obligations on the **entity**, and no supplier's posture discharges them. What
33
+ this SDK offers is *input* to your own risk assessment, not an attestation:
34
+
35
+ - Risk-management measures: cryptographic + access controls documented in `SECURITY.md`.
36
+ - Incident handling: statutory reporting of actively exploited vulnerabilities / severe incidents per CRA Art. 14 (early warning, notification, final report); see `SECURITY.md`.
37
+ - Supply-chain security: SBOM (CycloneDX) shipped with every release; npm build provenance (SLSA Build L2) attached to every published package.
38
+
39
+ ## DORA — Reg. (EU) 2022/2554
40
+
41
+ For financial-sector tenants, DORA governs ICT risk management (Art. 5–15) and ICT third-party risk
42
+ (Art. 28–30). What this SDK offers as *input* to those obligations, as one ICT component you consume:
43
+
44
+ - A CycloneDX SBOM and npm build provenance (SLSA Build L2) with every release — supporting your ICT
45
+ risk-management and supply-chain analysis. (Your Art. 28(3) register of information records the
46
+ **contractual arrangement** for the Rakomi service, not this library artefact.)
47
+ - Vulnerability handling per CRA Art. 13 + Annex I Part II, and statutory reporting per CRA Art. 14;
48
+ see `SECURITY.md`.
49
+
50
+ ## Strong Customer Authentication (PSD2 / RTS 2018/389)
51
+
52
+ **This SDK makes no SCA claim and no assurance-level (AAL / eIDAS LoA) claim.** SCA is a property of a
53
+ payment flow, assessed by the payment service provider against its own deployment; a library cannot
54
+ satisfy it, and nothing in this document should be quoted as if it could. Two things are worth stating
55
+ because they are the parts a PSP most often assumes wrongly:
56
+
57
+ - **Dynamic linking (RTS Art. 5) is NOT provided.** This SDK authenticates a *user*, not a
58
+ *transaction*: it accepts no amount and no payee, and binds neither into the signed challenge. A
59
+ payment initiation requiring dynamic linking cannot be built on this SDK's passkey flow alone.
60
+ - **A platform passkey is not necessarily device-bound.** On both iOS and Android a passkey is, by
61
+ default, **synced** through the platform account (iCloud Keychain / Google Password Manager), and the
62
+ SDK cannot tell a synced credential from a device-bound one — the WebAuthn signals that would hint at
63
+ it are opaque relays we neither interpret nor vouch for. Any element analysis under RTS Art. 7 or Art. 9
64
+ (including whether the elements are independent on a multi-purpose device, per Art. 9(2)–(3)) is
65
+ therefore the PSP's assessment, on evidence this SDK does not supply.
66
+
67
+ PSD3/PSR are proposals and, as at 2026-07, are not in force; nothing here anticipates their final text.
68
+
69
+ ## Apple App Store / Google Play Data Safety
70
+
71
+ Tenant fills the privacy nutrition labels. The SDK's data collection (consumer-app perspective):
72
+
73
+ - **User ID** — for app functionality (sign-in / sign-out lifecycle).
74
+ - **No** location, browsing history, advertising data, or third-party shipping by default.
75
+
76
+ ## WCAG 2.2 AA / EAA (Dir. 2019/882)
77
+
78
+ Mobile accessibility:
79
+
80
+ - Every interactive element has `accessibilityLabel` + `accessibilityRole` (verified by component snapshot tests).
81
+ - Keyboard hints (`textContentType`, `autoComplete`, `keyboardType`) appropriate for OTP / email / password.
82
+ - TOTP input uses `oneTimeCode` (iOS auto-fill); Android SMS Retriever is out-of-scope here (deferred).
83
+
84
+ ## OWASP MASVS L1 + Mobile Top 10 (2024)
85
+
86
+ See `SECURITY.md` for the per-control mapping.
87
+
88
+ ## EU AI Act — Reg. (EU) 2024/1689
89
+
90
+ This SDK does **NO AI inference**. Negative-scope statement for tenant comfort.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CRE8EVE Sp. z o.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,328 @@
1
- # @rakomi/react-native
1
+ # `@rakomi/react-native`
2
2
 
3
- Name reserved. The first stable release is published with build provenance from rakomidev/rakomi-js.
3
+ React Native / Expo SDK for [Rakomi](https://rakomi.com) — EU-native auth-as-a-service.
4
+
5
+ > **Status:** `0.1.0` — initial. API surface frozen for parity with `@rakomi/react`.
6
+ > Token-manager runtime, JWKS verification, social-provider deep-link auto-handler,
7
+ > bare-RN adapter example, and the demo app land in subsequent 0.x patches.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ # Expo-managed (recommended)
13
+ expo install @rakomi/react-native expo-secure-store expo-web-browser expo-crypto expo-linking expo-local-authentication
14
+ npm install @react-native-community/netinfo
15
+
16
+ # Bare React Native
17
+ npm install @rakomi/react-native react-native-keychain react-native-inappbrowser-reborn react-native-quick-crypto
18
+ ```
19
+
20
+ ## Quickstart
21
+
22
+ ```tsx
23
+ import { RakomiProvider, SignedIn, SignedOut, UserButton, SignIn } from '@rakomi/react-native';
24
+
25
+ export default function App() {
26
+ return (
27
+ <RakomiProvider
28
+ publishableKey={process.env.EXPO_PUBLIC_RAKOMI_KEY!}
29
+ baseUrl="https://api.rakomi.com"
30
+ redirectUri="myapp://callback"
31
+ >
32
+ <SignedIn><UserButton /></SignedIn>
33
+ <SignedOut><SignIn /></SignedOut>
34
+ </RakomiProvider>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ## What's included in 0.1.0
40
+
41
+ - **`<RakomiProvider>`** — context provider. Freezes the native adapter on mount. AppState debounce 300ms. Connectivity transitions wired.
42
+ - **Hooks (parity-locked):** `useAuth`, `useUser`, `useSession`, `useFlag`, `useOrganization`, `useOrganizationList`, `useLinkedAccounts`, `useTranslation`, `useAuthConfig`, `useBranding`, `useAnonymousSignin`, `useBaasPlans`, `useBaasSubscription`. Type-level parity with `@rakomi/react` is enforced by CI.
43
+ - **Components:** `<SignIn />` (password + social + MFA TOTP), `<SignUp />`, `<UserButton />`, `<UserProfile />` (preview), `<SignedIn>`, `<SignedOut>`, `<Protect>`, `<Feature>`. RN primitives only — no HTML, no WebView.
44
+ - **OAuth (RFC 8252):** PKCE S256, 32-byte state with single-use 60s TTL + constant-time comparison, system browser via `expo-web-browser` (`preferEphemeralSession: true` default), confused-deputy guard on callback ingest.
45
+ - **Native adapter contract:** `NativeAuthAdapter` interface with forward-compat slots (`verifiers` for EUDI, `dpopProver` for DPoP, `par` for RFC 9126 PAR).
46
+ - **`tokenCache` injection sugar** — replace storage without re-implementing the full adapter.
47
+ - **HKDF-style storage key derivation** — domain-separated per tenant + per purpose.
48
+
49
+ ## Passkeys (WebAuthn)
50
+
51
+ `usePasskeys()` is the whole passkey surface: sign-in, step-up, registration, and management
52
+ (list / rename / delete). Passkeys give you **passwordless** sign-in. They are **phishing-resistant**
53
+ only because the operating system binds the credential to your app's associated domain — on iOS
54
+ through your **Associated Domains** entitlement, on Android through your **Digital Asset Links** file.
55
+ If either is missing or wrong the OS **refuses** the ceremony; the SDK cannot and does not substitute
56
+ for that configuration. (The reassuring half: a misconfiguration does not silently weaken anything —
57
+ it stops the ceremony outright.)
58
+
59
+ The flow is not "biometric sign-in", and calling it that in your UI would be untrue for a share of your
60
+ users: user verification is performed by the **device's screen lock — biometrics *or* passcode** — and
61
+ the SDK cannot distinguish them, nor does it want to.
62
+
63
+ The SDK does **not** ship a passkey library and does **not** depend on one. The OS ceremony
64
+ (the system passkey sheet) belongs to your app: you supply a native module, the SDK talks to it
65
+ through one small contract. That keeps a third-party module off the credential path, keeps Expo Go
66
+ working for apps that never use passkeys, and lets you pick whichever community wrapper you already
67
+ trust.
68
+
69
+ ### Wiring the ceremony adapter
70
+
71
+ **With a native module of your own** (or a community wrapper's module):
72
+
73
+ ```tsx
74
+ import {
75
+ createDefaultExpoAdapter,
76
+ createNativePasskeyAdapter,
77
+ RakomiProvider,
78
+ } from '@rakomi/react-native';
79
+ import { NativeModules } from 'react-native';
80
+
81
+ const passkeys = createNativePasskeyAdapter({ module: NativeModules.MyPasskeyModule });
82
+
83
+ // `nativeAdapter` is normally optional (it defaults to the Expo adapter). To ADD passkeys you must
84
+ // name it explicitly — spread the default and attach the slot. There is no `passkeys` shorthand prop.
85
+ <RakomiProvider
86
+ publishableKey={process.env.EXPO_PUBLIC_RAKOMI_KEY!}
87
+ baseUrl="https://api.rakomi.com"
88
+ redirectUri="myapp://callback"
89
+ nativeAdapter={{ ...createDefaultExpoAdapter(), passkeys }}
90
+ >
91
+ {/* … */}
92
+ </RakomiProvider>
93
+ ```
94
+
95
+ **With a community wrapper whose API is not the module shape** — write a four-line shim; the contract
96
+ is deliberately tiny:
97
+
98
+ ```ts
99
+ import { createNativePasskeyAdapter } from '@rakomi/react-native';
100
+ import { Passkey } from 'some-passkey-wrapper'; // whichever wrapper you already trust
101
+
102
+ const passkeys = createNativePasskeyAdapter({
103
+ module: {
104
+ isPasskeySupported: () => Passkey.isSupported(),
105
+ // The SDK's contract is STRING in, STRING out. Most community wrappers are OBJECT in, OBJECT out —
106
+ // so the shim parses on the way in and serialises on the way out. Getting this backwards
107
+ // double-encodes the request (the wrapper receives a JSON string where it expects an object) and is
108
+ // the single most common wiring bug; check your wrapper's signature, do not copy this blindly.
109
+ createPasskey: (requestJson: string) =>
110
+ Passkey.create(JSON.parse(requestJson)).then((credential) => JSON.stringify(credential)),
111
+ getPasskey: (requestJson: string) =>
112
+ Passkey.get(JSON.parse(requestJson)).then((credential) => JSON.stringify(credential)),
113
+ // Implement this if your wrapper can dismiss an open sheet — it is what narrows the
114
+ // orphaned-credential window described below.
115
+ cancelPasskeyRequest: () => Passkey.cancel?.(),
116
+ },
117
+ });
118
+ ```
119
+
120
+ ### Using the hook
121
+
122
+ ```tsx
123
+ const {
124
+ isSupported, // null until probed; false = this device cannot run a ceremony
125
+ signInWithPasskey, // no session needed
126
+ stepUpWithPasskey, // mints a step-up token — needs a session AND an existing passkey
127
+ registerPasskey, listPasskeys, renamePasskey, deletePasskey, // all need a step-up token
128
+ passkeys, // `undefined` until you call listPasskeys(); `[]` means "none"
129
+ error, isSigningIn, isRegistering, isSteppingUp, isLoading, isMutating,
130
+ } = usePasskeys();
131
+ ```
132
+
133
+ `passkeys` starts as **`undefined`**, not `[]`. The difference is not pedantry: `[]` says "this user has
134
+ no passkeys" and `undefined` says "we have not looked". An empty-state UI keyed on `passkeys?.length === 0`
135
+ renders "no passkeys yet" before the first `listPasskeys()` has even run.
136
+
137
+ ### Step-up tokens — read this before building an "Add a passkey" button
138
+
139
+ Every management action (`registerPasskey`, `listPasskeys`, `renamePasskey`, `deletePasskey`) requires a
140
+ **step-up token**: changing which keys can sign you in is itself a sensitive act, so the server demands a
141
+ fresh re-authentication for it. The SDK never mints or stores one for you.
142
+
143
+ **There is a chicken-and-egg here, and it will bite you first.** `stepUpWithPasskey()` re-authenticates
144
+ with an **existing passkey** — so it cannot mint the token needed to register the user's **first** one.
145
+ For that first registration, obtain a step-up token through another factor (your app's password or MFA
146
+ step-up endpoint), then pass it to `registerPasskey({ stepUpToken })`. Once the user has a passkey,
147
+ `stepUpWithPasskey()` is the smooth path for every subsequent management action.
148
+
149
+ Treat a step-up token as **single-use and short-lived**: mint a fresh one per gated action rather than
150
+ caching one across a management screen. (`stepUpWithPasskey()` returns its `expiresIn`.) The server's
151
+ reuse semantics are not something the SDK guarantees, so the defensive reading is the correct one.
152
+
153
+ ### The bridge contract
154
+
155
+ | Module member | Required | Shape |
156
+ |---|---|---|
157
+ | `isPasskeySupported()` | yes | `Promise<boolean>` — the device can run a passkey ceremony at all |
158
+ | `createPasskey(requestJson)` | yes | `Promise<string>` — the registration credential, serialised |
159
+ | `getPasskey(requestJson)` | yes | `Promise<string>` — the authentication credential, serialised |
160
+ | `isPlatformAuthenticatorAvailable()` | no | `Promise<boolean>` — is there a *platform* authenticator, not just any |
161
+ | `cancelPasskeyRequest()` | no | `Promise<void> \| void` — dismiss an open sheet when the ceremony is abandoned |
162
+
163
+ Implement `cancelPasskeyRequest` if your module can: without it, a ceremony abandoned by your app (a
164
+ screen unmounts, a timeout fires) can leave the OS sheet standing, and a registration abandoned after
165
+ the credential provider already created the credential leaves the user holding a passkey the server
166
+ never learned about (see *Orphaned credentials* below).
167
+
168
+ **Strings, not objects — and this is not a style preference.** The RN bridge serialises through JSON
169
+ and **drops `undefined`**, which silently deletes optional members. A request that arrives with
170
+ `residentKey` missing is a *different* request from one that arrives with `residentKey: 'required'`,
171
+ and the sheet the user sees changes accordingly. Passing the request as a string we build ourselves
172
+ is the only way to guarantee the bytes the OS gets are the bytes the server signed off on.
173
+
174
+ Every binary field is **base64url without padding** (`A–Z a–z 0–9 - _`, no `=`). Standard base64 —
175
+ with `+`, `/`, `=` — is rejected, and it is the single most common wiring bug: an authenticator that
176
+ returns standard base64 must be re-encoded in your shim, not "fixed" server-side.
177
+
178
+ ### iOS ≠ Android
179
+
180
+ The two platforms fail differently, and the SDK maps both onto one vocabulary so your UI does not
181
+ have to branch:
182
+
183
+ | What happened | Code your UI handles |
184
+ |---|---|
185
+ | The user dismissed the sheet | `PASSKEY_CEREMONY_CANCELLED` |
186
+ | The device cannot do passkeys, or no adapter is wired | `PASSKEY_NOT_SUPPORTED` |
187
+ | The credential is already registered for this user | `PASSKEY_ALREADY_REGISTERED` |
188
+ | The action needs a fresh re-authentication first | `PASSKEY_STEP_UP_REQUIRED` |
189
+ | Your module broke the contract (returned a non-credential) | `PASSKEY_ADAPTER_ERROR` — an integration bug, never a retry |
190
+ | Sign-in succeeded but the tenant demands another factor | `PASSKEY_ADDITIONAL_STEP_REQUIRED` — **no tokens are issued**; route the user into your MFA flow, do not show "failed" |
191
+ | The user tried to delete their only sign-in method | `PASSKEY_LAST_METHOD` — "add another method first", not a generic failure |
192
+ | The phone was offline | `PASSKEY_NETWORK_ERROR` — retryable; do **not** sign the user out |
193
+ | The session is genuinely gone | `PASSKEY_SESSION_EXPIRED` — re-authenticate |
194
+ | Too many attempts | `PASSKEY_RATE_LIMITED` (`retryAfterMs` when the server sent one) |
195
+ | Anything else the OS reported | `PASSKEY_CEREMONY_FAILED` (retryable) |
196
+
197
+ Every error carries a `nextAction` (`retry` / `abort` / `none`) — branch on that rather than on the code
198
+ when all you need is "should the user try again". `PASSKEY_ADDITIONAL_STEP_REQUIRED` is the one most
199
+ likely to be mishandled: it arrives on a **successful** ceremony (HTTP 200) and simply means the tenant
200
+ requires a further factor before a session is issued.
201
+
202
+ Treat `PASSKEY_CEREMONY_CANCELLED` as a non-event — no error banner. It is by far the most frequent
203
+ outcome, and it also covers **system-initiated** dismissal (a swipe-down, an incoming call, the app
204
+ being backgrounded), not just a deliberate "Cancel". Users who dismissed a sheet on purpose do not
205
+ want to be told they failed.
206
+
207
+ **Mapping platform exceptions in your module.** Your native module reports failures with a `code`;
208
+ these are the codes the bridge understands, and everything else is re-thrown unchanged and surfaces
209
+ as `PASSKEY_CEREMONY_FAILED`:
210
+
211
+ | Platform exception | Your module's `code` |
212
+ |---|---|
213
+ | iOS `ASAuthorizationError.canceled` | `PASSKEY_CANCELLED` |
214
+ | iOS `ASAuthorizationError.failed` / `.invalidResponse` | *(re-throw unchanged)* |
215
+ | iOS — passkeys unavailable on this OS version | `PASSKEY_UNSUPPORTED` |
216
+ | Android `GetCredentialCancellationException` / `CreateCredentialCancellationException` | `PASSKEY_CANCELLED` |
217
+ | Android `GetCredentialUnsupportedException` / `CreateCredentialUnsupportedException` | `PASSKEY_UNSUPPORTED` |
218
+ | Android `CreateCredentialNoCreateOptionException` (no credential provider) | `PASSKEY_UNSUPPORTED` — fall back immediately, do not retry |
219
+ | Android `NoCredentialException` (the user has no passkey here) | `PASSKEY_NO_CREDENTIAL` |
220
+ | A community wrapper's own error codes | map them onto the three above, or re-throw |
221
+ | **Everything else** | **re-throw unchanged** → the SDK reports `PASSKEY_CEREMONY_FAILED` |
222
+
223
+ That last row is a known, documented compromise: the SDK's error vocabulary is closed and deliberately
224
+ small, so a platform-specific cause that has no code of its own arrives as a generic retryable failure.
225
+ Do **not** rewrite an error's `name` in your shim to force a different classification — the SDK reads
226
+ the `code`, and a renamed error is a lie the whole taxonomy then propagates.
227
+
228
+ **Development builds show request headers.** A host's network inspector / debugging interceptor can see
229
+ the passkey requests, including the `X-Step-Up-Token` header. That is a property of your development
230
+ build, not of the SDK: the token is held in memory for the duration of the call and never written to
231
+ device storage. Do not log headers in production builds.
232
+
233
+ ### Deployment prerequisite — RP-ID binding
234
+
235
+ Passkeys are bound to a **relying-party identifier** (your domain), and the OS refuses to run a
236
+ ceremony for an app that cannot prove it belongs to that domain. Before a single passkey works you
237
+ must publish the association files and declare the entitlement:
238
+
239
+ - **iOS** — an `apple-app-site-association` file served over HTTPS at your domain, plus the
240
+ Associated Domains entitlement (`webcredentials:example.com`).
241
+ - **Android** — a Digital Asset Links (`assetlinks.json`) file at your domain listing your app's
242
+ signing-certificate fingerprint.
243
+
244
+ Until both are in place the ceremony fails on the device with no useful message. These two files are
245
+ the prerequisite that turns "passwordless" into "phishing-resistant": with the Associated Domains
246
+ entitlement and the Digital Asset Links file in place, the OS will only offer a credential to an app
247
+ it has verified against the domain that credential was created for — and without them it offers
248
+ nothing at all.
249
+
250
+ ### Symptom → cause
251
+
252
+ | Symptom | Cause |
253
+ |---|---|
254
+ | The sheet never appears | No association file / entitlement (see above), or `isSupported()` is false |
255
+ | Every ceremony returns `PASSKEY_CEREMONY_FAILED` on a real device | The request is being mutated in your shim — pass the JSON string through untouched |
256
+ | It works in a debug build, not in a release build | Android: the release signing certificate is not in `assetlinks.json` |
257
+ | A field is missing on the OS side | Your wrapper passes objects, not the request string — `undefined` was dropped across the bridge |
258
+ | Sign-in succeeds on the device but the app stays signed out | The token submission was rejected — the hook reports this rather than claiming success |
259
+
260
+ A generic ceremony failure on a first integration is, in practice, almost always a missing or incorrect
261
+ associated-domains / `assetlinks.json` configuration. The error vocabulary cannot tell you that (the OS
262
+ does not tell *us*), so this line is the diagnostics: check the association files first, before you
263
+ suspect the SDK or your module.
264
+
265
+ **Two components, one sheet.** The passkey sheet is an operating-system modal: there is exactly one, for
266
+ the whole device. If a sign-in button in your header and a passkey screen in your settings both call
267
+ `usePasskeys()`, the SDK's lock lets only one of them open a ceremony — the second call is refused
268
+ locally with `PASSKEY_INVALID_INPUT` ("a ceremony is already in progress") and surfaces in that hook's
269
+ `error`. Note the busy flags (`isSigningIn`, `isSteppingUp`, …) are **per hook instance**: they tell you
270
+ about *your* component's call, not about the other one's. If you have two entry points on one screen,
271
+ drive both from a single `usePasskeys()` instance, or render one of them behind the other's busy state.
272
+
273
+ **Expo Go and emulators.** Expo Go cannot load a custom native module, so passkeys need a development
274
+ build. An Android emulator without Google Play services has no credential provider; an iOS simulator
275
+ needs a signed-in Apple account. A device is the only environment that proves the wiring.
276
+
277
+ **Orphaned credentials.** If registration succeeds on the device but the server never records it, the
278
+ authenticator holds a credential the server does not know about. Registering again with the same
279
+ authenticator returns `PASSKEY_ALREADY_REGISTERED` — that is the documented way out, not an error to
280
+ hide.
281
+
282
+ **Signing in as a different user — call `signOut()` first, and here is what happens if you don't.** A
283
+ passkey sign-in while another user's session is live is **not** an account switch. The token runtime
284
+ detects the change of subject and **clears the existing session** — user A is signed out — and the hook
285
+ then reports `PASSKEY_REQUEST_FAILED`. Its `nextAction` is `retry`, and a retry *will* succeed (the old
286
+ session is already gone), so from the user's seat it looks like "the first tap logged me out and did
287
+ nothing; the second tap worked". Gate your UI on the current session instead: sign out, then sign in.
288
+
289
+ **Bearer, not DPoP, on the passkey legs today.** The tokens a passkey sign-in returns are used exactly
290
+ like any other token this SDK issues; sender-constraining them is a separate concern from the ceremony.
291
+
292
+ **Expo web.** `usePasskeys()` on RN targets the native ceremony. There is no browser fallback here —
293
+ without a wired adapter the hook fails closed with `PASSKEY_NOT_SUPPORTED` rather than quietly
294
+ switching to a different ceremony. For the web, use `@rakomi/react`.
295
+
296
+ ## Security defaults
297
+
298
+ - Refresh tokens stored in `expo-secure-store` with `keychainAccessible: AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY` (no iCloud Keychain sync).
299
+ - Access tokens in-memory only (≤15min lifetime).
300
+ - WebView is **banned** in this package (RFC 8252 + ESLint guard).
301
+ - `Math.random` is **banned** (`expo-crypto.getRandomBytesAsync` is the only randomness source).
302
+ - `redirect: 'error'` on every fetch (SSRF guard — redirects are never auto-followed).
303
+
304
+ ## Compliance
305
+
306
+ See [`SECURITY.md`](./SECURITY.md) and [`COMPLIANCE.md`](./COMPLIANCE.md) for OWASP MASVS L1 mapping, Mobile Top-10, GDPR Art. 32, CRA (Reg. 2024/2847) Art. 13/14, and threat model.
307
+
308
+ ## Anti-patterns to avoid in consumer apps
309
+
310
+ - ❌ Don't store refresh tokens in `AsyncStorage` — it's not encrypted at rest.
311
+ - ❌ Don't ship without `expo prebuild` only if you're using bare-RN with custom native modules. Default Expo-managed flows do **not** require `expo prebuild`.
312
+ - ❌ Don't use generic redirect schemes (`rakomi://`) in production — register reverse-DNS (`com.example.myapp:/oauth/callback`) to defeat custom-scheme hijacking.
313
+
314
+ ## Threat model — what the SDK does NOT defend against
315
+
316
+ - Jailbroken / rooted devices at runtime (consumer adds `react-native-jail-monkey` if needed).
317
+ - Cloned / repackaged apps (use Play Integrity API / DeviceCheck on the consumer side).
318
+ - Hostile in-process npm dependencies (no JS-side mitigation; supply-chain hygiene is the consumer's responsibility).
319
+
320
+ ## Publisher webhooks
321
+
322
+ `verifyPublisherWebhook` verifies Rakomi publisher-app webhook deliveries (Standard Webhooks
323
+ HMAC-SHA256, replay defence, key-rotation tolerance). See the canonical
324
+ [publisher-webhook receiver contract](https://docs.rakomi.dev/guides/publisher-webhooks/).
325
+
326
+ ## License
327
+
328
+ See [`LICENSE`](./LICENSE).
package/SECURITY.md ADDED
@@ -0,0 +1,206 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ This policy covers the four JS-family SDK packages: `@rakomi/node`, `@rakomi/sdk-core`,
6
+ `@rakomi/react`, and `@rakomi/react-native`.
7
+
8
+ While these packages remain pre-1.0 (`0.x`), they carry **no stability or support guarantee**
9
+ (SemVer 2.0.0 §4); the latest `0.x` line receives security updates on a best-effort basis.
10
+
11
+ From version **1.0** onward, Rakomi maintains the current (N) and previous (N-1) MAJOR in parallel, with N-1 receiving
12
+ security-only fixes. The CRA support period for each MAJOR is determined in accordance with
13
+ **CRA Art. 13(8)** — at least five years, or the product's expected use time where shorter. The authoritative, machine-readable support windows are published at
14
+ [`https://api.rakomi.com/.well-known/sdk-support.json`](https://api.rakomi.com/.well-known/sdk-support.json)
15
+ and rendered for humans on the [SDK Support & Lifecycle page](https://rakomi.com/sdk-support). This
16
+ document points at that single source rather than re-typing dated rows.
17
+
18
+ Vulnerabilities in peer dependencies (e.g., React) are out of Rakomi's direct scope, but Rakomi will update minimum peer dependency versions when a peer dependency has a known critical CVE affecting SDK users.
19
+
20
+ ## Reporting a Vulnerability
21
+
22
+ **Please do NOT open a public GitHub issue for security vulnerabilities.**
23
+
24
+ We support two reporting channels:
25
+
26
+ 1. **Email:** security@rakomi.com (preferred for initial contact)
27
+ 2. **GitHub Private Vulnerability Reporting:** [Submit via GitHub Security](https://github.com/rakomidev/rakomi-js/security/advisories/new) — each report automatically receives a GHSA tracking identifier (GHSA-xxxx-xxxx-xxxx).
28
+
29
+ For encrypted communication, a PGP public key is available at:
30
+ `https://rakomi.com/rakomi-security-pgp-key.asc`
31
+
32
+ Include the key fingerprint from this file (section 14) for out-of-band verification when sending encrypted reports.
33
+
34
+ ## Response Targets
35
+
36
+ We strive to meet these response targets. Actual response times may vary based on issue complexity and team availability.
37
+
38
+ | Severity | First Response | Fix Target | Disclosure |
39
+ |----------|---------------|------------|------------|
40
+ | Critical (actively exploited) | without undue delay (target: 24h) | 72h patch/mitigation | Designated EU authority notified within 24h (CRA Art. 14) |
41
+ | High | without undue delay (target: 48h) | 14 days | Coordinated after fix |
42
+ | Medium | 5 business days | 90 days | Coordinated after fix |
43
+ | Low | 5 business days | Next release cycle | Changelog note |
44
+
45
+ Severity is assessed using industry-standard vulnerability scoring criteria.
46
+
47
+ Rakomi is maintained by a small team. During periods of reduced availability, the auto-reply from security@rakomi.com will confirm receipt and provide the PGP key. For actively exploited vulnerabilities, we will respond as quickly as humanly possible.
48
+
49
+ ## Coordinated Vulnerability Disclosure (CVD) Policy
50
+
51
+ We follow a coordinated disclosure model with a **90-day embargo** period from the date of acknowledgment. During this time:
52
+
53
+ - Rakomi will work to develop and release a fix
54
+ - We will keep the reporter updated on progress at least every 7 business days for Critical/High severity issues
55
+ - We will notify the reporter when a fix is released
56
+ - After 90 days, we will publish a security advisory regardless of fix status
57
+
58
+ We may request an extension if the fix requires significant infrastructure changes, and we will coordinate with the reporter before any deadline extension.
59
+
60
+ ## Safe Harbor
61
+
62
+ We will not pursue legal action against researchers who follow this disclosure policy and act in good faith. We consider security research conducted in accordance with this policy to be:
63
+ - Conducted lawfully and in good faith under applicable EU law
64
+ - Not subject to legal action by CRE8EVE Sp. z o.o.
65
+
66
+ Safe harbor **does not extend to**:
67
+ - Accessing or modifying other users' data
68
+ - Performing denial of service attacks
69
+ - Social engineering employees or users
70
+ - Exfiltrating data beyond what is necessary to demonstrate the vulnerability
71
+ - Any activity that violates applicable law
72
+
73
+ ## Scope
74
+
75
+ **In scope:**
76
+ - `@rakomi/node`, `@rakomi/sdk-core`, `@rakomi/react`, and `@rakomi/react-native` SDK source code and published npm packages
77
+ - Security properties of API interactions initiated by the SDKs (request signing, token verification, credential handling)
78
+ - Authentication flow logic within the SDKs
79
+
80
+ **Out of scope:**
81
+ - Social engineering attacks against Rakomi employees or users
82
+ - Denial of service attacks
83
+ - Physical security
84
+ - Vulnerabilities in third-party services used by Rakomi's backend
85
+ - Vulnerabilities in peer dependencies (e.g., React) — reported to the relevant maintainer, but Rakomi will update minimum peer dependency versions when a peer dependency has a known critical CVE affecting SDK users
86
+
87
+ This policy applies to the official `@rakomi/node`, `@rakomi/sdk-core`, `@rakomi/react`, and `@rakomi/react-native` packages distributed via npmjs.com. Forks and derivatives are maintained by their respective authors. Customers in regulated sectors (healthcare, finance) may have additional notification obligations beyond this general policy — contact security@rakomi.com for sector-specific compliance documentation.
88
+
89
+ ## EU Authority Reporting
90
+
91
+ It is our **policy** to report actively exploited vulnerabilities and severe security incidents
92
+ having an impact on the security of our products to the relevant EU authority in accordance with
93
+ **CRA Art. 14**, on the statutory timeline: an early warning, followed by a fuller notification, and
94
+ a final report.
95
+
96
+ We report to the national coordinator CSIRT designated for our Member State of main establishment
97
+ (Poland), which is our live reporting channel today; onboarding to the EU single reporting platform
98
+ is in progress, and that platform is the documented onward path as it becomes available to
99
+ manufacturers.
100
+
101
+ ## Security Update Notifications
102
+
103
+ Consumers of Rakomi SDKs can receive security update notifications through:
104
+ - **GitHub Security Advisories** on this repository (subscribe via GitHub "Watch" → "Security alerts")
105
+ - **npm audit:** `npm audit` or `pnpm audit` will flag known vulnerabilities in installed versions
106
+
107
+ In accordance with CRA Art. 14(8), after becoming aware of an actively exploited vulnerability or a severe incident having an impact on the security of our products, we will inform impacted users (and, where appropriate, all users) — together with any available risk-mitigation or corrective measures — through the above channels.
108
+
109
+ ## Manufacturer Identification
110
+
111
+ **Legal entity:** CRE8EVE Sp. z o.o.
112
+ **Registered address:** Tulipanowa 4, 72-003 Dobra, Poland (EU)
113
+ **Contact:** security@rakomi.com (role-based — no personal mailbox or phone is published)
114
+ **Products covered:** `@rakomi/node`, `@rakomi/sdk-core`, `@rakomi/react`, `@rakomi/react-native` (published on npmjs.com)
115
+
116
+ The manufacturer is itself EU-established (Poland), so no CRA Art. 18 Authorised Representative is required (Art. 18 applies to manufacturers established outside the Union). CRA conformity assessment (Art. 32): these are Class I important products (Annex III). The internal-control procedure (Annex VIII, Module A — manufacturer self-assessment, no notified-body involvement) is available for a Class I product **only where harmonised standards, common specifications, or a European cybersecurity certification scheme at assurance level at least 'substantial' are applied in full** (Art. 32(2)); otherwise a third-party route — EU-type examination plus conformity to type (modules B+C), or full quality assurance (module H) — is required. The applicable route will be confirmed against the harmonised standards in force at the CRA application date. The EU Declaration of Conformity and CE marking attach at the CRA application date (Dec 2027) and are not yet issued. See the full manufacturer record at https://docs.rakomi.dev/compliance/manufacturer/.
117
+
118
+ ## Export Control / Cryptography Notice
119
+
120
+ The four `@rakomi/*` SDK packages incorporate and invoke cryptography — they verify asymmetric
121
+ digital signatures (JWT/token verification), compare key material in constant time, and rely on the
122
+ host platform's TLS for transport security. They are distributed as **publicly available, mass-market
123
+ software** with cryptographic functionality the end user cannot readily modify.
124
+
125
+ - **EU — Regulation (EU) 2021/821 (Dual-Use):** the SDKs qualify for the **mass-market** treatment
126
+ under the Cryptography Note (Note 3) to Category 5, Part 2 of Annex I — generally available to the
127
+ public, sold without restriction, and not designed for the user to alter the cryptographic
128
+ functionality. No export authorisation is required for their distribution within or from the EU, and —
129
+ unlike the US path — the EU decontrol is **self-executing**, with no notification or filing step.
130
+ - **US — Export Administration Regulations (EAR):** the cryptographic functionality is classifiable
131
+ under **ECCN 5D002**. As **publicly available** open-source software the source code is **not
132
+ subject to the EAR** (15 CFR §734.7(a)), and the corresponding object code is distributed under the
133
+ mass-market provisions. The one-time email notification of the public source-code URL to the U.S.
134
+ BIS and NSA is filed at first public release (15 CFR §742.15(b)).
135
+
136
+ This notice is provided for transparency and is **not legal advice**. Downstream redistributors are
137
+ responsible for their own export, import, and use obligations in their jurisdiction.
138
+
139
+ ## Post-Market Surveillance
140
+
141
+ Rakomi monitors SDK health after release through:
142
+ - Automated dependency vulnerability scanning (npm audit, Dependabot)
143
+ - Runtime error patterns derived from API logs (SDK version reported in User-Agent header)
144
+ - Periodic security review of SDK code per the internal security review process
145
+
146
+ This constitutes the "effective and regular tests and reviews of the security of the product with digital elements" required under CRA Annex I, Part II, point (3). The coordinated-vulnerability-disclosure policy required under CRA Annex I, Part II, point (5) is set out in the "Coordinated Vulnerability Disclosure (CVD) Policy" section above.
147
+
148
+ ## No Bounty Program
149
+
150
+ Rakomi does not currently operate a paid bug bounty program. We deeply appreciate responsible disclosure and will acknowledge researchers in security advisories (with their consent).
151
+
152
+ ## Reference: security.txt
153
+
154
+ This policy is referenced in our machine-readable security contact file (RFC 9116):
155
+ `/.well-known/security.txt` — deployed at `https://rakomi.com/.well-known/security.txt`
156
+
157
+ ---
158
+
159
+ ## What to Include in Your Report
160
+
161
+ *(ISO/IEC 29147:2018 §6.5)*
162
+
163
+ To help us triage efficiently, please include:
164
+
165
+ 1. **Affected package** name and version (e.g., @rakomi/node 0.2.0)
166
+ 2. **Reproduction steps** — a minimal, reproducible example
167
+ 3. **Impact assessment** — what an attacker could achieve
168
+ 4. **Proof of concept** — if available (do not use real user data)
169
+ 5. **Reporter contact** — so we can keep you updated
170
+
171
+ Reports that do not include reproduction steps or fall outside the defined scope may be closed without a tracking ID.
172
+
173
+ ## Report Tracking
174
+
175
+ *(ISO/IEC 29147:2018 §6.6)*
176
+
177
+ Each report receives a unique tracking identifier upon acknowledgment. For reports submitted via GitHub Private Vulnerability Reporting, the GHSA identifier (e.g., GHSA-xxxx-xxxx-xxxx) serves as the tracking ID. For email reports, we will direct you to also submit via GitHub PVR for formal tracking.
178
+
179
+ ## Status Updates
180
+
181
+ *(ISO/IEC 29147:2018 §6.4)*
182
+
183
+ We provide status updates at least every **7 business days** for Critical/High severity issues, and upon resolution for Medium/Low severity issues.
184
+
185
+ ## CVE Assignment
186
+
187
+ Confirmed vulnerabilities with sufficient impact will receive CVE identifiers via GitHub's CNA (CVE Numbering Authority) program.
188
+
189
+ ## Reporter Data Privacy
190
+
191
+ *(GDPR Art. 6(1)(f) + Art. 13/14)*
192
+
193
+ Reporter personal data (name, email) is processed under GDPR Art. 6(1)(f) legitimate interest for vulnerability coordination. This data is:
194
+ - Retained for the duration of the vulnerability lifecycle plus 2 years
195
+ - Not shared with third parties except as required for CVE assignment or regulatory reporting (e.g., ENISA, national CSIRT)
196
+ - Accessible to the reporter upon request (GDPR Art. 15)
197
+ - Deletable upon request after vulnerability closure (GDPR Art. 17, where not overridden by regulatory retention obligations)
198
+
199
+ To exercise your GDPR rights, contact security@rakomi.com.
200
+
201
+ ## PGP Key Fingerprint
202
+
203
+ The PGP public key for encrypted communication is available at:
204
+ `https://rakomi.com/rakomi-security-pgp-key.asc`
205
+
206
+ Verify the key fingerprint through an independent channel (e.g., LinkedIn, Twitter/X, or a direct phone call) before sending sensitive information.