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

feat: add toId(hdkey) #33

Closed
coolaj86 opened this issue Jul 15, 2023 · 0 comments
Closed

feat: add toId(hdkey) #33

coolaj86 opened this issue Jul 15, 2023 · 0 comments

Comments

@coolaj86
Copy link
Member

coolaj86 commented Jul 15, 2023

As per dashpay/dips#134 (comment).

DashHd.toIdBytes = async function (hdkey) {
  let xpubBytes = await DashHd.toXPubBytes(hdkey);

  let hashBytes = await crypto.subtle.digest("SHA-256", xpubBytes)
  let idBytes = hashBytes.slice(0, 8);
  return idBytes;
}

let hdkey = await DashHd.fromXKey(xkey);
let idBytes = DashHd.toIdBytes(hdkey);

let id = bytesToBase64Url(idBytes);
let idBase32Crock = base32crockford.encode(idBytes);
let idHex = DashKeys.utils.bytesToHex(idBytes);
let idInt64 = BigInt(`0x${idHex}`);
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

No branches or pull requests

1 participant