@privy-io/react-auth 1.23.2 → 1.24.0-beta.1
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/esm/index.js +135 -135
- package/dist/index.d.ts +120 -4
- package/dist/index.js +135 -135
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import React, { ReactElement } from 'react';
|
|
2
|
-
import { ExternalProvider, Web3Provider } from '@ethersproject/providers';
|
|
2
|
+
import { ExternalProvider, InfuraProvider, Web3Provider } from '@ethersproject/providers';
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
3
4
|
import WCProvider from '@walletconnect/web3-provider';
|
|
4
5
|
import { AbstractProvider } from 'web3-core';
|
|
5
6
|
import { AxiosResponse, AxiosRequestConfig } from 'axios';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* We support a subset of the provider methods found here:
|
|
10
|
+
*
|
|
11
|
+
* https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods
|
|
12
|
+
*
|
|
13
|
+
* For now, we're focused on signing-related methods because the iframe (this code)
|
|
14
|
+
* is the only place that has access to the private key and thus is the only one
|
|
15
|
+
* who can create signatures. All other methods do not need the private key and
|
|
16
|
+
* can therefore be implemented by clients of the iframe.
|
|
17
|
+
*/
|
|
18
|
+
declare const SUPPORTED_JSON_RPC_METHODS: readonly ["eth_sign", "eth_populateTransactionRequest", "eth_signTransaction", "personal_sign"];
|
|
19
|
+
type JsonRpcMethodType = typeof SUPPORTED_JSON_RPC_METHODS[number];
|
|
7
20
|
type Quantity = string | number | bigint;
|
|
8
21
|
type UnsignedTransactionRequest = {
|
|
22
|
+
from?: string;
|
|
9
23
|
to?: string;
|
|
10
24
|
nonce?: number;
|
|
11
25
|
gasLimit?: Quantity;
|
|
@@ -51,10 +65,47 @@ type TransactionReceipt = {
|
|
|
51
65
|
cumulativeGasUsed: string;
|
|
52
66
|
effectiveGasPrice: string;
|
|
53
67
|
};
|
|
68
|
+
interface BaseRpcRequestType {
|
|
69
|
+
method: JsonRpcMethodType;
|
|
70
|
+
}
|
|
71
|
+
interface eth_populateTransactionRequest extends BaseRpcRequestType {
|
|
72
|
+
method: 'eth_populateTransactionRequest';
|
|
73
|
+
params: [UnsignedTransactionRequest];
|
|
74
|
+
}
|
|
75
|
+
interface eth_populateTransactionRequestResponse {
|
|
76
|
+
method: 'eth_populateTransactionRequest';
|
|
77
|
+
data: UnsignedTransactionRequest;
|
|
78
|
+
}
|
|
79
|
+
interface eth_signTransaction extends BaseRpcRequestType {
|
|
80
|
+
method: 'eth_signTransaction';
|
|
81
|
+
params: [UnsignedTransactionRequest];
|
|
82
|
+
}
|
|
83
|
+
interface eth_sign extends BaseRpcRequestType {
|
|
84
|
+
method: 'eth_sign';
|
|
85
|
+
params: [address: string, message: string];
|
|
86
|
+
}
|
|
87
|
+
interface eth_signResponse {
|
|
88
|
+
method: 'eth_sign';
|
|
89
|
+
data: string;
|
|
90
|
+
}
|
|
91
|
+
interface personal_sign extends BaseRpcRequestType {
|
|
92
|
+
method: 'personal_sign';
|
|
93
|
+
params: [string, string];
|
|
94
|
+
}
|
|
95
|
+
interface personal_signResponse {
|
|
96
|
+
method: 'personal_sign';
|
|
97
|
+
data: string;
|
|
98
|
+
}
|
|
99
|
+
interface eth_signTransactionResponse {
|
|
100
|
+
method: 'eth_signTransaction';
|
|
101
|
+
data: string;
|
|
102
|
+
}
|
|
103
|
+
type RpcRequestType = eth_signTransaction | eth_populateTransactionRequest | eth_sign | personal_sign;
|
|
104
|
+
type RpcResponseType = eth_signTransactionResponse | eth_populateTransactionRequestResponse | eth_signResponse | personal_signResponse;
|
|
54
105
|
|
|
55
106
|
declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "discord", "twitter", "github", "apple"];
|
|
56
107
|
type OAuthProviderType = typeof SUPPORTED_OAUTH_PROVIDERS[number];
|
|
57
|
-
declare const SUPPORTED_WALLET_CONNECTION_TYPES: readonly ["metamask", "phantom", "coinbase_wallet", "wallet_connect"];
|
|
108
|
+
declare const SUPPORTED_WALLET_CONNECTION_TYPES: readonly ["metamask", "phantom", "coinbase_wallet", "wallet_connect", "embedded"];
|
|
58
109
|
type WalletType = typeof SUPPORTED_WALLET_CONNECTION_TYPES[number];
|
|
59
110
|
/**
|
|
60
111
|
* Wallet metadata currently for internal use only
|
|
@@ -369,6 +420,44 @@ interface PrivyProviderProps {
|
|
|
369
420
|
*/
|
|
370
421
|
declare const PrivyProvider: (props: PrivyProviderProps) => JSX.Element;
|
|
371
422
|
|
|
423
|
+
type WalletCreateRequestDataType = {
|
|
424
|
+
accessToken: string;
|
|
425
|
+
recoveryPin: string;
|
|
426
|
+
};
|
|
427
|
+
type WalletConnectRequestDataType = {
|
|
428
|
+
accessToken: string;
|
|
429
|
+
address: string;
|
|
430
|
+
};
|
|
431
|
+
type WalletRecoverRequestDataType = {
|
|
432
|
+
accessToken: string;
|
|
433
|
+
address: string;
|
|
434
|
+
recoveryPin: string;
|
|
435
|
+
};
|
|
436
|
+
type WalletRpcRequestDataType = {
|
|
437
|
+
accessToken: string;
|
|
438
|
+
address: string;
|
|
439
|
+
request: RpcRequestType;
|
|
440
|
+
};
|
|
441
|
+
type WalletCreateResponseDataType = {
|
|
442
|
+
address: string;
|
|
443
|
+
};
|
|
444
|
+
type WalletConnectResponseDataType = {
|
|
445
|
+
address: string;
|
|
446
|
+
};
|
|
447
|
+
type WalletRecoverResponseDataType = {
|
|
448
|
+
address: string;
|
|
449
|
+
};
|
|
450
|
+
type WalletRpcResponseDataType = {
|
|
451
|
+
address: string;
|
|
452
|
+
response: RpcResponseType;
|
|
453
|
+
};
|
|
454
|
+
interface EmbeddedWalletProxy {
|
|
455
|
+
create: (data: WalletCreateRequestDataType) => Promise<WalletCreateResponseDataType>;
|
|
456
|
+
connect: (data: WalletConnectRequestDataType) => Promise<WalletConnectResponseDataType>;
|
|
457
|
+
recover: (data: WalletRecoverRequestDataType) => Promise<WalletRecoverResponseDataType>;
|
|
458
|
+
rpc: (data: WalletRpcRequestDataType) => Promise<WalletRpcResponseDataType>;
|
|
459
|
+
}
|
|
460
|
+
|
|
372
461
|
declare global {
|
|
373
462
|
interface Window {
|
|
374
463
|
ethereum?: any;
|
|
@@ -398,6 +487,23 @@ declare class PrivyProxyProvider implements EIP1193Provider {
|
|
|
398
487
|
removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
|
|
399
488
|
setWalletProvider: (provider: EIP1193Provider) => void;
|
|
400
489
|
}
|
|
490
|
+
interface RequestArguments {
|
|
491
|
+
readonly method: string;
|
|
492
|
+
readonly params?: readonly unknown[] | object;
|
|
493
|
+
}
|
|
494
|
+
declare class Embedded1193Provider extends EventEmitter implements EIP1193Provider {
|
|
495
|
+
walletProxy: EmbeddedWalletProxy;
|
|
496
|
+
address: string;
|
|
497
|
+
infuraProvider: InfuraProvider;
|
|
498
|
+
chainId: number;
|
|
499
|
+
constructor(walletProxy: EmbeddedWalletProxy, address: string, chainId?: number);
|
|
500
|
+
handleSendTransaction(args: RequestArguments): Promise<string>;
|
|
501
|
+
private handleSwitchEthereumChain;
|
|
502
|
+
private handlePersonalSign;
|
|
503
|
+
private handleEstimateGas;
|
|
504
|
+
request(args: RequestArguments): Promise<unknown>;
|
|
505
|
+
connect(): Promise<string | null>;
|
|
506
|
+
}
|
|
401
507
|
/**
|
|
402
508
|
* Shim to convert to ethers-compatible ExternalProvider class.
|
|
403
509
|
* @hidden
|
|
@@ -420,23 +526,31 @@ declare class AsExternalProvider extends PrivyProxyProvider implements ExternalP
|
|
|
420
526
|
|
|
421
527
|
/** @hidden */
|
|
422
528
|
declare abstract class WalletConnector {
|
|
423
|
-
proxyProvider: PrivyProxyProvider;
|
|
529
|
+
proxyProvider: PrivyProxyProvider | Embedded1193Provider;
|
|
424
530
|
walletType: WalletType;
|
|
425
531
|
connected: boolean;
|
|
426
532
|
address: string | null;
|
|
427
533
|
chain: string | null;
|
|
428
|
-
constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider, address: string | null);
|
|
534
|
+
constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider | Embedded1193Provider, address: string | null);
|
|
429
535
|
fetchAddress(): Promise<string | null>;
|
|
430
536
|
fetchChainId(): Promise<string>;
|
|
431
537
|
getConnectedWallet(): Promise<Wallet | null>;
|
|
432
538
|
abstract get walletBranding(): WalletBranding;
|
|
433
539
|
abstract connect(options: {
|
|
434
540
|
showPrompt: boolean;
|
|
541
|
+
chainId?: number;
|
|
435
542
|
}): Promise<Wallet | null>;
|
|
436
543
|
abstract disconnect(): void;
|
|
437
544
|
abstract isConnected(): Promise<boolean>;
|
|
438
545
|
abstract promptConnection(walletType: WalletType): void;
|
|
439
546
|
setActive(): Promise<boolean>;
|
|
547
|
+
/**
|
|
548
|
+
* Perform personal_sign with the user's wallet.
|
|
549
|
+
*
|
|
550
|
+
* @param {string} message The message to sign.
|
|
551
|
+
* @returns {string} The resulting signature.
|
|
552
|
+
*/
|
|
553
|
+
sign(message: string): Promise<string>;
|
|
440
554
|
}
|
|
441
555
|
|
|
442
556
|
/**
|
|
@@ -454,6 +568,7 @@ type WalletId = '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a36
|
|
|
454
568
|
*/
|
|
455
569
|
declare class WCWalletConnector extends WalletConnector {
|
|
456
570
|
private connectionManager;
|
|
571
|
+
proxyProvider: PrivyProxyProvider;
|
|
457
572
|
constructor(connectionManager: WCConnectionManager, proxyProvider: PrivyProxyProvider, address: string | null);
|
|
458
573
|
setActive(): Promise<boolean>;
|
|
459
574
|
connect(options: {
|
|
@@ -563,6 +678,7 @@ declare class ConnectorManager {
|
|
|
563
678
|
load(): void;
|
|
564
679
|
/** Persist the instance state to storage to reload the connectors later. */
|
|
565
680
|
save(): void;
|
|
681
|
+
addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
|
|
566
682
|
addWalletConnector(walletConnector: WalletConnector): void;
|
|
567
683
|
getConnectorByAddress(address: string): WalletConnector | undefined;
|
|
568
684
|
removeWallet(address: string): Promise<void>;
|