@dignetwork/dig-sdk 0.2.0 → 0.2.1

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-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';
3
3
 
4
4
  /** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
5
5
  interface WalletTransport {
@@ -386,7 +386,7 @@ declare const DIG_SDK_ERROR_CODES: Readonly<{
386
386
  readonly RPC_ERROR: "RPC_ERROR";
387
387
  /** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
388
388
  readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
389
- /** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
389
+ /** The read-crypto wasm failed its SRI integrity check — fail closed. */
390
390
  readonly WASM_INTEGRITY: "WASM_INTEGRITY";
391
391
  /** The read-crypto wasm could not be loaded (fetch/resolve failure). */
392
392
  readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
@@ -478,7 +478,7 @@ interface SdkCapabilities {
478
478
  readonly chains: readonly string[];
479
479
  /** The default dig RPC endpoint `DigClient` reads from. */
480
480
  readonly defaultRpc: string;
481
- /** The SRI digest of the vendored read-crypto wasm (fail-closed on mismatch). */
481
+ /** The SRI digest of the read-crypto wasm from @dignetwork/dig-client (fail-closed on mismatch). */
482
482
  readonly readCryptoWasmSha256: string;
483
483
  /** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
484
484
  readonly errorCodes: readonly DigSdkErrorCode[];
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-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';
3
3
 
4
4
  /** A wallet transport: connect, then `request` CHIP-0002 methods through it. */
5
5
  interface WalletTransport {
@@ -386,7 +386,7 @@ declare const DIG_SDK_ERROR_CODES: Readonly<{
386
386
  readonly RPC_ERROR: "RPC_ERROR";
387
387
  /** The dig RPC returned a malformed / inconsistent payload (e.g. chunk-length mismatch). */
388
388
  readonly RPC_MALFORMED_RESPONSE: "RPC_MALFORMED_RESPONSE";
389
- /** The vendored read-crypto wasm failed its SRI integrity check — fail closed. */
389
+ /** The read-crypto wasm failed its SRI integrity check — fail closed. */
390
390
  readonly WASM_INTEGRITY: "WASM_INTEGRITY";
391
391
  /** The read-crypto wasm could not be loaded (fetch/resolve failure). */
392
392
  readonly WASM_LOAD_FAILED: "WASM_LOAD_FAILED";
@@ -478,7 +478,7 @@ interface SdkCapabilities {
478
478
  readonly chains: readonly string[];
479
479
  /** The default dig RPC endpoint `DigClient` reads from. */
480
480
  readonly defaultRpc: string;
481
- /** The SRI digest of the vendored read-crypto wasm (fail-closed on mismatch). */
481
+ /** The SRI digest of the read-crypto wasm from @dignetwork/dig-client (fail-closed on mismatch). */
482
482
  readonly readCryptoWasmSha256: string;
483
483
  /** The stable error-code catalogue (UPPER_SNAKE) consumers can branch on. */
484
484
  readonly errorCodes: readonly DigSdkErrorCode[];
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",
@@ -699,7 +699,7 @@ var Paywall = class {
699
699
  };
700
700
 
701
701
  // src/loader.ts
702
- var DIG_CLIENT_WASM_SHA256 = "ff486be806f908a2a90780e499a04dbd34e10e3b97be0470cb9ee841a1e49e77";
702
+ var DIG_CLIENT_WASM_SHA256 = "8c983561eabca34778abf698ca7c2fba36117f87282ca649079599ef7d1b1156";
703
703
  var _config = {};
704
704
  var _ready = null;
705
705
  function configureWasm(config) {
@@ -731,47 +731,54 @@ function assertIntegrity(hex) {
731
731
  }
732
732
  }
733
733
  async function loadNode() {
734
+ const { createRequire } = await import('module');
734
735
  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");
736
+ const require2 = createRequire(import.meta.url);
737
+ const wasmPath = require2.resolve("@dignetwork/dig-client/dig_client_bg.wasm");
741
738
  const buf = await readFile(wasmPath);
742
739
  const bytes = new Uint8Array(buf.byteLength);
743
740
  bytes.set(buf);
744
- return { glueHref: pathToFileURL(gluePath).href, bytes };
741
+ assertIntegrity(await sha256Hex(bytes));
742
+ const mod = await import('@dignetwork/dig-client/node');
743
+ return mod;
745
744
  }
746
745
  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;
746
+ const glueHref = _config.glueUrl ?? "@dignetwork/dig-client/web";
747
+ const mod = await import(
748
+ /* @vite-ignore */
749
+ glueHref
750
+ );
751
+ if (typeof mod.default !== "function") {
752
+ throw new DigSdkError(
753
+ "WASM_LOAD_FAILED",
754
+ "dig-client web build exposed no init function (unexpected module shape)",
755
+ {}
756
+ );
757
+ }
758
+ if (_config.wasmBytes || _config.wasmUrl) {
759
+ let bytes;
760
+ if (_config.wasmBytes) {
761
+ bytes = _config.wasmBytes;
762
+ } else {
763
+ const wasmUrl = _config.wasmUrl;
764
+ const res = await fetch(wasmUrl);
765
+ if (!res.ok)
766
+ throw new DigSdkError("WASM_LOAD_FAILED", `dig-client wasm fetch failed (${res.status})`, {
767
+ httpStatus: res.status,
768
+ wasmUrl
769
+ });
770
+ bytes = await res.arrayBuffer();
771
+ }
772
+ assertIntegrity(await sha256Hex(bytes));
773
+ await mod.default({ module_or_path: bytes });
751
774
  } 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();
775
+ await mod.default();
760
776
  }
761
- return { glueHref, bytes };
777
+ return mod;
762
778
  }
763
779
  function loadDigClientWasm() {
764
780
  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) => {
781
+ _ready = (isNode ? loadNode() : loadBrowser()).catch((e) => {
775
782
  _ready = null;
776
783
  throw e;
777
784
  });
@@ -1108,7 +1115,7 @@ function undefinedFetch() {
1108
1115
  }
1109
1116
 
1110
1117
  // src/capabilities.ts
1111
- var SDK_VERSION = "0.2.0" ;
1118
+ var SDK_VERSION = "0.2.1" ;
1112
1119
  var MODULES = Object.freeze([
1113
1120
  {
1114
1121
  name: "ChiaProvider",