1+ using System . Threading . Tasks ;
2+ using UnityEngine ;
3+ using System . Runtime . InteropServices ;
4+
5+
6+ public class ParticleAuth : MonoBehaviour {
7+
8+ [ DllImport ( "__Internal" ) ]
9+ private static extern void InitParticleAuth ( string options ) ;
10+
11+ [ DllImport ( "__Internal" ) ]
12+ private static extern void SetParticleLanguage ( string language ) ;
13+
14+ [ DllImport ( "__Internal" ) ]
15+ private static extern void SetParticleFiatCoin ( string fiatCoin ) ;
16+
17+ [ DllImport ( "__Internal" ) ]
18+ private static extern void SetParticleAuthTheme ( string options ) ;
19+
20+ [ DllImport ( "__Internal" ) ]
21+ private static extern void LoginWithParticle ( string options ) ;
22+
23+ [ DllImport ( "__Internal" ) ]
24+ private static extern void LogoutParticle ( ) ;
25+
26+ [ DllImport ( "__Internal" ) ]
27+ private static extern int IsParticleLoggedIn ( ) ;
28+
29+ [ DllImport ( "__Internal" ) ]
30+ private static extern string GetParticleUserInfo ( ) ;
31+
32+ [ DllImport ( "__Internal" ) ]
33+ private static extern void OpenParticleAccountAndSecurity ( ) ;
34+
35+ [ DllImport ( "__Internal" ) ]
36+ private static extern void GetParticleSecurityAccount ( ) ;
37+
38+ [ DllImport ( "__Internal" ) ]
39+ private static extern void OpenParticleWallet ( ) ;
40+
41+ [ DllImport ( "__Internal" ) ]
42+ private static extern void OpenParticleBuy ( string options ) ;
43+
44+ [ DllImport ( "__Internal" ) ]
45+ private static extern string GetParticleWalletAddress ( ) ;
46+
47+ [ DllImport ( "__Internal" ) ]
48+ private static extern void ParticleSwitchChain ( string options ) ;
49+
50+ [ DllImport ( "__Internal" ) ]
51+ private static extern void ParticleEVMSendTransaction ( string options ) ;
52+
53+ [ DllImport ( "__Internal" ) ]
54+ private static extern void ParticleEVMPersonalSign ( string options ) ;
55+
56+ [ DllImport ( "__Internal" ) ]
57+ private static extern void ParticleEVMPersonalSignUniq ( string options ) ;
58+
59+ [ DllImport ( "__Internal" ) ]
60+ private static extern void ParticleEVMSignTypedData ( string options ) ;
61+
62+ [ DllImport ( "__Internal" ) ]
63+ private static extern void ParticleEVMSignTypedDataUniq ( string options ) ;
64+
65+ [ DllImport ( "__Internal" ) ]
66+ private static extern void ParticleSolanaSignAndSendTransaction ( string options ) ;
67+
68+ [ DllImport ( "__Internal" ) ]
69+ private static extern void ParticleSolanasSignMessage ( string options ) ;
70+
71+ public static ParticleAuth Instance ;
72+
73+ public string config ;
74+
75+
76+ private TaskCompletionSource < string > loginTask ;
77+ private TaskCompletionSource < bool > logoutTask ;
78+ private TaskCompletionSource < string > getSecurityAccountTask ;
79+ private TaskCompletionSource < string > switchChainTask ;
80+ private TaskCompletionSource < string > evmSendTransactionTask ;
81+ private TaskCompletionSource < string > evmPersonalSignTask ;
82+ private TaskCompletionSource < string > evmPersonalSignUniqTask ;
83+ private TaskCompletionSource < string > evmSignTypedDataTask ;
84+ private TaskCompletionSource < string > evmSignTypedDataUniqTask ;
85+ private TaskCompletionSource < string > solanaSignAndSendTransactionTask ;
86+ private TaskCompletionSource < string > solanasSignMessageTask ;
87+
88+
89+
90+ void Awake ( ) {
91+ Instance = this ;
92+ // replace xxxx with particle project config
93+ // {"projectId":"34c6b829-5b89-44e8-90a9-6d982787b9c9","clientKey":"c6Z44Ml4TQeNhctvwYgdSv6DBzfjf6t6CB0JDscR","appId":"64f36641-b68c-4b19-aa10-5c5304d0eab3","chainName":"Ethereum","chainId":1}'
94+ InitParticleAuth ( config ) ;
95+ }
96+
97+ void OnDestroy ( ) {
98+ Instance = null ;
99+ }
100+
101+ public void SetLanguage ( string language ) {
102+ SetParticleLanguage ( language ) ;
103+ }
104+
105+ public void SetFiatCoin ( string fiatCoin ) {
106+ SetParticleFiatCoin ( fiatCoin ) ;
107+ }
108+
109+ public void SetAuthTheme ( string options ) {
110+ SetParticleAuthTheme ( options ) ;
111+ }
112+
113+ public Task < string > Login ( string options ) {
114+ loginTask = new TaskCompletionSource < string > ( ) ;
115+ LoginWithParticle ( options ) ;
116+ return loginTask . Task ;
117+ }
118+
119+ // Called from browser
120+ public void OnLogin ( string json ) {
121+ loginTask ? . TrySetResult ( json ) ;
122+ }
123+
124+ public Task < bool > Logout ( ) {
125+ logoutTask = new TaskCompletionSource < bool > ( ) ;
126+ LogoutParticle ( ) ;
127+ return logoutTask . Task ;
128+ }
129+
130+ // Called from browser
131+ public void OnLogout ( ) {
132+ logoutTask ? . TrySetResult ( true ) ;
133+ }
134+
135+ public bool IsLoggedIn ( ) {
136+ return IsParticleLoggedIn ( ) == 1 ;
137+ }
138+
139+ public string GetUserInfo ( ) {
140+ return GetParticleUserInfo ( ) ;
141+ }
142+
143+ public void OpenAccountAndSecurity ( ) {
144+ OpenParticleAccountAndSecurity ( ) ;
145+ }
146+
147+ public Task < string > GetSecurityAccount ( ) {
148+ getSecurityAccountTask = new TaskCompletionSource < string > ( ) ;
149+ GetParticleSecurityAccount ( ) ;
150+ return getSecurityAccountTask . Task ;
151+ }
152+
153+ public void OnGetSecurityAccount ( string json ) {
154+ getSecurityAccountTask ? . TrySetResult ( json ) ;
155+ }
156+
157+ public void OpenWallet ( ) {
158+ OpenParticleWallet ( ) ;
159+ }
160+
161+ public void OpenBuy ( string options ) {
162+ OpenParticleBuy ( options ) ;
163+ }
164+
165+ public string GetWalletAddress ( ) {
166+ return GetParticleWalletAddress ( ) ;
167+ }
168+
169+ public Task < string > SwitchChain ( string options ) {
170+ switchChainTask = new TaskCompletionSource < string > ( ) ;
171+ ParticleSwitchChain ( options ) ;
172+ return switchChainTask . Task ;
173+ }
174+
175+ public void OnSwitchChain ( string json ) {
176+ switchChainTask ? . TrySetResult ( json ) ;
177+ }
178+
179+ public Task < string > EVMSendTransaction ( string options ) {
180+ evmSendTransactionTask = new TaskCompletionSource < string > ( ) ;
181+ ParticleEVMSendTransaction ( options ) ;
182+ return evmSendTransactionTask . Task ;
183+ }
184+
185+ public void OnEVMSendTransaction ( string json ) {
186+ evmSendTransactionTask ? . TrySetResult ( json ) ;
187+ }
188+
189+ public Task < string > EVMPersonalSign ( string options ) {
190+ evmPersonalSignTask = new TaskCompletionSource < string > ( ) ;
191+ ParticleEVMPersonalSign ( options ) ;
192+ return evmPersonalSignTask . Task ;
193+ }
194+
195+ public void OnEVMPersonalSign ( string json ) {
196+ evmPersonalSignTask ? . TrySetResult ( json ) ;
197+ }
198+
199+ public Task < string > EVMPersonalSignUniq ( string options ) {
200+ evmPersonalSignUniqTask = new TaskCompletionSource < string > ( ) ;
201+ ParticleEVMPersonalSignUniq ( options ) ;
202+ return evmPersonalSignUniqTask . Task ;
203+ }
204+
205+ public void OnEVMPersonalSignUniq ( string json ) {
206+ evmPersonalSignUniqTask ? . TrySetResult ( json ) ;
207+ }
208+
209+ public Task < string > EVMSignTypedData ( string options ) {
210+ evmSignTypedDataTask = new TaskCompletionSource < string > ( ) ;
211+ ParticleEVMSignTypedData ( options ) ;
212+ return evmSignTypedDataTask . Task ;
213+ }
214+
215+ public void OnEVMSignTypedData ( string json ) {
216+ evmSignTypedDataTask ? . TrySetResult ( json ) ;
217+ }
218+
219+ public Task < string > EVMSignTypedDataUniq ( string options ) {
220+ evmSignTypedDataUniqTask = new TaskCompletionSource < string > ( ) ;
221+ ParticleEVMSignTypedDataUniq ( options ) ;
222+ return evmSignTypedDataUniqTask . Task ;
223+ }
224+
225+ public void OnEVMSignTypedDataUniq ( string json ) {
226+ evmSignTypedDataUniqTask ? . TrySetResult ( json ) ;
227+ }
228+
229+ public Task < string > SolanaSignAndSendTransaction ( string options ) {
230+ solanaSignAndSendTransactionTask = new TaskCompletionSource < string > ( ) ;
231+ ParticleSolanaSignAndSendTransaction ( options ) ;
232+ return solanaSignAndSendTransactionTask . Task ;
233+ }
234+
235+ public void OnSolanaSignAndSendTransaction ( string json ) {
236+ solanaSignAndSendTransactionTask ? . TrySetResult ( json ) ;
237+ }
238+
239+ public Task < string > SolanasSignMessage ( string options ) {
240+ solanasSignMessageTask = new TaskCompletionSource < string > ( ) ;
241+ ParticleSolanasSignMessage ( options ) ;
242+ return solanasSignMessageTask . Task ;
243+ }
244+
245+ public void OnSolanasSignMessage ( string json ) {
246+ solanasSignMessageTask ? . TrySetResult ( json ) ;
247+ }
248+ }
0 commit comments