@dignetwork/dig-sdk 0.2.0 → 0.3.3

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-ChYxUvBn.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-ChYxUvBn.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). */
@@ -386,7 +435,7 @@ declare const DIG_SDK_ERROR_CODES: Readonly<{
386
435
  readonly RPC_ERROR: "RPC_ERROR";
387
436
  /** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
388
437
  readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
389
- /** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
438
+ /** The read-crypto wasm failed its SRI integrity check — fail closed. */
390
439
  readonly WASM_INTEGRITY: "WASM_INTEGRITY";
391
440
  /** The read-crypto wasm could not be loaded (fetch/resolve failure). */
392
441
  readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
@@ -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 vendored read-crypto wasm (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-ChYxUvBn.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-ChYxUvBn.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). */
@@ -386,7 +435,7 @@ declare const DIG_SDK_ERROR_CODES: Readonly<{
386
435
  readonly RPC_ERROR: "RPC_ERROR";
387
436
  /** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
388
437
  readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
389
- /** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
438
+ /** The read-crypto wasm failed its SRI integrity check — fail closed. */
390
439
  readonly WASM_INTEGRITY: "WASM_INTEGRITY";
391
440
  /** The read-crypto wasm could not be loaded (fetch/resolve failure). */
392
441
  readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
@@ -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 vendored read-crypto wasm (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
@@ -43,7 +43,7 @@ var DIG_SDK_ERROR_CODES = Object.freeze({
43
43
  RPC_ERROR: "RPC_ERROR",
44
44
  /** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
45
45
  RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE",
46
- /** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
46
+ /** The read-crypto wasm failed its SRI integrity check — fail closed. */
47
47
  WASM_INTEGRITY: "WASM_INTEGRITY",
48
48
  /** The read-crypto wasm could not be loaded (fetch/resolve failure). */
49
49
  WASM_LOAD_FAILED: "WASM_LOAD_FAILED",
@@ -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 = "ff486be806f908a2a90780e499a04dbd34e10e3b97be0470cb9ee841a1e49e77";
731
+ var DIG_CLIENT_WASM_SHA256 = "a186fd2d6b348a7caa3112c51b666a6618fe7cf8bb56ad395a1fab4323f6ae7e";
703
732
  var _config = {};
704
733
  var _ready = null;
705
734
  function configureWasm(config) {
@@ -731,47 +760,54 @@ function assertIntegrity(hex) {
731
760
  }
732
761
  }
733
762
  async function loadNode() {
763
+ const { createRequire } = await import('module');
734
764
  const { readFile } = await import('fs/promises');
735
- const { fileURLToPath, pathToFileURL } = await import('url');
736
- const path = await import('path');
737
- const here = path.dirname(fileURLToPath(import.meta.url));
738
- const vendorDir = path.resolve(here, "..", "vendor");
739
- const wasmPath = path.join(vendorDir, "dig_client_bg.wasm");
740
- const gluePath = path.join(vendorDir, "dig_client.mjs");
765
+ const require2 = createRequire(import.meta.url);
766
+ const wasmPath = require2.resolve("@dignetwork/dig-capsule-wasm/dig_client_bg.wasm");
741
767
  const buf = await readFile(wasmPath);
742
768
  const bytes = new Uint8Array(buf.byteLength);
743
769
  bytes.set(buf);
744
- return { glueHref: pathToFileURL(gluePath).href, bytes };
770
+ assertIntegrity(await sha256Hex(bytes));
771
+ const mod = await import('@dignetwork/dig-capsule-wasm/node');
772
+ return mod;
745
773
  }
746
774
  async function loadBrowser() {
747
- const glueHref = _config.glueUrl ?? new URL("../vendor/dig_client.mjs", import.meta.url).href;
748
- let bytes;
749
- if (_config.wasmBytes) {
750
- bytes = _config.wasmBytes;
775
+ const glueHref = _config.glueUrl ?? "@dignetwork/dig-capsule-wasm/web";
776
+ const mod = await import(
777
+ /* @vite-ignore */
778
+ glueHref
779
+ );
780
+ if (typeof mod.default !== "function") {
781
+ throw new DigSdkError(
782
+ "WASM_LOAD_FAILED",
783
+ "dig-client web build exposed no init function (unexpected module shape)",
784
+ {}
785
+ );
786
+ }
787
+ if (_config.wasmBytes || _config.wasmUrl) {
788
+ let bytes;
789
+ if (_config.wasmBytes) {
790
+ bytes = _config.wasmBytes;
791
+ } else {
792
+ const wasmUrl = _config.wasmUrl;
793
+ const res = await fetch(wasmUrl);
794
+ if (!res.ok)
795
+ throw new DigSdkError("WASM_LOAD_FAILED", `dig-client wasm fetch failed (${res.status})`, {
796
+ httpStatus: res.status,
797
+ wasmUrl
798
+ });
799
+ bytes = await res.arrayBuffer();
800
+ }
801
+ assertIntegrity(await sha256Hex(bytes));
802
+ await mod.default({ module_or_path: bytes });
751
803
  } else {
752
- const wasmUrl = _config.wasmUrl ?? new URL("../vendor/dig_client_bg.wasm", import.meta.url).href;
753
- const res = await fetch(wasmUrl);
754
- if (!res.ok)
755
- throw new DigSdkError("WASM_LOAD_FAILED", `dig-client wasm fetch failed (${res.status})`, {
756
- httpStatus: res.status,
757
- wasmUrl
758
- });
759
- bytes = await res.arrayBuffer();
804
+ await mod.default();
760
805
  }
761
- return { glueHref, bytes };
806
+ return mod;
762
807
  }
763
808
  function loadDigClientWasm() {
764
809
  if (_ready) return _ready;
765
- _ready = (async () => {
766
- const { glueHref, bytes } = isNode ? await loadNode() : await loadBrowser();
767
- assertIntegrity(await sha256Hex(bytes));
768
- const mod = await import(
769
- /* @vite-ignore */
770
- glueHref
771
- );
772
- await mod.default({ module_or_path: bytes });
773
- return mod;
774
- })().catch((e) => {
810
+ _ready = (isNode ? loadNode() : loadBrowser()).catch((e) => {
775
811
  _ready = null;
776
812
  throw e;
777
813
  });
@@ -1108,7 +1144,7 @@ function undefinedFetch() {
1108
1144
  }
1109
1145
 
1110
1146
  // src/capabilities.ts
1111
- var SDK_VERSION = "0.2.0" ;
1147
+ var SDK_VERSION = "0.3.3" ;
1112
1148
  var MODULES = Object.freeze([
1113
1149
  {
1114
1150
  name: "ChiaProvider",