@yume-chan/adb-credential-web 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.
@@ -1,10 +1,12 @@
1
1
  {
2
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"
3
+ "libraries/adb-credential-web/.rush/temp/shrinkwrap-deps.json": "33b90fa9ac2c165d2c550be4daa30217e725766d",
4
+ "libraries/adb-credential-web/CHANGELOG.json": "4bd9bb01844f5d68579ef4fbbb5757399c86faa5",
5
+ "libraries/adb-credential-web/CHANGELOG.md": "1efe083e89e217c2fee3e542ef5ab717ae56769c",
6
+ "libraries/adb-credential-web/README.md": "35dc273a753ae6f722bad96ae6e52efe9b2d6840",
7
+ "libraries/adb-credential-web/package.json": "4f44ba4eb7d52639bd2f13c49714f775f6762b9c",
8
+ "libraries/adb-credential-web/src/index.ts": "42f5ead9cfde7266096dce1e82f3c7cc0309986b",
9
+ "libraries/adb-credential-web/tsconfig.json": "43cb24d0667828c30374e15c5930a55ea1b0bb7e"
8
10
  },
9
11
  "arguments": "build-ts-package "
10
12
  }
@@ -0,0 +1,12 @@
1
+ {
2
+ "files": {
3
+ "libraries/adb-credential-web/.rush/temp/shrinkwrap-deps.json": "33b90fa9ac2c165d2c550be4daa30217e725766d",
4
+ "libraries/adb-credential-web/CHANGELOG.json": "4bd9bb01844f5d68579ef4fbbb5757399c86faa5",
5
+ "libraries/adb-credential-web/CHANGELOG.md": "1efe083e89e217c2fee3e542ef5ab717ae56769c",
6
+ "libraries/adb-credential-web/README.md": "35dc273a753ae6f722bad96ae6e52efe9b2d6840",
7
+ "libraries/adb-credential-web/package.json": "4f44ba4eb7d52639bd2f13c49714f775f6762b9c",
8
+ "libraries/adb-credential-web/src/index.ts": "42f5ead9cfde7266096dce1e82f3c7cc0309986b",
9
+ "libraries/adb-credential-web/tsconfig.json": "43cb24d0667828c30374e15c5930a55ea1b0bb7e"
10
+ },
11
+ "arguments": "build-ts-package --incremental "
12
+ }
@@ -1,9 +1,11 @@
1
1
  {
2
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",
3
+ "libraries/adb-credential-web/.rush/temp/shrinkwrap-deps.json": "7af6854cfa1793d25c7925569515eabafc855d04",
4
+ "libraries/adb-credential-web/CHANGELOG.json": "bdb99f8ca3eff53b8b260fae2e230e34d55a6902",
5
+ "libraries/adb-credential-web/CHANGELOG.md": "89f2ed92996da15a9f5ac27a7ff3d64b58b72f35",
6
+ "libraries/adb-credential-web/README.md": "842d937a3588938e938cc11ec157f820a8825418",
7
+ "libraries/adb-credential-web/package.json": "1ffae23b46edfaf644734e9dcf5cc15eaeb150ba",
8
+ "libraries/adb-credential-web/src/index.ts": "665518496f9ef6f8cc212e7a0636533b39763516",
7
9
  "libraries/adb-credential-web/tsconfig.json": "07f9242b115ab18b8e8d2564d25d32349ffb21cb"
8
10
  },
9
11
  "arguments": ""
@@ -1,6 +1,4 @@
1
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
2
  "tslib@2.3.1": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==",
5
- "typescript@4.5.4": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg=="
3
+ "typescript@4.7.0-beta": "sha512-m+CNL8lzHyHDxYYDTI+pm5hw5/bufYVGan2bokPyJY/y9C/4W/PCWMtYZ0vV9fLXbEL57elMeoaz9Evxs8UQ+A=="
6
4
  }
package/CHANGELOG.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@yume-chan/adb-credential-web",
3
3
  "entries": [
4
+ {
5
+ "version": "0.0.13",
6
+ "tag": "@yume-chan/adb-credential-web_v0.0.13",
7
+ "date": "Thu, 28 Apr 2022 01:23:53 GMT",
8
+ "comments": {}
9
+ },
10
+ {
11
+ "version": "0.0.12",
12
+ "tag": "@yume-chan/adb-credential-web_v0.0.12",
13
+ "date": "Sun, 03 Apr 2022 11:18:47 GMT",
14
+ "comments": {}
15
+ },
16
+ {
17
+ "version": "0.0.11",
18
+ "tag": "@yume-chan/adb-credential-web_v0.0.11",
19
+ "date": "Sun, 03 Apr 2022 10:54:15 GMT",
20
+ "comments": {
21
+ "none": [
22
+ {
23
+ "comment": "Update to use Web Streams API"
24
+ },
25
+ {
26
+ "comment": "Improve compatibility with Node.js 12 ESM format"
27
+ }
28
+ ],
29
+ "dependency": [
30
+ {
31
+ "comment": "Updating dependency \"@yume-chan/adb\" from `^0.0.10` to `^0.0.11`"
32
+ }
33
+ ]
34
+ }
35
+ },
4
36
  {
5
37
  "version": "0.0.10",
6
38
  "tag": "@yume-chan/adb-credential-web_v0.0.10",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  # Change Log - @yume-chan/adb-credential-web
2
2
 
3
- This log was last generated on Sun, 09 Jan 2022 15:52:20 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 28 Apr 2022 01:23:53 GMT and should not be manually modified.
4
+
5
+ ## 0.0.13
6
+ Thu, 28 Apr 2022 01:23:53 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 0.0.12
11
+ Sun, 03 Apr 2022 11:18:47 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 0.0.11
16
+ Sun, 03 Apr 2022 10:54:15 GMT
17
+
18
+ ### Updates
19
+
20
+ - Update to use Web Streams API
21
+ - Improve compatibility with Node.js 12 ESM format
4
22
 
5
23
  ## 0.0.10
6
24
  Sun, 09 Jan 2022 15:52:20 GMT
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
1
  # `@yume-chan/adb-credential-web`
2
2
 
3
- Store ADB credentials in LocalStorage.
3
+ 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)).
4
+
5
+ - [`generateKey`](#generatekey)
6
+ - [`iterateKeys`](#iteratekeys)
7
+
8
+ ## `generateKey`
9
+
10
+ ```ts
11
+ async generateKey(): Promise<Uint8Array>
12
+ ```
13
+
14
+ Generate a RSA private key and store it into LocalStorage.
15
+
16
+ Calling this method multiple times will overwrite the previous key.
17
+
18
+ The returned `Uint8Array` is the private key in PKCS #8 format.
19
+
20
+ ## `iterateKeys`
21
+
22
+ ```ts
23
+ *iterateKeys(): Generator<Uint8Array, void, void>
24
+ ```
25
+
26
+ Return the stored RSA private key. (This implementation doesn't support storing multiple keys)
@@ -1,2 +1,2 @@
1
- Invoking: build-ts-package --incremental
1
+ Invoking: build-ts-package
2
2
 
package/esm/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { type AdbCredentialStore } from "@yume-chan/adb";
2
+ export default class AdbWebCredentialStore implements AdbCredentialStore {
3
+ readonly localStorageKey: string;
4
+ constructor(localStorageKey?: string);
5
+ iterateKeys(): Generator<Uint8Array, void, void>;
6
+ generateKey(): Promise<Uint8Array>;
7
+ }
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsH,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE7K,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,kBAAkB;IACpE,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAErB,eAAe,SAAgB;IAI1C,WAAW,IAAI,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC;IAO3C,WAAW,IAAI,OAAO,CAAC,UAAU,CAAC;CAgClD"}
package/esm/index.js CHANGED
@@ -1,14 +1,7 @@
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
- }
1
+ // cspell: ignore RSASSA
2
+ import { calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, decodeUtf8, encodeBase64 } from "@yume-chan/adb";
11
3
  export default class AdbWebCredentialStore {
4
+ localStorageKey;
12
5
  constructor(localStorageKey = 'private-key') {
13
6
  this.localStorageKey = localStorageKey;
14
7
  }
@@ -18,29 +11,27 @@ export default class AdbWebCredentialStore {
18
11
  yield decodeBase64(privateKey);
19
12
  }
20
13
  }
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
- });
14
+ async generateKey() {
15
+ const { privateKey: cryptoKey } = await crypto.subtle.generateKey({
16
+ name: 'RSASSA-PKCS1-v1_5',
17
+ modulusLength: 2048,
18
+ // 65537
19
+ publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
20
+ hash: 'SHA-1',
21
+ }, true, ['sign', 'verify']);
22
+ const privateKey = new Uint8Array(await crypto.subtle.exportKey('pkcs8', cryptoKey));
23
+ window.localStorage.setItem(this.localStorageKey, decodeUtf8(encodeBase64(privateKey)));
24
+ // The authentication module in core doesn't need public keys.
25
+ // It will generate the public key from private key every time.
26
+ // However, maybe there are people want to manually put this public key onto their device,
27
+ // so also save the public key for their convenience.
28
+ const publicKeyLength = calculatePublicKeyLength();
29
+ const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
30
+ const publicKeyBuffer = new Uint8Array(publicKeyBase64Length);
31
+ calculatePublicKey(privateKey, publicKeyBuffer);
32
+ encodeBase64(publicKeyBuffer.subarray(0, publicKeyLength), publicKeyBuffer);
33
+ window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
34
+ return privateKey;
44
35
  }
45
36
  }
46
37
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +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,CAAC;SAClC;IACL,CAAC;IAEY,WAAW;;YACpB,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,WAAW,CAC7D;gBACI,IAAI,EAAE,mBAAmB;gBACzB,aAAa,EAAE,IAAI;gBACnB,QAAQ;gBACR,cAAc,EAAE,IAAI,UAAU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MAAM,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;QAExF,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,38 +1,39 @@
1
- {
2
- "name": "@yume-chan/adb-credential-web",
3
- "version": "0.0.10",
4
- "description": "Credential Store for `@yume-chan/adb` using 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
- }
1
+ {
2
+ "name": "@yume-chan/adb-credential-web",
3
+ "version": "0.0.13",
4
+ "description": "Credential Store for `@yume-chan/adb` using 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
+ "main": "esm/index.js",
25
+ "types": "esm/index.d.ts",
26
+ "devDependencies": {
27
+ "typescript": "4.7.0-beta",
28
+ "@yume-chan/ts-package-builder": "^1.0.0"
29
+ },
30
+ "dependencies": {
31
+ "@yume-chan/adb": "^0.0.13",
32
+ "tslib": "^2.3.1"
33
+ },
34
+ "scripts": {
35
+ "build": "build-ts-package",
36
+ "build:watch": "build-ts-package --incremental"
37
+ },
38
+ "readme": "# `@yume-chan/adb-credential-web`\r\n\r\nGenerate 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)).\r\n\r\n- [`generateKey`](#generatekey)\r\n- [`iterateKeys`](#iteratekeys)\r\n\r\n## `generateKey`\r\n\r\n```ts\r\nasync generateKey(): Promise<Uint8Array>\r\n```\r\n\r\nGenerate a RSA private key and store it into LocalStorage.\r\n\r\nCalling this method multiple times will overwrite the previous key.\r\n\r\nThe returned `Uint8Array` is the private key in PKCS #8 format.\r\n\r\n## `iterateKeys`\r\n\r\n```ts\r\n*iterateKeys(): Generator<Uint8Array, void, void>\r\n```\r\n\r\nReturn the stored RSA private key. (This implementation doesn't support storing multiple keys)\r\n"
39
+ }
package/src/index.ts CHANGED
@@ -1,15 +1,6 @@
1
- import { AdbCredentialStore, calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64 } from "@yume-chan/adb";
1
+ // cspell: ignore RSASSA
2
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
- }
3
+ import { calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, decodeUtf8, encodeBase64, type AdbCredentialStore } from "@yume-chan/adb";
13
4
 
14
5
  export default class AdbWebCredentialStore implements AdbCredentialStore {
15
6
  public readonly localStorageKey: string;
@@ -18,14 +9,14 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
18
9
  this.localStorageKey = localStorageKey;
19
10
  }
20
11
 
21
- public *iterateKeys(): Generator<ArrayBuffer, void, void> {
12
+ public *iterateKeys(): Generator<Uint8Array, void, void> {
22
13
  const privateKey = window.localStorage.getItem(this.localStorageKey);
23
14
  if (privateKey) {
24
15
  yield decodeBase64(privateKey);
25
16
  }
26
17
  }
27
18
 
28
- public async generateKey(): Promise<ArrayBuffer> {
19
+ public async generateKey(): Promise<Uint8Array> {
29
20
  const { privateKey: cryptoKey } = await crypto.subtle.generateKey(
30
21
  {
31
22
  name: 'RSASSA-PKCS1-v1_5',
@@ -38,7 +29,7 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
38
29
  ['sign', 'verify']
39
30
  );
40
31
 
41
- const privateKey = await crypto.subtle.exportKey('pkcs8', cryptoKey!);
32
+ const privateKey = new Uint8Array(await crypto.subtle.exportKey('pkcs8', cryptoKey!));
42
33
  window.localStorage.setItem(this.localStorageKey, decodeUtf8(encodeBase64(privateKey)));
43
34
 
44
35
  // The authentication module in core doesn't need public keys.
@@ -47,9 +38,12 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
47
38
  // so also save the public key for their convenience.
48
39
  const publicKeyLength = calculatePublicKeyLength();
49
40
  const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
50
- const publicKeyBuffer = new ArrayBuffer(publicKeyBase64Length);
41
+ const publicKeyBuffer = new Uint8Array(publicKeyBase64Length);
51
42
  calculatePublicKey(privateKey, publicKeyBuffer);
52
- encodeBase64(publicKeyBuffer, 0, publicKeyLength, publicKeyBuffer);
43
+ encodeBase64(
44
+ publicKeyBuffer.subarray(0, publicKeyLength),
45
+ publicKeyBuffer
46
+ );
53
47
  window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
54
48
 
55
49
  return privateKey;
package/tsconfig.json CHANGED
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "references": [
10
10
  {
11
- "path": "../adb/tsconfig.json"
11
+ "path": "../adb/tsconfig.build.json"
12
12
  }
13
13
  ]
14
14
  }
package/dts/index.d.ts DELETED
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}