@reyaxyz/wallet-sdk 0.17.91 → 0.18.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/dist/clients/types.js +0 -1
- package/dist/clients/types.js.map +1 -1
- package/dist/clients/wallet-client.js +0 -16
- package/dist/clients/wallet-client.js.map +1 -1
- package/dist/types/clients/types.d.ts +0 -1
- package/dist/types/clients/types.d.ts.map +1 -1
- package/dist/types/clients/wallet-client.d.ts +0 -10
- package/dist/types/clients/wallet-client.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/types.ts +0 -1
- package/src/clients/wallet-client.ts +0 -17
- package/dist/clients/modules/tos/index.js +0 -218
- package/dist/clients/modules/tos/index.js.map +0 -1
- package/dist/clients/modules/tos/types.js +0 -3
- package/dist/clients/modules/tos/types.js.map +0 -1
- package/dist/types/clients/modules/tos/index.d.ts +0 -13
- package/dist/types/clients/modules/tos/index.d.ts.map +0 -1
- package/dist/types/clients/modules/tos/types.d.ts +0 -17
- package/dist/types/clients/modules/tos/types.d.ts.map +0 -1
- package/src/clients/modules/tos/index.ts +0 -137
- package/src/clients/modules/tos/types.ts +0 -20
package/dist/clients/types.js
CHANGED
|
@@ -15,6 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./modules/risk/types"), exports);
|
|
18
|
-
__exportStar(require("./modules/tos/types"), exports);
|
|
19
18
|
__exportStar(require("./modules/tos-app/types"), exports);
|
|
20
19
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,0DAAwC","sourcesContent":["export * from './modules/risk/types';\nexport * from './modules/tos-app/types';\n"]}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.WalletClient = void 0;
|
|
7
7
|
var common_1 = require("@reyaxyz/common");
|
|
8
8
|
var risk_1 = __importDefault(require("./modules/risk"));
|
|
9
|
-
var tos_1 = __importDefault(require("./modules/tos"));
|
|
10
9
|
var tos_app_1 = __importDefault(require("./modules/tos-app"));
|
|
11
10
|
/**
|
|
12
11
|
* @description Client for Wallet
|
|
@@ -14,7 +13,6 @@ var tos_app_1 = __importDefault(require("./modules/tos-app"));
|
|
|
14
13
|
var WalletClient = /** @class */ (function () {
|
|
15
14
|
function WalletClient() {
|
|
16
15
|
this._riskClient = new risk_1.default(WalletClient.config.apiEndpoint, WalletClient.config.logging);
|
|
17
|
-
this._tosSignatureClient = new tos_1.default(WalletClient.config.apiEndpoint, WalletClient.config.logging);
|
|
18
16
|
this._tosSignatureAppClient = new tos_app_1.default(WalletClient.config.apiEndpoint, WalletClient.config.logging);
|
|
19
17
|
}
|
|
20
18
|
WalletClient.configure = function (environment) {
|
|
@@ -51,20 +49,6 @@ var WalletClient = /** @class */ (function () {
|
|
|
51
49
|
enumerable: false,
|
|
52
50
|
configurable: true
|
|
53
51
|
});
|
|
54
|
-
Object.defineProperty(WalletClient, "tosSignature", {
|
|
55
|
-
/**
|
|
56
|
-
* Provides access to the ToSSignatureClient instance for LGE.
|
|
57
|
-
* This getter allows for interacting with tos signature related API functionalities.
|
|
58
|
-
*
|
|
59
|
-
* @returns {ToSSignatureClient} An instance of ToSSignatureClient for account-related operations.
|
|
60
|
-
* @memberof WalletClient
|
|
61
|
-
*/
|
|
62
|
-
get: function () {
|
|
63
|
-
return WalletClient.getInstance()._tosSignatureClient;
|
|
64
|
-
},
|
|
65
|
-
enumerable: false,
|
|
66
|
-
configurable: true
|
|
67
|
-
});
|
|
68
52
|
Object.defineProperty(WalletClient, "tosSignatureApp", {
|
|
69
53
|
/**
|
|
70
54
|
* Provides general access to the ToSSignatureAppClient instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-client.js","sourceRoot":"/","sources":["clients/wallet-client.ts"],"names":[],"mappings":";;;;;;AAAA,0CAIyB;AACzB,wDAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"wallet-client.js","sourceRoot":"/","sources":["clients/wallet-client.ts"],"names":[],"mappings":";;;;;;AAAA,0CAIyB;AACzB,wDAAwC;AACxC,8DAAsD;AACtD;;GAEG;AACH;IAME;QACE,IAAI,CAAC,WAAW,GAAG,IAAI,cAAU,CAC/B,YAAY,CAAC,MAAM,CAAC,WAAW,EAC/B,YAAY,CAAC,MAAM,CAAC,OAAO,CAC5B,CAAC;QACF,IAAI,CAAC,sBAAsB,GAAG,IAAI,iBAAqB,CACrD,YAAY,CAAC,MAAM,CAAC,WAAW,EAC/B,YAAY,CAAC,MAAM,CAAC,OAAO,CAC5B,CAAC;IACJ,CAAC;IAEa,sBAAS,GAAvB,UAAwB,WAAyC;QAC/D,YAAY,CAAC,MAAM,GAAG,IAAA,2BAAkB,EAAC,WAAW,CAAC,CAAC;QACtD,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IAC7C,CAAC;IAEc,wBAAW,GAA1B;QACE,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;QACJ,CAAC;QACD,OAAO,YAAY,CAAC,QAAQ,CAAC;IAC/B,CAAC;IAED,sBAAkB,uBAAO;aAAzB;YACE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;YACpD,CAAC;YACD,OAAO,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,CAAC;;;OAAA;IASD,sBAAkB,oBAAI;QAPtB;;;;;;WAMG;aACH;YACE,OAAO,YAAY,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC;QAChD,CAAC;;;OAAA;IASD,sBAAkB,+BAAe;QAPjC;;;;;;WAMG;aACH;YACE,OAAO,YAAY,CAAC,WAAW,EAAE,CAAC,sBAAsB,CAAC;QAC3D,CAAC;;;OAAA;IAxDc,mBAAM,GAAkB,IAAA,2BAAkB,EAAC,MAAM,CAAC,CAAC;IAyDpE,mBAAC;CAAA,AA3DD,IA2DC;AA3DY,oCAAY","sourcesContent":["import {\n getApiClientConfig,\n ReyaChainId,\n ServiceConfig,\n} from '@reyaxyz/common';\nimport RiskClient from './modules/risk';\nimport ToSSignatureAppClient from './modules/tos-app';\n/**\n * @description Client for Wallet\n */\nexport class WalletClient {\n private static instance: WalletClient;\n private static config: ServiceConfig = getApiClientConfig('test');\n private readonly _riskClient: RiskClient;\n private readonly _tosSignatureAppClient: ToSSignatureAppClient;\n\n private constructor() {\n this._riskClient = new RiskClient(\n WalletClient.config.apiEndpoint,\n WalletClient.config.logging,\n );\n this._tosSignatureAppClient = new ToSSignatureAppClient(\n WalletClient.config.apiEndpoint,\n WalletClient.config.logging,\n );\n }\n\n public static configure(environment: ServiceConfig['environment']): void {\n WalletClient.config = getApiClientConfig(environment);\n WalletClient.instance = new WalletClient();\n }\n\n private static getInstance(): WalletClient {\n if (!WalletClient.instance) {\n throw new Error(\n 'WalletClient is not configured. Please configure it before using.',\n );\n }\n return WalletClient.instance;\n }\n\n public static get network(): ReyaChainId {\n if (!WalletClient.config.chain) {\n throw new Error('WalletClient is not configured');\n }\n return WalletClient.config.chain;\n }\n\n /**\n * Provides access to the RiskClient instance.\n * This getter allows for interacting with risk-related API functionalities.\n *\n * @returns {RiskClient} An instance of RiskClient for risk-related operations.\n * @memberof WalletClient\n */\n public static get risk(): RiskClient {\n return WalletClient.getInstance()._riskClient;\n }\n\n /**\n * Provides general access to the ToSSignatureAppClient instance.\n * This getter allows for interacting with tos signature related API functionalities.\n *\n * @returns {ToSSignatureClient} An instance of ToSSignatureClient for account-related operations.\n * @memberof WalletClient\n */\n public static get tosSignatureApp(): ToSSignatureAppClient {\n return WalletClient.getInstance()._tosSignatureAppClient;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/types.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ReyaChainId, ServiceConfig } from '@reyaxyz/common';
|
|
2
2
|
import RiskClient from './modules/risk';
|
|
3
|
-
import ToSSignatureClient from './modules/tos';
|
|
4
3
|
import ToSSignatureAppClient from './modules/tos-app';
|
|
5
4
|
/**
|
|
6
5
|
* @description Client for Wallet
|
|
@@ -9,7 +8,6 @@ export declare class WalletClient {
|
|
|
9
8
|
private static instance;
|
|
10
9
|
private static config;
|
|
11
10
|
private readonly _riskClient;
|
|
12
|
-
private readonly _tosSignatureClient;
|
|
13
11
|
private readonly _tosSignatureAppClient;
|
|
14
12
|
private constructor();
|
|
15
13
|
static configure(environment: ServiceConfig['environment']): void;
|
|
@@ -23,14 +21,6 @@ export declare class WalletClient {
|
|
|
23
21
|
* @memberof WalletClient
|
|
24
22
|
*/
|
|
25
23
|
static get risk(): RiskClient;
|
|
26
|
-
/**
|
|
27
|
-
* Provides access to the ToSSignatureClient instance for LGE.
|
|
28
|
-
* This getter allows for interacting with tos signature related API functionalities.
|
|
29
|
-
*
|
|
30
|
-
* @returns {ToSSignatureClient} An instance of ToSSignatureClient for account-related operations.
|
|
31
|
-
* @memberof WalletClient
|
|
32
|
-
*/
|
|
33
|
-
static get tosSignature(): ToSSignatureClient;
|
|
34
24
|
/**
|
|
35
25
|
* Provides general access to the ToSSignatureAppClient instance.
|
|
36
26
|
* This getter allows for interacting with tos signature related API functionalities.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-client.d.ts","sourceRoot":"/","sources":["clients/wallet-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"wallet-client.d.ts","sourceRoot":"/","sources":["clients/wallet-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,aAAa,EACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,qBAAqB,MAAM,mBAAmB,CAAC;AACtD;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA6C;IAClE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAwB;IAE/D,OAAO;WAWO,SAAS,CAAC,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,IAAI;IAKxE,OAAO,CAAC,MAAM,CAAC,WAAW;IAS1B,WAAkB,OAAO,IAAI,WAAW,CAKvC;IAED;;;;;;OAMG;IACH,WAAkB,IAAI,IAAI,UAAU,CAEnC;IAED;;;;;;OAMG;IACH,WAAkB,eAAe,IAAI,qBAAqB,CAEzD;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/wallet-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"ethers": "6.9.0"
|
|
40
40
|
},
|
|
41
41
|
"packageManager": "pnpm@8.3.1",
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "48c795585a82a1388f2868b80dee23151dd428de"
|
|
43
43
|
}
|
package/src/clients/types.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
ServiceConfig,
|
|
5
5
|
} from '@reyaxyz/common';
|
|
6
6
|
import RiskClient from './modules/risk';
|
|
7
|
-
import ToSSignatureClient from './modules/tos';
|
|
8
7
|
import ToSSignatureAppClient from './modules/tos-app';
|
|
9
8
|
/**
|
|
10
9
|
* @description Client for Wallet
|
|
@@ -13,7 +12,6 @@ export class WalletClient {
|
|
|
13
12
|
private static instance: WalletClient;
|
|
14
13
|
private static config: ServiceConfig = getApiClientConfig('test');
|
|
15
14
|
private readonly _riskClient: RiskClient;
|
|
16
|
-
private readonly _tosSignatureClient: ToSSignatureClient;
|
|
17
15
|
private readonly _tosSignatureAppClient: ToSSignatureAppClient;
|
|
18
16
|
|
|
19
17
|
private constructor() {
|
|
@@ -21,10 +19,6 @@ export class WalletClient {
|
|
|
21
19
|
WalletClient.config.apiEndpoint,
|
|
22
20
|
WalletClient.config.logging,
|
|
23
21
|
);
|
|
24
|
-
this._tosSignatureClient = new ToSSignatureClient(
|
|
25
|
-
WalletClient.config.apiEndpoint,
|
|
26
|
-
WalletClient.config.logging,
|
|
27
|
-
);
|
|
28
22
|
this._tosSignatureAppClient = new ToSSignatureAppClient(
|
|
29
23
|
WalletClient.config.apiEndpoint,
|
|
30
24
|
WalletClient.config.logging,
|
|
@@ -63,17 +57,6 @@ export class WalletClient {
|
|
|
63
57
|
return WalletClient.getInstance()._riskClient;
|
|
64
58
|
}
|
|
65
59
|
|
|
66
|
-
/**
|
|
67
|
-
* Provides access to the ToSSignatureClient instance for LGE.
|
|
68
|
-
* This getter allows for interacting with tos signature related API functionalities.
|
|
69
|
-
*
|
|
70
|
-
* @returns {ToSSignatureClient} An instance of ToSSignatureClient for account-related operations.
|
|
71
|
-
* @memberof WalletClient
|
|
72
|
-
*/
|
|
73
|
-
public static get tosSignature(): ToSSignatureClient {
|
|
74
|
-
return WalletClient.getInstance()._tosSignatureClient;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
60
|
/**
|
|
78
61
|
* Provides general access to the ToSSignatureAppClient instance.
|
|
79
62
|
* This getter allows for interacting with tos signature related API functionalities.
|
|
@@ -1,218 +0,0 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
24
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
33
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
34
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
35
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
36
|
-
function step(op) {
|
|
37
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
38
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
39
|
-
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;
|
|
40
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
41
|
-
switch (op[0]) {
|
|
42
|
-
case 0: case 1: t = op; break;
|
|
43
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
44
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
45
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
46
|
-
default:
|
|
47
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
48
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
49
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
50
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
51
|
-
if (t[2]) _.ops.pop();
|
|
52
|
-
_.trys.pop(); continue;
|
|
53
|
-
}
|
|
54
|
-
op = body.call(thisArg, _);
|
|
55
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
56
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
var common_1 = require("@reyaxyz/common");
|
|
61
|
-
var constants_1 = require("../../helpers/constants");
|
|
62
|
-
var ToSSignatureClient = /** @class */ (function (_super) {
|
|
63
|
-
__extends(ToSSignatureClient, _super);
|
|
64
|
-
function ToSSignatureClient(apiUrl, loggingEnabled) {
|
|
65
|
-
var _this = _super.call(this, apiUrl) || this;
|
|
66
|
-
_this.loggingEnabled = false;
|
|
67
|
-
_this.loggingEnabled = loggingEnabled;
|
|
68
|
-
return _this;
|
|
69
|
-
}
|
|
70
|
-
ToSSignatureClient.prototype.getSignature = function (walletAddress) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var uri;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
uri = "/api/owner/".concat(walletAddress, "/tos/get-signature");
|
|
77
|
-
return [4 /*yield*/, this.get(uri)];
|
|
78
|
-
case 1:
|
|
79
|
-
// todo: make sure get api returns undefined if not found
|
|
80
|
-
return [2 /*return*/, _a.sent()];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
ToSSignatureClient.prototype.getLatestToSVersion = function () {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
var uri;
|
|
88
|
-
return __generator(this, function (_a) {
|
|
89
|
-
switch (_a.label) {
|
|
90
|
-
case 0:
|
|
91
|
-
uri = "/api/tos/latest-version";
|
|
92
|
-
return [4 /*yield*/, this.get(uri)];
|
|
93
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
ToSSignatureClient.prototype.saveSignatureWithToS = function (walletAddress, signature, termsOfService, version, referredByCode) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
-
var formData, uri;
|
|
101
|
-
return __generator(this, function (_a) {
|
|
102
|
-
formData = new FormData();
|
|
103
|
-
formData.append('signature', signature);
|
|
104
|
-
formData.append('walletAddress', walletAddress);
|
|
105
|
-
formData.append('message', termsOfService);
|
|
106
|
-
formData.append('version', version);
|
|
107
|
-
if (referredByCode) {
|
|
108
|
-
formData.append('referredByCode', referredByCode);
|
|
109
|
-
}
|
|
110
|
-
uri = '/api/owner/tos/add-signature';
|
|
111
|
-
return [2 /*return*/, this.post(uri, undefined, formData, undefined)];
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
ToSSignatureClient.prototype.getLatestTacService = function () {
|
|
116
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
117
|
-
var tosDetails;
|
|
118
|
-
return __generator(this, function (_a) {
|
|
119
|
-
switch (_a.label) {
|
|
120
|
-
case 0: return [4 /*yield*/, this.getLatestToSVersion()];
|
|
121
|
-
case 1:
|
|
122
|
-
tosDetails = _a.sent();
|
|
123
|
-
return [2 /*return*/, {
|
|
124
|
-
version: tosDetails.version,
|
|
125
|
-
text: constants_1.TAC_TEXT,
|
|
126
|
-
}];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
ToSSignatureClient.prototype.getWalletLatestTacStatus = function (params) {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var signerAddress, signatureData, latestToS, termsAccepted;
|
|
134
|
-
return __generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0:
|
|
137
|
-
signerAddress = params.address.toLowerCase();
|
|
138
|
-
return [4 /*yield*/, this.getSignature(signerAddress)];
|
|
139
|
-
case 1:
|
|
140
|
-
signatureData = _a.sent();
|
|
141
|
-
return [4 /*yield*/, this.getLatestToSVersion()];
|
|
142
|
-
case 2:
|
|
143
|
-
latestToS = _a.sent();
|
|
144
|
-
termsAccepted = false;
|
|
145
|
-
if (signatureData &&
|
|
146
|
-
signatureData.walletAddress.toLowerCase() ===
|
|
147
|
-
signerAddress.toLowerCase() &&
|
|
148
|
-
signatureData.version === latestToS.version) {
|
|
149
|
-
// Wallet matches, and signed data also matches
|
|
150
|
-
// (signature was checked before being written to database)
|
|
151
|
-
termsAccepted = true;
|
|
152
|
-
} // todo: do we want eip1271?
|
|
153
|
-
return [2 /*return*/, { signed: termsAccepted }];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
ToSSignatureClient.prototype.signTac = function (params) {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var latestToS, error_1, signerAddress, modifiedText, signature, error_2, response, error_3;
|
|
161
|
-
return __generator(this, function (_a) {
|
|
162
|
-
switch (_a.label) {
|
|
163
|
-
case 0:
|
|
164
|
-
_a.trys.push([0, 2, , 3]);
|
|
165
|
-
return [4 /*yield*/, this.getLatestToSVersion()];
|
|
166
|
-
case 1:
|
|
167
|
-
latestToS = _a.sent();
|
|
168
|
-
return [3 /*break*/, 3];
|
|
169
|
-
case 2:
|
|
170
|
-
error_1 = _a.sent();
|
|
171
|
-
throw new Error('Error getting latest T&C version');
|
|
172
|
-
case 3: return [4 /*yield*/, params.signer.getAddress()];
|
|
173
|
-
case 4:
|
|
174
|
-
signerAddress = (_a.sent()).toLowerCase();
|
|
175
|
-
_a.label = 5;
|
|
176
|
-
case 5:
|
|
177
|
-
_a.trys.push([5, 7, , 8]);
|
|
178
|
-
// minimise special characters as they tend to change when signed
|
|
179
|
-
modifiedText = latestToS.text.replace(/\t/g, ''); // Remove tabs
|
|
180
|
-
modifiedText = modifiedText.replace(/\n\n/g, '\n'); // Replace double newline with single newline
|
|
181
|
-
return [4 /*yield*/, params.signer.signMessage(modifiedText)];
|
|
182
|
-
case 6:
|
|
183
|
-
signature = _a.sent();
|
|
184
|
-
return [3 /*break*/, 8];
|
|
185
|
-
case 7:
|
|
186
|
-
error_2 = _a.sent();
|
|
187
|
-
throw new Error('Error signing message');
|
|
188
|
-
case 8:
|
|
189
|
-
_a.trys.push([8, 10, , 11]);
|
|
190
|
-
return [4 /*yield*/, this.saveSignatureWithToS(signerAddress, signature, modifiedText, latestToS.version, params.referredByCode)];
|
|
191
|
-
case 9:
|
|
192
|
-
response = _a.sent();
|
|
193
|
-
return [3 /*break*/, 11];
|
|
194
|
-
case 10:
|
|
195
|
-
error_3 = _a.sent();
|
|
196
|
-
throw new Error('Error in saving signature endpoint');
|
|
197
|
-
case 11:
|
|
198
|
-
if (!response.signatureSavedSuccessfully) {
|
|
199
|
-
throw new Error('Error saving signature');
|
|
200
|
-
}
|
|
201
|
-
return [2 /*return*/];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
__decorate([
|
|
207
|
-
(0, common_1.Logger)('ToSSignatureClient.getLatestTacService')
|
|
208
|
-
], ToSSignatureClient.prototype, "getLatestTacService", null);
|
|
209
|
-
__decorate([
|
|
210
|
-
(0, common_1.Logger)('ToSSignatureClient.getWalletLatestTacStatus')
|
|
211
|
-
], ToSSignatureClient.prototype, "getWalletLatestTacStatus", null);
|
|
212
|
-
__decorate([
|
|
213
|
-
(0, common_1.Logger)('ToSSignatureClient.signTac')
|
|
214
|
-
], ToSSignatureClient.prototype, "signTac", null);
|
|
215
|
-
return ToSSignatureClient;
|
|
216
|
-
}(common_1.RestClient));
|
|
217
|
-
exports.default = ToSSignatureClient;
|
|
218
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/tos/index.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n Address,\n RestClient,\n SignatureData,\n SaveSignatureResult,\n ToSVersionDetails,\n Loggable,\n Logger,\n} from '@reyaxyz/common';\nimport { TAC_TEXT } from '../../helpers/constants';\n\nimport {\n GetLatestTacResult,\n GetWalletLatestTacStatusParams,\n GetWalletLatestTacStatusResult,\n SignTacParams,\n} from './types';\n\nexport default class ToSSignatureClient extends RestClient implements Loggable {\n loggingEnabled: boolean = false;\n\n constructor(apiUrl: string, loggingEnabled: boolean) {\n super(apiUrl);\n this.loggingEnabled = loggingEnabled;\n }\n\n private async getSignature(\n walletAddress: Address,\n ): Promise<SignatureData | undefined> {\n const uri = `/api/owner/${walletAddress}/tos/get-signature`;\n // todo: make sure get api returns undefined if not found\n return await this.get(uri);\n }\n\n private async getLatestToSVersion(): Promise<ToSVersionDetails> {\n const uri = `/api/tos/latest-version`;\n return await this.get(uri);\n }\n\n private async saveSignatureWithToS(\n walletAddress: Address,\n signature: string,\n termsOfService: string,\n version: string,\n referredByCode: string | undefined,\n ): Promise<SaveSignatureResult> {\n // Build formData object.\n const formData = new FormData();\n formData.append('signature', signature);\n formData.append('walletAddress', walletAddress);\n formData.append('message', termsOfService);\n formData.append('version', version);\n\n if (referredByCode) {\n formData.append('referredByCode', referredByCode);\n }\n\n const uri = '/api/owner/tos/add-signature';\n return this.post(uri, undefined, formData, undefined);\n }\n\n @Logger('ToSSignatureClient.getLatestTacService')\n async getLatestTacService(): Promise<GetLatestTacResult> {\n const tosDetails = await this.getLatestToSVersion();\n return {\n version: tosDetails.version,\n text: TAC_TEXT,\n };\n }\n\n @Logger('ToSSignatureClient.getWalletLatestTacStatus')\n async getWalletLatestTacStatus(\n params: GetWalletLatestTacStatusParams,\n ): Promise<GetWalletLatestTacStatusResult> {\n const signerAddress = params.address.toLowerCase() as Address;\n\n const signatureData = await this.getSignature(signerAddress);\n\n const latestToS = await this.getLatestToSVersion();\n let termsAccepted = false;\n\n if (\n signatureData &&\n signatureData.walletAddress.toLowerCase() ===\n signerAddress.toLowerCase() &&\n signatureData.version === latestToS.version\n ) {\n // Wallet matches, and signed data also matches\n // (signature was checked before being written to database)\n termsAccepted = true;\n } // todo: do we want eip1271?\n\n return { signed: termsAccepted };\n }\n\n @Logger('ToSSignatureClient.signTac')\n async signTac(params: SignTacParams): Promise<void> {\n let latestToS;\n try {\n latestToS = await this.getLatestToSVersion();\n } catch (error) {\n throw new Error('Error getting latest T&C version');\n }\n\n const signerAddress = (\n await params.signer.getAddress()\n ).toLowerCase() as Address;\n\n let modifiedText;\n let signature;\n try {\n // minimise special characters as they tend to change when signed\n modifiedText = latestToS.text.replace(/\\t/g, ''); // Remove tabs\n modifiedText = modifiedText.replace(/\\n\\n/g, '\\n'); // Replace double newline with single newline\n signature = await params.signer.signMessage(modifiedText);\n } catch (error) {\n throw new Error('Error signing message');\n }\n\n let response;\n try {\n response = await this.saveSignatureWithToS(\n signerAddress,\n signature,\n modifiedText,\n latestToS.version,\n params.referredByCode,\n );\n } catch (error) {\n throw new Error('Error in saving signature endpoint');\n }\n\n if (!response.signatureSavedSuccessfully) {\n throw new Error('Error saving signature');\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/tos/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport type GetLatestTacResult = {\n version: string;\n text: string;\n};\n\nexport type GetWalletLatestTacStatusResult = {\n signed: boolean;\n};\n\nexport type GetWalletLatestTacStatusParams = {\n address: string;\n};\n\nexport type SignTacParams = {\n signer: Signer | JsonRpcSigner;\n version: string;\n referredByCode?: string;\n};\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { RestClient, Loggable } from '@reyaxyz/common';
|
|
2
|
-
import { GetLatestTacResult, GetWalletLatestTacStatusParams, GetWalletLatestTacStatusResult, SignTacParams } from './types';
|
|
3
|
-
export default class ToSSignatureClient extends RestClient implements Loggable {
|
|
4
|
-
loggingEnabled: boolean;
|
|
5
|
-
constructor(apiUrl: string, loggingEnabled: boolean);
|
|
6
|
-
private getSignature;
|
|
7
|
-
private getLatestToSVersion;
|
|
8
|
-
private saveSignatureWithToS;
|
|
9
|
-
getLatestTacService(): Promise<GetLatestTacResult>;
|
|
10
|
-
getWalletLatestTacStatus(params: GetWalletLatestTacStatusParams): Promise<GetWalletLatestTacStatusResult>;
|
|
11
|
-
signTac(params: SignTacParams): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/tos/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAIV,QAAQ,EAET,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,kBAAkB,EAClB,8BAA8B,EAC9B,8BAA8B,EAC9B,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAW,YAAW,QAAQ;IAC5E,cAAc,EAAE,OAAO,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO;YAKrC,YAAY;YAQZ,mBAAmB;YAKnB,oBAAoB;IAuB5B,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IASlD,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,8BAA8B,CAAC;IAuBpC,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAwCpD"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
export type GetLatestTacResult = {
|
|
3
|
-
version: string;
|
|
4
|
-
text: string;
|
|
5
|
-
};
|
|
6
|
-
export type GetWalletLatestTacStatusResult = {
|
|
7
|
-
signed: boolean;
|
|
8
|
-
};
|
|
9
|
-
export type GetWalletLatestTacStatusParams = {
|
|
10
|
-
address: string;
|
|
11
|
-
};
|
|
12
|
-
export type SignTacParams = {
|
|
13
|
-
signer: Signer | JsonRpcSigner;
|
|
14
|
-
version: string;
|
|
15
|
-
referredByCode?: string;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/tos/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address,
|
|
3
|
-
RestClient,
|
|
4
|
-
SignatureData,
|
|
5
|
-
SaveSignatureResult,
|
|
6
|
-
ToSVersionDetails,
|
|
7
|
-
Loggable,
|
|
8
|
-
Logger,
|
|
9
|
-
} from '@reyaxyz/common';
|
|
10
|
-
import { TAC_TEXT } from '../../helpers/constants';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
GetLatestTacResult,
|
|
14
|
-
GetWalletLatestTacStatusParams,
|
|
15
|
-
GetWalletLatestTacStatusResult,
|
|
16
|
-
SignTacParams,
|
|
17
|
-
} from './types';
|
|
18
|
-
|
|
19
|
-
export default class ToSSignatureClient extends RestClient implements Loggable {
|
|
20
|
-
loggingEnabled: boolean = false;
|
|
21
|
-
|
|
22
|
-
constructor(apiUrl: string, loggingEnabled: boolean) {
|
|
23
|
-
super(apiUrl);
|
|
24
|
-
this.loggingEnabled = loggingEnabled;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
private async getSignature(
|
|
28
|
-
walletAddress: Address,
|
|
29
|
-
): Promise<SignatureData | undefined> {
|
|
30
|
-
const uri = `/api/owner/${walletAddress}/tos/get-signature`;
|
|
31
|
-
// todo: make sure get api returns undefined if not found
|
|
32
|
-
return await this.get(uri);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private async getLatestToSVersion(): Promise<ToSVersionDetails> {
|
|
36
|
-
const uri = `/api/tos/latest-version`;
|
|
37
|
-
return await this.get(uri);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private async saveSignatureWithToS(
|
|
41
|
-
walletAddress: Address,
|
|
42
|
-
signature: string,
|
|
43
|
-
termsOfService: string,
|
|
44
|
-
version: string,
|
|
45
|
-
referredByCode: string | undefined,
|
|
46
|
-
): Promise<SaveSignatureResult> {
|
|
47
|
-
// Build formData object.
|
|
48
|
-
const formData = new FormData();
|
|
49
|
-
formData.append('signature', signature);
|
|
50
|
-
formData.append('walletAddress', walletAddress);
|
|
51
|
-
formData.append('message', termsOfService);
|
|
52
|
-
formData.append('version', version);
|
|
53
|
-
|
|
54
|
-
if (referredByCode) {
|
|
55
|
-
formData.append('referredByCode', referredByCode);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const uri = '/api/owner/tos/add-signature';
|
|
59
|
-
return this.post(uri, undefined, formData, undefined);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@Logger('ToSSignatureClient.getLatestTacService')
|
|
63
|
-
async getLatestTacService(): Promise<GetLatestTacResult> {
|
|
64
|
-
const tosDetails = await this.getLatestToSVersion();
|
|
65
|
-
return {
|
|
66
|
-
version: tosDetails.version,
|
|
67
|
-
text: TAC_TEXT,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@Logger('ToSSignatureClient.getWalletLatestTacStatus')
|
|
72
|
-
async getWalletLatestTacStatus(
|
|
73
|
-
params: GetWalletLatestTacStatusParams,
|
|
74
|
-
): Promise<GetWalletLatestTacStatusResult> {
|
|
75
|
-
const signerAddress = params.address.toLowerCase() as Address;
|
|
76
|
-
|
|
77
|
-
const signatureData = await this.getSignature(signerAddress);
|
|
78
|
-
|
|
79
|
-
const latestToS = await this.getLatestToSVersion();
|
|
80
|
-
let termsAccepted = false;
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
signatureData &&
|
|
84
|
-
signatureData.walletAddress.toLowerCase() ===
|
|
85
|
-
signerAddress.toLowerCase() &&
|
|
86
|
-
signatureData.version === latestToS.version
|
|
87
|
-
) {
|
|
88
|
-
// Wallet matches, and signed data also matches
|
|
89
|
-
// (signature was checked before being written to database)
|
|
90
|
-
termsAccepted = true;
|
|
91
|
-
} // todo: do we want eip1271?
|
|
92
|
-
|
|
93
|
-
return { signed: termsAccepted };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Logger('ToSSignatureClient.signTac')
|
|
97
|
-
async signTac(params: SignTacParams): Promise<void> {
|
|
98
|
-
let latestToS;
|
|
99
|
-
try {
|
|
100
|
-
latestToS = await this.getLatestToSVersion();
|
|
101
|
-
} catch (error) {
|
|
102
|
-
throw new Error('Error getting latest T&C version');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const signerAddress = (
|
|
106
|
-
await params.signer.getAddress()
|
|
107
|
-
).toLowerCase() as Address;
|
|
108
|
-
|
|
109
|
-
let modifiedText;
|
|
110
|
-
let signature;
|
|
111
|
-
try {
|
|
112
|
-
// minimise special characters as they tend to change when signed
|
|
113
|
-
modifiedText = latestToS.text.replace(/\t/g, ''); // Remove tabs
|
|
114
|
-
modifiedText = modifiedText.replace(/\n\n/g, '\n'); // Replace double newline with single newline
|
|
115
|
-
signature = await params.signer.signMessage(modifiedText);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
throw new Error('Error signing message');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let response;
|
|
121
|
-
try {
|
|
122
|
-
response = await this.saveSignatureWithToS(
|
|
123
|
-
signerAddress,
|
|
124
|
-
signature,
|
|
125
|
-
modifiedText,
|
|
126
|
-
latestToS.version,
|
|
127
|
-
params.referredByCode,
|
|
128
|
-
);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
throw new Error('Error in saving signature endpoint');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!response.signatureSavedSuccessfully) {
|
|
134
|
-
throw new Error('Error saving signature');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
|
|
3
|
-
export type GetLatestTacResult = {
|
|
4
|
-
version: string;
|
|
5
|
-
text: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type GetWalletLatestTacStatusResult = {
|
|
9
|
-
signed: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type GetWalletLatestTacStatusParams = {
|
|
13
|
-
address: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type SignTacParams = {
|
|
17
|
-
signer: Signer | JsonRpcSigner;
|
|
18
|
-
version: string;
|
|
19
|
-
referredByCode?: string;
|
|
20
|
-
};
|