diff --git a/.changeset/cold-cows-bake.md b/.changeset/cold-cows-bake.md new file mode 100644 index 00000000..1fa08f2a --- /dev/null +++ b/.changeset/cold-cows-bake.md @@ -0,0 +1,36 @@ +--- +"@evolution-sdk/evolution": minor +--- + +Add CIP-30 message signing support with modular architecture + +This release introduces comprehensive CIP-30 `signData` and `verifyData` support, implementing the complete COSE Sign1 specification with a clean, modular structure: + +**New Features:** +- Full CIP-30 message signing (`signData`) and verification (`verifyData`) implementation +- COSE (CBOR Object Signing and Encryption) primitives per RFC 8152 +- Support for Ed25519 signatures with proper COSE key structures +- Message hashing with BLAKE2b-256 for payload integrity +- CIP-8 compliant address field handling +- Complete test coverage with CSL compatibility tests + +**Module Structure:** +- `message-signing/SignData.ts` - Main CIP-30 signData/verifyData API +- `message-signing/Header.ts` - COSE header structures and operations +- `message-signing/Label.ts` - COSE label types and algorithm identifiers +- `message-signing/CoseSign1.ts` - COSE_Sign1 structure implementation +- `message-signing/CoseKey.ts` - COSE key format support +- `message-signing/Ed25519Key.ts` - Ed25519 key operations +- `message-signing/Utils.ts` - Encoding and conversion utilities + +**Breaking Changes:** +- Refactored `Bytes` module API: + - Renamed `bytesEquals` to `equals` with stricter type signature (no longer accepts undefined) + - Removed `Bytes.FromHex` schema in favor of Effect's built-in `Schema.Uint8ArrayFromHex` + - Updated `fromHex`/`toHex` to use Effect's native schemas + +**Internal Improvements:** +- Removed unused `Bytes` imports across 32 files +- Updated all modules to use new Bytes API +- Improved CBOR encoding/decoding with proper codec options +- Enhanced type safety with Effect Schema compositions diff --git a/docs/content/docs/modules/core/Address.mdx b/docs/content/docs/modules/core/Address.mdx index 3f6c3c13..37123366 100644 --- a/docs/content/docs/modules/core/Address.mdx +++ b/docs/content/docs/modules/core/Address.mdx @@ -147,7 +147,7 @@ Handles both BaseAddress (57 bytes) and EnterpriseAddress (29 bytes) ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.Union<[Schema.filter, Schema.filter]>, + Schema.Union<[Schema.SchemaClass, Schema.SchemaClass]>, Schema.SchemaClass, never > @@ -163,9 +163,11 @@ Transform from hex string to AddressStructure ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.Union<[Schema.filter, Schema.filter]>, + Schema.Union< + [Schema.SchemaClass, Schema.SchemaClass] + >, Schema.SchemaClass, never > @@ -219,7 +221,7 @@ Added in v1.0.0 **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => Address +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => Address ``` ## fromHex @@ -243,7 +245,7 @@ export declare const toBech32: (a: Address, overrideOptions?: ParseOptions) => s **Signature** ```ts -export declare const toBytes: (a: Address, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: Address, overrideOptions?: ParseOptions) => Uint8Array ``` ## toHex diff --git a/docs/content/docs/modules/core/AddressEras.mdx b/docs/content/docs/modules/core/AddressEras.mdx index e081d3a5..b24a5c1c 100644 --- a/docs/content/docs/modules/core/AddressEras.mdx +++ b/docs/content/docs/modules/core/AddressEras.mdx @@ -275,7 +275,7 @@ Schema for encoding/decoding addresses as hex strings. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.SchemaClass< diff --git a/docs/content/docs/modules/core/Anchor.mdx b/docs/content/docs/modules/core/Anchor.mdx index 2cab0f00..eef2b9bf 100644 --- a/docs/content/docs/modules/core/Anchor.mdx +++ b/docs/content/docs/modules/core/Anchor.mdx @@ -191,7 +191,7 @@ CBOR hex transformation schema for Anchor. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Assets.mdx b/docs/content/docs/modules/core/Assets.mdx index 4fe97950..c95785a4 100644 --- a/docs/content/docs/modules/core/Assets.mdx +++ b/docs/content/docs/modules/core/Assets.mdx @@ -448,7 +448,7 @@ CBOR hex transformation schema for Assets. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/AuxiliaryData.mdx b/docs/content/docs/modules/core/AuxiliaryData.mdx index b5134c22..e5e52408 100644 --- a/docs/content/docs/modules/core/AuxiliaryData.mdx +++ b/docs/content/docs/modules/core/AuxiliaryData.mdx @@ -515,7 +515,7 @@ Transforms between CBOR hex string and AuxiliaryData using CDDL format. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/BaseAddress.mdx b/docs/content/docs/modules/core/BaseAddress.mdx index 4ff11aa8..058e5cab 100644 --- a/docs/content/docs/modules/core/BaseAddress.mdx +++ b/docs/content/docs/modules/core/BaseAddress.mdx @@ -53,7 +53,7 @@ Convert a BaseAddress to bytes. **Signature** ```ts -export declare const toBytes: (data: BaseAddress) => any +export declare const toBytes: (data: BaseAddress) => Uint8Array ``` Added in v2.0.0 @@ -150,7 +150,7 @@ toString(): string ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -162,9 +162,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/docs/content/docs/modules/core/Bech32.mdx b/docs/content/docs/modules/core/Bech32.mdx index 9113fa57..afd9b245 100644 --- a/docs/content/docs/modules/core/Bech32.mdx +++ b/docs/content/docs/modules/core/Bech32.mdx @@ -54,7 +54,7 @@ export declare const FromBytes: ( export declare const FromHex: ( prefix?: string ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail > ``` diff --git a/docs/content/docs/modules/core/Bip32PrivateKey.mdx b/docs/content/docs/modules/core/Bip32PrivateKey.mdx index c3be79ab..41104df5 100644 --- a/docs/content/docs/modules/core/Bip32PrivateKey.mdx +++ b/docs/content/docs/modules/core/Bip32PrivateKey.mdx @@ -164,7 +164,7 @@ Convert a Bip32PrivateKey to raw bytes. **Signature** ```ts -export declare const toBytes: (a: Bip32PrivateKey, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: Bip32PrivateKey, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -204,7 +204,7 @@ Parse a Bip32PrivateKey from raw bytes. **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => Bip32PrivateKey +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => Bip32PrivateKey ``` Added in v2.0.0 @@ -285,8 +285,8 @@ Schema for transforming between Uint8Array and Bip32PrivateKey. ```ts export declare const FromBytes: Schema.transform< - Schema.filter, - typeof Bip32PrivateKey + Schema.SchemaClass, + Schema.SchemaClass > ``` @@ -300,8 +300,11 @@ Schema for transforming between hex string and Bip32PrivateKey. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, typeof Bip32PrivateKey> + Schema.filter>, + Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass + > > ``` diff --git a/docs/content/docs/modules/core/BootstrapWitness.mdx b/docs/content/docs/modules/core/BootstrapWitness.mdx index 100cd3c2..9d3b9506 100644 --- a/docs/content/docs/modules/core/BootstrapWitness.mdx +++ b/docs/content/docs/modules/core/BootstrapWitness.mdx @@ -130,7 +130,7 @@ Transforms between hex string and BootstrapWitness using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/ByronAddress.mdx b/docs/content/docs/modules/core/ByronAddress.mdx index ea2c67ef..becb8a91 100644 --- a/docs/content/docs/modules/core/ByronAddress.mdx +++ b/docs/content/docs/modules/core/ByronAddress.mdx @@ -96,7 +96,7 @@ Schema for encoding/decoding Byron addresses as hex strings. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail > ``` diff --git a/docs/content/docs/modules/core/Bytes.mdx b/docs/content/docs/modules/core/Bytes.mdx index d6d83697..787f04b1 100644 --- a/docs/content/docs/modules/core/Bytes.mdx +++ b/docs/content/docs/modules/core/Bytes.mdx @@ -15,37 +15,11 @@ parent: Modules - [bytesLengthEquals](#byteslengthequals) - [bytesLengthMax](#byteslengthmax) - [bytesLengthMin](#byteslengthmin) - - [bytesStartsWithPrefix](#bytesstartswithprefix) - - [hexLengthBetween](#hexlengthbetween) - - [hexLengthEquals](#hexlengthequals) - - [hexLengthMax](#hexlengthmax) - - [hexLengthMin](#hexlengthmin) - - [hexStartsWithPrefix](#hexstartswithprefix) - [conversions](#conversions) - [fromHex](#fromhex) - - [fromHexLenient](#fromhexlenient) - [toHex](#tohex) - - [toHexLenient](#tohexlenient) -- [equality](#equality) - - [bytesEquals](#bytesequals) -- [namespaces](#namespaces) - - [Either (namespace)](#either-namespace) -- [predicates](#predicates) - - [isHexLenient](#ishexlenient) -- [schemas](#schemas) - - [HexLenientSchema](#hexlenientschema) - [utils](#utils) - - [BytesError (class)](#byteserror-class) - - [BytesFromHexLenient](#bytesfromhexlenient) - - [FromHex](#fromhex-1) - - [HexSchema](#hexschema) - [equals](#equals) - - [fromHexLenientUnsafe](#fromhexlenientunsafe) - - [fromHexUnsafe](#fromhexunsafe) - - [isHex](#ishex) - - [makeBytesTransformation](#makebytestransformation) - - [toHexLenientUnsafe](#tohexlenientunsafe) - - [toHexUnsafe](#tohexunsafe) --- @@ -113,97 +87,6 @@ export declare const bytesLengthMin: ( Added in v2.0.0 -## bytesStartsWithPrefix - -Creates a curried filter that validates bytes start with specific prefix. -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const bytesStartsWithPrefix: ( - prefix: Uint8Array -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthBetween - -Creates a curried filter that validates byte length is within a range (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthBetween: ( - minBytes: number, - maxBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthEquals - -Creates a curried filter that validates exact byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthEquals: ( - byteLength: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthMax - -Creates a curried filter that validates maximum byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthMax: ( - maxBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthMin - -Creates a curried filter that validates minimum byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthMin: ( - minBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexStartsWithPrefix - -Creates a curried filter that validates hex starts with specific prefix. -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexStartsWithPrefix: ( - prefix: string -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - # conversions ## fromHex @@ -213,19 +96,7 @@ Convert hex string to Uint8Array. Throws on invalid input. **Signature** ```ts -export declare const fromHex: (hex: string) => Uint8Array -``` - -Added in v2.0.0 - -## fromHexLenient - -Convert hex string to Uint8Array (allows empty strings). Throws on invalid input. - -**Signature** - -```ts -export declare const fromHexLenient: (hex: string) => Uint8Array +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -237,116 +108,13 @@ Convert Uint8Array to hex string. Never fails. **Signature** ```ts -export declare const toHex: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -## toHexLenient - -Convert Uint8Array to hex string (returns empty string for empty arrays). Never fails. - -**Signature** - -```ts -export declare const toHexLenient: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -# equality - -## bytesEquals - -Compare two Uint8Array instances for equality. -Returns true if both arrays have the same length and same byte values. - -**Signature** - -```ts -export declare const bytesEquals: (a: Uint8Array | undefined, b: Uint8Array | undefined) => boolean -``` - -Added in v2.0.0 - -# namespaces - -## Either (namespace) - -Safe API that returns Either for error handling instead of throwing. - -Added in v2.0.0 - -# predicates - -## isHexLenient - -Lenient version of isHex that allows empty strings. -Useful for PlutusData where empty byte arrays are valid. - -**Signature** - -```ts -export declare const isHexLenient: (input: string) => boolean -``` - -Added in v2.0.0 - -# schemas - -## HexLenientSchema - -Lenient hex schema that allows empty strings. -Useful for PlutusData where empty byte arrays are valid. - -**Signature** - -```ts -export declare const HexLenientSchema: Schema.refine +export declare const toHex: (a: Uint8Array, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 # utils -## BytesError (class) - -**Signature** - -```ts -export declare class BytesError -``` - -## BytesFromHexLenient - -**Signature** - -```ts -export declare const BytesFromHexLenient: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -## FromHex - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.refine -``` - ## equals **Signature** @@ -354,63 +122,3 @@ export declare const HexSchema: Schema.refine ```ts export declare const equals: (a: Uint8Array, b: Uint8Array) => boolean ``` - -## fromHexLenientUnsafe - -Pure conversion function from validated hex string to Uint8Array (lenient version). -Assumes input is already validated hex or empty string. - -**Signature** - -```ts -export declare const fromHexLenientUnsafe: (hex: string) => Uint8Array -``` - -## fromHexUnsafe - -Pure conversion function from validated hex string to Uint8Array. -Assumes input is already validated hex. - -**Signature** - -```ts -export declare const fromHexUnsafe: (hex: string) => Uint8Array -``` - -## isHex - -**Signature** - -```ts -export declare const isHex: (input: string) => boolean -``` - -## makeBytesTransformation - -**Signature** - -```ts -export declare const makeBytesTransformation: ( - config: Uint8ArrayTransformationConfig -) => Schema.transform, Schema.Schema> -``` - -## toHexLenientUnsafe - -Pure conversion function from Uint8Array to hex string (lenient version). - -**Signature** - -```ts -export declare const toHexLenientUnsafe: (bytes: Uint8Array) => string -``` - -## toHexUnsafe - -Pure conversion function from Uint8Array to hex string. - -**Signature** - -```ts -export declare const toHexUnsafe: (bytes: Uint8Array) => string -``` diff --git a/docs/content/docs/modules/core/Bytes128.mdx b/docs/content/docs/modules/core/Bytes128.mdx index f3f9b27d..43fdba83 100644 --- a/docs/content/docs/modules/core/Bytes128.mdx +++ b/docs/content/docs/modules/core/Bytes128.mdx @@ -22,13 +22,9 @@ Added in v2.0.0 - [encoding](#encoding) - [toHex](#tohex) - [toVariableHex](#tovariablehex) -- [schemas](#schemas) - - [FromHex](#fromhex-1) - - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) + - [BytesFromHex](#bytesfromhex) + - [VariableBytesFromHex](#variablebytesfromhex) - [equals](#equals) --- @@ -99,62 +95,22 @@ export declare const toVariableHex: (a: Uint8Array, overrideOptions?: ParseOptio Added in v2.0.0 -# schemas - -## FromHex - -Schema transformation for fixed-length bytes - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - -## VariableBytesFromHex - -Schema transformation for variable-length bytes (0..BYTES_LENGTH). - -**Signature** - -```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - # utils -## BytesSchema +## BytesFromHex **Signature** ```ts -export declare const BytesSchema: Schema.filter +export declare const BytesFromHex: Schema.filter> ``` -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes +## VariableBytesFromHex **Signature** ```ts -export declare const VariableBytes: Schema.filter +export declare const VariableBytesFromHex: Schema.filter> ``` ## equals diff --git a/docs/content/docs/modules/core/Bytes29.mdx b/docs/content/docs/modules/core/Bytes29.mdx index 74f4c5a8..9e99b7e9 100644 --- a/docs/content/docs/modules/core/Bytes29.mdx +++ b/docs/content/docs/modules/core/Bytes29.mdx @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/docs/content/docs/modules/core/Bytes448.mdx b/docs/content/docs/modules/core/Bytes448.mdx index ecddb1c8..de07c0af 100644 --- a/docs/content/docs/modules/core/Bytes448.mdx +++ b/docs/content/docs/modules/core/Bytes448.mdx @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/docs/content/docs/modules/core/Bytes57.mdx b/docs/content/docs/modules/core/Bytes57.mdx index bada8f12..24b1c89f 100644 --- a/docs/content/docs/modules/core/Bytes57.mdx +++ b/docs/content/docs/modules/core/Bytes57.mdx @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/docs/content/docs/modules/core/Bytes64.mdx b/docs/content/docs/modules/core/Bytes64.mdx index ad854ea5..05f2dde2 100644 --- a/docs/content/docs/modules/core/Bytes64.mdx +++ b/docs/content/docs/modules/core/Bytes64.mdx @@ -60,7 +60,7 @@ Decode variable-length hex (0..BYTES_LENGTH) into bytes. **Signature** ```ts -export declare const fromVariableHex: (i: any, overrideOptions?: ParseOptions) => any +export declare const fromVariableHex: (i: string, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -86,7 +86,7 @@ Encode variable-length bytes (0..BYTES_LENGTH) to hex. **Signature** ```ts -export declare const toVariableHex: (a: any, overrideOptions?: ParseOptions) => any +export declare const toVariableHex: (a: Uint8Array, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -106,7 +106,7 @@ export declare const BytesFromHex: Schema.filter +export declare const VariableBytesFromHex: Schema.filter> ``` ## equals diff --git a/docs/content/docs/modules/core/Bytes80.mdx b/docs/content/docs/modules/core/Bytes80.mdx index 94a48ed2..1c613010 100644 --- a/docs/content/docs/modules/core/Bytes80.mdx +++ b/docs/content/docs/modules/core/Bytes80.mdx @@ -23,11 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - [equals](#equals) --- @@ -100,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -122,32 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - ## equals **Signature** diff --git a/docs/content/docs/modules/core/Bytes96.mdx b/docs/content/docs/modules/core/Bytes96.mdx index 8fa0a0ac..d49c1430 100644 --- a/docs/content/docs/modules/core/Bytes96.mdx +++ b/docs/content/docs/modules/core/Bytes96.mdx @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/docs/content/docs/modules/core/CBOR.mdx b/docs/content/docs/modules/core/CBOR.mdx index e54cf8e1..68313e1e 100644 --- a/docs/content/docs/modules/core/CBOR.mdx +++ b/docs/content/docs/modules/core/CBOR.mdx @@ -407,7 +407,7 @@ export declare const Float: typeof Schema.Number export declare const FromHex: ( options: CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail, never> > ``` diff --git a/docs/content/docs/modules/core/Certificate.mdx b/docs/content/docs/modules/core/Certificate.mdx index 1d5f8c5e..b0b3890f 100644 --- a/docs/content/docs/modules/core/Certificate.mdx +++ b/docs/content/docs/modules/core/Certificate.mdx @@ -535,7 +535,7 @@ CBOR hex transformation schema for Certificate. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Constitution.mdx b/docs/content/docs/modules/core/Constitution.mdx index 90fba8fd..72264417 100644 --- a/docs/content/docs/modules/core/Constitution.mdx +++ b/docs/content/docs/modules/core/Constitution.mdx @@ -187,7 +187,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/CostModel.mdx b/docs/content/docs/modules/core/CostModel.mdx index 20298bc3..6745c124 100644 --- a/docs/content/docs/modules/core/CostModel.mdx +++ b/docs/content/docs/modules/core/CostModel.mdx @@ -75,7 +75,7 @@ Transforms between hex string and CostModels using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Credential.mdx b/docs/content/docs/modules/core/Credential.mdx index a94f74ae..e3da172f 100644 --- a/docs/content/docs/modules/core/Credential.mdx +++ b/docs/content/docs/modules/core/Credential.mdx @@ -214,7 +214,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/DRep.mdx b/docs/content/docs/modules/core/DRep.mdx index 15984742..e2fbcc5a 100644 --- a/docs/content/docs/modules/core/DRep.mdx +++ b/docs/content/docs/modules/core/DRep.mdx @@ -601,7 +601,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Data.mdx b/docs/content/docs/modules/core/Data.mdx index c4f1bb44..9a2b1372 100644 --- a/docs/content/docs/modules/core/Data.mdx +++ b/docs/content/docs/modules/core/Data.mdx @@ -554,7 +554,7 @@ Transforms between CBOR hex string and Data using CDDL encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/DatumOption.mdx b/docs/content/docs/modules/core/DatumOption.mdx index d6e8e7fd..13ad5bd7 100644 --- a/docs/content/docs/modules/core/DatumOption.mdx +++ b/docs/content/docs/modules/core/DatumOption.mdx @@ -270,7 +270,7 @@ Transforms between hex string and DatumOption using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/DnsName.mdx b/docs/content/docs/modules/core/DnsName.mdx index 230e4b79..98e7e935 100644 --- a/docs/content/docs/modules/core/DnsName.mdx +++ b/docs/content/docs/modules/core/DnsName.mdx @@ -52,7 +52,7 @@ Encode DnsName to bytes. **Signature** ```ts -export declare const toBytes: (dnsName: DnsName) => Uint8Array +export declare const toBytes: (a: string & Brand<"DnsName">, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -64,7 +64,7 @@ Encode DnsName to hex string. **Signature** ```ts -export declare const toHex: (dnsName: DnsName) => string +export declare const toHex: (a: string & Brand<"DnsName">, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -79,13 +79,7 @@ dns_name = text .size (0 .. 128) **Signature** ```ts -export declare const DnsName: Schema.brand< - Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" -> +export declare const DnsName: Schema.brand, "DnsName"> ``` Added in v2.0.0 @@ -111,7 +105,7 @@ Parse DnsName from bytes. **Signature** ```ts -export declare const fromBytes: (bytes: Uint8Array) => DnsName +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string & Brand<"DnsName"> ``` Added in v2.0.0 @@ -123,7 +117,7 @@ Parse DnsName from hex string. **Signature** ```ts -export declare const fromHex: (hex: string) => DnsName +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => string & Brand<"DnsName"> ``` Added in v2.0.0 @@ -150,14 +144,11 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.brand< - Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" - > + Schema.transform< + Schema.transform, + Schema.refine + >, + Schema.brand, "DnsName"> > ``` @@ -168,15 +159,12 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - Schema.brand< + Schema.Schema, Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" - > + Schema.transform, + Schema.refine + > + >, + Schema.brand, "DnsName"> > ``` diff --git a/docs/content/docs/modules/core/EnterpriseAddress.mdx b/docs/content/docs/modules/core/EnterpriseAddress.mdx index b003706e..4e30b453 100644 --- a/docs/content/docs/modules/core/EnterpriseAddress.mdx +++ b/docs/content/docs/modules/core/EnterpriseAddress.mdx @@ -40,7 +40,7 @@ Convert a EnterpriseAddress to bytes. **Signature** ```ts -export declare const toBytes: (data: EnterpriseAddress) => any +export declare const toBytes: (data: EnterpriseAddress) => Uint8Array ``` Added in v2.0.0 @@ -159,7 +159,7 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -171,9 +171,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/docs/content/docs/modules/core/Header.mdx b/docs/content/docs/modules/core/Header.mdx index 715fcc12..5ed1ead1 100644 --- a/docs/content/docs/modules/core/Header.mdx +++ b/docs/content/docs/modules/core/Header.mdx @@ -272,7 +272,7 @@ CBOR hex transformation schema for Header. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/HeaderBody.mdx b/docs/content/docs/modules/core/HeaderBody.mdx index fbc0c067..c262d060 100644 --- a/docs/content/docs/modules/core/HeaderBody.mdx +++ b/docs/content/docs/modules/core/HeaderBody.mdx @@ -220,7 +220,7 @@ CBOR hex transformation schema for HeaderBody. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/KesSignature.mdx b/docs/content/docs/modules/core/KesSignature.mdx index 0abb6cd1..ef242fb1 100644 --- a/docs/content/docs/modules/core/KesSignature.mdx +++ b/docs/content/docs/modules/core/KesSignature.mdx @@ -56,7 +56,7 @@ Encode KesSignature to bytes. **Signature** ```ts -export declare const toBytes: (a: KesSignature, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: KesSignature, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -82,7 +82,7 @@ Parse KesSignature from bytes. **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => KesSignature +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => KesSignature ``` Added in v2.0.0 @@ -175,7 +175,10 @@ toString(): string **Signature** ```ts -export declare const FromBytes: Schema.transform, typeof KesSignature> +export declare const FromBytes: Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass +> ``` ## FromHex @@ -184,7 +187,10 @@ export declare const FromBytes: Schema.transform, Schema.Schema>, - Schema.transform, typeof KesSignature> + Schema.filter>, + Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass + > > ``` diff --git a/docs/content/docs/modules/core/Metadata.mdx b/docs/content/docs/modules/core/Metadata.mdx index af64f378..d8486415 100644 --- a/docs/content/docs/modules/core/Metadata.mdx +++ b/docs/content/docs/modules/core/Metadata.mdx @@ -234,7 +234,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/Mint.mdx b/docs/content/docs/modules/core/Mint.mdx index 622d9679..81c67985 100644 --- a/docs/content/docs/modules/core/Mint.mdx +++ b/docs/content/docs/modules/core/Mint.mdx @@ -344,7 +344,7 @@ Transforms between CBOR hex string and Mint using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/MultiAsset.mdx b/docs/content/docs/modules/core/MultiAsset.mdx index 3676ca65..b3b89f16 100644 --- a/docs/content/docs/modules/core/MultiAsset.mdx +++ b/docs/content/docs/modules/core/MultiAsset.mdx @@ -321,7 +321,7 @@ Transforms between CBOR hex string and MultiAsset using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/MultiHostName.mdx b/docs/content/docs/modules/core/MultiHostName.mdx index ba8ee7d6..cdbe93b3 100644 --- a/docs/content/docs/modules/core/MultiHostName.mdx +++ b/docs/content/docs/modules/core/MultiHostName.mdx @@ -206,7 +206,7 @@ CBOR hex transformation schema for MultiHostName. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/NativeScripts.mdx b/docs/content/docs/modules/core/NativeScripts.mdx index b9ccf424..e0af49c2 100644 --- a/docs/content/docs/modules/core/NativeScripts.mdx +++ b/docs/content/docs/modules/core/NativeScripts.mdx @@ -384,7 +384,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/NativeScriptsOLD.mdx b/docs/content/docs/modules/core/NativeScriptsOLD.mdx index eede70ed..4a04dd53 100644 --- a/docs/content/docs/modules/core/NativeScriptsOLD.mdx +++ b/docs/content/docs/modules/core/NativeScriptsOLD.mdx @@ -272,7 +272,7 @@ Transforms between CBOR hex string and Native using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/NonnegativeInterval.mdx b/docs/content/docs/modules/core/NonnegativeInterval.mdx index 12da46f3..a019e17d 100644 --- a/docs/content/docs/modules/core/NonnegativeInterval.mdx +++ b/docs/content/docs/modules/core/NonnegativeInterval.mdx @@ -147,7 +147,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/OperationalCert.mdx b/docs/content/docs/modules/core/OperationalCert.mdx index 4231e21d..8741fdbb 100644 --- a/docs/content/docs/modules/core/OperationalCert.mdx +++ b/docs/content/docs/modules/core/OperationalCert.mdx @@ -225,7 +225,7 @@ CBOR hex transformation schema for OperationalCert. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/PointerAddress.mdx b/docs/content/docs/modules/core/PointerAddress.mdx index c957f70f..0392d300 100644 --- a/docs/content/docs/modules/core/PointerAddress.mdx +++ b/docs/content/docs/modules/core/PointerAddress.mdx @@ -212,7 +212,7 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.SchemaClass, diff --git a/docs/content/docs/modules/core/PoolMetadata.mdx b/docs/content/docs/modules/core/PoolMetadata.mdx index a25b48e3..9a6ae3d0 100644 --- a/docs/content/docs/modules/core/PoolMetadata.mdx +++ b/docs/content/docs/modules/core/PoolMetadata.mdx @@ -194,7 +194,7 @@ Transforms between hex string and PoolMetadata using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/PoolParams.mdx b/docs/content/docs/modules/core/PoolParams.mdx index 1b83a121..24c65d04 100644 --- a/docs/content/docs/modules/core/PoolParams.mdx +++ b/docs/content/docs/modules/core/PoolParams.mdx @@ -343,7 +343,7 @@ CBOR hex transformation schema for PoolParams. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/PrivateKey.mdx b/docs/content/docs/modules/core/PrivateKey.mdx index 40b4fb3b..a4f7dd24 100644 --- a/docs/content/docs/modules/core/PrivateKey.mdx +++ b/docs/content/docs/modules/core/PrivateKey.mdx @@ -402,7 +402,7 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform, Schema.SchemaClass> > ``` diff --git a/docs/content/docs/modules/core/ProposalProcedure.mdx b/docs/content/docs/modules/core/ProposalProcedure.mdx index e68c79d4..230dbe91 100644 --- a/docs/content/docs/modules/core/ProposalProcedure.mdx +++ b/docs/content/docs/modules/core/ProposalProcedure.mdx @@ -299,7 +299,7 @@ CBOR hex transformation schema for individual ProposalProcedure. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/ProposalProcedures.mdx b/docs/content/docs/modules/core/ProposalProcedures.mdx index 922374ef..f212badd 100644 --- a/docs/content/docs/modules/core/ProposalProcedures.mdx +++ b/docs/content/docs/modules/core/ProposalProcedures.mdx @@ -292,7 +292,7 @@ CBOR hex transformation schema for ProposalProcedures. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/ProtocolParamUpdate.mdx b/docs/content/docs/modules/core/ProtocolParamUpdate.mdx index 4f945931..6620f15b 100644 --- a/docs/content/docs/modules/core/ProtocolParamUpdate.mdx +++ b/docs/content/docs/modules/core/ProtocolParamUpdate.mdx @@ -200,7 +200,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/ProtocolVersion.mdx b/docs/content/docs/modules/core/ProtocolVersion.mdx index 35f79e32..6d4022b3 100644 --- a/docs/content/docs/modules/core/ProtocolVersion.mdx +++ b/docs/content/docs/modules/core/ProtocolVersion.mdx @@ -187,7 +187,7 @@ CBOR hex transformation schema for ProtocolVersion. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Redeemer.mdx b/docs/content/docs/modules/core/Redeemer.mdx index c82dbe5f..3a8e9c41 100644 --- a/docs/content/docs/modules/core/Redeemer.mdx +++ b/docs/content/docs/modules/core/Redeemer.mdx @@ -394,7 +394,7 @@ Transforms between CBOR hex string and Redeemer using CDDL encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Relay.mdx b/docs/content/docs/modules/core/Relay.mdx index 8541bedf..80c5be1b 100644 --- a/docs/content/docs/modules/core/Relay.mdx +++ b/docs/content/docs/modules/core/Relay.mdx @@ -274,7 +274,7 @@ CBOR hex transformation schema for Relay. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.Union< [ Schema.transform< diff --git a/docs/content/docs/modules/core/RewardAccount.mdx b/docs/content/docs/modules/core/RewardAccount.mdx index 8755c7ae..14dfc253 100644 --- a/docs/content/docs/modules/core/RewardAccount.mdx +++ b/docs/content/docs/modules/core/RewardAccount.mdx @@ -69,7 +69,7 @@ Convert a RewardAccount to bytes. **Signature** ```ts -export declare const toBytes: (data: RewardAccount) => any +export declare const toBytes: (data: RewardAccount) => Uint8Array ``` Added in v2.0.0 @@ -208,7 +208,7 @@ export declare const FromBech32: Schema.transformOrFail< ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -220,9 +220,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/docs/content/docs/modules/core/Script.mdx b/docs/content/docs/modules/core/Script.mdx index e56c74e1..ecefe385 100644 --- a/docs/content/docs/modules/core/Script.mdx +++ b/docs/content/docs/modules/core/Script.mdx @@ -170,7 +170,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/ScriptRef.mdx b/docs/content/docs/modules/core/ScriptRef.mdx index 3036057a..7076cc1a 100644 --- a/docs/content/docs/modules/core/ScriptRef.mdx +++ b/docs/content/docs/modules/core/ScriptRef.mdx @@ -206,7 +206,7 @@ CBOR hex transformation schema for ScriptRef. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, @@ -254,7 +254,7 @@ Schema for transforming from hex to ScriptRef. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform> > ``` diff --git a/docs/content/docs/modules/core/SingleHostAddr.mdx b/docs/content/docs/modules/core/SingleHostAddr.mdx index 03bf3d58..d114ba99 100644 --- a/docs/content/docs/modules/core/SingleHostAddr.mdx +++ b/docs/content/docs/modules/core/SingleHostAddr.mdx @@ -298,7 +298,7 @@ CBOR hex transformation schema for SingleHostAddr. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/SingleHostName.mdx b/docs/content/docs/modules/core/SingleHostName.mdx index 744803ed..76112be1 100644 --- a/docs/content/docs/modules/core/SingleHostName.mdx +++ b/docs/content/docs/modules/core/SingleHostName.mdx @@ -300,7 +300,7 @@ CBOR hex transformation schema for SingleHostName. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Text.mdx b/docs/content/docs/modules/core/Text.mdx index 5c37e24a..6f66e197 100644 --- a/docs/content/docs/modules/core/Text.mdx +++ b/docs/content/docs/modules/core/Text.mdx @@ -11,7 +11,7 @@ parent: Modules

Table of contents

- [composition](#composition) - - [textLengthBetween](#textlengthbetween) + - [between](#between) - [conversion](#conversion) - [fromBytes](#frombytes) - [fromHex](#fromhex) @@ -19,30 +19,21 @@ parent: Modules - [toHex](#tohex) - [schemas](#schemas) - [FromBytes](#frombytes-1) + - [FromHex](#fromhex-1) - [testing](#testing) - [arbitrary](#arbitrary) -- [types](#types) - - [TextTransformationConfig (interface)](#texttransformationconfig-interface) -- [unsafe](#unsafe) - - [fromBytesUnsafe](#frombytesunsafe) - - [fromHexUnsafe](#fromhexunsafe) - - [toBytesUnsafe](#tobytesunsafe) - - [toHexUnsafe](#tohexunsafe) -- [utilities](#utilities) - - [makeTextTransformation](#maketexttransformation) - [utils](#utils) - - [FromHex](#fromhex-1) - [Text](#text) - [validation](#validation) - - [textLengthEquals](#textlengthequals) - - [textLengthMax](#textlengthmax) - - [textLengthMin](#textlengthmin) + - [length](#length) + - [max](#max) + - [min](#min) --- # composition -## textLengthBetween +## between Creates a curried filter that validates text length is within a range. Preserves Context inference from the base schema. @@ -50,7 +41,7 @@ Preserves Context inference from the base schema. **Signature** ```ts -export declare const textLengthBetween: ( +export declare const between: ( min: number, max: number, moduleName: string @@ -68,7 +59,7 @@ Convert bytes to text **Signature** ```ts -export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => string +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -92,7 +83,7 @@ Convert text to bytes **Signature** ```ts -export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => Uint8Array +export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -113,134 +104,52 @@ Added in v2.0.0 ## FromBytes -Schema for converting between strings and hex representation of UTF-8 bytes. +Schema for converting between strings and bytes (UTF-8). ``` -text <-> hex -``` - -**Signature** - -```ts -export declare const FromBytes: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - -# testing - -## arbitrary - -FastCheck arbitrary for generating random text strings - -**Signature** - -```ts -export declare const arbitrary: FastCheck.Arbitrary +text <-> bytes ``` -Added in v2.0.0 - -# types - -## TextTransformationConfig (interface) - -Configuration for text transformations. - **Signature** ```ts -export interface TextTransformationConfig { - id: string - to: Schema.Schema - from: Schema.Schema -} +export declare const FromBytes: Schema.transform ``` Added in v2.0.0 -# unsafe - -## fromBytesUnsafe - -Convert bytes to text (unsafe, no validation). - -**Signature** - -```ts -export declare const fromBytesUnsafe: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -## fromHexUnsafe - -Convert hex to text (unsafe, no validation). +## FromHex -**Signature** +Schema for converting between strings and hex representation of UTF-8 bytes. -```ts -export declare const fromHexUnsafe: (hex: string) => string ``` - -Added in v2.0.0 - -## toBytesUnsafe - -Convert text to bytes (unsafe, no validation). - -**Signature** - -```ts -export declare const toBytesUnsafe: (text: string) => Uint8Array +text <-> hex ``` -Added in v2.0.0 - -## toHexUnsafe - -Convert text to hex (unsafe, no validation). - **Signature** ```ts -export declare const toHexUnsafe: (text: string) => string +export declare const FromHex: Schema.transform, typeof Schema.String> ``` Added in v2.0.0 -# utilities +# testing -## makeTextTransformation +## arbitrary -Creates a text transformation schema. +FastCheck arbitrary for generating random text strings **Signature** ```ts -export declare const makeTextTransformation: ( - config: TextTransformationConfig -) => Schema.transform, Schema.Schema> +export declare const arbitrary: FastCheck.Arbitrary ``` Added in v2.0.0 # utils -## FromHex - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> -> -``` - ## Text **Signature** @@ -251,14 +160,14 @@ export declare const Text: typeof Schema.String # validation -## textLengthEquals +## length Creates a schema that validates text length equals a specific value. **Signature** ```ts -export declare const textLengthEquals: ( +export declare const length: ( length: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter @@ -266,14 +175,14 @@ export declare const textLengthEquals: ( Added in v2.0.0 -## textLengthMax +## max Creates a schema that validates text length is at most max. **Signature** ```ts -export declare const textLengthMax: ( +export declare const max: ( max: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter @@ -281,14 +190,14 @@ export declare const textLengthMax: ( Added in v2.0.0 -## textLengthMin +## min Creates a schema that validates text length is at least min. **Signature** ```ts -export declare const textLengthMin: ( +export declare const min: ( min: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter diff --git a/docs/content/docs/modules/core/Text128.mdx b/docs/content/docs/modules/core/Text128.mdx index 2a5dd451..bac62a48 100644 --- a/docs/content/docs/modules/core/Text128.mdx +++ b/docs/content/docs/modules/core/Text128.mdx @@ -25,10 +25,9 @@ parent: Modules - [schemas](#schemas) - [Text128](#text128) - [utils](#utils) - - [FromVariableBytes](#fromvariablebytes) - - [FromVariableHex](#fromvariablehex) + - [FromBytes](#frombytes-1) + - [FromHex](#fromhex-1) - [TEXT128_MAX_LENGTH](#text128_max_length) - - [Text128 (type alias)](#text128-type-alias) --- @@ -70,7 +69,7 @@ Encode Text128 to bytes (unsafe) **Signature** ```ts -export declare const toBytes: (text: Text128) => Uint8Array +export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -82,7 +81,7 @@ Encode Text128 to hex string (unsafe) **Signature** ```ts -export declare const toHex: (text: Text128) => string +export declare const toHex: (a: string, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -96,7 +95,7 @@ Parse Text128 from bytes (unsafe) **Signature** ```ts -export declare const fromBytes: (bytes: Uint8Array) => Text128 +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -108,7 +107,7 @@ Parse Text128 from hex string (unsafe) **Signature** ```ts -export declare const fromHex: (hex: string) => Text128 +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -138,32 +137,35 @@ Follows the Conway-era CDDL specification. **Signature** ```ts -export declare const Text128: Schema.filter +export declare const Text128: Schema.refine ``` Added in v2.0.0 # utils -## FromVariableBytes +## FromBytes **Signature** ```ts -export declare const FromVariableBytes: Schema.transform< - Schema.Schema, - Schema.Schema +export declare const FromBytes: Schema.transform< + Schema.transform, + Schema.refine > ``` -## FromVariableHex +## FromHex **Signature** ```ts -export declare const FromVariableHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> +export declare const FromHex: Schema.transform< + Schema.Schema, + Schema.transform< + Schema.transform, + Schema.refine + > > ``` @@ -174,11 +176,3 @@ export declare const FromVariableHex: Schema.transform< ```ts export declare const TEXT128_MAX_LENGTH: 128 ``` - -## Text128 (type alias) - -**Signature** - -```ts -export type Text128 = typeof Text128.Type -``` diff --git a/docs/content/docs/modules/core/Transaction.mdx b/docs/content/docs/modules/core/Transaction.mdx index 9b65075a..358aed0e 100644 --- a/docs/content/docs/modules/core/Transaction.mdx +++ b/docs/content/docs/modules/core/Transaction.mdx @@ -149,7 +149,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/TransactionBody.mdx b/docs/content/docs/modules/core/TransactionBody.mdx index 96090921..7f8070a3 100644 --- a/docs/content/docs/modules/core/TransactionBody.mdx +++ b/docs/content/docs/modules/core/TransactionBody.mdx @@ -241,7 +241,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/TransactionInput.mdx b/docs/content/docs/modules/core/TransactionInput.mdx index 4521d1f0..063fff74 100644 --- a/docs/content/docs/modules/core/TransactionInput.mdx +++ b/docs/content/docs/modules/core/TransactionInput.mdx @@ -194,7 +194,7 @@ CBOR hex transformation schema for TransactionInput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/TransactionMetadatum.mdx b/docs/content/docs/modules/core/TransactionMetadatum.mdx index c4ea9148..764bc1ef 100644 --- a/docs/content/docs/modules/core/TransactionMetadatum.mdx +++ b/docs/content/docs/modules/core/TransactionMetadatum.mdx @@ -316,7 +316,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/TransactionOutput.mdx b/docs/content/docs/modules/core/TransactionOutput.mdx index 6daf8b51..096ccb37 100644 --- a/docs/content/docs/modules/core/TransactionOutput.mdx +++ b/docs/content/docs/modules/core/TransactionOutput.mdx @@ -372,7 +372,7 @@ CBOR hex transformation schema for TransactionOutput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/TransactionWitnessSet.mdx b/docs/content/docs/modules/core/TransactionWitnessSet.mdx index 6f9551b6..103462ff 100644 --- a/docs/content/docs/modules/core/TransactionWitnessSet.mdx +++ b/docs/content/docs/modules/core/TransactionWitnessSet.mdx @@ -393,7 +393,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/docs/content/docs/modules/core/TxOut.mdx b/docs/content/docs/modules/core/TxOut.mdx index 0520ae85..2b8b45f1 100644 --- a/docs/content/docs/modules/core/TxOut.mdx +++ b/docs/content/docs/modules/core/TxOut.mdx @@ -364,7 +364,7 @@ CBOR hex transformation schema for TransactionOutput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/UnitInterval.mdx b/docs/content/docs/modules/core/UnitInterval.mdx index a8f8e988..78243272 100644 --- a/docs/content/docs/modules/core/UnitInterval.mdx +++ b/docs/content/docs/modules/core/UnitInterval.mdx @@ -188,7 +188,7 @@ Transforms between hex string and UnitInterval using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/Url.mdx b/docs/content/docs/modules/core/Url.mdx index 255c6def..d0565eee 100644 --- a/docs/content/docs/modules/core/Url.mdx +++ b/docs/content/docs/modules/core/Url.mdx @@ -56,7 +56,7 @@ Encode Url to bytes. **Signature** ```ts -export declare const toBytes: (url: Url) => Uint8Array +export declare const toBytes: (url: Url) => any ``` Added in v2.0.0 @@ -196,7 +196,10 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.transform< + Schema.transform, + Schema.refine + >, typeof Url > ``` @@ -207,9 +210,12 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< - Schema.transform, Schema.Schema>, + Schema.transform< + Schema.transform, + Schema.refine + >, typeof Url > > diff --git a/docs/content/docs/modules/core/Value.mdx b/docs/content/docs/modules/core/Value.mdx index ef86932b..464b0256 100644 --- a/docs/content/docs/modules/core/Value.mdx +++ b/docs/content/docs/modules/core/Value.mdx @@ -268,7 +268,7 @@ Transforms between CBOR hex string and Value using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/VotingProcedures.mdx b/docs/content/docs/modules/core/VotingProcedures.mdx index de5e6e7a..47d2b2b3 100644 --- a/docs/content/docs/modules/core/VotingProcedures.mdx +++ b/docs/content/docs/modules/core/VotingProcedures.mdx @@ -519,7 +519,7 @@ CBOR hex transformation schema for VotingProcedures. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/VrfCert.mdx b/docs/content/docs/modules/core/VrfCert.mdx index f09409c5..28625b2c 100644 --- a/docs/content/docs/modules/core/VrfCert.mdx +++ b/docs/content/docs/modules/core/VrfCert.mdx @@ -222,7 +222,7 @@ CBOR hex transformation schema for VrfCert. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, @@ -338,7 +338,7 @@ vrf_output = bytes .size 32 ```ts export declare const VRFOutputHexSchema: Schema.transform< Schema.filter>, - Schema.transform, Schema.SchemaClass> + Schema.SchemaClass > ``` @@ -406,8 +406,8 @@ vrf_proof = bytes .size 80 ```ts export declare const VRFProofFromBytes: Schema.transform< - Schema.filter, - typeof VRFProof + Schema.SchemaClass, + Schema.SchemaClass > ``` @@ -422,8 +422,8 @@ vrf_proof = bytes .size 80 ```ts export declare const VRFProofHexSchema: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, typeof VRFProof> + Schema.filter>, + Schema.SchemaClass > ``` diff --git a/docs/content/docs/modules/core/Withdrawals.mdx b/docs/content/docs/modules/core/Withdrawals.mdx index a8aedc67..379f8350 100644 --- a/docs/content/docs/modules/core/Withdrawals.mdx +++ b/docs/content/docs/modules/core/Withdrawals.mdx @@ -275,7 +275,7 @@ CBOR hex transformation schema for Withdrawals. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/message-signing/CoseSign.mdx b/docs/content/docs/modules/core/message-signing/CoseSign.mdx index c3f3f2f4..83195324 100644 --- a/docs/content/docs/modules/core/message-signing/CoseSign.mdx +++ b/docs/content/docs/modules/core/message-signing/CoseSign.mdx @@ -291,7 +291,7 @@ CBOR hex transformation schema for COSESign. export declare const COSESignFromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/message-signing/CoseSign1.mdx b/docs/content/docs/modules/core/message-signing/CoseSign1.mdx index 8c67dcb8..06e80d2f 100644 --- a/docs/content/docs/modules/core/message-signing/CoseSign1.mdx +++ b/docs/content/docs/modules/core/message-signing/CoseSign1.mdx @@ -341,7 +341,7 @@ CBOR hex transformation schema for COSESign1. export declare const COSESign1FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/core/message-signing/Header.mdx b/docs/content/docs/modules/core/message-signing/Header.mdx index 616af9a7..257f992d 100644 --- a/docs/content/docs/modules/core/message-signing/Header.mdx +++ b/docs/content/docs/modules/core/message-signing/Header.mdx @@ -452,7 +452,7 @@ CBOR hex transformation schema for HeaderMap. export declare const HeaderMapFromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/docs/content/docs/modules/sdk/AddressDetails.mdx b/docs/content/docs/modules/sdk/AddressDetails.mdx index 23bfaba4..229cdbab 100644 --- a/docs/content/docs/modules/sdk/AddressDetails.mdx +++ b/docs/content/docs/modules/sdk/AddressDetails.mdx @@ -127,7 +127,7 @@ export declare const FromBech32: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transformOrFail< - Schema.refine, + typeof Schema.String, Schema.SchemaClass, never > diff --git a/packages/evolution/docs/modules/core/Address.ts.md b/packages/evolution/docs/modules/core/Address.ts.md index 5a5af7b1..78452a70 100644 --- a/packages/evolution/docs/modules/core/Address.ts.md +++ b/packages/evolution/docs/modules/core/Address.ts.md @@ -147,7 +147,7 @@ Handles both BaseAddress (57 bytes) and EnterpriseAddress (29 bytes) ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.Union<[Schema.filter, Schema.filter]>, + Schema.Union<[Schema.SchemaClass, Schema.SchemaClass]>, Schema.SchemaClass, never > @@ -163,9 +163,11 @@ Transform from hex string to AddressStructure ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.Union<[Schema.filter, Schema.filter]>, + Schema.Union< + [Schema.SchemaClass, Schema.SchemaClass] + >, Schema.SchemaClass, never > @@ -219,7 +221,7 @@ Added in v1.0.0 **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => Address +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => Address ``` ## fromHex @@ -243,7 +245,7 @@ export declare const toBech32: (a: Address, overrideOptions?: ParseOptions) => s **Signature** ```ts -export declare const toBytes: (a: Address, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: Address, overrideOptions?: ParseOptions) => Uint8Array ``` ## toHex diff --git a/packages/evolution/docs/modules/core/AddressEras.ts.md b/packages/evolution/docs/modules/core/AddressEras.ts.md index 37f1ac5e..d817294b 100644 --- a/packages/evolution/docs/modules/core/AddressEras.ts.md +++ b/packages/evolution/docs/modules/core/AddressEras.ts.md @@ -275,7 +275,7 @@ Schema for encoding/decoding addresses as hex strings. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.SchemaClass< diff --git a/packages/evolution/docs/modules/core/Anchor.ts.md b/packages/evolution/docs/modules/core/Anchor.ts.md index 453684d9..518ca7f8 100644 --- a/packages/evolution/docs/modules/core/Anchor.ts.md +++ b/packages/evolution/docs/modules/core/Anchor.ts.md @@ -191,7 +191,7 @@ CBOR hex transformation schema for Anchor. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Assets.ts.md b/packages/evolution/docs/modules/core/Assets.ts.md index fc7a9242..86859fa1 100644 --- a/packages/evolution/docs/modules/core/Assets.ts.md +++ b/packages/evolution/docs/modules/core/Assets.ts.md @@ -448,7 +448,7 @@ CBOR hex transformation schema for Assets. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/AuxiliaryData.ts.md b/packages/evolution/docs/modules/core/AuxiliaryData.ts.md index 62983822..916212c4 100644 --- a/packages/evolution/docs/modules/core/AuxiliaryData.ts.md +++ b/packages/evolution/docs/modules/core/AuxiliaryData.ts.md @@ -515,7 +515,7 @@ Transforms between CBOR hex string and AuxiliaryData using CDDL format. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/BaseAddress.ts.md b/packages/evolution/docs/modules/core/BaseAddress.ts.md index f034742d..2d5e00a7 100644 --- a/packages/evolution/docs/modules/core/BaseAddress.ts.md +++ b/packages/evolution/docs/modules/core/BaseAddress.ts.md @@ -53,7 +53,7 @@ Convert a BaseAddress to bytes. **Signature** ```ts -export declare const toBytes: (data: BaseAddress) => any +export declare const toBytes: (data: BaseAddress) => Uint8Array ``` Added in v2.0.0 @@ -150,7 +150,7 @@ toString(): string ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -162,9 +162,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/packages/evolution/docs/modules/core/Bech32.ts.md b/packages/evolution/docs/modules/core/Bech32.ts.md index 2b3b88ee..049cfd87 100644 --- a/packages/evolution/docs/modules/core/Bech32.ts.md +++ b/packages/evolution/docs/modules/core/Bech32.ts.md @@ -54,7 +54,7 @@ export declare const FromBytes: ( export declare const FromHex: ( prefix?: string ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail > ``` diff --git a/packages/evolution/docs/modules/core/Bip32PrivateKey.ts.md b/packages/evolution/docs/modules/core/Bip32PrivateKey.ts.md index 212ff5c1..2d2f4793 100644 --- a/packages/evolution/docs/modules/core/Bip32PrivateKey.ts.md +++ b/packages/evolution/docs/modules/core/Bip32PrivateKey.ts.md @@ -164,7 +164,7 @@ Convert a Bip32PrivateKey to raw bytes. **Signature** ```ts -export declare const toBytes: (a: Bip32PrivateKey, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: Bip32PrivateKey, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -204,7 +204,7 @@ Parse a Bip32PrivateKey from raw bytes. **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => Bip32PrivateKey +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => Bip32PrivateKey ``` Added in v2.0.0 @@ -285,8 +285,8 @@ Schema for transforming between Uint8Array and Bip32PrivateKey. ```ts export declare const FromBytes: Schema.transform< - Schema.filter, - typeof Bip32PrivateKey + Schema.SchemaClass, + Schema.SchemaClass > ``` @@ -300,8 +300,11 @@ Schema for transforming between hex string and Bip32PrivateKey. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, typeof Bip32PrivateKey> + Schema.filter>, + Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass + > > ``` diff --git a/packages/evolution/docs/modules/core/BootstrapWitness.ts.md b/packages/evolution/docs/modules/core/BootstrapWitness.ts.md index 827964ed..2e5d811d 100644 --- a/packages/evolution/docs/modules/core/BootstrapWitness.ts.md +++ b/packages/evolution/docs/modules/core/BootstrapWitness.ts.md @@ -130,7 +130,7 @@ Transforms between hex string and BootstrapWitness using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/ByronAddress.ts.md b/packages/evolution/docs/modules/core/ByronAddress.ts.md index 7807fb21..2ab2c005 100644 --- a/packages/evolution/docs/modules/core/ByronAddress.ts.md +++ b/packages/evolution/docs/modules/core/ByronAddress.ts.md @@ -96,7 +96,7 @@ Schema for encoding/decoding Byron addresses as hex strings. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail > ``` diff --git a/packages/evolution/docs/modules/core/Bytes.ts.md b/packages/evolution/docs/modules/core/Bytes.ts.md index b1ff1038..2172cf64 100644 --- a/packages/evolution/docs/modules/core/Bytes.ts.md +++ b/packages/evolution/docs/modules/core/Bytes.ts.md @@ -15,37 +15,11 @@ parent: Modules - [bytesLengthEquals](#byteslengthequals) - [bytesLengthMax](#byteslengthmax) - [bytesLengthMin](#byteslengthmin) - - [bytesStartsWithPrefix](#bytesstartswithprefix) - - [hexLengthBetween](#hexlengthbetween) - - [hexLengthEquals](#hexlengthequals) - - [hexLengthMax](#hexlengthmax) - - [hexLengthMin](#hexlengthmin) - - [hexStartsWithPrefix](#hexstartswithprefix) - [conversions](#conversions) - [fromHex](#fromhex) - - [fromHexLenient](#fromhexlenient) - [toHex](#tohex) - - [toHexLenient](#tohexlenient) -- [equality](#equality) - - [bytesEquals](#bytesequals) -- [namespaces](#namespaces) - - [Either (namespace)](#either-namespace) -- [predicates](#predicates) - - [isHexLenient](#ishexlenient) -- [schemas](#schemas) - - [HexLenientSchema](#hexlenientschema) - [utils](#utils) - - [BytesError (class)](#byteserror-class) - - [BytesFromHexLenient](#bytesfromhexlenient) - - [FromHex](#fromhex-1) - - [HexSchema](#hexschema) - [equals](#equals) - - [fromHexLenientUnsafe](#fromhexlenientunsafe) - - [fromHexUnsafe](#fromhexunsafe) - - [isHex](#ishex) - - [makeBytesTransformation](#makebytestransformation) - - [toHexLenientUnsafe](#tohexlenientunsafe) - - [toHexUnsafe](#tohexunsafe) --- @@ -113,97 +87,6 @@ export declare const bytesLengthMin: ( Added in v2.0.0 -## bytesStartsWithPrefix - -Creates a curried filter that validates bytes start with specific prefix. -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const bytesStartsWithPrefix: ( - prefix: Uint8Array -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthBetween - -Creates a curried filter that validates byte length is within a range (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthBetween: ( - minBytes: number, - maxBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthEquals - -Creates a curried filter that validates exact byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthEquals: ( - byteLength: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthMax - -Creates a curried filter that validates maximum byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthMax: ( - maxBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexLengthMin - -Creates a curried filter that validates minimum byte length (for hex strings). -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexLengthMin: ( - minBytes: number -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - -## hexStartsWithPrefix - -Creates a curried filter that validates hex starts with specific prefix. -Preserves Context inference from the base schema. - -**Signature** - -```ts -export declare const hexStartsWithPrefix: ( - prefix: string -) => >(baseSchema: S) => Schema.filter -``` - -Added in v2.0.0 - # conversions ## fromHex @@ -213,19 +96,7 @@ Convert hex string to Uint8Array. Throws on invalid input. **Signature** ```ts -export declare const fromHex: (hex: string) => Uint8Array -``` - -Added in v2.0.0 - -## fromHexLenient - -Convert hex string to Uint8Array (allows empty strings). Throws on invalid input. - -**Signature** - -```ts -export declare const fromHexLenient: (hex: string) => Uint8Array +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -237,116 +108,13 @@ Convert Uint8Array to hex string. Never fails. **Signature** ```ts -export declare const toHex: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -## toHexLenient - -Convert Uint8Array to hex string (returns empty string for empty arrays). Never fails. - -**Signature** - -```ts -export declare const toHexLenient: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -# equality - -## bytesEquals - -Compare two Uint8Array instances for equality. -Returns true if both arrays have the same length and same byte values. - -**Signature** - -```ts -export declare const bytesEquals: (a: Uint8Array | undefined, b: Uint8Array | undefined) => boolean -``` - -Added in v2.0.0 - -# namespaces - -## Either (namespace) - -Safe API that returns Either for error handling instead of throwing. - -Added in v2.0.0 - -# predicates - -## isHexLenient - -Lenient version of isHex that allows empty strings. -Useful for PlutusData where empty byte arrays are valid. - -**Signature** - -```ts -export declare const isHexLenient: (input: string) => boolean -``` - -Added in v2.0.0 - -# schemas - -## HexLenientSchema - -Lenient hex schema that allows empty strings. -Useful for PlutusData where empty byte arrays are valid. - -**Signature** - -```ts -export declare const HexLenientSchema: Schema.refine +export declare const toHex: (a: Uint8Array, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 # utils -## BytesError (class) - -**Signature** - -```ts -export declare class BytesError -``` - -## BytesFromHexLenient - -**Signature** - -```ts -export declare const BytesFromHexLenient: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -## FromHex - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.refine -``` - ## equals **Signature** @@ -354,63 +122,3 @@ export declare const HexSchema: Schema.refine ```ts export declare const equals: (a: Uint8Array, b: Uint8Array) => boolean ``` - -## fromHexLenientUnsafe - -Pure conversion function from validated hex string to Uint8Array (lenient version). -Assumes input is already validated hex or empty string. - -**Signature** - -```ts -export declare const fromHexLenientUnsafe: (hex: string) => Uint8Array -``` - -## fromHexUnsafe - -Pure conversion function from validated hex string to Uint8Array. -Assumes input is already validated hex. - -**Signature** - -```ts -export declare const fromHexUnsafe: (hex: string) => Uint8Array -``` - -## isHex - -**Signature** - -```ts -export declare const isHex: (input: string) => boolean -``` - -## makeBytesTransformation - -**Signature** - -```ts -export declare const makeBytesTransformation: ( - config: Uint8ArrayTransformationConfig -) => Schema.transform, Schema.Schema> -``` - -## toHexLenientUnsafe - -Pure conversion function from Uint8Array to hex string (lenient version). - -**Signature** - -```ts -export declare const toHexLenientUnsafe: (bytes: Uint8Array) => string -``` - -## toHexUnsafe - -Pure conversion function from Uint8Array to hex string. - -**Signature** - -```ts -export declare const toHexUnsafe: (bytes: Uint8Array) => string -``` diff --git a/packages/evolution/docs/modules/core/Bytes128.ts.md b/packages/evolution/docs/modules/core/Bytes128.ts.md index 7ea92d7f..0659c973 100644 --- a/packages/evolution/docs/modules/core/Bytes128.ts.md +++ b/packages/evolution/docs/modules/core/Bytes128.ts.md @@ -22,13 +22,9 @@ Added in v2.0.0 - [encoding](#encoding) - [toHex](#tohex) - [toVariableHex](#tovariablehex) -- [schemas](#schemas) - - [FromHex](#fromhex-1) - - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) + - [BytesFromHex](#bytesfromhex) + - [VariableBytesFromHex](#variablebytesfromhex) - [equals](#equals) --- @@ -99,62 +95,22 @@ export declare const toVariableHex: (a: Uint8Array, overrideOptions?: ParseOptio Added in v2.0.0 -# schemas - -## FromHex - -Schema transformation for fixed-length bytes - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - -## VariableBytesFromHex - -Schema transformation for variable-length bytes (0..BYTES_LENGTH). - -**Signature** - -```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - # utils -## BytesSchema +## BytesFromHex **Signature** ```ts -export declare const BytesSchema: Schema.filter +export declare const BytesFromHex: Schema.filter> ``` -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes +## VariableBytesFromHex **Signature** ```ts -export declare const VariableBytes: Schema.filter +export declare const VariableBytesFromHex: Schema.filter> ``` ## equals diff --git a/packages/evolution/docs/modules/core/Bytes29.ts.md b/packages/evolution/docs/modules/core/Bytes29.ts.md index ce359db3..6785aabd 100644 --- a/packages/evolution/docs/modules/core/Bytes29.ts.md +++ b/packages/evolution/docs/modules/core/Bytes29.ts.md @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/packages/evolution/docs/modules/core/Bytes448.ts.md b/packages/evolution/docs/modules/core/Bytes448.ts.md index 6f49a256..1ba0f074 100644 --- a/packages/evolution/docs/modules/core/Bytes448.ts.md +++ b/packages/evolution/docs/modules/core/Bytes448.ts.md @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/packages/evolution/docs/modules/core/Bytes57.ts.md b/packages/evolution/docs/modules/core/Bytes57.ts.md index 13f352eb..df114d73 100644 --- a/packages/evolution/docs/modules/core/Bytes57.ts.md +++ b/packages/evolution/docs/modules/core/Bytes57.ts.md @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/packages/evolution/docs/modules/core/Bytes64.ts.md b/packages/evolution/docs/modules/core/Bytes64.ts.md index 23e5d10e..1ab7ca5d 100644 --- a/packages/evolution/docs/modules/core/Bytes64.ts.md +++ b/packages/evolution/docs/modules/core/Bytes64.ts.md @@ -60,7 +60,7 @@ Decode variable-length hex (0..BYTES_LENGTH) into bytes. **Signature** ```ts -export declare const fromVariableHex: (i: any, overrideOptions?: ParseOptions) => any +export declare const fromVariableHex: (i: string, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -86,7 +86,7 @@ Encode variable-length bytes (0..BYTES_LENGTH) to hex. **Signature** ```ts -export declare const toVariableHex: (a: any, overrideOptions?: ParseOptions) => any +export declare const toVariableHex: (a: Uint8Array, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -106,7 +106,7 @@ export declare const BytesFromHex: Schema.filter +export declare const VariableBytesFromHex: Schema.filter> ``` ## equals diff --git a/packages/evolution/docs/modules/core/Bytes80.ts.md b/packages/evolution/docs/modules/core/Bytes80.ts.md index 3aecd165..a51544ca 100644 --- a/packages/evolution/docs/modules/core/Bytes80.ts.md +++ b/packages/evolution/docs/modules/core/Bytes80.ts.md @@ -23,11 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - [equals](#equals) --- @@ -100,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -122,32 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - ## equals **Signature** diff --git a/packages/evolution/docs/modules/core/Bytes96.ts.md b/packages/evolution/docs/modules/core/Bytes96.ts.md index 37fc1b61..a5a2a28a 100644 --- a/packages/evolution/docs/modules/core/Bytes96.ts.md +++ b/packages/evolution/docs/modules/core/Bytes96.ts.md @@ -23,12 +23,9 @@ Added in v2.0.0 - [toHex](#tohex) - [toVariableHex](#tovariablehex) - [schemas](#schemas) - - [FromHex](#fromhex-1) + - [BytesFromHex](#bytesfromhex) - [VariableBytesFromHex](#variablebytesfromhex) - [utils](#utils) - - [BytesSchema](#bytesschema) - - [HexSchema](#hexschema) - - [VariableBytes](#variablebytes) - [equals](#equals) --- @@ -101,17 +98,14 @@ Added in v2.0.0 # schemas -## FromHex +## BytesFromHex Schema transformation for fixed-length bytes **Signature** ```ts -export declare const FromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const BytesFromHex: Schema.filter> ``` Added in v2.0.0 @@ -123,40 +117,13 @@ Schema transformation for variable-length bytes (0..BYTES_LENGTH). **Signature** ```ts -export declare const VariableBytesFromHex: Schema.transform< - Schema.Schema, - Schema.Schema -> +export declare const VariableBytesFromHex: Schema.filter> ``` Added in v2.0.0 # utils -## BytesSchema - -**Signature** - -```ts -export declare const BytesSchema: Schema.filter -``` - -## HexSchema - -**Signature** - -```ts -export declare const HexSchema: Schema.filter> -``` - -## VariableBytes - -**Signature** - -```ts -export declare const VariableBytes: Schema.filter -``` - ## equals **Signature** diff --git a/packages/evolution/docs/modules/core/CBOR.ts.md b/packages/evolution/docs/modules/core/CBOR.ts.md index bd9d4c5d..f2d8bae2 100644 --- a/packages/evolution/docs/modules/core/CBOR.ts.md +++ b/packages/evolution/docs/modules/core/CBOR.ts.md @@ -407,7 +407,7 @@ export declare const Float: typeof Schema.Number export declare const FromHex: ( options: CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail, never> > ``` diff --git a/packages/evolution/docs/modules/core/Certificate.ts.md b/packages/evolution/docs/modules/core/Certificate.ts.md index da0babfe..b930142f 100644 --- a/packages/evolution/docs/modules/core/Certificate.ts.md +++ b/packages/evolution/docs/modules/core/Certificate.ts.md @@ -535,7 +535,7 @@ CBOR hex transformation schema for Certificate. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Constitution.ts.md b/packages/evolution/docs/modules/core/Constitution.ts.md index f6159524..4b822585 100644 --- a/packages/evolution/docs/modules/core/Constitution.ts.md +++ b/packages/evolution/docs/modules/core/Constitution.ts.md @@ -187,7 +187,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/CostModel.ts.md b/packages/evolution/docs/modules/core/CostModel.ts.md index 49dc9aff..8b8f9d00 100644 --- a/packages/evolution/docs/modules/core/CostModel.ts.md +++ b/packages/evolution/docs/modules/core/CostModel.ts.md @@ -75,7 +75,7 @@ Transforms between hex string and CostModels using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Credential.ts.md b/packages/evolution/docs/modules/core/Credential.ts.md index 51655004..61bf0656 100644 --- a/packages/evolution/docs/modules/core/Credential.ts.md +++ b/packages/evolution/docs/modules/core/Credential.ts.md @@ -214,7 +214,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/DRep.ts.md b/packages/evolution/docs/modules/core/DRep.ts.md index b9ff06e7..08f87c8b 100644 --- a/packages/evolution/docs/modules/core/DRep.ts.md +++ b/packages/evolution/docs/modules/core/DRep.ts.md @@ -601,7 +601,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Data.ts.md b/packages/evolution/docs/modules/core/Data.ts.md index dcf121d5..60027bf5 100644 --- a/packages/evolution/docs/modules/core/Data.ts.md +++ b/packages/evolution/docs/modules/core/Data.ts.md @@ -554,7 +554,7 @@ Transforms between CBOR hex string and Data using CDDL encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/DatumOption.ts.md b/packages/evolution/docs/modules/core/DatumOption.ts.md index 74212bd4..b3f2db87 100644 --- a/packages/evolution/docs/modules/core/DatumOption.ts.md +++ b/packages/evolution/docs/modules/core/DatumOption.ts.md @@ -270,7 +270,7 @@ Transforms between hex string and DatumOption using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/DnsName.ts.md b/packages/evolution/docs/modules/core/DnsName.ts.md index 3343a722..9c13486e 100644 --- a/packages/evolution/docs/modules/core/DnsName.ts.md +++ b/packages/evolution/docs/modules/core/DnsName.ts.md @@ -52,7 +52,7 @@ Encode DnsName to bytes. **Signature** ```ts -export declare const toBytes: (dnsName: DnsName) => Uint8Array +export declare const toBytes: (a: string & Brand<"DnsName">, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -64,7 +64,7 @@ Encode DnsName to hex string. **Signature** ```ts -export declare const toHex: (dnsName: DnsName) => string +export declare const toHex: (a: string & Brand<"DnsName">, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -79,13 +79,7 @@ dns_name = text .size (0 .. 128) **Signature** ```ts -export declare const DnsName: Schema.brand< - Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" -> +export declare const DnsName: Schema.brand, "DnsName"> ``` Added in v2.0.0 @@ -111,7 +105,7 @@ Parse DnsName from bytes. **Signature** ```ts -export declare const fromBytes: (bytes: Uint8Array) => DnsName +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string & Brand<"DnsName"> ``` Added in v2.0.0 @@ -123,7 +117,7 @@ Parse DnsName from hex string. **Signature** ```ts -export declare const fromHex: (hex: string) => DnsName +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => string & Brand<"DnsName"> ``` Added in v2.0.0 @@ -150,14 +144,11 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.brand< - Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" - > + Schema.transform< + Schema.transform, + Schema.refine + >, + Schema.brand, "DnsName"> > ``` @@ -168,15 +159,12 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - Schema.brand< + Schema.Schema, Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> - >, - "DnsName" - > + Schema.transform, + Schema.refine + > + >, + Schema.brand, "DnsName"> > ``` diff --git a/packages/evolution/docs/modules/core/EnterpriseAddress.ts.md b/packages/evolution/docs/modules/core/EnterpriseAddress.ts.md index 1ee62db9..dd2c67d7 100644 --- a/packages/evolution/docs/modules/core/EnterpriseAddress.ts.md +++ b/packages/evolution/docs/modules/core/EnterpriseAddress.ts.md @@ -40,7 +40,7 @@ Convert a EnterpriseAddress to bytes. **Signature** ```ts -export declare const toBytes: (data: EnterpriseAddress) => any +export declare const toBytes: (data: EnterpriseAddress) => Uint8Array ``` Added in v2.0.0 @@ -159,7 +159,7 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -171,9 +171,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/packages/evolution/docs/modules/core/Header.ts.md b/packages/evolution/docs/modules/core/Header.ts.md index a5a84fe4..3322be73 100644 --- a/packages/evolution/docs/modules/core/Header.ts.md +++ b/packages/evolution/docs/modules/core/Header.ts.md @@ -272,7 +272,7 @@ CBOR hex transformation schema for Header. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/HeaderBody.ts.md b/packages/evolution/docs/modules/core/HeaderBody.ts.md index cedbe038..97a4f62f 100644 --- a/packages/evolution/docs/modules/core/HeaderBody.ts.md +++ b/packages/evolution/docs/modules/core/HeaderBody.ts.md @@ -220,7 +220,7 @@ CBOR hex transformation schema for HeaderBody. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/KesSignature.ts.md b/packages/evolution/docs/modules/core/KesSignature.ts.md index 43694555..b9d35a0b 100644 --- a/packages/evolution/docs/modules/core/KesSignature.ts.md +++ b/packages/evolution/docs/modules/core/KesSignature.ts.md @@ -56,7 +56,7 @@ Encode KesSignature to bytes. **Signature** ```ts -export declare const toBytes: (a: KesSignature, overrideOptions?: ParseOptions) => any +export declare const toBytes: (a: KesSignature, overrideOptions?: ParseOptions) => Uint8Array ``` Added in v2.0.0 @@ -82,7 +82,7 @@ Parse KesSignature from bytes. **Signature** ```ts -export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => KesSignature +export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => KesSignature ``` Added in v2.0.0 @@ -175,7 +175,10 @@ toString(): string **Signature** ```ts -export declare const FromBytes: Schema.transform, typeof KesSignature> +export declare const FromBytes: Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass +> ``` ## FromHex @@ -184,7 +187,10 @@ export declare const FromBytes: Schema.transform, Schema.Schema>, - Schema.transform, typeof KesSignature> + Schema.filter>, + Schema.transform< + Schema.SchemaClass, + Schema.SchemaClass + > > ``` diff --git a/packages/evolution/docs/modules/core/Metadata.ts.md b/packages/evolution/docs/modules/core/Metadata.ts.md index 9a532115..253531e6 100644 --- a/packages/evolution/docs/modules/core/Metadata.ts.md +++ b/packages/evolution/docs/modules/core/Metadata.ts.md @@ -234,7 +234,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/Mint.ts.md b/packages/evolution/docs/modules/core/Mint.ts.md index 26c0a262..3146e40b 100644 --- a/packages/evolution/docs/modules/core/Mint.ts.md +++ b/packages/evolution/docs/modules/core/Mint.ts.md @@ -344,7 +344,7 @@ Transforms between CBOR hex string and Mint using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/MultiAsset.ts.md b/packages/evolution/docs/modules/core/MultiAsset.ts.md index 87f82978..03cfa1ba 100644 --- a/packages/evolution/docs/modules/core/MultiAsset.ts.md +++ b/packages/evolution/docs/modules/core/MultiAsset.ts.md @@ -321,7 +321,7 @@ Transforms between CBOR hex string and MultiAsset using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/MultiHostName.ts.md b/packages/evolution/docs/modules/core/MultiHostName.ts.md index f4daf2d1..08d179ea 100644 --- a/packages/evolution/docs/modules/core/MultiHostName.ts.md +++ b/packages/evolution/docs/modules/core/MultiHostName.ts.md @@ -206,7 +206,7 @@ CBOR hex transformation schema for MultiHostName. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/NativeScripts.ts.md b/packages/evolution/docs/modules/core/NativeScripts.ts.md index 6c0c6e83..21c391e4 100644 --- a/packages/evolution/docs/modules/core/NativeScripts.ts.md +++ b/packages/evolution/docs/modules/core/NativeScripts.ts.md @@ -384,7 +384,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/NativeScriptsOLD.ts.md b/packages/evolution/docs/modules/core/NativeScriptsOLD.ts.md index b214bd01..88691571 100644 --- a/packages/evolution/docs/modules/core/NativeScriptsOLD.ts.md +++ b/packages/evolution/docs/modules/core/NativeScriptsOLD.ts.md @@ -272,7 +272,7 @@ Transforms between CBOR hex string and Native using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/NonnegativeInterval.ts.md b/packages/evolution/docs/modules/core/NonnegativeInterval.ts.md index 99b27d6f..2a976f0b 100644 --- a/packages/evolution/docs/modules/core/NonnegativeInterval.ts.md +++ b/packages/evolution/docs/modules/core/NonnegativeInterval.ts.md @@ -147,7 +147,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/OperationalCert.ts.md b/packages/evolution/docs/modules/core/OperationalCert.ts.md index 5574557e..dd1999ee 100644 --- a/packages/evolution/docs/modules/core/OperationalCert.ts.md +++ b/packages/evolution/docs/modules/core/OperationalCert.ts.md @@ -225,7 +225,7 @@ CBOR hex transformation schema for OperationalCert. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/PointerAddress.ts.md b/packages/evolution/docs/modules/core/PointerAddress.ts.md index 5701b453..fb68f877 100644 --- a/packages/evolution/docs/modules/core/PointerAddress.ts.md +++ b/packages/evolution/docs/modules/core/PointerAddress.ts.md @@ -212,7 +212,7 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.SchemaClass, diff --git a/packages/evolution/docs/modules/core/PoolMetadata.ts.md b/packages/evolution/docs/modules/core/PoolMetadata.ts.md index 4bc18271..583e067c 100644 --- a/packages/evolution/docs/modules/core/PoolMetadata.ts.md +++ b/packages/evolution/docs/modules/core/PoolMetadata.ts.md @@ -194,7 +194,7 @@ Transforms between hex string and PoolMetadata using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/PoolParams.ts.md b/packages/evolution/docs/modules/core/PoolParams.ts.md index d852aa16..2f157736 100644 --- a/packages/evolution/docs/modules/core/PoolParams.ts.md +++ b/packages/evolution/docs/modules/core/PoolParams.ts.md @@ -343,7 +343,7 @@ CBOR hex transformation schema for PoolParams. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/PrivateKey.ts.md b/packages/evolution/docs/modules/core/PrivateKey.ts.md index 2c28b0ad..7f80c37c 100644 --- a/packages/evolution/docs/modules/core/PrivateKey.ts.md +++ b/packages/evolution/docs/modules/core/PrivateKey.ts.md @@ -402,7 +402,7 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform, Schema.SchemaClass> > ``` diff --git a/packages/evolution/docs/modules/core/ProposalProcedure.ts.md b/packages/evolution/docs/modules/core/ProposalProcedure.ts.md index 9990d84e..52d994a2 100644 --- a/packages/evolution/docs/modules/core/ProposalProcedure.ts.md +++ b/packages/evolution/docs/modules/core/ProposalProcedure.ts.md @@ -299,7 +299,7 @@ CBOR hex transformation schema for individual ProposalProcedure. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/ProposalProcedures.ts.md b/packages/evolution/docs/modules/core/ProposalProcedures.ts.md index 6e63edb0..c721f4ed 100644 --- a/packages/evolution/docs/modules/core/ProposalProcedures.ts.md +++ b/packages/evolution/docs/modules/core/ProposalProcedures.ts.md @@ -292,7 +292,7 @@ CBOR hex transformation schema for ProposalProcedures. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/ProtocolParamUpdate.ts.md b/packages/evolution/docs/modules/core/ProtocolParamUpdate.ts.md index 69d464d0..6c9f1788 100644 --- a/packages/evolution/docs/modules/core/ProtocolParamUpdate.ts.md +++ b/packages/evolution/docs/modules/core/ProtocolParamUpdate.ts.md @@ -200,7 +200,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/ProtocolVersion.ts.md b/packages/evolution/docs/modules/core/ProtocolVersion.ts.md index 8beaf4ba..6b56b7b9 100644 --- a/packages/evolution/docs/modules/core/ProtocolVersion.ts.md +++ b/packages/evolution/docs/modules/core/ProtocolVersion.ts.md @@ -187,7 +187,7 @@ CBOR hex transformation schema for ProtocolVersion. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Redeemer.ts.md b/packages/evolution/docs/modules/core/Redeemer.ts.md index 6534f61e..d9f7adb0 100644 --- a/packages/evolution/docs/modules/core/Redeemer.ts.md +++ b/packages/evolution/docs/modules/core/Redeemer.ts.md @@ -394,7 +394,7 @@ Transforms between CBOR hex string and Redeemer using CDDL encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Relay.ts.md b/packages/evolution/docs/modules/core/Relay.ts.md index 839ec3f1..49e0ef6e 100644 --- a/packages/evolution/docs/modules/core/Relay.ts.md +++ b/packages/evolution/docs/modules/core/Relay.ts.md @@ -274,7 +274,7 @@ CBOR hex transformation schema for Relay. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.Union< [ Schema.transform< diff --git a/packages/evolution/docs/modules/core/RewardAccount.ts.md b/packages/evolution/docs/modules/core/RewardAccount.ts.md index 82393a19..8a0c486a 100644 --- a/packages/evolution/docs/modules/core/RewardAccount.ts.md +++ b/packages/evolution/docs/modules/core/RewardAccount.ts.md @@ -69,7 +69,7 @@ Convert a RewardAccount to bytes. **Signature** ```ts -export declare const toBytes: (data: RewardAccount) => any +export declare const toBytes: (data: RewardAccount) => Uint8Array ``` Added in v2.0.0 @@ -208,7 +208,7 @@ export declare const FromBech32: Schema.transformOrFail< ```ts export declare const FromBytes: Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > @@ -220,9 +220,9 @@ export declare const FromBytes: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< - Schema.filter, + Schema.SchemaClass, Schema.SchemaClass, never > diff --git a/packages/evolution/docs/modules/core/Script.ts.md b/packages/evolution/docs/modules/core/Script.ts.md index 6454d80d..d31b5ac5 100644 --- a/packages/evolution/docs/modules/core/Script.ts.md +++ b/packages/evolution/docs/modules/core/Script.ts.md @@ -170,7 +170,7 @@ export declare const FromCBORBytes: ( export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/ScriptRef.ts.md b/packages/evolution/docs/modules/core/ScriptRef.ts.md index d94ff6f6..02dfb02b 100644 --- a/packages/evolution/docs/modules/core/ScriptRef.ts.md +++ b/packages/evolution/docs/modules/core/ScriptRef.ts.md @@ -206,7 +206,7 @@ CBOR hex transformation schema for ScriptRef. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, @@ -254,7 +254,7 @@ Schema for transforming from hex to ScriptRef. ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform> > ``` diff --git a/packages/evolution/docs/modules/core/SingleHostAddr.ts.md b/packages/evolution/docs/modules/core/SingleHostAddr.ts.md index 350f2805..a485f5a5 100644 --- a/packages/evolution/docs/modules/core/SingleHostAddr.ts.md +++ b/packages/evolution/docs/modules/core/SingleHostAddr.ts.md @@ -298,7 +298,7 @@ CBOR hex transformation schema for SingleHostAddr. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/SingleHostName.ts.md b/packages/evolution/docs/modules/core/SingleHostName.ts.md index f912e8de..603f6df1 100644 --- a/packages/evolution/docs/modules/core/SingleHostName.ts.md +++ b/packages/evolution/docs/modules/core/SingleHostName.ts.md @@ -300,7 +300,7 @@ CBOR hex transformation schema for SingleHostName. export declare const FromHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Text.ts.md b/packages/evolution/docs/modules/core/Text.ts.md index 40d43c33..fde9ef9a 100644 --- a/packages/evolution/docs/modules/core/Text.ts.md +++ b/packages/evolution/docs/modules/core/Text.ts.md @@ -11,7 +11,7 @@ parent: Modules

Table of contents

- [composition](#composition) - - [textLengthBetween](#textlengthbetween) + - [between](#between) - [conversion](#conversion) - [fromBytes](#frombytes) - [fromHex](#fromhex) @@ -19,30 +19,21 @@ parent: Modules - [toHex](#tohex) - [schemas](#schemas) - [FromBytes](#frombytes-1) + - [FromHex](#fromhex-1) - [testing](#testing) - [arbitrary](#arbitrary) -- [types](#types) - - [TextTransformationConfig (interface)](#texttransformationconfig-interface) -- [unsafe](#unsafe) - - [fromBytesUnsafe](#frombytesunsafe) - - [fromHexUnsafe](#fromhexunsafe) - - [toBytesUnsafe](#tobytesunsafe) - - [toHexUnsafe](#tohexunsafe) -- [utilities](#utilities) - - [makeTextTransformation](#maketexttransformation) - [utils](#utils) - - [FromHex](#fromhex-1) - [Text](#text) - [validation](#validation) - - [textLengthEquals](#textlengthequals) - - [textLengthMax](#textlengthmax) - - [textLengthMin](#textlengthmin) + - [length](#length) + - [max](#max) + - [min](#min) --- # composition -## textLengthBetween +## between Creates a curried filter that validates text length is within a range. Preserves Context inference from the base schema. @@ -50,7 +41,7 @@ Preserves Context inference from the base schema. **Signature** ```ts -export declare const textLengthBetween: ( +export declare const between: ( min: number, max: number, moduleName: string @@ -68,7 +59,7 @@ Convert bytes to text **Signature** ```ts -export declare const fromBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => string +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -92,7 +83,7 @@ Convert text to bytes **Signature** ```ts -export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => Uint8Array +export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -113,134 +104,52 @@ Added in v2.0.0 ## FromBytes -Schema for converting between strings and hex representation of UTF-8 bytes. +Schema for converting between strings and bytes (UTF-8). ``` -text <-> hex -``` - -**Signature** - -```ts -export declare const FromBytes: Schema.transform< - Schema.Schema, - Schema.Schema -> -``` - -Added in v2.0.0 - -# testing - -## arbitrary - -FastCheck arbitrary for generating random text strings - -**Signature** - -```ts -export declare const arbitrary: FastCheck.Arbitrary +text <-> bytes ``` -Added in v2.0.0 - -# types - -## TextTransformationConfig (interface) - -Configuration for text transformations. - **Signature** ```ts -export interface TextTransformationConfig { - id: string - to: Schema.Schema - from: Schema.Schema -} +export declare const FromBytes: Schema.transform ``` Added in v2.0.0 -# unsafe - -## fromBytesUnsafe - -Convert bytes to text (unsafe, no validation). - -**Signature** - -```ts -export declare const fromBytesUnsafe: (bytes: Uint8Array) => string -``` - -Added in v2.0.0 - -## fromHexUnsafe - -Convert hex to text (unsafe, no validation). +## FromHex -**Signature** +Schema for converting between strings and hex representation of UTF-8 bytes. -```ts -export declare const fromHexUnsafe: (hex: string) => string ``` - -Added in v2.0.0 - -## toBytesUnsafe - -Convert text to bytes (unsafe, no validation). - -**Signature** - -```ts -export declare const toBytesUnsafe: (text: string) => Uint8Array +text <-> hex ``` -Added in v2.0.0 - -## toHexUnsafe - -Convert text to hex (unsafe, no validation). - **Signature** ```ts -export declare const toHexUnsafe: (text: string) => string +export declare const FromHex: Schema.transform, typeof Schema.String> ``` Added in v2.0.0 -# utilities +# testing -## makeTextTransformation +## arbitrary -Creates a text transformation schema. +FastCheck arbitrary for generating random text strings **Signature** ```ts -export declare const makeTextTransformation: ( - config: TextTransformationConfig -) => Schema.transform, Schema.Schema> +export declare const arbitrary: FastCheck.Arbitrary ``` Added in v2.0.0 # utils -## FromHex - -**Signature** - -```ts -export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> -> -``` - ## Text **Signature** @@ -251,14 +160,14 @@ export declare const Text: typeof Schema.String # validation -## textLengthEquals +## length Creates a schema that validates text length equals a specific value. **Signature** ```ts -export declare const textLengthEquals: ( +export declare const length: ( length: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter @@ -266,14 +175,14 @@ export declare const textLengthEquals: ( Added in v2.0.0 -## textLengthMax +## max Creates a schema that validates text length is at most max. **Signature** ```ts -export declare const textLengthMax: ( +export declare const max: ( max: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter @@ -281,14 +190,14 @@ export declare const textLengthMax: ( Added in v2.0.0 -## textLengthMin +## min Creates a schema that validates text length is at least min. **Signature** ```ts -export declare const textLengthMin: ( +export declare const min: ( min: number, identifier?: string ) => (self: Schema.Schema.Any) => Schema.filter diff --git a/packages/evolution/docs/modules/core/Text128.ts.md b/packages/evolution/docs/modules/core/Text128.ts.md index 5bb2581c..20f539a1 100644 --- a/packages/evolution/docs/modules/core/Text128.ts.md +++ b/packages/evolution/docs/modules/core/Text128.ts.md @@ -25,10 +25,9 @@ parent: Modules - [schemas](#schemas) - [Text128](#text128) - [utils](#utils) - - [FromVariableBytes](#fromvariablebytes) - - [FromVariableHex](#fromvariablehex) + - [FromBytes](#frombytes-1) + - [FromHex](#fromhex-1) - [TEXT128_MAX_LENGTH](#text128_max_length) - - [Text128 (type alias)](#text128-type-alias) --- @@ -70,7 +69,7 @@ Encode Text128 to bytes (unsafe) **Signature** ```ts -export declare const toBytes: (text: Text128) => Uint8Array +export declare const toBytes: (a: string, overrideOptions?: ParseOptions) => any ``` Added in v2.0.0 @@ -82,7 +81,7 @@ Encode Text128 to hex string (unsafe) **Signature** ```ts -export declare const toHex: (text: Text128) => string +export declare const toHex: (a: string, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -96,7 +95,7 @@ Parse Text128 from bytes (unsafe) **Signature** ```ts -export declare const fromBytes: (bytes: Uint8Array) => Text128 +export declare const fromBytes: (i: any, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -108,7 +107,7 @@ Parse Text128 from hex string (unsafe) **Signature** ```ts -export declare const fromHex: (hex: string) => Text128 +export declare const fromHex: (i: string, overrideOptions?: ParseOptions) => string ``` Added in v2.0.0 @@ -138,32 +137,35 @@ Follows the Conway-era CDDL specification. **Signature** ```ts -export declare const Text128: Schema.filter +export declare const Text128: Schema.refine ``` Added in v2.0.0 # utils -## FromVariableBytes +## FromBytes **Signature** ```ts -export declare const FromVariableBytes: Schema.transform< - Schema.Schema, - Schema.Schema +export declare const FromBytes: Schema.transform< + Schema.transform, + Schema.refine > ``` -## FromVariableHex +## FromHex **Signature** ```ts -export declare const FromVariableHex: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, Schema.Schema> +export declare const FromHex: Schema.transform< + Schema.Schema, + Schema.transform< + Schema.transform, + Schema.refine + > > ``` @@ -174,11 +176,3 @@ export declare const FromVariableHex: Schema.transform< ```ts export declare const TEXT128_MAX_LENGTH: 128 ``` - -## Text128 (type alias) - -**Signature** - -```ts -export type Text128 = typeof Text128.Type -``` diff --git a/packages/evolution/docs/modules/core/Transaction.ts.md b/packages/evolution/docs/modules/core/Transaction.ts.md index 92301336..5b3c5619 100644 --- a/packages/evolution/docs/modules/core/Transaction.ts.md +++ b/packages/evolution/docs/modules/core/Transaction.ts.md @@ -149,7 +149,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/TransactionBody.ts.md b/packages/evolution/docs/modules/core/TransactionBody.ts.md index d29aa247..73b3c8b3 100644 --- a/packages/evolution/docs/modules/core/TransactionBody.ts.md +++ b/packages/evolution/docs/modules/core/TransactionBody.ts.md @@ -241,7 +241,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/TransactionInput.ts.md b/packages/evolution/docs/modules/core/TransactionInput.ts.md index 3f85777d..271d4e80 100644 --- a/packages/evolution/docs/modules/core/TransactionInput.ts.md +++ b/packages/evolution/docs/modules/core/TransactionInput.ts.md @@ -194,7 +194,7 @@ CBOR hex transformation schema for TransactionInput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/TransactionMetadatum.ts.md b/packages/evolution/docs/modules/core/TransactionMetadatum.ts.md index b932ecb3..cd66ab1b 100644 --- a/packages/evolution/docs/modules/core/TransactionMetadatum.ts.md +++ b/packages/evolution/docs/modules/core/TransactionMetadatum.ts.md @@ -316,7 +316,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/TransactionOutput.ts.md b/packages/evolution/docs/modules/core/TransactionOutput.ts.md index 1b1c7424..cdf66d35 100644 --- a/packages/evolution/docs/modules/core/TransactionOutput.ts.md +++ b/packages/evolution/docs/modules/core/TransactionOutput.ts.md @@ -372,7 +372,7 @@ CBOR hex transformation schema for TransactionOutput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/TransactionWitnessSet.ts.md b/packages/evolution/docs/modules/core/TransactionWitnessSet.ts.md index 010136f4..2877bbfe 100644 --- a/packages/evolution/docs/modules/core/TransactionWitnessSet.ts.md +++ b/packages/evolution/docs/modules/core/TransactionWitnessSet.ts.md @@ -393,7 +393,7 @@ export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, Schema.declare, diff --git a/packages/evolution/docs/modules/core/TxOut.ts.md b/packages/evolution/docs/modules/core/TxOut.ts.md index ba9c1d39..76e473a6 100644 --- a/packages/evolution/docs/modules/core/TxOut.ts.md +++ b/packages/evolution/docs/modules/core/TxOut.ts.md @@ -364,7 +364,7 @@ CBOR hex transformation schema for TransactionOutput. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/UnitInterval.ts.md b/packages/evolution/docs/modules/core/UnitInterval.ts.md index f09ed3d3..91bf144f 100644 --- a/packages/evolution/docs/modules/core/UnitInterval.ts.md +++ b/packages/evolution/docs/modules/core/UnitInterval.ts.md @@ -188,7 +188,7 @@ Transforms between hex string and UnitInterval using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/Url.ts.md b/packages/evolution/docs/modules/core/Url.ts.md index 58adaf26..904ea521 100644 --- a/packages/evolution/docs/modules/core/Url.ts.md +++ b/packages/evolution/docs/modules/core/Url.ts.md @@ -56,7 +56,7 @@ Encode Url to bytes. **Signature** ```ts -export declare const toBytes: (url: Url) => Uint8Array +export declare const toBytes: (url: Url) => any ``` Added in v2.0.0 @@ -196,7 +196,10 @@ Added in v2.0.0 ```ts export declare const FromBytes: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.transform< + Schema.transform, + Schema.refine + >, typeof Url > ``` @@ -207,9 +210,12 @@ export declare const FromBytes: Schema.transform< ```ts export declare const FromHex: Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< - Schema.transform, Schema.Schema>, + Schema.transform< + Schema.transform, + Schema.refine + >, typeof Url > > diff --git a/packages/evolution/docs/modules/core/Value.ts.md b/packages/evolution/docs/modules/core/Value.ts.md index ee3d2bed..c8c9fbcb 100644 --- a/packages/evolution/docs/modules/core/Value.ts.md +++ b/packages/evolution/docs/modules/core/Value.ts.md @@ -268,7 +268,7 @@ Transforms between CBOR hex string and Value using CBOR encoding. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/VotingProcedures.ts.md b/packages/evolution/docs/modules/core/VotingProcedures.ts.md index 6c4a3ccd..dbe767ca 100644 --- a/packages/evolution/docs/modules/core/VotingProcedures.ts.md +++ b/packages/evolution/docs/modules/core/VotingProcedures.ts.md @@ -519,7 +519,7 @@ CBOR hex transformation schema for VotingProcedures. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/VrfCert.ts.md b/packages/evolution/docs/modules/core/VrfCert.ts.md index 3a59473c..479a4b16 100644 --- a/packages/evolution/docs/modules/core/VrfCert.ts.md +++ b/packages/evolution/docs/modules/core/VrfCert.ts.md @@ -222,7 +222,7 @@ CBOR hex transformation schema for VrfCert. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, @@ -338,7 +338,7 @@ vrf_output = bytes .size 32 ```ts export declare const VRFOutputHexSchema: Schema.transform< Schema.filter>, - Schema.transform, Schema.SchemaClass> + Schema.SchemaClass > ``` @@ -406,8 +406,8 @@ vrf_proof = bytes .size 80 ```ts export declare const VRFProofFromBytes: Schema.transform< - Schema.filter, - typeof VRFProof + Schema.SchemaClass, + Schema.SchemaClass > ``` @@ -422,8 +422,8 @@ vrf_proof = bytes .size 80 ```ts export declare const VRFProofHexSchema: Schema.transform< - Schema.transform, Schema.Schema>, - Schema.transform, typeof VRFProof> + Schema.filter>, + Schema.SchemaClass > ``` diff --git a/packages/evolution/docs/modules/core/Withdrawals.ts.md b/packages/evolution/docs/modules/core/Withdrawals.ts.md index 5fa7ab14..257b83c4 100644 --- a/packages/evolution/docs/modules/core/Withdrawals.ts.md +++ b/packages/evolution/docs/modules/core/Withdrawals.ts.md @@ -275,7 +275,7 @@ CBOR hex transformation schema for Withdrawals. export declare const FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transform< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/message-signing/CoseSign.ts.md b/packages/evolution/docs/modules/core/message-signing/CoseSign.ts.md index b784f3cc..85d9dbde 100644 --- a/packages/evolution/docs/modules/core/message-signing/CoseSign.ts.md +++ b/packages/evolution/docs/modules/core/message-signing/CoseSign.ts.md @@ -291,7 +291,7 @@ CBOR hex transformation schema for COSESign. export declare const COSESignFromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/message-signing/CoseSign1.ts.md b/packages/evolution/docs/modules/core/message-signing/CoseSign1.ts.md index f3b74597..61d75065 100644 --- a/packages/evolution/docs/modules/core/message-signing/CoseSign1.ts.md +++ b/packages/evolution/docs/modules/core/message-signing/CoseSign1.ts.md @@ -341,7 +341,7 @@ CBOR hex transformation schema for COSESign1. export declare const COSESign1FromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/core/message-signing/Header.ts.md b/packages/evolution/docs/modules/core/message-signing/Header.ts.md index a61f0039..f53cd880 100644 --- a/packages/evolution/docs/modules/core/message-signing/Header.ts.md +++ b/packages/evolution/docs/modules/core/message-signing/Header.ts.md @@ -452,7 +452,7 @@ CBOR hex transformation schema for HeaderMap. export declare const HeaderMapFromCBORHex: ( options?: CBOR.CodecOptions ) => Schema.transform< - Schema.transform, Schema.Schema>, + Schema.Schema, Schema.transformOrFail< Schema.transformOrFail< typeof Schema.Uint8ArrayFromSelf, diff --git a/packages/evolution/docs/modules/sdk/AddressDetails.ts.md b/packages/evolution/docs/modules/sdk/AddressDetails.ts.md index 59291f10..2e97a558 100644 --- a/packages/evolution/docs/modules/sdk/AddressDetails.ts.md +++ b/packages/evolution/docs/modules/sdk/AddressDetails.ts.md @@ -127,7 +127,7 @@ export declare const FromBech32: Schema.transformOrFail< ```ts export declare const FromHex: Schema.transformOrFail< - Schema.refine, + typeof Schema.String, Schema.SchemaClass, never > diff --git a/packages/evolution/src/core/Address.ts b/packages/evolution/src/core/Address.ts index 3f5e5d95..bee625f8 100644 --- a/packages/evolution/src/core/Address.ts +++ b/packages/evolution/src/core/Address.ts @@ -5,7 +5,6 @@ import { bech32 } from "@scure/base" import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Bytes29 from "./Bytes29.js" import * as Bytes57 from "./Bytes57.js" import * as Credential from "./Credential.js" @@ -68,7 +67,7 @@ export class Address extends Schema.Class
("AddressStructure")({ * @category Transformations */ export const FromBytes = Schema.transformOrFail( - Schema.Union(Bytes57.BytesSchema, Bytes29.BytesSchema), + Schema.Union(Schema.typeSchema(Bytes57.BytesFromHex), Schema.typeSchema(Bytes29.BytesFromHex)), Schema.typeSchema(Address), { strict: true, @@ -147,7 +146,7 @@ export const FromBytes = Schema.transformOrFail( * @since 1.0.0 * @category Transformations */ -export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({ +export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes).annotations({ identifier: "AddressStructure.FromHex" }) diff --git a/packages/evolution/src/core/AddressEras.ts b/packages/evolution/src/core/AddressEras.ts index f79380e2..b3d956dd 100644 --- a/packages/evolution/src/core/AddressEras.ts +++ b/packages/evolution/src/core/AddressEras.ts @@ -3,7 +3,6 @@ import { Effect as Eff, FastCheck, ParseResult, Schema } from "effect" import * as BaseAddress from "./BaseAddress.js" import * as ByronAddress from "./ByronAddress.js" -import * as Bytes from "./Bytes.js" import * as EnterpriseAddress from "./EnterpriseAddress.js" import * as PointerAddress from "./PointerAddress.js" import * as RewardAccount from "./RewardAccount.js" @@ -136,7 +135,7 @@ export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Schem * @since 2.0.0 * @category schema */ -export const FromHex = Schema.compose(Bytes.FromHex, FromBytes) +export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes) /** * Schema for encoding/decoding addresses as Bech32 strings. diff --git a/packages/evolution/src/core/Anchor.ts b/packages/evolution/src/core/Anchor.ts index 3ff8611d..971cbe03 100644 --- a/packages/evolution/src/core/Anchor.ts +++ b/packages/evolution/src/core/Anchor.ts @@ -38,7 +38,7 @@ export class Anchor extends Schema.TaggedClass()("Anchor", { return ( that instanceof Anchor && Equal.equals(this.anchorUrl, that.anchorUrl) && - Bytes.bytesEquals(this.anchorDataHash, that.anchorDataHash) + Bytes.equals(this.anchorDataHash, that.anchorDataHash) ) } @@ -92,7 +92,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Anchor ) diff --git a/packages/evolution/src/core/AssetName.ts b/packages/evolution/src/core/AssetName.ts index 39552ccb..edd6f7d4 100644 --- a/packages/evolution/src/core/AssetName.ts +++ b/packages/evolution/src/core/AssetName.ts @@ -22,7 +22,7 @@ export class AssetName extends Schema.TaggedClass()("AssetName", { toJSON() { return { _tag: "AssetName", - bytes: Bytes.toHexUnsafe(this.bytes) + bytes: Bytes.toHex(this.bytes) } } @@ -53,7 +53,7 @@ export class AssetName extends Schema.TaggedClass()("AssetName", { * @category equality */ [Equal.symbol](that: unknown): boolean { - return that instanceof AssetName && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof AssetName && Bytes.equals(this.bytes, that.bytes) } /** diff --git a/packages/evolution/src/core/Assets.ts b/packages/evolution/src/core/Assets.ts index df303cea..ccbde98b 100644 --- a/packages/evolution/src/core/Assets.ts +++ b/packages/evolution/src/core/Assets.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" import * as AssetName from "./AssetName.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as MultiAsset from "./MultiAsset.js" @@ -404,7 +403,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Assets ).annotations({ identifier: "Assets.FromCBORHex", diff --git a/packages/evolution/src/core/AuxiliaryData.ts b/packages/evolution/src/core/AuxiliaryData.ts index f08200ce..78b092a9 100644 --- a/packages/evolution/src/core/AuxiliaryData.ts +++ b/packages/evolution/src/core/AuxiliaryData.ts @@ -1,6 +1,5 @@ import { Either as E, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Metadata from "./Metadata.js" import * as NativeScripts from "./NativeScripts.js" @@ -490,7 +489,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI * @category schemas */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, FromCBORBytes(options)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)).annotations({ identifier: "AuxiliaryData.FromCBORHex", title: "AuxiliaryData from CBOR hex", description: "Decode AuxiliaryData from CBOR-encoded hex (tag 259)" diff --git a/packages/evolution/src/core/AuxiliaryDataHash.ts b/packages/evolution/src/core/AuxiliaryDataHash.ts index 7ff826ab..64caf245 100644 --- a/packages/evolution/src/core/AuxiliaryDataHash.ts +++ b/packages/evolution/src/core/AuxiliaryDataHash.ts @@ -35,7 +35,7 @@ export class AuxiliaryDataHash extends Schema.TaggedClass()(" } [Equal.symbol](that: unknown): boolean { - return that instanceof AuxiliaryDataHash && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof AuxiliaryDataHash && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/BaseAddress.ts b/packages/evolution/src/core/BaseAddress.ts index 4337f44a..3c05bd7c 100644 --- a/packages/evolution/src/core/BaseAddress.ts +++ b/packages/evolution/src/core/BaseAddress.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Bytes57 from "./Bytes57.js" import * as Credential from "./Credential.js" import * as KeyHash from "./KeyHash.js" @@ -45,7 +44,7 @@ export class BaseAddress extends Schema.TaggedClass("BaseAddress")( } } -export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.typeSchema(BaseAddress), { +export const FromBytes = Schema.transformOrFail(Schema.typeSchema(Bytes57.BytesFromHex), Schema.typeSchema(BaseAddress), { strict: true, encode: (_, __, ___, toA) => Eff.gen(function* () { @@ -94,7 +93,7 @@ export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.type identifier: "BaseAddress.FromBytes" }) -export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({ +export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, FromBytes).annotations({ identifier: "BaseAddress.FromHex" }) diff --git a/packages/evolution/src/core/Bech32.ts b/packages/evolution/src/core/Bech32.ts index e145bfd9..f46a9da7 100644 --- a/packages/evolution/src/core/Bech32.ts +++ b/packages/evolution/src/core/Bech32.ts @@ -1,7 +1,6 @@ import { bech32 } from "@scure/base" import { Effect, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" export const Bech32Schema = Schema.String export type Bech32 = typeof Bech32Schema.Type @@ -21,6 +20,6 @@ export const FromBytes = (prefix: string = "addr") => }) export const FromHex = (prefix: string = "addr") => - Schema.compose(Bytes.FromHex, FromBytes(prefix)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, FromBytes(prefix)).annotations({ identifier: "Bech32.FromHex" }) diff --git a/packages/evolution/src/core/Bip32PrivateKey.ts b/packages/evolution/src/core/Bip32PrivateKey.ts index 1799d416..a5f02c69 100644 --- a/packages/evolution/src/core/Bip32PrivateKey.ts +++ b/packages/evolution/src/core/Bip32PrivateKey.ts @@ -31,7 +31,7 @@ export class Bip32PrivateKeyError extends Data.TaggedError("Bip32PrivateKeyError * @category schemas */ export class Bip32PrivateKey extends Schema.TaggedClass()("Bip32PrivateKey", { - bytes: Bytes96.BytesSchema + bytes: Bytes96.BytesFromHex }) { toJSON() { return { _tag: "Bip32PrivateKey" as const, bytes: Bytes.toHex(this.bytes) } @@ -46,7 +46,7 @@ export class Bip32PrivateKey extends Schema.TaggedClass()("Bip3 } [Equal.symbol](that: unknown): boolean { - return that instanceof Bip32PrivateKey && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof Bip32PrivateKey && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { @@ -60,7 +60,7 @@ export class Bip32PrivateKey extends Schema.TaggedClass()("Bip3 * @since 2.0.0 * @category schemas */ -export const FromBytes = Schema.transform(Bytes96.BytesSchema, Bip32PrivateKey, { +export const FromBytes = Schema.transform(Schema.typeSchema(Bytes96.BytesFromHex), Schema.typeSchema(Bip32PrivateKey), { strict: true, decode: (bytes) => new Bip32PrivateKey({ bytes }, { disableValidation: true }), encode: (bip32PrivateKey) => bip32PrivateKey.bytes @@ -75,7 +75,7 @@ export const FromBytes = Schema.transform(Bytes96.BytesSchema, Bip32PrivateKey, * @category schemas */ export const FromHex = Schema.compose( - Bytes96.FromHex, // string -> Bytes96 + Bytes96.BytesFromHex, // string -> Bytes96 FromBytes // Bytes96 -> Bip32PrivateKey ).annotations({ identifier: "Bip32PrivateKey.FromHex" @@ -443,7 +443,9 @@ export namespace Either { export const from_128_xprv = (bytes: Uint8Array) => Effect.gen(function* () { if (bytes.length !== 128) { - return yield* Effect.fail(new Bip32PrivateKeyError({ message: `Expected exactly 128 bytes, got ${bytes.length}` })) + return yield* Effect.fail( + new Bip32PrivateKeyError({ message: `Expected exactly 128 bytes, got ${bytes.length}` }) + ) } const scalar = bytes.slice(0, 32) const iv = bytes.slice(32, 64) diff --git a/packages/evolution/src/core/Bip32PublicKey.ts b/packages/evolution/src/core/Bip32PublicKey.ts index ed5793b6..b765e453 100644 --- a/packages/evolution/src/core/Bip32PublicKey.ts +++ b/packages/evolution/src/core/Bip32PublicKey.ts @@ -44,7 +44,7 @@ export class Bip32PublicKey extends Schema.TaggedClass()("Bip32P } [Equal.symbol](that: unknown): boolean { - return that instanceof Bip32PublicKey && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof Bip32PublicKey && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/BlockBodyHash.ts b/packages/evolution/src/core/BlockBodyHash.ts index 7ecb3474..9d93811f 100644 --- a/packages/evolution/src/core/BlockBodyHash.ts +++ b/packages/evolution/src/core/BlockBodyHash.ts @@ -30,7 +30,7 @@ export class BlockBodyHash extends Schema.TaggedClass()("BlockBod } [Equal.symbol](that: unknown): boolean { - return that instanceof BlockBodyHash && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof BlockBodyHash && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/BlockHeaderHash.ts b/packages/evolution/src/core/BlockHeaderHash.ts index 6226bc03..a21fbe63 100644 --- a/packages/evolution/src/core/BlockHeaderHash.ts +++ b/packages/evolution/src/core/BlockHeaderHash.ts @@ -30,7 +30,7 @@ export class BlockHeaderHash extends Schema.TaggedClass()("Bloc } [Equal.symbol](that: unknown): boolean { - return that instanceof BlockHeaderHash && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof BlockHeaderHash && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/BootstrapWitness.ts b/packages/evolution/src/core/BootstrapWitness.ts index fd98fbb4..ef7b90ea 100644 --- a/packages/evolution/src/core/BootstrapWitness.ts +++ b/packages/evolution/src/core/BootstrapWitness.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Bytes32 from "./Bytes32.js" import * as CBOR from "./CBOR.js" import * as Ed25519Signature from "./Ed25519Signature.js" @@ -154,7 +153,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → BootstrapWitness ).annotations({ identifier: "BootstrapWitness.FromCBORHex", diff --git a/packages/evolution/src/core/ByronAddress.ts b/packages/evolution/src/core/ByronAddress.ts index 403603d6..5bc61475 100644 --- a/packages/evolution/src/core/ByronAddress.ts +++ b/packages/evolution/src/core/ByronAddress.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as NetworkId from "./NetworkId.js" /** @@ -11,7 +10,7 @@ import * as NetworkId from "./NetworkId.js" */ export class ByronAddress extends Schema.TaggedClass("ByronAddress")("ByronAddress", { networkId: NetworkId.NetworkId, - bytes: Bytes.HexSchema + bytes: Schema.Uint8ArrayFromSelf }) { toJSON() { return { @@ -48,13 +47,12 @@ export class ByronAddress extends Schema.TaggedClass("ByronAddress */ export const BytesSchema = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, ByronAddress, { strict: true, - encode: (_, __, ___, toA) => ParseResult.decode(Bytes.FromHex)(toA.bytes), + encode: (_, __, ___, toA) => ParseResult.succeed(toA.bytes), decode: (_, __, ast, fromA) => Eff.gen(function* () { - const hexString = yield* ParseResult.encode(Bytes.FromHex)(fromA) return new ByronAddress({ networkId: NetworkId.NetworkId.make(0), - bytes: hexString + bytes: fromA }) }) }) @@ -65,4 +63,4 @@ export const BytesSchema = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Byr * @since 2.0.0 * @category schemas */ -export const FromHex = Schema.compose(Bytes.FromHex, BytesSchema) +export const FromHex = Schema.compose(Schema.Uint8ArrayFromHex, BytesSchema) diff --git a/packages/evolution/src/core/Bytes.ts b/packages/evolution/src/core/Bytes.ts index 3b464ae2..0b2181ca 100644 --- a/packages/evolution/src/core/Bytes.ts +++ b/packages/evolution/src/core/Bytes.ts @@ -1,89 +1,4 @@ -import { Data, Either as E, Schema } from "effect" - -export class BytesError extends Data.TaggedError("BytesError")<{ - message?: string - cause?: unknown -}> {} - -/** - * Compare two Uint8Array instances for equality. - * Returns true if both arrays have the same length and same byte values. - * - * @since 2.0.0 - * @category equality - */ -export const bytesEquals = (a: Uint8Array | undefined, b: Uint8Array | undefined): boolean => { - if (a === b) return true - if (a === undefined || b === undefined) return false - if (a.length !== b.length) return false - for (let i = 0; i < a.length; i++) { - if (a[i] !== b[i]) return false - } - return true -} - -export const isHex = (input: string): boolean => { - const len = input.length - if (len === 0) return false - if (len % 2 !== 0) return false - for (let i = 0; i < len; i++) { - const cc = input.charCodeAt(i) - if (!((cc >= 48 && cc <= 57) || (cc >= 65 && cc <= 70) || (cc >= 97 && cc <= 102))) { - return false - } - } - return true -} - -/** - * Lenient version of isHex that allows empty strings. - * Useful for PlutusData where empty byte arrays are valid. - * - * @since 2.0.0 - * @category predicates - */ -export const isHexLenient = (input: string): boolean => { - const len = input.length - - // Empty strings are valid (for empty byte arrays) - if (len === 0) return true - - // Must have even length - if (len % 2 !== 0) return false - - // Check each character is valid hex - for (let i = 0; i < len; i++) { - const cc = input.charCodeAt(i) - if ( - !( - (cc >= 48 && cc <= 57) || // '0'–'9' - (cc >= 65 && cc <= 70) || // 'A'–'F' - (cc >= 97 && cc <= 102) // 'a'–'f' - ) - ) { - return false - } - } - return true -} - -const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0")) - -// We use optimized technique to convert hex string to byte array -const asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 } as const - -/** - * Converts an ASCII character code to its base16 (hexadecimal) value. - * For use with pre-validated hex strings. - */ -const asciiToBase16 = (char: number): number => { - if (char >= asciis._0 && char <= asciis._9) return char - asciis._0 - if (char >= asciis._A && char <= asciis._F) return char - (asciis._A - 10) - if (char >= asciis._a && char <= asciis._f) return char - (asciis._a - 10) - // Since Hex is already validated, this should never happen - // but we return 0 to satisfy TypeScript - return 0 -} +import { Schema } from "effect" export const equals = (a: Uint8Array, b: Uint8Array): boolean => { if (a.length !== b.length) return false @@ -93,200 +8,6 @@ export const equals = (a: Uint8Array, b: Uint8Array): boolean => { return true } -/** - * Pure conversion function from validated hex string to Uint8Array. - * Assumes input is already validated hex. - */ -export const fromHexUnsafe = (hex: string): Uint8Array => { - const array = new Uint8Array(hex.length / 2) - for (let ai = 0, hi = 0; ai < array.length; ai++, hi += 2) { - const n1 = asciiToBase16(hex.charCodeAt(hi)) - const n2 = asciiToBase16(hex.charCodeAt(hi + 1)) - array[ai] = n1 * 16 + n2 - } - return array -} - -/** - * Pure conversion function from validated hex string to Uint8Array (lenient version). - * Assumes input is already validated hex or empty string. - */ -export const fromHexLenientUnsafe = (hex: string): Uint8Array => { - if (hex.length === 0) return new Uint8Array(0) - return fromHexUnsafe(hex) -} - -/** - * Pure conversion function from Uint8Array to hex string. - */ -export const toHexUnsafe = (bytes: Uint8Array): string => { - let hex = "" - for (let i = 0; i < bytes.length; i++) { - hex += hexes[bytes[i]] - } - return hex -} - -/** - * Pure conversion function from Uint8Array to hex string (lenient version). - */ -export const toHexLenientUnsafe = (bytes: Uint8Array): string => { - if (bytes.length === 0) return "" - return toHexUnsafe(bytes) -} - -// Updated factory: accepts a string-side schema (e.g. HexSchema / HexLenientSchema) -interface Uint8ArrayTransformationConfig { - id: string - stringSchema: Schema.Schema - uint8ArraySchema: Schema.Schema - decode: (s: I) => Uint8Array - encode: (u: Uint8Array) => I -} - -export const makeBytesTransformation = (config: Uint8ArrayTransformationConfig) => { - const { decode, encode, id, stringSchema, uint8ArraySchema } = config - return Schema.transform(stringSchema, uint8ArraySchema, { - strict: true, - decode: (i) => decode(i), - encode: (a) => encode(a) - }).annotations({ identifier: id }) -} - -export const HexSchema = Schema.String.pipe( - Schema.filter((a) => isHex(a), { - message: (issue) => `${issue.actual} must be a valid hex string (0-9, A-F, a-f) and cannot be empty` - }), - Schema.annotations({ - identifier: "Bytes.Hex" - }) -) - -export const FromHex = makeBytesTransformation({ - id: "Bytes.FromHex", - stringSchema: HexSchema, - uint8ArraySchema: Schema.Uint8ArrayFromSelf, - decode: fromHexUnsafe, - encode: toHexUnsafe -}) - -/** - * Lenient hex schema that allows empty strings. - * Useful for PlutusData where empty byte arrays are valid. - * - * @since 2.0.0 - * @category schemas - */ -export const HexLenientSchema = Schema.String.pipe( - Schema.filter((a) => isHexLenient(a), { - message: (issue) => `${issue.actual} must be a valid hex string (0-9, A-F, a-f) or empty string` - }), - Schema.annotations({ - identifier: "Bytes.HexLenient" - }) -) - -export const BytesFromHexLenient = makeBytesTransformation({ - id: "Bytes.FromHexLenient", - stringSchema: HexLenientSchema, - uint8ArraySchema: Schema.Uint8ArrayFromSelf, - decode: fromHexLenientUnsafe, - encode: toHexLenientUnsafe -}) - -// ============================================================================= -// Composition Helpers (Curried) -// ============================================================================= - -/** - * Creates a curried filter that validates exact byte length (for hex strings). - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const hexLengthEquals = - (byteLength: number) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter((hex: string) => hex.length === byteLength * 2, { - message: (issue) => - `${issue.actual} Must be exactly ${byteLength * 2} hex characters (${byteLength} bytes), got ${(issue.actual as string).length}` - }) - ) - -/** - * Creates a curried filter that validates byte length is within a range (for hex strings). - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const hexLengthBetween = - (minBytes: number, maxBytes: number) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter( - (hex: string) => { - const hexLength = hex.length - return hexLength >= minBytes * 2 && hexLength <= maxBytes * 2 - }, - { - message: () => - `Must be between ${minBytes} and ${maxBytes} bytes (${minBytes * 2}-${maxBytes * 2} hex characters)` - } - ) - ) - -/** - * Creates a curried filter that validates minimum byte length (for hex strings). - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const hexLengthMin = - (minBytes: number) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter((hex: string) => hex.length >= minBytes * 2, { - message: () => `Must be at least ${minBytes} bytes (${minBytes * 2} hex characters)` - }) - ) - -/** - * Creates a curried filter that validates maximum byte length (for hex strings). - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const hexLengthMax = - (maxBytes: number) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter((hex: string) => hex.length <= maxBytes * 2, { - message: () => `Must be at most ${maxBytes} bytes (${maxBytes * 2} hex characters)` - }) - ) - -/** - * Creates a curried filter that validates hex starts with specific prefix. - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const hexStartsWithPrefix = - (prefix: string) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter((hex: string) => hex.toLowerCase().startsWith(prefix.toLowerCase()), { - message: () => `Must start with prefix "${prefix}"` - }) - ) - -// Byte array composition helpers /** * Creates a curried filter that validates exact byte length (for Uint8Array). * Preserves Context inference from the base schema. @@ -353,47 +74,13 @@ export const bytesLengthMax = }) ) -/** - * Creates a curried filter that validates bytes start with specific prefix. - * Preserves Context inference from the base schema. - * - * @since 2.0.0 - * @category composition - */ -export const bytesStartsWithPrefix = - (prefix: Uint8Array) => - >(baseSchema: S) => - baseSchema.pipe( - Schema.filter( - (bytes: Uint8Array) => { - if (bytes.length < prefix.length) return false - for (let i = 0; i < prefix.length; i++) { - if (bytes[i] !== prefix[i]) return false - } - return true - }, - { - message: () => `Must start with prefix [${Array.from(prefix).join(", ")}]` - } - ) - ) - -// ============================================================================= -// Public API -// ============================================================================= - /** * Convert hex string to Uint8Array. Throws on invalid input. * * @since 2.0.0 * @category conversions */ -export const fromHex = (hex: string): Uint8Array => - Either.fromHex(hex).pipe( - E.getOrThrowWith((error) => { - throw error - }) - ) +export const fromHex = Schema.decodeSync(Schema.Uint8ArrayFromHex) /** * Convert Uint8Array to hex string. Never fails. @@ -401,71 +88,4 @@ export const fromHex = (hex: string): Uint8Array => * @since 2.0.0 * @category conversions */ -export const toHex = (bytes: Uint8Array): string => toHexUnsafe(bytes) - -/** - * Convert hex string to Uint8Array (allows empty strings). Throws on invalid input. - * - * @since 2.0.0 - * @category conversions - */ -export const fromHexLenient = (hex: string): Uint8Array => - Either.fromHexLenient(hex).pipe( - E.getOrThrowWith((error) => { - throw error - }) - ) - -/** - * Convert Uint8Array to hex string (returns empty string for empty arrays). Never fails. - * - * @since 2.0.0 - * @category conversions - */ -export const toHexLenient = (bytes: Uint8Array): string => toHexLenientUnsafe(bytes) - -/** - * Safe API that returns Either for error handling instead of throwing. - * - * @since 2.0.0 - * @category namespaces - */ -export namespace Either { - /** - * Convert hex string to Uint8Array. Returns Either with parse error on invalid input. - * - * @since 2.0.0 - * @category conversions - */ - export const fromHex = (hex: string) => - Schema.decodeEither(FromHex)(hex).pipe( - E.mapLeft((error) => new BytesError({ message: error.message, cause: error })) - ) - - /** - * Convert Uint8Array to hex string. Always succeeds, wrapped in Either.right. - * - * @since 2.0.0 - * @category conversions - */ - export const toHex = (bytes: Uint8Array) => E.right(toHexUnsafe(bytes)) - - /** - * Convert hex string to Uint8Array (allows empty strings). Returns Either with parse error on invalid input. - * - * @since 2.0.0 - * @category conversions - */ - export const fromHexLenient = (hex: string) => - Schema.decodeEither(BytesFromHexLenient)(hex).pipe( - E.mapLeft((error) => new BytesError({ message: error.message, cause: error })) - ) - - /** - * Convert Uint8Array to hex string (returns empty string for empty arrays). Always succeeds, wrapped in Either.right. - * - * @since 2.0.0 - * @category conversions - */ - export const toHexLenient = (bytes: Uint8Array) => E.right(toHexLenientUnsafe(bytes)) -} +export const toHex = Schema.encodeSync(Schema.Uint8ArrayFromHex) diff --git a/packages/evolution/src/core/Bytes128.ts b/packages/evolution/src/core/Bytes128.ts index a6ab7c64..13149418 100644 --- a/packages/evolution/src/core/Bytes128.ts +++ b/packages/evolution/src/core/Bytes128.ts @@ -15,39 +15,9 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 128 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - -/** - * Schema transformation for fixed-length bytes - * - * @since 2.0.0 - * @category schemas - */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) - -export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) - -/** - * Schema transformation for variable-length bytes (0..BYTES_LENGTH). - * - * @since 2.0.0 - * @category schemas - */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: VariableBytes, - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals @@ -61,7 +31,7 @@ export const equals = Bytes.equals * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -69,7 +39,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/Bytes29.ts b/packages/evolution/src/core/Bytes29.ts index 3ac2d539..38632a3d 100644 --- a/packages/evolution/src/core/Bytes29.ts +++ b/packages/evolution/src/core/Bytes29.ts @@ -15,25 +15,13 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 29 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) - -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - /** * Schema transformation for fixed-length bytes * * @since 2.0.0 * @category schemas */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) - -export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) /** * Schema transformation for variable-length bytes (0..BYTES_LENGTH). @@ -41,27 +29,17 @@ export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBet * @since 2.0.0 * @category schemas */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: VariableBytes, - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals -// ============================================================================= -// Public (throwing) API -// ============================================================================= - /** * Decode fixed-length hex into bytes. * * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -69,7 +47,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/Bytes448.ts b/packages/evolution/src/core/Bytes448.ts index 987ceea5..c473fee5 100644 --- a/packages/evolution/src/core/Bytes448.ts +++ b/packages/evolution/src/core/Bytes448.ts @@ -15,25 +15,13 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 448 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) - -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - /** * Schema transformation for fixed-length bytes * * @since 2.0.0 * @category schemas */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) - -export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) /** * Schema transformation for variable-length bytes (0..BYTES_LENGTH). @@ -41,13 +29,7 @@ export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBet * @since 2.0.0 * @category schemas */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: VariableBytes, - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals @@ -61,7 +43,7 @@ export const equals = Bytes.equals * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -69,7 +51,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/Bytes57.ts b/packages/evolution/src/core/Bytes57.ts index e56c6722..c3465f94 100644 --- a/packages/evolution/src/core/Bytes57.ts +++ b/packages/evolution/src/core/Bytes57.ts @@ -15,25 +15,13 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 57 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) - -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - /** * Schema transformation for fixed-length bytes * * @since 2.0.0 * @category schemas */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) - -export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) /** * Schema transformation for variable-length bytes (0..BYTES_LENGTH). @@ -41,13 +29,7 @@ export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBet * @since 2.0.0 * @category schemas */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: VariableBytes, - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals @@ -61,7 +43,7 @@ export const equals = Bytes.equals * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -69,7 +51,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/Bytes64.ts b/packages/evolution/src/core/Bytes64.ts index d4314572..b0567ee8 100644 --- a/packages/evolution/src/core/Bytes64.ts +++ b/packages/evolution/src/core/Bytes64.ts @@ -12,7 +12,7 @@ export const BYTES_LENGTH = 64 export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) -export const VariableBytesFromHex = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) // ============================================================================= // Public (throwing) API diff --git a/packages/evolution/src/core/Bytes80.ts b/packages/evolution/src/core/Bytes80.ts index 795f0f4b..1c5f9350 100644 --- a/packages/evolution/src/core/Bytes80.ts +++ b/packages/evolution/src/core/Bytes80.ts @@ -15,23 +15,13 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 80 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) - -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - /** * Schema transformation for fixed-length bytes * * @since 2.0.0 * @category schemas */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) /** * Schema transformation for variable-length bytes (0..BYTES_LENGTH). @@ -39,13 +29,7 @@ export const FromHex = Bytes.makeBytesTransformation({ * @since 2.0.0 * @category schemas */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)), - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals @@ -59,7 +43,7 @@ export const equals = Bytes.equals * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -67,7 +51,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/Bytes96.ts b/packages/evolution/src/core/Bytes96.ts index e817ab47..6d4e6698 100644 --- a/packages/evolution/src/core/Bytes96.ts +++ b/packages/evolution/src/core/Bytes96.ts @@ -15,25 +15,13 @@ import * as Bytes from "./Bytes.js" */ export const BYTES_LENGTH = 96 -export const BytesSchema = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) - -export const HexSchema = Bytes.HexSchema.pipe(Bytes.hexLengthEquals(BYTES_LENGTH)) - /** * Schema transformation for fixed-length bytes * * @since 2.0.0 * @category schemas */ -export const FromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.Bytes${BYTES_LENGTH}FromHex`, - stringSchema: HexSchema, - uint8ArraySchema: BytesSchema, - decode: Bytes.fromHexUnsafe, - encode: Bytes.toHexUnsafe -}) - -export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) +export const BytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthEquals(BYTES_LENGTH)) /** * Schema transformation for variable-length bytes (0..BYTES_LENGTH). @@ -41,13 +29,7 @@ export const VariableBytes = Schema.Uint8ArrayFromSelf.pipe(Bytes.bytesLengthBet * @since 2.0.0 * @category schemas */ -export const VariableBytesFromHex = Bytes.makeBytesTransformation({ - id: `Bytes${BYTES_LENGTH}.VariableBytes${BYTES_LENGTH}FromHex`, - stringSchema: Bytes.HexLenientSchema.pipe(Bytes.hexLengthBetween(0, BYTES_LENGTH)), - uint8ArraySchema: VariableBytes, - decode: Bytes.fromHexLenient, - encode: Bytes.toHexLenientUnsafe -}) +export const VariableBytesFromHex = Schema.Uint8ArrayFromHex.pipe(Bytes.bytesLengthBetween(0, BYTES_LENGTH)) export const equals = Bytes.equals @@ -61,7 +43,7 @@ export const equals = Bytes.equals * @since 2.0.0 * @category decoding */ -export const fromHex = Schema.decodeSync(FromHex) +export const fromHex = Schema.decodeSync(BytesFromHex) /** * Encode fixed-length bytes to hex. @@ -69,7 +51,7 @@ export const fromHex = Schema.decodeSync(FromHex) * @since 2.0.0 * @category encoding */ -export const toHex = Schema.encodeSync(FromHex) +export const toHex = Schema.encodeSync(BytesFromHex) /** * Decode variable-length hex (0..BYTES_LENGTH) into bytes. diff --git a/packages/evolution/src/core/CBOR.ts b/packages/evolution/src/core/CBOR.ts index c682f21c..76cf832f 100644 --- a/packages/evolution/src/core/CBOR.ts +++ b/packages/evolution/src/core/CBOR.ts @@ -605,7 +605,7 @@ export const FromBytes = (options: CodecOptions) => }) }) -export const FromHex = (options: CodecOptions) => Schema.compose(Bytes.FromHex, FromBytes(options)) +export const FromHex = (options: CodecOptions) => Schema.compose(Schema.Uint8ArrayFromHex, FromBytes(options)) // ============================================================================ // Either-based API (Step 1) @@ -627,8 +627,7 @@ export namespace Either { export const fromCBORHex = (hex: string, options: CodecOptions = CML_DEFAULT_OPTIONS): E.Either => E.try({ try: () => { - if (!Bytes.isHex(hex)) throw new CBORError({ message: "Invalid hex input" }) - const bytes = Bytes.fromHexUnsafe(hex) + const bytes = Bytes.fromHex(hex) return internalDecodeSync(bytes, options) }, catch: (e) => (e instanceof CBORError ? e : new CBORError({ message: String(e), cause: e })) @@ -647,7 +646,7 @@ export namespace Either { /** Encode a CBOR value to hex string, returning Either */ export const toCBORHex = (value: CBOR, options: CodecOptions = CML_DEFAULT_OPTIONS): E.Either => E.try({ - try: () => Bytes.toHexUnsafe(internalEncodeSync(value, options)), + try: () => Bytes.toHex(internalEncodeSync(value, options)), catch: (e) => (e instanceof CBORError ? e : new CBORError({ message: String(e), cause: e })) }) } @@ -672,8 +671,7 @@ export const fromCBORBytes = (bytes: Uint8Array, options: CodecOptions = CML_DEF * @category parsing */ export const fromCBORHex = (hex: string, options: CodecOptions = CML_DEFAULT_OPTIONS): CBOR => { - if (!Bytes.isHex(hex)) throw new CBORError({ message: "Invalid hex input" }) - const bytes = Bytes.fromHexUnsafe(hex) + const bytes = Bytes.fromHex(hex) return internalDecodeSync(bytes, options) } @@ -697,7 +695,7 @@ export const toCBORBytes = (value: CBOR, options: CodecOptions = CML_DEFAULT_OPT * @category encoding */ export const toCBORHex = (value: CBOR, options: CodecOptions = CML_DEFAULT_OPTIONS): string => - Bytes.toHexUnsafe(internalEncodeSync(value, options)) + Bytes.toHex(internalEncodeSync(value, options)) // ============================================================================ // Sync core (Step 2): fast, exception-based encode/decode with no Effect diff --git a/packages/evolution/src/core/Certificate.ts b/packages/evolution/src/core/Certificate.ts index e51d931f..62001a3d 100644 --- a/packages/evolution/src/core/Certificate.ts +++ b/packages/evolution/src/core/Certificate.ts @@ -1,7 +1,6 @@ import { Either as E, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" import * as Anchor from "./Anchor.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as Credential from "./Credential.js" @@ -1103,7 +1102,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Certificate ) diff --git a/packages/evolution/src/core/Combinator.ts b/packages/evolution/src/core/Combinator.ts index 918e878f..3432ff4d 100644 --- a/packages/evolution/src/core/Combinator.ts +++ b/packages/evolution/src/core/Combinator.ts @@ -1,6 +1,5 @@ import { pipe, Schema } from "effect" -import * as Bytes from "./Bytes.js" /** * Regular expression that matches valid hexadecimal strings. @@ -17,7 +16,7 @@ export const HexStringFilter = (self: Schema.Sche identifier: "HexString" }) -export const HexStringSchema = Schema.String.pipe(Schema.filter((a) => Bytes.isHex(a))).annotations({ +export const HexStringSchema = Schema.String.pipe(Schema.filter((a) => HEX_REGEX.test(a))).annotations({ message: () => `must be a hex string`, identifier: "HexString" }) diff --git a/packages/evolution/src/core/CostModel.ts b/packages/evolution/src/core/CostModel.ts index f93cc632..f85583ce 100644 --- a/packages/evolution/src/core/CostModel.ts +++ b/packages/evolution/src/core/CostModel.ts @@ -1,6 +1,5 @@ import { Equal, FastCheck, Hash, Inspectable, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" // Helper for array equality - Equal.equals compares arrays by instance, not content @@ -219,7 +218,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → CostModels ).annotations({ identifier: "CostModels.FromCBORHex", diff --git a/packages/evolution/src/core/Credential.ts b/packages/evolution/src/core/Credential.ts index db07cdb4..ca1aa00d 100644 --- a/packages/evolution/src/core/Credential.ts +++ b/packages/evolution/src/core/Credential.ts @@ -1,6 +1,5 @@ import { Effect as Eff, FastCheck, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as KeyHash from "./KeyHash.js" import * as ScriptHash from "./ScriptHash.js" @@ -84,7 +83,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Credential ) diff --git a/packages/evolution/src/core/DRep.ts b/packages/evolution/src/core/DRep.ts index 91fe24fe..f00c54e9 100644 --- a/packages/evolution/src/core/DRep.ts +++ b/packages/evolution/src/core/DRep.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as KeyHash from "./KeyHash.js" import * as ScriptHash from "./ScriptHash.js" @@ -218,7 +217,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → DRep ) diff --git a/packages/evolution/src/core/Data.ts b/packages/evolution/src/core/Data.ts index ef67119a..5a198586 100644 --- a/packages/evolution/src/core/Data.ts +++ b/packages/evolution/src/core/Data.ts @@ -1,6 +1,5 @@ import { Data as EffectData, Effect, Equal, FastCheck, Hash, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Numeric from "./Numeric.js" @@ -854,7 +853,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DATA_DEFAULT */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DATA_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Data ).annotations({ identifier: "Data.FromCBORHex", diff --git a/packages/evolution/src/core/DataJson.ts b/packages/evolution/src/core/DataJson.ts index 470ba39a..bff9cc9f 100644 --- a/packages/evolution/src/core/DataJson.ts +++ b/packages/evolution/src/core/DataJson.ts @@ -1,7 +1,6 @@ import { pipe, Schema } from "effect" import type { ParseIssue } from "effect/ParseResult" -import * as Bytes from "./Bytes.js" /** * Plutus data types and schemas for serialization/deserialization between @@ -39,10 +38,12 @@ export type Map = { const renderParseIssue = (issue: ParseIssue): string | undefined => typeof issue.actual === "object" ? "[complex value]" : String(issue.actual) +const HEX_REGEX = /^(?:[0-9a-f]{2})*$/ + const HexString = (self: Schema.Schema) => pipe( self, - Schema.filter((value) => Bytes.isHex(value), { + Schema.filter((value) => HEX_REGEX.test(value), { message: (issue) => `Expected a hexadecimal string but received: ${issue.actual}.` }) ) diff --git a/packages/evolution/src/core/DatumOption.ts b/packages/evolution/src/core/DatumOption.ts index 28d01f87..b15d1ef1 100644 --- a/packages/evolution/src/core/DatumOption.ts +++ b/packages/evolution/src/core/DatumOption.ts @@ -44,7 +44,7 @@ export class DatumHash extends Schema.TaggedClass()("DatumHash", { * @category equality */ [Equal.symbol](that: unknown): boolean { - return that instanceof DatumHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof DatumHash && Bytes.equals(this.hash, that.hash) } /** @@ -257,7 +257,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → DatumOption ).annotations({ identifier: "DatumOption.FromCBORHex", diff --git a/packages/evolution/src/core/DnsName.ts b/packages/evolution/src/core/DnsName.ts index 1b47a527..edfd980d 100644 --- a/packages/evolution/src/core/DnsName.ts +++ b/packages/evolution/src/core/DnsName.ts @@ -9,7 +9,7 @@ import * as Text128 from "./Text128.js" * @since 2.0.0 * @category model */ -export const DnsName = Text128.FromVariableHex.pipe(Schema.brand("DnsName")) +export const DnsName = Text128.Text128.pipe(Schema.brand("DnsName")) /** * Type alias for DnsName. @@ -19,11 +19,11 @@ export const DnsName = Text128.FromVariableHex.pipe(Schema.brand("DnsName")) */ export type DnsName = typeof DnsName.Type -export const FromBytes = Schema.compose(Text128.FromVariableBytes, DnsName).annotations({ +export const FromBytes = Schema.compose(Text128.FromBytes, DnsName).annotations({ identifier: "DnsName.FromBytes" }) -export const FromHex = Schema.compose(Text128.FromVariableHex, DnsName).annotations({ +export const FromHex = Schema.compose(Text128.FromHex, DnsName).annotations({ identifier: "DnsName.FromHex" }) @@ -53,7 +53,7 @@ export const arbitrary = Text128.arbitrary.map((text) => DnsName.make(text)) * @since 2.0.0 * @category parsing */ -export const fromBytes = (bytes: Uint8Array): DnsName => Schema.decodeSync(FromBytes)(bytes) +export const fromBytes = Schema.decodeSync(FromBytes) /** * Parse DnsName from hex string. @@ -61,7 +61,7 @@ export const fromBytes = (bytes: Uint8Array): DnsName => Schema.decodeSync(FromB * @since 2.0.0 * @category parsing */ -export const fromHex = (hex: string): DnsName => Schema.decodeSync(FromHex)(hex) +export const fromHex = Schema.decodeSync(FromHex) /** * Encode DnsName to bytes. @@ -69,7 +69,7 @@ export const fromHex = (hex: string): DnsName => Schema.decodeSync(FromHex)(hex) * @since 2.0.0 * @category encoding */ -export const toBytes = (dnsName: DnsName): Uint8Array => Schema.encodeSync(FromBytes)(dnsName) +export const toBytes = Schema.encodeSync(FromBytes) /** * Encode DnsName to hex string. @@ -77,4 +77,4 @@ export const toBytes = (dnsName: DnsName): Uint8Array => Schema.encodeSync(FromB * @since 2.0.0 * @category encoding */ -export const toHex = (dnsName: DnsName): string => Schema.encodeSync(FromHex)(dnsName) +export const toHex = Schema.encodeSync(FromHex) diff --git a/packages/evolution/src/core/Ed25519Signature.ts b/packages/evolution/src/core/Ed25519Signature.ts index 3c9d78c2..5daff8bd 100644 --- a/packages/evolution/src/core/Ed25519Signature.ts +++ b/packages/evolution/src/core/Ed25519Signature.ts @@ -27,7 +27,7 @@ export class Ed25519Signature extends Schema.Class("Ed25519Sig } [Equal.symbol](that: unknown): boolean { - return that instanceof Ed25519Signature && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof Ed25519Signature && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/EnterpriseAddress.ts b/packages/evolution/src/core/EnterpriseAddress.ts index 56da8fbd..7ae10a54 100644 --- a/packages/evolution/src/core/EnterpriseAddress.ts +++ b/packages/evolution/src/core/EnterpriseAddress.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Bytes29 from "./Bytes29.js" import * as Credential from "./Credential.js" import * as KeyHash from "./KeyHash.js" @@ -46,7 +45,7 @@ export class EnterpriseAddress extends Schema.TaggedClass("En } } -export const FromBytes = Schema.transformOrFail(Bytes29.BytesSchema, Schema.typeSchema(EnterpriseAddress), { +export const FromBytes = Schema.transformOrFail(Schema.typeSchema(Bytes29.BytesFromHex), Schema.typeSchema(EnterpriseAddress), { strict: true, encode: (_, __, ___, toA) => Eff.gen(function* () { @@ -89,7 +88,7 @@ export const FromBytes = Schema.transformOrFail(Bytes29.BytesSchema, Schema.type }) export const FromHex = Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes // Uint8Array → EnterpriseAddress ).annotations({ identifier: "EnterpriseAddress.FromHex", diff --git a/packages/evolution/src/core/Function.ts b/packages/evolution/src/core/Function.ts index ff1bf9e8..ceb4f1f4 100644 --- a/packages/evolution/src/core/Function.ts +++ b/packages/evolution/src/core/Function.ts @@ -157,7 +157,7 @@ export const makeCBOREncodeHexSync = ( try { const cborValue = encode(input) const bytes = CBOR.internalEncodeSync(cborValue, options || defaultOptions) - return Bytes.toHexUnsafe(bytes) + return Bytes.toHex(bytes) } catch (e) { const error = new ErrorClass({ message: `Failed to encode hex in ${functionName}`, cause: e }) if (Error.captureStackTrace) { @@ -258,6 +258,6 @@ export const makeCBOREncodeHexEither = (input: A, options?: CBOR.CodecOptions) => Schema.encodeEither(schemaTransformer)(input).pipe( Either.flatMap((cborValue) => Either.try(() => CBOR.internalEncodeSync(cborValue, options || defaultOptions))), - Either.map((bytes) => Bytes.toHexUnsafe(bytes)), + Either.map((bytes) => Bytes.toHex(bytes)), Either.mapLeft((e) => new ErrorClass({ message: (e as Error).message, cause: e as Error })) ) diff --git a/packages/evolution/src/core/Header.ts b/packages/evolution/src/core/Header.ts index 415f208d..5b009bc5 100644 --- a/packages/evolution/src/core/Header.ts +++ b/packages/evolution/src/core/Header.ts @@ -7,7 +7,6 @@ */ import { Effect, Equal, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as HeaderBody from "./HeaderBody.js" import * as KesSignature from "./KesSignature.js" @@ -114,7 +113,7 @@ export const FromBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) */ export const FromHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes(options) // Uint8Array → Header ) diff --git a/packages/evolution/src/core/HeaderBody.ts b/packages/evolution/src/core/HeaderBody.ts index c9da6a3f..e94b8be3 100644 --- a/packages/evolution/src/core/HeaderBody.ts +++ b/packages/evolution/src/core/HeaderBody.ts @@ -2,7 +2,6 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema import * as BlockBodyHash from "./BlockBodyHash.js" import * as BlockHeaderHash from "./BlockHeaderHash.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Ed25519Signature from "./Ed25519Signature.js" import * as KESVkey from "./KESVkey.js" @@ -300,7 +299,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → HeaderBody ).annotations({ identifier: "HeaderBody.FromCBORHex", diff --git a/packages/evolution/src/core/IPv4.ts b/packages/evolution/src/core/IPv4.ts index bd4dad82..e59db327 100644 --- a/packages/evolution/src/core/IPv4.ts +++ b/packages/evolution/src/core/IPv4.ts @@ -25,7 +25,7 @@ export class IPv4 extends Schema.TaggedClass()("IPv4", { } [Equal.symbol](that: unknown): boolean { - return that instanceof IPv4 && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof IPv4 && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/IPv6.ts b/packages/evolution/src/core/IPv6.ts index eb609bba..ace97017 100644 --- a/packages/evolution/src/core/IPv6.ts +++ b/packages/evolution/src/core/IPv6.ts @@ -25,7 +25,7 @@ export class IPv6 extends Schema.TaggedClass()("IPv6", { } [Equal.symbol](that: unknown): boolean { - return that instanceof IPv6 && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof IPv6 && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/KESVkey.ts b/packages/evolution/src/core/KESVkey.ts index 0a84f304..fca0c646 100644 --- a/packages/evolution/src/core/KESVkey.ts +++ b/packages/evolution/src/core/KESVkey.ts @@ -27,7 +27,7 @@ export class KESVkey extends Schema.TaggedClass()("KESVkey", { } [Equal.symbol](that: unknown): boolean { - return that instanceof KESVkey && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof KESVkey && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/KesSignature.ts b/packages/evolution/src/core/KesSignature.ts index b2d6183e..fa62d771 100644 --- a/packages/evolution/src/core/KesSignature.ts +++ b/packages/evolution/src/core/KesSignature.ts @@ -11,7 +11,7 @@ import * as Bytes448 from "./Bytes448.js" * @category schemas */ export class KesSignature extends Schema.TaggedClass()("KesSignature", { - bytes: Bytes448.BytesSchema + bytes: Bytes448.BytesFromHex }) { toJSON() { return { _tag: "KesSignature" as const, bytes: Bytes.toHex(this.bytes) } @@ -26,7 +26,7 @@ export class KesSignature extends Schema.TaggedClass()("KesSignatu } [Equal.symbol](that: unknown): boolean { - return that instanceof KesSignature && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof KesSignature && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { @@ -35,7 +35,7 @@ export class KesSignature extends Schema.TaggedClass()("KesSignatu } // Transform between raw bytes (Uint8Array length 448) and KesSignature -export const FromBytes = Schema.transform(Bytes448.BytesSchema, KesSignature, { +export const FromBytes = Schema.transform(Schema.typeSchema(Bytes448.BytesFromHex), Schema.typeSchema(KesSignature), { strict: true, decode: (bytes) => new KesSignature({ bytes }, { disableValidation: true }), encode: (value) => value.bytes @@ -44,7 +44,7 @@ export const FromBytes = Schema.transform(Bytes448.BytesSchema, KesSignature, { }) export const FromHex = Schema.compose( - Bytes448.FromHex, // string -> Uint8Array(448) + Bytes448.BytesFromHex, // string -> Uint8Array(448) FromBytes // bytes -> KesSignature ).annotations({ identifier: "KesSignature.FromHex" diff --git a/packages/evolution/src/core/KeyHash.ts b/packages/evolution/src/core/KeyHash.ts index 3fb8ee6a..6e73bb62 100644 --- a/packages/evolution/src/core/KeyHash.ts +++ b/packages/evolution/src/core/KeyHash.ts @@ -36,7 +36,7 @@ export class KeyHash extends Schema.TaggedClass()("KeyHash", { } [Equal.symbol](that: unknown): boolean { - return that instanceof KeyHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof KeyHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/Mint.ts b/packages/evolution/src/core/Mint.ts index 1c285106..5802d515 100644 --- a/packages/evolution/src/core/Mint.ts +++ b/packages/evolution/src/core/Mint.ts @@ -387,7 +387,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Mint ).annotations({ identifier: "Mint.FromCBORHex", @@ -408,13 +408,13 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.oneof( FastCheck.uniqueArray(PolicyId.arbitrary, { minLength: 1, maxLength: 5, - selector: (p) => Bytes.toHexUnsafe(p.hash) + selector: (p) => Bytes.toHex(p.hash) }).chain((policies) => { const assetsForPolicy = () => FastCheck.uniqueArray(AssetName.arbitrary, { minLength: 1, maxLength: 5, - selector: (a) => Bytes.toHexUnsafe(a.bytes) + selector: (a) => Bytes.toHex(a.bytes) }).chain((names) => FastCheck.array(NonZeroInt64.arbitrary, { minLength: names.length, diff --git a/packages/evolution/src/core/MultiAsset.ts b/packages/evolution/src/core/MultiAsset.ts index 64a00700..02d714c5 100644 --- a/packages/evolution/src/core/MultiAsset.ts +++ b/packages/evolution/src/core/MultiAsset.ts @@ -105,9 +105,9 @@ export class MultiAsset extends Schema.Class("MultiAsset")({ for (const [policyId, assetMap] of this.map.entries()) { const serializedAssets: Record = {} for (const [assetName, quantity] of assetMap.entries()) { - serializedAssets[Bytes.toHexUnsafe(assetName.bytes)] = quantity.toString() + serializedAssets[Bytes.toHex(assetName.bytes)] = quantity.toString() } - serializedMap[Bytes.toHexUnsafe(policyId.hash)] = serializedAssets + serializedMap[Bytes.toHex(policyId.hash)] = serializedAssets } return { _tag: "MultiAsset" as const, @@ -171,7 +171,7 @@ export const equals = (a: MultiAsset, b: MultiAsset): boolean => { // Find matching policy in b by comparing bytes let bAssetMap: typeof aAssetMap | undefined for (const [bPolicyId, bAssets] of b.map.entries()) { - if (Bytes.bytesEquals(aPolicyId.hash, bPolicyId.hash)) { + if (Bytes.equals(aPolicyId.hash, bPolicyId.hash)) { bAssetMap = bAssets break } @@ -185,7 +185,7 @@ export const equals = (a: MultiAsset, b: MultiAsset): boolean => { // Find matching asset name in b by comparing bytes let bAmount: bigint | undefined for (const [bAssetName, bAmt] of bAssetMap.entries()) { - if (Bytes.bytesEquals(aAssetName.bytes, bAssetName.bytes)) { + if (Bytes.equals(aAssetName.bytes, bAssetName.bytes)) { bAmount = bAmt as bigint break } @@ -321,14 +321,14 @@ export const is = (value: unknown): value is MultiAsset => Schema.is(MultiAsset) export const arbitrary: FastCheck.Arbitrary = FastCheck.uniqueArray(PolicyId.arbitrary, { minLength: 1, maxLength: 5, - selector: (p) => Bytes.toHexUnsafe(p.hash) + selector: (p) => Bytes.toHex(p.hash) }).chain((policies) => { // For each unique policy, generate a unique set of asset names with aligned positive amounts const assetsForPolicy = () => FastCheck.uniqueArray(AssetName.arbitrary, { minLength: 1, maxLength: 5, - selector: (a) => Bytes.toHexUnsafe(a.bytes) + selector: (a) => Bytes.toHex(a.bytes) }).chain((names) => // Generate exactly names.length amounts to pair with the unique names FastCheck.array(PositiveCoin.arbitrary, { minLength: names.length, maxLength: names.length }).map((amounts) => { @@ -444,7 +444,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → MultiAsset ).annotations({ identifier: "MultiAsset.FromCBORHex", diff --git a/packages/evolution/src/core/MultiHostName.ts b/packages/evolution/src/core/MultiHostName.ts index 98d402c6..195ec0a5 100644 --- a/packages/evolution/src/core/MultiHostName.ts +++ b/packages/evolution/src/core/MultiHostName.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as DnsName from "./DnsName.js" @@ -118,7 +117,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → MultiHostName ).annotations({ identifier: "MultiHostName.FromCBORHex", diff --git a/packages/evolution/src/core/NativeScripts.ts b/packages/evolution/src/core/NativeScripts.ts index cc97fbb9..04f71a7d 100644 --- a/packages/evolution/src/core/NativeScripts.ts +++ b/packages/evolution/src/core/NativeScripts.ts @@ -470,7 +470,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → NativeScript ) diff --git a/packages/evolution/src/core/NativeScriptsOLD.ts b/packages/evolution/src/core/NativeScriptsOLD.ts index b49f8c00..807122dd 100644 --- a/packages/evolution/src/core/NativeScriptsOLD.ts +++ b/packages/evolution/src/core/NativeScriptsOLD.ts @@ -1,7 +1,6 @@ import { Data, Either as E, FastCheck, ParseResult, Schema } from "effect" import type { ParseIssue } from "effect/ParseResult" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Function from "./Function.js" @@ -188,7 +187,7 @@ export const internalEncodeCDDL = (native: Native): E.Either Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Native ).annotations({ identifier: "Native.FromCBORHex", diff --git a/packages/evolution/src/core/NonnegativeInterval.ts b/packages/evolution/src/core/NonnegativeInterval.ts index cd40173f..aad5b3a5 100644 --- a/packages/evolution/src/core/NonnegativeInterval.ts +++ b/packages/evolution/src/core/NonnegativeInterval.ts @@ -1,6 +1,5 @@ import { Effect, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Numeric from "./Numeric.js" @@ -124,7 +123,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI Schema.compose(CBOR.FromBytes(options), FromCDDL) export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, FromCBORBytes(options)) + Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)) export const arbitrary: FastCheck.Arbitrary = FastCheck.bigInt({ min: 1n, max: 1000000n }) .chain((denominator) => diff --git a/packages/evolution/src/core/OperationalCert.ts b/packages/evolution/src/core/OperationalCert.ts index a322211e..f93bb53a 100644 --- a/packages/evolution/src/core/OperationalCert.ts +++ b/packages/evolution/src/core/OperationalCert.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Ed25519Signature from "./Ed25519Signature.js" import * as KESVkey from "./KESVkey.js" @@ -123,7 +122,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → OperationalCert ) diff --git a/packages/evolution/src/core/PointerAddress.ts b/packages/evolution/src/core/PointerAddress.ts index a0fdde80..84a66d95 100644 --- a/packages/evolution/src/core/PointerAddress.ts +++ b/packages/evolution/src/core/PointerAddress.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Credential from "./Credential.js" import * as KeyHash from "./KeyHash.js" import * as Natural from "./Natural.js" @@ -202,7 +201,7 @@ export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Schem }) export const FromHex = Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes // Uint8Array → PointerAddress ).annotations({ identifier: "PointerAddress.FromHex", diff --git a/packages/evolution/src/core/PolicyId.ts b/packages/evolution/src/core/PolicyId.ts index 330fe7e1..eadc9f88 100644 --- a/packages/evolution/src/core/PolicyId.ts +++ b/packages/evolution/src/core/PolicyId.ts @@ -33,7 +33,7 @@ export class PolicyId extends Schema.TaggedClass()("PolicyId", { } [Equal.symbol](that: unknown): boolean { - return that instanceof PolicyId && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof PolicyId && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/PoolKeyHash.ts b/packages/evolution/src/core/PoolKeyHash.ts index 102b372c..e7d1c6a3 100644 --- a/packages/evolution/src/core/PoolKeyHash.ts +++ b/packages/evolution/src/core/PoolKeyHash.ts @@ -29,7 +29,7 @@ export class PoolKeyHash extends Schema.TaggedClass()("PoolKeyHash" } [Equal.symbol](that: unknown): boolean { - return that instanceof PoolKeyHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof PoolKeyHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/PoolMetadata.ts b/packages/evolution/src/core/PoolMetadata.ts index 4e97df31..84bcab8c 100644 --- a/packages/evolution/src/core/PoolMetadata.ts +++ b/packages/evolution/src/core/PoolMetadata.ts @@ -136,7 +136,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → PoolMetadata ).annotations({ identifier: "PoolMetadata.FromCBORHex", diff --git a/packages/evolution/src/core/PoolParams.ts b/packages/evolution/src/core/PoolParams.ts index b6ad4a14..c788d1b7 100644 --- a/packages/evolution/src/core/PoolParams.ts +++ b/packages/evolution/src/core/PoolParams.ts @@ -1,6 +1,5 @@ import { BigDecimal, Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as KeyHash from "./KeyHash.js" @@ -271,7 +270,7 @@ export const FromBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) */ export const FromHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes(options) // Uint8Array → PoolParams ) diff --git a/packages/evolution/src/core/PrivateKey.ts b/packages/evolution/src/core/PrivateKey.ts index b794ba3a..2a01f49f 100644 --- a/packages/evolution/src/core/PrivateKey.ts +++ b/packages/evolution/src/core/PrivateKey.ts @@ -53,7 +53,7 @@ export class PrivateKey extends Schema.TaggedClass()("PrivateKey", { } [Equal.symbol](that: unknown): boolean { - return that instanceof PrivateKey && Bytes.bytesEquals(this.key, that.key) + return that instanceof PrivateKey && Bytes.equals(this.key, that.key) } [Hash.symbol](): number { @@ -74,7 +74,7 @@ export const FromBytes = Schema.transform( }) export const FromHex = Schema.compose( - Bytes.FromHex, // string -> Uint8Array (any length) + Schema.Uint8ArrayFromHex, // string -> Uint8Array (any length) FromBytes // Uint8Array -> PrivateKey (validates 32 or 64) ).annotations({ identifier: "PrivateKey.FromHex" diff --git a/packages/evolution/src/core/ProposalProcedure.ts b/packages/evolution/src/core/ProposalProcedure.ts index 13fefc1d..578037a4 100644 --- a/packages/evolution/src/core/ProposalProcedure.ts +++ b/packages/evolution/src/core/ProposalProcedure.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, Hash, Inspectable, ParseResult, Schema } from "effect" import * as Anchor from "./Anchor.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as GovernanceAction from "./GovernanceAction.js" @@ -168,7 +167,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → ProposalProcedure ).annotations({ identifier: "ProposalProcedure.FromCBORHex", diff --git a/packages/evolution/src/core/ProposalProcedures.ts b/packages/evolution/src/core/ProposalProcedures.ts index 6dcb8545..f9f9f2ad 100644 --- a/packages/evolution/src/core/ProposalProcedures.ts +++ b/packages/evolution/src/core/ProposalProcedures.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" import * as Anchor from "./Anchor.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as GovernanceAction from "./GovernanceAction.js" @@ -126,7 +125,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → ProposalProcedures ).annotations({ identifier: "ProposalProcedures.FromCBORHex", diff --git a/packages/evolution/src/core/ProtocolParamUpdate.ts b/packages/evolution/src/core/ProtocolParamUpdate.ts index 17d42465..790a805b 100644 --- a/packages/evolution/src/core/ProtocolParamUpdate.ts +++ b/packages/evolution/src/core/ProtocolParamUpdate.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as CostModel from "./CostModel.js" @@ -502,7 +501,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI }) export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, FromCBORBytes(options)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)).annotations({ identifier: "ProtocolParamUpdate.FromCBORHex" }) diff --git a/packages/evolution/src/core/ProtocolVersion.ts b/packages/evolution/src/core/ProtocolVersion.ts index 03692fbf..57c3739e 100644 --- a/packages/evolution/src/core/ProtocolVersion.ts +++ b/packages/evolution/src/core/ProtocolVersion.ts @@ -1,6 +1,5 @@ import { Equal, FastCheck, Function, Hash, Inspectable, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Numeric from "./Numeric.js" @@ -100,7 +99,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → ProtocolVersion ).annotations({ identifier: "ProtocolVersion.FromCBORHex", diff --git a/packages/evolution/src/core/Redeemer.ts b/packages/evolution/src/core/Redeemer.ts index 46d45302..d9d2fab1 100644 --- a/packages/evolution/src/core/Redeemer.ts +++ b/packages/evolution/src/core/Redeemer.ts @@ -1,6 +1,5 @@ import { Effect, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as PlutusData from "./Data.js" import * as Numeric from "./Numeric.js" @@ -283,7 +282,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Redeemer ).annotations({ identifier: "Redeemer.FromCBORHex", diff --git a/packages/evolution/src/core/Relay.ts b/packages/evolution/src/core/Relay.ts index f243ac1e..f9eae1cd 100644 --- a/packages/evolution/src/core/Relay.ts +++ b/packages/evolution/src/core/Relay.ts @@ -1,6 +1,5 @@ import { FastCheck, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as MultiHostName from "./MultiHostName.js" import * as SingleHostAddr from "./SingleHostAddr.js" @@ -55,7 +54,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Relay ).annotations({ identifier: "Relay.FromCBORHex", diff --git a/packages/evolution/src/core/RewardAccount.ts b/packages/evolution/src/core/RewardAccount.ts index a38220cd..3d791a77 100644 --- a/packages/evolution/src/core/RewardAccount.ts +++ b/packages/evolution/src/core/RewardAccount.ts @@ -1,7 +1,6 @@ import { bech32 } from "@scure/base" import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Bytes29 from "./Bytes29.js" import * as Credential from "./Credential.js" import * as KeyHash from "./KeyHash.js" @@ -63,7 +62,7 @@ export class RewardAccount extends Schema.TaggedClass("RewardAcco } } -export const FromBytes = Schema.transformOrFail(Bytes29.BytesSchema, Schema.typeSchema(RewardAccount), { +export const FromBytes = Schema.transformOrFail(Schema.typeSchema(Bytes29.BytesFromHex), Schema.typeSchema(RewardAccount), { strict: true, encode: (_, __, ___, toA) => Eff.gen(function* () { @@ -102,7 +101,7 @@ export const FromBytes = Schema.transformOrFail(Bytes29.BytesSchema, Schema.type }) export const FromHex = Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes // Uint8Array → RewardAccount ).annotations({ identifier: "RewardAccount.FromHex", diff --git a/packages/evolution/src/core/Script.ts b/packages/evolution/src/core/Script.ts index 34bd28c4..d129fd02 100644 --- a/packages/evolution/src/core/Script.ts +++ b/packages/evolution/src/core/Script.ts @@ -1,6 +1,5 @@ import { Effect as Eff, FastCheck, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as NativeScripts from "./NativeScripts.js" import * as PlutusV1 from "./PlutusV1.js" @@ -116,7 +115,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI ) export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, FromCBORBytes(options)) + Schema.compose(Schema.Uint8ArrayFromHex, FromCBORBytes(options)) /** * FastCheck arbitrary for Script. diff --git a/packages/evolution/src/core/ScriptDataHash.ts b/packages/evolution/src/core/ScriptDataHash.ts index 7a12e6d2..76ee2bd2 100644 --- a/packages/evolution/src/core/ScriptDataHash.ts +++ b/packages/evolution/src/core/ScriptDataHash.ts @@ -34,7 +34,7 @@ export class ScriptDataHash extends Schema.TaggedClass()("Script } [Equal.symbol](that: unknown): boolean { - return that instanceof ScriptDataHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof ScriptDataHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/ScriptHash.ts b/packages/evolution/src/core/ScriptHash.ts index 9207650a..abbef238 100644 --- a/packages/evolution/src/core/ScriptHash.ts +++ b/packages/evolution/src/core/ScriptHash.ts @@ -37,7 +37,7 @@ export class ScriptHash extends Schema.TaggedClass()("ScriptHash", { } [Equal.symbol](that: unknown): boolean { - return that instanceof ScriptHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof ScriptHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/ScriptRef.ts b/packages/evolution/src/core/ScriptRef.ts index c690f87a..e0051412 100644 --- a/packages/evolution/src/core/ScriptRef.ts +++ b/packages/evolution/src/core/ScriptRef.ts @@ -36,7 +36,7 @@ export class ScriptRef extends Schema.TaggedClass()("ScriptRef", { } [Equal.symbol](that: unknown): boolean { - return that instanceof ScriptRef && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof ScriptRef && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { @@ -65,7 +65,7 @@ export const FromBytes = Schema.transform(Schema.Uint8ArrayFromSelf, Schema.type * @category schemas */ export const FromHex = Schema.compose( - Bytes.FromHex, // string -> Uint8Array + Schema.Uint8ArrayFromHex, // string -> Uint8Array FromBytes // Uint8Array -> ScriptRef ).annotations({ identifier: "ScriptRef.FromHex" @@ -119,7 +119,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → ScriptRef ).annotations({ identifier: "ScriptRef.FromCBORHex" diff --git a/packages/evolution/src/core/SingleHostAddr.ts b/packages/evolution/src/core/SingleHostAddr.ts index f7560b50..15a658a1 100644 --- a/packages/evolution/src/core/SingleHostAddr.ts +++ b/packages/evolution/src/core/SingleHostAddr.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as IPv4 from "./IPv4.js" import * as IPv6 from "./IPv6.js" @@ -239,7 +238,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → SingleHostAddr ).annotations({ identifier: "SingleHostAddr.FromCBORHex", diff --git a/packages/evolution/src/core/SingleHostName.ts b/packages/evolution/src/core/SingleHostName.ts index d1ce83cb..7a5e76af 100644 --- a/packages/evolution/src/core/SingleHostName.ts +++ b/packages/evolution/src/core/SingleHostName.ts @@ -1,6 +1,5 @@ import { Effect, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as DnsName from "./DnsName.js" import * as Port from "./Port.js" @@ -213,7 +212,7 @@ export const FromBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) */ export const FromHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromBytes(options) // Uint8Array → SingleHostName ) diff --git a/packages/evolution/src/core/Text.ts b/packages/evolution/src/core/Text.ts index 214b1b7d..1f2db610 100644 --- a/packages/evolution/src/core/Text.ts +++ b/packages/evolution/src/core/Text.ts @@ -1,35 +1,28 @@ import { FastCheck, Schema } from "effect" -import * as Bytes from "./Bytes.js" export const Text = Schema.String -/** - * Configuration for text transformations. - * - * @since 2.0.0 - * @category types - */ -export interface TextTransformationConfig { - id: string - to: Schema.Schema - from: Schema.Schema +// Shared transform options for text conversions +const textTransform = { + strict: true as const, + decode: (input: Uint8Array) => new TextDecoder().decode(input), + encode: (text: string) => new TextEncoder().encode(text) } /** - * Creates a text transformation schema. + * Schema for converting between strings and bytes (UTF-8). + * + * ``` + * text <-> bytes + * ``` * * @since 2.0.0 - * @category utilities + * @category schemas */ -export const makeTextTransformation = (config: TextTransformationConfig) => { - const { from: bytesSchema, id, to: inputSchema } = config - return Schema.transform(bytesSchema, inputSchema, { - strict: true, - decode: (input) => new TextDecoder().decode(input), - encode: (text) => new TextEncoder().encode(text) - }).annotations({ identifier: id }) -} +export const FromBytes = Schema.transform(Schema.Uint8ArrayFromSelf, Text, textTransform).annotations({ + identifier: "Text.FromBytes" +}) /** * Schema for converting between strings and hex representation of UTF-8 bytes. @@ -41,18 +34,9 @@ export const makeTextTransformation = (config: TextTransformationConfig) => { * @since 2.0.0 * @category schemas */ -export const FromBytes = makeTextTransformation({ - id: "Text.FromBytes", - to: Text, - from: Schema.Uint8ArrayFromSelf +export const FromHex = Schema.transform(Schema.Uint8ArrayFromHex, Text, textTransform).annotations({ + identifier: "Text.FromHex" }) -// type t = typeof FromBytes.Type -// type e = typeof FromBytes.Encoded - -export const FromHex = Schema.compose( - Bytes.FromHex, // string → Uint8Array - FromBytes // Uint8Array → string -) // ============================================================================= // Text Length Validation Utilities @@ -64,7 +48,7 @@ export const FromHex = Schema.compose( * @since 2.0.0 * @category validation */ -export const textLengthEquals = (length: number, identifier?: string) => +export const length = (length: number, identifier?: string) => Schema.filter((text: string) => text.length === length, { message: () => `Expected text length ${length}`, identifier @@ -77,7 +61,7 @@ export const textLengthEquals = (length: number, identifier?: string) => * @since 2.0.0 * @category composition */ -export const textLengthBetween = +export const between = (min: number, max: number, moduleName: string) => >(baseSchema: S) => baseSchema.pipe( @@ -99,7 +83,7 @@ export const textLengthBetween = * @since 2.0.0 * @category validation */ -export const textLengthMin = (min: number, identifier?: string) => +export const min = (min: number, identifier?: string) => Schema.filter((text: string) => text.length >= min, { message: () => `Expected text length at least ${min}`, identifier @@ -111,58 +95,12 @@ export const textLengthMin = (min: number, identifier?: string) => * @since 2.0.0 * @category validation */ -export const textLengthMax = (max: number, identifier?: string) => +export const max = (max: number, identifier?: string) => Schema.filter((text: string) => text.length <= max, { message: () => `Expected text length at most ${max}`, identifier }) -// ============================================================================= -// Text Transformation Utilities -// ============================================================================= - -// ============================================================================= -// Unsafe Helper Functions -// ============================================================================= - -/** - * Convert bytes to text (unsafe, no validation). - * - * @since 2.0.0 - * @category unsafe - */ -export const fromBytesUnsafe = (bytes: Uint8Array): string => new TextDecoder().decode(bytes) - -/** - * Convert text to bytes (unsafe, no validation). - * - * @since 2.0.0 - * @category unsafe - */ -export const toBytesUnsafe = (text: string): Uint8Array => new TextEncoder().encode(text) - -/** - * Convert hex to text (unsafe, no validation). - * - * @since 2.0.0 - * @category unsafe - */ -export const fromHexUnsafe = (hex: string): string => { - const bytes = Bytes.fromHexUnsafe(hex) - return fromBytesUnsafe(bytes) -} - -/** - * Convert text to hex (unsafe, no validation). - * - * @since 2.0.0 - * @category unsafe - */ -export const toHexUnsafe = (text: string): string => { - const bytes = toBytesUnsafe(text) - return Bytes.toHexUnsafe(bytes) -} - /** * FastCheck arbitrary for generating random text strings * diff --git a/packages/evolution/src/core/Text128.ts b/packages/evolution/src/core/Text128.ts index 438da5e4..241da081 100644 --- a/packages/evolution/src/core/Text128.ts +++ b/packages/evolution/src/core/Text128.ts @@ -1,6 +1,5 @@ import { FastCheck, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Text from "./Text.js" /** @@ -21,19 +20,22 @@ export const TEXT128_MAX_LENGTH = 128 * @since 2.0.0 * @category schemas */ -export const Text128 = Text.Text.pipe(Text.textLengthBetween(TEXT128_MIN_LENGTH, TEXT128_MAX_LENGTH, "Text128")) - -export type Text128 = typeof Text128.Type +export const Text128 = Text.Text.pipe( + Text.between(TEXT128_MIN_LENGTH, TEXT128_MAX_LENGTH, "Text128") +).annotations({ + identifier: "Text128" +}) -export const FromVariableBytes = Text.makeTextTransformation({ - id: "Text128.FromBytes", - to: Text128, - from: Schema.Uint8ArrayFromSelf +export const FromBytes = Schema.compose( + Text.FromBytes, // Uint8Array -> string + Text128 // string -> Text128 +).annotations({ + identifier: "Text128.FromBytes" }) -export const FromVariableHex = Schema.compose( - Bytes.BytesFromHexLenient, - FromVariableBytes // Uint8Array -> Text128 +export const FromHex = Schema.compose( + Schema.Uint8ArrayFromHex, + FromBytes // Uint8Array -> Text128 ).annotations({ identifier: "Text128.FromHex" }) @@ -55,7 +57,7 @@ export const isText128 = Schema.is(Text128) export const arbitrary = FastCheck.string({ minLength: TEXT128_MIN_LENGTH, maxLength: TEXT128_MAX_LENGTH -}).map((text) => text as Text128) +}).map((text) => text) // ============================================================================ // Root Functions @@ -67,7 +69,7 @@ export const arbitrary = FastCheck.string({ * @since 2.0.0 * @category parsing */ -export const fromBytes = (bytes: Uint8Array): Text128 => Schema.decodeSync(FromVariableBytes)(bytes) +export const fromBytes = Schema.decodeSync(FromBytes) /** * Parse Text128 from hex string (unsafe) @@ -75,7 +77,7 @@ export const fromBytes = (bytes: Uint8Array): Text128 => Schema.decodeSync(FromV * @since 2.0.0 * @category parsing */ -export const fromHex = (hex: string): Text128 => Schema.decodeSync(FromVariableHex)(hex) +export const fromHex = Schema.decodeSync(FromHex) /** * Encode Text128 to bytes (unsafe) @@ -83,7 +85,7 @@ export const fromHex = (hex: string): Text128 => Schema.decodeSync(FromVariableH * @since 2.0.0 * @category encoding */ -export const toBytes = (text: Text128): Uint8Array => Schema.encodeSync(FromVariableBytes)(text) +export const toBytes = Schema.encodeSync(FromBytes) /** * Encode Text128 to hex string (unsafe) @@ -91,4 +93,4 @@ export const toBytes = (text: Text128): Uint8Array => Schema.encodeSync(FromVari * @since 2.0.0 * @category encoding */ -export const toHex = (text: Text128): string => Schema.encodeSync(FromVariableHex)(text) +export const toHex = Schema.encodeSync(FromHex) diff --git a/packages/evolution/src/core/TransactionBody.ts b/packages/evolution/src/core/TransactionBody.ts index 745ddb72..fedd612f 100644 --- a/packages/evolution/src/core/TransactionBody.ts +++ b/packages/evolution/src/core/TransactionBody.ts @@ -565,7 +565,7 @@ export const arbitrary: FastCheck.Arbitrary = inputs: FastCheck.uniqueArray(TransactionInput.arbitrary, { minLength: 1, maxLength: 5, - selector: (i) => `${Bytes.toHexUnsafe(i.transactionId.hash)}:${i.index.toString()}` + selector: (i) => `${Bytes.toHex(i.transactionId.hash)}:${i.index.toString()}` }), outputs: FastCheck.array(TxOut.arbitrary, { minLength: 1, maxLength: 5 }), fee: Coin.arbitrary, @@ -585,7 +585,7 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.uniqueArray(KeyHash.arbitrary, { minLength: 1, maxLength: 5, - selector: (k) => Bytes.toHexUnsafe(k.hash) + selector: (k) => Bytes.toHex(k.hash) }), { nil: undefined } ), @@ -600,7 +600,7 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.uniqueArray(TransactionInput.arbitrary, { minLength: 1, maxLength: 3, - selector: (i) => `${Bytes.toHexUnsafe(i.transactionId.hash)}:${i.index.toString()}` + selector: (i) => `${Bytes.toHex(i.transactionId.hash)}:${i.index.toString()}` }), { nil: undefined } ), @@ -609,7 +609,7 @@ export const arbitrary: FastCheck.Arbitrary = FastCheck.uniqueArray(TransactionInput.arbitrary, { minLength: 1, maxLength: 3, - selector: (i) => `${Bytes.toHexUnsafe(i.transactionId.hash)}:${i.index.toString()}` + selector: (i) => `${Bytes.toHex(i.transactionId.hash)}:${i.index.toString()}` }), { nil: undefined } ), diff --git a/packages/evolution/src/core/TransactionHash.ts b/packages/evolution/src/core/TransactionHash.ts index d2e77a64..4975dd18 100644 --- a/packages/evolution/src/core/TransactionHash.ts +++ b/packages/evolution/src/core/TransactionHash.ts @@ -29,7 +29,7 @@ export class TransactionHash extends Schema.TaggedClass()("Tran } [Equal.symbol](that: unknown): boolean { - return that instanceof TransactionHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof TransactionHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/TransactionInput.ts b/packages/evolution/src/core/TransactionInput.ts index f20f4595..12a2c0d2 100644 --- a/packages/evolution/src/core/TransactionInput.ts +++ b/packages/evolution/src/core/TransactionInput.ts @@ -1,6 +1,5 @@ import { Either as E, Equal, FastCheck, Hash, Inspectable, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Numeric from "./Numeric.js" import * as TransactionHash from "./TransactionHash.js" @@ -108,7 +107,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → TransactionInput ).annotations({ identifier: "TransactionInput.FromCBORHex", diff --git a/packages/evolution/src/core/TransactionOutput.ts b/packages/evolution/src/core/TransactionOutput.ts index 133bd582..8387152f 100644 --- a/packages/evolution/src/core/TransactionOutput.ts +++ b/packages/evolution/src/core/TransactionOutput.ts @@ -2,7 +2,6 @@ import { Either as E, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } import * as AddressEras from "./AddressEras.js" import * as BaseAddress from "./BaseAddress.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as DatumOption from "./DatumOption.js" import * as EnterpriseAddress from "./EnterpriseAddress.js" @@ -297,7 +296,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → TransactionOutput ).annotations({ identifier: "TransactionOutput.FromCBORHex", diff --git a/packages/evolution/src/core/TxOut.ts b/packages/evolution/src/core/TxOut.ts index 21dd55b1..8c12fe8f 100644 --- a/packages/evolution/src/core/TxOut.ts +++ b/packages/evolution/src/core/TxOut.ts @@ -2,7 +2,6 @@ import { Either as E, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } import * as Address from "./Address.js" import * as Assets from "./Assets.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as DatumOption from "./DatumOption.js" import * as ScriptRef from "./ScriptRef.js" @@ -345,7 +344,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → TransactionOutput ).annotations({ identifier: "TransactionOutput.FromCBORHex", diff --git a/packages/evolution/src/core/UnitInterval.ts b/packages/evolution/src/core/UnitInterval.ts index d592406f..6e3bc230 100644 --- a/packages/evolution/src/core/UnitInterval.ts +++ b/packages/evolution/src/core/UnitInterval.ts @@ -1,6 +1,5 @@ import { BigDecimal, Effect, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Numeric from "./Numeric.js" @@ -178,7 +177,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → UnitInterval ).annotations({ identifier: "UnitInterval.CBORHex" diff --git a/packages/evolution/src/core/Url.ts b/packages/evolution/src/core/Url.ts index 4ae9b6c0..15a175c9 100644 --- a/packages/evolution/src/core/Url.ts +++ b/packages/evolution/src/core/Url.ts @@ -1,6 +1,5 @@ import { Equal, Hash, Inspectable, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as Text128 from "./Text128.js" /** @@ -67,14 +66,14 @@ export class Url extends Schema.TaggedClass("Url")("Url", { } } -export const FromBytes = Schema.transform(Text128.FromVariableBytes, Url, { +export const FromBytes = Schema.transform(Text128.FromBytes, Url, { strict: true, decode: (bytes) => new Url({ href: bytes }, { disableValidation: true }), // Disable validation since we already check length in Text128 encode: (url) => url.href }) export const FromHex = Schema.compose( - Bytes.BytesFromHexLenient, // string -> hex string + Schema.Uint8ArrayFromHex, // string -> hex string FromBytes ).annotations({ identifier: "Url.Hex" diff --git a/packages/evolution/src/core/VKey.ts b/packages/evolution/src/core/VKey.ts index d7a795e6..268195e8 100644 --- a/packages/evolution/src/core/VKey.ts +++ b/packages/evolution/src/core/VKey.ts @@ -31,7 +31,7 @@ export class VKey extends Schema.TaggedClass()("VKey", { } [Equal.symbol](that: unknown): boolean { - return that instanceof VKey && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof VKey && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/Value.ts b/packages/evolution/src/core/Value.ts index 95700667..2f21f235 100644 --- a/packages/evolution/src/core/Value.ts +++ b/packages/evolution/src/core/Value.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, Option, ParseResult, Schema } from "effect" import * as AssetName from "./AssetName.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as MultiAsset from "./MultiAsset.js" @@ -377,7 +376,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Value ).annotations({ identifier: "Value.FromCBORHex", diff --git a/packages/evolution/src/core/VotingProcedures.ts b/packages/evolution/src/core/VotingProcedures.ts index f23aa869..f405f7b7 100644 --- a/packages/evolution/src/core/VotingProcedures.ts +++ b/packages/evolution/src/core/VotingProcedures.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" import * as Anchor from "./Anchor.js" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Credential from "./Credential.js" import * as DRep from "./DRep.js" @@ -605,7 +604,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → VotingProcedures ).annotations({ identifier: "VotingProcedures.FromCBORHex", diff --git a/packages/evolution/src/core/VrfCert.ts b/packages/evolution/src/core/VrfCert.ts index 2d585caa..8e32a8b1 100644 --- a/packages/evolution/src/core/VrfCert.ts +++ b/packages/evolution/src/core/VrfCert.ts @@ -25,13 +25,20 @@ export class VRFOutput extends Schema.TaggedClass()("VrfOutput", { return this.toJSON() } [Equal.symbol](that: unknown): boolean { - return that instanceof VRFOutput && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof VRFOutput && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { return Hash.array(Array.from(this.bytes)) } } +// Shared transform options for VRFOutput +const vrfOutputTransform = { + strict: true as const, + decode: (bytes: Uint8Array) => new VRFOutput({ bytes }, { disableValidation: true }), + encode: (vrfOutput: VRFOutput) => vrfOutput.bytes +} + /** * Schema for VRF output as a byte array. * vrf_output = bytes .size 32 @@ -42,11 +49,7 @@ export class VRFOutput extends Schema.TaggedClass()("VrfOutput", { export const VRFOutputFromBytes = Schema.transform( Schema.typeSchema(Bytes32.BytesFromHex), Schema.typeSchema(VRFOutput), - { - strict: true, - decode: (bytes) => new VRFOutput({ bytes }, { disableValidation: true }), // Disable validation since we already check length in Bytes32 - encode: (vrfOutput) => vrfOutput.bytes - } + vrfOutputTransform ).annotations({ identifier: "VrfOutput.Bytes" }) @@ -58,9 +61,10 @@ export const VRFOutputFromBytes = Schema.transform( * @since 2.0.0 * @category schemas */ -export const VRFOutputHexSchema = Schema.compose( - Bytes32.BytesFromHex, // string -> hex string - VRFOutputFromBytes // hex string -> VRFOutput +export const VRFOutputHexSchema = Schema.transform( + Bytes32.BytesFromHex, + Schema.typeSchema(VRFOutput), + vrfOutputTransform ).annotations({ identifier: "VrfOutput.Hex" }) @@ -73,7 +77,7 @@ export const VRFOutputHexSchema = Schema.compose( * @category schemas */ export class VRFProof extends Schema.TaggedClass()("VrfProof", { - bytes: Bytes80.BytesSchema + bytes: Bytes80.BytesFromHex }) { toJSON() { return { _tag: "VrfProof", bytes: this.bytes } @@ -85,13 +89,20 @@ export class VRFProof extends Schema.TaggedClass()("VrfProof", { return this.toJSON() } [Equal.symbol](that: unknown): boolean { - return that instanceof VRFProof && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof VRFProof && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { return Hash.array(Array.from(this.bytes)) } } +// Shared transform options for VRFProof +const vrfProofTransform = { + strict: true as const, + decode: (bytes: Uint8Array) => new VRFProof({ bytes }, { disableValidation: true }), + encode: (vrfProof: VRFProof) => vrfProof.bytes +} + /** * Schema for VRF proof as a byte array. * vrf_proof = bytes .size 80 @@ -99,11 +110,11 @@ export class VRFProof extends Schema.TaggedClass()("VrfProof", { * @since 2.0.0 * @category schemas */ -export const VRFProofFromBytes = Schema.transform(Bytes80.BytesSchema, VRFProof, { - strict: true, - decode: (bytes) => new VRFProof({ bytes }, { disableValidation: true }), // Disable validation since we already check length in Bytes80 - encode: (vrfProof) => vrfProof.bytes -}).annotations({ +export const VRFProofFromBytes = Schema.transform( + Schema.typeSchema(Bytes80.BytesFromHex), + Schema.typeSchema(VRFProof), + vrfProofTransform +).annotations({ identifier: "VrfProof.Bytes" }) @@ -114,9 +125,10 @@ export const VRFProofFromBytes = Schema.transform(Bytes80.BytesSchema, VRFProof, * @since 2.0.0 * @category schemas */ -export const VRFProofHexSchema = Schema.compose( - Bytes80.FromHex, // string -> hex string - VRFProofFromBytes // hex string -> VRFProof +export const VRFProofHexSchema = Schema.transform( + Bytes80.BytesFromHex, + Schema.typeSchema(VRFProof), + vrfProofTransform ).annotations({ identifier: "VrfProof.Hex" }) @@ -202,7 +214,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → VrfCert ).annotations({ identifier: "VrfCert.FromCBORHex" diff --git a/packages/evolution/src/core/VrfKeyHash.ts b/packages/evolution/src/core/VrfKeyHash.ts index 25df6f59..d43042d1 100644 --- a/packages/evolution/src/core/VrfKeyHash.ts +++ b/packages/evolution/src/core/VrfKeyHash.ts @@ -29,7 +29,7 @@ export class VrfKeyHash extends Schema.TaggedClass()("VrfKeyHash", { } [Equal.symbol](that: unknown): boolean { - return that instanceof VrfKeyHash && Bytes.bytesEquals(this.hash, that.hash) + return that instanceof VrfKeyHash && Bytes.equals(this.hash, that.hash) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/VrfVkey.ts b/packages/evolution/src/core/VrfVkey.ts index 6ceb7753..1b2cd5d4 100644 --- a/packages/evolution/src/core/VrfVkey.ts +++ b/packages/evolution/src/core/VrfVkey.ts @@ -27,7 +27,7 @@ export class VrfVkey extends Schema.TaggedClass()("VrfVkey", { } [Equal.symbol](that: unknown): boolean { - return that instanceof VrfVkey && Bytes.bytesEquals(this.bytes, that.bytes) + return that instanceof VrfVkey && Bytes.equals(this.bytes, that.bytes) } [Hash.symbol](): number { diff --git a/packages/evolution/src/core/Withdrawals.ts b/packages/evolution/src/core/Withdrawals.ts index ce5dcab5..8e690d9e 100644 --- a/packages/evolution/src/core/Withdrawals.ts +++ b/packages/evolution/src/core/Withdrawals.ts @@ -1,6 +1,5 @@ import { Effect as Eff, Equal, FastCheck, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "./Bytes.js" import * as CBOR from "./CBOR.js" import * as Coin from "./Coin.js" import * as RewardAccount from "./RewardAccount.js" @@ -157,7 +156,7 @@ export const FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTI */ export const FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => Schema.compose( - Bytes.FromHex, // string → Uint8Array + Schema.Uint8ArrayFromHex, // string → Uint8Array FromCBORBytes(options) // Uint8Array → Withdrawals ) diff --git a/packages/evolution/src/core/message-signing/CoseSign.ts b/packages/evolution/src/core/message-signing/CoseSign.ts index 8a274015..56a1f566 100644 --- a/packages/evolution/src/core/message-signing/CoseSign.ts +++ b/packages/evolution/src/core/message-signing/CoseSign.ts @@ -269,7 +269,7 @@ export const COSESignFromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEFA * @category Schemas */ export const COSESignFromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, COSESignFromCBORBytes(options)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, COSESignFromCBORBytes(options)).annotations({ identifier: "COSESign.FromCBORHex" }) diff --git a/packages/evolution/src/core/message-signing/CoseSign1.ts b/packages/evolution/src/core/message-signing/CoseSign1.ts index d18257a7..38ebfef9 100644 --- a/packages/evolution/src/core/message-signing/CoseSign1.ts +++ b/packages/evolution/src/core/message-signing/CoseSign1.ts @@ -258,7 +258,7 @@ export const COSESign1FromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEF * @category Schemas */ export const COSESign1FromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, COSESign1FromCBORBytes(options)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, COSESign1FromCBORBytes(options)).annotations({ identifier: "COSESign1.FromCBORHex", description: "Transforms CBOR hex string to COSESign1" }) @@ -302,11 +302,11 @@ export class COSESign1Builder extends Schema.Class("COSESign1B [Equal.symbol](that: unknown): boolean { return ( that instanceof COSESign1Builder && - Bytes.bytesEquals(this.externalAad, that.externalAad) && + Bytes.equals(this.externalAad, that.externalAad) && this.hashPayload === that.hashPayload && Equal.equals(this.headers, that.headers) && this.isPayloadExternal === that.isPayloadExternal && - Bytes.bytesEquals(this.payload, that.payload) + Bytes.equals(this.payload, that.payload) ) } diff --git a/packages/evolution/src/core/message-signing/Header.ts b/packages/evolution/src/core/message-signing/Header.ts index fe9b9c31..5de996b9 100644 --- a/packages/evolution/src/core/message-signing/Header.ts +++ b/packages/evolution/src/core/message-signing/Header.ts @@ -7,7 +7,6 @@ import { Equal, Hash, Inspectable, ParseResult, Schema } from "effect" -import * as Bytes from "../Bytes.js" import * as CBOR from "../CBOR.js" import type { AlgorithmId } from "./Label.js" import { @@ -333,7 +332,7 @@ export const HeaderMapFromCBORBytes = (options: CBOR.CodecOptions = CBOR.CML_DEF * @category Schemas */ export const HeaderMapFromCBORHex = (options: CBOR.CodecOptions = CBOR.CML_DEFAULT_OPTIONS) => - Schema.compose(Bytes.FromHex, HeaderMapFromCBORBytes(options)).annotations({ + Schema.compose(Schema.Uint8ArrayFromHex, HeaderMapFromCBORBytes(options)).annotations({ identifier: "HeaderMap.FromCBORHex", description: "Transforms CBOR hex string to HeaderMap" }) diff --git a/packages/evolution/src/core/message-signing/SignData.ts b/packages/evolution/src/core/message-signing/SignData.ts index 4fce7558..812415de 100644 --- a/packages/evolution/src/core/message-signing/SignData.ts +++ b/packages/evolution/src/core/message-signing/SignData.ts @@ -118,7 +118,7 @@ export const verifyData = ( // Verify payload matches (allow empty payloads) if (coseSign1.payload === undefined) return false - if (!Bytes.bytesEquals(coseSign1.payload, payload)) return false + if (!Bytes.equals(coseSign1.payload, payload)) return false // Get protected headers const addressLabel = labelFromText("address") diff --git a/packages/evolution/src/sdk/AddressDetails.ts b/packages/evolution/src/sdk/AddressDetails.ts index c374da61..06e54e02 100644 --- a/packages/evolution/src/sdk/AddressDetails.ts +++ b/packages/evolution/src/sdk/AddressDetails.ts @@ -1,7 +1,6 @@ import { Effect as Eff, Equal, ParseResult, Schema } from "effect" import * as AddressEras from "../core/AddressEras.js" -import * as Bytes from "../core/Bytes.js" import * as NetworkId from "../core/NetworkId.js" /** @@ -22,7 +21,7 @@ export class AddressDetails extends Schema.Class("AddressDetails ), address: AddressEras.AddressEras, bech32: Schema.String, - hex: Bytes.HexSchema + hex: Schema.String }) {} export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressDetails), { @@ -42,7 +41,7 @@ export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchem }) }) -export const FromHex = Schema.transformOrFail(Bytes.HexSchema, Schema.typeSchema(AddressDetails), { +export const FromHex = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressDetails), { strict: true, encode: (_, __, ___, toA) => ParseResult.succeed(toA.hex), decode: (_, __, ___, fromA) => diff --git a/packages/evolution/src/sdk/builders/phases/Evaluation.ts b/packages/evolution/src/sdk/builders/phases/Evaluation.ts index 58dde1d6..bf25f15e 100644 --- a/packages/evolution/src/sdk/builders/phases/Evaluation.ts +++ b/packages/evolution/src/sdk/builders/phases/Evaluation.ts @@ -201,7 +201,7 @@ export const executeEvaluation = (): Effect.Effect< }) }) - const txHex = Bytes.toHexUnsafe(txCborBytes) + const txHex = Bytes.toHex(txCborBytes) // Debug: Log transaction details yield* Effect.logDebug(`[Evaluation] Transaction CBOR length: ${txHex.length} chars`) diff --git a/packages/evolution/test/CBOR.Aiken.test.ts b/packages/evolution/test/CBOR.Aiken.test.ts index e4e2931c..16351c90 100644 --- a/packages/evolution/test/CBOR.Aiken.test.ts +++ b/packages/evolution/test/CBOR.Aiken.test.ts @@ -44,14 +44,14 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #6: encode_bytearray_small it("encode_bytearray_small: should encode small bytearray", () => { - const value = Bytes.fromHexUnsafe("a1b2") + const value = Bytes.fromHex("a1b2") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("42a1b2") }) // Test #7: encode_bytearray_long it("encode_bytearray_long: should encode longer bytearray", () => { - const value = Bytes.fromHexUnsafe("deadbeef") + const value = Bytes.fromHex("deadbeef") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("44deadbeef") }) @@ -93,14 +93,14 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #13: encode_pair_mixed it("encode_pair_mixed: should encode mixed pair", () => { - const value = Data.list([1n, Bytes.fromHexUnsafe("ff")]) + const value = Data.list([1n, Bytes.fromHex("ff")]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f0141ffff") }) // Test #14: encode_triple it("encode_triple: should encode triple", () => { - const value = Data.list([1n, Bytes.fromHexUnsafe("ff"), 3n]) + const value = Data.list([1n, Bytes.fromHex("ff"), 3n]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f0141ff03ff") }) @@ -121,7 +121,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #17: encode_map_single_entry it("encode_map_single_entry: should encode single entry map", () => { - const value = Data.map([[1n, Bytes.fromHexUnsafe("ff")]]) + const value = Data.map([[1n, Bytes.fromHex("ff")]]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f9f0141ffffff") }) @@ -129,9 +129,9 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #18: encode_map_multiple_entries it("encode_map_multiple_entries: should encode map with multiple entries", () => { const value = Data.map([ - [Bytes.fromHexUnsafe("01"), 1n], - [Bytes.fromHexUnsafe("02"), 2n], - [Bytes.fromHexUnsafe("03"), 3n] + [Bytes.fromHex("01"), 1n], + [Bytes.fromHex("02"), 2n], + [Bytes.fromHex("03"), 3n] ]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f9f410101ff9f410202ff9f410303ffff") @@ -166,7 +166,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #22: encode_option_some_bytearray it("encode_option_some_bytearray: should encode Some(bytearray)", () => { const OptionBytes = TSchema.UndefinedOr(TSchema.ByteArray) - const value = Data.withSchema(OptionBytes).toData(Bytes.fromHexUnsafe("deadbeef")) + const value = Data.withSchema(OptionBytes).toData(Bytes.fromHex("deadbeef")) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("d8799f44deadbeefff") }) @@ -214,7 +214,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #28: encode_pair_tuple it("encode_pair_tuple: should encode pair tuple (1, #ff)", () => { - const value = Data.list([1n, Bytes.fromHexUnsafe("ff")]) + const value = Data.list([1n, Bytes.fromHex("ff")]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f0141ffff") }) @@ -291,7 +291,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #31: encode_list_of_bytearrays it("encode_list_of_bytearrays: should encode list of bytearrays", () => { - const value = Data.list([Bytes.fromHexUnsafe("aa"), Bytes.fromHexUnsafe("bb"), Bytes.fromHexUnsafe("cc")]) + const value = Data.list([Bytes.fromHex("aa"), Bytes.fromHex("bb"), Bytes.fromHex("cc")]) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("9f41aa41bb41ccff") }) @@ -380,7 +380,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #41: encode_constructor_with_bytearray_field it("encode_constructor_with_bytearray_field: should encode Holder(#deadbeef)", () => { const Holder = TSchema.Struct({ data: TSchema.ByteArray }) - const value = Data.withSchema(Holder).toData({ data: Bytes.fromHexUnsafe("deadbeef") }) + const value = Data.withSchema(Holder).toData({ data: Bytes.fromHex("deadbeef") }) const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("d8799f44deadbeefff") }) @@ -472,37 +472,37 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #53: encode_bytearray_25_bytes it("encode_bytearray_25_bytes: should encode 25-byte bytearray", () => { - const value = Bytes.fromHexUnsafe("000102030405060708090a0b0c0d0e0f101112131415161718") + const value = Bytes.fromHex("000102030405060708090a0b0c0d0e0f101112131415161718") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("5819000102030405060708090a0b0c0d0e0f101112131415161718") }) // Test #54: encode_bytearray_max_inline it("encode_bytearray_max_inline: should encode 24-byte bytearray", () => { - const value = Bytes.fromHexUnsafe("000102030405060708090a0b0c0d0e0f1011121314151617") + const value = Bytes.fromHex("000102030405060708090a0b0c0d0e0f1011121314151617") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("5818000102030405060708090a0b0c0d0e0f1011121314151617") }) // Test #55: encode_string_empty it("encode_string_empty: should encode empty string as bytearray", () => { - const value = Bytes.fromHexUnsafe("") + const value = Bytes.fromHex("") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("40") }) // Test #56: encode_string_ascii it("encode_string_ascii: should encode 'hello' as bytearray", () => { - const value = Text.toBytesUnsafe("hello") + const value = Text.toBytes("hello") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("4568656c6c6f") }) // Test #57: encode_string_unicode it("encode_string_unicode: should encode 'café' as bytearray", () => { - const value = Text.toBytesUnsafe("café") + const value = Text.toBytes("café") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) - expect(encoded).toBe("45636166c3a9") + expect(encoded).toBe("45636166c3a9") // UTF-8 encoding of "café" }) // Test #58: encode_bool_true @@ -521,10 +521,10 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #60: encode_complex_datum it("encode_complex_datum: should encode Datum{owner: 28-byte hash, amount: 1000, beneficiaries: [], metadata: Some(#dead)}", () => { - const owner = Bytes.fromHexUnsafe("abababababababababababababababababababababababababababab") + const owner = Bytes.fromHex("abababababababababababababababababababababababababababab") const amount = 1000n const beneficiaries: Array<[Uint8Array, bigint]> = [] - const metadata = Bytes.fromHexUnsafe("dead") + const metadata = Bytes.fromHex("dead") const Datum = TSchema.Struct({ owner: TSchema.ByteArray, @@ -546,7 +546,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #61: encode_redeemer it("encode_redeemer: should encode Redeemer{action: 100, params: [#abcd]}", () => { const action = 100n - const params = [Bytes.fromHexUnsafe("abcd")] + const params = [Bytes.fromHex("abcd")] const Redeemer = TSchema.Struct({ action: TSchema.Integer, @@ -579,21 +579,21 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #63: encode_pkh_credential it("encode_pkh_credential: should encode 28-byte payment key hash", () => { - const value = Bytes.fromHexUnsafe("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") + const value = Bytes.fromHex("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("581cabcdef1234567890abcdef1234567890abcdef1234567890abcdef12") }) // Test #64: encode_script_hash it("encode_script_hash: should encode 26-byte script hash", () => { - const value = Bytes.fromHexUnsafe("1234567890abcdef1234567890abcdef1234567890abcdef1234") + const value = Bytes.fromHex("1234567890abcdef1234567890abcdef1234567890abcdef1234") const encoded = Data.toCBORHex(value, CBOR.AIKEN_DEFAULT_OPTIONS) expect(encoded).toBe("581a1234567890abcdef1234567890abcdef1234567890abcdef1234") }) // Test #65: encode_credential_verification_key it("encode_credential_verification_key: should encode Credential with VerificationKey", () => { - const hash = Bytes.fromHexUnsafe("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") + const hash = Bytes.fromHex("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") const Credential = TSchema.Variant({ VerificationKey: { hash: TSchema.ByteArray }, @@ -609,7 +609,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #66: encode_credential_script it("encode_credential_script: should encode Credential with Script", () => { - const hash = Bytes.fromHexUnsafe("1234567890abcdef1234567890abcdef1234567890abcdef1234ab") + const hash = Bytes.fromHex("1234567890abcdef1234567890abcdef1234567890abcdef1234ab") const Credential = TSchema.Variant({ VerificationKey: { hash: TSchema.ByteArray }, @@ -625,7 +625,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #67: encode_referenced_inline it("encode_referenced_inline: should encode Referenced with Inline credential", () => { - const hash = Bytes.fromHexUnsafe("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") + const hash = Bytes.fromHex("abcdef1234567890abcdef1234567890abcdef1234567890abcdef12") const Credential = TSchema.Variant({ VerificationKey: { hash: TSchema.ByteArray }, @@ -679,7 +679,7 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #69: encode_address_payment_only it("encode_address_payment_only: should encode Address with payment credential only", () => { - const hash = Bytes.fromHexUnsafe("ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507a6") + const hash = Bytes.fromHex("ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507a6") const Credential = TSchema.Variant({ VerificationKey: { hash: TSchema.ByteArray }, @@ -711,8 +711,8 @@ describe("Aiken CBOR Encoding Compatibility", () => { // Test #70: encode_address_with_inline_stake_key it("encode_address_with_inline_stake_key: should encode Address with payment and inline stake (key)", () => { - const paymentHash = Bytes.fromHexUnsafe("ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507a6") - const stakeHash = Bytes.fromHexUnsafe("64ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507") + const paymentHash = Bytes.fromHex("ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507a6") + const stakeHash = Bytes.fromHex("64ff0185c80386d7ff02a2042efd97fbe6012dac0102751cfcc14507") const Credential = TSchema.Variant({ VerificationKey: { hash: TSchema.ByteArray },