Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Accepting more address types in redemption #174

Open
Shadowfiend opened this issue Jan 31, 2020 · 2 comments
Open

Accepting more address types in redemption #174

Shadowfiend opened this issue Jan 31, 2020 · 2 comments
Assignees

Comments

@Shadowfiend
Copy link
Contributor

Shadowfiend commented Jan 31, 2020

EDIT to add: current contracts don't support this. When we bump to the latest tbtc contracts, they do support arbitrary redeemer scripts. We'll need to harmonize what we currently do with that anyway (these scripts require length prefixes, which the current code doesn't ship to the contract) and see what the best way is to support it with bcoin. The rest of the issue remains for now, as it will probably still inform what we end up doing.


Right now, we only accept bech32 p2wpkh addresses in the redemption flow. We should be able to do more than that, with a little bit of massaging of our bcoin invocations.

Here's what we do right now:

const script = bcoin.Script.fromAddress(toBTCAddress)
requesterPKH = script.getWitnessPubkeyhash()

For a p2pkh address, we can do script.getPubkeyhash(). For a p2sh/p2wsh address, it looks like things might be slightly more complicated… From some mucking around in node-land:

> const bcoin = require('bcoin/lib/bcoin-browser')
undefined
> const script = bcoin.Script.fromAddress("2MxLAgs87oBXvkAL6CwYPzBfZkhx4fGagEK")
undefined
> script
Script {
  raw:
   <Buffer a9 14 37 c7 f4 29 35 b0 3d c9 65 a9 91 60 5e 8c 6d 2b 4d 98 c2 a8 87>,
  code:
   [ Opcode { value: 169, data: null },
     Opcode {
       value: 20,
       data:
        <Buffer 37 c7 f4 29 35 b0 3d c9 65 a9 91 60 5e 8c 6d 2b 4d 98 c2 a8> },
     Opcode { value: 135, data: null } ] }

99% sure we just want script.code[1].data, based on the fact that this looks like the structure that we look for in p2wpkh:

> const bloop = bcoin.Script.fromAddress("tb1qjy5pyuaatyurt4wh7mq56kvdz6vlld28zu2np2")
> bloop.code
[ Opcode { value: 0, data: null },
  Opcode {
    value: 20,
    data:
     <Buffer 91 28 12 73 bd 59 38 35 d5 d7 f6 c1 4d 59 8d 16 99 ff b5 47> } ]
> bloop.getWitnessPubkeyhash()
<Buffer 91 28 12 73 bd 59 38 35 d5 d7 f6 c1 4d 59 8d 16 99 ff b5 47>

However, in p2wpkh that's behind an OP_HASH160 opcode and in p2sh it seems to be behind no opcode at all sooo… Yeah, not sure. Probably easiest to just try the thing, tbh 🤷‍♂

@liamzebedee
Copy link
Contributor

Low-key excited for this - I've got a hacked-together local Bitcoin regtest and ElectrumX setup here, and it's currently only blocked by the dApp redemption script requiring a specific network prefix in the address.

@Shadowfiend
Copy link
Contributor Author

Update here: all we need to do is Script.fromAddress, which will either work or not (returning null or not). keep-network/tbtc.js#8 will implement this for tbtc.js, then we'll adjust the validation here briefly.

@mhluongo mhluongo removed the tbtc label Aug 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants