@openfort/openfort-node 0.6.78 → 0.7.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/Makefile +75 -0
  3. package/README.md +174 -65
  4. package/biome.json +34 -4
  5. package/dist/index.d.mts +8871 -14863
  6. package/dist/index.d.ts +8871 -14863
  7. package/dist/index.js +4978 -24180
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +4677 -23904
  10. package/dist/index.mjs.map +1 -1
  11. package/examples/.env.example +16 -0
  12. package/examples/README.md +154 -0
  13. package/examples/contracts/createContract.ts +25 -0
  14. package/examples/contracts/listContracts.ts +18 -0
  15. package/examples/contracts/readContract.ts +29 -0
  16. package/examples/evm/accounts/createAccount.ts +18 -0
  17. package/examples/evm/accounts/exportAccount.ts +39 -0
  18. package/examples/evm/accounts/getAccount.ts +30 -0
  19. package/examples/evm/accounts/importAccount.ts +31 -0
  20. package/examples/evm/accounts/listAccounts.ts +32 -0
  21. package/examples/evm/signing/signHash.ts +28 -0
  22. package/examples/evm/signing/signMessage.ts +32 -0
  23. package/examples/evm/signing/signTransaction.ts +42 -0
  24. package/examples/evm/signing/signTypedData.ts +71 -0
  25. package/examples/exchange/createSwap.ts +49 -0
  26. package/examples/exchange/quoteSwap.ts +34 -0
  27. package/examples/iam/deleteUser.ts +22 -0
  28. package/examples/iam/getSession.ts +30 -0
  29. package/examples/iam/getUser.ts +32 -0
  30. package/examples/iam/listUsers.ts +18 -0
  31. package/examples/iam/pregenerateUser.ts +33 -0
  32. package/examples/package.json +31 -0
  33. package/examples/pnpm-lock.yaml +1231 -0
  34. package/examples/policies/createPolicy.ts +25 -0
  35. package/examples/policies/createPolicyRule.ts +43 -0
  36. package/examples/policies/disableEnablePolicy.ts +29 -0
  37. package/examples/policies/getPolicy.ts +30 -0
  38. package/examples/policies/listPolicies.ts +17 -0
  39. package/examples/policies/listPolicyRules.ts +37 -0
  40. package/examples/policies/updatePolicy.ts +29 -0
  41. package/examples/solana/accounts/createAccount.ts +18 -0
  42. package/examples/solana/accounts/exportAccount.ts +29 -0
  43. package/examples/solana/accounts/getAccount.ts +24 -0
  44. package/examples/solana/accounts/importAccount.ts +28 -0
  45. package/examples/solana/accounts/listAccounts.ts +32 -0
  46. package/examples/solana/signing/signMessage.ts +22 -0
  47. package/examples/solana/signing/signTransaction.ts +41 -0
  48. package/examples/transactions/createTransactionIntent.ts +49 -0
  49. package/examples/transactions/estimateGas.ts +52 -0
  50. package/examples/transactions/getTransactionIntent.ts +54 -0
  51. package/examples/transactions/listTransactionIntents.ts +31 -0
  52. package/examples/tsconfig.json +15 -0
  53. package/examples/webhook/index.ts +43 -0
  54. package/openapi-auth.json +6526 -0
  55. package/openapi.json +20425 -0
  56. package/orval.config.ts +41 -0
  57. package/package.json +22 -12
  58. package/pnpm-workspace.yaml +2 -0
  59. package/tsconfig.json +1 -1
  60. package/vitest.config.ts +20 -0
  61. package/updateGeneratedCode.sh +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#32](https://github.com/openfort-xyz/openfort-node/pull/32) [`105c4668d86686698d260822347dd873925b446f`](https://github.com/openfort-xyz/openfort-node/commit/105c4668d86686698d260822347dd873925b446f) Thanks [@jamalavedra](https://github.com/jamalavedra)! - include backend wallets and update account namespace interactions'
8
+
3
9
  ## 0.6.78
4
10
 
5
11
  ### Patch Changes
package/Makefile ADDED
@@ -0,0 +1,75 @@
1
+ .PHONY: update-openapi check-openapi generate-client help
2
+
3
+ # OpenAPI spec URLs with timestamp for cache-busting
4
+ TIMESTAMP := $(shell date +%s)
5
+ OPENAPI_MAIN_URL := https://api.openfort.io/api-docs/swagger.json?timestamp=$(TIMESTAMP)
6
+ OPENAPI_AUTH_URL := https://api.openfort.io/iam/v2/auth/reference?timestamp=$(TIMESTAMP)
7
+ OPENAPI_MAIN_LOCAL := openapi.json
8
+ OPENAPI_AUTH_LOCAL := openapi-auth.json
9
+ OPENAPI_MAIN_TEMP := openapi.json.new
10
+ OPENAPI_AUTH_TEMP := openapi-auth.json.new
11
+
12
+ help:
13
+ @echo "Available commands:"
14
+ @echo " make update-openapi - Download the latest OpenAPI specs (main + auth)"
15
+ @echo " make check-openapi - Check if newer OpenAPI specs are available"
16
+ @echo " make generate-client - Generate the TypeScript client from the specs"
17
+
18
+ # Generate the TypeScript client using Orval
19
+ generate-client:
20
+ @echo "Generating TypeScript client..."
21
+ @pnpm orval --config orval.config.ts
22
+ @echo "Client generated successfully!"
23
+
24
+ # Download all OpenAPI specs
25
+ update-openapi:
26
+ @echo "Downloading OpenAPI specs..."
27
+ @MAIN_UPDATED=0; AUTH_UPDATED=0; \
28
+ curl -s -o $(OPENAPI_MAIN_TEMP) "$(OPENAPI_MAIN_URL)"; \
29
+ curl -s -o $(OPENAPI_AUTH_TEMP) "$(OPENAPI_AUTH_URL)"; \
30
+ if [ ! -f $(OPENAPI_MAIN_LOCAL) ] || ! cmp -s $(OPENAPI_MAIN_TEMP) $(OPENAPI_MAIN_LOCAL); then \
31
+ mv $(OPENAPI_MAIN_TEMP) $(OPENAPI_MAIN_LOCAL); \
32
+ echo "Main API spec updated."; \
33
+ MAIN_UPDATED=1; \
34
+ else \
35
+ rm $(OPENAPI_MAIN_TEMP); \
36
+ echo "Main API spec is already up to date."; \
37
+ fi; \
38
+ if [ ! -f $(OPENAPI_AUTH_LOCAL) ] || ! cmp -s $(OPENAPI_AUTH_TEMP) $(OPENAPI_AUTH_LOCAL); then \
39
+ mv $(OPENAPI_AUTH_TEMP) $(OPENAPI_AUTH_LOCAL); \
40
+ echo "IAM v2 auth spec updated."; \
41
+ AUTH_UPDATED=1; \
42
+ else \
43
+ rm $(OPENAPI_AUTH_TEMP); \
44
+ echo "IAM v2 auth spec is already up to date."; \
45
+ fi
46
+
47
+ # Check if newer OpenAPI specs are available (returns exit code 1 if update available)
48
+ check-openapi:
49
+ @echo "Checking for OpenAPI updates..."
50
+ @NEEDS_UPDATE=0; \
51
+ curl -s -o $(OPENAPI_MAIN_TEMP) "$(OPENAPI_MAIN_URL)"; \
52
+ curl -s -o $(OPENAPI_AUTH_TEMP) "$(OPENAPI_AUTH_URL)"; \
53
+ if [ ! -f $(OPENAPI_MAIN_LOCAL) ]; then \
54
+ echo "Main API spec not found locally."; \
55
+ NEEDS_UPDATE=1; \
56
+ elif ! cmp -s $(OPENAPI_MAIN_TEMP) $(OPENAPI_MAIN_LOCAL); then \
57
+ echo "A newer main API spec is available."; \
58
+ NEEDS_UPDATE=1; \
59
+ else \
60
+ echo "Main API spec is up to date."; \
61
+ fi; \
62
+ if [ ! -f $(OPENAPI_AUTH_LOCAL) ]; then \
63
+ echo "IAM v2 auth spec not found locally."; \
64
+ NEEDS_UPDATE=1; \
65
+ elif ! cmp -s $(OPENAPI_AUTH_TEMP) $(OPENAPI_AUTH_LOCAL); then \
66
+ echo "A newer IAM v2 auth spec is available."; \
67
+ NEEDS_UPDATE=1; \
68
+ else \
69
+ echo "IAM v2 auth spec is up to date."; \
70
+ fi; \
71
+ rm -f $(OPENAPI_MAIN_TEMP) $(OPENAPI_AUTH_TEMP); \
72
+ if [ $$NEEDS_UPDATE -eq 1 ]; then \
73
+ echo "Run 'make update-openapi' to update."; \
74
+ exit 1; \
75
+ fi
package/README.md CHANGED
@@ -1,104 +1,213 @@
1
- ![Illustration_04 1-min](https://github.com/user-attachments/assets/84796219-8196-40fb-a28a-6ca24a388818)
2
-
3
1
  <div align="center">
4
- <h4>
5
- <a href="https://www.openfort.io/">
6
- Website
7
- </a>
8
- <span> | </span>
9
- <a href="https://www.openfort.io/docs">
10
- Documentation
11
- </a>
12
- <span> | </span>
13
- <a href="https://x.com/openfort_hq">
14
- Twitter
15
- </a>
16
- </h4>
2
+
3
+ ![Openfort](https://github.com/user-attachments/assets/84796219-8196-40fb-a28a-6ca24a388818)
4
+
5
+ <p>
6
+ Server-side SDK for managing EVM and Solana wallets, gas sponsorship, and blockchain interactions.
7
+ </p>
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@openfort/openfort-node.svg)](https://www.npmjs.org/package/@openfort/openfort-node)
10
+ [![npm downloads](https://img.shields.io/npm/dm/@openfort/openfort-node.svg)](https://www.npmjs.org/package/@openfort/openfort-node)
11
+ [![Follow @openfort_hq](https://img.shields.io/twitter/follow/openfort_hq.svg?style=social)](https://x.com/openfort_hq)
12
+ [![MIT License](https://img.shields.io/badge/license-MIT-0052FF?style=flat-square)](https://github.com/openfort-xyz/openfort-node/blob/main/LICENSE)
13
+
17
14
  </div>
18
15
 
16
+ <br />
17
+
18
+ ## Table of Contents
19
19
 
20
- # Openfort Node.js Library
20
+ - [Table of Contents](#table-of-contents)
21
+ - [Overview](#overview)
22
+ - [Installation](#installation)
23
+ - [Quickstart](#quickstart)
24
+ - [Features](#features)
25
+ - [Wallet Management](#wallet-management)
26
+ - [Signing](#signing)
27
+ - [Gas Sponsorship](#gas-sponsorship)
28
+ - [IAM \& Authentication](#iam--authentication)
29
+ - [Examples](#examples)
30
+ - [Documentation](#documentation)
31
+ - [Support](#support)
32
+ - [License](#license)
21
33
 
22
- [![Version](https://img.shields.io/npm/v/@openfort/openfort-node.svg)](https://www.npmjs.org/package/@openfort/openfort-node)
34
+ ## Overview
23
35
 
24
- The Openfort Node library provides convenient access to the Openfort API from applications written in server-side JavaScript.
25
- \
26
- ## Requirements
36
+ The Openfort Node.js SDK provides convenient access to the [Openfort API](https://www.openfort.io/docs) for server-side applications. It enables developers to:
27
37
 
28
- Node 14 or higher.
38
+ - Create and manage EVM and Solana backend wallets
39
+ - Sign messages, typed data, and transactions
40
+ - Execute gasless transactions with gas sponsorship policies
41
+ - Manage users, accounts, and transaction intents
42
+ - Integrate with smart contracts and token swaps
29
43
 
30
44
  ## Installation
31
45
 
32
- ```shell
46
+ Requires Node.js 14 or higher.
47
+
48
+ ```bash
33
49
  npm install @openfort/openfort-node
34
50
  ```
35
51
 
36
- ```shell
52
+ ```bash
37
53
  yarn add @openfort/openfort-node
38
54
  ```
39
55
 
40
- ## Usage
56
+ ```bash
57
+ pnpm add @openfort/openfort-node
58
+ ```
59
+
60
+ ## Quickstart
61
+
62
+ Get your API key from the [Openfort Dashboard](https://dashboard.openfort.io/api-keys).
63
+
64
+ ```typescript
65
+ import Openfort from "@openfort/openfort-node";
41
66
 
42
- The package needs to be configured with your account's secret key, which is
43
- available in the [Openfort Dashboard][api-keys]. Require it with the key's
44
- value:
67
+ const openfort = new Openfort("sk_test_...", {
68
+ walletSecret: "your-wallet-secret", // Required for signing operations
69
+ });
45
70
 
46
- <!-- prettier-ignore -->
47
- ```js
48
- const openfort = require('@openfort/openfort-node')('sk_test_...');
71
+ // Create an EVM backend account
72
+ const account = await openfort.accounts.evm.backend.create({
73
+ name: "MyWallet",
74
+ });
75
+ console.log("Account address:", account.address);
49
76
 
50
- openfort.players.create({
51
- name: 'Joan McCoain',
52
- description: 'API created player'
53
- })
54
- .then(player => console.log(player.id))
55
- .catch(error => console.error(error));
77
+ // Sign a message (methods are on the account object)
78
+ const signature = await account.signMessage({
79
+ message: "Hello, Openfort!",
80
+ });
81
+ console.log("Signature:", signature);
56
82
  ```
57
83
 
58
- Or using ES modules and `async`/`await`:
84
+ ## Features
85
+
86
+ ### Wallet Management
87
+
88
+ Create and manage wallets across EVM chains and Solana:
59
89
 
60
- ```js
61
- import Openfort from '@openfort/openfort-node';
62
- const openfort = new Openfort('sk_test_...');
90
+ ```typescript
91
+ // EVM backend accounts
92
+ const evmAccount = await openfort.accounts.evm.backend.create({
93
+ name: "MyEVMWallet",
94
+ });
63
95
 
64
- const player = await openfort.players.create({
65
- name: 'customer@example.com',
66
- description: 'API created player'
96
+ // Solana backend accounts
97
+ const solanaAccount = await openfort.accounts.solana.backend.create({
98
+ name: "MySolanaWallet",
67
99
  });
68
100
 
69
- console.log(player.id);
101
+ // Import existing wallet
102
+ const imported = await openfort.accounts.evm.backend.import({
103
+ privateKey: "0x...",
104
+ name: "ImportedWallet",
105
+ });
70
106
  ```
71
107
 
72
- Below code snippet shows exemplary usage of the configuration and the API.
108
+ ### Signing
109
+
110
+ Sign messages, typed data, and transactions. Methods are called directly on the account object:
73
111
 
74
112
  ```typescript
75
- import Openfort from "@openfort/openfort-node";
113
+ // Sign message
114
+ const signature = await account.signMessage({
115
+ message: "Hello, Openfort!",
116
+ });
76
117
 
77
- async function example() {
78
- const openfort = new Openfort("sk_test_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
79
- const players = await openfort.players.list();
80
- for (const player of players.data) {
81
- console.log(player.id);
82
- }
118
+ // Sign EIP-712 typed data
119
+ const typedSig = await account.signTypedData({
120
+ domain: { name: "MyApp", version: "1", chainId: 1 },
121
+ types: {
122
+ Person: [
123
+ { name: "name", type: "string" },
124
+ { name: "wallet", type: "address" },
125
+ ],
126
+ },
127
+ primaryType: "Person",
128
+ message: { name: "Alice", wallet: "0x..." },
129
+ });
130
+ ```
131
+
132
+ ### Gas Sponsorship
133
+
134
+ Sponsor gas fees for your users with policies:
135
+
136
+ ```typescript
137
+ // Create a sponsorship policy
138
+ const policy = await openfort.policies.create({
139
+ name: "Free gas for users",
140
+ chainId: 80002,
141
+ strategy: { sponsorSchema: "pay_for_user" },
142
+ });
143
+
144
+ // Register a contract
145
+ const contract = await openfort.contracts.create({
146
+ name: "MyContract",
147
+ chainId: 80002,
148
+ address: "0x38090d1636069c0ff1af6bc1737fb996b7f63ac0",
149
+ });
150
+
151
+ // Add rules to control sponsorship
152
+ await openfort.policyRules.create({
153
+ policy: policy.id,
154
+ type: "account_functions",
155
+ contract: contract.id,
156
+ functionName: "mint",
157
+ });
158
+ ```
83
159
 
84
- const newPlayer = await openfort.players.create({name: "Test"});
85
- console.log(newPlayer.id)
160
+ ### IAM & Authentication
86
161
 
87
- const transactionIntents = await openfort.transactionIntents.list();
88
- for (const intent of transactionIntents.data) {
89
- console.log(`Intent ${intent.id} by ${intent.player.name}`);
90
- }
91
- }
162
+ Manage users and verify sessions:
92
163
 
93
- example().catch((e) => console.error(e));
164
+ ```typescript
165
+ // List authenticated users
166
+ const users = await openfort.iam.users.list({ limit: 10 });
167
+
168
+ // Verify session from access token
169
+ const session = await openfort.iam.getSession({ accessToken });
170
+ console.log("User ID:", session.user.id);
171
+ console.log("Session expires:", session.session.expiresAt);
172
+ ```
173
+
174
+
175
+ ## Examples
176
+
177
+ The SDK includes comprehensive examples for all features. See the [examples directory](./examples) for runnable code.
178
+
179
+ | Category | Examples |
180
+ | -------------- | -------------------------------------------------- |
181
+ | EVM Wallets | Create, import, export, sign messages/transactions |
182
+ | Solana Wallets | Create, import, export, sign messages/transactions |
183
+ | Policies | Gas sponsorship, policy rules, enable/disable |
184
+ | Transactions | Create intents, estimate gas, read contracts |
185
+ | Exchange | Token swap quotes and execution |
186
+ | IAM | User management, session verification |
187
+
188
+ Run examples:
189
+
190
+ ```bash
191
+ cd examples
192
+ cp .env.example .env
193
+ # Edit .env with your API key
194
+ pnpm example evm/accounts/createAccount.ts
94
195
  ```
95
196
 
197
+ ## Documentation
198
+
199
+ - [Official Documentation](https://www.openfort.io/docs)
200
+ - [API Reference](https://www.openfort.io/docs/reference/api)
201
+ - [Dashboard](https://dashboard.openfort.io)
202
+
96
203
  ## Support
97
204
 
98
- New features and bug fixes are released on the latest major version of the `openfort` package. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
205
+ - [GitHub Issues](https://github.com/openfort-xyz/openfort-node/issues) - Report bugs and request features
206
+ - [Twitter](https://x.com/openfort_hq) - Follow for updates
207
+ - [Website](https://www.openfort.io) - Learn more about Openfort
208
+
209
+ New features and bug fixes are released on the latest major version. We recommend upgrading to the latest version for security updates and new functionality.
99
210
 
100
- [api-keys]: https://dashboard.openfort.io/api-keys
211
+ ## License
101
212
 
102
- <!--
103
- # vim: set tw=79:
104
- -->
213
+ This project is licensed under the MIT License.
package/biome.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3
3
  "files": {
4
- "includes": ["src/**/*", "*.ts", "*.js", "!src/generated", "*.json"]
4
+ "includes": [
5
+ "src/**/*",
6
+ "*.ts",
7
+ "*.js",
8
+ "!src/generated",
9
+ "!src/openapi-client/generated",
10
+ "*.json"
11
+ ]
5
12
  },
6
13
  "formatter": {
7
14
  "enabled": true,
@@ -24,8 +31,14 @@
24
31
  "noUnusedVariables": "error"
25
32
  },
26
33
  "performance": {
27
- "noBarrelFile": "error",
28
- "noReExportAll": "error",
34
+ "noBarrelFile": {
35
+ "level": "error",
36
+ "options": {}
37
+ },
38
+ "noReExportAll": {
39
+ "level": "error",
40
+ "options": {}
41
+ },
29
42
  "noDelete": "off"
30
43
  },
31
44
  "style": {
@@ -52,5 +65,22 @@
52
65
  "semicolons": "asNeeded"
53
66
  }
54
67
  },
55
- "assist": { "actions": { "source": { "organizeImports": "on" } } }
68
+ "assist": { "actions": { "source": { "organizeImports": "on" } } },
69
+ "overrides": [
70
+ {
71
+ "includes": [
72
+ "src/index.ts",
73
+ "src/openapi-client/index.ts",
74
+ "src/wallets/**/index.ts"
75
+ ],
76
+ "linter": {
77
+ "rules": {
78
+ "performance": {
79
+ "noBarrelFile": "off",
80
+ "noReExportAll": "off"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ ]
56
86
  }