@yume-chan/adb 0.0.10 → 0.0.13
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/CHANGELOG.json +50 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +1 -1
- package/README.md +71 -51
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +149 -136
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +11 -11
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +72 -110
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +19 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +49 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +56 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +88 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +35 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +53 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +39 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +157 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/protocols/index.d.ts +4 -0
- package/esm/commands/subprocess/protocols/index.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/index.js +4 -0
- package/esm/commands/subprocess/protocols/index.js.map +1 -0
- package/esm/commands/subprocess/protocols/none.d.ts +35 -0
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/none.js +53 -0
- package/esm/commands/subprocess/protocols/none.js.map +1 -0
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -0
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/shell.js +155 -0
- package/esm/commands/subprocess/protocols/shell.js.map +1 -0
- package/esm/commands/subprocess/protocols/types.d.ts +50 -0
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess/protocols}/types.js +0 -0
- package/esm/commands/subprocess/protocols/types.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +50 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/subprocess/types.js +2 -0
- package/esm/commands/{shell → subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +41 -0
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +52 -20
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +4 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +25 -27
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +4 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +17 -20
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +16 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +38 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +61 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +122 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +37 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +77 -62
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +8 -0
- package/esm/features.d.ts.map +1 -0
- package/esm/features.js +7 -3
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +47 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +27 -52
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +44 -0
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +146 -165
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +46 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +77 -13
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +2 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +5 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +9 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +402 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -5
- package/esm/utils/index.js.map +1 -1
- package/package.json +50 -44
- package/src/adb.ts +177 -150
- package/src/auth.ts +37 -30
- package/src/backend.ts +3 -12
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +24 -15
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +10 -8
- package/src/commands/subprocess/index.ts +139 -0
- package/src/commands/subprocess/protocols/index.ts +3 -0
- package/src/commands/subprocess/protocols/none.ts +68 -0
- package/src/commands/subprocess/protocols/shell.ts +190 -0
- package/src/commands/subprocess/protocols/types.ts +59 -0
- package/src/commands/{shell → subprocess}/utils.ts +0 -0
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +56 -9
- package/src/commands/sync/pull.ts +27 -18
- package/src/commands/sync/push.ts +25 -30
- package/src/commands/sync/request.ts +8 -7
- package/src/commands/sync/response.ts +12 -6
- package/src/commands/sync/stat.ts +43 -14
- package/src/commands/sync/sync.ts +102 -34
- package/src/commands/tcpip.ts +3 -3
- package/src/crypto.ts +95 -84
- package/src/features.ts +6 -2
- package/src/index.ts +11 -10
- package/src/packet.ts +49 -53
- package/src/socket/dispatcher.ts +110 -109
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +125 -17
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +28 -0
- package/src/stream/detect.ts +5 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +483 -0
- package/src/utils/auto-reset-event.ts +1 -1
- package/src/utils/base64.ts +161 -129
- package/src/utils/index.ts +3 -5
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -13
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -46
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -38
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -45
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -47
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts +0 -17
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -24
- package/dts/crypto.d.ts.map +0 -1
- package/dts/features.d.ts +0 -6
- package/dts/features.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts +0 -53
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -28
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/encoding.d.ts +0 -3
- package/dts/utils/encoding.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -6
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -62
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -49
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -106
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -67
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -87
- package/src/commands/shell/legacy.ts +0 -59
- package/src/commands/shell/protocol.ts +0 -121
- package/src/commands/shell/types.ts +0 -55
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -92
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/encoding.ts +0 -13
- package/src/utils/event-queue.ts +0 -145
package/esm/adb.js
CHANGED
|
@@ -1,55 +1,78 @@
|
|
|
1
|
-
|
|
1
|
+
// cspell: ignore libusb
|
|
2
2
|
import { PromiseResolver } from '@yume-chan/async';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { decodeUtf8 } from "./utils";
|
|
3
|
+
import { AdbAuthenticationProcessor, ADB_DEFAULT_AUTHENTICATORS } from './auth.js';
|
|
4
|
+
import { AdbPower, AdbReverseCommand, AdbSubprocess, AdbSync, AdbTcpIpCommand, escapeArg, framebuffer, install } from './commands/index.js';
|
|
5
|
+
import { AdbFeatures } from './features.js';
|
|
6
|
+
import { AdbCommand, calculateChecksum } from './packet.js';
|
|
7
|
+
import { AdbPacketDispatcher } from './socket/index.js';
|
|
8
|
+
import { AbortController, DecodeUtf8Stream, GatherStringStream, WritableStream } from "./stream/index.js";
|
|
9
|
+
import { decodeUtf8, encodeUtf8 } from "./utils/index.js";
|
|
10
10
|
export var AdbPropKey;
|
|
11
11
|
(function (AdbPropKey) {
|
|
12
12
|
AdbPropKey["Product"] = "ro.product.name";
|
|
13
13
|
AdbPropKey["Model"] = "ro.product.model";
|
|
14
14
|
AdbPropKey["Device"] = "ro.product.device";
|
|
15
15
|
AdbPropKey["Features"] = "features";
|
|
16
|
-
})(AdbPropKey || (AdbPropKey = {}));
|
|
16
|
+
})(AdbPropKey = AdbPropKey || (AdbPropKey = {}));
|
|
17
|
+
export const VERSION_OMIT_CHECKSUM = 0x01000001;
|
|
17
18
|
export class Adb {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
/**
|
|
20
|
+
* It's possible to call `authenticate` multiple times on a single connection,
|
|
21
|
+
* every time the device receives a `CNXN` packet, it resets its internal state,
|
|
22
|
+
* and starts a new authentication process.
|
|
23
|
+
*/
|
|
24
|
+
static async authenticate(connection, credentialStore, authenticators = ADB_DEFAULT_AUTHENTICATORS) {
|
|
25
|
+
// Initially, set to highest-supported version and payload size.
|
|
26
|
+
let version = 0x01000001;
|
|
27
|
+
let maxPayloadSize = 0x100000;
|
|
28
|
+
const resolver = new PromiseResolver();
|
|
29
|
+
const authProcessor = new AdbAuthenticationProcessor(authenticators, credentialStore);
|
|
30
|
+
// Here is similar to `AdbPacketDispatcher`,
|
|
31
|
+
// But the received packet types and send packet processing are different.
|
|
32
|
+
const abortController = new AbortController();
|
|
33
|
+
const pipe = connection.readable
|
|
34
|
+
.pipeTo(new WritableStream({
|
|
35
|
+
async write(packet) {
|
|
36
|
+
switch (packet.command) {
|
|
37
|
+
case AdbCommand.Connect:
|
|
38
|
+
version = Math.min(version, packet.arg0);
|
|
39
|
+
maxPayloadSize = Math.min(maxPayloadSize, packet.arg1);
|
|
40
|
+
resolver.resolve(decodeUtf8(packet.payload));
|
|
41
|
+
break;
|
|
42
|
+
case AdbCommand.Auth:
|
|
43
|
+
const response = await authProcessor.process(packet);
|
|
44
|
+
await sendPacket(response);
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
// Maybe the previous ADB session exited without reading all packets,
|
|
48
|
+
// so they are still waiting in OS internal buffer.
|
|
49
|
+
// Just ignore them.
|
|
50
|
+
// Because a `Connect` packet will reset the device,
|
|
51
|
+
// Eventually there will be `Connect` and `Auth` response packets.
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}), {
|
|
56
|
+
preventCancel: true,
|
|
57
|
+
signal: abortController.signal,
|
|
58
|
+
})
|
|
59
|
+
.catch((e) => {
|
|
60
|
+
resolver.reject(e);
|
|
61
|
+
});
|
|
62
|
+
const writer = connection.writable.getWriter();
|
|
63
|
+
async function sendPacket(init) {
|
|
64
|
+
// Always send checksum in auth steps
|
|
65
|
+
// Because we don't know if the device needs it or not.
|
|
66
|
+
await writer.write(calculateChecksum(init));
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
// https://android.googlesource.com/platform/packages/modules/adb/+/79010dc6d5ca7490c493df800d4421730f5466ca/transport.cpp#1252
|
|
70
|
+
// There are some other feature constants, but some of them are only used by ADB server, not devices.
|
|
48
71
|
const features = [
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
AdbFeatures.ShellV2,
|
|
73
|
+
AdbFeatures.Cmd,
|
|
51
74
|
AdbFeatures.StatV2,
|
|
52
|
-
|
|
75
|
+
AdbFeatures.ListV2,
|
|
53
76
|
'fixed_push_mkdir',
|
|
54
77
|
'apex',
|
|
55
78
|
'abb',
|
|
@@ -63,59 +86,67 @@ export class Adb {
|
|
|
63
86
|
'sendrecv_v2_zstd',
|
|
64
87
|
'sendrecv_v2_dry_run_send',
|
|
65
88
|
].join(',');
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
89
|
+
await sendPacket({
|
|
90
|
+
command: AdbCommand.Connect,
|
|
91
|
+
arg0: version,
|
|
92
|
+
arg1: maxPayloadSize,
|
|
93
|
+
// The terminating `;` is required in formal definition
|
|
94
|
+
// But ADB daemon (all versions) can still work without it
|
|
95
|
+
payload: encodeUtf8(`host::features=${features};`),
|
|
96
|
+
});
|
|
97
|
+
const banner = await resolver.promise;
|
|
98
|
+
// Stop piping before creating `Adb` object
|
|
99
|
+
// Because `AdbPacketDispatcher` will lock the streams when initializing
|
|
100
|
+
abortController.abort();
|
|
101
|
+
writer.releaseLock();
|
|
102
|
+
// Wait until pipe stops (`ReadableStream` lock released)
|
|
103
|
+
await pipe;
|
|
104
|
+
return new Adb(connection, version, maxPayloadSize, banner);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
abortController.abort();
|
|
108
|
+
writer.releaseLock();
|
|
109
|
+
throw e;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
packetDispatcher;
|
|
113
|
+
get disconnected() { return this.packetDispatcher.disconnected; }
|
|
114
|
+
_protocolVersion;
|
|
115
|
+
get protocolVersion() { return this._protocolVersion; }
|
|
116
|
+
_product;
|
|
117
|
+
get product() { return this._product; }
|
|
118
|
+
_model;
|
|
119
|
+
get model() { return this._model; }
|
|
120
|
+
_device;
|
|
121
|
+
get device() { return this._device; }
|
|
122
|
+
_features;
|
|
123
|
+
get features() { return this._features; }
|
|
124
|
+
subprocess;
|
|
125
|
+
power;
|
|
126
|
+
reverse;
|
|
127
|
+
tcpip;
|
|
128
|
+
constructor(connection, version, maxPayloadSize, banner) {
|
|
129
|
+
this.parseBanner(banner);
|
|
130
|
+
let calculateChecksum;
|
|
131
|
+
let appendNullToServiceString;
|
|
132
|
+
if (version >= VERSION_OMIT_CHECKSUM) {
|
|
133
|
+
calculateChecksum = false;
|
|
134
|
+
appendNullToServiceString = false;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
calculateChecksum = true;
|
|
138
|
+
appendNullToServiceString = true;
|
|
139
|
+
}
|
|
140
|
+
this.packetDispatcher = new AdbPacketDispatcher(connection, {
|
|
141
|
+
calculateChecksum,
|
|
142
|
+
appendNullToServiceString,
|
|
143
|
+
maxPayloadSize,
|
|
118
144
|
});
|
|
145
|
+
this._protocolVersion = version;
|
|
146
|
+
this.subprocess = new AdbSubprocess(this);
|
|
147
|
+
this.power = new AdbPower(this);
|
|
148
|
+
this.reverse = new AdbReverseCommand(this.packetDispatcher);
|
|
149
|
+
this.tcpip = new AdbTcpIpCommand(this);
|
|
119
150
|
}
|
|
120
151
|
parseBanner(banner) {
|
|
121
152
|
this._features = [];
|
|
@@ -148,55 +179,37 @@ export class Adb {
|
|
|
148
179
|
}
|
|
149
180
|
}
|
|
150
181
|
}
|
|
151
|
-
|
|
152
|
-
return
|
|
153
|
-
const output = yield this.childProcess.exec('getprop', key);
|
|
154
|
-
return output.trim();
|
|
155
|
-
});
|
|
182
|
+
async createSocket(service) {
|
|
183
|
+
return this.packetDispatcher.createSocket(service);
|
|
156
184
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
async createSocketAndWait(service) {
|
|
186
|
+
const socket = await this.createSocket(service);
|
|
187
|
+
const gatherStream = new GatherStringStream();
|
|
188
|
+
await socket.readable
|
|
189
|
+
.pipeThrough(new DecodeUtf8Stream())
|
|
190
|
+
.pipeTo(gatherStream);
|
|
191
|
+
return gatherStream.result;
|
|
161
192
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
});
|
|
193
|
+
async getProp(key) {
|
|
194
|
+
const stdout = await this.subprocess.spawnAndWaitLegacy(['getprop', key]);
|
|
195
|
+
return stdout.trim();
|
|
166
196
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return new AdbSync(this, socket);
|
|
171
|
-
});
|
|
197
|
+
async rm(...filenames) {
|
|
198
|
+
const stdout = await this.subprocess.spawnAndWaitLegacy(['rm', '-rf', ...filenames.map(arg => escapeArg(arg))]);
|
|
199
|
+
return stdout;
|
|
172
200
|
}
|
|
173
|
-
|
|
174
|
-
return
|
|
175
|
-
return framebuffer(this);
|
|
176
|
-
});
|
|
201
|
+
install() {
|
|
202
|
+
return install(this);
|
|
177
203
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
204
|
+
async sync() {
|
|
205
|
+
const socket = await this.createSocket('sync:');
|
|
206
|
+
return new AdbSync(this, socket);
|
|
182
207
|
}
|
|
183
|
-
|
|
184
|
-
return
|
|
185
|
-
const socket = yield this.createSocket(service);
|
|
186
|
-
const resolver = new PromiseResolver();
|
|
187
|
-
let result = '';
|
|
188
|
-
socket.onData(buffer => {
|
|
189
|
-
result += decodeUtf8(buffer);
|
|
190
|
-
});
|
|
191
|
-
socket.onClose(() => resolver.resolve(result));
|
|
192
|
-
return resolver.promise;
|
|
193
|
-
});
|
|
208
|
+
async framebuffer() {
|
|
209
|
+
return framebuffer(this);
|
|
194
210
|
}
|
|
195
|
-
dispose() {
|
|
196
|
-
|
|
197
|
-
this.packetDispatcher.dispose();
|
|
198
|
-
yield this.backend.dispose();
|
|
199
|
-
});
|
|
211
|
+
async dispose() {
|
|
212
|
+
this.packetDispatcher.dispose();
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
//# sourceMappingURL=adb.js.map
|
package/esm/adb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adb.js","sourceRoot":"","sources":["../src/adb.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adb.js","sourceRoot":"","sources":["../src/adb.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,0BAA0B,EAA2B,MAAM,WAAW,CAAC;AAC5G,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAuB,MAAM,qBAAqB,CAAC;AACjK,OAAO,EAAE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ACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,EAAE,CAAC,GAAG,SAAmB;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,kBAAkB,CACnD,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CACzD,CAAC;QACF,OAAO,MAAM,CAAC;IAClB,CAAC;IAEM,OAAO;QACV,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,IAAI;QACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,WAAW;QACpB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,OAAO;QAChB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
package/{dts → esm}/auth.d.ts
RENAMED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Disposable } from '@yume-chan/event';
|
|
2
|
-
import { ValueOrPromise } from '@yume-chan/struct';
|
|
3
|
-
import {
|
|
4
|
-
export declare type AdbKeyIterable = Iterable<
|
|
1
|
+
import type { Disposable } from '@yume-chan/event';
|
|
2
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
3
|
+
import { type AdbPacketData } from './packet.js';
|
|
4
|
+
export declare type AdbKeyIterable = Iterable<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
5
5
|
export interface AdbCredentialStore {
|
|
6
6
|
/**
|
|
7
7
|
* Generate and store a RSA private key with modulus length `2048` and public exponent `65537`.
|
|
8
8
|
*
|
|
9
|
-
* The returned `
|
|
9
|
+
* The returned `Uint8Array` is the private key in PKCS #8 format.
|
|
10
10
|
*/
|
|
11
|
-
generateKey(): ValueOrPromise<
|
|
11
|
+
generateKey(): ValueOrPromise<Uint8Array>;
|
|
12
12
|
/**
|
|
13
13
|
* Synchronously or asynchronously iterate through all stored RSA private keys.
|
|
14
14
|
*
|
|
@@ -33,20 +33,20 @@ export interface AdbAuthenticator {
|
|
|
33
33
|
*
|
|
34
34
|
* Calling `getNextRequest` multiple times without `yield` or `return` will always return the same request.
|
|
35
35
|
*/
|
|
36
|
-
(credentialStore: AdbCredentialStore, getNextRequest: () => Promise<
|
|
36
|
+
(credentialStore: AdbCredentialStore, getNextRequest: () => Promise<AdbPacketData>): AsyncIterable<AdbPacketData>;
|
|
37
37
|
}
|
|
38
38
|
export declare const AdbSignatureAuthenticator: AdbAuthenticator;
|
|
39
39
|
export declare const AdbPublicKeyAuthenticator: AdbAuthenticator;
|
|
40
|
-
export declare const
|
|
41
|
-
export declare class
|
|
40
|
+
export declare const ADB_DEFAULT_AUTHENTICATORS: AdbAuthenticator[];
|
|
41
|
+
export declare class AdbAuthenticationProcessor implements Disposable {
|
|
42
42
|
readonly authenticators: readonly AdbAuthenticator[];
|
|
43
43
|
private readonly credentialStore;
|
|
44
44
|
private pendingRequest;
|
|
45
45
|
private iterator;
|
|
46
46
|
constructor(authenticators: readonly AdbAuthenticator[], credentialStore: AdbCredentialStore);
|
|
47
47
|
private getNextRequest;
|
|
48
|
-
private
|
|
49
|
-
|
|
48
|
+
private invokeAuthenticator;
|
|
49
|
+
process(packet: AdbPacketData): Promise<AdbPacketData>;
|
|
50
50
|
dispose(): void;
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,K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
1
|
import { PromiseResolver } from '@yume-chan/async';
|
|
3
|
-
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto';
|
|
4
|
-
import { AdbCommand } from './packet';
|
|
5
|
-
import { calculateBase64EncodedLength, encodeBase64 } from './utils';
|
|
2
|
+
import { calculatePublicKey, calculatePublicKeyLength, sign } from './crypto.js';
|
|
3
|
+
import { AdbCommand } from './packet.js';
|
|
4
|
+
import { calculateBase64EncodedLength, encodeBase64 } from './utils/index.js';
|
|
6
5
|
export var AdbAuthType;
|
|
7
6
|
(function (AdbAuthType) {
|
|
8
7
|
AdbAuthType[AdbAuthType["Token"] = 1] = "Token";
|
|
9
8
|
AdbAuthType[AdbAuthType["Signature"] = 2] = "Signature";
|
|
10
9
|
AdbAuthType[AdbAuthType["PublicKey"] = 3] = "PublicKey";
|
|
11
|
-
})(AdbAuthType || (AdbAuthType = {}));
|
|
12
|
-
export const AdbSignatureAuthenticator = function (credentialStore, getNextRequest) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
for (var _b = __asyncValues(credentialStore.iterateKeys()), _c; _c = yield __await(_b.next()), !_c.done;) {
|
|
17
|
-
const key = _c.value;
|
|
18
|
-
const packet = yield __await(getNextRequest());
|
|
19
|
-
if (packet.arg0 !== AdbAuthType.Token) {
|
|
20
|
-
return yield __await(void 0);
|
|
21
|
-
}
|
|
22
|
-
const signature = sign(key, packet.payload);
|
|
23
|
-
yield yield __await({
|
|
24
|
-
command: AdbCommand.Auth,
|
|
25
|
-
arg0: AdbAuthType.Signature,
|
|
26
|
-
arg1: 0,
|
|
27
|
-
payload: signature,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
32
|
-
finally {
|
|
33
|
-
try {
|
|
34
|
-
if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
|
|
35
|
-
}
|
|
36
|
-
finally { if (e_1) throw e_1.error; }
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
export const AdbPublicKeyAuthenticator = function (credentialStore, getNextRequest) {
|
|
41
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
42
|
-
var e_2, _a;
|
|
43
|
-
const packet = yield __await(getNextRequest());
|
|
10
|
+
})(AdbAuthType = AdbAuthType || (AdbAuthType = {}));
|
|
11
|
+
export const AdbSignatureAuthenticator = async function* (credentialStore, getNextRequest) {
|
|
12
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
13
|
+
const packet = await getNextRequest();
|
|
44
14
|
if (packet.arg0 !== AdbAuthType.Token) {
|
|
45
|
-
return
|
|
15
|
+
return;
|
|
46
16
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (var _b = __asyncValues(credentialStore.iterateKeys()), _c; _c = yield __await(_b.next()), !_c.done;) {
|
|
50
|
-
const key = _c.value;
|
|
51
|
-
privateKey = key;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
56
|
-
finally {
|
|
57
|
-
try {
|
|
58
|
-
if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
|
|
59
|
-
}
|
|
60
|
-
finally { if (e_2) throw e_2.error; }
|
|
61
|
-
}
|
|
62
|
-
if (!privateKey) {
|
|
63
|
-
privateKey = yield __await(credentialStore.generateKey());
|
|
64
|
-
}
|
|
65
|
-
const publicKeyLength = calculatePublicKeyLength();
|
|
66
|
-
const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
|
|
67
|
-
// The public key is null terminated,
|
|
68
|
-
// So we allocate the buffer with one extra byte.
|
|
69
|
-
const publicKeyBuffer = new ArrayBuffer(publicKeyBase64Length + 1);
|
|
70
|
-
calculatePublicKey(privateKey, publicKeyBuffer);
|
|
71
|
-
encodeBase64(publicKeyBuffer, 0, publicKeyLength, publicKeyBuffer);
|
|
72
|
-
yield yield __await({
|
|
17
|
+
const signature = sign(key, packet.payload);
|
|
18
|
+
yield {
|
|
73
19
|
command: AdbCommand.Auth,
|
|
74
|
-
arg0: AdbAuthType.
|
|
20
|
+
arg0: AdbAuthType.Signature,
|
|
75
21
|
arg1: 0,
|
|
76
|
-
payload:
|
|
77
|
-
}
|
|
78
|
-
}
|
|
22
|
+
payload: new Uint8Array(signature),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const AdbPublicKeyAuthenticator = async function* (credentialStore, getNextRequest) {
|
|
27
|
+
const packet = await getNextRequest();
|
|
28
|
+
if (packet.arg0 !== AdbAuthType.Token) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let privateKey;
|
|
32
|
+
for await (const key of credentialStore.iterateKeys()) {
|
|
33
|
+
privateKey = key;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (!privateKey) {
|
|
37
|
+
privateKey = await credentialStore.generateKey();
|
|
38
|
+
}
|
|
39
|
+
const publicKeyLength = calculatePublicKeyLength();
|
|
40
|
+
const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
|
|
41
|
+
// The public key is null terminated,
|
|
42
|
+
// So we allocate the buffer with one extra byte.
|
|
43
|
+
const publicKeyBuffer = new Uint8Array(publicKeyBase64Length + 1);
|
|
44
|
+
calculatePublicKey(privateKey, publicKeyBuffer);
|
|
45
|
+
encodeBase64(publicKeyBuffer.subarray(0, publicKeyLength), publicKeyBuffer);
|
|
46
|
+
yield {
|
|
47
|
+
command: AdbCommand.Auth,
|
|
48
|
+
arg0: AdbAuthType.PublicKey,
|
|
49
|
+
arg1: 0,
|
|
50
|
+
payload: publicKeyBuffer,
|
|
51
|
+
};
|
|
79
52
|
};
|
|
80
|
-
export const
|
|
53
|
+
export const ADB_DEFAULT_AUTHENTICATORS = [
|
|
81
54
|
AdbSignatureAuthenticator,
|
|
82
55
|
AdbPublicKeyAuthenticator,
|
|
83
56
|
];
|
|
84
|
-
export class
|
|
57
|
+
export class AdbAuthenticationProcessor {
|
|
58
|
+
authenticators;
|
|
59
|
+
credentialStore;
|
|
60
|
+
pendingRequest = new PromiseResolver();
|
|
61
|
+
iterator;
|
|
85
62
|
constructor(authenticators, credentialStore) {
|
|
86
|
-
this.pendingRequest = new PromiseResolver();
|
|
87
|
-
this.getNextRequest = () => {
|
|
88
|
-
return this.pendingRequest.promise;
|
|
89
|
-
};
|
|
90
63
|
this.authenticators = authenticators;
|
|
91
64
|
this.credentialStore = credentialStore;
|
|
92
65
|
}
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
yield yield __await(packet);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
108
|
-
finally {
|
|
109
|
-
try {
|
|
110
|
-
if (_c && !_c.done && (_a = _b.return)) yield __await(_a.call(_b));
|
|
111
|
-
}
|
|
112
|
-
finally { if (e_3) throw e_3.error; }
|
|
113
|
-
}
|
|
114
|
-
// If the authenticator returned,
|
|
115
|
-
// Next authenticator will be given the same `pendingRequest`
|
|
66
|
+
getNextRequest = () => {
|
|
67
|
+
return this.pendingRequest.promise;
|
|
68
|
+
};
|
|
69
|
+
async *invokeAuthenticator() {
|
|
70
|
+
for (const authenticator of this.authenticators) {
|
|
71
|
+
for await (const packet of authenticator(this.credentialStore, this.getNextRequest)) {
|
|
72
|
+
// If the authenticator yielded a response
|
|
73
|
+
// Prepare `nextRequest` for next authentication request
|
|
74
|
+
this.pendingRequest = new PromiseResolver();
|
|
75
|
+
// Yield the response to outer layer
|
|
76
|
+
yield packet;
|
|
116
77
|
}
|
|
117
|
-
|
|
118
|
-
|
|
78
|
+
// If the authenticator returned,
|
|
79
|
+
// Next authenticator will be given the same `pendingRequest`
|
|
80
|
+
}
|
|
119
81
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
82
|
+
async process(packet) {
|
|
83
|
+
if (!this.iterator) {
|
|
84
|
+
this.iterator = this.invokeAuthenticator();
|
|
85
|
+
}
|
|
86
|
+
this.pendingRequest.resolve(packet);
|
|
87
|
+
const result = await this.iterator.next();
|
|
88
|
+
if (result.done) {
|
|
89
|
+
throw new Error('No authenticator can handle the request');
|
|
90
|
+
}
|
|
91
|
+
return result.value;
|
|
129
92
|
}
|
|
130
93
|
dispose() {
|
|
131
|
-
|
|
132
|
-
(_b = (_a = this.iterator) === null || _a === void 0 ? void 0 : _a.return) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
94
|
+
this.iterator?.return?.();
|
|
133
95
|
}
|
|
134
96
|
}
|
|
135
97
|
//# sourceMappingURL=auth.js.map
|