Skip to content

Commit

Permalink
WIP - general rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tegefaulkes committed Feb 10, 2022
1 parent ea540ba commit ce23508
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 111 deletions.
5 changes: 3 additions & 2 deletions src/nodes/NodeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import * as utilsPB from '../proto/js/polykey/v1/utils/utils_pb';
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';
import * as notificationsPB from '../proto/js/polykey/v1/notifications/notifications_pb';
import { utils as networkUtils } from '../network';
import * as validationUtils from '../validation/utils';

/**
* Encapsulates the unidirectional client-side connection of one node to another.
Expand Down Expand Up @@ -454,13 +455,13 @@ class NodeConnection {
nodeId: NodeId,
): Promise<Array<[VaultName, VaultId]>> {
const nodeIdMessage = new nodesPB.Node();
nodeIdMessage.setNodeId(nodeId);
nodeIdMessage.setNodeId(nodesUtils.encodeNodeId(nodeId));
const vaults: Array<[VaultName, VaultId]> = [];
const genReadable = this.client.vaultsScan(nodeIdMessage);
for await (const vault of genReadable) {
vaults.push([
vault.getVaultName() as VaultName,
vaultsUtils.makeVaultId(vault.getVaultId()),
validationUtils.parseVaultId(vault.getVaultId()),
]);
}
return vaults;
Expand Down
13 changes: 12 additions & 1 deletion src/validation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type { NodeId } from '../nodes/types';
import type { ProviderId, IdentityId } from '../identities/types';
import type { GestaltAction, GestaltId } from '../gestalts/types';
import type { VaultAction } from '../vaults/types';
import type { VaultAction, VaultId } from '../vaults/types';
import type { Host, Hostname, Port } from '../network/types';
import type { ClaimId } from '../claims/types';
import * as validationErrors from './errors';
Expand Down Expand Up @@ -81,6 +81,16 @@ function parseClaimId(data: any): ClaimId {
return data;
}

function parseVaultId(data: any): VaultId {
data = vaultsUtils.decodeVaultId(data);
if (data == null) {
throw new validationErrors.ErrorParse(
'Vault ID must be multibase base58btc encoded strings',
)
}
return data;
}

function parseGestaltAction(data: any): GestaltAction {
if (!gestaltsUtils.isGestaltAction(data)) {
throw new validationErrors.ErrorParse(
Expand Down Expand Up @@ -179,6 +189,7 @@ export {
parseNodeId,
parseGestaltId,
parseClaimId,
parseVaultId,
parseGestaltAction,
parseVaultAction,
parseProviderId,
Expand Down
4 changes: 2 additions & 2 deletions src/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ interface FileSystemWritable extends FileSystemReadable {
// }
// >;

// type VaultName = Opaque<'VaultName', string>;
type VaultName = string; // FIXME, placeholder, remove?

// type VaultKey = Opaque<'VaultKey', Buffer>;

Expand Down Expand Up @@ -195,7 +195,7 @@ export type {
FileSystemWritable,
// VaultIdPretty,
// VaultKey,
// VaultName,
VaultName,
// VaultList,
// VaultMap,
// VaultMetadata,
Expand Down
4 changes: 2 additions & 2 deletions tests/bin/notifications/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { utils as idUtils } from '@matrixai/id';
import PolykeyAgent from '@/PolykeyAgent';
import { makeVaultId } from '@/vaults/utils';
import * as vaultsUtils from '@/vaults/utils';
import { utils as nodesUtils } from '@/nodes';
import * as testBinUtils from '../utils';

Expand Down Expand Up @@ -353,7 +353,7 @@ describe('CLI Notifications', () => {
};
const notificationData3: NotificationData = {
type: 'VaultShare',
vaultId: makeVaultId(idUtils.fromString('vaultIdxxxxxxxxx')).toString(),
vaultId: vaultsUtils.encodeVaultId(vaultsUtils.generateVaultId()),
vaultName: 'vaultName' as VaultName,
actions: {
clone: null,
Expand Down
8 changes: 3 additions & 5 deletions tests/client/rpcVaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ describe('Vaults client service', () => {
const vaultId = await createVault(vaultMessage, callCredentials);
const vaultNames = await vaultManager.listVaults();
expect(vaultNames.get(vaultList[0])).toBeTruthy();
expect(vaultNames.get(vaultList[0])).toStrictEqual(
vaultsUtils.makeVaultId(vaultId.getNameOrId()),
);
expect(vaultNames.get(vaultList[0])).toStrictEqual(vaultId.getNameOrId());
});
test('should delete vaults', async () => {
const deleteVault = grpcUtils.promisifyUnaryCall<utilsPB.StatusMessage>(
Expand Down Expand Up @@ -174,7 +172,7 @@ describe('Vaults client service', () => {
vaultRenameMessage.setNewName(vaultList[1]);

const vaultId2 = await renameVault(vaultRenameMessage, callCredentials);
expect(vaultsUtils.makeVaultId(vaultId2.getNameOrId())).toStrictEqual(
expect(vaultsUtils.decodeVaultId(vaultId2.getNameOrId())).toStrictEqual(
vaultId1,
);

Expand Down Expand Up @@ -249,7 +247,7 @@ describe('Vaults client service', () => {
vaultVersionMessage.setVersionId('invalidOid');
const version = vaultsVersion(vaultVersionMessage, callCredentials);
await expect(version).rejects.toThrow(
vaultErrors.ErrorVaultsCommitUndefined,
vaultErrors.ErrorVaultReferenceMissing,
);
});
});
Expand Down
13 changes: 6 additions & 7 deletions tests/notifications/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import * as notificationsUtils from '@/notifications/utils';
import * as notificationsErrors from '@/notifications/errors';
import { createNotificationIdGenerator } from '@/notifications/utils';
import { sleep } from '@/utils';
import { makeVaultId } from '@/vaults/utils';
import { utils as nodesUtils } from '@/nodes';
import * as testUtils from '../utils';
import * as vaultUtils from '@/vaults/utils';

describe('Notifications utils', () => {
const nodeId = testUtils.generateRandomNodeId();
const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId);
const vaultId = makeVaultId(
idUtils.fromString('vaultIdxxxxxxxxx'),
).toString();
const vaultId = vaultUtils.generateVaultId();
const vaultIdEncoded = vaultUtils.encodeVaultId(vaultId);

test('generates notification ids', async () => {
const generator = createNotificationIdGenerator();
Expand Down Expand Up @@ -64,7 +63,7 @@ describe('Notifications utils', () => {
const vaultShareNotification: Notification = {
data: {
type: 'VaultShare',
vaultId: vaultId,
vaultId: vaultIdEncoded,
vaultName: 'vaultName' as VaultName,
actions: {
clone: null,
Expand Down Expand Up @@ -145,7 +144,7 @@ describe('Notifications utils', () => {
const vaultShareNotification: Notification = {
data: {
type: 'VaultShare',
vaultId: vaultId,
vaultId: vaultIdEncoded,
vaultName: 'vaultName' as VaultName,
actions: {
clone: null,
Expand Down Expand Up @@ -239,7 +238,7 @@ describe('Notifications utils', () => {
const vaultShareNotification: Notification = {
data: {
type: 'VaultShare',
vaultId: vaultId,
vaultId: vaultIdEncoded,
vaultName: 'vaultName' as VaultName,
actions: {
clone: null,
Expand Down
Loading

0 comments on commit ce23508

Please sign in to comment.