@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/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
|
@@ -9919,6 +9919,7 @@ var Sphere = class _Sphere {
|
|
|
9919
9919
|
_identity = null;
|
|
9920
9920
|
_masterKey = null;
|
|
9921
9921
|
_mnemonic = null;
|
|
9922
|
+
_password = null;
|
|
9922
9923
|
_source = "unknown";
|
|
9923
9924
|
_derivationMode = "bip32";
|
|
9924
9925
|
_basePath = DEFAULT_BASE_PATH;
|
|
@@ -10018,7 +10019,8 @@ var Sphere = class _Sphere {
|
|
|
10018
10019
|
tokenStorage: options.tokenStorage,
|
|
10019
10020
|
l1: options.l1,
|
|
10020
10021
|
price: options.price,
|
|
10021
|
-
groupChat
|
|
10022
|
+
groupChat,
|
|
10023
|
+
password: options.password
|
|
10022
10024
|
});
|
|
10023
10025
|
return { sphere: sphere2, created: false };
|
|
10024
10026
|
}
|
|
@@ -10044,7 +10046,8 @@ var Sphere = class _Sphere {
|
|
|
10044
10046
|
nametag: options.nametag,
|
|
10045
10047
|
l1: options.l1,
|
|
10046
10048
|
price: options.price,
|
|
10047
|
-
groupChat
|
|
10049
|
+
groupChat,
|
|
10050
|
+
password: options.password
|
|
10048
10051
|
});
|
|
10049
10052
|
return { sphere, created: true, generatedMnemonic };
|
|
10050
10053
|
}
|
|
@@ -10091,6 +10094,7 @@ var Sphere = class _Sphere {
|
|
|
10091
10094
|
options.price,
|
|
10092
10095
|
groupChatConfig
|
|
10093
10096
|
);
|
|
10097
|
+
sphere._password = options.password ?? null;
|
|
10094
10098
|
await sphere.storeMnemonic(options.mnemonic, options.derivationPath);
|
|
10095
10099
|
await sphere.initializeIdentityFromMnemonic(options.mnemonic, options.derivationPath);
|
|
10096
10100
|
await sphere.initializeProviders();
|
|
@@ -10124,6 +10128,7 @@ var Sphere = class _Sphere {
|
|
|
10124
10128
|
options.price,
|
|
10125
10129
|
groupChatConfig
|
|
10126
10130
|
);
|
|
10131
|
+
sphere._password = options.password ?? null;
|
|
10127
10132
|
await sphere.loadIdentityFromStorage();
|
|
10128
10133
|
await sphere.initializeProviders();
|
|
10129
10134
|
await sphere.initializeModules();
|
|
@@ -10176,6 +10181,7 @@ var Sphere = class _Sphere {
|
|
|
10176
10181
|
options.price,
|
|
10177
10182
|
groupChatConfig
|
|
10178
10183
|
);
|
|
10184
|
+
sphere._password = options.password ?? null;
|
|
10179
10185
|
if (options.mnemonic) {
|
|
10180
10186
|
if (!_Sphere.validateMnemonic(options.mnemonic)) {
|
|
10181
10187
|
throw new Error("Invalid mnemonic");
|
|
@@ -12354,9 +12360,20 @@ var Sphere = class _Sphere {
|
|
|
12354
12360
|
// Private: Encryption
|
|
12355
12361
|
// ===========================================================================
|
|
12356
12362
|
encrypt(data) {
|
|
12357
|
-
return
|
|
12363
|
+
if (!this._password) return data;
|
|
12364
|
+
return encryptSimple(data, this._password);
|
|
12358
12365
|
}
|
|
12359
12366
|
decrypt(encrypted) {
|
|
12367
|
+
if (this._password) {
|
|
12368
|
+
try {
|
|
12369
|
+
return decryptSimple(encrypted, this._password);
|
|
12370
|
+
} catch {
|
|
12371
|
+
return null;
|
|
12372
|
+
}
|
|
12373
|
+
}
|
|
12374
|
+
if (validateMnemonic2(encrypted) || /^[0-9a-f]{64}$/i.test(encrypted)) {
|
|
12375
|
+
return encrypted;
|
|
12376
|
+
}
|
|
12360
12377
|
try {
|
|
12361
12378
|
return decryptSimple(encrypted, DEFAULT_ENCRYPTION_KEY);
|
|
12362
12379
|
} catch {
|