Module: NwcRuby::NIP47::Request
- Defined in:
- lib/nwc_ruby/nip47/request.rb
Overview
Builds a signed kind 23194 request event with the JSON-RPC payload encrypted using either NIP-44 v2 or NIP-04.
Class Method Summary collapse
Class Method Details
.build(method:, params:, client_privkey:, wallet_pubkey:, encryption: :nip44_v2, expiration: nil) ⇒ Event
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nwc_ruby/nip47/request.rb', line 17 def build(method:, params:, client_privkey:, wallet_pubkey:, encryption: :nip44_v2, expiration: nil) payload = JSON.generate({ 'method' => method, 'params' => params }) ciphertext = case encryption when :nip44_v2 then NIP44::Cipher.encrypt(payload, client_privkey, wallet_pubkey) when :nip04 then NIP04::Cipher.encrypt(payload, client_privkey, wallet_pubkey) else raise ArgumentError, "unknown encryption: #{encryption}" end = [['p', wallet_pubkey]] << %w[encryption nip44_v2] if encryption == :nip44_v2 << ['expiration', expiration.to_s] if expiration client_pubkey = Crypto::Keys.public_key_from_private(client_privkey) event = Event.new(pubkey: client_pubkey, kind: Methods::KIND_REQUEST, content: ciphertext, tags: ) event.sign!(client_privkey) end |