UNPKG

ox

Version:

Ethereum Standard Library

59 lines 1.73 kB
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) { if (typeof value === 'string') return Signature.fromHex(value); if (value instanceof Uint8Array) return Signature.fromBytes(value); return value; } /** * Coerces a serialized or structured public key input into a structured * {@link ox#PublicKey.PublicKey}. * * @internal */ export function normalizePublicKey(value) { if (typeof value === 'string') return PublicKey.fromHex(value); if (value instanceof Uint8Array) return PublicKey.fromBytes(value); 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, as) { 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, as) { if (as === 'Hex') return PublicKey.toHex(publicKey); if (as === 'Bytes') return PublicKey.toBytes(publicKey); return publicKey; } //# sourceMappingURL=cryptoIo.js.map