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

Function cryptoKeyFromBytes

packages/effect/src/Schema.ts:14468–14483  ·  view source on GitHub ↗
(
  name: string,
  to: To,
  fromBytes: (bytes: globalThis.Uint8Array) => Effect.Effect<To["Type"], CryptoError_.CryptoError>,
  toBytes: ((key: To["Type"]) => Effect.Effect<globalThis.Uint8Array, CryptoError_.CryptoError>) | undefined
)

Source from the content-addressed store, hash-verified

14466type CryptoKeyOptions = { readonly allowEncode?: boolean | undefined }
14467
14468const cryptoKeyFromBytes = <To extends Codec<any>>(
14469 name: string,
14470 to: To,
14471 fromBytes: (bytes: globalThis.Uint8Array) => Effect.Effect<To["Type"], CryptoError_.CryptoError>,
14472 toBytes: ((key: To["Type"]) => Effect.Effect<globalThis.Uint8Array, CryptoError_.CryptoError>) | undefined
14473): decodeTo<To, Uint8Array> =>
14474 Uint8Array.pipe(decodeTo(
14475 to,
14476 SchemaTransformation.transformEffect({
14477 decode: (bytes, options) => Effect.mapError(fromBytes(bytes), (error) => cryptoIssue(error, bytes, options)),
14478 encode: (key, options) =>
14479 toBytes === undefined
14480 ? cryptoForbiddenEncode(name, key, options)
14481 : Effect.mapError(toBytes(key), (error) => cryptoIssue(error, key, options))
14482 })
14483 ))
14484
14485const CryptoJsonWebKeyMember = optionalKey(String)
14486

Callers 8

MacKeyFromBytesFunction · 0.85
AeadKeyFromBytesFunction · 0.85
CipherKeyFromBytesFunction · 0.85
KeyWrapKeyFromBytesFunction · 0.85

Calls 6

cryptoIssueFunction · 0.85
cryptoForbiddenEncodeFunction · 0.85
decodeToFunction · 0.70
pipeMethod · 0.65
fromBytesFunction · 0.50
toBytesFunction · 0.50

Tested by

no test coverage detected