@getpara/web-sdk 2.0.0-alpha.62 → 2.0.0-alpha.64

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/ParaWeb.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare class Para extends ParaCore {
6
6
  farcasterSdk: any;
7
7
  isReady: boolean;
8
8
  isFarcasterMiniApp: boolean;
9
+ private isFarcasterSetup;
9
10
  constructor(env: Environment | undefined, apiKey: string, opts?: ConstructorOpts);
10
11
  constructor(apiKey: string, opts?: ConstructorOpts);
11
12
  ready(): Promise<void>;
package/dist/ParaWeb.js CHANGED
@@ -22,13 +22,13 @@ class Para extends ParaCore {
22
22
  this.farcasterSdk = void 0;
23
23
  this.isReady = false;
24
24
  this.isFarcasterMiniApp = false;
25
+ this.isFarcasterSetup = false;
25
26
  this.portalEventListener = (event) => __async(this, null, function* () {
26
27
  var _a, _b, _c, _d, _e, _f;
27
28
  if (!event.data.isPara || event.origin !== (yield this.getPortalURL()) || this.isPortal()) {
28
29
  return;
29
30
  }
30
31
  const messagePort = event.ports[0];
31
- const userId = this.assertUserId();
32
32
  let payload, status = "SUCCESS";
33
33
  try {
34
34
  switch (event.data.type) {
@@ -71,6 +71,7 @@ class Para extends ParaCore {
71
71
  break;
72
72
  case "ONRAMPS__SIGN_MOONPAY_URL":
73
73
  {
74
+ const userId = this.assertUserId();
74
75
  const { url } = event.data.payload;
75
76
  const onRampPurchase = (_e = this.onRampPopup) == null ? void 0 : _e.onRampPurchase;
76
77
  const res = yield this.ctx.client.signMoonPayUrl(userId, {
@@ -96,19 +97,28 @@ class Para extends ParaCore {
96
97
  }
97
98
  }
98
99
  break;
100
+ case "WALLET_SWITCH_COMPLETED":
101
+ {
102
+ const { walletIds } = event.data.payload;
103
+ this.walletSwitchIds = walletIds;
104
+ payload = {};
105
+ }
106
+ break;
99
107
  }
100
108
  } catch (e) {
101
109
  status = "ERROR";
102
110
  payload = { error: e.message };
103
111
  }
104
- messagePort == null ? void 0 : messagePort.postMessage({
105
- id: event.data.id,
106
- type: event.data.type,
107
- isPara: true,
108
- status,
109
- payload
110
- });
111
- messagePort == null ? void 0 : messagePort.close();
112
+ if (messagePort) {
113
+ messagePort.postMessage({
114
+ id: event.data.id,
115
+ type: event.data.type,
116
+ isPara: true,
117
+ status,
118
+ payload
119
+ });
120
+ messagePort.close();
121
+ }
112
122
  });
113
123
  __privateAdd(this, _isPasskeySupported);
114
124
  if (typeof window !== "undefined") {
@@ -119,21 +129,27 @@ class Para extends ParaCore {
119
129
  return __async(this, null, function* () {
120
130
  var _a, _b, _c, _d;
121
131
  if (!this.isReady) {
122
- try {
123
- this.farcasterSdk = (_b = (_a = yield import("@farcaster/miniapp-sdk")) == null ? void 0 : _a.sdk) != null ? _b : void 0;
124
- if (!((_c = this.farcasterSdk) == null ? void 0 : _c.isInMiniApp)) {
125
- throw new Error("Farcaster SDK not detected or failed to load");
132
+ if (!this.isFarcasterSetup) {
133
+ try {
134
+ this.farcasterSdk = (_b = (_a = yield import("@farcaster/miniapp-sdk")) == null ? void 0 : _a.sdk) != null ? _b : void 0;
135
+ if (!((_c = this.farcasterSdk) == null ? void 0 : _c.isInMiniApp)) {
136
+ throw new Error("Farcaster SDK not detected or failed to load");
137
+ }
138
+ this.devLog("Farcaster SDK detected and loaded successfully.", this.farcasterSdk);
139
+ } catch (e) {
140
+ this.devLog(e);
126
141
  }
127
- this.devLog("Farcaster SDK detected and loaded successfully.", this.farcasterSdk);
128
- } catch (e) {
129
- this.devLog(e);
130
- }
131
- if (!!((_d = this.farcasterSdk) == null ? void 0 : _d.isInMiniApp)) {
132
- this.devLog("Initializing Farcaster SDK...");
133
- this.isFarcasterMiniApp = yield this.farcasterSdk.isInMiniApp();
134
- if (this.isFarcasterMiniApp) {
135
- this.externalWalletConnectionOnly = true;
142
+ if (!!((_d = this.farcasterSdk) == null ? void 0 : _d.isInMiniApp)) {
143
+ this.devLog("Initializing Farcaster SDK...");
144
+ this.isFarcasterMiniApp = yield this.farcasterSdk.isInMiniApp();
145
+ if (this.isFarcasterMiniApp) {
146
+ this.externalWalletConnectionOnly = true;
147
+ }
136
148
  }
149
+ this.isFarcasterSetup = true;
150
+ }
151
+ if (!this.isPortal() && Object.values(this.wallets).length > 0 && Object.values(this.wallets).every((wallet) => !wallet.partner)) {
152
+ yield this.populateWalletAddresses();
137
153
  }
138
154
  this.isReady = true;
139
155
  }
@@ -1,6 +1,6 @@
1
- import { OnRampConfig, OnRampPurchase, OnRampPurchaseUpdateParams } from '@getpara/user-management-client';
1
+ import { CurrentWalletIds, OnRampConfig, OnRampPurchase, OnRampPurchaseUpdateParams } from '@getpara/user-management-client';
2
2
  import { OfframpDepositRequest } from '@getpara/core-sdk';
3
- export type PortalMessageType = 'ONRAMPS__INIT' | 'ONRAMPS__UPDATE_PURCHASE' | 'ONRAMPS__SIGN_MOONPAY_URL' | 'ONRAMPS__SIGN_DEPOSIT_TX';
3
+ export type PortalMessageType = 'ONRAMPS__INIT' | 'ONRAMPS__UPDATE_PURCHASE' | 'ONRAMPS__SIGN_MOONPAY_URL' | 'ONRAMPS__SIGN_DEPOSIT_TX' | 'WALLET_SWITCH_COMPLETED';
4
4
  export type PortalMessageStatus = 'ERROR' | 'SUCCESS';
5
5
  export type PortalRequestPayload<T extends PortalMessageType> = T extends 'ONRAMPS__UPDATE_PURCHASE' ? {
6
6
  updates: OnRampPurchaseUpdateParams;
@@ -9,6 +9,8 @@ export type PortalRequestPayload<T extends PortalMessageType> = T extends 'ONRAM
9
9
  url: string;
10
10
  } : T extends 'ONRAMPS__SIGN_DEPOSIT_TX' ? {
11
11
  depositRequest: OfframpDepositRequest;
12
+ } : T extends 'WALLET_SWITCH_COMPLETED' ? {
13
+ walletIds?: CurrentWalletIds;
12
14
  } : never;
13
15
  export type PortalRequest = {
14
16
  isPara: boolean;
@@ -26,6 +28,9 @@ export type PortalRequest = {
26
28
  } | {
27
29
  type: 'ONRAMPS__SIGN_DEPOSIT_TX';
28
30
  payload: PortalRequestPayload<'ONRAMPS__SIGN_DEPOSIT_TX'>;
31
+ } | {
32
+ type: 'WALLET_SWITCH_COMPLETED';
33
+ payload: PortalRequestPayload<'WALLET_SWITCH_COMPLETED'>;
29
34
  });
30
35
  export type PortalResponsePayload<T extends PortalMessageType> = T extends 'ONRAMPS__INIT' ? {
31
36
  onRampPurchase: OnRampPurchase;
@@ -37,6 +42,8 @@ export type PortalResponsePayload<T extends PortalMessageType> = T extends 'ONRA
37
42
  } : T extends 'ONRAMPS__SIGN_DEPOSIT_TX' ? {
38
43
  txHash: string;
39
44
  onRampPurchase: OnRampPurchase;
45
+ } : T extends 'WALLET_SWITCH_COMPLETED' ? {
46
+ walletIds?: CurrentWalletIds;
40
47
  } : never;
41
48
  export type PortalResponse = {
42
49
  id: string;
@@ -63,4 +70,8 @@ export type PortalResponse = {
63
70
  status: 'SUCCESS';
64
71
  type: 'ONRAMPS__SIGN_DEPOSIT_TX';
65
72
  payload: PortalResponsePayload<'ONRAMPS__SIGN_DEPOSIT_TX'>;
73
+ } | {
74
+ status: 'SUCCESS';
75
+ type: 'WALLET_SWITCH_COMPLETED';
76
+ payload: PortalResponsePayload<'WALLET_SWITCH_COMPLETED'>;
66
77
  });
@@ -3,13 +3,13 @@ import {
3
3
  __async
4
4
  } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
- import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
6
+ import { distributeNewShare, waitUntilTrue, isPortal } from "@getpara/core-sdk";
7
7
  import * as uuid from "uuid";
8
8
  function isKeygenComplete(ctx, userId, walletId) {
9
9
  return __async(this, null, function* () {
10
- const wallets = yield ctx.client.getWallets(userId);
10
+ const wallets = yield (isPortal(ctx) ? ctx.client.getAllWallets : ctx.client.getWallets)(userId);
11
11
  const wallet = wallets.data.wallets.find((w) => w.id === walletId);
12
- return !!wallet.address;
12
+ return !!(wallet == null ? void 0 : wallet.address);
13
13
  });
14
14
  }
15
15
  function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
@@ -28,6 +28,17 @@ import {
28
28
  paraVersion
29
29
  } from "@getpara/core-sdk";
30
30
  let wasmLoaded = false;
31
+ function tryFetchWasm(url) {
32
+ return __async(this, null, function* () {
33
+ const response = yield fetch(url, { mode: "cors" });
34
+ const buffer = yield response.arrayBuffer();
35
+ const view = new Uint8Array(buffer);
36
+ if (view.length >= 4 && view[0] === 0 && view[1] === 97 && view[2] === 115 && view[3] === 109) {
37
+ return buffer;
38
+ }
39
+ throw new Error("invalid WASM magic bytes - possibly compressed data without proper Content-Encoding");
40
+ });
41
+ }
31
42
  function loadWasm(ctx, wasmOverride) {
32
43
  return __async(this, null, function* () {
33
44
  if (typeof self === "undefined") {
@@ -40,8 +51,8 @@ function loadWasm(ctx, wasmOverride) {
40
51
  if (process.env.DISABLE_WASM_FETCH === "true") {
41
52
  throw new Error("fetching wasm file is disabled");
42
53
  }
43
- const fetchedWasm = yield fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
44
- wasmArrayBuffer = yield fetchedWasm.arrayBuffer();
54
+ const wasmUrl = `${getPortalBaseURL(ctx)}/static/js/main.wasm`;
55
+ wasmArrayBuffer = yield tryFetchWasm(`${wasmUrl}.br`).catch(() => tryFetchWasm(`${wasmUrl}.gz`)).catch(() => tryFetchWasm(wasmUrl));
45
56
  }
46
57
  const newRes = yield WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
47
58
  goWasm.run(newRes.instance);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@getpara/web-sdk",
3
- "version": "2.0.0-alpha.62",
3
+ "version": "2.0.0-alpha.64",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "2.0.0-alpha.62",
6
- "@getpara/user-management-client": "2.0.0-alpha.62",
5
+ "@getpara/core-sdk": "2.0.0-alpha.64",
6
+ "@getpara/user-management-client": "2.0.0-alpha.64",
7
7
  "base64url": "^3.0.1",
8
8
  "buffer": "6.0.3",
9
9
  "cbor-web": "^9.0.2",
@@ -28,7 +28,7 @@
28
28
  "dist",
29
29
  "package.json"
30
30
  ],
31
- "gitHead": "a4e8ee28afb86a2318449def68eb7fcefdb31745",
31
+ "gitHead": "c55ecfbbd200053ddb78d88c93c597c0f781a6bb",
32
32
  "main": "dist/index.js",
33
33
  "scripts": {
34
34
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",