Copy
Ask AI
import { KeystoreService, KeystoreLive } from 'voltaire-effect/crypto'
import { Effect } from 'effect'
const result = await Effect.runPromise(
Effect.gen(function* () {
const keystore = yield* KeystoreService
const encrypted = yield* keystore.encrypt(privateKey, 'password', { kdf: 'scrypt', n: 262144 })
const decrypted = yield* keystore.decrypt(encrypted, 'password')
return { encrypted, decrypted }
}).pipe(Effect.provide(KeystoreLive))
)
Error Handling
Copy
Ask AI
program.pipe(
Effect.catchTag('InvalidMacError', () => Effect.fail('Wrong password')),
Effect.catchTag('UnsupportedVersionError', () => Effect.fail('Version not supported')),
Effect.catchTag('UnsupportedKdfError', () => Effect.fail('KDF not supported'))
)
Testing
Copy
Ask AI
import { KeystoreTest } from 'voltaire-effect/crypto'
myProgram.pipe(Effect.provide(KeystoreTest))
// Mock keystore without crypto overhead
Interface
Copy
Ask AI
interface KeystoreServiceShape {
readonly encrypt: (privateKey: PrivateKeyType, password: string, options?: EncryptOptions) => Effect.Effect<KeystoreV3, EncryptionError>
readonly decrypt: (keystore: KeystoreV3, password: string) => Effect.Effect<PrivateKeyType, DecryptError>
}

