@openfort/openfort-node 0.9.2 → 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.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +559 -582
- package/dist/index.d.ts +559 -582
- package/dist/index.js +539 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +538 -182
- package/dist/index.mjs.map +1 -1
- package/examples/evm/delegation/sendTransaction.ts +34 -0
- package/examples/evm/policies/createAccountPolicy.ts +68 -0
- package/examples/evm/policies/createProjectPolicy.ts +53 -0
- package/examples/evm/policies/deletePolicy.ts +34 -0
- package/examples/evm/policies/getPolicyById.ts +34 -0
- package/examples/evm/policies/listAccountPolicies.ts +11 -0
- package/examples/evm/policies/listPolicies.ts +11 -0
- package/examples/evm/policies/listProjectPolicies.ts +11 -0
- package/examples/evm/policies/signTypedDataPolicy.ts +35 -0
- package/examples/evm/policies/updatePolicy.ts +44 -0
- package/examples/evm/policies/validation.ts +45 -0
- package/examples/evm/transactions/sendTransaction.ts +44 -0
- package/examples/package.json +13 -0
- package/examples/pnpm-lock.yaml +933 -0
- package/examples/solana/policies/createSolAllowlistPolicy.ts +27 -0
- package/examples/solana/policies/createSolMessagePolicy.ts +29 -0
- package/examples/solana/policies/createSplTokenLimitsPolicy.ts +33 -0
- package/examples/solana/transactions/sendRawTransaction.ts +23 -0
- package/examples/solana/transactions/sendTransaction.ts +37 -0
- package/examples/solana/transactions/transfer.ts +44 -0
- package/knip.json +10 -1
- package/openapi.json +28 -637
- package/package.json +42 -4
- package/tsconfig.json +3 -4
- package/examples/policies/createAccountPolicy.ts +0 -71
- package/examples/policies/createEvmPolicy.ts +0 -149
- package/examples/policies/createSolanaPolicy.ts +0 -176
- package/examples/policies/createTypedDataPolicy.ts +0 -159
- package/examples/policies/deletePolicy.ts +0 -34
- package/examples/policies/getPolicy.ts +0 -41
- package/examples/policies/listPolicies.ts +0 -34
- package/examples/policies/multiRulePolicy.ts +0 -133
- package/examples/policies/updatePolicy.ts +0 -77
- package/examples/policies/validatePolicy.ts +0 -176
- /package/examples/{contracts → evm/contracts}/createContract.ts +0 -0
- /package/examples/{contracts → evm/contracts}/listContracts.ts +0 -0
- /package/examples/{transactions → evm/transactionIntents}/createTransactionIntent.ts +0 -0
- /package/examples/{transactions → evm/transactionIntents}/estimateGas.ts +0 -0
- /package/examples/{transactions → evm/transactionIntents}/getTransactionIntent.ts +0 -0
- /package/examples/{transactions → evm/transactionIntents}/listTransactionIntents.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/openfort-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Openfort Node SDK",
|
|
5
5
|
"author": "Openfort",
|
|
6
6
|
"repository": {
|
|
@@ -40,24 +40,29 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@openfort/shield-js": "^0.1.35",
|
|
43
|
-
"@types/node": "^25.3.2",
|
|
44
|
-
"@types/node-fetch": "^2.6.13",
|
|
45
43
|
"axios": "^1.13.6",
|
|
46
44
|
"axios-retry": "^4.5.0",
|
|
47
45
|
"bs58": "^6.0.0",
|
|
48
46
|
"jose": "^5.10.0",
|
|
49
47
|
"node-fetch": "^2.7.0",
|
|
50
|
-
"viem": "^2.46.3",
|
|
51
48
|
"zod": "^3.25.76"
|
|
52
49
|
},
|
|
53
50
|
"simple-git-hooks": {
|
|
54
51
|
"pre-commit": "pnpm check"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
54
|
+
"@types/node": "^25.3.2",
|
|
55
|
+
"@types/node-fetch": "^2.6.13",
|
|
57
56
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
58
57
|
"@biomejs/biome": "^2.4.4",
|
|
59
58
|
"@changesets/changelog-github": "^0.5.2",
|
|
60
59
|
"@changesets/cli": "^2.29.8",
|
|
60
|
+
"@solana-program/compute-budget": "^0.14.0",
|
|
61
|
+
"@solana-program/system": "^0.12.0",
|
|
62
|
+
"@solana-program/token": "^0.12.0",
|
|
63
|
+
"@solana/kit": "^6.1.0",
|
|
64
|
+
"@solana/kora": "^0.1.3",
|
|
65
|
+
"@solana/transaction-confirmation": "^6.1.0",
|
|
61
66
|
"@vitest/coverage-v8": "^3.2.4",
|
|
62
67
|
"knip": "^5.85.0",
|
|
63
68
|
"orval": "^8.5.1",
|
|
@@ -65,8 +70,41 @@
|
|
|
65
70
|
"simple-git-hooks": "^2.13.1",
|
|
66
71
|
"tsup": "^8.5.1",
|
|
67
72
|
"typescript": "^5.9.3",
|
|
73
|
+
"viem": "^2.46.3",
|
|
68
74
|
"vitest": "^3.2.4"
|
|
69
75
|
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"@solana-program/compute-budget": ">=0.7.0",
|
|
78
|
+
"@solana-program/system": ">=0.7.0",
|
|
79
|
+
"@solana-program/token": ">=0.7.0",
|
|
80
|
+
"@solana/kit": ">=6.0.0",
|
|
81
|
+
"@solana/kora": ">=0.1.0",
|
|
82
|
+
"@solana/transaction-confirmation": ">=6.0.0",
|
|
83
|
+
"viem": ">=2.0.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@solana/kit": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@solana-program/compute-budget": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"@solana-program/system": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@solana-program/token": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@solana/kora": {
|
|
99
|
+
"optional": true
|
|
100
|
+
},
|
|
101
|
+
"@solana/transaction-confirmation": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
104
|
+
"viem": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
107
|
+
},
|
|
70
108
|
"scripts": {
|
|
71
109
|
"prebuild": "node -p \"'export const VERSION = ' + JSON.stringify(require('./package.json').version) + ';\\nexport const PACKAGE = ' + JSON.stringify(require('./package.json').name) + ';'\" > src/version.ts",
|
|
72
110
|
"build": "tsup",
|
package/tsconfig.json
CHANGED
|
@@ -8,22 +8,21 @@
|
|
|
8
8
|
"moduleResolution": "bundler",
|
|
9
9
|
"types": ["node"],
|
|
10
10
|
"target": "es2021",
|
|
11
|
-
"lib": ["
|
|
11
|
+
"lib": ["es2022", "esnext.disposable", "dom"],
|
|
12
12
|
"typeRoots": ["node_modules/@types", "./typings"],
|
|
13
13
|
"downlevelIteration": true,
|
|
14
|
-
"experimentalDecorators": true,
|
|
15
14
|
"declaration": true,
|
|
16
15
|
"strictNullChecks": true,
|
|
17
16
|
"newLine": "LF",
|
|
18
17
|
"noUnusedParameters": false,
|
|
19
18
|
"noUnusedLocals": false,
|
|
20
|
-
"emitDecoratorMetadata": true,
|
|
21
19
|
"noImplicitThis": true,
|
|
22
20
|
"noImplicitReturns": true,
|
|
23
21
|
"noFallthroughCasesInSwitch": true,
|
|
24
22
|
"strictBindCallApply": true,
|
|
25
23
|
"esModuleInterop": true,
|
|
26
|
-
"resolveJsonModule": true
|
|
24
|
+
"resolveJsonModule": true,
|
|
25
|
+
"skipLibCheck": true
|
|
27
26
|
},
|
|
28
27
|
"include": ["src/**/*"],
|
|
29
28
|
"exclude": ["dist", "example"]
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
console.log("Created account:", account.id);
|
|
20
|
-
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Create an account-scoped policy
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
const body: CreatePolicyBody = {
|
|
26
|
-
scope: "account",
|
|
27
|
-
accountId: account.id,
|
|
28
|
-
description: "Account-level allowlist for this specific wallet",
|
|
29
|
-
enabled: true,
|
|
30
|
-
priority: 10,
|
|
31
|
-
rules: [
|
|
32
|
-
{
|
|
33
|
-
action: "accept",
|
|
34
|
-
operation: "signEvmTransaction",
|
|
35
|
-
criteria: [
|
|
36
|
-
{
|
|
37
|
-
type: "evmAddress",
|
|
38
|
-
operator: "in",
|
|
39
|
-
addresses: ["0x000000000000000000000000000000000000dEaD"],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: "ethValue",
|
|
43
|
-
operator: "<=",
|
|
44
|
-
ethValue: "500000000000000000", // 0.5 ETH
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
action: "accept",
|
|
50
|
-
operation: "signEvmMessage",
|
|
51
|
-
criteria: [
|
|
52
|
-
{
|
|
53
|
-
type: "evmMessage",
|
|
54
|
-
operator: "match",
|
|
55
|
-
pattern: "^Sign in to",
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
CreatePolicyBodySchema.parse(body);
|
|
63
|
-
|
|
64
|
-
const policy = await openfort.policies.create(body);
|
|
65
|
-
|
|
66
|
-
console.log("\nCreated account-scoped policy:");
|
|
67
|
-
console.log(" ID:", policy.id);
|
|
68
|
-
console.log(" Scope:", policy.scope);
|
|
69
|
-
console.log(" Account:", policy.accountId);
|
|
70
|
-
console.log(" Priority:", policy.priority);
|
|
71
|
-
console.log(" Rules:", policy.rules.length);
|
|
@@ -1,149 +0,0 @@
|
|
|
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);
|
|
@@ -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);
|