mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-02-05 16:54:21 +01:00
alice=client, bob=mint
This commit is contained in:
@@ -49,7 +49,7 @@ def hash_to_curve(secret_msg):
|
||||
return point
|
||||
|
||||
|
||||
def step1_bob(secret_msg):
|
||||
def step1_alice(secret_msg):
|
||||
secret_msg = secret_msg.encode("utf-8")
|
||||
Y = hash_to_curve(secret_msg)
|
||||
r = PrivateKey()
|
||||
@@ -57,12 +57,12 @@ def step1_bob(secret_msg):
|
||||
return B_, r
|
||||
|
||||
|
||||
def step2_alice(B_, a):
|
||||
def step2_bob(B_, a):
|
||||
C_ = B_.mult(a)
|
||||
return C_
|
||||
|
||||
|
||||
def step3_bob(C_, r, A):
|
||||
def step3_alice(C_, r, A):
|
||||
C = C_ - A.mult(r)
|
||||
return C
|
||||
|
||||
@@ -78,9 +78,9 @@ def verify(a, C, secret_msg):
|
||||
# a = PrivateKey()
|
||||
# A = a.pubkey
|
||||
# secret_msg = "test"
|
||||
# B_, r = step1_bob(secret_msg)
|
||||
# C_ = step2_alice(B_, a)
|
||||
# C = step3_bob(C_, r, A)
|
||||
# B_, r = step1_alice(secret_msg)
|
||||
# C_ = step2_bob(B_, a)
|
||||
# C = step3_alice(C_, r, A)
|
||||
# print("C:{}, secret_msg:{}".format(C, secret_msg))
|
||||
# assert verify(a, C, secret_msg)
|
||||
# assert verify(a, C + C, secret_msg) == False # adding C twice shouldn't pass
|
||||
|
||||
@@ -13,9 +13,14 @@ from core.secp import PrivateKey, PublicKey
|
||||
from core.settings import LIGHTNING, MAX_ORDER
|
||||
from core.split import amount_split
|
||||
from lightning import WALLET
|
||||
from mint.crud import (get_lightning_invoice, get_proofs_used,
|
||||
invalidate_proof, store_lightning_invoice,
|
||||
store_promise, update_lightning_invoice)
|
||||
from mint.crud import (
|
||||
get_lightning_invoice,
|
||||
get_proofs_used,
|
||||
invalidate_proof,
|
||||
store_lightning_invoice,
|
||||
store_promise,
|
||||
update_lightning_invoice,
|
||||
)
|
||||
|
||||
|
||||
class Ledger:
|
||||
@@ -58,7 +63,7 @@ class Ledger:
|
||||
async def _generate_promise(self, amount: int, B_: PublicKey):
|
||||
"""Generates a promise for given amount and returns a pair (amount, C')."""
|
||||
secret_key = self.keys[amount] # Get the correct key
|
||||
C_ = b_dhke.step2_alice(B_, secret_key)
|
||||
C_ = b_dhke.step2_bob(B_, secret_key)
|
||||
await store_promise(
|
||||
amount, B_=B_.serialize().hex(), C_=C_.serialize().hex(), db=self.db
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ class LedgerAPI:
|
||||
proofs = []
|
||||
for promise, (r, secret) in zip(promises, secrets):
|
||||
C_ = PublicKey(bytes.fromhex(promise.C_), raw=True)
|
||||
C = b_dhke.step3_bob(C_, r, self.keys[promise.amount])
|
||||
C = b_dhke.step3_alice(C_, r, self.keys[promise.amount])
|
||||
proof = Proof(amount=promise.amount, C=C.serialize().hex(), secret=secret)
|
||||
proofs.append(proof)
|
||||
return proofs
|
||||
@@ -74,7 +74,7 @@ class LedgerAPI:
|
||||
for amount in amounts:
|
||||
secret = self._generate_secret()
|
||||
secrets.append(secret)
|
||||
B_, r = b_dhke.step1_bob(secret)
|
||||
B_, r = b_dhke.step1_alice(secret)
|
||||
rs.append(r)
|
||||
payload: BlindedMessage = BlindedMessage(
|
||||
amount=amount, B_=B_.serialize().hex()
|
||||
@@ -101,7 +101,7 @@ class LedgerAPI:
|
||||
payloads: MintPayloads = MintPayloads()
|
||||
for output_amt in fst_outputs + snd_outputs:
|
||||
secret = self._generate_secret()
|
||||
B_, r = b_dhke.step1_bob(secret)
|
||||
B_, r = b_dhke.step1_alice(secret)
|
||||
secrets.append((r, secret))
|
||||
payload: BlindedMessage = BlindedMessage(
|
||||
amount=output_amt, B_=B_.serialize().hex()
|
||||
@@ -159,7 +159,7 @@ class Wallet(LedgerAPI):
|
||||
async def request_mint(self, amount):
|
||||
return super().request_mint(amount)
|
||||
|
||||
async def mint(self, amount, payment_hash=None):
|
||||
async def mint(self, amount: int, payment_hash: str = None):
|
||||
split = amount_split(amount)
|
||||
proofs = super().mint(split, payment_hash)
|
||||
if proofs == []:
|
||||
|
||||
Reference in New Issue
Block a user