-
Notifications
You must be signed in to change notification settings - Fork 15
[Feature] Add read only invites #20
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,14 +70,27 @@ class AutopassPairer extends ReadyResource { | |
|
|
||
| await this.pass.deleteInvite() | ||
| } | ||
| const readOnly = JSON.parse(result.data.toString()).readOnly | ||
| this.swarm = null | ||
| this.store = null | ||
| if (this.onresolve) this._whenWritable() | ||
| if (this.onresolve && readOnly) { | ||
| this._whenReadable() | ||
| } else if (this.onresolve) { | ||
| this._whenWritable() | ||
| } | ||
| this.candidate.close().catch(noop) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| _whenReadable() { | ||
| const check = () => { | ||
| this.pass.base.off('update', check) | ||
| this.onresolve(this.pass) | ||
| } | ||
| this.pass.base.on('update', check) | ||
| } | ||
|
|
||
| _whenWritable() { | ||
| if (this.pass.base.writable) return | ||
| const check = () => { | ||
|
|
@@ -238,14 +251,20 @@ class Autopass extends ReadyResource { | |
|
|
||
| async createInvite(opts) { | ||
| if (this.opened === false) await this.ready() | ||
| const readOnly = opts?.readOnly ? true : false | ||
| const existing = await this.base.view.findOne('@autopass/invite', {}) | ||
| if (existing) { | ||
| if (this.member) await this.member.flushed() | ||
| return z32.encode(existing.invite) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should check the existing invite to distinguish There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug case
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for flagging, makes sense since invites are deleted only once they are used, let me fix this so the flow is correct.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
| } | ||
| const { id, invite, publicKey, expires } = BlindPairing.createInvite(this.base.key) | ||
| const { id, invite, publicKey, expires, additional } = BlindPairing.createInvite( | ||
| this.base.key, | ||
| { | ||
| data: Buffer.from(JSON.stringify({ readOnly })) | ||
| } | ||
| ) | ||
|
|
||
| const record = { id, invite, publicKey, expires } | ||
| const record = { id, invite, publicKey, expires, readOnly, additional } | ||
| await this.base.append(encode('@autopass/add-invite', record)) | ||
| if (this.member) await this.member.flushed() | ||
| return z32.encode(record.invite) | ||
|
|
@@ -313,11 +332,15 @@ class Autopass extends ReadyResource { | |
| if (inv === null || !b4a.equals(inv.id, id)) { | ||
| return | ||
| } | ||
| const readOnly = inv.readOnly | ||
| candidate.open(inv.publicKey) | ||
| await this.addWriter(candidate.userData) | ||
| if (!readOnly) { | ||
| await this.addWriter(candidate.userData) | ||
| } | ||
| candidate.confirm({ | ||
| key: this.base.key, | ||
| encryptionKey: this.base.encryptionKey | ||
| encryptionKey: this.base.encryptionKey, | ||
| additional: inv.additional | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curios question, why do we need to send this don't see they use it in the other side only see
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. result.data comes from additional field on the other side
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it has information if the invite is read only or not, if it is read only then the base will wait just to check if pass is updating otherwise if its writeable it will wait to check if the pass has become writable before confirming that the device is paired |
||
| }) | ||
| await this.deleteInvite() | ||
| } | ||
|
|
||
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.
curios question,
in the confirm side, we set an object of
{ key, encryptionKey, additional }where is the
result.datacoming from?Uh oh!
There was an error while loading. Please reload this page.
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.
it comes from additional field