-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathironnode.d.ts
195 lines (181 loc) · 6.28 KB
/
ironnode.d.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
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
190
191
192
193
194
195
export type Base64String = string;
export type RFC3339Date = string;
export type PrivateKey<T> = T;
export interface PublicKey<T> {
x: T;
y: T;
}
export interface DocumentAccessList {
users?: Array<{id: string}>;
groups?: Array<{id: string}>;
}
export interface UserCreateOptions {
needsRotation: boolean;
}
export interface DeviceCreateOptions {
deviceName: string;
}
export interface DocumentCreateOptions {
documentID?: string;
documentName?: string;
accessList?: DocumentAccessList;
grantToAuthor?: boolean;
}
export interface GroupCreateOptions {
groupID?: string;
groupName?: string;
addAsMember?: boolean;
needsRotation?: boolean;
}
export interface GroupUpdateOptions {
groupName: string | null;
}
export type DocumentAssociation = "owner" | "fromUser" | "fromGroup";
export interface DocumentVisibilityList {
users: Array<{id: string}>;
groups: Array<{id: string; name?: string}>;
}
/**
* Document SDK response types
*/
export interface ApiUserResponse {
accountID: string;
segmentID: number;
userMasterPublicKey: PublicKey<Base64String>;
}
export interface DocumentIDNameResponse {
documentID: string;
documentName: string | null;
created: RFC3339Date;
updated: RFC3339Date;
}
export interface DocumentAssociationResponse extends DocumentIDNameResponse {
association: DocumentAssociation;
}
export interface DocumentListResponse {
result: DocumentAssociationResponse[];
}
export interface DocumentMetaResponse extends DocumentAssociationResponse {
visibleTo: DocumentVisibilityList;
}
export interface DecryptedDocumentResponse extends DocumentMetaResponse {
data: Buffer;
}
export interface EncryptedDocumentResponse extends DocumentIDNameResponse {
document: Buffer;
}
export interface DocumentAccessResponse {
succeeded: Array<{
id: string;
type: "user" | "group";
}>;
failed: Array<{
id: string;
type: "user" | "group";
error: string;
}>;
}
/**
* Group SDK response types
*/
export interface GroupMetaResponse {
groupID: string;
groupName: string | null;
isAdmin: boolean;
isMember: boolean;
created: RFC3339Date;
updated: RFC3339Date;
}
export interface GroupListResponse {
result: GroupMetaResponse[];
}
export interface GroupDetailResponse extends GroupMetaResponse {
groupAdmins: string[];
groupMembers: string[];
needsRotation: boolean;
}
export interface GroupUserEditResponse {
succeeded: string[];
failed: Array<{
id: string;
error: string;
}>;
}
export interface UserPublicKeyGetResponse {
[userID: string]: PublicKey<string> | null;
}
export interface UserDeviceListResponse {
result: Array<{
id: number;
name: string;
created: string;
updated: string;
isCurrentDevice: boolean;
}>;
}
export interface Document {
list(): Promise<DocumentListResponse>;
getMetadata(documentID: string): Promise<DocumentMetaResponse>;
getDocumentIDFromBytes(encryptedDocument: Buffer): Promise<string | null>;
getDocumentIDFromStream(encryptedDocument: NodeJS.ReadableStream): Promise<string | null>;
decryptBytes(documentID: string, encryptedDocument: Buffer): Promise<DecryptedDocumentResponse>;
encryptBytes(documentData: Buffer, options?: DocumentCreateOptions): Promise<EncryptedDocumentResponse>;
encryptStream(inputStream: NodeJS.ReadableStream, outputStream: NodeJS.WritableStream, options?: DocumentCreateOptions): Promise<DocumentIDNameResponse>;
updateEncryptedBytes(documentID: string, newDocumentData: Buffer): Promise<EncryptedDocumentResponse>;
updateEncryptedStream(documentID: string, inputStream: NodeJS.ReadableStream, outputStream: NodeJS.WritableStream): Promise<DocumentIDNameResponse>;
updateName(documentID: string, name: string | null): Promise<DocumentIDNameResponse>;
grantAccess(documentID: string, grantList: DocumentAccessList): Promise<DocumentAccessResponse>;
revokeAccess(documentID: string, revokeList: DocumentAccessList): Promise<DocumentAccessResponse>;
}
export interface Group {
list(): Promise<GroupListResponse>;
get(groupID: string): Promise<GroupMetaResponse | GroupDetailResponse>;
create(options?: GroupCreateOptions): Promise<GroupDetailResponse>;
update(groupID: string, options: GroupUpdateOptions): Promise<GroupMetaResponse>;
rotatePrivateKey(groupID: string): Promise<{needsRotation: boolean}>;
deleteGroup(groupID: string): Promise<{id: string}>;
addAdmins(groupID: string, adminList: string[]): Promise<GroupUserEditResponse>;
removeAdmins(groupID: string, adminList: string[]): Promise<GroupUserEditResponse>;
addMembers(groupID: string, userList: string[]): Promise<GroupUserEditResponse>;
removeMembers(groupID: string, userList: string[]): Promise<GroupUserEditResponse>;
}
export interface User {
getPublicKey(users: string | string[]): Promise<UserPublicKeyGetResponse>;
listDevices(): Promise<UserDeviceListResponse>;
deleteDevice(id?: number): Promise<{id: number}>;
rotateMasterKey(password: string): Promise<{needsRotation: boolean}>;
changePassword(currentPassword: string, newPassword: string): Promise<void>;
}
export interface SDK {
document: Document;
group: Group;
user: User;
userContext: {
userNeedsRotation: boolean;
groupsNeedingRotation: string[];
};
}
export class SDKError extends Error {
constructor(error: Error, code: number);
code: number;
rawError: Error;
}
export const ErrorCodes: {[key: string]: number};
export function initialize(accountID: string, segmentID: number, privateDeviceKey: Base64String, privateSigningKey: Base64String): Promise<SDK>;
export interface DeviceDetails {
accountID: string;
segmentID: number;
deviceKeys: {
publicKey: PublicKey<Base64String>;
privateKey: Base64String;
};
signingKeys: {
publicKey: Base64String;
privateKey: Base64String;
};
}
export namespace User {
export function verify(jwt: string): Promise<ApiUserResponse | undefined>;
export function create(jwt: string, password: string, options?: UserCreateOptions): Promise<ApiUserResponse>;
export function generateDeviceKeys(jwt: string, password: string, options?: DeviceCreateOptions): Promise<DeviceDetails>;
}