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,310 @@
|
|
|
1
|
+
"""Client for the keys 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 KeysClient:
|
|
10
|
+
"""Client for keys operations."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, http_client: HttpClient):
|
|
13
|
+
self._http = http_client
|
|
14
|
+
|
|
15
|
+
def list_keys(self, query: Optional[T.ListKeysQuery] = None) -> T.ListKeysResponse:
|
|
16
|
+
"""
|
|
17
|
+
List Keys.
|
|
18
|
+
|
|
19
|
+
Retrieve all keys registered for your organization.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
query: Query parameters.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
T.ListKeysResponse: The API response.
|
|
26
|
+
"""
|
|
27
|
+
return self._http.request(
|
|
28
|
+
method="GET",
|
|
29
|
+
path="/keys",
|
|
30
|
+
path_params={},
|
|
31
|
+
query_params=query,
|
|
32
|
+
body=None,
|
|
33
|
+
requires_signature=False,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def create_key(self, body: T.CreateKeyRequest) -> T.CreateKeyResponse:
|
|
37
|
+
"""
|
|
38
|
+
Create Key.
|
|
39
|
+
|
|
40
|
+
Creates a key for the given scheme and curve. Returns the new key entity.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
body: Request body.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
T.CreateKeyResponse: The API response.
|
|
47
|
+
"""
|
|
48
|
+
return self._http.request(
|
|
49
|
+
method="POST",
|
|
50
|
+
path="/keys",
|
|
51
|
+
path_params={},
|
|
52
|
+
query_params=None,
|
|
53
|
+
body=body,
|
|
54
|
+
requires_signature=True,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
def delegate_key(self, key_id: str, body: T.DelegateKeyRequest) -> T.DelegateKeyResponse:
|
|
58
|
+
"""
|
|
59
|
+
Delegate Key.
|
|
60
|
+
|
|
61
|
+
<Warning>
|
|
62
|
+
Only keys created with "`delayDelegation: true`" can then be delegated to an end-user. It means you need to know ahead of time that you're creating a wallet meant to be delegated to an end-user later. This is a safety to prevent, for example, a treasury wallet from being unintentionally delegated to an end-user.
|
|
63
|
+
</Warning>
|
|
64
|
+
|
|
65
|
+
<Note>
|
|
66
|
+
When a key is delegated to an end user, all wallets using this key as the signing key are also automatically delegated to the same end user. Key and wallet ownerships are guaranteed to be always consistent.
|
|
67
|
+
</Note>
|
|
68
|
+
|
|
69
|
+
<Danger>
|
|
70
|
+
This operation is irreversible. The key ownership will be transferred to the end-user
|
|
71
|
+
</Danger>
|
|
72
|
+
|
|
73
|
+
In most cases, when you want to implement [Wallet Delegation](https://docs.dfns.co/developers/guides/wallet-delegation), simply create the wallet by directly delegating it to an end user, in which case it will the non-custodial from the start. There are some rare cases, however, where the key or wallet must be created before the user has accessed to the system. To accommodate this, we've added the ability to create a key or wallet in delay delegation mode, and then later delegate it (ie. transfer ownership of it) to an end user via this endpoint.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
key_id: Path parameter.
|
|
77
|
+
body: Request body.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
T.DelegateKeyResponse: The API response.
|
|
81
|
+
"""
|
|
82
|
+
return self._http.request(
|
|
83
|
+
method="POST",
|
|
84
|
+
path="/keys/{keyId}/delegate",
|
|
85
|
+
path_params={"keyId": key_id},
|
|
86
|
+
query_params=None,
|
|
87
|
+
body=body,
|
|
88
|
+
requires_signature=True,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def get_key(self, key_id: str) -> T.GetKeyResponse:
|
|
92
|
+
"""
|
|
93
|
+
Get Key.
|
|
94
|
+
|
|
95
|
+
Retrieves a key information by its ID.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
key_id: Path parameter.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
T.GetKeyResponse: The API response.
|
|
102
|
+
"""
|
|
103
|
+
return self._http.request(
|
|
104
|
+
method="GET",
|
|
105
|
+
path="/keys/{keyId}",
|
|
106
|
+
path_params={"keyId": key_id},
|
|
107
|
+
query_params=None,
|
|
108
|
+
body=None,
|
|
109
|
+
requires_signature=False,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
def update_key(self, key_id: str, body: T.UpdateKeyRequest) -> T.UpdateKeyResponse:
|
|
113
|
+
"""
|
|
114
|
+
Update Key.
|
|
115
|
+
|
|
116
|
+
Updates the name of an existing key.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
key_id: Path parameter.
|
|
120
|
+
body: Request body.
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
T.UpdateKeyResponse: The API response.
|
|
124
|
+
"""
|
|
125
|
+
return self._http.request(
|
|
126
|
+
method="PUT",
|
|
127
|
+
path="/keys/{keyId}",
|
|
128
|
+
path_params={"keyId": key_id},
|
|
129
|
+
query_params=None,
|
|
130
|
+
body=body,
|
|
131
|
+
requires_signature=True,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def delete_key(self, key_id: str) -> T.DeleteKeyResponse:
|
|
135
|
+
"""
|
|
136
|
+
Delete Key.
|
|
137
|
+
|
|
138
|
+
Deletes the key and all wallets using this key. Once deleted, keys (and wallets) are not usable anymore, and won't count in your overall organisation wallet count.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
key_id: Path parameter.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
T.DeleteKeyResponse: The API response.
|
|
145
|
+
"""
|
|
146
|
+
return self._http.request(
|
|
147
|
+
method="DELETE",
|
|
148
|
+
path="/keys/{keyId}",
|
|
149
|
+
path_params={"keyId": key_id},
|
|
150
|
+
query_params=None,
|
|
151
|
+
body=None,
|
|
152
|
+
requires_signature=True,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
def derive_key(self, key_id: str, body: T.DeriveKeyRequest) -> T.DeriveKeyResponse:
|
|
156
|
+
"""
|
|
157
|
+
Derive Key.
|
|
158
|
+
|
|
159
|
+
Dfns decentralized key management network supports threshold Diffie-Hellman protocol based on [GLOW20 paper](https://eprint.iacr.org/2020/096). You can use the DH protocol to derive output from a domain separation tag and a seed value. The derivation process is deterministic, i.e. the same Diffie-Hellman key and seed will lead to the same derived output. To ensure reproducibility, we use hash to curve [RFC9380](https://www.rfc-editor.org/rfc/rfc9380.html) and standard ciphersuite `secp256k1_XMD:SHA-256_SSWU_RO_`.
|
|
160
|
+
|
|
161
|
+
<Tip>
|
|
162
|
+
The seed doesn’t need to be secret. Without access to the DH key, it is not possible to do the derivation, even if the seed is known. Moreover, if both seed and derived output are known, it’s also not possible to do the derivation for another seed without having access to the DH key.
|
|
163
|
+
</Tip>
|
|
164
|
+
|
|
165
|
+
This endpoint only supports Diffie-Hellman keys. Regular threshold signature keys, like `ECDSA` or `EdDSA`, will not work. You can create a Diffie-Hellman key with the [Create Key](https://docs.dfns.co/api-reference/keys/create-key) endpoint using `scheme=DH` and `curve=secp256k1`.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
key_id: Path parameter.
|
|
169
|
+
body: Request body.
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
T.DeriveKeyResponse: The API response.
|
|
173
|
+
"""
|
|
174
|
+
return self._http.request(
|
|
175
|
+
method="POST",
|
|
176
|
+
path="/keys/{keyId}/derive",
|
|
177
|
+
path_params={"keyId": key_id},
|
|
178
|
+
query_params=None,
|
|
179
|
+
body=body,
|
|
180
|
+
requires_signature=True,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
def export_key(self, key_id: str, body: T.ExportKeyRequest) -> T.ExportKeyResponse:
|
|
184
|
+
"""
|
|
185
|
+
Export Key.
|
|
186
|
+
|
|
187
|
+
Dfns secures private keys by generating them as MPC key shares in our decentralized key management network. Our goal is to eliminate all single points of failure (SPOFs) associated with blockchain private keys.
|
|
188
|
+
|
|
189
|
+
In certain circumstances, however, customers require Dfns to export a private key. In this case, Dfns exposes the following endpoint which can be used in conjunction with our [export SDK](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/sdk/export-wallet).
|
|
190
|
+
|
|
191
|
+
<Danger>
|
|
192
|
+
Dfns can not guarantee the security of exported keys as we have no way to control blockchain transactions once the single point of failure has been reconstituted. For this reason, this feature is restricted to customers who have signed a contractual addendum limiting our liability for exported keys. Additionally, by default exported keys can no longer be used to sign within the Dfns platform. Please contact your sales representative for more information.
|
|
193
|
+
</Danger>
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
key_id: Path parameter.
|
|
197
|
+
body: Request body.
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
T.ExportKeyResponse: The API response.
|
|
201
|
+
"""
|
|
202
|
+
return self._http.request(
|
|
203
|
+
method="POST",
|
|
204
|
+
path="/keys/{keyId}/export",
|
|
205
|
+
path_params={"keyId": key_id},
|
|
206
|
+
query_params=None,
|
|
207
|
+
body=body,
|
|
208
|
+
requires_signature=True,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
def list_signatures(self, key_id: str, query: Optional[T.ListSignaturesQuery] = None) -> T.ListSignaturesResponse:
|
|
212
|
+
"""
|
|
213
|
+
List Signatures.
|
|
214
|
+
|
|
215
|
+
List all signature requests for a key.
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
key_id: Path parameter.
|
|
219
|
+
query: Query parameters.
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
T.ListSignaturesResponse: The API response.
|
|
223
|
+
"""
|
|
224
|
+
return self._http.request(
|
|
225
|
+
method="GET",
|
|
226
|
+
path="/keys/{keyId}/signatures",
|
|
227
|
+
path_params={"keyId": key_id},
|
|
228
|
+
query_params=query,
|
|
229
|
+
body=None,
|
|
230
|
+
requires_signature=False,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
def generate_signature(self, key_id: str, body: dict[str, Any]) -> T.GenerateSignatureResponse:
|
|
234
|
+
"""
|
|
235
|
+
Generate Signature.
|
|
236
|
+
|
|
237
|
+
Request to generate a signature with the key. **This process does not broadcast anything on-chain**, this is just an off-chain signature request.
|
|
238
|
+
|
|
239
|
+
Dfns is compatible with any blockchain that uses a supported [key format](https://docs.dfns.co/networks/supported-key-formats). If Dfns doesn't officially integrate with a blockchain, you can use hash signing to generate the signatures to interact with the chain.
|
|
240
|
+
|
|
241
|
+
<Note>
|
|
242
|
+
If you were using the deprecated `POST /wallets/{walletId}/signatures` endpoint, then you should now use this one. See the [deprecation notice](https://docs.dfns.co/developers/guides/keys-and-multichain-migration-guide) to get more information about how to change your code. TL,DR: from a wallet you can obtain the key as `wallet.signingKey.id`.
|
|
243
|
+
</Note>
|
|
244
|
+
|
|
245
|
+
Args:
|
|
246
|
+
key_id: Path parameter.
|
|
247
|
+
body: Request body.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
T.GenerateSignatureResponse: The API response.
|
|
251
|
+
"""
|
|
252
|
+
return self._http.request(
|
|
253
|
+
method="POST",
|
|
254
|
+
path="/keys/{keyId}/signatures",
|
|
255
|
+
path_params={"keyId": key_id},
|
|
256
|
+
query_params=None,
|
|
257
|
+
body=body,
|
|
258
|
+
requires_signature=True,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
def get_signature(self, key_id: str, signature_id: str) -> T.GetSignatureResponse:
|
|
262
|
+
"""
|
|
263
|
+
Get Signature.
|
|
264
|
+
|
|
265
|
+
Retrieve a signature request details.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
key_id: Path parameter.
|
|
269
|
+
signature_id: Path parameter.
|
|
270
|
+
|
|
271
|
+
Returns:
|
|
272
|
+
T.GetSignatureResponse: The API response.
|
|
273
|
+
"""
|
|
274
|
+
return self._http.request(
|
|
275
|
+
method="GET",
|
|
276
|
+
path="/keys/{keyId}/signatures/{signatureId}",
|
|
277
|
+
path_params={"keyId": key_id, "signatureId": signature_id},
|
|
278
|
+
query_params=None,
|
|
279
|
+
body=None,
|
|
280
|
+
requires_signature=False,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
def import_key(self, body: T.ImportKeyRequest) -> T.ImportKeyResponse:
|
|
284
|
+
"""
|
|
285
|
+
Import Key.
|
|
286
|
+
|
|
287
|
+
Dfns secures private keys by generating them as MPC key shares in our decentralized key management network. This happens by default when you create a [key](https://docs.dfns.co/api-reference/keys/create-key) or [wallet](https://docs.dfns.co/api-reference/wallets/create-wallet).
|
|
288
|
+
|
|
289
|
+
In some circumstances, however, you may need to import an existing private key into Dfns infrastructure, instead of creating a brand new wallet with Dfns and transfer funds to it. As an example, you might want to keep an existing wallet if its address is tied to a smart contract which you don't want to re-deploy.
|
|
290
|
+
|
|
291
|
+
In such a case, Dfns exposes this key import API endpoint, which can be used in conjunction with our [import SDK](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/sdk/import-wallet). Note this is intended to be used only to migrate wallets when first onboarding onto the Dfns platform.
|
|
292
|
+
|
|
293
|
+
<Danger>
|
|
294
|
+
Dfns can not guarantee the security of imported wallets, as we have no way to control who had access to the private key prior to import. For this reason, this feature is restricted to Enterprise customers who have signed a contractual addendum limiting our liability for imported keys. Please contact your sales representative for more information.
|
|
295
|
+
</Danger>
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
body: Request body.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
T.ImportKeyResponse: The API response.
|
|
302
|
+
"""
|
|
303
|
+
return self._http.request(
|
|
304
|
+
method="POST",
|
|
305
|
+
path="/keys/import",
|
|
306
|
+
path_params={},
|
|
307
|
+
query_params=None,
|
|
308
|
+
body=body,
|
|
309
|
+
requires_signature=True,
|
|
310
|
+
)
|