Skip to content
This repository was archived by the owner on Jul 20, 2021. It is now read-only.

Commit 9e641e8

Browse files
committed
Research: a Rivine address can be recreated from a stellar one if created from the same private key
1 parent f86d703 commit 9e641e8

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

research/stellar/examples/accounts/convert.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/stellar/go/keypair"
9+
"github.com/stellar/go/strkey"
910

1011
"github.com/threefoldtech/rivine/crypto"
1112
"github.com/threefoldtech/rivine/modules"
@@ -30,13 +31,12 @@ func main() {
3031
if err != nil {
3132
panic("ERROR hashing the seed and the index")
3233
}
33-
fmt.Printf("Rivine and stellar private key: %x\n", h)
34+
fmt.Printf("Private key (1st one generated from the seed): %x\n", h[:])
3435
//Rivine
35-
rawrivinePublicKey, rawrivineSecretKey, err := ed25519.GenerateKey(bytes.NewReader(h[:]))
36+
rawrivinePublicKey, _, err := ed25519.GenerateKey(bytes.NewReader(h[:]))
3637
if err != nil {
3738
panic("ERROR generating the ed25519 key")
3839
}
39-
fmt.Printf("Generated rivine ed25519 private key (len=%d): %x\n", len(rawrivineSecretKey), rawrivineSecretKey)
4040
var rivinePublicKey crypto.PublicKey
4141
copy(rivinePublicKey[:], rawrivinePublicKey)
4242
rivineUnlockHash, err := types.NewEd25519PubKeyUnlockHash(rivinePublicKey)
@@ -50,7 +50,18 @@ func main() {
5050
if err != nil {
5151
panic("ERROR generating the stellar keypair ")
5252
}
53-
fmt.Println("Stellar Seed:", stellarKeypair.Seed())
54-
fmt.Println("Stellar address:", stellarKeypair.Address())
53+
stellarSeed := stellarKeypair.Seed()
54+
fmt.Println("Stellar Seed:", stellarSeed)
55+
stellarAddress := stellarKeypair.Address()
56+
fmt.Println("Stellar address:", stellarAddress)
5557

58+
//Back to Rivine
59+
decodedStellarPK := strkey.MustDecode(strkey.VersionByteAccountID, stellarAddress)
60+
copy(rivinePublicKey[:], decodedStellarPK)
61+
62+
rivineFromstellarUnlockHash, err := types.NewEd25519PubKeyUnlockHash(rivinePublicKey)
63+
if err != nil {
64+
panic("ERROR generating the rivine unlockhash from the decoded stellar address")
65+
}
66+
fmt.Println("Rivine address from Stellar address:", rivineFromstellarUnlockHash.String())
5667
}

research/stellar/examples/accounts/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To run:
2424

2525
- transfer.go
2626

27-
Tranfers an amount from an account to a destination address
27+
Transfers an amount from an account to a destination address
2828

2929
## Rivine key conversion
3030

@@ -33,10 +33,10 @@ Rivine hashes the public key along with the key alorithm to create an unlockhash
3333

3434
Stellar also uses uses default ed25519 keys.
3535
A Stellar seed is just a base32 encoded concatatantion of a versionbyte, a 32byte private key and a checksum.
36-
An address is the rawseed used to create an ed25519 keypair after which the versionbyte is concatenated with a checksum and base32 encoded.
36+
An address is the rawseed used to create an ed25519 keypair after which the versionbyte is concatenated with the public key and a checksum and base32 encoded.
3737

3838
The same 32 bytes can be used to create Rivine and Stellar keypairs.
3939

40-
It is possible to go from a Stellar account address to a Rivine "01"-address but not the reverse.
40+
It is possible to go from a Stellar account address to a Rivine "01"-address if they are created using the same private key (ed25519 entropy) but not the reverse.
4141

4242
`convert.go`

0 commit comments

Comments
 (0)