diff --git a/crypto/bls/bls_test.go b/crypto/bls/bls_test.go index 9fd940103..ba4f9a497 100644 --- a/crypto/bls/bls_test.go +++ b/crypto/bls/bls_test.go @@ -145,7 +145,7 @@ func TestDuplicatedAggregate(t *testing.T) { // TestHashToCurve ensures that the hash-to-curve function in kilic/bls12-381 // works as intended and is compatible with the spec. // test vectors can be found here: -// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#appendix-J.9.1 +// https://datatracker.ietf.org/doc/html/rfc9380 func TestHashToCurve(t *testing.T) { domain := []byte("QUUX-V01-CS02-with-BLS12381G1_XMD:SHA-256_SSWU_RO_") tests := []struct { @@ -173,6 +173,16 @@ func TestHashToCurve(t *testing.T) { "15f68eaa693b95ccb85215dc65fa81038d69629f70aeee0d0f677cf22285e7bf58d7cb86eefe8f2e9bc3f8cb84fac488" + "1807a1d50c29f430b8cafc4f8638dfeeadf51211e1602a5f184443076715f91bb90a48ba1e370edce6ae1062f5e6dd38", }, + { + "a512_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "082aabae8b7dedb0e78aeb619ad3bfd9277a2f77ba7fad20ef6aabdc6c31d19ba5a6d12283553294c1825c4b3ca2dcfe" + + "05b84ae5a942248eea39e1d91030458c40153f3b654ab7872d779ad1e942856a20c438e8d99bc8abfbf74729ce1f7ac8", + }, } g1 := bls12381.NewG1() diff --git a/wallet/wallet_test.go b/wallet/wallet_test.go index 9704b91fc..de274202b 100644 --- a/wallet/wallet_test.go +++ b/wallet/wallet_test.go @@ -1,6 +1,8 @@ package wallet_test import ( + "bytes" + "fmt" "path" "testing" @@ -9,8 +11,11 @@ import ( "github.com/pactus-project/pactus/genesis" "github.com/pactus-project/pactus/state" "github.com/pactus-project/pactus/types/account" + "github.com/pactus-project/pactus/types/amount" + "github.com/pactus-project/pactus/types/tx" "github.com/pactus-project/pactus/types/tx/payload" "github.com/pactus-project/pactus/util" + "github.com/pactus-project/pactus/util/encoding" "github.com/pactus-project/pactus/util/errors" "github.com/pactus-project/pactus/util/testsuite" "github.com/pactus-project/pactus/wallet" @@ -589,3 +594,27 @@ func TestTotalBalance(t *testing.T) { assert.NoError(t, err) assert.Equal(t, totalBalance, acc1.Balance()+acc3.Balance()) } + +func Test_sign(t *testing.T) { + prv, _ := bls.PrivateKeyFromString("SECRET1PDRWTLP5PX0FAHDX39GXZJP7FKZFALML0D5U9TT9KVQHDUC99CMGQQJVK67") + sender, _ := crypto.AddressFromString("pc1z5x2a0lkt5nrrdqe0rkcv6r4pfkmdhrr3mawvua") + receiver, _ := crypto.AddressFromString("pc1zt6qcdymkk48c5ds0fzfsaf6puwu8w8djn3ffpn") + amt, _ := amount.NewAmount(1.0) + fee, _ := amount.NewAmount(0.001) + lock_time := uint32(0x123456) + + trx := tx.NewTransferTx(lock_time, sender, receiver, amt, fee, tx.WithMemo("test")) + fmt.Printf("msg to sign: %x\n", trx.SignBytes()) + sig := prv.Sign(trx.SignBytes()) + + trx.SetPublicKey(prv.PublicKey()) + trx.SetSignature(sig) + + var buf bytes.Buffer + encoding.WriteVarInt(&buf, uint64(fee.ToNanoPAC())) + fmt.Printf("%x\n", buf.Bytes()) + + bz, _ := trx.Bytes() + fmt.Printf("%x", bz) + +}