@unicitylabs/sphere-sdk 0.3.3 → 0.3.5
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 +24 -5
- 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 +24 -5
- 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 +24 -5
- 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 +24 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -3667,6 +3667,8 @@ interface SphereCreateOptions {
|
|
|
3667
3667
|
network?: NetworkType;
|
|
3668
3668
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3669
3669
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3670
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3671
|
+
password?: string;
|
|
3670
3672
|
}
|
|
3671
3673
|
/** Options for loading existing wallet */
|
|
3672
3674
|
interface SphereLoadOptions {
|
|
@@ -3690,6 +3692,8 @@ interface SphereLoadOptions {
|
|
|
3690
3692
|
network?: NetworkType;
|
|
3691
3693
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3692
3694
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3695
|
+
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
3696
|
+
password?: string;
|
|
3693
3697
|
}
|
|
3694
3698
|
/** Options for importing a wallet */
|
|
3695
3699
|
interface SphereImportOptions {
|
|
@@ -3721,6 +3725,8 @@ interface SphereImportOptions {
|
|
|
3721
3725
|
price?: PriceProvider;
|
|
3722
3726
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3723
3727
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3728
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
3729
|
+
password?: string;
|
|
3724
3730
|
}
|
|
3725
3731
|
/** L1 (ALPHA blockchain) configuration */
|
|
3726
3732
|
interface L1Config {
|
|
@@ -3766,6 +3772,8 @@ interface SphereInitOptions {
|
|
|
3766
3772
|
* - Omit/undefined: No groupchat module
|
|
3767
3773
|
*/
|
|
3768
3774
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3775
|
+
/** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3776
|
+
password?: string;
|
|
3769
3777
|
}
|
|
3770
3778
|
/** Result of init operation */
|
|
3771
3779
|
interface SphereInitResult {
|
|
@@ -3782,6 +3790,7 @@ declare class Sphere {
|
|
|
3782
3790
|
private _identity;
|
|
3783
3791
|
private _masterKey;
|
|
3784
3792
|
private _mnemonic;
|
|
3793
|
+
private _password;
|
|
3785
3794
|
private _source;
|
|
3786
3795
|
private _derivationMode;
|
|
3787
3796
|
private _basePath;
|
package/dist/index.d.ts
CHANGED
|
@@ -3667,6 +3667,8 @@ interface SphereCreateOptions {
|
|
|
3667
3667
|
network?: NetworkType;
|
|
3668
3668
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3669
3669
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3670
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3671
|
+
password?: string;
|
|
3670
3672
|
}
|
|
3671
3673
|
/** Options for loading existing wallet */
|
|
3672
3674
|
interface SphereLoadOptions {
|
|
@@ -3690,6 +3692,8 @@ interface SphereLoadOptions {
|
|
|
3690
3692
|
network?: NetworkType;
|
|
3691
3693
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3692
3694
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3695
|
+
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
3696
|
+
password?: string;
|
|
3693
3697
|
}
|
|
3694
3698
|
/** Options for importing a wallet */
|
|
3695
3699
|
interface SphereImportOptions {
|
|
@@ -3721,6 +3725,8 @@ interface SphereImportOptions {
|
|
|
3721
3725
|
price?: PriceProvider;
|
|
3722
3726
|
/** Group chat configuration (NIP-29). Omit to disable groupchat. */
|
|
3723
3727
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3728
|
+
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
3729
|
+
password?: string;
|
|
3724
3730
|
}
|
|
3725
3731
|
/** L1 (ALPHA blockchain) configuration */
|
|
3726
3732
|
interface L1Config {
|
|
@@ -3766,6 +3772,8 @@ interface SphereInitOptions {
|
|
|
3766
3772
|
* - Omit/undefined: No groupchat module
|
|
3767
3773
|
*/
|
|
3768
3774
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3775
|
+
/** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3776
|
+
password?: string;
|
|
3769
3777
|
}
|
|
3770
3778
|
/** Result of init operation */
|
|
3771
3779
|
interface SphereInitResult {
|
|
@@ -3782,6 +3790,7 @@ declare class Sphere {
|
|
|
3782
3790
|
private _identity;
|
|
3783
3791
|
private _masterKey;
|
|
3784
3792
|
private _mnemonic;
|
|
3793
|
+
private _password;
|
|
3785
3794
|
private _source;
|
|
3786
3795
|
private _derivationMode;
|
|
3787
3796
|
private _basePath;
|
package/dist/index.js
CHANGED
|
@@ -9327,7 +9327,9 @@ function decryptTextFormatKey(encryptedKey, password) {
|
|
|
9327
9327
|
const key = deriveLegacyKey(password);
|
|
9328
9328
|
const decrypted = CryptoJS7.AES.decrypt(encryptedKey, key);
|
|
9329
9329
|
const result = decrypted.toString(CryptoJS7.enc.Utf8);
|
|
9330
|
-
|
|
9330
|
+
if (!result) return null;
|
|
9331
|
+
if (!/^[0-9a-fA-F]+$/.test(result)) return null;
|
|
9332
|
+
return result;
|
|
9331
9333
|
} catch {
|
|
9332
9334
|
return null;
|
|
9333
9335
|
}
|
|
@@ -9919,6 +9921,7 @@ var Sphere = class _Sphere {
|
|
|
9919
9921
|
_identity = null;
|
|
9920
9922
|
_masterKey = null;
|
|
9921
9923
|
_mnemonic = null;
|
|
9924
|
+
_password = null;
|
|
9922
9925
|
_source = "unknown";
|
|
9923
9926
|
_derivationMode = "bip32";
|
|
9924
9927
|
_basePath = DEFAULT_BASE_PATH;
|
|
@@ -10018,7 +10021,8 @@ var Sphere = class _Sphere {
|
|
|
10018
10021
|
tokenStorage: options.tokenStorage,
|
|
10019
10022
|
l1: options.l1,
|
|
10020
10023
|
price: options.price,
|
|
10021
|
-
groupChat
|
|
10024
|
+
groupChat,
|
|
10025
|
+
password: options.password
|
|
10022
10026
|
});
|
|
10023
10027
|
return { sphere: sphere2, created: false };
|
|
10024
10028
|
}
|
|
@@ -10044,7 +10048,8 @@ var Sphere = class _Sphere {
|
|
|
10044
10048
|
nametag: options.nametag,
|
|
10045
10049
|
l1: options.l1,
|
|
10046
10050
|
price: options.price,
|
|
10047
|
-
groupChat
|
|
10051
|
+
groupChat,
|
|
10052
|
+
password: options.password
|
|
10048
10053
|
});
|
|
10049
10054
|
return { sphere, created: true, generatedMnemonic };
|
|
10050
10055
|
}
|
|
@@ -10091,6 +10096,7 @@ var Sphere = class _Sphere {
|
|
|
10091
10096
|
options.price,
|
|
10092
10097
|
groupChatConfig
|
|
10093
10098
|
);
|
|
10099
|
+
sphere._password = options.password ?? null;
|
|
10094
10100
|
await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
|
|
10095
10101
|
await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
|
|
10096
10102
|
await sphere.initializeProviders();
|
|
@@ -10124,6 +10130,7 @@ var Sphere = class _Sphere {
|
|
|
10124
10130
|
options.price,
|
|
10125
10131
|
groupChatConfig
|
|
10126
10132
|
);
|
|
10133
|
+
sphere._password = options.password ?? null;
|
|
10127
10134
|
await sphere.loadIdentityFromStorage();
|
|
10128
10135
|
await sphere.initializeProviders();
|
|
10129
10136
|
await sphere.initializeModules();
|
|
@@ -10176,6 +10183,7 @@ var Sphere = class _Sphere {
|
|
|
10176
10183
|
options.price,
|
|
10177
10184
|
groupChatConfig
|
|
10178
10185
|
);
|
|
10186
|
+
sphere._password = options.password ?? null;
|
|
10179
10187
|
if (options.mnemonic) {
|
|
10180
10188
|
if (!_Sphere.validateMnemonic(options.mnemonic)) {
|
|
10181
10189
|
throw new Error("Invalid mnemonic");
|
|
@@ -11143,7 +11151,7 @@ var Sphere = class _Sphere {
|
|
|
11143
11151
|
await provider.initialize();
|
|
11144
11152
|
}
|
|
11145
11153
|
await this.reinitializeModulesForNewAddress();
|
|
11146
|
-
if (
|
|
11154
|
+
if (!newNametag) {
|
|
11147
11155
|
await this.syncIdentityWithTransport();
|
|
11148
11156
|
}
|
|
11149
11157
|
if (newNametag) {
|
|
@@ -12354,9 +12362,20 @@ var Sphere = class _Sphere {
|
|
|
12354
12362
|
// Private: Encryption
|
|
12355
12363
|
// ===========================================================================
|
|
12356
12364
|
encrypt(data) {
|
|
12357
|
-
return
|
|
12365
|
+
if (!this._password) return data;
|
|
12366
|
+
return encryptSimple(data, this._password);
|
|
12358
12367
|
}
|
|
12359
12368
|
decrypt(encrypted) {
|
|
12369
|
+
if (this._password) {
|
|
12370
|
+
try {
|
|
12371
|
+
return decryptSimple(encrypted, this._password);
|
|
12372
|
+
} catch {
|
|
12373
|
+
return null;
|
|
12374
|
+
}
|
|
12375
|
+
}
|
|
12376
|
+
if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
|
|
12377
|
+
return encrypted;
|
|
12378
|
+
}
|
|
12360
12379
|
try {
|
|
12361
12380
|
return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
|
|
12362
12381
|
} catch {
|