@smartcrab/react-native 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/app.plugin.js +9 -0
- package/dist/adapters/expo-crypto-port.d.ts +3 -0
- package/dist/adapters/expo-crypto-port.js +8 -0
- package/dist/adapters/expo-linking-port.d.ts +3 -0
- package/dist/adapters/expo-linking-port.js +21 -0
- package/dist/adapters/expo-secure-store-port.d.ts +11 -0
- package/dist/adapters/expo-secure-store-port.js +15 -0
- package/dist/adapters/expo-web-browser-port.d.ts +7 -0
- package/dist/adapters/expo-web-browser-port.js +9 -0
- package/dist/adapters/react-native-app-state-port.d.ts +8 -0
- package/dist/adapters/react-native-app-state-port.js +13 -0
- package/dist/adapters/react-native-passkeys-adapter.d.ts +2 -0
- package/dist/adapters/react-native-passkeys-adapter.js +112 -0
- package/dist/adapters/react-native-passkeys-adapter.test.d.ts +1 -0
- package/dist/adapters/react-native-passkeys-adapter.test.js +76 -0
- package/dist/base64url.d.ts +20 -0
- package/dist/base64url.js +89 -0
- package/dist/base64url.test.d.ts +1 -0
- package/dist/base64url.test.js +36 -0
- package/dist/browser-port.d.ts +17 -0
- package/dist/browser-port.js +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.js +871 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +995 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.js +17 -0
- package/dist/crypto-port.d.ts +16 -0
- package/dist/crypto-port.js +1 -0
- package/dist/errors.d.ts +113 -0
- package/dist/errors.js +82 -0
- package/dist/errors.test.d.ts +1 -0
- package/dist/errors.test.js +81 -0
- package/dist/hooks.d.ts +93 -0
- package/dist/hooks.js +191 -0
- package/dist/http.d.ts +41 -0
- package/dist/http.js +102 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +29 -0
- package/dist/jwt.d.ts +1 -0
- package/dist/jwt.js +23 -0
- package/dist/lifecycle-ports.d.ts +29 -0
- package/dist/lifecycle-ports.js +1 -0
- package/dist/linking-port.d.ts +15 -0
- package/dist/linking-port.js +1 -0
- package/dist/passkey-adapter.d.ts +20 -0
- package/dist/passkey-adapter.js +1 -0
- package/dist/pkce.d.ts +32 -0
- package/dist/pkce.js +41 -0
- package/dist/pkce.test.d.ts +1 -0
- package/dist/pkce.test.js +66 -0
- package/dist/plugin.d.ts +89 -0
- package/dist/plugin.js +242 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.js +210 -0
- package/dist/provider.d.ts +14 -0
- package/dist/provider.js +5 -0
- package/dist/secure-store.d.ts +54 -0
- package/dist/secure-store.js +55 -0
- package/dist/secure-store.test.d.ts +1 -0
- package/dist/secure-store.test.js +69 -0
- package/dist/types.d.ts +177 -0
- package/dist/types.js +1 -0
- package/package.json +69 -0
- package/src/adapters/expo-crypto-port.ts +11 -0
- package/src/adapters/expo-linking-port.ts +23 -0
- package/src/adapters/expo-secure-store-port.ts +20 -0
- package/src/adapters/expo-web-browser-port.ts +16 -0
- package/src/adapters/react-native-app-state-port.ts +15 -0
- package/src/adapters/react-native-passkeys-adapter.test.ts +87 -0
- package/src/adapters/react-native-passkeys-adapter.ts +138 -0
- package/src/base64url.test.ts +47 -0
- package/src/base64url.ts +92 -0
- package/src/browser-port.ts +19 -0
- package/src/client.test.ts +1275 -0
- package/src/client.ts +1329 -0
- package/src/context.ts +20 -0
- package/src/crypto-port.ts +16 -0
- package/src/errors.test.ts +94 -0
- package/src/errors.ts +216 -0
- package/src/hooks.ts +374 -0
- package/src/http.ts +159 -0
- package/src/index.ts +101 -0
- package/src/jwt.ts +24 -0
- package/src/lifecycle-ports.ts +32 -0
- package/src/linking-port.ts +16 -0
- package/src/passkey-adapter.ts +20 -0
- package/src/pkce.test.ts +84 -0
- package/src/pkce.ts +62 -0
- package/src/plugin.test.ts +303 -0
- package/src/plugin.ts +387 -0
- package/src/provider.tsx +20 -0
- package/src/secure-store.test.ts +91 -0
- package/src/secure-store.ts +102 -0
- package/src/types.ts +181 -0
package/src/base64url.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* base64url (RFC 4648 §5, no padding) helpers for the React Native SDK.
|
|
3
|
+
*
|
|
4
|
+
* Hermes (RN's JS engine) has no `atob`/`btoa`/`Buffer` guarantees for
|
|
5
|
+
* arbitrary bytes, so encoding is implemented directly over `Uint8Array`
|
|
6
|
+
* (same approach as `@smartcrab/identifiers`, which this package does not
|
|
7
|
+
* depend on).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
11
|
+
|
|
12
|
+
/** base64url-encodes raw bytes without padding. Suitable for PKCE/state values. */
|
|
13
|
+
export const base64UrlEncodeBytes = (bytes: Uint8Array): string => {
|
|
14
|
+
let out = "";
|
|
15
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
16
|
+
const b0 = bytes[i] ?? 0;
|
|
17
|
+
const b1 = bytes[i + 1];
|
|
18
|
+
const b2 = bytes[i + 2];
|
|
19
|
+
out += BASE64URL_ALPHABET[b0 >> 2] ?? "";
|
|
20
|
+
out += BASE64URL_ALPHABET[((b0 & 0x03) << 4) | ((b1 ?? 0) >> 4)] ?? "";
|
|
21
|
+
if (b1 !== undefined) out += BASE64URL_ALPHABET[((b1 & 0x0f) << 2) | ((b2 ?? 0) >> 6)] ?? "";
|
|
22
|
+
if (b2 !== undefined) out += BASE64URL_ALPHABET[b2 & 0x3f] ?? "";
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Reverses `base64UrlEncodeBytes`. Throws on invalid input (see callers: always wrapped in a promise chain, never a bare `try`). */
|
|
28
|
+
export const base64UrlDecodeToBytes = (encoded: string): Uint8Array => {
|
|
29
|
+
const out: number[] = [];
|
|
30
|
+
let buffer = 0;
|
|
31
|
+
let bits = 0;
|
|
32
|
+
for (const char of encoded) {
|
|
33
|
+
const index = BASE64URL_ALPHABET.indexOf(char);
|
|
34
|
+
if (index < 0) {
|
|
35
|
+
throw new Error(`Invalid base64url character: ${char}`);
|
|
36
|
+
}
|
|
37
|
+
buffer = (buffer << 6) | index;
|
|
38
|
+
bits += 6;
|
|
39
|
+
if (bits >= 8) {
|
|
40
|
+
bits -= 8;
|
|
41
|
+
out.push((buffer >>> bits) & 0xff);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new Uint8Array(out);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Minimal UTF-8 byte decoder (React Native's ambient types do not include `TextDecoder`). */
|
|
48
|
+
const decodeUtf8 = (bytes: Uint8Array): string => {
|
|
49
|
+
let out = "";
|
|
50
|
+
let i = 0;
|
|
51
|
+
while (i < bytes.length) {
|
|
52
|
+
const byte0 = bytes[i] ?? 0;
|
|
53
|
+
if (byte0 < 0x80) {
|
|
54
|
+
out += String.fromCharCode(byte0);
|
|
55
|
+
i += 1;
|
|
56
|
+
} else if ((byte0 & 0xe0) === 0xc0) {
|
|
57
|
+
const byte1 = bytes[i + 1] ?? 0;
|
|
58
|
+
out += String.fromCharCode(((byte0 & 0x1f) << 6) | (byte1 & 0x3f));
|
|
59
|
+
i += 2;
|
|
60
|
+
} else if ((byte0 & 0xf0) === 0xe0) {
|
|
61
|
+
const byte1 = bytes[i + 1] ?? 0;
|
|
62
|
+
const byte2 = bytes[i + 2] ?? 0;
|
|
63
|
+
out += String.fromCharCode(((byte0 & 0x0f) << 12) | ((byte1 & 0x3f) << 6) | (byte2 & 0x3f));
|
|
64
|
+
i += 3;
|
|
65
|
+
} else {
|
|
66
|
+
const byte1 = bytes[i + 1] ?? 0;
|
|
67
|
+
const byte2 = bytes[i + 2] ?? 0;
|
|
68
|
+
const byte3 = bytes[i + 3] ?? 0;
|
|
69
|
+
const codepoint =
|
|
70
|
+
((byte0 & 0x07) << 18) | ((byte1 & 0x3f) << 12) | ((byte2 & 0x3f) << 6) | (byte3 & 0x3f);
|
|
71
|
+
out += String.fromCodePoint(codepoint);
|
|
72
|
+
i += 4;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const base64UrlDecodeToUtf8String = (encoded: string): string =>
|
|
79
|
+
decodeUtf8(base64UrlDecodeToBytes(encoded));
|
|
80
|
+
|
|
81
|
+
const STANDARD_BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Converts a standard base64 string (as returned by
|
|
85
|
+
* `expo-crypto`'s `digestStringAsync` with `CryptoEncoding.BASE64`) into
|
|
86
|
+
* unpadded base64url. Returns `null` when the input is not valid base64 —
|
|
87
|
+
* the digest source is a native module and is never trusted blindly.
|
|
88
|
+
*/
|
|
89
|
+
export const standardBase64ToBase64Url = (value: string): string | null => {
|
|
90
|
+
if (!STANDARD_BASE64_PATTERN.test(value)) return null;
|
|
91
|
+
return value.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
92
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System-browser boundary for social sign-in / linking (design.md §20.6,
|
|
3
|
+
* §21.3): "埋め込みWebViewは禁止する。" This port's only production
|
|
4
|
+
* implementation opens `expo-web-browser`'s ephemeral/Custom Tabs auth
|
|
5
|
+
* session — never a `WebView` component. No `react-native-webview` import
|
|
6
|
+
* exists anywhere in this package.
|
|
7
|
+
*/
|
|
8
|
+
export type WebBrowserResultType = "success" | "cancel" | "dismiss" | "opened" | "locked";
|
|
9
|
+
|
|
10
|
+
export interface WebBrowserAuthResult {
|
|
11
|
+
readonly type: WebBrowserResultType;
|
|
12
|
+
/** Present only when `type === "success"`: the URL the browser was redirected to. */
|
|
13
|
+
readonly url?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface WebBrowserPort {
|
|
17
|
+
/** Opens `url` in the system browser and resolves once it redirects back to `redirectUrl`. */
|
|
18
|
+
openAuthSessionAsync(url: string, redirectUrl: string): Promise<WebBrowserAuthResult>;
|
|
19
|
+
}
|