{"version":3,"file":"index.cjs","sources":["../../../../src/utils/checkAddressOnCurve/index.ts"],"sourcesContent":["import { Address, ReadonlyUint8Array } from \"@solana/kit\";\r\n\r\nimport { addressCodec } from \"../../codecs\";\r\nimport { _pointIsOnCurve } from \"./ed25519\";\r\n\r\nfunction byteToHex(byte: number): string {\r\n  const hexString = byte.toString(16);\r\n  if (hexString.length === 1) {\r\n    return `0${hexString}`;\r\n  } else {\r\n    return hexString;\r\n  }\r\n}\r\n\r\nfunction decompressPointBytes(bytes: ReadonlyUint8Array): bigint {\r\n  const hexString = bytes.reduce(\r\n    (acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~0x80 : byte)}${acc}`,\r\n    \"\"\r\n  );\r\n  const integerLiteralString = `0x${hexString}`;\r\n\r\n  return BigInt(integerLiteralString);\r\n}\r\n\r\n/**\r\n * Returns whether a Solana address represents a valid Ed25519 curve point.\r\n *\r\n * @param address Solana address to validate\r\n * @returns Whether the address is an Ed25519 curve point\r\n *\r\n * @example\r\n * ```ts\r\n * const onCurve = checkAddressOnCurve(address);\r\n * ```\r\n */\r\nexport function checkAddressOnCurve(address: Address): boolean {\r\n  const bytes = addressCodec.encode(address);\r\n  if (bytes.byteLength !== 32) {\r\n    return false;\r\n  }\r\n  const y = decompressPointBytes(bytes);\r\n\r\n  return _pointIsOnCurve(y, bytes[31]);\r\n}\r\n"],"names":["addressCodec","_pointIsOnCurve"],"mappings":";;;;;;;AAKA,SAAS,SAAS,CAAC,IAAY,EAAA;IAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;AACnC,IAAA,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE;;SACjB;AACL,QAAA,OAAO,SAAS;;AAEpB;AAEA,SAAS,oBAAoB,CAAC,KAAyB,EAAA;AACrD,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAC5B,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,CAAA,EAAG,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,GAAG,IAAK,GAAG,IAAI,CAAC,CAAG,EAAA,GAAG,EAAE,EACxE,EAAE,CACH;AACD,IAAA,MAAM,oBAAoB,GAAG,CAAK,EAAA,EAAA,SAAS,EAAE;AAE7C,IAAA,OAAO,MAAM,CAAC,oBAAoB,CAAC;AACrC;AAEA;;;;;;;;;;AAUG;AACG,SAAU,mBAAmB,CAAC,OAAgB,EAAA;IAClD,MAAM,KAAK,GAAGA,mBAAY,CAAC,MAAM,CAAC,OAAO,CAAC;AAC1C,IAAA,IAAI,KAAK,CAAC,UAAU,KAAK,EAAE,EAAE;AAC3B,QAAA,OAAO,KAAK;;AAEd,IAAA,MAAM,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC;IAErC,OAAOC,uBAAe,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;AACtC;;;;"}