接入教程
1. 访问Chainpoint官网注册账户
2. 获取API密钥和访问凭证
3. 通过API提交需要锚定的数据
4. 等待区块链确认并获取证明
5. 使用证明验证数据完整性和时间戳
Python发送哈希到Chainpoint
python
import requests
import json
# 准备数据
base_url = 'https://api.chainpoint.org'
headers = {
'Content-Type': 'application/json'
}
payload = {
'hashes': [
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
]
}
try:
response = requests.post(f'{base_url}/hashes', headers=headers, data=json.dumps(payload))
response.raise_for_status()
result = response.json()
print('提交成功:', result)
except requests.exceptions.RequestException as e:
print('请求失败:', e)
PHP获取锚定证明
php
<?php
$baseUrl = 'https://api.chainpoint.org';
$proofId = 'your_proof_id_here';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $baseUrl . '/proofs/' . $proofId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo '请求错误: ' . curl_error($ch);
} else {
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
$data = json_decode($response, true);
echo '证明数据: ' . json_encode($data, JSON_PRETTY_PRINT);
} else {
echo 'HTTP错误: ' . $httpCode;
}
}
curl_close($ch);
?>
JavaScript验证证明
javascript
const baseUrl = 'https://api.chainpoint.org';
const proofId = 'your_proof_id_here';
async function verifyProof() {
try {
const response = await fetch(`${baseUrl}/proofs/${proofId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const proofData = await response.json();
console.log('验证结果:', proofData);
// 此处可添加本地验证逻辑
return proofData;
} catch (error) {
console.error('验证失败:', error);
throw error;
}
}
// 调用函数
verifyProof();
常见问题
Chainpoint API是否需要API密钥?
Chainpoint公开API通常不需要API密钥即可提交哈希和检索证明。但某些高级功能或商业用途可能需要身份验证,请参考官方文档获取最新信息。
提交哈希后多久可以获得区块链锚定证明?
时间取决于网络状况和区块链确认速度。通常提交后几分钟内可获得初始收据,完整的比特币区块链锚定证明可能需要1-2小时或更长时间。
Chainpoint支持哪些哈希算法?
Chainpoint主要支持SHA-256哈希算法。提交的哈希值应为十六进制格式的SHA-256哈希。请确保使用标准哈希算法生成待锚定数据的哈希。
Aitishiku.com