mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-06 00:12:11 +00:00
generate api key
This commit is contained in:
parent
4e629c5b64
commit
c278e16e4e
1 changed files with 5 additions and 4 deletions
|
|
@ -31,11 +31,12 @@ export namespace Key {
|
||||||
|
|
||||||
// Generate secret key: sk- + 64 random characters (upper, lower, numbers)
|
// Generate secret key: sk- + 64 random characters (upper, lower, numbers)
|
||||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
let randomPart = ""
|
let secretKey = "sk-"
|
||||||
for (let i = 0; i < 64; i++) {
|
const array = new Uint32Array(64)
|
||||||
randomPart += chars.charAt(Math.floor(Math.random() * chars.length))
|
crypto.getRandomValues(array)
|
||||||
|
for (let i = 0, l = array.length; i < l; i++) {
|
||||||
|
secretKey += chars[array[i] % chars.length]
|
||||||
}
|
}
|
||||||
const secretKey = `sk-${randomPart}`
|
|
||||||
const keyID = Identifier.create("key")
|
const keyID = Identifier.create("key")
|
||||||
|
|
||||||
await Database.use((tx) =>
|
await Database.use((tx) =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue