@entros/verify 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Entros Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # `@entros/verify`
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@entros/verify.svg)](https://www.npmjs.com/package/@entros/verify)
4
+
5
+ Drop-in React component for Entros verification on Solana. Click → popup window opens to entros.io → user completes wallet-connected verification → component fires `onVerified` with the on-chain attestation reference.
6
+
7
+ Source: [github.com/entros-protocol/entros-verify](https://github.com/entros-protocol/entros-verify) · Hosted by [entros.io](https://entros.io).
8
+
9
+ ```bash
10
+ npm install @entros/verify
11
+ ```
12
+
13
+ ## Five-line usage
14
+
15
+ ```tsx
16
+ import { EntrosVerify } from "@entros/verify";
17
+
18
+ <EntrosVerify
19
+ integratorKey="your-integrator-key"
20
+ onVerified={(result) => unlockClaim(result.walletPubkey)}
21
+ />
22
+ ```
23
+
24
+ ## Result shape
25
+
26
+ ```ts
27
+ interface EntrosVerifyResult {
28
+ walletPubkey: string; // base58 Solana pubkey
29
+ attestationPda: string; // base58 SAS attestation PDA
30
+ txSig: string; // base58 verification tx signature
31
+ trustScore: number; // current Trust Score (0–10000)
32
+ cluster: "devnet" | "mainnet-beta";
33
+ }
34
+ ```
35
+
36
+ Read the on-chain attestation from any Solana program or client. No API keys, no escrow, no per-call billing.
37
+
38
+ ## Full API
39
+
40
+ ```tsx
41
+ <EntrosVerify
42
+ integratorKey="jupiter" // required, registered with Entros
43
+ cluster="devnet" // "devnet" | "mainnet-beta", default "devnet"
44
+ minTrustScore={200} // optional gate
45
+ popupWidth={480} // CSS px, default 480
46
+ popupHeight={720} // CSS px, default 720
47
+ timeoutMs={5 * 60 * 1000} // 5 min default
48
+ popupBlockedFallback={true} // inline retry UI when popup blocked
49
+ className="..." // applied to trigger button
50
+ style={{ ... }}
51
+ onVerified={(r) => {}} // required
52
+ onError={(e) => {}} // optional — covers cancel, reject, timeout, etc.
53
+ onProgress={(p) => {}} // optional — heartbeats from popup
54
+ >
55
+ Verify with Entros {/* custom button content */}
56
+ </EntrosVerify>
57
+ ```
58
+
59
+ ## Error reasons
60
+
61
+ `onError` receives one of:
62
+
63
+ - `wallet_rejected` — user denied wallet connection or signing
64
+ - `validation_failed` — verification did not pass server-side checks
65
+ - `network_error` — popup encountered a network failure mid-flow
66
+ - `user_canceled` — user closed the popup before completing
67
+ - `origin_invalid` — integrator origin was not on the Entros allowlist
68
+ - `popup_blocked` — browser blocked `window.open()`
69
+ - `timeout` — popup remained open longer than `timeoutMs` without completing
70
+ - `unknown` — fallback for unexpected failure modes
71
+
72
+ Specific server-side rejection signals are deliberately not surfaced to the client.
73
+
74
+ ## v1 limitations
75
+
76
+ - Devnet only. Mainnet support lands in v2.
77
+ - Hardcoded integrator allowlist on the entros.io side. Self-serve integrator onboarding lands in v2.
78
+ - Mobile browsers may open the popup as a new tab rather than a windowed popup. Mobile-Wallet-Adapter-aware mobile flow lands in v1.5.
79
+
80
+ ## Production-readiness
81
+
82
+ - Origin gate on every postMessage (`event.origin === "https://entros.io"`)
83
+ - Replay protection via per-popup `request_id`
84
+ - 5-minute timeout
85
+ - Popup-blocked fallback with user-gesture retry
86
+ - Idempotent cancel
87
+ - React 19 typed strict-mode
88
+
89
+ ## License
90
+
91
+ MIT.
@@ -0,0 +1,91 @@
1
+ import { ReactNode, CSSProperties, ReactElement } from 'react';
2
+
3
+ /**
4
+ * Public type surface for `@entros/verify`.
5
+ *
6
+ * Wire format (popup → parent via postMessage) uses snake_case
7
+ * (`wallet_pubkey`); the JS API surfaced to integrators uses camelCase
8
+ * (`walletPubkey`). The popup-manager layer translates between them.
9
+ */
10
+ type Cluster = "devnet" | "mainnet-beta";
11
+ /** Result delivered to the integrator's onVerified callback. */
12
+ interface EntrosVerifyResult {
13
+ walletPubkey: string;
14
+ attestationPda: string;
15
+ txSig: string;
16
+ trustScore: number;
17
+ cluster: Cluster;
18
+ }
19
+ /**
20
+ * Opaque error categories. Specific server-side reason codes never reach
21
+ * the client (per the public-copy specificity rule in the org).
22
+ */
23
+ type EntrosVerifyErrorReason = "wallet_rejected" | "validation_failed" | "network_error" | "user_canceled" | "origin_invalid" | "popup_blocked" | "timeout" | "unknown";
24
+ interface EntrosVerifyError {
25
+ reason: EntrosVerifyErrorReason;
26
+ }
27
+ type EntrosVerifyProgressStatus = "wallet_connecting" | "capturing" | "proving" | "submitting" | "attesting";
28
+ interface EntrosVerifyProgress {
29
+ status: EntrosVerifyProgressStatus;
30
+ }
31
+
32
+ /**
33
+ * <EntrosVerify> — drop-in trigger for the Entros verification popup.
34
+ *
35
+ * Renders a button. On click, opens a popup window to entros.io. User
36
+ * completes wallet-connected verification inside the popup; the popup
37
+ * posts the result back via postMessage; this component fires the
38
+ * integrator's onVerified callback.
39
+ *
40
+ * See README and `EntrosVerifyProps` for usage.
41
+ */
42
+
43
+ interface EntrosVerifyProps {
44
+ /** Integrator key registered with Entros. Required. */
45
+ integratorKey: string;
46
+ /** Solana cluster. Defaults to "devnet". v1 supports devnet only. */
47
+ cluster?: Cluster;
48
+ /**
49
+ * Optional Trust Score floor. The popup runs the verification regardless
50
+ * and reports the result; if `minTrustScore` is set and the resulting
51
+ * score is below it, the popup posts `entros/error` with reason
52
+ * `validation_failed` instead of `entros/verified`.
53
+ */
54
+ minTrustScore?: number;
55
+ /** Called on successful verification. Required. */
56
+ onVerified: (result: EntrosVerifyResult) => void;
57
+ /** Called on any failure or cancellation. Optional. */
58
+ onError?: (error: EntrosVerifyError) => void;
59
+ /** Called on progress heartbeats from the popup. Optional. */
60
+ onProgress?: (progress: EntrosVerifyProgress) => void;
61
+ /** Popup width in CSS pixels. Defaults to 480. */
62
+ popupWidth?: number;
63
+ /** Popup height in CSS pixels. Defaults to 720. */
64
+ popupHeight?: number;
65
+ /**
66
+ * Maximum time the popup is allowed to be open before this component
67
+ * fires onError({reason: "timeout"}). Defaults to 5 minutes.
68
+ */
69
+ timeoutMs?: number;
70
+ /** Custom button content. Defaults to "Verify with Entros". */
71
+ children?: ReactNode;
72
+ /** className applied to the trigger button. */
73
+ className?: string;
74
+ /** Inline style applied to the trigger button. */
75
+ style?: CSSProperties;
76
+ /**
77
+ * If true, when the popup is blocked the component renders an inline
78
+ * retry button. Clicking it triggers a fresh window.open from a confirmed
79
+ * user gesture, which most browsers allow. Defaults to true.
80
+ */
81
+ popupBlockedFallback?: boolean;
82
+ /**
83
+ * INTERNAL: Override the entros.io base origin. Intended for end-to-end
84
+ * testing against a localhost popup host. Production consumers should
85
+ * not set this.
86
+ */
87
+ baseOrigin?: string;
88
+ }
89
+ declare function EntrosVerify(props: EntrosVerifyProps): ReactElement;
90
+
91
+ export { type Cluster, EntrosVerify, type EntrosVerifyError, type EntrosVerifyErrorReason, type EntrosVerifyProgress, type EntrosVerifyProgressStatus, type EntrosVerifyProps, type EntrosVerifyResult };
@@ -0,0 +1,91 @@
1
+ import { ReactNode, CSSProperties, ReactElement } from 'react';
2
+
3
+ /**
4
+ * Public type surface for `@entros/verify`.
5
+ *
6
+ * Wire format (popup → parent via postMessage) uses snake_case
7
+ * (`wallet_pubkey`); the JS API surfaced to integrators uses camelCase
8
+ * (`walletPubkey`). The popup-manager layer translates between them.
9
+ */
10
+ type Cluster = "devnet" | "mainnet-beta";
11
+ /** Result delivered to the integrator's onVerified callback. */
12
+ interface EntrosVerifyResult {
13
+ walletPubkey: string;
14
+ attestationPda: string;
15
+ txSig: string;
16
+ trustScore: number;
17
+ cluster: Cluster;
18
+ }
19
+ /**
20
+ * Opaque error categories. Specific server-side reason codes never reach
21
+ * the client (per the public-copy specificity rule in the org).
22
+ */
23
+ type EntrosVerifyErrorReason = "wallet_rejected" | "validation_failed" | "network_error" | "user_canceled" | "origin_invalid" | "popup_blocked" | "timeout" | "unknown";
24
+ interface EntrosVerifyError {
25
+ reason: EntrosVerifyErrorReason;
26
+ }
27
+ type EntrosVerifyProgressStatus = "wallet_connecting" | "capturing" | "proving" | "submitting" | "attesting";
28
+ interface EntrosVerifyProgress {
29
+ status: EntrosVerifyProgressStatus;
30
+ }
31
+
32
+ /**
33
+ * <EntrosVerify> — drop-in trigger for the Entros verification popup.
34
+ *
35
+ * Renders a button. On click, opens a popup window to entros.io. User
36
+ * completes wallet-connected verification inside the popup; the popup
37
+ * posts the result back via postMessage; this component fires the
38
+ * integrator's onVerified callback.
39
+ *
40
+ * See README and `EntrosVerifyProps` for usage.
41
+ */
42
+
43
+ interface EntrosVerifyProps {
44
+ /** Integrator key registered with Entros. Required. */
45
+ integratorKey: string;
46
+ /** Solana cluster. Defaults to "devnet". v1 supports devnet only. */
47
+ cluster?: Cluster;
48
+ /**
49
+ * Optional Trust Score floor. The popup runs the verification regardless
50
+ * and reports the result; if `minTrustScore` is set and the resulting
51
+ * score is below it, the popup posts `entros/error` with reason
52
+ * `validation_failed` instead of `entros/verified`.
53
+ */
54
+ minTrustScore?: number;
55
+ /** Called on successful verification. Required. */
56
+ onVerified: (result: EntrosVerifyResult) => void;
57
+ /** Called on any failure or cancellation. Optional. */
58
+ onError?: (error: EntrosVerifyError) => void;
59
+ /** Called on progress heartbeats from the popup. Optional. */
60
+ onProgress?: (progress: EntrosVerifyProgress) => void;
61
+ /** Popup width in CSS pixels. Defaults to 480. */
62
+ popupWidth?: number;
63
+ /** Popup height in CSS pixels. Defaults to 720. */
64
+ popupHeight?: number;
65
+ /**
66
+ * Maximum time the popup is allowed to be open before this component
67
+ * fires onError({reason: "timeout"}). Defaults to 5 minutes.
68
+ */
69
+ timeoutMs?: number;
70
+ /** Custom button content. Defaults to "Verify with Entros". */
71
+ children?: ReactNode;
72
+ /** className applied to the trigger button. */
73
+ className?: string;
74
+ /** Inline style applied to the trigger button. */
75
+ style?: CSSProperties;
76
+ /**
77
+ * If true, when the popup is blocked the component renders an inline
78
+ * retry button. Clicking it triggers a fresh window.open from a confirmed
79
+ * user gesture, which most browsers allow. Defaults to true.
80
+ */
81
+ popupBlockedFallback?: boolean;
82
+ /**
83
+ * INTERNAL: Override the entros.io base origin. Intended for end-to-end
84
+ * testing against a localhost popup host. Production consumers should
85
+ * not set this.
86
+ */
87
+ baseOrigin?: string;
88
+ }
89
+ declare function EntrosVerify(props: EntrosVerifyProps): ReactElement;
90
+
91
+ export { type Cluster, EntrosVerify, type EntrosVerifyError, type EntrosVerifyErrorReason, type EntrosVerifyProgress, type EntrosVerifyProgressStatus, type EntrosVerifyProps, type EntrosVerifyResult };
package/dist/index.js ADDED
@@ -0,0 +1,390 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ EntrosVerify: () => EntrosVerify
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/EntrosVerify.tsx
29
+ var import_react = require("react");
30
+
31
+ // src/messaging.ts
32
+ var MAX_TIMESTAMP_DRIFT_MS = 90 * 1e3;
33
+ var ERROR_REASONS = /* @__PURE__ */ new Set([
34
+ "wallet_rejected",
35
+ "validation_failed",
36
+ "network_error",
37
+ "user_canceled",
38
+ "origin_invalid",
39
+ "popup_blocked",
40
+ "timeout",
41
+ "unknown"
42
+ ]);
43
+ var HEARTBEAT_STATUSES = /* @__PURE__ */ new Set([
44
+ "wallet_connecting",
45
+ "capturing",
46
+ "proving",
47
+ "submitting",
48
+ "attesting"
49
+ ]);
50
+ var ENTROS_MESSAGE_TYPES = /* @__PURE__ */ new Set([
51
+ "entros/verified",
52
+ "entros/error",
53
+ "entros/heartbeat"
54
+ ]);
55
+ var CLUSTERS = /* @__PURE__ */ new Set(["devnet", "mainnet-beta"]);
56
+ function isEntrosMessage(data) {
57
+ if (typeof data !== "object" || data === null) return false;
58
+ const msg = data;
59
+ return msg.source === "entros" && msg.version === 1 && typeof msg.type === "string" && ENTROS_MESSAGE_TYPES.has(msg.type) && typeof msg.request_id === "string" && msg.request_id.length > 0 && typeof msg.timestamp === "number" && Number.isFinite(msg.timestamp) && "payload" in msg;
60
+ }
61
+ function isFreshMessage(msg, now = Date.now()) {
62
+ return Math.abs(now - msg.timestamp) < MAX_TIMESTAMP_DRIFT_MS;
63
+ }
64
+ function isVerifiedPayload(payload) {
65
+ if (typeof payload !== "object" || payload === null) return false;
66
+ const p = payload;
67
+ return typeof p.wallet_pubkey === "string" && p.wallet_pubkey.length > 0 && typeof p.attestation_pda === "string" && p.attestation_pda.length > 0 && typeof p.tx_sig === "string" && p.tx_sig.length > 0 && typeof p.trust_score === "number" && Number.isFinite(p.trust_score) && p.trust_score >= 0 && typeof p.cluster === "string" && CLUSTERS.has(p.cluster);
68
+ }
69
+ function isErrorPayload(payload) {
70
+ if (typeof payload !== "object" || payload === null) return false;
71
+ const p = payload;
72
+ return typeof p.reason === "string" && ERROR_REASONS.has(p.reason);
73
+ }
74
+ function isHeartbeatPayload(payload) {
75
+ if (typeof payload !== "object" || payload === null) return false;
76
+ const p = payload;
77
+ return typeof p.status === "string" && HEARTBEAT_STATUSES.has(p.status);
78
+ }
79
+
80
+ // src/url.ts
81
+ var VALID_INTEGRATOR_KEY = /^[a-z0-9_-]{1,64}$/;
82
+ var ORIGIN_PATTERN = /^https?:\/\/[^/]+$/;
83
+ function buildPopupUrl(opts) {
84
+ if (!VALID_INTEGRATOR_KEY.test(opts.integratorKey)) {
85
+ throw new Error(
86
+ `Invalid integratorKey: must match /^[a-z0-9_-]{1,64}$/ (got "${opts.integratorKey}")`
87
+ );
88
+ }
89
+ if (!ORIGIN_PATTERN.test(opts.parentOrigin)) {
90
+ throw new Error(
91
+ `Invalid parentOrigin: must be a fully-qualified origin (got "${opts.parentOrigin}")`
92
+ );
93
+ }
94
+ if (opts.minTrustScore !== void 0) {
95
+ if (!Number.isInteger(opts.minTrustScore) || opts.minTrustScore < 0 || opts.minTrustScore > 1e4) {
96
+ throw new Error(
97
+ `Invalid minTrustScore: must be an integer in [0, 10000] (got ${String(opts.minTrustScore)})`
98
+ );
99
+ }
100
+ }
101
+ const url = new URL("/embed/verify-popup", opts.baseOrigin);
102
+ url.searchParams.set("integrator", opts.integratorKey);
103
+ url.searchParams.set("parent_origin", opts.parentOrigin);
104
+ url.searchParams.set("cluster", opts.cluster);
105
+ url.searchParams.set("request_id", opts.requestId);
106
+ if (opts.minTrustScore !== void 0) {
107
+ url.searchParams.set("min_trust_score", String(opts.minTrustScore));
108
+ }
109
+ return url.toString();
110
+ }
111
+ function generateRequestId() {
112
+ if (typeof crypto === "undefined") {
113
+ throw new Error(
114
+ "crypto is unavailable in this environment; @entros/verify requires a secure context"
115
+ );
116
+ }
117
+ if (typeof crypto.randomUUID === "function") {
118
+ return crypto.randomUUID();
119
+ }
120
+ if (typeof crypto.getRandomValues !== "function") {
121
+ throw new Error(
122
+ "crypto.getRandomValues is unavailable; @entros/verify requires a secure context"
123
+ );
124
+ }
125
+ const bytes = new Uint8Array(16);
126
+ crypto.getRandomValues(bytes);
127
+ bytes[6] = (bytes[6] ?? 0) & 15 | 64;
128
+ bytes[8] = (bytes[8] ?? 0) & 63 | 128;
129
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
130
+ return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 16).join("");
131
+ }
132
+
133
+ // src/popup-manager.ts
134
+ var DEFAULT_TIMEOUT_MS = 5 * 60 * 1e3;
135
+ var POPUP_CLOSED_POLL_MS = 500;
136
+ var POPUP_CLOSED_GRACE_MS = 1500;
137
+ var POPUP_OWNED_FALLBACK_CLOSE_MS = 3e4;
138
+ function openVerifyPopup(opts) {
139
+ if (typeof window === "undefined") {
140
+ throw new Error("openVerifyPopup must be called in a browser context");
141
+ }
142
+ const requestId = generateRequestId();
143
+ const parentOrigin = window.location.origin;
144
+ const url = buildPopupUrl({
145
+ baseOrigin: opts.baseOrigin,
146
+ integratorKey: opts.integratorKey,
147
+ parentOrigin,
148
+ cluster: opts.cluster,
149
+ requestId,
150
+ minTrustScore: opts.minTrustScore
151
+ });
152
+ const left = Math.max(
153
+ 0,
154
+ Math.floor((window.screen.availWidth - opts.popupWidth) / 2)
155
+ );
156
+ const top = Math.max(
157
+ 0,
158
+ Math.floor((window.screen.availHeight - opts.popupHeight) / 2)
159
+ );
160
+ const features = [
161
+ `width=${opts.popupWidth}`,
162
+ `height=${opts.popupHeight}`,
163
+ `left=${left}`,
164
+ `top=${top}`,
165
+ "menubar=no",
166
+ "toolbar=no",
167
+ // location=yes lets the user verify entros.io in the URL bar.
168
+ "location=yes",
169
+ "status=no",
170
+ "resizable=yes",
171
+ "scrollbars=yes"
172
+ ].join(",");
173
+ const popupName = `entros_verify_${requestId}`;
174
+ const rawPopup = window.open(url, popupName, features);
175
+ if (!rawPopup || rawPopup.closed) {
176
+ return null;
177
+ }
178
+ const popup = rawPopup;
179
+ const expectedPopupOrigin = new URL(opts.baseOrigin).origin;
180
+ let settled = false;
181
+ let pollTimerId = null;
182
+ let timeoutTimerId = null;
183
+ let popupClosedAtMs = null;
184
+ function clearListenersAndTimers() {
185
+ window.removeEventListener("message", onMessage);
186
+ if (pollTimerId !== null) {
187
+ clearInterval(pollTimerId);
188
+ pollTimerId = null;
189
+ }
190
+ if (timeoutTimerId !== null) {
191
+ clearTimeout(timeoutTimerId);
192
+ timeoutTimerId = null;
193
+ }
194
+ }
195
+ function forceClosePopup() {
196
+ if (popup && !popup.closed) {
197
+ try {
198
+ popup.close();
199
+ } catch {
200
+ }
201
+ }
202
+ }
203
+ function settleVerified(result) {
204
+ if (settled) return;
205
+ settled = true;
206
+ clearListenersAndTimers();
207
+ setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);
208
+ opts.onVerified(result);
209
+ }
210
+ function settleError(reason, forceImmediateClose = false) {
211
+ if (settled) return;
212
+ settled = true;
213
+ clearListenersAndTimers();
214
+ if (forceImmediateClose) {
215
+ forceClosePopup();
216
+ } else {
217
+ setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);
218
+ }
219
+ opts.onError({ reason });
220
+ }
221
+ function onMessage(event) {
222
+ if (settled) return;
223
+ if (event.origin !== expectedPopupOrigin) return;
224
+ if (event.source !== popup) return;
225
+ if (!isEntrosMessage(event.data)) return;
226
+ if (event.data.request_id !== requestId) return;
227
+ if (!isFreshMessage(event.data)) return;
228
+ switch (event.data.type) {
229
+ case "entros/verified": {
230
+ if (isVerifiedPayload(event.data.payload)) {
231
+ settleVerified({
232
+ walletPubkey: event.data.payload.wallet_pubkey,
233
+ attestationPda: event.data.payload.attestation_pda,
234
+ txSig: event.data.payload.tx_sig,
235
+ trustScore: event.data.payload.trust_score,
236
+ cluster: event.data.payload.cluster
237
+ });
238
+ }
239
+ break;
240
+ }
241
+ case "entros/error": {
242
+ if (isErrorPayload(event.data.payload)) {
243
+ settleError(event.data.payload.reason);
244
+ }
245
+ break;
246
+ }
247
+ case "entros/heartbeat": {
248
+ if (isHeartbeatPayload(event.data.payload) && opts.onProgress) {
249
+ opts.onProgress({ status: event.data.payload.status });
250
+ }
251
+ break;
252
+ }
253
+ }
254
+ }
255
+ function onPoll() {
256
+ if (settled) return;
257
+ if (popup.closed) {
258
+ if (popupClosedAtMs === null) {
259
+ popupClosedAtMs = Date.now();
260
+ return;
261
+ }
262
+ if (Date.now() - popupClosedAtMs >= POPUP_CLOSED_GRACE_MS) {
263
+ settleError("user_canceled", true);
264
+ }
265
+ } else {
266
+ popupClosedAtMs = null;
267
+ }
268
+ }
269
+ function onTimeout() {
270
+ settleError("timeout", true);
271
+ }
272
+ window.addEventListener("message", onMessage);
273
+ pollTimerId = setInterval(onPoll, POPUP_CLOSED_POLL_MS);
274
+ timeoutTimerId = setTimeout(onTimeout, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
275
+ return {
276
+ cancel: () => settleError("user_canceled", true)
277
+ };
278
+ }
279
+
280
+ // src/EntrosVerify.tsx
281
+ var import_jsx_runtime = require("react/jsx-runtime");
282
+ var DEFAULT_BASE_ORIGIN = "https://entros.io";
283
+ var DEFAULT_POPUP_WIDTH = 480;
284
+ var DEFAULT_POPUP_HEIGHT = 720;
285
+ var SETTLE_RESET_MS = 1500;
286
+ function EntrosVerify(props) {
287
+ const [state, setState] = (0, import_react.useState)({ kind: "idle" });
288
+ const handleRef = (0, import_react.useRef)(null);
289
+ const resetTimerRef = (0, import_react.useRef)(null);
290
+ const onVerifiedRef = (0, import_react.useRef)(props.onVerified);
291
+ const onErrorRef = (0, import_react.useRef)(props.onError);
292
+ const onProgressRef = (0, import_react.useRef)(props.onProgress);
293
+ (0, import_react.useEffect)(() => {
294
+ onVerifiedRef.current = props.onVerified;
295
+ onErrorRef.current = props.onError;
296
+ onProgressRef.current = props.onProgress;
297
+ });
298
+ (0, import_react.useEffect)(() => {
299
+ return () => {
300
+ if (handleRef.current) {
301
+ handleRef.current.cancel();
302
+ handleRef.current = null;
303
+ }
304
+ if (resetTimerRef.current !== null) {
305
+ clearTimeout(resetTimerRef.current);
306
+ resetTimerRef.current = null;
307
+ }
308
+ };
309
+ }, []);
310
+ const scheduleReset = (0, import_react.useCallback)(() => {
311
+ if (resetTimerRef.current !== null) {
312
+ clearTimeout(resetTimerRef.current);
313
+ }
314
+ resetTimerRef.current = setTimeout(() => {
315
+ resetTimerRef.current = null;
316
+ setState({ kind: "idle" });
317
+ }, SETTLE_RESET_MS);
318
+ }, []);
319
+ const trigger = (0, import_react.useCallback)(() => {
320
+ if (resetTimerRef.current !== null) {
321
+ clearTimeout(resetTimerRef.current);
322
+ resetTimerRef.current = null;
323
+ }
324
+ setState({ kind: "opening" });
325
+ const handle = openVerifyPopup({
326
+ baseOrigin: props.baseOrigin ?? DEFAULT_BASE_ORIGIN,
327
+ integratorKey: props.integratorKey,
328
+ cluster: props.cluster ?? "devnet",
329
+ minTrustScore: props.minTrustScore,
330
+ popupWidth: props.popupWidth ?? DEFAULT_POPUP_WIDTH,
331
+ popupHeight: props.popupHeight ?? DEFAULT_POPUP_HEIGHT,
332
+ timeoutMs: props.timeoutMs,
333
+ onVerified: (result) => {
334
+ handleRef.current = null;
335
+ setState({ kind: "done" });
336
+ onVerifiedRef.current(result);
337
+ scheduleReset();
338
+ },
339
+ onError: (error) => {
340
+ handleRef.current = null;
341
+ setState({ kind: "error", reason: error.reason });
342
+ onErrorRef.current?.(error);
343
+ scheduleReset();
344
+ },
345
+ onProgress: (progress) => {
346
+ onProgressRef.current?.(progress);
347
+ }
348
+ });
349
+ if (handle === null) {
350
+ setState({ kind: "blocked" });
351
+ onErrorRef.current?.({ reason: "popup_blocked" });
352
+ return;
353
+ }
354
+ handleRef.current = handle;
355
+ setState({ kind: "waiting" });
356
+ }, [
357
+ props.baseOrigin,
358
+ props.cluster,
359
+ props.integratorKey,
360
+ props.minTrustScore,
361
+ props.popupHeight,
362
+ props.popupWidth,
363
+ props.timeoutMs,
364
+ scheduleReset
365
+ ]);
366
+ const isWaiting = state.kind === "opening" || state.kind === "waiting";
367
+ const showFallback = state.kind === "blocked" && (props.popupBlockedFallback ?? true);
368
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "entros-verify-container", "data-state": state.kind, children: [
369
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
370
+ "button",
371
+ {
372
+ type: "button",
373
+ onClick: trigger,
374
+ disabled: isWaiting,
375
+ className: props.className,
376
+ style: props.style,
377
+ children: isWaiting ? "Verifying\u2026" : props.children ?? "Verify with Entros"
378
+ }
379
+ ),
380
+ showFallback && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { role: "alert", className: "entros-verify-blocked", children: [
381
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Popup blocked. " }),
382
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: trigger, className: props.className, children: "Click here to open verification" })
383
+ ] })
384
+ ] });
385
+ }
386
+ // Annotate the CommonJS export names for ESM import in node:
387
+ 0 && (module.exports = {
388
+ EntrosVerify
389
+ });
390
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/EntrosVerify.tsx","../src/messaging.ts","../src/url.ts","../src/popup-manager.ts"],"sourcesContent":["/**\n * `@entros/verify` — public surface.\n *\n * Drop-in React component for Entros verification. See\n * https://entros.io and https://docs.entros.io/integrate/verify.\n */\n\nexport { EntrosVerify } from \"./EntrosVerify\";\nexport type { EntrosVerifyProps } from \"./EntrosVerify\";\nexport type {\n Cluster,\n EntrosVerifyError,\n EntrosVerifyErrorReason,\n EntrosVerifyProgress,\n EntrosVerifyProgressStatus,\n EntrosVerifyResult,\n} from \"./types\";\n","/**\n * <EntrosVerify> — drop-in trigger for the Entros verification popup.\n *\n * Renders a button. On click, opens a popup window to entros.io. User\n * completes wallet-connected verification inside the popup; the popup\n * posts the result back via postMessage; this component fires the\n * integrator's onVerified callback.\n *\n * See README and `EntrosVerifyProps` for usage.\n */\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactElement, ReactNode } from \"react\";\n\nimport { openVerifyPopup, type PopupHandle } from \"./popup-manager\";\nimport type {\n Cluster,\n EntrosVerifyError,\n EntrosVerifyErrorReason,\n EntrosVerifyProgress,\n EntrosVerifyResult,\n} from \"./types\";\n\nconst DEFAULT_BASE_ORIGIN = \"https://entros.io\";\nconst DEFAULT_POPUP_WIDTH = 480;\nconst DEFAULT_POPUP_HEIGHT = 720;\n/**\n * After a verification settles (done or error), state returns to idle so\n * the component is ready for re-use without consumer intervention. Long\n * enough to render the brief \"done\" / \"error\" UX without blocking re-clicks.\n */\nconst SETTLE_RESET_MS = 1500;\n\nexport interface EntrosVerifyProps {\n /** Integrator key registered with Entros. Required. */\n integratorKey: string;\n /** Solana cluster. Defaults to \"devnet\". v1 supports devnet only. */\n cluster?: Cluster;\n /**\n * Optional Trust Score floor. The popup runs the verification regardless\n * and reports the result; if `minTrustScore` is set and the resulting\n * score is below it, the popup posts `entros/error` with reason\n * `validation_failed` instead of `entros/verified`.\n */\n minTrustScore?: number;\n /** Called on successful verification. Required. */\n onVerified: (result: EntrosVerifyResult) => void;\n /** Called on any failure or cancellation. Optional. */\n onError?: (error: EntrosVerifyError) => void;\n /** Called on progress heartbeats from the popup. Optional. */\n onProgress?: (progress: EntrosVerifyProgress) => void;\n /** Popup width in CSS pixels. Defaults to 480. */\n popupWidth?: number;\n /** Popup height in CSS pixels. Defaults to 720. */\n popupHeight?: number;\n /**\n * Maximum time the popup is allowed to be open before this component\n * fires onError({reason: \"timeout\"}). Defaults to 5 minutes.\n */\n timeoutMs?: number;\n /** Custom button content. Defaults to \"Verify with Entros\". */\n children?: ReactNode;\n /** className applied to the trigger button. */\n className?: string;\n /** Inline style applied to the trigger button. */\n style?: CSSProperties;\n /**\n * If true, when the popup is blocked the component renders an inline\n * retry button. Clicking it triggers a fresh window.open from a confirmed\n * user gesture, which most browsers allow. Defaults to true.\n */\n popupBlockedFallback?: boolean;\n /**\n * INTERNAL: Override the entros.io base origin. Intended for end-to-end\n * testing against a localhost popup host. Production consumers should\n * not set this.\n */\n baseOrigin?: string;\n}\n\ntype State =\n | { kind: \"idle\" }\n | { kind: \"opening\" }\n | { kind: \"blocked\" }\n | { kind: \"waiting\" }\n | { kind: \"done\" }\n | { kind: \"error\"; reason: EntrosVerifyErrorReason };\n\nexport function EntrosVerify(props: EntrosVerifyProps): ReactElement {\n const [state, setState] = useState<State>({ kind: \"idle\" });\n const handleRef = useRef<PopupHandle | null>(null);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Refs hold the latest callbacks so trigger stays stable across re-renders\n // even when consumers pass inline arrow functions. Avoids unnecessary\n // re-creation of the click handler on every parent render.\n const onVerifiedRef = useRef(props.onVerified);\n const onErrorRef = useRef(props.onError);\n const onProgressRef = useRef(props.onProgress);\n useEffect(() => {\n onVerifiedRef.current = props.onVerified;\n onErrorRef.current = props.onError;\n onProgressRef.current = props.onProgress;\n });\n\n // Tear down any in-flight popup + reset timer on unmount.\n useEffect(() => {\n return () => {\n if (handleRef.current) {\n handleRef.current.cancel();\n handleRef.current = null;\n }\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = null;\n }\n };\n }, []);\n\n const scheduleReset = useCallback(() => {\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n }\n resetTimerRef.current = setTimeout(() => {\n resetTimerRef.current = null;\n setState({ kind: \"idle\" });\n }, SETTLE_RESET_MS);\n }, []);\n\n const trigger = useCallback(() => {\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = null;\n }\n setState({ kind: \"opening\" });\n\n const handle = openVerifyPopup({\n baseOrigin: props.baseOrigin ?? DEFAULT_BASE_ORIGIN,\n integratorKey: props.integratorKey,\n cluster: props.cluster ?? \"devnet\",\n minTrustScore: props.minTrustScore,\n popupWidth: props.popupWidth ?? DEFAULT_POPUP_WIDTH,\n popupHeight: props.popupHeight ?? DEFAULT_POPUP_HEIGHT,\n timeoutMs: props.timeoutMs,\n onVerified: (result) => {\n handleRef.current = null;\n setState({ kind: \"done\" });\n onVerifiedRef.current(result);\n scheduleReset();\n },\n onError: (error) => {\n handleRef.current = null;\n setState({ kind: \"error\", reason: error.reason });\n onErrorRef.current?.(error);\n scheduleReset();\n },\n onProgress: (progress) => {\n onProgressRef.current?.(progress);\n },\n });\n\n if (handle === null) {\n setState({ kind: \"blocked\" });\n onErrorRef.current?.({ reason: \"popup_blocked\" });\n return;\n }\n\n handleRef.current = handle;\n setState({ kind: \"waiting\" });\n }, [\n props.baseOrigin,\n props.cluster,\n props.integratorKey,\n props.minTrustScore,\n props.popupHeight,\n props.popupWidth,\n props.timeoutMs,\n scheduleReset,\n ]);\n\n const isWaiting = state.kind === \"opening\" || state.kind === \"waiting\";\n const showFallback =\n state.kind === \"blocked\" && (props.popupBlockedFallback ?? true);\n\n return (\n <div className=\"entros-verify-container\" data-state={state.kind}>\n <button\n type=\"button\"\n onClick={trigger}\n disabled={isWaiting}\n className={props.className}\n style={props.style}\n >\n {isWaiting\n ? \"Verifying…\"\n : (props.children ?? \"Verify with Entros\")}\n </button>\n {showFallback && (\n <div role=\"alert\" className=\"entros-verify-blocked\">\n <span>Popup blocked. </span>\n <button type=\"button\" onClick={trigger} className={props.className}>\n Click here to open verification\n </button>\n </div>\n )}\n </div>\n );\n}\n","/**\n * Type guards and validation for postMessage envelopes received from the\n * Entros verify popup. The component is the trust boundary — every message\n * arriving on `window` is hostile until proven otherwise.\n *\n * Validation order in popup-manager.ts:\n * 1. event.origin matches expected popup origin (caller's responsibility)\n * 2. isEntrosMessage(event.data)\n * 3. event.data.request_id matches the parent's expected ID\n * 4. isFreshMessage(event.data)\n * 5. payload-specific guard for the message type\n *\n * Skipping any step is a security regression.\n */\n\nimport type {\n EntrosMessage,\n ErrorPayload,\n HeartbeatPayload,\n VerifiedPayload,\n} from \"./types\";\n\n/**\n * Maximum allowed clock drift between popup and parent. 90 seconds.\n *\n * The popup completes verification in seconds. A tighter window narrows\n * replay surface without affecting legitimate flows. The 5-minute\n * popup-open timeout is enforced separately by popup-manager.\n */\nconst MAX_TIMESTAMP_DRIFT_MS = 90 * 1000;\n\n/** Allowed error reason values on the wire. */\nconst ERROR_REASONS = new Set<string>([\n \"wallet_rejected\",\n \"validation_failed\",\n \"network_error\",\n \"user_canceled\",\n \"origin_invalid\",\n \"popup_blocked\",\n \"timeout\",\n \"unknown\",\n]);\n\nconst HEARTBEAT_STATUSES = new Set<string>([\n \"wallet_connecting\",\n \"capturing\",\n \"proving\",\n \"submitting\",\n \"attesting\",\n]);\n\nconst ENTROS_MESSAGE_TYPES = new Set<string>([\n \"entros/verified\",\n \"entros/error\",\n \"entros/heartbeat\",\n]);\n\nconst CLUSTERS = new Set<string>([\"devnet\", \"mainnet-beta\"]);\n\nexport function isEntrosMessage(data: unknown): data is EntrosMessage {\n if (typeof data !== \"object\" || data === null) return false;\n const msg = data as Record<string, unknown>;\n return (\n msg.source === \"entros\" &&\n msg.version === 1 &&\n typeof msg.type === \"string\" &&\n ENTROS_MESSAGE_TYPES.has(msg.type) &&\n typeof msg.request_id === \"string\" &&\n msg.request_id.length > 0 &&\n typeof msg.timestamp === \"number\" &&\n Number.isFinite(msg.timestamp) &&\n \"payload\" in msg\n );\n}\n\nexport function isFreshMessage(msg: EntrosMessage, now: number = Date.now()): boolean {\n return Math.abs(now - msg.timestamp) < MAX_TIMESTAMP_DRIFT_MS;\n}\n\nexport function isVerifiedPayload(payload: unknown): payload is VerifiedPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return (\n typeof p.wallet_pubkey === \"string\" &&\n p.wallet_pubkey.length > 0 &&\n typeof p.attestation_pda === \"string\" &&\n p.attestation_pda.length > 0 &&\n typeof p.tx_sig === \"string\" &&\n p.tx_sig.length > 0 &&\n typeof p.trust_score === \"number\" &&\n Number.isFinite(p.trust_score) &&\n p.trust_score >= 0 &&\n typeof p.cluster === \"string\" &&\n CLUSTERS.has(p.cluster)\n );\n}\n\nexport function isErrorPayload(payload: unknown): payload is ErrorPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return typeof p.reason === \"string\" && ERROR_REASONS.has(p.reason);\n}\n\nexport function isHeartbeatPayload(payload: unknown): payload is HeartbeatPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return typeof p.status === \"string\" && HEARTBEAT_STATUSES.has(p.status);\n}\n","/**\n * URL builders for the Entros verify popup.\n *\n * The component constructs the popup URL deterministically from the\n * integrator's props. The popup host validates every field server-side;\n * these helpers exist to fail loudly on the integrator's side when a\n * misconfiguration would have wasted a popup roundtrip.\n */\n\nimport type { Cluster } from \"./types\";\n\nconst VALID_INTEGRATOR_KEY = /^[a-z0-9_-]{1,64}$/;\nconst ORIGIN_PATTERN = /^https?:\\/\\/[^/]+$/;\n\nexport interface BuildPopupUrlOptions {\n /** entros.io base origin. Override for E2E testing only. */\n baseOrigin: string;\n integratorKey: string;\n /** Caller's window origin — popup posts back to this. */\n parentOrigin: string;\n cluster: Cluster;\n requestId: string;\n minTrustScore?: number;\n}\n\nexport function buildPopupUrl(opts: BuildPopupUrlOptions): string {\n if (!VALID_INTEGRATOR_KEY.test(opts.integratorKey)) {\n throw new Error(\n `Invalid integratorKey: must match /^[a-z0-9_-]{1,64}$/ (got \"${opts.integratorKey}\")`,\n );\n }\n if (!ORIGIN_PATTERN.test(opts.parentOrigin)) {\n throw new Error(\n `Invalid parentOrigin: must be a fully-qualified origin (got \"${opts.parentOrigin}\")`,\n );\n }\n if (opts.minTrustScore !== undefined) {\n if (\n !Number.isInteger(opts.minTrustScore) ||\n opts.minTrustScore < 0 ||\n opts.minTrustScore > 10000\n ) {\n throw new Error(\n `Invalid minTrustScore: must be an integer in [0, 10000] (got ${String(opts.minTrustScore)})`,\n );\n }\n }\n\n const url = new URL(\"/embed/verify-popup\", opts.baseOrigin);\n url.searchParams.set(\"integrator\", opts.integratorKey);\n url.searchParams.set(\"parent_origin\", opts.parentOrigin);\n url.searchParams.set(\"cluster\", opts.cluster);\n url.searchParams.set(\"request_id\", opts.requestId);\n if (opts.minTrustScore !== undefined) {\n url.searchParams.set(\"min_trust_score\", String(opts.minTrustScore));\n }\n return url.toString();\n}\n\n/**\n * Generates a cryptographically random request ID for replay protection.\n * Uses crypto.randomUUID when available (modern browsers + Node 19+).\n * Falls back to crypto.getRandomValues (broadly supported back to IE11)\n * formatted as a UUIDv4. Math.random is never used.\n */\nexport function generateRequestId(): string {\n if (typeof crypto === \"undefined\") {\n throw new Error(\n \"crypto is unavailable in this environment; @entros/verify requires a secure context\",\n );\n }\n if (typeof crypto.randomUUID === \"function\") {\n return crypto.randomUUID();\n }\n if (typeof crypto.getRandomValues !== \"function\") {\n throw new Error(\n \"crypto.getRandomValues is unavailable; @entros/verify requires a secure context\",\n );\n }\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n // RFC 4122 v4 framing: bits 6-7 of byte 8 are 0b10, bits 12-15 of byte 6\n // are 0b0100. The remaining bits are random.\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\"));\n return (\n hex.slice(0, 4).join(\"\") +\n \"-\" +\n hex.slice(4, 6).join(\"\") +\n \"-\" +\n hex.slice(6, 8).join(\"\") +\n \"-\" +\n hex.slice(8, 10).join(\"\") +\n \"-\" +\n hex.slice(10, 16).join(\"\")\n );\n}\n","/**\n * Popup-window state machine for `<EntrosVerify>`.\n *\n * Owns: window.open, postMessage listener, popup.closed polling, timeout.\n * Boundary with the React layer: open → returns a handle (or null if blocked).\n * Component is responsible for rendering the trigger button and the\n * popup-blocked fallback UI.\n *\n * Security model — every postMessage from the popup is treated as hostile\n * until proven otherwise. Validation order (skipping any step is a\n * regression):\n * 1. event.origin === expectedPopupOrigin\n * 2. event.source === popup (the window we opened, not a sibling tab)\n * 3. envelope shape matches `EntrosMessage` (version, source, type)\n * 4. event.data.request_id === this popup's request_id (replay defense)\n * 5. timestamp within drift window (90s)\n * 6. payload-specific guard for the message type\n */\n\nimport {\n isEntrosMessage,\n isErrorPayload,\n isFreshMessage,\n isHeartbeatPayload,\n isVerifiedPayload,\n} from \"./messaging\";\nimport type {\n Cluster,\n EntrosVerifyError,\n EntrosVerifyErrorReason,\n EntrosVerifyProgress,\n EntrosVerifyResult,\n} from \"./types\";\nimport { buildPopupUrl, generateRequestId } from \"./url\";\n\nconst DEFAULT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes\nconst POPUP_CLOSED_POLL_MS = 500;\n\n/**\n * Grace period after detecting popup.closed before firing user_canceled.\n * Lets the final `entros/verified` message arrive when the popup posts\n * and self-closes within the same event-loop turn.\n */\nconst POPUP_CLOSED_GRACE_MS = 1500;\n\n/**\n * After a popup-emitted outcome (`entros/verified` or `entros/error`),\n * the popup owns its own close — its success / failure surface renders\n * and either self-closes or waits for explicit user action (e.g., the\n * baseline-stale recovery surface). The parent only force-closes after\n * this defensive fallback in case the popup fails to close itself.\n * Generous enough to allow interactive failure surfaces to be read and\n * acted on; short enough that an abandoned popup eventually dies.\n */\nconst POPUP_OWNED_FALLBACK_CLOSE_MS = 30_000;\n\nexport interface OpenPopupOptions {\n baseOrigin: string;\n integratorKey: string;\n cluster: Cluster;\n minTrustScore?: number;\n popupWidth: number;\n popupHeight: number;\n timeoutMs?: number;\n onVerified: (result: EntrosVerifyResult) => void;\n onError: (error: EntrosVerifyError) => void;\n onProgress?: (progress: EntrosVerifyProgress) => void;\n}\n\nexport interface PopupHandle {\n /**\n * Force-cancel the popup. Closes the window if still open, fires\n * onError({reason: \"user_canceled\"}), and tears down listeners.\n * Idempotent.\n */\n cancel: () => void;\n}\n\nexport function openVerifyPopup(opts: OpenPopupOptions): PopupHandle | null {\n if (typeof window === \"undefined\") {\n throw new Error(\"openVerifyPopup must be called in a browser context\");\n }\n\n const requestId = generateRequestId();\n const parentOrigin = window.location.origin;\n const url = buildPopupUrl({\n baseOrigin: opts.baseOrigin,\n integratorKey: opts.integratorKey,\n parentOrigin,\n cluster: opts.cluster,\n requestId,\n minTrustScore: opts.minTrustScore,\n });\n\n const left = Math.max(\n 0,\n Math.floor((window.screen.availWidth - opts.popupWidth) / 2),\n );\n const top = Math.max(\n 0,\n Math.floor((window.screen.availHeight - opts.popupHeight) / 2),\n );\n const features = [\n `width=${opts.popupWidth}`,\n `height=${opts.popupHeight}`,\n `left=${left}`,\n `top=${top}`,\n \"menubar=no\",\n \"toolbar=no\",\n // location=yes lets the user verify entros.io in the URL bar.\n \"location=yes\",\n \"status=no\",\n \"resizable=yes\",\n \"scrollbars=yes\",\n ].join(\",\");\n\n // Unique window name per popup. A fixed name causes collision when an\n // integrator renders multiple <EntrosVerify> on one page — the second\n // window.open would reuse the existing popup.\n const popupName = `entros_verify_${requestId}`;\n const rawPopup = window.open(url, popupName, features);\n if (!rawPopup || rawPopup.closed) {\n return null;\n }\n // Narrow once so closures below see the non-null type.\n const popup: Window = rawPopup;\n\n const expectedPopupOrigin = new URL(opts.baseOrigin).origin;\n\n let settled = false;\n let pollTimerId: ReturnType<typeof setInterval> | null = null;\n let timeoutTimerId: ReturnType<typeof setTimeout> | null = null;\n let popupClosedAtMs: number | null = null;\n\n function clearListenersAndTimers(): void {\n window.removeEventListener(\"message\", onMessage);\n if (pollTimerId !== null) {\n clearInterval(pollTimerId);\n pollTimerId = null;\n }\n if (timeoutTimerId !== null) {\n clearTimeout(timeoutTimerId);\n timeoutTimerId = null;\n }\n }\n\n function forceClosePopup(): void {\n if (popup && !popup.closed) {\n try {\n popup.close();\n } catch {\n // Defensive only. We opened this window so we own the close permission;\n // this branch is for esoteric extension or browser-quirk edge cases.\n }\n }\n }\n\n function settleVerified(result: EntrosVerifyResult): void {\n if (settled) return;\n settled = true;\n // The popup owns its own close on the verified path so its\n // recognition surface (`Verified.` checkmark) is visible to the user\n // before the window dies. Parent only force-closes as a defensive\n // fallback in case the popup fails to close itself.\n clearListenersAndTimers();\n setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);\n opts.onVerified(result);\n }\n\n /**\n * @param forceImmediateClose\n * - false (default) — error came from a popup-emitted `entros/error`\n * message; the popup is still alive and rendering its own\n * `PopupFailure` (auto-close) or interactive recovery surface\n * (e.g., baseline-stale). Parent waits the fallback window before\n * force-closing so the user sees the failure category.\n * - true — error came from the parent (timeout, user cancel, or\n * polling detected the popup already closed). No popup-side\n * surface to preserve; force-close immediately.\n */\n function settleError(\n reason: EntrosVerifyErrorReason,\n forceImmediateClose = false,\n ): void {\n if (settled) return;\n settled = true;\n clearListenersAndTimers();\n if (forceImmediateClose) {\n forceClosePopup();\n } else {\n setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);\n }\n opts.onError({ reason });\n }\n\n function onMessage(event: MessageEvent): void {\n if (settled) return;\n\n // Origin gate — first and most important check.\n if (event.origin !== expectedPopupOrigin) return;\n\n // Source gate — defense-in-depth against another same-origin tab on\n // entros.io (e.g., the standalone /verify route open in a sibling tab)\n // posting a forged message. Only the popup we opened is authoritative.\n if (event.source !== popup) return;\n\n if (!isEntrosMessage(event.data)) return;\n\n // Replay protection — request_id must match this popup's ID.\n if (event.data.request_id !== requestId) return;\n\n if (!isFreshMessage(event.data)) return;\n\n switch (event.data.type) {\n case \"entros/verified\": {\n if (isVerifiedPayload(event.data.payload)) {\n settleVerified({\n walletPubkey: event.data.payload.wallet_pubkey,\n attestationPda: event.data.payload.attestation_pda,\n txSig: event.data.payload.tx_sig,\n trustScore: event.data.payload.trust_score,\n cluster: event.data.payload.cluster,\n });\n }\n break;\n }\n case \"entros/error\": {\n if (isErrorPayload(event.data.payload)) {\n settleError(event.data.payload.reason);\n }\n break;\n }\n case \"entros/heartbeat\": {\n if (isHeartbeatPayload(event.data.payload) && opts.onProgress) {\n opts.onProgress({ status: event.data.payload.status });\n }\n break;\n }\n }\n }\n\n function onPoll(): void {\n if (settled) return;\n if (popup.closed) {\n // Start the grace period the first time we observe the close.\n if (popupClosedAtMs === null) {\n popupClosedAtMs = Date.now();\n return;\n }\n if (Date.now() - popupClosedAtMs >= POPUP_CLOSED_GRACE_MS) {\n settleError(\"user_canceled\", true);\n }\n } else {\n popupClosedAtMs = null;\n }\n }\n\n function onTimeout(): void {\n settleError(\"timeout\", true);\n }\n\n window.addEventListener(\"message\", onMessage);\n pollTimerId = setInterval(onPoll, POPUP_CLOSED_POLL_MS);\n timeoutTimerId = setTimeout(onTimeout, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n\n return {\n cancel: () => settleError(\"user_canceled\", true),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,mBAAyD;;;ACkBzD,IAAM,yBAAyB,KAAK;AAGpC,IAAM,gBAAgB,oBAAI,IAAY;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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AAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS;AAAA,QACT,UAAU;AAAA,QACV,WAAW,MAAM;AAAA,QACjB,OAAO,MAAM;AAAA,QAEZ,sBACG,oBACC,MAAM,YAAY;AAAA;AAAA,IACzB;AAAA,IACC,gBACC,6CAAC,SAAI,MAAK,SAAQ,WAAU,yBAC1B;AAAA,kDAAC,UAAK,6BAAe;AAAA,MACrB,4CAAC,YAAO,MAAK,UAAS,SAAS,SAAS,WAAW,MAAM,WAAW,6CAEpE;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,364 @@
1
+ "use client";
2
+
3
+ // src/EntrosVerify.tsx
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
+
6
+ // src/messaging.ts
7
+ var MAX_TIMESTAMP_DRIFT_MS = 90 * 1e3;
8
+ var ERROR_REASONS = /* @__PURE__ */ new Set([
9
+ "wallet_rejected",
10
+ "validation_failed",
11
+ "network_error",
12
+ "user_canceled",
13
+ "origin_invalid",
14
+ "popup_blocked",
15
+ "timeout",
16
+ "unknown"
17
+ ]);
18
+ var HEARTBEAT_STATUSES = /* @__PURE__ */ new Set([
19
+ "wallet_connecting",
20
+ "capturing",
21
+ "proving",
22
+ "submitting",
23
+ "attesting"
24
+ ]);
25
+ var ENTROS_MESSAGE_TYPES = /* @__PURE__ */ new Set([
26
+ "entros/verified",
27
+ "entros/error",
28
+ "entros/heartbeat"
29
+ ]);
30
+ var CLUSTERS = /* @__PURE__ */ new Set(["devnet", "mainnet-beta"]);
31
+ function isEntrosMessage(data) {
32
+ if (typeof data !== "object" || data === null) return false;
33
+ const msg = data;
34
+ return msg.source === "entros" && msg.version === 1 && typeof msg.type === "string" && ENTROS_MESSAGE_TYPES.has(msg.type) && typeof msg.request_id === "string" && msg.request_id.length > 0 && typeof msg.timestamp === "number" && Number.isFinite(msg.timestamp) && "payload" in msg;
35
+ }
36
+ function isFreshMessage(msg, now = Date.now()) {
37
+ return Math.abs(now - msg.timestamp) < MAX_TIMESTAMP_DRIFT_MS;
38
+ }
39
+ function isVerifiedPayload(payload) {
40
+ if (typeof payload !== "object" || payload === null) return false;
41
+ const p = payload;
42
+ return typeof p.wallet_pubkey === "string" && p.wallet_pubkey.length > 0 && typeof p.attestation_pda === "string" && p.attestation_pda.length > 0 && typeof p.tx_sig === "string" && p.tx_sig.length > 0 && typeof p.trust_score === "number" && Number.isFinite(p.trust_score) && p.trust_score >= 0 && typeof p.cluster === "string" && CLUSTERS.has(p.cluster);
43
+ }
44
+ function isErrorPayload(payload) {
45
+ if (typeof payload !== "object" || payload === null) return false;
46
+ const p = payload;
47
+ return typeof p.reason === "string" && ERROR_REASONS.has(p.reason);
48
+ }
49
+ function isHeartbeatPayload(payload) {
50
+ if (typeof payload !== "object" || payload === null) return false;
51
+ const p = payload;
52
+ return typeof p.status === "string" && HEARTBEAT_STATUSES.has(p.status);
53
+ }
54
+
55
+ // src/url.ts
56
+ var VALID_INTEGRATOR_KEY = /^[a-z0-9_-]{1,64}$/;
57
+ var ORIGIN_PATTERN = /^https?:\/\/[^/]+$/;
58
+ function buildPopupUrl(opts) {
59
+ if (!VALID_INTEGRATOR_KEY.test(opts.integratorKey)) {
60
+ throw new Error(
61
+ `Invalid integratorKey: must match /^[a-z0-9_-]{1,64}$/ (got "${opts.integratorKey}")`
62
+ );
63
+ }
64
+ if (!ORIGIN_PATTERN.test(opts.parentOrigin)) {
65
+ throw new Error(
66
+ `Invalid parentOrigin: must be a fully-qualified origin (got "${opts.parentOrigin}")`
67
+ );
68
+ }
69
+ if (opts.minTrustScore !== void 0) {
70
+ if (!Number.isInteger(opts.minTrustScore) || opts.minTrustScore < 0 || opts.minTrustScore > 1e4) {
71
+ throw new Error(
72
+ `Invalid minTrustScore: must be an integer in [0, 10000] (got ${String(opts.minTrustScore)})`
73
+ );
74
+ }
75
+ }
76
+ const url = new URL("/embed/verify-popup", opts.baseOrigin);
77
+ url.searchParams.set("integrator", opts.integratorKey);
78
+ url.searchParams.set("parent_origin", opts.parentOrigin);
79
+ url.searchParams.set("cluster", opts.cluster);
80
+ url.searchParams.set("request_id", opts.requestId);
81
+ if (opts.minTrustScore !== void 0) {
82
+ url.searchParams.set("min_trust_score", String(opts.minTrustScore));
83
+ }
84
+ return url.toString();
85
+ }
86
+ function generateRequestId() {
87
+ if (typeof crypto === "undefined") {
88
+ throw new Error(
89
+ "crypto is unavailable in this environment; @entros/verify requires a secure context"
90
+ );
91
+ }
92
+ if (typeof crypto.randomUUID === "function") {
93
+ return crypto.randomUUID();
94
+ }
95
+ if (typeof crypto.getRandomValues !== "function") {
96
+ throw new Error(
97
+ "crypto.getRandomValues is unavailable; @entros/verify requires a secure context"
98
+ );
99
+ }
100
+ const bytes = new Uint8Array(16);
101
+ crypto.getRandomValues(bytes);
102
+ bytes[6] = (bytes[6] ?? 0) & 15 | 64;
103
+ bytes[8] = (bytes[8] ?? 0) & 63 | 128;
104
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
105
+ return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 16).join("");
106
+ }
107
+
108
+ // src/popup-manager.ts
109
+ var DEFAULT_TIMEOUT_MS = 5 * 60 * 1e3;
110
+ var POPUP_CLOSED_POLL_MS = 500;
111
+ var POPUP_CLOSED_GRACE_MS = 1500;
112
+ var POPUP_OWNED_FALLBACK_CLOSE_MS = 3e4;
113
+ function openVerifyPopup(opts) {
114
+ if (typeof window === "undefined") {
115
+ throw new Error("openVerifyPopup must be called in a browser context");
116
+ }
117
+ const requestId = generateRequestId();
118
+ const parentOrigin = window.location.origin;
119
+ const url = buildPopupUrl({
120
+ baseOrigin: opts.baseOrigin,
121
+ integratorKey: opts.integratorKey,
122
+ parentOrigin,
123
+ cluster: opts.cluster,
124
+ requestId,
125
+ minTrustScore: opts.minTrustScore
126
+ });
127
+ const left = Math.max(
128
+ 0,
129
+ Math.floor((window.screen.availWidth - opts.popupWidth) / 2)
130
+ );
131
+ const top = Math.max(
132
+ 0,
133
+ Math.floor((window.screen.availHeight - opts.popupHeight) / 2)
134
+ );
135
+ const features = [
136
+ `width=${opts.popupWidth}`,
137
+ `height=${opts.popupHeight}`,
138
+ `left=${left}`,
139
+ `top=${top}`,
140
+ "menubar=no",
141
+ "toolbar=no",
142
+ // location=yes lets the user verify entros.io in the URL bar.
143
+ "location=yes",
144
+ "status=no",
145
+ "resizable=yes",
146
+ "scrollbars=yes"
147
+ ].join(",");
148
+ const popupName = `entros_verify_${requestId}`;
149
+ const rawPopup = window.open(url, popupName, features);
150
+ if (!rawPopup || rawPopup.closed) {
151
+ return null;
152
+ }
153
+ const popup = rawPopup;
154
+ const expectedPopupOrigin = new URL(opts.baseOrigin).origin;
155
+ let settled = false;
156
+ let pollTimerId = null;
157
+ let timeoutTimerId = null;
158
+ let popupClosedAtMs = null;
159
+ function clearListenersAndTimers() {
160
+ window.removeEventListener("message", onMessage);
161
+ if (pollTimerId !== null) {
162
+ clearInterval(pollTimerId);
163
+ pollTimerId = null;
164
+ }
165
+ if (timeoutTimerId !== null) {
166
+ clearTimeout(timeoutTimerId);
167
+ timeoutTimerId = null;
168
+ }
169
+ }
170
+ function forceClosePopup() {
171
+ if (popup && !popup.closed) {
172
+ try {
173
+ popup.close();
174
+ } catch {
175
+ }
176
+ }
177
+ }
178
+ function settleVerified(result) {
179
+ if (settled) return;
180
+ settled = true;
181
+ clearListenersAndTimers();
182
+ setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);
183
+ opts.onVerified(result);
184
+ }
185
+ function settleError(reason, forceImmediateClose = false) {
186
+ if (settled) return;
187
+ settled = true;
188
+ clearListenersAndTimers();
189
+ if (forceImmediateClose) {
190
+ forceClosePopup();
191
+ } else {
192
+ setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);
193
+ }
194
+ opts.onError({ reason });
195
+ }
196
+ function onMessage(event) {
197
+ if (settled) return;
198
+ if (event.origin !== expectedPopupOrigin) return;
199
+ if (event.source !== popup) return;
200
+ if (!isEntrosMessage(event.data)) return;
201
+ if (event.data.request_id !== requestId) return;
202
+ if (!isFreshMessage(event.data)) return;
203
+ switch (event.data.type) {
204
+ case "entros/verified": {
205
+ if (isVerifiedPayload(event.data.payload)) {
206
+ settleVerified({
207
+ walletPubkey: event.data.payload.wallet_pubkey,
208
+ attestationPda: event.data.payload.attestation_pda,
209
+ txSig: event.data.payload.tx_sig,
210
+ trustScore: event.data.payload.trust_score,
211
+ cluster: event.data.payload.cluster
212
+ });
213
+ }
214
+ break;
215
+ }
216
+ case "entros/error": {
217
+ if (isErrorPayload(event.data.payload)) {
218
+ settleError(event.data.payload.reason);
219
+ }
220
+ break;
221
+ }
222
+ case "entros/heartbeat": {
223
+ if (isHeartbeatPayload(event.data.payload) && opts.onProgress) {
224
+ opts.onProgress({ status: event.data.payload.status });
225
+ }
226
+ break;
227
+ }
228
+ }
229
+ }
230
+ function onPoll() {
231
+ if (settled) return;
232
+ if (popup.closed) {
233
+ if (popupClosedAtMs === null) {
234
+ popupClosedAtMs = Date.now();
235
+ return;
236
+ }
237
+ if (Date.now() - popupClosedAtMs >= POPUP_CLOSED_GRACE_MS) {
238
+ settleError("user_canceled", true);
239
+ }
240
+ } else {
241
+ popupClosedAtMs = null;
242
+ }
243
+ }
244
+ function onTimeout() {
245
+ settleError("timeout", true);
246
+ }
247
+ window.addEventListener("message", onMessage);
248
+ pollTimerId = setInterval(onPoll, POPUP_CLOSED_POLL_MS);
249
+ timeoutTimerId = setTimeout(onTimeout, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
250
+ return {
251
+ cancel: () => settleError("user_canceled", true)
252
+ };
253
+ }
254
+
255
+ // src/EntrosVerify.tsx
256
+ import { jsx, jsxs } from "react/jsx-runtime";
257
+ var DEFAULT_BASE_ORIGIN = "https://entros.io";
258
+ var DEFAULT_POPUP_WIDTH = 480;
259
+ var DEFAULT_POPUP_HEIGHT = 720;
260
+ var SETTLE_RESET_MS = 1500;
261
+ function EntrosVerify(props) {
262
+ const [state, setState] = useState({ kind: "idle" });
263
+ const handleRef = useRef(null);
264
+ const resetTimerRef = useRef(null);
265
+ const onVerifiedRef = useRef(props.onVerified);
266
+ const onErrorRef = useRef(props.onError);
267
+ const onProgressRef = useRef(props.onProgress);
268
+ useEffect(() => {
269
+ onVerifiedRef.current = props.onVerified;
270
+ onErrorRef.current = props.onError;
271
+ onProgressRef.current = props.onProgress;
272
+ });
273
+ useEffect(() => {
274
+ return () => {
275
+ if (handleRef.current) {
276
+ handleRef.current.cancel();
277
+ handleRef.current = null;
278
+ }
279
+ if (resetTimerRef.current !== null) {
280
+ clearTimeout(resetTimerRef.current);
281
+ resetTimerRef.current = null;
282
+ }
283
+ };
284
+ }, []);
285
+ const scheduleReset = useCallback(() => {
286
+ if (resetTimerRef.current !== null) {
287
+ clearTimeout(resetTimerRef.current);
288
+ }
289
+ resetTimerRef.current = setTimeout(() => {
290
+ resetTimerRef.current = null;
291
+ setState({ kind: "idle" });
292
+ }, SETTLE_RESET_MS);
293
+ }, []);
294
+ const trigger = useCallback(() => {
295
+ if (resetTimerRef.current !== null) {
296
+ clearTimeout(resetTimerRef.current);
297
+ resetTimerRef.current = null;
298
+ }
299
+ setState({ kind: "opening" });
300
+ const handle = openVerifyPopup({
301
+ baseOrigin: props.baseOrigin ?? DEFAULT_BASE_ORIGIN,
302
+ integratorKey: props.integratorKey,
303
+ cluster: props.cluster ?? "devnet",
304
+ minTrustScore: props.minTrustScore,
305
+ popupWidth: props.popupWidth ?? DEFAULT_POPUP_WIDTH,
306
+ popupHeight: props.popupHeight ?? DEFAULT_POPUP_HEIGHT,
307
+ timeoutMs: props.timeoutMs,
308
+ onVerified: (result) => {
309
+ handleRef.current = null;
310
+ setState({ kind: "done" });
311
+ onVerifiedRef.current(result);
312
+ scheduleReset();
313
+ },
314
+ onError: (error) => {
315
+ handleRef.current = null;
316
+ setState({ kind: "error", reason: error.reason });
317
+ onErrorRef.current?.(error);
318
+ scheduleReset();
319
+ },
320
+ onProgress: (progress) => {
321
+ onProgressRef.current?.(progress);
322
+ }
323
+ });
324
+ if (handle === null) {
325
+ setState({ kind: "blocked" });
326
+ onErrorRef.current?.({ reason: "popup_blocked" });
327
+ return;
328
+ }
329
+ handleRef.current = handle;
330
+ setState({ kind: "waiting" });
331
+ }, [
332
+ props.baseOrigin,
333
+ props.cluster,
334
+ props.integratorKey,
335
+ props.minTrustScore,
336
+ props.popupHeight,
337
+ props.popupWidth,
338
+ props.timeoutMs,
339
+ scheduleReset
340
+ ]);
341
+ const isWaiting = state.kind === "opening" || state.kind === "waiting";
342
+ const showFallback = state.kind === "blocked" && (props.popupBlockedFallback ?? true);
343
+ return /* @__PURE__ */ jsxs("div", { className: "entros-verify-container", "data-state": state.kind, children: [
344
+ /* @__PURE__ */ jsx(
345
+ "button",
346
+ {
347
+ type: "button",
348
+ onClick: trigger,
349
+ disabled: isWaiting,
350
+ className: props.className,
351
+ style: props.style,
352
+ children: isWaiting ? "Verifying\u2026" : props.children ?? "Verify with Entros"
353
+ }
354
+ ),
355
+ showFallback && /* @__PURE__ */ jsxs("div", { role: "alert", className: "entros-verify-blocked", children: [
356
+ /* @__PURE__ */ jsx("span", { children: "Popup blocked. " }),
357
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: trigger, className: props.className, children: "Click here to open verification" })
358
+ ] })
359
+ ] });
360
+ }
361
+ export {
362
+ EntrosVerify
363
+ };
364
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/EntrosVerify.tsx","../src/messaging.ts","../src/url.ts","../src/popup-manager.ts"],"sourcesContent":["/**\n * <EntrosVerify> — drop-in trigger for the Entros verification popup.\n *\n * Renders a button. On click, opens a popup window to entros.io. User\n * completes wallet-connected verification inside the popup; the popup\n * posts the result back via postMessage; this component fires the\n * integrator's onVerified callback.\n *\n * See README and `EntrosVerifyProps` for usage.\n */\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactElement, ReactNode } from \"react\";\n\nimport { openVerifyPopup, type PopupHandle } from \"./popup-manager\";\nimport type {\n Cluster,\n EntrosVerifyError,\n EntrosVerifyErrorReason,\n EntrosVerifyProgress,\n EntrosVerifyResult,\n} from \"./types\";\n\nconst DEFAULT_BASE_ORIGIN = \"https://entros.io\";\nconst DEFAULT_POPUP_WIDTH = 480;\nconst DEFAULT_POPUP_HEIGHT = 720;\n/**\n * After a verification settles (done or error), state returns to idle so\n * the component is ready for re-use without consumer intervention. Long\n * enough to render the brief \"done\" / \"error\" UX without blocking re-clicks.\n */\nconst SETTLE_RESET_MS = 1500;\n\nexport interface EntrosVerifyProps {\n /** Integrator key registered with Entros. Required. */\n integratorKey: string;\n /** Solana cluster. Defaults to \"devnet\". v1 supports devnet only. */\n cluster?: Cluster;\n /**\n * Optional Trust Score floor. The popup runs the verification regardless\n * and reports the result; if `minTrustScore` is set and the resulting\n * score is below it, the popup posts `entros/error` with reason\n * `validation_failed` instead of `entros/verified`.\n */\n minTrustScore?: number;\n /** Called on successful verification. Required. */\n onVerified: (result: EntrosVerifyResult) => void;\n /** Called on any failure or cancellation. Optional. */\n onError?: (error: EntrosVerifyError) => void;\n /** Called on progress heartbeats from the popup. Optional. */\n onProgress?: (progress: EntrosVerifyProgress) => void;\n /** Popup width in CSS pixels. Defaults to 480. */\n popupWidth?: number;\n /** Popup height in CSS pixels. Defaults to 720. */\n popupHeight?: number;\n /**\n * Maximum time the popup is allowed to be open before this component\n * fires onError({reason: \"timeout\"}). Defaults to 5 minutes.\n */\n timeoutMs?: number;\n /** Custom button content. Defaults to \"Verify with Entros\". */\n children?: ReactNode;\n /** className applied to the trigger button. */\n className?: string;\n /** Inline style applied to the trigger button. */\n style?: CSSProperties;\n /**\n * If true, when the popup is blocked the component renders an inline\n * retry button. Clicking it triggers a fresh window.open from a confirmed\n * user gesture, which most browsers allow. Defaults to true.\n */\n popupBlockedFallback?: boolean;\n /**\n * INTERNAL: Override the entros.io base origin. Intended for end-to-end\n * testing against a localhost popup host. Production consumers should\n * not set this.\n */\n baseOrigin?: string;\n}\n\ntype State =\n | { kind: \"idle\" }\n | { kind: \"opening\" }\n | { kind: \"blocked\" }\n | { kind: \"waiting\" }\n | { kind: \"done\" }\n | { kind: \"error\"; reason: EntrosVerifyErrorReason };\n\nexport function EntrosVerify(props: EntrosVerifyProps): ReactElement {\n const [state, setState] = useState<State>({ kind: \"idle\" });\n const handleRef = useRef<PopupHandle | null>(null);\n const resetTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n // Refs hold the latest callbacks so trigger stays stable across re-renders\n // even when consumers pass inline arrow functions. Avoids unnecessary\n // re-creation of the click handler on every parent render.\n const onVerifiedRef = useRef(props.onVerified);\n const onErrorRef = useRef(props.onError);\n const onProgressRef = useRef(props.onProgress);\n useEffect(() => {\n onVerifiedRef.current = props.onVerified;\n onErrorRef.current = props.onError;\n onProgressRef.current = props.onProgress;\n });\n\n // Tear down any in-flight popup + reset timer on unmount.\n useEffect(() => {\n return () => {\n if (handleRef.current) {\n handleRef.current.cancel();\n handleRef.current = null;\n }\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = null;\n }\n };\n }, []);\n\n const scheduleReset = useCallback(() => {\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n }\n resetTimerRef.current = setTimeout(() => {\n resetTimerRef.current = null;\n setState({ kind: \"idle\" });\n }, SETTLE_RESET_MS);\n }, []);\n\n const trigger = useCallback(() => {\n if (resetTimerRef.current !== null) {\n clearTimeout(resetTimerRef.current);\n resetTimerRef.current = null;\n }\n setState({ kind: \"opening\" });\n\n const handle = openVerifyPopup({\n baseOrigin: props.baseOrigin ?? DEFAULT_BASE_ORIGIN,\n integratorKey: props.integratorKey,\n cluster: props.cluster ?? \"devnet\",\n minTrustScore: props.minTrustScore,\n popupWidth: props.popupWidth ?? DEFAULT_POPUP_WIDTH,\n popupHeight: props.popupHeight ?? DEFAULT_POPUP_HEIGHT,\n timeoutMs: props.timeoutMs,\n onVerified: (result) => {\n handleRef.current = null;\n setState({ kind: \"done\" });\n onVerifiedRef.current(result);\n scheduleReset();\n },\n onError: (error) => {\n handleRef.current = null;\n setState({ kind: \"error\", reason: error.reason });\n onErrorRef.current?.(error);\n scheduleReset();\n },\n onProgress: (progress) => {\n onProgressRef.current?.(progress);\n },\n });\n\n if (handle === null) {\n setState({ kind: \"blocked\" });\n onErrorRef.current?.({ reason: \"popup_blocked\" });\n return;\n }\n\n handleRef.current = handle;\n setState({ kind: \"waiting\" });\n }, [\n props.baseOrigin,\n props.cluster,\n props.integratorKey,\n props.minTrustScore,\n props.popupHeight,\n props.popupWidth,\n props.timeoutMs,\n scheduleReset,\n ]);\n\n const isWaiting = state.kind === \"opening\" || state.kind === \"waiting\";\n const showFallback =\n state.kind === \"blocked\" && (props.popupBlockedFallback ?? true);\n\n return (\n <div className=\"entros-verify-container\" data-state={state.kind}>\n <button\n type=\"button\"\n onClick={trigger}\n disabled={isWaiting}\n className={props.className}\n style={props.style}\n >\n {isWaiting\n ? \"Verifying…\"\n : (props.children ?? \"Verify with Entros\")}\n </button>\n {showFallback && (\n <div role=\"alert\" className=\"entros-verify-blocked\">\n <span>Popup blocked. </span>\n <button type=\"button\" onClick={trigger} className={props.className}>\n Click here to open verification\n </button>\n </div>\n )}\n </div>\n );\n}\n","/**\n * Type guards and validation for postMessage envelopes received from the\n * Entros verify popup. The component is the trust boundary — every message\n * arriving on `window` is hostile until proven otherwise.\n *\n * Validation order in popup-manager.ts:\n * 1. event.origin matches expected popup origin (caller's responsibility)\n * 2. isEntrosMessage(event.data)\n * 3. event.data.request_id matches the parent's expected ID\n * 4. isFreshMessage(event.data)\n * 5. payload-specific guard for the message type\n *\n * Skipping any step is a security regression.\n */\n\nimport type {\n EntrosMessage,\n ErrorPayload,\n HeartbeatPayload,\n VerifiedPayload,\n} from \"./types\";\n\n/**\n * Maximum allowed clock drift between popup and parent. 90 seconds.\n *\n * The popup completes verification in seconds. A tighter window narrows\n * replay surface without affecting legitimate flows. The 5-minute\n * popup-open timeout is enforced separately by popup-manager.\n */\nconst MAX_TIMESTAMP_DRIFT_MS = 90 * 1000;\n\n/** Allowed error reason values on the wire. */\nconst ERROR_REASONS = new Set<string>([\n \"wallet_rejected\",\n \"validation_failed\",\n \"network_error\",\n \"user_canceled\",\n \"origin_invalid\",\n \"popup_blocked\",\n \"timeout\",\n \"unknown\",\n]);\n\nconst HEARTBEAT_STATUSES = new Set<string>([\n \"wallet_connecting\",\n \"capturing\",\n \"proving\",\n \"submitting\",\n \"attesting\",\n]);\n\nconst ENTROS_MESSAGE_TYPES = new Set<string>([\n \"entros/verified\",\n \"entros/error\",\n \"entros/heartbeat\",\n]);\n\nconst CLUSTERS = new Set<string>([\"devnet\", \"mainnet-beta\"]);\n\nexport function isEntrosMessage(data: unknown): data is EntrosMessage {\n if (typeof data !== \"object\" || data === null) return false;\n const msg = data as Record<string, unknown>;\n return (\n msg.source === \"entros\" &&\n msg.version === 1 &&\n typeof msg.type === \"string\" &&\n ENTROS_MESSAGE_TYPES.has(msg.type) &&\n typeof msg.request_id === \"string\" &&\n msg.request_id.length > 0 &&\n typeof msg.timestamp === \"number\" &&\n Number.isFinite(msg.timestamp) &&\n \"payload\" in msg\n );\n}\n\nexport function isFreshMessage(msg: EntrosMessage, now: number = Date.now()): boolean {\n return Math.abs(now - msg.timestamp) < MAX_TIMESTAMP_DRIFT_MS;\n}\n\nexport function isVerifiedPayload(payload: unknown): payload is VerifiedPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return (\n typeof p.wallet_pubkey === \"string\" &&\n p.wallet_pubkey.length > 0 &&\n typeof p.attestation_pda === \"string\" &&\n p.attestation_pda.length > 0 &&\n typeof p.tx_sig === \"string\" &&\n p.tx_sig.length > 0 &&\n typeof p.trust_score === \"number\" &&\n Number.isFinite(p.trust_score) &&\n p.trust_score >= 0 &&\n typeof p.cluster === \"string\" &&\n CLUSTERS.has(p.cluster)\n );\n}\n\nexport function isErrorPayload(payload: unknown): payload is ErrorPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return typeof p.reason === \"string\" && ERROR_REASONS.has(p.reason);\n}\n\nexport function isHeartbeatPayload(payload: unknown): payload is HeartbeatPayload {\n if (typeof payload !== \"object\" || payload === null) return false;\n const p = payload as Record<string, unknown>;\n return typeof p.status === \"string\" && HEARTBEAT_STATUSES.has(p.status);\n}\n","/**\n * URL builders for the Entros verify popup.\n *\n * The component constructs the popup URL deterministically from the\n * integrator's props. The popup host validates every field server-side;\n * these helpers exist to fail loudly on the integrator's side when a\n * misconfiguration would have wasted a popup roundtrip.\n */\n\nimport type { Cluster } from \"./types\";\n\nconst VALID_INTEGRATOR_KEY = /^[a-z0-9_-]{1,64}$/;\nconst ORIGIN_PATTERN = /^https?:\\/\\/[^/]+$/;\n\nexport interface BuildPopupUrlOptions {\n /** entros.io base origin. Override for E2E testing only. */\n baseOrigin: string;\n integratorKey: string;\n /** Caller's window origin — popup posts back to this. */\n parentOrigin: string;\n cluster: Cluster;\n requestId: string;\n minTrustScore?: number;\n}\n\nexport function buildPopupUrl(opts: BuildPopupUrlOptions): string {\n if (!VALID_INTEGRATOR_KEY.test(opts.integratorKey)) {\n throw new Error(\n `Invalid integratorKey: must match /^[a-z0-9_-]{1,64}$/ (got \"${opts.integratorKey}\")`,\n );\n }\n if (!ORIGIN_PATTERN.test(opts.parentOrigin)) {\n throw new Error(\n `Invalid parentOrigin: must be a fully-qualified origin (got \"${opts.parentOrigin}\")`,\n );\n }\n if (opts.minTrustScore !== undefined) {\n if (\n !Number.isInteger(opts.minTrustScore) ||\n opts.minTrustScore < 0 ||\n opts.minTrustScore > 10000\n ) {\n throw new Error(\n `Invalid minTrustScore: must be an integer in [0, 10000] (got ${String(opts.minTrustScore)})`,\n );\n }\n }\n\n const url = new URL(\"/embed/verify-popup\", opts.baseOrigin);\n url.searchParams.set(\"integrator\", opts.integratorKey);\n url.searchParams.set(\"parent_origin\", opts.parentOrigin);\n url.searchParams.set(\"cluster\", opts.cluster);\n url.searchParams.set(\"request_id\", opts.requestId);\n if (opts.minTrustScore !== undefined) {\n url.searchParams.set(\"min_trust_score\", String(opts.minTrustScore));\n }\n return url.toString();\n}\n\n/**\n * Generates a cryptographically random request ID for replay protection.\n * Uses crypto.randomUUID when available (modern browsers + Node 19+).\n * Falls back to crypto.getRandomValues (broadly supported back to IE11)\n * formatted as a UUIDv4. Math.random is never used.\n */\nexport function generateRequestId(): string {\n if (typeof crypto === \"undefined\") {\n throw new Error(\n \"crypto is unavailable in this environment; @entros/verify requires a secure context\",\n );\n }\n if (typeof crypto.randomUUID === \"function\") {\n return crypto.randomUUID();\n }\n if (typeof crypto.getRandomValues !== \"function\") {\n throw new Error(\n \"crypto.getRandomValues is unavailable; @entros/verify requires a secure context\",\n );\n }\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n // RFC 4122 v4 framing: bits 6-7 of byte 8 are 0b10, bits 12-15 of byte 6\n // are 0b0100. The remaining bits are random.\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\"));\n return (\n hex.slice(0, 4).join(\"\") +\n \"-\" +\n hex.slice(4, 6).join(\"\") +\n \"-\" +\n hex.slice(6, 8).join(\"\") +\n \"-\" +\n hex.slice(8, 10).join(\"\") +\n \"-\" +\n hex.slice(10, 16).join(\"\")\n );\n}\n","/**\n * Popup-window state machine for `<EntrosVerify>`.\n *\n * Owns: window.open, postMessage listener, popup.closed polling, timeout.\n * Boundary with the React layer: open → returns a handle (or null if blocked).\n * Component is responsible for rendering the trigger button and the\n * popup-blocked fallback UI.\n *\n * Security model — every postMessage from the popup is treated as hostile\n * until proven otherwise. Validation order (skipping any step is a\n * regression):\n * 1. event.origin === expectedPopupOrigin\n * 2. event.source === popup (the window we opened, not a sibling tab)\n * 3. envelope shape matches `EntrosMessage` (version, source, type)\n * 4. event.data.request_id === this popup's request_id (replay defense)\n * 5. timestamp within drift window (90s)\n * 6. payload-specific guard for the message type\n */\n\nimport {\n isEntrosMessage,\n isErrorPayload,\n isFreshMessage,\n isHeartbeatPayload,\n isVerifiedPayload,\n} from \"./messaging\";\nimport type {\n Cluster,\n EntrosVerifyError,\n EntrosVerifyErrorReason,\n EntrosVerifyProgress,\n EntrosVerifyResult,\n} from \"./types\";\nimport { buildPopupUrl, generateRequestId } from \"./url\";\n\nconst DEFAULT_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes\nconst POPUP_CLOSED_POLL_MS = 500;\n\n/**\n * Grace period after detecting popup.closed before firing user_canceled.\n * Lets the final `entros/verified` message arrive when the popup posts\n * and self-closes within the same event-loop turn.\n */\nconst POPUP_CLOSED_GRACE_MS = 1500;\n\n/**\n * After a popup-emitted outcome (`entros/verified` or `entros/error`),\n * the popup owns its own close — its success / failure surface renders\n * and either self-closes or waits for explicit user action (e.g., the\n * baseline-stale recovery surface). The parent only force-closes after\n * this defensive fallback in case the popup fails to close itself.\n * Generous enough to allow interactive failure surfaces to be read and\n * acted on; short enough that an abandoned popup eventually dies.\n */\nconst POPUP_OWNED_FALLBACK_CLOSE_MS = 30_000;\n\nexport interface OpenPopupOptions {\n baseOrigin: string;\n integratorKey: string;\n cluster: Cluster;\n minTrustScore?: number;\n popupWidth: number;\n popupHeight: number;\n timeoutMs?: number;\n onVerified: (result: EntrosVerifyResult) => void;\n onError: (error: EntrosVerifyError) => void;\n onProgress?: (progress: EntrosVerifyProgress) => void;\n}\n\nexport interface PopupHandle {\n /**\n * Force-cancel the popup. Closes the window if still open, fires\n * onError({reason: \"user_canceled\"}), and tears down listeners.\n * Idempotent.\n */\n cancel: () => void;\n}\n\nexport function openVerifyPopup(opts: OpenPopupOptions): PopupHandle | null {\n if (typeof window === \"undefined\") {\n throw new Error(\"openVerifyPopup must be called in a browser context\");\n }\n\n const requestId = generateRequestId();\n const parentOrigin = window.location.origin;\n const url = buildPopupUrl({\n baseOrigin: opts.baseOrigin,\n integratorKey: opts.integratorKey,\n parentOrigin,\n cluster: opts.cluster,\n requestId,\n minTrustScore: opts.minTrustScore,\n });\n\n const left = Math.max(\n 0,\n Math.floor((window.screen.availWidth - opts.popupWidth) / 2),\n );\n const top = Math.max(\n 0,\n Math.floor((window.screen.availHeight - opts.popupHeight) / 2),\n );\n const features = [\n `width=${opts.popupWidth}`,\n `height=${opts.popupHeight}`,\n `left=${left}`,\n `top=${top}`,\n \"menubar=no\",\n \"toolbar=no\",\n // location=yes lets the user verify entros.io in the URL bar.\n \"location=yes\",\n \"status=no\",\n \"resizable=yes\",\n \"scrollbars=yes\",\n ].join(\",\");\n\n // Unique window name per popup. A fixed name causes collision when an\n // integrator renders multiple <EntrosVerify> on one page — the second\n // window.open would reuse the existing popup.\n const popupName = `entros_verify_${requestId}`;\n const rawPopup = window.open(url, popupName, features);\n if (!rawPopup || rawPopup.closed) {\n return null;\n }\n // Narrow once so closures below see the non-null type.\n const popup: Window = rawPopup;\n\n const expectedPopupOrigin = new URL(opts.baseOrigin).origin;\n\n let settled = false;\n let pollTimerId: ReturnType<typeof setInterval> | null = null;\n let timeoutTimerId: ReturnType<typeof setTimeout> | null = null;\n let popupClosedAtMs: number | null = null;\n\n function clearListenersAndTimers(): void {\n window.removeEventListener(\"message\", onMessage);\n if (pollTimerId !== null) {\n clearInterval(pollTimerId);\n pollTimerId = null;\n }\n if (timeoutTimerId !== null) {\n clearTimeout(timeoutTimerId);\n timeoutTimerId = null;\n }\n }\n\n function forceClosePopup(): void {\n if (popup && !popup.closed) {\n try {\n popup.close();\n } catch {\n // Defensive only. We opened this window so we own the close permission;\n // this branch is for esoteric extension or browser-quirk edge cases.\n }\n }\n }\n\n function settleVerified(result: EntrosVerifyResult): void {\n if (settled) return;\n settled = true;\n // The popup owns its own close on the verified path so its\n // recognition surface (`Verified.` checkmark) is visible to the user\n // before the window dies. Parent only force-closes as a defensive\n // fallback in case the popup fails to close itself.\n clearListenersAndTimers();\n setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);\n opts.onVerified(result);\n }\n\n /**\n * @param forceImmediateClose\n * - false (default) — error came from a popup-emitted `entros/error`\n * message; the popup is still alive and rendering its own\n * `PopupFailure` (auto-close) or interactive recovery surface\n * (e.g., baseline-stale). Parent waits the fallback window before\n * force-closing so the user sees the failure category.\n * - true — error came from the parent (timeout, user cancel, or\n * polling detected the popup already closed). No popup-side\n * surface to preserve; force-close immediately.\n */\n function settleError(\n reason: EntrosVerifyErrorReason,\n forceImmediateClose = false,\n ): void {\n if (settled) return;\n settled = true;\n clearListenersAndTimers();\n if (forceImmediateClose) {\n forceClosePopup();\n } else {\n setTimeout(forceClosePopup, POPUP_OWNED_FALLBACK_CLOSE_MS);\n }\n opts.onError({ reason });\n }\n\n function onMessage(event: MessageEvent): void {\n if (settled) return;\n\n // Origin gate — first and most important check.\n if (event.origin !== expectedPopupOrigin) return;\n\n // Source gate — defense-in-depth against another same-origin tab on\n // entros.io (e.g., the standalone /verify route open in a sibling tab)\n // posting a forged message. Only the popup we opened is authoritative.\n if (event.source !== popup) return;\n\n if (!isEntrosMessage(event.data)) return;\n\n // Replay protection — request_id must match this popup's ID.\n if (event.data.request_id !== requestId) return;\n\n if (!isFreshMessage(event.data)) return;\n\n switch (event.data.type) {\n case \"entros/verified\": {\n if (isVerifiedPayload(event.data.payload)) {\n settleVerified({\n walletPubkey: event.data.payload.wallet_pubkey,\n attestationPda: event.data.payload.attestation_pda,\n txSig: event.data.payload.tx_sig,\n trustScore: event.data.payload.trust_score,\n cluster: event.data.payload.cluster,\n });\n }\n break;\n }\n case \"entros/error\": {\n if (isErrorPayload(event.data.payload)) {\n settleError(event.data.payload.reason);\n }\n break;\n }\n case \"entros/heartbeat\": {\n if (isHeartbeatPayload(event.data.payload) && opts.onProgress) {\n opts.onProgress({ status: event.data.payload.status });\n }\n break;\n }\n }\n }\n\n function onPoll(): void {\n if (settled) return;\n if (popup.closed) {\n // Start the grace period the first time we observe the close.\n if (popupClosedAtMs === null) {\n popupClosedAtMs = Date.now();\n return;\n }\n if (Date.now() - popupClosedAtMs >= POPUP_CLOSED_GRACE_MS) {\n settleError(\"user_canceled\", true);\n }\n } else {\n popupClosedAtMs = null;\n }\n }\n\n function onTimeout(): void {\n settleError(\"timeout\", true);\n }\n\n window.addEventListener(\"message\", onMessage);\n pollTimerId = setInterval(onPoll, POPUP_CLOSED_POLL_MS);\n timeoutTimerId = setTimeout(onTimeout, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n\n return {\n cancel: () => settleError(\"user_canceled\", true),\n };\n}\n"],"mappings":";;;AAWA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACkBzD,IAAM,yBAAyB,KAAK;AAGpC,IAAM,gBAAgB,oBAAI,IAAY;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,qBAAqB,oBAAI,IAAY;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,uBAAuB,oBAAI,IAAY;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,WAAW,oBAAI,IAAY,CAAC,UAAU,cAAc,CAAC;AAEpD,SAAS,gBAAgB,MAAsC;AACpE,MAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO;AACtD,QAAM,MAAM;AACZ,SACE,IAAI,WAAW,YACf,IAAI,YAAY,KAChB,OAAO,IAAI,SAAS,YACpB,qBAAqB,IAAI,IAAI,IAAI,KACjC,OAAO,IAAI,eAAe,YAC1B,IAAI,WAAW,SAAS,KACxB,OAAO,IAAI,cAAc,YACzB,OAA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AS,EAAE,MAAM,SAAS,QAAQ,MAAM,OAAO,CAAC;AAChD,mBAAW,UAAU,KAAK;AAC1B,sBAAc;AAAA,MAChB;AAAA,MACA,YAAY,CAAC,aAAa;AACxB,sBAAc,UAAU,QAAQ;AAAA,MAClC;AAAA,IACF,CAAC;AAED,QAAI,WAAW,MAAM;AACnB,eAAS,EAAE,MAAM,UAAU,CAAC;AAC5B,iBAAW,UAAU,EAAE,QAAQ,gBAAgB,CAAC;AAChD;AAAA,IACF;AAEA,cAAU,UAAU;AACpB,aAAS,EAAE,MAAM,UAAU,CAAC;AAAA,EAC9B,GAAG;AAAA,IACD,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AAED,QAAM,YAAY,MAAM,SAAS,aAAa,MAAM,SAAS;AAC7D,QAAM,eACJ,MAAM,SAAS,cAAc,MAAM,wBAAwB;AAE7D,SACE,qBAAC,SAAI,WAAU,2BAA0B,cAAY,MAAM,MACzD;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS;AAAA,QACT,UAAU;AAAA,QACV,WAAW,MAAM;AAAA,QACjB,OAAO,MAAM;AAAA,QAEZ,sBACG,oBACC,MAAM,YAAY;AAAA;AAAA,IACzB;AAAA,IACC,gBACC,qBAAC,SAAI,MAAK,SAAQ,WAAU,yBAC1B;AAAA,0BAAC,UAAK,6BAAe;AAAA,MACrB,oBAAC,YAAO,MAAK,UAAS,SAAS,SAAS,WAAW,MAAM,WAAW,6CAEpE;AAAA,OACF;AAAA,KAEJ;AAEJ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@entros/verify",
3
+ "version": "0.1.0",
4
+ "description": "Drop-in React component for Entros verification — popup-pattern, wallet-connected. The captcha-grade primitive integrators embed to send their users into the Entros verify flow.",
5
+ "license": "MIT",
6
+ "homepage": "https://entros.io",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/entros-protocol/entros-verify.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/entros-protocol/entros-verify/issues"
13
+ },
14
+ "keywords": [
15
+ "entros",
16
+ "solana",
17
+ "proof-of-personhood",
18
+ "verification",
19
+ "react",
20
+ "captcha"
21
+ ],
22
+ "main": "dist/index.js",
23
+ "module": "dist/index.mjs",
24
+ "types": "dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "test": "vitest run",
41
+ "test:watch": "vitest",
42
+ "typecheck": "tsc --noEmit",
43
+ "verify-publish-contents": "node scripts/verify-publish-contents.mjs",
44
+ "prepublishOnly": "npm run typecheck && npm test && npm run verify-publish-contents && npm run build"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^19.0.0",
48
+ "react-dom": "^19.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@testing-library/dom": "^10.4.0",
52
+ "@testing-library/jest-dom": "^6.9.1",
53
+ "@testing-library/react": "^16.3.0",
54
+ "@types/react": "^19.0.0",
55
+ "@types/react-dom": "^19.0.0",
56
+ "jsdom": "^25.0.0",
57
+ "react": "^19.0.0",
58
+ "react-dom": "^19.0.0",
59
+ "tsup": "^8.0.0",
60
+ "typescript": "^6.0.2",
61
+ "vitest": "^3.0.0"
62
+ }
63
+ }