Generate RSA keys using Web Crypto API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)) and store them in LocalStorage ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API)).
Reads the specified amount of data from the underlying connection.
Connect to a device and create a pair of `AdbPacket` streams.
The returned `ArrayBuffer` may have more or less data than the `length` parameter specified, if there is some residual data in the connection buffer. The client will automatically call `read` again with the same `length`.
#### `write`
```ts
write(buffer:ArrayBuffer):void|Promise<void>
```
Writes data to the underlying connection.
The backend is responsible for serializing and deserializing the packets, because it's extreme slow for WebUSB backend (`@yume-chan/adb-backend-webusb`) to read packets with unknown size.
## Authentication
@@ -102,22 +87,19 @@ For how does ADB authentication work, see https://chensi.moe/blog/2020/09/30/web
In this library, authentication comes in two parts:
*`AdbCredentialStore`: because JavaScript has no unified method to generate, store and iterate crypto keys, an implementation of `AdbCredentialStore` is required for the two built-in authenticators.
*`AdbAuthenticator`: can be used to implement custom authentication modes.
Custom `AdbCredentialStore`s and `AdbAuthenticator`s can be specified in the `Adb#connect` method.
#### AdbCredentialStore
An interface to generate, store and iterate ADB private keys on each runtime. (Because Node.js and Browsers have different APIs to do this)
##### `generateKey`
```ts
generateKey():ArrayBuffer|Promise<ArrayBuffer>
generateKey():ValueOrPromise<Uint8Array>
```
Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
The returned `ArrayBuffer` is the private key in PKCS #8 format.
The returned `Uint8Array` is the private key in PKCS #8 format.
##### `iterateKeys`
@@ -131,7 +113,7 @@ Each call to `iterateKeys` must return a different iterator that iterate through
##### Implementations
The `@yume-chan/adb-backend-webusb` package contains a `AdbWebCredentialStore` implementation using Web Crypto API to generating keys and Web Storage API to storing keys.
The `@yume-chan/adb-credential-web` package contains a `AdbWebCredentialStore` implementation using Web Crypto API for generating keys and Web Storage API for storing keys.
#### AdbAuthenticator
@@ -139,6 +121,20 @@ An `AdbAuthenticator` generates `AUTH` responses for each `AUTH` request from se
This package contains `AdbSignatureAuthenticator` and `AdbPublicKeyAuthenticator`, the two basic modes.
Call this method to authenticate the connection and create an `Adb` instance.
It's possible to call `authenticate` multiple times on a single connection, every time the device receives a `CNXN` packet, it resets its internal state, and starts a new authentication process.
## Stream multiplex
ADB commands are all based on streams. Multiple streams can send and receive at the same time in one connection.
@@ -159,15 +155,17 @@ The `Backend` is responsible for reading and writing data from underlying source
Spawns child process on server. ADB has two shell modes: