Skip to content

Instantly share code, notes, and snippets.

@robotamer
Created April 29, 2019 08:34
Show Gist options
  • Save robotamer/a4256e722eb718711a2aacb9022f9d5a to your computer and use it in GitHub Desktop.
Save robotamer/a4256e722eb718711a2aacb9022f9d5a to your computer and use it in GitHub Desktop.

Revisions

  1. robotamer created this gist Apr 29, 2019.
    56 changes: 56 additions & 0 deletions darkwallet-test.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    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!")
    }
    }