@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.
@@ -239,6 +239,7 @@ declare class FileStorageProvider implements StorageProvider {
239
239
  readonly type: "local";
240
240
  private dataDir;
241
241
  private filePath;
242
+ private isTxtMode;
242
243
  private data;
243
244
  private status;
244
245
  private _identity;
@@ -1399,6 +1400,8 @@ interface NodeProvidersConfig {
1399
1400
  network?: NetworkType;
1400
1401
  /** Directory for wallet data storage */
1401
1402
  dataDir?: string;
1403
+ /** Wallet file name (default: 'wallet.json') */
1404
+ walletFileName?: string;
1402
1405
  /** Directory for token files */
1403
1406
  tokensDir?: string;
1404
1407
  /** Transport (Nostr) configuration */
@@ -239,6 +239,7 @@ declare class FileStorageProvider implements StorageProvider {
239
239
  readonly type: "local";
240
240
  private dataDir;
241
241
  private filePath;
242
+ private isTxtMode;
242
243
  private data;
243
244
  private status;
244
245
  private _identity;
@@ -1399,6 +1400,8 @@ interface NodeProvidersConfig {
1399
1400
  network?: NetworkType;
1400
1401
  /** Directory for wallet data storage */
1401
1402
  dataDir?: string;
1403
+ /** Wallet file name (default: 'wallet.json') */
1404
+ walletFileName?: string;
1402
1405
  /** Directory for token files */
1403
1406
  tokensDir?: string;
1404
1407
  /** Transport (Nostr) configuration */
@@ -165,6 +165,7 @@ var FileStorageProvider = class {
165
165
  type = "local";
166
166
  dataDir;
167
167
  filePath;
168
+ isTxtMode;
168
169
  data = {};
169
170
  status = "disconnected";
170
171
  _identity = null;
@@ -176,6 +177,7 @@ var FileStorageProvider = class {
176
177
  this.dataDir = config.dataDir;
177
178
  this.filePath = path.join(config.dataDir, config.fileName ?? "wallet.json");
178
179
  }
180
+ this.isTxtMode = this.filePath.endsWith(".txt");
179
181
  }
180
182
  setIdentity(identity) {
181
183
  this._identity = identity;
@@ -192,8 +194,14 @@ var FileStorageProvider = class {
192
194
  }
193
195
  if (fs.existsSync(this.filePath)) {
194
196
  try {
195
- const content = fs.readFileSync(this.filePath, "utf-8");
196
- this.data = JSON.parse(content);
197
+ const content = fs.readFileSync(this.filePath, "utf-8").trim();
198
+ if (this.isTxtMode) {
199
+ if (content) {
200
+ this.data = { [STORAGE_KEYS_GLOBAL.MNEMONIC]: content };
201
+ }
202
+ } else {
203
+ this.data = JSON.parse(content);
204
+ }
197
205
  } catch {
198
206
  this.data = {};
199
207
  }
@@ -276,7 +284,12 @@ var FileStorageProvider = class {
276
284
  if (!fs.existsSync(this.dataDir)) {
277
285
  fs.mkdirSync(this.dataDir, { recursive: true });
278
286
  }
279
- fs.writeFileSync(this.filePath, JSON.stringify(this.data, null, 2));
287
+ if (this.isTxtMode) {
288
+ const mnemonic = this.data[STORAGE_KEYS_GLOBAL.MNEMONIC] ?? "";
289
+ fs.writeFileSync(this.filePath, mnemonic);
290
+ } else {
291
+ fs.writeFileSync(this.filePath, JSON.stringify(this.data, null, 2));
292
+ }
280
293
  }
281
294
  };
282
295
  function createFileStorageProvider(config) {
@@ -4902,7 +4915,8 @@ function createNodeProviders(config) {
4902
4915
  const l1Config = resolveL1Config(network, config?.l1);
4903
4916
  const priceConfig = resolvePriceConfig(config?.price);
4904
4917
  const storage = createFileStorageProvider({
4905
- dataDir: config?.dataDir ?? "./sphere-data"
4918
+ dataDir: config?.dataDir ?? "./sphere-data",
4919
+ ...config?.walletFileName ? { fileName: config.walletFileName } : {}
4906
4920
  });
4907
4921
  const ipfsSync = config?.tokenSync?.ipfs;
4908
4922
  const ipfsTokenStorage = ipfsSync?.enabled ? createNodeIpfsStorageProvider(ipfsSync.config, storage) : void 0;