Overview
Wallet Connect V2 client forked from github.com/Orange-Wallet/wallet-connect-dart and heavily extended and tested.
Completed APIs as per the spec:
- Core API
- Crypto API
- Pairing API
- Relay API
- Store API
- Sign API
Pieces that need to be completed:
- Example project and dapp
- General explanation on how to use the library
- Publish to dart pub
- Reduce number of crypto libraries used for encryption, shared key, etc.
- Auth API
- Push API
To Use
Setup
The following code provides an example for setting up the wallet connect client.
import 'package:wallet_connect_v2/wallet_connect_v2.dart';
SignClient wcClient = await SignClient.createInstance(
Core(
'wss://relay.walletconnect.com', // The relay websocket URL
'123', // The project ID
),
self: PairingMetadata(
'Wallet (Responder)',
'A wallet that can be requested to sign transactions',
'https://walletconnect.com',
['https://avatars.githubusercontent.com/u/37784886'],
),
);
Pair, Approve, and Sign
Now that you have a wallet connect client, you can pair with a dApp, approve a session and sign from the wallet.
dApp Flow
// For a dApp, you would connect with specific parameters, then display
// the returned URI.
ConnectResponse resp = await wcClient.connect(
ConnectParams(
requiredNamespaces: {
'eip155': RequiredNamespace(
chains: ['eip155:1'], // Ethereum chain
methods: ['eth_signTransaction'], // Requestable Methods
),
'kadena': RequiredNamespace(
chains: ['kadena:1'], // Kadena chain
methods: ['quicksign'], // Requestable Methods
),
}
)
)
Uri? uri = resp.uri;
// Once you've display the URI, you can wait for the future, and hide the QR code once you've received session data
final SessionData session = await resp.session.future;
// Now that you have a session, you can request signatures
final sig = await wcClient.request(
RequestParams(
topic: session.topic,
request: WcSessionRequestRequest(
chainId: 'eip155',
method: 'eth_signTransaction',
params: 'transaction',
),
),
);
Wallet Flow
// For a wallet, setup the proposal handler that will display the proposal to the user after the URI has been scanned.
late int id;
wcClient.onSessionProposal.subscribe((SessionProposal? args) async {
// Handle UI updates using the args.params
// Keep track of the args.id for the approval response
id = args!.id;
})
// Also setup the methods and chains that your wallet supports
final handler = (dynamic params) async {
return 'signed!';
};
wcClient.registerRequestHandler(
'eip155:1',
'eth_signTransaction',
handler,
);
// Then, scan the QR code and parse the URI, and pair with the dApp
// On the first pairing, you will immediately recieve a onSessionProposal request.
Uri uri = Uri.parse(scannedUriString);
await wcClient.pair(PairParams(uri: uri));
// Present the UI to the user, and allow them to reject or approve the proposal
final walletNamespaces = {
'eip155:1': Namespace(
accounts: ['abc'],
methods: ['eth_signTransaction'],
),
'kadena': Namespace(
accounts: ['k:abc'],
methods: ['sign', 'quicksign'],
),
}
await wcClient.approve(
ApproveParams(
id: id,
namespaces: walletNamespaces // This will have the accounts requested in params
)
);
// Or to reject...
await wcClient.reject(
RejectParams(
id: id,
reason: "Thou shall not pass!"
)
);
// Your wallet is setup and ready to go!
A wallet exposes different methods for different chains using the request
function. To register functions that will immediately respond to different requests you must call the
To Test
- Pull this repo and set it up: github.com/WalletConnect/relay
Build using make dev, docker must be open.
Install dependencies using npm install.
Run it using this command: PORT=5555 npm run start
.
- Run
flutter test
Libraries
- apis/core/core
- apis/core/crypto/crypto
- apis/core/crypto/crypto_models
- apis/core/crypto/crypto_utils
- apis/core/crypto/i_crypto
- apis/core/crypto/i_crypto_utils
- apis/core/i_core
- apis/core/key_chain/i_key_chain
- apis/core/key_chain/key_chain
- apis/core/pairing/expirer
- apis/core/pairing/i_expirer
- apis/core/pairing/i_json_rpc_history
- apis/core/pairing/i_pairing
- apis/core/pairing/i_pairing_store
- apis/core/pairing/json_rpc_history
- apis/core/pairing/pairing
- apis/core/pairing/pairing_models
- apis/core/pairing/pairing_store
- apis/core/pairing/pairing_utils
- apis/core/relay_auth/i_relay_auth
- apis/core/relay_auth/relay_auth
- apis/core/relay_auth/relay_auth_constants
- apis/core/relay_auth/relay_auth_models
- apis/core/relay_client/i_message_tracker
- apis/core/relay_client/i_relay_client
- apis/core/relay_client/i_topic_map
- apis/core/relay_client/message_tracker
- apis/core/relay_client/relay_client
- apis/core/relay_client/relay_client_models
- apis/core/relay_client/topic_map
- apis/core/store/get_storage_store
- apis/core/store/i_store
- apis/core/store/i_store_user
- apis/models/basic_errors
- apis/models/json_rpc_error
- apis/models/json_rpc_request
- apis/models/json_rpc_response
- apis/signing_api/engine
- apis/signing_api/i_engine
- apis/signing_api/i_proposals
- apis/signing_api/i_sessions
- apis/signing_api/i_sign_client
- apis/signing_api/models/generic_models
- apis/signing_api/models/json_rpc_models
- apis/signing_api/models/proposal_models
- apis/signing_api/models/session_models
- apis/signing_api/models/sign_client_models
- apis/signing_api/models/signing_models
- apis/signing_api/proposals
- apis/signing_api/sessions
- apis/signing_api/sign_client
- apis/signing_api/utils/namespace_utils
- apis/signing_api/utils/validator_utils
- apis/utils/constants
- apis/utils/errors
- apis/utils/rpc_constants
- apis/utils/wallet_connect_utils
- wallet_connect_v2