55 validateUnauthorizedErrorResponse ,
66 validateBadRequestErrorResponse ,
77 validateForbiddenErrorResponse ,
8- ise2eSetUserPublicAndPrivateKeysParamsPOST ,
98} from '@rocket.chat/rest-typings' ;
109import ExpiryMap from 'expiry-map' ;
1110
@@ -53,6 +52,12 @@ type E2EResetRoomKeyProps = {
5352 e2eKeyId : string ;
5453} ;
5554
55+ type e2eSetUserPublicAndPrivateKeysParamsPOST = {
56+ public_key : string ;
57+ private_key : string ;
58+ force ?: boolean ;
59+ } ;
60+
5661const E2eSetRoomKeyIdSchema = {
5762 type : 'object' ,
5863 properties : {
@@ -156,6 +161,23 @@ const E2EResetRoomKeySchema = {
156161 additionalProperties : false ,
157162} ;
158163
164+ const e2eSetUserPublicAndPrivateKeysParamsPOSTSchema = {
165+ type : 'object' ,
166+ properties : {
167+ public_key : {
168+ type : 'string' ,
169+ } ,
170+ private_key : {
171+ type : 'string' ,
172+ } ,
173+ force : {
174+ type : 'boolean' ,
175+ } ,
176+ } ,
177+ additionalProperties : false ,
178+ required : [ 'public_key' , 'private_key' ] ,
179+ } ;
180+
159181const isE2eSetRoomKeyIdProps = ajv . compile < E2eSetRoomKeyIdProps > ( E2eSetRoomKeyIdSchema ) ;
160182
161183const ise2eGetUsersOfRoomWithoutKeyParamsGET = ajv . compile < e2eGetUsersOfRoomWithoutKeyParamsGET > (
@@ -170,6 +192,10 @@ const isE2EProvideUsersGroupKeyProps = ajv.compile<E2EProvideUsersGroupKeyProps>
170192
171193const isE2EResetRoomKeyProps = ajv . compile < E2EResetRoomKeyProps > ( E2EResetRoomKeySchema ) ;
172194
195+ const ise2eSetUserPublicAndPrivateKeysParamsPOST = ajv . compile < e2eSetUserPublicAndPrivateKeysParamsPOST > (
196+ e2eSetUserPublicAndPrivateKeysParamsPOSTSchema ,
197+ ) ;
198+
173199const e2eEndpoints = API . v1
174200 . post (
175201 'e2e.setRoomKeyID' ,
@@ -293,6 +319,37 @@ const e2eEndpoints = API.v1
293319 return API . v1 . success ( ) ;
294320 } ,
295321 )
322+ . post (
323+ 'e2e.setUserPublicAndPrivateKeys' ,
324+ {
325+ authRequired : true ,
326+ body : ise2eSetUserPublicAndPrivateKeysParamsPOST ,
327+ response : {
328+ 400 : validateBadRequestErrorResponse ,
329+ 401 : validateUnauthorizedErrorResponse ,
330+ 200 : ajv . compile < void > ( {
331+ type : 'object' ,
332+ properties : {
333+ success : { type : 'boolean' , enum : [ true ] } ,
334+ } ,
335+ required : [ 'success' ] ,
336+ } ) ,
337+ } ,
338+ } ,
339+
340+ async function action ( ) {
341+ // eslint-disable-next-line @typescript-eslint/naming-convention
342+ const { public_key, private_key, force } = this . bodyParams ;
343+
344+ await setUserPublicAndPrivateKeysMethod ( this . userId , {
345+ public_key,
346+ private_key,
347+ force,
348+ } ) ;
349+
350+ return API . v1 . success ( ) ;
351+ } ,
352+ )
296353 . post (
297354 'e2e.acceptSuggestedGroupKey' ,
298355 {
@@ -469,61 +526,6 @@ const e2eEndpoints = API.v1
469526 } ,
470527 ) ;
471528
472- /**
473- * @openapi
474- * /api/v1/e2e.setUserPublicAndPrivateKeys:
475- * post:
476- * description: Sets the end-to-end encryption keys for the authenticated user
477- * security:
478- * - autenticated: {}
479- * requestBody:
480- * description: A tuple containing the public and the private keys
481- * content:
482- * application/json:
483- * schema:
484- * type: object
485- * properties:
486- * public_key:
487- * type: string
488- * private_key:
489- * type: string
490- * force:
491- * type: boolean
492- * responses:
493- * 200:
494- * content:
495- * application/json:
496- * schema:
497- * $ref: '#/components/schemas/ApiSuccessV1'
498- * default:
499- * description: Unexpected error
500- * content:
501- * application/json:
502- * schema:
503- * $ref: '#/components/schemas/ApiFailureV1'
504- */
505- API . v1 . addRoute (
506- 'e2e.setUserPublicAndPrivateKeys' ,
507- {
508- authRequired : true ,
509- validateParams : ise2eSetUserPublicAndPrivateKeysParamsPOST ,
510- } ,
511- {
512- async post ( ) {
513- // eslint-disable-next-line @typescript-eslint/naming-convention
514- const { public_key, private_key, force } = this . bodyParams ;
515-
516- await setUserPublicAndPrivateKeysMethod ( this . userId , {
517- public_key,
518- private_key,
519- force,
520- } ) ;
521-
522- return API . v1 . success ( ) ;
523- } ,
524- } ,
525- ) ;
526-
527529type E2eEndpoints = ExtractRoutesFromAPI < typeof e2eEndpoints > ;
528530
529531declare module '@rocket.chat/rest-typings' {
0 commit comments