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,21 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if value is RLP list data.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @returns True if value is RLP list data structure
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isListData } from 'voltaire-effect/primitives/Rlp'
|
|
12
|
+
*
|
|
13
|
+
* isListData({ type: 'list', value: [] }) // => true
|
|
14
|
+
* isListData({ type: 'bytes', value: new Uint8Array([1]) }) // => false
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @since 0.0.1
|
|
18
|
+
*/
|
|
19
|
+
export const isListData = (
|
|
20
|
+
value: unknown,
|
|
21
|
+
): value is BrandedRlp & { type: "list" } => VoltaireRlp.isListData(value);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RlpDecodingError,
|
|
3
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
4
|
+
Rlp as VoltaireRlp,
|
|
5
|
+
} from "@tevm/voltaire/Rlp";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
9
|
+
e instanceof RlpDecodingErrorClass ||
|
|
10
|
+
(e !== null &&
|
|
11
|
+
typeof e === "object" &&
|
|
12
|
+
"name" in e &&
|
|
13
|
+
e.name === "RlpDecodingError");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if RLP-encoded data represents a string (byte array).
|
|
17
|
+
*
|
|
18
|
+
* @param data - RLP-encoded data
|
|
19
|
+
* @returns Effect that succeeds with boolean or fails with RlpDecodingError
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import * as Effect from 'effect/Effect'
|
|
24
|
+
* import { isString } from 'voltaire-effect/primitives/Rlp'
|
|
25
|
+
*
|
|
26
|
+
* const bytes = new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
27
|
+
* Effect.runSync(isString(bytes)) // => true
|
|
28
|
+
*
|
|
29
|
+
* const list = new Uint8Array([0xc3, 0x01, 0x02, 0x03])
|
|
30
|
+
* Effect.runSync(isString(list)) // => false
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @since 0.0.1
|
|
34
|
+
*/
|
|
35
|
+
export const isString = (
|
|
36
|
+
data: Uint8Array,
|
|
37
|
+
): Effect.Effect<boolean, RlpDecodingError> =>
|
|
38
|
+
Effect.try({
|
|
39
|
+
try: () => VoltaireRlp.isString(data),
|
|
40
|
+
catch: (e) =>
|
|
41
|
+
isRlpDecodingError(e)
|
|
42
|
+
? e
|
|
43
|
+
: new RlpDecodingErrorClass("isString check failed", {
|
|
44
|
+
cause: e instanceof Error ? e : undefined,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts RLP Data to human-readable JSON format.
|
|
5
|
+
*
|
|
6
|
+
* @param data - RLP data structure
|
|
7
|
+
* @returns JSON-serializable representation
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { toJSON } from 'voltaire-effect/primitives/Rlp'
|
|
12
|
+
*
|
|
13
|
+
* const data = { type: 'bytes', value: new Uint8Array([1, 2, 3]) }
|
|
14
|
+
* const json = toJSON(data)
|
|
15
|
+
* // => { type: 'bytes', value: [1, 2, 3] }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @since 0.0.1
|
|
19
|
+
*/
|
|
20
|
+
export const toJSON = (data: BrandedRlp): unknown => VoltaireRlp.toJSON(data);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts RLP Data structure to raw JavaScript values.
|
|
5
|
+
*
|
|
6
|
+
* @param data - RLP data structure to convert
|
|
7
|
+
* @returns Raw value (Uint8Array for bytes, array for list)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { toRaw } from 'voltaire-effect/primitives/Rlp'
|
|
12
|
+
*
|
|
13
|
+
* const data = { type: 'bytes', value: new Uint8Array([1, 2, 3]) }
|
|
14
|
+
* const raw = toRaw(data)
|
|
15
|
+
* // => Uint8Array([1, 2, 3])
|
|
16
|
+
*
|
|
17
|
+
* const listData = {
|
|
18
|
+
* type: 'list',
|
|
19
|
+
* value: [
|
|
20
|
+
* { type: 'bytes', value: new Uint8Array([1]) },
|
|
21
|
+
* { type: 'bytes', value: new Uint8Array([2]) }
|
|
22
|
+
* ]
|
|
23
|
+
* }
|
|
24
|
+
* const rawList = toRaw(listData)
|
|
25
|
+
* // => [Uint8Array([1]), Uint8Array([2])]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @since 0.0.1
|
|
29
|
+
*/
|
|
30
|
+
export const toRaw = (data: BrandedRlp): Uint8Array | unknown[] =>
|
|
31
|
+
VoltaireRlp.toRaw(data);
|
|
@@ -3,6 +3,8 @@ import { Hash } from "@tevm/voltaire";
|
|
|
3
3
|
import { PrivateKey } from "@tevm/voltaire/PrivateKey";
|
|
4
4
|
import * as Secp256k1 from "@tevm/voltaire/Secp256k1";
|
|
5
5
|
import * as BaseSignature from "@tevm/voltaire/Signature";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Either from "effect/Either";
|
|
6
8
|
import * as S from "effect/Schema";
|
|
7
9
|
import * as Signature from "./index.js";
|
|
8
10
|
|
|
@@ -494,3 +496,218 @@ describe("signature component validation", () => {
|
|
|
494
496
|
expect(BaseSignature.verify(sig, messageHash, publicKey)).toBe(false);
|
|
495
497
|
});
|
|
496
498
|
});
|
|
499
|
+
|
|
500
|
+
describe("new pure functions", () => {
|
|
501
|
+
const sig = S.decodeSync(Signature.Hex)(validSig65);
|
|
502
|
+
|
|
503
|
+
describe("getR", () => {
|
|
504
|
+
it("returns 32-byte R component", () => {
|
|
505
|
+
const r = Signature.getR(sig);
|
|
506
|
+
expect(r).toBeInstanceOf(Uint8Array);
|
|
507
|
+
expect(r.length).toBe(32);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
describe("getS", () => {
|
|
512
|
+
it("returns 32-byte S component", () => {
|
|
513
|
+
const s = Signature.getS(sig);
|
|
514
|
+
expect(s).toBeInstanceOf(Uint8Array);
|
|
515
|
+
expect(s.length).toBe(32);
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
describe("getV", () => {
|
|
520
|
+
it("returns recovery value for secp256k1", () => {
|
|
521
|
+
const v = Signature.getV(sig);
|
|
522
|
+
expect(v).toBe(27);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("returns derived v for 64-byte signature", () => {
|
|
526
|
+
const sig64 = S.decodeSync(Signature.Hex)(validSig64);
|
|
527
|
+
const v = Signature.getV(sig64);
|
|
528
|
+
expect(typeof v === "number" || v === undefined).toBe(true);
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
describe("toHex", () => {
|
|
533
|
+
it("returns hex string with prefix", () => {
|
|
534
|
+
const hex = Signature.toHex(sig);
|
|
535
|
+
expect(hex.startsWith("0x")).toBe(true);
|
|
536
|
+
expect(hex.length).toBe(132); // 0x + 130 chars
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
describe("toDER", () => {
|
|
541
|
+
it("returns DER-encoded bytes", () => {
|
|
542
|
+
const der = Signature.toDER(sig);
|
|
543
|
+
expect(der).toBeInstanceOf(Uint8Array);
|
|
544
|
+
expect(der[0]).toBe(0x30); // DER sequence tag
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
describe("toRpc", () => {
|
|
549
|
+
it("returns RPC format object", () => {
|
|
550
|
+
const rpc = Signature.toRpc(sig);
|
|
551
|
+
expect(rpc.r).toBeDefined();
|
|
552
|
+
expect(rpc.s).toBeDefined();
|
|
553
|
+
expect(typeof rpc.r).toBe("string");
|
|
554
|
+
expect(typeof rpc.s).toBe("string");
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
describe("toTuple", () => {
|
|
559
|
+
it("returns [yParity, r, s] tuple", () => {
|
|
560
|
+
const tuple = Signature.toTuple(sig);
|
|
561
|
+
expect(Array.isArray(tuple)).toBe(true);
|
|
562
|
+
expect(tuple.length).toBe(3);
|
|
563
|
+
expect(typeof tuple[0]).toBe("number");
|
|
564
|
+
expect(tuple[1]).toBeInstanceOf(Uint8Array);
|
|
565
|
+
expect(tuple[2]).toBeInstanceOf(Uint8Array);
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
describe("verify", () => {
|
|
570
|
+
it("verifies valid signature", () => {
|
|
571
|
+
const messageHash = Hash.from(new Uint8Array(32).fill(0x42));
|
|
572
|
+
const privateKey = PrivateKey.fromBytes(new Uint8Array(32).fill(1));
|
|
573
|
+
const publicKey = Secp256k1.derivePublicKey(privateKey);
|
|
574
|
+
const secpSig = Secp256k1.sign(messageHash, privateKey);
|
|
575
|
+
const sig = BaseSignature.fromSecp256k1(secpSig.r, secpSig.s, secpSig.v);
|
|
576
|
+
expect(Signature.verify(sig, messageHash, publicKey)).toBe(true);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("rejects invalid signature", () => {
|
|
580
|
+
const messageHash = Hash.from(new Uint8Array(32).fill(0x42));
|
|
581
|
+
const privateKey = PrivateKey.fromBytes(new Uint8Array(32).fill(1));
|
|
582
|
+
const publicKey = Secp256k1.derivePublicKey(privateKey);
|
|
583
|
+
const invalidSig = BaseSignature.fromSecp256k1(
|
|
584
|
+
new Uint8Array(32).fill(0x11),
|
|
585
|
+
new Uint8Array(32).fill(0x22),
|
|
586
|
+
27,
|
|
587
|
+
);
|
|
588
|
+
expect(Signature.verify(invalidSig, messageHash, publicKey)).toBe(false);
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
describe("Effect-wrapped from* functions", () => {
|
|
594
|
+
describe("fromHex", () => {
|
|
595
|
+
it.effect("parses valid hex", () =>
|
|
596
|
+
Effect.gen(function* () {
|
|
597
|
+
const sig = yield* Signature.fromHex(validSig65);
|
|
598
|
+
expect(Signature.is(sig)).toBe(true);
|
|
599
|
+
}),
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
it.effect("fails on invalid hex", () =>
|
|
603
|
+
Effect.gen(function* () {
|
|
604
|
+
const result = yield* Effect.either(Signature.fromHex("invalid"));
|
|
605
|
+
expect(Either.isLeft(result)).toBe(true);
|
|
606
|
+
}),
|
|
607
|
+
);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
describe("fromBytes", () => {
|
|
611
|
+
it.effect("parses valid bytes", () =>
|
|
612
|
+
Effect.gen(function* () {
|
|
613
|
+
const bytes = new Uint8Array(64).fill(0xab);
|
|
614
|
+
const sig = yield* Signature.fromBytes(bytes);
|
|
615
|
+
expect(Signature.is(sig)).toBe(true);
|
|
616
|
+
}),
|
|
617
|
+
);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
describe("fromCompact", () => {
|
|
621
|
+
it.effect("parses compact format", () =>
|
|
622
|
+
Effect.gen(function* () {
|
|
623
|
+
const compact = new Uint8Array(64).fill(0xab);
|
|
624
|
+
const sig = yield* Signature.fromCompact(compact, "secp256k1");
|
|
625
|
+
expect(Signature.is(sig)).toBe(true);
|
|
626
|
+
}),
|
|
627
|
+
);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
describe("fromDER", () => {
|
|
631
|
+
it.effect("parses DER format", () =>
|
|
632
|
+
Effect.gen(function* () {
|
|
633
|
+
const validDER = new Uint8Array([
|
|
634
|
+
0x30,
|
|
635
|
+
0x44,
|
|
636
|
+
0x02,
|
|
637
|
+
0x20,
|
|
638
|
+
...new Uint8Array(32).fill(0x01),
|
|
639
|
+
0x02,
|
|
640
|
+
0x20,
|
|
641
|
+
...new Uint8Array(32).fill(0x02),
|
|
642
|
+
]);
|
|
643
|
+
const sig = yield* Signature.fromDER(validDER, "secp256k1");
|
|
644
|
+
expect(Signature.is(sig)).toBe(true);
|
|
645
|
+
}),
|
|
646
|
+
);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe("fromRpc", () => {
|
|
650
|
+
it.effect("parses RPC format", () =>
|
|
651
|
+
Effect.gen(function* () {
|
|
652
|
+
const sig = yield* Signature.fromRpc({
|
|
653
|
+
r: `0x${validR}`,
|
|
654
|
+
s: `0x${validS}`,
|
|
655
|
+
yParity: 0,
|
|
656
|
+
});
|
|
657
|
+
expect(Signature.is(sig)).toBe(true);
|
|
658
|
+
}),
|
|
659
|
+
);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
describe("fromTuple", () => {
|
|
663
|
+
it.effect("parses tuple format", () =>
|
|
664
|
+
Effect.gen(function* () {
|
|
665
|
+
const r = new Uint8Array(32).fill(0xab);
|
|
666
|
+
const s = new Uint8Array(32).fill(0xcd);
|
|
667
|
+
const sig = yield* Signature.fromTuple([0, r, s]);
|
|
668
|
+
expect(Signature.is(sig)).toBe(true);
|
|
669
|
+
}),
|
|
670
|
+
);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
describe("from", () => {
|
|
674
|
+
it.effect("parses from bytes", () =>
|
|
675
|
+
Effect.gen(function* () {
|
|
676
|
+
const bytes = new Uint8Array(64).fill(0xab);
|
|
677
|
+
const sig = yield* Signature.from(bytes);
|
|
678
|
+
expect(Signature.is(sig)).toBe(true);
|
|
679
|
+
}),
|
|
680
|
+
);
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
describe("constructor functions", () => {
|
|
685
|
+
describe("fromSecp256k1", () => {
|
|
686
|
+
it("creates secp256k1 signature", () => {
|
|
687
|
+
const r = new Uint8Array(32).fill(0x11);
|
|
688
|
+
const s = new Uint8Array(32).fill(0x22);
|
|
689
|
+
const sig = Signature.fromSecp256k1(r, s, 27);
|
|
690
|
+
expect(Signature.is(sig)).toBe(true);
|
|
691
|
+
expect(Signature.getAlgorithm(sig)).toBe("secp256k1");
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
describe("fromP256", () => {
|
|
696
|
+
it("creates p256 signature", () => {
|
|
697
|
+
const r = new Uint8Array(32).fill(0x11);
|
|
698
|
+
const s = new Uint8Array(32).fill(0x22);
|
|
699
|
+
const sig = Signature.fromP256(r, s);
|
|
700
|
+
expect(Signature.is(sig)).toBe(true);
|
|
701
|
+
expect(Signature.getAlgorithm(sig)).toBe("p256");
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
describe("fromEd25519", () => {
|
|
706
|
+
it("creates ed25519 signature", () => {
|
|
707
|
+
const bytes = new Uint8Array(64).fill(0x33);
|
|
708
|
+
const sig = Signature.fromEd25519(bytes);
|
|
709
|
+
expect(Signature.is(sig)).toBe(true);
|
|
710
|
+
expect(Signature.getAlgorithm(sig)).toBe("ed25519");
|
|
711
|
+
});
|
|
712
|
+
});
|
|
713
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from various inputs with Effect error handling.
|
|
3
|
+
* @module Signature/from
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from various input formats.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Input value (bytes or signature object with r, s, v)
|
|
13
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
18
|
+
* import { Effect } from 'effect'
|
|
19
|
+
*
|
|
20
|
+
* const sig = Effect.runSync(Signature.from(signatureBytes))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
*/
|
|
25
|
+
export const from = (
|
|
26
|
+
value:
|
|
27
|
+
| Uint8Array
|
|
28
|
+
| {
|
|
29
|
+
r: Uint8Array;
|
|
30
|
+
s: Uint8Array;
|
|
31
|
+
v?: number;
|
|
32
|
+
algorithm?: "secp256k1" | "p256" | "ed25519";
|
|
33
|
+
},
|
|
34
|
+
): Effect.Effect<SignatureType, Error> =>
|
|
35
|
+
Effect.try({
|
|
36
|
+
try: () => Signature.from(value),
|
|
37
|
+
catch: (e) => e as Error,
|
|
38
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from bytes with Effect error handling.
|
|
3
|
+
* @module Signature/fromBytes
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from raw bytes.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - 64 or 65 byte array (r + s, optionally + v)
|
|
13
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
18
|
+
* import { Effect } from 'effect'
|
|
19
|
+
*
|
|
20
|
+
* const sig = Effect.runSync(Signature.fromBytes(new Uint8Array(65)))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
*/
|
|
25
|
+
export const fromBytes = (
|
|
26
|
+
bytes: Uint8Array,
|
|
27
|
+
): Effect.Effect<SignatureType, Error> =>
|
|
28
|
+
Effect.try({
|
|
29
|
+
try: () => Signature.fromBytes(bytes),
|
|
30
|
+
catch: (e) => e as Error,
|
|
31
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from EIP-2098 compact format with Effect error handling.
|
|
3
|
+
* @module Signature/fromCompact
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from EIP-2098 compact format.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - 64-byte compact signature
|
|
13
|
+
* @param algorithmOrV - Algorithm ('secp256k1' | 'p256') or explicit v value
|
|
14
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
19
|
+
* import { Effect } from 'effect'
|
|
20
|
+
*
|
|
21
|
+
* const sig = Effect.runSync(Signature.fromCompact(compactBytes, 'secp256k1'))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
*/
|
|
26
|
+
export const fromCompact = (
|
|
27
|
+
bytes: Uint8Array,
|
|
28
|
+
algorithmOrV: "secp256k1" | "p256" | number = "secp256k1",
|
|
29
|
+
): Effect.Effect<SignatureType, Error> =>
|
|
30
|
+
Effect.try({
|
|
31
|
+
try: () => Signature.fromCompact(bytes, algorithmOrV),
|
|
32
|
+
catch: (e) => e as Error,
|
|
33
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from DER format with Effect error handling.
|
|
3
|
+
* @module Signature/fromDER
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from DER-encoded bytes.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - DER-encoded signature
|
|
13
|
+
* @param algorithm - Algorithm ('secp256k1' | 'p256')
|
|
14
|
+
* @param v - Optional recovery value for secp256k1
|
|
15
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
20
|
+
* import { Effect } from 'effect'
|
|
21
|
+
*
|
|
22
|
+
* const sig = Effect.runSync(Signature.fromDER(derBytes, 'secp256k1'))
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
*/
|
|
27
|
+
export const fromDER = (
|
|
28
|
+
bytes: Uint8Array,
|
|
29
|
+
algorithm: "secp256k1" | "p256" = "secp256k1",
|
|
30
|
+
v?: number,
|
|
31
|
+
): Effect.Effect<SignatureType, Error> =>
|
|
32
|
+
Effect.try({
|
|
33
|
+
try: () => Signature.fromDER(bytes, algorithm, v),
|
|
34
|
+
catch: (e) => e as Error,
|
|
35
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from Ed25519 bytes.
|
|
3
|
+
* @module Signature/fromEd25519
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates an Ed25519 Signature from 64-byte signature.
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - 64-byte Ed25519 signature
|
|
12
|
+
* @returns SignatureType with ed25519 algorithm
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
17
|
+
*
|
|
18
|
+
* const sig = Signature.fromEd25519(signatureBytes)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const fromEd25519 = (bytes: Uint8Array): SignatureType =>
|
|
24
|
+
Signature.fromEd25519(bytes);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from hex string with Effect error handling.
|
|
3
|
+
* @module Signature/fromHex
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from a hex string.
|
|
11
|
+
*
|
|
12
|
+
* @param hex - Hex string (64 or 65 bytes with 0x prefix)
|
|
13
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
18
|
+
* import { Effect } from 'effect'
|
|
19
|
+
*
|
|
20
|
+
* const sig = Effect.runSync(Signature.fromHex('0x' + 'ab'.repeat(32) + 'cd'.repeat(32) + '1b'))
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
*/
|
|
25
|
+
export const fromHex = (hex: string): Effect.Effect<SignatureType, Error> =>
|
|
26
|
+
Effect.try({
|
|
27
|
+
try: () => Signature.fromHex(hex),
|
|
28
|
+
catch: (e) => e as Error,
|
|
29
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from P-256 components.
|
|
3
|
+
* @module Signature/fromP256
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a P-256 Signature from r and s components.
|
|
10
|
+
*
|
|
11
|
+
* @param r - 32-byte R component
|
|
12
|
+
* @param s - 32-byte S component
|
|
13
|
+
* @returns SignatureType with p256 algorithm
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
18
|
+
*
|
|
19
|
+
* const sig = Signature.fromP256(r, s)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
*/
|
|
24
|
+
export const fromP256 = (r: Uint8Array, s: Uint8Array): SignatureType =>
|
|
25
|
+
Signature.fromP256(r, s);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from RPC format with Effect error handling.
|
|
3
|
+
* @module Signature/fromRpc
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from Ethereum RPC format.
|
|
11
|
+
*
|
|
12
|
+
* @param rpc - RPC signature object with r, s, and optionally yParity or v
|
|
13
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
18
|
+
* import { Effect } from 'effect'
|
|
19
|
+
*
|
|
20
|
+
* const sig = Effect.runSync(Signature.fromRpc({
|
|
21
|
+
* r: '0x...',
|
|
22
|
+
* s: '0x...',
|
|
23
|
+
* yParity: '0x0'
|
|
24
|
+
* }))
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @since 0.0.1
|
|
28
|
+
*/
|
|
29
|
+
export const fromRpc = (rpc: {
|
|
30
|
+
r: string;
|
|
31
|
+
s: string;
|
|
32
|
+
yParity?: string | number;
|
|
33
|
+
v?: string | number;
|
|
34
|
+
}): Effect.Effect<SignatureType, Error> =>
|
|
35
|
+
Effect.try({
|
|
36
|
+
try: () => Signature.fromRpc(rpc),
|
|
37
|
+
catch: (e) => e as Error,
|
|
38
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from secp256k1 components.
|
|
3
|
+
* @module Signature/fromSecp256k1
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a secp256k1 Signature from r, s, and v components.
|
|
10
|
+
*
|
|
11
|
+
* @param r - 32-byte R component
|
|
12
|
+
* @param s - 32-byte S component
|
|
13
|
+
* @param v - Recovery value (27, 28, or chainId-derived)
|
|
14
|
+
* @returns SignatureType with secp256k1 algorithm
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
19
|
+
*
|
|
20
|
+
* const sig = Signature.fromSecp256k1(r, s, 27)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
*/
|
|
25
|
+
export const fromSecp256k1 = (
|
|
26
|
+
r: Uint8Array,
|
|
27
|
+
s: Uint8Array,
|
|
28
|
+
v: number,
|
|
29
|
+
): SignatureType => Signature.fromSecp256k1(r, s, v);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Creates Signature from tuple format with Effect error handling.
|
|
3
|
+
* @module Signature/fromTuple
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
import { Signature, type SignatureType } from "@tevm/voltaire/Signature";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Signature from tuple format [yParity, r, s].
|
|
11
|
+
*
|
|
12
|
+
* @param tuple - Tuple of [yParity (0 or 1), r (32 bytes), s (32 bytes)]
|
|
13
|
+
* @param chainId - Optional chain ID for v value calculation
|
|
14
|
+
* @returns Effect that succeeds with SignatureType or fails with parse error
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import * as Signature from 'voltaire-effect/primitives/Signature'
|
|
19
|
+
* import { Effect } from 'effect'
|
|
20
|
+
*
|
|
21
|
+
* const sig = Effect.runSync(Signature.fromTuple([0, r, s]))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
*/
|
|
26
|
+
export const fromTuple = (
|
|
27
|
+
tuple: [number, Uint8Array, Uint8Array],
|
|
28
|
+
chainId?: number,
|
|
29
|
+
): Effect.Effect<SignatureType, Error> =>
|
|
30
|
+
Effect.try({
|
|
31
|
+
try: () => Signature.fromTuple(tuple, chainId),
|
|
32
|
+
catch: (e) => e as Error,
|
|
33
|
+
});
|