mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 03:24:18 +01:00
Coalesce all witness fields to Proof.witness (#342)
* call proofs field witness * test p2pk sig_all=True * outputs also use witness field
This commit is contained in:
@@ -9,7 +9,6 @@ from pydantic import BaseModel
|
||||
from .crypto.keys import derive_keys, derive_keyset_id, derive_pubkeys
|
||||
from .crypto.secp import PrivateKey, PublicKey
|
||||
from .legacy import derive_keys_backwards_compatible_insecure_pre_0_12
|
||||
from .p2pk import P2SHScript
|
||||
|
||||
|
||||
class DLEQ(BaseModel):
|
||||
@@ -34,6 +33,41 @@ class DLEQWallet(BaseModel):
|
||||
# ------- PROOFS -------
|
||||
|
||||
|
||||
class HTLCWitness(BaseModel):
|
||||
preimage: Optional[str] = None
|
||||
signature: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def from_witness(cls, witness: str):
|
||||
return cls(**json.loads(witness))
|
||||
|
||||
|
||||
class P2SHWitness(BaseModel):
|
||||
"""
|
||||
Unlocks P2SH spending condition of a Proof
|
||||
"""
|
||||
|
||||
script: str
|
||||
signature: str
|
||||
address: Union[str, None] = None
|
||||
|
||||
@classmethod
|
||||
def from_witness(cls, witness: str):
|
||||
return cls(**json.loads(witness))
|
||||
|
||||
|
||||
class P2PKWitness(BaseModel):
|
||||
"""
|
||||
Unlocks P2PK spending condition of a Proof
|
||||
"""
|
||||
|
||||
signatures: List[str]
|
||||
|
||||
@classmethod
|
||||
def from_witness(cls, witness: str):
|
||||
return cls(**json.loads(witness))
|
||||
|
||||
|
||||
class Proof(BaseModel):
|
||||
"""
|
||||
Value token
|
||||
@@ -46,10 +80,11 @@ class Proof(BaseModel):
|
||||
C: str = "" # signature on secret, unblinded by wallet
|
||||
dleq: Union[DLEQWallet, None] = None # DLEQ proof
|
||||
|
||||
p2pksigs: Union[List[str], None] = [] # P2PK signature
|
||||
p2shscript: Union[P2SHScript, None] = None # P2SH spending condition
|
||||
htlcpreimage: Union[str, None] = None # HTLC unlocking preimage
|
||||
htlcsignature: Union[str, None] = None # HTLC unlocking signature
|
||||
witness: Union[None, str] = "" # witness for spending condition
|
||||
# p2pksigs: Union[List[str], None] = [] # P2PK signature
|
||||
# p2shscript: Union[P2SHWitness, None] = None # P2SH spending condition
|
||||
# htlcpreimage: Union[str, None] = None # HTLC unlocking preimage
|
||||
# htlcsignature: Union[str, None] = None # HTLC unlocking signature
|
||||
# whether this proof is reserved for sending, used for coin management in the wallet
|
||||
reserved: Union[None, bool] = False
|
||||
# unique ID of send attempt, used for grouping pending tokens in the wallet
|
||||
@@ -93,6 +128,21 @@ class Proof(BaseModel):
|
||||
def __setitem__(self, key, val):
|
||||
self.__setattr__(key, val)
|
||||
|
||||
@property
|
||||
def p2pksigs(self) -> List[str]:
|
||||
assert self.witness, "Witness is missing"
|
||||
return P2PKWitness.from_witness(self.witness).signatures
|
||||
|
||||
@property
|
||||
def p2shscript(self) -> P2SHWitness:
|
||||
assert self.witness, "Witness is missing"
|
||||
return P2SHWitness.from_witness(self.witness)
|
||||
|
||||
@property
|
||||
def htlcpreimage(self) -> Union[str, None]:
|
||||
assert self.witness, "Witness is missing"
|
||||
return HTLCWitness.from_witness(self.witness).preimage
|
||||
|
||||
|
||||
class Proofs(BaseModel):
|
||||
# NOTE: not used in Pydantic validation
|
||||
@@ -106,7 +156,12 @@ class BlindedMessage(BaseModel):
|
||||
|
||||
amount: int
|
||||
B_: str # Hex-encoded blinded message
|
||||
p2pksigs: Union[List[str], None] = None # signature for p2pk with SIG_ALL
|
||||
witness: Union[str, None] = None # witnesses (used for P2PK with SIG_ALL)
|
||||
|
||||
@property
|
||||
def p2pksigs(self) -> List[str]:
|
||||
assert self.witness, "Witness is missing"
|
||||
return P2PKWitness.from_witness(self.witness).signatures
|
||||
|
||||
|
||||
class BlindedSignature(BaseModel):
|
||||
@@ -206,19 +261,6 @@ class PostSplitRequest(BaseModel):
|
||||
proofs: List[Proof]
|
||||
amount: Optional[int] = None # deprecated since 0.13.0
|
||||
outputs: List[BlindedMessage]
|
||||
# signature: Optional[str] = None
|
||||
|
||||
# def sign(self, private_key: PrivateKey):
|
||||
# """
|
||||
# Create a signed split request. The signature is over the `proofs` and `outputs` fields.
|
||||
# """
|
||||
# # message = json.dumps(self.proofs).encode("utf-8") + json.dumps(
|
||||
# # self.outputs
|
||||
# # ).encode("utf-8")
|
||||
# message = json.dumps(self.dict(include={"proofs": ..., "outputs": ...})).encode(
|
||||
# "utf-8"
|
||||
# )
|
||||
# self.signature = sign_p2pk_sign(message, private_key)
|
||||
|
||||
|
||||
class PostSplitResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user