Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIP: Canonical, Deterministic Wallet & XPub IDs #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coolaj86
Copy link

@coolaj86 coolaj86 commented Jul 14, 2023

Defines a 64-bit Wallet ID (and encodings) for applications that manage multiple Wallets Phrases.

Also provides an alternate HD Key ID, as Hierarchical Deterministic Wallets: Key Identifiers actually recommends NOT using their 32-bit fingerprint for these types of scenarios (and ripemd160 is weak and deprecated).

Preview

https://github.com/dashhive/DIPs/blob/aj-wallet-fingerprint/aj-wallet-id.md

Example

Wallet

Wallet Phrase:

zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong

Wallet Salt:

TREZOR

Wallet ID

Base64Url:  ZoR59UQ1QPA          (11 characters)
64-Bit Int: 7387163383112745200  (8 bytes)
Hex:        668479f5443540f0     (16 characters)
CB32:       CT27KXA46N0F0        (13 characters)

HD Key (a.k.a. X Key, a.k.a. XPub)

Wallet ZoR59UQ1QPA @ m/44'/5'/0'/0:

XPrv: xprvA2L7qar7dyJNhxnE47gK5J6cc1oEHQuAk8WrZLnLeHTtnkeyP4w6E
          o6Tt65trtdkTRtx8opazGnLbpWrkhzNaL6ZsgG3sQmc2yS8AxoMjfZ

XPub: xpub6FKUF6P1ULrfvSrhA9DKSS3MA3digsd27MSTMjBxCczsfYz7vcFLn
          bQwjP9CsAfEJsnD4UwtbU43iZaibv4vnzQNZmQAVcufN4r3pva8kTz

XPub ID:

64-Bit Int: 13572668744561724463
Hex:        bc5bce4fe5a60c2f
CB32:       QHDWWKZ5MR62Y
Base64Url:  vFvOT-WmDC8

In Pseudocode

let seedBytes = await DashPhrase.toSeed(phrase, salt);
let walletKey = await DashHd.fromSeed(seedBytes);
let xpubBytes = await DashHd.toXPubBytes(walletKey);
let hashBytes = await crypto.subtle.digest("SHA-256", xpubBytes);
let idBytes = hashBytes.slice(0, 8);

let id = bytesToBase64Url(idBytes);
let idBase32Crock = base32crockford.encode(idBytes);
let idHex = bytesToHex(idBytes);
let idInt64 = BigInt(`0x${idHex}`);
let hdkey = await DashHd.fromXKey(xkey);
let xpubBytes = await DashHd.toXPubBytes(hdkey);
let hashBytes = await crypto.subtle.digest("SHA-256", xpubBytes);
let idBytes = hashBytes.slice(0, 8);

let id = bytesToBase64Url(idBytes);
let idBase32Crock = base32crockford.encode(idBytes);
let idHex = bytesToHex(idBytes);
let idInt64 = BigInt(`0x${idHex}`);

Implementation

@coolaj86 coolaj86 changed the title WIP-DIP: Canonical, Deterministic Wallet IDs DIP: Canonical, Deterministic Wallet IDs Jul 14, 2023
@coolaj86 coolaj86 force-pushed the aj-wallet-fingerprint branch 3 times, most recently from c177474 to 63d2201 Compare July 15, 2023 05:41
@coolaj86 coolaj86 changed the title DIP: Canonical, Deterministic Wallet IDs DIP: Canonical, Deterministic Wallet & XPub IDs Jul 15, 2023
@coolaj86
Copy link
Author

coolaj86 commented Jul 15, 2023

Note: the methodology has been simplified to use the HD Key as the basis of the ID for both the Wallet Phrase and the XPub / XPrv use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant