Skip to content

Commit

Permalink
Merge pull-request #462
Browse files Browse the repository at this point in the history
  • Loading branch information
zkharit committed Dec 20, 2024
2 parents 3e5e7b2 + 2d5977b commit 4fceeea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit 4fceeea

Please sign in to comment.