@zerodev/wallet-react 0.0.1-alpha.14 → 0.0.1-alpha.15
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/CHANGELOG.md +8 -0
- package/dist/_cjs/actions.js +2 -1
- package/dist/_cjs/connector.js +4 -1
- package/dist/_cjs/oauth.js +6 -2
- package/dist/_esm/actions.js +2 -2
- package/dist/_esm/connector.js +4 -1
- package/dist/_esm/oauth.js +6 -2
- package/dist/_types/connector.d.ts.map +1 -1
- package/dist/_types/oauth.d.ts +2 -1
- package/dist/_types/oauth.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/actions.test.ts +16 -8
- package/src/actions.ts +2 -2
- package/src/connector.ts +4 -1
- package/src/oauth.test.ts +45 -11
- package/src/oauth.ts +7 -6
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/dist/_cjs/actions.js
CHANGED
|
@@ -83,11 +83,12 @@ async function authenticateOAuth(config, parameters) {
|
|
|
83
83
|
throw new Error(`Failed to open ${parameters.provider} login window.`);
|
|
84
84
|
}
|
|
85
85
|
return new Promise((resolve, reject) => {
|
|
86
|
-
const cleanup = (0, oauth_js_1.listenForOAuthMessage)(authWindow, window.location.origin, async () => {
|
|
86
|
+
const cleanup = (0, oauth_js_1.listenForOAuthMessage)(authWindow, window.location.origin, async (sessionId) => {
|
|
87
87
|
try {
|
|
88
88
|
await wallet.auth({
|
|
89
89
|
type: 'oauth',
|
|
90
90
|
provider: parameters.provider,
|
|
91
|
+
sessionId,
|
|
91
92
|
});
|
|
92
93
|
const [session, eoaAccount] = await Promise.all([
|
|
93
94
|
wallet.getSession(),
|
package/dist/_cjs/connector.js
CHANGED
|
@@ -12,6 +12,7 @@ const store_js_1 = require("./store.js");
|
|
|
12
12
|
const aaUtils_js_1 = require("./utils/aaUtils.js");
|
|
13
13
|
const OAUTH_SUCCESS_PARAM = 'oauth_success';
|
|
14
14
|
const OAUTH_PROVIDER_PARAM = 'oauth_provider';
|
|
15
|
+
const OAUTH_SESSION_ID_PARAM = 'session_id';
|
|
15
16
|
async function detectAndHandleOAuthCallback(wallet, store) {
|
|
16
17
|
if (typeof window === 'undefined')
|
|
17
18
|
return false;
|
|
@@ -26,8 +27,9 @@ async function detectAndHandleOAuthCallback(wallet, store) {
|
|
|
26
27
|
console.log('OAuth callback detected, completing authentication...');
|
|
27
28
|
const provider = (params.get(OAUTH_PROVIDER_PARAM) ||
|
|
28
29
|
'google');
|
|
30
|
+
const sessionId = params.get(OAUTH_SESSION_ID_PARAM) || '';
|
|
29
31
|
try {
|
|
30
|
-
await wallet.auth({ type: 'oauth', provider });
|
|
32
|
+
await wallet.auth({ type: 'oauth', provider, sessionId });
|
|
31
33
|
const [session, eoaAccount] = await Promise.all([
|
|
32
34
|
wallet.getSession(),
|
|
33
35
|
wallet.toAccount(),
|
|
@@ -36,6 +38,7 @@ async function detectAndHandleOAuthCallback(wallet, store) {
|
|
|
36
38
|
store.getState().setSession(session || null);
|
|
37
39
|
params.delete(OAUTH_SUCCESS_PARAM);
|
|
38
40
|
params.delete(OAUTH_PROVIDER_PARAM);
|
|
41
|
+
params.delete(OAUTH_SESSION_ID_PARAM);
|
|
39
42
|
const newUrl = params.toString()
|
|
40
43
|
? `${window.location.pathname}?${params.toString()}`
|
|
41
44
|
: window.location.pathname;
|
package/dist/_cjs/oauth.js
CHANGED
|
@@ -46,7 +46,7 @@ function listenForOAuthMessage(authWindow, expectedOrigin, onSuccess, onError) {
|
|
|
46
46
|
return;
|
|
47
47
|
if (event.data.type === 'oauth_success') {
|
|
48
48
|
cleanup();
|
|
49
|
-
onSuccess();
|
|
49
|
+
onSuccess(event.data.sessionId || '');
|
|
50
50
|
}
|
|
51
51
|
else if (event.data.type === 'oauth_error') {
|
|
52
52
|
cleanup();
|
|
@@ -73,9 +73,13 @@ function handleOAuthCallback(successParam = 'oauth_success') {
|
|
|
73
73
|
const urlParams = new URLSearchParams(window.location.search);
|
|
74
74
|
const isSuccess = urlParams.get(successParam) === 'true';
|
|
75
75
|
const error = urlParams.get('error');
|
|
76
|
+
const sessionId = urlParams.get('session_id') ?? undefined;
|
|
76
77
|
if (window.opener) {
|
|
77
78
|
if (isSuccess) {
|
|
78
|
-
|
|
79
|
+
const message = { type: 'oauth_success' };
|
|
80
|
+
if (sessionId)
|
|
81
|
+
message.sessionId = sessionId;
|
|
82
|
+
window.opener.postMessage(message, window.location.origin);
|
|
79
83
|
window.close();
|
|
80
84
|
return true;
|
|
81
85
|
}
|
package/dist/_esm/actions.js
CHANGED
|
@@ -93,13 +93,13 @@ export async function authenticateOAuth(config, parameters) {
|
|
|
93
93
|
}
|
|
94
94
|
// Listen for OAuth completion via postMessage
|
|
95
95
|
return new Promise((resolve, reject) => {
|
|
96
|
-
const cleanup = listenForOAuthMessage(authWindow, window.location.origin, async () => {
|
|
96
|
+
const cleanup = listenForOAuthMessage(authWindow, window.location.origin, async (sessionId) => {
|
|
97
97
|
try {
|
|
98
98
|
// Complete OAuth authentication with wallet-core
|
|
99
|
-
// The backend has stored the OAuth session in a cookie
|
|
100
99
|
await wallet.auth({
|
|
101
100
|
type: 'oauth',
|
|
102
101
|
provider: parameters.provider,
|
|
102
|
+
sessionId,
|
|
103
103
|
});
|
|
104
104
|
const [session, eoaAccount] = await Promise.all([
|
|
105
105
|
wallet.getSession(),
|
package/dist/_esm/connector.js
CHANGED
|
@@ -10,6 +10,7 @@ import { getAAUrl } from './utils/aaUtils.js';
|
|
|
10
10
|
// OAuth URL parameter used to detect callback
|
|
11
11
|
const OAUTH_SUCCESS_PARAM = 'oauth_success';
|
|
12
12
|
const OAUTH_PROVIDER_PARAM = 'oauth_provider';
|
|
13
|
+
const OAUTH_SESSION_ID_PARAM = 'session_id';
|
|
13
14
|
/**
|
|
14
15
|
* Detect OAuth callback from URL params and handle it.
|
|
15
16
|
* - If in popup: sends postMessage to opener and closes
|
|
@@ -31,8 +32,9 @@ async function detectAndHandleOAuthCallback(wallet, store) {
|
|
|
31
32
|
console.log('OAuth callback detected, completing authentication...');
|
|
32
33
|
const provider = (params.get(OAUTH_PROVIDER_PARAM) ||
|
|
33
34
|
'google');
|
|
35
|
+
const sessionId = params.get(OAUTH_SESSION_ID_PARAM) || '';
|
|
34
36
|
try {
|
|
35
|
-
await wallet.auth({ type: 'oauth', provider });
|
|
37
|
+
await wallet.auth({ type: 'oauth', provider, sessionId });
|
|
36
38
|
const [session, eoaAccount] = await Promise.all([
|
|
37
39
|
wallet.getSession(),
|
|
38
40
|
wallet.toAccount(),
|
|
@@ -42,6 +44,7 @@ async function detectAndHandleOAuthCallback(wallet, store) {
|
|
|
42
44
|
// Clean up URL params
|
|
43
45
|
params.delete(OAUTH_SUCCESS_PARAM);
|
|
44
46
|
params.delete(OAUTH_PROVIDER_PARAM);
|
|
47
|
+
params.delete(OAUTH_SESSION_ID_PARAM);
|
|
45
48
|
const newUrl = params.toString()
|
|
46
49
|
? `${window.location.pathname}?${params.toString()}`
|
|
47
50
|
: window.location.pathname;
|
package/dist/_esm/oauth.js
CHANGED
|
@@ -47,7 +47,7 @@ export function listenForOAuthMessage(authWindow, expectedOrigin, onSuccess, onE
|
|
|
47
47
|
return;
|
|
48
48
|
if (event.data.type === 'oauth_success') {
|
|
49
49
|
cleanup();
|
|
50
|
-
onSuccess();
|
|
50
|
+
onSuccess(event.data.sessionId || '');
|
|
51
51
|
}
|
|
52
52
|
else if (event.data.type === 'oauth_error') {
|
|
53
53
|
cleanup();
|
|
@@ -79,9 +79,13 @@ export function handleOAuthCallback(successParam = 'oauth_success') {
|
|
|
79
79
|
const urlParams = new URLSearchParams(window.location.search);
|
|
80
80
|
const isSuccess = urlParams.get(successParam) === 'true';
|
|
81
81
|
const error = urlParams.get('error');
|
|
82
|
+
const sessionId = urlParams.get('session_id') ?? undefined;
|
|
82
83
|
if (window.opener) {
|
|
83
84
|
if (isSuccess) {
|
|
84
|
-
|
|
85
|
+
const message = { type: 'oauth_success' };
|
|
86
|
+
if (sessionId)
|
|
87
|
+
message.sessionId = sessionId;
|
|
88
|
+
window.opener.postMessage(message, window.location.origin);
|
|
85
89
|
window.close();
|
|
86
90
|
return true;
|
|
87
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAmB,MAAM,aAAa,CAAA;AAOrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,OAAO,EAAE,KAAK,KAAK,EAA4B,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAmB,MAAM,aAAa,CAAA;AAOrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,OAAO,EAAE,KAAK,KAAK,EAA4B,MAAM,MAAM,CAAA;AAmE3D,MAAM,MAAM,4BAA4B,GAAG;IACzC,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,SAAS,KAAK,EAAE,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC,CAAA;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,4BAA4B,GACnC,iBAAiB,CA2TnB"}
|
package/dist/_types/oauth.d.ts
CHANGED
|
@@ -18,13 +18,14 @@ export declare function generateOAuthNonce(publicKey: string): string;
|
|
|
18
18
|
export declare function buildBackendOAuthUrl(params: BackendOAuthFlowParams): string;
|
|
19
19
|
export type OAuthMessageData = {
|
|
20
20
|
type: 'oauth_success' | 'oauth_error';
|
|
21
|
+
sessionId?: string;
|
|
21
22
|
error?: string;
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Listen for OAuth completion via postMessage from popup
|
|
25
26
|
* The popup sends a message when it detects a successful redirect
|
|
26
27
|
*/
|
|
27
|
-
export declare function listenForOAuthMessage(authWindow: Window, expectedOrigin: string, onSuccess: () => void, onError: (error: Error) => void): () => void;
|
|
28
|
+
export declare function listenForOAuthMessage(authWindow: Window, expectedOrigin: string, onSuccess: (sessionId: string) => void, onError: (error: Error) => void): () => void;
|
|
28
29
|
/**
|
|
29
30
|
* Handle OAuth callback on the return page
|
|
30
31
|
* Call this on the page that receives the OAuth redirect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/oauth.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe;;CAElB,CAAA;AAEV,MAAM,MAAM,aAAa,GACvB,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAA;AAExD,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,aAAa,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAKD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBzD;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAa3E;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,eAAe,GAAG,aAAa,CAAA;IACrC,KAAK,C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