Skip to content

Instantly share code, notes, and snippets.

@robotamer
Created April 29, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotamer/a4256e722eb718711a2aacb9022f9d5a to your computer and use it in GitHub Desktop.
Save robotamer/a4256e722eb718711a2aacb9022f9d5a to your computer and use it in GitHub Desktop.
Skycoin Darkwallet Addresses #Skycoin #Crypto #Darkwallet
package main
import (
"fmt"
"github.com/skycoin/skycoin/src/cipher"
"log"
)
func main() {
// This is your private/public key pair. You give them the public key
pubkey1, seckey1, err := cipher.GenerateDeterministicKeyPair([]byte("Password"))
if err != nil {
log.Fatal(err)
}
// This is their key pair
pubkey2, seckey2 := cipher.GenerateKeyPair()
// They communicate pubkey2, by for instance using it as the first destination for coins in a transaction
// You know pubkey2, and seckey1/pubkey1
// They know your pubkey, pubkey1 and know their seckey seckey2/pubkey2
// Your computer
// Use your private key and the pubkey they gave you
secret1, err := cipher.ECDH(pubkey2, seckey1)
if err != nil {
log.Fatal(err)
}
// Their computer
// They use your pubkey and their private key
secret2, err := cipher.ECDH(pubkey1, seckey2)
if err != nil {
log.Fatal(err)
}
// Now you may compute an address from the secrets
pubkey3, _, err := cipher.GenerateDeterministicKeyPair(secret1)
if err != nil {
log.Fatal(err)
}
address1 := cipher.AddressFromPubKey(pubkey3) // send coins here
// Now you may compute an address from the them
pubkey4, _, err := cipher.GenerateDeterministicKeyPair(secret2)
if err != nil {
log.Fatal(err)
}
address2 := cipher.AddressFromPubKey(pubkey4) // send coins here
if address1 == address2 {
fmt.Printf("%s\n%s", address1, address2)
} else {
fmt.Println("Addresses don't match!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment