@solana-mobile/mobile-wallet-adapter-protocol 2.0.0 → 2.0.2

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 (70) hide show
  1. package/.gitignore +2 -0
  2. package/README.md +69 -62
  3. package/android/.gitignore +14 -0
  4. package/android/.gradle/4.4.1/fileChanges/last-build.bin +0 -0
  5. package/android/.gradle/4.4.1/fileHashes/fileHashes.bin +0 -0
  6. package/android/.gradle/4.4.1/fileHashes/fileHashes.lock +0 -0
  7. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  8. package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
  9. package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
  10. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  11. package/android/.gradle/7.1/gc.properties +0 -0
  12. package/android/.gradle/7.5/checksums/checksums.lock +0 -0
  13. package/android/.gradle/7.5/dependencies-accessors/dependencies-accessors.lock +0 -0
  14. package/android/.gradle/7.5/dependencies-accessors/gc.properties +0 -0
  15. package/android/.gradle/7.5/fileChanges/last-build.bin +0 -0
  16. package/android/.gradle/7.5/fileHashes/fileHashes.lock +0 -0
  17. package/android/.gradle/7.5/gc.properties +0 -0
  18. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  19. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  20. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  21. package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
  22. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  23. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  24. package/android/.gradle/7.5.1/gc.properties +0 -0
  25. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  26. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  27. package/android/.gradle/checksums/checksums.lock +0 -0
  28. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  29. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  30. package/android/.gradle/vcs-1/gc.properties +0 -0
  31. package/android/build.gradle +146 -146
  32. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  33. package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterModule.kt +178 -139
  34. package/lib/cjs/index.browser.js +290 -81
  35. package/lib/cjs/index.js +290 -81
  36. package/lib/cjs/index.native.js +180 -28
  37. package/lib/esm/index.browser.js +288 -82
  38. package/lib/esm/index.js +288 -82
  39. package/lib/types/index.browser.d.ts +68 -5
  40. package/lib/types/index.browser.d.ts.map +1 -1
  41. package/lib/types/index.d.ts +68 -5
  42. package/lib/types/index.d.ts.map +1 -1
  43. package/lib/types/index.native.d.ts +68 -5
  44. package/lib/types/index.native.d.ts.map +1 -1
  45. package/package.json +56 -51
  46. package/src/__forks__/react-native/base64Utils.ts +1 -0
  47. package/src/__forks__/react-native/transact.ts +92 -0
  48. package/src/arrayBufferToBase64String.ts +10 -0
  49. package/src/associationPort.ts +19 -0
  50. package/src/base64Utils.ts +3 -0
  51. package/src/createHelloReq.ts +12 -0
  52. package/src/createMobileWalletProxy.ts +175 -0
  53. package/src/createSIWSMessage.ts +14 -0
  54. package/src/createSequenceNumberVector.ts +11 -0
  55. package/src/encryptedMessage.ts +60 -0
  56. package/src/errors.ts +95 -0
  57. package/src/generateAssociationKeypair.ts +10 -0
  58. package/src/generateECDHKeypair.ts +10 -0
  59. package/src/getAssociateAndroidIntentURL.ts +57 -0
  60. package/src/getJWS.ts +19 -0
  61. package/src/getStringWithURLUnsafeBase64CharactersReplaced.ts +11 -0
  62. package/src/index.ts +3 -0
  63. package/src/jsonRpcMessage.ts +38 -0
  64. package/src/parseHelloRsp.ts +46 -0
  65. package/src/parseSessionProps.ts +33 -0
  66. package/src/startSession.ts +94 -0
  67. package/src/transact.ts +266 -0
  68. package/src/types.ts +181 -0
  69. package/tsconfig.cjs.json +7 -0
  70. package/tsconfig.json +8 -0
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/createSequenceNumberVector.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/parseHelloRsp.ts","../../src/jsonRpcMessage.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/types.ts","../../src/transact.ts"],"names":[],"mappings":""}
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/createSequenceNumberVector.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/parseHelloRsp.ts","../../src/jsonRpcMessage.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/types.ts","../../src/transact.ts","../../src/__forks__/react-native/transact.ts"],"names":[],"mappings":""}
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,51 +1,56 @@
1
- {
2
- "name": "@solana-mobile/mobile-wallet-adapter-protocol",
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.0",
5
- "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
- "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
- "license": "Apache-2.0",
8
- "type": "module",
9
- "sideEffects": false,
10
- "main": "lib/cjs/index.js",
11
- "react-native": "lib/cjs/index.native.js",
12
- "module": "lib/esm/index.js",
13
- "types": "lib/types/index.d.ts",
14
- "browser": {
15
- "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
16
- "./lib/esm/index.js": "./lib/esm/index.browser.js"
17
- },
18
- "exports": {
19
- "./package.json": "./package.json",
20
- ".": {
21
- "import": "./lib/esm/index.js",
22
- "require": "./lib/cjs/index.js"
23
- }
24
- },
25
- "files": [
26
- "android",
27
- "!android/build",
28
- "lib",
29
- "LICENSE"
30
- ],
31
- "publishConfig": {
32
- "access": "public"
33
- },
34
- "scripts": {
35
- "clean": "shx rm -rf lib/*",
36
- "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
37
- "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
38
- "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
39
- "prepublishOnly": "agadoo"
40
- },
41
- "devDependencies": {
42
- "@solana/web3.js": "^1.58.0",
43
- "@types/react-native": "^0.69.3",
44
- "agadoo": "^2.0.0",
45
- "cross-env": "^7.0.3"
46
- },
47
- "peerDependencies": {
48
- "react-native": ">0.69"
49
- },
50
- "gitHead": "4118590f5f66fcbc9d04f839abb150f31f1d2ae5"
51
- }
1
+ {
2
+ "name": "@solana-mobile/mobile-wallet-adapter-protocol",
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.2",
5
+ "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
+ "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
+ "license": "Apache-2.0",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "main": "lib/cjs/index.js",
11
+ "react-native": "lib/cjs/index.native.js",
12
+ "module": "lib/esm/index.js",
13
+ "types": "lib/types/index.d.ts",
14
+ "browser": {
15
+ "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
16
+ "./lib/esm/index.js": "./lib/esm/index.browser.js"
17
+ },
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "import": "./lib/esm/index.js",
22
+ "require": "./lib/cjs/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "android",
27
+ "!android/build",
28
+ "lib",
29
+ "LICENSE"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "clean": "shx rm -rf lib/*",
36
+ "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
37
+ "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
38
+ "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
39
+ "prepublishOnly": "agadoo"
40
+ },
41
+ "dependencies": {
42
+ "@solana/wallet-standard-util": "^1.1.1",
43
+ "js-base64": "^3.7.5"
44
+ },
45
+ "devDependencies": {
46
+ "@solana/wallet-standard": "^1.1.1",
47
+ "@solana/web3.js": "^1.58.0",
48
+ "@types/react-native": "^0.69.3",
49
+ "@wallet-standard/core": "^1.0.3",
50
+ "agadoo": "^2.0.0",
51
+ "cross-env": "^7.0.3"
52
+ },
53
+ "peerDependencies": {
54
+ "react-native": ">0.69"
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export { encode } from 'js-base64';
@@ -0,0 +1,92 @@
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
+ }
@@ -0,0 +1,10 @@
1
+ // https://stackoverflow.com/a/9458996/802047
2
+ export default function arrayBufferToBase64String(buffer: ArrayBuffer) {
3
+ let binary = '';
4
+ const bytes = new Uint8Array(buffer);
5
+ const len = bytes.byteLength;
6
+ for (let ii = 0; ii < len; ii++) {
7
+ binary += String.fromCharCode(bytes[ii]);
8
+ }
9
+ return window.btoa(binary);
10
+ }
@@ -0,0 +1,19 @@
1
+ import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterErrorCode } from './errors.js';
2
+
3
+ declare const tag: unique symbol;
4
+ export type AssociationPort = number & { readonly [tag]: 'AssociationPort' };
5
+
6
+ export function getRandomAssociationPort(): AssociationPort {
7
+ return assertAssociationPort(49152 + Math.floor(Math.random() * (65535 - 49152 + 1)));
8
+ }
9
+
10
+ export function assertAssociationPort(port: number): AssociationPort {
11
+ if (port < 49152 || port > 65535) {
12
+ throw new SolanaMobileWalletAdapterError(
13
+ SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_PORT_OUT_OF_RANGE,
14
+ `Association port number must be between 49152 and 65535. ${port} given.`,
15
+ { port },
16
+ );
17
+ }
18
+ return port as AssociationPort;
19
+ }
@@ -0,0 +1,3 @@
1
+ export function encode(input: string): string {
2
+ return window.btoa(input);
3
+ }
@@ -0,0 +1,12 @@
1
+ export default async function createHelloReq(ecdhPublicKey: CryptoKey, associationKeypairPrivateKey: CryptoKey) {
2
+ const publicKeyBuffer = await crypto.subtle.exportKey('raw', ecdhPublicKey);
3
+ const signatureBuffer = await crypto.subtle.sign(
4
+ { hash: 'SHA-256', name: 'ECDSA' },
5
+ associationKeypairPrivateKey,
6
+ publicKeyBuffer,
7
+ );
8
+ const response = new Uint8Array(publicKeyBuffer.byteLength + signatureBuffer.byteLength);
9
+ response.set(new Uint8Array(publicKeyBuffer), 0);
10
+ response.set(new Uint8Array(signatureBuffer), publicKeyBuffer.byteLength);
11
+ return response;
12
+ }