{"version":3,"file":"hash.cjs","names":[],"sources":["../src/hash.ts"],"sourcesContent":["import { createHash, createHmac } from 'node:crypto';\n\nexport function durableObjectNamespaceIdFromName(uniqueKey: string, name: string) {\n  /**\n   * In v3.2, miniflare uses durable object to implement D1 and hashes the local sqlite filename.\n   *\n   * See the following for more context:\n   * https://github.com/cloudflare/workers-sdk/issues/4548 (understand the hash of the local D1 filename)\n   * https://github.com/cloudflare/miniflare/releases/tag/v3.20230918.0\n   *\n   * This function is copied from these links\n   */\n  const key = createHash('sha256').update(uniqueKey).digest();\n  const nameHmac = createHmac('sha256', key).update(name).digest().subarray(0, 16);\n  const hmac = createHmac('sha256', key).update(nameHmac).digest().subarray(0, 16);\n  return Buffer.concat([nameHmac, hmac]).toString('hex');\n}\n"],"mappings":";;;;AAEA,SAAgB,iCAAiC,WAAmB,MAAc;;;;;;;;;;CAUhF,MAAM,OAAA,GAAA,YAAA,YAAiB,SAAS,CAAC,OAAO,UAAU,CAAC,QAAQ;CAC3D,MAAM,YAAA,GAAA,YAAA,YAAsB,UAAU,IAAI,CAAC,OAAO,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,GAAG;CAChF,MAAM,QAAA,GAAA,YAAA,YAAkB,UAAU,IAAI,CAAC,OAAO,SAAS,CAAC,QAAQ,CAAC,SAAS,GAAG,GAAG;AAChF,QAAO,OAAO,OAAO,CAAC,UAAU,KAAK,CAAC,CAAC,SAAS,MAAM"}