@onekeyfe/react-native-sni-connect 6.7.0-46 → 6.7.0-48

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.
Files changed (2) hide show
  1. package/README.md +111 -73
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,21 +1,52 @@
1
- # @onekeyfe/react-native-sni-connect
1
+ <div align="center">
2
2
 
3
- OneKey SNI HTTP client for React Native. Performs HTTPS requests to a caller-supplied
4
- IP address while preserving the original TLS SNI / `Host` of a hostname, so certificate
5
- chain and hostname verification are still enforced against the real hostname (not the IP).
3
+ # @onekeyfe/react-native-sni-connect
6
4
 
7
- Backed by EMASCurl (libcurl) on iOS and OkHttp on Android.
5
+ **HTTPS requests to a caller-supplied IP while TLS still validates the real hostname.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-sni-connect?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-sni-connect)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-sni-connect?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![TurboModule](https://img.shields.io/badge/TurboModule-4D6BFE)
12
+
13
+ </div>
14
+
15
+ Connects to a literal IP address you already resolved while preserving the real
16
+ hostname's TLS SNI, `Host` header and certificate validation, so the certificate
17
+ chain is checked against the hostname rather than the IP. Requests are text-only:
18
+ send a UTF-8 body or stream an app-sandbox file through `uploadFile()`. The
19
+ transport is EMASCurl (libcurl) on iOS and OkHttp on Android; there is no Web
20
+ implementation, every request is `https` on port 443, and each connection is
21
+ pinned to a validated public destination.
22
+
23
+ ## Features
24
+
25
+ - **Pinned destination, real TLS identity** — SNI, `Host` and certificate
26
+ verification use `hostname`; `ip` only chooses the socket target.
27
+ - **Strict request validation** — public IP literals only, relative paths only,
28
+ control characters and module-owned routing headers rejected before I/O.
29
+ - **Bounded concurrency** — 64 active requests per process, 16 per
30
+ `(hostname, ip)` pair, a 256-request queue and `SNI_RESOURCE_LIMIT` on overflow.
31
+ - **Request-id cancellation** — cancel one in-flight request or every request
32
+ owned by the current runtime.
33
+ - **Binary uploads** — `uploadFile()` streams a local file up to 20 MiB;
34
+ `isUploadFileSupported()` feature-detects older native binaries.
35
+ - **Operational hooks** — `clearDNSCache()`, per-pair `getDebugSnapshot()` and a
36
+ `isProxyActiveForUrl()` preflight for adapters.
8
37
 
9
38
  ## Installation
10
39
 
11
- This package is published as part of the OneKey `app-modules` workspace:
12
-
13
40
  ```sh
14
41
  yarn add @onekeyfe/react-native-sni-connect
15
42
  ```
16
43
 
17
- iOS: add Aliyun's spec repo and make `EMASCurl` modular in your app Podfile,
18
- then run `pod install`:
44
+ Rebuild the native application after installing; the TurboModule is resolved at
45
+ import time and throws a linking error when the pods or Android native build are
46
+ missing. Android links through autolinking.
47
+
48
+ **iOS.** The pod depends on `EMASCurl`, which lives in Aliyun's spec repo. Add that source
49
+ and keep `EMASCurl` modular in the `Podfile`, then run `pod install`:
19
50
 
20
51
  ```ruby
21
52
  source 'https://github.com/CocoaPods/Specs.git'
@@ -28,7 +59,11 @@ target 'YourApp' do
28
59
  end
29
60
  ```
30
61
 
31
- Android autolinks.
62
+ **Android.** The application must declare the normal `INTERNET` permission:
63
+
64
+ ```xml
65
+ <uses-permission android:name="android.permission.INTERNET" />
66
+ ```
32
67
 
33
68
  ## Usage
34
69
 
@@ -36,85 +71,88 @@ Android autolinks.
36
71
  import {
37
72
  request,
38
73
  cancelRequest,
39
- cancelAllRequests,
40
- clearDNSCache,
41
- getDebugSnapshot,
42
74
  isProxyActiveForUrl,
43
- uploadFile,
44
- isUploadFileSupported,
45
75
  } from '@onekeyfe/react-native-sni-connect';
46
76
 
47
77
  const proxyActive = await isProxyActiveForUrl('https://example.com/api/v1/ping');
48
- if (proxyActive) {
49
- // Product adapters should avoid entering SNI mode when a per-URL/system proxy
50
- // is active. Low-level SNI requests still bypass proxies directly.
51
- }
78
+ // Adapters should avoid SNI mode while a per-URL/system proxy is active.
52
79
 
53
80
  const res = await request({
54
- // requestId is optional; required only if you want to cancel the request.
55
- requestId: 'health-check-1',
56
- ip: '93.184.216.34', // must be a public IP literal (private/loopback/metadata are rejected)
57
- hostname: 'example.com', // used for SNI, Host header and certificate validation
81
+ requestId: 'health-check-1', // required only if you want to cancel it
82
+ ip: '93.184.216.34', // public IP literal; private/loopback/metadata are rejected
83
+ hostname: 'example.com', // SNI, Host header and certificate validation
58
84
  method: 'GET',
59
- path: '/api/v1/ping', // relative path only — absolute URLs are rejected
85
+ path: '/api/v1/ping', // relative path only; absolute URLs are rejected
60
86
  headers: { 'Content-Type': 'application/json' },
61
87
  timeout: 30_000,
62
88
  });
63
89
 
64
90
  console.log(res.status, res.headers, res.data);
65
91
 
66
- // Cancellation (requires requestId on the request)
67
92
  await cancelRequest('health-check-1');
68
- await cancelAllRequests();
69
-
70
- // Drop pinned-IP connections / cached clients
71
- await clearDNSCache();
72
-
73
- // Diagnostics for one validated hostname/IP pair
74
- const snapshot = await getDebugSnapshot({
75
- hostname: 'example.com',
76
- ip: '93.184.216.34',
77
- });
78
93
  ```
79
94
 
80
- `multiValueHeaders` preserves repeated response headers when the native transport
81
- exposes them as raw entries. On iOS, EMASCurl 1.5.5 currently hands this module a
82
- `HTTPURLResponse` dictionary view, so duplicate header names may already be
83
- collapsed by the transport before this adapter can observe them. Full duplicate
84
- header preservation on iOS requires an EMASCurl version that exposes the raw
85
- response header list.
86
-
87
- Check `isUploadFileSupported()` before uploading when JS can run with older native
88
- binaries. `uploadFile()` rejects with `code: SNI_UNSUPPORTED` when unavailable.
89
-
90
- ## Specification
91
-
92
- The behavior of the SNI connect module is governed by a normative,
93
- platform-agnostic standard that all implementations (iOS, Android, Node/Desktop,
94
- shared JS adapters, and any future platform) must conform to:
95
-
96
- **-> [OneKey SNI Connect Standard (OSCS)](https://github.com/OneKeyHQ/app-modules/blob/main/native-modules/react-native-sni-connect/SPEC.md)**
97
-
98
- The [native upload contract](docs/SPEC.md) defines capability detection and
99
- consumption-time file bounds.
100
-
101
- Any change to request validation, destination pinning, TLS validation, redirect
102
- handling, cancellation, response shape, or cache behavior must be checked
103
- against OSCS.
104
- When an implementation and the standard disagree, the implementation is wrong.
105
-
106
- ### Security notes
107
-
108
- - The request scheme is always `https` on port `443`; `path` cannot override scheme, host or port.
109
- - `isProxyActiveForUrl(url)` is a preflight probe for adapters. It does not enable proxying;
110
- native SNI transport still bypasses system proxy configuration.
111
- - `ip` must be an IPv4/IPv6 literal that routes to a public destination; loopback, private,
112
- link-local (incl. cloud metadata), CGNAT, multicast and reserved ranges are rejected.
113
- - Header names/values containing CR/LF/control characters are rejected; the `Host` header is
114
- managed by the module.
115
- - Native logs go through OneKey's native logger (with sensitive-data redaction); there is no
116
- JS log event channel.
95
+ HTTP `4xx` and `5xx` resolve as normal responses; inspect `status`. The caller
96
+ owns the target IP, the request id lifecycle and higher-level retry policy.
97
+
98
+ ## API
99
+
100
+ | Export | Signature | Platforms | Description |
101
+ | --- | --- | :-: | --- |
102
+ | `request` | `(config: SniConnectRequest) => Promise<SniConnectResponse>` | iOS, Android | Sends one HTTPS request over the pinned SNI transport. |
103
+ | `uploadFile` | `(config: SniConnectUploadFileRequest) => Promise<SniConnectResponse>` | iOS, Android | Sends a local file body (`POST`/`PUT`, 1 byte–20 MiB). |
104
+ | `isUploadFileSupported` | `() => boolean` | iOS, Android | Reports whether the loaded native module exposes `uploadFile`. |
105
+ | `cancelRequest` | `(requestId: string) => Promise<{ success: boolean }>` | iOS, Android | Cancels the active request with that id. |
106
+ | `cancelAllRequests` | `() => Promise<{ success: boolean }>` | iOS, Android | Cancels every request owned by the current runtime. |
107
+ | `clearDNSCache` | `() => Promise<{ success: boolean }>` | iOS, Android | Evicts cached pinned destinations, clients and idle connections. |
108
+ | `getDebugSnapshot` | `({ hostname, ip }) => Promise<SniConnectDebugSnapshot>` | iOS, Android | Reads active/pending counters and request ids for one pair. |
109
+ | `isProxyActiveForUrl` | `(url: string) => Promise<boolean>` | iOS, Android | Preflight proxy probe; does not enable proxying for SNI requests. |
110
+
111
+ `SniConnectResponse` contains `data` (string), `status`, `statusText`, `headers`
112
+ and an optional `multiValueHeaders`. Limits: 1 MiB body, 8 KiB path/query, 64
113
+ headers / 32 KiB total, 10 MiB response. Exported types include
114
+ `SniConnectRequest`, `SniConnectResponse` and `SniConnectUploadFileRequest`; see
115
+ [`src/NativeSniConnect.ts`](src/NativeSniConnect.ts).
116
+
117
+ ## Platform support
118
+
119
+ | Capability | iOS | Android | Web |
120
+ | --- | :-: | :-: | :-: |
121
+ | Pinned-IP request with hostname TLS | ✅ | ✅ | — |
122
+ | String request body | ✅ | ✅ | — |
123
+ | Binary file upload (`uploadFile`) | ✅ | ✅ | — |
124
+ | Per-request and bulk cancellation | ✅ | ✅ | — |
125
+ | Cache clear and debug snapshot | ✅ | ✅ | — |
126
+ | Proxy preflight | ✅ | ✅ | — |
127
+ | Repeated response headers (`multiValueHeaders`) | ⚠️ may collapse | ✅ | — |
128
+
129
+ ## Caveats
130
+
131
+ > [!IMPORTANT]
132
+ > `ip` must be a public IP literal — loopback, private, link-local (including
133
+ > cloud metadata), CGNAT, multicast and reserved ranges are rejected. `path`
134
+ > cannot carry a scheme, host or port, and `Host` / `Content-Length` stay
135
+ > module-owned.
136
+
137
+ > [!WARNING]
138
+ > This is a text-response API with a 10 MiB response cap; binary response
139
+ > transport is out of scope. Send binary request bodies with `uploadFile()` and
140
+ > feature-detect it with `isUploadFileSupported()` before use.
141
+
142
+ > [!NOTE]
143
+ > On iOS the EMASCurl version used here exposes response headers as a dictionary
144
+ > view, so repeated headers may already be collapsed before `multiValueHeaders`
145
+ > is built. `isProxyActiveForUrl()` only reports proxy state; SNI transport
146
+ > always bypasses system proxy configuration.
147
+
148
+ ## References
149
+
150
+ - [OSCS standard](SPEC.md)
151
+ - [Native upload contract](docs/SPEC.md)
152
+ - [Native interface](src/NativeSniConnect.ts)
153
+ - [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-sni-connect)
154
+ - [Changelog](../../CHANGELOG.md)
117
155
 
118
156
  ## License
119
157
 
120
- MIT
158
+ MIT. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-sni-connect",
3
- "version": "6.7.0-46",
3
+ "version": "6.7.0-48",
4
4
  "description": "A React Native library for SNI-based HTTP requests with DNS caching and request management",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",