@openfort/openfort-node 0.8.4 → 0.9.1
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/README.md +29 -37
- package/dist/index.d.mts +3293 -1405
- package/dist/index.d.ts +3293 -1405
- package/dist/index.js +536 -273
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +500 -255
- package/dist/index.mjs.map +1 -1
- package/examples/README.md +7 -16
- package/examples/evm/accounts/getAccount.ts +0 -6
- package/examples/evm/embedded/pregenerate.ts +1 -1
- package/examples/fee-sponsorship/createPolicy.ts +24 -8
- package/examples/fee-sponsorship/disableEnablePolicy.ts +22 -9
- package/examples/fee-sponsorship/getPolicy.ts +24 -11
- package/examples/fee-sponsorship/listPolicies.ts +7 -5
- package/examples/fee-sponsorship/updatePolicy.ts +20 -7
- package/examples/iam/getSession.ts +0 -2
- package/examples/transactions/createTransactionIntent.ts +17 -11
- package/examples/transactions/estimateGas.ts +16 -14
- package/examples/transactions/getTransactionIntent.ts +16 -15
- package/openapi.json +1121 -117
- package/package.json +1 -1
- package/examples/fee-sponsorship/createPolicyRule.ts +0 -43
- package/examples/fee-sponsorship/listPolicyRules.ts +0 -37
package/examples/README.md
CHANGED
|
@@ -120,15 +120,13 @@ Policies provide fine-grained control over signing operations using Zod-validate
|
|
|
120
120
|
|
|
121
121
|
### Fee Sponsorship (`fee-sponsorship/`)
|
|
122
122
|
|
|
123
|
-
| Example | Description
|
|
124
|
-
| ---------------------------------------- |
|
|
125
|
-
| `fee-sponsorship/createPolicy.ts` | Create a
|
|
126
|
-
| `fee-sponsorship/getPolicy.ts` | Get a
|
|
127
|
-
| `fee-sponsorship/listPolicies.ts` | List all
|
|
128
|
-
| `fee-sponsorship/updatePolicy.ts` | Update a
|
|
129
|
-
| `fee-sponsorship/disableEnablePolicy.ts` | Enable/disable a
|
|
130
|
-
| `fee-sponsorship/createPolicyRule.ts` | Create a policy rule |
|
|
131
|
-
| `fee-sponsorship/listPolicyRules.ts` | List policy rules |
|
|
123
|
+
| Example | Description |
|
|
124
|
+
| ---------------------------------------- | ----------------------------------------------- |
|
|
125
|
+
| `fee-sponsorship/createPolicy.ts` | Create a policy and fee sponsorship |
|
|
126
|
+
| `fee-sponsorship/getPolicy.ts` | Get a fee sponsorship by ID |
|
|
127
|
+
| `fee-sponsorship/listPolicies.ts` | List all fee sponsorships |
|
|
128
|
+
| `fee-sponsorship/updatePolicy.ts` | Update a fee sponsorship |
|
|
129
|
+
| `fee-sponsorship/disableEnablePolicy.ts` | Enable/disable a fee sponsorship |
|
|
132
130
|
|
|
133
131
|
### Contracts
|
|
134
132
|
|
|
@@ -146,13 +144,6 @@ Policies provide fine-grained control over signing operations using Zod-validate
|
|
|
146
144
|
| `transactions/listTransactionIntents.ts` | List transaction intents |
|
|
147
145
|
| `transactions/estimateGas.ts` | Estimate gas for a transaction |
|
|
148
146
|
|
|
149
|
-
### Exchange / Swaps
|
|
150
|
-
|
|
151
|
-
| Example | Description |
|
|
152
|
-
| ------------------------ | -------------------------- |
|
|
153
|
-
| `exchange/quoteSwap.ts` | Get a quote for token swap |
|
|
154
|
-
| `exchange/createSwap.ts` | Execute a token swap |
|
|
155
|
-
|
|
156
147
|
### IAM (Identity & Access Management)
|
|
157
148
|
|
|
158
149
|
| Example | Description |
|
|
@@ -8,12 +8,6 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
8
8
|
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
// Create a player and account first
|
|
12
|
-
const player = await openfort.players.create({
|
|
13
|
-
name: `Player-${Date.now()}`,
|
|
14
|
-
});
|
|
15
|
-
console.log("Created player:", player.id);
|
|
16
|
-
|
|
17
11
|
const account = await openfort.accounts.evm.backend.create();
|
|
18
12
|
console.log("Created account:", account.address);
|
|
19
13
|
|
|
@@ -11,7 +11,7 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
11
11
|
// This creates the user and wallet before they authenticate
|
|
12
12
|
const result = await openfort.accounts.evm.embedded.pregenerate(
|
|
13
13
|
{
|
|
14
|
-
email:
|
|
14
|
+
email: process.env.TEST_EMAIL || `user-${Date.now()}@example.com`,
|
|
15
15
|
accountType: "Externally Owned Account"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
@@ -9,17 +9,33 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create a
|
|
13
|
-
const policy = await openfort.
|
|
12
|
+
// 1. Create a policy with criteria rules
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
description: "Sponsor all transactions on this chain",
|
|
16
|
+
rules: [
|
|
17
|
+
{
|
|
18
|
+
action: "accept",
|
|
19
|
+
operation: "sponsorEvmTransaction",
|
|
20
|
+
criteria: [
|
|
21
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
console.log("Created policy:", policy.id);
|
|
27
|
+
|
|
28
|
+
// 2. Create a fee sponsorship linked to that policy
|
|
29
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
14
30
|
name: "Gas Sponsorship Policy",
|
|
15
|
-
chainId,
|
|
16
31
|
strategy: {
|
|
17
32
|
sponsorSchema: "pay_for_user",
|
|
18
33
|
},
|
|
34
|
+
policyId: policy.id,
|
|
19
35
|
});
|
|
20
36
|
|
|
21
|
-
console.log("Created
|
|
22
|
-
console.log(" ID:",
|
|
23
|
-
console.log(" Name:",
|
|
24
|
-
console.log("
|
|
25
|
-
console.log("
|
|
37
|
+
console.log("Created fee sponsorship:");
|
|
38
|
+
console.log(" ID:", sponsorship.id);
|
|
39
|
+
console.log(" Name:", sponsorship.name);
|
|
40
|
+
console.log(" Strategy:", sponsorship.strategy.sponsorSchema);
|
|
41
|
+
console.log(" Policy ID:", sponsorship.policyId);
|
|
@@ -9,21 +9,34 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create a policy first
|
|
13
|
-
const policy = await openfort.
|
|
12
|
+
// Create a policy and fee sponsorship first
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
14
27
|
name: `TogglePolicy-${Date.now()}`,
|
|
15
|
-
chainId,
|
|
16
28
|
strategy: {
|
|
17
29
|
sponsorSchema: "pay_for_user",
|
|
18
30
|
},
|
|
31
|
+
policyId: policy.id,
|
|
19
32
|
});
|
|
20
|
-
console.log("Created
|
|
21
|
-
console.log("Initial state - Enabled:",
|
|
33
|
+
console.log("Created fee sponsorship:", sponsorship.id);
|
|
34
|
+
console.log("Initial state - Enabled:", sponsorship.enabled);
|
|
22
35
|
|
|
23
|
-
// Disable the
|
|
24
|
-
const disabled = await openfort.feeSponsorship.disable(
|
|
36
|
+
// Disable the fee sponsorship
|
|
37
|
+
const disabled = await openfort.feeSponsorship.disable(sponsorship.id);
|
|
25
38
|
console.log("\nAfter disable - Enabled:", disabled.enabled);
|
|
26
39
|
|
|
27
|
-
// Enable the
|
|
28
|
-
const enabled = await openfort.feeSponsorship.enable(
|
|
40
|
+
// Enable the fee sponsorship again
|
|
41
|
+
const enabled = await openfort.feeSponsorship.enable(sponsorship.id);
|
|
29
42
|
console.log("After enable - Enabled:", enabled.enabled);
|
|
@@ -9,22 +9,35 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create a policy first
|
|
12
|
+
// Create a policy and fee sponsorship first
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
13
26
|
const created = await openfort.feeSponsorship.create({
|
|
14
27
|
name: `TestPolicy-${Date.now()}`,
|
|
15
|
-
chainId,
|
|
16
28
|
strategy: {
|
|
17
29
|
sponsorSchema: "pay_for_user",
|
|
18
30
|
},
|
|
31
|
+
policyId: policy.id,
|
|
19
32
|
});
|
|
20
|
-
console.log("Created
|
|
33
|
+
console.log("Created fee sponsorship:", created.id);
|
|
21
34
|
|
|
22
|
-
// Retrieve the
|
|
23
|
-
const
|
|
35
|
+
// Retrieve the fee sponsorship by ID
|
|
36
|
+
const sponsorship = await openfort.feeSponsorship.get(created.id);
|
|
24
37
|
|
|
25
|
-
console.log("\nRetrieved
|
|
26
|
-
console.log(" ID:",
|
|
27
|
-
console.log(" Name:",
|
|
28
|
-
console.log("
|
|
29
|
-
console.log("
|
|
30
|
-
console.log("
|
|
38
|
+
console.log("\nRetrieved fee sponsorship:");
|
|
39
|
+
console.log(" ID:", sponsorship.id);
|
|
40
|
+
console.log(" Name:", sponsorship.name);
|
|
41
|
+
console.log(" Strategy:", sponsorship.strategy.sponsorSchema);
|
|
42
|
+
console.log(" Enabled:", sponsorship.enabled);
|
|
43
|
+
console.log(" Policy ID:", sponsorship.policyId);
|
|
@@ -7,11 +7,13 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
7
7
|
basePath: process.env.OPENFORT_BASE_URL,
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
// List all
|
|
10
|
+
// List all fee sponsorships
|
|
11
11
|
const result = await openfort.feeSponsorship.list({ limit: 10 });
|
|
12
12
|
|
|
13
|
-
console.log(`Found ${result.total}
|
|
14
|
-
for (const
|
|
15
|
-
console.log(` - ${
|
|
16
|
-
console.log(`
|
|
13
|
+
console.log(`Found ${result.total} fee sponsorships:`);
|
|
14
|
+
for (const sponsorship of result.data) {
|
|
15
|
+
console.log(` - ${sponsorship.name} (${sponsorship.id})`);
|
|
16
|
+
console.log(` Strategy: ${sponsorship.strategy.sponsorSchema}`);
|
|
17
|
+
console.log(` Policy: ${sponsorship.policyId}`);
|
|
18
|
+
console.log(` Enabled: ${sponsorship.enabled}`);
|
|
17
19
|
}
|
|
@@ -9,21 +9,34 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create a policy first
|
|
13
|
-
const policy = await openfort.
|
|
12
|
+
// Create a policy and fee sponsorship first
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
14
27
|
name: "Original Policy Name",
|
|
15
|
-
chainId,
|
|
16
28
|
strategy: {
|
|
17
29
|
sponsorSchema: "pay_for_user",
|
|
18
30
|
},
|
|
31
|
+
policyId: policy.id,
|
|
19
32
|
});
|
|
20
|
-
console.log("Created
|
|
33
|
+
console.log("Created fee sponsorship:", sponsorship.name);
|
|
21
34
|
|
|
22
|
-
// Update the
|
|
23
|
-
const updated = await openfort.feeSponsorship.update(
|
|
35
|
+
// Update the fee sponsorship
|
|
36
|
+
const updated = await openfort.feeSponsorship.update(sponsorship.id, {
|
|
24
37
|
name: "Updated Policy Name",
|
|
25
38
|
});
|
|
26
39
|
|
|
27
|
-
console.log("\nUpdated
|
|
40
|
+
console.log("\nUpdated fee sponsorship:");
|
|
28
41
|
console.log(" ID:", updated.id);
|
|
29
42
|
console.log(" Name:", updated.name);
|
|
@@ -6,7 +6,6 @@ import "dotenv/config";
|
|
|
6
6
|
const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
7
7
|
basePath: process.env.OPENFORT_BASE_URL,
|
|
8
8
|
publishableKey: process.env.OPENFORT_PUBLISHABLE_KEY,
|
|
9
|
-
debugging: true,
|
|
10
9
|
});
|
|
11
10
|
|
|
12
11
|
const accessToken = process.argv[2];
|
|
@@ -22,7 +21,6 @@ if (response === null) {
|
|
|
22
21
|
console.error("Invalid token");
|
|
23
22
|
process.exit(1);
|
|
24
23
|
}
|
|
25
|
-
console.log(response)
|
|
26
24
|
console.log("Session verified:");
|
|
27
25
|
console.log(" User ID:", response.user.id);
|
|
28
26
|
console.log(" User Email:", response.user.email);
|
|
@@ -10,12 +10,26 @@ 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 for gas sponsorship
|
|
13
|
-
const policy = await openfort.
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Create a fee sponsorship linked to the policy
|
|
27
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
14
28
|
name: `TxPolicy-${Date.now()}`,
|
|
15
|
-
chainId,
|
|
16
29
|
strategy: {
|
|
17
30
|
sponsorSchema: "pay_for_user",
|
|
18
31
|
},
|
|
32
|
+
policyId: policy.id,
|
|
19
33
|
});
|
|
20
34
|
|
|
21
35
|
const contract = await openfort.contracts.create({
|
|
@@ -26,18 +40,10 @@ const contract = await openfort.contracts.create({
|
|
|
26
40
|
// abi: [...]
|
|
27
41
|
});
|
|
28
42
|
|
|
29
|
-
// Create a policy rule to allow all account functions
|
|
30
|
-
await openfort.feeSponsorship.rules.create({
|
|
31
|
-
type: "contract_functions",
|
|
32
|
-
functionName: "All functions",
|
|
33
|
-
wildcard: true,
|
|
34
|
-
policy: policy.id,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
43
|
// Create a transaction intent
|
|
38
44
|
const transactionIntent = await openfort.transactionIntents.create({
|
|
39
45
|
chainId,
|
|
40
|
-
policy:
|
|
46
|
+
policy: sponsorship.id,
|
|
41
47
|
interactions: [
|
|
42
48
|
{
|
|
43
49
|
contract: contract.id,
|
|
@@ -9,18 +9,27 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
// Create a policy for gas sponsorship
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
15
24
|
});
|
|
16
25
|
|
|
17
|
-
// Create a policy
|
|
18
|
-
const
|
|
26
|
+
// Create a fee sponsorship linked to the policy
|
|
27
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
19
28
|
name: `TxPolicy-${Date.now()}`,
|
|
20
|
-
chainId,
|
|
21
29
|
strategy: {
|
|
22
30
|
sponsorSchema: "pay_for_user",
|
|
23
31
|
},
|
|
32
|
+
policyId: policy.id,
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
const contract = await openfort.contracts.create({
|
|
@@ -31,17 +40,10 @@ const contract = await openfort.contracts.create({
|
|
|
31
40
|
// abi: [...]
|
|
32
41
|
});
|
|
33
42
|
|
|
34
|
-
// Create a policy rule to allow all account functions
|
|
35
|
-
await openfort.feeSponsorship.rules.create({
|
|
36
|
-
type: "contract_functions",
|
|
37
|
-
functionName: "All functions",
|
|
38
|
-
wildcard: true,
|
|
39
|
-
policy: policy.id,
|
|
40
|
-
});
|
|
41
43
|
// Define transaction intent request
|
|
42
44
|
const transactionIntentRequest = {
|
|
43
45
|
chainId,
|
|
44
|
-
policy:
|
|
46
|
+
policy: sponsorship.id,
|
|
45
47
|
interactions: [
|
|
46
48
|
{
|
|
47
49
|
contract: contract.id,
|
|
@@ -9,18 +9,27 @@ const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
|
9
9
|
|
|
10
10
|
const chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
11
|
|
|
12
|
-
// Create
|
|
13
|
-
const
|
|
14
|
-
|
|
12
|
+
// Create a policy for gas sponsorship
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
scope: "project",
|
|
15
|
+
rules: [
|
|
16
|
+
{
|
|
17
|
+
action: "accept",
|
|
18
|
+
operation: "sponsorEvmTransaction",
|
|
19
|
+
criteria: [
|
|
20
|
+
{ type: "evmNetwork", operator: "in", chainIds: [chainId] },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
15
24
|
});
|
|
16
25
|
|
|
17
|
-
// Create a policy
|
|
18
|
-
const
|
|
26
|
+
// Create a fee sponsorship linked to the policy
|
|
27
|
+
const sponsorship = await openfort.feeSponsorship.create({
|
|
19
28
|
name: `TxPolicy-${Date.now()}`,
|
|
20
|
-
chainId,
|
|
21
29
|
strategy: {
|
|
22
30
|
sponsorSchema: "pay_for_user",
|
|
23
31
|
},
|
|
32
|
+
policyId: policy.id,
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
const contract = await openfort.contracts.create({
|
|
@@ -31,18 +40,10 @@ const contract = await openfort.contracts.create({
|
|
|
31
40
|
// abi: [...]
|
|
32
41
|
});
|
|
33
42
|
|
|
34
|
-
// Create a policy rule to allow all account functions
|
|
35
|
-
await openfort.feeSponsorship.rules.create({
|
|
36
|
-
type: "contract_functions",
|
|
37
|
-
functionName: "All functions",
|
|
38
|
-
wildcard: true,
|
|
39
|
-
policy: policy.id,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
43
|
// Create a transaction intent
|
|
43
44
|
const created = await openfort.transactionIntents.create({
|
|
44
45
|
chainId,
|
|
45
|
-
policy:
|
|
46
|
+
policy: sponsorship.id,
|
|
46
47
|
interactions: [
|
|
47
48
|
{
|
|
48
49
|
contract: contract.id,
|