@Denis Davidyuk Just to make sure the meeting conclusion is right. Re writing them here.
Subhod: With Current implementation aepp
can never really operate offline without Node information since preparing tx depends on this.client.api.getAccountNextNonce
Node API. We propose 2 new methods for the wallet.
1. getAccountNextNonce
2. getNetworkId()
Denis: Apart of this, Aepp needs Node details for other actions like displaying transaction data, querying contacts. Hence Aepp can never stay offline but it can request Node connection details from the wallet and wallet may share it.
Conclusion: Introduce a new method getNodesInPool
to the wallet standard. Aepp developers can use this API to get Node details and don’t have to worry about maintaining own nodes. Wallet may wan’t to share the details or reject the request. Aepp shall handle it accordingly.
Draft proposal for simplified wallet integration:
Conventions:
- SDK instance naming: ae/aex/aeInstance/aex/aeSdk/aeSdkInstance
- Wallet sub-instance: ae.wallet/aeInstance.wallet/*.wallet
Specification:
The wallet may be connected to Aeternity nodes or it’s offline.
If connected then the wallet may construct the SDK instance using RpcWallet class and Aepp can easily use RpcAepp class without the Node configuration.
wallet = await RpcWallet({
compilerUrl: compilerUrl,
accounts: [genesisAccount],
nodes: [{ name: 'local', instance: node }],
name: 'Wallet',
....
})
aepp = await RpcAepp({
name: 'AEPP'
})
If wallet is not connected to any node then aepp can use the SDK class RpcAepp
with Node configuration
aepp = await RpcAepp({
name: 'AEPP',
nodes: [
{name: 'ae_mainnet', instance: await Node({url: this.MAINNET_URL})},
{name: 'ae_uat', instance: await Node({url: this.TESTNET_URL})}
],
compilerUrl: this.COMPILER_URL,)
const signedTx = wallet.sign({tx}) // wallet interaction
aepp.sendTransaction({signedTx}) // Node interaction
Methods
-
connect: Connection request from aepp to wallet.
request: {'version': 1}
response:
- {'mode': 'bridge', 'networkId': .., 'accounts':[...], node:{Node:{...}
- {'mode': 'detach', 'accounts':[..]}
Note on modes.
- detach: offline wallet. Node/networkId is determined by the Aepp. Transactions can only be signed and not broadcasted.
- bridge: Wallet is connected to Node. Node/networkId is determined by the wallet. Transactions are signed and broadcast to the network.
import AeWallet from '@aeternity/aepp-sdk/es/ae/wallet'
import RpcAepp from '@aeternity/aepp-sdk'
const aepp = await RpcAepp({
name: 'AEPP'})
const wallet = AeWallet.connect(walletInfo)
-
sign: Ask the wallet to sign the transaction.
request: {'tx': ..., account:..}
response: {'signature': ..}
-
sendTransaction: Ask the wallet to sign and broadcast the transaction.
request: {'tx': ..., account:..}
response: {'txHash': ..}
const txHash = wallet.sendTransaction({tx, account: wallet.currentAccount})
-
disconnect: Disconnect wallet
wallet.disconnect()
-
getNodesInPool: Get Node Information from the wallet. The wallet may share the Node details.
wallet.getNodesInPool()
aepp
can use this Node data to communicate with the desired Aeternity network.
Backwards Compatibility
The existing subscribe/notification methods can be continued to be used in the same format.
Current connect, sign, sendTransaction, disconnect
will be marked as deprecated over the new methods.
Edit 1:
Nonce management
It’s important to address how the account nonce will be managed. SDK has an option nativeMode
to choose the preferred transaction build platform, use SDK to build if set to true, use Aeternity node otherwise. Current implementation still depends on the node API getAccountNextNonce
to build the transaction even when nativeMode
is set true.