@deephaven-enterprise/auth-nodejs 1.20240723.107-alpha-auth-nodejs.23556 → 1.20240723.107-alpha-auth-nodejs.23562

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.
@@ -0,0 +1,15 @@
1
+ import type { EnterpriseDhType as DheType } from '@deephaven-enterprise/jsapi-types';
2
+ import type { UnauthenticatedClient } from './types.js';
3
+ /**
4
+ * Create a connected, unauthenticated DHE client.
5
+ * @param dhe DHE JsApi.
6
+ * @param serverUrl The DHE server URL.
7
+ * @returns A connected, unauthenticated DHE client.
8
+ */
9
+ export declare function createClient(dhe: DheType, serverUrl: URL): Promise<UnauthenticatedClient>;
10
+ /**
11
+ * Get the WebSocket URL for a DHE server URL.
12
+ * @param serverUrl The DHE server URL.
13
+ * @returns The WebSocket URL.
14
+ */
15
+ export declare function getWsUrl(serverUrl: URL): URL;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Create a connected, unauthenticated DHE client.
3
+ * @param dhe DHE JsApi.
4
+ * @param serverUrl The DHE server URL.
5
+ * @returns A connected, unauthenticated DHE client.
6
+ */
7
+ export async function createClient(dhe, serverUrl) {
8
+ const dheClient = new dhe.Client(getWsUrl(serverUrl).toString());
9
+ return new Promise(resolve => {
10
+ const unsubscribe = dheClient.addEventListener(dhe.Client.EVENT_CONNECT, () => {
11
+ unsubscribe();
12
+ resolve(dheClient);
13
+ });
14
+ });
15
+ }
16
+ /**
17
+ * Get the WebSocket URL for a DHE server URL.
18
+ * @param serverUrl The DHE server URL.
19
+ * @returns The WebSocket URL.
20
+ */
21
+ export function getWsUrl(serverUrl) {
22
+ const url = new URL('/socket', serverUrl);
23
+ if (url.protocol === 'http:') {
24
+ url.protocol = 'ws:';
25
+ }
26
+ else {
27
+ url.protocol = 'wss:';
28
+ }
29
+ return url;
30
+ }
@@ -1,18 +1,18 @@
1
- import type { Base64KeyPair, Base64Nonce, Base64PrivateKey, Base64PublicKey, Base64Signature, KeyPairType } from './types.js';
2
- import type { EnterpriseClient, LoginCredentials } from '@deephaven-enterprise/jsapi-types';
1
+ import type { EnterpriseDhType as DheType } from '@deephaven-enterprise/jsapi-types';
2
+ import type { Base64KeyPair, Base64Nonce, Base64PrivateKey, Base64PublicKey, Base64Signature, KeyPairType, PasswordCredentials } from './types.js';
3
3
  /**
4
4
  * Generate a base64 encoded asymmetric key pair using eliptic curve.
5
5
  * @returns The base64 encoded public and private keys.
6
6
  */
7
7
  export declare function generateBase64KeyPair(): Base64KeyPair;
8
8
  /**
9
- * Prepend a sentinal value to a public key based on the given type. The
9
+ * Prepend a sentinal value to a Base64 key based on the given type. The
10
10
  * sentinel is the uppercase type followed by a colon.
11
11
  * @param type Keypair type.
12
- * @param key Base64 encoded public key.
12
+ * @param key Base64 encoded key.
13
13
  * @returns The key with the sentinel prepended.
14
14
  */
15
- export declare function keyWithSentinel(type: KeyPairType, key: Base64PublicKey): string;
15
+ export declare function keyWithSentinel(type: KeyPairType, key: Base64PublicKey | Base64PrivateKey): string;
16
16
  /**
17
17
  * Sign a nonce using a private key.
18
18
  * @param nonce Base64 encoded nonce.
@@ -20,12 +20,37 @@ export declare function keyWithSentinel(type: KeyPairType, key: Base64PublicKey)
20
20
  * @returns The base64 encoded signature.
21
21
  */
22
22
  export declare function signWithPrivateKey(nonce: Base64Nonce, privateKey: Base64PrivateKey): Base64Signature;
23
+ /**
24
+ * Delete a list of public keys for a user.
25
+ * @param dhe The JsApi to use.
26
+ * @param serverUrl The DHE server URL.
27
+ * @param credentials The credentials to use for authentication.
28
+ * @param publicKeys The list of public keys to delete.
29
+ * @param type The algorithm type used to generate the key.
30
+ * @returns A promise that resolves when the keys have been deleted.
31
+ */
32
+ export declare function deletePublicKeys({ dhe, serverUrl, credentials, publicKeys, type, }: {
33
+ dhe: DheType;
34
+ serverUrl: URL;
35
+ credentials: PasswordCredentials;
36
+ publicKeys: Base64PublicKey[];
37
+ type: KeyPairType;
38
+ }): Promise<void>;
23
39
  /**
24
40
  * Upload a public key to a DHE server.
25
- * @param dheClient The DHE client to use.
26
- * @param dheCredentials The credentials to use for authentication.
41
+ * @param dhe The DHE Jsapi to use.
42
+ * @param serverUrl The DHE server URL.
43
+ * @param credentials The credentials to use for authentication.
27
44
  * @param publicKey The base64 encoded public key.
45
+ * @param comment A comment to associate with the key.
28
46
  * @param type The type of key pair.
29
47
  * @returns The response from the server.
30
48
  */
31
- export declare function uploadPublicKey(dheClient: EnterpriseClient, dheCredentials: LoginCredentials, publicKey: Base64PublicKey, type: KeyPairType): Promise<Response>;
49
+ export declare function uploadPublicKey({ dhe, serverUrl, credentials, publicKey, comment, type, }: {
50
+ dhe: DheType;
51
+ serverUrl: URL;
52
+ credentials: PasswordCredentials;
53
+ comment: string;
54
+ publicKey: Base64PublicKey;
55
+ type: KeyPairType;
56
+ }): Promise<Response>;
@@ -1,4 +1,5 @@
1
1
  import { generateKeyPairSync, sign } from 'node:crypto';
2
+ import { createClient } from './clientUtils.js';
2
3
  /*
3
4
  * Named curve to use for generating key pairs.
4
5
  * Note that 'prime256v1' is synonymous with 'secp256r1'.
@@ -20,10 +21,10 @@ export function generateBase64KeyPair() {
20
21
  return { type, publicKey, privateKey };
21
22
  }
22
23
  /**
23
- * Prepend a sentinal value to a public key based on the given type. The
24
+ * Prepend a sentinal value to a Base64 key based on the given type. The
24
25
  * sentinel is the uppercase type followed by a colon.
25
26
  * @param type Keypair type.
26
- * @param key Base64 encoded public key.
27
+ * @param key Base64 encoded key.
27
28
  * @returns The key with the sentinel prepended.
28
29
  */
29
30
  export function keyWithSentinel(type, key) {
@@ -55,30 +56,62 @@ export function signWithPrivateKey(nonce, privateKey) {
55
56
  type: 'pkcs8',
56
57
  }).toString('base64');
57
58
  }
59
+ /**
60
+ * Delete a list of public keys for a user.
61
+ * @param dhe The JsApi to use.
62
+ * @param serverUrl The DHE server URL.
63
+ * @param credentials The credentials to use for authentication.
64
+ * @param publicKeys The list of public keys to delete.
65
+ * @param type The algorithm type used to generate the key.
66
+ * @returns A promise that resolves when the keys have been deleted.
67
+ */
68
+ export async function deletePublicKeys({ dhe, serverUrl, credentials, publicKeys, type, }) {
69
+ const dheClient = await createClient(dhe, serverUrl);
70
+ await dheClient.login(credentials);
71
+ const { dbAclWriterHost, dbAclWriterPort } = await dheClient.getServerConfigValues();
72
+ const encodedAlgorithm = encodeURIComponent(type.toUpperCase());
73
+ const encodedUserName = encodeURIComponent(credentials.username);
74
+ const authToken = await dheClient.createAuthToken('DbAclWriteServer');
75
+ const apiUrl = `https://${dbAclWriterHost}:${dbAclWriterPort}/acl/publickey/${encodedUserName}`;
76
+ const deletePromises = publicKeys.map(publicKey => {
77
+ const encodedPublicKey = encodeURIComponent(publicKey);
78
+ const query = new URLSearchParams();
79
+ query.set('algorithm', encodedAlgorithm);
80
+ query.set('encodedStr', encodedPublicKey);
81
+ return fetch(`${apiUrl}?${query.toString()}`, {
82
+ method: 'DELETE',
83
+ headers: {
84
+ Authorization: authToken,
85
+ },
86
+ });
87
+ });
88
+ await Promise.all(deletePromises);
89
+ }
58
90
  /**
59
91
  * Upload a public key to a DHE server.
60
- * @param dheClient The DHE client to use.
61
- * @param dheCredentials The credentials to use for authentication.
92
+ * @param dhe The DHE Jsapi to use.
93
+ * @param serverUrl The DHE server URL.
94
+ * @param credentials The credentials to use for authentication.
62
95
  * @param publicKey The base64 encoded public key.
96
+ * @param comment A comment to associate with the key.
63
97
  * @param type The type of key pair.
64
98
  * @returns The response from the server.
65
99
  */
66
- export async function uploadPublicKey(dheClient, dheCredentials, publicKey, type) {
67
- await dheClient.login(dheCredentials);
100
+ export async function uploadPublicKey({ dhe, serverUrl, credentials, publicKey, comment, type, }) {
101
+ const dheClient = await createClient(dhe, serverUrl);
102
+ await dheClient.login(credentials);
68
103
  const { dbAclWriterHost, dbAclWriterPort } = await dheClient.getServerConfigValues();
69
104
  const body = {
70
- user: dheCredentials.username,
105
+ user: credentials.username,
71
106
  encodedStr: keyWithSentinel(type, publicKey),
72
107
  algorithm: type.toUpperCase(),
73
- comment: `Generated by vscode extension ${new Date().toISOString()}`,
108
+ comment,
74
109
  };
75
110
  return fetch(`https://${dbAclWriterHost}:${dbAclWriterPort}/acl/publickey`, {
76
111
  method: 'POST',
77
112
  headers: {
78
- /* eslint-disable @typescript-eslint/naming-convention */
79
113
  Authorization: await dheClient.createAuthToken('DbAclWriteServer'),
80
114
  'Content-Type': 'application/json',
81
- /* eslint-enable @typescript-eslint/naming-convention */
82
115
  },
83
116
  body: JSON.stringify(body),
84
117
  });
@@ -1,18 +1,4 @@
1
- import type { EnterpriseDhType as DheType } from '@deephaven-enterprise/jsapi-types';
2
1
  import type { AuthenticatedClient, PasswordCredentials, KeyPairCredentials, UnauthenticatedClient } from './types.js';
3
- /**
4
- * Create a connected, unauthenticated DHE client.
5
- * @param dhe DHE JsApi.
6
- * @param serverUrl The DHE server URL.
7
- * @returns A connected, unauthenticated DHE client.
8
- */
9
- export declare function createClient(dhe: DheType, serverUrl: URL): Promise<UnauthenticatedClient>;
10
- /**
11
- * Get the WebSocket URL for a DHE server URL.
12
- * @param serverUrl The DHE server URL.
13
- * @returns The WebSocket URL.
14
- */
15
- export declare function getWsUrl(serverUrl: URL): URL;
16
2
  /**
17
3
  * Authenticate a given client with username and password. Return the
18
4
  * authenticated client.
@@ -3,36 +3,6 @@
3
3
  import Log from '@deephaven/log/dist/Log.js';
4
4
  import { keyWithSentinel, signWithPrivateKey } from './keyPairUtils.js';
5
5
  const logger = Log.module('@deephaven-enterprise/auth-nodejs:loginUtils');
6
- /**
7
- * Create a connected, unauthenticated DHE client.
8
- * @param dhe DHE JsApi.
9
- * @param serverUrl The DHE server URL.
10
- * @returns A connected, unauthenticated DHE client.
11
- */
12
- export async function createClient(dhe, serverUrl) {
13
- const dheClient = new dhe.Client(getWsUrl(serverUrl).toString());
14
- return new Promise(resolve => {
15
- const unsubscribe = dheClient.addEventListener(dhe.Client.EVENT_CONNECT, () => {
16
- unsubscribe();
17
- resolve(dheClient);
18
- });
19
- });
20
- }
21
- /**
22
- * Get the WebSocket URL for a DHE server URL.
23
- * @param serverUrl The DHE server URL.
24
- * @returns The WebSocket URL.
25
- */
26
- export function getWsUrl(serverUrl) {
27
- const url = new URL('/socket', serverUrl);
28
- if (url.protocol === 'http:') {
29
- url.protocol = 'ws:';
30
- }
31
- else {
32
- url.protocol = 'wss:';
33
- }
34
- return url;
35
- }
36
6
  /**
37
7
  * Authenticate a given client with username and password. Return the
38
8
  * authenticated client.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven-enterprise/auth-nodejs",
3
- "version": "1.20240723.107-alpha-auth-nodejs.23556+266602a43e",
3
+ "version": "1.20240723.107-alpha-auth-nodejs.23562+acecb48948",
4
4
  "description": "Deephaven Enterprise Auth Utils for NodeJS",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -17,12 +17,12 @@
17
17
  "build": "tsc --build"
18
18
  },
19
19
  "dependencies": {
20
- "@deephaven-enterprise/jsapi-types": "^1.20240723.107-alpha-auth-nodejs.23556+266602a43e",
20
+ "@deephaven-enterprise/jsapi-types": "^1.20240723.107-alpha-auth-nodejs.23562+acecb48948",
21
21
  "@deephaven/log": "^0.97.0",
22
22
  "@deephaven/utils": "^0.97.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"
26
26
  },
27
- "gitHead": "266602a43e7485bf3ef6a1664ceef589e9d5c215"
27
+ "gitHead": "acecb48948bd4556e8eeda5d6bc1f8f4fd978f5a"
28
28
  }