@solana-mobile/mobile-wallet-adapter-protocol 2.0.1 → 2.1.0-alpha1
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 +3 -3
- package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterModule.kt +17 -15
- package/lib/cjs/index.browser.js +290 -81
- package/lib/cjs/index.js +290 -81
- package/lib/cjs/index.native.js +180 -28
- package/lib/esm/index.browser.js +288 -82
- package/lib/esm/index.js +288 -82
- package/lib/types/index.browser.d.ts +68 -5
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.ts +68 -5
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +68 -5
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +10 -2
- package/src/__forks__/react-native/base64Utils.ts +1 -0
- package/src/__forks__/react-native/transact.ts +92 -106
- package/src/base64Utils.ts +3 -0
- package/src/createMobileWalletProxy.ts +175 -0
- package/src/createSIWSMessage.ts +14 -0
- package/src/encryptedMessage.ts +60 -0
- package/src/errors.ts +95 -93
- package/src/getAssociateAndroidIntentURL.ts +57 -52
- package/src/jsonRpcMessage.ts +38 -81
- package/src/parseHelloRsp.ts +46 -44
- package/src/parseSessionProps.ts +33 -0
- package/src/transact.ts +266 -268
- package/src/types.ts +74 -4
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TransactionVersion } from "@solana/web3.js";
|
|
2
|
+
import { SolanaSignInInput } from "@solana/wallet-standard";
|
|
3
|
+
import { IdentifierArray, IdentifierString, WalletAccount, WalletIcon } from "@wallet-standard/core";
|
|
2
4
|
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
3
5
|
declare const SolanaMobileWalletAdapterErrorCode: {
|
|
4
6
|
readonly ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: "ERROR_ASSOCIATION_PORT_OUT_OF_RANGE";
|
|
@@ -7,6 +9,7 @@ declare const SolanaMobileWalletAdapterErrorCode: {
|
|
|
7
9
|
readonly ERROR_SESSION_CLOSED: "ERROR_SESSION_CLOSED";
|
|
8
10
|
readonly ERROR_SESSION_TIMEOUT: "ERROR_SESSION_TIMEOUT";
|
|
9
11
|
readonly ERROR_WALLET_NOT_FOUND: "ERROR_WALLET_NOT_FOUND";
|
|
12
|
+
readonly ERROR_INVALID_PROTOCOL_VERSION: "ERROR_INVALID_PROTOCOL_VERSION";
|
|
10
13
|
};
|
|
11
14
|
type SolanaMobileWalletAdapterErrorCodeEnum = (typeof SolanaMobileWalletAdapterErrorCode)[keyof typeof SolanaMobileWalletAdapterErrorCode];
|
|
12
15
|
type ErrorDataTypeMap = {
|
|
@@ -20,6 +23,7 @@ type ErrorDataTypeMap = {
|
|
|
20
23
|
};
|
|
21
24
|
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT]: undefined;
|
|
22
25
|
[SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND]: undefined;
|
|
26
|
+
[SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION]: undefined;
|
|
23
27
|
};
|
|
24
28
|
declare class SolanaMobileWalletAdapterError<TErrorCode extends SolanaMobileWalletAdapterErrorCodeEnum> extends Error {
|
|
25
29
|
data: ErrorDataTypeMap[TErrorCode] | undefined;
|
|
@@ -74,7 +78,10 @@ declare class SolanaMobileWalletAdapterProtocolError<TErrorCode extends SolanaMo
|
|
|
74
78
|
type Account = Readonly<{
|
|
75
79
|
address: Base64EncodedAddress;
|
|
76
80
|
label?: string;
|
|
77
|
-
|
|
81
|
+
icon?: WalletIcon;
|
|
82
|
+
chains?: IdentifierArray;
|
|
83
|
+
features?: IdentifierArray;
|
|
84
|
+
}> | WalletAccount;
|
|
78
85
|
/**
|
|
79
86
|
* Properties that wallets may present to users when an app
|
|
80
87
|
* asks for authorization to execute privileged methods (see
|
|
@@ -91,6 +98,10 @@ type AppIdentity = Readonly<{
|
|
|
91
98
|
* The private key is used during session establishment.
|
|
92
99
|
*/
|
|
93
100
|
type AssociationKeypair = CryptoKeyPair;
|
|
101
|
+
type ProtocolVersion = "v1" | "legacy";
|
|
102
|
+
type SessionProperties = Readonly<{
|
|
103
|
+
protocol_version: ProtocolVersion;
|
|
104
|
+
}>;
|
|
94
105
|
/**
|
|
95
106
|
* The context returned from a wallet after having authorized a given
|
|
96
107
|
* account for use with a given application. You can cache this and
|
|
@@ -100,6 +111,7 @@ type AuthorizationResult = Readonly<{
|
|
|
100
111
|
accounts: Account[];
|
|
101
112
|
auth_token: AuthToken;
|
|
102
113
|
wallet_uri_base: string;
|
|
114
|
+
sign_in_result?: SignInResult;
|
|
103
115
|
}>;
|
|
104
116
|
type AuthToken = string;
|
|
105
117
|
type Base64EncodedAddress = string;
|
|
@@ -108,16 +120,31 @@ type Base64EncodedMessage = string;
|
|
|
108
120
|
type Base64EncodedSignedMessage = string;
|
|
109
121
|
type Base64EncodedSignedTransaction = string;
|
|
110
122
|
type Base64EncodedTransaction = string;
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Replaced by the 'chain' parameter, which adds multi-chain capability as per MWA 2.0 spec.
|
|
125
|
+
*/
|
|
111
126
|
type Cluster = "devnet" | "testnet" | "mainnet-beta";
|
|
127
|
+
type Chain = IdentifierString | Cluster;
|
|
112
128
|
type Finality = "confirmed" | "finalized" | "processed";
|
|
113
129
|
type WalletAssociationConfig = Readonly<{
|
|
114
130
|
baseUri?: string;
|
|
115
131
|
}>;
|
|
116
132
|
interface AuthorizeAPI {
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Replaced by updated authorize() method, which adds MWA 2.0 spec support.
|
|
135
|
+
*/
|
|
117
136
|
authorize(params: {
|
|
118
137
|
cluster: Cluster;
|
|
119
138
|
identity: AppIdentity;
|
|
120
139
|
}): Promise<AuthorizationResult>;
|
|
140
|
+
authorize(params: {
|
|
141
|
+
identity: AppIdentity;
|
|
142
|
+
chain?: Chain;
|
|
143
|
+
features?: IdentifierArray;
|
|
144
|
+
addresses?: string[];
|
|
145
|
+
auth_token?: AuthToken;
|
|
146
|
+
sign_in_payload?: SignInPayload;
|
|
147
|
+
}): Promise<AuthorizationResult>;
|
|
121
148
|
}
|
|
122
149
|
interface CloneAuthorizationAPI {
|
|
123
150
|
cloneAuthorization(params: {
|
|
@@ -133,11 +160,18 @@ interface DeauthorizeAPI {
|
|
|
133
160
|
}
|
|
134
161
|
interface GetCapabilitiesAPI {
|
|
135
162
|
getCapabilities(): Promise<Readonly<{
|
|
163
|
+
max_transactions_per_request: number;
|
|
164
|
+
max_messages_per_request: number;
|
|
165
|
+
supported_transaction_versions: ReadonlyArray<TransactionVersion>;
|
|
166
|
+
features: IdentifierArray;
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated Replaced by features array.
|
|
169
|
+
*/
|
|
136
170
|
supports_clone_authorization: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Replaced by features array.
|
|
173
|
+
*/
|
|
137
174
|
supports_sign_and_send_transactions: boolean;
|
|
138
|
-
max_transactions_per_request: boolean;
|
|
139
|
-
max_messages_per_request: boolean;
|
|
140
|
-
supported_transaction_versions: ReadonlyArray<TransactionVersion>;
|
|
141
175
|
}>>;
|
|
142
176
|
}
|
|
143
177
|
interface ReauthorizeAPI {
|
|
@@ -165,6 +199,10 @@ interface SignAndSendTransactionsAPI {
|
|
|
165
199
|
signAndSendTransactions(params: {
|
|
166
200
|
options?: Readonly<{
|
|
167
201
|
min_context_slot?: number;
|
|
202
|
+
commitment?: string;
|
|
203
|
+
skip_preflight?: boolean;
|
|
204
|
+
max_retries?: number;
|
|
205
|
+
wait_for_commitment_to_send_next_transaction?: boolean;
|
|
168
206
|
}>;
|
|
169
207
|
payloads: Base64EncodedTransaction[];
|
|
170
208
|
}): Promise<Readonly<{
|
|
@@ -173,6 +211,31 @@ interface SignAndSendTransactionsAPI {
|
|
|
173
211
|
}
|
|
174
212
|
interface MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI {
|
|
175
213
|
}
|
|
214
|
+
// optional features
|
|
215
|
+
declare const SolanaSignTransactions = "solana:signTransactions";
|
|
216
|
+
declare const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
217
|
+
declare const SolanaSignInWithSolana = "solana:signInWithSolana";
|
|
218
|
+
type SignInPayload = Readonly<{
|
|
219
|
+
domain?: string;
|
|
220
|
+
address?: string;
|
|
221
|
+
statement?: string;
|
|
222
|
+
uri?: string;
|
|
223
|
+
version?: string;
|
|
224
|
+
chainId?: string;
|
|
225
|
+
nonce?: string;
|
|
226
|
+
issuedAt?: string;
|
|
227
|
+
expirationTime?: string;
|
|
228
|
+
notBefore?: string;
|
|
229
|
+
requestId?: string;
|
|
230
|
+
resources?: readonly string[];
|
|
231
|
+
}> | SolanaSignInInput;
|
|
232
|
+
type SignInPayloadWithRequiredFields = Partial<SignInPayload> & Required<Pick<SignInPayload, "domain" | "address">>;
|
|
233
|
+
type SignInResult = Readonly<{
|
|
234
|
+
address: Base64EncodedAddress;
|
|
235
|
+
signed_message: Base64EncodedSignedMessage;
|
|
236
|
+
signature: Base64EncodedAddress;
|
|
237
|
+
signature_type?: string;
|
|
238
|
+
}>;
|
|
176
239
|
declare function transact<TReturn>(callback: (wallet: MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
|
|
177
|
-
export { SolanaMobileWalletAdapterErrorCode, SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolErrorCode, SolanaMobileWalletAdapterProtocolError, transact, Account, AppIdentity, AssociationKeypair, AuthorizationResult, AuthToken, Base64EncodedAddress, Base64EncodedTransaction, Cluster, Finality, WalletAssociationConfig, AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI, MobileWallet };
|
|
240
|
+
export { SolanaMobileWalletAdapterErrorCode, SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolErrorCode, SolanaMobileWalletAdapterProtocolError, transact, Account, AppIdentity, AssociationKeypair, ProtocolVersion, SessionProperties, AuthorizationResult, AuthToken, Base64EncodedAddress, Base64EncodedTransaction, Cluster, Chain, Finality, WalletAssociationConfig, AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI, MobileWallet, SolanaSignTransactions, SolanaCloneAuthorization, SolanaSignInWithSolana, SignInPayload, SignInPayloadWithRequiredFields, SignInResult };
|
|
178
241
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/types.ts","../../src/base64Utils.ts","../../src/createSIWSMessage.ts","../../src/createMobileWalletProxy.ts","../../src/createSequenceNumberVector.ts","../../src/parseHelloRsp.ts","../../src/encryptedMessage.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/jsonRpcMessage.ts","../../src/parseSessionProps.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/transact.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { TransactionVersion } from "@solana/web3.js";
|
|
2
|
+
import { SolanaSignInInput } from "@solana/wallet-standard";
|
|
3
|
+
import { IdentifierArray, IdentifierString, WalletAccount, WalletIcon } from "@wallet-standard/core";
|
|
2
4
|
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
3
5
|
declare const SolanaMobileWalletAdapterErrorCode: {
|
|
4
6
|
readonly ERROR_ASSOCIATION_PORT_OUT_OF_RANGE: "ERROR_ASSOCIATION_PORT_OUT_OF_RANGE";
|
|
@@ -7,6 +9,7 @@ declare const SolanaMobileWalletAdapterErrorCode: {
|
|
|
7
9
|
readonly ERROR_SESSION_CLOSED: "ERROR_SESSION_CLOSED";
|
|
8
10
|
readonly ERROR_SESSION_TIMEOUT: "ERROR_SESSION_TIMEOUT";
|
|
9
11
|
readonly ERROR_WALLET_NOT_FOUND: "ERROR_WALLET_NOT_FOUND";
|
|
12
|
+
readonly ERROR_INVALID_PROTOCOL_VERSION: "ERROR_INVALID_PROTOCOL_VERSION";
|
|
10
13
|
};
|
|
11
14
|
type SolanaMobileWalletAdapterErrorCodeEnum = (typeof SolanaMobileWalletAdapterErrorCode)[keyof typeof SolanaMobileWalletAdapterErrorCode];
|
|
12
15
|
type ErrorDataTypeMap = {
|
|
@@ -20,6 +23,7 @@ type ErrorDataTypeMap = {
|
|
|
20
23
|
};
|
|
21
24
|
[SolanaMobileWalletAdapterErrorCode.ERROR_SESSION_TIMEOUT]: undefined;
|
|
22
25
|
[SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND]: undefined;
|
|
26
|
+
[SolanaMobileWalletAdapterErrorCode.ERROR_INVALID_PROTOCOL_VERSION]: undefined;
|
|
23
27
|
};
|
|
24
28
|
declare class SolanaMobileWalletAdapterError<TErrorCode extends SolanaMobileWalletAdapterErrorCodeEnum> extends Error {
|
|
25
29
|
data: ErrorDataTypeMap[TErrorCode] | undefined;
|
|
@@ -74,7 +78,10 @@ declare class SolanaMobileWalletAdapterProtocolError<TErrorCode extends SolanaMo
|
|
|
74
78
|
type Account = Readonly<{
|
|
75
79
|
address: Base64EncodedAddress;
|
|
76
80
|
label?: string;
|
|
77
|
-
|
|
81
|
+
icon?: WalletIcon;
|
|
82
|
+
chains?: IdentifierArray;
|
|
83
|
+
features?: IdentifierArray;
|
|
84
|
+
}> | WalletAccount;
|
|
78
85
|
/**
|
|
79
86
|
* Properties that wallets may present to users when an app
|
|
80
87
|
* asks for authorization to execute privileged methods (see
|
|
@@ -91,6 +98,10 @@ type AppIdentity = Readonly<{
|
|
|
91
98
|
* The private key is used during session establishment.
|
|
92
99
|
*/
|
|
93
100
|
type AssociationKeypair = CryptoKeyPair;
|
|
101
|
+
type ProtocolVersion = "v1" | "legacy";
|
|
102
|
+
type SessionProperties = Readonly<{
|
|
103
|
+
protocol_version: ProtocolVersion;
|
|
104
|
+
}>;
|
|
94
105
|
/**
|
|
95
106
|
* The context returned from a wallet after having authorized a given
|
|
96
107
|
* account for use with a given application. You can cache this and
|
|
@@ -100,6 +111,7 @@ type AuthorizationResult = Readonly<{
|
|
|
100
111
|
accounts: Account[];
|
|
101
112
|
auth_token: AuthToken;
|
|
102
113
|
wallet_uri_base: string;
|
|
114
|
+
sign_in_result?: SignInResult;
|
|
103
115
|
}>;
|
|
104
116
|
type AuthToken = string;
|
|
105
117
|
type Base64EncodedAddress = string;
|
|
@@ -108,16 +120,31 @@ type Base64EncodedMessage = string;
|
|
|
108
120
|
type Base64EncodedSignedMessage = string;
|
|
109
121
|
type Base64EncodedSignedTransaction = string;
|
|
110
122
|
type Base64EncodedTransaction = string;
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Replaced by the 'chain' parameter, which adds multi-chain capability as per MWA 2.0 spec.
|
|
125
|
+
*/
|
|
111
126
|
type Cluster = "devnet" | "testnet" | "mainnet-beta";
|
|
127
|
+
type Chain = IdentifierString | Cluster;
|
|
112
128
|
type Finality = "confirmed" | "finalized" | "processed";
|
|
113
129
|
type WalletAssociationConfig = Readonly<{
|
|
114
130
|
baseUri?: string;
|
|
115
131
|
}>;
|
|
116
132
|
interface AuthorizeAPI {
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated Replaced by updated authorize() method, which adds MWA 2.0 spec support.
|
|
135
|
+
*/
|
|
117
136
|
authorize(params: {
|
|
118
137
|
cluster: Cluster;
|
|
119
138
|
identity: AppIdentity;
|
|
120
139
|
}): Promise<AuthorizationResult>;
|
|
140
|
+
authorize(params: {
|
|
141
|
+
identity: AppIdentity;
|
|
142
|
+
chain?: Chain;
|
|
143
|
+
features?: IdentifierArray;
|
|
144
|
+
addresses?: string[];
|
|
145
|
+
auth_token?: AuthToken;
|
|
146
|
+
sign_in_payload?: SignInPayload;
|
|
147
|
+
}): Promise<AuthorizationResult>;
|
|
121
148
|
}
|
|
122
149
|
interface CloneAuthorizationAPI {
|
|
123
150
|
cloneAuthorization(params: {
|
|
@@ -133,11 +160,18 @@ interface DeauthorizeAPI {
|
|
|
133
160
|
}
|
|
134
161
|
interface GetCapabilitiesAPI {
|
|
135
162
|
getCapabilities(): Promise<Readonly<{
|
|
163
|
+
max_transactions_per_request: number;
|
|
164
|
+
max_messages_per_request: number;
|
|
165
|
+
supported_transaction_versions: ReadonlyArray<TransactionVersion>;
|
|
166
|
+
features: IdentifierArray;
|
|
167
|
+
/**
|
|
168
|
+
* @deprecated Replaced by features array.
|
|
169
|
+
*/
|
|
136
170
|
supports_clone_authorization: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* @deprecated Replaced by features array.
|
|
173
|
+
*/
|
|
137
174
|
supports_sign_and_send_transactions: boolean;
|
|
138
|
-
max_transactions_per_request: boolean;
|
|
139
|
-
max_messages_per_request: boolean;
|
|
140
|
-
supported_transaction_versions: ReadonlyArray<TransactionVersion>;
|
|
141
175
|
}>>;
|
|
142
176
|
}
|
|
143
177
|
interface ReauthorizeAPI {
|
|
@@ -165,6 +199,10 @@ interface SignAndSendTransactionsAPI {
|
|
|
165
199
|
signAndSendTransactions(params: {
|
|
166
200
|
options?: Readonly<{
|
|
167
201
|
min_context_slot?: number;
|
|
202
|
+
commitment?: string;
|
|
203
|
+
skip_preflight?: boolean;
|
|
204
|
+
max_retries?: number;
|
|
205
|
+
wait_for_commitment_to_send_next_transaction?: boolean;
|
|
168
206
|
}>;
|
|
169
207
|
payloads: Base64EncodedTransaction[];
|
|
170
208
|
}): Promise<Readonly<{
|
|
@@ -173,6 +211,31 @@ interface SignAndSendTransactionsAPI {
|
|
|
173
211
|
}
|
|
174
212
|
interface MobileWallet extends AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI {
|
|
175
213
|
}
|
|
214
|
+
// optional features
|
|
215
|
+
declare const SolanaSignTransactions = "solana:signTransactions";
|
|
216
|
+
declare const SolanaCloneAuthorization = "solana:cloneAuthorization";
|
|
217
|
+
declare const SolanaSignInWithSolana = "solana:signInWithSolana";
|
|
218
|
+
type SignInPayload = Readonly<{
|
|
219
|
+
domain?: string;
|
|
220
|
+
address?: string;
|
|
221
|
+
statement?: string;
|
|
222
|
+
uri?: string;
|
|
223
|
+
version?: string;
|
|
224
|
+
chainId?: string;
|
|
225
|
+
nonce?: string;
|
|
226
|
+
issuedAt?: string;
|
|
227
|
+
expirationTime?: string;
|
|
228
|
+
notBefore?: string;
|
|
229
|
+
requestId?: string;
|
|
230
|
+
resources?: readonly string[];
|
|
231
|
+
}> | SolanaSignInInput;
|
|
232
|
+
type SignInPayloadWithRequiredFields = Partial<SignInPayload> & Required<Pick<SignInPayload, "domain" | "address">>;
|
|
233
|
+
type SignInResult = Readonly<{
|
|
234
|
+
address: Base64EncodedAddress;
|
|
235
|
+
signed_message: Base64EncodedSignedMessage;
|
|
236
|
+
signature: Base64EncodedAddress;
|
|
237
|
+
signature_type?: string;
|
|
238
|
+
}>;
|
|
176
239
|
declare function transact<TReturn>(callback: (wallet: MobileWallet) => TReturn, config?: WalletAssociationConfig): Promise<TReturn>;
|
|
177
|
-
export { SolanaMobileWalletAdapterErrorCode, SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolErrorCode, SolanaMobileWalletAdapterProtocolError, transact, Account, AppIdentity, AssociationKeypair, AuthorizationResult, AuthToken, Base64EncodedAddress, Base64EncodedTransaction, Cluster, Finality, WalletAssociationConfig, AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI, MobileWallet };
|
|
240
|
+
export { SolanaMobileWalletAdapterErrorCode, SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolErrorCode, SolanaMobileWalletAdapterProtocolError, transact, Account, AppIdentity, AssociationKeypair, ProtocolVersion, SessionProperties, AuthorizationResult, AuthToken, Base64EncodedAddress, Base64EncodedTransaction, Cluster, Chain, Finality, WalletAssociationConfig, AuthorizeAPI, CloneAuthorizationAPI, DeauthorizeAPI, GetCapabilitiesAPI, ReauthorizeAPI, SignMessagesAPI, SignTransactionsAPI, SignAndSendTransactionsAPI, MobileWallet, SolanaSignTransactions, SolanaCloneAuthorization, SolanaSignInWithSolana, SignInPayload, SignInPayloadWithRequiredFields, SignInResult };
|
|
178
241
|
//# sourceMappingURL=index.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/
|
|
1
|
+
{"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/types.ts","../../src/base64Utils.ts","../../src/createSIWSMessage.ts","../../src/createMobileWalletProxy.ts","../../src/createSequenceNumberVector.ts","../../src/parseHelloRsp.ts","../../src/encryptedMessage.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/jsonRpcMessage.ts","../../src/parseSessionProps.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/transact.ts","../../src/__forks__/react-native/transact.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana-mobile/mobile-wallet-adapter-protocol",
|
|
3
3
|
"description": "An implementation of the Solana Mobile Mobile Wallet Adapter protocol. Use this to open a session with a mobile wallet app, and to issue API calls to it.",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0-alpha1",
|
|
5
5
|
"author": "Steven Luscher <steven.luscher@solanamobile.com>",
|
|
6
6
|
"repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -38,13 +38,21 @@
|
|
|
38
38
|
"postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
|
|
39
39
|
"prepublishOnly": "agadoo"
|
|
40
40
|
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@solana/wallet-standard": "^1.1.2",
|
|
43
|
+
"@solana/wallet-standard-util": "^1.1.1",
|
|
44
|
+
"@wallet-standard/core": "^1.0.3",
|
|
45
|
+
"js-base64": "^3.7.5"
|
|
46
|
+
},
|
|
41
47
|
"devDependencies": {
|
|
42
48
|
"@solana/web3.js": "^1.58.0",
|
|
43
49
|
"@types/react-native": "^0.69.3",
|
|
44
50
|
"agadoo": "^2.0.0",
|
|
45
|
-
"cross-env": "^7.0.3"
|
|
51
|
+
"cross-env": "^7.0.3",
|
|
52
|
+
"shx": "^0.3.4"
|
|
46
53
|
},
|
|
47
54
|
"peerDependencies": {
|
|
55
|
+
"@solana/web3.js": "^1.58.0",
|
|
48
56
|
"react-native": ">0.69"
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { encode } from 'js-base64';
|
|
@@ -1,106 +1,92 @@
|
|
|
1
|
-
import { NativeModules, Platform } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolError } from '../../errors.js';
|
|
4
|
-
import { MobileWallet, WalletAssociationConfig } from '../../types.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'-
|
|
11
|
-
'-
|
|
12
|
-
'
|
|
13
|
-
' - You have added `@solana-mobile/mobile-wallet-adapter-protocol`
|
|
14
|
-
'- You
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
reactNativeError
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
deleteProperty() {
|
|
95
|
-
return false;
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
return await callback(wallet);
|
|
99
|
-
} catch (e) {
|
|
100
|
-
return handleError(e);
|
|
101
|
-
} finally {
|
|
102
|
-
if (didSuccessfullyConnect) {
|
|
103
|
-
await SolanaMobileWalletAdapter.endSession();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolError } from '../../errors.js';
|
|
4
|
+
import { MobileWallet, SessionProperties,WalletAssociationConfig } from '../../types.js';
|
|
5
|
+
import createMobileWalletProxy from '../../createMobileWalletProxy.js';
|
|
6
|
+
|
|
7
|
+
type ReactNativeError = Error & { code?: string; userInfo?: Record<string, unknown> };
|
|
8
|
+
|
|
9
|
+
const LINKING_ERROR =
|
|
10
|
+
`The package 'solana-mobile-wallet-adapter-protocol' doesn't seem to be linked. Make sure: \n\n` +
|
|
11
|
+
'- You rebuilt the app after installing the package\n' +
|
|
12
|
+
'- If you are using Lerna workspaces\n' +
|
|
13
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` as an explicit dependency, and\n' +
|
|
14
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n' +
|
|
15
|
+
'- You are not using Expo managed workflow\n';
|
|
16
|
+
|
|
17
|
+
const SolanaMobileWalletAdapter =
|
|
18
|
+
Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapter
|
|
19
|
+
? NativeModules.SolanaMobileWalletAdapter
|
|
20
|
+
: new Proxy(
|
|
21
|
+
{},
|
|
22
|
+
{
|
|
23
|
+
get() {
|
|
24
|
+
throw new Error(
|
|
25
|
+
Platform.OS !== 'android'
|
|
26
|
+
? 'The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android'
|
|
27
|
+
: LINKING_ERROR,
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function getErrorMessage(e: ReactNativeError): string {
|
|
34
|
+
switch (e.code) {
|
|
35
|
+
case 'ERROR_WALLET_NOT_FOUND':
|
|
36
|
+
return 'Found no installed wallet that supports the mobile wallet protocol.';
|
|
37
|
+
default:
|
|
38
|
+
return e.message;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function handleError(e: any): never {
|
|
43
|
+
if (e instanceof Error) {
|
|
44
|
+
const reactNativeError: ReactNativeError = e;
|
|
45
|
+
switch (reactNativeError.code) {
|
|
46
|
+
case undefined:
|
|
47
|
+
throw e;
|
|
48
|
+
case 'JSON_RPC_ERROR': {
|
|
49
|
+
const details = reactNativeError.userInfo as Readonly<{ jsonRpcErrorCode: number }>;
|
|
50
|
+
throw new SolanaMobileWalletAdapterProtocolError(
|
|
51
|
+
0 /* jsonRpcMessageId */,
|
|
52
|
+
details.jsonRpcErrorCode,
|
|
53
|
+
e.message,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
default:
|
|
57
|
+
throw new SolanaMobileWalletAdapterError<any>(
|
|
58
|
+
reactNativeError.code,
|
|
59
|
+
getErrorMessage(reactNativeError),
|
|
60
|
+
reactNativeError.userInfo,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw e;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function transact<TReturn>(
|
|
68
|
+
callback: (wallet: MobileWallet) => TReturn,
|
|
69
|
+
config?: WalletAssociationConfig,
|
|
70
|
+
): Promise<TReturn> {
|
|
71
|
+
let didSuccessfullyConnect = false;
|
|
72
|
+
try {
|
|
73
|
+
const sessionProperties: SessionProperties = await SolanaMobileWalletAdapter.startSession(config);
|
|
74
|
+
didSuccessfullyConnect = true;
|
|
75
|
+
const wallet = createMobileWalletProxy(sessionProperties.protocol_version,
|
|
76
|
+
async (method, params) => {
|
|
77
|
+
try {
|
|
78
|
+
return SolanaMobileWalletAdapter.invoke(method, params);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return handleError(e);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
return await callback(wallet);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return handleError(e);
|
|
87
|
+
} finally {
|
|
88
|
+
if (didSuccessfullyConnect) {
|
|
89
|
+
await SolanaMobileWalletAdapter.endSession();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|