@1sat/connect 0.0.26 → 0.0.27

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.
@@ -1,64 +1,51 @@
1
1
  import type { WalletInterface } from '@bsv/sdk';
2
2
  export interface WalletProviderConfig {
3
- /** Provider identifier 'onesat', 'sigma', or a custom string */
3
+ /** Unique identifier for this provider */
4
4
  type: string;
5
5
  /** Display name for UI */
6
6
  name: string;
7
7
  /** Icon URL or data URI */
8
8
  icon?: string;
9
- /** Base URL for iframe-based providers */
9
+ /** CWI iframe bridge URL any host that implements CWI over postMessage */
10
10
  url?: string;
11
- }
12
- export interface SigmaProviderConfig extends WalletProviderConfig {
13
- type: 'sigma';
14
- /** OAuth client ID registered with Sigma */
15
- clientId: string;
16
- /** Local callback URL path (default: /auth/sigma/callback) */
17
- callbackURL?: string;
11
+ /** Custom connect function — overrides url-based iframe bridge */
12
+ connect?: () => Promise<ConnectWalletResult>;
18
13
  }
19
14
  export interface ConnectWalletConfig {
20
- /** Try WalletClient('auto') first (default: true) */
15
+ /** Include WalletClient('auto') in the race (default: true).
16
+ * Detects any BRC-100 wallet: browser extensions (window.CWI),
17
+ * desktop wallets (localhost), XDM, React Native. */
21
18
  autoDetect?: boolean;
22
- /** Available providers for manual selection or fallback */
19
+ /** Wallet providers to race alongside auto-detect. */
23
20
  providers?: WalletProviderConfig[];
24
21
  }
25
22
  export interface ConnectWalletResult {
26
23
  wallet: WalletInterface;
27
- /** Which provider connected ('brc100', 'onesat', 'sigma', or custom) */
24
+ /** Which provider connected (e.g. 'brc100' for auto-detect, or the provider's type) */
28
25
  provider: string;
29
26
  identityKey: string;
30
27
  disconnect: () => void;
31
28
  }
32
29
  export interface AvailableProvider extends WalletProviderConfig {
33
- /** True if the provider was detected (e.g. extension installed) */
34
- detected: boolean;
35
- /** Connect to this provider */
36
30
  connect: () => Promise<ConnectWalletResult>;
37
31
  }
38
32
  /** @deprecated Use ConnectWalletConfig instead */
39
33
  export type ConnectWalletOptions = ConnectWalletConfig;
34
+ export declare function loadLastProvider(): string | null;
40
35
  /**
41
- * Connect to a Sigma wallet via CWI iframe.
42
- *
43
- * Creates the CWI iframe, sends SET_IDENTITY with the bapId,
44
- * and waits for authentication (user grants permission via iframe).
45
- * The user is not signed in until waitForAuthentication completes.
46
- */
47
- export declare function connectSigmaWallet(bapId: string): Promise<ConnectWalletResult>;
48
- /**
49
- * Get the list of available wallet providers with connect functions.
50
- *
51
- * Use this when you need to present a provider selection UI.
52
- * Each provider has a `connect()` function that returns a ConnectWalletResult.
36
+ * Get available wallet providers with connect functions.
37
+ * Sorts by last successful provider for faster reconnects.
53
38
  */
54
39
  export declare function getAvailableProviders(config?: ConnectWalletConfig): AvailableProvider[];
55
40
  /**
56
- * Auto-detect a BRC-100 wallet via WalletClient("auto").
41
+ * Connect to a BRC-100 wallet by racing all options in parallel.
42
+ *
43
+ * Auto-detect and all configured providers start simultaneously via
44
+ * Promise.any(). First to authenticate wins. The winning provider
45
+ * type is saved to localStorage for warm reconnects.
57
46
  *
58
- * Finds browser extensions, Cicada, localhost wallet, XDM.
59
- * Returns null if no wallet is detected. Does NOT fall through
60
- * to redirect-based providers (Sigma, OneSat popup) — those
61
- * require explicit user selection via getAvailableProviders().
47
+ * If the last successful provider is known, it's attempted first
48
+ * before falling back to the full race.
62
49
  */
63
- export declare function connectWallet(config?: ConnectWalletConfig): Promise<ConnectWalletResult | null>;
50
+ export declare function connectWallet(config?: ConnectWalletConfig): Promise<ConnectWalletResult>;
64
51
  //# sourceMappingURL=connectWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectWallet.d.ts","sourceRoot":"","sources":["../src/connectWallet.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAG/C,MAAM,WAAW,oBAAoB;IACpC,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,IAAI,EAAE,MAAM,C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":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,WAAW,oBAAoB;IACpC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAA;CAC5C;AAED,MAAM,WAAW,mBAAmB;IACnC;;0DAEsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,sDAAsD;IACtD,SAAS,CAAC,EAAE,oBAAoB,EAAE,CAAA;CAClC;AAED,MAAM,WAAW,mBAAmB;IACnC,MAAM,EAAE,eAAe,CAAA;IACvB,uFAAuF;IACvF,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,iBAAkB,SAAQ,oBAAoB;IAC9D,OAAO,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAA;CAC3C;AAED,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAA;AAWtD,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAOhD;AAwCD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,CAWvF;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoC9F"}
package/dist/index.d.ts CHANGED
@@ -1,64 +1,7 @@
1
- import type { OneSatConfig, OneSatProvider } from './types';
2
- export { connectWallet, getAvailableProviders, connectSigmaWallet, type AvailableProvider, type ConnectWalletConfig, type ConnectWalletOptions, type ConnectWalletResult, type SigmaProviderConfig, type WalletProviderConfig, } from './connectWallet';
3
- export { completeSigmaOAuth, initiateSigmaOAuth, setSigmaIdentity, sigmaAuthClient, SIGMA_URL, type SigmaOAuthConfig, type SigmaOAuthResult, } from './sigma-oauth';
1
+ export { connectWallet, getAvailableProviders, loadLastProvider, type AvailableProvider, type ConnectWalletConfig, type ConnectWalletOptions, type ConnectWalletResult, type WalletProviderConfig, } from './connectWallet';
2
+ export { completeSigmaOAuth, connectSigmaWallet, initiateSigmaOAuth, setSigmaIdentity, sigmaAuthClient, SIGMA_URL, type SigmaOAuthConfig, type SigmaOAuthResult, type SigmaProviderConfig, } from './sigma-oauth';
4
3
  export { signRequest } from './auth';
5
4
  export { AuthorizationTimeoutError, CodeReplayError, type ErrorCode, ErrorCodes, FallbackRequiredError, fromErrorResponse, InsufficientFundsError, OneSatError, PopupBlockedError, PopupClosedError, StateMismatchError, TimeoutError, TransportUnavailableError, UserRejectedError, WalletLockedError, WalletNotConnectedError, } from './errors';
6
- export { type BaseMessage, createErrorResponse, createRequest, createResponse, isResponse, isValidMessage, type MessageType, MessageTypes, PROTOCOL_VERSION, type ProtocolMessage, type RequestMessage, type ResponseMessage, } from './messages';
7
- export { type PendingRequest, type PopupConfig, PopupManager } from './popup';
8
- export { OneSatBrowserProvider } from './provider';
9
- export { clearConnection, hasStoredConnection, loadConnection, type StoredConnection, saveConnection, } from './storage';
10
- export { AutoTransport, createAutoTransport, createRedirectTransport, RedirectTransport, } from './transport';
11
- export type { BalanceResult, CancelListingRequest, ConnectParams, ConnectResult, CreateListingRequest, CWIHandshakeReason, CWIRequestMessage, CWIResponseMessage, CWIState, CWIStateMessage, CWITransport, CWITransportConfig, CWITransportEvent, CWITransportEventHandler, CWITransportName, CWIWalletStatus, EventHandler, InscribeRequest, InscribeResult, ListingResult, ListOptions, MobileFallbackMode, OneSatConfig, OneSatEvent, OneSatProvider, OrdinalOutput, PurchaseListingRequest, RpcMethod, SendOrdinalsRequest, SendResult, SignMessageResult, SignTransactionRequest, SignTransactionResult, TokenOutput, TransferTokenRequest, TransportMode, Utxo, } from './types';
5
+ export type { OneSatConfig, OneSatProvider, OneSatEvent, RpcMethod, } from './types';
12
6
  export { RpcMethods } from './types';
13
- export { closePopup, getPopupContext, isPopupContext, type PopupParams, parsePopupParams, rejectRequest, sendErrorResponse, sendResponse, walletLockedError, walletNotConnectedError, } from './wallet';
14
- /**
15
- * Check if the OneSat provider is injected by browser extension
16
- * Extensions inject window.onesat with isOneSat: true
17
- */
18
- export declare function isOneSatInjected(): boolean;
19
- /**
20
- * Get the injected OneSat provider from browser extension
21
- * Returns undefined if no extension is installed
22
- */
23
- export declare function getInjectedOneSat(): OneSatProvider | undefined;
24
- /**
25
- * Create or get a OneSat provider
26
- *
27
- * Detection priority:
28
- * 1. If browser extension is installed (window.onesat.isOneSat), use it
29
- * 2. Otherwise, create a popup-based provider
30
- *
31
- * @example
32
- * ```typescript
33
- * import { createOneSat } from '@1sat/connect'
34
- *
35
- * const onesat = createOneSat({
36
- * appName: 'My dApp',
37
- * })
38
- *
39
- * // Connect to wallet (opens popup if no extension)
40
- * const { paymentAddress, ordinalAddress } = await onesat.connect()
41
- *
42
- * // Sign a transaction
43
- * const result = await onesat.signTransaction({ rawtx })
44
- * ```
45
- */
46
- export declare function createOneSat(config?: OneSatConfig): OneSatProvider;
47
- /**
48
- * Get the existing provider from window.onesat or create a new popup provider
49
- * @deprecated Use createOneSat() instead - it handles detection automatically
50
- */
51
- export declare function getOneSat(config?: OneSatConfig): OneSatProvider;
52
- /**
53
- * Check if any OneSat provider is available (extension or popup)
54
- */
55
- export declare function isOneSatAvailable(): boolean;
56
- /**
57
- * Wait for the OneSat extension to be injected
58
- * Useful for detecting extension after page load
59
- *
60
- * @param timeout - Max time to wait in ms (default: 3000)
61
- * @returns The injected provider, or throws if timeout
62
- */
63
- export declare function waitForOneSat(timeout?: number): Promise<OneSatProvider>;
64
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAG3D,OAAO,EACN,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GACzB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACN,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACrB,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGpC,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;AAEjB,OAAO,EACN,KAAK,WAAW,EAChB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,UAAU,EACV,cAAc,EACd,KAAK,WAAW,EAChB,YAAY,EACZ,gBAAgB,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,GACpB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGlD,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,KAAK,gBAAgB,EACrB,c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