forked from douglasborthwick-crypto/insumer-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-xrpl.js
More file actions
205 lines (187 loc) · 5.19 KB
/
verify-xrpl.js
File metadata and controls
205 lines (187 loc) · 5.19 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* InsumerAPI — XRPL verification examples
*
* Demonstrates every XRPL verification scenario:
* 1. Native XRP balance check
* 2. RLUSD trust line token verification
* 3. USDC trust line token verification
* 4. Multi-condition (XRP + RLUSD in one call)
* 5. NFT ownership on XRPL
* 6. Trust profile with XRPL dimensions (requires EVM wallet + xrplWallet)
*
* Usage:
* INSUMER_API_KEY=insr_live_... node verify-xrpl.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": "xrpl-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 XRPL issuers
const RLUSD_ISSUER = "rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De";
const USDC_ISSUER = "rGm7WCVp9gb4jZHWTEtGUr4dd74z2XuWhE";
// Demo wallet — replace with any r-address
const XRPL_WALLET = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn";
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(`XRPL wallet: ${XRPL_WALLET}\n`);
// 1. Native XRP balance
printResult(
"1. Native XRP balance (>= 100 XRP)",
await attest({
xrplWallet: XRPL_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: "native",
chainId: "xrpl",
threshold: 100,
label: "XRP >= 100",
},
],
})
);
// 2. RLUSD trust line
printResult(
"2. RLUSD trust line (>= 10 RLUSD)",
await attest({
xrplWallet: XRPL_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: RLUSD_ISSUER,
chainId: "xrpl",
currency: "RLUSD",
threshold: 10,
label: "RLUSD >= 10",
},
],
})
);
// 3. USDC trust line
printResult(
"3. USDC trust line (>= 1 USDC)",
await attest({
xrplWallet: XRPL_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: USDC_ISSUER,
chainId: "xrpl",
currency: "USDC",
threshold: 1,
label: "USDC >= 1",
},
],
})
);
// 4. Multi-condition: XRP + RLUSD in one call
printResult(
"4. Multi-condition: XRP + RLUSD in one call",
await attest({
xrplWallet: XRPL_WALLET,
conditions: [
{
type: "token_balance",
contractAddress: "native",
chainId: "xrpl",
threshold: 50,
label: "XRP >= 50",
},
{
type: "token_balance",
contractAddress: RLUSD_ISSUER,
chainId: "xrpl",
currency: "RLUSD",
threshold: 10,
label: "RLUSD >= 10",
},
],
})
);
// 5. NFT ownership
// Replace with a real XRPL NFT issuer r-address
printResult(
"5. NFT ownership on XRPL",
await attest({
xrplWallet: XRPL_WALLET,
conditions: [
{
type: "nft_ownership",
contractAddress: "rExampleNFTIssuerAddress",
chainId: "xrpl",
label: "XRPL NFT holder",
},
],
})
);
// 6. Wallet trust profile with XRPL dimensions
// Trust profiles require an EVM wallet as the base. Pass xrplWallet
// to add XRPL-specific dimensions (RLUSD, USDC trust lines).
printResult(
"6. Trust profile with XRPL dimensions",
await trust({
wallet: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
xrplWallet: XRPL_WALLET,
})
);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});