@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
@@ -0,0 +1,68 @@
1
+ // Usage: pnpm tsx evm/policies/createAccountPolicy.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 policy = await openfort.policies.create({
11
+ scope: "account",
12
+ description: "Account Allowlist Example",
13
+ rules: [
14
+ {
15
+ action: "accept",
16
+ operation: "signEvmTransaction",
17
+ criteria: [
18
+ {
19
+ type: "ethValue",
20
+ ethValue: "1000000000000000000",
21
+ operator: "<=",
22
+ },
23
+ {
24
+ type: "evmAddress",
25
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
26
+ operator: "in",
27
+ },
28
+ ],
29
+ },
30
+ {
31
+ action: "accept",
32
+ operation: "sendEvmTransaction",
33
+ criteria: [
34
+ {
35
+ type: "ethValue",
36
+ ethValue: "1000000000000000000",
37
+ operator: "<=",
38
+ },
39
+ {
40
+ type: "evmAddress",
41
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
42
+ operator: "in",
43
+ },
44
+ {
45
+ type: "evmNetwork",
46
+ chainIds: [8453],
47
+ operator: "in",
48
+ },
49
+ ],
50
+ },
51
+ {
52
+ action: "accept",
53
+ operation: "signEvmHash",
54
+ },
55
+ {
56
+ action: "accept",
57
+ operation: "signEvmMessage",
58
+ criteria: [
59
+ {
60
+ type: "evmMessage",
61
+ operator: "match",
62
+ pattern: ".*",
63
+ },
64
+ ],
65
+ },
66
+ ],
67
+ });
68
+ console.log("Created account policy: ", policy.id);
@@ -0,0 +1,53 @@
1
+ // Usage: pnpm tsx evm/policies/createProjectPolicy.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 policy = await openfort.policies.create({
11
+ scope: "project",
12
+ description: "Project Allowlist Example",
13
+ rules: [
14
+ {
15
+ action: "accept",
16
+ operation: "signEvmTransaction",
17
+ criteria: [
18
+ {
19
+ type: "ethValue",
20
+ ethValue: "1000000000000000000",
21
+ operator: "<=",
22
+ },
23
+ {
24
+ type: "evmAddress",
25
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
26
+ operator: "in",
27
+ },
28
+ ],
29
+ },
30
+ {
31
+ action: "accept",
32
+ operation: "sendEvmTransaction",
33
+ criteria: [
34
+ {
35
+ type: "ethValue",
36
+ ethValue: "1000000000000000000",
37
+ operator: "<=",
38
+ },
39
+ {
40
+ type: "evmAddress",
41
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
42
+ operator: "in",
43
+ },
44
+ {
45
+ type: "evmNetwork",
46
+ chainIds: [8453],
47
+ operator: "in",
48
+ },
49
+ ],
50
+ },
51
+ ],
52
+ });
53
+ console.log("Created project policy: ", policy.id);
@@ -0,0 +1,34 @@
1
+ // Usage: pnpm tsx evm/policies/deletePolicy.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 policy = await openfort.policies.create({
11
+ scope: "account",
12
+ description: "Temporary Policy",
13
+ rules: [
14
+ {
15
+ action: "accept",
16
+ operation: "signEvmTransaction",
17
+ criteria: [
18
+ {
19
+ type: "ethValue",
20
+ ethValue: "1000000000000000000",
21
+ operator: "<=",
22
+ },
23
+ {
24
+ type: "evmAddress",
25
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
26
+ operator: "in",
27
+ },
28
+ ],
29
+ },
30
+ ],
31
+ });
32
+
33
+ await openfort.policies.delete(policy.id);
34
+ console.log("Deleted policy: ", policy.id);
@@ -0,0 +1,34 @@
1
+ // Usage: pnpm tsx evm/policies/getPolicyById.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 policy = await openfort.policies.create({
11
+ scope: "account",
12
+ description: "Account Policy",
13
+ rules: [
14
+ {
15
+ action: "accept",
16
+ operation: "signEvmTransaction",
17
+ criteria: [
18
+ {
19
+ type: "ethValue",
20
+ ethValue: "1000000000000000000",
21
+ operator: "<=",
22
+ },
23
+ {
24
+ type: "evmAddress",
25
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
26
+ operator: "in",
27
+ },
28
+ ],
29
+ },
30
+ ],
31
+ });
32
+
33
+ const retrievedPolicy = await openfort.policies.get(policy.id);
34
+ console.log("Retrieved policy: ", JSON.stringify(retrievedPolicy, null, 2));
@@ -0,0 +1,11 @@
1
+ // Usage: pnpm tsx evm/policies/listAccountPolicies.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 policies = await openfort.policies.list({ scope: ["account"] });
11
+ console.log("Listed account policies: ", JSON.stringify(policies, null, 2));
@@ -0,0 +1,11 @@
1
+ // Usage: pnpm tsx evm/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
+ const policies = await openfort.policies.list();
11
+ console.log("Listed policies: ", JSON.stringify(policies, null, 2));
@@ -0,0 +1,11 @@
1
+ // Usage: pnpm tsx evm/policies/listProjectPolicies.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 policies = await openfort.policies.list({ scope: ["project"] });
11
+ console.log("Listed project policies: ", JSON.stringify(policies, null, 2));
@@ -0,0 +1,35 @@
1
+ // Usage: pnpm tsx evm/policies/signTypedDataPolicy.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
+ // Create a policy that restricts EIP-712 Permit signatures to a max value of 1000 tokens
11
+ const permitPolicy = await openfort.policies.create({
12
+ scope: "account",
13
+ description: "Restrict Permit signatures to max 1000 tokens",
14
+ rules: [
15
+ {
16
+ action: "accept",
17
+ operation: "signEvmTypedData",
18
+ criteria: [
19
+ {
20
+ type: "evmTypedDataVerifyingContract",
21
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
22
+ operator: "in",
23
+ },
24
+ {
25
+ type: "evmTypedDataField",
26
+ fieldPath: "value",
27
+ operator: "<=",
28
+ value: "1000000000000000000000", // Max 1000 tokens (assuming 18 decimals)
29
+ },
30
+ ],
31
+ },
32
+ ],
33
+ });
34
+
35
+ console.log("Created permit policy. Policy ID:", permitPolicy.id);
@@ -0,0 +1,44 @@
1
+ // Usage: pnpm tsx evm/policies/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 policy = await openfort.policies.create({
11
+ scope: "account",
12
+ description: "Initial Allowlist Policy",
13
+ rules: [
14
+ {
15
+ action: "accept",
16
+ operation: "signEvmTransaction",
17
+ criteria: [
18
+ {
19
+ type: "evmAddress",
20
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
21
+ operator: "in",
22
+ },
23
+ ],
24
+ },
25
+ ],
26
+ });
27
+
28
+ const updatedPolicy = await openfort.policies.update(policy.id, {
29
+ description: "Updated Denylist Policy",
30
+ rules: [
31
+ {
32
+ action: "accept",
33
+ operation: "signEvmTransaction",
34
+ criteria: [
35
+ {
36
+ type: "evmAddress",
37
+ addresses: ["0x000000000000000000000000000000000000dEaD"],
38
+ operator: "not in",
39
+ },
40
+ ],
41
+ },
42
+ ],
43
+ });
44
+ console.log("Updated policy: ", JSON.stringify(updatedPolicy, null, 2));
@@ -0,0 +1,45 @@
1
+ // Usage: pnpm tsx evm/policies/validation.ts
2
+
3
+ import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "@openfort/openfort-node";
4
+
5
+ const invalidPolicy = {
6
+ description: 'Bad description with !#@ characters, also is wayyyyy toooooo long!!',
7
+ rules: [
8
+ {
9
+ action: 'accept',
10
+ operation: 'signEvmTransaction',
11
+ criteria: [
12
+ {
13
+ type: 'ethValue',
14
+ ethValue: 'not a number',
15
+ operator: '<='
16
+ },
17
+ {
18
+ type: 'evmAddress',
19
+ addresses: ["not an address"],
20
+ operator: 'in'
21
+ },
22
+ {
23
+ type: 'evmAddress',
24
+ addresses: ["not an address"],
25
+ operator: 'invalid operator'
26
+ }
27
+ ]
28
+ },
29
+ {
30
+ action: 'accept',
31
+ operation: 'unknownOperation',
32
+ criteria: []
33
+ },
34
+ {
35
+ action: 'accept',
36
+ operation: 'signEvmTransaction',
37
+ criteria: []
38
+ }
39
+ ]
40
+ }
41
+
42
+ // Validate a new Policy with several issues, will throw a ZodError with actionable validation errors
43
+ CreatePolicyBodySchema.parse(invalidPolicy)
44
+ // OR
45
+ UpdatePolicyBodySchema.parse(invalidPolicy)
@@ -0,0 +1,44 @@
1
+ // Usage: pnpm tsx evm/transactions/sendTransaction.ts
2
+
3
+ import 'dotenv/config'
4
+ import Openfort from '@openfort/openfort-node'
5
+
6
+ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
7
+ walletSecret: process.env.OPENFORT_WALLET_SECRET!,
8
+ })
9
+
10
+
11
+ // 1. Create an EVM backend account
12
+ const account = await openfort.accounts.evm.backend.create()
13
+ // const signedAuthorization = await account.sign({ hash: authHash })
14
+
15
+ const interactions = [
16
+ { to: '0x0000000000000000000000000000000000000000', value: '0', data: '0x' },
17
+ ]
18
+
19
+ console.log("=== Full delegation + signing flow via sendTransaction() ===")
20
+
21
+ // 2. First call: account is new -> delegates via EIP-7702, then sends the transaction
22
+ const result = await openfort.accounts.evm.backend.sendTransaction({
23
+ account: account,
24
+ chainId: 84532, // Base Sepolia
25
+ interactions,
26
+ // To send the transaction without native token in the wallet, use a fee sponsor.
27
+ // https://www.openfort.io/docs/configuration/gas-sponsorship
28
+ // policy: pol_...,
29
+ });
30
+
31
+ console.log("First tx", result.response?.transactionHash)
32
+
33
+ // 3. Second call: account is already delegated -> skips delegation, sends directly
34
+ const result2 = await openfort.accounts.evm.backend.sendTransaction({
35
+ account: account,
36
+ chainId: 84532,
37
+ interactions,
38
+ // To send the transaction without native token in the wallet, use a fee sponsor.
39
+ // https://www.openfort.io/docs/configuration/gas-sponsorship
40
+ // policy: pol_...,
41
+ })
42
+ console.log("Second tx", result2.response?.transactionHash)
43
+
44
+
@@ -23,9 +23,22 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@openfort/openfort-node": "link:..",
26
+ "@solana-program/compute-budget": "^0.14.0",
27
+ "@solana-program/memo": "^0.11.0",
28
+ "@solana-program/system": "^0.12.0",
29
+ "@solana-program/token": "^0.12.0",
30
+ "@solana/kit": "^6.1.0",
31
+ "@solana/kora": "^0.1.3",
32
+ "@solana/transaction-confirmation": "^6.1.0",
26
33
  "@types/express": "^4.17.17",
27
34
  "dotenv": "^16.3.1",
28
35
  "express": "^4.19.2",
29
36
  "viem": "^2.21.0"
37
+ },
38
+ "pnpm": {
39
+ "overrides": {
40
+ "@solana/kora>@solana/kit": "$@solana/kit",
41
+ "@solana/kora>@solana-program/token": "$@solana-program/token"
42
+ }
30
43
  }
31
44
  }