@sphereon/ssi-sdk.anomaly-detection 0.34.1-feature.merge.crypto.extensions.modules.37 → 0.34.1-fix.78
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.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../plugin.schema.json","../src/index.ts","../src/agent/AnomalyDetection.ts"],"sourcesContent":["{\n \"IAnomalyDetection\": {\n \"components\": {\n \"schemas\": {\n \"AnomalyDetectionLookupLocationArgs\": {\n \"$ref\": \"#/components/schemas/PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\"\n },\n \"PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\": {\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"properties\": {\n \"storeId\": {\n \"type\": \"string\"\n },\n \"namespace\": {\n \"type\": \"string\"\n },\n \"ipOrHostname\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"ipOrHostname\"]\n },\n \"AnomalyDetectionLookupLocationResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"continent\": {\n \"type\": \"string\"\n },\n \"country\": {\n \"type\": \"string\"\n }\n },\n \"additionalProperties\": false\n }\n },\n \"methods\": {\n \"anomalyDetectionLookupLocation\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationArgs\"\n },\n \"returnType\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationResult\"\n }\n }\n }\n }\n }\n}\n","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { AnomalyDetection, anomalyDetectionMethods } from './agent/AnomalyDetection'\nexport * from './types/IAnomalyDetection'\n","import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport { IAgentPlugin } from '@veramo/core'\nimport { CountryResponse, Reader } from 'mmdb-lib'\nimport { AnomalyDetectionLookupLocationArgs, AnomalyDetectionLookupLocationResult, IAnomalyDetection, IRequiredContext, schema } from '../index'\n\ntype DnsLookupFn = (hostname: string) => Promise<string>\n\nexport const anomalyDetectionMethods: Array<string> = ['lookupLocation']\n\n/**\n * {@inheritDoc IAnomalyDetection}\n */\nexport class AnomalyDetection implements IAgentPlugin {\n readonly schema = schema.IAnomalyDetection\n private readonly db: Uint8Array\n private readonly dnsLookup?: DnsLookupFn\n readonly methods: IAnomalyDetection = {\n anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),\n }\n\n constructor(args: { geoIpDB: Uint8Array; dnsLookupCallback?: DnsLookupFn }) {\n const { geoIpDB, dnsLookupCallback } = { ...args }\n if (geoIpDB === undefined || geoIpDB === null) {\n throw new Error('The geoIpDB argument is required')\n }\n this.db = geoIpDB\n this.dnsLookup = dnsLookupCallback\n }\n\n private async anomalyDetectionLookupLocation(\n args: AnomalyDetectionLookupLocationArgs,\n context: IRequiredContext,\n ): Promise<AnomalyDetectionLookupLocationResult> {\n const { ipOrHostname, storeId, namespace } = { ...args }\n const reader = new Reader<CountryResponse>(Buffer.from(this.db))\n const ipv4Reg = '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'\n const ipv6Reg =\n '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'\n let result: CountryResponse | null\n\n if (!new RegExp(ipv4Reg).test(ipOrHostname) && !new RegExp(ipv6Reg).test(ipOrHostname)) {\n const ip = await this.resolveDns(ipOrHostname)\n result = reader.get(ip)\n } else {\n result = reader.get(ipOrHostname)\n }\n\n const lookupResult = {\n continent: result?.continent?.code,\n country: result?.country?.iso_code,\n }\n\n if (contextHasPlugin(context, 'geolocationStorePersistLocation'))\n await context.agent.geolocationStorePersistLocation({\n namespace,\n storeId,\n ipOrHostname,\n locationArgs: lookupResult,\n })\n return Promise.resolve(lookupResult)\n }\n\n private async resolveDns(hostname: string): Promise<string> {\n if (this.dnsLookup) {\n return this.dnsLookup(hostname)\n }\n\n // Fallback to Node dns\n try {\n const dns = await import('dns')\n return new Promise((resolve, reject) => {\n dns.lookup(hostname, (error: NodeJS.ErrnoException | null, address: string, family: number) => {\n if (error) {\n reject(error)\n return\n }\n resolve(address)\n })\n })\n } catch (e) {\n console.error(e)\n throw new Error(\n `DNS resolution not available on this platform, use the dnsLookupCallback in the AnomalyDetection constructor to implement DNS resolution for your platform.\\r\\n${e.message}`,\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,gCAAAA,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,mBAAqB;AAAA,QACnB,YAAc;AAAA,UACZ,SAAW;AAAA,YACT,oCAAsC;AAAA,cACpC,MAAQ;AAAA,YACV;AAAA,YACA,2DAA+D;AAAA,cAC7D,MAAQ;AAAA,cACR,sBAAwB;AAAA,cACxB,YAAc;AAAA,gBACZ,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,gBACA,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,cAAgB;AAAA,kBACd,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,UAAY,CAAC,cAAc;AAAA,YAC7B;AAAA,YACA,sCAAwC;AAAA,cACtC,MAAQ;AAAA,cACR,YAAc;AAAA,gBACZ,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,sBAAwB;AAAA,YAC1B;AAAA,UACF;AAAA,UACA,SAAW;AAAA,YACT,gCAAkC;AAAA,cAChC,aAAe;AAAA,cACf,WAAa;AAAA,gBACX,MAAQ;AAAA,cACV;AAAA,cACA,YAAc;AAAA,gBACZ,MAAQ;AAAA,cACV;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAAA;;;ACjDA;;;;;;;;;ACAA,qBAAiC;AAEjC,sBAAwC;AAKjC,IAAMC,0BAAyC;EAAC;;AAKhD,IAAMC,mBAAN,MAAMA;EAZb,OAYaA;;;EACFC,SAASA,OAAOC;EACRC;EACAC;EACRC,UAA6B;IACpCC,gCAAgC,KAAKA,+BAA+BC,KAAK,IAAI;EAC/E;
|
|
1
|
+
{"version":3,"sources":["../plugin.schema.json","../src/index.ts","../src/agent/AnomalyDetection.ts"],"sourcesContent":["{\n \"IAnomalyDetection\": {\n \"components\": {\n \"schemas\": {\n \"AnomalyDetectionLookupLocationArgs\": {\n \"$ref\": \"#/components/schemas/PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\"\n },\n \"PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\": {\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"properties\": {\n \"storeId\": {\n \"type\": \"string\"\n },\n \"namespace\": {\n \"type\": \"string\"\n },\n \"ipOrHostname\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"ipOrHostname\"]\n },\n \"AnomalyDetectionLookupLocationResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"continent\": {\n \"type\": \"string\"\n },\n \"country\": {\n \"type\": \"string\"\n }\n },\n \"additionalProperties\": false\n }\n },\n \"methods\": {\n \"anomalyDetectionLookupLocation\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationArgs\"\n },\n \"returnType\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationResult\"\n }\n }\n }\n }\n }\n}\n","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { AnomalyDetection, anomalyDetectionMethods } from './agent/AnomalyDetection'\nexport * from './types/IAnomalyDetection'\n","import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport { IAgentPlugin } from '@veramo/core'\nimport { CountryResponse, Reader } from 'mmdb-lib'\nimport { AnomalyDetectionLookupLocationArgs, AnomalyDetectionLookupLocationResult, IAnomalyDetection, IRequiredContext, schema } from '../index'\n\ntype DnsLookupFn = (hostname: string) => Promise<string>\n\nexport const anomalyDetectionMethods: Array<string> = ['lookupLocation']\n\n/**\n * {@inheritDoc IAnomalyDetection}\n */\nexport class AnomalyDetection implements IAgentPlugin {\n readonly schema = schema.IAnomalyDetection\n private readonly db: Uint8Array\n private readonly dnsLookup?: DnsLookupFn\n readonly methods: IAnomalyDetection = {\n anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),\n }\n\n constructor(args: { geoIpDB: Uint8Array; dnsLookupCallback?: DnsLookupFn }) {\n const { geoIpDB, dnsLookupCallback } = { ...args }\n if (geoIpDB === undefined || geoIpDB === null) {\n throw new Error('The geoIpDB argument is required')\n }\n this.db = geoIpDB\n this.dnsLookup = dnsLookupCallback\n }\n\n private async anomalyDetectionLookupLocation(\n args: AnomalyDetectionLookupLocationArgs,\n context: IRequiredContext,\n ): Promise<AnomalyDetectionLookupLocationResult> {\n const { ipOrHostname, storeId, namespace } = { ...args }\n const reader = new Reader<CountryResponse>(Buffer.from(this.db))\n const ipv4Reg = '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'\n const ipv6Reg =\n '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'\n let result: CountryResponse | null\n\n if (!new RegExp(ipv4Reg).test(ipOrHostname) && !new RegExp(ipv6Reg).test(ipOrHostname)) {\n const ip = await this.resolveDns(ipOrHostname)\n result = reader.get(ip)\n } else {\n result = reader.get(ipOrHostname)\n }\n\n const lookupResult = {\n continent: result?.continent?.code,\n country: result?.country?.iso_code,\n }\n\n if (contextHasPlugin(context, 'geolocationStorePersistLocation'))\n await context.agent.geolocationStorePersistLocation({\n namespace,\n storeId,\n ipOrHostname,\n locationArgs: lookupResult,\n })\n return Promise.resolve(lookupResult)\n }\n\n private async resolveDns(hostname: string): Promise<string> {\n if (this.dnsLookup) {\n return this.dnsLookup(hostname)\n }\n\n // Fallback to Node dns\n try {\n const dns = await import('dns')\n return new Promise((resolve, reject) => {\n dns.lookup(hostname, (error: NodeJS.ErrnoException | null, address: string, family: number) => {\n if (error) {\n reject(error)\n return\n }\n resolve(address)\n })\n })\n } catch (e) {\n console.error(e)\n throw new Error(\n `DNS resolution not available on this platform, use the dnsLookupCallback in the AnomalyDetection constructor to implement DNS resolution for your platform.\\r\\n${e.message}`,\n )\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,gCAAAA,SAAA;AAAA,IAAAA,QAAA;AAAA,MACE,mBAAqB;AAAA,QACnB,YAAc;AAAA,UACZ,SAAW;AAAA,YACT,oCAAsC;AAAA,cACpC,MAAQ;AAAA,YACV;AAAA,YACA,2DAA+D;AAAA,cAC7D,MAAQ;AAAA,cACR,sBAAwB;AAAA,cACxB,YAAc;AAAA,gBACZ,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,gBACA,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,cAAgB;AAAA,kBACd,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,UAAY,CAAC,cAAc;AAAA,YAC7B;AAAA,YACA,sCAAwC;AAAA,cACtC,MAAQ;AAAA,cACR,YAAc;AAAA,gBACZ,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,SAAW;AA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P,QAAQO,WAAWC;MAC9BC,SAAST,QAAQS,SAASC;IAC5B;AAEA,YAAIC,iCAAiBrB,SAAS,iCAAA,EAC5B,OAAMA,QAAQsB,MAAMC,gCAAgC;MAClDpB;MACAD;MACAD;MACAuB,cAAcR;IAChB,CAAA;AACF,WAAOS,QAAQC,QAAQV,YAAAA;EACzB;EAEA,MAAcF,WAAWa,UAAmC;AAC1D,QAAI,KAAKrC,WAAW;AAClB,aAAO,KAAKA,UAAUqC,QAAAA;IACxB;AAGA,QAAI;AACF,YAAMC,MAAM,MAAM,OAAO,KAAA;AACzB,aAAO,IAAIH,QAAQ,CAACC,SAASG,WAAAA;AAC3BD,YAAIE,OAAOH,UAAU,CAACI,OAAqCC,SAAiBC,WAAAA;AAC1E,cAAIF,OAAO;AACTF,mBAAOE,KAAAA;AACP;UACF;AACAL,kBAAQM,OAAAA;QACV,CAAA;MACF,CAAA;IACF,SAASE,GAAG;AACVC,cAAQJ,MAAMG,CAAAA;AACd,YAAM,IAAInC,MACR;EAAkKmC,EAAEE,OAAO,EAAE;IAEjL;EACF;AACF;;;ADnFA,IAAMC,SAASC;","names":["module","anomalyDetectionMethods","AnomalyDetection","schema","IAnomalyDetection","db","dnsLookup","methods","anomalyDetectionLookupLocation","bind","constructor","args","geoIpDB","dnsLookupCallback","undefined","Error","context","ipOrHostname","storeId","namespace","reader","Reader","Buffer","from","ipv4Reg","ipv6Reg","result","RegExp","test","ip","resolveDns","get","lookupResult","continent","code","country","iso_code","contextHasPlugin","agent","geolocationStorePersistLocation","locationArgs","Promise","resolve","hostname","dns","reject","lookup","error","address","family","e","console","message","schema","require"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../plugin.schema.json","../src/agent/AnomalyDetection.ts","../src/index.ts"],"sourcesContent":["{\n \"IAnomalyDetection\": {\n \"components\": {\n \"schemas\": {\n \"AnomalyDetectionLookupLocationArgs\": {\n \"$ref\": \"#/components/schemas/PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\"\n },\n \"PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\": {\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"properties\": {\n \"storeId\": {\n \"type\": \"string\"\n },\n \"namespace\": {\n \"type\": \"string\"\n },\n \"ipOrHostname\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"ipOrHostname\"]\n },\n \"AnomalyDetectionLookupLocationResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"continent\": {\n \"type\": \"string\"\n },\n \"country\": {\n \"type\": \"string\"\n }\n },\n \"additionalProperties\": false\n }\n },\n \"methods\": {\n \"anomalyDetectionLookupLocation\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationArgs\"\n },\n \"returnType\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationResult\"\n }\n }\n }\n }\n }\n}\n","import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport { IAgentPlugin } from '@veramo/core'\nimport { CountryResponse, Reader } from 'mmdb-lib'\nimport { AnomalyDetectionLookupLocationArgs, AnomalyDetectionLookupLocationResult, IAnomalyDetection, IRequiredContext, schema } from '../index'\n\ntype DnsLookupFn = (hostname: string) => Promise<string>\n\nexport const anomalyDetectionMethods: Array<string> = ['lookupLocation']\n\n/**\n * {@inheritDoc IAnomalyDetection}\n */\nexport class AnomalyDetection implements IAgentPlugin {\n readonly schema = schema.IAnomalyDetection\n private readonly db: Uint8Array\n private readonly dnsLookup?: DnsLookupFn\n readonly methods: IAnomalyDetection = {\n anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),\n }\n\n constructor(args: { geoIpDB: Uint8Array; dnsLookupCallback?: DnsLookupFn }) {\n const { geoIpDB, dnsLookupCallback } = { ...args }\n if (geoIpDB === undefined || geoIpDB === null) {\n throw new Error('The geoIpDB argument is required')\n }\n this.db = geoIpDB\n this.dnsLookup = dnsLookupCallback\n }\n\n private async anomalyDetectionLookupLocation(\n args: AnomalyDetectionLookupLocationArgs,\n context: IRequiredContext,\n ): Promise<AnomalyDetectionLookupLocationResult> {\n const { ipOrHostname, storeId, namespace } = { ...args }\n const reader = new Reader<CountryResponse>(Buffer.from(this.db))\n const ipv4Reg = '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'\n const ipv6Reg =\n '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'\n let result: CountryResponse | null\n\n if (!new RegExp(ipv4Reg).test(ipOrHostname) && !new RegExp(ipv6Reg).test(ipOrHostname)) {\n const ip = await this.resolveDns(ipOrHostname)\n result = reader.get(ip)\n } else {\n result = reader.get(ipOrHostname)\n }\n\n const lookupResult = {\n continent: result?.continent?.code,\n country: result?.country?.iso_code,\n }\n\n if (contextHasPlugin(context, 'geolocationStorePersistLocation'))\n await context.agent.geolocationStorePersistLocation({\n namespace,\n storeId,\n ipOrHostname,\n locationArgs: lookupResult,\n })\n return Promise.resolve(lookupResult)\n }\n\n private async resolveDns(hostname: string): Promise<string> {\n if (this.dnsLookup) {\n return this.dnsLookup(hostname)\n }\n\n // Fallback to Node dns\n try {\n const dns = await import('dns')\n return new Promise((resolve, reject) => {\n dns.lookup(hostname, (error: NodeJS.ErrnoException | null, address: string, family: number) => {\n if (error) {\n reject(error)\n return\n }\n resolve(address)\n })\n })\n } catch (e) {\n console.error(e)\n throw new Error(\n `DNS resolution not available on this platform, use the dnsLookupCallback in the AnomalyDetection constructor to implement DNS resolution for your platform.\\r\\n${e.message}`,\n )\n }\n }\n}\n","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { AnomalyDetection, anomalyDetectionMethods } from './agent/AnomalyDetection'\nexport * from './types/IAnomalyDetection'\n"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA,MACE,mBAAqB;AAAA,QACnB,YAAc;AAAA,UACZ,SAAW;AAAA,YACT,oCAAsC;AAAA,cACpC,MAAQ;AAAA,YACV;AAAA,YACA,2DAA+D;AAAA,cAC7D,MAAQ;AAAA,cACR,sBAAwB;AAAA,cACxB,YAAc;AAAA,gBACZ,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,gBACA,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,cAAgB;AAAA,kBACd,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,UAAY,CAAC,cAAc;AAAA,YAC7B;AAAA,YACA,sCAAwC;AAAA,cACtC,MAAQ;AAAA,cACR,YAAc;AAAA,gBACZ,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,sBAAwB;AAAA,YAC1B;AAAA,UACF;AAAA,UACA,SAAW;AAAA,YACT,gCAAkC;AAAA,cAChC,aAAe;AAAA,cACf,WAAa;AAAA,gBACX,MAAQ;AAAA,cACV;AAAA,cACA,YAAc;AAAA,gBACZ,MAAQ;AAAA,cACV;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAAA;;;ACjDA,SAASA,wBAAwB;AAEjC,SAA0BC,cAAc;AAKjC,IAAMC,0BAAyC;EAAC;;AAKhD,IAAMC,mBAAN,MAAMA;EAZb,OAYaA;;;EACFC,SAASA,OAAOC;EACRC;EACAC;EACRC,UAA6B;IACpCC,gCAAgC,KAAKA,+BAA+BC,KAAK,IAAI;EAC/E;
|
|
1
|
+
{"version":3,"sources":["../plugin.schema.json","../src/agent/AnomalyDetection.ts","../src/index.ts"],"sourcesContent":["{\n \"IAnomalyDetection\": {\n \"components\": {\n \"schemas\": {\n \"AnomalyDetectionLookupLocationArgs\": {\n \"$ref\": \"#/components/schemas/PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\"\n },\n \"PartialBy<GeolocationStoreArgs,(\\\"storeId\\\"|\\\"namespace\\\")>\": {\n \"type\": \"object\",\n \"additionalProperties\": false,\n \"properties\": {\n \"storeId\": {\n \"type\": \"string\"\n },\n \"namespace\": {\n \"type\": \"string\"\n },\n \"ipOrHostname\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\"ipOrHostname\"]\n },\n \"AnomalyDetectionLookupLocationResult\": {\n \"type\": \"object\",\n \"properties\": {\n \"continent\": {\n \"type\": \"string\"\n },\n \"country\": {\n \"type\": \"string\"\n }\n },\n \"additionalProperties\": false\n }\n },\n \"methods\": {\n \"anomalyDetectionLookupLocation\": {\n \"description\": \"\",\n \"arguments\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationArgs\"\n },\n \"returnType\": {\n \"$ref\": \"#/components/schemas/AnomalyDetectionLookupLocationResult\"\n }\n }\n }\n }\n }\n}\n","import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'\nimport { IAgentPlugin } from '@veramo/core'\nimport { CountryResponse, Reader } from 'mmdb-lib'\nimport { AnomalyDetectionLookupLocationArgs, AnomalyDetectionLookupLocationResult, IAnomalyDetection, IRequiredContext, schema } from '../index'\n\ntype DnsLookupFn = (hostname: string) => Promise<string>\n\nexport const anomalyDetectionMethods: Array<string> = ['lookupLocation']\n\n/**\n * {@inheritDoc IAnomalyDetection}\n */\nexport class AnomalyDetection implements IAgentPlugin {\n readonly schema = schema.IAnomalyDetection\n private readonly db: Uint8Array\n private readonly dnsLookup?: DnsLookupFn\n readonly methods: IAnomalyDetection = {\n anomalyDetectionLookupLocation: this.anomalyDetectionLookupLocation.bind(this),\n }\n\n constructor(args: { geoIpDB: Uint8Array; dnsLookupCallback?: DnsLookupFn }) {\n const { geoIpDB, dnsLookupCallback } = { ...args }\n if (geoIpDB === undefined || geoIpDB === null) {\n throw new Error('The geoIpDB argument is required')\n }\n this.db = geoIpDB\n this.dnsLookup = dnsLookupCallback\n }\n\n private async anomalyDetectionLookupLocation(\n args: AnomalyDetectionLookupLocationArgs,\n context: IRequiredContext,\n ): Promise<AnomalyDetectionLookupLocationResult> {\n const { ipOrHostname, storeId, namespace } = { ...args }\n const reader = new Reader<CountryResponse>(Buffer.from(this.db))\n const ipv4Reg = '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])'\n const ipv6Reg =\n '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'\n let result: CountryResponse | null\n\n if (!new RegExp(ipv4Reg).test(ipOrHostname) && !new RegExp(ipv6Reg).test(ipOrHostname)) {\n const ip = await this.resolveDns(ipOrHostname)\n result = reader.get(ip)\n } else {\n result = reader.get(ipOrHostname)\n }\n\n const lookupResult = {\n continent: result?.continent?.code,\n country: result?.country?.iso_code,\n }\n\n if (contextHasPlugin(context, 'geolocationStorePersistLocation'))\n await context.agent.geolocationStorePersistLocation({\n namespace,\n storeId,\n ipOrHostname,\n locationArgs: lookupResult,\n })\n return Promise.resolve(lookupResult)\n }\n\n private async resolveDns(hostname: string): Promise<string> {\n if (this.dnsLookup) {\n return this.dnsLookup(hostname)\n }\n\n // Fallback to Node dns\n try {\n const dns = await import('dns')\n return new Promise((resolve, reject) => {\n dns.lookup(hostname, (error: NodeJS.ErrnoException | null, address: string, family: number) => {\n if (error) {\n reject(error)\n return\n }\n resolve(address)\n })\n })\n } catch (e) {\n console.error(e)\n throw new Error(\n `DNS resolution not available on this platform, use the dnsLookupCallback in the AnomalyDetection constructor to implement DNS resolution for your platform.\\r\\n${e.message}`,\n )\n }\n }\n}\n","/**\n * @public\n */\nconst schema = require('../plugin.schema.json')\nexport { schema }\nexport { AnomalyDetection, anomalyDetectionMethods } from './agent/AnomalyDetection'\nexport * from './types/IAnomalyDetection'\n"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA,MACE,mBAAqB;AAAA,QACnB,YAAc;AAAA,UACZ,SAAW;AAAA,YACT,oCAAsC;AAAA,cACpC,MAAQ;AAAA,YACV;AAAA,YACA,2DAA+D;AAAA,cAC7D,MAAQ;AAAA,cACR,sBAAwB;AAAA,cACxB,YAAc;AAAA,gBACZ,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,gBACA,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,cAAgB;AAAA,kBACd,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,UAAY,CAAC,cAAc;AAAA,YAC7B;AAAA,YACA,sCAAwC;AAAA,cACtC,MAAQ;AAAA,cACR,YAAc;AAAA,gBACZ,WAAa;AAAA,kBACX,MAAQ;AAAA,gBACV;AAAA,gBACA,SAAW;AAAA,kBACT,MAAQ;AAAA,gBACV;AAAA,cACF;AAAA,cACA,sBAAwB;AAAA,YAC1B;AAAA,UACF;AAAA,UACA,SAAW;AAAA,YACT,gCAAkC;AAAA,cAChC,aAAe;AAAA,cACf,WAAa;AAAA,gBACX,MAAQ;AAAA,cACV;AAAA,cACA,YAAc;AAAA,gBACZ,MAAQ;AAAA,cACV;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA;AAAA;;;ACjDA,SAASA,wBAAwB;AAEjC,SAA0BC,cAAc;AAKjC,IAAMC,0BAAyC;EAAC;;AAKhD,IAAMC,mBAAN,MAAMA;EAZb,OAYaA;;;EACFC,SAASA,OAAOC;EACRC;EACAC;EACRC,UAA6B;IACpCC,gCAAgC,KAAKA,+BAA+BC,KAAK,IAAI;EAC/E;EAEAC,YAAYC,MAAgE;AAC1E,UAAM,EAAEC,SA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AASE,GAAG;AACVC,cAAQJ,MAAMG,CAAAA;AACd,YAAM,IAAInC,MACR;EAAkKmC,EAAEE,OAAO,EAAE;IAEjL;EACF;AACF;;;ACnFA,IAAMC,SAASC;","names":["contextHasPlugin","Reader","anomalyDetectionMethods","AnomalyDetection","schema","IAnomalyDetection","db","dnsLookup","methods","anomalyDetectionLookupLocation","bind","constructor","args","geoIpDB","dnsLookupCallback","undefined","Error","context","ipOrHostname","storeId","namespace","reader","Reader","Buffer","from","ipv4Reg","ipv6Reg","result","RegExp","test","ip","resolveDns","get","lookupResult","continent","code","country","iso_code","contextHasPlugin","agent","geolocationStorePersistLocation","locationArgs","Promise","resolve","hostname","dns","reject","lookup","error","address","family","e","console","message","schema","require"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.anomaly-detection",
|
|
3
|
-
"version": "0.34.1-
|
|
3
|
+
"version": "0.34.1-fix.78+5114f005",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"generate-plugin-schema": "tsx ../../packages/dev/bin/sphereon.js dev generate-plugin-schema"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@sphereon/ssi-sdk.geolocation-store": "0.34.1-
|
|
31
|
-
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-
|
|
32
|
-
"cross-fetch": "^
|
|
30
|
+
"@sphereon/ssi-sdk.geolocation-store": "0.34.1-fix.78+5114f005",
|
|
31
|
+
"@sphereon/ssi-sdk.kv-store-temp": "0.34.1-fix.78+5114f005",
|
|
32
|
+
"cross-fetch": "^4.1.0",
|
|
33
33
|
"debug": "^4.3.5",
|
|
34
34
|
"dns-query": "^0.11.2",
|
|
35
35
|
"mmdb-lib": "^2.1.1",
|
|
36
36
|
"typeorm": "0.3.20"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@sphereon/ssi-sdk.agent-config": "0.34.1-
|
|
39
|
+
"@sphereon/ssi-sdk.agent-config": "0.34.1-fix.78+5114f005",
|
|
40
40
|
"@types/node": "^20.17.1",
|
|
41
41
|
"@veramo/remote-client": "4.2.0",
|
|
42
42
|
"@veramo/remote-server": "4.2.0"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"Veramo",
|
|
62
62
|
"Anomaly Detection"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "5114f005ed3bbb851b2c7bb226cbb195fc70bf92"
|
|
65
65
|
}
|