voltaire-effect 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,288 @@
1
+ import { h as SignatureInput, j as RecoverError, A as AddressDerivationError, V as VerifyError, E as EIP712Service } from '../X25519Test-avt1DUgp.js';
2
+ export { k as AesGcmLive, l as AesGcmService, m as AesGcmServiceShape, n as AesGcmTest, s as Bip39Live, B as Bip39Service, t as Bip39ServiceShape, u as Bip39Test, D as Blake2Live, a as Blake2Service, F as Blake2Test, J as Bls12381Live, b as Bls12381Service, L as Bls12381ServiceShape, O as Bn254Error, Q as Bn254Live, c as Bn254Service, T as Bn254ServiceShape, U as Bn254Test, a1 as ChaCha20Poly1305Live, C as ChaCha20Poly1305Service, a2 as ChaCha20Poly1305ServiceShape, a3 as ChaCha20Poly1305Test, f as CryptoLive, g as CryptoTest, ae as EIP712Live, af as EIP712ServiceShape, ag as EIP712Test, a8 as Ed25519Live, d as Ed25519Service, a9 as Ed25519ServiceShape, aa as Ed25519Test, ax as HDNode, ay as HDPath, az as HDWalletError, e as HDWalletService, aA as HDWalletServiceShape, aB as HDWalletTest, aI as HMACLive, H as HMACService, aJ as HMACServiceShape, aK as HMACTest, aw as HardenedDerivationError, aC as InvalidKeyError, aD as InvalidPathError, aE as InvalidSeedError, aO as KeystoreDecryptError, aR as KeystoreLive, K as KeystoreService, aS as KeystoreServiceShape, aT as KeystoreTest, aZ as ModExpLive, a_ as ModExpService, a$ as ModExpServiceShape, b0 as ModExpTest, b3 as P256Live, P as P256Service, b4 as P256ServiceShape, b8 as Ripemd160Live, R as Ripemd160Service, b9 as Ripemd160Test, bb as SHA256Live, S as SHA256Service, bc as SHA256Test, bv as Secp256k1Live, bw as Secp256k1Test, be as SignatureError, bi as Signer, bj as SignersLive, bk as SignersService, bl as SignersServiceShape, bm as SignersTest, bq as X25519Live, br as X25519Service, bs as X25519ServiceShape, bt as X25519Test, o as aesGcmDecrypt, p as aesGcmEncrypt, q as aesGcmGenerateKey, r as aesGcmGenerateNonce, v as bip39GenerateMnemonic, x as bip39MnemonicToSeed, G as blake2Hash, aV as blobToKzgCommitment, I as bls12381Aggregate, M as bls12381Sign, N as bls12381Verify, a4 as chaCha20Poly1305Decrypt, a5 as chaCha20Poly1305Encrypt, a6 as chaCha20Poly1305GenerateKey, a7 as chaCha20Poly1305GenerateNonce, aW as computeBlobKzgProof, ab as ed25519GetPublicKey, ac as ed25519Sign, ad as ed25519Verify, ak as eip712RecoverAddress, an as erc6492UnwrapSignature, ao as erc6492VerifySignature, ap as erc6492WrapSignature, ar as fromMnemonic, bf as fromPrivateKey, as as fromSeed, W as g1Add, X as g1Generator, Y as g1Mul, Z as g2Add, _ as g2Generator, $ as g2Mul, at as generateMnemonic, w as getWordCount, ah as hashDomain, ai as hashStruct, aj as hashTypedData, aq as hdwalletDerive, au as hdwalletGetPrivateKey, av as hdwalletGetPublicKey, aG as hdwalletWithPrivateKey, aH as hdwalletWithSeed, aL as hmacSha256, aM as hmacSha512, aN as keccakHash, aP as keystoreDecrypt, aQ as keystoreEncrypt, aU as keystoreWithDecryptedKey, aF as mnemonicToSeed, y as mnemonicToSeedSync, b1 as modexp, b2 as modexpBytes, aY as modexpCalculateGas, b5 as p256Sign, b6 as p256Verify, a0 as pairingCheck, bu as recover, bd as recoverAddress, bh as recoverTransactionAddress, b7 as ripemd160Hash, ba as sha256Hash, bx as sign, al as signTypedData, aj as signatureHashTypedData, bg as signersGetAddress, z as validateMnemonic, by as verify, aX as verifyBlobKzgProof, am as verifyTypedData, bn as x25519ComputeSecret, bo as x25519GenerateKeyPair, bp as x25519GetPublicKey } from '../X25519Test-avt1DUgp.js';
3
+ import { K as KeccakService } from '../ProviderService-BZ5pqDrD.js';
4
+ export { b as KeccakLive, c as KeccakTest } from '../ProviderService-BZ5pqDrD.js';
5
+ import { Keccak256Hash } from '@tevm/voltaire';
6
+ import * as Effect from 'effect/Effect';
7
+ export { a as KZGError, b as KZGLive, K as KZGService, c as KZGServiceShape, d as KZGTest } from '../KZGService-B7PJerOb.js';
8
+ import { S as Secp256k1Service } from '../Secp256k1Service-OxQ6hJFp.js';
9
+ export { I as InvalidPrivateKeyError, a as InvalidPublicKeyError, b as InvalidRecoveryIdError, c as InvalidSignatureError, d as Secp256k1Error, e as Secp256k1Errors, f as Secp256k1ServiceShape, g as SignOptions, m as mapToSecp256k1Error } from '../Secp256k1Service-OxQ6hJFp.js';
10
+ import { AddressType } from '@tevm/voltaire/Address';
11
+ import { HashType } from '@tevm/voltaire/Hash';
12
+ import { TypedData } from '@tevm/voltaire/EIP712';
13
+ import '@tevm/voltaire/Secp256k1';
14
+ import 'effect/Layer';
15
+ import '@tevm/voltaire/Signature';
16
+ import 'effect/Context';
17
+ import 'effect/Cause';
18
+ import 'effect/Types';
19
+ import '@tevm/voltaire/Bls12381';
20
+ import '@tevm/voltaire/Ed25519';
21
+ import '@tevm/voltaire/Hex';
22
+ import '@tevm/voltaire/HMAC';
23
+ import '@tevm/voltaire/Keystore';
24
+ import '@tevm/voltaire/P256';
25
+ import '@tevm/voltaire/X25519';
26
+
27
+ /**
28
+ * @fileoverview Constant-time comparison utility for cryptographic operations.
29
+ * @module Signature/constantTimeEqual
30
+ * @since 0.0.1
31
+ */
32
+ /**
33
+ * Performs constant-time comparison of two Uint8Arrays.
34
+ *
35
+ * @description
36
+ * This function is resistant to timing attacks - it always takes the same
37
+ * amount of time regardless of where the arrays differ. Use this for
38
+ * security-sensitive comparisons like:
39
+ * - Comparing cryptographic hashes
40
+ * - Comparing MACs/signatures
41
+ * - Comparing addresses for verification
42
+ *
43
+ * The implementation:
44
+ * 1. Returns false immediately if lengths differ (length is public information)
45
+ * 2. XORs all bytes and accumulates - no early exit on mismatch
46
+ * 3. Returns true only if all bytes match (XOR result is 0)
47
+ *
48
+ * @param a - First Uint8Array
49
+ * @param b - Second Uint8Array
50
+ * @returns true if arrays are equal, false otherwise
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { constantTimeEqual } from 'voltaire-effect/crypto/Signature'
55
+ *
56
+ * // Use for cryptographic comparisons
57
+ * const isValid = constantTimeEqual(computedHash, expectedHash)
58
+ * const addressMatch = constantTimeEqual(recoveredAddr, expectedAddr)
59
+ * ```
60
+ *
61
+ * @since 0.0.1
62
+ */
63
+ declare function constantTimeEqual(a: Uint8Array, b: Uint8Array): boolean;
64
+
65
+ /**
66
+ * @fileoverview EIP-191 personal message hashing.
67
+ * @module Signature/hashMessage
68
+ * @since 0.0.1
69
+ */
70
+
71
+ /**
72
+ * Hashes a message according to EIP-191 personal_sign format.
73
+ *
74
+ * @description
75
+ * Creates the hash: keccak256("\x19Ethereum Signed Message:\n" + len + message)
76
+ *
77
+ * This is the standard format used by `personal_sign` in Ethereum wallets.
78
+ * The prefix prevents signed messages from being valid transactions.
79
+ *
80
+ * @param message - The message to hash (string or bytes; strings starting with 0x are treated as hex)
81
+ * @returns Effect containing the 32-byte hash
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * import { hashMessage } from 'voltaire-effect/crypto/Signature'
86
+ * import { KeccakLive } from 'voltaire-effect/crypto'
87
+ * import * as Effect from 'effect/Effect'
88
+ *
89
+ * const program = hashMessage('Hello, Ethereum!').pipe(Effect.provide(KeccakLive))
90
+ * const hash = await Effect.runPromise(program)
91
+ * ```
92
+ *
93
+ * @see https://eips.ethereum.org/EIPS/eip-191
94
+ * @since 0.0.1
95
+ */
96
+ declare const hashMessage: (message: string | Uint8Array) => Effect.Effect<Keccak256Hash, never, KeccakService>;
97
+
98
+ /**
99
+ * @fileoverview Recover Ethereum address from EIP-191 signed message.
100
+ * @module Signature/recoverMessageAddress
101
+ * @since 0.0.1
102
+ */
103
+
104
+ /**
105
+ * Recovers the signer address from an EIP-191 personal_sign signature.
106
+ *
107
+ * @description
108
+ * Hashes the message using EIP-191 format, then recovers the signer address.
109
+ * This is the inverse of `personal_sign` - given a message and signature,
110
+ * we can determine who signed it.
111
+ *
112
+ * The function:
113
+ * 1. Hashes the message with EIP-191 prefix
114
+ * 2. Recovers the public key using ecrecover
115
+ * 3. Derives the address from the public key
116
+ *
117
+ * @param params - Object containing message and signature
118
+ * @param params.message - The original message (string or bytes)
119
+ * @param params.signature - The signature (65 bytes or {r, s, v/yParity})
120
+ * @returns Effect containing the recovered 20-byte address
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * import { recoverMessageAddress } from 'voltaire-effect/crypto/Signature'
125
+ * import { CryptoLive } from 'voltaire-effect/crypto'
126
+ * import * as Effect from 'effect/Effect'
127
+ *
128
+ * const program = recoverMessageAddress({
129
+ * message: 'Hello, Ethereum!',
130
+ * signature: sig
131
+ * }).pipe(Effect.provide(CryptoLive))
132
+ *
133
+ * const address = await Effect.runPromise(program)
134
+ * ```
135
+ *
136
+ * @throws {RecoverError} When public key recovery fails
137
+ * @throws {AddressDerivationError} When address derivation fails
138
+ * @since 0.0.1
139
+ */
140
+ declare const recoverMessageAddress: (params: {
141
+ message: string | Uint8Array;
142
+ signature: SignatureInput;
143
+ }) => Effect.Effect<AddressType, RecoverError | AddressDerivationError, KeccakService | Secp256k1Service>;
144
+
145
+ /**
146
+ * @fileoverview Verify signature against a raw hash.
147
+ * @module Signature/verifyHash
148
+ * @since 0.0.1
149
+ */
150
+
151
+ /**
152
+ * Verifies a signature against a raw message hash.
153
+ *
154
+ * @description
155
+ * Recovers the signer address from the hash and signature, then
156
+ * compares it to the expected address using constant-time comparison.
157
+ *
158
+ * Use this when you already have the message hash (e.g., from EIP-712
159
+ * or custom hashing). For EIP-191 personal_sign, use `verifyMessage` instead.
160
+ *
161
+ * @param params - Object containing hash, signature, and expected address
162
+ * @param params.hash - The 32-byte message hash that was signed
163
+ * @param params.signature - The signature (65 bytes or {r, s, v/yParity})
164
+ * @param params.address - The expected signer address (20 bytes)
165
+ * @returns Effect containing true if signature is valid
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * import { verifyHash } from 'voltaire-effect/crypto/Signature'
170
+ * import { CryptoLive } from 'voltaire-effect/crypto'
171
+ * import * as Effect from 'effect/Effect'
172
+ *
173
+ * const program = verifyHash({
174
+ * hash: messageHash,
175
+ * signature: sig,
176
+ * address: expectedAddress
177
+ * }).pipe(Effect.provide(CryptoLive))
178
+ *
179
+ * const isValid = await Effect.runPromise(program)
180
+ * ```
181
+ *
182
+ * @throws {VerifyError} When signature verification fails
183
+ * @since 0.0.1
184
+ */
185
+ declare const verifyHash: (params: {
186
+ hash: HashType;
187
+ signature: SignatureInput;
188
+ address: AddressType;
189
+ }) => Effect.Effect<boolean, VerifyError, KeccakService | Secp256k1Service>;
190
+
191
+ /**
192
+ * @fileoverview Verify EIP-191 personal_sign signature.
193
+ * @module Signature/verifyMessage
194
+ * @since 0.0.1
195
+ */
196
+
197
+ /**
198
+ * Verifies an EIP-191 personal_sign signature.
199
+ *
200
+ * @description
201
+ * Recovers the signer address from the message and signature, then
202
+ * compares it to the expected address using constant-time comparison.
203
+ *
204
+ * Returns true if the signature was created by the expected address.
205
+ *
206
+ * @param params - Object containing message, signature, and expected address
207
+ * @param params.message - The original message (string or bytes)
208
+ * @param params.signature - The signature (65 bytes or {r, s, v/yParity})
209
+ * @param params.address - The expected signer address (20 bytes)
210
+ * @returns Effect containing true if signature is valid
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * import { verifyMessage } from 'voltaire-effect/crypto/Signature'
215
+ * import { CryptoLive } from 'voltaire-effect/crypto'
216
+ * import * as Effect from 'effect/Effect'
217
+ *
218
+ * const program = verifyMessage({
219
+ * message: 'Hello, Ethereum!',
220
+ * signature: sig,
221
+ * address: expectedAddress
222
+ * }).pipe(Effect.provide(CryptoLive))
223
+ *
224
+ * const isValid = await Effect.runPromise(program)
225
+ * ```
226
+ *
227
+ * @throws {VerifyError} When signature verification fails
228
+ * @since 0.0.1
229
+ */
230
+ declare const verifyMessage: (params: {
231
+ message: string | Uint8Array;
232
+ signature: SignatureInput;
233
+ address: AddressType;
234
+ }) => Effect.Effect<boolean, VerifyError, KeccakService | Secp256k1Service>;
235
+
236
+ /**
237
+ * @fileoverview Verify EIP-712 typed data signature.
238
+ * @module Signature/verifyTypedData
239
+ * @since 0.0.1
240
+ */
241
+
242
+ /**
243
+ * Verifies an EIP-712 typed data signature.
244
+ *
245
+ * @description
246
+ * Hashes the typed data using EIP-712 format, recovers the signer address,
247
+ * and compares it to the expected address using constant-time comparison.
248
+ *
249
+ * Returns true if the signature was created by the expected address.
250
+ *
251
+ * @param params - Object containing typedData, signature, and expected address
252
+ * @param params.typedData - The EIP-712 typed data that was signed
253
+ * @param params.signature - The signature (65 bytes or {r, s, v/yParity})
254
+ * @param params.address - The expected signer address (20 bytes)
255
+ * @returns Effect containing true if signature is valid
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * import { verifyTypedData } from 'voltaire-effect/crypto/Signature'
260
+ * import { CryptoLive } from 'voltaire-effect/crypto'
261
+ * import * as Effect from 'effect/Effect'
262
+ *
263
+ * const typedData = {
264
+ * domain: { name: 'MyDApp', version: '1', chainId: 1 },
265
+ * types: { Person: [{ name: 'name', type: 'string' }] },
266
+ * primaryType: 'Person',
267
+ * message: { name: 'Alice' }
268
+ * }
269
+ *
270
+ * const program = verifyTypedData({
271
+ * typedData,
272
+ * signature: sig,
273
+ * address: expectedAddress
274
+ * }).pipe(Effect.provide(CryptoLive))
275
+ *
276
+ * const isValid = await Effect.runPromise(program)
277
+ * ```
278
+ *
279
+ * @throws {VerifyError} When signature verification fails
280
+ * @since 0.0.1
281
+ */
282
+ declare const verifyTypedData: (params: {
283
+ typedData: TypedData;
284
+ signature: SignatureInput;
285
+ address: AddressType;
286
+ }) => Effect.Effect<boolean, VerifyError, KeccakService | Secp256k1Service | EIP712Service>;
287
+
288
+ export { AddressDerivationError, EIP712Service, KeccakService, RecoverError, Secp256k1Service, SignatureInput, VerifyError, constantTimeEqual, hashMessage, hashMessage as hashPersonalMessage, recoverMessageAddress, verifyHash, verifyMessage, verifyTypedData as verifyTypedDataSignature };