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.
- package/dist/KZGService-B7PJerOb.d.ts +146 -0
- package/dist/ProviderService-BZ5pqDrD.d.ts +319 -0
- package/dist/Secp256k1Service-OxQ6hJFp.d.ts +250 -0
- package/dist/X25519Test-avt1DUgp.d.ts +5438 -0
- package/dist/crypto/index.d.ts +288 -0
- package/dist/index-DxwZo3xo.d.ts +28041 -0
- package/dist/index.d.ts +12075 -0
- package/dist/native/index.d.ts +203 -0
- package/dist/primitives/index.d.ts +280 -0
- package/dist/services/index.d.ts +9954 -0
- package/package.json +1 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { HashType } from '@tevm/voltaire/Hash';
|
|
2
|
+
import { Secp256k1SignatureType, Secp256k1PublicKeyType } from '@tevm/voltaire/Secp256k1';
|
|
3
|
+
import * as Context from 'effect/Context';
|
|
4
|
+
import * as Effect from 'effect/Effect';
|
|
5
|
+
import * as effect_Cause from 'effect/Cause';
|
|
6
|
+
import * as effect_Types from 'effect/Types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview Error types and mapping helpers for Secp256k1 Effect wrappers.
|
|
10
|
+
*
|
|
11
|
+
* @module Secp256k1/errors
|
|
12
|
+
* @since 0.0.1
|
|
13
|
+
*/
|
|
14
|
+
declare const Secp256k1Error_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
15
|
+
readonly _tag: "Secp256k1Error";
|
|
16
|
+
} & Readonly<A>;
|
|
17
|
+
/**
|
|
18
|
+
* Base error for all Secp256k1 cryptographic operations.
|
|
19
|
+
*
|
|
20
|
+
* @since 0.0.1
|
|
21
|
+
*/
|
|
22
|
+
declare class Secp256k1Error extends Secp256k1Error_base<{
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly cause?: unknown;
|
|
25
|
+
}> {
|
|
26
|
+
}
|
|
27
|
+
declare const InvalidPrivateKeyError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
28
|
+
readonly _tag: "InvalidPrivateKeyError";
|
|
29
|
+
} & Readonly<A>;
|
|
30
|
+
/**
|
|
31
|
+
* Invalid private key format or value.
|
|
32
|
+
*
|
|
33
|
+
* @since 0.0.1
|
|
34
|
+
*/
|
|
35
|
+
declare class InvalidPrivateKeyError extends InvalidPrivateKeyError_base<{
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly cause?: unknown;
|
|
38
|
+
}> {
|
|
39
|
+
}
|
|
40
|
+
declare const InvalidPublicKeyError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
41
|
+
readonly _tag: "InvalidPublicKeyError";
|
|
42
|
+
} & Readonly<A>;
|
|
43
|
+
/**
|
|
44
|
+
* Invalid public key format or not on curve.
|
|
45
|
+
*
|
|
46
|
+
* @since 0.0.1
|
|
47
|
+
*/
|
|
48
|
+
declare class InvalidPublicKeyError extends InvalidPublicKeyError_base<{
|
|
49
|
+
readonly message: string;
|
|
50
|
+
readonly cause?: unknown;
|
|
51
|
+
}> {
|
|
52
|
+
}
|
|
53
|
+
declare const InvalidSignatureError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
54
|
+
readonly _tag: "InvalidSignatureError";
|
|
55
|
+
} & Readonly<A>;
|
|
56
|
+
/**
|
|
57
|
+
* Invalid signature format or components.
|
|
58
|
+
*
|
|
59
|
+
* @since 0.0.1
|
|
60
|
+
*/
|
|
61
|
+
declare class InvalidSignatureError extends InvalidSignatureError_base<{
|
|
62
|
+
readonly message: string;
|
|
63
|
+
readonly cause?: unknown;
|
|
64
|
+
}> {
|
|
65
|
+
}
|
|
66
|
+
declare const InvalidRecoveryIdError_base: new <A extends Record<string, any> = {}>(args: effect_Types.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & {
|
|
67
|
+
readonly _tag: "InvalidRecoveryIdError";
|
|
68
|
+
} & Readonly<A>;
|
|
69
|
+
/**
|
|
70
|
+
* Recovery ID is invalid for signature recovery.
|
|
71
|
+
*
|
|
72
|
+
* @since 0.0.1
|
|
73
|
+
*/
|
|
74
|
+
declare class InvalidRecoveryIdError extends InvalidRecoveryIdError_base<{
|
|
75
|
+
readonly message: string;
|
|
76
|
+
readonly recoveryId: number;
|
|
77
|
+
readonly cause?: unknown;
|
|
78
|
+
}> {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Union of all Secp256k1 error types.
|
|
82
|
+
*
|
|
83
|
+
* @since 0.0.1
|
|
84
|
+
*/
|
|
85
|
+
type Secp256k1Errors = Secp256k1Error | InvalidPrivateKeyError | InvalidPublicKeyError | InvalidSignatureError | InvalidRecoveryIdError;
|
|
86
|
+
/**
|
|
87
|
+
* Maps unknown errors to specific Secp256k1 error types.
|
|
88
|
+
*
|
|
89
|
+
* @since 0.0.1
|
|
90
|
+
*/
|
|
91
|
+
declare function mapToSecp256k1Error(error: unknown, operation: "sign"): InvalidPrivateKeyError | Secp256k1Error;
|
|
92
|
+
declare function mapToSecp256k1Error(error: unknown, operation: "recover"): InvalidSignatureError | InvalidRecoveryIdError | Secp256k1Error;
|
|
93
|
+
declare function mapToSecp256k1Error(error: unknown, operation: "verify"): InvalidSignatureError | InvalidPublicKeyError | Secp256k1Error;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @fileoverview Secp256k1 service definition for Effect-based applications.
|
|
97
|
+
* Provides the service tag and shape interface for secp256k1 cryptographic operations.
|
|
98
|
+
*
|
|
99
|
+
* @module Secp256k1/Secp256k1Service
|
|
100
|
+
* @since 0.0.1
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Options for secp256k1 signing operations.
|
|
105
|
+
*
|
|
106
|
+
* @description
|
|
107
|
+
* Configuration options for the sign operation, primarily for controlling
|
|
108
|
+
* the RFC 6979 deterministic nonce generation.
|
|
109
|
+
*
|
|
110
|
+
* @example Using extra entropy
|
|
111
|
+
* ```typescript
|
|
112
|
+
* import { sign } from 'voltaire-effect/crypto/Secp256k1'
|
|
113
|
+
*
|
|
114
|
+
* const options: SignOptions = {
|
|
115
|
+
* extraEntropy: crypto.getRandomValues(new Uint8Array(32))
|
|
116
|
+
* }
|
|
117
|
+
* const signature = await Effect.runPromise(sign(hash, key, options))
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @since 0.0.1
|
|
121
|
+
*/
|
|
122
|
+
interface SignOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Additional entropy for RFC 6979 nonce generation.
|
|
125
|
+
*
|
|
126
|
+
* @description
|
|
127
|
+
* When set to a Uint8Array, it is mixed into the nonce generation for
|
|
128
|
+
* additional randomness beyond the deterministic RFC 6979 algorithm.
|
|
129
|
+
* When set to `true`, random entropy is automatically generated.
|
|
130
|
+
* When undefined or `false`, standard RFC 6979 is used.
|
|
131
|
+
*/
|
|
132
|
+
readonly extraEntropy?: Uint8Array | boolean;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Shape interface for secp256k1 cryptographic service operations.
|
|
136
|
+
*
|
|
137
|
+
* @description
|
|
138
|
+
* Defines the contract for secp256k1 ECDSA implementations. This interface
|
|
139
|
+
* specifies the three core operations: sign, recover, and verify.
|
|
140
|
+
*
|
|
141
|
+
* Used as the service shape for {@link Secp256k1Service}.
|
|
142
|
+
*
|
|
143
|
+
* @since 0.0.1
|
|
144
|
+
*/
|
|
145
|
+
interface Secp256k1ServiceShape {
|
|
146
|
+
/**
|
|
147
|
+
* Signs a message hash using secp256k1 ECDSA.
|
|
148
|
+
*
|
|
149
|
+
* @param {HashType} messageHash - The 32-byte message hash to sign
|
|
150
|
+
* @param {Uint8Array} privateKey - The 32-byte private key
|
|
151
|
+
* @param {SignOptions} [options] - Optional signing options for extra entropy
|
|
152
|
+
* @returns {Effect.Effect<Secp256k1SignatureType, InvalidPrivateKeyError | Secp256k1Error>}
|
|
153
|
+
* Effect containing the 65-byte recoverable signature
|
|
154
|
+
*/
|
|
155
|
+
readonly sign: (messageHash: HashType, privateKey: Uint8Array, options?: SignOptions) => Effect.Effect<Secp256k1SignatureType, InvalidPrivateKeyError | Secp256k1Error>;
|
|
156
|
+
/**
|
|
157
|
+
* Recovers the public key from a signature and message hash.
|
|
158
|
+
*
|
|
159
|
+
* @param {Secp256k1SignatureType} signature - The 65-byte recoverable signature
|
|
160
|
+
* @param {HashType} messageHash - The 32-byte message hash
|
|
161
|
+
* @returns {Effect.Effect<Secp256k1PublicKeyType, InvalidSignatureError | InvalidRecoveryIdError | Secp256k1Error>}
|
|
162
|
+
* Effect containing the 65-byte uncompressed public key
|
|
163
|
+
*/
|
|
164
|
+
readonly recover: (signature: Secp256k1SignatureType, messageHash: HashType) => Effect.Effect<Secp256k1PublicKeyType, InvalidSignatureError | InvalidRecoveryIdError | Secp256k1Error>;
|
|
165
|
+
/**
|
|
166
|
+
* Verifies a secp256k1 signature against a message hash and public key.
|
|
167
|
+
*
|
|
168
|
+
* @param {Secp256k1SignatureType} signature - The 65-byte signature
|
|
169
|
+
* @param {HashType} messageHash - The 32-byte message hash
|
|
170
|
+
* @param {Secp256k1PublicKeyType} publicKey - The 65-byte uncompressed public key
|
|
171
|
+
* @returns {Effect.Effect<boolean, InvalidSignatureError | InvalidPublicKeyError | Secp256k1Error>}
|
|
172
|
+
* Effect containing true if signature is valid
|
|
173
|
+
*/
|
|
174
|
+
readonly verify: (signature: Secp256k1SignatureType, messageHash: HashType, publicKey: Secp256k1PublicKeyType) => Effect.Effect<boolean, InvalidSignatureError | InvalidPublicKeyError | Secp256k1Error>;
|
|
175
|
+
}
|
|
176
|
+
declare const Secp256k1Service_base: Context.TagClass<Secp256k1Service, "Secp256k1Service", Secp256k1ServiceShape>;
|
|
177
|
+
/**
|
|
178
|
+
* Secp256k1 cryptographic service for Effect-based applications.
|
|
179
|
+
*
|
|
180
|
+
* @description
|
|
181
|
+
* An Effect Context.Tag that provides the standard Ethereum elliptic curve
|
|
182
|
+
* (secp256k1) for transaction and message signing. The service pattern enables
|
|
183
|
+
* swapping implementations for testing or alternative backends.
|
|
184
|
+
*
|
|
185
|
+
* The service exposes three operations:
|
|
186
|
+
* - `sign` - Create a recoverable signature from a message hash and private key
|
|
187
|
+
* - `recover` - Recover the public key from a signature and message hash
|
|
188
|
+
* - `verify` - Verify a signature against a public key
|
|
189
|
+
*
|
|
190
|
+
* @example Basic usage with Effect.gen
|
|
191
|
+
* ```typescript
|
|
192
|
+
* import { Secp256k1Service, Secp256k1Live } from 'voltaire-effect/crypto/Secp256k1'
|
|
193
|
+
* import * as Effect from 'effect/Effect'
|
|
194
|
+
*
|
|
195
|
+
* const program = Effect.gen(function* () {
|
|
196
|
+
* const secp = yield* Secp256k1Service
|
|
197
|
+
* const sig = yield* secp.sign(messageHash, privateKey)
|
|
198
|
+
* const pubKey = yield* secp.recover(sig, messageHash)
|
|
199
|
+
* return yield* secp.verify(sig, messageHash, pubKey)
|
|
200
|
+
* }).pipe(Effect.provide(Secp256k1Live))
|
|
201
|
+
*
|
|
202
|
+
* const isValid = await Effect.runPromise(program) // true
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example Signing a transaction
|
|
206
|
+
* ```typescript
|
|
207
|
+
* import { Secp256k1Service, Secp256k1Live } from 'voltaire-effect/crypto/Secp256k1'
|
|
208
|
+
* import { KeccakService, KeccakLive } from 'voltaire-effect/crypto/Keccak256'
|
|
209
|
+
* import * as Effect from 'effect/Effect'
|
|
210
|
+
* import * as Layer from 'effect/Layer'
|
|
211
|
+
*
|
|
212
|
+
* const signTx = (txBytes: Uint8Array, privateKey: Uint8Array) =>
|
|
213
|
+
* Effect.gen(function* () {
|
|
214
|
+
* const keccak = yield* KeccakService
|
|
215
|
+
* const secp = yield* Secp256k1Service
|
|
216
|
+
* const txHash = yield* keccak.hash(txBytes)
|
|
217
|
+
* return yield* secp.sign(txHash, privateKey)
|
|
218
|
+
* })
|
|
219
|
+
*
|
|
220
|
+
* const CryptoLive = Layer.merge(KeccakLive, Secp256k1Live)
|
|
221
|
+
* const signature = await Effect.runPromise(signTx(tx, key).pipe(Effect.provide(CryptoLive)))
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @example Error handling
|
|
225
|
+
* ```typescript
|
|
226
|
+
* import { Secp256k1Service, Secp256k1Live } from 'voltaire-effect/crypto/Secp256k1'
|
|
227
|
+
* import * as Effect from 'effect/Effect'
|
|
228
|
+
*
|
|
229
|
+
* const program = Effect.gen(function* () {
|
|
230
|
+
* const secp = yield* Secp256k1Service
|
|
231
|
+
* return yield* secp.sign(messageHash, privateKey)
|
|
232
|
+
* }).pipe(
|
|
233
|
+
* Effect.catchTag('InvalidPrivateKeyError', (e) =>
|
|
234
|
+
* Effect.fail(new Error(`Invalid key: ${e.message}`))
|
|
235
|
+
* ),
|
|
236
|
+
* Effect.provide(Secp256k1Live)
|
|
237
|
+
* )
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @see {@link Secp256k1Live} - Production implementation
|
|
241
|
+
* @see {@link Secp256k1Test} - Test implementation
|
|
242
|
+
* @see {@link sign} - Standalone sign function
|
|
243
|
+
* @see {@link recover} - Standalone recover function
|
|
244
|
+
* @see {@link verify} - Standalone verify function
|
|
245
|
+
* @since 0.0.1
|
|
246
|
+
*/
|
|
247
|
+
declare class Secp256k1Service extends Secp256k1Service_base {
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export { InvalidPrivateKeyError as I, Secp256k1Service as S, InvalidPublicKeyError as a, InvalidRecoveryIdError as b, InvalidSignatureError as c, Secp256k1Error as d, type Secp256k1Errors as e, type Secp256k1ServiceShape as f, type SignOptions as g, mapToSecp256k1Error as m };
|