@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,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KeyringLogger = void 0;
7
+ const pino_1 = __importDefault(require("pino"));
8
+ const package_json_1 = __importDefault(require("../../package.json"));
9
+ class KeyringLogger {
10
+ static init(scope) {
11
+ const logger = this.createPinoLogger(scope);
12
+ return logger;
13
+ }
14
+ static createPinoLogger(scope) {
15
+ const metadata = {
16
+ scope,
17
+ packageVersion: this.packageVersion,
18
+ };
19
+ const logger = (0, pino_1.default)({
20
+ name: this.prefix,
21
+ level: "debug",
22
+ browser: {
23
+ asObject: true,
24
+ formatters: {
25
+ level: (label) => ({
26
+ level: label.toUpperCase(),
27
+ }),
28
+ log(object) {
29
+ return Object.assign(Object.assign({}, object), { metadata });
30
+ },
31
+ },
32
+ },
33
+ timestamp: () => `${new Date(Date.now()).toISOString()}`,
34
+ });
35
+ return logger;
36
+ }
37
+ }
38
+ exports.KeyringLogger = KeyringLogger;
39
+ KeyringLogger.prefix = "[Keyring SDK]";
40
+ KeyringLogger.packageVersion = package_json_1.default.version;
@@ -0,0 +1,24 @@
1
+ export interface PlatformInfo {
2
+ isDesktop: boolean;
3
+ isMobile: boolean;
4
+ isAndroid: boolean;
5
+ isIOS: boolean;
6
+ }
7
+ export declare class PlatformUtils {
8
+ /**
9
+ * Detect the current platform and capabilities
10
+ */
11
+ static detectPlatform(): PlatformInfo;
12
+ /**
13
+ * Check if Chrome runtime is available for extension communication
14
+ */
15
+ static isChromeRuntimeAvailable(): boolean;
16
+ /**
17
+ * Check if running in browser environment
18
+ */
19
+ static isBrowser(): boolean;
20
+ /**
21
+ * Wait for online status
22
+ */
23
+ static waitForOnline(timeout?: number): Promise<boolean>;
24
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformUtils = void 0;
4
+ class PlatformUtils {
5
+ /**
6
+ * Detect the current platform and capabilities
7
+ */
8
+ static detectPlatform() {
9
+ const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "";
10
+ const isAndroid = /Android/i.test(userAgent);
11
+ const isIOS = /iPad|iPhone|iPod/.test(userAgent);
12
+ const isMobile = isAndroid ||
13
+ isIOS ||
14
+ /Mobile|Opera Mini|Fennec|webOS|BlackBerry|PlayBook|BB10|IEMobile/i.test(userAgent);
15
+ const isDesktop = !isMobile;
16
+ return {
17
+ isDesktop,
18
+ isMobile,
19
+ isAndroid,
20
+ isIOS,
21
+ };
22
+ }
23
+ /**
24
+ * Check if Chrome runtime is available for extension communication
25
+ */
26
+ static isChromeRuntimeAvailable() {
27
+ var _a;
28
+ try {
29
+ return typeof ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.sendMessage) === "function";
30
+ }
31
+ catch (error) {
32
+ return false;
33
+ }
34
+ }
35
+ /**
36
+ * Check if running in browser environment
37
+ */
38
+ static isBrowser() {
39
+ return typeof window !== "undefined";
40
+ }
41
+ /**
42
+ * Wait for online status
43
+ */
44
+ static waitForOnline(timeout = 30000) {
45
+ return new Promise((resolve) => {
46
+ if (typeof navigator === "undefined" || navigator.onLine) {
47
+ resolve(true);
48
+ return;
49
+ }
50
+ let timeoutId;
51
+ const onOnline = () => {
52
+ clearTimeout(timeoutId);
53
+ window.removeEventListener("online", onOnline);
54
+ resolve(true);
55
+ };
56
+ window.addEventListener("online", onOnline);
57
+ timeoutId = setTimeout(() => {
58
+ window.removeEventListener("online", onOnline);
59
+ resolve(false);
60
+ }, timeout);
61
+ });
62
+ }
63
+ }
64
+ exports.PlatformUtils = PlatformUtils;
package/package.json CHANGED
@@ -1,34 +1,49 @@
1
1
  {
2
2
  "name": "@keyringnetwork/keyring-connect-sdk",
3
- "version": "3.2.0",
3
+ "version": "4.1.0-alpha.2",
4
4
  "description": "An SDK for interacting with Keyring Connect browser extension",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
- "scripts": {
8
- "build": "rm -rf dist && tsc",
9
- "dev": "tsc --watch",
10
- "build_and_publish": "pnpm build && npm publish",
11
- "test": "jest",
12
- "test:watch": "jest --watch",
13
- "test:coverage": "jest --coverage",
14
- "test:ci": "jest --ci --coverage --watchAll=false"
15
- },
16
7
  "files": [
17
8
  "dist"
18
9
  ],
19
- "keywords": [],
20
- "author": "",
10
+ "keywords": [
11
+ "keyring",
12
+ "keyring connect",
13
+ "sdk"
14
+ ],
15
+ "author": "Keyring Network",
21
16
  "license": "ISC",
22
17
  "devDependencies": {
23
18
  "@types/chrome": "^0.0.268",
24
19
  "@types/jest": "^29.5.0",
20
+ "@types/qrcode": "^1.5.5",
21
+ "autoprefixer": "^10.4.21",
25
22
  "jest": "^29.7.0",
26
23
  "jest-environment-jsdom": "^29.7.0",
24
+ "postcss": "^8.5.6",
25
+ "tailwindcss": "^3.4.17",
27
26
  "ts-jest": "^29.1.0",
28
27
  "ts-node": "^10.9.2",
29
28
  "typescript": "^5.6.3"
30
29
  },
31
30
  "dependencies": {
32
- "@keyringnetwork/contracts-abi": "2.6.0"
31
+ "@keyringnetwork/contracts-abi": "2.6.1",
32
+ "@keyringnetwork/keyring-dtos": "1.0.0",
33
+ "axios": "^1.12.2",
34
+ "lit": "^3.3.1",
35
+ "pino": "^9.13.1",
36
+ "qr-code-styling": "^1.9.2",
37
+ "socket.io-client": "^4.8.1"
38
+ },
39
+ "scripts": {
40
+ "build:ts": "tsc",
41
+ "build": "rm -rf dist && npm run build:ts",
42
+ "dev": "tsc --watch",
43
+ "prepublish": "pnpm build",
44
+ "test": "jest",
45
+ "test:watch": "jest --watch",
46
+ "test:coverage": "jest --coverage",
47
+ "test:ci": "jest --ci --coverage --watchAll=false"
33
48
  }
34
- }
49
+ }
package/readme.md CHANGED
@@ -1,146 +1,98 @@
1
1
  # Keyring Connect SDK
2
2
 
3
- A TypeScript SDK for integrating with the Keyring Connect browser extension. This SDK enables seamless interaction with the Keyring Connect extension for user verification and attestation.
3
+ TypeScript SDK for integrating Keyring identity verification into web applications. Supports both browser extension and mobile app verification flows.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @keyringnetwork/keyring-connect-sdk
9
- yarn add @keyringnetwork/keyring-connect-sdk
10
8
  pnpm install @keyringnetwork/keyring-connect-sdk
11
9
  ```
12
10
 
13
- ## Features
14
-
15
- - Check if the extension is installed
16
- - Launch Keyring Connect with custom client configuration
17
- - Redirect the user back to the app where they left off after extension installation
18
- - Monitor extension status and user state
19
- - Full TypeScript support with comprehensive type definitions
20
-
21
- ## Usage
22
-
23
- ### Initialize
11
+ ## Quick Start
24
12
 
25
13
  ```typescript
26
- import { KeyringConnect } from "@keyringnetwork/keyring-connect-sdk";
27
- ```
28
-
29
- ### Check if the extension is installed
14
+ import { VerificationSession } from "@keyringnetwork/keyring-connect-sdk";
30
15
 
31
- ```typescript
32
- const isInstalled = await KeyringConnect.isKeyringConnectInstalled();
33
- ```
34
-
35
- ### Launch Keyring Connect
36
-
37
- ```typescript
38
- const extensionConfig = {
16
+ const session = await VerificationSession.launch({
39
17
  name: "My App",
40
18
  app_url: "https://myapp.com",
41
19
  logo_url: "https://myapp.com/logo.png",
42
20
  policy_id: 123,
21
+ api_key: "your-api-key",
43
22
  credential_config: {
44
23
  chain_id: 1,
45
- wallet_address: '0x123abc'
46
- }
47
- };
24
+ wallet_address: "0x123...",
25
+ },
26
+ });
48
27
 
49
- // This method handles both launching the extension if installed
50
- // or redirecting to the Chrome Web Store if not installed
51
28
  try {
52
- await KeyringConnect.launchExtension(extensionConfig);
29
+ const credential = await session.start();
30
+ console.log("Verification successful:", credential);
53
31
  } catch (error) {
54
- console.error("Failed to launch Keyring Connect:", error);
32
+ console.error("Verification failed:", error);
55
33
  }
56
34
  ```
57
35
 
58
- ### Monitor Extension Status
36
+ ## Features
59
37
 
60
- ```typescript
61
- export interface ExtensionState {
62
- status: "idle" | "mounted" | "proving" | "prove_success" | "error";
63
- manifest?: any;
64
- error?: string; // error message, only if status is 'error'
65
- user?: User;
66
- }
38
+ - Multi-platform support - Browser extension for desktop, QR code flow for mobile
39
+ - Real-time updates - WebSocket-based status updates during verification
40
+ - Built-in UI - Ready-to-use modals for platform selection, QR codes, and status
41
+ - TypeScript - Full type definitions included
42
+ - Error handling - Structured errors with `KeyringError` and error codes
67
43
 
68
- const extensionState = await KeyringConnect.getExtensionState();
69
- ```
44
+ ## API
70
45
 
71
- ### Integration Example
46
+ ### VerificationSession
47
+
48
+ Main entry point for verification flows.
72
49
 
73
50
  ```typescript
74
- import { useEffect, useState } from "react";
75
- import {
76
- ExtensionSDKConfig,
77
- KeyringConnect,
78
- } from "@keyringnetwork/keyring-connect-sdk";
79
-
80
- function KeyringConnectButton() {
81
- const [isInstalled, setIsInstalled] = useState<boolean | undefined>(
82
- undefined
83
- );
84
-
85
- // Check if extension is installed
86
- useEffect(() => {
87
- const checkExtension = async () => {
88
- const isInstalled = await KeyringConnect.isKeyringConnectInstalled();
89
- setIsInstalled(isInstalled);
90
- };
91
- checkExtension();
92
- }, []);
93
-
94
- // Configure your app
95
- const config: ExtensionSDKConfig = {
96
- app_url: window.location.origin,
97
- name: "My App",
98
- logo_url: "https://myapp.com/logo.png",
99
- policy_id: 7,
100
- };
51
+ // Launch a new session
52
+ const session = await VerificationSession.launch(config);
101
53
 
102
- // Launch the extension (handles both installed and not installed cases)
103
- const launchExtension = () => {
104
- KeyringConnect.launchExtension(config);
105
- };
54
+ // Start verification (returns credential on success)
55
+ const credential = await session.start();
106
56
 
107
- if (isInstalled === undefined) {
108
- return <button disabled>Checking extension...</button>;
109
- }
57
+ // Listen to events
58
+ session.addEventListener("processingStarted", (data) => {
59
+ console.log("Processing started");
60
+ });
110
61
 
111
- return (
112
- <button onClick={launchExtension}>
113
- {isInstalled ? "Launch Extension" : "Install Extension"}
114
- </button>
115
- );
116
- }
62
+ // Clean up
63
+ await session.close();
117
64
  ```
118
65
 
119
- ## API Reference
120
-
121
- #### Core Types Overview
122
-
123
- - `ExtensionConfig`: Configuration for initializing the Keyring Connect extension
124
- - `ExtensionState`: Current state and status information of the extension
125
- - `User`: User's verification and credential status information
126
-
127
- #### Status Types
66
+ ### SessionConfig
128
67
 
129
- - `ExtensionStatus`: Extension states (`idle`, `mounted`, `proving`, `prove_error`, `prove_success`, `error`)
130
- - `AttestationStatus`: Off-chain verification status (`onboarding_required`, `onboarding_pending`, `attestation_ready`, `non_compliant`)
131
- - `CredentialStatus`: On-chain credential status (`expired`, `valid`, `none`)
68
+ ```typescript
69
+ interface SessionConfig {
70
+ name: string; // App display name
71
+ app_url: string; // Your app URL
72
+ logo_url: string; // App logo for modals
73
+ policy_id: number; // On-chain Keyring policy ID
74
+ api_key: string; // Your API key
75
+ credential_config: {
76
+ chain_id: number; // Target chain ID
77
+ wallet_address: string; // User's wallet address
78
+ };
79
+ }
80
+ ```
132
81
 
133
- ## Extension States
82
+ ### Events
134
83
 
135
- - **idle**: Extension is installed but not active
136
- - **mounted**: Extension is launched and ready
137
- - **proving**: Currently generating proof
138
- - **prove_success**: Proof generation successful
139
- - **error**: An error occurred
84
+ - `mobileConnected` - Mobile app connected via QR scan
85
+ - `processingStarted` - Verification processing began
86
+ - `processingCompleted` - Verification successful
87
+ - `sessionExpired` - Session timed out
88
+ - `error` - An error occurred
140
89
 
141
90
  ## Requirements
142
91
 
143
- - An on-chain Keyring policy
144
- - Chrome browser (version 88 or higher recommended)
145
- - Keyring Connect browser extension installed
92
+ - Chrome browser (v88+) for extension flow
146
93
  - Active internet connection
94
+ - On-chain Keyring policy
95
+
96
+ ## License
97
+
98
+ ISC
File without changes