@@ -109,27 +109,32 @@ export interface ProtocolProfile {
109109 messageKeyInfo : string ;
110110
111111 /** Serialise the inner ratchet message (WhisperMessage / OMEMOMessage). */
112- encodeInner ( parts : RatchetMessageParts ) : Promise < Uint8Array > ;
112+ encodeInner ( parts : RatchetMessageParts ) : Uint8Array ;
113+
113114 /** Compute the (already-truncated) MAC over the encoded inner message. */
114115 computeMac (
115116 authKey : ArrayBuffer ,
116117 encodedInner : Uint8Array ,
117118 ctx : MacContext
118119 ) : Promise < ArrayBuffer > ;
120+
119121 /** Verify the MAC over the encoded inner message; throws on mismatch. */
120122 verifyMac (
121123 authKey : ArrayBuffer ,
122124 encodedInner : Uint8Array ,
123125 ctx : MacContext ,
124126 mac : ArrayBuffer
125127 ) : Promise < void > ;
128+
126129 /** Frame the final ratchet-message body (version byte + MAC, or OMEMOAuthenticatedMessage). */
127- frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Promise < Uint8Array > ;
130+ frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Uint8Array ;
131+
128132 /** Parse an incoming ratchet-message body. */
129- parseMessage ( bytes : ArrayBuffer ) : Promise < ParsedRatchetMessage > ;
133+ parseMessage ( bytes : ArrayBuffer ) : ParsedRatchetMessage ;
130134
131135 /** Wrap an already-framed ratchet message in a key-exchange message body. */
132136 encodeKeyExchange ( parts : KeyExchangeParts , framedMessage : Uint8Array ) : Promise < Uint8Array > ;
137+
133138 /** Parse an incoming key-exchange message body. */
134139 parseKeyExchange ( bytes : ArrayBuffer ) : Promise < ParsedKeyExchange > ;
135140
@@ -240,8 +245,8 @@ const OMEMO_0_3_0: ProtocolProfile = {
240245 rootChainInfo : "WhisperRatchet" ,
241246 messageKeyInfo : "WhisperMessageKeys" ,
242247
243- async encodeInner ( parts : RatchetMessageParts ) : Promise < Uint8Array > {
244- const { WhisperMessage } = await loadProtocolMessages ( ) ;
248+ encodeInner ( parts : RatchetMessageParts ) : Uint8Array {
249+ const { WhisperMessage } = loadProtocolMessages ( ) ;
245250 const msg = WhisperMessage . create ( {
246251 ephemeralKey : new Uint8Array ( parts . ephemeralKey ) ,
247252 counter : parts . counter ,
@@ -269,23 +274,23 @@ const OMEMO_0_3_0: ProtocolProfile = {
269274 await verifyMAC ( buildV3MacInput ( encodedInner , ctx ) , authKey , mac , 8 ) ;
270275 } ,
271276
272- async frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Promise < Uint8Array > {
277+ frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Uint8Array {
273278 const result = new Uint8Array ( encodedInner . byteLength + 1 + mac . byteLength ) ;
274279 result [ 0 ] = V3_VERSION_BYTE ;
275280 result . set ( encodedInner , 1 ) ;
276281 result . set ( new Uint8Array ( mac ) , encodedInner . byteLength + 1 ) ;
277282 return result ;
278283 } ,
279284
280- async parseMessage ( bytes : ArrayBuffer ) : Promise < ParsedRatchetMessage > {
285+ parseMessage ( bytes : ArrayBuffer ) : ParsedRatchetMessage {
281286 const version = new Uint8Array ( bytes ) [ 0 ] ;
282287 if ( ( version & 0xf ) > 3 || version >> 4 < 3 ) {
283288 throw new Error ( "Incompatible version number on WhisperMessage" ) ;
284289 }
285290 const encodedInner = new Uint8Array ( bytes . slice ( 1 , bytes . byteLength - 8 ) ) ;
286291 const mac = bytes . slice ( bytes . byteLength - 8 , bytes . byteLength ) ;
287292
288- const { WhisperMessage } = await loadProtocolMessages ( ) ;
293+ const { WhisperMessage } = loadProtocolMessages ( ) ;
289294 const message = WhisperMessage . decode ( encodedInner ) as unknown as WhisperMessageProto ;
290295 return {
291296 ephemeralKey : toExactBuffer ( message . ephemeralKey ) ,
@@ -301,7 +306,7 @@ const OMEMO_0_3_0: ProtocolProfile = {
301306 parts : KeyExchangeParts ,
302307 framedMessage : Uint8Array
303308 ) : Promise < Uint8Array > {
304- const { PreKeyWhisperMessage } = await loadProtocolMessages ( ) ;
309+ const { PreKeyWhisperMessage } = loadProtocolMessages ( ) ;
305310 const preKeyMsg = PreKeyWhisperMessage . create ( {
306311 baseKey : new Uint8Array ( parts . baseKey ) ,
307312 identityKey : new Uint8Array ( parts . ourIdentityKey . pubKey ) ,
@@ -322,7 +327,7 @@ const OMEMO_0_3_0: ProtocolProfile = {
322327 if ( ( version & 0xf ) > 3 || version >> 4 < 3 ) {
323328 throw new Error ( "Incompatible version number on PreKeyWhisperMessage" ) ;
324329 }
325- const { PreKeyWhisperMessage } = await loadProtocolMessages ( ) ;
330+ const { PreKeyWhisperMessage } = loadProtocolMessages ( ) ;
326331 const proto = PreKeyWhisperMessage . decode (
327332 new Uint8Array ( bytes . slice ( 1 ) )
328333 ) as unknown as PreKeyWhisperMessageProto ;
@@ -372,8 +377,8 @@ const OMEMO_2: ProtocolProfile = {
372377 rootChainInfo : "OMEMO Root Chain" ,
373378 messageKeyInfo : "OMEMO Message Key Material" ,
374379
375- async encodeInner ( parts : RatchetMessageParts ) : Promise < Uint8Array > {
376- const { OMEMOMessage } = await loadOMEMOMessages ( ) ;
380+ encodeInner ( parts : RatchetMessageParts ) : Uint8Array {
381+ const { OMEMOMessage } = loadOMEMOMessages ( ) ;
377382 // dh_pub is the raw 32-byte curve key (RFC 7748), without the 0x05 prefix.
378383 const msg = OMEMOMessage . create ( {
379384 n : parts . counter ,
@@ -410,17 +415,17 @@ const OMEMO_2: ProtocolProfile = {
410415 await verifyMAC ( macInput , authKey , mac , 16 ) ;
411416 } ,
412417
413- async frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Promise < Uint8Array > {
414- const { OMEMOAuthenticatedMessage } = await loadOMEMOMessages ( ) ;
418+ frameMessage ( encodedInner : Uint8Array , mac : ArrayBuffer ) : Uint8Array {
419+ const { OMEMOAuthenticatedMessage } = loadOMEMOMessages ( ) ;
415420 const authMsg = OMEMOAuthenticatedMessage . create ( {
416421 mac : new Uint8Array ( mac ) ,
417422 message : encodedInner ,
418423 } ) ;
419424 return OMEMOAuthenticatedMessage . encode ( authMsg ) . finish ( ) ;
420425 } ,
421426
422- async parseMessage ( bytes : ArrayBuffer ) : Promise < ParsedRatchetMessage > {
423- const { OMEMOMessage, OMEMOAuthenticatedMessage } = await loadOMEMOMessages ( ) ;
427+ parseMessage ( bytes : ArrayBuffer ) : ParsedRatchetMessage {
428+ const { OMEMOMessage, OMEMOAuthenticatedMessage } = loadOMEMOMessages ( ) ;
424429 const authMsg = OMEMOAuthenticatedMessage . decode ( new Uint8Array ( bytes ) ) as unknown as {
425430 mac : Uint8Array ;
426431 message : Uint8Array ;
@@ -441,7 +446,7 @@ const OMEMO_2: ProtocolProfile = {
441446 parts : KeyExchangeParts ,
442447 framedMessage : Uint8Array
443448 ) : Promise < Uint8Array > {
444- const { OMEMOAuthenticatedMessage, OMEMOKeyExchange } = await loadOMEMOMessages ( ) ;
449+ const { OMEMOAuthenticatedMessage, OMEMOKeyExchange } = loadOMEMOMessages ( ) ;
445450 // ik is the 32-byte Ed25519 form of our identity key; ek is the raw 32-byte curve base key.
446451 const ik = await internalCrypto . curvePubKeyToEd25519PubKey ( parts . ourIdentityKey . pubKey ) ;
447452 // The profile interface frames messages as bytes (opaque for 0.3.0), so we
@@ -460,7 +465,7 @@ const OMEMO_2: ProtocolProfile = {
460465 } ,
461466
462467 async parseKeyExchange ( bytes : ArrayBuffer ) : Promise < ParsedKeyExchange > {
463- const { OMEMOAuthenticatedMessage, OMEMOKeyExchange } = await loadOMEMOMessages ( ) ;
468+ const { OMEMOAuthenticatedMessage, OMEMOKeyExchange } = loadOMEMOMessages ( ) ;
464469 const proto = OMEMOKeyExchange . decode (
465470 new Uint8Array ( bytes )
466471 ) as unknown as OMEMOKeyExchangeProto ;
0 commit comments