@solana-mobile/mobile-wallet-adapter-protocol 2.2.1 → 2.2.2-hotfix.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/android/build.gradle +2 -2
- package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterModule.kt +100 -83
- package/lib/cjs/index.native.js +8 -0
- package/package.json +28 -16
- package/.gitignore +0 -2
- package/android/.gitignore +0 -14
- package/src/__forks__/react-native/base64Utils.ts +0 -1
- package/src/__forks__/react-native/transact.ts +0 -91
- package/src/arrayBufferToBase64String.ts +0 -10
- package/src/associationPort.ts +0 -19
- package/src/base64Utils.ts +0 -22
- package/src/createHelloReq.ts +0 -12
- package/src/createMobileWalletProxy.ts +0 -182
- package/src/createSIWSMessage.ts +0 -14
- package/src/createSequenceNumberVector.ts +0 -11
- package/src/encryptedMessage.ts +0 -60
- package/src/errors.ts +0 -101
- package/src/generateAssociationKeypair.ts +0 -10
- package/src/generateECDHKeypair.ts +0 -10
- package/src/getAssociateAndroidIntentURL.ts +0 -77
- package/src/getJWS.ts +0 -19
- package/src/getStringWithURLUnsafeBase64CharactersReplaced.ts +0 -11
- package/src/index.ts +0 -3
- package/src/jsonRpcMessage.ts +0 -38
- package/src/parseHelloRsp.ts +0 -46
- package/src/parseSessionProps.ts +0 -33
- package/src/reflectorId.ts +0 -31
- package/src/startSession.ts +0 -98
- package/src/transact.ts +0 -593
- package/src/types.ts +0 -201
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.json +0 -8
package/src/startSession.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AssociationPort, getRandomAssociationPort } from './associationPort.js';
|
|
2
|
-
import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterErrorCode } from './errors.js';
|
|
3
|
-
import getAssociateAndroidIntentURL from './getAssociateAndroidIntentURL.js';
|
|
4
|
-
|
|
5
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
6
|
-
const Browser = {
|
|
7
|
-
Firefox: 0,
|
|
8
|
-
Other: 1,
|
|
9
|
-
} as const;
|
|
10
|
-
type BrowserEnum = typeof Browser[keyof typeof Browser];
|
|
11
|
-
|
|
12
|
-
function assertUnreachable(x: never): never {
|
|
13
|
-
return x;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getBrowser(): BrowserEnum {
|
|
17
|
-
return navigator.userAgent.indexOf('Firefox/') !== -1 ? Browser.Firefox : Browser.Other;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getDetectionPromise() {
|
|
21
|
-
// Chrome and others silently fail if a custom protocol is not supported.
|
|
22
|
-
// For these, we wait to see if the browser is navigated away from in
|
|
23
|
-
// a reasonable amount of time (ie. the native wallet opened).
|
|
24
|
-
return new Promise<void>((resolve, reject) => {
|
|
25
|
-
function cleanup() {
|
|
26
|
-
clearTimeout(timeoutId);
|
|
27
|
-
window.removeEventListener('blur', handleBlur);
|
|
28
|
-
}
|
|
29
|
-
function handleBlur() {
|
|
30
|
-
cleanup();
|
|
31
|
-
resolve();
|
|
32
|
-
}
|
|
33
|
-
window.addEventListener('blur', handleBlur);
|
|
34
|
-
const timeoutId = setTimeout(() => {
|
|
35
|
-
cleanup();
|
|
36
|
-
reject();
|
|
37
|
-
}, 3000);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let _frame: HTMLIFrameElement | null = null;
|
|
42
|
-
function launchUrlThroughHiddenFrame(url: URL) {
|
|
43
|
-
if (_frame == null) {
|
|
44
|
-
_frame = document.createElement('iframe');
|
|
45
|
-
_frame.style.display = 'none';
|
|
46
|
-
document.body.appendChild(_frame);
|
|
47
|
-
}
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
-
_frame.contentWindow!.location.href = url.toString();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function launchAssociation(associationUrl: URL) {
|
|
53
|
-
if (associationUrl.protocol === 'https:') {
|
|
54
|
-
// The association URL is an Android 'App Link' or iOS 'Universal Link'.
|
|
55
|
-
// These are regular web URLs that are designed to launch an app if it
|
|
56
|
-
// is installed or load the actual target webpage if not.
|
|
57
|
-
window.location.assign(associationUrl);
|
|
58
|
-
} else {
|
|
59
|
-
// The association URL has a custom protocol (eg. `solana-wallet:`)
|
|
60
|
-
try {
|
|
61
|
-
const browser = getBrowser();
|
|
62
|
-
switch (browser) {
|
|
63
|
-
case Browser.Firefox:
|
|
64
|
-
// If a custom protocol is not supported in Firefox, it throws.
|
|
65
|
-
launchUrlThroughHiddenFrame(associationUrl);
|
|
66
|
-
// If we reached this line, it's supported.
|
|
67
|
-
break;
|
|
68
|
-
case Browser.Other: {
|
|
69
|
-
const detectionPromise = getDetectionPromise();
|
|
70
|
-
window.location.assign(associationUrl);
|
|
71
|
-
await detectionPromise;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
default:
|
|
75
|
-
assertUnreachable(browser);
|
|
76
|
-
}
|
|
77
|
-
} catch (e) {
|
|
78
|
-
throw new SolanaMobileWalletAdapterError(
|
|
79
|
-
SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
|
|
80
|
-
'Found no installed wallet that supports the mobile wallet protocol.',
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function startSession(
|
|
87
|
-
associationPublicKey: CryptoKey,
|
|
88
|
-
associationURLBase?: string,
|
|
89
|
-
): Promise<AssociationPort> {
|
|
90
|
-
const randomAssociationPort = getRandomAssociationPort();
|
|
91
|
-
const associationUrl = await getAssociateAndroidIntentURL(
|
|
92
|
-
associationPublicKey,
|
|
93
|
-
randomAssociationPort,
|
|
94
|
-
associationURLBase,
|
|
95
|
-
);
|
|
96
|
-
await launchAssociation(associationUrl);
|
|
97
|
-
return randomAssociationPort;
|
|
98
|
-
}
|