Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/evolution/src/core/AddressDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class AddressDetails extends Schema.Class<AddressDetails>("AddressDetails
hex: Bytes.HexSchema
}) {}

export const FromBech32 = Schema.transformOrFail(Schema.String, AddressDetails, {
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressDetails), {
strict: true,
encode: (_, __, ___, toA) => ParseResult.succeed(toA.bech32),
decode: (_, __, ___, fromA) =>
Expand All @@ -48,7 +48,7 @@ export const FromBech32 = Schema.transformOrFail(Schema.String, AddressDetails,
})
})

export const FromHex = Schema.transformOrFail(Bytes.HexSchema, AddressDetails, {
export const FromHex = Schema.transformOrFail(Bytes.HexSchema, Schema.typeSchema(AddressDetails), {
strict: true,
encode: (_, __, ___, toA) => ParseResult.succeed(toA.hex),
decode: (_, __, ___, fromA) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/evolution/src/core/AddressEras.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export type AddressEras = typeof AddressEras.Type
* @since 2.0.0
* @category schema
*/
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, AddressEras, {
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Schema.typeSchema(AddressEras), {
strict: true,
encode: (_, __, ___, toA) => {
switch (toA._tag) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export const FromHex = Schema.compose(Bytes.FromHex, FromBytes)
* @since 2.0.0
* @category schema
*/
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressEras, {
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressEras), {
strict: true,
encode: (_, __, ast, toA) =>
Eff.gen(function* () {
Expand Down
18 changes: 9 additions & 9 deletions packages/evolution/src/core/AddressStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class AddressStructureError extends Data.TaggedError("AddressStructureErr
*/
export class AddressStructure extends Schema.Class<AddressStructure>("AddressStructure")({
networkId: NetworkId.NetworkId,
paymentCredential: Credential.Credential,
stakingCredential: Schema.optional(Credential.Credential)
paymentCredential: Credential.CredentialSchema,
stakingCredential: Schema.optional(Credential.CredentialSchema)
}) {
toString(): string {
const staking = this.stakingCredential ? `, stakingCredential: ${this.stakingCredential}` : ""
Expand All @@ -47,7 +47,7 @@ export class AddressStructure extends Schema.Class<AddressStructure>("AddressStr
*/
export const FromBytes = Schema.transformOrFail(
Schema.Union(Bytes57.BytesSchema, Bytes29.BytesSchema),
AddressStructure,
Schema.typeSchema(AddressStructure),
{
strict: true,
encode: (_, __, ___, toA) =>
Expand Down Expand Up @@ -84,28 +84,28 @@ export const FromBytes = Schema.transformOrFail(
if (fromA.length === 57) {
// BaseAddress (with staking credential)
const isPaymentKey = (addressTypeBits & 0b0001) === 0
const paymentCredential: Credential.Credential = isPaymentKey
const paymentCredential: Credential.CredentialSchema = isPaymentKey
? new KeyHash.KeyHash({ hash: fromA.slice(1, 29) })
: new ScriptHash.ScriptHash({ hash: fromA.slice(1, 29) })

const isStakeKey = (addressTypeBits & 0b0010) === 0
const stakingCredential: Credential.Credential = isStakeKey
const stakingCredential: Credential.CredentialSchema = isStakeKey
? new KeyHash.KeyHash({ hash: fromA.slice(29, 57) })
: new ScriptHash.ScriptHash({ hash: fromA.slice(29, 57) })

return yield* ParseResult.decode(AddressStructure)({
return AddressStructure.make({
networkId,
paymentCredential,
stakingCredential
})
} else if (fromA.length === 29) {
// EnterpriseAddress (no staking credential)
const isPaymentKey = (addressTypeBits & 0b0001) === 0
const paymentCredential: Credential.Credential = isPaymentKey
const paymentCredential: Credential.CredentialSchema = isPaymentKey
? new KeyHash.KeyHash({ hash: fromA.slice(1, 29) })
: new ScriptHash.ScriptHash({ hash: fromA.slice(1, 29) })

return yield* ParseResult.decode(AddressStructure)({
return AddressStructure.make({
networkId,
paymentCredential,
stakingCredential: undefined
Expand Down Expand Up @@ -135,7 +135,7 @@ export const FromHex = Schema.compose(Bytes.FromHex, FromBytes).annotations({
* @since 1.0.0
* @category Transformations
*/
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressStructure, {
export const FromBech32 = Schema.transformOrFail(Schema.String, Schema.typeSchema(AddressStructure), {
strict: true,
encode: (_, __, ___, toA) =>
Eff.gen(function* () {
Expand Down
2 changes: 1 addition & 1 deletion packages/evolution/src/core/Anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AnchorError extends Data.TaggedError("AnchorError")<{
*/
export class Anchor extends Schema.Class<Anchor>("Anchor")({
anchorUrl: Url.Url,
anchorDataHash: Bytes32.BytesSchema
anchorDataHash: Bytes32.BytesFromHex
}) {}

export const CDDLSchema = Schema.Tuple(
Expand Down
25 changes: 11 additions & 14 deletions packages/evolution/src/core/AssetName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@ export class AssetNameError extends Data.TaggedError("AssetNameError")<{
* @category model
*/
export class AssetName extends Schema.TaggedClass<AssetName>()("AssetName", {
bytes: Bytes32.VariableBytes
}) {
toJSON(): string {
return toHex(this)
}
toString(): string {
return toHex(this)
}
}
bytes: Bytes32.VariableBytesFromHex
}) {}

/**
* Schema for encoding/decoding AssetName as bytes.
*
* @since 2.0.0
* @category schemas
*/
export const FromBytes = Schema.transform(Bytes32.VariableBytes, AssetName, {
strict: true,
decode: (bytes) => new AssetName({ bytes }, { disableValidation: true }),
encode: (assetName) => assetName.bytes
}).annotations({
export const FromBytes = Schema.transform(
Schema.typeSchema(Bytes32.VariableBytesFromHex),
Schema.typeSchema(AssetName),
{
strict: true,
decode: (bytes) => new AssetName({ bytes }, { disableValidation: true }),
encode: (assetName) => assetName.bytes
}
).annotations({
identifier: "AssetName.FromBytes"
})

Expand Down
10 changes: 5 additions & 5 deletions packages/evolution/src/core/AuxiliaryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ConwayAuxiliaryData extends Schema.TaggedClass<ConwayAuxiliaryData>
"ConwayAuxiliaryData",
{
metadata: Schema.optional(Metadata.Metadata),
nativeScripts: Schema.optional(Schema.Array(NativeScripts.Native)),
nativeScripts: Schema.optional(Schema.Array(NativeScripts.NativeScript)),
plutusV1Scripts: Schema.optional(Schema.Array(PlutusV1.PlutusV1)),
plutusV2Scripts: Schema.optional(Schema.Array(PlutusV2.PlutusV2)),
plutusV3Scripts: Schema.optional(Schema.Array(PlutusV3.PlutusV3))
Expand All @@ -65,7 +65,7 @@ export class ShelleyMAAuxiliaryData extends Schema.TaggedClass<ShelleyMAAuxiliar
"ShelleyMAAuxiliaryData",
{
metadata: Schema.optional(Metadata.Metadata),
nativeScripts: Schema.optional(Schema.Array(NativeScripts.Native))
nativeScripts: Schema.optional(Schema.Array(NativeScripts.NativeScript))
}
) {}

Expand Down Expand Up @@ -240,7 +240,7 @@ export const FromCDDL = Schema.transformOrFail(AnyEraCDDL, Schema.typeSchema(Aux
if (Array.isArray(input)) {
const arr = input
let metadata: Metadata.Metadata | undefined
let nativeScripts: Array<NativeScripts.Native> | undefined
let nativeScripts: Array<NativeScripts.NativeScript> | undefined

if (arr.length >= 1 && arr[0] !== undefined) {
const m = yield* ParseResult.decodeEither(Metadata.FromCDDL)(arr[0])
Expand Down Expand Up @@ -325,7 +325,7 @@ export const empty = (): AuxiliaryData => new ConwayAuxiliaryData({})
*/
export const conway = (input: {
metadata?: Metadata.Metadata
nativeScripts?: Array<NativeScripts.Native>
nativeScripts?: Array<NativeScripts.NativeScript>
plutusV1Scripts?: Array<PlutusV1.PlutusV1>
plutusV2Scripts?: Array<PlutusV2.PlutusV2>
plutusV3Scripts?: Array<PlutusV3.PlutusV3>
Expand All @@ -339,7 +339,7 @@ export const conway = (input: {
*/
export const shelleyMA = (input: {
metadata?: Metadata.Metadata
nativeScripts?: Array<NativeScripts.Native>
nativeScripts?: Array<NativeScripts.NativeScript>
}): AuxiliaryData => new ShelleyMAAuxiliaryData({ ...input })

/**
Expand Down
18 changes: 11 additions & 7 deletions packages/evolution/src/core/AuxiliaryDataHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ export class AuxiliaryDataHashError extends Data.TaggedError("AuxiliaryDataHashE
* @category model
*/
export class AuxiliaryDataHash extends Schema.TaggedClass<AuxiliaryDataHash>()("AuxiliaryDataHash", {
bytes: Bytes32.BytesSchema
bytes: Bytes32.BytesFromHex
}) {}

export const FromBytes = Schema.transform(Bytes32.BytesSchema, AuxiliaryDataHash, {
strict: true,
decode: (bytes) => new AuxiliaryDataHash({ bytes }, { disableValidation: true }),
encode: (a) => a.bytes
}).annotations({
export const FromBytes = Schema.transform(
Schema.typeSchema(Bytes32.BytesFromHex),
Schema.typeSchema(AuxiliaryDataHash),
{
strict: true,
decode: (bytes) => new AuxiliaryDataHash({ bytes }, { disableValidation: true }),
encode: (a) => a.bytes
}
).annotations({
identifier: "AuxiliaryDataHash.FromBytes"
})

export const FromHex = Schema.compose(
Bytes32.FromHex, // string -> Bytes32
Bytes32.BytesFromHex, // string -> Bytes32
FromBytes // Bytes32 -> AuxiliaryDataHash
).annotations({
identifier: "AuxiliaryDataHash.FromHex"
Expand Down
13 changes: 6 additions & 7 deletions packages/evolution/src/core/BaseAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export class BaseAddressError extends Data.TaggedError("BaseAddressError")<{
*/
export class BaseAddress extends Schema.TaggedClass<BaseAddress>("BaseAddress")("BaseAddress", {
networkId: NetworkId.NetworkId,
paymentCredential: Credential.Credential,
stakeCredential: Credential.Credential
paymentCredential: Credential.CredentialSchema,
stakeCredential: Credential.CredentialSchema
}) {
toString(): string {
return `BaseAddress { networkId: ${this.networkId}, paymentCredential: ${this.paymentCredential}, stakeCredential: ${this.stakeCredential} }`
Expand All @@ -33,7 +33,7 @@ export class BaseAddress extends Schema.TaggedClass<BaseAddress>("BaseAddress")(
}
}

export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, BaseAddress, {
export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, Schema.typeSchema(BaseAddress), {
strict: true,
encode: (_, __, ___, toA) =>
Eff.gen(function* () {
Expand All @@ -57,23 +57,22 @@ export const FromBytes = Schema.transformOrFail(Bytes57.BytesSchema, BaseAddress
const addressType = header >> 4
// Script payment, Script stake
const isPaymentKey = (addressType & 0b0001) === 0
const paymentCredential: Credential.Credential = isPaymentKey
const paymentCredential: Credential.CredentialSchema = isPaymentKey
? new KeyHash.KeyHash({
hash: fromA.slice(1, 29)
})
: new ScriptHash.ScriptHash({
hash: fromA.slice(1, 29)
})
const isStakeKey = (addressType & 0b0010) === 0
const stakeCredential: Credential.Credential = isStakeKey
const stakeCredential: Credential.CredentialSchema = isStakeKey
? new KeyHash.KeyHash({
hash: fromA.slice(29, 57)
})
: new ScriptHash.ScriptHash({
hash: fromA.slice(29, 57)
})
return yield* ParseResult.decode(BaseAddress)({
_tag: "BaseAddress",
return BaseAddress.make({
networkId,
paymentCredential,
stakeCredential
Expand Down
6 changes: 3 additions & 3 deletions packages/evolution/src/core/Bip32PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Bip32PublicKeyError extends Data.TaggedError("Bip32PublicKeyError")
* @category schemas
*/
export class Bip32PublicKey extends Schema.TaggedClass<Bip32PublicKey>()("Bip32PublicKey", {
bytes: Bytes64.BytesSchema
bytes: Bytes64.BytesFromHex
}) {
toJSON(): string {
return toHex(this)
Expand All @@ -46,7 +46,7 @@ export class Bip32PublicKey extends Schema.TaggedClass<Bip32PublicKey>()("Bip32P
* @since 2.0.0
* @category schemas
*/
export const FromBytes = Schema.transform(Bytes64.BytesSchema, Bip32PublicKey, {
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes64.BytesFromHex), Schema.typeSchema(Bip32PublicKey), {
strict: true,
decode: (bytes) => new Bip32PublicKey({ bytes }, { disableValidation: true }),
encode: (bip32PublicKey) => bip32PublicKey.bytes
Expand All @@ -61,7 +61,7 @@ export const FromBytes = Schema.transform(Bytes64.BytesSchema, Bip32PublicKey, {
* @category schemas
*/
export const FromHex = Schema.compose(
Bytes64.FromHex, // string -> Bytes64
Bytes64.BytesFromHex, // string -> Bytes64
FromBytes // Bytes64 -> Bip32PublicKey
).annotations({
identifier: "Bip32PublicKey.FromHex"
Expand Down
6 changes: 3 additions & 3 deletions packages/evolution/src/core/BlockBodyHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BlockBodyHashError extends Data.TaggedError("BlockBodyHashError")<{
* @category model
*/
export class BlockBodyHash extends Schema.TaggedClass<BlockBodyHash>()("BlockBodyHash", {
bytes: Bytes32.BytesSchema
bytes: Bytes32.BytesFromHex
}) {}

/**
Expand All @@ -32,7 +32,7 @@ export class BlockBodyHash extends Schema.TaggedClass<BlockBodyHash>()("BlockBod
* @since 2.0.0
* @category schemas
*/
export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockBodyHash, {
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes32.BytesFromHex), Schema.typeSchema(BlockBodyHash), {
strict: true,
decode: (bytes) => new BlockBodyHash({ bytes }, { disableValidation: true }),
encode: (bbh) => bbh.bytes
Expand All @@ -47,7 +47,7 @@ export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockBodyHash, {
* @category schemas
*/
export const FromHex = Schema.compose(
Bytes32.FromHex, // string -> Bytes32
Bytes32.BytesFromHex, // string -> Bytes32
FromBytes // Bytes32 -> BlockBodyHash
).annotations({
identifier: "BlockBodyHash.FromHex"
Expand Down
6 changes: 3 additions & 3 deletions packages/evolution/src/core/BlockHeaderHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BlockHeaderHashError extends Data.TaggedError("BlockHeaderHashError
* @category model
*/
export class BlockHeaderHash extends Schema.TaggedClass<BlockHeaderHash>()("BlockHeaderHash", {
bytes: Bytes32.BytesSchema
bytes: Bytes32.BytesFromHex
}) {}

/**
Expand All @@ -32,7 +32,7 @@ export class BlockHeaderHash extends Schema.TaggedClass<BlockHeaderHash>()("Bloc
* @since 2.0.0
* @category schemas
*/
export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockHeaderHash, {
export const FromBytes = Schema.transform(Schema.typeSchema(Bytes32.BytesFromHex), Schema.typeSchema(BlockHeaderHash), {
strict: true,
decode: (bytes) => new BlockHeaderHash({ bytes }, { disableValidation: true }),
encode: (bhh) => bhh.bytes
Expand All @@ -47,7 +47,7 @@ export const FromBytes = Schema.transform(Bytes32.BytesSchema, BlockHeaderHash,
* @category schemas
*/
export const FromHex = Schema.compose(
Bytes32.FromHex, // string -> Bytes32
Bytes32.BytesFromHex, // string -> Bytes32
FromBytes // Bytes32 -> BlockHeaderHash
).annotations({
identifier: "BlockHeaderHash.FromHex"
Expand Down
9 changes: 3 additions & 6 deletions packages/evolution/src/core/BootstrapWitness.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Effect as Eff, FastCheck, ParseResult, Schema } from "effect"

import * as Bytes32 from "./Bytes32.js"
import * as CBOR from "./CBOR.js"
import * as Ed25519Signature from "./Ed25519Signature.js"
import * as Function from "./Function.js"
Expand All @@ -21,12 +22,8 @@ import * as VKey from "./VKey.js"
export class BootstrapWitness extends Schema.Class<BootstrapWitness>("BootstrapWitness")({
publicKey: VKey.VKey,
signature: Ed25519Signature.Ed25519Signature,
chainCode: Schema.Uint8ArrayFromSelf.pipe(
Schema.filter((bytes) => bytes.length === 32, {
message: () => "Chain code must be exactly 32 bytes"
})
),
attributes: Schema.Uint8ArrayFromSelf
chainCode: Bytes32.BytesFromHex,
attributes: Schema.Uint8ArrayFromHex
}) {}

// Tuple schema as per CDDL
Expand Down
2 changes: 1 addition & 1 deletion packages/evolution/src/core/Bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const bytesLengthEquals =
*/
export const bytesLengthBetween =
(minBytes: number, maxBytes: number) =>
<S extends Schema.Schema<any, Uint8Array>>(baseSchema: S) =>
<S extends Schema.Schema<any, any>>(baseSchema: S) =>
baseSchema.pipe(
Schema.filter((bytes: Uint8Array) => bytes.length >= minBytes && bytes.length <= maxBytes, {
message: () => `Must be between ${minBytes} and ${maxBytes} bytes`
Expand Down
Loading
Loading