{"version":3,"file":"txCode.mjs","names":[],"sources":["../../../src/openid4vc-issuer/util/txCode.ts"],"sourcesContent":["import { type AgentContext, Kms } from '@credo-ts/core'\nimport type { OpenId4VciTxCode } from '../../shared'\n\nexport function generateTxCode(agentContext: AgentContext, txCode: OpenId4VciTxCode) {\n  const kms = agentContext.resolve(Kms.KeyManagementApi)\n\n  const length = txCode.length ?? 4\n  const inputMode = txCode.input_mode ?? 'numeric'\n\n  const numbers = '0123456789'\n  const letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'\n  const characters = inputMode === 'numeric' ? numbers : numbers + letters\n  const random = kms.randomBytes({ length })\n\n  let result = ''\n  for (let i = 0; i < length; i++) {\n    result += characters[random[i] % characters.length]\n  }\n\n  return result\n}\n"],"mappings":";;;AAGA,SAAgB,eAAe,cAA4B,QAA0B;CACnF,MAAM,MAAM,aAAa,QAAQ,IAAI,iBAAiB;CAEtD,MAAM,SAAS,OAAO,UAAU;CAChC,MAAM,YAAY,OAAO,cAAc;CAEvC,MAAM,UAAU;CAEhB,MAAM,aAAa,cAAc,YAAY,UAAU,UADvC;CAEhB,MAAM,SAAS,IAAI,YAAY,EAAE,QAAQ,CAAC;CAE1C,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,IAC1B,WAAU,WAAW,OAAO,KAAK,WAAW;AAG9C,QAAO"}