@getpara/web-sdk 2.0.0-fc.2 → 2.0.0

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/README.md ADDED
@@ -0,0 +1,20 @@
1
+ https://www.npmjs.com/package/@getpara/web-sdk
2
+
3
+ The `@getpara/web-sdk` is Para's core Web SDK for browser environments. It provides direct access to Para's wallet infrastructure without React-specific components.
4
+
5
+ ###Key Features
6
+
7
+ - Authentication: Email, phone, and OAuth login methods
8
+ - Wallet Management: Create and manage EVM, Solana, and Cosmos wallets
9
+ - Transaction Signing: Sign messages and transactions across multiple chains
10
+ - Session Management: Handle user sessions and JWT tokens
11
+
12
+ ###Prerequisites
13
+
14
+ To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration.
15
+
16
+ Don't have an API key yet? Request access to the [Developer Portal](https://developer.getpara.com/) to create API keys, manage billing, teams, and more.
17
+
18
+ ###Learn more
19
+
20
+ For more information on Para’s Web SDK visit the [Para Docs](https://docs.getpara.com/v2/react/examples#para-web-examples)
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "./chunk-WLGKV3EF.js";
2
+ import "./chunk-YJOFEY2L.js";
3
3
  class LocalStorage {
4
4
  constructor() {
5
5
  this.get = (key) => {
package/dist/ParaWeb.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  import ParaCore, { ConstructorOpts, Environment } from '@getpara/core-sdk';
2
2
  import { WebUtils } from './WebUtils.js';
3
+ import { PortalRequest } from './types/onRamp.js';
3
4
  export declare class Para extends ParaCore {
4
5
  #private;
5
6
  farcasterSdk: any;
6
7
  isReady: boolean;
7
8
  isFarcasterMiniApp: boolean;
8
- constructor(env: Environment, apiKey?: string, opts?: ConstructorOpts);
9
- protected ready(): Promise<void>;
9
+ private isFarcasterSetup;
10
+ constructor(env: Environment | undefined, apiKey: string, opts?: ConstructorOpts);
11
+ constructor(apiKey: string, opts?: ConstructorOpts);
12
+ ready(): Promise<void>;
13
+ protected portalEventListener: (event: MessageEvent<PortalRequest>) => Promise<void>;
10
14
  protected get toStringAdditions(): {
11
15
  isFarcasterMiniApp: boolean;
12
16
  };
package/dist/ParaWeb.js CHANGED
@@ -3,46 +3,154 @@ import {
3
3
  __async,
4
4
  __privateAdd,
5
5
  __privateGet,
6
- __privateSet
7
- } from "./chunk-WLGKV3EF.js";
6
+ __privateSet,
7
+ __spreadValues
8
+ } from "./chunk-YJOFEY2L.js";
8
9
  var _isPasskeySupported;
9
- import * as Sentry from "@sentry/browser";
10
- import ParaCore, { Environment } from "@getpara/core-sdk";
10
+ import ParaCore, {
11
+ dispatchEvent,
12
+ getNetworkPrefix,
13
+ OnRampPurchaseStatus,
14
+ ParaEvent
15
+ } from "@getpara/core-sdk";
11
16
  import { WebUtils } from "./WebUtils.js";
12
17
  import { isPasskeySupported } from "./utils/isPasskeySupported.js";
18
+ import { offRampSend } from "./utils/offrampSend.js";
13
19
  class Para extends ParaCore {
14
- constructor(env, apiKey, opts) {
15
- super(env, apiKey, opts);
20
+ constructor(envOrApiKey, apiKeyOrOpts, opts) {
21
+ super(envOrApiKey, apiKeyOrOpts, opts);
16
22
  this.farcasterSdk = void 0;
17
23
  this.isReady = false;
18
24
  this.isFarcasterMiniApp = false;
25
+ this.isFarcasterSetup = false;
26
+ this.portalEventListener = (event) => __async(this, null, function* () {
27
+ var _a, _b, _c, _d, _e, _f;
28
+ if (!event.data.isPara || event.origin !== (yield this.getPortalURL()) || this.isPortal()) {
29
+ return;
30
+ }
31
+ const messagePort = event.ports[0];
32
+ let payload, status = "SUCCESS";
33
+ try {
34
+ switch (event.data.type) {
35
+ case "ONRAMPS__INIT":
36
+ {
37
+ const onRampConfig = yield this.ctx.client.getOnRampConfig();
38
+ payload = { onRampPurchase: (_a = this.onRampPopup) == null ? void 0 : _a.onRampPurchase, onRampConfig };
39
+ }
40
+ break;
41
+ case "ONRAMPS__UPDATE_PURCHASE":
42
+ {
43
+ const { updates, depositRequest } = event.data.payload;
44
+ if ((_b = this.onRampPopup) == null ? void 0 : _b.onRampPurchase) {
45
+ this.onRampPopup.onRampPurchase = __spreadValues(__spreadValues({}, (_c = this.onRampPopup) == null ? void 0 : _c.onRampPurchase), updates);
46
+ const onRampPurchase = this.onRampPopup.onRampPurchase;
47
+ if (onRampPurchase.status === OnRampPurchaseStatus.FINISHED) {
48
+ const wallet = this.findWallet((_d = onRampPurchase.externalWalletAddress) != null ? _d : onRampPurchase.walletId);
49
+ if (wallet) {
50
+ const { asset, assetQuantity, network, address } = onRampPurchase;
51
+ if (depositRequest) {
52
+ const { chainId, contractAddress, destinationAddress } = depositRequest;
53
+ dispatchEvent(ParaEvent.ASSET_TRANSFERRED, {
54
+ wallet,
55
+ type: "OUTBOUND",
56
+ asset,
57
+ network,
58
+ quantity: assetQuantity,
59
+ chainId,
60
+ contractAddress,
61
+ sourceAddress: address,
62
+ destinationAddress
63
+ });
64
+ }
65
+ dispatchEvent(ParaEvent.ONRAMP_TRANSACTION_COMPLETE, onRampPurchase);
66
+ }
67
+ }
68
+ payload = { onRampPurchase };
69
+ }
70
+ }
71
+ break;
72
+ case "ONRAMPS__SIGN_MOONPAY_URL":
73
+ {
74
+ const userId = this.assertUserId();
75
+ const { url } = event.data.payload;
76
+ const onRampPurchase = (_e = this.onRampPopup) == null ? void 0 : _e.onRampPurchase;
77
+ const res = yield this.ctx.client.signMoonPayUrl(userId, {
78
+ url,
79
+ type: onRampPurchase.walletType,
80
+ cosmosPrefix: getNetworkPrefix(onRampPurchase.network),
81
+ testMode: onRampPurchase.testMode,
82
+ walletId: onRampPurchase.walletId,
83
+ externalWalletAddress: onRampPurchase.externalWalletAddress
84
+ });
85
+ payload = { signature: res.data.signature };
86
+ }
87
+ break;
88
+ case "ONRAMPS__SIGN_DEPOSIT_TX":
89
+ {
90
+ const { depositRequest } = event.data.payload;
91
+ const onRampPurchase = (_f = this.onRampPopup) == null ? void 0 : _f.onRampPurchase;
92
+ try {
93
+ const { txHash, updatedOnRampPurchase } = yield offRampSend(this, onRampPurchase, depositRequest);
94
+ payload = { onRampPurchase: updatedOnRampPurchase, txHash };
95
+ } catch (e) {
96
+ throw e;
97
+ }
98
+ }
99
+ break;
100
+ case "SYNC_WALLETS":
101
+ {
102
+ payload = {
103
+ wallets: this.wallets,
104
+ currentWalletIds: this.currentWalletIds
105
+ };
106
+ }
107
+ break;
108
+ }
109
+ } catch (e) {
110
+ status = "ERROR";
111
+ payload = { error: e.message };
112
+ }
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
+ }
123
+ });
19
124
  __privateAdd(this, _isPasskeySupported);
20
- if (env !== Environment.PROD && env !== Environment.DEV) {
21
- Sentry.init({
22
- environment: env.toLowerCase(),
23
- dsn: "https://38f27d4836da617ab9e95cf66b9611d9@o4504568036720640.ingest.us.sentry.io/4508850812944384"
24
- });
125
+ if (typeof window !== "undefined") {
126
+ window.addEventListener("message", this.portalEventListener);
25
127
  }
26
128
  }
27
129
  ready() {
28
130
  return __async(this, null, function* () {
29
131
  var _a, _b, _c, _d;
30
132
  if (!this.isReady) {
31
- try {
32
- this.farcasterSdk = (_b = (_a = yield import("@farcaster/miniapp-sdk")) == null ? void 0 : _a.sdk) != null ? _b : void 0;
33
- if (!((_c = this.farcasterSdk) == null ? void 0 : _c.isInMiniApp)) {
34
- 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);
35
142
  }
36
- this.devLog("Farcaster SDK detected and loaded successfully.", this.farcasterSdk);
37
- } catch (e) {
38
- this.devLog(e);
39
- }
40
- if (!!((_d = this.farcasterSdk) == null ? void 0 : _d.isInMiniApp)) {
41
- this.devLog("Initializing Farcaster SDK...");
42
- this.isFarcasterMiniApp = yield this.farcasterSdk.isInMiniApp();
43
- if (this.isFarcasterMiniApp) {
44
- 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
+ }
45
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();
46
154
  }
47
155
  this.isReady = true;
48
156
  }
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "./chunk-WLGKV3EF.js";
2
+ import "./chunk-YJOFEY2L.js";
3
3
  class SessionStorage {
4
4
  constructor() {
5
5
  this.get = (key) => {
@@ -43,5 +43,6 @@ export declare class WebUtils implements PlatformUtils {
43
43
  disableProviderModal: boolean;
44
44
  openPopup(popupUrl: string, opts?: {
45
45
  type: PopupType;
46
- }): Window;
46
+ }): Promise<Window>;
47
+ initializeWorker(ctx: Ctx): Promise<void>;
47
48
  }
package/dist/WebUtils.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use client";
2
- import "./chunk-WLGKV3EF.js";
2
+ import {
3
+ __async
4
+ } from "./chunk-YJOFEY2L.js";
3
5
  import { PopupType } from "@getpara/core-sdk";
4
6
  import { LocalStorage } from "./LocalStorage.js";
5
7
  import { SessionStorage } from "./SessionStorage.js";
6
- import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen, refresh } from "./wallet/keygen.js";
8
+ import { keygen, preKeygen, ed25519Keygen, ed25519PreKeygen, refresh, initializeWorker } from "./wallet/keygen.js";
7
9
  import { signMessage, sendTransaction, signTransaction, ed25519Sign } from "./wallet/signing.js";
8
10
  import { getPrivateKey } from "./wallet/privateKey.js";
9
11
  class WebUtils {
@@ -49,60 +51,71 @@ class WebUtils {
49
51
  return ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie);
50
52
  }
51
53
  openPopup(popupUrl, opts) {
52
- if (typeof window === "undefined") {
53
- return;
54
- }
55
- if (opts) {
56
- const { type } = opts;
57
- const popUpWidth = 550;
58
- let popUpHeight;
59
- switch (type) {
60
- case PopupType.LOGIN_PASSKEY: {
61
- popUpHeight = 798;
62
- break;
63
- }
64
- case PopupType.CREATE_PASSKEY: {
65
- popUpHeight = 464;
66
- break;
67
- }
68
- case PopupType.SIGN_MESSAGE_REVIEW: {
69
- popUpHeight = 585;
70
- break;
54
+ return __async(this, null, function* () {
55
+ if (typeof window === "undefined") {
56
+ return;
57
+ }
58
+ let popupWindow = null;
59
+ if (opts) {
60
+ const { type } = opts;
61
+ const popUpWidth = 550;
62
+ let popUpHeight;
63
+ switch (type) {
64
+ case PopupType.LOGIN_PASSKEY: {
65
+ popUpHeight = 798;
66
+ break;
67
+ }
68
+ case PopupType.CREATE_PASSKEY: {
69
+ popUpHeight = 464;
70
+ break;
71
+ }
72
+ case PopupType.SIGN_MESSAGE_REVIEW:
73
+ case PopupType.EXPORT_PRIVATE_KEY: {
74
+ popUpHeight = 585;
75
+ break;
76
+ }
77
+ case PopupType.SIGN_TRANSACTION_REVIEW: {
78
+ popUpHeight = 750;
79
+ break;
80
+ }
81
+ case PopupType.OAUTH:
82
+ default: {
83
+ popUpHeight = 768;
84
+ break;
85
+ }
71
86
  }
72
- case PopupType.SIGN_TRANSACTION_REVIEW: {
73
- popUpHeight = 750;
74
- break;
87
+ const dualScreenLeft = window.screenLeft !== void 0 ? window.screenLeft : window.screenX;
88
+ const dualScreenTop = window.screenTop !== void 0 ? window.screenTop : window.screenY;
89
+ const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
90
+ const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
91
+ const left = (width - popUpWidth) / 2 + dualScreenLeft;
92
+ const top = (height - popUpHeight) / 2 + dualScreenTop;
93
+ const windowFeatures = `toolbar=no, menubar=no, width=${popUpWidth},
94
+ height=${popUpHeight}, top=${top}, left=${left}`;
95
+ popupWindow = window.open(popupUrl, type.toString(), windowFeatures);
96
+ if (!popupWindow) {
97
+ setTimeout(() => {
98
+ popupWindow = window.open(popupUrl, "_blank");
99
+ }, 0);
75
100
  }
76
- case PopupType.OAUTH:
77
- default: {
78
- popUpHeight = 768;
79
- break;
101
+ } else {
102
+ popupWindow = window.open(popupUrl, "popup", "popup=true,width=400,height=500");
103
+ if (!popupWindow) {
104
+ setTimeout(() => {
105
+ popupWindow = window.open(popupUrl, "_blank");
106
+ }, 0);
80
107
  }
81
108
  }
82
- const dualScreenLeft = window.screenLeft !== void 0 ? window.screenLeft : window.screenX;
83
- const dualScreenTop = window.screenTop !== void 0 ? window.screenTop : window.screenY;
84
- const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
85
- const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
86
- const left = (width - popUpWidth) / 2 + dualScreenLeft;
87
- const top = (height - popUpHeight) / 2 + dualScreenTop;
88
- const windowFeatures = `toolbar=no, menubar=no, width=${popUpWidth},
89
- height=${popUpHeight}, top=${top}, left=${left}`;
90
- let popupWindow = window.open(popupUrl, type.toString(), windowFeatures);
91
- if (!popupWindow) {
92
- setTimeout(() => {
93
- popupWindow = window.open(popupUrl, "_blank");
94
- }, 0);
95
- }
96
- return popupWindow;
97
- } else {
98
- const popupWindow = window.open(popupUrl, "popup", "popup=true,width=400,height=500");
99
- if (!popupWindow) {
100
- setTimeout(() => {
101
- window.open(popupUrl, "_blank");
102
- }, 0);
109
+ while (!popupWindow) {
110
+ yield new Promise((resolve) => setTimeout(resolve, 100));
103
111
  }
104
112
  return popupWindow;
105
- }
113
+ });
114
+ }
115
+ initializeWorker(ctx) {
116
+ return __async(this, null, function* () {
117
+ return initializeWorker(ctx);
118
+ });
106
119
  }
107
120
  }
108
121
  export {
@@ -1,7 +1,23 @@
1
1
  "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2
6
  var __typeError = (msg) => {
3
7
  throw TypeError(msg);
4
8
  };
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
5
21
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
6
22
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
7
23
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
@@ -28,6 +44,7 @@ var __async = (__this, __arguments, generator) => {
28
44
  };
29
45
 
30
46
  export {
47
+ __spreadValues,
31
48
  __privateGet,
32
49
  __privateAdd,
33
50
  __privateSet,
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import base64url from "base64url";
6
6
  import * as cbor from "cbor-web";
7
7
  import forge from "node-forge";
package/dist/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "./chunk-WLGKV3EF.js";
2
+ import "./chunk-YJOFEY2L.js";
3
3
  class TransactionReviewError extends Error {
4
4
  constructor(transactionReviewUrl) {
5
5
  super("transaction review error");
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export * from '@getpara/core-sdk';
2
2
  import { Para as ParaWeb } from './ParaWeb.js';
3
3
  import ParaCore from '@getpara/core-sdk';
4
- export { type StorageUtils, type ConstructorOpts, Environment, type OnRampConfig, type OnRampAllowedAssets, } from '@getpara/core-sdk';
4
+ export { type StorageUtils, type ConstructorOpts, Environment, type OnRampConfig, type OnRampAssets, } from '@getpara/core-sdk';
5
5
  export { createCredential, generateSignature, parseCredentialCreationRes } from './cryptography/webAuth.js';
6
- export { truncateEthAddress } from './utils/truncateEthAddress.js';
7
- export { isPasskeySupported } from './utils/isPasskeySupported.js';
6
+ export { truncateEthAddress, isPasskeySupported, offRampSend } from './utils/index.js';
8
7
  export * from './utils/isMobile.js';
8
+ export * from './types/index.js';
9
9
  export { ParaWeb, ParaCore };
10
10
  export default ParaWeb;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "./chunk-WLGKV3EF.js";
2
+ import "./chunk-YJOFEY2L.js";
3
3
  export * from "@getpara/core-sdk";
4
4
  import { Para as ParaWeb } from "./ParaWeb.js";
5
5
  import ParaCore from "@getpara/core-sdk";
@@ -7,9 +7,9 @@ import {
7
7
  Environment
8
8
  } from "@getpara/core-sdk";
9
9
  import { createCredential, generateSignature, parseCredentialCreationRes } from "./cryptography/webAuth.js";
10
- import { truncateEthAddress } from "./utils/truncateEthAddress.js";
11
- import { isPasskeySupported } from "./utils/isPasskeySupported.js";
10
+ import { truncateEthAddress, isPasskeySupported, offRampSend } from "./utils/index.js";
12
11
  export * from "./utils/isMobile.js";
12
+ export * from "./types/index.js";
13
13
  var src_default = ParaWeb;
14
14
  export {
15
15
  Environment,
@@ -19,6 +19,7 @@ export {
19
19
  src_default as default,
20
20
  generateSignature,
21
21
  isPasskeySupported,
22
+ offRampSend,
22
23
  parseCredentialCreationRes,
23
24
  truncateEthAddress
24
25
  };
@@ -0,0 +1 @@
1
+ export * from './onRamp.js';
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export * from "./onRamp.js";
@@ -0,0 +1,87 @@
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
+ export type PortalMessageStatus = 'ERROR' | 'SUCCESS';
5
+ export type PortalRequestPayload<T extends PortalMessageType> = T extends 'ONRAMPS__UPDATE_PURCHASE' ? {
6
+ updates: OnRampPurchaseUpdateParams;
7
+ depositRequest?: OfframpDepositRequest;
8
+ } : T extends 'ONRAMPS__SIGN_MOONPAY_URL' ? {
9
+ url: string;
10
+ } : T extends 'ONRAMPS__SIGN_DEPOSIT_TX' ? {
11
+ depositRequest: OfframpDepositRequest;
12
+ } : T extends 'WALLET_SWITCH_COMPLETED' ? {
13
+ walletIds?: CurrentWalletIds;
14
+ } : T extends 'SYNC_WALLETS' ? undefined : never;
15
+ export type PortalRequest = {
16
+ isPara: boolean;
17
+ id: string;
18
+ status?: undefined;
19
+ } & ({
20
+ type: 'ONRAMPS__INIT';
21
+ payload?: undefined;
22
+ } | {
23
+ type: 'ONRAMPS__UPDATE_PURCHASE';
24
+ payload: PortalRequestPayload<'ONRAMPS__UPDATE_PURCHASE'>;
25
+ } | {
26
+ type: 'ONRAMPS__SIGN_MOONPAY_URL';
27
+ payload: PortalRequestPayload<'ONRAMPS__SIGN_MOONPAY_URL'>;
28
+ } | {
29
+ type: 'ONRAMPS__SIGN_DEPOSIT_TX';
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;
37
+ });
38
+ export type PortalResponsePayload<T extends PortalMessageType> = T extends 'ONRAMPS__INIT' ? {
39
+ onRampPurchase: OnRampPurchase;
40
+ onRampConfig: OnRampConfig;
41
+ } : T extends 'ONRAMPS__UPDATE_PURCHASE' ? {
42
+ onRampPurchase: OnRampPurchase;
43
+ } : T extends 'ONRAMPS__SIGN_MOONPAY_URL' ? {
44
+ signature: string;
45
+ } : T extends 'ONRAMPS__SIGN_DEPOSIT_TX' ? {
46
+ txHash: string;
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;
53
+ } : never;
54
+ export type PortalResponse = {
55
+ id: string;
56
+ status: PortalMessageStatus;
57
+ type: PortalMessageType;
58
+ } & ({
59
+ status: 'ERROR';
60
+ payload: {
61
+ error: string;
62
+ };
63
+ } | {
64
+ status: 'SUCCESS';
65
+ type: 'ONRAMPS__INIT';
66
+ payload: PortalResponsePayload<'ONRAMPS__INIT'>;
67
+ } | {
68
+ status: 'SUCCESS';
69
+ type: 'ONRAMPS__UPDATE_PURCHASE';
70
+ payload: PortalResponsePayload<'ONRAMPS__UPDATE_PURCHASE'>;
71
+ } | {
72
+ status: 'SUCCESS';
73
+ type: 'ONRAMPS__SIGN_MOONPAY_URL';
74
+ payload: PortalResponsePayload<'ONRAMPS__SIGN_MOONPAY_URL'>;
75
+ } | {
76
+ status: 'SUCCESS';
77
+ type: 'ONRAMPS__SIGN_DEPOSIT_TX';
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'>;
87
+ });
@@ -0,0 +1 @@
1
+ "use client";
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "../chunk-WLGKV3EF.js";
2
+ import "../chunk-YJOFEY2L.js";
3
3
  function getMailtoLink(email, recoveryShare) {
4
4
  const emailBody = `Hello,%0D%0DBelow is your Para Recovery Secret. Keep this safe!%0D%0D${recoveryShare}%0D%0DPlease get in touch via support@getpara.com if you have any questions`;
5
5
  const mailText = `mailto:${email}?subject=Para%20Recovery%20Secret&body=${emailBody}`;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "../chunk-WLGKV3EF.js";
2
+ import "../chunk-YJOFEY2L.js";
3
3
  function hexStringToBase64(hexString) {
4
4
  if (hexString.substring(0, 2) === "0x") {
5
5
  hexString = hexString.substring(2);
@@ -0,0 +1,5 @@
1
+ export * from './emailUtils.js';
2
+ export * from './formattingUtils.js';
3
+ export * from './isPasskeySupported.js';
4
+ export * from './offrampSend.js';
5
+ export * from './truncateEthAddress.js';
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ export * from "./emailUtils.js";
3
+ export * from "./formattingUtils.js";
4
+ export * from "./isPasskeySupported.js";
5
+ export * from "./offrampSend.js";
6
+ export * from "./truncateEthAddress.js";
@@ -1,7 +1,9 @@
1
1
  "use client";
2
- import "../chunk-WLGKV3EF.js";
2
+ import "../chunk-YJOFEY2L.js";
3
3
  function isAndroid() {
4
- return typeof navigator !== "undefined" && /android/i.test(navigator.userAgent);
4
+ if (typeof navigator === "undefined") return false;
5
+ const userAgent = navigator.userAgent.toLowerCase();
6
+ return /android/i.test(userAgent) || /linux.*mobile/i.test(userAgent) || navigator.platform && navigator.platform.toLowerCase().includes("android");
5
7
  }
6
8
  function isSmallIOS() {
7
9
  return typeof navigator !== "undefined" && /iPhone|iPod/.test(navigator.userAgent);
@@ -10,9 +12,15 @@ function isLargeIOS() {
10
12
  return typeof navigator !== "undefined" && (/iPad/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
11
13
  }
12
14
  function isTablet() {
13
- return typeof navigator !== "undefined" && /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(
14
- navigator.userAgent
15
- );
15
+ if (typeof navigator === "undefined") return false;
16
+ const userAgent = navigator.userAgent.toLowerCase();
17
+ if (/ipad/.test(userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1) {
18
+ return true;
19
+ }
20
+ if (/android/.test(userAgent)) {
21
+ return /tablet/.test(userAgent) || /android/.test(userAgent) && !/mobile/.test(userAgent) && typeof screen !== "undefined" && screen.width >= 768;
22
+ }
23
+ return /(tablet|kindle|playbook|silk)/.test(userAgent);
16
24
  }
17
25
  function isIOS() {
18
26
  return isSmallIOS() || isLargeIOS();
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { UAParser } from "ua-parser-js";
6
6
  const isPasskeySupported = (userAgent) => __async(void 0, null, function* () {
7
7
  var _a, _b, _c;
@@ -0,0 +1,5 @@
1
+ import Para, { OfframpDepositRequest, OnRampPurchase } from '@getpara/core-sdk';
2
+ export declare function offRampSend(para: Para, { id: purchaseId, provider, walletId, walletType, address, testMode }: Partial<OnRampPurchase>, { assetQuantity, fiat, fiatQuantity, chainId, destinationAddress, contractAddress }: OfframpDepositRequest): Promise<{
3
+ txHash: string;
4
+ updatedOnRampPurchase: OnRampPurchase;
5
+ }>;
@@ -0,0 +1,67 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-YJOFEY2L.js";
5
+ import { hexStringToBase64 } from "@getpara/core-sdk";
6
+ function offRampSend(_0, _1, _2) {
7
+ return __async(this, arguments, function* (para, { id: purchaseId, provider, walletId, walletType, address, testMode = false }, { assetQuantity, fiat, fiatQuantity, chainId, destinationAddress, contractAddress }) {
8
+ var _a, _b, _c;
9
+ if (!purchaseId || !walletId || !walletType || !provider) {
10
+ throw new Error("Missing required fields");
11
+ }
12
+ try {
13
+ const { tx, message, network, asset } = yield para.ctx.client.generateOffRampTx(para.getUserId(), {
14
+ walletId,
15
+ walletType,
16
+ provider,
17
+ chainId,
18
+ destinationAddress,
19
+ sourceAddress: address,
20
+ contractAddress,
21
+ testMode,
22
+ assetQuantity
23
+ });
24
+ let signature;
25
+ switch (walletType) {
26
+ case "EVM":
27
+ signature = (_a = yield para.signTransaction({
28
+ walletId,
29
+ rlpEncodedTxBase64: hexStringToBase64(tx),
30
+ chainId
31
+ })) == null ? void 0 : _a.signature;
32
+ break;
33
+ case "SOLANA":
34
+ signature = (_b = yield para.signMessage({ walletId, messageBase64: message })) == null ? void 0 : _b.signature;
35
+ break;
36
+ default:
37
+ throw new Error(`Unsupported wallet type: ${walletType}`);
38
+ }
39
+ const { txHash } = yield para.ctx.client.sendOffRampTx(para.getUserId(), {
40
+ tx,
41
+ signature: walletType === "EVM" ? `0x${signature}` : signature,
42
+ sourceAddress: address,
43
+ network,
44
+ walletId,
45
+ walletType
46
+ });
47
+ const updatedOnRampPurchase = yield para.ctx.client.updateOnRampPurchase({
48
+ userId: para.getUserId(),
49
+ walletId,
50
+ purchaseId,
51
+ updates: {
52
+ fiat,
53
+ fiatQuantity,
54
+ assetQuantity,
55
+ network,
56
+ asset
57
+ }
58
+ });
59
+ return { txHash, updatedOnRampPurchase };
60
+ } catch (e) {
61
+ throw new Error(((_c = e.response) == null ? void 0 : _c.data) || e.message);
62
+ }
63
+ });
64
+ }
65
+ export {
66
+ offRampSend
67
+ };
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import "../chunk-WLGKV3EF.js";
2
+ import "../chunk-YJOFEY2L.js";
3
3
  const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/;
4
4
  const truncateEthAddress = (address) => {
5
5
  const match = address.match(truncateRegex);
@@ -24,3 +24,4 @@ export declare function ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pre
24
24
  walletId: string;
25
25
  recoveryShare: string | null;
26
26
  }>;
27
+ export declare function initializeWorker(ctx: Ctx): Promise<void>;
@@ -1,15 +1,15 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
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) {
@@ -48,7 +48,10 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
48
48
  userId,
49
49
  walletId: res.walletId,
50
50
  userShare: res.signer,
51
- emailProps
51
+ emailProps,
52
+ isEnclaveUser: false,
53
+ walletScheme: "DKLS"
54
+ // since `isEnclaveUser` is false, we can use `DKLS` here as it won't be used
52
55
  });
53
56
  resolve({
54
57
  signer: res.signer,
@@ -241,9 +244,33 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
241
244
  });
242
245
  }));
243
246
  }
247
+ function initializeWorker(ctx) {
248
+ return __async(this, null, function* () {
249
+ return new Promise((resolve, reject) => __async(this, null, function* () {
250
+ const workId = uuid.v4();
251
+ const worker = yield setupWorker(
252
+ ctx,
253
+ () => __async(this, null, function* () {
254
+ resolve();
255
+ }),
256
+ (error) => {
257
+ reject(error);
258
+ },
259
+ workId
260
+ );
261
+ worker.postMessage({
262
+ env: ctx.env,
263
+ apiKey: ctx.apiKey,
264
+ functionType: "INIT",
265
+ workId
266
+ });
267
+ }));
268
+ });
269
+ }
244
270
  export {
245
271
  ed25519Keygen,
246
272
  ed25519PreKeygen,
273
+ initializeWorker,
247
274
  keygen,
248
275
  preKeygen,
249
276
  refresh
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
6
  import * as uuid from "uuid";
7
7
  function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
6
  import * as uuid from "uuid";
7
7
  function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  (() => {
6
6
  const enosys = () => {
7
7
  const err = new Error("not implemented");
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { getBaseMPCNetworkUrl } from "@getpara/core-sdk";
6
6
  import * as uuid from "uuid";
7
7
  const configCGGMPBase = (serverUrl, walletId, id) => `{"ServerUrl":"${serverUrl}", "WalletId": "${walletId}", "Id":"${id}", "Ids":["USER","CAPSULE"], "Threshold":1}`;
@@ -20,8 +20,25 @@ var __async = (__this, __arguments, generator) => {
20
20
  });
21
21
  };
22
22
  import * as walletUtils from "./walletUtils.js";
23
- import { getPortalBaseURL, initClient, mpcComputationClient, paraVersion } from "@getpara/core-sdk";
23
+ import {
24
+ getBaseMPCNetworkUrl,
25
+ getPortalBaseURL,
26
+ initClient,
27
+ mpcComputationClient,
28
+ paraVersion
29
+ } from "@getpara/core-sdk";
24
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
+ }
25
42
  function loadWasm(ctx, wasmOverride) {
26
43
  return __async(this, null, function* () {
27
44
  if (typeof self === "undefined") {
@@ -34,8 +51,8 @@ function loadWasm(ctx, wasmOverride) {
34
51
  if (process.env.DISABLE_WASM_FETCH === "true") {
35
52
  throw new Error("fetching wasm file is disabled");
36
53
  }
37
- const fetchedWasm = yield fetch(`${getPortalBaseURL(ctx)}/static/js/main.wasm`, { mode: "cors" });
38
- 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));
39
56
  }
40
57
  const newRes = yield WebAssembly.instantiate(wasmArrayBuffer, goWasm.importObject);
41
58
  goWasm.run(newRes.instance);
@@ -45,6 +62,9 @@ function executeMessage(ctx, message) {
45
62
  return __async(this, null, function* () {
46
63
  const { functionType, params, returnObject } = message;
47
64
  switch (functionType) {
65
+ case "INIT": {
66
+ return {};
67
+ }
48
68
  case "KEYGEN": {
49
69
  const { userId, secretKey, type = "EVM" } = params;
50
70
  const keygenRes = yield walletUtils.keygen(ctx, userId, type, secretKey);
@@ -87,7 +107,8 @@ function executeMessage(ctx, message) {
87
107
  }
88
108
  case "GET_PRIVATE_KEY": {
89
109
  const { share, walletId, userId } = params;
90
- return yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
110
+ const privateKey = yield walletUtils.getPrivateKey(ctx, share, walletId, userId);
111
+ return { privateKey };
91
112
  }
92
113
  case "ED25519_KEYGEN": {
93
114
  const { userId } = params;
@@ -171,6 +192,7 @@ function handleMessage(e, postMessage, useFetchAdapter) {
171
192
  };
172
193
  if (!wasmLoaded && (!ctx.offloadMPCComputationURL || ctx.useDKLS)) {
173
194
  yield loadWasm(ctx, wasmOverride);
195
+ const serverUrl = getBaseMPCNetworkUrl(ctx.env, !ctx.disableWebSockets);
174
196
  if (globalThis.initWasm) {
175
197
  yield new Promise(
176
198
  (resolve, reject) => {
@@ -180,7 +202,7 @@ function handleMessage(e, postMessage, useFetchAdapter) {
180
202
  reject(err);
181
203
  }
182
204
  resolve(result2);
183
- });
205
+ }, serverUrl);
184
206
  }
185
207
  );
186
208
  }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-WLGKV3EF.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { getPortalBaseURL } from "@getpara/core-sdk";
6
6
  import { handleMessage } from "./worker.js";
7
7
  const CLEAR_WORKER_TIMEOUT_MS = 1e3 * 90;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@getpara/web-sdk",
3
- "version": "2.0.0-fc.2",
3
+ "version": "2.0.0",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "2.0.0-fc.2",
6
- "@getpara/user-management-client": "2.0.0-fc.2",
7
- "@sentry/browser": "^9.1.0",
5
+ "@getpara/core-sdk": "2.0.0",
6
+ "@getpara/user-management-client": "2.0.0",
8
7
  "base64url": "^3.0.1",
9
8
  "buffer": "6.0.3",
10
9
  "cbor-web": "^9.0.2",
@@ -29,7 +28,7 @@
29
28
  "dist",
30
29
  "package.json"
31
30
  ],
32
- "gitHead": "65106fd9662a2c32b2071a0dea67ef55b3e4e98f",
31
+ "gitHead": "a64b6aa9b3c481a2d955022f621e495fb55e549e",
33
32
  "main": "dist/index.js",
34
33
  "scripts": {
35
34
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs && yarn post-build",