@0xsequence/connect 5.0.8 → 5.1.0
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/cjs/components/Connect/Connect.js +1 -1
- package/dist/cjs/components/Connect/Connect.js.map +1 -1
- package/dist/cjs/config/defaultConnectors.d.ts +3 -1
- package/dist/cjs/config/defaultConnectors.d.ts.map +1 -1
- package/dist/cjs/config/defaultConnectors.js +3 -0
- package/dist/cjs/config/defaultConnectors.js.map +1 -1
- package/dist/cjs/constants/version.d.ts +1 -1
- package/dist/cjs/constants/version.js +1 -1
- package/dist/cjs/hooks/useChain.d.ts +29 -1
- package/dist/cjs/hooks/useChain.d.ts.map +1 -1
- package/dist/cjs/hooks/useChain.js +27 -1
- package/dist/cjs/hooks/useChain.js.map +1 -1
- package/dist/cjs/hooks/useCheckWaasFeeOptions.d.ts +41 -0
- package/dist/cjs/hooks/useCheckWaasFeeOptions.d.ts.map +1 -1
- package/dist/cjs/hooks/useCheckWaasFeeOptions.js +41 -0
- package/dist/cjs/hooks/useCheckWaasFeeOptions.js.map +1 -1
- package/dist/cjs/hooks/useDirectEcosystemConnect.d.ts +32 -0
- package/dist/cjs/hooks/useDirectEcosystemConnect.d.ts.map +1 -1
- package/dist/cjs/hooks/useDirectEcosystemConnect.js +32 -0
- package/dist/cjs/hooks/useDirectEcosystemConnect.js.map +1 -1
- package/dist/cjs/hooks/useListAccounts.d.ts +39 -0
- package/dist/cjs/hooks/useListAccounts.d.ts.map +1 -0
- package/dist/cjs/hooks/useListAccounts.js +62 -0
- package/dist/cjs/hooks/useListAccounts.js.map +1 -0
- package/dist/cjs/hooks/useOpenConnectModal.d.ts +1 -1
- package/dist/cjs/hooks/useOpenConnectModal.js +1 -1
- package/dist/cjs/hooks/useProjectAccessKey.d.ts +17 -0
- package/dist/cjs/hooks/useProjectAccessKey.d.ts.map +1 -1
- package/dist/cjs/hooks/useProjectAccessKey.js +17 -0
- package/dist/cjs/hooks/useProjectAccessKey.js.map +1 -1
- package/dist/cjs/hooks/useSignInEmail.d.ts +20 -0
- package/dist/cjs/hooks/useSignInEmail.d.ts.map +1 -1
- package/dist/cjs/hooks/useSignInEmail.js +20 -0
- package/dist/cjs/hooks/useSignInEmail.js.map +1 -1
- package/dist/cjs/hooks/useTheme.d.ts +26 -0
- package/dist/cjs/hooks/useTheme.d.ts.map +1 -1
- package/dist/cjs/hooks/useTheme.js +26 -0
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/hooks/useWaasConfirmationHandler.d.ts +39 -0
- package/dist/cjs/hooks/useWaasConfirmationHandler.d.ts.map +1 -1
- package/dist/cjs/hooks/useWaasConfirmationHandler.js +39 -0
- package/dist/cjs/hooks/useWaasConfirmationHandler.js.map +1 -1
- package/dist/cjs/hooks/useWaasEmailAuth.d.ts +46 -0
- package/dist/cjs/hooks/useWaasEmailAuth.d.ts.map +1 -1
- package/dist/cjs/hooks/useWaasEmailAuth.js +46 -0
- package/dist/cjs/hooks/useWaasEmailAuth.js.map +1 -1
- package/dist/cjs/hooks/useWaasEmailConflict.d.ts +39 -0
- package/dist/cjs/hooks/useWaasEmailConflict.d.ts.map +1 -1
- package/dist/cjs/hooks/useWaasEmailConflict.js +39 -0
- package/dist/cjs/hooks/useWaasEmailConflict.js.map +1 -1
- package/dist/cjs/hooks/useWaasGetLinkedWalletsSignature.d.ts +60 -0
- package/dist/cjs/hooks/useWaasGetLinkedWalletsSignature.d.ts.map +1 -1
- package/dist/cjs/hooks/useWaasGetLinkedWalletsSignature.js +50 -0
- package/dist/cjs/hooks/useWaasGetLinkedWalletsSignature.js.map +1 -1
- package/dist/cjs/hooks/useWaasLinkWallet.d.ts +57 -0
- package/dist/cjs/hooks/useWaasLinkWallet.d.ts.map +1 -1
- package/dist/cjs/hooks/useWaasLinkWallet.js +42 -0
- package/dist/cjs/hooks/useWaasLinkWallet.js.map +1 -1
- package/dist/cjs/hooks/useWalletSettings.d.ts +28 -0
- package/dist/cjs/hooks/useWalletSettings.d.ts.map +1 -1
- package/dist/cjs/hooks/useWalletSettings.js +28 -0
- package/dist/cjs/hooks/useWalletSettings.js.map +1 -1
- package/dist/cjs/hooks/useWallets.d.ts.map +1 -1
- package/dist/cjs/hooks/useWallets.js +17 -1
- package/dist/cjs/hooks/useWallets.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/Connect/Connect.js +1 -1
- package/dist/esm/components/Connect/Connect.js.map +1 -1
- package/dist/esm/config/defaultConnectors.d.ts +3 -1
- package/dist/esm/config/defaultConnectors.d.ts.map +1 -1
- package/dist/esm/config/defaultConnectors.js +3 -0
- package/dist/esm/config/defaultConnectors.js.map +1 -1
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/hooks/useChain.d.ts +29 -1
- package/dist/esm/hooks/useChain.d.ts.map +1 -1
- package/dist/esm/hooks/useChain.js +27 -1
- package/dist/esm/hooks/useChain.js.map +1 -1
- package/dist/esm/hooks/useCheckWaasFeeOptions.d.ts +41 -0
- package/dist/esm/hooks/useCheckWaasFeeOptions.d.ts.map +1 -1
- package/dist/esm/hooks/useCheckWaasFeeOptions.js +41 -0
- package/dist/esm/hooks/useCheckWaasFeeOptions.js.map +1 -1
- package/dist/esm/hooks/useDirectEcosystemConnect.d.ts +32 -0
- package/dist/esm/hooks/useDirectEcosystemConnect.d.ts.map +1 -1
- package/dist/esm/hooks/useDirectEcosystemConnect.js +32 -0
- package/dist/esm/hooks/useDirectEcosystemConnect.js.map +1 -1
- package/dist/esm/hooks/useListAccounts.d.ts +39 -0
- package/dist/esm/hooks/useListAccounts.d.ts.map +1 -0
- package/dist/esm/hooks/useListAccounts.js +58 -0
- package/dist/esm/hooks/useListAccounts.js.map +1 -0
- package/dist/esm/hooks/useOpenConnectModal.d.ts +1 -1
- package/dist/esm/hooks/useOpenConnectModal.js +1 -1
- package/dist/esm/hooks/useProjectAccessKey.d.ts +17 -0
- package/dist/esm/hooks/useProjectAccessKey.d.ts.map +1 -1
- package/dist/esm/hooks/useProjectAccessKey.js +17 -0
- package/dist/esm/hooks/useProjectAccessKey.js.map +1 -1
- package/dist/esm/hooks/useSignInEmail.d.ts +20 -0
- package/dist/esm/hooks/useSignInEmail.d.ts.map +1 -1
- package/dist/esm/hooks/useSignInEmail.js +20 -0
- package/dist/esm/hooks/useSignInEmail.js.map +1 -1
- package/dist/esm/hooks/useTheme.d.ts +26 -0
- package/dist/esm/hooks/useTheme.d.ts.map +1 -1
- package/dist/esm/hooks/useTheme.js +26 -0
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/hooks/useWaasConfirmationHandler.d.ts +39 -0
- package/dist/esm/hooks/useWaasConfirmationHandler.d.ts.map +1 -1
- package/dist/esm/hooks/useWaasConfirmationHandler.js +39 -0
- package/dist/esm/hooks/useWaasConfirmationHandler.js.map +1 -1
- package/dist/esm/hooks/useWaasEmailAuth.d.ts +46 -0
- package/dist/esm/hooks/useWaasEmailAuth.d.ts.map +1 -1
- package/dist/esm/hooks/useWaasEmailAuth.js +46 -0
- package/dist/esm/hooks/useWaasEmailAuth.js.map +1 -1
- package/dist/esm/hooks/useWaasEmailConflict.d.ts +39 -0
- package/dist/esm/hooks/useWaasEmailConflict.d.ts.map +1 -1
- package/dist/esm/hooks/useWaasEmailConflict.js +39 -0
- package/dist/esm/hooks/useWaasEmailConflict.js.map +1 -1
- package/dist/esm/hooks/useWaasGetLinkedWalletsSignature.d.ts +60 -0
- package/dist/esm/hooks/useWaasGetLinkedWalletsSignature.d.ts.map +1 -1
- package/dist/esm/hooks/useWaasGetLinkedWalletsSignature.js +50 -0
- package/dist/esm/hooks/useWaasGetLinkedWalletsSignature.js.map +1 -1
- package/dist/esm/hooks/useWaasLinkWallet.d.ts +57 -0
- package/dist/esm/hooks/useWaasLinkWallet.d.ts.map +1 -1
- package/dist/esm/hooks/useWaasLinkWallet.js +42 -0
- package/dist/esm/hooks/useWaasLinkWallet.js.map +1 -1
- package/dist/esm/hooks/useWalletSettings.d.ts +28 -0
- package/dist/esm/hooks/useWalletSettings.d.ts.map +1 -1
- package/dist/esm/hooks/useWalletSettings.js +28 -0
- package/dist/esm/hooks/useWalletSettings.js.map +1 -1
- package/dist/esm/hooks/useWallets.d.ts.map +1 -1
- package/dist/esm/hooks/useWallets.js +17 -1
- package/dist/esm/hooks/useWallets.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -6,5 +6,44 @@ export type WaasRequestConfirmation = {
|
|
|
6
6
|
txs?: commons.transaction.Transaction[];
|
|
7
7
|
chainId?: number;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Hook to handle transaction and message signing confirmations for WaaS (Wallet-as-a-Service) connections.
|
|
11
|
+
*
|
|
12
|
+
* This hook sets up confirmation handlers for signing transactions and messages when using a WaaS connector.
|
|
13
|
+
* It manages the state of pending confirmations and provides functions to confirm or reject signing requests.
|
|
14
|
+
*
|
|
15
|
+
* @param waasConnector - The WaaS connector instance to handle confirmations for (optional)
|
|
16
|
+
*
|
|
17
|
+
* @returns A tuple containing:
|
|
18
|
+
* - [0] {@link WaasRequestConfirmation} | undefined - The current pending request confirmation info or undefined if none
|
|
19
|
+
* - [1] `(id: string) => void` - Function to confirm a pending request by ID
|
|
20
|
+
* - [2] `(id: string) => void` - Function to reject a pending request by ID
|
|
21
|
+
*
|
|
22
|
+
* The {@link WaasRequestConfirmation} object contains:
|
|
23
|
+
* - `id` - Unique identifier for the request
|
|
24
|
+
* - `type` - Either 'signTransaction' or 'signMessage'
|
|
25
|
+
* - `message?` - Optional message to sign (for signMessage requests)
|
|
26
|
+
* - `txs?` - Optional array of transactions (for signTransaction requests)
|
|
27
|
+
* - `chainId?` - Optional chain ID for the request
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const [
|
|
32
|
+
* pendingRequestConfirmation,
|
|
33
|
+
* confirmPendingRequest,
|
|
34
|
+
* rejectPendingRequest
|
|
35
|
+
* ] = useWaasConfirmationHandler(waasConnector)
|
|
36
|
+
*
|
|
37
|
+
* // When user confirms the request
|
|
38
|
+
* if (pendingRequestConfirmation) {
|
|
39
|
+
* confirmPendingRequest(pendingRequestConfirmation.id)
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // When user rejects the request
|
|
43
|
+
* if (pendingRequestConfirmation) {
|
|
44
|
+
* rejectPendingRequest(pendingRequestConfirmation.id)
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
9
48
|
export declare function useWaasConfirmationHandler(waasConnector?: any): [WaasRequestConfirmation | undefined, (id: string) => void, (id: string) => void];
|
|
10
49
|
//# sourceMappingURL=useWaasConfirmationHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasConfirmationHandler.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasConfirmationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAO1C,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,0BAA0B,CACxC,aAAa,CAAC,EAAE,GAAG,GAClB,CAAC,uBAAuB,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,CAkDnF"}
|
|
1
|
+
{"version":3,"file":"useWaasConfirmationHandler.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasConfirmationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAO1C,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,iBAAiB,GAAG,aAAa,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,CAAA;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,CAAC,EAAE,GAAG,GAClB,CAAC,uBAAuB,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,CAkDnF"}
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import { Deferred } from '../utils/deferred';
|
|
3
3
|
let _pendingConfirmation;
|
|
4
|
+
/**
|
|
5
|
+
* Hook to handle transaction and message signing confirmations for WaaS (Wallet-as-a-Service) connections.
|
|
6
|
+
*
|
|
7
|
+
* This hook sets up confirmation handlers for signing transactions and messages when using a WaaS connector.
|
|
8
|
+
* It manages the state of pending confirmations and provides functions to confirm or reject signing requests.
|
|
9
|
+
*
|
|
10
|
+
* @param waasConnector - The WaaS connector instance to handle confirmations for (optional)
|
|
11
|
+
*
|
|
12
|
+
* @returns A tuple containing:
|
|
13
|
+
* - [0] {@link WaasRequestConfirmation} | undefined - The current pending request confirmation info or undefined if none
|
|
14
|
+
* - [1] `(id: string) => void` - Function to confirm a pending request by ID
|
|
15
|
+
* - [2] `(id: string) => void` - Function to reject a pending request by ID
|
|
16
|
+
*
|
|
17
|
+
* The {@link WaasRequestConfirmation} object contains:
|
|
18
|
+
* - `id` - Unique identifier for the request
|
|
19
|
+
* - `type` - Either 'signTransaction' or 'signMessage'
|
|
20
|
+
* - `message?` - Optional message to sign (for signMessage requests)
|
|
21
|
+
* - `txs?` - Optional array of transactions (for signTransaction requests)
|
|
22
|
+
* - `chainId?` - Optional chain ID for the request
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* const [
|
|
27
|
+
* pendingRequestConfirmation,
|
|
28
|
+
* confirmPendingRequest,
|
|
29
|
+
* rejectPendingRequest
|
|
30
|
+
* ] = useWaasConfirmationHandler(waasConnector)
|
|
31
|
+
*
|
|
32
|
+
* // When user confirms the request
|
|
33
|
+
* if (pendingRequestConfirmation) {
|
|
34
|
+
* confirmPendingRequest(pendingRequestConfirmation.id)
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // When user rejects the request
|
|
38
|
+
* if (pendingRequestConfirmation) {
|
|
39
|
+
* rejectPendingRequest(pendingRequestConfirmation.id)
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
4
43
|
export function useWaasConfirmationHandler(waasConnector) {
|
|
5
44
|
const [pendingRequestConfirmation, setPendingRequestConfirmation] = useState();
|
|
6
45
|
function confirmPendingRequest(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasConfirmationHandler.js","sourceRoot":"","sources":["../../../src/hooks/useWaasConfirmationHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,IAAI,oBAA8E,CAAA;AAUlF,MAAM,UAAU,0BAA0B,CACxC,aAAmB;IAEnB,MAAM,CAAC,0BAA0B,EAAE,6BAA6B,CAAC,GAAG,QAAQ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a,CAAC,oBAAoB,CAAA;YAEvD,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAM;YACR,CAAC;YAED,YAAY,CAAC,0BAA0B,GAAG;gBACxC,6BAA6B,CAC3B,EAAU,EACV,GAAsC,EACtC,OAAe;oBAEf,MAAM,OAAO,GAAG,IAAI,QAAQ,EAAsC,CAAA;oBAClE,6BAA6B,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;oBAC9G,oBAAoB,GAAG,OAAO,CAAA;oBAC9B,OAAO,OAAO,CAAC,OAAO,CAAA;gBACxB,CAAC;gBACD,yBAAyB,CAAC,EAAU,EAAE,OAAe,EAAE,OAAe;oBACpE,MAAM,OAAO,GAAG,IAAI,QAAQ,EAAsC,CAAA;oBAClE,6BAA6B,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;oBAC5E,oBAAoB,GAAG,OAAO,CAAA;oBAC9B,OAAO,OAAO,CAAC,OAAO,CAAA;gBACxB,CAAC;aACF,CAAA;QACH,CAAC;QACD,KAAK,EAAE,CAAA;IACT,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,0BAA0B,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAA;AAClF,CAAC"}
|
|
@@ -8,6 +8,52 @@ interface SuccessResultV2 {
|
|
|
8
8
|
version: 2;
|
|
9
9
|
signInResponse: SignInResponse;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook to handle email-based authentication flow for WaaS (Wallet-as-a-Service).
|
|
13
|
+
*
|
|
14
|
+
* This hook manages the complete email authentication process, including:
|
|
15
|
+
* - Initiating email authentication
|
|
16
|
+
* - Handling verification code submission
|
|
17
|
+
* - Managing loading and error states
|
|
18
|
+
* - Supporting both v1 (idToken) and v2 (SignInResponse) authentication formats
|
|
19
|
+
*
|
|
20
|
+
* @param {ExtendedConnector} [params.connector] - The WaaS connector to use for authentication.
|
|
21
|
+
* Optional because the user might not have selected a connector yet.
|
|
22
|
+
* @param {Function} params.onSuccess - Callback function called when authentication succeeds.
|
|
23
|
+
* Receives either a v1 result (with idToken) or v2 result (with SignInResponse).
|
|
24
|
+
*
|
|
25
|
+
* @returns {Object} An object containing:
|
|
26
|
+
* - `inProgress` - Whether authentication is currently in progress
|
|
27
|
+
* - `loading` - Whether a specific authentication operation is loading
|
|
28
|
+
* - `error` - Any error that occurred during authentication
|
|
29
|
+
* - `initiateAuth` - Function to start the email authentication process
|
|
30
|
+
* - `sendChallengeAnswer` - Function to submit the verification code
|
|
31
|
+
* - `cancel` - Function to cancel the authentication process
|
|
32
|
+
* - `resetError` - Function to clear any error state
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const {
|
|
37
|
+
* inProgress,
|
|
38
|
+
* loading,
|
|
39
|
+
* error,
|
|
40
|
+
* initiateAuth,
|
|
41
|
+
* sendChallengeAnswer,
|
|
42
|
+
* resetError
|
|
43
|
+
* } = useEmailAuth({
|
|
44
|
+
* connector: emailConnector,
|
|
45
|
+
* onSuccess: async (result) => {
|
|
46
|
+
* if ('signInResponse' in result) {
|
|
47
|
+
* // Handle v2 authentication
|
|
48
|
+
* await storage.setItem('email', result.signInResponse.email)
|
|
49
|
+
* } else {
|
|
50
|
+
* // Handle v1 authentication
|
|
51
|
+
* await storage.setItem('idToken', result.idToken)
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
11
57
|
export declare function useEmailAuth({ connector, onSuccess }: {
|
|
12
58
|
connector?: ExtendedConnector;
|
|
13
59
|
onSuccess: (result: SuccessResultV1 | SuccessResultV2) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasEmailAuth.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAK/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE5C,UAAU,eAAe;IACvB,OAAO,EAAE,CAAC,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,CAAC,CAAA;IACV,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,SAAS,EACV,EAAE;IACD,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B,SAAS,EAAE,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,KAAK,IAAI,CAAA;CAC/D;;;;2BAYkC,MAAM;mCACE,MAAM;;;;;;;0BAmBZ,MAAM;kCA2BE,MAAM;;;EAwClD"}
|
|
1
|
+
{"version":3,"file":"useWaasEmailAuth.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAK/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE5C,UAAU,eAAe;IACvB,OAAO,EAAE,CAAC,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,CAAC,CAAA;IACV,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,SAAS,EACV,EAAE;IACD,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B,SAAS,EAAE,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,KAAK,IAAI,CAAA;CAC/D;;;;2BAYkC,MAAM;mCACE,MAAM;;;;;;;0BAmBZ,MAAM;kCA2BE,MAAM;;;EAwClD"}
|
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
// import { EmailWaasOptions } from '../connectors/email/emailWaas'
|
|
3
3
|
import { randomName } from '../connectors/wagmiConnectors';
|
|
4
|
+
/**
|
|
5
|
+
* Hook to handle email-based authentication flow for WaaS (Wallet-as-a-Service).
|
|
6
|
+
*
|
|
7
|
+
* This hook manages the complete email authentication process, including:
|
|
8
|
+
* - Initiating email authentication
|
|
9
|
+
* - Handling verification code submission
|
|
10
|
+
* - Managing loading and error states
|
|
11
|
+
* - Supporting both v1 (idToken) and v2 (SignInResponse) authentication formats
|
|
12
|
+
*
|
|
13
|
+
* @param {ExtendedConnector} [params.connector] - The WaaS connector to use for authentication.
|
|
14
|
+
* Optional because the user might not have selected a connector yet.
|
|
15
|
+
* @param {Function} params.onSuccess - Callback function called when authentication succeeds.
|
|
16
|
+
* Receives either a v1 result (with idToken) or v2 result (with SignInResponse).
|
|
17
|
+
*
|
|
18
|
+
* @returns {Object} An object containing:
|
|
19
|
+
* - `inProgress` - Whether authentication is currently in progress
|
|
20
|
+
* - `loading` - Whether a specific authentication operation is loading
|
|
21
|
+
* - `error` - Any error that occurred during authentication
|
|
22
|
+
* - `initiateAuth` - Function to start the email authentication process
|
|
23
|
+
* - `sendChallengeAnswer` - Function to submit the verification code
|
|
24
|
+
* - `cancel` - Function to cancel the authentication process
|
|
25
|
+
* - `resetError` - Function to clear any error state
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const {
|
|
30
|
+
* inProgress,
|
|
31
|
+
* loading,
|
|
32
|
+
* error,
|
|
33
|
+
* initiateAuth,
|
|
34
|
+
* sendChallengeAnswer,
|
|
35
|
+
* resetError
|
|
36
|
+
* } = useEmailAuth({
|
|
37
|
+
* connector: emailConnector,
|
|
38
|
+
* onSuccess: async (result) => {
|
|
39
|
+
* if ('signInResponse' in result) {
|
|
40
|
+
* // Handle v2 authentication
|
|
41
|
+
* await storage.setItem('email', result.signInResponse.email)
|
|
42
|
+
* } else {
|
|
43
|
+
* // Handle v1 authentication
|
|
44
|
+
* await storage.setItem('idToken', result.idToken)
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
4
50
|
export function useEmailAuth({ connector, onSuccess }) {
|
|
5
51
|
const [_email, setEmail] = useState('');
|
|
6
52
|
const [error, setError] = useState();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasEmailAuth.js","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,mEAAmE;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAa1D,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,SAAS,EAIV;IACC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IACvC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAqB,CAAA;IACvD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC7C,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,EAA4C,CAAA;IAElG,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,SAAS;YAChB,YAAY,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE,GAAE,CA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CAAA;IACrB,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,QAAQ,CAAC,SAAS,CAAC,CAAA;IACrB,CAAC,CAAA;IAED,OAAO;QACL,UAAU,EAAE,OAAO,IAAI,CAAC,CAAC,QAAQ;QACjC,OAAO;QACP,KAAK;QACL,YAAY;QACZ,mBAAmB;QACnB,MAAM;QACN,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents formatted email conflict information returned by the hook.
|
|
3
|
+
* This is a user-friendly version of the EmailConflictInfo from the WaaS service.
|
|
4
|
+
*/
|
|
1
5
|
export type FormattedEmailConflictInfo = {
|
|
6
|
+
/** The email address that caused the conflict */
|
|
2
7
|
email: string;
|
|
8
|
+
/** User-friendly description of the account type (e.g., 'Google login', 'Email login') */
|
|
3
9
|
type: string;
|
|
4
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Hook to handle email conflict detection and resolution for WaaS (Wallet-as-a-Service) authentication.
|
|
13
|
+
*
|
|
14
|
+
* This hook monitors all WaaS connectors for email conflicts that occur during sign-in attempts.
|
|
15
|
+
* A conflict happens when a user tries to sign up with an email that's already associated with
|
|
16
|
+
* a different authentication method (e.g., trying to use Google sign-in when the email was
|
|
17
|
+
* previously used with Apple sign-in).
|
|
18
|
+
*
|
|
19
|
+
* @returns An object containing:
|
|
20
|
+
* - `toggleEmailConflictModal` - Function to manually show/hide the conflict modal
|
|
21
|
+
* - `isEmailConflictOpen` - Whether the conflict modal is currently open
|
|
22
|
+
* - `emailConflictInfo` - Formatted information about the conflict (email and account type)
|
|
23
|
+
* - `forceCreate` - Function to force create a new account despite the conflict
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* const {
|
|
28
|
+
* isEmailConflictOpen,
|
|
29
|
+
* emailConflictInfo,
|
|
30
|
+
* toggleEmailConflictModal
|
|
31
|
+
* } = useEmailConflict()
|
|
32
|
+
*
|
|
33
|
+
* // When a conflict is detected
|
|
34
|
+
* if (isEmailConflictOpen && emailConflictInfo) {
|
|
35
|
+
* console.log(
|
|
36
|
+
* `Email ${emailConflictInfo.email} is already used with ${emailConflictInfo.type}`
|
|
37
|
+
* )
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // Close the conflict modal
|
|
41
|
+
* toggleEmailConflictModal(false)
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
5
44
|
export declare const useEmailConflict: () => {
|
|
6
45
|
toggleEmailConflictModal: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
7
46
|
isEmailConflictOpen: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasEmailConflict.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailConflict.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;
|
|
1
|
+
{"version":3,"file":"useWaasEmailConflict.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailConflict.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAA;IACb,0FAA0F;IAC1F,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAmCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,gBAAgB;;;uBAiCpB,0BAA0B;;CAKlC,CAAA"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { IdentityType } from '@0xsequence/waas';
|
|
2
2
|
import { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useConnect } from 'wagmi';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to convert raw account type information into user-friendly text.
|
|
6
|
+
*
|
|
7
|
+
* @param info - The raw email conflict information from WaaS
|
|
8
|
+
* @returns A user-friendly string describing the account type
|
|
9
|
+
*/
|
|
4
10
|
const accountTypeText = (info) => {
|
|
5
11
|
if (!info) {
|
|
6
12
|
return 'Unknown account type';
|
|
@@ -23,6 +29,39 @@ const accountTypeText = (info) => {
|
|
|
23
29
|
}
|
|
24
30
|
return info.type;
|
|
25
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Hook to handle email conflict detection and resolution for WaaS (Wallet-as-a-Service) authentication.
|
|
34
|
+
*
|
|
35
|
+
* This hook monitors all WaaS connectors for email conflicts that occur during sign-in attempts.
|
|
36
|
+
* A conflict happens when a user tries to sign up with an email that's already associated with
|
|
37
|
+
* a different authentication method (e.g., trying to use Google sign-in when the email was
|
|
38
|
+
* previously used with Apple sign-in).
|
|
39
|
+
*
|
|
40
|
+
* @returns An object containing:
|
|
41
|
+
* - `toggleEmailConflictModal` - Function to manually show/hide the conflict modal
|
|
42
|
+
* - `isEmailConflictOpen` - Whether the conflict modal is currently open
|
|
43
|
+
* - `emailConflictInfo` - Formatted information about the conflict (email and account type)
|
|
44
|
+
* - `forceCreate` - Function to force create a new account despite the conflict
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* const {
|
|
49
|
+
* isEmailConflictOpen,
|
|
50
|
+
* emailConflictInfo,
|
|
51
|
+
* toggleEmailConflictModal
|
|
52
|
+
* } = useEmailConflict()
|
|
53
|
+
*
|
|
54
|
+
* // When a conflict is detected
|
|
55
|
+
* if (isEmailConflictOpen && emailConflictInfo) {
|
|
56
|
+
* console.log(
|
|
57
|
+
* `Email ${emailConflictInfo.email} is already used with ${emailConflictInfo.type}`
|
|
58
|
+
* )
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* // Close the conflict modal
|
|
62
|
+
* toggleEmailConflictModal(false)
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
26
65
|
export const useEmailConflict = () => {
|
|
27
66
|
const { connectors } = useConnect();
|
|
28
67
|
const forceCreateFuncRef = useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasEmailConflict.js","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailConflict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmC,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"useWaasEmailConflict.js","sourceRoot":"","sources":["../../../src/hooks/useWaasEmailConflict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmC,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAalC;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,IAA8B,EAAE,EAAE;IACzD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,sBAAsB,CAAA;IAC/B,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,OAAO,EAAE,CAAC;QACvC,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,KAAK,EAAE,CAAC;QACrC,OAAO,aAAa,CAAA;IACtB,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,EAAE,CAAC;QACpC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;YACpB,KAAK,6BAA6B;gBAChC,OAAO,cAAc,CAAA;YACvB,KAAK,2BAA2B;gBAC9B,OAAO,aAAa,CAAA;YACtB;gBACE,OAAO,sBAAsB,CAAA;QACjC,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAA;AA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,mBAAmB,EAAE,MAAM;QAC3B,iBAAiB,EAAE;YACjB,KAAK,EAAE,iBAAiB,EAAE,KAAK,IAAI,SAAS;YAC5C,IAAI,EAAE,eAAe,CAAC,iBAAiB,CAAC;SACX;QAC/B,WAAW,EAAE,KAAK,IAAI,EAAE;YACtB,OAAO,kBAAkB,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;QAC3C,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,13 +1,73 @@
|
|
|
1
1
|
import { Address } from 'viem';
|
|
2
2
|
import { Connector } from 'wagmi';
|
|
3
|
+
/**
|
|
4
|
+
* Result object returned by the useWaasGetLinkedWalletsSignature hook.
|
|
5
|
+
* Contains all necessary information about the signature for wallet linking.
|
|
6
|
+
*/
|
|
3
7
|
interface UseWaasSignatureForLinkingResult {
|
|
8
|
+
/** The message that was signed */
|
|
4
9
|
message: string | undefined;
|
|
10
|
+
/** The signature of the message */
|
|
5
11
|
signature: string | undefined;
|
|
12
|
+
/** The address that signed the message */
|
|
6
13
|
address: string | undefined;
|
|
14
|
+
/** The chain ID used for signing */
|
|
7
15
|
chainId: number;
|
|
16
|
+
/** Whether the signature is currently being generated */
|
|
8
17
|
loading: boolean;
|
|
18
|
+
/** Any error that occurred during signature generation */
|
|
9
19
|
error: Error | null;
|
|
10
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Hook to manage signatures required for linking wallets in a WaaS (Wallet-as-a-Service) context.
|
|
23
|
+
*
|
|
24
|
+
* This hook handles the generation and caching of signatures that are used to prove ownership
|
|
25
|
+
* of a parent wallet when linking child wallets. The signatures are cached in localStorage
|
|
26
|
+
* for 24 hours to avoid unnecessary re-signing.
|
|
27
|
+
*
|
|
28
|
+
* Features:
|
|
29
|
+
* - Automatic signature generation when needed
|
|
30
|
+
* - 24-hour signature caching in localStorage
|
|
31
|
+
* - Automatic cleanup of old signatures
|
|
32
|
+
* - Error handling for signature generation
|
|
33
|
+
*
|
|
34
|
+
* @param connection - The current wallet connection object containing:
|
|
35
|
+
* - accounts: Array of connected addresses (uses the first one)
|
|
36
|
+
* - chainId: The current chain ID
|
|
37
|
+
* - connector: The wallet connector instance
|
|
38
|
+
*
|
|
39
|
+
* @returns An object containing:
|
|
40
|
+
* - `message` - The message that was signed
|
|
41
|
+
* - `signature` - The generated signature
|
|
42
|
+
* - `address` - The address that signed the message
|
|
43
|
+
* - `chainId` - The chain ID used for signing
|
|
44
|
+
* - `loading` - Whether signature generation is in progress
|
|
45
|
+
* - `error` - Any error that occurred during the process
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* const {
|
|
50
|
+
* message,
|
|
51
|
+
* signature,
|
|
52
|
+
* address,
|
|
53
|
+
* loading,
|
|
54
|
+
* error
|
|
55
|
+
* } = useWaasGetLinkedWalletsSignature(waasConnection)
|
|
56
|
+
*
|
|
57
|
+
* if (loading) {
|
|
58
|
+
* return <div>Generating signature...</div>
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* if (error) {
|
|
62
|
+
* return <div>Error: {error.message}</div>
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* if (signature) {
|
|
66
|
+
* // Use the signature for wallet linking
|
|
67
|
+
* console.log(`Got signature from ${address} for message: ${message}`)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
11
71
|
export declare const useWaasGetLinkedWalletsSignature: (connection: {
|
|
12
72
|
accounts: readonly [Address, ...Address[]];
|
|
13
73
|
chainId: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasGetLinkedWalletsSignature.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasGetLinkedWalletsSignature.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,UAAU,gCAAgC;IACxC,OAAO,EA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EAAE,SAAS,CAAA;CACrB,GACD,SAAS,KACZ,gCAwIF,CAAA"}
|
|
@@ -3,6 +3,56 @@ import { useState, useEffect } from 'react';
|
|
|
3
3
|
import { CHAIN_ID_FOR_SIGNATURE } from '../constants/walletLinking';
|
|
4
4
|
const WAAS_SIGNATURE_PREFIX = '@0xsequence.waas_signature-';
|
|
5
5
|
const getSignatureKey = (address) => `${WAAS_SIGNATURE_PREFIX}${address}`;
|
|
6
|
+
/**
|
|
7
|
+
* Hook to manage signatures required for linking wallets in a WaaS (Wallet-as-a-Service) context.
|
|
8
|
+
*
|
|
9
|
+
* This hook handles the generation and caching of signatures that are used to prove ownership
|
|
10
|
+
* of a parent wallet when linking child wallets. The signatures are cached in localStorage
|
|
11
|
+
* for 24 hours to avoid unnecessary re-signing.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Automatic signature generation when needed
|
|
15
|
+
* - 24-hour signature caching in localStorage
|
|
16
|
+
* - Automatic cleanup of old signatures
|
|
17
|
+
* - Error handling for signature generation
|
|
18
|
+
*
|
|
19
|
+
* @param connection - The current wallet connection object containing:
|
|
20
|
+
* - accounts: Array of connected addresses (uses the first one)
|
|
21
|
+
* - chainId: The current chain ID
|
|
22
|
+
* - connector: The wallet connector instance
|
|
23
|
+
*
|
|
24
|
+
* @returns An object containing:
|
|
25
|
+
* - `message` - The message that was signed
|
|
26
|
+
* - `signature` - The generated signature
|
|
27
|
+
* - `address` - The address that signed the message
|
|
28
|
+
* - `chainId` - The chain ID used for signing
|
|
29
|
+
* - `loading` - Whether signature generation is in progress
|
|
30
|
+
* - `error` - Any error that occurred during the process
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const {
|
|
35
|
+
* message,
|
|
36
|
+
* signature,
|
|
37
|
+
* address,
|
|
38
|
+
* loading,
|
|
39
|
+
* error
|
|
40
|
+
* } = useWaasGetLinkedWalletsSignature(waasConnection)
|
|
41
|
+
*
|
|
42
|
+
* if (loading) {
|
|
43
|
+
* return <div>Generating signature...</div>
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* if (error) {
|
|
47
|
+
* return <div>Error: {error.message}</div>
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* if (signature) {
|
|
51
|
+
* // Use the signature for wallet linking
|
|
52
|
+
* console.log(`Got signature from ${address} for message: ${message}`)
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
6
56
|
export const useWaasGetLinkedWalletsSignature = (connection) => {
|
|
7
57
|
const sequenceWaas = connection?.connector?.sequenceWaas;
|
|
8
58
|
const address = connection?.accounts[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasGetLinkedWalletsSignature.js","sourceRoot":"","sources":["../../../src/hooks/useWaasGetLinkedWalletsSignature.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAI3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"useWaasGetLinkedWalletsSignature.js","sourceRoot":"","sources":["../../../src/hooks/useWaasGetLinkedWalletsSignature.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAGZ,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAI3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAqBnE,MAAM,qBAAqB,GAAG,6BAA6B,CAAA;AAC3D,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,GAAG,qBAAqB,GAAG,OAAO,EAAE,CAAA;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,UAMa,EACqB,EAAE;IACpC,MAAM,YAAY,GAA8B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AAO,KAAK,EAAE,CAAC;gBACf,SAAS,CAAC;oBACR,OAAO,EAAE,SAAS;oBAClB,SAAS,EAAE,SAAS;oBACpB,OAAO,EAAE,SAAS;oBAClB,OAAO,EAAE,sBAAsB;oBAC/B,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAc;iBACtB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAA;QAED,YAAY,EAAE,CAAA;IAChB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA,CAAC,uCAAuC;IAErD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1,17 +1,74 @@
|
|
|
1
1
|
import { Connector } from 'wagmi';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters required for linking a child wallet to a parent WaaS wallet.
|
|
4
|
+
*/
|
|
2
5
|
interface LinkWalletParams {
|
|
6
|
+
/** Chain ID used for the signature verification */
|
|
3
7
|
signatureChainId: number;
|
|
8
|
+
/** Name of the connector used by the child wallet */
|
|
4
9
|
connectorName: string;
|
|
10
|
+
/** Address of the child wallet to be linked */
|
|
5
11
|
childWalletAddress: string;
|
|
12
|
+
/** Message signed by the child wallet */
|
|
6
13
|
childMessage: string;
|
|
14
|
+
/** Signature from the child wallet */
|
|
7
15
|
childSignature: string;
|
|
8
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Result object returned by the useWaasLinkWallet hook.
|
|
19
|
+
*/
|
|
9
20
|
interface UseWaasLinkWalletResult {
|
|
21
|
+
/** Function to link a child wallet to the parent WaaS wallet */
|
|
10
22
|
linkWallet: (params: LinkWalletParams) => Promise<void>;
|
|
23
|
+
/** Function to remove a previously linked wallet */
|
|
11
24
|
removeLinkedWallet: (linkedWalletAddress: string) => Promise<void>;
|
|
25
|
+
/** Whether a linking or unlinking operation is in progress */
|
|
12
26
|
loading: boolean;
|
|
27
|
+
/** Any error that occurred during the operation */
|
|
13
28
|
error: Error | null;
|
|
14
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Hook to manage wallet linking operations for WaaS (Wallet-as-a-Service).
|
|
32
|
+
*
|
|
33
|
+
* This hook provides functionality to link and unlink child wallets to/from a parent WaaS wallet.
|
|
34
|
+
* It handles the signature generation and API calls required for the linking process.
|
|
35
|
+
*
|
|
36
|
+
* The linking process involves:
|
|
37
|
+
* 1. Getting the parent WaaS wallet address
|
|
38
|
+
* 2. Signing a message with the parent wallet
|
|
39
|
+
* 3. Submitting both parent and child signatures to the API
|
|
40
|
+
*
|
|
41
|
+
* The unlinking process involves:
|
|
42
|
+
* 1. Getting the parent WaaS wallet address
|
|
43
|
+
* 2. Signing a removal message
|
|
44
|
+
* 3. Submitting the request to the API
|
|
45
|
+
*
|
|
46
|
+
* @param connector - The WaaS connector instance. Optional because the user might not have
|
|
47
|
+
* a WaaS wallet connected yet.
|
|
48
|
+
*
|
|
49
|
+
* @returns An object containing:
|
|
50
|
+
* - `linkWallet` - Function to link a child wallet
|
|
51
|
+
* - `removeLinkedWallet` - Function to remove a linked wallet
|
|
52
|
+
* - `loading` - Whether an operation is in progress
|
|
53
|
+
* - `error` - Any error that occurred
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* const { linkWallet, removeLinkedWallet, loading, error } = useWaasLinkWallet(waasConnector)
|
|
58
|
+
*
|
|
59
|
+
* // Link a wallet
|
|
60
|
+
* await linkWallet({
|
|
61
|
+
* signatureChainId: CHAIN_ID_FOR_SIGNATURE,
|
|
62
|
+
* connectorName: 'MetaMask',
|
|
63
|
+
* childWalletAddress: '0x...',
|
|
64
|
+
* childMessage: 'Link to parent wallet...',
|
|
65
|
+
* childSignature: '0x...'
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Remove a linked wallet
|
|
69
|
+
* await removeLinkedWallet('0x...')
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
15
72
|
export declare const useWaasLinkWallet: (connector: Connector | undefined) => UseWaasLinkWalletResult;
|
|
16
73
|
export {};
|
|
17
74
|
//# sourceMappingURL=useWaasLinkWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWaasLinkWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasLinkWallet.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,UAAU,gBAAgB;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,UAAU,uBAAuB;IAC/B,UAAU,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,kBAAkB,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED,eAAO,MAAM,iBAAiB,GAAI,WAAW,SAAS,GAAG,SAAS,KAAG,uBA4FpE,CAAA"}
|
|
1
|
+
{"version":3,"file":"useWaasLinkWallet.d.ts","sourceRoot":"","sources":["../../../src/hooks/useWaasLinkWallet.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC;;GAEG;AACH,UAAU,gBAAgB;IACxB,mDAAmD;IACnD,gBAAgB,EAAE,MAAM,CAAA;IACxB,qDAAqD;IACrD,aAAa,EAAE,MAAM,CAAA;IACrB,+CAA+C;IAC/C,kBAAkB,EAAE,MAAM,CAAA;IAC1B,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAA;IACpB,sCAAsC;IACtC,cAAc,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,UAAU,uBAAuB;IAC/B,gEAAgE;IAChE,UAAU,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,oDAAoD;IACpD,kBAAkB,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAClE,8DAA8D;IAC9D,OAAO,EAAE,OAAO,CAAA;IAChB,mDAAmD;IACnD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,SAAS,GAAG,SAAS,KAAG,uBA4FpE,CAAA"}
|
|
@@ -2,6 +2,48 @@
|
|
|
2
2
|
import { useAPIClient } from '@0xsequence/hooks';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
import { CHAIN_ID_FOR_SIGNATURE } from '../constants/walletLinking';
|
|
5
|
+
/**
|
|
6
|
+
* Hook to manage wallet linking operations for WaaS (Wallet-as-a-Service).
|
|
7
|
+
*
|
|
8
|
+
* This hook provides functionality to link and unlink child wallets to/from a parent WaaS wallet.
|
|
9
|
+
* It handles the signature generation and API calls required for the linking process.
|
|
10
|
+
*
|
|
11
|
+
* The linking process involves:
|
|
12
|
+
* 1. Getting the parent WaaS wallet address
|
|
13
|
+
* 2. Signing a message with the parent wallet
|
|
14
|
+
* 3. Submitting both parent and child signatures to the API
|
|
15
|
+
*
|
|
16
|
+
* The unlinking process involves:
|
|
17
|
+
* 1. Getting the parent WaaS wallet address
|
|
18
|
+
* 2. Signing a removal message
|
|
19
|
+
* 3. Submitting the request to the API
|
|
20
|
+
*
|
|
21
|
+
* @param connector - The WaaS connector instance. Optional because the user might not have
|
|
22
|
+
* a WaaS wallet connected yet.
|
|
23
|
+
*
|
|
24
|
+
* @returns An object containing:
|
|
25
|
+
* - `linkWallet` - Function to link a child wallet
|
|
26
|
+
* - `removeLinkedWallet` - Function to remove a linked wallet
|
|
27
|
+
* - `loading` - Whether an operation is in progress
|
|
28
|
+
* - `error` - Any error that occurred
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* const { linkWallet, removeLinkedWallet, loading, error } = useWaasLinkWallet(waasConnector)
|
|
33
|
+
*
|
|
34
|
+
* // Link a wallet
|
|
35
|
+
* await linkWallet({
|
|
36
|
+
* signatureChainId: CHAIN_ID_FOR_SIGNATURE,
|
|
37
|
+
* connectorName: 'MetaMask',
|
|
38
|
+
* childWalletAddress: '0x...',
|
|
39
|
+
* childMessage: 'Link to parent wallet...',
|
|
40
|
+
* childSignature: '0x...'
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* // Remove a linked wallet
|
|
44
|
+
* await removeLinkedWallet('0x...')
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
5
47
|
export const useWaasLinkWallet = (connector) => {
|
|
6
48
|
const [loading, setLoading] = useState(false);
|
|
7
49
|
const [error, setError] = useState(null);
|