@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,59 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ /**
3
+ * Derive the deposit PDA for a user and token mint
4
+ *
5
+ * @param user - The user's public key
6
+ * @param tokenMint - The SPL token mint
7
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
8
+ * @returns [PDA address, bump seed]
9
+ */
10
+ export declare function findDepositPda(user: PublicKey, tokenMint: PublicKey, programId?: PublicKey): [PublicKey, number];
11
+ /**
12
+ * Derive the username deposit PDA for a username and token mint
13
+ *
14
+ * @param username - The Telegram username
15
+ * @param tokenMint - The SPL token mint
16
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
17
+ * @returns [PDA address, bump seed]
18
+ */
19
+ export declare function findUsernameDepositPda(username: string, tokenMint: PublicKey, programId?: PublicKey): [PublicKey, number];
20
+ /**
21
+ * Derive the vault PDA
22
+ *
23
+ * @param tokenMint - The SPL token mint
24
+ * @param programId - Optional program ID (defaults to PROGRAM_ID)
25
+ * @returns [PDA address, bump seed]
26
+ */
27
+ export declare function findVaultPda(tokenMint: PublicKey, programId?: PublicKey): [PublicKey, number];
28
+ /**
29
+ * Derive the permission PDA for an account
30
+ *
31
+ * @param account - The account to derive permission for
32
+ * @param permissionProgramId - Optional permission program ID (defaults to PERMISSION_PROGRAM_ID)
33
+ * @returns [PDA address, bump seed]
34
+ */
35
+ export declare function findPermissionPda(account: PublicKey, permissionProgramId?: PublicKey): [PublicKey, number];
36
+ /**
37
+ * Derive the delegation record PDA for an account
38
+ *
39
+ * @param account - The delegated account
40
+ * @param delegationProgramId - Optional delegation program ID (defaults to DELEGATION_PROGRAM_ID)
41
+ * @returns [PDA address, bump seed]
42
+ */
43
+ export declare function findDelegationRecordPda(account: PublicKey, delegationProgramId?: PublicKey): [PublicKey, number];
44
+ /**
45
+ * Derive the delegation metadata PDA for an account
46
+ *
47
+ * @param account - The delegated account
48
+ * @param delegationProgramId - Optional delegation program ID (defaults to DELEGATION_PROGRAM_ID)
49
+ * @returns [PDA address, bump seed]
50
+ */
51
+ export declare function findDelegationMetadataPda(account: PublicKey, delegationProgramId?: PublicKey): [PublicKey, number];
52
+ /**
53
+ * Derive the buffer PDA for an account (used in delegation)
54
+ *
55
+ * @param account - The account to derive buffer for
56
+ * @param delegationProgramId - Optional delegation program ID (defaults to DELEGATION_PROGRAM_ID)
57
+ * @returns [PDA address, bump seed]
58
+ */
59
+ export declare function findBufferPda(account: PublicKey, ownerProgramId?: PublicKey): [PublicKey, number];
@@ -0,0 +1,254 @@
1
+ import type { PublicKey, Transaction, VersionedTransaction, Keypair, Commitment } from "@solana/web3.js";
2
+ import type { AnchorProvider } from "@coral-xyz/anchor";
3
+ /**
4
+ * Minimal wallet interface matching @solana/wallet-adapter-base
5
+ * Compatible with browser wallet adapters (Phantom, Solflare, etc.)
6
+ */
7
+ export interface WalletLike {
8
+ publicKey: PublicKey;
9
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
10
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
11
+ }
12
+ /**
13
+ * Union type supporting multiple wallet types:
14
+ * - WalletLike: Browser wallet adapters (Phantom, Solflare, etc.)
15
+ * - Keypair: Server-side scripts and testing
16
+ * - AnchorProvider: Existing Anchor projects
17
+ */
18
+ export type WalletSigner = WalletLike | Keypair | AnchorProvider;
19
+ /**
20
+ * RPC options for transactions
21
+ */
22
+ export interface RpcOptions {
23
+ skipPreflight?: boolean;
24
+ preflightCommitment?: Commitment;
25
+ maxRetries?: number;
26
+ }
27
+ /**
28
+ * Configuration for creating an ephemeral client
29
+ */
30
+ export interface ClientConfig {
31
+ signer: WalletSigner;
32
+ baseRpcEndpoint: string;
33
+ baseWsEndpoint?: string;
34
+ ephemeralRpcEndpoint: string;
35
+ ephemeralWsEndpoint?: string;
36
+ commitment?: Commitment;
37
+ authToken?: {
38
+ token: string;
39
+ expiresAt: number;
40
+ };
41
+ }
42
+ /**
43
+ * Data structure for a user deposit account
44
+ */
45
+ export interface DepositData {
46
+ user: PublicKey;
47
+ tokenMint: PublicKey;
48
+ amount: bigint;
49
+ address: PublicKey;
50
+ }
51
+ /**
52
+ * Data structure for a username-based deposit account
53
+ */
54
+ export interface UsernameDepositData {
55
+ username: string;
56
+ tokenMint: PublicKey;
57
+ amount: bigint;
58
+ address: PublicKey;
59
+ }
60
+ /**
61
+ * Parameters for initializing a deposit account
62
+ */
63
+ export interface InitializeDepositParams {
64
+ user: PublicKey;
65
+ tokenMint: PublicKey;
66
+ payer: PublicKey;
67
+ rpcOptions?: RpcOptions;
68
+ }
69
+ export interface InitializeUsernameDepositParams {
70
+ username: string;
71
+ tokenMint: PublicKey;
72
+ payer: PublicKey;
73
+ rpcOptions?: RpcOptions;
74
+ }
75
+ /**
76
+ * Parameters for modifying a deposit balance
77
+ */
78
+ export interface ModifyBalanceParams {
79
+ user: PublicKey;
80
+ tokenMint: PublicKey;
81
+ amount: number | bigint;
82
+ increase: boolean;
83
+ payer: PublicKey;
84
+ userTokenAccount: PublicKey;
85
+ rpcOptions?: RpcOptions;
86
+ }
87
+ /**
88
+ * Result of a balance modification
89
+ */
90
+ export interface ModifyBalanceResult {
91
+ signature: string;
92
+ deposit: DepositData;
93
+ }
94
+ /**
95
+ * Parameters for depositing tokens for a username
96
+ */
97
+ export interface DepositForUsernameParams {
98
+ username: string;
99
+ tokenMint: PublicKey;
100
+ amount: number | bigint;
101
+ depositor: PublicKey;
102
+ payer: PublicKey;
103
+ depositorTokenAccount: PublicKey;
104
+ rpcOptions?: RpcOptions;
105
+ }
106
+ /**
107
+ * Parameters for claiming tokens from a username deposit
108
+ */
109
+ export interface ClaimUsernameDepositParams {
110
+ username: string;
111
+ tokenMint: PublicKey;
112
+ amount: number | bigint;
113
+ recipient: PublicKey;
114
+ recipientTokenAccount: PublicKey;
115
+ session: PublicKey;
116
+ rpcOptions?: RpcOptions;
117
+ }
118
+ export interface ClaimUsernameDepositToDepositParams {
119
+ username: string;
120
+ tokenMint: PublicKey;
121
+ amount: number | bigint;
122
+ recipient: PublicKey;
123
+ session: PublicKey;
124
+ rpcOptions?: RpcOptions;
125
+ }
126
+ /**
127
+ * Parameters for creating a permission for a deposit
128
+ */
129
+ export interface CreatePermissionParams {
130
+ user: PublicKey;
131
+ tokenMint: PublicKey;
132
+ payer: PublicKey;
133
+ rpcOptions?: RpcOptions;
134
+ }
135
+ /**
136
+ * Parameters for creating a permission for a username deposit
137
+ */
138
+ export interface CreateUsernamePermissionParams {
139
+ username: string;
140
+ tokenMint: PublicKey;
141
+ session: PublicKey;
142
+ authority: PublicKey;
143
+ payer: PublicKey;
144
+ rpcOptions?: RpcOptions;
145
+ }
146
+ /**
147
+ * Parameters for delegating a deposit to an ephemeral rollup
148
+ */
149
+ export interface DelegateDepositParams {
150
+ user: PublicKey;
151
+ tokenMint: PublicKey;
152
+ payer: PublicKey;
153
+ validator: PublicKey;
154
+ rpcOptions?: RpcOptions;
155
+ }
156
+ /**
157
+ * Parameters for delegating a username deposit to an ephemeral rollup
158
+ */
159
+ export interface DelegateUsernameDepositParams {
160
+ username: string;
161
+ tokenMint: PublicKey;
162
+ payer: PublicKey;
163
+ validator: PublicKey;
164
+ rpcOptions?: RpcOptions;
165
+ }
166
+ /**
167
+ * Parameters for undelegating a deposit from an ephemeral rollup
168
+ */
169
+ export interface UndelegateDepositParams {
170
+ user: PublicKey;
171
+ tokenMint: PublicKey;
172
+ payer: PublicKey;
173
+ sessionToken?: PublicKey | null;
174
+ magicProgram: PublicKey;
175
+ magicContext: PublicKey;
176
+ rpcOptions?: RpcOptions;
177
+ }
178
+ /**
179
+ * Parameters for undelegating a username deposit from an ephemeral rollup
180
+ */
181
+ export interface UndelegateUsernameDepositParams {
182
+ username: string;
183
+ tokenMint: PublicKey;
184
+ session: PublicKey;
185
+ payer: PublicKey;
186
+ magicProgram: PublicKey;
187
+ magicContext: PublicKey;
188
+ rpcOptions?: RpcOptions;
189
+ }
190
+ /**
191
+ * Parameters for transferring between user deposits
192
+ */
193
+ export interface TransferDepositParams {
194
+ user: PublicKey;
195
+ tokenMint: PublicKey;
196
+ destinationUser: PublicKey;
197
+ amount: number | bigint;
198
+ payer: PublicKey;
199
+ sessionToken?: PublicKey | null;
200
+ rpcOptions?: RpcOptions;
201
+ }
202
+ /**
203
+ * Parameters for transferring from a user deposit to a username deposit
204
+ */
205
+ export interface TransferToUsernameDepositParams {
206
+ username: string;
207
+ tokenMint: PublicKey;
208
+ amount: number | bigint;
209
+ user: PublicKey;
210
+ payer: PublicKey;
211
+ sessionToken?: PublicKey | null;
212
+ rpcOptions?: RpcOptions;
213
+ }
214
+ /**
215
+ * Delegation record from MagicBlock router
216
+ */
217
+ export interface DelegationRecord {
218
+ authority: string;
219
+ owner: string;
220
+ delegationSlot: number;
221
+ lamports: number;
222
+ }
223
+ /**
224
+ * Response from MagicBlock getDelegationStatus RPC call
225
+ */
226
+ export interface DelegationStatusResult {
227
+ isDelegated: boolean;
228
+ fqdn?: string;
229
+ delegationRecord: DelegationRecord;
230
+ }
231
+ /**
232
+ * Full JSON-RPC response for getDelegationStatus
233
+ */
234
+ export interface DelegationStatusResponse {
235
+ jsonrpc: "2.0";
236
+ id: number | string;
237
+ result?: DelegationStatusResult;
238
+ error?: {
239
+ code: number;
240
+ message: string;
241
+ } | null;
242
+ }
243
+ /**
244
+ * Check if signer is a raw Keypair
245
+ */
246
+ export declare function isKeypair(signer: WalletSigner): signer is Keypair;
247
+ /**
248
+ * Check if signer is an AnchorProvider
249
+ */
250
+ export declare function isAnchorProvider(signer: WalletSigner): signer is AnchorProvider;
251
+ /**
252
+ * Check if signer is a WalletLike (wallet adapter)
253
+ */
254
+ export declare function isWalletLike(signer: WalletSigner): signer is WalletLike;
@@ -0,0 +1,31 @@
1
+ import { PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
2
+ import { type WalletSigner, type WalletLike } from "./types";
3
+ /**
4
+ * Internal wallet adapter that normalizes different wallet types
5
+ * to a common interface compatible with AnchorProvider
6
+ */
7
+ export declare class InternalWalletAdapter implements WalletLike {
8
+ private readonly signer;
9
+ readonly publicKey: PublicKey;
10
+ private constructor();
11
+ /**
12
+ * Create an adapter from any supported wallet type
13
+ */
14
+ static from(signer: WalletSigner): InternalWalletAdapter;
15
+ /**
16
+ * Extract public key from any supported wallet type
17
+ */
18
+ static getPublicKey(signer: WalletSigner): PublicKey;
19
+ /**
20
+ * Sign a single transaction
21
+ */
22
+ signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
23
+ /**
24
+ * Sign multiple transactions
25
+ */
26
+ signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
27
+ /**
28
+ * Sign a transaction with a Keypair
29
+ */
30
+ private signWithKeypair;
31
+ }
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@loyal-labs/private-transactions",
3
+ "version": "0.2.0",
4
+ "description": "SDK for Telegram-based private Solana deposits",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "typecheck": "tsc --noEmit",
20
+ "build": "bun run build:js && bun run build:types",
21
+ "build:js": "bun build ./index.ts --outdir ./dist --target browser --format esm --external @coral-xyz/anchor --external @solana/web3.js --external @solana/spl-token --external @magicblock-labs/ephemeral-rollups-sdk --external bn.js",
22
+ "build:types": "tsc -p tsconfig.build.json",
23
+ "prepublishOnly": "bun run build",
24
+ "clean": "rm -rf dist",
25
+ "test": "bun test --timeout 60000"
26
+ },
27
+ "keywords": [
28
+ "solana",
29
+ "telegram",
30
+ "anchor",
31
+ "web3",
32
+ "crypto",
33
+ "blockchain",
34
+ "deposit",
35
+ "transfer"
36
+ ],
37
+ "author": "Loyal",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/loyal/loyal-app.git",
42
+ "directory": "sdk/private-transactions"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/loyal/loyal-app/issues"
46
+ },
47
+ "homepage": "https://github.com/loyal/loyal-app/tree/main/sdk/private-transactions#readme",
48
+ "peerDependencies": {
49
+ "@coral-xyz/anchor": "^0.32.0",
50
+ "@magicblock-labs/ephemeral-rollups-sdk": "^0.8.5",
51
+ "@solana/spl-token": "^0.4.14",
52
+ "@solana/web3.js": "^1.95.0"
53
+ },
54
+ "dependencies": {
55
+ "tweetnacl": "^1.0.3"
56
+ },
57
+ "devDependencies": {
58
+ "@coral-xyz/anchor": "^0.32.1",
59
+ "@solana/web3.js": "^1.95.0",
60
+ "@types/bun": "latest",
61
+ "typescript": "^5"
62
+ }
63
+ }