Loading toolkit/components/lox/Lox.sys.mjs +20 −33 Original line number Diff line number Diff line Loading @@ -200,6 +200,15 @@ class LoxImpl { } } /** * Assert that the module is initialized. */ #assertInitialized() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } } get #inuse() { return ( Boolean(this.#activeLoxId) && Loading Loading @@ -267,9 +276,7 @@ class LoxImpl { * if there are no bridges. */ getBridges(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); // Note: this is messy now but can be mostly removed after we have // https://gitlab.torproject.org/tpo/anti-censorship/lox/-/issues/46 let bridgelines = JSON.parse(this.#getCredentials(loxId)).bridgelines; Loading Loading @@ -424,9 +431,7 @@ class LoxImpl { * If either blockages or a levelup happened, add an event to the event queue */ async #backgroundTasks() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); let addedEvent = false; // Only run background tasks for the active lox ID. const loxId = this.#activeLoxId; Loading Loading @@ -529,9 +534,7 @@ class LoxImpl { * @returns {bool} Whether the value passed in was a Lox invitation. */ validateInvitation(invite) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); try { lazy.invitation_is_trusted(invite); } catch (err) { Loading @@ -544,9 +547,7 @@ class LoxImpl { // Note: This is only here for testing purposes. We're going to be using telegram // to issue open invitations for Lox bridges. async requestOpenInvite() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); let invite = await this.#makeRequest("invite", []); lazy.logger.debug(invite); return invite; Loading @@ -559,9 +560,7 @@ class LoxImpl { * @returns {string} The loxId of the associated credential on success. */ async redeemInvite(invite) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getPubKeys(); let request = await lazy.open_invite(JSON.parse(invite).invite); let response; Loading Loading @@ -599,9 +598,7 @@ class LoxImpl { * @returns {string[]} A list of all historical invites. */ getInvites() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); // Return a copy. return structuredClone(this.#invites); } Loading @@ -618,9 +615,7 @@ class LoxImpl { * @returns {string} A valid Lox invitation. */ async generateInvite(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getPubKeys(); await this.#getEncTable(); let level = lazy.get_trust_level(this.#getCredentials(loxId)); Loading Loading @@ -668,9 +663,7 @@ class LoxImpl { * user's credential. */ getRemainingInviteCount(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); return parseInt(lazy.get_invites_remaining(this.#getCredentials(loxId))); } Loading Loading @@ -834,9 +827,7 @@ class LoxImpl { * associated with a user's credential. */ getEventData(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); if (loxId !== this.#activeLoxId) { lazy.logger.warn( `No event data for loxId ${loxId} since it was replaced by ${ Loading @@ -857,9 +848,7 @@ class LoxImpl { * @param {string} loxId - The ID to clear events for. */ clearEventData(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); if (loxId !== this.#activeLoxId) { lazy.logger.warn( `Not clearing event data for loxId ${loxId} since it was replaced by ${ Loading Loading @@ -891,9 +880,7 @@ class LoxImpl { * @returns {UnlockData} - Details about the next unlock. */ async getNextUnlock(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getConstants(); let nextUnlock = JSON.parse( lazy.get_next_unlock(this.#constants, this.#getCredentials(loxId)) Loading Loading
toolkit/components/lox/Lox.sys.mjs +20 −33 Original line number Diff line number Diff line Loading @@ -200,6 +200,15 @@ class LoxImpl { } } /** * Assert that the module is initialized. */ #assertInitialized() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } } get #inuse() { return ( Boolean(this.#activeLoxId) && Loading Loading @@ -267,9 +276,7 @@ class LoxImpl { * if there are no bridges. */ getBridges(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); // Note: this is messy now but can be mostly removed after we have // https://gitlab.torproject.org/tpo/anti-censorship/lox/-/issues/46 let bridgelines = JSON.parse(this.#getCredentials(loxId)).bridgelines; Loading Loading @@ -424,9 +431,7 @@ class LoxImpl { * If either blockages or a levelup happened, add an event to the event queue */ async #backgroundTasks() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); let addedEvent = false; // Only run background tasks for the active lox ID. const loxId = this.#activeLoxId; Loading Loading @@ -529,9 +534,7 @@ class LoxImpl { * @returns {bool} Whether the value passed in was a Lox invitation. */ validateInvitation(invite) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); try { lazy.invitation_is_trusted(invite); } catch (err) { Loading @@ -544,9 +547,7 @@ class LoxImpl { // Note: This is only here for testing purposes. We're going to be using telegram // to issue open invitations for Lox bridges. async requestOpenInvite() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); let invite = await this.#makeRequest("invite", []); lazy.logger.debug(invite); return invite; Loading @@ -559,9 +560,7 @@ class LoxImpl { * @returns {string} The loxId of the associated credential on success. */ async redeemInvite(invite) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getPubKeys(); let request = await lazy.open_invite(JSON.parse(invite).invite); let response; Loading Loading @@ -599,9 +598,7 @@ class LoxImpl { * @returns {string[]} A list of all historical invites. */ getInvites() { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); // Return a copy. return structuredClone(this.#invites); } Loading @@ -618,9 +615,7 @@ class LoxImpl { * @returns {string} A valid Lox invitation. */ async generateInvite(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getPubKeys(); await this.#getEncTable(); let level = lazy.get_trust_level(this.#getCredentials(loxId)); Loading Loading @@ -668,9 +663,7 @@ class LoxImpl { * user's credential. */ getRemainingInviteCount(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); return parseInt(lazy.get_invites_remaining(this.#getCredentials(loxId))); } Loading Loading @@ -834,9 +827,7 @@ class LoxImpl { * associated with a user's credential. */ getEventData(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); if (loxId !== this.#activeLoxId) { lazy.logger.warn( `No event data for loxId ${loxId} since it was replaced by ${ Loading @@ -857,9 +848,7 @@ class LoxImpl { * @param {string} loxId - The ID to clear events for. */ clearEventData(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); if (loxId !== this.#activeLoxId) { lazy.logger.warn( `Not clearing event data for loxId ${loxId} since it was replaced by ${ Loading Loading @@ -891,9 +880,7 @@ class LoxImpl { * @returns {UnlockData} - Details about the next unlock. */ async getNextUnlock(loxId) { if (!this.#initialized) { throw new LoxError(LoxErrors.NotInitialized); } this.#assertInitialized(); await this.#getConstants(); let nextUnlock = JSON.parse( lazy.get_next_unlock(this.#constants, this.#getCredentials(loxId)) Loading