Repository navigation
Expand file tree
/
Copy pathverify-sui.js
More file actions
173 lines (157 loc) · 4.76 KB
/
Copy pathverify-sui.js
File metadata and controls
173 lines (157 loc) · 4.76 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
166
167
168
169
170
171
172
173
/**
* InsumerAPI — Sui verification examples
*
* Demonstrates Sui verification scenarios:
* 1. Native SUI balance check
* 2. USDC on Sui (Sui-native token) balance
* 3. Multi-condition (SUI + USDC in one call)
* 4. Trust profile with Sui rows evaluated (requires EVM wallet + suiWallet)
*
* Sui conditions take a coin type (`address::module::Name`) as `contractAddress`:
* "0x2::sui::SUI" for native SUI, "0xdba34672...::usdc::USDC" for USDC.
*
* Usage:
* INSUMER_API_KEY=insr_live_... node verify-sui.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": "sui-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 Sui coin type strings. Native SUI is a coin type too: the string
// "native" is not accepted on Sui.
const SUI_NATIVE = "0x2::sui::SUI";
const USDC_SUI = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
// Demo wallet — Sui Foundation address `0x5` (always has SUI + USDC).
// Replace with any Sui address (0x + 64 hex).
const SUI_WALLET = "0x0000000000000000000000000000000000000000000000000000000000000005";
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(`Sui wallet: ${SUI_WALLET}\n`);
// 1. Native SUI
printResult(
"1. Native SUI balance (>= 1 SUI)",
await attest({
suiWallet: SUI_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: SUI_NATIVE,
chainId: "sui",
threshold: "1",
label: "SUI >= 1",
},
],
})
);
// 2. USDC on Sui
printResult(
"2. USDC on Sui (>= 1 USDC)",
await attest({
suiWallet: SUI_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: USDC_SUI,
chainId: "sui",
threshold: "1",
label: "USDC on Sui >= 1",
},
],
})
);
// 3. Multi-condition: SUI + USDC in one call
printResult(
"3. Multi-condition: SUI + USDC in one call",
await attest({
suiWallet: SUI_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: SUI_NATIVE,
chainId: "sui",
threshold: "1",
label: "SUI >= 1",
},
{
type: "token_balance",
contractAddress: USDC_SUI,
chainId: "sui",
threshold: "1",
label: "USDC >= 1",
},
],
})
);
// 4. Wallet trust profile with Sui rows evaluated
// Trust profiles require an EVM wallet as the base. Pass suiWallet
// to evaluate the Sui rows that sit inside the base dimensions (USDC in
// institutional_stablecoins, USDY in tokenized_treasuries). Sui adds no
// dimension of its own.
printResult(
"4. Trust profile with Sui rows evaluated",
await trust({
wallet: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
suiWallet: SUI_WALLET,
})
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});