@getpara/web-sdk 2.0.0-alpha.3 → 2.0.0-alpha.6

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-M66XENHI.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-M66XENHI.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-M66XENHI.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-M66XENHI.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-M66XENHI.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,204 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-M66XENHI.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
7
+ function isKeygenComplete(ctx, userId, walletId) {
8
+ return __async(this, null, function* () {
9
+ const wallets = yield ctx.client.getWallets(userId);
10
+ const wallet = wallets.data.wallets.find((w) => w.id === walletId);
11
+ return !!wallet.address;
12
+ });
13
+ }
14
+ function isRefreshComplete(ctx, userId, walletId, partnerId, protocolId) {
15
+ return __async(this, null, function* () {
16
+ const { isDone } = yield ctx.client.isRefreshDone(userId, walletId, partnerId, protocolId);
17
+ return isDone;
18
+ });
19
+ }
20
+ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, walletId) {
21
+ return __async(this, null, function* () {
22
+ const wallets = yield ctx.client.getPregenWallets({ [pregenIdentifierType]: [pregenIdentifier] });
23
+ const wallet = wallets.wallets.find((w) => w.id === walletId);
24
+ return !!wallet.address;
25
+ });
26
+ }
27
+ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
28
+ return new Promise((resolve) => __async(this, null, function* () {
29
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
30
+ yield waitUntilTrue(() => __async(this, null, function* () {
31
+ return isKeygenComplete(ctx, userId, res.walletId);
32
+ }), 15e3, 1e3);
33
+ if (skipDistribute) {
34
+ resolve({
35
+ signer: res.signer,
36
+ walletId: res.walletId,
37
+ recoveryShare: null
38
+ });
39
+ worker.terminate();
40
+ return;
41
+ }
42
+ const recoveryShare = yield distributeNewShare({
43
+ ctx,
44
+ userId,
45
+ walletId: res.walletId,
46
+ userShare: res.signer,
47
+ emailProps
48
+ });
49
+ resolve({
50
+ signer: res.signer,
51
+ walletId: res.walletId,
52
+ recoveryShare
53
+ });
54
+ worker.terminate();
55
+ }));
56
+ worker.postMessage({
57
+ env: ctx.env,
58
+ apiKey: ctx.apiKey,
59
+ cosmosPrefix: ctx.cosmosPrefix,
60
+ params: { userId, secretKey, type },
61
+ functionType: "KEYGEN",
62
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
63
+ disableWorkers: ctx.disableWorkers,
64
+ sessionCookie,
65
+ useDKLS: ctx.useDKLS,
66
+ disableWebSockets: ctx.disableWebSockets,
67
+ wasmOverride: ctx.wasmOverride
68
+ });
69
+ }));
70
+ }
71
+ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
72
+ return new Promise((resolve) => __async(this, null, function* () {
73
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
74
+ yield waitUntilTrue(
75
+ () => __async(this, null, function* () {
76
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
77
+ }),
78
+ 15e3,
79
+ 1e3
80
+ );
81
+ resolve({
82
+ signer: res.signer,
83
+ walletId: res.walletId,
84
+ recoveryShare: null
85
+ });
86
+ worker.terminate();
87
+ }));
88
+ const email = void 0;
89
+ const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
90
+ if (pregenIdentifierType === "EMAIL") {
91
+ params.email = pregenIdentifier;
92
+ }
93
+ worker.postMessage({
94
+ env: ctx.env,
95
+ apiKey: ctx.apiKey,
96
+ cosmosPrefix: ctx.cosmosPrefix,
97
+ params,
98
+ functionType: "PREKEYGEN",
99
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
100
+ disableWorkers: ctx.disableWorkers,
101
+ sessionCookie,
102
+ useDKLS: ctx.useDKLS,
103
+ disableWebSockets: ctx.disableWebSockets,
104
+ wasmOverride: ctx.wasmOverride
105
+ });
106
+ }));
107
+ }
108
+ function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
109
+ return new Promise((resolve) => __async(this, null, function* () {
110
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
111
+ if (!(yield waitUntilTrue(() => __async(this, null, function* () {
112
+ return isRefreshComplete(ctx, userId, walletId, newPartnerId);
113
+ }), 15e3, 1e3))) {
114
+ throw new Error("refresh failed");
115
+ }
116
+ const { protocolId, signer } = res;
117
+ resolve({
118
+ signer,
119
+ protocolId
120
+ });
121
+ worker.terminate();
122
+ }));
123
+ worker.postMessage({
124
+ env: ctx.env,
125
+ apiKey: ctx.apiKey,
126
+ params: { userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId },
127
+ functionType: "REFRESH",
128
+ disableWorkers: ctx.disableWorkers,
129
+ sessionCookie,
130
+ useDKLS: ctx.useDKLS,
131
+ disableWebSockets: ctx.disableWebSockets,
132
+ wasmOverride: ctx.wasmOverride,
133
+ returnObject: true
134
+ });
135
+ }));
136
+ }
137
+ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
138
+ return new Promise((resolve) => __async(this, null, function* () {
139
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
140
+ yield waitUntilTrue(() => __async(this, null, function* () {
141
+ return isKeygenComplete(ctx, userId, res.walletId);
142
+ }), 15e3, 1e3);
143
+ resolve({
144
+ signer: res.signer,
145
+ walletId: res.walletId,
146
+ recoveryShare: null
147
+ });
148
+ worker.terminate();
149
+ }));
150
+ worker.postMessage({
151
+ env: ctx.env,
152
+ apiKey: ctx.apiKey,
153
+ cosmosPrefix: ctx.cosmosPrefix,
154
+ params: { userId },
155
+ functionType: "ED25519_KEYGEN",
156
+ disableWorkers: ctx.disableWorkers,
157
+ sessionCookie,
158
+ disableWebSockets: ctx.disableWebSockets,
159
+ wasmOverride: ctx.wasmOverride
160
+ });
161
+ }));
162
+ }
163
+ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
164
+ return new Promise((resolve) => __async(this, null, function* () {
165
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
166
+ yield waitUntilTrue(
167
+ () => __async(this, null, function* () {
168
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
169
+ }),
170
+ 15e3,
171
+ 1e3
172
+ );
173
+ resolve({
174
+ signer: res.signer,
175
+ walletId: res.walletId,
176
+ recoveryShare: null
177
+ });
178
+ worker.terminate();
179
+ }));
180
+ const email = void 0;
181
+ const params = { pregenIdentifier, pregenIdentifierType, email };
182
+ if (pregenIdentifierType === "EMAIL") {
183
+ params.email = pregenIdentifier;
184
+ }
185
+ worker.postMessage({
186
+ env: ctx.env,
187
+ apiKey: ctx.apiKey,
188
+ cosmosPrefix: ctx.cosmosPrefix,
189
+ params,
190
+ functionType: "ED25519_PREKEYGEN",
191
+ disableWorkers: ctx.disableWorkers,
192
+ sessionCookie,
193
+ disableWebSockets: ctx.disableWebSockets,
194
+ wasmOverride: ctx.wasmOverride
195
+ });
196
+ }));
197
+ }
198
+ export {
199
+ ed25519Keygen,
200
+ ed25519PreKeygen,
201
+ keygen,
202
+ preKeygen,
203
+ refresh
204
+ };
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-M66XENHI.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
7
+ return __async(this, null, function* () {
8
+ return yield new Promise((resolve) => __async(this, null, function* () {
9
+ const worker = yield setupWorker(ctx, (res) => __async(this, null, function* () {
10
+ resolve(res);
11
+ worker.terminate();
12
+ }));
13
+ worker.postMessage({
14
+ env: ctx.env,
15
+ apiKey: ctx.apiKey,
16
+ cosmosPrefix: ctx.cosmosPrefix,
17
+ params: { share, walletId, userId },
18
+ functionType: "GET_PRIVATE_KEY",
19
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
20
+ disableWorkers: ctx.disableWorkers,
21
+ sessionCookie,
22
+ useDKLS: ctx.useDKLS,
23
+ disableWebSockets: ctx.disableWebSockets,
24
+ wasmOverride: ctx.wasmOverride
25
+ });
26
+ }));
27
+ });
28
+ }
29
+ export {
30
+ getPrivateKey
31
+ };
@@ -0,0 +1,101 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../chunk-M66XENHI.js";
5
+ import { setupWorker } from "../workers/workerWrapper.js";
6
+ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
7
+ return __async(this, null, function* () {
8
+ return yield new Promise((resolve) => __async(this, null, function* () {
9
+ const worker = yield setupWorker(ctx, (sendTransactionRes) => __async(this, null, function* () {
10
+ resolve(sendTransactionRes);
11
+ worker.terminate();
12
+ }));
13
+ worker.postMessage({
14
+ env: ctx.env,
15
+ apiKey: ctx.apiKey,
16
+ cosmosPrefix: ctx.cosmosPrefix,
17
+ params: { share, walletId, userId, tx, chainId },
18
+ functionType: "SIGN_TRANSACTION",
19
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
20
+ disableWorkers: ctx.disableWorkers,
21
+ sessionCookie,
22
+ useDKLS: isDKLS,
23
+ disableWebSockets: ctx.disableWebSockets,
24
+ wasmOverride: ctx.wasmOverride
25
+ });
26
+ }));
27
+ });
28
+ }
29
+ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
30
+ return __async(this, null, function* () {
31
+ return yield new Promise((resolve) => __async(this, null, function* () {
32
+ const worker = yield setupWorker(ctx, (sendTransactionRes) => __async(this, null, function* () {
33
+ resolve(sendTransactionRes);
34
+ worker.terminate();
35
+ }));
36
+ worker.postMessage({
37
+ env: ctx.env,
38
+ apiKey: ctx.apiKey,
39
+ cosmosPrefix: ctx.cosmosPrefix,
40
+ params: { share, walletId, userId, tx, chainId },
41
+ functionType: "SEND_TRANSACTION",
42
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
43
+ disableWorkers: ctx.disableWorkers,
44
+ sessionCookie,
45
+ useDKLS: isDKLS,
46
+ disableWebSockets: ctx.disableWebSockets,
47
+ wasmOverride: ctx.wasmOverride
48
+ });
49
+ }));
50
+ });
51
+ }
52
+ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
53
+ return __async(this, null, function* () {
54
+ return yield new Promise((resolve) => __async(this, null, function* () {
55
+ const worker = yield setupWorker(ctx, (signMessageRes) => __async(this, null, function* () {
56
+ resolve(signMessageRes);
57
+ worker.terminate();
58
+ }));
59
+ worker.postMessage({
60
+ env: ctx.env,
61
+ apiKey: ctx.apiKey,
62
+ cosmosPrefix: ctx.cosmosPrefix,
63
+ params: { share, walletId, userId, message, cosmosSignDoc },
64
+ functionType: "SIGN_MESSAGE",
65
+ offloadMPCComputationURL: ctx.offloadMPCComputationURL,
66
+ disableWorkers: ctx.disableWorkers,
67
+ sessionCookie,
68
+ useDKLS: isDKLS,
69
+ disableWebSockets: ctx.disableWebSockets,
70
+ wasmOverride: ctx.wasmOverride
71
+ });
72
+ }));
73
+ });
74
+ }
75
+ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
76
+ return __async(this, null, function* () {
77
+ return yield new Promise((resolve) => __async(this, null, function* () {
78
+ const worker = yield setupWorker(ctx, (signMessageRes) => __async(this, null, function* () {
79
+ resolve(signMessageRes);
80
+ worker.terminate();
81
+ }));
82
+ worker.postMessage({
83
+ env: ctx.env,
84
+ apiKey: ctx.apiKey,
85
+ cosmosPrefix: ctx.cosmosPrefix,
86
+ params: { share, walletId, userId, base64Bytes },
87
+ functionType: "ED25519_SIGN",
88
+ disableWorkers: ctx.disableWorkers,
89
+ sessionCookie,
90
+ disableWebSockets: ctx.disableWebSockets,
91
+ wasmOverride: ctx.wasmOverride
92
+ });
93
+ }));
94
+ });
95
+ }
96
+ export {
97
+ ed25519Sign,
98
+ sendTransaction,
99
+ signMessage,
100
+ signTransaction
101
+ };