-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(encryption): generated private key may already exist (#130)
- Loading branch information
1 parent
1dfb34e
commit 1aa7d6d
Showing
11 changed files
with
153 additions
and
77 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,7 @@ | ||
package test | ||
|
||
const ( | ||
Mnemonic1 = "artist silver basket insane canvas top drill social reflect park fruit bless" | ||
Mnemonic2 = "screen wrap color drop lady keep dwarf horror recipe gap ride garage" | ||
DerivationPath = "m/44'/60'/0'/0/0" | ||
) |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
package encryption | ||
|
||
import ( | ||
"fmt" | ||
"github.com/my-cloud/ruthenium/src/node/encryption" | ||
"github.com/my-cloud/ruthenium/test" | ||
"testing" | ||
) | ||
|
||
func Test_PrivateKeyFromMnemonic(t *testing.T) { | ||
// Arrange | ||
mnemonic := encryption.NewMnemonic(test.Mnemonic1) | ||
|
||
// Act | ||
privateKey, _ := mnemonic.PrivateKey(test.DerivationPath, "") | ||
|
||
// Assert | ||
expectedPrivateKey := "0x48913790c2bebc48417491f96a7e07ec94c76ccd0fe1562dc1749479d9715afd" | ||
actualPrivateKey := privateKey.String() | ||
test.Assert(t, actualPrivateKey == expectedPrivateKey, fmt.Sprintf("Wrong private key. Expected: %s - Actual: %s", expectedPrivateKey, actualPrivateKey)) | ||
} |
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,21 @@ | ||
package encryption | ||
|
||
import ( | ||
"fmt" | ||
"github.com/my-cloud/ruthenium/src/node/encryption" | ||
"github.com/my-cloud/ruthenium/test" | ||
"testing" | ||
) | ||
|
||
func Test_PublicKeyFromPrivateKey(t *testing.T) { | ||
// Arrange | ||
privateKey, _ := encryption.DecodePrivateKey("0x48913790c2bebc48417491f96a7e07ec94c76ccd0fe1562dc1749479d9715afd") | ||
|
||
// Act | ||
publicKey := encryption.NewPublicKey(privateKey) | ||
|
||
// Assert | ||
expectedPublicKey := "0x046bd857ce80ff5238d6561f3a775802453c570b6ea2cbf93a35a8a6542b2edbe5f625f9e3fbd2a5df62adebc27391332a265fb94340fb11b69cf569605a5df782" | ||
actualPublicKey := publicKey.String() | ||
test.Assert(t, actualPublicKey == expectedPublicKey, fmt.Sprintf("Wrong public key. Expected: %s - Actual: %s", expectedPublicKey, actualPublicKey)) | ||
} |
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,20 @@ | ||
package encryption | ||
|
||
import ( | ||
"fmt" | ||
"github.com/my-cloud/ruthenium/src/node/encryption" | ||
"github.com/my-cloud/ruthenium/test" | ||
"testing" | ||
) | ||
|
||
func Test_AddressFromPublicKey(t *testing.T) { | ||
// Arrange | ||
publicKey, _ := encryption.DecodePublicKey("0x046bd857ce80ff5238d6561f3a775802453c570b6ea2cbf93a35a8a6542b2edbe5f625f9e3fbd2a5df62adebc27391332a265fb94340fb11b69cf569605a5df782") | ||
|
||
// Act | ||
address := publicKey.Address() | ||
|
||
// Assert | ||
expectedAddress := "0x9C69443c3Ec0D660e257934ffc1754EB9aD039CB" | ||
test.Assert(t, address == expectedAddress, fmt.Sprintf("Wrong address. Expected: %s - Actual: %s", expectedAddress, address)) | ||
} |
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,53 @@ | ||
package encryption | ||
|
||
import ( | ||
"fmt" | ||
"github.com/my-cloud/ruthenium/src/node/encryption" | ||
"github.com/my-cloud/ruthenium/test" | ||
"testing" | ||
) | ||
|
||
func Test_DecodeWallet_PrivateKeyProvided_ReturnsWalletForPrivateKey(t *testing.T) { | ||
// Arrange | ||
expectedPrivateKey := "0x48913790c2bebc48417491f96a7e07ec94c76ccd0fe1562dc1749479d9715afd" | ||
|
||
// Act | ||
wallet, _ := encryption.DecodeWallet("", "", "", expectedPrivateKey) | ||
|
||
// Assert | ||
actualPrivateKey := wallet.PrivateKey().String() | ||
test.Assert(t, actualPrivateKey == expectedPrivateKey, fmt.Sprintf("Wrong private key. Expected: %s - Actual: %s", expectedPrivateKey, actualPrivateKey)) | ||
} | ||
|
||
func Test_DecodeWallet_BothPrivateKeyAndMnemonicAreEmpty_ReturnsEmptyWallet(t *testing.T) { | ||
// Act | ||
wallet, _ := encryption.DecodeWallet("", "", "", "") | ||
|
||
// Assert | ||
test.Assert(t, wallet.PrivateKey() == nil, "Private key is not nil whereas it should be.") | ||
} | ||
|
||
func Test_MarshalJSON_ValidPrivateKey_ReturnsMarshaledJsonWithoutError(t *testing.T) { | ||
// Arrange | ||
privateKey := "0x48913790c2bebc48417491f96a7e07ec94c76ccd0fe1562dc1749479d9715afd" | ||
wallet, _ := encryption.DecodeWallet("", "", "", privateKey) | ||
|
||
// Act | ||
marshaledWallet, err := wallet.MarshalJSON() | ||
|
||
// Assert | ||
test.Assert(t, marshaledWallet != nil, "Marshaled wallet is nil.") | ||
test.Assert(t, err == nil, "Marshal wallet returned an error.") | ||
} | ||
|
||
func Test_MarshalJSON_EmptyWallet_ReturnsMarshaledJsonWithoutError(t *testing.T) { | ||
// Arrange | ||
wallet := encryption.NewEmptyWallet() | ||
|
||
// Act | ||
marshaledWallet, err := wallet.MarshalJSON() | ||
|
||
// Assert | ||
test.Assert(t, marshaledWallet != nil, "Marshaled wallet is nil.") | ||
test.Assert(t, err == nil, "Marshal wallet returned an error.") | ||
} |
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