Skip to content

Commit ce23508

Browse files
committed
WIP - general rebase fixes
1 parent ea540ba commit ce23508

8 files changed

Lines changed: 120 additions & 111 deletions

File tree

src/nodes/NodeConnection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import * as utilsPB from '../proto/js/polykey/v1/utils/utils_pb';
2828
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';
2929
import * as notificationsPB from '../proto/js/polykey/v1/notifications/notifications_pb';
3030
import { utils as networkUtils } from '../network';
31+
import * as validationUtils from '../validation/utils';
3132

3233
/**
3334
* Encapsulates the unidirectional client-side connection of one node to another.
@@ -454,13 +455,13 @@ class NodeConnection {
454455
nodeId: NodeId,
455456
): Promise<Array<[VaultName, VaultId]>> {
456457
const nodeIdMessage = new nodesPB.Node();
457-
nodeIdMessage.setNodeId(nodeId);
458+
nodeIdMessage.setNodeId(nodesUtils.encodeNodeId(nodeId));
458459
const vaults: Array<[VaultName, VaultId]> = [];
459460
const genReadable = this.client.vaultsScan(nodeIdMessage);
460461
for await (const vault of genReadable) {
461462
vaults.push([
462463
vault.getVaultName() as VaultName,
463-
vaultsUtils.makeVaultId(vault.getVaultId()),
464+
validationUtils.parseVaultId(vault.getVaultId()),
464465
]);
465466
}
466467
return vaults;

src/validation/utils.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import type { NodeId } from '../nodes/types';
1010
import type { ProviderId, IdentityId } from '../identities/types';
1111
import type { GestaltAction, GestaltId } from '../gestalts/types';
12-
import type { VaultAction } from '../vaults/types';
12+
import type { VaultAction, VaultId } from '../vaults/types';
1313
import type { Host, Hostname, Port } from '../network/types';
1414
import type { ClaimId } from '../claims/types';
1515
import * as validationErrors from './errors';
@@ -81,6 +81,16 @@ function parseClaimId(data: any): ClaimId {
8181
return data;
8282
}
8383

84+
function parseVaultId(data: any): VaultId {
85+
data = vaultsUtils.decodeVaultId(data);
86+
if (data == null) {
87+
throw new validationErrors.ErrorParse(
88+
'Vault ID must be multibase base58btc encoded strings',
89+
)
90+
}
91+
return data;
92+
}
93+
8494
function parseGestaltAction(data: any): GestaltAction {
8595
if (!gestaltsUtils.isGestaltAction(data)) {
8696
throw new validationErrors.ErrorParse(
@@ -179,6 +189,7 @@ export {
179189
parseNodeId,
180190
parseGestaltId,
181191
parseClaimId,
192+
parseVaultId,
182193
parseGestaltAction,
183194
parseVaultAction,
184195
parseProviderId,

src/vaults/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ interface FileSystemWritable extends FileSystemReadable {
145145
// }
146146
// >;
147147

148-
// type VaultName = Opaque<'VaultName', string>;
148+
type VaultName = string; // FIXME, placeholder, remove?
149149

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

@@ -195,7 +195,7 @@ export type {
195195
FileSystemWritable,
196196
// VaultIdPretty,
197197
// VaultKey,
198-
// VaultName,
198+
VaultName,
199199
// VaultList,
200200
// VaultMap,
201201
// VaultMetadata,

tests/bin/notifications/notifications.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import fs from 'fs';
77
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { utils as idUtils } from '@matrixai/id';
99
import PolykeyAgent from '@/PolykeyAgent';
10-
import { makeVaultId } from '@/vaults/utils';
10+
import * as vaultsUtils from '@/vaults/utils';
1111
import { utils as nodesUtils } from '@/nodes';
1212
import * as testBinUtils from '../utils';
1313

@@ -353,7 +353,7 @@ describe('CLI Notifications', () => {
353353
};
354354
const notificationData3: NotificationData = {
355355
type: 'VaultShare',
356-
vaultId: makeVaultId(idUtils.fromString('vaultIdxxxxxxxxx')).toString(),
356+
vaultId: vaultsUtils.encodeVaultId(vaultsUtils.generateVaultId()),
357357
vaultName: 'vaultName' as VaultName,
358358
actions: {
359359
clone: null,

tests/client/rpcVaults.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ describe('Vaults client service', () => {
138138
const vaultId = await createVault(vaultMessage, callCredentials);
139139
const vaultNames = await vaultManager.listVaults();
140140
expect(vaultNames.get(vaultList[0])).toBeTruthy();
141-
expect(vaultNames.get(vaultList[0])).toStrictEqual(
142-
vaultsUtils.makeVaultId(vaultId.getNameOrId()),
143-
);
141+
expect(vaultNames.get(vaultList[0])).toStrictEqual(vaultId.getNameOrId());
144142
});
145143
test('should delete vaults', async () => {
146144
const deleteVault = grpcUtils.promisifyUnaryCall<utilsPB.StatusMessage>(
@@ -174,7 +172,7 @@ describe('Vaults client service', () => {
174172
vaultRenameMessage.setNewName(vaultList[1]);
175173

176174
const vaultId2 = await renameVault(vaultRenameMessage, callCredentials);
177-
expect(vaultsUtils.makeVaultId(vaultId2.getNameOrId())).toStrictEqual(
175+
expect(vaultsUtils.decodeVaultId(vaultId2.getNameOrId())).toStrictEqual(
178176
vaultId1,
179177
);
180178

@@ -249,7 +247,7 @@ describe('Vaults client service', () => {
249247
vaultVersionMessage.setVersionId('invalidOid');
250248
const version = vaultsVersion(vaultVersionMessage, callCredentials);
251249
await expect(version).rejects.toThrow(
252-
vaultErrors.ErrorVaultsCommitUndefined,
250+
vaultErrors.ErrorVaultReferenceMissing,
253251
);
254252
});
255253
});

tests/notifications/utils.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ import * as notificationsUtils from '@/notifications/utils';
99
import * as notificationsErrors from '@/notifications/errors';
1010
import { createNotificationIdGenerator } from '@/notifications/utils';
1111
import { sleep } from '@/utils';
12-
import { makeVaultId } from '@/vaults/utils';
1312
import { utils as nodesUtils } from '@/nodes';
1413
import * as testUtils from '../utils';
14+
import * as vaultUtils from '@/vaults/utils';
1515

1616
describe('Notifications utils', () => {
1717
const nodeId = testUtils.generateRandomNodeId();
1818
const nodeIdEncoded = nodesUtils.encodeNodeId(nodeId);
19-
const vaultId = makeVaultId(
20-
idUtils.fromString('vaultIdxxxxxxxxx'),
21-
).toString();
19+
const vaultId = vaultUtils.generateVaultId();
20+
const vaultIdEncoded = vaultUtils.encodeVaultId(vaultId);
2221

2322
test('generates notification ids', async () => {
2423
const generator = createNotificationIdGenerator();
@@ -64,7 +63,7 @@ describe('Notifications utils', () => {
6463
const vaultShareNotification: Notification = {
6564
data: {
6665
type: 'VaultShare',
67-
vaultId: vaultId,
66+
vaultId: vaultIdEncoded,
6867
vaultName: 'vaultName' as VaultName,
6968
actions: {
7069
clone: null,
@@ -145,7 +144,7 @@ describe('Notifications utils', () => {
145144
const vaultShareNotification: Notification = {
146145
data: {
147146
type: 'VaultShare',
148-
vaultId: vaultId,
147+
vaultId: vaultIdEncoded,
149148
vaultName: 'vaultName' as VaultName,
150149
actions: {
151150
clone: null,
@@ -239,7 +238,7 @@ describe('Notifications utils', () => {
239238
const vaultShareNotification: Notification = {
240239
data: {
241240
type: 'VaultShare',
242-
vaultId: vaultId,
241+
vaultId: vaultIdEncoded,
243242
vaultName: 'vaultName' as VaultName,
244243
actions: {
245244
clone: null,

0 commit comments

Comments
 (0)