@dubsdotapp/expo 0.2.8 → 0.2.9
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/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useAuth.ts +16 -3
- package/src/wallet/mwa-adapter.ts +31 -0
- package/src/wallet/types.ts +7 -0
package/package.json
CHANGED
package/src/hooks/useAuth.ts
CHANGED
|
@@ -73,21 +73,34 @@ export function useAuth(): UseAuthResult {
|
|
|
73
73
|
if (!wallet.publicKey) {
|
|
74
74
|
throw new Error('Wallet not connected');
|
|
75
75
|
}
|
|
76
|
-
if (!wallet.signMessage) {
|
|
76
|
+
if (!wallet.signMessage && !wallet.connectAndSignMessage) {
|
|
77
77
|
throw new Error('Wallet does not support signMessage');
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const walletAddress = wallet.publicKey.toBase58();
|
|
81
80
|
setStatus('authenticating');
|
|
82
81
|
setError(null);
|
|
83
82
|
|
|
83
|
+
const walletAddress = wallet.publicKey.toBase58();
|
|
84
|
+
|
|
84
85
|
// 1. Get nonce
|
|
85
86
|
const { nonce, message } = await client.getNonce(walletAddress);
|
|
86
87
|
|
|
87
88
|
// 2. Sign message
|
|
88
89
|
setStatus('signing');
|
|
89
90
|
const messageBytes = new TextEncoder().encode(message);
|
|
90
|
-
|
|
91
|
+
let signatureBytes: Uint8Array;
|
|
92
|
+
|
|
93
|
+
if (wallet.connectAndSignMessage) {
|
|
94
|
+
// MWA path: reauthorize + sign in a single transact() session.
|
|
95
|
+
// This avoids the double-open problem with Phantom on regular Android
|
|
96
|
+
// where two rapid transact() calls cause the second to be auto-declined.
|
|
97
|
+
signatureBytes = await wallet.connectAndSignMessage(messageBytes);
|
|
98
|
+
} else if (wallet.signMessage) {
|
|
99
|
+
signatureBytes = await wallet.signMessage(messageBytes);
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error('Wallet does not support signMessage');
|
|
102
|
+
}
|
|
103
|
+
|
|
91
104
|
const signature = bs58.encode(signatureBytes);
|
|
92
105
|
|
|
93
106
|
// 3. Verify with server
|
|
@@ -135,6 +135,37 @@ export class MwaWalletAdapter implements WalletAdapter {
|
|
|
135
135
|
return sig instanceof Uint8Array ? sig : new Uint8Array(sig);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Connect (authorize) and sign a message in a single MWA transact() session.
|
|
140
|
+
* This avoids the double-open problem with Phantom on regular Android where
|
|
141
|
+
* two rapid transact() calls cause the second one to be auto-declined.
|
|
142
|
+
*/
|
|
143
|
+
async connectAndSignMessage(message: Uint8Array): Promise<Uint8Array> {
|
|
144
|
+
const sig = await this.transact(async (wallet) => {
|
|
145
|
+
// Authorize or reauthorize in the same session
|
|
146
|
+
const authResult = this._authToken
|
|
147
|
+
? await wallet.reauthorize({ auth_token: this._authToken })
|
|
148
|
+
: await wallet.authorize({
|
|
149
|
+
identity: this.config.appIdentity,
|
|
150
|
+
cluster: this.config.cluster || 'mainnet-beta',
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
this._publicKey = toPublicKey(authResult.accounts[0].address);
|
|
154
|
+
this._authToken = authResult.auth_token;
|
|
155
|
+
this._connected = true;
|
|
156
|
+
this.config.onAuthTokenChange?.(this._authToken);
|
|
157
|
+
|
|
158
|
+
// Sign message in the same session — no second app-switch
|
|
159
|
+
const result = await wallet.signMessages({
|
|
160
|
+
addresses: [this._publicKey.toBytes()],
|
|
161
|
+
payloads: [message],
|
|
162
|
+
});
|
|
163
|
+
return result[0];
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return sig instanceof Uint8Array ? sig : new Uint8Array(sig);
|
|
167
|
+
}
|
|
168
|
+
|
|
138
169
|
async signAndSendTransaction(transaction: Transaction): Promise<string> {
|
|
139
170
|
if (!this._connected) throw new Error('Wallet not connected');
|
|
140
171
|
|
package/src/wallet/types.ts
CHANGED
|
@@ -33,4 +33,11 @@ export interface WalletAdapter {
|
|
|
33
33
|
|
|
34
34
|
/** Optional: Disconnect the wallet */
|
|
35
35
|
disconnect?(): void | Promise<void>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Optional: Connect and sign a message in one step.
|
|
39
|
+
* For MWA wallets, this runs authorize + signMessage in a single transact() session
|
|
40
|
+
* (avoids the double-open problem with Phantom on regular Android).
|
|
41
|
+
*/
|
|
42
|
+
connectAndSignMessage?(message: Uint8Array): Promise<Uint8Array>;
|
|
36
43
|
}
|