@privy-io/react-auth 1.23.2 → 1.24.0-beta.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.
- package/dist/esm/index.js +135 -135
- package/dist/index.d.ts +130 -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
|
|
@@ -250,6 +301,7 @@ type PrivyServerConfig = {
|
|
|
250
301
|
updatedAt?: Date;
|
|
251
302
|
logoUrl?: string;
|
|
252
303
|
accentColor?: string;
|
|
304
|
+
customApiUrl?: string | null;
|
|
253
305
|
};
|
|
254
306
|
type HexColor = `#${string}`;
|
|
255
307
|
type PrivyClientConfig = {
|
|
@@ -369,6 +421,44 @@ interface PrivyProviderProps {
|
|
|
369
421
|
*/
|
|
370
422
|
declare const PrivyProvider: (props: PrivyProviderProps) => JSX.Element;
|
|
371
423
|
|
|
424
|
+
type WalletCreateRequestDataType = {
|
|
425
|
+
accessToken: string;
|
|
426
|
+
recoveryPin: string;
|
|
427
|
+
};
|
|
428
|
+
type WalletConnectRequestDataType = {
|
|
429
|
+
accessToken: string;
|
|
430
|
+
address: string;
|
|
431
|
+
};
|
|
432
|
+
type WalletRecoverRequestDataType = {
|
|
433
|
+
accessToken: string;
|
|
434
|
+
address: string;
|
|
435
|
+
recoveryPin: string;
|
|
436
|
+
};
|
|
437
|
+
type WalletRpcRequestDataType = {
|
|
438
|
+
accessToken: string;
|
|
439
|
+
address: string;
|
|
440
|
+
request: RpcRequestType;
|
|
441
|
+
};
|
|
442
|
+
type WalletCreateResponseDataType = {
|
|
443
|
+
address: string;
|
|
444
|
+
};
|
|
445
|
+
type WalletConnectResponseDataType = {
|
|
446
|
+
address: string;
|
|
447
|
+
};
|
|
448
|
+
type WalletRecoverResponseDataType = {
|
|
449
|
+
address: string;
|
|
450
|
+
};
|
|
451
|
+
type WalletRpcResponseDataType = {
|
|
452
|
+
address: string;
|
|
453
|
+
response: RpcResponseType;
|
|
454
|
+
};
|
|
455
|
+
interface EmbeddedWalletProxy {
|
|
456
|
+
create: (data: WalletCreateRequestDataType) => Promise<WalletCreateResponseDataType>;
|
|
457
|
+
connect: (data: WalletConnectRequestDataType) => Promise<WalletConnectResponseDataType>;
|
|
458
|
+
recover: (data: WalletRecoverRequestDataType) => Promise<WalletRecoverResponseDataType>;
|
|
459
|
+
rpc: (data: WalletRpcRequestDataType) => Promise<WalletRpcResponseDataType>;
|
|
460
|
+
}
|
|
461
|
+
|
|
372
462
|
declare global {
|
|
373
463
|
interface Window {
|
|
374
464
|
ethereum?: any;
|
|
@@ -398,6 +488,23 @@ declare class PrivyProxyProvider implements EIP1193Provider {
|
|
|
398
488
|
removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
|
|
399
489
|
setWalletProvider: (provider: EIP1193Provider) => void;
|
|
400
490
|
}
|
|
491
|
+
interface RequestArguments {
|
|
492
|
+
readonly method: string;
|
|
493
|
+
readonly params?: readonly unknown[] | object;
|
|
494
|
+
}
|
|
495
|
+
declare class Embedded1193Provider extends EventEmitter implements EIP1193Provider {
|
|
496
|
+
walletProxy: EmbeddedWalletProxy;
|
|
497
|
+
address: string;
|
|
498
|
+
infuraProvider: InfuraProvider;
|
|
499
|
+
chainId: number;
|
|
500
|
+
constructor(walletProxy: EmbeddedWalletProxy, address: string, chainId?: number);
|
|
501
|
+
handleSendTransaction(args: RequestArguments): Promise<string>;
|
|
502
|
+
private handleSwitchEthereumChain;
|
|
503
|
+
private handlePersonalSign;
|
|
504
|
+
private handleEstimateGas;
|
|
505
|
+
request(args: RequestArguments): Promise<unknown>;
|
|
506
|
+
connect(): Promise<string | null>;
|
|
507
|
+
}
|
|
401
508
|
/**
|
|
402
509
|
* Shim to convert to ethers-compatible ExternalProvider class.
|
|
403
510
|
* @hidden
|
|
@@ -420,23 +527,31 @@ declare class AsExternalProvider extends PrivyProxyProvider implements ExternalP
|
|
|
420
527
|
|
|
421
528
|
/** @hidden */
|
|
422
529
|
declare abstract class WalletConnector {
|
|
423
|
-
proxyProvider: PrivyProxyProvider;
|
|
530
|
+
proxyProvider: PrivyProxyProvider | Embedded1193Provider;
|
|
424
531
|
walletType: WalletType;
|
|
425
532
|
connected: boolean;
|
|
426
533
|
address: string | null;
|
|
427
534
|
chain: string | null;
|
|
428
|
-
constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider, address: string | null);
|
|
535
|
+
constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider | Embedded1193Provider, address: string | null);
|
|
429
536
|
fetchAddress(): Promise<string | null>;
|
|
430
537
|
fetchChainId(): Promise<string>;
|
|
431
538
|
getConnectedWallet(): Promise<Wallet | null>;
|
|
432
539
|
abstract get walletBranding(): WalletBranding;
|
|
433
540
|
abstract connect(options: {
|
|
434
541
|
showPrompt: boolean;
|
|
542
|
+
chainId?: number;
|
|
435
543
|
}): Promise<Wallet | null>;
|
|
436
544
|
abstract disconnect(): void;
|
|
437
545
|
abstract isConnected(): Promise<boolean>;
|
|
438
546
|
abstract promptConnection(walletType: WalletType): void;
|
|
439
547
|
setActive(): Promise<boolean>;
|
|
548
|
+
/**
|
|
549
|
+
* Perform personal_sign with the user's wallet.
|
|
550
|
+
*
|
|
551
|
+
* @param {string} message The message to sign.
|
|
552
|
+
* @returns {string} The resulting signature.
|
|
553
|
+
*/
|
|
554
|
+
sign(message: string): Promise<string>;
|
|
440
555
|
}
|
|
441
556
|
|
|
442
557
|
/**
|
|
@@ -454,6 +569,7 @@ type WalletId = '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a36
|
|
|
454
569
|
*/
|
|
455
570
|
declare class WCWalletConnector extends WalletConnector {
|
|
456
571
|
private connectionManager;
|
|
572
|
+
proxyProvider: PrivyProxyProvider;
|
|
457
573
|
constructor(connectionManager: WCConnectionManager, proxyProvider: PrivyProxyProvider, address: string | null);
|
|
458
574
|
setActive(): Promise<boolean>;
|
|
459
575
|
connect(options: {
|
|
@@ -563,6 +679,7 @@ declare class ConnectorManager {
|
|
|
563
679
|
load(): void;
|
|
564
680
|
/** Persist the instance state to storage to reload the connectors later. */
|
|
565
681
|
save(): void;
|
|
682
|
+
addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
|
|
566
683
|
addWalletConnector(walletConnector: WalletConnector): void;
|
|
567
684
|
getConnectorByAddress(address: string): WalletConnector | undefined;
|
|
568
685
|
removeWallet(address: string): Promise<void>;
|
|
@@ -840,6 +957,7 @@ declare class Http {
|
|
|
840
957
|
private client;
|
|
841
958
|
private defaults;
|
|
842
959
|
private sdkVersion;
|
|
960
|
+
fallbackApiUrl: string;
|
|
843
961
|
constructor(appId: string, client: PrivyClient, defaults: DefaultsType);
|
|
844
962
|
get<T = any, R = AxiosResponse<T>, D = any>(path: string, config?: AxiosRequestConfig<D>, fetchAccessToken?: boolean): Promise<R>;
|
|
845
963
|
post<T = any, R = AxiosResponse<T>, D = any>(path: string, data?: D, config?: AxiosRequestConfig<D>, fetchAccessToken?: boolean): Promise<R>;
|
|
@@ -899,8 +1017,10 @@ declare class PrivyClient {
|
|
|
899
1017
|
private api;
|
|
900
1018
|
private appId;
|
|
901
1019
|
private session;
|
|
1020
|
+
private timeout;
|
|
902
1021
|
private clientAnalyticsId;
|
|
903
1022
|
apiUrl: string;
|
|
1023
|
+
fallbackApiUrl: string;
|
|
904
1024
|
authFlow?: AuthFlow;
|
|
905
1025
|
connectors: ConnectorManager;
|
|
906
1026
|
/**
|
|
@@ -921,6 +1041,12 @@ declare class PrivyClient {
|
|
|
921
1041
|
*/
|
|
922
1042
|
timeout?: number;
|
|
923
1043
|
});
|
|
1044
|
+
generateApi(): Http;
|
|
1045
|
+
/**
|
|
1046
|
+
* In the case of cookie-based auth, re-initialize the http client with the custom api url.
|
|
1047
|
+
* @param customApiUrl the custom api url to use for cookie-based authFlow
|
|
1048
|
+
*/
|
|
1049
|
+
updateApiUrl(customApiUrl?: string | null): void;
|
|
924
1050
|
authenticate(): Promise<{
|
|
925
1051
|
user: User | null;
|
|
926
1052
|
isNewUser?: boolean | undefined;
|