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 5 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
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(
`invalid API key: Ensure that you are using a valid public and private key in compressed or uncompressed format and they are not switched`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to template the value of compressedPublicKeyHex in this case?

I think this message should be purely about API public key rather than both public and private keys. Something like unable to load API key: invalid public key ("${compressedPublicKeyHex}")?

);
}

// 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