esp-idf-provisioning-web 0.0.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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/dist/ESPDevice.d.ts +66 -0
  4. package/dist/ESPDevice.d.ts.map +1 -0
  5. package/dist/ESPProvisionManager.d.ts +34 -0
  6. package/dist/ESPProvisionManager.d.ts.map +1 -0
  7. package/dist/constants.d.ts +19 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/index.d.ts +16 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.es.js +5085 -0
  12. package/dist/protocol/protocol.d.ts +4 -0
  13. package/dist/protocol/protocol.d.ts.map +1 -0
  14. package/dist/protocol/wifiConfig.d.ts +8 -0
  15. package/dist/protocol/wifiConfig.d.ts.map +1 -0
  16. package/dist/protocol/wifiScan.d.ts +8 -0
  17. package/dist/protocol/wifiScan.d.ts.map +1 -0
  18. package/dist/security/Security.d.ts +26 -0
  19. package/dist/security/Security.d.ts.map +1 -0
  20. package/dist/security/Security0.d.ts +13 -0
  21. package/dist/security/Security0.d.ts.map +1 -0
  22. package/dist/transport/BLETransport.d.ts +22 -0
  23. package/dist/transport/BLETransport.d.ts.map +1 -0
  24. package/dist/transport/SoftAPTransport.d.ts +27 -0
  25. package/dist/transport/SoftAPTransport.d.ts.map +1 -0
  26. package/dist/transport/Transport.d.ts +22 -0
  27. package/dist/transport/Transport.d.ts.map +1 -0
  28. package/dist/types.d.ts +73 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/utils/crypto.d.ts +44 -0
  31. package/dist/utils/crypto.d.ts.map +1 -0
  32. package/package.json +60 -0
  33. package/src/ESPDevice.ts +231 -0
  34. package/src/ESPProvisionManager.ts +78 -0
  35. package/src/constants.ts +29 -0
  36. package/src/generated/.gitkeep +0 -0
  37. package/src/generated/proto.d.ts +3418 -0
  38. package/src/generated/proto.js +10006 -0
  39. package/src/index.ts +31 -0
  40. package/src/proto/constants.proto +14 -0
  41. package/src/proto/sec0.proto +28 -0
  42. package/src/proto/sec1.proto +45 -0
  43. package/src/proto/sec2.proto +48 -0
  44. package/src/proto/session.proto +25 -0
  45. package/src/proto/wifi_config.proto +57 -0
  46. package/src/proto/wifi_constants.proto +32 -0
  47. package/src/proto/wifi_ctrl.proto +38 -0
  48. package/src/proto/wifi_scan.proto +63 -0
  49. package/src/protocol/protocol.ts +23 -0
  50. package/src/protocol/wifiConfig.ts +108 -0
  51. package/src/protocol/wifiScan.ts +91 -0
  52. package/src/security/Security.ts +29 -0
  53. package/src/security/Security0.ts +40 -0
  54. package/src/transport/BLETransport.ts +111 -0
  55. package/src/transport/SoftAPTransport.ts +89 -0
  56. package/src/transport/Transport.ts +24 -0
  57. package/src/types.ts +86 -0
  58. package/src/utils/crypto.ts +129 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
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 ADDED
@@ -0,0 +1,129 @@
1
+ # ESP-IDF Provisioning Web SDK
2
+
3
+ A TypeScript SDK for provisioning ESP32 devices from web browsers using the ESP-IDF provisioning protocol. Supports both BLE (Web Bluetooth) and SoftAP (HTTP) transport modes.
4
+
5
+ ## Features
6
+
7
+ - [ ] **Multiple Security Modes**
8
+ - [ ] Security1 (not implemented)
9
+ - [ ] Security2 (not implemented)
10
+ - [x] **BLE Transport**: Uses Web Bluetooth API for wireless provisioning
11
+ - [x] **SoftAP Transport**: HTTP-based provisioning for devices in AP mode
12
+ - [x] **Provisioning Protocol**: Supports ESP-IDF provisioning protocol for WiFi credentials
13
+ - [x] Scan APs
14
+ - [x] Provision device status monitoring
15
+ - [ ] Reset and re-provisioning
16
+ - [ ] Custom endpoints
17
+
18
+ ## Browser Compatibility
19
+
20
+ - **BLE Mode**: Requires browsers with Web Bluetooth API support (Chrome, Edge, Opera)
21
+ - **SoftAP Mode**: Works in all modern browsers (user must manually connect to WiFi)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install esp-idf-provisioning-web
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### BLE Provisioning
32
+
33
+ ```typescript
34
+ import { ESPProvisionManager } from 'esp-idf-provisioning-web';
35
+
36
+ // Search for devices with BLE
37
+ const device = await ESPProvisionManager.searchBLEDevice();
38
+
39
+ // Connect with proof of possession
40
+ await device.connect();
41
+
42
+ // Scan for WiFi networks
43
+ const wifiList = await device.scanWifiList();
44
+
45
+ // Provision the device
46
+ await device.provision('MyWiFiSSID', 'MyWiFiPassword');
47
+
48
+ // Wait for STA connected
49
+ let result;
50
+ do {
51
+ result = await device.fetchWifiStatus();
52
+ await new Promise((resolve) => setTimeout(resolve, 2000));
53
+ } while (result.staState !== ESPWifiStaState.connecting);
54
+
55
+ if (result.staState === ESPWifiStaState.connected) {
56
+ console.log('Provisioning successful!');
57
+ } else {
58
+ console.log('Provisioning failed:', result);
59
+ }
60
+
61
+ // Disconnect
62
+ device.disconnect();
63
+ ```
64
+
65
+ ### SoftAP Provisioning
66
+
67
+ **Important**: The browser cannot automatically connect to WiFi networks. Users must manually connect to the ESP device's access point before running this code.
68
+
69
+ ```typescript
70
+ import { ESPProvisionManager } from 'esp-idf-provisioning-web';
71
+
72
+ // Create device instance for SoftAP
73
+ // User should already be connected to the device's WiFi network
74
+ const device = ESPProvisionManager.createSoftAPDevice(new URL('http://192.168.4.1'));
75
+
76
+ // Connect and provision
77
+ await device.connect();
78
+ await device.provision('MyWiFiSSID', 'MyWiFiPassword');
79
+ ```
80
+
81
+ ### Check Bluetooth Support
82
+
83
+ ```typescript
84
+ // Check if Web Bluetooth is available
85
+ if (ESPProvisionManager.isBluetoothSupported()) {
86
+ const isAvailable = await ESPProvisionManager.getBluetoothAvailability();
87
+ console.log('Bluetooth available:', isAvailable);
88
+ }
89
+ ```
90
+
91
+ ## Browser Limitations
92
+
93
+ ### BLE Mode
94
+ - Requires user interaction (button click) to initiate device scanning
95
+ - User must manually select device from browser's device picker
96
+ - HTTPS or localhost required for Web Bluetooth API
97
+ - Service UUID must be filled in optionalServiceUUIDs for some browsers
98
+
99
+ ### SoftAP Mode
100
+ - Browser cannot connect to WiFi networks programmatically
101
+ - User must manually connect to ESP device's access point
102
+ - CORS may need to be configured on the ESP device
103
+ - May not work on all networks due to browser security restrictions
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ # Install dependencies
109
+ npm install
110
+
111
+ # Build
112
+ npm run build
113
+
114
+ # Lint
115
+ npm run lint
116
+
117
+ # Format
118
+ npm run format
119
+ ```
120
+
121
+ ## License
122
+
123
+ MIT
124
+
125
+ ## References
126
+
127
+ - [ESP-IDF Provisioning Protocol](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/provisioning/provisioning.html)
128
+ - [Web Bluetooth API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API)
129
+ - [React Native ESP-IDF Provisioning](https://github.com/orbital-systems/react-native-esp-idf-provisioning)
@@ -0,0 +1,66 @@
1
+ import { ESPDeviceInterface, ESPWifiAp, ESPWifiStatus, ESPSecurityConfig } from './types';
2
+ /**
3
+ * ESP Device class for provisioning operations
4
+ */
5
+ export declare class ESPDevice implements ESPDeviceInterface {
6
+ private device;
7
+ private transportImpl?;
8
+ private securityImpl?;
9
+ /**
10
+ * Create a new ESPDevice instance
11
+ * @param device - BluetoothDevice for BLE or URL for SoftAP
12
+ */
13
+ constructor(device: BluetoothDevice | URL);
14
+ /**
15
+ * Connect to the device
16
+ * @param proofOfPossession - Proof of possession for secure modes
17
+ * @param softAPPassword - Password for SoftAP mode (not used in browser)
18
+ * @param username - Username for authentication
19
+ */
20
+ connect(security?: ESPSecurityConfig): Promise<void>;
21
+ /**
22
+ * Scan for available WiFi networks
23
+ * @returns List of WiFi networks
24
+ */
25
+ scanWifiList(): Promise<ESPWifiAp[]>;
26
+ /**
27
+ * Provision device with WiFi credentials
28
+ * @note Call fetchWifiStatus() after provisioning to check provisioning status
29
+ * @param ssid - WiFi network SSID
30
+ * @param passphrase - WiFi network password
31
+ */
32
+ provision(ssid: string, passphrase: string): Promise<void>;
33
+ /**
34
+ * Fetch WiFi status from device
35
+ * @returns WiFi status
36
+ */
37
+ fetchWifiStatus(): Promise<ESPWifiStatus>;
38
+ /**
39
+ * Disconnect from device
40
+ */
41
+ disconnect(): void;
42
+ /**
43
+ * Get device
44
+ */
45
+ getDevice(): BluetoothDevice | URL;
46
+ /**
47
+ * Initialize security layer based on security type
48
+ */
49
+ private initializeSecurity;
50
+ /**
51
+ * Establish secure session with device
52
+ */
53
+ private establishSession;
54
+ /**
55
+ * Initialize transport layer based on transport type
56
+ */
57
+ private initializeTransport;
58
+ /**
59
+ * Send custom data to device
60
+ * @param path - Data endpoint path
61
+ * @param data - Data to send
62
+ * @returns Response data from device
63
+ */
64
+ private sendData;
65
+ }
66
+ //# sourceMappingURL=ESPDevice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ESPDevice.d.ts","sourceRoot":"","sources":["../src/ESPDevice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAwBjB;;GAEG;AACH,qBAAa,SAAU,YAAW,kBAAkB;IAClD,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,aAAa,CAAC,CAAY;IAClC,OAAO,CAAC,YAAY,CAAC,CAAW;IAEhC;;;OAGG;gBACS,MAAM,EAAE,eAAe,GAAG,GAAG;IAIzC;;;;;OAKG;IACG,OAAO,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1D;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAiC1C;;;;;OAKG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBhE;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,aAAa,CAAC;IAc/C;;OAEG;IACH,UAAU,IAAI,IAAI;IAQlB;;OAEG;IACH,SAAS,IAAI,eAAe,GAAG,GAAG;IAIlC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;OAEG;YACW,gBAAgB;IAkB9B;;OAEG;YACW,mBAAmB;IAajC;;;;;OAKG;YACW,QAAQ;CAevB"}
@@ -0,0 +1,34 @@
1
+ import { ESPDevice } from './ESPDevice';
2
+ /**
3
+ * ESP Provision Manager for device discovery
4
+ */
5
+ export declare class ESPProvisionManager {
6
+ /**
7
+ * Search for ESP devices using BLE
8
+ * @param devicePrefix - Prefix to filter device names
9
+ * @param transport - Transport type (only BLE supported for search)
10
+ * @param security - Security type to use
11
+ * @returns Promise resolving to array of discovered devices
12
+ */
13
+ static searchBLEDevice(bleDeviceOptions?: RequestDeviceOptions): Promise<ESPDevice | null>;
14
+ /**
15
+ * Create an ESPDevice instance for SoftAP mode
16
+ * Note: Browser cannot automatically connect to WiFi.
17
+ * User must manually connect to the device's access point before using this.
18
+ *
19
+ * @param baseURL - Base URL for the SoftAP
20
+ * @returns ESPDevice instance configured for SoftAP
21
+ */
22
+ static createSoftAPDevice(baseURL: URL): ESPDevice;
23
+ /**
24
+ * Check if Web Bluetooth is supported
25
+ * @returns true if Web Bluetooth is available
26
+ */
27
+ static isBluetoothSupported(): boolean;
28
+ /**
29
+ * Get Bluetooth availability status
30
+ * @returns Promise resolving to availability status
31
+ */
32
+ static getBluetoothAvailability(): Promise<boolean>;
33
+ }
34
+ //# sourceMappingURL=ESPProvisionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ESPProvisionManager.d.ts","sourceRoot":"","sources":["../src/ESPProvisionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;;;;;OAMG;WACU,eAAe,CAC1B,gBAAgB,GAAE,oBAAiD,GAClE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAyB5B;;;;;;;OAOG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,SAAS;IAIlD;;;OAGG;IACH,MAAM,CAAC,oBAAoB,IAAI,OAAO;IAItC;;;OAGG;WACU,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC;CAY1D"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Constants for ESP provisioning protocol
3
+ */
4
+ export declare const PROTO_ENDPOINTS: {
5
+ PROV_SESSION: string;
6
+ PROV_SCAN: string;
7
+ PROV_CTRL: string;
8
+ PROV_CONFIG: string;
9
+ PROTO_VER: string;
10
+ };
11
+ export declare const DEFAULT_DEVICE_PREFIX = "PROV_";
12
+ export declare const FALLBACK_SERVICE_UUID = "1775244d-6b43-439b-877c-060f2d9bed07";
13
+ export declare const FALLBACK_NU_LOOKUP: {
14
+ 'prov-session': string;
15
+ 'prov-config': string;
16
+ 'proto-ver': string;
17
+ };
18
+ export declare const DEFAULT_BLE_DEVICE_OPTIONS: RequestDeviceOptions;
19
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,eAAe;;;;;;CAM3B,CAAC;AAGF,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAG7C,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAE5E,eAAO,MAAM,kBAAkB;;;;CAI9B,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,oBAGxC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * ESP-IDF Provisioning Web SDK
3
+ *
4
+ * A TypeScript library for provisioning ESP32 devices via Web Bluetooth API and HTTP.
5
+ * Supports both BLE and SoftAP transport modes with Security0, Security1, and Security2.
6
+ *
7
+ * Note: Browser limitations apply:
8
+ * - BLE requires user interaction to select devices
9
+ * - SoftAP requires manual WiFi connection by the user
10
+ * - Some security features may require additional crypto libraries for production use
11
+ */
12
+ export { ESPDevice } from './ESPDevice';
13
+ export { ESPProvisionManager } from './ESPProvisionManager';
14
+ export { ESPWifiAuthMode, ESPWifiStaState, type ESPDeviceInterface, type ESPSecurity1Config, type ESPSecurity2Config, type ESPWifiAp, type ESPScanStatusResponse as ESPStatusResponse, type ESPConnectFailReason, type ESPWifiStatus, } from './types';
15
+ export { FALLBACK_SERVICE_UUID, DEFAULT_DEVICE_PREFIX, } from './constants';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EACL,eAAe,EACf,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,qBAAqB,IAAI,iBAAiB,EAC/C,KAAK,oBAAoB,EACzB,KAAK,aAAa,GACnB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,aAAa,CAAC"}