esp-idf-provisioning-web 0.0.3 → 0.0.6
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 +0 -0
- package/README.md +84 -21
- package/dist/ESPDevice.d.ts +4 -19
- package/dist/ESPDevice.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +4623 -3094
- package/dist/security/Security0.d.ts.map +1 -1
- package/dist/security/Security1.d.ts +17 -0
- package/dist/security/Security1.d.ts.map +1 -0
- package/dist/types.d.ts +15 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/crypto.d.ts +9 -0
- package/dist/utils/crypto.d.ts.map +1 -1
- package/package.json +26 -24
- package/src/ESPDevice.ts +79 -74
- package/src/ESPProvisionManager.ts +0 -0
- package/src/constants.ts +0 -0
- package/src/generated/.gitkeep +0 -0
- package/src/generated/proto.d.ts +0 -0
- package/src/generated/proto.js +1864 -659
- package/src/index.ts +9 -4
- package/src/proto/constants.proto +0 -0
- package/src/proto/sec0.proto +0 -0
- package/src/proto/sec1.proto +0 -0
- package/src/proto/sec2.proto +0 -0
- package/src/proto/session.proto +0 -0
- package/src/proto/wifi_config.proto +0 -0
- package/src/proto/wifi_constants.proto +0 -0
- package/src/proto/wifi_ctrl.proto +0 -0
- package/src/proto/wifi_scan.proto +0 -0
- package/src/protocol/protocol.ts +0 -0
- package/src/protocol/wifiConfig.ts +6 -6
- package/src/protocol/wifiScan.ts +4 -4
- package/src/security/Security.ts +0 -0
- package/src/security/Security0.ts +5 -3
- package/src/security/Security1.ts +110 -0
- package/src/transport/BLETransport.ts +0 -0
- package/src/transport/SoftAPTransport.ts +2 -2
- package/src/transport/Transport.ts +0 -0
- package/src/types.ts +17 -1
- package/src/utils/crypto.ts +43 -9
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@ A TypeScript SDK for provisioning ESP32 devices from web browsers using the ESP-
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- [
|
|
8
|
-
- [
|
|
7
|
+
- [x] **Security 0 and Security 1**
|
|
8
|
+
- [x] Security1: X25519 + PoP + AES-256-CTR
|
|
9
9
|
- [ ] Security2 (not implemented)
|
|
10
10
|
- [x] **BLE Transport**: Uses Web Bluetooth API for wireless provisioning
|
|
11
11
|
- [x] **SoftAP Transport**: HTTP-based provisioning for devices in AP mode
|
|
@@ -28,40 +28,99 @@ npm install esp-idf-provisioning-web
|
|
|
28
28
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
|
-
### BLE
|
|
31
|
+
### BLE with Security 0
|
|
32
|
+
|
|
33
|
+
Security 0 sends provisioning data without application-layer encryption. Use it
|
|
34
|
+
only when the device is configured for Security 0.
|
|
32
35
|
|
|
33
36
|
```typescript
|
|
34
37
|
import { ESPProvisionManager } from 'esp-idf-provisioning-web';
|
|
35
38
|
|
|
36
|
-
// Search for devices with BLE
|
|
37
39
|
const device = await ESPProvisionManager.searchBLEDevice();
|
|
38
|
-
|
|
39
|
-
// Connect with proof of possession
|
|
40
40
|
await device.connect();
|
|
41
|
+
const networks = await device.scanWifiList();
|
|
42
|
+
await device.provision('MyWiFiSSID', 'MyWiFiPassword');
|
|
43
|
+
// Poll fetchWifiStatus() until connected or failed, then disconnect.
|
|
44
|
+
```
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
const wifiList = await device.scanWifiList();
|
|
46
|
+
Runnable example: [BLE Security 0](examples/ble-provisioning.html).
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
### BLE with Security 1
|
|
49
|
+
|
|
50
|
+
Security 1 uses X25519, proof of possession (PoP), and AES-256-CTR. Supply the
|
|
51
|
+
PoP expected by the device:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { ESPProvisionManager } from 'esp-idf-provisioning-web';
|
|
55
|
+
|
|
56
|
+
const device = await ESPProvisionManager.searchBLEDevice();
|
|
57
|
+
await device.connect({
|
|
58
|
+
type: 'Security1',
|
|
59
|
+
proofOfPossession: 'device-proof-of-possession',
|
|
60
|
+
});
|
|
61
|
+
const networks = await device.scanWifiList();
|
|
46
62
|
await device.provision('MyWiFiSSID', 'MyWiFiPassword');
|
|
63
|
+
// Poll fetchWifiStatus() until connected or failed, then disconnect.
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Runnable example: [BLE Security 1](examples/ble-provisioning-security1.html).
|
|
67
|
+
|
|
68
|
+
### Resolve Security 1 credentials asynchronously
|
|
69
|
+
|
|
70
|
+
`connect()` reads the public `proto-ver` endpoint before starting the handshake.
|
|
71
|
+
Pass a resolver to obtain credentials using the returned protocol and application
|
|
72
|
+
metadata. `requestProofOfPossession` below is supplied by the consuming application:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
await device.connect(async (info) => {
|
|
76
|
+
if (info.prov.sec_ver !== 1) throw new Error('Expected Security 1');
|
|
77
|
+
const proofOfPossession = await requestProofOfPossession(info);
|
|
78
|
+
return { type: 'Security1', proofOfPossession };
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The SDK passes through custom metadata without interpreting it. Credential
|
|
83
|
+
retrieval and authorization belong to the consuming application.
|
|
84
|
+
|
|
85
|
+
A new `connect()` call reads fresh metadata and runs the resolver again. Failed
|
|
86
|
+
authentication, resolver failure, or transport failure clears the session; retry
|
|
87
|
+
with `connect()`. There is no automatic downgrade to Security 0. Security 2 is
|
|
88
|
+
unsupported.
|
|
47
89
|
|
|
48
|
-
|
|
49
|
-
|
|
90
|
+
### Custom endpoints and connection status
|
|
91
|
+
|
|
92
|
+
After connecting with either security mode, use the same APIs for application
|
|
93
|
+
endpoints and Wi-Fi status. Custom endpoints use the established security mode:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const response = await device.sendData(
|
|
97
|
+
'custom-data', new TextEncoder().encode('{"command":"get"}')
|
|
98
|
+
);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Requests are serialized because Security 1 shares one continuous AES-CTR stream
|
|
102
|
+
across both directions. `sendData('proto-ver', ...)` remains plaintext;
|
|
103
|
+
`prov-session` is managed internally. Other endpoints require a completed handshake.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { ESPWifiStaState } from 'esp-idf-provisioning-web';
|
|
107
|
+
|
|
108
|
+
let status;
|
|
50
109
|
do {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
console.log('Provisioning successful!');
|
|
57
|
-
} else {
|
|
58
|
-
console.log('Provisioning failed:', result);
|
|
59
|
-
}
|
|
110
|
+
status = await device.fetchWifiStatus();
|
|
111
|
+
if (status.staState === ESPWifiStaState.connecting) {
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
113
|
+
}
|
|
114
|
+
} while (status.staState === ESPWifiStaState.connecting);
|
|
60
115
|
|
|
61
|
-
// Disconnect
|
|
62
116
|
device.disconnect();
|
|
63
117
|
```
|
|
64
118
|
|
|
119
|
+
Security 1 requires a secure browser context and native Web Crypto **X25519**
|
|
120
|
+
support. Unsupported browsers fail the handshake instead of falling back to
|
|
121
|
+
plaintext. See the [Web Crypto specification](https://www.w3.org/TR/webcrypto/)
|
|
122
|
+
and [ESP-IDF protocol documentation](https://docs.espressif.com/projects/esp-idf/en/v5.3.3/esp32s3/api-reference/provisioning/provisioning.html).
|
|
123
|
+
|
|
65
124
|
### SoftAP Provisioning
|
|
66
125
|
|
|
67
126
|
**Important**: The browser cannot automatically connect to WiFi networks. Users must manually connect to the ESP device's access point before running this code.
|
|
@@ -104,6 +163,10 @@ if (ESPProvisionManager.isBluetoothSupported()) {
|
|
|
104
163
|
|
|
105
164
|
## Development
|
|
106
165
|
|
|
166
|
+
Use Node.js 24 LTS to build and lint the SDK.
|
|
167
|
+
`npm pack` and `npm publish` rebuild the generated protocol code, bundles and
|
|
168
|
+
type declarations before packaging.
|
|
169
|
+
|
|
107
170
|
```bash
|
|
108
171
|
# Install dependencies
|
|
109
172
|
npm install
|
package/dist/ESPDevice.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ESPDeviceInterface, ESPWifiAp, ESPWifiStatus, ESPSecurityConfig } from './types';
|
|
1
|
+
import { ESPDeviceInterface, ESPWifiAp, ESPWifiStatus, ESPSecurityConfig, ESPSecurityResolver } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* ESP Device class for provisioning operations
|
|
4
4
|
*/
|
|
@@ -6,18 +6,14 @@ export declare class ESPDevice implements ESPDeviceInterface {
|
|
|
6
6
|
private device;
|
|
7
7
|
private transportImpl?;
|
|
8
8
|
private securityImpl?;
|
|
9
|
+
private requestQueue;
|
|
9
10
|
/**
|
|
10
11
|
* Create a new ESPDevice instance
|
|
11
12
|
* @param device - BluetoothDevice for BLE or URL for SoftAP
|
|
12
13
|
*/
|
|
13
14
|
constructor(device: BluetoothDevice | URL);
|
|
14
|
-
/**
|
|
15
|
-
|
|
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>;
|
|
15
|
+
/** Connect, read public metadata, resolve credentials, then complete the handshake. */
|
|
16
|
+
connect(security?: ESPSecurityConfig | ESPSecurityResolver): Promise<void>;
|
|
21
17
|
/**
|
|
22
18
|
* Scan for available WiFi networks
|
|
23
19
|
* @returns List of WiFi networks
|
|
@@ -50,17 +46,6 @@ export declare class ESPDevice implements ESPDeviceInterface {
|
|
|
50
46
|
* Get device
|
|
51
47
|
*/
|
|
52
48
|
getDevice(): BluetoothDevice | URL;
|
|
53
|
-
/**
|
|
54
|
-
* Initialize security layer based on security type
|
|
55
|
-
*/
|
|
56
|
-
private initializeSecurity;
|
|
57
|
-
/**
|
|
58
|
-
* Establish secure session with device
|
|
59
|
-
*/
|
|
60
49
|
private establishSession;
|
|
61
|
-
/**
|
|
62
|
-
* Initialize transport layer based on transport type
|
|
63
|
-
*/
|
|
64
|
-
private initializeTransport;
|
|
65
50
|
}
|
|
66
51
|
//# sourceMappingURL=ESPDevice.d.ts.map
|
package/dist/ESPDevice.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"ESPDevice.d.ts","sourceRoot":"","sources":["../src/ESPDevice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EAEpB,MAAM,SAAS,CAAC;AA0BjB;;GAEG;AACH,qBAAa,SAAU,YAAW,kBAAkB;IAClD,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,aAAa,CAAC,CAAY;IAClC,OAAO,CAAC,YAAY,CAAC,CAAW;IAChC,OAAO,CAAC,YAAY,CAAoC;IAExD;;;OAGG;gBACS,MAAM,EAAE,eAAe,GAAG,GAAG;IAIzC,uFAAuF;IACjF,OAAO,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2ChF;;;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;;;;;OAKG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA2BnE;;OAEG;IACH,UAAU,IAAI,IAAI;IASlB;;OAEG;IACH,SAAS,IAAI,eAAe,GAAG,GAAG;YAIpB,gBAAgB;CAU/B"}
|