@dripfi/drip-sdk 1.1.2 → 1.1.3
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/DripSdk.d.ts +1 -0
- package/dist/DripSdk.js +41 -6
- package/package.json +1 -1
package/dist/DripSdk.d.ts
CHANGED
@@ -18,6 +18,7 @@ export default class DripSdk {
|
|
18
18
|
getTokenPrice(tokenName: string): Promise<number>;
|
19
19
|
updateSigner(newSigner: Signer): void;
|
20
20
|
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
21
|
+
verifySignature(address: string, message: string, signature: string): Promise<boolean>;
|
21
22
|
authenticate(): Promise<boolean>;
|
22
23
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
23
24
|
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
package/dist/DripSdk.js
CHANGED
@@ -87,17 +87,52 @@ class DripSdk {
|
|
87
87
|
if (!authToken) {
|
88
88
|
return { isAuthenticated: false, message: 'Auth token not found' };
|
89
89
|
}
|
90
|
-
const { address } =
|
91
|
-
|
90
|
+
// const { address, body } = Web3Token.verify(authToken);
|
91
|
+
const decodedBody = JSON.parse(Buffer.from(authToken, 'base64').toString('utf-8'));
|
92
|
+
const message = decodedBody.body;
|
93
|
+
const signature = decodedBody.signature;
|
94
|
+
if (!message || !signature) {
|
95
|
+
console.error('Message or signature not found in the token body');
|
96
|
+
return { isAuthenticated: false, message: 'Invalid token structure' };
|
97
|
+
}
|
98
|
+
const isValid = yield this.verifySignature(userAddress, message, signature);
|
99
|
+
if (!isValid) {
|
92
100
|
js_cookie_1.default.remove(cookieName);
|
93
|
-
return { isAuthenticated: false, message: 'Invalid token' };
|
101
|
+
return { isAuthenticated: false, message: 'Invalid token or signature' };
|
94
102
|
}
|
95
|
-
return { isAuthenticated: true, address:
|
103
|
+
return { isAuthenticated: true, address: userAddress.toLowerCase(), token: authToken };
|
104
|
+
}
|
105
|
+
catch (error) {
|
106
|
+
return { isAuthenticated: false };
|
107
|
+
}
|
108
|
+
});
|
109
|
+
}
|
110
|
+
verifySignature(address, message, signature) {
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
112
|
+
var _a;
|
113
|
+
// First, try standard signature verification
|
114
|
+
try {
|
115
|
+
const recoveredAddress = ethers_1.ethers.utils.verifyMessage(message, signature);
|
116
|
+
if (recoveredAddress.toLowerCase() === address.toLowerCase()) {
|
117
|
+
return true;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
catch (error) {
|
121
|
+
console.error('Standard signature verification error: ', error);
|
122
|
+
}
|
123
|
+
// If standard verification fails, try EIP-1271 verification
|
124
|
+
try {
|
125
|
+
const SafeInterface = new ethers_1.ethers.utils.Interface([
|
126
|
+
'function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4)'
|
127
|
+
]);
|
128
|
+
const safeContract = new ethers_1.ethers.Contract(address, SafeInterface, (_a = this.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
129
|
+
const messageHash = ethers_1.ethers.utils.hashMessage(message);
|
130
|
+
const isValidSignature = yield safeContract.isValidSignature(messageHash, signature);
|
131
|
+
return isValidSignature === '0x1626ba7e'; // EIP-1271 magic value
|
96
132
|
}
|
97
133
|
catch (error) {
|
98
|
-
|
134
|
+
return false;
|
99
135
|
}
|
100
|
-
return { isAuthenticated: false };
|
101
136
|
});
|
102
137
|
}
|
103
138
|
authenticate() {
|