135
136 this._privkey = key;
137 if (browser) localStorage.setItem("keys", JSON.stringify([this._pubkey, key]));
138 return input;139 }
140
141 public generateKeys(): string[] {
129 try {
130 key = nip19.decode(input).data;
131 } catch (error) {
132 return new Error("Failed to decode nsec");133 }
134 }
135
111
112 this._pubkey = key;
113 if (browser) localStorage.setItem("keys", JSON.stringify([key, this._privkey]));
114 return input;115 }
116 public get privkey(): string {
117 if (!this._privkey) return "";
105 try {
106 key = nip19.decode(input).data;
107 } catch (error) {
108 return new Error("Failed to decode npub");109 }
110 }
111
Setters are special methods in JavaScript that override the assignment operator in object properties.
The return value from a set
method will never be usable.
In set
methods, return
statements should only be used for control flow.
Returning actual values will only confuse the readers.
const dataStore = {
_data: null,
set data(value) {
if (this.isValid(value)) {
this._data = value
return true
}
// We're returning false to indicate that
// the `set` was unsuccessful, but this
// return value will *never* be usable.
return false
}
}
const dataStore = {
_data: null,
set data(value) {
if (this.isValid(value)) {
this._data = value
}
}
}
console.log((dataStore.data = 1)) // 1