steemit / steem-uri-spec

steem:// signing spec and reference implementation
MIT License
14 stars 13 forks source link

Parsing URIs in browser doesn't work #2

Closed Sekhmet closed 5 years ago

Sekhmet commented 5 years ago

Browsers's URL is not compatible with node's URL. This incompatibility causes steem-uri fail to decode URIs in browser environment.

Node.js:

> new URL('steem://sign/op/WyJ2b3RlIix7InZvdGVyIjoiZm9vIiwiYXV0aG9yIjoiYmFyIiwicGVybWxpbmsiOiJiYXoiLCJ3ZWlnaHQiOjEwMDAwfV0.').host === "sign"
true

Chrome/FF:

> new URL('steem://sign/op/WyJ2b3RlIix7InZvdGVyIjoiZm9vIiwiYXV0aG9yIjoiYmFyIiwicGVybWxpbmsiOiJiYXoiLCJ3ZWlnaHQiOjEwMDAwfV0.').host === "sign"
false

This way decode can't pass this check: https://github.com/steemit/steem-uri-spec/blob/bf4a5a4a9f3ccc7e651a5086fa316d7fa795147a/src/index.ts#L76-L78

Failing example

const resp = steemuri.encodeOp(['vote', {voter: 'foo', author: 'bar', permlink: 'baz', weight: 10000}])
steemuri.decode(resp);