Skip to content

Function crypto_sign_ed25519_sk_to_curve25519, from_string are not implemented #105

@kaladivo

Description

@kaladivo

The function is exported by the library but it is not implemented. This is very confusing since the error is thrown when calling that function (even though it's exported)....

Might be a good idea to either not export it, or actually implement it.

I found a workaround, that can be used in the meantime:

function privateKeyToCurve25519Fallback(
  ed25519PrivateKey: Uint8Array
): Uint8Array {
  if (ed25519PrivateKey.length < 32) {
    throw new Error('Invalid Ed25519 private key length')
  }

  const hash = sha512(ed25519PrivateKey.subarray(0, 32))
  const curve25519PrivateKey = new Uint8Array(hash.subarray(0, 32))

  curve25519PrivateKey[0] &= 248
  curve25519PrivateKey[31] &= 127
  curve25519PrivateKey[31] |= 64

  return curve25519PrivateKey
}

The same is true for from_string functions.

again the workaround might simply be:

sodium.from_string(message) // THIS DOES NOT WORK
Buffer.from(message, 'utf-8') // THIS WORKS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions