@@ -142,30 +142,36 @@ export class SmartAccountConnector {
142142
143143 public async login ( ) : Promise < LoginResult > {
144144 const keyStore = await this . keyStoreService . readDm3KeyStore ( ) ;
145+ console . log ( 'keyStore' , keyStore ) ;
145146 //Smart account has never used dm3 before
146147 if ( Object . keys ( keyStore ) . length === 0 ) {
148+ console . log ( 'signUp' ) ;
147149 return await this . signUp ( ) ;
148150 }
149151 //Smart account has used Dm before. We have to check if the controller has published its public key yet
150- const { encryptionKeyPair, signature } =
151- await this . createEncryptionKeys ( ) ;
152+ console . debug ( 'Starting login process for existing smart account.' ) ;
153+ const { encryptionKeyPair, signature } = await this . createEncryptionKeys ( ) ;
154+ console . debug ( 'Encryption keys created:' , encryptionKeyPair , 'Signature:' , signature ) ;
152155
153156 //Recover the address of the controller from the signature
154- const upControllerAddress =
155- await this . recoverAddressFromEncryptionKeySignature ( signature ) ;
157+ const upControllerAddress = await this . recoverAddressFromEncryptionKeySignature ( signature ) ;
158+ console . debug ( 'Recovered UP controller address from signature:' , upControllerAddress ) ;
156159
157- //Check if the controller has already a ketStore entry
160+ //Check if the controller has already a keyStore entry
158161 const encryptedControllerKeyStore = keyStore [ upControllerAddress ] ;
162+ console . debug ( 'Retrieved encrypted controller key store:' , encryptedControllerKeyStore ) ;
159163
160164 //If the controller already has a keyStore, we can decrypt the profileKeys using its encryptionKeys
161165 //If not we've to start the keyExchange process
162166 if (
163167 ! encryptedControllerKeyStore ||
164168 ! encryptedControllerKeyStore . encryptedProfileKeys
165169 ) {
166- //The signer connected to the UP has not used dm3 before, it has to publish its public key so another device can share the profile keys
170+ console . debug ( 'No existing key store or encrypted profile keys found. Initiating key exchange process.' ) ;
171+ //The signer connected to the UP has not used dm3 before, it has to publish its public key so another device can share the profile keys
167172 return await this . addNewSigner ( keyStore ) ;
168173 }
174+ console . debug ( 'Existing key store and encrypted profile keys found. Proceeding with sign-in for existing signer.' ) ;
169175 //The signer connected to the UP has already used dm3 before, hence it knows the profile
170176 return await this . signInExistingSigner (
171177 encryptionKeyPair ,
@@ -222,15 +228,22 @@ export class SmartAccountConnector {
222228
223229 //Returns Keys to encrypt the actual profile at UP
224230 private async createEncryptionKeys ( ) {
225- //If the user has created its encryption keys before, we can reuse them. That way we don't have to ask the user to sign again
231+ // If the user has created its encryption keys before, we can reuse them. That way we don't have to ask the user to sign again
232+ console . debug ( 'Checking for cached encryption keys.' ) ;
226233 if ( this . cachedEncryptionKeys ) {
234+ console . debug ( 'Cached encryption keys found, returning them.' ) ;
227235 return this . cachedEncryptionKeys ;
228236 }
237+
238+ console . debug ( 'No cached encryption keys found, proceeding to create new ones.' ) ;
229239 const upAddress = await this . keyStoreService . getAccountAddress ( ) ;
240+ console . debug ( 'Retrieved account address:' , upAddress ) ;
241+
230242 const statement =
231243 `Connect the DM3 MESSENGER with your wallet. ` +
232244 `Keys for secure communication are derived from this signature.` +
233245 `(There is no paid transaction initiated. The signature is used off-chain only.)` ;
246+ console . debug ( 'Prepared statement for SiweMessage:' , statement ) ;
234247
235248 const message = new SiweMessage ( {
236249 domain : 'dm3.chat' ,
@@ -240,23 +253,31 @@ export class SmartAccountConnector {
240253 version : '1' ,
241254 chainId : 42 ,
242255 nonce : this . nonce ,
243- //Date is a mandatory property otherwise it'll be DAte .now(). We need it to be constant to create teh encryption keys deterministically
256+ // Date is a mandatory property otherwise it'll be Date .now(). We need it to be constant to create the encryption keys deterministically
244257 issuedAt : new Date ( 978307200000 ) . toISOString ( ) ,
245258 resources : [ 'https://dm3.network' ] ,
246259 } ) ;
260+ console . debug ( 'Created SiweMessage:' , message ) ;
261+ console . debug ( 'this.controller:' , this . controller ) ;
262+ console . debug ( 'message.prepareMessage():' , message . prepareMessage ( ) ) ;
247263
248264 const signature = await this . controller . signMessage (
249265 message . prepareMessage ( ) ,
250266 ) ;
267+ console . debug ( 'Generated signature:' , signature ) ;
268+
251269 const storageKey = await createStorageKey ( signature ) ;
270+ console . debug ( 'Created storage key:' , storageKey ) ;
252271
253272 const keys = await _createProfileKeys ( storageKey , this . nonce ) ;
273+ console . debug ( 'Generated profile keys:' , keys ) ;
254274
255- //Keep the encryptionKeyPair for later use
275+ // Keep the encryptionKeyPair for later use
256276 this . cachedEncryptionKeys = {
257277 encryptionKeyPair : keys . encryptionKeyPair ,
258278 signature : signature ,
259279 } ;
280+ console . debug ( 'Cached encryption keys for future use.' ) ;
260281
261282 return {
262283 encryptionKeyPair : keys . encryptionKeyPair ,
0 commit comments