idb_wasm.mx raw

   1  //go:build wasm
   2  //:build wasm
   3  
   4  package idb
   5  
   6  import (
   7  	"git.smesh.lol/smesh/web/common/jsbridge/callback"
   8  	"unsafe"
   9  )
  10  
  11  //:wasmimport bridge idb_set_enc_key
  12  func wasmSetEncKey(ptr *byte, len int32, cap int32)
  13  
  14  //:wasmimport bridge idb_open
  15  func wasmOpen(cbID int32)
  16  
  17  //:wasmimport bridge idb_save_event
  18  func wasmSaveEvent(ptr *byte, len int32, cap int32, cbID int32)
  19  
  20  //:wasmimport bridge idb_query_events
  21  func wasmQueryEvents(ptr *byte, len int32, cap int32, cbID int32)
  22  
  23  //:wasmimport bridge idb_save_dm
  24  func wasmSaveDM(ptr *byte, len int32, cap int32, cbID int32)
  25  
  26  //:wasmimport bridge idb_query_dms
  27  func wasmQueryDMs(peerPtr *byte, peerLen int32, peerCap int32, limit int32, until int64, cbID int32)
  28  
  29  //:wasmimport bridge idb_get_conversation_list
  30  func wasmGetConversationList(cbID int32)
  31  
  32  //:wasmimport bridge idb_clear_dms_by_peer
  33  func wasmClearDMsByPeer(ptr *byte, len int32, cap int32, cbID int32)
  34  
  35  //:wasmimport bridge idb_set_version
  36  func wasmSetVersion(ptr *byte, len int32, cap int32)
  37  
  38  func SetEncKey(hexKey string) {
  39  	wasmSetEncKey(unsafe.StringData(hexKey), int32(len(hexKey)), int32(len(hexKey)))
  40  }
  41  
  42  func Open(fn func()) {
  43  	wasmOpen(callback.Register0Once(fn))
  44  }
  45  
  46  func SaveEvent(eventJSON string, fn func(bool)) {
  47  	wasmSaveEvent(unsafe.StringData(eventJSON), int32(len(eventJSON)), int32(len(eventJSON)), callback.RegisterBOnce(fn))
  48  }
  49  
  50  func QueryEvents(filterJSON string, fn func(string)) {
  51  	wasmQueryEvents(unsafe.StringData(filterJSON), int32(len(filterJSON)), int32(len(filterJSON)), callback.RegisterSOnce(fn))
  52  }
  53  
  54  func SaveDM(dmJSON string, fn func(string)) {
  55  	wasmSaveDM(unsafe.StringData(dmJSON), int32(len(dmJSON)), int32(len(dmJSON)), callback.RegisterSOnce(fn))
  56  }
  57  
  58  func QueryDMs(peer string, limit int, until int64, fn func(string)) {
  59  	wasmQueryDMs(unsafe.StringData(peer), int32(len(peer)), int32(len(peer)), int32(limit), until, callback.RegisterSOnce(fn))
  60  }
  61  
  62  func GetConversationList(fn func(string)) {
  63  	wasmGetConversationList(callback.RegisterSOnce(fn))
  64  }
  65  
  66  func ClearDMsByPeer(peer string, fn func()) {
  67  	wasmClearDMsByPeer(unsafe.StringData(peer), int32(len(peer)), int32(len(peer)), callback.Register0Once(fn))
  68  }
  69  
  70  func SetVersion(v string) {
  71  	wasmSetVersion(unsafe.StringData(v), int32(len(v)), int32(len(v)))
  72  }
  73  
  74  //:wasmimport bridge idb_mls_save_group
  75  func wasmMlsSaveGroup(gPtr *byte, gLen int32, gCap int32, sPtr *byte, sLen int32, sCap int32, cbID int32)
  76  
  77  //:wasmimport bridge idb_mls_load_group
  78  func wasmMlsLoadGroup(gPtr *byte, gLen int32, gCap int32, cbID int32)
  79  
  80  //:wasmimport bridge idb_mls_list_groups
  81  func wasmMlsListGroups(cbID int32)
  82  
  83  //:wasmimport bridge idb_mls_save_kpp
  84  func wasmMlsSaveKPP(ptr *byte, len int32, cap int32, cbID int32)
  85  
  86  //:wasmimport bridge idb_mls_load_kpp
  87  func wasmMlsLoadKPP(cbID int32)
  88  
  89  func MlsSaveGroup(groupIDHex, stateBase64 string, fn func()) {
  90  	wasmMlsSaveGroup(
  91  		unsafe.StringData(groupIDHex), int32(len(groupIDHex)), int32(len(groupIDHex)),
  92  		unsafe.StringData(stateBase64), int32(len(stateBase64)), int32(len(stateBase64)),
  93  		callback.Register0Once(fn),
  94  	)
  95  }
  96  
  97  func MlsLoadGroup(groupIDHex string, fn func(string)) {
  98  	wasmMlsLoadGroup(unsafe.StringData(groupIDHex), int32(len(groupIDHex)), int32(len(groupIDHex)), callback.RegisterSOnce(fn))
  99  }
 100  
 101  func MlsListGroups(fn func(string)) {
 102  	wasmMlsListGroups(callback.RegisterSOnce(fn))
 103  }
 104  
 105  func MlsSaveKPP(kppBase64 string, fn func()) {
 106  	wasmMlsSaveKPP(unsafe.StringData(kppBase64), int32(len(kppBase64)), int32(len(kppBase64)), callback.Register0Once(fn))
 107  }
 108  
 109  func MlsLoadKPP(fn func(string)) {
 110  	wasmMlsLoadKPP(callback.RegisterSOnce(fn))
 111  }
 112  
 113  //:wasmimport bridge idb_kv_get
 114  func wasmKVGet(sPtr *byte, sLen int32, sCap int32, kPtr *byte, kLen int32, kCap int32, cbID int32)
 115  
 116  //:wasmimport bridge idb_kv_put
 117  func wasmKVPut(sPtr *byte, sLen int32, sCap int32, kPtr *byte, kLen int32, kCap int32, vPtr *byte, vLen int32, vCap int32)
 118  
 119  //:wasmimport bridge idb_kv_get_all
 120  func wasmKVGetAll(sPtr *byte, sLen int32, sCap int32, fnID int32, doneID int32)
 121  
 122  func KVGet(store, key string, fn func(string)) {
 123  	wasmKVGet(
 124  		unsafe.StringData(store), int32(len(store)), int32(len(store)),
 125  		unsafe.StringData(key), int32(len(key)), int32(len(key)),
 126  		callback.RegisterSOnce(fn),
 127  	)
 128  }
 129  
 130  func KVPut(store, key, value string) {
 131  	wasmKVPut(
 132  		unsafe.StringData(store), int32(len(store)), int32(len(store)),
 133  		unsafe.StringData(key), int32(len(key)), int32(len(key)),
 134  		unsafe.StringData(value), int32(len(value)), int32(len(value)),
 135  	)
 136  }
 137  
 138  func KVGetAll(store string, each func(string, string), done func()) {
 139  	fnID := callback.RegisterSS(each)
 140  	doneID := callback.Register0Once(done)
 141  	wasmKVGetAll(unsafe.StringData(store), int32(len(store)), int32(len(store)), fnID, doneID)
 142  }
 143