Skip to content

Commit

Permalink
Merge pull request #65 from everFinance/fix/verify-bundleitem
Browse files Browse the repository at this point in the history
feat(): fix bundle item
  • Loading branch information
zyjblockchain authored Mar 18, 2024
2 parents 35d590e + 4b0ec5c commit 36c3704
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
31 changes: 31 additions & 0 deletions example/api_example_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package example

import (
"github.com/everFinance/goar/types"
"github.com/everFinance/goar/utils"
"testing"

"github.com/everFinance/goar"
Expand Down Expand Up @@ -139,3 +141,32 @@ func Test_SendFormatTx(t *testing.T) {
// t.Log("from: ",wallet.Address)
// t.Log("txHash: ", tx.ID)
}

func Test_SendMsg(t *testing.T) {
signer02, err := goar.NewSignerFromPath("./testKey.json")
assert.NoError(t, err)
t.Log(signer02.Address)
itemSigner02, err := goar.NewItemSigner(signer02)
assert.NoError(t, err)

defaultTags := []types.Tag{
{Name: "Data-Protocol", Value: "ao"},
{Name: "Variant", Value: "ao.TN.1"},
{Name: "Type", Value: "Message"},
{Name: "SDK", Value: "argo"},
}
tags := append(defaultTags, []types.Tag{
{Name: "Action", Value: "Transfer"},
{Name: "Recipient", Value: "AVm7zHYGzw9PmUXv4CFHgiK3QtbRTpBMS2VOxJAK-F4"},
{Name: "Quantity", Value: "22"},
}...)
target := "7En3PZJ0BBROTuSazQ9yZmeL1ThwsVqk616gY3DMFZU"
data := []byte("1234")
item02, err := itemSigner02.CreateAndSignItem(data, target, "", tags)
assert.NoError(t, err)
muUrl := "https://mu.ao-testnet.xyz"
t.Log("item", "id", item02.Id)
resp, err := utils.SubmitItemToMU(item02, muUrl)
assert.NoError(t, err)
t.Log(string(resp))
}
39 changes: 39 additions & 0 deletions example/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package example
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"io/ioutil"
Expand Down Expand Up @@ -396,3 +397,41 @@ func changeData(item types.BundleItem) error {
}
return nil
}

func TestA(t *testing.T) {
arId := "-0ArzIK-Vfki6Kmm-HiWSBQifRho4SRcYMFkcGW9bTo"
cli := goar.NewClient("https://arweave.net")
data, err := cli.GetTransactionDataByGateway(arId)
assert.NoError(t, err)
t.Log(len(data))
b, err := utils.DecodeBundle(data)
assert.NoError(t, err)
item := b.Items[0]
t.Log(item.Id)
t.Log(item.TagsBy)

tagsBy, err := utils.SerializeTags(item.Tags)
assert.NoError(t, err)
t.Log(utils.Base64Encode(tagsBy))

tagsBy1, err := utils.SerializeTags1(item.Tags)
assert.NoError(t, err)
t.Log(utils.Base64Encode(tagsBy1))
}

func TestB(t *testing.T) {
// data := `{"mainItem":{"signatureType":1,"signature":"f1iKOgLh6LYCLWWvrzfrvB3dO1VnQ9rniy29OEI8C6bJTgBF7ybB1JjCBsiy1Cb7OaGwDYvYc50aY2wbbAw0ysIhSDUoXZQkyKlrcEVMWM7gUhzEOI6N9BjRlj3cDkN2K1esisIDwhA6OGhBoffA9RCv3RmOnL4kUa34JiDq43NX3IsKnAf7Fjy9Jnk2eDqbxmDVIysF48X13NqKvEtvjSorOS62KmbmBhEasbYnEFeHoMSQfTAHbgJx6hRwn46ujNPKI9QRM-HVpecbmy7W2tubjZkHqP1CWzpBYCo8FyJrDqV1qtmWzFhPXxcyZOirg_aQbS2mxD9jJYzDVCgonkzkbWVURgYusEuD0gH2uMkLKFOP5CHzsWYkf08pLI7wMZQvYXRnLNeX5Gxjd8SMZK5zXFY3cY6mjzvqCa0k1AMladFaQt2JqnlG4yC-nOkc_x35EDTM4ogMe3SS0AG7lgUR4bpPxPk36DxpejU0aZUBGzdXhDWJOhzuOQHXLJfOvyCgassKDLV3-4cS0pQM11he2-0GmlD-KO-qOyvJlZk_J5-crXeeXdyU_gCt9_Hcu8Zzef3F5kaWOvO_q5NO-41aDcrlxDa1r2ONMdMaR7qnbmOAyk3YzdgQ0eSBreCmqAagLjHa8qQMqRL5KEu2cvGad6G84_-tNWE25Wn2MWY","owner":"t99k0vXXnX6h4lboKxfwZd2FfUoR1yPNUk1-LyCHcHMReVvZWfUvpOW1no_3axDSlo7xRsbTp4UEUeazZiv_It9PwcqT8lC_p1CzKv0kWH_1kjCYKm-0efgx5SPc7rIT3SVohC2-SI8meEA_3YP_k-FxUNa3zwbu5sKcy_hAUia_4a6sEFymeuQaBJux5snjYnX-iVhc5tjqauAGOXTh_Nhg9LNC_VlItutKxmkF7W-lM1wtka_yK-v1Xbcr4CFExiRI03keGqTfesSxfbkPm9C7N3ihbpYhQ68nhBdZzNFPEHGWPeEVW0yA8yHTZ5ytckpAmLSqOrqnPEiMeZrh-Fsgp7beIyfvjRG4yNjfoZkZdHrOHhppBPUp2t64OTQickkPsDkHQRf_BhNAXkdco4pOwMF_N6GQS8YhCN6TUp3DAvJp4QFR2jDH4nuMWma5TcxSDXfLM8HBD478Uwzflbrfrb0FQgfyD6lfNqvaArwqbJBIiwNo70FT65i8V1g507297VZ9UmuJfahea9aDgLntZT6kbZTZnE4m4lE9U6B9in_Wvx_ZdGi3BptGd8AyB-2FWv-xOltEmN-pDRaBhjucQmVzoptZZ6UrzXwlL21fiTBCoUJPJVjOYldW0VqXevkGe24SWLiUB_EApg418JNiHplJtUsEhI2DIhHFb9M","target":"Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc","anchor":"","tags":[{"name":"Action","value":"Transfer"},{"name":"Recipient","value":"FyINHRSrHW0teUhvJzd6R33Tl50qxLnSj8LJCP5puiI"},{"name":"Quantity","value":"2000"},{"name":"Data-Protocol","value":"ao"},{"name":"Variant","value":"ao.TN.1"},{"name":"Type","value":"Message"},{"name":"SDK","value":"argo"}],"data":"MTIzNA","id":"2usO_ScavCzedD4zS6QE1fBQK35dSCoclFTueL17CsU"},"targetChainType":"aostest"}`
data := `{"mainItem":{"signatureType":1,"signature":"H7RKwdh8B-ZXxLgNxPN4LNYmz-Gb_vcmmsYDFDFCOg-6uHUgXfQQtqnJ_wSZUrIXucuG8rVowCJps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FQgfyD6lfNqvaArwqbJBIiwNo70FT65i8V1g507297VZ9UmuJfahea9aDgLntZT6kbZTZnE4m4lE9U6B9in_Wvx_ZdGi3BptGd8AyB-2FWv-xOltEmN-pDRaBhjucQmVzoptZZ6UrzXwlL21fiTBCoUJPJVjOYldW0VqXevkGe24SWLiUB_EApg418JNiHplJtUsEhI2DIhHFb9M","target":"Sa0iBLPNyJQrwpTTG-tWLQU-1QeUAJA73DdxGGiKoJc","anchor":"","tags":[{"name":"Action","value":"Transfer"},{"name":"Recipient","value":"FyINHRSrHW0teUhvJzd6R33Tl50qxLnSj8LJCP5puiI"},{"name":"Quantity","value":"2000"},{"name":"Data-Protocol","value":"ao"},{"name":"Variant","value":"ao.TN.1"},{"name":"Type","value":"Message"},{"name":"SDK","value":"argo"}],"data":"MTIzNA","id":"UDL4bmFI_E74WLBkol69NWoHJG4dwRA_sLo78u79eAg"},"targetChainType":"aostest"}`
items := struct {
MainItem types.BundleItem `json:"mainItem"`
PushedItem types.BundleItem `json:"pushedItem"`
}{}

err := json.Unmarshal([]byte(data), &items)
assert.NoError(t, err)
// check main Item
mainItem := items.MainItem
// verify mainItem sig
err = utils.VerifyBundleItem(mainItem)
assert.NoError(t, err)
}
8 changes: 8 additions & 0 deletions utils/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ func newBundleItem(owner string, signatureType int, target, anchor string, data
}

func BundleItemSignData(d types.BundleItem) ([]byte, error) {
if len(d.TagsBy) == 0 && len(d.Tags) > 0 {
// calc tagsBy
tagsBy, err := SerializeTags(d.Tags)
if err != nil {
return nil, err
}
d.TagsBy = Base64Encode(tagsBy)
}
// deep hash
dataList := make([]interface{}, 0)
dataList = append(dataList, Base64Encode([]byte("dataitem")))
Expand Down

0 comments on commit 36c3704

Please sign in to comment.