-
-
Save gpsnmeajp/23a2563ec39d4db43f0f922e5f08de87 to your computer and use it in GitHub Desktop.
HelloNip07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://unpkg.com/nostr-tools/lib/nostr.bundle.js を読み込んでおく | |
// nostor-toolsが署名など実装してくれているので、適切な形で処理するだけ | |
// ブラウザ拡張か何かで、NIP-07に対応しているWebページにinjectionすることで秘密鍵を渡すことなく署名・暗号化が提供できる。 | |
//これは秘密鍵を埋め込んでいる為機密性がない学習用の実装です。 | |
//常用禁止。テスト用アカウントのみ可 | |
const privateKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; | |
window.nostr = { | |
getPublicKey: async function(){ | |
let pubkey = NostrTools.getPublicKey(privateKey); | |
console.log("[helloNip07]", "getPublicKey", pubkey); | |
return pubkey; | |
}, | |
signEvent: async function(event){ | |
event.pubkey = NostrTools.getPublicKey(privateKey); | |
event.id = NostrTools.getEventHash(event); | |
event.sig = NostrTools.signEvent(event,privateKey); | |
console.log("[helloNip07]", "signEvent", event); | |
return event; | |
}, | |
nip04:{ | |
encrypt: async function(pubkey, plaintext){ | |
console.log("[helloNip07]", "encrypt", pubkey, plaintext); | |
return await NostrTools.nip04.encrypt(privateKey, pubkey, plaintext); | |
}, | |
decrypt: async function(pubkey, ciphertext){ | |
console.log("[helloNip07]", "decrypt", pubkey, ciphertext); | |
return await NostrTools.nip04.decrypt(privateKey, pubkey, ciphertext); | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment