@quantabit/kyc-sdk 1.0.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 QuantaBit Team
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,83 @@
1
+ # @quantabit/kyc-sdk
2
+
3
+ > QuantaBit KYC SDK - Identity verification, document upload, and compliance level management
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @quantabit/kyc-sdk
9
+ # or
10
+ yarn add @quantabit/kyc-sdk
11
+ ```
12
+
13
+ ## 🚀 Quick Start
14
+
15
+ ### API Client
16
+
17
+ ```javascript
18
+ import { kycApi, KYCLevel, KYCStatus } from "@quantabit/kyc-sdk";
19
+
20
+ // Get KYC status
21
+ const status = await kycApi.getStatus();
22
+
23
+ // Phone verification
24
+ await kycApi.verifyPhone("+1234567890");
25
+
26
+ // Email verification
27
+ await kycApi.verifyEmail("user@example.com");
28
+
29
+ // Upload identity document
30
+ await kycApi.uploadDocument(documentFile);
31
+
32
+ // Submit document for verification
33
+ await kycApi.submitDocumentVerification({
34
+ documentType: "passport",
35
+ frontImage: frontFile,
36
+ backImage: backFile,
37
+ });
38
+ ```
39
+
40
+ ## 📖 Type Definitions
41
+
42
+ ```javascript
43
+ import { KYCLevel, KYCStatus, DocumentType, VerificationType } from "@quantabit/kyc-sdk";
44
+
45
+ // KYC levels
46
+ KYCLevel.NONE; // Not verified
47
+ KYCLevel.BASIC; // Email/phone verified
48
+ KYCLevel.STANDARD; // Document verified
49
+ KYCLevel.ADVANCED; // Full KYC (video call)
50
+
51
+ // KYC status
52
+ KYCStatus.PENDING; // Under review
53
+ KYCStatus.APPROVED; // Approved
54
+ KYCStatus.REJECTED; // Rejected
55
+ KYCStatus.EXPIRED; // Expired
56
+
57
+ // Document types
58
+ DocumentType.PASSPORT; // Passport
59
+ DocumentType.ID_CARD; // National ID card
60
+ DocumentType.DRIVERS_LICENSE; // Driver's license
61
+ ```
62
+
63
+ ## 🌐 Internationalization
64
+
65
+ ```javascript
66
+ import { setLanguage, t } from "@quantabit/kyc-sdk";
67
+ setLanguage("en");
68
+ ```
69
+
70
+ ## 📄 License
71
+
72
+ MIT License
73
+
74
+
75
+
76
+ ---
77
+
78
+ ## 🌐 Brand & Links
79
+ - Official Mainnet: [QuantaBit Chain](https://qbitchain.io/)
80
+ - Developer Platform: [Developer Platform](https://developer.quantabit.io/)
81
+ - Open Platform: [Open Platform](https://open.quantabit.io/)
82
+ - Payment Platform: [Pay Platform](https://pay.qbitwallet.io/)
83
+ - Feedback: [Feedback](https://xwin.live/qbit)
package/dist/index.cjs ADDED
@@ -0,0 +1,540 @@
1
+ 'use strict';
2
+
3
+ var sdkConfig = require('@quantabit/sdk-config');
4
+
5
+ /**
6
+ * Kyc SDK - API 客户端
7
+ * KYC 身份认证系统后端接口封装
8
+ *
9
+ * 使用 BaseApiClient 基类简化代码
10
+ */
11
+
12
+
13
+ /**
14
+ * KYC API 客户端
15
+ */
16
+ class KycApiClient extends sdkConfig.BaseApiClient {
17
+ constructor(config = {}) {
18
+ super('/kyc', config);
19
+ }
20
+
21
+ // ============ 认证状态 ============
22
+
23
+ /**
24
+ * 获取认证状态
25
+ */
26
+ async getStatus() {
27
+ return this.get('/status');
28
+ }
29
+
30
+ /**
31
+ * 获取认证等级信息
32
+ */
33
+ async getLevelInfo() {
34
+ return this.get('/levels');
35
+ }
36
+
37
+ /**
38
+ * 获取当前认证等级
39
+ */
40
+ async getCurrentLevel() {
41
+ return this.get('/my/level');
42
+ }
43
+
44
+ // ============ 基础认证(Level 1)============
45
+
46
+ /**
47
+ * 提交基础信息
48
+ * @param {Object} data - 基础信息
49
+ */
50
+ async submitBasicInfo(data) {
51
+ return this.post('/basic', data);
52
+ }
53
+
54
+ /**
55
+ * 获取基础认证状态
56
+ */
57
+ async getBasicStatus() {
58
+ return this.get('/basic/status');
59
+ }
60
+
61
+ /**
62
+ * 验证手机号
63
+ * @param {string} phone - 手机号
64
+ * @param {string} code - 验证码
65
+ */
66
+ async verifyPhone(phone, code) {
67
+ return this.post('/phone/verify', {
68
+ phone,
69
+ code
70
+ });
71
+ }
72
+
73
+ /**
74
+ * 验证邮箱
75
+ * @param {string} email - 邮箱
76
+ * @param {string} code - 验证码
77
+ */
78
+ async verifyEmail(email, code) {
79
+ return this.post('/email/verify', {
80
+ email,
81
+ code
82
+ });
83
+ }
84
+
85
+ // ============ 身份认证(Level 2)============
86
+
87
+ /**
88
+ * 提交身份证件
89
+ * @param {Object} data - 证件信息
90
+ */
91
+ async submitIdDocument(data) {
92
+ return this.post('/identity', data);
93
+ }
94
+
95
+ /**
96
+ * 提交证件认证(兼容快捷导出命名)
97
+ * @param {Object} data - 证件认证数据
98
+ */
99
+ async submitDocumentVerification(data) {
100
+ return this.submitIdDocument(data);
101
+ }
102
+
103
+ /**
104
+ * 上传证件照片
105
+ * @param {string} type - 照片类型(front, back, selfie)
106
+ * @param {File} file - 图片文件
107
+ */
108
+ async uploadIdPhoto(type, file) {
109
+ const formData = new FormData();
110
+ formData.append('type', type);
111
+ formData.append('file', file);
112
+ const token = this.getToken();
113
+ const response = await fetch(`${this.baseUrl}/identity/upload`, {
114
+ method: 'POST',
115
+ headers: {
116
+ 'Authorization': token ? `Bearer ${token}` : ''
117
+ },
118
+ body: formData
119
+ });
120
+ return response.json();
121
+ }
122
+
123
+ /**
124
+ * 获取身份认证状态
125
+ */
126
+ async getIdentityStatus() {
127
+ return this.get('/identity/status');
128
+ }
129
+
130
+ // ============ 人脸识别 ============
131
+
132
+ /**
133
+ * 获取人脸识别 Token
134
+ */
135
+ async getFaceToken() {
136
+ return this.post('/face/token');
137
+ }
138
+
139
+ /**
140
+ * 提交人脸识别结果
141
+ * @param {string} token - 人脸识别 Token
142
+ * @param {Object} result - 识别结果
143
+ */
144
+ async submitFaceResult(token, result) {
145
+ return this.post('/face/verify', {
146
+ token,
147
+ result
148
+ });
149
+ }
150
+
151
+ /**
152
+ * 获取人脸识别状态
153
+ */
154
+ async getFaceStatus() {
155
+ return this.get('/face/status');
156
+ }
157
+
158
+ // ============ 高级认证(Level 3)============
159
+
160
+ /**
161
+ * 提交高级认证信息
162
+ * @param {Object} data - 高级认证数据
163
+ */
164
+ async submitAdvancedInfo(data) {
165
+ return this.post('/advanced', data);
166
+ }
167
+
168
+ /**
169
+ * 上传补充材料
170
+ * @param {string} type - 材料类型
171
+ * @param {File} file - 文件
172
+ */
173
+ async uploadDocument(type, file) {
174
+ const formData = new FormData();
175
+ formData.append('type', type);
176
+ formData.append('file', file);
177
+ const token = this.getToken();
178
+ const response = await fetch(`${this.baseUrl}/advanced/upload`, {
179
+ method: 'POST',
180
+ headers: {
181
+ 'Authorization': token ? `Bearer ${token}` : ''
182
+ },
183
+ body: formData
184
+ });
185
+ return response.json();
186
+ }
187
+
188
+ /**
189
+ * 获取高级认证状态
190
+ */
191
+ async getAdvancedStatus() {
192
+ return this.get('/advanced/status');
193
+ }
194
+
195
+ // ============ 认证记录 ============
196
+
197
+ /**
198
+ * 获取认证历史
199
+ * @param {Object} params - 查询参数
200
+ */
201
+ async getHistory(params = {}) {
202
+ return this.get('/history', params);
203
+ }
204
+
205
+ /**
206
+ * 重新提交认证
207
+ * @param {string} level - 认证等级
208
+ */
209
+ async resubmit(level) {
210
+ return this.post('/resubmit', {
211
+ level
212
+ });
213
+ }
214
+
215
+ // ============ 管理员操作 ============
216
+
217
+ /**
218
+ * 获取待审核列表(管理员)
219
+ * @param {Object} params - 查询参数
220
+ */
221
+ async getPendingReviews(params = {}) {
222
+ return this.get('/admin/pending', params);
223
+ }
224
+
225
+ /**
226
+ * 审核认证(管理员)
227
+ * @param {string} userId - 用户 ID
228
+ * @param {string} level - 认证等级
229
+ * @param {Object} decision - 审核决定
230
+ */
231
+ async review(userId, level, decision) {
232
+ return this.post('/admin/review', {
233
+ user_id: userId,
234
+ level,
235
+ ...decision
236
+ });
237
+ }
238
+
239
+ // ============ 隐私合规 (GDPR 特殊类别数据) ============
240
+
241
+ /**
242
+ * 请求删除身份认证数据 — GDPR 第17条
243
+ * 向服务端提交身份数据删除请求
244
+ * 注意: 受 AML/KYC 法规限制,某些数据可能需要保留法定期限
245
+ * @param {string} reason - 删除原因
246
+ * @returns {Promise<object>} 删除请求结果
247
+ */
248
+ async requestDataDeletion(reason = '') {
249
+ return this.post('/gdpr/delete', {
250
+ reason
251
+ });
252
+ }
253
+
254
+ /**
255
+ * 导出身份认证数据 — GDPR 第20条
256
+ * 返回脱敏后的身份认证信息(证件号部分遮蔽)
257
+ * @returns {Promise<object>} 脱敏后的身份数据
258
+ */
259
+ async exportKycData() {
260
+ try {
261
+ const status = await this.getStatus();
262
+ const history = await this.getHistory({
263
+ page_size: 50
264
+ });
265
+ return {
266
+ exportDate: new Date().toISOString(),
267
+ format: 'QBit KYC Export (GDPR Art. 20)',
268
+ note: 'ID numbers are partially masked for security',
269
+ currentLevel: status?.data?.level || 'none',
270
+ verificationStatus: status?.data?.status || 'unknown',
271
+ history: history?.data?.items?.map(item => ({
272
+ ...item,
273
+ // 证件号脱敏
274
+ id_number: item.id_number ? `${item.id_number.slice(0, 4)}****${item.id_number.slice(-4)}` : undefined,
275
+ // 移除证件照片 URL(敏感生物数据)
276
+ photo_url: undefined,
277
+ selfie_url: undefined
278
+ })) || []
279
+ };
280
+ } catch (e) {
281
+ return {
282
+ error: e.message,
283
+ exportDate: new Date().toISOString()
284
+ };
285
+ }
286
+ }
287
+
288
+ /**
289
+ * 获取隐私数据声明
290
+ */
291
+ getDataDisclosure() {
292
+ return {
293
+ sdk: '@quantabit/kyc-sdk',
294
+ privacyLevel: 'functional',
295
+ consentRequired: true,
296
+ specialCategory: true,
297
+ collected: [{
298
+ type: 'identity_documents',
299
+ description: 'Government-issued ID (front/back)',
300
+ retention: '5 years (AML regulation)',
301
+ encrypted: true
302
+ }, {
303
+ type: 'biometric_data',
304
+ description: 'Facial recognition data',
305
+ retention: 'Until verification complete',
306
+ encrypted: true
307
+ }, {
308
+ type: 'personal_info',
309
+ description: 'Name, DOB, nationality',
310
+ retention: '5 years (AML regulation)'
311
+ }, {
312
+ type: 'address_proof',
313
+ description: 'Proof of address documents',
314
+ retention: '5 years'
315
+ }],
316
+ compliance: ['GDPR Art. 9 (Special categories)', 'AML 5th Directive', 'KYC/CDD'],
317
+ gdprCapabilities: ['export', 'delete-request'],
318
+ legalBasis: 'Legal obligation (AML) + Explicit consent (biometric)',
319
+ note: 'Biometric data is processed with explicit consent and deleted after verification. AML-required data has a 5-year legal retention period.'
320
+ };
321
+ }
322
+ }
323
+
324
+ // 创建默认实例
325
+ const kycApi = new KycApiClient();
326
+ const KYCApiClient = KycApiClient;
327
+
328
+ /**
329
+ * KYC SDK - 国际化
330
+ */
331
+
332
+ const SUPPORTED_LANGUAGES = ['en', 'zh', 'ja', 'ko'];
333
+ const messages = {
334
+ zh: {
335
+ title: '实名认证',
336
+ level0: '未认证',
337
+ level1: '基础认证',
338
+ level2: '标准认证',
339
+ level3: '高级认证',
340
+ level4: '尊享认证',
341
+ statusNotStarted: '未开始',
342
+ statusPending: '待审核',
343
+ statusReviewing: '审核中',
344
+ statusApproved: '已通过',
345
+ statusRejected: '已拒绝',
346
+ statusExpired: '已过期',
347
+ idCard: '身份证',
348
+ passport: '护照',
349
+ driverLicense: '驾驶证',
350
+ uploadFront: '上传证件正面',
351
+ uploadBack: '上传证件背面',
352
+ uploadSelfie: '上传手持证件照',
353
+ startLiveness: '开始活体检测',
354
+ nameLabel: '姓名',
355
+ idNumberLabel: '证件号码',
356
+ countryLabel: '国家/地区',
357
+ addressLabel: '地址',
358
+ submitVerification: '提交认证',
359
+ processing: '处理中...',
360
+ verificationSuccess: '认证成功',
361
+ verificationFailed: '认证失败',
362
+ tips: '请确保照片清晰、完整,证件在有效期内',
363
+ privacyNotice: '您的信息将被安全加密存储,仅用于身份验证'
364
+ },
365
+ ja: {
366
+ title: '実名認証',
367
+ level0: '未認証',
368
+ level1: '基本認証',
369
+ level2: '標準認証',
370
+ level3: '高級認証',
371
+ level4: 'プレミアム認証',
372
+ statusNotStarted: '未開始',
373
+ statusPending: '審査待ち',
374
+ statusReviewing: '審査中',
375
+ statusApproved: '承認済み',
376
+ statusRejected: '拒否されました',
377
+ statusExpired: '期限切れ',
378
+ idCard: '身分証明書',
379
+ passport: 'パスポート',
380
+ driverLicense: '運転免許証',
381
+ uploadFront: '身分証の表面をアップロード',
382
+ uploadBack: '身分証の裏面をアップロード',
383
+ uploadSelfie: '身分証を持った写真をアップロード',
384
+ startLiveness: '生体認証を開始',
385
+ nameLabel: '氏名',
386
+ idNumberLabel: '身分証番号',
387
+ countryLabel: '国/地域',
388
+ addressLabel: '住所',
389
+ submitVerification: '認証を提出',
390
+ processing: '処理中...',
391
+ verificationSuccess: '認証成功',
392
+ verificationFailed: '認証失敗',
393
+ tips: '写真が鮮明で完全であること、身分証が有効期限内であることを確認してください',
394
+ privacyNotice: 'あなたの情報は安全に暗号化され、本人確認のみに使用されます'
395
+ },
396
+ ko: {
397
+ title: '실명 인증',
398
+ level0: '미인증',
399
+ level1: '기본 인증',
400
+ level2: '표준 인증',
401
+ level3: '고급 인증',
402
+ level4: '프리미엄 인증',
403
+ statusNotStarted: '시작되지 않음',
404
+ statusPending: '심사 대기 중',
405
+ statusReviewing: '심사 중',
406
+ statusApproved: '승인됨',
407
+ statusRejected: '거부됨',
408
+ statusExpired: '만료됨',
409
+ idCard: '신분증',
410
+ passport: '여권',
411
+ driverLicense: '운전면허증',
412
+ uploadFront: '신분증 앞면 업로드',
413
+ uploadBack: '신분증 뒷면 업로드',
414
+ uploadSelfie: '신분증을 든 사진 업로드',
415
+ startLiveness: '생체 인증 시작',
416
+ nameLabel: '성명',
417
+ idNumberLabel: '신분증 번호',
418
+ countryLabel: '국가/지역',
419
+ addressLabel: '주소',
420
+ submitVerification: '인증 제출',
421
+ processing: '처리 중...',
422
+ verificationSuccess: '인증 성공',
423
+ verificationFailed: '인증 실패',
424
+ tips: '사진이 선명하고 완전하며 신분증이 유효 기간 내에 있는지 확인하세요',
425
+ privacyNotice: '귀하의 정보는 안전하게 암호화되어 본인 확인 용도로만 사용됩니다'
426
+ },
427
+ en: {
428
+ title: 'Identity Verification',
429
+ level0: 'Not Verified',
430
+ level1: 'Basic Verified',
431
+ level2: 'Standard Verified',
432
+ level3: 'Advanced Verified',
433
+ level4: 'Premium Verified',
434
+ statusNotStarted: 'Not Started',
435
+ statusPending: 'Pending',
436
+ statusReviewing: 'Under Review',
437
+ statusApproved: 'Approved',
438
+ statusRejected: 'Rejected',
439
+ statusExpired: 'Expired',
440
+ idCard: 'ID Card',
441
+ passport: 'Passport',
442
+ driverLicense: 'Driver License',
443
+ uploadFront: 'Upload Front Side',
444
+ uploadBack: 'Upload Back Side',
445
+ uploadSelfie: 'Upload Selfie with ID',
446
+ startLiveness: 'Start Liveness Check',
447
+ nameLabel: 'Full Name',
448
+ idNumberLabel: 'ID Number',
449
+ countryLabel: 'Country/Region',
450
+ addressLabel: 'Address',
451
+ submitVerification: 'Submit Verification',
452
+ processing: 'Processing...',
453
+ verificationSuccess: 'Verification Successful',
454
+ verificationFailed: 'Verification Failed',
455
+ tips: 'Please ensure photos are clear and complete, and documents are valid',
456
+ privacyNotice: 'Your information will be securely encrypted and used only for identity verification'
457
+ }
458
+ };
459
+ let currentLanguage = 'zh';
460
+ function setLanguage(lang) {
461
+ if (SUPPORTED_LANGUAGES.includes(lang)) currentLanguage = lang;
462
+ }
463
+ function getLanguage() {
464
+ return currentLanguage;
465
+ }
466
+ function t(key) {
467
+ return (messages[currentLanguage] || messages.en)[key] || key;
468
+ }
469
+
470
+ /**
471
+ * KYC SDK - 类型定义
472
+ */
473
+
474
+ // 认证级别
475
+ const KYCLevel = {
476
+ NONE: 0,
477
+ BASIC: 1,
478
+ // 手机/邮箱验证
479
+ STANDARD: 2,
480
+ // 身份证验证
481
+ ADVANCED: 3,
482
+ // 视频活体验证
483
+ PREMIUM: 4 // 高级认证
484
+ };
485
+
486
+ // 认证状态
487
+ const KYCStatus = {
488
+ NOT_STARTED: 'not_started',
489
+ PENDING: 'pending',
490
+ REVIEWING: 'reviewing',
491
+ APPROVED: 'approved',
492
+ REJECTED: 'rejected',
493
+ EXPIRED: 'expired'
494
+ };
495
+
496
+ // 证件类型
497
+ const DocumentType = {
498
+ ID_CARD: 'id_card',
499
+ PASSPORT: 'passport',
500
+ DRIVER_LICENSE: 'driver_license',
501
+ RESIDENCE_PERMIT: 'residence_permit'
502
+ };
503
+
504
+ // 验证类型
505
+ const VerificationType = {
506
+ PHONE: 'phone',
507
+ EMAIL: 'email',
508
+ DOCUMENT: 'document',
509
+ LIVENESS: 'liveness',
510
+ ADDRESS: 'address'
511
+ };
512
+
513
+ /**
514
+ * @quantabit/kyc-sdk
515
+ * KYC SDK
516
+ */
517
+
518
+ const getStatus = (...args) => kycApi.getStatus(...args);
519
+ const verifyPhone = (...args) => kycApi.verifyPhone(...args);
520
+ const verifyEmail = (...args) => kycApi.verifyEmail(...args);
521
+ const uploadDocument = (...args) => kycApi.uploadDocument(...args);
522
+ const submitDocumentVerification = (...args) => kycApi.submitDocumentVerification(...args);
523
+
524
+ exports.DocumentType = DocumentType;
525
+ exports.KYCApiClient = KYCApiClient;
526
+ exports.KYCLevel = KYCLevel;
527
+ exports.KYCStatus = KYCStatus;
528
+ exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
529
+ exports.VerificationType = VerificationType;
530
+ exports.getLanguage = getLanguage;
531
+ exports.getStatus = getStatus;
532
+ exports.kycApi = kycApi;
533
+ exports.messages = messages;
534
+ exports.setLanguage = setLanguage;
535
+ exports.submitDocumentVerification = submitDocumentVerification;
536
+ exports.t = t;
537
+ exports.uploadDocument = uploadDocument;
538
+ exports.verifyEmail = verifyEmail;
539
+ exports.verifyPhone = verifyPhone;
540
+ //# sourceMappingURL=index.cjs.map