|
1 | 1 | import { Code } from '/components/Code'; |
2 | 2 |
|
3 | 3 | # Keypair |
4 | | -**Keypair is the combination of a public key and private key, any authorized action requires this.** |
| 4 | +**Keypair is the combination of a public key and private key. It handles key generation, signing, and key management.** |
5 | 5 |
|
6 | 6 | <Code> |
7 | | - ```python |
8 | | - class Keypair(value: NaclPrivateKey | None = None) |
9 | | - ``` |
| 7 | +```python |
| 8 | +class Keypair(value: NaclPrivateKey | None = None) |
| 9 | +``` |
10 | 10 | </Code> |
11 | 11 |
|
12 | | -> The value is required to initialise the object with an existing [nacl.Public.PrivateKey](https://pynacl.readthedocs.io/en/latest/public/#nacl.public.PrivateKey) object. To initialize with a private key as a string or bytes, use [from_private_key](#from_private_key) class method. Without the value a new keypair is generated. |
| 12 | +> The value is optional. Without a value, a new keypair is generated. If provided, it must be a [nacl.public.PrivateKey](https://pynacl.readthedocs.io/en/latest/public/#nacl.public.PrivateKey) object. To initialize with a private key as a string or bytes, use [from_private_key](#from_private_key) class method. |
13 | 13 |
|
14 | 14 | #### Methods |
15 | 15 | - [sign](#sign) |
16 | 16 | - [from_private_key](#from_private_key) |
| 17 | +- [from_file](#from_file) |
17 | 18 |
|
18 | 19 | #### Attributes |
19 | 20 | - [public_key](#public_key) |
20 | 21 | - [private_key](#private_key) |
21 | 22 | - [key_pair](#key_pair) |
22 | 23 |
|
23 | | - |
24 | 24 | ## Methods |
25 | 25 |
|
26 | 26 | #### .sign |
27 | | -Signs a message which can be either a string or bytes. |
| 27 | +Signs a message using the keypair's private key. |
28 | 28 |
|
29 | 29 | <Code> |
30 | 30 | ```python |
31 | | -def sign(message: str | bytes) |
| 31 | +def sign(message: str | bytes) -> SignedMessage |
32 | 32 | ``` |
33 | 33 | </Code> |
34 | 34 |
|
| 35 | +> Returns a SignedMessage object from PyNaCl. The message can be either a UTF-8 string or bytes. |
| 36 | + |
35 | 37 | #### .from_private_key |
36 | | -Initializes the keypair object using a private key, which can be either a string or bytes. |
| 38 | +Class method that creates a Keypair from an existing private key. |
| 39 | + |
| 40 | +<Code> |
| 41 | +```python |
| 42 | +@classmethod |
| 43 | +def from_private_key(cls, private_key: str | List[int]) -> Keypair |
| 44 | +``` |
| 45 | +</Code> |
| 46 | + |
| 47 | +> Accepts either a base58-encoded string or a list of integers representing the private key. Returns a new Keypair instance. |
| 48 | + |
| 49 | +#### .from_file |
| 50 | +Class method that loads a Keypair from a JSON file containing the private key. |
37 | 51 |
|
38 | 52 | <Code> |
39 | 53 | ```python |
40 | | -def from_private_key(private_key: str | bytes) |
| 54 | +@staticmethod |
| 55 | +def from_file(file_path: str) -> Keypair |
41 | 56 | ``` |
42 | 57 | </Code> |
43 | 58 |
|
| 59 | +> Reads a JSON file containing the private key data and returns a new Keypair instance. |
44 | 60 |
|
45 | 61 | ## Attributes |
46 | 62 |
|
47 | 63 | #### .public_key |
48 | | -Returns the keypair object's public key. |
| 64 | +The keypair's public key as a PublicKey instance. |
49 | 65 |
|
50 | 66 | #### .private_key |
51 | | -Returns the keypair object's private key. |
| 67 | +The keypair's private key as a PrivateKey instance. |
52 | 68 |
|
53 | 69 | #### .key_pair |
54 | | -Returns the keypair value itself in bytes. |
| 70 | +The underlying NaclPrivateKey object used in bytes |
0 commit comments