green-gdk 0.73.4__cp39-cp39-macosx_14_0_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
green_gdk/__init__.py ADDED
@@ -0,0 +1,358 @@
1
+ import atexit
2
+ import json
3
+ from ._green_gdk import *
4
+ from ._green_gdk import _python_set_callback_handler, _python_destroy_session
5
+ try:
6
+ import queue
7
+ except:
8
+ import Queue as queue
9
+
10
+ try:
11
+ basestring
12
+ except NameError:
13
+ basestring = str
14
+
15
+ # Unused: Provided for back compatibility only
16
+ GA_MEMO_USER = 0
17
+ GA_MEMO_BIP70 = 1
18
+
19
+ class Call(object):
20
+ """Handler class to process a call potentally requiring twofactor.
21
+
22
+ Initialize the class with the auth_handler object returned from
23
+ functions that may require authentication. Then call resolve()
24
+ on the object, optionally passing in callables to select and enter
25
+ twofactor auth methods and codes.
26
+
27
+ """
28
+
29
+ def __init__(self, call_obj):
30
+ self.call_obj = call_obj
31
+
32
+ def status(self):
33
+ return json.loads(auth_handler_get_status(self.call_obj))
34
+
35
+ def _select_method(self, methods):
36
+ # Default implementation just uses the first method provided
37
+ return methods[0]
38
+
39
+ def _resolve_code(self, method):
40
+ if isinstance(method, dict):
41
+ # Caller must provide their own handler for data requests
42
+ raise RuntimeError(f'Unhandled data request {method}')
43
+ # 2FA: Default implementation just uses localtest dummy 2fa code
44
+ return '555555'
45
+
46
+ def request_code(self, method):
47
+ auth_handler_request_code(self.call_obj, method)
48
+
49
+ def resolve(self, select_method_fn=None, resolve_code_fn=None):
50
+ select_method_fn = select_method_fn or self._select_method
51
+ resolve_code_fn = resolve_code_fn or self._resolve_code
52
+ while True:
53
+ status = self.status()
54
+ state = status['status']
55
+ if state == 'error':
56
+ self.call_obj = None
57
+ raise RuntimeError(status['error'])
58
+ if state == 'done':
59
+ self.call_obj = None
60
+ return status['result']
61
+ if state == 'request_code':
62
+ method = select_method_fn(status['methods'])
63
+ auth_handler_request_code(self.call_obj, method)
64
+ elif state == 'resolve_code':
65
+ if 'required_data' in status:
66
+ # Hardware device authorization requested
67
+ code = resolve_code_fn(status['required_data'])
68
+ elif status['method'] == 'data':
69
+ # Caller data requested
70
+ code = resolve_code_fn(status)
71
+ else:
72
+ # Twofactor authorization requested
73
+ code = resolve_code_fn(status['method'])
74
+ auth_handler_resolve_code(self.call_obj, code)
75
+ elif state == 'call':
76
+ auth_handler_call(self.call_obj)
77
+
78
+
79
+ class Session(object):
80
+ """A session representing either a Green multisig or a singlesig wallet.
81
+
82
+ """
83
+
84
+ to_destroy = []
85
+
86
+ @staticmethod
87
+ @atexit.register
88
+ def destroy_all():
89
+ while len(Session.to_destroy):
90
+ session = Session.to_destroy.pop()
91
+ session._destroy()
92
+
93
+ def __init__(self, net_params):
94
+ self.notifications = queue.Queue()
95
+ self.session_obj = create_session()
96
+ Session.to_destroy.append(self)
97
+ _python_set_callback_handler(self.session_obj, self._callback_handler)
98
+ return self.connect(net_params)
99
+
100
+ def _destroy(self):
101
+ if getattr(self, 'session_obj', None):
102
+ obj = self.session_obj
103
+ self.session_obj = None
104
+ _python_set_callback_handler(obj, None)
105
+ _python_destroy_session(obj)
106
+
107
+ def destroy(self):
108
+ if self in Session.to_destroy:
109
+ Session.to_destroy.remove(self)
110
+ self._destroy()
111
+
112
+ def __enter__(self):
113
+ return self
114
+
115
+ def __exit__(self, *args):
116
+ self.destroy()
117
+
118
+ def __del__(self):
119
+ self.destroy()
120
+
121
+ def _callback_handler(self, obj, event):
122
+ assert obj is self.session_obj
123
+ try:
124
+ self.callback_handler(json.loads(event))
125
+ except Exception as e:
126
+ print('exception {}\n'.format(e))
127
+
128
+ def callback_handler(self, event):
129
+ """Callback handler.
130
+
131
+ Override or monkey patch to handle notifications, or read the
132
+ self.notification queue to receive events.
133
+
134
+ """
135
+ timeout_seconds = 60
136
+ self.notifications.put(event, timeout_seconds)
137
+
138
+ @staticmethod
139
+ def _to_json(obj):
140
+ return obj if isinstance(obj, basestring) else json.dumps(obj)
141
+
142
+ def connect(self, net_params):
143
+ return connect(self.session_obj, self._to_json(net_params))
144
+
145
+ def disconnect(self):
146
+ raise RuntimeError('use reconnect_hint() to disconnect a session')
147
+
148
+ def reconnect_hint(self, hint):
149
+ return reconnect_hint(self.session_obj, self._to_json(hint))
150
+
151
+ def get_proxy_settings(self):
152
+ return json.loads(get_proxy_settings(self.session_obj))
153
+
154
+ @staticmethod
155
+ def get_wallet_identifier(net_params, params):
156
+ return json.loads(get_wallet_identifier(Session._to_json(net_params), Session._to_json(params)))
157
+
158
+ def register_user(self, hw_device, details):
159
+ return Call(register_user(self.session_obj, self._to_json(hw_device), self._to_json(details)))
160
+
161
+ def login_user(self, hw_device, details):
162
+ return Call(login_user(self.session_obj, self._to_json(hw_device), self._to_json(details)))
163
+
164
+ def get_watch_only_username(self):
165
+ return get_watch_only_username(self.session_obj)
166
+
167
+ def remove_account(self):
168
+ return Call(remove_account(self.session_obj))
169
+
170
+ def encrypt_with_pin(self, details):
171
+ return Call(encrypt_with_pin(self.session_obj, self._to_json(details)))
172
+
173
+ def decrypt_with_pin(self, details):
174
+ return Call(decrypt_with_pin(self.session_obj, self._to_json(details)))
175
+
176
+ def rsa_verify(self, details):
177
+ return Call(rsa_verify(self.session_obj, self._to_json(details)))
178
+
179
+ def disable_all_pin_logins(self):
180
+ return disable_all_pin_logins(self.session_obj)
181
+
182
+ def create_subaccount(self, details):
183
+ return Call(create_subaccount(self.session_obj, self._to_json(details)))
184
+
185
+ def update_subaccount(self, details):
186
+ return Call(update_subaccount(self.session_obj, self._to_json(details)))
187
+
188
+ def get_subaccounts(self, details=None):
189
+ details = details or {}
190
+ return Call(get_subaccounts(self.session_obj, self._to_json(details)))
191
+
192
+ def get_subaccount(self, subaccount):
193
+ return Call(get_subaccount(self.session_obj, subaccount))
194
+
195
+ def get_transactions(self, details={'subaccount': 0, 'first': 0, 'count': 30}):
196
+ return Call(get_transactions(self.session_obj, self._to_json(details)))
197
+
198
+ def get_receive_address(self, details=None):
199
+ details = details or {}
200
+ return Call(get_receive_address(self.session_obj, self._to_json(details)))
201
+
202
+ def get_previous_addresses(self, details={'subaccount': 0, 'last_pointer': 0}):
203
+ return Call(get_previous_addresses(self.session_obj, self._to_json(details)))
204
+
205
+ def get_unspent_outputs(self, details={'subaccount': 0, 'num_confs': 1}):
206
+ return Call(get_unspent_outputs(self.session_obj, self._to_json(details)))
207
+
208
+ def get_unspent_outputs_for_private_key(self, details):
209
+ return Call(get_unspent_outputs_for_private_key(self.session_obj, self._to_json(details)))
210
+
211
+ def set_unspent_outputs_status(self, details):
212
+ return Call(set_unspent_outputs_status(self.session_obj, self._to_json(details)))
213
+
214
+ def get_transaction_details(self, txhash_hex):
215
+ return json.loads(get_transaction_details(self.session_obj, txhash_hex))
216
+
217
+ def convert_amount(self, details):
218
+ return json.loads(convert_amount(self.session_obj, self._to_json(details)))
219
+
220
+ def get_balance(self, details={'subaccount': 0, 'num_confs': 0}):
221
+ return Call(get_balance(self.session_obj, self._to_json(details)))
222
+
223
+ def get_available_currencies(self):
224
+ return json.loads(get_available_currencies(self.session_obj))
225
+
226
+ def create_transaction(self, transaction_details):
227
+ return Call(create_transaction(self.session_obj, self._to_json(transaction_details)))
228
+
229
+ def blind_transaction(self, transaction_details):
230
+ return Call(blind_transaction(self.session_obj, self._to_json(transaction_details)))
231
+
232
+ def sign_transaction(self, transaction_details):
233
+ return Call(sign_transaction(self.session_obj, self._to_json(transaction_details)))
234
+
235
+ def create_swap_transaction(self, swap_details):
236
+ return Call(create_swap_transaction(self.session_obj, self._to_json(swap_details)))
237
+
238
+ def complete_swap_transaction(self, swap_details):
239
+ return Call(complete_swap_transaction(self.session_obj, self._to_json(swap_details)))
240
+
241
+ def create_redeposit_transaction(self, redeposit_details):
242
+ return Call(create_redeposit_transaction(self.session_obj, self._to_json(redeposit_details)))
243
+
244
+ def psbt_sign(self, details):
245
+ return Call(psbt_sign(self.session_obj, self._to_json(details)))
246
+
247
+ def psbt_from_json(self, details):
248
+ return Call(psbt_from_json(self.session_obj, self._to_json(details)))
249
+
250
+ def psbt_get_details(self, details):
251
+ return Call(psbt_get_details(self.session_obj, self._to_json(details)))
252
+
253
+ def send_transaction(self, details):
254
+ return Call(send_transaction(self.session_obj, self._to_json(details)))
255
+
256
+ def broadcast_transaction(self, details):
257
+ return Call(broadcast_transaction(self.session_obj, self._to_json(details)))
258
+
259
+ def sign_message(self, details):
260
+ return Call(sign_message(self.session_obj, self._to_json(details)))
261
+
262
+ def send_nlocktimes(self):
263
+ return send_nlocktimes(self.session_obj)
264
+
265
+ def set_csvtime(self, locktime_details):
266
+ return Call(set_csvtime(self.session_obj, self._to_json(locktime_details)))
267
+
268
+ def set_nlocktime(self, locktime_details):
269
+ return Call(set_nlocktime(self.session_obj, self._to_json(locktime_details)))
270
+
271
+ def set_transaction_memo(self, txhash_hex, memo, memo_type=0):
272
+ return set_transaction_memo(self.session_obj, txhash_hex, memo, memo_type)
273
+
274
+ def get_fee_estimates(self):
275
+ return json.loads(get_fee_estimates(self.session_obj))
276
+
277
+ def get_credentials(self, details):
278
+ return Call(get_credentials(self.session_obj, self._to_json(details)))
279
+
280
+ def get_system_message(self):
281
+ return get_system_message(self.session_obj)
282
+
283
+ def ack_system_message(self, message_text):
284
+ return Call(ack_system_message(self.session_obj, message_text))
285
+
286
+ def cache_control(self, details):
287
+ return Call(cache_control(self.session_obj, self._to_json(details)))
288
+
289
+ def get_twofactor_config(self):
290
+ return json.loads(get_twofactor_config(self.session_obj))
291
+
292
+ def change_settings_twofactor(self, method, details):
293
+ return Call(change_settings_twofactor(self.session_obj, method, self._to_json(details)))
294
+
295
+ def get_settings(self):
296
+ return json.loads(get_settings(self.session_obj))
297
+
298
+ def change_settings(self, settings):
299
+ return Call(change_settings(self.session_obj, self._to_json(settings)))
300
+
301
+ def twofactor_reset(self, email, is_dispute):
302
+ return Call(twofactor_reset(self.session_obj, email, is_dispute))
303
+
304
+ def twofactor_undo_reset(self, email):
305
+ return Call(twofactor_undo_reset(self.session_obj, email))
306
+
307
+ def twofactor_cancel_reset(self):
308
+ return Call(twofactor_cancel_reset(self.session_obj))
309
+
310
+ def twofactor_change_limits(self, details):
311
+ return Call(twofactor_change_limits(self.session_obj, self._to_json(details)))
312
+
313
+ def bcur_encode(self, details):
314
+ return Call(bcur_encode(self.session_obj, self._to_json(details)))
315
+
316
+ def bcur_decode(self, details):
317
+ return Call(bcur_decode(self.session_obj, self._to_json(details)))
318
+
319
+ def http_request(self, params):
320
+ return json.loads(http_request(self.session_obj, self._to_json(params)))
321
+
322
+ def refresh_assets(self, params):
323
+ return refresh_assets(self.session_obj, self._to_json(params))
324
+
325
+ def get_assets(self, params):
326
+ return json.loads(get_assets(self.session_obj, self._to_json(params)))
327
+
328
+ def validate_asset_domain_name(self, params):
329
+ return json.loads(validate_asset_domain_name(self.session_obj, self._to_json(params)))
330
+
331
+ def validate(self, details):
332
+ return Call(validate(self.session_obj, self._to_json(details)))
333
+
334
+ _old_get_networks = get_networks
335
+ def get_networks():
336
+ return json.loads(_old_get_networks())
337
+
338
+ _old_register_network = register_network
339
+ def register_network(name, details):
340
+ return _old_register_network(name, Session._to_json(details))
341
+
342
+ _old_get_random_bytes = get_random_bytes
343
+ def get_random_bytes(n):
344
+ out = bytearray(n)
345
+ _old_get_random_bytes(n, out)
346
+ return bytes(out)
347
+
348
+ _old_init = init
349
+ def init(config):
350
+ import os, os.path
351
+ if not config.get('datadir', None):
352
+ try:
353
+ datadir = os.path.join(os.path.expanduser('~'), '.blockstream', 'gdk')
354
+ os.makedirs(os.path.join(datadir, 'assets'), exist_ok = True);
355
+ config['datadir'] = datadir
356
+ except:
357
+ pass
358
+ return _old_init(json.dumps(config))
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.1
2
+ Name: green_gdk
3
+ Version: 0.73.4
4
+ Summary: Blockstream Green Development Kit
5
+ Author-email: Blockstream <inquiries@blockstream.com>
6
+ License: MIT
7
+ Project-URL: repository, https://github.com/blockstream/gdk
8
+ Project-URL: documentation, https://gdk.readthedocs.io/en/release_0.73.4
9
+ Project-URL: tracker, https://github.com/blockstream/gdk/issues
10
+ Keywords: Bitcoin,wallet,library,BIP32,BIP38,BIP39,secp256k1
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.5
16
+ Classifier: Programming Language :: Python :: 3.6
17
+ Classifier: Programming Language :: Python :: 3.7
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Description-Content-Type: text/markdown
20
+
21
+ Python bindings for the gdk Bitcoin library
@@ -0,0 +1,6 @@
1
+ green_gdk/__init__.py,sha256=MJ8gaRh5tcwlZW6VdhPPMIZHi8b8ZU56Jp5wem5cAaw,13150
2
+ green_gdk/_green_gdk.cpython-39-darwin.so,sha256=fdYG1Afxq_ISzLIy7ZvjDG0aK_po_6KsFqqhF8d1YWA,32147072
3
+ green_gdk-0.73.4.dist-info/METADATA,sha256=2yLFoD5bX9ve8qCfSoz0sNahJEA_GMO5Y-HlXhqSsb0,913
4
+ green_gdk-0.73.4.dist-info/WHEEL,sha256=FxNNXqpkJKhCyjhDFzWIj3wUJfdcADbCZVK6qt9f9Jg,108
5
+ green_gdk-0.73.4.dist-info/top_level.txt,sha256=Xe5CQrUkf885laA8xvVS_nRODRHCp0I-wvO3ueN3H2I,10
6
+ green_gdk-0.73.4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.4.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp39-cp39-macosx_14_0_x86_64
5
+
@@ -0,0 +1 @@
1
+ green_gdk