@neus/sdk 1.0.12 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +206 -208
- package/cjs/client.cjs +191 -22
- package/cjs/errors.cjs +2 -35
- package/cjs/gates.cjs +1 -21
- package/cjs/index.cjs +203 -22
- package/cjs/utils.cjs +2 -0
- package/cli/neus.mjs +1215 -120
- package/client.js +150 -31
- package/errors.js +154 -189
- package/gates.js +0 -20
- package/index.js +2 -0
- package/package.json +142 -135
- package/sponsor.js +95 -0
- package/types.d.ts +91 -14
- package/utils.js +2 -0
- package/widgets/README.md +1 -1
- package/widgets/verify-gate/dist/ProofBadge.js +8 -16
- package/widgets/verify-gate/dist/VerifyGate.js +28 -15
- package/neus-logo.svg +0 -3
|
@@ -28,7 +28,7 @@ var NeusLogo = ({ size = 12, logoUrl }) => /* @__PURE__ */ jsx(
|
|
|
28
28
|
}
|
|
29
29
|
);
|
|
30
30
|
function ProofBadge({
|
|
31
|
-
qHash
|
|
31
|
+
qHash,
|
|
32
32
|
proofUrlPattern = "/proof/:qHash",
|
|
33
33
|
size = "sm",
|
|
34
34
|
uiLinkBase = "https://neus.network",
|
|
@@ -38,10 +38,8 @@ function ProofBadge({
|
|
|
38
38
|
showLabel = true,
|
|
39
39
|
logoUrl = void 0,
|
|
40
40
|
onClick = void 0,
|
|
41
|
-
className = ""
|
|
42
|
-
...legacyProps
|
|
41
|
+
className = ""
|
|
43
42
|
}) {
|
|
44
|
-
const qHash = qHashProp ?? legacyProps.proofId;
|
|
45
43
|
const resolvedQHash = qHash;
|
|
46
44
|
const [status, setStatus] = useState(() => {
|
|
47
45
|
if (proof) {
|
|
@@ -149,7 +147,7 @@ function ProofBadge({
|
|
|
149
147
|
);
|
|
150
148
|
}
|
|
151
149
|
function SimpleProofBadge({
|
|
152
|
-
qHash
|
|
150
|
+
qHash,
|
|
153
151
|
proofUrlPattern = "/proof/:qHash",
|
|
154
152
|
uiLinkBase = "https://neus.network",
|
|
155
153
|
apiUrl = DEFAULT_API_BASE,
|
|
@@ -158,10 +156,8 @@ function SimpleProofBadge({
|
|
|
158
156
|
logoUrl = void 0,
|
|
159
157
|
proof = void 0,
|
|
160
158
|
onClick = void 0,
|
|
161
|
-
className = ""
|
|
162
|
-
...legacyProps
|
|
159
|
+
className = ""
|
|
163
160
|
}) {
|
|
164
|
-
const qHash = qHashProp ?? legacyProps.proofId;
|
|
165
161
|
const resolvedQHash = qHash;
|
|
166
162
|
const [status, setStatus] = useState(() => {
|
|
167
163
|
if (proof) {
|
|
@@ -244,17 +240,15 @@ function SimpleProofBadge({
|
|
|
244
240
|
);
|
|
245
241
|
}
|
|
246
242
|
function NeusPillLink({
|
|
247
|
-
qHash
|
|
243
|
+
qHash,
|
|
248
244
|
proofUrlPattern = "/proof/:qHash",
|
|
249
245
|
uiLinkBase = "https://neus.network",
|
|
250
246
|
label = "View",
|
|
251
247
|
size = "sm",
|
|
252
248
|
logoUrl = void 0,
|
|
253
249
|
onClick = void 0,
|
|
254
|
-
className = ""
|
|
255
|
-
...legacyProps
|
|
250
|
+
className = ""
|
|
256
251
|
}) {
|
|
257
|
-
const qHash = qHashProp ?? legacyProps.proofId;
|
|
258
252
|
const resolvedQHash = qHash;
|
|
259
253
|
const base = String(uiLinkBase).replace(/\/$/, "");
|
|
260
254
|
const href = resolvedQHash ? `${base}${String(proofUrlPattern).replace(":qHash", resolvedQHash)}` : base;
|
|
@@ -304,17 +298,15 @@ function NeusPillLink({
|
|
|
304
298
|
);
|
|
305
299
|
}
|
|
306
300
|
function VerifiedIcon({
|
|
307
|
-
qHash
|
|
301
|
+
qHash,
|
|
308
302
|
proofUrlPattern = "/proof/:qHash",
|
|
309
303
|
uiLinkBase = "https://neus.network",
|
|
310
304
|
size = 14,
|
|
311
305
|
logoUrl = void 0,
|
|
312
306
|
tooltip = "Proof",
|
|
313
307
|
onClick = void 0,
|
|
314
|
-
className = ""
|
|
315
|
-
...legacyProps
|
|
308
|
+
className = ""
|
|
316
309
|
}) {
|
|
317
|
-
const qHash = qHashProp ?? legacyProps.proofId;
|
|
318
310
|
const resolvedQHash = qHash;
|
|
319
311
|
const href = resolvedQHash ? `${String(uiLinkBase).replace(/\/$/, "")}${String(proofUrlPattern).replace(":qHash", resolvedQHash)}` : void 0;
|
|
320
312
|
const handleClick = (e) => {
|
|
@@ -13,13 +13,25 @@ function buildHostedCheckoutUrl({
|
|
|
13
13
|
origin,
|
|
14
14
|
oauthProvider,
|
|
15
15
|
campaignTitle,
|
|
16
|
-
campaignMessage
|
|
16
|
+
campaignMessage,
|
|
17
|
+
appId,
|
|
18
|
+
billingWallet,
|
|
19
|
+
gateId
|
|
17
20
|
}) {
|
|
18
21
|
const checkoutUrl = new URL(hostedCheckoutUrl);
|
|
19
22
|
checkoutUrl.searchParams.set("verifiers", verifierList.join(","));
|
|
20
23
|
checkoutUrl.searchParams.set("mode", "popup");
|
|
21
24
|
checkoutUrl.searchParams.set("returnUrl", returnUrl);
|
|
22
25
|
checkoutUrl.searchParams.set("origin", origin);
|
|
26
|
+
if (typeof appId === "string" && appId.trim()) {
|
|
27
|
+
checkoutUrl.searchParams.set("appId", appId.trim());
|
|
28
|
+
}
|
|
29
|
+
if (typeof billingWallet === "string" && billingWallet.trim()) {
|
|
30
|
+
checkoutUrl.searchParams.set("billingWallet", billingWallet.trim().toLowerCase());
|
|
31
|
+
}
|
|
32
|
+
if (typeof gateId === "string" && gateId.trim()) {
|
|
33
|
+
checkoutUrl.searchParams.set("gateId", gateId.trim());
|
|
34
|
+
}
|
|
23
35
|
if (typeof oauthProvider === "string" && oauthProvider.trim()) {
|
|
24
36
|
checkoutUrl.searchParams.set("oauthProvider", oauthProvider.trim());
|
|
25
37
|
}
|
|
@@ -124,11 +136,10 @@ function getVerifyGateUserError(err) {
|
|
|
124
136
|
}
|
|
125
137
|
return null;
|
|
126
138
|
}
|
|
127
|
-
function dispatchNeusProofCreatedForHost({ qHash, walletAddress
|
|
139
|
+
function dispatchNeusProofCreatedForHost({ qHash, walletAddress }) {
|
|
128
140
|
try {
|
|
129
141
|
if (typeof window === "undefined") return;
|
|
130
|
-
const raw = typeof qHash === "string"
|
|
131
|
-
"";
|
|
142
|
+
const raw = typeof qHash === "string" ? qHash.trim() : "";
|
|
132
143
|
if (!raw) return;
|
|
133
144
|
const w = typeof walletAddress === "string" ? walletAddress.trim() : "";
|
|
134
145
|
const normalizedWallet = w && /^0x[a-fA-F0-9]{40}$/.test(w) ? w.toLowerCase() : w;
|
|
@@ -187,6 +198,7 @@ function VerifyGate({
|
|
|
187
198
|
onVerified = void 0,
|
|
188
199
|
apiUrl = void 0,
|
|
189
200
|
appId = void 0,
|
|
201
|
+
billingWallet = void 0,
|
|
190
202
|
paymentSignature = void 0,
|
|
191
203
|
extraHeaders = void 0,
|
|
192
204
|
hostedCheckoutUrl = void 0,
|
|
@@ -211,8 +223,7 @@ function VerifyGate({
|
|
|
211
223
|
onError = void 0,
|
|
212
224
|
wallet = void 0,
|
|
213
225
|
chain = void 0,
|
|
214
|
-
signatureMethod = void 0
|
|
215
|
-
...legacyProps
|
|
226
|
+
signatureMethod = void 0
|
|
216
227
|
}) {
|
|
217
228
|
const [state, setState] = useState("idle");
|
|
218
229
|
const [error, setError] = useState(null);
|
|
@@ -222,14 +233,14 @@ function VerifyGate({
|
|
|
222
233
|
const [existingProofs, setExistingProofs] = useState(null);
|
|
223
234
|
const [operation, setOperation] = useState("verify");
|
|
224
235
|
const client = useMemo(
|
|
225
|
-
() => new NeusClient({ apiUrl, appId, paymentSignature, extraHeaders }),
|
|
226
|
-
[apiUrl, appId, paymentSignature, extraHeaders]
|
|
236
|
+
() => new NeusClient({ apiUrl, appId, billingWallet, paymentSignature, extraHeaders }),
|
|
237
|
+
[apiUrl, appId, billingWallet, paymentSignature, extraHeaders]
|
|
227
238
|
);
|
|
228
239
|
const verifierList = useMemo(() => {
|
|
229
240
|
return Array.isArray(requiredVerifiers) && requiredVerifiers.length > 0 ? requiredVerifiers : ["ownership-basic"];
|
|
230
241
|
}, [requiredVerifiers]);
|
|
231
242
|
const primaryVerifier = verifierList[0];
|
|
232
|
-
const qHash = qHashProp ||
|
|
243
|
+
const qHash = qHashProp || null;
|
|
233
244
|
const resolvedQHash = qHash;
|
|
234
245
|
const hasInteractiveVerifier = useMemo(
|
|
235
246
|
() => verifierList.some((verifierId) => {
|
|
@@ -277,7 +288,7 @@ function VerifyGate({
|
|
|
277
288
|
setExistingProofs(gateResult);
|
|
278
289
|
const existingProof = gateResult.existing?.[primaryVerifier];
|
|
279
290
|
if (existingProof && onVerified) {
|
|
280
|
-
const existingQHash = existingProof.qHash ||
|
|
291
|
+
const existingQHash = existingProof.qHash || null;
|
|
281
292
|
onVerified({
|
|
282
293
|
qHash: existingQHash,
|
|
283
294
|
address: existingProof.walletAddress || address,
|
|
@@ -399,7 +410,9 @@ function VerifyGate({
|
|
|
399
410
|
origin,
|
|
400
411
|
oauthProvider,
|
|
401
412
|
campaignTitle,
|
|
402
|
-
campaignMessage
|
|
413
|
+
campaignMessage,
|
|
414
|
+
appId,
|
|
415
|
+
billingWallet
|
|
403
416
|
});
|
|
404
417
|
let expectedOrigin = null;
|
|
405
418
|
try {
|
|
@@ -453,7 +466,7 @@ function VerifyGate({
|
|
|
453
466
|
};
|
|
454
467
|
window.addEventListener("message", onMessage);
|
|
455
468
|
});
|
|
456
|
-
}, [resolvedHostedCheckoutUrl, verifierList, oauthProvider, campaignTitle, campaignMessage]);
|
|
469
|
+
}, [resolvedHostedCheckoutUrl, verifierList, oauthProvider, campaignTitle, campaignMessage, appId, billingWallet]);
|
|
457
470
|
useEffect(() => {
|
|
458
471
|
onStateChange?.(state);
|
|
459
472
|
}, [state, onStateChange]);
|
|
@@ -546,7 +559,7 @@ function VerifyGate({
|
|
|
546
559
|
setState("interactive-checkout");
|
|
547
560
|
onStateChange?.("interactive-checkout");
|
|
548
561
|
const checkoutResult = await launchHostedCheckout();
|
|
549
|
-
const checkoutQHash = checkoutResult?.qHash ||
|
|
562
|
+
const checkoutQHash = checkoutResult?.qHash || null;
|
|
550
563
|
const handoffWallet = typeof checkoutResult?.walletAddress === "string" && checkoutResult.walletAddress.trim() || walletAddress && String(walletAddress).trim() || "";
|
|
551
564
|
setState("verified");
|
|
552
565
|
dispatchNeusProofCreatedForHost({
|
|
@@ -611,7 +624,7 @@ function VerifyGate({
|
|
|
611
624
|
wallet: wallet || (typeof window !== "undefined" ? window.ethereum : void 0)
|
|
612
625
|
});
|
|
613
626
|
setState("verifying");
|
|
614
|
-
const qHashToCheck = created.qHash || created
|
|
627
|
+
const qHashToCheck = created.qHash || created?.data?.qHash;
|
|
615
628
|
const final = await client.pollProofStatus(qHashToCheck, { interval: 3e3, timeout: 6e4 });
|
|
616
629
|
const verifiedVerifiers = final?.data?.verifiedVerifiers || [];
|
|
617
630
|
const verifierResult = verifiedVerifiers.find((v) => v.verifierId === verifierId);
|
|
@@ -621,7 +634,7 @@ function VerifyGate({
|
|
|
621
634
|
const hubTx = final?.data?.hubTransaction || {};
|
|
622
635
|
const crosschain = final?.data?.crosschain || {};
|
|
623
636
|
const txHash = hubTx?.txHash || crosschain?.hubTxHash || null;
|
|
624
|
-
const finalQHash = final?.qHash ||
|
|
637
|
+
const finalQHash = final?.qHash || qHashToCheck;
|
|
625
638
|
return {
|
|
626
639
|
verifierId,
|
|
627
640
|
qHash: finalQHash,
|