StaticsignSigns a value under a scope.
The shared secret. Any sufficiently random value; reusing an existing API token is fine and saves operating a second secret.
What this token is for, e.g. session/resume/v1.
The value being signed.
The signature, hex-encoded. An empty string when secret is
unset, which callers should read as "cannot issue" rather than as a
token.
The scope is domain separation, and it is not optional decoration. Two
different kinds of token signed with the same secret and no scope are
interchangeable — a signature issued for one purpose verifies for the
other, and whichever check is laxer becomes the one that matters. Give
every use its own scope, and version it (.../v1), so changing what a
token covers invalidates the old ones instead of silently accepting them.
StaticverifyChecks a token against a value and scope.
The shared secret the token was signed with.
The scope the token was issued under. Must match exactly.
The value being claimed.
The token presented.
true only when the token was issued for that value under that
scope with that secret.
Stateless signed tokens over HMAC-SHA-256.
Remarks
For the case where a value has to travel through somewhere you do not control — a query string, a URL fragment, a cookie, a redirect — and come back unmodified. The signature is verified rather than looked up, so issuing and checking one costs no storage read, nothing accumulates, and nothing has to be expired.
What this is not: it does not hide the value, it proves the value is one you issued. Anyone holding the token can read what it covers. And because there is no stored record, a token cannot be revoked before whatever bound it expires — build an expiry into the signed value when that matters.
Reach for it when an identifier alone is doing work it cannot do. An unguessable id is not a secret: it travels in URLs and therefore into access logs, proxies, and referrer headers. A signature over that id is what makes presenting it evidence of anything.
Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.0.0