-
Notifications
You must be signed in to change notification settings - Fork 17
chore: enforce prettier configuration #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lpatiny
wants to merge
1
commit into
meshcore-dev:master
Choose a base branch
from
lpatiny:neighbours
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "arrowParens": "always", | ||
| "semi": true, | ||
| "singleQuote": true, | ||
| "tabWidth": 2, | ||
| "trailingComma": "all" | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,101 +1,97 @@ | ||
| import BufferReader from "./buffer_reader.js"; | ||
| import BufferWriter from "./buffer_writer.js"; | ||
| import BufferReader from './buffer_reader.js'; | ||
| import BufferWriter from './buffer_writer.js'; | ||
|
|
||
| class Advert { | ||
|
|
||
| static ADV_TYPE_NONE = 0; | ||
| static ADV_TYPE_CHAT = 1; | ||
| static ADV_TYPE_REPEATER = 2; | ||
| static ADV_TYPE_ROOM = 3; | ||
|
|
||
| static ADV_LATLON_MASK = 0x10; | ||
| static ADV_BATTERY_MASK = 0x20; | ||
| static ADV_TEMPERATURE_MASK = 0x40; | ||
| static ADV_NAME_MASK = 0x80; | ||
|
|
||
| constructor(publicKey, timestamp, signature, appData) { | ||
| this.publicKey = publicKey; | ||
| this.timestamp = timestamp; | ||
| this.signature = signature; | ||
| this.appData = appData; | ||
| this.parsed = this.parseAppData(); | ||
| } | ||
|
|
||
| static fromBytes(bytes) { | ||
|
|
||
| // read bytes | ||
| const bufferReader = new BufferReader(bytes); | ||
| const publicKey = bufferReader.readBytes(32); | ||
| const timestamp = bufferReader.readUInt32LE(); | ||
| const signature = bufferReader.readBytes(64); | ||
| const appData = bufferReader.readRemainingBytes(); | ||
|
|
||
| return new Advert(publicKey, timestamp, signature, appData); | ||
|
|
||
| } | ||
|
|
||
| getFlags() { | ||
| return this.appData[0]; | ||
| } | ||
|
|
||
| getType() { | ||
| const flags = this.getFlags(); | ||
| return flags & 0x0F; | ||
| static ADV_TYPE_NONE = 0; | ||
| static ADV_TYPE_CHAT = 1; | ||
| static ADV_TYPE_REPEATER = 2; | ||
| static ADV_TYPE_ROOM = 3; | ||
|
|
||
| static ADV_LATLON_MASK = 0x10; | ||
| static ADV_BATTERY_MASK = 0x20; | ||
| static ADV_TEMPERATURE_MASK = 0x40; | ||
| static ADV_NAME_MASK = 0x80; | ||
|
|
||
| constructor(publicKey, timestamp, signature, appData) { | ||
| this.publicKey = publicKey; | ||
| this.timestamp = timestamp; | ||
| this.signature = signature; | ||
| this.appData = appData; | ||
| this.parsed = this.parseAppData(); | ||
| } | ||
|
|
||
| static fromBytes(bytes) { | ||
| // read bytes | ||
| const bufferReader = new BufferReader(bytes); | ||
| const publicKey = bufferReader.readBytes(32); | ||
| const timestamp = bufferReader.readUInt32LE(); | ||
| const signature = bufferReader.readBytes(64); | ||
| const appData = bufferReader.readRemainingBytes(); | ||
|
|
||
| return new Advert(publicKey, timestamp, signature, appData); | ||
| } | ||
|
|
||
| getFlags() { | ||
| return this.appData[0]; | ||
| } | ||
|
|
||
| getType() { | ||
| const flags = this.getFlags(); | ||
| return flags & 0x0f; | ||
| } | ||
|
|
||
| getTypeString() { | ||
| const type = this.getType(); | ||
| if (type === Advert.ADV_TYPE_NONE) return 'NONE'; | ||
| if (type === Advert.ADV_TYPE_CHAT) return 'CHAT'; | ||
| if (type === Advert.ADV_TYPE_REPEATER) return 'REPEATER'; | ||
| if (type === Advert.ADV_TYPE_ROOM) return 'ROOM'; | ||
| return null; | ||
| } | ||
|
|
||
| async isVerified() { | ||
| const { ed25519 } = await import('@noble/curves/ed25519'); | ||
|
|
||
| // build signed data | ||
| const bufferWriter = new BufferWriter(); | ||
| bufferWriter.writeBytes(this.publicKey); | ||
| bufferWriter.writeUInt32LE(this.timestamp); | ||
| bufferWriter.writeBytes(this.appData); | ||
|
|
||
| // verify signature | ||
| return ed25519.verify( | ||
| this.signature, | ||
| bufferWriter.toBytes(), | ||
| this.publicKey, | ||
| ); | ||
| } | ||
|
|
||
| parseAppData() { | ||
| // read app data | ||
| const bufferReader = new BufferReader(this.appData); | ||
| const flags = bufferReader.readByte(); | ||
|
|
||
| // parse lat lon | ||
| var lat = null; | ||
| var lon = null; | ||
| if (flags & Advert.ADV_LATLON_MASK) { | ||
| lat = bufferReader.readInt32LE(); | ||
| lon = bufferReader.readInt32LE(); | ||
| } | ||
|
|
||
| getTypeString() { | ||
| const type = this.getType(); | ||
| if(type === Advert.ADV_TYPE_NONE) return "NONE"; | ||
| if(type === Advert.ADV_TYPE_CHAT) return "CHAT"; | ||
| if(type === Advert.ADV_TYPE_REPEATER) return "REPEATER"; | ||
| if(type === Advert.ADV_TYPE_ROOM) return "ROOM"; | ||
| return null; | ||
| } | ||
|
|
||
| async isVerified() { | ||
|
|
||
| const { ed25519 } = await import("@noble/curves/ed25519"); | ||
|
|
||
| // build signed data | ||
| const bufferWriter = new BufferWriter(); | ||
| bufferWriter.writeBytes(this.publicKey); | ||
| bufferWriter.writeUInt32LE(this.timestamp); | ||
| bufferWriter.writeBytes(this.appData); | ||
|
|
||
| // verify signature | ||
| return ed25519.verify(this.signature, bufferWriter.toBytes(), this.publicKey); | ||
|
|
||
| } | ||
|
|
||
| parseAppData() { | ||
|
|
||
| // read app data | ||
| const bufferReader = new BufferReader(this.appData); | ||
| const flags = bufferReader.readByte(); | ||
|
|
||
| // parse lat lon | ||
| var lat = null; | ||
| var lon = null; | ||
| if(flags & Advert.ADV_LATLON_MASK){ | ||
| lat = bufferReader.readInt32LE(); | ||
| lon = bufferReader.readInt32LE(); | ||
| } | ||
|
|
||
| // parse name (remainder of app data) | ||
| var name = null; | ||
| if(flags & Advert.ADV_NAME_MASK){ | ||
| name = bufferReader.readString(); | ||
| } | ||
|
|
||
| return { | ||
| type: this.getTypeString(), | ||
| lat: lat, | ||
| lon: lon, | ||
| name: name, | ||
| }; | ||
|
|
||
| // parse name (remainder of app data) | ||
| var name = null; | ||
| if (flags & Advert.ADV_NAME_MASK) { | ||
| name = bufferReader.readString(); | ||
| } | ||
|
|
||
| return { | ||
| type: this.getTypeString(), | ||
| lat: lat, | ||
| lon: lon, | ||
| name: name, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export default Advert; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codebase is already formatted with tab width 4. Keeping that will significantly reduce the number of changes you're trying to make all at once.