Merge branch 'feat/solana-signMessage' into main
This commit is contained in:
commit
a99f7d82c8
@ -146,6 +146,47 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const testSignMessage = async (account: string): Promise<IFormattedRpcResponse> => {
|
||||||
|
if (!client || !publicKeys || !session) {
|
||||||
|
throw new Error("WalletConnect Client not initialized properly.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const address = account.split(":").pop();
|
||||||
|
|
||||||
|
if (!address) {
|
||||||
|
throw new Error(`Could not derive Solana address from CAIP account: ${account}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const senderPublicKey = publicKeys[address];
|
||||||
|
|
||||||
|
// Encode message to `UInt8Array` first via `TextEncoder` so we can pass it to `bs58.encode`.
|
||||||
|
const message = bs58.encode(
|
||||||
|
new TextEncoder().encode(`This is an example message to be signed - ${Date.now()}`),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await client.request({
|
||||||
|
topic: session.topic,
|
||||||
|
request: {
|
||||||
|
method: SolanaRpcMethod.SOL_SIGN_MESSAGE,
|
||||||
|
params: {
|
||||||
|
pubkey: senderPublicKey.toBase58(),
|
||||||
|
message,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
method: SolanaRpcMethod.SOL_SIGN_MESSAGE,
|
||||||
|
address,
|
||||||
|
valid: true,
|
||||||
|
result: result.signature,
|
||||||
|
};
|
||||||
|
} catch (error: any) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getSolanaActions = (): AccountAction[] => {
|
const getSolanaActions = (): AccountAction[] => {
|
||||||
const wrapRpcRequest =
|
const wrapRpcRequest =
|
||||||
(rpcRequest: (account: string) => Promise<IFormattedRpcResponse>) =>
|
(rpcRequest: (account: string) => Promise<IFormattedRpcResponse>) =>
|
||||||
@ -168,6 +209,10 @@ export default function App() {
|
|||||||
method: SolanaRpcMethod.SOL_SIGN_TRANSACTION,
|
method: SolanaRpcMethod.SOL_SIGN_TRANSACTION,
|
||||||
callback: wrapRpcRequest(testSignTransaction),
|
callback: wrapRpcRequest(testSignTransaction),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
method: SolanaRpcMethod.SOL_SIGN_MESSAGE,
|
||||||
|
callback: wrapRpcRequest(testSignMessage),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import { AccountBalances, ChainNamespaces, getAllChainNamespaces } from "../help
|
|||||||
|
|
||||||
export enum SolanaRpcMethod {
|
export enum SolanaRpcMethod {
|
||||||
SOL_SIGN_TRANSACTION = "sol_signTransaction",
|
SOL_SIGN_TRANSACTION = "sol_signTransaction",
|
||||||
|
SOL_SIGN_MESSAGE = "sol_signMessage",
|
||||||
}
|
}
|
||||||
interface IContext {
|
interface IContext {
|
||||||
client: Client | undefined;
|
client: Client | undefined;
|
||||||
@ -181,7 +182,9 @@ export function ClientContextProvider({ children }: { children: ReactNode | Reac
|
|||||||
const _session = await client.connect({
|
const _session = await client.connect({
|
||||||
permissions: {
|
permissions: {
|
||||||
blockchain: { chains: [caipChainId] },
|
blockchain: { chains: [caipChainId] },
|
||||||
jsonrpc: { methods: [SolanaRpcMethod.SOL_SIGN_TRANSACTION] },
|
jsonrpc: {
|
||||||
|
methods: [SolanaRpcMethod.SOL_SIGN_TRANSACTION, SolanaRpcMethod.SOL_SIGN_MESSAGE],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
onSessionConnected(_session);
|
onSessionConnected(_session);
|
||||||
|
Loading…
Reference in New Issue
Block a user