@mezo-org/passport 0.3.0 → 0.4.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/api/auth.d.ts +73 -0
- package/dist/src/api/auth.d.ts.map +1 -0
- package/dist/src/api/auth.js +108 -0
- package/dist/src/api/auth.js.map +1 -0
- package/dist/src/hooks/constants.d.ts +7 -0
- package/dist/src/hooks/constants.d.ts.map +1 -0
- package/dist/src/hooks/constants.js +7 -0
- package/dist/src/hooks/constants.js.map +1 -0
- package/dist/src/hooks/index.d.ts +13 -0
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +13 -0
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts +2 -0
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -0
- package/dist/src/hooks/useAuthApiClient.js +6 -0
- package/dist/src/hooks/useAuthApiClient.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +204 -0
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -0
- package/dist/src/hooks/useCreateAccount.js +23 -0
- package/dist/src/hooks/useCreateAccount.js.map +1 -0
- package/dist/src/hooks/useCreateSession.d.ts +246 -0
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -0
- package/dist/src/hooks/useCreateSession.js +35 -0
- package/dist/src/hooks/useCreateSession.js.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts +6 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.js +18 -0
- package/dist/src/hooks/useGetAccountByAddress.js.map +1 -0
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +6 -0
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useGetAccountByMezoId.js +18 -0
- package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -0
- package/dist/src/hooks/useGetCurrentAccount.d.ts +12 -0
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -0
- package/dist/src/hooks/useGetCurrentAccount.js +15 -0
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -0
- package/dist/src/hooks/useGetSession.d.ts +21 -0
- package/dist/src/hooks/useGetSession.d.ts.map +1 -0
- package/dist/src/hooks/useGetSession.js +15 -0
- package/dist/src/hooks/useGetSession.js.map +1 -0
- package/dist/src/hooks/useLinkAccount.d.ts +178 -0
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -0
- package/dist/src/hooks/useLinkAccount.js +32 -0
- package/dist/src/hooks/useLinkAccount.js.map +1 -0
- package/dist/src/hooks/usePassportContext.d.ts +3 -0
- package/dist/src/hooks/usePassportContext.d.ts.map +1 -0
- package/dist/src/hooks/usePassportContext.js +10 -0
- package/dist/src/hooks/usePassportContext.js.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts +242 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.js +36 -0
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts +242 -0
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignInWithWallet.js +48 -0
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -0
- package/dist/src/hooks/useSignOut.d.ts +88 -0
- package/dist/src/hooks/useSignOut.d.ts.map +1 -0
- package/dist/src/hooks/useSignOut.js +17 -0
- package/dist/src/hooks/useSignOut.js.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts +160 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.js +23 -0
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/provider.d.ts +20 -0
- package/dist/src/provider.d.ts.map +1 -0
- package/dist/src/provider.js +25 -0
- package/dist/src/provider.js.map +1 -0
- package/dist/src/utils/siww.d.ts +4 -0
- package/dist/src/utils/siww.d.ts.map +1 -0
- package/dist/src/utils/siww.js +19 -0
- package/dist/src/utils/siww.js.map +1 -0
- package/dist/src/utils/time.d.ts +5 -0
- package/dist/src/utils/time.d.ts.map +1 -0
- package/dist/src/utils/time.js +5 -0
- package/dist/src/utils/time.js.map +1 -0
- package/package.json +6 -4
- package/src/api/auth.ts +203 -0
- package/src/hooks/constants.ts +6 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useAuthApiClient.ts +6 -0
- package/src/hooks/useCreateAccount.ts +27 -0
- package/src/hooks/useCreateSession.ts +38 -0
- package/src/hooks/useGetAccountByAddress.ts +19 -0
- package/src/hooks/useGetAccountByMezoId.ts +19 -0
- package/src/hooks/useGetCurrentAccount.ts +16 -0
- package/src/hooks/useGetSession.ts +15 -0
- package/src/hooks/useLinkAccount.ts +45 -0
- package/src/hooks/usePassportContext.ts +11 -0
- package/src/hooks/useSignInWithDiscord.ts +44 -0
- package/src/hooks/useSignInWithWallet.ts +61 -0
- package/src/hooks/useSignOut.ts +19 -0
- package/src/hooks/useUpdateMezoId.ts +25 -0
- package/src/index.ts +1 -0
- package/src/provider.ts +57 -0
- package/src/utils/siww.ts +31 -0
- package/src/utils/time.ts +4 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSignOut.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,CAAC,kBAAkB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
export function useSignOut(useMutationOptions = {}) {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
8
|
+
mutationFn: () => authApiClient.deleteSession(),
|
|
9
|
+
onSuccess: () => {
|
|
10
|
+
queryClient.resetQueries({ queryKey: [QUERY_KEYS.SESSION], exact: false });
|
|
11
|
+
queryClient.resetQueries({ queryKey: [QUERY_KEYS.CURRENT_ACCOUNT] });
|
|
12
|
+
},
|
|
13
|
+
...useMutationOptions,
|
|
14
|
+
});
|
|
15
|
+
return { signOut: mutate, signOutAsync: mutateAsync, ...rest };
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useSignOut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSignOut.js","sourceRoot":"","sources":["../../../src/hooks/useSignOut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,UAAU,UAAU,CAAC,kBAAkB,GAAG,EAAE;IAChD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE;QAC/C,SAAS,EAAE,GAAG,EAAE;YACd,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAC1E,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;QACtE,CAAC;QACD,GAAG,kBAAkB;KACtB,CAAC,CAAA;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
export declare function useUpdateMezoId(useMutationOptions?: {}): {
|
|
2
|
+
data: undefined;
|
|
3
|
+
variables: undefined;
|
|
4
|
+
error: null;
|
|
5
|
+
isError: false;
|
|
6
|
+
isIdle: true;
|
|
7
|
+
isPending: false;
|
|
8
|
+
isSuccess: false;
|
|
9
|
+
status: "idle";
|
|
10
|
+
reset: () => void;
|
|
11
|
+
context: unknown;
|
|
12
|
+
failureCount: number;
|
|
13
|
+
failureReason: Error | null;
|
|
14
|
+
isPaused: boolean;
|
|
15
|
+
submittedAt: number;
|
|
16
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
17
|
+
app_metadata: {
|
|
18
|
+
provider: "wallet" | "discord" | "email";
|
|
19
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
20
|
+
};
|
|
21
|
+
user_metadata: {
|
|
22
|
+
mezoId?: string | undefined;
|
|
23
|
+
btcAddress: string;
|
|
24
|
+
evmAddress: string;
|
|
25
|
+
};
|
|
26
|
+
}, Error, string, unknown>;
|
|
27
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
28
|
+
app_metadata: {
|
|
29
|
+
provider: "wallet" | "discord" | "email";
|
|
30
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
31
|
+
};
|
|
32
|
+
user_metadata: {
|
|
33
|
+
mezoId?: string | undefined;
|
|
34
|
+
btcAddress: string;
|
|
35
|
+
evmAddress: string;
|
|
36
|
+
};
|
|
37
|
+
}, Error, string, unknown>;
|
|
38
|
+
} | {
|
|
39
|
+
data: undefined;
|
|
40
|
+
variables: string;
|
|
41
|
+
error: null;
|
|
42
|
+
isError: false;
|
|
43
|
+
isIdle: false;
|
|
44
|
+
isPending: true;
|
|
45
|
+
isSuccess: false;
|
|
46
|
+
status: "pending";
|
|
47
|
+
reset: () => void;
|
|
48
|
+
context: unknown;
|
|
49
|
+
failureCount: number;
|
|
50
|
+
failureReason: Error | null;
|
|
51
|
+
isPaused: boolean;
|
|
52
|
+
submittedAt: number;
|
|
53
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
54
|
+
app_metadata: {
|
|
55
|
+
provider: "wallet" | "discord" | "email";
|
|
56
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
57
|
+
};
|
|
58
|
+
user_metadata: {
|
|
59
|
+
mezoId?: string | undefined;
|
|
60
|
+
btcAddress: string;
|
|
61
|
+
evmAddress: string;
|
|
62
|
+
};
|
|
63
|
+
}, Error, string, unknown>;
|
|
64
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
65
|
+
app_metadata: {
|
|
66
|
+
provider: "wallet" | "discord" | "email";
|
|
67
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
68
|
+
};
|
|
69
|
+
user_metadata: {
|
|
70
|
+
mezoId?: string | undefined;
|
|
71
|
+
btcAddress: string;
|
|
72
|
+
evmAddress: string;
|
|
73
|
+
};
|
|
74
|
+
}, Error, string, unknown>;
|
|
75
|
+
} | {
|
|
76
|
+
data: undefined;
|
|
77
|
+
error: Error;
|
|
78
|
+
variables: string;
|
|
79
|
+
isError: true;
|
|
80
|
+
isIdle: false;
|
|
81
|
+
isPending: false;
|
|
82
|
+
isSuccess: false;
|
|
83
|
+
status: "error";
|
|
84
|
+
reset: () => void;
|
|
85
|
+
context: unknown;
|
|
86
|
+
failureCount: number;
|
|
87
|
+
failureReason: Error | null;
|
|
88
|
+
isPaused: boolean;
|
|
89
|
+
submittedAt: number;
|
|
90
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
91
|
+
app_metadata: {
|
|
92
|
+
provider: "wallet" | "discord" | "email";
|
|
93
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
94
|
+
};
|
|
95
|
+
user_metadata: {
|
|
96
|
+
mezoId?: string | undefined;
|
|
97
|
+
btcAddress: string;
|
|
98
|
+
evmAddress: string;
|
|
99
|
+
};
|
|
100
|
+
}, Error, string, unknown>;
|
|
101
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
102
|
+
app_metadata: {
|
|
103
|
+
provider: "wallet" | "discord" | "email";
|
|
104
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
105
|
+
};
|
|
106
|
+
user_metadata: {
|
|
107
|
+
mezoId?: string | undefined;
|
|
108
|
+
btcAddress: string;
|
|
109
|
+
evmAddress: string;
|
|
110
|
+
};
|
|
111
|
+
}, Error, string, unknown>;
|
|
112
|
+
} | {
|
|
113
|
+
data: {
|
|
114
|
+
app_metadata: {
|
|
115
|
+
provider: "wallet" | "discord" | "email";
|
|
116
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
117
|
+
};
|
|
118
|
+
user_metadata: {
|
|
119
|
+
mezoId?: string | undefined;
|
|
120
|
+
btcAddress: string;
|
|
121
|
+
evmAddress: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
error: null;
|
|
125
|
+
variables: string;
|
|
126
|
+
isError: false;
|
|
127
|
+
isIdle: false;
|
|
128
|
+
isPending: false;
|
|
129
|
+
isSuccess: true;
|
|
130
|
+
status: "success";
|
|
131
|
+
reset: () => void;
|
|
132
|
+
context: unknown;
|
|
133
|
+
failureCount: number;
|
|
134
|
+
failureReason: Error | null;
|
|
135
|
+
isPaused: boolean;
|
|
136
|
+
submittedAt: number;
|
|
137
|
+
updateMezoId: import("@tanstack/react-query").UseMutateFunction<{
|
|
138
|
+
app_metadata: {
|
|
139
|
+
provider: "wallet" | "discord" | "email";
|
|
140
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
141
|
+
};
|
|
142
|
+
user_metadata: {
|
|
143
|
+
mezoId?: string | undefined;
|
|
144
|
+
btcAddress: string;
|
|
145
|
+
evmAddress: string;
|
|
146
|
+
};
|
|
147
|
+
}, Error, string, unknown>;
|
|
148
|
+
updateMezoIdAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
149
|
+
app_metadata: {
|
|
150
|
+
provider: "wallet" | "discord" | "email";
|
|
151
|
+
providers: ("wallet" | "discord" | "email")[];
|
|
152
|
+
};
|
|
153
|
+
user_metadata: {
|
|
154
|
+
mezoId?: string | undefined;
|
|
155
|
+
btcAddress: string;
|
|
156
|
+
evmAddress: string;
|
|
157
|
+
};
|
|
158
|
+
}, Error, string, unknown>;
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=useUpdateMezoId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useUpdateMezoId.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAAC,kBAAkB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBtD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQueryClient, useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
|
+
import { QUERY_KEYS } from "./constants";
|
|
4
|
+
export function useUpdateMezoId(useMutationOptions = {}) {
|
|
5
|
+
const queryClient = useQueryClient();
|
|
6
|
+
const authApiClient = useAuthApiClient();
|
|
7
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
8
|
+
mutationFn: (newMezoId) => authApiClient.updateMezoId(newMezoId),
|
|
9
|
+
onSuccess: () => {
|
|
10
|
+
queryClient.resetQueries({
|
|
11
|
+
queryKey: [QUERY_KEYS.ACCOUNT_BY_ADDRESS],
|
|
12
|
+
exact: false,
|
|
13
|
+
});
|
|
14
|
+
queryClient.resetQueries({
|
|
15
|
+
queryKey: [QUERY_KEYS.ACCOUNT_BY_MEZO_ID],
|
|
16
|
+
exact: false,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
...useMutationOptions,
|
|
20
|
+
});
|
|
21
|
+
return { updateMezoId: mutate, updateMezoIdAsync: mutateAsync, ...rest };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=useUpdateMezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useUpdateMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,UAAU,eAAe,CAAC,kBAAkB,GAAG,EAAE;IACrD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,CAAC;QACnD,UAAU,EAAE,CAAC,SAAiB,EAAE,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC;QACxE,SAAS,EAAE,GAAG,EAAE;YACd,WAAW,CAAC,YAAY,CAAC;gBACvB,QAAQ,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC;gBACzC,KAAK,EAAE,KAAK;aACb,CAAC,CAAA;YACF,WAAW,CAAC,YAAY,CAAC;gBACvB,QAAQ,EAAE,CAAC,UAAU,CAAC,kBAAkB,CAAC;gBACzC,KAAK,EAAE,KAAK;aACb,CAAC,CAAA;QACJ,CAAC;QACD,GAAG,kBAAkB;KACtB,CAAC,CAAA;IAEF,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAA;AAC1E,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { API_ENDPOINTS_BY_ENV, AuthApiClient } from "./api/auth";
|
|
3
|
+
export interface PassportContextValue {
|
|
4
|
+
authApiClient: AuthApiClient;
|
|
5
|
+
}
|
|
6
|
+
export declare const PassportContext: import("react").Context<PassportContextValue | undefined>;
|
|
7
|
+
interface PassportProviderProps {
|
|
8
|
+
options: {
|
|
9
|
+
environment?: keyof typeof API_ENDPOINTS_BY_ENV;
|
|
10
|
+
apiUrl?: string;
|
|
11
|
+
} & ({
|
|
12
|
+
environment: keyof typeof API_ENDPOINTS_BY_ENV;
|
|
13
|
+
} | {
|
|
14
|
+
apiUrl: string;
|
|
15
|
+
});
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export declare function PassportProvider({ options, children }: PassportProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<PassportContextValue | undefined>>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,aAAa,CAAA;CAC7B;AAED,eAAO,MAAM,eAAe,2DAE3B,CAAA;AAED,UAAU,qBAAqB;IAE7B,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,OAAO,oBAAoB,CAAA;QAC/C,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,GAAG,CACA;QACE,WAAW,EAAE,MAAM,OAAO,oBAAoB,CAAA;KAC/C,GACD;QACE,MAAM,EAAE,MAAM,CAAA;KACf,CACJ,CAAA;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,qBAAqB,6GA6B5E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContext, createElement, useMemo } from "react";
|
|
2
|
+
import { API_ENDPOINTS_BY_ENV, AuthApiClient } from "./api/auth";
|
|
3
|
+
export const PassportContext = createContext(undefined);
|
|
4
|
+
export function PassportProvider({ options, children }) {
|
|
5
|
+
const { environment, apiUrl } = options;
|
|
6
|
+
const finalApiUrl = useMemo(() => {
|
|
7
|
+
if (!environment && !apiUrl) {
|
|
8
|
+
throw new Error("Neither apiUrl or environment are specified in Passport Provider");
|
|
9
|
+
}
|
|
10
|
+
if (apiUrl)
|
|
11
|
+
return apiUrl;
|
|
12
|
+
if (!(environment in API_ENDPOINTS_BY_ENV)) {
|
|
13
|
+
throw new Error("Wrong environment passed to PassportProvider.");
|
|
14
|
+
}
|
|
15
|
+
return API_ENDPOINTS_BY_ENV[environment];
|
|
16
|
+
}, [environment, apiUrl]);
|
|
17
|
+
return createElement(PassportContext.Provider, {
|
|
18
|
+
value: finalApiUrl
|
|
19
|
+
? {
|
|
20
|
+
authApiClient: new AuthApiClient(finalApiUrl),
|
|
21
|
+
}
|
|
22
|
+
: undefined,
|
|
23
|
+
}, children);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAMhE,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAC1C,SAAS,CACV,CAAA;AAkBD,MAAM,UAAU,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAyB;IAC3E,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEvC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE;QAC/B,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAA;QACH,CAAC;QACD,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QAEzB,IAAI,CAAC,CAAC,WAAY,IAAI,oBAAoB,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;QAED,OAAO,oBAAoB,CAAC,WAAY,CAAC,CAAA;IAC3C,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;IAEzB,OAAO,aAAa,CAClB,eAAe,CAAC,QAAQ,EACxB;QACE,KAAK,EAAE,WAAW;YAChB,CAAC,CAAC;gBACE,aAAa,EAAE,IAAI,aAAa,CAAC,WAAW,CAAC;aAC9C;YACH,CAAC,CAAC,SAAS;KACd,EACD,QAAQ,CACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siww.d.ts","sourceRoot":"","sources":["../../../src/utils/siww.ts"],"names":[],"mappings":"AAKA,KAAK,aAAa,GAAG,KAAK,GAAG,SAAS,CAAA;AAEtC,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,MAAM,UAmBjB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SignInWithWalletMessage } from "@mezo-org/sign-in-with-wallet";
|
|
2
|
+
import { ONE_DAY_MS } from "./time";
|
|
3
|
+
const SESSION_EXPIRATION_DURATION_MS = 14 * ONE_DAY_MS;
|
|
4
|
+
export function createSignInWithWalletMessage(address, nonce, networkFamily, chainId) {
|
|
5
|
+
const { host: domain, origin: uri } = window.location;
|
|
6
|
+
const message = new SignInWithWalletMessage({
|
|
7
|
+
domain,
|
|
8
|
+
address, // if "bitcoin" this should be btc address, not underlaying eth address
|
|
9
|
+
uri,
|
|
10
|
+
nonce,
|
|
11
|
+
issuedAt: new Date().toISOString(),
|
|
12
|
+
expirationTime: new Date(Date.now() + SESSION_EXPIRATION_DURATION_MS).toISOString(),
|
|
13
|
+
version: "1",
|
|
14
|
+
chainId: networkFamily === "evm" ? chainId : undefined,
|
|
15
|
+
networkFamily,
|
|
16
|
+
});
|
|
17
|
+
return message.prepareMessage();
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=siww.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siww.js","sourceRoot":"","sources":["../../../src/utils/siww.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEnC,MAAM,8BAA8B,GAAG,EAAE,GAAG,UAAU,CAAA;AAItD,MAAM,UAAU,6BAA6B,CAC3C,OAAe,EACf,KAAa,EACb,aAA4B,EAC5B,OAAgB;IAEhB,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAA;IAErD,MAAM,OAAO,GAAG,IAAI,uBAAuB,CAAC;QAC1C,MAAM;QACN,OAAO,EAAE,uEAAuE;QAChF,GAAG;QACH,KAAK;QACL,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,cAAc,EAAE,IAAI,IAAI,CACtB,IAAI,CAAC,GAAG,EAAE,GAAG,8BAA8B,CAC5C,CAAC,WAAW,EAAE;QACf,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QACtD,aAAa;KACd,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,cAAc,EAAE,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,OAAO,CAAA;AACjC,eAAO,MAAM,aAAa,QAAqB,CAAA;AAC/C,eAAO,MAAM,WAAW,QAAqB,CAAA;AAC7C,eAAO,MAAM,UAAU,QAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../../src/utils/time.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AACjC,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,GAAG,aAAa,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,GAAG,aAAa,CAAA;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,GAAG,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezo-org/passport",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-dev.1",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"scripts": {
|
|
@@ -28,16 +28,18 @@
|
|
|
28
28
|
"@types/jest": "^29.5.12",
|
|
29
29
|
"@types/node": "^20.11.30",
|
|
30
30
|
"@types/react": "^18.2.64",
|
|
31
|
-
"eslint": "^8.
|
|
31
|
+
"eslint": "^8.57.1",
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
|
-
"prettier": "^3.
|
|
33
|
+
"prettier": "^3.2.5",
|
|
34
34
|
"ts-jest": "^29.1.2",
|
|
35
35
|
"ts-node": "^10.9.2",
|
|
36
36
|
"typescript": "^5.4.3"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@mezo-org/orangekit": "1.0.0-beta.
|
|
39
|
+
"@mezo-org/orangekit": "1.0.0-beta.40-dev.0",
|
|
40
40
|
"@rainbow-me/rainbowkit": "2.0.2",
|
|
41
|
+
"@tanstack/react-query": "^5.28.4",
|
|
42
|
+
"@mezo-org/sign-in-with-wallet": "1.0.0-beta.8",
|
|
41
43
|
"react": "^18.2.0",
|
|
42
44
|
"viem": "2.22.8",
|
|
43
45
|
"wagmi": "2.5.12"
|
package/src/api/auth.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
|
|
2
|
+
body?: Record<string, unknown>
|
|
3
|
+
queryParams?: Record<string, string | undefined>
|
|
4
|
+
}
|
|
5
|
+
type PassportIdentityProvider = "wallet" | "discord" | "email"
|
|
6
|
+
|
|
7
|
+
type AccountPublicData = {
|
|
8
|
+
mezoId?: string
|
|
9
|
+
btcAddress: string
|
|
10
|
+
evmAddress: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Account = {
|
|
14
|
+
app_metadata: {
|
|
15
|
+
provider: PassportIdentityProvider
|
|
16
|
+
providers: PassportIdentityProvider[]
|
|
17
|
+
}
|
|
18
|
+
user_metadata: AccountPublicData
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Session = {
|
|
22
|
+
access_token: string
|
|
23
|
+
token_type: string
|
|
24
|
+
expires_in: number
|
|
25
|
+
expires_at: number
|
|
26
|
+
refresh_token: string
|
|
27
|
+
user: Account
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type AuthenticationProviderRedirectResponse = {
|
|
31
|
+
redirectTo: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type WalletAccountCredentials = {
|
|
35
|
+
type: "wallet"
|
|
36
|
+
message: string
|
|
37
|
+
signature: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type CreateSessionRequest =
|
|
41
|
+
| WalletAccountCredentials
|
|
42
|
+
| { type: "discord" }
|
|
43
|
+
|
|
44
|
+
export type LinkAccountRequest = CreateSessionRequest
|
|
45
|
+
|
|
46
|
+
export type CreateAccountRequest = WalletAccountCredentials
|
|
47
|
+
|
|
48
|
+
export const API_ENDPOINTS_BY_ENV = {
|
|
49
|
+
mainnet: "https://api.mezo.org",
|
|
50
|
+
testnet: "https://api.test.mezo.org",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DEFAULT_API_ENDPOINT = API_ENDPOINTS_BY_ENV.mainnet
|
|
54
|
+
|
|
55
|
+
export class AuthApiClient {
|
|
56
|
+
private apiUrl: string
|
|
57
|
+
|
|
58
|
+
constructor(apiUrl?: string) {
|
|
59
|
+
this.apiUrl = apiUrl ?? DEFAULT_API_ENDPOINT
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The request handler for the Passport API. It accepts an API endpoint and
|
|
64
|
+
* request options.
|
|
65
|
+
* @dev Generic type `D` is a type of returned object from the function
|
|
66
|
+
* @param endpoint - The API endpoint to request. Should start with
|
|
67
|
+
* forward slash ("/")
|
|
68
|
+
* @param {RequestHandlerOptions<B>} options - The request options, the
|
|
69
|
+
* `RequestInit` type with additional type-safe properties
|
|
70
|
+
* @returns The promise of the API response
|
|
71
|
+
*/
|
|
72
|
+
protected async handleRequest<D>(
|
|
73
|
+
endpoint: `/${string}`,
|
|
74
|
+
options: RequestHandlerOptions,
|
|
75
|
+
): Promise<D> {
|
|
76
|
+
const {
|
|
77
|
+
method,
|
|
78
|
+
headers,
|
|
79
|
+
body,
|
|
80
|
+
queryParams = {},
|
|
81
|
+
...restOptions
|
|
82
|
+
} = options || {}
|
|
83
|
+
|
|
84
|
+
// If last character in apiUrl is forward slash we are removing it
|
|
85
|
+
const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
|
|
86
|
+
const url = new URL(`${authApiUrlRoute}${endpoint}`)
|
|
87
|
+
|
|
88
|
+
// Removes falsy values (e.g. null, undefined etc.) from query params and
|
|
89
|
+
// appends remaining ones to the URL
|
|
90
|
+
Object.entries(queryParams)
|
|
91
|
+
.filter(([, value]) => value) // Remove falsy values
|
|
92
|
+
.forEach(([key, value]) => url.searchParams.append(key, value!))
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const response = await fetch(url, {
|
|
96
|
+
method,
|
|
97
|
+
credentials: "include",
|
|
98
|
+
headers: {
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
...headers,
|
|
101
|
+
},
|
|
102
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
103
|
+
...restOptions,
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const data = await response.json()
|
|
107
|
+
|
|
108
|
+
if (!response.ok || data?.error) {
|
|
109
|
+
const error = data?.error || "An error occurred"
|
|
110
|
+
throw new Error(error)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return data as D
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const errorMessage =
|
|
116
|
+
error instanceof Error ? error.message : "An error occurred"
|
|
117
|
+
|
|
118
|
+
throw new Error(errorMessage)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async getSession(code?: string) {
|
|
123
|
+
const data = await this.handleRequest<Session | { nonce: string }>(
|
|
124
|
+
"/session",
|
|
125
|
+
{
|
|
126
|
+
method: "GET",
|
|
127
|
+
queryParams: { code },
|
|
128
|
+
},
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
return data
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async createSession(createSessionRequest: CreateSessionRequest) {
|
|
135
|
+
const data = await this.handleRequest<Session | { redirectTo: string }>(
|
|
136
|
+
"/session",
|
|
137
|
+
{
|
|
138
|
+
method: "POST",
|
|
139
|
+
body: createSessionRequest,
|
|
140
|
+
},
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return data
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async deleteSession() {
|
|
147
|
+
const data = await this.handleRequest<{
|
|
148
|
+
message: string
|
|
149
|
+
}>("/session", {
|
|
150
|
+
method: "DELETE",
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
return data
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async getCurrentAccount() {
|
|
157
|
+
const data = await this.handleRequest<Account>("/session/account", {
|
|
158
|
+
method: "GET",
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
return data
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getAccountByMezoIdOrAddress(mezoIdOrAddress: string) {
|
|
165
|
+
const data = await this.handleRequest<AccountPublicData>(
|
|
166
|
+
`/accounts/${mezoIdOrAddress}`,
|
|
167
|
+
{
|
|
168
|
+
method: "GET",
|
|
169
|
+
},
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
return data
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async linkAccount(linkAccountRequest: LinkAccountRequest) {
|
|
176
|
+
const data = await this.handleRequest<
|
|
177
|
+
Account | AuthenticationProviderRedirectResponse
|
|
178
|
+
>("/session/account/linked-accounts", {
|
|
179
|
+
method: "POST",
|
|
180
|
+
body: linkAccountRequest,
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
return data
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async createAccount(createAccountRequest: CreateAccountRequest) {
|
|
187
|
+
const data = await this.handleRequest<Account>("/accounts", {
|
|
188
|
+
method: "POST",
|
|
189
|
+
body: createAccountRequest,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
return data
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async updateMezoId(newMezoId: string) {
|
|
196
|
+
const data = await this.handleRequest<Account>("/session/account", {
|
|
197
|
+
method: "PATCH",
|
|
198
|
+
body: { newMezoId },
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
return data
|
|
202
|
+
}
|
|
203
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -6,3 +6,16 @@ export {
|
|
|
6
6
|
useSubscribeToConnectorEvent,
|
|
7
7
|
useSubscribeToWalletNetworkDoesNotMatchProviderChain,
|
|
8
8
|
} from "@mezo-org/orangekit"
|
|
9
|
+
export * from "./constants"
|
|
10
|
+
export * from "./useAuthApiClient"
|
|
11
|
+
export * from "./useCreateAccount"
|
|
12
|
+
export * from "./useGetAccountByAddress"
|
|
13
|
+
export * from "./useGetAccountByMezoId"
|
|
14
|
+
export * from "./useGetCurrentAccount"
|
|
15
|
+
export * from "./useGetSession"
|
|
16
|
+
export * from "./useLinkAccount"
|
|
17
|
+
export * from "./usePassportContext"
|
|
18
|
+
export * from "./useSignInWithDiscord"
|
|
19
|
+
export * from "./useSignInWithWallet"
|
|
20
|
+
export * from "./useSignOut"
|
|
21
|
+
export * from "./useUpdateMezoId"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useQueryClient, useMutation } from "@tanstack/react-query"
|
|
2
|
+
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
|
+
import { QUERY_KEYS } from "./constants"
|
|
4
|
+
import { CreateAccountRequest } from "../api/auth"
|
|
5
|
+
|
|
6
|
+
export function useCreateAccount(useMutationOptions = {}) {
|
|
7
|
+
const queryClient = useQueryClient()
|
|
8
|
+
const authApiClient = useAuthApiClient()
|
|
9
|
+
|
|
10
|
+
const { mutate, mutateAsync, ...rest } = useMutation({
|
|
11
|
+
mutationFn: (createAccountRequest: CreateAccountRequest) =>
|
|
12
|
+
authApiClient.createAccount(createAccountRequest),
|
|
13
|
+
onSuccess: () => {
|
|
14
|
+
queryClient.resetQueries({
|
|
15
|
+
queryKey: [QUERY_KEYS.ACCOUNT_BY_ADDRESS],
|
|
16
|
+
exact: false,
|
|
17
|
+
})
|
|
18
|
+
queryClient.resetQueries({
|
|
19
|
+
queryKey: [QUERY_KEYS.ACCOUNT_BY_MEZO_ID],
|
|
20
|
+
exact: false,
|
|
21
|
+
})
|
|
22
|
+
},
|
|
23
|
+
...useMutationOptions,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return { createAccount: mutate, createAccountAsync: mutateAsync, ...rest }
|
|
27
|
+
}
|