Răsfoiți Sursa

tweetnacl -> @noble/curves/ed25519

Jordan Sexton 2 ani în urmă
părinte
comite
73e0029d9b

+ 2 - 2
FAQ.md

@@ -124,10 +124,10 @@ The signature string returned by this method can be verified using [tweetnacl-js
 This can be used to sign offline — without sending a transaction — and prove a user controls a given private key.
 
 ```tsx
+import { ed25519 } from '@noble/curves/ed25519';
 import { useWallet } from '@solana/wallet-adapter-react';
 import bs58 from 'bs58';
 import React, { FC, useCallback } from 'react';
-import { sign } from 'tweetnacl';
 
 export const SignMessageButton: FC = () => {
     const { publicKey, signMessage } = useWallet();
@@ -144,7 +144,7 @@ export const SignMessageButton: FC = () => {
             // Sign the bytes using the wallet
             const signature = await signMessage(message);
             // Verify that the bytes were signed using the private key that matches the known public key
-            if (!sign.detached.verify(message, signature, publicKey.toBytes())) throw new Error('Invalid signature!');
+            if (!ed25519.verify(signature, message, publicKey.toBytes())) throw new Error('Invalid signature!');
 
             alert(`Message signature: ${bs58.encode(signature)}`);
         } catch (error: any) {

+ 2 - 2
packages/starter/example/package.json

@@ -39,6 +39,7 @@
         "@emotion/styled": "^11.11.0",
         "@mui/icons-material": "^5.11.16",
         "@mui/material": "^5.13.5",
+        "@noble/curves": "^1.1.0",
         "@solana/wallet-adapter-ant-design": "workspace:^",
         "@solana/wallet-adapter-base": "workspace:^",
         "@solana/wallet-adapter-material-ui": "workspace:^",
@@ -51,8 +52,7 @@
         "next": "^12.3.4",
         "notistack": "^2.0.8",
         "react": "^18.2.0",
-        "react-dom": "^18.2.0",
-        "tweetnacl": "^1.0.3"
+        "react-dom": "^18.2.0"
     },
     "devDependencies": {
         "@types/bs58": "^4.0.1",

+ 3 - 4
packages/starter/example/src/components/SignMessage.tsx

@@ -1,9 +1,9 @@
 import { Button } from '@mui/material';
+import { ed25519 } from '@noble/curves/ed25519';
 import { useWallet } from '@solana/wallet-adapter-react';
 import bs58 from 'bs58';
 import type { FC } from 'react';
 import React, { useCallback } from 'react';
-import { sign } from 'tweetnacl';
 import { useNotify } from './notify';
 
 export const SignMessage: FC = () => {
@@ -17,12 +17,11 @@ export const SignMessage: FC = () => {
 
             const message = new TextEncoder().encode('Hello, world!');
             const signature = await signMessage(message);
-            if (!sign.detached.verify(message, signature, publicKey.toBytes()))
-                throw new Error('Message signature invalid!');
+            if (!ed25519.verify(signature, message, publicKey.toBytes())) throw new Error('Message signature invalid!');
 
             notify('success', `Message signature: ${bs58.encode(signature)}`);
         } catch (error: any) {
-            notify('error', `Message signing failing: ${error?.message}`);
+            notify('error', `Sign Message failed: ${error?.message}`);
         }
     }, [publicKey, signMessage, notify]);
 

+ 1 - 0
packages/wallets/unsafe-burner/package.json

@@ -35,6 +35,7 @@
         "@solana/web3.js": "^1.77.3"
     },
     "dependencies": {
+        "@noble/curves": "^1.1.0",
         "@solana/wallet-adapter-base": "workspace:^"
     },
     "devDependencies": {

+ 9 - 2
packages/wallets/unsafe-burner/src/adapter.ts

@@ -1,6 +1,7 @@
+import { ed25519 } from '@noble/curves/ed25519';
 import type { WalletName } from '@solana/wallet-adapter-base';
 import {
-    BaseSignerWalletAdapter,
+    BaseMessageSignerWalletAdapter,
     isVersionedTransaction,
     WalletNotConnectedError,
     WalletReadyState,
@@ -14,7 +15,7 @@ export const UnsafeBurnerWalletName = 'Burner Wallet' as WalletName<'Burner Wall
  * This burner wallet adapter is unsafe to use and is only included to provide an easy way for applications to test
  * Wallet Adapter without using a third-party wallet.
  */
-export class UnsafeBurnerWalletAdapter extends BaseSignerWalletAdapter {
+export class UnsafeBurnerWalletAdapter extends BaseMessageSignerWalletAdapter {
     name = UnsafeBurnerWalletName;
     url = 'https://github.com/solana-labs/wallet-adapter#usage';
     icon =
@@ -70,4 +71,10 @@ export class UnsafeBurnerWalletAdapter extends BaseSignerWalletAdapter {
 
         return transaction;
     }
+
+    async signMessage(message: Uint8Array): Promise<Uint8Array> {
+        if (!this._keypair) throw new WalletNotConnectedError();
+
+        return ed25519.sign(message, this._keypair.secretKey.slice(0, 32));
+    }
 }