@getpara/web-sdk 2.0.0-dev.1 → 2.0.0-dev.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.
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": [
4
+ "wasm_exec.js"
5
+ ]
6
+ }
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import "../chunk-WLGKV3EF.js";
3
+ function getMailtoLink(email, recoveryShare) {
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
+ const mailText = `mailto:${email}?subject=Para%20Recovery%20Secret&body=${emailBody}`;
6
+ return mailText;
7
+ }
8
+ export {
9
+ getMailtoLink
10
+ };
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import "../chunk-WLGKV3EF.js";
3
+ function hexStringToBase64(hexString) {
4
+ if (hexString.substring(0, 2) === "0x") {
5
+ hexString = hexString.substring(2);
6
+ }
7
+ return Buffer.from(hexString, "hex").toString("base64");
8
+ }
9
+ function hexToSignature(hexSig) {
10
+ return {
11
+ r: `0x${hexSig.slice(2, 66)}`,
12
+ s: `0x${hexSig.slice(66, 130)}`,
13
+ v: BigInt(hexSig.slice(130, 132))
14
+ };
15
+ }
16
+ function hexToUint8Array(hex) {
17
+ if (hex.startsWith("0x")) {
18
+ hex = hex.slice(2);
19
+ }
20
+ return new Uint8Array(Buffer.from(hex, "hex"));
21
+ }
22
+ function hexToDecimal(hex) {
23
+ if (hex.startsWith("0x")) {
24
+ hex = hex.slice(2);
25
+ }
26
+ return `${parseInt(hex, 16)}`;
27
+ }
28
+ function decimalToHex(decimal) {
29
+ return `0x${parseInt(decimal).toString(16)}`;
30
+ }
31
+ export {
32
+ decimalToHex,
33
+ hexStringToBase64,
34
+ hexToDecimal,
35
+ hexToSignature,
36
+ hexToUint8Array
37
+ };
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ import "../chunk-WLGKV3EF.js";
3
+ function isAndroid() {
4
+ return typeof navigator !== "undefined" && /android/i.test(navigator.userAgent);
5
+ }
6
+ function isSmallIOS() {
7
+ return typeof navigator !== "undefined" && /iPhone|iPod/.test(navigator.userAgent);
8
+ }
9
+ function isLargeIOS() {
10
+ return typeof navigator !== "undefined" && (/iPad/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
11
+ }
12
+ 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
+ );
16
+ }
17
+ function isIOS() {
18
+ return isSmallIOS() || isLargeIOS();
19
+ }
20
+ function isMobile() {
21
+ return isAndroid() || isIOS();
22
+ }
23
+ function isSafari() {
24
+ return typeof navigator !== "undefined" && /AppleWebKit/i.test(navigator.userAgent) && !/CriOS/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent);
25
+ }
26
+ function isIOSWebview() {
27
+ const isStandalone = typeof navigator !== "undefined" && !navigator.standalone;
28
+ return typeof navigator !== "undefined" && isIOS() && !isStandalone && !/safari/i.test(navigator.userAgent.toLowerCase());
29
+ }
30
+ function isMobileSafari() {
31
+ return isMobile() && isSafari();
32
+ }
33
+ function isTelegram() {
34
+ return typeof window !== "undefined" && (Boolean(window.TelegramWebviewProxy) || Boolean(window.Telegram) || Boolean(window.TelegramWebviewProxyProto));
35
+ }
36
+ export {
37
+ isAndroid,
38
+ isIOS,
39
+ isIOSWebview,
40
+ isLargeIOS,
41
+ isMobile,
42
+ isMobileSafari,
43
+ isSafari,
44
+ isSmallIOS,
45
+ isTablet,
46
+ isTelegram
47
+ };
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-WLGKV3EF.js";
5
+ import { UAParser } from "ua-parser-js";
6
+ const isPasskeySupported = (userAgent) => __async(void 0, null, function* () {
7
+ var _a, _b, _c;
8
+ const directPasskeyCheck = yield (_b = (_a = window == null ? void 0 : window.PublicKeyCredential) == null ? void 0 : _a.isUserVerifyingPlatformAuthenticatorAvailable) == null ? void 0 : _b.call(_a);
9
+ if (directPasskeyCheck === true || directPasskeyCheck === false) {
10
+ return directPasskeyCheck;
11
+ }
12
+ const osName = (_c = new UAParser(userAgent).getOS().name) == null ? void 0 : _c.toLowerCase();
13
+ return !!osName && !["linux", "chrome os"].includes(osName);
14
+ });
15
+ export {
16
+ isPasskeySupported
17
+ };
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import "../chunk-WLGKV3EF.js";
3
+ const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/;
4
+ const truncateEthAddress = (address) => {
5
+ const match = address.match(truncateRegex);
6
+ if (!match) return address;
7
+ return `${match[1]}\u2026${match[2]}`;
8
+ };
9
+ export {
10
+ truncateEthAddress
11
+ };
@@ -1,11 +1,11 @@
1
1
  import { Ctx, TPregenIdentifierType } from '@getpara/core-sdk';
2
- import { BackupKitEmailProps, WalletType } from '@getpara/user-management-client';
3
- export declare function keygen(ctx: Ctx, userId: string, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null, skipDistribute?: boolean, sessionCookie?: string, emailProps?: BackupKitEmailProps): Promise<{
2
+ import { BackupKitEmailProps, TWalletType } from '@getpara/user-management-client';
3
+ export declare function keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, skipDistribute?: boolean, sessionCookie?: string, emailProps?: BackupKitEmailProps): Promise<{
4
4
  signer: string;
5
5
  walletId: string;
6
6
  recoveryShare: string | null;
7
7
  }>;
8
- export declare function preKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<WalletType, WalletType.SOLANA>, secretKey: string | null, _skipDistribute: boolean, partnerId: string, sessionCookie?: string): Promise<{
8
+ export declare function preKeygen(ctx: Ctx, pregenIdentifier: string, pregenIdentifierType: TPregenIdentifierType, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null, _skipDistribute: boolean, partnerId: string, sessionCookie?: string): Promise<{
9
9
  signer: string;
10
10
  walletId: string;
11
11
  recoveryShare: string | null;
@@ -0,0 +1,250 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-WLGKV3EF.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
7
+ import * as uuid from "uuid";
8
+ function isKeygenComplete(ctx, userId, walletId) {
9
+ return __async(this, null, function* () {
10
+ const wallets = yield ctx.client.getWallets(userId);
11
+ const wallet = wallets.data.wallets.find((w) => w.id === walletId);
12
+ return !!wallet.address;
13
+ });
14
+ }
15
+ function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
16
+ return __async(this, null, function* () {
17
+ const { isDone } = yield ctx.client.isRefreshDone(userId, walletId, partnerId, protocolId);
18
+ return isDone;
19
+ });
20
+ }
21
+ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
22
+ return __async(this, null, function* () {
23
+ const wallets = yield ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
24
+ const wallet = wallets.wallets.find((w) => w.id === walletId);
25
+ return !!wallet.address;
26
+ });
27
+ }
28
+ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
29
+ return new Promise((resolve, reject) => __async(this, null, function* () {
30
+ const workId = uuid.v4();
31
+ let worker = null;
32
+ worker = yield setupWorker(
33
+ ctx,
34
+ (res) => __async(this, null, function* () {
35
+ yield waitUntilTrue(() => __async(this, null, function* () {
36
+ return isKeygenComplete(ctx, userId, res.walletId);
37
+ }), 15e3, 1e3);
38
+ if (skipDistribute) {
39
+ resolve({
40
+ signer: res.signer,
41
+ walletId: res.walletId,
42
+ recoveryShare: null
43
+ });
44
+ return;
45
+ }
46
+ const recoveryShare = yield distributeNewShare({
47
+ ctx,
48
+ userId,
49
+ walletId: res.walletId,
50
+ userShare: res.signer,
51
+ emailProps
52
+ });
53
+ resolve({
54
+ signer: res.signer,
55
+ walletId: res.walletId,
56
+ recoveryShare
57
+ });
58
+ }),
59
+ (error) => {
60
+ reject(error);
61
+ },
62
+ workId
63
+ );
64
+ worker.postMessage({
65
+ env: ctx.env,
66
+ apiKey: ctx.apiKey,
67
+ cosmosPrefix: ctx.cosmosPrefix,
68
+ params: { userId, secretKey, type },
69
+ functionType: "KEYGEN",
70
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
71
+ disableWorkers: ctx.disableWorkers,
72
+ sessionCookie,
73
+ useDKLS: ctx.useDKLS,
74
+ disableWebSockets: ctx.disableWebSockets,
75
+ wasmOverride: ctx.wasmOverride,
76
+ workId
77
+ });
78
+ }));
79
+ }
80
+ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
81
+ return new Promise((resolve, reject) => __async(this, null, function* () {
82
+ const workId = uuid.v4();
83
+ let worker = null;
84
+ worker = yield setupWorker(
85
+ ctx,
86
+ (res) => __async(this, null, function* () {
87
+ yield waitUntilTrue(
88
+ () => __async(this, null, function* () {
89
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
90
+ }),
91
+ 15e3,
92
+ 1e3
93
+ );
94
+ resolve({
95
+ signer: res.signer,
96
+ walletId: res.walletId,
97
+ recoveryShare: null
98
+ });
99
+ }),
100
+ (error) => {
101
+ reject(error);
102
+ },
103
+ workId
104
+ );
105
+ const email = void 0;
106
+ const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
107
+ if (pregenIdentifierType === "EMAIL") {
108
+ params.email = pregenIdentifier;
109
+ }
110
+ worker.postMessage({
111
+ env: ctx.env,
112
+ apiKey: ctx.apiKey,
113
+ cosmosPrefix: ctx.cosmosPrefix,
114
+ params,
115
+ functionType: "PREKEYGEN",
116
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
117
+ disableWorkers: ctx.disableWorkers,
118
+ sessionCookie,
119
+ useDKLS: ctx.useDKLS,
120
+ disableWebSockets: ctx.disableWebSockets,
121
+ wasmOverride: ctx.wasmOverride,
122
+ workId
123
+ });
124
+ }));
125
+ }
126
+ function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
127
+ return new Promise((resolve, reject) => __async(this, null, function* () {
128
+ const workId = uuid.v4();
129
+ let worker = null;
130
+ worker = yield setupWorker(
131
+ ctx,
132
+ (res) => __async(this, null, function* () {
133
+ if (!(yield waitUntilTrue(() => __async(this, null, function* () {
134
+ return isRefreshComplete(ctx, userId, walletId, newPartnerId);
135
+ }), 15e3, 1e3))) {
136
+ reject(new Error("refresh failed"));
137
+ return;
138
+ }
139
+ const { protocolId, signer } = res;
140
+ resolve({
141
+ signer,
142
+ protocolId
143
+ });
144
+ }),
145
+ (error) => {
146
+ reject(error);
147
+ },
148
+ workId
149
+ );
150
+ worker.postMessage({
151
+ env: ctx.env,
152
+ apiKey: ctx.apiKey,
153
+ params: { userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId },
154
+ functionType: "REFRESH",
155
+ disableWorkers: ctx.disableWorkers,
156
+ sessionCookie,
157
+ useDKLS: ctx.useDKLS,
158
+ disableWebSockets: ctx.disableWebSockets,
159
+ wasmOverride: ctx.wasmOverride,
160
+ returnObject: true,
161
+ workId
162
+ });
163
+ }));
164
+ }
165
+ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
166
+ return new Promise((resolve, reject) => __async(this, null, function* () {
167
+ const workId = uuid.v4();
168
+ let worker = null;
169
+ worker = yield setupWorker(
170
+ ctx,
171
+ (res) => __async(this, null, function* () {
172
+ yield waitUntilTrue(() => __async(this, null, function* () {
173
+ return isKeygenComplete(ctx, userId, res.walletId);
174
+ }), 15e3, 1e3);
175
+ resolve({
176
+ signer: res.signer,
177
+ walletId: res.walletId,
178
+ recoveryShare: null
179
+ });
180
+ }),
181
+ (error) => {
182
+ reject(error);
183
+ },
184
+ workId
185
+ );
186
+ worker.postMessage({
187
+ env: ctx.env,
188
+ apiKey: ctx.apiKey,
189
+ cosmosPrefix: ctx.cosmosPrefix,
190
+ params: { userId },
191
+ functionType: "ED25519_KEYGEN",
192
+ disableWorkers: ctx.disableWorkers,
193
+ sessionCookie,
194
+ disableWebSockets: ctx.disableWebSockets,
195
+ wasmOverride: ctx.wasmOverride,
196
+ workId
197
+ });
198
+ }));
199
+ }
200
+ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
201
+ return new Promise((resolve, reject) => __async(this, null, function* () {
202
+ const workId = uuid.v4();
203
+ let worker = null;
204
+ worker = yield setupWorker(
205
+ ctx,
206
+ (res) => __async(this, null, function* () {
207
+ yield waitUntilTrue(
208
+ () => __async(this, null, function* () {
209
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
210
+ }),
211
+ 15e3,
212
+ 1e3
213
+ );
214
+ resolve({
215
+ signer: res.signer,
216
+ walletId: res.walletId,
217
+ recoveryShare: null
218
+ });
219
+ }),
220
+ (error) => {
221
+ reject(error);
222
+ },
223
+ workId
224
+ );
225
+ const email = void 0;
226
+ const params = { pregenIdentifier, pregenIdentifierType, email };
227
+ if (pregenIdentifierType === "EMAIL") {
228
+ params.email = pregenIdentifier;
229
+ }
230
+ worker.postMessage({
231
+ env: ctx.env,
232
+ apiKey: ctx.apiKey,
233
+ cosmosPrefix: ctx.cosmosPrefix,
234
+ params,
235
+ functionType: "ED25519_PREKEYGEN",
236
+ disableWorkers: ctx.disableWorkers,
237
+ sessionCookie,
238
+ disableWebSockets: ctx.disableWebSockets,
239
+ wasmOverride: ctx.wasmOverride,
240
+ workId
241
+ });
242
+ }));
243
+ }
244
+ export {
245
+ ed25519Keygen,
246
+ ed25519PreKeygen,
247
+ keygen,
248
+ preKeygen,
249
+ refresh
250
+ };
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-WLGKV3EF.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ import * as uuid from "uuid";
7
+ function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
8
+ return __async(this, null, function* () {
9
+ return new Promise((resolve, reject) => __async(this, null, function* () {
10
+ const workId = uuid.v4();
11
+ let worker = null;
12
+ worker = yield setupWorker(
13
+ ctx,
14
+ (res) => __async(this, null, function* () {
15
+ resolve((res == null ? void 0 : res.privateKey) || res);
16
+ }),
17
+ (error) => {
18
+ reject(error);
19
+ },
20
+ workId
21
+ );
22
+ worker.postMessage({
23
+ env: ctx.env,
24
+ apiKey: ctx.apiKey,
25
+ cosmosPrefix: ctx.cosmosPrefix,
26
+ params: { share, walletId, userId },
27
+ functionType: "GET_PRIVATE_KEY",
28
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
29
+ disableWorkers: ctx.disableWorkers,
30
+ sessionCookie,
31
+ useDKLS: ctx.useDKLS,
32
+ disableWebSockets: ctx.disableWebSockets,
33
+ wasmOverride: ctx.wasmOverride,
34
+ workId
35
+ });
36
+ }));
37
+ });
38
+ }
39
+ export {
40
+ getPrivateKey
41
+ };
@@ -0,0 +1,140 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-WLGKV3EF.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ import * as uuid from "uuid";
7
+ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
8
+ return __async(this, null, function* () {
9
+ return new Promise((resolve, reject) => __async(this, null, function* () {
10
+ const workId = uuid.v4();
11
+ let worker = null;
12
+ worker = yield setupWorker(
13
+ ctx,
14
+ (sendTransactionRes) => __async(this, null, function* () {
15
+ resolve(sendTransactionRes);
16
+ }),
17
+ (error) => {
18
+ reject(error);
19
+ },
20
+ workId
21
+ );
22
+ worker.postMessage({
23
+ env: ctx.env,
24
+ apiKey: ctx.apiKey,
25
+ cosmosPrefix: ctx.cosmosPrefix,
26
+ params: { share, walletId, userId, tx, chainId },
27
+ functionType: "SIGN_TRANSACTION",
28
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
29
+ disableWorkers: ctx.disableWorkers,
30
+ sessionCookie,
31
+ useDKLS: isDKLS,
32
+ disableWebSockets: ctx.disableWebSockets,
33
+ wasmOverride: ctx.wasmOverride,
34
+ workId
35
+ });
36
+ }));
37
+ });
38
+ }
39
+ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
40
+ return __async(this, null, function* () {
41
+ return new Promise((resolve, reject) => __async(this, null, function* () {
42
+ const workId = uuid.v4();
43
+ let worker = null;
44
+ worker = yield setupWorker(
45
+ ctx,
46
+ (sendTransactionRes) => __async(this, null, function* () {
47
+ resolve(sendTransactionRes);
48
+ }),
49
+ (error) => {
50
+ reject(error);
51
+ },
52
+ workId
53
+ );
54
+ worker.postMessage({
55
+ env: ctx.env,
56
+ apiKey: ctx.apiKey,
57
+ cosmosPrefix: ctx.cosmosPrefix,
58
+ params: { share, walletId, userId, tx, chainId },
59
+ functionType: "SEND_TRANSACTION",
60
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
61
+ disableWorkers: ctx.disableWorkers,
62
+ sessionCookie,
63
+ useDKLS: isDKLS,
64
+ disableWebSockets: ctx.disableWebSockets,
65
+ wasmOverride: ctx.wasmOverride,
66
+ workId
67
+ });
68
+ }));
69
+ });
70
+ }
71
+ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
72
+ return __async(this, null, function* () {
73
+ return new Promise((resolve, reject) => __async(this, null, function* () {
74
+ const workId = uuid.v4();
75
+ let worker = null;
76
+ worker = yield setupWorker(
77
+ ctx,
78
+ (signMessageRes) => __async(this, null, function* () {
79
+ resolve(signMessageRes);
80
+ }),
81
+ (error) => {
82
+ console.error(`Worker error in signMessage for userId ${userId}, walletId ${walletId}:`, error);
83
+ reject(error);
84
+ },
85
+ workId
86
+ );
87
+ worker.postMessage({
88
+ env: ctx.env,
89
+ apiKey: ctx.apiKey,
90
+ cosmosPrefix: ctx.cosmosPrefix,
91
+ params: { share, walletId, userId, message, cosmosSignDoc },
92
+ functionType: "SIGN_MESSAGE",
93
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
94
+ disableWorkers: ctx.disableWorkers,
95
+ sessionCookie,
96
+ useDKLS: isDKLS,
97
+ disableWebSockets: ctx.disableWebSockets,
98
+ wasmOverride: ctx.wasmOverride,
99
+ workId
100
+ });
101
+ }));
102
+ });
103
+ }
104
+ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
105
+ return __async(this, null, function* () {
106
+ return new Promise((resolve, reject) => __async(this, null, function* () {
107
+ const workId = uuid.v4();
108
+ let worker = null;
109
+ worker = yield setupWorker(
110
+ ctx,
111
+ (signMessageRes) => __async(this, null, function* () {
112
+ resolve(signMessageRes);
113
+ }),
114
+ (error) => {
115
+ console.error(`Worker error in ed25519Sign for userId ${userId}, walletId ${walletId}:`, error);
116
+ reject(error);
117
+ },
118
+ workId
119
+ );
120
+ worker.postMessage({
121
+ env: ctx.env,
122
+ apiKey: ctx.apiKey,
123
+ cosmosPrefix: ctx.cosmosPrefix,
124
+ params: { share, walletId, userId, base64Bytes },
125
+ functionType: "ED25519_SIGN",
126
+ disableWorkers: ctx.disableWorkers,
127
+ sessionCookie,
128
+ disableWebSockets: ctx.disableWebSockets,
129
+ wasmOverride: ctx.wasmOverride,
130
+ workId
131
+ });
132
+ }));
133
+ });
134
+ }
135
+ export {
136
+ ed25519Sign,
137
+ sendTransaction,
138
+ signMessage,
139
+ signTransaction
140
+ };