Comment on page
👩💻
UserAuthorization Module
The UserAuthorization module, accessible via
ssx.userAuthorization
, allows developers to ask the end user for signing-related operations. This includes:
- Authentication (using Sign-in with Ethereum),
- User authorizations (delegating to a session key, using ReCap messages) and,
- Accessing capabilities granted by the user.
It's enabled by default, and many methods from this module are already accessible directly from the SSX instance (see Root Methods). However, some methods must be called from the module.
Some of the functions for the UserAuthorization Module are written in Rust and made available to the SSX SDK through WebAssembly. This allows for a more secure and performant implementation of these functions using SpruceID Rust libraries.
The UserAuthorization Module is built using two classes:
UserAuthorizationInit
and UserAuthorizationConnected
. This approach prevents downstream consumers of this module from having to consider and manage WebAssembly in their application.Once you have a SSX object, you can use the UserAuthorization Module to authenticate and authorize users. The UserAuthorization Module is available on the SSX object as
ssx.userAuthorization
after sign-in.Gets the address that is connected and signed in.
address = () => string | undefined;
Here is an example of how to use it:
const address = ssx.userAuthorization.address();
Get the chainId that the address is connected and signed in on.
chainId = () => number | undefined;
Here is an example of how to use it:
const chainId = ssx.userAuthorization.chainId();
Prompts the user to connect their wallet to the application. Once the user has connected their wallet, you can use the UserAuthorization Module to authenticate and authorize the user.
Calling this is optional, as calling
signIn
will automatically connect to the wallet if it is not already connected.connect = () => Promise<void>;
Here is an example of how to use it:
ssx.userAuthorization.connect();
Extends SSX with functions that are called after connecting and signing in.
extend = (extension: SSXExtension) => void;
Here is an example of how to use it:
ssx.userAuthorization.extend(extension);
Gets the provider that is connected and signed in.
getProvider = () => ethers.providers.BrowserProvider | undefined;
Here is an example of how to use it:
const provider = ssx.userAuthorization.getProvider();
Returns the signer of the connected address.
getSigner = () => ethers.Signer | undefined;
Here is an example of how to use it:
const signer = ssx.userAuthorization.getSigner();
Resolve ENS data supported by SSX.
resolveEns = (
address: string,
resolveEnsOpts: {
domain: boolean,
avatar: boolean
}
) => Promise<SSXEnsData>;
Here is an example of how to use it:
const ensData = await ssx.userAuthorization.resolveEns('0xADDRESS', {
domain: true,
avatar: false
});
Resolves Lens profiles owned by the given Ethereum Address. Each request is limited to 10. To get other pages, you must pass the pageCursor parameter.
This feature is available for Polygon Mainnet and Mumbai Testnet. Visit the Lens docs for more information.
resolveLens = (
address: string,
pageCursor: string,
) => Promise<string | SSXLensProfileResponse>;
Here is an example of how to use it:
const lensData = await ssx.userAuthorization.resolveLens('0xADDRESS');
Request the user to sign in and start the session. Returns an object containing information about the session.
signIn = () => Promise<SSXClientSession>;
Here is an example of how to use it:
const session = await ssx.userAuthorization.signIn();
Signs a message using the private key of the connected address and returns the signature.
signMessage = (message: string) => Promise<string>;
Here is an example of how to use it:
const signature = await ssx.userAuthorization.signMessage('message');
Invalidates the user's session.
signOut = () => Promise<void>;
Here is an example of how to use it:
await ssx.userAuthorization.signOut();
Last modified 4mo ago