Skip to content

Commit 07e8c7f

Browse files
committed
feat: update wallet creation and signing processes to support multiple protocols
1 parent bb8cf07 commit 07e8c7f

14 files changed

Lines changed: 1049 additions & 599 deletions

File tree

examples/generate/kms/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ func main() {
117117
for _, walletID := range walletIDs {
118118
wg.Add(1) // Add to WaitGroup BEFORE attempting to create wallet
119119

120-
if err := mpcClient.CreateWallet(walletID); err != nil {
120+
if err := mpcClient.CreateWallet(&types.GenerateKeyMessage{
121+
WalletID: walletID,
122+
ECDSAProtocol: types.ProtocolCGGMP21,
123+
EdDSAProtocol: types.ProtocolGG18,
124+
}); err != nil {
121125
logger.Error("CreateWallet failed", err)
122126
walletStartTimes.Delete(walletID)
123127
wg.Done() // Now this is safe since we added 1 above

examples/presign/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/fystack/mpcium/pkg/event"
1313
"github.com/fystack/mpcium/pkg/logger"
1414
"github.com/fystack/mpcium/pkg/types"
15+
"github.com/google/uuid"
1516
"github.com/nats-io/nats.go"
1617
"github.com/spf13/viper"
1718
)
@@ -65,8 +66,10 @@ func main() {
6566
})
6667

6768
txMsg := &types.PresignTxMessage{
68-
KeyType: types.KeyTypeCGGMP21,
69+
KeyType: types.KeyTypeSecp256k1,
70+
Protocol: types.ProtocolCGGMP21,
6971
WalletID: "196c6858-30de-4a49-9134-8bc825d40764", // Use the generated wallet ID
72+
TxID: uuid.New().String(),
7073
}
7174
err = mpcClient.PresignTransaction(txMsg)
7275
if err != nil {

examples/reshare/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func main() {
8888

8989
NewThreshold: 1, // t+1 <= len(NodeIDs)
9090
KeyType: types.KeyTypeEd25519,
91+
Protocol: types.ProtocolFROST,
9192
}
9293
err = mpcClient.Resharing(resharingMsg)
9394
if err != nil {

examples/sign/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ func main() {
7070
dummyTx := []byte("deadbeef") // replace with real transaction bytes
7171

7272
txMsg := &types.SignTxMessage{
73-
KeyType: types.KeyTypeEd25519,
74-
WalletID: "ad24f678-b04b-4149-bcf6-bf9c90df8e63", // Use the generated wallet ID
73+
KeyType: types.KeyTypeSecp256k1,
74+
Protocol: types.ProtocolFROST,
75+
WalletID: "6d553e80-a1dc-4894-9eaf-b81e3fe0c94a", // Use the generated wallet ID
7576
NetworkInternalCode: "solana-devnet",
7677
TxID: txID,
7778
Tx: dummyTx,
@@ -87,6 +88,8 @@ func main() {
8788
logger.Info("Signing result received",
8889
"txID", evt.TxID,
8990
"signature", fmt.Sprintf("%x", evt.Signature),
91+
"error", evt.ErrorReason,
92+
"errorCode", evt.ErrorCode,
9093
)
9194
})
9295
if err != nil {

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ require (
1111
github.com/aws/aws-sdk-go-v2/credentials v1.18.8
1212
github.com/aws/aws-sdk-go-v2/service/kms v1.45.0
1313
github.com/bnb-chain/tss-lib/v2 v2.0.2
14+
github.com/btcsuite/btcd/btcec/v2 v2.3.2
1415
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3
15-
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
1616
github.com/dgraph-io/badger/v4 v4.7.0
17+
github.com/fxamacker/cbor/v2 v2.4.0
1718
github.com/google/uuid v1.6.0
1819
github.com/hashicorp/consul/api v1.32.1
1920
github.com/mitchellh/mapstructure v1.5.0
@@ -25,6 +26,7 @@ require (
2526
github.com/taurusgroup/multi-party-sig v0.7.0-alpha-2025-01-28
2627
github.com/urfave/cli/v3 v3.3.2
2728
golang.org/x/crypto v0.37.0
29+
golang.org/x/sync v0.13.0
2830
golang.org/x/term v0.31.0
2931
)
3032

@@ -43,17 +45,16 @@ require (
4345
github.com/aws/aws-sdk-go-v2/service/sts v1.38.1 // indirect
4446
github.com/aws/smithy-go v1.23.0 // indirect
4547
github.com/btcsuite/btcd v0.24.2 // indirect
46-
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
4748
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
4849
github.com/btcsuite/btcutil v1.0.2 // indirect
4950
github.com/cespare/xxhash/v2 v2.3.0 // indirect
5051
github.com/cronokirby/saferith v0.33.0 // indirect
5152
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
53+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
5254
github.com/dgraph-io/ristretto/v2 v2.2.0 // indirect
5355
github.com/dustin/go-humanize v1.0.1 // indirect
5456
github.com/fatih/color v1.18.0 // indirect
5557
github.com/fsnotify/fsnotify v1.7.0 // indirect
56-
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
5758
github.com/go-logr/logr v1.4.2 // indirect
5859
github.com/go-logr/stdr v1.2.2 // indirect
5960
github.com/gogo/protobuf v1.3.2 // indirect

pkg/client/client.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
)
2020

2121
type MPCClient interface {
22-
CreateWallet(walletID string) error
22+
CreateWallet(msg *types.GenerateKeyMessage) error
2323
OnWalletCreationResult(callback func(event event.KeygenResultEvent)) error
2424

2525
SignTransaction(msg *types.SignTxMessage) error
@@ -110,11 +110,7 @@ func NewMPCClient(opts Options) MPCClient {
110110
}
111111

112112
// CreateWallet generates a GenerateKeyMessage, signs it, and publishes it.
113-
func (c *mpcClient) CreateWallet(walletID string) error {
114-
// build the message
115-
msg := &types.GenerateKeyMessage{
116-
WalletID: walletID,
117-
}
113+
func (c *mpcClient) CreateWallet(msg *types.GenerateKeyMessage) error {
118114
// compute the canonical raw bytes
119115
raw, err := msg.Raw()
120116
if err != nil {

pkg/event/keygen.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ const (
77
)
88

99
type KeygenResultEvent struct {
10-
WalletID string `json:"wallet_id"`
11-
ECDSAPubKey []byte `json:"ecdsa_pub_key"`
12-
EDDSAPubKey []byte `json:"eddsa_pub_key"`
13-
CGGMP21PubKey []byte `json:"cggmp21_pub_key"`
14-
TaprootPubKey []byte `json:"taproot_pub_key"`
10+
WalletID string `json:"wallet_id"`
11+
ECDSAPubKey []byte `json:"ecdsa_pub_key"`
12+
EDDSAPubKey []byte `json:"eddsa_pub_key"`
1513

1614
ResultType ResultType `json:"result_type"`
1715
ErrorReason string `json:"error_reason"`

pkg/event/presign.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ type PresignResultEvent struct {
1313
ErrorReason string `json:"error_reason"`
1414
IsTimeout bool `json:"is_timeout"`
1515
WalletID string `json:"wallet_id"`
16+
TxID string `json:"tx_id"`
1617
Status string `json:"status"`
1718
}

0 commit comments

Comments
 (0)