@@ -54,7 +54,7 @@ type mpcClient struct {
5454 // privKey ed25519.PrivateKey
5555 // privKeyECDSA *ecdsa.PrivateKey
5656 initiatorPrivKey * InitiatorPrivKey
57- algorithm string
57+ algorithm types. EventInitiatorKeyType
5858}
5959
6060// Options defines configuration options for creating a new MPCClient
@@ -70,7 +70,7 @@ type Options struct {
7070 Password string // Password for encrypted key
7171
7272 // Algorithm for key type
73- Algorithm string // Either "ed25519" or "p256" (default: "ed25519")
73+ Algorithm types. EventInitiatorKeyType // Either "ed25519" or "p256" (default: "ed25519")
7474}
7575
7676// NewMPCClient creates a new MPC client using the provided options.
@@ -83,8 +83,8 @@ func NewMPCClient(opts Options) MPCClient {
8383 }
8484
8585 // Set default algorithm if not provided
86- if opts .Algorithm == "" {
87- opts .Algorithm = "ed25519"
86+ if opts .Algorithm == types . EventInitiatorKeyType ( "" ) {
87+ opts .Algorithm = types . EventInitiatorKeyTypeEd25519
8888 }
8989
9090 if strings .HasSuffix (opts .KeyPath , ".age" ) {
@@ -127,7 +127,7 @@ func NewMPCClient(opts Options) MPCClient {
127127 var priv ed25519.PrivateKey
128128 var privECDSA * ecdsa.PrivateKey
129129
130- if opts .Algorithm == "p256" {
130+ if opts .Algorithm == types . EventInitiatorKeyTypeP256 {
131131 // Parse P256 key
132132 privECDSA , err = encryption .ParseP256PrivateKey (privHexBytes )
133133 if err != nil {
@@ -240,22 +240,22 @@ func (c *mpcClient) CreateWallet(walletID string) error {
240240 if err != nil {
241241 return fmt .Errorf ("CreateWallet: raw payload error: %w" , err )
242242 }
243- logger .Info ("Raw payload for signing" , "raw" , string (raw ), "raw_bytes" , raw )
244243 // sign based on algorithm
245244 var signature []byte
246- if c .algorithm == "p256" {
245+
246+ switch c .algorithm {
247+ case types .EventInitiatorKeyTypeP256 :
247248 if c .initiatorPrivKey .P256 .Curve == nil {
248249 return fmt .Errorf ("CreateWallet: P256 private key not initialized" )
249250 }
250251 signature , err = encryption .SignWithP256 (c .initiatorPrivKey .P256 , raw )
251252 if err != nil {
252253 return fmt .Errorf ("CreateWallet: failed to create P256 signature: %w" , err )
253254 }
254- if signature == nil {
255- return fmt .Errorf ("CreateWallet: failed to create P256 signature" )
256- }
257- } else {
255+ case types .EventInitiatorKeyTypeEd25519 :
258256 signature = ed25519 .Sign (c .initiatorPrivKey .Ed25519 , raw )
257+ default :
258+ return fmt .Errorf ("CreateWallet: unsupported algorithm: %s" , c .algorithm )
259259 }
260260 msg .Signature = signature
261261
@@ -298,19 +298,19 @@ func (c *mpcClient) SignTransaction(msg *types.SignTxMessage) error {
298298 }
299299 // sign based on algorithm
300300 var signature []byte
301- if c .algorithm == "p256" {
301+ switch c .algorithm {
302+ case types .EventInitiatorKeyTypeP256 :
302303 if c .initiatorPrivKey .P256 .Curve == nil {
303304 return fmt .Errorf ("SignTransaction: P256 private key not initialized" )
304305 }
305306 signature , err = encryption .SignWithP256 (c .initiatorPrivKey .P256 , raw )
306307 if err != nil {
307308 return fmt .Errorf ("SignTransaction: failed to create P256 signature: %w" , err )
308309 }
309- if signature == nil {
310- return fmt .Errorf ("SignTransaction: failed to create P256 signature" )
311- }
312- } else {
310+ case types .EventInitiatorKeyTypeEd25519 :
313311 signature = ed25519 .Sign (c .initiatorPrivKey .Ed25519 , raw )
312+ default :
313+ return fmt .Errorf ("SignTransaction: unsupported algorithm: %s" , c .algorithm )
314314 }
315315 msg .Signature = signature
316316
@@ -351,19 +351,19 @@ func (c *mpcClient) Resharing(msg *types.ResharingMessage) error {
351351 }
352352 // sign based on algorithm
353353 var signature []byte
354- if c .algorithm == "p256" {
354+ switch c .algorithm {
355+ case types .EventInitiatorKeyTypeP256 :
355356 if c .initiatorPrivKey .P256 .Curve == nil {
356357 return fmt .Errorf ("Resharing: P256 private key not initialized" )
357358 }
358359 signature , err = encryption .SignWithP256 (c .initiatorPrivKey .P256 , raw )
359360 if err != nil {
360361 return fmt .Errorf ("Resharing: failed to create P256 signature: %w" , err )
361362 }
362- if signature == nil {
363- return fmt .Errorf ("Resharing: failed to create P256 signature" )
364- }
365- } else {
363+ case types .EventInitiatorKeyTypeEd25519 :
366364 signature = ed25519 .Sign (c .initiatorPrivKey .Ed25519 , raw )
365+ default :
366+ return fmt .Errorf ("Resharing: unsupported algorithm: %s" , c .algorithm )
367367 }
368368 msg .Signature = signature
369369
0 commit comments