@reyaxyz/wallet-sdk 0.15.20 → 0.15.22
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/modules/tos-app/index.js +105 -18
- package/dist/clients/modules/tos-app/index.js.map +1 -1
- package/dist/clients/modules/tos-app/types.js.map +1 -1
- package/dist/types/clients/modules/tos-app/index.d.ts +3 -1
- package/dist/types/clients/modules/tos-app/index.d.ts.map +1 -1
- package/dist/types/clients/modules/tos-app/types.d.ts +6 -4
- package/dist/types/clients/modules/tos-app/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/clients/modules/tos-app/index.ts +104 -18
- package/src/clients/modules/tos-app/types.ts +7 -4
|
@@ -66,13 +66,43 @@ var ToSSignatureAppClient = /** @class */ (function (_super) {
|
|
|
66
66
|
_this.loggingEnabled = loggingEnabled;
|
|
67
67
|
return _this;
|
|
68
68
|
}
|
|
69
|
-
ToSSignatureAppClient.prototype.
|
|
69
|
+
ToSSignatureAppClient.prototype.getSignature = function (walletAddress) {
|
|
70
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
71
|
var uri;
|
|
72
72
|
return __generator(this, function (_a) {
|
|
73
73
|
switch (_a.label) {
|
|
74
74
|
case 0:
|
|
75
|
-
uri = "/api/tos/
|
|
75
|
+
uri = "/api/owner/".concat(walletAddress, "/tos/get-signature");
|
|
76
|
+
return [4 /*yield*/, this.get(uri)];
|
|
77
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
ToSSignatureAppClient.prototype.saveSignatureWithToS = function (walletAddress, signature, termsOfService, version, referredByCode) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var formData, uri;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
formData = new FormData();
|
|
87
|
+
formData.append('signature', signature);
|
|
88
|
+
formData.append('walletAddress', walletAddress);
|
|
89
|
+
formData.append('message', termsOfService);
|
|
90
|
+
formData.append('version', version);
|
|
91
|
+
if (referredByCode) {
|
|
92
|
+
formData.append('referredByCode', referredByCode);
|
|
93
|
+
}
|
|
94
|
+
uri = '/api/owner/tos/add-signature';
|
|
95
|
+
return [2 /*return*/, this.post(uri, undefined, formData, undefined)];
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
ToSSignatureAppClient.prototype.getLatestToSProductVersion = function (product) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
var uri;
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
uri = "/api/tos/latest-product-version/".concat(product);
|
|
76
106
|
return [4 /*yield*/, this.get(uri)];
|
|
77
107
|
case 1: return [2 /*return*/, _a.sent()];
|
|
78
108
|
}
|
|
@@ -84,12 +114,12 @@ var ToSSignatureAppClient = /** @class */ (function (_super) {
|
|
|
84
114
|
var tosDetails;
|
|
85
115
|
return __generator(this, function (_a) {
|
|
86
116
|
switch (_a.label) {
|
|
87
|
-
case 0: return [4 /*yield*/, this.
|
|
117
|
+
case 0: return [4 /*yield*/, this.getLatestToSProductVersion(params.product)];
|
|
88
118
|
case 1:
|
|
89
119
|
tosDetails = _a.sent();
|
|
90
120
|
return [2 /*return*/, {
|
|
91
121
|
version: tosDetails.version,
|
|
92
|
-
text: tosDetails.
|
|
122
|
+
text: tosDetails.longText,
|
|
93
123
|
product: params.product,
|
|
94
124
|
}];
|
|
95
125
|
}
|
|
@@ -100,14 +130,28 @@ var ToSSignatureAppClient = /** @class */ (function (_super) {
|
|
|
100
130
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
101
131
|
params) {
|
|
102
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
var signerAddress, signatureData, latestToS, termsAccepted;
|
|
103
134
|
return __generator(this, function (_a) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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.getLatestToSProductVersion(params.product)];
|
|
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
|
+
}
|
|
153
|
+
return [2 /*return*/, { signed: termsAccepted }];
|
|
154
|
+
}
|
|
111
155
|
});
|
|
112
156
|
});
|
|
113
157
|
};
|
|
@@ -115,18 +159,61 @@ var ToSSignatureAppClient = /** @class */ (function (_super) {
|
|
|
115
159
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
160
|
params) {
|
|
117
161
|
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
+
var latestToS, error_1, signerAddress, modifiedText, signature, error_2, response, error_3;
|
|
118
163
|
return __generator(this, function (_a) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
_a.trys.push([0, 2, , 3]);
|
|
167
|
+
return [4 /*yield*/, this.getLatestToSProductVersion(params.product)];
|
|
168
|
+
case 1:
|
|
169
|
+
latestToS = _a.sent();
|
|
170
|
+
return [3 /*break*/, 3];
|
|
171
|
+
case 2:
|
|
172
|
+
error_1 = _a.sent();
|
|
173
|
+
throw new Error('Error getting latest T&C version');
|
|
174
|
+
case 3: return [4 /*yield*/, params.signer.getAddress()];
|
|
175
|
+
case 4:
|
|
176
|
+
signerAddress = (_a.sent()).toLowerCase();
|
|
177
|
+
_a.label = 5;
|
|
178
|
+
case 5:
|
|
179
|
+
_a.trys.push([5, 7, , 8]);
|
|
180
|
+
// minimise special characters as they tend to change when signed
|
|
181
|
+
modifiedText = latestToS.shortText.replace(/\t/g, ''); // Remove tabs
|
|
182
|
+
modifiedText = modifiedText.replace(/\n\n/g, '\n'); // Replace double newline with single newline
|
|
183
|
+
return [4 /*yield*/, params.signer.signMessage(modifiedText)];
|
|
184
|
+
case 6:
|
|
185
|
+
signature = _a.sent();
|
|
186
|
+
return [3 /*break*/, 8];
|
|
187
|
+
case 7:
|
|
188
|
+
error_2 = _a.sent();
|
|
189
|
+
throw new Error('Error signing message');
|
|
190
|
+
case 8:
|
|
191
|
+
_a.trys.push([8, 10, , 11]);
|
|
192
|
+
return [4 /*yield*/, this.saveSignatureWithToS(signerAddress, signature, modifiedText, latestToS.version, params.referredByCode)];
|
|
193
|
+
case 9:
|
|
194
|
+
response = _a.sent();
|
|
195
|
+
return [3 /*break*/, 11];
|
|
196
|
+
case 10:
|
|
197
|
+
error_3 = _a.sent();
|
|
198
|
+
throw new Error('Error in saving signature endpoint');
|
|
199
|
+
case 11:
|
|
200
|
+
if (!response.signatureSavedSuccessfully) {
|
|
201
|
+
throw new Error('Error saving signature');
|
|
202
|
+
}
|
|
203
|
+
return [2 /*return*/];
|
|
204
|
+
}
|
|
124
205
|
});
|
|
125
206
|
});
|
|
126
207
|
};
|
|
127
208
|
__decorate([
|
|
128
|
-
(0, common_1.Logger)('ToSSignatureAppClient.
|
|
129
|
-
], ToSSignatureAppClient.prototype, "
|
|
209
|
+
(0, common_1.Logger)('ToSSignatureAppClient.getSignature')
|
|
210
|
+
], ToSSignatureAppClient.prototype, "getSignature", null);
|
|
211
|
+
__decorate([
|
|
212
|
+
(0, common_1.Logger)('ToSSignatureAppClient.saveSignatureWithToS')
|
|
213
|
+
], ToSSignatureAppClient.prototype, "saveSignatureWithToS", null);
|
|
214
|
+
__decorate([
|
|
215
|
+
(0, common_1.Logger)('ToSSignatureAppClient.getLatestToSProductVersion')
|
|
216
|
+
], ToSSignatureAppClient.prototype, "getLatestToSProductVersion", null);
|
|
130
217
|
__decorate([
|
|
131
218
|
(0, common_1.Logger)('ToSSignatureAppClient.getLatestTacService')
|
|
132
219
|
], ToSSignatureAppClient.prototype, "getLatestTacService", null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/tos-app/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["clients/modules/tos-app/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAOyB;AAWzB;IACU,yCAAU;IAKlB,+BAAY,MAAc,EAAE,cAAuB;QACjD,YAAA,MAAK,YAAC,MAAM,CAAC,SAAC;QAHhB,oBAAc,GAAY,KAAK,CAAC;QAI9B,KAAI,CAAC,cAAc,GAAG,cAAc,CAAC;;IACvC,CAAC;IAGa,4CAAY,GAAZ,UACZ,aAAsB;;;;;;wBAEhB,GAAG,GAAG,qBAAc,aAAa,uBAAoB,CAAC;wBACrD,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAA;4BAA1B,sBAAO,SAAmB,EAAC;;;;KAC5B;IAGa,oDAAoB,GAApB,UACZ,aAAsB,EACtB,SAAiB,EACjB,cAAsB,EACtB,OAAe,EACf,cAAkC;;;;gBAG5B,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;gBAChC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;gBACxC,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CAAC,QAAQ,CAAC,0BAA0B,EAAE,CAAC;4BACzC,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;wBAC5C,CAAC;;;;;KACF;IAvHa;QADb,IAAA,eAAM,EAAC,oCAAoC,CAAC;6DAM5C;IAGa;QADb,IAAA,eAAM,EAAC,4CAA4C,CAAC;qEAqBpD;IAGa;QADb,IAAA,eAAM,EAAC,kDAAkD,CAAC;2EAM1D;IAGK;QADL,IAAA,eAAM,EAAC,2CAA2C,CAAC;oEAUnD;IAGK;QADL,IAAA,eAAM,EAAC,gDAAgD,CAAC;yEAwBxD;IAGK;QADL,IAAA,eAAM,EAAC,+BAA+B,CAAC;wDA2CvC;IACH,4BAAC;CAAA,AApID,CACU,mBAAU,GAmInB;kBApIoB,qBAAqB","sourcesContent":["import {\n Address,\n Logger,\n RestClient,\n SaveSignatureResult,\n SignatureData,\n ToSProductVersionDetails,\n} from '@reyaxyz/common';\nimport {\n GetLatestAppTacResult,\n GetLatestAppTacParam,\n GetWalletLatestAppTacStatusParams,\n GetWalletLatestAppTacStatusResult,\n SignAppTacParams,\n Product,\n} from './types';\nimport { Loggable } from '@reyaxyz/common';\n\nexport default class ToSSignatureAppClient\n extends RestClient\n implements Loggable\n{\n loggingEnabled: boolean = false;\n\n constructor(apiUrl: string, loggingEnabled: boolean) {\n super(apiUrl);\n this.loggingEnabled = loggingEnabled;\n }\n\n @Logger('ToSSignatureAppClient.getSignature')\n private async getSignature(\n walletAddress: Address,\n ): Promise<SignatureData | undefined> {\n const uri = `/api/owner/${walletAddress}/tos/get-signature`;\n return await this.get(uri);\n }\n\n @Logger('ToSSignatureAppClient.saveSignatureWithToS')\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('ToSSignatureAppClient.getLatestToSProductVersion')\n private async getLatestToSProductVersion(\n product: Product,\n ): Promise<ToSProductVersionDetails> {\n const uri = `/api/tos/latest-product-version/${product}`;\n return await this.get(uri);\n }\n\n @Logger('ToSSignatureAppClient.getLatestTacService')\n async getLatestTacService(\n params: GetLatestAppTacParam,\n ): Promise<GetLatestAppTacResult> {\n const tosDetails = await this.getLatestToSProductVersion(params.product);\n return {\n version: tosDetails.version,\n text: tosDetails.longText,\n product: params.product,\n };\n }\n\n @Logger('ToSSignatureAppClient.getWalletLatestTacStatus')\n async getWalletLatestTacStatus(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: GetWalletLatestAppTacStatusParams,\n ): Promise<GetWalletLatestAppTacStatusResult> {\n const signerAddress = params.address.toLowerCase() as Address;\n\n const signatureData = await this.getSignature(signerAddress);\n\n const latestToS = await this.getLatestToSProductVersion(params.product);\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 }\n\n return { signed: termsAccepted };\n }\n\n @Logger('ToSSignatureAppClient.signTac')\n async signTac(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n params: SignAppTacParams,\n ): Promise<void> {\n let latestToS;\n try {\n latestToS = await this.getLatestToSProductVersion(params.product);\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.shortText.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/tos-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport type GetLatestAppTacResult = {\n version: string;\n text: string;\n product:
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"/","sources":["clients/modules/tos-app/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\n\nexport type Product = 'app.reya.xyz' | 'reya.network' | 'reya.xyz';\n\nexport type GetLatestAppTacResult = {\n version: string;\n text: string;\n product: Product;\n};\n\nexport type GetLatestAppTacParam = {\n product: Product;\n};\n\nexport type GetWalletLatestAppTacStatusResult = {\n signed: boolean;\n};\n\nexport type GetWalletLatestAppTacStatusParams = {\n address: string;\n product: Product;\n};\n\nexport type SignAppTacParams = {\n signer: Signer | JsonRpcSigner;\n version: string;\n product: Product;\n referredByCode?: string;\n};\n"]}
|
|
@@ -4,7 +4,9 @@ import { Loggable } from '@reyaxyz/common';
|
|
|
4
4
|
export default class ToSSignatureAppClient extends RestClient implements Loggable {
|
|
5
5
|
loggingEnabled: boolean;
|
|
6
6
|
constructor(apiUrl: string, loggingEnabled: boolean);
|
|
7
|
-
private
|
|
7
|
+
private getSignature;
|
|
8
|
+
private saveSignatureWithToS;
|
|
9
|
+
private getLatestToSProductVersion;
|
|
8
10
|
getLatestTacService(params: GetLatestAppTacParam): Promise<GetLatestAppTacResult>;
|
|
9
11
|
getWalletLatestTacStatus(params: GetWalletLatestAppTacStatusParams): Promise<GetWalletLatestAppTacStatusResult>;
|
|
10
12
|
signTac(params: SignAppTacParams): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/tos-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["clients/modules/tos-app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAIX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iCAAiC,EACjC,iCAAiC,EACjC,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,qBACnB,SAAQ,UACR,YAAW,QAAQ;IAEnB,cAAc,EAAE,OAAO,CAAS;gBAEpB,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO;YAMrC,YAAY;YAQZ,oBAAoB;YAuBpB,0BAA0B;IAQlC,mBAAmB,CACvB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,qBAAqB,CAAC;IAU3B,wBAAwB,CAE5B,MAAM,EAAE,iCAAiC,GACxC,OAAO,CAAC,iCAAiC,CAAC;IAuBvC,OAAO,CAEX,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,IAAI,CAAC;CAwCjB"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
+
export type Product = 'app.reya.xyz' | 'reya.network' | 'reya.xyz';
|
|
2
3
|
export type GetLatestAppTacResult = {
|
|
3
4
|
version: string;
|
|
4
5
|
text: string;
|
|
5
|
-
product:
|
|
6
|
+
product: Product;
|
|
6
7
|
};
|
|
7
8
|
export type GetLatestAppTacParam = {
|
|
8
|
-
product:
|
|
9
|
+
product: Product;
|
|
9
10
|
};
|
|
10
11
|
export type GetWalletLatestAppTacStatusResult = {
|
|
11
12
|
signed: boolean;
|
|
12
13
|
};
|
|
13
14
|
export type GetWalletLatestAppTacStatusParams = {
|
|
14
15
|
address: string;
|
|
15
|
-
product:
|
|
16
|
+
product: Product;
|
|
16
17
|
};
|
|
17
18
|
export type SignAppTacParams = {
|
|
18
19
|
signer: Signer | JsonRpcSigner;
|
|
19
20
|
version: string;
|
|
20
|
-
product:
|
|
21
|
+
product: Product;
|
|
22
|
+
referredByCode?: string;
|
|
21
23
|
};
|
|
22
24
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/tos-app/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["clients/modules/tos-app/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,cAAc,GAAG,UAAU,CAAC;AAEnE,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/wallet-sdk",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.22",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@reyaxyz/common": "0.
|
|
36
|
+
"@reyaxyz/common": "0.101.0",
|
|
37
37
|
"axios": "^1.6.2",
|
|
38
38
|
"bignumber.js": "^9.1.2",
|
|
39
39
|
"ethers": "6.9.0"
|
|
40
40
|
},
|
|
41
41
|
"packageManager": "pnpm@8.3.1",
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "28b1a475082b95ac0954c766d404a9c91946d31b"
|
|
43
43
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
Logger,
|
|
4
|
+
RestClient,
|
|
5
|
+
SaveSignatureResult,
|
|
6
|
+
SignatureData,
|
|
7
|
+
ToSProductVersionDetails,
|
|
8
|
+
} from '@reyaxyz/common';
|
|
2
9
|
import {
|
|
3
10
|
GetLatestAppTacResult,
|
|
4
11
|
GetLatestAppTacParam,
|
|
5
12
|
GetWalletLatestAppTacStatusParams,
|
|
6
13
|
GetWalletLatestAppTacStatusResult,
|
|
7
14
|
SignAppTacParams,
|
|
15
|
+
Product,
|
|
8
16
|
} from './types';
|
|
9
17
|
import { Loggable } from '@reyaxyz/common';
|
|
10
18
|
|
|
@@ -19,9 +27,42 @@ export default class ToSSignatureAppClient
|
|
|
19
27
|
this.loggingEnabled = loggingEnabled;
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
@Logger('ToSSignatureAppClient.
|
|
23
|
-
private async
|
|
24
|
-
|
|
30
|
+
@Logger('ToSSignatureAppClient.getSignature')
|
|
31
|
+
private async getSignature(
|
|
32
|
+
walletAddress: Address,
|
|
33
|
+
): Promise<SignatureData | undefined> {
|
|
34
|
+
const uri = `/api/owner/${walletAddress}/tos/get-signature`;
|
|
35
|
+
return await this.get(uri);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Logger('ToSSignatureAppClient.saveSignatureWithToS')
|
|
39
|
+
private async saveSignatureWithToS(
|
|
40
|
+
walletAddress: Address,
|
|
41
|
+
signature: string,
|
|
42
|
+
termsOfService: string,
|
|
43
|
+
version: string,
|
|
44
|
+
referredByCode: string | undefined,
|
|
45
|
+
): Promise<SaveSignatureResult> {
|
|
46
|
+
// Build formData object.
|
|
47
|
+
const formData = new FormData();
|
|
48
|
+
formData.append('signature', signature);
|
|
49
|
+
formData.append('walletAddress', walletAddress);
|
|
50
|
+
formData.append('message', termsOfService);
|
|
51
|
+
formData.append('version', version);
|
|
52
|
+
|
|
53
|
+
if (referredByCode) {
|
|
54
|
+
formData.append('referredByCode', referredByCode);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const uri = '/api/owner/tos/add-signature';
|
|
58
|
+
return this.post(uri, undefined, formData, undefined);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@Logger('ToSSignatureAppClient.getLatestToSProductVersion')
|
|
62
|
+
private async getLatestToSProductVersion(
|
|
63
|
+
product: Product,
|
|
64
|
+
): Promise<ToSProductVersionDetails> {
|
|
65
|
+
const uri = `/api/tos/latest-product-version/${product}`;
|
|
25
66
|
return await this.get(uri);
|
|
26
67
|
}
|
|
27
68
|
|
|
@@ -29,10 +70,10 @@ export default class ToSSignatureAppClient
|
|
|
29
70
|
async getLatestTacService(
|
|
30
71
|
params: GetLatestAppTacParam,
|
|
31
72
|
): Promise<GetLatestAppTacResult> {
|
|
32
|
-
const tosDetails = await this.
|
|
73
|
+
const tosDetails = await this.getLatestToSProductVersion(params.product);
|
|
33
74
|
return {
|
|
34
75
|
version: tosDetails.version,
|
|
35
|
-
text: tosDetails.
|
|
76
|
+
text: tosDetails.longText,
|
|
36
77
|
product: params.product,
|
|
37
78
|
};
|
|
38
79
|
}
|
|
@@ -42,13 +83,25 @@ export default class ToSSignatureAppClient
|
|
|
42
83
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
84
|
params: GetWalletLatestAppTacStatusParams,
|
|
44
85
|
): Promise<GetWalletLatestAppTacStatusResult> {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
86
|
+
const signerAddress = params.address.toLowerCase() as Address;
|
|
87
|
+
|
|
88
|
+
const signatureData = await this.getSignature(signerAddress);
|
|
89
|
+
|
|
90
|
+
const latestToS = await this.getLatestToSProductVersion(params.product);
|
|
91
|
+
let termsAccepted = false;
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
signatureData &&
|
|
95
|
+
signatureData.walletAddress.toLowerCase() ===
|
|
96
|
+
signerAddress.toLowerCase() &&
|
|
97
|
+
signatureData.version === latestToS.version
|
|
98
|
+
) {
|
|
99
|
+
// Wallet matches, and signed data also matches
|
|
100
|
+
// (signature was checked before being written to database)
|
|
101
|
+
termsAccepted = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { signed: termsAccepted };
|
|
52
105
|
}
|
|
53
106
|
|
|
54
107
|
@Logger('ToSSignatureAppClient.signTac')
|
|
@@ -56,10 +109,43 @@ export default class ToSSignatureAppClient
|
|
|
56
109
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
57
110
|
params: SignAppTacParams,
|
|
58
111
|
): Promise<void> {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
112
|
+
let latestToS;
|
|
113
|
+
try {
|
|
114
|
+
latestToS = await this.getLatestToSProductVersion(params.product);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
throw new Error('Error getting latest T&C version');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const signerAddress = (
|
|
120
|
+
await params.signer.getAddress()
|
|
121
|
+
).toLowerCase() as Address;
|
|
122
|
+
|
|
123
|
+
let modifiedText;
|
|
124
|
+
let signature;
|
|
125
|
+
try {
|
|
126
|
+
// minimise special characters as they tend to change when signed
|
|
127
|
+
modifiedText = latestToS.shortText.replace(/\t/g, ''); // Remove tabs
|
|
128
|
+
modifiedText = modifiedText.replace(/\n\n/g, '\n'); // Replace double newline with single newline
|
|
129
|
+
signature = await params.signer.signMessage(modifiedText);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
throw new Error('Error signing message');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let response;
|
|
135
|
+
try {
|
|
136
|
+
response = await this.saveSignatureWithToS(
|
|
137
|
+
signerAddress,
|
|
138
|
+
signature,
|
|
139
|
+
modifiedText,
|
|
140
|
+
latestToS.version,
|
|
141
|
+
params.referredByCode,
|
|
142
|
+
);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new Error('Error in saving signature endpoint');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!response.signatureSavedSuccessfully) {
|
|
148
|
+
throw new Error('Error saving signature');
|
|
149
|
+
}
|
|
64
150
|
}
|
|
65
151
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
2
|
|
|
3
|
+
export type Product = 'app.reya.xyz' | 'reya.network' | 'reya.xyz';
|
|
4
|
+
|
|
3
5
|
export type GetLatestAppTacResult = {
|
|
4
6
|
version: string;
|
|
5
7
|
text: string;
|
|
6
|
-
product:
|
|
8
|
+
product: Product;
|
|
7
9
|
};
|
|
8
10
|
|
|
9
11
|
export type GetLatestAppTacParam = {
|
|
10
|
-
product:
|
|
12
|
+
product: Product;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export type GetWalletLatestAppTacStatusResult = {
|
|
@@ -16,11 +18,12 @@ export type GetWalletLatestAppTacStatusResult = {
|
|
|
16
18
|
|
|
17
19
|
export type GetWalletLatestAppTacStatusParams = {
|
|
18
20
|
address: string;
|
|
19
|
-
product:
|
|
21
|
+
product: Product;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export type SignAppTacParams = {
|
|
23
25
|
signer: Signer | JsonRpcSigner;
|
|
24
26
|
version: string;
|
|
25
|
-
product:
|
|
27
|
+
product: Product;
|
|
28
|
+
referredByCode?: string;
|
|
26
29
|
};
|