-
Notifications
You must be signed in to change notification settings - Fork 0
Plasma Wallet API
This API defines how developers can create and manage a Wallet using Plasma. A Wallet is a place where private user information can be stored. This information is kept encrypted when on disk or stored on the remote server.
The purpose of this API is to abstract the details of synchronizing local and remote copies of your wallet.
Assume a class named Wallet that has the following calls:
This method will configure the wallet to look to a remote host to load and/or save your wallet. By passing null into this call the wallet will stop synchronizing its state with the remote server.
wallet.useBackupServer( hostname )
This call is used to configure the wallet to keep a local copy on disk. This allows the user to access the wallet even if the server is no longer available. This option can be disabled on public computers where the wallet data should never touch disk and should be deleted when the user logs out.
wallet.keepLocalCopy( save = true )
This method is used to configure the wallet to save its data on the remote server. If this is set to false, then it will be removed from the server. If it is set to true, then it will be uploaded to the server. If the wallet is not currently saved on the server a token will be required to allow the creation of a new wallet.
wallet.keepRemoteCopy( save = true, token = null )
This API call is used to load the wallet. If a backup server has been specified then it will attempt to fetch the latest version from the server, otherwise it will load the local wallet into memory. The configuration set by keepLocalCopy will determine whether or not the wallet is saved to disk as a side effect of logging in.
wallet.login( username, password )
This API call will remove the wallet state from memory.
wallet.logout()
This method returns a JSON object representing the state of the wallet. It is only valid if the wallet has successfully logged in.
wallet.getState()
This method is used to update the wallet state. If the wallet is configured to keep synchronized with the remote wallet then it will perform the following steps to ensure that two clients to attempt to modify the state at the same time:
- fetch the current wallet from the server
- verify that the local wallet state is the same as the remote server or "fail" by throwing execption
- store the new value on the server on the condition that the server's current state equals the prior state. This verification will have to be performed on the server where it can do an atomic update. The call to the server should fail if the state has been changed by another client.
- after successfully storing the state on the server, save the state to local memory, and optionally disk.
wallet.setState( state )