shogun-core 1.1.4 → 1.2.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 (82) hide show
  1. package/README.md +61 -1327
  2. package/dist/browser/shogun-core.js +1 -1
  3. package/dist/browser/shogun-core.js.LICENSE.txt +0 -9
  4. package/dist/browser/shogun-core.light.js +1 -1
  5. package/dist/browser/shogun-core.vendors.light.js +1 -1
  6. package/dist/browser.js +27 -11
  7. package/dist/core.js +603 -0
  8. package/dist/{gun → gundb}/crypto.js +38 -8
  9. package/dist/gundb/gun.js +676 -0
  10. package/dist/{gun → gundb}/index.js +0 -5
  11. package/dist/{gun → gundb}/utils.js +6 -0
  12. package/dist/index.js +1 -807
  13. package/dist/plugins/index.js +15 -28
  14. package/dist/plugins/{stealth → nostr}/index.js +3 -4
  15. package/dist/plugins/nostr/nostrConnector.js +656 -0
  16. package/dist/plugins/nostr/nostrConnectorPlugin.js +259 -0
  17. package/dist/plugins/{metamask → web3}/index.js +2 -2
  18. package/dist/plugins/{metamask/metamask.js → web3/web3Connector.js} +8 -8
  19. package/dist/plugins/{metamask/metamaskPlugin.js → web3/web3ConnectorPlugin.js} +32 -42
  20. package/dist/plugins/webauthn/webauthnPlugin.js +4 -0
  21. package/dist/types/browser.d.ts +9 -4
  22. package/dist/types/core.d.ts +221 -0
  23. package/dist/types/{gun → gundb}/crypto.d.ts +20 -5
  24. package/dist/types/{gun → gundb}/gun.d.ts +56 -28
  25. package/dist/types/gundb/index.d.ts +1 -0
  26. package/dist/types/{gun → gundb}/utils.d.ts +1 -0
  27. package/dist/types/index.d.ts +1 -282
  28. package/dist/types/plugins/index.d.ts +7 -10
  29. package/dist/types/plugins/nostr/index.d.ts +3 -0
  30. package/dist/types/plugins/nostr/nostrConnector.d.ts +111 -0
  31. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +87 -0
  32. package/dist/types/plugins/nostr/types.d.ts +122 -0
  33. package/dist/types/plugins/web3/index.d.ts +3 -0
  34. package/dist/types/plugins/{metamask → web3}/types.d.ts +4 -4
  35. package/dist/types/plugins/{metamask/metamask.d.ts → web3/web3Connector.d.ts} +7 -7
  36. package/dist/types/plugins/{metamask/metamaskPlugin.d.ts → web3/web3ConnectorPlugin.d.ts} +4 -4
  37. package/dist/types/shogun.js +40 -15
  38. package/dist/types/types/shogun.d.ts +67 -67
  39. package/dist/types/utils/errorHandler.d.ts +39 -36
  40. package/dist/types/utils/utility.d.ts +0 -4
  41. package/dist/utils/errorHandler.js +43 -40
  42. package/dist/utils/utility.js +0 -8
  43. package/package.json +2 -2
  44. package/dist/config.js +0 -18
  45. package/dist/gun/gun.js +0 -542
  46. package/dist/plugins/stealth/stealth.js +0 -176
  47. package/dist/plugins/stealth/stealthPlugin.js +0 -113
  48. package/dist/plugins/stealth/types.js +0 -2
  49. package/dist/plugins/utils/stubs/didStub.js +0 -35
  50. package/dist/plugins/utils/stubs/stealthStub.js +0 -35
  51. package/dist/plugins/utils/stubs/webauthnStub.js +0 -29
  52. package/dist/plugins/wallet/index.js +0 -20
  53. package/dist/plugins/wallet/types.js +0 -15
  54. package/dist/plugins/wallet/walletManager.js +0 -1832
  55. package/dist/plugins/wallet/walletPlugin.js +0 -236
  56. package/dist/types/config.d.ts +0 -15
  57. package/dist/types/gun/index.d.ts +0 -6
  58. package/dist/types/gun/types.d.ts +0 -2
  59. package/dist/types/plugins/metamask/index.d.ts +0 -3
  60. package/dist/types/plugins/stealth/index.d.ts +0 -3
  61. package/dist/types/plugins/stealth/stealth.d.ts +0 -93
  62. package/dist/types/plugins/stealth/stealthPlugin.d.ts +0 -60
  63. package/dist/types/plugins/stealth/types.d.ts +0 -93
  64. package/dist/types/plugins/utils/stubs/didStub.d.ts +0 -15
  65. package/dist/types/plugins/utils/stubs/stealthStub.d.ts +0 -15
  66. package/dist/types/plugins/utils/stubs/webauthnStub.d.ts +0 -13
  67. package/dist/types/plugins/wallet/index.d.ts +0 -3
  68. package/dist/types/plugins/wallet/types.d.ts +0 -167
  69. package/dist/types/plugins/wallet/walletManager.d.ts +0 -306
  70. package/dist/types/plugins/wallet/walletPlugin.d.ts +0 -126
  71. package/dist/types/utils/stubs/didStub.d.ts +0 -15
  72. package/dist/types/utils/stubs/stealthStub.d.ts +0 -15
  73. package/dist/types/utils/stubs/webauthnStub.d.ts +0 -13
  74. package/dist/utils/stubs/didStub.js +0 -35
  75. package/dist/utils/stubs/stealthStub.js +0 -35
  76. package/dist/utils/stubs/webauthnStub.js +0 -29
  77. /package/dist/{gun → gundb}/errors.js +0 -0
  78. /package/dist/{gun → gundb}/rxjs-integration.js +0 -0
  79. /package/dist/{gun → plugins/nostr}/types.js +0 -0
  80. /package/dist/plugins/{metamask → web3}/types.js +0 -0
  81. /package/dist/types/{gun → gundb}/errors.d.ts +0 -0
  82. /package/dist/types/{gun → gundb}/rxjs-integration.d.ts +0 -0
@@ -6,6 +6,8 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.isHash = isHash;
9
+ exports.encrypt = encrypt;
10
+ exports.decrypt = decrypt;
9
11
  exports.encFor = encFor;
10
12
  exports.decFrom = decFrom;
11
13
  exports.hashText = hashText;
@@ -15,7 +17,8 @@ exports.getShortHash = getShortHash;
15
17
  exports.safeHash = safeHash;
16
18
  exports.unsafeHash = unsafeHash;
17
19
  exports.safeJSONParse = safeJSONParse;
18
- const sea_1 = require("gun/sea");
20
+ exports.randomUUID = randomUUID;
21
+ const gun_1 = require("gun");
19
22
  /**
20
23
  * Checks if a string is a valid GunDB hash
21
24
  * @param str - String to check
@@ -24,6 +27,30 @@ const sea_1 = require("gun/sea");
24
27
  function isHash(str) {
25
28
  return typeof str === "string" && str.length === 44 && str.charAt(43) === "=";
26
29
  }
30
+ /**
31
+ * Encrypts data with Gun.SEA
32
+ * @param data Data to encrypt
33
+ * @param key Encryption key
34
+ * @returns Promise that resolves with the encrypted data
35
+ */
36
+ async function encrypt(data, key) {
37
+ if (!Gun.SEA) {
38
+ throw new Error("SEA is not available");
39
+ }
40
+ return Gun.SEA.encrypt(data, key);
41
+ }
42
+ /**
43
+ * Decrypts data with Gun.SEA
44
+ * @param encryptedData Encrypted data
45
+ * @param key Decryption key
46
+ * @returns Promise that resolves with the decrypted data
47
+ */
48
+ async function decrypt(encryptedData, key) {
49
+ if (!Gun.SEA) {
50
+ throw new Error("SEA is not available");
51
+ }
52
+ return Gun.SEA.decrypt(encryptedData, key);
53
+ }
27
54
  /**
28
55
  * Encrypts data from a sender to a receiver using their public keys
29
56
  * @param data - Data to encrypt
@@ -32,8 +59,8 @@ function isHash(str) {
32
59
  * @returns Promise resolving to encrypted data
33
60
  */
34
61
  async function encFor(data, sender, receiver) {
35
- const secret = await sea_1.SEA.secret(receiver.epub, sender);
36
- const encryptedData = await sea_1.SEA.encrypt(data, secret);
62
+ const secret = (await gun_1.SEA.secret(receiver.epub, sender));
63
+ const encryptedData = await gun_1.SEA.encrypt(data, secret);
37
64
  return encryptedData;
38
65
  }
39
66
  /**
@@ -44,8 +71,8 @@ async function encFor(data, sender, receiver) {
44
71
  * @returns Promise resolving to decrypted data
45
72
  */
46
73
  async function decFrom(data, sender, receiver) {
47
- const secret = await sea_1.SEA.secret(sender.epub, receiver);
48
- const decryptedData = await sea_1.SEA.decrypt(data, secret);
74
+ const secret = (await gun_1.SEA.secret(sender.epub, receiver));
75
+ const decryptedData = await gun_1.SEA.decrypt(data, secret);
49
76
  return decryptedData;
50
77
  }
51
78
  /**
@@ -54,7 +81,7 @@ async function decFrom(data, sender, receiver) {
54
81
  * @returns Promise resolving to hash string
55
82
  */
56
83
  async function hashText(text) {
57
- let hash = await sea_1.SEA.work(text, null, null, { name: "SHA-256" });
84
+ let hash = await gun_1.SEA.work(text, null, null, { name: "SHA-256" });
58
85
  return hash;
59
86
  }
60
87
  /**
@@ -74,7 +101,7 @@ async function hashObj(obj) {
74
101
  * @returns Promise resolving to shared secret
75
102
  */
76
103
  async function secret(epub, pair) {
77
- const secret = await sea_1.SEA.secret(epub, pair);
104
+ const secret = await gun_1.SEA.secret(epub, pair);
78
105
  return secret;
79
106
  }
80
107
  /**
@@ -84,7 +111,7 @@ async function secret(epub, pair) {
84
111
  * @returns Promise resolving to hex-encoded hash
85
112
  */
86
113
  async function getShortHash(text, salt) {
87
- return await sea_1.SEA.work(text, null, null, {
114
+ return await gun_1.SEA.work(text, null, null, {
88
115
  name: "PBKDF2",
89
116
  encode: "hex",
90
117
  salt,
@@ -164,3 +191,6 @@ function safeJSONParse(input, def = {}) {
164
191
  return def;
165
192
  }
166
193
  }
194
+ function randomUUID() {
195
+ throw new Error("Function not implemented.");
196
+ }