@ledgerhq/revault-sdk 0.28.5 → 0.28.8
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 +5 -4
- package/lib/bake.cjs.map +1 -1
- package/lib/bake.d.cts +3 -3
- package/lib/bake.d.ts +3 -3
- package/lib/bake.js +3 -2
- package/lib/bake.js.map +1 -1
- package/lib/{crypto-B4xS0N1u.cjs → crypto-BTN8FS8v.cjs} +5 -3
- package/lib/crypto-BTN8FS8v.cjs.map +1 -0
- package/lib/{crypto-BZw0pZ1Z.js → crypto-BcqzGi2f.js} +4 -2
- package/lib/{crypto-BZw0pZ1Z.js.map → crypto-BcqzGi2f.js.map} +1 -1
- package/lib/crypto.cjs +1 -1
- package/lib/crypto.js +1 -1
- package/lib/{device-dbZH_1Pt.cjs → device-CTYTWL2K.cjs} +6 -5
- package/lib/device-CTYTWL2K.cjs.map +1 -0
- package/lib/{device-Bo6m3O1I.js → device-WXLkORvV.js} +6 -5
- package/lib/device-WXLkORvV.js.map +1 -0
- package/lib/device.cjs +1 -1
- package/lib/device.d.cts +1 -1
- package/lib/device.d.ts +1 -1
- package/lib/device.js +1 -1
- package/lib/engine.cjs +53 -80
- package/lib/engine.cjs.map +1 -1
- package/lib/engine.d.cts +2 -2
- package/lib/engine.d.ts +2 -2
- package/lib/engine.js +51 -78
- package/lib/engine.js.map +1 -1
- package/lib/{index-aYbRTZvr.d.ts → index-BOGRCryj.d.ts} +2 -3
- package/lib/{index-D_EED8aS.d.cts → index-DhsFtPU0.d.cts} +2 -3
- package/lib/{index-Ds_t9ilJ.d.ts → index-OGfo9h6i.d.ts} +1 -4
- package/lib/{index-C5AAKtIf.d.cts → index-XIIQ2731.d.cts} +1 -4
- package/lib/index.cjs +1 -1
- package/lib/index.d.cts +2 -5
- package/lib/index.d.ts +2 -5
- package/lib/onboarding.cjs +2 -2
- package/lib/onboarding.cjs.map +1 -1
- package/lib/onboarding.d.cts +151 -884
- package/lib/onboarding.d.ts +151 -884
- package/lib/onboarding.js +1 -1
- package/lib/{rolldown-runtime-emK7D4bc.cjs → rolldown-runtime-y5ARvAq5.cjs} +1 -1
- package/lib/{trpc-DBU35NJq.d.ts → trpc-BCwyqVKi.d.cts} +0 -1
- package/lib/{trpc-DBU35NJq.d.cts → trpc-BCwyqVKi.d.ts} +0 -1
- package/lib/{types-ALsH_YtN.d.ts → types-BF0VbAJ_.d.ts} +2 -3
- package/lib/{types-DP-rmxvy.d.cts → types-D-dTS1te.d.cts} +2 -3
- package/lib/types.d.cts +2 -6
- package/lib/types.d.ts +2 -6
- package/lib/{utils-CavXJGCh.cjs → utils-qv4hwX4J.cjs} +2 -2
- package/lib/{utils-CavXJGCh.cjs.map → utils-qv4hwX4J.cjs.map} +1 -1
- package/package.json +11 -11
- package/lib/crypto-B4xS0N1u.cjs.map +0 -1
- package/lib/device-Bo6m3O1I.js.map +0 -1
- package/lib/device-dbZH_1Pt.cjs.map +0 -1
package/lib/engine.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { c as LockedDeviceError, d as PAGINATED_STATUS, f as PATHS, i as isTransportStatusError, l as createApiDevice, m as STR_ROLES, o as withDevicePolling, p as SCRIPT_IDS, r as isPskMissingError, s as DisconnectedDevice, u as APPID_VAULT_ADMINISTRATOR } from "./device-
|
|
1
|
+
import { c as LockedDeviceError, d as PAGINATED_STATUS, f as PATHS, i as isTransportStatusError, l as createApiDevice, m as STR_ROLES, o as withDevicePolling, p as SCRIPT_IDS, r as isPskMissingError, s as DisconnectedDevice, u as APPID_VAULT_ADMINISTRATOR } from "./device-WXLkORvV.js";
|
|
2
2
|
import { i as fetchAllCursor, r as fetchAll, t as buildTrpcContext } from "./utils-CW0gdJME.js";
|
|
3
3
|
import invariant from "invariant";
|
|
4
|
-
import { match } from "ts-pattern";
|
|
5
4
|
import { from, lastValueFrom } from "rxjs";
|
|
6
5
|
import { createTRPCClient, httpLink } from "@trpc/client";
|
|
7
6
|
import superjson from "superjson";
|
|
@@ -174,20 +173,22 @@ function createRealDevice(options, logger) {
|
|
|
174
173
|
keyHandleDataLength,
|
|
175
174
|
keyHandleData
|
|
176
175
|
]);
|
|
177
|
-
|
|
176
|
+
const authentication = await run((transport) => sendByChunk(transport, [
|
|
178
177
|
224,
|
|
179
178
|
2,
|
|
180
179
|
0,
|
|
181
180
|
0
|
|
182
|
-
], data))
|
|
181
|
+
], data));
|
|
182
|
+
return removeStatus(authentication).toString("hex");
|
|
183
183
|
},
|
|
184
184
|
finalizePairingHandshake: async (params) => {
|
|
185
|
-
|
|
185
|
+
const bufWithStatus = await run((transport) => sendByChunk(transport, [
|
|
186
186
|
224,
|
|
187
187
|
71,
|
|
188
188
|
0,
|
|
189
189
|
2
|
|
190
|
-
], buildAttestation(params)))
|
|
190
|
+
], buildAttestation(params)));
|
|
191
|
+
return removeStatus(bufWithStatus).toString("hex");
|
|
191
192
|
},
|
|
192
193
|
generateSeedFragment: async () => {
|
|
193
194
|
logger.info(`[device] generateSeedFragment`);
|
|
@@ -197,7 +198,8 @@ function createRealDevice(options, logger) {
|
|
|
197
198
|
buf.writeUInt32BE(derivation, 0);
|
|
198
199
|
return buf;
|
|
199
200
|
})]);
|
|
200
|
-
|
|
201
|
+
const response = await run((transport) => transport.send(224, 68, 0, 0, data));
|
|
202
|
+
return removeStatus(response).toString("base64");
|
|
201
203
|
},
|
|
202
204
|
generateWrappingKeyFragment: async () => {
|
|
203
205
|
logger.info(`[device] generateWrappingKeyFragment`);
|
|
@@ -207,10 +209,12 @@ function createRealDevice(options, logger) {
|
|
|
207
209
|
buf.writeUInt32BE(derivation, 0);
|
|
208
210
|
return buf;
|
|
209
211
|
})]);
|
|
210
|
-
|
|
212
|
+
const response = await run((transport) => transport.send(224, 68, 1, 0, data));
|
|
213
|
+
return removeStatus(response).toString("base64");
|
|
211
214
|
},
|
|
212
215
|
getAttestation: async () => {
|
|
213
|
-
const
|
|
216
|
+
const bufWithStatus = await run((transport) => transport.send(224, 65, 0, 0));
|
|
217
|
+
const buffer = removeStatus(bufWithStatus);
|
|
214
218
|
const certLen = buffer.readInt8(98);
|
|
215
219
|
return {
|
|
216
220
|
attestation: {
|
|
@@ -223,7 +227,8 @@ function createRealDevice(options, logger) {
|
|
|
223
227
|
},
|
|
224
228
|
getConfidentialityKey: async () => {
|
|
225
229
|
logger.info(`[device] getConfidentialityKey`);
|
|
226
|
-
const
|
|
230
|
+
const bufWithStatus = await run((transport) => transport.send(224, 77, 0, 0));
|
|
231
|
+
const buf = removeStatus(bufWithStatus);
|
|
227
232
|
const keyLength = buf[0];
|
|
228
233
|
const key = buf.slice(1, 1 + keyLength);
|
|
229
234
|
const sig = buf.slice(1 + keyLength + 1);
|
|
@@ -235,7 +240,8 @@ function createRealDevice(options, logger) {
|
|
|
235
240
|
getConfidentialityPubKey: () => getPublicKey(PATHS.CONFIDENTIALITY, { secp256k1: true }),
|
|
236
241
|
getDeviceUserId: async () => {
|
|
237
242
|
logger.info(`[device] getDeviceUserId`);
|
|
238
|
-
|
|
243
|
+
const response = await run((transport) => transport.send(224, 82, 0, 0));
|
|
244
|
+
return removeStatus(response).toString("hex").toUpperCase();
|
|
239
245
|
},
|
|
240
246
|
getU2FPubKey: () => getPublicKey(PATHS.U2F, { secp256k1: false }),
|
|
241
247
|
getValidationPubKey: () => getPublicKey(PATHS.VALIDATION, { secp256k1: true }),
|
|
@@ -343,7 +349,8 @@ function createRealDevice(options, logger) {
|
|
|
343
349
|
const { challenge: strChallenge } = params;
|
|
344
350
|
const challenge = Buffer.from(strChallenge, "hex");
|
|
345
351
|
invariant(challenge.length === 32, "challenge hex is expected to have 32 bytes");
|
|
346
|
-
|
|
352
|
+
const response = await run((transport) => transport.send(224, 3, 0, 0, challenge));
|
|
353
|
+
return removeStatus(response).toString("hex");
|
|
347
354
|
},
|
|
348
355
|
setPairing: async ({ pairing }) => {
|
|
349
356
|
logger.info(`[device] setPairing`);
|
|
@@ -376,12 +383,13 @@ function createRealDevice(options, logger) {
|
|
|
376
383
|
startKKPatternAsResponder: async (params) => {
|
|
377
384
|
logger.info(`[device] startKKPatternAsResponder`);
|
|
378
385
|
const data = buildAttestation(params);
|
|
379
|
-
const
|
|
386
|
+
const bufWithStatus = await run((transport) => sendByChunk(transport, [
|
|
380
387
|
224,
|
|
381
388
|
76,
|
|
382
389
|
0,
|
|
383
390
|
SCRIPT_IDS.ACCOUNT_MANAGER_SESSION
|
|
384
|
-
], data))
|
|
391
|
+
], data));
|
|
392
|
+
const buffer = removeStatus(bufWithStatus);
|
|
385
393
|
const dataLength = buffer.readInt8(0);
|
|
386
394
|
return {
|
|
387
395
|
handshake: buffer.slice(1, dataLength + 1).toString("base64"),
|
|
@@ -490,9 +498,8 @@ const createClient = (options) => {
|
|
|
490
498
|
};
|
|
491
499
|
//#endregion
|
|
492
500
|
//#region src/engine/index.ts
|
|
493
|
-
const PSK_NONCE_BYTE_LEN = 32;
|
|
494
501
|
const openSecureChannel = (device, challenge) => {
|
|
495
|
-
if (challenge.handshake.length ===
|
|
502
|
+
if (challenge.handshake.length === 64) return device.startPskSession({
|
|
496
503
|
nonce: challenge.handshake,
|
|
497
504
|
partitionId: challenge.partitionId
|
|
498
505
|
});
|
|
@@ -660,55 +667,40 @@ function createEngine(options, logger) {
|
|
|
660
667
|
});
|
|
661
668
|
if (engine.device && engine.__onboardingId) decorate((engine) => {
|
|
662
669
|
const { device, client, __onboardingId } = engine;
|
|
663
|
-
const isPskEnabled = async () => {
|
|
664
|
-
try {
|
|
665
|
-
return await client.onboarding.getPskFeatureFlag.query({ onboardingId: __onboardingId }) === true;
|
|
666
|
-
} catch {
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
670
|
async function enforcePairing() {
|
|
671
671
|
const status = await device.hasPairing();
|
|
672
672
|
if (status === "OK") return;
|
|
673
|
-
const pskEnabled = await isPskEnabled();
|
|
674
673
|
let pubKeyPromise;
|
|
675
674
|
const getPubKey = async () => {
|
|
676
675
|
pubKeyPromise ??= device.getU2FPubKey().then(({ pubKey }) => pubKey);
|
|
677
676
|
return pubKeyPromise;
|
|
678
677
|
};
|
|
679
|
-
const
|
|
678
|
+
const refreshCurrentPsk = async () => {
|
|
680
679
|
const pubKey = await getPubKey();
|
|
681
|
-
await
|
|
680
|
+
await refreshPsk({
|
|
682
681
|
device,
|
|
683
|
-
|
|
682
|
+
getRefreshPskData: (data) => client.onboarding.refreshPsk.mutate({
|
|
684
683
|
pubKey,
|
|
685
684
|
onboardingId: __onboardingId,
|
|
686
|
-
data
|
|
687
|
-
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
688
|
-
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
689
|
-
}
|
|
685
|
+
data
|
|
690
686
|
})
|
|
691
687
|
});
|
|
692
688
|
};
|
|
693
|
-
|
|
689
|
+
if (status === "NO_PAIRING") {
|
|
694
690
|
const pubKey = await getPubKey();
|
|
695
|
-
await
|
|
691
|
+
await pairDevice({
|
|
696
692
|
device,
|
|
697
|
-
|
|
693
|
+
getPairing: (confidentialityKey) => client.onboarding.pairDevicePartition.mutate({
|
|
698
694
|
pubKey,
|
|
699
695
|
onboardingId: __onboardingId,
|
|
700
|
-
data
|
|
696
|
+
data: {
|
|
697
|
+
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
698
|
+
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
699
|
+
}
|
|
701
700
|
})
|
|
702
701
|
});
|
|
703
|
-
}
|
|
704
|
-
await
|
|
705
|
-
await pairCurrentDevice();
|
|
706
|
-
}).with(["NO_PAIRING", true], async () => {
|
|
707
|
-
await pairCurrentDevice();
|
|
708
|
-
await refreshCurrentPsk();
|
|
709
|
-
}).with(["PSK_MISSING", false], async () => {}).with(["PSK_MISSING", true], async () => {
|
|
710
|
-
await refreshCurrentPsk();
|
|
711
|
-
}).exhaustive();
|
|
702
|
+
}
|
|
703
|
+
await refreshCurrentPsk();
|
|
712
704
|
}
|
|
713
705
|
return {
|
|
714
706
|
claimDevice: async (params) => {
|
|
@@ -829,13 +821,14 @@ function createEngine(options, logger) {
|
|
|
829
821
|
workspaceName: __workspaceName
|
|
830
822
|
}, buildTrpcContext({ correlationId: opts?.correlationId }));
|
|
831
823
|
await opts?.onScreenDisplayed?.();
|
|
824
|
+
const authentication = await device.authenticate({
|
|
825
|
+
challenge,
|
|
826
|
+
workspaceName: __workspaceName
|
|
827
|
+
});
|
|
832
828
|
const authPayload = {
|
|
833
829
|
workspaceName: __workspaceName,
|
|
834
830
|
pubKey,
|
|
835
|
-
authentication
|
|
836
|
-
challenge,
|
|
837
|
-
workspaceName: __workspaceName
|
|
838
|
-
}),
|
|
831
|
+
authentication,
|
|
839
832
|
challengeId: challenge.challengeId,
|
|
840
833
|
validityDurationSecs: opts?.validityDurationSecs
|
|
841
834
|
};
|
|
@@ -890,40 +883,23 @@ function createEngine(options, logger) {
|
|
|
890
883
|
});
|
|
891
884
|
if (engine.device && engine.__workspaceName && engine.__psdToken) decorate((engine) => {
|
|
892
885
|
const { client, device } = engine;
|
|
893
|
-
const isPskEnabled = async () => {
|
|
894
|
-
try {
|
|
895
|
-
return await client.debug.getPskFeatureFlag.query() === true;
|
|
896
|
-
} catch {
|
|
897
|
-
return false;
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
886
|
async function enforcePairing() {
|
|
901
887
|
const status = await device.hasPairing();
|
|
902
888
|
if (status === "OK") return;
|
|
903
|
-
const pskEnabled = await isPskEnabled();
|
|
904
|
-
const pairCurrentDevice = async () => {
|
|
905
|
-
await pairDevice({
|
|
906
|
-
device,
|
|
907
|
-
getPairing: (confidentialityKey) => client.debug.pairDevicePartition.mutate({
|
|
908
|
-
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
909
|
-
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
910
|
-
})
|
|
911
|
-
});
|
|
912
|
-
};
|
|
913
889
|
const refreshCurrentPsk = async () => {
|
|
914
890
|
await refreshPsk({
|
|
915
891
|
device,
|
|
916
892
|
getRefreshPskData: (data) => client.debug.refreshPsk.mutate(data)
|
|
917
893
|
});
|
|
918
894
|
};
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
895
|
+
if (status === "NO_PAIRING") await pairDevice({
|
|
896
|
+
device,
|
|
897
|
+
getPairing: (confidentialityKey) => client.debug.pairDevicePartition.mutate({
|
|
898
|
+
confidentialityKeyCurve25519: confidentialityKey.confidentialityKeyCurve25519,
|
|
899
|
+
confidentialityKeySignature: confidentialityKey.confidentialityKeySignature
|
|
900
|
+
})
|
|
901
|
+
});
|
|
902
|
+
await refreshCurrentPsk();
|
|
927
903
|
}
|
|
928
904
|
const approveChallenge = async (challenge, params) => {
|
|
929
905
|
await enforcePairing();
|
|
@@ -931,11 +907,8 @@ function createEngine(options, logger) {
|
|
|
931
907
|
await openSecureChannel(device, challenge);
|
|
932
908
|
} catch (err) {
|
|
933
909
|
if (!isPskMissingError(err)) throw err;
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
await enforcePairing();
|
|
937
|
-
await openSecureChannel(device, challenge);
|
|
938
|
-
}
|
|
910
|
+
await enforcePairing();
|
|
911
|
+
await openSecureChannel(device, challenge);
|
|
939
912
|
}
|
|
940
913
|
await params?.onScreenDisplayed?.();
|
|
941
914
|
return await device.validateVaultOperation({ actions: challenge.wActions });
|