Sign Messages
Request an off-chain message signature from D9 Wallet and verify it on your server. Message signing does not submit anything on chain and incurs no transaction fee.
Prerequisites: walletRuntime from Quickstart and a connected account.
1. Request a signature
Section titled “1. Request a signature”Pass the signer’s SS58 address and message string to connector.signMessage:
import { Effect } from "effect";import { D9DAppConnector } from "@d9-network/dapp-connector";import { walletRuntime } from "./wallet";
export async function signTermsAcknowledgement(userAddress: string) { return walletRuntime.runPromise( Effect.gen(function* () { const connector = yield* D9DAppConnector; return yield* connector.signMessage({ address: userAddress, message: "I acknowledge and accept the Terms of Service for My D9 DApp.", }); }), );}Returned fields:
| Field | Description |
|---|---|
transport |
'papi' | 'walletconnect' |
address |
SS58 address that produced the signature |
message |
Original message string |
signature |
Hex-encoded signature |
messageHex |
Exact bytes signed |
Calling a raw WalletConnect handle
Section titled “Calling a raw WalletConnect handle”If you invoke a WalletConnect transport handle directly, hex-encode the UTF-8 message first:
import type { D9WalletConnectTransportHandle } from "@d9-network/dapp-connector";import { utf8ToHex, type D9AccountId,} from "@d9-network/dapp-connector/protocol";import { walletRuntime } from "./wallet";
export async function requestRawHexSignature( handle: D9WalletConnectTransportHandle, accountId: D9AccountId, rawUtf8String: string,) { return walletRuntime.runPromise( handle.requestMessage({ account: accountId, message: utf8ToHex(rawUtf8String), }), );}2. Verify the signature on your server
Section titled “2. Verify the signature on your server”Send address, messageHex, and signature to your backend and perform both checks:
- Verify the sr25519 or ed25519 signature over
<Bytes>...</Bytes>—D9 Wallet signs the Substrate-wrapped bytes, not the bare payload. - Confirm that the recovered public key encodes to the claimed SS58 address with prefix
9.
Verify
Section titled “Verify”Both checks succeed for the unmodified payload and fail if even a single character is altered.
