@yume-chan/adb-credential-web 0.0.10

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.
File without changes
@@ -0,0 +1,10 @@
1
+ {
2
+ "files": {
3
+ "libraries/adb-credential-web/.rush/temp/shrinkwrap-deps.json": "1425648bdf799a63152e303d86be9555f8643497",
4
+ "libraries/adb-credential-web/README.md": "6127ebcf1f2d1aa76c1a1c70c1eb7b75061369c6",
5
+ "libraries/adb-credential-web/package.json": "8a38b7eaff0a80f419d2ac37cf17d54c04b328ec",
6
+ "libraries/adb-credential-web/src/index.ts": "b4ce8682d8a0e7bdc8d33b4615d96856203c83e4",
7
+ "libraries/adb-credential-web/tsconfig.json": "07f9242b115ab18b8e8d2564d25d32349ffb21cb"
8
+ },
9
+ "arguments": "build-ts-package "
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "files": {
3
+ "libraries/adb-credential-web/.rush/temp/shrinkwrap-deps.json": "1425648bdf799a63152e303d86be9555f8643497",
4
+ "libraries/adb-credential-web/README.md": "6127ebcf1f2d1aa76c1a1c70c1eb7b75061369c6",
5
+ "libraries/adb-credential-web/package.json": "fe73866e135bf1100de8d7b8f44f058f248e0ffb",
6
+ "libraries/adb-credential-web/src/index.ts": "b4ce8682d8a0e7bdc8d33b4615d96856203c83e4",
7
+ "libraries/adb-credential-web/tsconfig.json": "07f9242b115ab18b8e8d2564d25d32349ffb21cb"
8
+ },
9
+ "arguments": ""
10
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "@yume-chan/async@2.1.4": "sha512-dfzxt6iV7G3m+XEIHJH0eNBjh0bxI0pduRCGpA+dR1u38l7U87GpnGm2Vq1/Na+C1ZWod6mJMRoDECLKjWYXEg==",
3
+ "tslib@2.0.3": "sha512-uZtkfKblCEQtZKBF6EBXVZeQNl82yqtDQdv+eck8u7tdPxjLu2/lp5/uPW+um2tpuxINHWy3GhiccY7QgEaVHQ==",
4
+ "tslib@2.3.1": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==",
5
+ "typescript@4.5.4": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg=="
6
+ }
package/CHANGELOG.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@yume-chan/adb-credential-web",
3
+ "entries": [
4
+ {
5
+ "version": "0.0.10",
6
+ "tag": "@yume-chan/adb-credential-web_v0.0.10",
7
+ "date": "Sun, 09 Jan 2022 15:52:20 GMT",
8
+ "comments": {}
9
+ }
10
+ ]
11
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Change Log - @yume-chan/adb-credential-web
2
+
3
+ This log was last generated on Sun, 09 Jan 2022 15:52:20 GMT and should not be manually modified.
4
+
5
+ ## 0.0.10
6
+ Sun, 09 Jan 2022 15:52:20 GMT
7
+
8
+ _Initial release_
9
+
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@yume-chan/adb-credential-web`
2
+
3
+ Store ADB credentials in LocalStorage.
@@ -0,0 +1,2 @@
1
+ Invoking: build-ts-package --incremental
2
+
package/dts/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { AdbCredentialStore } from "@yume-chan/adb";
2
+ export declare function encodeUtf8(input: string): ArrayBuffer;
3
+ export declare function decodeUtf8(buffer: ArrayBuffer): string;
4
+ export default class AdbWebCredentialStore implements AdbCredentialStore {
5
+ readonly localStorageKey: string;
6
+ constructor(localStorageKey?: string);
7
+ iterateKeys(): Generator<ArrayBuffer, void, void>;
8
+ generateKey(): Promise<ArrayBuffer>;
9
+ }
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA0G,MAAM,gBAAgB,CAAC;AAK5J,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAErD;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAEtD;AAED,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,kBAAkB;IACpE,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAErB,eAAe,SAAgB;IAI1C,WAAW,IAAI,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC;IAO5C,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;CA6BnD"}
package/esm/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { __awaiter } from "tslib";
2
+ import { calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64 } from "@yume-chan/adb";
3
+ const Utf8Encoder = new TextEncoder();
4
+ const Utf8Decoder = new TextDecoder();
5
+ export function encodeUtf8(input) {
6
+ return Utf8Encoder.encode(input).buffer;
7
+ }
8
+ export function decodeUtf8(buffer) {
9
+ return Utf8Decoder.decode(buffer);
10
+ }
11
+ export default class AdbWebCredentialStore {
12
+ constructor(localStorageKey = 'private-key') {
13
+ this.localStorageKey = localStorageKey;
14
+ }
15
+ *iterateKeys() {
16
+ const privateKey = window.localStorage.getItem(this.localStorageKey);
17
+ if (privateKey) {
18
+ yield decodeBase64(privateKey);
19
+ }
20
+ }
21
+ generateKey() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const { privateKey: cryptoKey } = yield crypto.subtle.generateKey({
24
+ name: 'RSASSA-PKCS1-v1_5',
25
+ modulusLength: 2048,
26
+ // 65537
27
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
28
+ hash: 'SHA-1',
29
+ }, true, ['sign', 'verify']);
30
+ const privateKey = yield crypto.subtle.exportKey('pkcs8', cryptoKey);
31
+ window.localStorage.setItem(this.localStorageKey, decodeUtf8(encodeBase64(privateKey)));
32
+ // The authentication module in core doesn't need public keys.
33
+ // It will generate the public key from private key every time.
34
+ // However, maybe there are people want to manually put this public key onto their device,
35
+ // so also save the public key for their convenience.
36
+ const publicKeyLength = calculatePublicKeyLength();
37
+ const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
38
+ const publicKeyBuffer = new ArrayBuffer(publicKeyBase64Length);
39
+ calculatePublicKey(privateKey, publicKeyBuffer);
40
+ encodeBase64(publicKeyBuffer, 0, publicKeyLength, publicKeyBuffer);
41
+ window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
42
+ return privateKey;
43
+ });
44
+ }
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAsB,4BAA4B,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE5J,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,MAAM,UAAU,UAAU,CAAC,KAAa;IACpC,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAmB;IAC1C,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,OAAO,OAAO,qBAAqB;IAGtC,YAAmB,eAAe,GAAG,aAAa;QAC9C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAEM,CAAC,WAAW;QACf,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACrE,IAAI,UAAU,EAAE;YACZ,MAAM,YAAY,CAAC,UAAU,CAAC,C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web LocalStorage API.",
5
+ "keywords": [
6
+ "adb"
7
+ ],
8
+ "license": "MIT",
9
+ "author": {
10
+ "name": "Simon Chan",
11
+ "email": "cnsimonchan@live.com",
12
+ "url": "https://chensi.moe/blog"
13
+ },
14
+ "homepage": "https://github.com/yume-chan/ya-webadb/tree/master/libraries/adb-credential-web#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/yume-chan/ya-webadb.git",
18
+ "directory": "libraries/adb-credential-web"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/yume-chan/ya-webadb/issues"
22
+ },
23
+ "type": "module",
24
+ "module": "esm/index.js",
25
+ "types": "dts/index.d.ts",
26
+ "scripts": {
27
+ "build": "build-ts-package",
28
+ "build:watch": "build-ts-package --incremental"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^4.5.4",
32
+ "@yume-chan/ts-package-builder": "^1.0.0"
33
+ },
34
+ "dependencies": {
35
+ "@yume-chan/adb": "^0.0.10",
36
+ "tslib": "^2.3.1"
37
+ }
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { AdbCredentialStore, calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64 } from "@yume-chan/adb";
2
+
3
+ const Utf8Encoder = new TextEncoder();
4
+ const Utf8Decoder = new TextDecoder();
5
+
6
+ export function encodeUtf8(input: string): ArrayBuffer {
7
+ return Utf8Encoder.encode(input).buffer;
8
+ }
9
+
10
+ export function decodeUtf8(buffer: ArrayBuffer): string {
11
+ return Utf8Decoder.decode(buffer);
12
+ }
13
+
14
+ export default class AdbWebCredentialStore implements AdbCredentialStore {
15
+ public readonly localStorageKey: string;
16
+
17
+ public constructor(localStorageKey = 'private-key') {
18
+ this.localStorageKey = localStorageKey;
19
+ }
20
+
21
+ public *iterateKeys(): Generator<ArrayBuffer, void, void> {
22
+ const privateKey = window.localStorage.getItem(this.localStorageKey);
23
+ if (privateKey) {
24
+ yield decodeBase64(privateKey);
25
+ }
26
+ }
27
+
28
+ public async generateKey(): Promise<ArrayBuffer> {
29
+ const { privateKey: cryptoKey } = await crypto.subtle.generateKey(
30
+ {
31
+ name: 'RSASSA-PKCS1-v1_5',
32
+ modulusLength: 2048,
33
+ // 65537
34
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
35
+ hash: 'SHA-1',
36
+ },
37
+ true,
38
+ ['sign', 'verify']
39
+ );
40
+
41
+ const privateKey = await crypto.subtle.exportKey('pkcs8', cryptoKey!);
42
+ window.localStorage.setItem(this.localStorageKey, decodeUtf8(encodeBase64(privateKey)));
43
+
44
+ // The authentication module in core doesn't need public keys.
45
+ // It will generate the public key from private key every time.
46
+ // However, maybe there are people want to manually put this public key onto their device,
47
+ // so also save the public key for their convenience.
48
+ const publicKeyLength = calculatePublicKeyLength();
49
+ const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
50
+ const publicKeyBuffer = new ArrayBuffer(publicKeyBase64Length);
51
+ calculatePublicKey(privateKey, publicKeyBuffer);
52
+ encodeBase64(publicKeyBuffer, 0, publicKeyLength, publicKeyBuffer);
53
+ window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
54
+
55
+ return privateKey;
56
+ }
57
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./node_modules/@yume-chan/ts-package-builder/tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": [
5
+ "ESNext",
6
+ "DOM"
7
+ ],
8
+ },
9
+ "references": [
10
+ {
11
+ "path": "../adb/tsconfig.json"
12
+ }
13
+ ]
14
+ }