aether-wv 0.0.0-stage → 1.0.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.
Files changed (106) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +313 -2
  3. package/bin/aetherc.js +4 -0
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +5 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/packages/client/src/client.d.ts +26 -0
  9. package/dist/packages/client/src/client.d.ts.map +1 -0
  10. package/dist/packages/client/src/client.js +58 -0
  11. package/dist/packages/client/src/client.js.map +1 -0
  12. package/dist/packages/client/src/index.d.ts +8 -0
  13. package/dist/packages/client/src/index.d.ts.map +1 -0
  14. package/dist/packages/client/src/index.js +8 -0
  15. package/dist/packages/client/src/index.js.map +1 -0
  16. package/dist/packages/client/src/transports/android.d.ts +10 -0
  17. package/dist/packages/client/src/transports/android.d.ts.map +1 -0
  18. package/dist/packages/client/src/transports/android.js +38 -0
  19. package/dist/packages/client/src/transports/android.js.map +1 -0
  20. package/dist/packages/client/src/transports/electron.d.ts +39 -0
  21. package/dist/packages/client/src/transports/electron.d.ts.map +1 -0
  22. package/dist/packages/client/src/transports/electron.js +51 -0
  23. package/dist/packages/client/src/transports/electron.js.map +1 -0
  24. package/dist/packages/client/src/transports/ios.d.ts +9 -0
  25. package/dist/packages/client/src/transports/ios.d.ts.map +1 -0
  26. package/dist/packages/client/src/transports/ios.js +37 -0
  27. package/dist/packages/client/src/transports/ios.js.map +1 -0
  28. package/dist/packages/client/src/transports/memory.d.ts +10 -0
  29. package/dist/packages/client/src/transports/memory.d.ts.map +1 -0
  30. package/dist/packages/client/src/transports/memory.js +29 -0
  31. package/dist/packages/client/src/transports/memory.js.map +1 -0
  32. package/dist/packages/client/src/transports/transport.d.ts +3 -0
  33. package/dist/packages/client/src/transports/transport.d.ts.map +1 -0
  34. package/dist/packages/client/src/transports/transport.js +2 -0
  35. package/dist/packages/client/src/transports/transport.js.map +1 -0
  36. package/dist/packages/client/src/transports/webview2.d.ts +25 -0
  37. package/dist/packages/client/src/transports/webview2.d.ts.map +1 -0
  38. package/dist/packages/client/src/transports/webview2.js +45 -0
  39. package/dist/packages/client/src/transports/webview2.js.map +1 -0
  40. package/dist/packages/compiler/src/ast.d.ts +27 -0
  41. package/dist/packages/compiler/src/ast.d.ts.map +1 -0
  42. package/dist/packages/compiler/src/ast.js +2 -0
  43. package/dist/packages/compiler/src/ast.js.map +1 -0
  44. package/dist/packages/compiler/src/cli.d.ts +2 -0
  45. package/dist/packages/compiler/src/cli.d.ts.map +1 -0
  46. package/dist/packages/compiler/src/cli.js +68 -0
  47. package/dist/packages/compiler/src/cli.js.map +1 -0
  48. package/dist/packages/compiler/src/codegen-kotlin.d.ts +3 -0
  49. package/dist/packages/compiler/src/codegen-kotlin.d.ts.map +1 -0
  50. package/dist/packages/compiler/src/codegen-kotlin.js +119 -0
  51. package/dist/packages/compiler/src/codegen-kotlin.js.map +1 -0
  52. package/dist/packages/compiler/src/codegen-swift.d.ts +3 -0
  53. package/dist/packages/compiler/src/codegen-swift.d.ts.map +1 -0
  54. package/dist/packages/compiler/src/codegen-swift.js +129 -0
  55. package/dist/packages/compiler/src/codegen-swift.js.map +1 -0
  56. package/dist/packages/compiler/src/codegen-ts.d.ts +3 -0
  57. package/dist/packages/compiler/src/codegen-ts.d.ts.map +1 -0
  58. package/dist/packages/compiler/src/codegen-ts.js +121 -0
  59. package/dist/packages/compiler/src/codegen-ts.js.map +1 -0
  60. package/dist/packages/compiler/src/index.d.ts +7 -0
  61. package/dist/packages/compiler/src/index.d.ts.map +1 -0
  62. package/dist/packages/compiler/src/index.js +7 -0
  63. package/dist/packages/compiler/src/index.js.map +1 -0
  64. package/dist/packages/compiler/src/parser.d.ts +3 -0
  65. package/dist/packages/compiler/src/parser.d.ts.map +1 -0
  66. package/dist/packages/compiler/src/parser.js +80 -0
  67. package/dist/packages/compiler/src/parser.js.map +1 -0
  68. package/dist/packages/core/src/index.d.ts +7 -0
  69. package/dist/packages/core/src/index.d.ts.map +1 -0
  70. package/dist/packages/core/src/index.js +7 -0
  71. package/dist/packages/core/src/index.js.map +1 -0
  72. package/dist/packages/core/src/multiplexer/backpressure.d.ts +41 -0
  73. package/dist/packages/core/src/multiplexer/backpressure.d.ts.map +1 -0
  74. package/dist/packages/core/src/multiplexer/backpressure.js +80 -0
  75. package/dist/packages/core/src/multiplexer/backpressure.js.map +1 -0
  76. package/dist/packages/core/src/multiplexer/multiplexer.d.ts +36 -0
  77. package/dist/packages/core/src/multiplexer/multiplexer.d.ts.map +1 -0
  78. package/dist/packages/core/src/multiplexer/multiplexer.js +238 -0
  79. package/dist/packages/core/src/multiplexer/multiplexer.js.map +1 -0
  80. package/dist/packages/core/src/protocol/frames.d.ts +46 -0
  81. package/dist/packages/core/src/protocol/frames.d.ts.map +1 -0
  82. package/dist/packages/core/src/protocol/frames.js +89 -0
  83. package/dist/packages/core/src/protocol/frames.js.map +1 -0
  84. package/dist/packages/core/src/protocol/serializer.d.ts +38 -0
  85. package/dist/packages/core/src/protocol/serializer.d.ts.map +1 -0
  86. package/dist/packages/core/src/protocol/serializer.js +145 -0
  87. package/dist/packages/core/src/protocol/serializer.js.map +1 -0
  88. package/dist/packages/core/src/security/capability.d.ts +18 -0
  89. package/dist/packages/core/src/security/capability.d.ts.map +1 -0
  90. package/dist/packages/core/src/security/capability.js +56 -0
  91. package/dist/packages/core/src/security/capability.js.map +1 -0
  92. package/dist/packages/core/src/session/session.d.ts +29 -0
  93. package/dist/packages/core/src/session/session.d.ts.map +1 -0
  94. package/dist/packages/core/src/session/session.js +52 -0
  95. package/dist/packages/core/src/session/session.js.map +1 -0
  96. package/dist/packages/native-host/src/host.d.ts +30 -0
  97. package/dist/packages/native-host/src/host.d.ts.map +1 -0
  98. package/dist/packages/native-host/src/host.js +232 -0
  99. package/dist/packages/native-host/src/host.js.map +1 -0
  100. package/dist/packages/native-host/src/index.d.ts +2 -0
  101. package/dist/packages/native-host/src/index.d.ts.map +1 -0
  102. package/dist/packages/native-host/src/index.js +2 -0
  103. package/dist/packages/native-host/src/index.js.map +1 -0
  104. package/package.json +37 -4
  105. package/packages/platform-templates/android/AetherNativeDriver.kt +57 -0
  106. package/packages/platform-templates/ios/AetherNativeDriver.swift +78 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,314 @@
1
- # Temporary Holding Version
1
+ # Aether-WV
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > A typed, binary IPC protocol for WebView bridges.
4
+ > One `.aether` schema compiles to TypeScript, Swift and Kotlin. Frames carry a fixed 16-byte header, streams are flow-controlled with credits, and every call can be gated by an HMAC capability token.
5
+ > Works on iOS, Android, Windows (WebView2) and Electron.
6
+
7
+ ---
8
+
9
+ ## Why
10
+
11
+ Every WebView bridge around today — Capacitor, Cordova, WebViewJavascriptBridge, or a hand-rolled `postMessage` layer — runs into the same problems:
12
+
13
+ | Problem | Usual approach | Aether-WV |
14
+ |----------|----------------|-----------|
15
+ | Wire format | JSON text, 207 bytes per call | Binary frames, 71 bytes per call (65.7% less) |
16
+ | Typing | Untyped strings passed around | `.aether` schema compiled to TS / Swift / Kotlin |
17
+ | Flow control | None — large streams can OOM the WebView | Credit-based backpressure |
18
+ | Security | Origin checks at best | HMAC-SHA256 token per service/method |
19
+ | Session recovery | Reload loses all state | Ring-buffer replay after reconnect |
20
+ | Codegen | Every side written by hand | One schema, three languages |
21
+
22
+ ---
23
+
24
+ ## Architecture
25
+
26
+ ```
27
+ ┌──────────────────────────────────────────────────────────┐
28
+ │ Native App Process │
29
+ │ ┌─────────────────────┐ ┌────────────────────────┐ │
30
+ │ │ AetherNativeHost │ │ CapabilityGatekeeper │ │
31
+ │ │ registerRpc() │ │ HMAC-SHA256 tokens │ │
32
+ │ │ registerStream() │ └────────────────────────┘ │
33
+ │ └─────────┬───────────┘ │
34
+ │ │ Transport (WebMessagePort / WKScriptMessage) │
35
+ │ ┌─────────▼───────────────────────────────────────────┐ │
36
+ │ │ AetherMultiplexer (16-byte frames) │ │
37
+ │ │ StreamID | SeqID | Type | Flags | PayloadLen │ │
38
+ │ └─────────┬───────────────────────────────────────────┘ │
39
+ │ │ IPC boundary (kernel) │
40
+ └────────────┼─────────────────────────────────────────────┘
41
+ │
42
+ ┌────────────▼─────────────────────────────────────────────┐
43
+ │ WebView (JS Context) │
44
+ │ ┌──────────────────────────────────────────────────┐ │
45
+ │ │ AetherClient │ │
46
+ │ │ client.invoke('DeviceService', 'GetInfo', ...) │ │
47
+ │ │ client.stream('PaymentService', 'Watch', ...) │ │
48
+ │ └──────────────────────────────────────────────────┘ │
49
+ └──────────────────────────────────────────────────────────┘
50
+ ```
51
+
52
+ **Wire frame (16 bytes, integers big-endian):**
53
+
54
+ ```
55
+ ┌──────┬─────┬──────┬───────┬────────────┬──────────┬────────────┐
56
+ │Magic │ Ver │ Type │ Flags │ StreamID │ SeqID │ PayloadLen │
57
+ │ 0xAE │ 1B │ 1B │ 1B │ 4B BE │ 4B BE │ 4B BE │
58
+ └──────┴─────┴──────┴───────┴────────────┴──────────┴────────────┘
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Quick Start
64
+
65
+ ### 1. Write a schema
66
+
67
+ ```proto
68
+ // examples/schema.aether
69
+ syntax = "aether_v1";
70
+ package com.myapp;
71
+
72
+ message DeviceInfoRequest {
73
+ string locale = 1;
74
+ }
75
+
76
+ message DeviceInfoResponse {
77
+ string model = 1;
78
+ string os = 2;
79
+ int32 battery = 3;
80
+ }
81
+
82
+ service DeviceService {
83
+ rpc GetInfo(DeviceInfoRequest) returns (DeviceInfoResponse);
84
+ }
85
+ ```
86
+
87
+ ### 2. Compile
88
+
89
+ ```bash
90
+ node bin/aetherc.js compile examples/schema.aether \
91
+ --out-ts generated/schema.ts \
92
+ --out-swift generated/schema.swift \
93
+ --out-kotlin generated/schema.kt
94
+ ```
95
+
96
+ ### 3. Use from JavaScript (WebView side)
97
+
98
+ ```typescript
99
+ import { AetherClient } from 'aether-wv';
100
+ import { DeviceServiceClient } from './generated/schema.js';
101
+
102
+ // transport: IosScriptMessageTransport, AndroidWebMessageTransport,
103
+ // WebView2Transport or ElectronRendererTransport
104
+ const client = new AetherClient({ transport });
105
+ const svc = new DeviceServiceClient(client, token);
106
+
107
+ const info = await svc.getInfo({ locale: 'en-US' });
108
+ console.log(info.model, info.battery);
109
+ ```
110
+
111
+ ### 4. Native side (iOS)
112
+
113
+ The driver templates live in `packages/platform-templates`. The iOS one attaches to your `WKWebView` and hands raw frame bytes back to you:
114
+
115
+ ```swift
116
+ import WebKit
117
+
118
+ let driver = AetherIosDriver(webView: webView) { frameData in
119
+ // decode with the codecs from generated/schema.swift,
120
+ // run your handler, then push the reply back:
121
+ // driver.sendFrameToWeb(data: replyFrame)
122
+ }
123
+ ```
124
+
125
+ ### 5. Native side (Android)
126
+
127
+ ```kotlin
128
+ import io.aether.webview.AetherAndroidDriver
129
+
130
+ val driver = AetherAndroidDriver(
131
+ webView = webView,
132
+ allowedOrigins = setOf("https://app.example.com")
133
+ ) { frame ->
134
+ // decode with the codecs from generated/schema.kt,
135
+ // run your handler, then driver.sendFrameToWeb(reply)
136
+ }
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Codegen Output
142
+
143
+ The compiler produces three files from one schema:
144
+
145
+ **TypeScript** (WebView side)
146
+ - an interface per message
147
+ - `encodeX()` / `decodeX()` binary codecs
148
+ - a `<Service>Client` class, one async method per RPC, streams as async generators
149
+
150
+ **Swift** (iOS side)
151
+ - `struct X: Sendable, Equatable` per message
152
+ - codecs on top of `AetherWriter` / `AetherReader`
153
+ - `protocol <Service>Protocol: Actor`
154
+ - a client stub with async and stream methods
155
+
156
+ **Kotlin** (Android side)
157
+ - a `data class` per message
158
+ - codecs on `AetherWriter` / `AetherReader` (`com.aetherwv`)
159
+ - an interface with `suspend fun` for RPCs and `Flow<T>` for streams
160
+ - a client stub built on coroutines
161
+
162
+ ---
163
+
164
+ ## Features
165
+
166
+ ### Streaming with backpressure
167
+
168
+ ```typescript
169
+ const stream = client.stream('PaymentService', 'WatchTransactions', request, token);
170
+ for await (const frame of stream) {
171
+ // the host cannot push faster than you consume:
172
+ // every frame spends a credit, and credits are refilled by your ACKs
173
+ }
174
+ ```
175
+
176
+ The host registers a handler that receives an emitter:
177
+
178
+ ```typescript
179
+ host.registerStream('PaymentService', 'WatchTransactions', async (payload, emitter) => {
180
+ const timer = setInterval(async () => {
181
+ await emitter.send(encodeTransaction(...));
182
+ }, 100);
183
+
184
+ emitter.onCancel(() => clearInterval(timer)); // client aborted the stream
185
+ });
186
+ ```
187
+
188
+ ### Capability tokens
189
+
190
+ ```typescript
191
+ const token = host.gatekeeper.generateToken({
192
+ origin: 'https://app.example.com',
193
+ allowedServices: ['DeviceService.GetInfo', 'PaymentService.*'],
194
+ expiresAt: Date.now() + 3_600_000,
195
+ });
196
+ // the token travels with every call; the host verifies the HMAC
197
+ // and the allow-list before routing
198
+ ```
199
+
200
+ ### Session resumption
201
+
202
+ ```typescript
203
+ // the WebView was killed and reloaded — recreate the client
204
+ // with the same session ID you had before:
205
+ const client = new AetherClient({ transport, sessionId: savedSessionId });
206
+ client.handshake(lastAckedSeq);
207
+
208
+ // the host replays everything after lastAckedSeq
209
+ // from its 256-frame ring buffer
210
+ ```
211
+
212
+ ---
213
+
214
+ ## Transports
215
+
216
+ | Platform | Transport class | Mechanism |
217
+ |----------|----------------|-----------|
218
+ | iOS | `IosScriptMessageTransport` | `WKScriptMessageHandlerWithReply` + Base64 |
219
+ | Android | `AndroidWebMessageTransport` | `WebMessagePort`, ArrayBuffer transfer |
220
+ | Windows (WebView2) | `WebView2Transport` | `chrome.webview.postMessage` + Base64 |
221
+ | Desktop (Electron) | `ElectronRendererTransport` / `ElectronMainTransport` | `ipcRenderer` / `ipcMain`, structured clone |
222
+ | Tests | `MemoryTransport` | in-process transport pair |
223
+
224
+ WKWebView only exchanges string messages with page content, so the iOS path Base64-encodes every frame — about 33% bigger on the wire. Android's `WebMessagePort` and Electron's structured clone move raw bytes with no encoding overhead.
225
+
226
+ ---
227
+
228
+ ## Benchmark
229
+
230
+ 10,000 calls, run with `npm run benchmark`:
231
+
232
+ ```
233
+ =============================================================
234
+ AETHER-WV vs JSON BRIDGE BENCHMARK (10,000 Ops)
235
+ =============================================================
236
+ * Aether Binary Frame:
237
+ - Total Time: 87.51 ms
238
+ - Throughput: 114,266 ops/sec
239
+ - Avg Wire Size: 71 bytes / frame
240
+ - Avg Latency: 8.75 µs / op
241
+
242
+ * Classic JSON Bridge (Capacitor / Cordova pattern):
243
+ - Total Time: 25.56 ms
244
+ - Throughput: 391,256 ops/sec
245
+ - Avg Wire Size: 207 bytes / frame
246
+ - Avg Latency: 2.56 µs / op
247
+
248
+ * Speedup: 0.29x faster
249
+ * Wire Size Savings: 65.7% smaller
250
+ =============================================================
251
+ ```
252
+
253
+ The JSON side wins on raw CPU: `JSON.stringify` is native C++ with full type specialization, while the Aether codec is plain `DataView` writes in JavaScript.
254
+
255
+ Serialization is not where WebView IPC spends its time, though. Every `postMessage` pays 1.5-3.5 ms to cross the process boundary regardless of how fast you encode. Aether frames are 65.7% smaller, so there is less to copy across that boundary on every call. Exact numbers depend on the machine — measure your own with `npm run benchmark`.
256
+
257
+ ---
258
+
259
+ ## Project Structure
260
+
261
+ ```
262
+ packages/
263
+ core/ ← Protocol, frames, multiplexer, security, session
264
+ client/ ← AetherClient + platform transports (iOS, Android, Electron, WebView2, Memory)
265
+ native-host/ ← AetherNativeHost (register handlers, route frames)
266
+ compiler/ ← .aether parser + TypeScript/Swift/Kotlin codegen
267
+ platform-templates/
268
+ ios/AetherNativeDriver.swift ← WKWebView integration template
269
+ android/AetherNativeDriver.kt ← WebViewCompat integration template
270
+
271
+ bin/
272
+ aetherc.js ← CLI schema compiler
273
+
274
+ examples/
275
+ schema.aether ← Example schema
276
+ run-demo.ts ← End-to-end demo (8 steps)
277
+
278
+ tests/
279
+ protocol.test.ts ← Binary frame codec
280
+ rpc.test.ts ← Unary RPC
281
+ streaming.test.ts ← Backpressure + abort
282
+ security.test.ts ← HMAC token ACL
283
+ session.test.ts ← Ring buffer replay
284
+ compiler.test.ts ← Schema parser + codegen
285
+ pc-transport.test.ts ← Electron + WebView2 PC drivers
286
+ benchmark.test.ts ← Aether vs JSON
287
+ ```
288
+
289
+ ---
290
+
291
+ ## CLI Reference
292
+
293
+ ```bash
294
+ # Compile a schema to all three targets
295
+ node bin/aetherc.js compile <schema.aether> \
296
+ --out-ts <file.ts> \ # TypeScript client
297
+ --out-swift <file.swift> \ # Swift 6 (iOS)
298
+ --out-kotlin <file.kt> # Kotlin 2.x (Android)
299
+
300
+ # End-to-end demo
301
+ npm run demo
302
+
303
+ # Tests
304
+ npm test
305
+
306
+ # Benchmark
307
+ npm run benchmark
308
+ ```
309
+
310
+ ---
311
+
312
+ ## License
313
+
314
+ Apache-2.0 — see [LICENSE](LICENSE).
package/bin/aetherc.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from '../dist/packages/compiler/src/cli.js';
3
+
4
+ runCli(process.argv.slice(2));
@@ -0,0 +1,5 @@
1
+ export * from './packages/core/src/index.js';
2
+ export * from './packages/client/src/index.js';
3
+ export * from './packages/native-host/src/index.js';
4
+ export * from './packages/compiler/src/index.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './packages/core/src/index.js';
2
+ export * from './packages/client/src/index.js';
3
+ export * from './packages/native-host/src/index.js';
4
+ export * from './packages/compiler/src/index.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { Transport } from '../../core/src/index.js';
2
+ export interface ClientConfig {
3
+ transport: Transport;
4
+ sessionId?: string;
5
+ defaultTimeoutMs?: number;
6
+ }
7
+ export declare class AetherClient {
8
+ private multiplexer;
9
+ private sessionId;
10
+ private defaultTimeoutMs;
11
+ constructor(config: ClientConfig);
12
+ get currentSessionId(): string;
13
+ /**
14
+ * Invokes a unary RPC method on a native service
15
+ */
16
+ invoke(service: string, method: string, requestPayload: Uint8Array, token?: string, timeoutMs?: number): Promise<Uint8Array>;
17
+ /**
18
+ * Opens a reactive stream from a native service
19
+ */
20
+ stream(service: string, method: string, requestPayload: Uint8Array, token?: string, signal?: AbortSignal): AsyncIterableIterator<Uint8Array>;
21
+ /**
22
+ * Handshake for OOM crash recovery
23
+ */
24
+ handshake(lastAckSequenceId: number): void;
25
+ }
26
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAOV,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,gBAAgB,CAAS;gBAErB,MAAM,EAAE,YAAY;IAMhC,IAAI,gBAAgB,IAAI,MAAM,CAE7B;IAED;;OAEG;IACG,MAAM,CACV,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAC1B,KAAK,GAAE,MAAW,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC;IAYtB;;OAEG;IACH,MAAM,CACJ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,UAAU,EAC1B,KAAK,GAAE,MAAW,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,qBAAqB,CAAC,UAAU,CAAC;IAYpC;;OAEG;IACH,SAAS,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI;CAe3C"}
@@ -0,0 +1,58 @@
1
+ import { AetherMultiplexer, BinaryWriter, FrameType, FrameFlags, } from '../../core/src/index.js';
2
+ export class AetherClient {
3
+ multiplexer;
4
+ sessionId;
5
+ defaultTimeoutMs;
6
+ constructor(config) {
7
+ this.multiplexer = new AetherMultiplexer(config.transport);
8
+ this.sessionId = config.sessionId ?? `session_${Math.random().toString(36).slice(2, 10)}`;
9
+ this.defaultTimeoutMs = config.defaultTimeoutMs ?? 15000;
10
+ }
11
+ get currentSessionId() {
12
+ return this.sessionId;
13
+ }
14
+ /**
15
+ * Invokes a unary RPC method on a native service
16
+ */
17
+ async invoke(service, method, requestPayload, token = '', timeoutMs) {
18
+ const envelope = new BinaryWriter()
19
+ .writeString(this.sessionId)
20
+ .writeString(service)
21
+ .writeString(method)
22
+ .writeString(token)
23
+ .writeBytes(requestPayload)
24
+ .finish();
25
+ return this.multiplexer.invokeRpc(envelope, timeoutMs ?? this.defaultTimeoutMs);
26
+ }
27
+ /**
28
+ * Opens a reactive stream from a native service
29
+ */
30
+ stream(service, method, requestPayload, token = '', signal) {
31
+ const envelope = new BinaryWriter()
32
+ .writeString(this.sessionId)
33
+ .writeString(service)
34
+ .writeString(method)
35
+ .writeString(token)
36
+ .writeBytes(requestPayload)
37
+ .finish();
38
+ return this.multiplexer.openStream(envelope, signal);
39
+ }
40
+ /**
41
+ * Handshake for OOM crash recovery
42
+ */
43
+ handshake(lastAckSequenceId) {
44
+ const payload = new BinaryWriter()
45
+ .writeString(this.sessionId)
46
+ .writeUint32(lastAckSequenceId)
47
+ .finish();
48
+ const frame = {
49
+ type: FrameType.HANDSHAKE,
50
+ flags: FrameFlags.NONE,
51
+ streamId: 0,
52
+ sequenceId: 0,
53
+ payload,
54
+ };
55
+ this.multiplexer.send(frame);
56
+ }
57
+ }
58
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../packages/client/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,YAAY,EAGZ,SAAS,EACT,UAAU,GACX,MAAM,yBAAyB,CAAC;AAQjC,MAAM,OAAO,YAAY;IACf,WAAW,CAAoB;IAC/B,SAAS,CAAS;IAClB,gBAAgB,CAAS;IAEjC,YAAY,MAAoB;QAC9B,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,WAAW,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QAC1F,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,KAAK,CAAC;IAC3D,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,OAAe,EACf,MAAc,EACd,cAA0B,EAC1B,QAAgB,EAAE,EAClB,SAAkB;QAElB,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE;aAChC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;aAC3B,WAAW,CAAC,OAAO,CAAC;aACpB,WAAW,CAAC,MAAM,CAAC;aACnB,WAAW,CAAC,KAAK,CAAC;aAClB,UAAU,CAAC,cAAc,CAAC;aAC1B,MAAM,EAAE,CAAC;QAEZ,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAClF,CAAC;IAED;;OAEG;IACH,MAAM,CACJ,OAAe,EACf,MAAc,EACd,cAA0B,EAC1B,QAAgB,EAAE,EAClB,MAAoB;QAEpB,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE;aAChC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;aAC3B,WAAW,CAAC,OAAO,CAAC;aACpB,WAAW,CAAC,MAAM,CAAC;aACnB,WAAW,CAAC,KAAK,CAAC;aAClB,UAAU,CAAC,cAAc,CAAC;aAC1B,MAAM,EAAE,CAAC;QAEZ,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,iBAAyB;QACjC,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE;aAC/B,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC;aAC3B,WAAW,CAAC,iBAAiB,CAAC;aAC9B,MAAM,EAAE,CAAC;QAEZ,MAAM,KAAK,GAAgB;YACzB,IAAI,EAAE,SAAS,CAAC,SAAS;YACzB,KAAK,EAAE,UAAU,CAAC,IAAI;YACtB,QAAQ,EAAE,CAAC;YACX,UAAU,EAAE,CAAC;YACb,OAAO;SACR,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export * from './client.js';
2
+ export * from './transports/transport.js';
3
+ export * from './transports/memory.js';
4
+ export * from './transports/android.js';
5
+ export * from './transports/ios.js';
6
+ export * from './transports/electron.js';
7
+ export * from './transports/webview2.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './client.js';
2
+ export * from './transports/transport.js';
3
+ export * from './transports/memory.js';
4
+ export * from './transports/android.js';
5
+ export * from './transports/ios.js';
6
+ export * from './transports/electron.js';
7
+ export * from './transports/webview2.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/client/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}