-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
90 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package libwallet | ||
|
||
import ( | ||
"math/big" | ||
) | ||
|
||
func paddedSerializeBigInt(size uint, x *big.Int) []byte { | ||
src := x.Bytes() | ||
dst := make([]byte, 0, size) | ||
|
||
for i := 0; i < int(size)-len(src); i++ { | ||
dst = append(dst, 0) | ||
} | ||
|
||
return append(dst, src...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package libwallet | ||
|
||
import ( | ||
"encoding/hex" | ||
"math/big" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func hexToBigInt(value string) *big.Int { | ||
result := &big.Int{} | ||
bytes, _ := hex.DecodeString(value) | ||
result.SetBytes(bytes) | ||
return result | ||
} | ||
|
||
func hexToBytes(value string) []byte { | ||
bytes, _ := hex.DecodeString(value) | ||
return bytes | ||
} | ||
|
||
func Test_paddedSerializeBigInt(t *testing.T) { | ||
|
||
type args struct { | ||
size uint | ||
x *big.Int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []byte | ||
}{ | ||
{ | ||
name: "31 bytes key", | ||
args: args{size: 32, x: hexToBigInt("0e815b7892396a2e28e09c0d50082931eedd7fec16ef2e06724fe48f877ea6")}, | ||
want: hexToBytes("000e815b7892396a2e28e09c0d50082931eedd7fec16ef2e06724fe48f877ea6"), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := paddedSerializeBigInt(tt.args.size, tt.args.x); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("paddedSerializeBigInt() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/muun/libwallet | ||
module libwallet | ||
|
||
go 1.12 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters