-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e269bc
commit 2e4fa27
Showing
4 changed files
with
53 additions
and
13 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test, expect } from "@jest/globals"; | ||
import { convertTurnkeyApiKeyToJwk } from "../utils"; | ||
import { readFixture } from "../__fixtures__/shared"; | ||
import { assertValidSignature } from "./shared"; | ||
import { generateP256KeyPair } from "@turnkey/crypto"; | ||
import * as crypto from "crypto"; | ||
import { uint8ArrayFromHexString } from "@turnkey/encoding"; | ||
|
||
Object.defineProperty(globalThis, "crypto", { | ||
value: { | ||
getRandomValues: (arr) => crypto.randomBytes(arr.length), | ||
}, | ||
}); | ||
|
||
test("correctly converts turnkey API key to JWK", function () { | ||
for (let i = 0; i < 100; i++) { | ||
try { | ||
const newApiKeyPair = generateP256KeyPair(); | ||
|
||
const result = convertTurnkeyApiKeyToJwk({ | ||
uncompressedPrivateKeyHex: newApiKeyPair.privateKey, | ||
compressedPublicKeyHex: newApiKeyPair.publicKey, | ||
}); | ||
} catch (err: any) { | ||
console.log("caught an error", err); | ||
expect(err).toBeTruthy(); | ||
|
||
return; | ||
} | ||
} | ||
}); | ||
|
||
const uint8ArrayFromHex = (hexString: string) => new Uint8Array(hexString.match(/../g)!.map((h) => parseInt(h, 16))); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.