@yume-chan/adb-credential-web 0.0.10 → 0.0.11

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": "c2eea9e95f7a91089a0529b750286ccd75726818",
4
+ "libraries/adb-credential-web/CHANGELOG.json": "bdb99f8ca3eff53b8b260fae2e230e34d55a6902",
5
+ "libraries/adb-credential-web/CHANGELOG.md": "89f2ed92996da15a9f5ac27a7ff3d64b58b72f35",
6
+ "libraries/adb-credential-web/README.md": "35dc273a753ae6f722bad96ae6e52efe9b2d6840",
7
+ "libraries/adb-credential-web/package.json": "f684dc163578c7b5a2245b5f552fa0482e301d55",
8
+ "libraries/adb-credential-web/src/index.ts": "88b871f305e19ca09bd26b8fdc868284790379af",
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": "c2eea9e95f7a91089a0529b750286ccd75726818",
4
+ "libraries/adb-credential-web/CHANGELOG.json": "bdb99f8ca3eff53b8b260fae2e230e34d55a6902",
5
+ "libraries/adb-credential-web/CHANGELOG.md": "89f2ed92996da15a9f5ac27a7ff3d64b58b72f35",
6
+ "libraries/adb-credential-web/README.md": "35dc273a753ae6f722bad96ae6e52efe9b2d6840",
7
+ "libraries/adb-credential-web/package.json": "f684dc163578c7b5a2245b5f552fa0482e301d55",
8
+ "libraries/adb-credential-web/src/index.ts": "88b871f305e19ca09bd26b8fdc868284790379af",
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-dev.20220403": "sha512-1kTFg2+08XMrBmgDDQVNxSmDWcVstTcNT+rt9JC9Z511ewqUYe45IpWSVdS/xSSTei3N5grakAVbSAhZO0HloA=="
6
4
  }
package/CHANGELOG.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@yume-chan/adb-credential-web",
3
3
  "entries": [
4
+ {
5
+ "version": "0.0.11",
6
+ "tag": "@yume-chan/adb-credential-web_v0.0.11",
7
+ "date": "Sun, 03 Apr 2022 10:54:15 GMT",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "comment": "Update to use Web Streams API"
12
+ },
13
+ {
14
+ "comment": "Improve compatibility with Node.js 12 ESM format"
15
+ }
16
+ ],
17
+ "dependency": [
18
+ {
19
+ "comment": "Updating dependency \"@yume-chan/adb\" from `^0.0.10` to `^0.0.11`"
20
+ }
21
+ ]
22
+ }
23
+ },
4
24
  {
5
25
  "version": "0.0.10",
6
26
  "tag": "@yume-chan/adb-credential-web_v0.0.10",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
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 Sun, 03 Apr 2022 10:54:15 GMT and should not be manually modified.
4
+
5
+ ## 0.0.11
6
+ Sun, 03 Apr 2022 10:54:15 GMT
7
+
8
+ ### Updates
9
+
10
+ - Update to use Web Streams API
11
+ - Improve compatibility with Node.js 12 ESM format
4
12
 
5
13
  ## 0.0.10
6
14
  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,10 @@
1
+ import { type AdbCredentialStore } from "@yume-chan/adb";
2
+ export declare function encodeUtf8(input: string): Uint8Array;
3
+ export declare function decodeUtf8(array: Uint8Array): string;
4
+ export default class AdbWebCredentialStore implements AdbCredentialStore {
5
+ readonly localStorageKey: string;
6
+ constructor(localStorageKey?: string);
7
+ iterateKeys(): Generator<Uint8Array, void, void>;
8
+ generateKey(): Promise<Uint8Array>;
9
+ }
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0G,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKjK,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAEpD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED,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,15 @@
1
- import { __awaiter } from "tslib";
1
+ // cspell: ignore RSASSA
2
2
  import { calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64 } from "@yume-chan/adb";
3
3
  const Utf8Encoder = new TextEncoder();
4
4
  const Utf8Decoder = new TextDecoder();
5
5
  export function encodeUtf8(input) {
6
- return Utf8Encoder.encode(input).buffer;
6
+ return Utf8Encoder.encode(input);
7
7
  }
8
- export function decodeUtf8(buffer) {
9
- return Utf8Decoder.decode(buffer);
8
+ export function decodeUtf8(array) {
9
+ return Utf8Decoder.decode(array);
10
10
  }
11
11
  export default class AdbWebCredentialStore {
12
+ localStorageKey;
12
13
  constructor(localStorageKey = 'private-key') {
13
14
  this.localStorageKey = localStorageKey;
14
15
  }
@@ -18,29 +19,27 @@ export default class AdbWebCredentialStore {
18
19
  yield decodeBase64(privateKey);
19
20
  }
20
21
  }
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
- });
22
+ async generateKey() {
23
+ const { privateKey: cryptoKey } = await 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 = new Uint8Array(await 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 Uint8Array(publicKeyBase64Length);
39
+ calculatePublicKey(privateKey, publicKeyBuffer);
40
+ encodeBase64(publicKeyBuffer.subarray(0, publicKeyLength), publicKeyBuffer);
41
+ window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
42
+ return privateKey;
44
43
  }
45
44
  }
46
45
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@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AC;QACF,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,GAAG,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.11",
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": "next",
28
+ "@yume-chan/ts-package-builder": "^1.0.0"
29
+ },
30
+ "dependencies": {
31
+ "@yume-chan/adb": "^0.0.11",
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,14 +1,16 @@
1
- import { AdbCredentialStore, calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64 } from "@yume-chan/adb";
1
+ // cspell: ignore RSASSA
2
+
3
+ import { calculateBase64EncodedLength, calculatePublicKey, calculatePublicKeyLength, decodeBase64, encodeBase64, type AdbCredentialStore } from "@yume-chan/adb";
2
4
 
3
5
  const Utf8Encoder = new TextEncoder();
4
6
  const Utf8Decoder = new TextDecoder();
5
7
 
6
- export function encodeUtf8(input: string): ArrayBuffer {
7
- return Utf8Encoder.encode(input).buffer;
8
+ export function encodeUtf8(input: string): Uint8Array {
9
+ return Utf8Encoder.encode(input);
8
10
  }
9
11
 
10
- export function decodeUtf8(buffer: ArrayBuffer): string {
11
- return Utf8Decoder.decode(buffer);
12
+ export function decodeUtf8(array: Uint8Array): string {
13
+ return Utf8Decoder.decode(array);
12
14
  }
13
15
 
14
16
  export default class AdbWebCredentialStore implements AdbCredentialStore {
@@ -18,14 +20,14 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
18
20
  this.localStorageKey = localStorageKey;
19
21
  }
20
22
 
21
- public *iterateKeys(): Generator<ArrayBuffer, void, void> {
23
+ public *iterateKeys(): Generator<Uint8Array, void, void> {
22
24
  const privateKey = window.localStorage.getItem(this.localStorageKey);
23
25
  if (privateKey) {
24
26
  yield decodeBase64(privateKey);
25
27
  }
26
28
  }
27
29
 
28
- public async generateKey(): Promise<ArrayBuffer> {
30
+ public async generateKey(): Promise<Uint8Array> {
29
31
  const { privateKey: cryptoKey } = await crypto.subtle.generateKey(
30
32
  {
31
33
  name: 'RSASSA-PKCS1-v1_5',
@@ -38,7 +40,7 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
38
40
  ['sign', 'verify']
39
41
  );
40
42
 
41
- const privateKey = await crypto.subtle.exportKey('pkcs8', cryptoKey!);
43
+ const privateKey = new Uint8Array(await crypto.subtle.exportKey('pkcs8', cryptoKey!));
42
44
  window.localStorage.setItem(this.localStorageKey, decodeUtf8(encodeBase64(privateKey)));
43
45
 
44
46
  // The authentication module in core doesn't need public keys.
@@ -47,9 +49,12 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
47
49
  // so also save the public key for their convenience.
48
50
  const publicKeyLength = calculatePublicKeyLength();
49
51
  const [publicKeyBase64Length] = calculateBase64EncodedLength(publicKeyLength);
50
- const publicKeyBuffer = new ArrayBuffer(publicKeyBase64Length);
52
+ const publicKeyBuffer = new Uint8Array(publicKeyBase64Length);
51
53
  calculatePublicKey(privateKey, publicKeyBuffer);
52
- encodeBase64(publicKeyBuffer, 0, publicKeyLength, publicKeyBuffer);
54
+ encodeBase64(
55
+ publicKeyBuffer.subarray(0, publicKeyLength),
56
+ publicKeyBuffer
57
+ );
53
58
  window.localStorage.setItem(this.localStorageKey + '.pub', decodeUtf8(publicKeyBuffer));
54
59
 
55
60
  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"}