Module: Linzer::JWS

Defined in:
lib/linzer/jws.rb

Overview

Note:

This module requires the jwt and ed25519 gems.

JSON Web Signature (JWS) compatible key support.

This module provides integration with the jwt gem for working with JWK (JSON Web Key) format keys. It enables interoperability with systems using JWS/JWT standards.

Currently supports:

  • EdDSA (Ed25519)

Examples:

Generating a JWS-compatible EdDSA key

key = Linzer.generate_jws_key(algorithm: "EdDSA")

Importing from JWK format

jwk = {
  "kty" => "OKP",
  "crv" => "Ed25519",
  "x" => "...",
  "d" => "..."  # private key component (optional)
}
key = Linzer.jwk_import(jwk)

See Also:

Defined Under Namespace

Classes: Key

Class Method Summary collapse

Class Method Details

.generate_key(algorithm:) ⇒ JWS::Key

Generates a new JWS-compatible key pair.

Examples:

key = Linzer::JWS.generate_key(algorithm: "EdDSA")

Parameters:

  • algorithm (String)

    The JWS algorithm identifier. Currently only "EdDSA" is supported.

Returns:

Raises:

  • (Error)

    If the algorithm is not supported



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/linzer/jws.rb', line 72

def generate_key(algorithm:)
  case String(algorithm)
  when "EdDSA"
    ed25519_keypair = ::Ed25519::SigningKey.generate
    material = JWT::JWK.new(ed25519_keypair)
    Linzer::JWS::Key.new(material)
  else
    err_msg = "Algorithm '#{algorithm}' is unsupported or not implemented yet."
    raise Linzer::Error, err_msg
  end
end

.jwk_import(key, params = {}) ⇒ JWS::Key

Imports a key from JWK (JSON Web Key) format.

Examples:

jwk = JSON.parse(File.read("key.jwk"))
key = Linzer::JWS.jwk_import(jwk, id: "my-key-id")

Parameters:

  • key (Hash)

    The JWK as a Hash with string keys

  • params (Hash) (defaults to: {})

    Additional key parameters

Options Hash (params):

  • :id (String)

    Key identifier (overrides JWK "kid" if present)

Returns:

Raises:

  • (Error)

    If the JWK format is invalid or algorithm unsupported



57
58
59
60
# File 'lib/linzer/jws.rb', line 57

def jwk_import(key, params = {})
  material = JWT::JWK.import(key)
  Linzer::JWS::Key.new(material, params)
end