NIP-07
> window.nostr capability for web browsers
ブラウザのjavascriptに存在する
window
Objectを拡張して、
window.nostr
内にnostrに関連するメソッドをぶら下げる提案。

具体的にはpubkeyなどを入手したり、eventに対してsign(
署名)する、などがある。

メリットとしてはブラウザ拡張機能に秘密鍵やrelayなどの情報を記録させることで以下の効果が考えられそう?

様々なWeb版クライアントに対して秘密鍵の流出を防ぐ

毎回秘密鍵を入力する手間省ける

対応しているブラウザ拡張

その他のクライアントの情報
防げないこと
XSSがあった場合
操作を一定時間許可した後すぐに何かしらの操作がされてしまうこと
最初は何もせずにユーザの操作を監視して、認可したと判断できたら後にスパムメッセージを投稿、とか
nos2x自体に脆弱性がある場合の秘密鍵の漏洩
実装例
window.nostr
の型定義
仕様
オブジェクトにはこれらのメソッドが定義されていなければならない:
_.js// 公開鍵を16進数表記で返す
async window.nostr.getPublicKey(): string
// イベントのobjectを受け取り、`id`と`pubkey`、`sig`を追加して、それを返す
async window.nostr.signEvent(event: Event): Event
上記の2つのメソッドと異なり、これらの関数の実装は任意である:
_.js// returns a basic map of relay urls to relay policies
async window.nostr.getRelays(): { [url: string]: {read: boolean, write: boolean} }
// returns ciphertext and iv as specified in nip-04
async window.nostr.nip04.encrypt(pubkey, plaintext): string
// takes ciphertext and iv as specified in nip-04
async window.nostr.nip04.decrypt(pubkey, ciphertext): string
// returns ciphertext as specified in nip-44
async window.nostr.nip44.encrypt(pubkey, plaintext): string
// takes ciphertext as specified in nip-44
async window.nostr.nip44.decrypt(pubkey, ciphertext): string