@openfort/openfort-node 0.7.7 → 0.8.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 (32) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/biome.json +2 -1
  3. package/dist/index.d.mts +4835 -437
  4. package/dist/index.d.ts +4835 -437
  5. package/dist/index.js +920 -121
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +802 -114
  8. package/dist/index.mjs.map +1 -1
  9. package/examples/README.md +28 -11
  10. package/examples/{policies → fee-sponsorship}/createPolicy.ts +2 -2
  11. package/examples/{policies → fee-sponsorship}/createPolicyRule.ts +3 -3
  12. package/examples/{policies → fee-sponsorship}/disableEnablePolicy.ts +4 -4
  13. package/examples/fee-sponsorship/getPolicy.ts +30 -0
  14. package/examples/fee-sponsorship/listPolicies.ts +17 -0
  15. package/examples/{policies → fee-sponsorship}/listPolicyRules.ts +4 -4
  16. package/examples/fee-sponsorship/updatePolicy.ts +29 -0
  17. package/examples/policies/createAccountPolicy.ts +73 -0
  18. package/examples/policies/createEvmPolicy.ts +149 -0
  19. package/examples/policies/createSolanaPolicy.ts +176 -0
  20. package/examples/policies/createTypedDataPolicy.ts +159 -0
  21. package/examples/policies/deletePolicy.ts +34 -0
  22. package/examples/policies/getPolicy.ts +24 -13
  23. package/examples/policies/listPolicies.ts +19 -2
  24. package/examples/policies/multiRulePolicy.ts +133 -0
  25. package/examples/policies/updatePolicy.ts +64 -16
  26. package/examples/policies/validatePolicy.ts +176 -0
  27. package/examples/transactions/createTransactionIntent.ts +2 -2
  28. package/examples/transactions/estimateGas.ts +2 -2
  29. package/examples/transactions/getTransactionIntent.ts +2 -2
  30. package/openapi.json +2352 -1142
  31. package/package.json +4 -3
  32. package/pnpm-workspace.yaml +1 -0
@@ -101,17 +101,34 @@ pnpm example evm/accounts/createAccount.ts
101
101
  | `signTransaction.ts` | Sign a Solana transaction |
102
102
 
103
103
 
104
- ### Policies
105
-
106
- | Example | Description |
107
- | --------------------------------- | ------------------------------- |
108
- | `policies/createPolicy.ts` | Create a gas sponsorship policy |
109
- | `policies/getPolicy.ts` | Get a policy by ID |
110
- | `policies/listPolicies.ts` | List all policies |
111
- | `policies/updatePolicy.ts` | Update a policy |
112
- | `policies/disableEnablePolicy.ts` | Enable/disable a policy |
113
- | `policies/createPolicyRule.ts` | Create a policy rule |
114
- | `policies/listPolicyRules.ts` | List policy rules |
104
+ ### Policies (`policies/`)
105
+
106
+ Policies provide fine-grained control over signing operations using Zod-validated rules with type-safe criteria.
107
+
108
+ | Example | Description |
109
+ | --------------------------- | ------------------------------------------------------ |
110
+ | `createEvmPolicy.ts` | EVM policies: value caps, address allowlists, ABI data |
111
+ | `createSolanaPolicy.ts` | Solana policies: SOL/SPL limits, program IDs, messages |
112
+ | `createTypedDataPolicy.ts` | EIP-712 typed-data and message signing policies |
113
+ | `createAccountPolicy.ts` | Account-scoped policy (vs project-scoped) |
114
+ | `multiRulePolicy.ts` | Multi-rule policy covering EVM + Solana operations |
115
+ | `listPolicies.ts` | List policies with scope filtering |
116
+ | `getPolicy.ts` | Retrieve a policy by ID |
117
+ | `updatePolicy.ts` | Update a policy's rules and description |
118
+ | `deletePolicy.ts` | Delete a policy |
119
+ | `validatePolicy.ts` | Client-side Zod validation without API calls |
120
+
121
+ ### Fee Sponsorship (`fee-sponsorship/`)
122
+
123
+ | Example | Description |
124
+ | ---------------------------------------- | ------------------------------- |
125
+ | `fee-sponsorship/createPolicy.ts` | Create a gas sponsorship policy |
126
+ | `fee-sponsorship/getPolicy.ts` | Get a policy by ID |
127
+ | `fee-sponsorship/listPolicies.ts` | List all policies |
128
+ | `fee-sponsorship/updatePolicy.ts` | Update a policy |
129
+ | `fee-sponsorship/disableEnablePolicy.ts` | Enable/disable a policy |
130
+ | `fee-sponsorship/createPolicyRule.ts` | Create a policy rule |
131
+ | `fee-sponsorship/listPolicyRules.ts` | List policy rules |
115
132
 
116
133
  ### Contracts
117
134
 
@@ -1,4 +1,4 @@
1
- // Usage: npx tsx policies/createPolicy.ts
1
+ // Usage: npx tsx fee-sponsorship/createPolicy.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
4
  import "dotenv/config";
@@ -10,7 +10,7 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
10
  const chainId = Number(process.env.CHAIN_ID) || 80002;
11
11
 
12
12
  // Create a gas sponsorship policy
13
- const policy = await openfort.policies.create({
13
+ const policy = await openfort.feeSponsorship.create({
14
14
  name: "Gas Sponsorship Policy",
15
15
  chainId,
16
16
  strategy: {
@@ -1,4 +1,4 @@
1
- // Usage: npx tsx policies/createPolicyRule.ts
1
+ // Usage: npx tsx fee-sponsorship/createPolicyRule.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
4
  import "dotenv/config";
@@ -10,7 +10,7 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
10
  const chainId = Number(process.env.CHAIN_ID) || 80002;
11
11
 
12
12
  // Create a policy first
13
- const policy = await openfort.policies.create({
13
+ const policy = await openfort.feeSponsorship.create({
14
14
  name: `PolicyWithRules-${Date.now()}`,
15
15
  chainId,
16
16
  strategy: {
@@ -28,7 +28,7 @@ const contract = await openfort.contracts.create({
28
28
  console.log("Created contract:", contract.id);
29
29
 
30
30
  // Create a policy rule for account functions
31
- const rule = await openfort.policyRules.create({
31
+ const rule = await openfort.feeSponsorship.rules.create({
32
32
  type: "account_functions",
33
33
  policy: policy.id,
34
34
  functionName: "transfer",
@@ -1,4 +1,4 @@
1
- // Usage: npx tsx policies/disableEnablePolicy.ts
1
+ // Usage: npx tsx fee-sponsorship/disableEnablePolicy.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
4
  import "dotenv/config";
@@ -10,7 +10,7 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
10
  const chainId = Number(process.env.CHAIN_ID) || 80002;
11
11
 
12
12
  // Create a policy first
13
- const policy = await openfort.policies.create({
13
+ const policy = await openfort.feeSponsorship.create({
14
14
  name: `TogglePolicy-${Date.now()}`,
15
15
  chainId,
16
16
  strategy: {
@@ -21,9 +21,9 @@ console.log("Created policy:", policy.id);
21
21
  console.log("Initial state - Enabled:", policy.enabled);
22
22
 
23
23
  // Disable the policy
24
- const disabled = await openfort.policies.disable(policy.id);
24
+ const disabled = await openfort.feeSponsorship.disable(policy.id);
25
25
  console.log("\nAfter disable - Enabled:", disabled.enabled);
26
26
 
27
27
  // Enable the policy again
28
- const enabled = await openfort.policies.enable(policy.id);
28
+ const enabled = await openfort.feeSponsorship.enable(policy.id);
29
29
  console.log("After enable - Enabled:", enabled.enabled);
@@ -0,0 +1,30 @@
1
+ // Usage: npx tsx fee-sponsorship/getPolicy.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
+ const chainId = Number(process.env.CHAIN_ID) || 80002;
11
+
12
+ // Create a policy first
13
+ const created = await openfort.feeSponsorship.create({
14
+ name: `TestPolicy-${Date.now()}`,
15
+ chainId,
16
+ strategy: {
17
+ sponsorSchema: "pay_for_user",
18
+ },
19
+ });
20
+ console.log("Created policy:", created.id);
21
+
22
+ // Retrieve the policy by ID
23
+ const policy = await openfort.feeSponsorship.get(created.id);
24
+
25
+ console.log("\nRetrieved policy:");
26
+ console.log(" ID:", policy.id);
27
+ console.log(" Name:", policy.name);
28
+ console.log(" Chain ID:", policy.chainId);
29
+ console.log(" Strategy:", policy.strategy.sponsorSchema);
30
+ console.log(" Enabled:", policy.enabled);
@@ -0,0 +1,17 @@
1
+ // Usage: npx tsx fee-sponsorship/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.feeSponsorship.list({ limit: 10 });
12
+
13
+ console.log(`Found ${result.total} policies:`);
14
+ for (const policy of result.data) {
15
+ console.log(` - ${policy.name} (${policy.id})`);
16
+ console.log(` Chain: ${policy.chainId}, Strategy: ${policy.strategy.sponsorSchema}`);
17
+ }
@@ -1,4 +1,4 @@
1
- // Usage: npx tsx policies/listPolicyRules.ts
1
+ // Usage: npx tsx fee-sponsorship/listPolicyRules.ts
2
2
 
3
3
  import Openfort from "@openfort/openfort-node";
4
4
  import "dotenv/config";
@@ -10,7 +10,7 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
10
10
  const chainId = Number(process.env.CHAIN_ID) || 80002;
11
11
 
12
12
  // Create a policy with rules
13
- const policy = await openfort.policies.create({
13
+ const policy = await openfort.feeSponsorship.create({
14
14
  name: `PolicyWithRules-${Date.now()}`,
15
15
  chainId,
16
16
  strategy: {
@@ -19,13 +19,13 @@ const policy = await openfort.policies.create({
19
19
  });
20
20
 
21
21
  // Add some rules
22
- await openfort.policyRules.create({
22
+ await openfort.feeSponsorship.rules.create({
23
23
  type: "account_functions",
24
24
  policy: policy.id,
25
25
  });
26
26
 
27
27
  // List rules for this policy
28
- const result = await openfort.policyRules.list({ policy: policy.id });
28
+ const result = await openfort.feeSponsorship.rules.list({ policy: policy.id });
29
29
 
30
30
  console.log(`Found ${result.total} rules for policy ${policy.id}:`);
31
31
  for (const rule of result.data) {
@@ -0,0 +1,29 @@
1
+ // Usage: npx tsx fee-sponsorship/updatePolicy.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
+ const chainId = Number(process.env.CHAIN_ID) || 80002;
11
+
12
+ // Create a policy first
13
+ const policy = await openfort.feeSponsorship.create({
14
+ name: "Original Policy Name",
15
+ chainId,
16
+ strategy: {
17
+ sponsorSchema: "pay_for_user",
18
+ },
19
+ });
20
+ console.log("Created policy:", policy.name);
21
+
22
+ // Update the policy
23
+ const updated = await openfort.feeSponsorship.update(policy.id, {
24
+ name: "Updated Policy Name",
25
+ });
26
+
27
+ console.log("\nUpdated policy:");
28
+ console.log(" ID:", updated.id);
29
+ console.log(" Name:", updated.name);
@@ -0,0 +1,73 @@
1
+ // Usage: npx tsx policies/createAccountPolicy.ts
2
+ //
3
+ // Creates an account-scoped policy (as opposed to project-scoped).
4
+ // Account policies apply only to a specific wallet account.
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
+ walletSecret: process.env.OPENFORT_WALLET_SECRET,
15
+ });
16
+
17
+ // Create an EVM backend wallet to attach the policy to
18
+ const account = await openfort.accounts.evm.backend.create({
19
+ name: `PolicyAccount-${Date.now()}`,
20
+ });
21
+ console.log("Created account:", account.id);
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Create an account-scoped policy
25
+ // ---------------------------------------------------------------------------
26
+
27
+ const body: CreatePolicyBody = {
28
+ scope: "account",
29
+ accountId: account.id,
30
+ description: "Account-level allowlist for this specific wallet",
31
+ enabled: true,
32
+ priority: 10,
33
+ rules: [
34
+ {
35
+ action: "accept",
36
+ operation: "signEvmTransaction",
37
+ criteria: [
38
+ {
39
+ type: "evmAddress",
40
+ operator: "in",
41
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
42
+ },
43
+ {
44
+ type: "ethValue",
45
+ operator: "<=",
46
+ ethValue: "500000000000000000", // 0.5 ETH
47
+ },
48
+ ],
49
+ },
50
+ {
51
+ action: "accept",
52
+ operation: "signEvmMessage",
53
+ criteria: [
54
+ {
55
+ type: "evmMessage",
56
+ operator: "match",
57
+ pattern: "^Sign in to",
58
+ },
59
+ ],
60
+ },
61
+ ],
62
+ };
63
+
64
+ CreatePolicyBodySchema.parse(body);
65
+
66
+ const policy = await openfort.policies.create(body);
67
+
68
+ console.log("\nCreated account-scoped policy:");
69
+ console.log(" ID:", policy.id);
70
+ console.log(" Scope:", policy.scope);
71
+ console.log(" Account:", policy.accountId);
72
+ console.log(" Priority:", policy.priority);
73
+ console.log(" Rules:", policy.rules.length);
@@ -0,0 +1,149 @@
1
+ // Usage: npx tsx policies/createEvmPolicy.ts
2
+ //
3
+ // Creates policies that control EVM signing operations.
4
+ // Demonstrates: ethValue limits, address allowlists, network restrictions,
5
+ // and combined criteria.
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 EVM transactions (> 1 ETH)
19
+ // ---------------------------------------------------------------------------
20
+
21
+ const highValueBody: CreatePolicyBody = {
22
+ scope: "project",
23
+ description: "Reject transactions above 1 ETH",
24
+ rules: [
25
+ {
26
+ action: "reject",
27
+ operation: "signEvmTransaction",
28
+ criteria: [
29
+ {
30
+ type: "ethValue",
31
+ operator: ">",
32
+ ethValue: "1000000000000000000", // 1 ETH in wei
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ };
38
+
39
+ // Validate with Zod before sending
40
+ CreatePolicyBodySchema.parse(highValueBody);
41
+
42
+ const highValuePolicy = await openfort.policies.create(highValueBody);
43
+ console.log("Created high-value rejection policy:");
44
+ console.log(" ID:", highValuePolicy.id);
45
+ console.log(" Scope:", highValuePolicy.scope);
46
+ console.log(" Rules:", highValuePolicy.rules.length);
47
+
48
+ // ---------------------------------------------------------------------------
49
+ // 2. Address allowlist — only allow transactions to known addresses
50
+ // ---------------------------------------------------------------------------
51
+
52
+ const allowlistBody: CreatePolicyBody = {
53
+ scope: "project",
54
+ description: "Only allow transfers to treasury and vault",
55
+ rules: [
56
+ {
57
+ action: "accept",
58
+ operation: "sendEvmTransaction",
59
+ criteria: [
60
+ {
61
+ type: "evmAddress",
62
+ operator: "in",
63
+ addresses: [
64
+ "0x000000000000000000000000000000000000dEaD",
65
+ "0x1234567890abcdef1234567890abcdef12345678",
66
+ ],
67
+ },
68
+ {
69
+ type: "evmNetwork",
70
+ operator: "in",
71
+ chainIds: [1, 137, 8453], // Ethereum, Polygon, Base
72
+ },
73
+ ],
74
+ },
75
+ ],
76
+ };
77
+
78
+ CreatePolicyBodySchema.parse(allowlistBody);
79
+
80
+ const allowlistPolicy = await openfort.policies.create(allowlistBody);
81
+ console.log("\nCreated address allowlist policy:");
82
+ console.log(" ID:", allowlistPolicy.id);
83
+
84
+ // ---------------------------------------------------------------------------
85
+ // 3. Restrict EVM contract calls by ABI function
86
+ // ---------------------------------------------------------------------------
87
+
88
+ const dataBody: CreatePolicyBody = {
89
+ scope: "project",
90
+ description: "Only allow ERC-20 transfer calls",
91
+ rules: [
92
+ {
93
+ action: "accept",
94
+ operation: "signEvmTransaction",
95
+ criteria: [
96
+ {
97
+ type: "evmData",
98
+ operator: "==",
99
+ abi: '[{"type":"function","name":"transfer","inputs":[{"name":"to","type":"address"},{"name":"amount","type":"uint256"}],"outputs":[{"type":"bool"}]}]',
100
+ functionName: "transfer",
101
+ },
102
+ ],
103
+ },
104
+ ],
105
+ };
106
+
107
+ CreatePolicyBodySchema.parse(dataBody);
108
+
109
+ const dataPolicy = await openfort.policies.create(dataBody);
110
+ console.log("\nCreated ERC-20 transfer-only policy:");
111
+ console.log(" ID:", dataPolicy.id);
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // 4. Combined: value cap + address allowlist + network restriction
115
+ // ---------------------------------------------------------------------------
116
+
117
+ const combinedBody: CreatePolicyBody = {
118
+ scope: "project",
119
+ description: "Accept low-value sends to known addresses on mainnet only",
120
+ rules: [
121
+ {
122
+ action: "accept",
123
+ operation: "sendEvmTransaction",
124
+ criteria: [
125
+ {
126
+ type: "ethValue",
127
+ operator: "<=",
128
+ ethValue: "500000000000000000", // 0.5 ETH
129
+ },
130
+ {
131
+ type: "evmAddress",
132
+ operator: "in",
133
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
134
+ },
135
+ {
136
+ type: "evmNetwork",
137
+ operator: "in",
138
+ chainIds: [1], // Ethereum mainnet only
139
+ },
140
+ ],
141
+ },
142
+ ],
143
+ };
144
+
145
+ CreatePolicyBodySchema.parse(combinedBody);
146
+
147
+ const combinedPolicy = await openfort.policies.create(combinedBody);
148
+ console.log("\nCreated combined EVM policy:");
149
+ console.log(" ID:", combinedPolicy.id);
@@ -0,0 +1,176 @@
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);