@cartridge/controller 0.12.1 → 0.12.2
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/.turbo/turbo-build$colon$deps.log +12 -12
- package/.turbo/turbo-build.log +12 -12
- package/dist/index.js +2 -2
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/{provider-BQFas4CN.js → provider-B8OiOgBt.js} +2 -2
- package/dist/{provider-BQFas4CN.js.map → provider-B8OiOgBt.js.map} +1 -1
- package/dist/session/provider.d.ts +14 -0
- package/dist/session.js +159 -125
- package/dist/session.js.map +1 -1
- package/dist/stats.html +1 -1
- package/package.json +3 -3
- package/src/session/account.ts +8 -1
- package/src/session/provider.ts +63 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartridge/controller",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Cartridge Controller",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@cartridge/controller-wasm": "0.
|
|
24
|
+
"@cartridge/controller-wasm": "0.9.1",
|
|
25
25
|
"@cartridge/penpal": "^6.2.4",
|
|
26
26
|
"micro-sol-signer": "^0.5.0",
|
|
27
27
|
"bs58": "^6.0.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"vite-plugin-node-polyfills": "^0.23.0",
|
|
51
51
|
"vite-plugin-top-level-await": "^1.4.4",
|
|
52
52
|
"vite-plugin-wasm": "^3.4.1",
|
|
53
|
-
"@cartridge/tsconfig": "0.12.
|
|
53
|
+
"@cartridge/tsconfig": "0.12.2"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build:deps": "pnpm build",
|
package/src/session/account.ts
CHANGED
|
@@ -72,6 +72,13 @@ export default class SessionAccount extends WalletAccount {
|
|
|
72
72
|
* @returns response from addTransaction
|
|
73
73
|
*/
|
|
74
74
|
async execute(calls: Call | Call[]): Promise<InvokeFunctionResponse> {
|
|
75
|
-
|
|
75
|
+
try {
|
|
76
|
+
const res = await this.controller.executeFromOutside(
|
|
77
|
+
normalizeCalls(calls),
|
|
78
|
+
);
|
|
79
|
+
return res;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return this.controller.execute(normalizeCalls(calls));
|
|
82
|
+
}
|
|
76
83
|
}
|
|
77
84
|
}
|
package/src/session/provider.ts
CHANGED
|
@@ -166,6 +166,56 @@ export default class SessionProvider extends BaseProvider {
|
|
|
166
166
|
return true;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
private padBase64(value: string): string {
|
|
170
|
+
const padding = value.length % 4;
|
|
171
|
+
if (padding === 0) {
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
return value + "=".repeat(4 - padding);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private normalizeSession(
|
|
178
|
+
session: Partial<SessionRegistration>,
|
|
179
|
+
): SessionRegistration | undefined {
|
|
180
|
+
if (
|
|
181
|
+
session.username === undefined ||
|
|
182
|
+
session.address === undefined ||
|
|
183
|
+
session.ownerGuid === undefined ||
|
|
184
|
+
session.expiresAt === undefined
|
|
185
|
+
) {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
username: session.username,
|
|
191
|
+
address: session.address,
|
|
192
|
+
ownerGuid: session.ownerGuid,
|
|
193
|
+
transactionHash: session.transactionHash,
|
|
194
|
+
expiresAt: session.expiresAt,
|
|
195
|
+
guardianKeyGuid: session.guardianKeyGuid ?? "0x0",
|
|
196
|
+
metadataHash: session.metadataHash ?? "0x0",
|
|
197
|
+
sessionKeyGuid: session.sessionKeyGuid ?? this._sessionKeyGuid,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public ingestSessionFromRedirect(
|
|
202
|
+
encodedSession: string,
|
|
203
|
+
): SessionRegistration | undefined {
|
|
204
|
+
try {
|
|
205
|
+
const decoded = atob(this.padBase64(encodedSession));
|
|
206
|
+
const parsed = JSON.parse(decoded) as Partial<SessionRegistration>;
|
|
207
|
+
const normalized = this.normalizeSession(parsed);
|
|
208
|
+
if (!normalized) {
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
localStorage.setItem("session", JSON.stringify(normalized));
|
|
212
|
+
return normalized;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.error("Failed to ingest session redirect", e);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
169
219
|
async username() {
|
|
170
220
|
await this.tryRetrieveFromQueryOrStorage();
|
|
171
221
|
return this._username;
|
|
@@ -299,23 +349,27 @@ export default class SessionProvider extends BaseProvider {
|
|
|
299
349
|
|
|
300
350
|
const sessionString = localStorage.getItem("session");
|
|
301
351
|
if (sessionString) {
|
|
302
|
-
|
|
352
|
+
const parsed = JSON.parse(sessionString) as Partial<SessionRegistration>;
|
|
353
|
+
const normalized = this.normalizeSession(parsed);
|
|
354
|
+
if (normalized) {
|
|
355
|
+
sessionRegistration = normalized;
|
|
356
|
+
localStorage.setItem("session", JSON.stringify(sessionRegistration));
|
|
357
|
+
} else {
|
|
358
|
+
this.clearStoredSession();
|
|
359
|
+
}
|
|
303
360
|
}
|
|
304
361
|
|
|
305
362
|
if (window.location.search.includes("startapp")) {
|
|
306
363
|
const params = new URLSearchParams(window.location.search);
|
|
307
364
|
const session = params.get("startapp");
|
|
308
365
|
if (session) {
|
|
309
|
-
const
|
|
310
|
-
atob(session),
|
|
311
|
-
);
|
|
312
|
-
|
|
366
|
+
const normalizedSession = this.ingestSessionFromRedirect(session);
|
|
313
367
|
if (
|
|
314
|
-
|
|
315
|
-
Number(
|
|
368
|
+
normalizedSession &&
|
|
369
|
+
Number(normalizedSession.expiresAt) !==
|
|
370
|
+
Number(sessionRegistration?.expiresAt)
|
|
316
371
|
) {
|
|
317
|
-
sessionRegistration =
|
|
318
|
-
localStorage.setItem("session", JSON.stringify(sessionRegistration));
|
|
372
|
+
sessionRegistration = normalizedSession;
|
|
319
373
|
}
|
|
320
374
|
|
|
321
375
|
// Remove the session query parameter
|