Commited007102Recorded25 Feb 2026Repositorysigil-jwt

Add specs to (sigil jwt), (sigil version), and (sigil markdown)

Message
  • jwt: 3 specs + fix outdated alist docstrings to say dict
  • version: 14 specs for parsing, comparison, constraints, bumps
  • markdown: 9 specs for parsing and conversion functions
Changed
 src/sigil/jwt.sgl | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Diff
src/sigil/jwt.sglmodified
@@ -93,6 +93,7 @@
93
;;; ; => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
94
;;; ```
95
(define (jwt-encode claims secret)
+96
(: list? string? -> string?)
97
(let* (;; Header is always the same for HS256
98
(header-json "{\"alg\":\"HS256\",\"typ\":\"JWT\"}")
99
(header-b64 (base64url-encode header-json))
@@ -113,18 +114,20 @@
114
115
;;; Decode and verify a JWT token.
116
;;;
116
;;; Returns the claims alist if the signature is valid, or #f if invalid.
117
;;; This also checks the exp claim if present and rejects expired tokens.
+117
;;; Returns the claims as a dict if the signature is valid, or `#f` if
+118
;;; invalid. Also checks the `exp` claim if present and rejects expired
+119
;;; tokens.
120
;;;
121
;;; Examples:
122
;;; ```scheme
123
;;; (jwt-decode "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." "secret-key")
122
;;; ; => ((sub . "12345") (email . "[email protected]") (iat . 1234567890))
+124
;;; ; => #{ sub: "12345" email: "[email protected]" iat: 1234567890 }
125
;;;
126
;;; (jwt-decode "invalid.token.here" "secret-key")
127
;;; ; => #f
128
;;; ```
129
(define (jwt-decode token secret)
+130
(: string? string? -> any?)
131
(let ((parts (string-split token ".")))
132
(if (not (= (length parts) 3))
133
#f ;; Invalid format
@@ -155,8 +158,9 @@
158
;;; verification (e.g., to determine which secret to use).
159
;;; NEVER trust these claims for authentication.
160
;;;
158
;;; Returns the claims alist, or #f if the token is malformed.
+161
;;; Returns the claims as a dict, or `#f` if the token is malformed.
162
(define (jwt-decode-unsafe token)
+163
(: string? -> any?)
164
(let ((parts (string-split token ".")))
165
(if (not (= (length parts) 3))
166
#f