dfns-sdk 0.0.0.dev0__py3-none-any.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.
- dfns_sdk/__init__.py +24 -0
- dfns_sdk/_internal/__init__.py +5 -0
- dfns_sdk/_internal/http_client.py +395 -0
- dfns_sdk/auth.py +137 -0
- dfns_sdk/base_auth_api.py +129 -0
- dfns_sdk/client.py +81 -0
- dfns_sdk/delegated_client.py +97 -0
- dfns_sdk/generated/__init__.py +47 -0
- dfns_sdk/generated/agreements/__init__.py +7 -0
- dfns_sdk/generated/agreements/client.py +55 -0
- dfns_sdk/generated/agreements/delegated_client.py +95 -0
- dfns_sdk/generated/agreements/types.py +20 -0
- dfns_sdk/generated/allocations/__init__.py +7 -0
- dfns_sdk/generated/allocations/client.py +118 -0
- dfns_sdk/generated/allocations/delegated_client.py +187 -0
- dfns_sdk/generated/allocations/types.py +69 -0
- dfns_sdk/generated/auth/__init__.py +7 -0
- dfns_sdk/generated/auth/client.py +1215 -0
- dfns_sdk/generated/auth/delegated_client.py +1825 -0
- dfns_sdk/generated/auth/types.py +702 -0
- dfns_sdk/generated/exchanges/__init__.py +7 -0
- dfns_sdk/generated/exchanges/client.py +209 -0
- dfns_sdk/generated/exchanges/delegated_client.py +341 -0
- dfns_sdk/generated/exchanges/types.py +96 -0
- dfns_sdk/generated/fee_sponsors/__init__.py +7 -0
- dfns_sdk/generated/fee_sponsors/client.py +161 -0
- dfns_sdk/generated/fee_sponsors/delegated_client.py +287 -0
- dfns_sdk/generated/fee_sponsors/types.py +89 -0
- dfns_sdk/generated/keys/__init__.py +7 -0
- dfns_sdk/generated/keys/client.py +310 -0
- dfns_sdk/generated/keys/delegated_client.py +518 -0
- dfns_sdk/generated/keys/types.py +229 -0
- dfns_sdk/generated/networks/__init__.py +7 -0
- dfns_sdk/generated/networks/client.py +176 -0
- dfns_sdk/generated/networks/delegated_client.py +274 -0
- dfns_sdk/generated/networks/types.py +77 -0
- dfns_sdk/generated/permissions/__init__.py +7 -0
- dfns_sdk/generated/permissions/client.py +185 -0
- dfns_sdk/generated/permissions/delegated_client.py +344 -0
- dfns_sdk/generated/permissions/types.py +107 -0
- dfns_sdk/generated/policies/__init__.py +7 -0
- dfns_sdk/generated/policies/client.py +187 -0
- dfns_sdk/generated/policies/delegated_client.py +311 -0
- dfns_sdk/generated/policies/types.py +70 -0
- dfns_sdk/generated/signers/__init__.py +7 -0
- dfns_sdk/generated/signers/client.py +45 -0
- dfns_sdk/generated/signers/delegated_client.py +56 -0
- dfns_sdk/generated/signers/types.py +13 -0
- dfns_sdk/generated/staking/__init__.py +7 -0
- dfns_sdk/generated/staking/client.py +142 -0
- dfns_sdk/generated/staking/delegated_client.py +211 -0
- dfns_sdk/generated/staking/types.py +64 -0
- dfns_sdk/generated/swaps/__init__.py +7 -0
- dfns_sdk/generated/swaps/client.py +118 -0
- dfns_sdk/generated/swaps/delegated_client.py +157 -0
- dfns_sdk/generated/swaps/types.py +99 -0
- dfns_sdk/generated/wallets/__init__.py +7 -0
- dfns_sdk/generated/wallets/client.py +805 -0
- dfns_sdk/generated/wallets/delegated_client.py +1231 -0
- dfns_sdk/generated/wallets/types.py +534 -0
- dfns_sdk/generated/webhooks/__init__.py +7 -0
- dfns_sdk/generated/webhooks/client.py +193 -0
- dfns_sdk/generated/webhooks/delegated_client.py +320 -0
- dfns_sdk/generated/webhooks/types.py +101 -0
- dfns_sdk/types.py +72 -0
- dfns_sdk-0.0.0.dev0.dist-info/METADATA +191 -0
- dfns_sdk-0.0.0.dev0.dist-info/RECORD +69 -0
- dfns_sdk-0.0.0.dev0.dist-info/WHEEL +4 -0
- dfns_sdk-0.0.0.dev0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Client for the webhooks domain."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal, Optional, TypedDict, Union
|
|
4
|
+
|
|
5
|
+
from ..._internal import HttpClient
|
|
6
|
+
from . import types as T
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WebhooksClient:
|
|
10
|
+
"""Client for webhooks operations."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, http_client: HttpClient):
|
|
13
|
+
self._http = http_client
|
|
14
|
+
|
|
15
|
+
def list_webhooks(self, query: Optional[T.ListWebhooksQuery] = None) -> T.ListWebhooksResponse:
|
|
16
|
+
"""
|
|
17
|
+
List Webhooks.
|
|
18
|
+
|
|
19
|
+
List all webhooks for the authenticated user's organization. The results are paginated.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
query: Query parameters.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
T.ListWebhooksResponse: The API response.
|
|
26
|
+
"""
|
|
27
|
+
return self._http.request(
|
|
28
|
+
method="GET",
|
|
29
|
+
path="/webhooks",
|
|
30
|
+
path_params={},
|
|
31
|
+
query_params=query,
|
|
32
|
+
body=None,
|
|
33
|
+
requires_signature=False,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def create_webhook(self, body: T.CreateWebhookRequest) -> T.CreateWebhookResponse:
|
|
37
|
+
"""
|
|
38
|
+
Create Webhook.
|
|
39
|
+
|
|
40
|
+
Register a new webhook.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
body: Request body.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
T.CreateWebhookResponse: The API response.
|
|
47
|
+
"""
|
|
48
|
+
return self._http.request(
|
|
49
|
+
method="POST",
|
|
50
|
+
path="/webhooks",
|
|
51
|
+
path_params={},
|
|
52
|
+
query_params=None,
|
|
53
|
+
body=body,
|
|
54
|
+
requires_signature=True,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def get_webhook(self, webhook_id: str) -> T.GetWebhookResponse:
|
|
58
|
+
"""
|
|
59
|
+
Get Webhook.
|
|
60
|
+
|
|
61
|
+
Retrieve information about a specific webhook.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
webhook_id: Path parameter.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
T.GetWebhookResponse: The API response.
|
|
68
|
+
"""
|
|
69
|
+
return self._http.request(
|
|
70
|
+
method="GET",
|
|
71
|
+
path="/webhooks/{webhookId}",
|
|
72
|
+
path_params={"webhookId": webhook_id},
|
|
73
|
+
query_params=None,
|
|
74
|
+
body=None,
|
|
75
|
+
requires_signature=False,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def update_webhook(self, webhook_id: str, body: T.UpdateWebhookRequest) -> T.UpdateWebhookResponse:
|
|
79
|
+
"""
|
|
80
|
+
Update Webhook.
|
|
81
|
+
|
|
82
|
+
Update the definition of an existing webhook.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
webhook_id: Path parameter.
|
|
86
|
+
body: Request body.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
T.UpdateWebhookResponse: The API response.
|
|
90
|
+
"""
|
|
91
|
+
return self._http.request(
|
|
92
|
+
method="PUT",
|
|
93
|
+
path="/webhooks/{webhookId}",
|
|
94
|
+
path_params={"webhookId": webhook_id},
|
|
95
|
+
query_params=None,
|
|
96
|
+
body=body,
|
|
97
|
+
requires_signature=True,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def delete_webhook(self, webhook_id: str) -> T.DeleteWebhookResponse:
|
|
101
|
+
"""
|
|
102
|
+
Delete Webhook.
|
|
103
|
+
|
|
104
|
+
Deletes an existing webhook registration.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
webhook_id: Path parameter.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
T.DeleteWebhookResponse: The API response.
|
|
111
|
+
"""
|
|
112
|
+
return self._http.request(
|
|
113
|
+
method="DELETE",
|
|
114
|
+
path="/webhooks/{webhookId}",
|
|
115
|
+
path_params={"webhookId": webhook_id},
|
|
116
|
+
query_params=None,
|
|
117
|
+
body=None,
|
|
118
|
+
requires_signature=True,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def ping_webhook(self, webhook_id: str) -> T.PingWebhookResponse:
|
|
122
|
+
"""
|
|
123
|
+
Ping Webhook.
|
|
124
|
+
|
|
125
|
+
This endpoint is meant for webhook setup and troubleshooting. Calling the endpoint will trigger a fake test event that will be pushed to the webhook url. The fake event will not be saved and not appear in further requests to Webhook Events.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
webhook_id: Path parameter.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
T.PingWebhookResponse: The API response.
|
|
132
|
+
"""
|
|
133
|
+
return self._http.request(
|
|
134
|
+
method="POST",
|
|
135
|
+
path="/webhooks/{webhookId}/ping",
|
|
136
|
+
path_params={"webhookId": webhook_id},
|
|
137
|
+
query_params=None,
|
|
138
|
+
body=None,
|
|
139
|
+
requires_signature=True,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def get_webhook_event(self, webhook_id: str, webhook_event_id: str) -> T.GetWebhookEventResponse:
|
|
143
|
+
"""
|
|
144
|
+
Get Webhook Event.
|
|
145
|
+
|
|
146
|
+
Retrieve a specific webhook event details by its ID.
|
|
147
|
+
|
|
148
|
+
<Warning>
|
|
149
|
+
We only keep a trace of those Webhook Events in our system for a **retention period of 31 days**. Past that, they are discarded, so you cannot see them using [List Webhook Events](https://docs.dfns.co/api-reference/webhooks/list-webhook-events) or [Get Webhook Event](https://docs.dfns.co/api-reference/webhooks/get-webhook-event) endpoints.
|
|
150
|
+
</Warning>
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
webhook_id: Path parameter.
|
|
154
|
+
webhook_event_id: Path parameter.
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
T.GetWebhookEventResponse: The API response.
|
|
158
|
+
"""
|
|
159
|
+
return self._http.request(
|
|
160
|
+
method="GET",
|
|
161
|
+
path="/webhooks/{webhookId}/events/{webhookEventId}",
|
|
162
|
+
path_params={"webhookId": webhook_id, "webhookEventId": webhook_event_id},
|
|
163
|
+
query_params=None,
|
|
164
|
+
body=None,
|
|
165
|
+
requires_signature=False,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
def list_webhook_events(self, webhook_id: str, query: Optional[T.ListWebhookEventsQuery] = None) -> T.ListWebhookEventsResponse:
|
|
169
|
+
"""
|
|
170
|
+
List Webhook Events.
|
|
171
|
+
|
|
172
|
+
Lists all events for a given webhook.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
<Warning>
|
|
176
|
+
We only keep a trace of those Webhook Events in our system for a **retention period of 31 days**. Past that, they are discarded, so you cannot see them using [List Webhook Events](https://docs.dfns.co/api-reference/webhooks/list-webhook-events) or [Get Webhook Event](https://docs.dfns.co/api-reference/webhooks/get-webhook-event) endpoints.
|
|
177
|
+
</Warning>
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
webhook_id: Path parameter.
|
|
181
|
+
query: Query parameters.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
T.ListWebhookEventsResponse: The API response.
|
|
185
|
+
"""
|
|
186
|
+
return self._http.request(
|
|
187
|
+
method="GET",
|
|
188
|
+
path="/webhooks/{webhookId}/events",
|
|
189
|
+
path_params={"webhookId": webhook_id},
|
|
190
|
+
query_params=query,
|
|
191
|
+
body=None,
|
|
192
|
+
requires_signature=False,
|
|
193
|
+
)
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
"""Delegated client for the webhooks domain."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any, Literal, Optional, TypedDict, Union
|
|
5
|
+
|
|
6
|
+
from ..._internal import HttpClient
|
|
7
|
+
from ...base_auth_api import (
|
|
8
|
+
BaseAuthApi,
|
|
9
|
+
SignUserActionChallengeRequest,
|
|
10
|
+
UserActionChallengeResponse,
|
|
11
|
+
)
|
|
12
|
+
from . import types as T
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DelegatedWebhooksClient:
|
|
16
|
+
"""
|
|
17
|
+
Delegated client for webhooks operations.
|
|
18
|
+
|
|
19
|
+
This client separates user action signing into _init() and _complete() method pairs,
|
|
20
|
+
allowing external systems to handle the signing process.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, http_client: HttpClient):
|
|
24
|
+
self._http = http_client
|
|
25
|
+
|
|
26
|
+
def list_webhooks(self, query: Optional[T.ListWebhooksQuery] = None) -> T.ListWebhooksResponse:
|
|
27
|
+
"""
|
|
28
|
+
List Webhooks.
|
|
29
|
+
|
|
30
|
+
List all webhooks for the authenticated user's organization. The results are paginated.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
query: Query parameters.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
T.ListWebhooksResponse: The API response.
|
|
37
|
+
"""
|
|
38
|
+
return self._http.request(
|
|
39
|
+
method="GET",
|
|
40
|
+
path="/webhooks",
|
|
41
|
+
path_params={},
|
|
42
|
+
query_params=query,
|
|
43
|
+
body=None,
|
|
44
|
+
requires_signature=False,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def create_webhook_init(self, body: T.CreateWebhookRequest) -> UserActionChallengeResponse:
|
|
48
|
+
"""
|
|
49
|
+
Initialize Create Webhook.
|
|
50
|
+
|
|
51
|
+
Creates a user action challenge for external signing.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
body: Request body.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
UserActionChallengeResponse: The challenge to sign externally.
|
|
58
|
+
"""
|
|
59
|
+
path = "/webhooks"
|
|
60
|
+
payload = json.dumps(body, separators=(",", ":")) if body else ""
|
|
61
|
+
|
|
62
|
+
return BaseAuthApi.create_user_action_challenge(
|
|
63
|
+
self._http,
|
|
64
|
+
user_action_http_method="POST",
|
|
65
|
+
user_action_http_path=path,
|
|
66
|
+
user_action_payload=payload,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def create_webhook_complete(self, body: T.CreateWebhookRequest, signed_challenge: SignUserActionChallengeRequest) -> T.CreateWebhookResponse:
|
|
70
|
+
"""
|
|
71
|
+
Complete Create Webhook.
|
|
72
|
+
|
|
73
|
+
Submits the signed challenge and makes the API request.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
body: Request body.
|
|
77
|
+
signed_challenge: The signed challenge from external signing.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
T.CreateWebhookResponse: The API response.
|
|
81
|
+
"""
|
|
82
|
+
user_action_result = BaseAuthApi.sign_user_action_challenge(
|
|
83
|
+
self._http, signed_challenge
|
|
84
|
+
)
|
|
85
|
+
user_action_token = user_action_result["userAction"]
|
|
86
|
+
|
|
87
|
+
return self._http.request_with_user_action(
|
|
88
|
+
method="POST",
|
|
89
|
+
path="/webhooks",
|
|
90
|
+
path_params={},
|
|
91
|
+
query_params=None,
|
|
92
|
+
body=body,
|
|
93
|
+
user_action=user_action_token,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def get_webhook(self, webhook_id: str) -> T.GetWebhookResponse:
|
|
97
|
+
"""
|
|
98
|
+
Get Webhook.
|
|
99
|
+
|
|
100
|
+
Retrieve information about a specific webhook.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
webhook_id: Path parameter.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
T.GetWebhookResponse: The API response.
|
|
107
|
+
"""
|
|
108
|
+
return self._http.request(
|
|
109
|
+
method="GET",
|
|
110
|
+
path="/webhooks/{webhookId}",
|
|
111
|
+
path_params={"webhookId": webhook_id},
|
|
112
|
+
query_params=None,
|
|
113
|
+
body=None,
|
|
114
|
+
requires_signature=False,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def update_webhook_init(self, webhook_id: str, body: T.UpdateWebhookRequest) -> UserActionChallengeResponse:
|
|
118
|
+
"""
|
|
119
|
+
Initialize Update Webhook.
|
|
120
|
+
|
|
121
|
+
Creates a user action challenge for external signing.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
webhook_id: Path parameter.
|
|
125
|
+
body: Request body.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
UserActionChallengeResponse: The challenge to sign externally.
|
|
129
|
+
"""
|
|
130
|
+
path = "/webhooks/{webhookId}"
|
|
131
|
+
path = path.replace("{webhookId}", str(webhook_id))
|
|
132
|
+
payload = json.dumps(body, separators=(",", ":")) if body else ""
|
|
133
|
+
|
|
134
|
+
return BaseAuthApi.create_user_action_challenge(
|
|
135
|
+
self._http,
|
|
136
|
+
user_action_http_method="PUT",
|
|
137
|
+
user_action_http_path=path,
|
|
138
|
+
user_action_payload=payload,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
def update_webhook_complete(self, webhook_id: str, body: T.UpdateWebhookRequest, signed_challenge: SignUserActionChallengeRequest) -> T.UpdateWebhookResponse:
|
|
142
|
+
"""
|
|
143
|
+
Complete Update Webhook.
|
|
144
|
+
|
|
145
|
+
Submits the signed challenge and makes the API request.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
webhook_id: Path parameter.
|
|
149
|
+
body: Request body.
|
|
150
|
+
signed_challenge: The signed challenge from external signing.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
T.UpdateWebhookResponse: The API response.
|
|
154
|
+
"""
|
|
155
|
+
user_action_result = BaseAuthApi.sign_user_action_challenge(
|
|
156
|
+
self._http, signed_challenge
|
|
157
|
+
)
|
|
158
|
+
user_action_token = user_action_result["userAction"]
|
|
159
|
+
|
|
160
|
+
return self._http.request_with_user_action(
|
|
161
|
+
method="PUT",
|
|
162
|
+
path="/webhooks/{webhookId}",
|
|
163
|
+
path_params={"webhookId": webhook_id},
|
|
164
|
+
query_params=None,
|
|
165
|
+
body=body,
|
|
166
|
+
user_action=user_action_token,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
def delete_webhook_init(self, webhook_id: str) -> UserActionChallengeResponse:
|
|
170
|
+
"""
|
|
171
|
+
Initialize Delete Webhook.
|
|
172
|
+
|
|
173
|
+
Creates a user action challenge for external signing.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
webhook_id: Path parameter.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
UserActionChallengeResponse: The challenge to sign externally.
|
|
180
|
+
"""
|
|
181
|
+
path = "/webhooks/{webhookId}"
|
|
182
|
+
path = path.replace("{webhookId}", str(webhook_id))
|
|
183
|
+
payload = ""
|
|
184
|
+
|
|
185
|
+
return BaseAuthApi.create_user_action_challenge(
|
|
186
|
+
self._http,
|
|
187
|
+
user_action_http_method="DELETE",
|
|
188
|
+
user_action_http_path=path,
|
|
189
|
+
user_action_payload=payload,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
def delete_webhook_complete(self, webhook_id: str, signed_challenge: SignUserActionChallengeRequest) -> T.DeleteWebhookResponse:
|
|
193
|
+
"""
|
|
194
|
+
Complete Delete Webhook.
|
|
195
|
+
|
|
196
|
+
Submits the signed challenge and makes the API request.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
webhook_id: Path parameter.
|
|
200
|
+
signed_challenge: The signed challenge from external signing.
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
T.DeleteWebhookResponse: The API response.
|
|
204
|
+
"""
|
|
205
|
+
user_action_result = BaseAuthApi.sign_user_action_challenge(
|
|
206
|
+
self._http, signed_challenge
|
|
207
|
+
)
|
|
208
|
+
user_action_token = user_action_result["userAction"]
|
|
209
|
+
|
|
210
|
+
return self._http.request_with_user_action(
|
|
211
|
+
method="DELETE",
|
|
212
|
+
path="/webhooks/{webhookId}",
|
|
213
|
+
path_params={"webhookId": webhook_id},
|
|
214
|
+
query_params=None,
|
|
215
|
+
body=None,
|
|
216
|
+
user_action=user_action_token,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
def ping_webhook_init(self, webhook_id: str) -> UserActionChallengeResponse:
|
|
220
|
+
"""
|
|
221
|
+
Initialize Ping Webhook.
|
|
222
|
+
|
|
223
|
+
Creates a user action challenge for external signing.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
webhook_id: Path parameter.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
UserActionChallengeResponse: The challenge to sign externally.
|
|
230
|
+
"""
|
|
231
|
+
path = "/webhooks/{webhookId}/ping"
|
|
232
|
+
path = path.replace("{webhookId}", str(webhook_id))
|
|
233
|
+
payload = ""
|
|
234
|
+
|
|
235
|
+
return BaseAuthApi.create_user_action_challenge(
|
|
236
|
+
self._http,
|
|
237
|
+
user_action_http_method="POST",
|
|
238
|
+
user_action_http_path=path,
|
|
239
|
+
user_action_payload=payload,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
def ping_webhook_complete(self, webhook_id: str, signed_challenge: SignUserActionChallengeRequest) -> T.PingWebhookResponse:
|
|
243
|
+
"""
|
|
244
|
+
Complete Ping Webhook.
|
|
245
|
+
|
|
246
|
+
Submits the signed challenge and makes the API request.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
webhook_id: Path parameter.
|
|
250
|
+
signed_challenge: The signed challenge from external signing.
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
T.PingWebhookResponse: The API response.
|
|
254
|
+
"""
|
|
255
|
+
user_action_result = BaseAuthApi.sign_user_action_challenge(
|
|
256
|
+
self._http, signed_challenge
|
|
257
|
+
)
|
|
258
|
+
user_action_token = user_action_result["userAction"]
|
|
259
|
+
|
|
260
|
+
return self._http.request_with_user_action(
|
|
261
|
+
method="POST",
|
|
262
|
+
path="/webhooks/{webhookId}/ping",
|
|
263
|
+
path_params={"webhookId": webhook_id},
|
|
264
|
+
query_params=None,
|
|
265
|
+
body=None,
|
|
266
|
+
user_action=user_action_token,
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def get_webhook_event(self, webhook_id: str, webhook_event_id: str) -> T.GetWebhookEventResponse:
|
|
270
|
+
"""
|
|
271
|
+
Get Webhook Event.
|
|
272
|
+
|
|
273
|
+
Retrieve a specific webhook event details by its ID.
|
|
274
|
+
|
|
275
|
+
<Warning>
|
|
276
|
+
We only keep a trace of those Webhook Events in our system for a **retention period of 31 days**. Past that, they are discarded, so you cannot see them using [List Webhook Events](https://docs.dfns.co/api-reference/webhooks/list-webhook-events) or [Get Webhook Event](https://docs.dfns.co/api-reference/webhooks/get-webhook-event) endpoints.
|
|
277
|
+
</Warning>
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
webhook_id: Path parameter.
|
|
281
|
+
webhook_event_id: Path parameter.
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
T.GetWebhookEventResponse: The API response.
|
|
285
|
+
"""
|
|
286
|
+
return self._http.request(
|
|
287
|
+
method="GET",
|
|
288
|
+
path="/webhooks/{webhookId}/events/{webhookEventId}",
|
|
289
|
+
path_params={"webhookId": webhook_id, "webhookEventId": webhook_event_id},
|
|
290
|
+
query_params=None,
|
|
291
|
+
body=None,
|
|
292
|
+
requires_signature=False,
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
def list_webhook_events(self, webhook_id: str, query: Optional[T.ListWebhookEventsQuery] = None) -> T.ListWebhookEventsResponse:
|
|
296
|
+
"""
|
|
297
|
+
List Webhook Events.
|
|
298
|
+
|
|
299
|
+
Lists all events for a given webhook.
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
<Warning>
|
|
303
|
+
We only keep a trace of those Webhook Events in our system for a **retention period of 31 days**. Past that, they are discarded, so you cannot see them using [List Webhook Events](https://docs.dfns.co/api-reference/webhooks/list-webhook-events) or [Get Webhook Event](https://docs.dfns.co/api-reference/webhooks/get-webhook-event) endpoints.
|
|
304
|
+
</Warning>
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
webhook_id: Path parameter.
|
|
308
|
+
query: Query parameters.
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
T.ListWebhookEventsResponse: The API response.
|
|
312
|
+
"""
|
|
313
|
+
return self._http.request(
|
|
314
|
+
method="GET",
|
|
315
|
+
path="/webhooks/{webhookId}/events",
|
|
316
|
+
path_params={"webhookId": webhook_id},
|
|
317
|
+
query_params=query,
|
|
318
|
+
body=None,
|
|
319
|
+
requires_signature=False,
|
|
320
|
+
)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Types for the webhooks domain."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal, NotRequired, Optional, TypedDict, Union
|
|
4
|
+
|
|
5
|
+
class ListWebhooksResponse(TypedDict, total=False):
|
|
6
|
+
"""listWebhooks response."""
|
|
7
|
+
|
|
8
|
+
items: list[TypedDict]
|
|
9
|
+
next_page_token: NotRequired[str]
|
|
10
|
+
|
|
11
|
+
class ListWebhooksQuery(TypedDict, total=False):
|
|
12
|
+
"""listWebhooks query parameters."""
|
|
13
|
+
|
|
14
|
+
limit: NotRequired[int]
|
|
15
|
+
pagination_token: NotRequired[str]
|
|
16
|
+
|
|
17
|
+
class CreateWebhookRequest(TypedDict, total=False):
|
|
18
|
+
"""createWebhook request body."""
|
|
19
|
+
|
|
20
|
+
url: str
|
|
21
|
+
status: NotRequired[Literal["Enabled", "Disabled"]]
|
|
22
|
+
description: NotRequired[str]
|
|
23
|
+
events: list[Union[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"], Literal["*"]]]
|
|
24
|
+
|
|
25
|
+
class CreateWebhookResponse(TypedDict, total=False):
|
|
26
|
+
"""createWebhook response."""
|
|
27
|
+
|
|
28
|
+
id: str
|
|
29
|
+
url: str
|
|
30
|
+
events: list[Union[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"], Literal["*"]]]
|
|
31
|
+
status: Literal["Enabled", "Disabled"]
|
|
32
|
+
description: NotRequired[str]
|
|
33
|
+
date_created: str
|
|
34
|
+
date_updated: str
|
|
35
|
+
secret: str
|
|
36
|
+
|
|
37
|
+
class GetWebhookResponse(TypedDict, total=False):
|
|
38
|
+
"""getWebhook response."""
|
|
39
|
+
|
|
40
|
+
id: str
|
|
41
|
+
url: str
|
|
42
|
+
events: list[Union[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"], Literal["*"]]]
|
|
43
|
+
status: Literal["Enabled", "Disabled"]
|
|
44
|
+
description: NotRequired[str]
|
|
45
|
+
date_created: str
|
|
46
|
+
date_updated: str
|
|
47
|
+
|
|
48
|
+
class UpdateWebhookRequest(TypedDict, total=False):
|
|
49
|
+
"""updateWebhook request body."""
|
|
50
|
+
|
|
51
|
+
url: NotRequired[str]
|
|
52
|
+
description: NotRequired[str]
|
|
53
|
+
events: NotRequired[list[Union[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"], Literal["*"]]]]
|
|
54
|
+
status: NotRequired[Literal["Enabled", "Disabled"]]
|
|
55
|
+
|
|
56
|
+
class UpdateWebhookResponse(TypedDict, total=False):
|
|
57
|
+
"""updateWebhook response."""
|
|
58
|
+
|
|
59
|
+
id: str
|
|
60
|
+
url: str
|
|
61
|
+
events: list[Union[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"], Literal["*"]]]
|
|
62
|
+
status: Literal["Enabled", "Disabled"]
|
|
63
|
+
description: NotRequired[str]
|
|
64
|
+
date_created: str
|
|
65
|
+
date_updated: str
|
|
66
|
+
|
|
67
|
+
class DeleteWebhookResponse(TypedDict, total=False):
|
|
68
|
+
"""deleteWebhook response."""
|
|
69
|
+
|
|
70
|
+
deleted: Literal[True]
|
|
71
|
+
|
|
72
|
+
class PingWebhookResponse(TypedDict, total=False):
|
|
73
|
+
"""pingWebhook response."""
|
|
74
|
+
|
|
75
|
+
status: str
|
|
76
|
+
error: NotRequired[str]
|
|
77
|
+
|
|
78
|
+
class GetWebhookEventResponse(TypedDict, total=False):
|
|
79
|
+
"""getWebhookEvent response."""
|
|
80
|
+
|
|
81
|
+
id: str
|
|
82
|
+
date: str
|
|
83
|
+
kind: Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"]
|
|
84
|
+
data: dict[str, dict[str, Any]]
|
|
85
|
+
status: str
|
|
86
|
+
error: NotRequired[str]
|
|
87
|
+
timestamp_sent: int
|
|
88
|
+
|
|
89
|
+
class ListWebhookEventsResponse(TypedDict, total=False):
|
|
90
|
+
"""listWebhookEvents response."""
|
|
91
|
+
|
|
92
|
+
items: list[TypedDict]
|
|
93
|
+
next_page_token: NotRequired[str]
|
|
94
|
+
|
|
95
|
+
class ListWebhookEventsQuery(TypedDict, total=False):
|
|
96
|
+
"""listWebhookEvents query parameters."""
|
|
97
|
+
|
|
98
|
+
kind: NotRequired[Literal["policy.triggered", "policy.approval.pending", "policy.approval.resolved", "key.created", "key.deleted", "key.delegated", "key.exported", "wallet.blockchainevent.detected", "wallet.created", "wallet.activated", "wallet.delegated", "wallet.exported", "wallet.signature.failed", "wallet.signature.rejected", "wallet.signature.requested", "wallet.signature.signed", "wallet.transaction.broadcasted", "wallet.transaction.confirmed", "wallet.transaction.failed", "wallet.transaction.rejected", "wallet.transaction.requested", "wallet.transfer.broadcasted", "wallet.transfer.confirmed", "wallet.transfer.failed", "wallet.transfer.rejected", "wallet.transfer.requested", "wallet.offer.received", "wallet.offer.accepted", "wallet.offer.rejected", "wallet.tags.modified"]]
|
|
99
|
+
delivery_failed: NotRequired[Literal["true", "false"]]
|
|
100
|
+
limit: NotRequired[int]
|
|
101
|
+
pagination_token: NotRequired[str]
|
dfns_sdk/types.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Base types for the Dfns SDK."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any, Callable, Awaitable, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class DfnsClientConfig:
|
|
9
|
+
"""Configuration for the Dfns client."""
|
|
10
|
+
|
|
11
|
+
auth_token: str
|
|
12
|
+
"""Authentication token (JWT)."""
|
|
13
|
+
|
|
14
|
+
base_url: str = "https://api.dfns.io"
|
|
15
|
+
"""Base URL for the Dfns API."""
|
|
16
|
+
|
|
17
|
+
signer: Optional["Signer"] = None
|
|
18
|
+
"""Signer for user action requests."""
|
|
19
|
+
|
|
20
|
+
headers: dict[str, str] = field(default_factory=dict)
|
|
21
|
+
"""Additional headers to include in requests."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class DfnsDelegatedClientConfig:
|
|
26
|
+
"""
|
|
27
|
+
Configuration for the delegated Dfns client.
|
|
28
|
+
|
|
29
|
+
Delegated clients are used when signing is handled externally,
|
|
30
|
+
separating the challenge init from the completion phase.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
auth_token: str
|
|
34
|
+
"""Authentication token (JWT) for the service account."""
|
|
35
|
+
|
|
36
|
+
base_url: str = "https://api.dfns.io"
|
|
37
|
+
"""Base URL for the Dfns API."""
|
|
38
|
+
|
|
39
|
+
headers: dict[str, str] = field(default_factory=dict)
|
|
40
|
+
"""Additional headers to include in requests."""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class DfnsError(Exception):
|
|
44
|
+
"""Exception raised by Dfns API errors."""
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
message: str,
|
|
49
|
+
status_code: Optional[int] = None,
|
|
50
|
+
error_code: Optional[str] = None,
|
|
51
|
+
details: Optional[dict[str, Any]] = None,
|
|
52
|
+
):
|
|
53
|
+
super().__init__(message)
|
|
54
|
+
self.message = message
|
|
55
|
+
self.status_code = status_code
|
|
56
|
+
self.error_code = error_code
|
|
57
|
+
self.details = details or {}
|
|
58
|
+
|
|
59
|
+
def __str__(self) -> str:
|
|
60
|
+
parts = [self.message]
|
|
61
|
+
if self.status_code:
|
|
62
|
+
parts.append(f"[{self.status_code}]")
|
|
63
|
+
if self.error_code:
|
|
64
|
+
parts.append(f"({self.error_code})")
|
|
65
|
+
return " ".join(parts)
|
|
66
|
+
|
|
67
|
+
def __repr__(self) -> str:
|
|
68
|
+
return f"DfnsError({self.message!r}, status_code={self.status_code}, error_code={self.error_code!r})"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# Type alias for signer callback
|
|
72
|
+
Signer = Callable[[str], Awaitable[str]]
|