@loyal-labs/private-transactions 0.2.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.
@@ -0,0 +1,139 @@
1
+ import { Connection, PublicKey } from "@solana/web3.js";
2
+ import { Program } from "@coral-xyz/anchor";
3
+ import type { TelegramPrivateTransfer } from "./idl/telegram_private_transfer.ts";
4
+ import type { WalletLike, ClientConfig, DepositData, UsernameDepositData, InitializeDepositParams, ModifyBalanceParams, ModifyBalanceResult, DepositForUsernameParams, ClaimUsernameDepositParams, CreatePermissionParams, CreateUsernamePermissionParams, DelegateDepositParams, DelegateUsernameDepositParams, UndelegateDepositParams, UndelegateUsernameDepositParams, TransferDepositParams, TransferToUsernameDepositParams, InitializeUsernameDepositParams, ClaimUsernameDepositToDepositParams } from "./types";
5
+ export declare function waitForAccountOwnerChange(connection: Connection, account: PublicKey, expectedOwner: PublicKey, timeoutMs?: number, intervalMs?: number): {
6
+ wait: () => Promise<void>;
7
+ cancel: () => Promise<void>;
8
+ };
9
+ /**
10
+ * LoyalPrivateTransactionsClient - SDK for interacting with the Telegram Private Transfer program
11
+ * with MagicBlock PER (Private Ephemeral Rollups) support
12
+ *
13
+ * @example
14
+ * // Base layer client with keypair
15
+ * const client = LoyalPrivateTransactionsClient.from(connection, keypair);
16
+ *
17
+ * // Ephemeral rollup client
18
+ * const ephemeralClient = await LoyalPrivateTransactionsClient.fromEphemeral({
19
+ * signer: keypair,
20
+ * rpcEndpoint: "http://localhost:7799",
21
+ * wsEndpoint: "ws://localhost:7800",
22
+ * });
23
+ *
24
+ * // Deposit tokens and delegate to PER
25
+ * await client.initializeDeposit({ user, tokenMint, payer });
26
+ * await client.modifyBalance({ user, tokenMint, amount: 1000000, increase: true, ... });
27
+ * await client.createPermission({ user, tokenMint, payer });
28
+ * await client.delegateDeposit({ user, tokenMint, payer, validator });
29
+ *
30
+ * // Execute private transfers on ephemeral rollup
31
+ * await ephemeralClient.transferToUsernameDeposit({ username, tokenMint, amount, ... });
32
+ *
33
+ * // Commit and undelegate
34
+ * await ephemeralClient.undelegateDeposit({ user, tokenMint, ... });
35
+ */
36
+ export declare class LoyalPrivateTransactionsClient {
37
+ readonly baseProgram: Program<TelegramPrivateTransfer>;
38
+ readonly ephemeralProgram: Program<TelegramPrivateTransfer>;
39
+ readonly wallet: WalletLike;
40
+ private constructor();
41
+ /**
42
+ * Create client connected to an ephemeral rollup endpoint with PER auth token.
43
+ * Verifies TEE RPC integrity and obtains an auth token automatically.
44
+ */
45
+ static fromConfig(config: ClientConfig): Promise<LoyalPrivateTransactionsClient>;
46
+ /**
47
+ * Initialize a deposit account for a user and token mint
48
+ */
49
+ initializeDeposit(params: InitializeDepositParams): Promise<string>;
50
+ initializeUsernameDeposit(params: InitializeUsernameDepositParams): Promise<string>;
51
+ /**
52
+ * Modify the balance of a user's deposit account
53
+ */
54
+ modifyBalance(params: ModifyBalanceParams): Promise<ModifyBalanceResult>;
55
+ /**
56
+ * Deposit tokens for a Telegram username
57
+ */
58
+ depositForUsername(params: DepositForUsernameParams): Promise<string>;
59
+ /**
60
+ * Claim tokens from a username-based deposit
61
+ */
62
+ claimUsernameDeposit(params: ClaimUsernameDepositParams): Promise<string>;
63
+ claimUsernameDepositToDeposit(params: ClaimUsernameDepositToDepositParams): Promise<string>;
64
+ /**
65
+ * Create a permission for a deposit account (required for PER)
66
+ */
67
+ createPermission(params: CreatePermissionParams): Promise<string | null>;
68
+ /**
69
+ * Create a permission for a username-based deposit account
70
+ */
71
+ createUsernamePermission(params: CreateUsernamePermissionParams): Promise<string | null>;
72
+ /**
73
+ * Delegate a deposit account to the ephemeral rollup
74
+ */
75
+ delegateDeposit(params: DelegateDepositParams): Promise<string>;
76
+ /**
77
+ * Delegate a username-based deposit account to the ephemeral rollup
78
+ */
79
+ delegateUsernameDeposit(params: DelegateUsernameDepositParams): Promise<string>;
80
+ /**
81
+ * Undelegate a deposit account from the ephemeral rollup.
82
+ * Waits for both base and ephemeral connections to confirm the deposit
83
+ * is owned by PROGRAM_ID before returning.
84
+ */
85
+ undelegateDeposit(params: UndelegateDepositParams): Promise<string>;
86
+ /**
87
+ * Undelegate a username-based deposit account from the ephemeral rollup
88
+ */
89
+ undelegateUsernameDeposit(params: UndelegateUsernameDepositParams): Promise<string>;
90
+ /**
91
+ * Transfer between two user deposits
92
+ */
93
+ transferDeposit(params: TransferDepositParams): Promise<string>;
94
+ /**
95
+ * Transfer from a user deposit to a username deposit
96
+ */
97
+ transferToUsernameDeposit(params: TransferToUsernameDepositParams): Promise<string>;
98
+ /**
99
+ * Get deposit data for a user and token mint
100
+ */
101
+ getBaseDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
102
+ getEphemeralDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
103
+ /**
104
+ * Get username deposit data
105
+ */
106
+ getBaseUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
107
+ getEphemeralUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
108
+ /**
109
+ * Find the deposit PDA for a user and token mint
110
+ */
111
+ findDepositPda(user: PublicKey, tokenMint: PublicKey): [PublicKey, number];
112
+ /**
113
+ * Find the username deposit PDA
114
+ */
115
+ findUsernameDepositPda(username: string, tokenMint: PublicKey): [PublicKey, number];
116
+ /**
117
+ * Find the vault PDA
118
+ */
119
+ findVaultPda(tokenMint: PublicKey): [PublicKey, number];
120
+ /**
121
+ * Get the connected wallet's public key
122
+ */
123
+ get publicKey(): PublicKey;
124
+ /**
125
+ * Get the underlying Anchor program instance
126
+ */
127
+ getBaseProgram(): Program<TelegramPrivateTransfer>;
128
+ getEphemeralProgram(): Program<TelegramPrivateTransfer>;
129
+ /**
130
+ * Get the program ID
131
+ */
132
+ getProgramId(): PublicKey;
133
+ private validateUsername;
134
+ private permissionAccountExists;
135
+ private isAccountAlreadyInUse;
136
+ private ensureNotDelegated;
137
+ private ensureDelegated;
138
+ private getDelegationStatus;
139
+ }
@@ -0,0 +1,58 @@
1
+ /// <reference types="node" />
2
+ import { LAMPORTS_PER_SOL } from "@solana/web3.js";
3
+ /**
4
+ * TEE ER Validator
5
+ */
6
+ export declare const ER_VALIDATOR: any;
7
+ /**
8
+ * Telegram Private Transfer program ID
9
+ */
10
+ export declare const PROGRAM_ID: any;
11
+ /**
12
+ * MagicBlock Delegation Program ID
13
+ */
14
+ export declare const DELEGATION_PROGRAM_ID: any;
15
+ /**
16
+ * MagicBlock Permission Program ID (ACL)
17
+ */
18
+ export declare const PERMISSION_PROGRAM_ID: any;
19
+ /**
20
+ * MagicBlock Magic Program ID (for undelegation)
21
+ */
22
+ export declare const MAGIC_PROGRAM_ID: any;
23
+ /**
24
+ * MagicBlock Magic Context Account (for undelegation)
25
+ */
26
+ export declare const MAGIC_CONTEXT_ID: any;
27
+ /**
28
+ * PDA seed for deposit accounts
29
+ */
30
+ export declare const DEPOSIT_SEED = "deposit";
31
+ export declare const DEPOSIT_SEED_BYTES: Buffer;
32
+ /**
33
+ * PDA seed for username deposit accounts
34
+ */
35
+ export declare const USERNAME_DEPOSIT_SEED = "username_deposit";
36
+ export declare const USERNAME_DEPOSIT_SEED_BYTES: Buffer;
37
+ /**
38
+ * PDA seed for vault account
39
+ */
40
+ export declare const VAULT_SEED = "vault";
41
+ export declare const VAULT_SEED_BYTES: Buffer;
42
+ /**
43
+ * PDA seed for permission accounts
44
+ */
45
+ export declare const PERMISSION_SEED = "permission:";
46
+ export declare const PERMISSION_SEED_BYTES: Buffer;
47
+ /**
48
+ * Re-export LAMPORTS_PER_SOL for convenience
49
+ */
50
+ export { LAMPORTS_PER_SOL };
51
+ /**
52
+ * Convert SOL to lamports
53
+ */
54
+ export declare function solToLamports(sol: number): number;
55
+ /**
56
+ * Convert lamports to SOL
57
+ */
58
+ export declare function lamportsToSol(lamports: number): number;