-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchittyid-client.js
More file actions
52 lines (43 loc) · 1.4 KB
/
chittyid-client.js
File metadata and controls
52 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// ChittyID Service Client
const CHITTYID_SERVICE = process.env.CHITTYID_SERVICE_URL || 'https://id.chitty.cc';
class ChittyIDClient {
constructor(token) {
this.token = token || process.env.CHITTY_ID_TOKEN;
if (!this.token) {
throw new Error('CHITTY_ID_TOKEN required');
}
}
async mint(domain, subtype, metadata = {}) {
const response = await fetch(`${CHITTYID_SERVICE}/v1/mint`, {
method: 'POST',
headers: {
'authorization': `Bearer ${this.token}`,
'content-type': 'application/json'
},
body: JSON.stringify({ domain, subtype, metadata })
});
if (!response.ok) {
const error = await response.text();
throw new Error(`ChittyID mint failed: ${response.status} - ${error}`);
}
const data = await response.json();
return data.chitty_id;
}
async validate(chittyId) {
const response = await fetch(`${CHITTYID_SERVICE}/v1/validate/${chittyId}`, {
headers: { 'authorization': `Bearer ${this.token}` }
});
return response.ok;
}
async lookup(chittyId) {
const response = await fetch(`${CHITTYID_SERVICE}/v1/lookup/${chittyId}`, {
headers: { 'authorization': `Bearer ${this.token}` }
});
if (!response.ok) {
throw new Error(`ChittyID lookup failed: ${response.status}`);
}
return response.json();
}
}
module.exports = { ChittyIDClient };
// For ES6: export { ChittyIDClient };