Skip to content

Instantly share code, notes, and snippets.

@dcb9
Last active December 10, 2024 14:36
Show Gist options
  • Save dcb9/a9936b59c1d9cd8a08ff874ca734e8c9 to your computer and use it in GitHub Desktop.
Save dcb9/a9936b59c1d9cd8a08ff874ca734e8c9 to your computer and use it in GitHub Desktop.

Revisions

  1. Du, Chengbin revised this gist May 22, 2024. No changes.
  2. Du, Chengbin revised this gist May 22, 2024. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions extractable-one-time-signatures-example-in-go.go
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@ import (
    "fmt"

    "github.com/babylonchain/babylon/crypto/eots"
    "github.com/btcsuite/btcd/chaincfg/chainhash"
    )

    func main() {
    @@ -15,15 +14,15 @@ func main() {
    privateRand, publicRand, _ := eots.RandGen(rand.Reader)

    // sign for message 1
    h1 := chainhash.HashB([]byte("hello"))
    h1 := []byte("hello")
    s1, _ := eots.Sign(secretKey, privateRand, h1)

    // sign for message 2
    h2 := chainhash.HashB([]byte("world"))
    h2 := []byte("world")
    s2, _ := eots.Sign(secretKey, privateRand, h2)

    // extract private key
    extractedKey, _ := eots.Extract(publicKey, publicRand, h1, s1, h2, s2)
    fmt.Println(" original secret key:", secretKey)
    fmt.Println("extracted secret key:", extractedKey)
    }
    }
  3. Du, Chengbin revised this gist May 22, 2024. No changes.
  4. Du, Chengbin created this gist May 22, 2024.
    29 changes: 29 additions & 0 deletions extractable-one-time-signatures-example-in-go.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    package main

    import (
    "crypto/rand"
    "fmt"

    "github.com/babylonchain/babylon/crypto/eots"
    "github.com/btcsuite/btcd/chaincfg/chainhash"
    )

    func main() {
    // Generate keys
    secretKey, _ := eots.KeyGen(rand.Reader)
    publicKey := eots.PubGen(secretKey)
    privateRand, publicRand, _ := eots.RandGen(rand.Reader)

    // sign for message 1
    h1 := chainhash.HashB([]byte("hello"))
    s1, _ := eots.Sign(secretKey, privateRand, h1)

    // sign for message 2
    h2 := chainhash.HashB([]byte("world"))
    s2, _ := eots.Sign(secretKey, privateRand, h2)

    // extract private key
    extractedKey, _ := eots.Extract(publicKey, publicRand, h1, s1, h2, s2)
    fmt.Println(" original secret key:", secretKey)
    fmt.Println("extracted secret key:", extractedKey)
    }