diff --git a/package-lock.json b/package-lock.json index 142953f5..5d8d25ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "devDependencies": { "@matrixai/errors": "^1.2.0", "@matrixai/logger": "^3.1.0", - "@matrixai/ws": "1.1.7", "@swc/core": "1.3.82", "@swc/jest": "^0.2.29", "@types/jest": "^29.5.2", @@ -40,7 +39,7 @@ "nexpect": "^0.6.0", "node-gyp-build": "^4.4.0", "nodemon": "^3.0.1", - "polykey": "^1.2.1-alpha.14", + "polykey": "^1.2.1-alpha.17", "prettier": "^3.0.0", "shelljs": "^0.8.5", "shx": "^0.3.4", @@ -7430,9 +7429,9 @@ } }, "node_modules/polykey": { - "version": "1.2.1-alpha.14", - "resolved": "https://registry.npmjs.org/polykey/-/polykey-1.2.1-alpha.14.tgz", - "integrity": "sha512-5Dx0EMdk6rE8p7GL/hy/73XygV+uUip7hZnFLu8W/OJW1vOjR3dXA4dKDKuIhLmRE4BZGDsUAOqN1C3lT+1mTQ==", + "version": "1.2.1-alpha.17", + "resolved": "https://registry.npmjs.org/polykey/-/polykey-1.2.1-alpha.17.tgz", + "integrity": "sha512-oj9+ZPKeq//nRg4FZGY0yBIBfliGycJqV66gneFqk6fYOpD4hp/ltlvpgR73CHzHrvARbEQFDU7rHnw5HUY/fQ==", "dev": true, "dependencies": { "@matrixai/async-cancellable": "^1.1.1", diff --git a/package.json b/package.json index 57bde0d2..b6c30767 100644 --- a/package.json +++ b/package.json @@ -108,9 +108,8 @@ "devDependencies": { "@matrixai/errors": "^1.2.0", "@matrixai/logger": "^3.1.0", - "@matrixai/ws": "1.1.7", "commander": "^8.3.0", - "polykey": "^1.2.1-alpha.14", + "polykey": "^1.2.1-alpha.17", "threads": "^1.6.5", "@swc/core": "1.3.82", "@swc/jest": "^0.2.29", diff --git a/src/agent/CommandLockAll.ts b/src/agent/CommandLockAll.ts index 17227fb8..18b7cf52 100644 --- a/src/agent/CommandLockAll.ts +++ b/src/agent/CommandLockAll.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import path from 'path'; import config from 'polykey/dist/config'; import CommandPolykey from '../CommandPolykey'; @@ -19,8 +18,6 @@ class CommandLockAll extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const { default: Session } = await import( 'polykey/dist/sessions/Session' ); @@ -41,37 +38,23 @@ class CommandLockAll extends CommandPolykey { fs: this.fs, logger: this.logger.getChild(Session.name), }); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.agentLockAll({ + pkClient.rpcClient.methods.agentLockAll({ metadata: auth, }), auth, @@ -80,7 +63,6 @@ class CommandLockAll extends CommandPolykey { await session.destroy(); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/agent/CommandStatus.ts b/src/agent/CommandStatus.ts index 5db17011..c661da99 100644 --- a/src/agent/CommandStatus.ts +++ b/src/agent/CommandStatus.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { StatusResultMessage } from 'polykey/dist/client/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -18,8 +17,6 @@ class CommandStatus extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientStatus = await binProcessors.processClientStatus( options.nodePath, options.nodeId, @@ -46,45 +43,30 @@ class CommandStatus extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); let response: StatusResultMessage; try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientStatus.nodeId!], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientStatus.nodeId!, host: clientStatus.clientHost!, port: clientStatus.clientPort!, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.agentStatus({ + pkClient.rpcClient.methods.agentStatus({ metadata: auth, }), auth, ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } process.stdout.write( binUtils.outputFormatter({ diff --git a/src/agent/CommandStop.ts b/src/agent/CommandStop.ts index e1c2c55b..217ae237 100644 --- a/src/agent/CommandStop.ts +++ b/src/agent/CommandStop.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandStop extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientStatus = await binProcessors.processClientStatus( options.nodePath, options.nodeId, @@ -44,37 +41,23 @@ class CommandStop extends CommandPolykey { ); // Either the statusInfo is undefined or LIVE // Either way, the connection parameters now exist - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientStatus.nodeId!], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientStatus.nodeId!, host: clientStatus.clientHost!, port: clientStatus.clientPort!, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.agentStop({ + pkClient.rpcClient.methods.agentStop({ metadata: auth, }), auth, @@ -82,7 +65,6 @@ class CommandStop extends CommandPolykey { this.logger.info('Stopping Agent'); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/agent/CommandUnlock.ts b/src/agent/CommandUnlock.ts index bed56e6c..c9ca19a8 100644 --- a/src/agent/CommandUnlock.ts +++ b/src/agent/CommandUnlock.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandUnlock extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,44 +28,29 @@ class CommandUnlock extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.agentUnlock({ + pkClient.rpcClient.methods.agentUnlock({ metadata: auth, }), auth, ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/bootstrap/CommandBootstrap.ts b/src/bootstrap/CommandBootstrap.ts index f20a7cdc..18dbd714 100644 --- a/src/bootstrap/CommandBootstrap.ts +++ b/src/bootstrap/CommandBootstrap.ts @@ -26,17 +26,11 @@ class CommandBootstrap extends CommandPolykey { ); const recoveryCodeOut = await bootstrapUtils.bootstrapState({ password, - options: { - nodePath: options.nodePath, - keys: { - recoveryCode: recoveryCodeIn, - privateKeyPath: options.privateKeyFile, - passwordOpsLimit: - keysUtils.passwordOpsLimits[options.passwordOpsLimit], - passwordMemLimit: - keysUtils.passwordMemLimits[options.passwordMemLimit], - }, - }, + nodePath: options.nodePath, + recoveryCode: recoveryCodeIn, + privateKeyPath: options.privateKeyFile, + passwordOpsLimit: keysUtils.passwordOpsLimits[options.passwordOpsLimit], + passwordMemLimit: keysUtils.passwordMemLimits[options.passwordMemLimit], fresh: options.fresh, fs: this.fs, logger: this.logger, diff --git a/src/identities/CommandAllow.ts b/src/identities/CommandAllow.ts index d22e9980..8aadf2c4 100644 --- a/src/identities/CommandAllow.ts +++ b/src/identities/CommandAllow.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -29,8 +28,6 @@ class CommandAllow extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -45,32 +42,18 @@ class CommandAllow extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const [type, id] = gestaltId; @@ -80,7 +63,7 @@ class CommandAllow extends CommandPolykey { // Trusting await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsSetByNode({ + pkClient.rpcClient.methods.gestaltsActionsSetByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), action: permission, @@ -94,14 +77,12 @@ class CommandAllow extends CommandPolykey { // Setting By Identity await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsSetByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - action: permission, - }, - ), + pkClient.rpcClient.methods.gestaltsActionsSetByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + action: permission, + }), auth, ); } @@ -111,7 +92,6 @@ class CommandAllow extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandAuthenticate.ts b/src/identities/CommandAuthenticate.ts index 08943368..83a5d4c8 100644 --- a/src/identities/CommandAuthenticate.ts +++ b/src/identities/CommandAuthenticate.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { ClientRPCResponseResult } from 'polykey/dist/client/types'; import type { AuthProcessMessage } from 'polykey/dist/client/types'; import type { ReadableStream } from 'stream/web'; @@ -27,8 +26,6 @@ class CommandAuthenticate extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const { never } = await import('polykey/dist/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -42,43 +39,30 @@ class CommandAuthenticate extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let genReadable: ReadableStream< ClientRPCResponseResult >; await binUtils.retryAuthentication(async (auth) => { - genReadable = - await pkClient.rpcClientClient.methods.identitiesAuthenticate({ + genReadable = await pkClient.rpcClient.methods.identitiesAuthenticate( + { metadata: auth, providerId: providerId, - }); + }, + ); for await (const message of genReadable) { if (message.request != null) { this.logger.info(`Navigate to the URL in order to authenticate`); @@ -112,7 +96,6 @@ class CommandAuthenticate extends CommandPolykey { }, auth); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandAuthenticated.ts b/src/identities/CommandAuthenticated.ts index 37f74a98..01e9181c 100644 --- a/src/identities/CommandAuthenticated.ts +++ b/src/identities/CommandAuthenticated.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; import * as binUtils from '../utils'; @@ -23,8 +22,6 @@ class CommandAuthenticated extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,23 @@ class CommandAuthenticated extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication(async (auth) => { const readableStream = - await pkClient.rpcClientClient.methods.identitiesAuthenticatedGet({ + await pkClient.rpcClient.methods.identitiesAuthenticatedGet({ metadata: auth, providerId: options.providerId, }); @@ -86,7 +69,6 @@ class CommandAuthenticated extends CommandPolykey { }, auth); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandClaim.ts b/src/identities/CommandClaim.ts index de7ca070..4bfb81a3 100644 --- a/src/identities/CommandClaim.ts +++ b/src/identities/CommandClaim.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -28,8 +27,6 @@ class CommandClaim extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -42,37 +39,23 @@ class CommandClaim extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const claimMessage = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.identitiesClaim({ + pkClient.rpcClient.methods.identitiesClaim({ metadata: auth, providerId: providerId, identityId: identityId, @@ -91,7 +74,6 @@ class CommandClaim extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandDisallow.ts b/src/identities/CommandDisallow.ts index 7888d3ea..f56fb580 100644 --- a/src/identities/CommandDisallow.ts +++ b/src/identities/CommandDisallow.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; @@ -29,8 +28,6 @@ class CommandDisallow extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -45,32 +42,18 @@ class CommandDisallow extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const [type, id] = gestaltId; @@ -80,7 +63,7 @@ class CommandDisallow extends CommandPolykey { // Trusting await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsUnsetByNode({ + pkClient.rpcClient.methods.gestaltsActionsUnsetByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), action: permission, @@ -94,14 +77,12 @@ class CommandDisallow extends CommandPolykey { // Trusting. await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsUnsetByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - action: permission, - }, - ), + pkClient.rpcClient.methods.gestaltsActionsUnsetByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + action: permission, + }), auth, ); } @@ -111,7 +92,6 @@ class CommandDisallow extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandDiscover.ts b/src/identities/CommandDiscover.ts index 67c619fc..a376dc11 100644 --- a/src/identities/CommandDiscover.ts +++ b/src/identities/CommandDiscover.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandDiscover extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -40,32 +37,18 @@ class CommandDiscover extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const [type, id] = gestaltId; @@ -75,7 +58,7 @@ class CommandDiscover extends CommandPolykey { // Discovery by Node await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsDiscoveryByNode({ + pkClient.rpcClient.methods.gestaltsDiscoveryByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), }), @@ -88,7 +71,7 @@ class CommandDiscover extends CommandPolykey { // Discovery by Identity await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsDiscoveryByIdentity({ + pkClient.rpcClient.methods.gestaltsDiscoveryByIdentity({ metadata: auth, providerId: id[0], identityId: id[1], @@ -102,7 +85,6 @@ class CommandDiscover extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandGet.ts b/src/identities/CommandGet.ts index 61885c8f..e8b1e267 100644 --- a/src/identities/CommandGet.ts +++ b/src/identities/CommandGet.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import type { GestaltMessage } from 'polykey/dist/client/types'; import CommandPolykey from '../CommandPolykey'; @@ -27,8 +26,6 @@ class CommandGet extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -43,32 +40,18 @@ class CommandGet extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let res: GestaltMessage | null = null; @@ -79,7 +62,7 @@ class CommandGet extends CommandPolykey { // Getting from node res = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsGestaltGetByNode({ + pkClient.rpcClient.methods.gestaltsGestaltGetByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), }), @@ -92,13 +75,11 @@ class CommandGet extends CommandPolykey { // Getting from identity. res = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsGestaltGetByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - }, - ), + pkClient.rpcClient.methods.gestaltsGestaltGetByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + }), auth, ); } @@ -130,7 +111,6 @@ class CommandGet extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandInvite.ts b/src/identities/CommandInvite.ts index 3d8c6527..0f1d9272 100644 --- a/src/identities/CommandInvite.ts +++ b/src/identities/CommandInvite.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -24,8 +23,6 @@ class CommandClaim extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -39,37 +36,24 @@ class CommandClaim extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, + logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.identitiesInvite({ + pkClient.rpcClient.methods.identitiesInvite({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), }), @@ -87,7 +71,6 @@ class CommandClaim extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandList.ts b/src/identities/CommandList.ts index de0f7aca..7d7c7e43 100644 --- a/src/identities/CommandList.ts +++ b/src/identities/CommandList.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; import * as binUtils from '../utils'; @@ -17,8 +16,6 @@ class CommandList extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,41 +28,26 @@ class CommandList extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let output: any; const gestalts = await binUtils.retryAuthentication(async (auth) => { const gestalts: Array = []; - const stream = - await pkClient.rpcClientClient.methods.gestaltsGestaltList({ - metadata: auth, - }); + const stream = await pkClient.rpcClient.methods.gestaltsGestaltList({ + metadata: auth, + }); for await (const gestaltMessage of stream) { const gestalt = gestaltMessage.gestalt; const newGestalt: any = { @@ -87,7 +69,7 @@ class CommandList extends CommandPolykey { // Getting the permissions for the gestalt. const actionsMessage = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsGetByNode({ + pkClient.rpcClient.methods.gestaltsActionsGetByNode({ metadata: auth, nodeIdEncoded: newGestalt.nodes[0].nodeId, }), @@ -128,7 +110,6 @@ class CommandList extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandPermissions.ts b/src/identities/CommandPermissions.ts index 9806c895..813afe7b 100644 --- a/src/identities/CommandPermissions.ts +++ b/src/identities/CommandPermissions.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandPermissions extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -40,32 +37,18 @@ class CommandPermissions extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const [type, id] = gestaltId; @@ -76,7 +59,7 @@ class CommandPermissions extends CommandPolykey { // Getting by Node const res = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsGetByNode({ + pkClient.rpcClient.methods.gestaltsActionsGetByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), }), @@ -90,13 +73,11 @@ class CommandPermissions extends CommandPolykey { // Getting by Identity const res = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsGetByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - }, - ), + pkClient.rpcClient.methods.gestaltsActionsGetByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + }), auth, ); actions = res.actionsList; @@ -115,7 +96,6 @@ class CommandPermissions extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandSearch.ts b/src/identities/CommandSearch.ts index 2f900d23..56400305 100644 --- a/src/identities/CommandSearch.ts +++ b/src/identities/CommandSearch.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { IdentityInfoMessage } from 'polykey/dist/client/types'; import type { ReadableStream } from 'stream/web'; import type { ClientRPCResponseResult } from 'polykey/dist/client/types'; @@ -48,8 +47,6 @@ class CommandSearch extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -62,32 +59,18 @@ class CommandSearch extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication(async (auth) => { @@ -95,8 +78,8 @@ class CommandSearch extends CommandPolykey { ClientRPCResponseResult >; if (options.identityId) { - readableStream = - await pkClient.rpcClientClient.methods.identitiesInfoGet({ + readableStream = await pkClient.rpcClient.methods.identitiesInfoGet( + { metadata: auth, identityId: options.identityId, authIdentityId: options.authIdentityId, @@ -104,20 +87,19 @@ class CommandSearch extends CommandPolykey { providerIdList: options.providerId ?? [], searchTermList: searchTerms, limit: options.limit, - }); + }, + ); } else { readableStream = - await pkClient.rpcClientClient.methods.identitiesInfoConnectedGet( - { - metadata: auth, - identityId: options.identityId, - authIdentityId: options.authIdentityId, - disconnected: options.disconnected, - providerIdList: options.providerId ?? [], - searchTermList: searchTerms, - limit: options.limit, - }, - ); + await pkClient.rpcClient.methods.identitiesInfoConnectedGet({ + metadata: auth, + identityId: options.identityId, + authIdentityId: options.authIdentityId, + disconnected: options.disconnected, + providerIdList: options.providerId ?? [], + searchTermList: searchTerms, + limit: options.limit, + }); } for await (const identityInfoMessage of readableStream) { const output = { @@ -137,7 +119,6 @@ class CommandSearch extends CommandPolykey { }, auth); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandTrust.ts b/src/identities/CommandTrust.ts index dabc36a2..bb42a62a 100644 --- a/src/identities/CommandTrust.ts +++ b/src/identities/CommandTrust.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandTrust extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -40,32 +37,18 @@ class CommandTrust extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const [type, id] = gestaltId; @@ -75,7 +58,7 @@ class CommandTrust extends CommandPolykey { // Setting by Node. await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsGestaltTrustByNode({ + pkClient.rpcClient.methods.gestaltsGestaltTrustByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), }), @@ -88,13 +71,11 @@ class CommandTrust extends CommandPolykey { // Setting by Identity await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsGestaltTrustByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - }, - ), + pkClient.rpcClient.methods.gestaltsGestaltTrustByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + }), auth, ); } @@ -104,7 +85,6 @@ class CommandTrust extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/identities/CommandUntrust.ts b/src/identities/CommandUntrust.ts index 5c4b584c..722d9bd9 100644 --- a/src/identities/CommandUntrust.ts +++ b/src/identities/CommandUntrust.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { GestaltId } from 'polykey/dist/gestalts/types'; import CommandPolykey from '../CommandPolykey'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandUntrust extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const utils = await import('polykey/dist/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -40,32 +37,18 @@ class CommandUntrust extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const action = 'notify'; @@ -76,7 +59,7 @@ class CommandUntrust extends CommandPolykey { // Setting by Node. await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsUnsetByNode({ + pkClient.rpcClient.methods.gestaltsActionsUnsetByNode({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(id), action, @@ -90,14 +73,12 @@ class CommandUntrust extends CommandPolykey { // Setting by Identity await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.gestaltsActionsUnsetByIdentity( - { - metadata: auth, - providerId: id[0], - identityId: id[1], - action, - }, - ), + pkClient.rpcClient.methods.gestaltsActionsUnsetByIdentity({ + metadata: auth, + providerId: id[0], + identityId: id[1], + action, + }), auth, ); } @@ -107,7 +88,6 @@ class CommandUntrust extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandCert.ts b/src/keys/CommandCert.ts index 97a6a201..68c39dfa 100644 --- a/src/keys/CommandCert.ts +++ b/src/keys/CommandCert.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandCert extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,37 +28,23 @@ class CommandCert extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysCertsGet({ + pkClient.rpcClient.methods.keysCertsGet({ metadata: auth, }), auth, @@ -81,7 +64,6 @@ class CommandCert extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandCertchain.ts b/src/keys/CommandCertchain.ts index 2b6366d0..046e47e1 100644 --- a/src/keys/CommandCertchain.ts +++ b/src/keys/CommandCertchain.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandsCertchain extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,40 +28,25 @@ class CommandsCertchain extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { const data: Array = []; - const stream = - await pkClient.rpcClientClient.methods.keysCertsChainGet({ - metadata: auth, - }); + const stream = await pkClient.rpcClient.methods.keysCertsChainGet({ + metadata: auth, + }); for await (const cert of stream) { data.push(cert.cert); } @@ -85,7 +67,6 @@ class CommandsCertchain extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandDecrypt.ts b/src/keys/CommandDecrypt.ts index a8e86598..d6760ea2 100644 --- a/src/keys/CommandDecrypt.ts +++ b/src/keys/CommandDecrypt.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -22,8 +21,6 @@ class CommandDecrypt extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -36,32 +33,18 @@ class CommandDecrypt extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let cipherText: string; @@ -82,7 +65,7 @@ class CommandDecrypt extends CommandPolykey { } const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysDecrypt({ + pkClient.rpcClient.methods.keysDecrypt({ metadata: auth, data: cipherText, }), @@ -103,7 +86,6 @@ class CommandDecrypt extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandEncrypt.ts b/src/keys/CommandEncrypt.ts index 5074731d..c8e1ca8a 100644 --- a/src/keys/CommandEncrypt.ts +++ b/src/keys/CommandEncrypt.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { PublicKeyJWK } from 'polykey/dist/keys/types'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; @@ -24,8 +23,6 @@ class CommandEncypt extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const keysUtils = await import('polykey/dist/keys/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -40,32 +37,18 @@ class CommandEncypt extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let plainText: string; @@ -108,7 +91,7 @@ class CommandEncypt extends CommandPolykey { } const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysEncrypt({ + pkClient.rpcClient.methods.keysEncrypt({ metadata: auth, publicKeyJwk: publicJWK, data: plainText, @@ -130,7 +113,6 @@ class CommandEncypt extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandPair.ts b/src/keys/CommandPair.ts index 64d7feec..a9cd9218 100644 --- a/src/keys/CommandPair.ts +++ b/src/keys/CommandPair.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -20,8 +19,6 @@ class CommandKeypair extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -39,37 +36,23 @@ class CommandKeypair extends CommandPolykey { this.fs, true, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const keyPairJWK = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysKeyPair({ + pkClient.rpcClient.methods.keysKeyPair({ metadata: auth, password: passwordNew, }), @@ -87,7 +70,6 @@ class CommandKeypair extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandPassword.ts b/src/keys/CommandPassword.ts index d5762f24..70d035b1 100644 --- a/src/keys/CommandPassword.ts +++ b/src/keys/CommandPassword.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandPassword extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,23 @@ class CommandPassword extends CommandPolykey { this.fs, true, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysPasswordChange({ + pkClient.rpcClient.methods.keysPasswordChange({ metadata: auth, password: passwordNew, }), @@ -75,7 +58,6 @@ class CommandPassword extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandPrivate.ts b/src/keys/CommandPrivate.ts index 03883038..e873bb51 100644 --- a/src/keys/CommandPrivate.ts +++ b/src/keys/CommandPrivate.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandPrivate extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,23 @@ class CommandPrivate extends CommandPolykey { this.fs, true, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const keyPairJWK = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysKeyPair({ + pkClient.rpcClient.methods.keysKeyPair({ metadata: auth, password: passwordNew, }), @@ -82,7 +65,6 @@ class CommandPrivate extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandPublic.ts b/src/keys/CommandPublic.ts index 1a09bc7e..ae6e98d1 100644 --- a/src/keys/CommandPublic.ts +++ b/src/keys/CommandPublic.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandPublic extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,37 +28,23 @@ class CommandPublic extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const keyPairJWK = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysPublicKey({ + pkClient.rpcClient.methods.keysPublicKey({ metadata: auth, }), auth, @@ -75,7 +58,6 @@ class CommandPublic extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandRenew.ts b/src/keys/CommandRenew.ts index 584af54b..06ef1033 100644 --- a/src/keys/CommandRenew.ts +++ b/src/keys/CommandRenew.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandRenew extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,23 @@ class CommandRenew extends CommandPolykey { this.fs, true, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysKeyPairRenew({ + pkClient.rpcClient.methods.keysKeyPairRenew({ metadata: auth, password: passwordNew, }), @@ -75,7 +58,6 @@ class CommandRenew extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandReset.ts b/src/keys/CommandReset.ts index 71458557..62b4b722 100644 --- a/src/keys/CommandReset.ts +++ b/src/keys/CommandReset.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandReset extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,23 @@ class CommandReset extends CommandPolykey { this.fs, true, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysKeyPairReset({ + pkClient.rpcClient.methods.keysKeyPairReset({ metadata: auth, password: passwordNew, }), @@ -75,7 +58,6 @@ class CommandReset extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandSign.ts b/src/keys/CommandSign.ts index fbed0b53..7a419be2 100644 --- a/src/keys/CommandSign.ts +++ b/src/keys/CommandSign.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -22,8 +21,6 @@ class CommandSign extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -36,32 +33,18 @@ class CommandSign extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let data: string; @@ -82,7 +65,7 @@ class CommandSign extends CommandPolykey { } const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysSign({ + pkClient.rpcClient.methods.keysSign({ metadata: auth, data, }), @@ -103,7 +86,6 @@ class CommandSign extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/keys/CommandVerify.ts b/src/keys/CommandVerify.ts index 50f5e51e..f2f3690d 100644 --- a/src/keys/CommandVerify.ts +++ b/src/keys/CommandVerify.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { PublicKeyJWK } from 'polykey/dist/keys/types'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; @@ -28,8 +27,6 @@ class CommandVerify extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const keysUtils = await import('polykey/dist/keys/utils'); const clientOptions = await binProcessors.processClientOptions( @@ -44,32 +41,18 @@ class CommandVerify extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let data: string; @@ -116,7 +99,7 @@ class CommandVerify extends CommandPolykey { } const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.keysVerify({ + pkClient.rpcClient.methods.keysVerify({ metadata: auth, publicKeyJwk: publicJWK, data, @@ -139,7 +122,6 @@ class CommandVerify extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandAdd.ts b/src/nodes/CommandAdd.ts index 24828bf6..116af9fb 100644 --- a/src/nodes/CommandAdd.ts +++ b/src/nodes/CommandAdd.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import type { Host, Port } from 'polykey/dist/network/types'; import CommandPolykey from '../CommandPolykey'; @@ -25,8 +24,6 @@ class CommandAdd extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -40,37 +37,23 @@ class CommandAdd extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.nodesAdd({ + pkClient.rpcClient.methods.nodesAdd({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), host: host, @@ -82,7 +65,6 @@ class CommandAdd extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandClaim.ts b/src/nodes/CommandClaim.ts index 17901048..3e17ec8d 100644 --- a/src/nodes/CommandClaim.ts +++ b/src/nodes/CommandClaim.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -28,8 +27,6 @@ class CommandClaim extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -43,37 +40,23 @@ class CommandClaim extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.nodesClaim({ + pkClient.rpcClient.methods.nodesClaim({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), forceInvite: options.forceInvite, @@ -106,7 +89,6 @@ class CommandClaim extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandConnections.ts b/src/nodes/CommandConnections.ts index ae52c321..a8ee7452 100644 --- a/src/nodes/CommandConnections.ts +++ b/src/nodes/CommandConnections.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeConnectionMessage } from 'polykey/dist/client/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils/utils'; @@ -14,8 +13,6 @@ class CommandAdd extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -28,39 +25,25 @@ class CommandAdd extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); // DO things here... // Like create the message. const connections = await binUtils.retryAuthentication(async (auth) => { const connections = - await pkClient.rpcClientClient.methods.nodesListConnections({ + await pkClient.rpcClient.methods.nodesListConnections({ metadata: auth, }); const connectionEntries: Array = []; @@ -97,7 +80,6 @@ class CommandAdd extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandFind.ts b/src/nodes/CommandFind.ts index 75bfb7f4..4528ade8 100644 --- a/src/nodes/CommandFind.ts +++ b/src/nodes/CommandFind.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import type { Host, Port } from 'polykey/dist/network/types'; import CommandPolykey from '../CommandPolykey'; @@ -22,8 +21,6 @@ class CommandFind extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const networkUtils = await import('polykey/dist/network/utils'); const nodesErrors = await import('polykey/dist/nodes/errors'); @@ -39,32 +36,19 @@ class CommandFind extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const result = { @@ -77,7 +61,7 @@ class CommandFind extends CommandPolykey { try { const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.nodesFind({ + pkClient.rpcClient.methods.nodesFind({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), }), @@ -118,7 +102,6 @@ class CommandFind extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandGetAll.ts b/src/nodes/CommandGetAll.ts index e22cc417..c0ded8bb 100644 --- a/src/nodes/CommandGetAll.ts +++ b/src/nodes/CommandGetAll.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandGetAll extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,37 +28,24 @@ class CommandGetAll extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const result = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.nodesGetAll({ + pkClient.rpcClient.methods.nodesGetAll({ metadata: auth, }), auth, @@ -84,7 +68,6 @@ class CommandGetAll extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/nodes/CommandPing.ts b/src/nodes/CommandPing.ts index eff75732..aaff1ca0 100644 --- a/src/nodes/CommandPing.ts +++ b/src/nodes/CommandPing.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -21,8 +20,6 @@ class CommandPing extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -36,38 +33,25 @@ class CommandPing extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let error; const statusMessage = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.nodesPing({ + pkClient.rpcClient.methods.nodesPing({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), }), @@ -93,7 +77,6 @@ class CommandPing extends CommandPolykey { if (error != null) throw error; } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/notifications/CommandClear.ts b/src/notifications/CommandClear.ts index 5fa80603..16077b0c 100644 --- a/src/notifications/CommandClear.ts +++ b/src/notifications/CommandClear.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandClear extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,44 +28,30 @@ class CommandClear extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.notificationsClear({ + pkClient.rpcClient.methods.notificationsClear({ metadata: auth, }), auth, ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/notifications/CommandRead.ts b/src/notifications/CommandRead.ts index 6b63789d..78153798 100644 --- a/src/notifications/CommandRead.ts +++ b/src/notifications/CommandRead.ts @@ -1,5 +1,4 @@ import type { Notification } from 'polykey/dist/notifications/types'; -import type { WebSocketClient } from '@matrixai/ws'; import type PolykeyClient from 'polykey/dist/PolykeyClient'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -32,8 +31,6 @@ class CommandRead extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const notificationsUtils = await import( 'polykey/dist/notifications/utils' ); @@ -49,37 +46,24 @@ class CommandRead extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.notificationsRead({ + pkClient.rpcClient.methods.notificationsRead({ metadata: auth, unread: options.unread, number: options.number, @@ -104,7 +88,6 @@ class CommandRead extends CommandPolykey { } } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/notifications/CommandSend.ts b/src/notifications/CommandSend.ts index e3026ae6..0a85d635 100644 --- a/src/notifications/CommandSend.ts +++ b/src/notifications/CommandSend.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -25,8 +24,6 @@ class CommandSend extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -40,37 +37,24 @@ class CommandSend extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.notificationsSend({ + pkClient.rpcClient.methods.notificationsSend({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), message: message, @@ -79,7 +63,6 @@ class CommandSend extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandCreate.ts b/src/secrets/CommandCreate.ts index a3e67497..ad80c543 100644 --- a/src/secrets/CommandCreate.ts +++ b/src/secrets/CommandCreate.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -28,8 +27,6 @@ class CommandCreate extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -42,32 +39,19 @@ class CommandCreate extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let content: Buffer; @@ -86,7 +70,7 @@ class CommandCreate extends CommandPolykey { } await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsNew({ + pkClient.rpcClient.methods.vaultsSecretsNew({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -96,7 +80,6 @@ class CommandCreate extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandDelete.ts b/src/secrets/CommandDelete.ts index e85bd119..b034fe1e 100644 --- a/src/secrets/CommandDelete.ts +++ b/src/secrets/CommandDelete.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandDelete extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -38,37 +35,24 @@ class CommandDelete extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsDelete({ + pkClient.rpcClient.methods.vaultsSecretsDelete({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -77,7 +61,6 @@ class CommandDelete extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandDir.ts b/src/secrets/CommandDir.ts index 8cd3bf91..a9009d47 100644 --- a/src/secrets/CommandDir.ts +++ b/src/secrets/CommandDir.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -22,8 +21,6 @@ class CommandDir extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -36,37 +33,24 @@ class CommandDir extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsNewDir({ + pkClient.rpcClient.methods.vaultsSecretsNewDir({ metadata: auth, nameOrId: vaultName, dirName: directoryPath, @@ -75,7 +59,6 @@ class CommandDir extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandEdit.ts b/src/secrets/CommandEdit.ts index d8d9a8c1..541f8920 100644 --- a/src/secrets/CommandEdit.ts +++ b/src/secrets/CommandEdit.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -26,8 +25,6 @@ class CommandEdit extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -40,37 +37,24 @@ class CommandEdit extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsGet({ + pkClient.rpcClient.methods.vaultsSecretsGet({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -98,7 +82,7 @@ class CommandEdit extends CommandPolykey { cause: e, }); } - await pkClient.rpcClientClient.methods.vaultsSecretsEdit({ + await pkClient.rpcClient.methods.vaultsSecretsEdit({ nameOrId: secretPath[0], secretName: secretPath[1], secretContent: content.toString('binary'), @@ -108,7 +92,6 @@ class CommandEdit extends CommandPolykey { // TODO: complete windows impl } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandGet.ts b/src/secrets/CommandGet.ts index 8a93eb8e..6ab24c60 100644 --- a/src/secrets/CommandGet.ts +++ b/src/secrets/CommandGet.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -23,8 +22,6 @@ class CommandGet extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,37 +34,24 @@ class CommandGet extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsGet({ + pkClient.rpcClient.methods.vaultsSecretsGet({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -83,7 +67,6 @@ class CommandGet extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandList.ts b/src/secrets/CommandList.ts index 405e07a1..a4b7b0d1 100644 --- a/src/secrets/CommandList.ts +++ b/src/secrets/CommandList.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -19,8 +18,6 @@ class CommandList extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -33,41 +30,27 @@ class CommandList extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { const data: Array = []; - const stream = - await pkClient.rpcClientClient.methods.vaultsSecretsList({ - metadata: auth, - nameOrId: vaultName, - }); + const stream = await pkClient.rpcClient.methods.vaultsSecretsList({ + metadata: auth, + nameOrId: vaultName, + }); for await (const secret of stream) { data.push(secret.secretName); } @@ -81,7 +64,6 @@ class CommandList extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandMkdir.ts b/src/secrets/CommandMkdir.ts index a1613668..bf07c6b5 100644 --- a/src/secrets/CommandMkdir.ts +++ b/src/secrets/CommandMkdir.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandMkdir extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -38,37 +35,24 @@ class CommandMkdir extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsMkdir({ + pkClient.rpcClient.methods.vaultsSecretsMkdir({ metadata: auth, nameOrId: secretPath[0], dirName: secretPath[1], @@ -78,7 +62,6 @@ class CommandMkdir extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandRename.ts b/src/secrets/CommandRename.ts index ea7008ce..b11985f2 100644 --- a/src/secrets/CommandRename.ts +++ b/src/secrets/CommandRename.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -24,8 +23,6 @@ class CommandRename extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -38,37 +35,24 @@ class CommandRename extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsRename({ + pkClient.rpcClient.methods.vaultsSecretsRename({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -78,7 +62,6 @@ class CommandRename extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandStat.ts b/src/secrets/CommandStat.ts index d9247260..fd383970 100644 --- a/src/secrets/CommandStat.ts +++ b/src/secrets/CommandStat.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binProcessors from '../utils/processors'; import * as binParsers from '../utils/parsers'; @@ -23,8 +22,6 @@ class CommandStat extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -37,38 +34,25 @@ class CommandStat extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); // Get the secret's stat. const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsStat({ + pkClient.rpcClient.methods.vaultsSecretsStat({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -90,7 +74,6 @@ class CommandStat extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/secrets/CommandUpdate.ts b/src/secrets/CommandUpdate.ts index 85fd8c7e..6db294c2 100644 --- a/src/secrets/CommandUpdate.ts +++ b/src/secrets/CommandUpdate.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as errors from '../errors'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -28,8 +27,6 @@ class CommandUpdate extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -42,32 +39,19 @@ class CommandUpdate extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); let content: Buffer; @@ -86,7 +70,7 @@ class CommandUpdate extends CommandPolykey { } await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsSecretsEdit({ + pkClient.rpcClient.methods.vaultsSecretsEdit({ metadata: auth, nameOrId: secretPath[0], secretName: secretPath[1], @@ -96,7 +80,6 @@ class CommandUpdate extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandClone.ts b/src/vaults/CommandClone.ts index 422ef26c..23508dff 100644 --- a/src/vaults/CommandClone.ts +++ b/src/vaults/CommandClone.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -25,8 +24,6 @@ class CommandClone extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -40,37 +37,24 @@ class CommandClone extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsClone({ + pkClient.rpcClient.methods.vaultsClone({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), nameOrId: vaultNameOrId, @@ -79,7 +63,6 @@ class CommandClone extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandCreate.ts b/src/vaults/CommandCreate.ts index a83dd846..18912299 100644 --- a/src/vaults/CommandCreate.ts +++ b/src/vaults/CommandCreate.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -19,8 +18,6 @@ class CommandCreate extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -33,37 +30,24 @@ class CommandCreate extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const response = await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsCreate({ + pkClient.rpcClient.methods.vaultsCreate({ metadata: auth, vaultName: vaultName, }), @@ -77,7 +61,6 @@ class CommandCreate extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandDelete.ts b/src/vaults/CommandDelete.ts index a790010a..ff3e905c 100644 --- a/src/vaults/CommandDelete.ts +++ b/src/vaults/CommandDelete.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandDelete extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -32,37 +29,24 @@ class CommandDelete extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsDelete({ + pkClient.rpcClient.methods.vaultsDelete({ metadata: auth, nameOrId: vaultName, }), @@ -70,7 +54,6 @@ class CommandDelete extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandList.ts b/src/vaults/CommandList.ts index b8fa43e2..ab420ddb 100644 --- a/src/vaults/CommandList.ts +++ b/src/vaults/CommandList.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -17,8 +16,6 @@ class CommandList extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -31,37 +28,24 @@ class CommandList extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { const data: Array = []; - const stream = await pkClient.rpcClientClient.methods.vaultsList({ + const stream = await pkClient.rpcClient.methods.vaultsList({ metadata: auth, }); for await (const vaultListMessage of stream) { @@ -79,7 +63,6 @@ class CommandList extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandLog.ts b/src/vaults/CommandLog.ts index a6e27400..21e8b2d4 100644 --- a/src/vaults/CommandLog.ts +++ b/src/vaults/CommandLog.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -20,8 +19,6 @@ class CommandLog extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -34,37 +31,24 @@ class CommandLog extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { const data: Array = []; - const logStream = await pkClient.rpcClientClient.methods.vaultsLog({ + const logStream = await pkClient.rpcClient.methods.vaultsLog({ metadata: auth, nameOrId: vault, depth: options.depth, @@ -86,7 +70,6 @@ class CommandLog extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandPermissions.ts b/src/vaults/CommandPermissions.ts index 54a1a5b7..58575381 100644 --- a/src/vaults/CommandPermissions.ts +++ b/src/vaults/CommandPermissions.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import * as binProcessors from '../utils/processors'; import * as binUtils from '../utils'; import CommandPolykey from '../CommandPolykey'; @@ -19,8 +18,6 @@ class CommandPermissions extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -33,38 +30,25 @@ class CommandPermissions extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data: Array = []; await binUtils.retryAuthentication(async (auth) => { const permissionStream = - await pkClient.rpcClientClient.methods.vaultsPermissionGet({ + await pkClient.rpcClient.methods.vaultsPermissionGet({ metadata: auth, nameOrId: vaultName, }); @@ -85,7 +69,6 @@ class CommandPermissions extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandPull.ts b/src/vaults/CommandPull.ts index a27b6e65..6078f292 100644 --- a/src/vaults/CommandPull.ts +++ b/src/vaults/CommandPull.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -27,8 +26,6 @@ class CommandPull extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -42,37 +39,24 @@ class CommandPull extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, - host: clientOptions.clientHost, - port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + nodeId: clientOptions.nodeId, + host: options.host, + port: options.port, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsPull({ + pkClient.rpcClient.methods.vaultsPull({ metadata: auth, nodeIdEncoded: targetNodeId != null @@ -85,7 +69,6 @@ class CommandPull extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }, ); diff --git a/src/vaults/CommandRename.ts b/src/vaults/CommandRename.ts index ea04d373..34f1f2b3 100644 --- a/src/vaults/CommandRename.ts +++ b/src/vaults/CommandRename.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -19,8 +18,6 @@ class CommandRename extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -33,37 +30,24 @@ class CommandRename extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsRename({ + pkClient.rpcClient.methods.vaultsRename({ metadata: auth, nameOrId: vaultName, newName: newVaultName, @@ -72,7 +56,6 @@ class CommandRename extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandScan.ts b/src/vaults/CommandScan.ts index 6d9676b5..6ca0ae00 100644 --- a/src/vaults/CommandScan.ts +++ b/src/vaults/CommandScan.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -18,8 +17,6 @@ class CommandScan extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -32,37 +29,24 @@ class CommandScan extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); const data = await binUtils.retryAuthentication(async (auth) => { const data: Array = []; - const stream = await pkClient.rpcClientClient.methods.vaultsScan({ + const stream = await pkClient.rpcClient.methods.vaultsScan({ metadata: auth, nodeIdEncoded: nodeId, }); @@ -82,7 +66,6 @@ class CommandScan extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandShare.ts b/src/vaults/CommandShare.ts index 00240151..b6e86ad3 100644 --- a/src/vaults/CommandShare.ts +++ b/src/vaults/CommandShare.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -25,8 +24,6 @@ class CommandShare extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -40,37 +37,24 @@ class CommandShare extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsPermissionSet({ + pkClient.rpcClient.methods.vaultsPermissionSet({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), nameOrId: vaultName, @@ -80,7 +64,6 @@ class CommandShare extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandUnshare.ts b/src/vaults/CommandUnshare.ts index 4aa3a074..e791f170 100644 --- a/src/vaults/CommandUnshare.ts +++ b/src/vaults/CommandUnshare.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import type { NodeId } from 'polykey/dist/ids/types'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; @@ -25,8 +24,6 @@ class CommandUnshare extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const nodesUtils = await import('polykey/dist/nodes/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, @@ -40,37 +37,24 @@ class CommandUnshare extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsPermissionUnset({ + pkClient.rpcClient.methods.vaultsPermissionUnset({ metadata: auth, nodeIdEncoded: nodesUtils.encodeNodeId(nodeId), nameOrId: vaultName, @@ -80,7 +64,6 @@ class CommandUnshare extends CommandPolykey { ); } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); } diff --git a/src/vaults/CommandVersion.ts b/src/vaults/CommandVersion.ts index 56392bfd..327bfd18 100644 --- a/src/vaults/CommandVersion.ts +++ b/src/vaults/CommandVersion.ts @@ -1,5 +1,4 @@ import type PolykeyClient from 'polykey/dist/PolykeyClient'; -import type { WebSocketClient } from '@matrixai/ws'; import CommandPolykey from '../CommandPolykey'; import * as binUtils from '../utils'; import * as binOptions from '../utils/options'; @@ -19,8 +18,6 @@ class CommandVersion extends CommandPolykey { const { default: PolykeyClient } = await import( 'polykey/dist/PolykeyClient' ); - const { WebSocketClient } = await import('@matrixai/ws'); - const clientUtils = await import('polykey/dist/client/utils'); const clientOptions = await binProcessors.processClientOptions( options.nodePath, options.nodeId, @@ -33,37 +30,24 @@ class CommandVersion extends CommandPolykey { options.passwordFile, this.fs, ); - let webSocketClient: WebSocketClient; + let pkClient: PolykeyClient; this.exitHandlers.handlers.push(async () => { if (pkClient != null) await pkClient.stop(); - if (webSocketClient != null) { - await webSocketClient.destroy({ force: true }); - } }); try { - webSocketClient = await WebSocketClient.createWebSocketClient({ - config: { - verifyPeer: true, - verifyCallback: async (certs) => { - await clientUtils.verifyServerCertificateChain( - [clientOptions.nodeId], - certs, - ); - }, - }, + pkClient = await PolykeyClient.createPolykeyClient({ + nodeId: clientOptions.nodeId, host: clientOptions.clientHost, port: clientOptions.clientPort, - logger: this.logger.getChild(WebSocketClient.name), - }); - pkClient = await PolykeyClient.createPolykeyClient({ - streamFactory: () => webSocketClient.connection.newStream(), - nodePath: options.nodePath, + options: { + nodePath: options.nodePath, + }, logger: this.logger.getChild(PolykeyClient.name), }); await binUtils.retryAuthentication( (auth) => - pkClient.rpcClientClient.methods.vaultsVersion({ + pkClient.rpcClient.methods.vaultsVersion({ metadata: auth, nameOrId: vault, versionId: versionId, @@ -79,7 +63,6 @@ class CommandVersion extends CommandPolykey { */ } finally { if (pkClient! != null) await pkClient.stop(); - if (webSocketClient! != null) await webSocketClient.destroy(); } }); }