Class: AgentAdmit::AppAttestedPresence

Inherits:
Object
  • Object
show all
Defined in:
lib/agentadmit/app_attested_presence.rb

Overview

App-attested presence: a ceremony fact your app attests at token issuance.

Pass an instance to TokensClient#issue_token AFTER verifying and consuming your app's own fresh, purpose-bound WebAuthn/passkey attestation for the mint. The SDK forwards it to the hosted mint as presence true, uv: true, method, verified_at; the hosted service stores it method-prefixed "app:" — the provenance marker that keeps app-attested facts distinct from hosted-witnessed ceremonies.

Honesty ceiling: this is YOUR attestation, recorded and provenance-marked. It is not witnessed by AgentAdmit and not independently verifiable. Only construct one for a ceremony that verified the user with UV (biometric or PIN user verification); verified/uv serialize as literal true and cannot represent anything else — a ceremony without UV carries no presence fact, so simply pass nil.

verified_at must be recent: the hosted service enforces a 10-minute freshness window with 60 seconds of future clock-skew slack. Ruby Time and DateTime always carry an offset, so #iso8601 serializes RFC 3339 with an explicit offset by construction (the hosted contract; offset-less timestamps are rejected with 400).

Constant Summary collapse

METHOD_PATTERN =
/\A[a-z0-9_]+\z/
METHOD_MAX_LENGTH =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, verified_at:) ⇒ AppAttestedPresence

Returns a new instance of AppAttestedPresence.

Parameters:

  • method (String)

    your ceremony mechanism, 1-60 lowercase alphanumeric/underscore characters (e.g. "my_webauthn")

  • verified_at (Time, DateTime)

    when the ceremony completed

Raises:

  • (ArgumentError)

    when method is out of contract or verified_at is not a timestamp — validated at construction, before any request, where the fix is obvious



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/agentadmit/app_attested_presence.rb', line 46

def initialize(method:, verified_at:)
  unless method.is_a?(String) && !method.empty? &&
         method.length <= METHOD_MAX_LENGTH && METHOD_PATTERN.match?(method)
    raise ArgumentError,
          "method must be 1-#{METHOD_MAX_LENGTH} lowercase alphanumeric/underscore " \
          "characters (e.g. 'my_webauthn')"
  end
  unless verified_at.respond_to?(:iso8601)
    raise ArgumentError,
          "verified_at must be a Time or DateTime (the ceremony that authorized " \
          "this mint just happened)"
  end

  @method = method
  @verified_at = verified_at
end

Instance Attribute Details

#methodObject (readonly)

NOTE: a method reader shadows Object#method on instances — the same trade stdlib's Net::HTTPGenericRequest makes; the name matches the wire field.



36
37
38
# File 'lib/agentadmit/app_attested_presence.rb', line 36

def method
  @method
end

#verified_atObject (readonly)

NOTE: a method reader shadows Object#method on instances — the same trade stdlib's Net::HTTPGenericRequest makes; the name matches the wire field.



36
37
38
# File 'lib/agentadmit/app_attested_presence.rb', line 36

def verified_at
  @verified_at
end

Instance Method Details

#to_wireHash

The exact JSON object forwarded to the hosted mint.

Returns:

  • (Hash)


68
69
70
71
72
73
74
75
# File 'lib/agentadmit/app_attested_presence.rb', line 68

def to_wire
  {
    "verified" => true,
    "uv" => true,
    "method" => @method,
    "verified_at" => @verified_at.iso8601
  }
end