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
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
*
|
|
49
49
|
* ```typescript
|
|
50
50
|
* Transaction.hash(tx) // HashType
|
|
51
|
-
* Transaction.
|
|
51
|
+
* Transaction.getSigningHash(tx) // HashType
|
|
52
52
|
* Transaction.getSender(tx) // AddressType
|
|
53
53
|
* Transaction.getRecipient(tx) // AddressType | null
|
|
54
54
|
* Transaction.getChainId(tx) // bigint | null
|
|
@@ -58,11 +58,44 @@
|
|
|
58
58
|
* Transaction.detectType(bytes) // Type
|
|
59
59
|
* ```
|
|
60
60
|
*
|
|
61
|
+
* ## Type Guards
|
|
62
|
+
*
|
|
63
|
+
* ```typescript
|
|
64
|
+
* Transaction.isLegacy(tx) // tx is Legacy
|
|
65
|
+
* Transaction.isEIP1559(tx) // tx is EIP1559
|
|
66
|
+
* Transaction.isEIP2930(tx) // tx is EIP2930
|
|
67
|
+
* Transaction.isEIP4844(tx) // tx is EIP4844
|
|
68
|
+
* Transaction.isEIP7702(tx) // tx is EIP7702
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* ## Effect-Returning Functions (Validation)
|
|
72
|
+
*
|
|
73
|
+
* ```typescript
|
|
74
|
+
* Transaction.assertSigned(tx) // Effect<void, UnsignedTransactionError>
|
|
75
|
+
* Transaction.verifySignature(tx) // Effect<boolean, InvalidSignatureError>
|
|
76
|
+
* Transaction.validateChainId(tx) // Effect<void, InvalidChainIdError>
|
|
77
|
+
* Transaction.validateGasLimit(tx) // Effect<void, InvalidGasLimitError>
|
|
78
|
+
* Transaction.validateGasPrice(tx) // Effect<void, InvalidGasPriceError>
|
|
79
|
+
* Transaction.validateNonce(tx) // Effect<void, InvalidNonceError>
|
|
80
|
+
* Transaction.validateValue(tx) // Effect<void, InvalidValueError>
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* ## Mutation (returns new transaction)
|
|
84
|
+
*
|
|
85
|
+
* ```typescript
|
|
86
|
+
* Transaction.withNonce(tx, nonce) // Any
|
|
87
|
+
* Transaction.withGasLimit(tx, limit) // Any
|
|
88
|
+
* Transaction.withGasPrice(tx, price) // Any
|
|
89
|
+
* Transaction.withData(tx, data) // Any
|
|
90
|
+
* Transaction.replaceWith(tx, opts) // Any
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
61
93
|
* @since 0.1.0
|
|
62
94
|
*/
|
|
63
95
|
import type { AddressType } from "@tevm/voltaire/Address";
|
|
64
96
|
import type { HashType } from "@tevm/voltaire/Hash";
|
|
65
97
|
import * as VoltaireTransaction from "@tevm/voltaire/Transaction";
|
|
98
|
+
import * as Effect from "effect/Effect";
|
|
66
99
|
|
|
67
100
|
/**
|
|
68
101
|
* Union type of all supported Ethereum transaction types.
|
|
@@ -148,6 +181,15 @@ export {
|
|
|
148
181
|
Schema,
|
|
149
182
|
} from "./TransactionSchema.js";
|
|
150
183
|
|
|
184
|
+
// Re-export types from voltaire
|
|
185
|
+
export type {
|
|
186
|
+
AccessList,
|
|
187
|
+
AccessListItem,
|
|
188
|
+
AuthorizationList,
|
|
189
|
+
ReplaceOptions,
|
|
190
|
+
VersionedHash,
|
|
191
|
+
} from "@tevm/voltaire/Transaction";
|
|
192
|
+
|
|
151
193
|
// Pure functions
|
|
152
194
|
|
|
153
195
|
/**
|
|
@@ -168,9 +210,14 @@ export const hash = (tx: Any): HashType => VoltaireTransaction.hash(tx);
|
|
|
168
210
|
*
|
|
169
211
|
* @since 0.1.0
|
|
170
212
|
*/
|
|
171
|
-
export const
|
|
213
|
+
export const getSigningHash = (tx: Any): HashType =>
|
|
172
214
|
VoltaireTransaction.getSigningHash(tx);
|
|
173
215
|
|
|
216
|
+
/**
|
|
217
|
+
* @deprecated Use getSigningHash instead
|
|
218
|
+
*/
|
|
219
|
+
export const signingHash = getSigningHash;
|
|
220
|
+
|
|
174
221
|
/**
|
|
175
222
|
* Recovers the sender address from the transaction signature.
|
|
176
223
|
*
|
|
@@ -287,3 +334,421 @@ export const isSigned = (tx: Any): boolean => VoltaireTransaction.isSigned(tx);
|
|
|
287
334
|
*/
|
|
288
335
|
export const detectType = (data: Uint8Array): VoltaireTransaction.Type =>
|
|
289
336
|
VoltaireTransaction.detectType(data);
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Checks if transaction is a contract call.
|
|
340
|
+
*
|
|
341
|
+
* @param tx - Transaction object
|
|
342
|
+
* @returns true if to is set and data is non-empty
|
|
343
|
+
*
|
|
344
|
+
* @since 0.1.0
|
|
345
|
+
*/
|
|
346
|
+
export const isContractCall = (tx: Any): boolean =>
|
|
347
|
+
VoltaireTransaction.isContractCall(tx);
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Checks if transaction has an access list.
|
|
351
|
+
*
|
|
352
|
+
* @param tx - Transaction object
|
|
353
|
+
* @returns true if transaction type supports and has access list
|
|
354
|
+
*
|
|
355
|
+
* @since 0.1.0
|
|
356
|
+
*/
|
|
357
|
+
export const hasAccessList = (tx: Any): boolean =>
|
|
358
|
+
VoltaireTransaction.hasAccessList(tx);
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Gets the access list from transaction.
|
|
362
|
+
*
|
|
363
|
+
* @param tx - Transaction object
|
|
364
|
+
* @returns Access list (empty array for legacy transactions)
|
|
365
|
+
*
|
|
366
|
+
* @since 0.1.0
|
|
367
|
+
*/
|
|
368
|
+
export const getAccessList = (
|
|
369
|
+
tx: Any,
|
|
370
|
+
): VoltaireTransaction.AccessList => VoltaireTransaction.getAccessList(tx);
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Gets blob count for EIP-4844 transactions.
|
|
374
|
+
*
|
|
375
|
+
* @param tx - EIP-4844 transaction
|
|
376
|
+
* @returns Number of blobs
|
|
377
|
+
*
|
|
378
|
+
* @since 0.1.0
|
|
379
|
+
*/
|
|
380
|
+
export const getBlobCount = (tx: EIP4844): number =>
|
|
381
|
+
VoltaireTransaction.getBlobCount(tx);
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Gets blob versioned hashes for EIP-4844 transactions.
|
|
385
|
+
*
|
|
386
|
+
* @param tx - EIP-4844 transaction
|
|
387
|
+
* @returns Array of versioned hashes
|
|
388
|
+
*
|
|
389
|
+
* @since 0.1.0
|
|
390
|
+
*/
|
|
391
|
+
export const getBlobVersionedHashes = (
|
|
392
|
+
tx: EIP4844,
|
|
393
|
+
): readonly VoltaireTransaction.VersionedHash[] =>
|
|
394
|
+
VoltaireTransaction.getBlobVersionedHashes(tx);
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Gets authorization count for EIP-7702 transactions.
|
|
398
|
+
*
|
|
399
|
+
* @param tx - EIP-7702 transaction
|
|
400
|
+
* @returns Number of authorizations
|
|
401
|
+
*
|
|
402
|
+
* @since 0.1.0
|
|
403
|
+
*/
|
|
404
|
+
export const getAuthorizationCount = (tx: EIP7702): number =>
|
|
405
|
+
VoltaireTransaction.getAuthorizationCount(tx);
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Gets authorization list for EIP-7702 transactions.
|
|
409
|
+
*
|
|
410
|
+
* @param tx - EIP-7702 transaction
|
|
411
|
+
* @returns Authorization list
|
|
412
|
+
*
|
|
413
|
+
* @since 0.1.0
|
|
414
|
+
*/
|
|
415
|
+
export const getAuthorizations = (
|
|
416
|
+
tx: EIP7702,
|
|
417
|
+
): VoltaireTransaction.AuthorizationList =>
|
|
418
|
+
VoltaireTransaction.getAuthorizations(tx);
|
|
419
|
+
|
|
420
|
+
// Type Guards
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Type guard for Legacy transactions.
|
|
424
|
+
*
|
|
425
|
+
* @param tx - Transaction object
|
|
426
|
+
* @returns true if Legacy type
|
|
427
|
+
*
|
|
428
|
+
* @since 0.1.0
|
|
429
|
+
*/
|
|
430
|
+
export const isLegacy = (tx: Any): tx is Legacy =>
|
|
431
|
+
VoltaireTransaction.isLegacy(tx);
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Type guard for EIP-2930 transactions.
|
|
435
|
+
*
|
|
436
|
+
* @param tx - Transaction object
|
|
437
|
+
* @returns true if EIP-2930 type
|
|
438
|
+
*
|
|
439
|
+
* @since 0.1.0
|
|
440
|
+
*/
|
|
441
|
+
export const isEIP2930 = (tx: Any): tx is EIP2930 =>
|
|
442
|
+
VoltaireTransaction.isEIP2930(tx);
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Type guard for EIP-1559 transactions.
|
|
446
|
+
*
|
|
447
|
+
* @param tx - Transaction object
|
|
448
|
+
* @returns true if EIP-1559 type
|
|
449
|
+
*
|
|
450
|
+
* @since 0.1.0
|
|
451
|
+
*/
|
|
452
|
+
export const isEIP1559 = (tx: Any): tx is EIP1559 =>
|
|
453
|
+
VoltaireTransaction.isEIP1559(tx);
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Type guard for EIP-4844 transactions.
|
|
457
|
+
*
|
|
458
|
+
* @param tx - Transaction object
|
|
459
|
+
* @returns true if EIP-4844 type
|
|
460
|
+
*
|
|
461
|
+
* @since 0.1.0
|
|
462
|
+
*/
|
|
463
|
+
export const isEIP4844 = (tx: Any): tx is EIP4844 =>
|
|
464
|
+
VoltaireTransaction.isEIP4844(tx);
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Type guard for EIP-7702 transactions.
|
|
468
|
+
*
|
|
469
|
+
* @param tx - Transaction object
|
|
470
|
+
* @returns true if EIP-7702 type
|
|
471
|
+
*
|
|
472
|
+
* @since 0.1.0
|
|
473
|
+
*/
|
|
474
|
+
export const isEIP7702 = (tx: Any): tx is EIP7702 =>
|
|
475
|
+
VoltaireTransaction.isEIP7702(tx);
|
|
476
|
+
|
|
477
|
+
// Mutation functions (return new transaction)
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Returns new transaction with updated nonce.
|
|
481
|
+
*
|
|
482
|
+
* @param tx - Transaction object
|
|
483
|
+
* @param nonce - New nonce value
|
|
484
|
+
* @returns New transaction with updated nonce
|
|
485
|
+
*
|
|
486
|
+
* @since 0.1.0
|
|
487
|
+
*/
|
|
488
|
+
export const withNonce = (tx: Any, nonce: bigint): Any =>
|
|
489
|
+
VoltaireTransaction.withNonce(tx, nonce);
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Returns new transaction with updated gas limit.
|
|
493
|
+
*
|
|
494
|
+
* @param tx - Transaction object
|
|
495
|
+
* @param gasLimit - New gas limit
|
|
496
|
+
* @returns New transaction with updated gas limit
|
|
497
|
+
*
|
|
498
|
+
* @since 0.1.0
|
|
499
|
+
*/
|
|
500
|
+
export const withGasLimit = (tx: Any, gasLimit: bigint): Any =>
|
|
501
|
+
VoltaireTransaction.withGasLimit(tx, gasLimit);
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Returns new transaction with updated gas price.
|
|
505
|
+
*
|
|
506
|
+
* @param tx - Transaction object
|
|
507
|
+
* @param gasPrice - New gas price
|
|
508
|
+
* @returns New transaction with updated gas price
|
|
509
|
+
*
|
|
510
|
+
* @since 0.1.0
|
|
511
|
+
*/
|
|
512
|
+
export const withGasPrice = (tx: Any, gasPrice: bigint): Any =>
|
|
513
|
+
VoltaireTransaction.withGasPrice(tx, gasPrice);
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Returns new transaction with updated data.
|
|
517
|
+
*
|
|
518
|
+
* @param tx - Transaction object
|
|
519
|
+
* @param data - New data
|
|
520
|
+
* @returns New transaction with updated data
|
|
521
|
+
*
|
|
522
|
+
* @since 0.1.0
|
|
523
|
+
*/
|
|
524
|
+
export const withData = (tx: Any, data: Uint8Array): Any =>
|
|
525
|
+
VoltaireTransaction.withData(tx, data);
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Returns new transaction with fee bump for replacement.
|
|
529
|
+
*
|
|
530
|
+
* @param tx - Transaction object
|
|
531
|
+
* @param options - Replace options (fee bump percentage)
|
|
532
|
+
* @returns New transaction suitable for replacement
|
|
533
|
+
*
|
|
534
|
+
* @since 0.1.0
|
|
535
|
+
*/
|
|
536
|
+
export const replaceWith = (
|
|
537
|
+
tx: Any,
|
|
538
|
+
options?: VoltaireTransaction.ReplaceOptions,
|
|
539
|
+
): Any => VoltaireTransaction.replaceWith(tx, options);
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Formats transaction to human-readable string.
|
|
543
|
+
*
|
|
544
|
+
* @param tx - Transaction object
|
|
545
|
+
* @returns Formatted string representation
|
|
546
|
+
*
|
|
547
|
+
* @since 0.1.0
|
|
548
|
+
*/
|
|
549
|
+
export const format = (tx: Any): string => VoltaireTransaction.format(tx);
|
|
550
|
+
|
|
551
|
+
// Effect-returning functions (validation)
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Error thrown when transaction is not signed.
|
|
555
|
+
*
|
|
556
|
+
* @since 0.1.0
|
|
557
|
+
*/
|
|
558
|
+
export class UnsignedTransactionError extends Error {
|
|
559
|
+
readonly _tag = "UnsignedTransactionError";
|
|
560
|
+
constructor(message = "Transaction is not signed") {
|
|
561
|
+
super(message);
|
|
562
|
+
this.name = "UnsignedTransactionError";
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Error thrown when signature verification fails.
|
|
568
|
+
*
|
|
569
|
+
* @since 0.1.0
|
|
570
|
+
*/
|
|
571
|
+
export class InvalidSignatureError extends Error {
|
|
572
|
+
readonly _tag = "InvalidSignatureError";
|
|
573
|
+
constructor(message = "Invalid signature") {
|
|
574
|
+
super(message);
|
|
575
|
+
this.name = "InvalidSignatureError";
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Error thrown when chain ID validation fails.
|
|
581
|
+
*
|
|
582
|
+
* @since 0.1.0
|
|
583
|
+
*/
|
|
584
|
+
export class InvalidChainIdError extends Error {
|
|
585
|
+
readonly _tag = "InvalidChainIdError";
|
|
586
|
+
constructor(message = "Invalid chain ID") {
|
|
587
|
+
super(message);
|
|
588
|
+
this.name = "InvalidChainIdError";
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Error thrown when gas limit validation fails.
|
|
594
|
+
*
|
|
595
|
+
* @since 0.1.0
|
|
596
|
+
*/
|
|
597
|
+
export class InvalidGasLimitError extends Error {
|
|
598
|
+
readonly _tag = "InvalidGasLimitError";
|
|
599
|
+
constructor(message = "Invalid gas limit") {
|
|
600
|
+
super(message);
|
|
601
|
+
this.name = "InvalidGasLimitError";
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Error thrown when gas price validation fails.
|
|
607
|
+
*
|
|
608
|
+
* @since 0.1.0
|
|
609
|
+
*/
|
|
610
|
+
export class InvalidGasPriceError extends Error {
|
|
611
|
+
readonly _tag = "InvalidGasPriceError";
|
|
612
|
+
constructor(message = "Invalid gas price") {
|
|
613
|
+
super(message);
|
|
614
|
+
this.name = "InvalidGasPriceError";
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Error thrown when nonce validation fails.
|
|
620
|
+
*
|
|
621
|
+
* @since 0.1.0
|
|
622
|
+
*/
|
|
623
|
+
export class InvalidNonceError extends Error {
|
|
624
|
+
readonly _tag = "InvalidNonceError";
|
|
625
|
+
constructor(message = "Invalid nonce") {
|
|
626
|
+
super(message);
|
|
627
|
+
this.name = "InvalidNonceError";
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Error thrown when value validation fails.
|
|
633
|
+
*
|
|
634
|
+
* @since 0.1.0
|
|
635
|
+
*/
|
|
636
|
+
export class InvalidValueError extends Error {
|
|
637
|
+
readonly _tag = "InvalidValueError";
|
|
638
|
+
constructor(message = "Invalid value") {
|
|
639
|
+
super(message);
|
|
640
|
+
this.name = "InvalidValueError";
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Asserts transaction is signed, returning Effect that fails if not.
|
|
646
|
+
*
|
|
647
|
+
* @param tx - Transaction object
|
|
648
|
+
* @returns Effect that succeeds if signed, fails with UnsignedTransactionError otherwise
|
|
649
|
+
*
|
|
650
|
+
* @since 0.1.0
|
|
651
|
+
*/
|
|
652
|
+
export const assertSigned = (
|
|
653
|
+
tx: Any,
|
|
654
|
+
): Effect.Effect<void, UnsignedTransactionError> =>
|
|
655
|
+
Effect.try({
|
|
656
|
+
try: () => VoltaireTransaction.assertSigned(tx),
|
|
657
|
+
catch: (e) => new UnsignedTransactionError((e as Error).message),
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Verifies transaction signature, returning Effect.
|
|
662
|
+
*
|
|
663
|
+
* @param tx - Transaction object
|
|
664
|
+
* @returns Effect with boolean result or InvalidSignatureError
|
|
665
|
+
*
|
|
666
|
+
* @since 0.1.0
|
|
667
|
+
*/
|
|
668
|
+
export const verifySignature = (
|
|
669
|
+
tx: Any,
|
|
670
|
+
): Effect.Effect<boolean, InvalidSignatureError> =>
|
|
671
|
+
Effect.try({
|
|
672
|
+
try: () => VoltaireTransaction.verifySignature(tx),
|
|
673
|
+
catch: (e) => new InvalidSignatureError((e as Error).message),
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Validates chain ID, returning Effect that fails if invalid.
|
|
678
|
+
*
|
|
679
|
+
* @param tx - Transaction object
|
|
680
|
+
* @returns Effect that succeeds if valid, fails with InvalidChainIdError otherwise
|
|
681
|
+
*
|
|
682
|
+
* @since 0.1.0
|
|
683
|
+
*/
|
|
684
|
+
export const validateChainId = (
|
|
685
|
+
tx: Any,
|
|
686
|
+
): Effect.Effect<void, InvalidChainIdError> =>
|
|
687
|
+
Effect.try({
|
|
688
|
+
try: () => VoltaireTransaction.validateChainId(tx),
|
|
689
|
+
catch: (e) => new InvalidChainIdError((e as Error).message),
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Validates gas limit, returning Effect that fails if invalid.
|
|
694
|
+
*
|
|
695
|
+
* @param tx - Transaction object
|
|
696
|
+
* @returns Effect that succeeds if valid, fails with InvalidGasLimitError otherwise
|
|
697
|
+
*
|
|
698
|
+
* @since 0.1.0
|
|
699
|
+
*/
|
|
700
|
+
export const validateGasLimit = (
|
|
701
|
+
tx: Any,
|
|
702
|
+
): Effect.Effect<void, InvalidGasLimitError> =>
|
|
703
|
+
Effect.try({
|
|
704
|
+
try: () => VoltaireTransaction.validateGasLimit(tx),
|
|
705
|
+
catch: (e) => new InvalidGasLimitError((e as Error).message),
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Validates gas price, returning Effect that fails if invalid.
|
|
710
|
+
*
|
|
711
|
+
* @param tx - Transaction object
|
|
712
|
+
* @returns Effect that succeeds if valid, fails with InvalidGasPriceError otherwise
|
|
713
|
+
*
|
|
714
|
+
* @since 0.1.0
|
|
715
|
+
*/
|
|
716
|
+
export const validateGasPrice = (
|
|
717
|
+
tx: Any,
|
|
718
|
+
): Effect.Effect<void, InvalidGasPriceError> =>
|
|
719
|
+
Effect.try({
|
|
720
|
+
try: () => VoltaireTransaction.validateGasPrice(tx),
|
|
721
|
+
catch: (e) => new InvalidGasPriceError((e as Error).message),
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Validates nonce, returning Effect that fails if invalid.
|
|
726
|
+
*
|
|
727
|
+
* @param tx - Transaction object
|
|
728
|
+
* @returns Effect that succeeds if valid, fails with InvalidNonceError otherwise
|
|
729
|
+
*
|
|
730
|
+
* @since 0.1.0
|
|
731
|
+
*/
|
|
732
|
+
export const validateNonce = (
|
|
733
|
+
tx: Any,
|
|
734
|
+
): Effect.Effect<void, InvalidNonceError> =>
|
|
735
|
+
Effect.try({
|
|
736
|
+
try: () => VoltaireTransaction.validateNonce(tx),
|
|
737
|
+
catch: (e) => new InvalidNonceError((e as Error).message),
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Validates value, returning Effect that fails if invalid.
|
|
742
|
+
*
|
|
743
|
+
* @param tx - Transaction object
|
|
744
|
+
* @returns Effect that succeeds if valid, fails with InvalidValueError otherwise
|
|
745
|
+
*
|
|
746
|
+
* @since 0.1.0
|
|
747
|
+
*/
|
|
748
|
+
export const validateValue = (
|
|
749
|
+
tx: Any,
|
|
750
|
+
): Effect.Effect<void, InvalidValueError> =>
|
|
751
|
+
Effect.try({
|
|
752
|
+
try: () => VoltaireTransaction.validateValue(tx),
|
|
753
|
+
catch: (e) => new InvalidValueError((e as Error).message),
|
|
754
|
+
});
|
|
@@ -836,3 +836,203 @@ describe("additional edge cases", () => {
|
|
|
836
836
|
});
|
|
837
837
|
});
|
|
838
838
|
});
|
|
839
|
+
|
|
840
|
+
describe("constructor functions", () => {
|
|
841
|
+
describe("from", () => {
|
|
842
|
+
it("creates from bigint", () => {
|
|
843
|
+
const result = Effect.runSync(Uint.from(100n));
|
|
844
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(100n);
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it("creates from number", () => {
|
|
848
|
+
const result = Effect.runSync(Uint.from(42));
|
|
849
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(42n);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
it("creates from hex string", () => {
|
|
853
|
+
const result = Effect.runSync(Uint.from("0xff"));
|
|
854
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(255n);
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
it("creates from decimal string", () => {
|
|
858
|
+
const result = Effect.runSync(Uint.from("1000"));
|
|
859
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(1000n);
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
it("fails on negative", () => {
|
|
863
|
+
expect(() => Effect.runSync(Uint.from(-1n))).toThrow();
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
it("fails on overflow", () => {
|
|
867
|
+
expect(() => Effect.runSync(Uint.from(MAX_UINT256 + 1n))).toThrow();
|
|
868
|
+
});
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
describe("fromBigInt", () => {
|
|
872
|
+
it("creates from valid bigint", () => {
|
|
873
|
+
const result = Effect.runSync(Uint.fromBigInt(100n));
|
|
874
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(100n);
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
it("fails on negative", () => {
|
|
878
|
+
expect(() => Effect.runSync(Uint.fromBigInt(-1n))).toThrow();
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
describe("fromNumber", () => {
|
|
883
|
+
it("creates from valid number", () => {
|
|
884
|
+
const result = Effect.runSync(Uint.fromNumber(42));
|
|
885
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(42n);
|
|
886
|
+
});
|
|
887
|
+
|
|
888
|
+
it("fails on non-integer", () => {
|
|
889
|
+
expect(() => Effect.runSync(Uint.fromNumber(1.5))).toThrow();
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
it("fails on negative", () => {
|
|
893
|
+
expect(() => Effect.runSync(Uint.fromNumber(-1))).toThrow();
|
|
894
|
+
});
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
describe("fromHex", () => {
|
|
898
|
+
it("creates from hex with prefix", () => {
|
|
899
|
+
const result = Effect.runSync(Uint.fromHex("0xde0b6b3a7640000"));
|
|
900
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(1000000000000000000n);
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
it("creates from hex without prefix", () => {
|
|
904
|
+
const result = Effect.runSync(Uint.fromHex("ff"));
|
|
905
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(255n);
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it("fails on invalid hex", () => {
|
|
909
|
+
expect(() => Effect.runSync(Uint.fromHex("0xGGG"))).toThrow();
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
describe("fromBytes", () => {
|
|
914
|
+
it("creates from bytes", () => {
|
|
915
|
+
const result = Effect.runSync(Uint.fromBytes(new Uint8Array([0xff])));
|
|
916
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(255n);
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
it("creates from 32-byte array", () => {
|
|
920
|
+
const bytes = new Uint8Array(32).fill(0);
|
|
921
|
+
bytes[31] = 100;
|
|
922
|
+
const result = Effect.runSync(Uint.fromBytes(bytes));
|
|
923
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(100n);
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
describe("fromAbiEncoded", () => {
|
|
928
|
+
it("creates from 32-byte ABI-encoded data", () => {
|
|
929
|
+
const data = new Uint8Array(32).fill(0);
|
|
930
|
+
data[31] = 42;
|
|
931
|
+
const result = Effect.runSync(Uint.fromAbiEncoded(data));
|
|
932
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(42n);
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
describe("tryFrom", () => {
|
|
937
|
+
it("returns Some for valid value", () => {
|
|
938
|
+
const result = Uint.tryFrom(100n);
|
|
939
|
+
expect(result._tag).toBe("Some");
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
it("returns None for invalid value", () => {
|
|
943
|
+
const result = Uint.tryFrom(-1n);
|
|
944
|
+
expect(result._tag).toBe("None");
|
|
945
|
+
});
|
|
946
|
+
|
|
947
|
+
it("returns None for invalid string", () => {
|
|
948
|
+
const result = Uint.tryFrom("invalid");
|
|
949
|
+
expect(result._tag).toBe("None");
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
describe("type guards", () => {
|
|
955
|
+
describe("isUint256", () => {
|
|
956
|
+
it("returns true for valid bigint", () => {
|
|
957
|
+
expect(Uint.isUint256(100n)).toBe(true);
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
it("returns false for negative", () => {
|
|
961
|
+
expect(Uint.isUint256(-1n)).toBe(false);
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
it("returns false for overflow", () => {
|
|
965
|
+
expect(Uint.isUint256(MAX_UINT256 + 1n)).toBe(false);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
it("returns false for non-bigint", () => {
|
|
969
|
+
expect(Uint.isUint256(100)).toBe(false);
|
|
970
|
+
expect(Uint.isUint256("100")).toBe(false);
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
describe("isValid", () => {
|
|
975
|
+
it("returns true for valid bigint", () => {
|
|
976
|
+
expect(Uint.isValid(100n)).toBe(true);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it("returns false for negative", () => {
|
|
980
|
+
expect(Uint.isValid(-1n)).toBe(false);
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
it("returns false for non-bigint", () => {
|
|
984
|
+
expect(Uint.isValid("hello")).toBe(false);
|
|
985
|
+
});
|
|
986
|
+
});
|
|
987
|
+
});
|
|
988
|
+
|
|
989
|
+
describe("division operations", () => {
|
|
990
|
+
const a = S.decodeSync(Uint.BigInt)(100n);
|
|
991
|
+
const b = S.decodeSync(Uint.BigInt)(30n);
|
|
992
|
+
const zero = S.decodeSync(Uint.BigInt)(0n);
|
|
993
|
+
|
|
994
|
+
describe("dividedBy", () => {
|
|
995
|
+
it("divides two values", () => {
|
|
996
|
+
const result = Effect.runSync(Uint.dividedBy(a, b));
|
|
997
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(3n);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
it("fails on division by zero", () => {
|
|
1001
|
+
expect(() => Effect.runSync(Uint.dividedBy(a, zero))).toThrow();
|
|
1002
|
+
});
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
describe("modulo", () => {
|
|
1006
|
+
it("computes remainder", () => {
|
|
1007
|
+
const result = Effect.runSync(Uint.modulo(a, b));
|
|
1008
|
+
expect(S.encodeSync(Uint.BigInt)(result)).toBe(10n);
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
it("fails on modulo by zero", () => {
|
|
1012
|
+
expect(() => Effect.runSync(Uint.modulo(a, zero))).toThrow();
|
|
1013
|
+
});
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
describe("toHex", () => {
|
|
1018
|
+
it("converts to padded hex by default", () => {
|
|
1019
|
+
const val = S.decodeSync(Uint.BigInt)(255n);
|
|
1020
|
+
const result = Effect.runSync(Uint.toHex(val));
|
|
1021
|
+
expect(result).toMatch(/^0x[0-9a-f]{64}$/);
|
|
1022
|
+
expect(result).toBe(
|
|
1023
|
+
"0x00000000000000000000000000000000000000000000000000000000000000ff",
|
|
1024
|
+
);
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
it("converts to unpadded hex when requested", () => {
|
|
1028
|
+
const val = S.decodeSync(Uint.BigInt)(255n);
|
|
1029
|
+
const result = Effect.runSync(Uint.toHex(val, false));
|
|
1030
|
+
expect(result).toBe("0xff");
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
it("converts zero", () => {
|
|
1034
|
+
const val = S.decodeSync(Uint.BigInt)(0n);
|
|
1035
|
+
const result = Effect.runSync(Uint.toHex(val, false));
|
|
1036
|
+
expect(result).toBe("0x0");
|
|
1037
|
+
});
|
|
1038
|
+
});
|