@turnkey/api-key-stamper
Version:
API key stamper for @turnkey/http
20 lines (17 loc) • 763 B
JavaScript
import { pointDecode } from './tink/elliptic_curves.mjs';
import { uint8ArrayFromHexString, hexStringToBase64url, DEFAULT_JWK_MEMBER_BYTE_LENGTH } from '@turnkey/encoding';
function convertTurnkeyApiKeyToJwk(input) {
const { uncompressedPrivateKeyHex, compressedPublicKeyHex } = input;
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(uncompressedPrivateKeyHex, DEFAULT_JWK_MEMBER_BYTE_LENGTH);
return jwk;
}
export { convertTurnkeyApiKeyToJwk };
//# sourceMappingURL=utils.mjs.map