@ledgerhq/revault-sdk 0.24.1 → 0.25.1
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/bake.cjs +1219 -1025
- package/lib/bake.cjs.map +1 -1
- package/lib/bake.d.cts +572 -548
- package/lib/bake.d.ts +572 -548
- package/lib/bake.js +1209 -1025
- package/lib/bake.js.map +1 -1
- package/lib/chunk-CKQMccvm.cjs +28 -0
- package/lib/crypto-BDBF_rfw.cjs +268 -0
- package/lib/crypto-BDBF_rfw.cjs.map +1 -0
- package/lib/crypto-CPCBrCSZ.js +245 -0
- package/lib/crypto-CPCBrCSZ.js.map +1 -0
- package/lib/crypto.cjs +5 -11
- package/lib/crypto.d.cts +10 -7
- package/lib/crypto.d.ts +10 -7
- package/lib/crypto.js +2 -11
- package/lib/device-0lcfYGHr.cjs +793 -0
- package/lib/device-0lcfYGHr.cjs.map +1 -0
- package/lib/device-B8Fww8_6.js +719 -0
- package/lib/device-B8Fww8_6.js.map +1 -0
- package/lib/device.cjs +6 -13
- package/lib/device.d.cts +2 -50
- package/lib/device.d.ts +2 -50
- package/lib/device.js +2 -13
- package/lib/engine.cjs +835 -886
- package/lib/engine.cjs.map +1 -1
- package/lib/engine.d.cts +3 -25
- package/lib/engine.d.ts +3 -25
- package/lib/engine.js +828 -885
- package/lib/engine.js.map +1 -1
- package/lib/index--fscLDTT.d.ts +237 -0
- package/lib/index-BE7oUpCb.d.cts +237 -0
- package/lib/index-C4Xjiv0k.d.cts +23 -0
- package/lib/index-CVjhPoZh.d.ts +23 -0
- package/lib/index.cjs +0 -1
- package/lib/index.d.cts +10 -5
- package/lib/index.d.ts +10 -5
- package/lib/index.js +1 -1
- package/lib/logger-Cme0iL1f.d.cts +10 -0
- package/lib/logger-DWLViq7U.d.ts +10 -0
- package/lib/onboarding.cjs +179 -181
- package/lib/onboarding.cjs.map +1 -1
- package/lib/onboarding.d.cts +1751 -1722
- package/lib/onboarding.d.ts +1751 -1722
- package/lib/onboarding.js +175 -181
- package/lib/onboarding.js.map +1 -1
- package/lib/trpc-CWGPr8Ox.d.ts +20 -0
- package/lib/trpc-C_dUOB1u.d.cts +20 -0
- package/lib/types-4CfR5--z.d.ts +203 -0
- package/lib/types-Byf9V35t.d.cts +203 -0
- package/lib/types-CQROu0nu.d.cts +6 -0
- package/lib/types-_QeBv1U4.d.ts +6 -0
- package/lib/types.cjs +0 -1
- package/lib/types.d.cts +3 -4
- package/lib/types.d.ts +3 -4
- package/lib/types.js +1 -1
- package/lib/utils-BGbdjOP9.js +61 -0
- package/lib/utils-BGbdjOP9.js.map +1 -0
- package/lib/utils-DbSFXp4c.cjs +86 -0
- package/lib/utils-DbSFXp4c.cjs.map +1 -0
- package/package.json +23 -23
- package/lib/chunk-2WGM7EWA.cjs +0 -282
- package/lib/chunk-2WGM7EWA.cjs.map +0 -1
- package/lib/chunk-AXI72NFY.js +0 -50
- package/lib/chunk-AXI72NFY.js.map +0 -1
- package/lib/chunk-EBMIZ52H.cjs +0 -814
- package/lib/chunk-EBMIZ52H.cjs.map +0 -1
- package/lib/chunk-KV5FO7N5.js +0 -282
- package/lib/chunk-KV5FO7N5.js.map +0 -1
- package/lib/chunk-LH4QQXUH.cjs +0 -50
- package/lib/chunk-LH4QQXUH.cjs.map +0 -1
- package/lib/chunk-XQ4BT4HB.js +0 -814
- package/lib/chunk-XQ4BT4HB.js.map +0 -1
- package/lib/crypto.cjs.map +0 -1
- package/lib/crypto.js.map +0 -1
- package/lib/device.cjs.map +0 -1
- package/lib/device.js.map +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/logger-C-TPbnjv.d.cts +0 -9
- package/lib/logger-C-TPbnjv.d.ts +0 -9
- package/lib/types-C-ngtI5m.d.ts +0 -202
- package/lib/types-CpGEbAxh.d.cts +0 -19
- package/lib/types-CpGEbAxh.d.ts +0 -19
- package/lib/types-CryvY9pW.d.cts +0 -202
- package/lib/types-DJfbanPz.d.cts +0 -167
- package/lib/types-DJfbanPz.d.ts +0 -167
- package/lib/types.cjs.map +0 -1
- package/lib/types.js.map +0 -1
package/lib/engine.cjs
CHANGED
|
@@ -1,899 +1,848 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var _chunkEBMIZ52Hcjs = require('./chunk-EBMIZ52H.cjs');
|
|
21
|
-
|
|
22
|
-
// src/engine/index.ts
|
|
23
|
-
var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant);
|
|
24
|
-
|
|
25
|
-
// src/device/real-device.ts
|
|
26
|
-
|
|
27
|
-
var _rxjs = require('rxjs');
|
|
28
|
-
var MAX_CHUNK_LENGTH = 250;
|
|
29
|
-
var getPathFromPathString = (pathString) => {
|
|
30
|
-
const parts = pathString.split("'/").map((part) => Number.parseInt(part, 10));
|
|
31
|
-
return parts.map((part) => (part | 2147483648) >>> 0);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("./chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_device = require("./device-0lcfYGHr.cjs");
|
|
4
|
+
const require_utils = require("./utils-DbSFXp4c.cjs");
|
|
5
|
+
let invariant = require("invariant");
|
|
6
|
+
invariant = require_chunk.__toESM(invariant);
|
|
7
|
+
let rxjs = require("rxjs");
|
|
8
|
+
let _trpc_client = require("@trpc/client");
|
|
9
|
+
let superjson = require("superjson");
|
|
10
|
+
superjson = require_chunk.__toESM(superjson);
|
|
11
|
+
//#region src/device/real-device.ts
|
|
12
|
+
const MAX_CHUNK_LENGTH = 250;
|
|
13
|
+
const getPathFromPathString = (pathString) => {
|
|
14
|
+
return pathString.split("'/").map((part) => Number.parseInt(part, 10)).map((part) => (part | 2147483648) >>> 0);
|
|
32
15
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return chunks;
|
|
16
|
+
const splitChunks = (chunk, buffer) => {
|
|
17
|
+
const chunks = [];
|
|
18
|
+
for (let i = 0, size = chunk; i < buffer.length; i += size, size = chunk) chunks.push(buffer.slice(i, i + size));
|
|
19
|
+
return chunks;
|
|
39
20
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return response;
|
|
21
|
+
const removeStatus = (result) => result.slice(0, result.length - 2);
|
|
22
|
+
const sendByChunk = async (transport, command, data, chunkSize = MAX_CHUNK_LENGTH) => {
|
|
23
|
+
const chunks = splitChunks(chunkSize, data);
|
|
24
|
+
let response = Buffer.from([]);
|
|
25
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
26
|
+
const chunk = chunks[i];
|
|
27
|
+
const apdu = [...command];
|
|
28
|
+
/* v8 ignore next -- @preserve */
|
|
29
|
+
apdu[2] = i && 128;
|
|
30
|
+
response = await transport.send(apdu[0], apdu[1], apdu[2], apdu[3], chunk, [36864, ...require_device.PAGINATED_STATUS]);
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
54
33
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return toSend;
|
|
34
|
+
const buildAttestation = (params) => {
|
|
35
|
+
const sigBuffer = Buffer.from(params.handshakeAttestation.signature, "base64");
|
|
36
|
+
const sigLengthBuffer = Buffer.alloc(1);
|
|
37
|
+
sigLengthBuffer.writeUIntBE(sigBuffer.length, 0, 1);
|
|
38
|
+
const certBuffer = Buffer.from(params.handshakeAttestation.certificate, "base64");
|
|
39
|
+
const certLengthBuffer = Buffer.alloc(1);
|
|
40
|
+
certLengthBuffer.writeUIntBE(certBuffer.length, 0, 1);
|
|
41
|
+
const pubBuffer = Buffer.from(params.handshakeAttestation.attestationPub, "base64");
|
|
42
|
+
const certChainData = Buffer.concat([
|
|
43
|
+
sigLengthBuffer,
|
|
44
|
+
sigBuffer,
|
|
45
|
+
pubBuffer,
|
|
46
|
+
certLengthBuffer,
|
|
47
|
+
certBuffer
|
|
48
|
+
]);
|
|
49
|
+
const cliMsgBuffer = Buffer.from(params.handshake, "hex");
|
|
50
|
+
const cliMsgLengthBuffer = Buffer.alloc(1);
|
|
51
|
+
cliMsgLengthBuffer.writeUIntBE(cliMsgBuffer.length, 0, 1);
|
|
52
|
+
const pidBuffer = Buffer.from(params.partitionId, "hex");
|
|
53
|
+
const pidLengthBuffer = Buffer.alloc(1);
|
|
54
|
+
pidLengthBuffer.writeUIntBE(pidBuffer.length, 0, 1);
|
|
55
|
+
const certChainDataLengthBuff = Buffer.alloc(2);
|
|
56
|
+
certChainDataLengthBuff.writeUInt16BE(certChainData.length, 0);
|
|
57
|
+
const data = Buffer.concat([
|
|
58
|
+
cliMsgLengthBuffer,
|
|
59
|
+
cliMsgBuffer,
|
|
60
|
+
certChainDataLengthBuff,
|
|
61
|
+
certChainData,
|
|
62
|
+
pidLengthBuffer,
|
|
63
|
+
pidBuffer
|
|
64
|
+
]);
|
|
65
|
+
const totalLengthBuffer = Buffer.alloc(2);
|
|
66
|
+
totalLengthBuffer.writeUInt16BE(data.length, 0);
|
|
67
|
+
return Buffer.concat([totalLengthBuffer, data]);
|
|
90
68
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
/* v8 ignore next -- @preserve */
|
|
70
|
+
const genericRetryOnError = (err) => {
|
|
71
|
+
if (err instanceof require_device.LockedDeviceError) return true;
|
|
72
|
+
if (require_device.isTransportStatusError(err) && err.statusCode === 27913) return true;
|
|
73
|
+
if (err instanceof require_device.DisconnectedDevice) return true;
|
|
74
|
+
return false;
|
|
96
75
|
};
|
|
97
76
|
function createRealDevice(options, logger) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
77
|
+
const { transportId } = options;
|
|
78
|
+
async function run(job, retryOnError = genericRetryOnError) {
|
|
79
|
+
return (0, rxjs.lastValueFrom)(require_device.withDevicePolling(transportId)((transport) => (0, rxjs.from)(job(transport)), retryOnError));
|
|
80
|
+
}
|
|
81
|
+
/* v8 ignore next -- @preserve */
|
|
82
|
+
const noRetry = () => false;
|
|
83
|
+
/* v8 ignore next -- @preserve */
|
|
84
|
+
const alwaysRetry = () => true;
|
|
85
|
+
const poll = async (opts = {}) => {
|
|
86
|
+
await run(async (_transport) => {}, opts.retryOnError ?? alwaysRetry);
|
|
87
|
+
try {
|
|
88
|
+
await getPublicKey(require_device.PATHS.U2F, {
|
|
89
|
+
secp256k1: true,
|
|
90
|
+
retryOnError: noRetry
|
|
91
|
+
});
|
|
92
|
+
return { isAppOpened: true };
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (require_device.isTransportStatusError(err) && genericRetryOnError(err)) return { isAppOpened: false };
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const pollApp = async (appName) => {
|
|
99
|
+
const res = await run((transport) => transport.send(224, 216, 0, 0, Buffer.from(appName, "utf8")));
|
|
100
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
101
|
+
return res.toString("hex");
|
|
102
|
+
};
|
|
103
|
+
const getPublicKey = async (pathString, { secp256k1, retryOnError }) => {
|
|
104
|
+
logger.info(`[device] getPublicKey (${pathString})`);
|
|
105
|
+
const path = getPathFromPathString(pathString);
|
|
106
|
+
const data = Buffer.concat([Buffer.from([path.length]), ...path.map((derivation) => {
|
|
107
|
+
const buf = Buffer.alloc(4);
|
|
108
|
+
buf.writeUInt32BE(derivation, 0);
|
|
109
|
+
return buf;
|
|
110
|
+
})]);
|
|
111
|
+
const curve = secp256k1 ? 1 : 2;
|
|
112
|
+
const response = await run((transport) => transport.send(224, 64, curve, 0, data), retryOnError ?? genericRetryOnError);
|
|
113
|
+
const pubKeyLength = response.readInt8(0);
|
|
114
|
+
return {
|
|
115
|
+
pubKey: response.slice(1, pubKeyLength + 1).toString("hex").toUpperCase(),
|
|
116
|
+
signature: response.slice(pubKeyLength + 1, response.length - 2).toString("base64")
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
authenticate: async ({ challenge: { challenge, name, role, keyHandle }, workspaceName }) => {
|
|
121
|
+
logger.info(`[device] Authenticate`);
|
|
122
|
+
(0, invariant.default)(role !== "READ_ONLY_API_KEY", "Invalid role for authenticate: READ_ONLY_API_KEY");
|
|
123
|
+
const applicationBuffer = Buffer.from(require_device.APPID_VAULT_ADMINISTRATOR, "hex");
|
|
124
|
+
const nameBuffer = Buffer.from(name);
|
|
125
|
+
const workspaceBuffer = Buffer.from(workspaceName);
|
|
126
|
+
const keyHandleData = Buffer.concat([
|
|
127
|
+
Buffer.from(require_device.STR_ROLES[role], "hex"),
|
|
128
|
+
Buffer.from([nameBuffer.length]),
|
|
129
|
+
nameBuffer,
|
|
130
|
+
Buffer.from([workspaceBuffer.length]),
|
|
131
|
+
workspaceBuffer
|
|
132
|
+
]);
|
|
133
|
+
const keyHandleDataLength = Buffer.alloc(2);
|
|
134
|
+
keyHandleDataLength.writeUInt16BE(keyHandleData.length, 0);
|
|
135
|
+
const data = Buffer.concat([
|
|
136
|
+
Buffer.from(challenge, "base64"),
|
|
137
|
+
applicationBuffer,
|
|
138
|
+
Buffer.from([keyHandle.length]),
|
|
139
|
+
Buffer.from(keyHandle, "hex"),
|
|
140
|
+
keyHandleDataLength,
|
|
141
|
+
keyHandleData
|
|
142
|
+
]);
|
|
143
|
+
return removeStatus(await run((transport) => sendByChunk(transport, [
|
|
144
|
+
224,
|
|
145
|
+
2,
|
|
146
|
+
0,
|
|
147
|
+
0
|
|
148
|
+
], data))).toString("hex");
|
|
149
|
+
},
|
|
150
|
+
finalizePairingHandshake: async (params) => {
|
|
151
|
+
return removeStatus(await run((transport) => sendByChunk(transport, [
|
|
152
|
+
224,
|
|
153
|
+
71,
|
|
154
|
+
0,
|
|
155
|
+
2
|
|
156
|
+
], buildAttestation(params)))).toString("hex");
|
|
157
|
+
},
|
|
158
|
+
generateSeedFragment: async () => {
|
|
159
|
+
logger.info(`[device] generateSeedFragment`);
|
|
160
|
+
const path = getPathFromPathString(require_device.PATHS.KEY_MATERIAL);
|
|
161
|
+
const data = Buffer.concat([Buffer.from([path.length]), ...path.map((derivation) => {
|
|
162
|
+
const buf = Buffer.alloc(4);
|
|
163
|
+
buf.writeUInt32BE(derivation, 0);
|
|
164
|
+
return buf;
|
|
165
|
+
})]);
|
|
166
|
+
return removeStatus(await run((transport) => transport.send(224, 68, 0, 0, data))).toString("base64");
|
|
167
|
+
},
|
|
168
|
+
generateWrappingKeyFragment: async () => {
|
|
169
|
+
logger.info(`[device] generateWrappingKeyFragment`);
|
|
170
|
+
const path = getPathFromPathString(require_device.PATHS.KEY_MATERIAL);
|
|
171
|
+
const data = Buffer.concat([Buffer.from([path.length]), ...path.map((derivation) => {
|
|
172
|
+
const buf = Buffer.alloc(4);
|
|
173
|
+
buf.writeUInt32BE(derivation, 0);
|
|
174
|
+
return buf;
|
|
175
|
+
})]);
|
|
176
|
+
return removeStatus(await run((transport) => transport.send(224, 68, 1, 0, data))).toString("base64");
|
|
177
|
+
},
|
|
178
|
+
getAttestation: async () => {
|
|
179
|
+
const buffer = removeStatus(await run((transport) => transport.send(224, 65, 0, 0)));
|
|
180
|
+
const certLen = buffer.readInt8(98);
|
|
181
|
+
return {
|
|
182
|
+
attestation: {
|
|
183
|
+
codeHash: buffer.slice(0, 32).toString("base64"),
|
|
184
|
+
attestationPub: buffer.slice(32, 97).toString("base64"),
|
|
185
|
+
certificate: buffer.slice(97, 99 + certLen).toString("base64")
|
|
186
|
+
},
|
|
187
|
+
buffer
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
getConfidentialityKey: async () => {
|
|
191
|
+
logger.info(`[device] getConfidentialityKey`);
|
|
192
|
+
const buf = removeStatus(await run((transport) => transport.send(224, 77, 0, 0)));
|
|
193
|
+
const keyLength = buf[0];
|
|
194
|
+
const key = buf.slice(1, 1 + keyLength);
|
|
195
|
+
const sig = buf.slice(1 + keyLength + 1);
|
|
196
|
+
return {
|
|
197
|
+
confidentialityKeyCurve25519: key.toString("hex"),
|
|
198
|
+
confidentialityKeySignature: sig.toString("hex")
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
getConfidentialityPubKey: () => getPublicKey(require_device.PATHS.CONFIDENTIALITY, { secp256k1: true }),
|
|
202
|
+
getDeviceUserId: async () => {
|
|
203
|
+
logger.info(`[device] getDeviceUserId`);
|
|
204
|
+
return removeStatus(await run((transport) => transport.send(224, 82, 0, 0))).toString("hex").toUpperCase();
|
|
205
|
+
},
|
|
206
|
+
getU2FPubKey: () => getPublicKey(require_device.PATHS.U2F, { secp256k1: false }),
|
|
207
|
+
getValidationPubKey: () => getPublicKey(require_device.PATHS.VALIDATION, { secp256k1: true }),
|
|
208
|
+
hasPairing: async () => {
|
|
209
|
+
logger.info(`[device] hasPairing`);
|
|
210
|
+
const apdu = [
|
|
211
|
+
224,
|
|
212
|
+
81,
|
|
213
|
+
0,
|
|
214
|
+
0,
|
|
215
|
+
181
|
|
216
|
+
];
|
|
217
|
+
const res = await run((transport) => transport.exchange(Buffer.from(apdu)));
|
|
218
|
+
const hex = Buffer.from(res).toString("hex");
|
|
219
|
+
return hex !== "6f45" && hex !== "6a87";
|
|
220
|
+
},
|
|
221
|
+
initPairingHandshake: async () => {
|
|
222
|
+
const res = await run((transport) => transport.send(224, 70, 0, 0));
|
|
223
|
+
const pubKeyLength = res.readInt8(0);
|
|
224
|
+
return {
|
|
225
|
+
pubKey: res.slice(1, pubKeyLength + 1).toString("hex").toUpperCase(),
|
|
226
|
+
signature: res.slice(pubKeyLength + 1, res.length - 2).toString("base64")
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
openSession: async (params) => {
|
|
230
|
+
logger.info(`[device] openSession`);
|
|
231
|
+
const { secureChannel } = params;
|
|
232
|
+
const path = getPathFromPathString(require_device.PATHS.CONFIDENTIALITY);
|
|
233
|
+
const dataDerivation = Buffer.concat([Buffer.from([path.length]), ...path.map((derivation) => {
|
|
234
|
+
const buf = Buffer.alloc(4);
|
|
235
|
+
buf.writeUInt32BE(derivation, 0);
|
|
236
|
+
return buf;
|
|
237
|
+
})]);
|
|
238
|
+
const pubKey = Buffer.from(secureChannel.pubKey, "hex");
|
|
239
|
+
const sigBuffer = Buffer.from(secureChannel.certificate.signature, "base64");
|
|
240
|
+
const attestationPubBuffer = Buffer.from(secureChannel.certificate.attestationPub, "base64");
|
|
241
|
+
const certBuffer = Buffer.from(secureChannel.certificate.certificate, "base64");
|
|
242
|
+
const attestation = Buffer.concat([
|
|
243
|
+
Buffer.from([sigBuffer.length]),
|
|
244
|
+
sigBuffer,
|
|
245
|
+
attestationPubBuffer,
|
|
246
|
+
Buffer.from([certBuffer.length]),
|
|
247
|
+
certBuffer
|
|
248
|
+
]);
|
|
249
|
+
const lengthAttestation = Buffer.alloc(2);
|
|
250
|
+
lengthAttestation.writeUInt16BE(attestation.length, 0);
|
|
251
|
+
const data = Buffer.concat([
|
|
252
|
+
dataDerivation,
|
|
253
|
+
pubKey,
|
|
254
|
+
lengthAttestation,
|
|
255
|
+
attestation
|
|
256
|
+
]);
|
|
257
|
+
await run((transport) => sendByChunk(transport, [
|
|
258
|
+
224,
|
|
259
|
+
66,
|
|
260
|
+
0,
|
|
261
|
+
require_device.SCRIPT_IDS.INIT_SESSION
|
|
262
|
+
], data));
|
|
263
|
+
},
|
|
264
|
+
register: async (params) => {
|
|
265
|
+
const { challenge: strChallenge, u2fRegisterData: _, name, role } = params;
|
|
266
|
+
const challenge = Buffer.from(strChallenge, "hex");
|
|
267
|
+
(0, invariant.default)(challenge.length === 32, "challenge hex is expected to have 32 bytes");
|
|
268
|
+
const applicationBuf = Buffer.from(require_device.APPID_VAULT_ADMINISTRATOR, "hex");
|
|
269
|
+
(0, invariant.default)(applicationBuf.length === 32, "application hex is expected to have 32 bytes");
|
|
270
|
+
const userNameBuff = Buffer.from(name);
|
|
271
|
+
const keyHandleData = Buffer.concat([
|
|
272
|
+
Buffer.from(require_device.STR_ROLES[role], "hex"),
|
|
273
|
+
Buffer.from([userNameBuff.length]),
|
|
274
|
+
userNameBuff
|
|
275
|
+
]);
|
|
276
|
+
const keyHandleDataLength = Buffer.alloc(2);
|
|
277
|
+
keyHandleDataLength.writeUInt16BE(keyHandleData.length, 0);
|
|
278
|
+
const data = Buffer.concat([
|
|
279
|
+
challenge,
|
|
280
|
+
applicationBuf,
|
|
281
|
+
keyHandleDataLength,
|
|
282
|
+
keyHandleData
|
|
283
|
+
]);
|
|
284
|
+
const response = await run((transport) => sendByChunk(transport, [
|
|
285
|
+
224,
|
|
286
|
+
1,
|
|
287
|
+
0,
|
|
288
|
+
0
|
|
289
|
+
], data));
|
|
290
|
+
let i = 0;
|
|
291
|
+
const rfu = response.slice(i, i + 1)[0];
|
|
292
|
+
i += 1;
|
|
293
|
+
const pubKey = response.slice(i, i + 65).toString("hex");
|
|
294
|
+
i += 65;
|
|
295
|
+
const keyHandleLength = response.slice(i, i + 1)[0];
|
|
296
|
+
i++;
|
|
297
|
+
const keyHandle = response.slice(i, i + keyHandleLength);
|
|
298
|
+
i += keyHandleLength;
|
|
299
|
+
return {
|
|
300
|
+
u2fRegister: removeStatus(response),
|
|
301
|
+
keyHandle,
|
|
302
|
+
rfu,
|
|
303
|
+
pubKey
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
registerData: async (params) => {
|
|
307
|
+
const { challenge: strChallenge } = params;
|
|
308
|
+
const challenge = Buffer.from(strChallenge, "hex");
|
|
309
|
+
(0, invariant.default)(challenge.length === 32, "challenge hex is expected to have 32 bytes");
|
|
310
|
+
return removeStatus(await run((transport) => transport.send(224, 3, 0, 0, challenge))).toString("hex");
|
|
311
|
+
},
|
|
312
|
+
setPairing: async ({ pairing }) => {
|
|
313
|
+
logger.info(`[device] setPairing`);
|
|
314
|
+
const psdPayload = Buffer.from(pairing.blob, "base64");
|
|
315
|
+
const length = Buffer.alloc(2);
|
|
316
|
+
length.writeUInt16BE(psdPayload.length, 0);
|
|
317
|
+
const final = Buffer.concat([length, psdPayload]);
|
|
318
|
+
await run((transport) => sendByChunk(transport, [
|
|
319
|
+
224,
|
|
320
|
+
78,
|
|
321
|
+
0,
|
|
322
|
+
0
|
|
323
|
+
], final));
|
|
324
|
+
},
|
|
325
|
+
startKKPatternAsResponder: async (params) => {
|
|
326
|
+
logger.info(`[device] startKKPatternAsResponder`);
|
|
327
|
+
const data = buildAttestation(params);
|
|
328
|
+
const buffer = removeStatus(await run((transport) => sendByChunk(transport, [
|
|
329
|
+
224,
|
|
330
|
+
76,
|
|
331
|
+
0,
|
|
332
|
+
require_device.SCRIPT_IDS.ACCOUNT_MANAGER_SESSION
|
|
333
|
+
], data)));
|
|
334
|
+
const dataLength = buffer.readInt8(0);
|
|
335
|
+
return {
|
|
336
|
+
handshake: buffer.slice(1, dataLength + 1).toString("base64"),
|
|
337
|
+
signature: buffer.slice(dataLength + 1).toString("base64")
|
|
338
|
+
};
|
|
339
|
+
},
|
|
340
|
+
startKPatternAsResponder: async (params) => {
|
|
341
|
+
logger.info(`[device] startKPatternAsResponder`);
|
|
342
|
+
const data = buildAttestation(params);
|
|
343
|
+
await run((transport) => sendByChunk(transport, [
|
|
344
|
+
224,
|
|
345
|
+
73,
|
|
346
|
+
0,
|
|
347
|
+
require_device.SCRIPT_IDS.ACCOUNT_MANAGER_SESSION
|
|
348
|
+
], data));
|
|
349
|
+
},
|
|
350
|
+
validateVaultOperation: async (params) => {
|
|
351
|
+
logger.info(`[device] validateVaultOperation`);
|
|
352
|
+
const path = getPathFromPathString(require_device.PATHS.VALIDATION);
|
|
353
|
+
const paths = Buffer.concat([Buffer.from([path.length]), ...path.map((derivation) => {
|
|
354
|
+
const buf = Buffer.alloc(4);
|
|
355
|
+
buf.writeUInt32BE(derivation, 0);
|
|
356
|
+
return buf;
|
|
357
|
+
})]);
|
|
358
|
+
let nextActionId = 1;
|
|
359
|
+
let finalResponse = null;
|
|
360
|
+
while (!finalResponse) {
|
|
361
|
+
const screen = Buffer.from(params.actions[nextActionId - 1], "base64");
|
|
362
|
+
const length = Buffer.alloc(2);
|
|
363
|
+
length.writeUInt16BE(screen.length, 0);
|
|
364
|
+
const data = Buffer.concat([
|
|
365
|
+
paths,
|
|
366
|
+
length,
|
|
367
|
+
screen
|
|
368
|
+
]);
|
|
369
|
+
const response = await run((transport) => sendByChunk(transport, [
|
|
370
|
+
224,
|
|
371
|
+
69,
|
|
372
|
+
0,
|
|
373
|
+
0
|
|
374
|
+
], data));
|
|
375
|
+
const responseType = response.readInt8(0);
|
|
376
|
+
let responseStatus = response.readUInt16BE(response.length - 2);
|
|
377
|
+
switch (responseType) {
|
|
378
|
+
case 1:
|
|
379
|
+
nextActionId = response.readUIntBE(1, 2);
|
|
380
|
+
break;
|
|
381
|
+
case 2:
|
|
382
|
+
finalResponse = response.slice(3, response.length - 2);
|
|
383
|
+
while (responseStatus !== 36864) {
|
|
384
|
+
const resp = await run((transport) => transport.send(0, 192, 0, 0));
|
|
385
|
+
responseStatus = resp.readUInt16BE(resp.length - 2);
|
|
386
|
+
finalResponse = Buffer.concat([finalResponse, removeStatus(resp)]);
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
default: throw new Error(`Invalid response type: ${responseType}`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return finalResponse.toString("base64");
|
|
393
|
+
},
|
|
394
|
+
sendAPDU: async (apduCommand) => {
|
|
395
|
+
const res = await run((transport) => transport.exchange(Buffer.from(apduCommand, "hex")));
|
|
396
|
+
return Buffer.from(res).toString("hex");
|
|
397
|
+
},
|
|
398
|
+
getVersion: async () => {
|
|
399
|
+
const res = await run((transport) => transport.send(176, 1, 0, 0));
|
|
400
|
+
const appNameLen = res.readInt8(1);
|
|
401
|
+
const appVersionLen = res.readInt8(2 + appNameLen);
|
|
402
|
+
const appVersionHex = res.slice(3 + appNameLen, 2 + appNameLen + appVersionLen + 1);
|
|
403
|
+
return Buffer.from(appVersionHex).toString();
|
|
404
|
+
},
|
|
405
|
+
poll,
|
|
406
|
+
pollApp
|
|
407
|
+
};
|
|
420
408
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
// Merge in any headers passed via context
|
|
439
|
-
...contextHeaders
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
})
|
|
443
|
-
]
|
|
444
|
-
});
|
|
445
|
-
return trpc;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/trpc.ts
|
|
411
|
+
const createClient = (options) => {
|
|
412
|
+
return (0, _trpc_client.createTRPCClient)({ links: [(0, _trpc_client.httpLink)({
|
|
413
|
+
url: `${options.baseUrl}/trpc`,
|
|
414
|
+
transformer: superjson.default,
|
|
415
|
+
headers(opts) {
|
|
416
|
+
const contextHeaders = opts.op.context?.headers || {};
|
|
417
|
+
return {
|
|
418
|
+
...options.debugAuthToken ? { "x-revault-debug-auth-token": options.debugAuthToken } : {},
|
|
419
|
+
...options.rootAuthToken ? { "x-revault-root-auth-token": options.rootAuthToken } : {},
|
|
420
|
+
...options.psdAuth ? { Authorization: `PsdAuth ${options.psdAuth}` } : {},
|
|
421
|
+
...options.apiAccessToken ? { Authorization: `Bearer ${options.apiAccessToken}` } : {},
|
|
422
|
+
...contextHeaders
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
})] });
|
|
446
426
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
async function genericRegister({
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
return submitChallenge({ pubKey: u2fPubKey.pubKey, challengeResponse });
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/engine/index.ts
|
|
429
|
+
async function genericRegister({ device, name, role, getChallenge, submitChallenge, onScreenDisplayed }) {
|
|
430
|
+
const [attestation, u2fPubKey, confidentialityKey] = await Promise.all([
|
|
431
|
+
device.getAttestation(),
|
|
432
|
+
device.getU2FPubKey(),
|
|
433
|
+
device.getConfidentialityPubKey()
|
|
434
|
+
]);
|
|
435
|
+
const ephemeralPubKey = await device.initPairingHandshake();
|
|
436
|
+
const deviceData = {
|
|
437
|
+
name,
|
|
438
|
+
pubKey: u2fPubKey.pubKey,
|
|
439
|
+
psdModel: "STAX",
|
|
440
|
+
confidentialityKey: confidentialityKey.pubKey,
|
|
441
|
+
psdEphemeralKey: ephemeralPubKey.pubKey,
|
|
442
|
+
psdEphemeralKeyAttestation: {
|
|
443
|
+
...attestation.attestation,
|
|
444
|
+
signature: ephemeralPubKey.signature
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
const challenge = await getChallenge({
|
|
448
|
+
pubKey: u2fPubKey.pubKey,
|
|
449
|
+
deviceData
|
|
450
|
+
});
|
|
451
|
+
const pairingPayload = await device.finalizePairingHandshake({
|
|
452
|
+
handshake: challenge.handshake,
|
|
453
|
+
partitionId: challenge.ciphertext,
|
|
454
|
+
handshakeAttestation: challenge.handshakeAttestation
|
|
455
|
+
});
|
|
456
|
+
await onScreenDisplayed?.();
|
|
457
|
+
const register = await device.register({
|
|
458
|
+
challenge: challenge.challenge,
|
|
459
|
+
u2fRegisterData: challenge.u2fRegisterData,
|
|
460
|
+
name,
|
|
461
|
+
role
|
|
462
|
+
});
|
|
463
|
+
const validationPubKey = await device.getValidationPubKey();
|
|
464
|
+
const registerData = await device.registerData({ challenge: challenge.challenge });
|
|
465
|
+
const attestationOffset = 67 + register.u2fRegister.readInt8(66);
|
|
466
|
+
const u2fRegister = Buffer.concat([
|
|
467
|
+
register.u2fRegister.slice(0, attestationOffset),
|
|
468
|
+
Buffer.from([attestation.buffer.length]),
|
|
469
|
+
attestation.buffer,
|
|
470
|
+
register.u2fRegister.slice(attestationOffset)
|
|
471
|
+
]).toString("hex");
|
|
472
|
+
const challengeResponse = {
|
|
473
|
+
registerData,
|
|
474
|
+
certificate: {
|
|
475
|
+
...attestation.attestation,
|
|
476
|
+
signature: validationPubKey.signature
|
|
477
|
+
},
|
|
478
|
+
u2fRegister,
|
|
479
|
+
u2fKeyHandle: register.keyHandle.toString("hex"),
|
|
480
|
+
validationKey: validationPubKey.pubKey,
|
|
481
|
+
pairingPayload
|
|
482
|
+
};
|
|
483
|
+
return submitChallenge({
|
|
484
|
+
pubKey: u2fPubKey.pubKey,
|
|
485
|
+
challengeResponse
|
|
486
|
+
});
|
|
508
487
|
}
|
|
509
488
|
function createEngine(options, logger) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
const { challenge } = await client2.requests.getChallenge.query({ id: request.id });
|
|
864
|
-
_invariant2.default.call(void 0, challenge.challengeType === "API", "Challenge type must be API");
|
|
865
|
-
return challenge.payload;
|
|
866
|
-
},
|
|
867
|
-
approve: (request, signature) => {
|
|
868
|
-
return client2.requests.approve.mutate({
|
|
869
|
-
id: request.id,
|
|
870
|
-
data: { challengeType: "API", signature }
|
|
871
|
-
});
|
|
872
|
-
},
|
|
873
|
-
reject: (request, signature) => {
|
|
874
|
-
return client2.requests.reject.mutate({
|
|
875
|
-
id: request.id,
|
|
876
|
-
data: { challengeType: "API", signature }
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
return engine;
|
|
883
|
-
}
|
|
884
|
-
return {
|
|
885
|
-
...base,
|
|
886
|
-
withDeviceIndex,
|
|
887
|
-
withTransportId,
|
|
888
|
-
withApiUser,
|
|
889
|
-
withWorkspace,
|
|
890
|
-
withOnboarding
|
|
891
|
-
};
|
|
489
|
+
const clientOptions = { baseUrl: options.baseUrl };
|
|
490
|
+
const client = createClient(clientOptions);
|
|
491
|
+
const apiDevice = require_device.createApiDevice(options, logger);
|
|
492
|
+
const base = {
|
|
493
|
+
client,
|
|
494
|
+
createClient: (overrides) => createClient({
|
|
495
|
+
...clientOptions,
|
|
496
|
+
...overrides
|
|
497
|
+
}),
|
|
498
|
+
__options: options
|
|
499
|
+
};
|
|
500
|
+
const withDeviceIndex = function(deviceIndex) {
|
|
501
|
+
const withPsd = { device: apiDevice.with(deviceIndex) };
|
|
502
|
+
return decorateEngine({
|
|
503
|
+
...this,
|
|
504
|
+
...withPsd
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
const withTransportId = function(transportId) {
|
|
508
|
+
const withPsd = { device: createRealDevice({ transportId }, logger) };
|
|
509
|
+
return decorateEngine({
|
|
510
|
+
...this,
|
|
511
|
+
...withPsd
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
const withApiUser = function() {
|
|
515
|
+
const withApiUser = { __isApiUser: true };
|
|
516
|
+
return decorateEngine({
|
|
517
|
+
...this,
|
|
518
|
+
...withApiUser
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
const withWorkspace = function(workspaceName) {
|
|
522
|
+
const withWorkspace = { __workspaceName: workspaceName };
|
|
523
|
+
return decorateEngine({
|
|
524
|
+
...this,
|
|
525
|
+
...withWorkspace
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
const withOnboarding = function(onboardingId) {
|
|
529
|
+
const withOnboarding = { __onboardingId: onboardingId };
|
|
530
|
+
return decorateEngine({
|
|
531
|
+
...this,
|
|
532
|
+
...withOnboarding
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
function decorateEngine(engine) {
|
|
536
|
+
function decorate(decorator) {
|
|
537
|
+
Object.assign(engine, decorator(engine));
|
|
538
|
+
}
|
|
539
|
+
if (engine.device) decorate((engine) => ({
|
|
540
|
+
getWorkspaces: async () => {
|
|
541
|
+
const { device, client } = engine;
|
|
542
|
+
const { pubKey } = await device.getU2FPubKey();
|
|
543
|
+
const { workspaceNames } = await client.auth.psd.findWorkspaceNames.query({ pubKey });
|
|
544
|
+
return workspaceNames;
|
|
545
|
+
},
|
|
546
|
+
getWorkspacesForSso: async () => {
|
|
547
|
+
const { device, client } = engine;
|
|
548
|
+
const { pubKey } = await device.getU2FPubKey();
|
|
549
|
+
const { workspaces } = await client.auth.sso.findWorkspaces.query({ pubKey });
|
|
550
|
+
return workspaces;
|
|
551
|
+
}
|
|
552
|
+
}));
|
|
553
|
+
if (engine.__workspaceName && !engine.__psdToken && !engine.__apiAuth) decorate((engine) => {
|
|
554
|
+
const { __workspaceName } = engine;
|
|
555
|
+
return { withPsdToken: function(token) {
|
|
556
|
+
const withPsdAuth = { __psdToken: token };
|
|
557
|
+
const psdAuth = `${__workspaceName}:${token}`;
|
|
558
|
+
const client = engine.createClient({ psdAuth });
|
|
559
|
+
return decorateEngine({
|
|
560
|
+
...this,
|
|
561
|
+
client,
|
|
562
|
+
...withPsdAuth
|
|
563
|
+
});
|
|
564
|
+
} };
|
|
565
|
+
});
|
|
566
|
+
if (engine.device && engine.__onboardingId) decorate((engine) => {
|
|
567
|
+
const { device, client, __onboardingId } = engine;
|
|
568
|
+
async function enforcePairing() {
|
|
569
|
+
if (await device.hasPairing()) return;
|
|
570
|
+
const [{ pubKey }, confidentialityKey] = await Promise.all([device.getU2FPubKey(), device.getConfidentialityKey()]);
|
|
571
|
+
const pairing = await client.onboarding.pairDevicePartition.mutate({
|
|
572
|
+
pubKey,
|
|
573
|
+
onboardingId: __onboardingId,
|
|
574
|
+
data: {
|
|
575
|
+
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
576
|
+
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
await device.setPairing({ pairing });
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
claimDevice: async (params) => {
|
|
583
|
+
const { role, deviceName } = params;
|
|
584
|
+
const [{ pubKey }, { pubKey: confidentialityKey }] = await Promise.all([device.getU2FPubKey(), device.getConfidentialityPubKey()]);
|
|
585
|
+
await client.onboarding.claimDevice.mutate({
|
|
586
|
+
onboardingId: __onboardingId,
|
|
587
|
+
claim: {
|
|
588
|
+
role,
|
|
589
|
+
pubKey,
|
|
590
|
+
deviceName,
|
|
591
|
+
confidentialityKey
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
},
|
|
595
|
+
collectWrappingKeyFragment: async (wrappingKey, params) => {
|
|
596
|
+
const [{ pubKey }, confidentialityKey] = await Promise.all([device.getU2FPubKey(), device.getConfidentialityPubKey()]);
|
|
597
|
+
await device.openSession({ secureChannel: {
|
|
598
|
+
pubKey: wrappingKey.ephemeralPubKey,
|
|
599
|
+
certificate: wrappingKey.ephemeralCertificate
|
|
600
|
+
} });
|
|
601
|
+
const { attestation } = await device.getAttestation();
|
|
602
|
+
await params?.onScreenDisplayed?.();
|
|
603
|
+
const blob = await device.generateWrappingKeyFragment();
|
|
604
|
+
await client.onboarding.submitWrappingKeyFragment.mutate({
|
|
605
|
+
pubKey,
|
|
606
|
+
onboardingId: __onboardingId,
|
|
607
|
+
fragment: {
|
|
608
|
+
blob,
|
|
609
|
+
ephemeralPubKey: confidentialityKey.pubKey,
|
|
610
|
+
ephemeralCertificate: {
|
|
611
|
+
...attestation,
|
|
612
|
+
signature: confidentialityKey.signature
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
},
|
|
617
|
+
registerDevice: async (registerParams, params) => {
|
|
618
|
+
const { role, name } = registerParams;
|
|
619
|
+
const getChallengeMutation = role === "ADMIN" ? client.onboarding.generateMasterAdminRegistrationChallenge : client.onboarding.generateSharedOwnerRegistrationChallenge;
|
|
620
|
+
const submitChallengeMutation = role === "ADMIN" ? client.onboarding.submitMasterAdminRegistration : client.onboarding.submitSharedOwnerRegistration;
|
|
621
|
+
await genericRegister({
|
|
622
|
+
device,
|
|
623
|
+
name,
|
|
624
|
+
role,
|
|
625
|
+
getChallenge: ({ pubKey, deviceData }) => getChallengeMutation.mutate({
|
|
626
|
+
onboardingId: __onboardingId,
|
|
627
|
+
pubKey,
|
|
628
|
+
deviceData
|
|
629
|
+
}),
|
|
630
|
+
submitChallenge: ({ pubKey, challengeResponse }) => submitChallengeMutation.mutate({
|
|
631
|
+
onboardingId: engine.__onboardingId,
|
|
632
|
+
pubKey,
|
|
633
|
+
response: challengeResponse
|
|
634
|
+
}),
|
|
635
|
+
onScreenDisplayed: params?.onScreenDisplayed
|
|
636
|
+
});
|
|
637
|
+
},
|
|
638
|
+
reviewSharedOwner: async (challenge, params) => {
|
|
639
|
+
await enforcePairing();
|
|
640
|
+
const { pubKey } = await device.getU2FPubKey();
|
|
641
|
+
await device.startKPatternAsResponder({
|
|
642
|
+
handshake: challenge.handshake,
|
|
643
|
+
handshakeAttestation: challenge.handshakeAttestation,
|
|
644
|
+
partitionId: challenge.partitionId
|
|
645
|
+
});
|
|
646
|
+
await params?.onScreenDisplayed?.();
|
|
647
|
+
const signature = await device.validateVaultOperation({ actions: challenge.wActions });
|
|
648
|
+
await client.onboarding.submitReviewByMasterAdminSignature.mutate({
|
|
649
|
+
onboardingId: __onboardingId,
|
|
650
|
+
pubKey,
|
|
651
|
+
signature
|
|
652
|
+
});
|
|
653
|
+
},
|
|
654
|
+
collectSeedFragment: async (challenge, params) => {
|
|
655
|
+
await enforcePairing();
|
|
656
|
+
const [{ pubKey }, { attestation }] = await Promise.all([device.getU2FPubKey(), device.getAttestation()]);
|
|
657
|
+
await device.startKPatternAsResponder({
|
|
658
|
+
handshake: challenge.handshake,
|
|
659
|
+
handshakeAttestation: challenge.handshakeAttestation,
|
|
660
|
+
partitionId: challenge.partitionId
|
|
661
|
+
});
|
|
662
|
+
await params?.onScreenDisplayed?.();
|
|
663
|
+
const challengeResponse = await device.validateVaultOperation({ actions: challenge.wActions });
|
|
664
|
+
const kkPattern = await device.startKKPatternAsResponder({
|
|
665
|
+
partitionId: challenge.partitionId,
|
|
666
|
+
handshake: challenge.kkHandshake,
|
|
667
|
+
handshakeAttestation: challenge.kkHandshakeAttestation
|
|
668
|
+
});
|
|
669
|
+
const approverBlob = await device.generateSeedFragment();
|
|
670
|
+
await client.onboarding.submitSeedFragment.mutate({
|
|
671
|
+
onboardingId: __onboardingId,
|
|
672
|
+
pubKey,
|
|
673
|
+
seedFragment: {
|
|
674
|
+
challengeResponse,
|
|
675
|
+
approverBlob,
|
|
676
|
+
handshake: kkPattern.handshake,
|
|
677
|
+
handshakeAttestation: {
|
|
678
|
+
...attestation,
|
|
679
|
+
signature: kkPattern.signature
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
});
|
|
686
|
+
if (engine.device && engine.__workspaceName && !engine.__psdToken) decorate((engine) => {
|
|
687
|
+
const { device, client, __workspaceName } = engine;
|
|
688
|
+
return {
|
|
689
|
+
login: async function(opts) {
|
|
690
|
+
const { pubKey } = await device.getU2FPubKey();
|
|
691
|
+
const challenge = await client.auth.psd.generateChallenge.mutate({
|
|
692
|
+
pubKey,
|
|
693
|
+
workspaceName: __workspaceName
|
|
694
|
+
}, require_utils.buildTrpcContext({ correlationId: opts?.correlationId }));
|
|
695
|
+
await opts?.onScreenDisplayed?.();
|
|
696
|
+
const authPayload = {
|
|
697
|
+
workspaceName: __workspaceName,
|
|
698
|
+
pubKey,
|
|
699
|
+
authentication: await device.authenticate({
|
|
700
|
+
challenge,
|
|
701
|
+
workspaceName: __workspaceName
|
|
702
|
+
}),
|
|
703
|
+
challengeId: challenge.challengeId,
|
|
704
|
+
validityDurationSecs: opts?.validityDurationSecs
|
|
705
|
+
};
|
|
706
|
+
const { token } = await client.auth.psd.authenticate.mutate({ ...authPayload }, require_utils.buildTrpcContext({ correlationId: opts?.correlationId }));
|
|
707
|
+
const withPsdAuth = { __psdToken: token };
|
|
708
|
+
const psdAuth = `${engine.__workspaceName}:${token}`;
|
|
709
|
+
const __authClient = engine.createClient({ psdAuth });
|
|
710
|
+
return decorateEngine({
|
|
711
|
+
...this,
|
|
712
|
+
client: __authClient,
|
|
713
|
+
...withPsdAuth
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
register: (registration) => {
|
|
717
|
+
return genericRegister({
|
|
718
|
+
device,
|
|
719
|
+
name: registration.name,
|
|
720
|
+
role: registration.role,
|
|
721
|
+
getChallenge: async ({ deviceData }) => {
|
|
722
|
+
return await client.userRegistrations.generateChallenge.mutate({
|
|
723
|
+
id: registration.id,
|
|
724
|
+
workspaceName: __workspaceName,
|
|
725
|
+
deviceData
|
|
726
|
+
});
|
|
727
|
+
},
|
|
728
|
+
submitChallenge: ({ challengeResponse }) => client.userRegistrations.submitChallenge.mutate({
|
|
729
|
+
workspaceName: __workspaceName,
|
|
730
|
+
id: registration.id,
|
|
731
|
+
challengeResponse
|
|
732
|
+
})
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
});
|
|
737
|
+
if (engine.__workspaceName && engine.__isApiUser && !engine.__apiAuth) decorate((engine) => {
|
|
738
|
+
const { client, __workspaceName } = engine;
|
|
739
|
+
return { login: async function(credentials, opts) {
|
|
740
|
+
const res = await client.auth.authenticate.mutate({
|
|
741
|
+
apiKeyId: credentials.apiKeyId,
|
|
742
|
+
apiKeySecret: credentials.apiKeySecret,
|
|
743
|
+
workspace: __workspaceName
|
|
744
|
+
}, require_utils.buildTrpcContext({ correlationId: opts?.correlationId }));
|
|
745
|
+
const withApiAuth = { __apiAuth: res };
|
|
746
|
+
const __authClient = engine.createClient({ apiAccessToken: res.accessToken });
|
|
747
|
+
return decorateEngine({
|
|
748
|
+
...this,
|
|
749
|
+
client: __authClient,
|
|
750
|
+
...withApiAuth
|
|
751
|
+
});
|
|
752
|
+
} };
|
|
753
|
+
});
|
|
754
|
+
if (engine.device && engine.__workspaceName && engine.__psdToken) decorate((engine) => {
|
|
755
|
+
const { client, device } = engine;
|
|
756
|
+
async function enforcePairing() {
|
|
757
|
+
if (await device.hasPairing()) return;
|
|
758
|
+
const confidentialityKey = await device.getConfidentialityKey();
|
|
759
|
+
const pairing = await client.debug.pairDevicePartition.mutate({
|
|
760
|
+
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
761
|
+
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
762
|
+
});
|
|
763
|
+
await device.setPairing({ pairing });
|
|
764
|
+
}
|
|
765
|
+
const approveChallenge = async (challenge, params) => {
|
|
766
|
+
await enforcePairing();
|
|
767
|
+
await device.startKPatternAsResponder({
|
|
768
|
+
handshake: challenge.handshake,
|
|
769
|
+
handshakeAttestation: challenge.handshakeAttestation,
|
|
770
|
+
partitionId: challenge.partitionId
|
|
771
|
+
});
|
|
772
|
+
await params?.onScreenDisplayed?.();
|
|
773
|
+
return await device.validateVaultOperation({ actions: challenge.wActions });
|
|
774
|
+
};
|
|
775
|
+
return {
|
|
776
|
+
approve: async (request, params) => {
|
|
777
|
+
const { challenge } = await client.requests.getChallenge.query({ id: request.id });
|
|
778
|
+
if (challenge.challengeType === "PSD") {
|
|
779
|
+
const signature = await approveChallenge(challenge, params);
|
|
780
|
+
await params?.onPsdChallengeSigned?.();
|
|
781
|
+
return client.requests.approve.mutate({
|
|
782
|
+
id: request.id,
|
|
783
|
+
data: {
|
|
784
|
+
challengeType: "PSD",
|
|
785
|
+
signature
|
|
786
|
+
}
|
|
787
|
+
}, require_utils.buildTrpcContext(params));
|
|
788
|
+
}
|
|
789
|
+
if (challenge.challengeType === "SOFT") return client.requests.approve.mutate({
|
|
790
|
+
id: request.id,
|
|
791
|
+
data: { challengeType: "SOFT" }
|
|
792
|
+
}, require_utils.buildTrpcContext(params));
|
|
793
|
+
throw new Error("Challenge type must be either PSD or SOFT");
|
|
794
|
+
},
|
|
795
|
+
approveChallenge,
|
|
796
|
+
reject: (request, opts) => {
|
|
797
|
+
return client.requests.reject.mutate({
|
|
798
|
+
id: request.id,
|
|
799
|
+
data: null
|
|
800
|
+
}, require_utils.buildTrpcContext(opts));
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
});
|
|
804
|
+
if (engine.__workspaceName && engine.__apiAuth) decorate((engine) => {
|
|
805
|
+
const { client } = engine;
|
|
806
|
+
return {
|
|
807
|
+
getChallenge: async (request) => {
|
|
808
|
+
const { challenge } = await client.requests.getChallenge.query({ id: request.id });
|
|
809
|
+
(0, invariant.default)(challenge.challengeType === "API", "Challenge type must be API");
|
|
810
|
+
return challenge.payload;
|
|
811
|
+
},
|
|
812
|
+
approve: (request, signature) => {
|
|
813
|
+
return client.requests.approve.mutate({
|
|
814
|
+
id: request.id,
|
|
815
|
+
data: {
|
|
816
|
+
challengeType: "API",
|
|
817
|
+
signature
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
},
|
|
821
|
+
reject: (request, signature) => {
|
|
822
|
+
return client.requests.reject.mutate({
|
|
823
|
+
id: request.id,
|
|
824
|
+
data: {
|
|
825
|
+
challengeType: "API",
|
|
826
|
+
signature
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
});
|
|
832
|
+
return engine;
|
|
833
|
+
}
|
|
834
|
+
return {
|
|
835
|
+
...base,
|
|
836
|
+
withDeviceIndex,
|
|
837
|
+
withTransportId,
|
|
838
|
+
withApiUser,
|
|
839
|
+
withWorkspace,
|
|
840
|
+
withOnboarding
|
|
841
|
+
};
|
|
892
842
|
}
|
|
843
|
+
//#endregion
|
|
844
|
+
exports.createEngine = createEngine;
|
|
845
|
+
exports.fetchAll = require_utils.fetchAll;
|
|
846
|
+
exports.fetchAllCursor = require_utils.fetchAllCursor;
|
|
893
847
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
exports.createEngine = createEngine; exports.fetchAll = _chunkLH4QQXUHcjs.fetchAll; exports.fetchAllCursor = _chunkLH4QQXUHcjs.fetchAllCursor;
|
|
898
|
-
/* v8 ignore next -- @preserve */
|
|
899
848
|
//# sourceMappingURL=engine.cjs.map
|