Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update common error message #462

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/red-carrots-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@turnkey/api-key-stamper": patch
"@turnkey/sdk-browser": patch
---

Update error messaging around api key and target public key usage
9 changes: 8 additions & 1 deletion packages/api-key-stamper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ export function convertTurnkeyApiKeyToJwk(input: {
}): JsonWebKey {
const { uncompressedPrivateKeyHex, compressedPublicKeyHex } = input;

const jwk = pointDecode(uint8ArrayFromHexString(compressedPublicKeyHex));
let jwk;
try {
jwk = pointDecode(uint8ArrayFromHexString(compressedPublicKeyHex));
} catch (e) {
throw new Error(
`unable to load API key: invalid public key. Did you switch your public and private key?`
);
}

// Ensure that d is sufficiently padded
jwk.d = hexStringToBase64url(
Expand Down
11 changes: 10 additions & 1 deletion packages/sdk-browser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ export const createEmbeddedAPIKey = async (

// 3: import the targetPublicKey (i.e. passed in from the iframe)
const targetKeyBytes = uint8ArrayFromHexString(targetPublicKey);
const jwk = pointDecode(targetKeyBytes);

let jwk;
try {
jwk = pointDecode(targetKeyBytes);
} catch (e) {
// provide more context about the error that is being thrown
throw new Error(
`target public key is not a valid compressed public key: ${targetPublicKey}`
);
}

const targetKey = await crypto.subtle.importKey(
"jwk",
Expand Down
Loading