Skip to content

Commit 5ca4704

Browse files
committed
Merge branch 'main' into feature/refactor
# Conflicts: # client_test.go # go.sum # sign_test.go
2 parents f465f17 + 48fc426 commit 5ca4704

File tree

6 files changed

+139
-133
lines changed

6 files changed

+139
-133
lines changed

client_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import (
1111
// "fmt"
1212
// "testing"
1313

14-
// "github.com/everFinance/goar/types"
15-
// "github.com/stretchr/testify/assert"
16-
// )
17-
1814
// func TestGetTransactionByID(t *testing.T) {
1915
// client := NewClient("https://arweave.net")
2016
// fmt.Println(client.GetTransactionByID("FgcKlptyDXSgEonYfy5cNBimq7GJ4h8h6L6pxuuYOBc"))

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.15
55
require (
66
github.com/everFinance/gojwk v1.0.0
77
github.com/everFinance/sandy_log v1.0.3
8-
github.com/everFinance/ttcrsa v1.1.1
8+
github.com/everFinance/ttcrsa v1.1.2
99
github.com/shopspring/decimal v1.2.0
1010
github.com/stretchr/testify v1.7.0
1111
)

go.sum

Whitespace-only changes.

sign_test.go

Whitespace-only changes.

threshold.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ func (ts *TcSign) AssembleSigShares(signedShares tcrsa.SigShareList) ([]byte, er
101101
}
102102

103103
// VerifySigShare verify share sig
104-
func (ts *TcSign) VerifySigShare(sigShareData string) error {
104+
func (ts *TcSign) VerifySigShare(sigShareData []byte) error {
105105
// unmarshal share sig data
106106
ss := &tcrsa.SigShare{}
107-
if err := json.Unmarshal([]byte(sigShareData), ss); err != nil {
107+
if err := json.Unmarshal(sigShareData, ss); err != nil {
108108
return err
109109
}
110110
return ss.Verify(ts.pssData, ts.keyMeta)

threshold_test.go

+136-126
Original file line numberDiff line numberDiff line change
@@ -341,129 +341,139 @@ func GetKeyPairFormLocalFile() (shares tcrsa.KeyShareList, meta *tcrsa.KeyMeta,
341341
// }
342342

343343
// TestCreateKeyPair2 send ar tx by threshold signature keypair
344-
// func TestCreateKeyPair2(t *testing.T) {
345-
// cli := client.New("https://arweave.net")
346-
347-
// target := "Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck"
348-
// reward, err := cli.GetTransactionPrice(nil, &target)
349-
// assert.NoError(t, err)
350-
// // anchor, err := cli.GetTransactionAnchor() // for test
351-
// anchor, err := cli.GetLastTransactionID("KKzL8og7VFLNwxbwW6cpUY_WkE5jFjWL26cTvKfWYms")
352-
// assert.NoError(t, err)
353-
// t.Log("lastTx: ", anchor)
354-
// // read created threshold keypair for local file; need to be generated ahead of time;
355-
// keyMeta := &tcrsa.KeyMeta{}
356-
// keyMetaBy, err := ioutil.ReadFile("keyMeta.json")
357-
// assert.NoError(t, err)
358-
// err = json.Unmarshal(keyMetaBy, keyMeta)
359-
// assert.NoError(t, err)
360-
361-
// owner := utils.Base64Encode(keyMeta.PublicKey.N.Bytes())
362-
363-
// amount := big.NewInt(140000) // transfer amount
364-
// tags := []types.Tag{{Name: "Content-Type", Value: "application/json"}, {Name: "tcrsa", Value: "sandyTest"}}
365-
// tx := &types.Transaction{
366-
// Format: 2,
367-
// ID: "",
368-
// LastTx: anchor,
369-
// Owner: owner,
370-
// Tags: types.TagsEncode(tags),
371-
// Target: target,
372-
// Quantity: amount.String(),
373-
// Data: "",
374-
// DataSize: "0",
375-
// DataRoot: "",
376-
// Reward: fmt.Sprintf("%d", reward),
377-
// Signature: "",
378-
// Chunks: nil,
379-
// }
380-
// signData, err := types.GetSignatureData(tx)
381-
// assert.NoError(t, err)
382-
// t.Log("signData: ", signData)
383-
384-
// // signature
385-
// keyShares := tcrsa.KeyShareList{}
386-
// keySharesBy, err := ioutil.ReadFile("keyShares.json")
387-
// assert.NoError(t, err)
388-
// err = json.Unmarshal(keySharesBy, &keyShares)
389-
// assert.NoError(t, err)
390-
391-
// ts, err := NewTcSign(keyMeta, signData)
392-
// assert.NoError(t, err)
393-
394-
// /* --------------------------distribute keyShares to the signers ----------------------------*/
395-
// signer01 := keyShares[0]
396-
// signer02 := keyShares[1]
397-
// signer03 := keyShares[2]
398-
// signer04 := keyShares[3]
399-
// signer05 := keyShares[4]
400-
401-
// /* -------------------------- signers to sign data ----------------------------*/
402-
// signedData01, err := ts.ThresholdSign(signer01)
403-
// if err != nil {
404-
// panic(err)
405-
// }
406-
// t.Log(signedData01.Id)
407-
408-
// signedData02, err := ts.ThresholdSign(signer02)
409-
// if err != nil {
410-
// panic(err)
411-
// }
412-
// t.Log(signedData02.Id)
413-
414-
// signedData03, err := ts.ThresholdSign(signer03)
415-
// if err != nil {
416-
// panic(err)
417-
// }
418-
// t.Log(signedData03.Id)
419-
420-
// signedData04, err := ts.ThresholdSign(signer04)
421-
// if err != nil {
422-
// panic(err)
423-
// }
424-
// t.Log(signedData04.Id)
425-
426-
// signedData05, err := ts.ThresholdSign(signer05)
427-
// if err != nil {
428-
// panic(err)
429-
// }
430-
// t.Log(signedData05.Id)
431-
432-
// /* -------------------------- After receiving the signature data submitted by the signers, the server verifies the signature and assembles the signature ----------------------------*/
433-
// // Collect the signer's signature data into an array
434-
// signedShares := tcrsa.SigShareList{
435-
// // signedData01,
436-
// signedData02,
437-
// signedData03,
438-
// signedData04,
439-
// // signedData05,
440-
// }
441-
442-
// // Verify the signature of each collected signer. And what happens in practice is that the server receives the signature submitted by the signer and then it verifies it and then it puts it in the array above
443-
// for _, sd := range signedShares {
444-
// err = sd.Verify(ts.pssData, keyMeta)
445-
// if err != nil {
446-
// panic(err)
447-
// }
448-
// }
449-
450-
// // assemble signatures
451-
// signature, err := ts.AssembleSigShares(signedShares)
452-
// if err != nil {
453-
// panic(err)
454-
// }
455-
// // Finally, RSA native PSS verification signature method is used to verify the aggregated signature
456-
// signHashed := sha256.Sum256(signData)
457-
// err = rsa.VerifyPSS(keyMeta.PublicKey, crypto.SHA256, signHashed[:], signature, nil)
458-
// if err != nil {
459-
// panic(err)
460-
// }
461-
// // assemble tx and send to ar chain
462-
// tx.AddSignature(signature)
463-
// t.Log("txHash: ", tx.ID)
464-
465-
// status, code, err := cli.SubmitTransaction(tx)
466-
// assert.NoError(t, err)
467-
// t.Log("status: ", status)
468-
// t.Log("code: ", code)
469-
// }
344+
func TestCreateKeyPair2(t *testing.T) {
345+
// cli := client.New("https://arweave.net")
346+
//
347+
// target := "Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck"
348+
// reward, err := cli.GetTransactionPrice(nil, &target)
349+
// assert.NoError(t, err)
350+
// // anchor, err := cli.GetTransactionAnchor() // for test
351+
// anchor, err := cli.GetLastTransactionID("KKzL8og7VFLNwxbwW6cpUY_WkE5jFjWL26cTvKfWYms")
352+
// assert.NoError(t, err)
353+
// t.Log("lastTx: ", anchor)
354+
// // read created threshold keypair for local file; need to be generated ahead of time;
355+
// keyMeta := &tcrsa.KeyMeta{}
356+
// keyMetaBy, err := ioutil.ReadFile("keyMeta.json")
357+
// assert.NoError(t, err)
358+
// err = json.Unmarshal(keyMetaBy, keyMeta)
359+
// assert.NoError(t, err)
360+
//
361+
// owner := utils.Base64Encode(keyMeta.PublicKey.N.Bytes())
362+
//
363+
// amount := big.NewInt(140000) // transfer amount
364+
// tags := []types.Tag{{Name: "Content-Type", Value: "application/json"}, {Name: "tcrsa", Value: "sandyTest"}}
365+
// tx := &types.Transaction{
366+
// Format: 2,
367+
// ID: "",
368+
// LastTx: anchor,
369+
// Owner: owner,
370+
// Tags: types.TagsEncode(tags),
371+
// Target: target,
372+
// Quantity: amount.String(),
373+
// Data: "",
374+
// DataSize: "0",
375+
// DataRoot: "",
376+
// Reward: fmt.Sprintf("%d", reward),
377+
// Signature: "",
378+
// Chunks: nil,
379+
// }
380+
// signData, err := types.GetSignatureData(tx)
381+
// assert.NoError(t, err)
382+
// t.Log("signData: ", signData)
383+
//
384+
// // signature
385+
// keyShares := tcrsa.KeyShareList{}
386+
// keySharesBy, err := ioutil.ReadFile("keyShares.json")
387+
// assert.NoError(t, err)
388+
// err = json.Unmarshal(keySharesBy, &keyShares)
389+
// assert.NoError(t, err)
390+
//
391+
// ts, err := NewTcSign(keyMeta, signData)
392+
// assert.NoError(t, err)
393+
//
394+
// /* --------------------------distribute keyShares to the signers ----------------------------*/
395+
// signer01 := keyShares[0]
396+
// signer02 := keyShares[1]
397+
// signer03 := keyShares[2]
398+
// signer04 := keyShares[3]
399+
// signer05 := keyShares[4]
400+
//
401+
// /* -------------------------- signers to sign data ----------------------------*/
402+
// signedData01, err := ts.ThresholdSign(signer01)
403+
// if err != nil {
404+
// panic(err)
405+
// }
406+
// t.Log(signedData01.Id)
407+
// bb, _ := json.Marshal(signedData01)
408+
// t.Log(hex.EncodeToString(bb))
409+
//
410+
// signedData02, err := ts.ThresholdSign(signer02)
411+
// if err != nil {
412+
// panic(err)
413+
// }
414+
// t.Log(signedData02.Id)
415+
// bb, _ = json.Marshal(signedData02)
416+
// t.Log(hex.EncodeToString(bb))
417+
//
418+
// signedData03, err := ts.ThresholdSign(signer03)
419+
// if err != nil {
420+
// panic(err)
421+
// }
422+
// t.Log(signedData03.Id)
423+
// bb, _ = json.Marshal(signedData03)
424+
// t.Log(hex.EncodeToString(bb))
425+
//
426+
// signedData04, err := ts.ThresholdSign(signer04)
427+
// if err != nil {
428+
// panic(err)
429+
// }
430+
// t.Log(signedData04.Id)
431+
// bb, _ = json.Marshal(signedData04)
432+
// t.Log(hex.EncodeToString(bb))
433+
//
434+
// signedData05, err := ts.ThresholdSign(signer05)
435+
// if err != nil {
436+
// panic(err)
437+
// }
438+
// t.Log(signedData05.Id)
439+
// bb, _ = json.Marshal(signedData05)
440+
// t.Log(hex.EncodeToString(bb))
441+
//
442+
// /* -------------------------- After receiving the signature data submitted by the signers, the server verifies the signature and assembles the signature ----------------------------*/
443+
// // Collect the signer's signature data into an array
444+
// signedShares := tcrsa.SigShareList{
445+
// // signedData01,
446+
// signedData02,
447+
// signedData03,
448+
// signedData04,
449+
// // signedData05,
450+
// }
451+
//
452+
// // Verify the signature of each collected signer. And what happens in practice is that the server receives the signature submitted by the signer and then it verifies it and then it puts it in the array above
453+
// for _, sd := range signedShares {
454+
// err = sd.Verify(ts.pssData, keyMeta)
455+
// if err != nil {
456+
// panic(err)
457+
// }
458+
// }
459+
//
460+
// // assemble signatures
461+
// signature, err := ts.AssembleSigShares(signedShares)
462+
// if err != nil {
463+
// panic(err)
464+
// }
465+
// // Finally, RSA native PSS verification signature method is used to verify the aggregated signature
466+
// signHashed := sha256.Sum256(signData)
467+
// err = rsa.VerifyPSS(keyMeta.PublicKey, crypto.SHA256, signHashed[:], signature, nil)
468+
// if err != nil {
469+
// panic(err)
470+
// }
471+
// // assemble tx and send to ar chain
472+
// tx.AddSignature(signature)
473+
// t.Log("txHash: ", tx.ID)
474+
//
475+
// status, code, err := cli.SubmitTransaction(tx)
476+
// assert.NoError(t, err)
477+
// t.Log("status: ", status)
478+
// t.Log("code: ", code)
479+
}

0 commit comments

Comments
 (0)