keyring-agent-core 0.2.29 → 0.2.30
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.ts +110 -16
- package/dist/index.js +92 -57
- package/dist/index.native.js +166 -131
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1863,6 +1863,16 @@ interface WebsiteTrustKeyringAgentConfig {
|
|
|
1863
1863
|
llm?: LLMProviderConfig;
|
|
1864
1864
|
/** Bring your own LLM provider (e.g. a shared instance). Overrides `llm`. */
|
|
1865
1865
|
provider?: LLMProvider;
|
|
1866
|
+
/**
|
|
1867
|
+
* The ecosystem the input URLs belong to. Every URL handed to this agent is a
|
|
1868
|
+
* site that integrates WalletConnect — i.e. a blockchain / Web3 dApp — so the
|
|
1869
|
+
* default ({@link DEFAULT_ECOSYSTEM_CONTEXT}) tells the investigation to scope
|
|
1870
|
+
* its web search to that ecosystem FIRST (which brand it likely imitates,
|
|
1871
|
+
* which official domains to look up, which scam sources to consult) while
|
|
1872
|
+
* still flagging a major non-crypto impersonation. Pass a different string to
|
|
1873
|
+
* reuse the agent for another context.
|
|
1874
|
+
*/
|
|
1875
|
+
ecosystemContext?: string;
|
|
1866
1876
|
/** Enable debug logging. */
|
|
1867
1877
|
debug?: boolean;
|
|
1868
1878
|
}
|
|
@@ -1877,8 +1887,8 @@ interface WebsiteTrustInput {
|
|
|
1877
1887
|
*/
|
|
1878
1888
|
isMarkOfficial: boolean;
|
|
1879
1889
|
/**
|
|
1880
|
-
* Language for the user-facing strings (`answer`, `reasons`) —
|
|
1881
|
-
* ("vi", "en") or a language name. Defaults to English.
|
|
1890
|
+
* Language for the user-facing strings (`answer`, `reasons`, `keyFeatures`) —
|
|
1891
|
+
* a BCP-47 tag ("vi", "en") or a language name. Defaults to English.
|
|
1882
1892
|
*/
|
|
1883
1893
|
language?: string;
|
|
1884
1894
|
/** Cancels the underlying LLM requests when aborted. */
|
|
@@ -1911,13 +1921,27 @@ interface WebsiteTrustExtraData {
|
|
|
1911
1921
|
* legitimate-but-obscure site is never defamed. Present ONLY when `isPhishing`.
|
|
1912
1922
|
*/
|
|
1913
1923
|
reasons?: string[];
|
|
1924
|
+
/**
|
|
1925
|
+
* 3-5 features the site offers, each a full, informative sentence naming the
|
|
1926
|
+
* feature AND what the user can do with it (e.g. token swaps, NFT minting,
|
|
1927
|
+
* cross-chain bridging, staking), written in the requested language —
|
|
1928
|
+
* complementing the high-level `answer`. Present ONLY for a SAFE site — i.e.
|
|
1929
|
+
* when the caller pre-marked it
|
|
1930
|
+
* official (`isMarkOfficial: true`) OR the analysis found it is not phishing
|
|
1931
|
+
* (`isPhishing: false`). Omitted for a flagged site, since advertising the
|
|
1932
|
+
* features of a dangerous look-alike would mislead the user.
|
|
1933
|
+
*/
|
|
1934
|
+
keyFeatures?: string[];
|
|
1914
1935
|
}
|
|
1915
1936
|
/** Result of {@link WebsiteTrustKeyringAgent.chat}. */
|
|
1916
1937
|
interface WebsiteTrustResult {
|
|
1917
1938
|
/**
|
|
1918
1939
|
* Natural-language information ABOUT the site under test — what it is, what it
|
|
1919
|
-
* does and who runs it —
|
|
1920
|
-
* language.
|
|
1940
|
+
* does and who runs it — a PURELY DESCRIPTIVE, high-level overview in the
|
|
1941
|
+
* requested language. It deliberately does NOT state the safety verdict: any
|
|
1942
|
+
* danger is conveyed (in a cautious, non-definitive tone) through `reasons`,
|
|
1943
|
+
* and the boolean verdict through `isPhishing`. The purpose is to tell the user
|
|
1944
|
+
* what the provided site actually is.
|
|
1921
1945
|
*/
|
|
1922
1946
|
answer: string;
|
|
1923
1947
|
/** Structured trust signals. */
|
|
@@ -1942,11 +1966,14 @@ interface WebsiteTrustResult {
|
|
|
1942
1966
|
* (trusted by the caller, `isPhishing: false`).
|
|
1943
1967
|
*
|
|
1944
1968
|
* Returns `{ answer, extraData: { currentSite, isPhishing, copiedSite?,
|
|
1945
|
-
* reasons? } }
|
|
1969
|
+
* reasons?, keyFeatures? } }`, where `keyFeatures` (3-5 site features) is present
|
|
1970
|
+
* only for a safe site. Designed to be exported and used standalone.
|
|
1946
1971
|
*/
|
|
1947
1972
|
declare class WebsiteTrustKeyringAgent {
|
|
1948
1973
|
private readonly llm;
|
|
1949
1974
|
private readonly debug;
|
|
1975
|
+
/** Ecosystem prior scoping every search-grounded call (see {@link DEFAULT_ECOSYSTEM_CONTEXT}). */
|
|
1976
|
+
private readonly ecosystem;
|
|
1950
1977
|
constructor(config?: WebsiteTrustKeyringAgentConfig);
|
|
1951
1978
|
chat(input: WebsiteTrustInput): Promise<WebsiteTrustResult>;
|
|
1952
1979
|
/**
|
|
@@ -1961,14 +1988,23 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
1961
1988
|
* step returning an empty/unparseable turn used to blank out the analysis).
|
|
1962
1989
|
*/
|
|
1963
1990
|
private investigate;
|
|
1964
|
-
/** Gather a plain description for a caller-trusted (official) site. */
|
|
1991
|
+
/** Gather a plain description + feature list for a caller-trusted (official) site. */
|
|
1965
1992
|
private describeOfficial;
|
|
1993
|
+
/**
|
|
1994
|
+
* Focused feature-only gather, used as a fallback for a SAFE untrusted site
|
|
1995
|
+
* when the (phishing-focused) {@link investigate} call came back with no
|
|
1996
|
+
* features. A small dedicated call reliably yields the 3-5 features — the user
|
|
1997
|
+
* value for a legitimate site — without bloating the verdict call.
|
|
1998
|
+
*/
|
|
1999
|
+
private gatherKeyFeatures;
|
|
1966
2000
|
/**
|
|
1967
2001
|
* ONE non-search call that turns the finished assessment into the user-facing
|
|
1968
|
-
* `answer` + `reasons`, in the requested language. Because
|
|
1969
|
-
* SAME call — with the language mandated at the system level
|
|
1970
|
-
* the same language and never leak the English evidence.
|
|
1971
|
-
* facts (English) only if the model reply is unusable, so
|
|
2002
|
+
* `answer` + `reasons` + `keyFeatures`, in the requested language. Because they
|
|
2003
|
+
* all come from the SAME call — with the language mandated at the system level
|
|
2004
|
+
* — they are always the same language and never leak the English evidence.
|
|
2005
|
+
* Falls back to the raw facts (English) only if the model reply is unusable, so
|
|
2006
|
+
* we never return empty. `keyFeatures` are produced only for a SAFE site (not
|
|
2007
|
+
* phishing) — features of a flagged look-alike are never advertised.
|
|
1972
2008
|
*/
|
|
1973
2009
|
private present;
|
|
1974
2010
|
/**
|
|
@@ -1984,6 +2020,13 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
1984
2020
|
* language NAME (via {@link languageLabel}), not a bare tag.
|
|
1985
2021
|
*/
|
|
1986
2022
|
private presentationSystem;
|
|
2023
|
+
/**
|
|
2024
|
+
* System instruction for the search-grounded gather calls: the configured
|
|
2025
|
+
* ecosystem prior ({@link ecosystem}) prepended to the anti-impersonation
|
|
2026
|
+
* {@link GATHER_SYSTEM_PROMPT}, so every web search is scoped to the
|
|
2027
|
+
* WalletConnect/Web3 context without loosening the existing rigor.
|
|
2028
|
+
*/
|
|
2029
|
+
private gatherSystem;
|
|
1987
2030
|
/**
|
|
1988
2031
|
* One focused LLM call returning the parsed JSON object.
|
|
1989
2032
|
*
|
|
@@ -1997,10 +2040,34 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
1997
2040
|
* (a single attempt used to blank out the whole analysis).
|
|
1998
2041
|
*/
|
|
1999
2042
|
private askJson;
|
|
2000
|
-
/**
|
|
2043
|
+
/**
|
|
2044
|
+
* Hostname when the URL parses, else the raw (trimmed) input — with any
|
|
2045
|
+
* IDN/punycode labels decoded back to Unicode. The decode is the crucial step
|
|
2046
|
+
* for homoglyph phishing: `new URL()` (in Node) renders an internationalized
|
|
2047
|
+
* host as ASCII punycode (`xn--bnance-...`), which would hide the look-alike
|
|
2048
|
+
* characters from BOTH the model and the code. Returning the real Unicode form
|
|
2049
|
+
* means the model sees (and can analyze) the actual address, and the
|
|
2050
|
+
* look-alike-character check below sees the non-ASCII letters.
|
|
2051
|
+
*/
|
|
2001
2052
|
private normalizeSite;
|
|
2002
|
-
/**
|
|
2053
|
+
/**
|
|
2054
|
+
* Lowercased hostname (IDN already decoded by {@link normalizeSite}) with any
|
|
2055
|
+
* scheme/path and a leading "www." stripped.
|
|
2056
|
+
*/
|
|
2003
2057
|
private toHost;
|
|
2058
|
+
/**
|
|
2059
|
+
* Decode every `xn--` (punycode) label in a host back to its Unicode form so a
|
|
2060
|
+
* homoglyph address surfaces its real, non-ASCII characters. A no-op for a
|
|
2061
|
+
* plain ASCII host. Self-contained — no Node/browser-only API — so it behaves
|
|
2062
|
+
* the same in Node, the browser and React Native.
|
|
2063
|
+
*/
|
|
2064
|
+
private decodeIdn;
|
|
2065
|
+
/**
|
|
2066
|
+
* Decode a single RFC 3492 punycode label (the part AFTER the "xn--" prefix)
|
|
2067
|
+
* to Unicode. Returns the input unchanged if it is not valid punycode, so a
|
|
2068
|
+
* malformed label never throws.
|
|
2069
|
+
*/
|
|
2070
|
+
private punycodeDecodeLabel;
|
|
2004
2071
|
/**
|
|
2005
2072
|
* True when `test` is the SAME registrable domain as `official` (or a real
|
|
2006
2073
|
* subdomain of it) — a deterministic, byte-exact comparison. This is what
|
|
@@ -2011,8 +2078,16 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
2011
2078
|
private isSameRegistrableDomain;
|
|
2012
2079
|
/** Lowercased, letters-and-digits-only form (drops dots, hyphens, etc.). */
|
|
2013
2080
|
private alnum;
|
|
2014
|
-
/**
|
|
2015
|
-
|
|
2081
|
+
/**
|
|
2082
|
+
* The host's labels as alnum tokens, e.g. "opensee.co.uk" → ["opensee","co",
|
|
2083
|
+
* "uk"]. Comparing a brand core against EVERY label (rather than guessing which
|
|
2084
|
+
* one is "registrable") sidesteps the public-suffix problem entirely: a
|
|
2085
|
+
* typosquat on a multi-level TLD ("opensee.co.uk") is caught without hard-coding
|
|
2086
|
+
* a list of suffixes — the brand label is just one of the labels we test.
|
|
2087
|
+
*/
|
|
2088
|
+
private hostLabels;
|
|
2089
|
+
/** The brand "core" — the first (leftmost) significant label of a domain, e.g. "opensea.io" → "opensea". */
|
|
2090
|
+
private brandCore;
|
|
2016
2091
|
/** Levenshtein edit distance between two strings. */
|
|
2017
2092
|
private editDistance;
|
|
2018
2093
|
/**
|
|
@@ -2031,6 +2106,16 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
2031
2106
|
* any brand the model can name, so it covers the class, not one domain.
|
|
2032
2107
|
*/
|
|
2033
2108
|
private carriesBrandName;
|
|
2109
|
+
/**
|
|
2110
|
+
* True when `candidate` looks like a TYPO- or COMBO-squat of the canonical
|
|
2111
|
+
* `official` domain — used to scrub the model's `affiliatedDomains` list so a
|
|
2112
|
+
* search-poisoned answer cannot self-whitelist the squat under test. Pure code,
|
|
2113
|
+
* no enumerated list. A real subdomain / the official domain itself returns
|
|
2114
|
+
* false (kept), and an EXACT-name-different-TLD entry also returns false: it may
|
|
2115
|
+
* be a legitimate regional variant we cannot tell apart from a TLD swap in code,
|
|
2116
|
+
* so we defer THAT call to the model rather than risk dropping a real one.
|
|
2117
|
+
*/
|
|
2118
|
+
private looksLikeSquatOf;
|
|
2034
2119
|
/**
|
|
2035
2120
|
* Name the specific look-alike trick a domain uses against the official one,
|
|
2036
2121
|
* when it is one of the high-confidence, deterministically detectable cases.
|
|
@@ -2043,10 +2128,19 @@ declare class WebsiteTrustKeyringAgent {
|
|
|
2043
2128
|
/** Trim a value to a non-empty string, treating null-ish words as absent. */
|
|
2044
2129
|
private cleanStr;
|
|
2045
2130
|
/**
|
|
2046
|
-
* Normalize a model `string[]` into a clean array. Accepts an array of
|
|
2047
|
-
*
|
|
2131
|
+
* Normalize a model `string[]` into a clean array. Accepts an array of strings
|
|
2132
|
+
* (or OBJECTS — models often answer a "name + explanation" request with
|
|
2133
|
+
* `{ feature, description }` items; those are coerced rather than dropped), or a
|
|
2134
|
+
* single string (split on lines / bullets) as a fallback.
|
|
2048
2135
|
*/
|
|
2049
2136
|
private cleanStrArray;
|
|
2137
|
+
/**
|
|
2138
|
+
* A model list item → a clean string. A plain string is trimmed as-is; an
|
|
2139
|
+
* object (e.g. `{ feature, description }` / `{ name, detail }` / `{ title,
|
|
2140
|
+
* text }`) is folded into "label — detail", so a structured answer to a
|
|
2141
|
+
* sentence request is preserved instead of silently lost.
|
|
2142
|
+
*/
|
|
2143
|
+
private coerceToStr;
|
|
2050
2144
|
/** Drop case-insensitive duplicate strings, preserving order. */
|
|
2051
2145
|
private dedupe;
|
|
2052
2146
|
}
|