authorize method

  1. @override
Future<AuthorizeResult> authorize(
  1. AuthorizeParams params, {
  2. bool? onlyIfTrusted,
})

Non-privileged method

This method allows the dApp endpoint to request authorization from the wallet endpoint for access to privileged methods. On success, it returns an AuthorizeResult.authToken providing access to privileged methods, along with addresses and optional labels for all authorized accounts. It may also return a URI suitable for future use as an endpoint-specific URI. After a successful call to authorize, the current session will be placed into an authorized state, with privileges associated with the returned AuthorizeResult.authToken. On failure, the current session with be placed into the unauthorized state.

This AuthorizeResult.authToken may be used to reauthorize future sessions between the dApp and wallet endpoint.

DApp endpoints should make every effort possible to verify the authenticity of the presented identity. While the uri parameter is optional, it is strongly recommended - without it, the wallet endpoint may not be able to verify the authenticity of the dApp.

The cluster parameter allows the dApp endpoint to select a specific Solana cluster with which to interact. This is relevant for both sign_transactions, where a wallet may refuse to sign transactions without a currently valid blockhash, and for sign_and_send_transactions, where the wallet endpoint must know which cluster to submit the transactions to. This parameter would normally be used to select a cluster other than mainnet-beta for dApp development and testing purposes. Under normal circumstances, this field should be omitted, in which case the wallet endpoint will interact with the mainnet-beta cluster.

Implementation

@override
Future<AuthorizeResult> authorize(
  final AuthorizeParams params, {
  final bool? onlyIfTrusted,
}) async {
  SolanaWalletAdapterWeb.platform.addListeners(provider);
  final Map<String, dynamic> response = await provider.connect(onlyIfTrusted: onlyIfTrusted);
  final String address = response[pubkeyKey].toString();
  final AppInfo app = provider.info;
  return AuthorizeResult(
    accounts: [Account.fromBase58(address)],
    authToken: generateAuthToken(),
    walletUriBase: Uri.https(app.host, app.schemePath),
  );
}