{
  "version": 3,
  "sources": ["src/automation/api/_actor.api.ts", "src/automation/api/automation.api.ts", "src/automation/errors.ts", "src/automation/_automation.ts", "src/automation/_context.ts", "src/utils/nonce.utils.ts", "src/utils/url.utils.ts", "src/automation/authenticate.ts"],
  "sourcesContent": ["import {type SatelliteActor, getSatelliteActor} from '@junobuild/ic-client/actor';\nimport type {ActorParameters} from '../types/actor';\n\nexport const getAutomationActor = ({\n  automation,\n  identity\n}: ActorParameters): Promise<SatelliteActor> =>\n  getSatelliteActor({...automation.satellite, identity});\n", "import type {ActorParameters, AutomationArgs, AutomationResult} from '../types/actor';\nimport {getAutomationActor} from './_actor.api';\n\nexport const authenticateAutomation = async ({\n  actorParams,\n  args\n}: {\n  args: AutomationArgs;\n  actorParams: ActorParameters;\n}): Promise<AutomationResult> => {\n  const {authenticate_automation} = await getAutomationActor(actorParams);\n  return await authenticate_automation(args);\n};\n", "export class AutomationError extends Error {}\n\nexport class GenerateJwtError extends Error {\n  constructor(options?: ErrorOptions) {\n    super('Jwt generation failed', options);\n  }\n}\n", "import type {AuthParameters} from '../delegation/types/authenticate';\nimport {authenticateAutomation as authenticateAutomationApi} from './api/automation.api';\nimport {AutomationError, GenerateJwtError} from './errors';\nimport type {\n  AuthenticatedAutomation,\n  AutomationCredentials,\n  AutomationParameters\n} from './types/authenticate';\nimport type {OpenIdAutomationContext} from './types/context';\n\ninterface AutomationArgs {\n  jwt: string;\n  context: Omit<OpenIdAutomationContext, 'nonce'>;\n  automation: AutomationParameters;\n}\n\ntype AuthenticationAutomationArgs = AutomationCredentials & {\n  context: OpenIdAutomationContext;\n  automation: AutomationParameters;\n};\n\nexport const authenticateAutomation = async <T extends AuthParameters>({\n  generateJwt,\n  context: {nonce, ...context},\n  automation\n}: AuthenticationAutomationArgs): Promise<AuthenticatedAutomation> => {\n  const generate = async (): Promise<{jwt: string}> => {\n    try {\n      return await generateJwt({nonce});\n    } catch (err: unknown) {\n      throw new GenerateJwtError({cause: err});\n    }\n  };\n\n  return await authenticate<T>({\n    ...(await generate()),\n    context,\n    automation\n  });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst authenticate = async <T extends AuthParameters>({\n  jwt,\n  context: {caller, salt},\n  automation\n}: AutomationArgs): Promise<AuthenticatedAutomation> => {\n  const result = await authenticateAutomationApi({\n    args: {\n      OpenId: {\n        jwt,\n        salt\n      }\n    },\n    actorParams: {\n      automation,\n      identity: caller\n    }\n  });\n\n  if ('Err' in result) {\n    throw new AutomationError('Automation authentication failed', {cause: result});\n  }\n\n  const {Ok: data} = result;\n\n  return {\n    identity: caller,\n    data\n  };\n};\n", "import {Ed25519KeyIdentity} from '@icp-sdk/core/identity';\nimport {generateNonce} from '../utils/nonce.utils';\nimport type {OpenIdAutomationContext} from './types/context';\n\nexport const initContext = async (): Promise<OpenIdAutomationContext> => {\n  const caller = Ed25519KeyIdentity.generate();\n  const {nonce, salt} = await generateNonce({caller});\n\n  return {\n    nonce,\n    salt,\n    caller\n  };\n};\n", "import type {Ed25519KeyIdentity} from '@icp-sdk/core/identity';\nimport {arrayBufferToUint8Array} from '@junobuild/utils';\nimport type {Nonce, Salt} from '../types/nonce';\nimport {toBase64URL} from './url.utils';\n\nconst generateSalt = (): Salt => crypto.getRandomValues(new Uint8Array(32));\n\nconst buildNonce = async ({salt, caller}: {salt: Salt; caller: Ed25519KeyIdentity}) => {\n  const principal = caller.getPrincipal().toUint8Array();\n\n  const bytes = new Uint8Array(salt.length + principal.byteLength);\n  bytes.set(salt);\n  bytes.set(principal, salt.length);\n\n  const hash = await crypto.subtle.digest('SHA-256', bytes);\n\n  return toBase64URL(arrayBufferToUint8Array(hash));\n};\n\nexport const generateNonce = async ({\n  caller\n}: {\n  caller: Ed25519KeyIdentity;\n}): Promise<{nonce: Nonce; salt: Salt}> => {\n  const salt = generateSalt();\n  const nonce = await buildNonce({salt, caller});\n\n  return {nonce, salt};\n};\n", "import {uint8ArrayToBase64} from '@junobuild/utils';\n\n// In the future: uint8Array.toBase64({ alphabet: \"base64url\" })\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64\nexport const toBase64URL = (uint8Array: Uint8Array): string =>\n  uint8ArrayToBase64(uint8Array).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '');\n", "import {authenticateAutomation as authenticate} from './_automation';\nimport {initContext} from './_context';\nimport type {\n  AuthenticatedAutomation,\n  AutomationParameters,\n  AutomationParams\n} from './types/authenticate';\n\nexport const authenticateAutomation = async <T extends AutomationParameters>(\n  params: AutomationParams<T>\n): Promise<AuthenticatedAutomation> => {\n  const context = await initContext();\n\n  const {\n    github: {\n      credentials: {generateJwt},\n      automation\n    }\n  } = params;\n\n  return await authenticate<T>({\n    generateJwt,\n    context,\n    automation\n  });\n};\n"],
  "mappings": ";;AAAA,OAA6B,qBAAAA,MAAwB,6BAG9C,IAAMC,EAAqB,CAAC,CACjC,WAAAC,EACA,SAAAC,CACF,IACEH,EAAkB,CAAC,GAAGE,EAAW,UAAW,SAAAC,CAAQ,CAAC,ECJhD,IAAMC,EAAyB,MAAO,CAC3C,YAAAC,EACA,KAAAC,CACF,IAGiC,CAC/B,GAAM,CAAC,wBAAAC,CAAuB,EAAI,MAAMC,EAAmBH,CAAW,EACtE,OAAO,MAAME,EAAwBD,CAAI,CAC3C,ECZO,IAAMG,EAAN,cAA8B,KAAM,CAAC,EAE/BC,EAAN,cAA+B,KAAM,CAC1C,YAAYC,EAAwB,CAClC,MAAM,wBAAyBA,CAAO,CACxC,CACF,ECeO,IAAMC,EAAyB,MAAiC,CACrE,YAAAC,EACA,QAAS,CAAC,MAAAC,EAAO,GAAGC,CAAO,EAC3B,WAAAC,CACF,IASS,MAAMC,EAAgB,CAC3B,GAAI,MATW,SAAoC,CACnD,GAAI,CACF,OAAO,MAAMJ,EAAY,CAAC,MAAAC,CAAK,CAAC,CAClC,OAASI,EAAc,CACrB,MAAM,IAAIC,EAAiB,CAAC,MAAOD,CAAG,CAAC,CACz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,CAAI,CACrB,EDxBO,IAAMQ,EAAc,SAA8C,CACvE,IAAMC,EAASC,EAAmB,SAAS,EACrC,CAAC,MAAAC,EAAO,KAAAC,CAAI,EAAI,MAAMC,EAAc,CAAC,OAAAJ,CAAM,CAAC,EAElD,MAAO,CACL,MAAAE,EACA,KAAAC,EACA,OAAAH,CACF,CACF,EGLO,IAAMK,EAAyB,MACpCC,GACqC,CACrC,IAAMC,EAAU,MAAMC,EAAY,EAE5B,CACJ,OAAQ,CACN,YAAa,CAAC,YAAAC,CAAW,EACzB,WAAAC,CACF,CACF,EAAIJ,EAEJ,OAAO,MAAMD,EAAgB,CAC3B,YAAAI,EACA,QAAAF,EACA,WAAAG,CACF,CAAC,CACH",
  "names": ["getSatelliteActor", "getAutomationActor", "automation", "identity", "authenticateAutomation", "actorParams", "args", "authenticate_automation", "getAutomationActor", "AutomationError", "GenerateJwtError", "options", "authenticateAutomation", "generateJwt", "nonce", "context", "automation", "authenticate", "err", "GenerateJwtError", "jwt", "caller", "salt", "result", "AutomationError", "data", "Ed25519KeyIdentity", "arrayBufferToUint8Array", "uint8ArrayToBase64", "toBase64URL", "uint8Array", "generateSalt", "buildNonce", "salt", "caller", "principal", "bytes", "hash", "toBase64URL", "arrayBufferToUint8Array", "generateNonce", "initContext", "caller", "Ed25519KeyIdentity", "nonce", "salt", "generateNonce", "authenticateAutomation", "params", "context", "initContext", "generateJwt", "automation"]
}
