@qidcloud/sdk 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -276
- package/dist/components/QidSignInButton.d.ts +15 -0
- package/dist/hooks/useQidAuth.d.ts +18 -0
- package/dist/index.d.ts +24 -4
- package/dist/index.js +2432 -5
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2425 -0
- package/dist/index.mjs.map +1 -0
- package/dist/modules/auth.d.ts +23 -0
- package/dist/modules/db.d.ts +21 -0
- package/dist/modules/edge.d.ts +61 -0
- package/dist/modules/logs.d.ts +20 -0
- package/dist/modules/vault.d.ts +57 -0
- package/dist/types.d.ts +46 -0
- package/package.json +34 -30
- package/rollup.config.mjs +26 -0
- package/src/components/QidSignInButton.tsx +174 -0
- package/src/hooks/useQidAuth.ts +104 -0
- package/src/index.ts +54 -4
- package/src/modules/auth.ts +77 -0
- package/src/modules/db.ts +40 -0
- package/src/modules/edge.ts +98 -0
- package/src/modules/logs.ts +30 -0
- package/src/modules/vault.ts +124 -0
- package/src/types.ts +52 -0
- package/tsconfig.json +30 -19
- package/dist/QidCloud.d.ts +0 -31
- package/dist/QidCloud.js +0 -142
- package/dist/crypto/pqc.d.ts +0 -12
- package/dist/crypto/pqc.js +0 -91
- package/dist/storage/index.d.ts +0 -18
- package/dist/storage/index.js +0 -58
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -46
- package/src/QidCloud.ts +0 -171
- package/src/crypto/pqc.ts +0 -79
- package/src/storage/index.ts +0 -49
- package/src/utils.ts +0 -48
- package/verify_sdk.ts +0 -53
package/README.md
CHANGED
|
@@ -1,310 +1,68 @@
|
|
|
1
1
|
# @qidcloud/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official JavaScript/TypeScript SDK for QidCloud. Build PQC-secured, enclave-backed applications in minutes.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 🚀 30-Minute Quick Start
|
|
6
6
|
|
|
7
|
+
### 1. Install
|
|
7
8
|
```bash
|
|
8
9
|
npm install @qidcloud/sdk
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
### 2. Initialize
|
|
13
13
|
```typescript
|
|
14
14
|
import { QidCloud } from '@qidcloud/sdk';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// baseUrl is optional, defaults to https://qgate.onrender.com
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Register a new user
|
|
23
|
-
const user = await qgate.register('alice');
|
|
24
|
-
|
|
25
|
-
// Login
|
|
26
|
-
const token = await qgate.login();
|
|
27
|
-
|
|
28
|
-
// Get user profile
|
|
29
|
-
const profile = await qgate.getProfile();
|
|
30
|
-
|
|
31
|
-
// Logout
|
|
32
|
-
await qgate.logout();
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Features
|
|
36
|
-
|
|
37
|
-
✅ **Quantum-Resistant** - Uses CRYSTALS-Dilithium and Kyber
|
|
38
|
-
✅ **Passwordless** - No passwords to remember or manage
|
|
39
|
-
✅ **Zero-Knowledge** - Keys never leave the device
|
|
40
|
-
✅ **TypeScript Support** - Full type definitions included
|
|
41
|
-
✅ **Browser & Node.js** - Works everywhere
|
|
42
|
-
|
|
43
|
-
## API Reference
|
|
44
|
-
|
|
45
|
-
### `new QidCloud(config)`
|
|
46
|
-
|
|
47
|
-
Initialize the QidCloud client.
|
|
48
|
-
|
|
49
|
-
**Parameters:**
|
|
50
|
-
- `config.apiKey` (required): Your QidCloud API key
|
|
51
|
-
- `config.baseUrl` (optional): Custom backend URL, defaults to `https://qgate.onrender.com`
|
|
52
|
-
- `config.storage` (optional): Custom storage implementation (defaults to localStorage in browser, memory in Node.js)
|
|
53
|
-
|
|
54
|
-
**Example:**
|
|
55
|
-
```typescript
|
|
56
|
-
const qgate = new QidCloud({
|
|
57
|
-
apiKey: 'qg-abc123...',
|
|
58
|
-
baseUrl: 'https://custom-backend.com' // optional
|
|
16
|
+
const qid = new QidCloud({
|
|
17
|
+
apiKey: 'your_api_key', // Found in QidCloud Console -> Settings
|
|
18
|
+
tenantId: 'your_project_id'
|
|
59
19
|
});
|
|
60
20
|
```
|
|
61
21
|
|
|
62
22
|
---
|
|
63
23
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Register a new user identity.
|
|
24
|
+
## 🔑 Identity (`qid.auth`)
|
|
67
25
|
|
|
68
|
-
|
|
69
|
-
- `username` (required): Unique username
|
|
70
|
-
- `tenantId` (optional): Custom tenant ID, defaults to 'default'
|
|
71
|
-
|
|
72
|
-
**Returns:** `Promise<UserProfile>`
|
|
73
|
-
|
|
74
|
-
**Example:**
|
|
75
|
-
```typescript
|
|
76
|
-
const user = await qgate.register('alice');
|
|
77
|
-
console.log(user);
|
|
78
|
-
// { userId: "uuid", username: "alice", role: "user" }
|
|
79
|
-
```
|
|
26
|
+
Enforce Pure Post-Quantum Identity with zero passwords.
|
|
80
27
|
|
|
81
|
-
|
|
28
|
+
### `createSession()`
|
|
29
|
+
Initiates a new QR handshake session.
|
|
30
|
+
- **Returns**: `Promise<QidAuthSession>`
|
|
82
31
|
|
|
83
32
|
---
|
|
84
33
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Authenticate using stored identity.
|
|
88
|
-
|
|
89
|
-
**Returns:** `Promise<string>` - Session token
|
|
34
|
+
## 🏗️ React Integration
|
|
90
35
|
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
const token = await qgate.login();
|
|
94
|
-
// Use token for API requests
|
|
95
|
-
```
|
|
36
|
+
The SDK provides powerful React tools for seamless integration.
|
|
96
37
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
- `MISSING_USER_ID` - Re-registration required
|
|
38
|
+
### `useQidAuth(sdk)`
|
|
39
|
+
The recommended way to manage auth state in React.
|
|
100
40
|
|
|
101
|
-
|
|
41
|
+
```tsx
|
|
42
|
+
import { useQidAuth } from '@qidcloud/sdk';
|
|
102
43
|
|
|
103
|
-
|
|
44
|
+
function MyComponent({ qid }) {
|
|
45
|
+
const { user, token, session, login, initializing } = useQidAuth(qid);
|
|
104
46
|
|
|
105
|
-
|
|
47
|
+
if (user) return <p>Welcome, {user.username}</p>;
|
|
106
48
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const profile = await qgate.getProfile();
|
|
112
|
-
console.log(profile);
|
|
113
|
-
// { userId: "uuid", username: "alice", role: "user", status: "active" }
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
**Requires:** Active session (must be logged in)
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
### `qgate.logout()`
|
|
121
|
-
|
|
122
|
-
End the current session.
|
|
123
|
-
|
|
124
|
-
**Returns:** `Promise<void>`
|
|
125
|
-
|
|
126
|
-
**Example:**
|
|
127
|
-
```typescript
|
|
128
|
-
await qgate.logout();
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
**Note:** Local keys are preserved for future login.
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
### `qgate.hasIdentity()`
|
|
136
|
-
|
|
137
|
-
Check if user has registered identity.
|
|
138
|
-
|
|
139
|
-
**Returns:** `Promise<boolean>`
|
|
140
|
-
|
|
141
|
-
**Example:**
|
|
142
|
-
```typescript
|
|
143
|
-
if (await qgate.hasIdentity()) {
|
|
144
|
-
await qgate.login();
|
|
145
|
-
} else {
|
|
146
|
-
await qgate.register('alice');
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Advanced Usage
|
|
153
|
-
|
|
154
|
-
### Custom Storage
|
|
155
|
-
|
|
156
|
-
Provide your own storage implementation:
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
import { QidCloud, IStorage } from '@qidcloud/sdk';
|
|
160
|
-
|
|
161
|
-
class CustomStorage implements IStorage {
|
|
162
|
-
async getItem(key: string): Promise<string | null> {
|
|
163
|
-
// Your implementation
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async setItem(key: string, value: string): Promise<void> {
|
|
167
|
-
// Your implementation
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async removeItem(key: string): Promise<void> {
|
|
171
|
-
// Your implementation
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const qgate = new QidCloud({
|
|
176
|
-
apiKey: 'your-key',
|
|
177
|
-
storage: new CustomStorage()
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Error Handling
|
|
182
|
-
|
|
183
|
-
```typescript
|
|
184
|
-
try {
|
|
185
|
-
await qgate.login();
|
|
186
|
-
} catch (error) {
|
|
187
|
-
if (error.message === 'NO_IDENTITY') {
|
|
188
|
-
console.log('User not registered');
|
|
189
|
-
} else if (error.response?.status === 401) {
|
|
190
|
-
console.log('Authentication failed');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Session Management
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
// Check if user is logged in
|
|
199
|
-
const hasIdentity = await qgate.hasIdentity();
|
|
200
|
-
|
|
201
|
-
// Auto-login on app start
|
|
202
|
-
if (hasIdentity) {
|
|
203
|
-
try {
|
|
204
|
-
await qgate.login();
|
|
205
|
-
} catch {
|
|
206
|
-
// Handle expired/invalid session
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## TypeScript
|
|
212
|
-
|
|
213
|
-
Full TypeScript support included:
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
import { QidCloud, QidConfig, UserProfile } from '@qidcloud/sdk';
|
|
217
|
-
|
|
218
|
-
const config: QidConfig = {
|
|
219
|
-
apiKey: 'your-key'
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const qgate = new QidCloud(config);
|
|
223
|
-
|
|
224
|
-
const profile: UserProfile = await qgate.getProfile();
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## Security Notes
|
|
228
|
-
|
|
229
|
-
🔒 **Private keys never leave the device**
|
|
230
|
-
🔒 **All communication is encrypted**
|
|
231
|
-
🔒 **Quantum-resistant cryptography**
|
|
232
|
-
🔒 **Store API keys securely (environment variables)**
|
|
233
|
-
|
|
234
|
-
## Examples
|
|
235
|
-
|
|
236
|
-
### React Integration
|
|
237
|
-
|
|
238
|
-
```typescript
|
|
239
|
-
import { useState, useEffect } from 'react';
|
|
240
|
-
import { QidCloud } from '@qidcloud/sdk';
|
|
241
|
-
|
|
242
|
-
const qgate = new QidCloud({ apiKey: process.env.REACT_APP_QGATE_KEY });
|
|
243
|
-
|
|
244
|
-
function App() {
|
|
245
|
-
const [user, setUser] = useState(null);
|
|
246
|
-
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
async function init() {
|
|
249
|
-
if (await qgate.hasIdentity()) {
|
|
250
|
-
await qgate.login();
|
|
251
|
-
const profile = await qgate.getProfile();
|
|
252
|
-
setUser(profile);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
init();
|
|
256
|
-
}, []);
|
|
257
|
-
|
|
258
|
-
const register = async (username) => {
|
|
259
|
-
const user = await qgate.register(username);
|
|
260
|
-
setUser(user);
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
const logout = async () => {
|
|
264
|
-
await qgate.logout();
|
|
265
|
-
setUser(null);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
return user ? (
|
|
269
|
-
<div>
|
|
270
|
-
<h1>Welcome, {user.username}!</h1>
|
|
271
|
-
<button onClick={logout}>Logout</button>
|
|
272
|
-
</div>
|
|
273
|
-
) : (
|
|
274
|
-
<button onClick={() => register('alice')}>Register</button>
|
|
49
|
+
return (
|
|
50
|
+
<button onClick={login}>
|
|
51
|
+
{initializing ? 'Connecting...' : 'Login'}
|
|
52
|
+
</button>
|
|
275
53
|
);
|
|
276
54
|
}
|
|
277
55
|
```
|
|
278
56
|
|
|
279
|
-
###
|
|
280
|
-
|
|
281
|
-
```javascript
|
|
282
|
-
const { QidCloud } = require('@qidcloud/sdk');
|
|
57
|
+
### `QidSignInButton`
|
|
58
|
+
A plug-and-play button that handles the entire handshake UI.
|
|
283
59
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
60
|
+
```tsx
|
|
61
|
+
import { QidSignInButton } from '@qidcloud/sdk';
|
|
287
62
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const token = await qgate.login();
|
|
294
|
-
return token;
|
|
295
|
-
}
|
|
63
|
+
<QidSignInButton
|
|
64
|
+
sdk={qid}
|
|
65
|
+
onSuccess={(user, token) => console.log(user)}
|
|
66
|
+
onError={(err) => alert(err)}
|
|
67
|
+
/>
|
|
296
68
|
```
|
|
297
|
-
|
|
298
|
-
## Support
|
|
299
|
-
|
|
300
|
-
**Documentation:** [Provider Guide](../PROVIDER_API_GUIDE.md)
|
|
301
|
-
**Issues:** [GitHub Issues](https://github.com/qgate/sdk/issues)
|
|
302
|
-
**Email:** support@qgate.io
|
|
303
|
-
|
|
304
|
-
## License
|
|
305
|
-
|
|
306
|
-
ISC
|
|
307
|
-
|
|
308
|
-
---
|
|
309
|
-
|
|
310
|
-
**Built with ❤️ by the QidCloud Team**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { QidCloud } from '../index';
|
|
3
|
+
import { QidUser } from '../types';
|
|
4
|
+
interface QidSignInButtonProps {
|
|
5
|
+
sdk: QidCloud;
|
|
6
|
+
onSuccess: (user: QidUser, token: string) => void;
|
|
7
|
+
onError?: (error: string) => void;
|
|
8
|
+
className?: string;
|
|
9
|
+
buttonText?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A ready-to-use React component for QidCloud QR identity authentication.
|
|
13
|
+
*/
|
|
14
|
+
export declare const QidSignInButton: React.FC<QidSignInButtonProps>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QidCloud } from '../index';
|
|
2
|
+
import { QidUser, QidAuthSession } from '../types';
|
|
3
|
+
export interface UseQidAuthReturn {
|
|
4
|
+
user: QidUser | null;
|
|
5
|
+
token: string | null;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
session: QidAuthSession | null;
|
|
9
|
+
initializing: boolean;
|
|
10
|
+
login: () => Promise<void>;
|
|
11
|
+
logout: () => void;
|
|
12
|
+
cancel: () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A React hook for managing QidCloud authentication lifecycle.
|
|
16
|
+
* Handles handshake initialization, WebSocket listeners, and profile fetching.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useQidAuth(sdk: QidCloud): UseQidAuthReturn;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { QidConfig } from './types';
|
|
3
|
+
import { AuthModule } from './modules/auth';
|
|
4
|
+
import { DbModule } from './modules/db';
|
|
5
|
+
import { EdgeModule } from './modules/edge';
|
|
6
|
+
import { VaultModule } from './modules/vault';
|
|
7
|
+
import { LogsModule } from './modules/logs';
|
|
8
|
+
export declare class QidCloud {
|
|
9
|
+
private config;
|
|
10
|
+
api: AxiosInstance;
|
|
11
|
+
auth: AuthModule;
|
|
12
|
+
db: DbModule;
|
|
13
|
+
edge: EdgeModule;
|
|
14
|
+
vault: VaultModule;
|
|
15
|
+
logs: LogsModule;
|
|
16
|
+
constructor(config: QidConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Get the current project configuration
|
|
19
|
+
*/
|
|
20
|
+
getConfig(): QidConfig;
|
|
21
|
+
}
|
|
5
22
|
export default QidCloud;
|
|
23
|
+
export * from './types';
|
|
24
|
+
export { QidSignInButton } from './components/QidSignInButton';
|
|
25
|
+
export { useQidAuth } from './hooks/useQidAuth';
|