@@ -283,6 +283,7 @@ func DecodeBundleItem(itemBinary []byte) (*types.BundleItem, error) {
283
283
284
284
var tagsBytesLength int
285
285
tags := []types.Tag {}
286
+ tagsBytes := make ([]byte , 0 )
286
287
if numOfTags > 0 {
287
288
if len (itemBinary ) < tagsStart + 16 {
288
289
return nil , errors .New ("itemBinary incorrect" )
@@ -291,7 +292,7 @@ func DecodeBundleItem(itemBinary []byte) (*types.BundleItem, error) {
291
292
if len (itemBinary ) < tagsStart + 16 + tagsBytesLength || tagsStart + 16 + tagsBytesLength < 0 {
292
293
return nil , errors .New ("itemBinary incorrect" )
293
294
}
294
- tagsBytes : = itemBinary [tagsStart + 16 : tagsStart + 16 + tagsBytesLength ]
295
+ tagsBytes = itemBinary [tagsStart + 16 : tagsStart + 16 + tagsBytesLength ]
295
296
// parser tags
296
297
tgs , err := DeserializeTags (tagsBytes )
297
298
if err != nil {
@@ -311,6 +312,7 @@ func DecodeBundleItem(itemBinary []byte) (*types.BundleItem, error) {
311
312
Tags : tags ,
312
313
Data : Base64Encode (data ),
313
314
Id : id ,
315
+ TagsBy : Base64Encode (tagsBytes ),
314
316
ItemBinary : itemBinary ,
315
317
}, nil
316
318
}
@@ -383,14 +385,15 @@ func DecodeBundleItemStream(itemBinary io.Reader) (*types.BundleItem, error) {
383
385
384
386
var tagsBytesLength int
385
387
tags := []types.Tag {}
388
+ tagsBytes := make ([]byte , 0 )
386
389
if numOfTags > 0 {
387
390
tagsBytesLengthBy := make ([]byte , 8 , 8 )
388
391
n , err = itemBinary .Read (tagsBytesLengthBy )
389
392
if err != nil || n < 8 {
390
393
return nil , errors .New ("itemBinary incorrect" )
391
394
}
392
395
tagsBytesLength = ByteArrayToLong (tagsBytesLengthBy )
393
- tagsBytes : = make ([]byte , tagsBytesLength , tagsBytesLength )
396
+ tagsBytes = make ([]byte , tagsBytesLength , tagsBytesLength )
394
397
n , err = itemBinary .Read (tagsBytes )
395
398
if err != nil || n < tagsBytesLength {
396
399
return nil , errors .New ("itemBinary incorrect" )
@@ -425,6 +428,7 @@ func DecodeBundleItemStream(itemBinary io.Reader) (*types.BundleItem, error) {
425
428
Tags : tags ,
426
429
Data : "" ,
427
430
Id : id ,
431
+ TagsBy : Base64Encode (tagsBytes ),
428
432
ItemBinary : make ([]byte , 0 ),
429
433
DataReader : dataReader ,
430
434
}, nil
@@ -457,6 +461,10 @@ func newBundleItem(owner string, signatureType int, target, anchor string, data
457
461
return nil , errors .New ("anchor length must be 32" )
458
462
}
459
463
}
464
+ tagsBytes , err := SerializeTags (tags )
465
+ if err != nil {
466
+ return nil , err
467
+ }
460
468
item := & types.BundleItem {
461
469
SignatureType : signatureType ,
462
470
Signature : "" ,
@@ -465,6 +473,7 @@ func newBundleItem(owner string, signatureType int, target, anchor string, data
465
473
Anchor : anchor ,
466
474
Tags : tags ,
467
475
Id : "" ,
476
+ TagsBy : Base64Encode (tagsBytes ),
468
477
ItemBinary : make ([]byte , 0 ),
469
478
}
470
479
if _ , ok := data .(* os.File ); ok {
@@ -476,20 +485,6 @@ func newBundleItem(owner string, signatureType int, target, anchor string, data
476
485
}
477
486
478
487
func BundleItemSignData (d types.BundleItem ) ([]byte , error ) {
479
- var err error
480
- tagsBy := make ([]byte , 0 )
481
- if len (d .ItemBinary ) > 0 { // verify logic
482
- tagsBy , err = GetBundleItemTagsBytes (d .ItemBinary )
483
- if err != nil {
484
- return nil , err
485
- }
486
- } else {
487
- tagsBy , err = SerializeTags (d .Tags )
488
- if err != nil {
489
- return nil , err
490
- }
491
- }
492
-
493
488
// deep hash
494
489
dataList := make ([]interface {}, 0 )
495
490
dataList = append (dataList , Base64Encode ([]byte ("dataitem" )))
@@ -498,7 +493,7 @@ func BundleItemSignData(d types.BundleItem) ([]byte, error) {
498
493
dataList = append (dataList , d .Owner )
499
494
dataList = append (dataList , d .Target )
500
495
dataList = append (dataList , d .Anchor )
501
- dataList = append (dataList , Base64Encode ( tagsBy ) )
496
+ dataList = append (dataList , d . TagsBy )
502
497
if d .DataReader != nil {
503
498
dataList = append (dataList , d .DataReader )
504
499
} else {
@@ -641,9 +636,12 @@ func generateItemMetaBinary(d *types.BundleItem) ([]byte, error) {
641
636
return nil , errors .New ("anchorBytes length must 32" )
642
637
}
643
638
}
644
- tagsBytes , err := SerializeTags (d .Tags )
645
- if err != nil {
646
- return nil , err
639
+ tagsBytes := make ([]byte , 0 )
640
+ if len (d .Tags ) > 0 {
641
+ tagsBytes , err = Base64Decode (d .TagsBy )
642
+ if err != nil {
643
+ return nil , err
644
+ }
647
645
}
648
646
649
647
sigMeta , ok := types .SigConfigMap [d .SignatureType ]
0 commit comments