@openfort/openfort-node 0.9.3 → 0.10.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 (45) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.mts +274 -84
  3. package/dist/index.d.ts +274 -84
  4. package/dist/index.js +423 -35
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +423 -45
  7. package/dist/index.mjs.map +1 -1
  8. package/examples/evm/policies/createAccountPolicy.ts +68 -0
  9. package/examples/evm/policies/createProjectPolicy.ts +53 -0
  10. package/examples/evm/policies/deletePolicy.ts +34 -0
  11. package/examples/evm/policies/getPolicyById.ts +34 -0
  12. package/examples/evm/policies/listAccountPolicies.ts +11 -0
  13. package/examples/evm/policies/listPolicies.ts +11 -0
  14. package/examples/evm/policies/listProjectPolicies.ts +11 -0
  15. package/examples/evm/policies/signTypedDataPolicy.ts +35 -0
  16. package/examples/evm/policies/updatePolicy.ts +44 -0
  17. package/examples/evm/policies/validation.ts +45 -0
  18. package/examples/evm/transactions/sendTransaction.ts +44 -0
  19. package/examples/package.json +13 -0
  20. package/examples/pnpm-lock.yaml +933 -0
  21. package/examples/solana/policies/createSolAllowlistPolicy.ts +27 -0
  22. package/examples/solana/policies/createSolMessagePolicy.ts +29 -0
  23. package/examples/solana/policies/createSplTokenLimitsPolicy.ts +33 -0
  24. package/examples/solana/transactions/sendRawTransaction.ts +23 -0
  25. package/examples/solana/transactions/sendTransaction.ts +37 -0
  26. package/examples/solana/transactions/transfer.ts +44 -0
  27. package/knip.json +10 -1
  28. package/package.json +42 -4
  29. package/tsconfig.json +2 -3
  30. package/examples/policies/createAccountPolicy.ts +0 -71
  31. package/examples/policies/createEvmPolicy.ts +0 -149
  32. package/examples/policies/createSolanaPolicy.ts +0 -176
  33. package/examples/policies/createTypedDataPolicy.ts +0 -159
  34. package/examples/policies/deletePolicy.ts +0 -34
  35. package/examples/policies/getPolicy.ts +0 -41
  36. package/examples/policies/listPolicies.ts +0 -34
  37. package/examples/policies/multiRulePolicy.ts +0 -133
  38. package/examples/policies/updatePolicy.ts +0 -77
  39. package/examples/policies/validatePolicy.ts +0 -176
  40. /package/examples/{contracts → evm/contracts}/createContract.ts +0 -0
  41. /package/examples/{contracts → evm/contracts}/listContracts.ts +0 -0
  42. /package/examples/{transactions → evm/transactionIntents}/createTransactionIntent.ts +0 -0
  43. /package/examples/{transactions → evm/transactionIntents}/estimateGas.ts +0 -0
  44. /package/examples/{transactions → evm/transactionIntents}/getTransactionIntent.ts +0 -0
  45. /package/examples/{transactions → evm/transactionIntents}/listTransactionIntents.ts +0 -0
@@ -1,176 +0,0 @@
1
- // Usage: npx tsx policies/createSolanaPolicy.ts
2
- //
3
- // Creates policies that control Solana signing operations.
4
- // Demonstrates: SOL value limits, address allowlists, SPL token criteria,
5
- // program ID restrictions, and Solana network constraints.
6
-
7
- import Openfort, {
8
- CreatePolicyBodySchema,
9
- type CreatePolicyBody,
10
- } from "@openfort/openfort-node";
11
- import "dotenv/config";
12
-
13
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
14
- basePath: process.env.OPENFORT_BASE_URL,
15
- });
16
-
17
- // ---------------------------------------------------------------------------
18
- // 1. Reject high-value SOL transfers (> 10 SOL)
19
- // ---------------------------------------------------------------------------
20
-
21
- const solValueBody: CreatePolicyBody = {
22
- scope: "project",
23
- description: "Reject SOL transfers above 10 SOL",
24
- rules: [
25
- {
26
- action: "reject",
27
- operation: "signSolTransaction",
28
- criteria: [
29
- {
30
- type: "solValue",
31
- operator: ">=",
32
- value: "10000000000", // 10 SOL in lamports
33
- },
34
- ],
35
- },
36
- ],
37
- };
38
-
39
- CreatePolicyBodySchema.parse(solValueBody);
40
-
41
- const solValuePolicy = await openfort.policies.create(solValueBody);
42
- console.log("Created SOL value limit policy:");
43
- console.log(" ID:", solValuePolicy.id);
44
-
45
- // ---------------------------------------------------------------------------
46
- // 2. SOL address allowlist
47
- // ---------------------------------------------------------------------------
48
-
49
- const addressBody: CreatePolicyBody = {
50
- scope: "project",
51
- description: "Only allow transfers to known Solana addresses",
52
- rules: [
53
- {
54
- action: "accept",
55
- operation: "sendSolTransaction",
56
- criteria: [
57
- {
58
- type: "solAddress",
59
- operator: "in",
60
- addresses: [
61
- "DtdSSG8ZJRZVv5Jx7K1MeWp7Zxcu19GD5wQRGRpQ9uMF",
62
- "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
63
- ],
64
- },
65
- ],
66
- },
67
- ],
68
- };
69
-
70
- CreatePolicyBodySchema.parse(addressBody);
71
-
72
- const addressPolicy = await openfort.policies.create(addressBody);
73
- console.log("\nCreated SOL address allowlist policy:");
74
- console.log(" ID:", addressPolicy.id);
75
-
76
- // ---------------------------------------------------------------------------
77
- // 3. SPL token transfer restrictions (e.g. USDC mint)
78
- // ---------------------------------------------------------------------------
79
-
80
- const splBody: CreatePolicyBody = {
81
- scope: "project",
82
- description: "Restrict SPL transfers to specific USDC mint and recipients",
83
- rules: [
84
- {
85
- action: "accept",
86
- operation: "signSolTransaction",
87
- criteria: [
88
- {
89
- type: "mintAddress",
90
- operator: "==",
91
- addresses: ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"], // USDC
92
- },
93
- {
94
- type: "splAddress",
95
- operator: "in",
96
- addresses: ["DtdSSG8ZJRZVv5Jx7K1MeWp7Zxcu19GD5wQRGRpQ9uMF"],
97
- },
98
- {
99
- type: "splValue",
100
- operator: "<=",
101
- value: "1000000000", // 1000 USDC (6 decimals)
102
- },
103
- ],
104
- },
105
- ],
106
- };
107
-
108
- CreatePolicyBodySchema.parse(splBody);
109
-
110
- const splPolicy = await openfort.policies.create(splBody);
111
- console.log("\nCreated SPL token policy:");
112
- console.log(" ID:", splPolicy.id);
113
-
114
- // ---------------------------------------------------------------------------
115
- // 4. Program ID restriction with network constraint
116
- // ---------------------------------------------------------------------------
117
-
118
- const programBody: CreatePolicyBody = {
119
- scope: "project",
120
- description: "Only allow interactions with specific programs on mainnet",
121
- rules: [
122
- {
123
- action: "accept",
124
- operation: "sendSolTransaction",
125
- criteria: [
126
- {
127
- type: "programId",
128
- operator: "in",
129
- programIds: [
130
- "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", // Token Program
131
- "11111111111111111111111111111111", // System Program
132
- ],
133
- },
134
- {
135
- type: "solNetwork",
136
- operator: "in",
137
- networks: ["mainnet-beta"],
138
- },
139
- ],
140
- },
141
- ],
142
- };
143
-
144
- CreatePolicyBodySchema.parse(programBody);
145
-
146
- const programPolicy = await openfort.policies.create(programBody);
147
- console.log("\nCreated program ID + network policy:");
148
- console.log(" ID:", programPolicy.id);
149
-
150
- // ---------------------------------------------------------------------------
151
- // 5. Sign Solana message — restrict to matching pattern
152
- // ---------------------------------------------------------------------------
153
-
154
- const messageBody: CreatePolicyBody = {
155
- scope: "project",
156
- description: "Only allow signing messages that match a known format",
157
- rules: [
158
- {
159
- action: "accept",
160
- operation: "signSolMessage",
161
- criteria: [
162
- {
163
- type: "solMessage",
164
- operator: "match",
165
- pattern: "^Sign in to MyApp:",
166
- },
167
- ],
168
- },
169
- ],
170
- };
171
-
172
- CreatePolicyBodySchema.parse(messageBody);
173
-
174
- const messagePolicy = await openfort.policies.create(messageBody);
175
- console.log("\nCreated Solana message policy:");
176
- console.log(" ID:", messagePolicy.id);
@@ -1,159 +0,0 @@
1
- // Usage: npx tsx policies/createTypedDataPolicy.ts
2
- //
3
- // Creates policies for EVM typed-data signing (EIP-712) and message signing
4
- // operations.
5
-
6
- import Openfort, {
7
- CreatePolicyBodySchema,
8
- type CreatePolicyBody,
9
- } from "@openfort/openfort-node";
10
- import "dotenv/config";
11
-
12
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
13
- basePath: process.env.OPENFORT_BASE_URL,
14
- });
15
-
16
- // ---------------------------------------------------------------------------
17
- // 1. Restrict typed-data signing to specific verifying contracts
18
- // ---------------------------------------------------------------------------
19
-
20
- const verifyingContractBody: CreatePolicyBody = {
21
- scope: "project",
22
- description: "Only allow signing typed data from known contracts",
23
- rules: [
24
- {
25
- action: "accept",
26
- operation: "signEvmTypedData",
27
- criteria: [
28
- {
29
- type: "evmTypedDataVerifyingContract",
30
- operator: "in",
31
- addresses: [
32
- "0x000000000000000000000000000000000000dEaD",
33
- "0x1234567890abcdef1234567890abcdef12345678",
34
- ],
35
- },
36
- ],
37
- },
38
- ],
39
- };
40
-
41
- CreatePolicyBodySchema.parse(verifyingContractBody);
42
-
43
- const verifyingPolicy = await openfort.policies.create(
44
- verifyingContractBody,
45
- );
46
- console.log("Created verifying-contract typed-data policy:");
47
- console.log(" ID:", verifyingPolicy.id);
48
-
49
- // ---------------------------------------------------------------------------
50
- // 2. Restrict typed-data field values (e.g. limit order amount)
51
- // ---------------------------------------------------------------------------
52
-
53
- const fieldBody: CreatePolicyBody = {
54
- scope: "project",
55
- description: "Restrict Order.amount to known values",
56
- rules: [
57
- {
58
- action: "accept",
59
- operation: "signEvmTypedData",
60
- criteria: [
61
- {
62
- type: "evmTypedDataField",
63
- operator: "in",
64
- fieldPath: "Order.amount",
65
- values: ["100", "200", "500"],
66
- },
67
- ],
68
- },
69
- ],
70
- };
71
-
72
- CreatePolicyBodySchema.parse(fieldBody);
73
-
74
- const fieldPolicy = await openfort.policies.create(fieldBody);
75
- console.log("\nCreated typed-data field restriction policy:");
76
- console.log(" ID:", fieldPolicy.id);
77
-
78
- // ---------------------------------------------------------------------------
79
- // 3. Combined: verifying contract + field constraint
80
- // ---------------------------------------------------------------------------
81
-
82
- const combinedBody: CreatePolicyBody = {
83
- scope: "project",
84
- description: "Accept orders from known contract with capped amount",
85
- rules: [
86
- {
87
- action: "accept",
88
- operation: "signEvmTypedData",
89
- criteria: [
90
- {
91
- type: "evmTypedDataVerifyingContract",
92
- operator: "in",
93
- addresses: ["0x000000000000000000000000000000000000dEaD"],
94
- },
95
- {
96
- type: "evmTypedDataField",
97
- operator: "<=",
98
- fieldPath: "Order.amount",
99
- value: "1000",
100
- },
101
- ],
102
- },
103
- ],
104
- };
105
-
106
- CreatePolicyBodySchema.parse(combinedBody);
107
-
108
- const combinedPolicy = await openfort.policies.create(combinedBody);
109
- console.log("\nCreated combined typed-data policy:");
110
- console.log(" ID:", combinedPolicy.id);
111
-
112
- // ---------------------------------------------------------------------------
113
- // 4. EVM message signing — restrict to known pattern
114
- // ---------------------------------------------------------------------------
115
-
116
- const messageBody: CreatePolicyBody = {
117
- scope: "project",
118
- description: "Only allow signing messages that match the login format",
119
- rules: [
120
- {
121
- action: "accept",
122
- operation: "signEvmMessage",
123
- criteria: [
124
- {
125
- type: "evmMessage",
126
- operator: "match",
127
- pattern: "^Sign in to MyApp: nonce=",
128
- },
129
- ],
130
- },
131
- ],
132
- };
133
-
134
- CreatePolicyBodySchema.parse(messageBody);
135
-
136
- const messagePolicy = await openfort.policies.create(messageBody);
137
- console.log("\nCreated EVM message signing policy:");
138
- console.log(" ID:", messagePolicy.id);
139
-
140
- // ---------------------------------------------------------------------------
141
- // 5. Reject all raw hash signing (no criteria = blanket rule)
142
- // ---------------------------------------------------------------------------
143
-
144
- const hashBody: CreatePolicyBody = {
145
- scope: "project",
146
- description: "Reject all raw hash signing operations",
147
- rules: [
148
- {
149
- action: "reject",
150
- operation: "signEvmHash",
151
- },
152
- ],
153
- };
154
-
155
- CreatePolicyBodySchema.parse(hashBody);
156
-
157
- const hashPolicy = await openfort.policies.create(hashBody);
158
- console.log("\nCreated hash signing rejection policy:");
159
- console.log(" ID:", hashPolicy.id);
@@ -1,34 +0,0 @@
1
- // Usage: npx tsx policies/deletePolicy.ts
2
-
3
- import Openfort, {
4
- CreatePolicyBodySchema,
5
- type CreatePolicyBody,
6
- } from "@openfort/openfort-node";
7
- import "dotenv/config";
8
-
9
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
- basePath: process.env.OPENFORT_BASE_URL,
11
- });
12
-
13
- // Create a policy to delete
14
- const body: CreatePolicyBody = {
15
- scope: "project",
16
- description: "Temporary policy to be deleted",
17
- rules: [
18
- {
19
- action: "reject",
20
- operation: "signEvmHash",
21
- },
22
- ],
23
- };
24
- CreatePolicyBodySchema.parse(body);
25
-
26
- const policy = await openfort.policies.create(body);
27
- console.log("Created policy:", policy.id);
28
-
29
- // Delete the policy (soft delete)
30
- const result = await openfort.policies.delete(policy.id);
31
-
32
- console.log("\nDeleted policy:");
33
- console.log(" ID:", result.id);
34
- console.log(" Deleted:", result.deleted);
@@ -1,41 +0,0 @@
1
- // Usage: npx tsx policies/getPolicy.ts
2
-
3
- import Openfort, {
4
- CreatePolicyBodySchema,
5
- type CreatePolicyBody,
6
- } from "@openfort/openfort-node";
7
- import "dotenv/config";
8
-
9
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
- basePath: process.env.OPENFORT_BASE_URL,
11
- });
12
-
13
- // Create a policy first
14
- const body: CreatePolicyBody = {
15
- scope: "project",
16
- description: "Test policy to retrieve",
17
- rules: [
18
- {
19
- action: "reject",
20
- operation: "signEvmHash",
21
- },
22
- ],
23
- };
24
- CreatePolicyBodySchema.parse(body);
25
-
26
- const created = await openfort.policies.create(body);
27
- console.log("Created policy:", created.id);
28
-
29
- // Retrieve the policy by ID
30
- const policy = await openfort.policies.get(created.id);
31
-
32
- console.log("\nRetrieved policy:");
33
- console.log(" ID:", policy.id);
34
- console.log(" Scope:", policy.scope);
35
- console.log(" Description:", policy.description);
36
- console.log(" Enabled:", policy.enabled);
37
- console.log(" Priority:", policy.priority);
38
- console.log(" Rules:");
39
- for (const rule of policy.rules) {
40
- console.log(` - Action: ${rule.action}, Operation: ${rule.operation}`);
41
- }
@@ -1,34 +0,0 @@
1
- // Usage: npx tsx policies/listPolicies.ts
2
-
3
- import Openfort from "@openfort/openfort-node";
4
- import "dotenv/config";
5
-
6
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
7
- basePath: process.env.OPENFORT_BASE_URL,
8
- });
9
-
10
- // List all policies
11
- const result = await openfort.policies.list({ limit: 10 });
12
-
13
- console.log(`Found ${result.total} policies:`);
14
- for (const policy of result.data) {
15
- console.log(` - ${policy.id}`);
16
- console.log(` Scope: ${policy.scope}`);
17
- console.log(` Description: ${policy.description ?? "(none)"}`);
18
- console.log(` Enabled: ${policy.enabled}`);
19
- console.log(` Rules: ${policy.rules.length}`);
20
- }
21
-
22
- // List only project-scoped policies
23
- console.log("\nProject-scoped policies:");
24
- const projectPolicies = await openfort.policies.list({
25
- scope: "project",
26
- });
27
- console.log(` Found: ${projectPolicies.total}`);
28
-
29
- // List only account-scoped policies
30
- console.log("\nAccount-scoped policies:");
31
- const accountPolicies = await openfort.policies.list({
32
- scope: "account",
33
- });
34
- console.log(` Found: ${accountPolicies.total}`);
@@ -1,133 +0,0 @@
1
- // Usage: npx tsx policies/multiRulePolicy.ts
2
- //
3
- // Creates a comprehensive policy with multiple rules covering different
4
- // operations (EVM + Solana) in a single policy.
5
-
6
- import Openfort, {
7
- CreatePolicyBodySchema,
8
- type CreatePolicyBody,
9
- } from "@openfort/openfort-node";
10
- import "dotenv/config";
11
-
12
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
13
- basePath: process.env.OPENFORT_BASE_URL,
14
- });
15
-
16
- const body: CreatePolicyBody = {
17
- scope: "project",
18
- description: "Comprehensive cross-chain policy",
19
- priority: 100,
20
- rules: [
21
- // Rule 1: Accept EVM transactions under 1 ETH to known addresses
22
- {
23
- action: "accept",
24
- operation: "signEvmTransaction",
25
- criteria: [
26
- {
27
- type: "ethValue",
28
- operator: "<=",
29
- ethValue: "1000000000000000000",
30
- },
31
- {
32
- type: "evmAddress",
33
- operator: "in",
34
- addresses: ["0x000000000000000000000000000000000000dEaD"],
35
- },
36
- ],
37
- },
38
-
39
- // Rule 2: Accept EVM sends on specific networks
40
- {
41
- action: "accept",
42
- operation: "sendEvmTransaction",
43
- criteria: [
44
- {
45
- type: "evmNetwork",
46
- operator: "in",
47
- chainIds: [1, 137, 8453], // Ethereum, Polygon, Base
48
- },
49
- {
50
- type: "ethValue",
51
- operator: "<=",
52
- ethValue: "500000000000000000",
53
- },
54
- ],
55
- },
56
-
57
- // Rule 3: Accept EVM message signing matching login pattern
58
- {
59
- action: "accept",
60
- operation: "signEvmMessage",
61
- criteria: [
62
- {
63
- type: "evmMessage",
64
- operator: "match",
65
- pattern: "^Sign in to",
66
- },
67
- ],
68
- },
69
-
70
- // Rule 4: Reject all raw hash signing
71
- {
72
- action: "reject",
73
- operation: "signEvmHash",
74
- },
75
-
76
- // Rule 5: Accept SOL transfers under 5 SOL to known addresses
77
- {
78
- action: "accept",
79
- operation: "signSolTransaction",
80
- criteria: [
81
- {
82
- type: "solValue",
83
- operator: "<=",
84
- value: "5000000000", // 5 SOL
85
- },
86
- {
87
- type: "solAddress",
88
- operator: "in",
89
- addresses: ["DtdSSG8ZJRZVv5Jx7K1MeWp7Zxcu19GD5wQRGRpQ9uMF"],
90
- },
91
- ],
92
- },
93
-
94
- // Rule 6: Accept Solana sends on mainnet only
95
- {
96
- action: "accept",
97
- operation: "sendSolTransaction",
98
- criteria: [
99
- {
100
- type: "solNetwork",
101
- operator: "in",
102
- networks: ["mainnet-beta"],
103
- },
104
- ],
105
- },
106
-
107
- // Rule 7: Accept SOL message signing with known prefix
108
- {
109
- action: "accept",
110
- operation: "signSolMessage",
111
- criteria: [
112
- {
113
- type: "solMessage",
114
- operator: "match",
115
- pattern: "^Verify ownership:",
116
- },
117
- ],
118
- },
119
- ],
120
- };
121
-
122
- // Validate locally before sending
123
- CreatePolicyBodySchema.parse(body);
124
-
125
- const policy = await openfort.policies.create(body);
126
-
127
- console.log("Created multi-rule policy:");
128
- console.log(" ID:", policy.id);
129
- console.log(" Priority:", policy.priority);
130
- console.log(" Rules:", policy.rules.length);
131
- for (const rule of policy.rules) {
132
- console.log(` - ${rule.action} ${rule.operation}`);
133
- }
@@ -1,77 +0,0 @@
1
- // Usage: npx tsx policies/updatePolicy.ts
2
-
3
- import Openfort, {
4
- CreatePolicyBodySchema,
5
- UpdatePolicyBodySchema,
6
- type CreatePolicyBody,
7
- type UpdatePolicyBody,
8
- } from "@openfort/openfort-node";
9
- import "dotenv/config";
10
-
11
- const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
12
- basePath: process.env.OPENFORT_BASE_URL,
13
- });
14
-
15
- // Create a policy first
16
- const createBody: CreatePolicyBody = {
17
- scope: "project",
18
- description: "Original policy — reject high-value transactions",
19
- rules: [
20
- {
21
- action: "reject",
22
- operation: "signEvmTransaction",
23
- criteria: [
24
- {
25
- type: "ethValue",
26
- operator: ">",
27
- ethValue: "1000000000000000000", // 1 ETH
28
- },
29
- ],
30
- },
31
- ],
32
- };
33
- CreatePolicyBodySchema.parse(createBody);
34
-
35
- const policy = await openfort.policies.create(createBody);
36
- console.log("Created policy:", policy.id);
37
- console.log(" Description:", policy.description);
38
-
39
- // ---------------------------------------------------------------------------
40
- // Update the policy — lower the threshold and add an address denylist
41
- // ---------------------------------------------------------------------------
42
-
43
- const updateBody: UpdatePolicyBody = {
44
- description: "Updated — reject high-value or denylist transactions",
45
- rules: [
46
- {
47
- action: "reject",
48
- operation: "signEvmTransaction",
49
- criteria: [
50
- {
51
- type: "ethValue",
52
- operator: ">",
53
- ethValue: "500000000000000000", // 0.5 ETH (lowered)
54
- },
55
- ],
56
- },
57
- {
58
- action: "reject",
59
- operation: "sendEvmTransaction",
60
- criteria: [
61
- {
62
- type: "evmAddress",
63
- operator: "in",
64
- addresses: ["0x000000000000000000000000000000000000dEaD"],
65
- },
66
- ],
67
- },
68
- ],
69
- };
70
- UpdatePolicyBodySchema.parse(updateBody);
71
-
72
- const updated = await openfort.policies.update(policy.id, updateBody);
73
-
74
- console.log("\nUpdated policy:");
75
- console.log(" ID:", updated.id);
76
- console.log(" Description:", updated.description);
77
- console.log(" Rules:", updated.rules.length);