@openfort/openfort-node 0.6.78 → 0.7.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/Makefile +75 -0
- package/README.md +174 -65
- package/biome.json +34 -4
- package/dist/index.d.mts +8871 -14863
- package/dist/index.d.ts +8871 -14863
- package/dist/index.js +4978 -24180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4677 -23904
- package/dist/index.mjs.map +1 -1
- package/examples/.env.example +16 -0
- package/examples/README.md +154 -0
- package/examples/contracts/createContract.ts +25 -0
- package/examples/contracts/listContracts.ts +18 -0
- package/examples/contracts/readContract.ts +29 -0
- package/examples/evm/accounts/createAccount.ts +18 -0
- package/examples/evm/accounts/exportAccount.ts +39 -0
- package/examples/evm/accounts/getAccount.ts +30 -0
- package/examples/evm/accounts/importAccount.ts +31 -0
- package/examples/evm/accounts/listAccounts.ts +32 -0
- package/examples/evm/signing/signHash.ts +28 -0
- package/examples/evm/signing/signMessage.ts +32 -0
- package/examples/evm/signing/signTransaction.ts +42 -0
- package/examples/evm/signing/signTypedData.ts +71 -0
- package/examples/exchange/createSwap.ts +49 -0
- package/examples/exchange/quoteSwap.ts +34 -0
- package/examples/iam/deleteUser.ts +22 -0
- package/examples/iam/getSession.ts +30 -0
- package/examples/iam/getUser.ts +32 -0
- package/examples/iam/listUsers.ts +18 -0
- package/examples/iam/pregenerateUser.ts +33 -0
- package/examples/package.json +31 -0
- package/examples/pnpm-lock.yaml +1231 -0
- package/examples/policies/createPolicy.ts +25 -0
- package/examples/policies/createPolicyRule.ts +43 -0
- package/examples/policies/disableEnablePolicy.ts +29 -0
- package/examples/policies/getPolicy.ts +30 -0
- package/examples/policies/listPolicies.ts +17 -0
- package/examples/policies/listPolicyRules.ts +37 -0
- package/examples/policies/updatePolicy.ts +29 -0
- package/examples/solana/accounts/createAccount.ts +18 -0
- package/examples/solana/accounts/exportAccount.ts +29 -0
- package/examples/solana/accounts/getAccount.ts +24 -0
- package/examples/solana/accounts/importAccount.ts +28 -0
- package/examples/solana/accounts/listAccounts.ts +32 -0
- package/examples/solana/signing/signMessage.ts +22 -0
- package/examples/solana/signing/signTransaction.ts +41 -0
- package/examples/transactions/createTransactionIntent.ts +49 -0
- package/examples/transactions/estimateGas.ts +52 -0
- package/examples/transactions/getTransactionIntent.ts +54 -0
- package/examples/transactions/listTransactionIntents.ts +31 -0
- package/examples/tsconfig.json +15 -0
- package/examples/webhook/index.ts +43 -0
- package/openapi-auth.json +6526 -0
- package/openapi.json +20425 -0
- package/orval.config.ts +41 -0
- package/package.json +22 -12
- package/pnpm-workspace.yaml +2 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +20 -0
- package/updateGeneratedCode.sh +0 -8
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Usage: npx tsx policies/createPolicy.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 gas sponsorship policy
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
name: "Gas Sponsorship Policy",
|
|
15
|
+
chainId,
|
|
16
|
+
strategy: {
|
|
17
|
+
sponsorSchema: "pay_for_user",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log("Created policy:");
|
|
22
|
+
console.log(" ID:", policy.id);
|
|
23
|
+
console.log(" Name:", policy.name);
|
|
24
|
+
console.log(" Chain ID:", policy.chainId);
|
|
25
|
+
console.log(" Strategy:", policy.strategy.sponsorSchema);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Usage: npx tsx policies/createPolicyRule.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.policies.create({
|
|
14
|
+
name: `PolicyWithRules-${Date.now()}`,
|
|
15
|
+
chainId,
|
|
16
|
+
strategy: {
|
|
17
|
+
sponsorSchema: "pay_for_user",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
console.log("Created policy:", policy.id);
|
|
21
|
+
|
|
22
|
+
// Create a contract to reference in the rule
|
|
23
|
+
const contract = await openfort.contracts.create({
|
|
24
|
+
name: "Test Contract",
|
|
25
|
+
chainId,
|
|
26
|
+
address: "0x38090d1636069c0ff1af6bc1737fb996b7f63ac0",
|
|
27
|
+
});
|
|
28
|
+
console.log("Created contract:", contract.id);
|
|
29
|
+
|
|
30
|
+
// Create a policy rule for account functions
|
|
31
|
+
const rule = await openfort.policyRules.create({
|
|
32
|
+
type: "account_functions",
|
|
33
|
+
policy: policy.id,
|
|
34
|
+
functionName: "transfer",
|
|
35
|
+
contract: contract.id,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log("\nCreated policy rule:");
|
|
39
|
+
console.log(" ID:", rule.id);
|
|
40
|
+
console.log(" Type:", rule.type);
|
|
41
|
+
if ("functionName" in rule && rule.functionName) {
|
|
42
|
+
console.log(" Function:", rule.functionName);
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Usage: npx tsx policies/disableEnablePolicy.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.policies.create({
|
|
14
|
+
name: `TogglePolicy-${Date.now()}`,
|
|
15
|
+
chainId,
|
|
16
|
+
strategy: {
|
|
17
|
+
sponsorSchema: "pay_for_user",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
console.log("Created policy:", policy.id);
|
|
21
|
+
console.log("Initial state - Enabled:", policy.enabled);
|
|
22
|
+
|
|
23
|
+
// Disable the policy
|
|
24
|
+
const disabled = await openfort.policies.disable(policy.id);
|
|
25
|
+
console.log("\nAfter disable - Enabled:", disabled.enabled);
|
|
26
|
+
|
|
27
|
+
// Enable the policy again
|
|
28
|
+
const enabled = await openfort.policies.enable(policy.id);
|
|
29
|
+
console.log("After enable - Enabled:", enabled.enabled);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Usage: npx tsx policies/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.policies.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.policies.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 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
|
+
// List all policies
|
|
11
|
+
const result = await openfort.policies.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
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Usage: npx tsx policies/listPolicyRules.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 with rules
|
|
13
|
+
const policy = await openfort.policies.create({
|
|
14
|
+
name: `PolicyWithRules-${Date.now()}`,
|
|
15
|
+
chainId,
|
|
16
|
+
strategy: {
|
|
17
|
+
sponsorSchema: "pay_for_user",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Add some rules
|
|
22
|
+
await openfort.policyRules.create({
|
|
23
|
+
type: "account_functions",
|
|
24
|
+
policy: policy.id,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// List rules for this policy
|
|
28
|
+
const result = await openfort.policyRules.list({ policy: policy.id });
|
|
29
|
+
|
|
30
|
+
console.log(`Found ${result.total} rules for policy ${policy.id}:`);
|
|
31
|
+
for (const rule of result.data) {
|
|
32
|
+
console.log(` - ${rule.id}`);
|
|
33
|
+
console.log(` Type: ${rule.type}`);
|
|
34
|
+
if ("functionName" in rule && rule.functionName) {
|
|
35
|
+
console.log(` Function: ${rule.functionName}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Usage: npx tsx 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 chainId = Number(process.env.CHAIN_ID) || 80002;
|
|
11
|
+
|
|
12
|
+
// Create a policy first
|
|
13
|
+
const policy = await openfort.policies.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.policies.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,18 @@
|
|
|
1
|
+
// Usage: npx tsx solana/accounts/createAccount.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Create a Solana backend account
|
|
12
|
+
const account = await openfort.accounts.solana.backend.create({
|
|
13
|
+
name: `SolanaWallet-${Date.now()}`,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
console.log("Created Solana account:");
|
|
17
|
+
console.log(" ID:", account.id);
|
|
18
|
+
console.log(" Address:", account.address);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Usage: npx tsx solana/accounts/exportAccount.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Create a Solana backend account
|
|
12
|
+
const account = await openfort.accounts.solana.backend.create({
|
|
13
|
+
name: "ExportTestSolanaWallet",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
console.log("Created Solana account:");
|
|
17
|
+
console.log(" ID:", account.id);
|
|
18
|
+
console.log(" Address:", account.address);
|
|
19
|
+
|
|
20
|
+
// Export the account's private key
|
|
21
|
+
// Returns base58 encoded private key (standard Solana format)
|
|
22
|
+
const exportedPrivateKey = await openfort.accounts.solana.backend.export({
|
|
23
|
+
id: account.id,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log("\nExported private key (base58):", exportedPrivateKey);
|
|
27
|
+
console.log(
|
|
28
|
+
"\nNote: This is the standard Solana private key format that can be used with Phantom, Solflare, etc."
|
|
29
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Usage: npx tsx solana/accounts/getAccount.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Create a Solana backend account
|
|
11
|
+
const account = await openfort.accounts.solana.backend.create({
|
|
12
|
+
name: `MySolanaWallet-${Date.now()}`,
|
|
13
|
+
});
|
|
14
|
+
console.log("Created account:", account.address);
|
|
15
|
+
|
|
16
|
+
// Retrieve account by ID
|
|
17
|
+
const accountById = await openfort.accounts.solana.backend.get({ id: account.id });
|
|
18
|
+
console.log("Retrieved account by ID:", accountById.address);
|
|
19
|
+
|
|
20
|
+
// Retrieve account by address
|
|
21
|
+
const accountByAddress = await openfort.accounts.solana.backend.get({
|
|
22
|
+
address: account.address,
|
|
23
|
+
});
|
|
24
|
+
console.log("Retrieved account by address:", accountByAddress.address);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Usage: npx tsx solana/accounts/importAccount.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// For demonstration, we'll use a random 32-byte hex key
|
|
12
|
+
// In production, you would use an actual Solana private key (base58 or hex format)
|
|
13
|
+
const privateKeyHex = Array.from({ length: 64 }, () =>
|
|
14
|
+
Math.floor(Math.random() * 16).toString(16)
|
|
15
|
+
).join("");
|
|
16
|
+
|
|
17
|
+
console.log("Private key (hex):", privateKeyHex);
|
|
18
|
+
|
|
19
|
+
// Import the account to Openfort
|
|
20
|
+
// Openfort accepts both base58 and hex format for Solana keys
|
|
21
|
+
const account = await openfort.accounts.solana.backend.import({
|
|
22
|
+
privateKey: privateKeyHex, // Can also be base58 format
|
|
23
|
+
name: "ImportedSolanaWallet",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log("\nImported Solana account:");
|
|
27
|
+
console.log(" ID:", account.id);
|
|
28
|
+
console.log(" Address:", account.address);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Usage: npx tsx solana/accounts/listAccounts.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// List all Solana backend accounts
|
|
12
|
+
const result = await openfort.accounts.solana.backend.list({ limit: 10 });
|
|
13
|
+
|
|
14
|
+
console.log(`Found ${result.total} Solana accounts:`);
|
|
15
|
+
for (const account of result.accounts) {
|
|
16
|
+
console.log(` - ${account.address} (${account.id})`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Create a few more accounts
|
|
20
|
+
await openfort.accounts.solana.backend.create({ name: `SolanaWallet-${Date.now()}-1` });
|
|
21
|
+
await openfort.accounts.solana.backend.create({ name: `SolanaWallet-${Date.now()}-2` });
|
|
22
|
+
|
|
23
|
+
// List accounts with pagination
|
|
24
|
+
const moreAccounts = await openfort.accounts.solana.backend.list({
|
|
25
|
+
limit: 5,
|
|
26
|
+
skip: 0,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(`\nPaginated results (first 5):`);
|
|
30
|
+
for (const account of moreAccounts.accounts) {
|
|
31
|
+
console.log(` - ${account.address}`);
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Usage: npx tsx solana/signing/signMessage.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Create a Solana backend account
|
|
12
|
+
const account = await openfort.accounts.solana.backend.create({
|
|
13
|
+
name: `SolanaWallet-${Date.now()}`,
|
|
14
|
+
});
|
|
15
|
+
console.log("Created Solana account:", account.address);
|
|
16
|
+
|
|
17
|
+
// Sign a message
|
|
18
|
+
const message = "Hello, Openfort on Solana!";
|
|
19
|
+
const signature = await account.signMessage({ message });
|
|
20
|
+
|
|
21
|
+
console.log("\nMessage:", message);
|
|
22
|
+
console.log("Signature:", signature);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Usage: npx tsx solana/signing/signTransaction.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
|
+
walletSecret: process.env.OPENFORT_WALLET_SECRET,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Create a Solana backend account
|
|
12
|
+
const account = await openfort.accounts.solana.backend.create({
|
|
13
|
+
name: `SolanaWallet-${Date.now()}`,
|
|
14
|
+
});
|
|
15
|
+
console.log("Created Solana account:", account.address);
|
|
16
|
+
|
|
17
|
+
// Create a sample transaction (base64 encoded)
|
|
18
|
+
// In production, you would create this using @solana/web3.js
|
|
19
|
+
// This is a placeholder transaction for demonstration
|
|
20
|
+
const sampleTransaction = Buffer.from("sample-transaction-data").toString(
|
|
21
|
+
"base64"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
console.log("\nTransaction (base64):", sampleTransaction);
|
|
25
|
+
|
|
26
|
+
// Sign the transaction
|
|
27
|
+
// Note: This example uses a placeholder. In production, create a proper
|
|
28
|
+
// Solana transaction using @solana/web3.js or @solana/kit and serialize it to base64
|
|
29
|
+
try {
|
|
30
|
+
const signedTransaction = await account.signTransaction({
|
|
31
|
+
transaction: sampleTransaction,
|
|
32
|
+
});
|
|
33
|
+
console.log("Signed transaction:", signedTransaction);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.log(
|
|
36
|
+
"\nNote: This example uses a placeholder transaction."
|
|
37
|
+
);
|
|
38
|
+
console.log(
|
|
39
|
+
"In production, create a valid Solana transaction using @solana/web3.js"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Usage: npx tsx transactions/createTransactionIntent.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 an account (V1 legacy API)
|
|
13
|
+
const account = await openfort.accounts.v1.create({
|
|
14
|
+
chainId,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Create a policy for gas sponsorship
|
|
18
|
+
const policy = await openfort.policies.create({
|
|
19
|
+
name: `TxPolicy-${Date.now()}`,
|
|
20
|
+
chainId,
|
|
21
|
+
strategy: {
|
|
22
|
+
sponsorSchema: "pay_for_user",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Create a policy rule to allow all account functions
|
|
27
|
+
await openfort.policyRules.create({
|
|
28
|
+
type: "account_functions",
|
|
29
|
+
policy: policy.id,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Create a transaction intent
|
|
33
|
+
const transactionIntent = await openfort.transactionIntents.create({
|
|
34
|
+
chainId,
|
|
35
|
+
policy: policy.id,
|
|
36
|
+
interactions: [
|
|
37
|
+
{
|
|
38
|
+
contract: "0x38090d1636069c0ff1af6bc1737fb996b7f63ac0",
|
|
39
|
+
functionName: "mint",
|
|
40
|
+
functionArgs: [account.address],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log("Created transaction intent:");
|
|
46
|
+
console.log(" ID:", transactionIntent.id);
|
|
47
|
+
console.log(" Chain ID:", transactionIntent.chainId);
|
|
48
|
+
console.log(" Player:", transactionIntent.player?.id);
|
|
49
|
+
console.log(" Policy:", transactionIntent.policy?.id);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Usage: npx tsx transactions/estimateGas.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 an account (V1 legacy API)
|
|
13
|
+
const account = await openfort.accounts.v1.create({
|
|
14
|
+
chainId,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Create a policy
|
|
18
|
+
const policy = await openfort.policies.create({
|
|
19
|
+
name: `TxPolicy-${Date.now()}`,
|
|
20
|
+
chainId,
|
|
21
|
+
strategy: {
|
|
22
|
+
sponsorSchema: "pay_for_user",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await openfort.policyRules.create({
|
|
27
|
+
type: "account_functions",
|
|
28
|
+
policy: policy.id,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Define transaction intent request
|
|
32
|
+
const transactionIntentRequest = {
|
|
33
|
+
chainId,
|
|
34
|
+
policy: policy.id,
|
|
35
|
+
interactions: [
|
|
36
|
+
{
|
|
37
|
+
contract: "0x38090d1636069c0ff1af6bc1737fb996b7f63ac0",
|
|
38
|
+
functionName: "mint",
|
|
39
|
+
functionArgs: [account.address],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Estimate cost for the transaction before creating it
|
|
45
|
+
const estimate = await openfort.transactionIntents.estimateCost(
|
|
46
|
+
transactionIntentRequest,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
console.log("Cost estimate:");
|
|
50
|
+
console.log(" Estimated TX Gas:", estimate.estimatedTXGas);
|
|
51
|
+
console.log(" Estimated TX Gas Fee:", estimate.estimatedTXGasFee);
|
|
52
|
+
console.log(" Estimated TX Gas Fee (USD):", estimate.estimatedTXGasFeeUSD);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Usage: npx tsx transactions/getTransactionIntent.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 an account (V1 legacy API)
|
|
13
|
+
const account = await openfort.accounts.v1.create({
|
|
14
|
+
chainId,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Create a policy
|
|
18
|
+
const policy = await openfort.policies.create({
|
|
19
|
+
name: `TxPolicy-${Date.now()}`,
|
|
20
|
+
chainId,
|
|
21
|
+
strategy: {
|
|
22
|
+
sponsorSchema: "pay_for_user",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
await openfort.policyRules.create({
|
|
27
|
+
type: "account_functions",
|
|
28
|
+
policy: policy.id,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Create a transaction intent
|
|
32
|
+
const created = await openfort.transactionIntents.create({
|
|
33
|
+
chainId,
|
|
34
|
+
policy: policy.id,
|
|
35
|
+
interactions: [
|
|
36
|
+
{
|
|
37
|
+
contract: "0x38090d1636069c0ff1af6bc1737fb996b7f63ac0",
|
|
38
|
+
functionName: "mint",
|
|
39
|
+
functionArgs: [account.address],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log("Created transaction intent:", created.id);
|
|
45
|
+
|
|
46
|
+
// Retrieve the transaction intent
|
|
47
|
+
const intent = await openfort.transactionIntents.get(created.id);
|
|
48
|
+
|
|
49
|
+
console.log("\nRetrieved transaction intent:");
|
|
50
|
+
console.log(" ID:", intent.id);
|
|
51
|
+
console.log(" Chain ID:", intent.chainId);
|
|
52
|
+
console.log(" Player:", intent.player?.id);
|
|
53
|
+
console.log(" Account:", intent.account?.id);
|
|
54
|
+
console.log(" Created:", intent.createdAt);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Usage: npx tsx transactions/listTransactionIntents.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 transaction intents
|
|
11
|
+
const result = await openfort.transactionIntents.list({ limit: 10 });
|
|
12
|
+
|
|
13
|
+
console.log(`Found ${result.total} transaction intents:`);
|
|
14
|
+
for (const intent of result.data) {
|
|
15
|
+
console.log(` - ${intent.id}`);
|
|
16
|
+
console.log(` Chain: ${intent.chainId}`);
|
|
17
|
+
console.log(` Player: ${intent.player?.id || "N/A"}`);
|
|
18
|
+
console.log(` Created: ${intent.createdAt}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// List transaction intents for a specific player
|
|
22
|
+
const player = await openfort.players.create({
|
|
23
|
+
name: `Player-${Date.now()}`,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const playerIntents = await openfort.transactionIntents.list({
|
|
27
|
+
player: [player.id],
|
|
28
|
+
limit: 10,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(`\nTransaction intents for player ${player.id}: ${playerIntents.total}`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2021",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "."
|
|
12
|
+
},
|
|
13
|
+
"include": ["./**/*.ts"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import express, { type Request, type Response } from "express";
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import Openfort from "@openfort/openfort-node";
|
|
4
|
+
|
|
5
|
+
interface WebhookEvent {
|
|
6
|
+
type: string;
|
|
7
|
+
data: {
|
|
8
|
+
id: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const app = express();
|
|
14
|
+
const port = process.env.APP_PORT || "3001";
|
|
15
|
+
|
|
16
|
+
app.post(
|
|
17
|
+
"/webhook/openfort",
|
|
18
|
+
express.raw({ type: "application/json" }),
|
|
19
|
+
async (req: Request, res: Response) => {
|
|
20
|
+
const openfort = new Openfort(process.env.OPENFORT_API_KEY!, {
|
|
21
|
+
basePath: process.env.OPENFORT_BASE_URL,
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
const signature = req.headers["openfort-signature"];
|
|
25
|
+
if (typeof signature !== "string") {
|
|
26
|
+
throw new Error("Missing or invalid openfort-signature header");
|
|
27
|
+
}
|
|
28
|
+
const event = await openfort.constructWebhookEvent<WebhookEvent>(
|
|
29
|
+
req.body.toString(),
|
|
30
|
+
signature,
|
|
31
|
+
);
|
|
32
|
+
console.info("Received webhook event:", event.type, event.data.id);
|
|
33
|
+
res.status(200).send("OK");
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error((e as Error).message);
|
|
36
|
+
res.status(400).send("Invalid webhook");
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
app.listen(port, () => {
|
|
42
|
+
console.info(`Server is running on http://localhost:${port}`);
|
|
43
|
+
});
|