Skip to content

Instantly share code, notes, and snippets.

@shea256
Last active February 3, 2023 17:15
Show Gist options
  • Save shea256/e0b09f82f8b4408fdf9ee74f7a5febbd to your computer and use it in GitHub Desktop.
Save shea256/e0b09f82f8b4408fdf9ee74f7a5febbd to your computer and use it in GitHub Desktop.
import * as secp from '@noble/secp256k1'
import { hkdf } from '@noble/hashes/hkdf'
import { sha256 } from '@noble/hashes/sha256'

function makeSharedSecret(priv: Uint8Array, pub: Uint8Array, i: number) : Uint8Array {
  const secretNumber = secp.getSharedSecret(priv, pub, true).slice(1,33)
  const salt = ""
  const keyInfo = String(i)
  const keyLength = 64

  const derivedKey = hkdf(sha256, String(secretNumber), salt, info, keyLength)
  
  return derivedKey
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment