@solana-mobile/mobile-wallet-adapter-protocol 2.1.5 → 2.1.6
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/.DS_Store +0 -0
- package/.gitignore +2 -0
- package/README.md +69 -69
- package/android/.gitignore +14 -0
- package/android/build.gradle +2 -2
- package/lib/cjs/index.browser.js +249 -184
- package/lib/cjs/index.js +249 -184
- package/lib/cjs/index.native.js +8 -0
- package/lib/esm/index.browser.js +249 -184
- package/lib/esm/index.js +249 -184
- package/lib/types/index.browser.d.ts +10 -4
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.ts +10 -4
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +10 -4
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/__forks__/react-native/base64Utils.ts +1 -0
- package/src/__forks__/react-native/transact.ts +91 -0
- package/src/arrayBufferToBase64String.ts +10 -0
- package/src/associationPort.ts +19 -0
- package/src/base64Utils.ts +22 -0
- package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +13 -0
- package/src/createHelloReq.ts +12 -0
- package/src/createMobileWalletProxy.ts +182 -0
- package/src/createSIWSMessage.ts +14 -0
- package/src/createSequenceNumberVector.ts +11 -0
- package/src/encryptedMessage.ts +60 -0
- package/src/errors.ts +101 -0
- package/src/generateAssociationKeypair.ts +10 -0
- package/src/generateECDHKeypair.ts +10 -0
- package/src/getAssociateAndroidIntentURL.ts +77 -0
- package/src/getJWS.ts +19 -0
- package/src/getStringWithURLUnsafeBase64CharactersReplaced.ts +11 -0
- package/src/index.ts +3 -0
- package/src/jsonRpcMessage.ts +38 -0
- package/src/parseHelloRsp.ts +46 -0
- package/src/parseSessionProps.ts +33 -0
- package/src/reflectorId.ts +31 -0
- package/src/startSession.ts +98 -0
- package/src/transact.ts +593 -0
- package/src/types.ts +201 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +8 -0
package/.DS_Store
ADDED
|
Binary file
|
package/.gitignore
ADDED
package/README.md
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
# `@solana-mobile/mobile-wallet-adapter-protocol`
|
|
2
|
-
|
|
3
|
-
This is a reference implementation of the [Mobile Wallet Adapter specification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md) in JavaScript. Use this to start a session with a mobile wallet in which you can issue API calls to it (eg. `sign_messages`) as per the spec.
|
|
4
|
-
|
|
5
|
-
If you are simply looking to integrate a JavaScript application with mobile wallets, see [`@solana-mobile/wallet-adapter-mobile`](https://www.npmjs.com/package/@solana-mobile/wallet-adapter-mobile) instead.
|
|
6
|
-
|
|
7
|
-
## Learn how to use this API on our [documentation website](https://docs.solanamobile.com/):
|
|
8
|
-
- React Native
|
|
9
|
-
- [Quickstart Setup](https://docs.solanamobile.com/react-native/quickstart)
|
|
10
|
-
- [dApp Integration Guide](https://docs.solanamobile.com/react-native/mwa_integration_rn)
|
|
11
|
-
- [Hello World Tutorial](https://docs.solanamobile.com/getting-started/hello_world_tutorial)
|
|
12
|
-
- [Sample App Reference](https://docs.solanamobile.com/sample-apps/sample_app_overview)
|
|
13
|
-
|
|
14
|
-
## Quick start
|
|
15
|
-
|
|
16
|
-
Use this API to start a session:
|
|
17
|
-
|
|
18
|
-
```typescript
|
|
19
|
-
import {transact} from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
20
|
-
|
|
21
|
-
await transact(async (wallet) => {
|
|
22
|
-
/* ... */
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
The callback you provide will be called once a session has been established with a wallet. It will recieve the `MobileWallet` API as an argument. You can call protocol-specified methods using this function. Whatever you return from this callback will be returned by `transact`.
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
const signedPayloads = await transact(async (wallet) => {
|
|
30
|
-
const {signed_payloads} = await wallet.signMessages({
|
|
31
|
-
auth_token,
|
|
32
|
-
payloads: [/* ... */],
|
|
33
|
-
});
|
|
34
|
-
return signed_payloads;
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
The wallet session will stay active until your callback returns. Typically, wallets will redirect back to your app once the session ends.
|
|
39
|
-
|
|
40
|
-
## Exception handling
|
|
41
|
-
|
|
42
|
-
You can catch exceptions at any level. See `errors.ts` for a list of exceptions that might be thrown.
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
try {
|
|
46
|
-
await transact(async (wallet) => {
|
|
47
|
-
try {
|
|
48
|
-
await wallet.signTransactions(/* ... */);
|
|
49
|
-
} catch (e) {
|
|
50
|
-
if (
|
|
51
|
-
e instanceof SolanaMobileWalletAdapterProtocolError &&
|
|
52
|
-
e.code === SolanaMobileWalletAdapterProtocolErrorCode.ERROR_REAUTHORIZE
|
|
53
|
-
) {
|
|
54
|
-
console.error('The auth token has gone stale');
|
|
55
|
-
await wallet.reauthorize({auth_token, identity});
|
|
56
|
-
// Retry...
|
|
57
|
-
}
|
|
58
|
-
throw e;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
} catch(e) {
|
|
62
|
-
if (
|
|
63
|
-
e instanceof SolanaMobileWalletAdapterError &&
|
|
64
|
-
e.code === SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND
|
|
65
|
-
) {
|
|
66
|
-
/* ... */
|
|
67
|
-
}
|
|
68
|
-
throw e;
|
|
69
|
-
}
|
|
1
|
+
# `@solana-mobile/mobile-wallet-adapter-protocol`
|
|
2
|
+
|
|
3
|
+
This is a reference implementation of the [Mobile Wallet Adapter specification](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md) in JavaScript. Use this to start a session with a mobile wallet in which you can issue API calls to it (eg. `sign_messages`) as per the spec.
|
|
4
|
+
|
|
5
|
+
If you are simply looking to integrate a JavaScript application with mobile wallets, see [`@solana-mobile/wallet-adapter-mobile`](https://www.npmjs.com/package/@solana-mobile/wallet-adapter-mobile) instead.
|
|
6
|
+
|
|
7
|
+
## Learn how to use this API on our [documentation website](https://docs.solanamobile.com/):
|
|
8
|
+
- React Native
|
|
9
|
+
- [Quickstart Setup](https://docs.solanamobile.com/react-native/quickstart)
|
|
10
|
+
- [dApp Integration Guide](https://docs.solanamobile.com/react-native/mwa_integration_rn)
|
|
11
|
+
- [Hello World Tutorial](https://docs.solanamobile.com/getting-started/hello_world_tutorial)
|
|
12
|
+
- [Sample App Reference](https://docs.solanamobile.com/sample-apps/sample_app_overview)
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
Use this API to start a session:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import {transact} from '@solana-mobile/mobile-wallet-adapter-protocol';
|
|
20
|
+
|
|
21
|
+
await transact(async (wallet) => {
|
|
22
|
+
/* ... */
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The callback you provide will be called once a session has been established with a wallet. It will recieve the `MobileWallet` API as an argument. You can call protocol-specified methods using this function. Whatever you return from this callback will be returned by `transact`.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const signedPayloads = await transact(async (wallet) => {
|
|
30
|
+
const {signed_payloads} = await wallet.signMessages({
|
|
31
|
+
auth_token,
|
|
32
|
+
payloads: [/* ... */],
|
|
33
|
+
});
|
|
34
|
+
return signed_payloads;
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The wallet session will stay active until your callback returns. Typically, wallets will redirect back to your app once the session ends.
|
|
39
|
+
|
|
40
|
+
## Exception handling
|
|
41
|
+
|
|
42
|
+
You can catch exceptions at any level. See `errors.ts` for a list of exceptions that might be thrown.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
try {
|
|
46
|
+
await transact(async (wallet) => {
|
|
47
|
+
try {
|
|
48
|
+
await wallet.signTransactions(/* ... */);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (
|
|
51
|
+
e instanceof SolanaMobileWalletAdapterProtocolError &&
|
|
52
|
+
e.code === SolanaMobileWalletAdapterProtocolErrorCode.ERROR_REAUTHORIZE
|
|
53
|
+
) {
|
|
54
|
+
console.error('The auth token has gone stale');
|
|
55
|
+
await wallet.reauthorize({auth_token, identity});
|
|
56
|
+
// Retry...
|
|
57
|
+
}
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
} catch(e) {
|
|
62
|
+
if (
|
|
63
|
+
e instanceof SolanaMobileWalletAdapterError &&
|
|
64
|
+
e.code === SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND
|
|
65
|
+
) {
|
|
66
|
+
/* ... */
|
|
67
|
+
}
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
70
|
```
|
package/android/build.gradle
CHANGED
|
@@ -8,7 +8,7 @@ buildscript {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
11
|
-
classpath 'com.android.tools.build:gradle:8.8.
|
|
11
|
+
classpath 'com.android.tools.build:gradle:8.8.2'
|
|
12
12
|
// noinspection DifferentKotlinGradleVersion
|
|
13
13
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
14
14
|
}
|
|
@@ -144,7 +144,7 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
|
144
144
|
dependencies {
|
|
145
145
|
//noinspection GradleDynamicVersion
|
|
146
146
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
147
|
-
implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.
|
|
147
|
+
implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.7"
|
|
148
148
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
149
149
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0"
|
|
150
150
|
}
|