@unicitylabs/sphere-sdk 0.3.3 → 0.3.4
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/core/index.cjs +20 -3
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +9 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +20 -3
- package/dist/core/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +18 -4
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +3 -0
- package/dist/impl/nodejs/index.d.ts +3 -0
- package/dist/impl/nodejs/index.js +18 -4
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +20 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.cts
CHANGED
|
@@ -2844,6 +2844,8 @@ interface SphereCreateOptions {
|
|
|
2844
2844
|
network?: NetworkType;
|
|
2845
2845
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2846
2846
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2847
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
2848
|
+
password?: string;
|
|
2847
2849
|
}
|
|
2848
2850
|
/** Options for loading existing wallet */
|
|
2849
2851
|
interface SphereLoadOptions {
|
|
@@ -2867,6 +2869,8 @@ interface SphereLoadOptions {
|
|
|
2867
2869
|
network?: NetworkType;
|
|
2868
2870
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2869
2871
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2872
|
+
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
2873
|
+
password?: string;
|
|
2870
2874
|
}
|
|
2871
2875
|
/** Options for importing a wallet */
|
|
2872
2876
|
interface SphereImportOptions {
|
|
@@ -2898,6 +2902,8 @@ interface SphereImportOptions {
|
|
|
2898
2902
|
price?: PriceProvider;
|
|
2899
2903
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2900
2904
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2905
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
2906
|
+
password?: string;
|
|
2901
2907
|
}
|
|
2902
2908
|
/** L1 (ALPHA blockchain) configuration */
|
|
2903
2909
|
interface L1Config {
|
|
@@ -2943,6 +2949,8 @@ interface SphereInitOptions {
|
|
|
2943
2949
|
* - Omit/undefined: No groupchat module
|
|
2944
2950
|
*/
|
|
2945
2951
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2952
|
+
/** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
2953
|
+
password?: string;
|
|
2946
2954
|
}
|
|
2947
2955
|
/** Result of init operation */
|
|
2948
2956
|
interface SphereInitResult {
|
|
@@ -2959,6 +2967,7 @@ declare class Sphere {
|
|
|
2959
2967
|
private _identity;
|
|
2960
2968
|
private _masterKey;
|
|
2961
2969
|
private _mnemonic;
|
|
2970
|
+
private _password;
|
|
2962
2971
|
private _source;
|
|
2963
2972
|
private _derivationMode;
|
|
2964
2973
|
private _basePath;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -2844,6 +2844,8 @@ interface SphereCreateOptions {
|
|
|
2844
2844
|
network?: NetworkType;
|
|
2845
2845
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2846
2846
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2847
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
2848
|
+
password?: string;
|
|
2847
2849
|
}
|
|
2848
2850
|
/** Options for loading existing wallet */
|
|
2849
2851
|
interface SphereLoadOptions {
|
|
@@ -2867,6 +2869,8 @@ interface SphereLoadOptions {
|
|
|
2867
2869
|
network?: NetworkType;
|
|
2868
2870
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2869
2871
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2872
|
+
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
2873
|
+
password?: string;
|
|
2870
2874
|
}
|
|
2871
2875
|
/** Options for importing a wallet */
|
|
2872
2876
|
interface SphereImportOptions {
|
|
@@ -2898,6 +2902,8 @@ interface SphereImportOptions {
|
|
|
2898
2902
|
price?: PriceProvider;
|
|
2899
2903
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
2900
2904
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2905
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
2906
|
+
password?: string;
|
|
2901
2907
|
}
|
|
2902
2908
|
/** L1 (ALPHA blockchain) configuration */
|
|
2903
2909
|
interface L1Config {
|
|
@@ -2943,6 +2949,8 @@ interface SphereInitOptions {
|
|
|
2943
2949
|
* - Omit/undefined: No groupchat module
|
|
2944
2950
|
*/
|
|
2945
2951
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
2952
|
+
/** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
2953
|
+
password?: string;
|
|
2946
2954
|
}
|
|
2947
2955
|
/** Result of init operation */
|
|
2948
2956
|
interface SphereInitResult {
|
|
@@ -2959,6 +2967,7 @@ declare class Sphere {
|
|
|
2959
2967
|
private _identity;
|
|
2960
2968
|
private _masterKey;
|
|
2961
2969
|
private _mnemonic;
|
|
2970
|
+
private _password;
|
|
2962
2971
|
private _source;
|
|
2963
2972
|
private _derivationMode;
|
|
2964
2973
|
private _basePath;
|
package/dist/core/index.js
CHANGED
|
@@ -9712,6 +9712,7 @@ var Sphere = class _Sphere {
|
|
|
9712
9712
|
_identity = null;
|
|
9713
9713
|
_masterKey = null;
|
|
9714
9714
|
_mnemonic = null;
|
|
9715
|
+
_password = null;
|
|
9715
9716
|
_source = "unknown";
|
|
9716
9717
|
_derivationMode = "bip32";
|
|
9717
9718
|
_basePath = DEFAULT_BASE_PATH;
|
|
@@ -9811,7 +9812,8 @@ var Sphere = class _Sphere {
|
|
|
9811
9812
|
tokenStorage: options.tokenStorage,
|
|
9812
9813
|
l1: options.l1,
|
|
9813
9814
|
price: options.price,
|
|
9814
|
-
groupChat
|
|
9815
|
+
groupChat,
|
|
9816
|
+
password: options.password
|
|
9815
9817
|
});
|
|
9816
9818
|
return { sphere: sphere2, created: false };
|
|
9817
9819
|
}
|
|
@@ -9837,7 +9839,8 @@ var Sphere = class _Sphere {
|
|
|
9837
9839
|
nametag: options.nametag,
|
|
9838
9840
|
l1: options.l1,
|
|
9839
9841
|
price: options.price,
|
|
9840
|
-
groupChat
|
|
9842
|
+
groupChat,
|
|
9843
|
+
password: options.password
|
|
9841
9844
|
});
|
|
9842
9845
|
return { sphere, created: true, generatedMnemonic };
|
|
9843
9846
|
}
|
|
@@ -9884,6 +9887,7 @@ var Sphere = class _Sphere {
|
|
|
9884
9887
|
options.price,
|
|
9885
9888
|
groupChatConfig
|
|
9886
9889
|
);
|
|
9890
|
+
sphere._password = options.password ?? null;
|
|
9887
9891
|
await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
|
|
9888
9892
|
await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
|
|
9889
9893
|
await sphere.initializeProviders();
|
|
@@ -9917,6 +9921,7 @@ var Sphere = class _Sphere {
|
|
|
9917
9921
|
options.price,
|
|
9918
9922
|
groupChatConfig
|
|
9919
9923
|
);
|
|
9924
|
+
sphere._password = options.password ?? null;
|
|
9920
9925
|
await sphere.loadIdentityFromStorage();
|
|
9921
9926
|
await sphere.initializeProviders();
|
|
9922
9927
|
await sphere.initializeModules();
|
|
@@ -9969,6 +9974,7 @@ var Sphere = class _Sphere {
|
|
|
9969
9974
|
options.price,
|
|
9970
9975
|
groupChatConfig
|
|
9971
9976
|
);
|
|
9977
|
+
sphere._password = options.password ?? null;
|
|
9972
9978
|
if (options.mnemonic) {
|
|
9973
9979
|
if (!_Sphere.validateMnemonic(options.mnemonic)) {
|
|
9974
9980
|
throw new Error("Invalid mnemonic");
|
|
@@ -12147,9 +12153,20 @@ var Sphere = class _Sphere {
|
|
|
12147
12153
|
// Private: Encryption
|
|
12148
12154
|
// ===========================================================================
|
|
12149
12155
|
encrypt(data) {
|
|
12150
|
-
return
|
|
12156
|
+
if (!this._password) return data;
|
|
12157
|
+
return encryptSimple(data, this._password);
|
|
12151
12158
|
}
|
|
12152
12159
|
decrypt(encrypted) {
|
|
12160
|
+
if (this._password) {
|
|
12161
|
+
try {
|
|
12162
|
+
return decryptSimple(encrypted, this._password);
|
|
12163
|
+
} catch {
|
|
12164
|
+
return null;
|
|
12165
|
+
}
|
|
12166
|
+
}
|
|
12167
|
+
if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
|
|
12168
|
+
return encrypted;
|
|
12169
|
+
}
|
|
12153
12170
|
try {
|
|
12154
12171
|
return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
|
|
12155
12172
|
} catch {
|