Class: Solrengine::Auth::SiwsMessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/solrengine/auth/siws_message_builder.rb

Overview

Builds a SIWS (Sign In With Solana) message following the standard format. Modeled after EIP-4361 (SIWE) adapted for Solana.

Instance Method Summary collapse

Constructor Details

#initialize(domain:, wallet_address:, nonce:, statement: nil, uri: nil, chain_id: nil) ⇒ SiwsMessageBuilder

Returns a new instance of SiwsMessageBuilder.



8
9
10
11
12
13
14
15
16
# File 'lib/solrengine/auth/siws_message_builder.rb', line 8

def initialize(domain:, wallet_address:, nonce:, statement: nil, uri: nil, chain_id: nil)
  @domain = domain
  @wallet_address = wallet_address
  @nonce = nonce
  @statement = statement || "Sign in to #{domain}"
  @uri = uri || "https://#{domain}"
  @chain_id = chain_id || Solrengine::Auth.configuration.chain_id
  @issued_at = Time.current.iso8601
end

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/solrengine/auth/siws_message_builder.rb', line 18

def build
  [
    "#{@domain} wants you to sign in with your Solana account:",
    @wallet_address,
    "",
    @statement,
    "",
    "URI: #{@uri}",
    "Version: 1",
    "Chain ID: #{@chain_id}",
    "Nonce: #{@nonce}",
    "Issued At: #{@issued_at}"
  ].join("\n")
end