feat: privatekey method change (#442)
This commit is contained in:
@@ -48,11 +48,12 @@ func generateSignature(signingString []byte, privateKeyBase64 string) ([]byte, e
|
|||||||
return nil, fmt.Errorf("error decoding private key: %w", err)
|
return nil, fmt.Errorf("error decoding private key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(privateKeyBytes) != ed25519.PrivateKeySize {
|
if len(privateKeyBytes) != ed25519.SeedSize {
|
||||||
return nil, errors.New("invalid private key length")
|
return nil, errors.New("invalid seed length")
|
||||||
}
|
}
|
||||||
|
|
||||||
privateKey := ed25519.PrivateKey(privateKeyBytes)
|
// Generate the private key from the seed
|
||||||
|
privateKey := ed25519.NewKeyFromSeed(privateKeyBytes)
|
||||||
return ed25519.Sign(privateKey, signingString), nil
|
return ed25519.Sign(privateKey, signingString), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
// generateTestKeys generates a test private and public key pair in base64 encoding.
|
// generateTestKeys generates a test private and public key pair in base64 encoding.
|
||||||
func generateTestKeys() (string, string) {
|
func generateTestKeys() (string, string) {
|
||||||
publicKey, privateKey, _ := ed25519.GenerateKey(nil)
|
publicKey, privateKey, _ := ed25519.GenerateKey(nil)
|
||||||
return base64.StdEncoding.EncodeToString(privateKey), base64.StdEncoding.EncodeToString(publicKey)
|
return base64.StdEncoding.EncodeToString(privateKey.Seed()), base64.StdEncoding.EncodeToString(publicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSignSuccess tests the Sign method with valid inputs to ensure it produces a valid signature.
|
// TestSignSuccess tests the Sign method with valid inputs to ensure it produces a valid signature.
|
||||||
@@ -82,7 +82,7 @@ func TestSignFailure(t *testing.T) {
|
|||||||
privateKey: base64.StdEncoding.EncodeToString([]byte("short_key")),
|
privateKey: base64.StdEncoding.EncodeToString([]byte("short_key")),
|
||||||
createdAt: time.Now().Unix(),
|
createdAt: time.Now().Unix(),
|
||||||
expiresAt: time.Now().Unix() + 3600,
|
expiresAt: time.Now().Unix() + 3600,
|
||||||
expectErrString: "invalid private key length",
|
expectErrString: "invalid seed length",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user