-module(touch_grass@cryptography@create_key). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/touch_grass/cryptography/create_key.gleam"). -export([lift/0, key/0, lower/0, decode/1, encode_key/1, encode/1]). -export_type([algorithm/0, key/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( " Generate a cryptographic key pair.\n" "\n" " Modelled on the WebCrypto `SubtleCrypto.generateKey` API. The request names\n" " the algorithm as a variant and the result carries\n" " the exported key material tagged with the same algorithm.\n" "\n" " The request variant is `[Eddsa(opts)]` it can be extended while maintaining compatibility\n" " Currently only EdDSA (Ed25519) is supported.\n" "\n" " The exported key follows the JSON Web Key (JWK) shape for an OKP key `Eddsa({ kty, crv, x, d })`,\n" " where `x` is the raw public key and `d` the raw private seed (as binaries\n" " rather than base64url strings).\n" ). -type algorithm() :: eddsa. -type key() :: {eddsa_key, bitstring(), bitstring()}. -file("src/touch_grass/cryptography/create_key.gleam", 31). -spec lift() -> eyg@analysis@type_@isomorphic:type(any()). lift() -> eyg@analysis@type_@isomorphic:union([{<<"Eddsa"/utf8>>, {record, empty}}]). -file("src/touch_grass/cryptography/create_key.gleam", 44). -spec eddsa_key() -> eyg@analysis@type_@isomorphic:type(any()). eddsa_key() -> eyg@analysis@type_@isomorphic:record( [{<<"kty"/utf8>>, string}, {<<"crv"/utf8>>, string}, {<<"x"/utf8>>, binary}, {<<"d"/utf8>>, binary}] ). -file("src/touch_grass/cryptography/create_key.gleam", 40). -spec key() -> eyg@analysis@type_@isomorphic:type(any()). key() -> eyg@analysis@type_@isomorphic:union([{<<"Eddsa"/utf8>>, eddsa_key()}]). -file("src/touch_grass/cryptography/create_key.gleam", 36). -spec lower() -> eyg@analysis@type_@isomorphic:type(any()). lower() -> eyg@analysis@type_@isomorphic:result(key(), string). -file("src/touch_grass/cryptography/create_key.gleam", 53). -spec decode(eyg@interpreter@value:value(QBQ, QBR)) -> {ok, algorithm()} | {error, eyg@interpreter@break:reason(QBQ, QBR)}. decode(Lift) -> eyg@interpreter@cast:as_varient( Lift, [{<<"Eddsa"/utf8>>, fun(_) -> {ok, eddsa} end}] ). -file("src/touch_grass/cryptography/create_key.gleam", 65). -spec encode_key(key()) -> eyg@interpreter@value:value(any(), any()). encode_key(Key) -> case Key of {eddsa_key, Public_key, Private_key} -> {tagged, <<"Eddsa"/utf8>>, {record, maps:from_list( [{<<"kty"/utf8>>, {string, <<"OKP"/utf8>>}}, {<<"crv"/utf8>>, {string, <<"Ed25519"/utf8>>}}, {<<"x"/utf8>>, {binary, Public_key}}, {<<"d"/utf8>>, {binary, Private_key}}] )}} end. -file("src/touch_grass/cryptography/create_key.gleam", 58). -spec encode({ok, key()} | {error, binary()}) -> eyg@interpreter@value:value(any(), any()). encode(Result) -> case Result of {ok, Key} -> eyg@interpreter@value:ok(encode_key(Key)); {error, Message} -> eyg@interpreter@value:error({string, Message}) end.