import { AddressUtils } from "../address"; import { HexUtils } from "../hex"; import { CborArray } from "./array"; import { CborSet } from "./set"; const decode = (signedData: string, parseData?: (v: string) => any) => { const decodedSignedData = CborArray.decode(signedData); const data = HexUtils.hexToString(decodedSignedData[2] as string) .split("|") .reduce( (acc, v) => { const [key, value] = v.split(":"); acc[key] = parseData ? parseData(value) : value; return acc; }, {} as { [key: string]: any; } ); const addressMap = CborSet.read<{ "61646472657373": string }>( decodedSignedData[0] as string ); const address = AddressUtils.toStakeAddress( AddressUtils.convertFromHexAddressToBech32(addressMap["61646472657373"]) ); return { address, data, }; }; export const CborSignedData = { decode };