// Fetch public key in JWK format (default)
async function getPublicKey() {
const response = await fetch('https://cc.firmly.work/api/v1/payment/key');
if (!response.ok) {
throw new Error(`Failed to fetch public key: ${response.statusText}`);
}
const publicKey = await response.json();
console.log('Key ID:', publicKey.kid);
console.log('Key Type:', publicKey.kty);
return publicKey;
}
// Use with Web Crypto API
async function importKey(jwk) {
return await crypto.subtle.importKey(
'jwk',
jwk,
{
name: 'RSA-OAEP',
hash: 'SHA-256'
},
false,
['encrypt']
);
}