seckey.mx raw

   1  // Copyright (c) 2013-2016 The btcsuite developers
   2  // Use of this source code is governed by an ISC
   3  // license that can be found in the LICENSE file.
   4  
   5  package btcec
   6  
   7  import (
   8  	"smesh.lol/pkg/nostr/ec/secp256k1"
   9  )
  10  
  11  // SecretKey wraps an ecdsa.SecretKey as a convenience mainly for signing things with the secret key without having to
  12  // directly import the ecdsa package.
  13  type SecretKey = secp256k1.SecretKey
  14  
  15  // PrivateKey wraps an ecdsa.SecretKey as a convenience mainly for signing things with the secret key without having to
  16  // directly import the ecdsa package.
  17  //
  18  // Deprecated: use SecretKey - secret = one person; private = two or more (you don't share secret keys!)
  19  type PrivateKey = SecretKey
  20  
  21  // SecKeyFromBytes returns a secret and public key for `curve' based on the
  22  // secret key passed as an argument as a byte slice.
  23  func SecKeyFromBytes(pk []byte) (*SecretKey, *PublicKey) {
  24  	privKey := secp256k1.SecKeyFromBytes(pk)
  25  	return privKey, privKey.PubKey()
  26  }
  27  
  28  var PrivKeyFromBytes = SecKeyFromBytes
  29  
  30  // NewSecretKey is a wrapper for ecdsa.GenerateKey that returns a SecretKey instead of the normal ecdsa.PrivateKey.
  31  func NewSecretKey() (*SecretKey, error) { return secp256k1.GenerateSecretKey() }
  32  
  33  // NewPrivateKey is a wrapper for ecdsa.GenerateKey that returns a SecretKey instead of the normal ecdsa.PrivateKey.
  34  //
  35  // Deprecated: use SecretKey - secret = one person; private = two or more (you don't share secret keys!)
  36  var NewPrivateKey = NewSecretKey
  37  
  38  // SecKeyFromScalar instantiates a new secret key from a scalar encoded as a
  39  // big integer.
  40  func SecKeyFromScalar(key *ModNScalar) *SecretKey {
  41  	return &SecretKey{Key: *key}
  42  }
  43  
  44  var PrivKeyFromScalar = SecKeyFromScalar
  45  
  46  // SecKeyBytesLen defines the length in bytes of a serialized secret key.
  47  const SecKeyBytesLen = 32
  48  const PrivKeyBytesLen = SecKeyBytesLen
  49