mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
bitlogin's widget now implements NIP-04 (nip04Encrypt/nip04Decrypt), closing the one gap left relative to a real NIP-07 extension. bitvid's own nip07Adapter/nsecAdapter/nip46Adapter all already wire this up and report it via signerCapabilities.nip04 -- BitLogin's adapter was the one exception, hardcoded to nip04: false because the widget genuinely didn't support it before. js/nostr/client.js's DM encrypt/decrypt path only offers NIP-04 to a caller when that capability flag is true, so a BitLogin-signed-in user previously had no working legacy-DM path at all. Re-vendored the widget bundle (bitlogin's CHANGELOG.md, 2026-07-21 entry, third one) and updated the one test that hardcoded the old (now-incorrect) capabilities shape. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DY9UMTuF43Ekc2U4E1eDwX
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
// js/nostr/adapters/bitloginAdapter.js
|
|
//
|
|
// Wraps a live <bitlogin-auth> element (already signed in) as a signer matching
|
|
// the same shape as nip07Adapter/nsecAdapter/nip46Adapter. Never touches
|
|
// window.nostr and never sees the private key -- every call is proxied through
|
|
// the element's own crypto Web Worker (see BitLogin's README, "Embedding
|
|
// BitLogin" -> element-scoped methods).
|
|
|
|
export function createBitloginAdapter(widgetElement, pubkey) {
|
|
const signer = {
|
|
type: "bitlogin",
|
|
pubkey: typeof pubkey === "string" ? pubkey : "",
|
|
metadata: async () => null,
|
|
relays: async () => null,
|
|
signEvent: async (event) => widgetElement.signEvent(event),
|
|
nip44Encrypt: async (peerPubkey, plaintext) =>
|
|
widgetElement.nip44Encrypt(peerPubkey, plaintext),
|
|
nip44Decrypt: async (peerPubkey, payload) =>
|
|
widgetElement.nip44Decrypt(peerPubkey, payload),
|
|
nip04Encrypt: async (peerPubkey, plaintext) =>
|
|
widgetElement.nip04Encrypt(peerPubkey, plaintext),
|
|
nip04Decrypt: async (peerPubkey, payload) =>
|
|
widgetElement.nip04Decrypt(peerPubkey, payload),
|
|
requestPermissions: async () => ({ ok: true }),
|
|
destroy: async () => {
|
|
try {
|
|
await widgetElement.logout();
|
|
} catch (error) {
|
|
// The element is permanently mounted and reused for the next sign-in;
|
|
// a failed logout here shouldn't block switching to another signer.
|
|
}
|
|
},
|
|
canSign: () => true,
|
|
capabilities: {
|
|
sign: true,
|
|
nip44: true,
|
|
nip04: true,
|
|
},
|
|
};
|
|
|
|
return signer;
|
|
}
|