Skip to content

Commit 6ab6b9b

Browse files
committed
refactor: bytes modules
1 parent 5459ad1 commit 6ab6b9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+255
-815
lines changed

packages/evolution/src/core/Address.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import { bech32 } from "@scure/base"
66
import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect"
77

8-
import * as Bytes from "./Bytes.js"
98
import * as Bytes29 from "./Bytes29.js"
109
import * as Bytes57 from "./Bytes57.js"
1110
import * as Credential from "./Credential.js"
@@ -68,7 +67,7 @@ export class Address extends Schema.Class<Address>("AddressStructure")({
6867
* @category Transformations
6968
*/
7069
export const FromBytes = Schema.transformOrFail(
71-
Schema.Union(Bytes57.BytesSchema, Bytes29.BytesSchema),
70+
Schema.Union(Schema.typeSchema(Bytes57.BytesFromHex), Schema.typeSchema(Bytes29.BytesFromHex)),
7271
Schema.typeSchema(Address),
7372
{
7473
strict: true,
@@ -147,7 +146,7 @@ export const FromBytes = Schema.transformOrFail(
147146
* @since 1.0.0
148147
* @category Transformations
149148
*/
150-
export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({
149+
export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes).annotations({
151150
identifier: "AddressStructure.FromHex"
152151
})
153152

packages/evolution/src/core/AddressEras.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Effect as Eff, FastCheck, ParseResult, Schema } from "effect"
33

44
import * as BaseAddress from "./BaseAddress.js"
55
import * as ByronAddress from "./ByronAddress.js"
6-
import * as Bytes from "./Bytes.js"
76
import * as EnterpriseAddress from "./EnterpriseAddress.js"
87
import * as PointerAddress from "./PointerAddress.js"
98
import * as RewardAccount from "./RewardAccount.js"
@@ -136,7 +135,7 @@ export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Schem
136135
* @since 2.0.0
137136
* @category schema
138137
*/
139-
export const FromHex = Schema.compose(Bytes.FromHex, FromBytes)
138+
export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes)
140139

141140
/**
142141
* Schema for encoding/decoding addresses as Bech32 strings.

packages/evolution/src/core/Anchor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Anchor extends Schema.TaggedClass<Anchor>()("Anchor", {
3838
return (
3939
that instanceof Anchor &&
4040
Equal.equals(this.anchorUrl, that.anchorUrl) &&
41-
Bytes.bytesEquals(this.anchorDataHash, that.anchorDataHash)
41+
Bytes.equals(this.anchorDataHash, that.anchorDataHash)
4242
)
4343
}
4444

@@ -92,7 +92,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
9292
*/
9393
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
9494
Schema.compose(
95-
Bytes.FromHex, // string → Uint8Array
95+
Schema.Uint8ArrayFromHex, // string → Uint8Array
9696
FromCBORBytes(options) // Uint8Array → Anchor
9797
)
9898

packages/evolution/src/core/AssetName.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class AssetName extends Schema.TaggedClass<AssetName>()("AssetName", {
2222
toJSON() {
2323
return {
2424
_tag: "AssetName",
25-
bytes: Bytes.toHexUnsafe(this.bytes)
25+
bytes: Bytes.toHex(this.bytes)
2626
}
2727
}
2828

@@ -53,7 +53,7 @@ export class AssetName extends Schema.TaggedClass<AssetName>()("AssetName", {
5353
* @category equality
5454
*/
5555
[Equal.symbol](that: unknown): boolean {
56-
return that instanceof AssetName && Bytes.bytesEquals(this.bytes, that.bytes)
56+
return that instanceof AssetName && Bytes.equals(this.bytes, that.bytes)
5757
}
5858

5959
/**

packages/evolution/src/core/Assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
404404
*/
405405
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
406406
Schema.compose(
407-
Bytes.FromHex, // string → Uint8Array
407+
Schema.Uint8ArrayFromHex, // string → Uint8Array
408408
FromCBORBytes(options) // Uint8Array → Assets
409409
).annotations({
410410
identifier: "Assets.FromCBORHex",

packages/evolution/src/core/AuxiliaryData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI
490490
* @category schemas
491491
*/
492492
export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) =>
493-
Schema.compose(Bytes.FromHex, FromCBORBytes(options)).annotations({
493+
Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)).annotations({
494494
identifier: "AuxiliaryData.FromCBORHex",
495495
title: "AuxiliaryData from CBOR hex",
496496
description: "Decode AuxiliaryData from CBOR-encoded hex (tag 259)"

packages/evolution/src/core/AuxiliaryDataHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class AuxiliaryDataHash extends Schema.TaggedClass<AuxiliaryDataHash>()("
3535
}
3636

3737
[Equal.symbol](that: unknown): boolean {
38-
return that instanceof AuxiliaryDataHash && Bytes.bytesEquals(this.bytes, that.bytes)
38+
return that instanceof AuxiliaryDataHash && Bytes.equals(this.bytes, that.bytes)
3939
}
4040

4141
[Hash.symbol](): number {

packages/evolution/src/core/BaseAddress.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Effect as Eff, Equal, FastCheck, Inspectable, ParseResult, Schema } from "effect"
22

3-
import * as Bytes from "./Bytes.js"
43
import * as Bytes57 from "./Bytes57.js"
54
import * as Credential from "./Credential.js"
65
import * as KeyHash from "./KeyHash.js"
@@ -45,7 +44,7 @@ export class BaseAddress extends Schema.TaggedClass<BaseAddress>("BaseAddress")(
4544
}
4645
}
4746

48-
export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.typeSchema(BaseAddress), {
47+
export const FromBytes = Schema.transformOrFail(Schema.typeSchema(Bytes57.BytesFromHex), Schema.typeSchema(BaseAddress), {
4948
strict: true,
5049
encode: (_, __, ___, toA) =>
5150
Eff.gen(function* () {
@@ -94,7 +93,7 @@ export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.type
9493
identifier: "BaseAddress.FromBytes"
9594
})
9695

97-
export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({
96+
export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes).annotations({
9897
identifier: "BaseAddress.FromHex"
9998
})
10099

packages/evolution/src/core/Bech32.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export const FromBytes = (prefix: string = "addr") =>
2121
})
2222

2323
export const FromHex = (prefix: string = "addr") =>
24-
Schema.compose(Bytes.FromHex, FromBytes(prefix)).annotations({
24+
Schema.compose(Schema.Uint8ArrayFromHex, FromBytes(prefix)).annotations({
2525
identifier: "Bech32.FromHex"
2626
})

packages/evolution/src/core/Bip32PrivateKey.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Bip32PrivateKeyError extends Data.TaggedError("Bip32PrivateKeyError
3131
* @category schemas
3232
*/
3333
export class Bip32PrivateKey extends Schema.TaggedClass<Bip32PrivateKey>()("Bip32PrivateKey", {
34-
bytes: Bytes96.BytesSchema
34+
bytes: Bytes96.BytesFromHex
3535
}) {
3636
toJSON() {
3737
return { _tag: "Bip32PrivateKey" as const, bytes: Bytes.toHex(this.bytes) }
@@ -46,7 +46,7 @@ export class Bip32PrivateKey extends Schema.TaggedClass<Bip32PrivateKey>()("Bip3
4646
}
4747

4848
[Equal.symbol](that: unknown): boolean {
49-
return that instanceof Bip32PrivateKey && Bytes.bytesEquals(this.bytes, that.bytes)
49+
return that instanceof Bip32PrivateKey && Bytes.equals(this.bytes, that.bytes)
5050
}
5151

5252
[Hash.symbol](): number {
@@ -60,7 +60,7 @@ export class Bip32PrivateKey extends Schema.TaggedClass<Bip32PrivateKey>()("Bip3
6060
* @since 2.0.0
6161
* @category schemas
6262
*/
63-
export const FromBytes = Schema.transform(Bytes96.BytesSchema, Bip32PrivateKey, {
63+
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes96.BytesFromHex), Schema.typeSchema(Bip32PrivateKey), {
6464
strict: true,
6565
decode: (bytes) => new Bip32PrivateKey({ bytes }, { disableValidation: true }),
6666
encode: (bip32PrivateKey) => bip32PrivateKey.bytes
@@ -75,7 +75,7 @@ export const FromBytes = Schema.transform(Bytes96.BytesSchema, Bip32PrivateKey,
7575
* @category schemas
7676
*/
7777
export const FromHex = Schema.compose(
78-
Bytes96.FromHex, // string -> Bytes96
78+
Bytes96.BytesFromHex, // string -> Bytes96
7979
FromBytes // Bytes96 -> Bip32PrivateKey
8080
).annotations({
8181
identifier: "Bip32PrivateKey.FromHex"
@@ -443,7 +443,9 @@ export namespace Either {
443443
export const from_128_xprv = (bytes: Uint8Array) =>
444444
Effect.gen(function* () {
445445
if (bytes.length !== 128) {
446-
return yield* Effect.fail(new Bip32PrivateKeyError({ message: `Expected exactly 128 bytes, got ${bytes.length}` }))
446+
return yield* Effect.fail(
447+
new Bip32PrivateKeyError({ message: `Expected exactly 128 bytes, got ${bytes.length}` })
448+
)
447449
}
448450
const scalar = bytes.slice(0, 32)
449451
const iv = bytes.slice(32, 64)

0 commit comments

Comments
 (0)