@dripfi/drip-sdk 1.1.4 → 1.1.6

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/DripApi.d.ts CHANGED
@@ -5,6 +5,7 @@ import { QLFastRedeem } from './types/QLFastRedeem';
5
5
  import { UserRewards } from './types/UserRewards';
6
6
  import { VaultStats } from './types/VaultStats';
7
7
  import { UserBalance } from './types/UserBalance';
8
+ import { VaultClaimData } from './types/VaultClaimData';
8
9
  export declare const IMPERSONATOR_HEADER = "impersonatorAddress";
9
10
  export default class DripApi {
10
11
  route: string;
@@ -28,4 +29,5 @@ export default class DripApi {
28
29
  fetchAssetPerSvtAtBlock(vaultAddress: string, blocknumber: number, token: string): Promise<BigNumber>;
29
30
  fetchFastWithdrawNFTs(vaultAddress: string, walletAddress: string, token: string, headers?: Headers): Promise<QLFastRedeem[]>;
30
31
  fetchUserRewards(walletAddress: string, token: string, headers?: Headers): Promise<UserRewards>;
32
+ fetchVaultsClaimableData(walletAddress: string, token: string, headers?: Headers): Promise<VaultClaimData>;
31
33
  }
package/dist/DripApi.js CHANGED
@@ -252,5 +252,19 @@ class DripApi {
252
252
  return data;
253
253
  });
254
254
  }
255
+ fetchVaultsClaimableData(walletAddress, token, headers) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ const reqHeaders = headers ? headers : new Headers();
258
+ reqHeaders.append(AUTHORIZATION_HEADER, token);
259
+ if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
260
+ walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
261
+ }
262
+ const res = yield fetch(`${this.route}/api-be/api/user/claimableVaults/${walletAddress}`, {
263
+ headers: reqHeaders,
264
+ });
265
+ const data = yield res.json();
266
+ return data;
267
+ });
268
+ }
255
269
  }
256
270
  exports.default = DripApi;
package/dist/DripSdk.d.ts CHANGED
@@ -5,6 +5,7 @@ import { UserRewards } from './types/UserRewards';
5
5
  import { VaultStats } from './types/VaultStats';
6
6
  import { UserBalance } from './types/UserBalance';
7
7
  import { UserVaultBalance } from './types/UserVaultBalance';
8
+ import { VaultClaimData } from './types/VaultClaimData';
8
9
  import { Vault } from './types/Vault';
9
10
  export default class DripSdk {
10
11
  private dripApi;
@@ -18,7 +19,6 @@ export default class DripSdk {
18
19
  getTokenPrice(tokenName: string): Promise<number>;
19
20
  updateSigner(newSigner: Signer): void;
20
21
  isUserAuthenticated(): Promise<AuthenticationStatus>;
21
- verifySignature(address: string, message: string, signature: string): Promise<boolean>;
22
22
  authenticate(): Promise<boolean>;
23
23
  deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
24
24
  getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
@@ -31,6 +31,7 @@ export default class DripSdk {
31
31
  swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
32
32
  withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
33
33
  claimWithdraws(vaultAddress: string): Promise<string>;
34
+ getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>;
34
35
  private generateOldRedeemBagStruct;
35
36
  private generateNewRedeemBagStruct;
36
37
  private getAllSvts;
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
- try {
81
- if (!this.signer) {
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);
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
80
+ if (!this.signer) {
81
+ return { isAuthenticated: false, message: 'Signer not provided' };
132
82
  }
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((msg) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(msg); }), {
147
- statement: 'Please sign this message to authenticate.',
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
- js_cookie_1.default.set(cookieName, token, { expires: 30 });
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) {
@@ -375,6 +343,18 @@ class DripSdk {
375
343
  return txReceipt.transactionHash;
376
344
  });
377
345
  }
346
+ getVaultsClaimableData(headers) {
347
+ return __awaiter(this, void 0, void 0, function* () {
348
+ const authData = yield this.isUserAuthenticated();
349
+ if (!authData.isAuthenticated) {
350
+ throw Error(`User not authenticated: ${authData.message}`);
351
+ }
352
+ if (!this.signer) {
353
+ throw Error('No signer provided');
354
+ }
355
+ return yield this.dripApi.fetchVaultsClaimableData(authData.address, authData.token, headers);
356
+ });
357
+ }
378
358
  generateOldRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
379
359
  return __awaiter(this, void 0, void 0, function* () {
380
360
  const dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress, signerAddress, token);
@@ -31,6 +31,7 @@ export type DeployedProject = {
31
31
  projectInfoText: string;
32
32
  projectRewardText: string;
33
33
  stretchGoals: StretchGoal[];
34
+ owners: string[];
34
35
  };
35
36
  export type ProjectBacker = {
36
37
  name: string;
@@ -0,0 +1,6 @@
1
+ export type VaultClaimData = {
2
+ vaultAddress: string;
3
+ asset: string;
4
+ dripping: string;
5
+ claimable: number;
6
+ }[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",