Create a EOA or SCW signer
This code defines two functions that convert different types of Ethereum accounts—Externally Owned Accounts (EOAs) and Smart Contract Wallets (SCWs)—into a unified Signer
interface.
This ensures that both account types conform to a common interface for message signing and deriving shared secrets as per MLS (Message Layer Security) requirements. SigningKey
now supports only one sign method: sign(signatureText: String): SignedData
.
Create an EOA signer
For an EOA, the convertEOAToSigner
function creates a signer that can get the account identity and sign messages and has placeholder methods for chain ID and block number.
import type { Signer } from "@xmtp/browser-sdk";
const accountIdentity = {
kind: "ETHEREUM", // Specifies the identity type
identifier: "0x...", // Ethereum address as the identifier
};
const signer: Signer = {
getIdentity: () => accountIdentity,
signMessage: async (message) => {
// return value from a signing method here
},
};
Create an SCW signer
For an SCW, the convertSCWToSigner
function similarly creates a signer but includes a specific implementation for chain ID and an optional block number computation.
import type { Signer } from "@xmtp/browser-sdk";
const accountIdentity = {
kind: "ETHEREUM", // Specifies the identity type
identifier: "0x...", // Smart Contract Wallet address
};
const signer: Signer = {
getIdentity: () => accountIdentity,
signMessage: async (message) => {
// return value from a signing method here
},
// These methods are required for smart contract wallets
getBlockNumber: () => undefined, // Optional block number
getChainId: () => BigInt(8453), // Example: Base chain ID
};