ox 0.8.0 → 0.8.2

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/Ed25519/package.json +6 -0
  3. package/X25519/package.json +6 -0
  4. package/_cjs/core/Bls.js +10 -0
  5. package/_cjs/core/Bls.js.map +1 -1
  6. package/_cjs/core/Ed25519.js +53 -0
  7. package/_cjs/core/Ed25519.js.map +1 -0
  8. package/_cjs/core/Keystore.js +65 -5
  9. package/_cjs/core/Keystore.js.map +1 -1
  10. package/_cjs/core/P256.js +23 -0
  11. package/_cjs/core/P256.js.map +1 -1
  12. package/_cjs/core/Secp256k1.js +20 -0
  13. package/_cjs/core/Secp256k1.js.map +1 -1
  14. package/_cjs/core/WebCryptoP256.js +31 -0
  15. package/_cjs/core/WebCryptoP256.js.map +1 -1
  16. package/_cjs/core/X25519.js +45 -0
  17. package/_cjs/core/X25519.js.map +1 -0
  18. package/_cjs/index.js +4 -2
  19. package/_cjs/index.js.map +1 -1
  20. package/_cjs/version.js +1 -1
  21. package/_esm/core/Bls.js +109 -0
  22. package/_esm/core/Bls.js.map +1 -1
  23. package/_esm/core/Ed25519.js +121 -0
  24. package/_esm/core/Ed25519.js.map +1 -0
  25. package/_esm/core/Keystore.js +107 -9
  26. package/_esm/core/Keystore.js.map +1 -1
  27. package/_esm/core/P256.js +54 -2
  28. package/_esm/core/P256.js.map +1 -1
  29. package/_esm/core/Secp256k1.js +50 -0
  30. package/_esm/core/Secp256k1.js.map +1 -1
  31. package/_esm/core/WebCryptoP256.js +72 -0
  32. package/_esm/core/WebCryptoP256.js.map +1 -1
  33. package/_esm/core/X25519.js +97 -0
  34. package/_esm/core/X25519.js.map +1 -0
  35. package/_esm/index.js +85 -4
  36. package/_esm/index.js.map +1 -1
  37. package/_esm/version.js +1 -1
  38. package/_types/core/Bls.d.ts +124 -0
  39. package/_types/core/Bls.d.ts.map +1 -1
  40. package/_types/core/Ed25519.d.ts +156 -0
  41. package/_types/core/Ed25519.d.ts.map +1 -0
  42. package/_types/core/Keystore.d.ts +66 -8
  43. package/_types/core/Keystore.d.ts.map +1 -1
  44. package/_types/core/P256.d.ts +68 -2
  45. package/_types/core/P256.d.ts.map +1 -1
  46. package/_types/core/Secp256k1.d.ts +67 -0
  47. package/_types/core/Secp256k1.d.ts.map +1 -1
  48. package/_types/core/WebCryptoP256.d.ts +76 -1
  49. package/_types/core/WebCryptoP256.d.ts.map +1 -1
  50. package/_types/core/X25519.d.ts +127 -0
  51. package/_types/core/X25519.d.ts.map +1 -0
  52. package/_types/index.d.ts +85 -4
  53. package/_types/index.d.ts.map +1 -1
  54. package/_types/version.d.ts +1 -1
  55. package/core/Bls.ts +150 -0
  56. package/core/Ed25519.ts +237 -0
  57. package/core/Keystore.ts +141 -12
  58. package/core/P256.ts +114 -2
  59. package/core/Secp256k1.ts +110 -0
  60. package/core/WebCryptoP256.ts +141 -1
  61. package/core/X25519.ts +202 -0
  62. package/index.ts +87 -4
  63. package/package.json +11 -1
  64. package/version.ts +1 -1
package/_types/index.d.ts CHANGED
@@ -1310,6 +1310,37 @@ export * as Caches from './core/Caches.js';
1310
1310
  * @category Addresses
1311
1311
  */
1312
1312
  export * as ContractAddress from './core/ContractAddress.js';
1313
+ /**
1314
+ * Utilities for working with Ed25519 signatures and key pairs.
1315
+ *
1316
+ * Ed25519 is a modern elliptic curve signature scheme that provides strong security
1317
+ * guarantees and high performance. It is widely used in various cryptographic applications.
1318
+ *
1319
+ * @example
1320
+ * ### Creating Key Pairs
1321
+ *
1322
+ * ```ts twoslash
1323
+ * import { Ed25519 } from 'ox'
1324
+ *
1325
+ * const { privateKey, publicKey } = Ed25519.createKeyPair()
1326
+ * ```
1327
+ *
1328
+ * @example
1329
+ * ### Signing & Verifying
1330
+ *
1331
+ * ```ts twoslash
1332
+ * import { Ed25519 } from 'ox'
1333
+ *
1334
+ * const { privateKey, publicKey } = Ed25519.createKeyPair()
1335
+ * const payload = '0xdeadbeef'
1336
+ *
1337
+ * const signature = Ed25519.sign({ payload, privateKey })
1338
+ * const isValid = Ed25519.verify({ payload, publicKey, signature })
1339
+ * ```
1340
+ *
1341
+ * @category Crypto
1342
+ */
1343
+ export * as Ed25519 from './core/Ed25519.js';
1313
1344
  /**
1314
1345
  * Utility functions for working with ENS names.
1315
1346
  *
@@ -1529,9 +1560,9 @@ export * as Json from './core/Json.js';
1529
1560
  * Utilities & types for working with [Keystores](https://ethereum.org/en/developers/docs/data-structures-and-encoding/web3-secret-storage).
1530
1561
  *
1531
1562
  * @example
1532
- * ### Encrypting & Decrypting Private Keys
1563
+ * ### Encrypting Private Keys
1533
1564
  *
1534
- * Private keys can be encrypted into a JSON keystore using {@link ox#Keystore.(encrypt:function)} and decrypted using {@link ox#Keystore.(decrypt:function)}:
1565
+ * Private keys can be encrypted into a JSON keystore using {@link ox#Keystore.(encrypt:function)}:
1535
1566
  *
1536
1567
  * ```ts twoslash
1537
1568
  * import { Keystore, Secp256k1 } from 'ox'
@@ -1543,7 +1574,7 @@ export * as Json from './core/Json.js';
1543
1574
  * const [key, opts] = Keystore.pbkdf2({ password: 'testpassword' })
1544
1575
  *
1545
1576
  * // Encrypt the private key.
1546
- * const encrypted = await Keystore.encrypt(privateKey, key, opts)
1577
+ * const keystore = Keystore.encrypt(privateKey, key, opts)
1547
1578
  * // @log: {
1548
1579
  * // @log: "crypto": {
1549
1580
  * // @log: "cipher": "aes-128-ctr",
@@ -1563,10 +1594,26 @@ export * as Json from './core/Json.js';
1563
1594
  * // @log: "id": "...",
1564
1595
  * // @log: "version": 3,
1565
1596
  * // @log: }
1597
+ * ```
1598
+ *
1599
+ * @example
1600
+ * ### Decrypting Private Keys
1601
+ *
1602
+ * Private keys can be decrypted from a JSON keystore using {@link ox#Keystore.(decrypt:function)}:
1603
+ *
1604
+ * ```ts twoslash
1605
+ * // @noErrors
1606
+ * import { Keystore, Secp256k1 } from 'ox'
1607
+ *
1608
+ * const keystore = { crypto: { ... }, id: '...', version: 3 }
1609
+ *
1610
+ * // Derive the key.
1611
+ * const key = Keystore.toKey(keystore, { password: 'testpassword' })
1566
1612
  *
1567
1613
  * // Decrypt the private key.
1568
- * const decrypted = await Keystore.decrypt(encrypted, key)
1614
+ * const decrypted = Keystore.decrypt(keystore, key)
1569
1615
  * // @log: "0x..."
1616
+ *
1570
1617
  * ```
1571
1618
  *
1572
1619
  * @category Crypto
@@ -3432,4 +3479,38 @@ export * as WebCryptoP256 from './core/WebCryptoP256.js';
3432
3479
  * @category Execution Spec
3433
3480
  */
3434
3481
  export * as Withdrawal from './core/Withdrawal.js';
3482
+ /**
3483
+ * Utilities for working with X25519 elliptic curve Diffie-Hellman key agreement.
3484
+ *
3485
+ * X25519 is a high-performance elliptic curve that can be used to perform
3486
+ * Diffie-Hellman key agreement to derive shared secrets between parties.
3487
+ * It is designed for use with the elliptic curve Diffie-Hellman (ECDH) key agreement scheme.
3488
+ *
3489
+ * @example
3490
+ * ### Creating Key Pairs
3491
+ *
3492
+ * ```ts twoslash
3493
+ * import { X25519 } from 'ox'
3494
+ *
3495
+ * const { privateKey, publicKey } = X25519.createKeyPair()
3496
+ * ```
3497
+ *
3498
+ * @example
3499
+ * ### Deriving Shared Secrets
3500
+ *
3501
+ * ```ts twoslash
3502
+ * import { X25519 } from 'ox'
3503
+ *
3504
+ * const { privateKey: privateKeyA } = X25519.createKeyPair()
3505
+ * const { publicKey: publicKeyB } = X25519.createKeyPair()
3506
+ *
3507
+ * const sharedSecret = X25519.getSharedSecret({
3508
+ * privateKey: privateKeyA,
3509
+ * publicKey: publicKeyB
3510
+ * })
3511
+ * ```
3512
+ *
3513
+ * @category Crypto
3514
+ */
3515
+ export * as X25519 from './core/X25519.js';
3435
3516
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,YAAY,EAAE,CAAA;AAEd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kB,MAAM,8BAA8B,CAAA;AAElE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,kBAAkB,MAAM,8BAA8B,CAAA;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAEhD;;;;GAIG;AACH,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AAExD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AAExD;;;;GAIG;AACH,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,MAAM,MAAM,kBAAkB,CAAA"}
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export declare const version = "0.8.0";
2
+ export declare const version = "0.8.2";
3
3
  //# sourceMappingURL=version.d.ts.map
package/core/Bls.ts CHANGED
@@ -70,6 +70,156 @@ export declare namespace aggregate {
70
70
  type ErrorType = Errors.GlobalErrorType
71
71
  }
72
72
 
73
+ /**
74
+ * Creates a new BLS12-381 key pair consisting of a private key and its corresponding public key.
75
+ *
76
+ * - G1 Point (Default):
77
+ * - short (48 bytes)
78
+ * - computes longer G2 Signatures (96 bytes)
79
+ * - G2 Point:
80
+ * - long (96 bytes)
81
+ * - computes short G1 Signatures (48 bytes)
82
+ *
83
+ * @example
84
+ * ### Short G1 Public Keys (Default)
85
+ *
86
+ * ```ts twoslash
87
+ * import { Bls } from 'ox'
88
+ *
89
+ * const { publicKey } = Bls.createKeyPair()
90
+ * // ^?
91
+ *
92
+ *
93
+ *
94
+ *
95
+ *
96
+ *
97
+ *
98
+ * ```
99
+ *
100
+ * @example
101
+ * ### Long G2 Public Keys
102
+ *
103
+ * A G2 Public Key can be derived as a G2 point (96 bytes) using `size: 'long-key:short-sig'`.
104
+ *
105
+ * This will allow you to compute G1 Signatures (48 bytes) with {@link ox#Bls.(sign:function)}.
106
+ *
107
+ * ```ts twoslash
108
+ * import { Bls } from 'ox'
109
+ *
110
+ * const { publicKey } = Bls.createKeyPair({
111
+ * size: 'long-key:short-sig',
112
+ * })
113
+ *
114
+ * publicKey
115
+ * // ^?
116
+ *
117
+ *
118
+ *
119
+ *
120
+ *
121
+ *
122
+ *
123
+ *
124
+ *
125
+ *
126
+ *
127
+ *
128
+ *
129
+ *
130
+ *
131
+ *
132
+ * ```
133
+ *
134
+ * ### Serializing
135
+ *
136
+ * Public Keys can be serialized to hex or bytes using {@link ox#BlsPoint.(toHex:function)} or {@link ox#BlsPoint.(toBytes:function)}:
137
+ *
138
+ * ```ts twoslash
139
+ * import { Bls, BlsPoint } from 'ox'
140
+ *
141
+ * const { publicKey } = Bls.createKeyPair()
142
+ *
143
+ * const publicKeyHex = BlsPoint.toHex(publicKey)
144
+ * // ^?
145
+ *
146
+ *
147
+ * const publicKeyBytes = BlsPoint.toBytes(publicKey)
148
+ * // ^?
149
+ *
150
+ * ```
151
+ *
152
+ * They can also be deserialized from hex or bytes using {@link ox#BlsPoint.(fromHex:function)} or {@link ox#BlsPoint.(fromBytes:function)}:
153
+ *
154
+ * ```ts twoslash
155
+ * import { Bls, BlsPoint } from 'ox'
156
+ *
157
+ * const publicKeyHex = '0x...'
158
+ *
159
+ * const publicKey = BlsPoint.fromHex(publicKeyHex, 'G1')
160
+ * // ^?
161
+ *
162
+ *
163
+ *
164
+ *
165
+ *
166
+ *
167
+ *
168
+ * ```
169
+ *
170
+ * @param options - The options to generate the key pair.
171
+ * @returns The generated key pair containing both private and public keys.
172
+ */
173
+ export function createKeyPair<
174
+ as extends 'Hex' | 'Bytes' = 'Hex',
175
+ size extends Size = 'short-key:long-sig',
176
+ >(
177
+ options: createKeyPair.Options<as, size> = {},
178
+ ): createKeyPair.ReturnType<as, size> {
179
+ const { as = 'Hex', size = 'short-key:long-sig' } = options
180
+ const privateKey = randomPrivateKey({ as })
181
+ const publicKey = getPublicKey({ privateKey, size })
182
+
183
+ return {
184
+ privateKey: privateKey as never,
185
+ publicKey: publicKey as never,
186
+ }
187
+ }
188
+
189
+ export declare namespace createKeyPair {
190
+ type Options<
191
+ as extends 'Hex' | 'Bytes' = 'Hex',
192
+ size extends Size = 'short-key:long-sig',
193
+ > = {
194
+ /**
195
+ * Format of the returned private key.
196
+ * @default 'Hex'
197
+ */
198
+ as?: as | 'Hex' | 'Bytes' | undefined
199
+ /**
200
+ * Size of the public key to compute.
201
+ *
202
+ * - `'short-key:long-sig'`: 48 bytes; computes long signatures (96 bytes)
203
+ * - `'long-key:short-sig'`: 96 bytes; computes short signatures (48 bytes)
204
+ *
205
+ * @default 'short-key:long-sig'
206
+ */
207
+ size?: size | Size | undefined
208
+ }
209
+
210
+ type ReturnType<as extends 'Hex' | 'Bytes', size extends Size> = {
211
+ privateKey:
212
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
213
+ | (as extends 'Hex' ? Hex.Hex : never)
214
+ publicKey: size extends 'short-key:long-sig' ? BlsPoint.G1 : BlsPoint.G2
215
+ }
216
+
217
+ type ErrorType =
218
+ | Hex.fromBytes.ErrorType
219
+ | getPublicKey.ErrorType
220
+ | Errors.GlobalErrorType
221
+ }
222
+
73
223
  /**
74
224
  * Computes the BLS12-381 public key from a provided private key.
75
225
  *
@@ -0,0 +1,237 @@
1
+ import { ed25519 } from '@noble/curves/ed25519'
2
+ import * as Bytes from './Bytes.js'
3
+ import type * as Errors from './Errors.js'
4
+ import * as Hex from './Hex.js'
5
+
6
+ /** Re-export of noble/curves Ed25519 utilities. */
7
+ export const noble = ed25519
8
+
9
+ /**
10
+ * Creates a new Ed25519 key pair consisting of a private key and its corresponding public key.
11
+ *
12
+ * @example
13
+ * ```ts twoslash
14
+ * import { Ed25519 } from 'ox'
15
+ *
16
+ * const { privateKey, publicKey } = Ed25519.createKeyPair()
17
+ * ```
18
+ *
19
+ * @param options - The options to generate the key pair.
20
+ * @returns The generated key pair containing both private and public keys.
21
+ */
22
+ export function createKeyPair<as extends 'Hex' | 'Bytes' = 'Hex'>(
23
+ options: createKeyPair.Options<as> = {},
24
+ ): createKeyPair.ReturnType<as> {
25
+ const { as = 'Hex' } = options
26
+ const privateKey = randomPrivateKey({ as })
27
+ const publicKey = getPublicKey({ privateKey, as })
28
+
29
+ return {
30
+ privateKey: privateKey as never,
31
+ publicKey: publicKey as never,
32
+ }
33
+ }
34
+
35
+ export declare namespace createKeyPair {
36
+ type Options<as extends 'Hex' | 'Bytes' = 'Hex'> = {
37
+ /**
38
+ * Format of the returned private and public keys.
39
+ * @default 'Hex'
40
+ */
41
+ as?: as | 'Hex' | 'Bytes' | undefined
42
+ }
43
+
44
+ type ReturnType<as extends 'Hex' | 'Bytes'> = {
45
+ privateKey:
46
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
47
+ | (as extends 'Hex' ? Hex.Hex : never)
48
+ publicKey:
49
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
50
+ | (as extends 'Hex' ? Hex.Hex : never)
51
+ }
52
+
53
+ type ErrorType =
54
+ | Hex.fromBytes.ErrorType
55
+ | randomPrivateKey.ErrorType
56
+ | getPublicKey.ErrorType
57
+ | Errors.GlobalErrorType
58
+ }
59
+
60
+ /**
61
+ * Computes the Ed25519 public key from a provided private key.
62
+ *
63
+ * @example
64
+ * ```ts twoslash
65
+ * import { Ed25519 } from 'ox'
66
+ *
67
+ * const publicKey = Ed25519.getPublicKey({ privateKey: '0x...' })
68
+ * ```
69
+ *
70
+ * @param options - The options to compute the public key.
71
+ * @returns The computed public key.
72
+ */
73
+ export function getPublicKey<as extends 'Hex' | 'Bytes' = 'Hex'>(
74
+ options: getPublicKey.Options<as>,
75
+ ): getPublicKey.ReturnType<as> {
76
+ const { as = 'Hex', privateKey } = options
77
+ const privateKeyBytes = Bytes.from(privateKey)
78
+ const publicKeyBytes = ed25519.getPublicKey(privateKeyBytes)
79
+ if (as === 'Hex') return Hex.fromBytes(publicKeyBytes) as never
80
+ return publicKeyBytes as never
81
+ }
82
+
83
+ export declare namespace getPublicKey {
84
+ type Options<as extends 'Hex' | 'Bytes' = 'Hex'> = {
85
+ /**
86
+ * Format of the returned public key.
87
+ * @default 'Hex'
88
+ */
89
+ as?: as | 'Hex' | 'Bytes' | undefined
90
+ /**
91
+ * Private key to compute the public key from.
92
+ */
93
+ privateKey: Hex.Hex | Bytes.Bytes
94
+ }
95
+
96
+ type ReturnType<as extends 'Hex' | 'Bytes'> =
97
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
98
+ | (as extends 'Hex' ? Hex.Hex : never)
99
+
100
+ type ErrorType =
101
+ | Bytes.from.ErrorType
102
+ | Hex.fromBytes.ErrorType
103
+ | Errors.GlobalErrorType
104
+ }
105
+
106
+ /**
107
+ * Generates a random Ed25519 private key.
108
+ *
109
+ * @example
110
+ * ```ts twoslash
111
+ * import { Ed25519 } from 'ox'
112
+ *
113
+ * const privateKey = Ed25519.randomPrivateKey()
114
+ * ```
115
+ *
116
+ * @param options - The options to generate the private key.
117
+ * @returns The generated private key.
118
+ */
119
+ export function randomPrivateKey<as extends 'Hex' | 'Bytes' = 'Hex'>(
120
+ options: randomPrivateKey.Options<as> = {},
121
+ ): randomPrivateKey.ReturnType<as> {
122
+ const { as = 'Hex' } = options
123
+ const bytes = ed25519.utils.randomPrivateKey()
124
+ if (as === 'Hex') return Hex.fromBytes(bytes) as never
125
+ return bytes as never
126
+ }
127
+
128
+ export declare namespace randomPrivateKey {
129
+ type Options<as extends 'Hex' | 'Bytes' = 'Hex'> = {
130
+ /**
131
+ * Format of the returned private key.
132
+ * @default 'Hex'
133
+ */
134
+ as?: as | 'Hex' | 'Bytes' | undefined
135
+ }
136
+
137
+ type ReturnType<as extends 'Hex' | 'Bytes'> =
138
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
139
+ | (as extends 'Hex' ? Hex.Hex : never)
140
+
141
+ type ErrorType = Hex.fromBytes.ErrorType | Errors.GlobalErrorType
142
+ }
143
+
144
+ /**
145
+ * Signs the payload with the provided private key and returns an Ed25519 signature.
146
+ *
147
+ * @example
148
+ * ```ts twoslash
149
+ * import { Ed25519 } from 'ox'
150
+ *
151
+ * const signature = Ed25519.sign({ // [!code focus]
152
+ * payload: '0xdeadbeef', // [!code focus]
153
+ * privateKey: '0x...' // [!code focus]
154
+ * }) // [!code focus]
155
+ * ```
156
+ *
157
+ * @param options - The signing options.
158
+ * @returns The Ed25519 signature.
159
+ */
160
+ export function sign<as extends 'Hex' | 'Bytes' = 'Hex'>(
161
+ options: sign.Options<as>,
162
+ ): sign.ReturnType<as> {
163
+ const { as = 'Hex', payload, privateKey } = options
164
+ const payloadBytes = Bytes.from(payload)
165
+ const privateKeyBytes = Bytes.from(privateKey)
166
+ const signatureBytes = ed25519.sign(payloadBytes, privateKeyBytes)
167
+ if (as === 'Hex') return Hex.fromBytes(signatureBytes) as never
168
+ return signatureBytes as never
169
+ }
170
+
171
+ export declare namespace sign {
172
+ type Options<as extends 'Hex' | 'Bytes' = 'Hex'> = {
173
+ /**
174
+ * Format of the returned signature.
175
+ * @default 'Hex'
176
+ */
177
+ as?: as | 'Hex' | 'Bytes' | undefined
178
+ /**
179
+ * Payload to sign.
180
+ */
181
+ payload: Hex.Hex | Bytes.Bytes
182
+ /**
183
+ * Ed25519 private key.
184
+ */
185
+ privateKey: Hex.Hex | Bytes.Bytes
186
+ }
187
+
188
+ type ReturnType<as extends 'Hex' | 'Bytes'> =
189
+ | (as extends 'Bytes' ? Bytes.Bytes : never)
190
+ | (as extends 'Hex' ? Hex.Hex : never)
191
+
192
+ type ErrorType =
193
+ | Bytes.from.ErrorType
194
+ | Hex.fromBytes.ErrorType
195
+ | Errors.GlobalErrorType
196
+ }
197
+
198
+ /**
199
+ * Verifies a payload was signed by the provided public key.
200
+ *
201
+ * @example
202
+ * ```ts twoslash
203
+ * import { Ed25519 } from 'ox'
204
+ *
205
+ * const { privateKey, publicKey } = Ed25519.createKeyPair()
206
+ * const signature = Ed25519.sign({ payload: '0xdeadbeef', privateKey })
207
+ *
208
+ * const verified = Ed25519.verify({ // [!code focus]
209
+ * publicKey, // [!code focus]
210
+ * payload: '0xdeadbeef', // [!code focus]
211
+ * signature, // [!code focus]
212
+ * }) // [!code focus]
213
+ * ```
214
+ *
215
+ * @param options - The verification options.
216
+ * @returns Whether the payload was signed by the provided public key.
217
+ */
218
+ export function verify(options: verify.Options): boolean {
219
+ const { payload, publicKey, signature } = options
220
+ const payloadBytes = Bytes.from(payload)
221
+ const publicKeyBytes = Bytes.from(publicKey)
222
+ const signatureBytes = Bytes.from(signature)
223
+ return ed25519.verify(signatureBytes, payloadBytes, publicKeyBytes)
224
+ }
225
+
226
+ export declare namespace verify {
227
+ type Options = {
228
+ /** Payload that was signed. */
229
+ payload: Hex.Hex | Bytes.Bytes
230
+ /** Public key that signed the payload. */
231
+ publicKey: Hex.Hex | Bytes.Bytes
232
+ /** Signature of the payload. */
233
+ signature: Hex.Hex | Bytes.Bytes
234
+ }
235
+
236
+ type ErrorType = Bytes.from.ErrorType | Errors.GlobalErrorType
237
+ }