Last active
April 25, 2024 05:08
-
-
Save KyGuy2002/1c70a5129042f1b037c56fe0b70b066e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function durableObjectNamespaceIdFromName(uniqueKey: string, name: string) { | |
const key = crypto.createHash("sha256").update(uniqueKey).digest(); | |
const nameHmac = crypto | |
.createHmac("sha256", key) | |
.update(name) | |
.digest() | |
.subarray(0, 16); | |
const hmac = crypto | |
.createHmac("sha256", key) | |
.update(nameHmac) | |
.digest() | |
.subarray(0, 16); | |
return Buffer.concat([nameHmac, hmac]).toString("hex"); | |
} | |
// ABOVE FOUND AT: https://github.dev/cloudflare/workers-sdk | |
// PATH: packages/miniflare/src/plugins/shared/index.ts | |
// UNIQUE KEY IS ALWAYS: miniflare-D1DatabaseObject | |
// NAME UNKNOWN. Probably binding, id, or name in wrangler.toml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment