voltaire-effect 0.2.23 → 0.2.24
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/{X25519Test-DGsk1V9o.d.ts → X25519Test-C8Cicdd_.d.ts} +2 -139
- package/dist/crypto/index.d.ts +3 -2
- package/dist/{index-IgkEHjBe.d.ts → index-DsFjN_a3.d.ts} +17633 -11961
- package/dist/index.d.ts +3104 -938
- package/dist/index.js +4467 -2446
- package/dist/native/index.d.ts +14 -5
- package/dist/native/index.js +4489 -2468
- package/dist/primitives/index.d.ts +12 -4
- package/dist/primitives/index.js +3980 -2411
- package/package.json +2 -2
- package/src/crypto/Keccak256/index.ts +1 -0
- package/src/index.ts +2 -2
- package/src/primitives/Abi/decode.test.ts +38 -0
- package/src/primitives/Abi/decode.ts +67 -0
- package/src/primitives/Abi/decodeData.test.ts +37 -0
- package/src/primitives/Abi/decodeData.ts +77 -0
- package/src/primitives/Abi/decodeLog.test.ts +32 -0
- package/src/primitives/Abi/decodeLog.ts +81 -0
- package/src/primitives/Abi/decodeWrappedError.test.ts +41 -0
- package/src/primitives/Abi/decodeWrappedError.ts +68 -0
- package/src/primitives/Abi/encode.test.ts +43 -0
- package/src/primitives/Abi/encode.ts +67 -0
- package/src/primitives/Abi/encodePacked.test.ts +35 -0
- package/src/primitives/Abi/encodePacked.ts +62 -0
- package/src/primitives/Abi/encodeWrappedError.test.ts +21 -0
- package/src/primitives/Abi/encodeWrappedError.ts +64 -0
- package/src/primitives/Abi/findSelectorCollisions.test.ts +50 -0
- package/src/primitives/Abi/findSelectorCollisions.ts +83 -0
- package/src/primitives/Abi/index.ts +33 -7
- package/src/primitives/Abi/parseLogs.test.ts +37 -0
- package/src/primitives/Abi/parseLogs.ts +62 -0
- package/src/primitives/AccessList/AccessList.test.ts +229 -0
- package/src/primitives/AccessList/AccessListTypeSchema.ts +16 -0
- package/src/primitives/AccessList/addressCount.ts +21 -0
- package/src/primitives/AccessList/assertValid.ts +37 -0
- package/src/primitives/AccessList/create.ts +19 -0
- package/src/primitives/AccessList/deduplicate.ts +23 -0
- package/src/primitives/AccessList/from.ts +39 -0
- package/src/primitives/AccessList/fromBytes.ts +36 -0
- package/src/primitives/AccessList/gasCost.ts +22 -0
- package/src/primitives/AccessList/gasSavings.ts +26 -0
- package/src/primitives/AccessList/hasSavings.ts +23 -0
- package/src/primitives/AccessList/includesAddress.ts +25 -0
- package/src/primitives/AccessList/includesStorageKey.ts +28 -0
- package/src/primitives/AccessList/index.ts +99 -19
- package/src/primitives/AccessList/is.ts +23 -0
- package/src/primitives/AccessList/isEmpty.ts +23 -0
- package/src/primitives/AccessList/isItem.ts +22 -0
- package/src/primitives/AccessList/keysFor.ts +29 -0
- package/src/primitives/AccessList/merge.ts +24 -0
- package/src/primitives/AccessList/storageKeyCount.ts +21 -0
- package/src/primitives/AccessList/toBytes.ts +23 -0
- package/src/primitives/AccessList/withAddress.ts +27 -0
- package/src/primitives/AccessList/withStorageKey.ts +30 -0
- package/src/primitives/Address/Address.test.ts +146 -0
- package/src/primitives/Address/assert.ts +51 -0
- package/src/primitives/Address/calculateCreate2Address.ts +33 -0
- package/src/primitives/Address/calculateCreateAddress.ts +30 -0
- package/src/primitives/Address/deduplicateAddresses.ts +20 -0
- package/src/primitives/Address/from.ts +41 -0
- package/src/primitives/Address/fromAbiEncoded.ts +35 -0
- package/src/primitives/Address/fromBase64.ts +25 -0
- package/src/primitives/Address/fromBytes.ts +25 -0
- package/src/primitives/Address/fromHex.ts +31 -0
- package/src/primitives/Address/fromNumber.ts +25 -0
- package/src/primitives/Address/fromPrivateKey.ts +25 -0
- package/src/primitives/Address/fromPublicKey.ts +56 -0
- package/src/primitives/Address/index.ts +99 -35
- package/src/primitives/Address/is.ts +20 -0
- package/src/primitives/Address/isAddress.ts +22 -0
- package/src/primitives/Address/sortAddresses.ts +19 -0
- package/src/primitives/Address/toChecksummed.ts +32 -0
- package/src/primitives/Address/toHex.ts +18 -0
- package/src/primitives/Address/zero.ts +18 -0
- package/src/primitives/Base64/Base64.test.ts +75 -0
- package/src/primitives/Base64/convert.ts +37 -0
- package/src/primitives/Base64/decode.ts +59 -0
- package/src/primitives/Base64/encode.ts +42 -0
- package/src/primitives/Base64/from.ts +39 -0
- package/src/primitives/Base64/index.ts +81 -1
- package/src/primitives/Base64/size.ts +16 -0
- package/src/primitives/Base64/validation.ts +16 -0
- package/src/primitives/Blob/Blob.test.ts +292 -0
- package/src/primitives/Blob/calculateGas.ts +30 -0
- package/src/primitives/Blob/estimateBlobCount.ts +30 -0
- package/src/primitives/Blob/from.ts +38 -0
- package/src/primitives/Blob/fromData.ts +36 -0
- package/src/primitives/Blob/index.ts +99 -12
- package/src/primitives/Blob/isValidVersion.ts +27 -0
- package/src/primitives/Blob/joinData.ts +43 -0
- package/src/primitives/Blob/splitData.ts +36 -0
- package/src/primitives/Blob/toCommitment.ts +43 -0
- package/src/primitives/Blob/toProof.ts +50 -0
- package/src/primitives/Blob/toVersionedHash.ts +35 -0
- package/src/primitives/Blob/verify.ts +49 -0
- package/src/primitives/Blob/verifyBatch.ts +119 -0
- package/src/primitives/BloomFilter/BloomFilter.test.ts +138 -0
- package/src/primitives/BloomFilter/add.ts +23 -0
- package/src/primitives/BloomFilter/combine.ts +21 -0
- package/src/primitives/BloomFilter/contains.ts +26 -0
- package/src/primitives/BloomFilter/create.ts +35 -0
- package/src/primitives/BloomFilter/density.ts +22 -0
- package/src/primitives/BloomFilter/expectedFalsePositiveRate.ts +25 -0
- package/src/primitives/BloomFilter/fromHex.ts +37 -0
- package/src/primitives/BloomFilter/hash.ts +43 -0
- package/src/primitives/BloomFilter/index.ts +59 -37
- package/src/primitives/BloomFilter/isEmpty.ts +22 -0
- package/src/primitives/BloomFilter/merge.ts +24 -0
- package/src/primitives/BloomFilter/toHex.ts +22 -0
- package/src/primitives/Bytecode/analyze.ts +58 -0
- package/src/primitives/Bytecode/detectFusions.ts +10 -0
- package/src/primitives/Bytecode/equals.ts +10 -0
- package/src/primitives/Bytecode/extractRuntime.ts +12 -0
- package/src/primitives/Bytecode/format.ts +16 -0
- package/src/primitives/Bytecode/from.ts +16 -0
- package/src/primitives/Bytecode/fromHex.ts +14 -0
- package/src/primitives/Bytecode/getBlock.ts +12 -0
- package/src/primitives/Bytecode/getNextPc.ts +12 -0
- package/src/primitives/Bytecode/getPushSize.ts +8 -0
- package/src/primitives/Bytecode/hasMetadata.ts +10 -0
- package/src/primitives/Bytecode/hash.ts +9 -0
- package/src/primitives/Bytecode/index.ts +103 -13
- package/src/primitives/Bytecode/isPush.ts +8 -0
- package/src/primitives/Bytecode/isTerminator.ts +8 -0
- package/src/primitives/Bytecode/isValidJumpDest.ts +12 -0
- package/src/primitives/Bytecode/parseInstructions.ts +10 -0
- package/src/primitives/Bytecode/prettyPrint.ts +12 -0
- package/src/primitives/Bytecode/scan.ts +20 -0
- package/src/primitives/Bytecode/size.ts +9 -0
- package/src/primitives/Bytecode/stripMetadata.ts +10 -0
- package/src/primitives/Bytecode/toAbi.ts +10 -0
- package/src/primitives/Bytecode/toHex.ts +10 -0
- package/src/primitives/Bytecode/types.ts +23 -0
- package/src/primitives/Bytecode/validate.ts +9 -0
- package/src/primitives/Ens/Ens.test.ts +71 -0
- package/src/primitives/Ens/convert.ts +13 -0
- package/src/primitives/Ens/from.ts +32 -0
- package/src/primitives/Ens/hash.ts +46 -0
- package/src/primitives/Ens/index.ts +86 -4
- package/src/primitives/Ens/normalize.ts +45 -0
- package/src/primitives/Ens/validation.ts +38 -0
- package/src/primitives/EventLog/accessors.ts +32 -0
- package/src/primitives/EventLog/clone.ts +17 -0
- package/src/primitives/EventLog/create.ts +46 -0
- package/src/primitives/EventLog/filtering.ts +48 -0
- package/src/primitives/EventLog/index.ts +96 -6
- package/src/primitives/EventLog/status.ts +17 -0
- package/src/primitives/EventLog/toRpc.ts +49 -0
- package/src/primitives/Hardfork/HardforkSchema.ts +3 -3
- package/src/primitives/Hardfork/allIds.ts +13 -0
- package/src/primitives/Hardfork/allNames.ts +13 -0
- package/src/primitives/Hardfork/compare.ts +17 -0
- package/src/primitives/Hardfork/comparisons.ts +45 -0
- package/src/primitives/Hardfork/equals.ts +17 -0
- package/src/primitives/Hardfork/features.ts +61 -0
- package/src/primitives/Hardfork/fromString.ts +16 -0
- package/src/primitives/Hardfork/index.ts +128 -18
- package/src/primitives/Hardfork/isValidName.ts +14 -0
- package/src/primitives/Hardfork/minMax.ts +23 -0
- package/src/primitives/Hardfork/range.ts +19 -0
- package/src/primitives/Hardfork/toString.ts +16 -0
- package/src/primitives/Hash/Hash.test.ts +104 -0
- package/src/primitives/Hash/from.ts +47 -0
- package/src/primitives/Hash/fromBytes.ts +46 -0
- package/src/primitives/Hash/fromHex.ts +44 -0
- package/src/primitives/Hash/index.ts +45 -8
- package/src/primitives/Hash/isHash.ts +31 -0
- package/src/primitives/Hash/toHex.ts +29 -0
- package/src/primitives/Hex/Hex.test.ts +266 -155
- package/src/primitives/Hex/assertSize.ts +41 -0
- package/src/primitives/Hex/concat.ts +37 -0
- package/src/primitives/Hex/from.ts +38 -0
- package/src/primitives/Hex/fromBigInt.ts +40 -0
- package/src/primitives/Hex/fromBoolean.ts +29 -0
- package/src/primitives/Hex/fromNumber.ts +41 -0
- package/src/primitives/Hex/fromString.ts +28 -0
- package/src/primitives/Hex/index.ts +68 -37
- package/src/primitives/Hex/pad.ts +40 -0
- package/src/primitives/Hex/padRight.ts +39 -0
- package/src/primitives/Hex/size.ts +29 -0
- package/src/primitives/Hex/slice.ts +42 -0
- package/src/primitives/Hex/toBigInt.ts +27 -0
- package/src/primitives/Hex/toBoolean.ts +38 -0
- package/src/primitives/Hex/toNumber.ts +37 -0
- package/src/primitives/Hex/toStringHex.ts +39 -0
- package/src/primitives/Hex/trim.ts +27 -0
- package/src/primitives/Hex/validate.ts +37 -0
- package/src/primitives/Hex/xor.ts +39 -0
- package/src/primitives/Opcode/OpcodeSchema.ts +1 -1
- package/src/primitives/Opcode/disassemble.ts +15 -0
- package/src/primitives/Opcode/dupPosition.ts +15 -0
- package/src/primitives/Opcode/format.ts +15 -0
- package/src/primitives/Opcode/getters.ts +54 -0
- package/src/primitives/Opcode/index.ts +301 -11
- package/src/primitives/Opcode/info.ts +18 -0
- package/src/primitives/Opcode/jumpDests.ts +15 -0
- package/src/primitives/Opcode/logTopics.ts +15 -0
- package/src/primitives/Opcode/name.ts +15 -0
- package/src/primitives/Opcode/parse.ts +15 -0
- package/src/primitives/Opcode/predicates.ts +72 -0
- package/src/primitives/Opcode/pushBytes.ts +15 -0
- package/src/primitives/Opcode/pushOpcode.ts +15 -0
- package/src/primitives/Opcode/swapPosition.ts +15 -0
- package/src/primitives/Rlp/decodeBatch.ts +46 -0
- package/src/primitives/Rlp/decodeObject.ts +46 -0
- package/src/primitives/Rlp/decodeValue.ts +51 -0
- package/src/primitives/Rlp/encodeBatch.ts +50 -0
- package/src/primitives/Rlp/encodeObject.ts +48 -0
- package/src/primitives/Rlp/encodeVariadic.ts +49 -0
- package/src/primitives/Rlp/equals.ts +22 -0
- package/src/primitives/Rlp/from.ts +44 -0
- package/src/primitives/Rlp/fromJSON.ts +45 -0
- package/src/primitives/Rlp/getEncodedLength.ts +47 -0
- package/src/primitives/Rlp/getLength.ts +44 -0
- package/src/primitives/Rlp/index.ts +67 -14
- package/src/primitives/Rlp/isBytesData.ts +21 -0
- package/src/primitives/Rlp/isCanonical.ts +32 -0
- package/src/primitives/Rlp/isData.ts +21 -0
- package/src/primitives/Rlp/isList.ts +46 -0
- package/src/primitives/Rlp/isListData.ts +21 -0
- package/src/primitives/Rlp/isString.ts +46 -0
- package/src/primitives/Rlp/toJSON.ts +20 -0
- package/src/primitives/Rlp/toRaw.ts +31 -0
- package/src/primitives/Signature/Signature.test.ts +217 -0
- package/src/primitives/Signature/from.ts +38 -0
- package/src/primitives/Signature/fromBytes.ts +31 -0
- package/src/primitives/Signature/fromCompact.ts +33 -0
- package/src/primitives/Signature/fromDER.ts +35 -0
- package/src/primitives/Signature/fromEd25519.ts +24 -0
- package/src/primitives/Signature/fromHex.ts +29 -0
- package/src/primitives/Signature/fromP256.ts +25 -0
- package/src/primitives/Signature/fromRpc.ts +38 -0
- package/src/primitives/Signature/fromSecp256k1.ts +29 -0
- package/src/primitives/Signature/fromTuple.ts +33 -0
- package/src/primitives/Signature/getR.ts +24 -0
- package/src/primitives/Signature/getS.ts +24 -0
- package/src/primitives/Signature/getV.ts +24 -0
- package/src/primitives/Signature/index.ts +61 -11
- package/src/primitives/Signature/toDER.ts +24 -0
- package/src/primitives/Signature/toHex.ts +24 -0
- package/src/primitives/Signature/toRpc.ts +35 -0
- package/src/primitives/Signature/toTuple.ts +29 -0
- package/src/primitives/Signature/verify.ts +31 -0
- package/src/primitives/Siwe/create.ts +56 -0
- package/src/primitives/Siwe/hash.ts +27 -0
- package/src/primitives/Siwe/index.ts +57 -21
- package/src/primitives/Siwe/parse.ts +24 -0
- package/src/primitives/Siwe/verify.ts +47 -0
- package/src/primitives/Transaction/index.ts +467 -2
- package/src/primitives/Uint/Uint.test.ts +200 -0
- package/src/primitives/Uint/dividedBy.ts +34 -0
- package/src/primitives/Uint/from.ts +35 -0
- package/src/primitives/Uint/fromAbiEncoded.ts +29 -0
- package/src/primitives/Uint/fromBigInt.ts +30 -0
- package/src/primitives/Uint/fromBytes.ts +32 -0
- package/src/primitives/Uint/fromHex.ts +32 -0
- package/src/primitives/Uint/fromNumber.ts +30 -0
- package/src/primitives/Uint/index.ts +90 -45
- package/src/primitives/Uint/isUint256.ts +25 -0
- package/src/primitives/Uint/isValid.ts +25 -0
- package/src/primitives/Uint/modulo.ts +34 -0
- package/src/primitives/Uint/toHex.ts +31 -0
- package/src/primitives/Uint/tryFrom.ts +30 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Gets R component from Signature.
|
|
3
|
+
* @module Signature/getR
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the R component of a signature as a 32-byte Uint8Array.
|
|
10
|
+
*
|
|
11
|
+
* @param signature - The SignatureType to extract R from
|
|
12
|
+
* @returns 32-byte Uint8Array containing the R value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const r = Signature.getR(sig)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const getR = (signature: SignatureType): Uint8Array =>
|
|
24
|
+
Signature.getR(signature);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Gets S component from Signature.
|
|
3
|
+
* @module Signature/getS
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the S component of a signature as a 32-byte Uint8Array.
|
|
10
|
+
*
|
|
11
|
+
* @param signature - The SignatureType to extract S from
|
|
12
|
+
* @returns 32-byte Uint8Array containing the S value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const s = Signature.getS(sig)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const getS = (signature: SignatureType): Uint8Array =>
|
|
24
|
+
Signature.getS(signature);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Gets V component from Signature.
|
|
3
|
+
* @module Signature/getV
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Gets the V (recovery) component of a signature.
|
|
10
|
+
*
|
|
11
|
+
* @param signature - The SignatureType to extract V from
|
|
12
|
+
* @returns Recovery value (27, 28, or chainId-derived) or undefined if not present
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const v = Signature.getV(sig) // 27, 28, or undefined
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const getV = (signature: SignatureType): number | undefined =>
|
|
24
|
+
Signature.getV(signature);
|
|
@@ -48,43 +48,93 @@
|
|
|
48
48
|
* Signature.isSignature(value) // alias for is
|
|
49
49
|
* Signature.isCanonical(sig) // boolean - check if s <= n/2
|
|
50
50
|
* Signature.getAlgorithm(sig) // 'secp256k1' | 'p256' | 'ed25519'
|
|
51
|
+
* Signature.getR(sig) // Uint8Array - 32-byte R component
|
|
52
|
+
* Signature.getS(sig) // Uint8Array - 32-byte S component
|
|
53
|
+
* Signature.getV(sig) // number | undefined - recovery value
|
|
51
54
|
* Signature.normalize(sig) // SignatureType - normalize to canonical form
|
|
52
55
|
* Signature.toBytes(sig) // Uint8Array - raw bytes
|
|
53
56
|
* Signature.toCompact(sig) // Uint8Array - EIP-2098 compact
|
|
57
|
+
* Signature.toDER(sig) // Uint8Array - DER encoding
|
|
54
58
|
* Signature.toHex(sig) // string - hex encoding
|
|
59
|
+
* Signature.toRpc(sig) // { r, s, yParity, v } - RPC format
|
|
60
|
+
* Signature.toTuple(sig) // [yParity, r, s] - tuple format
|
|
61
|
+
* Signature.verify(sig, hash, pubkey) // boolean - verify signature
|
|
55
62
|
* ```
|
|
56
63
|
*
|
|
57
|
-
* ## Effect-wrapped Functions (fallible
|
|
64
|
+
* ## Effect-wrapped Functions (fallible parsing)
|
|
58
65
|
*
|
|
59
66
|
* ```typescript
|
|
60
67
|
* import * as Effect from 'effect/Effect'
|
|
61
68
|
*
|
|
62
|
-
* Signature.
|
|
63
|
-
* Signature.
|
|
64
|
-
* Signature.
|
|
65
|
-
* Signature.
|
|
69
|
+
* Signature.from(input) // Effect<SignatureType, Error>
|
|
70
|
+
* Signature.fromHex(hex) // Effect<SignatureType, Error>
|
|
71
|
+
* Signature.fromBytes(bytes) // Effect<SignatureType, Error>
|
|
72
|
+
* Signature.fromCompact(bytes) // Effect<SignatureType, Error>
|
|
73
|
+
* Signature.fromDER(bytes) // Effect<SignatureType, Error>
|
|
74
|
+
* Signature.fromRpc(rpc) // Effect<SignatureType, Error>
|
|
75
|
+
* Signature.fromTuple(tuple) // Effect<SignatureType, Error>
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* ## Constructor Functions (pure, for known-valid inputs)
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* Signature.fromSecp256k1(r, s, v) // SignatureType
|
|
82
|
+
* Signature.fromP256(r, s) // SignatureType
|
|
83
|
+
* Signature.fromEd25519(bytes) // SignatureType
|
|
66
84
|
* ```
|
|
67
85
|
*
|
|
68
86
|
* @since 0.1.0
|
|
69
87
|
*/
|
|
70
88
|
|
|
89
|
+
// Schemas
|
|
71
90
|
export { Bytes } from "./Bytes.js";
|
|
72
91
|
export { Compact } from "./Compact.js";
|
|
73
92
|
export { DER } from "./DER.js";
|
|
74
|
-
export { getAlgorithm } from "./getAlgorithm.js";
|
|
75
93
|
export { Hex } from "./Hex.js";
|
|
94
|
+
export { Rpc } from "./Rpc.js";
|
|
95
|
+
export { SignatureTypeSchema } from "./SignatureSchema.js";
|
|
96
|
+
export { Tuple } from "./Tuple.js";
|
|
97
|
+
|
|
76
98
|
// Pure functions (infallible)
|
|
99
|
+
export { equals } from "./equals.js";
|
|
100
|
+
export { getAlgorithm } from "./getAlgorithm.js";
|
|
101
|
+
export { getR } from "./getR.js";
|
|
102
|
+
export { getS } from "./getS.js";
|
|
103
|
+
export { getV } from "./getV.js";
|
|
77
104
|
export { is } from "./is.js";
|
|
78
105
|
export { isCanonical } from "./isCanonical.js";
|
|
79
106
|
export { isSignature } from "./isSignature.js";
|
|
80
107
|
export { normalize } from "./normalize.js";
|
|
81
|
-
export {
|
|
82
|
-
// Schemas
|
|
83
|
-
export { SignatureTypeSchema } from "./SignatureSchema.js";
|
|
84
|
-
export { Tuple } from "./Tuple.js";
|
|
108
|
+
export { toBytes } from "./toBytes.js";
|
|
85
109
|
export { toCompact } from "./toCompact.js";
|
|
110
|
+
export { toDER } from "./toDER.js";
|
|
111
|
+
export { toHex } from "./toHex.js";
|
|
112
|
+
export { toRpc, type RpcSignature } from "./toRpc.js";
|
|
113
|
+
export { toTuple, type SignatureTuple } from "./toTuple.js";
|
|
114
|
+
export { verify } from "./verify.js";
|
|
115
|
+
|
|
116
|
+
// Effect-wrapped functions (fallible parsing)
|
|
117
|
+
export { from } from "./from.js";
|
|
118
|
+
export { fromBytes } from "./fromBytes.js";
|
|
119
|
+
export { fromCompact } from "./fromCompact.js";
|
|
120
|
+
export { fromDER } from "./fromDER.js";
|
|
121
|
+
export { fromHex } from "./fromHex.js";
|
|
122
|
+
export { fromRpc } from "./fromRpc.js";
|
|
123
|
+
export { fromTuple } from "./fromTuple.js";
|
|
86
124
|
|
|
87
|
-
//
|
|
125
|
+
// Constructor functions (pure, for known-valid inputs)
|
|
126
|
+
export { fromEd25519 } from "./fromEd25519.js";
|
|
127
|
+
export { fromP256 } from "./fromP256.js";
|
|
128
|
+
export { fromSecp256k1 } from "./fromSecp256k1.js";
|
|
129
|
+
|
|
130
|
+
// Re-export errors from voltaire
|
|
131
|
+
export {
|
|
132
|
+
InvalidAlgorithmError,
|
|
133
|
+
InvalidDERError,
|
|
134
|
+
InvalidSignatureFormatError,
|
|
135
|
+
InvalidSignatureLengthError,
|
|
136
|
+
NonCanonicalSignatureError,
|
|
137
|
+
} from "@tevm/voltaire/Signature";
|
|
88
138
|
|
|
89
139
|
// Re-export types from voltaire
|
|
90
140
|
export type {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Converts Signature to DER format.
|
|
3
|
+
* @module Signature/toDER
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Signature to DER-encoded bytes.
|
|
10
|
+
*
|
|
11
|
+
* @param signature - The SignatureType to convert
|
|
12
|
+
* @returns DER-encoded signature bytes
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const der = Signature.toDER(sig)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const toDER = (signature: SignatureType): Uint8Array =>
|
|
24
|
+
Signature.toDER(signature);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Converts Signature to hex string.
|
|
3
|
+
* @module Signature/toHex
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Signature to a hex string with 0x prefix.
|
|
10
|
+
*
|
|
11
|
+
* @param signature - The SignatureType to convert
|
|
12
|
+
* @returns Hex string (130 chars for secp256k1 with v, 128 chars otherwise)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const hex = Signature.toHex(sig) // "0x..."
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const toHex = (signature: SignatureType): string =>
|
|
24
|
+
Signature.toHex(signature);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Converts Signature to RPC format.
|
|
3
|
+
* @module Signature/toRpc
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* RPC signature format with r, s, and optional yParity/v fields.
|
|
10
|
+
*/
|
|
11
|
+
export type RpcSignature = {
|
|
12
|
+
r: string;
|
|
13
|
+
s: string;
|
|
14
|
+
yParity?: string;
|
|
15
|
+
v?: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Converts a Signature to Ethereum RPC format.
|
|
20
|
+
*
|
|
21
|
+
* @param signature - The SignatureType to convert
|
|
22
|
+
* @returns RPC-formatted signature object with r, s, yParity, and v
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
27
|
+
*
|
|
28
|
+
* const rpc = Signature.toRpc(sig)
|
|
29
|
+
* // { r: "0x...", s: "0x...", yParity: "0x0", v: "0x1b" }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @since 0.0.1
|
|
33
|
+
*/
|
|
34
|
+
export const toRpc = (signature: SignatureType): RpcSignature =>
|
|
35
|
+
Signature.toRpc(signature);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Converts Signature to tuple format.
|
|
3
|
+
* @module Signature/toTuple
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Tuple signature format: [yParity, r, s].
|
|
10
|
+
*/
|
|
11
|
+
export type SignatureTuple = readonly [number, Uint8Array, Uint8Array];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts a Signature to tuple format [yParity, r, s].
|
|
15
|
+
*
|
|
16
|
+
* @param signature - The SignatureType to convert
|
|
17
|
+
* @returns Tuple of [yParity (0 or 1), r (32 bytes), s (32 bytes)]
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
22
|
+
*
|
|
23
|
+
* const [yParity, r, s] = Signature.toTuple(sig)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
export const toTuple = (signature: SignatureType): SignatureTuple =>
|
|
29
|
+
Signature.toTuple(signature);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Verifies a Signature against a message hash and public key.
|
|
3
|
+
* @module Signature/verify
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import type { HashType } from "@tevm/voltaire/Hash";
|
|
7
|
+
import type { PublicKeyType } from "@tevm/voltaire/PublicKey";
|
|
8
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Verifies a signature against a message hash and public key.
|
|
12
|
+
*
|
|
13
|
+
* @param signature - The signature to verify
|
|
14
|
+
* @param messageHash - The 32-byte hash of the signed message
|
|
15
|
+
* @param publicKey - The public key to verify against
|
|
16
|
+
* @returns True if signature is valid, false otherwise
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
21
|
+
*
|
|
22
|
+
* const isValid = Signature.verify(sig, messageHash, publicKey)
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
*/
|
|
27
|
+
export const verify = (
|
|
28
|
+
signature: SignatureType,
|
|
29
|
+
messageHash: HashType,
|
|
30
|
+
publicKey: PublicKeyType,
|
|
31
|
+
): boolean => Signature.verify(signature, messageHash, publicKey);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module create
|
|
3
|
+
* @description Effect-wrapped SIWE constructors
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Siwe } from "@tevm/voltaire";
|
|
8
|
+
import type { SiweMessageType } from "./String.js";
|
|
9
|
+
import type { AddressType } from "@tevm/voltaire/Address";
|
|
10
|
+
|
|
11
|
+
interface CreateParams<
|
|
12
|
+
TDomain extends string = string,
|
|
13
|
+
TAddress extends AddressType = AddressType,
|
|
14
|
+
TUri extends string = string,
|
|
15
|
+
TChainId extends number = number,
|
|
16
|
+
> {
|
|
17
|
+
domain: TDomain;
|
|
18
|
+
address: TAddress | string;
|
|
19
|
+
uri: TUri;
|
|
20
|
+
chainId: TChainId;
|
|
21
|
+
statement?: string;
|
|
22
|
+
expirationTime?: string;
|
|
23
|
+
notBefore?: string;
|
|
24
|
+
requestId?: string;
|
|
25
|
+
resources?: string[];
|
|
26
|
+
nonce?: string;
|
|
27
|
+
issuedAt?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create SIWE message from parameters
|
|
32
|
+
*
|
|
33
|
+
* @param params - SIWE message parameters
|
|
34
|
+
* @returns Effect yielding SiweMessageType
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const message = await Effect.runPromise(Siwe.create({
|
|
38
|
+
* domain: 'example.com',
|
|
39
|
+
* address: '0x...',
|
|
40
|
+
* uri: 'https://example.com',
|
|
41
|
+
* chainId: 1,
|
|
42
|
+
* }))
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export const create = <
|
|
46
|
+
TDomain extends string = string,
|
|
47
|
+
TAddress extends AddressType = AddressType,
|
|
48
|
+
TUri extends string = string,
|
|
49
|
+
TChainId extends number = number,
|
|
50
|
+
>(
|
|
51
|
+
params: CreateParams<TDomain, TAddress, TUri, TChainId>,
|
|
52
|
+
): Effect.Effect<SiweMessageType, Error> =>
|
|
53
|
+
Effect.try({
|
|
54
|
+
try: () => Siwe.create(params as Parameters<typeof Siwe.create>[0]),
|
|
55
|
+
catch: (e) => e as Error,
|
|
56
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module hash
|
|
3
|
+
* @description Effect-wrapped SIWE hash operations
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Siwe } from "@tevm/voltaire";
|
|
8
|
+
import type { SiweMessageType } from "./String.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get message hash for signing
|
|
12
|
+
*
|
|
13
|
+
* @param message - SIWE message to hash
|
|
14
|
+
* @returns Effect yielding 32-byte hash
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const hash = await Effect.runPromise(Siwe.getMessageHash(message))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const getMessageHash = (message: SiweMessageType): Effect.Effect<Uint8Array, Error> =>
|
|
21
|
+
Effect.try({
|
|
22
|
+
try: () => Siwe.getMessageHash(message),
|
|
23
|
+
catch: (e) => e as Error,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Re-export factory for advanced usage
|
|
27
|
+
export { GetMessageHash, Verify, VerifyMessage } from "@tevm/voltaire/Siwe";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Siwe
|
|
3
|
-
* @description Effect Schemas for Sign-In with Ethereum (SIWE) messages (EIP-4361).
|
|
3
|
+
* @description Effect Schemas and functions for Sign-In with Ethereum (SIWE) messages (EIP-4361).
|
|
4
4
|
*
|
|
5
5
|
* ## Type Declarations
|
|
6
6
|
*
|
|
@@ -19,37 +19,73 @@
|
|
|
19
19
|
* | `Siwe.String` | SIWE message string | SiweMessageType |
|
|
20
20
|
* | `Siwe.MessageStruct` | SIWE message object | validated object |
|
|
21
21
|
*
|
|
22
|
-
* ##
|
|
22
|
+
* ## Constructors (Effect-wrapped)
|
|
23
23
|
*
|
|
24
24
|
* ```typescript
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Siwe.create(params) // Effect<SiweMessageType, Error>
|
|
26
|
+
* Siwe.parse(text) // Effect<SiweMessageType, Error>
|
|
27
|
+
* ```
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
-
* const message = S.decodeSync(Siwe.String)(`example.com wants you to sign in...`)
|
|
29
|
+
* ## Verification (Effect-wrapped)
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* Siwe.verify(message, signature) // Effect<boolean, Error>
|
|
33
|
+
* Siwe.verifyMessage(msg, sig, opts) // Effect<ValidationResult, Error>
|
|
34
|
+
* Siwe.getMessageHash(message) // Effect<Uint8Array, Error>
|
|
33
35
|
* ```
|
|
34
36
|
*
|
|
35
37
|
* ## Pure Functions
|
|
36
38
|
*
|
|
37
39
|
* ```typescript
|
|
38
|
-
* Siwe.format(message)
|
|
39
|
-
* Siwe.validate(message,
|
|
40
|
-
* Siwe.generateNonce(length)
|
|
40
|
+
* Siwe.format(message) // string
|
|
41
|
+
* Siwe.validate(message, opts) // ValidationResult
|
|
42
|
+
* Siwe.generateNonce(length) // string
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import * as Siwe from 'voltaire-effect/primitives/Siwe'
|
|
48
|
+
* import { Effect } from 'effect'
|
|
49
|
+
*
|
|
50
|
+
* const program = Effect.gen(function* () {
|
|
51
|
+
* const message = yield* Siwe.create({
|
|
52
|
+
* domain: 'example.com',
|
|
53
|
+
* address: '0x...',
|
|
54
|
+
* uri: 'https://example.com',
|
|
55
|
+
* chainId: 1,
|
|
56
|
+
* })
|
|
57
|
+
* const text = Siwe.format(message)
|
|
58
|
+
* const hash = yield* Siwe.getMessageHash(message)
|
|
59
|
+
* return { message, text, hash }
|
|
60
|
+
* })
|
|
41
61
|
* ```
|
|
42
62
|
*
|
|
43
63
|
* @since 0.1.0
|
|
44
64
|
*/
|
|
65
|
+
|
|
66
|
+
// Types
|
|
67
|
+
export type { SiweMessageType, ValidationResult } from "./String.js";
|
|
68
|
+
export type { Signature } from "@tevm/voltaire/Siwe";
|
|
69
|
+
|
|
70
|
+
// Errors (re-export from voltaire)
|
|
45
71
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
InvalidFieldError,
|
|
73
|
+
InvalidNonceLengthError,
|
|
74
|
+
InvalidSiweMessageError,
|
|
75
|
+
MissingFieldError,
|
|
76
|
+
SiweParseError,
|
|
77
|
+
} from "@tevm/voltaire/Siwe";
|
|
78
|
+
|
|
79
|
+
// Schemas
|
|
80
|
+
export { MessageStruct, Schema, SiweMessageSchema, String } from "./String.js";
|
|
81
|
+
|
|
82
|
+
// Constructors (Effect-wrapped)
|
|
83
|
+
export { create } from "./create.js";
|
|
84
|
+
export { parse } from "./parse.js";
|
|
85
|
+
|
|
86
|
+
// Verification (Effect-wrapped)
|
|
87
|
+
export { verify, verifyMessage } from "./verify.js";
|
|
88
|
+
export { getMessageHash, GetMessageHash, Verify, VerifyMessage } from "./hash.js";
|
|
89
|
+
|
|
90
|
+
// Pure Functions (re-export)
|
|
91
|
+
export { format, generateNonce, validate } from "./String.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module parse
|
|
3
|
+
* @description Effect-wrapped SIWE parsing
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Siwe } from "@tevm/voltaire";
|
|
8
|
+
import type { SiweMessageType } from "./String.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse SIWE message from formatted string
|
|
12
|
+
*
|
|
13
|
+
* @param text - Formatted SIWE message string
|
|
14
|
+
* @returns Effect yielding SiweMessageType
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const message = await Effect.runPromise(Siwe.parse(`example.com wants you to sign in...`))
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const parse = (text: string): Effect.Effect<SiweMessageType, Error> =>
|
|
21
|
+
Effect.try({
|
|
22
|
+
try: () => Siwe.parse(text),
|
|
23
|
+
catch: (e) => e as Error,
|
|
24
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module verify
|
|
3
|
+
* @description Effect-wrapped SIWE verification
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Siwe } from "@tevm/voltaire";
|
|
8
|
+
import type { SiweMessageType } from "./String.js";
|
|
9
|
+
import type { Signature as SiweSignature } from "@tevm/voltaire/Siwe";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verify SIWE message signature
|
|
13
|
+
*
|
|
14
|
+
* @param message - SIWE message to verify
|
|
15
|
+
* @param signature - Signature to verify against (65 bytes: r(32) + s(32) + v(1))
|
|
16
|
+
* @returns Effect yielding boolean
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const isValid = await Effect.runPromise(Siwe.verify(message, signature))
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const verify = (
|
|
23
|
+
message: SiweMessageType,
|
|
24
|
+
signature: SiweSignature,
|
|
25
|
+
): Effect.Effect<boolean, Error> =>
|
|
26
|
+
Effect.try({
|
|
27
|
+
try: () => Siwe.verify(message, signature),
|
|
28
|
+
catch: (e) => e as Error,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Verify SIWE message with full validation
|
|
33
|
+
*
|
|
34
|
+
* @param message - SIWE message to verify
|
|
35
|
+
* @param signature - Signature to verify against
|
|
36
|
+
* @param options - Verification options
|
|
37
|
+
* @returns Effect yielding ValidationResult
|
|
38
|
+
*/
|
|
39
|
+
export const verifyMessage = (
|
|
40
|
+
message: SiweMessageType,
|
|
41
|
+
signature: SiweSignature,
|
|
42
|
+
options?: { now?: Date },
|
|
43
|
+
): Effect.Effect<ReturnType<typeof Siwe.verifyMessage>, Error> =>
|
|
44
|
+
Effect.try({
|
|
45
|
+
try: () => Siwe.verifyMessage(message, signature, options),
|
|
46
|
+
catch: (e) => e as Error,
|
|
47
|
+
});
|