@@ -36,10 +36,17 @@ impl Database {
3636 let encryption_cipher = cx. argument :: < JsString > ( 2 ) ?. value ( & mut cx) ;
3737 let encryption_key = cx. argument :: < JsString > ( 3 ) ?. value ( & mut cx) ;
3838 let busy_timeout = cx. argument :: < JsNumber > ( 4 ) ?. value ( & mut cx) ;
39+ let remote_encryption_key = cx. argument :: < JsString > ( 5 ) ?. value ( & mut cx) ;
3940 let db = if is_remote_path ( & db_path) {
40- let version = version ( "remote" ) ;
4141 trace ! ( "Opening remote database: {}" , db_path) ;
42- libsql:: Database :: open_remote_internal ( db_path. clone ( ) , auth_token, version)
42+ let mut builder = libsql:: Builder :: new_remote ( db_path. clone ( ) , auth_token) ;
43+ if !remote_encryption_key. is_empty ( ) {
44+ let encryption_context = libsql:: EncryptionContext {
45+ key : libsql:: EncryptionKey :: Base64Encoded ( remote_encryption_key) ,
46+ } ;
47+ builder = builder. remote_encryption ( Some ( encryption_context) ) ;
48+ }
49+ rt. block_on ( builder. build ( ) )
4350 } else {
4451 let cipher = libsql:: Cipher :: from_str ( & encryption_cipher) . or_else ( |err| {
4552 throw_libsql_error (
@@ -76,7 +83,7 @@ impl Database {
7683 let sync_period = cx. argument :: < JsNumber > ( 5 ) ?. value ( & mut cx) ;
7784 let read_your_writes = cx. argument :: < JsBoolean > ( 6 ) ?. value ( & mut cx) ;
7885 let offline = cx. argument :: < JsBoolean > ( 7 ) ?. value ( & mut cx) ;
79-
86+ let remote_encryption_key = cx . argument :: < JsString > ( 8 ) ? . value ( & mut cx ) ;
8087 let cipher = libsql:: Cipher :: from_str ( & encryption_cipher) . or_else ( |err| {
8188 throw_libsql_error (
8289 & mut cx,
@@ -103,7 +110,17 @@ impl Database {
103110 ) ;
104111 let rt = runtime ( & mut cx) ?;
105112 let result = if offline {
106- rt. block_on ( libsql:: Builder :: new_synced_database ( db_path, sync_url, sync_auth) . build ( ) )
113+ rt. block_on ( async {
114+ let mut builder =
115+ libsql:: Builder :: new_synced_database ( db_path, sync_url, sync_auth) ;
116+ if !remote_encryption_key. is_empty ( ) {
117+ let encryption_context = libsql:: EncryptionContext {
118+ key : libsql:: EncryptionKey :: Base64Encoded ( remote_encryption_key) ,
119+ } ;
120+ builder = builder. remote_encryption ( Some ( encryption_context) ) ;
121+ }
122+ builder. build ( ) . await
123+ } )
107124 } else {
108125 rt. block_on ( async {
109126 let mut builder = libsql:: Builder :: new_remote_replica ( db_path, sync_url, sync_auth) ;
@@ -113,6 +130,12 @@ impl Database {
113130 if let Some ( sync_period) = sync_period {
114131 builder = builder. sync_interval ( sync_period) ;
115132 }
133+ if !remote_encryption_key. is_empty ( ) {
134+ let encryption_context = libsql:: EncryptionContext {
135+ key : libsql:: EncryptionKey :: Base64Encoded ( remote_encryption_key) ,
136+ } ;
137+ builder = builder. remote_encryption ( Some ( encryption_context) ) ;
138+ }
116139 builder. build ( ) . await
117140 } )
118141 } ;
0 commit comments