@sirosfoundation/wmp-js 0.5.0 → 0.5.2

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.
@@ -40,7 +40,12 @@ export declare function extractDomain(identifier: string): string;
40
40
  /**
41
41
  * Fetch the well-known WMP configuration for any WMP identifier.
42
42
  *
43
- * Extracts the domain and fetches `https://<domain>/.well-known/wmp-configuration`.
44
- * Throws if no domain can be extracted or the fetch fails.
43
+ * For a full URL (e.g. `https://host/wmp-engine/wmp`), tries the well-known
44
+ * at the URL's own path prefix FIRST (`https://host/wmp-engine/.well-known/
45
+ * wmp-configuration`) — path-prefixed deployments (a reverse proxy's
46
+ * location) serve it there — and falls back to the domain root.
47
+ * For bare identifiers (domains, DIDs), fetches the domain root.
48
+ *
49
+ * Throws if no domain can be extracted or every fetch fails.
45
50
  */
46
51
  export declare function discoverEndpoint(identifier: string, fetchFn?: typeof globalThis.fetch): Promise<WellKnownConfig>;
package/dist/discovery.js CHANGED
@@ -51,20 +51,51 @@ export function extractDomain(identifier) {
51
51
  /**
52
52
  * Fetch the well-known WMP configuration for any WMP identifier.
53
53
  *
54
- * Extracts the domain and fetches `https://<domain>/.well-known/wmp-configuration`.
55
- * Throws if no domain can be extracted or the fetch fails.
54
+ * For a full URL (e.g. `https://host/wmp-engine/wmp`), tries the well-known
55
+ * at the URL's own path prefix FIRST (`https://host/wmp-engine/.well-known/
56
+ * wmp-configuration`) — path-prefixed deployments (a reverse proxy's
57
+ * location) serve it there — and falls back to the domain root.
58
+ * For bare identifiers (domains, DIDs), fetches the domain root.
59
+ *
60
+ * Throws if no domain can be extracted or every fetch fails.
56
61
  */
57
62
  export async function discoverEndpoint(identifier, fetchFn = globalThis.fetch.bind(globalThis)) {
58
63
  const domain = extractDomain(identifier);
59
64
  if (!domain) {
60
65
  throw new Error(`Cannot extract domain from identifier "${identifier}": use session parameters or a profile resolver`);
61
66
  }
62
- const url = `https://${domain}/.well-known/wmp-configuration`;
63
- const resp = await fetchFn(url, {
64
- headers: { Accept: "application/json" },
65
- });
66
- if (!resp.ok) {
67
- throw new Error(`WMP discovery failed for ${url}: HTTP ${resp.status}`);
67
+ // The candidate well-known URLs, first-wins: the URL's own path prefix
68
+ // (a reverse-proxied deployment), then the domain root.
69
+ const candidates = [];
70
+ if (identifier.startsWith("https://")) {
71
+ try {
72
+ const url = new URL(identifier);
73
+ const path = url.pathname.replace(/\/+$/, "").replace(/\/wmp$/, "");
74
+ if (path && path !== "/") {
75
+ candidates.push(`${url.origin}${path}/.well-known/wmp-configuration`);
76
+ }
77
+ }
78
+ catch {
79
+ // fall through to the domain root
80
+ }
81
+ }
82
+ candidates.push(`https://${domain}/.well-known/wmp-configuration`);
83
+ let lastError;
84
+ for (const url of candidates) {
85
+ try {
86
+ const resp = await fetchFn(url, {
87
+ headers: { Accept: "application/json" },
88
+ });
89
+ if (resp.ok) {
90
+ return (await resp.json());
91
+ }
92
+ lastError = new Error(`WMP discovery failed for ${url}: HTTP ${resp.status}`);
93
+ }
94
+ catch (err) {
95
+ lastError = err;
96
+ }
68
97
  }
69
- return (await resp.json());
98
+ throw lastError instanceof Error
99
+ ? lastError
100
+ : new Error(`WMP discovery failed for ${identifier}`);
70
101
  }
package/dist/types.d.ts CHANGED
@@ -113,6 +113,8 @@ export declare const ErrorCode: {
113
113
  readonly ConsignmentModeUnsupported: -31016;
114
114
  readonly AssuranceLevelUnsupported: -31017;
115
115
  readonly PolicyUnsupported: -31018;
116
+ /** Core §3.8.2: the decrypted plaintext does not match the sender's `plaintext_hash` commitment (§5.2.1). The message MUST NOT be acknowledged. */
117
+ readonly PlaintextHashMismatch: -31019;
116
118
  };
117
119
  export interface AuthObject {
118
120
  type: string;
package/dist/types.js CHANGED
@@ -54,6 +54,8 @@ export const ErrorCode = {
54
54
  ConsignmentModeUnsupported: -31016,
55
55
  AssuranceLevelUnsupported: -31017,
56
56
  PolicyUnsupported: -31018,
57
+ /** Core §3.8.2: the decrypted plaintext does not match the sender's `plaintext_hash` commitment (§5.2.1). The message MUST NOT be acknowledged. */
58
+ PlaintextHashMismatch: -31019,
57
59
  };
58
60
  /** Authentication type constants. */
59
61
  export const AuthType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sirosfoundation/wmp-js",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Wallet Messaging Protocol (WMP) client library — JSON-RPC 2.0 over WebSocket and HTTP+SSE",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",