@solana-mobile/mobile-wallet-adapter-protocol 2.1.5 → 2.1.7

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.
Files changed (44) hide show
  1. package/.DS_Store +0 -0
  2. package/.gitignore +2 -0
  3. package/README.md +69 -69
  4. package/android/.gitignore +14 -0
  5. package/android/build.gradle +2 -2
  6. package/lib/cjs/index.browser.js +249 -184
  7. package/lib/cjs/index.js +249 -184
  8. package/lib/cjs/index.native.js +8 -0
  9. package/lib/esm/index.browser.js +249 -184
  10. package/lib/esm/index.js +249 -184
  11. package/lib/types/index.browser.d.ts +10 -4
  12. package/lib/types/index.browser.d.ts.map +1 -1
  13. package/lib/types/index.d.ts +10 -4
  14. package/lib/types/index.d.ts.map +1 -1
  15. package/lib/types/index.native.d.ts +10 -4
  16. package/lib/types/index.native.d.ts.map +1 -1
  17. package/package.json +2 -1
  18. package/src/__forks__/react-native/base64Utils.ts +1 -0
  19. package/src/__forks__/react-native/transact.ts +91 -0
  20. package/src/arrayBufferToBase64String.ts +10 -0
  21. package/src/associationPort.ts +19 -0
  22. package/src/base64Utils.ts +22 -0
  23. package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +13 -0
  24. package/src/createHelloReq.ts +12 -0
  25. package/src/createMobileWalletProxy.ts +182 -0
  26. package/src/createSIWSMessage.ts +14 -0
  27. package/src/createSequenceNumberVector.ts +11 -0
  28. package/src/encryptedMessage.ts +60 -0
  29. package/src/errors.ts +101 -0
  30. package/src/generateAssociationKeypair.ts +10 -0
  31. package/src/generateECDHKeypair.ts +10 -0
  32. package/src/getAssociateAndroidIntentURL.ts +77 -0
  33. package/src/getJWS.ts +19 -0
  34. package/src/getStringWithURLUnsafeBase64CharactersReplaced.ts +11 -0
  35. package/src/index.ts +3 -0
  36. package/src/jsonRpcMessage.ts +38 -0
  37. package/src/parseHelloRsp.ts +46 -0
  38. package/src/parseSessionProps.ts +33 -0
  39. package/src/reflectorId.ts +31 -0
  40. package/src/startSession.ts +98 -0
  41. package/src/transact.ts +593 -0
  42. package/src/types.ts +201 -0
  43. package/tsconfig.cjs.json +7 -0
  44. package/tsconfig.json +8 -0
package/.DS_Store ADDED
Binary file
package/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ lib/
2
+ android/build
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
  ```
@@ -0,0 +1,14 @@
1
+ # OSX
2
+ #
3
+ .DS_Store
4
+
5
+ # Android/IJ
6
+ #
7
+ .classpath
8
+ .cxx
9
+ .gradle
10
+ .idea
11
+ .project
12
+ .settings
13
+ local.properties
14
+ android.iml
@@ -8,7 +8,7 @@ buildscript {
8
8
  }
9
9
 
10
10
  dependencies {
11
- classpath 'com.android.tools.build:gradle:8.8.0'
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.5"
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
  }