@getpara/web-sdk 2.0.0-alpha.63 → 2.0.0-alpha.65

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,29 @@ class Para extends ParaCore {
96
97
  }
97
98
  }
98
99
  break;
100
+ case "SYNC_WALLETS":
101
+ {
102
+ payload = {
103
+ wallets: this.wallets,
104
+ currentWalletIds: this.currentWalletIds
105
+ };
106
+ }
107
+ break;
99
108
  }
100
109
  } catch (e) {
101
110
  status = "ERROR";
102
111
  payload = { error: e.message };
103
112
  }
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();
113
+ if (messagePort) {
114
+ messagePort.postMessage({
115
+ id: event.data.id,
116
+ type: event.data.type,
117
+ isPara: true,
118
+ status,
119
+ payload
120
+ });
121
+ messagePort.close();
122
+ }
112
123
  });
113
124
  __privateAdd(this, _isPasskeySupported);
114
125
  if (typeof window !== "undefined") {
@@ -119,21 +130,27 @@ class Para extends ParaCore {
119
130
  return __async(this, null, function* () {
120
131
  var _a, _b, _c, _d;
121
132
  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");
133
+ if (!this.isFarcasterSetup) {
134
+ try {
135
+ this.farcasterSdk = (_b = (_a = yield import("@farcaster/miniapp-sdk")) == null ? void 0 : _a.sdk) != null ? _b : void 0;
136
+ if (!((_c = this.farcasterSdk) == null ? void 0 : _c.isInMiniApp)) {
137
+ throw new Error("Farcaster SDK not detected or failed to load");
138
+ }
139
+ this.devLog("Farcaster SDK detected and loaded successfully.", this.farcasterSdk);
140
+ } catch (e) {
141
+ this.devLog(e);
126
142
  }
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;
143
+ if (!!((_d = this.farcasterSdk) == null ? void 0 : _d.isInMiniApp)) {
144
+ this.devLog("Initializing Farcaster SDK...");
145
+ this.isFarcasterMiniApp = yield this.farcasterSdk.isInMiniApp();
146
+ if (this.isFarcasterMiniApp) {
147
+ this.externalWalletConnectionOnly = true;
148
+ }
136
149
  }
150
+ this.isFarcasterSetup = true;
151
+ }
152
+ if (!this.isPortal() && Object.values(this.wallets).length > 0 && Object.values(this.wallets).every((wallet) => !wallet.partner)) {
153
+ yield this.populateWalletAddresses();
137
154
  }
138
155
  this.isReady = true;
139
156
  }
package/dist/WebUtils.js CHANGED
@@ -69,7 +69,8 @@ class WebUtils {
69
69
  popUpHeight = 464;
70
70
  break;
71
71
  }
72
- case PopupType.SIGN_MESSAGE_REVIEW: {
72
+ case PopupType.SIGN_MESSAGE_REVIEW:
73
+ case PopupType.EXPORT_PRIVATE_KEY: {
73
74
  popUpHeight = 585;
74
75
  break;
75
76
  }
@@ -1,6 +1,6 @@
1
- import { OnRampConfig, OnRampPurchase, OnRampPurchaseUpdateParams } from '@getpara/user-management-client';
2
- import { OfframpDepositRequest } from '@getpara/core-sdk';
3
- export type PortalMessageType = 'ONRAMPS__INIT' | 'ONRAMPS__UPDATE_PURCHASE' | 'ONRAMPS__SIGN_MOONPAY_URL' | 'ONRAMPS__SIGN_DEPOSIT_TX';
1
+ import { CurrentWalletIds, OnRampConfig, OnRampPurchase, OnRampPurchaseUpdateParams } from '@getpara/user-management-client';
2
+ import { OfframpDepositRequest, Wallet } from '@getpara/core-sdk';
3
+ export type PortalMessageType = 'ONRAMPS__INIT' | 'ONRAMPS__UPDATE_PURCHASE' | 'ONRAMPS__SIGN_MOONPAY_URL' | 'ONRAMPS__SIGN_DEPOSIT_TX' | 'WALLET_SWITCH_COMPLETED' | 'SYNC_WALLETS';
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,7 +9,9 @@ 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
- } : never;
12
+ } : T extends 'WALLET_SWITCH_COMPLETED' ? {
13
+ walletIds?: CurrentWalletIds;
14
+ } : T extends 'SYNC_WALLETS' ? undefined : never;
13
15
  export type PortalRequest = {
14
16
  isPara: boolean;
15
17
  id: string;
@@ -26,6 +28,12 @@ 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'>;
34
+ } | {
35
+ type: 'SYNC_WALLETS';
36
+ payload?: undefined;
29
37
  });
30
38
  export type PortalResponsePayload<T extends PortalMessageType> = T extends 'ONRAMPS__INIT' ? {
31
39
  onRampPurchase: OnRampPurchase;
@@ -37,6 +45,11 @@ export type PortalResponsePayload<T extends PortalMessageType> = T extends 'ONRA
37
45
  } : T extends 'ONRAMPS__SIGN_DEPOSIT_TX' ? {
38
46
  txHash: string;
39
47
  onRampPurchase: OnRampPurchase;
48
+ } : T extends 'WALLET_SWITCH_COMPLETED' ? {
49
+ walletIds?: CurrentWalletIds;
50
+ } : T extends 'SYNC_WALLETS' ? {
51
+ wallets: Record<string, Wallet>;
52
+ currentWalletIds?: CurrentWalletIds;
40
53
  } : never;
41
54
  export type PortalResponse = {
42
55
  id: string;
@@ -63,4 +76,12 @@ export type PortalResponse = {
63
76
  status: 'SUCCESS';
64
77
  type: 'ONRAMPS__SIGN_DEPOSIT_TX';
65
78
  payload: PortalResponsePayload<'ONRAMPS__SIGN_DEPOSIT_TX'>;
79
+ } | {
80
+ status: 'SUCCESS';
81
+ type: 'WALLET_SWITCH_COMPLETED';
82
+ payload: PortalResponsePayload<'WALLET_SWITCH_COMPLETED'>;
83
+ } | {
84
+ status: 'SUCCESS';
85
+ type: 'SYNC_WALLETS';
86
+ payload: PortalResponsePayload<'SYNC_WALLETS'>;
66
87
  });
@@ -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.63",
3
+ "version": "2.0.0-alpha.65",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "2.0.0-alpha.63",
6
- "@getpara/user-management-client": "2.0.0-alpha.63",
5
+ "@getpara/core-sdk": "2.0.0-alpha.65",
6
+ "@getpara/user-management-client": "2.0.0-alpha.65",
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": "440300efa66a6bc808504e2771b21e92bdee4c9b",
31
+ "gitHead": "9945ab14944c22851eb81c5bbb831b23bf7eaf2a",
32
32
  "main": "dist/index.js",
33
33
  "scripts": {
34
34
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",