feat: Add import wallet from seed
All checks were successful
Build Docker / Build Image (push) Successful in 31s

This commit is contained in:
Nathan Woodburn 2024-02-04 16:55:28 +11:00
parent 441a0274ff
commit f692cacc41
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
6 changed files with 144 additions and 6 deletions

View File

@ -42,6 +42,8 @@ sudo docker run -p 5000:5000 -e hsd_api=yourapikeyhere -e hsd_ip=hsdcontainer gi
## Features
- Basic wallet functionality
- Create new wallet
- Import wallet from seed
- Send HNS
- Receive HNS
- Have multiple wallets

View File

@ -84,6 +84,31 @@ def createWallet(account: str, password: str):
"password": password
}
def importWallet(account: str, password: str,seed: str):
# Import the wallet
data = {
"passphrase": password,
"mnemonic": seed,
}
response = requests.put(f"http://x:{APIKEY}@{ip}:12039/wallet/{account}",json=data)
print(response)
print(response.json())
if response.status_code != 200:
return {
"error": {
"message": "Error creating account"
}
}
return {
"seed": seed,
"account": account,
"password": password
}
def listWallets():
# List the wallets
response = hsw.listWallets()
@ -461,7 +486,21 @@ def finalize(account,domain):
}
try:
response = hsw.sendFINALIZE(account_name,password,domain)
response = hsw.rpc_selectWallet(account_name)
if response['error'] is not None:
return {
"error": {
"message": response['error']['message']
}
}
response = hsw.rpc_walletPassphrase(password,10)
if response['error'] is not None:
return {
"error": {
"message": response['error']['message']
}
}
response = hsw.rpc_sendFINALIZE(domain)
return response
except Exception as e:
return {

48
main.py
View File

@ -391,11 +391,11 @@ def finalize(domain: str):
domain = domain.lower()
print(domain)
response = account_module.finalize(request.cookies.get("account"),domain)
if 'error' in response:
if response['error'] != None:
print(response)
return redirect("/manage/" + domain + "?error=" + response['error']['message'])
return redirect("/success?tx=" + response['hash'])
return redirect("/success?tx=" + response['result']['hash'])
@app.route('/manage/<domain>/cancel')
def cancelTransfer(domain: str):
@ -966,6 +966,50 @@ def register():
response.set_cookie("account", account+":"+password)
return response
@app.route('/import-wallet', methods=["POST"])
def import_wallet():
# Get the account and password
account = request.form.get("name")
password = request.form.get("password")
repeatPassword = request.form.get("password_repeat")
seed = request.form.get("seed")
# Check if the passwords match
if password != repeatPassword:
return render_template("import-wallet.html",
error="Passwords do not match",
name=account,password=password,password_repeat=repeatPassword,
seed=seed)
# Check if the account is valid
if account.count(":") > 0:
return render_template("import-wallet.html",
error="Invalid account",
name=account,password=password,password_repeat=repeatPassword,
seed=seed)
# List wallets
wallets = account_module.listWallets()
if account in wallets:
return render_template("import-wallet.html",
error="Account already exists",
name=account,password=password,password_repeat=repeatPassword,
seed=seed)
# Create the account
response = account_module.importWallet(account,password,seed)
if 'error' in response:
return render_template("import-wallet.html",
error=response['error'],
name=account,password=password,password_repeat=repeatPassword,
seed=seed)
# Set the cookie
response = make_response(redirect("/"))
response.set_cookie("account", account+":"+password)
return response
@app.route('/report')
def report():

View File

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html data-bs-theme="dark" lang="en-au">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Import Wallet - FireWallet</title>
<link rel="icon" type="image/png" sizes="900x768" href="/assets/img/favicon.png">
<link rel="icon" type="image/png" sizes="900x768" href="/assets/img/favicon.png">
<link rel="icon" type="image/png" sizes="900x768" href="/assets/img/favicon.png">
<link rel="icon" type="image/png" sizes="900x768" href="/assets/img/favicon.png">
<link rel="icon" type="image/png" sizes="900x768" href="/assets/img/favicon.png">
<link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i&amp;display=swap">
<link rel="stylesheet" href="/assets/css/styles.min.css">
</head>
<body class="bg-gradient-primary">
<div class="container">
<div class="card shadow-lg o-hidden border-0 my-5">
<div class="card-body p-0">
<div class="row">
<div class="col-lg-5 d-none d-lg-flex">
<div class="flex-grow-1 bg-register-image" style="background: url(&quot;/assets/img/favicon.png&quot;) center / contain no-repeat;"></div>
</div>
<div class="col-lg-7">
<div class="p-5">
<h1 class="text-center" style="color: rgb(255,0,0);">{{error}}</h1>
<div class="text-center">
<h4 class="text-dark mb-4">Import a wallet!</h4>
</div>
<form class="user" method="post">
<div class="row mb-3" style="padding-right: 16px;padding-left: 16px;"><input class="form-control form-control-user" type="text" id="exampleLastName" placeholder="Wallet name" name="name" value="{{name}}"></div>
<div class="row mb-3">
<div class="col-sm-6 mb-3 mb-sm-0"><input class="form-control form-control-user" type="password" id="examplePasswordInput" placeholder="Password" name="password" required="" value="{{password}}"></div>
<div class="col-sm-6"><input class="form-control form-control-user" type="password" id="exampleRepeatPasswordInput" placeholder="Repeat Password" name="password_repeat" required="" value="{{password_repeat}}"></div>
</div>
<div style="margin-bottom: 16px;"><textarea class="form-control form-control-lg" placeholder="Seed Phrase" name="seed" rows="1" style="height: 7em;">{{seed}}</textarea></div><button class="btn btn-primary d-block btn-user w-100" type="submit">Import Wallet</button>
<hr>
</form>
<div class="text-center"><a class="small" href="/login">Didn't mean to create a new wallet? Login!</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="/assets/bootstrap/js/bootstrap.min.js"></script>
<script src="/assets/js/script.min.js"></script>
</body>
</html>

View File

@ -37,7 +37,8 @@
<div class="mb-3"><input class="form-control form-control-user" type="password" id="exampleInputPassword" placeholder="Password" name="password"></div><button class="btn btn-primary d-block btn-user w-100" type="submit">Login</button>
<hr>
</form>
<div class="text-center"><a class="small" href="register">Create a wallet!</a></div>
<div class="text-center"><a class="small" href="register">Create a wallet</a></div>
<div class="text-center"><a class="small" href="import-wallet">Import an existing wallet</a></div>
</div>
</div>
</div>

View File

@ -27,14 +27,14 @@
<div class="p-5">
<h1 class="text-center" style="color: rgb(255,0,0);">{{error}}</h1>
<div class="text-center">
<h4 class="text-dark mb-4">Create an Account!</h4>
<h4 class="text-dark mb-4">Create a new wallet!</h4>
</div>
<form class="user" method="post">
<div class="row mb-3" style="padding-right: 16px;padding-left: 16px;"><input class="form-control form-control-user" type="text" id="exampleLastName" placeholder="Wallet name" name="name" value="{{name}}"></div>
<div class="row mb-3">
<div class="col-sm-6 mb-3 mb-sm-0"><input class="form-control form-control-user" type="password" id="examplePasswordInput" placeholder="Password" name="password" required="" value="{{password}}"></div>
<div class="col-sm-6"><input class="form-control form-control-user" type="password" id="exampleRepeatPasswordInput" placeholder="Repeat Password" name="password_repeat" required="" value="{{password_repeat}}"></div>
</div><button class="btn btn-primary d-block btn-user w-100" type="submit">Register Account</button>
</div><button class="btn btn-primary d-block btn-user w-100" type="submit">Create Wallet</button>
<hr>
</form>
<div class="text-center"><a class="small" href="/login">Didn't mean to create a new wallet? Login!</a></div>