BlockchainCommons / GordianWallet-iOS

iOS wallet linked by Torgap to your own full-node server
Other
47 stars 14 forks source link

Enhanced recovery: custom derivation support and sub account support. #84

Closed Fonta1n3 closed 4 years ago

Fonta1n3 commented 4 years ago

Users may now add a custom derivation path when recovering single sig with words. For example if a user supplies m/0'/0' as a derivation then internally we generate receive keys with m/0'/0'/0/0 and change keys with m/0'/0'/1/0.

If a user is recovering an account with words only we now auto scan each derivation BIP44/84/49 at account 0 address index 0 m/84'/0'/0'/0/0 as BIP84 example to see if the addresses have history on other popular derivations. If they do we will ask the user if they would like to recover the account with history and automate the process for them.

When a user is recovering a single sig account with words only we automatically recover sub accounts 0-9 as a BIP84 example:

# Account 0
m/84'/0'/0'/0/*
m/84'/0'/0'/1/*

# Account 1
m/84'/0'/1'/0/*
m/84'/0'/1'/1/*

# Account 2
m/84'/0'/2'/0/*
m/84'/0'/2'/1/*

# etc... up to Account 9

Account 0 is always added to the keypool whereas the other accounts are for "watching" and not added to the keypool, since we save the account xprv for each they are all spendable, hence it is a recovery account.

If the account already exists on the node we do not do this at is seems pointless, considering they have already got an active account they are obviously trying to recover that specific account, it simply and quickly adds the account locally linking to its counterpart on the node as normal.

We also do not check any sub accounts if they are recovering with an account map as again they clearly already have a specific account they want to recover.

Keep in mind it takes significantly longer to recover 0-9 sub accounts instead of one specific account, 40 rpc commands vs 4.