88// Note in particular that functions _must not_ use a normal parameters list. Instead they must
99// internally destructure the `arguments` list. This is to conform with the webdriver `.execute` API.
1010
11- import { Ciphersuite , CoreCrypto , CredentialType , MlsTransport , MlsTransportData } from "./corecrypto.js" ;
11+ import { Ciphersuite , CoreCrypto , CredentialType , MlsTransport , } from "./corecrypto.js" ;
1212
1313declare global {
1414 interface Window {
@@ -25,11 +25,11 @@ export async function ccNew() {
2525 await initWasmModule ( "autogenerated/wasm-bindgen/" ) ;
2626
2727 let [ clientConfig ] = arguments ;
28- const clientId = new ClientId ( new TextEncoder ( ) . encode ( clientConfig . clientId ) )
28+ const clientId = new ClientId ( new TextEncoder ( ) . encode ( clientConfig . clientId ) . buffer )
2929 const ciphersuites = clientConfig . ciphersuites . map ( ( n ) => ciphersuiteFromU16 ( n ) )
3030
3131 const keyBytes = new Uint8Array ( 32 ) ;
32- const key = new DatabaseKey ( keyBytes ) ;
32+ const key = new DatabaseKey ( keyBytes . buffer ) ;
3333 window . crypto . getRandomValues ( keyBytes ) ;
3434 const database = await openDatabase ( clientConfig . databaseName , key ) ;
3535
@@ -53,26 +53,28 @@ export async function ccNew() {
5353 return "success" ;
5454 } ,
5555 async prepareForTransport ( secret ) {
56- return new MlsTransportData ( secret . data )
56+ return secret . data
5757 }
5858 } ;
5959
6060 await window . cc . provideTransport ( window . deliveryService ) ;
6161}
6262
6363export async function getKeypackage ( ) {
64- const [ kp ] = await window . cc . transaction ( ( ctx ) =>
65- ctx . clientKeypackages ( window . ciphersuite , window . credentialType , 1 )
66- ) ;
64+ const kp = await window . cc . transaction ( async ( ctx ) => {
65+ const credentials = await ctx . findCredentials ( { ciphersuite : window . ciphersuite , credentialType : window . credentialType } ) ;
66+ const credential = credentials [ 0 ]
67+ return await ctx . generateKeypackage ( credential )
68+ } ) ;
6769
68- return new Uint8Array ( kp ) ;
70+ return new Uint8Array ( kp . serialize ( ) ) ;
6971}
7072
7173export async function addClient ( ) {
72- const { ConversationId } = await import ( "./corecrypto.js" ) ;
74+ const { ConversationId, Keypackage } = await import ( "./corecrypto.js" ) ;
7375 const [ cId , kp ] = arguments ;
74- const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) ) ;
75- const keyPackage = Uint8Array . from ( Object . values ( kp ) ) ;
76+ const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) . buffer ) ;
77+ const keyPackage = new Keypackage ( Uint8Array . from ( Object . values ( kp ) ) . buffer ) ;
7678
7779 if ( ! window . cc . conversationExists ( conversationId ) ) {
7880 await window . cc . transaction ( ( ctx ) =>
@@ -86,8 +88,8 @@ export async function addClient() {
8688export async function kickClient ( ) {
8789 const { ConversationId, ClientId } = await import ( "./corecrypto.js" ) ;
8890 const [ cId , clId ] = arguments ;
89- const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) ) ;
90- const clientId = new ClientId ( Uint8Array . from ( Object . values ( clId ) ) ) ;
91+ const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) . buffer ) ;
92+ const clientId = new ClientId ( Uint8Array . from ( Object . values ( clId ) ) . buffer ) ;
9193 await window . cc . transaction ( ( ctx ) =>
9294 ctx . removeClientsFromConversation ( conversationId , [ clientId ] ) ) ;
9395}
@@ -105,8 +107,8 @@ export async function processWelcome() {
105107export async function encryptMessage ( ) {
106108 const { ConversationId } = await import ( "./corecrypto.js" ) ;
107109 const [ cId , cleartext ] = arguments ;
108- const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) ) ;
109- const message = Uint8Array . from ( Object . values ( cleartext ) ) ;
110+ const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) . buffer ) ;
111+ const message = Uint8Array . from ( Object . values ( cleartext ) ) . buffer ;
110112
111113 return new Uint8Array ( await window . cc . transaction ( ( ctx ) =>
112114 ctx . encryptMessage ( conversationId , message ) ) ) ;
@@ -115,8 +117,8 @@ export async function encryptMessage() {
115117export async function decryptMessage ( ) {
116118 const { ConversationId } = await import ( "./corecrypto.js" ) ;
117119 const [ cId , encMessage ] = arguments ;
118- const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) ) ;
119- const encryptedMessage = Uint8Array . from ( Object . values ( encMessage ) ) ;
120+ const conversationId = new ConversationId ( Uint8Array . from ( Object . values ( cId ) ) . buffer ) ;
121+ const encryptedMessage = Uint8Array . from ( Object . values ( encMessage ) ) . buffer ;
120122
121123 const { message } = await window . cc . transaction ( ( ctx ) =>
122124 ctx . decryptMessage ( conversationId , encryptedMessage )
0 commit comments