3Box accounts have a 3ID identity that they use to authorize and encrypt/decrypt data. In order to authorize, access, and update data saved in a 3Box, you will need to generate an IdentityWallet instance which contains the user's 3ID. There are two primary ways to accomplish this; choose the correct one for your use case:
When an application requests access to the users data, the user normally needs to give consent for this. In order to facilitate this interation IdentityWallet requires a getConsent function that returns true or false depending on if the user approved the application request to access certain spaces.
const getConsent = async ({ type, origin, spaces }) => {// For testing purposes a function that just returns// true can be used. In prodicution systems the user// should be prompted for input.return true}
You should consider generating an IdentityWallet from a seed if your wallet implements a traditional cryptographic key-pair account model.
To create a wallet with a seed you can simply pass it as an option to the constructor. This will create an instance of the IdentityWallet that derives all it's keys from this seed. Be careful, if this seed is lost the identity and all of it's data will be lost as well.
const seed = '0xabc123...' // a hex encoded seedconst idWallet = new IdentityWallet(getConsent, { seed })
This is best for...
Keypair account-based wallets
Node.js applications
Web applications with hosted wallets
You should consider creating an IdentityWallet this way if your wallet implements a contract-based user account mode. This will allow you to associate multiple signing/authentication accounts to the same user identity.
For wallets which doesn't have key-pair accounts/identities, e.g. smart contract wallets, we provide a way of creating an identity with multiple authentication secrets. In this model each authentication secret grants full access to the identity.
const authSecret = '0xabc123...' // a hex encoded secretconst idWallet = new IdentityWallet(getConsent, { authSecret })
This is best for...
Smart contract-based wallets
Sharing 3Box data across multiple signing/auth/eth accounts and contracts