Skip to content

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

Description

@serapath

@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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions