@portal-hq/web 3.11.0 → 3.12.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/lib/commonjs/index.js +12 -7
- package/lib/commonjs/index.test.js +1 -1
- package/lib/commonjs/mpc/index.js +58 -10
- package/lib/commonjs/mpc/index.test.js +202 -100
- package/lib/commonjs/namespaces/evmAccountType/index.test.js +25 -12
- package/lib/commonjs/provider/index.js +14 -17
- package/lib/commonjs/provider/index.test.js +25 -2
- package/lib/commonjs/shared/logger.js +59 -0
- package/lib/commonjs/shared/trace/index.js +55 -0
- package/lib/commonjs/shared/types/index.js +2 -1
- package/lib/esm/index.js +12 -7
- package/lib/esm/index.test.js +1 -1
- package/lib/esm/mpc/index.js +58 -10
- package/lib/esm/mpc/index.test.js +202 -100
- package/lib/esm/namespaces/evmAccountType/index.test.js +25 -12
- package/lib/esm/provider/index.js +14 -17
- package/lib/esm/provider/index.test.js +25 -2
- package/lib/esm/shared/logger.js +56 -0
- package/lib/esm/shared/trace/index.js +51 -0
- package/lib/esm/shared/types/index.js +2 -1
- package/package.json +1 -1
- package/src/index.test.ts +1 -0
- package/src/index.ts +14 -3
- package/src/logger/index.ts +1 -8
- package/src/mpc/index.test.ts +202 -100
- package/src/mpc/index.ts +73 -5
- package/src/namespaces/evmAccountType/index.test.ts +25 -12
- package/src/provider/index.test.ts +30 -2
- package/src/provider/index.ts +17 -3
- package/src/shared/logger.ts +69 -0
- package/src/shared/trace/index.ts +59 -0
- package/src/shared/types/api.ts +5 -0
- package/src/shared/types/common.ts +14 -0
- package/src/shared/types/index.ts +2 -1
- package/types.d.ts +1 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -46,6 +46,7 @@ const delegations_1 = __importDefault(require("./integrations/delegations"));
|
|
|
46
46
|
const passkeys_1 = __importDefault(require("./passkeys"));
|
|
47
47
|
const evmAccountType_1 = require("./namespaces/evmAccountType");
|
|
48
48
|
const logger_1 = require("./logger");
|
|
49
|
+
const trace_1 = require("./shared/trace");
|
|
49
50
|
class Portal {
|
|
50
51
|
get ready() {
|
|
51
52
|
return this.mpc.ready;
|
|
@@ -472,16 +473,18 @@ class Portal {
|
|
|
472
473
|
});
|
|
473
474
|
}
|
|
474
475
|
sendAsset(chain, params) {
|
|
475
|
-
var _a;
|
|
476
|
+
var _a, _b;
|
|
476
477
|
return __awaiter(this, void 0, void 0, function* () {
|
|
478
|
+
const traceId = (_a = params.traceId) !== null && _a !== void 0 ? _a : (0, trace_1.generateTraceId)();
|
|
479
|
+
logger_1.sdkLogger.debug('[Portal] sendAsset started (single traceId for build + sign)', { traceId });
|
|
477
480
|
try {
|
|
478
481
|
// Convert the chain to a chain ID
|
|
479
482
|
const chainId = this.convertChainToChainId(chain);
|
|
480
|
-
// Build the transaction
|
|
481
|
-
const buildTxResponse = yield this.buildTransaction(chainId, params.to, params.token, params.amount);
|
|
483
|
+
// Build the transaction (same traceId for correlation with backend)
|
|
484
|
+
const buildTxResponse = yield this.buildTransaction(chainId, params.to, params.token, params.amount, traceId);
|
|
482
485
|
// Get the chain namespace
|
|
483
|
-
const chainNamespace = (
|
|
484
|
-
// Send the transaction based on chain namespace
|
|
486
|
+
const chainNamespace = (_b = chainId.split(':')[0]) !== null && _b !== void 0 ? _b : '';
|
|
487
|
+
// Send the transaction based on chain namespace (same traceId on request)
|
|
485
488
|
let response;
|
|
486
489
|
switch (chainNamespace) {
|
|
487
490
|
case 'eip155': {
|
|
@@ -491,6 +494,7 @@ class Portal {
|
|
|
491
494
|
params: [buildTxResponse.transaction],
|
|
492
495
|
sponsorGas: params.sponsorGas,
|
|
493
496
|
signatureApprovalMemo: params.signatureApprovalMemo,
|
|
497
|
+
traceId,
|
|
494
498
|
});
|
|
495
499
|
break;
|
|
496
500
|
}
|
|
@@ -501,6 +505,7 @@ class Portal {
|
|
|
501
505
|
params: [buildTxResponse.transaction],
|
|
502
506
|
sponsorGas: params.sponsorGas,
|
|
503
507
|
signatureApprovalMemo: params.signatureApprovalMemo,
|
|
508
|
+
traceId,
|
|
504
509
|
});
|
|
505
510
|
break;
|
|
506
511
|
}
|
|
@@ -828,10 +833,10 @@ class Portal {
|
|
|
828
833
|
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.getNFTAssets(chainId);
|
|
829
834
|
});
|
|
830
835
|
}
|
|
831
|
-
buildTransaction(chainId, to, token, amount) {
|
|
836
|
+
buildTransaction(chainId, to, token, amount, traceId) {
|
|
832
837
|
var _a;
|
|
833
838
|
return __awaiter(this, void 0, void 0, function* () {
|
|
834
|
-
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.buildTransaction(chainId, to, token, amount);
|
|
839
|
+
return (_a = this.mpc) === null || _a === void 0 ? void 0 : _a.buildTransaction(chainId, to, token, amount, traceId);
|
|
835
840
|
});
|
|
836
841
|
}
|
|
837
842
|
/*******************************
|
|
@@ -663,7 +663,7 @@ describe('Portal', () => {
|
|
|
663
663
|
it('should correctly call mpc.buildTransaction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
664
664
|
yield portal.buildTransaction('eip155:1', constants_1.mockAddress, 'USDC', '1');
|
|
665
665
|
expect(portal.mpc.buildTransaction).toHaveBeenCalledTimes(1);
|
|
666
|
-
expect(portal.mpc.buildTransaction).toHaveBeenCalledWith('eip155:1', constants_1.mockAddress, 'USDC', '1');
|
|
666
|
+
expect(portal.mpc.buildTransaction).toHaveBeenCalledWith('eip155:1', constants_1.mockAddress, 'USDC', '1', undefined);
|
|
667
667
|
}));
|
|
668
668
|
});
|
|
669
669
|
describe('getNFTAssets', () => {
|
|
@@ -11,8 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MpcErrorCodes = exports.MpcError = void 0;
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
|
+
const logger_1 = require("../logger");
|
|
14
15
|
const index_1 = require("../index");
|
|
15
|
-
const
|
|
16
|
+
const trace_1 = require("../shared/trace");
|
|
17
|
+
const WEB_SDK_VERSION = '3.12.0';
|
|
16
18
|
class Mpc {
|
|
17
19
|
get ready() {
|
|
18
20
|
return this._ready;
|
|
@@ -22,6 +24,7 @@ class Mpc {
|
|
|
22
24
|
}
|
|
23
25
|
constructor({ portal }) {
|
|
24
26
|
this._ready = false;
|
|
27
|
+
this.presignatureLogHandler = null;
|
|
25
28
|
this.configureIframe = () => {
|
|
26
29
|
const config = {
|
|
27
30
|
apiKey: this.portal.apiKey,
|
|
@@ -34,12 +37,14 @@ class Mpc {
|
|
|
34
37
|
mpcHost: this.portal.mpcHost,
|
|
35
38
|
mpcVersion: this.portal.mpcVersion,
|
|
36
39
|
featureFlags: this.portal.featureFlags,
|
|
40
|
+
logLevel: this.portal.getLogLevel(),
|
|
37
41
|
};
|
|
38
42
|
const message = {
|
|
39
43
|
type: 'portal:configure',
|
|
40
44
|
data: config,
|
|
41
45
|
};
|
|
42
46
|
this.postMessage(message);
|
|
47
|
+
this.setupPresignatureLogForwarding();
|
|
43
48
|
this.waitForReadyMessage();
|
|
44
49
|
};
|
|
45
50
|
this.portal = portal;
|
|
@@ -53,10 +58,12 @@ class Mpc {
|
|
|
53
58
|
*******************************/
|
|
54
59
|
backup(data, progress = () => {
|
|
55
60
|
// Noop
|
|
56
|
-
}) {
|
|
61
|
+
}, traceId) {
|
|
57
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
63
|
// validates password config for password backup
|
|
59
64
|
this.validateBackupConfig(data);
|
|
65
|
+
const resolvedTraceId = traceId !== null && traceId !== void 0 ? traceId : (0, trace_1.generateTraceId)();
|
|
66
|
+
logger_1.sdkLogger.info(`[Portal MPC] backup started | backupMethod=${data.backupMethod} | traceId=${resolvedTraceId}`);
|
|
60
67
|
return this.handleRequestToIframeAndPost({
|
|
61
68
|
methodMessage: 'portal:wasm:backup',
|
|
62
69
|
errorMessage: 'portal:wasm:backupError',
|
|
@@ -64,6 +71,7 @@ class Mpc {
|
|
|
64
71
|
data,
|
|
65
72
|
progressMessage: 'portal:wasm:backupProgress',
|
|
66
73
|
progressCallback: progress,
|
|
74
|
+
traceId: resolvedTraceId,
|
|
67
75
|
mapReturnValue: (result) => {
|
|
68
76
|
const resultData = result;
|
|
69
77
|
const backupIds = Array.isArray(resultData.backupIds)
|
|
@@ -90,12 +98,17 @@ class Mpc {
|
|
|
90
98
|
resultMessage: 'portal:destroyResult',
|
|
91
99
|
data: {},
|
|
92
100
|
mapReturnValue: () => true,
|
|
101
|
+
}).then((result) => {
|
|
102
|
+
this.teardownPresignatureLogForwarding();
|
|
103
|
+
return result;
|
|
93
104
|
});
|
|
94
105
|
}
|
|
95
106
|
generate(data, progress = () => {
|
|
96
107
|
// Noop
|
|
97
|
-
}) {
|
|
108
|
+
}, traceId) {
|
|
98
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const resolvedTraceId = traceId !== null && traceId !== void 0 ? traceId : (0, trace_1.generateTraceId)();
|
|
111
|
+
logger_1.sdkLogger.info(`[Portal MPC] generate started | traceId=${resolvedTraceId}`);
|
|
99
112
|
return this.handleRequestToIframeAndPost({
|
|
100
113
|
methodMessage: 'portal:wasm:generate',
|
|
101
114
|
errorMessage: 'portal:wasm:generateError',
|
|
@@ -103,6 +116,7 @@ class Mpc {
|
|
|
103
116
|
data,
|
|
104
117
|
progressMessage: 'portal:wasm:generateProgress',
|
|
105
118
|
progressCallback: progress,
|
|
119
|
+
traceId: resolvedTraceId,
|
|
106
120
|
});
|
|
107
121
|
});
|
|
108
122
|
}
|
|
@@ -118,8 +132,10 @@ class Mpc {
|
|
|
118
132
|
}
|
|
119
133
|
recover(data, progress = () => {
|
|
120
134
|
// Noop
|
|
121
|
-
}) {
|
|
135
|
+
}, traceId) {
|
|
122
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const resolvedTraceId = traceId !== null && traceId !== void 0 ? traceId : (0, trace_1.generateTraceId)();
|
|
138
|
+
logger_1.sdkLogger.info(`[Portal MPC] recover started | backupMethod=${data.backupMethod} | traceId=${resolvedTraceId}`);
|
|
123
139
|
return this.handleRequestToIframeAndPost({
|
|
124
140
|
methodMessage: 'portal:wasm:recover',
|
|
125
141
|
errorMessage: 'portal:wasm:recoverError',
|
|
@@ -127,26 +143,29 @@ class Mpc {
|
|
|
127
143
|
data,
|
|
128
144
|
progressMessage: 'portal:wasm:recoverProgress',
|
|
129
145
|
progressCallback: progress,
|
|
146
|
+
traceId: resolvedTraceId,
|
|
130
147
|
});
|
|
131
148
|
});
|
|
132
149
|
}
|
|
133
|
-
eject(data) {
|
|
150
|
+
eject(data, traceId) {
|
|
134
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
152
|
return this.handleRequestToIframeAndPost({
|
|
136
153
|
methodMessage: 'portal:wasm:eject',
|
|
137
154
|
errorMessage: 'portal:wasm:ejectError',
|
|
138
155
|
resultMessage: 'portal:wasm:ejectResult',
|
|
139
156
|
data,
|
|
157
|
+
traceId,
|
|
140
158
|
});
|
|
141
159
|
});
|
|
142
160
|
}
|
|
143
|
-
ejectPrivateKeys(data) {
|
|
161
|
+
ejectPrivateKeys(data, traceId) {
|
|
144
162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
163
|
return this.handleRequestToIframeAndPost({
|
|
146
164
|
methodMessage: 'portal:wasm:ejectPrivateKeys',
|
|
147
165
|
errorMessage: 'portal:wasm:ejectPrivateKeysError',
|
|
148
166
|
resultMessage: 'portal:wasm:ejectPrivateKeysResult',
|
|
149
167
|
data,
|
|
168
|
+
traceId,
|
|
150
169
|
});
|
|
151
170
|
});
|
|
152
171
|
}
|
|
@@ -166,14 +185,18 @@ class Mpc {
|
|
|
166
185
|
sign(data, progress = () => {
|
|
167
186
|
// Noop
|
|
168
187
|
}) {
|
|
188
|
+
var _a;
|
|
169
189
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
const resolvedTraceId = (_a = data.traceId) !== null && _a !== void 0 ? _a : (0, trace_1.generateTraceId)();
|
|
191
|
+
logger_1.sdkLogger.info(`[Portal MPC] sign started | method=${data.method} | traceId=${resolvedTraceId} | chainId=${data.chainId}`);
|
|
170
192
|
return this.handleRequestToIframeAndPost({
|
|
171
193
|
methodMessage: 'portal:wasm:sign',
|
|
172
194
|
errorMessage: 'portal:wasm:signError',
|
|
173
195
|
resultMessage: 'portal:wasm:signResult',
|
|
174
|
-
data,
|
|
196
|
+
data: Object.assign(Object.assign({}, data), { traceId: resolvedTraceId }),
|
|
175
197
|
progressMessage: 'portal:wasm:signProgress',
|
|
176
198
|
progressCallback: progress,
|
|
199
|
+
traceId: resolvedTraceId,
|
|
177
200
|
});
|
|
178
201
|
});
|
|
179
202
|
}
|
|
@@ -250,13 +273,14 @@ class Mpc {
|
|
|
250
273
|
});
|
|
251
274
|
});
|
|
252
275
|
}
|
|
253
|
-
buildTransaction(chainId, to, token, amount) {
|
|
276
|
+
buildTransaction(chainId, to, token, amount, traceId) {
|
|
254
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
255
278
|
return this.handleRequestToIframeAndPost({
|
|
256
279
|
methodMessage: 'portal:buildTransaction',
|
|
257
280
|
errorMessage: 'portal:buildTransactionError',
|
|
258
281
|
resultMessage: 'portal:buildTransactionResult',
|
|
259
282
|
data: { chainId, to, token, amount },
|
|
283
|
+
traceId,
|
|
260
284
|
});
|
|
261
285
|
});
|
|
262
286
|
}
|
|
@@ -710,8 +734,11 @@ class Mpc {
|
|
|
710
734
|
* This method is not part of the stable public surface area and may change in
|
|
711
735
|
* future releases without notice.
|
|
712
736
|
*/
|
|
713
|
-
handleRequestToIframeAndPost({ methodMessage, errorMessage, resultMessage, data, progressMessage, progressCallback, mapReturnValue, }) {
|
|
737
|
+
handleRequestToIframeAndPost({ methodMessage, errorMessage, resultMessage, data, progressMessage, progressCallback, mapReturnValue, traceId: providedTraceId, }) {
|
|
714
738
|
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
+
// Single traceId per operation: use provided or generate. Propagates to iframe and all internal REST/MPC calls.
|
|
740
|
+
const traceId = providedTraceId !== null && providedTraceId !== void 0 ? providedTraceId : (0, trace_1.generateTraceId)();
|
|
741
|
+
logger_1.sdkLogger.debug('[Portal] request traceId:', traceId, 'method:', methodMessage);
|
|
715
742
|
return new Promise((resolve, reject) => {
|
|
716
743
|
const handleRequest = (event) => {
|
|
717
744
|
const { type, data: result } = event.data;
|
|
@@ -738,10 +765,11 @@ class Mpc {
|
|
|
738
765
|
};
|
|
739
766
|
// Bind the function to the message event
|
|
740
767
|
window.addEventListener('message', handleRequest);
|
|
741
|
-
// Send the request to the iframe
|
|
768
|
+
// Send the request to the iframe (traceId at top-level so data shape stays unchanged)
|
|
742
769
|
this.postMessage({
|
|
743
770
|
type: methodMessage,
|
|
744
771
|
data,
|
|
772
|
+
traceId,
|
|
745
773
|
});
|
|
746
774
|
});
|
|
747
775
|
});
|
|
@@ -763,6 +791,26 @@ class Mpc {
|
|
|
763
791
|
document.body.appendChild(iframe);
|
|
764
792
|
this.iframe = iframe;
|
|
765
793
|
}
|
|
794
|
+
setupPresignatureLogForwarding() {
|
|
795
|
+
if (this.presignatureLogHandler)
|
|
796
|
+
return;
|
|
797
|
+
const handler = (event) => {
|
|
798
|
+
if (event.origin !== this.getOrigin())
|
|
799
|
+
return;
|
|
800
|
+
const { type, data } = event.data || {};
|
|
801
|
+
if (type === 'portal:presignature:log' && (data === null || data === void 0 ? void 0 : data.message)) {
|
|
802
|
+
logger_1.sdkLogger.warn(data.message);
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
this.presignatureLogHandler = handler;
|
|
806
|
+
window.addEventListener('message', handler);
|
|
807
|
+
}
|
|
808
|
+
teardownPresignatureLogForwarding() {
|
|
809
|
+
if (!this.presignatureLogHandler)
|
|
810
|
+
return;
|
|
811
|
+
window.removeEventListener('message', this.presignatureLogHandler);
|
|
812
|
+
this.presignatureLogHandler = null;
|
|
813
|
+
}
|
|
766
814
|
getOrigin() {
|
|
767
815
|
const host = this.portal.host;
|
|
768
816
|
const origin = host.startsWith('localhost:')
|