Current section
Files
Jump to
Current section
Files
src/touch_grass@cryptography@sign.erl
-module(touch_grass@cryptography@sign).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/touch_grass/cryptography/sign.gleam").
-export([lift/0, lower/0, decode/1, encode/1]).
-export_type([request/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Produce a signature over a binary with a private key.\n"
"\n"
" Modelled on the WebCrypto `SubtleCrypto.sign(algorithm, key, data)` API. The\n"
" request is a record `{ key, data }` where `key` is a key in the shape\n"
" produced by a successful `CreateKey` effect (`Eddsa({ kty, crv, x, d })`)\n"
" and `data` is the binary to sign. The algorithm is taken from the key's\n"
" variant tag.\n"
).
-type request() :: {eddsa_sign, bitstring(), bitstring()}.
-file("src/touch_grass/cryptography/sign.gleam", 23).
-spec lift() -> eyg@analysis@type_@isomorphic:type(any()).
lift() ->
eyg@analysis@type_@isomorphic:record(
[{<<"key"/utf8>>, touch_grass@cryptography@create_key:key()},
{<<"data"/utf8>>, binary}]
).
-file("src/touch_grass/cryptography/sign.gleam", 27).
-spec lower() -> eyg@analysis@type_@isomorphic:type(any()).
lower() ->
eyg@analysis@type_@isomorphic:result(binary, string).
-file("src/touch_grass/cryptography/sign.gleam", 31).
-spec decode(eyg@interpreter@value:value(QGI, QGJ)) -> {ok, request()} |
{error, eyg@interpreter@break:reason(QGI, QGJ)}.
decode(Lift) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"key"/utf8>>,
fun(Field@0) -> {ok, Field@0} end,
Lift
),
fun(Key) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"data"/utf8>>,
fun eyg@interpreter@cast:as_binary/1,
Lift
),
fun(Data) ->
eyg@interpreter@cast:as_varient(
Key,
[{<<"Eddsa"/utf8>>,
fun(Keydata) ->
gleam@result:'try'(
eyg@interpreter@cast:field(
<<"d"/utf8>>,
fun eyg@interpreter@cast:as_binary/1,
Keydata
),
fun(D) ->
{ok, {eddsa_sign, D, Data}}
end
)
end}]
)
end
)
end
).
-file("src/touch_grass/cryptography/sign.gleam", 42).
-spec encode({ok, bitstring()} | {error, binary()}) -> eyg@interpreter@value:value(any(), any()).
encode(Result) ->
case Result of
{ok, Signature} ->
eyg@interpreter@value:ok({binary, Signature});
{error, Message} ->
eyg@interpreter@value:error({string, Message})
end.