@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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request tracing for Portal API calls.
|
|
3
|
+
* Aligns with portal-react-native X-Portal-Trace-Id / traceId behavior.
|
|
4
|
+
*
|
|
5
|
+
* Propagation in the Web SDK:
|
|
6
|
+
* - Browser: High-level methods (backup, recover, sendAsset, provider.request) accept optional
|
|
7
|
+
* traceId or generate one. They pass it to handleRequestToIframeAndPost (postMessage) or
|
|
8
|
+
* to fetch headers (X-Portal-Trace-Id).
|
|
9
|
+
* - Iframe: On each portal:* message, the iframe reads traceId from the message (top-level or
|
|
10
|
+
* data.traceId), calls setRequestTraceId(traceId), which sets it on Api, Mpc, ZeroX, etc.
|
|
11
|
+
* All REST and MPC calls made during that request then use the same trace ID (header or reqId).
|
|
12
|
+
* - After the request completes, clearRequestTraceId() is called so the next message gets a
|
|
13
|
+
* fresh or caller-provided trace ID.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* HTTP header name for request tracing.
|
|
18
|
+
* Used by connect-api (client + custodian APIs) in the Web SDK.
|
|
19
|
+
* Note: Other internal services may use different header names.
|
|
20
|
+
*/
|
|
21
|
+
export const X_PORTAL_TRACE_ID_HEADER = 'X-Portal-Trace-Id'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generates a UUID v4 trace ID for request correlation.
|
|
25
|
+
* Uses crypto.randomUUID() when available; otherwise crypto.getRandomValues() for better
|
|
26
|
+
* quality than Math.random(); falls back to Math.random() only when no crypto API exists.
|
|
27
|
+
*/
|
|
28
|
+
export function generateTraceId(): string {
|
|
29
|
+
if (
|
|
30
|
+
typeof crypto !== 'undefined' &&
|
|
31
|
+
typeof (crypto as Crypto).randomUUID === 'function'
|
|
32
|
+
) {
|
|
33
|
+
return (crypto as Crypto).randomUUID()
|
|
34
|
+
}
|
|
35
|
+
if (
|
|
36
|
+
typeof crypto !== 'undefined' &&
|
|
37
|
+
typeof (crypto as Crypto).getRandomValues === 'function'
|
|
38
|
+
) {
|
|
39
|
+
return fallbackUuidV4WithCrypto(crypto as Crypto)
|
|
40
|
+
}
|
|
41
|
+
return fallbackUuidV4WithMathRandom()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fallbackUuidV4WithCrypto(crypto: Crypto): string {
|
|
45
|
+
const bytes = new Uint8Array(16)
|
|
46
|
+
crypto.getRandomValues(bytes)
|
|
47
|
+
bytes[6] = (bytes[6]! & 0x0f) | 0x40
|
|
48
|
+
bytes[8] = (bytes[8]! & 0x3f) | 0x80
|
|
49
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('')
|
|
50
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function fallbackUuidV4WithMathRandom(): string {
|
|
54
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
55
|
+
const r = (Math.random() * 16) | 0
|
|
56
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
57
|
+
return v.toString(16)
|
|
58
|
+
})
|
|
59
|
+
}
|
package/src/shared/types/api.ts
CHANGED
|
@@ -133,6 +133,8 @@ interface MediaInfo {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
// Iframe configuration types
|
|
136
|
+
export type IframeLogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug'
|
|
137
|
+
|
|
136
138
|
export interface IframeConfigurationOptions {
|
|
137
139
|
autoApprove: boolean
|
|
138
140
|
featureFlags?: FeatureFlags
|
|
@@ -142,6 +144,9 @@ export interface IframeConfigurationOptions {
|
|
|
142
144
|
mpcHost: string
|
|
143
145
|
mpcVersion: string
|
|
144
146
|
|
|
147
|
+
/** When set to 'none', the iframe SDK will not log to the console. Passed from parent via portal:configure. */
|
|
148
|
+
logLevel?: IframeLogLevel
|
|
149
|
+
|
|
145
150
|
// One of these three is required for authentication
|
|
146
151
|
apiKey?: string
|
|
147
152
|
authToken?: string
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
// Basic types
|
|
6
6
|
export interface FeatureFlags {
|
|
7
7
|
isMultiBackupEnabled?: boolean
|
|
8
|
+
/** Enable presignature buffer for faster signing (SECP256K1 only). */
|
|
9
|
+
usePresignatures?: boolean
|
|
10
|
+
/** Per-curve max presignatures (e.g. { SECP256K1: 3 }). */
|
|
11
|
+
maxPresignaturesPerCurve?: Partial<Record<string, number>>
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export interface Network {
|
|
@@ -36,6 +40,13 @@ export interface DkgData {
|
|
|
36
40
|
signingSharePairId?: string
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
/** Presignature item stored per curve (SECP256K1 only in current implementation). */
|
|
44
|
+
export interface Presignature {
|
|
45
|
+
id: string
|
|
46
|
+
expiresAt: string
|
|
47
|
+
data: string
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
// Transaction types
|
|
40
51
|
export interface EIP1559Transaction {
|
|
41
52
|
from: string
|
|
@@ -433,6 +444,8 @@ export interface SendAssetParams {
|
|
|
433
444
|
token: string
|
|
434
445
|
sponsorGas?: boolean
|
|
435
446
|
signatureApprovalMemo?: string
|
|
447
|
+
/** Optional trace ID for correlating this operation with backend logs (X-Portal-Trace-Id). */
|
|
448
|
+
traceId?: string
|
|
436
449
|
}
|
|
437
450
|
|
|
438
451
|
export interface SendAssetResponse {
|
|
@@ -539,6 +552,7 @@ export interface SignArgs {
|
|
|
539
552
|
sponsorGas?: boolean
|
|
540
553
|
/** Optional memo displayed to the user during the signature approval flow. */
|
|
541
554
|
signatureApprovalMemo?: string
|
|
555
|
+
traceId?: string
|
|
542
556
|
}
|
|
543
557
|
|
|
544
558
|
export interface SignResult {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared types barrel export
|
|
3
3
|
*
|
|
4
|
-
* This module exports all shared types used by both browser and iframe packages
|
|
4
|
+
* This module exports all shared types used by both browser and iframe packages.
|
|
5
|
+
* For trace ID helpers (X_PORTAL_TRACE_ID_HEADER, generateTraceId), use shared/trace.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
// Common types
|
package/types.d.ts
CHANGED