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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ docs/.next

# Ignore debug
debug/
CLAUDE.md
1 change: 1 addition & 0 deletions packages/evolution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"typescript": "^5.9.2"
},
"dependencies": {
"@effect/platform": "^0.90.6",
"@effect/platform-node": "^0.96.0",
"@noble/hashes": "^1.8.0",
"@scure/base": "^1.2.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Data, Effect as Eff, ParseResult, Schema } from "effect"

import * as Address from "./Address.js"
import * as AddressEras from "./AddressEras.js"
import * as Bytes from "./Bytes.js"
import * as Function from "./Function.js"
import * as NetworkId from "./NetworkId.js"
Expand All @@ -26,7 +26,7 @@ export class AddressDetails extends Schema.Class<AddressDetails>("AddressDetails
Schema.Literal("RewardAccount"),
Schema.Literal("ByronAddress")
),
address: Address.Address,
address: AddressEras.AddressEras,
bech32: Schema.String,
hex: Bytes.HexSchema
}) {}
Expand All @@ -36,8 +36,8 @@ export const FromBech32 = Schema.transformOrFail(Schema.String, AddressDetails,
encode: (_, __, ___, toA) => ParseResult.succeed(toA.bech32),
decode: (_, __, ___, fromA) =>
Eff.gen(function* () {
const address = yield* ParseResult.decode(Address.FromBech32)(fromA)
const hex = yield* ParseResult.encode(Address.FromHex)(address)
const address = yield* ParseResult.decode(AddressEras.FromBech32)(fromA)
const hex = yield* ParseResult.encode(AddressEras.FromHex)(address)
return new AddressDetails({
networkId: address.networkId,
type: address._tag,
Expand All @@ -53,8 +53,8 @@ export const FromHex = Schema.transformOrFail(Bytes.HexSchema, AddressDetails, {
encode: (_, __, ___, toA) => ParseResult.succeed(toA.hex),
decode: (_, __, ___, fromA) =>
Eff.gen(function* () {
const address = yield* ParseResult.decode(Address.FromHex)(fromA)
const bech32 = yield* ParseResult.encode(Address.FromBech32)(address)
const address = yield* ParseResult.decode(AddressEras.FromHex)(fromA)
const bech32 = yield* ParseResult.encode(AddressEras.FromBech32)(address)
return new AddressDetails({
networkId: address.networkId,
type: address._tag,
Expand Down Expand Up @@ -83,7 +83,7 @@ export const equals = (self: AddressDetails, that: AddressDetails): boolean => {
return (
self.networkId === that.networkId &&
self.type === that.type &&
Address.equals(self.address, that.address) &&
AddressEras.equals(self.address, that.address) &&
self.bech32 === that.bech32 &&
self.hex === that.hex
)
Expand All @@ -95,18 +95,18 @@ export const equals = (self: AddressDetails, that: AddressDetails): boolean => {
* @since 2.0.0
* @category arbitrary
*/
export const arbitrary = Address.arbitrary.map((address) => fromAddress(address))
export const arbitrary = AddressEras.arbitrary.map((address) => fromAddress(address))

/**
* Create AddressDetails from an Address.
*
* @since 2.0.0
* @category constructors
*/
export const fromAddress = (address: Address.Address): AddressDetails => {
export const fromAddress = (address: AddressEras.AddressEras): AddressDetails => {
// Use schema encoding to get the serialized formats
const bech32 = Eff.runSync(Schema.encode(Address.FromBech32)(address))
const hex = Eff.runSync(Schema.encode(Address.FromHex)(address))
const bech32 = Eff.runSync(Schema.encode(AddressEras.FromBech32)(address))
const hex = Eff.runSync(Schema.encode(AddressEras.FromHex)(address))
return new AddressDetails({
networkId: address.networkId,
type: address._tag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,31 @@ export class AddressError extends Data.TaggedError("AddressError")<{
* @since 2.0.0
* @category model
*/
export const Address = Schema.Union(
export const AddressEras = Schema.Union(
BaseAddress.BaseAddress,
EnterpriseAddress.EnterpriseAddress,
PointerAddress.PointerAddress,
RewardAccount.RewardAccount,
ByronAddress.ByronAddress
)

export const isAddress = Schema.is(AddressEras)

/**
* Type representing an address.
*
* @since 2.0.0
* @category model
*/
export type Address = typeof Address.Type
export type AddressEras = typeof AddressEras.Type

/**
* Schema for encoding/decoding addresses as bytes.
*
* @since 2.0.0
* @category schema
*/
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, Address, {
export const FromBytes = Schema.transformOrFail(Schema.Uint8ArrayFromSelf, AddressEras, {
strict: true,
encode: (_, __, ___, toA) => {
switch (toA._tag) {
Expand Down Expand Up @@ -154,7 +156,7 @@ export const FromHex = Schema.compose(Bytes.FromHex, FromBytes)
* @since 2.0.0
* @category schema
*/
export const FromBech32 = Schema.transformOrFail(Schema.String, Address, {
export const FromBech32 = Schema.transformOrFail(Schema.String, AddressEras, {
strict: true,
encode: (_, __, ast, toA) =>
Eff.gen(function* () {
Expand Down Expand Up @@ -206,7 +208,7 @@ export const FromBech32 = Schema.transformOrFail(Schema.String, Address, {
* @since 2.0.0
* @category utils
*/
export const equals = (a: Address, b: Address): boolean => {
export const equals = (a: AddressEras, b: AddressEras): boolean => {
if (a._tag !== b._tag) {
return false
}
Expand Down
Loading
Loading