@gardenfi/utils 0.0.1-beta.10 → 0.0.1-beta.11

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/index6.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),u=require("./index7.cjs"),d=require("./index8.cjs"),g=require("jsonwebtoken"),f=require("./index5.cjs"),w=require("./index10.cjs");class m{constructor(t,i,e){this.API="https://api.garden.finance",this.url=new f.Url("/",t??this.API),this.walletClient=i,this.domain=(e==null?void 0:e.domain)||"app.garden.finance",this.domain.startsWith("https://")&&(this.domain=this.domain.split("https://")[1]),this.signingStatement=(e==null?void 0:e.signingStatement)??"Garden.fi",this.store=(e==null?void 0:e.store)??new u.MemoryStorage}verifyToken(t,i){console.log("token inside verifyToken :",t);try{const e=h(t);if(console.log("parsedToken :",e),!e)return n.Ok(!1);const r=Math.floor(Date.now()/1e3)+120;return n.Ok(e.exp>r&&e.address.toLowerCase()===i.toLowerCase())}catch{return n.Ok(!1)}}async getToken(){var s;if(!((s=this.walletClient.account)!=null&&s.address))return n.Err("Wallet client does not have an account");const t=this.store.getItem(d.StoreKeys.AUTH_TOKEN);if(console.log("authToken from store :",t),t){const o=this.verifyToken(t,this.walletClient.account.address);if(o.ok&&o.val)return n.Ok(t)}const i=await this.signStatement();if(i.error)return n.Err(i.error);const e=await n.Fetcher.post(this.url.endpoint("verify"),{body:JSON.stringify({...i.val}),headers:{"Content-Type":"application/json"}});if(e.error)return n.Err(e.error);const r=e.result;if(console.log("token :",r),!r)return n.Err("Failed to get token");if(!this.verifyToken(r,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(d.StoreKeys.AUTH_TOKEN,r),n.Ok(r)}async signStatement(){var l;if(!((l=this.walletClient.account)!=null&&l.address))return n.Err("Wallet client does not have a valid account");const t=new Date,i=new Date(t.getTime()+300*1e3),r=(await n.Fetcher.get(this.url.endpoint("nonce"))).result;if(!r)return n.Err("Failed to get nonce");const c=await this.walletClient.getChainId(),s=w.createSiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:r,uri:"https://"+this.domain,version:"1",chainId:c,notBefore:i}),o=await this.walletClient.signMessage({account:this.walletClient.account,message:s});return n.Ok({message:s,signature:o,nonce:r})}}const h=a=>{try{const t=g.decode(a);return console.log("decodedToken :",t),t}catch{return}};exports.Siwe=m;exports.parseJwt=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),u=require("./index7.cjs"),d=require("./index8.cjs"),g=require("jwt-decode"),f=require("./index5.cjs"),w=require("./index10.cjs");class m{constructor(t,i,e){this.API="https://api.garden.finance",this.url=new f.Url("/",t??this.API),this.walletClient=i,this.domain=(e==null?void 0:e.domain)||"app.garden.finance",this.domain.startsWith("https://")&&(this.domain=this.domain.split("https://")[1]),this.signingStatement=(e==null?void 0:e.signingStatement)??"Garden.fi",this.store=(e==null?void 0:e.store)??new u.MemoryStorage}verifyToken(t,i){console.log("token inside verifyToken :",t);try{const e=h(t);if(console.log("parsedToken :",e),!e)return n.Ok(!1);const r=Math.floor(Date.now()/1e3)+120;return n.Ok(e.exp>r&&e.address.toLowerCase()===i.toLowerCase())}catch{return n.Ok(!1)}}async getToken(){var s;if(!((s=this.walletClient.account)!=null&&s.address))return n.Err("Wallet client does not have an account");const t=this.store.getItem(d.StoreKeys.AUTH_TOKEN);if(console.log("authToken from store :",t),t){const o=this.verifyToken(t,this.walletClient.account.address);if(o.ok&&o.val)return n.Ok(t)}const i=await this.signStatement();if(i.error)return n.Err(i.error);const e=await n.Fetcher.post(this.url.endpoint("verify"),{body:JSON.stringify({...i.val}),headers:{"Content-Type":"application/json"}});if(e.error)return n.Err(e.error);const r=e.result;if(console.log("token :",r),!r)return n.Err("Failed to get token");if(!this.verifyToken(r,this.walletClient.account.address).val)throw new Error("Token verification failed");return this.store.setItem(d.StoreKeys.AUTH_TOKEN,r),n.Ok(r)}async signStatement(){var l;if(!((l=this.walletClient.account)!=null&&l.address))return n.Err("Wallet client does not have a valid account");const t=new Date,i=new Date(t.getTime()+300*1e3),r=(await n.Fetcher.get(this.url.endpoint("nonce"))).result;if(!r)return n.Err("Failed to get nonce");const c=await this.walletClient.getChainId(),s=w.createSiweMessage({domain:this.domain,address:this.walletClient.account.address,statement:this.signingStatement,nonce:r,uri:"https://"+this.domain,version:"1",chainId:c,notBefore:i}),o=await this.walletClient.signMessage({account:this.walletClient.account,message:s});return n.Ok({message:s,signature:o,nonce:r})}}const h=a=>{try{const t=g.jwtDecode(a);return console.log("decodedToken :",t),t}catch{return}};exports.Siwe=m;exports.parseJwt=h;
package/dist/index6.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Ok as r, Err as o, Fetcher as h } from "@catalogfi/utils";
2
2
  import { MemoryStorage as m } from "./index7.js";
3
3
  import { StoreKeys as f } from "./index8.js";
4
- import u from "jsonwebtoken";
4
+ import { jwtDecode as u } from "jwt-decode";
5
5
  import { Url as g } from "./index5.js";
6
6
  import { createSiweMessage as w } from "./index10.js";
7
7
  class I {
@@ -85,7 +85,7 @@ class I {
85
85
  }
86
86
  const T = (c) => {
87
87
  try {
88
- const t = u.decode(c);
88
+ const t = u(c);
89
89
  return console.log("decodedToken :", t), t;
90
90
  } catch {
91
91
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/utils",
3
- "version": "0.0.1-beta.10",
3
+ "version": "0.0.1-beta.11",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -26,7 +26,6 @@
26
26
  "registry": "https://registry.npmjs.org/"
27
27
  },
28
28
  "devDependencies": {
29
- "@types/jsonwebtoken": "^9",
30
29
  "@types/ws": "^8.5.7",
31
30
  "dotenv": "^16.3.1",
32
31
  "typescript": "^5.2.2",
@@ -38,7 +37,7 @@
38
37
  "dependencies": {
39
38
  "@catalogfi/utils": "^0.1.11",
40
39
  "axios": "^1.7.2",
41
- "jsonwebtoken": "^9.0.2",
40
+ "jwt-decode": "^4.0.0",
42
41
  "viem": "^2.21.15"
43
42
  }
44
43
  }