@openfort/openfort-js 0.1.7 → 0.2.0

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.
@@ -0,0 +1 @@
1
+ src/generated
package/README.md CHANGED
@@ -1,33 +1,81 @@
1
- # openfort-typescript-client
1
+ # Openfort.js Library
2
2
 
3
- ## Registration of the player session
4
- 1. Create a key pair for the player:
5
- ```typescript
6
- const playerKey = new KeyPair();
3
+ [![Version](https://img.shields.io/npm/v/@openfort/openfort-js.svg)](https://www.npmjs.org/package/@openfort/openfort-js)
4
+
5
+ The Openfort js library provides convinient access to handle client session keys and return signed messages back to Openfort from applications written in client-side JavaScript.
6
+
7
+ ## Installation
8
+
9
+ ```shell
10
+ npm install @openfort/openfort-js
7
11
  ```
8
12
 
9
- 2. Authorize player with the game backend service and pass public key to the `openfortClient.players.createSession` api method
13
+ ```shell
14
+ yarn add @openfort/openfort-js
15
+ ```
10
16
 
11
- 3. Save private key. You can use local storage, file storage or any other type of storaged
12
- ```typescript
13
- await keyPair.saveToLocalStorage();
17
+ ## Usage
18
+
19
+ The package needs to be configured with your account's public key, which is
20
+ available in the [Openfort Dashboard][api-keys]. Require it with the key's
21
+ value:
22
+
23
+ ```js
24
+ import Openfort from '@openfort/openfort-js';
25
+ const openfort = new Openfort('pk_test_...');
14
26
  ```
27
+
28
+ ### Create and store a new player session key
29
+
30
+ 1. Create a session key pair for the player:
31
+
15
32
  ```typescript
16
- await keyPair.saveToFile();
33
+ openfort.createSessionKey();
17
34
  ```
35
+
36
+ 2. Save the generated session key pair on device:
37
+
18
38
  ```typescript
19
- await KeyPair.saveToStorage(customeStorageImplementation);
39
+ openfort.saveSessionKey();
20
40
  ```
21
41
 
22
- 4. Use the private key to communicate with openfort api.
42
+ 3. Authorize player with the game backend service and passing the address of the session key pair:
23
43
 
24
- 5. To the future use one of the load methods to load key pair. Depends on the solution, that was chosen in the step 4.
25
44
  ```typescript
26
- const playerKey = await KeyPair.loadFromLocalStorage();
45
+ const address = openfort.sessionKey.address
46
+ // API call to the game backend with the address to register it
27
47
  ```
48
+
49
+ #### Register the session key using a non-custodial signer
50
+
51
+ If the Openfort account is owned by an external signer, the owner must use it to sign and approve the registration of the session key. The hash containing the message to be signed appears in [next_actions][next-action] from the create session request.
52
+
28
53
  ```typescript
29
- const playerKey = await KeyPair.loadFromFile();
54
+ // Sign the message with the signer
55
+ await openfort.sendSignatureSessionRequest(
56
+ session_id,
57
+ signed_message
58
+ );
30
59
  ```
60
+
61
+ ### Use the session key to sign a message
62
+
63
+ The hash containing the message to be signed appears in [next_actions][next-action] from the create transactionIntent request.
64
+
31
65
  ```typescript
32
- const playerKey = await KeyPair.loadFromStorage(customeStorageImplementation);
66
+ await openfort.signMessage(message);
67
+ await openfort.sendSignatureTransactionIntentRequest(
68
+ transactionIntent_id,
69
+ signed_message
70
+ );
33
71
  ```
72
+
73
+ ## Usage examples
74
+ - [Next.js application with non-custodial signer](https://github.com/openfort-xyz/samples/tree/main/rainbow-ssv-nextjs)
75
+ - [Next.js application with custodial signer and social login](https://github.com/openfort-xyz/samples/tree/main/ssv-social-nextjs)
76
+
77
+ [next-action]: https://www.openfort.xyz/docs/api/transaction_intents#the-transaction-intent-object
78
+
79
+ <!--
80
+ # vim: set tw=79:
81
+ -->