-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,46 @@ | ||
# `@yume-chan/adb-credential-web` | ||
|
||
Generate RSA keys using Web Crypto API ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)) and store them in IndexedDB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)). | ||
|
||
Local storage is not available in Web Workers (for example WebUSB API is supported in Chrome extension service workers), so IndexedDB is used instead. | ||
|
||
- [Constructor](#constructor) | ||
- [`generateKey`](#generatekey) | ||
- [`iterateKeys`](#iteratekeys) | ||
|
||
## Constructor | ||
|
||
```ts | ||
public constructor(); | ||
``` | ||
|
||
Create a new instance of `AdbWebCredentialStore`. | ||
|
||
## `generateKey` | ||
|
||
```ts | ||
async generateKey(): Promise<Uint8Array> | ||
``` | ||
|
||
Generate a RSA private key and store it into LocalStorage. | ||
|
||
Calling this method multiple times will overwrite the previous key. | ||
|
||
The returned `Uint8Array` is the private key in PKCS #8 format. | ||
|
||
## `iterateKeys` | ||
|
||
```ts | ||
async *iterateKeys(): AsyncGenerator<Uint8Array, void, void> | ||
``` | ||
|
||
Yield the stored RSA private key. `AdbWebCredentialStore` only stores one key, so only one value will be yielded. | ||
|
||
This method returns a generator, so `for await...of...` loop should be used to read the key. | ||
<p align="center"> | ||
<img alt="Tango" src="https://raw.githubusercontent.com/yume-chan/ya-webadb/main/.github/logo.svg" width="200"> | ||
</p> | ||
|
||
<h1 align="center">@yume-chan/adb-credential-web</h1> | ||
|
||
<p align="center"> | ||
Credential Store for `@yume-chan/adb` using WebCrypto and IndexedDB APIs. | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/yume-chan/ya-webadb/blob/main/LICENSE"> | ||
<img alt="MIT License" src="https://img.shields.io/github/license/yume-chan/ya-webadb"> | ||
</a> | ||
<a href="https://github.com/yume-chan/ya-webadb/releases"> | ||
<img alt="GitHub release" src="https://img.shields.io/github/v/release/yume-chan/ya-webadb?logo=github"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@yume-chan/adb"> | ||
<img alt="npm" src="https://img.shields.io/npm/dm/%40yume-chan/adb?logo=npm"> | ||
</a> | ||
<a href="https://discord.gg/26k3ttC2PN"> | ||
<img alt="Discord" src="https://img.shields.io/discord/1120215514732564502?logo=discord&logoColor=%23ffffff&label=Discord"> | ||
</a> | ||
</p> | ||
|
||
This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Generally you need multiple packages to build a complete ADB client that can run on Web browsers and Node.js. Read the documentation for more information. | ||
|
||
## Documentation | ||
|
||
Check the latest documentation at https://tango-adb.github.io/docs/ | ||
|
||
## Sponsors | ||
|
||
[Become a backer](https://opencollective.com/ya-webadb) and get your image on our README on Github with a link to your site. | ||
|
||
<a href="https://opencollective.com/ya-webadb/backer/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/0/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/1/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/2/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/3/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/4/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/5/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/6/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/7/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/7/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/8/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/9/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/9/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/10/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/10/avatar.svg?requireActive=false"></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,46 @@ | ||
# @yume-chan/adb-daemon-webusb | ||
|
||
ADB daemon transport device for `@yume-chan/adb` using WebUSB ([MDN](https://developer.mozilla.org/en-US/docs/Web/API/USB), [Spec](https://wicg.github.io/webusb)) API. | ||
|
||
- [Use in browser](#use-in-browser) | ||
- [Use in Node.js](#use-in-nodejs) | ||
- [`AdbDaemonWebUsbDevice`](#adbdaemonwebusbdevice) | ||
- [constructor](#constructor) | ||
- [`raw`](#raw) | ||
- [`connect`](#connect) | ||
- [`AdbDaemonWebUsbDeviceManager`](#adbdaemonwebusbdevicemanager) | ||
- [`BROWSER`](#browser) | ||
- [constructor](#constructor-1) | ||
- [`requestDevice`](#requestdevice) | ||
- [`getDevices`](#getdevices) | ||
- [Note on secure context](#note-on-secure-context) | ||
|
||
## Use in browser | ||
|
||
| Chrome | Edge | Firefox | Internet Explorer | Safari | | ||
| -------------- | -------------- | ------- | ----------------- | ------ | | ||
| 61<sup>1</sup> | 79<sup>1</sup> | No | No | No | | ||
|
||
<sup>1</sup>: Chrome for Android is supported, Chrome for iOS is NOT supported. | ||
|
||
## Use in Node.js | ||
|
||
| Node.js | `usb` NPM Package | | ||
| ------- | ----------------- | | ||
| 10.5 | 2.8.1 | | ||
|
||
Node.js doesn't have native support for WebUSB API, but the [`usb`](https://www.npmjs.com/package/usb) NPM package provides a WebUSB compatible API. | ||
|
||
To use a custom WebUSB API implementation, pass it to the constructor of `AdbDaemonWebUsbDevice`, `AdbDaemonWebUsbDeviceManager` and `AdbDaemonWebUsbConnectionWatcher` via the `usbManager` parameter. | ||
|
||
## `AdbDaemonWebUsbDevice` | ||
|
||
### constructor | ||
|
||
```ts | ||
public constructor( | ||
device: USBDevice, | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] | ||
usbManager: USB | ||
); | ||
``` | ||
|
||
Create a new instance of `AdbDaemonWebUsbDevice` using a specified `USBDevice` instance. | ||
|
||
`USBDevice` and `USB` types are from WebUSB API. | ||
|
||
The `filters` parameter specifies the `classCode`, `subclassCode` and `protocolCode` to use when searching for ADB interface. The default value is `[{ classCode: 0xff, subclassCode: 0x42, protocolCode: 0x1 }]`, defined by Google. | ||
|
||
### `raw` | ||
|
||
```ts | ||
public get raw(): USBDevice; | ||
``` | ||
|
||
Gets the raw `USBDevice` from the device. Allow sending/receiving USB packets to other interfaces/endpoints. For example can be used with `@yume-chan/aoa` package. | ||
|
||
### `connect` | ||
|
||
```ts | ||
public async connect(): Promise< | ||
ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> | ||
> | ||
``` | ||
|
||
Claim the device and create a pair of `AdbPacket` streams to the ADB interface. | ||
|
||
## `AdbDaemonWebUsbDeviceManager` | ||
|
||
A helper class that wraps the WebUSB API. | ||
|
||
### `BROWSER` | ||
|
||
```ts | ||
public static readonly BROWSER: AdbDaemonWebUsbDeviceManager | undefined; | ||
``` | ||
|
||
Gets the instance of `AdbDaemonWebUsbDeviceManager` using browser WebUSB implementation. | ||
|
||
May be `undefined` if the browser does not support WebUSB. | ||
|
||
### constructor | ||
|
||
```ts | ||
public constructor(usbManager: USB); | ||
``` | ||
|
||
Create a new instance of `AdbDaemonWebUsbDeviceManager` using the specified WebUSB API implementation. | ||
|
||
### `requestDevice` | ||
|
||
```ts | ||
public async requestDevice( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] | ||
): Promise<AdbDaemonWebUsbDevice | undefined> | ||
``` | ||
|
||
Request access to a connected device. | ||
This is a convince method for `usb.requestDevice()`. | ||
|
||
The `filters` parameter must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface. It can also have `vendorId`, `productId` or `serialNumber` fields to limit the displayed device list. | ||
|
||
Returns an `AdbDaemonWebUsbDevice` instance, or `undefined` if the user cancelled the picker. | ||
|
||
### `getDevices` | ||
|
||
```ts | ||
public async getDevices( | ||
filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER] | ||
): Promise<AdbDaemonWebUsbDevice[]> | ||
``` | ||
|
||
Get all connected and authenticated devices. | ||
|
||
This is a convince method for `usb.getDevices()`. | ||
|
||
## Note on secure context | ||
|
||
WebUSB requires a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS). | ||
|
||
`localhost` is considered secure, so local development works. But to access a self-hosted server running on another machine, either add a certificate, or add the domain name to the allowlist on each client machine: | ||
|
||
1. Open `chrome://flags/#unsafely-treat-insecure-origin-as-secure` | ||
2. Add the protocol and domain part of your url (e.g. `http://192.168.0.100:9000`) to the input box | ||
3. Choose `Enable` from the dropdown menu | ||
4. Restart browser | ||
<p align="center"> | ||
<img alt="Tango" src="https://raw.githubusercontent.com/yume-chan/ya-webadb/main/.github/logo.svg" width="200"> | ||
</p> | ||
|
||
<h1 align="center">@yume-chan/adb-daemon-webusb</h1> | ||
|
||
<p align="center"> | ||
Adb daemon transport connection for `@yume-chan/adb` using WebUSB API. | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://github.com/yume-chan/ya-webadb/blob/main/LICENSE"> | ||
<img alt="MIT License" src="https://img.shields.io/github/license/yume-chan/ya-webadb"> | ||
</a> | ||
<a href="https://github.com/yume-chan/ya-webadb/releases"> | ||
<img alt="GitHub release" src="https://img.shields.io/github/v/release/yume-chan/ya-webadb?logo=github"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/@yume-chan/adb"> | ||
<img alt="npm" src="https://img.shields.io/npm/dm/%40yume-chan/adb?logo=npm"> | ||
</a> | ||
<a href="https://discord.gg/26k3ttC2PN"> | ||
<img alt="Discord" src="https://img.shields.io/discord/1120215514732564502?logo=discord&logoColor=%23ffffff&label=Discord"> | ||
</a> | ||
</p> | ||
|
||
This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Generally you need multiple packages to build a complete ADB client that can run on Web browsers and Node.js. Read the documentation for more information. | ||
|
||
## Documentation | ||
|
||
Check the latest documentation at https://tango-adb.github.io/docs/ | ||
|
||
## Sponsors | ||
|
||
[Become a backer](https://opencollective.com/ya-webadb) and get your image on our README on Github with a link to your site. | ||
|
||
<a href="https://opencollective.com/ya-webadb/backer/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/0/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/1/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/2/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/2/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/3/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/3/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/4/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/4/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/5/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/5/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/6/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/6/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/7/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/7/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/8/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/8/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/9/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/9/avatar.svg?requireActive=false"></a> | ||
<a href="https://opencollective.com/ya-webadb/backer/10/website?requireActive=false" target="_blank"><img src="https://opencollective.com/ya-webadb/backer/10/avatar.svg?requireActive=false"></a> |
Oops, something went wrong.