{
  "version": 3,
  "sources": ["../../../src/services/nativeAuth/nativeAuth.ts"],
  "sourcesContent": ["import { NativeAuthClient } from '@multiversx/sdk-native-auth-client';\n\nimport {\n  getLatestBlockHash,\n  LatestBlockHashType\n} from './helpers/getLatestBlockHash';\n\nimport { buildNativeAuthConfig } from './methods/buildNativeAuthConfig';\nimport { getTokenExpiration } from './methods/getTokenExpiration';\nimport { NativeAuthConfigType } from './nativeAuth.types';\n\ninterface NativeAuthInitType {\n  extraInfo?: { [key: string]: string };\n  latestBlockInfo?: LatestBlockHashType;\n  noCache?: boolean;\n}\n\nexport const nativeAuth = (config?: NativeAuthConfigType) => {\n  const {\n    origin,\n    apiAddress,\n    expirySeconds,\n    blockHashShard,\n    extraInfo: extraInfoFromConfig,\n    gatewayUrl,\n    extraRequestHeaders\n  } = buildNativeAuthConfig(config);\n\n  const nativeAuthClient = new NativeAuthClient({\n    origin,\n    apiUrl: apiAddress,\n    expirySeconds,\n    blockHashShard,\n    gatewayUrl,\n    extraRequestHeaders\n  });\n\n  const initialize = async (\n    initProps?: NativeAuthInitType\n  ): Promise<string> => {\n    if (!apiAddress || !origin) {\n      return '';\n    }\n\n    const getBlockHash = (): Promise<string> =>\n      nativeAuthClient.getCurrentBlockHash();\n\n    let latestBlockInfo = initProps?.latestBlockInfo;\n\n    latestBlockInfo ??= await getLatestBlockHash({\n      apiAddress,\n      blockHashShard,\n      getBlockHash,\n      noCache: initProps?.noCache\n    });\n\n    const { hash, timestamp } = latestBlockInfo;\n    const encodedExtraInfo = nativeAuthClient.encodeValue(\n      JSON.stringify({\n        ...(initProps?.extraInfo ?? extraInfoFromConfig),\n        ...(timestamp ? { timestamp } : {})\n      })\n    );\n    const encodedOrigin = nativeAuthClient.encodeValue(origin);\n\n    return `${encodedOrigin}.${hash}.${expirySeconds}.${encodedExtraInfo}`;\n  };\n\n  const getToken = ({\n    address,\n    token,\n    signature\n  }: {\n    address: string;\n    token: string;\n    signature: string;\n  }): string => nativeAuthClient.getToken(address, token, signature);\n\n  return {\n    initialize,\n    getToken,\n    getTokenExpiration\n  };\n};\n"],
  "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiC,8CAEjCC,EAGO,wCAEPC,EAAsC,2CACtCC,EAAmC,wCAS5B,MAAML,EAAcM,GAAkC,CAC3D,KAAM,CACJ,OAAAC,EACA,WAAAC,EACA,cAAAC,EACA,eAAAC,EACA,UAAWC,EACX,WAAAC,EACA,oBAAAC,CACF,KAAI,yBAAsBP,CAAM,EAE1BQ,EAAmB,IAAI,mBAAiB,CAC5C,OAAAP,EACA,OAAQC,EACR,cAAAC,EACA,eAAAC,EACA,WAAAE,EACA,oBAAAC,CACF,CAAC,EA2CD,MAAO,CACL,WA1CiB,MACjBE,GACoB,CACpB,GAAI,CAACP,GAAc,CAACD,EAClB,MAAO,GAGT,MAAMS,EAAe,IACnBF,EAAiB,oBAAoB,EAEvC,IAAIG,EAAkBF,GAAW,gBAEjCE,IAAoB,QAAM,sBAAmB,CAC3C,WAAAT,EACA,eAAAE,EACA,aAAAM,EACA,QAASD,GAAW,OACtB,CAAC,EAED,KAAM,CAAE,KAAAG,EAAM,UAAAC,CAAU,EAAIF,EACtBG,EAAmBN,EAAiB,YACxC,KAAK,UAAU,CACb,GAAIC,GAAW,WAAaJ,EAC5B,GAAIQ,EAAY,CAAE,UAAAA,CAAU,EAAI,CAAC,CACnC,CAAC,CACH,EAGA,MAAO,GAFeL,EAAiB,YAAYP,CAAM,CAElC,IAAIW,CAAI,IAAIT,CAAa,IAAIW,CAAgB,EACtE,EAcE,SAZe,CAAC,CAChB,QAAAC,EACA,MAAAC,EACA,UAAAC,CACF,IAIcT,EAAiB,SAASO,EAASC,EAAOC,CAAS,EAK/D,uCACF,CACF",
  "names": ["nativeAuth_exports", "__export", "nativeAuth", "__toCommonJS", "import_sdk_native_auth_client", "import_getLatestBlockHash", "import_buildNativeAuthConfig", "import_getTokenExpiration", "config", "origin", "apiAddress", "expirySeconds", "blockHashShard", "extraInfoFromConfig", "gatewayUrl", "extraRequestHeaders", "nativeAuthClient", "initProps", "getBlockHash", "latestBlockInfo", "hash", "timestamp", "encodedExtraInfo", "address", "token", "signature"]
}
