@1sat/connect 0.0.78 → 0.0.79

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { connectWallet, getAvailableProviders, loadLastProvider, type AvailableProvider, type ConnectWalletConfig, type ConnectWalletOptions, type ConnectWalletResult, type WalletProviderConfig, } from './connectWallet';
2
+ export { createWalletSession, type DisconnectReason, type DisconnectedEvent, type IdentityChangeEvent, type WalletSession, type WalletSessionOptions, type WalletSessionStatus, } from './walletSession';
2
3
  export { completeSigmaOAuth, connectSigmaWallet, getStoredSigmaBapId, initiateSigmaOAuth, reconnectSigmaWallet, setSigmaIdentity, sigmaAuthClient, SIGMA_URL, type SigmaOAuthConfig, type SigmaOAuthResult, type SigmaProviderConfig, } from './sigma-oauth';
3
4
  export { signRequest } from './auth';
4
5
  export { AuthorizationTimeoutError, CodeReplayError, type ErrorCode, ErrorCodes, FallbackRequiredError, fromErrorResponse, InsufficientFundsError, OneSatError, PopupBlockedError, PopupClosedError, StateMismatchError, TimeoutError, TransportUnavailableError, UserRejectedError, WalletLockedError, WalletNotConnectedError, } from './errors';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GACzB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACxB,MAAM,eAAe,CAAA;AAItB,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAIpC,OAAO,EACN,yBAAyB,EACzB,eAAe,EACf,KAAK,SAAS,EACd,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,UAAU,CAAA;AAIjB,YAAY,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,SAAS,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GACzB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,EACN,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACxB,MAAM,iBAAiB,CAAA;AAIxB,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,GACxB,MAAM,eAAe,CAAA;AAItB,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAIpC,OAAO,EACN,yBAAyB,EACzB,eAAe,EACf,KAAK,SAAS,EACd,UAAU,EACV,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,UAAU,CAAA;AAIjB,YAAY,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,SAAS,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -80361,6 +80361,184 @@ var require_index_client5 = __commonJS((exports) => {
80361
80361
  __exportStar(require_WalletPermissionsManager(), exports);
80362
80362
  });
80363
80363
 
80364
+ // ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.js
80365
+ var require_eventemitter3 = __commonJS((exports, module) => {
80366
+ var has = Object.prototype.hasOwnProperty;
80367
+ var prefix = "~";
80368
+ function Events() {}
80369
+ if (Object.create) {
80370
+ Events.prototype = Object.create(null);
80371
+ if (!new Events().__proto__)
80372
+ prefix = false;
80373
+ }
80374
+ function EE(fn, context, once) {
80375
+ this.fn = fn;
80376
+ this.context = context;
80377
+ this.once = once || false;
80378
+ }
80379
+ function addListener(emitter, event, fn, context, once) {
80380
+ if (typeof fn !== "function") {
80381
+ throw new TypeError("The listener must be a function");
80382
+ }
80383
+ var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
80384
+ if (!emitter._events[evt])
80385
+ emitter._events[evt] = listener, emitter._eventsCount++;
80386
+ else if (!emitter._events[evt].fn)
80387
+ emitter._events[evt].push(listener);
80388
+ else
80389
+ emitter._events[evt] = [emitter._events[evt], listener];
80390
+ return emitter;
80391
+ }
80392
+ function clearEvent(emitter, evt) {
80393
+ if (--emitter._eventsCount === 0)
80394
+ emitter._events = new Events;
80395
+ else
80396
+ delete emitter._events[evt];
80397
+ }
80398
+ function EventEmitter2() {
80399
+ this._events = new Events;
80400
+ this._eventsCount = 0;
80401
+ }
80402
+ EventEmitter2.prototype.eventNames = function eventNames() {
80403
+ var names = [], events, name;
80404
+ if (this._eventsCount === 0)
80405
+ return names;
80406
+ for (name in events = this._events) {
80407
+ if (has.call(events, name))
80408
+ names.push(prefix ? name.slice(1) : name);
80409
+ }
80410
+ if (Object.getOwnPropertySymbols) {
80411
+ return names.concat(Object.getOwnPropertySymbols(events));
80412
+ }
80413
+ return names;
80414
+ };
80415
+ EventEmitter2.prototype.listeners = function listeners(event) {
80416
+ var evt = prefix ? prefix + event : event, handlers = this._events[evt];
80417
+ if (!handlers)
80418
+ return [];
80419
+ if (handlers.fn)
80420
+ return [handlers.fn];
80421
+ for (var i2 = 0, l6 = handlers.length, ee = new Array(l6);i2 < l6; i2++) {
80422
+ ee[i2] = handlers[i2].fn;
80423
+ }
80424
+ return ee;
80425
+ };
80426
+ EventEmitter2.prototype.listenerCount = function listenerCount(event) {
80427
+ var evt = prefix ? prefix + event : event, listeners = this._events[evt];
80428
+ if (!listeners)
80429
+ return 0;
80430
+ if (listeners.fn)
80431
+ return 1;
80432
+ return listeners.length;
80433
+ };
80434
+ EventEmitter2.prototype.emit = function emit(event, a1, a22, a32, a4, a5) {
80435
+ var evt = prefix ? prefix + event : event;
80436
+ if (!this._events[evt])
80437
+ return false;
80438
+ var listeners = this._events[evt], len2 = arguments.length, args, i2;
80439
+ if (listeners.fn) {
80440
+ if (listeners.once)
80441
+ this.removeListener(event, listeners.fn, undefined, true);
80442
+ switch (len2) {
80443
+ case 1:
80444
+ return listeners.fn.call(listeners.context), true;
80445
+ case 2:
80446
+ return listeners.fn.call(listeners.context, a1), true;
80447
+ case 3:
80448
+ return listeners.fn.call(listeners.context, a1, a22), true;
80449
+ case 4:
80450
+ return listeners.fn.call(listeners.context, a1, a22, a32), true;
80451
+ case 5:
80452
+ return listeners.fn.call(listeners.context, a1, a22, a32, a4), true;
80453
+ case 6:
80454
+ return listeners.fn.call(listeners.context, a1, a22, a32, a4, a5), true;
80455
+ }
80456
+ for (i2 = 1, args = new Array(len2 - 1);i2 < len2; i2++) {
80457
+ args[i2 - 1] = arguments[i2];
80458
+ }
80459
+ listeners.fn.apply(listeners.context, args);
80460
+ } else {
80461
+ var length = listeners.length, j2;
80462
+ for (i2 = 0;i2 < length; i2++) {
80463
+ if (listeners[i2].once)
80464
+ this.removeListener(event, listeners[i2].fn, undefined, true);
80465
+ switch (len2) {
80466
+ case 1:
80467
+ listeners[i2].fn.call(listeners[i2].context);
80468
+ break;
80469
+ case 2:
80470
+ listeners[i2].fn.call(listeners[i2].context, a1);
80471
+ break;
80472
+ case 3:
80473
+ listeners[i2].fn.call(listeners[i2].context, a1, a22);
80474
+ break;
80475
+ case 4:
80476
+ listeners[i2].fn.call(listeners[i2].context, a1, a22, a32);
80477
+ break;
80478
+ default:
80479
+ if (!args)
80480
+ for (j2 = 1, args = new Array(len2 - 1);j2 < len2; j2++) {
80481
+ args[j2 - 1] = arguments[j2];
80482
+ }
80483
+ listeners[i2].fn.apply(listeners[i2].context, args);
80484
+ }
80485
+ }
80486
+ }
80487
+ return true;
80488
+ };
80489
+ EventEmitter2.prototype.on = function on(event, fn, context) {
80490
+ return addListener(this, event, fn, context, false);
80491
+ };
80492
+ EventEmitter2.prototype.once = function once(event, fn, context) {
80493
+ return addListener(this, event, fn, context, true);
80494
+ };
80495
+ EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
80496
+ var evt = prefix ? prefix + event : event;
80497
+ if (!this._events[evt])
80498
+ return this;
80499
+ if (!fn) {
80500
+ clearEvent(this, evt);
80501
+ return this;
80502
+ }
80503
+ var listeners = this._events[evt];
80504
+ if (listeners.fn) {
80505
+ if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
80506
+ clearEvent(this, evt);
80507
+ }
80508
+ } else {
80509
+ for (var i2 = 0, events = [], length = listeners.length;i2 < length; i2++) {
80510
+ if (listeners[i2].fn !== fn || once && !listeners[i2].once || context && listeners[i2].context !== context) {
80511
+ events.push(listeners[i2]);
80512
+ }
80513
+ }
80514
+ if (events.length)
80515
+ this._events[evt] = events.length === 1 ? events[0] : events;
80516
+ else
80517
+ clearEvent(this, evt);
80518
+ }
80519
+ return this;
80520
+ };
80521
+ EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
80522
+ var evt;
80523
+ if (event) {
80524
+ evt = prefix ? prefix + event : event;
80525
+ if (this._events[evt])
80526
+ clearEvent(this, evt);
80527
+ } else {
80528
+ this._events = new Events;
80529
+ this._eventsCount = 0;
80530
+ }
80531
+ return this;
80532
+ };
80533
+ EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
80534
+ EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
80535
+ EventEmitter2.prefixed = prefix;
80536
+ EventEmitter2.EventEmitter = EventEmitter2;
80537
+ if (typeof module !== "undefined") {
80538
+ module.exports = EventEmitter2;
80539
+ }
80540
+ });
80541
+
80364
80542
  // ../client/dist/errors.js
80365
80543
  class HttpError extends Error {
80366
80544
  status;
@@ -102507,6 +102685,122 @@ async function connectWallet(config) {
102507
102685
  return null;
102508
102686
  }
102509
102687
  }
102688
+ // ../../node_modules/.bun/eventemitter3@5.0.4/node_modules/eventemitter3/index.mjs
102689
+ var import__4 = __toESM(require_eventemitter3(), 1);
102690
+ var eventemitter3_default = import__4.default;
102691
+
102692
+ // src/walletSession.ts
102693
+ var DEFAULT_POLL_INTERVAL_MS = 4000;
102694
+ function createWalletSession(result, options) {
102695
+ const pollIntervalMs = options?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
102696
+ const events = new eventemitter3_default;
102697
+ const providerDisconnect = result.disconnect;
102698
+ let wallet2 = result.wallet;
102699
+ let identityKey = result.identityKey;
102700
+ let status = "connected";
102701
+ let disconnectReason = null;
102702
+ const provider = result.provider;
102703
+ let timer = null;
102704
+ let inFlight = false;
102705
+ let generation = 0;
102706
+ function setStatus(next) {
102707
+ if (status === next)
102708
+ return;
102709
+ status = next;
102710
+ events.emit("status", next);
102711
+ }
102712
+ function stopPolling() {
102713
+ if (timer !== null) {
102714
+ clearInterval(timer);
102715
+ timer = null;
102716
+ }
102717
+ generation += 1;
102718
+ }
102719
+ async function tick(gen) {
102720
+ if (gen !== generation || status !== "connected" || !wallet2 || inFlight) {
102721
+ return;
102722
+ }
102723
+ inFlight = true;
102724
+ try {
102725
+ const auth2 = await wallet2.isAuthenticated({});
102726
+ if (gen !== generation || status !== "connected")
102727
+ return;
102728
+ if (!auth2.authenticated) {
102729
+ endSession("unauthenticated");
102730
+ return;
102731
+ }
102732
+ const { publicKey } = await wallet2.getPublicKey({ identityKey: true });
102733
+ if (gen !== generation || status !== "connected")
102734
+ return;
102735
+ if (publicKey && publicKey !== identityKey) {
102736
+ const previous = identityKey;
102737
+ identityKey = publicKey;
102738
+ events.emit("identityChange", {
102739
+ previous,
102740
+ next: publicKey
102741
+ });
102742
+ }
102743
+ } catch {
102744
+ if (gen !== generation || status !== "connected")
102745
+ return;
102746
+ endSession("unavailable");
102747
+ } finally {
102748
+ inFlight = false;
102749
+ }
102750
+ }
102751
+ function endSession(reason) {
102752
+ if (status === "disconnected")
102753
+ return;
102754
+ stopPolling();
102755
+ disconnectReason = reason;
102756
+ setStatus("disconnected");
102757
+ const w3 = wallet2;
102758
+ wallet2 = null;
102759
+ identityKey = null;
102760
+ try {
102761
+ providerDisconnect();
102762
+ } catch {}
102763
+ events.emit("disconnected", { reason });
102764
+ }
102765
+ const session = {
102766
+ get wallet() {
102767
+ return wallet2;
102768
+ },
102769
+ get identityKey() {
102770
+ return identityKey;
102771
+ },
102772
+ get status() {
102773
+ return status;
102774
+ },
102775
+ get provider() {
102776
+ return provider;
102777
+ },
102778
+ get disconnectReason() {
102779
+ return disconnectReason;
102780
+ },
102781
+ start() {
102782
+ if (status !== "connected" || timer !== null)
102783
+ return;
102784
+ const gen = generation;
102785
+ timer = setInterval(() => {
102786
+ tick(gen);
102787
+ }, pollIntervalMs);
102788
+ },
102789
+ stop() {
102790
+ stopPolling();
102791
+ },
102792
+ disconnect(reason = "manual") {
102793
+ endSession(reason);
102794
+ },
102795
+ on(event, handler) {
102796
+ events.on(event, handler);
102797
+ return () => {
102798
+ events.off(event, handler);
102799
+ };
102800
+ }
102801
+ };
102802
+ return session;
102803
+ }
102510
102804
  // ../../node_modules/.bun/nanostores@1.4.0/node_modules/nanostores/clean-stores/index.js
102511
102805
  var clean2 = Symbol("clean");
102512
102806
 
@@ -106070,6 +106364,7 @@ export {
106070
106364
  getStoredSigmaBapId,
106071
106365
  getAvailableProviders,
106072
106366
  fromErrorResponse,
106367
+ createWalletSession,
106073
106368
  connectWallet,
106074
106369
  connectSigmaWallet,
106075
106370
  completeSigmaOAuth,
@@ -0,0 +1,40 @@
1
+ import type { WalletInterface } from '@bsv/sdk';
2
+ import type { ConnectWalletResult } from './connectWallet';
3
+ export type WalletSessionStatus = 'connected' | 'disconnected';
4
+ export type DisconnectReason = 'unauthenticated' | 'unavailable' | 'manual';
5
+ export interface WalletSessionOptions {
6
+ /** How often to check auth + identity. Default 4000ms. */
7
+ pollIntervalMs?: number;
8
+ }
9
+ export interface IdentityChangeEvent {
10
+ previous: string;
11
+ next: string;
12
+ }
13
+ export interface DisconnectedEvent {
14
+ reason: DisconnectReason;
15
+ }
16
+ export interface WalletSession {
17
+ readonly wallet: WalletInterface | null;
18
+ readonly identityKey: string | null;
19
+ readonly status: WalletSessionStatus;
20
+ readonly provider: string | null;
21
+ readonly disconnectReason: DisconnectReason | null;
22
+ /** Start the poll loop (idempotent). No-op if already disconnected. */
23
+ start(): void;
24
+ /** Stop polling without clearing session state. */
25
+ stop(): void;
26
+ /** Stop polling, call provider disconnect, clear session, emit disconnected. */
27
+ disconnect(reason?: DisconnectReason): void;
28
+ on(event: 'identityChange', handler: (e: IdentityChangeEvent) => void): () => void;
29
+ on(event: 'disconnected', handler: (e: DisconnectedEvent) => void): () => void;
30
+ on(event: 'status', handler: (status: WalletSessionStatus) => void): () => void;
31
+ }
32
+ /**
33
+ * Holds a connected BRC-100 wallet and watches for identity / auth changes.
34
+ *
35
+ * Polling is gated on `isAuthenticated` so a locked wallet does not trigger
36
+ * unlock popups via `getPublicKey`. When auth is lost or the substrate fails,
37
+ * the session disconnects and emits `disconnected`.
38
+ */
39
+ export declare function createWalletSession(result: Pick<ConnectWalletResult, 'wallet' | 'identityKey' | 'provider' | 'disconnect'>, options?: WalletSessionOptions): WalletSession;
40
+ //# sourceMappingURL=walletSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../src/walletSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,cAAc,CAAA;AAE9D,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,aAAa,GAAG,QAAQ,CAAA;AAE3E,MAAM,WAAW,oBAAoB;IACpC,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,gBAAgB,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;IACvC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAElD,uEAAuE;IACvE,KAAK,IAAI,IAAI,CAAA;IACb,mDAAmD;IACnD,IAAI,IAAI,IAAI,CAAA;IACZ,gFAAgF;IAChF,UAAU,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;IAE3C,EAAE,CACD,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,GACvC,MAAM,IAAI,CAAA;IACb,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;IAC9E,EAAE,CACD,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,GAC5C,MAAM,IAAI,CAAA;CACb;AAID;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,IAAI,CACX,mBAAmB,EACnB,QAAQ,GAAG,aAAa,GAAG,UAAU,GAAG,YAAY,CACpD,EACD,OAAO,CAAC,EAAE,oBAAoB,GAC5B,aAAa,CA+Hf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1sat/connect",
3
- "version": "0.0.78",
3
+ "version": "0.0.79",
4
4
  "description": "Connection layer for 1Sat wallet - popup flow, events, session management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",