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
|
@@ -364,3 +364,149 @@ describe("edge cases", () => {
|
|
|
364
364
|
expect(short.includes("...")).toBe(true);
|
|
365
365
|
});
|
|
366
366
|
});
|
|
367
|
+
|
|
368
|
+
describe("Effect-wrapped constructors", () => {
|
|
369
|
+
it("from succeeds with valid hex", async () => {
|
|
370
|
+
const program = Address.from("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
371
|
+
const addr = await Effect.runPromise(program);
|
|
372
|
+
expect(addr.length).toBe(20);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("from succeeds with bytes", async () => {
|
|
376
|
+
const bytes = new Uint8Array(20).fill(0xab);
|
|
377
|
+
const program = Address.from(bytes);
|
|
378
|
+
const addr = await Effect.runPromise(program);
|
|
379
|
+
expect(addr.length).toBe(20);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("from fails with invalid hex", async () => {
|
|
383
|
+
const program = Address.from("invalid");
|
|
384
|
+
const result = await Effect.runPromiseExit(program);
|
|
385
|
+
expect(result._tag).toBe("Failure");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("fromHex succeeds with valid hex", async () => {
|
|
389
|
+
const program = Address.fromHex("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
390
|
+
const addr = await Effect.runPromise(program);
|
|
391
|
+
expect(addr.length).toBe(20);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("fromHex fails on wrong length", async () => {
|
|
395
|
+
const program = Address.fromHex("0x742d35");
|
|
396
|
+
const result = await Effect.runPromiseExit(program);
|
|
397
|
+
expect(result._tag).toBe("Failure");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("fromBytes succeeds with 20 bytes", async () => {
|
|
401
|
+
const program = Address.fromBytes(new Uint8Array(20));
|
|
402
|
+
const addr = await Effect.runPromise(program);
|
|
403
|
+
expect(addr.length).toBe(20);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("fromBytes fails on wrong length", async () => {
|
|
407
|
+
const program = Address.fromBytes(new Uint8Array(19));
|
|
408
|
+
const result = await Effect.runPromiseExit(program);
|
|
409
|
+
expect(result._tag).toBe("Failure");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("fromNumber creates address from bigint", async () => {
|
|
413
|
+
const program = Address.fromNumber(1n);
|
|
414
|
+
const addr = await Effect.runPromise(program);
|
|
415
|
+
expect(addr.length).toBe(20);
|
|
416
|
+
expect(addr[19]).toBe(1);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it("zero creates zero address", () => {
|
|
420
|
+
const addr = Address.zero();
|
|
421
|
+
expect(addr.length).toBe(20);
|
|
422
|
+
expect(Address.isZero(addr)).toBe(true);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it("toHex converts address to hex", () => {
|
|
426
|
+
const addr = S.decodeSync(Address.Hex)("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
427
|
+
const hex = Address.toHex(addr);
|
|
428
|
+
expect(hex).toBe("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("is type guard works", () => {
|
|
432
|
+
const addr = S.decodeSync(Address.Hex)("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
433
|
+
expect(Address.is(addr)).toBe(true);
|
|
434
|
+
expect(Address.is("not an address")).toBe(false);
|
|
435
|
+
expect(Address.is(new Uint8Array(20))).toBe(true);
|
|
436
|
+
expect(Address.is(new Uint8Array(19))).toBe(false);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("isAddress validates address format", () => {
|
|
440
|
+
expect(Address.isAddress("0x742d35cc6634c0532925a3b844bc9e7595f251e3")).toBe(true);
|
|
441
|
+
expect(Address.isAddress("invalid")).toBe(false);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe("utility functions", () => {
|
|
446
|
+
it("sortAddresses sorts lexicographically", () => {
|
|
447
|
+
const addr1 = S.decodeSync(Address.Hex)("0x0000000000000000000000000000000000000001");
|
|
448
|
+
const addr2 = S.decodeSync(Address.Hex)("0x0000000000000000000000000000000000000002");
|
|
449
|
+
const addr3 = S.decodeSync(Address.Hex)("0x0000000000000000000000000000000000000003");
|
|
450
|
+
|
|
451
|
+
const sorted = Address.sortAddresses([addr3, addr1, addr2]);
|
|
452
|
+
expect(Address.equals(sorted[0], addr1)).toBe(true);
|
|
453
|
+
expect(Address.equals(sorted[1], addr2)).toBe(true);
|
|
454
|
+
expect(Address.equals(sorted[2], addr3)).toBe(true);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("deduplicateAddresses removes duplicates", () => {
|
|
458
|
+
const addr1 = S.decodeSync(Address.Hex)("0x0000000000000000000000000000000000000001");
|
|
459
|
+
const addr2 = S.decodeSync(Address.Hex)("0x0000000000000000000000000000000000000002");
|
|
460
|
+
|
|
461
|
+
const deduped = Address.deduplicateAddresses([addr1, addr1, addr2, addr2]);
|
|
462
|
+
expect(deduped.length).toBe(2);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
describe("assert functions", () => {
|
|
467
|
+
it("assert succeeds on valid address", async () => {
|
|
468
|
+
const program = Address.assert("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
469
|
+
await Effect.runPromise(program);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("assert fails on invalid address", async () => {
|
|
473
|
+
const program = Address.assert("invalid");
|
|
474
|
+
const result = await Effect.runPromiseExit(program);
|
|
475
|
+
expect(result._tag).toBe("Failure");
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("assert with strict mode validates checksum", async () => {
|
|
479
|
+
const program = Address.assert("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", { strict: true });
|
|
480
|
+
await Effect.runPromise(program);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("assertBasic succeeds on valid format", async () => {
|
|
484
|
+
const program = Address.assertBasic("0x742d35cc6634c0532925a3b844bc9e7595f251e3");
|
|
485
|
+
await Effect.runPromise(program);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
describe("toChecksummed", () => {
|
|
490
|
+
it("converts to checksummed format", async () => {
|
|
491
|
+
const addr = S.decodeSync(Address.Hex)("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed");
|
|
492
|
+
const program = Address.toChecksummed(addr).pipe(Effect.provide(KeccakLive));
|
|
493
|
+
const result = await Effect.runPromise(program);
|
|
494
|
+
expect(result).toBe("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed");
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
describe("calculateCreateAddress", () => {
|
|
499
|
+
it("calculates CREATE address", async () => {
|
|
500
|
+
const deployer = S.decodeSync(Address.Hex)("0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0");
|
|
501
|
+
const program = Address.calculateCreateAddress(deployer, 0n);
|
|
502
|
+
const result = await Effect.runPromise(program);
|
|
503
|
+
expect(result.length).toBe(20);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("fails on negative nonce", async () => {
|
|
507
|
+
const deployer = S.decodeSync(Address.Hex)("0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0");
|
|
508
|
+
const program = Address.calculateCreateAddress(deployer, -1n);
|
|
509
|
+
const result = await Effect.runPromiseExit(program);
|
|
510
|
+
expect(result._tag).toBe("Failure");
|
|
511
|
+
});
|
|
512
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module assert
|
|
3
|
+
* @description Assert value is valid address with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type InvalidAddressError, type InvalidChecksumError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
type AssertError =
|
|
10
|
+
| InvalidAddressError
|
|
11
|
+
| InvalidChecksumError;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Assert value is valid address
|
|
15
|
+
*
|
|
16
|
+
* @param value - Value to validate
|
|
17
|
+
* @param options - Validation options
|
|
18
|
+
* @param options.strict - If true, validates EIP-55 checksum
|
|
19
|
+
* @returns Effect yielding void or failing with AssertError
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Basic validation
|
|
23
|
+
* const program = Address.assert('0x742d35cc6634c0532925a3b844bc9e7595f251e3')
|
|
24
|
+
*
|
|
25
|
+
* // Strict checksum validation
|
|
26
|
+
* const strictProgram = Address.assert('0x742d35Cc6634C0532925a3b844Bc9e7595f251e3', { strict: true })
|
|
27
|
+
* await Effect.runPromise(strictProgram)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const assert = (
|
|
31
|
+
value: string | Uint8Array,
|
|
32
|
+
options?: { strict?: boolean },
|
|
33
|
+
): Effect.Effect<void, AssertError> =>
|
|
34
|
+
Effect.try({
|
|
35
|
+
try: () => { Address.assert(value, options); },
|
|
36
|
+
catch: (e) => e as AssertError,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Assert value is valid address (non-strict, no checksum validation)
|
|
41
|
+
*
|
|
42
|
+
* @param value - Value to validate
|
|
43
|
+
* @returns Effect yielding void or failing with InvalidAddressError
|
|
44
|
+
*/
|
|
45
|
+
export const assertBasic = (
|
|
46
|
+
value: string | Uint8Array,
|
|
47
|
+
): Effect.Effect<void, InvalidAddressError> =>
|
|
48
|
+
Effect.try({
|
|
49
|
+
try: () => { Address.assert(value, { strict: false }); },
|
|
50
|
+
catch: (e) => e as InvalidAddressError,
|
|
51
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module calculateCreate2Address
|
|
3
|
+
* @description Calculate CREATE2 contract deployment address with Effect
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType } from "@tevm/voltaire/Address";
|
|
8
|
+
import type { HashType } from "@tevm/voltaire/Hash";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Calculate CREATE2 contract deployment address
|
|
12
|
+
*
|
|
13
|
+
* Formula: keccak256(0xff ++ sender ++ salt ++ keccak256(initCode))[12:32]
|
|
14
|
+
*
|
|
15
|
+
* @param address - Deployer address
|
|
16
|
+
* @param salt - 32-byte salt value
|
|
17
|
+
* @param initCode - Contract initialization bytecode (Uint8Array)
|
|
18
|
+
* @returns Effect yielding the contract address that would be created
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const program = Address.calculateCreate2Address(deployerAddr, salt, initCode)
|
|
22
|
+
* const contractAddr = await Effect.runPromise(program)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const calculateCreate2Address = (
|
|
26
|
+
address: AddressType,
|
|
27
|
+
salt: HashType,
|
|
28
|
+
initCode: Uint8Array,
|
|
29
|
+
): Effect.Effect<AddressType, Error> =>
|
|
30
|
+
Effect.try({
|
|
31
|
+
try: () => Address.calculateCreate2Address(address, salt, initCode as Parameters<typeof Address.calculateCreate2Address>[2]),
|
|
32
|
+
catch: (e) => e as Error,
|
|
33
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module calculateCreateAddress
|
|
3
|
+
* @description Calculate CREATE contract deployment address with Effect
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType, type InvalidValueError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculate CREATE contract deployment address
|
|
11
|
+
*
|
|
12
|
+
* Formula: keccak256(rlp([sender, nonce]))[12:32]
|
|
13
|
+
*
|
|
14
|
+
* @param address - Deployer address
|
|
15
|
+
* @param nonce - Transaction nonce
|
|
16
|
+
* @returns Effect yielding the contract address that would be created
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const program = Address.calculateCreateAddress(deployerAddr, 0n)
|
|
20
|
+
* const contractAddr = await Effect.runPromise(program)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const calculateCreateAddress = (
|
|
24
|
+
address: AddressType,
|
|
25
|
+
nonce: bigint,
|
|
26
|
+
): Effect.Effect<AddressType, InvalidValueError> =>
|
|
27
|
+
Effect.try({
|
|
28
|
+
try: () => Address.calculateCreateAddress(address, nonce),
|
|
29
|
+
catch: (e) => e as InvalidValueError,
|
|
30
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module deduplicateAddresses
|
|
3
|
+
* @description Remove duplicate addresses from array
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { deduplicateAddresses as voltaireDeduplicateAddresses, type AddressType } from "@tevm/voltaire/Address";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Remove duplicate addresses from array
|
|
10
|
+
*
|
|
11
|
+
* @param addresses - Array with potential duplicates
|
|
12
|
+
* @returns New array with duplicates removed
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const unique = Address.deduplicateAddresses([addr1, addr1, addr2])
|
|
16
|
+
* // [addr1, addr2]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const deduplicateAddresses = (addresses: AddressType[]): AddressType[] =>
|
|
20
|
+
voltaireDeduplicateAddresses(addresses);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module from
|
|
3
|
+
* @description Create Address from various input types with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType } from "@tevm/voltaire/Address";
|
|
8
|
+
import type {
|
|
9
|
+
InvalidAddressError,
|
|
10
|
+
InvalidHexFormatError,
|
|
11
|
+
InvalidAddressLengthError,
|
|
12
|
+
InvalidValueError,
|
|
13
|
+
} from "@tevm/voltaire/Address";
|
|
14
|
+
|
|
15
|
+
type AddressError =
|
|
16
|
+
| InvalidAddressError
|
|
17
|
+
| InvalidHexFormatError
|
|
18
|
+
| InvalidAddressLengthError
|
|
19
|
+
| InvalidValueError;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create Address from hex string, bytes, or number
|
|
23
|
+
*
|
|
24
|
+
* @param value - Hex string, Uint8Array, number, or bigint
|
|
25
|
+
* @returns Effect yielding AddressType or failing with AddressError
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import * as Address from 'voltaire-effect/primitives/Address'
|
|
29
|
+
* import * as Effect from 'effect/Effect'
|
|
30
|
+
*
|
|
31
|
+
* const program = Address.from('0x742d35cc6634c0532925a3b844bc9e7595f251e3')
|
|
32
|
+
* const addr = await Effect.runPromise(program)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const from = (
|
|
36
|
+
value: string | Uint8Array | number | bigint,
|
|
37
|
+
): Effect.Effect<AddressType, AddressError> =>
|
|
38
|
+
Effect.try({
|
|
39
|
+
try: () => Address.from(value),
|
|
40
|
+
catch: (e) => e as AddressError,
|
|
41
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromAbiEncoded
|
|
3
|
+
* @description Create Address from ABI-encoded bytes with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType } from "@tevm/voltaire/Address";
|
|
8
|
+
import type {
|
|
9
|
+
InvalidAddressLengthError,
|
|
10
|
+
InvalidAbiEncodedPaddingError,
|
|
11
|
+
} from "@tevm/voltaire/Address";
|
|
12
|
+
|
|
13
|
+
type AbiEncodedError =
|
|
14
|
+
| InvalidAddressLengthError
|
|
15
|
+
| InvalidAbiEncodedPaddingError;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Address from ABI-encoded bytes (32 bytes, left-padded)
|
|
19
|
+
*
|
|
20
|
+
* @param value - 32-byte ABI-encoded address
|
|
21
|
+
* @returns Effect yielding AddressType or failing with error
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const abiEncoded = new Uint8Array(32)
|
|
25
|
+
* abiEncoded.set(addressBytes, 12) // left-pad with 12 zeros
|
|
26
|
+
* const program = Address.fromAbiEncoded(abiEncoded)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const fromAbiEncoded = (
|
|
30
|
+
value: Uint8Array,
|
|
31
|
+
): Effect.Effect<AddressType, AbiEncodedError> =>
|
|
32
|
+
Effect.try({
|
|
33
|
+
try: () => Address.fromAbiEncoded(value),
|
|
34
|
+
catch: (e) => e as AbiEncodedError,
|
|
35
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromBase64
|
|
3
|
+
* @description Create Address from base64 string with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType, type InvalidAddressLengthError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create Address from base64 encoded string
|
|
11
|
+
*
|
|
12
|
+
* @param value - Base64 string (must decode to 20 bytes)
|
|
13
|
+
* @returns Effect yielding AddressType or failing with InvalidAddressLengthError
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const program = Address.fromBase64('dC01zGY0wFMpJaO4RLyeZV8lHuM=')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const fromBase64 = (
|
|
20
|
+
value: string,
|
|
21
|
+
): Effect.Effect<AddressType, InvalidAddressLengthError> =>
|
|
22
|
+
Effect.try({
|
|
23
|
+
try: () => Address.fromBase64(value),
|
|
24
|
+
catch: (e) => e as InvalidAddressLengthError,
|
|
25
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromBytes
|
|
3
|
+
* @description Create Address from Uint8Array with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType, type InvalidAddressLengthError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create Address from 20-byte Uint8Array
|
|
11
|
+
*
|
|
12
|
+
* @param value - 20-byte Uint8Array
|
|
13
|
+
* @returns Effect yielding AddressType or failing with InvalidAddressLengthError
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const program = Address.fromBytes(new Uint8Array(20))
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const fromBytes = (
|
|
20
|
+
value: Uint8Array,
|
|
21
|
+
): Effect.Effect<AddressType, InvalidAddressLengthError> =>
|
|
22
|
+
Effect.try({
|
|
23
|
+
try: () => Address.fromBytes(value),
|
|
24
|
+
catch: (e) => e as InvalidAddressLengthError,
|
|
25
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromHex
|
|
3
|
+
* @description Create Address from hex string with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType } from "@tevm/voltaire/Address";
|
|
8
|
+
import type {
|
|
9
|
+
InvalidHexFormatError,
|
|
10
|
+
InvalidAddressLengthError,
|
|
11
|
+
} from "@tevm/voltaire/Address";
|
|
12
|
+
|
|
13
|
+
type AddressError =
|
|
14
|
+
| InvalidHexFormatError
|
|
15
|
+
| InvalidAddressLengthError;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Address from hex string
|
|
19
|
+
*
|
|
20
|
+
* @param value - Hex string with 0x prefix
|
|
21
|
+
* @returns Effect yielding AddressType or failing with AddressError
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const program = Address.fromHex('0x742d35cc6634c0532925a3b844bc9e7595f251e3')
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const fromHex = (value: string): Effect.Effect<AddressType, AddressError> =>
|
|
28
|
+
Effect.try({
|
|
29
|
+
try: () => Address.fromHex(value),
|
|
30
|
+
catch: (e) => e as AddressError,
|
|
31
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromNumber
|
|
3
|
+
* @description Create Address from number or bigint with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType, type InvalidValueError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create Address from number or bigint
|
|
11
|
+
*
|
|
12
|
+
* @param value - Number or bigint (will be left-padded to 20 bytes)
|
|
13
|
+
* @returns Effect yielding AddressType or failing with InvalidValueError
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const program = Address.fromNumber(1n) // 0x0000...0001
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const fromNumber = (
|
|
20
|
+
value: number | bigint,
|
|
21
|
+
): Effect.Effect<AddressType, InvalidValueError> =>
|
|
22
|
+
Effect.try({
|
|
23
|
+
try: () => Address.fromNumber(value),
|
|
24
|
+
catch: (e) => e as InvalidValueError,
|
|
25
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromPrivateKey
|
|
3
|
+
* @description Derive Address from secp256k1 private key with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType, type InvalidValueError } from "@tevm/voltaire/Address";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create Address from secp256k1 private key
|
|
11
|
+
*
|
|
12
|
+
* @param value - 32-byte private key
|
|
13
|
+
* @returns Effect yielding AddressType or failing with InvalidValueError
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const program = Address.fromPrivateKey(privateKeyBytes)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const fromPrivateKey = (
|
|
20
|
+
value: Uint8Array,
|
|
21
|
+
): Effect.Effect<AddressType, InvalidValueError> =>
|
|
22
|
+
Effect.try({
|
|
23
|
+
try: () => Address.fromPrivateKey(value),
|
|
24
|
+
catch: (e) => e as InvalidValueError,
|
|
25
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromPublicKey
|
|
3
|
+
* @description Derive Address from secp256k1 public key with Effect error handling
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { Address, type AddressType } from "@tevm/voltaire/Address";
|
|
8
|
+
import type {
|
|
9
|
+
InvalidAddressLengthError,
|
|
10
|
+
InvalidValueError,
|
|
11
|
+
} from "@tevm/voltaire/Address";
|
|
12
|
+
|
|
13
|
+
type PublicKeyError =
|
|
14
|
+
| InvalidAddressLengthError
|
|
15
|
+
| InvalidValueError;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Address from secp256k1 public key
|
|
19
|
+
*
|
|
20
|
+
* @param publicKey - 64-byte uncompressed public key
|
|
21
|
+
* @returns Effect yielding AddressType or failing with error
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const program = Address.fromPublicKey(publicKeyBytes)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function fromPublicKey(
|
|
28
|
+
publicKey: Uint8Array,
|
|
29
|
+
): Effect.Effect<AddressType, PublicKeyError>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create Address from secp256k1 public key coordinates
|
|
33
|
+
*
|
|
34
|
+
* @param x - x coordinate (bigint)
|
|
35
|
+
* @param y - y coordinate (bigint)
|
|
36
|
+
* @returns Effect yielding AddressType or failing with error
|
|
37
|
+
*/
|
|
38
|
+
export function fromPublicKey(
|
|
39
|
+
x: bigint,
|
|
40
|
+
y: bigint,
|
|
41
|
+
): Effect.Effect<AddressType, PublicKeyError>;
|
|
42
|
+
|
|
43
|
+
export function fromPublicKey(
|
|
44
|
+
xOrPublicKey: bigint | Uint8Array,
|
|
45
|
+
y?: bigint,
|
|
46
|
+
): Effect.Effect<AddressType, PublicKeyError> {
|
|
47
|
+
return Effect.try({
|
|
48
|
+
try: () => {
|
|
49
|
+
if (typeof xOrPublicKey === "bigint") {
|
|
50
|
+
return Address.fromPublicKey(xOrPublicKey, y!);
|
|
51
|
+
}
|
|
52
|
+
return Address.fromPublicKey(xOrPublicKey);
|
|
53
|
+
},
|
|
54
|
+
catch: (e) => e as PublicKeyError,
|
|
55
|
+
});
|
|
56
|
+
}
|