@huma-finance/shared 0.0.41 → 0.0.42-beta.91
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/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useAsyncError.d.ts +1 -1
- package/dist/cjs/hooks/useAsyncError.js +1 -1
- package/dist/cjs/hooks/useAuthErrorHandling.d.ts +7 -0
- package/dist/cjs/hooks/useAuthErrorHandling.js +68 -0
- package/dist/cjs/hooks/useAuthErrorHandling.js.map +1 -0
- package/dist/cjs/services/AuthService.d.ts +8 -0
- package/dist/cjs/services/AuthService.js +14 -0
- package/dist/cjs/services/AuthService.js.map +1 -0
- package/dist/cjs/services/EAService.js +2 -2
- package/dist/cjs/services/IdentityService.js +2 -2
- package/dist/cjs/services/index.d.ts +1 -0
- package/dist/cjs/services/index.js +1 -0
- package/dist/cjs/services/index.js.map +1 -1
- package/dist/cjs/utils/request.js +3 -0
- package/dist/cjs/utils/request.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useAsyncError.d.ts +1 -1
- package/dist/hooks/useAsyncError.js +1 -1
- package/dist/hooks/useAuthErrorHandling.d.ts +7 -0
- package/dist/hooks/useAuthErrorHandling.js +63 -0
- package/dist/hooks/useAuthErrorHandling.js.map +1 -0
- package/dist/services/AuthService.d.ts +8 -0
- package/dist/services/AuthService.js +11 -0
- package/dist/services/AuthService.js.map +1 -0
- package/dist/services/EAService.js +2 -2
- package/dist/services/IdentityService.js +2 -2
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/request.js +3 -0
- package/dist/utils/request.js.map +1 -1
- package/package.json +3 -2
|
@@ -2,6 +2,7 @@ export * from './useERC2612Permit';
|
|
|
2
2
|
export * from './web3';
|
|
3
3
|
export * from './useActiveRoute';
|
|
4
4
|
export * from './useAsyncError';
|
|
5
|
+
export * from './useAuthErrorHandling';
|
|
5
6
|
export * from './useCLPoolContract';
|
|
6
7
|
export * from './useContract';
|
|
7
8
|
export * from './useContractFunction';
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./useERC2612Permit"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./web3"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./useActiveRoute"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./useAsyncError"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useAuthErrorHandling"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./useCLPoolContract"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./useContract"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./useContractFunction"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.tsx"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,iDAAsB;AACtB,2DAAgC;AAChC,0DAA+B;AAC/B,8DAAmC;AACnC,wDAA6B;AAC7B,gEAAqC;AACrC,yDAA8B;AAC9B,4DAAiC;AACjC,kEAAuC;AACvC,kDAAuB;AACvB,qDAA0B;AAC1B,4DAAiC;AACjC,oDAAyB;AACzB,4DAAiC;AACjC,8DAAmC;AACnC,uDAA4B;AAC5B,wDAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.tsx"],"names":[],"mappings":";;;AAAA,6DAAkC;AAClC,iDAAsB;AACtB,2DAAgC;AAChC,0DAA+B;AAC/B,iEAAsC;AACtC,8DAAmC;AACnC,wDAA6B;AAC7B,gEAAqC;AACrC,yDAA8B;AAC9B,4DAAiC;AACjC,kEAAuC;AACvC,kDAAuB;AACvB,qDAA0B;AAC1B,4DAAiC;AACjC,oDAAyB;AACzB,4DAAiC;AACjC,8DAAmC;AACnC,uDAA4B;AAC5B,wDAA6B"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useAsyncError = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
/**
|
|
6
|
-
* Throws an error from outside
|
|
6
|
+
* Throws an error from outside the React lifecycle.
|
|
7
7
|
* Errors thrown through this method will correctly trigger the ErrorBoundary.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type AuthState = {
|
|
3
|
+
isWalletOwnershipVerificationRequired: boolean;
|
|
4
|
+
isWalletOwnershipVerified: boolean;
|
|
5
|
+
setError: React.Dispatch<React.SetStateAction<unknown>>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useAuthErrorHandling: (isDev: boolean) => AuthState;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAuthErrorHandling = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const axios_1 = tslib_1.__importStar(require("axios"));
|
|
7
|
+
const siwe_1 = require("siwe");
|
|
8
|
+
const core_1 = require("@web3-react/core");
|
|
9
|
+
const useAsyncError_1 = require("./useAsyncError");
|
|
10
|
+
const services_1 = require("../services");
|
|
11
|
+
const createSiweMessage = (address, chainId, nonce, expiresAt) => {
|
|
12
|
+
const domain = window.location.hostname;
|
|
13
|
+
const message = new siwe_1.SiweMessage({
|
|
14
|
+
domain,
|
|
15
|
+
address,
|
|
16
|
+
statement: 'Please sign in to verify your ownership of this wallet',
|
|
17
|
+
uri: window.location.origin,
|
|
18
|
+
version: '1',
|
|
19
|
+
chainId,
|
|
20
|
+
nonce,
|
|
21
|
+
expirationTime: expiresAt,
|
|
22
|
+
});
|
|
23
|
+
return message.prepareMessage();
|
|
24
|
+
};
|
|
25
|
+
const verifyOwnership = async (address, chainId, isDev, provider, onVerificationComplete) => {
|
|
26
|
+
const { nonce, expiresAt } = await services_1.AuthService.createSession(chainId, isDev);
|
|
27
|
+
const message = createSiweMessage(address, chainId, nonce, expiresAt);
|
|
28
|
+
const signer = await provider.getSigner();
|
|
29
|
+
const signature = await signer.signMessage(message);
|
|
30
|
+
await services_1.AuthService.verifySignature(message, signature, chainId, isDev);
|
|
31
|
+
onVerificationComplete();
|
|
32
|
+
};
|
|
33
|
+
const useAuthErrorHandling = (isDev) => {
|
|
34
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
35
|
+
const [isVerificationRequired, setIsVerificationRequired] = (0, react_1.useState)(false);
|
|
36
|
+
const [isVerified, setIsVerified] = (0, react_1.useState)(false);
|
|
37
|
+
const { account, chainId, provider } = (0, core_1.useWeb3React)();
|
|
38
|
+
const throwError = (0, useAsyncError_1.useAsyncError)();
|
|
39
|
+
const handleVerificationCompletion = () => {
|
|
40
|
+
setIsVerified(true);
|
|
41
|
+
};
|
|
42
|
+
(0, react_1.useEffect)(() => {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
if (!account || !chainId || !error || !provider) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (axios_1.default.isAxiosError(error) &&
|
|
48
|
+
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === axios_1.HttpStatusCode.Unauthorized &&
|
|
49
|
+
[
|
|
50
|
+
'IdTokenNotFoundException',
|
|
51
|
+
'InvalidIdTokenException',
|
|
52
|
+
'WalletMismatchException',
|
|
53
|
+
].includes((_d = (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.detail) === null || _d === void 0 ? void 0 : _d.type)) {
|
|
54
|
+
setIsVerificationRequired(true);
|
|
55
|
+
verifyOwnership(account, chainId, isDev, provider, handleVerificationCompletion).catch((e) => throwError(e));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throwError(error);
|
|
59
|
+
}
|
|
60
|
+
}, [chainId, isDev, error, throwError, account, provider]);
|
|
61
|
+
return {
|
|
62
|
+
isWalletOwnershipVerificationRequired: isVerificationRequired,
|
|
63
|
+
isWalletOwnershipVerified: isVerified,
|
|
64
|
+
setError,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.useAuthErrorHandling = useAuthErrorHandling;
|
|
68
|
+
//# sourceMappingURL=useAuthErrorHandling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthErrorHandling.js","sourceRoot":"","sources":["../../../src/hooks/useAuthErrorHandling.ts"],"names":[],"mappings":";;;;AAAA,iCAA2C;AAC3C,uDAA6C;AAC7C,+BAAkC;AAClC,2CAA+C;AAE/C,mDAA+C;AAC/C,0CAAyC;AAEzC,MAAM,iBAAiB,GAAG,CACxB,OAAe,EACf,OAAe,EACf,KAAa,EACb,SAAiB,EACjB,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAA;IACvC,MAAM,OAAO,GAAG,IAAI,kBAAW,CAAC;QAC9B,MAAM;QACN,OAAO;QACP,SAAS,EAAE,wDAAwD;QACnE,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,GAAG;QACZ,OAAO;QACP,KAAK;QACL,cAAc,EAAE,SAAS;KAC1B,CAAC,CAAA;IACF,OAAO,OAAO,CAAC,cAAc,EAAE,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,KAAK,EAC3B,OAAe,EACf,OAAe,EACf,KAAc,EACd,QAAyB,EACzB,sBAAkC,EAClC,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,sBAAW,CAAC,aAAa,CAAC,OAAO,EAAE,KAA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yBAAyB;aAC1B,CAAC,QAAQ,CAAC,MAAA,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,MAAM,0CAAE,IAAI,CAAC,EAC9C;YACA,yBAAyB,CAAC,IAAI,CAAC,CAAA;YAC/B,eAAe,CACb,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,EACR,4BAA4B,CAC7B,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;SAC9B;aAAM;YACL,UAAU,CAAC,KAAK,CAAC,CAAA;SAClB;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;IAE1D,OAAO;QACL,qCAAqC,EAAE,sBAAsB;QAC7D,yBAAyB,EAAE,UAAU;QACrC,QAAQ;KACT,CAAA;AACH,CAAC,CAAA;AA1CY,QAAA,oBAAoB,wBA0ChC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CreateSessionResult = {
|
|
2
|
+
nonce: string;
|
|
3
|
+
expiresAt: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const AuthService: {
|
|
6
|
+
createSession: (chainId: number, isDev?: boolean) => Promise<CreateSessionResult>;
|
|
7
|
+
verifySignature: (message: string, signature: string, chainId: number, isDev?: boolean) => Promise<null>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthService = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const createSession = async (chainId, isDev = false) => (0, utils_1.requestPost)(`${utils_1.configUtil.getAuthServiceUrl(chainId, isDev)}/session`);
|
|
6
|
+
const verifySignature = async (message, signature, chainId, isDev = false) => (0, utils_1.requestPost)(`${utils_1.configUtil.getAuthServiceUrl(chainId, isDev)}/verify-signature`, {
|
|
7
|
+
message,
|
|
8
|
+
signature,
|
|
9
|
+
});
|
|
10
|
+
exports.AuthService = {
|
|
11
|
+
createSession,
|
|
12
|
+
verifySignature,
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=AuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/AuthService.ts"],"names":[],"mappings":";;;AAAA,oCAAkD;AAOlD,MAAM,aAAa,GAAG,KAAK,EACzB,OAAe,EACf,QAAiB,KAAK,EACQ,EAAE,CAChC,IAAA,mBAAW,EACT,GAAG,kBAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAC1D,CAAA;AAEH,MAAM,eAAe,GAAG,KAAK,EAC3B,OAAe,EACf,SAAiB,EACjB,OAAe,EACf,QAAiB,KAAK,EACP,EAAE,CACjB,IAAA,mBAAW,EACT,GAAG,kBAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,mBAAmB,EAClE;IACE,OAAO;IACP,SAAS;CACV,CACF,CAAA;AAEU,QAAA,WAAW,GAAG;IACzB,aAAa;IACb,eAAe;CAChB,CAAA"}
|
|
@@ -40,8 +40,8 @@ const approve = async (payload, chainId, isDev = false) => {
|
|
|
40
40
|
return result;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
|
-
* Checks whether
|
|
44
|
-
* Note that this does not approve a creditline in Huma's pools and an approve call is still required.
|
|
43
|
+
* Checks whether a credit underwriting request to Huma's EAVerse would be approved.
|
|
44
|
+
* Note that this does not approve a creditline in Huma's pools and an `approve` call is still required.
|
|
45
45
|
*
|
|
46
46
|
* @param {EAPreapprovalPayload} payload The payload for the underwrite approval.
|
|
47
47
|
* @param {number} chainId The chain ID.
|
|
@@ -50,7 +50,7 @@ const onboard = async (walletAddress, code, pool, chainId, isDev = false) => (0,
|
|
|
50
50
|
/**
|
|
51
51
|
* Get document signature status
|
|
52
52
|
*
|
|
53
|
-
* @param {string} envelopeId The envelope
|
|
53
|
+
* @param {string} envelopeId The envelope ID.
|
|
54
54
|
* @param {number} chainId chain ID.
|
|
55
55
|
* @param {boolean} isDev Is dev environment or not.
|
|
56
56
|
* @returns {Promise<{envelopeId: string}>} Promise that returns the envelope ID
|
|
@@ -68,7 +68,7 @@ const requestDocSignature = async (walletAddress, chainId, isDev = false) => (0,
|
|
|
68
68
|
/**
|
|
69
69
|
* Resend document signature link
|
|
70
70
|
*
|
|
71
|
-
* @param {string} envelopeId The envelope
|
|
71
|
+
* @param {string} envelopeId The envelope ID.
|
|
72
72
|
* @param {number} chainId chain ID.
|
|
73
73
|
* @param {boolean} isDev Is dev environment or not.
|
|
74
74
|
* @returns {Promise<{envelopeId: string}>} Promise that returns the envelope ID
|
|
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./EAService"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./RNService"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./IdentityService"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./AuthService"), exports);
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,sDAA2B;AAC3B,4DAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,sDAA2B;AAC3B,4DAAiC;AACjC,wDAA6B"}
|
|
@@ -9,6 +9,7 @@ const requestGet = async (url) => {
|
|
|
9
9
|
headers: {
|
|
10
10
|
'Content-Type': 'application/json',
|
|
11
11
|
},
|
|
12
|
+
withCredentials: true,
|
|
12
13
|
};
|
|
13
14
|
// @ts-ignore
|
|
14
15
|
return axios_1.default.get(url, {}, config).then((response) => response.data);
|
|
@@ -22,6 +23,7 @@ payload) => {
|
|
|
22
23
|
headers: {
|
|
23
24
|
'Content-Type': 'application/json',
|
|
24
25
|
},
|
|
26
|
+
withCredentials: true,
|
|
25
27
|
};
|
|
26
28
|
return (axios_1.default
|
|
27
29
|
.post(url, payload, config)
|
|
@@ -36,6 +38,7 @@ const requestPut = async (url, payload) => {
|
|
|
36
38
|
headers: {
|
|
37
39
|
'Content-Type': 'application/json',
|
|
38
40
|
},
|
|
41
|
+
withCredentials: true,
|
|
39
42
|
};
|
|
40
43
|
return (axios_1.default
|
|
41
44
|
.put(url, payload, config)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AAElB,MAAM,UAAU,GAAG,KAAK,EAAK,GAAW,EAAc,EAAE;IAC7D,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AAElB,MAAM,UAAU,GAAG,KAAK,EAAK,GAAW,EAAc,EAAE;IAC7D,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,eAAe,EAAE,IAAI;KACtB,CAAA;IAED,aAAa;IACb,OAAO,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAS,CAAC,CAAA;AAC1E,CAAC,CAAA;AAXY,QAAA,UAAU,cAWtB;AAEM,MAAM,WAAW,GAAG,KAAK,EAC9B,GAAW;AACX,8DAA8D;AAC9D,OAAa,EACD,EAAE;IACd,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,eAAe,EAAE,IAAI;KACtB,CAAA;IAED,OAAO,CACL,eAAK;SACF,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC;QAC3B,aAAa;SACZ,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAS,CAAC,CAC1C,CAAA;AACH,CAAC,CAAA;AAnBY,QAAA,WAAW,eAmBvB;AAED,8DAA8D;AACvD,MAAM,UAAU,GAAG,KAAK,EAAK,GAAW,EAAE,OAAa,EAAc,EAAE;IAC5E,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,eAAe,EAAE,IAAI;KACtB,CAAA;IAED,OAAO,CACL,eAAK;SACF,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC;QAC1B,aAAa;SACZ,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAS,CAAC,CAC1C,CAAA;AACH,CAAC,CAAA;AAfY,QAAA,UAAU,cAetB"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useERC2612Permit';
|
|
|
2
2
|
export * from './web3';
|
|
3
3
|
export * from './useActiveRoute';
|
|
4
4
|
export * from './useAsyncError';
|
|
5
|
+
export * from './useAuthErrorHandling';
|
|
5
6
|
export * from './useCLPoolContract';
|
|
6
7
|
export * from './useContract';
|
|
7
8
|
export * from './useContractFunction';
|
package/dist/hooks/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from './useERC2612Permit';
|
|
|
2
2
|
export * from './web3';
|
|
3
3
|
export * from './useActiveRoute';
|
|
4
4
|
export * from './useAsyncError';
|
|
5
|
+
export * from './useAuthErrorHandling';
|
|
5
6
|
export * from './useCLPoolContract';
|
|
6
7
|
export * from './useContract';
|
|
7
8
|
export * from './useContractFunction';
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.tsx"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,QAAQ,CAAA;AACtB,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,yBAAyB,CAAA;AACvC,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type AuthState = {
|
|
3
|
+
isWalletOwnershipVerificationRequired: boolean;
|
|
4
|
+
isWalletOwnershipVerified: boolean;
|
|
5
|
+
setError: React.Dispatch<React.SetStateAction<unknown>>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useAuthErrorHandling: (isDev: boolean) => AuthState;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import axios, { HttpStatusCode } from 'axios';
|
|
3
|
+
import { SiweMessage } from 'siwe';
|
|
4
|
+
import { useWeb3React } from '@web3-react/core';
|
|
5
|
+
import { useAsyncError } from './useAsyncError';
|
|
6
|
+
import { AuthService } from '../services';
|
|
7
|
+
const createSiweMessage = (address, chainId, nonce, expiresAt) => {
|
|
8
|
+
const domain = window.location.hostname;
|
|
9
|
+
const message = new SiweMessage({
|
|
10
|
+
domain,
|
|
11
|
+
address,
|
|
12
|
+
statement: 'Please sign in to verify your ownership of this wallet',
|
|
13
|
+
uri: window.location.origin,
|
|
14
|
+
version: '1',
|
|
15
|
+
chainId,
|
|
16
|
+
nonce,
|
|
17
|
+
expirationTime: expiresAt,
|
|
18
|
+
});
|
|
19
|
+
return message.prepareMessage();
|
|
20
|
+
};
|
|
21
|
+
const verifyOwnership = async (address, chainId, isDev, provider, onVerificationComplete) => {
|
|
22
|
+
const { nonce, expiresAt } = await AuthService.createSession(chainId, isDev);
|
|
23
|
+
const message = createSiweMessage(address, chainId, nonce, expiresAt);
|
|
24
|
+
const signer = await provider.getSigner();
|
|
25
|
+
const signature = await signer.signMessage(message);
|
|
26
|
+
await AuthService.verifySignature(message, signature, chainId, isDev);
|
|
27
|
+
onVerificationComplete();
|
|
28
|
+
};
|
|
29
|
+
export const useAuthErrorHandling = (isDev) => {
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const [isVerificationRequired, setIsVerificationRequired] = useState(false);
|
|
32
|
+
const [isVerified, setIsVerified] = useState(false);
|
|
33
|
+
const { account, chainId, provider } = useWeb3React();
|
|
34
|
+
const throwError = useAsyncError();
|
|
35
|
+
const handleVerificationCompletion = () => {
|
|
36
|
+
setIsVerified(true);
|
|
37
|
+
};
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
if (!account || !chainId || !error || !provider) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (axios.isAxiosError(error) &&
|
|
44
|
+
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === HttpStatusCode.Unauthorized &&
|
|
45
|
+
[
|
|
46
|
+
'IdTokenNotFoundException',
|
|
47
|
+
'InvalidIdTokenException',
|
|
48
|
+
'WalletMismatchException',
|
|
49
|
+
].includes((_d = (_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.detail) === null || _d === void 0 ? void 0 : _d.type)) {
|
|
50
|
+
setIsVerificationRequired(true);
|
|
51
|
+
verifyOwnership(account, chainId, isDev, provider, handleVerificationCompletion).catch((e) => throwError(e));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
throwError(error);
|
|
55
|
+
}
|
|
56
|
+
}, [chainId, isDev, error, throwError, account, provider]);
|
|
57
|
+
return {
|
|
58
|
+
isWalletOwnershipVerificationRequired: isVerificationRequired,
|
|
59
|
+
isWalletOwnershipVerified: isVerified,
|
|
60
|
+
setError,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=useAuthErrorHandling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthErrorHandling.js","sourceRoot":"","sources":["../../src/hooks/useAuthErrorHandling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAA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,CAAA;IAE1D,OAAO;QACL,qCAAqC,EAAE,sBAAsB;QAC7D,yBAAyB,EAAE,UAAU;QACrC,QAAQ;KACT,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type CreateSessionResult = {
|
|
2
|
+
nonce: string;
|
|
3
|
+
expiresAt: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const AuthService: {
|
|
6
|
+
createSession: (chainId: number, isDev?: boolean) => Promise<CreateSessionResult>;
|
|
7
|
+
verifySignature: (message: string, signature: string, chainId: number, isDev?: boolean) => Promise<null>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { configUtil, requestPost } from '../utils';
|
|
2
|
+
const createSession = async (chainId, isDev = false) => requestPost(`${configUtil.getAuthServiceUrl(chainId, isDev)}/session`);
|
|
3
|
+
const verifySignature = async (message, signature, chainId, isDev = false) => requestPost(`${configUtil.getAuthServiceUrl(chainId, isDev)}/verify-signature`, {
|
|
4
|
+
message,
|
|
5
|
+
signature,
|
|
6
|
+
});
|
|
7
|
+
export const AuthService = {
|
|
8
|
+
createSession,
|
|
9
|
+
verifySignature,
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=AuthService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../src/services/AuthService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAOlD,MAAM,aAAa,GAAG,KAAK,EACzB,OAAe,EACf,QAAiB,KAAK,EACQ,EAAE,CAChC,WAAW,CACT,GAAG,UAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,UAAU,CAC1D,CAAA;AAEH,MAAM,eAAe,GAAG,KAAK,EAC3B,OAAe,EACf,SAAiB,EACjB,OAAe,EACf,QAAiB,KAAK,EACP,EAAE,CACjB,WAAW,CACT,GAAG,UAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,mBAAmB,EAClE;IACE,OAAO;IACP,SAAS;CACV,CACF,CAAA;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,aAAa;IACb,eAAe;CAChB,CAAA"}
|
|
@@ -37,8 +37,8 @@ const approve = async (payload, chainId, isDev = false) => {
|
|
|
37
37
|
return result;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
-
* Checks whether
|
|
41
|
-
* Note that this does not approve a creditline in Huma's pools and an approve call is still required.
|
|
40
|
+
* Checks whether a credit underwriting request to Huma's EAVerse would be approved.
|
|
41
|
+
* Note that this does not approve a creditline in Huma's pools and an `approve` call is still required.
|
|
42
42
|
*
|
|
43
43
|
* @param {EAPreapprovalPayload} payload The payload for the underwrite approval.
|
|
44
44
|
* @param {number} chainId The chain ID.
|
|
@@ -47,7 +47,7 @@ const onboard = async (walletAddress, code, pool, chainId, isDev = false) => req
|
|
|
47
47
|
/**
|
|
48
48
|
* Get document signature status
|
|
49
49
|
*
|
|
50
|
-
* @param {string} envelopeId The envelope
|
|
50
|
+
* @param {string} envelopeId The envelope ID.
|
|
51
51
|
* @param {number} chainId chain ID.
|
|
52
52
|
* @param {boolean} isDev Is dev environment or not.
|
|
53
53
|
* @returns {Promise<{envelopeId: string}>} Promise that returns the envelope ID
|
|
@@ -65,7 +65,7 @@ const requestDocSignature = async (walletAddress, chainId, isDev = false) => req
|
|
|
65
65
|
/**
|
|
66
66
|
* Resend document signature link
|
|
67
67
|
*
|
|
68
|
-
* @param {string} envelopeId The envelope
|
|
68
|
+
* @param {string} envelopeId The envelope ID.
|
|
69
69
|
* @param {number} chainId chain ID.
|
|
70
70
|
* @param {boolean} isDev Is dev environment or not.
|
|
71
71
|
* @returns {Promise<{envelopeId: string}>} Promise that returns the envelope ID
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA"}
|