import type * as Bytes from '../Bytes.js' import type * as Hex from '../Hex.js' import * as PublicKey from '../PublicKey.js' import * as Signature from '../Signature.js' /** * Coerces a serialized or structured signature input into a structured * {@link ox#Signature.Signature} object. * * Accepts the existing structured form (pass-through), a hex string, or a * `Uint8Array` (delegates to `Signature.fromHex` / `Signature.fromBytes`). * * @internal */ export function normalizeSignature( value: | Hex.Hex | Bytes.Bytes | Signature.Signature | Signature.Signature, ): Signature.Signature { if (typeof value === 'string') return Signature.fromHex(value) as Signature.Signature if (value instanceof Uint8Array) return Signature.fromBytes(value) as Signature.Signature return value as Signature.Signature } /** * Coerces a serialized or structured public key input into a structured * {@link ox#PublicKey.PublicKey}. * * @internal */ export function normalizePublicKey( value: Hex.Hex | Bytes.Bytes | PublicKey.PublicKey, ): PublicKey.PublicKey { if (typeof value === 'string') return PublicKey.fromHex(value) as PublicKey.PublicKey if (value instanceof Uint8Array) return PublicKey.fromBytes(value) as PublicKey.PublicKey return value } /** * Formats a structured {@link ox#Signature.Signature} as the requested * representation: the structured object (`'Object'`), serialized hex * (`'Hex'`), or serialized bytes (`'Bytes'`). * * @internal */ export function formatSignature( signature: Signature.Signature, as: 'Hex' | 'Bytes' | 'Object', ): unknown { if (as === 'Hex') return Signature.toHex(signature) if (as === 'Bytes') return Signature.toBytes(signature) return signature } /** * Formats a structured {@link ox#PublicKey.PublicKey} as the requested * representation. * * @internal */ export function formatPublicKey( publicKey: PublicKey.PublicKey, as: 'Hex' | 'Bytes' | 'Object', ): unknown { if (as === 'Hex') return PublicKey.toHex(publicKey) if (as === 'Bytes') return PublicKey.toBytes(publicKey) return publicKey }