Browse Source

fix frontend example

0xproflupin 2 years ago
parent
commit
48f77f2643
3 changed files with 41 additions and 16 deletions
  1. 9 1
      README.md
  2. 7 15
      example-dapp/package.json
  3. 25 0
      example-dapp/src/App.tsx

+ 9 - 1
README.md

@@ -262,9 +262,17 @@ const autoSignIn = useCallback(async (adapter: Adapter) => {
   const output = await adapter.signIn(input);
 
   // Verify the sign-in output against the generated input server-side
+  let strPayload = JSON.stringify({ input, output: {
+    account: {
+      address: output.account.address,
+      publicKey: Array.from(output.account.publicKey),
+    },
+    signature: Array.from(output["signature"]),
+    signedMessage: Array.from(output["signedMessage"]),
+  } });
   const verifyResponse = await fetch("/backend/verifySIWS", {
     method: "POST",
-    body: JSON.stringify({ input, output }),
+    body: strPayload,
   });
   const success = await verifyResponse.json();
 

+ 7 - 15
example-dapp/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "@0xproflupin/example-dapp",
+  "name": "@phantom/sign-in-with-solana",
   "version": "1.0.0",
   "description": "Reference implementation of Sign-In With Solana",
   "license": "MIT",
@@ -16,16 +16,17 @@
   ],
   "dependencies": {
     "@solana/wallet-adapter-ant-design": "^0.11.28",
-    "@solana/wallet-adapter-base": "0.9.23-alpha.3",
+    "@solana/wallet-adapter-base": "0.9.23",
     "@solana/wallet-adapter-material-ui": "^0.16.30",
-    "@solana/wallet-adapter-react": "0.15.34-alpha.3",
+    "@solana/wallet-adapter-react": "0.15.34",
     "@solana/wallet-adapter-react-ui": "^0.9.31",
-    "@solana/wallet-standard-features": "1.1.0-alpha.5",
-    "@solana/wallet-standard-util": "1.1.0-alpha.10",
+    "@solana/wallet-standard-features": "1.1.0",
+    "@solana/wallet-standard-util": "1.1.0",
     "@solana/web3.js": "1.63.1",
     "@types/node": "^16.7.13",
     "@types/react": "^18.0.0",
     "@types/react-dom": "^18.0.0",
+    "@@wallet-standard/base": "1.0.1",
     "bs58": "^5.0.0",
     "react": "^17.0.2",
     "react-dom": "^17.0.2",
@@ -68,14 +69,5 @@
     "not dead",
     "not ie <= 11",
     "not op_mini all"
-  ],
-  "resolutions": {
-    "@solana/wallet-adapter-react": "0.15.34-alpha.3",
-    "@solana/wallet-adapter-base": "0.9.23-alpha.3"
-    
-  },
-  "overrides": {
-    "@solana/wallet-adapter-react": "0.15.34-alpha.3",
-    "@solana/wallet-adapter-base": "0.9.23-alpha.3"
-  }
+  ]
 }

+ 25 - 0
example-dapp/src/App.tsx

@@ -225,9 +225,34 @@ const App = () => {
   const autoSignIn = useCallback(async (adapter: Adapter) => {
     if (!('signIn' in adapter)) return true;
 
+    // Fetch the signInInput from the backend
+    /*
+    const createResponse = await fetch("/backend/createSignInData");
+    const input: SolanaSignInInput = await createResponse.json();
+    */
     const input: SolanaSignInInput = await createSignInData();
+
+    // Send the signInInput to the wallet and trigger a sign-in request
     const output = await adapter.signIn(input);
 
+    // Verify the sign-in output against the generated input server-side
+    /*
+    let strPayload = JSON.stringify({ input, output: {
+      account: {
+        address: output.account.address,
+        publicKey: Array.from(output.account.publicKey),
+      },
+      signature: Array.from(output["signature"]),
+      signedMessage: Array.from(output["signedMessage"]),
+    } });
+    const verifyResponse = await fetch("/backend/verifySIWS", {
+      method: "POST",
+      body: strPayload,
+    });
+    const success = await verifyResponse.json();
+    */
+
+    // For demonstration purposes only, this should happen server-side
     if (!verifySignIn(input, output)) {
       console.error('Sign In verification failed!')
       throw new Error('Sign In verification failed!');