( name: string, family: string, type: string, is: (u: unknown) => boolean, algorithm: CryptoAlgorithm )
| 14428 | } |
| 14429 | |
| 14430 | const 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 | |
| 14454 | const cryptoIssue = (error: CryptoError_.CryptoError, input: unknown, options: SchemaAST.ParseOptions) => |
| 14455 | new SchemaIssue.InvalidValue({ message: error.message, cause: error }, input, options) |
no test coverage detected