@@ -16,7 +16,7 @@ import {
16
16
GroupKeyRotationOut ,
17
17
GroupList ,
18
18
GroupOutDataHmacKeys ,
19
- GroupOutDataKeys ,
19
+ GroupOutDataKeys , GroupOutDataSortableKeys ,
20
20
GroupUserListItem ,
21
21
HttpMethod ,
22
22
KeyRotationInput ,
@@ -33,7 +33,9 @@ import {
33
33
group_create_child_group ,
34
34
group_create_connected_group ,
35
35
group_decrypt_hmac_key ,
36
- group_decrypt_key , group_extract_group_data ,
36
+ group_decrypt_key ,
37
+ group_decrypt_sortable_key ,
38
+ group_extract_group_data ,
37
39
group_extract_group_key ,
38
40
group_extract_group_keys ,
39
41
group_finish_key_rotation ,
@@ -48,7 +50,11 @@ import {
48
50
group_prepare_update_rank ,
49
51
prepare_create_searchable ,
50
52
prepare_create_searchable_light ,
51
- prepare_search
53
+ prepare_search ,
54
+ sortable_encrypt_number ,
55
+ sortable_encrypt_raw_number ,
56
+ sortable_encrypt_raw_string ,
57
+ sortable_encrypt_string
52
58
} from "sentc_wasm" ;
53
59
import { Sentc } from "./Sentc" ;
54
60
import { AbstractSymCrypto } from "./crypto/AbstractSymCrypto" ;
@@ -175,6 +181,7 @@ export async function getGroup(
175
181
access_by_parent_group,
176
182
is_connected_group : out . get_is_connected_group ( ) ,
177
183
hmac_keys : [ ] ,
184
+ sortable_keys : [ ] ,
178
185
last_check_time : Date . now ( )
179
186
} ;
180
187
@@ -212,6 +219,12 @@ export async function getGroup(
212
219
const decrypted_hmac_keys = await group_obj . decryptHmacKeys ( hmac_keys ) ;
213
220
group_obj . data . hmac_keys = decrypted_hmac_keys ;
214
221
group_data . hmac_keys = decrypted_hmac_keys ;
222
+
223
+ const sortable_keys = out . get_sortable_keys ( ) ;
224
+
225
+ const decrypted_sortable_keys = await group_obj . decryptSortableKeys ( sortable_keys ) ;
226
+ group_obj . data . sortable_keys = decrypted_sortable_keys ;
227
+ group_data . sortable_keys = decrypted_sortable_keys ;
215
228
216
229
await Promise . all ( [
217
230
//store the group data
@@ -1127,6 +1140,24 @@ export class Group extends AbstractSymCrypto
1127
1140
return keys ;
1128
1141
}
1129
1142
1143
+ public async decryptSortableKeys ( fetchedKeys : GroupOutDataSortableKeys [ ] )
1144
+ {
1145
+ const keys = [ ] ;
1146
+
1147
+ for ( let i = 0 ; i < fetchedKeys . length ; i ++ ) {
1148
+ const fetched_key = fetchedKeys [ i ] ;
1149
+
1150
+ // eslint-disable-next-line no-await-in-loop
1151
+ const group_key = await this . getSymKeyById ( fetched_key . group_key_id ) ;
1152
+
1153
+ const decrypted_key = group_decrypt_sortable_key ( group_key , fetched_key . key_data ) ;
1154
+
1155
+ keys . push ( decrypted_key ) ;
1156
+ }
1157
+
1158
+ return keys ;
1159
+ }
1160
+
1130
1161
private prepareKeys ( page = 0 ) : [ string , boolean ]
1131
1162
{
1132
1163
return prepareKeys ( this . data . keys , page ) ;
@@ -1223,6 +1254,11 @@ export class Group extends AbstractSymCrypto
1223
1254
return this . data . hmac_keys [ 0 ] ;
1224
1255
}
1225
1256
1257
+ getNewestSortableKey ( ) : string
1258
+ {
1259
+ return this . data . sortable_keys [ 0 ] ;
1260
+ }
1261
+
1226
1262
//__________________________________________________________________________________________________________________
1227
1263
1228
1264
/**
@@ -1559,6 +1595,44 @@ export class Group extends AbstractSymCrypto
1559
1595
return handle_server_response ( res ) ;
1560
1596
}
1561
1597
1598
+ //__________________________________________________________________________________________________________________
1599
+ //sortable
1600
+
1601
+ public encryptSortableRawNumber ( number : number )
1602
+ {
1603
+ const key = this . getNewestSortableKey ( ) ;
1604
+
1605
+ return sortable_encrypt_raw_number ( key , BigInt ( number ) ) ;
1606
+ }
1607
+
1608
+ public encryptSortableNumber ( number : number )
1609
+ {
1610
+ const key = this . getNewestSortableKey ( ) ;
1611
+
1612
+ const out = sortable_encrypt_number ( key , BigInt ( number ) ) ;
1613
+
1614
+ return [ out . get_number ( ) , out . get_alg ( ) , out . get_key_id ( ) ] ;
1615
+ }
1616
+
1617
+ public encryptSortableRawString ( data : string )
1618
+ {
1619
+ const key = this . getNewestSortableKey ( ) ;
1620
+
1621
+ return sortable_encrypt_raw_string ( key , data ) ;
1622
+ }
1623
+
1624
+ public encryptSortableString ( data : string )
1625
+ {
1626
+ const key = this . getNewestSortableKey ( ) ;
1627
+
1628
+ const out = sortable_encrypt_string ( key , data ) ;
1629
+
1630
+ return [ out . get_number ( ) , out . get_alg ( ) , out . get_key_id ( ) ] ;
1631
+ }
1632
+
1633
+ //__________________________________________________________________________________________________________________
1634
+ //content
1635
+
1562
1636
public async fetchContent ( data : { last_fetched_item ?: ListContentItem , cat_id ?: string , limit ?: CONTENT_FETCH_LIMIT } ) : Promise < ListContentItem [ ] >
1563
1637
{
1564
1638
const { limit, cat_id, last_fetched_item} = data ;
0 commit comments