Skip to content
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

what is the message format used to communicate directly over .postMessage()? #2

Open
1 task
Tracked by #1
serapath opened this issue Aug 26, 2019 · 0 comments
Open
1 task
Tracked by #1

Comments

@serapath
Copy link
Member

serapath commented Aug 26, 2019

@todo

  • implement message format and tests to check for correct messages

Maybe any valid message could look like:

onmessage = event => {
  const [lid, from, path, ref, type, body] = event.data
  console.log(from)
  // => e.g. `/wallet` or `/wallet/data-wallet-feature`? or any other capability
  console.log(type) // => e.g. `"error"`, `"pay"`, `"get"` ... (meaning depends on `path`)
  console.log(path)
  // => e.g.`/dapp` or `/dapp/marketplace` or any other feature of the dapp
  console.log(from, lid) // uniquely identifies a message
  console.log(lid) // => lid>0, probably just a counter maintained by code around `from`
    // it can be used by a sender to specifically "replay" to a previously received message
  console.log(ref) // => a `lid` or a previous message where `from` was `path`
  console.log(body) // => any kind of data that makes sense in the context of `type` & `path`
}

example scenarios

  1. dapp requests payment confirmation from wallet and returns transaction response
  2. or dapp listens to events and wallet sends a lot of "responses" over time every time
  3. user revokes access in wallet and it sends a message about revoked access to dapp
  4. ....

"communication" - depending on wallet features - could be initiated by either:

  1. the dapp
  2. the wallet

every "protocol type" involves a certain amount of messages passing back and forth depending on what the communication is about and can be initiated and/or terminated by any party

so whether:

  1. an API (list of methods/commands/querys/...) the wallet understands
  2. an API (list of methods/commands/querys/...) the dapp understands

each method/command/query/... would:

  1. start with a message
  2. followed by 0 or more messages going back and forth
  3. until success or fail or e.g. in case of subscribing to an event, this might go on forever...
@serapath serapath mentioned this issue Aug 26, 2019
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant