@unicitylabs/sphere-sdk 0.2.0 → 0.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.
@@ -318,9 +318,10 @@ declare function createFileTokenStorageProvider(config: FileTokenStorageConfig |
318
318
  */
319
319
  interface TransportProvider extends BaseProvider {
320
320
  /**
321
- * Set identity for signing/encryption
321
+ * Set identity for signing/encryption.
322
+ * If the transport is already connected, reconnects with the new identity.
322
323
  */
323
- setIdentity(identity: FullIdentity): void;
324
+ setIdentity(identity: FullIdentity): void | Promise<void>;
324
325
  /**
325
326
  * Send encrypted direct message
326
327
  * @param recipientTransportPubkey - Transport-specific pubkey for messaging
@@ -742,7 +743,7 @@ declare class NostrTransportProvider implements TransportProvider {
742
743
  * Check if a relay is currently connected
743
744
  */
744
745
  isRelayConnected(relayUrl: string): boolean;
745
- setIdentity(identity: FullIdentity): void;
746
+ setIdentity(identity: FullIdentity): Promise<void>;
746
747
  /**
747
748
  * Get the Nostr-format public key (32 bytes / 64 hex chars)
748
749
  * This is the x-coordinate only, without the 02/03 prefix.
@@ -819,6 +820,7 @@ declare class NostrTransportProvider implements TransportProvider {
819
820
  * Handles: payment_request:, token_transfer:, etc.
820
821
  */
821
822
  private stripContentPrefix;
823
+ private ensureConnected;
822
824
  private ensureReady;
823
825
  private emitEvent;
824
826
  private log;
@@ -318,9 +318,10 @@ declare function createFileTokenStorageProvider(config: FileTokenStorageConfig |
318
318
  */
319
319
  interface TransportProvider extends BaseProvider {
320
320
  /**
321
- * Set identity for signing/encryption
321
+ * Set identity for signing/encryption.
322
+ * If the transport is already connected, reconnects with the new identity.
322
323
  */
323
- setIdentity(identity: FullIdentity): void;
324
+ setIdentity(identity: FullIdentity): void | Promise<void>;
324
325
  /**
325
326
  * Send encrypted direct message
326
327
  * @param recipientTransportPubkey - Transport-specific pubkey for messaging
@@ -742,7 +743,7 @@ declare class NostrTransportProvider implements TransportProvider {
742
743
  * Check if a relay is currently connected
743
744
  */
744
745
  isRelayConnected(relayUrl: string): boolean;
745
- setIdentity(identity: FullIdentity): void;
746
+ setIdentity(identity: FullIdentity): Promise<void>;
746
747
  /**
747
748
  * Get the Nostr-format public key (32 bytes / 64 hex chars)
748
749
  * This is the x-coordinate only, without the 02/03 prefix.
@@ -819,6 +820,7 @@ declare class NostrTransportProvider implements TransportProvider {
819
820
  * Handles: payment_request:, token_transfer:, etc.
820
821
  */
821
822
  private stripContentPrefix;
823
+ private ensureConnected;
822
824
  private ensureReady;
823
825
  private emitEvent;
824
826
  private log;
@@ -1295,7 +1295,7 @@ var NostrTransportProvider = class {
1295
1295
  // ===========================================================================
1296
1296
  // TransportProvider Implementation
1297
1297
  // ===========================================================================
1298
- setIdentity(identity) {
1298
+ async setIdentity(identity) {
1299
1299
  this.identity = identity;
1300
1300
  const secretKey = Buffer2.from(identity.privateKey, "hex");
1301
1301
  this.keyManager = NostrKeyManager.fromPrivateKey(secretKey);
@@ -1325,12 +1325,9 @@ var NostrTransportProvider = class {
1325
1325
  this.log("NostrClient reconnected to relay:", url);
1326
1326
  }
1327
1327
  });
1328
- this.nostrClient.connect(...this.config.relays).then(() => {
1329
- this.subscribeToEvents();
1330
- oldClient.disconnect();
1331
- }).catch((err) => {
1332
- this.log("Failed to reconnect with new identity:", err);
1333
- });
1328
+ await this.nostrClient.connect(...this.config.relays);
1329
+ this.subscribeToEvents();
1330
+ oldClient.disconnect();
1334
1331
  } else if (this.isConnected()) {
1335
1332
  this.subscribeToEvents();
1336
1333
  }
@@ -1473,7 +1470,7 @@ var NostrTransportProvider = class {
1473
1470
  return this.resolveNametagInfo(identifier);
1474
1471
  }
1475
1472
  async resolveNametag(nametag) {
1476
- this.ensureReady();
1473
+ this.ensureConnected();
1477
1474
  const hashedNametag = hashNametag(nametag);
1478
1475
  let events = await this.queryEvents({
1479
1476
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1497,7 +1494,7 @@ var NostrTransportProvider = class {
1497
1494
  return null;
1498
1495
  }
1499
1496
  async resolveNametagInfo(nametag) {
1500
- this.ensureReady();
1497
+ this.ensureConnected();
1501
1498
  const hashedNametag = hashNametag(nametag);
1502
1499
  let events = await this.queryEvents({
1503
1500
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1574,7 +1571,7 @@ var NostrTransportProvider = class {
1574
1571
  * Works with both new identity binding events and legacy nametag binding events.
1575
1572
  */
1576
1573
  async resolveAddressInfo(address) {
1577
- this.ensureReady();
1574
+ this.ensureConnected();
1578
1575
  const addressHash = hashAddressForTag(address);
1579
1576
  const events = await this.queryEvents({
1580
1577
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
@@ -1609,7 +1606,7 @@ var NostrTransportProvider = class {
1609
1606
  * Queries binding events authored by the given pubkey.
1610
1607
  */
1611
1608
  async resolveTransportPubkeyInfo(transportPubkey) {
1612
- this.ensureReady();
1609
+ this.ensureConnected();
1613
1610
  const events = await this.queryEvents({
1614
1611
  kinds: [EVENT_KINDS.NAMETAG_BINDING],
1615
1612
  authors: [transportPubkey],
@@ -2227,10 +2224,13 @@ var NostrTransportProvider = class {
2227
2224
  // ===========================================================================
2228
2225
  // Private: Helpers
2229
2226
  // ===========================================================================
2230
- ensureReady() {
2227
+ ensureConnected() {
2231
2228
  if (!this.isConnected()) {
2232
2229
  throw new Error("NostrTransportProvider not connected");
2233
2230
  }
2231
+ }
2232
+ ensureReady() {
2233
+ this.ensureConnected();
2234
2234
  if (!this.identity) {
2235
2235
  throw new Error("Identity not set");
2236
2236
  }