Ejemplo n.º 1
0
func GenerateAddressFromPrivateKey(name string, privateKey string) (factoid.IAddress, error) {
	if Utility.IsValidKey(name) == false {
		return nil, fmt.Errorf("Invalid name or address")
	}
	if len(privateKey) != 64 && len(privateKey) != 128 {
		return nil, fmt.Errorf("Invalid private key length")
	}
	if Utility.IsValidHex(privateKey) == false {
		return nil, fmt.Errorf("Invalid private key format")
	}
	priv, err := hex.DecodeString(privateKey)
	if err != nil {
		return nil, err
	}
	addr, err := factoidState.GetWallet().GenerateFctAddressFromPrivateKey([]byte(name), priv, 1, 1)
	if err != nil {
		return nil, err
	}
	return addr, nil
}
Ejemplo n.º 2
0
func HandleFactoidGenerateECAddressFromPrivateKey(ctx *web.Context, params string) {
	name := ctx.Params["name"]
	privateKey := ctx.Params["privateKey"]
	if Utility.IsValidKey(name) == false {
		reportResults(ctx, "Name provided is not valid", false)
		return
	}
	if len(privateKey) != 64 && len(privateKey) != 128 {
		reportResults(ctx, "Invalid private key length", false)
		return
	}
	if Utility.IsValidHex(privateKey) == false {
		reportResults(ctx, "Invalid private key format", false)
		return
	}

	adrstr, err := Wallet.GenerateECAddressStringFromPrivateKey(name, privateKey)
	if err != nil {
		reportResults(ctx, err.Error(), false)
		return
	}

	reportResults(ctx, adrstr, true)
}