@reyaxyz/risk-sdk 0.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/LICENSE.md ADDED
@@ -0,0 +1 @@
1
+ MIT License
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @reyaxyz/risk-sdk
2
+
3
+ <p align="center"> Risk sdk for the Reya Network </p>
4
+
5
+ <br />
6
+
7
+ | Statements | Branches | Functions | Lines |
8
+ | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
+ | ![Statements](https://img.shields.io/badge/statements-0%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-0%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-0%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-0%25-red.svg?style=flat) |
10
+
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ var common_1 = require("@reyaxyz/common");
58
+ var axios_1 = __importDefault(require("axios"));
59
+ var GeofencingClient = /** @class */ (function (_super) {
60
+ __extends(GeofencingClient, _super);
61
+ function GeofencingClient(ipInfoApiKey, host, apiTimeout) {
62
+ var _this = _super.call(this, host, apiTimeout) || this;
63
+ _this.cache = {}; // Cache for storing IP info results
64
+ _this.ipInfoApiKey = ipInfoApiKey;
65
+ return _this;
66
+ }
67
+ GeofencingClient.prototype.checkIPAddress = function (params) {
68
+ return __awaiter(this, void 0, void 0, function () {
69
+ var cachedResult, url, response, ipInfo;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ cachedResult = this.cache[params.ipAddress];
74
+ if (cachedResult) {
75
+ // Return the cached result if available
76
+ return [2 /*return*/, {
77
+ isVpn: cachedResult.privacy.vpn,
78
+ }];
79
+ }
80
+ url = "https://ipinfo.io/".concat(params.ipAddress, "?token=").concat(this.ipInfoApiKey);
81
+ return [4 /*yield*/, axios_1.default.get(url)];
82
+ case 1:
83
+ response = _a.sent();
84
+ ipInfo = response.data;
85
+ // Store the result in cache before returning
86
+ this.cache[params.ipAddress] = ipInfo;
87
+ return [2 /*return*/, {
88
+ isVpn: ipInfo.privacy.vpn,
89
+ }];
90
+ }
91
+ });
92
+ });
93
+ };
94
+ return GeofencingClient;
95
+ }(common_1.RestClient));
96
+ exports.default = GeofencingClient;
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA6C;AAE7C,gDAA0B;AAO1B;IAA8C,oCAAU;IAItD,0BAAY,YAAoB,EAAE,IAAY,EAAE,UAA0B;QACxE,YAAA,MAAK,YAAC,IAAI,EAAE,UAAU,CAAC,SAAC;QAHlB,WAAK,GAAgB,EAAE,CAAC,CAAC,oCAAoC;QAInE,KAAI,CAAC,YAAY,GAAG,YAAY,CAAC;;IACnC,CAAC;IAEK,yCAAc,GAApB,UACE,MAA4B;;;;;;wBAGtB,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;wBAClD,IAAI,YAAY,EAAE,CAAC;4BACjB,wCAAwC;4BACxC,sBAAO;oCACL,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG;iCAChC,EAAC;wBACJ,CAAC;wBAGK,GAAG,GAAG,4BAAqB,MAAM,CAAC,SAAS,oBAAU,IAAI,CAAC,YAAY,CAAE,CAAC;wBAC9D,qBAAM,eAAK,CAAC,GAAG,CAAS,GAAG,CAAC,EAAA;;wBAAvC,QAAQ,GAAG,SAA4B;wBACvC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC;wBAE7B,6CAA6C;wBAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;wBAEtC,sBAAO;gCACL,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG;6BAC1B,EAAC;;;;KACH;IACH,uBAAC;AAAD,CAAC,AAjCD,CAA8C,mBAAU,GAiCvD","sourcesContent":["import { RestClient } from '@reyaxyz/common';\nimport { CheckIPAddressParams, CheckIPAddressResult, IpInfo } from './types';\nimport axios from 'axios';\n\n// Define a cache interface\ninterface IpInfoCache {\n [key: string]: IpInfo;\n}\n\nexport default class GeofencingClient extends RestClient {\n readonly ipInfoApiKey: string;\n private cache: IpInfoCache = {}; // Cache for storing IP info results\n\n constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null) {\n super(host, apiTimeout);\n this.ipInfoApiKey = ipInfoApiKey;\n }\n\n async checkIPAddress(\n params: CheckIPAddressParams,\n ): Promise<CheckIPAddressResult> {\n // Check if we already have the result in cache\n const cachedResult = this.cache[params.ipAddress];\n if (cachedResult) {\n // Return the cached result if available\n return {\n isVpn: cachedResult.privacy.vpn,\n };\n }\n\n // If the result is not in cache, make a request to ipinfo\n const url = `https://ipinfo.io/${params.ipAddress}?token=${this.ipInfoApiKey}`;\n const response = await axios.get<IpInfo>(url);\n const ipInfo = response.data;\n\n // Store the result in cache before returning\n this.cache[params.ipAddress] = ipInfo;\n\n return {\n isVpn: ipInfo.privacy.vpn,\n };\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/geofencing/types.ts"],"names":[],"mappings":"","sourcesContent":["export type CheckIPAddressParams = {\n ipAddress: string;\n};\n\nexport type CheckIPAddressResult = {\n isVpn: boolean;\n};\n\nexport type IpInfo = {\n ip: string;\n hostname: string;\n city: string;\n region: string;\n country: string;\n loc: string;\n org: string;\n postal: string;\n timezone: string;\n privacy: {\n vpn: boolean;\n proxy: boolean;\n tor: boolean;\n relay: boolean;\n hosting: boolean;\n service: string;\n };\n countryCode: string;\n countryFlag: {\n emoji: string;\n unicode: string;\n };\n countryFlagURL: string;\n countryCurrency: {\n code: string;\n symbol: string;\n };\n continent: {\n code: string;\n name: string;\n };\n isEU: boolean;\n};\n"]}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RiskClient = void 0;
7
+ var common_1 = require("@reyaxyz/common");
8
+ var geofencing_1 = __importDefault(require("./modules/geofencing"));
9
+ /**
10
+ * @description Client for Risk
11
+ */
12
+ var RiskClient = /** @class */ (function () {
13
+ function RiskClient() {
14
+ this._geofencingClient = new geofencing_1.default(RiskClient.ipInfoApiKey, RiskClient.config.apiEndpoint);
15
+ }
16
+ RiskClient.configure = function (environment, ipInfoApiKey) {
17
+ RiskClient.config =
18
+ common_1.API_CLIENT_CONFIGS[environment] || common_1.API_CLIENT_CONFIGS['test'];
19
+ RiskClient.ipInfoApiKey = ipInfoApiKey;
20
+ RiskClient.instance = new RiskClient();
21
+ };
22
+ RiskClient.getInstance = function () {
23
+ if (!RiskClient.instance) {
24
+ throw new Error('RiskClient is not configured. Please configure it before using.');
25
+ }
26
+ return RiskClient.instance;
27
+ };
28
+ Object.defineProperty(RiskClient, "network", {
29
+ get: function () {
30
+ if (!RiskClient.config.chain) {
31
+ throw new Error('RiskClient is not configured');
32
+ }
33
+ return RiskClient.config.chain;
34
+ },
35
+ enumerable: false,
36
+ configurable: true
37
+ });
38
+ Object.defineProperty(RiskClient, "geofencing", {
39
+ /**
40
+ * Provides access to the GeofencingClient instance.
41
+ * This getter allows for interacting with GeofencingClient related API functionalities.
42
+ *
43
+ * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.
44
+ * @memberof RiskClient
45
+ */
46
+ get: function () {
47
+ return RiskClient.getInstance()._geofencingClient;
48
+ },
49
+ enumerable: false,
50
+ configurable: true
51
+ });
52
+ RiskClient.config = common_1.API_CLIENT_CONFIGS['test'];
53
+ return RiskClient;
54
+ }());
55
+ exports.RiskClient = RiskClient;
56
+ //# sourceMappingURL=risk-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-client.js","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":";;;;;;AAAA,0CAIyB;AACzB,oEAAoD;AACpD;;GAEG;AACH;IAME;QACE,IAAI,CAAC,iBAAiB,GAAG,IAAI,oBAAgB,CAC3C,UAAU,CAAC,YAAY,EACvB,UAAU,CAAC,MAAM,CAAC,WAAW,CAC9B,CAAC;IACJ,CAAC;IAEa,oBAAS,GAAvB,UACE,WAAyC,EACzC,YAAoB;QAEpB,UAAU,CAAC,MAAM;YACf,2BAAkB,CAAC,WAAW,CAAC,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;QAChE,UAAU,CAAC,YAAY,GAAG,YAAY,CAAC;QACvC,UAAU,CAAC,QAAQ,GAAG,IAAI,UAAU,EAAE,CAAC;IACzC,CAAC;IAEc,sBAAW,GAA1B;QACE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CACb,iEAAiE,CAClE,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,sBAAkB,qBAAO;aAAzB;YACE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YACD,OAAO,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,CAAC;;;OAAA;IASD,sBAAkB,wBAAU;QAP5B;;;;;;WAMG;aACH;YACE,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC,iBAAiB,CAAC;QACpD,CAAC;;;OAAA;IA9Cc,iBAAM,GAAkB,2BAAkB,CAAC,MAAM,CAAC,CAAC;IA+CpE,iBAAC;CAAA,AAjDD,IAiDC;AAjDY,gCAAU","sourcesContent":["import {\n ReyaChainId,\n API_CLIENT_CONFIGS,\n ServiceConfig,\n} from '@reyaxyz/common';\nimport GeofencingClient from './modules/geofencing';\n/**\n * @description Client for Risk\n */\nexport class RiskClient {\n private static instance: RiskClient;\n private static config: ServiceConfig = API_CLIENT_CONFIGS['test'];\n private static ipInfoApiKey: string;\n private readonly _geofencingClient: GeofencingClient;\n\n private constructor() {\n this._geofencingClient = new GeofencingClient(\n RiskClient.ipInfoApiKey,\n RiskClient.config.apiEndpoint,\n );\n }\n\n public static configure(\n environment: ServiceConfig['environment'],\n ipInfoApiKey: string,\n ): void {\n RiskClient.config =\n API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];\n RiskClient.ipInfoApiKey = ipInfoApiKey;\n RiskClient.instance = new RiskClient();\n }\n\n private static getInstance(): RiskClient {\n if (!RiskClient.instance) {\n throw new Error(\n 'RiskClient is not configured. Please configure it before using.',\n );\n }\n return RiskClient.instance;\n }\n\n public static get network(): ReyaChainId {\n if (!RiskClient.config.chain) {\n throw new Error('RiskClient is not configured');\n }\n return RiskClient.config.chain;\n }\n\n /**\n * Provides access to the GeofencingClient instance.\n * This getter allows for interacting with GeofencingClient related API functionalities.\n *\n * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.\n * @memberof RiskClient\n */\n public static get geofencing(): GeofencingClient {\n return RiskClient.getInstance()._geofencingClient;\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./modules/geofencing/types"), exports);
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C","sourcesContent":["export * from './modules/geofencing/types';\n"]}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RiskClient = void 0;
18
+ var risk_client_1 = require("./clients/risk-client");
19
+ Object.defineProperty(exports, "RiskClient", { enumerable: true, get: function () { return risk_client_1.RiskClient; } });
20
+ __exportStar(require("./clients/types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAmD;AAA1C,yGAAA,UAAU,OAAA;AACnB,kDAAgC","sourcesContent":["export { RiskClient } from './clients/risk-client';\nexport * from './clients/types';\n"]}
@@ -0,0 +1,9 @@
1
+ import { RestClient } from '@reyaxyz/common';
2
+ import { CheckIPAddressParams, CheckIPAddressResult } from './types';
3
+ export default class GeofencingClient extends RestClient {
4
+ readonly ipInfoApiKey: string;
5
+ private cache;
6
+ constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null);
7
+ checkIPAddress(params: CheckIPAddressParams): Promise<CheckIPAddressResult>;
8
+ }
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/geofencing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAU,MAAM,SAAS,CAAC;AAQ7E,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU;IACtD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,OAAO,CAAC,KAAK,CAAmB;gBAEpB,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAKpE,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;CAsBjC"}
@@ -0,0 +1,41 @@
1
+ export type CheckIPAddressParams = {
2
+ ipAddress: string;
3
+ };
4
+ export type CheckIPAddressResult = {
5
+ isVpn: boolean;
6
+ };
7
+ export type IpInfo = {
8
+ ip: string;
9
+ hostname: string;
10
+ city: string;
11
+ region: string;
12
+ country: string;
13
+ loc: string;
14
+ org: string;
15
+ postal: string;
16
+ timezone: string;
17
+ privacy: {
18
+ vpn: boolean;
19
+ proxy: boolean;
20
+ tor: boolean;
21
+ relay: boolean;
22
+ hosting: boolean;
23
+ service: string;
24
+ };
25
+ countryCode: string;
26
+ countryFlag: {
27
+ emoji: string;
28
+ unicode: string;
29
+ };
30
+ countryFlagURL: string;
31
+ countryCurrency: {
32
+ code: string;
33
+ symbol: string;
34
+ };
35
+ continent: {
36
+ code: string;
37
+ name: string;
38
+ };
39
+ isEU: boolean;
40
+ };
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/geofencing/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,GAAG,EAAE,OAAO,CAAC;QACb,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,EAAE,OAAO,CAAC;QACb,KAAK,EAAE,OAAO,CAAC;QACf,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,SAAS,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE,OAAO,CAAC;CACf,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { ReyaChainId, ServiceConfig } from '@reyaxyz/common';
2
+ import GeofencingClient from './modules/geofencing';
3
+ /**
4
+ * @description Client for Risk
5
+ */
6
+ export declare class RiskClient {
7
+ private static instance;
8
+ private static config;
9
+ private static ipInfoApiKey;
10
+ private readonly _geofencingClient;
11
+ private constructor();
12
+ static configure(environment: ServiceConfig['environment'], ipInfoApiKey: string): void;
13
+ private static getInstance;
14
+ static get network(): ReyaChainId;
15
+ /**
16
+ * Provides access to the GeofencingClient instance.
17
+ * This getter allows for interacting with GeofencingClient related API functionalities.
18
+ *
19
+ * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.
20
+ * @memberof RiskClient
21
+ */
22
+ static get geofencing(): GeofencingClient;
23
+ }
24
+ //# sourceMappingURL=risk-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-client.d.ts","sourceRoot":"/","sources":["clients/risk-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AACpD;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAa;IACpC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA6C;IAClE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IAErD,OAAO;WAOO,SAAS,CACrB,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,EACzC,YAAY,EAAE,MAAM,GACnB,IAAI;IAOP,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B,WAAkB,OAAO,IAAI,WAAW,CAKvC;IAED;;;;;;OAMG;IACH,WAAkB,UAAU,IAAI,gBAAgB,CAE/C;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './modules/geofencing/types';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { RiskClient } from './clients/risk-client';
2
+ export * from './clients/types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,cAAc,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@reyaxyz/risk-sdk",
3
+ "version": "0.1.0",
4
+ "publishConfig": {
5
+ "access": "public",
6
+ "registry": "https://registry.npmjs.org"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
11
+ },
12
+ "main": "dist/index.js",
13
+ "types": "dist/types",
14
+ "license": "MIT",
15
+ "files": [
16
+ "src/**/*.*",
17
+ "dist/**/*.*",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "prebuild": "rm -rf node_modules && rm -rf dist",
22
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
23
+ "ts:check-types": "npx tsc --noEmit",
24
+ "ts:circular-check": "dpdm --no-output --no-tree --no-warning --exit-code circular:1 -T src/index.ts",
25
+ "ts:check": "pnpm ts:check-types && pnpm ts:circular-check",
26
+ "lint:check": "eslint '{src,demo,tests}/**/*.{ts,tsx}'",
27
+ "prettier:check": "npx prettier --log-level silent --check './{src,demo,tests}/**/*.{ts,tsx}'",
28
+ "code-quality:check": "npx concurrently 'pnpm ts:check' 'pnpm prettier:check' 'pnpm lint:check --quiet'",
29
+ "lint:fix": "npx eslint --fix '{src,demo,tests}/**/*.{ts,tsx}'",
30
+ "prettier:fix": "npx prettier --log-level silent --write './{src,demo,tests}/**/*.{ts,tsx}'",
31
+ "test": "npx jest --silent",
32
+ "test:coverage": "npx jest test --coverage",
33
+ "generate:coverage-badges": "npx istanbul-badges-readme --silent"
34
+ },
35
+ "dependencies": {
36
+ "@reyaxyz/common": "0.60.0",
37
+ "axios": "^1.6.2"
38
+ },
39
+ "packageManager": "pnpm@8.10.4",
40
+ "gitHead": "49884d481663540cb9f3fb883164cb935e1b2bee"
41
+ }
@@ -0,0 +1,43 @@
1
+ import { RestClient } from '@reyaxyz/common';
2
+ import { CheckIPAddressParams, CheckIPAddressResult, IpInfo } from './types';
3
+ import axios from 'axios';
4
+
5
+ // Define a cache interface
6
+ interface IpInfoCache {
7
+ [key: string]: IpInfo;
8
+ }
9
+
10
+ export default class GeofencingClient extends RestClient {
11
+ readonly ipInfoApiKey: string;
12
+ private cache: IpInfoCache = {}; // Cache for storing IP info results
13
+
14
+ constructor(ipInfoApiKey: string, host: string, apiTimeout?: number | null) {
15
+ super(host, apiTimeout);
16
+ this.ipInfoApiKey = ipInfoApiKey;
17
+ }
18
+
19
+ async checkIPAddress(
20
+ params: CheckIPAddressParams,
21
+ ): Promise<CheckIPAddressResult> {
22
+ // Check if we already have the result in cache
23
+ const cachedResult = this.cache[params.ipAddress];
24
+ if (cachedResult) {
25
+ // Return the cached result if available
26
+ return {
27
+ isVpn: cachedResult.privacy.vpn,
28
+ };
29
+ }
30
+
31
+ // If the result is not in cache, make a request to ipinfo
32
+ const url = `https://ipinfo.io/${params.ipAddress}?token=${this.ipInfoApiKey}`;
33
+ const response = await axios.get<IpInfo>(url);
34
+ const ipInfo = response.data;
35
+
36
+ // Store the result in cache before returning
37
+ this.cache[params.ipAddress] = ipInfo;
38
+
39
+ return {
40
+ isVpn: ipInfo.privacy.vpn,
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,42 @@
1
+ export type CheckIPAddressParams = {
2
+ ipAddress: string;
3
+ };
4
+
5
+ export type CheckIPAddressResult = {
6
+ isVpn: boolean;
7
+ };
8
+
9
+ export type IpInfo = {
10
+ ip: string;
11
+ hostname: string;
12
+ city: string;
13
+ region: string;
14
+ country: string;
15
+ loc: string;
16
+ org: string;
17
+ postal: string;
18
+ timezone: string;
19
+ privacy: {
20
+ vpn: boolean;
21
+ proxy: boolean;
22
+ tor: boolean;
23
+ relay: boolean;
24
+ hosting: boolean;
25
+ service: string;
26
+ };
27
+ countryCode: string;
28
+ countryFlag: {
29
+ emoji: string;
30
+ unicode: string;
31
+ };
32
+ countryFlagURL: string;
33
+ countryCurrency: {
34
+ code: string;
35
+ symbol: string;
36
+ };
37
+ continent: {
38
+ code: string;
39
+ name: string;
40
+ };
41
+ isEU: boolean;
42
+ };
@@ -0,0 +1,59 @@
1
+ import {
2
+ ReyaChainId,
3
+ API_CLIENT_CONFIGS,
4
+ ServiceConfig,
5
+ } from '@reyaxyz/common';
6
+ import GeofencingClient from './modules/geofencing';
7
+ /**
8
+ * @description Client for Risk
9
+ */
10
+ export class RiskClient {
11
+ private static instance: RiskClient;
12
+ private static config: ServiceConfig = API_CLIENT_CONFIGS['test'];
13
+ private static ipInfoApiKey: string;
14
+ private readonly _geofencingClient: GeofencingClient;
15
+
16
+ private constructor() {
17
+ this._geofencingClient = new GeofencingClient(
18
+ RiskClient.ipInfoApiKey,
19
+ RiskClient.config.apiEndpoint,
20
+ );
21
+ }
22
+
23
+ public static configure(
24
+ environment: ServiceConfig['environment'],
25
+ ipInfoApiKey: string,
26
+ ): void {
27
+ RiskClient.config =
28
+ API_CLIENT_CONFIGS[environment] || API_CLIENT_CONFIGS['test'];
29
+ RiskClient.ipInfoApiKey = ipInfoApiKey;
30
+ RiskClient.instance = new RiskClient();
31
+ }
32
+
33
+ private static getInstance(): RiskClient {
34
+ if (!RiskClient.instance) {
35
+ throw new Error(
36
+ 'RiskClient is not configured. Please configure it before using.',
37
+ );
38
+ }
39
+ return RiskClient.instance;
40
+ }
41
+
42
+ public static get network(): ReyaChainId {
43
+ if (!RiskClient.config.chain) {
44
+ throw new Error('RiskClient is not configured');
45
+ }
46
+ return RiskClient.config.chain;
47
+ }
48
+
49
+ /**
50
+ * Provides access to the GeofencingClient instance.
51
+ * This getter allows for interacting with GeofencingClient related API functionalities.
52
+ *
53
+ * @returns {GeofencingClient} An instance of GeofencingClient for account-related operations.
54
+ * @memberof RiskClient
55
+ */
56
+ public static get geofencing(): GeofencingClient {
57
+ return RiskClient.getInstance()._geofencingClient;
58
+ }
59
+ }
@@ -0,0 +1 @@
1
+ export * from './modules/geofencing/types';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { RiskClient } from './clients/risk-client';
2
+ export * from './clients/types';