diff --git a/crypto.go b/crypto.go index ddf05244a..7b7e11bf8 100644 --- a/crypto.go +++ b/crypto.go @@ -332,6 +332,10 @@ func (pk PublicKey) Bytes() []byte { return pk.keyData } +func (sk PrivateKey) toProtoKey() *proto.Key { + return sk.PublicKey().toProtoKey() +} + func (pk PublicKey) toProtoKey() *proto.Key { return &proto.Key{Key: &proto.Key_Ed25519{Ed25519: pk.keyData}} } diff --git a/crypto_test.go b/crypto_test.go index 90120f53a..1641d333e 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -219,3 +219,40 @@ func TestPrivateKey_FromPemWithPassphrase(t *testing.T) { assert.Equal(t, actualPrivateKey, privateKey) } + +func TestSetKeyUsesAnyKey(t *testing.T) { + client := newTestClient(t) + + newKey, err := GeneratePrivateKey() + assert.NoError(t, err) + + newBalance := NewHbar(1) + + assert.Equal(t, HbarUnits.Hbar.numberOfTinybar(), newBalance.tinybar) + + keys := make([]PrivateKey, 3) + pubKeys := make([]PublicKey, 3) + + for i := range keys { + newKey, err := GeneratePrivateKey() + if err != nil { + panic(err) + } + + keys[i] = newKey + pubKeys[i] = newKey.PublicKey() + } + + thresholdKey := KeyListWithThreshold(2). + AddAllPublicKeys(pubKeys) + + _, err = NewAccountCreateTransaction(). + SetKey(newKey.PublicKey()). + SetKey(newKey). + SetKey(thresholdKey). + SetMaxTransactionFee(NewHbar(2)). + SetInitialBalance(newBalance). + Execute(client) + assert.NoError(t, err) + +}