-
Notifications
You must be signed in to change notification settings - Fork 29
/
crypto-types.js
189 lines (168 loc) · 5.07 KB
/
crypto-types.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// @flow
import t, { type TInterface } from 'tcomb';
import type { OlmSessionInitializationInfo } from './request-types.js';
import { type AuthMetadata } from '../shared/identity-client-context.js';
import { tShape } from '../utils/validation-utils.js';
export type OLMIdentityKeys = {
+ed25519: string,
+curve25519: string,
};
const olmIdentityKeysValidator: TInterface<OLMIdentityKeys> =
tShape<OLMIdentityKeys>({
ed25519: t.String,
curve25519: t.String,
});
export type OLMPrekey = {
+curve25519: {
+[key: string]: string,
},
};
export type SignedPrekeys = {
+contentPrekey: string,
+contentPrekeySignature: string,
+notifPrekey: string,
+notifPrekeySignature: string,
};
export const signedPrekeysValidator: TInterface<SignedPrekeys> =
tShape<SignedPrekeys>({
contentPrekey: t.String,
contentPrekeySignature: t.String,
notifPrekey: t.String,
notifPrekeySignature: t.String,
});
export type OLMOneTimeKeys = {
+curve25519: { +[string]: string },
};
export type OneTimeKeysResult = {
+contentOneTimeKeys: OLMOneTimeKeys,
+notificationsOneTimeKeys: OLMOneTimeKeys,
};
export type OneTimeKeysResultValues = {
+contentOneTimeKeys: $ReadOnlyArray<string>,
+notificationsOneTimeKeys: $ReadOnlyArray<string>,
};
export type PickledOLMAccount = {
+picklingKey: string,
+pickledAccount: string,
};
export type NotificationsOlmDataType = {
+mainSession: string,
+picklingKey: string,
+pendingSessionUpdate: string,
+updateCreationTimestamp: number,
};
export type IdentityKeysBlob = {
+primaryIdentityPublicKeys: OLMIdentityKeys,
+notificationIdentityPublicKeys: OLMIdentityKeys,
};
export const identityKeysBlobValidator: TInterface<IdentityKeysBlob> =
tShape<IdentityKeysBlob>({
primaryIdentityPublicKeys: olmIdentityKeysValidator,
notificationIdentityPublicKeys: olmIdentityKeysValidator,
});
export type SignedIdentityKeysBlob = {
+payload: string,
+signature: string,
};
export const signedIdentityKeysBlobValidator: TInterface<SignedIdentityKeysBlob> =
tShape<SignedIdentityKeysBlob>({
payload: t.String,
signature: t.String,
});
export type UserDetail = {
+username: string,
+userID: string,
};
// This type should not be changed without making equivalent changes to
// `Message` in Identity service's `reserved_users` module
export type ReservedUsernameMessage =
| {
+statement: 'Add the following usernames to reserved list',
+payload: $ReadOnlyArray<UserDetail>,
+issuedAt: string,
}
| {
+statement: 'Remove the following username from reserved list',
+payload: string,
+issuedAt: string,
}
| {
+statement: 'This user is the owner of the following username and user ID',
+payload: UserDetail,
+issuedAt: string,
};
export const olmEncryptedMessageTypes = Object.freeze({
PREKEY: 0,
TEXT: 1,
});
export type OlmEncryptedMessageTypes = $Values<typeof olmEncryptedMessageTypes>;
export type EncryptedData = {
+message: string,
+messageType: OlmEncryptedMessageTypes,
};
export const encryptedDataValidator: TInterface<EncryptedData> =
tShape<EncryptedData>({
message: t.String,
messageType: t.Number,
});
export type ClientPublicKeys = {
+primaryIdentityPublicKeys: {
+ed25519: string,
+curve25519: string,
},
+notificationIdentityPublicKeys: {
+ed25519: string,
+curve25519: string,
},
+blobPayload: string,
+signature: string,
};
export type OutboundSessionCreationResult = {
+encryptedData: EncryptedData,
+sessionVersion: number,
};
export type OlmAPI = {
+initializeCryptoAccount: () => Promise<void>,
+getUserPublicKey: () => Promise<ClientPublicKeys>,
+encrypt: (content: string, deviceID: string) => Promise<EncryptedData>,
+encryptAndPersist: (
content: string,
deviceID: string,
messageID: string,
) => Promise<EncryptedData>,
+decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise<string>,
+decryptSequentialAndPersist: (
encryptedData: EncryptedData,
deviceID: string,
messageID: string,
) => Promise<string>,
+contentInboundSessionCreator: (
contentIdentityKeys: OLMIdentityKeys,
initialEncryptedData: EncryptedData,
sessionVersion: number,
overwrite: boolean,
) => Promise<string>,
+contentOutboundSessionCreator: (
contentIdentityKeys: OLMIdentityKeys,
contentInitializationInfo: OlmSessionInitializationInfo,
) => Promise<OutboundSessionCreationResult>,
+notificationsSessionCreator: (
cookie: ?string,
notificationsIdentityKeys: OLMIdentityKeys,
notificationsInitializationInfo: OlmSessionInitializationInfo,
keyserverID: string,
) => Promise<string>,
+reassignNotificationsSession?: (
prevCookie: ?string,
newCookie: ?string,
keyserverID: string,
) => Promise<void>,
+getOneTimeKeys: (numberOfKeys: number) => Promise<OneTimeKeysResultValues>,
+validateAndUploadPrekeys: (authMetadata: AuthMetadata) => Promise<void>,
+signMessage: (message: string) => Promise<string>,
+verifyMessage: (
message: string,
signature: string,
signingPublicKey: string,
) => Promise<boolean>,
};