Module: Swt3Ai::Fingerprint

Defined in:
lib/swt3_ai/fingerprint.rb

Class Method Summary collapse

Class Method Details

.mint_fingerprint(tenant_id, procedure_id, factor_a, factor_b, factor_c, timestamp_ms) ⇒ Object

Mint an SWT3 fingerprint from the canonical formula.

Returns the first 12 hex characters of:

SHA-256("WITNESS:{tenant}:{proc}:{fa}:{fb}:{fc}:{ts_ms}")

This formula is locked and must produce identical output across all SWT3 SDK implementations (Python, TypeScript, Rust, C#, Ruby).



12
13
14
15
# File 'lib/swt3_ai/fingerprint.rb', line 12

def self.mint_fingerprint(tenant_id, procedure_id, factor_a, factor_b, factor_c, timestamp_ms)
  input = "WITNESS:#{tenant_id}:#{procedure_id}:#{num_str(factor_a)}:#{num_str(factor_b)}:#{num_str(factor_c)}:#{timestamp_ms}"
  sha256_hex(input, 12)
end

.sha256_hex(data, length = 64) ⇒ Object

Compute SHA-256 and return the first N hex characters.



23
24
25
26
# File 'lib/swt3_ai/fingerprint.rb', line 23

def self.sha256_hex(data, length = 64)
  digest = OpenSSL::Digest::SHA256.hexdigest(data.to_s)
  digest[0, [length, 64].min]
end

.sha256_truncated(data, length = 16) ⇒ Object

Compute a truncated SHA-256 hash. Default length is 16 hex characters.



18
19
20
# File 'lib/swt3_ai/fingerprint.rb', line 18

def self.sha256_truncated(data, length = 16)
  sha256_hex(data, length)
end

.timestamp_msObject

Get the current timestamp in milliseconds and epoch seconds.



29
30
31
32
33
# File 'lib/swt3_ai/fingerprint.rb', line 29

def self.timestamp_ms
  ms = (Time.now.to_f * 1000).to_i
  epoch = ms / 1000
  [ms, epoch]
end