@dignetwork/dig-sdk 0.2.1 → 0.4.0

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.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-Bc95rd_t.cjs';
2
- export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-Bc95rd_t.cjs';
1
+ import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-Deb8ZwaO.cjs';
2
+ export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-Deb8ZwaO.cjs';
3
3
 
4
4
  /** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
5
5
  interface WalletTransport {
@@ -70,15 +70,49 @@ declare class WalletConnectTransport implements WalletTransport {
70
70
  disconnect(): Promise<void>;
71
71
  }
72
72
 
73
+ /**
74
+ * A connector id for the 'Browser Wallet vs WalletConnect' chooser (#63) — the discoverable,
75
+ * user-facing counterpart of the lower-level {@link WalletBackend}. `"browser-wallet"` is an alias
76
+ * for the `"injected"` backend, named to match the chooser UI label every DIG frontend uses.
77
+ */
78
+ type ConnectorId = "browser-wallet" | "walletconnect";
79
+ /**
80
+ * One entry in {@link ChiaProvider.listConnectors}: a connector a chooser UI can offer, and
81
+ * whether it's currently usable.
82
+ */
83
+ interface ConnectorInfo {
84
+ /** The id to pass as `ConnectOptions.mode` once the user picks this connector. */
85
+ id: ConnectorId;
86
+ /** The underlying transport backend this connector selects. */
87
+ backend: WalletBackend;
88
+ /** Human-facing label ("Browser Wallet" / "WalletConnect") — the canonical chooser copy. */
89
+ label: string;
90
+ /**
91
+ * True iff this connector can be connected right now. Browser Wallet requires a detected
92
+ * injected `window.chia`; WalletConnect is always offered (its relay has no presence to detect).
93
+ */
94
+ available: boolean;
95
+ }
73
96
  /** Options for `ChiaProvider.connect()`. */
74
97
  interface ConnectOptions {
75
98
  /**
76
99
  * Connection mode:
77
- * • "auto" (default) — prefer the injected DIG wallet; fall back to WalletConnect if absent.
78
- * "injected" — require the injected wallet (throws if absent).
79
- * "walletconnect" — force the WalletConnect→Sage pairing.
100
+ * • "auto" (default) — prefer the injected DIG wallet; fall back to WalletConnect if
101
+ * absent. A convenience for callers that don't want to present a
102
+ * chooser; it never asks the user, so if BOTH a Browser Wallet and
103
+ * WalletConnect are viable it silently picks Browser Wallet — kept
104
+ * for backward compatibility with existing single-shot integrations.
105
+ * • "browser-wallet" — require the injected Browser Wallet (throws if absent). The
106
+ * explicit-preference value for a Connect chooser (see
107
+ * {@link ChiaProvider.listConnectors}); an alias of "injected".
108
+ * • "injected" — same as "browser-wallet" (kept for backward compatibility).
109
+ * • "walletconnect" — force the WalletConnect→Sage pairing.
110
+ *
111
+ * To offer the user a real choice — never auto-binding to whichever wallet happens to be
112
+ * injected — call {@link ChiaProvider.listConnectors} to enumerate what's available, let the
113
+ * user pick, then pass their pick's `id` (`"browser-wallet"` or `"walletconnect"`) as `mode`.
80
114
  */
81
- mode?: "auto" | WalletBackend;
115
+ mode?: "auto" | WalletBackend | ConnectorId;
82
116
  /**
83
117
  * WalletConnect options, required for the WalletConnect fallback/force path (projectId +
84
118
  * metadata + onUri). Omit if you only target the injected DIG Browser wallet.
@@ -117,6 +151,21 @@ declare class ChiaProvider {
117
151
  * injected DIG wallet and falls back to WalletConnect.
118
152
  */
119
153
  static connect(options?: ConnectOptions): Promise<ChiaProvider>;
154
+ /**
155
+ * Enumerate the connectors a 'Browser Wallet vs WalletConnect' Connect chooser can offer (#63).
156
+ * Pure and side-effect-free — it only DETECTS what's usable right now, it never connects to
157
+ * anything — so a chooser UI built around it always surfaces the choice instead of silently
158
+ * auto-binding to whichever wallet happens to be injected.
159
+ *
160
+ * @example
161
+ * const connectors = ChiaProvider.listConnectors();
162
+ * // render a button per connector, disabling any with `available: false`
163
+ * const chosen = connectors.find((c) => c.id === userPick)!;
164
+ * const provider = await ChiaProvider.connect({ mode: chosen.id, walletConnect });
165
+ */
166
+ static listConnectors(options?: {
167
+ acceptAnyInjected?: boolean;
168
+ }): ConnectorInfo[];
120
169
  /** Wrap an already-constructed transport (advanced / restored sessions). */
121
170
  static fromTransport(transport: WalletTransport): ChiaProvider;
122
171
  /** The wallet's receive address (cached after first read). */
@@ -478,7 +527,7 @@ interface SdkCapabilities {
478
527
  readonly chains: readonly string[];
479
528
  /** The default dig RPC endpoint `DigClient` reads from. */
480
529
  readonly defaultRpc: string;
481
- /** The SRI digest of the read-crypto wasm from @dignetwork/dig-client (fail-closed on mismatch). */
530
+ /** The SRI digest of the read-crypto wasm from @dignetwork/dig-capsule-wasm (fail-closed on mismatch). */
482
531
  readonly readCryptoWasmSha256: string;
483
532
  /** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
484
533
  readonly errorCodes: readonly DigSdkErrorCode[];
@@ -499,4 +548,4 @@ declare function capabilities(): SdkCapabilities;
499
548
  /** Alias for {@link capabilities} — the conventional `describe()` introspection name. */
500
549
  declare const describe: typeof capabilities;
501
550
 
502
- export { ChiaProvider, type ConnectOptions, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
551
+ export { ChiaProvider, type ConnectOptions, type ConnectorId, type ConnectorInfo, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-Bc95rd_t.js';
2
- export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-Bc95rd_t.js';
1
+ import { W as WalletBackend, a as WalletSession, S as SignResult, I as InjectedChiaProvider } from './dig-client-entry-Deb8ZwaO.js';
2
+ export { C as CollectionItem, b as CollectionItemMetadata, c as CollectionItemsPage, d as CollectionMeta, D as DEFAULT_RPC, e as DIG_CLIENT_WASM_SHA256, f as DigClient, g as DigClientOptions, h as DigClientWasm, P as ParsedUrn, R as ReadOptions, i as ReadResult, U as UrnKeys, j as WasmConfig, k as configureWasm, l as isUrn, m as loadDigClientWasm, p as parseUrn, r as reconstructUrn, n as reconstructUrnWithRoot } from './dig-client-entry-Deb8ZwaO.js';
3
3
 
4
4
  /** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
5
5
  interface WalletTransport {
@@ -70,15 +70,49 @@ declare class WalletConnectTransport implements WalletTransport {
70
70
  disconnect(): Promise<void>;
71
71
  }
72
72
 
73
+ /**
74
+ * A connector id for the 'Browser Wallet vs WalletConnect' chooser (#63) — the discoverable,
75
+ * user-facing counterpart of the lower-level {@link WalletBackend}. `"browser-wallet"` is an alias
76
+ * for the `"injected"` backend, named to match the chooser UI label every DIG frontend uses.
77
+ */
78
+ type ConnectorId = "browser-wallet" | "walletconnect";
79
+ /**
80
+ * One entry in {@link ChiaProvider.listConnectors}: a connector a chooser UI can offer, and
81
+ * whether it's currently usable.
82
+ */
83
+ interface ConnectorInfo {
84
+ /** The id to pass as `ConnectOptions.mode` once the user picks this connector. */
85
+ id: ConnectorId;
86
+ /** The underlying transport backend this connector selects. */
87
+ backend: WalletBackend;
88
+ /** Human-facing label ("Browser Wallet" / "WalletConnect") — the canonical chooser copy. */
89
+ label: string;
90
+ /**
91
+ * True iff this connector can be connected right now. Browser Wallet requires a detected
92
+ * injected `window.chia`; WalletConnect is always offered (its relay has no presence to detect).
93
+ */
94
+ available: boolean;
95
+ }
73
96
  /** Options for `ChiaProvider.connect()`. */
74
97
  interface ConnectOptions {
75
98
  /**
76
99
  * Connection mode:
77
- * • "auto" (default) — prefer the injected DIG wallet; fall back to WalletConnect if absent.
78
- * "injected" — require the injected wallet (throws if absent).
79
- * "walletconnect" — force the WalletConnect→Sage pairing.
100
+ * • "auto" (default) — prefer the injected DIG wallet; fall back to WalletConnect if
101
+ * absent. A convenience for callers that don't want to present a
102
+ * chooser; it never asks the user, so if BOTH a Browser Wallet and
103
+ * WalletConnect are viable it silently picks Browser Wallet — kept
104
+ * for backward compatibility with existing single-shot integrations.
105
+ * • "browser-wallet" — require the injected Browser Wallet (throws if absent). The
106
+ * explicit-preference value for a Connect chooser (see
107
+ * {@link ChiaProvider.listConnectors}); an alias of "injected".
108
+ * • "injected" — same as "browser-wallet" (kept for backward compatibility).
109
+ * • "walletconnect" — force the WalletConnect→Sage pairing.
110
+ *
111
+ * To offer the user a real choice — never auto-binding to whichever wallet happens to be
112
+ * injected — call {@link ChiaProvider.listConnectors} to enumerate what's available, let the
113
+ * user pick, then pass their pick's `id` (`"browser-wallet"` or `"walletconnect"`) as `mode`.
80
114
  */
81
- mode?: "auto" | WalletBackend;
115
+ mode?: "auto" | WalletBackend | ConnectorId;
82
116
  /**
83
117
  * WalletConnect options, required for the WalletConnect fallback/force path (projectId +
84
118
  * metadata + onUri). Omit if you only target the injected DIG Browser wallet.
@@ -117,6 +151,21 @@ declare class ChiaProvider {
117
151
  * injected DIG wallet and falls back to WalletConnect.
118
152
  */
119
153
  static connect(options?: ConnectOptions): Promise<ChiaProvider>;
154
+ /**
155
+ * Enumerate the connectors a 'Browser Wallet vs WalletConnect' Connect chooser can offer (#63).
156
+ * Pure and side-effect-free — it only DETECTS what's usable right now, it never connects to
157
+ * anything — so a chooser UI built around it always surfaces the choice instead of silently
158
+ * auto-binding to whichever wallet happens to be injected.
159
+ *
160
+ * @example
161
+ * const connectors = ChiaProvider.listConnectors();
162
+ * // render a button per connector, disabling any with `available: false`
163
+ * const chosen = connectors.find((c) => c.id === userPick)!;
164
+ * const provider = await ChiaProvider.connect({ mode: chosen.id, walletConnect });
165
+ */
166
+ static listConnectors(options?: {
167
+ acceptAnyInjected?: boolean;
168
+ }): ConnectorInfo[];
120
169
  /** Wrap an already-constructed transport (advanced / restored sessions). */
121
170
  static fromTransport(transport: WalletTransport): ChiaProvider;
122
171
  /** The wallet's receive address (cached after first read). */
@@ -478,7 +527,7 @@ interface SdkCapabilities {
478
527
  readonly chains: readonly string[];
479
528
  /** The default dig RPC endpoint `DigClient` reads from. */
480
529
  readonly defaultRpc: string;
481
- /** The SRI digest of the read-crypto wasm from @dignetwork/dig-client (fail-closed on mismatch). */
530
+ /** The SRI digest of the read-crypto wasm from @dignetwork/dig-capsule-wasm (fail-closed on mismatch). */
482
531
  readonly readCryptoWasmSha256: string;
483
532
  /** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
484
533
  readonly errorCodes: readonly DigSdkErrorCode[];
@@ -499,4 +548,4 @@ declare function capabilities(): SdkCapabilities;
499
548
  /** Alias for {@link capabilities} — the conventional `describe()` introspection name. */
500
549
  declare const describe: typeof capabilities;
501
550
 
502
- export { ChiaProvider, type ConnectOptions, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
551
+ export { ChiaProvider, type ConnectOptions, type ConnectorId, type ConnectorInfo, DEFAULT_CHAIN, DIG_SDK_ERROR_CODES, DigSdkError, type DigSdkErrorCode, type DigSdkErrorContext, INJECTED_TOPIC, InjectedChiaProvider, InjectedTransport, type ModuleDescriptor, type MonetizationSpends, type PaymentAssetSpec, type PaymentResult, Paywall, type PaywallOptions, type ProveAccessArgs, type RequestPaymentArgs, SDK_VERSION, SIGN_METHODS, type SdkCapabilities, SignResult, type VerifyReceiptArgs, WALLET_METHODS, WalletBackend, type WalletConnectMetadata, type WalletConnectOptions, WalletConnectTransport, type WalletMethod, WalletSession, type WalletTransport, capabilities, connectWallet, describe, getInjectedProvider, isDigSdkError, isInjectedAvailable, isTransientPublishError };
package/dist/index.js CHANGED
@@ -400,7 +400,8 @@ var ChiaProvider = class _ChiaProvider {
400
400
  * injected DIG wallet and falls back to WalletConnect.
401
401
  */
402
402
  static async connect(options = {}) {
403
- const mode = options.mode ?? "auto";
403
+ const rawMode = options.mode ?? "auto";
404
+ const mode = rawMode === "browser-wallet" ? "injected" : rawMode;
404
405
  const chain = options.chain ?? DEFAULT_CHAIN;
405
406
  const tryInjected = async () => {
406
407
  if (!isInjectedAvailable({ anyChia: options.acceptAnyInjected })) return null;
@@ -414,7 +415,7 @@ var ChiaProvider = class _ChiaProvider {
414
415
  throw new DigSdkError(
415
416
  "WC_OPTIONS_REQUIRED",
416
417
  "WalletConnect options are required to connect via WalletConnect (pass { walletConnect: { projectId, metadata, onUri } }).",
417
- { mode }
418
+ { mode: rawMode }
418
419
  );
419
420
  }
420
421
  const transport = await WalletConnectTransport.connect({
@@ -429,7 +430,7 @@ var ChiaProvider = class _ChiaProvider {
429
430
  throw new DigSdkError(
430
431
  "NO_INJECTED_WALLET",
431
432
  "No injected DIG wallet found. Open this page in the DIG Browser, or use mode 'auto'.",
432
- { mode, acceptAnyInjected: !!options.acceptAnyInjected }
433
+ { mode: rawMode, acceptAnyInjected: !!options.acceptAnyInjected }
433
434
  );
434
435
  }
435
436
  return injected;
@@ -437,6 +438,34 @@ var ChiaProvider = class _ChiaProvider {
437
438
  if (mode === "walletconnect") return tryWalletConnect();
438
439
  return await tryInjected() ?? await tryWalletConnect();
439
440
  }
441
+ /**
442
+ * Enumerate the connectors a 'Browser Wallet vs WalletConnect' Connect chooser can offer (#63).
443
+ * Pure and side-effect-free — it only DETECTS what's usable right now, it never connects to
444
+ * anything — so a chooser UI built around it always surfaces the choice instead of silently
445
+ * auto-binding to whichever wallet happens to be injected.
446
+ *
447
+ * @example
448
+ * const connectors = ChiaProvider.listConnectors();
449
+ * // render a button per connector, disabling any with `available: false`
450
+ * const chosen = connectors.find((c) => c.id === userPick)!;
451
+ * const provider = await ChiaProvider.connect({ mode: chosen.id, walletConnect });
452
+ */
453
+ static listConnectors(options = {}) {
454
+ return [
455
+ {
456
+ id: "browser-wallet",
457
+ backend: "injected",
458
+ label: "Browser Wallet",
459
+ available: isInjectedAvailable({ anyChia: options.acceptAnyInjected })
460
+ },
461
+ {
462
+ id: "walletconnect",
463
+ backend: "walletconnect",
464
+ label: "WalletConnect",
465
+ available: true
466
+ }
467
+ ];
468
+ }
440
469
  /** Wrap an already-constructed transport (advanced / restored sessions). */
441
470
  static fromTransport(transport) {
442
471
  return new _ChiaProvider(transport);
@@ -699,7 +728,7 @@ var Paywall = class {
699
728
  };
700
729
 
701
730
  // src/loader.ts
702
- var DIG_CLIENT_WASM_SHA256 = "8c983561eabca34778abf698ca7c2fba36117f87282ca649079599ef7d1b1156";
731
+ var DIG_CLIENT_WASM_SHA256 = "a186fd2d6b348a7caa3112c51b666a6618fe7cf8bb56ad395a1fab4323f6ae7e";
703
732
  var _config = {};
704
733
  var _ready = null;
705
734
  function configureWasm(config) {
@@ -734,16 +763,16 @@ async function loadNode() {
734
763
  const { createRequire } = await import('module');
735
764
  const { readFile } = await import('fs/promises');
736
765
  const require2 = createRequire(import.meta.url);
737
- const wasmPath = require2.resolve("@dignetwork/dig-client/dig_client_bg.wasm");
766
+ const wasmPath = require2.resolve("@dignetwork/dig-capsule-wasm/dig_client_bg.wasm");
738
767
  const buf = await readFile(wasmPath);
739
768
  const bytes = new Uint8Array(buf.byteLength);
740
769
  bytes.set(buf);
741
770
  assertIntegrity(await sha256Hex(bytes));
742
- const mod = await import('@dignetwork/dig-client/node');
771
+ const mod = await import('@dignetwork/dig-capsule-wasm/node');
743
772
  return mod;
744
773
  }
745
774
  async function loadBrowser() {
746
- const glueHref = _config.glueUrl ?? "@dignetwork/dig-client/web";
775
+ const glueHref = _config.glueUrl ?? "@dignetwork/dig-capsule-wasm/web";
747
776
  const mod = await import(
748
777
  /* @vite-ignore */
749
778
  glueHref
@@ -1115,7 +1144,7 @@ function undefinedFetch() {
1115
1144
  }
1116
1145
 
1117
1146
  // src/capabilities.ts
1118
- var SDK_VERSION = "0.2.1" ;
1147
+ var SDK_VERSION = "0.4.0" ;
1119
1148
  var MODULES = Object.freeze([
1120
1149
  {
1121
1150
  name: "ChiaProvider",