@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/dist/index.d.mts
CHANGED
|
@@ -438,6 +438,12 @@ interface WalletAdapter {
|
|
|
438
438
|
connect?(): Promise<void>;
|
|
439
439
|
/** Optional: Disconnect the wallet */
|
|
440
440
|
disconnect?(): void | Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Optional: Connect and sign a message in one step.
|
|
443
|
+
* For MWA wallets, this runs authorize + signMessage in a single transact() session
|
|
444
|
+
* (avoids the double-open problem with Phantom on regular Android).
|
|
445
|
+
*/
|
|
446
|
+
connectAndSignMessage?(message: Uint8Array): Promise<Uint8Array>;
|
|
441
447
|
}
|
|
442
448
|
|
|
443
449
|
interface RegistrationScreenProps {
|
|
@@ -562,6 +568,12 @@ declare class MwaWalletAdapter implements WalletAdapter {
|
|
|
562
568
|
disconnect(): void;
|
|
563
569
|
signTransaction(transaction: Transaction): Promise<Transaction>;
|
|
564
570
|
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
571
|
+
/**
|
|
572
|
+
* Connect (authorize) and sign a message in a single MWA transact() session.
|
|
573
|
+
* This avoids the double-open problem with Phantom on regular Android where
|
|
574
|
+
* two rapid transact() calls cause the second one to be auto-declined.
|
|
575
|
+
*/
|
|
576
|
+
connectAndSignMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
565
577
|
signAndSendTransaction(transaction: Transaction): Promise<string>;
|
|
566
578
|
}
|
|
567
579
|
|
package/dist/index.d.ts
CHANGED
|
@@ -438,6 +438,12 @@ interface WalletAdapter {
|
|
|
438
438
|
connect?(): Promise<void>;
|
|
439
439
|
/** Optional: Disconnect the wallet */
|
|
440
440
|
disconnect?(): void | Promise<void>;
|
|
441
|
+
/**
|
|
442
|
+
* Optional: Connect and sign a message in one step.
|
|
443
|
+
* For MWA wallets, this runs authorize + signMessage in a single transact() session
|
|
444
|
+
* (avoids the double-open problem with Phantom on regular Android).
|
|
445
|
+
*/
|
|
446
|
+
connectAndSignMessage?(message: Uint8Array): Promise<Uint8Array>;
|
|
441
447
|
}
|
|
442
448
|
|
|
443
449
|
interface RegistrationScreenProps {
|
|
@@ -562,6 +568,12 @@ declare class MwaWalletAdapter implements WalletAdapter {
|
|
|
562
568
|
disconnect(): void;
|
|
563
569
|
signTransaction(transaction: Transaction): Promise<Transaction>;
|
|
564
570
|
signMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
571
|
+
/**
|
|
572
|
+
* Connect (authorize) and sign a message in a single MWA transact() session.
|
|
573
|
+
* This avoids the double-open problem with Phantom on regular Android where
|
|
574
|
+
* two rapid transact() calls cause the second one to be auto-declined.
|
|
575
|
+
*/
|
|
576
|
+
connectAndSignMessage(message: Uint8Array): Promise<Uint8Array>;
|
|
565
577
|
signAndSendTransaction(transaction: Transaction): Promise<string>;
|
|
566
578
|
}
|
|
567
579
|
|
package/dist/index.js
CHANGED
|
@@ -637,6 +637,29 @@ var MwaWalletAdapter = class {
|
|
|
637
637
|
});
|
|
638
638
|
return sig instanceof Uint8Array ? sig : new Uint8Array(sig);
|
|
639
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Connect (authorize) and sign a message in a single MWA transact() session.
|
|
642
|
+
* This avoids the double-open problem with Phantom on regular Android where
|
|
643
|
+
* two rapid transact() calls cause the second one to be auto-declined.
|
|
644
|
+
*/
|
|
645
|
+
async connectAndSignMessage(message) {
|
|
646
|
+
const sig = await this.transact(async (wallet) => {
|
|
647
|
+
const authResult = this._authToken ? await wallet.reauthorize({ auth_token: this._authToken }) : await wallet.authorize({
|
|
648
|
+
identity: this.config.appIdentity,
|
|
649
|
+
cluster: this.config.cluster || "mainnet-beta"
|
|
650
|
+
});
|
|
651
|
+
this._publicKey = toPublicKey(authResult.accounts[0].address);
|
|
652
|
+
this._authToken = authResult.auth_token;
|
|
653
|
+
this._connected = true;
|
|
654
|
+
this.config.onAuthTokenChange?.(this._authToken);
|
|
655
|
+
const result = await wallet.signMessages({
|
|
656
|
+
addresses: [this._publicKey.toBytes()],
|
|
657
|
+
payloads: [message]
|
|
658
|
+
});
|
|
659
|
+
return result[0];
|
|
660
|
+
});
|
|
661
|
+
return sig instanceof Uint8Array ? sig : new Uint8Array(sig);
|
|
662
|
+
}
|
|
640
663
|
async signAndSendTransaction(transaction) {
|
|
641
664
|
if (!this._connected) throw new Error("Wallet not connected");
|
|
642
665
|
const signature = await this.transact(async (wallet) => {
|
|
@@ -1327,16 +1350,23 @@ function useAuth() {
|
|
|
1327
1350
|
if (!wallet.publicKey) {
|
|
1328
1351
|
throw new Error("Wallet not connected");
|
|
1329
1352
|
}
|
|
1330
|
-
if (!wallet.signMessage) {
|
|
1353
|
+
if (!wallet.signMessage && !wallet.connectAndSignMessage) {
|
|
1331
1354
|
throw new Error("Wallet does not support signMessage");
|
|
1332
1355
|
}
|
|
1333
|
-
const walletAddress = wallet.publicKey.toBase58();
|
|
1334
1356
|
setStatus("authenticating");
|
|
1335
1357
|
setError(null);
|
|
1358
|
+
const walletAddress = wallet.publicKey.toBase58();
|
|
1336
1359
|
const { nonce, message } = await client.getNonce(walletAddress);
|
|
1337
1360
|
setStatus("signing");
|
|
1338
1361
|
const messageBytes = new TextEncoder().encode(message);
|
|
1339
|
-
|
|
1362
|
+
let signatureBytes;
|
|
1363
|
+
if (wallet.connectAndSignMessage) {
|
|
1364
|
+
signatureBytes = await wallet.connectAndSignMessage(messageBytes);
|
|
1365
|
+
} else if (wallet.signMessage) {
|
|
1366
|
+
signatureBytes = await wallet.signMessage(messageBytes);
|
|
1367
|
+
} else {
|
|
1368
|
+
throw new Error("Wallet does not support signMessage");
|
|
1369
|
+
}
|
|
1340
1370
|
const signature = import_bs58.default.encode(signatureBytes);
|
|
1341
1371
|
setStatus("verifying");
|
|
1342
1372
|
const result = await client.authenticate({ walletAddress, signature, nonce });
|