@wallet-ui/react-native-web3js 2.2.0-canary-20251120223258
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/LICENSE +20 -0
- package/README.md +17 -0
- package/dist/index.browser.cjs +275 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.mjs +246 -0
- package/dist/index.browser.mjs.map +1 -0
- package/dist/index.native.mjs +246 -0
- package/dist/index.native.mjs.map +1 -0
- package/dist/index.node.cjs +275 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +246 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/mobile-wallet-adapter-provider.d.ts +18 -0
- package/dist/types/mobile-wallet-adapter-provider.d.ts.map +1 -0
- package/dist/types/use-authorization.d.ts +53 -0
- package/dist/types/use-authorization.d.ts.map +1 -0
- package/dist/types/use-mobile-wallet-adapter.d.ts +19 -0
- package/dist/types/use-mobile-wallet-adapter.d.ts.map +1 -0
- package/dist/types/use-mobile-wallet.d.ts +16 -0
- package/dist/types/use-mobile-wallet.d.ts.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import React, { createContext, useMemo, useCallback, useContext } from 'react';
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
5
|
+
import { toUint8Array } from 'js-base64';
|
|
6
|
+
export { fromUint8Array, toUint8Array } from 'js-base64';
|
|
7
|
+
import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
|
|
8
|
+
export * from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
|
|
9
|
+
export * from '@wallet-ui/core';
|
|
10
|
+
|
|
11
|
+
// src/mobile-wallet-adapter-provider.tsx
|
|
12
|
+
var MobileWalletAdapterProviderContext = createContext(
|
|
13
|
+
{}
|
|
14
|
+
);
|
|
15
|
+
function MobileWalletAdapterProvider({
|
|
16
|
+
children,
|
|
17
|
+
clusterId,
|
|
18
|
+
endpoint,
|
|
19
|
+
identity
|
|
20
|
+
}) {
|
|
21
|
+
const connection = useMemo(() => new Connection(endpoint, { commitment: "confirmed" }), [endpoint]);
|
|
22
|
+
const value = useMemo(() => ({ clusterId, connection, identity }), [connection, identity, clusterId]);
|
|
23
|
+
return /* @__PURE__ */ React.createElement(MobileWalletAdapterProviderContext.Provider, { value }, children);
|
|
24
|
+
}
|
|
25
|
+
function ellipsify(str = "", len = 4, delimiter = "..") {
|
|
26
|
+
const limit = len * 2 + delimiter.length;
|
|
27
|
+
return str.length > limit ? str.slice(0, len) + delimiter + str.slice(-len) : str;
|
|
28
|
+
}
|
|
29
|
+
function getPublicKeyFromAddress(address) {
|
|
30
|
+
const publicKeyByteArray = toUint8Array(address);
|
|
31
|
+
return new PublicKey(publicKeyByteArray);
|
|
32
|
+
}
|
|
33
|
+
function getAccountFromAuthorizedAccount(account) {
|
|
34
|
+
const publicKey = getPublicKeyFromAddress(account.address);
|
|
35
|
+
return {
|
|
36
|
+
address: account.address,
|
|
37
|
+
// TODO: Fix upstream?
|
|
38
|
+
displayAddress: account.display_address,
|
|
39
|
+
icon: account.icon,
|
|
40
|
+
label: account.label ?? ellipsify(publicKey.toString(), 8),
|
|
41
|
+
publicKey
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function getAuthorizationFromAuthorizationResult(authorizationResult, previouslySelectedAccount) {
|
|
45
|
+
let selectedAccount;
|
|
46
|
+
if (
|
|
47
|
+
// We have yet to select an account.
|
|
48
|
+
previouslySelectedAccount == null || // The previously selected account is no longer in the set of authorized addresses.
|
|
49
|
+
!authorizationResult.accounts.some(({ address }) => address === previouslySelectedAccount.address)
|
|
50
|
+
) {
|
|
51
|
+
const firstAccount = authorizationResult.accounts[0];
|
|
52
|
+
selectedAccount = getAccountFromAuthorizedAccount(firstAccount);
|
|
53
|
+
} else {
|
|
54
|
+
selectedAccount = previouslySelectedAccount;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
accounts: authorizationResult.accounts.map(getAccountFromAuthorizedAccount),
|
|
58
|
+
authToken: authorizationResult.auth_token,
|
|
59
|
+
selectedAccount
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var AUTHORIZATION_STORAGE_KEY = "authorization-cache";
|
|
63
|
+
var queryKey = ["wallet-authorization"];
|
|
64
|
+
function cacheReviver(key, value) {
|
|
65
|
+
if (key === "publicKey") {
|
|
66
|
+
return new PublicKey(value);
|
|
67
|
+
} else {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function usePersistAuthorization() {
|
|
72
|
+
const queryClient = useQueryClient();
|
|
73
|
+
return useMutation({
|
|
74
|
+
mutationFn: async (auth) => {
|
|
75
|
+
await AsyncStorage.setItem(AUTHORIZATION_STORAGE_KEY, JSON.stringify(auth));
|
|
76
|
+
},
|
|
77
|
+
onSuccess: async () => {
|
|
78
|
+
await queryClient.invalidateQueries({ queryKey });
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function useFetchAuthorization() {
|
|
83
|
+
return useQuery({
|
|
84
|
+
queryFn: async () => {
|
|
85
|
+
const cacheFetchResult = await AsyncStorage.getItem(AUTHORIZATION_STORAGE_KEY);
|
|
86
|
+
return cacheFetchResult ? JSON.parse(cacheFetchResult, cacheReviver) : null;
|
|
87
|
+
},
|
|
88
|
+
queryKey
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function useInvalidateAuthorizations() {
|
|
92
|
+
const client = useQueryClient();
|
|
93
|
+
return () => client.invalidateQueries({ queryKey });
|
|
94
|
+
}
|
|
95
|
+
function useAuthorization({ clusterId, identity }) {
|
|
96
|
+
const fetchQuery = useFetchAuthorization();
|
|
97
|
+
const invalidateAuthorizations = useInvalidateAuthorizations();
|
|
98
|
+
const persistMutation = usePersistAuthorization();
|
|
99
|
+
const handleAuthorizationResult = useCallback(
|
|
100
|
+
async (authorizationResult) => {
|
|
101
|
+
const nextAuthorization = getAuthorizationFromAuthorizationResult(
|
|
102
|
+
authorizationResult,
|
|
103
|
+
fetchQuery.data?.selectedAccount
|
|
104
|
+
);
|
|
105
|
+
await persistMutation.mutateAsync(nextAuthorization);
|
|
106
|
+
return nextAuthorization;
|
|
107
|
+
},
|
|
108
|
+
[fetchQuery.data?.selectedAccount, persistMutation]
|
|
109
|
+
);
|
|
110
|
+
const authorizeSession = useCallback(
|
|
111
|
+
async (wallet) => {
|
|
112
|
+
const authorizationResult = await wallet.authorize({
|
|
113
|
+
auth_token: fetchQuery.data?.authToken,
|
|
114
|
+
chain: clusterId,
|
|
115
|
+
identity
|
|
116
|
+
});
|
|
117
|
+
return (await handleAuthorizationResult(authorizationResult)).selectedAccount;
|
|
118
|
+
},
|
|
119
|
+
[fetchQuery.data?.authToken, clusterId, identity, handleAuthorizationResult]
|
|
120
|
+
);
|
|
121
|
+
const authorizeSessionWithSignIn = useCallback(
|
|
122
|
+
async (wallet, signInPayload) => {
|
|
123
|
+
const authorizationResult = await wallet.authorize({
|
|
124
|
+
auth_token: fetchQuery.data?.authToken,
|
|
125
|
+
chain: clusterId,
|
|
126
|
+
identity,
|
|
127
|
+
sign_in_payload: signInPayload
|
|
128
|
+
});
|
|
129
|
+
return (await handleAuthorizationResult(authorizationResult)).selectedAccount;
|
|
130
|
+
},
|
|
131
|
+
[fetchQuery.data?.authToken, clusterId, identity, handleAuthorizationResult]
|
|
132
|
+
);
|
|
133
|
+
const deauthorizeSession = useCallback(
|
|
134
|
+
async (wallet) => {
|
|
135
|
+
if (fetchQuery.data?.authToken == null) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
await wallet.deauthorize({ auth_token: fetchQuery.data.authToken });
|
|
139
|
+
await persistMutation.mutateAsync(null);
|
|
140
|
+
},
|
|
141
|
+
[fetchQuery.data?.authToken, persistMutation]
|
|
142
|
+
);
|
|
143
|
+
const deauthorizeSessions = useCallback(async () => {
|
|
144
|
+
await invalidateAuthorizations();
|
|
145
|
+
await persistMutation.mutateAsync(null);
|
|
146
|
+
}, [invalidateAuthorizations, persistMutation]);
|
|
147
|
+
return useMemo(
|
|
148
|
+
() => ({
|
|
149
|
+
accounts: fetchQuery.data?.accounts ?? null,
|
|
150
|
+
authorizeSession,
|
|
151
|
+
authorizeSessionWithSignIn,
|
|
152
|
+
deauthorizeSession,
|
|
153
|
+
deauthorizeSessions,
|
|
154
|
+
isLoading: fetchQuery.isLoading,
|
|
155
|
+
selectedAccount: fetchQuery.data?.selectedAccount ?? null
|
|
156
|
+
}),
|
|
157
|
+
[
|
|
158
|
+
authorizeSession,
|
|
159
|
+
authorizeSessionWithSignIn,
|
|
160
|
+
deauthorizeSession,
|
|
161
|
+
deauthorizeSessions,
|
|
162
|
+
fetchQuery.data?.accounts,
|
|
163
|
+
fetchQuery.data?.selectedAccount,
|
|
164
|
+
fetchQuery.isLoading
|
|
165
|
+
]
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
function useMobileWallet({ clusterId, identity }) {
|
|
169
|
+
const { authorizeSessionWithSignIn, authorizeSession, deauthorizeSessions } = useAuthorization({
|
|
170
|
+
clusterId,
|
|
171
|
+
identity
|
|
172
|
+
});
|
|
173
|
+
const connect = useCallback(
|
|
174
|
+
async () => await transact(async (wallet) => await authorizeSession(wallet)),
|
|
175
|
+
[authorizeSession]
|
|
176
|
+
);
|
|
177
|
+
const connectAnd = useCallback(
|
|
178
|
+
async (cb) => {
|
|
179
|
+
return await transact(async (wallet) => await cb(wallet));
|
|
180
|
+
},
|
|
181
|
+
[]
|
|
182
|
+
);
|
|
183
|
+
const signIn = useCallback(
|
|
184
|
+
async (signInPayload) => await transact(async (wallet) => await authorizeSessionWithSignIn(wallet, signInPayload)),
|
|
185
|
+
[authorizeSessionWithSignIn]
|
|
186
|
+
);
|
|
187
|
+
const disconnect = useCallback(async () => {
|
|
188
|
+
await deauthorizeSessions();
|
|
189
|
+
}, [deauthorizeSessions]);
|
|
190
|
+
const signAndSendTransaction = useCallback(
|
|
191
|
+
async (transaction, minContextSlot) => {
|
|
192
|
+
return await transact(async (wallet) => {
|
|
193
|
+
await authorizeSession(wallet);
|
|
194
|
+
const signatures = await wallet.signAndSendTransactions({
|
|
195
|
+
minContextSlot,
|
|
196
|
+
transactions: [transaction]
|
|
197
|
+
});
|
|
198
|
+
return signatures[0];
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
[authorizeSession]
|
|
202
|
+
);
|
|
203
|
+
const signMessage = useCallback(
|
|
204
|
+
async (message) => {
|
|
205
|
+
return await transact(async (wallet) => {
|
|
206
|
+
const authResult = await authorizeSession(wallet);
|
|
207
|
+
const signedMessages = await wallet.signMessages({
|
|
208
|
+
addresses: [authResult.address],
|
|
209
|
+
payloads: [message]
|
|
210
|
+
});
|
|
211
|
+
return signedMessages[0];
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
[authorizeSession]
|
|
215
|
+
);
|
|
216
|
+
return useMemo(
|
|
217
|
+
() => ({
|
|
218
|
+
connect,
|
|
219
|
+
connectAnd,
|
|
220
|
+
disconnect,
|
|
221
|
+
signAndSendTransaction,
|
|
222
|
+
signIn,
|
|
223
|
+
signMessage
|
|
224
|
+
}),
|
|
225
|
+
[connect, connectAnd, disconnect, signAndSendTransaction, signIn, signMessage]
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function useMobileWalletAdapter() {
|
|
229
|
+
const ctx = useContext(MobileWalletAdapterProviderContext);
|
|
230
|
+
const { connect, connectAnd, signAndSendTransaction, signMessage, signIn } = useMobileWallet(ctx);
|
|
231
|
+
const { selectedAccount, deauthorizeSessions } = useAuthorization(ctx);
|
|
232
|
+
return {
|
|
233
|
+
...ctx,
|
|
234
|
+
account: selectedAccount,
|
|
235
|
+
connect,
|
|
236
|
+
connectAnd,
|
|
237
|
+
disconnect: deauthorizeSessions,
|
|
238
|
+
signAndSendTransaction,
|
|
239
|
+
signIn,
|
|
240
|
+
signMessage
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export { MobileWalletAdapterProvider, MobileWalletAdapterProviderContext, useAuthorization, useMobileWallet, useMobileWalletAdapter };
|
|
245
|
+
//# sourceMappingURL=index.node.mjs.map
|
|
246
|
+
//# sourceMappingURL=index.node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mobile-wallet-adapter-provider.tsx","../src/use-authorization.ts","../src/use-mobile-wallet.ts","../src/use-mobile-wallet-adapter.ts"],"names":["useMemo","useCallback"],"mappings":";;;;;;;;;;;AAiBO,IAAM,kCAAA,GAAqC,aAAA;AAAA,EAC9C;AACJ;AACO,SAAS,2BAAA,CAA4B;AAAA,EACxC,QAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACJ,CAAA,EAAqC;AACjC,EAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,MAAM,IAAI,UAAA,CAAW,QAAA,EAAU,EAAE,UAAA,EAAY,WAAA,EAAa,CAAA,EAAG,CAAC,QAAQ,CAAC,CAAA;AAClG,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,OAAO,EAAE,SAAA,EAAW,UAAA,EAAY,QAAA,EAAS,CAAA,EAAI,CAAC,UAAA,EAAY,QAAA,EAAU,SAAS,CAAC,CAAA;AAEpG,EAAA,uBACI,KAAA,CAAA,aAAA,CAAC,kCAAA,CAAmC,QAAA,EAAnC,EAA4C,SACxC,QACL,CAAA;AAER;AChBA,SAAS,UAAU,GAAA,GAAM,EAAA,EAAI,GAAA,GAAM,CAAA,EAAG,YAAY,IAAA,EAAM;AACpD,EAAA,MAAM,KAAA,GAAQ,GAAA,GAAM,CAAA,GAAI,SAAA,CAAU,MAAA;AAElC,EAAA,OAAO,GAAA,CAAI,MAAA,GAAS,KAAA,G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MAAA,OAAO,MAAM,QAAA,CAAS,OAAM,MAAA,KAAU;AAClC,QAAA,MAAM,UAAA,GAAa,MAAM,gBAAA,CAAiB,MAAM,CAAA;AAChD,QAAA,MAAM,cAAA,GAAiB,MAAM,MAAA,CAAO,YAAA,CAAa;AAAA,UAC7C,SAAA,EAAW,CAAC,UAAA,CAAW,OAAO,CAAA;AAAA,UAC9B,QAAA,EAAU,CAAC,OAAO;AAAA,SACrB,CAAA;AACD,QAAA,OAAO,eAAe,CAAC,CAAA;AAAA,MAC3B,CAAC,CAAA;AAAA,IACL,CAAA;AAAA,IACA,CAAC,gBAAgB;AAAA,GACrB;AAEA,EAAA,OAAOD,OAAAA;AAAA,IACH,OAAO;AAAA,MACH,OAAA;AAAA,MACA,UAAA;AAAA,MACA,UAAA;AAAA,MACA,sBAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACJ,CAAA;AAAA,IACA,CAAC,OAAA,EAAS,UAAA,EAAY,UAAA,EAAY,sBAAA,EAAwB,QAAQ,WAAW;AAAA,GACjF;AACJ;ACxEO,SAAS,sBAAA,GAAyB;AACrC,EAAA,MAAM,GAAA,GAAM,WAAW,kCAAkC,CAAA;AACzD,EAAA,MAAM,EAAE,SAAS,UAAA,EAAY,sBAAA,EAAwB,aAAa,MAAA,EAAO,GAAI,gBAAgB,GAAG,CAAA;AAChG,EAAA,MAAM,EAAE,eAAA,EAAiB,mBAAA,EAAoB,GAAI,iBAAiB,GAAG,CAAA;AAErE,EAAA,OAAO;AAAA,IACH,GAAG,GAAA;AAAA,IACH,OAAA,EAAS,eAAA;AAAA,IACT,OAAA;AAAA,IACA,UAAA;AAAA,IACA,UAAA,EAAY,mBAAA;AAAA,IACZ,sBAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACJ;AACJ","file":"index.node.mjs","sourcesContent":["import { Connection } from '@solana/web3.js';\nimport { AppIdentity } from '@solana-mobile/mobile-wallet-adapter-protocol';\nimport { SolanaClusterId } from '@wallet-ui/core/src';\nimport React, { createContext, type ReactNode, useMemo } from 'react';\n\nexport interface MobileWalletAdapterProviderProps {\n children: ReactNode;\n clusterId: SolanaClusterId;\n endpoint: string;\n identity: AppIdentity;\n}\nexport interface MobileWalletAdapterProviderState {\n clusterId: SolanaClusterId;\n connection: Connection;\n identity: AppIdentity;\n}\n\nexport const MobileWalletAdapterProviderContext = createContext<MobileWalletAdapterProviderState>(\n {} as MobileWalletAdapterProviderState,\n);\nexport function MobileWalletAdapterProvider({\n children,\n clusterId,\n endpoint,\n identity,\n}: MobileWalletAdapterProviderProps) {\n const connection = useMemo(() => new Connection(endpoint, { commitment: 'confirmed' }), [endpoint]);\n const value = useMemo(() => ({ clusterId, connection, identity }), [connection, identity, clusterId]);\n\n return (\n <MobileWalletAdapterProviderContext.Provider value={value}>\n {children}\n </MobileWalletAdapterProviderContext.Provider>\n );\n}\n","import AsyncStorage from '@react-native-async-storage/async-storage';\nimport { PublicKey, PublicKeyInitData } from '@solana/web3.js';\nimport {\n Account as AuthorizedAccount,\n AppIdentity,\n AuthorizationResult,\n AuthorizeAPI,\n AuthToken,\n Base64EncodedAddress,\n DeauthorizeAPI,\n SignInPayload,\n} from '@solana-mobile/mobile-wallet-adapter-protocol';\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';\nimport { WalletIcon } from '@wallet-standard/core';\nimport { SolanaClusterId } from '@wallet-ui/core';\nimport { toUint8Array } from 'js-base64';\nimport { useCallback, useMemo } from 'react';\n\nfunction ellipsify(str = '', len = 4, delimiter = '..') {\n const limit = len * 2 + delimiter.length;\n\n return str.length > limit ? str.slice(0, len) + delimiter + str.slice(-len) : str;\n}\n\nexport type Account = Readonly<{\n address: Base64EncodedAddress;\n displayAddress?: string;\n icon?: WalletIcon;\n label?: string;\n publicKey: PublicKey;\n}>;\n\nexport type WalletAuthorization = Readonly<{\n accounts: Account[];\n authToken: AuthToken;\n selectedAccount: Account;\n}>;\n\nfunction getPublicKeyFromAddress(address: Base64EncodedAddress): PublicKey {\n const publicKeyByteArray = toUint8Array(address);\n return new PublicKey(publicKeyByteArray);\n}\n\nfunction getAccountFromAuthorizedAccount(account: AuthorizedAccount): Account {\n const publicKey = getPublicKeyFromAddress(account.address);\n return {\n address: account.address,\n // TODO: Fix upstream?\n displayAddress: (account as unknown as { display_address: string }).display_address,\n icon: account.icon,\n label: account.label ?? ellipsify(publicKey.toString(), 8),\n publicKey,\n };\n}\n\nfunction getAuthorizationFromAuthorizationResult(\n authorizationResult: AuthorizationResult,\n previouslySelectedAccount?: Account,\n): WalletAuthorization {\n let selectedAccount: Account;\n if (\n // We have yet to select an account.\n previouslySelectedAccount == null ||\n // The previously selected account is no longer in the set of authorized addresses.\n !authorizationResult.accounts.some(({ address }) => address === previouslySelectedAccount.address)\n ) {\n const firstAccount = authorizationResult.accounts[0];\n selectedAccount = getAccountFromAuthorizedAccount(firstAccount);\n } else {\n selectedAccount = previouslySelectedAccount;\n }\n return {\n accounts: authorizationResult.accounts.map(getAccountFromAuthorizedAccount),\n authToken: authorizationResult.auth_token,\n selectedAccount,\n };\n}\n\nconst AUTHORIZATION_STORAGE_KEY = 'authorization-cache';\n\nconst queryKey = ['wallet-authorization'];\n\nfunction cacheReviver(key: string, value: unknown) {\n if (key === 'publicKey') {\n return new PublicKey(value as PublicKeyInitData); // the PublicKeyInitData should match the actual data structure stored in AsyncStorage\n } else {\n return value;\n }\n}\nfunction usePersistAuthorization() {\n const queryClient = useQueryClient();\n return useMutation({\n mutationFn: async (auth: WalletAuthorization | null): Promise<void> => {\n await AsyncStorage.setItem(AUTHORIZATION_STORAGE_KEY, JSON.stringify(auth));\n },\n onSuccess: async () => {\n await queryClient.invalidateQueries({ queryKey });\n },\n });\n}\n\nfunction useFetchAuthorization() {\n return useQuery({\n queryFn: async (): Promise<WalletAuthorization | null> => {\n const cacheFetchResult = await AsyncStorage.getItem(AUTHORIZATION_STORAGE_KEY);\n\n // Return prior authorization, if found.\n return cacheFetchResult ? JSON.parse(cacheFetchResult, cacheReviver) : null;\n },\n queryKey,\n });\n}\n\nfunction useInvalidateAuthorizations() {\n const client = useQueryClient();\n return () => client.invalidateQueries({ queryKey });\n}\n\nexport function useAuthorization({ clusterId, identity }: { clusterId: SolanaClusterId; identity: AppIdentity }) {\n const fetchQuery = useFetchAuthorization();\n const invalidateAuthorizations = useInvalidateAuthorizations();\n const persistMutation = usePersistAuthorization();\n\n const handleAuthorizationResult = useCallback(\n async (authorizationResult: AuthorizationResult): Promise<WalletAuthorization> => {\n const nextAuthorization = getAuthorizationFromAuthorizationResult(\n authorizationResult,\n fetchQuery.data?.selectedAccount,\n );\n await persistMutation.mutateAsync(nextAuthorization);\n return nextAuthorization;\n },\n [fetchQuery.data?.selectedAccount, persistMutation],\n );\n\n const authorizeSession = useCallback(\n async (wallet: AuthorizeAPI) => {\n const authorizationResult = await wallet.authorize({\n auth_token: fetchQuery.data?.authToken,\n chain: clusterId,\n identity,\n });\n return (await handleAuthorizationResult(authorizationResult)).selectedAccount;\n },\n [fetchQuery.data?.authToken, clusterId, identity, handleAuthorizationResult],\n );\n\n const authorizeSessionWithSignIn = useCallback(\n async (wallet: AuthorizeAPI, signInPayload: SignInPayload) => {\n const authorizationResult = await wallet.authorize({\n auth_token: fetchQuery.data?.authToken,\n chain: clusterId,\n identity,\n sign_in_payload: signInPayload,\n });\n return (await handleAuthorizationResult(authorizationResult)).selectedAccount;\n },\n [fetchQuery.data?.authToken, clusterId, identity, handleAuthorizationResult],\n );\n\n const deauthorizeSession = useCallback(\n async (wallet: DeauthorizeAPI) => {\n if (fetchQuery.data?.authToken == null) {\n return;\n }\n await wallet.deauthorize({ auth_token: fetchQuery.data.authToken });\n await persistMutation.mutateAsync(null);\n },\n [fetchQuery.data?.authToken, persistMutation],\n );\n\n const deauthorizeSessions = useCallback(async () => {\n await invalidateAuthorizations();\n await persistMutation.mutateAsync(null);\n }, [invalidateAuthorizations, persistMutation]);\n\n return useMemo(\n () => ({\n accounts: fetchQuery.data?.accounts ?? null,\n authorizeSession,\n authorizeSessionWithSignIn,\n deauthorizeSession,\n deauthorizeSessions,\n isLoading: fetchQuery.isLoading,\n selectedAccount: fetchQuery.data?.selectedAccount ?? null,\n }),\n [\n authorizeSession,\n authorizeSessionWithSignIn,\n deauthorizeSession,\n deauthorizeSessions,\n fetchQuery.data?.accounts,\n fetchQuery.data?.selectedAccount,\n fetchQuery.isLoading,\n ],\n );\n}\n","import { Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';\nimport { AppIdentity, AuthorizeAPI, SignInPayload } from '@solana-mobile/mobile-wallet-adapter-protocol';\nimport { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';\nimport { SolanaClusterId } from '@wallet-ui/core';\nimport { useCallback, useMemo } from 'react';\n\nimport { Account, useAuthorization } from './use-authorization';\n\nexport function useMobileWallet({ clusterId, identity }: { clusterId: SolanaClusterId; identity: AppIdentity }) {\n const { authorizeSessionWithSignIn, authorizeSession, deauthorizeSessions } = useAuthorization({\n clusterId,\n identity,\n });\n\n const connect = useCallback(\n async (): Promise<Account> => await transact(async wallet => await authorizeSession(wallet)),\n [authorizeSession],\n );\n\n const connectAnd = useCallback(\n async (cb: (wallet: AuthorizeAPI) => Promise<Account | void>): Promise<Account | void> => {\n return await transact(async wallet => await cb(wallet));\n },\n [],\n );\n\n const signIn = useCallback(\n async (signInPayload: SignInPayload): Promise<Account> =>\n await transact(async wallet => await authorizeSessionWithSignIn(wallet, signInPayload)),\n [authorizeSessionWithSignIn],\n );\n\n const disconnect = useCallback(async (): Promise<void> => {\n await deauthorizeSessions();\n }, [deauthorizeSessions]);\n\n const signAndSendTransaction = useCallback(\n async (\n transaction: Transaction | VersionedTransaction,\n minContextSlot: number,\n ): Promise<TransactionSignature> => {\n return await transact(async wallet => {\n await authorizeSession(wallet);\n const signatures = await wallet.signAndSendTransactions({\n minContextSlot,\n transactions: [transaction],\n });\n return signatures[0];\n });\n },\n [authorizeSession],\n );\n\n const signMessage = useCallback(\n async (message: Uint8Array): Promise<Uint8Array> => {\n return await transact(async wallet => {\n const authResult = await authorizeSession(wallet);\n const signedMessages = await wallet.signMessages({\n addresses: [authResult.address],\n payloads: [message],\n });\n return signedMessages[0];\n });\n },\n [authorizeSession],\n );\n\n return useMemo(\n () => ({\n connect,\n connectAnd,\n disconnect,\n signAndSendTransaction,\n signIn,\n signMessage,\n }),\n [connect, connectAnd, disconnect, signAndSendTransaction, signIn, signMessage],\n );\n}\n","import { useContext } from 'react';\n\nimport { MobileWalletAdapterProviderContext } from './mobile-wallet-adapter-provider';\nimport { useAuthorization } from './use-authorization';\nimport { useMobileWallet } from './use-mobile-wallet';\n\nexport function useMobileWalletAdapter() {\n const ctx = useContext(MobileWalletAdapterProviderContext);\n const { connect, connectAnd, signAndSendTransaction, signMessage, signIn } = useMobileWallet(ctx);\n const { selectedAccount, deauthorizeSessions } = useAuthorization(ctx);\n\n return {\n ...ctx,\n account: selectedAccount,\n connect,\n connectAnd,\n disconnect: deauthorizeSessions,\n signAndSendTransaction,\n signIn,\n signMessage,\n };\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './mobile-wallet-adapter-provider';
|
|
2
|
+
export * from './use-authorization';
|
|
3
|
+
export * from './use-mobile-wallet';
|
|
4
|
+
export * from './use-mobile-wallet-adapter';
|
|
5
|
+
export type { AppIdentity, SignInPayload } from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
6
|
+
export * from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
|
|
7
|
+
export * from '@wallet-ui/core';
|
|
8
|
+
export { toUint8Array, fromUint8Array } from 'js-base64';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAE5C,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAChG,cAAc,sDAAsD,CAAC;AACrE,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connection } from '@solana/web3.js';
|
|
2
|
+
import { AppIdentity } from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
3
|
+
import { SolanaClusterId } from '@wallet-ui/core/src';
|
|
4
|
+
import React, { type ReactNode } from 'react';
|
|
5
|
+
export interface MobileWalletAdapterProviderProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
clusterId: SolanaClusterId;
|
|
8
|
+
endpoint: string;
|
|
9
|
+
identity: AppIdentity;
|
|
10
|
+
}
|
|
11
|
+
export interface MobileWalletAdapterProviderState {
|
|
12
|
+
clusterId: SolanaClusterId;
|
|
13
|
+
connection: Connection;
|
|
14
|
+
identity: AppIdentity;
|
|
15
|
+
}
|
|
16
|
+
export declare const MobileWalletAdapterProviderContext: React.Context<MobileWalletAdapterProviderState>;
|
|
17
|
+
export declare function MobileWalletAdapterProvider({ children, clusterId, endpoint, identity, }: MobileWalletAdapterProviderProps): React.JSX.Element;
|
|
18
|
+
//# sourceMappingURL=mobile-wallet-adapter-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mobile-wallet-adapter-provider.d.ts","sourceRoot":"","sources":["../../src/mobile-wallet-adapter-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,EAAiB,KAAK,SAAS,EAAW,MAAM,OAAO,CAAC;AAEtE,MAAM,WAAW,gCAAgC;IAC7C,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,WAAW,CAAC;CACzB;AACD,MAAM,WAAW,gCAAgC;IAC7C,SAAS,EAAE,eAAe,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,WAAW,CAAC;CACzB;AAED,eAAO,MAAM,kCAAkC,iDAE9C,CAAC;AACF,wBAAgB,2BAA2B,CAAC,EACxC,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,GACX,EAAE,gCAAgC,qBASlC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { AppIdentity, AuthorizeAPI, AuthToken, Base64EncodedAddress, DeauthorizeAPI, SignInPayload } from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
3
|
+
import { WalletIcon } from '@wallet-standard/core';
|
|
4
|
+
import { SolanaClusterId } from '@wallet-ui/core';
|
|
5
|
+
export type Account = Readonly<{
|
|
6
|
+
address: Base64EncodedAddress;
|
|
7
|
+
displayAddress?: string;
|
|
8
|
+
icon?: WalletIcon;
|
|
9
|
+
label?: string;
|
|
10
|
+
publicKey: PublicKey;
|
|
11
|
+
}>;
|
|
12
|
+
export type WalletAuthorization = Readonly<{
|
|
13
|
+
accounts: Account[];
|
|
14
|
+
authToken: AuthToken;
|
|
15
|
+
selectedAccount: Account;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function useAuthorization({ clusterId, identity }: {
|
|
18
|
+
clusterId: SolanaClusterId;
|
|
19
|
+
identity: AppIdentity;
|
|
20
|
+
}): {
|
|
21
|
+
accounts: Readonly<{
|
|
22
|
+
address: Base64EncodedAddress;
|
|
23
|
+
displayAddress?: string;
|
|
24
|
+
icon?: WalletIcon;
|
|
25
|
+
label?: string;
|
|
26
|
+
publicKey: PublicKey;
|
|
27
|
+
}>[] | null;
|
|
28
|
+
authorizeSession: (wallet: AuthorizeAPI) => Promise<Readonly<{
|
|
29
|
+
address: Base64EncodedAddress;
|
|
30
|
+
displayAddress?: string;
|
|
31
|
+
icon?: WalletIcon;
|
|
32
|
+
label?: string;
|
|
33
|
+
publicKey: PublicKey;
|
|
34
|
+
}>>;
|
|
35
|
+
authorizeSessionWithSignIn: (wallet: AuthorizeAPI, signInPayload: SignInPayload) => Promise<Readonly<{
|
|
36
|
+
address: Base64EncodedAddress;
|
|
37
|
+
displayAddress?: string;
|
|
38
|
+
icon?: WalletIcon;
|
|
39
|
+
label?: string;
|
|
40
|
+
publicKey: PublicKey;
|
|
41
|
+
}>>;
|
|
42
|
+
deauthorizeSession: (wallet: DeauthorizeAPI) => Promise<void>;
|
|
43
|
+
deauthorizeSessions: () => Promise<void>;
|
|
44
|
+
isLoading: boolean;
|
|
45
|
+
selectedAccount: Readonly<{
|
|
46
|
+
address: Base64EncodedAddress;
|
|
47
|
+
displayAddress?: string;
|
|
48
|
+
icon?: WalletIcon;
|
|
49
|
+
label?: string;
|
|
50
|
+
publicKey: PublicKey;
|
|
51
|
+
}> | null;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=use-authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-authorization.d.ts","sourceRoot":"","sources":["../../src/use-authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAEH,WAAW,EAEX,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,aAAa,EAChB,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAUlD,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC3B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;CACxB,CAAC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC;IACvC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;CAC5B,CAAC,CAAC;AAkFH,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAAE,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE;;iBA7FlG,oBAAoB;yBACZ,MAAM;eAChB,UAAU;gBACT,MAAM;mBACH,SAAS;;+BA2GD,YAAY;iBA/GtB,oBAAoB;yBACZ,MAAM;eAChB,UAAU;gBACT,MAAM;mBACH,SAAS;;yCAuHD,YAAY,iBAAiB,aAAa;iBA3HpD,oBAAoB;yBACZ,MAAM;eAChB,UAAU;gBACT,MAAM;mBACH,SAAS;;iCAoID,cAAc;;;;iBAxIxB,oBAAoB;yBACZ,MAAM;eAChB,UAAU;gBACT,MAAM;mBACH,SAAS;;EAuKvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function useMobileWalletAdapter(): {
|
|
2
|
+
account: Readonly<{
|
|
3
|
+
address: import("@solana-mobile/mobile-wallet-adapter-protocol").Base64EncodedAddress;
|
|
4
|
+
displayAddress?: string;
|
|
5
|
+
icon?: import("@wallet-standard/core").WalletIcon;
|
|
6
|
+
label?: string;
|
|
7
|
+
publicKey: import("@solana/web3.js").PublicKey;
|
|
8
|
+
}> | null;
|
|
9
|
+
connect: () => Promise<import("./use-authorization").Account>;
|
|
10
|
+
connectAnd: (cb: (wallet: import("@solana-mobile/mobile-wallet-adapter-protocol").AuthorizeAPI) => Promise<import("./use-authorization").Account | void>) => Promise<import("./use-authorization").Account | void>;
|
|
11
|
+
disconnect: () => Promise<void>;
|
|
12
|
+
signAndSendTransaction: (transaction: import("@solana/web3.js").Transaction | import("@solana/web3.js").VersionedTransaction, minContextSlot: number) => Promise<import("@solana/web3.js").TransactionSignature>;
|
|
13
|
+
signIn: (signInPayload: import("@solana-mobile/mobile-wallet-adapter-protocol").SignInPayload) => Promise<import("./use-authorization").Account>;
|
|
14
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
15
|
+
clusterId: import("@wallet-ui/core/src").SolanaClusterId;
|
|
16
|
+
connection: import("@solana/web3.js").Connection;
|
|
17
|
+
identity: import("@solana-mobile/mobile-wallet-adapter-protocol").AppIdentity;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=use-mobile-wallet-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mobile-wallet-adapter.d.ts","sourceRoot":"","sources":["../../src/use-mobile-wallet-adapter.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB;;;;;;;;;;;;;;;;;EAerC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { AppIdentity, AuthorizeAPI, SignInPayload } from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
3
|
+
import { SolanaClusterId } from '@wallet-ui/core';
|
|
4
|
+
import { Account } from './use-authorization';
|
|
5
|
+
export declare function useMobileWallet({ clusterId, identity }: {
|
|
6
|
+
clusterId: SolanaClusterId;
|
|
7
|
+
identity: AppIdentity;
|
|
8
|
+
}): {
|
|
9
|
+
connect: () => Promise<Account>;
|
|
10
|
+
connectAnd: (cb: (wallet: AuthorizeAPI) => Promise<Account | void>) => Promise<Account | void>;
|
|
11
|
+
disconnect: () => Promise<void>;
|
|
12
|
+
signAndSendTransaction: (transaction: Transaction | VersionedTransaction, minContextSlot: number) => Promise<TransactionSignature>;
|
|
13
|
+
signIn: (signInPayload: SignInPayload) => Promise<Account>;
|
|
14
|
+
signMessage: (message: Uint8Array) => Promise<Uint8Array>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=use-mobile-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-mobile-wallet.d.ts","sourceRoot":"","sources":["../../src/use-mobile-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+CAA+C,CAAC;AAEzG,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAoB,MAAM,qBAAqB,CAAC;AAEhE,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAAE,SAAS,EAAE,eAAe,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE;mBAO5F,OAAO,CAAC,OAAO,CAAC;qBAKf,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,KAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;sBAYjD,OAAO,CAAC,IAAI,CAAC;0CAMjC,WAAW,GAAG,oBAAoB,kBAC/B,MAAM,KACvB,OAAO,CAAC,oBAAoB,CAAC;4BAbV,aAAa,KAAG,OAAO,CAAC,OAAO,CAAC;2BA2BtC,UAAU,KAAG,OAAO,CAAC,UAAU,CAAC;EAwBvD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wallet-ui/react-native-web3js",
|
|
3
|
+
"version": "2.2.0-canary-20251120223258",
|
|
4
|
+
"description": "React components for Wallet UI",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"edge-light": {
|
|
8
|
+
"import": "./dist/index.node.mjs",
|
|
9
|
+
"require": "./dist/index.node.cjs"
|
|
10
|
+
},
|
|
11
|
+
"workerd": {
|
|
12
|
+
"import": "./dist/index.node.mjs",
|
|
13
|
+
"require": "./dist/index.node.cjs"
|
|
14
|
+
},
|
|
15
|
+
"browser": {
|
|
16
|
+
"import": "./dist/index.browser.mjs",
|
|
17
|
+
"require": "./dist/index.browser.cjs"
|
|
18
|
+
},
|
|
19
|
+
"node": {
|
|
20
|
+
"import": "./dist/index.node.mjs",
|
|
21
|
+
"require": "./dist/index.node.cjs"
|
|
22
|
+
},
|
|
23
|
+
"react-native": "./dist/index.native.mjs",
|
|
24
|
+
"types": "./dist/types/index.d.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"browser": {
|
|
28
|
+
"./dist/index.node.cjs": "./dist/index.browser.cjs",
|
|
29
|
+
"./dist/index.node.mjs": "./dist/index.browser.mjs"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.node.cjs",
|
|
32
|
+
"module": "./dist/index.node.mjs",
|
|
33
|
+
"react-native": "./dist/index.native.mjs",
|
|
34
|
+
"types": "./dist/types/index.d.ts",
|
|
35
|
+
"type": "commonjs",
|
|
36
|
+
"files": [
|
|
37
|
+
"./dist/"
|
|
38
|
+
],
|
|
39
|
+
"sideEffects": false,
|
|
40
|
+
"keywords": [
|
|
41
|
+
"blockchain",
|
|
42
|
+
"solana",
|
|
43
|
+
"web3"
|
|
44
|
+
],
|
|
45
|
+
"author": "beeman <beeman@beeman.nl>",
|
|
46
|
+
"homepage": "https://wallet-ui.dev",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/wallet-ui/wallet-ui"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/wallet-ui/wallet-ui/issues"
|
|
54
|
+
},
|
|
55
|
+
"browserslist": [
|
|
56
|
+
"supports bigint and not dead",
|
|
57
|
+
"maintained node versions"
|
|
58
|
+
],
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
61
|
+
"@solana-mobile/mobile-wallet-adapter-protocol": "^2.2.3",
|
|
62
|
+
"@solana-mobile/mobile-wallet-adapter-protocol-web3js": "^2.2.3",
|
|
63
|
+
"@solana/react": "3.0.3",
|
|
64
|
+
"@solana/wallet-standard-features": "1.3.0",
|
|
65
|
+
"@solana/web3.js": "^1.98.4",
|
|
66
|
+
"@tanstack/react-query": "^5.90.2",
|
|
67
|
+
"@wallet-standard/core": "1.1.1",
|
|
68
|
+
"@wallet-standard/react": "1.0.1",
|
|
69
|
+
"js-base64": "^3.7.8",
|
|
70
|
+
"@wallet-ui/core": "2.2.0-canary-20251120223258"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@solana/signers": "2.3.0",
|
|
74
|
+
"react": ">=18"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=20.18.0"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
81
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
82
|
+
"dev": "jest -c ../../node_modules/@wallet-ui/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
83
|
+
"publish-impl": "npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || (pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks && (([ \"$PUBLISH_TAG\" != \"canary\" ] && pnpm dist-tag add $npm_package_name@$npm_package_version latest) || true))",
|
|
84
|
+
"publish-packages": "pnpm prepublishOnly && pnpm publish-impl",
|
|
85
|
+
"style:fix": "pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*",
|
|
86
|
+
"test:lint": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@wallet-ui/test-config/jest-lint.config.ts --rootDir . --silent",
|
|
87
|
+
"test:prettier": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@wallet-ui/test-config/jest-prettier.config.ts --rootDir . --silent",
|
|
88
|
+
"test:treeshakability:browser": "true # agadoo dist/index.browser.mjs",
|
|
89
|
+
"test:treeshakability:native": "true # agadoo dist/index.native.mjs",
|
|
90
|
+
"test:treeshakability:node": "true # agadoo dist/index.node.mjs",
|
|
91
|
+
"test:typecheck": "tsc --noEmit",
|
|
92
|
+
"test:unit:browser": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@wallet-ui/test-config/jest-unit.config.browser.ts --rootDir . --silent",
|
|
93
|
+
"test:unit:node": "TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@wallet-ui/test-config/jest-unit.config.node.ts --rootDir . --silent"
|
|
94
|
+
}
|
|
95
|
+
}
|