@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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +274 -84
- package/dist/index.d.ts +274 -84
- package/dist/index.js +423 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +423 -45
- package/dist/index.mjs.map +1 -1
- 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/package.json +42 -4
- package/tsconfig.json +2 -3
- 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
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
// Usage: npx tsx policies/validatePolicy.ts
|
|
2
|
-
//
|
|
3
|
-
// Demonstrates client-side validation of policy bodies using the exported
|
|
4
|
-
// Zod schemas. This catches invalid payloads before they reach the API —
|
|
5
|
-
// no network request required.
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
CreatePolicyBodySchema,
|
|
9
|
-
UpdatePolicyBodySchema,
|
|
10
|
-
type CreatePolicyBody,
|
|
11
|
-
} from "@openfort/openfort-node";
|
|
12
|
-
import { ZodError } from "zod";
|
|
13
|
-
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// 1. Valid policy — validation passes
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
const validBody: CreatePolicyBody = {
|
|
19
|
-
scope: "project",
|
|
20
|
-
description: "Reject high-value transactions",
|
|
21
|
-
rules: [
|
|
22
|
-
{
|
|
23
|
-
action: "reject",
|
|
24
|
-
operation: "signEvmTransaction",
|
|
25
|
-
criteria: [
|
|
26
|
-
{
|
|
27
|
-
type: "ethValue",
|
|
28
|
-
operator: ">",
|
|
29
|
-
ethValue: "1000000000000000000",
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const parsed = CreatePolicyBodySchema.parse(validBody);
|
|
37
|
-
console.log("Valid policy parsed successfully!");
|
|
38
|
-
console.log(" Scope:", parsed.scope);
|
|
39
|
-
console.log(" Rules:", parsed.rules.length);
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// 2. Invalid criterion type — validation fails
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
console.log("\n--- Invalid criterion type ---");
|
|
46
|
-
try {
|
|
47
|
-
CreatePolicyBodySchema.parse({
|
|
48
|
-
scope: "project",
|
|
49
|
-
rules: [
|
|
50
|
-
{
|
|
51
|
-
action: "reject",
|
|
52
|
-
operation: "signEvmTransaction",
|
|
53
|
-
criteria: [
|
|
54
|
-
{
|
|
55
|
-
type: "INVALID_TYPE", // not a valid criterion
|
|
56
|
-
operator: ">",
|
|
57
|
-
ethValue: "100",
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
} catch (e) {
|
|
64
|
-
if (e instanceof ZodError) {
|
|
65
|
-
console.log("Caught ZodError:", e.issues[0].message);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
// 3. Invalid EVM address format — validation fails
|
|
71
|
-
// ---------------------------------------------------------------------------
|
|
72
|
-
|
|
73
|
-
console.log("\n--- Invalid EVM address ---");
|
|
74
|
-
try {
|
|
75
|
-
CreatePolicyBodySchema.parse({
|
|
76
|
-
scope: "project",
|
|
77
|
-
rules: [
|
|
78
|
-
{
|
|
79
|
-
action: "accept",
|
|
80
|
-
operation: "sendEvmTransaction",
|
|
81
|
-
criteria: [
|
|
82
|
-
{
|
|
83
|
-
type: "evmAddress",
|
|
84
|
-
operator: "in",
|
|
85
|
-
addresses: ["not-a-hex-address"], // bad format
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
});
|
|
91
|
-
} catch (e) {
|
|
92
|
-
if (e instanceof ZodError) {
|
|
93
|
-
console.log("Caught ZodError:", e.issues[0].message);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
// 4. Wrong criterion for operation — validation fails
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
console.log("\n--- Wrong criterion for operation ---");
|
|
102
|
-
try {
|
|
103
|
-
CreatePolicyBodySchema.parse({
|
|
104
|
-
scope: "project",
|
|
105
|
-
rules: [
|
|
106
|
-
{
|
|
107
|
-
action: "accept",
|
|
108
|
-
operation: "signEvmMessage",
|
|
109
|
-
criteria: [
|
|
110
|
-
{
|
|
111
|
-
type: "ethValue", // ethValue is not valid for signEvmMessage
|
|
112
|
-
operator: ">",
|
|
113
|
-
ethValue: "100",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
});
|
|
119
|
-
} catch (e) {
|
|
120
|
-
if (e instanceof ZodError) {
|
|
121
|
-
console.log("Caught ZodError:", e.issues[0].message);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// 5. Missing required fields — validation fails
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
|
|
129
|
-
console.log("\n--- Missing scope ---");
|
|
130
|
-
try {
|
|
131
|
-
CreatePolicyBodySchema.parse({
|
|
132
|
-
// scope is missing
|
|
133
|
-
rules: [
|
|
134
|
-
{
|
|
135
|
-
action: "reject",
|
|
136
|
-
operation: "signEvmHash",
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
} catch (e) {
|
|
141
|
-
if (e instanceof ZodError) {
|
|
142
|
-
console.log("Caught ZodError:", e.issues[0].message);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ---------------------------------------------------------------------------
|
|
147
|
-
// 6. Validate update body
|
|
148
|
-
// ---------------------------------------------------------------------------
|
|
149
|
-
|
|
150
|
-
console.log("\n--- Valid update body ---");
|
|
151
|
-
const updateParsed = UpdatePolicyBodySchema.parse({
|
|
152
|
-
description: "Updated description",
|
|
153
|
-
enabled: false,
|
|
154
|
-
});
|
|
155
|
-
console.log("Update body parsed successfully!");
|
|
156
|
-
console.log(" Description:", updateParsed.description);
|
|
157
|
-
console.log(" Enabled:", updateParsed.enabled);
|
|
158
|
-
|
|
159
|
-
// ---------------------------------------------------------------------------
|
|
160
|
-
// 7. Too many rules — validation fails
|
|
161
|
-
// ---------------------------------------------------------------------------
|
|
162
|
-
|
|
163
|
-
console.log("\n--- Too many rules (> 10) ---");
|
|
164
|
-
try {
|
|
165
|
-
CreatePolicyBodySchema.parse({
|
|
166
|
-
scope: "project",
|
|
167
|
-
rules: Array.from({ length: 11 }, () => ({
|
|
168
|
-
action: "reject",
|
|
169
|
-
operation: "signEvmHash",
|
|
170
|
-
})),
|
|
171
|
-
});
|
|
172
|
-
} catch (e) {
|
|
173
|
-
if (e instanceof ZodError) {
|
|
174
|
-
console.log("Caught ZodError:", e.issues[0].message);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|