I am working with the RegisterUser class which contains various methods and properties:
class RegisterUser {
constructor(username, password, ispublic){
this.username = username;
this.password = password;
this.ispublic = ispublic;
this.identity = crypto.signKey();
this.preKeys = [];
if (ispublic){
this.preKeys = crypto.getPreKeys(10);
}
}
get data(){
return {
identity_key: this.identity.publicKey,
username: this.username,
usernameSignature: this.usernameSignature,
signedPreKeys: this.signedPreKeys,
ispublic: this.ispublic
}
}
get usernameSignature(){
return this.identity.sign(Buffer.from(this.username, 'utf8'));
}
signPreKey(key){
var publicKey = key.publicKey;
var signature = this.identity.sign(publicKey);
return {
publicKey: publicKey,
signature: signature
}
}
get signedPreKeys(){
var signFunc = this.signPreKey;
return this.preKeys ? this.preKeys.map(signFunc) : null;
}
get encryptedIdentity(){
var cipher = ncrypto.createCipher('aes192', this.password);
var encrypted = Buffer.concat([Buffer.from(cipher.update(this.identity.secretKey)), Buffer.from(cipher.final())]);
return encrypted;
}
}
However, when I call .data()
on a new instance of this class, I encounter an issue:
I receive the error message "Cannot read property 'identity' of undefined" in the signPreKey function.
Is there a way to utilize .map
without replacing the context of this
? Any suggestions would be greatly appreciated!