Skip to content

Commit ca4f9dd

Browse files
Lightspark Engzhenlu
authored andcommitted
Project import generated by Copybara.
GitOrigin-RevId: 7d04721d3d8fc63ec1728bef64f3cfe5b4242c01
1 parent 184b061 commit ca4f9dd

File tree

66 files changed

+4127
-693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4127
-693
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
# v2.0.0
4+
- Add support for remote signing.
5+
36
# v1.4.4
47

58
- Fix parsing of the pay_uma_invoice response

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cryptography = "*"
88
eciespy = "*"
99
pyjwt = "*"
1010
requests = "*"
11+
lightspark-crypto-python = "*"
1112

1213
[dev-packages]
1314
black = "*"

Pipfile.lock

Lines changed: 129 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright ©, 2022-present, Lightspark Group, Inc. - All Rights Reserved
2+
"""Sample Lightspark Webhooks Flask App.
3+
4+
Install Flask (pip install flask) and then run this like:
5+
6+
pipenv run flask --app examples.flask_remote_signin_server run --port 5001
7+
"""
8+
9+
import os
10+
import lightspark
11+
from flask import Flask, request
12+
13+
app = Flask(__name__)
14+
15+
# Get this from the API Configuration page.
16+
webhook_secret = os.environ.get("RK_WEBHOOK_SECRET")
17+
18+
api_token_client_id = os.environ.get("RK_API_CLIENT_ID")
19+
api_token_client_secret = os.environ.get("RK_API_CLIENT_SECRET")
20+
21+
master_seed = os.environ.get("RK_MASTER_SEED_HEX")
22+
23+
24+
@app.route("/ping", methods=["GET"])
25+
def ping():
26+
print("ping")
27+
return "OK"
28+
29+
30+
@app.route("/lightspark-webhook", methods=["POST"])
31+
def webhook():
32+
client = lightspark.LightsparkSyncClient(
33+
api_token_client_id=api_token_client_id,
34+
api_token_client_secret=api_token_client_secret,
35+
base_url=os.environ.get("RK_API_ENDPOINT"),
36+
)
37+
validator = lightspark.PositiveValidator()
38+
handler = lightspark.RemoteSigningWebhookEventHandler(
39+
client=client, master_seed=bytes.fromhex(master_seed), validator=validator
40+
)
41+
42+
handler.handle_remote_signing_webhook_request(
43+
request.data, request.headers.get(lightspark.SIGNATURE_HEADER), webhook_secret
44+
)
45+
return "OK"

lightspark/__init__.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
from lightspark.objects.CreateUmaInvoiceInput import CreateUmaInvoiceInput
4444
from lightspark.objects.CurrencyAmount import CurrencyAmount
4545
from lightspark.objects.CurrencyUnit import CurrencyUnit
46+
from lightspark.objects.DeclineToSignMessagesInput import DeclineToSignMessagesInput
47+
from lightspark.objects.DeclineToSignMessagesOutput import DeclineToSignMessagesOutput
4648
from lightspark.objects.DeleteApiTokenInput import DeleteApiTokenInput
4749
from lightspark.objects.DeleteApiTokenOutput import DeleteApiTokenOutput
4850
from lightspark.objects.Deposit import Deposit
@@ -53,6 +55,7 @@
5355
from lightspark.objects.GraphNode import GraphNode
5456
from lightspark.objects.Hop import Hop
5557
from lightspark.objects.HtlcAttemptFailureCode import HtlcAttemptFailureCode
58+
from lightspark.objects.IdAndSignature import IdAndSignature
5659
from lightspark.objects.IncomingPayment import IncomingPayment
5760
from lightspark.objects.IncomingPaymentAttempt import IncomingPaymentAttempt
5861
from lightspark.objects.IncomingPaymentAttemptStatus import IncomingPaymentAttemptStatus
@@ -72,11 +75,14 @@
7275
from lightspark.objects.LightningTransaction import LightningTransaction
7376
from lightspark.objects.LightsparkNode import LightsparkNode
7477
from lightspark.objects.LightsparkNodeOwner import LightsparkNodeOwner
75-
from lightspark.objects.LightsparkNodePurpose import LightsparkNodePurpose
7678
from lightspark.objects.LightsparkNodeStatus import LightsparkNodeStatus
7779
from lightspark.objects.LightsparkNodeToChannelsConnection import (
7880
LightsparkNodeToChannelsConnection,
7981
)
82+
from lightspark.objects.LightsparkNodeWithOSK import LightsparkNodeWithOSK
83+
from lightspark.objects.LightsparkNodeWithRemoteSigning import (
84+
LightsparkNodeWithRemoteSigning,
85+
)
8086
from lightspark.objects.Node import Node
8187
from lightspark.objects.NodeAddress import NodeAddress
8288
from lightspark.objects.NodeAddressType import NodeAddressType
@@ -110,6 +116,15 @@
110116
from lightspark.objects.PostTransactionData import PostTransactionData
111117
from lightspark.objects.RegisterPaymentInput import RegisterPaymentInput
112118
from lightspark.objects.RegisterPaymentOutput import RegisterPaymentOutput
119+
from lightspark.objects.ReleaseChannelPerCommitmentSecretInput import (
120+
ReleaseChannelPerCommitmentSecretInput,
121+
)
122+
from lightspark.objects.ReleaseChannelPerCommitmentSecretOutput import (
123+
ReleaseChannelPerCommitmentSecretOutput,
124+
)
125+
from lightspark.objects.ReleasePaymentPreimageInput import ReleasePaymentPreimageInput
126+
from lightspark.objects.ReleasePaymentPreimageOutput import ReleasePaymentPreimageOutput
127+
from lightspark.objects.RemoteSigningSubEventType import RemoteSigningSubEventType
113128
from lightspark.objects.RequestWithdrawalInput import RequestWithdrawalInput
114129
from lightspark.objects.RequestWithdrawalOutput import RequestWithdrawalOutput
115130
from lightspark.objects.RichText import RichText
@@ -123,10 +138,27 @@
123138
from lightspark.objects.Secret import Secret
124139
from lightspark.objects.SendPaymentInput import SendPaymentInput
125140
from lightspark.objects.SendPaymentOutput import SendPaymentOutput
141+
from lightspark.objects.SetInvoicePaymentHashInput import SetInvoicePaymentHashInput
142+
from lightspark.objects.SetInvoicePaymentHashOutput import SetInvoicePaymentHashOutput
143+
from lightspark.objects.Signable import Signable
144+
from lightspark.objects.SignablePayload import SignablePayload
145+
from lightspark.objects.SignablePayloadStatus import SignablePayloadStatus
146+
from lightspark.objects.SignInvoiceInput import SignInvoiceInput
147+
from lightspark.objects.SignInvoiceOutput import SignInvoiceOutput
148+
from lightspark.objects.SignMessagesInput import SignMessagesInput
149+
from lightspark.objects.SignMessagesOutput import SignMessagesOutput
126150
from lightspark.objects.Transaction import Transaction
127151
from lightspark.objects.TransactionFailures import TransactionFailures
128152
from lightspark.objects.TransactionStatus import TransactionStatus
129153
from lightspark.objects.TransactionType import TransactionType
154+
from lightspark.objects.UpdateChannelPerCommitmentPointInput import (
155+
UpdateChannelPerCommitmentPointInput,
156+
)
157+
from lightspark.objects.UpdateChannelPerCommitmentPointOutput import (
158+
UpdateChannelPerCommitmentPointOutput,
159+
)
160+
from lightspark.objects.UpdateNodeSharedSecretInput import UpdateNodeSharedSecretInput
161+
from lightspark.objects.UpdateNodeSharedSecretOutput import UpdateNodeSharedSecretOutput
130162
from lightspark.objects.Wallet import Wallet
131163
from lightspark.objects.WalletStatus import WalletStatus
132164
from lightspark.objects.WalletToPaymentRequestsConnection import (
@@ -146,5 +178,6 @@
146178
from lightspark.objects.WithdrawalRequestToChannelOpeningTransactionsConnection import (
147179
WithdrawalRequestToChannelOpeningTransactionsConnection,
148180
)
181+
from lightspark.remote_signing import *
149182
from lightspark.version import __version__
150183
from lightspark.webhooks import SIGNATURE_HEADER, WebhookEvent

lightspark/lightspark_client.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
from lightspark.scripts.send_payment import SEND_PAYMENT_MUTATION
8282
from lightspark.utils.crypto import decrypt_private_key
8383
from lightspark.utils.enums import parse_enum
84+
from lightspark.utils.signing_key import SigningKey, Secp256k1SigningKey, RSASigningKey
8485

8586
logger = logging.getLogger("lightspark")
8687

@@ -90,7 +91,7 @@
9091
@dataclass
9192
class LightsparkSyncClient:
9293
_requester: Requester
93-
_node_private_keys: Dict[str, bytes]
94+
_node_private_keys: Dict[str, SigningKey]
9495

9596
def __init__(
9697
self,
@@ -410,11 +411,11 @@ def get_lightning_fee_estimate_for_node(
410411
self._requester, json["lightning_fee_estimate_for_node"]
411412
).fee_estimate
412413

413-
def load_node_signing_key(self, node_id: str, signing_key: bytes) -> None:
414+
def load_node_signing_key(self, node_id: str, signing_key: SigningKey) -> None:
414415
logger.info("Loading the signing key for node %s", node_id)
415416
self._node_private_keys[node_id] = signing_key
416417

417-
def recover_node_signing_key(self, node_id: str, node_password: str) -> bytes:
418+
def recover_node_signing_key(self, node_id: str, node_password: str) -> SigningKey:
418419
logger.info("Recovering the signing key for node %s", node_id)
419420
json = self._requester.execute_graphql(
420421
RECOVER_NODE_SIGNING_KEY_QUERY,
@@ -431,8 +432,16 @@ def recover_node_signing_key(self, node_id: str, node_password: str) -> bytes:
431432
password=node_password,
432433
)
433434

434-
self.load_node_signing_key(node_id=node_id, signing_key=decrypted_private_key)
435-
return decrypted_private_key
435+
signing_key = RSASigningKey(decrypted_private_key)
436+
437+
self.load_node_signing_key(node_id=node_id, signing_key=signing_key)
438+
return signing_key
439+
440+
def provide_node_master_seed(
441+
self, node_id: str, master_seed: bytes, bitcoin_network: BitcoinNetwork
442+
) -> None:
443+
signing_key = Secp256k1SigningKey(master_seed, bitcoin_network)
444+
self.load_node_signing_key(node_id=node_id, signing_key=signing_key)
436445

437446
def pay_invoice(
438447
self,
@@ -518,7 +527,7 @@ def screen_node(self, provider: ComplianceProvider, node_pubkey: str) -> RiskRat
518527
)
519528
return parse_enum(RiskRating, json["screen_node"]["rating"])
520529

521-
def get_signing_key(self, node_id: str) -> bytes:
530+
def get_signing_key(self, node_id: str) -> SigningKey:
522531
if node_id not in self._node_private_keys:
523532
raise LightsparkException(
524533
"SIGNING_ERROR",

0 commit comments

Comments
 (0)