@arcadiasol/game-sdk 1.0.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,26 @@
1
+ import { PaymentResult } from './types';
2
+ import { MessageHandler } from './messaging';
3
+ import { WalletManager } from './wallet';
4
+ /**
5
+ * Payment processing
6
+ */
7
+ export declare class PaymentManager {
8
+ private gameId;
9
+ private isIframe;
10
+ private messageHandler;
11
+ private walletManager;
12
+ constructor(gameId: string, isIframe: boolean, messageHandler: MessageHandler, walletManager: WalletManager);
13
+ /**
14
+ * Pay to play - one-time payment to access game
15
+ */
16
+ payToPlay(amount: number, token: 'SOL' | 'USDC'): Promise<PaymentResult>;
17
+ /**
18
+ * Purchase in-game item
19
+ */
20
+ purchaseItem(itemId: string, amount: number, token: 'SOL' | 'USDC'): Promise<PaymentResult>;
21
+ /**
22
+ * Validate payment parameters
23
+ */
24
+ private validatePaymentParams;
25
+ }
26
+ //# sourceMappingURL=payment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,aAAa,EAAmB,MAAM,SAAS,CAAC;AAQtF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,aAAa,CAAgB;gBAGnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,aAAa;IAQ9B;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA6D9E;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAkEjG;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAS9B"}
@@ -0,0 +1,72 @@
1
+ import { SDKConfig } from './types';
2
+ /**
3
+ * Main Arcadia Game SDK class
4
+ */
5
+ export declare class ArcadiaSDK {
6
+ private config;
7
+ private isIframe;
8
+ private initialized;
9
+ private messageHandler;
10
+ private walletManager;
11
+ private paymentManager;
12
+ /**
13
+ * Create new SDK instance
14
+ */
15
+ constructor(config: SDKConfig);
16
+ /**
17
+ * Initialize SDK and request initialization data from parent
18
+ */
19
+ init(): Promise<void>;
20
+ /**
21
+ * Get wallet address - use this as user identifier
22
+ * Games should link all save data to this wallet address
23
+ * Returns null if wallet not connected
24
+ */
25
+ getWalletAddress(): Promise<string | null>;
26
+ /**
27
+ * Check if wallet is connected
28
+ */
29
+ isWalletConnected(): Promise<boolean>;
30
+ /**
31
+ * Listen for wallet connection changes
32
+ */
33
+ onWalletChange(callback: (connected: boolean, address: string | null) => void): void;
34
+ /**
35
+ * Remove wallet change listener
36
+ */
37
+ offWalletChange(callback: (connected: boolean, address: string | null) => void): void;
38
+ /**
39
+ * Payment methods
40
+ */
41
+ get payment(): {
42
+ /**
43
+ * Pay to play - one-time payment to start/access game
44
+ */
45
+ payToPlay: (amount: number, token: "SOL" | "USDC") => Promise<import("./types").PaymentResult>;
46
+ /**
47
+ * In-game purchase - buy items, upgrades, etc.
48
+ */
49
+ purchaseItem: (itemId: string, amount: number, token: "SOL" | "USDC") => Promise<import("./types").PaymentResult>;
50
+ };
51
+ /**
52
+ * Get SDK configuration
53
+ */
54
+ getConfig(): SDKConfig;
55
+ /**
56
+ * Check if SDK is running in iframe
57
+ */
58
+ isInIframe(): boolean;
59
+ /**
60
+ * Check if SDK is initialized
61
+ */
62
+ isInitialized(): boolean;
63
+ /**
64
+ * Cleanup SDK resources
65
+ */
66
+ destroy(): void;
67
+ /**
68
+ * Set up message listener for wallet updates
69
+ */
70
+ private setupMessageListener;
71
+ }
72
+ //# sourceMappingURL=sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAqC,MAAM,SAAS,CAAC;AAMvE;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,cAAc,CAAiB;IAEvC;;OAEG;gBACS,MAAM,EAAE,SAAS;IAqC7B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC3B;;;;OAIG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIhD;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAI3C;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAIpF;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAIrF;;OAEG;IACH,IAAI,OAAO;QAEP;;WAEG;4BACiB,MAAM,SAAS,KAAK,GAAG,MAAM;QAIjD;;WAEG;+BACoB,MAAM,UAAU,MAAM,SAAS,KAAK,GAAG,MAAM;MAIvE;IAED;;OAEG;IACH,SAAS,IAAI,SAAS;IAItB;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACH,OAAO,CAAC,oBAAoB;CAsB7B"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * SDK Configuration
3
+ */
4
+ export interface SDKConfig {
5
+ /** Unique game identifier */
6
+ gameId: string;
7
+ /** Optional: Parent window origin for security (defaults to '*' if not provided) */
8
+ parentOrigin?: string;
9
+ /** Optional: Request timeout in milliseconds (default: 30000) */
10
+ timeout?: number;
11
+ }
12
+ /**
13
+ * Payment result
14
+ */
15
+ export interface PaymentResult {
16
+ /** Whether payment was successful */
17
+ success: boolean;
18
+ /** Transaction signature on blockchain */
19
+ txSignature: string;
20
+ /** Amount paid by user */
21
+ amount: number;
22
+ /** Token type used for payment */
23
+ token: 'SOL' | 'USDC';
24
+ /** Timestamp when payment was completed (ISO string) */
25
+ timestamp: string;
26
+ /** Purchase ID from Arcadia database (for tracking/reference) */
27
+ purchaseId?: string;
28
+ /** Platform fee deducted (for transparency) */
29
+ platformFee?: number;
30
+ /** Amount received by developer (after platform fee) */
31
+ developerAmount?: number;
32
+ /** Optional error message if payment failed */
33
+ error?: string;
34
+ }
35
+ /**
36
+ * Wallet connection information
37
+ */
38
+ export interface WalletInfo {
39
+ /** Whether wallet is connected */
40
+ connected: boolean;
41
+ /** Wallet address (public key) or null if not connected */
42
+ address: string | null;
43
+ }
44
+ /**
45
+ * Message types for postMessage communication
46
+ */
47
+ export declare enum MessageType {
48
+ INIT_REQUEST = "INIT_REQUEST",
49
+ GET_WALLET_ADDRESS = "GET_WALLET_ADDRESS",
50
+ PAYMENT_REQUEST = "PAYMENT_REQUEST",
51
+ GAME_READY = "GAME_READY",
52
+ INIT = "INIT",
53
+ WALLET_ADDRESS_RESPONSE = "WALLET_ADDRESS_RESPONSE",
54
+ WALLET_UPDATE = "WALLET_UPDATE",
55
+ PAYMENT_RESPONSE = "PAYMENT_RESPONSE"
56
+ }
57
+ /**
58
+ * Payment request payload
59
+ */
60
+ export interface PaymentRequest {
61
+ /** Payment amount */
62
+ amount: number;
63
+ /** Token type: 'SOL' or 'USDC' */
64
+ token: 'SOL' | 'USDC';
65
+ /** Payment type */
66
+ type: 'pay_to_play' | 'in_game_purchase';
67
+ /** Game ID */
68
+ gameId: string;
69
+ /** Optional: Item ID for in-game purchases */
70
+ itemId?: string;
71
+ }
72
+ /**
73
+ * Payment response payload
74
+ */
75
+ export interface PaymentResponse {
76
+ /** Whether payment was successful */
77
+ success: boolean;
78
+ /** Transaction signature if successful */
79
+ txSignature?: string;
80
+ /** Amount paid by user */
81
+ amount?: number;
82
+ /** Token type used for payment */
83
+ token?: 'SOL' | 'USDC';
84
+ /** Timestamp when payment was completed (ISO string) */
85
+ timestamp?: string;
86
+ /** Purchase ID from Arcadia database (for tracking/reference) */
87
+ purchaseId?: string;
88
+ /** Platform fee deducted (for transparency) */
89
+ platformFee?: number;
90
+ /** Amount received by developer (after platform fee) */
91
+ developerAmount?: number;
92
+ /** Error message if failed */
93
+ error?: string;
94
+ }
95
+ /**
96
+ * Message envelope for postMessage
97
+ */
98
+ export interface Message {
99
+ /** Message type */
100
+ type: MessageType | string;
101
+ /** Unique message ID for request/response matching */
102
+ id?: number;
103
+ /** Message payload */
104
+ payload?: any;
105
+ }
106
+ /**
107
+ * Initialization data from parent
108
+ */
109
+ export interface InitData {
110
+ /** Game ID */
111
+ gameId: string;
112
+ /** User ID */
113
+ userId: string;
114
+ /** Wallet information */
115
+ wallet: WalletInfo;
116
+ }
117
+ /**
118
+ * Wallet address response
119
+ */
120
+ export interface WalletAddressResponse {
121
+ /** Wallet address or null */
122
+ walletAddress: string | null;
123
+ /** Whether wallet is connected */
124
+ connected: boolean;
125
+ }
126
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,6BAA6B;IAC7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AAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,mBAAmB;IACnB,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3B,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,cAAc;IACd,MAAM,EAAE,MAAM,CAAC;IACf,cAAc;IACd,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,6BAA6B;IAC7B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1,46 @@
1
+ import { WalletInfo } from './types';
2
+ import { MessageHandler } from './messaging';
3
+ /**
4
+ * Wallet address management
5
+ */
6
+ export declare class WalletManager {
7
+ private walletAddress;
8
+ private walletConnected;
9
+ private isIframe;
10
+ private messageHandler;
11
+ private walletChangeCallbacks;
12
+ constructor(messageHandler: MessageHandler, isIframe: boolean);
13
+ /**
14
+ * Get wallet address from parent window
15
+ */
16
+ getWalletAddress(): Promise<string | null>;
17
+ /**
18
+ * Check if wallet is connected
19
+ */
20
+ isWalletConnected(): Promise<boolean>;
21
+ /**
22
+ * Listen for wallet connection changes
23
+ */
24
+ onWalletChange(callback: (connected: boolean, address: string | null) => void): void;
25
+ /**
26
+ * Remove wallet change listener
27
+ */
28
+ offWalletChange(callback: (connected: boolean, address: string | null) => void): void;
29
+ /**
30
+ * Update wallet status (called by SDK when receiving WALLET_UPDATE message)
31
+ */
32
+ updateWalletStatus(walletInfo: WalletInfo): void;
33
+ /**
34
+ * Get current cached wallet address (without fetching)
35
+ */
36
+ getCachedWalletAddress(): string | null;
37
+ /**
38
+ * Get current cached connection status (without fetching)
39
+ */
40
+ getCachedConnectionStatus(): boolean;
41
+ /**
42
+ * Clear cached wallet data
43
+ */
44
+ clearCache(): void;
45
+ }
46
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,UAAU,EAAyB,MAAM,SAAS,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,qBAAqB,CAAmE;gBAEpF,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO;IAK7D;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsBhD;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAe3C;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAIpF;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAOrF;;OAEG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAmBhD;;OAEG;IACH,sBAAsB,IAAI,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACH,yBAAyB,IAAI,OAAO;IAIpC;;OAEG;IACH,UAAU,IAAI,IAAI;CAInB"}