Beispiel #1
0
func (bc *Blockchain) ValidRegisterTxn(t Txn) bool {
	if !t.ValidNumInputs(2) || !t.ValidNumOutputs() {
		return false
	}

	domain := t.Inputs[0].PrevHash.String()
	subdomain := t.Inputs[1].PrevHash.String()

	identity, err := NewIdentity(domain, subdomain)
	if err != nil {
		log.Println(err)
		return false
	}

	// Check that Identity is not registered
	// Check that Identity-PKs is not in accumulator

	return t.Type == Register &&
		t.Outputs[0].Value >= REGISTRATION_FEE &&
		crypto.Verify(identity.FullName(), t.Inputs[0].Signature, t.Inputs[0].PublicKey) &&
		crypto.Verify(identity.FullName(), t.Inputs[1].Signature, t.Inputs[1].PublicKey)
}
Beispiel #2
0
func (bc *Blockchain) ValidUpdateTxn(t Txn) bool {
	if !t.ValidNumInputs(2) || !t.ValidNumOutputs() {
		return false
	}

	domain := t.Inputs[0].PrevHash.String()
	subdomain := t.Inputs[1].PrevHash.String()

	identity, err := NewIdentity(domain, subdomain)
	if err != nil {
		return false
	}

	// offlinePK := lookup from database

	return t.Type == Update &&
		t.Outputs[0].Value >= UPDATE_FEE &&
		crypto.Verify(identity.FullName(), t.Inputs[0].Signature, t.Inputs[0].PublicKey)
	//crypto.Verify(identity.FullName(), t.OfflineSignature, offlinePK)
}
Beispiel #3
0
func (bc *Blockchain) ValidRevokeTxn(t Txn) bool {
	if !t.ValidNumInputs(2) || !t.ValidNumOutputs() {
		return false
	}

	fmt.Println("Txn: %v", t)

	domain := t.Inputs[0].PrevHash.String()
	subdomain := t.Inputs[1].PrevHash.String()

	identity, err := NewIdentity(domain, subdomain)
	if err != nil {
		return false
	}

	// offlinePK := lookup from database

	return t.Type == Revoke &&
		t.Outputs[0].Value >= REVOKE_FEE &&
		crypto.Verify(identity.FullName(), t.Inputs[0].Signature, t.Inputs[0].PublicKey)
}
Beispiel #4
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,
			},
		},
	}
}