@ledgerhq/revault-sdk 0.21.6 → 0.21.7
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 +4 -2
- package/lib/bake.cjs.map +1 -1
- package/lib/bake.js +3 -1
- package/lib/bake.js.map +1 -1
- package/lib/{chunk-KS6SB3HR.cjs → chunk-2HKHCIKX.cjs} +49 -41
- package/lib/chunk-2HKHCIKX.cjs.map +1 -0
- package/lib/{chunk-OJW4TCAG.js → chunk-42CFPNWC.js} +52 -44
- package/lib/chunk-42CFPNWC.js.map +1 -0
- package/lib/{chunk-OU3QTNYT.js → chunk-73OX5XDM.js} +13 -11
- package/lib/chunk-73OX5XDM.js.map +1 -0
- package/lib/{chunk-XO66ZFXN.cjs → chunk-P53CFOI6.cjs} +13 -11
- package/lib/chunk-P53CFOI6.cjs.map +1 -0
- package/lib/crypto.cjs +2 -2
- package/lib/crypto.js +1 -1
- package/lib/device.cjs +2 -2
- package/lib/device.d.cts +4 -4
- package/lib/device.d.ts +4 -4
- package/lib/device.js +1 -1
- package/lib/engine.cjs +46 -35
- package/lib/engine.cjs.map +1 -1
- package/lib/engine.js +28 -17
- package/lib/engine.js.map +1 -1
- package/lib/onboarding.cjs +20 -7
- package/lib/onboarding.cjs.map +1 -1
- package/lib/onboarding.js +19 -6
- package/lib/onboarding.js.map +1 -1
- package/package.json +6 -6
- package/lib/chunk-KS6SB3HR.cjs.map +0 -1
- package/lib/chunk-OJW4TCAG.js.map +0 -1
- package/lib/chunk-OU3QTNYT.js.map +0 -1
- package/lib/chunk-XO66ZFXN.cjs.map +0 -1
|
@@ -37,15 +37,19 @@ function createApiDevice(options, logger) {
|
|
|
37
37
|
axiosRetry(deviceApi, {
|
|
38
38
|
retryDelay: axiosRetry.linearDelay(1e3),
|
|
39
39
|
retries: 3,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
retryCondition: (
|
|
41
|
+
/* v8 ignore next -- @preserve */
|
|
42
|
+
() => true
|
|
43
|
+
),
|
|
44
|
+
onRetry: (
|
|
45
|
+
/* v8 ignore next -- @preserve */
|
|
46
|
+
(retryCount, err) => {
|
|
47
|
+
const formattedErr = `${err.code ?? `UNKNOWN`} on ${err.config?.method?.toUpperCase() ?? "UNKNOWN_METHOD"} ${err.config?.url ?? "UNKNOWN_URL"}`;
|
|
48
|
+
logger.warning(
|
|
49
|
+
`Retrying request to device-api (attempt ${retryCount}) - Cause: ${formattedErr}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
)
|
|
49
53
|
});
|
|
50
54
|
deviceApi.interceptors.request.use(
|
|
51
55
|
(config) => {
|
|
@@ -68,7 +72,6 @@ function createApiDevice(options, logger) {
|
|
|
68
72
|
}
|
|
69
73
|
return config;
|
|
70
74
|
},
|
|
71
|
-
/* v8 ignore stop */
|
|
72
75
|
(error) => Promise.reject(error)
|
|
73
76
|
);
|
|
74
77
|
return {
|
|
@@ -210,10 +213,14 @@ function createApiDevice(options, logger) {
|
|
|
210
213
|
const { data } = await deviceApi.post("/register", payload);
|
|
211
214
|
const response = Buffer.from(data, "hex");
|
|
212
215
|
let i = 0;
|
|
213
|
-
const rfu = response.slice(i, i
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
216
|
+
const rfu = response.slice(i, i + 1)[0];
|
|
217
|
+
i += 1;
|
|
218
|
+
const pubKey = response.slice(i, i + 65).toString("hex");
|
|
219
|
+
i += 65;
|
|
220
|
+
const keyHandleLength = response.slice(i, i + 1)[0];
|
|
221
|
+
i++;
|
|
222
|
+
const keyHandle = response.slice(i, i + keyHandleLength);
|
|
223
|
+
i += keyHandleLength;
|
|
217
224
|
return {
|
|
218
225
|
u2fRegister: response.slice(0, response.length - 2),
|
|
219
226
|
keyHandle,
|
|
@@ -343,30 +350,6 @@ function createApiDevice(options, logger) {
|
|
|
343
350
|
};
|
|
344
351
|
}
|
|
345
352
|
|
|
346
|
-
// src/device/utils.ts
|
|
347
|
-
import { TransportStatusError } from "@ledgerhq/errors";
|
|
348
|
-
var isTransportStatusError = (error) => {
|
|
349
|
-
return error instanceof TransportStatusError || error instanceof Error && "statusCode" in error && error.message.startsWith("Ledger device:");
|
|
350
|
-
};
|
|
351
|
-
var CANCEL_STATUS_CODES = [
|
|
352
|
-
27013,
|
|
353
|
-
// cancel on Ledger Blue
|
|
354
|
-
// STAX
|
|
355
|
-
45068,
|
|
356
|
-
// cancel collect wk fragment
|
|
357
|
-
45069,
|
|
358
|
-
// cancel user registration
|
|
359
|
-
45072,
|
|
360
|
-
// cancel review
|
|
361
|
-
45074,
|
|
362
|
-
// cancel master seed generation
|
|
363
|
-
45075
|
|
364
|
-
// cancel login
|
|
365
|
-
];
|
|
366
|
-
var isDeviceCancelError = (error) => {
|
|
367
|
-
return isTransportStatusError(error) && CANCEL_STATUS_CODES.includes(error.statusCode);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
353
|
// src/device/device-access.ts
|
|
371
354
|
import {
|
|
372
355
|
BluetoothRequired,
|
|
@@ -374,13 +357,13 @@ import {
|
|
|
374
357
|
DeviceHalted,
|
|
375
358
|
FirmwareOrAppUpdateRequired,
|
|
376
359
|
TransportInterfaceNotAvailable,
|
|
377
|
-
TransportStatusError
|
|
360
|
+
TransportStatusError,
|
|
378
361
|
TransportWebUSBGestureRequired
|
|
379
362
|
} from "@ledgerhq/errors";
|
|
380
363
|
import { Observable, throwError, timer } from "rxjs";
|
|
381
364
|
import { catchError, mergeMap, retryWhen } from "rxjs/operators";
|
|
382
365
|
var initialErrorRemapping = (error) => throwError(
|
|
383
|
-
error && error instanceof
|
|
366
|
+
error && error instanceof TransportStatusError && error.statusCode === 28586 ? new DeviceHalted(error.message) : error instanceof TransportStatusError && error.statusCode === 27392 ? new FirmwareOrAppUpdateRequired(error.message) : error
|
|
384
367
|
);
|
|
385
368
|
var never = new Promise(() => {
|
|
386
369
|
});
|
|
@@ -490,6 +473,30 @@ var retryWhileErrors = (acceptError) => (
|
|
|
490
473
|
);
|
|
491
474
|
var withDevicePolling = (deviceId) => (job, acceptError = () => false) => withDevice(deviceId)(job).pipe(retryWhen(retryWhileErrors(acceptError)));
|
|
492
475
|
|
|
476
|
+
// src/device/utils.ts
|
|
477
|
+
import { TransportStatusError as TransportStatusError2 } from "@ledgerhq/errors";
|
|
478
|
+
var isTransportStatusError = (error) => {
|
|
479
|
+
return error instanceof TransportStatusError2 || error instanceof Error && "statusCode" in error && error.message.startsWith("Ledger device:");
|
|
480
|
+
};
|
|
481
|
+
var CANCEL_STATUS_CODES = [
|
|
482
|
+
27013,
|
|
483
|
+
// cancel on Ledger Blue
|
|
484
|
+
// STAX
|
|
485
|
+
45068,
|
|
486
|
+
// cancel collect wk fragment
|
|
487
|
+
45069,
|
|
488
|
+
// cancel user registration
|
|
489
|
+
45072,
|
|
490
|
+
// cancel review
|
|
491
|
+
45074,
|
|
492
|
+
// cancel master seed generation
|
|
493
|
+
45075
|
|
494
|
+
// cancel login
|
|
495
|
+
];
|
|
496
|
+
var isDeviceCancelError = (error) => {
|
|
497
|
+
return isTransportStatusError(error) && CANCEL_STATUS_CODES.includes(error.statusCode);
|
|
498
|
+
};
|
|
499
|
+
|
|
493
500
|
export {
|
|
494
501
|
PATHS,
|
|
495
502
|
STATUS_LENGTH,
|
|
@@ -500,9 +507,10 @@ export {
|
|
|
500
507
|
STREAMING_RESPONSE,
|
|
501
508
|
STREAMING_NEXT_ACTION,
|
|
502
509
|
createApiDevice,
|
|
503
|
-
isTransportStatusError,
|
|
504
|
-
isDeviceCancelError,
|
|
505
510
|
registerTransportModule,
|
|
506
|
-
withDevicePolling
|
|
511
|
+
withDevicePolling,
|
|
512
|
+
isTransportStatusError,
|
|
513
|
+
isDeviceCancelError
|
|
507
514
|
};
|
|
508
|
-
|
|
515
|
+
/* v8 ignore next -- @preserve */
|
|
516
|
+
//# sourceMappingURL=chunk-42CFPNWC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/device/api-device.ts","../src/device/constants.ts","../src/device/device-access.ts","../src/device/utils.ts"],"sourcesContent":["import type {\n HsmCertificate,\n PsdAuthChallengeResponse,\n PsdPairingData,\n PubKey,\n} from \"@ledgerhq/revault-api\";\nimport axios from \"axios\";\nimport axiosRetry from \"axios-retry\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport type { Logger } from \"@/logger\";\n\nimport { APPID_VAULT_ADMINISTRATOR, PATHS, SCRIPT_IDS, STR_ROLES } from \"./constants\";\nimport type { Device } from \"./types\";\n\ntype Options = {\n /**\n * device-api URL\n */\n deviceApiUrl: string;\n\n /**\n * salt used by device-api\n */\n salt: string;\n\n /**\n * seed generation function used for device-api device spawn\n */\n genSeed: (p: { salt: string; index: number }) => string | Promise<string>;\n};\n\nexport type ApiDevice = {\n /**\n * bind a device to the given device index\n */\n with: (index: number) => Device;\n};\n\nexport function createApiDevice(options: Options, logger: Logger): ApiDevice {\n const { genSeed } = options;\n const sessionId = uuidv4();\n const deviceApi = axios.create({ baseURL: options.deviceApiUrl });\n\n axiosRetry(deviceApi, {\n retryDelay: axiosRetry.linearDelay(1000),\n retries: 3,\n retryCondition: /* v8 ignore next -- @preserve */ () => true,\n onRetry:\n /* v8 ignore next -- @preserve */\n (retryCount, err) => {\n const formattedErr = `${err.code ?? `UNKNOWN`} on ${err.config?.method?.toUpperCase() ?? \"UNKNOWN_METHOD\"} ${err.config?.url ?? \"UNKNOWN_URL\"}`;\n logger.warning(\n `Retrying request to device-api (attempt ${retryCount}) - Cause: ${formattedErr}`,\n );\n },\n });\n\n /* v8 ignore next -- @preserve */\n deviceApi.interceptors.request.use(\n (config) => {\n logger.debug(\n `[device-api] ${config.method?.toUpperCase()} ${config.url}${config.data ? ` ${JSON.stringify(config.data)}` : \"\"}`,\n );\n if ([\"post\", \"put\"].includes(config.method!)) {\n // when interceptor is called in combination with axios-retry, config.data can be a string or an object\n // and we should return either a string or an object compatible with the original type\n const isStringMode = typeof config.data === \"string\";\n const data = (isStringMode ? JSON.parse(config.data) : config.data) as Record<\n string,\n unknown\n >;\n const enhancedData = {\n sessionID: sessionId, // Used to ensure dedicated session if someones else uses same seed\n psd_model: \"02\", // Stax\n version: 3, // Used to properly enable noise channel\n ...data,\n };\n config.data = isStringMode ? JSON.stringify(enhancedData) : enhancedData;\n }\n return config;\n },\n (error: Error) => Promise.reject(error),\n );\n\n return {\n with: (index: number): Device => {\n const __seed = genSeed({ salt: options.salt, index });\n\n const getSeed = async (): Promise<string> => {\n if (typeof __seed === \"string\") return Promise.resolve(__seed);\n return __seed;\n };\n\n const authenticate = async ({\n challenge,\n workspaceName,\n }: {\n challenge: PsdAuthChallengeResponse;\n workspaceName: string;\n }): Promise<string> => {\n const role = challenge.role;\n if (role === \"READ_ONLY_API_KEY\")\n throw new Error(\"Invalid role for authenticate: READ_ONLY_API_KEY\");\n const { data } = await deviceApi.post<string>(\"/authenticate\", {\n seed: await getSeed(),\n challenge: Buffer.from(challenge.challenge, \"base64\").toString(\"hex\"),\n application: APPID_VAULT_ADMINISTRATOR,\n key_handle: challenge.keyHandle,\n name: challenge.name,\n role: STR_ROLES[role],\n type: \"02\", // Stax\n workspaceName,\n });\n return data;\n };\n\n const finalizePairingHandshake = async (params: {\n handshake: string;\n partitionId: string;\n }): Promise<string> => {\n const { handshake, partitionId } = params;\n const payload = { seed: await getSeed(), handshake, ciphertext: partitionId };\n const res = await deviceApi.post<string>(\"/finalize-pairing-handshake\", payload);\n return res.data;\n };\n\n const generateSeedFragment = async (): Promise<string> => {\n const payload = {\n seed: await getSeed(),\n path: PATHS.KEY_MATERIAL,\n goal: 0, // seed fragment\n };\n const { data } = await deviceApi.post<string>(\"/generate-key-component\", payload);\n return data;\n };\n\n const generateWrappingKeyFragment = async (): Promise<string> => {\n const goal = 1; // means Wrapping Key\n const payload = { seed: await getSeed(), goal, path: PATHS.KEY_MATERIAL };\n const res = await deviceApi.post<string>(\"/generate-key-fragments\", payload);\n return Buffer.from(res.data, \"hex\").toString(\"base64\");\n };\n\n const getAttestation = async (): Promise<{\n attestation: {\n codeHash: string;\n attestationPub: string;\n certificate: string;\n };\n buffer: Buffer;\n }> => {\n const { data: attestationStr } = await deviceApi.post<string>(\"/get-attestation\", {\n seed: await getSeed(),\n });\n const attestationBuffer = Buffer.from(attestationStr, \"hex\");\n const certLen = attestationBuffer.readInt8(32 + 65 + 1);\n return {\n attestation: {\n codeHash: attestationBuffer.slice(0, 32).toString(\"base64\"),\n attestationPub: attestationBuffer.slice(32, 32 + 65).toString(\"base64\"),\n certificate: attestationBuffer.slice(32 + 65, 32 + 65 + 2 + certLen).toString(\"base64\"),\n },\n buffer: attestationBuffer,\n };\n };\n\n const getConfidentialityKey = async (): Promise<{\n confidentialityKeyCurve25519: string;\n confidentialityKeySignature: string;\n }> => {\n const res = await deviceApi.post<{\n confidentiality_key_curve25519: string;\n confidentiality_key_signature: string;\n }>(\"/get-confidentiality-key\", { seed: await getSeed() });\n return {\n confidentialityKeyCurve25519: res.data.confidentiality_key_curve25519,\n confidentialityKeySignature: res.data.confidentiality_key_signature,\n };\n };\n\n const getConfidentialityPubKey = async (): Promise<{ pubKey: string; signature: string }> => {\n return getPublicKey({ path: PATHS.CONFIDENTIALITY });\n };\n\n const getDeviceUserId = async (): Promise<string> => {\n const res = await deviceApi.post<{ blue_device_id: string }>(\"/blue-device-id\", {\n seed: await getSeed(),\n });\n return res.data.blue_device_id.toUpperCase();\n };\n\n const getU2FPubKey = async (): Promise<{ pubKey: string; signature: string }> => {\n return getPublicKey({ path: PATHS.U2F });\n };\n\n const getValidationPubKey = async (): Promise<{ pubKey: string; signature: string }> => {\n return getPublicKey({ path: PATHS.VALIDATION });\n };\n\n const hasPairing = async (): Promise<boolean> => {\n const res = await deviceApi.post<string[]>(\"/get-partition-ids\", { seed: await getSeed() });\n return res.data.length > 0;\n };\n\n const initPairingHandshake = async (): Promise<{ pubKey: string; signature: string }> => {\n const { data } = await deviceApi.post<{ attestation: string; pubKey: string }>(\n \"/initiate-pairing-handshake\",\n { seed: await getSeed() },\n );\n return {\n pubKey: data.pubKey,\n signature: Buffer.from(data.attestation, \"hex\").toString(\"base64\"),\n };\n };\n\n const openSession = async (params: {\n secureChannel: { pubKey: PubKey; certificate: HsmCertificate };\n }): Promise<void> => {\n const { secureChannel } = params;\n const signature = Buffer.from(secureChannel.certificate.signature, \"base64\");\n const attestationPubKey = Buffer.from(secureChannel.certificate.attestationPub, \"base64\");\n const attestationCertificate = Buffer.from(secureChannel.certificate.certificate, \"base64\");\n const attestation = Buffer.concat([\n Buffer.from([signature.length]),\n signature,\n attestationPubKey,\n Buffer.from([attestationCertificate.length]),\n attestationCertificate,\n ]);\n const payload = {\n seed: await getSeed(),\n path: PATHS.CONFIDENTIALITY,\n pubKey: secureChannel.pubKey,\n attestation: attestation.toString(\"hex\"),\n scriptId: SCRIPT_IDS.INIT_SESSION,\n };\n const { data: deviceResponse } = await deviceApi.post<string>(\"/open-session\", payload);\n if (deviceResponse !== \"9000\") {\n throw new Error(`device-api device failed with code: ${deviceResponse}`);\n }\n };\n\n const register = async (params: {\n challenge: string;\n u2fRegisterData: string;\n name: string;\n role: \"ADMIN\" | \"SHARED_OWNER\" | \"OPERATOR\";\n }): Promise<{\n u2fRegister: Buffer;\n keyHandle: Buffer;\n rfu: number;\n pubKey: string;\n }> => {\n const { challenge, u2fRegisterData, name, role } = params;\n const payload = {\n seed: await getSeed(),\n challenge,\n name,\n role: STR_ROLES[role],\n hsm_data: u2fRegisterData,\n type: \"02\", // Stax\n application: APPID_VAULT_ADMINISTRATOR,\n };\n const { data } = await deviceApi.post<string>(\"/register\", payload);\n const response = Buffer.from(data, \"hex\");\n let i = 0;\n const rfu = response.slice(i, i + 1)[0]!;\n i += 1;\n const pubKey = response.slice(i, i + 65).toString(\"hex\");\n i += 65;\n const keyHandleLength = response.slice(i, i + 1)[0]!;\n i++;\n const keyHandle = response.slice(i, i + keyHandleLength);\n i += keyHandleLength;\n return {\n u2fRegister: response.slice(0, response.length - 2),\n keyHandle,\n rfu,\n pubKey,\n };\n };\n\n const registerData = async (params: { challenge: string }): Promise<string> => {\n const { challenge } = params;\n const payload = { seed: await getSeed(), challenge };\n const res = await deviceApi.post<string>(\"/u2f-register-data\", payload);\n return res.data;\n };\n\n const setPairing = async ({ pairing }: { pairing: PsdPairingData }): Promise<void> => {\n const payload = {\n seed: await getSeed(),\n blob: pairing.blob,\n pairing: {\n bootstrap_enabled: pairing.pairing.bootstrapEnabled,\n partition_key: pairing.pairing.partitionKey,\n workspace_name: pairing.pairing.workspaceName,\n },\n partition_key_attestation: {\n code_hash: pairing.partitionKeyAttestation.codeHash,\n attestation_pub: pairing.partitionKeyAttestation.attestationPub,\n certificate: pairing.partitionKeyAttestation.certificate,\n signature: pairing.partitionKeyAttestation.signature,\n },\n };\n await deviceApi.post(\"/set-partition-key\", payload);\n };\n\n const startKKPatternAsResponder = async (params: {\n handshake: string;\n handshakeAttestation: HsmCertificate;\n partitionId: string;\n }): Promise<{ handshake: string; signature: string }> => {\n const payload = {\n seed: await getSeed(),\n script_id: SCRIPT_IDS.ACCOUNT_MANAGER_SESSION,\n handshake: params.handshake,\n // for device-api it's normal to have empty string as handshake_attestation\n handshake_attestation: \"\",\n partition_id: params.partitionId,\n };\n const { data } = await deviceApi.post<string>(\"/start-kk-pattern-as-responder\", payload);\n const buffer = Buffer.from(data, \"hex\");\n const dataLength = buffer.readInt8(0);\n return {\n handshake: buffer.slice(1, dataLength + 1).toString(\"base64\"),\n signature: buffer.slice(dataLength + 1).toString(\"base64\"),\n };\n };\n\n const startKPatternAsResponder = async (params: {\n handshake: string;\n handshakeAttestation: HsmCertificate;\n partitionId: string;\n }): Promise<void> => {\n const { handshake, partitionId } = params;\n const payload = {\n seed: await getSeed(),\n script_id: SCRIPT_IDS.ACCOUNT_MANAGER_SESSION,\n handshake,\n // for device-api it's normal to have empty string as handshake_attestation\n handshake_attestation: \"\",\n partition_id: partitionId,\n };\n const { data: deviceResponse } = await deviceApi.post<string>(\n \"/start-k-pattern-as-responder\",\n payload,\n );\n if (deviceResponse !== \"9000\") {\n throw new Error(`device-api device failed with code: ${deviceResponse}`);\n }\n };\n\n const getPublicKey = async (params: {\n path: string;\n }): Promise<{ pubKey: string; signature: string }> => {\n const { path } = params;\n type DeviceApiGetPubKeyResponse = { attestation: string; pubKey: string };\n const payload = { seed: await getSeed(), secp256k1: true, path };\n const res = await deviceApi.post<DeviceApiGetPubKeyResponse>(\"/get-public-key\", payload);\n return {\n pubKey: res.data.pubKey,\n signature: Buffer.from(res.data.attestation, \"hex\").toString(\"base64\"),\n };\n };\n\n const validateVaultOperation = async (params: { actions: string[] }): Promise<string> => {\n const { actions } = params;\n const payload = {\n seed: await getSeed(),\n path: PATHS.VALIDATION,\n actions,\n };\n const { data: signature } = await deviceApi.post<string>(\"/validate-op\", payload);\n return signature;\n };\n\n const sendAPDU = (_apdu: string): Promise<string> => {\n logger.info(\"Can't send arbitrary APDU to software device\");\n return Promise.resolve(\"9000\");\n };\n\n const getVersion = async (): Promise<string> => {\n return \"1.2.3\";\n };\n\n const poll = async (): Promise<{ isAppOpened: boolean }> => {\n await new Promise((r) => setTimeout(r, 1e3));\n return { isAppOpened: true };\n };\n\n const pollApp = async (): Promise<string> => {\n await new Promise((r) => setTimeout(r, 1e3));\n return \"9000\";\n };\n\n return {\n authenticate,\n finalizePairingHandshake,\n generateSeedFragment,\n generateWrappingKeyFragment,\n getAttestation,\n getConfidentialityKey,\n getConfidentialityPubKey,\n getDeviceUserId,\n getU2FPubKey,\n getValidationPubKey,\n hasPairing,\n initPairingHandshake,\n openSession,\n register,\n registerData,\n setPairing,\n startKKPatternAsResponder,\n startKPatternAsResponder,\n validateVaultOperation,\n getVersion,\n sendAPDU,\n poll,\n pollApp,\n };\n },\n };\n}\n","export const PATHS = {\n U2F: \"5655636'/5583430'\",\n CONFIDENTIALITY: \"5655636'/4410950'\",\n KEY_MATERIAL: \"5655636'/4932953'\",\n VALIDATION: \"5655636'/5652812'\",\n} as const;\n\nexport const STATUS_LENGTH = 2;\n\nexport const SCRIPT_IDS = {\n INIT_SESSION: 3,\n ACCOUNT_MANAGER_SESSION: 2,\n} as const;\n\nexport const STR_ROLES: Record<\"OPERATOR\" | \"ADMIN\" | \"SHARED_OWNER\", string> = {\n OPERATOR: \"00\",\n ADMIN: \"01\",\n SHARED_OWNER: \"02\",\n} as const;\n\nexport const APPID_VAULT_ADMINISTRATOR =\n \"ad5be1a1fe011ce7f53ae081a22ae000a42021f3f94106a3bac9f76e8230e4b9\";\n\nconst all61xxStatus = [];\nfor (let i = 0x6100; i <= 0x61ff; i++) {\n all61xxStatus.push(i);\n}\n\nexport const PAGINATED_STATUS = all61xxStatus;\nexport const STREAMING_RESPONSE = 0x02;\nexport const STREAMING_NEXT_ACTION = 0x01;\n","// biome-ignore-all lint: outside copy-paste, not worth fixing\n// ------------------------------------------------------------------------------------------------\n// ------------------------------------------------------------------------------------------------\n// THIS IS SOME HORRIBLE CODE IMPORTED JUST\n// FOR THE SAKE OF NOT IMPORTING UGLY, WICKED, AND\n// BROKEN @ledgerhq/live-* LIBRARIES\n//\n// IT'S MEANT TO BE CONSIDERED AS A BLACK BOX\n// ------------------------------------------------------------------------------------------------\n// ------------------------------------------------------------------------------------------------\nimport {\n BluetoothRequired,\n CantOpenDevice,\n DeviceHalted,\n FirmwareOrAppUpdateRequired,\n TransportInterfaceNotAvailable,\n TransportStatusError,\n TransportWebUSBGestureRequired,\n} from \"@ledgerhq/errors\";\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport { Observable, throwError, timer } from \"rxjs\";\nimport { catchError, mergeMap, retryWhen } from \"rxjs/operators\";\n\nconst initialErrorRemapping = (error: Error): Observable<never> =>\n throwError(\n error && error instanceof TransportStatusError && error.statusCode === 0x6faa\n ? new DeviceHalted(error.message)\n : error instanceof TransportStatusError && error.statusCode === 0x6b00\n ? new FirmwareOrAppUpdateRequired(error.message)\n : error,\n );\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nconst never = new Promise(() => {});\n\ntype Discovery = Observable<{\n type: \"add\" | \"remove\";\n id: string;\n name: string;\n}>;\n\nexport type TransportModule = {\n // unique transport name that identify the transport module\n id: string;\n // open a device by an id, this id must be unique across all modules\n // you can typically prefix it with `something|` that identify it globally\n // returns falsy if the transport module can't handle this id\n // here, open means we want to START doing something with the transport\n open: (id: string) => Promise<Transport> | null | undefined;\n // here, close means we want to STOP doing something with the transport\n close?: (transport: Transport, id: string) => Promise<void> | null | undefined;\n // disconnect/interrupt a device connection globally\n // returns falsy if the transport module can't handle this id\n disconnect: (id: string) => Promise<void> | null | undefined;\n // optional observable that allows to discover a transport\n discovery?: Discovery;\n};\n\nconst modules: TransportModule[] = [];\n\nexport const registerTransportModule = (module: TransportModule): void => {\n modules.push(module);\n};\n\nexport const close = (transport: Transport, deviceId: string): Promise<void> => {\n for (const m of modules) {\n const p = m.close?.(transport, deviceId);\n if (p) return p;\n }\n // fallback on an actual close\n return transport.close();\n};\n\nexport const open = (deviceId: string): Promise<Transport> => {\n for (const m of modules) {\n const p = m.open(deviceId);\n if (p) return p;\n }\n return Promise.reject(new Error(`Can't find handler to open ${deviceId}`));\n};\n\nconst transportFinally =\n (cleanup: () => Promise<void>) =>\n <T>(observable: Observable<T>): Observable<T> =>\n // @ts-expect-error typescript not checking against the instanceof\n Observable.create((o) => {\n let done = false;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const finalize = (): any => {\n if (done) return never;\n done = true;\n return cleanup();\n };\n\n const sub = observable.subscribe({\n next: (e) => o.next(e),\n complete: () => {\n void finalize().then(() => o.complete());\n },\n error: (e) => {\n void finalize().then(() => o.error(e));\n },\n });\n return () => {\n sub.unsubscribe();\n void finalize();\n };\n });\n\ntype AccessHook = () => () => void;\n\nconst accessHooks: AccessHook[] = [];\n\nconst deviceQueues = {};\n\nexport const withDevice =\n (deviceId: string) =>\n <T>(job: (t: Transport) => Observable<T>): Observable<T> =>\n new Observable((o) => {\n // @ts-expect-error typescript not checking against the instanceof\n let unsubscribed;\n // @ts-expect-error typescript not checking against the instanceof\n let sub;\n // @ts-expect-error typescript not checking against the instanceof\n const deviceQueue = deviceQueues[deviceId] ?? Promise.resolve();\n\n // @ts-expect-error typescript not checking against the instanceof\n const finalize = (transport, cleanups): Promise<void> =>\n close(transport, deviceId)\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n .catch(() => {})\n .then(() => {\n // @ts-expect-error typescript not checking against the instanceof\n cleanups.forEach((c) => c());\n });\n\n // when we'll finish all the current job, we'll call finish\n // @ts-expect-error typescript not checking against the instanceof\n let finish;\n // this new promise is the next exec queue\n // @ts-expect-error typescript not checking against the instanceof\n deviceQueues[deviceId] = new Promise((resolve) => {\n finish = resolve;\n });\n // for any new job, we'll now wait the exec queue to be available\n deviceQueue\n .then(() => open(deviceId)) // open the transport\n // @ts-expect-error typescript not checking against the instanceof\n .then(async (transport) => {\n // @ts-expect-error typescript not checking against the instanceof\n if (unsubscribed) {\n // it was unsubscribed prematurely\n // @ts-expect-error typescript not checking against the instanceof\n return finalize(transport, [finish]);\n }\n\n if (\n transport.requestConnectionPriority &&\n typeof transport.requestConnectionPriority === \"function\"\n ) {\n await transport.requestConnectionPriority(\"High\");\n }\n\n return transport;\n })\n // @ts-expect-error typescript not checking against the instanceof\n .catch((e) => {\n // @ts-expect-error typescript not checking against the instanceof\n finish();\n if (e instanceof BluetoothRequired) throw e;\n if (e instanceof TransportWebUSBGestureRequired) throw e;\n if (e instanceof TransportInterfaceNotAvailable) throw e;\n throw new CantOpenDevice(e.message);\n })\n // @ts-expect-error typescript not checking against the instanceof\n .then((transport) => {\n if (!transport) return;\n\n // @ts-expect-error typescript not checking against the instanceof\n if (unsubscribed) {\n // it was unsubscribed prematurely\n // @ts-expect-error typescript not checking against the instanceof\n return finalize(transport, [finish]);\n }\n\n const cleanups = accessHooks.map((hook) => hook());\n sub = job(transport) // $FlowFixMe\n .pipe(\n catchError(initialErrorRemapping),\n // $FlowFixMe\n transportFinally(() =>\n // @ts-expect-error typescript not checking against the instanceof\n finalize(transport, [...cleanups, finish]),\n ),\n )\n .subscribe(o);\n })\n // @ts-expect-error typescript not checking against the instanceof\n .catch((error) => o.error(error));\n return () => {\n unsubscribed = true;\n // @ts-expect-error typescript not checking against the instanceof\n if (sub) sub.unsubscribe();\n };\n });\n\nconst WITH_DEVICE_POLLING_DELAY = 500;\n\nexport const retryWhileErrors =\n (acceptError: (arg0: Error) => boolean) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (attempts: Observable<any>): Observable<any> =>\n attempts.pipe(\n mergeMap((error) => {\n if (!acceptError(error)) {\n return throwError(error);\n }\n\n return timer(WITH_DEVICE_POLLING_DELAY);\n }),\n );\n\nexport const withDevicePolling =\n (deviceId: string) =>\n <T>(\n job: (arg0: Transport) => Observable<T>,\n acceptError: (arg0: Error) => boolean = () => false,\n ): Observable<T> =>\n withDevice(deviceId)(job).pipe(retryWhen(retryWhileErrors(acceptError)));\n","import { TransportStatusError } from \"@ledgerhq/errors\";\n\nexport const isTransportStatusError = (error: unknown): error is TransportStatusError => {\n return (\n error instanceof TransportStatusError ||\n (error instanceof Error && \"statusCode\" in error && error.message.startsWith(\"Ledger device:\"))\n );\n};\n\nconst CANCEL_STATUS_CODES = [\n 0x6985, // cancel on Ledger Blue\n\n // STAX\n 0xb00c, // cancel collect wk fragment\n 0xb00d, // cancel user registration\n 0xb010, // cancel review\n 0xb012, // cancel master seed generation\n 0xb013, // cancel login\n];\n\nexport const isDeviceCancelError = (error: Error): boolean => {\n return isTransportStatusError(error) && CANCEL_STATUS_CODES.includes(error.statusCode);\n};\n"],"mappings":";AAMA,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,SAAS,MAAM,cAAc;;;ACRtB,IAAM,QAAQ;AAAA,EACnB,KAAK;AAAA,EACL,iBAAiB;AAAA,EACjB,cAAc;AAAA,EACd,YAAY;AACd;AAEO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A;AAAA,EACA;AAAA;AACF;AAEO,IAAM,sBAAsB,CAAC,UAA0B;AAC5D,SAAO,uBAAuB,KAAK,KAAK,oBAAoB,SAAS,MAAM,UAAU;AACvF;","names":["TransportStatusError"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/crypto/utils.ts
|
|
2
|
-
import crypto from "crypto";
|
|
3
2
|
import elliptic2 from "elliptic";
|
|
4
3
|
import * as jose from "jose";
|
|
5
4
|
|
|
@@ -18,7 +17,7 @@ var ECPrivateKeyASN = asn1.define("ECPrivateKey", function() {
|
|
|
18
17
|
});
|
|
19
18
|
var ECPrivateKey8ASN = asn1.define(
|
|
20
19
|
"ECPrivateKey",
|
|
21
|
-
/* v8 ignore
|
|
20
|
+
/* v8 ignore next -- @preserve */
|
|
22
21
|
function() {
|
|
23
22
|
const self = this;
|
|
24
23
|
self.seq().obj(
|
|
@@ -28,7 +27,6 @@ var ECPrivateKey8ASN = asn1.define(
|
|
|
28
27
|
self.key("attributes").explicit(0).bitstr().optional()
|
|
29
28
|
);
|
|
30
29
|
}
|
|
31
|
-
/* v8 ignore stop */
|
|
32
30
|
);
|
|
33
31
|
var SubjectPublicKeyInfoASN = asn1.define("SubjectPublicKeyInfo", function() {
|
|
34
32
|
const self = this;
|
|
@@ -58,14 +56,14 @@ var KeyEncoder = class {
|
|
|
58
56
|
constructor(options) {
|
|
59
57
|
if (typeof options === "string") {
|
|
60
58
|
if (options !== "secp256k1" && options !== "p256") {
|
|
61
|
-
throw new Error(
|
|
59
|
+
throw new Error(`Unknown curve ${options}`);
|
|
62
60
|
}
|
|
63
61
|
options = curves[options];
|
|
64
62
|
}
|
|
65
63
|
this.options = options;
|
|
66
64
|
this.algorithmID = [1, 2, 840, 10045, 2, 1];
|
|
67
65
|
}
|
|
68
|
-
/* v8 ignore
|
|
66
|
+
/* v8 ignore next -- @preserve */
|
|
69
67
|
PKCS1toPKCS8(privateKey) {
|
|
70
68
|
return {
|
|
71
69
|
version: new BN(0),
|
|
@@ -76,7 +74,6 @@ var KeyEncoder = class {
|
|
|
76
74
|
}
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
|
-
/* v8 ignore stop */
|
|
80
77
|
privateKeyObject(rawPrivateKey, rawPublicKey) {
|
|
81
78
|
const privateKeyObject = {
|
|
82
79
|
version: new BN(1),
|
|
@@ -115,6 +112,7 @@ var KeyEncoder = class {
|
|
|
115
112
|
privateKeyObject = this.privateKeyObject(privateKey, rawPublicKey);
|
|
116
113
|
break;
|
|
117
114
|
}
|
|
115
|
+
/* v8 ignore next -- @preserve */
|
|
118
116
|
case "der":
|
|
119
117
|
if (typeof privateKey === "string") {
|
|
120
118
|
privateKey = Buffer.from(privateKey, "hex");
|
|
@@ -131,7 +129,7 @@ var KeyEncoder = class {
|
|
|
131
129
|
this.options.privatePEMOptions
|
|
132
130
|
);
|
|
133
131
|
break;
|
|
134
|
-
/* v8 ignore
|
|
132
|
+
/* v8 ignore next -- @preserve */
|
|
135
133
|
default:
|
|
136
134
|
throw new Error("invalid private key format");
|
|
137
135
|
}
|
|
@@ -162,7 +160,7 @@ var KeyEncoder = class {
|
|
|
162
160
|
});
|
|
163
161
|
}
|
|
164
162
|
break;
|
|
165
|
-
/* v8 ignore
|
|
163
|
+
/* v8 ignore next -- @preserve */
|
|
166
164
|
default:
|
|
167
165
|
throw new Error("invalid destination format for private key");
|
|
168
166
|
}
|
|
@@ -177,6 +175,7 @@ var KeyEncoder = class {
|
|
|
177
175
|
}
|
|
178
176
|
publicKeyObject = this.publicKeyObject(publicKey);
|
|
179
177
|
break;
|
|
178
|
+
/* v8 ignore next -- @preserve */
|
|
180
179
|
case "der":
|
|
181
180
|
if (typeof publicKey === "string") {
|
|
182
181
|
publicKey = Buffer.from(publicKey, "hex");
|
|
@@ -193,7 +192,7 @@ var KeyEncoder = class {
|
|
|
193
192
|
this.options.publicPEMOptions
|
|
194
193
|
);
|
|
195
194
|
break;
|
|
196
|
-
/* v8 ignore
|
|
195
|
+
/* v8 ignore next -- @preserve */
|
|
197
196
|
default:
|
|
198
197
|
throw new Error("invalid public key format");
|
|
199
198
|
}
|
|
@@ -208,7 +207,7 @@ var KeyEncoder = class {
|
|
|
208
207
|
"pem",
|
|
209
208
|
this.options.publicPEMOptions
|
|
210
209
|
);
|
|
211
|
-
/* v8 ignore
|
|
210
|
+
/* v8 ignore next -- @preserve */
|
|
212
211
|
default:
|
|
213
212
|
throw new Error("invalid destination format for public key");
|
|
214
213
|
}
|
|
@@ -216,6 +215,7 @@ var KeyEncoder = class {
|
|
|
216
215
|
};
|
|
217
216
|
|
|
218
217
|
// src/crypto/utils.ts
|
|
218
|
+
import crypto from "crypto";
|
|
219
219
|
function extractPublicKey(pemKey) {
|
|
220
220
|
const pem = pemKey.split("\n");
|
|
221
221
|
pem.shift();
|
|
@@ -266,4 +266,6 @@ export {
|
|
|
266
266
|
genKeys,
|
|
267
267
|
sign
|
|
268
268
|
};
|
|
269
|
-
|
|
269
|
+
/* v8 ignore else -- @preserve */
|
|
270
|
+
/* v8 ignore if -- @preserve */
|
|
271
|
+
//# sourceMappingURL=chunk-73OX5XDM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto/utils.ts","../src/crypto/key-encoder.ts"],"sourcesContent":["import elliptic from \"elliptic\";\nimport * as jose from \"jose\";\n\nimport { KeyEncoder } from \"./key-encoder\";\nimport type { GeneratedKeys } from \"./types\";\nimport crypto from \"node:crypto\";\n\nfunction extractPublicKey(pemKey: string): string {\n // convert the PEM formatted public key to raw public key in X9.62 uncompressed format\n // this is an oversimplified method and may not work with different curves or PEM formats\n const pem = pemKey.split(\"\\n\");\n pem.shift(); // remove the first line (BEGIN PUBLIC KEY)\n pem.pop(); // remove the last line (END PUBLIC KEY)\n // convert base64 to buffer\n const keyBuffer = Buffer.from(pem.join(\"\"), \"base64\");\n // assuming the first 26 bytes are the header for the SPKI formatted key.\n // the actual key should begin after this header.\n const actualKeyBuffer = keyBuffer.slice(26);\n return actualKeyBuffer.toString(\"hex\").toUpperCase();\n}\n\nfunction hexToPem(hexString: string, { isPrivate = true } = {}): string {\n const keyEncoder = new KeyEncoder(\"p256\");\n if (isPrivate) {\n return keyEncoder.encodePrivate(hexString, \"raw\", \"pem\");\n }\n return keyEncoder.encodePublic(hexString, \"raw\", \"pem\");\n}\n\n/**\n * If `entropy` is passed, will generate keys pair deterministically\n * else, random keys pair generated\n */\nexport function genKeys(entropy?: string): GeneratedKeys {\n if (entropy) {\n const ec = new elliptic.ec(\"p256\");\n const hashedEntropy = crypto.createHash(\"sha256\").update(entropy).digest(\"hex\");\n const keyPair = ec.genKeyPair({\n entropy: Buffer.from(hashedEntropy, \"hex\"),\n });\n return {\n privateKey: String(hexToPem(keyPair.getPrivate(\"hex\"))),\n publicKey: String(hexToPem(keyPair.getPublic(\"hex\"), { isPrivate: false })),\n hexPubKey: extractPublicKey(String(hexToPem(keyPair.getPublic(\"hex\"), { isPrivate: false }))),\n };\n }\n const { publicKey, privateKey } = crypto.generateKeyPairSync(\"ec\", {\n namedCurve: \"P-256\",\n publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n privateKeyEncoding: { type: \"sec1\", format: \"pem\" },\n });\n const hexPubKey = extractPublicKey(publicKey);\n return {\n privateKey,\n publicKey,\n hexPubKey,\n };\n}\n\nexport const sign = async (privateKeyPem: string, base64Challenge: string): Promise<string> => {\n // Decode base64url challenge to bytes\n const challengeDataBytes = jose.base64url.decode(base64Challenge);\n\n // For EC private key format, we need to use a different import method\n // Since jose doesn't support SEC1 format directly, let's use Node.js crypto\n // Create a KeyObject from the EC private key\n const privateKey = crypto.createPrivateKey(privateKeyPem);\n\n // Use jose with the KeyObject\n return await new jose.CompactSign(challengeDataBytes)\n .setProtectedHeader({ alg: \"ES256\", typ: \"JWT\" })\n .sign(privateKey);\n};\n","// ========================================================================== //\n// //\n// DISCLAIMER //\n// //\n// This code has been blindly copy-pasted from: //\n// https://github.com/LedgerHQ/pkey-ts //\n// //\n// ========================================================================== //\n//\n// @ts-expect-error this library does not ship types\nimport asn1 from \"asn1.js\";\nimport BN from \"bn.js\";\nimport elliptic from \"elliptic\";\n\n/* cspell:disable */\nconst ECPrivateKeyASN = asn1.define(\"ECPrivateKey\", function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"version\").int(),\n self.key(\"privateKey\").octstr(),\n self.key(\"parameters\").explicit(0).objid().optional(),\n self.key(\"publicKey\").explicit(1).bitstr().optional(),\n );\n});\n\nconst ECPrivateKey8ASN = asn1.define(\n \"ECPrivateKey\",\n /* v8 ignore next -- @preserve */\n function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"version\").int(),\n self\n .key(\"privateKeyAlgorithm\")\n .seq()\n .obj(self.key(\"ecPublicKey\").objid(), self.key(\"curve\").objid()),\n self.key(\"privateKey\").octstr().contains(ECPrivateKeyASN),\n self.key(\"attributes\").explicit(0).bitstr().optional(),\n );\n },\n);\n\nconst SubjectPublicKeyInfoASN = asn1.define(\"SubjectPublicKeyInfo\", function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"algorithm\").seq().obj(self.key(\"id\").objid(), self.key(\"curve\").objid()),\n self.key(\"pub\").bitstr(),\n );\n});\n\ntype CurveOptions = {\n curveParameters: number[];\n privatePEMOptions: { label: string };\n publicPEMOptions: { label: string };\n curve: elliptic.ec;\n};\n\nconst curves: Record<string, CurveOptions> = {\n secp256k1: {\n curveParameters: [1, 3, 132, 0, 10],\n privatePEMOptions: { label: \"EC PRIVATE KEY\" },\n publicPEMOptions: { label: \"PUBLIC KEY\" },\n curve: new elliptic.ec(\"secp256k1\"),\n },\n p256: {\n curveParameters: [1, 2, 840, 10045, 3, 1, 7], // OID for p256 curve\n privatePEMOptions: { label: \"EC PRIVATE KEY\" },\n publicPEMOptions: { label: \"PUBLIC KEY\" },\n curve: new elliptic.ec(\"p256\"),\n },\n};\n\ntype PrivateKeyPKCS1 = {\n version: BN;\n privateKey: Buffer;\n parameters: number[];\n publicKey?: {\n unused: number;\n data: Buffer;\n };\n};\n\ntype PrivateKeyPKCS8 = {\n version: BN;\n privateKey: PrivateKeyPKCS1;\n privateKeyAlgorithm: { ecPublicKey: number[]; curve: number[] };\n};\n\nexport type KeyFormat = \"raw\" | \"pem\" | \"der\";\n\nexport class KeyEncoder {\n algorithmID: number[];\n options: CurveOptions;\n\n constructor(options: string | CurveOptions) {\n /* v8 ignore else -- @preserve */\n if (typeof options === \"string\") {\n /* v8 ignore if -- @preserve */\n if (options !== \"secp256k1\" && options !== \"p256\") {\n throw new Error(`Unknown curve ${options}`);\n }\n options = curves[options]!;\n }\n this.options = options;\n this.algorithmID = [1, 2, 840, 10045, 2, 1];\n }\n\n /* v8 ignore next -- @preserve */\n private PKCS1toPKCS8(privateKey: PrivateKeyPKCS1): PrivateKeyPKCS8 {\n return {\n version: new BN(0),\n privateKey,\n privateKeyAlgorithm: {\n ecPublicKey: this.algorithmID,\n curve: privateKey.parameters,\n },\n };\n }\n\n privateKeyObject(rawPrivateKey: string, rawPublicKey: string): PrivateKeyPKCS1 {\n const privateKeyObject: PrivateKeyPKCS1 = {\n version: new BN(1),\n privateKey: Buffer.from(rawPrivateKey, \"hex\"),\n parameters: this.options.curveParameters,\n };\n\n /* v8 ignore else -- @preserve */\n if (rawPublicKey) {\n privateKeyObject.publicKey = {\n unused: 0,\n data: Buffer.from(rawPublicKey, \"hex\"),\n };\n }\n\n return privateKeyObject;\n }\n\n publicKeyObject(rawPublicKey: string): {\n algorithm: { id: number[]; curve: number[] };\n pub: { unused: number; data: Buffer };\n } {\n return {\n algorithm: {\n id: this.algorithmID,\n curve: this.options.curveParameters,\n },\n pub: {\n unused: 0,\n data: Buffer.from(rawPublicKey, \"hex\"),\n },\n };\n }\n\n encodePrivate(\n privateKey: string | Buffer,\n originalFormat: KeyFormat,\n destinationFormat: KeyFormat,\n destinationFormatType: \"pkcs8\" | \"pkcs1\" = \"pkcs1\",\n ): string {\n let privateKeyObject: PrivateKeyPKCS1;\n\n /* Parse the incoming private key and convert it to a private key object */\n switch (originalFormat) {\n case \"raw\": {\n if (typeof privateKey !== \"string\") {\n throw new Error(\"private key must be a string\");\n }\n const keyPair = this.options.curve.keyFromPrivate(privateKey, \"hex\");\n const rawPublicKey = keyPair.getPublic(\"hex\");\n privateKeyObject = this.privateKeyObject(privateKey, rawPublicKey);\n break;\n }\n /* v8 ignore next -- @preserve */\n case \"der\":\n if (typeof privateKey === \"string\") {\n privateKey = Buffer.from(privateKey, \"hex\");\n }\n privateKeyObject = ECPrivateKeyASN.decode(privateKey, \"der\");\n break;\n case \"pem\":\n if (typeof privateKey !== \"string\") {\n throw new Error(\"private key must be a string\");\n }\n privateKeyObject = ECPrivateKeyASN.decode(\n privateKey,\n \"pem\",\n this.options.privatePEMOptions,\n );\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid private key format\");\n }\n\n /* Export the private key object to the desired format */\n switch (destinationFormat) {\n case \"raw\":\n if (destinationFormatType === \"pkcs1\") {\n return privateKeyObject.privateKey.toString(\"hex\");\n } else if (destinationFormatType === \"pkcs8\") {\n return this.PKCS1toPKCS8(privateKeyObject).privateKey.privateKey.toString(\"hex\");\n }\n break;\n case \"der\":\n if (destinationFormatType === \"pkcs1\") {\n return ECPrivateKeyASN.encode(privateKeyObject, \"der\").toString(\"hex\");\n } else if (destinationFormatType === \"pkcs8\") {\n return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), \"der\").toString(\n \"hex\",\n );\n }\n break;\n case \"pem\":\n if (destinationFormatType === \"pkcs1\") {\n return ECPrivateKeyASN.encode(privateKeyObject, \"pem\", this.options.privatePEMOptions);\n } else if (destinationFormatType === \"pkcs8\") {\n return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), \"pem\", {\n ...this.options.privatePEMOptions,\n label: \"PRIVATE KEY\",\n });\n }\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid destination format for private key\");\n }\n\n throw new Error(\"unsupported destination format or type\");\n }\n\n encodePublic(\n publicKey: string | Buffer,\n originalFormat: KeyFormat,\n destinationFormat: KeyFormat,\n ): string {\n // biome-ignore lint/suspicious/noImplicitAnyLet: melting pot object\n let publicKeyObject;\n\n switch (originalFormat) {\n case \"raw\":\n if (typeof publicKey !== \"string\") {\n throw new Error(\"public key must be a string\");\n }\n publicKeyObject = this.publicKeyObject(publicKey);\n break;\n /* v8 ignore next -- @preserve */\n case \"der\":\n if (typeof publicKey === \"string\") {\n publicKey = Buffer.from(publicKey, \"hex\");\n }\n publicKeyObject = SubjectPublicKeyInfoASN.decode(publicKey, \"der\");\n break;\n case \"pem\":\n if (typeof publicKey !== \"string\") {\n throw new Error(\"public key must be a string\");\n }\n publicKeyObject = SubjectPublicKeyInfoASN.decode(\n publicKey,\n \"pem\",\n this.options.publicPEMOptions,\n );\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid public key format\");\n }\n\n /* Export the private key object to the desired format */\n switch (destinationFormat) {\n case \"raw\":\n return publicKeyObject.pub.data.toString(\"hex\");\n case \"der\":\n return SubjectPublicKeyInfoASN.encode(publicKeyObject, \"der\").toString(\"hex\");\n case \"pem\":\n return SubjectPublicKeyInfoASN.encode(\n publicKeyObject,\n \"pem\",\n this.options.publicPEMOptions,\n );\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid destination format for public key\");\n }\n }\n}\n/* cspell:enable */\n"],"mappings":";AAAA,OAAOA,eAAc;AACrB,YAAY,UAAU;;;ACStB,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,cAAc;AAGrB,IAAM,kBAAkB,KAAK,OAAO,gBAAgB,WAAY;AAG9D,QAAM,OAAO;AACb,OACG,IAAI,EACJ;AAAA,IACC,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E,MAAM,QAAQ,QAAQ,MAAM;AAAA,EACpD,CAAC;AACD,QAAM,YAAY,iBAAiB,SAAS;AAC5C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,OAAO,OAAO,eAAuB,oBAA6C;AAE7F,QAAM,qBAA0B,eAAU,OAAO,eAAe;AAKhE,QAAM,aAAa,OAAO,iBAAiB,aAAa;AAGxD,SAAO,MAAM,IAAS,iBAAY,kBAAkB,EACjD,mBAAmB,EAAE,KAAK,SAAS,KAAK,MAAM,CAAC,EAC/C,KAAK,UAAU;AACpB;","names":["elliptic","elliptic"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/crypto/utils.ts
|
|
2
|
-
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
3
2
|
var _elliptic = require('elliptic'); var _elliptic2 = _interopRequireDefault(_elliptic);
|
|
4
3
|
var _jose = require('jose'); var jose = _interopRequireWildcard(_jose);
|
|
5
4
|
|
|
@@ -18,7 +17,7 @@ var ECPrivateKeyASN = _asn1js2.default.define("ECPrivateKey", function() {
|
|
|
18
17
|
});
|
|
19
18
|
var ECPrivateKey8ASN = _asn1js2.default.define(
|
|
20
19
|
"ECPrivateKey",
|
|
21
|
-
/* v8 ignore
|
|
20
|
+
/* v8 ignore next -- @preserve */
|
|
22
21
|
function() {
|
|
23
22
|
const self = this;
|
|
24
23
|
self.seq().obj(
|
|
@@ -28,7 +27,6 @@ var ECPrivateKey8ASN = _asn1js2.default.define(
|
|
|
28
27
|
self.key("attributes").explicit(0).bitstr().optional()
|
|
29
28
|
);
|
|
30
29
|
}
|
|
31
|
-
/* v8 ignore stop */
|
|
32
30
|
);
|
|
33
31
|
var SubjectPublicKeyInfoASN = _asn1js2.default.define("SubjectPublicKeyInfo", function() {
|
|
34
32
|
const self = this;
|
|
@@ -58,14 +56,14 @@ var KeyEncoder = class {
|
|
|
58
56
|
constructor(options) {
|
|
59
57
|
if (typeof options === "string") {
|
|
60
58
|
if (options !== "secp256k1" && options !== "p256") {
|
|
61
|
-
throw new Error(
|
|
59
|
+
throw new Error(`Unknown curve ${options}`);
|
|
62
60
|
}
|
|
63
61
|
options = curves[options];
|
|
64
62
|
}
|
|
65
63
|
this.options = options;
|
|
66
64
|
this.algorithmID = [1, 2, 840, 10045, 2, 1];
|
|
67
65
|
}
|
|
68
|
-
/* v8 ignore
|
|
66
|
+
/* v8 ignore next -- @preserve */
|
|
69
67
|
PKCS1toPKCS8(privateKey) {
|
|
70
68
|
return {
|
|
71
69
|
version: new (0, _bnjs2.default)(0),
|
|
@@ -76,7 +74,6 @@ var KeyEncoder = class {
|
|
|
76
74
|
}
|
|
77
75
|
};
|
|
78
76
|
}
|
|
79
|
-
/* v8 ignore stop */
|
|
80
77
|
privateKeyObject(rawPrivateKey, rawPublicKey) {
|
|
81
78
|
const privateKeyObject = {
|
|
82
79
|
version: new (0, _bnjs2.default)(1),
|
|
@@ -115,6 +112,7 @@ var KeyEncoder = class {
|
|
|
115
112
|
privateKeyObject = this.privateKeyObject(privateKey, rawPublicKey);
|
|
116
113
|
break;
|
|
117
114
|
}
|
|
115
|
+
/* v8 ignore next -- @preserve */
|
|
118
116
|
case "der":
|
|
119
117
|
if (typeof privateKey === "string") {
|
|
120
118
|
privateKey = Buffer.from(privateKey, "hex");
|
|
@@ -131,7 +129,7 @@ var KeyEncoder = class {
|
|
|
131
129
|
this.options.privatePEMOptions
|
|
132
130
|
);
|
|
133
131
|
break;
|
|
134
|
-
/* v8 ignore
|
|
132
|
+
/* v8 ignore next -- @preserve */
|
|
135
133
|
default:
|
|
136
134
|
throw new Error("invalid private key format");
|
|
137
135
|
}
|
|
@@ -162,7 +160,7 @@ var KeyEncoder = class {
|
|
|
162
160
|
});
|
|
163
161
|
}
|
|
164
162
|
break;
|
|
165
|
-
/* v8 ignore
|
|
163
|
+
/* v8 ignore next -- @preserve */
|
|
166
164
|
default:
|
|
167
165
|
throw new Error("invalid destination format for private key");
|
|
168
166
|
}
|
|
@@ -177,6 +175,7 @@ var KeyEncoder = class {
|
|
|
177
175
|
}
|
|
178
176
|
publicKeyObject = this.publicKeyObject(publicKey);
|
|
179
177
|
break;
|
|
178
|
+
/* v8 ignore next -- @preserve */
|
|
180
179
|
case "der":
|
|
181
180
|
if (typeof publicKey === "string") {
|
|
182
181
|
publicKey = Buffer.from(publicKey, "hex");
|
|
@@ -193,7 +192,7 @@ var KeyEncoder = class {
|
|
|
193
192
|
this.options.publicPEMOptions
|
|
194
193
|
);
|
|
195
194
|
break;
|
|
196
|
-
/* v8 ignore
|
|
195
|
+
/* v8 ignore next -- @preserve */
|
|
197
196
|
default:
|
|
198
197
|
throw new Error("invalid public key format");
|
|
199
198
|
}
|
|
@@ -208,7 +207,7 @@ var KeyEncoder = class {
|
|
|
208
207
|
"pem",
|
|
209
208
|
this.options.publicPEMOptions
|
|
210
209
|
);
|
|
211
|
-
/* v8 ignore
|
|
210
|
+
/* v8 ignore next -- @preserve */
|
|
212
211
|
default:
|
|
213
212
|
throw new Error("invalid destination format for public key");
|
|
214
213
|
}
|
|
@@ -216,6 +215,7 @@ var KeyEncoder = class {
|
|
|
216
215
|
};
|
|
217
216
|
|
|
218
217
|
// src/crypto/utils.ts
|
|
218
|
+
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
219
219
|
function extractPublicKey(pemKey) {
|
|
220
220
|
const pem = pemKey.split("\n");
|
|
221
221
|
pem.shift();
|
|
@@ -266,4 +266,6 @@ var sign = async (privateKeyPem, base64Challenge) => {
|
|
|
266
266
|
|
|
267
267
|
|
|
268
268
|
exports.genKeys = genKeys; exports.sign = sign;
|
|
269
|
-
|
|
269
|
+
/* v8 ignore else -- @preserve */
|
|
270
|
+
/* v8 ignore if -- @preserve */
|
|
271
|
+
//# sourceMappingURL=chunk-P53CFOI6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/_work/revault/revault/packages/sdk/lib/chunk-P53CFOI6.cjs","../src/crypto/utils.ts","../src/crypto/key-encoder.ts"],"names":[],"mappings":"AAAA;ACAA,wFAAqB;AACrB,uEAAsB;ADEtB;AACA;AEMA,iFAAiB;AACjB,yEAAe;AACf;AAGA,IAAM,gBAAA,EAAkB,gBAAA,CAAK,MAAA,CAAO,cAAA,EAAgB,QAAA,CAAA,EAAY;AAG9D,EAAA,MAAM,KAAA,EAAO,IAAA;AACb,EAAA,IAAA,CACG,GAAA,CAAI,CAAA,CACJ,GAAA;AAAA,IACC,IAAA,CAAK,GAAA,CAAI,SAAS,CAAA,CAAE,GAAA,CAAI,CAAA;AAAA,IACxB,IAAA,CAAK,GAAA,CAAI,YAAY,CAAA,CAAE,MAAA,CAAO,CAAA;AAAA,IAC9B,IAAA,CAAK,GAAA,CAAI,YAAY,CAAA,CAAE,QAAA,CAAS,CAAC,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAA,CAAS,CAAA;AAAA,IACpD,IAAA,CAAK,GAAA,CAAI,WAAW,CAAA,CAAE,QAAA,CAAS,CAAC,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,QAAA,CAAS;AAAA,EACtD,CAAA;AACJ,CAAC,CAAA;AAED,IAAM,iBAAA,EAAmB,gBAAA,CAAK,MAAA;AAAA,EAC5B,cAAA;AAAA;AAAA,EAEA,QAAA,CAAA,EAAY;AAGV,IAAA,MAAM,KAAA,EAAO,IAAA;AACb,IAAA,IAAA,CACG,GAAA,CAAI,CAAA,CACJ,GAAA;AAAA,MACC,IAAA,CAAK,GAAA,CAAI,SAAS,CAAA,CAAE,GAAA,CAAI,CA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A;AAEF,MAAA;AACkB,QAAA;AACpB,IAAA;AACF,EAAA;AACF;AFjFiD;AACA;ACnN9B;AAE+B;AAGnB,EAAA;AACnB,EAAA;AACF,EAAA;AAEoC,EAAA;AAGF,EAAA;AACH,EAAA;AACzC;AAEwD;AACd,EAAA;AACzB,EAAA;AAC8B,IAAA;AAC7C,EAAA;AAC0C,EAAA;AAC5C;AAMyD;AAC1C,EAAA;AACsB,IAAA;AACO,IAAA;AACV,IAAA;AACa,MAAA;AAC1C,IAAA;AACM,IAAA;AAC+B,MAAA;AACD,MAAA;AACA,MAAA;AACrC,IAAA;AACF,EAAA;AACyC,EAAA;AAC3B,IAAA;AAC+B,IAAA;AACC,IAAA;AAC7C,EAAA;AAC2C,EAAA;AACrC,EAAA;AACL,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;AAEkD;AAEN,EAAA;AAKC,EAAA;AAGT,EAAA;AAGpC;AD+LiD;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/_work/revault/revault/packages/sdk/lib/chunk-P53CFOI6.cjs","sourcesContent":[null,"import elliptic from \"elliptic\";\nimport * as jose from \"jose\";\n\nimport { KeyEncoder } from \"./key-encoder\";\nimport type { GeneratedKeys } from \"./types\";\nimport crypto from \"node:crypto\";\n\nfunction extractPublicKey(pemKey: string): string {\n // convert the PEM formatted public key to raw public key in X9.62 uncompressed format\n // this is an oversimplified method and may not work with different curves or PEM formats\n const pem = pemKey.split(\"\\n\");\n pem.shift(); // remove the first line (BEGIN PUBLIC KEY)\n pem.pop(); // remove the last line (END PUBLIC KEY)\n // convert base64 to buffer\n const keyBuffer = Buffer.from(pem.join(\"\"), \"base64\");\n // assuming the first 26 bytes are the header for the SPKI formatted key.\n // the actual key should begin after this header.\n const actualKeyBuffer = keyBuffer.slice(26);\n return actualKeyBuffer.toString(\"hex\").toUpperCase();\n}\n\nfunction hexToPem(hexString: string, { isPrivate = true } = {}): string {\n const keyEncoder = new KeyEncoder(\"p256\");\n if (isPrivate) {\n return keyEncoder.encodePrivate(hexString, \"raw\", \"pem\");\n }\n return keyEncoder.encodePublic(hexString, \"raw\", \"pem\");\n}\n\n/**\n * If `entropy` is passed, will generate keys pair deterministically\n * else, random keys pair generated\n */\nexport function genKeys(entropy?: string): GeneratedKeys {\n if (entropy) {\n const ec = new elliptic.ec(\"p256\");\n const hashedEntropy = crypto.createHash(\"sha256\").update(entropy).digest(\"hex\");\n const keyPair = ec.genKeyPair({\n entropy: Buffer.from(hashedEntropy, \"hex\"),\n });\n return {\n privateKey: String(hexToPem(keyPair.getPrivate(\"hex\"))),\n publicKey: String(hexToPem(keyPair.getPublic(\"hex\"), { isPrivate: false })),\n hexPubKey: extractPublicKey(String(hexToPem(keyPair.getPublic(\"hex\"), { isPrivate: false }))),\n };\n }\n const { publicKey, privateKey } = crypto.generateKeyPairSync(\"ec\", {\n namedCurve: \"P-256\",\n publicKeyEncoding: { type: \"spki\", format: \"pem\" },\n privateKeyEncoding: { type: \"sec1\", format: \"pem\" },\n });\n const hexPubKey = extractPublicKey(publicKey);\n return {\n privateKey,\n publicKey,\n hexPubKey,\n };\n}\n\nexport const sign = async (privateKeyPem: string, base64Challenge: string): Promise<string> => {\n // Decode base64url challenge to bytes\n const challengeDataBytes = jose.base64url.decode(base64Challenge);\n\n // For EC private key format, we need to use a different import method\n // Since jose doesn't support SEC1 format directly, let's use Node.js crypto\n // Create a KeyObject from the EC private key\n const privateKey = crypto.createPrivateKey(privateKeyPem);\n\n // Use jose with the KeyObject\n return await new jose.CompactSign(challengeDataBytes)\n .setProtectedHeader({ alg: \"ES256\", typ: \"JWT\" })\n .sign(privateKey);\n};\n","// ========================================================================== //\n// //\n// DISCLAIMER //\n// //\n// This code has been blindly copy-pasted from: //\n// https://github.com/LedgerHQ/pkey-ts //\n// //\n// ========================================================================== //\n//\n// @ts-expect-error this library does not ship types\nimport asn1 from \"asn1.js\";\nimport BN from \"bn.js\";\nimport elliptic from \"elliptic\";\n\n/* cspell:disable */\nconst ECPrivateKeyASN = asn1.define(\"ECPrivateKey\", function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"version\").int(),\n self.key(\"privateKey\").octstr(),\n self.key(\"parameters\").explicit(0).objid().optional(),\n self.key(\"publicKey\").explicit(1).bitstr().optional(),\n );\n});\n\nconst ECPrivateKey8ASN = asn1.define(\n \"ECPrivateKey\",\n /* v8 ignore next -- @preserve */\n function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"version\").int(),\n self\n .key(\"privateKeyAlgorithm\")\n .seq()\n .obj(self.key(\"ecPublicKey\").objid(), self.key(\"curve\").objid()),\n self.key(\"privateKey\").octstr().contains(ECPrivateKeyASN),\n self.key(\"attributes\").explicit(0).bitstr().optional(),\n );\n },\n);\n\nconst SubjectPublicKeyInfoASN = asn1.define(\"SubjectPublicKeyInfo\", function () {\n // @ts-expect-error pure black box\n // biome-ignore lint/suspicious/noExplicitAny: black box\n const self = this as any;\n self\n .seq()\n .obj(\n self.key(\"algorithm\").seq().obj(self.key(\"id\").objid(), self.key(\"curve\").objid()),\n self.key(\"pub\").bitstr(),\n );\n});\n\ntype CurveOptions = {\n curveParameters: number[];\n privatePEMOptions: { label: string };\n publicPEMOptions: { label: string };\n curve: elliptic.ec;\n};\n\nconst curves: Record<string, CurveOptions> = {\n secp256k1: {\n curveParameters: [1, 3, 132, 0, 10],\n privatePEMOptions: { label: \"EC PRIVATE KEY\" },\n publicPEMOptions: { label: \"PUBLIC KEY\" },\n curve: new elliptic.ec(\"secp256k1\"),\n },\n p256: {\n curveParameters: [1, 2, 840, 10045, 3, 1, 7], // OID for p256 curve\n privatePEMOptions: { label: \"EC PRIVATE KEY\" },\n publicPEMOptions: { label: \"PUBLIC KEY\" },\n curve: new elliptic.ec(\"p256\"),\n },\n};\n\ntype PrivateKeyPKCS1 = {\n version: BN;\n privateKey: Buffer;\n parameters: number[];\n publicKey?: {\n unused: number;\n data: Buffer;\n };\n};\n\ntype PrivateKeyPKCS8 = {\n version: BN;\n privateKey: PrivateKeyPKCS1;\n privateKeyAlgorithm: { ecPublicKey: number[]; curve: number[] };\n};\n\nexport type KeyFormat = \"raw\" | \"pem\" | \"der\";\n\nexport class KeyEncoder {\n algorithmID: number[];\n options: CurveOptions;\n\n constructor(options: string | CurveOptions) {\n /* v8 ignore else -- @preserve */\n if (typeof options === \"string\") {\n /* v8 ignore if -- @preserve */\n if (options !== \"secp256k1\" && options !== \"p256\") {\n throw new Error(`Unknown curve ${options}`);\n }\n options = curves[options]!;\n }\n this.options = options;\n this.algorithmID = [1, 2, 840, 10045, 2, 1];\n }\n\n /* v8 ignore next -- @preserve */\n private PKCS1toPKCS8(privateKey: PrivateKeyPKCS1): PrivateKeyPKCS8 {\n return {\n version: new BN(0),\n privateKey,\n privateKeyAlgorithm: {\n ecPublicKey: this.algorithmID,\n curve: privateKey.parameters,\n },\n };\n }\n\n privateKeyObject(rawPrivateKey: string, rawPublicKey: string): PrivateKeyPKCS1 {\n const privateKeyObject: PrivateKeyPKCS1 = {\n version: new BN(1),\n privateKey: Buffer.from(rawPrivateKey, \"hex\"),\n parameters: this.options.curveParameters,\n };\n\n /* v8 ignore else -- @preserve */\n if (rawPublicKey) {\n privateKeyObject.publicKey = {\n unused: 0,\n data: Buffer.from(rawPublicKey, \"hex\"),\n };\n }\n\n return privateKeyObject;\n }\n\n publicKeyObject(rawPublicKey: string): {\n algorithm: { id: number[]; curve: number[] };\n pub: { unused: number; data: Buffer };\n } {\n return {\n algorithm: {\n id: this.algorithmID,\n curve: this.options.curveParameters,\n },\n pub: {\n unused: 0,\n data: Buffer.from(rawPublicKey, \"hex\"),\n },\n };\n }\n\n encodePrivate(\n privateKey: string | Buffer,\n originalFormat: KeyFormat,\n destinationFormat: KeyFormat,\n destinationFormatType: \"pkcs8\" | \"pkcs1\" = \"pkcs1\",\n ): string {\n let privateKeyObject: PrivateKeyPKCS1;\n\n /* Parse the incoming private key and convert it to a private key object */\n switch (originalFormat) {\n case \"raw\": {\n if (typeof privateKey !== \"string\") {\n throw new Error(\"private key must be a string\");\n }\n const keyPair = this.options.curve.keyFromPrivate(privateKey, \"hex\");\n const rawPublicKey = keyPair.getPublic(\"hex\");\n privateKeyObject = this.privateKeyObject(privateKey, rawPublicKey);\n break;\n }\n /* v8 ignore next -- @preserve */\n case \"der\":\n if (typeof privateKey === \"string\") {\n privateKey = Buffer.from(privateKey, \"hex\");\n }\n privateKeyObject = ECPrivateKeyASN.decode(privateKey, \"der\");\n break;\n case \"pem\":\n if (typeof privateKey !== \"string\") {\n throw new Error(\"private key must be a string\");\n }\n privateKeyObject = ECPrivateKeyASN.decode(\n privateKey,\n \"pem\",\n this.options.privatePEMOptions,\n );\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid private key format\");\n }\n\n /* Export the private key object to the desired format */\n switch (destinationFormat) {\n case \"raw\":\n if (destinationFormatType === \"pkcs1\") {\n return privateKeyObject.privateKey.toString(\"hex\");\n } else if (destinationFormatType === \"pkcs8\") {\n return this.PKCS1toPKCS8(privateKeyObject).privateKey.privateKey.toString(\"hex\");\n }\n break;\n case \"der\":\n if (destinationFormatType === \"pkcs1\") {\n return ECPrivateKeyASN.encode(privateKeyObject, \"der\").toString(\"hex\");\n } else if (destinationFormatType === \"pkcs8\") {\n return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), \"der\").toString(\n \"hex\",\n );\n }\n break;\n case \"pem\":\n if (destinationFormatType === \"pkcs1\") {\n return ECPrivateKeyASN.encode(privateKeyObject, \"pem\", this.options.privatePEMOptions);\n } else if (destinationFormatType === \"pkcs8\") {\n return ECPrivateKey8ASN.encode(this.PKCS1toPKCS8(privateKeyObject), \"pem\", {\n ...this.options.privatePEMOptions,\n label: \"PRIVATE KEY\",\n });\n }\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid destination format for private key\");\n }\n\n throw new Error(\"unsupported destination format or type\");\n }\n\n encodePublic(\n publicKey: string | Buffer,\n originalFormat: KeyFormat,\n destinationFormat: KeyFormat,\n ): string {\n // biome-ignore lint/suspicious/noImplicitAnyLet: melting pot object\n let publicKeyObject;\n\n switch (originalFormat) {\n case \"raw\":\n if (typeof publicKey !== \"string\") {\n throw new Error(\"public key must be a string\");\n }\n publicKeyObject = this.publicKeyObject(publicKey);\n break;\n /* v8 ignore next -- @preserve */\n case \"der\":\n if (typeof publicKey === \"string\") {\n publicKey = Buffer.from(publicKey, \"hex\");\n }\n publicKeyObject = SubjectPublicKeyInfoASN.decode(publicKey, \"der\");\n break;\n case \"pem\":\n if (typeof publicKey !== \"string\") {\n throw new Error(\"public key must be a string\");\n }\n publicKeyObject = SubjectPublicKeyInfoASN.decode(\n publicKey,\n \"pem\",\n this.options.publicPEMOptions,\n );\n break;\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid public key format\");\n }\n\n /* Export the private key object to the desired format */\n switch (destinationFormat) {\n case \"raw\":\n return publicKeyObject.pub.data.toString(\"hex\");\n case \"der\":\n return SubjectPublicKeyInfoASN.encode(publicKeyObject, \"der\").toString(\"hex\");\n case \"pem\":\n return SubjectPublicKeyInfoASN.encode(\n publicKeyObject,\n \"pem\",\n this.options.publicPEMOptions,\n );\n /* v8 ignore next -- @preserve */\n default:\n throw new Error(\"invalid destination format for public key\");\n }\n }\n}\n/* cspell:enable */\n"]}
|
package/lib/crypto.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkP53CFOI6cjs = require('./chunk-P53CFOI6.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.genKeys =
|
|
8
|
+
exports.genKeys = _chunkP53CFOI6cjs.genKeys; exports.sign = _chunkP53CFOI6cjs.sign;
|
|
9
9
|
//# sourceMappingURL=crypto.cjs.map
|
package/lib/crypto.js
CHANGED
package/lib/device.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk2HKHCIKXcjs = require('./chunk-2HKHCIKX.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
exports.createApiDevice =
|
|
12
|
+
exports.createApiDevice = _chunk2HKHCIKXcjs.createApiDevice; exports.isDeviceCancelError = _chunk2HKHCIKXcjs.isDeviceCancelError; exports.isTransportStatusError = _chunk2HKHCIKXcjs.isTransportStatusError; exports.registerTransportModule = _chunk2HKHCIKXcjs.registerTransportModule;
|
|
13
13
|
//# sourceMappingURL=device.cjs.map
|
package/lib/device.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { L as Logger } from './logger-C-TPbnjv.cjs';
|
|
2
2
|
import { D as Device } from './types-DJfbanPz.cjs';
|
|
3
|
-
import { TransportStatusError } from '@ledgerhq/errors';
|
|
4
3
|
import Transport from '@ledgerhq/hw-transport';
|
|
5
4
|
import { Observable } from 'rxjs';
|
|
5
|
+
import { TransportStatusError } from '@ledgerhq/errors';
|
|
6
6
|
import '@ledgerhq/revault-api';
|
|
7
7
|
|
|
8
8
|
type Options = {
|
|
@@ -30,9 +30,6 @@ type ApiDevice = {
|
|
|
30
30
|
};
|
|
31
31
|
declare function createApiDevice(options: Options, logger: Logger): ApiDevice;
|
|
32
32
|
|
|
33
|
-
declare const isTransportStatusError: (error: unknown) => error is TransportStatusError;
|
|
34
|
-
declare const isDeviceCancelError: (error: Error) => boolean;
|
|
35
|
-
|
|
36
33
|
type Discovery = Observable<{
|
|
37
34
|
type: "add" | "remove";
|
|
38
35
|
id: string;
|
|
@@ -47,4 +44,7 @@ type TransportModule = {
|
|
|
47
44
|
};
|
|
48
45
|
declare const registerTransportModule: (module: TransportModule) => void;
|
|
49
46
|
|
|
47
|
+
declare const isTransportStatusError: (error: unknown) => error is TransportStatusError;
|
|
48
|
+
declare const isDeviceCancelError: (error: Error) => boolean;
|
|
49
|
+
|
|
50
50
|
export { type ApiDevice, Device, createApiDevice, isDeviceCancelError, isTransportStatusError, registerTransportModule };
|