Skip to content

Commit 6095474

Browse files
committed
Successfully self-sign a License grant
o Fix up some unrelated tests
1 parent fa480f0 commit 6095474

File tree

9 files changed

+137
-34
lines changed

9 files changed

+137
-34
lines changed

GNUmakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ dist/SLIP-39.app-checkids: SLIP-39.spec
584584
# For details on Signing Apps:
585585
# See: https://developer.apple.com/library/archive/technotes/tn2318/_index.html
586586

587+
# For PyInstaller-specific hints:
588+
# https://gist.github.com/txoof/0636835d3cc65245c6288b2374799c43
589+
# https://github.com/txoof/codesign
590+
# https://github.com/The-Nicholas-R-Barrow-Company-LLC/PyMacApp
591+
587592
# * In order for code signing to succeed, your code signing key(s) MUST have all of their dependent
588593
# (issuer) keys downloaded to your Keychain, from https://www.apple.com/certificateauthority.
589594
# - Use Keychain Access, right-click on your signing key and click Evaluate "...".

slip39/communications_test.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
2-
import re
32
import os
3+
import re
4+
import sys
45

56
from io import StringIO
67
from pathlib import Path
@@ -216,11 +217,12 @@ async def handle_DATA(self, server, session, envelope):
216217
assert len( envelopes ) == 2
217218
assert envelopes[-1].rcpt_tos == [ '[email protected]' ]
218219

219-
# Now, try the CLI version.
220+
# Now, try the CLI version. Must use the current python interpreter, and this local instance of python-slip39
220221
here = Path( __file__ ).resolve().parent
222+
221223
for execute in [
222224
[
223-
"python3", "-m", "slip39.communications",
225+
sys.executable, "-m", "slip39.communications",
224226
]
225227

226228
]:
@@ -235,15 +237,16 @@ async def handle_DATA(self, server, session, envelope):
235237
from_addr,
236238
*to_addrs
237239
] ))
238-
log.info( f"Running filter: {' . '.join( command )}" )
240+
PYTHONPATH = f"{here.parent}"
241+
log.info( f"Running filter w/ PYTHONPATH={PYTHONPATH}: {' . '.join( command )}" )
239242
with Popen(
240243
command,
241244
stdin = PIPE,
242245
stdout = PIPE,
243246
stderr = PIPE,
244247
env = dict(
245248
os.environ,
246-
PYTHONPATH = f"{here.parent.parent}"
249+
PYTHONPATH = PYTHONPATH,
247250
)) as process:
248251
out, err = process.communicate( msg.as_bytes() )
249252
log.info( f"Filter stdout: {out.decode( 'UTF-8' ) if out else out}, stderr: {err.decode( 'UTF-8' ) if err else err}" )

slip39/invoice/bitquery_test.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import pytest
2+
import http.client
3+
import json
4+
import os
5+
6+
7+
# We don't want to run this test unless we provide our bitquery API
8+
# key in X-API-KEY
9+
@pytest.mark.skipif( not os.getenv( "BITQUERY_API_KEY" ), reason="Missing BITQUERY_API_KEY environment variable" )
10+
def test_bitquery_smoke():
11+
12+
queries = [
13+
{
14+
"query": """\
15+
query ($network: EthereumNetwork!, $addresses: [String!]) {
16+
ethereum(network: $network) {
17+
address(address: {in: $addresses}) {
18+
address
19+
annotation
20+
balances {
21+
value
22+
currency {
23+
address
24+
symbol
25+
tokenType
26+
}
27+
}
28+
}
29+
}
30+
}
31+
""",
32+
"variables": {
33+
"network": "ethereum",
34+
"addresses": [
35+
"0x22615C3A31d8f9d47bdB84502780A8D2C136fCF5"
36+
]
37+
}
38+
},
39+
{
40+
"query": """\
41+
query ($network: BitcoinNetwork!, $addresses: [String!]) {
42+
bitcoin(network: $network) {
43+
inbound: coinpath(receiver: {in: $addresses}) {
44+
receiver {
45+
address
46+
}
47+
amount
48+
}
49+
}
50+
}
51+
""",
52+
"variables": {
53+
"network": "bitcoin",
54+
"addresses": [
55+
"bc1qcj9ujyvrf94wu0902g2lnklzlyn5j5nrr44hwp",
56+
"18cBEMRxXHqzWWCxZNtU91F5sbUNKhL5PX",
57+
"bc1qygm3dlynmjxuflghr0hmq6r7wmff2jd5gtgz0q"
58+
]
59+
}
60+
}
61+
]
62+
63+
headers = {
64+
'Content-Type': 'application/json',
65+
'X-API-KEY': os.getenv( "BITQUERY_API_KEY" ),
66+
}
67+
68+
conn = http.client.HTTPSConnection("graphql.bitquery.io")
69+
70+
for query in queries:
71+
payload = json.dumps( query )
72+
print( payload )
73+
74+
conn.request("POST", "/", payload, headers)
75+
rx = conn.getresponse()
76+
rxstr = rx.read().decode("UTF-8")
77+
print(rxstr)
78+
response = json.loads( rxstr )
79+
print( json.dumps( response, indent=4 ))

slip39/invoice/ethereum.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ def __init__( self, chain=None, speed=None ):
451451
chain, = ( c for c in Chain if c.name.lower() == chain.lower() )
452452
assert isinstance( chain, (Chain, type(None)) )
453453
self._chain = chain or Chain.Ethereum
454-
assert self._chain in ( Chain.Ethereum, Chain.Goerli )
455454

456455
if speed and isinstance( speed, str ):
457456
speed, = ( s for s in Speed if s.name.lower() == speed.lower() )

slip39/invoice/ethereum_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_etherscan_ethprice():
1818
even without an ETHERSCAN_API_TOKEN (subject to default 1/5s rate limit.
1919
2020
"""
21-
ETH = Etherscan( "Nothing" ) # Specify Nothing for Ethereum back-end (uses defualts)
21+
ETH = Etherscan( "Nothing" ) # Specify Nothing for Ethereum back-end (uses defaults)
2222

2323
log.warning( "ETH: USD${}".format( ETH.ETH_USD ))
2424
log.warning( "Gas: USD${:7.2f} / 100,000 gas".format( 100000 * ETH.GAS_GWEI / ETH.ETH_GWEI * ETH.ETH_USD ))
@@ -111,11 +111,11 @@ def test_tokenprice():
111111
def test_tokenratio():
112112
# Now, get the token price ratio of two tokens (both cached, relative to default ETH)
113113
WBTC_USDC = tokenratio( WBTC, USDC )
114-
print( f"{WBTC_USDC[0]['symbol']:>6}/{WBTC_USDC[1]['symbol']:<6}: {float( WBTC_USDC[2] ):13.4f} =~= {WBTC_USDC[2]}" )
114+
print( f"{WBTC_USDC[0].symbol:>6}/{WBTC_USDC[1].symbol:<6}: {float( WBTC_USDC[2] ):13.4f} =~= {WBTC_USDC[2]}" )
115115
assert WBTC_USDC[2] > 10000, \
116116
"WBTC has crashed vs. USDC?"
117117

118118
HOT_USDC = tokenratio( "HOT", "USDC" )
119-
print( f"{HOT_USDC[0]['symbol']:>6}/{HOT_USDC[1]['symbol']:<6}: {float( HOT_USDC[2] ):13.4f} =~= {HOT_USDC[2]}" )
119+
print( f"{HOT_USDC[0].symbol:>6}/{HOT_USDC[1].symbol:<6}: {float( HOT_USDC[2] ):13.4f} =~= {HOT_USDC[2]}" )
120120
assert HOT_USDC[2] < .10, \
121121
"HOT has exploded vs. USDC?"

slip39/invoice/payments.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -406,22 +406,30 @@ def process(
406406
**kwds
407407
)
408408

409-
keypairs = []
410-
grants = None
411-
for key,val in reloader:
412-
if key is Process.PROMPT:
413-
# User information is required; yield the prompt, send the returned data into reloader
414-
reloader.send( (yield key, val) )
415-
continue
416-
# Some other key,val not returning input
417-
yield key, val
418-
if key is Process.KEYPAIR:
419-
keypairs.append( val )
420-
if key is Process.LICENSE:
421-
keypairs.append( val[0] )
422-
if key is Process.GRANTS:
423-
grants = val
409+
keypairs = []
410+
grants = None
411+
credentials = None
412+
try:
413+
while True:
414+
key,val = reloader.send( credentials )
415+
if key is Process.PROMPT:
416+
# User information is required; yield the prompt, send the returned data into reloader
417+
log.warning( f"Prompt: {val}" )
418+
# Some other key,val not returning input
419+
if key is Process.KEYPAIR:
420+
log.warning( f"Keypair: {val}" )
421+
keypairs.append( val )
422+
if key is Process.LICENSE:
423+
log.warning( f"License: {val[1]}" )
424+
keypairs.append( val[0] )
425+
if key is Process.GRANTS:
426+
grants = val
427+
credentials = ( yield (key,val) )
428+
except StopIteration:
429+
pass
430+
424431
if grants:
425-
return
432+
# TODO: check grants
433+
pass
426434

427-
# No license grants. Engage the process of paying for and obtaining a License.
435+
# No/insufficient license grants. Engage the process of paying for and obtaining a License.

slip39/invoice/payments_test.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_grants( tmp_path ):
5050
5151
"""
5252

53-
#test = Path( __file__ ).resolve().parent, # Our payments_test.crypto-keypair... file w/ O2o...2ik=
53+
test = Path( __file__ ).resolve() # Our payments_test.py file
5454
here = Path( tmp_path ).resolve() # Our testing directory.
5555

5656
name_ss = "self-signed"
@@ -119,6 +119,7 @@ def test_grants( tmp_path ):
119119
# We'll be loading an existing Client Agent keypair, so restrict it from registering a new one.
120120
# It must try to load the Author's License (using the author.service as the basename), and then
121121
# attempt to sign and save an instance of it with the client Keypair.
122+
machine_id_path = test.with_suffix( '' ) / "payments_test.machine-id"
122123
reloader = reload(
123124
author = author,
124125
client = client,
@@ -127,11 +128,16 @@ def test_grants( tmp_path ):
127128
basename = name_cl, # basename of the License, and the Keypair use to self-sign it
128129
confirm = False,
129130
extra = [ str( here ) ],
131+
constraints = dict(
132+
machine = True,
133+
),
134+
machine_id_path = machine_id_path,
130135
)
131136

132137
username = user_cl
133138
password = pswd_cl
134139
grants = None
140+
keypairs,licenses = [],[]
135141
try:
136142
key,val = next( reloader )
137143
while True:
@@ -147,8 +153,16 @@ def test_grants( tmp_path ):
147153
continue
148154
else:
149155
log.info( f"test_grants -x- ignoring {val}" )
150-
elif key == Process.GRANTS:
156+
elif key is Process.GRANTS:
157+
log.warning( f"Grants: {val}" )
151158
grants = val
159+
elif key is Process.KEYPAIR:
160+
log.warning( f"Keypair: {val}" )
161+
keypairs.append( val )
162+
elif key is Process.LICENSE:
163+
log.warning( f"License: {val[1]}, w/ Keypair: {licensing.KeypairPlaintext( val[0] )}" )
164+
keypairs.append( val[0] )
165+
licenses.append( val[1] )
152166
key,val = next( reloader )
153167
except StopIteration:
154168
log.info( f"test_grants xxx Done w/ key == {key}, val == {val}" )

slip39/invoice/payments_test/payments_test.crypto-keypair

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
000102030405060708090A0B0C0D0E0F

0 commit comments

Comments
 (0)