-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-data.ts
78 lines (72 loc) · 2.31 KB
/
user-data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import GraphEdge from "./avro/GraphEdge.js";
import PRId from "./avro/PRId.js";
import PublicKey from "./avro/PublicKey.js";
import ProfileResource from "./avro/ProfileResource.js";
export enum UserDataType {
PublicFollows = "publicFollows",
PrivateFollows = "privateFollows",
PrivateConnections = "privateConnections",
PrivateConnectionPRIds = "privateConnectionPRIds",
KeyAgreementPublicKeys = "keyAgreementPublicKeys",
AssertionMethodPublicKeys = "assertionMethodPublicKeys",
ProfileResources = "profileResources",
}
export enum UserDataEncryptionAlgorithmType {
Curve25519XSalsa20Poly1305 = "curve25519xsalsa20poly1305",
}
export enum UserDataCompressionCodecType {
DEFLATE = "DEFLATE",
}
export type UserDataDescriptor = {
systemName: UserDataType;
encryptionAlgorithm: null | UserDataEncryptionAlgorithmType;
compressionCodec: null | UserDataCompressionCodecType;
avroSchema: object;
};
export function descriptorForUserDataType(userDataType: UserDataType): UserDataDescriptor {
const base = {
systemName: userDataType,
encryptionAlgorithm: null,
compressionCodec: null,
};
switch (userDataType) {
case UserDataType.PublicFollows:
return {
...base,
compressionCodec: UserDataCompressionCodecType.DEFLATE,
avroSchema: GraphEdge,
};
case UserDataType.PrivateFollows:
return {
...base,
encryptionAlgorithm: UserDataEncryptionAlgorithmType.Curve25519XSalsa20Poly1305,
compressionCodec: UserDataCompressionCodecType.DEFLATE,
avroSchema: GraphEdge,
};
case UserDataType.PrivateConnections:
return {
...base,
encryptionAlgorithm: UserDataEncryptionAlgorithmType.Curve25519XSalsa20Poly1305,
compressionCodec: UserDataCompressionCodecType.DEFLATE,
avroSchema: GraphEdge,
};
case UserDataType.PrivateConnectionPRIds:
return {
...base,
compressionCodec: UserDataCompressionCodecType.DEFLATE,
avroSchema: PRId,
};
case UserDataType.KeyAgreementPublicKeys:
case UserDataType.AssertionMethodPublicKeys:
return {
...base,
avroSchema: PublicKey,
};
case UserDataType.ProfileResources:
return {
...base,
avroSchema: ProfileResource,
};
}
throw new Error("Invalid enum value");
}