@lanonasis/oauth-client 1.2.5 → 1.2.6
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/dist/index.cjs +77 -37
- package/dist/index.mjs +77 -37
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -368,11 +368,26 @@ var DesktopOAuthFlow = class extends BaseOAuthFlow {
|
|
|
368
368
|
};
|
|
369
369
|
|
|
370
370
|
// src/storage/token-storage.ts
|
|
371
|
-
var
|
|
372
|
-
var
|
|
373
|
-
var
|
|
374
|
-
var
|
|
375
|
-
|
|
371
|
+
var _fs = null;
|
|
372
|
+
var _path = null;
|
|
373
|
+
var _os = null;
|
|
374
|
+
var _crypto = null;
|
|
375
|
+
async function getNodeModules() {
|
|
376
|
+
if (_fs && _path && _os && _crypto) {
|
|
377
|
+
return { fs: _fs, path: _path, os: _os, crypto: _crypto };
|
|
378
|
+
}
|
|
379
|
+
const [fs, path, os, crypto2] = await Promise.all([
|
|
380
|
+
import("fs"),
|
|
381
|
+
import("path"),
|
|
382
|
+
import("os"),
|
|
383
|
+
import("crypto")
|
|
384
|
+
]);
|
|
385
|
+
_fs = fs;
|
|
386
|
+
_path = path;
|
|
387
|
+
_os = os;
|
|
388
|
+
_crypto = crypto2;
|
|
389
|
+
return { fs, path, os, crypto: crypto2 };
|
|
390
|
+
}
|
|
376
391
|
var TokenStorage = class {
|
|
377
392
|
constructor() {
|
|
378
393
|
this.storageKey = "lanonasis_mcp_tokens";
|
|
@@ -462,25 +477,27 @@ var TokenStorage = class {
|
|
|
462
477
|
}
|
|
463
478
|
async storeToFile(tokenString) {
|
|
464
479
|
if (!this.isNode()) return;
|
|
480
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules();
|
|
465
481
|
const configDir = path.join(os.homedir(), ".lanonasis");
|
|
466
482
|
const tokenFile = path.join(configDir, "mcp-tokens.enc");
|
|
467
|
-
await
|
|
468
|
-
const key = this.getFileEncryptionKey();
|
|
483
|
+
await fs.promises.mkdir(configDir, { recursive: true });
|
|
484
|
+
const key = await this.getFileEncryptionKey();
|
|
469
485
|
const iv = crypto2.randomBytes(16);
|
|
470
486
|
const cipher = crypto2.createCipheriv("aes-256-gcm", key, iv);
|
|
471
487
|
let encrypted = cipher.update(tokenString, "utf8", "hex");
|
|
472
488
|
encrypted += cipher.final("hex");
|
|
473
489
|
const authTag = cipher.getAuthTag().toString("hex");
|
|
474
490
|
const data = [iv.toString("hex"), authTag, encrypted].join(":");
|
|
475
|
-
await
|
|
491
|
+
await fs.promises.writeFile(tokenFile, data, { mode: 384 });
|
|
476
492
|
}
|
|
477
493
|
async retrieveFromFile() {
|
|
478
494
|
if (!this.isNode()) return null;
|
|
495
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules();
|
|
479
496
|
const tokenFile = path.join(os.homedir(), ".lanonasis", "mcp-tokens.enc");
|
|
480
497
|
try {
|
|
481
|
-
const data = await
|
|
498
|
+
const data = await fs.promises.readFile(tokenFile, "utf8");
|
|
482
499
|
const parts = data.split(":");
|
|
483
|
-
const key = this.getFileEncryptionKey();
|
|
500
|
+
const key = await this.getFileEncryptionKey();
|
|
484
501
|
if (parts.length === 3) {
|
|
485
502
|
const [ivHex, authTagHex, encrypted] = parts;
|
|
486
503
|
const iv = Buffer.from(ivHex, "hex");
|
|
@@ -506,13 +523,15 @@ var TokenStorage = class {
|
|
|
506
523
|
}
|
|
507
524
|
async deleteFile() {
|
|
508
525
|
if (!this.isNode()) return;
|
|
526
|
+
const { fs, path, os } = await getNodeModules();
|
|
509
527
|
const tokenFile = path.join(os.homedir(), ".lanonasis", "mcp-tokens.enc");
|
|
510
528
|
try {
|
|
511
|
-
await
|
|
529
|
+
await fs.promises.unlink(tokenFile);
|
|
512
530
|
} catch (error) {
|
|
513
531
|
}
|
|
514
532
|
}
|
|
515
|
-
getFileEncryptionKey() {
|
|
533
|
+
async getFileEncryptionKey() {
|
|
534
|
+
const { os, crypto: crypto2 } = await getNodeModules();
|
|
516
535
|
const machineId = os.hostname() + os.userInfo().username;
|
|
517
536
|
const salt = "lanonasis-mcp-oauth-2024";
|
|
518
537
|
return crypto2.pbkdf2Sync(machineId, salt, 1e5, 32, "sha256");
|
|
@@ -652,11 +671,26 @@ var TokenStorage = class {
|
|
|
652
671
|
};
|
|
653
672
|
|
|
654
673
|
// src/storage/api-key-storage.ts
|
|
655
|
-
var
|
|
656
|
-
var
|
|
657
|
-
var
|
|
658
|
-
var
|
|
659
|
-
|
|
674
|
+
var _fs2 = null;
|
|
675
|
+
var _path2 = null;
|
|
676
|
+
var _os2 = null;
|
|
677
|
+
var _crypto2 = null;
|
|
678
|
+
async function getNodeModules2() {
|
|
679
|
+
if (_fs2 && _path2 && _os2 && _crypto2) {
|
|
680
|
+
return { fs: _fs2, path: _path2, os: _os2, crypto: _crypto2 };
|
|
681
|
+
}
|
|
682
|
+
const [fs, path, os, crypto2] = await Promise.all([
|
|
683
|
+
import("fs"),
|
|
684
|
+
import("path"),
|
|
685
|
+
import("os"),
|
|
686
|
+
import("crypto")
|
|
687
|
+
]);
|
|
688
|
+
_fs2 = fs;
|
|
689
|
+
_path2 = path;
|
|
690
|
+
_os2 = os;
|
|
691
|
+
_crypto2 = crypto2;
|
|
692
|
+
return { fs, path, os, crypto: crypto2 };
|
|
693
|
+
}
|
|
660
694
|
var ApiKeyStorage = class {
|
|
661
695
|
constructor() {
|
|
662
696
|
this.storageKey = "lanonasis_api_key";
|
|
@@ -856,31 +890,33 @@ var ApiKeyStorage = class {
|
|
|
856
890
|
// ==================== Node.js File Storage ====================
|
|
857
891
|
async storeToFile(keyString) {
|
|
858
892
|
if (!this.isNode()) return;
|
|
859
|
-
const
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
const
|
|
864
|
-
const
|
|
893
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules2();
|
|
894
|
+
const configDir = path.join(os.homedir(), ".lanonasis");
|
|
895
|
+
const keyFile = path.join(configDir, "api-key.enc");
|
|
896
|
+
await fs.promises.mkdir(configDir, { recursive: true, mode: 448 });
|
|
897
|
+
const key = await this.getFileEncryptionKey();
|
|
898
|
+
const iv = crypto2.randomBytes(16);
|
|
899
|
+
const cipher = crypto2.createCipheriv("aes-256-gcm", key, iv);
|
|
865
900
|
let encrypted = cipher.update(keyString, "utf8", "hex");
|
|
866
901
|
encrypted += cipher.final("hex");
|
|
867
902
|
const authTag = cipher.getAuthTag();
|
|
868
903
|
const data = iv.toString("hex") + ":" + authTag.toString("hex") + ":" + encrypted;
|
|
869
|
-
await
|
|
904
|
+
await fs.promises.writeFile(keyFile, data, { mode: 384 });
|
|
870
905
|
}
|
|
871
906
|
async retrieveFromFile() {
|
|
872
907
|
if (!this.isNode()) return null;
|
|
873
|
-
const
|
|
908
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules2();
|
|
909
|
+
const keyFile = path.join(os.homedir(), ".lanonasis", "api-key.enc");
|
|
874
910
|
try {
|
|
875
|
-
const data = await
|
|
911
|
+
const data = await fs.promises.readFile(keyFile, "utf8");
|
|
876
912
|
const [ivHex, authTagHex, encrypted] = data.split(":");
|
|
877
913
|
if (!ivHex || !authTagHex || !encrypted) {
|
|
878
914
|
throw new Error("Invalid encrypted file format");
|
|
879
915
|
}
|
|
880
|
-
const key = this.getFileEncryptionKey();
|
|
916
|
+
const key = await this.getFileEncryptionKey();
|
|
881
917
|
const iv = Buffer.from(ivHex, "hex");
|
|
882
918
|
const authTag = Buffer.from(authTagHex, "hex");
|
|
883
|
-
const decipher =
|
|
919
|
+
const decipher = crypto2.createDecipheriv("aes-256-gcm", key, iv);
|
|
884
920
|
decipher.setAuthTag(authTag);
|
|
885
921
|
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
886
922
|
decrypted += decipher.final("utf8");
|
|
@@ -891,33 +927,37 @@ var ApiKeyStorage = class {
|
|
|
891
927
|
}
|
|
892
928
|
async deleteFile() {
|
|
893
929
|
if (!this.isNode()) return;
|
|
894
|
-
const
|
|
930
|
+
const { fs, path, os } = await getNodeModules2();
|
|
931
|
+
const keyFile = path.join(os.homedir(), ".lanonasis", "api-key.enc");
|
|
895
932
|
try {
|
|
896
|
-
await
|
|
933
|
+
await fs.promises.unlink(keyFile);
|
|
897
934
|
} catch (error) {
|
|
898
935
|
}
|
|
899
936
|
}
|
|
900
937
|
async retrieveLegacyFromFile() {
|
|
901
938
|
if (!this.isNode()) return null;
|
|
902
|
-
const
|
|
939
|
+
const { fs, path, os } = await getNodeModules2();
|
|
940
|
+
const legacyFile = path.join(os.homedir(), ".lanonasis", "api-key.txt");
|
|
903
941
|
try {
|
|
904
|
-
return await
|
|
942
|
+
return await fs.promises.readFile(legacyFile, "utf8");
|
|
905
943
|
} catch {
|
|
906
944
|
return null;
|
|
907
945
|
}
|
|
908
946
|
}
|
|
909
947
|
async deleteLegacyFile() {
|
|
910
948
|
if (!this.isNode()) return;
|
|
911
|
-
const
|
|
949
|
+
const { fs, path, os } = await getNodeModules2();
|
|
950
|
+
const legacyFile = path.join(os.homedir(), ".lanonasis", "api-key.txt");
|
|
912
951
|
try {
|
|
913
|
-
await
|
|
952
|
+
await fs.promises.unlink(legacyFile);
|
|
914
953
|
} catch {
|
|
915
954
|
}
|
|
916
955
|
}
|
|
917
|
-
getFileEncryptionKey() {
|
|
918
|
-
const
|
|
956
|
+
async getFileEncryptionKey() {
|
|
957
|
+
const { os, crypto: crypto2 } = await getNodeModules2();
|
|
958
|
+
const machineId = os.hostname() + os.userInfo().username;
|
|
919
959
|
const salt = "lanonasis-mcp-api-key-2024";
|
|
920
|
-
return
|
|
960
|
+
return crypto2.pbkdf2Sync(machineId, salt, 1e5, 32, "sha256");
|
|
921
961
|
}
|
|
922
962
|
// ==================== Web Encryption ====================
|
|
923
963
|
async encrypt(text) {
|
package/dist/index.mjs
CHANGED
|
@@ -332,11 +332,26 @@ var DesktopOAuthFlow = class extends BaseOAuthFlow {
|
|
|
332
332
|
};
|
|
333
333
|
|
|
334
334
|
// src/storage/token-storage.ts
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
335
|
+
var _fs = null;
|
|
336
|
+
var _path = null;
|
|
337
|
+
var _os = null;
|
|
338
|
+
var _crypto = null;
|
|
339
|
+
async function getNodeModules() {
|
|
340
|
+
if (_fs && _path && _os && _crypto) {
|
|
341
|
+
return { fs: _fs, path: _path, os: _os, crypto: _crypto };
|
|
342
|
+
}
|
|
343
|
+
const [fs, path, os, crypto2] = await Promise.all([
|
|
344
|
+
import("fs"),
|
|
345
|
+
import("path"),
|
|
346
|
+
import("os"),
|
|
347
|
+
import("crypto")
|
|
348
|
+
]);
|
|
349
|
+
_fs = fs;
|
|
350
|
+
_path = path;
|
|
351
|
+
_os = os;
|
|
352
|
+
_crypto = crypto2;
|
|
353
|
+
return { fs, path, os, crypto: crypto2 };
|
|
354
|
+
}
|
|
340
355
|
var TokenStorage = class {
|
|
341
356
|
constructor() {
|
|
342
357
|
this.storageKey = "lanonasis_mcp_tokens";
|
|
@@ -426,25 +441,27 @@ var TokenStorage = class {
|
|
|
426
441
|
}
|
|
427
442
|
async storeToFile(tokenString) {
|
|
428
443
|
if (!this.isNode()) return;
|
|
444
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules();
|
|
429
445
|
const configDir = path.join(os.homedir(), ".lanonasis");
|
|
430
446
|
const tokenFile = path.join(configDir, "mcp-tokens.enc");
|
|
431
|
-
await
|
|
432
|
-
const key = this.getFileEncryptionKey();
|
|
447
|
+
await fs.promises.mkdir(configDir, { recursive: true });
|
|
448
|
+
const key = await this.getFileEncryptionKey();
|
|
433
449
|
const iv = crypto2.randomBytes(16);
|
|
434
450
|
const cipher = crypto2.createCipheriv("aes-256-gcm", key, iv);
|
|
435
451
|
let encrypted = cipher.update(tokenString, "utf8", "hex");
|
|
436
452
|
encrypted += cipher.final("hex");
|
|
437
453
|
const authTag = cipher.getAuthTag().toString("hex");
|
|
438
454
|
const data = [iv.toString("hex"), authTag, encrypted].join(":");
|
|
439
|
-
await
|
|
455
|
+
await fs.promises.writeFile(tokenFile, data, { mode: 384 });
|
|
440
456
|
}
|
|
441
457
|
async retrieveFromFile() {
|
|
442
458
|
if (!this.isNode()) return null;
|
|
459
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules();
|
|
443
460
|
const tokenFile = path.join(os.homedir(), ".lanonasis", "mcp-tokens.enc");
|
|
444
461
|
try {
|
|
445
|
-
const data = await
|
|
462
|
+
const data = await fs.promises.readFile(tokenFile, "utf8");
|
|
446
463
|
const parts = data.split(":");
|
|
447
|
-
const key = this.getFileEncryptionKey();
|
|
464
|
+
const key = await this.getFileEncryptionKey();
|
|
448
465
|
if (parts.length === 3) {
|
|
449
466
|
const [ivHex, authTagHex, encrypted] = parts;
|
|
450
467
|
const iv = Buffer.from(ivHex, "hex");
|
|
@@ -470,13 +487,15 @@ var TokenStorage = class {
|
|
|
470
487
|
}
|
|
471
488
|
async deleteFile() {
|
|
472
489
|
if (!this.isNode()) return;
|
|
490
|
+
const { fs, path, os } = await getNodeModules();
|
|
473
491
|
const tokenFile = path.join(os.homedir(), ".lanonasis", "mcp-tokens.enc");
|
|
474
492
|
try {
|
|
475
|
-
await
|
|
493
|
+
await fs.promises.unlink(tokenFile);
|
|
476
494
|
} catch (error) {
|
|
477
495
|
}
|
|
478
496
|
}
|
|
479
|
-
getFileEncryptionKey() {
|
|
497
|
+
async getFileEncryptionKey() {
|
|
498
|
+
const { os, crypto: crypto2 } = await getNodeModules();
|
|
480
499
|
const machineId = os.hostname() + os.userInfo().username;
|
|
481
500
|
const salt = "lanonasis-mcp-oauth-2024";
|
|
482
501
|
return crypto2.pbkdf2Sync(machineId, salt, 1e5, 32, "sha256");
|
|
@@ -616,11 +635,26 @@ var TokenStorage = class {
|
|
|
616
635
|
};
|
|
617
636
|
|
|
618
637
|
// src/storage/api-key-storage.ts
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
638
|
+
var _fs2 = null;
|
|
639
|
+
var _path2 = null;
|
|
640
|
+
var _os2 = null;
|
|
641
|
+
var _crypto2 = null;
|
|
642
|
+
async function getNodeModules2() {
|
|
643
|
+
if (_fs2 && _path2 && _os2 && _crypto2) {
|
|
644
|
+
return { fs: _fs2, path: _path2, os: _os2, crypto: _crypto2 };
|
|
645
|
+
}
|
|
646
|
+
const [fs, path, os, crypto2] = await Promise.all([
|
|
647
|
+
import("fs"),
|
|
648
|
+
import("path"),
|
|
649
|
+
import("os"),
|
|
650
|
+
import("crypto")
|
|
651
|
+
]);
|
|
652
|
+
_fs2 = fs;
|
|
653
|
+
_path2 = path;
|
|
654
|
+
_os2 = os;
|
|
655
|
+
_crypto2 = crypto2;
|
|
656
|
+
return { fs, path, os, crypto: crypto2 };
|
|
657
|
+
}
|
|
624
658
|
var ApiKeyStorage = class {
|
|
625
659
|
constructor() {
|
|
626
660
|
this.storageKey = "lanonasis_api_key";
|
|
@@ -820,31 +854,33 @@ var ApiKeyStorage = class {
|
|
|
820
854
|
// ==================== Node.js File Storage ====================
|
|
821
855
|
async storeToFile(keyString) {
|
|
822
856
|
if (!this.isNode()) return;
|
|
823
|
-
const
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
const
|
|
828
|
-
const
|
|
857
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules2();
|
|
858
|
+
const configDir = path.join(os.homedir(), ".lanonasis");
|
|
859
|
+
const keyFile = path.join(configDir, "api-key.enc");
|
|
860
|
+
await fs.promises.mkdir(configDir, { recursive: true, mode: 448 });
|
|
861
|
+
const key = await this.getFileEncryptionKey();
|
|
862
|
+
const iv = crypto2.randomBytes(16);
|
|
863
|
+
const cipher = crypto2.createCipheriv("aes-256-gcm", key, iv);
|
|
829
864
|
let encrypted = cipher.update(keyString, "utf8", "hex");
|
|
830
865
|
encrypted += cipher.final("hex");
|
|
831
866
|
const authTag = cipher.getAuthTag();
|
|
832
867
|
const data = iv.toString("hex") + ":" + authTag.toString("hex") + ":" + encrypted;
|
|
833
|
-
await
|
|
868
|
+
await fs.promises.writeFile(keyFile, data, { mode: 384 });
|
|
834
869
|
}
|
|
835
870
|
async retrieveFromFile() {
|
|
836
871
|
if (!this.isNode()) return null;
|
|
837
|
-
const
|
|
872
|
+
const { fs, path, os, crypto: crypto2 } = await getNodeModules2();
|
|
873
|
+
const keyFile = path.join(os.homedir(), ".lanonasis", "api-key.enc");
|
|
838
874
|
try {
|
|
839
|
-
const data = await
|
|
875
|
+
const data = await fs.promises.readFile(keyFile, "utf8");
|
|
840
876
|
const [ivHex, authTagHex, encrypted] = data.split(":");
|
|
841
877
|
if (!ivHex || !authTagHex || !encrypted) {
|
|
842
878
|
throw new Error("Invalid encrypted file format");
|
|
843
879
|
}
|
|
844
|
-
const key = this.getFileEncryptionKey();
|
|
880
|
+
const key = await this.getFileEncryptionKey();
|
|
845
881
|
const iv = Buffer.from(ivHex, "hex");
|
|
846
882
|
const authTag = Buffer.from(authTagHex, "hex");
|
|
847
|
-
const decipher =
|
|
883
|
+
const decipher = crypto2.createDecipheriv("aes-256-gcm", key, iv);
|
|
848
884
|
decipher.setAuthTag(authTag);
|
|
849
885
|
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
850
886
|
decrypted += decipher.final("utf8");
|
|
@@ -855,33 +891,37 @@ var ApiKeyStorage = class {
|
|
|
855
891
|
}
|
|
856
892
|
async deleteFile() {
|
|
857
893
|
if (!this.isNode()) return;
|
|
858
|
-
const
|
|
894
|
+
const { fs, path, os } = await getNodeModules2();
|
|
895
|
+
const keyFile = path.join(os.homedir(), ".lanonasis", "api-key.enc");
|
|
859
896
|
try {
|
|
860
|
-
await
|
|
897
|
+
await fs.promises.unlink(keyFile);
|
|
861
898
|
} catch (error) {
|
|
862
899
|
}
|
|
863
900
|
}
|
|
864
901
|
async retrieveLegacyFromFile() {
|
|
865
902
|
if (!this.isNode()) return null;
|
|
866
|
-
const
|
|
903
|
+
const { fs, path, os } = await getNodeModules2();
|
|
904
|
+
const legacyFile = path.join(os.homedir(), ".lanonasis", "api-key.txt");
|
|
867
905
|
try {
|
|
868
|
-
return await
|
|
906
|
+
return await fs.promises.readFile(legacyFile, "utf8");
|
|
869
907
|
} catch {
|
|
870
908
|
return null;
|
|
871
909
|
}
|
|
872
910
|
}
|
|
873
911
|
async deleteLegacyFile() {
|
|
874
912
|
if (!this.isNode()) return;
|
|
875
|
-
const
|
|
913
|
+
const { fs, path, os } = await getNodeModules2();
|
|
914
|
+
const legacyFile = path.join(os.homedir(), ".lanonasis", "api-key.txt");
|
|
876
915
|
try {
|
|
877
|
-
await
|
|
916
|
+
await fs.promises.unlink(legacyFile);
|
|
878
917
|
} catch {
|
|
879
918
|
}
|
|
880
919
|
}
|
|
881
|
-
getFileEncryptionKey() {
|
|
882
|
-
const
|
|
920
|
+
async getFileEncryptionKey() {
|
|
921
|
+
const { os, crypto: crypto2 } = await getNodeModules2();
|
|
922
|
+
const machineId = os.hostname() + os.userInfo().username;
|
|
883
923
|
const salt = "lanonasis-mcp-api-key-2024";
|
|
884
|
-
return
|
|
924
|
+
return crypto2.pbkdf2Sync(machineId, salt, 1e5, 32, "sha256");
|
|
885
925
|
}
|
|
886
926
|
// ==================== Web Encryption ====================
|
|
887
927
|
async encrypt(text) {
|