import {
signHttpRequest,
importPrivateKey,
} from '@belticlabs/kya';
import fs from 'fs';
// Load the agent's private key
const pemContent = fs.readFileSync('agent-key.pem', 'utf-8');
const privateKey = await importPrivateKey(pemContent, 'EdDSA');
// Sign an HTTP request
const signedHeaders = await signHttpRequest({
method: 'POST',
url: 'https://api.example.com/payments/transfer',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
amount: 100,
currency: 'USD',
recipient: 'acct_123',
}),
privateKey,
keyId: 'agent-key-thumbprint',
keyDirectoryUrl: 'https://api.beltic.dev/v1/agents/agt_xxx/keys',
credentialUrl: 'https://api.beltic.dev/v1/credentials/cred_xxx',
});
// Make the signed request
const response = await fetch('https://api.example.com/payments/transfer', {
method: 'POST',
headers: {
...signedHeaders,
'content-type': 'application/json',
},
body: JSON.stringify({
amount: 100,
currency: 'USD',
recipient: 'acct_123',
}),
});