3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/shugoi/challenge_url.rb', line 3
def self.build(secret:, difficulty:, context:)
timestamp = Utils.now_sec
nonce = SecureRandom.hex(8)
salt = Utils.hmac_hex(secret, "#{timestamp}:#{nonce}")
prefix = context[:forwarded_prefix].to_s
prefix = "" if prefix == "/"
prefix = prefix.sub(%r{/\z}, "") unless prefix.empty?
path = ChallengePath.sanitize(context[:path].to_s)
query = "ts=#{timestamp}&salt=#{salt}&nonce=#{nonce}&diff=#{difficulty}"
"#{prefix}/__sg_challenge?#{query}&path=#{URI.encode_www_form_component(prefix + path)}"
end
|