@vue-solana/core 0.4.2 → 0.5.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.
- package/README.md +12 -2
- package/dist/index.cjs +19 -17
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/ios-wallet.cjs +12 -579
- package/dist/ios-wallet.d.cts +27 -8
- package/dist/ios-wallet.d.mts +27 -8
- package/dist/ios-wallet.d.ts +27 -8
- package/dist/ios-wallet.mjs +4 -558
- package/dist/rpc.cjs +1 -4
- package/dist/rpc.mjs +1 -4
- package/dist/shared/core.8V8PLE-S.cjs +237 -0
- package/dist/shared/core.D7olTUN_.mjs +225 -0
- package/dist/shared/core.DJZldB_x.cjs +612 -0
- package/dist/shared/core.DSI7vIfT.mjs +586 -0
- package/dist/transaction.cjs +35 -0
- package/dist/transaction.d.cts +3 -2
- package/dist/transaction.d.mts +3 -2
- package/dist/transaction.d.ts +3 -2
- package/dist/transaction.mjs +35 -1
- package/dist/types.d.cts +11 -2
- package/dist/types.d.mts +11 -2
- package/dist/types.d.ts +11 -2
- package/dist/wallet-standard.cjs +13 -227
- package/dist/wallet-standard.d.cts +6 -3
- package/dist/wallet-standard.d.mts +6 -3
- package/dist/wallet-standard.d.ts +6 -3
- package/dist/wallet-standard.mjs +6 -221
- package/package.json +1 -1
package/dist/ios-wallet.d.ts
CHANGED
|
@@ -19,24 +19,43 @@ interface AdaptSolanaIosWalletOptions {
|
|
|
19
19
|
cluster?: SolanaCluster;
|
|
20
20
|
onChange?: () => void;
|
|
21
21
|
}
|
|
22
|
+
interface IosWalletDefinition {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
icon: string;
|
|
26
|
+
appUrl: string;
|
|
27
|
+
installUrl: string;
|
|
28
|
+
encryptionPublicKeyParam: string;
|
|
29
|
+
connectUrl: string;
|
|
30
|
+
signTransactionUrl?: string;
|
|
31
|
+
signAllTransactionsUrl?: string;
|
|
32
|
+
signAndSendTransactionUrl?: string;
|
|
33
|
+
}
|
|
22
34
|
type IosWalletMethod = "connect" | "signTransaction" | "signAllTransactions" | "signAndSendTransaction";
|
|
23
|
-
|
|
24
|
-
declare function adaptSolanaIosWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaIosWalletOptions): SolanaWallet;
|
|
25
|
-
declare function handleSolanaIosWalletCallback(options?: {
|
|
26
|
-
clearUrl?: boolean;
|
|
27
|
-
}): {
|
|
35
|
+
type IosWalletCallbackResult = {
|
|
28
36
|
walletId: string;
|
|
29
37
|
method: IosWalletMethod;
|
|
30
38
|
publicKey?: string;
|
|
31
39
|
signature?: string;
|
|
32
40
|
transaction?: Uint8Array;
|
|
33
41
|
transactions?: Uint8Array[];
|
|
34
|
-
}
|
|
35
|
-
|
|
42
|
+
};
|
|
43
|
+
type IosWalletInfo = SolanaWalletInfo & {
|
|
44
|
+
wallet: IosWalletDefinition;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
declare function getSolanaIosWallets(options?: GetSolanaIosWalletsOptions): SolanaWalletInfo[];
|
|
48
|
+
declare function adaptSolanaIosWallet(walletInfo: SolanaWalletInfo, options?: AdaptSolanaIosWalletOptions): SolanaWallet;
|
|
49
|
+
declare function isSolanaIosWalletInfo(walletInfo: SolanaWalletInfo): walletInfo is IosWalletInfo;
|
|
50
|
+
|
|
36
51
|
declare function isSolanaIosBrowserWalletSupported(): boolean;
|
|
37
52
|
declare function isIosBrowser(): boolean;
|
|
38
53
|
declare function getDefaultIosWalletAppIdentity(): SolanaIosWalletAppIdentity;
|
|
39
54
|
declare function getDefaultIosWalletRedirectUrl(): string;
|
|
40
55
|
|
|
56
|
+
declare function handleSolanaIosWalletCallback(options?: {
|
|
57
|
+
clearUrl?: boolean;
|
|
58
|
+
}): IosWalletCallbackResult | null;
|
|
59
|
+
|
|
41
60
|
export { adaptSolanaIosWallet, getDefaultIosWalletAppIdentity, getDefaultIosWalletRedirectUrl, getSolanaIosWallets, handleSolanaIosWalletCallback, isIosBrowser, isSolanaIosBrowserWalletSupported, isSolanaIosWalletInfo };
|
|
42
|
-
export type { AdaptSolanaIosWalletOptions, GetSolanaIosWalletsOptions, SolanaIosWalletAppIdentity };
|
|
61
|
+
export type { AdaptSolanaIosWalletOptions, GetSolanaIosWalletsOptions, IosWalletCallbackResult, IosWalletInfo, IosWalletMethod, SolanaIosWalletAppIdentity };
|
package/dist/ios-wallet.mjs
CHANGED
|
@@ -1,558 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const nacl = resolveTweetNaCl();
|
|
6
|
-
function resolveTweetNaCl() {
|
|
7
|
-
const moduleDefault = naclModule.default;
|
|
8
|
-
const globalNacl = globalThis.nacl;
|
|
9
|
-
return "box" in naclModule ? naclModule : moduleDefault ?? globalNacl;
|
|
10
|
-
}
|
|
11
|
-
const DEFAULT_IOS_WALLET_CHAINS = ["solana:mainnet", "solana:devnet"];
|
|
12
|
-
const PENDING_REQUEST_KEY = "vue-solana:ios-wallet:pending";
|
|
13
|
-
const PENDING_REQUEST_TTL_MS = 10 * 60 * 1e3;
|
|
14
|
-
const SESSION_PREFIX = "vue-solana:ios-wallet:session:";
|
|
15
|
-
const CALLBACK_PARAMS = /* @__PURE__ */ new Set([
|
|
16
|
-
"data",
|
|
17
|
-
"nonce",
|
|
18
|
-
"errorCode",
|
|
19
|
-
"errorMessage",
|
|
20
|
-
"phantom_encryption_public_key",
|
|
21
|
-
"solflare_encryption_public_key",
|
|
22
|
-
"wallet_encryption_public_key"
|
|
23
|
-
]);
|
|
24
|
-
const IOS_WALLETS = [
|
|
25
|
-
{
|
|
26
|
-
id: "phantom",
|
|
27
|
-
name: "Phantom",
|
|
28
|
-
icon: "https://phantom.app/img/phantom-logo.svg",
|
|
29
|
-
appUrl: "https://phantom.app",
|
|
30
|
-
installUrl: "https://phantom.app/download",
|
|
31
|
-
encryptionPublicKeyParam: "phantom_encryption_public_key",
|
|
32
|
-
connectUrl: "https://phantom.app/ul/v1/connect",
|
|
33
|
-
signTransactionUrl: "https://phantom.app/ul/v1/signTransaction",
|
|
34
|
-
signAllTransactionsUrl: "https://phantom.app/ul/v1/signAllTransactions"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: "solflare",
|
|
38
|
-
name: "Solflare",
|
|
39
|
-
icon: "https://solflare.com/favicon.ico",
|
|
40
|
-
appUrl: "https://solflare.com",
|
|
41
|
-
installUrl: "https://solflare.com/download",
|
|
42
|
-
encryptionPublicKeyParam: "solflare_encryption_public_key",
|
|
43
|
-
connectUrl: "https://solflare.com/ul/v1/connect",
|
|
44
|
-
signTransactionUrl: "https://solflare.com/ul/v1/signTransaction",
|
|
45
|
-
signAllTransactionsUrl: "https://solflare.com/ul/v1/signAllTransactions",
|
|
46
|
-
signAndSendTransactionUrl: "https://solflare.com/ul/v1/signAndSendTransaction"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: "backpack",
|
|
50
|
-
name: "Backpack",
|
|
51
|
-
icon: "https://backpack.app/favicon.ico",
|
|
52
|
-
appUrl: "https://backpack.app",
|
|
53
|
-
installUrl: "https://backpack.app/download",
|
|
54
|
-
encryptionPublicKeyParam: "wallet_encryption_public_key",
|
|
55
|
-
connectUrl: "https://backpack.app/ul/v1/connect",
|
|
56
|
-
signTransactionUrl: "https://backpack.app/ul/v1/signTransaction",
|
|
57
|
-
signAllTransactionsUrl: "https://backpack.app/ul/v1/signAllTransactions",
|
|
58
|
-
signAndSendTransactionUrl: "https://backpack.app/ul/v1/signAndSendTransaction"
|
|
59
|
-
}
|
|
60
|
-
];
|
|
61
|
-
function getSolanaIosWallets(options = {}) {
|
|
62
|
-
if (!isSolanaIosBrowserWalletSupported()) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
const chains = options.chains?.length ? options.chains : DEFAULT_IOS_WALLET_CHAINS;
|
|
66
|
-
const callbackUrl = options.redirectUrl ?? getDefaultIosWalletRedirectUrl();
|
|
67
|
-
return IOS_WALLETS.map((wallet) => ({
|
|
68
|
-
name: wallet.name,
|
|
69
|
-
icon: wallet.icon,
|
|
70
|
-
chains,
|
|
71
|
-
platform: "mobile",
|
|
72
|
-
source: "deep-link",
|
|
73
|
-
appUrl: wallet.appUrl,
|
|
74
|
-
installUrl: wallet.installUrl,
|
|
75
|
-
callbackUrl,
|
|
76
|
-
capabilities: {
|
|
77
|
-
connect: true,
|
|
78
|
-
signTransaction: Boolean(wallet.signTransactionUrl),
|
|
79
|
-
signAllTransactions: Boolean(wallet.signAllTransactionsUrl),
|
|
80
|
-
signAndSendTransaction: Boolean(wallet.signAndSendTransactionUrl)
|
|
81
|
-
},
|
|
82
|
-
accounts: getStoredIosWalletAccount(wallet.id, chains),
|
|
83
|
-
wallet
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
function adaptSolanaIosWallet(walletInfo, options = {}) {
|
|
87
|
-
const definition = getIosWalletDefinition(walletInfo);
|
|
88
|
-
let connecting = false;
|
|
89
|
-
let disconnecting = false;
|
|
90
|
-
let session = getStoredSession(definition.id);
|
|
91
|
-
function refreshSession() {
|
|
92
|
-
session = getStoredSession(definition.id);
|
|
93
|
-
options.onChange?.();
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
get publicKey() {
|
|
97
|
-
return session?.publicKey ? new PublicKey(session.publicKey) : null;
|
|
98
|
-
},
|
|
99
|
-
get connected() {
|
|
100
|
-
return Boolean(session?.publicKey && session.session);
|
|
101
|
-
},
|
|
102
|
-
get connecting() {
|
|
103
|
-
return connecting;
|
|
104
|
-
},
|
|
105
|
-
get disconnecting() {
|
|
106
|
-
return disconnecting;
|
|
107
|
-
},
|
|
108
|
-
async connect() {
|
|
109
|
-
const callback = handleSolanaIosWalletCallback({ clearUrl: true });
|
|
110
|
-
if (callback?.walletId === definition.id) {
|
|
111
|
-
refreshSession();
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
connecting = true;
|
|
115
|
-
options.onChange?.();
|
|
116
|
-
try {
|
|
117
|
-
launchConnect(definition, options);
|
|
118
|
-
await waitForRedirect();
|
|
119
|
-
} finally {
|
|
120
|
-
connecting = false;
|
|
121
|
-
options.onChange?.();
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
async disconnect() {
|
|
125
|
-
disconnecting = true;
|
|
126
|
-
options.onChange?.();
|
|
127
|
-
try {
|
|
128
|
-
removeStoredSession(definition.id);
|
|
129
|
-
refreshSession();
|
|
130
|
-
} finally {
|
|
131
|
-
disconnecting = false;
|
|
132
|
-
options.onChange?.();
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
signTransaction: definition.signTransactionUrl ? async (transaction) => {
|
|
136
|
-
const signedTransaction = await launchSignTransaction(definition, transaction, options);
|
|
137
|
-
return deserializeTransaction(transaction, signedTransaction);
|
|
138
|
-
} : void 0,
|
|
139
|
-
signAllTransactions: definition.signAllTransactionsUrl ? async (transactions) => {
|
|
140
|
-
const signedTransactions = await launchSignAllTransactions(
|
|
141
|
-
definition,
|
|
142
|
-
transactions,
|
|
143
|
-
options
|
|
144
|
-
);
|
|
145
|
-
if (signedTransactions.length !== transactions.length) {
|
|
146
|
-
throw new Error(
|
|
147
|
-
`iOS wallet returned ${signedTransactions.length} signed transactions for ${transactions.length} requested transactions`
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
return signedTransactions.map(
|
|
151
|
-
(transaction, index) => deserializeTransaction(transactions[index], transaction)
|
|
152
|
-
);
|
|
153
|
-
} : void 0,
|
|
154
|
-
signAndSendTransaction: definition.signAndSendTransactionUrl ? async (transaction, sendOptions) => launchSignAndSendTransaction(definition, transaction, sendOptions, options) : void 0
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function handleSolanaIosWalletCallback(options = {}) {
|
|
158
|
-
if (typeof window === "undefined") {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
const url = new URL(window.location.href);
|
|
162
|
-
if (!hasIosWalletCallbackParams(url)) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
const errorCode = url.searchParams.get("errorCode");
|
|
166
|
-
const errorMessage = url.searchParams.get("errorMessage");
|
|
167
|
-
if (errorCode || errorMessage) {
|
|
168
|
-
clearPendingRequest();
|
|
169
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
170
|
-
throw new Error(errorMessage || `iOS wallet request failed: ${errorCode}`);
|
|
171
|
-
}
|
|
172
|
-
const pending = getPendingRequest();
|
|
173
|
-
if (!pending) {
|
|
174
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
175
|
-
throw new Error("Received an iOS wallet callback without a pending request");
|
|
176
|
-
}
|
|
177
|
-
if (isPendingRequestExpired(pending)) {
|
|
178
|
-
clearPendingRequest();
|
|
179
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
180
|
-
throw new Error("Received an expired iOS wallet callback");
|
|
181
|
-
}
|
|
182
|
-
const definition = getIosWalletDefinitionById(pending.walletId);
|
|
183
|
-
const walletEncryptionPublicKey = url.searchParams.get(definition.encryptionPublicKeyParam);
|
|
184
|
-
const nonce = url.searchParams.get("nonce");
|
|
185
|
-
const data = url.searchParams.get("data");
|
|
186
|
-
if (!nonce || !data) {
|
|
187
|
-
clearPendingRequest();
|
|
188
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
189
|
-
throw new Error("Received an incomplete iOS wallet callback");
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const sharedSecret = getSharedSecret(
|
|
193
|
-
walletEncryptionPublicKey ?? getStoredSession(pending.walletId)?.walletEncryptionPublicKey,
|
|
194
|
-
pending.dappEncryptionSecretKey
|
|
195
|
-
);
|
|
196
|
-
const payload = decryptPayload(data, nonce, sharedSecret);
|
|
197
|
-
const result = createCallbackResult(pending, payload);
|
|
198
|
-
if (pending.method === "connect") {
|
|
199
|
-
if (!walletEncryptionPublicKey) {
|
|
200
|
-
throw new Error("iOS wallet connect callback did not include an encryption public key");
|
|
201
|
-
}
|
|
202
|
-
const publicKey = getPublicKeyField(payload, "public_key");
|
|
203
|
-
storeSession({
|
|
204
|
-
walletId: pending.walletId,
|
|
205
|
-
publicKey,
|
|
206
|
-
session: getStringField(payload, "session"),
|
|
207
|
-
dappEncryptionPublicKey: pending.dappEncryptionPublicKey,
|
|
208
|
-
dappEncryptionSecretKey: pending.dappEncryptionSecretKey,
|
|
209
|
-
walletEncryptionPublicKey,
|
|
210
|
-
sharedSecret: bs58.encode(sharedSecret)
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
clearPendingRequest();
|
|
214
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
215
|
-
return result;
|
|
216
|
-
} catch (cause) {
|
|
217
|
-
clearPendingRequest();
|
|
218
|
-
cleanCallbackUrl(url, options.clearUrl);
|
|
219
|
-
throw cause;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function isSolanaIosWalletInfo(walletInfo) {
|
|
223
|
-
return walletInfo.source === "deep-link" && isIosWalletDefinition(walletInfo.wallet);
|
|
224
|
-
}
|
|
225
|
-
function isSolanaIosBrowserWalletSupported() {
|
|
226
|
-
return isIosBrowser();
|
|
227
|
-
}
|
|
228
|
-
function isIosBrowser() {
|
|
229
|
-
if (typeof window === "undefined" || typeof navigator === "undefined") {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
const userAgent = navigator.userAgent;
|
|
233
|
-
const platform = navigator.platform;
|
|
234
|
-
const maxTouchPoints = navigator.maxTouchPoints ?? 0;
|
|
235
|
-
return /iPad|iPhone|iPod/i.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
|
|
236
|
-
}
|
|
237
|
-
function getDefaultIosWalletAppIdentity() {
|
|
238
|
-
if (typeof window === "undefined") {
|
|
239
|
-
return {
|
|
240
|
-
name: "Vue Solana App",
|
|
241
|
-
uri: "https://localhost"
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
name: document.title || "Vue Solana App",
|
|
246
|
-
uri: window.location.origin,
|
|
247
|
-
icon: getDocumentIconUrl()
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function getDefaultIosWalletRedirectUrl() {
|
|
251
|
-
if (typeof window === "undefined") {
|
|
252
|
-
return "https://localhost";
|
|
253
|
-
}
|
|
254
|
-
const url = new URL(window.location.href);
|
|
255
|
-
for (const param of CALLBACK_PARAMS) {
|
|
256
|
-
url.searchParams.delete(param);
|
|
257
|
-
}
|
|
258
|
-
return url.toString();
|
|
259
|
-
}
|
|
260
|
-
function launchConnect(definition, options) {
|
|
261
|
-
const keyPair = nacl.box.keyPair();
|
|
262
|
-
const pending = createPendingRequest(definition.id, "connect", keyPair, options.redirectUrl);
|
|
263
|
-
const appIdentity = options.appIdentity ?? getDefaultIosWalletAppIdentity();
|
|
264
|
-
const url = new URL(definition.connectUrl);
|
|
265
|
-
url.searchParams.set("app_url", appIdentity.uri);
|
|
266
|
-
url.searchParams.set("dapp_encryption_public_key", pending.dappEncryptionPublicKey);
|
|
267
|
-
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
268
|
-
if (options.cluster && options.cluster !== "localnet") {
|
|
269
|
-
url.searchParams.set("cluster", options.cluster);
|
|
270
|
-
}
|
|
271
|
-
storePendingRequest(pending);
|
|
272
|
-
openIosWalletUrl(url.toString());
|
|
273
|
-
}
|
|
274
|
-
async function launchSignTransaction(definition, transaction, options) {
|
|
275
|
-
const response = await launchEncryptedWalletRequest(definition, "signTransaction", options, {
|
|
276
|
-
transaction: bs58.encode(serializeTransaction(transaction))
|
|
277
|
-
});
|
|
278
|
-
if (!response.transaction) {
|
|
279
|
-
throw new Error("iOS wallet did not return a signed transaction");
|
|
280
|
-
}
|
|
281
|
-
return response.transaction;
|
|
282
|
-
}
|
|
283
|
-
async function launchSignAllTransactions(definition, transactions, options) {
|
|
284
|
-
const response = await launchEncryptedWalletRequest(definition, "signAllTransactions", options, {
|
|
285
|
-
transactions: transactions.map((transaction) => bs58.encode(serializeTransaction(transaction)))
|
|
286
|
-
});
|
|
287
|
-
if (!response.transactions) {
|
|
288
|
-
throw new Error("iOS wallet did not return signed transactions");
|
|
289
|
-
}
|
|
290
|
-
return response.transactions;
|
|
291
|
-
}
|
|
292
|
-
async function launchSignAndSendTransaction(definition, transaction, sendOptions, options) {
|
|
293
|
-
const response = await launchEncryptedWalletRequest(
|
|
294
|
-
definition,
|
|
295
|
-
"signAndSendTransaction",
|
|
296
|
-
options,
|
|
297
|
-
{
|
|
298
|
-
transaction: bs58.encode(serializeTransaction(transaction)),
|
|
299
|
-
sendOptions
|
|
300
|
-
}
|
|
301
|
-
);
|
|
302
|
-
if (!response.signature) {
|
|
303
|
-
throw new Error("iOS wallet did not return a transaction signature");
|
|
304
|
-
}
|
|
305
|
-
return { signature: response.signature };
|
|
306
|
-
}
|
|
307
|
-
async function launchEncryptedWalletRequest(definition, method, options, payload) {
|
|
308
|
-
const session = getStoredSession(definition.id);
|
|
309
|
-
if (!session) {
|
|
310
|
-
throw new Error("Connect the iOS wallet before signing");
|
|
311
|
-
}
|
|
312
|
-
const methodUrl = getIosWalletMethodUrl(definition, method);
|
|
313
|
-
const pending = createPendingRequest(
|
|
314
|
-
definition.id,
|
|
315
|
-
method,
|
|
316
|
-
{
|
|
317
|
-
publicKey: bs58.decode(session.dappEncryptionPublicKey),
|
|
318
|
-
secretKey: bs58.decode(session.dappEncryptionSecretKey)
|
|
319
|
-
},
|
|
320
|
-
options.redirectUrl,
|
|
321
|
-
method === "signAllTransactions" && Array.isArray(payload.transactions) ? payload.transactions.length : void 0
|
|
322
|
-
);
|
|
323
|
-
const nonce = nacl.randomBytes(nacl.box.nonceLength);
|
|
324
|
-
const encryptedPayload = encryptPayload(
|
|
325
|
-
{ ...payload, session: session.session },
|
|
326
|
-
nonce,
|
|
327
|
-
bs58.decode(session.sharedSecret)
|
|
328
|
-
);
|
|
329
|
-
const url = new URL(methodUrl);
|
|
330
|
-
url.searchParams.set("dapp_encryption_public_key", session.dappEncryptionPublicKey);
|
|
331
|
-
url.searchParams.set("nonce", bs58.encode(nonce));
|
|
332
|
-
url.searchParams.set("redirect_link", pending.redirectUrl);
|
|
333
|
-
url.searchParams.set("payload", encryptedPayload);
|
|
334
|
-
storePendingRequest(pending);
|
|
335
|
-
openIosWalletUrl(url.toString());
|
|
336
|
-
return waitForRedirect();
|
|
337
|
-
}
|
|
338
|
-
function createPendingRequest(walletId, method, keyPair, redirectUrl, requestedTransactionCount) {
|
|
339
|
-
return {
|
|
340
|
-
id: createRequestId(),
|
|
341
|
-
walletId,
|
|
342
|
-
method,
|
|
343
|
-
dappEncryptionPublicKey: bs58.encode(keyPair.publicKey),
|
|
344
|
-
dappEncryptionSecretKey: bs58.encode(keyPair.secretKey),
|
|
345
|
-
redirectUrl: redirectUrl ?? getDefaultIosWalletRedirectUrl(),
|
|
346
|
-
createdAt: Date.now(),
|
|
347
|
-
requestedTransactionCount
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
function createCallbackResult(pending, payload) {
|
|
351
|
-
if (pending.method === "connect") {
|
|
352
|
-
return {
|
|
353
|
-
walletId: pending.walletId,
|
|
354
|
-
method: pending.method,
|
|
355
|
-
publicKey: getPublicKeyField(payload, "public_key")
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
if (pending.method === "signTransaction") {
|
|
359
|
-
return {
|
|
360
|
-
walletId: pending.walletId,
|
|
361
|
-
method: pending.method,
|
|
362
|
-
transaction: bs58.decode(getStringField(payload, "transaction"))
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
if (pending.method === "signAllTransactions") {
|
|
366
|
-
const transactions = payload.transactions;
|
|
367
|
-
if (!Array.isArray(transactions) || transactions.some((transaction) => typeof transaction !== "string")) {
|
|
368
|
-
throw new Error("iOS wallet returned invalid signed transactions");
|
|
369
|
-
}
|
|
370
|
-
if (typeof pending.requestedTransactionCount === "number" && transactions.length !== pending.requestedTransactionCount) {
|
|
371
|
-
throw new Error(
|
|
372
|
-
`iOS wallet returned ${transactions.length} signed transactions for ${pending.requestedTransactionCount} requested transactions`
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
return {
|
|
376
|
-
walletId: pending.walletId,
|
|
377
|
-
method: pending.method,
|
|
378
|
-
transactions: transactions.map((transaction) => bs58.decode(transaction))
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
walletId: pending.walletId,
|
|
383
|
-
method: pending.method,
|
|
384
|
-
signature: getStringField(payload, "signature")
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function getIosWalletMethodUrl(definition, method) {
|
|
388
|
-
const url = definition[`${method}Url`];
|
|
389
|
-
if (!url) {
|
|
390
|
-
throw new Error(`${definition.name} does not support ${method} through iOS deeplinks`);
|
|
391
|
-
}
|
|
392
|
-
return url;
|
|
393
|
-
}
|
|
394
|
-
function getSharedSecret(walletEncryptionPublicKey, dappSecretKey) {
|
|
395
|
-
if (!walletEncryptionPublicKey) {
|
|
396
|
-
throw new Error("Missing iOS wallet encryption public key");
|
|
397
|
-
}
|
|
398
|
-
return nacl.box.before(bs58.decode(walletEncryptionPublicKey), bs58.decode(dappSecretKey));
|
|
399
|
-
}
|
|
400
|
-
function encryptPayload(payload, nonce, sharedSecret) {
|
|
401
|
-
return bs58.encode(nacl.box.after(encodeJson(payload), nonce, sharedSecret));
|
|
402
|
-
}
|
|
403
|
-
function decryptPayload(data, nonce, sharedSecret) {
|
|
404
|
-
const decrypted = nacl.box.open.after(bs58.decode(data), bs58.decode(nonce), sharedSecret);
|
|
405
|
-
if (!decrypted) {
|
|
406
|
-
throw new Error("Unable to decrypt iOS wallet callback");
|
|
407
|
-
}
|
|
408
|
-
return JSON.parse(new TextDecoder().decode(decrypted));
|
|
409
|
-
}
|
|
410
|
-
function encodeJson(value) {
|
|
411
|
-
return new TextEncoder().encode(JSON.stringify(value));
|
|
412
|
-
}
|
|
413
|
-
function serializeTransaction(transaction) {
|
|
414
|
-
if (transaction instanceof Transaction) {
|
|
415
|
-
return transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
|
|
416
|
-
}
|
|
417
|
-
return transaction.serialize();
|
|
418
|
-
}
|
|
419
|
-
function deserializeTransaction(source, bytes) {
|
|
420
|
-
if (source instanceof Transaction) {
|
|
421
|
-
return Transaction.from(bytes);
|
|
422
|
-
}
|
|
423
|
-
return VersionedTransaction.deserialize(bytes);
|
|
424
|
-
}
|
|
425
|
-
function getStoredIosWalletAccount(walletId, chains) {
|
|
426
|
-
const session = getStoredSession(walletId);
|
|
427
|
-
if (!session) {
|
|
428
|
-
return [];
|
|
429
|
-
}
|
|
430
|
-
return [
|
|
431
|
-
{
|
|
432
|
-
address: session.publicKey,
|
|
433
|
-
publicKey: new PublicKey(session.publicKey).toBytes(),
|
|
434
|
-
chains
|
|
435
|
-
}
|
|
436
|
-
];
|
|
437
|
-
}
|
|
438
|
-
function getStoredSession(walletId) {
|
|
439
|
-
const value = getStorage()?.getItem(`${SESSION_PREFIX}${walletId}`);
|
|
440
|
-
if (!value) {
|
|
441
|
-
return null;
|
|
442
|
-
}
|
|
443
|
-
try {
|
|
444
|
-
const session = JSON.parse(value);
|
|
445
|
-
new PublicKey(session.publicKey);
|
|
446
|
-
return session;
|
|
447
|
-
} catch {
|
|
448
|
-
removeStoredSession(walletId);
|
|
449
|
-
return null;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
function storeSession(session) {
|
|
453
|
-
getStorage()?.setItem(`${SESSION_PREFIX}${session.walletId}`, JSON.stringify(session));
|
|
454
|
-
}
|
|
455
|
-
function removeStoredSession(walletId) {
|
|
456
|
-
getStorage()?.removeItem(`${SESSION_PREFIX}${walletId}`);
|
|
457
|
-
}
|
|
458
|
-
function getPendingRequest() {
|
|
459
|
-
const value = getStorage()?.getItem(PENDING_REQUEST_KEY);
|
|
460
|
-
if (!value) {
|
|
461
|
-
return null;
|
|
462
|
-
}
|
|
463
|
-
try {
|
|
464
|
-
return JSON.parse(value);
|
|
465
|
-
} catch {
|
|
466
|
-
clearPendingRequest();
|
|
467
|
-
return null;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function storePendingRequest(request) {
|
|
471
|
-
getStorage()?.setItem(PENDING_REQUEST_KEY, JSON.stringify(request));
|
|
472
|
-
}
|
|
473
|
-
function clearPendingRequest() {
|
|
474
|
-
getStorage()?.removeItem(PENDING_REQUEST_KEY);
|
|
475
|
-
}
|
|
476
|
-
function getStorage() {
|
|
477
|
-
if (typeof window === "undefined") {
|
|
478
|
-
return null;
|
|
479
|
-
}
|
|
480
|
-
try {
|
|
481
|
-
return window.sessionStorage;
|
|
482
|
-
} catch {
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function openIosWalletUrl(url) {
|
|
487
|
-
if (typeof window === "undefined") {
|
|
488
|
-
throw new Error("iOS wallet links are only available in browser runtimes");
|
|
489
|
-
}
|
|
490
|
-
window.location.assign(url);
|
|
491
|
-
}
|
|
492
|
-
function waitForRedirect() {
|
|
493
|
-
return new Promise(() => {
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
function hasIosWalletCallbackParams(url) {
|
|
497
|
-
for (const param of CALLBACK_PARAMS) {
|
|
498
|
-
if (url.searchParams.has(param)) {
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
function cleanCallbackUrl(url, clearUrl) {
|
|
505
|
-
if (!clearUrl || typeof window === "undefined") {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
for (const param of CALLBACK_PARAMS) {
|
|
509
|
-
url.searchParams.delete(param);
|
|
510
|
-
}
|
|
511
|
-
window.history.replaceState(window.history.state, document.title, url.toString());
|
|
512
|
-
}
|
|
513
|
-
function createRequestId() {
|
|
514
|
-
return bs58.encode(nacl.randomBytes(16));
|
|
515
|
-
}
|
|
516
|
-
function getStringField(payload, field) {
|
|
517
|
-
const value = payload[field];
|
|
518
|
-
if (typeof value !== "string" || !value) {
|
|
519
|
-
throw new Error(`iOS wallet callback is missing ${field}`);
|
|
520
|
-
}
|
|
521
|
-
return value;
|
|
522
|
-
}
|
|
523
|
-
function getPublicKeyField(payload, field) {
|
|
524
|
-
const value = getStringField(payload, field);
|
|
525
|
-
try {
|
|
526
|
-
new PublicKey(value);
|
|
527
|
-
} catch {
|
|
528
|
-
throw new Error(`iOS wallet callback returned an invalid ${field}`);
|
|
529
|
-
}
|
|
530
|
-
return value;
|
|
531
|
-
}
|
|
532
|
-
function isPendingRequestExpired(request) {
|
|
533
|
-
return Date.now() - request.createdAt > PENDING_REQUEST_TTL_MS;
|
|
534
|
-
}
|
|
535
|
-
function getIosWalletDefinition(walletInfo) {
|
|
536
|
-
if (!isIosWalletDefinition(walletInfo.wallet)) {
|
|
537
|
-
throw new Error("Solana wallet info is not an iOS wallet");
|
|
538
|
-
}
|
|
539
|
-
return walletInfo.wallet;
|
|
540
|
-
}
|
|
541
|
-
function getIosWalletDefinitionById(walletId) {
|
|
542
|
-
const definition = IOS_WALLETS.find((wallet) => wallet.id === walletId);
|
|
543
|
-
if (!definition) {
|
|
544
|
-
throw new Error(`Unknown iOS wallet: ${walletId}`);
|
|
545
|
-
}
|
|
546
|
-
return definition;
|
|
547
|
-
}
|
|
548
|
-
function isIosWalletDefinition(value) {
|
|
549
|
-
return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" && IOS_WALLETS.some((wallet) => wallet.id === value.id);
|
|
550
|
-
}
|
|
551
|
-
function getDocumentIconUrl() {
|
|
552
|
-
const icon = document.querySelector(
|
|
553
|
-
'link[rel="icon"], link[rel="shortcut icon"], link[rel="apple-touch-icon"]'
|
|
554
|
-
);
|
|
555
|
-
return icon?.href;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
export { adaptSolanaIosWallet, getDefaultIosWalletAppIdentity, getDefaultIosWalletRedirectUrl, getSolanaIosWallets, handleSolanaIosWalletCallback, isIosBrowser, isSolanaIosBrowserWalletSupported, isSolanaIosWalletInfo };
|
|
1
|
+
export { a as adaptSolanaIosWallet, g as getDefaultIosWalletAppIdentity, b as getDefaultIosWalletRedirectUrl, c as getSolanaIosWallets, h as handleSolanaIosWalletCallback, i as isIosBrowser, d as isSolanaIosBrowserWalletSupported, e as isSolanaIosWalletInfo } from './shared/core.DSI7vIfT.mjs';
|
|
2
|
+
import '@solana/web3-compat';
|
|
3
|
+
import 'bs58';
|
|
4
|
+
import 'tweetnacl';
|
package/dist/rpc.cjs
CHANGED
package/dist/rpc.mjs
CHANGED