vulpemventures / marina

Liquid Wallet browser extension
MIT License
37 stars 19 forks source link

Custom deterministic BIP32 derivation path for imported script templates #319

Closed louisinger closed 2 years ago

louisinger commented 2 years ago

related to https://github.com/vulpemventures/marina/issues/250

We need an util function creating an index from namespace + templates. It lets to create a deterministic account index with custom external and internal script types. m/ toUint32(tagged_sha256("marina", namespace/template/templateForChange>)[:4])' / 0 / 0

tiero commented 2 years ago

cc/ @altafan

we realized would be best to put the templates (internal, external) and a prefix for marina to try to be more unique. Thoughts?

tiero commented 2 years ago

Look into this standard from trezor used for login into websites

https://github.com/satoshilabs/slips/blob/master/slip-0013.md#hd-structure

TL;DR

We can tkae the namespace string, make an hash 128bit and split in 4 pieces of 32bit and do the following m/ A' / B' / C' / D' / <chain> / <index>

altafan commented 2 years ago

we realized would be best to put the templates (internal, external) and a prefix for marina to try to be more unique. Thoughts?

This doesn't solve the problem. The problem is not the uniqueness of the hash result, but rather the uniqueness of its first X bytes.

For me, the namespace alone would be enough to guarantee no collisions between hashes as long as every account has a unique name.

The real problem is that while it is true that hash(x) == hash(y) if and only if x == y, it does not stand for a subset of those results, like:

a = hash(x)
b = hash(y)

a[0:4] == b[0:4] even if x != and therefore a != b

The last solution works for sure because it uses the whole hash result as part of the derivation path, therefore we are sure every namespace generates a unique derivation path.

We should definitely go for it, and the fact that is a standard is great for compatibility with other services in the future.

tiero commented 2 years ago

the fact that is a standard

Its a "new" standard anyway, we are just using their solution for the hashing namespace. ie. they use it for login, we use to anchor specific template script.