@getpara/web-sdk 2.0.0-alpha.15 → 2.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wallet/keygen.js +122 -80
- package/dist/wallet/privateKey.js +13 -5
- package/dist/wallet/signing.js +54 -20
- package/dist/workers/workerWrapper.d.ts +1 -1
- package/dist/workers/workerWrapper.js +10 -2
- package/package.json +4 -4
package/dist/wallet/keygen.js
CHANGED
|
@@ -25,34 +25,42 @@ function isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, wallet
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCookie, emailProps = {}) {
|
|
28
|
-
return new Promise((resolve) => __async(this, null, function* () {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
29
|
+
let worker = null;
|
|
30
|
+
worker = yield setupWorker(
|
|
31
|
+
ctx,
|
|
32
|
+
(res) => __async(this, null, function* () {
|
|
33
|
+
yield waitUntilTrue(() => __async(this, null, function* () {
|
|
34
|
+
return isKeygenComplete(ctx, userId, res.walletId);
|
|
35
|
+
}), 15e3, 1e3);
|
|
36
|
+
if (skipDistribute) {
|
|
37
|
+
resolve({
|
|
38
|
+
signer: res.signer,
|
|
39
|
+
walletId: res.walletId,
|
|
40
|
+
recoveryShare: null
|
|
41
|
+
});
|
|
42
|
+
worker == null ? void 0 : worker.terminate();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const recoveryShare = yield distributeNewShare({
|
|
46
|
+
ctx,
|
|
47
|
+
userId,
|
|
48
|
+
walletId: res.walletId,
|
|
49
|
+
userShare: res.signer,
|
|
50
|
+
emailProps
|
|
51
|
+
});
|
|
34
52
|
resolve({
|
|
35
53
|
signer: res.signer,
|
|
36
54
|
walletId: res.walletId,
|
|
37
|
-
recoveryShare
|
|
55
|
+
recoveryShare
|
|
38
56
|
});
|
|
39
|
-
worker.terminate();
|
|
40
|
-
|
|
57
|
+
worker == null ? void 0 : worker.terminate();
|
|
58
|
+
}),
|
|
59
|
+
(error) => {
|
|
60
|
+
worker == null ? void 0 : worker.terminate();
|
|
61
|
+
reject(error);
|
|
41
62
|
}
|
|
42
|
-
|
|
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
|
-
}));
|
|
63
|
+
);
|
|
56
64
|
worker.postMessage({
|
|
57
65
|
env: ctx.env,
|
|
58
66
|
apiKey: ctx.apiKey,
|
|
@@ -69,22 +77,30 @@ function keygen(ctx, userId, type, secretKey, skipDistribute = false, sessionCoo
|
|
|
69
77
|
}));
|
|
70
78
|
}
|
|
71
79
|
function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey, _skipDistribute = false, partnerId, sessionCookie) {
|
|
72
|
-
return new Promise((resolve) => __async(this, null, function* () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
81
|
+
let worker = null;
|
|
82
|
+
worker = yield setupWorker(
|
|
83
|
+
ctx,
|
|
84
|
+
(res) => __async(this, null, function* () {
|
|
85
|
+
yield waitUntilTrue(
|
|
86
|
+
() => __async(this, null, function* () {
|
|
87
|
+
return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
|
|
88
|
+
}),
|
|
89
|
+
15e3,
|
|
90
|
+
1e3
|
|
91
|
+
);
|
|
92
|
+
resolve({
|
|
93
|
+
signer: res.signer,
|
|
94
|
+
walletId: res.walletId,
|
|
95
|
+
recoveryShare: null
|
|
96
|
+
});
|
|
97
|
+
worker == null ? void 0 : worker.terminate();
|
|
98
|
+
}),
|
|
99
|
+
(error) => {
|
|
100
|
+
worker == null ? void 0 : worker.terminate();
|
|
101
|
+
reject(error);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
88
104
|
const email = void 0;
|
|
89
105
|
const params = { pregenIdentifier, pregenIdentifierType, type, secretKey, partnerId, email };
|
|
90
106
|
if (pregenIdentifierType === "EMAIL") {
|
|
@@ -106,20 +122,30 @@ function preKeygen(ctx, pregenIdentifier, pregenIdentifierType, type, secretKey,
|
|
|
106
122
|
}));
|
|
107
123
|
}
|
|
108
124
|
function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newPartnerId, keyShareProtocolId) {
|
|
109
|
-
return new Promise((resolve) => __async(this, null, function* () {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
126
|
+
let worker = null;
|
|
127
|
+
worker = yield setupWorker(
|
|
128
|
+
ctx,
|
|
129
|
+
(res) => __async(this, null, function* () {
|
|
130
|
+
if (!(yield waitUntilTrue(() => __async(this, null, function* () {
|
|
131
|
+
return isRefreshComplete(ctx, userId, walletId, newPartnerId);
|
|
132
|
+
}), 15e3, 1e3))) {
|
|
133
|
+
worker == null ? void 0 : worker.terminate();
|
|
134
|
+
reject(new Error("refresh failed"));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const { protocolId, signer } = res;
|
|
138
|
+
resolve({
|
|
139
|
+
signer,
|
|
140
|
+
protocolId
|
|
141
|
+
});
|
|
142
|
+
worker == null ? void 0 : worker.terminate();
|
|
143
|
+
}),
|
|
144
|
+
(error) => {
|
|
145
|
+
worker == null ? void 0 : worker.terminate();
|
|
146
|
+
reject(error);
|
|
115
147
|
}
|
|
116
|
-
|
|
117
|
-
resolve({
|
|
118
|
-
signer,
|
|
119
|
-
protocolId
|
|
120
|
-
});
|
|
121
|
-
worker.terminate();
|
|
122
|
-
}));
|
|
148
|
+
);
|
|
123
149
|
worker.postMessage({
|
|
124
150
|
env: ctx.env,
|
|
125
151
|
apiKey: ctx.apiKey,
|
|
@@ -135,18 +161,26 @@ function refresh(ctx, sessionCookie, userId, walletId, share, oldPartnerId, newP
|
|
|
135
161
|
}));
|
|
136
162
|
}
|
|
137
163
|
function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
138
|
-
return new Promise((resolve) => __async(this, null, function* () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
164
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
165
|
+
let worker = null;
|
|
166
|
+
worker = yield setupWorker(
|
|
167
|
+
ctx,
|
|
168
|
+
(res) => __async(this, null, function* () {
|
|
169
|
+
yield waitUntilTrue(() => __async(this, null, function* () {
|
|
170
|
+
return isKeygenComplete(ctx, userId, res.walletId);
|
|
171
|
+
}), 15e3, 1e3);
|
|
172
|
+
resolve({
|
|
173
|
+
signer: res.signer,
|
|
174
|
+
walletId: res.walletId,
|
|
175
|
+
recoveryShare: null
|
|
176
|
+
});
|
|
177
|
+
worker == null ? void 0 : worker.terminate();
|
|
178
|
+
}),
|
|
179
|
+
(error) => {
|
|
180
|
+
worker == null ? void 0 : worker.terminate();
|
|
181
|
+
reject(error);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
150
184
|
worker.postMessage({
|
|
151
185
|
env: ctx.env,
|
|
152
186
|
apiKey: ctx.apiKey,
|
|
@@ -161,22 +195,30 @@ function ed25519Keygen(ctx, userId, sessionCookie, _emailProps = {}) {
|
|
|
161
195
|
}));
|
|
162
196
|
}
|
|
163
197
|
function ed25519PreKeygen(ctx, pregenIdentifier, pregenIdentifierType, sessionCookie) {
|
|
164
|
-
return new Promise((resolve) => __async(this, null, function* () {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
199
|
+
let worker = null;
|
|
200
|
+
worker = yield setupWorker(
|
|
201
|
+
ctx,
|
|
202
|
+
(res) => __async(this, null, function* () {
|
|
203
|
+
yield waitUntilTrue(
|
|
204
|
+
() => __async(this, null, function* () {
|
|
205
|
+
return isPreKeygenComplete(ctx, pregenIdentifier, pregenIdentifierType, res.walletId);
|
|
206
|
+
}),
|
|
207
|
+
15e3,
|
|
208
|
+
1e3
|
|
209
|
+
);
|
|
210
|
+
resolve({
|
|
211
|
+
signer: res.signer,
|
|
212
|
+
walletId: res.walletId,
|
|
213
|
+
recoveryShare: null
|
|
214
|
+
});
|
|
215
|
+
worker == null ? void 0 : worker.terminate();
|
|
216
|
+
}),
|
|
217
|
+
(error) => {
|
|
218
|
+
worker == null ? void 0 : worker.terminate();
|
|
219
|
+
reject(error);
|
|
220
|
+
}
|
|
221
|
+
);
|
|
180
222
|
const email = void 0;
|
|
181
223
|
const params = { pregenIdentifier, pregenIdentifierType, email };
|
|
182
224
|
if (pregenIdentifierType === "EMAIL") {
|
|
@@ -5,11 +5,19 @@ import {
|
|
|
5
5
|
import { setupWorker } from "../workers/workerWrapper.js";
|
|
6
6
|
function getPrivateKey(ctx, userId, walletId, share, sessionCookie) {
|
|
7
7
|
return __async(this, null, function* () {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
9
|
+
let worker = null;
|
|
10
|
+
worker = yield setupWorker(
|
|
11
|
+
ctx,
|
|
12
|
+
(res) => __async(this, null, function* () {
|
|
13
|
+
resolve(res);
|
|
14
|
+
worker == null ? void 0 : worker.terminate();
|
|
15
|
+
}),
|
|
16
|
+
(error) => {
|
|
17
|
+
worker == null ? void 0 : worker.terminate();
|
|
18
|
+
reject(error);
|
|
19
|
+
}
|
|
20
|
+
);
|
|
13
21
|
worker.postMessage({
|
|
14
22
|
env: ctx.env,
|
|
15
23
|
apiKey: ctx.apiKey,
|
package/dist/wallet/signing.js
CHANGED
|
@@ -5,11 +5,19 @@ import {
|
|
|
5
5
|
import { setupWorker } from "../workers/workerWrapper.js";
|
|
6
6
|
function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
7
7
|
return __async(this, null, function* () {
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
9
|
+
let worker = null;
|
|
10
|
+
worker = yield setupWorker(
|
|
11
|
+
ctx,
|
|
12
|
+
(sendTransactionRes) => __async(this, null, function* () {
|
|
13
|
+
resolve(sendTransactionRes);
|
|
14
|
+
worker == null ? void 0 : worker.terminate();
|
|
15
|
+
}),
|
|
16
|
+
(error) => {
|
|
17
|
+
worker == null ? void 0 : worker.terminate();
|
|
18
|
+
reject(error);
|
|
19
|
+
}
|
|
20
|
+
);
|
|
13
21
|
worker.postMessage({
|
|
14
22
|
env: ctx.env,
|
|
15
23
|
apiKey: ctx.apiKey,
|
|
@@ -28,11 +36,19 @@ function signTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
|
|
|
28
36
|
}
|
|
29
37
|
function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCookie, isDKLS) {
|
|
30
38
|
return __async(this, null, function* () {
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
40
|
+
let worker = null;
|
|
41
|
+
worker = yield setupWorker(
|
|
42
|
+
ctx,
|
|
43
|
+
(sendTransactionRes) => __async(this, null, function* () {
|
|
44
|
+
resolve(sendTransactionRes);
|
|
45
|
+
worker == null ? void 0 : worker.terminate();
|
|
46
|
+
}),
|
|
47
|
+
(error) => {
|
|
48
|
+
worker == null ? void 0 : worker.terminate();
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
36
52
|
worker.postMessage({
|
|
37
53
|
env: ctx.env,
|
|
38
54
|
apiKey: ctx.apiKey,
|
|
@@ -51,11 +67,20 @@ function sendTransaction(ctx, userId, walletId, share, tx, chainId, sessionCooki
|
|
|
51
67
|
}
|
|
52
68
|
function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKLS, cosmosSignDoc) {
|
|
53
69
|
return __async(this, null, function* () {
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
71
|
+
let worker = null;
|
|
72
|
+
worker = yield setupWorker(
|
|
73
|
+
ctx,
|
|
74
|
+
(signMessageRes) => __async(this, null, function* () {
|
|
75
|
+
resolve(signMessageRes);
|
|
76
|
+
worker == null ? void 0 : worker.terminate();
|
|
77
|
+
}),
|
|
78
|
+
(error) => {
|
|
79
|
+
console.error(`Worker error in signMessage for userId ${userId}, walletId ${walletId}:`, error);
|
|
80
|
+
worker == null ? void 0 : worker.terminate();
|
|
81
|
+
reject(error);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
59
84
|
worker.postMessage({
|
|
60
85
|
env: ctx.env,
|
|
61
86
|
apiKey: ctx.apiKey,
|
|
@@ -74,11 +99,20 @@ function signMessage(ctx, userId, walletId, share, message, sessionCookie, isDKL
|
|
|
74
99
|
}
|
|
75
100
|
function ed25519Sign(ctx, userId, walletId, share, base64Bytes, sessionCookie) {
|
|
76
101
|
return __async(this, null, function* () {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
103
|
+
let worker = null;
|
|
104
|
+
worker = yield setupWorker(
|
|
105
|
+
ctx,
|
|
106
|
+
(signMessageRes) => __async(this, null, function* () {
|
|
107
|
+
resolve(signMessageRes);
|
|
108
|
+
worker == null ? void 0 : worker.terminate();
|
|
109
|
+
}),
|
|
110
|
+
(error) => {
|
|
111
|
+
console.error(`Worker error in ed25519Sign for userId ${userId}, walletId ${walletId}:`, error);
|
|
112
|
+
worker == null ? void 0 : worker.terminate();
|
|
113
|
+
reject(error);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
82
116
|
worker.postMessage({
|
|
83
117
|
env: ctx.env,
|
|
84
118
|
apiKey: ctx.apiKey,
|
|
@@ -3,4 +3,4 @@ export interface SyncWorker {
|
|
|
3
3
|
postMessage: (message: any) => void;
|
|
4
4
|
terminate: () => void;
|
|
5
5
|
}
|
|
6
|
-
export declare function setupWorker(ctx: Ctx, resFunction: (arg: any) => void): Promise<Worker | SyncWorker>;
|
|
6
|
+
export declare function setupWorker(ctx: Ctx, resFunction: (arg: any) => void, errorFunction: (err: Error) => void): Promise<Worker | SyncWorker>;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "../chunk-WLGKV3EF.js";
|
|
5
5
|
import { getPortalBaseURL } from "@getpara/core-sdk";
|
|
6
6
|
import { handleMessage } from "./worker.js";
|
|
7
|
-
function setupWorker(ctx, resFunction) {
|
|
7
|
+
function setupWorker(ctx, resFunction, errorFunction) {
|
|
8
8
|
return __async(this, null, function* () {
|
|
9
9
|
const onmessage = (event) => {
|
|
10
10
|
if (event.data.functionType === "CUSTOM") {
|
|
@@ -12,12 +12,19 @@ function setupWorker(ctx, resFunction) {
|
|
|
12
12
|
}
|
|
13
13
|
resFunction(event.data);
|
|
14
14
|
};
|
|
15
|
+
const onerror = (error) => {
|
|
16
|
+
errorFunction(error);
|
|
17
|
+
};
|
|
15
18
|
if (ctx.disableWorkers) {
|
|
16
19
|
const syncWorker = {
|
|
17
20
|
postMessage: function(message) {
|
|
18
21
|
(function() {
|
|
19
22
|
return __async(this, null, function* () {
|
|
20
|
-
|
|
23
|
+
try {
|
|
24
|
+
yield handleMessage({ data: message }, (data) => onmessage({ data }), ctx.disableWorkers);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
onerror(error);
|
|
27
|
+
}
|
|
21
28
|
});
|
|
22
29
|
})();
|
|
23
30
|
},
|
|
@@ -37,6 +44,7 @@ function setupWorker(ctx, resFunction) {
|
|
|
37
44
|
worker = new Worker(workerScriptURL);
|
|
38
45
|
}
|
|
39
46
|
worker.onmessage = onmessage;
|
|
47
|
+
worker.onerror = onerror;
|
|
40
48
|
return worker;
|
|
41
49
|
});
|
|
42
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/web-sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"wasm_exec.js"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@getpara/core-sdk": "2.0.0-alpha.
|
|
12
|
-
"@getpara/user-management-client": "2.0.0-alpha.
|
|
11
|
+
"@getpara/core-sdk": "2.0.0-alpha.17",
|
|
12
|
+
"@getpara/user-management-client": "2.0.0-alpha.17",
|
|
13
13
|
"@sentry/browser": "^9.1.0",
|
|
14
14
|
"base64url": "3.0.1",
|
|
15
15
|
"buffer": "6.0.3",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"dist",
|
|
37
37
|
"package.json"
|
|
38
38
|
],
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "5cb0f3dee5564995c465ead160ed817ba2ba37a7"
|
|
40
40
|
}
|