signer_wasm.mx raw

   1  //:build wasm
   2  
   3  package signer
   4  
   5  import (
   6  	"git.smesh.lol/musiquay/web/common/jsbridge/callback"
   7  	"unsafe"
   8  )
   9  
  10  //:wasmimport bridge signer_has_signer
  11  func wasmHasSigner() (n int32)
  12  
  13  //:wasmimport bridge signer_has_mls
  14  func wasmHasMLS() (n int32)
  15  
  16  //:wasmimport bridge signer_get_public_key
  17  func wasmGetPublicKey(cbID int32)
  18  
  19  //:wasmimport bridge signer_sign_event
  20  func wasmSignEvent(ptr *byte, length int32, capacity int32, cbID int32)
  21  
  22  //:wasmimport bridge signer_get_shared_secret
  23  func wasmGetSharedSecret(ptr *byte, length int32, capacity int32, cbID int32)
  24  
  25  //:wasmimport bridge signer_nip44_decrypt
  26  func wasmNip44Decrypt(pkPtr *byte, pkLen int32, pkCap int32, ctPtr *byte, ctLen int32, ctCap int32, cbID int32)
  27  
  28  //:wasmimport bridge signer_nip44_encrypt
  29  func wasmNip44Encrypt(pkPtr *byte, pkLen int32, pkCap int32, ptPtr *byte, ptLen int32, ptCap int32, cbID int32)
  30  
  31  //:wasmimport bridge signer_is_installed
  32  func wasmIsInstalled(cbID int32)
  33  
  34  //:wasmimport bridge signer_get_vault_status
  35  func wasmGetVaultStatus(cbID int32)
  36  
  37  //:wasmimport bridge signer_create_vault
  38  func wasmCreateVault(ptr *byte, length int32, capacity int32, cbID int32)
  39  
  40  //:wasmimport bridge signer_unlock_vault
  41  func wasmUnlockVault(ptr *byte, length int32, capacity int32, cbID int32)
  42  
  43  //:wasmimport bridge signer_last_unlock_error
  44  func wasmLastUnlockError(cbID int32)
  45  
  46  //:wasmimport bridge signer_lock_vault
  47  func wasmLockVault(cbID int32)
  48  
  49  //:wasmimport bridge signer_list_identities
  50  func wasmListIdentities(cbID int32)
  51  
  52  //:wasmimport bridge signer_add_identity
  53  func wasmAddIdentity(ptr *byte, length int32, capacity int32, cbID int32)
  54  
  55  //:wasmimport bridge signer_nsec_login
  56  func wasmNsecLogin(ptr *byte, length int32, capacity int32, cbID int32)
  57  
  58  //:wasmimport bridge signer_switch_identity
  59  func wasmSwitchIdentity(ptr *byte, length int32, capacity int32, cbID int32)
  60  
  61  //:wasmimport bridge signer_export_vault
  62  func wasmExportVault(ptr *byte, length int32, capacity int32, cbID int32)
  63  
  64  //:wasmimport bridge signer_import_vault
  65  func wasmImportVault(ptr *byte, length int32, capacity int32, cbID int32)
  66  
  67  //:wasmimport bridge signer_remove_identity
  68  func wasmRemoveIdentity(ptr *byte, length int32, capacity int32, cbID int32)
  69  
  70  //:wasmimport bridge signer_generate_mnemonic
  71  func wasmGenerateMnemonic(cbID int32)
  72  
  73  //:wasmimport bridge signer_validate_mnemonic
  74  func wasmValidateMnemonic(ptr *byte, length int32, capacity int32, cbID int32)
  75  
  76  //:wasmimport bridge signer_create_hd_vault
  77  func wasmCreateHDVault(pwPtr *byte, pwLen int32, pwCap int32, mnPtr *byte, mnLen int32, mnCap int32, cbID int32)
  78  
  79  //:wasmimport bridge signer_restore_hd_vault
  80  func wasmRestoreHDVault(pwPtr *byte, pwLen int32, pwCap int32, mnPtr *byte, mnLen int32, mnCap int32, lblPtr *byte, lblLen int32, lblCap int32, cbID int32)
  81  
  82  //:wasmimport bridge signer_derive_identity
  83  func wasmDeriveIdentity(ptr *byte, length int32, capacity int32, cbID int32)
  84  
  85  //:wasmimport bridge signer_get_mnemonic
  86  func wasmGetMnemonic(cbID int32)
  87  
  88  //:wasmimport bridge signer_probe_account
  89  func wasmProbeAccount(index int32, cbID int32)
  90  
  91  //:wasmimport bridge signer_is_hd
  92  func wasmIsHD(cbID int32)
  93  
  94  //:wasmimport bridge signer_reset_extension
  95  func wasmResetExtension(cbID int32)
  96  
  97  //:wasmimport bridge signer_nwc_list
  98  func wasmNwcList(cbID int32)
  99  
 100  //:wasmimport bridge signer_nwc_add
 101  func wasmNwcAdd(uriPtr *byte, uriLen int32, uriCap int32, aliasPtr *byte, aliasLen int32, aliasCap int32, createdAt int64, cbID int32)
 102  
 103  //:wasmimport bridge signer_nwc_remove
 104  func wasmNwcRemove(ptr *byte, length int32, capacity int32, cbID int32)
 105  
 106  //:wasmimport bridge signer_nwc_build_request
 107  func wasmNwcBuildRequest(idPtr *byte, idLen int32, idCap int32, methodPtr *byte, methodLen int32, methodCap int32, paramsPtr *byte, paramsLen int32, paramsCap int32, encPtr *byte, encLen int32, encCap int32, createdAt int64, cbID int32)
 108  
 109  //:wasmimport bridge signer_nwc_parse_response
 110  func wasmNwcParseResponse(idPtr *byte, idLen int32, idCap int32, ctPtr *byte, ctLen int32, ctCap int32, encPtr *byte, encLen int32, encCap int32, cbID int32)
 111  
 112  //:wasmimport bridge signer_on_state_change
 113  func wasmOnStateChange(cbID int32)
 114  
 115  //:wasmimport bridge signer_ecdh_with_secret
 116  func wasmEcdhWithSecret(skPtr *byte, skLen int32, skCap int32, pkPtr *byte, pkLen int32, pkCap int32, cbID int32)
 117  
 118  //:wasmimport bridge signer_sign_with_secret
 119  func wasmSignWithSecret(skPtr *byte, skLen int32, skCap int32, evPtr *byte, evLen int32, evCap int32, cbID int32)
 120  
 121  //:wasmimport bridge signer_pubkey_from_secret
 122  func wasmPubkeyFromSecret(skPtr *byte, skLen int32, skCap int32, cbID int32)
 123  
 124  func HasSigner() (ok bool) { return wasmHasSigner() != 0 }
 125  func HasMLS() (ok bool) { return wasmHasMLS() != 0 }
 126  
 127  func GetPublicKey(fn func(string)) {
 128  	wasmGetPublicKey(callback.RegisterSOnce(fn))
 129  }
 130  
 131  func SignEvent(eventJSON string, fn func(string)) {
 132  	wasmSignEvent(unsafe.StringData(eventJSON), int32(len(eventJSON)), int32(len(eventJSON)), callback.RegisterSOnce(fn))
 133  }
 134  
 135  func GetSharedSecret(peerPubkey string, fn func(string)) {
 136  	wasmGetSharedSecret(unsafe.StringData(peerPubkey), int32(len(peerPubkey)), int32(len(peerPubkey)), callback.RegisterSOnce(fn))
 137  }
 138  
 139  func Nip44Decrypt(peerPubkey, ciphertext string, fn func(string)) {
 140  	wasmNip44Decrypt(
 141  		unsafe.StringData(peerPubkey), int32(len(peerPubkey)), int32(len(peerPubkey)),
 142  		unsafe.StringData(ciphertext), int32(len(ciphertext)), int32(len(ciphertext)),
 143  		callback.RegisterSOnce(fn),
 144  	)
 145  }
 146  
 147  func Nip44Encrypt(peerPubkey, plaintext string, fn func(string)) {
 148  	wasmNip44Encrypt(
 149  		unsafe.StringData(peerPubkey), int32(len(peerPubkey)), int32(len(peerPubkey)),
 150  		unsafe.StringData(plaintext), int32(len(plaintext)), int32(len(plaintext)),
 151  		callback.RegisterSOnce(fn),
 152  	)
 153  }
 154  
 155  func IsInstalled(fn func(bool))       { wasmIsInstalled(callback.RegisterBOnce(fn)) }
 156  func GetVaultStatus(fn func(string))   { wasmGetVaultStatus(callback.RegisterSOnce(fn)) }
 157  
 158  func CreateVault(password string, fn func(bool)) {
 159  	wasmCreateVault(unsafe.StringData(password), int32(len(password)), int32(len(password)), callback.RegisterBOnce(fn))
 160  }
 161  
 162  func UnlockVault(password string, fn func(bool)) {
 163  	wasmUnlockVault(unsafe.StringData(password), int32(len(password)), int32(len(password)), callback.RegisterBOnce(fn))
 164  }
 165  
 166  func LastUnlockError(fn func(string)) {
 167  	wasmLastUnlockError(callback.RegisterSOnce(fn))
 168  }
 169  
 170  func LockVault(fn func())             { wasmLockVault(callback.Register0Once(fn)) }
 171  func ListIdentities(fn func(string))  { wasmListIdentities(callback.RegisterSOnce(fn)) }
 172  
 173  func AddIdentity(nsec string, fn func(bool)) {
 174  	wasmAddIdentity(unsafe.StringData(nsec), int32(len(nsec)), int32(len(nsec)), callback.RegisterBOnce(fn))
 175  }
 176  
 177  func NsecLogin(nsec string, fn func(bool)) {
 178  	wasmNsecLogin(unsafe.StringData(nsec), int32(len(nsec)), int32(len(nsec)), callback.RegisterBOnce(fn))
 179  }
 180  
 181  func SwitchIdentity(pubkey string, fn func(bool)) {
 182  	wasmSwitchIdentity(unsafe.StringData(pubkey), int32(len(pubkey)), int32(len(pubkey)), callback.RegisterBOnce(fn))
 183  }
 184  
 185  func ExportVault(password string, fn func(string)) {
 186  	wasmExportVault(unsafe.StringData(password), int32(len(password)), int32(len(password)), callback.RegisterSOnce(fn))
 187  }
 188  
 189  func ImportVault(data string, fn func(bool)) {
 190  	wasmImportVault(unsafe.StringData(data), int32(len(data)), int32(len(data)), callback.RegisterBOnce(fn))
 191  }
 192  
 193  func RemoveIdentity(pubkey string, fn func(bool)) {
 194  	wasmRemoveIdentity(unsafe.StringData(pubkey), int32(len(pubkey)), int32(len(pubkey)), callback.RegisterBOnce(fn))
 195  }
 196  
 197  func GenerateMnemonic(fn func(string)) { wasmGenerateMnemonic(callback.RegisterSOnce(fn)) }
 198  
 199  func ValidateMnemonic(mnemonic string, fn func(bool)) {
 200  	wasmValidateMnemonic(unsafe.StringData(mnemonic), int32(len(mnemonic)), int32(len(mnemonic)), callback.RegisterBOnce(fn))
 201  }
 202  
 203  func CreateHDVault(password, mnemonic string, fn func(string)) {
 204  	wasmCreateHDVault(
 205  		unsafe.StringData(password), int32(len(password)), int32(len(password)),
 206  		unsafe.StringData(mnemonic), int32(len(mnemonic)), int32(len(mnemonic)),
 207  		callback.RegisterSOnce(fn),
 208  	)
 209  }
 210  
 211  func RestoreHDVault(password, mnemonic, label string, fn func(bool)) {
 212  	wasmRestoreHDVault(
 213  		unsafe.StringData(password), int32(len(password)), int32(len(password)),
 214  		unsafe.StringData(mnemonic), int32(len(mnemonic)), int32(len(mnemonic)),
 215  		unsafe.StringData(label), int32(len(label)), int32(len(label)),
 216  		callback.RegisterBOnce(fn),
 217  	)
 218  }
 219  
 220  func DeriveIdentity(accountStr string, fn func(string)) {
 221  	wasmDeriveIdentity(unsafe.StringData(accountStr), int32(len(accountStr)), int32(len(accountStr)), callback.RegisterSOnce(fn))
 222  }
 223  
 224  func GetMnemonic(fn func(string))      { wasmGetMnemonic(callback.RegisterSOnce(fn)) }
 225  
 226  func ProbeAccount(index int32, fn func(string)) {
 227  	wasmProbeAccount(index, callback.RegisterSOnce(fn))
 228  }
 229  
 230  func IsHD(fn func(bool))              { wasmIsHD(callback.RegisterBOnce(fn)) }
 231  func ResetExtension(fn func(bool))    { wasmResetExtension(callback.RegisterBOnce(fn)) }
 232  func NwcList(fn func(string))         { wasmNwcList(callback.RegisterSOnce(fn)) }
 233  
 234  func NwcAdd(uri, alias string, createdAt int64, fn func(string)) {
 235  	wasmNwcAdd(
 236  		unsafe.StringData(uri), int32(len(uri)), int32(len(uri)),
 237  		unsafe.StringData(alias), int32(len(alias)), int32(len(alias)),
 238  		createdAt,
 239  		callback.RegisterSOnce(fn),
 240  	)
 241  }
 242  
 243  func NwcRemove(id string, fn func(bool)) {
 244  	wasmNwcRemove(unsafe.StringData(id), int32(len(id)), int32(len(id)), callback.RegisterBOnce(fn))
 245  }
 246  
 247  func NwcBuildRequest(id, method, paramsJSON, encryption string, createdAt int64, fn func(string)) {
 248  	wasmNwcBuildRequest(
 249  		unsafe.StringData(id), int32(len(id)), int32(len(id)),
 250  		unsafe.StringData(method), int32(len(method)), int32(len(method)),
 251  		unsafe.StringData(paramsJSON), int32(len(paramsJSON)), int32(len(paramsJSON)),
 252  		unsafe.StringData(encryption), int32(len(encryption)), int32(len(encryption)),
 253  		createdAt,
 254  		callback.RegisterSOnce(fn),
 255  	)
 256  }
 257  
 258  func NwcParseResponse(id, ciphertext, encryption string, fn func(string)) {
 259  	wasmNwcParseResponse(
 260  		unsafe.StringData(id), int32(len(id)), int32(len(id)),
 261  		unsafe.StringData(ciphertext), int32(len(ciphertext)), int32(len(ciphertext)),
 262  		unsafe.StringData(encryption), int32(len(encryption)), int32(len(encryption)),
 263  		callback.RegisterSOnce(fn),
 264  	)
 265  }
 266  
 267  // OnStateChange registers a persistent (non-once) string callback.
 268  // The JS bridge calls it on every state change for the session lifetime.
 269  func OnStateChange(fn func(string)) {
 270  	wasmOnStateChange(callback.RegisterS(fn))
 271  }
 272  
 273  // EcdhWithSecret: ECDH with a caller-provided secret key (not the vault identity).
 274  // secretHex is 64-char hex secret key, peerPubkeyHex is 64-char hex pubkey.
 275  // fn receives the shared secret as 64-char hex, or "" on failure.
 276  func EcdhWithSecret(secretHex, peerPubkeyHex string, fn func(string)) {
 277  	wasmEcdhWithSecret(
 278  		unsafe.StringData(secretHex), int32(len(secretHex)), int32(len(secretHex)),
 279  		unsafe.StringData(peerPubkeyHex), int32(len(peerPubkeyHex)), int32(len(peerPubkeyHex)),
 280  		callback.RegisterSOnce(fn),
 281  	)
 282  }
 283  
 284  // SignWithSecret: sign an event with a caller-provided secret key.
 285  // secretHex is 64-char hex secret key, eventJSON is the unsigned event.
 286  // fn receives the signed event JSON, or "" on failure.
 287  func SignWithSecret(secretHex, eventJSON string, fn func(string)) {
 288  	wasmSignWithSecret(
 289  		unsafe.StringData(secretHex), int32(len(secretHex)), int32(len(secretHex)),
 290  		unsafe.StringData(eventJSON), int32(len(eventJSON)), int32(len(eventJSON)),
 291  		callback.RegisterSOnce(fn),
 292  	)
 293  }
 294  
 295  // PubkeyFromSecret: derive x-only pubkey from a caller-provided secret key.
 296  // secretHex is 64-char hex secret key.
 297  // fn receives the pubkey as 64-char hex, or "" on failure.
 298  func PubkeyFromSecret(secretHex string, fn func(string)) {
 299  	wasmPubkeyFromSecret(
 300  		unsafe.StringData(secretHex), int32(len(secretHex)), int32(len(secretHex)),
 301  		callback.RegisterSOnce(fn),
 302  	)
 303  }
 304