Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Next Generation Cryptographic Wallet for Documents, Blockchains and Verifiable Credentials

License

Notifications You must be signed in to change notification settings

Electronic-Signatures-Industries/go-xdv-wallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-xdv-wallet

Next Generation Cryptographic Wallet for Documents, Blockchains and Verifiable Credentials

Example

package main

import (
	"bytes"
	"crypto"
	"golang.org/x/crypto/ed25519"
	"log"
)

type zeroReader struct{}

func (zeroReader) Read(buf []byte) (int, error) {
	for i := range buf {
		buf[i] = 0
	}
	return len(buf), nil
}

func TestSignVerify() {
	var zero zeroReader
	public, private, _ := ed25519.GenerateKey(zero)
	
	message := []byte("test message")
	sig := ed25519.Sign(private, message)
	log.Println(ed25519.Verify(public, message, sig))
	
	wrongMessage := []byte("wrong message")
	log.Println(ed25519.Verify(public, wrongMessage, sig))
}

func TestCryptoSigner() {
	var zero zeroReader
	public, private, _ := ed25519.GenerateKey(zero)
	
	signer := crypto.Signer(private)
	
	publicInterface := signer.Public()
	public2, ok := publicInterface.(ed25519.PublicKey)
	if !ok {
		log.Fatalf("expected PublicKey from Public() but got %T", publicInterface)
	}
	
	if !bytes.Equal(public, public2) {
		log.Fatalf("public keys do not match: original:%x vs Public():%x", public, public2)
	}
	
	message := []byte("message")
	var noHash crypto.Hash
	signature, err := signer.Sign(zero, message, noHash)
	if err != nil {
		log.Fatalf("error from Sign(): %s", err)
	}
	
	log.Println(ed25519.Verify(public, message, signature))
}

func main() {
	TestSignVerify()
	TestCryptoSigner()
}

About

Next Generation Cryptographic Wallet for Documents, Blockchains and Verifiable Credentials

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages