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

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,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-M66XENHI.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,9 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-M66XENHI.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
6
  import { distributeNewShare, waitUntilTrue } from "@getpara/core-sdk";
7
+ import * as uuid from "uuid";
7
8
  function isKeygenComplete(ctx, userId, walletId) {
8
9
  return __async(this, null, function* () {
9
10
  const wallets = yield ctx.client.getWallets(userId);
@@ -25,34 +26,44 @@ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, wallet
25
26
  });
26
27
  }
27
28
  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) {
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
+ isEnclaveUser: false,
53
+ walletScheme: "DKLS"
54
+ // since `isEnclaveUser` is false, we can use `DKLS` here as it won't be used
55
+ });
34
56
  resolve({
35
57
  signer: res.signer,
36
58
  walletId: res.walletId,
37
- recoveryShare: null
59
+ recoveryShare
38
60
  });
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
- }));
61
+ }),
62
+ (error) => {
63
+ reject(error);
64
+ },
65
+ workId
66
+ );
56
67
  worker.postMessage({
57
68
  env: ctx.env,
58
69
  apiKey: ctx.apiKey,
@@ -64,27 +75,36 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
64
75
  sessionCookie,
65
76
  useDKLS: ctx.useDKLS,
66
77
  disableWebSockets: ctx.disableWebSockets,
67
- wasmOverride: ctx.wasmOverride
78
+ wasmOverride: ctx.wasmOverride,
79
+ workId
68
80
  });
69
81
  }));
70
82
  }
71
83
  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
- }));
84
+ return new Promise((resolve, reject) => __async(this, null, function* () {
85
+ const workId = uuid.v4();
86
+ let worker = null;
87
+ worker = yield setupWorker(
88
+ ctx,
89
+ (res) => __async(this, null, function* () {
90
+ yield waitUntilTrue(
91
+ () => __async(this, null, function* () {
92
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
93
+ }),
94
+ 15e3,
95
+ 1e3
96
+ );
97
+ resolve({
98
+ signer: res.signer,
99
+ walletId: res.walletId,
100
+ recoveryShare: null
101
+ });
102
+ }),
103
+ (error) => {
104
+ reject(error);
105
+ },
106
+ workId
107
+ );
88
108
  const email = void 0;
89
109
  const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
90
110
  if (pregenIdentifierType === "EMAIL") {
@@ -101,25 +121,35 @@ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey,
101
121
  sessionCookie,
102
122
  useDKLS: ctx.useDKLS,
103
123
  disableWebSockets: ctx.disableWebSockets,
104
- wasmOverride: ctx.wasmOverride
124
+ wasmOverride: ctx.wasmOverride,
125
+ workId
105
126
  });
106
127
  }));
107
128
  }
108
129
  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
- }));
130
+ return new Promise((resolve, reject) => __async(this, null, function* () {
131
+ const workId = uuid.v4();
132
+ let worker = null;
133
+ worker = yield setupWorker(
134
+ ctx,
135
+ (res) => __async(this, null, function* () {
136
+ if (!(yield waitUntilTrue(() => __async(this, null, function* () {
137
+ return isRefreshComplete(ctx, userId, walletId, newPartnerId);
138
+ }), 15e3, 1e3))) {
139
+ reject(new Error("refresh failed"));
140
+ return;
141
+ }
142
+ const { protocolId, signer } = res;
143
+ resolve({
144
+ signer,
145
+ protocolId
146
+ });
147
+ }),
148
+ (error) => {
149
+ reject(error);
150
+ },
151
+ workId
152
+ );
123
153
  worker.postMessage({
124
154
  env: ctx.env,
125
155
  apiKey: ctx.apiKey,
@@ -130,23 +160,32 @@ function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newP
130
160
  useDKLS: ctx.useDKLS,
131
161
  disableWebSockets: ctx.disableWebSockets,
132
162
  wasmOverride: ctx.wasmOverride,
133
- returnObject: true
163
+ returnObject: true,
164
+ workId
134
165
  });
135
166
  }));
136
167
  }
137
168
  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
- }));
169
+ return new Promise((resolve, reject) => __async(this, null, function* () {
170
+ const workId = uuid.v4();
171
+ let worker = null;
172
+ worker = yield setupWorker(
173
+ ctx,
174
+ (res) => __async(this, null, function* () {
175
+ yield waitUntilTrue(() => __async(this, null, function* () {
176
+ return isKeygenComplete(ctx, userId, res.walletId);
177
+ }), 15e3, 1e3);
178
+ resolve({
179
+ signer: res.signer,
180
+ walletId: res.walletId,
181
+ recoveryShare: null
182
+ });
183
+ }),
184
+ (error) => {
185
+ reject(error);
186
+ },
187
+ workId
188
+ );
150
189
  worker.postMessage({
151
190
  env: ctx.env,
152
191
  apiKey: ctx.apiKey,
@@ -156,27 +195,36 @@ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
156
195
  disableWorkers: ctx.disableWorkers,
157
196
  sessionCookie,
158
197
  disableWebSockets: ctx.disableWebSockets,
159
- wasmOverride: ctx.wasmOverride
198
+ wasmOverride: ctx.wasmOverride,
199
+ workId
160
200
  });
161
201
  }));
162
202
  }
163
203
  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
- }));
204
+ return new Promise((resolve, reject) => __async(this, null, function* () {
205
+ const workId = uuid.v4();
206
+ let worker = null;
207
+ worker = yield setupWorker(
208
+ ctx,
209
+ (res) => __async(this, null, function* () {
210
+ yield waitUntilTrue(
211
+ () => __async(this, null, function* () {
212
+ return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
213
+ }),
214
+ 15e3,
215
+ 1e3
216
+ );
217
+ resolve({
218
+ signer: res.signer,
219
+ walletId: res.walletId,
220
+ recoveryShare: null
221
+ });
222
+ }),
223
+ (error) => {
224
+ reject(error);
225
+ },
226
+ workId
227
+ );
180
228
  const email = void 0;
181
229
  const params = { pregenIdentifier, pregenIdentifierType, email };
182
230
  if (pregenIdentifierType === "EMAIL") {
@@ -191,13 +239,38 @@ function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCo
191
239
  disableWorkers: ctx.disableWorkers,
192
240
  sessionCookie,
193
241
  disableWebSockets: ctx.disableWebSockets,
194
- wasmOverride: ctx.wasmOverride
242
+ wasmOverride: ctx.wasmOverride,
243
+ workId
195
244
  });
196
245
  }));
197
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
+ }
198
270
  export {
199
271
  ed25519Keygen,
200
272
  ed25519PreKeygen,
273
+ initializeWorker,
201
274
  keygen,
202
275
  preKeygen,
203
276
  refresh
@@ -1,15 +1,24 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-M66XENHI.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
+ import * as uuid from "uuid";
6
7
  function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
7
8
  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
- }));
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
+ );
13
22
  worker.postMessage({
14
23
  env: ctx.env,
15
24
  apiKey: ctx.apiKey,
@@ -21,7 +30,8 @@ function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
21
30
  sessionCookie,
22
31
  useDKLS: ctx.useDKLS,
23
32
  disableWebSockets: ctx.disableWebSockets,
24
- wasmOverride: ctx.wasmOverride
33
+ wasmOverride: ctx.wasmOverride,
34
+ workId
25
35
  });
26
36
  }));
27
37
  });
@@ -1,15 +1,24 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-M66XENHI.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  import { setupWorker } from "../workers/workerWrapper.js";
6
+ import * as uuid from "uuid";
6
7
  function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
7
8
  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
- }));
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
+ );
13
22
  worker.postMessage({
14
23
  env: ctx.env,
15
24
  apiKey: ctx.apiKey,
@@ -21,18 +30,27 @@ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
21
30
  sessionCookie,
22
31
  useDKLS: isDKLS,
23
32
  disableWebSockets: ctx.disableWebSockets,
24
- wasmOverride: ctx.wasmOverride
33
+ wasmOverride: ctx.wasmOverride,
34
+ workId
25
35
  });
26
36
  }));
27
37
  });
28
38
  }
29
39
  function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
30
40
  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
- }));
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
+ );
36
54
  worker.postMessage({
37
55
  env: ctx.env,
38
56
  apiKey: ctx.apiKey,
@@ -44,18 +62,28 @@ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
44
62
  sessionCookie,
45
63
  useDKLS: isDKLS,
46
64
  disableWebSockets: ctx.disableWebSockets,
47
- wasmOverride: ctx.wasmOverride
65
+ wasmOverride: ctx.wasmOverride,
66
+ workId
48
67
  });
49
68
  }));
50
69
  });
51
70
  }
52
71
  function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
53
72
  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
- }));
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
+ );
59
87
  worker.postMessage({
60
88
  env: ctx.env,
61
89
  apiKey: ctx.apiKey,
@@ -67,18 +95,28 @@ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKL
67
95
  sessionCookie,
68
96
  useDKLS: isDKLS,
69
97
  disableWebSockets: ctx.disableWebSockets,
70
- wasmOverride: ctx.wasmOverride
98
+ wasmOverride: ctx.wasmOverride,
99
+ workId
71
100
  });
72
101
  }));
73
102
  });
74
103
  }
75
104
  function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
76
105
  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
- }));
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
+ );
82
120
  worker.postMessage({
83
121
  env: ctx.env,
84
122
  apiKey: ctx.apiKey,
@@ -88,7 +126,8 @@ function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
88
126
  disableWorkers: ctx.disableWorkers,
89
127
  sessionCookie,
90
128
  disableWebSockets: ctx.disableWebSockets,
91
- wasmOverride: ctx.wasmOverride
129
+ wasmOverride: ctx.wasmOverride,
130
+ workId
92
131
  });
93
132
  }));
94
133
  });
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  __async
4
- } from "../chunk-M66XENHI.js";
4
+ } from "../chunk-YJOFEY2L.js";
5
5
  (() => {
6
6
  const enosys = () => {
7
7
  const err = new Error("not implemented");
@@ -7,9 +7,7 @@ export declare function ed25519PreKeygen(ctx: Ctx, pregenIdentifier: string, pre
7
7
  signer: string;
8
8
  walletId: string;
9
9
  }>;
10
- export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string): Promise<{
11
- signature: string;
12
- }>;
10
+ export declare function ed25519Sign(ctx: Ctx, share: string, userId: string, walletId: string, base64Bytes: string): Promise<SignatureRes>;
13
11
  export declare function keygen(ctx: Ctx, userId: string, type: Exclude<TWalletType, 'SOLANA'>, secretKey: string | null): Promise<{
14
12
  signer: string;
15
13
  walletId: string;