@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.
- package/.prettierignore +1 -0
- package/README.md +64 -16
- package/dist/generated/api.d.ts +3907 -0
- package/dist/{api.js → generated/api.js} +1748 -1947
- package/dist/generated/api.js.map +1 -0
- package/dist/{base.d.ts → generated/base.d.ts} +2 -2
- package/dist/{base.js → generated/base.js} +1 -0
- package/dist/generated/base.js.map +1 -0
- package/dist/{common.d.ts → generated/common.d.ts} +1 -1
- package/dist/{common.js → generated/common.js} +11 -9
- package/dist/generated/common.js.map +1 -0
- package/dist/{configuration.js → generated/configuration.js} +2 -2
- package/dist/generated/configuration.js.map +1 -0
- package/dist/key-pair.d.ts +4 -0
- package/dist/key-pair.js +7 -1
- package/dist/key-pair.js.map +1 -1
- package/dist/openfort.d.ts +2 -1
- package/dist/openfort.js +8 -5
- package/dist/openfort.js.map +1 -1
- package/dist/storage/local-storage.js +1 -1
- package/dist/storage/local-storage.js.map +1 -1
- package/dist/storage/storage-keys.js +1 -1
- package/dist/storage/storage-keys.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/api.d.ts +0 -3028
- package/dist/api.js.map +0 -1
- package/dist/base.js.map +0 -1
- package/dist/common.js.map +0 -1
- package/dist/configuration.js.map +0 -1
- /package/dist/{configuration.d.ts → generated/configuration.d.ts} +0 -0
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src/generated
|
package/README.md
CHANGED
|
@@ -1,33 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Openfort.js Library
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
[](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
|
-
|
|
13
|
+
```shell
|
|
14
|
+
yarn add @openfort/openfort-js
|
|
15
|
+
```
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
33
|
+
openfort.createSessionKey();
|
|
17
34
|
```
|
|
35
|
+
|
|
36
|
+
2. Save the generated session key pair on device:
|
|
37
|
+
|
|
18
38
|
```typescript
|
|
19
|
-
|
|
39
|
+
openfort.saveSessionKey();
|
|
20
40
|
```
|
|
21
41
|
|
|
22
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
-->
|