@openfort/openfort-js 1.3.3 → 1.3.4
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/cjs/sdk/src/api/embeddedWallet.cjs +1 -1
- package/dist/cjs/sdk/src/core/passkey/handler.cjs +1 -1
- package/dist/cjs/sdk/src/version.cjs +1 -1
- package/dist/cjs/sdk/src/wallets/embedded.cjs +1 -1
- package/dist/cjs/sdk/src/wallets/iframeManager.cjs +1 -1
- package/dist/cjs/sdk/src/wallets/types.cjs +1 -1
- package/dist/index.d.cts +134 -202
- package/dist/index.d.ts +134 -202
- package/dist/sdk/src/api/embeddedWallet.js +1 -1
- package/dist/sdk/src/core/passkey/handler.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/dist/sdk/src/wallets/embedded.js +1 -1
- package/dist/sdk/src/wallets/iframeManager.js +1 -1
- package/dist/sdk/src/wallets/types.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -37,13 +37,7 @@ interface ShieldOptions {
|
|
|
37
37
|
// TypeScript Version: 4.7
|
|
38
38
|
type StringLiteralsOrString<Literals extends string> = Literals | (string & {});
|
|
39
39
|
|
|
40
|
-
type AxiosHeaderValue =
|
|
41
|
-
| AxiosHeaders
|
|
42
|
-
| string
|
|
43
|
-
| string[]
|
|
44
|
-
| number
|
|
45
|
-
| boolean
|
|
46
|
-
| null;
|
|
40
|
+
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
|
47
41
|
|
|
48
42
|
interface RawAxiosHeaders {
|
|
49
43
|
[key: string]: AxiosHeaderValue;
|
|
@@ -60,11 +54,7 @@ type AxiosHeaderMatcher =
|
|
|
60
54
|
| RegExp
|
|
61
55
|
| ((this: AxiosHeaders, value: string, name: string) => boolean);
|
|
62
56
|
|
|
63
|
-
type AxiosHeaderParser = (
|
|
64
|
-
this: AxiosHeaders,
|
|
65
|
-
value: AxiosHeaderValue,
|
|
66
|
-
header: string,
|
|
67
|
-
) => any;
|
|
57
|
+
type AxiosHeaderParser = (this: AxiosHeaders, value: AxiosHeaderValue, header: string) => any;
|
|
68
58
|
|
|
69
59
|
declare class AxiosHeaders {
|
|
70
60
|
constructor(headers?: RawAxiosHeaders | AxiosHeaders | string);
|
|
@@ -74,12 +64,9 @@ declare class AxiosHeaders {
|
|
|
74
64
|
set(
|
|
75
65
|
headerName?: string,
|
|
76
66
|
value?: AxiosHeaderValue,
|
|
77
|
-
rewrite?: boolean | AxiosHeaderMatcher
|
|
78
|
-
): AxiosHeaders;
|
|
79
|
-
set(
|
|
80
|
-
headers?: RawAxiosHeaders | AxiosHeaders | string,
|
|
81
|
-
rewrite?: boolean,
|
|
67
|
+
rewrite?: boolean | AxiosHeaderMatcher
|
|
82
68
|
): AxiosHeaders;
|
|
69
|
+
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
|
|
83
70
|
|
|
84
71
|
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
|
85
72
|
get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
|
|
@@ -93,9 +80,7 @@ declare class AxiosHeaders {
|
|
|
93
80
|
normalize(format: boolean): AxiosHeaders;
|
|
94
81
|
|
|
95
82
|
concat(
|
|
96
|
-
...targets: Array<
|
|
97
|
-
AxiosHeaders | RawAxiosHeaders | string | undefined | null
|
|
98
|
-
>
|
|
83
|
+
...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>
|
|
99
84
|
): AxiosHeaders;
|
|
100
85
|
|
|
101
86
|
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
|
@@ -105,55 +90,35 @@ declare class AxiosHeaders {
|
|
|
105
90
|
static accessor(header: string | string[]): AxiosHeaders;
|
|
106
91
|
|
|
107
92
|
static concat(
|
|
108
|
-
...targets: Array<
|
|
109
|
-
AxiosHeaders | RawAxiosHeaders | string | undefined | null
|
|
110
|
-
>
|
|
93
|
+
...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>
|
|
111
94
|
): AxiosHeaders;
|
|
112
95
|
|
|
113
|
-
setContentType(
|
|
114
|
-
value: ContentType,
|
|
115
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
116
|
-
): AxiosHeaders;
|
|
96
|
+
setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
117
97
|
getContentType(parser?: RegExp): RegExpExecArray | null;
|
|
118
98
|
getContentType(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
119
99
|
hasContentType(matcher?: AxiosHeaderMatcher): boolean;
|
|
120
100
|
|
|
121
|
-
setContentLength(
|
|
122
|
-
value: AxiosHeaderValue,
|
|
123
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
124
|
-
): AxiosHeaders;
|
|
101
|
+
setContentLength(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
125
102
|
getContentLength(parser?: RegExp): RegExpExecArray | null;
|
|
126
103
|
getContentLength(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
127
104
|
hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
|
|
128
105
|
|
|
129
|
-
setAccept(
|
|
130
|
-
value: AxiosHeaderValue,
|
|
131
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
132
|
-
): AxiosHeaders;
|
|
106
|
+
setAccept(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
133
107
|
getAccept(parser?: RegExp): RegExpExecArray | null;
|
|
134
108
|
getAccept(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
135
109
|
hasAccept(matcher?: AxiosHeaderMatcher): boolean;
|
|
136
110
|
|
|
137
|
-
setUserAgent(
|
|
138
|
-
value: AxiosHeaderValue,
|
|
139
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
140
|
-
): AxiosHeaders;
|
|
111
|
+
setUserAgent(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
141
112
|
getUserAgent(parser?: RegExp): RegExpExecArray | null;
|
|
142
113
|
getUserAgent(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
143
114
|
hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
|
|
144
115
|
|
|
145
|
-
setContentEncoding(
|
|
146
|
-
value: AxiosHeaderValue,
|
|
147
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
148
|
-
): AxiosHeaders;
|
|
116
|
+
setContentEncoding(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
149
117
|
getContentEncoding(parser?: RegExp): RegExpExecArray | null;
|
|
150
118
|
getContentEncoding(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
151
119
|
hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
|
|
152
120
|
|
|
153
|
-
setAuthorization(
|
|
154
|
-
value: AxiosHeaderValue,
|
|
155
|
-
rewrite?: boolean | AxiosHeaderMatcher,
|
|
156
|
-
): AxiosHeaders;
|
|
121
|
+
setAuthorization(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
|
157
122
|
getAuthorization(parser?: RegExp): RegExpExecArray | null;
|
|
158
123
|
getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
|
159
124
|
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
|
|
@@ -164,56 +129,53 @@ declare class AxiosHeaders {
|
|
|
164
129
|
}
|
|
165
130
|
|
|
166
131
|
type CommonRequestHeadersList =
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
132
|
+
| 'Accept'
|
|
133
|
+
| 'Content-Length'
|
|
134
|
+
| 'User-Agent'
|
|
135
|
+
| 'Content-Encoding'
|
|
136
|
+
| 'Authorization'
|
|
137
|
+
| 'Location';
|
|
172
138
|
|
|
173
139
|
type ContentType =
|
|
174
140
|
| AxiosHeaderValue
|
|
175
|
-
|
|
|
176
|
-
|
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
141
|
+
| 'text/html'
|
|
142
|
+
| 'text/plain'
|
|
143
|
+
| 'multipart/form-data'
|
|
144
|
+
| 'application/json'
|
|
145
|
+
| 'application/x-www-form-urlencoded'
|
|
146
|
+
| 'application/octet-stream';
|
|
181
147
|
|
|
182
148
|
type RawAxiosRequestHeaders = Partial<
|
|
183
149
|
RawAxiosHeaders & {
|
|
184
150
|
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
|
185
151
|
} & {
|
|
186
|
-
|
|
152
|
+
'Content-Type': ContentType;
|
|
187
153
|
}
|
|
188
154
|
>;
|
|
189
155
|
|
|
190
156
|
type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
|
191
157
|
|
|
192
158
|
type CommonResponseHeadersList =
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
|
|
|
196
|
-
|
|
|
197
|
-
|
|
|
159
|
+
| 'Server'
|
|
160
|
+
| 'Content-Type'
|
|
161
|
+
| 'Content-Length'
|
|
162
|
+
| 'Cache-Control'
|
|
163
|
+
| 'Content-Encoding';
|
|
164
|
+
|
|
165
|
+
type CommonResponseHeaderKey = CommonResponseHeadersList | Lowercase<CommonResponseHeadersList>;
|
|
198
166
|
|
|
199
167
|
type RawCommonResponseHeaders = {
|
|
200
|
-
[Key in
|
|
168
|
+
[Key in CommonResponseHeaderKey]: AxiosHeaderValue;
|
|
201
169
|
} & {
|
|
202
|
-
|
|
170
|
+
'set-cookie': string[];
|
|
203
171
|
};
|
|
204
172
|
|
|
205
|
-
type RawAxiosResponseHeaders = Partial<
|
|
206
|
-
RawAxiosHeaders & RawCommonResponseHeaders
|
|
207
|
-
>;
|
|
173
|
+
type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
|
|
208
174
|
|
|
209
175
|
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
|
210
176
|
|
|
211
177
|
interface AxiosRequestTransformer {
|
|
212
|
-
(
|
|
213
|
-
this: InternalAxiosRequestConfig,
|
|
214
|
-
data: any,
|
|
215
|
-
headers: AxiosRequestHeaders,
|
|
216
|
-
): any;
|
|
178
|
+
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
|
217
179
|
}
|
|
218
180
|
|
|
219
181
|
interface AxiosResponseTransformer {
|
|
@@ -221,7 +183,7 @@ interface AxiosResponseTransformer {
|
|
|
221
183
|
this: InternalAxiosRequestConfig,
|
|
222
184
|
data: any,
|
|
223
185
|
headers: AxiosResponseHeaders,
|
|
224
|
-
status?: number
|
|
186
|
+
status?: number
|
|
225
187
|
): any;
|
|
226
188
|
}
|
|
227
189
|
|
|
@@ -307,62 +269,48 @@ declare enum HttpStatusCode {
|
|
|
307
269
|
NetworkAuthenticationRequired = 511,
|
|
308
270
|
}
|
|
309
271
|
|
|
310
|
-
type
|
|
311
|
-
|
|
|
312
|
-
|
|
|
313
|
-
|
|
|
314
|
-
|
|
|
315
|
-
|
|
|
316
|
-
|
|
|
317
|
-
|
|
|
318
|
-
|
|
|
319
|
-
|
|
|
320
|
-
|
|
|
321
|
-
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
| "PATCH"
|
|
325
|
-
| "purge"
|
|
326
|
-
| "PURGE"
|
|
327
|
-
| "link"
|
|
328
|
-
| "LINK"
|
|
329
|
-
| "unlink"
|
|
330
|
-
| "UNLINK";
|
|
272
|
+
type UppercaseMethod =
|
|
273
|
+
| 'GET'
|
|
274
|
+
| 'DELETE'
|
|
275
|
+
| 'HEAD'
|
|
276
|
+
| 'OPTIONS'
|
|
277
|
+
| 'POST'
|
|
278
|
+
| 'PUT'
|
|
279
|
+
| 'PATCH'
|
|
280
|
+
| 'PURGE'
|
|
281
|
+
| 'LINK'
|
|
282
|
+
| 'UNLINK'
|
|
283
|
+
| 'QUERY';
|
|
284
|
+
|
|
285
|
+
type Method = (UppercaseMethod | Lowercase<UppercaseMethod>) & {};
|
|
331
286
|
|
|
332
287
|
type ResponseType =
|
|
333
|
-
|
|
|
334
|
-
|
|
|
335
|
-
|
|
|
336
|
-
|
|
|
337
|
-
|
|
|
338
|
-
|
|
|
339
|
-
|
|
|
340
|
-
|
|
341
|
-
type
|
|
342
|
-
|
|
|
343
|
-
|
|
|
344
|
-
|
|
|
345
|
-
|
|
|
346
|
-
|
|
|
347
|
-
|
|
|
348
|
-
|
|
|
349
|
-
|
|
|
350
|
-
|
|
|
351
|
-
|
|
|
352
|
-
|
|
|
353
|
-
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
|
357
|
-
|
|
|
358
|
-
|
|
359
|
-
| "UCS2"
|
|
360
|
-
| "utf-8"
|
|
361
|
-
| "UTF-8"
|
|
362
|
-
| "utf8"
|
|
363
|
-
| "UTF8"
|
|
364
|
-
| "utf16le"
|
|
365
|
-
| "UTF16LE";
|
|
288
|
+
| 'arraybuffer'
|
|
289
|
+
| 'blob'
|
|
290
|
+
| 'document'
|
|
291
|
+
| 'json'
|
|
292
|
+
| 'text'
|
|
293
|
+
| 'stream'
|
|
294
|
+
| 'formdata';
|
|
295
|
+
|
|
296
|
+
type UppercaseResponseEncoding =
|
|
297
|
+
| 'ASCII'
|
|
298
|
+
| 'ANSI'
|
|
299
|
+
| 'BINARY'
|
|
300
|
+
| 'BASE64'
|
|
301
|
+
| 'BASE64URL'
|
|
302
|
+
| 'HEX'
|
|
303
|
+
| 'LATIN1'
|
|
304
|
+
| 'UCS-2'
|
|
305
|
+
| 'UCS2'
|
|
306
|
+
| 'UTF-8'
|
|
307
|
+
| 'UTF8'
|
|
308
|
+
| 'UTF16LE';
|
|
309
|
+
|
|
310
|
+
type responseEncoding = (
|
|
311
|
+
| UppercaseResponseEncoding
|
|
312
|
+
| Lowercase<UppercaseResponseEncoding>
|
|
313
|
+
) & {};
|
|
366
314
|
|
|
367
315
|
interface TransitionalOptions {
|
|
368
316
|
silentJSONParsing?: boolean;
|
|
@@ -390,7 +338,7 @@ interface SerializerVisitor {
|
|
|
390
338
|
value: any,
|
|
391
339
|
key: string | number,
|
|
392
340
|
path: null | Array<string | number>,
|
|
393
|
-
helpers: FormDataVisitorHelpers
|
|
341
|
+
helpers: FormDataVisitorHelpers
|
|
394
342
|
): boolean;
|
|
395
343
|
}
|
|
396
344
|
|
|
@@ -438,7 +386,7 @@ interface AxiosProgressEvent {
|
|
|
438
386
|
|
|
439
387
|
type Milliseconds = number;
|
|
440
388
|
|
|
441
|
-
type AxiosAdapterName = StringLiteralsOrString<
|
|
389
|
+
type AxiosAdapterName = StringLiteralsOrString<'xhr' | 'http' | 'fetch'>;
|
|
442
390
|
|
|
443
391
|
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
|
444
392
|
|
|
@@ -484,8 +432,14 @@ interface AxiosRequestConfig<D = any> {
|
|
|
484
432
|
headers: Record<string, string>;
|
|
485
433
|
statusCode: HttpStatusCode;
|
|
486
434
|
},
|
|
435
|
+
requestDetails: {
|
|
436
|
+
headers: Record<string, string>;
|
|
437
|
+
url: string;
|
|
438
|
+
method: string;
|
|
439
|
+
},
|
|
487
440
|
) => void;
|
|
488
441
|
socketPath?: string | null;
|
|
442
|
+
allowedSocketPaths?: string | string[] | null;
|
|
489
443
|
transport?: any;
|
|
490
444
|
httpAgent?: any;
|
|
491
445
|
httpsAgent?: any;
|
|
@@ -497,24 +451,11 @@ interface AxiosRequestConfig<D = any> {
|
|
|
497
451
|
insecureHTTPParser?: boolean;
|
|
498
452
|
env?: {
|
|
499
453
|
FormData?: new (...args: any[]) => object;
|
|
500
|
-
fetch?: (
|
|
501
|
-
|
|
502
|
-
init?: RequestInit,
|
|
503
|
-
) => Promise<Response>;
|
|
504
|
-
Request?: new (
|
|
505
|
-
input: URL | Request | string,
|
|
506
|
-
init?: RequestInit,
|
|
507
|
-
) => Request;
|
|
454
|
+
fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
|
|
455
|
+
Request?: new (input: URL | Request | string, init?: RequestInit) => Request;
|
|
508
456
|
Response?: new (
|
|
509
|
-
body?:
|
|
510
|
-
|
|
511
|
-
| ArrayBufferView
|
|
512
|
-
| Blob
|
|
513
|
-
| FormData
|
|
514
|
-
| URLSearchParams
|
|
515
|
-
| string
|
|
516
|
-
| null,
|
|
517
|
-
init?: ResponseInit,
|
|
457
|
+
body?: ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | string | null,
|
|
458
|
+
init?: ResponseInit
|
|
518
459
|
) => Response;
|
|
519
460
|
};
|
|
520
461
|
formSerializer?: FormSerializerOptions;
|
|
@@ -526,35 +467,27 @@ interface AxiosRequestConfig<D = any> {
|
|
|
526
467
|
cb: (
|
|
527
468
|
err: Error | null,
|
|
528
469
|
address: LookupAddress | LookupAddress[],
|
|
529
|
-
family?: AddressFamily
|
|
530
|
-
) => void
|
|
470
|
+
family?: AddressFamily
|
|
471
|
+
) => void
|
|
531
472
|
) => void)
|
|
532
473
|
| ((
|
|
533
474
|
hostname: string,
|
|
534
|
-
options: object
|
|
475
|
+
options: object
|
|
535
476
|
) => Promise<
|
|
536
|
-
| [
|
|
537
|
-
address: LookupAddressEntry | LookupAddressEntry[],
|
|
538
|
-
family?: AddressFamily,
|
|
539
|
-
]
|
|
540
|
-
| LookupAddress
|
|
477
|
+
[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress
|
|
541
478
|
>);
|
|
542
|
-
withXSRFToken?:
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
parseReviver?: (this: any, key: string, value: any) => any;
|
|
546
|
-
fetchOptions?:
|
|
547
|
-
| Omit<RequestInit, "body" | "headers" | "method" | "signal">
|
|
548
|
-
| Record<string, any>;
|
|
479
|
+
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
|
480
|
+
parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
|
|
481
|
+
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
|
|
549
482
|
httpVersion?: 1 | 2;
|
|
550
483
|
http2Options?: Record<string, any> & {
|
|
551
484
|
sessionTimeout?: number;
|
|
552
485
|
};
|
|
486
|
+
formDataHeaderPolicy?: 'legacy' | 'content-only';
|
|
487
|
+
redact?: string[];
|
|
553
488
|
}
|
|
554
489
|
|
|
555
|
-
interface InternalAxiosRequestConfig<
|
|
556
|
-
D = any,
|
|
557
|
-
> extends AxiosRequestConfig<D> {
|
|
490
|
+
interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
|
558
491
|
headers: AxiosRequestHeaders;
|
|
559
492
|
}
|
|
560
493
|
|
|
@@ -570,19 +503,14 @@ interface HeadersDefaults {
|
|
|
570
503
|
purge?: RawAxiosRequestHeaders;
|
|
571
504
|
link?: RawAxiosRequestHeaders;
|
|
572
505
|
unlink?: RawAxiosRequestHeaders;
|
|
506
|
+
query?: RawAxiosRequestHeaders;
|
|
573
507
|
}
|
|
574
508
|
|
|
575
|
-
interface AxiosDefaults<D = any> extends Omit<
|
|
576
|
-
AxiosRequestConfig<D>,
|
|
577
|
-
"headers"
|
|
578
|
-
> {
|
|
509
|
+
interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
|
579
510
|
headers: HeadersDefaults;
|
|
580
511
|
}
|
|
581
512
|
|
|
582
|
-
interface CreateAxiosDefaults<D = any> extends Omit<
|
|
583
|
-
AxiosRequestConfig<D>,
|
|
584
|
-
"headers"
|
|
585
|
-
> {
|
|
513
|
+
interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
|
586
514
|
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
|
587
515
|
}
|
|
588
516
|
|
|
@@ -609,7 +537,7 @@ interface CancelToken {
|
|
|
609
537
|
|
|
610
538
|
interface AxiosInterceptorOptions {
|
|
611
539
|
synchronous?: boolean;
|
|
612
|
-
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
|
540
|
+
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
|
613
541
|
}
|
|
614
542
|
|
|
615
543
|
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
|
@@ -618,25 +546,23 @@ type AxiosInterceptorRejected = (error: any) => any;
|
|
|
618
546
|
type AxiosRequestInterceptorUse<T> = (
|
|
619
547
|
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
|
620
548
|
onRejected?: AxiosInterceptorRejected | null,
|
|
621
|
-
options?: AxiosInterceptorOptions
|
|
549
|
+
options?: AxiosInterceptorOptions
|
|
622
550
|
) => number;
|
|
623
551
|
|
|
624
552
|
type AxiosResponseInterceptorUse<T> = (
|
|
625
553
|
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
|
626
|
-
onRejected?: AxiosInterceptorRejected | null
|
|
554
|
+
onRejected?: AxiosInterceptorRejected | null
|
|
627
555
|
) => number;
|
|
628
556
|
|
|
629
557
|
interface AxiosInterceptorHandler<T> {
|
|
630
558
|
fulfilled: AxiosInterceptorFulfilled<T>;
|
|
631
559
|
rejected?: AxiosInterceptorRejected;
|
|
632
560
|
synchronous: boolean;
|
|
633
|
-
runWhen
|
|
561
|
+
runWhen?: ((config: InternalAxiosRequestConfig) => boolean) | null;
|
|
634
562
|
}
|
|
635
563
|
|
|
636
564
|
interface AxiosInterceptorManager<V> {
|
|
637
|
-
use: V extends AxiosResponse
|
|
638
|
-
? AxiosResponseInterceptorUse<V>
|
|
639
|
-
: AxiosRequestInterceptorUse<V>;
|
|
565
|
+
use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
|
|
640
566
|
eject(id: number): void;
|
|
641
567
|
clear(): void;
|
|
642
568
|
handlers?: Array<AxiosInterceptorHandler<V>>;
|
|
@@ -650,68 +576,66 @@ declare class Axios {
|
|
|
650
576
|
response: AxiosInterceptorManager<AxiosResponse>;
|
|
651
577
|
};
|
|
652
578
|
getUri(config?: AxiosRequestConfig): string;
|
|
653
|
-
request<T = any, R = AxiosResponse<T>, D = any>(
|
|
654
|
-
config: AxiosRequestConfig<D>,
|
|
655
|
-
): Promise<R>;
|
|
579
|
+
request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
656
580
|
get<T = any, R = AxiosResponse<T>, D = any>(
|
|
657
581
|
url: string,
|
|
658
|
-
config?: AxiosRequestConfig<D
|
|
582
|
+
config?: AxiosRequestConfig<D>
|
|
659
583
|
): Promise<R>;
|
|
660
584
|
delete<T = any, R = AxiosResponse<T>, D = any>(
|
|
661
585
|
url: string,
|
|
662
|
-
config?: AxiosRequestConfig<D
|
|
586
|
+
config?: AxiosRequestConfig<D>
|
|
663
587
|
): Promise<R>;
|
|
664
588
|
head<T = any, R = AxiosResponse<T>, D = any>(
|
|
665
589
|
url: string,
|
|
666
|
-
config?: AxiosRequestConfig<D
|
|
590
|
+
config?: AxiosRequestConfig<D>
|
|
667
591
|
): Promise<R>;
|
|
668
592
|
options<T = any, R = AxiosResponse<T>, D = any>(
|
|
669
593
|
url: string,
|
|
670
|
-
config?: AxiosRequestConfig<D
|
|
594
|
+
config?: AxiosRequestConfig<D>
|
|
671
595
|
): Promise<R>;
|
|
672
596
|
post<T = any, R = AxiosResponse<T>, D = any>(
|
|
673
597
|
url: string,
|
|
674
598
|
data?: D,
|
|
675
|
-
config?: AxiosRequestConfig<D
|
|
599
|
+
config?: AxiosRequestConfig<D>
|
|
676
600
|
): Promise<R>;
|
|
677
601
|
put<T = any, R = AxiosResponse<T>, D = any>(
|
|
678
602
|
url: string,
|
|
679
603
|
data?: D,
|
|
680
|
-
config?: AxiosRequestConfig<D
|
|
604
|
+
config?: AxiosRequestConfig<D>
|
|
681
605
|
): Promise<R>;
|
|
682
606
|
patch<T = any, R = AxiosResponse<T>, D = any>(
|
|
683
607
|
url: string,
|
|
684
608
|
data?: D,
|
|
685
|
-
config?: AxiosRequestConfig<D
|
|
609
|
+
config?: AxiosRequestConfig<D>
|
|
686
610
|
): Promise<R>;
|
|
687
611
|
postForm<T = any, R = AxiosResponse<T>, D = any>(
|
|
688
612
|
url: string,
|
|
689
613
|
data?: D,
|
|
690
|
-
config?: AxiosRequestConfig<D
|
|
614
|
+
config?: AxiosRequestConfig<D>
|
|
691
615
|
): Promise<R>;
|
|
692
616
|
putForm<T = any, R = AxiosResponse<T>, D = any>(
|
|
693
617
|
url: string,
|
|
694
618
|
data?: D,
|
|
695
|
-
config?: AxiosRequestConfig<D
|
|
619
|
+
config?: AxiosRequestConfig<D>
|
|
696
620
|
): Promise<R>;
|
|
697
621
|
patchForm<T = any, R = AxiosResponse<T>, D = any>(
|
|
698
622
|
url: string,
|
|
699
623
|
data?: D,
|
|
700
|
-
config?: AxiosRequestConfig<D
|
|
624
|
+
config?: AxiosRequestConfig<D>
|
|
625
|
+
): Promise<R>;
|
|
626
|
+
query<T = any, R = AxiosResponse<T>, D = any>(
|
|
627
|
+
url: string,
|
|
628
|
+
data?: D,
|
|
629
|
+
config?: AxiosRequestConfig<D>
|
|
701
630
|
): Promise<R>;
|
|
702
631
|
}
|
|
703
632
|
|
|
704
633
|
interface AxiosInstance extends Axios {
|
|
705
|
-
<T = any, R = AxiosResponse<T>, D = any>(
|
|
706
|
-
|
|
707
|
-
): Promise<R>;
|
|
708
|
-
<T = any, R = AxiosResponse<T>, D = any>(
|
|
709
|
-
url: string,
|
|
710
|
-
config?: AxiosRequestConfig<D>,
|
|
711
|
-
): Promise<R>;
|
|
634
|
+
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
|
635
|
+
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
|
712
636
|
|
|
713
637
|
create(config?: CreateAxiosDefaults): AxiosInstance;
|
|
714
|
-
defaults: Omit<AxiosDefaults,
|
|
638
|
+
defaults: Omit<AxiosDefaults, 'headers'> & {
|
|
715
639
|
headers: HeadersDefaults & {
|
|
716
640
|
[key: string]: AxiosHeaderValue;
|
|
717
641
|
};
|
|
@@ -11549,6 +11473,13 @@ type EmbeddedAccountCreateParams = {
|
|
|
11549
11473
|
chainId?: number;
|
|
11550
11474
|
recoveryParams: RecoveryParams;
|
|
11551
11475
|
};
|
|
11476
|
+
type EmbeddedAccountImportParams = {
|
|
11477
|
+
privateKey: string;
|
|
11478
|
+
accountType: AccountTypeEnum;
|
|
11479
|
+
chainType: ChainTypeEnum;
|
|
11480
|
+
chainId?: number;
|
|
11481
|
+
recoveryParams: RecoveryParams;
|
|
11482
|
+
};
|
|
11552
11483
|
type PasskeyInfo = {
|
|
11553
11484
|
passkeyId: string;
|
|
11554
11485
|
passkeyKey?: string;
|
|
@@ -11814,6 +11745,7 @@ declare class EmbeddedWalletApi {
|
|
|
11814
11745
|
private getEntropy;
|
|
11815
11746
|
configure(params: EmbeddedAccountConfigureParams): Promise<EmbeddedAccount>;
|
|
11816
11747
|
create(params: EmbeddedAccountCreateParams): Promise<EmbeddedAccount>;
|
|
11748
|
+
import(params: EmbeddedAccountImportParams): Promise<EmbeddedAccount>;
|
|
11817
11749
|
recover(params: EmbeddedAccountRecoverParams): Promise<EmbeddedAccount>;
|
|
11818
11750
|
/**
|
|
11819
11751
|
* Signs a personal message using the configured signer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BackendApiClients as e}from"../../../packages/internal/openapi-clients/dist/index.js";import{ConfigurationError as r,AuthenticationError as t,SessionError as s,SignerError as a}from"../core/errors/openfortError.js";import{PasskeyHandler as i}from"../core/passkey/handler.js";import{SDKConfiguration as n}from"../core/config/config.js";import{Account as o}from"../core/configuration/account.js";import{Authentication as d}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as c}from"../core/errors/authErrorCodes.js";import{withApiError as h}from"../core/errors/withApiError.js";import{StorageKeys as m}from"../storage/istorage.js";import{OpenfortEvents as g,RecoveryMethod as y,ChainTypeEnum as l,AccountTypeEnum as p,EmbeddedState as f}from"../types/types.js";import{debugLog as u}from"../utils/debug.js";import{observe as w}from"../utils/observe.js";import{EmbeddedSigner as A}from"../wallets/embedded.js";import{EvmProvider as E}from"../wallets/evm/evmProvider.js";import"../wallets/evm/types.js";import{announceProvider as v,openfortProviderInfo as M}from"../wallets/evm/provider/eip6963.js";import{signMessage as D}from"../wallets/evm/walletHelpers.js";import{IframeManager as I}from"../wallets/iframeManager.js";import{ReactNativeMessenger as T}from"../wallets/messaging/ReactNativeMessenger.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import S from"../wallets/messaging/browserMessenger/messengers/WindowMessenger.js";class k{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,r,t,s,a){this.storage=e,this.validateAndRefreshToken=r,this.ensureInitialized=t,this.eventEmitter=s,this.passkeyHandler=a,this.eventEmitter.on(g.ON_LOGOUT,()=>{u("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const t=n.getInstance();if(!t)throw new r("Configuration not found");return new e({basePath:t.backendUrl,accessToken:t.baseConfiguration.publishableKey,nativeAppIdentifier:t.nativeAppIdentifier})}async getIframeManager(){if(u("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager?.hasFailed&&(u("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return u("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return u("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;u("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return u("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,u("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw u("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){u("[HANDSHAKE DEBUG] createIframeManager starting");const e=n.getInstance();if(!e)throw u("[HANDSHAKE DEBUG] Configuration not found"),new r("Configuration not found");let t;if(u("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)u("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(u("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new T(this.messagePoster),u("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),t=this.messenger;else{u("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const r=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;t=new S({remoteWindow:r.contentWindow,allowedOrigins:[s]}),u("[HANDSHAKE DEBUG] Created WindowMessenger")}return u("[HANDSHAKE DEBUG] Creating IframeManager instance"),new I(e,this.storage,t)}async ensureSigner(){if(this.iframeManager?.hasFailed&&(u("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();await e.initialize();return new A(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new r("Document is not available. Please provide a message poster for non-browser environments.");const t=document.getElementById("openfort-iframe");t&&t.remove();const s=document.createElement("iframe");return s.style.display="none",s.id="openfort-iframe",s.src=e,document.body.appendChild(s),s}async getPasskeyKey(e){const r=await d.fromStorage(this.storage);if(!r?.userId)throw new t("auth","User is required for passkey key derivation. Logout and login again.",401);return this.passkeyHandler.deriveAndExportKey({id:e,seed:r.userId})}async getEntropy(e){switch(e.recoveryMethod){case y.PASSWORD:return{recoveryPassword:e.password};case y.AUTOMATIC:return{encryptionSession:e.encryptionSession};case y.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new r("Invalid recovery method")}}async configure(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:y.AUTOMATIC},[t,s]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),a={chainId:e.chainId,entropy:s,accountType:e.accountType??p.SMART_ACCOUNT,chainType:e.chainType??l.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},i=await t.configure(a);return{id:i.id,chainId:i.chainId,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,factoryAddress:i.factoryAddress,salt:i.salt,createdAt:i.createdAt,implementationAddress:i.implementationAddress,recoveryMethod:o.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:y.AUTOMATIC},a=await d.fromStorage(this.storage);if(!a)throw new s(c.NOT_LOGGED_IN,"missing authentication");if(t.recoveryMethod===y.PASSKEY){if(!a.userId)throw new r("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:i.randomPasskeyName(),seed:a.userId});if(!e.key)throw new r("Passkey creation failed: no key material returned");t.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[n,h]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),m=await n.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:h}),l={id:m.id,chainId:m.chainId,address:m.address,ownerAddress:m.ownerAddress,chainType:m.chainType,accountType:m.accountType,implementationType:m.implementationType,factoryAddress:m.factoryAddress,salt:m.salt,createdAt:m.createdAt,implementationAddress:m.implementationAddress,recoveryMethod:o.parseRecoveryMethod(m.recoveryMethod),recoveryMethodDetails:m.recoveryMethodDetails};return this.eventEmitter.emit(g.ON_EMBEDDED_WALLET_CREATED,l),l}async recover(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:y.AUTOMATIC};if(t.recoveryMethod===y.PASSKEY){if(!t.passkeyInfo?.passkeyId)throw new r("Passkey ID must be provided for passkey recovery");t.passkeyInfo={passkeyId:t.passkeyInfo.passkeyId}}const[s,a]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),i=await s.recover({account:e.account,entropy:a}),n={id:i.id,chainId:i.chainId,implementationAddress:i.implementationAddress,factoryAddress:i.factoryAddress,salt:i.salt,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,createdAt:i.createdAt,recoveryMethod:o.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails};return this.eventEmitter.emit(g.ON_EMBEDDED_WALLET_RECOVERED,n),n}async signMessage(e,r){await this.validateAndRefreshToken();const t=await this.ensureSigner(),{hashMessage:s=!0,arrayifyMessage:a=!1}=r||{},i=await o.fromStorage(this.storage);return await t.sign(e,a,s,i?.chainType)}async signTypedData(e,r,t){await this.validateAndRefreshToken();const s=await this.ensureSigner(),i=await o.fromStorage(this.storage);if(!i)throw new a(c.MISSING_SIGNER,"No account found");const n={...r};delete n.EIP712Domain;const{_TypedDataEncoder:d}=await import("@ethersproject/hash"),h=d.hash(e,n,t);return await D({hash:h,implementationType:i.implementationType||i.type,chainId:Number(i.chainId),signer:s,address:i.address,ownerAddress:i.ownerAddress,factoryAddress:i.factoryAddress,salt:i.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,t){await this.validateAndRefreshToken();const a=await this.ensureSigner(),n=await d.fromStorage(this.storage);if(!n)throw new s(c.NOT_LOGGED_IN,"missing authentication");let h,m,g,l;if(e.recoveryMethod===y.PASSKEY){const e=await o.fromStorage(this.storage);if(!e)throw new r("missing account");const t=e?.recoveryMethodDetails?.passkeyId;if(!t)throw new r("missing passkey id for account");if(!n.userId)throw new r("User ID is required for passkey key derivation");g={passkeyId:t,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:t,seed:n.userId})}}else if(t.recoveryMethod===y.PASSKEY){if(!n.userId)throw new r("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:i.randomPasskeyName(),seed:n.userId});if(!e.key)throw new r("Passkey creation failed: no key material returned");g={passkeyId:e.id,passkeyKey:e.key},l={passkeyId:e.id}}if(e.recoveryMethod===y.PASSWORD?h=e.password:t.recoveryMethod===y.PASSWORD&&(h=t.password),e.recoveryMethod===y.AUTOMATIC?m=e.encryptionSession:t.recoveryMethod===y.AUTOMATIC&&(m=t.encryptionSession),!h&&!m)throw new r("Password or encryption session is not provided");await a.setRecoveryMethod({recoveryMethod:t.recoveryMethod,recoveryPassword:h,encryptionSession:m,passkeyInfo:g});const p=await o.fromStorage(this.storage);p&&new o({...p,recoveryMethod:t.recoveryMethod,recoveryMethodDetails:l}).save(this.storage)}async get(){await this.validateAndRefreshToken();const e=await o.fromStorage(this.storage);if(!e)throw new a(c.MISSING_SIGNER,"No signer configured");if(!await d.fromStorage(this.storage))throw new s(c.NOT_LOGGED_IN,"No access token found");return{id:e.id,chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:o.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){await this.validateAndRefreshToken();const t={...e},a=n.getInstance();if(!a)throw new r("Configuration not found");const i=await d.fromStorage(this.storage);if(!i)throw new s(c.NOT_LOGGED_IN,"No access token found");return await this.validateAndRefreshToken(),h(async()=>(await this.backendApiClients.accountsV2Api.getAccountsV2(t,{headers:i.thirdPartyProvider?{authorization:`Bearer ${a.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":a.baseConfiguration.publishableKey}})).data.data.map(e=>({chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:o.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{context:"list"})}async getEmbeddedState(){try{if(!await d.fromStorage(this.storage))return f.UNAUTHENTICATED;return await o.fromStorage(this.storage)?f.READY:f.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return u("Failed to get embedded state:",e),f.UNAUTHENTICATED}}watchEmbeddedState(e){return w("watchEmbeddedState",{onChange:e.onChange,onError:e.onError},r=>{let t;const s=async()=>{try{const e=await this.getEmbeddedState();t!==e&&(r.onChange?.(e,t),t=e)}catch(e){r.onError?.(e instanceof Error?e:new Error(String(e)))}};s();const a=()=>s(),i=()=>s(),n=()=>s(),o=()=>s();this.eventEmitter.on(g.ON_AUTH_SUCCESS,a),this.eventEmitter.on(g.ON_LOGOUT,i),this.eventEmitter.on(g.ON_EMBEDDED_WALLET_CREATED,n),this.eventEmitter.on(g.ON_EMBEDDED_WALLET_RECOVERED,o);const d=setInterval(s,e.pollingInterval??2e3);return()=>{clearInterval(d),this.eventEmitter.off(g.ON_AUTH_SUCCESS,a),this.eventEmitter.off(g.ON_LOGOUT,i),this.eventEmitter.off(g.ON_EMBEDDED_WALLET_CREATED,n),this.eventEmitter.off(g.ON_EMBEDDED_WALLET_RECOVERED,o)}})}async getEthereumProvider(e){await this.ensureInitialized();const r={announceProvider:!0,...e},t=await d.fromStorage(this.storage),s=await o.fromStorage(this.storage);return this.provider?this.provider&&r.feeSponsorship&&this.provider.updateFeeSponsorship(r.feeSponsorship):(this.provider=new E({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:s||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,feeSponsorshipId:r.feeSponsorship,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:r.chains}),r.announceProvider&&v({info:{...M,...r.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(r=>{setTimeout(r,e)});const r=await this.getIframeManager();if(!r.isLoaded())return!1;const t=await d.fromStorage(this.storage);if(t)try{return await r.getCurrentDevice(t.userId),!0}catch(e){return!1}return r.isLoaded()}catch(e){return u("Ping failed:",e),!1}}getURL(){const e=n.getInstance();if(!e)throw new r("Configuration not found");return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new r("Invalid message poster");this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){if(this.storage.remove(m.ACCOUNT),"undefined"==typeof document&&!this.messagePoster)return u("Skipping signer disconnect: no messagePoster available in non-browser environment"),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,void(this.signerPromise=null);try{const e=await this.ensureSigner();await e.disconnect()}catch{}this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void u("Invalid message received:",e);u("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const r="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(r&&this.messenger&&this.messagePoster)return u("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const t=await this.getIframeManager();u(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${t.isLoaded()}`),r&&!t.isLoaded()&&u("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),u("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await t.onMessage(e),u("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}}export{k as EmbeddedWalletApi};
|
|
1
|
+
import{BackendApiClients as e}from"../../../packages/internal/openapi-clients/dist/index.js";import{ConfigurationError as t,AuthenticationError as r,SessionError as s,SignerError as a}from"../core/errors/openfortError.js";import{PasskeyHandler as i}from"../core/passkey/handler.js";import{SDKConfiguration as n}from"../core/config/config.js";import{Account as o}from"../core/configuration/account.js";import{Authentication as d}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as c}from"../core/errors/authErrorCodes.js";import{withApiError as h}from"../core/errors/withApiError.js";import{StorageKeys as m}from"../storage/istorage.js";import{OpenfortEvents as y,RecoveryMethod as g,ChainTypeEnum as l,AccountTypeEnum as p,EmbeddedState as f}from"../types/types.js";import{debugLog as u}from"../utils/debug.js";import{observe as w}from"../utils/observe.js";import{EmbeddedSigner as A}from"../wallets/embedded.js";import{EvmProvider as E}from"../wallets/evm/evmProvider.js";import"../wallets/evm/types.js";import{announceProvider as v,openfortProviderInfo as M}from"../wallets/evm/provider/eip6963.js";import{signMessage as T}from"../wallets/evm/walletHelpers.js";import{IframeManager as D}from"../wallets/iframeManager.js";import{ReactNativeMessenger as I}from"../wallets/messaging/ReactNativeMessenger.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import S from"../wallets/messaging/browserMessenger/messengers/WindowMessenger.js";class k{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,t,r,s,a){this.storage=e,this.validateAndRefreshToken=t,this.ensureInitialized=r,this.eventEmitter=s,this.passkeyHandler=a,this.eventEmitter.on(y.ON_LOGOUT,()=>{u("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const r=n.getInstance();if(!r)throw new t("Configuration not found");return new e({basePath:r.backendUrl,accessToken:r.baseConfiguration.publishableKey,nativeAppIdentifier:r.nativeAppIdentifier})}async getIframeManager(){if(u("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager?.hasFailed&&(u("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return u("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return u("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;u("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return u("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,u("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw u("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){u("[HANDSHAKE DEBUG] createIframeManager starting");const e=n.getInstance();if(!e)throw u("[HANDSHAKE DEBUG] Configuration not found"),new t("Configuration not found");let r;if(u("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)u("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(u("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new I(this.messagePoster),u("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),r=this.messenger;else{u("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const t=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;r=new S({remoteWindow:t.contentWindow,allowedOrigins:[s]}),u("[HANDSHAKE DEBUG] Created WindowMessenger")}return u("[HANDSHAKE DEBUG] Creating IframeManager instance"),new D(e,this.storage,r)}async ensureSigner(){if(this.iframeManager?.hasFailed&&(u("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();await e.initialize();return new A(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new t("Document is not available. Please provide a message poster for non-browser environments.");const r=document.getElementById("openfort-iframe");r&&r.remove();const s=document.createElement("iframe");return s.style.display="none",s.id="openfort-iframe",s.src=e,document.body.appendChild(s),s}async getPasskeyKey(e){const t=await d.fromStorage(this.storage);if(!t?.userId)throw new r("auth","User is required for passkey key derivation. Logout and login again.",401);return this.passkeyHandler.deriveAndExportKey({id:e,seed:t.userId})}async getEntropy(e){switch(e.recoveryMethod){case g.PASSWORD:return{recoveryPassword:e.password};case g.AUTOMATIC:return{encryptionSession:e.encryptionSession};case g.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new t("Invalid recovery method")}}async configure(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:g.AUTOMATIC},[r,s]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),a={chainId:e.chainId,entropy:s,accountType:e.accountType??p.SMART_ACCOUNT,chainType:e.chainType??l.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},i=await r.configure(a);return{id:i.id,chainId:i.chainId,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,factoryAddress:i.factoryAddress,salt:i.salt,createdAt:i.createdAt,implementationAddress:i.implementationAddress,recoveryMethod:o.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:g.AUTOMATIC},a=await d.fromStorage(this.storage);if(!a)throw new s(c.NOT_LOGGED_IN,"missing authentication");if(r.recoveryMethod===g.PASSKEY){if(!a.userId)throw new t("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:i.randomPasskeyName(),seed:a.userId});if(!e.key)throw new t("Passkey creation failed: no key material returned");r.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[n,h]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),m=await n.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:h}),l={id:m.id,chainId:m.chainId,address:m.address,ownerAddress:m.ownerAddress,chainType:m.chainType,accountType:m.accountType,implementationType:m.implementationType,factoryAddress:m.factoryAddress,salt:m.salt,createdAt:m.createdAt,implementationAddress:m.implementationAddress,recoveryMethod:o.parseRecoveryMethod(m.recoveryMethod),recoveryMethodDetails:m.recoveryMethodDetails};return this.eventEmitter.emit(y.ON_EMBEDDED_WALLET_CREATED,l),l}async import(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:g.AUTOMATIC},a=await d.fromStorage(this.storage);if(!a)throw new s(c.NOT_LOGGED_IN,"missing authentication");if(r.recoveryMethod===g.PASSKEY){if(!a.userId)throw new t("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:i.randomPasskeyName(),seed:a.userId});if(!e.key)throw new t("Passkey creation failed: no key material returned");r.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[n,h]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),m=await n.import({privateKey:e.privateKey,accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:h}),l={id:m.id,chainId:m.chainId,address:m.address,ownerAddress:m.ownerAddress,chainType:m.chainType,accountType:m.accountType,implementationType:m.implementationType,factoryAddress:m.factoryAddress,salt:m.salt,createdAt:m.createdAt,implementationAddress:m.implementationAddress,recoveryMethod:o.parseRecoveryMethod(m.recoveryMethod),recoveryMethodDetails:m.recoveryMethodDetails};return this.eventEmitter.emit(y.ON_EMBEDDED_WALLET_CREATED,l),l}async recover(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:g.AUTOMATIC};if(r.recoveryMethod===g.PASSKEY){if(!r.passkeyInfo?.passkeyId)throw new t("Passkey ID must be provided for passkey recovery");r.passkeyInfo={passkeyId:r.passkeyInfo.passkeyId}}const[s,a]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),i=await s.recover({account:e.account,entropy:a}),n={id:i.id,chainId:i.chainId,implementationAddress:i.implementationAddress,factoryAddress:i.factoryAddress,salt:i.salt,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,createdAt:i.createdAt,recoveryMethod:o.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails};return this.eventEmitter.emit(y.ON_EMBEDDED_WALLET_RECOVERED,n),n}async signMessage(e,t){await this.validateAndRefreshToken();const r=await this.ensureSigner(),{hashMessage:s=!0,arrayifyMessage:a=!1}=t||{},i=await o.fromStorage(this.storage);return await r.sign(e,a,s,i?.chainType)}async signTypedData(e,t,r){await this.validateAndRefreshToken();const s=await this.ensureSigner(),i=await o.fromStorage(this.storage);if(!i)throw new a(c.MISSING_SIGNER,"No account found");const n={...t};delete n.EIP712Domain;const{_TypedDataEncoder:d}=await import("@ethersproject/hash"),h=d.hash(e,n,r);return await T({hash:h,implementationType:i.implementationType||i.type,chainId:Number(i.chainId),signer:s,address:i.address,ownerAddress:i.ownerAddress,factoryAddress:i.factoryAddress,salt:i.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,r){await this.validateAndRefreshToken();const a=await this.ensureSigner(),n=await d.fromStorage(this.storage);if(!n)throw new s(c.NOT_LOGGED_IN,"missing authentication");let h,m,y,l;if(e.recoveryMethod===g.PASSKEY){const e=await o.fromStorage(this.storage);if(!e)throw new t("missing account");const r=e?.recoveryMethodDetails?.passkeyId;if(!r)throw new t("missing passkey id for account");if(!n.userId)throw new t("User ID is required for passkey key derivation");y={passkeyId:r,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:r,seed:n.userId})}}else if(r.recoveryMethod===g.PASSKEY){if(!n.userId)throw new t("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:i.randomPasskeyName(),seed:n.userId});if(!e.key)throw new t("Passkey creation failed: no key material returned");y={passkeyId:e.id,passkeyKey:e.key},l={passkeyId:e.id}}if(e.recoveryMethod===g.PASSWORD?h=e.password:r.recoveryMethod===g.PASSWORD&&(h=r.password),e.recoveryMethod===g.AUTOMATIC?m=e.encryptionSession:r.recoveryMethod===g.AUTOMATIC&&(m=r.encryptionSession),!h&&!m)throw new t("Password or encryption session is not provided");await a.setRecoveryMethod({recoveryMethod:r.recoveryMethod,recoveryPassword:h,encryptionSession:m,passkeyInfo:y});const p=await o.fromStorage(this.storage);p&&new o({...p,recoveryMethod:r.recoveryMethod,recoveryMethodDetails:l}).save(this.storage)}async get(){await this.validateAndRefreshToken();const e=await o.fromStorage(this.storage);if(!e)throw new a(c.MISSING_SIGNER,"No signer configured");if(!await d.fromStorage(this.storage))throw new s(c.NOT_LOGGED_IN,"No access token found");return{id:e.id,chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:o.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){await this.validateAndRefreshToken();const r={...e},a=n.getInstance();if(!a)throw new t("Configuration not found");const i=await d.fromStorage(this.storage);if(!i)throw new s(c.NOT_LOGGED_IN,"No access token found");return await this.validateAndRefreshToken(),h(async()=>(await this.backendApiClients.accountsV2Api.getAccountsV2(r,{headers:i.thirdPartyProvider?{authorization:`Bearer ${a.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":a.baseConfiguration.publishableKey}})).data.data.map(e=>({chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:o.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{context:"list"})}async getEmbeddedState(){try{if(!await d.fromStorage(this.storage))return f.UNAUTHENTICATED;return await o.fromStorage(this.storage)?f.READY:f.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return u("Failed to get embedded state:",e),f.UNAUTHENTICATED}}watchEmbeddedState(e){return w("watchEmbeddedState",{onChange:e.onChange,onError:e.onError},t=>{let r;const s=async()=>{try{const e=await this.getEmbeddedState();r!==e&&(t.onChange?.(e,r),r=e)}catch(e){t.onError?.(e instanceof Error?e:new Error(String(e)))}};s();const a=()=>s(),i=()=>s(),n=()=>s(),o=()=>s();this.eventEmitter.on(y.ON_AUTH_SUCCESS,a),this.eventEmitter.on(y.ON_LOGOUT,i),this.eventEmitter.on(y.ON_EMBEDDED_WALLET_CREATED,n),this.eventEmitter.on(y.ON_EMBEDDED_WALLET_RECOVERED,o);const d=setInterval(s,e.pollingInterval??2e3);return()=>{clearInterval(d),this.eventEmitter.off(y.ON_AUTH_SUCCESS,a),this.eventEmitter.off(y.ON_LOGOUT,i),this.eventEmitter.off(y.ON_EMBEDDED_WALLET_CREATED,n),this.eventEmitter.off(y.ON_EMBEDDED_WALLET_RECOVERED,o)}})}async getEthereumProvider(e){await this.ensureInitialized();const t={announceProvider:!0,...e},r=await d.fromStorage(this.storage),s=await o.fromStorage(this.storage);return this.provider?this.provider&&t.feeSponsorship&&this.provider.updateFeeSponsorship(t.feeSponsorship):(this.provider=new E({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:s||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,feeSponsorshipId:t.feeSponsorship,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:t.chains}),t.announceProvider&&v({info:{...M,...t.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(t=>{setTimeout(t,e)});const t=await this.getIframeManager();if(!t.isLoaded())return!1;const r=await d.fromStorage(this.storage);if(r)try{return await t.getCurrentDevice(r.userId),!0}catch(e){return!1}return t.isLoaded()}catch(e){return u("Ping failed:",e),!1}}getURL(){const e=n.getInstance();if(!e)throw new t("Configuration not found");return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new t("Invalid message poster");this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){if(this.storage.remove(m.ACCOUNT),"undefined"==typeof document&&!this.messagePoster)return u("Skipping signer disconnect: no messagePoster available in non-browser environment"),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,void(this.signerPromise=null);try{const e=await this.ensureSigner();await e.disconnect()}catch{}this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void u("Invalid message received:",e);u("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const t="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(t&&this.messenger&&this.messagePoster)return u("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const r=await this.getIframeManager();u(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${r.isLoaded()}`),t&&!r.isLoaded()&&u("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),u("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await r.onMessage(e),u("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}}export{k as EmbeddedWalletApi};
|