MCPcopy Create free account
hub / github.com/Effect-TS/effect / declareCryptoKey

Function declareCryptoKey

packages/effect/src/Schema.ts:14430–14452  ·  view source on GitHub ↗
(
  name: string,
  family: string,
  type: string,
  is: (u: unknown) => boolean,
  algorithm: CryptoAlgorithm
)

Source from the content-addressed store, hash-verified

14428}
14429
14430const declareCryptoKey = <K extends { readonly algorithm: CryptoAlgorithm }>(
14431 name: string,
14432 family: string,
14433 type: string,
14434 is: (u: unknown) => boolean,
14435 algorithm: CryptoAlgorithm
14436): declare<K> => {
14437 const forbidden = SchemaGetter.forbidden<never, unknown>(() =>
14438 `Cannot serialize ${family}.${type} values as JSON, use Schema.${name}FromFormat to read and write keys`
14439 )
14440 return declare<K>(
14441 (u): u is K => is(u) && cryptoAlgorithmEquals((u as K).algorithm, algorithm),
14442 {
14443 expected: `${family}.${type} for ${algorithm.name}`,
14444 representation: { id: `effect/crypto/${name}`, payload: cryptoAlgorithmPayload(algorithm) },
14445 toCodecJson: () => link<K>()(Unknown, { decode: forbidden, encode: forbidden }),
14446 // Keys have no Arbitrary: linking to `Never` makes derivation fail.
14447 toCodecArbitrary: () => link<K>()(Never, { decode: forbidden, encode: forbidden }),
14448 toFormatter: () => (key) => globalThis.String(key),
14449 toEquivalence: () => (self, that) => self === that
14450 }
14451 )
14452}
14453
14454const cryptoIssue = (error: CryptoError_.CryptoError, input: unknown, options: SchemaAST.ParseOptions) =>
14455 new SchemaIssue.InvalidValue({ message: error.message, cause: error }, input, options)

Callers 10

MacKeyFunction · 0.85
AeadKeyFunction · 0.85
CipherKeyFunction · 0.85
SignaturePublicKeyFunction · 0.85
SignaturePrivateKeyFunction · 0.85
KeyAgreementPublicKeyFunction · 0.85
KeyAgreementPrivateKeyFunction · 0.85
KeyWrapKeyFunction · 0.85
KeyWrapPublicKeyFunction · 0.85
KeyWrapPrivateKeyFunction · 0.85

Calls 5

cryptoAlgorithmEqualsFunction · 0.85
cryptoAlgorithmPayloadFunction · 0.85
declareFunction · 0.70
linkFunction · 0.70
isFunction · 0.50

Tested by

no test coverage detected