@huma-finance/shared 0.0.41 → 0.0.42-beta.76
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 +6 -0
- package/dist/cjs/hooks/useAuthErrorHandling.js +65 -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/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 +6 -0
- package/dist/hooks/useAuthErrorHandling.js +60 -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/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,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type AuthState = {
|
|
3
|
+
isWalletOwnershipVerified: boolean;
|
|
4
|
+
setError: React.Dispatch<React.SetStateAction<unknown>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const useAuthErrorHandling: (address: string | undefined, chainId: number | undefined, isDev: boolean) => AuthState;
|
|
@@ -0,0 +1,65 @@
|
|
|
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.__importDefault(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 = (address, chainId, isDev) => {
|
|
34
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
35
|
+
const [isVerified, setIsVerified] = (0, react_1.useState)(false);
|
|
36
|
+
const { provider } = (0, core_1.useWeb3React)();
|
|
37
|
+
const throwError = (0, useAsyncError_1.useAsyncError)();
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
if (address === undefined ||
|
|
41
|
+
chainId === undefined ||
|
|
42
|
+
error === null ||
|
|
43
|
+
provider === undefined) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (axios_1.default.isAxiosError(error) &&
|
|
47
|
+
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 &&
|
|
48
|
+
[
|
|
49
|
+
'IdTokenNotFoundException',
|
|
50
|
+
'InvalidIdTokenException',
|
|
51
|
+
'WalletMismatchException',
|
|
52
|
+
].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)) {
|
|
53
|
+
verifyOwnership(address, chainId, isDev, provider, () => setIsVerified(true)).catch((e) => throwError(e));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throwError(error);
|
|
57
|
+
}
|
|
58
|
+
}, [chainId, isDev, error, throwError, address, provider]);
|
|
59
|
+
return {
|
|
60
|
+
isWalletOwnershipVerified: isVerified,
|
|
61
|
+
setError,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.useAuthErrorHandling = useAuthErrorHandling;
|
|
65
|
+
//# sourceMappingURL=useAuthErrorHandling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAuthErrorHandling.js","sourceRoot":"","sources":["../../../src/hooks/useAuthErrorHandling.ts"],"names":[],"mappings":";;;;AAAA,iCAA2C;AAC3C,0DAAyB;AACzB,+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,KAAK,CAAC,CAAA;IAC5E,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IACrE,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAA;IACzC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,OAAO,C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,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;IAE1D,OAAO;QACL,yBAAyB,EAAE,UAAU;QACrC,QAAQ;KACT,CAAA;AACH,CAAC,CAAA;AAxCY,QAAA,oBAAoB,wBAwChC"}
|
|
@@ -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"}
|
|
@@ -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,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@ 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,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export type AuthState = {
|
|
3
|
+
isWalletOwnershipVerified: boolean;
|
|
4
|
+
setError: React.Dispatch<React.SetStateAction<unknown>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const useAuthErrorHandling: (address: string | undefined, chainId: number | undefined, isDev: boolean) => AuthState;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import axios 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 = (address, chainId, isDev) => {
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const [isVerified, setIsVerified] = useState(false);
|
|
32
|
+
const { provider } = useWeb3React();
|
|
33
|
+
const throwError = useAsyncError();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
var _a, _b, _c, _d;
|
|
36
|
+
if (address === undefined ||
|
|
37
|
+
chainId === undefined ||
|
|
38
|
+
error === null ||
|
|
39
|
+
provider === undefined) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (axios.isAxiosError(error) &&
|
|
43
|
+
((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401 &&
|
|
44
|
+
[
|
|
45
|
+
'IdTokenNotFoundException',
|
|
46
|
+
'InvalidIdTokenException',
|
|
47
|
+
'WalletMismatchException',
|
|
48
|
+
].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)) {
|
|
49
|
+
verifyOwnership(address, chainId, isDev, provider, () => setIsVerified(true)).catch((e) => throwError(e));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throwError(error);
|
|
53
|
+
}
|
|
54
|
+
}, [chainId, isDev, error, throwError, address, provider]);
|
|
55
|
+
return {
|
|
56
|
+
isWalletOwnershipVerified: isVerified,
|
|
57
|
+
setError,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=useAuthErrorHandling.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAA;IAE1D,OAAO;QACL,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"}
|
|
@@ -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"}
|