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