@tetherto/wdk-worklet-bundler 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -0
- package/bin/wdk-worklet-bundler.js +2 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1320 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +758 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# @tetherto/wdk-worklet-bundler
|
|
2
|
+
|
|
3
|
+
CLI tool for generating optimized WDK worklet bundles. This tool packages specific blockchain modules (Wallets, Protocols) into a single artifact designed to run in a separate **Bare runtime** thread, isolated from your main React Native application loop.
|
|
4
|
+
|
|
5
|
+
This architecture ensures:
|
|
6
|
+
* **Performance:** Heavy cryptographic operations do not block the UI thread.
|
|
7
|
+
* **Compatibility:** Provides a Node.js-like environment (via `bare-node-runtime`) for standard crypto libraries.
|
|
8
|
+
* **Isolation:** Securely encapsulates wallet logic and private keys.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Global installation
|
|
14
|
+
npm install -g @tetherto/wdk-worklet-bundler
|
|
15
|
+
|
|
16
|
+
# Or as a project dependency (recommended)
|
|
17
|
+
npm install --save-dev @tetherto/wdk-worklet-bundler
|
|
18
|
+
|
|
19
|
+
# Or run directly without installation
|
|
20
|
+
npx @tetherto/wdk-worklet-bundler
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
1. **Initialize** a configuration in your React Native project:
|
|
26
|
+
```bash
|
|
27
|
+
wdk-worklet-bundler init
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. **Configure** your networks in `wdk.config.js`:
|
|
31
|
+
```javascript
|
|
32
|
+
module.exports = {
|
|
33
|
+
networks: {
|
|
34
|
+
ethereum: {
|
|
35
|
+
package: '@tetherto/wdk-wallet-evm-erc-4337'
|
|
36
|
+
},
|
|
37
|
+
bitcoin: {
|
|
38
|
+
package: '@tetherto/wdk-wallet-btc'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. **Generate** the bundle:
|
|
45
|
+
```bash
|
|
46
|
+
# Automatically installs missing WDK modules to your dependencies
|
|
47
|
+
wdk-worklet-bundler generate --install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
4. **Use** it in your App:
|
|
51
|
+
```typescript
|
|
52
|
+
import { WdkAppProvider } from '@tetherto/pear-wrk-wdk';
|
|
53
|
+
// Import the generated bundle asset (handled by metro/webpack as a static asset)
|
|
54
|
+
const workletBundle = require('./.wdk-bundle/wdk-worklet.bundle.js');
|
|
55
|
+
|
|
56
|
+
function App() {
|
|
57
|
+
return (
|
|
58
|
+
<WdkAppProvider bundle={{ bundle: workletBundle }}>
|
|
59
|
+
{/* Your App Content */}
|
|
60
|
+
</WdkAppProvider>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Architecture
|
|
66
|
+
|
|
67
|
+
The bundler orchestrates the creation of a standalone JavaScript environment ("Worklet") that communicates with your main application.
|
|
68
|
+
|
|
69
|
+
* **Host (React Native App):** Your UI layer. It loads the generated bundle and communicates with it via HRPC (Host-Remote Procedure Call).
|
|
70
|
+
* **Guest (Worklet Bundle):** A compact, optimized bundle containing your selected Wallet and Protocol modules. It runs inside the **Bare runtime** (a minimal Node.js-compatible runtime for mobile).
|
|
71
|
+
* **Bundler (The Chef):** This CLI tool. It resolves dependencies, generates the entry point code, and compiles everything using `bare-pack`.
|
|
72
|
+
|
|
73
|
+
We recommend installing all WDK modules and the core library as **`dependencies`**. The bundler compiles them into the separate worklet artifact, but having them in `dependencies` ensures proper resolution and type availability.
|
|
74
|
+
|
|
75
|
+
## Commands
|
|
76
|
+
|
|
77
|
+
### `generate`
|
|
78
|
+
Builds the worklet bundle.
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
wdk-worklet-bundler generate [options]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Options:**
|
|
85
|
+
* `-c, --config <path>`: Path to config file.
|
|
86
|
+
* `--install`: Automatically install missing modules listed in your config (saves to `devDependencies`).
|
|
87
|
+
* `--keep-artifacts`: Keep the intermediate `.wdk/` folder (useful for debugging generated source code). By default, this is cleaned up.
|
|
88
|
+
* `--source-only`: Generate the entry files but skip the final `bare-pack` bundling step.
|
|
89
|
+
* `--skip-generation`: Skip artifact generation and use existing files.
|
|
90
|
+
* `--dry-run`: Print what would happen without writing files.
|
|
91
|
+
* `--no-types`: Skip generating TypeScript definitions (`index.d.ts`).
|
|
92
|
+
* `-v, --verbose`: Show verbose output.
|
|
93
|
+
|
|
94
|
+
### `init`
|
|
95
|
+
Creates a fresh `wdk.config.js` file.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
wdk-worklet-bundler init [options]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Options:**
|
|
102
|
+
* `-y, --yes`: Use defaults without prompting.
|
|
103
|
+
|
|
104
|
+
### `validate`
|
|
105
|
+
Checks if your configuration is valid and if all required dependencies are installed.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
wdk-worklet-bundler validate [options]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Options:**
|
|
112
|
+
* `-c, --config <path>`: Path to config file.
|
|
113
|
+
|
|
114
|
+
### `list-modules`
|
|
115
|
+
List available WDK modules.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
wdk-worklet-bundler list-modules [options]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Options:**
|
|
122
|
+
* `--json`: Output as JSON.
|
|
123
|
+
|
|
124
|
+
### `clean`
|
|
125
|
+
Remove generated `.wdk` folder.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
wdk-worklet-bundler clean [options]
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Options:**
|
|
132
|
+
* `-y, --yes`: Skip confirmation.
|
|
133
|
+
|
|
134
|
+
## Configuration Reference (`wdk.config.js`)
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
module.exports = {
|
|
138
|
+
// Map logical network names to WDK wallet packages
|
|
139
|
+
networks: {
|
|
140
|
+
ethereum: {
|
|
141
|
+
package: '@tetherto/wdk-wallet-evm-erc-4337'
|
|
142
|
+
},
|
|
143
|
+
local_dev: {
|
|
144
|
+
package: './local-packages/my-custom-wallet' // Local paths supported
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
// Map logical protocol names to WDK protocol packages
|
|
149
|
+
protocols: {
|
|
150
|
+
aaveEvm: {
|
|
151
|
+
package: '@tetherto/wdk-protocol-aave-lending-evm'
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
// Native addons to preload (e.g. for specific crypto requirements)
|
|
156
|
+
preloadModules: [
|
|
157
|
+
'spark-frost-bare-addon'
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
// Customize output locations
|
|
161
|
+
output: {
|
|
162
|
+
bundle: './.wdk-bundle/wdk-worklet.bundle.js',
|
|
163
|
+
types: './.wdk/index.d.ts'
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// Build options
|
|
167
|
+
options: {
|
|
168
|
+
minify: false, // Optional: Minify the bundle
|
|
169
|
+
sourceMaps: false, // Optional: Generate source maps
|
|
170
|
+
targets: ['ios-arm64', 'android-arm64'] // bare-pack targets
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Troubleshooting
|
|
176
|
+
|
|
177
|
+
**"Module not found" during generation:**
|
|
178
|
+
Run `wdk-worklet-bundler generate --install`. This ensures all packages defined in your config (plus the core `@tetherto/pear-wrk-wdk`) are present in your `node_modules`.
|
|
179
|
+
|
|
180
|
+
**"Missing dependency" inside the worklet:**
|
|
181
|
+
If you see runtime errors about missing modules inside the worklet, ensure `pear-wrk-wdk` is properly installed. The bundler treats it as an external dependency that must be present.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|