@dripfi/drip-sdk 1.1.3 → 1.1.5
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/README.md +1 -1
- package/dist/DripSdk.d.ts +0 -1
- package/dist/DripSdk.js +25 -57
- package/dist/types/DeployedProject.d.ts +1 -0
- package/dist/types/VaultReward.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/DripSdk.d.ts
CHANGED
@@ -18,7 +18,6 @@ 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>;
|
22
21
|
authenticate(): Promise<boolean>;
|
23
22
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
24
23
|
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
package/dist/DripSdk.js
CHANGED
@@ -77,62 +77,16 @@ class DripSdk {
|
|
77
77
|
}
|
78
78
|
isUserAuthenticated() {
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
80
|
-
|
81
|
-
|
82
|
-
return { isAuthenticated: false, message: 'Signer not provided' };
|
83
|
-
}
|
84
|
-
const userAddress = yield this.signer.getAddress();
|
85
|
-
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
86
|
-
const authToken = js_cookie_1.default.get(cookieName);
|
87
|
-
if (!authToken) {
|
88
|
-
return { isAuthenticated: false, message: 'Auth token not found' };
|
89
|
-
}
|
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) {
|
100
|
-
js_cookie_1.default.remove(cookieName);
|
101
|
-
return { isAuthenticated: false, message: 'Invalid token or signature' };
|
102
|
-
}
|
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);
|
80
|
+
if (!this.signer) {
|
81
|
+
return { isAuthenticated: false, message: 'Signer not provided' };
|
122
82
|
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
132
|
-
}
|
133
|
-
catch (error) {
|
134
|
-
return false;
|
83
|
+
const userAddress = yield this.signer.getAddress();
|
84
|
+
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
85
|
+
const authToken = js_cookie_1.default.get(cookieName);
|
86
|
+
if (!authToken) {
|
87
|
+
return { isAuthenticated: false, message: 'Auth token not found' };
|
135
88
|
}
|
89
|
+
return { isAuthenticated: true, address: userAddress.toLowerCase(), token: authToken };
|
136
90
|
});
|
137
91
|
}
|
138
92
|
authenticate() {
|
@@ -143,11 +97,25 @@ class DripSdk {
|
|
143
97
|
}
|
144
98
|
const address = yield this.signer.getAddress();
|
145
99
|
const cookieName = `auth_${address.toLowerCase()}`;
|
146
|
-
const token = yield web3_token_1.default.sign((
|
147
|
-
statement: 'Please sign
|
100
|
+
const token = yield web3_token_1.default.sign((message) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(message); }), {
|
101
|
+
statement: JSON.stringify({ address, message: 'Please sign in into Drip' }),
|
148
102
|
expires_in: '30d',
|
149
103
|
});
|
150
|
-
|
104
|
+
const response = yield fetch(`${this.dripConfig.dripRoute}/api-be/auth/verify`, {
|
105
|
+
method: 'POST',
|
106
|
+
headers: {
|
107
|
+
'Content-Type': 'application/json',
|
108
|
+
},
|
109
|
+
body: JSON.stringify({ token }),
|
110
|
+
});
|
111
|
+
const result = yield response.json();
|
112
|
+
if (result.success) {
|
113
|
+
js_cookie_1.default.set(cookieName, result.auth, { expires: 30 });
|
114
|
+
}
|
115
|
+
else {
|
116
|
+
js_cookie_1.default.remove(cookieName);
|
117
|
+
return false;
|
118
|
+
}
|
151
119
|
return true;
|
152
120
|
}
|
153
121
|
catch (error) {
|