import { createHash } from 'crypto';
const API_URL = process.env.TREESHIP_API_URL || 'https://api.treeship.dev';
const API_KEY = process.env.TREESHIP_API_KEY;
async function attest(action, inputsHash) {
const res = await fetch(`${API_URL}/v1/attest`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
agent_slug: process.env.TREESHIP_AGENT,
action,
inputs_hash: inputsHash,
}),
});
if (!res.ok) throw new Error(`Attestation failed: ${res.status}`);
return res.json();
}
// Usage
const hash = createHash('sha256')
.update(JSON.stringify(inputData))
.digest('hex');
const result = await attest('Processed order #123', hash);
console.log(`Verify at: ${result.public_url}`);