Repository navigation
Expand file tree
/
Copy pathverify-tron.js
More file actions
165 lines (149 loc) · 4.31 KB
/
Copy pathverify-tron.js
File metadata and controls
165 lines (149 loc) · 4.31 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* InsumerAPI — Tron verification examples
*
* Demonstrates Tron verification scenarios:
* 1. Native TRX balance check
* 2. USDT-TRC20 token balance
* 3. Multi-condition (TRX + USDT-TRC20 in one call)
* 4. Trust profile with Tron dimension (requires EVM wallet + tronWallet)
*
* Usage:
* INSUMER_API_KEY=insr_live_... node verify-tron.js
*
* Get a free key:
* curl -X POST https://api.insumermodel.com/v1/keys/create \
* -H "Content-Type: application/json" \
* -d '{"email": "you@example.com", "appName": "tron-demo", "tier": "free"}'
*/
const API = "https://api.insumermodel.com";
const KEY = process.env.INSUMER_API_KEY;
if (!KEY) {
console.error("Set INSUMER_API_KEY environment variable");
process.exit(1);
}
const headers = { "Content-Type": "application/json", "X-API-Key": KEY };
// Well-known Tron contracts
const USDT_TRC20 = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
// Demo wallet — Binance hot wallet, holds USDT-TRC20. Replace with any T-address.
const TRON_WALLET = "TAUN6FwrnwwmaEqYcckffC7wYmbaS6cBiX";
async function attest(body) {
const res = await fetch(`${API}/v1/attest`, {
method: "POST",
headers,
body: JSON.stringify(body),
});
return res.json();
}
async function trust(body) {
const res = await fetch(`${API}/v1/trust`, {
method: "POST",
headers,
body: JSON.stringify(body),
});
return res.json();
}
function printResult(label, result) {
console.log(`\n${"=".repeat(60)}`);
console.log(label);
console.log("=".repeat(60));
if (!result.ok) {
console.log("Error:", result.error || result.message || "Unknown error");
return;
}
if (result.data.attestation) {
const { pass, results } = result.data.attestation;
console.log(`Pass: ${pass}`);
for (const r of results) {
console.log(` ${r.label}: ${r.met ? "PASS" : "FAIL"}`);
}
console.log(`Signature: ${result.data.sig.slice(0, 50)}...`);
} else if (result.data.trust) {
const tp = result.data.trust;
console.log(`Trust ID: ${tp.id}`);
const dims = Object.keys(tp.dimensions);
console.log(`Dimensions: ${dims.length}`);
for (const name of dims) {
const dim = tp.dimensions[name];
console.log(` ${name}: ${dim.passCount}/${dim.total} passed`);
for (const c of dim.checks) {
console.log(` ${c.met ? "[+]" : "[-]"} ${c.label}`);
}
}
console.log(`Overall: ${tp.summary.totalPassed}/${tp.summary.totalChecks} checks passed`);
console.log(`Signature: ${result.data.sig.slice(0, 50)}...`);
} else {
console.log(JSON.stringify(result.data, null, 2));
}
}
async function main() {
console.log(`Tron wallet: ${TRON_WALLET}\n`);
// 1. Native TRX balance
printResult(
"1. Native TRX balance (>= 1 TRX)",
await attest({
tronWallet: TRON_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: "native",
chainId: "tron",
threshold: "1",
label: "TRX >= 1",
},
],
})
);
// 2. USDT-TRC20
printResult(
"2. USDT-TRC20 balance (>= 1 USDT)",
await attest({
tronWallet: TRON_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: USDT_TRC20,
chainId: "tron",
threshold: "1",
label: "USDT-TRC20 >= 1",
},
],
})
);
// 3. Multi-condition: TRX + USDT-TRC20 in one call
printResult(
"3. Multi-condition: TRX + USDT-TRC20 in one call",
await attest({
tronWallet: TRON_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: "native",
chainId: "tron",
threshold: "1",
label: "TRX >= 1",
},
{
type: "token_balance",
contractAddress: USDT_TRC20,
chainId: "tron",
threshold: "1",
label: "USDT-TRC20 >= 1",
},
],
})
);
// 4. Wallet trust profile with Tron dimension
// Trust profiles require an EVM wallet as the base. Pass tronWallet
// to add the tron dimension: three checks (USDT, USD1, WBTC on Tron).
printResult(
"4. Trust profile with Tron dimension",
await trust({
wallet: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
tronWallet: TRON_WALLET,
})
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});