@keyringnetwork/keyring-connect-sdk 3.2.0 → 4.1.0-alpha.2

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.
Files changed (68) hide show
  1. package/dist/core/VerificationSession.d.ts +62 -0
  2. package/dist/core/VerificationSession.js +404 -0
  3. package/dist/core/errors.d.ts +49 -0
  4. package/dist/core/errors.js +81 -0
  5. package/dist/core/htppClient.d.ts +17 -0
  6. package/dist/core/htppClient.js +160 -0
  7. package/dist/{main.d.ts → core/keyringConnectExtension.d.ts} +6 -4
  8. package/dist/{main.js → core/keyringConnectExtension.js} +33 -16
  9. package/dist/core/websocketClient.d.ts +23 -0
  10. package/dist/core/websocketClient.js +220 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +3 -3
  13. package/dist/types/api.d.ts +24 -0
  14. package/dist/types/api.js +2 -0
  15. package/dist/types/core.d.ts +78 -0
  16. package/dist/types/core.js +2 -0
  17. package/dist/{types.d.ts → types/extension.d.ts} +2 -49
  18. package/dist/types/index.d.ts +4 -0
  19. package/dist/types/index.js +20 -0
  20. package/dist/types/websocket.d.ts +68 -0
  21. package/dist/types/websocket.js +3 -0
  22. package/dist/ui/UIManager.d.ts +52 -0
  23. package/dist/ui/UIManager.js +257 -0
  24. package/dist/ui/components/keyring-button.d.ts +12 -0
  25. package/dist/ui/components/keyring-button.js +140 -0
  26. package/dist/ui/components/keyring-text.d.ts +12 -0
  27. package/dist/ui/components/keyring-text.js +169 -0
  28. package/dist/ui/composites/keyring-complete-modal.d.ts +19 -0
  29. package/dist/ui/composites/keyring-complete-modal.js +200 -0
  30. package/dist/ui/composites/keyring-mobile-modal.d.ts +25 -0
  31. package/dist/ui/composites/keyring-mobile-modal.js +308 -0
  32. package/dist/ui/composites/keyring-qr-modal.d.ts +32 -0
  33. package/dist/ui/composites/keyring-qr-modal.js +464 -0
  34. package/dist/ui/composites/keyring-selection-modal.d.ts +25 -0
  35. package/dist/ui/composites/keyring-selection-modal.js +342 -0
  36. package/dist/ui/composites/keyring-terminated-modal.d.ts +14 -0
  37. package/dist/ui/composites/keyring-terminated-modal.js +121 -0
  38. package/dist/ui/icons/apple-icon.d.ts +4 -0
  39. package/dist/ui/icons/apple-icon.js +47 -0
  40. package/dist/ui/icons/check-circle.d.ts +4 -0
  41. package/dist/ui/icons/check-circle.js +35 -0
  42. package/dist/ui/icons/checkmark.d.ts +4 -0
  43. package/dist/ui/icons/checkmark.js +37 -0
  44. package/dist/ui/icons/close-circle.d.ts +4 -0
  45. package/dist/ui/icons/close-circle.js +35 -0
  46. package/dist/ui/icons/error-circle.d.ts +4 -0
  47. package/dist/ui/icons/error-circle.js +48 -0
  48. package/dist/ui/icons/extension-grid.d.ts +4 -0
  49. package/dist/ui/icons/extension-grid.js +79 -0
  50. package/dist/ui/icons/google-icon.d.ts +4 -0
  51. package/dist/ui/icons/google-icon.js +55 -0
  52. package/dist/ui/icons/gradient-donut.d.ts +8 -0
  53. package/dist/ui/icons/gradient-donut.js +85 -0
  54. package/dist/ui/icons/keyring.d.ts +4 -0
  55. package/dist/ui/icons/keyring.js +71 -0
  56. package/dist/ui/icons/mobile-grid.d.ts +4 -0
  57. package/dist/ui/icons/mobile-grid.js +68 -0
  58. package/dist/ui/icons/success.d.ts +4 -0
  59. package/dist/ui/icons/success.js +54 -0
  60. package/dist/utils/environment.d.ts +34 -0
  61. package/dist/utils/environment.js +67 -0
  62. package/dist/utils/logger.d.ts +7 -0
  63. package/dist/utils/logger.js +40 -0
  64. package/dist/utils/platformUtils.d.ts +24 -0
  65. package/dist/utils/platformUtils.js +64 -0
  66. package/package.json +29 -14
  67. package/readme.md +57 -105
  68. /package/dist/{types.js → types/extension.js} +0 -0
@@ -0,0 +1,464 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.KeyringQRModal = void 0;
19
+ const lit_1 = require("lit");
20
+ const decorators_js_1 = require("lit/decorators.js");
21
+ require("../components/keyring-button");
22
+ require("../components/keyring-text");
23
+ require("../icons/apple-icon");
24
+ require("../icons/checkmark");
25
+ require("../icons/google-icon");
26
+ require("../icons/gradient-donut");
27
+ let KeyringQRModal = class KeyringQRModal extends lit_1.LitElement {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.sessionId = "";
31
+ this.expiresAt = 0;
32
+ this.qrData = "";
33
+ this.qrCodeError = false;
34
+ this.status = "pending";
35
+ this.statusMessage = "Waiting for mobile app...";
36
+ this.timeLeft = "";
37
+ this.linkCopied = false;
38
+ }
39
+ connectedCallback() {
40
+ super.connectedCallback();
41
+ this.startCountdown();
42
+ this.trapFocus();
43
+ }
44
+ disconnectedCallback() {
45
+ super.disconnectedCallback();
46
+ if (this.countdownInterval) {
47
+ clearInterval(this.countdownInterval);
48
+ }
49
+ }
50
+ render() {
51
+ return (0, lit_1.html) `
52
+ <div class="modal" @click=${this.stopPropagation}>
53
+ <div class="header">
54
+ <div class="header-title">
55
+ <button class="close-btn" @click=${this.handleBack} aria-label="Back">
56
+ <svg
57
+ xmlns="http://www.w3.org/2000/svg"
58
+ width="24"
59
+ height="24"
60
+ viewBox="0 0 24 24"
61
+ fill="none"
62
+ >
63
+ <path
64
+ d="M5.29297 11.2938C4.90234 11.6844 4.90234 12.3188 5.29297 12.7094L10.293 17.7094C10.6836 18.1 11.318 18.1 11.7086 17.7094C12.0992 17.3188 12.0992 16.6844 11.7086 16.2938L8.41172 13H17.9992C18.5523 13 18.9992 12.5531 18.9992 12C18.9992 11.4469 18.5523 11 17.9992 11H8.41484L11.7055 7.70627C12.0961 7.31565 12.0961 6.68127 11.7055 6.29065C11.3148 5.90002 10.6805 5.90002 10.2898 6.29065L5.28984 11.2906L5.29297 11.2938Z"
65
+ fill="#0F2830"
66
+ />
67
+ </svg>
68
+ </button>
69
+ <keyring-text variant="text-2xl" weight="medium">Scan QR Code</keyring-text>
70
+ </div>
71
+ <button
72
+ class="close-btn"
73
+ @click=${this.status === "completed" ? this.handleClose : this.handleCancel}
74
+ aria-label="Close"
75
+ >
76
+ <svg
77
+ xmlns="http://www.w3.org/2000/svg"
78
+ width="24"
79
+ height="24"
80
+ viewBox="0 0 24 24"
81
+ fill="none"
82
+ >
83
+ <path
84
+ d="M16.0391 6.54694C16.4296 6.15641 17.0626 6.15641 17.4531 6.54694C17.8436 6.93747 17.8436 7.5705 17.4531 7.961L13.4141 12.0001L17.4531 16.0391C17.8436 16.4297 17.8436 17.0627 17.4531 17.4532C17.0626 17.8437 16.4296 17.8436 16.0391 17.4532L12 13.4141L7.96094 17.4532C7.57044 17.8437 6.93741 17.8436 6.54688 17.4532C6.15635 17.0627 6.15635 16.4296 6.54688 16.0391L10.5859 12.0001L6.54688 7.961C6.15635 7.57047 6.15635 6.93746 6.54688 6.54694C6.9374 6.15641 7.57041 6.15641 7.96094 6.54694L12 10.586L16.0391 6.54694Z"
85
+ fill="#75849A"
86
+ />
87
+ </svg>
88
+ </button>
89
+ </div>
90
+
91
+ <div class="content">
92
+ <div class="qr-container">
93
+ ${this.qrCodeError
94
+ ? (0, lit_1.html) `
95
+ <keyring-text class="qr-title">Unable to generate QR code</keyring-text>
96
+ <keyring-text variant="text-sm" color="secondary" class="qr-subtitle">
97
+ On your mobile device, open the link below to continue verification
98
+ </keyring-text>
99
+ <div class="qr-link-container">
100
+ <keyring-text variant="text-sm" color="primary" class="qr-link"
101
+ >${this.qrData}</keyring-text
102
+ >
103
+ <keyring-button
104
+ variant="ghost"
105
+ size="sm"
106
+ @click=${() => this.onCopy(this.qrData, "linkCopied")}
107
+ >${this.linkCopied ? "Copied" : "Copy"}</keyring-button
108
+ >
109
+ </div>
110
+ `
111
+ : (0, lit_1.html) `
112
+ <keyring-text class="qr-title">Scan with Keyring Connect App</keyring-text>
113
+ <keyring-text variant="text-sm" color="secondary" class="qr-subtitle">
114
+ Open the app and scan this code to continue verification
115
+ </keyring-text>
116
+ <slot name="qr-code"></slot>
117
+ `}
118
+ </div>
119
+
120
+ <div class="app-download">
121
+ <keyring-text>Don't have the app?</keyring-text>
122
+ <div class="app-download-btn-wrapper">
123
+ <a href="https://apps.apple.com/app/keyring-connect/id6635768260" target="_blank">
124
+ <apple-icon></apple-icon>
125
+ </a>
126
+ <a
127
+ href="https://play.google.com/store/apps/details?id=com.keyring.connect"
128
+ target="_blank"
129
+ >
130
+ <google-icon></google-icon>
131
+ </a>
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ <div class="footer">
137
+ <div class="footer-content">
138
+ <div class="footer-branding">
139
+ <keyring-text variant="text-sm" color="secondary"
140
+ >Verification provided by</keyring-text
141
+ >
142
+ <keyring-icon></keyring-icon>
143
+ </div>
144
+ <div class="footer-links">
145
+ <a href="https://www.keyring.network/terms" target="_blank" class="link">
146
+ <keyring-text variant="text-sm" color="secondary"
147
+ >Keyring Terms and Conditions</keyring-text
148
+ >
149
+ </a>
150
+ <a href="https://docs.keyring.network/docs" target="_blank" class="link">
151
+ <keyring-text variant="text-sm" color="secondary">Keyring Docs</keyring-text>
152
+ </a>
153
+ </div>
154
+ </div>
155
+
156
+ <div class="status-container ${this.status}">
157
+ <div class="status-item">
158
+ ${this.getStatusIcon()}
159
+ <keyring-text variant="text-sm">${this.statusMessage}</keyring-text>
160
+ </div>
161
+
162
+ ${this.timeLeft !== "00:00"
163
+ ? (0, lit_1.html) `
164
+ <keyring-text variant="text-xs" color="secondary">
165
+ Expires: <span>${this.timeLeft}</span>
166
+ </keyring-text>
167
+ `
168
+ : (0, lit_1.html) ``}
169
+ </div>
170
+ </div>
171
+ </div>
172
+ `;
173
+ }
174
+ // Public API methods
175
+ updateStatus(message, status) {
176
+ this.statusMessage = message;
177
+ this.status = status;
178
+ }
179
+ // Event handlers
180
+ handleClose() {
181
+ this.dispatchEvent(new CustomEvent("close", { bubbles: true, composed: true }));
182
+ }
183
+ handleCancel() {
184
+ this.dispatchEvent(new CustomEvent("cancel", { bubbles: true, composed: true }));
185
+ }
186
+ handleBack() {
187
+ this.dispatchEvent(new CustomEvent("back", { bubbles: true, composed: true }));
188
+ }
189
+ stopPropagation(e) {
190
+ e.stopPropagation();
191
+ }
192
+ // Utility methods
193
+ startCountdown() {
194
+ if (this.countdownInterval) {
195
+ clearInterval(this.countdownInterval);
196
+ }
197
+ const updateCountdown = () => {
198
+ const now = Date.now();
199
+ const timeLeft = this.expiresAt - now;
200
+ if (timeLeft <= 0) {
201
+ this.timeLeft = "00:00";
202
+ this.updateStatus("Session expired", "expired");
203
+ if (this.countdownInterval)
204
+ clearInterval(this.countdownInterval);
205
+ return;
206
+ }
207
+ const minutes = Math.floor(timeLeft / 60000);
208
+ const seconds = Math.floor((timeLeft % 60000) / 1000);
209
+ this.timeLeft = `${minutes}:${seconds.toString().padStart(2, "0")}`;
210
+ };
211
+ updateCountdown();
212
+ this.countdownInterval = window.setInterval(updateCountdown, 1000);
213
+ }
214
+ trapFocus() {
215
+ var _a;
216
+ // Simple focus trap implementation
217
+ const focusableElements = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
218
+ if (focusableElements && focusableElements.length > 0) {
219
+ focusableElements[0].focus();
220
+ }
221
+ }
222
+ getStatusIcon() {
223
+ switch (this.status) {
224
+ case "pending":
225
+ case "processing":
226
+ return (0, lit_1.html) `<gradient-donut-icon spinning></gradient-donut-icon>`;
227
+ case "connected":
228
+ return (0, lit_1.html) `<checkmark-icon></checkmark-icon>`;
229
+ case "failed":
230
+ return (0, lit_1.html) `<gradient-donut-icon startColour="#EB4577"></gradient-donut-icon>`;
231
+ default:
232
+ return (0, lit_1.html) `<gradient-donut-icon startColour="#75849A"></gradient-donut-icon>`;
233
+ }
234
+ }
235
+ onCopy(text, stateKey) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ navigator.clipboard.writeText(text);
238
+ this[stateKey] = true;
239
+ setTimeout(() => {
240
+ this[stateKey] = false;
241
+ }, 2000);
242
+ });
243
+ }
244
+ };
245
+ exports.KeyringQRModal = KeyringQRModal;
246
+ KeyringQRModal.styles = (0, lit_1.css) `
247
+ :host {
248
+ position: fixed;
249
+ top: 0;
250
+ left: 0;
251
+ right: 0;
252
+ bottom: 0;
253
+ background-color: rgba(15, 40, 48, 0.45);
254
+ display: flex;
255
+ align-items: center;
256
+ justify-content: center;
257
+ z-index: 10000;
258
+ font-family: Inter, "Segoe UI", Roboto, sans-serif;
259
+ }
260
+
261
+ .modal {
262
+ background: white;
263
+ border-radius: 20px;
264
+ display: flex;
265
+ gap: 24px;
266
+ padding: 24px 24px 32px 24px;
267
+ flex-direction: column;
268
+ align-items: center;
269
+ max-width: 524px;
270
+ width: 100%;
271
+ max-height: 90vh;
272
+ overflow-y: auto;
273
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
274
+ }
275
+
276
+ .header {
277
+ display: flex;
278
+ justify-content: space-between;
279
+ align-items: flex-start;
280
+ width: 100%;
281
+ }
282
+
283
+ .header-title {
284
+ display: flex;
285
+ align-items: center;
286
+ justify-content: space-between;
287
+ gap: 12px;
288
+ }
289
+
290
+ .close-btn {
291
+ background-color: transparent;
292
+ border: none;
293
+ cursor: pointer;
294
+ padding: 4px;
295
+ border-radius: 8px;
296
+ transition: all 300ms ease-in-out;
297
+ }
298
+
299
+ .close-btn:hover {
300
+ background-color: #75849a1a;
301
+ }
302
+
303
+ .content {
304
+ width: 100%;
305
+ display: flex;
306
+ flex-direction: column;
307
+ align-items: center;
308
+ justify-content: center;
309
+ gap: 24px;
310
+ }
311
+
312
+ .content > * {
313
+ width: 100%;
314
+ }
315
+
316
+ .qr-container {
317
+ display: flex;
318
+ flex-direction: column;
319
+ align-items: center;
320
+ justify-content: center;
321
+ padding-top: 24px;
322
+ padding-bottom: 16px;
323
+ border-radius: 12px;
324
+ border: 1px solid #e3e7ee;
325
+ }
326
+
327
+ .qr-container .qr-title {
328
+ margin-bottom: 12px;
329
+ }
330
+
331
+ .qr-container .qr-subtitle {
332
+ margin-bottom: 16px;
333
+ }
334
+
335
+ .app-download {
336
+ display: flex;
337
+ flex-direction: column;
338
+ align-items: center;
339
+ justify-content: center;
340
+ gap: 24px;
341
+ }
342
+
343
+ .app-download-btn-wrapper {
344
+ display: flex;
345
+ gap: 12px;
346
+ width: 100%;
347
+ align-items: center;
348
+ justify-content: center;
349
+ }
350
+
351
+ .app-download-btn-wrapper a {
352
+ text-decoration: none;
353
+ transition: all 300ms ease-in-out;
354
+ }
355
+
356
+ .app-download-btn-wrapper a:hover {
357
+ opacity: 0.8;
358
+ }
359
+
360
+ .status-container {
361
+ margin: 24px -24px -32px;
362
+ padding: 16px;
363
+ border-top: 1px solid #e3e7ee;
364
+ background-color: #f3f5fa;
365
+ display: flex;
366
+ flex-direction: column;
367
+ justify-content: center;
368
+ align-items: center;
369
+ }
370
+
371
+ .status-container.connected {
372
+ background-color: #f2fcf7;
373
+ border-color: #e3e7ee;
374
+ }
375
+
376
+ .status-container.failed {
377
+ background-color: #ffefef;
378
+ border-color: #e3e7ee;
379
+ }
380
+
381
+ .status-item {
382
+ display: flex;
383
+ align-items: center;
384
+ justify-content: center;
385
+ gap: 12px;
386
+ }
387
+
388
+ .footer {
389
+ width: 100%;
390
+ border-top: 1px solid rgba(15, 40, 48, 0.12);
391
+ }
392
+
393
+ .footer-content {
394
+ display: flex;
395
+ flex-direction: column;
396
+ gap: 12px;
397
+ margin-top: 24px;
398
+ }
399
+
400
+ .footer-branding {
401
+ display: flex;
402
+ gap: 12px;
403
+ align-items: center;
404
+ justify-content: center;
405
+ }
406
+
407
+ .footer-links {
408
+ width: 100%;
409
+ display: flex;
410
+ gap: 24px;
411
+ align-items: center;
412
+ justify-content: center;
413
+ }
414
+
415
+ a {
416
+ text-decoration: none;
417
+ color: inherit;
418
+ cursor: pointer;
419
+ }
420
+
421
+ a:hover {
422
+ text-decoration: underline;
423
+ color: #75849a;
424
+ }
425
+
426
+ .qr-link-container {
427
+ display: flex;
428
+ align-items: center;
429
+ gap: 8px;
430
+ }
431
+
432
+ .qr-link {
433
+ padding: 4px 8px;
434
+ border: 1px solid rgba(15, 40, 48, 0.12);
435
+ border-radius: 8px;
436
+ }
437
+ `;
438
+ __decorate([
439
+ (0, decorators_js_1.property)({ attribute: "session-id" })
440
+ ], KeyringQRModal.prototype, "sessionId", void 0);
441
+ __decorate([
442
+ (0, decorators_js_1.property)({ attribute: "expires-at", type: Number })
443
+ ], KeyringQRModal.prototype, "expiresAt", void 0);
444
+ __decorate([
445
+ (0, decorators_js_1.property)({ attribute: "qr-data" })
446
+ ], KeyringQRModal.prototype, "qrData", void 0);
447
+ __decorate([
448
+ (0, decorators_js_1.property)({ attribute: "qr-code-error" })
449
+ ], KeyringQRModal.prototype, "qrCodeError", void 0);
450
+ __decorate([
451
+ (0, decorators_js_1.state)()
452
+ ], KeyringQRModal.prototype, "status", void 0);
453
+ __decorate([
454
+ (0, decorators_js_1.state)()
455
+ ], KeyringQRModal.prototype, "statusMessage", void 0);
456
+ __decorate([
457
+ (0, decorators_js_1.state)()
458
+ ], KeyringQRModal.prototype, "timeLeft", void 0);
459
+ __decorate([
460
+ (0, decorators_js_1.state)()
461
+ ], KeyringQRModal.prototype, "linkCopied", void 0);
462
+ exports.KeyringQRModal = KeyringQRModal = __decorate([
463
+ (0, decorators_js_1.customElement)("keyring-qr-modal")
464
+ ], KeyringQRModal);
@@ -0,0 +1,25 @@
1
+ import { LitElement } from "lit";
2
+ import "../components/keyring-button";
3
+ import "../components/keyring-text";
4
+ import "../icons/check-circle";
5
+ import "../icons/close-circle";
6
+ import "../icons/extension-grid";
7
+ import "../icons/gradient-donut";
8
+ import "../icons/keyring";
9
+ import "../icons/mobile-grid";
10
+ export declare class KeyringSelectionModal extends LitElement {
11
+ title: string;
12
+ subtitle: string;
13
+ isExtensionInstalled: boolean;
14
+ extensionBtnText: string;
15
+ mobileBtnText: string;
16
+ private mobileSelected;
17
+ static styles: import("lit").CSSResult;
18
+ connectedCallback(): void;
19
+ render(): import("lit").TemplateResult<1>;
20
+ private handleCancel;
21
+ private handleExtensionSelect;
22
+ private handleMobileSelect;
23
+ private stopPropagation;
24
+ private trapFocus;
25
+ }