Exemple #1
0
func InitializeBalance() {
	var once sync.Once
	onceBody := func() {
		w, err := wallet.NewMapDBWallet()
		if err != nil {
			panic(err)
		}

		fa, err := factom.GetFactoidAddress(FaucetAddressPriv)
		err = w.InsertFCTAddress(fa)
		if err != nil {
			panic(err)
		}

		priv, _, _ := testHelper.NewFactoidAddressStrings(Seed)

		FKey, err = primitives.NewPrivateKeyFromHex(priv)
		if err != nil {
			panic(err)
		}
		ECKey, err = primitives.NewPrivateKeyFromHex(priv)
		if err != nil {
			panic(err)
		}

		FAddressStr, err = factoid.PublicKeyStringToFactoidAddressString(FKey.PublicKeyString())
		if err != nil {
			panic(err)
		}

		ECAddressStr, err = factoid.PublicKeyStringToECAddressString(ECKey.PublicKeyString())
		if err != nil {
			panic(err)
		}

		ECAddress, err = factom.MakeECAddress(ECKey.Key[:32])
		if err != nil {
			panic(err)
		}

		go wsapi.Start(w, fmt.Sprintf(":%d", 8089))
		defer func() {
			time.Sleep(10 * time.Millisecond)
			wsapi.Stop()
		}()

		TopupFAddress()
		TopupECAddress()
	}
	once.Do(onceBody)
}
func TestMarshalUnmarshalAnchorRecordV2(t *testing.T) {
	record := `{"AnchorRecordVer":1,"DBHeight":5,"KeyMR":"980ab6d50d9fad574ad4df6dba06a8c02b1c67288ee5beab3fbfde2723f73ef6","RecordHeight":6,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"e2ac71c9c0fd8edc0be8c0ba7098b77fb7d90dcca755d5b9348116f3f9d9f951","BlockHeight":372576,"BlockHash":"000000000000000003059382ed4dd82b2086e99ec78d1b6e811ebb9d53d8656d","Offset":1144}}`
	ar, err := UnmarshalAnchorRecord([]byte(record))
	if err != nil {
		t.Error(err)
	}

	priv := "ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973"
	pk1, err := primitives.NewPrivateKeyFromHex(priv)
	if err != nil {
		t.Error(err)
	}

	data, sig, err := ar.MarshalAndSignV2(pk1)
	if err != nil {
		t.Error(err)
	}

	if primitives.AreBytesEqual([]byte(record), data) == false {
		t.Errorf("Anchors are not equal\n%s\nvs\n%s", record, string(data))
	}

	ar, valid, err := UnmarshalAndValidateAnchorRecordV2(data, [][]byte{sig}, pk1.Pub)
	if err != nil {
		t.Error(err)
	}
	if valid != true {
		t.Errorf("Anchor record is not valid")
	}
	if ar == nil {
		t.Errorf("No anchor record returned!")
	}
}
Exemple #3
0
func (s *State) initServerKeys() {
	var err error
	s.serverPrivKey, err = primitives.NewPrivateKeyFromHex(s.GetCfg().(*util.FactomdConfig).App.LocalServerPrivKey)
	if err != nil {
		//panic("Cannot parse Server Private Key from configuration file: " + err.Error())
	}
	s.serverPubKey = primitives.PubKeyFromString(constants.SERVER_PUB_KEY)
}
func newSignedDirectoryBlockSignature() *DirectoryBlockSignature {
	dbs := newDirectoryBlockSignature()
	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		panic(err)
	}
	err = dbs.Sign(key)
	if err != nil {
		panic(err)
	}
	return dbs
}
Exemple #5
0
func (a *Anchor) readConfig() {
	anchorLog.Info("readConfig")
	a.cfg = util.ReadConfig("")
	a.confirmationsNeeded = a.cfg.Anchor.ConfirmationsNeeded
	a.fee, _ = btcutil.NewAmount(a.cfg.Btc.BtcTransFee)

	var err error
	a.serverPrivKey, err = primitives.NewPrivateKeyFromHex(a.cfg.App.LocalServerPrivKey)
	if err != nil {
		panic("Cannot parse Server Private Key from configuration file: " + err.Error())
	}
	a.serverECKey, err = primitives.NewPrivateKeyFromHex(a.cfg.Anchor.ServerECPrivKey)
	if err != nil {
		panic("Cannot parse Server EC Key from configuration file: " + err.Error())
	}
	a.anchorChainID, err = primitives.HexToHash(a.cfg.Anchor.AnchorChainID)
	anchorLog.Debug("anchorChainID: ", a.anchorChainID)
	if err != nil || a.anchorChainID == nil {
		panic("Cannot parse Server AnchorChainID from configuration file: " + err.Error())
	}
}
func newSignedCommitChain() *CommitChainMsg {
	msg := newCommitChain()

	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		panic(err)
	}
	err = msg.Sign(key)
	if err != nil {
		panic(err)
	}

	return msg
}
func newSignedChangeServerKey() *ChangeServerKeyMsg {
	addserv := newChangeServerKey()

	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		panic(err)
	}
	err = addserv.Sign(key)
	if err != nil {
		panic(err)
	}

	return addserv
}
func newSignedHeartbeat() *Heartbeat {
	ack := newHeartbeat()

	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		panic(err)
	}
	err = ack.Sign(key)
	if err != nil {
		panic(err)
	}

	return ack
}
Exemple #9
0
func TestSignAndVerifyAck(t *testing.T) {
	ack := newAck()
	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		t.Error(err)
	}
	err = ack.Sign(&key)
	if err != nil {
		t.Error(err)
	}
	hex, err := ack.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	t.Logf("Marshalled - %x", hex)

	t.Logf("Sig - %x", *ack.Signature.GetSignature())
	if len(*ack.Signature.GetSignature()) == 0 {
		t.Error("Signature not present")
	}

	valid, err := ack.VerifySignature()
	if err != nil {
		t.Error(err)
	}
	if valid == false {
		t.Error("Signature is not valid")
	}

	ack2, err := UnmarshalMessage(hex)
	if err != nil {
		t.Error(err)
	}

	if ack2.Type() != constants.ACK_MSG {
		t.Error("Invalid message type unmarshalled")
	}
	ackProper := ack2.(*Ack)

	valid, err = ackProper.VerifySignature()
	if err != nil {
		t.Error(err)
	}
	if valid == false {
		t.Error("Signature 2 is not valid")
	}

}
func TestSignAndVerifyDirectoryBlockSignature(t *testing.T) {
	dbs := newDirectoryBlockSignature()
	key, err := primitives.NewPrivateKeyFromHex("07c0d52cb74f4ca3106d80c4a70488426886bccc6ebc10c6bafb37bf8a65f4c38cee85c62a9e48039d4ac294da97943c2001be1539809ea5f54721f0c5477a0a")
	if err != nil {
		t.Error(err)
	}
	err = dbs.Sign(&key)
	if err != nil {
		t.Error(err)
	}
	hex, err := dbs.MarshalBinary()
	if err != nil {
		t.Error(err)
	}
	t.Logf("Marshalled - %x", hex)

	t.Logf("Sig - %x", *dbs.Signature.GetSignature())
	if len(*dbs.Signature.GetSignature()) == 0 {
		t.Error("Signature not present")
	}

	valid, err := dbs.VerifySignature()
	if err != nil {
		t.Error(err)
	}
	if valid == false {
		t.Error("Signature is not valid")
	}

	dbs2, err := UnmarshalMessage(hex)
	if err != nil {
		t.Error(err)
	}

	if dbs2.Type() != constants.DIRECTORY_BLOCK_SIGNATURE_MSG {
		t.Error("Invalid message type unmarshalled")
	}
	dbsProper := dbs2.(*DirectoryBlockSignature)

	valid, err = dbsProper.VerifySignature()
	if err != nil {
		t.Error(err)
	}
	if valid == false {
		t.Error("Signature 2 is not valid")
	}

}