Esempio n. 1
0
func NewUpdateTxn(onlineSecret, offlineSecret crypto.CertcoinSecretKey,
	source crypto.CertcoinPublicKey,
	identity Identity) Txn {

	fullName := identity.FullName()
	return Txn{
		Type: Update,
		Inputs: []Input{
			Input{
				PrevHash:  identity.Domain,
				PublicKey: onlineSecret.PublicKey,
				Signature: crypto.Sign(fullName, onlineSecret),
			},
			Input{
				PrevHash:  identity.Subdomain,
				PublicKey: offlineSecret.PublicKey,
				Signature: crypto.Sign(fullName, offlineSecret),
			},
			Input{
				PrevHash:  crypto.SHA256Sum{},
				PublicKey: source,
				Signature: crypto.CertcoinSignature{},
			},
		},
		Outputs: []Output{
			Output{
				Address: crypto.SHA256Sum{},
				Value:   UPDATE_FEE,
			},
		},
	}
}
Esempio n. 2
0
func NewRevokeTxn(onlineSecret, offlineSecret crypto.CertcoinSecretKey,
	source crypto.CertcoinPublicKey,
	identity Identity) Txn {

	sig := crypto.Sign(identity.FullName(), onlineSecret)
	log.Println("Signature:", sig)
	verifies := crypto.Verify(identity.FullName(), sig, onlineSecret.PublicKey)
	log.Println("PublicKey:", onlineSecret.PublicKey)
	log.Println("Signature:", sig)
	log.Println("Verifies:", verifies)

	return Txn{
		Type: Revoke,
		Inputs: []Input{
			Input{
				PrevHash:  identity.Domain,
				PublicKey: onlineSecret.PublicKey,
				Signature: sig,
			},
			Input{
				PrevHash:  identity.Subdomain,
				PublicKey: offlineSecret.PublicKey,
				Signature: sig,
			},
			Input{
				PrevHash:  crypto.SHA256Sum{},
				PublicKey: source,
				Signature: sig,
			},
		},
		Outputs: []Output{
			Output{
				Address: crypto.SHA256Sum{},
				Value:   REVOKE_FEE,
			},
		},
	}
}
Esempio n. 3
0
func Mine() {
	bc := NewBlockchain()

	g := GenesisBlock()
	for !g.Header.ValidPoW() {
		g.Header.Nonce += 1
	}
	fmt.Println(fmt.Sprintf("Gen: %v", string(g.Json())))

	fromKey := crypto.NewKey()
	toKey := crypto.NewKey()

	online := crypto.NewKey()
	offline := crypto.NewKey()

	//for {
	b := NewBlock(bc.LastHeader, crypto.Address(fromKey.PublicKey))

	// Create and sign txn
	txn := NewPaymentTxn(fromKey.PublicKey, crypto.Address(toKey.PublicKey), 10)
	txn.Inputs[0].Signature = crypto.Sign("", fromKey)
	b.Txns = append(b.Txns, txn)

	identity, err := NewIdentity("certcoin.net", "")
	if err != nil {
		fmt.Println(err)
		panic(err)
	}

	// Create and sign registration txn
	rtxn := NewRegisterTxn(online, offline, fromKey.PublicKey, identity)
	rtxn.Inputs[2].Signature = crypto.Sign("", fromKey)
	b.Txns = append(b.Txns, rtxn)

	newOnline := crypto.NewKey()
	// Create and sign update txn
	utxn := NewUpdateTxn(newOnline, offline, fromKey.PublicKey, identity)
	utxn.Inputs[1].Signature = crypto.Sign("", offline)
	utxn.Inputs[2].Signature = crypto.Sign("", fromKey)
	b.Txns = append(b.Txns, utxn)

	// Create and sign revoke txn
	vtxn := NewRevokeTxn(newOnline, offline, fromKey.PublicKey, identity)
	b.Txns = append(b.Txns, vtxn)

	for !b.Header.ValidPoW() {
		b.Header.Nonce += 1
	}

	//fmt.Println(fmt.Sprintf("%v", b.Json()))
	//fmt.Println(b.Header.Hash())

	if bc.ValidBlock(b) {
		err = bc.WriteBlock(b)
		if err != nil {
			log.Println(err)
			panic("Unable to save block")
		} else {
			fmt.Println("Saved block successfully")
		}
	} else {
		fmt.Println("Invalid Block")
	}
	//}
}