signer.mx raw

   1  //:build !wasm
   2  
   3  package signer
   4  
   5  // HasSigner returns true if window.nostr (NIP-07) is available.
   6  func HasSigner() (ok bool) { panic("jsbridge") }
   7  
   8  // HasMLS returns true if window.nostr.mls (Smesh Signer MLS) is available.
   9  func HasMLS() (ok bool) { panic("jsbridge") }
  10  
  11  // GetPublicKey requests the public key from the browser extension.
  12  // Calls fn with hex pubkey on success, empty string on failure.
  13  func GetPublicKey(fn func(string)) { panic("jsbridge") }
  14  
  15  // SignEvent signs a serialized nostr event via NIP-07.
  16  // Calls fn with the signed event JSON on success, empty string on failure.
  17  func SignEvent(eventJSON string, fn func(string)) { panic("jsbridge") }
  18  
  19  // GetSharedSecret computes ECDH(user_seckey, peerPubkey) and returns
  20  // the shared secret as hex via fn. Used for IDB encryption key derivation.
  21  func GetSharedSecret(peerPubkey string, fn func(string)) { panic("jsbridge") }
  22  
  23  // Nip44Decrypt decrypts NIP-44 ciphertext via the browser extension.
  24  func Nip44Decrypt(peerPubkey, ciphertext string, fn func(string)) { panic("jsbridge") }
  25  
  26  // Nip44Encrypt encrypts plaintext via NIP-44 through the browser extension.
  27  func Nip44Encrypt(peerPubkey, plaintext string, fn func(string)) { panic("jsbridge") }
  28  
  29  // --- Smesh management API (window.nostr.musiquay) ---
  30  
  31  // IsInstalled checks whether the musiquay signer extension is present.
  32  // Calls fn(true) if window.nostr.musiquay exists.
  33  func IsInstalled(fn func(bool)) { panic("jsbridge") }
  34  
  35  // GetVaultStatus returns "none", "locked", or "unlocked".
  36  func GetVaultStatus(fn func(string)) { panic("jsbridge") }
  37  
  38  // CreateVault creates a new vault with the given password.
  39  func CreateVault(password string, fn func(bool)) { panic("jsbridge") }
  40  
  41  // UnlockVault unlocks the vault with the given password.
  42  func UnlockVault(password string, fn func(bool)) { panic("jsbridge") }
  43  
  44  // LastUnlockError returns the diagnostic reason for the most recent unlock
  45  // failure. One of: "" (no error), "no-vault", "no-hash", "wrong-password",
  46  // "bad-iv", "kdf-failed", "decrypt-failed".
  47  func LastUnlockError(fn func(string)) { panic("jsbridge") }
  48  
  49  // LockVault locks the vault.
  50  func LockVault(fn func()) { panic("jsbridge") }
  51  
  52  // ListIdentities returns a JSON array of identities.
  53  func ListIdentities(fn func(string)) { panic("jsbridge") }
  54  
  55  // AddIdentity imports an nsec into the vault.
  56  func AddIdentity(nsec string, fn func(bool)) { panic("jsbridge") }
  57  
  58  // NsecLogin sets up an in-memory identity from an nsec without vault crypto.
  59  func NsecLogin(nsec string, fn func(bool)) { panic("jsbridge") }
  60  
  61  // SwitchIdentity sets the active identity by pubkey.
  62  func SwitchIdentity(pubkey string, fn func(bool)) { panic("jsbridge") }
  63  
  64  // ExportVault re-encrypts the vault with the given password and returns it.
  65  func ExportVault(password string, fn func(string)) { panic("jsbridge") }
  66  
  67  // ImportVault imports an encrypted vault data string.
  68  func ImportVault(data string, fn func(bool)) { panic("jsbridge") }
  69  
  70  // RemoveIdentity removes an identity by pubkey.
  71  func RemoveIdentity(pubkey string, fn func(bool)) { panic("jsbridge") }
  72  
  73  // --- HD keychain ---
  74  
  75  // GenerateMnemonic generates a 12-word BIP39 mnemonic (preview only, not stored).
  76  func GenerateMnemonic(fn func(string)) { panic("jsbridge") }
  77  
  78  // ValidateMnemonic checks if a mnemonic is valid BIP39.
  79  func ValidateMnemonic(mnemonic string, fn func(bool)) { panic("jsbridge") }
  80  
  81  // CreateHDVault creates an HD vault from `mnemonic` (or generates a fresh one
  82  // if mnemonic == "") and derives the first identity. fn receives the mnemonic
  83  // on success, empty string on failure. The WASM signer rejects non-empty input
  84  // that is not a valid BIP-39 phrase to prevent a PBKDF2-derived deterministic
  85  // seed from arbitrary strings.
  86  func CreateHDVault(password, mnemonic string, fn func(string)) { panic("jsbridge") }
  87  
  88  // RestoreHDVault restores an HD vault from an existing mnemonic.
  89  // The third (label) parameter is currently ignored by the WASM signer; pass "".
  90  func RestoreHDVault(password, mnemonic, label string, fn func(bool)) { panic("jsbridge") }
  91  
  92  // DeriveIdentity derives the identity at the given account index from the
  93  // active HD keychain. fn receives the hex pubkey on success, empty string on
  94  // failure. The argument is sent as a string; the WASM signer extracts the
  95  // integer account number from it (digits only, leading non-digits ignored).
  96  // Pass a plain decimal string like "1" or "42" - arbitrary text falls back to 0.
  97  func DeriveIdentity(accountStr string, fn func(string)) { panic("jsbridge") }
  98  
  99  // GetMnemonic returns the decrypted mnemonic if the vault is HD and unlocked.
 100  func GetMnemonic(fn func(string)) { panic("jsbridge") }
 101  
 102  // ProbeAccount derives the key at the given account index without adding it.
 103  // Calls fn with the hex pubkey, or empty string on failure.
 104  func ProbeAccount(index int32, fn func(string)) { panic("jsbridge") }
 105  
 106  // IsHD returns true if the unlocked vault is HD-based.
 107  func IsHD(fn func(bool)) { panic("jsbridge") }
 108  
 109  // ResetExtension wipes the vault and all keys from the extension.
 110  func ResetExtension(fn func(bool)) { panic("jsbridge") }
 111  
 112  // --- NWC wallet connections ---
 113  
 114  // NwcList returns a JSON array of connections: [{id,alias,walletPubkey,relayURL,clientPubkey,createdAt}].
 115  func NwcList(fn func(string)) { panic("jsbridge") }
 116  
 117  // NwcAdd parses a nostr+walletconnect:// URI, stores it, and calls fn with the id (or empty on failure).
 118  func NwcAdd(uri, alias string, createdAt int64, fn func(string)) { panic("jsbridge") }
 119  
 120  // NwcRemove deletes a connection by id.
 121  func NwcRemove(id string, fn func(bool)) { panic("jsbridge") }
 122  
 123  // NwcBuildRequest builds a signed kind:23194 NWC request event.
 124  // method is the NWC method name, paramsJSON is a JSON object string (or "{}").
 125  // encryption is "nip04" or "nip44". Returns the signed event JSON or empty on failure.
 126  func NwcBuildRequest(id, method, paramsJSON, encryption string, createdAt int64, fn func(string)) {
 127  	panic("jsbridge")
 128  }
 129  
 130  // NwcParseResponse decrypts a kind:23195 response ciphertext.
 131  // Returns plaintext JSON or empty on failure.
 132  func NwcParseResponse(id, ciphertext, encryption string, fn func(string)) { panic("jsbridge") }
 133  
 134  // OnStateChange registers a persistent callback that fires whenever signer state
 135  // changes (vault status, active pubkey). The callback receives a JSON object:
 136  // {"installed":bool,"vaultStatus":"none"|"locked"|"unlocked","pubkey":"hex"}.
 137  // The callback is NOT one-shot - it stays registered and fires on each change.
 138  // Fires once immediately with current state.
 139  func OnStateChange(fn func(string)) { panic("jsbridge") }
 140