@neus/sdk 1.0.10 → 1.1.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/cjs/index.cjs CHANGED
@@ -1081,6 +1081,11 @@ function normalizeBrowserSignerString(raw) {
1081
1081
  }
1082
1082
  return null;
1083
1083
  }
1084
+ function isPlaceholderNeusSignature(signature) {
1085
+ const s = typeof signature === "string" ? signature.trim() : "";
1086
+ if (!s) return true;
1087
+ return /^0x0+$/i.test(s);
1088
+ }
1084
1089
  var FALLBACK_PUBLIC_VERIFIER_CATALOG, EVM_ADDRESS_RE, WALLET_LINK_RELATIONSHIP_TYPES, validateVerifierData, NeusClient;
1085
1090
  var init_client = __esm({
1086
1091
  "client.js"() {
@@ -1278,6 +1283,17 @@ var init_client = __esm({
1278
1283
  if (data.agentType && !["ai", "bot", "service", "automation", "agent"].includes(data.agentType)) {
1279
1284
  return { valid: false, error: "agentType must be one of: ai, bot, service, automation, agent" };
1280
1285
  }
1286
+ if (data.defaultRuntime && typeof data.defaultRuntime === "object") {
1287
+ if (data.defaultRuntime.provider && typeof data.defaultRuntime.provider === "string" && data.defaultRuntime.provider.length > 64) {
1288
+ return { valid: false, error: "defaultRuntime.provider must be 64 chars or less" };
1289
+ }
1290
+ if (data.defaultRuntime.model && typeof data.defaultRuntime.model === "string" && data.defaultRuntime.model.length > 128) {
1291
+ return { valid: false, error: "defaultRuntime.model must be 128 chars or less" };
1292
+ }
1293
+ if (data.defaultRuntime.mode && typeof data.defaultRuntime.mode === "string" && data.defaultRuntime.mode.length > 64) {
1294
+ return { valid: false, error: "defaultRuntime.mode must be 64 chars or less" };
1295
+ }
1296
+ }
1281
1297
  break;
1282
1298
  case "agent-delegation":
1283
1299
  if (!data.controllerWallet || !validateWalletAddress(data.controllerWallet)) {
@@ -1292,6 +1308,18 @@ var init_client = __esm({
1292
1308
  if (data.expiresAt && (typeof data.expiresAt !== "number" || data.expiresAt < Date.now())) {
1293
1309
  return { valid: false, error: "expiresAt must be a future timestamp" };
1294
1310
  }
1311
+ if (data.model && typeof data.model === "string" && data.model.length > 128) {
1312
+ return { valid: false, error: "model must be 128 chars or less" };
1313
+ }
1314
+ if (data.provider && typeof data.provider === "string" && data.provider.length > 64) {
1315
+ return { valid: false, error: "provider must be 64 chars or less" };
1316
+ }
1317
+ if (data.allowedActions && Array.isArray(data.allowedActions) && data.allowedActions.length > 32) {
1318
+ return { valid: false, error: "allowedActions must have 32 items or less" };
1319
+ }
1320
+ if (data.deniedActions && Array.isArray(data.deniedActions) && data.deniedActions.length > 32) {
1321
+ return { valid: false, error: "deniedActions must have 32 items or less" };
1322
+ }
1295
1323
  break;
1296
1324
  case "ai-content-moderation":
1297
1325
  if (!data.content || typeof data.content !== "string") {
@@ -1481,7 +1509,7 @@ var init_client = __esm({
1481
1509
  }
1482
1510
  _getDefaultBrowserWallet() {
1483
1511
  if (typeof window === "undefined") return null;
1484
- return window.ethereum || window.solana || window.phantom && window.phantom.solana || null;
1512
+ return window.ethereum || null;
1485
1513
  }
1486
1514
  async _buildPrivateGateAuth({ address, wallet, chain, signatureMethod } = {}) {
1487
1515
  const providerWallet = wallet || this._getDefaultBrowserWallet();
@@ -1606,8 +1634,57 @@ var init_client = __esm({
1606
1634
  ...label ? { label } : {}
1607
1635
  };
1608
1636
  }
1637
+ async verifyFromApp(params) {
1638
+ if (!params || typeof params !== "object") {
1639
+ throw new ValidationError("verifyFromApp requires a params object");
1640
+ }
1641
+ const {
1642
+ user,
1643
+ verifier = "ownership-basic",
1644
+ content,
1645
+ data: explicitData = null,
1646
+ options = {}
1647
+ } = params;
1648
+ if (!user || typeof user !== "object") {
1649
+ throw new ValidationError("verifyFromApp requires user object");
1650
+ }
1651
+ const walletAddress = user.walletAddress || user.address || user.identity;
1652
+ if (!walletAddress || typeof walletAddress !== "string") {
1653
+ throw new ValidationError("verifyFromApp requires user.walletAddress");
1654
+ }
1655
+ const delegationQHash = this.config.appLinkQHash || typeof process !== "undefined" && process.env && process.env.NEUS_APP_LINK_QHASH || null;
1656
+ let data;
1657
+ if (explicitData && typeof explicitData === "object") {
1658
+ data = { owner: walletAddress, ...explicitData };
1659
+ } else if (content && typeof content === "object") {
1660
+ data = {
1661
+ owner: walletAddress,
1662
+ content: JSON.stringify(content),
1663
+ contentType: typeof content.contentType === "string" ? content.contentType : "application/json",
1664
+ reference: content.reference || { type: "other" }
1665
+ };
1666
+ } else if (typeof content === "string") {
1667
+ data = {
1668
+ owner: walletAddress,
1669
+ content,
1670
+ reference: { type: "other" }
1671
+ };
1672
+ } else {
1673
+ data = { owner: walletAddress, reference: { type: "other" } };
1674
+ }
1675
+ const signedTimestamp = Date.now();
1676
+ const verifierIds = [verifier];
1677
+ return this.verify({
1678
+ verifierIds,
1679
+ data,
1680
+ walletAddress,
1681
+ signedTimestamp,
1682
+ ...delegationQHash ? { delegationQHash } : {},
1683
+ options
1684
+ });
1685
+ }
1609
1686
  async verify(params) {
1610
- if ((!params?.signature || !params?.walletAddress) && (params?.verifier || params?.content || params?.data)) {
1687
+ if ((isPlaceholderNeusSignature(params?.signature) || !params?.signature || !params?.walletAddress) && (params?.verifier || params?.content || params?.data)) {
1611
1688
  const { content, verifier = "ownership-basic", data: data2 = null, wallet = null, options: options2 = {} } = params;
1612
1689
  if (verifier === "ownership-basic" && !data2 && (!content || typeof content !== "string")) {
1613
1690
  throw new ValidationError("content is required and must be a string (or use data param with owner + reference)");
@@ -1660,7 +1737,7 @@ var init_client = __esm({
1660
1737
  }
1661
1738
  } else {
1662
1739
  if (typeof window === "undefined" || !window.ethereum) {
1663
- throw new ConfigurationError("No Web3 wallet detected. Please install MetaMask or provide wallet parameter.");
1740
+ throw new ConfigurationError("No EVM browser wallet detected. Provide wallet explicitly for non-EVM flows and include chain as a CAIP-2 value.");
1664
1741
  }
1665
1742
  await window.ethereum.request({ method: "eth_requestAccounts" });
1666
1743
  provider = window.ethereum;
@@ -1776,9 +1853,13 @@ var init_client = __esm({
1776
1853
  verificationData = {
1777
1854
  agentId: data2.agentId,
1778
1855
  agentWallet: data2?.agentWallet || walletAddress2,
1856
+ ...data2?.agentChainRef && { agentChainRef: data2.agentChainRef },
1857
+ ...data2?.agentAccountId && { agentAccountId: data2.agentAccountId },
1779
1858
  ...data2?.agentLabel && { agentLabel: data2.agentLabel },
1780
1859
  ...data2?.agentType && { agentType: data2.agentType },
1860
+ ...data2?.avatar && { avatar: data2.avatar },
1781
1861
  ...data2?.description && { description: data2.description },
1862
+ ...data2?.defaultRuntime && { defaultRuntime: data2.defaultRuntime },
1782
1863
  ...data2?.capabilities && { capabilities: data2.capabilities },
1783
1864
  ...data2?.instructions && { instructions: data2.instructions },
1784
1865
  ...data2?.skills && { skills: data2.skills },
@@ -1790,7 +1871,11 @@ var init_client = __esm({
1790
1871
  }
1791
1872
  verificationData = {
1792
1873
  controllerWallet: data2?.controllerWallet || walletAddress2,
1874
+ ...data2?.controllerChainRef && { controllerChainRef: data2.controllerChainRef },
1793
1875
  agentWallet: data2.agentWallet,
1876
+ ...data2?.agentChainRef && { agentChainRef: data2.agentChainRef },
1877
+ ...data2?.controllerAccountId && { controllerAccountId: data2.controllerAccountId },
1878
+ ...data2?.agentAccountId && { agentAccountId: data2.agentAccountId },
1794
1879
  ...data2?.agentId && { agentId: data2.agentId },
1795
1880
  ...data2?.scope && { scope: data2.scope },
1796
1881
  ...data2?.permissions && { permissions: data2.permissions },
@@ -1799,7 +1884,13 @@ var init_client = __esm({
1799
1884
  ...data2?.receiptDisclosure && { receiptDisclosure: data2.receiptDisclosure },
1800
1885
  ...data2?.expiresAt && { expiresAt: data2.expiresAt },
1801
1886
  ...data2?.instructions && { instructions: data2.instructions },
1802
- ...data2?.skills && { skills: data2.skills }
1887
+ ...data2?.skills && { skills: data2.skills },
1888
+ ...data2?.model && { model: data2.model },
1889
+ ...data2?.provider && { provider: data2.provider },
1890
+ ...data2?.runtimePolicy && { runtimePolicy: data2.runtimePolicy },
1891
+ ...data2?.allowedActions && { allowedActions: data2.allowedActions },
1892
+ ...data2?.deniedActions && { deniedActions: data2.deniedActions },
1893
+ ...data2?.approvalPolicy && { approvalPolicy: data2.approvalPolicy }
1803
1894
  };
1804
1895
  } else if (verifier === "ai-content-moderation") {
1805
1896
  if (!data2?.content) {
@@ -1948,13 +2039,15 @@ ${bytes.length}`;
1948
2039
  verifierIds,
1949
2040
  data,
1950
2041
  walletAddress,
1951
- signature,
2042
+ signature: rawSignature,
1952
2043
  signedTimestamp,
1953
2044
  chainId,
1954
2045
  chain,
1955
2046
  signatureMethod,
2047
+ delegationQHash,
1956
2048
  options = {}
1957
2049
  } = params;
2050
+ const signature = isPlaceholderNeusSignature(rawSignature) ? void 0 : rawSignature;
1958
2051
  const resolvedChainId = chainId || (chain ? null : NEUS_CONSTANTS.HUB_CHAIN_ID);
1959
2052
  const normalizeVerifierId = (id) => {
1960
2053
  if (typeof id !== "string") return id;
@@ -1971,8 +2064,11 @@ ${bytes.length}`;
1971
2064
  if (!walletAddress || typeof walletAddress !== "string") {
1972
2065
  throw new ValidationError("walletAddress is required");
1973
2066
  }
1974
- if (!signature) {
1975
- throw new ValidationError("signature is required");
2067
+ const hasAppAttribution = typeof this.config.appId === "string" && this.config.appId.trim().length > 0;
2068
+ if (!signature && !delegationQHash && !hasAppAttribution) {
2069
+ throw new ValidationError(
2070
+ "signature, delegationQHash, or NeusClient config appId (sent as X-Neus-App) is required"
2071
+ );
1976
2072
  }
1977
2073
  if (!signedTimestamp || typeof signedTimestamp !== "number") {
1978
2074
  throw new ValidationError("signedTimestamp is required");
@@ -1998,11 +2094,12 @@ ${bytes.length}`;
1998
2094
  verifierIds: normalizedVerifierIds,
1999
2095
  data,
2000
2096
  walletAddress,
2001
- signature,
2097
+ ...signature ? { signature } : {},
2002
2098
  signedTimestamp,
2003
2099
  ...resolvedChainId !== null && { chainId: resolvedChainId },
2004
2100
  ...chain && { chain },
2005
2101
  ...signatureMethod && { signatureMethod },
2102
+ ...delegationQHash && { delegationQHash },
2006
2103
  options: optionsPayload
2007
2104
  };
2008
2105
  const response = await this._makeRequest("POST", "/api/v1/verification", requestData);
@@ -2012,19 +2109,17 @@ ${bytes.length}`;
2012
2109
  return this._formatResponse(response);
2013
2110
  }
2014
2111
  async getProof(qHash) {
2015
- const resolvedQHash = qHash;
2016
- if (!resolvedQHash || typeof resolvedQHash !== "string") {
2112
+ if (!qHash || typeof qHash !== "string") {
2017
2113
  throw new ValidationError("qHash is required");
2018
2114
  }
2019
- const response = await this._makeRequest("GET", `/api/v1/proofs/${resolvedQHash}`);
2115
+ const response = await this._makeRequest("GET", `/api/v1/proofs/${qHash}`);
2020
2116
  if (!response.success) {
2021
2117
  throw new ApiError(`Failed to get proof: ${response.error?.message || "Unknown error"}`, response.error);
2022
2118
  }
2023
2119
  return this._formatResponse(response);
2024
2120
  }
2025
2121
  async getPrivateProof(qHash, wallet = null) {
2026
- const resolvedQHash = qHash;
2027
- if (!resolvedQHash || typeof resolvedQHash !== "string") {
2122
+ if (!qHash || typeof qHash !== "string") {
2028
2123
  throw new ValidationError("qHash is required");
2029
2124
  }
2030
2125
  const isPreSignedAuth = wallet && typeof wallet === "object" && typeof wallet.walletAddress === "string" && typeof wallet.signature === "string" && typeof wallet.signedTimestamp === "number";
@@ -2037,7 +2132,7 @@ ${bytes.length}`;
2037
2132
  ...typeof auth.chain === "string" && auth.chain.trim() ? { "x-chain": auth.chain.trim() } : {},
2038
2133
  ...typeof auth.signatureMethod === "string" && auth.signatureMethod.trim() ? { "x-signature-method": auth.signatureMethod.trim() } : {}
2039
2134
  };
2040
- const response2 = await this._makeRequest("GET", `/api/v1/proofs/${resolvedQHash}`, null, headers);
2135
+ const response2 = await this._makeRequest("GET", `/api/v1/proofs/${qHash}`, null, headers);
2041
2136
  if (!response2.success) {
2042
2137
  throw new ApiError(
2043
2138
  `Failed to access private proof: ${response2.error?.message || "Unauthorized"}`,
@@ -2058,7 +2153,7 @@ ${bytes.length}`;
2058
2153
  const message = constructVerificationMessage({
2059
2154
  walletAddress,
2060
2155
  signedTimestamp,
2061
- data: { action: "access_private_proof", qHash: resolvedQHash },
2156
+ data: { action: "access_private_proof", qHash },
2062
2157
  verifierIds: ["ownership-basic"],
2063
2158
  ...signerIsEvm ? { chainId: this._getHubChainId() } : { chain }
2064
2159
  });
@@ -2076,7 +2171,7 @@ ${bytes.length}`;
2076
2171
  }
2077
2172
  throw new ValidationError(`Failed to sign message: ${error.message}`);
2078
2173
  }
2079
- const response = await this._makeRequest("GET", `/api/v1/proofs/${resolvedQHash}`, null, {
2174
+ const response = await this._makeRequest("GET", `/api/v1/proofs/${qHash}`, null, {
2080
2175
  "x-wallet-address": walletAddress,
2081
2176
  "x-signature": signature,
2082
2177
  "x-signed-timestamp": signedTimestamp.toString(),
@@ -2114,20 +2209,19 @@ ${bytes.length}`;
2114
2209
  };
2115
2210
  }
2116
2211
  async pollProofStatus(qHash, options = {}) {
2117
- const resolvedQHash = qHash;
2118
2212
  const {
2119
2213
  interval = 5e3,
2120
2214
  timeout = 12e4,
2121
2215
  onProgress
2122
2216
  } = options;
2123
- if (!resolvedQHash || typeof resolvedQHash !== "string") {
2217
+ if (!qHash || typeof qHash !== "string") {
2124
2218
  throw new ValidationError("qHash is required");
2125
2219
  }
2126
2220
  const startTime = Date.now();
2127
2221
  let consecutiveRateLimits = 0;
2128
2222
  while (Date.now() - startTime < timeout) {
2129
2223
  try {
2130
- const status = await this.getProof(resolvedQHash);
2224
+ const status = await this.getProof(qHash);
2131
2225
  consecutiveRateLimits = 0;
2132
2226
  if (onProgress && typeof onProgress === "function") {
2133
2227
  onProgress(status.data || status);
@@ -2170,8 +2264,7 @@ ${bytes.length}`;
2170
2264
  }
2171
2265
  }
2172
2266
  async revokeOwnProof(qHash, wallet) {
2173
- const resolvedQHash = qHash;
2174
- if (!resolvedQHash || typeof resolvedQHash !== "string") {
2267
+ if (!qHash || typeof qHash !== "string") {
2175
2268
  throw new ValidationError("qHash is required");
2176
2269
  }
2177
2270
  const providerWallet = wallet || this._getDefaultBrowserWallet();
@@ -2186,7 +2279,7 @@ ${bytes.length}`;
2186
2279
  const message = constructVerificationMessage({
2187
2280
  walletAddress: address,
2188
2281
  signedTimestamp,
2189
- data: { action: "revoke_proof", qHash: resolvedQHash },
2282
+ data: { action: "revoke_proof", qHash },
2190
2283
  verifierIds: ["ownership-basic"],
2191
2284
  ...signerIsEvm ? { chainId: this._getHubChainId() } : { chain }
2192
2285
  });
@@ -2204,7 +2297,7 @@ ${bytes.length}`;
2204
2297
  }
2205
2298
  throw new ValidationError(`Failed to sign revocation: ${error.message}`);
2206
2299
  }
2207
- const res = await this._makeRequest("POST", `/api/v1/proofs/revoke-self/${resolvedQHash}`, {
2300
+ const res = await this._makeRequest("POST", `/api/v1/proofs/revoke-self/${qHash}`, {
2208
2301
  walletAddress: address,
2209
2302
  signature,
2210
2303
  signedTimestamp,
@@ -2611,10 +2704,7 @@ ${bytes.length}`;
2611
2704
  }
2612
2705
  }
2613
2706
  _formatResponse(response) {
2614
- const qHash = response?.data?.qHash || response?.qHash || response?.data?.resource?.qHash || response?.data?.proofId || // Legacy input compatibility only. Do not expose or store proofId.
2615
- response?.proofId || // Legacy input compatibility only. Do not expose or store proofId.
2616
- response?.data?.resource?.proofId || // Legacy input compatibility only. Do not expose or store proofId.
2617
- response?.data?.id;
2707
+ const qHash = response?.data?.qHash || response?.qHash || response?.data?.resource?.qHash || response?.data?.id;
2618
2708
  const status = response?.data?.status || response?.status || response?.data?.resource?.status || (response?.success ? "completed" : "unknown");
2619
2709
  return {
2620
2710
  success: response.success,