@solana-mobile/mobile-wallet-adapter-walletlib 1.0.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/LICENSE +13 -0
- package/README.md +93 -0
- package/android/build.gradle +150 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +23 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/Extensions.kt +99 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/JsonSerializationUtils.kt +83 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterBottomSheetActivity.kt +55 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterWalletLibReactNativePackage.kt +16 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +401 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterConfig.kt +60 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterRequest.kt +83 -0
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterResponse.kt +46 -0
- package/android/src/main/res/drawable/background_bottom_sheet_dialog.xml +11 -0
- package/android/src/main/res/values/styles.xml +9 -0
- package/lib/commonjs/index.js +39 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/mwaSessionEvents.js +24 -0
- package/lib/commonjs/mwaSessionEvents.js.map +1 -0
- package/lib/commonjs/resolve.js +48 -0
- package/lib/commonjs/resolve.js.map +1 -0
- package/lib/commonjs/useMobileWalletAdapterSession.js +50 -0
- package/lib/commonjs/useMobileWalletAdapterSession.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/mwaSessionEvents.js +17 -0
- package/lib/module/mwaSessionEvents.js.map +1 -0
- package/lib/module/resolve.js +46 -0
- package/lib/module/resolve.js.map +1 -0
- package/lib/module/useMobileWalletAdapterSession.js +44 -0
- package/lib/module/useMobileWalletAdapterSession.js.map +1 -0
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/mwaSessionEvents.d.ts +48 -0
- package/lib/typescript/mwaSessionEvents.d.ts.map +1 -0
- package/lib/typescript/resolve.d.ts +94 -0
- package/lib/typescript/resolve.d.ts.map +1 -0
- package/lib/typescript/useMobileWalletAdapterSession.d.ts +12 -0
- package/lib/typescript/useMobileWalletAdapterSession.d.ts.map +1 -0
- package/package.json +69 -0
- package/src/index.ts +3 -0
- package/src/mwaSessionEvents.ts +75 -0
- package/src/resolve.ts +165 -0
- package/src/useMobileWalletAdapterSession.ts +83 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/resolve.ts"],"names":[],"mappings":"AA0BA,aAAK,WAAW,GAAG,QAAQ,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC;AAEH;;;GAGG;AAEH,oBAAY,UAAU,GAChB,mBAAmB,GACnB,uBAAuB,GACvB,8BAA8B,GAC9B,oBAAoB,CAAC;AAE3B,oBAAY,cAAc;IACtB,oBAAoB,mBAAmB;IACvC,sBAAsB,qBAAqB;IAC3C,sBAAsB,qBAAqB;IAC3C,mBAAmB,kBAAkB;IACrC,uBAAuB,sBAAsB;IAC7C,8BAA8B,+BAA+B;CAChE;AACD,UAAU,WAAW;IACjB,MAAM,EAAE,cAAc,CAAC;I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CAAC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAC;AAC9F,wBAAgB,OAAO,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;AAC5F,wBAAgB,OAAO,CAAC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI,CAAC;AACpG,wBAAgB,OAAO,CAAC,OAAO,EAAE,8BAA8B,EAAE,QAAQ,EAAE,+BAA+B,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TransactionVersion } from '@solana/web3.js';
|
|
2
|
+
import { MWASessionEvent } from './mwaSessionEvents.js';
|
|
3
|
+
import { MWARequest } from './resolve.js';
|
|
4
|
+
export interface MobileWalletAdapterConfig {
|
|
5
|
+
supportsSignAndSendTransactions: boolean;
|
|
6
|
+
maxTransactionsPerSigningRequest: number;
|
|
7
|
+
maxMessagesPerSigningRequest: number;
|
|
8
|
+
supportedTransactionVersions: Array<TransactionVersion>;
|
|
9
|
+
noConnectionWarningTimeoutMs: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function useMobileWalletAdapterSession(walletName: string, config: MobileWalletAdapterConfig, handleRequest: (request: MWARequest) => void, handleSessionEvent: (sessionEvent: MWASessionEvent) => void): void;
|
|
12
|
+
//# sourceMappingURL=useMobileWalletAdapterSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMobileWalletAdapterSession.d.ts","sourceRoot":"","sources":["../../src/useMobileWalletAdapterSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAuB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAC;AA4B1D,MAAM,WAAW,yBAAyB;IACtC,+BAA+B,EAAE,OAAO,CAAC;IACzC,gCAAgC,EAAE,MAAM,CAAC;IACzC,4BAA4B,EAAE,MAAM,CAAC;IACrC,4BAA4B,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACxD,4BAA4B,EAAE,MAAM,CAAC;CACxC;AAED,wBAAgB,6BAA6B,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,yBAAyB,EACjC,aAAa,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,EAC5C,kBAAkB,EAAE,CAAC,YAAY,EAAE,eAAe,KAAK,IAAI,QAqB9D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@solana-mobile/mobile-wallet-adapter-walletlib",
|
|
3
|
+
"description": "A React Native wrapper of the Solana Mobile, Mobile Wallet Adapter Wallet Library. Wallet apps can use this to handle dapp requests for signing and sending.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Michael Sulistio <mike.sulistio@solanamobile.com>",
|
|
6
|
+
"repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"react-native": "src/index",
|
|
11
|
+
"main": "lib/commonjs/index",
|
|
12
|
+
"module": "lib/module/index",
|
|
13
|
+
"types": "lib/typescript/index.d.ts",
|
|
14
|
+
"files": [
|
|
15
|
+
"android",
|
|
16
|
+
"!android/build",
|
|
17
|
+
"lib",
|
|
18
|
+
"src",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
27
|
+
"prepack": "bob build",
|
|
28
|
+
"release": "release-it",
|
|
29
|
+
"example": "yarn --cwd example",
|
|
30
|
+
"bootstrap": "yarn example && yarn install && yarn example pods",
|
|
31
|
+
"clean": "shx rm -rf lib/*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@release-it/conventional-changelog": "^5.0.0",
|
|
35
|
+
"@solana/web3.js": "^1.58.0",
|
|
36
|
+
"@types/react-native": "^0.69.3",
|
|
37
|
+
"react-native-builder-bob": "^0.20.4",
|
|
38
|
+
"release-it": "^15.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react-native": ">0.69"
|
|
42
|
+
},
|
|
43
|
+
"release-it": {
|
|
44
|
+
"git": {
|
|
45
|
+
"commitMessage": "chore: release ${version}",
|
|
46
|
+
"tagName": "v${version}"
|
|
47
|
+
},
|
|
48
|
+
"npm": {
|
|
49
|
+
"publish": true
|
|
50
|
+
},
|
|
51
|
+
"github": {
|
|
52
|
+
"release": true
|
|
53
|
+
},
|
|
54
|
+
"plugins": {
|
|
55
|
+
"@release-it/conventional-changelog": {
|
|
56
|
+
"preset": "angular"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"react-native-builder-bob": {
|
|
61
|
+
"source": "src",
|
|
62
|
+
"output": "lib",
|
|
63
|
+
"targets": [
|
|
64
|
+
"commonjs",
|
|
65
|
+
"module",
|
|
66
|
+
"typescript"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mobile Wallet Adapter Session Events are notifications and events
|
|
3
|
+
* about the underlying session between the wallet and the dApp.
|
|
4
|
+
*/
|
|
5
|
+
export enum MWASessionEventType {
|
|
6
|
+
SessionStartEvent = 'SESSION_START',
|
|
7
|
+
SessionReadyEvent = 'SESSION_READY',
|
|
8
|
+
SessionTerminatedEvent = 'SESSION_TERMINATED',
|
|
9
|
+
SessionServingClientsEvent = 'SESSION_SERVING_CLIENTS',
|
|
10
|
+
SessionServingCompleteEvent = 'SESSION_SERVING_COMPLETE',
|
|
11
|
+
SessionCompleteEvent = 'SESSION_COMPLETE',
|
|
12
|
+
SessionErrorEvent = 'SESSION_ERROR',
|
|
13
|
+
SessionTeardownCompleteEvent = 'SESSION_TEARDOWN_COMPLETE',
|
|
14
|
+
LowPowerNoConnectionEvent = 'LOW_POWER_NO_CONNECTION',
|
|
15
|
+
}
|
|
16
|
+
export interface IMWASessionEvent {
|
|
17
|
+
__type: MWASessionEventType;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type SessionStartEvent = Readonly<{
|
|
22
|
+
__type: MWASessionEventType.SessionStartEvent;
|
|
23
|
+
}> &
|
|
24
|
+
IMWASessionEvent;
|
|
25
|
+
|
|
26
|
+
export type SessionReadyEvent = Readonly<{
|
|
27
|
+
__type: MWASessionEventType.SessionReadyEvent;
|
|
28
|
+
}> &
|
|
29
|
+
IMWASessionEvent;
|
|
30
|
+
|
|
31
|
+
export type SessionTerminatedEvent = Readonly<{
|
|
32
|
+
__type: MWASessionEventType.SessionTerminatedEvent;
|
|
33
|
+
}> &
|
|
34
|
+
IMWASessionEvent;
|
|
35
|
+
|
|
36
|
+
export type SessionServingClientsEvent = Readonly<{
|
|
37
|
+
__type: MWASessionEventType.SessionServingClientsEvent;
|
|
38
|
+
}> &
|
|
39
|
+
IMWASessionEvent;
|
|
40
|
+
|
|
41
|
+
export type SessionServingCompleteEvent = Readonly<{
|
|
42
|
+
__type: MWASessionEventType.SessionServingCompleteEvent;
|
|
43
|
+
}> &
|
|
44
|
+
IMWASessionEvent;
|
|
45
|
+
|
|
46
|
+
export type SessionCompleteEvent = Readonly<{
|
|
47
|
+
__type: MWASessionEventType.SessionCompleteEvent;
|
|
48
|
+
}> &
|
|
49
|
+
IMWASessionEvent;
|
|
50
|
+
|
|
51
|
+
export type SessionErrorEvent = Readonly<{
|
|
52
|
+
__type: MWASessionEventType.SessionErrorEvent;
|
|
53
|
+
}> &
|
|
54
|
+
IMWASessionEvent;
|
|
55
|
+
|
|
56
|
+
export type SessionTeardownCompleteEvent = Readonly<{
|
|
57
|
+
__type: MWASessionEventType.SessionTeardownCompleteEvent;
|
|
58
|
+
}> &
|
|
59
|
+
IMWASessionEvent;
|
|
60
|
+
|
|
61
|
+
export type LowPowerNoConnectionEvent = Readonly<{
|
|
62
|
+
__type: MWASessionEventType.LowPowerNoConnectionEvent;
|
|
63
|
+
}> &
|
|
64
|
+
IMWASessionEvent;
|
|
65
|
+
|
|
66
|
+
export type MWASessionEvent =
|
|
67
|
+
| SessionStartEvent
|
|
68
|
+
| SessionReadyEvent
|
|
69
|
+
| SessionTerminatedEvent
|
|
70
|
+
| SessionServingClientsEvent
|
|
71
|
+
| SessionServingCompleteEvent
|
|
72
|
+
| SessionCompleteEvent
|
|
73
|
+
| SessionErrorEvent
|
|
74
|
+
| SessionTeardownCompleteEvent
|
|
75
|
+
| LowPowerNoConnectionEvent;
|
package/src/resolve.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
+
'- You rebuilt the app after installing the package\n' +
|
|
6
|
+
'- If you are using Lerna workspaces\n' +
|
|
7
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
8
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
9
|
+
'- You are not using Expo managed workflow\n';
|
|
10
|
+
|
|
11
|
+
const SolanaMobileWalletAdapterWalletLib =
|
|
12
|
+
Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
13
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
14
|
+
: new Proxy(
|
|
15
|
+
{},
|
|
16
|
+
{
|
|
17
|
+
get() {
|
|
18
|
+
throw new Error(
|
|
19
|
+
Platform.OS !== 'android'
|
|
20
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
21
|
+
: LINKING_ERROR,
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
type AppIdentity = Readonly<{
|
|
28
|
+
identityUri?: string;
|
|
29
|
+
iconRelativeUri?: string;
|
|
30
|
+
identityName?: string;
|
|
31
|
+
}>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Mobile Wallet Adapter Requests are remote requests coming from
|
|
35
|
+
* the dApp for authorization, signing, and sending services.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export type MWARequest =
|
|
39
|
+
| SignMessagesRequest
|
|
40
|
+
| SignTransactionsRequest
|
|
41
|
+
| SignAndSendTransactionsRequest
|
|
42
|
+
| AuthorizeDappRequest;
|
|
43
|
+
|
|
44
|
+
export enum MWARequestType {
|
|
45
|
+
AuthorizeDappRequest = 'AUTHORIZE_DAPP',
|
|
46
|
+
ReauthorizeDappRequest = 'REAUTHORIZE_DAPP',
|
|
47
|
+
DeauthorizeDappRequest = 'DEAUTHORIZE_DAPP',
|
|
48
|
+
SignMessagesRequest = 'SIGN_MESSAGES',
|
|
49
|
+
SignTransactionsRequest = 'SIGN_TRANSACTIONS',
|
|
50
|
+
SignAndSendTransactionsRequest = 'SIGN_AND_SEND_TRANSACTIONS',
|
|
51
|
+
}
|
|
52
|
+
interface IMWARequest {
|
|
53
|
+
__type: MWARequestType;
|
|
54
|
+
requestId: string;
|
|
55
|
+
sessionId: string;
|
|
56
|
+
cluster: string;
|
|
57
|
+
authorizationScope: Uint8Array;
|
|
58
|
+
appIdentity?: AppIdentity;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type AuthorizeDappRequest = Readonly<{
|
|
62
|
+
__type: MWARequestType.AuthorizeDappRequest;
|
|
63
|
+
}> &
|
|
64
|
+
IMWARequest;
|
|
65
|
+
|
|
66
|
+
export type ReauthorizeDappRequest = Readonly<{
|
|
67
|
+
__type: MWARequestType.ReauthorizeDappRequest;
|
|
68
|
+
}> &
|
|
69
|
+
IMWARequest;
|
|
70
|
+
|
|
71
|
+
export type DeauthorizeDappRequest = Readonly<{
|
|
72
|
+
__type: MWARequestType.DeauthorizeDappRequest;
|
|
73
|
+
}> &
|
|
74
|
+
IMWARequest;
|
|
75
|
+
|
|
76
|
+
export type SignMessagesRequest = Readonly<{
|
|
77
|
+
__type: MWARequestType.SignMessagesRequest;
|
|
78
|
+
payloads: Uint8Array[];
|
|
79
|
+
}> &
|
|
80
|
+
IMWARequest;
|
|
81
|
+
|
|
82
|
+
export type SignTransactionsRequest = Readonly<{
|
|
83
|
+
__type: MWARequestType.SignTransactionsRequest;
|
|
84
|
+
payloads: Uint8Array[];
|
|
85
|
+
}> &
|
|
86
|
+
IMWARequest;
|
|
87
|
+
|
|
88
|
+
export type SignAndSendTransactionsRequest = Readonly<{
|
|
89
|
+
__type: MWARequestType.SignAndSendTransactionsRequest;
|
|
90
|
+
payloads: Uint8Array[];
|
|
91
|
+
minContextSlot?: number;
|
|
92
|
+
}> &
|
|
93
|
+
IMWARequest;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* MWA Request Responses
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
export type MWAResponse =
|
|
100
|
+
| AuthorizeDappResponse
|
|
101
|
+
| SignMessagesResponse
|
|
102
|
+
| SignTransactionsResponse
|
|
103
|
+
| SignAndSendTransactionsResponse;
|
|
104
|
+
|
|
105
|
+
/* Failure Responses */
|
|
106
|
+
export enum MWARequestFailReason {
|
|
107
|
+
UserDeclined = 'USER_DECLINED',
|
|
108
|
+
TooManyPayloads = 'TOO_MANY_PAYLOADS',
|
|
109
|
+
InvalidSignatures = 'INVALID_SIGNATURES',
|
|
110
|
+
AuthorizationNotValid = 'AUTHORIZATION_NOT_VALID',
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type UserDeclinedResponse = Readonly<{
|
|
114
|
+
failReason: MWARequestFailReason.UserDeclined;
|
|
115
|
+
}>;
|
|
116
|
+
|
|
117
|
+
export type TooManyPayloadsResponse = Readonly<{
|
|
118
|
+
failReason: MWARequestFailReason.TooManyPayloads;
|
|
119
|
+
}>;
|
|
120
|
+
|
|
121
|
+
export type AuthorizationNotValidResponse = Readonly<{
|
|
122
|
+
failReason: MWARequestFailReason.AuthorizationNotValid;
|
|
123
|
+
}>;
|
|
124
|
+
|
|
125
|
+
export type InvalidSignaturesResponse = Readonly<{
|
|
126
|
+
failReason: MWARequestFailReason.InvalidSignatures;
|
|
127
|
+
valid: boolean[];
|
|
128
|
+
}>;
|
|
129
|
+
|
|
130
|
+
/* Authorize Dapp */
|
|
131
|
+
export type AuthorizeDappCompleteResponse = Readonly<{
|
|
132
|
+
publicKey: Uint8Array;
|
|
133
|
+
accountLabel?: string;
|
|
134
|
+
walletUriBase?: string;
|
|
135
|
+
authorizationScope?: Uint8Array;
|
|
136
|
+
}>;
|
|
137
|
+
export type AuthorizeDappResponse = AuthorizeDappCompleteResponse | UserDeclinedResponse;
|
|
138
|
+
|
|
139
|
+
/* Sign Transactions/Messages */
|
|
140
|
+
export type SignPayloadsCompleteResponse = Readonly<{ signedPayloads: Uint8Array[] }>;
|
|
141
|
+
export type SignPayloadsFailResponse =
|
|
142
|
+
| UserDeclinedResponse
|
|
143
|
+
| TooManyPayloadsResponse
|
|
144
|
+
| AuthorizationNotValidResponse
|
|
145
|
+
| InvalidSignaturesResponse;
|
|
146
|
+
|
|
147
|
+
export type SignTransactionsResponse = SignPayloadsCompleteResponse | SignPayloadsFailResponse;
|
|
148
|
+
export type SignMessagesResponse = SignPayloadsCompleteResponse | SignPayloadsFailResponse;
|
|
149
|
+
|
|
150
|
+
/* Sign and Send Transaction */
|
|
151
|
+
export type SignAndSendTransactionsCompleteResponse = Readonly<{ signedTransactions: Uint8Array[] }>;
|
|
152
|
+
export type SignAndSendTransactionsResponse =
|
|
153
|
+
| SignAndSendTransactionsCompleteResponse
|
|
154
|
+
| UserDeclinedResponse
|
|
155
|
+
| TooManyPayloadsResponse
|
|
156
|
+
| AuthorizationNotValidResponse
|
|
157
|
+
| InvalidSignaturesResponse;
|
|
158
|
+
|
|
159
|
+
export function resolve(request: AuthorizeDappRequest, response: AuthorizeDappResponse): void;
|
|
160
|
+
export function resolve(request: SignMessagesRequest, response: SignMessagesResponse): void;
|
|
161
|
+
export function resolve(request: SignTransactionsRequest, response: SignTransactionsResponse): void;
|
|
162
|
+
export function resolve(request: SignAndSendTransactionsRequest, response: SignAndSendTransactionsResponse): void;
|
|
163
|
+
export function resolve(request: MWARequest, response: unknown): void {
|
|
164
|
+
SolanaMobileWalletAdapterWalletLib.resolve(JSON.stringify(request), JSON.stringify(response));
|
|
165
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { TransactionVersion } from '@solana/web3.js';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { Linking, NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { MWASessionEvent, MWASessionEventType } from './mwaSessionEvents.js';
|
|
6
|
+
import { MWARequest, MWARequestType } from './resolve.js';
|
|
7
|
+
|
|
8
|
+
const LINKING_ERROR =
|
|
9
|
+
`The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
10
|
+
'- You rebuilt the app after installing the package\n' +
|
|
11
|
+
'- If you are using Lerna workspaces\n' +
|
|
12
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
13
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
14
|
+
'- You are not using Expo managed workflow\n';
|
|
15
|
+
|
|
16
|
+
const SolanaMobileWalletAdapterWalletLib =
|
|
17
|
+
Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
18
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
19
|
+
: new Proxy(
|
|
20
|
+
{},
|
|
21
|
+
{
|
|
22
|
+
get() {
|
|
23
|
+
throw new Error(
|
|
24
|
+
Platform.OS !== 'android'
|
|
25
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
26
|
+
: LINKING_ERROR,
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = 'MobileWalletAdapterServiceRequestBridge';
|
|
33
|
+
|
|
34
|
+
export interface MobileWalletAdapterConfig {
|
|
35
|
+
supportsSignAndSendTransactions: boolean;
|
|
36
|
+
maxTransactionsPerSigningRequest: number;
|
|
37
|
+
maxMessagesPerSigningRequest: number;
|
|
38
|
+
supportedTransactionVersions: Array<TransactionVersion>;
|
|
39
|
+
noConnectionWarningTimeoutMs: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useMobileWalletAdapterSession(
|
|
43
|
+
walletName: string,
|
|
44
|
+
config: MobileWalletAdapterConfig,
|
|
45
|
+
handleRequest: (request: MWARequest) => void,
|
|
46
|
+
handleSessionEvent: (sessionEvent: MWASessionEvent) => void,
|
|
47
|
+
) {
|
|
48
|
+
// Start native event listeners
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const mwaEventEmitter = new NativeEventEmitter();
|
|
51
|
+
const listener = mwaEventEmitter.addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {
|
|
52
|
+
if (isMWARequest(nativeEvent)) {
|
|
53
|
+
handleRequest(nativeEvent as MWARequest);
|
|
54
|
+
} else if (isMWASessionEvent(nativeEvent)) {
|
|
55
|
+
handleSessionEvent(nativeEvent as MWASessionEvent);
|
|
56
|
+
} else {
|
|
57
|
+
console.warn('Unexpected native event type');
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
listener.remove();
|
|
63
|
+
};
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
initializeScenario(walletName, config);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function initializeScenario(walletName: string, walletConfig: MobileWalletAdapterConfig) {
|
|
70
|
+
// Get initial URL
|
|
71
|
+
const initialUrl = await Linking.getInitialURL();
|
|
72
|
+
|
|
73
|
+
// Create Scenario and establish session with dapp
|
|
74
|
+
SolanaMobileWalletAdapterWalletLib.createScenario(walletName, initialUrl, JSON.stringify(walletConfig));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isMWARequest(nativeEvent: any): boolean {
|
|
78
|
+
return Object.values(MWARequestType).includes(nativeEvent.__type);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isMWASessionEvent(nativeEvent: any) {
|
|
82
|
+
return Object.values(MWASessionEventType).includes(nativeEvent.__type);
|
|
83
|
+
}
|